source: translator/CodeGen/CodeGenerator2.h@ 643a2e1

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new string with_gc
Last change on this file since 643a2e1 was 17cd4eb, checked in by Peter A. Buhr <pabuhr@…>, 11 years ago

fixed restrict, fixed parameter copy, introduced name table for types, changed variable after to string

  • Property mode set to 100644
File size: 3.1 KB
Line 
1#ifndef CODEGENV_H
2#define CODEGENV_H
3
4#include <strstream>
5#include <list>
6
7#include "SynTree/SynTree.h"
8#include "SynTree/Visitor.h"
9#include "SymTab/Indexer.h"
10
11namespace CodeGen {
12 class CodeGenerator2 : public Visitor {
13 public:
14 static int tabsize;
15
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 );
19
20 CodeGenerator2( CodeGenerator2 & );
21
22 //*** Declaration
23 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 );
31
32 //*** Initializer
33 virtual void visit( SingleInit * );
34 virtual void visit( ListInit * );
35
36 //*** Constant
37 virtual void visit( Constant * );
38
39 //*** Expression
40 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 );
55
56 //*** Statements
57 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 * );
68
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 private:
74 int cur_indent;
75 bool insideFunction;
76 std::ostream &before;
77 std::string after;
78
79 static std::string printLabels ( std::list < Label > & );
80 void handleStorageClass( Declaration *decl );
81 void handleAggregate( AggregateDecl *aggDecl );
82 void handleTypedef( NamedTypeDecl *namedType );
83
84 };
85
86 template< class Iterator >
87 void CodeGenerator2::genCommaList( Iterator begin, Iterator end ) {
88 if ( begin == end ) return;
89
90 for ( ;; ) {
91 (*begin++)->accept( *this );
92 if ( begin == end ) return;
93 before << ", ";
94 }
95 }
96
97 inline bool doSemicolon( Declaration* decl ) {
98 if ( FunctionDecl* func = dynamic_cast< FunctionDecl* >( decl ) ) {
99 return !func->get_statements();
100 }
101 return true;
102 }
103} // namespace CodeGen
104
105#endif /* #ifndef CODEGENV_H */
106
107/*
108 Local Variables:
109 mode: "c++"
110 End:
111*/
Note: See TracBrowser for help on using the repository browser.