source: translator/InitTweak/InitModel.h @ d4778a6

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since d4778a6 was bdd516a, checked in by Peter A. Buhr <pabuhr@…>, 9 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
Line 
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 {
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;
71    };
72
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    };
90
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    };
105
106} // namespace InitTweak
107
108#endif // _INITTWEAK_MODEL_H_
109
110/*
111  Local Variables:
112  mode: c++
113  End:
114*/
Note: See TracBrowser for help on using the repository browser.