From 9e8f8dbd9c52d1da132d618573d87650e0a0f7f9 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Thu, 14 Aug 2014 08:32:50 +1000 Subject: Only collect the errors and warnings during a compile, output them in a batch at the end. --- src/LuaSL/LuaSL_compile.c | 32 ++++++++++++++++++++++++++------ src/LuaSL/LuaSL_main.c | 14 ++++++++++++++ src/libraries/Runnr.c | 4 +--- src/libraries/Runnr.h | 8 ++++++++ src/libraries/SledjHamr.c | 25 +++++++++++++++++++++++++ src/libraries/SledjHamr.h | 1 + 6 files changed, 75 insertions(+), 9 deletions(-) diff --git a/src/LuaSL/LuaSL_compile.c b/src/LuaSL/LuaSL_compile.c index d1ef48b..b2ae841 100644 --- a/src/LuaSL/LuaSL_compile.c +++ b/src/LuaSL/LuaSL_compile.c @@ -223,6 +223,15 @@ LSL_Script constants; int lowestToken = 999999; +static void finishMessage(LuaCompile *compiler, compileMessage *message, int type, int column, int line) +{ + message->type = type; + message->column = column; + message->line = line; + if (type) + compiler->bugCount++; +} + static LSL_Leaf *newLeaf(LSL_Type type, LSL_Leaf *left, LSL_Leaf *right) { LSL_Leaf *leaf = calloc(1, sizeof(LSL_Leaf)); @@ -361,8 +370,11 @@ LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf } else { - compiler->compiler->bugCount++; - sendBack(compiler->compiler->client, compiler->compiler->SID, "compilerError(%d,%d,NOT FOUND variable %s)", identifier->line, identifier->column, identifier->value.stringValue); +// compiler->compiler->bugCount++; +// sendBack(compiler->compiler->client, compiler->compiler->SID, "compilerError(%d,%d,NOT FOUND variable %s)", identifier->line, identifier->column, identifier->value.stringValue); + finishMessage(compiler->compiler, addMessage(&(compiler->compiler->messages), sizeof(compileMessage), + "NOT FOUND variable %s", identifier->value.stringValue), + 1, identifier->column, identifier->line); } } @@ -632,8 +644,11 @@ else rightType = allowed[right->basicType].name; } - compiler->compiler->bugCount++; - sendBack(compiler->compiler->client, compiler->compiler->SID, "compilerError(%d,%d,Invalid operation [%s(%s) %s %s(%s)])", lval->line, lval->column, leftType, leftToken, lval->toKen->toKen, rightType, rightToken); +// compiler->compiler->bugCount++; +// sendBack(compiler->compiler->client, compiler->compiler->SID, "compilerError(%d,%d,Invalid operation [%s(%s) %s %s(%s)])", lval->line, lval->column, leftType, leftToken, lval->toKen->toKen, rightType, rightToken); + finishMessage(compiler->compiler, addMessage(&(compiler->compiler->messages), sizeof(compileMessage), + "Invalid operation [%s(%s) %s %s(%s)]", leftType, leftToken, lval->toKen->toKen, rightType, rightToken), + 1, lval->column, lval->line); } } @@ -2234,7 +2249,7 @@ void compileLSL(LuaCompiler *compiler) lcompiler->ignorable = eina_strbuf_new(); #endif - PI("Compiling %s.", lcompiler->compiler->file); +// PI("Compiling %s.", lcompiler->compiler->file); in = fopen(lcompiler->compiler->file, "r"); if (NULL == in) @@ -2300,7 +2315,12 @@ void compileLSL(LuaCompiler *compiler) call->call->basicType = func->basicType; } else - sendBack(lcompiler->compiler->client, lcompiler->compiler->SID, "compilerError(%d,%d,NOT FOUND function %s called)", call->call->line, call->call->column, call->call->value.stringValue); + { +// sendBack(lcompiler->compiler->client, lcompiler->compiler->SID, "compilerError(%d,%d,NOT FOUND function %s called)", call->call->line, call->call->column, call->call->value.stringValue); + finishMessage(lcompiler->compiler, addMessage(&(lcompiler->compiler->messages), sizeof(compileMessage), + "NOT FOUND function %s called)", call->call->value.stringValue), + 1, call->call->column, call->call->line); + } } } secondPass(lcompiler, lcompiler->ast); diff --git a/src/LuaSL/LuaSL_main.c b/src/LuaSL/LuaSL_main.c index f316fdb..1eaa43a 100644 --- a/src/LuaSL/LuaSL_main.c +++ b/src/LuaSL/LuaSL_main.c @@ -182,6 +182,18 @@ static Eina_Bool _add(void *data, int type __UNUSED__, Ecore_Con_Event_Client_Ad static void _compileCb(LuaCompiler *compiler) { + compileMessage *message = NULL, *safe = NULL; + + EINA_CLIST_FOR_EACH_ENTRY_SAFE(message, safe, &(compiler->messages), compileMessage, node) + { + if (message->type) + sendBack(compiler->client, compiler->SID, "compilerError(%d,%d,%s)", message->line, message->column, message->message); + else + sendBack(compiler->client, compiler->SID, "compilerWarning(%d,%d,%s)", message->line, message->column, message->message); + eina_clist_remove(&(message->node)); + free(message); + } + if (0 == compiler->bugCount) sendBack(compiler->client, compiler->SID, "compiled(true)"); else @@ -223,6 +235,7 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Client_D temp++; temp[0] = '\0'; + eina_clist_init(&(compiler->messages)); compiler->file = strdup(file); compiler->SID = strdup(SID); compiler->client = ev->client; @@ -304,6 +317,7 @@ int main(int argc, char **argv) ourGlobals.names = eina_hash_string_superfast_new(NULL); if (ecore_init()) { +// ecore_thread_max_set(4); if (ecore_con_init()) { if ((ourGlobals.server = ecore_con_server_add(ECORE_CON_REMOTE_TCP, ourGlobals.address, ourGlobals.port, &ourGlobals))) diff --git a/src/libraries/Runnr.c b/src/libraries/Runnr.c index 1f10d33..5fecfdf 100644 --- a/src/libraries/Runnr.c +++ b/src/libraries/Runnr.c @@ -421,9 +421,6 @@ static void _compileEnd(void *data, Ecore_Thread *thread) free(compiler->SID); } -// TODO - Should pass error messages back through a linked list. -// To eventually get passed back to the calling app via compiler->errors and compiler->warnings. -// Will need ageneric "add this formatted string to a linked list" function, in SledjHamr.c static void _compileThread(void *data, Ecore_Thread *thread) { LuaCompiler *compiler = data; @@ -487,6 +484,7 @@ static void _compileThread(void *data, Ecore_Thread *thread) } } +// TODO - Threaded version is consistantly about half the speed. WTF? void compileScript(LuaCompiler *compiler, int threadIt) { if (threadIt) diff --git a/src/libraries/Runnr.h b/src/libraries/Runnr.h index 63e0afc..a2098d9 100644 --- a/src/libraries/Runnr.h +++ b/src/libraries/Runnr.h @@ -30,6 +30,13 @@ typedef enum typedef struct _LuaCompile LuaCompile; typedef void (* compileCb)(LuaCompile *compiler); +typedef struct _compileMessage +{ + Eina_Clist node; + char *message; + int type, column, line; +} compileMessage; + typedef struct _LuaCompile { char *file, *SID, *luaName; @@ -38,6 +45,7 @@ typedef struct _LuaCompile compileCb parser; compileCb cb; boolean doConstants; + Eina_Clist messages; // HEAD for error and warning messages. } LuaCompiler; typedef struct _script script; diff --git a/src/libraries/SledjHamr.c b/src/libraries/SledjHamr.c index 5e1d387..5b1cfd5 100644 --- a/src/libraries/SledjHamr.c +++ b/src/libraries/SledjHamr.c @@ -13,6 +13,12 @@ struct _conct Ecore_Event_Handler *add, *data, *del; }; +struct _message +{ + Eina_Clist node; + char *message; +}; + static Eina_Bool _add(void *data, int type, Ecore_Con_Event_Server_Del *ev) { @@ -85,6 +91,25 @@ Ecore_Con_Server *reachOut(char *address, int port, void *data, Ecore_Event_Hand return server; } +void *addMessage(Eina_Clist *list, size_t size, const char *message, ...) +{ + va_list args; + char buf[PATH_MAX]; + int length = 0; + struct _message *result; + + va_start(args, message); + length += vsprintf(&buf[length], message, args); + va_end(args); + result = calloc(1, size + length + 1); + eina_clist_element_init(&(result->node)); + eina_clist_add_tail(list, &(result->node)); + result->message = ((char *) result) + size; + strcpy(result->message, buf); + + return result; +} + void sendBack(Ecore_Con_Client *client, const char *SID, const char *message, ...) { va_list args; diff --git a/src/libraries/SledjHamr.h b/src/libraries/SledjHamr.h index 7ce32b9..07018a1 100644 --- a/src/libraries/SledjHamr.h +++ b/src/libraries/SledjHamr.h @@ -9,6 +9,7 @@ Ecore_Con_Server *reachOut(char *address, int port, void *data, Ecore_Event_Handler_Cb _add, Ecore_Event_Handler_Cb _data, Ecore_Event_Handler_Cb _del); +void *addMessage(Eina_Clist *list, size_t size, const char *message, ...); void sendBack(Ecore_Con_Client *client, const char *SID, const char *message, ...); void sendForth(Ecore_Con_Server *server, const char *SID, const char *message, ...); -- cgit v1.1