Changes in / [45161b4d:b11fac4]


Ignore:
Location:
src/GenPoly
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    r45161b4d rb11fac4  
    292292                        /// adds type parameters to the layout call; will generate the appropriate parameters if needed
    293293                        void addOtypeParamsToLayoutCall( UntypedExpr *layoutCall, const std::list< Type* > &otypeParams );
     294
     295                        /// Enters a new scope for type-variables, adding the type variables from ty
     296                        void beginTypeScope( Type *ty );
     297                        /// Exits the type-variable scope
     298                        void endTypeScope();
    294299                       
    295300                        ScopedSet< std::string > knownLayouts;          ///< Set of generic type layouts known in the current scope, indexed by sizeofName
     
    18211826////////////////////////////////////////// PolyGenericCalculator ////////////////////////////////////////////////////
    18221827
     1828                void PolyGenericCalculator::beginTypeScope( Type *ty ) {
     1829                        scopeTyVars.beginScope();
     1830                        makeTyVarMap( ty, scopeTyVars );
     1831                }
     1832
     1833                void PolyGenericCalculator::endTypeScope() {
     1834                        scopeTyVars.endScope();
     1835                }
     1836
    18231837                template< typename DeclClass >
    18241838                DeclClass * PolyGenericCalculator::handleDecl( DeclClass *decl, Type *type ) {
    1825                         scopeTyVars.beginScope();
    1826                         makeTyVarMap( type, scopeTyVars );
     1839                        beginTypeScope( type );
     1840                        knownLayouts.beginScope();
     1841                        knownOffsets.beginScope();
    18271842
    18281843                        DeclClass *ret = static_cast< DeclClass *>( Mutator::mutate( decl ) );
    18291844
    1830                         scopeTyVars.endScope();
     1845                        knownOffsets.endScope();
     1846                        knownLayouts.endScope();
     1847                        endTypeScope();
    18311848                        return ret;
    18321849                }
     
    18501867
    18511868                Type * PolyGenericCalculator::mutate( PointerType *pointerType ) {
    1852                         scopeTyVars.beginScope();
    1853                         makeTyVarMap( pointerType, scopeTyVars );
     1869                        beginTypeScope( pointerType );
    18541870
    18551871                        Type *ret = Mutator::mutate( pointerType );
    18561872
    1857                         scopeTyVars.endScope();
     1873                        endTypeScope();
    18581874                        return ret;
    18591875                }
    18601876
    18611877                Type * PolyGenericCalculator::mutate( FunctionType *funcType ) {
    1862                         scopeTyVars.beginScope();
    1863                         makeTyVarMap( funcType, scopeTyVars );
     1878                        beginTypeScope( funcType );
    18641879
    18651880                        // make sure that any type information passed into the function is accounted for
     
    18741889                        Type *ret = Mutator::mutate( funcType );
    18751890
    1876                         scopeTyVars.endScope();
     1891                        endTypeScope();
    18771892                        return ret;
    18781893                }
  • src/GenPoly/Lvalue.cc

    r45161b4d rb11fac4  
    1717
    1818#include "Lvalue.h"
     19
     20#include "GenPoly.h"
    1921
    2022#include "SynTree/Declaration.h"
     
    6365
    6466        namespace {
    65                 bool isLvalueRet( FunctionType *function ) {
    66                         if ( ! function->get_returnVals().empty() ) {
    67                                 return function->get_returnVals().front()->get_type()->get_isLvalue();
    68                         } else {
    69                                 return false;
    70                         } // if
     67                Type* isLvalueRet( FunctionType *function ) {
     68                        if ( function->get_returnVals().empty() ) return 0;
     69                        Type *ty = function->get_returnVals().front()->get_type();
     70                        return ty->get_isLvalue() ? ty : 0;
    7171                }
    7272
     
    107107                        assert( function );
    108108
    109                         std::string typeName;
    110                         if ( isLvalueRet( function ) && ! isIntrinsicApp( appExpr ) ) {
     109                        Type *funType = isLvalueRet( function );
     110                        if ( funType && ! isIntrinsicApp( appExpr ) ) {
     111                                Expression *expr = appExpr;
     112                                Type *appType = appExpr->get_results().front();
     113                                if ( isPolyType( funType ) ) {
     114                                        // make sure cast for polymorphic type is inside dereference
     115                                        expr = new CastExpr( appExpr, new PointerType( Type::Qualifiers(), appType->clone() ) );
     116                                }
    111117                                UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
    112                                 deref->get_results().push_back( appExpr->get_results().front() );
    113                                 appExpr->get_results().front() = new PointerType( Type::Qualifiers(), deref->get_results().front()->clone() );
    114                                 deref->get_args().push_back( appExpr );
     118                                deref->get_results().push_back( appType->clone() );
     119                                appExpr->get_results().front() = new PointerType( Type::Qualifiers(), appType );
     120                                deref->get_args().push_back( expr );
    115121                                return deref;
    116122                        } else {
Note: See TracChangeset for help on using the changeset viewer.