From e235a097751de7ad97563997215f76761b3db609 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Tue, 17 Jan 2012 13:15:15 +1000 Subject: Use EFL logging. --- LuaSL/src/LuaSL.h | 3 +- LuaSL/src/LuaSL_LSL_tree.h | 3 +- LuaSL/src/LuaSL_compile.c | 32 +++++++++++-------- LuaSL/src/LuaSL_lemon_yaccer.y | 72 +++++++++++++++++++++++++++--------------- LuaSL/src/LuaSL_main.c | 4 +-- 5 files changed, 71 insertions(+), 43 deletions(-) (limited to 'LuaSL') diff --git a/LuaSL/src/LuaSL.h b/LuaSL/src/LuaSL.h index 509f155..852847d 100644 --- a/LuaSL/src/LuaSL.h +++ b/LuaSL/src/LuaSL.h @@ -56,11 +56,12 @@ typedef struct } gameGlobals; -Eina_Bool compilerSetup(); +Eina_Bool compilerSetup(gameGlobals *game); Eina_Bool compileLSL(gameGlobals *game, char *script); void loggingStartup(gameGlobals *game); char *getDateTime(struct tm **nowOut, char *dateOut, time_t *tiemOut); float timeDiff(struct timeval *now, struct timeval *then); +#include "LuaSL_LSL_tree.h" diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index b287b8f..4b6e3c4 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h @@ -277,6 +277,7 @@ struct _LSL_Script typedef struct { + gameGlobals *game; void *scanner; // This should be of type yyscan_t, which is typedef to void * anyway, but that does not get defined until LuaSL_lexer.h, which depends on this struct being defined first. int argc; char **argv; @@ -298,7 +299,7 @@ typedef struct void burnLeaf(LSL_Leaf *leaf); LSL_Leaf *addFunction(LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_Leaf *params, LSL_Leaf *close, LSL_Leaf *block); -LSL_Leaf *addOperation(LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right); +LSL_Leaf *addOperation(LuaSL_yyparseParam *param, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right); LSL_Leaf *addParameter(LSL_Leaf *type, LSL_Leaf *newParam); LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf *rval); LSL_Leaf *addState(LuaSL_yyparseParam *param, LSL_Leaf *identifier, LSL_Leaf *block); diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index 01657bc..030f140 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c @@ -1,5 +1,4 @@ #include "LuaSL.h" -#include "LuaSL_LSL_tree.h" static LSL_Leaf *evaluateFloatToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); @@ -210,8 +209,10 @@ void burnLeaf(LSL_Leaf *leaf) } } -LSL_Leaf *addOperation(LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right) +LSL_Leaf *addOperation(LuaSL_yyparseParam *param, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right) { + gameGlobals *game = param->game; + if (lval) { opType lType, rType; @@ -283,7 +284,7 @@ LSL_Leaf *addOperation(LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right) if (right) rightType = allowed[right->basicType].name; - fprintf(stderr, "Invalid operation [%s %s %s] @ line %d column %d\n", leftType, lval->token->token, rightType, lval->line, lval->column); + PE("Invalid operation [%s %s %s] @ line %d column %d", leftType, lval->token->token, rightType, lval->line, lval->column); } } @@ -870,6 +871,8 @@ static void outputVariableToken(FILE *file, outputMode mode, LSL_Leaf *content) static void doneParsing(LuaSL_yyparseParam *param) { + gameGlobals *game = param->game; + if (param->ast) { FILE *out; @@ -894,12 +897,12 @@ static void doneParsing(LuaSL_yyparseParam *param) fclose(out); sprintf(buffer, "diff %s %s", param->fileName, outName); // count = system(buffer); -// printf("Return value of %s is %d\n", buffer, count); +// PI("Return value of %s is %d", buffer, count); // if (0 != count) -// fprintf(stderr, "%s says they are different!\n", buffer); +// PE("%s says they are different!", buffer); } else - fprintf(stderr, "Unable to open file %s for writing!\n", outName); + PC("Unable to open file %s for writing!", outName); out = fopen(luaName, "w"); if (out) { @@ -907,11 +910,11 @@ static void doneParsing(LuaSL_yyparseParam *param) fclose(out); } else - fprintf(stderr, "Unable to open file %s for writing!\n", luaName); + PC("Unable to open file %s for writing!", luaName); } } -Eina_Bool compilerSetup() +Eina_Bool compilerSetup(gameGlobals *game) { int i; @@ -934,7 +937,7 @@ Eina_Bool compilerSetup() return EINA_TRUE; } else - fprintf(stderr, "No memory for tokens!"); + PC("No memory for tokens!"); return EINA_FALSE; } @@ -950,15 +953,18 @@ Eina_Bool compileLSL(gameGlobals *game, char *script) // Just pass all constants and function names through to Lua, assume they are globals there. memset(¶m, 0, sizeof(LuaSL_yyparseParam)); + param.game = game; + + strncpy(param.fileName, script, PATH_MAX - 1); param.fileName[PATH_MAX - 1] = '\0'; param.file = fopen(param.fileName, "r"); if (NULL == param.file) { - fprintf(stderr, "Error opening file %s.\n", param.fileName); + PE("Error opening file %s.", param.fileName); return FALSE; } - printf("Opened %s.\n", param.fileName); + PI("Opened %s.", param.fileName); param.ast = NULL; param.lval = calloc(1, sizeof(LSL_Leaf)); // Text editors usually start counting at 1, even programmers editors. @@ -1025,10 +1031,10 @@ static int nextFile(LuaSL_yyparseParam *param) param->file = fopen(param->fileName, "r"); if (NULL == param->file) { - fprintf(stderr, "Error opening file %s.\n", param->fileName); + PE(stderr, "Error opening file %s.", param->fileName); return FALSE; } - printf("Opened %s.\n", param->fileName); + PE("Opened %s.", param->fileName); burnLeaf(param->ast); param->ast = NULL; param->lval = calloc(1, sizeof(LSL_Leaf)); diff --git a/LuaSL/src/LuaSL_lemon_yaccer.y b/LuaSL/src/LuaSL_lemon_yaccer.y index 5899052..3df7def 100644 --- a/LuaSL/src/LuaSL_lemon_yaccer.y +++ b/LuaSL/src/LuaSL_lemon_yaccer.y @@ -1,5 +1,5 @@ %include { -#include "LuaSL_LSL_tree.h" +#include "LuaSL.h" } %extra_argument {LuaSL_yyparseParam *param} @@ -89,40 +89,40 @@ exprList ::= expr. exprList ::= . %right LSL_BOOL_AND. -expr(A) ::= expr(B) LSL_BOOL_AND(C) expr(D). { A = addOperation(B, C, D); } +expr(A) ::= expr(B) LSL_BOOL_AND(C) expr(D). { A = addOperation(param, B, C, D); } %right LSL_BOOL_OR. -expr(A) ::= expr(B) LSL_BOOL_OR(C) expr(D). { A = addOperation(B, C, D); } +expr(A) ::= expr(B) LSL_BOOL_OR(C) expr(D). { A = addOperation(param, B, C, D); } %left LSL_BIT_AND LSL_BIT_XOR LSL_BIT_OR. -expr(A) ::= expr(B) LSL_BIT_OR(C) expr(D). { A = addOperation(B, C, D); } -expr(A) ::= expr(B) LSL_BIT_XOR(C) expr(D). { A = addOperation(B, C, D); } -expr(A) ::= expr(B) LSL_BIT_AND(C) expr(D). { A = addOperation(B, C, D); } +expr(A) ::= expr(B) LSL_BIT_OR(C) expr(D). { A = addOperation(param, B, C, D); } +expr(A) ::= expr(B) LSL_BIT_XOR(C) expr(D). { A = addOperation(param, B, C, D); } +expr(A) ::= expr(B) LSL_BIT_AND(C) expr(D). { A = addOperation(param, B, C, D); } %right LSL_EQUAL LSL_NOT_EQUAL. -expr(A) ::= expr(B) LSL_NOT_EQUAL(C) expr(D). { A = addOperation(B, C, D); } -expr(A) ::= expr(B) LSL_EQUAL(C) expr(D). { A = addOperation(B, C, D); } +expr(A) ::= expr(B) LSL_NOT_EQUAL(C) expr(D). { A = addOperation(param, B, C, D); } +expr(A) ::= expr(B) LSL_EQUAL(C) expr(D). { A = addOperation(param, B, C, D); } %right LSL_LESS_THAN LSL_GREATER_THAN LSL_LESS_EQUAL LSL_GREATER_EQUAL. -expr(A) ::= expr(B) LSL_GREATER_EQUAL(C) expr(D). { A = addOperation(B, C, D); } -expr(A) ::= expr(B) LSL_LESS_EQUAL(C) expr(D). { A = addOperation(B, C, D); } -expr(A) ::= expr(B) LSL_GREATER_THAN(C) expr(D). { A = addOperation(B, C, D); } -expr(A) ::= expr(B) LSL_LESS_THAN(C) expr(D). { A = addOperation(B, C, D); } +expr(A) ::= expr(B) LSL_GREATER_EQUAL(C) expr(D). { A = addOperation(param, B, C, D); } +expr(A) ::= expr(B) LSL_LESS_EQUAL(C) expr(D). { A = addOperation(param, B, C, D); } +expr(A) ::= expr(B) LSL_GREATER_THAN(C) expr(D). { A = addOperation(param, B, C, D); } +expr(A) ::= expr(B) LSL_LESS_THAN(C) expr(D). { A = addOperation(param, B, C, D); } %left LSL_LEFT_SHIFT LSL_RIGHT_SHIFT. -expr(A) ::= expr(B) LSL_RIGHT_SHIFT(C) expr(D). { A = addOperation(B, C, D); } -expr(A) ::= expr(B) LSL_LEFT_SHIFT(C) expr(D). { A = addOperation(B, C, D); } +expr(A) ::= expr(B) LSL_RIGHT_SHIFT(C) expr(D). { A = addOperation(param, B, C, D); } +expr(A) ::= expr(B) LSL_LEFT_SHIFT(C) expr(D). { A = addOperation(param, B, C, D); } %left LSL_SUBTRACT LSL_ADD LSL_CONCATENATE. -expr(A) ::= expr(B) LSL_ADD(C) expr(D). { A = addOperation(B, C, D); } -expr(A) ::= expr(B) LSL_SUBTRACT(C) expr(D). { A = addOperation(B, C, D); } +expr(A) ::= expr(B) LSL_ADD(C) expr(D). { A = addOperation(param, B, C, D); } +expr(A) ::= expr(B) LSL_SUBTRACT(C) expr(D). { A = addOperation(param, B, C, D); } %left LSL_DIVIDE LSL_MODULO LSL_MULTIPLY LSL_DOT_PRODUCT LSL_CROSS_PRODUCT. -expr(A) ::= expr(B) LSL_MULTIPLY(C) expr(D). { A = addOperation(B, C, D); } -expr(A) ::= expr(B) LSL_MODULO(C) expr(D). { A = addOperation(B, C, D); } -expr(A) ::= expr(B) LSL_DIVIDE(C) expr(D). { A = addOperation(B, C, D); } +expr(A) ::= expr(B) LSL_MULTIPLY(C) expr(D). { A = addOperation(param, B, C, D); } +expr(A) ::= expr(B) LSL_MODULO(C) expr(D). { A = addOperation(param, B, C, D); } +expr(A) ::= expr(B) LSL_DIVIDE(C) expr(D). { A = addOperation(param, B, C, D); } %right LSL_BIT_NOT LSL_BOOL_NOT LSL_NEGATION. -expr(A) ::= LSL_BIT_NOT(B) expr(C). { A = addOperation(NULL, B, C); } -expr(A) ::= LSL_BOOL_NOT(B) expr(C). { A = addOperation(NULL, B, C); } -expr(A) ::= LSL_SUBTRACT(B) expr(C). [LSL_NEGATION] { A = addOperation(NULL, B, C); } +expr(A) ::= LSL_BIT_NOT(B) expr(C). { A = addOperation(param, NULL, B, C); } +expr(A) ::= LSL_BOOL_NOT(B) expr(C). { A = addOperation(param, NULL, B, C); } +expr(A) ::= LSL_SUBTRACT(B) expr(C). [LSL_NEGATION] { A = addOperation(param, NULL, B, C); } // Types, typecasts, and expression reordering. @@ -198,13 +198,33 @@ expr ::= LSL_ANGLE_OPEN expr LSL_COMMA expr LSL_COMMA expr LSL_ANGLE_CLOSE. [L // Parser callbacks. -%parse_accept {printf("Parsing complete.\n");} +%parse_accept +{ + gameGlobals *game = param->game; -%parse_failure {fprintf(stderr,"Giving up. Parser is hopelessly lost!\n");} + PI("Parsing complete."); +} + +%parse_failure +{ + gameGlobals *game = param->game; + + PE("Giving up. Parser is hopelessly lost!"); +} -%stack_overflow {fprintf(stderr,"*******************************************************************Giving up. Parser stack overflow @ line %04d column %04d\n", yypMinor->yy0->line, yypMinor->yy0->column);} // Gotta love consistancy, if it ever happens. +%stack_overflow +{ + gameGlobals *game = param->game; -%syntax_error {fprintf(stderr,"*******************************************************************Syntax error @ line %04d column %04d\n", yyminor.yy0->line, yyminor.yy0->column);} + PE("Giving up. Parser stack overflow @ line %04d column %04d.", yypMinor->yy0->line, yypMinor->yy0->column); // Gotta love consistancy, if it ever happens. +} + +%syntax_error +{ + gameGlobals *game = param->game; + + PE("Syntax error @ line %04d column %04d.", yyminor.yy0->line, yyminor.yy0->column); +} /* Undocumented shit that might be useful later. Pffft diff --git a/LuaSL/src/LuaSL_main.c b/LuaSL/src/LuaSL_main.c index fb2a8ba..b1141c6 100644 --- a/LuaSL/src/LuaSL_main.c +++ b/LuaSL/src/LuaSL_main.c @@ -161,13 +161,13 @@ main(int argc, char **argv) edje_object_signal_callback_add(game.edje, "*", "game_*", _edje_signal_cb, &game); // Setup for the compler. - compilerSetup(); + compilerSetup(&game); // snprintf(buf, sizeof(buf), "%s/Test sim/objects/onefang's test bed/~run", PACKAGE_DATA_DIR); snprintf(buf, sizeof(buf), "%s/test2.lsl", PACKAGE_DATA_DIR); if (compileLSL(&game, buf)) PIm("Against all odds, the compile of %s worked! lol", buf); else - PEm("The compile of %s failed, as expected!", buf); + PEm("The compile of %s failed!", buf); // ecore_main_loop_begin(); -- cgit v1.1