Changeset 906e24d


Ignore:
Timestamp:
Sep 15, 2016, 10:17:16 AM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, 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:
aa8f9df
Parents:
96a10cd
git-author:
Rob Schluntz <rschlunt@…> (09/14/16 22:32:34)
git-committer:
Rob Schluntz <rschlunt@…> (09/15/16 10:17:16)
Message:

replace results list on Expressions with a single Type field

Location:
src
Files:
2 deleted
28 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r96a10cd r906e24d  
    309309                                                        UntypedExpr * newExpr = new UntypedExpr( new NameExpr( "*?" ) );
    310310                                                        newExpr->get_args().push_back( *arg );
    311                                                         assert( (*arg)->get_results().size() == 1 );
    312                                                         Type * type = InitTweak::getPointerBase( (*arg)->get_results().front() );
     311                                                        Type * type = InitTweak::getPointerBase( (*arg)->get_result() );
    313312                                                        assert( type );
    314                                                         newExpr->get_results().push_back( type->clone() );
     313                                                        newExpr->set_result( type->clone() );
    315314                                                        *arg = newExpr;
    316315                                                } // if
     
    527526                extension( castExpr );
    528527                output << "(";
    529                 if ( castExpr->get_results().empty() ) {
     528                if ( castExpr->get_result()->isVoid() ) {
    530529                        output << "(void)" ;
    531                 } else if ( ! castExpr->get_results().front()->get_isLvalue() ) {
     530                } else if ( ! castExpr->get_result()->get_isLvalue() ) {
    532531                        // at least one result type of cast, but not an lvalue
    533532                        output << "(";
    534                         output << genType( castExpr->get_results().front(), "" );
     533                        output << genType( castExpr->get_result(), "" );
    535534                        output << ")";
    536535                } else {
  • src/ControlStruct/Mutate.cc

    r96a10cd r906e24d  
    2323#include "MLEMutator.h"
    2424#include "ForExprMutator.h"
    25 #include "LabelTypeChecker.h"
    2625//#include "ExceptMutator.h"
    2726
     
    4140
    4241                //ExceptMutator exc;
    43                 // LabelTypeChecker lbl;
    4442
    4543                mutateAll( translationUnit, formut );
    4644                acceptAll( translationUnit, lfix );
    4745                //mutateAll( translationUnit, exc );
    48                 //acceptAll( translationUnit, lbl );
    4946        }
    5047} // namespace CodeGen
  • src/ControlStruct/module.mk

    r96a10cd r906e24d  
    66## file "LICENCE" distributed with Cforall.
    77##
    8 ## module.mk -- 
     8## module.mk --
    99##
    1010## Author           : Richard C. Bilson
     
    1919        ControlStruct/MLEMutator.cc \
    2020        ControlStruct/Mutate.cc \
    21         ControlStruct/ForExprMutator.cc \
    22         ControlStruct/LabelTypeChecker.cc
     21        ControlStruct/ForExprMutator.cc
    2322
  • src/GenPoly/Box.cc

    r96a10cd r906e24d  
    782782
    783783                        // add size/align for generic types to parameter list
    784                         if ( appExpr->get_function()->get_results().empty() ) return;
    785                         FunctionType *funcType = getFunctionType( appExpr->get_function()->get_results().front() );
     784                        if ( ! appExpr->get_function()->has_result() ) return;
     785                        FunctionType *funcType = getFunctionType( appExpr->get_function()->get_result() );
    786786                        assert( funcType );
    787787
     
    799799                        for ( ; fnParm != funcType->get_parameters().end() && fnArg != appExpr->get_args().end(); ++fnParm, ++fnArg ) {
    800800                                VariableExpr *fnArgBase = getBaseVar( *fnArg );
    801                                 if ( ! fnArgBase || fnArgBase->get_results().empty() ) continue;
    802                                 passArgTypeVars( appExpr, (*fnParm)->get_type(), fnArgBase->get_results().front(), arg, exprTyVars, seenTypes );
     801                                if ( ! fnArgBase ) continue; // xxx - previously had check for non-empty fnArgBase results
     802                                passArgTypeVars( appExpr, (*fnParm)->get_type(), fnArgBase->get_result(), arg, exprTyVars, seenTypes );
    803803                        }
    804804                }
     
    890890                        Type * adapteeType = new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) );
    891891                        appExpr->get_args().push_front( new CastExpr( appExpr->get_function(), adapteeType ) );
    892                         appExpr->set_function( new NameExpr( adapterName ) );
     892                        appExpr->set_function( new NameExpr( adapterName ) ); // xxx - result is never set on NameExpr
    893893
    894894                        return ret;
     
    896896
    897897                void Pass1::boxParam( Type *param, Expression *&arg, const TyVarMap &exprTyVars ) {
    898                         assert( ! arg->get_results().empty() );
     898                        assert( arg->has_result() );
    899899                        if ( isPolyType( param, exprTyVars ) ) {
    900                                 if ( isPolyType( arg->get_results().front() ) ) {
     900                                if ( isPolyType( arg->get_result() ) ) {
    901901                                        // if the argument's type is polymorphic, we don't need to box again!
    902902                                        return;
    903                                 } else if ( arg->get_results().front()->get_isLvalue() ) {
     903                                } else if ( arg->get_result()->get_isLvalue() ) {
    904904                                        // VariableExpr and MemberExpr are lvalues; need to check this isn't coming from the second arg of a comma expression though (not an lvalue)
    905905                                        // xxx - need to test that this code is still reachable
     
    987987                                        UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
    988988                                        deref->get_args().push_back( new CastExpr( new VariableExpr( param ), new PointerType( Type::Qualifiers(), arg->get_type()->clone() ) ) );
    989                                         deref->get_results().push_back( arg->get_type()->clone() );
     989                                        deref->set_result( arg->get_type()->clone() );
    990990                                        return deref;
    991991                                } // if
     
    11241124                        } // if
    11251125                        addAssign->get_args().push_back( new NameExpr( sizeofName( mangleType( polyType ) ) ) );
    1126                         addAssign->get_results().front() = appExpr->get_results().front()->clone();
     1126                        addAssign->set_result( appExpr->get_result()->clone() );
    11271127                        if ( appExpr->get_env() ) {
    11281128                                addAssign->set_env( appExpr->get_env() );
     
    11381138                                if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic ) {
    11391139                                        if ( varExpr->get_var()->get_name() == "?[?]" ) {
    1140                                                 assert( ! appExpr->get_results().empty() );
     1140                                                assert( appExpr->has_result() );
    11411141                                                assert( appExpr->get_args().size() == 2 );
    1142                                                 Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), scopeTyVars, env );
    1143                                                 Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), scopeTyVars, env );
     1142                                                Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_result(), scopeTyVars, env );
     1143                                                Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_result(), scopeTyVars, env );
    11441144                                                assert( ! baseType1 || ! baseType2 ); // the arguments cannot both be polymorphic pointers
    11451145                                                UntypedExpr *ret = 0;
     
    11611161                                                } // if
    11621162                                                if ( baseType1 || baseType2 ) {
    1163                                                         ret->get_results().push_front( appExpr->get_results().front()->clone() );
     1163                                                        ret->set_result( appExpr->get_result()->clone() );
    11641164                                                        if ( appExpr->get_env() ) {
    11651165                                                                ret->set_env( appExpr->get_env() );
     
    11711171                                                } // if
    11721172                                        } else if ( varExpr->get_var()->get_name() == "*?" ) {
    1173                                                 assert( ! appExpr->get_results().empty() );
     1173                                                assert( appExpr->has_result() );
    11741174                                                assert( ! appExpr->get_args().empty() );
    1175                                                 if ( isPolyType( appExpr->get_results().front(), scopeTyVars, env ) ) {
     1175                                                if ( isPolyType( appExpr->get_result(), scopeTyVars, env ) ) {
    11761176                                                        Expression *ret = appExpr->get_args().front();
    1177                                                         delete ret->get_results().front();
    1178                                                         ret->get_results().front() = appExpr->get_results().front()->clone();
     1177                                                        delete ret->get_result();
     1178                                                        ret->set_result( appExpr->get_result()->clone() );
    11791179                                                        if ( appExpr->get_env() ) {
    11801180                                                                ret->set_env( appExpr->get_env() );
     
    11861186                                                } // if
    11871187                                        } else if ( varExpr->get_var()->get_name() == "?++" || varExpr->get_var()->get_name() == "?--" ) {
    1188                                                 assert( ! appExpr->get_results().empty() );
     1188                                                assert( appExpr->has_result() );
    11891189                                                assert( appExpr->get_args().size() == 1 );
    1190                                                 if ( Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env ) ) {
    1191                                                         Type *tempType = appExpr->get_results().front()->clone();
     1190                                                if ( Type *baseType = isPolyPtr( appExpr->get_result(), scopeTyVars, env ) ) {
     1191                                                        Type *tempType = appExpr->get_result()->clone();
    11921192                                                        if ( env ) {
    11931193                                                                env->apply( tempType );
     
    12061206                                                } // if
    12071207                                        } else if ( varExpr->get_var()->get_name() == "++?" || varExpr->get_var()->get_name() == "--?" ) {
    1208                                                 assert( ! appExpr->get_results().empty() );
     1208                                                assert( appExpr->has_result() );
    12091209                                                assert( appExpr->get_args().size() == 1 );
    1210                                                 if ( Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env ) ) {
     1210                                                if ( Type *baseType = isPolyPtr( appExpr->get_result(), scopeTyVars, env ) ) {
    12111211                                                        return makeIncrDecrExpr( appExpr, baseType, varExpr->get_var()->get_name() == "++?" );
    12121212                                                } // if
    12131213                                        } else if ( varExpr->get_var()->get_name() == "?+?" || varExpr->get_var()->get_name() == "?-?" ) {
    1214                                                 assert( ! appExpr->get_results().empty() );
     1214                                                assert( appExpr->has_result() );
    12151215                                                assert( appExpr->get_args().size() == 2 );
    1216                                                 Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), scopeTyVars, env );
    1217                                                 Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), scopeTyVars, env );
     1216                                                Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_result(), scopeTyVars, env );
     1217                                                Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_result(), scopeTyVars, env );
    12181218                                                if ( baseType1 && baseType2 ) {
    12191219                                                        UntypedExpr *divide = new UntypedExpr( new NameExpr( "?/?" ) );
    12201220                                                        divide->get_args().push_back( appExpr );
    12211221                                                        divide->get_args().push_back( new SizeofExpr( baseType1->clone() ) );
    1222                                                         divide->get_results().push_front( appExpr->get_results().front()->clone() );
     1222                                                        divide->set_result( appExpr->get_result()->clone() );
    12231223                                                        if ( appExpr->get_env() ) {
    12241224                                                                divide->set_env( appExpr->get_env() );
     
    12381238                                                } // if
    12391239                                        } else if ( varExpr->get_var()->get_name() == "?+=?" || varExpr->get_var()->get_name() == "?-=?" ) {
    1240                                                 assert( ! appExpr->get_results().empty() );
     1240                                                assert( appExpr->has_result() );
    12411241                                                assert( appExpr->get_args().size() == 2 );
    1242                                                 Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env );
     1242                                                Type *baseType = isPolyPtr( appExpr->get_result(), scopeTyVars, env );
    12431243                                                if ( baseType ) {
    12441244                                                        UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
     
    12661266                        useRetval = oldUseRetval;
    12671267
    1268                         assert( ! appExpr->get_function()->get_results().empty() );
    1269                         PointerType *pointer = dynamic_cast< PointerType *>( appExpr->get_function()->get_results().front() );
    1270                         assert( pointer );
    1271                         FunctionType *function = dynamic_cast< FunctionType *>( pointer->get_base() );
    1272                         assert( function );
     1268                        assert( appExpr->get_function()->has_result() );
     1269                        PointerType *pointer = safe_dynamic_cast< PointerType *>( appExpr->get_function()->get_result() );
     1270                        FunctionType *function = safe_dynamic_cast< FunctionType *>( pointer->get_base() );
    12731271
    12741272                        if ( Expression *newExpr = handleIntrinsics( appExpr ) ) {
     
    13081306
    13091307                Expression *Pass1::mutate( UntypedExpr *expr ) {
    1310                         if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), scopeTyVars, env ) ) {
     1308                        if ( expr->has_result() && isPolyType( expr->get_result(), scopeTyVars, env ) ) {
    13111309                                if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) {
    13121310                                        if ( name->get_name() == "*?" ) {
     
    13221320
    13231321                Expression *Pass1::mutate( AddressExpr *addrExpr ) {
    1324                         assert( ! addrExpr->get_arg()->get_results().empty() );
     1322                        assert( addrExpr->get_arg()->has_result() && ! addrExpr->get_arg()->get_result()->isVoid() );
    13251323
    13261324                        bool needs = false;
    13271325                        if ( UntypedExpr *expr = dynamic_cast< UntypedExpr *>( addrExpr->get_arg() ) ) {
    1328                                 if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), scopeTyVars, env ) ) {
     1326                                if ( expr->has_result() && isPolyType( expr->get_result(), scopeTyVars, env ) ) {
    13291327                                        if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) {
    13301328                                                if ( name->get_name() == "*?" ) {
    13311329                                                        if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr->get_args().front() ) ) {
    1332                                                                 assert( ! appExpr->get_function()->get_results().empty() );
    1333                                                                 PointerType *pointer = dynamic_cast< PointerType *>( appExpr->get_function()->get_results().front() );
    1334                                                                 assert( pointer );
    1335                                                                 FunctionType *function = dynamic_cast< FunctionType *>( pointer->get_base() );
    1336                                                                 assert( function );
     1330                                                                assert( appExpr->get_function()->has_result() );
     1331                                                                PointerType *pointer = safe_dynamic_cast< PointerType *>( appExpr->get_function()->get_result() );
     1332                                                                FunctionType *function = safe_dynamic_cast< FunctionType *>( pointer->get_base() );
    13371333                                                                needs = needsAdapter( function, scopeTyVars );
    13381334                                                        } // if
     
    13431339                        // isPolyType check needs to happen before mutating addrExpr arg, so pull it forward
    13441340                        // out of the if condition.
    1345                         bool polytype = isPolyType( addrExpr->get_arg()->get_results().front(), scopeTyVars, env );
     1341                        bool polytype = isPolyType( addrExpr->get_arg()->get_result(), scopeTyVars, env );
    13461342                        addrExpr->set_arg( mutateExpression( addrExpr->get_arg() ) );
    13471343                        if ( polytype || needs ) {
    13481344                                Expression *ret = addrExpr->get_arg();
    1349                                 delete ret->get_results().front();
    1350                                 ret->get_results().front() = addrExpr->get_results().front()->clone();
     1345                                delete ret->get_result();
     1346                                ret->set_result( addrExpr->get_result()->clone() );
    13511347                                addrExpr->set_arg( 0 );
    13521348                                delete addrExpr;
     
    13861382                Statement * Pass1::mutate( ReturnStmt *returnStmt ) {
    13871383                        if ( retval && returnStmt->get_expr() ) {
    1388                                 assert( ! returnStmt->get_expr()->get_results().empty() );
     1384                                assert( returnStmt->get_expr()->has_result() && ! returnStmt->get_expr()->get_result()->isVoid() );
    13891385                                // ***** Code Removal ***** After introducing a temporary variable for all return expressions, the following code appears superfluous.
    13901386                                // if ( returnStmt->get_expr()->get_results().front()->get_isLvalue() ) {
     
    14661462                                // replace return statement with appropriate assignment to out parameter
    14671463                                Expression *retParm = new NameExpr( retval->get_name() );
    1468                                 retParm->get_results().push_back( new PointerType( Type::Qualifiers(), retval->get_type()->clone() ) );
     1464                                retParm->set_result( new PointerType( Type::Qualifiers(), retval->get_type()->clone() ) );
    14691465                                assignExpr->get_args().push_back( retParm );
    14701466                                assignExpr->get_args().push_back( returnStmt->get_expr() );
  • src/GenPoly/Lvalue.cc

    r96a10cd r906e24d  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Lvalue.cc -- 
     7// Lvalue.cc --
    88//
    99// Author           : Richard C. Bilson
     
    4141                  public:
    4242                        Pass1();
    43  
     43
    4444                        virtual Expression *mutate( ApplicationExpr *appExpr );
    4545                        virtual Statement *mutate( ReturnStmt *appExpr );
     
    9999                        appExpr->get_function()->acceptMutator( *this );
    100100                        mutateAll( appExpr->get_args(), *this );
    101  
    102                         assert( ! appExpr->get_function()->get_results().empty() );
    103101
    104                         PointerType *pointer = dynamic_cast< PointerType* >( appExpr->get_function()->get_results().front() );
    105                         assert( pointer );
    106                         FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() );
    107                         assert( function );
     102                        PointerType *pointer = safe_dynamic_cast< PointerType* >( appExpr->get_function()->get_result() );
     103                        FunctionType *function = safe_dynamic_cast< FunctionType* >( pointer->get_base() );
    108104
    109105                        Type *funType = isLvalueRet( function );
    110106                        if ( funType && ! isIntrinsicApp( appExpr ) ) {
    111107                                Expression *expr = appExpr;
    112                                 Type *appType = appExpr->get_results().front();
     108                                Type *appType = appExpr->get_result();
    113109                                if ( isPolyType( funType ) && ! isPolyType( appType ) ) {
    114110                                        // make sure cast for polymorphic type is inside dereference
     
    116112                                }
    117113                                UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
    118                                 deref->get_results().push_back( appType->clone() );
    119                                 appExpr->get_results().front() = new PointerType( Type::Qualifiers(), appType );
     114                                deref->set_result( appType->clone() );
     115                                appExpr->set_result( new PointerType( Type::Qualifiers(), appType ) );
    120116                                deref->get_args().push_back( expr );
    121117                                return deref;
     
    127123                Statement * Pass1::mutate(ReturnStmt *retStmt) {
    128124                        if ( retval && retStmt->get_expr() ) {
    129                                 assert( ! retStmt->get_expr()->get_results().empty() );
    130                                 if ( retStmt->get_expr()->get_results().front()->get_isLvalue() ) {
     125                                if ( retStmt->get_expr()->get_result()->get_isLvalue() ) {
    131126                                        // ***** Code Removal ***** because casts may be stripped already
    132127
     
    155150                                retParm->set_type( new PointerType( Type::Qualifiers(), retParm->get_type() ) );
    156151                        } // if
    157  
     152
    158153                        Visitor::visit( funType );
    159154                }
  • src/GenPoly/Specialize.cc

    r96a10cd r906e24d  
    147147
    148148        Expression * Specialize::doSpecialization( Type *formalType, Expression *actual, InferredParams *inferParams ) {
    149                 assert( ! actual->get_results().empty() ); // using front, should have this assert
    150                 if ( needsSpecialization( formalType, actual->get_results().front(), env ) ) {
     149                assert( actual->has_result() );
     150                if ( needsSpecialization( formalType, actual->get_result(), env ) ) {
    151151                        FunctionType *funType;
    152152                        if ( ( funType = getFunctionType( formalType ) ) ) {
     
    171171        void Specialize::handleExplicitParams( ApplicationExpr *appExpr ) {
    172172                // create thunks for the explicit parameters
    173                 assert( ! appExpr->get_function()->get_results().empty() );
    174                 FunctionType *function = getFunctionType( appExpr->get_function()->get_results().front() );
     173                assert( appExpr->get_function()->has_result() );
     174                FunctionType *function = getFunctionType( appExpr->get_function()->get_result() );
    175175                assert( function );
    176176                std::list< DeclarationWithType* >::iterator formal;
     
    200200        Expression * Specialize::mutate( AddressExpr *addrExpr ) {
    201201                addrExpr->get_arg()->acceptMutator( *this );
    202                 assert( ! addrExpr->get_results().empty() );
    203                 addrExpr->set_arg( doSpecialization( addrExpr->get_results().front(), addrExpr->get_arg() ) );
     202                assert( addrExpr->has_result() );
     203                addrExpr->set_arg( doSpecialization( addrExpr->get_result(), addrExpr->get_arg() ) );
    204204                return addrExpr;
    205205        }
     
    207207        Expression * Specialize::mutate( CastExpr *castExpr ) {
    208208                castExpr->get_arg()->acceptMutator( *this );
    209                 if ( castExpr->get_results().empty() ) {
     209                if ( castExpr->get_result()->isVoid() ) {
    210210                        // can't specialize if we don't have a return value
    211211                        return castExpr;
    212212                }
    213                 Expression *specialized = doSpecialization( castExpr->get_results().front(), castExpr->get_arg() );
     213                Expression *specialized = doSpecialization( castExpr->get_result(), castExpr->get_arg() );
    214214                if ( specialized != castExpr->get_arg() ) {
    215215                        // assume here that the specialization incorporates the cast
  • src/InitTweak/FixInit.cc

    r96a10cd r906e24d  
    391391                                CP_CTOR_PRINT( std::cerr << "Type Substitution: " << *impCpCtorExpr->get_env() << std::endl; )
    392392                                // xxx - need to handle tuple arguments
    393                                 assert( ! arg->get_results().empty() );
    394                                 Type * result = arg->get_results().front();
     393                                assert( arg->has_result() );
     394                                Type * result = arg->get_result();
    395395                                if ( skipCopyConstruct( result ) ) continue; // skip certain non-copyable types
    396396                                // type may involve type variables, so apply type substitution to get temporary variable's actual type
     
    423423                        // level. Trying to pass that environment along.
    424424                        callExpr->set_env( impCpCtorExpr->get_env()->clone() );
    425                         for ( Type * result : appExpr->get_results() ) {
     425                        Type * result = appExpr->get_result();
     426                        if ( ! result->isVoid() ) {
     427                                // need to flatten result type and construct each
    426428                                result = result->clone();
    427429                                impCpCtorExpr->get_env()->apply( result );
     
    479481                                // know the result type of the assignment is the type of the LHS (minus the pointer), so
    480482                                // add that onto the assignment expression so that later steps have the necessary information
    481                                 assign->add_result( returnDecl->get_type()->clone() );
     483                                assign->set_result( returnDecl->get_type()->clone() );
    482484
    483485                                Expression * retExpr = new CommaExpr( assign, new VariableExpr( returnDecl ) );
    484                                 if ( callExpr->get_results().front()->get_isLvalue() ) {
     486                                if ( callExpr->get_result()->get_isLvalue() ) {
    485487                                        // lvalue returning functions are funny. Lvalue.cc inserts a *? in front of any lvalue returning
    486488                                        // non-intrinsic function. Add an AddressExpr to the call to negate the derefence and change the
     
    500502                                        UntypedExpr * deref = new UntypedExpr( new NameExpr( "*?" ) );
    501503                                        deref->get_args().push_back( retExpr );
    502                                         deref->add_result( resultType );
     504                                        deref->set_result( resultType );
    503505                                        retExpr = deref;
    504506                                } // if
     
    939941                Expression * FixCtorExprs::mutate( ConstructorExpr * ctorExpr ) {
    940942                        static UniqueName tempNamer( "_tmp_ctor_expr" );
    941                         assert( ctorExpr->get_results().size() == 1 );
    942                         ObjectDecl * tmp = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, nullptr, ctorExpr->get_results().front()->clone(), nullptr );
     943                        assert( ctorExpr->has_result() && ctorExpr->get_result()->size() == 1 );
     944                        ObjectDecl * tmp = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, nullptr, ctorExpr->get_result()->clone(), nullptr );
    943945                        addDeclaration( tmp );
    944946
     
    952954                        assign->get_args().push_back( new VariableExpr( tmp ) );
    953955                        assign->get_args().push_back( firstArg );
    954                         cloneAll( ctorExpr->get_results(), assign->get_results() );
     956                        assign->set_result( ctorExpr->get_result()->clone() );
    955957                        firstArg = assign;
    956958
  • src/InitTweak/InitTweak.cc

    r96a10cd r906e24d  
    340340                return allofCtorDtor( stmt, []( Expression * callExpr ){
    341341                        if ( ApplicationExpr * appExpr = isIntrinsicCallExpr( callExpr ) ) {
    342                                 assert( ! appExpr->get_function()->get_results().empty() );
    343                                 FunctionType *funcType = GenPoly::getFunctionType( appExpr->get_function()->get_results().front() );
     342                                FunctionType *funcType = GenPoly::getFunctionType( appExpr->get_function()->get_result() );
    344343                                assert( funcType );
    345344                                return funcType->get_parameters().size() == 1;
  • src/Makefile.in

    r96a10cd r906e24d  
    104104        ControlStruct/driver_cfa_cpp-Mutate.$(OBJEXT) \
    105105        ControlStruct/driver_cfa_cpp-ForExprMutator.$(OBJEXT) \
    106         ControlStruct/driver_cfa_cpp-LabelTypeChecker.$(OBJEXT) \
    107106        GenPoly/driver_cfa_cpp-Box.$(OBJEXT) \
    108107        GenPoly/driver_cfa_cpp-GenPoly.$(OBJEXT) \
     
    361360        ControlStruct/LabelGenerator.cc ControlStruct/LabelFixer.cc \
    362361        ControlStruct/MLEMutator.cc ControlStruct/Mutate.cc \
    363         ControlStruct/ForExprMutator.cc \
    364         ControlStruct/LabelTypeChecker.cc GenPoly/Box.cc \
     362        ControlStruct/ForExprMutator.cc GenPoly/Box.cc \
    365363        GenPoly/GenPoly.cc GenPoly/PolyMutator.cc \
    366364        GenPoly/ScrubTyVars.cc GenPoly/Lvalue.cc GenPoly/Specialize.cc \
     
    535533        ControlStruct/$(DEPDIR)/$(am__dirstamp)
    536534ControlStruct/driver_cfa_cpp-ForExprMutator.$(OBJEXT):  \
    537         ControlStruct/$(am__dirstamp) \
    538         ControlStruct/$(DEPDIR)/$(am__dirstamp)
    539 ControlStruct/driver_cfa_cpp-LabelTypeChecker.$(OBJEXT):  \
    540535        ControlStruct/$(am__dirstamp) \
    541536        ControlStruct/$(DEPDIR)/$(am__dirstamp)
     
    791786        -rm -f ControlStruct/driver_cfa_cpp-LabelFixer.$(OBJEXT)
    792787        -rm -f ControlStruct/driver_cfa_cpp-LabelGenerator.$(OBJEXT)
    793         -rm -f ControlStruct/driver_cfa_cpp-LabelTypeChecker.$(OBJEXT)
    794788        -rm -f ControlStruct/driver_cfa_cpp-MLEMutator.$(OBJEXT)
    795789        -rm -f ControlStruct/driver_cfa_cpp-Mutate.$(OBJEXT)
     
    896890@AMDEP_TRUE@@am__include@ @am__quote@ControlStruct/$(DEPDIR)/driver_cfa_cpp-LabelFixer.Po@am__quote@
    897891@AMDEP_TRUE@@am__include@ @am__quote@ControlStruct/$(DEPDIR)/driver_cfa_cpp-LabelGenerator.Po@am__quote@
    898 @AMDEP_TRUE@@am__include@ @am__quote@ControlStruct/$(DEPDIR)/driver_cfa_cpp-LabelTypeChecker.Po@am__quote@
    899892@AMDEP_TRUE@@am__include@ @am__quote@ControlStruct/$(DEPDIR)/driver_cfa_cpp-MLEMutator.Po@am__quote@
    900893@AMDEP_TRUE@@am__include@ @am__quote@ControlStruct/$(DEPDIR)/driver_cfa_cpp-Mutate.Po@am__quote@
     
    12111204@am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o ControlStruct/driver_cfa_cpp-ForExprMutator.obj `if test -f 'ControlStruct/ForExprMutator.cc'; then $(CYGPATH_W) 'ControlStruct/ForExprMutator.cc'; else $(CYGPATH_W) '$(srcdir)/ControlStruct/ForExprMutator.cc'; fi`
    12121205
    1213 ControlStruct/driver_cfa_cpp-LabelTypeChecker.o: ControlStruct/LabelTypeChecker.cc
    1214 @am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT ControlStruct/driver_cfa_cpp-LabelTypeChecker.o -MD -MP -MF ControlStruct/$(DEPDIR)/driver_cfa_cpp-LabelTypeChecker.Tpo -c -o ControlStruct/driver_cfa_cpp-LabelTypeChecker.o `test -f 'ControlStruct/LabelTypeChecker.cc' || echo '$(srcdir)/'`ControlStruct/LabelTypeChecker.cc
    1215 @am__fastdepCXX_TRUE@   $(AM_V_at)$(am__mv) ControlStruct/$(DEPDIR)/driver_cfa_cpp-LabelTypeChecker.Tpo ControlStruct/$(DEPDIR)/driver_cfa_cpp-LabelTypeChecker.Po
    1216 @AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(AM_V_CXX)source='ControlStruct/LabelTypeChecker.cc' object='ControlStruct/driver_cfa_cpp-LabelTypeChecker.o' libtool=no @AMDEPBACKSLASH@
    1217 @AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    1218 @am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o ControlStruct/driver_cfa_cpp-LabelTypeChecker.o `test -f 'ControlStruct/LabelTypeChecker.cc' || echo '$(srcdir)/'`ControlStruct/LabelTypeChecker.cc
    1219 
    1220 ControlStruct/driver_cfa_cpp-LabelTypeChecker.obj: ControlStruct/LabelTypeChecker.cc
    1221 @am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT ControlStruct/driver_cfa_cpp-LabelTypeChecker.obj -MD -MP -MF ControlStruct/$(DEPDIR)/driver_cfa_cpp-LabelTypeChecker.Tpo -c -o ControlStruct/driver_cfa_cpp-LabelTypeChecker.obj `if test -f 'ControlStruct/LabelTypeChecker.cc'; then $(CYGPATH_W) 'ControlStruct/LabelTypeChecker.cc'; else $(CYGPATH_W) '$(srcdir)/ControlStruct/LabelTypeChecker.cc'; fi`
    1222 @am__fastdepCXX_TRUE@   $(AM_V_at)$(am__mv) ControlStruct/$(DEPDIR)/driver_cfa_cpp-LabelTypeChecker.Tpo ControlStruct/$(DEPDIR)/driver_cfa_cpp-LabelTypeChecker.Po
    1223 @AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(AM_V_CXX)source='ControlStruct/LabelTypeChecker.cc' object='ControlStruct/driver_cfa_cpp-LabelTypeChecker.obj' libtool=no @AMDEPBACKSLASH@
    1224 @AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    1225 @am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o ControlStruct/driver_cfa_cpp-LabelTypeChecker.obj `if test -f 'ControlStruct/LabelTypeChecker.cc'; then $(CYGPATH_W) 'ControlStruct/LabelTypeChecker.cc'; else $(CYGPATH_W) '$(srcdir)/ControlStruct/LabelTypeChecker.cc'; fi`
    1226 
    12271206GenPoly/driver_cfa_cpp-Box.o: GenPoly/Box.cc
    12281207@am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT GenPoly/driver_cfa_cpp-Box.o -MD -MP -MF GenPoly/$(DEPDIR)/driver_cfa_cpp-Box.Tpo -c -o GenPoly/driver_cfa_cpp-Box.o `test -f 'GenPoly/Box.cc' || echo '$(srcdir)/'`GenPoly/Box.cc
  • src/ResolvExpr/Alternative.cc

    r96a10cd r906e24d  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Alternative.cc -- 
     7// Alternative.cc --
    88//
    99// Author           : Richard C. Bilson
     
    1212// Last Modified On : Sat May 16 23:54:23 2015
    1313// Update Count     : 2
    14 // 
     14//
    1515
    1616#include "Alternative.h"
     
    5454                        expr->print( os, indent );
    5555                        os << "(types:" << std::endl;
    56                         printAll( expr->get_results(), os, indent + 4 );
    57                         os << ")" << std::endl;
     56                        os << std::string( indent+4, ' ' );
     57                        expr->get_result()->print( os, indent + 4 );
     58                        os << std::endl << ")" << std::endl;
    5859                } else {
    5960                        os << "Null expression!" << std::endl;
  • src/ResolvExpr/AlternativeFinder.cc

    r96a10cd r906e24d  
    101101                                PruneStruct current( candidate );
    102102                                std::string mangleName;
    103                                 for ( std::list< Type* >::const_iterator retType = candidate->expr->get_results().begin(); retType != candidate->expr->get_results().end(); ++retType ) {
    104                                         Type *newType = (*retType)->clone();
     103                                {
     104                                        Type * newType = candidate->expr->get_result()->clone();
    105105                                        candidate->env.apply( newType );
    106                                         mangleName += SymTab::Mangler::mangle( newType );
     106                                        mangleName = SymTab::Mangler::mangle( newType );
    107107                                        delete newType;
    108108                                }
     
    133133                                if ( ! target->second.isAmbiguous ) {
    134134                                        Alternative &alt = *target->second.candidate;
    135                                         for ( std::list< Type* >::iterator result = alt.expr->get_results().begin(); result != alt.expr->get_results().end(); ++result ) {
    136                                                 alt.env.applyFree( *result );
    137                                         }
     135                                        alt.env.applyFree( alt.expr->get_result() );
    138136                                        *out++ = alt;
    139137                                }
    140138                        }
    141 
    142139                }
    143140
     
    170167
    171168                void renameTypes( Expression *expr ) {
    172                         for ( std::list< Type* >::iterator i = expr->get_results().begin(); i != expr->get_results().end(); ++i ) {
    173                                 (*i)->accept( global_renamer );
    174                         }
     169                        expr->get_result()->accept( global_renamer );
    175170                }
    176171        }
     
    204199                for ( AltList::iterator i = alternatives.begin(); i != alternatives.end(); ++i ) {
    205200                        if ( adjust ) {
    206                                 adjustExprTypeList( i->expr->get_results().begin(), i->expr->get_results().end(), i->env, indexer );
     201                                adjustExprType( i->expr->get_result(), i->env, indexer );
    207202                        }
    208203                }
     
    259254
    260255        Cost computeConversionCost( Alternative &alt, const SymTab::Indexer &indexer ) {
    261                 ApplicationExpr *appExpr = dynamic_cast< ApplicationExpr* >( alt.expr );
    262                 assert( appExpr );
    263                 PointerType *pointer = dynamic_cast< PointerType* >( appExpr->get_function()->get_results().front() );
    264                 assert( pointer );
    265                 FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() );
    266                 assert( function );
     256                ApplicationExpr *appExpr = safe_dynamic_cast< ApplicationExpr* >( alt.expr );
     257                PointerType *pointer = safe_dynamic_cast< PointerType* >( appExpr->get_function()->get_result() );
     258                FunctionType *function = safe_dynamic_cast< FunctionType* >( pointer->get_base() );
    267259
    268260                Cost convCost( 0, 0, 0 );
     
    275267                                (*actualExpr)->print( std::cerr, 8 );
    276268                                std::cerr << "--- results are" << std::endl;
    277                                 printAll( (*actualExpr)->get_results(), std::cerr, 8 );
     269                                (*actualExpr)->get_result()->print( std::cerr, 8 );
    278270                        )
    279271                        std::list< DeclarationWithType* >::iterator startFormal = formal;
    280272                        Cost actualCost;
    281                         for ( std::list< Type* >::iterator actual = (*actualExpr)->get_results().begin(); actual != (*actualExpr)->get_results().end(); ++actual ) {
     273                        // xxx - tuple type matching
     274                        std::list< Type * > flatActualTypes;
     275                        flatten( (*actualExpr)->get_result(), back_inserter( flatActualTypes ) );
     276                        for ( std::list< Type* >::iterator actual = flatActualTypes.begin(); actual != flatActualTypes.end(); ++actual ) {
    282277                                if ( formal == formals.end() ) {
    283278                                        if ( function->get_isVarArgs() ) {
     
    383378                std::list< DeclarationWithType* >::iterator formal = formals.begin();
    384379                for ( AltList::const_iterator actualExpr = actuals.begin(); actualExpr != actuals.end(); ++actualExpr ) {
    385                         for ( std::list< Type* >::iterator actual = actualExpr->expr->get_results().begin(); actual != actualExpr->expr->get_results().end(); ++actual ) {
     380                        std::list< Type * > flatActualTypes;
     381                        flatten( actualExpr->expr->get_result(), back_inserter( flatActualTypes ) );
     382                        for ( std::list< Type* >::iterator actual = flatActualTypes.begin(); actual != flatActualTypes.end(); ++actual ) {
    386383                                if ( formal == formals.end() ) {
    387384                                        return isVarArgs;
     
    500497                                //if ( newNeedParents[ curDecl->get_uniqueId() ][ candDecl->get_uniqueId() ]++ > recursionParentLimit ) continue;
    501498                                Expression *varExpr = new VariableExpr( candDecl );
    502                                 deleteAll( varExpr->get_results() );
    503                                 varExpr->get_results().clear();
    504                                 varExpr->get_results().push_front( adjType->clone() );
     499                                delete varExpr->get_result();
     500                                varExpr->set_result( adjType->clone() );
    505501                                PRINT(
    506502                                        std::cerr << "satisfying assertion " << curDecl->get_uniqueId() << " ";
     
    574570                                PointerType pt( Type::Qualifiers(), v.clone() );
    575571                                UntypedExpr *vexpr = untypedExpr->clone();
    576                                 vexpr->get_results().push_front( pt.clone() );
     572                                vexpr->set_result( pt.clone() );
    577573                                alternatives.push_back( Alternative( vexpr, env, Cost()) );
    578574                                return;
     
    604600                                // check if the type is pointer to function
    605601                                PointerType *pointer;
    606                                 if ( func->expr->get_results().size() == 1 && ( pointer = dynamic_cast< PointerType* >( func->expr->get_results().front() ) ) ) {
     602                                if ( ( pointer = dynamic_cast< PointerType* >( func->expr->get_result() ) ) ) {
    607603                                        if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) {
    608604                                                for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) {
     
    640636                                                // check if the type is pointer to function
    641637                                                PointerType *pointer;
    642                                                 if ( funcOp->expr->get_results().size() == 1
    643                                                         && ( pointer = dynamic_cast< PointerType* >( funcOp->expr->get_results().front() ) ) ) {
     638                                                if ( ( pointer = dynamic_cast< PointerType* >( funcOp->expr->get_result() ) ) ) {
    644639                                                        if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) {
    645640                                                                for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) {
     
    665660
    666661                        PRINT(
    667                                 ApplicationExpr *appExpr = dynamic_cast< ApplicationExpr* >( withFunc->expr );
    668                                 assert( appExpr );
    669                                 PointerType *pointer = dynamic_cast< PointerType* >( appExpr->get_function()->get_results().front() );
    670                                 assert( pointer );
    671                                 FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() );
    672                                 assert( function );
     662                                ApplicationExpr *appExpr = safe_dynamic_cast< ApplicationExpr* >( withFunc->expr );
     663                                PointerType *pointer = safe_dynamic_cast< PointerType* >( appExpr->get_function()->get_result() );
     664                                FunctionType *function = safe_dynamic_cast< FunctionType* >( pointer->get_base() );
    673665                                std::cerr << "Case +++++++++++++" << std::endl;
    674666                                std::cerr << "formals are:" << std::endl;
     
    692684
    693685        bool isLvalue( Expression *expr ) {
    694                 for ( std::list< Type* >::const_iterator i = expr->get_results().begin(); i != expr->get_results().end(); ++i ) {
    695                         if ( !(*i)->get_isLvalue() ) return false;
    696                 } // for
    697                 return true;
     686                // xxx - recurse into tuples?
     687                return expr->has_result() && expr->get_result()->get_isLvalue();
    698688        }
    699689
     
    709699
    710700        void AlternativeFinder::visit( CastExpr *castExpr ) {
    711                 for ( std::list< Type* >::iterator i = castExpr->get_results().begin(); i != castExpr->get_results().end(); ++i ) {
    712                         *i = resolveTypeof( *i, indexer );
    713                         SymTab::validateType( *i, &indexer );
    714                         adjustExprType( *i, env, indexer );
    715                 } // for
     701                Type *& toType = castExpr->get_result();
     702                toType = resolveTypeof( toType, indexer );
     703                SymTab::validateType( toType, &indexer );
     704                adjustExprType( toType, env, indexer );
    716705
    717706                AlternativeFinder finder( indexer, env );
     
    727716                        // that are cast directly.  The candidate is invalid if it has fewer results than there are types to cast
    728717                        // to.
    729                         int discardedValues = (*i).expr->get_results().size() - castExpr->get_results().size();
     718                        int discardedValues = (*i).expr->get_result()->size() - castExpr->get_result()->size();
    730719                        if ( discardedValues < 0 ) continue;
    731                         std::list< Type* >::iterator candidate_end = (*i).expr->get_results().begin();
    732                         std::advance( candidate_end, castExpr->get_results().size() );
     720                        // xxx - may need to go into tuple types and extract relavent types and use unifyList
    733721                        // unification run for side-effects
    734                         unifyList( castExpr->get_results().begin(), castExpr->get_results().end(),
    735                                            (*i).expr->get_results().begin(), candidate_end,
    736                                    i->env, needAssertions, haveAssertions, openVars, indexer );
    737                         Cost thisCost = castCostList( (*i).expr->get_results().begin(), candidate_end,
    738                                                                                   castExpr->get_results().begin(), castExpr->get_results().end(),
    739                                                                                   indexer, i->env );
     722                        unify( castExpr->get_result(), (*i).expr->get_result(), i->env, needAssertions, haveAssertions, openVars, indexer );
     723                        Cost thisCost = castCost( (*i).expr->get_result(), castExpr->get_result(), indexer, i->env );
    740724                        if ( thisCost != Cost::infinity ) {
    741725                                // count one safe conversion for each value that is thrown away
     
    760744
    761745                for ( AltList::const_iterator agg = funcFinder.alternatives.begin(); agg != funcFinder.alternatives.end(); ++agg ) {
    762                         if ( agg->expr->get_results().size() == 1 ) {
    763                                 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( agg->expr->get_results().front() ) ) {
    764                                         addAggMembers( structInst, agg->expr, agg->cost, agg->env, memberExpr->get_member() );
    765                                 } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( agg->expr->get_results().front() ) ) {
    766                                         addAggMembers( unionInst, agg->expr, agg->cost, agg->env, memberExpr->get_member() );
    767                                 } // if
     746                        if ( StructInstType *structInst = dynamic_cast< StructInstType* >( agg->expr->get_result() ) ) {
     747                                addAggMembers( structInst, agg->expr, agg->cost, agg->env, memberExpr->get_member() );
     748                        } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( agg->expr->get_result() ) ) {
     749                                addAggMembers( unionInst, agg->expr, agg->cost, agg->env, memberExpr->get_member() );
    768750                        } // if
    769751                } // for
     
    894876                        alternatives.push_back( Alternative( new AttrExpr( new VariableExpr( funcDecl ), argType->clone() ), env, Cost::zero ) );
    895877                        for ( std::list< DeclarationWithType* >::iterator i = function->get_returnVals().begin(); i != function->get_returnVals().end(); ++i ) {
    896                                 alternatives.back().expr->get_results().push_back( (*i)->get_type()->clone() );
     878                                alternatives.back().expr->set_result( (*i)->get_type()->clone() );
    897879                        } // for
    898880                } // if
     
    917899                                                        finder.find( attrExpr->get_expr() );
    918900                                                        for ( AltList::iterator choice = finder.alternatives.begin(); choice != finder.alternatives.end(); ++choice ) {
    919                                                                 if ( choice->expr->get_results().size() == 1 ) {
    920                                                                         resolveAttr(*i, function, choice->expr->get_results().front(), choice->env );
     901                                                                if ( choice->expr->get_result()->size() == 1 ) {
     902                                                                        resolveAttr(*i, function, choice->expr->get_result(), choice->env );
    921903                                                                } // fi
    922904                                                        } // for
     
    960942                                        AssertionSet needAssertions, haveAssertions;
    961943                                        Alternative newAlt( 0, third->env, first->cost + second->cost + third->cost );
    962                                         std::list< Type* > commonTypes;
    963                                         if ( unifyList( second->expr->get_results().begin(), second->expr->get_results().end(), third->expr->get_results().begin(), third->expr->get_results().end(), newAlt.env, needAssertions, haveAssertions, openVars, indexer, commonTypes ) ) {
     944                                        Type* commonType;
     945                                        if ( unify( second->expr->get_result(), third->expr->get_result(), newAlt.env, needAssertions, haveAssertions, openVars, indexer, commonType ) ) {
    964946                                                ConditionalExpr *newExpr = new ConditionalExpr( first->expr->clone(), second->expr->clone(), third->expr->clone() );
    965                                                 std::list< Type* >::const_iterator original = second->expr->get_results().begin();
    966                                                 std::list< Type* >::const_iterator commonType = commonTypes.begin();
    967                                                 for ( ; original != second->expr->get_results().end() && commonType != commonTypes.end(); ++original, ++commonType ) {
    968                                                         if ( *commonType ) {
    969                                                                 newExpr->get_results().push_back( *commonType );
    970                                                         } else {
    971                                                                 newExpr->get_results().push_back( (*original)->clone() );
    972                                                         } // if
    973                                                 } // for
     947                                                newExpr->set_result( commonType ? commonType : second->expr->get_result()->clone() );
    974948                                                newAlt.expr = newExpr;
    975949                                                inferParameters( needAssertions, haveAssertions, newAlt, openVars, back_inserter( alternatives ) );
     
    999973                        TupleExpr *newExpr = new TupleExpr;
    1000974                        makeExprList( *i, newExpr->get_exprs() );
    1001                         for ( std::list< Expression* >::const_iterator resultExpr = newExpr->get_exprs().begin(); resultExpr != newExpr->get_exprs().end(); ++resultExpr ) {
    1002                                 for ( std::list< Type* >::const_iterator resultType = (*resultExpr)->get_results().begin(); resultType != (*resultExpr)->get_results().end(); ++resultType ) {
    1003                                         newExpr->get_results().push_back( (*resultType)->clone() );
    1004                                 } // for
     975                        for ( Expression * resultExpr : newExpr->get_exprs() ) {
     976                                newExpr->set_result( resultExpr->get_result()->clone() );
    1005977                        } // for
    1006978
  • src/ResolvExpr/AlternativePrinter.cc

    r96a10cd r906e24d  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // AlternativePrinter.cc -- 
     7// AlternativePrinter.cc --
    88//
    99// Author           : Richard C. Bilson
     
    3333                for ( AltList::const_iterator i = finder.get_alternatives().begin(); i != finder.get_alternatives().end(); ++i ) {
    3434                        os << "Alternative " << count++ << " ==============" << std::endl;
    35                         printAll( i->expr->get_results(), os );
     35                        i->expr->get_result()->print( os );
    3636                        //    i->print( os );
    3737                        os << std::endl;
  • src/ResolvExpr/ResolveTypeof.cc

    r96a10cd r906e24d  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // ResolveTypeof.cc -- 
     7// ResolveTypeof.cc --
    88//
    99// Author           : Richard C. Bilson
     
    5858                if ( typeofType->get_expr() ) {
    5959                        Expression *newExpr = resolveInVoidContext( typeofType->get_expr(), indexer );
    60                         assert( newExpr->get_results().size() > 0 );
    61                         Type *newType;
    62                         if ( newExpr->get_results().size() > 1 ) {
    63                                 TupleType *tupleType = new TupleType( Type::Qualifiers() );
    64                                 cloneAll( newExpr->get_results(), tupleType->get_types() );
    65                                 newType = tupleType;
    66                         } else {
    67                                 newType = newExpr->get_results().front()->clone();
    68                         } // if
     60                        assert( newExpr->has_result() && ! newExpr->get_result()->isVoid() );
     61                        Type *newType = newExpr->get_result();
    6962                        delete typeofType;
    7063                        return newType;
  • src/ResolvExpr/Resolver.cc

    r96a10cd r906e24d  
    1919#include "RenameVars.h"
    2020#include "ResolveTypeof.h"
     21#include "typeops.h"
    2122#include "SynTree/Statement.h"
    2223#include "SynTree/Type.h"
     
    6768          void resolveSingleAggrInit( Declaration *, InitIterator &, InitIterator & );
    6869          void fallbackInit( ConstructorInit * ctorInit );
    69                 std::list< Type * > functionReturn;
     70                Type * functionReturn;
    7071                Type *initContext;
    7172                Type *switchType;
     
    155156                        const TypeEnvironment *newEnv = 0;
    156157                        for ( AltList::const_iterator i = finder.get_alternatives().begin(); i != finder.get_alternatives().end(); ++i ) {
    157                                 if ( i->expr->get_results().size() == 1 && isIntegralType( i->expr->get_results().front() ) ) {
     158                                if ( i->expr->get_result()->size() == 1 && isIntegralType( i->expr->get_result() ) ) {
    158159                                        if ( newExpr ) {
    159160                                                throw SemanticError( "Too many interpretations for case control expression", untyped );
     
    232233                Type *new_type = resolveTypeof( functionDecl->get_type(), *this );
    233234                functionDecl->set_type( new_type );
    234                 std::list< Type * > oldFunctionReturn = functionReturn;
    235                 functionReturn.clear();
    236                 for ( std::list< DeclarationWithType * >::const_iterator i = functionDecl->get_functionType()->get_returnVals().begin(); i != functionDecl->get_functionType()->get_returnVals().end(); ++i ) {
    237                         functionReturn.push_back( (*i)->get_type() );
    238                 } // for
     235                ValueGuard< Type * > oldFunctionReturn( functionReturn );
     236                functionReturn = ResolvExpr::extractResultType( functionDecl->get_functionType() );
    239237                SymTab::Indexer::visit( functionDecl );
    240                 functionReturn = oldFunctionReturn;
    241238        }
    242239
     
    336333        void Resolver::visit( ReturnStmt *returnStmt ) {
    337334                if ( returnStmt->get_expr() ) {
    338                         CastExpr *castExpr = new CastExpr( returnStmt->get_expr() );
    339                         cloneAll( functionReturn, castExpr->get_results() );
     335                        CastExpr *castExpr = new CastExpr( returnStmt->get_expr(), functionReturn->clone() );
    340336                        Expression *newExpr = findSingleExpression( castExpr, *this );
    341337                        delete castExpr;
     
    382378                                if ( isCharType( at->get_base() ) ) {
    383379                                        // check if the resolved type is char *
    384                                         if ( PointerType * pt = dynamic_cast< PointerType *>( newExpr->get_results().front() ) ) {
     380                                        if ( PointerType * pt = dynamic_cast< PointerType *>( newExpr->get_result() ) ) {
    385381                                                if ( isCharType( pt->get_base() ) ) {
    386382                                                        // strip cast if we're initializing a char[] with a char *, e.g.  char x[] = "hello";
  • src/ResolvExpr/Unify.cc

    r96a10cd r906e24d  
    588588        }
    589589
     590        // xxx - compute once and store in the FunctionType?
     591        Type * extractResultType( FunctionType * function ) {
     592                if ( function->get_returnVals().size() == 0 ) {
     593                        return new VoidType( Type::Qualifiers() );
     594                } else if ( function->get_returnVals().size() == 1 ) {
     595                        return function->get_returnVals().front()->get_type()->clone();
     596                } else {
     597                        TupleType * tupleType = new TupleType( Type::Qualifiers() );
     598                        for ( DeclarationWithType * decl : function->get_returnVals() ) {
     599                                tupleType->get_types().push_back( decl->get_type()->clone() );
     600                        } // for
     601                        return tupleType;
     602                }
     603        }
     604
    590605} // namespace ResolvExpr
    591606
  • src/ResolvExpr/typeops.h

    r96a10cd r906e24d  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // typeops.h -- 
     7// typeops.h --
    88//
    99// Author           : Richard C. Bilson
     
    3030                typedef typename InputIterator::value_type SetType;
    3131                typedef typename std::list< typename SetType::value_type > ListType;
    32  
     32
    3333                if ( begin == end )     {
    3434                        *out++ = ListType();
    3535                        return;
    3636                } // if
    37  
     37
    3838                InputIterator current = begin;
    3939                begin++;
     
    4141                std::list< ListType > recursiveResult;
    4242                combos( begin, end, back_inserter( recursiveResult ) );
    43  
     43
    4444                for ( typename std::list< ListType >::const_iterator i = recursiveResult.begin(); i != recursiveResult.end(); ++i ) {
    4545                        for ( typename ListType::const_iterator j = current->begin(); j != current->end(); ++j ) {
     
    5252                } // for
    5353        }
    54  
     54
    5555        // in AdjustExprType.cc
    5656        /// Replaces array types with the equivalent pointer, and function types with a pointer-to-function
     
    144144        }
    145145
     146        /// creates the type represented by the list of returnVals in a FunctionType. The caller owns the return value.
     147        Type * extractResultType( FunctionType * functionType );
     148
    146149        // in CommonType.cc
    147150        Type *commonType( Type *type1, Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars );
     
    152155        // in Occurs.cc
    153156        bool occurs( Type *type, std::string varName, const TypeEnvironment &env );
     157
     158        // flatten tuple type into list of types
     159        template< typename OutputIterator >
     160        void flatten( Type * type, OutputIterator out ) {
     161                if ( TupleType * tupleType = dynamic_cast< TupleType * >( type ) ) {
     162                        for ( Type * t : tupleType->get_types() ) {
     163                                flatten( t, out );
     164                        }
     165                } else {
     166                        *out++ = type;
     167                }
     168        }
    154169} // namespace ResolvExpr
    155170
  • src/SymTab/Autogen.cc

    r96a10cd r906e24d  
    116116                // This happens before function pointer type conversion, so need to do it manually here
    117117                VariableExpr * assignVarExpr = new VariableExpr( assignDecl );
    118                 Type *& assignVarExprType = assignVarExpr->get_results().front();
     118                Type * assignVarExprType = assignVarExpr->get_result();
    119119                assignVarExprType = new PointerType( Type::Qualifiers(), assignVarExprType );
     120                assignVarExpr->set_result( assignVarExprType );
    120121                ApplicationExpr * assignExpr = new ApplicationExpr( assignVarExpr );
    121122                assignExpr->get_args().push_back( new VariableExpr( dstParam ) );
  • src/SymTab/Indexer.cc

    r96a10cd r906e24d  
    4040
    4141namespace SymTab {
    42         template< typename Container, typename VisitorType >
    43         inline void acceptAllNewScope( Container &container, VisitorType &visitor ) {
     42        template< typename TreeType, typename VisitorType >
     43        inline void acceptNewScope( TreeType *tree, VisitorType &visitor ) {
    4444                visitor.enterScope();
    45                 acceptAll( container, visitor );
     45                maybeAccept( tree, visitor );
    4646                visitor.leaveScope();
    4747        }
     
    337337
    338338        void Indexer::visit( ApplicationExpr *applicationExpr ) {
    339                 acceptAllNewScope( applicationExpr->get_results(), *this );
     339                acceptNewScope( applicationExpr->get_result(), *this );
    340340                maybeAccept( applicationExpr->get_function(), *this );
    341341                acceptAll( applicationExpr->get_args(), *this );
     
    343343
    344344        void Indexer::visit( UntypedExpr *untypedExpr ) {
    345                 acceptAllNewScope( untypedExpr->get_results(), *this );
     345                acceptNewScope( untypedExpr->get_result(), *this );
    346346                acceptAll( untypedExpr->get_args(), *this );
    347347        }
    348348
    349349        void Indexer::visit( NameExpr *nameExpr ) {
    350                 acceptAllNewScope( nameExpr->get_results(), *this );
     350                acceptNewScope( nameExpr->get_result(), *this );
    351351        }
    352352
    353353        void Indexer::visit( AddressExpr *addressExpr ) {
    354                 acceptAllNewScope( addressExpr->get_results(), *this );
     354                acceptNewScope( addressExpr->get_result(), *this );
    355355                maybeAccept( addressExpr->get_arg(), *this );
    356356        }
    357357
    358358        void Indexer::visit( LabelAddressExpr *labAddressExpr ) {
    359                 acceptAllNewScope( labAddressExpr->get_results(), *this );
     359                acceptNewScope( labAddressExpr->get_result(), *this );
    360360                maybeAccept( labAddressExpr->get_arg(), *this );
    361361        }
    362362
    363363        void Indexer::visit( CastExpr *castExpr ) {
    364                 acceptAllNewScope( castExpr->get_results(), *this );
     364                acceptNewScope( castExpr->get_result(), *this );
    365365                maybeAccept( castExpr->get_arg(), *this );
    366366        }
    367367
    368368        void Indexer::visit( UntypedMemberExpr *memberExpr ) {
    369                 acceptAllNewScope( memberExpr->get_results(), *this );
     369                acceptNewScope( memberExpr->get_result(), *this );
    370370                maybeAccept( memberExpr->get_aggregate(), *this );
    371371        }
    372372
    373373        void Indexer::visit( MemberExpr *memberExpr ) {
    374                 acceptAllNewScope( memberExpr->get_results(), *this );
     374                acceptNewScope( memberExpr->get_result(), *this );
    375375                maybeAccept( memberExpr->get_aggregate(), *this );
    376376        }
    377377
    378378        void Indexer::visit( VariableExpr *variableExpr ) {
    379                 acceptAllNewScope( variableExpr->get_results(), *this );
     379                acceptNewScope( variableExpr->get_result(), *this );
    380380        }
    381381
    382382        void Indexer::visit( ConstantExpr *constantExpr ) {
    383                 acceptAllNewScope( constantExpr->get_results(), *this );
     383                acceptNewScope( constantExpr->get_result(), *this );
    384384                maybeAccept( constantExpr->get_constant(), *this );
    385385        }
    386386
    387387        void Indexer::visit( SizeofExpr *sizeofExpr ) {
    388                 acceptAllNewScope( sizeofExpr->get_results(), *this );
     388                acceptNewScope( sizeofExpr->get_result(), *this );
    389389                if ( sizeofExpr->get_isType() ) {
    390390                        maybeAccept( sizeofExpr->get_type(), *this );
     
    395395
    396396        void Indexer::visit( AlignofExpr *alignofExpr ) {
    397                 acceptAllNewScope( alignofExpr->get_results(), *this );
     397                acceptNewScope( alignofExpr->get_result(), *this );
    398398                if ( alignofExpr->get_isType() ) {
    399399                        maybeAccept( alignofExpr->get_type(), *this );
     
    404404
    405405        void Indexer::visit( UntypedOffsetofExpr *offsetofExpr ) {
    406                 acceptAllNewScope( offsetofExpr->get_results(), *this );
     406                acceptNewScope( offsetofExpr->get_result(), *this );
    407407                maybeAccept( offsetofExpr->get_type(), *this );
    408408        }
    409409
    410410        void Indexer::visit( OffsetofExpr *offsetofExpr ) {
    411                 acceptAllNewScope( offsetofExpr->get_results(), *this );
     411                acceptNewScope( offsetofExpr->get_result(), *this );
    412412                maybeAccept( offsetofExpr->get_type(), *this );
    413413                maybeAccept( offsetofExpr->get_member(), *this );
     
    415415
    416416        void Indexer::visit( OffsetPackExpr *offsetPackExpr ) {
    417                 acceptAllNewScope( offsetPackExpr->get_results(), *this );
     417                acceptNewScope( offsetPackExpr->get_result(), *this );
    418418                maybeAccept( offsetPackExpr->get_type(), *this );
    419419        }
    420420
    421421        void Indexer::visit( AttrExpr *attrExpr ) {
    422                 acceptAllNewScope( attrExpr->get_results(), *this );
     422                acceptNewScope( attrExpr->get_result(), *this );
    423423                if ( attrExpr->get_isType() ) {
    424424                        maybeAccept( attrExpr->get_type(), *this );
     
    429429
    430430        void Indexer::visit( LogicalExpr *logicalExpr ) {
    431                 acceptAllNewScope( logicalExpr->get_results(), *this );
     431                acceptNewScope( logicalExpr->get_result(), *this );
    432432                maybeAccept( logicalExpr->get_arg1(), *this );
    433433                maybeAccept( logicalExpr->get_arg2(), *this );
     
    435435
    436436        void Indexer::visit( ConditionalExpr *conditionalExpr ) {
    437                 acceptAllNewScope( conditionalExpr->get_results(), *this );
     437                acceptNewScope( conditionalExpr->get_result(), *this );
    438438                maybeAccept( conditionalExpr->get_arg1(), *this );
    439439                maybeAccept( conditionalExpr->get_arg2(), *this );
     
    442442
    443443        void Indexer::visit( CommaExpr *commaExpr ) {
    444                 acceptAllNewScope( commaExpr->get_results(), *this );
     444                acceptNewScope( commaExpr->get_result(), *this );
    445445                maybeAccept( commaExpr->get_arg1(), *this );
    446446                maybeAccept( commaExpr->get_arg2(), *this );
     
    448448
    449449        void Indexer::visit( TupleExpr *tupleExpr ) {
    450                 acceptAllNewScope( tupleExpr->get_results(), *this );
     450                acceptNewScope( tupleExpr->get_result(), *this );
    451451                acceptAll( tupleExpr->get_exprs(), *this );
    452452        }
    453453
    454454        void Indexer::visit( SolvedTupleExpr *tupleExpr ) {
    455                 acceptAllNewScope( tupleExpr->get_results(), *this );
     455                acceptNewScope( tupleExpr->get_result(), *this );
    456456                acceptAll( tupleExpr->get_exprs(), *this );
    457457        }
    458458
    459459        void Indexer::visit( TypeExpr *typeExpr ) {
    460                 acceptAllNewScope( typeExpr->get_results(), *this );
     460                acceptNewScope( typeExpr->get_result(), *this );
    461461                maybeAccept( typeExpr->get_type(), *this );
    462462        }
     
    469469
    470470        void Indexer::visit( UntypedValofExpr *valofExpr ) {
    471                 acceptAllNewScope( valofExpr->get_results(), *this );
     471                acceptNewScope( valofExpr->get_result(), *this );
    472472                maybeAccept( valofExpr->get_body(), *this );
    473473        }
  • src/SynTree/AddressExpr.cc

    r96a10cd r906e24d  
    1919
    2020AddressExpr::AddressExpr( Expression *arg, Expression *_aname ) : Expression( _aname ), arg( arg ) {
    21         for ( std::list< Type* >::const_iterator i = arg->get_results().begin(); i != arg->get_results().end(); ++i ) {
    22                 get_results().push_back( new PointerType( Type::Qualifiers(), (*i)->clone() ) );
    23         } // for
     21        if ( arg->has_result() ) {
     22                set_result( new PointerType( Type::Qualifiers(), arg->get_result()->clone() ) );
     23        }
    2424}
    2525
     
    3535        if ( arg ) {
    3636                os << std::string( indent+2, ' ' );
    37     arg->print( os, indent+2 );
     37                arg->print( os, indent+2 );
    3838        } // if
    3939}
  • src/SynTree/ApplicationExpr.cc

    r96a10cd r906e24d  
    2121#include "TypeSubstitution.h"
    2222#include "Common/utility.h"
    23 
     23#include "ResolvExpr/typeops.h"
    2424
    2525ParamEntry::ParamEntry( const ParamEntry &other ) :
     
    4343
    4444ApplicationExpr::ApplicationExpr( Expression *funcExpr ) : function( funcExpr ) {
    45         PointerType *pointer = dynamic_cast< PointerType* >( funcExpr->get_results().front() );
    46         assert( pointer );
    47         FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() );
    48         assert( function );
     45        PointerType *pointer = safe_dynamic_cast< PointerType* >( funcExpr->get_result() );
     46        FunctionType *function = safe_dynamic_cast< FunctionType* >( pointer->get_base() );
    4947
    50         for ( std::list< DeclarationWithType* >::const_iterator i = function->get_returnVals().begin(); i != function->get_returnVals().end(); ++i ) {
    51                 get_results().push_back( (*i)->get_type()->clone() );
    52         } // for
     48        set_result( ResolvExpr::extractResultType( function ) );
     49
     50        assert( has_result() );
    5351}
    5452
  • src/SynTree/CommaExpr.cc

    r96a10cd r906e24d  
    2323        // to false on all result types. Actually doing this causes some strange things
    2424        // to happen in later passes (particularly, Specialize, Lvalue, and Box). This needs to be looked into.
    25         cloneAll( arg2->get_results(), get_results() );
    26         // for ( Type *& type : get_results() ) {
    27         //      type->set_isLvalue( false );
    28         // }
     25        set_result( maybeClone( arg2->get_result() ) );
     26        // get_type->set_isLvalue( false );
    2927}
    3028
  • src/SynTree/Expression.cc

    r96a10cd r906e24d  
    3131
    3232
    33 Expression::Expression( Expression *_aname ) : env( 0 ), argName( _aname ) {}
    34 
    35 Expression::Expression( const Expression &other ) : env( maybeClone( other.env ) ), argName( maybeClone( other.get_argName() ) ), extension( other.extension ) {
    36         cloneAll( other.results, results );
     33Expression::Expression( Expression *_aname ) : result( 0 ), env( 0 ), argName( _aname ) {}
     34
     35Expression::Expression( const Expression &other ) : result( maybeClone( other.result ) ), env( maybeClone( other.env ) ), argName( maybeClone( other.get_argName() ) ), extension( other.extension ) {
    3736}
    3837
     
    4039        delete env;
    4140        delete argName; // xxx -- there's a problem in cloning ConstantExpr I still don't know how to fix
    42         deleteAll( results );
    43 }
    44 
    45 void Expression::add_result( Type *t ) {
    46         if ( TupleType *tuple = dynamic_cast< TupleType* >( t ) ) {
    47                 std::copy( tuple->get_types().begin(), tuple->get_types().end(), back_inserter( results ) );
    48         } else {
    49                 results.push_back(t);
    50         } // if
     41        delete result;
    5142}
    5243
     
    6859
    6960ConstantExpr::ConstantExpr( Constant _c, Expression *_aname ) : Expression( _aname ), constant( _c ) {
    70         add_result( constant.get_type()->clone() );
     61        set_result( constant.get_type()->clone() );
    7162}
    7263
     
    8576        assert( var );
    8677        assert( var->get_type() );
    87         add_result( var->get_type()->clone() );
    88         for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) {
    89                 (*i)->set_isLvalue( true );
    90         } // for
     78        Type * type = var->get_type()->clone();
     79        type->set_isLvalue( true );
     80        set_result( type );
    9181}
    9282
     
    110100SizeofExpr::SizeofExpr( Expression *expr_, Expression *_aname ) :
    111101                Expression( _aname ), expr(expr_), type(0), isType(false) {
    112         add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
     102        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    113103}
    114104
    115105SizeofExpr::SizeofExpr( Type *type_, Expression *_aname ) :
    116106                Expression( _aname ), expr(0), type(type_), isType(true) {
    117         add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
     107        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    118108}
    119109
     
    141131AlignofExpr::AlignofExpr( Expression *expr_, Expression *_aname ) :
    142132                Expression( _aname ), expr(expr_), type(0), isType(false) {
    143         add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
     133        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    144134}
    145135
    146136AlignofExpr::AlignofExpr( Type *type_, Expression *_aname ) :
    147137                Expression( _aname ), expr(0), type(type_), isType(true) {
    148         add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
     138        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    149139}
    150140
     
    172162UntypedOffsetofExpr::UntypedOffsetofExpr( Type *type_, const std::string &member_, Expression *_aname ) :
    173163                Expression( _aname ), type(type_), member(member_) {
    174         add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
     164        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    175165}
    176166
     
    197187OffsetofExpr::OffsetofExpr( Type *type_, DeclarationWithType *member_, Expression *_aname ) :
    198188                Expression( _aname ), type(type_), member(member_) {
    199         add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
     189        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    200190}
    201191
     
    229219
    230220OffsetPackExpr::OffsetPackExpr( StructInstType *type_, Expression *aname_ ) : Expression( aname_ ), type( type_ ) {
    231         add_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );
     221        set_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );
    232222}
    233223
     
    284274
    285275CastExpr::CastExpr( Expression *arg_, Type *toType, Expression *_aname ) : Expression( _aname ), arg(arg_) {
    286         add_result(toType);
     276        set_result(toType);
    287277}
    288278
    289279CastExpr::CastExpr( Expression *arg_, Expression *_aname ) : Expression( _aname ), arg(arg_) {
     280        set_result( new VoidType( Type::Qualifiers() ) );
    290281}
    291282
     
    303294        arg->print(os, indent+2);
    304295        os << std::endl << std::string( indent, ' ' ) << "to:" << std::endl;
    305         if ( results.empty() ) {
    306                 os << std::string( indent+2, ' ' ) << "nothing" << std::endl;
     296        os << std::string( indent+2, ' ' );
     297        if ( result->isVoid() ) {
     298                os << "nothing";
    307299        } else {
    308                 printAll(results, os, indent+2);
     300                result->print( os, indent+2 );
    309301        } // if
     302        os << std::endl;
    310303        Expression::print( os, indent );
    311304}
     
    338331MemberExpr::MemberExpr( DeclarationWithType *_member, Expression *_aggregate, Expression *_aname ) :
    339332                Expression( _aname ), member(_member), aggregate(_aggregate) {
    340         add_result( member->get_type()->clone() );
    341         for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) {
    342                 (*i)->set_isLvalue( true );
    343         } // for
     333        set_result( member->get_type()->clone() );
     334        get_result()->set_isLvalue( true );
    344335}
    345336
     
    419410LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp, Expression *_aname ) :
    420411                Expression( _aname ), arg1(arg1_), arg2(arg2_), isAnd(andp) {
    421         add_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
     412        set_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
    422413}
    423414
     
    477468ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( ApplicationExpr * callExpr ) : callExpr( callExpr ) {
    478469        assert( callExpr );
    479         cloneAll( callExpr->get_results(), results );
     470        assert( callExpr->has_result() );
     471        set_result( callExpr->get_result()->clone() );
    480472}
    481473
     
    510502        Expression * arg = InitTweak::getCallArg( callExpr, 0 );
    511503        assert( arg );
    512         cloneAll( arg->get_results(), results );
     504        set_result( maybeClone( arg->get_result() ) );
    513505}
    514506
     
    530522
    531523CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) {
    532         add_result( type->clone() );
     524        set_result( type->clone() );
    533525}
    534526
  • src/SynTree/Expression.h

    r96a10cd r906e24d  
    3232        virtual ~Expression();
    3333
    34         std::list<Type *>& get_results() { return results; }
    35         void add_result( Type *t );
     34        Type *& get_result() { return result; }
     35        void set_result( Type *newValue ) { result = newValue; }
     36        bool has_result() const { return result != nullptr; }
    3637
    3738        TypeSubstitution *get_env() const { return env; }
     
    4748        virtual void print( std::ostream &os, int indent = 0 ) const;
    4849  protected:
    49         std::list<Type *> results;
     50        Type * result;
    5051        TypeSubstitution *env;
    5152        Expression* argName; // if expression is used as an argument, it can be "designated" by this name
  • src/SynTree/Mutator.cc

    r96a10cd r906e24d  
    178178
    179179Expression *Mutator::mutate( ApplicationExpr *applicationExpr ) {
    180         mutateAll( applicationExpr->get_results(), *this );
     180        applicationExpr->set_result( maybeMutate( applicationExpr->get_result(), *this ) );
    181181        applicationExpr->set_function( maybeMutate( applicationExpr->get_function(), *this ) );
    182182        mutateAll( applicationExpr->get_args(), *this );
     
    185185
    186186Expression *Mutator::mutate( UntypedExpr *untypedExpr ) {
    187         mutateAll( untypedExpr->get_results(), *this );
     187        untypedExpr->set_result( maybeMutate( untypedExpr->get_result(), *this ) );
    188188        mutateAll( untypedExpr->get_args(), *this );
    189189        return untypedExpr;
     
    191191
    192192Expression *Mutator::mutate( NameExpr *nameExpr ) {
    193         mutateAll( nameExpr->get_results(), *this );
     193        nameExpr->set_result( maybeMutate( nameExpr->get_result(), *this ) );
    194194        return nameExpr;
    195195}
    196196
    197197Expression *Mutator::mutate( AddressExpr *addressExpr ) {
    198         mutateAll( addressExpr->get_results(), *this );
     198        addressExpr->set_result( maybeMutate( addressExpr->get_result(), *this ) );
    199199        addressExpr->set_arg( maybeMutate( addressExpr->get_arg(), *this ) );
    200200        return addressExpr;
     
    202202
    203203Expression *Mutator::mutate( LabelAddressExpr *labelAddressExpr ) {
    204         mutateAll( labelAddressExpr->get_results(), *this );
     204        labelAddressExpr->set_result( maybeMutate( labelAddressExpr->get_result(), *this ) );
    205205        labelAddressExpr->set_arg( maybeMutate( labelAddressExpr->get_arg(), *this ) );
    206206        return labelAddressExpr;
     
    208208
    209209Expression *Mutator::mutate( CastExpr *castExpr ) {
    210         mutateAll( castExpr->get_results(), *this );
     210        castExpr->set_result( maybeMutate( castExpr->get_result(), *this ) );
    211211        castExpr->set_arg( maybeMutate( castExpr->get_arg(), *this ) );
    212212        return castExpr;
     
    214214
    215215Expression *Mutator::mutate( UntypedMemberExpr *memberExpr ) {
    216         mutateAll( memberExpr->get_results(), *this );
     216        memberExpr->set_result( maybeMutate( memberExpr->get_result(), *this ) );
    217217        memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) );
    218218        return memberExpr;
     
    220220
    221221Expression *Mutator::mutate( MemberExpr *memberExpr ) {
    222         mutateAll( memberExpr->get_results(), *this );
     222        memberExpr->set_result( maybeMutate( memberExpr->get_result(), *this ) );
    223223        memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) );
    224224        return memberExpr;
     
    226226
    227227Expression *Mutator::mutate( VariableExpr *variableExpr ) {
    228         mutateAll( variableExpr->get_results(), *this );
     228        variableExpr->set_result( maybeMutate( variableExpr->get_result(), *this ) );
    229229        return variableExpr;
    230230}
    231231
    232232Expression *Mutator::mutate( ConstantExpr *constantExpr ) {
    233         mutateAll( constantExpr->get_results(), *this );
     233        constantExpr->set_result( maybeMutate( constantExpr->get_result(), *this ) );
    234234//  maybeMutate( constantExpr->get_constant(), *this )
    235235        return constantExpr;
     
    237237
    238238Expression *Mutator::mutate( SizeofExpr *sizeofExpr ) {
    239         mutateAll( sizeofExpr->get_results(), *this );
     239        sizeofExpr->set_result( maybeMutate( sizeofExpr->get_result(), *this ) );
    240240        if ( sizeofExpr->get_isType() ) {
    241241                sizeofExpr->set_type( maybeMutate( sizeofExpr->get_type(), *this ) );
     
    247247
    248248Expression *Mutator::mutate( AlignofExpr *alignofExpr ) {
    249         mutateAll( alignofExpr->get_results(), *this );
     249        alignofExpr->set_result( maybeMutate( alignofExpr->get_result(), *this ) );
    250250        if ( alignofExpr->get_isType() ) {
    251251                alignofExpr->set_type( maybeMutate( alignofExpr->get_type(), *this ) );
     
    257257
    258258Expression *Mutator::mutate( UntypedOffsetofExpr *offsetofExpr ) {
    259         mutateAll( offsetofExpr->get_results(), *this );
     259        offsetofExpr->set_result( maybeMutate( offsetofExpr->get_result(), *this ) );
    260260        offsetofExpr->set_type( maybeMutate( offsetofExpr->get_type(), *this ) );
    261261        return offsetofExpr;
     
    263263
    264264Expression *Mutator::mutate( OffsetofExpr *offsetofExpr ) {
    265         mutateAll( offsetofExpr->get_results(), *this );
     265        offsetofExpr->set_result( maybeMutate( offsetofExpr->get_result(), *this ) );
    266266        offsetofExpr->set_type( maybeMutate( offsetofExpr->get_type(), *this ) );
    267267        offsetofExpr->set_member( maybeMutate( offsetofExpr->get_member(), *this ) );
     
    270270
    271271Expression *Mutator::mutate( OffsetPackExpr *offsetPackExpr ) {
    272         mutateAll( offsetPackExpr->get_results(), *this );
     272        offsetPackExpr->set_result( maybeMutate( offsetPackExpr->get_result(), *this ) );
    273273        offsetPackExpr->set_type( maybeMutate( offsetPackExpr->get_type(), *this ) );
    274274        return offsetPackExpr;
     
    276276
    277277Expression *Mutator::mutate( AttrExpr *attrExpr ) {
    278         mutateAll( attrExpr->get_results(), *this );
     278        attrExpr->set_result( maybeMutate( attrExpr->get_result(), *this ) );
    279279        if ( attrExpr->get_isType() ) {
    280280                attrExpr->set_type( maybeMutate( attrExpr->get_type(), *this ) );
     
    286286
    287287Expression *Mutator::mutate( LogicalExpr *logicalExpr ) {
    288         mutateAll( logicalExpr->get_results(), *this );
     288        logicalExpr->set_result( maybeMutate( logicalExpr->get_result(), *this ) );
    289289        logicalExpr->set_arg1( maybeMutate( logicalExpr->get_arg1(), *this ) );
    290290        logicalExpr->set_arg2( maybeMutate( logicalExpr->get_arg2(), *this ) );
     
    293293
    294294Expression *Mutator::mutate( ConditionalExpr *conditionalExpr ) {
    295         mutateAll( conditionalExpr->get_results(), *this );
     295        conditionalExpr->set_result( maybeMutate( conditionalExpr->get_result(), *this ) );
    296296        conditionalExpr->set_arg1( maybeMutate( conditionalExpr->get_arg1(), *this ) );
    297297        conditionalExpr->set_arg2( maybeMutate( conditionalExpr->get_arg2(), *this ) );
     
    301301
    302302Expression *Mutator::mutate( CommaExpr *commaExpr ) {
    303         mutateAll( commaExpr->get_results(), *this );
     303        commaExpr->set_result( maybeMutate( commaExpr->get_result(), *this ) );
    304304        commaExpr->set_arg1( maybeMutate( commaExpr->get_arg1(), *this ) );
    305305        commaExpr->set_arg2( maybeMutate( commaExpr->get_arg2(), *this ) );
     
    308308
    309309Expression *Mutator::mutate( TupleExpr *tupleExpr ) {
    310         mutateAll( tupleExpr->get_results(), *this );
     310        tupleExpr->set_result( maybeMutate( tupleExpr->get_result(), *this ) );
    311311        mutateAll( tupleExpr->get_exprs(), *this );
    312312        return tupleExpr;
     
    314314
    315315Expression *Mutator::mutate( SolvedTupleExpr *tupleExpr ) {
    316         mutateAll( tupleExpr->get_results(), *this );
     316        tupleExpr->set_result( maybeMutate( tupleExpr->get_result(), *this ) );
    317317        mutateAll( tupleExpr->get_exprs(), *this );
    318318        return tupleExpr;
     
    320320
    321321Expression *Mutator::mutate( TypeExpr *typeExpr ) {
    322         mutateAll( typeExpr->get_results(), *this );
     322        typeExpr->set_result( maybeMutate( typeExpr->get_result(), *this ) );
    323323        typeExpr->set_type( maybeMutate( typeExpr->get_type(), *this ) );
    324324        return typeExpr;
     
    340340
    341341Expression* Mutator::mutate( ConstructorExpr *ctorExpr ) {
    342         mutateAll( ctorExpr->get_results(), *this );
     342        ctorExpr->set_result( maybeMutate( ctorExpr->get_result(), *this ) );
    343343        ctorExpr->set_callExpr( maybeMutate( ctorExpr->get_callExpr(), *this ) );
    344344        return ctorExpr;
     
    346346
    347347Expression *Mutator::mutate( CompoundLiteralExpr *compLitExpr ) {
    348         mutateAll( compLitExpr->get_results(), *this );
     348        compLitExpr->set_result( maybeMutate( compLitExpr->get_result(), *this ) );
    349349        compLitExpr->set_type( maybeMutate( compLitExpr->get_type(), *this ) );
    350350        compLitExpr->set_initializer( maybeMutate( compLitExpr->get_initializer(), *this ) );
     
    353353
    354354Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) {
    355         mutateAll( valofExpr->get_results(), *this );
     355        valofExpr->set_result( maybeMutate( valofExpr->get_result(), *this ) );
    356356        return valofExpr;
    357357}
  • src/SynTree/Type.h

    r96a10cd r906e24d  
    6565        std::list<TypeDecl*>& get_forall() { return forall; }
    6666
     67        /// How many elemental types are represented by this type
     68        virtual unsigned size() const { return 1; };
     69        virtual bool isVoid() const { return size() == 0; }
     70
    6771        virtual Type *clone() const = 0;
    6872        virtual void accept( Visitor &v ) = 0;
     
    7781  public:
    7882        VoidType( const Type::Qualifiers &tq );
     83
     84        virtual unsigned size() const { return 0; };
    7985
    8086        virtual VoidType *clone() const { return new VoidType( *this ); }
     
    353359
    354360        std::list<Type*>& get_types() { return types; }
     361        virtual unsigned size() const { return types.size(); };
    355362
    356363        virtual TupleType *clone() const { return new TupleType( *this ); }
  • src/SynTree/Visitor.cc

    r96a10cd r906e24d  
    150150
    151151void Visitor::visit( ApplicationExpr *applicationExpr ) {
    152         acceptAll( applicationExpr->get_results(), *this );
     152        maybeAccept( applicationExpr->get_result(), *this );
    153153        maybeAccept( applicationExpr->get_function(), *this );
    154154        acceptAll( applicationExpr->get_args(), *this );
     
    156156
    157157void Visitor::visit( UntypedExpr *untypedExpr ) {
    158         acceptAll( untypedExpr->get_results(), *this );
     158        maybeAccept( untypedExpr->get_result(), *this );
    159159        acceptAll( untypedExpr->get_args(), *this );
    160160}
    161161
    162162void Visitor::visit( NameExpr *nameExpr ) {
    163         acceptAll( nameExpr->get_results(), *this );
     163        maybeAccept( nameExpr->get_result(), *this );
    164164}
    165165
    166166void Visitor::visit( AddressExpr *addressExpr ) {
    167         acceptAll( addressExpr->get_results(), *this );
     167        maybeAccept( addressExpr->get_result(), *this );
    168168        maybeAccept( addressExpr->get_arg(), *this );
    169169}
    170170
    171171void Visitor::visit( LabelAddressExpr *labAddressExpr ) {
    172         acceptAll( labAddressExpr->get_results(), *this );
     172        maybeAccept( labAddressExpr->get_result(), *this );
    173173        maybeAccept( labAddressExpr->get_arg(), *this );
    174174}
    175175
    176176void Visitor::visit( CastExpr *castExpr ) {
    177         acceptAll( castExpr->get_results(), *this );
     177        maybeAccept( castExpr->get_result(), *this );
    178178        maybeAccept( castExpr->get_arg(), *this );
    179179}
    180180
    181181void Visitor::visit( UntypedMemberExpr *memberExpr ) {
    182         acceptAll( memberExpr->get_results(), *this );
     182        maybeAccept( memberExpr->get_result(), *this );
    183183        maybeAccept( memberExpr->get_aggregate(), *this );
    184184}
    185185
    186186void Visitor::visit( MemberExpr *memberExpr ) {
    187         acceptAll( memberExpr->get_results(), *this );
     187        maybeAccept( memberExpr->get_result(), *this );
    188188        maybeAccept( memberExpr->get_aggregate(), *this );
    189189}
    190190
    191191void Visitor::visit( VariableExpr *variableExpr ) {
    192         acceptAll( variableExpr->get_results(), *this );
     192        maybeAccept( variableExpr->get_result(), *this );
    193193}
    194194
    195195void Visitor::visit( ConstantExpr *constantExpr ) {
    196         acceptAll( constantExpr->get_results(), *this );
     196        maybeAccept( constantExpr->get_result(), *this );
    197197        maybeAccept( constantExpr->get_constant(), *this );
    198198}
    199199
    200200void Visitor::visit( SizeofExpr *sizeofExpr ) {
    201         acceptAll( sizeofExpr->get_results(), *this );
     201        maybeAccept( sizeofExpr->get_result(), *this );
    202202        if ( sizeofExpr->get_isType() ) {
    203203                maybeAccept( sizeofExpr->get_type(), *this );
     
    208208
    209209void Visitor::visit( AlignofExpr *alignofExpr ) {
    210         acceptAll( alignofExpr->get_results(), *this );
     210        maybeAccept( alignofExpr->get_result(), *this );
    211211        if ( alignofExpr->get_isType() ) {
    212212                maybeAccept( alignofExpr->get_type(), *this );
     
    217217
    218218void Visitor::visit( UntypedOffsetofExpr *offsetofExpr ) {
    219         acceptAll( offsetofExpr->get_results(), *this );
     219        maybeAccept( offsetofExpr->get_result(), *this );
    220220        maybeAccept( offsetofExpr->get_type(), *this );
    221221}
    222222
    223223void Visitor::visit( OffsetofExpr *offsetofExpr ) {
    224         acceptAll( offsetofExpr->get_results(), *this );
     224        maybeAccept( offsetofExpr->get_result(), *this );
    225225        maybeAccept( offsetofExpr->get_type(), *this );
    226226        maybeAccept( offsetofExpr->get_member(), *this );
     
    228228
    229229void Visitor::visit( OffsetPackExpr *offsetPackExpr ) {
    230         acceptAll( offsetPackExpr->get_results(), *this );
     230        maybeAccept( offsetPackExpr->get_result(), *this );
    231231        maybeAccept( offsetPackExpr->get_type(), *this );
    232232}
    233233
    234234void Visitor::visit( AttrExpr *attrExpr ) {
    235         acceptAll( attrExpr->get_results(), *this );
     235        maybeAccept( attrExpr->get_result(), *this );
    236236        if ( attrExpr->get_isType() ) {
    237237                maybeAccept( attrExpr->get_type(), *this );
     
    242242
    243243void Visitor::visit( LogicalExpr *logicalExpr ) {
    244         acceptAll( logicalExpr->get_results(), *this );
     244        maybeAccept( logicalExpr->get_result(), *this );
    245245        maybeAccept( logicalExpr->get_arg1(), *this );
    246246        maybeAccept( logicalExpr->get_arg2(), *this );
     
    248248
    249249void Visitor::visit( ConditionalExpr *conditionalExpr ) {
    250         acceptAll( conditionalExpr->get_results(), *this );
     250        maybeAccept( conditionalExpr->get_result(), *this );
    251251        maybeAccept( conditionalExpr->get_arg1(), *this );
    252252        maybeAccept( conditionalExpr->get_arg2(), *this );
     
    255255
    256256void Visitor::visit( CommaExpr *commaExpr ) {
    257         acceptAll( commaExpr->get_results(), *this );
     257        maybeAccept( commaExpr->get_result(), *this );
    258258        maybeAccept( commaExpr->get_arg1(), *this );
    259259        maybeAccept( commaExpr->get_arg2(), *this );
     
    261261
    262262void Visitor::visit( TupleExpr *tupleExpr ) {
    263         acceptAll( tupleExpr->get_results(), *this );
     263        maybeAccept( tupleExpr->get_result(), *this );
    264264        acceptAll( tupleExpr->get_exprs(), *this );
    265265}
    266266
    267267void Visitor::visit( SolvedTupleExpr *tupleExpr ) {
    268         acceptAll( tupleExpr->get_results(), *this );
     268        maybeAccept( tupleExpr->get_result(), *this );
    269269        acceptAll( tupleExpr->get_exprs(), *this );
    270270}
    271271
    272272void Visitor::visit( TypeExpr *typeExpr ) {
    273         acceptAll( typeExpr->get_results(), *this );
     273        maybeAccept( typeExpr->get_result(), *this );
    274274        maybeAccept( typeExpr->get_type(), *this );
    275275}
     
    288288
    289289void Visitor::visit( ConstructorExpr * ctorExpr ) {
    290         acceptAll( ctorExpr->get_results(), *this );
     290        maybeAccept( ctorExpr->get_result(), *this );
    291291        maybeAccept( ctorExpr->get_callExpr(), *this );
    292292}
    293293
    294294void Visitor::visit( CompoundLiteralExpr *compLitExpr ) {
    295         acceptAll( compLitExpr->get_results(), *this );
     295        maybeAccept( compLitExpr->get_result(), *this );
    296296        maybeAccept( compLitExpr->get_type(), *this );
    297297        maybeAccept( compLitExpr->get_initializer(), *this );
     
    299299
    300300void Visitor::visit( UntypedValofExpr *valofExpr ) {
    301         acceptAll( valofExpr->get_results(), *this );
     301        maybeAccept( valofExpr->get_result(), *this );
    302302        maybeAccept( valofExpr->get_body(), *this );
    303303}
  • src/Tuples/TupleAssignment.cc

    r96a10cd r906e24d  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // TupleAssignment.cc -- 
     7// TupleAssignment.cc --
    88//
    99// Author           : Rodolfo G. Esteves
     
    125125
    126126        bool TupleAssignSpotter::isMVR( Expression *expr ) {
    127                 if ( expr->get_results().size() > 1 ) {
    128                         // MVR processing
    129                         return true;
    130                 }
    131                 return false;
     127                return isTuple( expr );
    132128        }
    133129
  • src/Tuples/TupleAssignment.h

    r96a10cd r906e24d  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // TupleAssignment.h -- 
     7// TupleAssignment.h --
    88//
    99// Author           : Rodolfo G. Esteves
Note: See TracChangeset for help on using the changeset viewer.