Changes in / [ba417e2:f49b3fc]


Ignore:
Location:
src/AST
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    rba417e2 rf49b3fc  
    21242124                                old->location,
    21252125                                GET_ACCEPT_1(member, DeclWithType),
    2126                                 GET_ACCEPT_1(aggregate, Expr),
    2127                                 ast::MemberExpr::NoOpConstructionChosen
     2126                                GET_ACCEPT_1(aggregate, Expr)
    21282127                        )
    21292128                );
  • src/AST/Expr.cpp

    rba417e2 rf49b3fc  
    158158        assert( aggregate->result );
    159159
    160         // Deep copy on result type avoids mutation on transitively multiply referenced object.
    161         //
    162         // Example, adapted from parts of builtins and bootloader:
    163         //
    164         // forall(dtype T)
    165         // struct __Destructor {
    166         //   T * object;
    167         //   void (*dtor)(T *);
    168         // };
    169         //
    170         // forall(dtype S)
    171         // void foo(__Destructor(S) &d) {
    172         //   if (d.dtor) {  // here
    173         //   }
    174         // }
    175         //
    176         // Let e be the "d.dtor" guard espression, which is MemberExpr after resolve.  Let d be the
    177         // declaration of member __Destructor.dtor (an ObjectDecl), as accessed via the top-level
    178         // declaration of __Destructor.  Consider the types e.result and d.type.  In the old AST, one
    179         // is a clone of the other.  Ordinary new-AST use would set them up as a multiply-referenced
    180         // object.
    181         //
    182         // e.result: PointerType
    183         // .base: FunctionType
    184         // .params.front(): ObjectDecl, the anonymous parameter of type T*
    185         // .type: PointerType
    186         // .base: TypeInstType
    187         // let x = that
    188         // let y = similar, except start from d.type
    189         //
    190         // Consider two code lines down, genericSubstitution(...).apply(result).
    191         //
    192         // Applying this chosen-candidate's type substitution means modifying x, substituting
    193         // S for T.  This mutation should affect x and not y.
    194 
    195         result = deepCopy(mem->get_type());
    196 
     160        // take ownership of member type
     161        result = mem->get_type();
    197162        // substitute aggregate generic parameters into member type
    198163        genericSubstitution( aggregate->result ).apply( result );
    199164        // ensure lvalue and appropriate restrictions from aggregate type
    200165        add_qualifiers( result, aggregate->result->qualifiers | CV::Lvalue );
    201 }
    202 
    203 MemberExpr::MemberExpr( const CodeLocation & loc, const DeclWithType * mem, const Expr * agg,
    204     MemberExpr::NoOpConstruction overloadSelector )
    205 : Expr( loc ), member( mem ), aggregate( agg ) {
    206         assert( member );
    207         assert( aggregate );
    208         assert( aggregate->result );
    209         (void) overloadSelector;
    210166}
    211167
  • src/AST/Expr.hpp

    rba417e2 rf49b3fc  
    358358        MemberExpr * clone() const override { return new MemberExpr{ *this }; }
    359359        MUTATE_FRIEND
    360 
    361         // Custructor overload meant only for AST conversion
    362         enum NoOpConstruction { NoOpConstructionChosen };
    363         MemberExpr( const CodeLocation & loc, const DeclWithType * mem, const Expr * agg,
    364             NoOpConstruction overloadSelector );
    365         friend class ::ConverterOldToNew;
    366         friend class ::ConverterNewToOld;
    367360};
    368361
Note: See TracChangeset for help on using the changeset viewer.