Ignore:
Timestamp:
Apr 28, 2015, 4:21:36 PM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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:
42e2ad7
Parents:
ad17ba6a
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • translator/InitTweak/InitModel.h

    rad17ba6a rbdd516a  
    1212
    1313namespace InitTweak {
     14    class InitModelBuilder : public AssociationBuilder, public Visitor {
     15      public:
     16        InitModelBuilder( Declaration * );
     17        ~InitModelBuilder();
    1418
    15   class InitModelBuilder : public AssociationBuilder, public Visitor {
    16   public:
    17     InitModelBuilder( Declaration * );
    18     ~InitModelBuilder();
     19        virtual Association *grab_assoc() { taken = true; return building; }
     20        virtual Association *get_assoc() { return building; }
     21        void set_assoc( Association *newAssoc ) { building = newAssoc; }
    1922
    20     virtual Association *grab_assoc() { taken = true; return building; }
    21     virtual Association *get_assoc() { return building; }
    22     void set_assoc( Association *newAssoc ) { building = newAssoc; }
     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        }
    2332
    24     void init();
    25     static int interpretDimension( Expression *exp ) {
    26       ConstantFolder folder( exp );
    27       try {
    28         return folder.get_constant();
    29       } catch (...) {
    30         throw SemanticError("Invalid array dimension");
    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        };
    3367
    34     // types
    35     virtual void visit( ArrayType * );
    36     virtual void visit( StructInstType * );
    37     virtual void visit( UnionInstType * );
    38     virtual void visit( EnumInstType * );
    39     virtual void visit( ContextInstType * ) { throw 0; }
    40     virtual void visit( TypeInstType * )    { throw 0; }
    41     // virtual void visit( TupleType *tupleType );
    42     // declarations
    43     virtual void visit( StructDecl *);
    44     virtual void visit( UnionDecl *);
    45     virtual void visit( EnumDecl *);
    46 
    47   private:
    48     class ConstantFolder : public Visitor {
    49     public:
    50       ConstantFolder( Expression *_expr = 0 ): expr(_expr) {}
    51       int get_constant() throw() { expr->accept( *this ); return value; }
    52       void set_constant( Expression *newExp ) { expr = newExp; }
    53       // Visitor interface
    54       void visit( Expression * ) { throw 0; }
    55       void visit( NameExpr * ) { throw 0; }
    56       void visit( CastExpr * ) { throw 0; }
    57       void visit( UntypedMemberExpr * ) { throw 0; }
    58       void visit( VariableExpr * ) { throw 0; }
    59       void visit( ConstantExpr * );
    60       void visit( SizeofExpr * ) { throw 0; }
    61       void visit( AttrExpr * ) { throw 0; }
    62       void visit( LogicalExpr * ) { throw 0; }
    63       void visit( ConditionalExpr * ) { throw 0; }
    64       void visit( CommaExpr * ) { throw 0; }
    65     private:
    66       Expression *expr;
    67       int value;
     68        bool taken;
     69        Declaration *decl;  // ?
     70        Association *building;
    6871    };
    6972
    70     bool taken;
    71     Declaration *decl;  // ?
    72     Association *building;
    73   };
     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; }
    7479
    75   class InitModelFiller : public AssociationFiller, public Visitor {
    76   public:
    77     InitModelFiller( Association *, Initializer *, bool _topLevel = false );
    78     ~InitModelFiller() { /* pointers in here are not owned by object (never created by object either) */ }
    79     virtual Association *get_assoc() { return model; }
    80     virtual void set_assoc( Association *newAssoc ) { model = newAssoc; }
     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    };
    8190
    82     void init();
    83     // Visitor interface
    84     virtual void visit( MemberInit *memberInit ) { throw 0; }
    85     virtual void visit( ElementInit *elementInit ) { throw 0; }
    86     virtual void visit( SingleInit *singleInit );
    87     virtual void visit( ListInit *listInit );
     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; }
    8897
    89   private:
    90     Association *model;
    91     Initializer *orgInit;
    92     bool topLevel;
    93     long int next;
    94   };
    95 
    96   class InitUnspooler : public AssociationVisitor {
    97   public:
    98     InitUnspooler() : init(0), taken( false ) {}
    99     virtual ~InitUnspooler() { if (!taken && (init != 0)) { delete init; init = 0; } }
    100     Initializer *get_initializer() { return init; }
    101     Initializer *grab_initializer() { taken = true; return init; }
    102 
    103     virtual void visit( SingleName * );
    104     virtual void visit( PointAssociation * );
    105     virtual void visit( RangeAssociation * ) { std::cerr << "InitUnspooler - In a range assoc" << std::endl; return; }
    106 
    107   private:
    108     Initializer *init;
    109     bool taken;
    110   };
     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    };
    111105
    112106} // namespace InitTweak
    113107
    114 #endif // #define _INITTWEAK_MODEL_H_
     108#endif // _INITTWEAK_MODEL_H_
    115109
    116110/*
Note: See TracChangeset for help on using the changeset viewer.