From: Baptiste L. <bl...@us...> - 2004-06-20 15:53:53
|
Update of /cvsroot/cpptool/CppParser/examples/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv788/examples/parser Modified Files: parser.vcproj symboltabletest.cpp Added Files: symboltabletestprocessor.cpp symboltabletestprocessor.h Log Message: * extracted class SymbolTableTestProcessor Index: parser.vcproj =================================================================== RCS file: /cvsroot/cpptool/CppParser/examples/parser/parser.vcproj,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** parser.vcproj 20 Jun 2004 10:07:56 -0000 1.3 --- parser.vcproj 20 Jun 2004 15:53:41 -0000 1.4 *************** *** 498,506 **** <File RelativePath=".\refactoringtest.cpp"> - <FileConfiguration - Name="Debug|Win32"> - <Tool - Name="VCCLCompilerTool"/> - </FileConfiguration> </File> <File --- 498,501 ---- *************** *** 542,550 **** <File RelativePath=".\symboltabletest.cpp"> - <FileConfiguration - Name="Debug|Win32"> - <Tool - Name="VCCLCompilerTool"/> - </FileConfiguration> </File> <File --- 537,540 ---- *************** *** 552,555 **** --- 542,551 ---- </File> <File + RelativePath=".\symboltabletestprocessor.cpp"> + </File> + <File + RelativePath=".\symboltabletestprocessor.h"> + </File> + <File RelativePath=".\testproject.cpp"> </File> --- NEW FILE: symboltabletestprocessor.h --- #ifndef PARSER_SYMBOLTABLETESTPROCESSOR_H_INCLUDED # define PARSER_SYMBOLTABLETESTPROCESSOR_H_INCLUDED # include "lineprocessor.h" # include "nodeprocessor.h" class TestProject; class SymbolTableTestProcessor : public LineProcessor { public: SymbolTableTestProcessor( LocationTracker &tracker, TestProject &project ); NodePtr declarationsTree() const; private: // overridden from LineProcessor bool commentAllowed() const; void doProcessLine( const std::string &line ); bool doStateChange( const std::string &name, const std::string ¶meter ); void doProcessReadFile( const std::string &path, const std::string &content ); void doTerminateCurrentAction(); private: void processDeclarations(); std::string declarations_; std::string description_; std::string *currentLineBuffer_; unsigned declarationsStartLine_; NodePtr declarationsTree_; TestProject &project_; }; #endif // PARSER_SYMBOLTABLETESTPROCESSOR_H_INCLUDED --- NEW FILE: symboltabletestprocessor.cpp --- #include "symboltabletestprocessor.h" #include "testproject.h" // class DeclarationsNodeProcessor // /////////////////////////////////////////////////////////////// class DeclarationsNodeProcessor : public NodeProcessor { public: DeclarationsNodeProcessor(); }; DeclarationsNodeProcessor::DeclarationsNodeProcessor() { NodeSpecification globalDeclarations( "global_declarations", "", nsHasChildren ); globalDeclarations.addChild( "aggregate" ); globalDeclarations.addChild( "type_alias" ); globalDeclarations.addChild( "namespace" ); globalDeclarations.addChild( "anonymous_namespace" ); globalDeclarations.addChild( "variable" ); globalDeclarations.addChild( "enumeration" ); recordSpecfication( globalDeclarations ); setRootSpecification( globalDeclarations.specificationName() ); NodeSpecification declarations( "declarations", "declarations", nsHasColonStringListValue ); recordSpecfication( declarations ); NodeSpecification references( "references", "references", nsHasColonStringListValue ); recordSpecfication( references ); NodeSpecification aggregate( "aggregate", "aggregate", nsHasBraceValue | nsHasChildren ); aggregate.addChild( "aggregate_kind" ); aggregate.addMandatoryChild( "declarations" ); aggregate.addMandatoryChild( "references" ); aggregate.addChild( "aggregate_members" ); recordSpecfication( aggregate ); NodeSpecification aggregateKind( "aggregate_kind", "kind", nsHasColonEnumerationValue ); aggregateKind.addEnumerationValue( "class" ); aggregateKind.addEnumerationValue( "struct" ); aggregateKind.addEnumerationValue( "union" ); recordSpecfication( aggregateKind ); NodeSpecification aggregateMembers( "aggregate_members", "members", nsHasChildren ); aggregateMembers.addChild( "aggregate" ); aggregateMembers.addChild( "constructor" ); aggregateMembers.addChild( "destructor" ); aggregateMembers.addChild( "function" ); aggregateMembers.addChild( "type_alias" ); recordSpecfication( aggregateMembers ); NodeSpecification constructor( "constructor", "constructor", nsHasBraceValue | nsHasChildren ); constructor.addMandatoryChild( "prototypes" ); constructor.addChild( "function_definition" ); constructor.addChild( "function_parameters" ); recordSpecfication( constructor ); NodeSpecification destructor( "destructor", "destructor", nsHasBraceValue | nsHasChildren ); destructor.addMandatoryChild( "prototypes" ); destructor.addChild( "function_definition" ); destructor.addChild( "function_parameters" ); recordSpecfication( destructor ); NodeSpecification function( "function", "function", nsHasBraceValue | nsHasChildren ); function.addMandatoryChild( "prototypes" ); function.addMandatoryChild( "return_type" ); function.addChild( "function_definition" ); function.addChild( "function_parameters" ); recordSpecfication( function ); NodeSpecification prototypes( "prototypes", "prototypes", nsHasColonStringListValue ); recordSpecfication( prototypes ); NodeSpecification functionDefinition( "function_definition", "definition", nsHasColonStringListValue ); recordSpecfication( functionDefinition ); NodeSpecification returnType( "return_type", "return_type", nsHasColonNodeValue ); returnType.addChild( "type_built_in" ); returnType.addChild( "type_const" ); returnType.addChild( "type_volatile" ); returnType.addChild( "type_ref" ); returnType.addChild( "type_ptr" ); recordSpecfication( returnType ); NodeSpecification functionParameters( "function_parameters", "parameters", nsHasChildren ); functionParameters.addChild( "function_parameter" ); recordSpecfication( functionParameters ); NodeSpecification functionParameter( "function_parameter", "parameter", nsHasBraceValue | nsHasChildren ); functionParameter.addMandatoryChild( "type" ); recordSpecfication( functionParameter ); NodeSpecification type( "type", "type", nsHasColonNodeValue ); type.addChild( "type_built_in" ); type.addChild( "type_const" ); type.addChild( "type_volatile" ); type.addChild( "type_ref" ); type.addChild( "type_ptr" ); type.addChild( "type_type" ); recordSpecfication( type ); NodeSpecification typeBuiltIn( "type_built_in", "built_in", nsHasBraceValues ); recordSpecfication( typeBuiltIn ); NodeSpecification typeType( "type_type", "type", nsHasBraceValue ); recordSpecfication( typeType ); NodeSpecification typeConst( "type_const", "const", nsHasBraceNodeValue ); typeConst.addChild( "type_built_in" ); typeConst.addChild( "type_volatile" ); typeConst.addChild( "type_ref" ); typeConst.addChild( "type_ptr" ); typeConst.addChild( "type_type" ); recordSpecfication( typeConst ); NodeSpecification typeVolatile( "type_volatile", "volatile", nsHasBraceNodeValue ); typeVolatile.addChild( "type_built_in" ); typeVolatile.addChild( "type_const" ); typeVolatile.addChild( "type_ref" ); typeVolatile.addChild( "type_ptr" ); typeVolatile.addChild( "type_type" ); recordSpecfication( typeVolatile ); NodeSpecification typeRef( "type_ref", "ref", nsHasBraceNodeValue ); typeRef.addChild( "type_built_in" ); typeRef.addChild( "type_const" ); typeRef.addChild( "type_volatile" ); typeRef.addChild( "type_ptr" ); typeRef.addChild( "type_type" ); recordSpecfication( typeRef ); NodeSpecification typePtr( "type_ptr", "ptr", nsHasBraceNodeValue ); typePtr.addChild( "type_built_in" ); typePtr.addChild( "type_const" ); typePtr.addChild( "type_volatile" ); typePtr.addChild( "type_ref" ); typePtr.addChild( "type_ptr" ); typePtr.addChild( "type_type" ); recordSpecfication( typePtr ); NodeSpecification typeAlias( "type_alias", "type_alias", nsHasBraceValue | nsHasChildren ); typeAlias.addMandatoryChild( "declarations" ); typeAlias.addMandatoryChild( "references" ); typeAlias.addMandatoryChild( "type" ); recordSpecfication( typeAlias ); NodeSpecification namespaceSpec( "namespace", "namespace", nsHasBraceValue | nsHasChildren ); namespaceSpec.addMandatoryChild( "declarations" ); namespaceSpec.addMandatoryChild( "references" ); namespaceSpec.addMandatoryChild( "namespace_members" ); recordSpecfication( namespaceSpec ); NodeSpecification anonymousNamespace( "anonymous_namespace", "anonymous_namespace", nsHasBraceValue | nsHasChildren ); anonymousNamespace.addMandatoryChild( "declarations" ); anonymousNamespace.addMandatoryChild( "namespace_members" ); recordSpecfication( anonymousNamespace ); NodeSpecification namespaceMembers( "namespace_members", "members", nsHasChildren ); // .. add declaration sequence members namespaceMembers.addChild( "aggregate" ); namespaceMembers.addChild( "type_alias" ); namespaceMembers.addChild( "namespace" ); namespaceMembers.addChild( "variable" ); namespaceMembers.addChild( "enumeration" ); recordSpecfication( namespaceMembers ); NodeSpecification enumeration( "enumeration", "enumeration", nsHasBraceValue | nsHasChildren ); enumeration.addMandatoryChild( "declarations" ); enumeration.addMandatoryChild( "references" ); enumeration.addMandatoryChild( "enumeration_values" ); recordSpecfication( enumeration ); NodeSpecification enumerationValues( "enumeration_values", "values", nsHasChildren ); enumerationValues.addChild( "enumeration_value" ); recordSpecfication( enumerationValues ); NodeSpecification enumerationValue( "enumeration_value", "value", nsHasBraceValue ); recordSpecfication( enumerationValue ); NodeSpecification variable( "variable", "variable", nsHasBraceValue | nsHasChildren ); variable.addMandatoryChild( "declarations" ); variable.addMandatoryChild( "references" ); variable.addMandatoryChild( "type" ); recordSpecfication( variable ); checkSpecifications(); } // class SymbolTableTestProcessor // /////////////////////////////////////////////////////////////// SymbolTableTestProcessor::SymbolTableTestProcessor( LocationTracker &tracker, TestProject &project ) : LineProcessor( tracker ) , project_( project ) , declarationsStartLine_( -1 ) , currentLineBuffer_( 0 ) { } void SymbolTableTestProcessor::processDeclarations() { DeclarationsNodeProcessor nodeProcessor; declarationsTree_ = nodeProcessor.parseNodeTree( declarations_, declarationsStartLine_ ); } bool SymbolTableTestProcessor::commentAllowed() const { return !currentLineBuffer_; } void SymbolTableTestProcessor::doProcessLine( const std::string &line ) { if ( !currentLineBuffer_ ) return; *currentLineBuffer_ += line; *currentLineBuffer_ += "\n"; } bool SymbolTableTestProcessor::doStateChange( const std::string &name, const std::string ¶meter ) { if ( name == "declarations" ) { currentLineBuffer_ = &declarations_; declarations_ = ""; declarationsStartLine_ = currentLine() + 1; return true; } else if ( name == "description" ) { currentLineBuffer_ = &description_; return true; } return false; } void SymbolTableTestProcessor::doProcessReadFile( const std::string &path, const std::string &content ) { Parser::FileId file = project_.setSourceFile( path, content ); memorizePendingLocations( file ); } void SymbolTableTestProcessor::doTerminateCurrentAction() { if ( currentLineBuffer_ == &declarations_ ) processDeclarations(); currentLineBuffer_ = 0; } NodePtr SymbolTableTestProcessor::declarationsTree() const { return declarationsTree_; } Index: symboltabletest.cpp =================================================================== RCS file: /cvsroot/cpptool/CppParser/examples/parser/symboltabletest.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** symboltabletest.cpp 20 Jun 2004 11:00:38 -0000 1.5 --- symboltabletest.cpp 20 Jun 2004 15:53:41 -0000 1.6 *************** *** 7,10 **** --- 7,11 ---- #include "symboldeclarator.h" #include "symboltable.h" + #include "symboltabletestprocessor.h" #include "stlhelper.h" #include <fstream> *************** *** 22,318 **** } - // class DeclarationsNodeProcessor - // /////////////////////////////////////////////////////////////// - - class DeclarationsNodeProcessor : public NodeProcessor - { - public: - DeclarationsNodeProcessor(); - }; - - - DeclarationsNodeProcessor::DeclarationsNodeProcessor() - { - NodeSpecification globalDeclarations( "global_declarations", "", nsHasChildren ); - globalDeclarations.addChild( "aggregate" ); - globalDeclarations.addChild( "type_alias" ); - globalDeclarations.addChild( "namespace" ); - globalDeclarations.addChild( "anonymous_namespace" ); - globalDeclarations.addChild( "variable" ); - globalDeclarations.addChild( "enumeration" ); - recordSpecfication( globalDeclarations ); - setRootSpecification( globalDeclarations.specificationName() ); - - NodeSpecification declarations( "declarations", "declarations", nsHasColonStringListValue ); - recordSpecfication( declarations ); - - NodeSpecification references( "references", "references", nsHasColonStringListValue ); - recordSpecfication( references ); - - NodeSpecification aggregate( "aggregate", "aggregate", nsHasBraceValue | nsHasChildren ); - aggregate.addChild( "aggregate_kind" ); - aggregate.addMandatoryChild( "declarations" ); - aggregate.addMandatoryChild( "references" ); - aggregate.addChild( "aggregate_members" ); - recordSpecfication( aggregate ); - - NodeSpecification aggregateKind( "aggregate_kind", "kind", nsHasColonEnumerationValue ); - aggregateKind.addEnumerationValue( "class" ); - aggregateKind.addEnumerationValue( "struct" ); - aggregateKind.addEnumerationValue( "union" ); - recordSpecfication( aggregateKind ); - - NodeSpecification aggregateMembers( "aggregate_members", "members", nsHasChildren ); - aggregateMembers.addChild( "aggregate" ); - aggregateMembers.addChild( "constructor" ); - aggregateMembers.addChild( "destructor" ); - aggregateMembers.addChild( "function" ); - aggregateMembers.addChild( "type_alias" ); - recordSpecfication( aggregateMembers ); - - NodeSpecification constructor( "constructor", "constructor", nsHasBraceValue | nsHasChildren ); - constructor.addMandatoryChild( "prototypes" ); - constructor.addChild( "function_definition" ); - constructor.addChild( "function_parameters" ); - recordSpecfication( constructor ); - - NodeSpecification destructor( "destructor", "destructor", nsHasBraceValue | nsHasChildren ); - destructor.addMandatoryChild( "prototypes" ); - destructor.addChild( "function_definition" ); - destructor.addChild( "function_parameters" ); - recordSpecfication( destructor ); - - NodeSpecification function( "function", "function", nsHasBraceValue | nsHasChildren ); - function.addMandatoryChild( "prototypes" ); - function.addMandatoryChild( "return_type" ); - function.addChild( "function_definition" ); - function.addChild( "function_parameters" ); - recordSpecfication( function ); - - NodeSpecification prototypes( "prototypes", "prototypes", nsHasColonStringListValue ); - recordSpecfication( prototypes ); - - NodeSpecification functionDefinition( "function_definition", "definition", nsHasColonStringListValue ); - recordSpecfication( functionDefinition ); - - NodeSpecification returnType( "return_type", "return_type", nsHasColonNodeValue ); - returnType.addChild( "type_built_in" ); - returnType.addChild( "type_const" ); - returnType.addChild( "type_volatile" ); - returnType.addChild( "type_ref" ); - returnType.addChild( "type_ptr" ); - recordSpecfication( returnType ); - - NodeSpecification functionParameters( "function_parameters", "parameters", nsHasChildren ); - functionParameters.addChild( "function_parameter" ); - recordSpecfication( functionParameters ); - - NodeSpecification functionParameter( "function_parameter", "parameter", nsHasBraceValue | nsHasChildren ); - functionParameter.addMandatoryChild( "type" ); - recordSpecfication( functionParameter ); - - NodeSpecification type( "type", "type", nsHasColonNodeValue ); - type.addChild( "type_built_in" ); - type.addChild( "type_const" ); - type.addChild( "type_volatile" ); - type.addChild( "type_ref" ); - type.addChild( "type_ptr" ); - type.addChild( "type_type" ); - recordSpecfication( type ); - - NodeSpecification typeBuiltIn( "type_built_in", "built_in", nsHasBraceValues ); - recordSpecfication( typeBuiltIn ); - - NodeSpecification typeType( "type_type", "type", nsHasBraceValue ); - recordSpecfication( typeType ); - - NodeSpecification typeConst( "type_const", "const", nsHasBraceNodeValue ); - typeConst.addChild( "type_built_in" ); - typeConst.addChild( "type_volatile" ); - typeConst.addChild( "type_ref" ); - typeConst.addChild( "type_ptr" ); - typeConst.addChild( "type_type" ); - recordSpecfication( typeConst ); - - NodeSpecification typeVolatile( "type_volatile", "volatile", nsHasBraceNodeValue ); - typeVolatile.addChild( "type_built_in" ); - typeVolatile.addChild( "type_const" ); - typeVolatile.addChild( "type_ref" ); - typeVolatile.addChild( "type_ptr" ); - typeVolatile.addChild( "type_type" ); - recordSpecfication( typeVolatile ); - - NodeSpecification typeRef( "type_ref", "ref", nsHasBraceNodeValue ); - typeRef.addChild( "type_built_in" ); - typeRef.addChild( "type_const" ); - typeRef.addChild( "type_volatile" ); - typeRef.addChild( "type_ptr" ); - typeRef.addChild( "type_type" ); - recordSpecfication( typeRef ); - - NodeSpecification typePtr( "type_ptr", "ptr", nsHasBraceNodeValue ); - typePtr.addChild( "type_built_in" ); - typePtr.addChild( "type_const" ); - typePtr.addChild( "type_volatile" ); - typePtr.addChild( "type_ref" ); - typePtr.addChild( "type_ptr" ); - typePtr.addChild( "type_type" ); - recordSpecfication( typePtr ); - - NodeSpecification typeAlias( "type_alias", "type_alias", nsHasBraceValue | nsHasChildren ); - typeAlias.addMandatoryChild( "declarations" ); - typeAlias.addMandatoryChild( "references" ); - typeAlias.addMandatoryChild( "type" ); - recordSpecfication( typeAlias ); - - NodeSpecification namespaceSpec( "namespace", "namespace", nsHasBraceValue | nsHasChildren ); - namespaceSpec.addMandatoryChild( "declarations" ); - namespaceSpec.addMandatoryChild( "references" ); - namespaceSpec.addMandatoryChild( "namespace_members" ); - recordSpecfication( namespaceSpec ); - - NodeSpecification anonymousNamespace( "anonymous_namespace", "anonymous_namespace", nsHasBraceValue | nsHasChildren ); - anonymousNamespace.addMandatoryChild( "declarations" ); - anonymousNamespace.addMandatoryChild( "namespace_members" ); - recordSpecfication( anonymousNamespace ); - - NodeSpecification namespaceMembers( "namespace_members", "members", nsHasChildren ); - // .. add declaration sequence members - namespaceMembers.addChild( "aggregate" ); - namespaceMembers.addChild( "type_alias" ); - namespaceMembers.addChild( "namespace" ); - namespaceMembers.addChild( "variable" ); - namespaceMembers.addChild( "enumeration" ); - recordSpecfication( namespaceMembers ); - - NodeSpecification enumeration( "enumeration", "enumeration", nsHasBraceValue | nsHasChildren ); - enumeration.addMandatoryChild( "declarations" ); - enumeration.addMandatoryChild( "references" ); - enumeration.addMandatoryChild( "enumeration_values" ); - recordSpecfication( enumeration ); - - NodeSpecification enumerationValues( "enumeration_values", "values", nsHasChildren ); - enumerationValues.addChild( "enumeration_value" ); - recordSpecfication( enumerationValues ); - - NodeSpecification enumerationValue( "enumeration_value", "value", nsHasBraceValue ); - recordSpecfication( enumerationValue ); - - NodeSpecification variable( "variable", "variable", nsHasBraceValue | nsHasChildren ); - variable.addMandatoryChild( "declarations" ); - variable.addMandatoryChild( "references" ); - variable.addMandatoryChild( "type" ); - recordSpecfication( variable ); - - checkSpecifications(); - } - - // class SymbolTableTestProcessor - // /////////////////////////////////////////////////////////////// - class SymbolTableTestProcessor : public LineProcessor - { - public: - SymbolTableTestProcessor( LocationTracker &tracker, - TestProject &project ); - - NodePtr declarationsTree() const; - - private: // overridden from LineProcessor - bool commentAllowed() const; - - void doProcessLine( const std::string &line ); - bool doStateChange( const std::string &name, - const std::string ¶meter ); - void doProcessReadFile( const std::string &path, - const std::string &content ); - void doTerminateCurrentAction(); - - private: - void processDeclarations(); - - std::string declarations_; - std::string description_; - std::string *currentLineBuffer_; - unsigned declarationsStartLine_; - NodePtr declarationsTree_; - TestProject &project_; - }; - - SymbolTableTestProcessor::SymbolTableTestProcessor( LocationTracker &tracker, - TestProject &project ) - : LineProcessor( tracker ) - , project_( project ) - , declarationsStartLine_( -1 ) - , currentLineBuffer_( 0 ) - { - } - - - void - SymbolTableTestProcessor::processDeclarations() - { - DeclarationsNodeProcessor nodeProcessor; - declarationsTree_ = nodeProcessor.parseNodeTree( declarations_, declarationsStartLine_ ); - } - - bool - SymbolTableTestProcessor::commentAllowed() const - { - return !currentLineBuffer_; - } - - void - SymbolTableTestProcessor::doProcessLine( const std::string &line ) - { - if ( !currentLineBuffer_ ) - return; - - *currentLineBuffer_ += line; - *currentLineBuffer_ += "\n"; - } - - bool - SymbolTableTestProcessor::doStateChange( const std::string &name, - const std::string ¶meter ) - { - if ( name == "declarations" ) - { - currentLineBuffer_ = &declarations_; - declarations_ = ""; - declarationsStartLine_ = currentLine() + 1; - return true; - } - else if ( name == "description" ) - { - currentLineBuffer_ = &description_; - return true; - } - return false; - } - - void - SymbolTableTestProcessor::doProcessReadFile( const std::string &path, - const std::string &content ) - { - Parser::FileId file = project_.setSourceFile( path, content ); - memorizePendingLocations( file ); - } - - - void - SymbolTableTestProcessor::doTerminateCurrentAction() - { - if ( currentLineBuffer_ == &declarations_ ) - processDeclarations(); - currentLineBuffer_ = 0; - } - - NodePtr - SymbolTableTestProcessor::declarationsTree() const - { - return declarationsTree_; - } - - // class DeclarationChecker // /////////////////////////////////////////////////////////////// --- 23,26 ---- |