Changeset 02c816f


Ignore:
Timestamp:
Mar 7, 2018, 5:00:25 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
661214c
Parents:
9bfc9da
Message:

Strip address-of from generic member-access expressions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    r9bfc9da r02c816f  
    163163                        void premutate( DeclStmt *declStmt );
    164164                        Expression *postmutate( MemberExpr *memberExpr );
     165                        void premutate( AddressExpr *addrExpr );
     166                        Expression *postmutate( AddressExpr *addrExpr );
    165167                        Expression *postmutate( SizeofExpr *sizeofExpr );
    166168                        Expression *postmutate( AlignofExpr *alignofExpr );
     
    193195                        ScopedSet< std::string > knownOffsets;          ///< Set of non-generic types for which the offset array exists in the current scope, indexed by offsetofName
    194196                        UniqueName bufNamer;                           ///< Namer for VLA buffers
     197                        Expression * addrMember = nullptr;             ///< AddressExpr argument is MemberExpr?
    195198                };
    196199
     
    15961599                }
    15971600
     1601                void PolyGenericCalculator::premutate( AddressExpr * addrExpr ) {
     1602                        GuardValue( addrMember );
     1603                        // is the argument a MemberExpr before mutating?
     1604                        addrMember = dynamic_cast< MemberExpr * >( addrExpr->arg );
     1605                }
     1606
     1607                Expression * PolyGenericCalculator::postmutate( AddressExpr * addrExpr ) {
     1608                        if ( addrMember && addrMember != addrExpr->arg ) {
     1609                                // arg was a MemberExpr and has been mutated
     1610                                if ( UntypedExpr * untyped = dynamic_cast< UntypedExpr * >( addrExpr->arg ) ) {
     1611                                        if ( InitTweak::getFunctionName( untyped ) == "?+?" ) {
     1612                                                // MemberExpr was converted to pointer+offset, and it is not valid C to take the address of an addition, so strip the address-of
     1613                                                // TODO: should  addrExpr->arg->result be changed to addrExpr->result?
     1614                                                Expression * ret = addrExpr->arg;
     1615                                                addrExpr->arg = nullptr;
     1616                                                std::swap( addrExpr->env, ret->env );
     1617                                                delete addrExpr;
     1618                                                return ret;
     1619                                        }
     1620                                }
     1621                        }
     1622                        return addrExpr;
     1623                }
     1624
    15981625                ObjectDecl *PolyGenericCalculator::makeVar( const std::string &name, Type *type, Initializer *init ) {
    15991626                        ObjectDecl *newObj = new ObjectDecl( name, Type::StorageClasses(), LinkageSpec::C, nullptr, type, init );
Note: See TracChangeset for help on using the changeset viewer.