]> git.tdb.fi Git - libs/gl.git/commitdiff
Retain assignment location when moving out variables to global scope
authorMikko Rasa <tdb@tdb.fi>
Fri, 21 Jun 2019 12:13:27 +0000 (15:13 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 21 Jun 2019 12:13:27 +0000 (15:13 +0300)
source/programcompiler.cpp
source/programcompiler.h

index bb77e0ea911e205c192c68cd88462f6affdf1ff6..223392ffd4d1e21a4ac599405eba6b2bb1503aba 100644 (file)
@@ -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;
                        }
                }
index bea3faec1d0fee7552cb4cbd5fb36717dca8fb34..0bff354a50571128a0fa31bed3dbe8c935a0b1dc 100644 (file)
@@ -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 &);