diff options
author | Christopher L. Conway <christopherleeconway@gmail.com> | 2010-02-23 17:15:44 +0000 |
---|---|---|
committer | Christopher L. Conway <christopherleeconway@gmail.com> | 2010-02-23 17:15:44 +0000 |
commit | 4c1cb16059e6e484581873dfb3103851183ccc72 (patch) | |
tree | 692ccbf8b07aef6ca8b8adc96a5de50cc408d0b1 /src/parser/antlr_parser.cpp | |
parent | 7115bef6bc8aac38b5e718db8fcb39c26ef4954a (diff) |
Minor optimizations to parser (use const string& for ids, keep only one binding in symtab)
Diffstat (limited to 'src/parser/antlr_parser.cpp')
-rw-r--r-- | src/parser/antlr_parser.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/parser/antlr_parser.cpp b/src/parser/antlr_parser.cpp index 28cee62e7..066cb3aed 100644 --- a/src/parser/antlr_parser.cpp +++ b/src/parser/antlr_parser.cpp @@ -48,7 +48,7 @@ AntlrParser::AntlrParser(antlr::TokenStream& lexer, int k) : antlr::LLkParser(lexer, k), d_checksEnabled(true) { } -Expr AntlrParser::getSymbol(std::string name, SymbolType type) { +Expr AntlrParser::getSymbol(const std::string& name, SymbolType type) { Assert( isDeclared(name, type) ); @@ -63,40 +63,40 @@ Expr AntlrParser::getSymbol(std::string name, SymbolType type) { } } -Expr AntlrParser::getVariable(std::string name) { +Expr AntlrParser::getVariable(const std::string& name) { return getSymbol(name, SYM_VARIABLE); } -Expr AntlrParser::getFunction(std::string name) { +Expr AntlrParser::getFunction(const std::string& name) { return getSymbol(name, SYM_FUNCTION); } const Type* -AntlrParser::getType(std::string var_name, +AntlrParser::getType(const std::string& var_name, SymbolType type) { Assert( isDeclared(var_name, type) ); const Type* t = getSymbol(var_name,type).getType(); return t; } -const Type* AntlrParser::getSort(std::string name) { +const Type* AntlrParser::getSort(const std::string& name) { Assert( isDeclared(name, SYM_SORT) ); const Type* t = d_sortTable.getObject(name); return t; } /* Returns true if name is bound to a boolean variable. */ -bool AntlrParser::isBoolean(std::string name) { +bool AntlrParser::isBoolean(const std::string& name) { return isDeclared(name, SYM_VARIABLE) && getType(name)->isBoolean(); } /* Returns true if name is bound to a function. */ -bool AntlrParser::isFunction(std::string name) { +bool AntlrParser::isFunction(const std::string& name) { return isDeclared(name, SYM_FUNCTION) && getType(name)->isFunction(); } /* Returns true if name is bound to a function returning boolean. */ -bool AntlrParser::isPredicate(std::string name) { +bool AntlrParser::isPredicate(const std::string& name) { return isDeclared(name, SYM_FUNCTION) && getType(name)->isPredicate(); } @@ -168,7 +168,7 @@ const Type* AntlrParser::predicateType(const std::vector<const Type*>& sorts) { } Expr -AntlrParser::mkVar(const std::string name, const Type* type) { +AntlrParser::mkVar(const std::string& name, const Type* type) { Debug("parser") << "mkVar(" << name << "," << *type << ")" << std::endl; Assert( !isDeclared(name) ) ; Expr expr = d_exprManager->mkVar(type, name); @@ -189,7 +189,7 @@ AntlrParser::mkVars(const std::vector<std::string> names, const Type* -AntlrParser::newSort(std::string name) { +AntlrParser::newSort(const std::string& name) { Debug("parser") << "newSort(" << name << ")" << std::endl; Assert( !isDeclared(name, SYM_SORT) ) ; const Type* type = d_exprManager->mkSort(name); @@ -279,7 +279,7 @@ void AntlrParser::setExpressionManager(ExprManager* em) { d_exprManager = em; } -bool AntlrParser::isDeclared(string name, SymbolType type) { +bool AntlrParser::isDeclared(const std::string& name, SymbolType type) { switch(type) { case SYM_VARIABLE: // Functions share var namespace case SYM_FUNCTION: @@ -291,14 +291,14 @@ bool AntlrParser::isDeclared(string name, SymbolType type) { } } -void AntlrParser::parseError(string message) +void AntlrParser::parseError(const std::string& message) throw (antlr::SemanticException) { throw antlr::SemanticException(message, getFilename(), LT(1).get()->getLine(), LT(1).get()->getColumn()); } -void AntlrParser::checkDeclaration(string varName, +void AntlrParser::checkDeclaration(const std::string& varName, DeclarationCheck check, SymbolType type) throw (antlr::SemanticException) { @@ -327,7 +327,7 @@ void AntlrParser::checkDeclaration(string varName, } } -void AntlrParser::checkFunction(string name) +void AntlrParser::checkFunction(const std::string& name) throw (antlr::SemanticException) { if( d_checksEnabled && !isFunction(name) ) { parseError("Expecting function symbol, found '" + name + "'"); |