Ignore:
Timestamp:
Sep 18, 2017, 1:25:03 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
698ec72
Parents:
acdfb45
Message:

Convert CodeGenerator? to PassVisitor?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.h

    racdfb45 r9857e8d  
    2121
    2222#include "Common/Indenter.h"      // for Indenter
     23#include "Common/PassVisitor.h"   // for PassVisitor
    2324#include "SynTree/Declaration.h"  // for DeclarationWithType (ptr only), Fun...
    2425#include "SynTree/Visitor.h"      // for Visitor
     
    2627
    2728namespace CodeGen {
    28         class CodeGenerator : public Visitor {
    29           public:
    30                 static int tabsize;
     29        struct CodeGenerator : public WithShortCircuiting, public WithVisitorRef<CodeGenerator> {
     30          static int tabsize;
    3131
    3232                CodeGenerator( std::ostream &os, bool pretty = false, bool genC = false, bool lineMarks = false );
     
    3434                CodeGenerator( std::ostream &os, char *, int indent = 0, bool infun = false );
    3535
     36                //*** Turn off visit_children for all nodes
     37                void previsit( BaseSyntaxNode * );
     38
     39                //*** Error for unhandled node types
     40                void postvisit( BaseSyntaxNode * );
     41
    3642                //*** Declaration
    37                 virtual void visit( StructDecl * );
    38                 virtual void visit( FunctionDecl * );
    39                 virtual void visit( ObjectDecl * );
    40                 virtual void visit( UnionDecl *aggregateDecl );
    41                 virtual void visit( EnumDecl *aggregateDecl );
    42                 virtual void visit( TraitDecl *aggregateDecl );
    43                 virtual void visit( TypedefDecl *typeDecl );
    44                 virtual void visit( TypeDecl *typeDecl );
     43                void postvisit( StructDecl * );
     44                void postvisit( FunctionDecl * );
     45                void postvisit( ObjectDecl * );
     46                void postvisit( UnionDecl *aggregateDecl );
     47                void postvisit( EnumDecl *aggregateDecl );
     48                void postvisit( TraitDecl *aggregateDecl );
     49                void postvisit( TypedefDecl *typeDecl );
     50                void postvisit( TypeDecl *typeDecl );
    4551
    4652                //*** Initializer
    47                 virtual void visit( Designation * );
    48                 virtual void visit( SingleInit * );
    49                 virtual void visit( ListInit * );
    50                 virtual void visit( ConstructorInit * );
     53                void postvisit( Designation * );
     54                void postvisit( SingleInit * );
     55                void postvisit( ListInit * );
     56                void postvisit( ConstructorInit * );
    5157
    5258                //*** Constant
    53                 virtual void visit( Constant * );
     59                void postvisit( Constant * );
    5460
    5561                //*** Expression
    56                 virtual void visit( ApplicationExpr *applicationExpr );
    57                 virtual void visit( UntypedExpr *untypedExpr );
    58                 virtual void visit( RangeExpr * rangeExpr );
    59                 virtual void visit( NameExpr *nameExpr );
    60                 virtual void visit( AddressExpr *addressExpr );
    61                 virtual void visit( LabelAddressExpr *addressExpr );
    62                 virtual void visit( CastExpr *castExpr );
    63                 virtual void visit( VirtualCastExpr *castExpr );
    64                 virtual void visit( UntypedMemberExpr *memberExpr );
    65                 virtual void visit( MemberExpr *memberExpr );
    66                 virtual void visit( VariableExpr *variableExpr );
    67                 virtual void visit( ConstantExpr *constantExpr );
    68                 virtual void visit( SizeofExpr *sizeofExpr );
    69                 virtual void visit( AlignofExpr *alignofExpr );
    70                 virtual void visit( UntypedOffsetofExpr *offsetofExpr );
    71                 virtual void visit( OffsetofExpr *offsetofExpr );
    72                 virtual void visit( OffsetPackExpr *offsetPackExpr );
    73                 virtual void visit( LogicalExpr *logicalExpr );
    74                 virtual void visit( ConditionalExpr *conditionalExpr );
    75                 virtual void visit( CommaExpr *commaExpr );
    76                 virtual void visit( CompoundLiteralExpr *compLitExpr );
    77                 virtual void visit( UniqueExpr * );
    78                 virtual void visit( TupleAssignExpr * tupleExpr );
    79                 virtual void visit( UntypedTupleExpr *tupleExpr );
    80                 virtual void visit( TupleExpr *tupleExpr );
    81                 virtual void visit( TupleIndexExpr * tupleExpr );
    82                 virtual void visit( TypeExpr *typeExpr );
    83                 virtual void visit( AsmExpr * );
    84                 virtual void visit( StmtExpr * );
     62                void postvisit( ApplicationExpr *applicationExpr );
     63                void postvisit( UntypedExpr *untypedExpr );
     64                void postvisit( RangeExpr * rangeExpr );
     65                void postvisit( NameExpr *nameExpr );
     66                void postvisit( AddressExpr *addressExpr );
     67                void postvisit( LabelAddressExpr *addressExpr );
     68                void postvisit( CastExpr *castExpr );
     69                void postvisit( VirtualCastExpr *castExpr );
     70                void postvisit( UntypedMemberExpr *memberExpr );
     71                void postvisit( MemberExpr *memberExpr );
     72                void postvisit( VariableExpr *variableExpr );
     73                void postvisit( ConstantExpr *constantExpr );
     74                void postvisit( SizeofExpr *sizeofExpr );
     75                void postvisit( AlignofExpr *alignofExpr );
     76                void postvisit( UntypedOffsetofExpr *offsetofExpr );
     77                void postvisit( OffsetofExpr *offsetofExpr );
     78                void postvisit( OffsetPackExpr *offsetPackExpr );
     79                void postvisit( LogicalExpr *logicalExpr );
     80                void postvisit( ConditionalExpr *conditionalExpr );
     81                void postvisit( CommaExpr *commaExpr );
     82                void postvisit( CompoundLiteralExpr *compLitExpr );
     83                void postvisit( UniqueExpr * );
     84                void postvisit( TupleAssignExpr * tupleExpr );
     85                void postvisit( UntypedTupleExpr *tupleExpr );
     86                void postvisit( TupleExpr *tupleExpr );
     87                void postvisit( TupleIndexExpr * tupleExpr );
     88                void postvisit( TypeExpr *typeExpr );
     89                void postvisit( AsmExpr * );
     90                void postvisit( StmtExpr * );
    8591
    8692                //*** Statements
    87                 virtual void visit( CompoundStmt * );
    88                 virtual void visit( ExprStmt * );
    89                 virtual void visit( AsmStmt * );
    90                 virtual void visit( AsmDecl * );                                // special: statement in declaration context
    91                 virtual void visit( IfStmt * );
    92                 virtual void visit( SwitchStmt * );
    93                 virtual void visit( CaseStmt * );
    94                 virtual void visit( BranchStmt * );
    95                 virtual void visit( ReturnStmt * );
    96                 virtual void visit( ThrowStmt * );
    97                 virtual void visit( WhileStmt * );
    98                 virtual void visit( ForStmt * );
    99                 virtual void visit( NullStmt * );
    100                 virtual void visit( DeclStmt * );
     93                void postvisit( CompoundStmt * );
     94                void postvisit( ExprStmt * );
     95                void postvisit( AsmStmt * );
     96                void postvisit( AsmDecl * );                            // special: statement in declaration context
     97                void postvisit( IfStmt * );
     98                void postvisit( SwitchStmt * );
     99                void postvisit( CaseStmt * );
     100                void postvisit( BranchStmt * );
     101                void postvisit( ReturnStmt * );
     102                void postvisit( ThrowStmt * );
     103                void postvisit( WhileStmt * );
     104                void postvisit( ForStmt * );
     105                void postvisit( NullStmt * );
     106                void postvisit( DeclStmt * );
     107                void postvisit( ImplicitCtorDtorStmt * );
    101108
    102109                void genAttributes( std::list< Attribute * > & attributes );
     
    140147          if ( begin == end ) return;
    141148                for ( ;; ) {
    142                         (*begin++)->accept( *this );
     149                        (*begin++)->accept( *visitor );
    143150                  if ( begin == end ) break;
    144151                        output << ", ";                                                         // separator
Note: See TracChangeset for help on using the changeset viewer.