From: Baptiste L. <bl...@us...> - 2004-06-21 18:53:33
|
Update of /cvsroot/cpptool/CppParser/examples/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32593/examples/parser Modified Files: symboltabletestprocessor.cpp scope.cpp scope.h symboldeclarator.cpp symboltabletest.cpp Log Message: * added enum support to symbol table Index: symboldeclarator.cpp =================================================================== RCS file: /cvsroot/cpptool/CppParser/examples/parser/symboldeclarator.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** symboldeclarator.cpp 21 Jun 2004 13:49:30 -0000 1.4 --- symboldeclarator.cpp 21 Jun 2004 18:53:16 -0000 1.5 *************** *** 332,336 **** SymbolDeclarationPtr valueDeclaration = symbolTable_.declare( valueSymbol ); enumScope->addValue( valueDeclaration ); - //parentScope.add( } } --- 332,335 ---- Index: scope.h =================================================================== RCS file: /cvsroot/cpptool/CppParser/examples/parser/scope.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** scope.h 21 Jun 2004 13:49:30 -0000 1.4 --- scope.h 21 Jun 2004 18:53:16 -0000 1.5 *************** *** 234,237 **** --- 234,238 ---- void accept( ScopeVisitor &visitor ); SymbolDeclarationPtr resolve( const std::string &name ) const; + SymbolDeclarationPtr getMemberDeclaration( const std::string &name ) const; SymbolDeclarationPtr memberResolve( const std::string &name ) const; std::string str() const; *************** *** 239,243 **** private: ! std::deque<SymbolDeclarationPtr> values_; }; --- 240,245 ---- private: ! typedef std::map<std::string, SymbolDeclarationPtr> Values; ! Values values_; }; Index: scope.cpp =================================================================== RCS file: /cvsroot/cpptool/CppParser/examples/parser/scope.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** scope.cpp 21 Jun 2004 13:49:30 -0000 1.4 --- scope.cpp 21 Jun 2004 18:53:16 -0000 1.5 *************** *** 1,3 **** --- 1,4 ---- #include "scope.h" + #include "stlhelper.h" namespace Parser { *************** *** 505,509 **** EnumScope::values() const { ! return CppUT::enumStl( values_ ); } --- 506,510 ---- EnumScope::values() const { ! return CppUT::enumStlMapValues( values_, CppUT::Type<SymbolDeclarationPtr>() ); } *************** *** 511,515 **** EnumScope::addValue( const SymbolDeclarationPtr &valueSymbol ) { ! values_.push_back( valueSymbol ); } --- 512,516 ---- EnumScope::addValue( const SymbolDeclarationPtr &valueSymbol ) { ! values_[ valueSymbol->name() ] = valueSymbol; } *************** *** 533,536 **** --- 534,545 ---- } + SymbolDeclarationPtr + EnumScope::getMemberDeclaration( const std::string &name ) const + { + if ( name == declaration()->name() ) + return declaration(); + return StlHelper::mapDefaultGet( values_, name, SymbolDeclarationPtr() ); + } + std::string EnumScope::str() const Index: symboltabletestprocessor.cpp =================================================================== RCS file: /cvsroot/cpptool/CppParser/examples/parser/symboltabletestprocessor.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** symboltabletestprocessor.cpp 20 Jun 2004 15:53:41 -0000 1.1 --- symboltabletestprocessor.cpp 21 Jun 2004 18:53:16 -0000 1.2 *************** *** 176,180 **** recordSpecfication( enumerationValues ); ! NodeSpecification enumerationValue( "enumeration_value", "value", nsHasBraceValue ); recordSpecfication( enumerationValue ); --- 176,181 ---- recordSpecfication( enumerationValues ); ! NodeSpecification enumerationValue( "enumeration_value", "value", nsHasBraceValue | nsHasChildren ); ! enumerationValue.addMandatoryChild( "references" ); recordSpecfication( enumerationValue ); Index: symboltabletest.cpp =================================================================== RCS file: /cvsroot/cpptool/CppParser/examples/parser/symboltabletest.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** symboltabletest.cpp 21 Jun 2004 13:49:30 -0000 1.7 --- symboltabletest.cpp 21 Jun 2004 18:53:16 -0000 1.8 *************** *** 49,52 **** --- 49,53 ---- void checkEnumerationValues( const Parser::EnumScopePtr &enumScope, const NodePtr &valuesNode ); + void checkEnumerationValue( const NodePtr &valueNode ); CppUT::Message makeMessage( const NodePtr &node, *************** *** 330,334 **** makeMessage( valuesNode, "Enumerator values do not match." ) ); ! // for each expected value: // resolve value name // check type --- 331,343 ---- makeMessage( valuesNode, "Enumerator values do not match." ) ); ! enumNode = valuesNode->children(); ! while ( enumNode.hasNext() ) ! checkEnumerationValue( enumNode.next() ); ! } ! ! ! void ! DeclarationChecker::checkEnumerationValue( const NodePtr &valueNode ) ! { // resolve value name // check type *************** *** 336,341 **** --- 345,356 ---- // check declarations // check references + + std::string valueName = valueNode->braceValue(); + Parser::SymbolDeclarationPtr declaration = memberResolve( valueName ); + CppUT::checkTrue( declaration, makeMessage( valueNode, "Declaration not found." ) ); + checkReferences( valueNode, declaration ); } + } // anonymous namespace |