You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(37) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(15) |
Feb
(26) |
Mar
(97) |
Apr
(224) |
May
(226) |
Jun
|
Jul
(3) |
Aug
(22) |
Sep
(48) |
Oct
|
Nov
|
Dec
(38) |
2004 |
Jan
(28) |
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
(37) |
Jul
|
Aug
(73) |
Sep
|
Oct
|
Nov
|
Dec
|
From: Baptiste L. <bl...@us...> - 2004-08-14 14:15:08
|
Update of /cvsroot/cpptool/CppParser/src/pyrfta/samples In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20940/samples Log Message: Directory /cvsroot/cpptool/CppParser/src/pyrfta/samples added to the repository |
From: Andre B. <net...@us...> - 2004-08-09 11:02:00
|
Update of /cvsroot/cpptool/CppParser/examples/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6861/examples/parser Modified Files: parser.dsp Log Message: -- updated files in project -- restructuring of file hierarchie Index: parser.dsp =================================================================== RCS file: /cvsroot/cpptool/CppParser/examples/parser/parser.dsp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** parser.dsp 8 Jun 2004 20:23:16 -0000 1.1.1.1 --- parser.dsp 9 Aug 2004 11:01:51 -0000 1.2 *************** *** 52,56 **** # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\build\cpput\release" /libpath:"..\..\libs\boost" # Begin Special Build Tool ! TargetPath=\prg\vc\CppParser\build\examples\parser\release\parser.exe SOURCE="$(InputPath)" PostBuild_Desc=Testing... --- 52,56 ---- # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\build\cpput\release" /libpath:"..\..\libs\boost" # Begin Special Build Tool ! TargetPath=\Projects\Cpptool\CppParser\build\examples\parser\release\parser.exe SOURCE="$(InputPath)" PostBuild_Desc=Testing... *************** *** 82,86 **** # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\build\cpput\debug" /libpath:"..\..\libs\boost" # Begin Special Build Tool ! TargetPath=\prg\vc\CppParser\build\examples\parser\debug\parser.exe SOURCE="$(InputPath)" PostBuild_Desc=Testing... --- 82,86 ---- # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\build\cpput\debug" /libpath:"..\..\libs\boost" # Begin Special Build Tool ! TargetPath=\Projects\Cpptool\CppParser\build\examples\parser\debug\parser.exe SOURCE="$(InputPath)" PostBuild_Desc=Testing... *************** *** 94,97 **** --- 94,100 ---- # Name "parser - Win32 Release" # Name "parser - Win32 Debug" + # Begin Group "source" + + # PROP Default_Filter "" # Begin Source File *************** *** 108,392 **** # Begin Source File ! SOURCE=.\commandstreamtest.cpp # End Source File # Begin Source File ! SOURCE=.\commandstreamtest.h # End Source File # Begin Source File ! SOURCE=.\conststring.h # End Source File # Begin Source File ! SOURCE=.\conststringtest.cpp # End Source File # Begin Source File ! SOURCE=.\conststringtest.h # End Source File # Begin Source File ! SOURCE=.\cpplexer.cpp # End Source File # Begin Source File ! SOURCE=.\cpplexer.h # End Source File # Begin Source File ! SOURCE=.\cpplexertest.cpp # End Source File # Begin Source File ! SOURCE=.\cpplexertest.h # End Source File # Begin Source File ! SOURCE=.\cppnodetestbase.cpp # End Source File # Begin Source File ! SOURCE=.\cppnodetestbase.h # End Source File # Begin Source File ! SOURCE=.\cppparser.cpp # End Source File # Begin Source File ! SOURCE=.\cppparser.h # End Source File # Begin Source File ! SOURCE=.\cppparserfacade.cpp # End Source File # Begin Source File ! SOURCE=.\cppparserfacade.h # End Source File # Begin Source File ! SOURCE=.\cppparsersettings.h # End Source File # Begin Source File ! SOURCE=.\cppparsertest.cpp # End Source File # Begin Source File ! SOURCE=.\cppparsertest.h # End Source File # Begin Source File ! SOURCE=.\forwards.h # End Source File # Begin Source File ! SOURCE=.\grammarbuilder.cpp # End Source File # Begin Source File ! SOURCE=.\grammarbuilder.h # End Source File # Begin Source File ! SOURCE=.\grammarbuildertest.cpp # End Source File # Begin Source File ! SOURCE=.\grammarbuildertest.h # End Source File # Begin Source File ! SOURCE=.\grammarparser.cpp # End Source File # Begin Source File ! SOURCE=.\grammarparser.h # End Source File # Begin Source File ! SOURCE=.\grammarparsertest.cpp # End Source File # Begin Source File ! SOURCE=.\grammarparsertest.h # End Source File # Begin Source File ! SOURCE=.\lineprocessor.cpp # End Source File # Begin Source File ! SOURCE=.\lineprocessor.h # End Source File # Begin Source File ! SOURCE=.\location.h # End Source File # Begin Source File ! SOURCE=.\main.cpp # End Source File # Begin Source File ! SOURCE=.\node.cpp # End Source File # Begin Source File ! SOURCE=.\node.h # End Source File # Begin Source File ! SOURCE=.\nodeiterator.h # End Source File # Begin Source File ! SOURCE=.\nodeprocessor.cpp # End Source File # Begin Source File ! SOURCE=.\nodeprocessor.h # End Source File # Begin Source File ! SOURCE=.\nodetest.cpp # End Source File # Begin Source File ! SOURCE=.\nodetest.h # End Source File # Begin Source File ! SOURCE=.\nodetesthelper.cpp # End Source File # Begin Source File ! SOURCE=.\nodetesthelper.h # End Source File # Begin Source File ! SOURCE=.\nodetracker.cpp # End Source File # Begin Source File ! SOURCE=.\nodetracker.h # End Source File # Begin Source File ! SOURCE=.\nodetrackertest.cpp # End Source File # Begin Source File ! SOURCE=.\nodetrackertest.h # End Source File # Begin Source File ! SOURCE=.\nodetreetestbase.cpp # End Source File # Begin Source File ! SOURCE=.\nodetreetestbase.h # End Source File # Begin Source File ! SOURCE=.\options.h # End Source File # Begin Source File ! SOURCE=.\parsecontext.h # End Source File # Begin Source File ! SOURCE=.\parser.h # End Source File # Begin Source File ! SOURCE=.\parsertest.cpp # End Source File # Begin Source File ! SOURCE=.\parsertest.h # End Source File # Begin Source File ! SOURCE=.\parsertesthelper.cpp # End Source File # Begin Source File ! SOURCE=.\parsertesthelper.h # End Source File # Begin Source File ! SOURCE=.\parsingtracker.cpp # End Source File # Begin Source File ! SOURCE=.\parsingtracker.h # End Source File # Begin Source File ! SOURCE=.\preprocessortest.cpp # End Source File # Begin Source File ! SOURCE=.\preprocessortest.h # End Source File # Begin Source File ! SOURCE=.\project.h # End Source File # Begin Source File ! SOURCE=.\refactoringtest.cpp # End Source File # Begin Source File ! SOURCE=.\refactoringtest.h # End Source File # Begin Source File ! SOURCE=.\scope.cpp # End Source File # Begin Source File ! SOURCE=.\scope.h # End Source File # Begin Source File ! SOURCE=.\sourceeditor.cpp # End Source File # Begin Source File ! SOURCE=.\sourceeditor.h # End Source File # Begin Source File ! SOURCE=.\stlhelper.h # End Source File # Begin Source File ! SOURCE=.\symboldeclaration.cpp # End Source File # Begin Source File ! SOURCE=.\symboldeclaration.h # End Source File # Begin Source File ! SOURCE=.\symboldeclarator.cpp # End Source File # Begin Source File ! SOURCE=.\symboldeclarator.h # End Source File # Begin Source File ! SOURCE=.\symboltable.cpp # End Source File # Begin Source File ! SOURCE=.\symboltable.h # End Source File # Begin Source File --- 111,407 ---- # Begin Source File ! SOURCE=.\conststring.h # End Source File # Begin Source File ! SOURCE=.\cpplexer.cpp # End Source File # Begin Source File ! SOURCE=.\cpplexer.h # End Source File # Begin Source File ! SOURCE=.\cppparser.cpp # End Source File # Begin Source File ! SOURCE=.\cppparser.h # End Source File # Begin Source File ! SOURCE=.\cppparserfacade.cpp # End Source File # Begin Source File ! SOURCE=.\cppparserfacade.h # End Source File # Begin Source File ! SOURCE=.\cppparsersettings.h # End Source File # Begin Source File ! SOURCE=.\forwards.h # End Source File # Begin Source File ! SOURCE=.\grammarbuilder.cpp # End Source File # Begin Source File ! SOURCE=.\grammarbuilder.h # End Source File # Begin Source File ! SOURCE=.\grammarparser.cpp # End Source File # Begin Source File ! SOURCE=.\grammarparser.h # End Source File # Begin Source File ! SOURCE=.\lineprocessor.cpp # End Source File # Begin Source File ! SOURCE=.\lineprocessor.h # End Source File # Begin Source File ! SOURCE=.\location.h # End Source File # Begin Source File ! SOURCE=.\main.cpp # End Source File # Begin Source File ! SOURCE=.\node.cpp # End Source File # Begin Source File ! SOURCE=.\node.h # End Source File # Begin Source File ! SOURCE=.\nodeiterator.h # End Source File # Begin Source File ! SOURCE=.\nodeprocessor.cpp # End Source File # Begin Source File ! SOURCE=.\nodeprocessor.h # End Source File # Begin Source File ! SOURCE=.\nodetracker.cpp # End Source File # Begin Source File ! SOURCE=.\nodetracker.h # End Source File # Begin Source File ! SOURCE=.\options.h # End Source File # Begin Source File ! SOURCE=.\parsecontext.h # End Source File # Begin Source File ! SOURCE=.\parser.h # End Source File # Begin Source File ! SOURCE=.\parsingtracker.cpp # End Source File # Begin Source File ! SOURCE=.\parsingtracker.h # End Source File # Begin Source File ! SOURCE=.\project.h # End Source File # Begin Source File ! SOURCE=.\scope.cpp # End Source File # Begin Source File ! SOURCE=.\scope.h # End Source File # Begin Source File ! SOURCE=.\sourceeditor.cpp # End Source File # Begin Source File ! SOURCE=.\sourceeditor.h # End Source File # Begin Source File ! SOURCE=.\stlhelper.h # End Source File # Begin Source File ! SOURCE=.\symboldeclaration.cpp # End Source File # Begin Source File ! SOURCE=.\symboldeclaration.h # End Source File # Begin Source File ! SOURCE=.\symboldeclarator.cpp # End Source File # Begin Source File ! SOURCE=.\symboldeclarator.h # End Source File # Begin Source File ! SOURCE=.\symboltable.cpp # End Source File # Begin Source File ! SOURCE=.\symboltable.h # End Source File # Begin Source File ! SOURCE=.\token.h # End Source File # Begin Source File ! SOURCE=.\tokenmanager.h # End Source File + # End Group + # Begin Group "tests" + + # PROP Default_Filter "" # Begin Source File ! SOURCE=.\commandstreamtest.cpp # End Source File # Begin Source File ! SOURCE=.\commandstreamtest.h # End Source File # Begin Source File ! SOURCE=.\conststringtest.cpp # End Source File # Begin Source File ! SOURCE=.\conststringtest.h # End Source File # Begin Source File ! SOURCE=.\cpplexertest.cpp # End Source File # Begin Source File ! SOURCE=.\cpplexertest.h # End Source File # Begin Source File ! SOURCE=.\cppnodetestbase.cpp # End Source File # Begin Source File ! SOURCE=.\cppnodetestbase.h # End Source File # Begin Source File ! SOURCE=.\cppparsertest.cpp # End Source File # Begin Source File ! SOURCE=.\cppparsertest.h # End Source File # Begin Source File ! SOURCE=.\grammarbuildertest.cpp # End Source File # Begin Source File ! SOURCE=.\grammarbuildertest.h # End Source File # Begin Source File ! SOURCE=.\grammarparsertest.cpp # End Source File # Begin Source File ! SOURCE=.\grammarparsertest.h # End Source File # Begin Source File ! SOURCE=.\nodetest.cpp # End Source File # Begin Source File ! SOURCE=.\nodetest.h # End Source File # Begin Source File ! SOURCE=.\nodetesthelper.cpp # End Source File # Begin Source File ! SOURCE=.\nodetesthelper.h # End Source File # Begin Source File ! SOURCE=.\nodetrackertest.cpp # End Source File # Begin Source File ! SOURCE=.\nodetrackertest.h # End Source File # Begin Source File ! SOURCE=.\nodetreetestbase.cpp # End Source File # Begin Source File ! SOURCE=.\nodetreetestbase.h # End Source File # Begin Source File ! SOURCE=.\parsertest.cpp # End Source File # Begin Source File ! SOURCE=.\parsertest.h # End Source File # Begin Source File ! SOURCE=.\parsertesthelper.cpp # End Source File # Begin Source File ! SOURCE=.\parsertesthelper.h # End Source File # Begin Source File ! SOURCE=.\preprocessortest.cpp # End Source File # Begin Source File ! SOURCE=.\preprocessortest.h ! # End Source File ! # Begin Source File ! ! SOURCE=.\refactoringtest.cpp ! # End Source File ! # Begin Source File ! ! SOURCE=.\refactoringtest.h # End Source File # Begin Source File *************** *** 400,403 **** --- 415,426 ---- # Begin Source File + SOURCE=.\symboltabletestprocessor.cpp + # End Source File + # Begin Source File + + SOURCE=.\symboltabletestprocessor.h + # End Source File + # Begin Source File + SOURCE=.\testproject.cpp # End Source File *************** *** 412,429 **** # Begin Source File ! SOURCE=.\token.h # End Source File # Begin Source File ! SOURCE=.\tokenmanager.h # End Source File # Begin Source File ! SOURCE=.\tokentesthelper.h # End Source File # Begin Source File ! SOURCE=.\unittesting.h # End Source File # End Target # End Project --- 435,630 ---- # Begin Source File ! SOURCE=.\tokentesthelper.h # End Source File # Begin Source File ! SOURCE=.\unittesting.h # End Source File + # End Group + # Begin Group "testdata" + + # PROP Default_Filter "" + # Begin Group "refactoring" + + # PROP Default_Filter "" + # Begin Group "rename_class" + + # PROP Default_Filter "" # Begin Source File ! SOURCE=.\testdata\refactoring\rename_class\test1.cpp ! ! !IF "$(CFG)" == "parser - Win32 Release" ! ! !ELSEIF "$(CFG)" == "parser - Win32 Debug" ! ! # PROP Exclude_From_Build 1 ! ! !ENDIF ! # End Source File # Begin Source File ! SOURCE=.\testdata\refactoring\rename_class\test2.cpp ! ! !IF "$(CFG)" == "parser - Win32 Release" ! ! !ELSEIF "$(CFG)" == "parser - Win32 Debug" ! ! # PROP Exclude_From_Build 1 ! ! !ENDIF ! ! # End Source File ! # Begin Source File ! ! SOURCE=.\testdata\refactoring\rename_class\test3.cpp ! ! !IF "$(CFG)" == "parser - Win32 Release" ! ! !ELSEIF "$(CFG)" == "parser - Win32 Debug" ! ! # PROP Exclude_From_Build 1 ! ! !ENDIF ! # End Source File + # Begin Source File + + SOURCE=.\testdata\refactoring\rename_class\test4.cpp + + !IF "$(CFG)" == "parser - Win32 Release" + + !ELSEIF "$(CFG)" == "parser - Win32 Debug" + + # PROP Exclude_From_Build 1 + + !ENDIF + + # End Source File + # Begin Source File + + SOURCE=.\testdata\refactoring\rename_class\test5.cpp + + !IF "$(CFG)" == "parser - Win32 Release" + + !ELSEIF "$(CFG)" == "parser - Win32 Debug" + + # PROP Exclude_From_Build 1 + + !ENDIF + + # End Source File + # End Group + # End Group + # Begin Group "symboltable" + + # PROP Default_Filter "" + # Begin Group "scopes" + + # PROP Default_Filter "" + # Begin Source File + + SOURCE=.\testdata\symbol_table\scopes\function1.txt + # End Source File + # Begin Source File + + SOURCE=.\testdata\symbol_table\scopes\namespace1.txt + # End Source File + # Begin Source File + + SOURCE=.\testdata\symbol_table\scopes\namespace2.txt + # End Source File + # Begin Source File + + SOURCE=.\testdata\symbol_table\scopes\test1.txt + # End Source File + # Begin Source File + + SOURCE=.\testdata\symbol_table\scopes\test2.txt + # End Source File + # Begin Source File + + SOURCE=.\testdata\symbol_table\scopes\test3.txt + # End Source File + # Begin Source File + + SOURCE=.\testdata\symbol_table\scopes\typedef1.txt + # End Source File + # Begin Source File + + SOURCE=.\testdata\symbol_table\scopes\typedef2.txt + # End Source File + # End Group + # Begin Source File + + SOURCE=.\testdata\symbol_table\__tests__.txt + # End Source File + # Begin Source File + + SOURCE=.\testdata\symbol_table\class1.txt + # End Source File + # Begin Source File + + SOURCE=.\testdata\symbol_table\class2.txt + # End Source File + # Begin Source File + + SOURCE=.\testdata\symbol_table\class3.txt + # End Source File + # Begin Source File + + SOURCE=.\testdata\symbol_table\class4.txt + # End Source File + # Begin Source File + + SOURCE=.\testdata\symbol_table\declarative_region_3.3.txt + # End Source File + # Begin Source File + + SOURCE=.\testdata\symbol_table\definitions_3.1a.txt + # End Source File + # Begin Source File + + SOURCE=.\testdata\symbol_table\enum1.txt + # End Source File + # Begin Source File + + SOURCE=.\testdata\symbol_table\enum2.txt + # End Source File + # Begin Source File + + SOURCE=.\testdata\symbol_table\function1.txt + # End Source File + # Begin Source File + + SOURCE=.\testdata\symbol_table\namespace1.txt + # End Source File + # Begin Source File + + SOURCE=.\testdata\symbol_table\namespace2.txt + # End Source File + # Begin Source File + + SOURCE=.\testdata\symbol_table\namespace3.txt + # End Source File + # Begin Source File + + SOURCE=.\testdata\symbol_table\standard.txt + # End Source File + # Begin Source File + + SOURCE=.\testdata\symbol_table\typedef1.txt + # End Source File + # Begin Source File + + SOURCE=.\testdata\symbol_table\typedef2.txt + # End Source File + # Begin Source File + + SOURCE=.\testdata\symbol_table\variable1.txt + # End Source File + # End Group + # End Group # End Target # End Project |
From: Andre B. <net...@us...> - 2004-08-09 11:01:18
|
Update of /cvsroot/cpptool/CppParser/examples/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6763/examples/parser Modified Files: node.h Log Message: -- fix the problem with "std::size_t" when compiling with VC6 Index: node.h =================================================================== RCS file: /cvsroot/cpptool/CppParser/examples/parser/node.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** node.h 8 Jun 2004 20:23:14 -0000 1.1.1.1 --- node.h 9 Aug 2004 11:01:09 -0000 1.2 *************** *** 2,5 **** --- 2,6 ---- # define PARSER_NODE_H_INCLUDED + # include <boost/compatibility/cpp_c_headers/cstddef> # include <boost/intrusive_ptr.hpp> # include "token.h" |
From: Baptiste L. <bl...@us...> - 2004-08-08 21:41:26
|
Update of /cvsroot/cpptool/CppParser/src/pyrfta In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27348/src/pyrfta Modified Files: ast.py dumpast.py Log Message: * added a few more expressions Index: ast.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/ast.py,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** ast.py 8 Aug 2004 20:28:07 -0000 1.10 --- ast.py 8 Aug 2004 21:41:17 -0000 1.11 *************** *** 55,60 **** class Initializer(ASTElement): ! def __init( self, node ): self.node = node class AssignInitializer(Initializer): --- 55,61 ---- class Initializer(ASTElement): ! def __init__( self, node ): self.node = node + self.expression = None class AssignInitializer(Initializer): *************** *** 71,80 **** self.declarator_node = nodetools.getFirstChildNamed( init_declarator_node, 'declarator' ) self.initializer = None - assign_initializer_node = nodetools.tryGetFirstChildNamed( init_declarator_node, 'assign_initializer' ) - if assign_initializer_node: - self.initializer = AssignInitializer( assign_initializer_node ) - expression_list_node = nodetools.tryGetFirstChildNamed( init_declarator_node, 'expression_list' ) - if expression_list_node: - self.initializer = ConstructorInitializer( expression_list_node ) class SimpleDeclaration(Declaration): --- 72,75 ---- *************** *** 120,123 **** --- 115,122 ---- self.declarator_id = id + class PointerOperator(ASTElement): + def __init__( self, node ): + self.node = node + class DeclaratorId(ASTElement): def __init__( self, node ): *************** *** 360,364 **** class ReturnStatement(Statement): ! pass class GotoStatement(Statement): --- 359,365 ---- class ReturnStatement(Statement): ! def __init__( self, node ): ! Statement.__init__( self, node ) ! self.expression = None class GotoStatement(Statement): *************** *** 423,426 **** --- 424,431 ---- self.id_node = None + class CastExpression(ExpressionBase): + def __init__( self, node ): + ExpressionBase.__init__( self, node ) + class PostIncDecExpression(ExpressionBase): def __init__( self, node ): *************** *** 469,472 **** --- 474,482 ---- self.index = None + class BracedExpression(ExpressionBase): + def __init__( self, node ): + ExpressionBase.__init__( self, node ) + self.expression = None + class NewOperatorExpression(ExpressionBase): def __init__( self, node ): *************** *** 475,478 **** --- 485,497 ---- self.new_type_id_node = None + class SizeOfExpression(ExpressionBase): + def __init__( self, node ): + ExpressionBase.__init__( self, node ) + self.expression = None + + class ThisRefExpression(ExpressionBase): + def __init__( self, node ): + ExpressionBase.__init__( self, node ) + class UnaryOperatorExpression(ExpressionBase): def __init__( self, node ): *************** *** 521,524 **** --- 540,550 ---- return ErrorStatement( statement ) + def buildCaseStatement( self, statement ): + ast = CaseStatement( statement ) + value_node = nodetools.getFirstChildNamed( statement, 'constant_expression' ) + ast.setValue( self.buildConstantExpression( value_node ) ) + self.buildTargetStatement( ast, statement ) + return ast + def buildCompoundStatement( self, statement ): ast = CompoundStatement( statement ) *************** *** 529,549 **** return ast - def buildLabelStatement( self, statement ): - return self.buildTargetStatement( LabelStatement( statement ), statement ) - - def buildCaseStatement( self, statement ): - ast = CaseStatement( statement ) - value_node = nodetools.getFirstChildNamed( statement, 'constant_expression' ) - ast.setValue( self.buildConstantExpression( value_node ) ) - self.buildTargetStatement( ast, statement ) - return ast - def buildDefaultStatement( self, statement ): return self.buildTargetStatement( DefaultStatement( statement ), statement ) ! def buildTargetStatement( self, ast, label_statement_node ): ! target_statement_node = nodetools.getFirstChildNamed( label_statement_node, 'target_statement' ) ! ast.setStatement( self.buildStatement( nodetools.getFirstChild( target_statement_node ) ) ) ! return ast def buildIfStatement( self, statement ): --- 555,566 ---- return ast def buildDefaultStatement( self, statement ): return self.buildTargetStatement( DefaultStatement( statement ), statement ) ! def buildDoWhileStatement( self, statement ): ! return DoWhileStatement( statement ) ! ! def buildLabelStatement( self, statement ): ! return self.buildTargetStatement( LabelStatement( statement ), statement ) def buildIfStatement( self, statement ): *************** *** 566,575 **** return ast def buildWhileStatement( self, statement ): return WhileStatement( statement ) - def buildDoWhileStatement( self, statement ): - return DoWhileStatement( statement ) - def buildForStatement( self, statement ): ast = ForStatement( statement ) --- 583,594 ---- return ast + def buildTargetStatement( self, ast, label_statement_node ): + target_statement_node = nodetools.getFirstChildNamed( label_statement_node, 'target_statement' ) + ast.setStatement( self.buildStatement( nodetools.getFirstChild( target_statement_node ) ) ) + return ast + def buildWhileStatement( self, statement ): return WhileStatement( statement ) def buildForStatement( self, statement ): ast = ForStatement( statement ) *************** *** 622,626 **** def buildReturnStatement( self, statement ): ! return ReturnStatement( statement ) def buildGotoStatement( self, statement ): --- 641,649 ---- def buildReturnStatement( self, statement ): ! ast = ReturnStatement( statement ) ! expression_node = nodetools.tryGetFirstChildNamed( statement, 'expression' ) ! if expression_node: ! ast.expression = self.dispatchBuildExpression( expression_node ) ! return ast def buildGotoStatement( self, statement ): *************** *** 676,680 **** 'unary_operator' : self.buildUnaryOperatorExpression, 'assignment_operator' : self.buildAssignmentOperatorExpression, ! 'new_operator' : self.buildNewOperatorExpression } --- 699,708 ---- 'unary_operator' : self.buildUnaryOperatorExpression, 'assignment_operator' : self.buildAssignmentOperatorExpression, ! 'new_operator' : self.buildNewOperatorExpression, ! 'this_ref' : self.buildThisRef, ! 'sizeof_operator' : self.buildSizeOfExpression, ! 'braced_expr' : self.buildBracedExpression, ! 'expression' : self.buildExpression, ! 'cast_expression' : self.buildCastExpression } *************** *** 715,718 **** --- 743,751 ---- return ast + def buildBracedExpression( self, expression ): + ast = BracedExpression( expression ) + ast.expression = self.dispatchBuildExpression( nodetools.getFirstCompositeChild( expression ) ) + return ast + def buildCallOrConversionExpression( self, expression ): parameters_node = nodetools.tryGetFirstChildNamed( expression, 'expression_list' ) *************** *** 734,737 **** --- 767,775 ---- return ast + def buildCastExpression( self, expression ): + ast = CastExpression( expression ) + #todo + return ast + def buildConstantExpression( self, expression ): return self.dispatchBuildExpression( nodetools.getFirstChild( expression ) ) *************** *** 775,778 **** --- 813,824 ---- return ast + def buildSizeOfExpression( self, expression ): + ast = SizeOfExpression( expression ) + ast.expression = self.dispatchBuildExpression( nodetools.getFirstCompositeChild( expression ) ) + return ast + + def buildThisRef( self, expression ): + return ThisRefExpression( expression ) + def buildUnaryOperatorExpression( self, expression ): ast = UnaryOperatorExpression( expression ) *************** *** 892,895 **** --- 938,956 ---- declarator = Declarator( declarator_node ) self.buildDeclarator( declarator, declarator_node ) + + assign_node = nodetools.tryGetFirstChildNamed( init_declarator, 'assign_initializer' ) + constructor_node = nodetools.tryGetFirstChildNamed( init_declarator, 'expression_list' ) + if assign_node: + initializer = AssignInitializer( assign_node ) + value = self.dispatchBuildExpression( nodetools.tryGetFirstChildNamed( assign_node, + 'assignment_expression' ) ) + initializer.expression = value + elif constructor_node: + initializer = ConstructorInitializer( constructor_node ) + initializer.expression = self.dispatchBuildExpression( constructor_node ) + else: # we ignore array & structure initializer for the time being + initializer = None + declarator.initializer = initializer + ast.addDeclarator( declarator ) return ast Index: dumpast.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/dumpast.py,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dumpast.py 8 Aug 2004 20:28:07 -0000 1.8 --- dumpast.py 8 Aug 2004 21:41:17 -0000 1.9 *************** *** 32,35 **** --- 32,57 ---- def __init__( self, source ): self.source = source + + def _location( self, location ): + previousEOL = self.source.rfind( '\n', 0, location.startPos ) + 1 + line = self.source.count( '\n', 0, previousEOL ) + column = location.startPos - previousEOL + return (line+1,column+1) + + def _nodeTreeSource( self, node ): + source = '' + if node.hasValidToken(): + source += node.text + for child in node.enumChildren(): + source += self._nodeTreeSource( child ) + return source + + def _nodeTreeIdentifier( self, node ): + source = '' + if node.hasValidToken() and not node.token.isSilent: + source += node.text + for child in node.enumChildren(): + source += self._nodeTreeIdentifier( child ) + return source def visitASTNode( self, ast ): *************** *** 38,41 **** --- 60,73 ---- return getattr( self, visit_method )( ast ) + def visitAssignInitializer( self, ast ): + info = ASTInfo( ast ) + info.attr( 'expression', self.visitASTNode( ast.expression ) ) + return info + + def visitConstructorInitializer( self, ast ): + info = ASTInfo( ast ) + info.attr( 'expression', self.visitASTNode( ast.expression ) ) + return info + def visitTranslationUnit( self, ast ): info = ASTInfo( ast ) *************** *** 47,61 **** info.attr('declarations').append( self.visitASTNode( declaration ) ) return info - - def visitFunctionDefinition( self, ast ): - name = (ast.body and 'FunctionDefinition') or 'FunctionPrototype' - info = ASTInfo( name ) - info.attr( 'return_type', self.visitASTNode( ast.return_type ) ) - if ast.body: - info.attr( 'body', self.visitASTNode( ast.body ) ) - return info ! def visitFunctionReturnType( self, ast ): info = ASTInfo( ast ) return info --- 79,89 ---- info.attr('declarations').append( self.visitASTNode( declaration ) ) return info ! def visitDeclarator( self, ast ): info = ASTInfo( ast ) + # + ptr operators + info.attr( 'declator_id', self._nodeTreeIdentifier( ast.declarator_id.node ) ) + if ast.initializer: + info.attr( 'initializer', self.visitASTNode( ast.initializer ) ) return info *************** *** 73,98 **** info.attr( 'text', text ) return info ! def _location( self, location ): ! previousEOL = self.source.rfind( '\n', 0, location.startPos ) + 1 ! line = self.source.count( '\n', 0, previousEOL ) ! column = location.startPos - previousEOL ! return (line+1,column+1) ! ! def _nodeTreeSource( self, node ): ! source = '' ! if node.hasValidToken(): ! source += node.text ! for child in node.enumChildren(): ! source += self._nodeTreeSource( child ) ! return source ! ! def _nodeTreeIdentifier( self, node ): ! source = '' ! if node.hasValidToken() and not node.token.isSilent: ! source += node.text ! for child in node.enumChildren(): ! source += self._nodeTreeIdentifier( child ) ! return source def visitStandardDeclaration( self, ast ): --- 101,116 ---- info.attr( 'text', text ) return info + + def visitFunctionDefinition( self, ast ): + name = (ast.body and 'FunctionDefinition') or 'FunctionPrototype' + info = ASTInfo( name ) + info.attr( 'return_type', self.visitASTNode( ast.return_type ) ) + if ast.body: + info.attr( 'body', self.visitASTNode( ast.body ) ) + return info ! def visitFunctionReturnType( self, ast ): ! info = ASTInfo( ast ) ! return info def visitStandardDeclaration( self, ast ): *************** *** 103,111 **** return info ! def visitDeclarator( self, ast ): ! info = ASTInfo( ast ) ! # + ptr operators ! info.attr( 'declator_id', self._nodeTreeIdentifier( ast.declarator_id.node ) ) ! return info ## Statements --- 121,127 ---- return info ! def visitTypedefDeclaration( self, ast ): ! #todo ! return ASTInfo( ast ) ## Statements *************** *** 147,150 **** --- 163,169 ---- return self.visitLabelStatement( ast ) + def visitErrorStatement( self, ast ): + return self.visitErrorDeclaration( ast ) + def visitExpressionCondition( self, ast ): return self.visitASTNode( ast.expression ) *************** *** 171,174 **** --- 190,196 ---- return self.visitASTNode( ast.init_declaration ) + def visitForInitStatement( self, ast ): + return self.visitASTNode( ast.init_statement ) + def visitIfStatement( self, ast ): info = ASTInfo( ast ) *************** *** 184,187 **** --- 206,215 ---- return info + def visitReturnStatement( self, ast ): + info = ASTInfo( ast ) + if ast.expression: + info.attr( 'expression', self.visitASTNode( ast.expression ) ) + return info + def visitSwitchStatement( self, ast ): info = ASTInfo( ast ) *************** *** 223,226 **** --- 251,259 ---- info.attr( 'right', self.visitASTNode( ast.right_expression ) ) return info + + def visitBracedExpression( self, ast ): + info = ASTInfo( ast ) + info.attr( 'expression', self.visitASTNode( ast.expression ) ) + return info def visitCallExpression( self, ast ): *************** *** 241,244 **** --- 274,280 ---- return info + def visitCastExpression( self, ast ): + return ASTInfo( ast ) + def visitDeleteOperatorExpression( self, ast ): info = ASTInfo( ast ) *************** *** 279,282 **** --- 315,327 ---- return info + def visitSizeOfExpression( self, ast ): + info = ASTInfo( ast ) + info.attr( 'expression', self.visitASTNode( ast.expression ) ) + return info + + def visitThisRefExpression( self, ast ): + info = ASTInfo( ast ) + return info + def visitUnaryOperatorExpression( self, ast ): info = ASTInfo( ast ) |
From: Baptiste L. <bl...@us...> - 2004-08-08 20:28:16
|
Update of /cvsroot/cpptool/CppParser/src/pyrfta In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13724/src/pyrfta Modified Files: ast.py dumpast.py nodetools.py Log Message: * better call or conversion wrapping Index: nodetools.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/nodetools.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** nodetools.py 8 Aug 2004 17:26:34 -0000 1.5 --- nodetools.py 8 Aug 2004 20:28:07 -0000 1.6 *************** *** 46,50 **** def getFirstIdentifierChildNode( node, exception_if_not_found = True ): for child in node.enumChildren(): ! if child.category == cprs.TK_IDENTIFIER: return child if exception_if_not_found: --- 46,50 ---- def getFirstIdentifierChildNode( node, exception_if_not_found = True ): for child in node.enumChildren(): ! if child.hasValidToken() and child.token.category == cprs.TK_IDENTIFIER: return child if exception_if_not_found: *************** *** 54,62 **** def getFirstStringChildNode( node, exception_if_not_found = True ): for child in node.enumChildren(): ! if child.category == cprs.TK_STRING: return child if exception_if_not_found: raise AssertionError( "Fail to find string child in node %s" % node) - return None def getFirstTokenChildNode( node ): --- 54,61 ---- def getFirstStringChildNode( node, exception_if_not_found = True ): for child in node.enumChildren(): ! if child.hasValidToken() and child.token.category == cprs.TK_STRING: return child if exception_if_not_found: raise AssertionError( "Fail to find string child in node %s" % node) def getFirstTokenChildNode( node ): *************** *** 64,66 **** if child.hasValidToken(): return child ! raise AssertionError( "Fail to find a child node with token in %s." % node ) \ No newline at end of file --- 63,72 ---- if child.hasValidToken(): return child ! raise AssertionError( "Fail to find a child node with token in %s." % node ) ! ! def getFirstSymbolChildNode( node ): ! for child in node.enumChildren(): ! if child.hasValidToken() and child.token.category == cprs.TK_SYMBOL: ! return child ! if exception_if_not_found: ! raise AssertionError( "Fail to find string child in node %s" % node) Index: ast.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/ast.py,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** ast.py 8 Aug 2004 19:15:31 -0000 1.9 --- ast.py 8 Aug 2004 20:28:07 -0000 1.10 *************** *** 418,422 **** class CallOrConversionExpression(ExpressionBase): ! pass class PostIncDecExpression(ExpressionBase): --- 418,425 ---- class CallOrConversionExpression(ExpressionBase): ! def __init__( self, node ): ! ExpressionBase.__init__( self, node ) ! self.parameters = None ! self.id_node = None class PostIncDecExpression(ExpressionBase): *************** *** 432,436 **** ExpressionBase.__init__( self, node ) self.left_expression = None ! self.operator_node = nodetools.getFirstTokenChildNode( node ) self.right_expression = None --- 435,439 ---- ExpressionBase.__init__( self, node ) self.left_expression = None ! self.operator_node = nodetools.getFirstSymbolChildNode( node ) self.right_expression = None *************** *** 476,480 **** ExpressionBase.__init__( self, node ) self.expression = None ! self.operator_node = nodetools.getFirstTokenChildNode( node ) class AssignmentOperatorExpression(BinaryOperatorExpression): --- 479,483 ---- ExpressionBase.__init__( self, node ) self.expression = None ! self.operator_node = nodetools.getFirstSymbolChildNode( node ) class AssignmentOperatorExpression(BinaryOperatorExpression): *************** *** 713,718 **** def buildCallOrConversionExpression( self, expression ): ast = CallOrConversionExpression( expression ) ! # todo return ast --- 716,727 ---- def buildCallOrConversionExpression( self, expression ): + parameters_node = nodetools.tryGetFirstChildNamed( expression, 'expression_list' ) + ## if not parameters_node: + ## ast = CallExpression( expression ) + ## ast.parameters.append( self.dispatchBuildExpression( parameters_node ) ) ast = CallOrConversionExpression( expression ) ! if parameters_node: ! ast.parameters = self.dispatchBuildExpression( parameters_node ) ! ast.id_node = nodetools.getFirstCompositeChild( expression ) return ast Index: dumpast.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/dumpast.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dumpast.py 8 Aug 2004 19:15:31 -0000 1.7 --- dumpast.py 8 Aug 2004 20:28:07 -0000 1.8 *************** *** 88,91 **** --- 88,99 ---- return source + def _nodeTreeIdentifier( self, node ): + source = '' + if node.hasValidToken() and not node.token.isSilent: + source += node.text + for child in node.enumChildren(): + source += self._nodeTreeIdentifier( child ) + return source + def visitStandardDeclaration( self, ast ): info = ASTInfo( ast ) *************** *** 98,102 **** info = ASTInfo( ast ) # + ptr operators ! info.attr( 'declator_id', self._nodeTreeSource( ast.declarator_id.node ) ) return info --- 106,110 ---- info = ASTInfo( ast ) # + ptr operators ! info.attr( 'declator_id', self._nodeTreeIdentifier( ast.declarator_id.node ) ) return info *************** *** 226,229 **** --- 234,242 ---- def visitCallOrConversionExpression( self, ast ): info = ASTInfo( ast ) + info.attr( 'id', self._nodeTreeIdentifier( ast.id_node ) ) + # it's an expression list + #info.attr( 'parameters', [ self.visitASTNode( expression ) for expression in ast.parameters ] ) + if ast.parameters: + info.attr( 'parameters', self.visitASTNode( ast.parameters ) ) return info *************** *** 240,249 **** def visitIdExpression( self, ast ): info = ASTInfo( ast ) ! info.attr( 'id', self._nodeTreeSource( ast.node ) ) return info def visitLiteralExpression( self, ast ): info = ASTInfo( ast ) ! info.attr( 'literal', self._nodeTreeSource( ast.node ) ) return info --- 253,262 ---- def visitIdExpression( self, ast ): info = ASTInfo( ast ) ! info.attr( 'id', self._nodeTreeIdentifier( ast.node ) ) return info def visitLiteralExpression( self, ast ): info = ASTInfo( ast ) ! info.attr( 'literal', self._nodeTreeIdentifier( ast.node ) ) return info *************** *** 251,255 **** info = ASTInfo( ast ) info.attr( 'expression', self.visitASTNode( ast.expression ) ) ! info.attr( 'member', self._nodeTreeSource( ast.member_node ) ) return info --- 264,268 ---- info = ASTInfo( ast ) info.attr( 'expression', self.visitASTNode( ast.expression ) ) ! info.attr( 'member', self._nodeTreeIdentifier( ast.member_node ) ) return info *************** *** 258,262 **** if ast.placement_expression: info.attr( 'placement_expression', self.visitASTNode( ast.placement_expression ) ) ! info.attr( 'type', self._nodeTreeSource( ast.new_type_id_node ) ) return info --- 271,275 ---- if ast.placement_expression: info.attr( 'placement_expression', self.visitASTNode( ast.placement_expression ) ) ! info.attr( 'type', self._nodeTreeIdentifier( ast.new_type_id_node ) ) return info |
From: Baptiste L. <bl...@us...> - 2004-08-08 19:15:44
|
Update of /cvsroot/cpptool/CppParser/src/pyrfta In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2889/src/pyrfta Modified Files: ast.py dumpast.py Log Message: * fixed assignment operator * added new operator Index: ast.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/ast.py,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ast.py 8 Aug 2004 17:26:34 -0000 1.8 --- ast.py 8 Aug 2004 19:15:31 -0000 1.9 *************** *** 341,347 **** self.init_declaration = simple_declaration ! class Condition(ASTElement): def __init__( self, node ): self.node = node class BreakStatement(Statement): --- 341,355 ---- self.init_declaration = simple_declaration ! class ExpressionCondition(ASTElement): ! def __init__( self, node, expression ): ! self.node = node ! self.expression = expression ! ! class DeclarationCondition(ASTElement): def __init__( self, node ): self.node = node + self.type_specifier = None + self.declarator = None + self.expression = None class BreakStatement(Statement): *************** *** 420,432 **** pass ! class BinaryExpression(ExpressionBase): def __init__( self, node ): ExpressionBase.__init__( self, node ) self.left_expression = None self.right_expression = None - class BinaryOperatorExpression(BinaryExpression): - pass # operator is first non silent symbol ? - class CallExpression(ExpressionBase): def __init__( self, node ): --- 428,438 ---- pass ! class BinaryOperatorExpression(ExpressionBase): def __init__( self, node ): ExpressionBase.__init__( self, node ) self.left_expression = None + self.operator_node = nodetools.getFirstTokenChildNode( node ) self.right_expression = None class CallExpression(ExpressionBase): def __init__( self, node ): *************** *** 454,457 **** --- 460,487 ---- self.expression = None + class ArrayAccessExpression(ExpressionBase): + def __init__( self, node ): + ExpressionBase.__init__( self, node ) + self.expression = None + self.index = None + + class NewOperatorExpression(ExpressionBase): + def __init__( self, node ): + ExpressionBase.__init__( self, node ) + self.placement_expression = None + self.new_type_id_node = None + + class UnaryOperatorExpression(ExpressionBase): + def __init__( self, node ): + ExpressionBase.__init__( self, node ) + self.expression = None + self.operator_node = nodetools.getFirstTokenChildNode( node ) + + class AssignmentOperatorExpression(BinaryOperatorExpression): + def __init__( self, node ): + ExpressionBase.__init__( self, node ) + self.left_expression = None + self.right_expression = None + ##################################### ##################################### *************** *** 502,506 **** ast = CaseStatement( statement ) value_node = nodetools.getFirstChildNamed( statement, 'constant_expression' ) ! #ast.setValue( ast.buildConstantExpression( value_node ) ) self.buildTargetStatement( ast, statement ) return ast --- 532,536 ---- ast = CaseStatement( statement ) value_node = nodetools.getFirstChildNamed( statement, 'constant_expression' ) ! ast.setValue( self.buildConstantExpression( value_node ) ) self.buildTargetStatement( ast, statement ) return ast *************** *** 566,570 **** def buildCondition( self, condition_node ): ! ast = Condition( condition_node ) return ast --- 596,613 ---- def buildCondition( self, condition_node ): ! expression_node = nodetools.tryGetFirstChildNamed( condition_node, 'expression' ) ! if expression_node: ! return ExpressionCondition( condition_node, ! self.buildExpression( expression_node ) ) ! ! ast = DeclarationCondition( condition_node ) ! type_specifier_node = nodetools.getFirstChildNamed( condition_node, 'type_specifier' ) ! ast.type_specifier = self.buildTypeSpecifier( type_specifier_node ) ! ! declarator_node = nodetools.getFirstChildNamed( condition_node, 'declarator' ) ! ast.declarator = Declarator( declarator_node ) ! ! init_node = nodetools.getFirstChildNamed( condition_node, 'assignment_expression' ) ! ast.expression = self.buildAssignementExpression( init_node ) return ast *************** *** 625,633 **** 'assignment_expression' : self.buildAssignementExpression, 'literal' : self.buildLiteralExpression, ! 'delete_operator' : self.buildDeleteOperator } def buildExpression( self, expression ): ! self.dispatchBuildExpression( nodetools.getFirstChild( expression ) ) def dispatchBuildExpression( self, expression ): --- 668,687 ---- 'assignment_expression' : self.buildAssignementExpression, 'literal' : self.buildLiteralExpression, ! 'delete_operator' : self.buildDeleteOperator, ! 'constant_expression' : self.buildConstantExpression, ! 'array_access' : self.buildArrayAccessExpression, ! 'unary_operator' : self.buildUnaryOperatorExpression, ! 'assignment_operator' : self.buildAssignmentOperatorExpression, ! 'new_operator' : self.buildNewOperatorExpression } + def buildAssignmentOperatorExpression( self, expression ): + ast = AssignmentOperatorExpression( expression ) + ast.left_expression = self.dispatchBuildExpression( nodetools.getCompositeChildAt( expression, 0 ) ) + ast.right_expression = self.dispatchBuildExpression( nodetools.getCompositeChildAt( expression, 1 ) ) + return ast + def buildExpression( self, expression ): ! return self.dispatchBuildExpression( nodetools.getFirstChild( expression ) ) def dispatchBuildExpression( self, expression ): *************** *** 642,656 **** return ast ! def buildCallOrConversionExpression( self, expression ): ! ast = CallOrConversionExpression( expression ) ! return ast ! ! def buildPostIncDecExpression( self, expression ): ! ast = PostIncDecExpression( expression ) ! ast.expression = self.dispatchBuildExpression( nodetools.getFirstCompositeChild( expression ) ) return ast ! def buildIdExpression( self, expression ): ! return IdExpression( expression ) def buildBinaryOperatorExpression( self, expression ): --- 696,708 ---- return ast ! def buildArrayAccessExpression( self, expression ): ! ast = ArrayAccessExpression( expression ) ! ast.expression = self.dispatchBuildExpression( nodetools.getFirstChild( expression ) ) ! index_node = nodetools.getFirstChildNamed( expression, 'array_index' ) ! ast.index = self.buildExpression( nodetools.getFirstChildNamed( index_node, 'expression' ) ) return ast ! def buildAssignementExpression( self, expression ): ! return self.dispatchBuildExpression( nodetools.getFirstChild( expression ) ) def buildBinaryOperatorExpression( self, expression ): *************** *** 660,663 **** --- 712,720 ---- return ast + def buildCallOrConversionExpression( self, expression ): + ast = CallOrConversionExpression( expression ) + # todo + return ast + def buildCallExpression( self, expression ): ast = CallExpression( expression ) *************** *** 668,676 **** return ast ! def buildMemberAccessExpression( self, expression ): ! ast = MemberAccessExpression( expression ) ! ast.expression = self.dispatchBuildExpression( nodetools.getFirstChild( expression ) ) ! member_node = nodetools.getFirstChildNamed( expression, 'accessed_member' ) ! ast.member_node = member_node return ast --- 725,734 ---- return ast ! def buildConstantExpression( self, expression ): ! return self.dispatchBuildExpression( nodetools.getFirstChild( expression ) ) ! ! def buildDeleteOperator( self, expression ): ! ast = DeleteOperatorExpression( expression ) ! ast.expression = self.dispatchBuildExpression( nodetools.getFirstCompositeChild( expression ) ) return ast *************** *** 681,693 **** return ast ! def buildAssignementExpression( self, expression ): ! return self.dispatchBuildExpression( nodetools.getFirstChild( expression ) ) def buildLiteralExpression( self, expression ): return LiteralExpression( expression ) ! def buildDeleteOperator( self, expression ): ! ast = DeleteOperatorExpression( expression ) ! ast.expression = self.dispatchBuildExpression( nodetools.getFirstCompositeChild( expression ) ) return ast --- 739,772 ---- return ast ! def buildIdExpression( self, expression ): ! return IdExpression( expression ) def buildLiteralExpression( self, expression ): return LiteralExpression( expression ) ! def buildMemberAccessExpression( self, expression ): ! ast = MemberAccessExpression( expression ) ! ast.expression = self.dispatchBuildExpression( nodetools.getFirstChild( expression ) ) ! member_node = nodetools.getFirstChildNamed( expression, 'accessed_member' ) ! ast.member_node = member_node ! return ast ! ! def buildNewOperatorExpression( self, expression ): ! ast = NewOperatorExpression( expression ) ! placement_node = nodetools.tryGetFirstChildNamed( expression, 'new_placement' ) ! if placement_node: ! expression_list_node = nodetools.getFirstChildNamed( placement_expression, 'expression_list' ) ! ast.placement_expression = self.buildExpressionList( expression_list_node ) ! ast.new_type_id_node = nodetools.getFirstChildNamed( expression, 'new_type_id' ) ! return ast ! ! def buildPostIncDecExpression( self, expression ): ! ast = PostIncDecExpression( expression ) ! ast.expression = self.dispatchBuildExpression( nodetools.getFirstCompositeChild( expression ) ) ! return ast ! ! def buildUnaryOperatorExpression( self, expression ): ! ast = UnaryOperatorExpression( expression ) ! ast.expression = self.dispatchBuildExpression( nodetools.getFirstCompositeChild( expression ) ) return ast Index: dumpast.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/dumpast.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dumpast.py 8 Aug 2004 16:19:09 -0000 1.6 --- dumpast.py 8 Aug 2004 19:15:31 -0000 1.7 *************** *** 102,105 **** --- 102,116 ---- ## Statements + ################################################################# + def visitBreakStatement( self, ast ): + info = ASTInfo( ast ) + return info + + def visitCaseStatement( self, ast ): + info = ASTInfo( ast ) + info.attr( 'value', self.visitASTNode( ast.value ) ) + info.attr( 'statement', self.visitASTNode( ast.statement ) ) + return info + def visitCompoundStatement( self, ast ): info = ASTInfo( ast ) *************** *** 109,114 **** --- 120,149 ---- return info + def visitContinueStatement( self, ast ): + info = ASTInfo( ast ) + return info + + def visitDeclarationCondition( self, ast ): + info = ASTInfo( ast ) + #info.attr( 'type_specifier', self.visitASTNode( ast.type_specifier ) ) + info.attr( 'declarator', self.visitASTNode( ast.declarator ) ) + info.attr( 'expression', self.visitASTNode( ast.expression ) ) + return info + + def visitDeclarationStatement( self, ast ): + info = ASTInfo( ast ) + info.attr( 'declaration', self.visitASTNode( ast.declaration ) ) + return info + + def visitDefaultStatement( self, ast ): + return self.visitLabelStatement( ast ) + + def visitExpressionCondition( self, ast ): + return self.visitASTNode( ast.expression ) + def visitExpressionStatement( self, ast ): info = ASTInfo( ast ) + if ast.expression: + info.attr('expression', self.visitASTNode( ast.expression ) ) return info *************** *** 128,135 **** return self.visitASTNode( ast.init_declaration ) - def visitCondition( self, ast ): - info = ASTInfo( ast ) - return info - def visitIfStatement( self, ast ): info = ASTInfo( ast ) --- 163,166 ---- *************** *** 140,143 **** --- 171,185 ---- return info + def visitLabelStatement( self, ast ): + info = ASTInfo( ast ) + info.attr( 'statement', self.visitASTNode( ast.statement ) ) + return info + + def visitSwitchStatement( self, ast ): + info = ASTInfo( ast ) + info.attr( 'condition', self.visitASTNode( ast.condition ) ) + info.attr( 'statement', self.visitASTNode( ast.statement ) ) + return info + def visitTryBlockStatement( self, ast ): info = ASTInfo( ast ) *************** *** 153,189 **** return info ! def visitDeclarationStatement( self, ast ): info = ASTInfo( ast ) ! info.attr( 'declaration', self.visitASTNode( ast.declaration ) ) return info ! def visitSwitchStatement( self, ast ): info = ASTInfo( ast ) ! info.attr( 'condition', self.visitASTNode( ast.condition ) ) ! info.attr( 'statement', self.visitASTNode( ast.statement ) ) return info ! def visitCaseStatement( self, ast ): info = ASTInfo( ast ) - # info.attr( 'value', self.visitASTNode( ast.value ) ) - info.attr( 'statement', self.visitASTNode( ast.statement ) ) return info ! def visitLabelStatement( self, ast ): info = ASTInfo( ast ) ! info.attr( 'statement', self.visitASTNode( ast.statement ) ) return info ! def visitDefaultStatement( self, ast ): ! return self.visitLabelStatement( ast ) ! def visitBreakStatement( self, ast ): info = ASTInfo( ast ) return info ! def visitContinueStatement( self, ast ): info = ASTInfo( ast ) return info - --- 195,274 ---- return info ! ## Expressions ! ################################################################# ! def visitArrayAccessExpression( self, ast ): info = ASTInfo( ast ) ! info.attr( 'expression', self.visitASTNode( ast.expression ) ) ! info.attr( 'index', self.visitASTNode( ast.index ) ) return info ! def visitAssignmentOperatorExpression( self, ast ): info = ASTInfo( ast ) ! info.attr( 'left', self.visitASTNode( ast.left_expression ) ) ! info.attr( 'right', self.visitASTNode( ast.right_expression ) ) ! return info ! ! def visitBinaryOperatorExpression( self, ast ): ! info = ASTInfo( ast ) ! info.attr( 'left', self.visitASTNode( ast.left_expression ) ) ! info.attr( 'operator', ast.operator_node.text ) ! info.attr( 'right', self.visitASTNode( ast.right_expression ) ) ! return info ! ! def visitCallExpression( self, ast ): ! info = ASTInfo( ast ) ! info.attr( 'callee', self.visitASTNode( ast.callee ) ) ! info.attr( 'parameters', [] ) ! for parameter in ast.parameters: ! info.attr( 'parameters' ).append( self.visitASTNode( parameter ) ) return info ! def visitCallOrConversionExpression( self, ast ): info = ASTInfo( ast ) return info ! def visitDeleteOperatorExpression( self, ast ): info = ASTInfo( ast ) ! info.attr( 'expression', self.visitASTNode( ast.expression ) ) ! return info ! ! def visitExpressionList( self, ast ): ! info = ASTInfo( ast ) ! info.attr( 'list', [ self.visitASTNode( expression ) for expression in ast.expressions ] ) ! return info ! ! def visitIdExpression( self, ast ): ! info = ASTInfo( ast ) ! info.attr( 'id', self._nodeTreeSource( ast.node ) ) ! return info ! ! def visitLiteralExpression( self, ast ): ! info = ASTInfo( ast ) ! info.attr( 'literal', self._nodeTreeSource( ast.node ) ) return info ! def visitMemberAccessExpression( self, ast ): ! info = ASTInfo( ast ) ! info.attr( 'expression', self.visitASTNode( ast.expression ) ) ! info.attr( 'member', self._nodeTreeSource( ast.member_node ) ) ! return info ! def visitNewOperatorExpression( self, ast ): info = ASTInfo( ast ) + if ast.placement_expression: + info.attr( 'placement_expression', self.visitASTNode( ast.placement_expression ) ) + info.attr( 'type', self._nodeTreeSource( ast.new_type_id_node ) ) return info ! def visitPostIncDecExpression( self, ast ): info = ASTInfo( ast ) + info.attr( 'expression', self.visitASTNode( ast.expression ) ) + return info + + def visitUnaryOperatorExpression( self, ast ): + info = ASTInfo( ast ) + info.attr( 'operator', ast.operator_node.text ) + info.attr( 'expression', self.visitASTNode( ast.expression ) ) return info |
From: Baptiste L. <bl...@us...> - 2004-08-08 19:15:01
|
Update of /cvsroot/cpptool/CppParser/src/cppparser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2700/src/cppparser Modified Files: cpp_grammar.txt Log Message: * fixed structure error in assignment operator expression rules Index: cpp_grammar.txt =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/cppparser/cpp_grammar.txt,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** cpp_grammar.txt 8 Aug 2004 16:19:08 -0000 1.5 --- cpp_grammar.txt 8 Aug 2004 19:14:51 -0000 1.6 *************** *** 271,277 **** assignment_operator = %'= *= /= %= += -= >>= <<= &= ^= |='; assignment_expression_intern = conditional_expression ! || [ logical_or_expression assignment_operator assignment_expression ] || throw_expression ; --- 271,281 ---- assignment_operator = %'= *= /= %= += -= >>= <<= &= ^= |='; + #assignment_operation = + assignment_operation = :node( 'assignment_operator', + logical_or_expression assignment_operator assignment_expression ); + assignment_expression_intern = conditional_expression ! || assignment_operation || throw_expression ; |
From: Baptiste L. <bl...@us...> - 2004-08-08 17:26:44
|
Update of /cvsroot/cpptool/CppParser/src/pyrfta In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19513/src/pyrfta Modified Files: ast.py nodetools.py Log Message: * started wrapping expressions Index: nodetools.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/nodetools.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** nodetools.py 8 Aug 2004 15:55:03 -0000 1.4 --- nodetools.py 8 Aug 2004 17:26:34 -0000 1.5 *************** *** 11,14 **** --- 11,32 ---- return node.childAt(0) + def getFirstCompositeChild( node ): + for child in node.enumChildren(): + if not child.hasValidToken(): + return child + raise AssertionError( "Fail to get first chil in node %s" % node ) + + def getCompositeChildAt( node, index ): + current_index = 0 + for child in node.enumChildren(): + if not child.hasValidToken(): + if current_index == index: + return child + current_index += 1 + raise AssertionError( "Fail to get first chil in node %s" % node ) + + def getCompositeChildren( node ): + return [ child for child in node.enumChildren() if not child.hasValidToken() ] + def getFirstChildNamed( node, name ): for child in node.enumChildren(): Index: ast.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/ast.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ast.py 8 Aug 2004 16:19:09 -0000 1.7 --- ast.py 8 Aug 2004 17:26:34 -0000 1.8 *************** *** 358,362 **** class ExpressionStatement(Statement): ! pass class DeclarationStatement(Statement): --- 358,367 ---- class ExpressionStatement(Statement): ! def __init__( self, node ): ! Statement.__init__( self, node ) ! self.expression = None ! ! def setExpression( self, expression ): ! self.expression = expression class DeclarationStatement(Statement): *************** *** 382,389 **** self.body = body # catch exception is missing, need more structure in input ! ! class ASTBuilder: def __init__( self ): ! self.current = None self.declaration_builders = { 'simple_declaration' : self.buildSimpleDeclaration, --- 387,699 ---- self.body = body # catch exception is missing, need more structure in input ! ! ## ################################################################## ! ## ################################################################## ! ## AST Expressions ! ## ################################################################## ! ## ################################################################## ! ! class ExpressionBase(ASTElement): ! def __init__( self, node ): ! self.node = node ! ! class Expression(ExpressionBase): ! pass ! ! class AssignementExpressionList(ExpressionBase): ! def __init__( self, node ): ! ExpressionBase.__init__( self, node ) ! self.expressions = [] ! ! def addExpression( self, expression ): ! self.expressions.append( expression ) ! ! class CallOrConversionExpression(ExpressionBase): ! pass ! ! class PostIncDecExpression(ExpressionBase): ! def __init__( self, node ): ! ExpressionBase.__init__( self, node ) ! self.expression = None # ++ / -- in 'post_operator' child ! ! class IdExpression(ExpressionBase): ! pass ! ! class BinaryExpression(ExpressionBase): ! def __init__( self, node ): ! ExpressionBase.__init__( self, node ) ! self.left_expression = None ! self.right_expression = None ! ! class BinaryOperatorExpression(BinaryExpression): ! pass # operator is first non silent symbol ? ! ! class CallExpression(ExpressionBase): ! def __init__( self, node ): ! ExpressionBase.__init__( self, node ) ! self.callee = None ! self.parameters = [] ! ! class MemberAccessExpression(ExpressionBase): ! def __init__( self, node ): # -> or . in child 'accessed_member' ! ExpressionBase.__init__( self, node ) ! self.expression = None ! self.member_node = None # id of the accessed member ! ! class ExpressionList(ExpressionBase): ! def __init__( self, node ): # -> or . in child 'accessed_member' ! ExpressionBase.__init__( self, node ) ! self.expressions = [] ! ! class LiteralExpression(ExpressionBase): ! pass ! ! class DeleteOperatorExpression(ExpressionBase): ! def __init__( self, node ): ! ExpressionBase.__init__( self, node ) ! self.expression = None ! ! ##################################### ! ##################################### ! ## Statements ! ##################################### ! ##################################### ! ! class ASTStatementsBuilder: def __init__( self ): ! self.statement_builders = { ! 'compound_statement' : self.buildCompoundStatement, ! 'error_statement' : self.buildErrorStatement, ! 'label_statement' : self.buildLabelStatement, ! 'case_statement' : self.buildCaseStatement, ! 'default_statement' : self.buildDefaultStatement, ! 'if_statement' : self.buildIfStatement, ! 'switch_statement' : self.buildSwitchStatement, ! 'while_statement' : self.buildWhileStatement, ! 'dowhile_statement' : self.buildDoWhileStatement, ! 'for_statement' : self.buildForStatement, ! 'break_statement' : self.buildBreakStatement, ! 'continue_statement' : self.buildContinueStatement, ! 'return_statement' : self.buildReturnStatement, ! 'goto_statement' : self.buildGotoStatement, ! 'expression_statement' : self.buildExpressionStatement, ! 'declaration_statement' : self.buildDeclarationStatement, ! 'try_block' : self.buildTryBlockStatement ! } ! ! def buildStatement( self, statement_node ): ! return self.statement_builders[ statement_node.name ]( statement_node ) ! ! def buildErrorStatement( self, statement ): ! return ErrorStatement( statement ) ! ! def buildCompoundStatement( self, statement ): ! ast = CompoundStatement( statement ) ! for child in statement.enumChildren(): ! if not child.hasValidToken(): ! statement = self.buildStatement( child ) ! ast.addStatement( statement ) ! return ast ! ! def buildLabelStatement( self, statement ): ! return self.buildTargetStatement( LabelStatement( statement ), statement ) ! ! def buildCaseStatement( self, statement ): ! ast = CaseStatement( statement ) ! value_node = nodetools.getFirstChildNamed( statement, 'constant_expression' ) ! #ast.setValue( ast.buildConstantExpression( value_node ) ) ! self.buildTargetStatement( ast, statement ) ! return ast ! ! def buildDefaultStatement( self, statement ): ! return self.buildTargetStatement( DefaultStatement( statement ), statement ) ! ! def buildTargetStatement( self, ast, label_statement_node ): ! target_statement_node = nodetools.getFirstChildNamed( label_statement_node, 'target_statement' ) ! ast.setStatement( self.buildStatement( nodetools.getFirstChild( target_statement_node ) ) ) ! return ast ! ! def buildIfStatement( self, statement ): ! ast = IfStatement( statement ) ! condition_node = nodetools.getFirstChildNamed( statement, 'condition' ) ! ast.setCondition( self.buildCondition( condition_node ) ) ! statement_node = nodetools.getFirstChildNamed( statement, 'then_statement' ) ! ast.setThenStatement( self.buildStatement( nodetools.getFirstChild( statement_node ) ) ) ! statement_node = nodetools.tryGetFirstChildNamed( statement, 'else_statement' ) ! if statement_node: ! ast.setElseStatement( self.buildStatement( nodetools.getFirstChild( statement_node ) ) ) ! return ast ! ! def buildSwitchStatement( self, statement ): ! ast = SwitchStatement( statement ) ! condition_node = nodetools.getFirstChildNamed( statement, 'condition' ) ! ast.setCondition( self.buildCondition( condition_node ) ) ! statement_node = nodetools.getFirstChildNamed( statement, 'condition_statement' ) ! ast.setStatement( self.buildStatement( nodetools.getFirstChild( statement_node ) ) ) ! return ast ! ! def buildWhileStatement( self, statement ): ! return WhileStatement( statement ) ! ! def buildDoWhileStatement( self, statement ): ! return DoWhileStatement( statement ) ! ! def buildForStatement( self, statement ): ! ast = ForStatement( statement ) ! for_init_statement_node = nodetools.getFirstChildNamed( statement, 'for_init_statement' ) ! init_node = nodetools.tryGetFirstChildNamed( for_init_statement_node, 'expression_statement' ) ! if init_node: ! init = ForInitStatement( self.buildExpressionStatement( init_node ) ) ! else: ! init_declaration_node = nodetools.getFirstChildNamed( for_init_statement_node, ! 'simple_declaration' ) ! init = ForInitDeclaration( self.buildSimpleDeclaration( init_declaration_node ) ) ! ast.setInit( init ) ! ! for_condition_node = nodetools.tryGetFirstChildNamed( statement, 'for_condition' ) ! if for_condition_node: ! ast.setCondition( self.buildCondition( for_condition_node ) ) ! ! expression_node = nodetools.tryGetFirstChildNamed( statement, 'expression' ) ! if expression_node: ! ast.setLoopExpression( self.buildExpression( expression_node ) ) ! ! for_loop_statement_node = nodetools.getFirstChild( nodetools.getFirstChildNamed( statement, ! 'for_loop_statement' ) ) ! loop_statement = self.buildStatement( for_loop_statement_node ) ! ast.setLoopStatement( loop_statement ) ! return ast ! ! def buildCondition( self, condition_node ): ! ast = Condition( condition_node ) ! return ast ! ! def buildBreakStatement( self, statement ): ! return BreakStatement( statement ) ! ! def buildContinueStatement( self, statement ): ! return ContinueStatement( statement ) ! ! def buildReturnStatement( self, statement ): ! return ReturnStatement( statement ) ! ! def buildGotoStatement( self, statement ): ! return GotoStatement( statement ) ! ! def buildExpressionStatement( self, statement ): ! ast = ExpressionStatement( statement ) ! expression_node = nodetools.tryGetFirstChildNamed( statement, 'expression' ) ! if expression_node: ! ast.setExpression( self.buildExpression( expression_node ) ) ! return ast ! ! def buildDeclarationStatement( self, statement ): ! ast = DeclarationStatement( statement ) ! declaration_node = nodetools.getFirstChild( statement ) ! declaration = self.declaration_builders[ declaration_node.name ]( declaration_node ) ! ast.setDeclaration( declaration ) ! return ast ! ! def buildTryBlockStatement( self, statement ): ! body = self.buildCompoundStatement( nodetools.getFirstChildNamed(statement, 'compound_statement') ) ! ast = TryBlockStatement( statement, body ) ! for child in nodetools.getChildrenNamed( statement, 'exception_handler' ): ! body_node = nodetools.getFirstChildNamed( child, 'compound_statement' ) ! handler = ExceptionHandler( child, self.buildCompoundStatement( body_node ) ) ! ast.addHandler( handler ) ! return ast ! ! ! ! ##################################### ! ##################################### ! ## Expressions ! ##################################### ! ##################################### ! ! class ASTExpressionsBuilder: ! def __init__( self ): ! self.expression_builders = { ! 'assignment_expression_list' : self.buildAssignementExpressionList, ! 'call_or_conversion_expression' : self.buildCallOrConversionExpression, ! 'post_incdec' : self.buildPostIncDecExpression, ! 'id_expression' : self.buildIdExpression, ! 'binary_operator' : self.buildBinaryOperatorExpression, ! 'call' : self.buildCallExpression, ! 'member_access' : self.buildMemberAccessExpression, ! 'expression_list' : self.buildExpressionList, ! 'assignment_expression' : self.buildAssignementExpression, ! 'literal' : self.buildLiteralExpression, ! 'delete_operator' : self.buildDeleteOperator ! } ! ! def buildExpression( self, expression ): ! self.dispatchBuildExpression( nodetools.getFirstChild( expression ) ) ! ! def dispatchBuildExpression( self, expression ): ! return self.expression_builders[ expression.name ]( expression ) ! ! def buildAssignementExpressionList( self, expression ): ! ast = AssignementExpressionList( expression ) ! for child in expression.enumChildren(): ! if not child.hasValidToken(): ! assignment_expression = self.dispatchBuildExpression( child ) ! ast.addExpression( assignment_expression ) ! return ast ! ! def buildCallOrConversionExpression( self, expression ): ! ast = CallOrConversionExpression( expression ) ! return ast ! ! def buildPostIncDecExpression( self, expression ): ! ast = PostIncDecExpression( expression ) ! ast.expression = self.dispatchBuildExpression( nodetools.getFirstCompositeChild( expression ) ) ! return ast ! ! def buildIdExpression( self, expression ): ! return IdExpression( expression ) ! ! def buildBinaryOperatorExpression( self, expression ): ! ast = BinaryOperatorExpression( expression ) ! ast.left_expression = self.dispatchBuildExpression( nodetools.getCompositeChildAt( expression, 0 ) ) ! ast.right_expression = self.dispatchBuildExpression( nodetools.getCompositeChildAt( expression, 1 ) ) ! return ast ! ! def buildCallExpression( self, expression ): ! ast = CallExpression( expression ) ! ast.callee = self.dispatchBuildExpression( nodetools.getCompositeChildAt( expression, 0 ) ) ! call_parameters_node = nodetools.getFirstChildNamed( expression, 'call_parameters' ) ! for parameter_node in nodetools.getCompositeChildren( call_parameters_node ): ! ast.parameters.append( self.dispatchBuildExpression( parameter_node ) ) ! return ast ! ! def buildMemberAccessExpression( self, expression ): ! ast = MemberAccessExpression( expression ) ! ast.expression = self.dispatchBuildExpression( nodetools.getFirstChild( expression ) ) ! member_node = nodetools.getFirstChildNamed( expression, 'accessed_member' ) ! ast.member_node = member_node ! return ast ! ! def buildExpressionList( self, expression ): ! ast = ExpressionList( expression ) ! for child in nodetools.getChildrenNamed( expression, 'assignment_expression' ): ! ast.expressions.append( self.dispatchBuildExpression( child ) ) ! return ast ! ! def buildAssignementExpression( self, expression ): ! return self.dispatchBuildExpression( nodetools.getFirstChild( expression ) ) ! ! def buildLiteralExpression( self, expression ): ! return LiteralExpression( expression ) ! ! def buildDeleteOperator( self, expression ): ! ast = DeleteOperatorExpression( expression ) ! ast.expression = self.dispatchBuildExpression( nodetools.getFirstCompositeChild( expression ) ) ! return ast ! ! class ASTBuilder(ASTStatementsBuilder,ASTExpressionsBuilder): ! def __init__( self ): ! ASTStatementsBuilder.__init__( self ) ! ASTExpressionsBuilder.__init__( self ) self.declaration_builders = { 'simple_declaration' : self.buildSimpleDeclaration, *************** *** 415,438 **** 'member_error' : self.buildMemberErrorDeclaration } ! self.statement_builders = { ! 'compound_statement' : self.buildCompoundStatement, ! 'error_statement' : self.buildErrorStatement, ! 'label_statement' : self.buildLabelStatement, ! 'case_statement' : self.buildCaseStatement, ! 'default_statement' : self.buildDefaultStatement, ! 'if_statement' : self.buildIfStatement, ! 'switch_statement' : self.buildSwitchStatement, ! 'while_statement' : self.buildWhileStatement, ! 'dowhile_statement' : self.buildDoWhileStatement, ! 'for_statement' : self.buildForStatement, ! 'break_statement' : self.buildBreakStatement, ! 'continue_statement' : self.buildContinueStatement, ! 'return_statement' : self.buildReturnStatement, ! 'goto_statement' : self.buildGotoStatement, ! 'expression_statement' : self.buildExpressionStatement, ! 'declaration_statement' : self.buildDeclarationStatement, ! 'try_block' : self.buildTryBlockStatement ! } ! def buildTranslationUnit( self, root ): assert root.name == 'translation_unit' --- 725,729 ---- 'member_error' : self.buildMemberErrorDeclaration } ! def buildTranslationUnit( self, root ): assert root.name == 'translation_unit' *************** *** 616,741 **** # ? exception_specification return ast - - ##################################### - ## Statements - ##################################### - - def buildStatement( self, statement_node ): - return self.statement_builders[ statement_node.name ]( statement_node ) - - def buildErrorStatement( self, statement ): - return ErrorStatement( statement ) - - def buildCompoundStatement( self, statement ): - ast = CompoundStatement( statement ) - for child in statement.enumChildren(): - if not child.hasValidToken(): - statement = self.buildStatement( child ) - ast.addStatement( statement ) - return ast - - def buildLabelStatement( self, statement ): - return self.buildTargetStatement( LabelStatement( statement ), statement ) - - def buildCaseStatement( self, statement ): - ast = CaseStatement( statement ) - value_node = nodetools.getFirstChildNamed( statement, 'constant_expression' ) - #ast.setValue( ast.buildConstantExpression( value_node ) ) - self.buildTargetStatement( ast, statement ) - return ast - - def buildDefaultStatement( self, statement ): - return self.buildTargetStatement( DefaultStatement( statement ), statement ) - - def buildTargetStatement( self, ast, label_statement_node ): - target_statement_node = nodetools.getFirstChildNamed( label_statement_node, 'target_statement' ) - ast.setStatement( self.buildStatement( nodetools.getFirstChild( target_statement_node ) ) ) - return ast - - def buildIfStatement( self, statement ): - ast = IfStatement( statement ) - condition_node = nodetools.getFirstChildNamed( statement, 'condition' ) - ast.setCondition( self.buildCondition( condition_node ) ) - statement_node = nodetools.getFirstChildNamed( statement, 'then_statement' ) - ast.setThenStatement( self.buildStatement( nodetools.getFirstChild( statement_node ) ) ) - statement_node = nodetools.tryGetFirstChildNamed( statement, 'else_statement' ) - if statement_node: - ast.setElseStatement( self.buildStatement( nodetools.getFirstChild( statement_node ) ) ) - return ast - - def buildSwitchStatement( self, statement ): - ast = SwitchStatement( statement ) - condition_node = nodetools.getFirstChildNamed( statement, 'condition' ) - ast.setCondition( self.buildCondition( condition_node ) ) - statement_node = nodetools.getFirstChildNamed( statement, 'condition_statement' ) - ast.setStatement( self.buildStatement( nodetools.getFirstChild( statement_node ) ) ) - return ast - - def buildWhileStatement( self, statement ): - return WhileStatement( statement ) - - def buildDoWhileStatement( self, statement ): - return DoWhileStatement( statement ) - - def buildForStatement( self, statement ): - ast = ForStatement( statement ) - for_init_statement_node = nodetools.getFirstChildNamed( statement, 'for_init_statement' ) - init_node = nodetools.tryGetFirstChildNamed( for_init_statement_node, 'expression_statement' ) - if init_node: - init = ForInitStatement( self.buildExpressionStatement( init_node ) ) - else: - init_declaration_node = nodetools.getFirstChildNamed( for_init_statement_node, - 'simple_declaration' ) - init = ForInitDeclaration( self.buildSimpleDeclaration( init_declaration_node ) ) - ast.setInit( init ) - - for_condition_node = nodetools.tryGetFirstChildNamed( statement, 'for_condition' ) - if for_condition_node: - ast.setCondition( self.buildCondition( for_condition_node ) ) - - ## expression_node = nodetools.tryGetFirstChildNamed( statement, 'expression' ) - ## if expression_node: - ## ast.setLoopExpression( self.buildExpression( expression_node ) ) - - for_loop_statement_node = nodetools.getFirstChild( nodetools.getFirstChildNamed( statement, - 'for_loop_statement' ) ) - loop_statement = self.buildStatement( for_loop_statement_node ) - ast.setLoopStatement( loop_statement ) - return ast - - def buildCondition( self, condition_node ): - ast = Condition( condition_node ) - return ast - - def buildBreakStatement( self, statement ): - return BreakStatement( statement ) - - def buildContinueStatement( self, statement ): - return ContinueStatement( statement ) - - def buildReturnStatement( self, statement ): - return ReturnStatement( statement ) - - def buildGotoStatement( self, statement ): - return GotoStatement( statement ) - - def buildExpressionStatement( self, statement ): - return ExpressionStatement( statement ) - - def buildDeclarationStatement( self, statement ): - ast = DeclarationStatement( statement ) - declaration_node = nodetools.getFirstChild( statement ) - declaration = self.declaration_builders[ declaration_node.name ]( declaration_node ) - ast.setDeclaration( declaration ) - return ast - - def buildTryBlockStatement( self, statement ): - body = self.buildCompoundStatement( nodetools.getFirstChildNamed(statement, 'compound_statement') ) - ast = TryBlockStatement( statement, body ) - for child in nodetools.getChildrenNamed( statement, 'exception_handler' ): - body_node = nodetools.getFirstChildNamed( child, 'compound_statement' ) - handler = ExceptionHandler( child, self.buildCompoundStatement( body_node ) ) - ast.addHandler( handler ) - return ast - - --- 907,908 ---- |
From: Baptiste L. <bl...@us...> - 2004-08-08 16:19:17
|
Update of /cvsroot/cpptool/CppParser/src/pyrfta In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10274/src/pyrfta Modified Files: ast.py dumpast.py Log Message: * improved support for if statement Index: ast.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/ast.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ast.py 8 Aug 2004 16:12:52 -0000 1.6 --- ast.py 8 Aug 2004 16:19:09 -0000 1.7 *************** *** 280,284 **** class IfStatement(Statement): ! pass class SwitchStatement(Statement): --- 280,297 ---- class IfStatement(Statement): ! def __init__( self, node ): ! Statement.__init__( self, node ) ! self.condition = None ! self.then_statement = None ! self.else_statement = None ! ! def setCondition( self, condition ): ! self.condition = condition ! ! def setThenStatement( self, statement ): ! self.then_statement = statement ! ! def setElseStatement( self, statement ): ! self.else_statement = statement class SwitchStatement(Statement): *************** *** 639,646 **** ast.setStatement( self.buildStatement( nodetools.getFirstChild( target_statement_node ) ) ) return ast - def buildIfStatement( self, statement ): ! return IfStatement( statement ) def buildSwitchStatement( self, statement ): --- 652,666 ---- ast.setStatement( self.buildStatement( nodetools.getFirstChild( target_statement_node ) ) ) return ast def buildIfStatement( self, statement ): ! ast = IfStatement( statement ) ! condition_node = nodetools.getFirstChildNamed( statement, 'condition' ) ! ast.setCondition( self.buildCondition( condition_node ) ) ! statement_node = nodetools.getFirstChildNamed( statement, 'then_statement' ) ! ast.setThenStatement( self.buildStatement( nodetools.getFirstChild( statement_node ) ) ) ! statement_node = nodetools.tryGetFirstChildNamed( statement, 'else_statement' ) ! if statement_node: ! ast.setElseStatement( self.buildStatement( nodetools.getFirstChild( statement_node ) ) ) ! return ast def buildSwitchStatement( self, statement ): Index: dumpast.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/dumpast.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dumpast.py 8 Aug 2004 16:12:52 -0000 1.5 --- dumpast.py 8 Aug 2004 16:19:09 -0000 1.6 *************** *** 134,137 **** --- 134,141 ---- def visitIfStatement( self, ast ): info = ASTInfo( ast ) + info.attr( 'condition', self.visitASTNode( ast.condition ) ) + info.attr( 'then_statement', self.visitASTNode( ast.then_statement ) ) + if ast.else_statement: + info.attr( 'else_statement', self.visitASTNode( ast.else_statement ) ) return info |
From: Baptiste L. <bl...@us...> - 2004-08-08 16:19:17
|
Update of /cvsroot/cpptool/CppParser/src/cppparser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10274/src/cppparser Modified Files: cpp_grammar.txt Log Message: * improved support for if statement Index: cpp_grammar.txt =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/cppparser/cpp_grammar.txt,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** cpp_grammar.txt 8 Aug 2004 16:12:52 -0000 1.4 --- cpp_grammar.txt 8 Aug 2004 16:19:08 -0000 1.5 *************** *** 320,324 **** selection_statement = :node( 'if_statement', ! 'if' '(' condition ')' statement ?( 'else' statement ) ) | :node( 'switch_statement', 'switch' '(' :node('condition', condition) ')' --- 320,326 ---- selection_statement = :node( 'if_statement', ! 'if' '(' :node('condition', condition) ')' ! :node('then_statement', statement) ! ?( 'else' :node('else_statement', statement) ) ) | :node( 'switch_statement', 'switch' '(' :node('condition', condition) ')' |
From: Baptiste L. <bl...@us...> - 2004-08-08 16:13:01
|
Update of /cvsroot/cpptool/CppParser/src/pyrfta In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9161/src/pyrfta Modified Files: ast.py dumpast.py Log Message: * improved support for label statements Index: ast.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/ast.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ast.py 8 Aug 2004 15:55:03 -0000 1.5 --- ast.py 8 Aug 2004 16:12:52 -0000 1.6 *************** *** 259,278 **** class ErrorStatement(Statement): pass class LabelStatement(Statement): - pass - - class CaseStatement(Statement): def __init__( self, node ): Statement.__init__( self, node ) - self.value = None self.statement = None - def setValue( self, value ): - self.value = value - def setStatement( self, statement ): self.statement = statement ! class DefaultStatement(Statement): pass --- 259,280 ---- class ErrorStatement(Statement): pass + class LabelStatement(Statement): def __init__( self, node ): Statement.__init__( self, node ) self.statement = None def setStatement( self, statement ): self.statement = statement ! class CaseStatement(LabelStatement): ! def __init__( self, node ): ! LabelStatement.__init__( self, node ) ! self.value = None ! ! def setValue( self, value ): ! self.value = value ! ! class DefaultStatement(LabelStatement): pass *************** *** 621,625 **** def buildLabelStatement( self, statement ): ! return LabelStatement( statement ) def buildCaseStatement( self, statement ): --- 623,627 ---- def buildLabelStatement( self, statement ): ! return self.buildTargetStatement( LabelStatement( statement ), statement ) def buildCaseStatement( self, statement ): *************** *** 627,636 **** value_node = nodetools.getFirstChildNamed( statement, 'constant_expression' ) #ast.setValue( ast.buildConstantExpression( value_node ) ) ! target_statement_node = nodetools.getFirstChildNamed( statement, 'target_statement' ) ! ast.setStatement( self.buildStatement( nodetools.getFirstChild( target_statement_node ) ) ) return ast def buildDefaultStatement( self, statement ): ! return DefaultStatement( statement ) def buildIfStatement( self, statement ): --- 629,643 ---- value_node = nodetools.getFirstChildNamed( statement, 'constant_expression' ) #ast.setValue( ast.buildConstantExpression( value_node ) ) ! self.buildTargetStatement( ast, statement ) return ast def buildDefaultStatement( self, statement ): ! return self.buildTargetStatement( DefaultStatement( statement ), statement ) ! ! def buildTargetStatement( self, ast, label_statement_node ): ! target_statement_node = nodetools.getFirstChildNamed( label_statement_node, 'target_statement' ) ! ast.setStatement( self.buildStatement( nodetools.getFirstChild( target_statement_node ) ) ) ! return ast ! def buildIfStatement( self, statement ): Index: dumpast.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/dumpast.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dumpast.py 8 Aug 2004 15:55:03 -0000 1.4 --- dumpast.py 8 Aug 2004 16:12:52 -0000 1.5 *************** *** 166,174 **** return info ! def visitBreakStatement( self, ast ): ! return ASTInfo( ast ) def visitDefaultStatement( self, ast ): ! return ASTInfo( ast ) --- 166,184 ---- return info ! def visitLabelStatement( self, ast ): ! info = ASTInfo( ast ) ! info.attr( 'statement', self.visitASTNode( ast.statement ) ) ! return info def visitDefaultStatement( self, ast ): ! return self.visitLabelStatement( ast ) ! ! def visitBreakStatement( self, ast ): ! info = ASTInfo( ast ) ! return info ! ! def visitContinueStatement( self, ast ): ! info = ASTInfo( ast ) ! return info *************** *** 206,210 **** print 'Parsing', sys.argv[1] translation_unit_node = parser.parse( source ) - print 'Building ast..' ast = ast.ASTBuilder().buildTranslationUnit( translation_unit_node ) --- 216,219 ---- |
From: Baptiste L. <bl...@us...> - 2004-08-08 16:13:00
|
Update of /cvsroot/cpptool/CppParser/src/cppparser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9161/src/cppparser Modified Files: cpp_grammar.txt Log Message: * improved support for label statements Index: cpp_grammar.txt =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/cppparser/cpp_grammar.txt,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** cpp_grammar.txt 8 Aug 2004 15:55:03 -0000 1.3 --- cpp_grammar.txt 8 Aug 2004 16:12:52 -0000 1.4 *************** *** 333,340 **** # '{' *( statement | error_recovery_statement ) '}' ); ! labeled_statement = :node('label_statement', id ':' statement) ! | :node('case_statement', 'case' constant_expression ':' ! :node('target_statement', statement ) ) ! | :node('default_statement', 'default' ':' statement ); declaration_statement = :node( 'declaration_statement', block_declaration ); --- 333,341 ---- # '{' *( statement | error_recovery_statement ) '}' ); ! target_statement = ':' :node('target_statement', statement ); ! ! labeled_statement = :node('label_statement', id target_statement ) ! | :node('case_statement', 'case' constant_expression target_statement ) ! | :node('default_statement', 'default' target_statement ); declaration_statement = :node( 'declaration_statement', block_declaration ); |
From: Baptiste L. <bl...@us...> - 2004-08-08 15:55:12
|
Update of /cvsroot/cpptool/CppParser/src/pyrfta In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6127/src/pyrfta Modified Files: ast.py dumpast.py nodetools.py Log Message: * enhanced wrapping of for, switch, case and default statements Index: nodetools.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/nodetools.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** nodetools.py 8 Aug 2004 14:50:29 -0000 1.3 --- nodetools.py 8 Aug 2004 15:55:03 -0000 1.4 *************** *** 3,7 **** def getFirstChild( node ): if node.childCount == 0: ! raise LogicError( "Fail to get first chil in node %s" % node ) return node.childAt(0) --- 3,7 ---- def getFirstChild( node ): if node.childCount == 0: ! raise AssertionError( "Fail to get first chil in node %s" % node ) return node.childAt(0) *************** *** 15,19 **** if child.name == name: return child ! raise LogicError( "Fail to find children named '%s' in node %s" % (name,node) ) def tryGetFirstChildNamed( node, name ): --- 15,19 ---- if child.name == name: return child ! raise AssertionError( "Fail to find children named '%s' in node %s" % (name,node) ) def tryGetFirstChildNamed( node, name ): *************** *** 31,35 **** return child if exception_if_not_found: ! raise LogicError( "Fail to find identifier child in node %s" % node ) return None --- 31,35 ---- return child if exception_if_not_found: ! raise AssertionError( "Fail to find identifier child in node %s" % node ) return None *************** *** 39,43 **** return child if exception_if_not_found: ! raise LogicError( "Fail to find string child in node %s" % node) return None --- 39,43 ---- return child if exception_if_not_found: ! raise AssertionError( "Fail to find string child in node %s" % node) return None *************** *** 46,48 **** if child.hasValidToken(): return child ! raise LogicError( "Fail to find a child node with token in %s." % node ) \ No newline at end of file --- 46,48 ---- if child.hasValidToken(): return child ! raise AssertionError( "Fail to find a child node with token in %s." % node ) \ No newline at end of file Index: ast.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/ast.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ast.py 8 Aug 2004 14:50:29 -0000 1.4 --- ast.py 8 Aug 2004 15:55:03 -0000 1.5 *************** *** 263,267 **** class CaseStatement(Statement): ! pass class DefaultStatement(Statement): --- 263,276 ---- class CaseStatement(Statement): ! def __init__( self, node ): ! Statement.__init__( self, node ) ! self.value = None ! self.statement = None ! ! def setValue( self, value ): ! self.value = value ! ! def setStatement( self, statement ): ! self.statement = statement class DefaultStatement(Statement): *************** *** 272,276 **** class SwitchStatement(Statement): ! pass class WhileStatement(Statement): --- 281,294 ---- class SwitchStatement(Statement): ! def __init__( self, node ): ! Statement.__init__( self, node ) ! self.condition = None ! self.statement = None ! ! def setCondition( self, condition ): ! self.condition = condition ! ! def setStatement( self, statement ): ! self.statement = statement class WhileStatement(Statement): *************** *** 281,285 **** class ForStatement(Statement): ! pass class BreakStatement(Statement): --- 299,332 ---- class ForStatement(Statement): ! def __init__( self, node ): ! Statement.__init__( self, node ) ! self.init = None ! self.condition = None ! self.loop_expression = None ! self.loop_statement = None ! ! def setInit( self, init ): ! self.init = init ! ! def setCondition( self, condition ): ! self.condition = condition ! ! def setLoopExpression( self, expression ): ! self.loop_expression = expression ! ! def setLoopStatement( self, statement ): ! self.loop_statement = statement ! ! class ForInitStatement: ! def __init__( self, statement ): ! self.init_statement = statement ! ! class ForInitDeclaration: ! def __init__( self, simple_declaration ): ! self.init_declaration = simple_declaration ! ! class Condition(ASTElement): ! def __init__( self, node ): ! self.node = node class BreakStatement(Statement): *************** *** 427,431 **** elif declaration_specifier.name == 'declaration_specifier': return self.buildStandardSimpleDeclaration( declaration, declaration_specifier ) ! raise LogicError( "Don't know how to build simple declaration for: '%s'" % declaration_specifier.name ) else: return self.buildDeclaratorsSimpleDeclaration( declaration ) --- 474,478 ---- elif declaration_specifier.name == 'declaration_specifier': return self.buildStandardSimpleDeclaration( declaration, declaration_specifier ) ! raise AssertionError( "Don't know how to build simple declaration for: '%s'" % declaration_specifier.name ) else: return self.buildDeclaratorsSimpleDeclaration( declaration ) *************** *** 559,562 **** --- 606,612 ---- ##################################### + def buildStatement( self, statement_node ): + return self.statement_builders[ statement_node.name ]( statement_node ) + def buildErrorStatement( self, statement ): return ErrorStatement( statement ) *************** *** 566,570 **** for child in statement.enumChildren(): if not child.hasValidToken(): ! statement = self.statement_builders[ child.name ]( child ) ast.addStatement( statement ) return ast --- 616,620 ---- for child in statement.enumChildren(): if not child.hasValidToken(): ! statement = self.buildStatement( child ) ast.addStatement( statement ) return ast *************** *** 574,578 **** def buildCaseStatement( self, statement ): ! return CaseStatement( statement ) def buildDefaultStatement( self, statement ): --- 624,633 ---- def buildCaseStatement( self, statement ): ! ast = CaseStatement( statement ) ! value_node = nodetools.getFirstChildNamed( statement, 'constant_expression' ) ! #ast.setValue( ast.buildConstantExpression( value_node ) ) ! target_statement_node = nodetools.getFirstChildNamed( statement, 'target_statement' ) ! ast.setStatement( self.buildStatement( nodetools.getFirstChild( target_statement_node ) ) ) ! return ast def buildDefaultStatement( self, statement ): *************** *** 583,587 **** def buildSwitchStatement( self, statement ): ! return SwitchStatement( statement ) def buildWhileStatement( self, statement ): --- 638,647 ---- def buildSwitchStatement( self, statement ): ! ast = SwitchStatement( statement ) ! condition_node = nodetools.getFirstChildNamed( statement, 'condition' ) ! ast.setCondition( self.buildCondition( condition_node ) ) ! statement_node = nodetools.getFirstChildNamed( statement, 'condition_statement' ) ! ast.setStatement( self.buildStatement( nodetools.getFirstChild( statement_node ) ) ) ! return ast def buildWhileStatement( self, statement ): *************** *** 592,596 **** def buildForStatement( self, statement ): ! return ForStatement( statement ) def buildBreakStatement( self, statement ): --- 652,683 ---- def buildForStatement( self, statement ): ! ast = ForStatement( statement ) ! for_init_statement_node = nodetools.getFirstChildNamed( statement, 'for_init_statement' ) ! init_node = nodetools.tryGetFirstChildNamed( for_init_statement_node, 'expression_statement' ) ! if init_node: ! init = ForInitStatement( self.buildExpressionStatement( init_node ) ) ! else: ! init_declaration_node = nodetools.getFirstChildNamed( for_init_statement_node, ! 'simple_declaration' ) ! init = ForInitDeclaration( self.buildSimpleDeclaration( init_declaration_node ) ) ! ast.setInit( init ) ! ! for_condition_node = nodetools.tryGetFirstChildNamed( statement, 'for_condition' ) ! if for_condition_node: ! ast.setCondition( self.buildCondition( for_condition_node ) ) ! ! ## expression_node = nodetools.tryGetFirstChildNamed( statement, 'expression' ) ! ## if expression_node: ! ## ast.setLoopExpression( self.buildExpression( expression_node ) ) ! ! for_loop_statement_node = nodetools.getFirstChild( nodetools.getFirstChildNamed( statement, ! 'for_loop_statement' ) ) ! loop_statement = self.buildStatement( for_loop_statement_node ) ! ast.setLoopStatement( loop_statement ) ! return ast ! ! def buildCondition( self, condition_node ): ! ast = Condition( condition_node ) ! return ast def buildBreakStatement( self, statement ): Index: dumpast.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/dumpast.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dumpast.py 8 Aug 2004 14:50:29 -0000 1.3 --- dumpast.py 8 Aug 2004 15:55:03 -0000 1.4 *************** *** 11,14 **** --- 11,15 ---- def __init__( self, name_or_ast ): self._attributes = {} + self._order = [] self._children = [] if type(name_or_ast) == str: *************** *** 21,28 **** def attr( self, name, value = None ): return self._attributes.setdefault( name, value ) def attributes( self ): ! return self._attributes.items() class ASTInfoBuilder: --- 22,31 ---- def attr( self, name, value = None ): + if not self._attributes.has_key( name ): + self._order.append( name ) return self._attributes.setdefault( name, value ) def attributes( self ): ! return [ (name,self._attributes[name]) for name in self._order ] class ASTInfoBuilder: *************** *** 112,115 **** --- 115,133 ---- def visitForStatement( self, ast ): info = ASTInfo( ast ) + if ast.init: + info.attr( 'init', self.visitASTNode( ast.init ) ) + if ast.condition: + info.attr( 'condition', self.visitASTNode( ast.condition ) ) + if ast.loop_expression: + info.attr( 'loop_expression', self.visitASTNode( ast.loop_expression ) ) + if ast.loop_statement: + info.attr( 'loop_statement', self.visitASTNode( ast.loop_statement ) ) + return info + + def visitForInitDeclaration( self, ast ): + return self.visitASTNode( ast.init_declaration ) + + def visitCondition( self, ast ): + info = ASTInfo( ast ) return info *************** *** 135,149 **** info.attr( 'declaration', self.visitASTNode( ast.declaration ) ) return info ! def printASTInfo( info, indent = 0 ): margin = '| ' * indent indent += 1 ! print margin + info.name() + '[' attribute_margin = margin + '|-' for name, value in info.attributes(): if isinstance(value, ASTInfo): ! printASTInfo( value, indent ) elif type(value) == type([]): printASTInfoChildren( name, value, attribute_margin, indent-1 ) --- 153,187 ---- info.attr( 'declaration', self.visitASTNode( ast.declaration ) ) return info + + def visitSwitchStatement( self, ast ): + info = ASTInfo( ast ) + info.attr( 'condition', self.visitASTNode( ast.condition ) ) + info.attr( 'statement', self.visitASTNode( ast.statement ) ) + return info + + def visitCaseStatement( self, ast ): + info = ASTInfo( ast ) + # info.attr( 'value', self.visitASTNode( ast.value ) ) + info.attr( 'statement', self.visitASTNode( ast.statement ) ) + return info + + def visitBreakStatement( self, ast ): + return ASTInfo( ast ) + + def visitDefaultStatement( self, ast ): + return ASTInfo( ast ) ! def printASTInfo( info, indent = 0, attribute_name = '' ): margin = '| ' * indent indent += 1 ! if attribute_name: ! attribute_name += ': ' ! print margin + attribute_name + info.name() + '[' attribute_margin = margin + '|-' for name, value in info.attributes(): if isinstance(value, ASTInfo): ! printASTInfo( value, indent, name ) elif type(value) == type([]): printASTInfoChildren( name, value, attribute_margin, indent-1 ) |
From: Baptiste L. <bl...@us...> - 2004-08-08 15:55:11
|
Update of /cvsroot/cpptool/CppParser/src/cppparser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6127/src/cppparser Modified Files: cpp_grammar.txt Log Message: * enhanced wrapping of for, switch, case and default statements Index: cpp_grammar.txt =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/cppparser/cpp_grammar.txt,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** cpp_grammar.txt 7 Aug 2004 22:57:39 -0000 1.2 --- cpp_grammar.txt 8 Aug 2004 15:55:03 -0000 1.3 *************** *** 303,308 **** ; ! for_init_statement = expression_statement ! | simple_declaration ; --- 303,309 ---- ; ! for_init_statement = :node( 'for_init_statement', ! expression_statement ! | simple_declaration ) ; *************** *** 313,318 **** | :node('for_statement', 'for' '(' for_init_statement ! :node('for_condition', ?( condition ) ) ! ';' ?( expression ) ')' statement ) ; --- 314,320 ---- | :node('for_statement', 'for' '(' for_init_statement ! ?( :node('for_condition', condition ) ) ! ';' ?( expression ) ')' ! :node('for_loop_statement', statement) ) ; *************** *** 320,324 **** 'if' '(' condition ')' statement ?( 'else' statement ) ) | :node( 'switch_statement', ! 'switch' '(' condition ')' statement ) ; --- 322,327 ---- 'if' '(' condition ')' statement ?( 'else' statement ) ) | :node( 'switch_statement', ! 'switch' '(' :node('condition', condition) ')' ! :node('condition_statement', statement) ) ; *************** *** 331,335 **** labeled_statement = :node('label_statement', id ':' statement) ! | :node('case_statement', 'case' constant_expression ':' statement ) | :node('default_statement', 'default' ':' statement ); --- 334,339 ---- labeled_statement = :node('label_statement', id ':' statement) ! | :node('case_statement', 'case' constant_expression ':' ! :node('target_statement', statement ) ) | :node('default_statement', 'default' ':' statement ); *************** *** 735,740 **** throw_expression = 'throw' ?( assignment_expression ); ! exception_declaration = [ type_specifier ?( declarator | abstract_declarator ) ] ! | '...'; handler = :node('exception_handler', --- 739,745 ---- throw_expression = 'throw' ?( assignment_expression ); ! exception_declaration = :node( 'exception_declaration', ! [ type_specifier ?( declarator | abstract_declarator ) ] ) ! | :node( 'ellipsis_exception_handler', '...' ); handler = :node('exception_handler', |
From: Baptiste L. <bl...@us...> - 2004-08-08 14:50:53
|
Update of /cvsroot/cpptool/CppParser/src/pyrfta In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30262/src/pyrfta Modified Files: ast.py dumpast.py nodetools.py Log Message: * enhanced simple declaration wrapping, now outputting declarator id Index: nodetools.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/nodetools.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** nodetools.py 8 Aug 2004 11:52:40 -0000 1.2 --- nodetools.py 8 Aug 2004 14:50:29 -0000 1.3 *************** *** 11,20 **** return node.childAt(0) ! def getFirstChildNamed( node, name, exception_if_not_found = True ): for child in node.enumChildren(): if child.name == name: return child - if exception_if_not_found: - raise LogicError( "Fail to find children named '%s' in node %s" % (name,node) ) return None --- 11,24 ---- return node.childAt(0) ! def getFirstChildNamed( node, name ): ! for child in node.enumChildren(): ! if child.name == name: ! return child ! raise LogicError( "Fail to find children named '%s' in node %s" % (name,node) ) ! ! def tryGetFirstChildNamed( node, name ): for child in node.enumChildren(): if child.name == name: return child return None *************** *** 37,38 **** --- 41,48 ---- raise LogicError( "Fail to find string child in node %s" % node) return None + + def getFirstTokenChildNode( node ): + for child in node.enumChildren(): + if child.hasValidToken(): + return child + raise LogicError( "Fail to find a child node with token in %s." % node ) \ No newline at end of file Index: ast.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/ast.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ast.py 8 Aug 2004 11:52:40 -0000 1.3 --- ast.py 8 Aug 2004 14:50:29 -0000 1.4 *************** *** 23,26 **** --- 23,29 ---- self.node = node + class ErrorDeclaration(Declaration): + pass + class NamespaceAliasDef(Declaration): def __init__( self, namespace_node ): *************** *** 68,75 **** self.declarator_node = nodetools.getFirstChildNamed( init_declarator_node, 'declarator' ) self.initializer = None ! assign_initializer_node = nodetools.getFirstChildNamed( init_declarator_node, 'assign_initializer', False ) if assign_initializer_node: self.initializer = AssignInitializer( assign_initializer_node ) ! expression_list_node = nodetools.getFirstChildNamed( init_declarator_node, 'expression_list', False ) if expression_list_node: self.initializer = ConstructorInitializer( expression_list_node ) --- 71,78 ---- self.declarator_node = nodetools.getFirstChildNamed( init_declarator_node, 'declarator' ) self.initializer = None ! assign_initializer_node = nodetools.tryGetFirstChildNamed( init_declarator_node, 'assign_initializer' ) if assign_initializer_node: self.initializer = AssignInitializer( assign_initializer_node ) ! expression_list_node = nodetools.tryGetFirstChildNamed( init_declarator_node, 'expression_list' ) if expression_list_node: self.initializer = ConstructorInitializer( expression_list_node ) *************** *** 94,104 **** class StandardDeclaration(SimpleDeclaration): def setDeclarationSpecifierNode( self, declaration_specifier_node ): ! self.storage_class_node = nodetools.getFirstChildNamed( declaration_specifier_node, 'storage_class_specifier', False ) ! self.function_spec_node = nodetools.getFirstChildNamed( declaration_specifier_node, 'function_specifier', False ) # self.type_specifier_node = nodetools.getFirstChildNamed( declaration_specifier_node, 'type_specifier' ) class FriendDeclaration(StandardDeclaration): pass # same as StandardDeclaration class TypeSpecifier(ASTElement): def __init__( self, type_specifier_node, type ): --- 97,127 ---- class StandardDeclaration(SimpleDeclaration): def setDeclarationSpecifierNode( self, declaration_specifier_node ): ! self.storage_class_node = nodetools.tryGetFirstChildNamed( declaration_specifier_node, 'storage_class_specifier' ) ! self.function_spec_node = nodetools.tryGetFirstChildNamed( declaration_specifier_node, 'function_specifier' ) # self.type_specifier_node = nodetools.getFirstChildNamed( declaration_specifier_node, 'type_specifier' ) + self.declarators = [] + + def addDeclarator( self, declarator ): + self.declarators.append( declarator ) class FriendDeclaration(StandardDeclaration): pass # same as StandardDeclaration + class Declarator(ASTElement): + def __init__( self, node ): + self.node = node + self.pointer_operators = [] + self.declarator_id = None + + def addPointerOperator( self, pointer_operator ): + self.pointer_operators.append( pointer_operator ) + + def setDeclaratorId( self, id ): + self.declarator_id = id + + class DeclaratorId(ASTElement): + def __init__( self, node ): + self.node = node + class TypeSpecifier(ASTElement): def __init__( self, type_specifier_node, type ): *************** *** 212,215 **** --- 235,242 ---- Type.__init__( self, node ) + class DefaultFunctionReturnType(Type): # int + def __init__( self, node ): + Type.__init__( self, node ) + ## ################################################################## ## ################################################################## *************** *** 280,284 **** class TryBlockStatement(Statement): ! pass class ASTBuilder: --- 307,323 ---- class TryBlockStatement(Statement): ! def __init__( self, node, body ): ! Statement.__init__( self, node ) ! self.body = body ! self.handlers = [] ! ! def addHandler( self, handler ): ! self.handlers.append( handler ) ! ! class ExceptionHandler(ASTElement): # catch ! def __init__( self, node, body ): ! self.node = node ! self.body = body ! # catch exception is missing, need more structure in input class ASTBuilder: *************** *** 293,297 **** 'namespace_alias_def' : self.buildNamespaceAliasDef, 'using_declaration' : self.buildUsingDeclaration, ! 'using_directive' : self.buildUsingDirective } self.type_builders = { --- 332,337 ---- 'namespace_alias_def' : self.buildNamespaceAliasDef, 'using_declaration' : self.buildUsingDeclaration, ! 'using_directive' : self.buildUsingDirective, ! 'declaration_error' : self.buildErrorDeclaration } self.type_builders = { *************** *** 344,347 **** --- 384,391 ---- ast.addDeclaration( self.declaration_builders[ declaration.name ]( declaration ) ) return ast + + def buildErrorDeclaration( self, declaration ): + ast = ErrorDeclaration( declaration ) + return ast def buildNamedNamespaceDef( self, declaration ): *************** *** 366,370 **** def buildLinkageSpecification( self, declaration ): ! declarations = nodetools.getFirstChildNamed( declaration, 'declarations', False ) if declarations is None: ast = LinkageSpecification( declaration ) # how to I build the child declaration ??? --- 410,414 ---- def buildLinkageSpecification( self, declaration ): ! declarations = nodetools.tryGetFirstChildNamed( declaration, 'declarations' ) if declarations is None: ast = LinkageSpecification( declaration ) # how to I build the child declaration ??? *************** *** 400,405 **** --- 444,469 ---- type_specifier_node = nodetools.getFirstChildNamed( declaration_specifier, 'type_specifier' ) ast.type_specifier = self.buildTypeSpecifier( type_specifier_node ) + + init_declarators = nodetools.tryGetFirstChildNamed( declaration, 'init_declarators' ) + if init_declarators: + for init_declarator in nodetools.getChildrenNamed( init_declarators, 'init_declarator' ): + declarator_node = nodetools.getFirstChildNamed( init_declarator, 'declarator' ) + declarator = Declarator( declarator_node ) + self.buildDeclarator( declarator, declarator_node ) + ast.addDeclarator( declarator ) return ast + def buildDeclarator( self, declarator, declarator_node ): + ptr_operator_declarator_node = nodetools.tryGetFirstChildNamed( declarator_node, 'ptr_operator_declarator' ) + if ptr_operator_declarator_node: + declarator.addPointerOperator( PointerOperator( ptr_operator_declarator_node ) ) + + braced_declarator_node = nodetools.tryGetFirstChildNamed( declarator_node, 'braced_declarator' ) + if braced_declarator_node: + self.buildDeclarator( declarator, braced_declarator_node ) + else: + declarator_id_node = nodetools.getFirstChildNamed( declarator_node, 'declarator_id' ) + declarator.setDeclaratorId( DeclaratorId( declarator_id_node ) ) + def buildTypeSpecifier( self, type_specifier ): index = 0 *************** *** 430,434 **** def buildClassBases( self, ast, type_node ): ! class_bases_node = nodetools.getFirstChildNamed( type_node, 'class_bases', False ) if class_bases_node: for child in nodetools.getChildrenNamed( class_bases_node, 'base_specifier' ): --- 494,498 ---- def buildClassBases( self, ast, type_node ): ! class_bases_node = nodetools.tryGetFirstChildNamed( type_node, 'class_bases' ) if class_bases_node: for child in nodetools.getChildrenNamed( class_bases_node, 'base_specifier' ): *************** *** 436,440 **** def buildClassMembers( self, ast, type_node ): ! members_node = nodetools.getFirstChildNamed( type_node, 'member_specification', False ) if members_node: for child in members_node.enumChildren(): --- 500,504 ---- def buildClassMembers( self, ast, type_node ): ! members_node = nodetools.tryGetFirstChildNamed( type_node, 'member_specification' ) if members_node: for child in members_node.enumChildren(): *************** *** 470,476 **** def buildFunctionDefinition( self, declaration ): ast = FunctionDefinition( declaration ) ! function_return_type_node = nodetools.getFirstChildNamed( declaration, 'function_return_type' ) if function_return_type_node: ast.setReturnType( FunctionReturnType(function_return_type_node) ) ## 'declarator_id' --- 534,542 ---- def buildFunctionDefinition( self, declaration ): ast = FunctionDefinition( declaration ) ! function_return_type_node = nodetools.tryGetFirstChildNamed( declaration, 'function_return_type' ) if function_return_type_node: ast.setReturnType( FunctionReturnType(function_return_type_node) ) + else: + ast.setReturnType( DefaultFunctionReturnType( declaration ) ) ## 'declarator_id' *************** *** 551,555 **** def buildTryBlockStatement( self, statement ): ! return TryBlockStatement( statement ) --- 617,627 ---- def buildTryBlockStatement( self, statement ): ! body = self.buildCompoundStatement( nodetools.getFirstChildNamed(statement, 'compound_statement') ) ! ast = TryBlockStatement( statement, body ) ! for child in nodetools.getChildrenNamed( statement, 'exception_handler' ): ! body_node = nodetools.getFirstChildNamed( child, 'compound_statement' ) ! handler = ExceptionHandler( child, self.buildCompoundStatement( body_node ) ) ! ast.addHandler( handler ) ! return ast Index: dumpast.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/dumpast.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dumpast.py 8 Aug 2004 11:52:40 -0000 1.2 --- dumpast.py 8 Aug 2004 14:50:29 -0000 1.3 *************** *** 2,5 **** --- 2,6 ---- import pycppparser as cprs import ast + import nodetools def _getClassName( obj ): *************** *** 8,29 **** class ASTInfo: ! def __init__( self, name_or_ast = None ): ! self.__attributes = {} ! self.__children = [] if type(name_or_ast) == str: ! self.__name = name_or_ast else: ! self.__name = _getClassName( ast ) def name( self ): ! return self.__name def attr( self, name, value = None ): ! return self.__attributes.setdefault( name, value ) def attributes( self ): ! return self.__attributes.items() class ASTInfoBuilder: def visitASTNode( self, ast ): visit_method = 'visit' + _getClassName(ast) --- 9,33 ---- class ASTInfo: ! def __init__( self, name_or_ast ): ! self._attributes = {} ! self._children = [] if type(name_or_ast) == str: ! self._name = name_or_ast else: ! self._name = _getClassName( name_or_ast ) def name( self ): ! return self._name def attr( self, name, value = None ): ! return self._attributes.setdefault( name, value ) def attributes( self ): ! return self._attributes.items() class ASTInfoBuilder: + def __init__( self, source ): + self.source = source + def visitASTNode( self, ast ): visit_method = 'visit' + _getClassName(ast) *************** *** 44,49 **** --- 48,139 ---- name = (ast.body and 'FunctionDefinition') or 'FunctionPrototype' info = ASTInfo( name ) + info.attr( 'return_type', self.visitASTNode( ast.return_type ) ) + if ast.body: + info.attr( 'body', self.visitASTNode( ast.body ) ) + return info + + def visitFunctionReturnType( self, ast ): + info = ASTInfo( ast ) + return info + + def visitDefaultFunctionReturnType( self, ast ): + info = ASTInfo( ast ) + return info + + def visitErrorDeclaration( self, ast ): + info = ASTInfo( ast ) + location = nodetools.getFirstTokenChildNode( ast.node ).location + info.attr( 'location', 'Line: %d, column: %d' % self._location(location) ) + text = '' + for node in ast.node.enumChildren(): + text += node.text + info.attr( 'text', text ) + return info + + def _location( self, location ): + previousEOL = self.source.rfind( '\n', 0, location.startPos ) + 1 + line = self.source.count( '\n', 0, previousEOL ) + column = location.startPos - previousEOL + return (line+1,column+1) + + def _nodeTreeSource( self, node ): + source = '' + if node.hasValidToken(): + source += node.text + for child in node.enumChildren(): + source += self._nodeTreeSource( child ) + return source + + def visitStandardDeclaration( self, ast ): + info = ASTInfo( ast ) + info.attr( 'declarators', [] ) + for declarator in ast.declarators: + info.attr( 'declarators' ).append( self.visitASTNode( declarator ) ) + return info + + def visitDeclarator( self, ast ): + info = ASTInfo( ast ) + # + ptr operators + info.attr( 'declator_id', self._nodeTreeSource( ast.declarator_id.node ) ) + return info + + ## Statements + def visitCompoundStatement( self, ast ): + info = ASTInfo( ast ) + info.attr( 'statements', [] ) + for statement in ast.statements: + info.attr( 'statements' ).append( self.visitASTNode( statement ) ) return info + def visitExpressionStatement( self, ast ): + info = ASTInfo( ast ) + return info + + def visitForStatement( self, ast ): + info = ASTInfo( ast ) + return info + + def visitIfStatement( self, ast ): + info = ASTInfo( ast ) + return info + + def visitTryBlockStatement( self, ast ): + info = ASTInfo( ast ) + info.attr( 'body', self.visitASTNode( ast.body ) ) + info.attr( 'handlers', [] ) + for handler in ast.handlers: + info.attr( 'handlers' ).append( self.visitASTNode( handler ) ) + return info + + def visitExceptionHandler( self, ast ): + info = ASTInfo( ast ) + info.attr( 'body', self.visitASTNode( ast.body ) ) + return info + + def visitDeclarationStatement( self, ast ): + info = ASTInfo( ast ) + info.attr( 'declaration', self.visitASTNode( ast.declaration ) ) + return info + *************** *** 54,58 **** attribute_margin = margin + '|-' for name, value in info.attributes(): ! if type(value) == ASTInfo: printASTInfo( value, indent ) elif type(value) == type([]): --- 144,148 ---- attribute_margin = margin + '|-' for name, value in info.attributes(): ! if isinstance(value, ASTInfo): printASTInfo( value, indent ) elif type(value) == type([]): *************** *** 81,84 **** ast = ast.ASTBuilder().buildTranslationUnit( translation_unit_node ) ! info = ASTInfoBuilder().visitTranslationUnit( ast ) printASTInfo( info ) \ No newline at end of file --- 171,174 ---- ast = ast.ASTBuilder().buildTranslationUnit( translation_unit_node ) ! info = ASTInfoBuilder( source ).visitTranslationUnit( ast ) printASTInfo( info ) \ No newline at end of file |
From: Baptiste L. <bl...@us...> - 2004-08-08 11:52:58
|
Update of /cvsroot/cpptool/CppParser/src/pyrfta In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8063/src/pyrfta Modified Files: ast.py dumpast.py nodetools.py Added Files: dumpnodetree.py Log Message: * renamed dumpast to dumpnodetree * added dumpast to dump the node tree ast wrapper Index: nodetools.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/nodetools.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** nodetools.py 7 Aug 2004 22:56:20 -0000 1.1 --- nodetools.py 8 Aug 2004 11:52:40 -0000 1.2 *************** *** 6,9 **** --- 6,14 ---- return node.childAt(0) + def tryGetFirstChild( node ): + if node.childCount == 0: + return None + return node.childAt(0) + def getFirstChildNamed( node, name, exception_if_not_found = True ): for child in node.enumChildren(): Index: ast.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/ast.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ast.py 8 Aug 2004 08:57:57 -0000 1.2 --- ast.py 8 Aug 2004 11:52:40 -0000 1.3 *************** *** 1,8 **** import nodetools ! class ASTNode: pass ! class Statement(ASTNode): pass --- 1,8 ---- import nodetools ! class ASTElement: pass ! class Statement(ASTElement): pass *************** *** 17,23 **** class TranslationUnit(Declarations): def __init__( self, translation_unit_node ): ! Declarations.__init__( translation_unit_node ) ! class Declaration(ASTNode): def __init__( self, node ): self.node = node --- 17,23 ---- class TranslationUnit(Declarations): def __init__( self, translation_unit_node ): ! Declarations.__init__( self, translation_unit_node ) ! class Declaration(ASTElement): def __init__( self, node ): self.node = node *************** *** 92,98 **** self.type_specifier_node = nodetools.getFirstChildNamed( declaration_specifier_node, 'type_specifier' ) - class FriendDeclaration(StandardDeclaration): - pass # same as StandardDeclaration - class StandardDeclaration(SimpleDeclaration): def setDeclarationSpecifierNode( self, declaration_specifier_node ): --- 92,95 ---- *************** *** 101,107 **** # self.type_specifier_node = nodetools.getFirstChildNamed( declaration_specifier_node, 'type_specifier' ) class TypeSpecifier(ASTElement): def __init__( self, type_specifier_node, type ): ! self.cv_qualifiers_nodes = nodetools.getChildrenNamed( 'cv_qualifiers' ) # const/volatile self.type = type --- 98,108 ---- # self.type_specifier_node = nodetools.getFirstChildNamed( declaration_specifier_node, 'type_specifier' ) + class FriendDeclaration(StandardDeclaration): + pass # same as StandardDeclaration + class TypeSpecifier(ASTElement): def __init__( self, type_specifier_node, type ): ! self.node = type_specifier_node ! self.cv_qualifiers_nodes = nodetools.getChildrenNamed( type_specifier_node, 'cv_qualifiers' ) # const/volatile self.type = type *************** *** 196,203 **** class FunctionDefinition(Declaration): ! pass class ASTBuilder: def __init__( self ): --- 197,285 ---- class FunctionDefinition(Declaration): ! def __init__( self, function_def_node ): ! Declaration.__init__( self, function_def_node ) ! self.return_type = None ! self.body = None + def setReturnType( self, return_type ): + self.return_type = return_type + def setBody( self, body ): + self.body = body + class FunctionReturnType(Type): + def __init__( self, node ): + Type.__init__( self, node ) + + ## ################################################################## + ## ################################################################## + ## AST Statements + ## ################################################################## + ## ################################################################## + + class Statement(ASTElement): + def __init__( self, statement_node ): + self.node = statement_node + + class CompoundStatement(Statement): + def __init__( self, compound_node ): + Statement.__init__( self, compound_node ) + self.statements = [] + + def addStatement( self, statement ): + self.statements.append( statement ) + + class ErrorStatement(Statement): + pass + class LabelStatement(Statement): + pass + + class CaseStatement(Statement): + pass + + class DefaultStatement(Statement): + pass + + class IfStatement(Statement): + pass + + class SwitchStatement(Statement): + pass + + class WhileStatement(Statement): + pass + + class DoWhileStatement(Statement): + pass + + class ForStatement(Statement): + pass + + class BreakStatement(Statement): + pass + + class ContinueStatement(Statement): + pass + + class ReturnStatement(Statement): + pass + + class GotoStatement(Statement): + pass + + class ExpressionStatement(Statement): + pass + + class DeclarationStatement(Statement): + def __init__( self, node ): + Statement.__init__( self, node ) + self.declaration = None + + def setDeclaration( self, declaration ): + self.declaration = declaration + + class TryBlockStatement(Statement): + pass + class ASTBuilder: def __init__( self ): *************** *** 231,244 **** 'member_error' : self.buildMemberErrorDeclaration } def buildTranslationUnit( self, root ): assert root.name == 'translation_unit' ast = TranslationUnit( root ) ! return self.buildDeclarations( ast, root ) def buildDeclarations( self, ast, declarations_parent ): ! declarations = nodetools.getFirstChildNamed( root, 'declarations' ) for declaration in declarations.enumChildren(): ! ast.addDeclaration( self.declaration_builders[ declaration.name ]() ) return ast --- 313,346 ---- 'member_error' : self.buildMemberErrorDeclaration } + self.statement_builders = { + 'compound_statement' : self.buildCompoundStatement, + 'error_statement' : self.buildErrorStatement, + 'label_statement' : self.buildLabelStatement, + 'case_statement' : self.buildCaseStatement, + 'default_statement' : self.buildDefaultStatement, + 'if_statement' : self.buildIfStatement, + 'switch_statement' : self.buildSwitchStatement, + 'while_statement' : self.buildWhileStatement, + 'dowhile_statement' : self.buildDoWhileStatement, + 'for_statement' : self.buildForStatement, + 'break_statement' : self.buildBreakStatement, + 'continue_statement' : self.buildContinueStatement, + 'return_statement' : self.buildReturnStatement, + 'goto_statement' : self.buildGotoStatement, + 'expression_statement' : self.buildExpressionStatement, + 'declaration_statement' : self.buildDeclarationStatement, + 'try_block' : self.buildTryBlockStatement + } def buildTranslationUnit( self, root ): assert root.name == 'translation_unit' ast = TranslationUnit( root ) ! self.buildDeclarations( ast, root ) ! return ast def buildDeclarations( self, ast, declarations_parent ): ! declarations = nodetools.getFirstChildNamed( declarations_parent, 'declarations' ) for declaration in declarations.enumChildren(): ! ast.addDeclaration( self.declaration_builders[ declaration.name ]( declaration ) ) return ast *************** *** 273,277 **** def buildSimpleDeclaration( self, declaration ): ! declaration_specifier = nodetools.getFirstChild( declaration, False ) if declaration_specifier: if declaration_specifier.name == 'typedef_specifier': --- 375,379 ---- def buildSimpleDeclaration( self, declaration ): ! declaration_specifier = nodetools.tryGetFirstChild( declaration ) if declaration_specifier: if declaration_specifier.name == 'typedef_specifier': *************** *** 286,298 **** def buildTypedefSimpleDeclaration( self, declaration, typedef_specifier ): ! ast = TypedefDeclaration( self, declaration ) return ast def buildFriendSimpleDeclaration( self, declaration, friend_specifier ): ! ast = FriendDeclaration( self, declaration ) return ast def buildStandardSimpleDeclaration( self, declaration, declaration_specifier ): ! ast = StandardDeclaration( self, declaration ) ast.setDeclarationSpecifierNode( declaration_specifier ) type_specifier_node = nodetools.getFirstChildNamed( declaration_specifier, 'type_specifier' ) --- 388,400 ---- def buildTypedefSimpleDeclaration( self, declaration, typedef_specifier ): ! ast = TypedefDeclaration( declaration ) return ast def buildFriendSimpleDeclaration( self, declaration, friend_specifier ): ! ast = FriendDeclaration( declaration ) return ast def buildStandardSimpleDeclaration( self, declaration, declaration_specifier ): ! ast = StandardDeclaration( declaration ) ast.setDeclarationSpecifierNode( declaration_specifier ) type_specifier_node = nodetools.getFirstChildNamed( declaration_specifier, 'type_specifier' ) *************** *** 355,359 **** def buildMemberErrorDeclaration( self, declaration ): ! return MemberErrorDeclaration( declaration ): def buildForwardClassType( self, type_node ): --- 457,461 ---- def buildMemberErrorDeclaration( self, declaration ): ! return MemberErrorDeclaration( declaration ) def buildForwardClassType( self, type_node ): *************** *** 367,370 **** --- 469,485 ---- def buildFunctionDefinition( self, declaration ): + ast = FunctionDefinition( declaration ) + function_return_type_node = nodetools.getFirstChildNamed( declaration, 'function_return_type' ) + if function_return_type_node: + ast.setReturnType( FunctionReturnType(function_return_type_node) ) + + ## 'declarator_id' + ## 'braced_declarator' + + body_node = nodetools.getFirstChildNamed( declaration, 'compound_statement' ) + if body_node: + ast.setBody( self.buildCompoundStatement( body_node ) ) + + # ? function_return_type # declarator_id *************** *** 372,375 **** # ? cv_qualifiers # ? exception_specification ! pass ! \ No newline at end of file --- 487,555 ---- # ? cv_qualifiers # ? exception_specification ! return ast ! ! ##################################### ! ## Statements ! ##################################### ! ! def buildErrorStatement( self, statement ): ! return ErrorStatement( statement ) ! ! def buildCompoundStatement( self, statement ): ! ast = CompoundStatement( statement ) ! for child in statement.enumChildren(): ! if not child.hasValidToken(): ! statement = self.statement_builders[ child.name ]( child ) ! ast.addStatement( statement ) ! return ast ! ! def buildLabelStatement( self, statement ): ! return LabelStatement( statement ) ! ! def buildCaseStatement( self, statement ): ! return CaseStatement( statement ) ! ! def buildDefaultStatement( self, statement ): ! return DefaultStatement( statement ) ! ! def buildIfStatement( self, statement ): ! return IfStatement( statement ) ! ! def buildSwitchStatement( self, statement ): ! return SwitchStatement( statement ) ! ! def buildWhileStatement( self, statement ): ! return WhileStatement( statement ) ! ! def buildDoWhileStatement( self, statement ): ! return DoWhileStatement( statement ) ! ! def buildForStatement( self, statement ): ! return ForStatement( statement ) ! ! def buildBreakStatement( self, statement ): ! return BreakStatement( statement ) ! ! def buildContinueStatement( self, statement ): ! return ContinueStatement( statement ) ! ! def buildReturnStatement( self, statement ): ! return ReturnStatement( statement ) ! ! def buildGotoStatement( self, statement ): ! return GotoStatement( statement ) ! ! def buildExpressionStatement( self, statement ): ! return ExpressionStatement( statement ) ! ! def buildDeclarationStatement( self, statement ): ! ast = DeclarationStatement( statement ) ! declaration_node = nodetools.getFirstChild( statement ) ! declaration = self.declaration_builders[ declaration_node.name ]( declaration_node ) ! ast.setDeclaration( declaration ) ! return ast ! ! def buildTryBlockStatement( self, statement ): ! return TryBlockStatement( statement ) ! ! --- NEW FILE: dumpnodetree.py --- import sys import pycppparser as cprs source = file( sys.argv[1], "rt" ).read() grammar_path = 'cpp_grammar.txt' parser = cprs.makeParser( grammar_path ) translation_unit = parser.parse( source ) print translation_unit.treeStr() Index: dumpast.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/dumpast.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dumpast.py 7 Aug 2004 22:55:07 -0000 1.1 --- dumpast.py 8 Aug 2004 11:52:40 -0000 1.2 *************** *** 1,4 **** --- 1,74 ---- import sys import pycppparser as cprs + import ast + + def _getClassName( obj ): + class_name = str(obj.__class__).split('.')[-1] + return class_name + + class ASTInfo: + def __init__( self, name_or_ast = None ): + self.__attributes = {} + self.__children = [] + if type(name_or_ast) == str: + self.__name = name_or_ast + else: + self.__name = _getClassName( ast ) + + def name( self ): + return self.__name + + def attr( self, name, value = None ): + return self.__attributes.setdefault( name, value ) + + def attributes( self ): + return self.__attributes.items() + + class ASTInfoBuilder: + def visitASTNode( self, ast ): + visit_method = 'visit' + _getClassName(ast) + print 'visiting ', visit_method + return getattr( self, visit_method )( ast ) + + def visitTranslationUnit( self, ast ): + info = ASTInfo( ast ) + return self.handleDeclarations( info, ast ) + + def handleDeclarations( self, info, ast ): + info.attr( 'declarations', [] ) + for declaration in ast.declarations: + info.attr('declarations').append( self.visitASTNode( declaration ) ) + return info + + def visitFunctionDefinition( self, ast ): + name = (ast.body and 'FunctionDefinition') or 'FunctionPrototype' + info = ASTInfo( name ) + return info + + + + def printASTInfo( info, indent = 0 ): + margin = '| ' * indent + indent += 1 + print margin + info.name() + '[' + attribute_margin = margin + '|-' + for name, value in info.attributes(): + if type(value) == ASTInfo: + printASTInfo( value, indent ) + elif type(value) == type([]): + printASTInfoChildren( name, value, attribute_margin, indent-1 ) + else: + print attribute_margin + name + ': ' + str(value) + print margin + ']' + + def printASTInfoChildren( name, children, attribute_margin, indent ): + margin = '| ' * indent + indent += 2 + print margin + '|-' + name + ': ' + '[' + for child in children: + printASTInfo( child, indent ) + print margin + '| ]' + + source = file( sys.argv[1], "rt" ).read() *************** *** 6,9 **** grammar_path = 'cpp_grammar.txt' parser = cprs.makeParser( grammar_path ) ! translation_unit = parser.parse( source ) ! print translation_unit.treeStr() --- 76,84 ---- grammar_path = 'cpp_grammar.txt' parser = cprs.makeParser( grammar_path ) ! print 'Parsing', sys.argv[1] ! translation_unit_node = parser.parse( source ) ! print 'Building ast..' ! ! ast = ast.ASTBuilder().buildTranslationUnit( translation_unit_node ) ! info = ASTInfoBuilder().visitTranslationUnit( ast ) ! printASTInfo( info ) \ No newline at end of file |
From: Baptiste L. <bl...@us...> - 2004-08-08 08:58:06
|
Update of /cvsroot/cpptool/CppParser/src/pyrfta In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12264/src/pyrfta Modified Files: ast.py Log Message: * added wrapping for most member declarations Index: ast.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/ast.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ast.py 7 Aug 2004 22:56:20 -0000 1.1 --- ast.py 8 Aug 2004 08:57:57 -0000 1.2 *************** *** 106,110 **** self.type = type ! class Type(...): def __init__( self, node ): self.node = node --- 106,110 ---- self.type = type ! class Type(ASTElement): def __init__( self, node ): self.node = node *************** *** 134,137 **** --- 134,170 ---- self.node = enum_definition_node + class ClassType(Type): + def __init__( self, class_node ): + self.base_classes = [] + pass + + def addBaseClass( self, base_class_specifier ): + self.base_classes.append( base_class_specifier ) + + class ClassBaseSpecifier(ASTElement): + def __init__( self, base_specifier_node ): + self.node = base_specifier_node + # base_class_access + # base_class_name + + class MemberAccessSpecification(ASTElement): + def __init__( self, access_node ): # private, public, ... + self.node = access_node + + class MemberDeclaration(Declaration): + pass # rule member_declaration, node 'member_declaration' + + class ConstructorMemberDeclaration(Declaration): + pass + + class MemberErrorDeclaration(Declaration): + pass + + class ForwardClassType(Type): + pass + + class ForwardEnumType(Type): + pass + class LinkageSpecificationBase: def __init__( self ): *************** *** 165,173 **** pass - class AggregateDeclaration(Declaration): - pass - - class Type: - pass --- 198,201 ---- *************** *** 191,196 **** 'class_specifier' : self.buildClassType, 'forward_class_specifier' : self.buildForwardClassType, ! 'forward_enum_specifier' : self.buildForwardEnumType, ! 'forward_typename_specifier' : self.buildForwardTypenameType } --- 219,233 ---- 'class_specifier' : self.buildClassType, 'forward_class_specifier' : self.buildForwardClassType, ! 'forward_enum_specifier' : self.buildForwardEnumType ! # 'forward_typename_specifier' : self.buildForwardTypenameType ! } ! self.member_declaration_builders = { ! 'access_specification' : self.buildMemberAccessSpecification, ! 'member_function_definition' : self.buildMemberFunctionDefinition, ! 'member_declaration' : self.buildMemberDeclaration, ! 'typeless_function_declaration' : self.buildTypelessFunctionDeclaration, ! 'using_declaration' : self.buildUsingDeclaration, ! # 'template_declaration' : self.buildMemberTemplateDeclaration ! 'member_error' : self.buildMemberErrorDeclaration } *************** *** 279,283 **** def buildEnumType( self, type_node ): ! ast = EnumType( self, type_node ) for definition in nodetools.getFirstChildNamed( type_node, 'enumerator_definitions' ).enumChildren(): ast.addDefinition( EnumDefinition( definition ) ) --- 316,320 ---- def buildEnumType( self, type_node ): ! ast = EnumType( type_node ) for definition in nodetools.getFirstChildNamed( type_node, 'enumerator_definitions' ).enumChildren(): ast.addDefinition( EnumDefinition( definition ) ) *************** *** 285,298 **** def buildClassType( self, type_node ): ! pass def buildForwardClassType( self, type_node ): ! pass def buildForwardEnumType( self, type_node ): ! pass ! def buildForwardTypenameType( self, type_node ): ! pass def buildFunctionDefinition( self, declaration ): --- 322,368 ---- def buildClassType( self, type_node ): ! ast = ClassType( type_node ) ! self.buildClassBases( ast, type_node ) ! self.buildClassMembers( ast, type_node ) ! return ast ! ! def buildClassBases( self, ast, type_node ): ! class_bases_node = nodetools.getFirstChildNamed( type_node, 'class_bases', False ) ! if class_bases_node: ! for child in nodetools.getChildrenNamed( class_bases_node, 'base_specifier' ): ! ast.addBaseClasse( ClassBaseSpecifier( child ) ) ! ! def buildClassMembers( self, ast, type_node ): ! members_node = nodetools.getFirstChildNamed( type_node, 'member_specification', False ) ! if members_node: ! for child in members_node.enumChildren(): ! declaration = self.member_declaration_builders[ child.name ]( child ) ! ast.addMemberDeclaration( declaration ) ! ! def buildMemberAccessSpecification( self, declaration ): ! return MemberAccessSpecification( declaration ) ! ! def buildMemberFunctionDefinition( self, declaration ): ! return self.buildFunctionDefinition( self, declaration ) ! ! def buildMemberDeclaration( self, declaration ): ! ast = MemberDeclaration( self, declaration ) ! return ast ! ! def buildTypelessFunctionDeclaration( self, declaration ): ! ast = ConstructorMemberDeclaration( self, declaration ) ! return ast ! ! def buildMemberErrorDeclaration( self, declaration ): ! return MemberErrorDeclaration( declaration ): def buildForwardClassType( self, type_node ): ! return ForwardClassDeclaration( type_node ) def buildForwardEnumType( self, type_node ): ! return ForwardEnumDeclaration( type_node ) ! # def buildForwardTypenameType( self, type_node ): ! # return Forward def buildFunctionDefinition( self, declaration ): |
From: Baptiste L. <bl...@us...> - 2004-08-07 22:58:24
|
Update of /cvsroot/cpptool/CppParser/src/cppparser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7543/src/cppparser Modified Files: cppparser.vcproj Log Message: * added grammar files to project Index: cppparser.vcproj =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/cppparser/cppparser.vcproj,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** cppparser.vcproj 7 Aug 2004 15:52:23 -0000 1.1 --- cppparser.vcproj 7 Aug 2004 22:58:16 -0000 1.2 *************** *** 5,8 **** --- 5,9 ---- Name="cppparser" ProjectGUID="{EA6D6F9C-4BA7-4A0D-BD46-7ACA6F3D6E72}" + RootNamespace="cppparser" Keyword="Win32Proj"> <Platforms> *************** *** 291,294 **** --- 292,305 ---- </File> </Filter> + <Filter + Name="grammar" + Filter=""> + <File + RelativePath=".\cpp_grammar.txt"> + </File> + <File + RelativePath=".\grammar_tree.txt"> + </File> + </Filter> </Files> <Globals> |
From: Baptiste L. <bl...@us...> - 2004-08-07 22:57:49
|
Update of /cvsroot/cpptool/CppParser/src/cppparser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7395/src/cppparser Modified Files: cpp_grammar.txt Log Message: * made small optimization Index: cpp_grammar.txt =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/cppparser/cpp_grammar.txt,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** cpp_grammar.txt 7 Aug 2004 15:52:23 -0000 1.1 --- cpp_grammar.txt 7 Aug 2004 22:57:39 -0000 1.2 *************** *** 541,545 **** typedef_name = id; # p793 ! type_name = class_name | enum_name | typedef_name; # Notes: simplified, alternatives are redondant in typeless context --- 541,547 ---- typedef_name = id; # p793 ! # optimization: all three are identical during parsing ! #type_name = class_name | enum_name | typedef_name; ! type_name = class_name; # Notes: simplified, alternatives are redondant in typeless context |
From: Baptiste L. <bl...@us...> - 2004-08-07 22:56:30
|
Update of /cvsroot/cpptool/CppParser/src/pyrfta In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7098/src/pyrfta Added Files: ast.py nodetools.py Log Message: * started implementing a wrapper around the AST (typed node) --- NEW FILE: nodetools.py --- import pycppparser as cprs def getFirstChild( node ): if node.childCount == 0: raise LogicError( "Fail to get first chil in node %s" % node ) return node.childAt(0) def getFirstChildNamed( node, name, exception_if_not_found = True ): for child in node.enumChildren(): if child.name == name: return child if exception_if_not_found: raise LogicError( "Fail to find children named '%s' in node %s" % (name,node) ) return None def getChildrenNamed( node, name ): return [ child for child in node.enumChildren() if child.name == name ] def getFirstIdentifierChildNode( node, exception_if_not_found = True ): for child in node.enumChildren(): if child.category == cprs.TK_IDENTIFIER: return child if exception_if_not_found: raise LogicError( "Fail to find identifier child in node %s" % node ) return None def getFirstStringChildNode( node, exception_if_not_found = True ): for child in node.enumChildren(): if child.category == cprs.TK_STRING: return child if exception_if_not_found: raise LogicError( "Fail to find string child in node %s" % node) return None --- NEW FILE: ast.py --- import nodetools class ASTNode: pass class Statement(ASTNode): pass class Declarations: def __init__( self, node ): self.node = node self.declarations = [] def addDeclaration( self, declaration ): self.declarations.append( declaration ) class TranslationUnit(Declarations): def __init__( self, translation_unit_node ): Declarations.__init__( translation_unit_node ) class Declaration(ASTNode): def __init__( self, node ): self.node = node class NamespaceAliasDef(Declaration): def __init__( self, namespace_node ): Declaration.__init__( self, namespace_node ) self.id_node = nodetools.getFirstIdentifierChildNode( namespace_node ) self.alias_node = nodetools.getFirstChildNamed( namespace_node, 'namespace_specifier' ) def name( self ): return self.id_node.text def aliasNode( self ): # namespace... return self.alias_node class UsingDeclaration(Declaration): # very similar to NamespaceAliasDef def __init__( self, using_node ): Declaration.__init__( self, using_node ) self.using_id_node = nodetools.getFirstChildNamed( using_node, 'using_id' ) def usingIdNode( self ): # qualified id return self.using_id_node class UsingDirective(Declaration): def __init__( self, using_node ): Declaration.__init__( self, using_node ) self.namespace_id_node = nodetools.getFirstChildNamed( using_node, 'namespace_specifier' ) def usingIdNode( self ): # namespace... return self.namespace_id_node class Initializer(ASTElement): def __init( self, node ): self.node = node class AssignInitializer(Initializer): # ~ n assignment_expression or array/struct initializer pass class ConstructorInitializer(Initializer): # n assignment_expression pass class Declarator: def __init__( self, declaration, init_declarator_node ): self.declaration = declaration self.declarator_node = nodetools.getFirstChildNamed( init_declarator_node, 'declarator' ) self.initializer = None assign_initializer_node = nodetools.getFirstChildNamed( init_declarator_node, 'assign_initializer', False ) if assign_initializer_node: self.initializer = AssignInitializer( assign_initializer_node ) expression_list_node = nodetools.getFirstChildNamed( init_declarator_node, 'expression_list', False ) if expression_list_node: self.initializer = ConstructorInitializer( expression_list_node ) class SimpleDeclaration(Declaration): def __init__( self, declaration_node ): Declaration.__init__( self, declaration_node ) # type_specifiers # typedef + type specifier # or friend + standard # or standard # storage class specifier: mutable, static... # function specifier (inline, explicit, virtual) # type specifier # init_declarators pass class TypedefDeclaration(SimpleDeclaration): def setDeclarationSpecifierNode( self, declaration_specifier_node ): self.type_specifier_node = nodetools.getFirstChildNamed( declaration_specifier_node, 'type_specifier' ) class FriendDeclaration(StandardDeclaration): pass # same as StandardDeclaration class StandardDeclaration(SimpleDeclaration): def setDeclarationSpecifierNode( self, declaration_specifier_node ): self.storage_class_node = nodetools.getFirstChildNamed( declaration_specifier_node, 'storage_class_specifier', False ) self.function_spec_node = nodetools.getFirstChildNamed( declaration_specifier_node, 'function_specifier', False ) # self.type_specifier_node = nodetools.getFirstChildNamed( declaration_specifier_node, 'type_specifier' ) class TypeSpecifier(ASTElement): def __init__( self, type_specifier_node, type ): self.cv_qualifiers_nodes = nodetools.getChildrenNamed( 'cv_qualifiers' ) # const/volatile self.type = type class Type(...): def __init__( self, node ): self.node = node class FundamentalType(Type): pass class TypeNameType(Type): pass class EnumType(Type): def __init__( self, enum_node ): Type.__init__( enum_node ) self.id_node = nodetools.getFirstIdentifierChildNode( enum_node, False ) self.definitions = [] def name( self ): if self.id_node: return self.id_node.name return None def addDefinition( self, definition ): self.definitions.append( definition ) class EnumDefinition(ASTElement): def __init__( self, enum_definition_node ): self.node = enum_definition_node class LinkageSpecificationBase: def __init__( self ): self.linkage_type_node = nodetools.getFirstStringChildNode( self.node ) def linkageType( self ): return self.linkage_type_node.text class LinkageSpecification(Declaration,LinkageSpecificationBase): def __init__( self, linkage_spec_node ): Declaration.__init__( self ) LinkageSpecificationBase.__init__( self ) class LinkageSpecificationBlock(Declarations,LinkageSpecificationBase): def __init__( self, linkage_spec_node ): Declarations.__init__( self ) LinkageSpecificationBase.__init__( self ) class NamedNamespaceDef(Declarations): def __init__( self, namespace_node ): Declarations.__init__( namespace_node ) self.id_node = nodetools.getFirstIdentifierChildNode( namespace_node ) def name( self ): return self.id_node.text class AnonymousNamespaceDef(Declarations): pass # nothing else needed class FunctionDefinition(Declaration): pass class AggregateDeclaration(Declaration): pass class Type: pass class ASTBuilder: def __init__( self ): self.current = None self.declaration_builders = { 'simple_declaration' : self.buildSimpleDeclaration, 'named_namespace_def' : self.buildNamedNamespaceDef, 'unnamed_namespace_def' : self.buildAnonymousNamespaceDef, 'linkage_specification' : self.buildLinkageSpecification, 'function_definition' : self.buildFunctionDefinition, 'namespace_alias_def' : self.buildNamespaceAliasDef, 'using_declaration' : self.buildUsingDeclaration, 'using_directive' : self.buildUsingDirective } self.type_builders = { 'fundamental_type_specifier' : self.buildFundamentalType, 'type_name' : self.buildTypeNameType, 'enum_specifier': self.buildEnumType, 'class_specifier' : self.buildClassType, 'forward_class_specifier' : self.buildForwardClassType, 'forward_enum_specifier' : self.buildForwardEnumType, 'forward_typename_specifier' : self.buildForwardTypenameType } def buildTranslationUnit( self, root ): assert root.name == 'translation_unit' ast = TranslationUnit( root ) return self.buildDeclarations( ast, root ) def buildDeclarations( self, ast, declarations_parent ): declarations = nodetools.getFirstChildNamed( root, 'declarations' ) for declaration in declarations.enumChildren(): ast.addDeclaration( self.declaration_builders[ declaration.name ]() ) return ast def buildNamedNamespaceDef( self, declaration ): ast = NamedNamespaceDef( declaration ) return self.buildDeclarations( ast, declaration ) def buildAnonymousNamespaceDef( self, declaration ): ast = AnonymousNamespaceDef( declaration ) return self.buildDeclarations( ast, declaration ) def buildNamespaceAliasDef( self, declaration ): ast = NamespaceAliasDef( declaration ) return ast def buildUsingDeclaration( self, declaration ): ast = UsingDeclaration( declaration ) return ast def buildUsingDirective( self, declaration ): ast = UsingDeclaration( declaration ) return ast def buildLinkageSpecification( self, declaration ): declarations = nodetools.getFirstChildNamed( declaration, 'declarations', False ) if declarations is None: ast = LinkageSpecification( declaration ) # how to I build the child declaration ??? else: ast = LinkageSpecificationBlock( declaration ) self.buildDeclarations( ast, declaration ) return ast def buildSimpleDeclaration( self, declaration ): declaration_specifier = nodetools.getFirstChild( declaration, False ) if declaration_specifier: if declaration_specifier.name == 'typedef_specifier': return self.buildTypedefSimpleDeclaration( declaration, declaration_specifier ) elif declaration_specifier.name == 'friend_specifier': return self.buildFriendSimpleDeclaration( declaration, declaration_specifier ) elif declaration_specifier.name == 'declaration_specifier': return self.buildStandardSimpleDeclaration( declaration, declaration_specifier ) raise LogicError( "Don't know how to build simple declaration for: '%s'" % declaration_specifier.name ) else: return self.buildDeclaratorsSimpleDeclaration( declaration ) def buildTypedefSimpleDeclaration( self, declaration, typedef_specifier ): ast = TypedefDeclaration( self, declaration ) return ast def buildFriendSimpleDeclaration( self, declaration, friend_specifier ): ast = FriendDeclaration( self, declaration ) return ast def buildStandardSimpleDeclaration( self, declaration, declaration_specifier ): ast = StandardDeclaration( self, declaration ) ast.setDeclarationSpecifierNode( declaration_specifier ) type_specifier_node = nodetools.getFirstChildNamed( declaration_specifier, 'type_specifier' ) ast.type_specifier = self.buildTypeSpecifier( type_specifier_node ) return ast def buildTypeSpecifier( self, type_specifier ): index = 0 if type_specifier.childAt(0).name == 'cv_qualifiers': index = 1 type_node = type_specifier.childAt(index) type = self.type_builders[ type_node.name ]( type_node ) ast = TypeSpecifier( type_specifier, type ) return ast def buildFundamentalType( self, type_node ): return FundamentalType( type_node ) def buildTypeNameType( self, type_node ): return TypeNameType( type_node ) def buildEnumType( self, type_node ): ast = EnumType( self, type_node ) for definition in nodetools.getFirstChildNamed( type_node, 'enumerator_definitions' ).enumChildren(): ast.addDefinition( EnumDefinition( definition ) ) return ast def buildClassType( self, type_node ): pass def buildForwardClassType( self, type_node ): pass def buildForwardEnumType( self, type_node ): pass def buildForwardTypenameType( self, type_node ): pass def buildFunctionDefinition( self, declaration ): # ? function_return_type # declarator_id # function_parameters # ? cv_qualifiers # ? exception_specification pass |
From: Baptiste L. <bl...@us...> - 2004-08-07 22:55:15
|
Update of /cvsroot/cpptool/CppParser/src/pyrfta In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6955/src/pyrfta Added Files: dumpast.py Log Message: * tool to dump the raw AST output from the C++ parser --- NEW FILE: dumpast.py --- import sys import pycppparser as cprs source = file( sys.argv[1], "rt" ).read() grammar_path = 'cpp_grammar.txt' parser = cprs.makeParser( grammar_path ) translation_unit = parser.parse( source ) print translation_unit.treeStr() |
From: Baptiste L. <bl...@us...> - 2004-08-07 20:16:15
|
Update of /cvsroot/cpptool/CppParser/src/pyrfta In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16971/src/pyrfta Modified Files: pycppparser.py pycppparsertest.py Added Files: symboltabletest.py testtools.py Log Message: * ported the basis of symbol table test --- NEW FILE: symboltabletest.py --- import testtools import unittest import os.path from pycppparser import * class DeclarationsNodeProcessor(ValueNodeProcessor): def __init__( self ): ValueNodeProcessor.__init__( self ) globalDeclarations = NodeSpecification( "global_declarations", "", NS_HAS_CHILDREN ) globalDeclarations.addChild( "aggregate" ) globalDeclarations.addChild( "type_alias" ) globalDeclarations.addChild( "namespace" ) globalDeclarations.addChild( "anonymous_namespace" ) globalDeclarations.addChild( "variable" ) globalDeclarations.addChild( "enumeration" ) self.recordSpecification( globalDeclarations ) self.setRootSpecification( globalDeclarations.specificationName ) declarations = NodeSpecification( "declarations", "declarations", NS_HAS_COLON_STRING_LIST_VALUE ) self.recordSpecification( declarations ) references = NodeSpecification( "references", "references", NS_HAS_COLON_STRING_LIST_VALUE ) self.recordSpecification( references ) aggregate = NodeSpecification( "aggregate", "aggregate", NS_HAS_BRACE_VALUE | NS_HAS_CHILDREN ) aggregate.addChild( "aggregate_kind" ) aggregate.addMandatoryChild( "declarations" ) aggregate.addMandatoryChild( "references" ) aggregate.addChild( "aggregate_members" ) self.recordSpecification( aggregate ) aggregateKind = NodeSpecification( "aggregate_kind", "kind", NS_HAS_COLON_ENUMERATION_VALUE ) aggregateKind.addEnumerationValue( "class" ) aggregateKind.addEnumerationValue( "struct" ) aggregateKind.addEnumerationValue( "union" ) self.recordSpecification( aggregateKind ) aggregateMembers = NodeSpecification( "aggregate_members", "members", NS_HAS_CHILDREN ) aggregateMembers.addChild( "aggregate" ) aggregateMembers.addChild( "constructor" ) aggregateMembers.addChild( "destructor" ) aggregateMembers.addChild( "function" ) aggregateMembers.addChild( "type_alias" ) self.recordSpecification( aggregateMembers ) constructor = NodeSpecification( "constructor", "constructor", NS_HAS_BRACE_VALUE | NS_HAS_CHILDREN ) constructor.addMandatoryChild( "prototypes" ) constructor.addChild( "function_definition" ) constructor.addChild( "function_parameters" ) self.recordSpecification( constructor ) destructor = NodeSpecification( "destructor", "destructor", NS_HAS_BRACE_VALUE | NS_HAS_CHILDREN ) destructor.addMandatoryChild( "prototypes" ) destructor.addChild( "function_definition" ) destructor.addChild( "function_parameters" ) self.recordSpecification( destructor ) function = NodeSpecification( "function", "function", NS_HAS_BRACE_VALUE | NS_HAS_CHILDREN ) function.addMandatoryChild( "prototypes" ) function.addMandatoryChild( "return_type" ) function.addChild( "function_definition" ) function.addChild( "function_parameters" ) self.recordSpecification( function ) prototypes = NodeSpecification( "prototypes", "prototypes", NS_HAS_COLON_STRING_LIST_VALUE ) self.recordSpecification( prototypes ) functionDefinition = NodeSpecification( "function_definition", "definition", NS_HAS_COLON_STRING_LIST_VALUE ) self.recordSpecification( functionDefinition ) returnType = NodeSpecification( "return_type", "return_type", NS_HAS_COLON_NODE_VALUE ) returnType.addChild( "type_built_in" ) returnType.addChild( "type_const" ) returnType.addChild( "type_volatile" ) returnType.addChild( "type_ref" ) returnType.addChild( "type_ptr" ) self.recordSpecification( returnType ) functionParameters = NodeSpecification( "function_parameters", "parameters", NS_HAS_CHILDREN ) functionParameters.addChild( "function_parameter" ) self.recordSpecification( functionParameters ) functionParameter = NodeSpecification( "function_parameter", "parameter", NS_HAS_BRACE_VALUE | NS_HAS_CHILDREN ) functionParameter.addMandatoryChild( "type" ) self.recordSpecification( functionParameter ) type = NodeSpecification( "type", "type", NS_HAS_COLON_NODE_VALUE ) 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" ) self.recordSpecification( type ) typeBuiltIn = NodeSpecification( "type_built_in", "built_in", NS_HAS_BRACE_VALUES ) self.recordSpecification( typeBuiltIn ) typeType = NodeSpecification( "type_type", "type", NS_HAS_BRACE_VALUE ) self.recordSpecification( typeType ) typeConst = NodeSpecification( "type_const", "const", NS_HAS_BRACE_NODE_VALUE ) typeConst.addChild( "type_built_in" ) typeConst.addChild( "type_volatile" ) typeConst.addChild( "type_ref" ) typeConst.addChild( "type_ptr" ) typeConst.addChild( "type_type" ) self.recordSpecification( typeConst ) typeVolatile = NodeSpecification( "type_volatile", "volatile", NS_HAS_BRACE_NODE_VALUE ) typeVolatile.addChild( "type_built_in" ) typeVolatile.addChild( "type_const" ) typeVolatile.addChild( "type_ref" ) typeVolatile.addChild( "type_ptr" ) typeVolatile.addChild( "type_type" ) self.recordSpecification( typeVolatile ) typeRef = NodeSpecification( "type_ref", "ref", NS_HAS_BRACE_NODE_VALUE ) typeRef.addChild( "type_built_in" ) typeRef.addChild( "type_const" ) typeRef.addChild( "type_volatile" ) typeRef.addChild( "type_ptr" ) typeRef.addChild( "type_type" ) self.recordSpecification( typeRef ) typePtr = NodeSpecification( "type_ptr", "ptr", NS_HAS_BRACE_NODE_VALUE ) 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" ) self.recordSpecification( typePtr ) typeAlias = NodeSpecification( "type_alias", "type_alias", NS_HAS_BRACE_VALUE | NS_HAS_CHILDREN ) typeAlias.addMandatoryChild( "declarations" ) typeAlias.addMandatoryChild( "references" ) typeAlias.addMandatoryChild( "type" ) self.recordSpecification( typeAlias ) namespaceSpec = NodeSpecification( "namespace", "namespace", NS_HAS_BRACE_VALUE | NS_HAS_CHILDREN ) namespaceSpec.addMandatoryChild( "declarations" ) namespaceSpec.addMandatoryChild( "references" ) namespaceSpec.addMandatoryChild( "namespace_members" ) self.recordSpecification( namespaceSpec ) anonymousNamespace = NodeSpecification( "anonymous_namespace", "anonymous_namespace", NS_HAS_BRACE_VALUE | NS_HAS_CHILDREN ) anonymousNamespace.addMandatoryChild( "declarations" ) anonymousNamespace.addMandatoryChild( "namespace_members" ) self.recordSpecification( anonymousNamespace ) namespaceMembers = NodeSpecification( "namespace_members", "members", NS_HAS_CHILDREN ) # .. add declaration sequence members namespaceMembers.addChild( "aggregate" ) namespaceMembers.addChild( "type_alias" ) namespaceMembers.addChild( "namespace" ) namespaceMembers.addChild( "variable" ) namespaceMembers.addChild( "enumeration" ) self.recordSpecification( namespaceMembers ) enumeration = NodeSpecification( "enumeration", "enumeration", NS_HAS_BRACE_VALUE | NS_HAS_CHILDREN ) enumeration.addMandatoryChild( "declarations" ) enumeration.addMandatoryChild( "references" ) enumeration.addMandatoryChild( "enumeration_values" ) self.recordSpecification( enumeration ) enumerationValues = NodeSpecification( "enumeration_values", "values", NS_HAS_CHILDREN ) enumerationValues.addChild( "enumeration_value" ) self.recordSpecification( enumerationValues ) enumerationValue = NodeSpecification( "enumeration_value", "value", NS_HAS_BRACE_VALUE | NS_HAS_CHILDREN ) enumerationValue.addMandatoryChild( "references" ) self.recordSpecification( enumerationValue ) variable = NodeSpecification( "variable", "variable", NS_HAS_BRACE_VALUE | NS_HAS_CHILDREN ) variable.addMandatoryChild( "declarations" ) variable.addMandatoryChild( "references" ) variable.addMandatoryChild( "type" ) self.recordSpecification( variable ) self.checkSpecifications() class SymbolTableTestProcessor(testtools.LineProcessor): def __init__( self, location_tracker, filesystem ): testtools.LineProcessor.__init__( self, location_tracker ) self.buffer_name = None self.filesystem = filesystem self.declarations_start_line = -1 self.description = '' def _commentAllowed( self ): pass def _doProcessLine( self, line ): if not self.buffer_name: return value = getattr( self, self.buffer_name ) + line setattr( self, self.buffer_name, value ) def _doStateChange( self, name, parameter ): if name == 'declarations': self.buffer_name = 'declarations' self.declarations = '' self.declarations_start_line = self.currentLine() + 1 elif name == 'description': self.buffer_name = 'description' else: return False return True def _doProcessReadFile( self, path, content ): file_id = self.filesystem.setFileContent( path, content ) self._memorizePendingLocations( file_id ) def _doTerminateCurrentAction( self ): if self.buffer_name == 'declarations': self._processDeclarations() self.buffer_name = None def _processDeclarations( self ): processor = DeclarationsNodeProcessor() self.declarations_tree = processor.parseNodeTree( self.declarations, self.declarations_start_line ) class DeclarationChecker: def __init__( self, filesystem, tracker ): pass def checkDeclarations( self, root ): pass class SymbolTableTestCase(unittest.TestCase): def __init__( self, base_path, filename ): unittest.TestCase.__init__( self ) self.path = os.path.join( base_path, filename ) def runTest( self ): tracker = testtools.LocationTracker() filesystem = testtools.FileSystem() processor = SymbolTableTestProcessor( tracker, filesystem ) processor.processFile( self.path ) root = processor.declarations_tree checker = DeclarationChecker( filesystem, tracker ) checker.checkDeclarations( root ) class SymbolTableTestSuite(unittest.TestSuite): def __init__( self ): unittest.TestSuite.__init__( self ) generator = testtools.TestListTestCaseGenerator( self, SymbolTableTestCase, 'testdata/symbol_table', '__tests__.txt' ) if __name__ == '__main__': unittest.main( defaultTest = 'SymbolTableTestSuite' ) --- NEW FILE: testtools.py --- import os.path import unittest class LineProcessorError(RuntimeError): pass class LocationTracker: def __init__( self ): self.locations_by_files = {} def memorizeLocation( self, file_id, locations ): self.locations_by_files[ file_id ] = locations.copy() class LineProcessor: def __init__( self, location_tracker ): self.location_tracker = location_tracker self.line = 0 self.is_reading_file = False def processFile( self, path ): try: f = file(path, 'rt') for line in f: self.processLine( line ) f.close() self.terminateCurrentAction() except IOError, e: self._raiseError( 'Failed to read: %s\n%s' % (path,str(e)) ) def processLine( self, line ): self.line += 1 if self._isCommentLine( line ) or self._handleStateChangeLine( line ): return if self.is_reading_file: self._processReadFile( line ) else: self._doProcessLine( line ) def terminateCurrentAction( self ): if self.is_reading_file: self._doProcessReadFile( self.file_path, self.file_content ) self.is_reading_file = False self._doTerminateCurrentAction() def currentLine( self ): return self.line def _memorizePendingLocations( self, file ): self.location_tracker.memorizeLocation( file, self.pending_locations ) def _processActionLine( self, line ): pass def _isCommentLine( self, line ): return self._commentAllowed() and line.startswith( '##' ) def _handleStateChangeLine( self, line ): marker = '====' if not line.startswith( marker ): return False endNameIndex = line.find( ':', len(marker) ) if endNameIndex == -1: self._raiseError( "Missing ':' on state change line." ) stateName = line[len(marker):endNameIndex] parameter = line[endNameIndex:].strip() self.terminateCurrentAction() if stateName == 'file': self._beginReadingFile( parameter ) return True elif stateName == 'end': return True if not self._doStateChange( stateName, parameter ): self._raiseError( "Unknown action: '%s'." % stateName ) return True def _raiseError( self, message ): raise LineProcessorError( 'Line: %d\n%s' % (self.line,message) ) def _beginReadingFile( self, virtual_path ): self.is_reading_file = True self.file_content = '' self.file_path = virtual_path self.pending_locations = {} def _processReadFile( self, line ): cleanLine = line[:] while True: locIndex = cleanLine.find( '$' ) if locIndex == -1: break locEndIndex = cleanLine.find( '$', locIndex+1 ) if locEndIndex == -1: break tag = cleanLine[locIndex+1:locEndIndex] cleanLine = cleanLine[0:locIndex] + cleanLine[locEndIndex:] text_offset = len(self.file_content) + locIndex self.pending_locations[tag] = text_offset self.file_content += cleanLine # Those should be define in derived class def _commentAllowed( self ): return True ## def _doProcessLine( self, line ): ## pass def _doStateChange( self, name, parameter ): return False def _doProcessReadFile( self, path, content ): pass def _doTerminateCurrentAction( self ): pass class TestListTestCaseGenerator(LineProcessor): """Instiate test case parametrized by a path read from a file, and add them in a test suite.""" def __init__( self, test_suite, test_class, base_path, list_filename ): LineProcessor.__init__( self, None ) self.base_path = base_path self.test_suite = test_suite self.test_class = test_class test_list_path = os.path.join( base_path, list_filename ) try: self.processFile( test_list_path ) except LineProcessorError, e: class FailingTestCase(unittest.TestCase): def __init__( self, message ): unittests.TestCase.__init__( self ) self.message = message def runTest( self ): raise message self.test_suite.addTest( FailingTestCase( "Failed to load test list: " ) ) def _doProcessLine( self, line ): line = line.strip() if len(line) > 0: self.test_suite.addTest( self.test_class( self.base_path, line ) ) class FileSystem: def __init__( self ): self.next_id = 1 self.id_by_path = {} self.content_by_id = {} def setFileContent( self, path, content ): id = self.getFileId( path ) self.content_by_id[ id ] = content return id def getFileId( self, path ): if self.id_by_path.has_key( path ): return self.id_by_path[ path ] id = self.next_id self.next_id += 1 self.id_by_path[ path ] = id return id Index: pycppparser.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/pycppparser.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** pycppparser.py 7 Aug 2004 15:52:24 -0000 1.1 --- pycppparser.py 7 Aug 2004 20:16:06 -0000 1.2 *************** *** 1 **** --- 1,16 ---- from pycppparser_ import * + + ##for name in dir(NodeSpecificationTypes): + ## if name.startswith( 'NS_' ): + ## print '%s = NodeSpecificationTypes.%s' % (name,name) + + # Can't find out how to inject symbol in the current module + NS_HAS_BRACE_NODE_VALUE = NodeSpecificationTypes.HAS_BRACE_NODE_VALUE + NS_HAS_BRACE_VALUE = NodeSpecificationTypes.HAS_BRACE_VALUE + NS_HAS_BRACE_VALUES = NodeSpecificationTypes.HAS_BRACE_VALUES + NS_HAS_CHILDREN = NodeSpecificationTypes.HAS_CHILDREN + NS_HAS_COLON_ENUMERATION_VALUE = NodeSpecificationTypes.HAS_COLON_ENUMERATION_VALUE + NS_HAS_COLON_NODE_VALUE = NodeSpecificationTypes.HAS_COLON_NODE_VALUE + NS_HAS_COLON_STRING_LIST_VALUE = NodeSpecificationTypes.HAS_COLON_STRING_LIST_VALUE + NS_HAS_COLON_VALUE = NodeSpecificationTypes.HAS_COLON_VALUE + NS_NONE = NodeSpecificationTypes.NONE \ No newline at end of file Index: pycppparsertest.py =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pyrfta/pycppparsertest.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** pycppparsertest.py 7 Aug 2004 15:52:24 -0000 1.1 --- pycppparsertest.py 7 Aug 2004 20:16:06 -0000 1.2 *************** *** 58,62 **** def visitChildren( self, node ): for child in node.enumChildren(): ! print 'visiting:', child self.visitChildren( child ) --- 58,62 ---- def visitChildren( self, node ): for child in node.enumChildren(): ! #print 'visiting:', child self.visitChildren( child ) |
From: Baptiste L. <bl...@us...> - 2004-08-07 20:15:38
|
Update of /cvsroot/cpptool/CppParser/src/pycppparser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16909/src/pycppparser Modified Files: main.cpp pycppparser.vcproj pyenumerator.h Added Files: nodeprocessor.cpp Log Message: * fixed many small issues revealed by python unit tests. * added NodeProcessor binding --- NEW FILE: nodeprocessor.cpp --- // Boost Includes ============================================================== #include <boost/python.hpp> #include <boost/cstdint.hpp> // Includes ==================================================================== #include <rfta/cppparser/nodeprocessor.h> #include "pyenumerator.h" // Using ======================================================================= using namespace boost::python; // Declarations ================================================================ namespace py { }// namespace py // Module ====================================================================== void Export_cppparser_NodeProcessor() { enum_<NodeSpecificationTypes>( "NodeSpecificationTypes" ) .value( "NONE", nsNone ) .value( "HAS_BRACE_VALUE", nsHasBraceValue ) .value( "HAS_BRACE_VALUES", nsHasBraceValues ) .value( "HAS_BRACE_NODE_VALUE", nsHasBraceNodeValue ) .value( "HAS_COLON_VALUE", nsHasColonValue ) .value( "HAS_COLON_NODE_VALUE", nsHasColonNodeValue ) .value( "HAS_COLON_ENUMERATION_VALUE", nsHasColonEnumerationValue ) .value( "HAS_COLON_STRING_LIST_VALUE", nsHasColonStringListValue ) .value( "HAS_CHILDREN", nsHasChildren ) ; class_< NodeSpecification >( "NodeSpecification", init<const std::string & ,const std::string & ,NodeSpecification::Features>() ) .add_property( "inputName", make_function( &NodeSpecification::inputName, return_value_policy<copy_const_reference>() ) ) .add_property( "specificationName", make_function( &NodeSpecification::specificationName, return_value_policy<copy_const_reference>() ) ) .def( "addEnumerationValue", &NodeSpecification::addEnumerationValue ) .def( "addChild", &NodeSpecification::addChild ) .def( "addMandatoryChild", &NodeSpecification::addMandatoryChild ) ; class_< Node, boost::noncopyable >( "ValueNode", no_init ) .add_property( "column", &Node::column ) .add_property( "line", &Node::line ) .add_property( "inputName", make_function( &Node::inputName, return_value_policy<copy_const_reference>() ) ) .add_property( "specificationName", make_function( &Node::specificationName, return_value_policy<copy_const_reference>() ) ) .def( "braceValue", &Node::braceValue ) .def( "braceValues", &Node::braceValues ) .def( "braceNodeValue", &Node::braceNodeValue ) .def( "braceNodeValues", &Node::braceNodeValues ) .def( "colonValue", &Node::colonValue ) .def( "colonValues", &Node::colonValues ) .def( "colonNodeValue", &Node::colonNodeValue ) .def( "colonNodeValues", &Node::colonNodeValues ) .def( "hasChild", &Node::hasChild ) .def( "child", &Node::child ) .def( "children", &Node::children ) ; EnumeratorDeclarator< Node::NodeEnumerator >( "ValueNodeEnumerator" ); EnumeratorDeclarator< Node::ValueEnumerator >( "ValueNodeValueEnumerator" ); class_< NodeProcessor, boost::noncopyable >( "ValueNodeProcessor", init<>() ) .def( "recordSpecification", &NodeProcessor::recordSpecfication ) .def( "setRootSpecification", &NodeProcessor::setRootSpecification ) .def( "checkSpecifications", &NodeProcessor::checkSpecifications ) .def( "parseNodeTree", &NodeProcessor::parseNodeTree ) ; register_ptr_to_python< NodeSpecificationPtr >(); register_ptr_to_python< NodePtr >(); } Index: main.cpp =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pycppparser/main.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** main.cpp 7 Aug 2004 15:52:24 -0000 1.1 --- main.cpp 7 Aug 2004 20:15:28 -0000 1.2 *************** *** 8,11 **** --- 8,12 ---- void Export_cppparser_ConstString(); void Export_cppparser_CppParserFacade(); + void Export_cppparser_NodeProcessor(); // Module ====================================================================== *************** *** 17,20 **** --- 18,22 ---- Export_cppparser_ConstString(); Export_cppparser_CppParserFacade(); + Export_cppparser_NodeProcessor(); } Index: pycppparser.vcproj =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pycppparser/pycppparser.vcproj,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** pycppparser.vcproj 7 Aug 2004 15:52:24 -0000 1.1 --- pycppparser.vcproj 7 Aug 2004 20:15:28 -0000 1.2 *************** *** 173,176 **** --- 173,179 ---- </File> <File + RelativePath=".\nodeprocessor.cpp"> + </File> + <File RelativePath=".\pyenumerator.h"> </File> Index: pyenumerator.h =================================================================== RCS file: /cvsroot/cpptool/CppParser/src/pycppparser/pyenumerator.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** pyenumerator.h 7 Aug 2004 15:52:24 -0000 1.1 --- pyenumerator.h 7 Aug 2004 20:15:28 -0000 1.2 *************** *** 22,29 **** if ( !iterator.hasNext() ) boost::python::objects::stop_iteration_error(); // in object/iterator_core.hpp ! return iterator.nextPtr(); } ! static IteratorType iter( const IteratorType &iterator ) { return iterator; --- 22,29 ---- if ( !iterator.hasNext() ) boost::python::objects::stop_iteration_error(); // in object/iterator_core.hpp ! return iterator.next(); } ! static EnumeratorType iter( const EnumeratorType &iterator ) { return iterator; |
Update of /cvsroot/cpptool/CppParser/src/cppparser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9448/src/cppparser Added Files: commandstream.cpp commandstream.h commandstreamtest.cpp commandstreamtest.h conststringtest.cpp conststringtest.h cpp_grammar.txt cpplexer.cpp cpplexer.h cpplexertest.cpp cpplexertest.h cppnodetestbase.cpp cppnodetestbase.h cppparser.cpp cppparser.vcproj cppparserfacade.cpp cppparsertest.cpp cppparsertest.h grammar_tree.txt grammarbuilder.cpp grammarbuilder.h grammarbuildertest.cpp grammarbuildertest.h grammarparser.cpp grammarparser.h grammarparsertest.cpp grammarparsertest.h node.cpp nodeiterator.h nodeprocessor.cpp nodetest.cpp nodetest.h nodetesthelper.cpp nodetesthelper.h nodetracker.cpp nodetrackertest.cpp nodetreetestbase.cpp nodetreetestbase.h parsecontext.h parser.h parsertest.cpp parsertest.h parsertesthelper.cpp parsertesthelper.h parsingtracker.cpp parsingtracker.h preprocessortest.cpp preprocessortest.h stlhelper.h testtools.h token.h tokentesthelper.h unittesting.h Log Message: * made a library out of the c++ parser (cppparser) * exposed the c++ parser to python (pycppparser) * migrating refactoring framework to python (pyrfta) --- NEW FILE: cppparser.vcproj --- <?xml version="1.0" encoding="Windows-1252"?> <VisualStudioProject ProjectType="Visual C++" Version="7.10" Name="cppparser" ProjectGUID="{EA6D6F9C-4BA7-4A0D-BD46-7ACA6F3D6E72}" Keyword="Win32Proj"> <Platforms> <Platform Name="Win32"/> </Platforms> <Configurations> <Configuration Name="Debug|Win32" OutputDirectory="../../build/cppparser/debug" IntermediateDirectory="../../build/cppparser/debug" ConfigurationType="2" CharacterSet="2"> <Tool Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="../../include" PreprocessorDefinitions="PARSER_ENABLE_TRACKING;RFTA_CPPPARSER_DLL_BUILD" MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="3" EnableFunctionLevelLinking="FALSE" ForceConformanceInForLoopScope="TRUE" RuntimeTypeInfo="TRUE" UsePrecompiledHeader="0" WarningLevel="3" Detect64BitPortabilityProblems="TRUE" DebugInformationFormat="4" DisableSpecificWarnings="4267;4244;4018;4251"/> <Tool Name="VCCustomBuildTool"/> <Tool Name="VCLinkerTool" AdditionalDependencies="cpput_vc6_mds.lib" OutputFile="$(OutDir)/rfta_cppparser_vc7_mdd.dll" AdditionalLibraryDirectories="../../build/cpput/debug;../../libs/vc71/boost" GenerateDebugInformation="TRUE" SubSystem="2" TargetMachine="1"/> <Tool Name="VCMIDLTool"/> <Tool Name="VCPostBuildEventTool"/> <Tool Name="VCPreBuildEventTool"/> <Tool Name="VCPreLinkEventTool"/> <Tool Name="VCResourceCompilerTool"/> <Tool Name="VCWebServiceProxyGeneratorTool"/> <Tool Name="VCXMLDataGeneratorTool"/> <Tool Name="VCWebDeploymentTool"/> <Tool Name="VCManagedWrapperGeneratorTool"/> <Tool Name="VCAuxiliaryManagedWrapperGeneratorTool"/> </Configuration> <Configuration Name="Release|Win32" OutputDirectory="../../build/cppparser/release" IntermediateDirectory="../../build/cppparser/release" ConfigurationType="4" CharacterSet="2"> <Tool Name="VCCLCompilerTool" AdditionalIncludeDirectories="../../include" PreprocessorDefinitions="PARSER_ENABLE_TRACKING;RFTA_CPPPARSER_DLL_BUILD" RuntimeLibrary="2" ForceConformanceInForLoopScope="TRUE" RuntimeTypeInfo="TRUE" UsePrecompiledHeader="0" WarningLevel="3" Detect64BitPortabilityProblems="TRUE" DebugInformationFormat="3" DisableSpecificWarnings="4267;4244;4018;4251"/> <Tool Name="VCCustomBuildTool"/> <Tool Name="VCLibrarianTool" OutputFile="$(OutDir)/cppparser.lib" AdditionalLibraryDirectories="../../libs/vc71/boost;../../build/cpput/release"/> <Tool Name="VCMIDLTool"/> <Tool Name="VCPostBuildEventTool"/> <Tool Name="VCPreBuildEventTool"/> <Tool Name="VCPreLinkEventTool"/> <Tool Name="VCResourceCompilerTool"/> <Tool Name="VCWebServiceProxyGeneratorTool"/> <Tool Name="VCXMLDataGeneratorTool"/> <Tool Name="VCManagedWrapperGeneratorTool"/> <Tool Name="VCAuxiliaryManagedWrapperGeneratorTool"/> </Configuration> </Configurations> <References> </References> <Files> <Filter Name="parser" Filter=""> <File RelativePath=".\commandstream.cpp"> </File> <File RelativePath=".\commandstream.h"> </File> <File RelativePath=".\cpplexer.cpp"> </File> <File RelativePath=".\cpplexer.h"> </File> <File RelativePath=".\cppparser.cpp"> </File> <File RelativePath=".\cppparserfacade.cpp"> </File> <File RelativePath=".\grammarbuilder.cpp"> </File> <File RelativePath=".\grammarbuilder.h"> </File> <File RelativePath=".\grammarparser.cpp"> </File> <File RelativePath=".\grammarparser.h"> </File> <File RelativePath=".\grammarparsertest.cpp"> </File> <File RelativePath=".\grammarparsertest.h"> </File> <File RelativePath=".\node.cpp"> </File> <File RelativePath=".\nodeiterator.h"> </File> <File RelativePath=".\nodeprocessor.cpp"> </File> <File RelativePath=".\parsecontext.h"> </File> <File RelativePath=".\parser.h"> </File> <File RelativePath=".\parsingtracker.cpp"> </File> <File RelativePath=".\parsingtracker.h"> </File> <File RelativePath=".\stlhelper.h"> </File> <File RelativePath=".\tokenmanager.h"> </File> <Filter Name="interface" Filter=""> <File RelativePath="..\..\include\rfta\cppparser\autolink.h"> </File> <File RelativePath="..\..\include\rfta\cppparser\config.h"> </File> <File RelativePath="..\..\include\rfta\cppparser\conststring.h"> </File> <File RelativePath="..\..\include\rfta\cppparser\cppparser.h"> </File> <File RelativePath="..\..\include\rfta\cppparser\cppparserfacade.h"> </File> <File RelativePath="..\..\include\rfta\cppparser\cppparsersettings.h"> </File> <File RelativePath="..\..\include\rfta\cppparser\forwards.h"> </File> <File RelativePath="..\..\include\rfta\cppparser\node.h"> </File> <File RelativePath="..\..\include\rfta\cppparser\nodeprocessor.h"> </File> <File RelativePath="..\..\include\rfta\cppparser\token.h"> </File> </Filter> </Filter> <Filter Name="tests" Filter=""> <File RelativePath=".\commandstreamtest.cpp"> </File> <File RelativePath=".\commandstreamtest.h"> </File> <File RelativePath=".\conststringtest.cpp"> </File> <File RelativePath=".\conststringtest.h"> </File> <File RelativePath=".\cpplexertest.cpp"> </File> <File RelativePath=".\cpplexertest.h"> </File> <File RelativePath=".\cppnodetestbase.cpp"> </File> <File RelativePath=".\cppnodetestbase.h"> </File> <File RelativePath=".\cppparsertest.cpp"> </File> <File RelativePath=".\cppparsertest.h"> </File> <File RelativePath=".\grammarbuildertest.cpp"> </File> <File RelativePath=".\grammarbuildertest.h"> </File> <File RelativePath=".\nodetest.cpp"> </File> <File RelativePath=".\nodetest.h"> </File> <File RelativePath=".\nodetesthelper.cpp"> </File> <File RelativePath=".\nodetesthelper.h"> </File> <File RelativePath=".\nodetreetestbase.cpp"> </File> <File RelativePath=".\nodetreetestbase.h"> </File> <File RelativePath=".\parsertest.cpp"> </File> <File RelativePath=".\parsertest.h"> </File> <File RelativePath=".\parsertesthelper.cpp"> </File> <File RelativePath=".\parsertesthelper.h"> </File> <File RelativePath=".\preprocessortest.cpp"> </File> <File RelativePath=".\tokentesthelper.h"> </File> <File RelativePath=".\unittesting.h"> </File> </Filter> </Files> <Globals> </Globals> </VisualStudioProject> --- NEW FILE: cpplexer.cpp --- #include "cpplexer.h" #include "stlhelper.h" #include <boost/regex/v4/regex.hpp> #include <algorithm> #include <iterator> #include <set> #include <utility> #include <vector> using namespace Parser::CppLexerMatchType; namespace { template<bool isMacroLexer> class GenericCppLexer : public Parser::CppLexer { public: GenericCppLexer() { initializePatterns(); } // overridden from CppLexer void tokenize( const char *inputStart, const char *inputEnd, Parser::CppLexerMatchHandler &handler ) { handler.setTokenizedText( inputStart, inputEnd ); const char *current = inputStart; while ( current != inputEnd ) { bool matchFound = false; Patterns::iterator it = patterns().begin(); for ( ; it != patterns().end(); ++it ) { boost::match_results<const char *> results; if ( boost::regex_search( current, inputEnd, results, it->second, boost::match_default ) ) { MatchType type = it->first; if ( type == matchIdentifier && keywords().count( std::string( results[0].first,results[0].length() ) ) > 0 ) { type = matchSymbol; } else if ( type == matchInteger && results[0].length() == 1 && *(results[0].first) == '0' ) { type = matchSymbol; } handler.matched( results[0].first - inputStart, results[0].second - inputStart, type ); current = results[0].second; matchFound = true; break; } } if ( !matchFound ) { handler.matched( current - inputStart, current+1 - inputStart, matchError ); ++current; } } } static void addPattern( Parser::CppLexerMatchType::MatchType type, const std::string &pattern ) { boost::regex expression( pattern ); patterns().push_back( PatternInfo( type, expression ) ); } static void setKeywords( const std::string &keywordsList ) { StlHelper::splitStringList( keywordsList, std::inserter( keywords(), keywords().begin() ) ); } private: static void initializePatterns() { // pattern compilation takes a large amount of time, so they are static if ( !patterns().empty() ) return; addPattern( matchSpaces, "\\A[ \t\r\n]+" ); addPattern( matchCppComment, "\\A//[^\\r\\n]*" ); addPattern( matchCComment, "\\A(?:/\\*.*?\\*/)" ); if ( !isMacroLexer ) { addPattern( matchPreprocessorDirective, "\\A#[ \t]*[a-zA-Z_]" "(?:" "(?:\\\\(?:\\r|\\n|\\r\\n))|" // '\n': macro continue "(?:/\\*.*?\\*/)|" // C comment "[^\\r\\n]" ")*" ); } addPattern( matchIdentifier, "\\A[A-Za-z_][A-Za-z0-9_]*" ); addPattern( matchString, "\\A\"(?:[^\\\\\"]|\\\\.)*\"" ); addPattern( matchCharacter, "\\A'(?:[^\\\\']|\\\\.)*'" ); addPattern( matchFloat, "\\A(?:[0-9]*\\.[0-9]+(?:e[-\\+]?[0-9]+)?[fFL]?|" // [1234].1234[e[-+]123][fFL] "[0-9]+(?:[eE][+-]?[0-9]+)[fFL]?)" ); // 1234e[-+]123[fFL] addPattern( matchInteger, "\\A(?:0x[0-9a-fA-F]+|[0-9]+)L?" ); std::string keywords = "__asm asm else struct __assume enum __multiple_inheritance switch " "auto __except __single_inheritance template __based explicit __virtual_inheritance this " "bool extern mutable break false throw case __fastcall namespace true " "catch __finally new try __cdecl float __try char for operator typedef " "class friend private typeid const goto protected typename const_cast if public union " "continue inline register unsigned __declspec __inline reinterpret_cast using " "default int return delete __int8 short __uuidof __int16 signed virtual " "__int32 sizeof void do __int64 static volatile double __leave static_cast wmain " "dynamic_cast long __stdcall while "; setKeywords( keywords ); std::string symbols = "\\.\\.\\. >>= <<= :: << >> <= >= == != \\|\\| && " "&= \\|= \\+= -= /= \\*= \\^= %= -> \\+\\+ -- " "\\. \\( \\) \\[ \\] \\{ \\} ~ / - \\+ / \\* = \\^ % < > & \\| ; , : \\? !"; if ( isMacroLexer ) symbols = "## " + symbols + " #"; std::replace( symbols.begin(), symbols.end(), ' ', '|' ); addPattern( matchSymbol, "\\A(?:" + symbols + ")" ); } private: typedef std::pair<Parser::CppLexerMatchType::MatchType,boost::regex> PatternInfo; typedef std::vector<PatternInfo> Patterns; static Patterns &patterns() { static Patterns patternsGlobal; return patternsGlobal; } typedef std::set<std::string> Keywords; static Keywords &keywords() { static Keywords keywordsGlobal; return keywordsGlobal; } }; } // anonymous namespace namespace Parser { CppLexerPtr makeCppLexer() { return CppLexerPtr( new GenericCppLexer<false>() ); } CppLexerPtr makeCppMacroLexer() { return CppLexerPtr( new GenericCppLexer<true>() ); } } // namespace Parser --- NEW FILE: grammar_tree.txt --- /* C++ grammar Tree */ translation_unit[ declarations[...] ] ///////////////////////////////// declarations /////////////////////////// declarations[ [ n declaration_error | namespace_alias_def[ id namespace_specifier[...] ~ n id] // +(namespace_name) | using_declaration[ using_id ~ n id] // @todo any_id | using_directive[ namespace_specifier[...] ] | simple_declaration[ [ typedef_decl_specifiers[ type_specifier[...] ] | friend_specifier[ declaration_specifier[...] ] | declaration_specifier[ //content same as friend_specifier ? storage_class_specifier ? function_specifier type_specifier[...] ] ] ? init_declarators[ n init_declarator[ declarator[...] ? assign_initializer[ [ assignment_expression[...] // = 1234 | n initializer_clause ] // = {1,2,3,4} | expression_list[...] // (1,2,3,4) ctor ] ] ] ] ] | linkage_specification[ 'extern' $string [ '{' !declaration_seq '}' => same as translation_unit | declaration[...] ] ] | named_namespace_def[ id namespace_body[ !declaration_seq ] ] | unnamed_namespace_def[ namespace_body[ !declaration_seq ] ] | function_definition[ ... ] | template_declaration[ ... ] | explicit_template_instantiation[...] | explicit_template_specialization[...] ] ] ///////////////////////////////// type_specifier /////////////////////////// type_specifier[ cv_qualifiers [ fundamental_type_specifier | type_name | enum_specifier[ id enumerator_definitions[ n enumerator_definition[ id constant_expression[...] ] ] ] | class_specifier[...] | forward_class_specifier[ forwarded_type_id[ ~n id ] ] | forward_enum_specifier[ // @todo better tree structure forwarded_type_id[ ~n id ] ] | forward_typename_specifier[ forwarded_type_id[ ~n id ] ] ] ? cv_qualifiers ] ///////////////////////////////// class_specifier[ class_name ? dll_macro[ id] ? nested_name_specifier[...] id[ id] | template_id[...] ? class_bases[ n base_specifier[ base_class_access ? 'virtual' %access_specifier ? 'virtual'] base_class_name[ ? nested_name_specifier id] ] ? member_specification[ n access_specification[ %access_specifier ] | member_declaration[ member_function_definition[ function_definition[ ? function_return_type declarator_id[~ n id] function_parameters[ n function_parameter[ declaration_specifier[ ] declarator[ ? ptr_operator_declarator[ '*' ? cv_qualifier_seq[...] | '&' | pointer_to_member[ nested_name_specifier[..] ?cv_qualifier_seq[...] ] ] declarator_id[...] | braced_declarator[ declarator[...] ] function_parameters[...] | abstract_array_declarator[ constant_expression[...] ] ? assign_initializer[ assignment_expression[...] ] ] ? ellipsis_parameter[ '...' ] ? cv_qualifiers ? exception_specification ] ? cv_qualifiers[ n cv_qualifier] ? exception_specification[ type_id_list[ type_id[...] ] ] ] | member_error[...] ] ] --- NEW FILE: cppparserfacade.cpp --- #include <rfta/cppparser/cppparserfacade.h> #include <rfta/cppparser/cppparser.h> #include "grammarbuilder.h" #include "parsecontext.h" //#include "commandstream.h" #include <fstream> namespace Parser { CppParserFacade::CppParserFacade( const CppParserSettings &settings ) : builder_( new GrammarBuilder() ) , settings_( settings ) { std::ifstream is( settings.grammarPath().c_str() ); if ( is.fail() ) throw CppParserFacadeError( "Failed to open c++ grammar file: " + settings.grammarPath() ); std::string grammar; std::string line; while ( !is.eof() ) { std::getline( is, line ); grammar += line; grammar += '\n'; } is.close(); CppParser::setUpGrammarBuilder( *builder_ ); builder_->build( grammar ); if ( builder_->getErrorCount() > 0 ) throw CppParserFacadeError( "C++ grammar contains error." ); translationUnitMatcher_ = builder_->getMatcher( "translation_unit" ); if ( !translationUnitMatcher_ ) throw CppParserFacadeError( "C++ grammar does not contains a 'translation_unit' rule." ); } NodePtr CppParserFacade::parse( const std::string &input ) { Parser::Tokens tokens; // Parser::CppParser::preprocess( input, tokens ); Parser::CppParser::tokenize( input, tokens ); Parser::CommandStream result; Parser::ParseContext context( tokens.begin(), tokens.end(), result ); bool matched = translationUnitMatcher_->parse( context ); if ( !matched ) // should never happen because of error recovery throw CppParserFacadeError( "Critical error: failed to parse input." ); // note: at the current time, ending silent tokens are not added to the ast NodePtr rootNode = result.makeNodeTree(); if ( rootNode->hasChildren() ) return rootNode->childAt(0); return NodePtr(); } } // namespace Parser --- NEW FILE: parsertesthelper.cpp --- #include "parsertesthelper.h" namespace ParserTesting { void addParseContextRemainingTokens( Parser::ParseContext &context, CppUT::Message &message ) { Parser::Tokens remainingTokens; context.getRelativeTokenRange( 0, 100, remainingTokens ); message.add( "Remaining tokens: " + CppUT::enumToString( CppUT::enumStl( remainingTokens ) ) ); } static bool containsErrorNode( const Parser::NodePtr &tree ) { if ( tree->name().str().find( "error" ) != std::string::npos ) return true; Parser::NodeEnumerator enumNode( tree->enumChildren() ); while ( enumNode.hasNext() ) if ( containsErrorNode( enumNode.nextPtr() ) ) return true; return false; } void checkContainsNoErrorNode( const Parser::NodePtr &tree, const CppUT::Message &message ) { if ( containsErrorNode( tree ) ) { CppUT::Message errorMessage( message ); errorMessage.add( "Produced tree:\n" + tree->treeStr(2) ); CppUT::fail( errorMessage ); } } void checkParseContextIsBalanced( Parser::ParseContext &context, Parser::Tokens tokens, const Parser::MatcherPtr &matcher, Parser::FullParsingTracker &tracker ) { if ( context.isStateBalanced() ) return; CppUT::Message newMessage; newMessage.add( "Parser state is not balanced." ); addParseContextRemainingTokens( context, newMessage ); newMessage.add( "Tokens: " + CppUT::enumToString( CppUT::enumStl( tokens ) ) ); newMessage.add( "Parser: " + matcher->str() ); newMessage.add( "Parsing traces:\n" + tracker.collectedTraces() ); CppUT::fail( newMessage ); } void checkParserMatchPartial( Parser::Tokens tokens, const Parser::MatcherPtr &matcher, int expectedRemainingTokens, TraceFlag flag, Parser::NodePtr expectedTree ) { // tokens.push_back( Parser::Token( "", Parser::endStream ) ); Parser::FullParsingTracker tracker; if ( (flag & progressiveTrace) != 0 ) tracker.setProgressive( true ); bool enableTrace = (flag & traceEnabled) != 0; Parser::CommandStream result; Parser::ParseContext context( tokens.begin(), tokens.end(), result, enableTrace ? &tracker : 0 ); bool matched = matcher->parse( context ); checkParseContextIsBalanced( context, tokens, matcher, tracker ); CppUT::Message newMessage; if ( matched ) { context.pushState(); int actualRemainingTokens = 0; while ( context.hasMoreToken() ) // context.nextToken() && .type() != Parser::endStream ) { context.nextToken(); ++actualRemainingTokens; } context.popState(); if ( actualRemainingTokens == expectedRemainingTokens ) { bool checkNoError = (flag & checkNoErrorNodeInTree) != 0; if ( expectedTree || checkNoError ) { Parser::NodePtr actualTree = result.makeNodeTree(); if ( expectedTree ) { if ( (flag & addEmptyRootToExpectedTree) != 0 ) expectedTree = testNode( "", expectedTree ); ParserTesting::checkNodeTreeEquals( expectedTree, actualTree, "Parsing did not produce the expected tree." ); } if ( checkNoError ) ParserTesting::checkContainsNoErrorNode( actualTree, "Error recovery was triggered during parsing." ); } return; } if ( expectedRemainingTokens == 0 ) newMessage.add( "All tokens were not consumed by parsing." ); else newMessage.add( CppUT::makeEqualityFailedMessage( expectedRemainingTokens, actualRemainingTokens, "Wrong remaining token count." ) ); } else newMessage.add( "Parsing failed." ); addParseContextRemainingTokens( context, newMessage ); newMessage.add( "Tokens: " + CppUT::enumToString( CppUT::enumStl( tokens ) ) ); if ( (flag & dumpParser) != 0 ) newMessage.add( "Parser: " + matcher->str() ); else if ( !matcher->name().empty() ) newMessage.add( "Parser name: " + matcher->name() ); if ( enableTrace ) newMessage.add( "Parsing traces:\n" + tracker.collectedTraces() ); CppUT::fail( newMessage ); } void checkParserMatch( Parser::Tokens tokens, const Parser::MatcherPtr &matcher, TraceFlag flag ) { checkParserMatchPartial( tokens, matcher, 0, flag, Parser::NodePtr() ); } void checkParserFail( Parser::Tokens tokens, const Parser::MatcherPtr &matcher, TraceFlag flag ) { // tokens.push_back( Parser::Token( "", Parser::endStream ) ); Parser::FullParsingTracker tracker; if ( (flag & progressiveTrace) != 0 ) tracker.setProgressive( true ); Parser::CommandStream result; Parser::ParseContext context( tokens.begin(), tokens.end(), result, &tracker ); bool matched = matcher->parse( context ); checkParseContextIsBalanced( context, tokens, matcher, tracker ); if ( !matched ) return; CppUT::Message newMessage; newMessage.add( "Parsing did not failed." ); newMessage.add( "Tokens: " + CppUT::enumToString( CppUT::enumStl( tokens ) ) ); newMessage.add( "Parser: " + matcher->str() ); newMessage.add( "Parsing traces:\n" + tracker.collectedTraces() ); CppUT::fail( newMessage ); } void checkProducedTreeEqual( Parser::Tokens tokens, const Parser::MatcherPtr &matcher, const Parser::NodePtr &expected, TraceFlag flag ) { checkParserMatchPartial( tokens, matcher, 0, flag, expected ); } void checkPartialProducedTreeEqual( Parser::Tokens tokens, const Parser::MatcherPtr &matcher, const Parser::NodePtr &expected, int expectedRemaining, TraceFlag flag ) { checkParserMatchPartial( tokens, matcher, expectedRemaining, flag, expected ); } } // namespace ParserTesting --- NEW FILE: token.h --- #ifndef PARSER_TOKEN_H_INCLUDED # define PARSER_TOKEN_H_INCLUDED # include <rfta/cppparser/conststring.h> # include <map> # include <sstream> # include <vector> namespace Parser { typedef unsigned int BufferId; class TokenLocation { public: TokenLocation() : startPos_(-1) , endPos_(-1) , bufferId_(-1) { } TokenLocation( unsigned int startPos, unsigned int endPos, BufferId bufferId ) : startPos_( startPos ) , endPos_( endPos ) , bufferId_( bufferId ) { } bool isValid() const { return startPos_ != -1 && endPos_ != -1; } bool operator ==( const TokenLocation &other ) const { return startPos_ == other.startPos_ && endPos_ == other.endPos_ && bufferId_ == other.bufferId_; } bool operator !=( const TokenLocation &other ) const { return !( *this == other ); } unsigned int length() const { return endPos_ - startPos_; } unsigned int startPos_; unsigned int endPos_; BufferId bufferId_; }; class TokenType { public: enum { idShift = 16 }; TokenType() { } TokenType( unsigned int type ) : type_( type ) { } TokenType( TokenType category, unsigned int id ) : type_( category.type_ | id ) { } bool operator ==( TokenType other ) const; bool operator !=( TokenType other ) const; bool operator <( TokenType other ) const; unsigned int id() const; bool isSilent() const; TokenType category() const; TokenType nextCategory() const; unsigned int hash() const; void setSilent(); private: enum { tokenIdMask = 0xffff0000, tokenCategoryMask = 0xfff, tokenCategoryIncrement = 0x1, tokenSilentMask = 0x8000000 }; unsigned int type_; }; class TokenIdManager { public: static unsigned int get( const ConstString &text ); static std::string str( TokenType type ); private: static TokenIdManager &instance(); typedef std::map<ConstString,unsigned int> TokenIds; TokenIds ids_; typedef std::map<unsigned int,std::string> IdTexts; IdTexts texts_; }; enum DefaultTokenType { invalidTokenType = -1, endStream = 0, symbol, lastUsedTokenType }; class TokenTypeManager { public: TokenTypeManager(); static TokenTypeManager &instance(); TokenType add( const ConstString &name, bool isSilent = false ); ConstString typeName( TokenType type ) const; private: void set( TokenType id, const ConstString &name ); typedef std::map<ConstString,TokenType> Types; Types types_; typedef std::map<TokenType,ConstString> Names; Names names_; ConstString unknownName_; TokenType last_; }; inline ConstString tokenTypeName( TokenType type ) { return TokenTypeManager::instance().typeName( type ); } class Token { public: Token( const ConstString &text, TokenType tokenType, TokenLocation location = TokenLocation() ); const ConstString &text() const; const TokenLocation &location() const; TokenType type() const; TokenType category() const; bool isSilent() const; ConstString typeName() const; unsigned int hash() const; bool operator ==( const Token &other ) const; bool operator !=( const Token &other ) const; std::string str() const; private: ConstString text_; TokenLocation location_; TokenType tokenType_; }; typedef std::vector<Token> Tokens; // Inline functions // ////////////////////////////////////////// inline bool TokenType::operator ==( TokenType other ) const { return type_ == other.type_; } inline bool TokenType::operator !=( TokenType other ) const { return type_ != other.type_; } inline bool TokenType::operator <( TokenType other ) const { return type_ < other.type_; } inline unsigned int TokenType::id() const { return type_ & tokenIdMask; } inline bool TokenType::isSilent() const { return (type_ & tokenSilentMask) != 0; } inline void TokenType::setSilent() { type_ |= tokenSilentMask; } inline TokenType TokenType::category() const { return TokenType( type_ & ~tokenIdMask ); } inline TokenType TokenType::nextCategory() const { return category().type_ + tokenCategoryIncrement; } inline unsigned int TokenType::hash() const { return type_; } inline unsigned int TokenIdManager::get( const ConstString &text ) { TokenIds::iterator it = instance().ids_.find( text ); if ( it == instance().ids_.end() ) { unsigned int id = (instance().ids_.size()+1) << TokenType::idShift; instance().ids_.insert( TokenIds::value_type( text, id ) ); instance().texts_.insert( IdTexts::value_type( id, text.str() ) ); return id; } return it->second; } inline std::string TokenIdManager::str( TokenType type ) { if ( instance().texts_.count(type.id()) == 0) return "<unknown>"; return instance().texts_.find(type.id())->second; } inline TokenIdManager & TokenIdManager::instance() { static TokenIdManager manager; return manager; } inline TokenTypeManager::TokenTypeManager() : last_( lastUsedTokenType ) , unknownName_( "?" ) { set( endStream, "end_stream" ); set( symbol, "symbol" ); } inline TokenTypeManager & TokenTypeManager::instance() { static TokenTypeManager manager; return manager; } inline TokenType TokenTypeManager::add( const ConstString &name, bool isSilent ) { Types::iterator it = types_.find( name ); if ( it == types_.end() ) { TokenType type = last_; if ( isSilent ) { type.setSilent(); set( last_, "__silent__." + name.str() ); } else set( last_, name ); last_ = last_.nextCategory(); return type; } return it->second; } inline ConstString TokenTypeManager::typeName( TokenType type ) const { Names::const_iterator it = names_.find( type.category() ); if ( it == names_.end() ) return unknownName_; if ( type.isSilent() ) return it->second.str().substr( 11 ); // "__silent__." return it->second; } inline void TokenTypeManager::set( TokenType id, const ConstString &name ) { types_[name] = id; names_[id] = name; } inline Token::Token( const ConstString &text, TokenType tokenType, TokenLocation location ) : text_( text ) , tokenType_( tokenType ) , location_( location ) { if ( tokenType.category() == TokenType(symbol) && tokenType.id() == 0 ) tokenType_ = TokenType( tokenType.category(), TokenIdManager::get( text ) ); } inline const ConstString & Token::text() const { return text_; } inline const TokenLocation & Token::location() const { return location_; } inline TokenType Token::type() const { return tokenType_; } inline TokenType Token::category() const { return tokenType_.category(); } inline bool Token::isSilent() const { return tokenType_.isSilent(); } inline ConstString Token::typeName() const { return tokenTypeName( tokenType_ ); } inline unsigned int Token::hash() const { return (tokenType_.hash() << 17) + text_.hash(); } inline bool Token::operator ==( const Token &other ) const { return text_ == other.text_ && tokenType_ == other.tokenType_ && location_ == other.location_; } inline bool Token::operator !=( const Token &other ) const { return !( *this == other ); } inline std::string Token::str() const { std::ostringstream os; os << "Token(" << tokenTypeName(tokenType_).str() << ", " << location_.startPos_ << "-" << location_.endPos_ << " = '" << text_.str() << "')"; return os.str(); } } // namespace Parser #endif // PARSER_TOKEN_H_INCLUDED --- NEW FILE: cppparsertest.h --- #ifndef PARSER_PARSERTEST_H_INCLUDED # define PARSER_PARSERTEST_H_INCLUDED # include "cppnodetestbase.h" # include "grammarbuilder.h" # include "parsertesthelper.h" class CppParserTest : public CppNodeTestBase { public: CPPUT_TESTSUITE_BEGIN( CppParserTest ); CPPUT_TEST( testCheckAssertFailIfContainsErrorNode ); CPPUT_TEST( testLiteralExpression ); CPPUT_TEST( testUnqualifiedId ); CPPUT_TEST( testTokenize ); CPPUT_TEST( testQualifiedId ); CPPUT_TEST( testPrimaryExpression ); CPPUT_TEST( testPostFixExpressionSuffix ); CPPUT_TEST( testPostFixExpression ); CPPUT_TEST( testDeleteExpressionParser ); CPPUT_TEST( testNewTypeIdParser ); CPPUT_TEST( testNewExpressionParser ); CPPUT_TEST( testUnaryExpressionParser ); CPPUT_TEST( testPMExpression ); CPPUT_TEST( testLogicalOrExpressionParser ); CPPUT_TEST( testConditionalExpressionParser ); CPPUT_TEST( testAssignmentExpressionParser ); CPPUT_TEST( testExpressionParser ); CPPUT_TEST( testExpressionListParser ); CPPUT_TEST( testConstantExpressionParser ); CPPUT_TEST( testJumpStatementParser ); CPPUT_TEST( testCompoundStatementParser ); CPPUT_TEST( testSelectionStatementParser ); CPPUT_TEST( testExpressionStatementParser ); CPPUT_TEST( testLabelStatementParser ); CPPUT_TEST( testIterationStatementParser ); CPPUT_TEST( testDeclarationStatement ); CPPUT_TEST( testTryBlockParser ); CPPUT_TEST( testStatementParser ); CPPUT_TEST( testExceptionSpecifierParser ); CPPUT_TEST( testPtrOperatorParser ); CPPUT_TEST( testParameterDeclarationParser ); CPPUT_TEST( testParameterDeclarationClauseParser ); CPPUT_TEST( testAbstractDeclaratorParser ); CPPUT_TEST( testDirectDeclaratorParser ); CPPUT_TEST( testDeclaratorParser ); CPPUT_TEST( testInitializerParser ); CPPUT_TEST( testInitDeclaratorParser ); CPPUT_TEST( testDirectAbstractDeclaratorFnSuffixParser ); CPPUT_TEST( testDirectAbstractDeclaratorArraySuffixParser ); CPPUT_TEST( testFunctionReturnTypeParser ); CPPUT_TEST( testFunctionDefinitionStartParser ); CPPUT_TEST( testFunctionDefinitionParser ); CPPUT_TEST( testTypeIdParser ); CPPUT_TEST( testASMDefinitionParser ); CPPUT_TEST( testNamespaceAliasDefinitionParser ); CPPUT_TEST( testUsingDeclarationParser ); CPPUT_TEST( testUsingDirectiveParser ); CPPUT_TEST( testNamespaceDefinitionParser ); CPPUT_TEST( testSimpleTypeSpecifierParser ); CPPUT_TEST( testEnumSpecifierParser ); CPPUT_TEST( testLinkageSpecificationParser ); CPPUT_TEST( testElaboratedTypeSpecifierParser ); CPPUT_TEST( testTypeSpecifierSeqParser ); CPPUT_TEST( testWorkAroundTypeSpecifierParser ); CPPUT_TEST( testDeclSpecifiersParser ); CPPUT_TEST( testSimpleDeclarationParser ); CPPUT_TEST( testDeclarationParser ); CPPUT_TEST( testPureSpecifier ); CPPUT_TEST( testBaseClauseParser ); CPPUT_TEST( testClassHeadParser ); CPPUT_TEST( testMemInitializer ); CPPUT_TEST( testCtorInitializer ); CPPUT_TEST( testMemberDeclarationParser ); CPPUT_TEST( testMemberSpecificationParser ); CPPUT_TEST( testClassSpecifierParser ); CPPUT_TEST( testOperatorFunctionIdParser ); CPPUT_TEST( testConversionFunctionIdParser ); CPPUT_TEST( testTemplateParameter ); CPPUT_TEST( testTemplateDeclaration ); CPPUT_TEST( testTranslationUnit ); CPPUT_TESTSUITE_END(); void setUp(); void tearDown(); void testTokenize(); void testCheckAssertFailIfContainsErrorNode(); // expressions void testLiteralExpression(); void testUnqualifiedId(); void testQualifiedId(); void testPrimaryExpression(); void testPostFixExpressionSuffix(); void testPostFixExpression(); void testDeleteExpressionParser(); void testNewTypeIdParser(); void testNewExpressionParser(); void testUnaryExpressionParser(); void testPMExpression(); void testLogicalOrExpressionParser(); void testConditionalExpressionParser(); void testAssignmentExpressionParser(); void testExpressionParser(); void testExpressionListParser(); void testConstantExpressionParser(); // statements void testJumpStatementParser(); void testCompoundStatementParser(); void testSelectionStatementParser(); void testExpressionStatementParser(); void testLabelStatementParser(); void testIterationStatementParser(); void testDeclarationStatement(); void testTryBlockParser(); void testStatementParser(); // declarators void testExceptionSpecifierParser(); void testPtrOperatorParser(); void testParameterDeclarationParser(); void testParameterDeclarationClauseParser(); void testAbstractDeclaratorParser(); void testDirectDeclaratorParser(); void testDeclaratorParser(); void testInitializerParser(); void testInitDeclaratorParser(); void testDirectAbstractDeclaratorFnSuffixParser(); void testDirectAbstractDeclaratorArraySuffixParser(); void testFunctionReturnTypeParser(); void testFunctionDefinitionStartParser(); void testFunctionDefinitionParser(); void testTypeIdParser(); // Declarations void testASMDefinitionParser(); void testNamespaceAliasDefinitionParser(); void testUsingDeclarationParser(); void testUsingDirectiveParser(); void testNamespaceDefinitionParser(); void testSimpleTypeSpecifierParser(); void testEnumSpecifierParser(); void testLinkageSpecificationParser(); void testElaboratedTypeSpecifierParser(); void testTypeSpecifierSeqParser(); void testWorkAroundTypeSpecifierParser(); void testDeclSpecifiersParser(); void testSimpleDeclarationParser(); void testDeclarationParser(); // Classes void testPureSpecifier(); void testBaseClauseParser(); void testClassHeadParser(); void testMemInitializer(); void testCtorInitializer(); void testMemberDeclarationParser(); void testMemberSpecificationParser(); void testClassSpecifierParser(); void testOperatorFunctionIdParser(); void testConversionFunctionIdParser(); // Templates void testTemplateParameter(); void testTemplateDeclaration(); // Program void testTranslationUnit(); private: Parser::NodePtr fundamentalTypeSpecifierNode( const std::string &type1, int spaces = 0 ); Parser::NodePtr fundamentalTypeNode( const std::string &type1, int spaces = 0 ); Parser::NodePtr unqualifiedIdNode( const std::string &name, int spaces = 0 ); Parser::NodePtr unqualifiedIdExpressionNode( const std::string &name, int spaces = 0 ); Parser::NodePtr declaratorIdNode( const std::string &id, int spaces = 0 ); Parser::NodePtr intLiteralNode( const std::string &value ); Parser::NodePtr floatLiteralNode( const std::string &value ); void checkGrammarParserMatch( const std::string &input, const std::string &parserName, ParserTesting::TraceFlag flag = ParserTesting::noParseTrace ); void checkGrammarParserMatchPartial( const std::string &input, const std::string &parserName, int expectedRemainingToken, ParserTesting::TraceFlag flag = ParserTesting::noParseTrace ); void checkGrammarParserMatchFail( const std::string &input, const std::string &parserName, ParserTesting::TraceFlag flag = ParserTesting::noParseTrace ); void checkGrammarParserProducedTree( const std::string &input, const std::string &parserName, const Parser::NodePtr &expected, ParserTesting::TraceFlag flag = ParserTesting::noParseTrace ); void checkGrammarParserProducedPartialTree( const std::string &input, const std::string &parserName, const Parser::NodePtr &expected, int expectedRemaining, ParserTesting::TraceFlag flag = ParserTesting::noParseTrace ); void checkGrammarParserProducedTreeInPlace( const std::string &input, const std::string &parserName, const Parser::NodePtr &expected, ParserTesting::TraceFlag flag = ParserTesting::matchedTrace ); static boost::shared_ptr<Parser::GrammarBuilder> builder_; static bool initializationFailed_; }; #endif // PARSER_PARSERTEST_H_INCLUDED --- NEW FILE: cppparsertest.cpp --- #include "cppparsertest.h" #include <rfta/cppparser/cppparser.h> #include "testtools.h" #include <algorithm> #include <fstream> // Notes: when debugging a unit test, set the trace flag // to Parser::matchedTrace: // CPPPARSER_ASSERT_MATCH( "(this)", "postfix_expression", Parser::matchedTrace ); // Trace are disabled by default, there just way to big at high-level... CPPUT_REGISTER_SUITE_TO_DEFAULT( CppParserTest ); using namespace ParserTesting; #define CPPPARSER_ASSERT_MATCH \ [...1609 lines suppressed...] // " void f() {}" // "};", // "translation_unit", // testNode( "translation_unit" ) ); // test error recovery CPPPARSER_ASSERT_TREE( "struct S { };" "WEIRD_MACRO(12)" "int x;" "struct X {};" , "translation_unit", testNode( "translation_unit", testNode( "declarations", jokerNode("simple_declaration"), testNode("declaration_error", id_t("WEIRD_MACRO"), "(",int_t("12"),")", "int", spaces_t(1), id_t("x"), ";" ), jokerNode("simple_declaration") ) ) ); } --- NEW FILE: commandstreamtest.h --- #ifndef PARSER_COMMANDSTREAMTEST_H_INCLUDED # define PARSER_COMMANDSTREAMTEST_H_INCLUDED # include "nodetreetestbase.h" # include "commandstream.h" # include <boost/shared_ptr.hpp> class CommandStreamTest : public NodeTreeTestBase { public: CPPUT_TESTSUITE_BEGIN( CommandStreamTest ); CPPUT_TEST( testMakeEmptyNodeTree ); CPPUT_TEST( testLinearTokenStream ); CPPUT_TEST( testNewNodeCommand ); CPPUT_TEST( testRenameNodeCommand ); CPPUT_TEST( testRenameLastChildNodeCommand ); CPPUT_TEST( testSaveRestoreCurrentNodeCommand ); CPPUT_TEST( testMakePenultimateChildOfLast ); CPPUT_TEST( testRemoveLastChildCommand ); CPPUT_TEST( testPushPopState ); CPPUT_TESTSUITE_END(); void setUp(); void tearDown(); void testMakeEmptyNodeTree(); void testLinearTokenStream(); void testNewNodeCommand(); void testRenameNodeCommand(); void testRenameLastChildNodeCommand(); void testSaveRestoreCurrentNodeCommand(); void testMakePenultimateChildOfLast(); void testRemoveLastChildCommand(); void testPushPopState(); private: boost::shared_ptr<Parser::CommandStream> stream_; }; #endif // PARSER_COMMANDSTREAMTEST_H_INCLUDED --- NEW FILE: cpplexer.h --- #ifndef PARSER_CPPLEXER_H_INCLUDED # define PARSER_CPPLEXER_H_INCLUDED # include <boost/shared_ptr.hpp> # include <string> namespace Parser { namespace CppLexerMatchType { enum MatchType { matchSpaces = 0, matchIdentifier, matchString, matchCharacter, matchInteger, matchFloat, matchSymbol, matchCppComment, matchCComment, matchPreprocessorDirective, matchError }; }; class CppLexerMatchHandler { public: virtual ~CppLexerMatchHandler() { } virtual void setTokenizedText( const char *begin, const char *end ) = 0; virtual void matched( unsigned int startPos, unsigned int endPos, CppLexerMatchType::MatchType type ) = 0; }; class CppLexerMatchHandlerBase : public CppLexerMatchHandler { public: CppLexerMatchHandlerBase() : begin_( 0 ) , end_( 0 ) { } const char *tokenizedTextAt( unsigned int pos ) const { return begin_ + pos; } const std::string tokenizedStringAt( unsigned int startPos, unsigned int endPos ) const { return std::string( tokenizedTextAt( startPos ), tokenizedTextAt( endPos ) ); } public: // overridden from CppLexerMatchHandler void setTokenizedText( const char *begin, const char *end ) { begin_ = begin; end_ = end; } virtual void matched( unsigned int startPos, unsigned int endPos, CppLexerMatchType::MatchType type ) = 0; private: const char *begin_; const char *end_; }; class CppLexer { public: virtual ~CppLexer() { } virtual void tokenize( const char *inputStart, const char *inputEnd, CppLexerMatchHandler &handler ) = 0; }; typedef boost::shared_ptr<CppLexer> CppLexerPtr; CppLexerPtr makeCppLexer(); CppLexerPtr makeCppMacroLexer(); } // namespace Parser #endif // PARSER_CPPLEXER_H_INCLUDED --- NEW FILE: preprocessortest.h --- #ifndef PARSER_PREPROCESSORTEST_H_INCLUDED # define PARSER_PREPROCESSORTEST_H_INCLUDED # include "cppnodetestbase.h" class PreprocessorTest : public CppNodeTestBase { public: CPPUT_TESTSUITE_BEGIN( PreprocessorTest ); CPPUT_TEST( testNoMacro ); CPPUT_TEST( testMacroDefinition ); CPPUT_TEST( testMacroNoParameterExpansion ); CPPUT_TEST( testMultiLineNoParameterMacroExpansion ); CPPUT_TEST( testBracedMacroNoParameterExpansion ); CPPUT_TEST( testOneParameterMacroExpansion ); CPPUT_TEST( testThreeParametersMacroExpansion ); CPPUT_TEST( testNestedMacrosExpansion ); CPPUT_TEST( testMacroAsMacroParameter ); CPPUT_TESTSUITE_END(); void setUp(); void tearDown(); void testNoMacro(); void testMacroDefinition(); void testMacroNoParameterExpansion(); void testMultiLineNoParameterMacroExpansion(); void testBracedMacroNoParameterExpansion(); void testOneParameterMacroExpansion(); void testThreeParametersMacroExpansion(); void testNestedMacrosExpansion(); void testMacroAsMacroParameter(); private: void checkPreprocess( const std::string &input, const Parser::Tokens &expected ); }; #endif // PARSER_PREPROCESSORTEST_H_INCLUDED --- NEW FILE: cppnodetestbase.cpp --- #include "cppnodetestbase.h" #include <rfta/cppparser/cppparser.h> const Parser::Token & CppNodeTestBase::id_t( const std::string &text ) { return addToken( Parser::Token( text, Parser::CppParser::tkIdentifier ) ); } const Parser::Token & CppNodeTestBase::spaces_t( int count, char separator ) { return addToken( Parser::Token( std::string(count, separator), Parser::CppParser::tkSpaces ) ); } const Parser::Token & CppNodeTestBase::symb_t( const std::string &text ) { return addToken( Parser::Token( text, Parser::CppParser::tkSymbol ) ); } const Parser::Token & CppNodeTestBase::int_t( const std::string &text ) { return addToken( Parser::Token( text, Parser::CppParser::tkInteger ) ); } const Parser::Token & CppNodeTestBase::string_t( const std::string &text ) { return addToken( Parser::Token( "\"" + text + "\"", Parser::CppParser::tkString ) ); } const Parser::Token & CppNodeTestBase::char_t( const std::string &text ) { return addToken( Parser::Token( "'" + text + "'", Parser::CppParser::tkCharacter ) ); } const Parser::Token & CppNodeTestBase::float_t( const std::string &text ) { return addToken( Parser::Token( text, Parser::CppParser::tkFloat ) ); } const Parser::Token & CppNodeTestBase::error_t( const std::string &text ) { return addToken( Parser::Token( text, Parser::CppParser::tkError ) ); } --- NEW FILE: cppnodetestbase.h --- #ifndef PARSER_CPPNODETESTBASE_H_INCLUDED # define PARSER_CPPNODETESTBASE_H_INCLUDED # include "nodetreetestbase.h" # include "tokentesthelper.h" class CppNodeTestBase : public NodeTreeTestBase { public: const Parser::Token &id_t( const std::string &text ); const Parser::Token &spaces_t( int count, char separator = ' ' ); const Parser::Token &symb_t( const std::string &text ); const Parser::Token &string_t( const std::string &text ); const Parser::Token &char_t( const std::string &text ); const Parser::Token &int_t( const std::string &text ); const Parser::Token &float_t( const std::string &text ); const Parser::Token &error_t( const std::string &text ); }; #endif // PARSER_CPPNODETESTBASE_H_INCLUDED --- NEW FILE: cpp_grammar.txt --- # Syntax: # '#' any on the line for one line comment # $token_type matches 1 occurence of the specified token type # ( @string matches a string, @float a float...) # '...' matches 1 occurrence of the 'symbol' token type with the specified text # %'... ...' matches 1 occurrence of one of the symbol specified in the text. # Symbols must be separated by exactly one space ( %'true false' will # match either the token symbol 'true' or 'false'. # @node_name( ... ) braced expression tokens become children of a node which # name is specified by 'node_name'. # $token_type( '...' ) matches 1 occurrence of the specified token with # the specified type. # list( expression, separator_expression ) predefined parametrized parser # :rename_last_node( '...' ) # parser_name = ... ';' declare a parser with the specified name matches the expression # on the right side of '='. A parser name may be declared only once # parser_name(.p1,.p2,...) = ... declare a parametrized parser with the specified name # matches the expression on the right side of '='. A parser name may # be declared only once. '.p1' are the expression passed as parameter # of the parser. # parser_name matches the expression specified in the declaration of 'parser_name'. # A parser may be referenced before being declared, but all references # must be resolved. # parser_name(p1,p2,...) matched the expression specified in the declaration of # the parametrized parser 'parser_name'. p1, p2, ... are passed as parameters. # ... ... matches the specified sequence. # ... || ... matches either the left side expression or the right side expression. # All expressions are tested for matching and the longuest is kept as # a matched (the one that matched the most important number of tokens). # ... | ... matches either the left side expression or the right side expression. # If the left side expression is matched, then the right side expression # is not tested for matching. # '[' ... ']' matches the braced expression. # ?( ... ) matches 0 or 1 occurence of the braced expression # +( ... ) matches 1 or more occurrences of the braced expression # *( ... ) matches 0 or more occurrences of the braced expression # %('... ...' '... ...') matches 1 occurrence of one of the symbol specified in the text. # Symbols must be separated by exactly one space ( %'true false' will # match either the token symbol 'true' or 'false'. # !( ... ) fail if the inner expression is matched # Operators priority: # sequence, longuest alternative, first alternative # # Commands: # :node( name, matcher ) create a new node which children are the specified matcher production # :rename( name ) rename the 'current' node # :rename_last_child( name ) rename the last child node # :new_node(name) create a new node with the specified name. Next matched token will be first child. # :save_node() push the current node on the memory stack # :restore_node() pop the last node from the memory stack # :make_penultimate_node_child_of_last() make the penultimate node child of the last node # :remove_last_child remove the last node ::TokenType $symbol $spaces $identifier $string $character $integer $float $cpp_comment $c_comment $error ::Grammar # Additional commands available: # :cpp_block_error_recovery(): skip all tokens until the end of the statement is found. # The end of the statement is: # - closing of the current declaration block (non nested '}' found) # - a non nested ';' found # - no more token available (end of input) list(.item,.sep) = .item *(.sep .item); list_min2(.item,.sep) = .item .sep .item *(.sep .item); binary_operator(.left_operand,.right_operand_node) = .left_operand *( .right_operand_node :make_penultimate_node_child_of_last() ) ; make_right_operand(.name,.operand) = :node(.name, .operand ); # Used parse sequence where the first element is optional and can not be distinguished # from the mandatory part. optional_alternative(.optional, .mandatory) = .optional .mandatory | .mandatory; # ############################## A.4: Program ############################ # A.4, C++PL3 p.798 translation_unit = :node( 'translation_unit', declaration_seq ); # ############################## A.5: Expressions ############################ # A.5, C++PL3 p.798-802 literal_expression = :node('literal', $integer | '0' | $character | $string | $float | %'true false' ); id = $identifier; namespace_name = id; class_or_namespace_name = class_name; # | namespace_name; template_name_specifier = 'template' nested_name_specifier; nested_name_specifier = +( class_or_namespace_name '::' ?(template_name_specifier) ); # Notes: qualified_id can not include 'template' => A::template B::zozo is not parsed (IT SHOULD BE) qualified_id = :node( 'qualified_id', ?('::') nested_name_specifier ?('template') unqualified_id | [ '::' [ id | operator_function_id | conversion_function_id ] ] ); # Notes: template id not included # destructor_ref may be parsed as such while it is not a reference to a destructor (overloaded ~ operator & ()) unqualified_id = id | operator_function_id | conversion_function_id | :node( 'destructor_ref', '~' id ??( '(' ')' ) ) ; id_expression = qualified_id || :node( 'unqualified_id', unqualified_id ) ; # C++ Standard p65 primary_expression = literal_expression | :node('this_ref', 'this' ) | :node('braced_expr', '(' expression ')' ) | :node('id_expression', id_expression ) ; # Notes: not included in postfix_expression_p: # typename with template in scope # # postfix_expression_p as been modified to avoid the infinite left recursion. This recursion has been # moved to multiple 'optional' suffixes # array_operator_suffix = :node('array_index', '[' expression ']'); call_operator_suffix = :node('call_parameters', '(' ?( expression_list ) ')'); # Notes: missing template in scope case pseudo_destructor_name = :node( 'pseudo_destructor_name', ?('::') ?(nested_name_specifier) ?(class_name '::') '~' id ); # type_name accessed_member = pseudo_destructor_name | [ ?( 'template' ) ?('::') id_expression ] ; instance_accessor = %'. ->'; member_access_suffix = :node('accessed_member', instance_accessor accessed_member ); post_incdec_suffix = :node( 'post_operator', %'++ --' ); cast_keywords = %'dynamic_cast static_cast reinterpret_cast const_cast'; cppcast_expression = :node('cppcast_expression', cast_keywords '<' type_id '>' '(' expression ')' ); type_id_expression = :node('typeid_expression', 'typeid' '(' [type_id | expression] ')' ); # Notes: because of the typeless parsing a function call can not be distinguished from a # functional type conversion. In the case of a function call, the name of the function will be found in the # type id. call_or_conversion_expression = :node( 'call_or_conversion_expression', [ ['typename' ?('::') nested_name_specifier id] | simple_type_specifier ] '(' ?( expression_list ) ')' ); #Notes: template_id construction is missing postfix_expression = binary_operator( cppcast_expression | type_id_expression | call_or_conversion_expression | primary_expression, make_right_operand( 'array_access', array_operator_suffix ) | make_right_operand( 'call', call_operator_suffix ) | make_right_operand( 'member_access', member_access_suffix ) | make_right_operand( 'post_incdec', post_incdec_suffix ) ); cast_expression = unary_expression | :node('cast_expression', '(' type_id ')' :node('casted_expression', cast_expression ) ) ; delete_expression = :node( 'delete_operator', ?( '::') 'delete' ?( '[' ']' ) cast_expression ) ; new... [truncated message content] |
Update of /cvsroot/cpptool/CppParser/src/pycppparser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9448/src/pycppparser Added Files: conststring.cpp cppparser.cpp cppparserfacade.cpp main.cpp node.cpp pycppparser.vcproj pyenumerator.h token.cpp Log Message: * made a library out of the c++ parser (cppparser) * exposed the c++ parser to python (pycppparser) * migrating refactoring framework to python (pyrfta) --- NEW FILE: main.cpp --- // Include ===================================================================== #include <boost/python/module.hpp> // Exports ===================================================================== void Export_cppparser_Node(); void Export_cppparser_Token(); void Export_cppparser_CppParser(); void Export_cppparser_ConstString(); void Export_cppparser_CppParserFacade(); // Module ====================================================================== BOOST_PYTHON_MODULE(pycppparser_) { Export_cppparser_Node(); Export_cppparser_Token(); Export_cppparser_CppParser(); Export_cppparser_ConstString(); Export_cppparser_CppParserFacade(); } --- NEW FILE: node.cpp --- // Boost Includes ============================================================== #include <boost/python.hpp> #include <boost/cstdint.hpp> // Includes ==================================================================== #include <rfta/cppparser/node.h> // Using ======================================================================= using namespace boost::python; // Declarations ================================================================ namespace py { BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Node_treeStr_overloads, treeStr, 0, 2) Parser::NodePtr Node_parent( const Parser::Node &node ) { return Parser::NodePtr( node.parent() ); } Parser::NodePtr Node_previousSibling( const Parser::Node &node ) { return Parser::NodePtr( node.getPreviousSibling() ); } Parser::NodePtr Node_nextSibling( const Parser::Node &node ) { return Parser::NodePtr( node.getNextSibling() ); } Parser::NodePtr NodeEnumerator_next( Parser::NodeEnumerator &e ) { if ( !e.hasNext() ) boost::python::objects::stop_iteration_error(); // in object/iterator_core.hpp return e.nextPtr(); } Parser::NodeEnumerator NodeEnumerator_iter( const Parser::NodeEnumerator &e ) { return e; } }// namespace py // Module ====================================================================== void Export_cppparser_Node() { class_< Parser::Node, Parser::NodePtr, boost::noncopyable >("Node", no_init) .def( "enumChildren", &Parser::Node::enumChildren ) .def( "previousSibling", &py::Node_previousSibling ) .def( "nextSibling", &py::Node_nextSibling ) .def( "hasChildren", &Parser::Node::hasChildren ) .def( "childCount", &Parser::Node::getChildCount ) .def( "childAt", &Parser::Node::childAt ) .def( "hasValidToken", &Parser::Node::hasValidToken ) .def( "treeStr", &Parser::Node::treeStr, py::Node_treeStr_overloads( args("margin","indent") ) ) .def( "__repr__", &Parser::Node::str ) .add_property( "location", make_function( &Parser::Node::location, return_value_policy<copy_const_reference>() ) ) .add_property( "name", make_function( &Parser::Node::name, return_value_policy<copy_const_reference>() ) ) .add_property( "text", make_function( &Parser::Node::text, return_value_policy<copy_const_reference>() ) ) .add_property( "token", make_function( &Parser::Node::token, return_value_policy<copy_const_reference>() ) ) .add_property( "type", &Parser::Node::type ) .add_property( "parent", &py::Node_parent ) ; class_< Parser::NodeEnumerator >( "NodeEnumerator", init<const Parser::NodePtr&>() ) .def( "next", &py::NodeEnumerator_next ) .def( "__iter__", &py::NodeEnumerator_iter ) ; } --- NEW FILE: cppparser.cpp --- // Boost Includes ============================================================== #include <boost/python.hpp> #include <boost/cstdint.hpp> // Includes ==================================================================== #include <rfta/cppparser/cppparser.h> // Using ======================================================================= using namespace boost::python; // Declarations ================================================================ namespace py { //BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Ogre_Vector3_randomDeviant_overloads_1_2, randomDeviant, 1, 2) }// namespace py // Module ====================================================================== void Export_cppparser_CppParser() { scope().attr( "TK_SPACES" ) = Parser::CppParser::tkSpaces; scope().attr( "TK_IDENTIFIER" ) = Parser::CppParser::tkIdentifier; scope().attr( "TK_STRING" ) = Parser::CppParser::tkString; scope().attr( "TK_CHARACTER" ) = Parser::CppParser::tkCharacter; scope().attr( "TK_INTEGER" ) = Parser::CppParser::tkInteger; scope().attr( "TK_FLOAT" ) = Parser::CppParser::tkFloat; scope().attr( "TK_CPP_COMMENT" ) = Parser::CppParser::tkCppComment; scope().attr( "TK_C_COMMENT" ) = Parser::CppParser::tkCComment; scope().attr( "TK_PREPROCESSOR_DIRECTIVE" ) = Parser::CppParser::tkPreprocessorDirective; scope().attr( "TK_SYMBOL" ) = Parser::CppParser::tkSymbol; scope().attr( "TK_ERROR" ) = Parser::CppParser::tkError; } --- NEW FILE: pycppparser.vcproj --- <?xml version="1.0" encoding="Windows-1252"?> <VisualStudioProject ProjectType="Visual C++" Version="7.10" Name="pycppparser" ProjectGUID="{481DC14A-E1BD-4146-8789-113C962EDA21}" RootNamespace="pycppparser" Keyword="Win32Proj"> <Platforms> <Platform Name="Win32"/> </Platforms> <Configurations> <Configuration Name="Debug|Win32" OutputDirectory="../../build/pycppparser/debug" IntermediateDirectory="../../build/pycppparser/debug" ConfigurationType="2" CharacterSet="2"> <Tool Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="../../include" PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_MT;_DLL;_WINDLL;_MBCS" MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="3" ForceConformanceInForLoopScope="TRUE" RuntimeTypeInfo="TRUE" UsePrecompiledHeader="0" WarningLevel="3" Detect64BitPortabilityProblems="TRUE" DebugInformationFormat="4" DisableSpecificWarnings="4267;4244;4018"/> <Tool Name="VCCustomBuildTool"/> <Tool Name="VCLinkerTool" AdditionalDependencies="rfta_cppparser_vc7_mdd.lib boost_python_debug.lib" OutputFile="$(OutDir)/pycppparser_.pyd" LinkIncremental="2" AdditionalLibraryDirectories="../../libs/vc71/boost;../../build/cppparser/debug;../../build/cpput/debug" GenerateDebugInformation="TRUE" ProgramDatabaseFile="$(OutDir)/pycppparser.pdb" SubSystem="2" ImportLibrary="$(OutDir)/pycppparser.lib" TargetMachine="1"/> <Tool Name="VCMIDLTool"/> <Tool Name="VCPostBuildEventTool" Description="updating pyrfta .pyd" CommandLine="XCOPY /Y $(TargetPath) ..\pyrfta\$(TargetFileName)"/> <Tool Name="VCPreBuildEventTool"/> <Tool Name="VCPreLinkEventTool"/> <Tool Name="VCResourceCompilerTool"/> <Tool Name="VCWebServiceProxyGeneratorTool"/> <Tool Name="VCXMLDataGeneratorTool"/> <Tool Name="VCWebDeploymentTool"/> <Tool Name="VCManagedWrapperGeneratorTool"/> <Tool Name="VCAuxiliaryManagedWrapperGeneratorTool"/> </Configuration> <Configuration Name="Release|Win32" OutputDirectory="../../build/pycppparser/release" IntermediateDirectory="../../build/pycppparser/release" ConfigurationType="2" CharacterSet="2"> <Tool Name="VCCLCompilerTool" AdditionalIncludeDirectories="../../include" PreprocessorDefinitions="BOOST_PYTHON_STATIC_LINK" RuntimeLibrary="0" ForceConformanceInForLoopScope="TRUE" RuntimeTypeInfo="TRUE" UsePrecompiledHeader="0" WarningLevel="3" Detect64BitPortabilityProblems="TRUE" DebugInformationFormat="3" DisableSpecificWarnings="4267;4244;4018"/> <Tool Name="VCCustomBuildTool"/> <Tool Name="VCLinkerTool" AdditionalDependencies="cppparser.lib cpput_vc6_mrs.lib libboost_python.lib" OutputFile="$(OutDir)/pycppparser.dll" LinkIncremental="1" AdditionalLibraryDirectories="../../libs/vc71/boost;../../build/cppparser/release;../../build/cpput/release" GenerateDebugInformation="TRUE" SubSystem="2" OptimizeReferences="2" EnableCOMDATFolding="2" ImportLibrary="$(OutDir)/pycppparser.lib" TargetMachine="1"/> <Tool Name="VCMIDLTool"/> <Tool Name="VCPostBuildEventTool"/> <Tool Name="VCPreBuildEventTool"/> <Tool Name="VCPreLinkEventTool"/> <Tool Name="VCResourceCompilerTool"/> <Tool Name="VCWebServiceProxyGeneratorTool"/> <Tool Name="VCXMLDataGeneratorTool"/> <Tool Name="VCWebDeploymentTool"/> <Tool Name="VCManagedWrapperGeneratorTool"/> <Tool Name="VCAuxiliaryManagedWrapperGeneratorTool"/> </Configuration> </Configurations> <References> </References> <Files> <Filter Name="interface" Filter=""> <File RelativePath="..\..\include\rfta\cppparser\conststring.h"> </File> <File RelativePath="..\..\include\rfta\cppparser\cppparser.h"> </File> <File RelativePath="..\..\include\rfta\cppparser\cppparserfacade.h"> </File> <File RelativePath="..\..\include\rfta\cppparser\cppparsersettings.h"> </File> <File RelativePath="..\..\include\rfta\cppparser\forwards.h"> </File> <File RelativePath="..\..\include\rfta\cppparser\node.h"> </File> <File RelativePath="..\..\include\rfta\cppparser\nodeprocessor.h"> </File> <File RelativePath="..\..\include\rfta\cppparser\tests.h"> </File> <File RelativePath="..\..\include\rfta\cppparser\token.h"> </File> </Filter> <File RelativePath=".\conststring.cpp"> </File> <File RelativePath=".\cppparser.cpp"> </File> <File RelativePath=".\cppparserfacade.cpp"> </File> <File RelativePath=".\main.cpp"> </File> <File RelativePath=".\node.cpp"> </File> <File RelativePath=".\pyenumerator.h"> </File> <File RelativePath=".\token.cpp"> </File> </Files> <Globals> </Globals> </VisualStudioProject> --- NEW FILE: cppparserfacade.cpp --- // Boost Includes ============================================================== #include <boost/python.hpp> #include <boost/cstdint.hpp> // Includes ==================================================================== #include <rfta/cppparser/cppparserfacade.h> #include <rfta/cppparser/node.h> // Using ======================================================================= using namespace boost::python; // Declarations ================================================================ namespace py { class SimpleSettings : public Parser::CppParserSettings { public: SimpleSettings( const std::string &path ) : path_( path ) { } public: // overridden from Parser::CppParserSettings std::string grammarPath() const { return path_; } private: std::string path_; }; class CppParserWithSettings { public: CppParserWithSettings( const SimpleSettings &settings ) : settings_( settings ) , facade_( settings_ ) { } Parser::NodePtr parse( const std::string &input ) { return facade_.parse( input ); } private: // order is important SimpleSettings settings_; Parser::CppParserFacade facade_; }; boost::shared_ptr<CppParserWithSettings> cppparser_CppParserFacade_make( const std::string &grammarPath ) { SimpleSettings settings( grammarPath ); return boost::shared_ptr<CppParserWithSettings>( new CppParserWithSettings( settings ) ); } }// namespace py // Module ====================================================================== void Export_cppparser_CppParserFacade() { class_< py::CppParserWithSettings >( "CppParserFacade", no_init ) .def( "parse", &py::CppParserWithSettings::parse ) ; register_ptr_to_python< boost::shared_ptr< py::CppParserWithSettings > >(); def( "makeParser", &py::cppparser_CppParserFacade_make ); } --- NEW FILE: token.cpp --- // Boost Includes ============================================================== #include <boost/python.hpp> #include <boost/cstdint.hpp> // Includes ==================================================================== #include <rfta/cppparser/token.h> // Using ======================================================================= using namespace boost::python; // Declarations ================================================================ namespace py { //BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Ogre_Vector3_randomDeviant_overloads_1_2, randomDeviant, 1, 2) std::string cppparser_TokenType_name( Parser::TokenType type ) { return Parser::tokenTypeName( type ).str(); } }// namespace py // Module ====================================================================== void Export_cppparser_Token() { class_< Parser::TokenLocation >( "TokenLocation", init<>() ) .def( init<unsigned int,unsigned int,unsigned int>() ) .def( "isValid", &Parser::TokenLocation::isValid ) .def( self == self ) .def( self != self ) .add_property( "length", &Parser::TokenLocation::length ) .def_readwrite( "startPos", &Parser::TokenLocation::startPos_ ) .def_readwrite( "endPos", &Parser::TokenLocation::endPos_ ) .def_readwrite( "bufferId", &Parser::TokenLocation::bufferId_ ) ; class_< Parser::TokenType >( "TokenType", init<>() ) .def( init<unsigned int>() ) .def( init<Parser::TokenType, unsigned int>() ) .def( self == self ) .def( self != self ) .def( self < self ) .def( "__hash__", &Parser::TokenType::hash ) .def( "__repr__", &py::cppparser_TokenType_name ) .add_property( "id", &Parser::TokenType::id ) .add_property( "isSilent", &Parser::TokenType::isSilent, &Parser::TokenType::setSilent ) .add_property( "category", &Parser::TokenType::id ) .add_property( "name", &py::cppparser_TokenType_name ) ; class_< Parser::Token >("Token", init< Parser::ConstString , Parser::TokenType , optional<Parser::TokenLocation> >() ) .def( init< const Parser::Token &>() ) .add_property( "text", make_function( &Parser::Token::text, return_value_policy<copy_const_reference>() ) ) .add_property( "location", make_function( &Parser::Token::location, return_value_policy<copy_const_reference>() ) ) .add_property( "type", &Parser::Token::type ) .add_property( "category", &Parser::Token::category ) .add_property( "isSilent", &Parser::Token::isSilent ) .add_property( "typeName", &Parser::Token::typeName ) .def( self == self ) .def( self != self ) .def( "__hash__", &Parser::Token::hash ) ; } --- NEW FILE: conststring.cpp --- // Boost Includes ============================================================== #include <boost/python.hpp> #include <boost/cstdint.hpp> // Includes ==================================================================== #include <rfta/cppparser/conststring.h> // Using ======================================================================= using namespace boost::python; // Declarations ================================================================ namespace py { struct ConstStringToPython { static PyObject *convert( const Parser::ConstString &s ) { return PyString_FromString( s.c_str() ); } }; }// namespace py // Module ====================================================================== void Export_cppparser_ConstString() { to_python_converter<Parser::ConstString, py::ConstStringToPython>(); implicitly_convertible<std::string,Parser::ConstString>(); } --- NEW FILE: pyenumerator.h --- #ifndef PYCPPPARSER_PYENUMERATOR_H_INCLUDED # define PYCPPPARSER_PYENUMERATOR_H_INCLUDED #include <boost/python.hpp> template<typename EnumeratorType> class EnumeratorDeclarator { public: typedef typename EnumeratorType::Type ValueType; EnumeratorDeclarator( const std::string &className ) { boost::python::class_< EnumeratorDeclarator >( className.c_str(), no_init ) .def( "next", &next ) .def( "__iter__", &iter ) ; } static ValueType next( EnumeratorType &iterator ) { if ( !iterator.hasNext() ) boost::python::objects::stop_iteration_error(); // in object/iterator_core.hpp return iterator.nextPtr(); } static IteratorType iter( const IteratorType &iterator ) { return iterator; } }; #endif // PYCPPPARSER_PYENUMERATOR_H_INCLUDED |