Ignore:
Timestamp:
Nov 14, 2022, 11:52:44 AM (3 years ago)
Author:
caparson <caparson@…>
Branches:
ADT, ast-experimental, master
Children:
7d9598d8
Parents:
b77f0e1 (diff), 19a8c40 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/InstantiateGenericNew.cpp

    rb77f0e1 r63be3387  
    1010// Created On       : Tue Aug 16 10:51:00 2022
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Sep 13 16:03:00 2022
    13 // Update Count     : 0
     12// Last Modified On : Mon Oct 31 16:48:00 2022
     13// Update Count     : 1
    1414//
    1515
     
    378378                //   Ptr(int) p;
    379379                //   int i;
     380                // The original expression:
    380381                //   p.x = &i;
    381                 // becomes
    382                 //   int *& _dtype_static_member_0 = (int **)&p.x;
    383                 //   _dtype_static_member_0 = &i;
     382                // Becomes the expression/declaration:
     383                //   int *& _dtype_static_member_0;
     384                //   (_dtype_static_member_0 = (int**)&p.x,
     385                //    _dtype_static_member_0) = &i;
     386
     387                // The declaration is simple:
    384388                static UniqueName tmpNamer( "_dtype_static_member_" );
    385                 ast::Expr * init = new ast::CastExpr( location,
    386                         new ast::AddressExpr( location, memberExpr ),
    387                         new ast::PointerType( ast::deepCopy( concType ) ),
    388                         ast::ExplicitCast
    389                 );
    390389                ast::ObjectDecl * tmp = new ast::ObjectDecl( location,
    391390                        tmpNamer.newName(),
    392391                        new ast::ReferenceType( concType ),
    393                         new ast::SingleInit( location, init ),
     392                        nullptr,
    394393                        ast::Storage::Classes(),
    395394                        ast::Linkage::C
    396395                );
    397396                stmtsToAddBefore.push_back( new ast::DeclStmt( location, tmp ) );
    398                 return new ast::VariableExpr( location, tmp );
     397
     398                // The expression is more complex, uses references and reference /
     399                // pointer parity. But breaking it up risks reordering.
     400                return new ast::CommaExpr( location,
     401                        ast::UntypedExpr::createAssign( location,
     402                                new ast::VariableExpr( location, tmp ),
     403                                new ast::CastExpr( location,
     404                                        new ast::AddressExpr( location, memberExpr ),
     405                                        new ast::PointerType( ast::deepCopy( concType ) ),
     406                                        ast::ExplicitCast
     407                                )
     408                        ),
     409                        new ast::VariableExpr( location, tmp )
     410                );
    399411        } else {
    400412                // Here, it can simply add a cast to actual types.
     
    476488};
    477489
    478 // I think this and the UnionInstType can be made into a template function.
    479490ast::Type const * GenericInstantiator::postvisit(
    480491                ast::StructInstType const * inst ) {
Note: See TracChangeset for help on using the changeset viewer.