aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorDavid Faust <david.faust@oracle.com>2021-11-15 11:24:40 -0800
committerDavid Faust <david.faust@oracle.com>2021-11-16 13:10:41 -0800
commit553e88f1dd4b4794334ee6d1861c185b92361a0b (patch)
tree62075b93b07f3dce20b0c0afa1bc8024bb1cac89 /gcc
parentb52a68d2d8676ea378f0fbb6726639cc80402542 (diff)
downloadgcc-553e88f1dd4b4794334ee6d1861c185b92361a0b.zip
gcc-553e88f1dd4b4794334ee6d1861c185b92361a0b.tar.gz
gcc-553e88f1dd4b4794334ee6d1861c185b92361a0b.tar.bz2
Replace Bstatement with GCC tree
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile-block.h11
-rw-r--r--gcc/rust/backend/rust-compile-context.h6
-rw-r--r--gcc/rust/backend/rust-compile-expr.cc4
-rw-r--r--gcc/rust/backend/rust-compile-expr.h35
-rw-r--r--gcc/rust/backend/rust-compile-implitem.h4
-rw-r--r--gcc/rust/backend/rust-compile-item.h2
-rw-r--r--gcc/rust/backend/rust-compile-stmt.h2
-rw-r--r--gcc/rust/backend/rust-compile.cc14
-rw-r--r--gcc/rust/rust-backend.h63
-rw-r--r--gcc/rust/rust-gcc.cc211
10 files changed, 153 insertions, 199 deletions
diff --git a/gcc/rust/backend/rust-compile-block.h b/gcc/rust/backend/rust-compile-block.h
index 6876e8a..0e631e1 100644
--- a/gcc/rust/backend/rust-compile-block.h
+++ b/gcc/rust/backend/rust-compile-block.h
@@ -53,8 +53,7 @@ class CompileConditionalBlocks : public HIRCompileBase
using Rust::Compile::HIRCompileBase::visit;
public:
- static Bstatement *compile (HIR::IfExpr *expr, Context *ctx,
- Bvariable *result)
+ static tree compile (HIR::IfExpr *expr, Context *ctx, Bvariable *result)
{
CompileConditionalBlocks resolver (ctx, result);
expr->accept_vis (resolver);
@@ -72,7 +71,7 @@ private:
: HIRCompileBase (ctx), translated (nullptr), result (result)
{}
- Bstatement *translated;
+ tree translated;
Bvariable *result;
};
@@ -81,8 +80,8 @@ class CompileExprWithBlock : public HIRCompileBase
using Rust::Compile::HIRCompileBase::visit;
public:
- static Bstatement *compile (HIR::ExprWithBlock *expr, Context *ctx,
- Bvariable *result)
+ static tree compile (HIR::ExprWithBlock *expr, Context *ctx,
+ Bvariable *result)
{
CompileExprWithBlock resolver (ctx, result);
expr->accept_vis (resolver);
@@ -109,7 +108,7 @@ private:
: HIRCompileBase (ctx), translated (nullptr), result (result)
{}
- Bstatement *translated;
+ tree translated;
Bvariable *result;
};
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h
index 35ea012..1128fa8 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -139,12 +139,12 @@ public:
return scope_stack.back ();
}
- void add_statement_to_enclosing_scope (Bstatement *stmt)
+ void add_statement_to_enclosing_scope (tree stmt)
{
statements.at (statements.size () - 2).push_back (stmt);
}
- void add_statement (Bstatement *stmt) { statements.back ().push_back (stmt); }
+ void add_statement (tree stmt) { statements.back ().push_back (stmt); }
void insert_var_decl (HirId id, ::Bvariable *decl)
{
@@ -323,7 +323,7 @@ private:
std::map<HirId, ::Bfunction *> compiled_fn_map;
std::map<HirId, tree> compiled_consts;
std::map<HirId, ::Blabel *> compiled_labels;
- std::vector<::std::vector<Bstatement *>> statements;
+ std::vector<::std::vector<tree>> statements;
std::vector<::Bblock *> scope_stack;
std::vector<::Bvariable *> loop_value_stack;
std::vector<::Blabel *> loop_begin_labels;
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index d475ec4..8786702 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -86,7 +86,7 @@ CompileExpr::visit (HIR::CompoundAssignmentExpr &expr)
auto operator_expr
= ctx->get_backend ()->arithmetic_or_logical_expression (op, lhs, rhs,
expr.get_locus ());
- Bstatement *assignment
+ tree assignment
= ctx->get_backend ()->assignment_statement (fn.fndecl, lhs, operator_expr,
expr.get_locus ());
ctx->add_statement (assignment);
@@ -178,7 +178,7 @@ CompileExpr::compile_dyn_dispatch_call (const TyTy::DynamicObjectType *dyn,
fncontext fnctx = ctx->peek_fn ();
Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
bool is_address_taken = false;
- Bstatement *ret_var_stmt = nullptr;
+ tree ret_var_stmt = NULL_TREE;
Bvariable *fn_convert_expr_tmp
= ctx->get_backend ()->temporary_variable (fnctx.fndecl, enclosing_scope,
expected_fntype, fn_convert_expr,
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index 2f6395c..14d4345 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -379,7 +379,7 @@ public:
rvalue = coercion_site (rvalue, actual, expected, expr.get_locus ());
- Bstatement *assignment
+ tree assignment
= ctx->get_backend ()->assignment_statement (fn.fndecl, lvalue, rvalue,
expr.get_locus ());
@@ -518,7 +518,7 @@ public:
tree block_type = TyTyResolveCompile::compile (ctx, if_type);
bool is_address_taken = false;
- Bstatement *ret_var_stmt = nullptr;
+ tree ret_var_stmt = nullptr;
tmp = ctx->get_backend ()->temporary_variable (
fnctx.fndecl, enclosing_scope, block_type, NULL, is_address_taken,
expr.get_locus (), &ret_var_stmt);
@@ -555,7 +555,7 @@ public:
tree block_type = TyTyResolveCompile::compile (ctx, if_type);
bool is_address_taken = false;
- Bstatement *ret_var_stmt = nullptr;
+ tree ret_var_stmt = nullptr;
tmp = ctx->get_backend ()->temporary_variable (
fnctx.fndecl, enclosing_scope, block_type, NULL, is_address_taken,
expr.get_locus (), &ret_var_stmt);
@@ -591,7 +591,7 @@ public:
tree block_type = TyTyResolveCompile::compile (ctx, block_tyty);
bool is_address_taken = false;
- Bstatement *ret_var_stmt = nullptr;
+ tree ret_var_stmt = nullptr;
tmp = ctx->get_backend ()->temporary_variable (
fnctx.fndecl, enclosing_scope, block_type, NULL, is_address_taken,
expr.get_locus (), &ret_var_stmt);
@@ -744,7 +744,7 @@ public:
tree block_type = TyTyResolveCompile::compile (ctx, block_tyty);
bool is_address_taken = false;
- Bstatement *ret_var_stmt = nullptr;
+ tree ret_var_stmt = NULL_TREE;
tmp = ctx->get_backend ()->temporary_variable (
fnctx.fndecl, enclosing_scope, block_type, NULL, is_address_taken,
expr.get_locus (), &ret_var_stmt);
@@ -759,7 +759,7 @@ public:
= ctx->get_backend ()->label (fnctx.fndecl,
loop_label.get_lifetime ().get_name (),
loop_label.get_locus ());
- Bstatement *label_decl
+ tree label_decl
= ctx->get_backend ()->label_definition_statement (label);
ctx->add_statement (label_decl);
ctx->insert_label_decl (
@@ -768,7 +768,7 @@ public:
Blabel *loop_begin_label
= ctx->get_backend ()->label (fnctx.fndecl, "", expr.get_locus ());
- Bstatement *loop_begin_label_decl
+ tree loop_begin_label_decl
= ctx->get_backend ()->label_definition_statement (loop_begin_label);
ctx->add_statement (loop_begin_label_decl);
ctx->push_loop_begin_label (loop_begin_label);
@@ -777,7 +777,7 @@ public:
= CompileBlock::compile (expr.get_loop_block ().get (), ctx, nullptr);
tree loop_expr
= ctx->get_backend ()->loop_expression (code_block, expr.get_locus ());
- Bstatement *loop_stmt
+ tree loop_stmt
= ctx->get_backend ()->expression_statement (fnctx.fndecl, loop_expr);
ctx->add_statement (loop_stmt);
@@ -800,7 +800,7 @@ public:
= ctx->get_backend ()->label (fnctx.fndecl,
loop_label.get_lifetime ().get_name (),
loop_label.get_locus ());
- Bstatement *label_decl
+ tree label_decl
= ctx->get_backend ()->label_definition_statement (label);
ctx->add_statement (label_decl);
ctx->insert_label_decl (
@@ -819,7 +819,7 @@ public:
Blabel *loop_begin_label
= ctx->get_backend ()->label (fnctx.fndecl, "", expr.get_locus ());
- Bstatement *loop_begin_label_decl
+ tree loop_begin_label_decl
= ctx->get_backend ()->label_definition_statement (loop_begin_label);
ctx->add_statement (loop_begin_label_decl);
ctx->push_loop_begin_label (loop_begin_label);
@@ -828,14 +828,13 @@ public:
= CompileExpr::Compile (expr.get_predicate_expr ().get (), ctx);
tree exit_expr
= ctx->get_backend ()->exit_expression (condition, expr.get_locus ());
- Bstatement *break_stmt
+ tree break_stmt
= ctx->get_backend ()->expression_statement (fnctx.fndecl, exit_expr);
ctx->add_statement (break_stmt);
Bblock *code_block
= CompileBlock::compile (expr.get_loop_block ().get (), ctx, nullptr);
- Bstatement *code_block_stmt
- = ctx->get_backend ()->block_statement (code_block);
+ tree code_block_stmt = ctx->get_backend ()->block_statement (code_block);
ctx->add_statement (code_block_stmt);
ctx->pop_loop_begin_label ();
@@ -843,7 +842,7 @@ public:
tree loop_expr
= ctx->get_backend ()->loop_expression (loop_block, expr.get_locus ());
- Bstatement *loop_stmt
+ tree loop_stmt
= ctx->get_backend ()->expression_statement (fnctx.fndecl, loop_expr);
ctx->add_statement (loop_stmt);
}
@@ -860,7 +859,7 @@ public:
tree result_reference = ctx->get_backend ()->var_expression (
loop_result_holder, expr.get_expr ()->get_locus ());
- Bstatement *assignment = ctx->get_backend ()->assignment_statement (
+ tree assignment = ctx->get_backend ()->assignment_statement (
fnctx.fndecl, result_reference, compiled_expr, expr.get_locus ());
ctx->add_statement (assignment);
}
@@ -896,7 +895,7 @@ public:
return;
}
- Bstatement *goto_label
+ tree goto_label
= ctx->get_backend ()->goto_statement (label, expr.get_locus ());
ctx->add_statement (goto_label);
}
@@ -905,7 +904,7 @@ public:
tree exit_expr = ctx->get_backend ()->exit_expression (
ctx->get_backend ()->boolean_constant_expression (true),
expr.get_locus ());
- Bstatement *break_stmt
+ tree break_stmt
= ctx->get_backend ()->expression_statement (fnctx.fndecl, exit_expr);
ctx->add_statement (break_stmt);
}
@@ -945,7 +944,7 @@ public:
}
}
- Bstatement *goto_label
+ tree goto_label
= ctx->get_backend ()->goto_statement (label, expr.get_locus ());
ctx->add_statement (goto_label);
}
diff --git a/gcc/rust/backend/rust-compile-implitem.h b/gcc/rust/backend/rust-compile-implitem.h
index 65f3d2c..fb3b381 100644
--- a/gcc/rust/backend/rust-compile-implitem.h
+++ b/gcc/rust/backend/rust-compile-implitem.h
@@ -278,7 +278,7 @@ public:
tree return_type = TyTyResolveCompile::compile (ctx, tyret);
bool address_is_taken = false;
- Bstatement *ret_var_stmt = nullptr;
+ tree ret_var_stmt = NULL_TREE;
return_address = ctx->get_backend ()->temporary_variable (
fndecl, code_block, return_type, NULL, address_is_taken,
@@ -538,7 +538,7 @@ public:
tree return_type = TyTyResolveCompile::compile (ctx, tyret);
bool address_is_taken = false;
- Bstatement *ret_var_stmt = nullptr;
+ tree ret_var_stmt = NULL_TREE;
return_address = ctx->get_backend ()->temporary_variable (
fndecl, code_block, return_type, NULL, address_is_taken,
diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h
index 95de611..0e7737c 100644
--- a/gcc/rust/backend/rust-compile-item.h
+++ b/gcc/rust/backend/rust-compile-item.h
@@ -277,7 +277,7 @@ public:
tree return_type = TyTyResolveCompile::compile (ctx, tyret);
bool address_is_taken = false;
- Bstatement *ret_var_stmt = nullptr;
+ tree ret_var_stmt = NULL_TREE;
return_address = ctx->get_backend ()->temporary_variable (
fndecl, code_block, return_type, NULL, address_is_taken,
diff --git a/gcc/rust/backend/rust-compile-stmt.h b/gcc/rust/backend/rust-compile-stmt.h
index 604d9a5..f3ee69d 100644
--- a/gcc/rust/backend/rust-compile-stmt.h
+++ b/gcc/rust/backend/rust-compile-stmt.h
@@ -118,7 +118,7 @@ public:
auto fnctx = ctx->peek_fn ();
if (ty->is_unit ())
{
- Bstatement *expr_stmt
+ tree expr_stmt
= ctx->get_backend ()->expression_statement (fnctx.fndecl, init);
ctx->add_statement (expr_stmt);
}
diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc
index 3531930..8b74c77 100644
--- a/gcc/rust/backend/rust-compile.cc
+++ b/gcc/rust/backend/rust-compile.cc
@@ -349,7 +349,7 @@ CompileBlock::visit (HIR::BlockExpr &expr)
auto compiled_expr = CompileStmt::Compile (s.get (), ctx);
if (compiled_expr != nullptr)
{
- Bstatement *compiled_stmt
+ tree compiled_stmt
= ctx->get_backend ()->expression_statement (fnctx.fndecl,
compiled_expr);
ctx->add_statement (compiled_stmt);
@@ -365,7 +365,7 @@ CompileBlock::visit (HIR::BlockExpr &expr)
{
if (result == nullptr)
{
- Bstatement *final_stmt
+ tree final_stmt
= ctx->get_backend ()->expression_statement (fnctx.fndecl,
compiled_expr);
ctx->add_statement (final_stmt);
@@ -375,7 +375,7 @@ CompileBlock::visit (HIR::BlockExpr &expr)
tree result_reference = ctx->get_backend ()->var_expression (
result, expr.get_final_expr ()->get_locus ());
- Bstatement *assignment
+ tree assignment
= ctx->get_backend ()->assignment_statement (fnctx.fndecl,
result_reference,
compiled_expr,
@@ -438,7 +438,7 @@ CompileConditionalBlocks::visit (HIR::IfExprConseqIf &expr)
start_location, end_location);
ctx->push_block (else_block);
- Bstatement *else_stmt_decl
+ tree else_stmt_decl
= CompileConditionalBlocks::compile (expr.get_conseq_if_expr (), ctx,
result);
ctx->add_statement (else_stmt_decl);
@@ -486,7 +486,7 @@ HIRCompileBase::compile_function_body (
auto compiled_expr = CompileStmt::Compile (s.get (), ctx);
if (compiled_expr != nullptr)
{
- Bstatement *compiled_stmt
+ tree compiled_stmt
= ctx->get_backend ()->expression_statement (fndecl, compiled_expr);
ctx->add_statement (compiled_stmt);
}
@@ -513,7 +513,7 @@ HIRCompileBase::compile_function_body (
}
else
{
- Bstatement *final_stmt
+ tree final_stmt
= ctx->get_backend ()->expression_statement (fndecl,
compiled_expr);
ctx->add_statement (final_stmt);
@@ -612,7 +612,7 @@ HIRCompileBase::coerce_to_dyn_object (tree compiled_ref,
fncontext fnctx = ctx->peek_fn ();
Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
bool is_address_taken = false;
- Bstatement *ret_var_stmt = nullptr;
+ tree ret_var_stmt = NULL_TREE;
Bvariable *dyn_tmp = ctx->get_backend ()->temporary_variable (
fnctx.fndecl, enclosing_scope, dynamic_object, constructed_trait_object,
diff --git a/gcc/rust/rust-backend.h b/gcc/rust/rust-backend.h
index 49b9eea..22e2b6b 100644
--- a/gcc/rust/rust-backend.h
+++ b/gcc/rust/rust-backend.h
@@ -41,9 +41,6 @@ saw_errors (void);
// frontend, and passed back to the backend. The types must be
// defined by the backend using these names.
-// The backend representation of a statement.
-class Bstatement;
-
// The backend representation of a function definition or declaration.
class Bfunction;
@@ -84,7 +81,6 @@ public:
// debug
virtual void debug (tree) = 0;
- virtual void debug (Bstatement *) = 0;
virtual void debug (Bfunction *) = 0;
virtual void debug (Bblock *) = 0;
virtual void debug (Bvariable *) = 0;
@@ -328,8 +324,7 @@ public:
= 0;
// Create an expression that executes BSTAT before BEXPR.
- virtual tree compound_expression (Bstatement *bstat, tree bexpr, Location)
- = 0;
+ virtual tree compound_expression (tree bstat, tree bexpr, Location) = 0;
// Return an expression that executes THEN_EXPR if CONDITION is true, or
// ELSE_EXPR otherwise and returns the result as type BTYPE, within the
@@ -400,32 +395,29 @@ public:
// Create an error statement. This is used for cases which should
// not occur in a correct program, in order to keep the compilation
// going without crashing.
- virtual Bstatement *error_statement () = 0;
+ virtual tree error_statement () = 0;
// Create an expression statement within the specified function.
- virtual Bstatement *expression_statement (Bfunction *, tree) = 0;
+ virtual tree expression_statement (Bfunction *, tree) = 0;
// Create a variable initialization statement in the specified
// function. This initializes a local variable at the point in the
// program flow where it is declared.
- virtual Bstatement *init_statement (Bfunction *, Bvariable *var, tree init)
- = 0;
+ virtual tree init_statement (Bfunction *, Bvariable *var, tree init) = 0;
// Create an assignment statement within the specified function.
- virtual Bstatement *assignment_statement (Bfunction *, tree lhs, tree rhs,
- Location)
+ virtual tree assignment_statement (Bfunction *, tree lhs, tree rhs, Location)
= 0;
// Create a return statement, passing the representation of the
// function and the list of values to return.
- virtual Bstatement *return_statement (Bfunction *, const std::vector<tree> &,
- Location)
+ virtual tree return_statement (Bfunction *, const std::vector<tree> &,
+ Location)
= 0;
// Create an if statement within a function. ELSE_BLOCK may be NULL.
- virtual Bstatement *if_statement (Bfunction *, tree condition,
- Bblock *then_block, Bblock *else_block,
- Location)
+ virtual tree if_statement (Bfunction *, tree condition, Bblock *then_block,
+ Bblock *else_block, Location)
= 0;
// infinite loop expressions
@@ -441,26 +433,24 @@ public:
// either end with a goto statement or will fall through into
// STATEMENTS[i + 1]. CASES[i] is empty for the default clause,
// which need not be last. FUNCTION is the current function.
- virtual Bstatement *
- switch_statement (Bfunction *function, tree value,
- const std::vector<std::vector<tree> > &cases,
- const std::vector<Bstatement *> &statements, Location)
+ virtual tree switch_statement (Bfunction *function, tree value,
+ const std::vector<std::vector<tree> > &cases,
+ const std::vector<tree> &statements, Location)
= 0;
// Create a single statement from two statements.
- virtual Bstatement *compound_statement (Bstatement *, Bstatement *) = 0;
+ virtual tree compound_statement (tree, tree) = 0;
// Create a single statement from a list of statements.
- virtual Bstatement *statement_list (const std::vector<Bstatement *> &) = 0;
+ virtual tree statement_list (const std::vector<tree> &) = 0;
// Create a statement that attempts to execute BSTAT and calls EXCEPT_STMT if
// an exception occurs. EXCEPT_STMT may be NULL. FINALLY_STMT may be NULL and
// if not NULL, it will always be executed. This is used for handling defers
// in Go functions. In C++, the resulting code is of this form:
// try { BSTAT; } catch { EXCEPT_STMT; } finally { FINALLY_STMT; }
- virtual Bstatement *
- exception_handler_statement (Bstatement *bstat, Bstatement *except_stmt,
- Bstatement *finally_stmt, Location)
+ virtual tree exception_handler_statement (tree bstat, tree except_stmt,
+ tree finally_stmt, Location)
= 0;
// Blocks.
@@ -484,13 +474,11 @@ public:
// the statements are created. Then the statements are added to the
// block. This will called exactly once per block. The vector may
// be empty if there are no statements.
- virtual void block_add_statements (Bblock *,
- const std::vector<Bstatement *> &)
- = 0;
+ virtual void block_add_statements (Bblock *, const std::vector<tree> &) = 0;
// Return the block as a statement. This is used to include a block
// in a list of statements.
- virtual Bstatement *block_statement (Bblock *) = 0;
+ virtual tree block_statement (Bblock *) = 0;
// Variables.
@@ -567,8 +555,7 @@ public:
// *PSTATEMENT to a statement which initializes the variable.
virtual Bvariable *temporary_variable (Bfunction *, Bblock *, tree, tree init,
bool address_is_taken,
- Location location,
- Bstatement **pstatement)
+ Location location, tree *pstatement)
= 0;
// Create an implicit variable that is compiler-defined. This is
@@ -694,10 +681,10 @@ public:
// Create a statement which defines a label. This statement will be
// put into the codestream at the point where the label should be
// defined.
- virtual Bstatement *label_definition_statement (Blabel *) = 0;
+ virtual tree label_definition_statement (Blabel *) = 0;
// Create a goto statement to a label.
- virtual Bstatement *goto_statement (Blabel *, Location) = 0;
+ virtual tree goto_statement (Blabel *, Location) = 0;
// Create an expression for the address of a label. This is used to
// get the return address of a deferred function which may call
@@ -759,9 +746,8 @@ public:
// be a statement that looks like this in C++:
// finish:
// try { DEFER_RETURN; } catch { CHECK_DEFER; goto finish; }
- virtual Bstatement *function_defer_statement (Bfunction *function,
- tree undefer, tree check_defer,
- Location)
+ virtual tree function_defer_statement (Bfunction *function, tree undefer,
+ tree check_defer, Location)
= 0;
// Record PARAM_VARS as the variables to use for the parameters of FUNCTION.
@@ -774,8 +760,7 @@ public:
// Set the function body for FUNCTION using the code in CODE_STMT. Returns
// true on success, false on failure.
- virtual bool function_set_body (Bfunction *function, Bstatement *code_stmt)
- = 0;
+ virtual bool function_set_body (Bfunction *function, tree code_stmt) = 0;
// Look up a named built-in function in the current backend implementation.
// Returns NULL if no built-in function by that name exists.
diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index ef7b0b7..873e664 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -70,12 +70,6 @@ private:
// In gcc, types, expressions, and statements are all trees.
-class Bstatement : public Gcc_tree
-{
-public:
- Bstatement (tree t) : Gcc_tree (t) {}
-};
-
class Bfunction : public Gcc_tree
{
public:
@@ -149,7 +143,6 @@ public:
Gcc_backend ();
void debug (tree t) { debug_tree (t); };
- void debug (Bstatement *t) { debug_tree (t->get_tree ()); };
void debug (Bfunction *t) { debug_tree (t->get_tree ()); };
void debug (Bblock *t) { debug_tree (t->get_tree ()); };
void debug (Bvariable *t) { debug_tree (t->get_decl ()); };
@@ -318,7 +311,7 @@ public:
tree struct_field_expression (tree, size_t, Location);
- tree compound_expression (Bstatement *, tree, Location);
+ tree compound_expression (tree, tree, Location);
tree conditional_expression (Bfunction *, tree, tree, tree, tree, Location);
@@ -348,35 +341,29 @@ public:
// Statements.
- Bstatement *error_statement ()
- {
- return this->make_statement (error_mark_node);
- }
+ tree error_statement () { return error_mark_node; }
- Bstatement *expression_statement (Bfunction *, tree);
+ tree expression_statement (Bfunction *, tree);
- Bstatement *init_statement (Bfunction *, Bvariable *var, tree init);
+ tree init_statement (Bfunction *, Bvariable *var, tree init);
- Bstatement *assignment_statement (Bfunction *, tree lhs, tree rhs, Location);
+ tree assignment_statement (Bfunction *, tree lhs, tree rhs, Location);
- Bstatement *return_statement (Bfunction *, const std::vector<tree> &,
- Location);
+ tree return_statement (Bfunction *, const std::vector<tree> &, Location);
- Bstatement *if_statement (Bfunction *, tree condition, Bblock *then_block,
- Bblock *else_block, Location);
+ tree if_statement (Bfunction *, tree condition, Bblock *then_block,
+ Bblock *else_block, Location);
- Bstatement *switch_statement (Bfunction *function, tree value,
- const std::vector<std::vector<tree>> &cases,
- const std::vector<Bstatement *> &statements,
- Location);
+ tree switch_statement (Bfunction *function, tree value,
+ const std::vector<std::vector<tree>> &cases,
+ const std::vector<tree> &statements, Location);
- Bstatement *compound_statement (Bstatement *, Bstatement *);
+ tree compound_statement (tree, tree);
- Bstatement *statement_list (const std::vector<Bstatement *> &);
+ tree statement_list (const std::vector<tree> &);
- Bstatement *exception_handler_statement (Bstatement *bstat,
- Bstatement *except_stmt,
- Bstatement *finally_stmt, Location);
+ tree exception_handler_statement (tree bstat, tree except_stmt,
+ tree finally_stmt, Location);
tree loop_expression (Bblock *body, Location);
@@ -387,9 +374,9 @@ public:
Bblock *block (Bfunction *, Bblock *, const std::vector<Bvariable *> &,
Location, Location);
- void block_add_statements (Bblock *, const std::vector<Bstatement *> &);
+ void block_add_statements (Bblock *, const std::vector<tree> &);
- Bstatement *block_statement (Bblock *);
+ tree block_statement (Bblock *);
// Variables.
@@ -412,7 +399,7 @@ public:
Location);
Bvariable *temporary_variable (Bfunction *, Bblock *, tree, tree, bool,
- Location, Bstatement **);
+ Location, tree *);
Bvariable *implicit_variable (const std::string &, const std::string &,
tree, bool, bool, bool, int64_t);
@@ -437,9 +424,9 @@ public:
Blabel *label (Bfunction *, const std::string &name, Location);
- Bstatement *label_definition_statement (Blabel *);
+ tree label_definition_statement (Blabel *);
- Bstatement *goto_statement (Blabel *, Location);
+ tree goto_statement (Blabel *, Location);
tree label_address (Blabel *, Location);
@@ -451,13 +438,13 @@ public:
const std::string &asm_name, unsigned int flags,
Location);
- Bstatement *function_defer_statement (Bfunction *function, tree undefer,
- tree defer, Location);
+ tree function_defer_statement (Bfunction *function, tree undefer, tree defer,
+ Location);
bool function_set_parameters (Bfunction *function,
const std::vector<Bvariable *> &);
- bool function_set_body (Bfunction *function, Bstatement *code_stmt);
+ bool function_set_body (Bfunction *function, tree code_stmt);
Bfunction *lookup_gcc_builtin (const std::string &);
@@ -472,9 +459,6 @@ public:
private:
- // Make a Bstatement from a tree.
- Bstatement *make_statement (tree t) { return new Bstatement (t); }
-
Bfunction *make_function (tree t) { return new Bfunction (t); }
tree fill_in_fields (tree, const std::vector<typed_identifier> &);
@@ -1530,10 +1514,8 @@ Gcc_backend::struct_field_expression (tree struct_tree, size_t index,
// Return an expression that executes BSTAT before BEXPR.
tree
-Gcc_backend::compound_expression (Bstatement *bstat, tree expr,
- Location location)
+Gcc_backend::compound_expression (tree stat, tree expr, Location location)
{
- tree stat = bstat->get_tree ();
if (stat == error_mark_node || expr == error_mark_node)
return this->error_expression ();
tree ret = fold_build2_loc (location.gcc_location (), COMPOUND_EXPR,
@@ -2042,15 +2024,15 @@ Gcc_backend::call_expression (Bfunction *, // containing fcn for call
// An expression as a statement.
-Bstatement *
+tree
Gcc_backend::expression_statement (Bfunction *, tree expr)
{
- return this->make_statement (expr);
+ return expr;
}
// Variable initialization.
-Bstatement *
+tree
Gcc_backend::init_statement (Bfunction *, Bvariable *var, tree init_tree)
{
tree var_tree = var->get_decl ();
@@ -2077,12 +2059,12 @@ Gcc_backend::init_statement (Bfunction *, Bvariable *var, tree init_tree)
ret = build2_loc (DECL_SOURCE_LOCATION (var_tree), COMPOUND_EXPR,
void_type_node, init_tree, ret);
- return this->make_statement (ret);
+ return ret;
}
// Assignment.
-Bstatement *
+tree
Gcc_backend::assignment_statement (Bfunction *bfn, tree lhs, tree rhs,
Location location)
{
@@ -2104,14 +2086,13 @@ Gcc_backend::assignment_statement (Bfunction *bfn, tree lhs, tree rhs,
rhs = this->convert_tree (TREE_TYPE (lhs), rhs, location);
- return this->make_statement (fold_build2_loc (location.gcc_location (),
- MODIFY_EXPR, void_type_node,
- lhs, rhs));
+ return fold_build2_loc (location.gcc_location (), MODIFY_EXPR, void_type_node,
+ lhs, rhs);
}
// Return.
-Bstatement *
+tree
Gcc_backend::return_statement (Bfunction *bfunction,
const std::vector<tree> &vals, Location location)
{
@@ -2140,7 +2121,7 @@ Gcc_backend::return_statement (Bfunction *bfunction,
tree ret = fold_build1_loc (location.gcc_location (), RETURN_EXPR,
void_type_node, NULL_TREE);
append_to_statement_list (ret, &stmt_list);
- return this->make_statement (stmt_list);
+ return stmt_list;
}
tree ret;
@@ -2196,7 +2177,7 @@ Gcc_backend::return_statement (Bfunction *bfunction,
append_to_statement_list (ret_expr, &stmt_list);
ret = stmt_list;
}
- return this->make_statement (ret);
+ return ret;
}
// Create a statement that attempts to execute BSTAT and calls EXCEPT_STMT if an
@@ -2205,35 +2186,28 @@ Gcc_backend::return_statement (Bfunction *bfunction,
// functions. In C++, the resulting code is of this form:
// try { BSTAT; } catch { EXCEPT_STMT; } finally { FINALLY_STMT; }
-Bstatement *
-Gcc_backend::exception_handler_statement (Bstatement *bstat,
- Bstatement *except_stmt,
- Bstatement *finally_stmt,
- Location location)
+tree
+Gcc_backend::exception_handler_statement (tree try_stmt, tree except_stmt,
+ tree finally_stmt, Location location)
{
- tree stat_tree = bstat->get_tree ();
- tree except_tree = except_stmt == NULL ? NULL_TREE : except_stmt->get_tree ();
- tree finally_tree
- = finally_stmt == NULL ? NULL_TREE : finally_stmt->get_tree ();
-
- if (stat_tree == error_mark_node || except_tree == error_mark_node
- || finally_tree == error_mark_node)
+ if (try_stmt == error_mark_node || except_stmt == error_mark_node
+ || finally_stmt == error_mark_node)
return this->error_statement ();
- if (except_tree != NULL_TREE)
- stat_tree = build2_loc (location.gcc_location (), TRY_CATCH_EXPR,
- void_type_node, stat_tree,
- build2_loc (location.gcc_location (), CATCH_EXPR,
- void_type_node, NULL, except_tree));
- if (finally_tree != NULL_TREE)
- stat_tree = build2_loc (location.gcc_location (), TRY_FINALLY_EXPR,
- void_type_node, stat_tree, finally_tree);
- return this->make_statement (stat_tree);
+ if (except_stmt != NULL_TREE)
+ try_stmt = build2_loc (location.gcc_location (), TRY_CATCH_EXPR,
+ void_type_node, try_stmt,
+ build2_loc (location.gcc_location (), CATCH_EXPR,
+ void_type_node, NULL, except_stmt));
+ if (finally_stmt != NULL_TREE)
+ try_stmt = build2_loc (location.gcc_location (), TRY_FINALLY_EXPR,
+ void_type_node, try_stmt, finally_stmt);
+ return try_stmt;
}
// If.
-Bstatement *
+tree
Gcc_backend::if_statement (Bfunction *, tree cond_tree, Bblock *then_block,
Bblock *else_block, Location location)
{
@@ -2244,7 +2218,7 @@ Gcc_backend::if_statement (Bfunction *, tree cond_tree, Bblock *then_block,
return this->error_statement ();
tree ret = build3_loc (location.gcc_location (), COND_EXPR, void_type_node,
cond_tree, then_tree, else_tree);
- return this->make_statement (ret);
+ return ret;
}
// Loops
@@ -2265,10 +2239,10 @@ Gcc_backend::exit_expression (tree cond_tree, Location locus)
// Switch.
-Bstatement *
+tree
Gcc_backend::switch_statement (Bfunction *function, tree value,
const std::vector<std::vector<tree>> &cases,
- const std::vector<Bstatement *> &statements,
+ const std::vector<tree> &statements,
Location switch_location)
{
gcc_assert (cases.size () == statements.size ());
@@ -2281,13 +2255,13 @@ Gcc_backend::switch_statement (Bfunction *function, tree value,
tree stmt_list = NULL_TREE;
std::vector<std::vector<tree>>::const_iterator pc = cases.begin ();
- for (std::vector<Bstatement *>::const_iterator ps = statements.begin ();
+ for (std::vector<tree>::const_iterator ps = statements.begin ();
ps != statements.end (); ++ps, ++pc)
{
if (pc->empty ())
{
- location_t loc = (*ps != NULL ? EXPR_LOCATION ((*ps)->get_tree ())
- : UNKNOWN_LOCATION);
+ location_t loc
+ = (*ps != NULL ? EXPR_LOCATION (*ps) : UNKNOWN_LOCATION);
tree label = create_artificial_label (loc);
tree c = build_case_label (NULL_TREE, NULL_TREE, label);
append_to_statement_list (c, &stmt_list);
@@ -2309,7 +2283,7 @@ Gcc_backend::switch_statement (Bfunction *function, tree value,
if (*ps != NULL)
{
- tree t = (*ps)->get_tree ();
+ tree t = (*ps);
if (t == error_mark_node)
return this->error_statement ();
append_to_statement_list (t, &stmt_list);
@@ -2322,20 +2296,20 @@ Gcc_backend::switch_statement (Bfunction *function, tree value,
return this->error_statement ();
tree t = build2_loc (switch_location.gcc_location (), SWITCH_EXPR, NULL_TREE,
tv, stmt_list);
- return this->make_statement (t);
+ return t;
}
// Pair of statements.
-Bstatement *
-Gcc_backend::compound_statement (Bstatement *s1, Bstatement *s2)
+tree
+Gcc_backend::compound_statement (tree s1, tree s2)
{
tree stmt_list = NULL_TREE;
- tree t = s1->get_tree ();
+ tree t = s1;
if (t == error_mark_node)
return this->error_statement ();
append_to_statement_list (t, &stmt_list);
- t = s2->get_tree ();
+ t = s2;
if (t == error_mark_node)
return this->error_statement ();
append_to_statement_list (t, &stmt_list);
@@ -2345,24 +2319,24 @@ Gcc_backend::compound_statement (Bstatement *s1, Bstatement *s2)
if (stmt_list == NULL_TREE)
stmt_list = integer_zero_node;
- return this->make_statement (stmt_list);
+ return stmt_list;
}
// List of statements.
-Bstatement *
-Gcc_backend::statement_list (const std::vector<Bstatement *> &statements)
+tree
+Gcc_backend::statement_list (const std::vector<tree> &statements)
{
tree stmt_list = NULL_TREE;
- for (std::vector<Bstatement *>::const_iterator p = statements.begin ();
+ for (std::vector<tree>::const_iterator p = statements.begin ();
p != statements.end (); ++p)
{
- tree t = (*p)->get_tree ();
+ tree t = (*p);
if (t == error_mark_node)
return this->error_statement ();
append_to_statement_list (t, &stmt_list);
}
- return this->make_statement (stmt_list);
+ return stmt_list;
}
// Make a block. For some reason gcc uses a dual structure for
@@ -2436,13 +2410,13 @@ Gcc_backend::block (Bfunction *function, Bblock *enclosing,
void
Gcc_backend::block_add_statements (Bblock *bblock,
- const std::vector<Bstatement *> &statements)
+ const std::vector<tree> &statements)
{
tree stmt_list = NULL_TREE;
- for (std::vector<Bstatement *>::const_iterator p = statements.begin ();
+ for (std::vector<tree>::const_iterator p = statements.begin ();
p != statements.end (); ++p)
{
- tree s = (*p)->get_tree ();
+ tree s = (*p);
if (s != error_mark_node)
append_to_statement_list (s, &stmt_list);
}
@@ -2454,12 +2428,12 @@ Gcc_backend::block_add_statements (Bblock *bblock,
// Return a block as a statement.
-Bstatement *
+tree
Gcc_backend::block_statement (Bblock *bblock)
{
tree bind_tree = bblock->get_tree ();
gcc_assert (TREE_CODE (bind_tree) == BIND_EXPR);
- return this->make_statement (bind_tree);
+ return bind_tree;
}
// This is not static because we declare it with GTY(()) in rust-c.h.
@@ -2706,7 +2680,7 @@ Bvariable *
Gcc_backend::temporary_variable (Bfunction *function, Bblock *bblock,
tree type_tree, tree init_tree,
bool is_address_taken, Location location,
- Bstatement **pstatement)
+ tree *pstatement)
{
gcc_assert (function != NULL);
tree decl = function->get_tree ();
@@ -2756,8 +2730,8 @@ Gcc_backend::temporary_variable (Bfunction *function, Bblock *bblock,
if (is_address_taken)
TREE_ADDRESSABLE (var) = 1;
- *pstatement = this->make_statement (
- build1_loc (location.gcc_location (), DECL_EXPR, void_type_node, var));
+ *pstatement
+ = build1_loc (location.gcc_location (), DECL_EXPR, void_type_node, var);
// For a zero sized type, don't initialize VAR with BINIT, but still
// evaluate BINIT for its side effects.
@@ -3004,24 +2978,22 @@ Gcc_backend::label (Bfunction *function, const std::string &name,
// Make a statement which defines a label.
-Bstatement *
+tree
Gcc_backend::label_definition_statement (Blabel *label)
{
tree lab = label->get_tree ();
- tree ret = fold_build1_loc (DECL_SOURCE_LOCATION (lab), LABEL_EXPR,
- void_type_node, lab);
- return this->make_statement (ret);
+ return fold_build1_loc (DECL_SOURCE_LOCATION (lab), LABEL_EXPR,
+ void_type_node, lab);
}
// Make a goto statement.
-Bstatement *
+tree
Gcc_backend::goto_statement (Blabel *label, Location location)
{
tree lab = label->get_tree ();
- tree ret = fold_build1_loc (location.gcc_location (), GOTO_EXPR,
- void_type_node, lab);
- return this->make_statement (ret);
+ return fold_build1_loc (location.gcc_location (), GOTO_EXPR, void_type_node,
+ lab);
}
// Get the address of a label.
@@ -3097,7 +3069,7 @@ Gcc_backend::function (tree functype, const std::string &name,
// finish:
// try { UNDEFER; } catch { CHECK_DEFER; goto finish; }
-Bstatement *
+tree
Gcc_backend::function_defer_statement (Bfunction *function, tree undefer_tree,
tree defer_tree, Location location)
{
@@ -3114,19 +3086,19 @@ Gcc_backend::function_defer_statement (Bfunction *function, tree undefer_tree,
tree stmt_list = NULL;
Blabel *blabel = this->label (function, "", location);
- Bstatement *label_def = this->label_definition_statement (blabel);
- append_to_statement_list (label_def->get_tree (), &stmt_list);
+ tree label_def = this->label_definition_statement (blabel);
+ append_to_statement_list (label_def, &stmt_list);
- Bstatement *jump_stmt = this->goto_statement (blabel, location);
- tree jump = jump_stmt->get_tree ();
- tree catch_body = build2 (COMPOUND_EXPR, void_type_node, defer_tree, jump);
+ tree jump_stmt = this->goto_statement (blabel, location);
+ tree catch_body
+ = build2 (COMPOUND_EXPR, void_type_node, defer_tree, jump_stmt);
catch_body = build2 (CATCH_EXPR, void_type_node, NULL, catch_body);
tree try_catch
= build2 (TRY_CATCH_EXPR, void_type_node, undefer_tree, catch_body);
append_to_statement_list (try_catch, &stmt_list);
pop_cfun ();
- return this->make_statement (stmt_list);
+ return stmt_list;
}
// Record PARAM_VARS as the variables to use for the parameters of FUNCTION.
@@ -3157,14 +3129,13 @@ Gcc_backend::function_set_parameters (
// Set the function body for FUNCTION using the code in CODE_BLOCK.
bool
-Gcc_backend::function_set_body (Bfunction *function, Bstatement *code_stmt)
+Gcc_backend::function_set_body (Bfunction *function, tree code_stmt)
{
tree func_tree = function->get_tree ();
- tree code = code_stmt->get_tree ();
- if (func_tree == error_mark_node || code == error_mark_node)
+ if (func_tree == error_mark_node || code_stmt == error_mark_node)
return false;
- DECL_SAVED_TREE (func_tree) = code;
+ DECL_SAVED_TREE (func_tree) = code_stmt;
return true;
}