source: translator/InitTweak/InitModel.h@ b8508a2

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 stuck-waitfor-destruct with_gc
Last change on this file since b8508a2 was bdd516a, checked in by Peter A. Buhr <pabuhr@…>, 11 years ago

fixed sizeof type variable, find lowest cost alternative for sizeof expression, removed unused classes, added compiler flag, remove temporary file for -CFA, formatting

  • Property mode set to 100644
File size: 3.4 KB
RevLine 
[51b73452]1#ifndef _INITTWEAK_MODEL_H_
2#define _INITTWEAK_MODEL_H_
3
4#include "Association.h"
5#include "SemanticError.h"
6#include "SynTree/Visitor.h"
7
8#include "SynTree/Initializer.h"
9#include "SynTree/Declaration.h"
10#include "SynTree/Expression.h"
11#include "SynTree/Type.h"
12
13namespace InitTweak {
[bdd516a]14 class InitModelBuilder : public AssociationBuilder, public Visitor {
15 public:
16 InitModelBuilder( Declaration * );
17 ~InitModelBuilder();
18
19 virtual Association *grab_assoc() { taken = true; return building; }
20 virtual Association *get_assoc() { return building; }
21 void set_assoc( Association *newAssoc ) { building = newAssoc; }
22
23 void init();
24 static int interpretDimension( Expression *exp ) {
25 ConstantFolder folder( exp );
26 try {
27 return folder.get_constant();
28 } catch (...) {
29 throw SemanticError("Invalid array dimension");
30 }
31 }
32
33 // types
34 virtual void visit( ArrayType * );
35 virtual void visit( StructInstType * );
36 virtual void visit( UnionInstType * );
37 virtual void visit( EnumInstType * );
38 virtual void visit( ContextInstType * ) { throw 0; }
39 virtual void visit( TypeInstType * ) { throw 0; }
40 // virtual void visit( TupleType *tupleType );
41 // declarations
42 virtual void visit( StructDecl *);
43 virtual void visit( UnionDecl *);
44 virtual void visit( EnumDecl *);
45 private:
46 class ConstantFolder : public Visitor {
47 public:
48 ConstantFolder( Expression *_expr = 0 ): expr(_expr) {}
49 int get_constant() throw() { expr->accept( *this ); return value; }
50 void set_constant( Expression *newExp ) { expr = newExp; }
51 // Visitor interface
52 void visit( Expression * ) { throw 0; }
53 void visit( NameExpr * ) { throw 0; }
54 void visit( CastExpr * ) { throw 0; }
55 void visit( UntypedMemberExpr * ) { throw 0; }
56 void visit( VariableExpr * ) { throw 0; }
57 void visit( ConstantExpr * );
58 void visit( SizeofExpr * ) { throw 0; }
59 void visit( AttrExpr * ) { throw 0; }
60 void visit( LogicalExpr * ) { throw 0; }
61 void visit( ConditionalExpr * ) { throw 0; }
62 void visit( CommaExpr * ) { throw 0; }
63 private:
64 Expression *expr;
65 int value;
66 };
67
68 bool taken;
69 Declaration *decl; // ?
70 Association *building;
[51b73452]71 };
72
[bdd516a]73 class InitModelFiller : public AssociationFiller, public Visitor {
74 public:
75 InitModelFiller( Association *, Initializer *, bool _topLevel = false );
76 ~InitModelFiller() { /* pointers in here are not owned by object (never created by object either) */ }
77 virtual Association *get_assoc() { return model; }
78 virtual void set_assoc( Association *newAssoc ) { model = newAssoc; }
79
80 void init();
81 // Visitor interface
82 virtual void visit( SingleInit *singleInit );
83 virtual void visit( ListInit *listInit );
84 private:
85 Association *model;
86 Initializer *orgInit;
87 bool topLevel;
88 long int next;
89 };
[51b73452]90
[bdd516a]91 class InitUnspooler : public AssociationVisitor {
92 public:
93 InitUnspooler() : init(0), taken( false ) {}
94 virtual ~InitUnspooler() { if (!taken && (init != 0)) { delete init; init = 0; } }
95 Initializer *get_initializer() { return init; }
96 Initializer *grab_initializer() { taken = true; return init; }
97
98 virtual void visit( SingleName * );
99 virtual void visit( PointAssociation * );
100 virtual void visit( RangeAssociation * ) { std::cerr << "InitUnspooler - In a range assoc" << std::endl; return; }
101 private:
102 Initializer *init;
103 bool taken;
104 };
[51b73452]105
106} // namespace InitTweak
107
[bdd516a]108#endif // _INITTWEAK_MODEL_H_
[51b73452]109
110/*
111 Local Variables:
112 mode: c++
113 End:
114*/
Note: See TracBrowser for help on using the repository browser.