void BinaryCompArithOpAST::renameAttrRef(const SchemaMapString* schemaMap) { RefAST childAST = getFirstChild(); assert (childAST); (RefBasicAST(childAST))->renameAttrRef(schemaMap); if (childAST->getNextSibling()) { (RefBasicAST(childAST->getNextSibling()))->renameAttrRef(schemaMap); } }
void BinaryCompArithOpAST::getReferredAttributes(set<string>& referredAttrs) { RefAST childAST = getFirstChild(); assert (childAST); (RefBasicAST(childAST))->getReferredAttributes(referredAttrs); if (childAST->getNextSibling()) { (RefBasicAST(childAST->getNextSibling()))-> getReferredAttributes(referredAttrs); } }
void BinaryCompArithOpAST::write(ostream& out) { RefAST childAST = getFirstChild(); assert (childAST); (RefBasicAST(childAST))->write(out); out<<getText(); if (childAST->getNextSibling()) { (RefBasicAST(childAST->getNextSibling()))->write(out); } }
int main(int argc, char *argv[]) { if (argc < 1) return 0; ANTLR_USING_NAMESPACE(std); ANTLR_USING_NAMESPACE(antlr); ANTLR_USING_NAMESPACE(Asm); char *filename = argv[1]; if (!filename) exit(1); try { ifstream input(filename); AsmLexer lexer(input); TokenBuffer buffer(lexer); AsmParser parser(buffer); ASTFactory ast_factory; parser.initializeASTFactory(ast_factory); parser.setASTFactory(&ast_factory); parser.asmFile(); RefAST a = parser.getAST(); AsmTreeParser tree_parser; tree_parser.init(false, false, false); tree_parser.initializeASTFactory(ast_factory); tree_parser.setASTFactory(&ast_factory); tree_parser.asmFile(a); #if 0 cout << "List:" << endl; cout << a->toStringList() << endl; cout << "Tree:" << endl; cout << a->toStringTree() << endl; #endif } catch (ANTLRException& e) { cerr << "exception: " << e.getMessage() << endl; return 2; } catch (exception& e) { cerr << "exception: " << e.what() << endl; return 3; } return 0; }
void TreeParser::matchNot(RefAST t, int ttype) { //ANTLR_USE_NAMESPACE(std)cout << "match(" << ttype << "); cursor is " << t.toString() << ANTLR_USE_NAMESPACE(std)endl; if ( !t || t==ASTNULL || t->getType()==ttype ) { throw MismatchedTokenException(); } }
// Expected BitSet / not BitSet MismatchedTokenException::MismatchedTokenException( const char* const* tokenNames_, const int numTokens_, RefAST node_, BitSet set_, bool matchNot ) : RecognitionException("Mismatched Token","<AST>",-1,-1) , token(0) , node(node_) , tokenText( (node_ ? node_->toString(): ANTLR_USE_NAMESPACE(std)string("<empty tree>")) ) , mismatchType(matchNot ? NOT_SET : SET) , set(set_) , tokenNames(tokenNames_) , numTokens(numTokens_) { }
// Expected range / not range MismatchedTokenException::MismatchedTokenException( const char* const* tokenNames_, const int numTokens_, RefAST node_, int lower, int upper_, bool matchNot ) : RecognitionException("Mismatched Token","<AST>",-1,-1) , token(0) , node(node_) , tokenText( (node_ ? node_->toString(): ANTLR_USE_NAMESPACE(std)string("<empty tree>")) ) , mismatchType(matchNot ? NOT_RANGE : RANGE) , expecting(lower) , upper(upper_) , tokenNames(tokenNames_) , numTokens(numTokens_) { }
/** Create a new empty AST node; if the user did not specify * an AST node type, then create a default one: CommonAST. */ RefAST ASTFactory::create() { RefAST node = nodeFactories[0]->second(); node->setType(Token::INVALID_TYPE); return node; }
RefAST ASTFactory::create(int type) { RefAST t = nodeFactories[type]->second(); t->initialize(type,""); return t; }
/**Make sure current lookahead symbol matches the given set * Throw an exception upon mismatch, which is caught by either the * error handler or by the syntactic predicate. */ void TreeParser::match(RefAST t, const BitSet& b) { if ( !t || t==ASTNULL || !b.member(t->getType()) ) { throw MismatchedTokenException(); } }
RefAST ASTFactory::create(int type) { RefAST t = create(); t->initialize(type,""); return t; }
/** Create a new empty AST node; if the user did not specify * an AST node type, then create a default one: CommonAST. */ RefAST ASTFactory::create() { RefAST node = nodeFactory(); //new CommonASTNode(); node->setType(Token::INVALID_TYPE); return node; }
void TreeParser::matchNot(RefAST t, int ttype) { if ( !t || t == ASTNULL || t->getType() == ttype ) throw MismatchedTokenException( getTokenNames(), getNumTokens(), t, ttype, true ); }
/** Make sure current lookahead symbol matches the given set * Throw an exception upon mismatch, which is caught by either the * error handler or by the syntactic predicate. */ void TreeParser::match(RefAST t, const BitSet& b) { if ( !t || t==ASTNULL || !b.member(t->getType()) ) throw MismatchedTokenException( getTokenNames(), getNumTokens(), t, b, false ); }
virtual void match(RefAST t, int ttype) { if (!t || t == ASTNULL || t->getType() != ttype ) throw MismatchedTokenException( getTokenNames(), getNumTokens(), t, ttype, false ); }
while( t->right ) { t = t->right; n++; } return n; } return n; } void BaseAST::doWorkForFindAll( ANTLR_USE_NAMESPACE(std)vector<RefAST>& v, RefAST target,bool partialMatch) { // Start walking sibling lists, looking for matches. for (RefAST sibling=this; sibling; sibling=sibling->getNextSibling()) { if ( (partialMatch && sibling->equalsTreePartial(target)) || (!partialMatch && sibling->equalsTree(target)) ) { v.push_back(sibling); } // regardless of match or not, check any children for matches if ( sibling->getFirstChild() ) { RefBaseAST(sibling->getFirstChild())->doWorkForFindAll(v, target, partialMatch); } } } /** Is t an exact structural and equals() match of this tree. The
void CommonAST::initialize(RefAST t) { setType(t->getType()); setText(t->getText()); }
void TreeParser::match(RefAST t, int ttype) { if (!t || t==ASTNULL || t->getType()!=ttype) throw MismatchedTokenException(); }