From a1110536f78c820e91f491928bd0471a470202cb Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Fri, 20 Jan 2012 17:19:25 +1000 Subject: Clean up parentesis and typecast a bit. --- LuaSL/src/LuaSL_LSL_tree.h | 3 +-- LuaSL/src/LuaSL_compile.c | 43 ++++++++++++++++++++----------------------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index c2d3260..4b5c067 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h @@ -173,9 +173,8 @@ struct _LSL_Leaf struct _LSL_Parenthesis { - LSL_Leaf *left; LSL_Leaf *contents; - LSL_Leaf *right; + Eina_Strbuf *rightIgnorableText; LSL_Type type; }; diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index 3538ad4..4f51ee4 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c @@ -466,10 +466,11 @@ LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Type type, LSL_Leaf if (parens) { - parens->left = lval; parens->contents = expr; parens->type = type; - parens->right = rval; + parens->rightIgnorableText = rval->ignorableText; + // Actualy, at this point, rval is no longer needed. +// rval->ignorableText = eina_strbuf_new(); if (lval) { lval->value.parenthesis = parens; @@ -512,26 +513,17 @@ LSL_Leaf *addStatement(LSL_Leaf *lval, LSL_Type type, LSL_Leaf *expr) LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf *expr) { - LSL_Parenthesis *parens = calloc(1, sizeof(LSL_Parenthesis)); - - if (parens) + addParenthesis(lval, expr, LSL_TYPECAST_OPEN, rval); + if (lval) { - parens->left = lval; - parens->contents = expr; - parens->type = LSL_TYPECAST_OPEN; - parens->right = rval; - if (lval) - { - lval->value.parenthesis = parens; - if (type) - lval->basicType = type->basicType; - lval->token = tokens[LSL_TYPECAST_OPEN - lowestToken]; - } - if (rval) - { - rval->token = tokens[LSL_TYPECAST_CLOSE - lowestToken]; - } + if (type) + lval->basicType = type->basicType; + // Actualy, at this point, type is no longer needed. + lval->token = tokens[LSL_TYPECAST_OPEN - lowestToken]; } +// if (rval) +// rval->token = tokens[LSL_TYPECAST_CLOSE - lowestToken]; + return lval; } @@ -937,9 +929,14 @@ static void outputParenthesisToken(FILE *file, outputMode mode, LSL_Leaf *conten { if (content) { - fprintf(file, "%s", content->token->token); - outputLeaf(file, mode, content->value.parenthesis->contents); - outputLeaf(file, mode, content->value.parenthesis->right); + fprintf(file, "("); + if (LSL_TYPECAST_OPEN == content->value.parenthesis->type) + fprintf(file, "%s", allowed[content->basicType].name); // TODO - We are missing the type ignorable text here. + else + outputLeaf(file, mode, content->value.parenthesis->contents); + fprintf(file, "%s)", eina_strbuf_string_get(content->value.parenthesis->rightIgnorableText)); + if (LSL_TYPECAST_OPEN == content->value.parenthesis->type) + outputLeaf(file, mode, content->value.parenthesis->contents); } } -- cgit v1.1