Changeset afc1045


Ignore:
Timestamp:
Apr 5, 2016, 3:31:09 PM (9 years ago)
Author:
Aaron Moss <a3moss@…>
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:
d75038c
Parents:
b3f9a0cb
Message:

Hoist OffsetPackExpr? to top level expression

Location:
src
Files:
1 added
17 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    rb3f9a0cb rafc1045  
    455455
    456456        void CodeGenerator::visit( UntypedOffsetofExpr *offsetofExpr ) {
    457                 assert( false );
     457                assert( false && "UntypedOffsetofExpr should not reach code generation" );
    458458        }
    459459
     
    464464                output << ", " << mangleName( offsetofExpr->get_member() );
    465465                output << ")";
     466        }
     467
     468        void CodeGenerator::visit( OffsetPackExpr *offsetPackExpr ) {
     469                assert( false && "OffsetPackExpr should not reach code generation" );
    466470        }
    467471 
  • src/CodeGen/CodeGenerator.h

    rb3f9a0cb rafc1045  
    6565                virtual void visit( UntypedOffsetofExpr *offsetofExpr );
    6666                virtual void visit( OffsetofExpr *offsetofExpr );
     67                virtual void visit( OffsetPackExpr *offsetPackExpr );
    6768                virtual void visit( LogicalExpr *logicalExpr );
    6869                virtual void visit( ConditionalExpr *conditionalExpr );
  • src/GenPoly/Box.cc

    rb3f9a0cb rafc1045  
    214214                };
    215215
    216                 class OffsetPackExpr;  // forward declaration so that it can be mutated by Pass2
    217 
    218216                /// * Moves polymorphic returns in function types to pointer-type parameters
    219217                /// * adds type size and assertion parameters to parameter lists
     
    232230                        virtual Expression *mutate( AlignofExpr *alignofExpr );
    233231                        virtual Expression *mutate( OffsetofExpr *offsetofExpr );
    234                                 Expression *mutate( OffsetPackExpr *offsetPackExpr );
     232                        virtual Expression *mutate( OffsetPackExpr *offsetPackExpr );
    235233
    236234                        virtual void doBeginScope();
     
    248246                        ScopedSet< std::string > knownLayouts;          ///< Set of generic type layouts known in the current scope, indexed by sizeofName
    249247                        ScopedSet< std::string > knownOffsets;          ///< Set of non-generic types for which the offset array exists in the current scope, indexed by offsetofName
    250                 };
    251 
    252                 /// Special internal expression for offset arrays inserted by Pass1 and replaced by Pass2
    253                 class OffsetPackExpr : public Expression {
    254                 public:
    255                         OffsetPackExpr( StructInstType *type_, Expression *aname_ = 0 ) : Expression( aname_ ), type( type_ ) {
    256                                         add_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );
    257                         }
    258                        
    259                         OffsetPackExpr( const OffsetPackExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) {}
    260                         virtual ~OffsetPackExpr() { delete type; }
    261 
    262                         StructInstType *get_type() const { return type; }
    263                         void set_type( StructInstType *newValue ) { type = newValue; }
    264 
    265                         virtual OffsetPackExpr *clone() const { return new OffsetPackExpr( *this ); }
    266                         virtual void accept( Visitor &v ) { /* do nothing */ }
    267                         virtual Expression *acceptMutator( Mutator &m ) {
    268                                 // only act if the mutator is a Pass2, which knows about this class
    269                                 if ( Pass2 *m2 = dynamic_cast< Pass2* >( &m ) ) {
    270                                         return m2->mutate( this );
    271                                 } else {
    272                                         return this;
    273                                 }
    274                         }
    275 
    276                         virtual void print( std::ostream &os, int indent = 0 ) const {
    277                                 os << std::string( indent, ' ' ) << "Offset pack expression on ";
    278 
    279                                 if ( type ) {
    280                                         type->print(os, indent + 2);
    281                                 } else {
    282                                         os << "<NULL>";
    283                                 }
    284 
    285                                 os << std::endl;
    286                                 Expression::print( os, indent );
    287                         }
    288                        
    289                 private:
    290                         StructInstType *type;
    291248                };
    292249
  • src/InitTweak/InitModel.h

    rb3f9a0cb rafc1045  
    7575                        void visit( UntypedOffsetofExpr * ) { throw 0; }
    7676                        void visit( OffsetofExpr * ) { throw 0; }
     77                        void visit( OffsetPackExpr * ) { throw 0; }
    7778                        void visit( AttrExpr * ) { throw 0; }
    7879                        void visit( LogicalExpr * ) { throw 0; }
  • src/ResolvExpr/AlternativeFinder.cc

    rb3f9a0cb rafc1045  
    848848        }
    849849
     850        void AlternativeFinder::visit( OffsetPackExpr *offsetPackExpr ) {
     851                alternatives.push_back( Alternative( offsetPackExpr->clone(), env, Cost::zero ) );
     852        }
     853
    850854        void AlternativeFinder::resolveAttr( DeclarationWithType *funcDecl, FunctionType *function, Type *argType, const TypeEnvironment &env ) {
    851855                // assume no polymorphism
  • src/ResolvExpr/AlternativeFinder.h

    rb3f9a0cb rafc1045  
    5959                virtual void visit( UntypedOffsetofExpr *offsetofExpr );
    6060                virtual void visit( OffsetofExpr *offsetofExpr );
     61                virtual void visit( OffsetPackExpr *offsetPackExpr );
    6162                virtual void visit( AttrExpr *attrExpr );
    6263                virtual void visit( LogicalExpr *logicalExpr );
  • src/SymTab/Indexer.cc

    rb3f9a0cb rafc1045  
    344344                maybeAccept( offsetofExpr->get_type(), *this );
    345345                maybeAccept( offsetofExpr->get_member(), *this );
     346        }
     347
     348        void Indexer::visit( OffsetPackExpr *offsetPackExpr ) {
     349                acceptAllNewScope( offsetPackExpr->get_results(), *this );
     350                maybeAccept( offsetPackExpr->get_type(), *this );
    346351        }
    347352
  • src/SymTab/Indexer.h

    rb3f9a0cb rafc1045  
    5959                virtual void visit( UntypedOffsetofExpr *offsetofExpr );
    6060                virtual void visit( OffsetofExpr *offsetofExpr );
     61                virtual void visit( OffsetPackExpr *offsetPackExpr );
    6162                virtual void visit( AttrExpr *attrExpr );
    6263                virtual void visit( LogicalExpr *logicalExpr );
  • src/SynTree/Expression.cc

    rb3f9a0cb rafc1045  
    222222}
    223223
     224OffsetPackExpr::OffsetPackExpr( StructInstType *type_, Expression *aname_ ) : Expression( aname_ ), type( type_ ) {
     225        add_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );
     226}
     227
     228OffsetPackExpr::OffsetPackExpr( const OffsetPackExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) {}
     229
     230OffsetPackExpr::~OffsetPackExpr() { delete type; }
     231
     232void OffsetPackExpr::print( std::ostream &os, int indent ) const {
     233        os << std::string( indent, ' ' ) << "Offset pack expression on ";
     234
     235        if ( type ) {
     236                type->print(os, indent + 2);
     237        } else {
     238                os << "<NULL>";
     239        }
     240
     241        os << std::endl;
     242        Expression::print( os, indent );
     243}
     244
    224245AttrExpr::AttrExpr( Expression *attr, Expression *expr_, Expression *_aname ) :
    225246                Expression( _aname ), attr( attr ), expr(expr_), type(0), isType(false) {
  • src/SynTree/Expression.h

    rb3f9a0cb rafc1045  
    362362};
    363363
     364/// Expression representing a pack of field-offsets for a generic type
     365class OffsetPackExpr : public Expression {
     366public:
     367        OffsetPackExpr( StructInstType *type_, Expression *aname_ = 0 );
     368        OffsetPackExpr( const OffsetPackExpr &other );
     369        virtual ~OffsetPackExpr();
     370
     371        StructInstType *get_type() const { return type; }
     372        void set_type( StructInstType *newValue ) { type = newValue; }
     373
     374        virtual OffsetPackExpr *clone() const { return new OffsetPackExpr( *this ); }
     375        virtual void accept( Visitor &v ) { v.visit( this ); }
     376        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     377
     378        virtual void print( std::ostream &os, int indent = 0 ) const;
     379
     380private:
     381        StructInstType *type;
     382};
     383
    364384/// AttrExpr represents an @attribute expression (like sizeof, but user-defined)
    365385class AttrExpr : public Expression {
  • src/SynTree/Mutator.cc

    rb3f9a0cb rafc1045  
    274274}
    275275
     276Expression *Mutator::mutate( OffsetPackExpr *offsetPackExpr ) {
     277        mutateAll( offsetPackExpr->get_results(), *this );
     278        offsetPackExpr->set_type( maybeMutate( offsetPackExpr->get_type(), *this ) );
     279        return offsetPackExpr;
     280}
     281
    276282Expression *Mutator::mutate( AttrExpr *attrExpr ) {
    277283        mutateAll( attrExpr->get_results(), *this );
  • src/SynTree/Mutator.h

    rb3f9a0cb rafc1045  
    6767        virtual Expression* mutate( UntypedOffsetofExpr *offsetofExpr );
    6868        virtual Expression* mutate( OffsetofExpr *offsetofExpr );
     69        virtual Expression* mutate( OffsetPackExpr *offsetPackExpr );
    6970        virtual Expression* mutate( AttrExpr *attrExpr );
    7071        virtual Expression* mutate( LogicalExpr *logicalExpr );
  • src/SynTree/SynTree.h

    rb3f9a0cb rafc1045  
    7272class UntypedOffsetofExpr;
    7373class OffsetofExpr;
     74class OffsetPackExpr;
    7475class AttrExpr;
    7576class LogicalExpr;
  • src/SynTree/Visitor.cc

    rb3f9a0cb rafc1045  
    230230}
    231231
     232void Visitor::visit( OffsetPackExpr *offsetPackExpr ) {
     233        acceptAll( offsetPackExpr->get_results(), *this );
     234        maybeAccept( offsetPackExpr->get_type(), *this );
     235}
     236
    232237void Visitor::visit( AttrExpr *attrExpr ) {
    233238        acceptAll( attrExpr->get_results(), *this );
  • src/SynTree/Visitor.h

    rb3f9a0cb rafc1045  
    6767        virtual void visit( UntypedOffsetofExpr *offsetofExpr );
    6868        virtual void visit( OffsetofExpr *offsetofExpr );
     69        virtual void visit( OffsetPackExpr *offsetPackExpr );
    6970        virtual void visit( AttrExpr *attrExpr );
    7071        virtual void visit( LogicalExpr *logicalExpr );
  • src/Tuples/FlattenTuple.cc

    rb3f9a0cb rafc1045  
    4949        void FlattenTuple::CollectArgs::visit( UntypedOffsetofExpr *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    5050        void FlattenTuple::CollectArgs::visit( OffsetofExpr        *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
     51        void FlattenTuple::CollectArgs::visit( OffsetPackExpr      *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    5152        void FlattenTuple::CollectArgs::visit( AttrExpr            *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    5253        void FlattenTuple::CollectArgs::visit( LogicalExpr         *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
  • src/Tuples/FlattenTuple.h

    rb3f9a0cb rafc1045  
    4545                        virtual void visit( UntypedOffsetofExpr * );
    4646                        virtual void visit( OffsetofExpr * );
     47                        virtual void visit( OffsetPackExpr * );
    4748                        virtual void visit( AttrExpr * );
    4849                        virtual void visit( LogicalExpr * );
Note: See TracChangeset for help on using the changeset viewer.