From 67bb592b153cd97ece90f12b106c251ca4d08694 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Tue, 17 Jan 2012 14:05:48 +1000 Subject: Use stringshare, and const. --- LuaSL/src/LuaSL_LSL_tree.h | 22 +++++++++++----------- LuaSL/src/LuaSL_compile.c | 4 ++-- LuaSL/src/LuaSL_lexer.l | 8 ++++---- 3 files changed, 17 insertions(+), 17 deletions(-) (limited to 'LuaSL/src') diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index 20ba877..626d005 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h @@ -159,7 +159,7 @@ typedef enum struct _allowedTypes { opType result; - char *name; + const char *name; int subTypes; }; @@ -167,7 +167,7 @@ struct _LSL_Token { LSL_Type type; opSubType subType; - char *token; + const char *token; LSL_Flags flags; outputToken output; evaluateToken evaluate; @@ -190,22 +190,22 @@ struct _LSL_Leaf int integerValue; char *keyValue; LSL_Leaf *listValue; - char *stringValue; + const char *stringValue; float vectorValue[3]; float rotationValue[4]; LSL_Identifier *identifierValue; LSL_Identifier *variableValue; - char *labelValue; + const char *labelValue; LSL_Statement *doValue; LSL_Statement *forValue; LSL_Statement *elseIfValue; LSL_Statement *elseValue; LSL_Statement *ifValue; - char *jumpValue; + const char *jumpValue; LSL_Statement *returnValue; - char *stateChangeValue; + const char *stateChangeValue; LSL_Statement *whileValue; LSL_Statement *statementValue; @@ -215,7 +215,7 @@ struct _LSL_Leaf LSL_State *stateValue; LSL_Script *scriptValue; - char *unknownValue; + const char *unknownValue; } value; }; @@ -229,7 +229,7 @@ struct _LSL_Parenthesis struct _LSL_Identifier // For variables and function parameters. { - char *name; + const char *name; LSL_Leaf value; }; @@ -249,7 +249,7 @@ struct _LSL_Block struct _LSL_Function { - char *name; + const char *name; LSL_Leaf *type; LSL_Leaf *params; LSL_Leaf *block; @@ -257,14 +257,14 @@ struct _LSL_Function struct _LSL_State { - char *name; + const char *name; LSL_Leaf *block; LSL_Function **handlers; }; struct _LSL_Script { - char *name; + const char *name; LSL_Function **functions; LSL_State **states; LSL_Identifier **variables; diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index 523b9c3..e54e0e6 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c @@ -277,7 +277,7 @@ LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, } if (OT_invalid == lval->basicType) { - char *leftType = "", *rightType = ""; + const char *leftType = "", *rightType = ""; if (left) leftType = allowed[left->basicType].name; @@ -335,7 +335,7 @@ LSL_Leaf *addFunction(LSL_Leaf *type, LSL_Leaf *identifier, LSL_Leaf *open, LSL_ { if (identifier) { - char *temp = identifier->value.stringValue; + const char *temp = identifier->value.stringValue; identifier->token = tokens[LSL_FUNCTION - lowestToken]; identifier->value.functionValue = func; diff --git a/LuaSL/src/LuaSL_lexer.l b/LuaSL/src/LuaSL_lexer.l index 5945599..68d0b43 100644 --- a/LuaSL/src/LuaSL_lexer.l +++ b/LuaSL/src/LuaSL_lexer.l @@ -98,18 +98,18 @@ STRING \"(\\.|[^\\"\n])*\" "state" %{ return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_STATE_CHANGE); %} "while" %{ return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_WHILE); %} -{IDENTIFIER} %{ yylval->value.stringValue = strdup(yytext); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_IDENTIFIER); %} +{IDENTIFIER} %{ yylval->value.stringValue = eina_stringshare_add_length(yytext, yyleng); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_IDENTIFIER); %} /* Types. */ {INTEGER} %{ yylval->value.integerValue = atoi(yytext); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_INTEGER); %} {FLOAT} %{ yylval->value.floatValue = atof(yytext); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_FLOAT); %} -{KEY} %{ yylval->value.stringValue = strdup(yytext); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_KEY); %} -{STRING} %{ yylval->value.stringValue = strdup(yytext); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_STRING); %} +{KEY} %{ yylval->value.stringValue = eina_stringshare_add_length(yytext, yyleng); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_KEY); %} +{STRING} %{ yylval->value.stringValue = eina_stringshare_add_length(yytext, yyleng); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_STRING); %} <> { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_SCRIPT); } /* Everything else */ -. %{ printf(" unexpected character.\n"); yylval->value.unknownValue = strdup(yytext); common(yylval, yytext, yyleng, yyextra, TRUE, LSL_UNKNOWN); %} +. %{ printf(" unexpected character.\n"); yylval->value.unknownValue = eina_stringshare_add_length(yytext, yyleng); common(yylval, yytext, yyleng, yyextra, TRUE, LSL_UNKNOWN); %} %% -- cgit v1.1