]> gitweb.hamatoma.de Git - reqt/commitdiff
day's work
authorhama <hama@siduction.net>
Thu, 10 Jul 2014 22:29:04 +0000 (00:29 +0200)
committerhama <hama@siduction.net>
Thu, 10 Jul 2014 22:29:04 +0000 (00:29 +0200)
rplexpr/rplasclasses.cpp
rplexpr/rplmfparser.cpp

index 47fd2a4f086b002e00ebfeb291d2188713e3179f..9362ce561012b9956680c0ea5644b9720dbc880f 100644 (file)
@@ -790,8 +790,7 @@ RplASFormula::RplASFormula() :
  */
 void*RplASFormula::newValueInstance(void* expr) const
 {
-    RplASExprStatement* rc = new RplASFormula();
-    rc->setChild();
+    return expr;
 }
 
 /**
index 1ac53f93310a65a18b19d2b4076df80db3a099bd..ca93d7ca974402a5eec156b72b23c0c965f3fb86 100644 (file)
@@ -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<RplASListOfVariants*>
+            (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<RplASExprStatement*>
+                        (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;