From 9b0ff54007aaaf4d838a29dc6f301ce28ab8cad9 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Tue, 31 Jan 2012 17:46:09 +1000 Subject: Collect and print function arguments. --- LuaSL/src/LuaSL_LSL_tree.h | 1 + LuaSL/src/LuaSL_compile.c | 57 ++++++++++++++++++++++++++++++++++++++---- LuaSL/src/LuaSL_lemon_yaccer.y | 6 ++--- 3 files changed, 56 insertions(+), 8 deletions(-) diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index d62c0b6..d877f22 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h @@ -405,6 +405,7 @@ LSL_Leaf *addVariable(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identi LSL_Leaf *beginBlock(LuaSL_compiler *compiler, LSL_Leaf *block); LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier); +LSL_Leaf *collectArguments(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *comma, LSL_Leaf *arg); LSL_Leaf *collectParameters(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *comma, LSL_Leaf *newParam); LSL_Leaf *collectStatements(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *newStatement); diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index f8310a6..d9ac1c3 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c @@ -580,7 +580,7 @@ LSL_Leaf *addFunction(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identi LSL_Leaf *addFunctionBody(LuaSL_compiler *compiler, LSL_Leaf *function, LSL_Leaf *block) { - LSL_Leaf *statement = NULL; + LSL_Leaf *statement = NULL; if (function) { @@ -591,10 +591,55 @@ LSL_Leaf *addFunctionBody(LuaSL_compiler *compiler, LSL_Leaf *function, LSL_Leaf return statement; } +LSL_Leaf *collectArguments(LuaSL_compiler *compiler, LSL_Leaf *list, LSL_Leaf *comma, LSL_Leaf *arg) +{ + LSL_FunctionCall *call = NULL; + + if (NULL == list) + list = newLeaf(LSL_FUNCTION_CALL, NULL, NULL); + + if (list) + { + call = list->value.functionCallValue; + if (NULL == call) + { + call = calloc(1, sizeof(LSL_FunctionCall)); + if (call) + { + list->value.functionCallValue = call; + eina_inarray_setup(&(call->params), sizeof(LSL_Leaf), 3); + } + } + + if (call) + { + if (arg) + { + if (LUASL_DIFF_CHECK) + { + // Stash the comma for diff later. + if (comma) + eina_inarray_append(&(call->params), comma); + } + eina_inarray_append(&(call->params), arg); + // At this point, pointers to arg are not pointing to the one in call->params, AND arg is no longer needed. + } + } + } + return list; +} + LSL_Leaf *addFunctionCall(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close) { LSL_Leaf *func = findFunction(compiler, identifier->value.stringValue); - LSL_FunctionCall *call = calloc(1, sizeof(LSL_FunctionCall)); + LSL_FunctionCall *call = NULL; + + if (params) + { + call = params->value.functionCallValue; + } + else + call = calloc(1, sizeof(LSL_FunctionCall)); if (func) { @@ -604,8 +649,6 @@ LSL_Leaf *addFunctionCall(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Le eina_clist_element_init(&(call->dangler)); } identifier->value.functionCallValue = call; - // TODO - Put the params in call. -// eina_inarray_setup(&(cal->vars), sizeof(LSL_Text), 3); identifier->toKen = tokens[LSL_FUNCTION_CALL - lowestToken]; identifier->basicType = func->basicType; } @@ -1507,11 +1550,15 @@ static void outputFunctionCallToken(FILE *file, outputMode mode, LSL_Leaf *conte if (content) { LSL_FunctionCall *call = content->value.functionCallValue; + LSL_Leaf *param = NULL; // TODO - should output it's own ignorable here. outputText(file, &(call->function->name), FALSE); // Don't output the function definitions ignorable. fprintf(file, "("); - // TODO - print params here. + EINA_INARRAY_FOREACH((&(call->params)), param) + { + outputLeaf(file, mode, param); + } fprintf(file, ")"); } } diff --git a/LuaSL/src/LuaSL_lemon_yaccer.y b/LuaSL/src/LuaSL_lemon_yaccer.y index bbc4939..0aa6c5b 100644 --- a/LuaSL/src/LuaSL_lemon_yaccer.y +++ b/LuaSL/src/LuaSL_lemon_yaccer.y @@ -96,9 +96,9 @@ statement(A) ::= expr(E) LSL_STATEMENT(S). { A = addStatement(compi // Various forms of expression. // Used for function call params, and list contents. -exprList ::= exprList LSL_COMMA expr. -exprList ::= expr. -exprList ::= . +exprList(A) ::= exprList(B) LSL_COMMA(C) expr(D). { A = collectArguments(compiler, B, C, D); } +exprList(A) ::= expr(D). { A = collectArguments(compiler, NULL, NULL, D); } +exprList(A) ::= . { A = collectArguments(compiler, NULL, NULL, NULL); } %right LSL_BOOL_AND. expr(A) ::= expr(B) LSL_BOOL_AND(C) expr(D). { A = addOperation(compiler, B, C, D); } -- cgit v1.1