Changeset 2a4b088 for src/SynTree


Ignore:
Timestamp:
Feb 2, 2016, 2:00:37 PM (10 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:
4789f44, b10c9959
Parents:
5721a6d
Message:

Make offsetof expressions work

Location:
src/SynTree
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Expression.cc

    r5721a6d r2a4b088  
    163163}
    164164
     165UntypedOffsetofExpr::UntypedOffsetofExpr( Type *type_, const std::string &member_, Expression *_aname ) :
     166                Expression( _aname ), type(type_), member(member_) {
     167        add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
     168}
     169
     170UntypedOffsetofExpr::UntypedOffsetofExpr( const UntypedOffsetofExpr &other ) :
     171        Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {}
     172
     173UntypedOffsetofExpr::~UntypedOffsetofExpr() {
     174        delete type;
     175}
     176
     177void UntypedOffsetofExpr::print( std::ostream &os, int indent) const {
     178        os << std::string( indent, ' ' ) << "Untyped Offsetof Expression on member " << member << " of ";
     179
     180        if ( type ) {
     181                type->print(os, indent + 2);
     182        } else {
     183                os << "<NULL>";
     184        }
     185
     186        os << std::endl;
     187        Expression::print( os, indent );
     188}
     189
    165190OffsetofExpr::OffsetofExpr( Type *type_, DeclarationWithType *member_, Expression *_aname ) :
    166191                Expression( _aname ), type(type_), member(member_) {
  • src/SynTree/Expression.h

    r5721a6d r2a4b088  
    319319};
    320320
     321/// UntypedOffsetofExpr represents an offsetof expression before resolution
     322class UntypedOffsetofExpr : public Expression {
     323  public:
     324        UntypedOffsetofExpr( Type *type, const std::string &member, Expression *_aname = 0 );
     325        UntypedOffsetofExpr( const UntypedOffsetofExpr &other );
     326        virtual ~UntypedOffsetofExpr();
     327
     328        std::string get_member() const { return member; }
     329        void set_member( const std::string &newValue ) { member = newValue; }
     330        Type *get_type() const { return type; }
     331        void set_type( Type *newValue ) { type = newValue; }
     332
     333        virtual UntypedOffsetofExpr *clone() const { return new UntypedOffsetofExpr( *this ); }
     334        virtual void accept( Visitor &v ) { v.visit( this ); }
     335        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     336        virtual void print( std::ostream &os, int indent = 0 ) const;
     337  private:
     338        Type *type;
     339        std::string member;
     340};
     341
    321342/// OffsetofExpr represents an offsetof expression
    322343class OffsetofExpr : public Expression {
  • src/SynTree/Mutator.cc

    r5721a6d r2a4b088  
    261261}
    262262
     263Expression *Mutator::mutate( UntypedOffsetofExpr *offsetofExpr ) {
     264        mutateAll( offsetofExpr->get_results(), *this );
     265        offsetofExpr->set_type( maybeMutate( offsetofExpr->get_type(), *this ) );
     266        return offsetofExpr;
     267}
     268
    263269Expression *Mutator::mutate( OffsetofExpr *offsetofExpr ) {
    264270        mutateAll( offsetofExpr->get_results(), *this );
  • src/SynTree/Mutator.h

    r5721a6d r2a4b088  
    6565        virtual Expression* mutate( SizeofExpr *sizeofExpr );
    6666        virtual Expression* mutate( AlignofExpr *alignofExpr );
     67        virtual Expression* mutate( UntypedOffsetofExpr *offsetofExpr );
    6768        virtual Expression* mutate( OffsetofExpr *offsetofExpr );
    6869        virtual Expression* mutate( AttrExpr *attrExpr );
  • src/SynTree/SynTree.h

    r5721a6d r2a4b088  
    7070class SizeofExpr;
    7171class AlignofExpr;
     72class UntypedOffsetofExpr;
    7273class OffsetofExpr;
    7374class AttrExpr;
  • src/SynTree/Visitor.cc

    r5721a6d r2a4b088  
    219219}
    220220
     221void Visitor::visit( UntypedOffsetofExpr *offsetofExpr ) {
     222        acceptAll( offsetofExpr->get_results(), *this );
     223        maybeAccept( offsetofExpr->get_type(), *this );
     224}
     225
    221226void Visitor::visit( OffsetofExpr *offsetofExpr ) {
    222227        acceptAll( offsetofExpr->get_results(), *this );
  • src/SynTree/Visitor.h

    r5721a6d r2a4b088  
    6565        virtual void visit( SizeofExpr *sizeofExpr );
    6666        virtual void visit( AlignofExpr *alignofExpr );
     67        virtual void visit( UntypedOffsetofExpr *offsetofExpr );
    6768        virtual void visit( OffsetofExpr *offsetofExpr );
    6869        virtual void visit( AttrExpr *attrExpr );
Note: See TracChangeset for help on using the changeset viewer.