From: hama Date: Thu, 10 Jul 2014 22:29:04 +0000 (+0200) Subject: day's work X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=0edf919d4bf725a475162c96a5cf6674e010e11c;p=reqt day's work --- diff --git a/rplexpr/rplasclasses.cpp b/rplexpr/rplasclasses.cpp index 47fd2a4..9362ce5 100644 --- a/rplexpr/rplasclasses.cpp +++ b/rplexpr/rplasclasses.cpp @@ -790,8 +790,7 @@ RplASFormula::RplASFormula() : */ void*RplASFormula::newValueInstance(void* expr) const { - RplASExprStatement* rc = new RplASFormula(); - rc->setChild(); + return expr; } /** diff --git a/rplexpr/rplmfparser.cpp b/rplexpr/rplmfparser.cpp index 1ac53f9..ca93d7c 100644 --- a/rplexpr/rplmfparser.cpp +++ b/rplexpr/rplmfparser.cpp @@ -30,7 +30,8 @@ enum MFLocations{ L_PARSE_REPEAT_NO_UNTIL, L_PARSE_REPEAT_NO_SEMI, L_PARSE_BODY_WRONG_ITEM, - L_PARSE_FOR_NO_TO = 2020 + L_PARSE_FOR_NO_TO = 2020, + L_PARSE_LIST_NO_COMMA }; @@ -244,8 +245,11 @@ RplASItem* RplMFParser::parseVarDefinition(Keyword attribute) RplASItem* RplMFParser::parseList() { RplASListConstant* rc = new RplASListConstant(); + RplASVariant& varList = rc->value(); + RplASListOfVariants* list = static_cast + (varList.asObject(NULL)); rc->setPosition(m_lexer.currentPosition()); - + RplASVariant* variant; bool again = true; RplToken* token; RplToken* token2; @@ -254,20 +258,23 @@ RplASItem* RplMFParser::parseList() if (token->isOperator(O_LBRACKET)) again = false; else{ + variant = NULL; m_lexer.saveLastToken(); - RplASVariant* variant = NULL; token2 = m_lexer.nextNonSpaceToken(); if (token2->isOperator(O_COMMA)){ switch(token->tokenType()){ case TOKEN_NUMBER: + // freed in the destructor of varList (~RplASVariant()): variant = new RplASVariant(); variant->setInt(token->asInteger()); break; case TOKEN_STRING: + // freed in the destructor of varList (~RplASVariant()): variant = new RplASVariant(); variant->setString(token->toString()); break; case TOKEN_REAL: + // freed in the destructor of varList (~RplASVariant()): variant = new RplASVariant(); variant->setFloat(token->asReal()); break; @@ -275,10 +282,12 @@ RplASItem* RplMFParser::parseList() switch(token->id()){ case K_TRUE: case K_FALSE: + // freed in the destructor of varList (~RplASVariant()): variant = new RplASVariant(); variant->setBool(token->id() == K_TRUE); break; case K_NONE: + // freed in the destructor of varList (~RplASVariant()): variant = new RplASVariant(); break; default: @@ -291,11 +300,21 @@ RplASItem* RplMFParser::parseList() } if (variant == NULL){ m_lexer.undoLastToken2(); - RplASExprStatement* expr = parseExprStatement(); - expr->successor(rc->child()); + RplASExprStatement* expr = dynamic_cast + (parseExprStatement()); + // chaining per m_successor is for freeing in destruction: + expr->setSuccessor(rc->child()); rc->setChild(expr); - variant = RplASFormula::m_instance.newValueInstance(expr); + variant->setObject(expr, &RplASFormula::m_instance); + token = m_lexer.currentToken(); + if (token->isOperator(O_RBRACKET)) + again = false; + else if (token->isOperator(O_COMMA)) + m_lexer.undoLastToken(); + else + syntaxError(L_PARSE_LIST_NO_COMMA, "',' or ']' expected"); } + list->append(variant); } } return rc;