Changeset b0440b7


Ignore:
Timestamp:
Aug 8, 2017, 8:01:10 PM (4 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
9a4e996
Parents:
4618319
Message:

Prevent reference types from being added in Box through createDeref

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Lvalue.cc

    r4618319 rb0440b7  
    9494        } // namespace
    9595
     96        static bool referencesEliminated = false;
     97        // used by UntypedExpr::createDeref to determine whether result type of dereference should be ReferenceType or value type.
     98        bool referencesPermissable() {
     99                return ! referencesEliminated;
     100        }
     101
    96102        void convertLvalue( std::list< Declaration* >& translationUnit ) {
    97103                std::cerr << "convertLvalue" << std::endl;
     
    106112                mutateAll( translationUnit, collapser );
    107113                mutateAll( translationUnit, elim );  // last because other passes need reference types to work
     114
     115                // from this point forward, no other pass should create reference types.
     116                referencesEliminated = true;
    108117        }
    109118
     
    134143                                // can be of differing lengths only when function is variadic
    135144                                assertf( ftype->get_parameters().size() == appExpr->get_args().size() || ftype->get_isVarArgs(), "ApplicationExpr args do not match formal parameter type." );
     145
     146                                if ( isIntrinsicReference( appExpr ) ) {
     147                                        // eliminate reference types from intrinsic applications - now they return lvalues
     148                                        appExpr->set_result( appExpr->get_result()->stripReferences() );
     149                                        appExpr->get_result()->set_lvalue( true );
     150                                }
     151
    136152                                unsigned int i = 0;
    137153                                const unsigned int end = ftype->get_parameters().size();
     
    252268                                }
    253269                                if ( ResolvExpr::typesCompatibleIgnoreQualifiers( castExpr->get_result(), castExpr->get_arg()->get_result()->stripReferences(), SymTab::Indexer() ) ) {
    254                                         // can remove cast if types are compatible
     270                                        // can remove cast if types are compatible, changing expression type to value type
     271                                        ret->set_result( castExpr->get_result()->clone() );
    255272                                        castExpr->set_arg( nullptr );
    256273                                        delete castExpr;
  • src/GenPoly/Lvalue.h

    r4618319 rb0440b7  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Lvalue.h -- 
     7// Lvalue.h --
    88//
    99// Author           : Richard C. Bilson
     
    2424        /// replaces return type of `lvalue T` with `T*`, along with appropriate address-of and dereference operators
    2525        void convertLvalue( std::list< Declaration* >& translationUnit );
     26
     27        /// true after reference types have been eliminated from the source code. After this point, reference types should not be added to the AST.
     28        bool referencesPermissable();
    2629} // namespace GenPoly
    2730
  • src/SynTree/Expression.cc

    r4618319 rb0440b7  
    3434#include "InitTweak/InitTweak.h"
    3535
     36#include "GenPoly/Lvalue.h"
    3637
    3738Expression::Expression( Expression *_aname ) : result( 0 ), env( 0 ), argName( _aname ) {}
     
    409410                Type * base = InitTweak::getPointerBase( type );
    410411                assertf( base, "expected pointer type in dereference (type was %s)", toString( type ).c_str() );
    411                 ret->set_result( new ReferenceType( Type::Qualifiers(), base->clone() ) );
     412                ret->set_result( base->clone() );
     413                if ( GenPoly::referencesPermissable() ) {
     414                        // if references are still allowed in the AST, dereference returns a reference
     415                        ret->set_result( new ReferenceType( Type::Qualifiers(), ret->get_result() ) );
     416                } else {
     417                        // references have been removed, in which case dereference returns an lvalue of the base type.
     418                        ret->get_result()->set_lvalue( true );
     419                }
    412420        }
    413421        return ret;
Note: See TracChangeset for help on using the changeset viewer.