From 55a0cfca1f42acbf5b4c5b7aa7c070eb02975d50 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sat, 21 Jan 2012 19:15:41 +1000 Subject: Second part of the second pass to clean up functions used before they where declared. Way too easy. B-) --- LuaSL/src/LuaSL_compile.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index a410152..5a3a68b 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c @@ -338,6 +338,7 @@ LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, lType = left->basicType; if (OT_undeclared == lType) { + PW("Undeclared identifier issue, deferring this until the second pass. @ line %d, column %d.", lval->line, lval->column); lval->basicType = OT_undeclared; return lval; } @@ -359,6 +360,7 @@ LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, rType = right->basicType; if (OT_undeclared == rType) { + PW("Undeclared identifier issue, deferring this until the second pass. @ line %d, column %d.", lval->line, lval->column); lval->basicType = OT_undeclared; return lval; } @@ -707,6 +709,17 @@ void endBlock(LuaSL_compiler *compiler, LSL_Leaf *block) compiler->currentBlock = compiler->currentBlock->outerBlock; } +static void secondPass(LuaSL_compiler *compiler, LSL_Leaf *leaf) +{ + if (leaf) + { + secondPass(compiler, leaf->left); + if (OT_undeclared == leaf->basicType) + leaf = addOperation(compiler, leaf->left, leaf, leaf->right); + secondPass(compiler, leaf->right); + } +} + static LSL_Leaf *evaluateLeaf(LSL_Leaf *leaf, LSL_Leaf *left, LSL_Leaf *right) { LSL_Leaf *result = NULL; @@ -1291,7 +1304,7 @@ Eina_Bool compileLSL(gameGlobals *game, char *script, boolean doConstants) if (compiler.undeclared) { - PI("A second pass will be needed to check if functions where declared after they where used. To avoid this second pass, don't do that."); + PW("A second pass is needed to check if functions where used before they where declared. To avoid this second pass, don't do that."); if (eina_clist_count(&(compiler.danglingCalls))) { LSL_FunctionCall *call = NULL; @@ -1311,7 +1324,7 @@ Eina_Bool compileLSL(gameGlobals *game, char *script, boolean doConstants) PE("Undeclared function %s called @ line %d, column %d!", call->call->value.stringValue, call->call->line, call->call->column); } } -// TODO - Run through the expressions, cleaning up the function calls. + secondPass(&compiler, compiler.ast); PI("Second pass completed."); } -- cgit v1.1