From: Mikko Rasa Date: Fri, 21 Jun 2019 12:13:27 +0000 (+0300) Subject: Retain assignment location when moving out variables to global scope X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=6e528ad728ed93f2016bc9f4204a9d906576300e;p=libs%2Fgl.git Retain assignment location when moving out variables to global scope --- diff --git a/source/programcompiler.cpp b/source/programcompiler.cpp index bb77e0ea..223392ff 100644 --- a/source/programcompiler.cpp +++ b/source/programcompiler.cpp @@ -989,7 +989,7 @@ bool ProgramCompiler::InterfaceGenerator::generate_interface(VariableDeclaration return true; } -void ProgramCompiler::InterfaceGenerator::insert_assignment(const string &left, ProgramSyntax::Expression *right) +ExpressionStatement &ProgramCompiler::InterfaceGenerator::insert_assignment(const string &left, ProgramSyntax::Expression *right) { Assignment *assign = new Assignment; VariableReference *ref = new VariableReference; @@ -1002,6 +1002,8 @@ void ProgramCompiler::InterfaceGenerator::insert_assignment(const string &left, stmt->expression = assign; stmt->visit(*this); insert_nodes.push_back(stmt); + + return *stmt; } void ProgramCompiler::InterfaceGenerator::visit(VariableReference &var) @@ -1033,7 +1035,9 @@ void ProgramCompiler::InterfaceGenerator::visit(VariableDeclaration &var) remove_node = true; if(var.init_expression) { - insert_assignment(var.name, var.init_expression->clone()); + ExpressionStatement &stmt = insert_assignment(var.name, var.init_expression->clone()); + stmt.source = var.source; + stmt.line = var.line; return; } } diff --git a/source/programcompiler.h b/source/programcompiler.h index bea3faec..0bff354a 100644 --- a/source/programcompiler.h +++ b/source/programcompiler.h @@ -156,7 +156,7 @@ private: virtual void visit(ProgramSyntax::Block &); std::string change_prefix(const std::string &, const std::string &) const; bool generate_interface(ProgramSyntax::VariableDeclaration &, const std::string &, const std::string &); - void insert_assignment(const std::string &, ProgramSyntax::Expression *); + ProgramSyntax::ExpressionStatement &insert_assignment(const std::string &, ProgramSyntax::Expression *); virtual void visit(ProgramSyntax::VariableReference &); virtual void visit(ProgramSyntax::VariableDeclaration &); virtual void visit(ProgramSyntax::Passthrough &);