From: <ibr...@us...> - 2013-05-16 15:29:39
|
Revision: 4645 http://sourceforge.net/p/tora/code/4645 Author: ibre5041 Date: 2013-05-16 15:29:36 +0000 (Thu, 16 May 2013) Log Message: ----------- Cpp.stg/AST.stg cleanup, CommonTree reflects Java API Modified Paths: -------------- branches/tora3/extlibs/libantlr3cpp-3.5.1/include/antlr3commontree.hpp branches/tora3/extlibs/libantlr3cpp-3.5.1/include/antlr3commontree.inl branches/tora3/extlibs/libantlr3cpp-3.5.1/include/antlr3commontreeadaptor.inl branches/tora3/extlibs/libantlr3cpp-3.5.1/include/antlr3defs.hpp branches/tora3/extlibs/parsing.cpp/Makefile branches/tora3/extlibs/parsing.cpp/MySQLGuiLexer.g branches/tora3/extlibs/parsing.cpp/OraclePLSQL.g branches/tora3/extlibs/parsing.cpp/UserMiniTraits.hpp branches/tora3/extlibs/parsing.cpp/antlr-complete-3.5.1-SNAPSHOT.jar branches/tora3/extlibs/parsing.cpp/input/simple01.sql branches/tora3/extlibs/parsing.cpp/org/antlr/codegen/templates/Cpp/AST.stg branches/tora3/extlibs/parsing.cpp/org/antlr/codegen/templates/Cpp/Cpp.stg branches/tora3/extlibs/parsing.cpp/s0.cpp Modified: branches/tora3/extlibs/libantlr3cpp-3.5.1/include/antlr3commontree.hpp =================================================================== --- branches/tora3/extlibs/libantlr3cpp-3.5.1/include/antlr3commontree.hpp 2013-05-15 20:25:01 UTC (rev 4644) +++ branches/tora3/extlibs/libantlr3cpp-3.5.1/include/antlr3commontree.hpp 2013-05-16 15:29:36 UTC (rev 4645) @@ -45,55 +45,22 @@ typedef typename ImplTraits::StringType StringType; typedef typename ImplTraits::CommonTokenType CommonTokenType; typedef typename ImplTraits::TreeType TreeType; - typedef CommonTree TokenType; + //typedef CommonTree TokenType; typedef typename AllocPolicyType::template VectorType<TreeType*> ChildrenType; typedef typename AllocPolicyType::template ListType<TreeType*> ChildListType; -private: - /// The list of all the children that belong to this node. They are not part of the node - /// as they belong to the common tree node that implements this. - /// - ChildrenType m_children; - - /// This is used to store the current child index position while descending - /// and ascending trees as the tree walk progresses. - /// - ANTLR_MARKER m_savedIndex; - - /// Start token index that encases this tree - /// - ANTLR_MARKER m_startIndex; - - /// End token that encases this tree - /// - ANTLR_MARKER m_stopIndex; - - /// A single token, this is the payload for the tree - /// - CommonTokenType* m_token; - - /// Points to the node that has this node as a child. - /// If this is NULL, then this is the root node. - /// - CommonTree* m_parent; - - /// What index is this particular node in the child list it - /// belongs to? - /// - ANTLR_INT32 m_childIndex; - public: CommonTree(); CommonTree( CommonTokenType* token ); CommonTree( CommonTree* token ); CommonTree( CommonTree& ctree ); + ~CommonTree(); CommonTokenType* getToken() const; void setToken(CommonTokenType*); ChildrenType& getChildren(); const ChildrenType& getChildren() const; - ChildrenType* get_children_p(); ANTLR_INT32 getChildIndex() const; TreeType* getParent() const; @@ -110,7 +77,7 @@ /// Add all elements of the supplied list as children of this node /// void addChildren(const ChildListType& kids); - void createChildrenList(); + TreeType* deleteChild(ANTLR_UINT32 i); /// Delete children from start to stop and replace with t even if t is /// a list (nil-root tree). Num of children can increase or decrease. @@ -132,10 +99,38 @@ void setChild(ANTLR_UINT32 i, TreeType* child); StringType toStringTree(); StringType toString(); - void freshenPACIndexesAll(); - void freshenPACIndexes(ANTLR_UINT32 offset); - void reuse(); - ~CommonTree(); + void freshenParentAndChildIndexes(); + void freshenParentAndChildIndexes(ANTLR_UINT32 offset); + void freshenParentAndChildIndexesDeeply(); + void freshenParentAndChildIndexesDeeply(ANTLR_UINT32 offset); + +private: + /// Start token index that encases this tree + /// + ANTLR_MARKER m_startIndex; + + /// End token that encases this tree + /// + ANTLR_MARKER m_stopIndex; + + /// What index is this particular node in the child list it + /// belongs to? + /// + ANTLR_INT32 m_childIndex; + + /// The list of all the children that belong to this node. They are not part of the node + /// as they belong to the common tree node that implements this. + /// + ChildrenType m_children; + + /// A single token, this is the payload for the tree + /// + CommonTokenType* m_token; + + /// Points to the node that has this node as a child. + /// If this is NULL, then this is the root node. + /// + CommonTree* m_parent; }; ANTLR_END_NAMESPACE() Modified: branches/tora3/extlibs/libantlr3cpp-3.5.1/include/antlr3commontree.inl =================================================================== --- branches/tora3/extlibs/libantlr3cpp-3.5.1/include/antlr3commontree.inl 2013-05-15 20:25:01 UTC (rev 4644) +++ branches/tora3/extlibs/libantlr3cpp-3.5.1/include/antlr3commontree.inl 2013-05-16 15:29:36 UTC (rev 4645) @@ -3,46 +3,42 @@ template<class ImplTraits> CommonTree<ImplTraits>::CommonTree() { - m_savedIndex = 0; - m_startIndex = 0; - m_stopIndex = 0; + m_startIndex = -1; + m_stopIndex = -1; + m_childIndex = -1; m_token = NULL; m_parent = NULL; - m_childIndex = 0; } template<class ImplTraits> CommonTree<ImplTraits>::CommonTree( CommonTree& ctree ) :m_children( ctree.m_children) { - m_savedIndex = ctree.m_savedIndex; m_startIndex = ctree.m_startIndex; m_stopIndex = ctree.m_stopIndex; + m_childIndex = ctree.m_childIndex; m_token = ctree.m_token; m_parent = ctree.m_parent; - m_childIndex = ctree.m_childIndex; } template<class ImplTraits> CommonTree<ImplTraits>::CommonTree( CommonTokenType* token ) { - m_savedIndex = 0; - m_startIndex = 0; - m_stopIndex = 0; + m_startIndex = -1; + m_stopIndex = -1; + m_childIndex = -1; m_token = token; m_parent = NULL; - m_childIndex = 0; } template<class ImplTraits> CommonTree<ImplTraits>::CommonTree( CommonTree* tree ) { - m_savedIndex = 0; - m_startIndex = 0; - m_stopIndex = 0; + m_startIndex = -1; + m_stopIndex = -1; + m_childIndex = -1; m_token = tree->getToken(); m_parent = NULL; - m_childIndex = 0; } template<class ImplTraits> @@ -70,29 +66,19 @@ } template<class ImplTraits> -typename CommonTree<ImplTraits>::ChildrenType* CommonTree<ImplTraits>::get_children_p() -{ - return &m_children; -} - -template<class ImplTraits> void CommonTree<ImplTraits>::addChild(TreeType* child) { - ANTLR_UINT32 n; - ANTLR_UINT32 i; - if (child == NULL) return; ChildrenType& child_children = child->getChildren(); - ChildrenType& tree_children = this->getChildren(); + //ChildrenType& tree_children = this->getChildren(); if (child->isNilNode() == true) { - if ( !child_children.empty() && child_children == tree_children ) + if ( !child_children.empty() && child_children == m_children ) { // TODO: Change to exception rather than ANTLR3_FPRINTF? - // fprintf(stderr, "ANTLR3: An attempt was made to add a child list to itself!\n"); return; } @@ -101,55 +87,42 @@ // if ( !child_children.empty() ) { - if (tree_children.empty()) + if (!m_children.empty()) { + // Need to copy the children + ANTLR_UINT32 n = child_children.size(); + for (ANTLR_UINT32 i = 0; i < n; i++) + { + TreeType* entry = child_children.at(i); + // ANTLR3 lists can be sparse, unlike Array Lists (TODO: really?) + if (entry != NULL) + m_children.push_back(entry); + entry->setParent(this); + entry->setChildIndex(m_children.size()-1); + } + } else { // We are build ing the tree structure here, so we need not // worry about duplication of pointers as the tree node // factory will only clean up each node once. So we just // copy in the child's children pointer as the child is // a nil node (has not root itself). // - tree_children.swap( child_children ); - this->freshenPACIndexesAll(); + m_children.swap( child_children ); + this->freshenParentAndChildIndexes(); } - else - { - // Need to copy the children - // - n = child_children.size(); - - for (i = 0; i < n; i++) - { - TreeType* entry; - entry = child_children[i]; - - // ANTLR3 lists can be sparse, unlike Array Lists - // - if (entry != NULL) - { - tree_children.push_back(entry); - } - } - } } } else { // Tree we are adding is not a Nil and might have children to copy - // - if (tree_children.empty()) - { - // No children in the tree we are adding to, so create a new list on - // the fly to hold them. - // - this->createChildrenList(); - } - tree_children.push_back( child ); + m_children.push_back( child ); + child->setParent(this); + child->setChildIndex(m_children.size()-1); } } template<class ImplTraits> -void CommonTree<ImplTraits>::addChildren(const ChildListType& kids) +void CommonTree<ImplTraits>::addChildren(const ChildListType& kids) { for( typename ChildListType::const_iterator iter = kids.begin(); iter != kids.end(); ++iter ) @@ -158,19 +131,14 @@ } } -//dummy one, as vector is always there template<class ImplTraits> -void CommonTree<ImplTraits>::createChildrenList() -{ -} - -template<class ImplTraits> typename CommonTree<ImplTraits>::TreeType* CommonTree<ImplTraits>::deleteChild(ANTLR_UINT32 i) { if( m_children.empty() ) return NULL; - - return m_children.erase( m_children.begin() + i); + TreeType* killed = m_children.erase( m_children.begin() + i); + this->freshenParentAndChildIndexes(i); + return killed; } template<class ImplTraits> @@ -321,33 +289,23 @@ template<class ImplTraits> ANTLR_UINT32 CommonTree<ImplTraits>::getCharPositionInLine() { - CommonTokenType* token; - token = m_token; - - if (token == NULL || (token->getCharPositionInLine() == -1) ) + if(m_token == NULL || (m_token->getCharPositionInLine() == -1) ) { - if (this->getChildCount() > 0) - { - TreeType* child; - - child = this->getChild(0); - - return child->getCharPositionInLine(); - } + if(this->getChildCount() > 0) + return this->getChild(0)->getCharPositionInLine(); return 0; } - return token->getCharPositionInLine(); + return m_token->getCharPositionInLine(); } template<class ImplTraits> typename CommonTree<ImplTraits>::TreeType* CommonTree<ImplTraits>::getChild(ANTLR_UINT32 i) { - if ( m_children.empty() - || i >= m_children.size() ) + if ( m_children.empty() || i >= m_children.size() ) { return NULL; } - return m_children[i]; + return m_children.at(i); } @@ -384,6 +342,8 @@ template<class ImplTraits> ANTLR_MARKER CommonTree<ImplTraits>::getStartIndex() const { + if( m_startIndex==-1 && m_token!=NULL) + return m_token->getTokenIndex(); return m_startIndex; } @@ -396,6 +356,8 @@ template<class ImplTraits> ANTLR_MARKER CommonTree<ImplTraits>::getStopIndex() const { + if( m_stopIndex==-1 && m_token!=NULL) + return m_token->getTokenIndex(); return m_stopIndex; } @@ -408,14 +370,10 @@ template<class ImplTraits> ANTLR_UINT32 CommonTree<ImplTraits>::getType() { - if (this == NULL) - { - return 0; - } + if (m_token == NULL) + return CommonTokenType::TOKEN_INVALID; else - { return m_token->getType(); - } } template<class ImplTraits> @@ -443,21 +401,13 @@ template<class ImplTraits> ANTLR_UINT32 CommonTree<ImplTraits>::getLine() { - TreeType* cTree = this; - CommonTokenType* token; - token = cTree->get_token(); - - if (token == NULL || token->getLine() == 0) + if(m_token == NULL || m_token->getLine() == 0) { if ( this->getChildCount() > 0) - { - TreeType* child; - child = this->getChild(0); - return child->getLine(); - } + return this->getChild(0)->getLine(); return 0; } - return token->getLine(); + return m_token->getLine(); } template<class ImplTraits> @@ -467,121 +417,117 @@ } template<class ImplTraits> -bool CommonTree<ImplTraits>::isNilNode() +bool CommonTree<ImplTraits>::isNilNode() { // This is a Nil tree if it has no payload (Token in our case) - // if(m_token == NULL) - { return true; - } else - { return false; - } } template<class ImplTraits> -void CommonTree<ImplTraits>::setChild(ANTLR_UINT32 i, TreeType* child) +void CommonTree<ImplTraits>::setChild(ANTLR_UINT32 i, TreeType* child) { - if( m_children.size() >= i ) + if( child==NULL) + return; + + if( child->isNilNode()) + { + // TODO: throw IllegalArgumentException + return; + } + + if( m_children.size() <= i ) m_children.resize(i+1); + m_children[i] = child; + child->setParent(this); + child->setChildIndex(i); } template<class ImplTraits> typename CommonTree<ImplTraits>::StringType CommonTree<ImplTraits>::toStringTree() { - StringType string; - ANTLR_UINT32 i; - ANTLR_UINT32 n; - TreeType* t; + StringType retval; if( m_children.empty() ) - { return this->toString(); - } /* Need a new string with nothing at all in it. */ - if (this->isNilNode() == false) + if(this->isNilNode() == false) { - string.append("("); - string.append(this->toString()); - string.append(" "); + retval.append("("); + retval.append(this->toString()); + retval.append(" "); } if ( !m_children.empty()) { - n = m_children.size(); - - for (i = 0; i < n; i++) + ANTLR_UINT32 n = m_children.size(); + for (ANTLR_UINT32 i = 0; i < n; i++) { - t = m_children[i]; - + TreeType *t = m_children.at(i); if (i > 0) { - string.append(" "); + retval.append(" "); } - string.append(t->toStringTree()); + retval.append(t->toStringTree()); } } if (this->isNilNode() == false) { - string.append(")"); + retval.append(")"); } - - return string; + return retval; } template<class ImplTraits> typename CommonTree<ImplTraits>::StringType CommonTree<ImplTraits>::toString() { - if (this->isNilNode() ) - { - StringType nilNode; - - nilNode = "nil"; - - return nilNode; - } - + if( this->isNilNode()) + return StringType("nil"); return m_token->getText(); } template<class ImplTraits> -void CommonTree<ImplTraits>::freshenPACIndexesAll() +void CommonTree<ImplTraits>::freshenParentAndChildIndexes() { - this->freshenPACIndexes(0); + this->freshenParentAndChildIndexes(0); } template<class ImplTraits> -void CommonTree<ImplTraits>::freshenPACIndexes(ANTLR_UINT32 offset) +void CommonTree<ImplTraits>::freshenParentAndChildIndexes(ANTLR_UINT32 offset) { - ANTLR_UINT32 count; - ANTLR_UINT32 c; - - count = this->getChildCount(); // How many children do we have - + ANTLR_UINT32 count = this->getChildCount(); // Loop from the supplied index and set the indexes and parent - // - for (c = offset; c < count; c++) + for (ANTLR_UINT32 c = offset; c < count; c++) { - TreeType* child; - - child = this->getChild(c); - + TreeType* child = this->getChild(c); child->setChildIndex(c); child->setParent(this); } } template<class ImplTraits> -void CommonTree<ImplTraits>::reuse() +void CommonTree<ImplTraits>::freshenParentAndChildIndexesDeeply() { - delete this; //memory re-use should be taken by the library user + this->freshenParentAndChildIndexes(0); } template<class ImplTraits> +void CommonTree<ImplTraits>::freshenParentAndChildIndexesDeeply(ANTLR_UINT32 offset) +{ + ANTLR_UINT32 count = this->getChildCount(); + for (ANTLR_UINT32 c = offset; c < count; c++) { + TreeType* child = getChild(c); + child->setChildIndex(c); + child->setParent(this); + child->freshenParentAndChildIndexesDeeply(); + } +} + +template<class ImplTraits> CommonTree<ImplTraits>::~CommonTree() { } Modified: branches/tora3/extlibs/libantlr3cpp-3.5.1/include/antlr3commontreeadaptor.inl =================================================================== --- branches/tora3/extlibs/libantlr3cpp-3.5.1/include/antlr3commontreeadaptor.inl 2013-05-15 20:25:01 UTC (rev 4644) +++ branches/tora3/extlibs/libantlr3cpp-3.5.1/include/antlr3commontreeadaptor.inl 2013-05-16 15:29:36 UTC (rev 4645) @@ -140,8 +140,7 @@ newRootTree = newRootTree->getChild(0); // Reclaim the old nilNode() - // - saveRoot->reuse(); + delete saveRoot; } /* Add old root into new root. addChild takes care of the case where oldRoot @@ -163,7 +162,7 @@ // don't know necessarilly know how to do this for the real node, we just ask the tree itself // to do it. // - oldRootTree->reuse(); + delete oldRootTree; } /* Always returns new root structure */ @@ -670,7 +669,7 @@ // been abandoned and would be lost in the node factory. However // nodes can be flagged as resuable to prevent this terrible waste // - saveRoot->reuse(); + delete saveRoot; } } return root; Modified: branches/tora3/extlibs/libantlr3cpp-3.5.1/include/antlr3defs.hpp =================================================================== --- branches/tora3/extlibs/libantlr3cpp-3.5.1/include/antlr3defs.hpp 2013-05-15 20:25:01 UTC (rev 4644) +++ branches/tora3/extlibs/libantlr3cpp-3.5.1/include/antlr3defs.hpp 2013-05-16 15:29:36 UTC (rev 4645) @@ -98,8 +98,6 @@ #define ANTLR_BEGIN_NAMESPACE() namespace antlr3 { #define ANTLR_END_NAMESPACE() } -#define ANTLR_USE_64BIT - /* Common definitions come first */ #include <antlr3errors.hpp> Modified: branches/tora3/extlibs/parsing.cpp/Makefile =================================================================== --- branches/tora3/extlibs/parsing.cpp/Makefile 2013-05-15 20:25:01 UTC (rev 4644) +++ branches/tora3/extlibs/parsing.cpp/Makefile 2013-05-16 15:29:36 UTC (rev 4645) @@ -6,7 +6,7 @@ SOURCES = $(wildcard *.cpp) PSOURCES = $(wildcard PLSQLParser*.cpp) PLSQLLexer.cpp POBJS = $(PSOURCES:.cpp=.o) -GRAMMAROPTIONS=-report -Xconversiontimeout 1500000 -Xmultithreaded -Xwatchconversion +GRAMMAROPTIONS= -report -Xconversiontimeout 1500000 -Xmultithreaded -Xwatchconversion ANTLR = antlr-complete-3.5.1-SNAPSHOT.jar .SUFFIXES: @@ -18,7 +18,7 @@ TOBJS= utils.o -all: t0 m0 p0 s0 +all: t0 m0 p0 s0 s1 $(ANTLR): org/antlr/codegen/templates/Cpp/Cpp.stg \ org/antlr/codegen/templates/Cpp/AST.stg \ @@ -49,8 +49,11 @@ s0: s0.cpp SQLMini.tokens $(TOBJS) Makefile UserMiniTraits.hpp g++ $(CFLAGS) -DUSESTL $(INCLUDES) $(TOBJS) s0.cpp SQLMiniLexer.cpp SQLMiniParser.cpp $(LIBS) -o $@ +s1: s1.cpp S.tokens $(TOBJS) Makefile UserMiniTraits.hpp + g++ $(CFLAGS) -DUSESTL $(INCLUDES) $(TOBJS) s1.cpp SLexer.cpp SParser.cpp $(LIBS) -o $@ + clean: - rm -f *.o *GuiLexer*.[ch]pp PLSQLLexer*.[ch]pp PLSQL*[ch]pp t0 t1 t2 t3 t4 m0 *.tokens SQLMini*.[ch]pp + rm -f *.o *GuiLexer*.[ch]pp PLSQLLexer*.[ch]pp PLSQL*[ch]pp t0 t1 t2 t3 t4 m0 s0 s1 *.tokens SQLMini*.[ch]pp %.u: %.g @echo "Bulding dependencies for "$< Modified: branches/tora3/extlibs/parsing.cpp/MySQLGuiLexer.g =================================================================== --- branches/tora3/extlibs/parsing.cpp/MySQLGuiLexer.g 2013-05-15 20:25:01 UTC (rev 4644) +++ branches/tora3/extlibs/parsing.cpp/MySQLGuiLexer.g 2013-05-16 15:29:36 UTC (rev 4645) @@ -1104,7 +1104,7 @@ fragment USER_VAR_SUBFIX4: ( 'A'..'Z' | 'a'..'z' | '_' | '$' | '0'..'9' | DOT )+ ; // basic const data definition --------------------------------------------------------------- -STRING_LITERAL: TEXT_STRING | USER_VAR_SUBFIX2 | USER_VAR_SUBFIX3 | USER_VAR_SUBFIX4; +STRING_LITERAL: TEXT_STRING /*| USER_VAR_SUBFIX2 | USER_VAR_SUBFIX3*/ | USER_VAR_SUBFIX4; // GUI RULES COMMENT_ML_PART Modified: branches/tora3/extlibs/parsing.cpp/OraclePLSQL.g =================================================================== --- branches/tora3/extlibs/parsing.cpp/OraclePLSQL.g 2013-05-15 20:25:01 UTC (rev 4644) +++ branches/tora3/extlibs/parsing.cpp/OraclePLSQL.g 2013-05-16 15:29:36 UTC (rev 4645) @@ -23,7 +23,7 @@ language=Cpp; backtrack=true; memoize=true; - //output=AST; + output=AST; //TokenLabelType=CommonTokenTypeCTT; } Modified: branches/tora3/extlibs/parsing.cpp/UserMiniTraits.hpp =================================================================== --- branches/tora3/extlibs/parsing.cpp/UserMiniTraits.hpp 2013-05-15 20:25:01 UTC (rev 4644) +++ branches/tora3/extlibs/parsing.cpp/UserMiniTraits.hpp 2013-05-16 15:29:36 UTC (rev 4645) @@ -15,6 +15,8 @@ namespace Antlr3Mini { class SQLMiniLexer; class SQLMiniParser; + class SLexer; + class SParser; }; namespace Antlr3Mini { @@ -28,6 +30,9 @@ typedef antlr3::Traits<SQLMiniLexer, SQLMiniParser, UserTraits> SQLMiniLexerTraits; typedef SQLMiniLexerTraits SQLMiniParserTraits; +typedef antlr3::Traits<SLexer, SParser, UserTraits> SLexerTraits; +typedef antlr3::Traits<SLexer, SParser, UserTraits> SParserTraits; + }; #endif Modified: branches/tora3/extlibs/parsing.cpp/antlr-complete-3.5.1-SNAPSHOT.jar =================================================================== (Binary files differ) Modified: branches/tora3/extlibs/parsing.cpp/input/simple01.sql =================================================================== --- branches/tora3/extlibs/parsing.cpp/input/simple01.sql 2013-05-15 20:25:01 UTC (rev 4644) +++ branches/tora3/extlibs/parsing.cpp/input/simple01.sql 2013-05-16 15:29:36 UTC (rev 4645) @@ -1,5 +1,7 @@ -#1234 +for update of xyz.a123.g5556 +/*#1234*/ --fdskfjsdfk +/* -1 - 1 1.5 + .5 @@ -20,3 +22,5 @@ , n'nchar literal' from dual select 1..10 from dd "gdgdgd" 'gfgdgd' fdfsfs ; +*/ + Modified: branches/tora3/extlibs/parsing.cpp/org/antlr/codegen/templates/Cpp/AST.stg =================================================================== --- branches/tora3/extlibs/parsing.cpp/org/antlr/codegen/templates/Cpp/AST.stg 2013-05-15 20:25:01 UTC (rev 4644) +++ branches/tora3/extlibs/parsing.cpp/org/antlr/codegen/templates/Cpp/AST.stg 2013-05-16 15:29:36 UTC (rev 4645) @@ -61,14 +61,27 @@ <super.ASTLabelType()> getTree() { return tree; } >> -ruleReturnMembersInit(value, prefix) ::= <% -<if(!prefix)> -tree = <value>; -<else> -tree = <prefix>.tree; -<endif> +...@re...leReturnMembersInit() ::= << +tree = NULL; +>> + +...@re...leReturnMembersCopy() ::= <% +tree = other.tree; const_cast\< <ruleDescriptor:returnStructName()>& >(other).tree = NULL; %> +...@re...leReturnMembersDelete() ::= << +//if(tree != NULL) +// delete tree; +>> + +//ruleReturnMembersInit(value, prefix) ::= <% +//<if(!prefix)> +//tree = <value>; +//<else> +//tree = <prefix>.tree; +//<endif> +//%> + /** Add a variable to track rule's return AST */ ruleDeclarations() ::= << <super.ruleDeclarations()> Modified: branches/tora3/extlibs/parsing.cpp/org/antlr/codegen/templates/Cpp/Cpp.stg =================================================================== --- branches/tora3/extlibs/parsing.cpp/org/antlr/codegen/templates/Cpp/Cpp.stg 2013-05-15 20:25:01 UTC (rev 4644) +++ branches/tora3/extlibs/parsing.cpp/org/antlr/codegen/templates/Cpp/Cpp.stg 2013-05-16 15:29:36 UTC (rev 4645) @@ -546,7 +546,7 @@ <endif> %> -headerReturnScope(ruleDescriptor) ::= "<returnScope(...)>" +headerReturnScope(ruleDescriptor) ::= "<returnScope(scope=ruleDescriptor.returnScope)>" headerReturnType(ruleDescriptor) ::= <% <if(LEXER)> @@ -1271,15 +1271,13 @@ ruleInitializations() ::= << /* Initialize rule variables */ +<if(ruleDescriptor.returnScope)> <if(ruleDescriptor.hasMultipleReturnValues)> -<ruleDescriptor.returnScope.attributes:{ a | -<if(a.initValue)>retval.<a.name> = <a.initValue>;<endif> -}> +<ruleDescriptor.returnScope.attributes:{ a | <if(a.initValue)>retval.<a.name> = <a.initValue>;<endif> }> <else> -<ruleDescriptor.returnScope.attributes:{ a | -<if(a.initValue)><a.name> = <a.initValue>;<endif> -}> +<ruleDescriptor.returnScope.attributes:{ a | <if(a.initValue)><a.name> = <a.initValue>;<endif> }> <endif> +<endif> <if(memoize)> <ruleDescriptor.name>_StartIndex = this->index();<\n> <endif> @@ -2092,35 +2090,26 @@ <endif> } - <if(dfa.specialStateSTs)> - ANTLR_UINT32 LA(ANTLR_INT32 i) - { - return m_ctx->LA(i); - } + <if(dfa.specialStateSTs)> + ANTLR_UINT32 LA(ANTLR_INT32 i) + { + return m_ctx->LA(i); + } - <if(PARSER)> - template\<typename PredType> - bool msynpred( PredType pred ) - { - return m_ctx->msynpred(pred); - } + <if(PARSER)> + const CtxType::CommonTokenType* LT(ANTLR_INT32 k) + { + return m_ctx->LT(k); + } + <endif> + <if(synpreds)> + template\<typename PredType> + bool msynpred( PredType pred ) + { + return m_ctx->msynpred(pred); + } + <endif> - const CtxType::CommonTokenType* LT(ANTLR_INT32 k) - { - return m_ctx->LT(k); - } - <endif> - - <if(LEXER)> - <if(synpreds)> - template\<typename PredType> - bool msynpred( PredType pred ) - { - return m_ctx->msynpred(pred); - } - <endif> - <endif> - ANTLR_INT32 specialStateTransition(CtxType * ctx, RecognizerType* recognizer, IntStreamType* is, ANTLR_INT32 s) { ANTLR_INT32 _s; @@ -2374,55 +2363,59 @@ { public: typedef <name>ImplTraits::RuleReturnValueType BaseType; -<else> -struct <ruleDescriptor.grammar.recognizerName>_<ruleDescriptor:returnStructName()> -{ - <name>ImplTraits::<recognizer.ASTLabelType> start; - <name>ImplTraits::<recognizer.ASTLabelType> stop; -<endif> - <@ruleReturnMembers()> - <ruleDescriptor.returnScope.attributes:{it |<it.type> <it.name>;}; separator="\n"> -<if(!TREE_PARSER)> - <ruleDescriptor:returnStructName()>() : BaseType() { <ruleReturnMembersInit("NULL")> } - <ruleDescriptor:returnStructName()>( BaseParserType* parser ) : BaseType(parser) { <ruleReturnMembersInit("NULL")> } - <ruleDescriptor:returnStructName()>( const <ruleDescriptor:returnStructName()>& n ) : BaseType(n) - <if(ruleDescriptor.returnScope.attributes)> - , <ruleDescriptor.returnScope.attributes:{it | <it.name>(n.<it.name>) }; separator=","> + <ruleDescriptor:returnStructName()>() : BaseType() { init(); } + <ruleDescriptor:returnStructName()>( BaseParserType* parser ) : BaseType(parser) { init(); } + <ruleDescriptor:returnStructName()>( const <ruleDescriptor:returnStructName()>& other ) : BaseType(other) + <if(scope)> + , <scope.attributes:{it | <it.name>(other.<it.name>) }; separator=","> <endif> { - <ruleReturnMembersInit("n","n")> + copy(other); } - + ~<ruleDescriptor:returnStructName()>() + { + <@ruleReturnMembersDelete()> + } + <ruleDescriptor:returnStructName()>& - operator=( const <ruleDescriptor:returnStructName()>& n ) + operator=( const <ruleDescriptor:returnStructName()>& other ) { - BaseType::operator=( n ); - <ruleDescriptor.returnScope.attributes:{it | <it.name> = n.<it.name>; }; separator="\n"> - <ruleReturnMembersInit("n","n")> - return *this; + BaseType::operator=( other ); + <if(ruleDescriptor.returnScope)> + <scope.attributes:{it | <it.name> = other.<it.name>; }; separator="\n"> + <endif> + copy(other); + return *this; } + <@ruleReturnMembers()> + void init() { <@ruleReturnMembersInit()> } + void copy( const <ruleDescriptor:returnStructName()>& other) { <@ruleReturnMembersCopy()> } <else> - <ruleDescriptor.grammar.recognizerName>_<ruleDescriptor:returnStructName()>( const <ruleDescriptor.grammar.recognizerName>_<ruleDescriptor:returnStructName()>& n ) - <if(ruleDescriptor.returnScope.attributes)> - <ruleDescriptor.returnScope.attributes:{it | <it.name>(n.<it.name>) }; separator=","> +struct <ruleDescriptor:returnStructName()> +{ +public: + <name>ImplTraits::<recognizer.ASTLabelType> start; + <name>ImplTraits::<recognizer.ASTLabelType> stop; + <ruleDescriptor:returnStructName()>( const <ruleDescriptor:returnStructName()>& other ) + <if(scope.attributes)> + <scope.attributes:{it | <it.name>(other.<it.name>) }; separator=","> <endif> { - start = n.start; - stop = n.stop; + start = other.start; + stop = other.stop; } - <ruleDescriptor.grammar.recognizerName>_<ruleDescriptor:returnStructName()>& - operator=( const <ruleDescriptor.grammar.recognizerName>_<ruleDescriptor:returnStructName()>& n ) + <ruleDescriptor:returnStructName()>& + operator=( const <ruleDescriptor:returnStructName()>& other ) { - start = n.start; - stop = n.stop; + start = other.start; + stop = other.stop; - <ruleDescriptor.returnScope.attributes:{it | <it.name> = n.<it.name>; }; separator="\n"> - return *this; + <scope.attributes:{it | <it.name> = other.<it.name>; }; separator="\n"> + return *this; } - <endif> - + <if(scope)><scope.attributes:{it |<it.type> <it.name>;}; separator="\n"><endif> }; <endif> Modified: branches/tora3/extlibs/parsing.cpp/s0.cpp =================================================================== --- branches/tora3/extlibs/parsing.cpp/s0.cpp 2013-05-15 20:25:01 UTC (rev 4644) +++ branches/tora3/extlibs/parsing.cpp/s0.cpp 2013-05-16 15:29:36 UTC (rev 4645) @@ -139,7 +139,7 @@ (ANTLR_UINT8*)fName); input->setUcaseLA(true); - + // Our input stream is now open and all set to go, so we can create a new instance of our // lexer and set the lexer input to our input stream: // (file | memory | ?) --> inputstream -> lexer --> tokenstream --> parser ( --> treeparser )? This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |