Changeset 51587aa for translator/CodeGen/CodeGenerator2.h
- Timestamp:
- May 18, 2015, 11:45:33 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 01aeade
- Parents:
- 0dd3a2f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/CodeGen/CodeGenerator2.h
r0dd3a2f r51587aa 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // CodeGenerator2.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 23:35:37 2015 13 // Update Count : 2 14 // 15 1 16 #ifndef CODEGENV_H 2 17 #define CODEGENV_H … … 10 25 11 26 namespace CodeGen { 12 13 14 static int tabsize;27 class CodeGenerator2 : public Visitor { 28 public: 29 static int tabsize; 15 30 16 CodeGenerator2( std::ostream &os );17 CodeGenerator2( std::ostream &os, std::string, int indent = 0, bool infun = false );18 CodeGenerator2( std::ostream &os, char *, int indent = 0, bool infun = false );31 CodeGenerator2( std::ostream &os ); 32 CodeGenerator2( std::ostream &os, std::string, int indent = 0, bool infun = false ); 33 CodeGenerator2( std::ostream &os, char *, int indent = 0, bool infun = false ); 19 34 20 CodeGenerator2( CodeGenerator2 & );35 CodeGenerator2( CodeGenerator2 & ); 21 36 22 //*** Declaration23 virtual void visit( StructDecl * );24 virtual void visit( FunctionDecl * );25 virtual void visit( ObjectDecl * );26 virtual void visit( UnionDecl *aggregateDecl );27 virtual void visit( EnumDecl *aggregateDecl );28 virtual void visit( ContextDecl *aggregateDecl );29 virtual void visit( TypedefDecl *typeDecl );30 virtual void visit( TypeDecl *typeDecl );37 //*** Declaration 38 virtual void visit( StructDecl * ); 39 virtual void visit( FunctionDecl * ); 40 virtual void visit( ObjectDecl * ); 41 virtual void visit( UnionDecl *aggregateDecl ); 42 virtual void visit( EnumDecl *aggregateDecl ); 43 virtual void visit( ContextDecl *aggregateDecl ); 44 virtual void visit( TypedefDecl *typeDecl ); 45 virtual void visit( TypeDecl *typeDecl ); 31 46 32 //*** Initializer33 virtual void visit( SingleInit * );34 virtual void visit( ListInit * );47 //*** Initializer 48 virtual void visit( SingleInit * ); 49 virtual void visit( ListInit * ); 35 50 36 //*** Constant37 virtual void visit( Constant * );51 //*** Constant 52 virtual void visit( Constant * ); 38 53 39 //*** Expression40 virtual void visit( ApplicationExpr *applicationExpr );41 virtual void visit( UntypedExpr *untypedExpr );42 virtual void visit( NameExpr *nameExpr );43 virtual void visit( AddressExpr *addressExpr );44 virtual void visit( CastExpr *castExpr );45 virtual void visit( UntypedMemberExpr *memberExpr );46 virtual void visit( MemberExpr *memberExpr );47 virtual void visit( VariableExpr *variableExpr );48 virtual void visit( ConstantExpr *constantExpr );49 virtual void visit( SizeofExpr *sizeofExpr );50 virtual void visit( LogicalExpr *logicalExpr );51 virtual void visit( ConditionalExpr *conditionalExpr );52 virtual void visit( CommaExpr *commaExpr );53 virtual void visit( TupleExpr *tupleExpr );54 virtual void visit( TypeExpr *typeExpr );54 //*** Expression 55 virtual void visit( ApplicationExpr *applicationExpr ); 56 virtual void visit( UntypedExpr *untypedExpr ); 57 virtual void visit( NameExpr *nameExpr ); 58 virtual void visit( AddressExpr *addressExpr ); 59 virtual void visit( CastExpr *castExpr ); 60 virtual void visit( UntypedMemberExpr *memberExpr ); 61 virtual void visit( MemberExpr *memberExpr ); 62 virtual void visit( VariableExpr *variableExpr ); 63 virtual void visit( ConstantExpr *constantExpr ); 64 virtual void visit( SizeofExpr *sizeofExpr ); 65 virtual void visit( LogicalExpr *logicalExpr ); 66 virtual void visit( ConditionalExpr *conditionalExpr ); 67 virtual void visit( CommaExpr *commaExpr ); 68 virtual void visit( TupleExpr *tupleExpr ); 69 virtual void visit( TypeExpr *typeExpr ); 55 70 56 //*** Statements57 virtual void visit( CompoundStmt * );58 virtual void visit( ExprStmt * );59 virtual void visit( IfStmt * );60 virtual void visit( SwitchStmt * );61 virtual void visit( CaseStmt * );62 virtual void visit( BranchStmt * );63 virtual void visit( ReturnStmt * );64 virtual void visit( WhileStmt * );65 virtual void visit( ForStmt * );66 virtual void visit( NullStmt * );67 virtual void visit( DeclStmt * );71 //*** Statements 72 virtual void visit( CompoundStmt * ); 73 virtual void visit( ExprStmt * ); 74 virtual void visit( IfStmt * ); 75 virtual void visit( SwitchStmt * ); 76 virtual void visit( CaseStmt * ); 77 virtual void visit( BranchStmt * ); 78 virtual void visit( ReturnStmt * ); 79 virtual void visit( WhileStmt * ); 80 virtual void visit( ForStmt * ); 81 virtual void visit( NullStmt * ); 82 virtual void visit( DeclStmt * ); 68 83 69 std::string get_string( void );70 void add_string_left( std::string s ) { before << s; }71 void shift_left();72 template< class Iterator > void genCommaList( Iterator begin, Iterator end );73 74 int cur_indent;75 bool insideFunction;76 std::ostream &before;77 std::string after;84 std::string get_string( void ); 85 void add_string_left( std::string s ) { before << s; } 86 void shift_left(); 87 template< class Iterator > void genCommaList( Iterator begin, Iterator end ); 88 private: 89 int cur_indent; 90 bool insideFunction; 91 std::ostream &before; 92 std::string after; 78 93 79 static std::string printLabels ( std::list < Label > & );80 void handleStorageClass( Declaration *decl );81 void handleAggregate( AggregateDecl *aggDecl );82 void handleTypedef( NamedTypeDecl *namedType );94 static std::string printLabels ( std::list < Label > & ); 95 void handleStorageClass( Declaration *decl ); 96 void handleAggregate( AggregateDecl *aggDecl ); 97 void handleTypedef( NamedTypeDecl *namedType ); 83 98 84 85 86 87 88 if ( begin == end ) return;99 }; 100 101 template< class Iterator > 102 void CodeGenerator2::genCommaList( Iterator begin, Iterator end ) { 103 if ( begin == end ) return; 89 104 90 for ( ;; ) { 91 (*begin++)->accept( *this ); 92 if ( begin == end ) return; 93 before << ", "; 105 for ( ;; ) { 106 (*begin++)->accept( *this ); 107 if ( begin == end ) return; 108 before << ", "; 109 } // for 94 110 } 95 }96 111 97 inline bool doSemicolon( Declaration* decl ) { 98 if ( FunctionDecl* func = dynamic_cast< FunctionDecl* >( decl ) ) { 99 return ! func->get_statements(); 112 inline bool doSemicolon( Declaration* decl ) { 113 if ( FunctionDecl* func = dynamic_cast< FunctionDecl* >( decl ) ) { 114 return ! func->get_statements(); 115 } // if 116 return true; 100 117 } 101 return true;102 }103 118 } // namespace CodeGen 104 119 105 #endif / * #ifndef CODEGENV_H */120 #endif // CODEGENV_H 106 121 107 / *108 Local Variables: 109 mode: "c++" 110 End: 111 */122 // Local Variables: // 123 // tab-width: 4 // 124 // mode: c++ // 125 // compile-command: "make install" // 126 // End: //
Note: See TracChangeset
for help on using the changeset viewer.