From: Mikko Rasa Date: Tue, 28 May 2019 08:59:45 +0000 (+0300) Subject: Inline functions in variable initialization expressions X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=405c00de24374c282adb1116551a833b8130d76d;p=libs%2Fgl.git Inline functions in variable initialization expressions If the entire expression was a function call, it didn't get inlined because VariableDeclaration wasn't being handled separately. --- diff --git a/source/programcompiler.cpp b/source/programcompiler.cpp index afb2a3c3..5a17a9ed 100644 --- a/source/programcompiler.cpp +++ b/source/programcompiler.cpp @@ -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); diff --git a/source/programcompiler.h b/source/programcompiler.h index 1258bde0..06306743 100644 --- a/source/programcompiler.h +++ b/source/programcompiler.h @@ -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 &); };