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

Make offsetof expressions work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    r5721a6d r2a4b088  
    811811        }
    812812
     813        template< typename StructOrUnionType >
     814        void AlternativeFinder::addOffsetof( StructOrUnionType *aggInst, const std::string &name ) {
     815                std::list< Declaration* > members;
     816                aggInst->lookup( name, members );
     817                for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) {
     818                        if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( *i ) ) {
     819                                alternatives.push_back( Alternative( new OffsetofExpr( aggInst->clone(), dwt->clone() ), env, Cost::zero ) );
     820                                renameTypes( alternatives.back().expr );
     821                        } else {
     822                                assert( false );
     823                        }
     824                }
     825        }
     826       
     827        void AlternativeFinder::visit( UntypedOffsetofExpr *offsetofExpr ) {
     828                AlternativeFinder funcFinder( indexer, env );
     829                if ( StructInstType *structInst = dynamic_cast< StructInstType* >( offsetofExpr->get_type() ) ) {
     830                        addOffsetof( structInst, offsetofExpr->get_member() );
     831                } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( offsetofExpr->get_type() ) ) {
     832                        addOffsetof( unionInst, offsetofExpr->get_member() );
     833                }
     834        }
     835       
    813836        void AlternativeFinder::visit( OffsetofExpr *offsetofExpr ) {
    814837                alternatives.push_back( Alternative( offsetofExpr->clone(), env, Cost::zero ) );
Note: See TracChangeset for help on using the changeset viewer.