From 21f319d2263fce2eab43eb50428dd23b9826fa9a Mon Sep 17 00:00:00 2001 From: hama Date: Sun, 27 Jul 2014 23:10:43 +0200 Subject: [PATCH] dayly work --- rplexpr/rplasclasses.cpp | 92 +++++++++++++++++++-------------- rplexpr/rplastree.cpp | 20 ++++++- rplexpr/rplastree.hpp | 2 +- rplexpr/rplmfparser.cpp | 8 +-- test/rplmfparser/baseTest.txt | 2 - test/rplmfparser/defTest.txt | 9 +++- test/rplmfparser/field1.txt | 2 - test/rplmfparser/forC1.txt | 3 +- test/rplmfparser/forC2.txt | 3 +- test/rplmfparser/forIt1.txt | 3 +- test/rplmfparser/ifTest1.txt | 5 +- test/rplmfparser/ifTest2.txt | 3 +- test/rplmfparser/list1.txt | 5 +- test/rplmfparser/list2.txt | 9 +++- test/rplmfparser/map1.txt | 5 +- test/rplmfparser/map2.txt | 9 +++- test/rplmfparser/meth1.txt | 19 +++---- test/rplmfparser/meth2.txt | 40 ++++---------- test/rplmfparser/meth3.txt | 32 ++++++++++++ test/rplmfparser/meth4.txt | 59 +++++++++++++++++++++ test/rplmfparser/methc1.txt | 2 - test/rplmfparser/opTest1.txt | 7 ++- test/rplmfparser/repeatTest.txt | 3 +- test/rplmfparser/whileTest.txt | 4 +- unittests/rplmfparser_test.cpp | 16 ++++++ 25 files changed, 256 insertions(+), 106 deletions(-) create mode 100644 test/rplmfparser/meth3.txt create mode 100644 test/rplmfparser/meth4.txt diff --git a/rplexpr/rplasclasses.cpp b/rplexpr/rplasclasses.cpp index 0b4ce34..8b4cd37 100644 --- a/rplexpr/rplasclasses.cpp +++ b/rplexpr/rplasclasses.cpp @@ -120,50 +120,59 @@ void RplSymbolSpace::dump(FILE* fp, int indent, const char* header) fprintf(fp, "%s= %s (%s) parent: %s\n", tabs, m_name.toUtf8().constData(), spaceTypeName(m_type), m_parent == NULL ? "" : m_parent->name().toUtf8().constData()); - fprintf(fp, "%s== Classes:\n", tabs); QList sorted; - sorted.reserve(m_classes.size()); - ClassMap::iterator it; - for (it = m_classes.begin(); it != m_classes.end(); it++){ - sorted.append(it.key()); - } - qSort(sorted.begin(), sorted.end(), qLess()); - QList::iterator it2; - for (it2 = sorted.begin(); it2 != sorted.end(); it2++){ - RplASClass* clazz = m_classes[*it2]; - clazz->dump(fp, indent); - } - - fprintf(fp, "%s== Methods:\n", tabs); - sorted.clear(); - sorted.reserve(m_variables.size()); - MethodMap::iterator it3; - for (it3 = m_methods.begin(); it3 != m_methods.end(); it3++){ - sorted.append(it3.key()); + if (m_classes.size() > 0){ + fprintf(fp, "%s== Classes:\n", tabs); + sorted.reserve(m_classes.size()); + ClassMap::iterator it; + for (it = m_classes.begin(); it != m_classes.end(); it++){ + sorted.append(it.key()); + } + qSort(sorted.begin(), sorted.end(), qLess()); + QList::iterator it2; + for (it2 = sorted.begin(); it2 != sorted.end(); it2++){ + RplASClass* clazz = m_classes[*it2]; + clazz->dump(fp, indent); + } } - qSort(sorted.begin(), sorted.end(), qLess()); - QList::iterator it4; - for (it4 = sorted.begin(); it4 != sorted.end(); it4++){ - RplASMethod* var = m_methods[*it4]; - var->dump(fp, indent); + if (m_methods.size() > 0){ + fprintf(fp, "%s== Methods:\n", tabs); + sorted.clear(); + sorted.reserve(m_variables.size()); + MethodMap::iterator it3; + for (it3 = m_methods.begin(); it3 != m_methods.end(); it3++){ + sorted.append(it3.key()); + } + qSort(sorted.begin(), sorted.end(), qLess()); + QList::iterator it4; + for (it4 = sorted.begin(); it4 != sorted.end(); it4++){ + RplASMethod* method = m_methods[*it4]; + do { + method->dump(fp, indent); + method = method->sibling(); + } while (method != NULL); + } } - fprintf(fp, "%s== Variables:\n", tabs); - sorted.clear(); - sorted.reserve(m_variables.size()); - VariableMap::iterator it5; - for (it5 = m_variables.begin(); it5 != m_variables.end(); it5++){ - sorted.append(it5.key()); + if (m_variables.size() > 0){ + fprintf(fp, "%s== Variables:\n", tabs); + sorted.clear(); + sorted.reserve(m_variables.size()); + VariableMap::iterator it5; + for (it5 = m_variables.begin(); it5 != m_variables.end(); it5++){ + sorted.append(it5.key()); + } + qSort(sorted.begin(), sorted.end(), qLess()); + QList::iterator it6; + for (it6 = sorted.begin(); it6 != sorted.end(); it6++){ + RplASVarDefinition* var = m_variables[*it6]; + var->dump(fp, indent); + } } - qSort(sorted.begin(), sorted.end(), qLess()); - QList::iterator it6; - for (it6 = sorted.begin(); it6 != sorted.end(); it6++){ - RplASVarDefinition* var = m_variables[*it6]; - var->dump(fp, indent); + if (m_body != NULL){ + fprintf(fp, "%s== Body:\n", tabs); + RplASNode1::dumpStatements(fp, indent, m_body); } - - fprintf(fp, "%s== Body:%s\n", tabs, m_body == NULL ? " " : ""); - RplASNode1::dumpStatements(fp, indent, m_body); } /** @@ -266,15 +275,18 @@ RplASItem* RplSymbolSpace::addMethod(RplASMethod* method) else if (! m_methods.contains(name)){ m_methods[name] = method; } else { - RplASMethod* oldMethod = m_methods[name]; + RplASMethod* first = m_methods[name]; + RplASMethod* oldMethod = first; do { if (oldMethod->equalSignature(*method)) rc = oldMethod; else oldMethod = oldMethod->sibling(); } while (rc == NULL && oldMethod != NULL); - if (rc == NULL) + if (rc == NULL){ + method->setChild(first); m_methods[name] = method; + } } return rc; } diff --git a/rplexpr/rplastree.cpp b/rplexpr/rplastree.cpp index 70a1791..9a9c12d 100644 --- a/rplexpr/rplastree.cpp +++ b/rplexpr/rplastree.cpp @@ -832,7 +832,7 @@ void RplASVarDefinition::dump(FILE* fp, int indent) const QString& RplASVarDefinition::name() const { RplASNamedValue* namedValue = dynamic_cast(m_child2); - const QString& rc = namedValue == NULL ? "?" : namedValue->name(); + const QString& rc = namedValue->name(); return rc; } @@ -910,6 +910,8 @@ void RplASExprStatement::dump(FILE* fp, int indent) { DEFINE_TABS(indent); char buffer[256]; + if (m_id == 40) + m_id = 40; fprintf(fp, "%sExpr id: %d expr: %d succ: %d %s\n", tabs, m_id, m_child2 == NULL ? 0 : m_child2->id(), m_child == NULL ? 0 : m_child->id(), @@ -2086,7 +2088,7 @@ RplASMethod::RplASMethod(const QString& name, RplASTree& tree) : RplASNode2(AST_METHOD), m_name(name), m_resultType(NULL), - m_symbols(tree.startClassOrMethod(name, RplSymbolSpace::SST_METHOD)), + m_symbols(NULL), m_sibling(NULL), m_tree(tree) { @@ -2115,11 +2117,25 @@ void RplASMethod::dump(FILE* fp, int indent) if (m_child2 != NULL) m_child2->dump(fp, indent + 1); dumpStatements(fp, indent + 1, m_child); + m_symbols->dump(fp, indent + 1); } +/** + * @brief Returns the symbol space of the instance. + * + * @return the symbol space + */ RplSymbolSpace* RplASMethod::symbols() const { return m_symbols; } + +/** + * @brief Sets the symbol space from the current of the tree. + */ +void RplASMethod::setSymbols() +{ + m_symbols = m_tree.currentSpace(); +} /** * @brief Returns the name of the method * @return the name diff --git a/rplexpr/rplastree.hpp b/rplexpr/rplastree.hpp index 26487d0..e1f2f84 100644 --- a/rplexpr/rplastree.hpp +++ b/rplexpr/rplastree.hpp @@ -487,7 +487,7 @@ public: void execute(); void dump(FILE* fp, int indent); RplSymbolSpace* symbols() const; - + void setSymbols(); const QString& name() const; bool equalSignature(RplASMethod& other) const; RplASMethod* sibling() const; diff --git a/rplexpr/rplmfparser.cpp b/rplexpr/rplmfparser.cpp index 08a2624..11f4090 100644 --- a/rplexpr/rplmfparser.cpp +++ b/rplexpr/rplmfparser.cpp @@ -892,15 +892,16 @@ RplASExprStatement* RplMFParser::parseParameterList(){ RplASExprStatement* rc = NULL; RplASExprStatement* last = NULL; const RplSourcePosition* startPos = m_lexer.currentPosition(); - RplASItem* definition; + RplASItem* definition = NULL; do { + if (definition != NULL) + m_lexer.nextNonSpaceToken(); definition = parseVarDefinition(RplASNamedValue::A_PARAM); RplASExprStatement *current = new RplASExprStatement(); current->setChild2(definition); if (rc == NULL){ rc = current; } else { - current->setChild(last); last->setChild(current); } last = current; @@ -947,7 +948,8 @@ void RplMFParser::parseMethod() method->setPosition(startPos); RplSymbolSpace* symbols = m_tree.currentSpace(); symbols->addMethod(method); - + m_tree.startClassOrMethod(name, RplSymbolSpace::SST_METHOD); + method->setSymbols(); if (token->isOperator(O_LPARENTH)){ token = m_lexer.nextNonSpaceToken(); if (token->isOperator(O_RPARENTH)){ diff --git a/test/rplmfparser/baseTest.txt b/test/rplmfparser/baseTest.txt index 4f2fbfd..0f195b5 100644 --- a/test/rplmfparser/baseTest.txt +++ b/test/rplmfparser/baseTest.txt @@ -1,7 +1,5 @@ 2+3*4 = (module) parent: global -== Classes: -== Variables: == Body: Expr id: 6 expr: 2 succ: 0 :1:1 BinOp id: 2 op: + (26) left: 1 right: 4 :1:1 diff --git a/test/rplmfparser/defTest.txt b/test/rplmfparser/defTest.txt index 8d941fa..89dc16b 100644 --- a/test/rplmfparser/defTest.txt +++ b/test/rplmfparser/defTest.txt @@ -1,7 +1,14 @@ Int i = 3; const lazy Str s = 'Hi'; const List l; = (module) parent: global -== Classes: == Variables: +varDef i id: 2 namedValue: 1 value: 3 succ: 5 :1:4 + namedValue i id: 1 attr: 0x0 :1:4 + const id: 3 value: 3 :1:8 +varDef l id: 8 namedValue: 7 value: 0 succ: 0 :1:47 + namedValue l id: 7 attr: 0x2 :1:47 +varDef s id: 5 namedValue: 4 value: 6 succ: 8 :1:26 + namedValue s id: 4 attr: 0x12 :1:26 + const id: 6 value: 'Hi' :1:30 == Body: varDef i id: 2 namedValue: 1 value: 3 succ: 5 :1:4 namedValue i id: 1 attr: 0x0 :1:4 diff --git a/test/rplmfparser/field1.txt b/test/rplmfparser/field1.txt index b14cd76..4cbe926 100644 --- a/test/rplmfparser/field1.txt +++ b/test/rplmfparser/field1.txt @@ -2,8 +2,6 @@ file.find('*.c')[0].name; [1,2,3].join(' '); 3.14.trunc; = (module) parent: global -== Classes: -== Variables: == Body: Expr id: 8 expr: 7 succ: 15 :1:24 field name id: 7 parent: 5 succ: :1:24 diff --git a/test/rplmfparser/forC1.txt b/test/rplmfparser/forC1.txt index 7f59d50..64c14c3 100644 --- a/test/rplmfparser/forC1.txt +++ b/test/rplmfparser/forC1.txt @@ -3,8 +3,9 @@ for b from 10 to 1 step -2 do a += 1; od = (module) parent: global -== Classes: == Variables: +varDef a id: 2 namedValue: 1 value: 0 succ: 4 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 == Body: varDef a id: 2 namedValue: 1 value: 0 succ: 4 :1:4 namedValue a id: 1 attr: 0x0 :1:4 diff --git a/test/rplmfparser/forC2.txt b/test/rplmfparser/forC2.txt index a3a4940..117dc32 100644 --- a/test/rplmfparser/forC2.txt +++ b/test/rplmfparser/forC2.txt @@ -1,7 +1,8 @@ Int a; for to 10 do a += 1 od = (module) parent: global -== Classes: == Variables: +varDef a id: 2 namedValue: 1 value: 0 succ: 3 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 == Body: varDef a id: 2 namedValue: 1 value: 0 succ: 3 :1:4 namedValue a id: 1 attr: 0x0 :1:4 diff --git a/test/rplmfparser/forIt1.txt b/test/rplmfparser/forIt1.txt index b32a016..e76a69d 100644 --- a/test/rplmfparser/forIt1.txt +++ b/test/rplmfparser/forIt1.txt @@ -3,8 +3,9 @@ for x in a do a += 1; od = (module) parent: global -== Classes: == Variables: +varDef a id: 2 namedValue: 1 value: 0 succ: 4 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 == Body: varDef a id: 2 namedValue: 1 value: 0 succ: 4 :1:4 namedValue a id: 1 attr: 0x0 :1:4 diff --git a/test/rplmfparser/ifTest1.txt b/test/rplmfparser/ifTest1.txt index 55b6cc2..217a7be 100644 --- a/test/rplmfparser/ifTest1.txt +++ b/test/rplmfparser/ifTest1.txt @@ -6,8 +6,11 @@ then a = 13 * 14 else a = 15 / 16 fi = (module) parent: global -== Classes: == Variables: +varDef a id: 2 namedValue: 1 value: 0 succ: 4 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 +varDef b id: 4 namedValue: 3 value: 0 succ: 10 :2:4 + namedValue b id: 3 attr: 0x0 :2:4 == Body: varDef a id: 2 namedValue: 1 value: 0 succ: 4 :1:4 namedValue a id: 1 attr: 0x0 :1:4 diff --git a/test/rplmfparser/ifTest2.txt b/test/rplmfparser/ifTest2.txt index 47f173c..bfaa9ea 100644 --- a/test/rplmfparser/ifTest2.txt +++ b/test/rplmfparser/ifTest2.txt @@ -3,8 +3,9 @@ if 7 < 6 then x = '123'; fi = (module) parent: global -== Classes: == Variables: +varDef x id: 2 namedValue: 1 value: 0 succ: 3 :1:4 + namedValue x id: 1 attr: 0x0 :1:4 == Body: varDef x id: 2 namedValue: 1 value: 0 succ: 3 :1:4 namedValue x id: 1 attr: 0x0 :1:4 diff --git a/test/rplmfparser/list1.txt b/test/rplmfparser/list1.txt index b35935c..2de17e1 100644 --- a/test/rplmfparser/list1.txt +++ b/test/rplmfparser/list1.txt @@ -1,7 +1,10 @@ List b = []; = (module) parent: global -== Classes: == Variables: +varDef b id: 2 namedValue: 1 value: 3 succ: 0 :1:5 + namedValue b id: 1 attr: 0x0 :1:5 + listConst id: 3 :1:9 + [] == Body: varDef b id: 2 namedValue: 1 value: 3 succ: 0 :1:5 namedValue b id: 1 attr: 0x0 :1:5 diff --git a/test/rplmfparser/list2.txt b/test/rplmfparser/list2.txt index ec5cbe5..fd904e5 100644 --- a/test/rplmfparser/list2.txt +++ b/test/rplmfparser/list2.txt @@ -1,7 +1,14 @@ List a = [2+3, 3.14, 7, 'hi', a]; List b = []; = (module) parent: global -== Classes: == Variables: +varDef a id: 2 namedValue: 1 value: 3 succ: 11 :1:5 + namedValue a id: 1 attr: 0x0 :1:5 + listConst id: 3 :1:9 + [,3.140000,7,'hi',] +varDef b id: 11 namedValue: 10 value: 12 succ: 0 :1:39 + namedValue b id: 10 attr: 0x0 :1:39 + listConst id: 12 :1:43 + [] == Body: varDef a id: 2 namedValue: 1 value: 3 succ: 11 :1:5 namedValue a id: 1 attr: 0x0 :1:5 diff --git a/test/rplmfparser/map1.txt b/test/rplmfparser/map1.txt index 25c1359..0d69fce 100644 --- a/test/rplmfparser/map1.txt +++ b/test/rplmfparser/map1.txt @@ -1,7 +1,10 @@ Map a = {}; = (module) parent: global -== Classes: == Variables: +varDef a id: 2 namedValue: 1 value: 3 succ: 0 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 + mapConst id: 3 :1:8 + {} == Body: varDef a id: 2 namedValue: 1 value: 3 succ: 0 :1:4 namedValue a id: 1 attr: 0x0 :1:4 diff --git a/test/rplmfparser/map2.txt b/test/rplmfparser/map2.txt index 6272b8b..ca85376 100644 --- a/test/rplmfparser/map2.txt +++ b/test/rplmfparser/map2.txt @@ -1,8 +1,15 @@ Map a = {'a': 2+3,'bcd':3.14,'ccc':7, 'hi':'world'}; Map b = {}; = (module) parent: global -== Classes: == Variables: +varDef a id: 2 namedValue: 1 value: 3 succ: 11 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 + mapConst id: 3 :1:8 + {'a':,'bcd':3.140000,'ccc':7,'hi':} +varDef b id: 11 namedValue: 10 value: 12 succ: 0 :2:4 + namedValue b id: 10 attr: 0x0 :2:4 + mapConst id: 12 :2:8 + {} == Body: varDef a id: 2 namedValue: 1 value: 3 succ: 11 :1:4 namedValue a id: 1 attr: 0x0 :1:4 diff --git a/test/rplmfparser/meth1.txt b/test/rplmfparser/meth1.txt index f0ef7ac..3f7dc3f 100644 --- a/test/rplmfparser/meth1.txt +++ b/test/rplmfparser/meth1.txt @@ -1,16 +1,11 @@ func Float pi: 3.1415; endf func Str delim(): '/' endf; = (module) parent: global -== Classes: -== Variables: -== Body: -Method pi() id: 1 parent: 0 args: 0 body: 4 :0:0 - Method delim() id: 4 parent: 0 args: 0 body: 6 :1:28 - Expr id: 6 expr: 5 succ: 0 :1:46 - const id: 5 value: '/' :1:46 +== Methods: +Method delim() id: 4 parent: args: 0 body: 6 :1:28 Expr id: 6 expr: 5 succ: 0 :1:46 const id: 5 value: '/' :1:46 -Method delim() id: 4 parent: 0 args: 0 body: 6 :1:28 - Expr id: 6 expr: 5 succ: 0 :1:46 - const id: 5 value: '/' :1:46 -Expr id: 6 expr: 5 succ: 0 :1:46 - const id: 5 value: '/' :1:46 + = .delim (method) parent: +Method pi() id: 1 parent: args: 0 body: 3 :0:0 + Expr id: 3 expr: 2 succ: 0 :1:15 + const id: 2 value: 3.141500 :1:15 + = .pi (method) parent: diff --git a/test/rplmfparser/meth2.txt b/test/rplmfparser/meth2.txt index df66892..4838410 100644 --- a/test/rplmfparser/meth2.txt +++ b/test/rplmfparser/meth2.txt @@ -2,13 +2,11 @@ func Int fac(const Int n): Int rc; if rc <= 1 then rc = 1 else rc = n*fac(n-1) fi rc endf = (module) parent: global -== Classes: -== Variables: -== Body: -Method fac() id: 4 parent: 0 args: 3 body: 6 :0:55 - Expr id: 3 expr: 2 succ: 0 - varDef n id: 2 namedValue: 1 value: 0 succ: 0 :1:23 - namedValue n id: 1 attr: 0x22 :1:23 +== Methods: +Method fac() id: 1 parent: args: 4 body: 6 :0:55 + Expr id: 4 expr: 3 succ: 0 + varDef n id: 3 namedValue: 2 value: 0 succ: 0 :1:23 + namedValue n id: 2 attr: 0x22 :1:23 varDef rc id: 6 namedValue: 5 value: 0 succ: 7 :2:4 namedValue rc id: 5 attr: 0x0 :2:4 If id: 7 condition: 9 then: 14 else: 24 succ: 26:2:8 @@ -31,25 +29,9 @@ Method fac() id: 4 parent: 0 args: 3 body: 6 :0:55 const id: 22 value: 1 :2:49 Expr id: 26 expr: 25 succ: 0 :3:3 namedValue rc id: 25 attr: 0x0 :3:3 -varDef rc id: 6 namedValue: 5 value: 0 succ: 7 :2:4 - namedValue rc id: 5 attr: 0x0 :2:4 -If id: 7 condition: 9 then: 14 else: 24 succ: 26:2:8 - BinOp id: 9 op: <= (23) left: 8 right: 10 :2:14 - namedValue rc id: 8 attr: 0x0 :2:14 - const id: 10 value: 1 :2:17 - Expr id: 14 expr: 12 succ: 0 :2:27 - BinOp id: 12 op: = (5) left: 11 right: 13 :2:27 - namedValue rc id: 11 attr: 0x0 :2:27 - const id: 13 value: 1 :2:29 - Expr id: 24 expr: 16 succ: 0 :2:39 - BinOp id: 16 op: = (5) left: 15 right: 18 :2:39 - namedValue rc id: 15 attr: 0x0 :2:39 - BinOp id: 18 op: * (30) left: 17 right: 19 :2:42 - namedValue n id: 17 attr: 0x0 :2:42 - call fac Id: 19 args: 23 parent: 0 succ: 0 :2:46 - arg 1 id: 23 expr: 21 succ: 0 - BinOp id: 21 op: - (27) left: 20 right: 22 :2:48 - namedValue n id: 20 attr: 0x0 :2:48 - const id: 22 value: 1 :2:49 -Expr id: 26 expr: 25 succ: 0 :3:3 - namedValue rc id: 25 attr: 0x0 :3:3 + = .fac (method) parent: + == Variables: + varDef n id: 3 namedValue: 2 value: 0 succ: 0 :1:23 + namedValue n id: 2 attr: 0x22 :1:23 + varDef rc id: 6 namedValue: 5 value: 0 succ: 7 :2:4 + namedValue rc id: 5 attr: 0x0 :2:4 diff --git a/test/rplmfparser/meth3.txt b/test/rplmfparser/meth3.txt new file mode 100644 index 0000000..74b57d8 --- /dev/null +++ b/test/rplmfparser/meth3.txt @@ -0,0 +1,32 @@ +func Int max(Int a, Int b): + Int rc = a; +if a < b then rc = b; fi +rc +endf +func Int max(const Int a, Int b, Int c): +max(a, max(b, c)) +endf += (module) parent: global +== Methods: +Method max() id: 21 parent: args: 24 body: 40 :5:5 + Expr id: 24 expr: 23 succ: 27 + varDef a id: 23 namedValue: 22 value: 0 succ: 0 :6:23 + namedValue a id: 22 attr: 0x22 :6:23 + Expr id: 40 expr: 31 succ: 0 :7:3 + call max Id: 31 args: 33 parent: 0 succ: 0 :7:3 + arg 1 id: 33 expr: 32 succ: 39 + namedValue a id: 32 attr: 0x0 :7:5 + arg 2 id: 39 expr: 34 succ: 0 + call max Id: 34 args: 36 parent: 0 succ: 0 :7:10 + arg 1 id: 36 expr: 35 succ: 38 + namedValue b id: 35 attr: 0x0 :7:12 + arg 2 id: 38 expr: 37 succ: 0 + namedValue c id: 37 attr: 0x0 :7:15 + = .max (method) parent: + == Variables: + varDef a id: 23 namedValue: 22 value: 0 succ: 0 :6:23 + namedValue a id: 22 attr: 0x22 :6:23 + varDef b id: 26 namedValue: 25 value: 0 succ: 0 :6:30 + namedValue b id: 25 attr: 0x20 :6:30 + varDef c id: 29 namedValue: 28 value: 0 succ: 0 :6:37 + namedValue c id: 28 attr: 0x20 :6:37 diff --git a/test/rplmfparser/meth4.txt b/test/rplmfparser/meth4.txt new file mode 100644 index 0000000..1e0449a --- /dev/null +++ b/test/rplmfparser/meth4.txt @@ -0,0 +1,59 @@ +func Int max(const Int a, Int b, Int c): +func Int max(Int a, Int b): + Int rc = a; +if a < b then rc = b; fi +rc +endf +max(a, max(b, c)) +endf += (module) parent: global +== Methods: +Method max() id: 1 parent: args: 4 body: 40 :0:4 + Expr id: 4 expr: 3 succ: 7 + varDef a id: 3 namedValue: 2 value: 0 succ: 0 :1:23 + namedValue a id: 2 attr: 0x22 :1:23 + Expr id: 40 expr: 31 succ: 0 :7:3 + call max Id: 31 args: 33 parent: 0 succ: 0 :7:3 + arg 1 id: 33 expr: 32 succ: 39 + namedValue a id: 32 attr: 0x0 :7:5 + arg 2 id: 39 expr: 34 succ: 0 + call max Id: 34 args: 36 parent: 0 succ: 0 :7:10 + arg 1 id: 36 expr: 35 succ: 38 + namedValue b id: 35 attr: 0x0 :7:12 + arg 2 id: 38 expr: 37 succ: 0 + namedValue c id: 37 attr: 0x0 :7:15 + = .max (method) parent: + == Methods: + Method max() id: 11 parent: .max args: 14 body: 19 :1:41 + Expr id: 14 expr: 13 succ: 17 + varDef a id: 13 namedValue: 12 value: 0 succ: 0 :2:17 + namedValue a id: 12 attr: 0x20 :2:17 + varDef rc id: 19 namedValue: 18 value: 20 succ: 21 :3:5 + namedValue rc id: 18 attr: 0x0 :3:5 + namedValue a id: 20 attr: 0x0 :3:11 + If id: 21 condition: 23 then: 28 else: 0 succ: 30:3:13 + BinOp id: 23 op: < (21) left: 22 right: 24 :4:5 + namedValue a id: 22 attr: 0x0 :4:5 + namedValue b id: 24 attr: 0x0 :4:9 + Expr id: 28 expr: 26 succ: 0 :4:17 + BinOp id: 26 op: = (5) left: 25 right: 27 :4:17 + namedValue rc id: 25 attr: 0x0 :4:17 + namedValue b id: 27 attr: 0x0 :4:20 + Expr id: 30 expr: 29 succ: 0 :5:3 + namedValue rc id: 29 attr: 0x0 :5:3 + = .max.max (method) parent: .max + == Variables: + varDef a id: 13 namedValue: 12 value: 0 succ: 0 :2:17 + namedValue a id: 12 attr: 0x20 :2:17 + varDef b id: 16 namedValue: 15 value: 0 succ: 0 :2:24 + namedValue b id: 15 attr: 0x20 :2:24 + varDef rc id: 19 namedValue: 18 value: 20 succ: 21 :3:5 + namedValue rc id: 18 attr: 0x0 :3:5 + namedValue a id: 20 attr: 0x0 :3:11 + == Variables: + varDef a id: 3 namedValue: 2 value: 0 succ: 0 :1:23 + namedValue a id: 2 attr: 0x22 :1:23 + varDef b id: 6 namedValue: 5 value: 0 succ: 0 :1:30 + namedValue b id: 5 attr: 0x20 :1:30 + varDef c id: 9 namedValue: 8 value: 0 succ: 0 :1:37 + namedValue c id: 8 attr: 0x20 :1:37 diff --git a/test/rplmfparser/methc1.txt b/test/rplmfparser/methc1.txt index bd9866a..3ccf636 100644 --- a/test/rplmfparser/methc1.txt +++ b/test/rplmfparser/methc1.txt @@ -2,8 +2,6 @@ rand(); sin(a); max(1+2*3,4**(5-4)); = (module) parent: global -== Classes: -== Variables: == Body: Expr id: 2 expr: 1 succ: 6 :1:4 call rand Id: 1 args: 0 parent: 0 succ: 0 :1:4 diff --git a/test/rplmfparser/opTest1.txt b/test/rplmfparser/opTest1.txt index 446622d..ac8e160 100644 --- a/test/rplmfparser/opTest1.txt +++ b/test/rplmfparser/opTest1.txt @@ -5,8 +5,13 @@ b++; a--*++b**(8-3); a=b=(a+(b-2)*3) = (module) parent: global -== Classes: == Variables: +varDef a id: 2 namedValue: 1 value: 3 succ: 5 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 + const id: 3 value: 1 :1:8 +varDef b id: 5 namedValue: 4 value: 6 succ: 9 :2:4 + namedValue b id: 4 attr: 0x0 :2:4 + const id: 6 value: 100 :2:8 == Body: varDef a id: 2 namedValue: 1 value: 3 succ: 5 :1:4 namedValue a id: 1 attr: 0x0 :1:4 diff --git a/test/rplmfparser/repeatTest.txt b/test/rplmfparser/repeatTest.txt index 93b5f5a..e2acdec 100644 --- a/test/rplmfparser/repeatTest.txt +++ b/test/rplmfparser/repeatTest.txt @@ -3,8 +3,9 @@ repeat a++; until a != 2 * 3; = (module) parent: global -== Classes: == Variables: +varDef a id: 2 namedValue: 1 value: 0 succ: 3 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 == Body: varDef a id: 2 namedValue: 1 value: 0 succ: 3 :1:4 namedValue a id: 1 attr: 0x0 :1:4 diff --git a/test/rplmfparser/whileTest.txt b/test/rplmfparser/whileTest.txt index 410991b..ad6887d 100644 --- a/test/rplmfparser/whileTest.txt +++ b/test/rplmfparser/whileTest.txt @@ -3,8 +3,10 @@ while 3 < 5 do a = 7 od = (module) parent: global -== Classes: == Variables: +varDef a id: 2 namedValue: 1 value: 3 succ: 4 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 + const id: 3 value: 20 :1:8 == Body: varDef a id: 2 namedValue: 1 value: 3 succ: 4 :1:4 namedValue a id: 1 attr: 0x0 :1:4 diff --git a/unittests/rplmfparser_test.cpp b/unittests/rplmfparser_test.cpp index 8b2424d..14f1174 100644 --- a/unittests/rplmfparser_test.cpp +++ b/unittests/rplmfparser_test.cpp @@ -155,6 +155,22 @@ public: "rc endf"); parser.parse(); checkAST("meth2.txt", __LINE__); + setSource("func Int max(Int a, Int b):\n Int rc = a;\n" + "if a < b then rc = b; fi\nrc\n" + "endf\n" + "func Int max(const Int a, Int b, Int c):\n" + "max(a, max(b, c))\n" + "endf"); + parser.parse(); + checkAST("meth3.txt", __LINE__); + setSource("func Int max(const Int a, Int b, Int c):\n" + "func Int max(Int a, Int b):\n Int rc = a;\n" + "if a < b then rc = b; fi\nrc\n" + "endf\n" + "max(a, max(b, c))\n" + "endf"); + parser.parse(); + checkAST("meth4.txt", __LINE__); } virtual void doIt(void) { methodTest(); -- 2.39.5