From 16fce1165cebdf772f39d9af55c4ee024c57d18a Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 12 Feb 2012 02:34:41 +1000 Subject: Implement compilerError() and compilerWarning(), and pass the client to the compiler so it can use them.. --- LuaSL/src/LuaSL_LSL_tree.h | 3 ++- LuaSL/src/LuaSL_compile.c | 25 +++++++------------ LuaSL/src/LuaSL_main.c | 2 +- LuaSL/src/LuaSL_test.c | 60 ++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 68 insertions(+), 22 deletions(-) (limited to 'LuaSL') diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index 286d22d..600fb6f 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h @@ -387,6 +387,7 @@ Need to do something about that. typedef struct { gameGlobals *game; + Ecore_Con_Client *client; 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; @@ -415,7 +416,7 @@ typedef struct boolean compilerSetup(gameGlobals *game); -boolean compileLSL(gameGlobals *game, char *script, boolean doConstants); +boolean compileLSL(gameGlobals *game, Ecore_Con_Client *client, char *script, boolean doConstants); void burnLeaf(void *data); LSL_Leaf *addBlock(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right); diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index 95761a2..8e9bd01 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c @@ -358,7 +358,7 @@ LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf else { compiler->script.bugCount++; - PE("NOT found %s @ line %d, column %d!", identifier->value.stringValue, identifier->line, identifier->column); + sendBack(game, compiler->client, compiler->fileName, "compilerError(%d,%d,NOT found %s)", identifier->line, identifier->column, identifier->value.stringValue); } } @@ -402,7 +402,7 @@ LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, if (OT_undeclared == lType) { compiler->script.warningCount++; - PW("Undeclared identifier issue, deferring this until the second pass. @ line %d, column %d.", lval->line, lval->column); + sendBack(game, compiler->client, compiler->fileName, "compilerWarning(%d,%d,Undeclared identifier issue, deferring this until the second pass)", lval->line, lval->column); lval->basicType = OT_undeclared; return lval; } @@ -430,7 +430,7 @@ LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, if (OT_undeclared == rType) { compiler->script.warningCount++; - PW("Undeclared identifier issue, deferring this until the second pass. @ line %d, column %d.", lval->line, lval->column); + sendBack(game, compiler->client, compiler->fileName, "compilerWarning(%d,%d,Undeclared identifier issue, deferring this until the second pass)", lval->line, lval->column); lval->basicType = OT_undeclared; return lval; } @@ -587,7 +587,7 @@ else } compiler->script.bugCount++; - PE("Invalid operation [%s(%s) %s %s(%s)] @ line %d, column %d!", leftType, leftToken, lval->toKen->toKen, rightType, rightToken, lval->line, lval->column); + sendBack(game, compiler->client, compiler->fileName, "compilerError(%d,%d,Invalid operation [%s(%s) %s %s(%s)])", lval->line, lval->column, leftType, leftToken, lval->toKen->toKen, rightType, rightToken); } } @@ -2120,7 +2120,7 @@ boolean compilerSetup(gameGlobals *game) // Compile the constants. snprintf(buf, sizeof(buf), "%s/src/constants.lsl", PACKAGE_DATA_DIR); - compileLSL(game, buf, TRUE); + compileLSL(game, NULL, buf, TRUE); return TRUE; } @@ -2140,7 +2140,7 @@ static int luaWriter(lua_State *L, const void* p, size_t sz, void* ud) return result; } -boolean compileLSL(gameGlobals *game, char *script, boolean doConstants) +boolean compileLSL(gameGlobals *game, Ecore_Con_Client *client, char *script, boolean doConstants) { boolean result = FALSE; LuaSL_compiler compiler; @@ -2152,6 +2152,7 @@ boolean compileLSL(gameGlobals *game, char *script, boolean doConstants) memset(&compiler, 0, sizeof(LuaSL_compiler)); compiler.game = game; + compiler.client = client; compiler.script.functions = eina_hash_stringshared_new(burnLeaf); compiler.script.states = eina_hash_stringshared_new(burnLeaf); compiler.script.variables = eina_hash_stringshared_new(burnLeaf); @@ -2215,7 +2216,7 @@ boolean compileLSL(gameGlobals *game, char *script, boolean doConstants) call->call->basicType = func->basicType; } else - PE("Undeclared function %s called @ line %d, column %d!", call->call->value.stringValue, call->call->line, call->call->column); + sendBack(game, compiler.client, compiler.fileName, "compilerError(%d,%d,Undeclared function %s called)", call->call->line, call->call->column, call->call->value.stringValue); } } secondPass(&compiler, compiler.ast); @@ -2319,16 +2320,8 @@ boolean compileLSL(gameGlobals *game, char *script, boolean doConstants) PC("Unable to open file %s for writing!", luaName); } - if (compiler.script.bugCount) - PE("%d errors and %d warnings in %s", compiler.script.bugCount, compiler.script.warningCount, compiler.fileName); - else - { - if (compiler.script.warningCount) - PW("%d errors and %d warnings in %s", compiler.script.bugCount, compiler.script.warningCount, compiler.fileName); -// else -// PI("%d errors and %d warnings in %s", compiler.script.bugCount, compiler.script.warningCount, compiler.fileName); + if (0 == compiler.script.bugCount) result = TRUE; - } } if (NULL != compiler.file) diff --git a/LuaSL/src/LuaSL_main.c b/LuaSL/src/LuaSL_main.c index 7dad1c0..1056535 100644 --- a/LuaSL/src/LuaSL_main.c +++ b/LuaSL/src/LuaSL_main.c @@ -36,7 +36,7 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Client_D if (0 == strcmp(command, "compile()")) { PD("Compiling %s.", SID); - if (compileLSL(game, SID, FALSE)) + if (compileLSL(game, ev->client, SID, FALSE)) sendBack(game, ev->client, SID, "compiled(true)"); else sendBack(game, ev->client, SID, "compiled(false)"); diff --git a/LuaSL/src/LuaSL_test.c b/LuaSL/src/LuaSL_test.c index f7087cf..ec7824a 100644 --- a/LuaSL/src/LuaSL_test.c +++ b/LuaSL/src/LuaSL_test.c @@ -8,7 +8,7 @@ typedef struct char fileName[PATH_MAX]; struct timeval startTime; float compileTime; - int errors, warnings; + int bugs, warnings; boolean running; } script; @@ -144,6 +144,7 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Server_D { gameGlobals *game = data; + char buf[PATH_MAX]; char SID[PATH_MAX]; const char *command; char *ext; @@ -160,14 +161,65 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Server_D ext = rindex(SID, '.'); if (ext) { + script *me; + ext[0] = '\0'; command = ext + 1; - if (0 == strcmp(command, "compiled(false)")) + me = eina_hash_find(game->scripts, SID); + if (0 == strncmp(command, "compilerWarning(", 16)) + { + char *temp; + char *line; + char *column; + char *text; + + strcpy(buf, &command[16]); + temp = buf; + line = temp; + while (',' != temp[0]) + temp++; + temp[0] = '\0'; + column = ++temp; + while (',' != temp[0]) + temp++; + temp[0] = '\0'; + text = ++temp; + while (')' != temp[0]) + temp++; + temp[0] = '\0'; + PW("%s @ line %s, column %s.", text, line, column); + if (me) + me->warnings++; + } + else if (0 == strncmp(command, "compilerError(", 14)) + { + char *temp; + char *line; + char *column; + char *text; + + strcpy(buf, &command[14]); + temp = buf; + line = temp; + while (',' != temp[0]) + temp++; + temp[0] = '\0'; + column = ++temp; + while (',' != temp[0]) + temp++; + temp[0] = '\0'; + text = ++temp; + while (')' != temp[0]) + temp++; + temp[0] = '\0'; + PE("%s @ line %s, column %s.", text, line, column); + if (me) + me->bugs++; + } + else if (0 == strcmp(command, "compiled(false)")) PE("The compile of %s failed!", SID); else if (0 == strcmp(command, "compiled(true)")) { - script *me = eina_hash_find(game->scripts, SID); - if (me) { struct timeval now; -- cgit v1.1