From 1271b772038d1e01cfed35ea5c764ceedc9842f9 Mon Sep 17 00:00:00 2001 From: SimplyTheOther Date: Thu, 5 Nov 2020 22:27:44 +0800 Subject: Added more trait item stripping Fixed lack of AST:: prepending in rust-parse-impl.h - should prevent compilation error Fixed expr renaming in Method as_string, should prevent compile error Fixed issue with changing location accessibility for AST nodes Fixed rust-compile.cc not using get_locus() instead of .locus --- gcc/rust/backend/rust-compile.cc | 86 ++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 43 deletions(-) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index 6374a45..af0f454 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -173,10 +173,10 @@ Compilation::visit (AST::IdentifierExpr &ident_expr) Bvariable *var = NULL; if (!scope.LookupVar (ident_expr.as_string (), &var)) { - rust_fatal_error (ident_expr.locus, "unknown var"); + rust_fatal_error (ident_expr.get_locus (), "unknown var"); return; } - exprs.push_back (backend->var_expression (var, ident_expr.locus)); + exprs.push_back (backend->var_expression (var, ident_expr.get_locus ())); } void @@ -199,7 +199,7 @@ Compilation::visit (AST::PathInExpression &path) if (scope.LookupFunction (path.as_string (), &fn)) { auto expr - = backend->function_code_expression (fn, path.get_locus_slow ()); + = backend->function_code_expression (fn, path.get_locus ()); exprs.push_back (expr); translatedType = scope.GetFnRetType (fn); return; @@ -221,14 +221,14 @@ Compilation::visit (AST::TypePath &path) { if (path.segments.size () > 1) { - rust_error_at (path.locus, "unable to compile multi segment types yet"); + rust_error_at (path.get_locus (), "unable to compile multi segment types yet"); return; } Btype *type = NULL; if (!scope.LookupType (path.as_string (), &type)) { - rust_error_at (path.locus, "unknown type"); + rust_error_at (path.get_locus (), "unknown type"); return; } translatedType = type; @@ -254,16 +254,16 @@ Compilation::visit (AST::LiteralExpr &expr) case AST::Literal::FLOAT: compiled - = compileFloatLiteral (expr.as_string (), expr.get_locus_slow ()); + = compileFloatLiteral (expr.as_string (), expr.get_locus ()); break; case AST::Literal::INT: compiled - = compileIntegerLiteral (expr.as_string (), expr.get_locus_slow ()); + = compileIntegerLiteral (expr.as_string (), expr.get_locus ()); break; default: - rust_fatal_error (expr.get_locus_slow (), "unknown literal"); + rust_fatal_error (expr.get_locus (), "unknown literal"); return; } @@ -311,11 +311,11 @@ Compilation::visit (AST::NegationExpr &expr) op = OPERATOR_NOT; break; default: - rust_fatal_error (expr.get_locus_slow (), "failed to compile operator"); + rust_fatal_error (expr.get_locus (), "failed to compile operator"); return; } - auto unary = backend->unary_expression (op, root, expr.get_locus_slow ()); + auto unary = backend->unary_expression (op, root, expr.get_locus ()); exprs.push_back (unary); } @@ -372,12 +372,12 @@ Compilation::visit (AST::ArithmeticOrLogicalExpr &expr) op = OPERATOR_RSHIFT; break; default: - rust_fatal_error (expr.get_locus_slow (), "failed to compile operator"); + rust_fatal_error (expr.get_locus (), "failed to compile operator"); return; } auto binExpr - = backend->binary_expression (op, lhs, rhs, expr.get_locus_slow ()); + = backend->binary_expression (op, lhs, rhs, expr.get_locus ()); exprs.push_back (binExpr); } @@ -422,12 +422,12 @@ Compilation::visit (AST::ComparisonExpr &expr) op = OPERATOR_LE; break; default: - rust_fatal_error (expr.get_locus_slow (), "failed to compile operator"); + rust_fatal_error (expr.get_locus (), "failed to compile operator"); return; } auto compExpr - = backend->binary_expression (op, lhs, rhs, expr.get_locus_slow ()); + = backend->binary_expression (op, lhs, rhs, expr.get_locus ()); exprs.push_back (compExpr); } @@ -460,12 +460,12 @@ Compilation::visit (AST::LazyBooleanExpr &expr) op = OPERATOR_ANDAND; break; default: - rust_fatal_error (expr.get_locus_slow (), "failed to compile operator"); + rust_fatal_error (expr.get_locus (), "failed to compile operator"); return; } auto compExpr - = backend->binary_expression (op, lhs, rhs, expr.get_locus_slow ()); + = backend->binary_expression (op, lhs, rhs, expr.get_locus ()); exprs.push_back (compExpr); } @@ -493,7 +493,7 @@ Compilation::visit (AST::AssignmentExpr &expr) } auto s = backend->assignment_statement (scope.GetCurrentFndecl (), lhs, rhs, - expr.get_locus_slow ()); + expr.get_locus ()); scope.AddStatement (s); } @@ -582,14 +582,14 @@ Compilation::visit (AST::StructExprStructFields &expr) AST::StructStruct *decl = NULL; if (!scope.LookupStructDecl (expr.get_struct_name ().as_string (), &decl)) { - rust_error_at (expr.get_locus_slow (), "unknown type"); + rust_error_at (expr.get_locus (), "unknown type"); return; } Btype *structType = NULL; if (!scope.LookupType (expr.get_struct_name ().as_string (), &structType)) { - rust_fatal_error (expr.get_locus_slow (), "unknown type"); + rust_fatal_error (expr.get_locus (), "unknown type"); return; } @@ -601,10 +601,10 @@ Compilation::visit (AST::StructExprStructFields &expr) for (auto &field : expr.fields) { Bexpression *value = NULL; - VISIT_POP (expr.get_locus_slow (), field, value, exprs); + VISIT_POP (expr.get_locus (), field, value, exprs); if (value == NULL) { - rust_fatal_error (expr.get_locus_slow (), + rust_fatal_error (expr.get_locus (), "failed to compile value to struct"); return; } @@ -614,7 +614,7 @@ Compilation::visit (AST::StructExprStructFields &expr) structBuffer.pop_back (); auto cons = backend->constructor_expression (structType, constructor, - expr.get_locus_slow ()); + expr.get_locus ()); exprs.push_back (cons); } @@ -674,7 +674,7 @@ Compilation::visit (AST::CallExpr &expr) } auto call = backend->call_expression (scope.GetCurrentFndecl (), fn, args, - NULL, expr.locus); + NULL, expr.get_locus ()); exprs.push_back (call); } @@ -751,7 +751,7 @@ Compilation::visit (AST::ReturnExpr &expr) std::vector retstmts; retstmts.push_back (ret); auto s = backend->return_statement (scope.GetCurrentFndecl (), retstmts, - expr.locus); + expr.get_locus ()); scope.AddStatement (s); } @@ -791,7 +791,7 @@ Compilation::visit (AST::IfExpr &expr) Bblock *then_block = scope.PopBlock (); auto stmt = backend->if_statement (scope.GetCurrentFndecl (), cond, - then_block, NULL, expr.get_locus_slow ()); + then_block, NULL, expr.get_locus ()); stmts.push_back (stmt); } @@ -816,7 +816,7 @@ Compilation::visit (AST::IfExprConseqElse &expr) auto stmt = backend->if_statement (scope.GetCurrentFndecl (), cond, then_block, - else_block, expr.get_locus_slow ()); + else_block, expr.get_locus ()); stmts.push_back (stmt); } @@ -856,7 +856,7 @@ Compilation::visit (AST::IfExprConseqIf &expr) auto stmt = backend->if_statement (scope.GetCurrentFndecl (), cond, then_block, - else_block, expr.get_locus_slow ()); + else_block, expr.get_locus ()); stmts.push_back (stmt); } @@ -956,7 +956,7 @@ Compilation::visit (AST::Function &function) param.type->accept_vis (*this); if (translatedType == NULL) { - rust_error_at (param.locus, "failed to generate type for parameter"); + rust_error_at (param.get_locus (), "failed to generate type for parameter"); return; } @@ -964,7 +964,7 @@ Compilation::visit (AST::Function &function) param.param_name->accept_vis (*this); if (patternBuffer.size () <= before) { - rust_error_at (param.locus, "failed to analyse parameter name"); + rust_error_at (param.get_locus (), "failed to analyse parameter name"); return; } @@ -975,7 +975,7 @@ Compilation::visit (AST::Function &function) patternBuffer.pop_back (); parameters.push_back ( Backend::Btyped_identifier (paramName.variable_ident, - translatedType, param.locus)); + translatedType, param.get_locus ())); } } @@ -986,7 +986,7 @@ Compilation::visit (AST::Function &function) function.return_type->accept_vis (*this); if (translatedType == NULL) { - rust_fatal_error (function.locus, + rust_fatal_error (function.get_locus (), "failed to generate type for function"); return; } @@ -998,10 +998,10 @@ Compilation::visit (AST::Function &function) } Btype *fntype = backend->function_type (receiver, parameters, results, NULL, - function.locus); + function.get_locus ()); Bfunction *fndecl = backend->function (fntype, function.function_name, "" /* asm_name */, - 0 /* flags */, function.locus); + 0 /* flags */, function.get_locus ()); scope.InsertFunction (function.function_name, fndecl, returnType); scope.Push (); @@ -1020,7 +1020,7 @@ Compilation::visit (AST::Function &function) if (!backend->function_set_parameters (fndecl, param_vars)) { - rust_error_at (function.locus, "failed to setup parameter variables"); + rust_error_at (function.get_locus (), "failed to setup parameter variables"); return; } @@ -1029,7 +1029,7 @@ Compilation::visit (AST::Function &function) { if (!compileVarDecl (fndecl, decl, vars)) { - rust_error_at (decl->locus, "failed to compile var decl"); + rust_error_at (decl->get_locus (), "failed to compile var decl"); return; } } @@ -1037,7 +1037,7 @@ Compilation::visit (AST::Function &function) // is null for top level functions - nested functions will have an enclosing // scope Bblock *enclosingScope = NULL; - Location start_location = function.locus; + Location start_location = function.get_locus (); Location end_location; if (function.function_body->statements.size () > 0) { @@ -1057,7 +1057,7 @@ Compilation::visit (AST::Function &function) Bstatement *ret_var_stmt = NULL; retDecl = backend->temporary_variable (fndecl, code_block, returnType, NULL, address_is_taken, - function.locus, &ret_var_stmt); + function.get_locus (), &ret_var_stmt); scope.AddStatement (ret_var_stmt); } scope.PushCurrentFunction (function.function_name, fndecl, returnType, @@ -1071,7 +1071,7 @@ Compilation::visit (AST::Function &function) auto body = backend->block_statement (code_block); if (!backend->function_set_body (fndecl, body)) { - rust_error_at (function.locus, "failed to set body to function"); + rust_error_at (function.get_locus (), "failed to set body to function"); return; } @@ -1096,23 +1096,23 @@ Compilation::visit (AST::StructStruct &struct_item) if (translatedType == NULL) { rust_fatal_error ( - struct_item.locus /* StructField is mi sing locus */, + struct_item.get_locus () /* StructField is mi sing locus */, "failed to compile struct field"); return; } fields.push_back (Backend::Btyped_identifier ( field.field_name, translatedType, - struct_item.locus /* StructField is mi sing locus */)); + struct_item.get_locus () /* StructField is mi sing locus */)); } auto compiledStruct = backend->placeholder_struct_type (struct_item.struct_name, - struct_item.locus); + struct_item.get_locus ()); bool ok = backend->set_placeholder_struct_type (compiledStruct, fields); if (!ok) { - rust_fatal_error (struct_item.locus, "failed to compile struct"); + rust_fatal_error (struct_item.get_locus (), "failed to compile struct"); return; } @@ -1304,7 +1304,7 @@ Compilation::visit (AST::LetStmt &stmt) Bvariable *var = NULL; if (!scope.LookupVar (pattern.variable_ident, &var)) { - rust_error_at (stmt.locus, "failed to find var decl for %s", + rust_error_at (stmt.get_locus (), "failed to find var decl for %s", pattern.variable_ident.c_str ()); return; } -- cgit v1.1 From 37bbf2b8cbd4578f0fbe7cbbd573493481f62a45 Mon Sep 17 00:00:00 2001 From: SimplyTheOther Date: Tue, 10 Nov 2020 12:22:20 +0800 Subject: Added cfg stripping for some expressions Attempt to fix compile error --- gcc/rust/backend/rust-compile.cc | 50 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index af0f454..0589347 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -246,7 +246,7 @@ void Compilation::visit (AST::LiteralExpr &expr) { Bexpression *compiled; - switch (expr.literal.get_lit_type ()) + switch (expr.get_lit_type ()) { case AST::Literal::BOOL: compiled = compileBooleanLiteral (expr.as_string ()); @@ -293,16 +293,16 @@ void Compilation::visit (AST::NegationExpr &expr) { Bexpression *root = NULL; - VISIT_POP (expr.get_expr ()->get_locus_slow (), expr.get_expr (), root, + VISIT_POP (expr.get_negated_expr ()->get_locus_slow (), expr.get_negated_expr ().get (), root, exprs); if (root == NULL) { - rust_error_at (expr.get_expr ()->get_locus_slow (), "failed to compile"); + rust_error_at (expr.get_negated_expr ()->get_locus_slow (), "failed to compile"); return; } Operator op; - switch (expr.negation_type) + switch (expr.get_negation_type ()) { case AST::NegationExpr::NEGATE: op = OPERATOR_MINUS; @@ -323,23 +323,23 @@ void Compilation::visit (AST::ArithmeticOrLogicalExpr &expr) { Bexpression *lhs = NULL; - VISIT_POP (expr.get_lhs ()->get_locus_slow (), expr.get_lhs (), lhs, exprs); + VISIT_POP (expr.get_left_expr ()->get_locus_slow (), expr.get_left_expr ().get (), lhs, exprs); if (lhs == NULL) { - rust_error_at (expr.get_lhs ()->get_locus_slow (), "failed to compile"); + rust_error_at (expr.get_left_expr ()->get_locus_slow (), "failed to compile"); return; } Bexpression *rhs = NULL; - VISIT_POP (expr.right_expr->get_locus_slow (), expr.right_expr, rhs, exprs); + VISIT_POP (expr.get_right_expr ()->get_locus_slow (), expr.get_right_expr ().get (), rhs, exprs); if (rhs == NULL) { - rust_error_at (expr.right_expr->get_locus_slow (), "failed to compile"); + rust_error_at (expr.get_right_expr ()->get_locus_slow (), "failed to compile"); return; } Operator op; - switch (expr.expr_type) + switch (expr.get_expr_type ()) { case AST::ArithmeticOrLogicalExpr::ADD: op = OPERATOR_PLUS; @@ -385,23 +385,23 @@ void Compilation::visit (AST::ComparisonExpr &expr) { Bexpression *lhs = NULL; - VISIT_POP (expr.get_lhs ()->get_locus_slow (), expr.get_lhs (), lhs, exprs); + VISIT_POP (expr.get_left_expr ()->get_locus_slow (), expr.get_left_expr ().get (), lhs, exprs); if (lhs == NULL) { - rust_error_at (expr.get_lhs ()->get_locus_slow (), "failed to compile"); + rust_error_at (expr.get_left_expr ()->get_locus_slow (), "failed to compile"); return; } Bexpression *rhs = NULL; - VISIT_POP (expr.right_expr->get_locus_slow (), expr.right_expr, rhs, exprs); + VISIT_POP (expr.get_right_expr ()->get_locus_slow (), expr.get_right_expr ().get (), rhs, exprs); if (rhs == NULL) { - rust_error_at (expr.right_expr->get_locus_slow (), "failed to compile"); + rust_error_at (expr.get_right_expr ()->get_locus_slow (), "failed to compile"); return; } Operator op; - switch (expr.expr_type) + switch (expr.get_expr_type ()) { case AST::ComparisonExpr::EQUAL: op = OPERATOR_EQEQ; @@ -435,23 +435,23 @@ void Compilation::visit (AST::LazyBooleanExpr &expr) { Bexpression *lhs = NULL; - VISIT_POP (expr.get_lhs ()->get_locus_slow (), expr.get_lhs (), lhs, exprs); + VISIT_POP (expr.get_left_expr ()->get_locus_slow (), expr.get_left_expr ().get (), lhs, exprs); if (lhs == NULL) { - rust_error_at (expr.get_lhs ()->get_locus_slow (), "failed to compile"); + rust_error_at (expr.get_left_expr ()->get_locus_slow (), "failed to compile"); return; } Bexpression *rhs = NULL; - VISIT_POP (expr.right_expr->get_locus_slow (), expr.right_expr, rhs, exprs); + VISIT_POP (expr.get_right_expr ()->get_locus_slow (), expr.get_right_expr ().get (), rhs, exprs); if (rhs == NULL) { - rust_error_at (expr.right_expr->get_locus_slow (), "failed to compile"); + rust_error_at (expr.get_right_expr ()->get_locus_slow (), "failed to compile"); return; } Operator op; - switch (expr.expr_type) + switch (expr.get_expr_type ()) { case AST::LazyBooleanExpr::LOGICAL_OR: op = OPERATOR_OROR; @@ -477,18 +477,18 @@ void Compilation::visit (AST::AssignmentExpr &expr) { Bexpression *lhs = NULL; - VISIT_POP (expr.get_lhs ()->get_locus_slow (), expr.get_lhs (), lhs, exprs); + VISIT_POP (expr.get_left_expr ()->get_locus_slow (), expr.get_left_expr ().get (), lhs, exprs); if (lhs == NULL) { - rust_error_at (expr.get_lhs ()->get_locus_slow (), "failed to compile"); + rust_error_at (expr.get_left_expr ()->get_locus_slow (), "failed to compile"); return; } Bexpression *rhs = NULL; - VISIT_POP (expr.right_expr->get_locus_slow (), expr.right_expr, rhs, exprs); + VISIT_POP (expr.get_right_expr ()->get_locus_slow (), expr.get_right_expr ().get (), rhs, exprs); if (rhs == NULL) { - rust_error_at (expr.right_expr->get_locus_slow (), "failed to compile"); + rust_error_at (expr.get_right_expr ()->get_locus_slow (), "failed to compile"); return; } @@ -536,7 +536,7 @@ Compilation::visit (AST::StructExprFieldIdentifierValue &field) AST::StructStruct *decl = structBuffer.back (); size_t index = 0; bool found = false; - for (auto &df : decl->fields) + for (auto &df : decl->get_fields ()) { if (field.field_name.compare (df.field_name) == 0) { @@ -1089,7 +1089,7 @@ void Compilation::visit (AST::StructStruct &struct_item) { std::vector fields; - for (auto &field : struct_item.fields) + for (auto &field : struct_item.get_fields ()) { translatedType = NULL; field.field_type->accept_vis (*this); -- cgit v1.1 From f5ae2781823b3a2bcded1ac3446de83cc52403a9 Mon Sep 17 00:00:00 2001 From: SimplyTheOther Date: Thu, 12 Nov 2020 22:22:41 +0800 Subject: Added more expression stripping Fixed compile errors and started on enum expr stripping --- gcc/rust/backend/rust-compile.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index 0589347..ca310ca 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -538,7 +538,7 @@ Compilation::visit (AST::StructExprFieldIdentifierValue &field) bool found = false; for (auto &df : decl->get_fields ()) { - if (field.field_name.compare (df.field_name) == 0) + if (field.get_field_name ().compare (df.field_name) == 0) { found = true; break; @@ -546,16 +546,16 @@ Compilation::visit (AST::StructExprFieldIdentifierValue &field) } if (!found) { - rust_fatal_error (field.value->get_locus_slow (), + rust_fatal_error (field.get_value ()->get_locus_slow (), "failed to lookup field index"); return; } Bexpression *value = NULL; - VISIT_POP (field.value->get_locus_slow (), field.value.get (), value, exprs); + VISIT_POP (field.get_value ()->get_locus_slow (), field.get_value ().get (), value, exprs); if (value == NULL) { - rust_fatal_error (field.value->get_locus_slow (), + rust_fatal_error (field.get_value ()->get_locus_slow (), "failed to compile value to struct"); return; } @@ -566,10 +566,10 @@ void Compilation::visit (AST::StructExprFieldIndexValue &field) { Bexpression *value = NULL; - VISIT_POP (field.value->get_locus_slow (), field.value.get (), value, exprs); + VISIT_POP (field.get_value ()->get_locus_slow (), field.get_value ().get (), value, exprs); if (value == NULL) { - rust_fatal_error (field.value->get_locus_slow (), + rust_fatal_error (field.get_value ()->get_locus_slow (), "failed to compile value to struct"); return; } @@ -598,7 +598,7 @@ Compilation::visit (AST::StructExprStructFields &expr) // FIXME type resolution pass should ensures these are in correct order // and have defaults if required - for (auto &field : expr.fields) + for (auto &field : expr.get_fields ()) { Bexpression *value = NULL; VISIT_POP (expr.get_locus (), field, value, exprs); @@ -1332,7 +1332,7 @@ Compilation::visit (AST::LetStmt &stmt) void Compilation::visit (AST::ExprStmtWithoutBlock &stmt) { - stmt.expr->accept_vis (*this); + stmt.get_expr ()->accept_vis (*this); } void @@ -1348,7 +1348,7 @@ Compilation::visit (AST::ExprStmtWithBlock &stmt) start_location, end_location); scope.PushBlock (code_block); - stmt.expr->accept_vis (*this); + stmt.get_expr ()->accept_vis (*this); // get trailing if required for (auto &s : stmts) -- cgit v1.1 From 25de39b1f0e307b0ff6de485d9ac5648e9295f3d Mon Sep 17 00:00:00 2001 From: SimplyTheOther Date: Sat, 14 Nov 2020 21:26:11 +0800 Subject: Added more expr stripping --- gcc/rust/backend/rust-compile.cc | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index ca310ca..12ce47f 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -538,7 +538,7 @@ Compilation::visit (AST::StructExprFieldIdentifierValue &field) bool found = false; for (auto &df : decl->get_fields ()) { - if (field.get_field_name ().compare (df.field_name) == 0) + if (field.get_field_name ().compare (df.get_field_name ()) == 0) { found = true; break; @@ -651,15 +651,15 @@ void Compilation::visit (AST::CallExpr &expr) { Bexpression *fn = NULL; - VISIT_POP (expr.function->get_locus_slow (), expr.function, fn, exprs); + VISIT_POP (expr.get_function_expr ()->get_locus_slow (), expr.get_function_expr (), fn, exprs); if (fn == NULL) { - rust_error_at (expr.function->get_locus_slow (), "failed to resolve"); + rust_error_at (expr.get_function_expr ()->get_locus_slow (), "failed to resolve"); return; } std::vector args; - for (auto ¶m : expr.params) + for (auto ¶m : expr.get_params ()) { Bexpression *arg = NULL; VISIT_POP (param->get_locus_slow (), param, arg, exprs); @@ -949,7 +949,7 @@ Compilation::visit (AST::Function &function) std::vector parameters; std::vector results; - for (auto ¶m : function.function_params) + for (auto ¶m : function.get_function_params ()) { // translate the type translatedType = NULL; @@ -983,7 +983,7 @@ Compilation::visit (AST::Function &function) if (function.has_function_return_type ()) { translatedType = NULL; - function.return_type->accept_vis (*this); + function.get_return_type ()->accept_vis (*this); if (translatedType == NULL) { rust_fatal_error (function.get_locus (), @@ -1000,10 +1000,10 @@ Compilation::visit (AST::Function &function) Btype *fntype = backend->function_type (receiver, parameters, results, NULL, function.get_locus ()); Bfunction *fndecl - = backend->function (fntype, function.function_name, "" /* asm_name */, + = backend->function (fntype, function.get_function_name (), "" /* asm_name */, 0 /* flags */, function.get_locus ()); - scope.InsertFunction (function.function_name, fndecl, returnType); + scope.InsertFunction (function.get_function_name (), fndecl, returnType); scope.Push (); // setup the params @@ -1039,10 +1039,10 @@ Compilation::visit (AST::Function &function) Bblock *enclosingScope = NULL; Location start_location = function.get_locus (); Location end_location; - if (function.function_body->statements.size () > 0) + if (function.get_definition ()->statements.size () > 0) { end_location - = function.function_body->statements.back ()->get_locus_slow (); + = function.get_definition ()->statements.back ()->get_locus_slow (); } auto code_block = backend->block (fndecl, enclosingScope, vars, @@ -1060,10 +1060,10 @@ Compilation::visit (AST::Function &function) function.get_locus (), &ret_var_stmt); scope.AddStatement (ret_var_stmt); } - scope.PushCurrentFunction (function.function_name, fndecl, returnType, + scope.PushCurrentFunction (function.get_function_name (), fndecl, returnType, retDecl); - for (auto &stmt : function.function_body->statements) + for (auto &stmt : function.get_definition ()->statements) stmt->accept_vis (*this); scope.PopBlock (); @@ -1092,7 +1092,7 @@ Compilation::visit (AST::StructStruct &struct_item) for (auto &field : struct_item.get_fields ()) { translatedType = NULL; - field.field_type->accept_vis (*this); + field.get_field_type ()->accept_vis (*this); if (translatedType == NULL) { rust_fatal_error ( @@ -1102,12 +1102,12 @@ Compilation::visit (AST::StructStruct &struct_item) } fields.push_back (Backend::Btyped_identifier ( - field.field_name, translatedType, + field.get_field_name (), translatedType, struct_item.get_locus () /* StructField is mi sing locus */)); } auto compiledStruct - = backend->placeholder_struct_type (struct_item.struct_name, + = backend->placeholder_struct_type (struct_item.get_struct_name (), struct_item.get_locus ()); bool ok = backend->set_placeholder_struct_type (compiledStruct, fields); if (!ok) @@ -1117,8 +1117,8 @@ Compilation::visit (AST::StructStruct &struct_item) } type_decls.push_back (compiledStruct); - scope.InsertType (struct_item.struct_name, compiledStruct); - scope.InsertStructDecl (struct_item.struct_name, &struct_item); + scope.InsertType (struct_item.get_struct_name (), compiledStruct); + scope.InsertStructDecl (struct_item.get_struct_name (), &struct_item); } void -- cgit v1.1 From 4ec3b8d62b1b6ae79d55b71b423dcb04129884c6 Mon Sep 17 00:00:00 2001 From: SimplyTheOther Date: Sun, 15 Nov 2020 22:18:49 +0800 Subject: Added more expr cfg stripping Fixed compile errors Fixed compile errors relating to block expr visibility changes --- gcc/rust/backend/rust-compile.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index 12ce47f..17d9cde 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -701,7 +701,7 @@ Compilation::visit (AST::BlockExpr &expr) start_location, end_location); scope.PushBlock (code_block); - for (auto &stmt : expr.statements) + for (auto &stmt : expr.get_statements ()) { stmt->accept_vis (*this); } @@ -1039,10 +1039,10 @@ Compilation::visit (AST::Function &function) Bblock *enclosingScope = NULL; Location start_location = function.get_locus (); Location end_location; - if (function.get_definition ()->statements.size () > 0) + if (function.get_definition ()->get_statements ().size () > 0) { end_location - = function.get_definition ()->statements.back ()->get_locus_slow (); + = function.get_definition ()->get_statements ().back ()->get_locus_slow (); } auto code_block = backend->block (fndecl, enclosingScope, vars, @@ -1063,7 +1063,7 @@ Compilation::visit (AST::Function &function) scope.PushCurrentFunction (function.get_function_name (), fndecl, returnType, retDecl); - for (auto &stmt : function.get_definition ()->statements) + for (auto &stmt : function.get_definition ()->get_statements ()) stmt->accept_vis (*this); scope.PopBlock (); -- cgit v1.1 From 9b252167a77316750f34c455222e5f30724e51e4 Mon Sep 17 00:00:00 2001 From: SimplyTheOther Date: Tue, 17 Nov 2020 22:00:30 +0800 Subject: Added more expression cfg stripping Fixed compile errors --- gcc/rust/backend/rust-compile.cc | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index 17d9cde..eb01b12 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -740,10 +740,10 @@ void Compilation::visit (AST::ReturnExpr &expr) { Bexpression *ret = NULL; - VISIT_POP (expr.return_expr->get_locus_slow (), expr.return_expr, ret, exprs); + VISIT_POP (expr.get_returned_expr ()->get_locus_slow (), expr.get_returned_expr ().get (), ret, exprs); if (ret == NULL) { - rust_fatal_error (expr.return_expr->get_locus_slow (), + rust_fatal_error (expr.get_returned_expr ()->get_locus_slow (), "failed to compile"); return; } @@ -778,11 +778,11 @@ void Compilation::visit (AST::IfExpr &expr) { Bexpression *cond = NULL; - VISIT_POP (expr.get_if_condition ()->get_locus_slow (), - expr.get_if_condition (), cond, exprs); + VISIT_POP (expr.get_condition_expr ()->get_locus_slow (), + expr.get_condition_expr ().get (), cond, exprs); if (cond == NULL) { - rust_error_at (expr.get_if_condition ()->get_locus_slow (), + rust_error_at (expr.get_condition_expr ()->get_locus_slow (), "failed to compile"); return; } @@ -799,11 +799,11 @@ void Compilation::visit (AST::IfExprConseqElse &expr) { Bexpression *cond = NULL; - VISIT_POP (expr.get_if_condition ()->get_locus_slow (), - expr.get_if_condition (), cond, exprs); + VISIT_POP (expr.get_condition_expr ()->get_locus_slow (), + expr.get_condition_expr ().get (), cond, exprs); if (cond == NULL) { - rust_error_at (expr.get_if_condition ()->get_locus_slow (), + rust_error_at (expr.get_condition_expr ()->get_locus_slow (), "failed to compile"); return; } @@ -824,11 +824,11 @@ void Compilation::visit (AST::IfExprConseqIf &expr) { Bexpression *cond = NULL; - VISIT_POP (expr.get_if_condition ()->get_locus_slow (), - expr.get_if_condition (), cond, exprs); + VISIT_POP (expr.get_condition_expr ()->get_locus_slow (), + expr.get_condition_expr ().get (), cond, exprs); if (cond == NULL) { - rust_error_at (expr.get_if_condition ()->get_locus_slow (), + rust_error_at (expr.get_condition_expr ()->get_locus_slow (), "failed to compile"); return; } -- cgit v1.1 From db39766514144dbbad34d9db3977c3a72d1216c3 Mon Sep 17 00:00:00 2001 From: SimplyTheOther Date: Sun, 29 Nov 2020 22:47:31 +0800 Subject: Added new pattern stripping Fixed get_locus_slow call in StructPatternField compile error Added and improved cfg stripping Fixed compilation errors --- gcc/rust/backend/rust-compile.cc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index eb01b12..d684c7d 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -100,11 +100,11 @@ Compilation::compileVarDecl (Bfunction *fndecl, AST::LetStmt *stmt, stmt->variables_pattern->accept_vis (*this); for (auto &pattern : patternBuffer) { - auto var = backend->local_variable (fndecl, pattern.variable_ident, + auto var = backend->local_variable (fndecl, pattern.get_ident (), translatedType, NULL /*decl_var*/, false /*address_taken*/, stmt->locus); vars.push_back (var); - scope.InsertVar (pattern.variable_ident, var); + scope.InsertVar (pattern.get_ident (), var); } patternBuffer.clear (); return true; @@ -219,7 +219,7 @@ Compilation::visit (AST::TypePathSegmentFunction &segment) void Compilation::visit (AST::TypePath &path) { - if (path.segments.size () > 1) + if (path.get_segments ().size () > 1) { rust_error_at (path.get_locus (), "unable to compile multi segment types yet"); return; @@ -953,7 +953,7 @@ Compilation::visit (AST::Function &function) { // translate the type translatedType = NULL; - param.type->accept_vis (*this); + param.get_type ()->accept_vis (*this); if (translatedType == NULL) { rust_error_at (param.get_locus (), "failed to generate type for parameter"); @@ -961,7 +961,7 @@ Compilation::visit (AST::Function &function) } auto before = patternBuffer.size (); - param.param_name->accept_vis (*this); + param.get_pattern ()->accept_vis (*this); if (patternBuffer.size () <= before) { rust_error_at (param.get_locus (), "failed to analyse parameter name"); @@ -974,13 +974,13 @@ Compilation::visit (AST::Function &function) auto paramName = patternBuffer.back (); patternBuffer.pop_back (); parameters.push_back ( - Backend::Btyped_identifier (paramName.variable_ident, + Backend::Btyped_identifier (paramName.get_ident (), translatedType, param.get_locus ())); } } Btype *returnType = NULL; - if (function.has_function_return_type ()) + if (function.has_return_type ()) { translatedType = NULL; function.get_return_type ()->accept_vis (*this); @@ -1051,7 +1051,7 @@ Compilation::visit (AST::Function &function) scope.PushBlock (code_block); Bvariable *retDecl = NULL; - if (function.has_function_return_type ()) + if (function.has_return_type ()) { bool address_is_taken = false; Bstatement *ret_var_stmt = NULL; @@ -1302,21 +1302,21 @@ Compilation::visit (AST::LetStmt &stmt) for (auto &pattern : patternBuffer) { Bvariable *var = NULL; - if (!scope.LookupVar (pattern.variable_ident, &var)) + if (!scope.LookupVar (pattern.get_ident (), &var)) { rust_error_at (stmt.get_locus (), "failed to find var decl for %s", - pattern.variable_ident.c_str ()); + pattern.get_ident ().c_str ()); return; } varBuffer.push_back (var); Bexpression *init = NULL; - VISIT_POP (stmt.init_expr->get_locus_slow (), stmt.init_expr, init, + VISIT_POP (stmt.get_init_expr ()->get_locus_slow (), stmt.get_init_expr (), init, exprs); if (init == NULL) { - rust_error_at (stmt.init_expr->get_locus_slow (), + rust_error_at (stmt.get_init_expr ()->get_locus_slow (), "failed to compile init statement"); return; } -- cgit v1.1 From c7080f178a637cad04e196a404d5d44bb33189af Mon Sep 17 00:00:00 2001 From: SimplyTheOther Date: Mon, 7 Dec 2020 19:51:24 +0800 Subject: Added more cfg stripping code --- gcc/rust/backend/rust-compile.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index d684c7d..3691f9e 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -88,21 +88,21 @@ bool Compilation::compileVarDecl (Bfunction *fndecl, AST::LetStmt *stmt, std::vector &vars) { - AST::Type *type = stmt->has_type () ? stmt->type.get () : stmt->inferedType; + AST::Type *type = stmt->has_type () ? stmt->get_type ().get () : stmt->inferedType; translatedType = NULL; type->accept_vis (*this); if (translatedType == NULL) { - rust_error_at (stmt->locus, "failed to compile type for var decl"); + rust_error_at (stmt->get_locus (), "failed to compile type for var decl"); return false; } - stmt->variables_pattern->accept_vis (*this); + stmt->get_pattern ()->accept_vis (*this); for (auto &pattern : patternBuffer) { auto var = backend->local_variable (fndecl, pattern.get_ident (), translatedType, NULL /*decl_var*/, - false /*address_taken*/, stmt->locus); + false /*address_taken*/, stmt->get_locus ()); vars.push_back (var); scope.InsertVar (pattern.get_ident (), var); } @@ -1298,7 +1298,7 @@ Compilation::visit (AST::LetStmt &stmt) if (!stmt.has_init_expr ()) return; - stmt.variables_pattern->accept_vis (*this); + stmt.get_pattern ()->accept_vis (*this); for (auto &pattern : patternBuffer) { Bvariable *var = NULL; -- cgit v1.1 From b343d117f5cf7976d3c4c93d9595e2471d780acd Mon Sep 17 00:00:00 2001 From: SimplyTheOther Date: Wed, 9 Dec 2020 16:01:35 +0800 Subject: Fixed rust-compile.cc compile error --- gcc/rust/backend/rust-compile.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index dd28759..300240f 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -550,7 +550,7 @@ Compilation::visit (AST::ArrayExpr &expr) translatedType = nullptr; auto before = arrayConsStack.size (); - expr.get_internal_elements ()->accept_vis (*this); + expr.get_array_elems ()->accept_vis (*this); if (arrayConsStack.size () <= before) { rust_error_at (expr.get_locus_slow (), @@ -1465,7 +1465,7 @@ Compilation::visit (AST::ArrayType &type) { Btype *elementType; translatedType = nullptr; - type.get_element_type ()->accept_vis (*this); + type.get_elem_type ()->accept_vis (*this); if (translatedType == nullptr) { rust_error_at (type.get_locus (), -- cgit v1.1