Ignore:
Timestamp:
May 19, 2015, 4:58:14 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:
843054c2
Parents:
01aeade
Message:

licencing: sixth groups of files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • translator/InitTweak/InitModel.h

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// InitModel.h --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By :
    12 // Last Modified On :
    13 // Update Count     : 0
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue May 19 16:37:52 2015
     13// Update Count     : 2
    1414//
     15
    1516#ifndef _INITTWEAK_MODEL_H_
    1617#define _INITTWEAK_MODEL_H_
     
    2627
    2728namespace InitTweak {
    28     class InitModelBuilder : public AssociationBuilder, public Visitor {
    29       public:
    30         InitModelBuilder( Declaration * );
    31         ~InitModelBuilder();
     29        class InitModelBuilder : public AssociationBuilder, public Visitor {
     30          public:
     31                InitModelBuilder( Declaration * );
     32                ~InitModelBuilder();
    3233
    33         virtual Association *grab_assoc() { taken = true; return building; }
    34         virtual Association *get_assoc() { return building; }
    35         void set_assoc( Association *newAssoc ) { building = newAssoc; }
     34                virtual Association *grab_assoc() { taken = true; return building; }
     35                virtual Association *get_assoc() { return building; }
     36                void set_assoc( Association *newAssoc ) { building = newAssoc; }
    3637
    37         void init();
    38         static int interpretDimension( Expression *exp ) {
    39             ConstantFolder folder( exp );
    40             try {
    41                 return folder.get_constant();
    42             } catch (...) {
    43                 throw SemanticError("Invalid array dimension");
    44             }
    45         }
     38                void init();
     39                static int interpretDimension( Expression *exp ) {
     40                        ConstantFolder folder( exp );
     41                        try {
     42                                return folder.get_constant();
     43                        } catch (...) {
     44                                throw SemanticError("Invalid array dimension");
     45                        }
     46                }
    4647
    47         // types
    48         virtual void visit( ArrayType * );
    49         virtual void visit( StructInstType * );
    50         virtual void visit( UnionInstType * );
    51         virtual void visit( EnumInstType * );
    52         virtual void visit( ContextInstType * ) { throw 0; }
    53         virtual void visit( TypeInstType * )    { throw 0; }
    54         // virtual void visit( TupleType *tupleType );
    55         // declarations
    56         virtual void visit( StructDecl *);
    57         virtual void visit( UnionDecl *);
    58         virtual void visit( EnumDecl *);
    59       private:
    60         class ConstantFolder : public Visitor {
    61           public:
    62             ConstantFolder( Expression *_expr = 0 ): expr(_expr) {}
    63             int get_constant() throw() { expr->accept( *this ); return value; }
    64             void set_constant( Expression *newExp ) { expr = newExp; }
    65             // Visitor interface
    66             void visit( Expression * ) { throw 0; }
    67             void visit( NameExpr * ) { throw 0; }
    68             void visit( CastExpr * ) { throw 0; }
    69             void visit( UntypedMemberExpr * ) { throw 0; }
    70             void visit( VariableExpr * ) { throw 0; }
    71             void visit( ConstantExpr * );
    72             void visit( SizeofExpr * ) { throw 0; }
    73             void visit( AttrExpr * ) { throw 0; }
    74             void visit( LogicalExpr * ) { throw 0; }
    75             void visit( ConditionalExpr * ) { throw 0; }
    76             void visit( CommaExpr * ) { throw 0; }
     48                // types
     49                virtual void visit( ArrayType * );
     50                virtual void visit( StructInstType * );
     51                virtual void visit( UnionInstType * );
     52                virtual void visit( EnumInstType * );
     53                virtual void visit( ContextInstType * ) { throw 0; }
     54                virtual void visit( TypeInstType * )    { throw 0; }
     55                // virtual void visit( TupleType *tupleType );
     56                // declarations
     57                virtual void visit( StructDecl *);
     58                virtual void visit( UnionDecl *);
     59                virtual void visit( EnumDecl *);
    7760          private:
    78             Expression *expr;
    79             int value;
     61                class ConstantFolder : public Visitor {
     62                  public:
     63                        ConstantFolder( Expression *_expr = 0 ): expr(_expr) {}
     64                        int get_constant() throw() { expr->accept( *this ); return value; }
     65                        void set_constant( Expression *newExp ) { expr = newExp; }
     66                        // Visitor interface
     67                        void visit( Expression * ) { throw 0; }
     68                        void visit( NameExpr * ) { throw 0; }
     69                        void visit( CastExpr * ) { throw 0; }
     70                        void visit( UntypedMemberExpr * ) { throw 0; }
     71                        void visit( VariableExpr * ) { throw 0; }
     72                        void visit( ConstantExpr * );
     73                        void visit( SizeofExpr * ) { throw 0; }
     74                        void visit( AttrExpr * ) { throw 0; }
     75                        void visit( LogicalExpr * ) { throw 0; }
     76                        void visit( ConditionalExpr * ) { throw 0; }
     77                        void visit( CommaExpr * ) { throw 0; }
     78                  private:
     79                        Expression *expr;
     80                        int value;
     81                };
     82
     83                bool taken;
     84                Declaration *decl;  // ?
     85                Association *building;
    8086        };
    8187
    82         bool taken;
    83         Declaration *decl;  // ?
    84         Association *building;
    85     };
     88        class InitModelFiller : public AssociationFiller, public Visitor {
     89          public:
     90                InitModelFiller( Association *, Initializer *, bool _topLevel = false );
     91                ~InitModelFiller() { /* pointers in here are not owned by object (never created by object either) */ }
     92                virtual Association *get_assoc() { return model; }
     93                virtual void set_assoc( Association *newAssoc ) { model = newAssoc; }
    8694
    87     class InitModelFiller : public AssociationFiller, public Visitor {
    88       public:
    89         InitModelFiller( Association *, Initializer *, bool _topLevel = false );
    90         ~InitModelFiller() { /* pointers in here are not owned by object (never created by object either) */ }
    91         virtual Association *get_assoc() { return model; }
    92         virtual void set_assoc( Association *newAssoc ) { model = newAssoc; }
     95                void init();
     96                // Visitor interface
     97                virtual void visit( SingleInit *singleInit );
     98                virtual void visit( ListInit *listInit );
     99          private:
     100                Association *model;
     101                Initializer *orgInit;
     102                bool topLevel;
     103                long int next;
     104        };
    93105
    94         void init();
    95         // Visitor interface
    96         virtual void visit( SingleInit *singleInit );
    97         virtual void visit( ListInit *listInit );
    98       private:
    99         Association *model;
    100         Initializer *orgInit;
    101         bool topLevel;
    102         long int next;
    103     };
     106        class InitUnspooler : public AssociationVisitor {
     107          public:
     108                InitUnspooler() : init(0), taken( false ) {}
     109                virtual ~InitUnspooler() { if ( ! taken && (init != 0)) { delete init; init = 0; } }
     110                Initializer *get_initializer() { return init; }
     111                Initializer *grab_initializer() { taken = true; return init; }
    104112
    105     class InitUnspooler : public AssociationVisitor {
    106       public:
    107         InitUnspooler() : init(0), taken( false ) {}
    108         virtual ~InitUnspooler() { if (! taken && (init != 0)) { delete init; init = 0; } }
    109         Initializer *get_initializer() { return init; }
    110         Initializer *grab_initializer() { taken = true; return init; }
    111 
    112         virtual void visit( SingleName * );
    113         virtual void visit( PointAssociation * );
    114         virtual void visit( RangeAssociation * ) { std::cerr << "InitUnspooler - In a range assoc" << std::endl; return; }
    115       private:
    116         Initializer *init;
    117         bool taken;
    118     };
    119 
     113                virtual void visit( SingleName * );
     114                virtual void visit( PointAssociation * );
     115                virtual void visit( RangeAssociation * ) { std::cerr << "InitUnspooler - In a range assoc" << std::endl; return; }
     116          private:
     117                Initializer *init;
     118                bool taken;
     119        };
    120120} // namespace InitTweak
    121121
    122122#endif // _INITTWEAK_MODEL_H_
    123123
    124 /*
    125   Local Variables:
    126   mode: c++
    127   End:
    128 */
    129124// Local Variables: //
    130125// tab-width: 4 //
Note: See TracChangeset for help on using the changeset viewer.