From b46240b2f476c0194f8b25b24d8343128d889832 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Wed, 1 Feb 2012 21:36:05 +1000 Subject: Track event handlers differently from functions. --- LuaSL/src/LuaSL_LSL_tree.h | 2 ++ LuaSL/src/LuaSL_compile.c | 24 +++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'LuaSL') diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index d877f22..87d1af0 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h @@ -372,6 +372,7 @@ typedef struct FILE *file; LSL_Leaf *ast; LSL_Script script; + LSL_State state; #if LUASL_DIFF_CHECK Eina_Strbuf *ignorable; #endif @@ -381,6 +382,7 @@ typedef struct Eina_Clist danglingCalls; // HEAD for function calls used before the function is defined. int column, line; int undeclared; + boolean inState; } LuaSL_compiler; diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index a438a63..9c86f97 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c @@ -566,7 +566,10 @@ LSL_Leaf *addFunction(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identi } else identifier->basicType = OT_nothing; - eina_hash_add(compiler->script.functions, func->name.text, identifier); + if (compiler->inState) + eina_hash_add(compiler->state.handlers, func->name.text, func); + else + eina_hash_add(compiler->script.functions, func->name.text, identifier); #if LUASL_DIFF_CHECK // func->params = addParenthesis(open, params, LSL_PARAMETER_LIST, close); #endif @@ -698,6 +701,9 @@ LSL_Leaf *addState(LuaSL_compiler *compiler, LSL_Leaf *state, LSL_Leaf *identifi if ((identifier) && (result)) { + memcpy(result, &(compiler->state), sizeof(LSL_State)); + compiler->state.block = NULL; + compiler->state.handlers = NULL; result->name.text = identifier->value.stringValue; #if LUASL_DIFF_CHECK result->name.ignorable = identifier->ignorable; @@ -715,6 +721,7 @@ LSL_Leaf *addState(LuaSL_compiler *compiler, LSL_Leaf *state, LSL_Leaf *identifi identifier->value.stateValue = result; identifier->toKen = tokens[LSL_STATE - lowestToken]; eina_hash_add(compiler->script.states, result->name.text, identifier); + compiler->inState = FALSE; } return identifier; @@ -859,8 +866,13 @@ LSL_Leaf *collectStatements(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf * if (statement) { if (!wasNull) - list->value.blockValue = compiler->currentBlock; // Maybe NULL. - if (list->value.blockValue) + list->value.blockValue = compiler->currentBlock; // Maybe NULL. + + if ((compiler->inState) && (LSL_FUNCTION == statement->value.statementValue->type)) + { + eina_clist_add_tail(&(compiler->state.block->statements), &(statement->value.statementValue->statement)); + } + else if (list->value.blockValue) { eina_clist_add_tail(&(list->value.blockValue->statements), &(statement->value.statementValue->statement)); } @@ -928,6 +940,12 @@ LSL_Leaf *beginBlock(LuaSL_compiler *compiler, LSL_Leaf *block) eina_clist_init(&(blok->statements)); blok->variables = eina_hash_stringshared_new(burnLeaf); block->value.blockValue = blok; + if ((NULL == compiler->currentBlock) && (NULL == compiler->currentFunction)) + { + compiler->inState = TRUE; + compiler->state.block=blok; + compiler->state.handlers = eina_hash_stringshared_new(free); + } blok->outerBlock = compiler->currentBlock; compiler->currentBlock = blok; blok->function = compiler->currentFunction; -- cgit v1.1