]> git.tdb.fi Git - libs/gl.git/commitdiff
Inline functions in variable initialization expressions
authorMikko Rasa <tdb@tdb.fi>
Tue, 28 May 2019 08:59:45 +0000 (11:59 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 28 May 2019 08:59:45 +0000 (11:59 +0300)
If the entire expression was a function call, it didn't get inlined
because VariableDeclaration wasn't being handled separately.

source/programcompiler.cpp
source/programcompiler.h

index afb2a3c32ecac3465cfe8620e74f816beeb84473..5a17a9ed3857bf969005e57a73ebe94d01b9ec20 100644 (file)
@@ -1223,6 +1223,13 @@ void ProgramCompiler::FunctionInliner::visit(FunctionCall &call)
                inline_result = 0;
 }
 
+void ProgramCompiler::FunctionInliner::visit(VariableDeclaration &var)
+{
+       if(var.init_expression)
+               visit_and_inline(var.init_expression);
+       inline_result = 0;
+}
+
 void ProgramCompiler::FunctionInliner::visit(Return &ret)
 {
        TraversingVisitor::visit(ret);
index 1258bde00ce0cbc8b9f45326377e9fe7524d7af7..06306743fb7945b5f2783c70663bf11ff4a04828 100644 (file)
@@ -218,6 +218,7 @@ private:
                virtual void visit(ProgramSyntax::BinaryExpression &);
                virtual void visit(ProgramSyntax::MemberAccess &);
                virtual void visit(ProgramSyntax::FunctionCall &);
+               virtual void visit(ProgramSyntax::VariableDeclaration &);
                virtual void visit(ProgramSyntax::Return &);
        };