Changeset dcbb03b for src/ResolvExpr


Ignore:
Timestamp:
Mar 1, 2018, 9:29:03 AM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, 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:
1f37ed02
Parents:
b002261 (diff), 446ffa3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

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

Location:
src/ResolvExpr
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    rb002261 rdcbb03b  
    204204        } // namespace
    205205
    206         void referenceToRvalueConversion( Expression *& expr ) {
     206        void referenceToRvalueConversion( Expression *& expr, Cost & cost ) {
    207207                if ( dynamic_cast< ReferenceType * >( expr->get_result() ) ) {
    208208                        // cast away reference from expr
    209209                        expr = new CastExpr( expr, expr->get_result()->stripReferences()->clone() );
     210                        cost.incReference();
    210211                }
    211212        }
     
    239240                                std::cerr << "No reasonable alternatives for expression " << expr << std::endl;
    240241                        )
    241                         throw SemanticError( expr, "No reasonable alternatives for expression " );
     242                        SemanticError( expr, "No reasonable alternatives for expression " );
    242243                }
    243244                if ( prune ) {
     
    257258                                stream << " Alternatives are:\n";
    258259                                printAlts( winners, stream, 1 );
    259                                 throw SemanticError( expr->location, stream.str() );
     260                                SemanticError( expr->location, stream.str() );
    260261                        }
    261262                        alternatives = move(pruned);
     
    435436                                        PRINT( std::cerr << "end of formals with varargs function: inc unsafe: " << convCost << std::endl; ; )
    436437                                        // convert reference-typed expressions to value-typed expressions
    437                                         referenceToRvalueConversion( *actualExpr );
     438                                        referenceToRvalueConversion( *actualExpr, convCost );
    438439                                        continue;
    439440                                } else {
     
    494495                                return;
    495496                        } else if ( level >= recursionLimit ) {
    496                                 throw SemanticError( newAlt.expr->location, "Too many recursive assertions" );
     497                                SemanticError( newAlt.expr->location, "Too many recursive assertions" );
    497498                        } else {
    498499                                AssertionSet newerNeed;
     
    565566                                // DOESN'T WORK: grandchild nodes conflict with their cousins
    566567                                //if ( newNeedParents[ curDecl->get_uniqueId() ][ candDecl->get_uniqueId() ]++ > recursionParentLimit ) continue;
    567                                 Expression *varExpr = data.combine();
     568
     569                                Expression *varExpr = data.combine( newerAlt.cvtCost );
    568570                                delete varExpr->get_result();
    569571                                varExpr->set_result( adjType->clone() );
     
    11101112
    11111113                AltList candidates;
    1112                 SemanticError errors;
     1114                SemanticErrorException errors;
    11131115                for ( AltList::iterator func = funcFinder.alternatives.begin(); func != funcFinder.alternatives.end(); ++func ) {
    11141116                        try {
     
    11211123                                        if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) {
    11221124                                                Alternative newFunc( *func );
    1123                                                 referenceToRvalueConversion( newFunc.expr );
     1125                                                referenceToRvalueConversion( newFunc.expr, newFunc.cost );
    11241126                                                makeFunctionAlternatives( newFunc, function, argExpansions,
    11251127                                                        std::back_inserter( candidates ) );
     
    11301132                                                if ( FunctionType *function = dynamic_cast< FunctionType* >( eqvClass.type ) ) {
    11311133                                                        Alternative newFunc( *func );
    1132                                                         referenceToRvalueConversion( newFunc.expr );
     1134                                                        referenceToRvalueConversion( newFunc.expr, newFunc.cost );
    11331135                                                        makeFunctionAlternatives( newFunc, function, argExpansions,
    11341136                                                                std::back_inserter( candidates ) );
     
    11361138                                        } // if
    11371139                                }
    1138                         } catch ( SemanticError &e ) {
     1140                        } catch ( SemanticErrorException &e ) {
    11391141                                errors.append( e );
    11401142                        }
     
    11601162                                                                dynamic_cast<FunctionType*>( pointer->get_base() ) ) {
    11611163                                                        Alternative newFunc( *funcOp );
    1162                                                         referenceToRvalueConversion( newFunc.expr );
     1164                                                        referenceToRvalueConversion( newFunc.expr, newFunc.cost );
    11631165                                                        makeFunctionAlternatives( newFunc, function, argExpansions,
    11641166                                                                std::back_inserter( candidates ) );
    11651167                                                }
    11661168                                        }
    1167                                 } catch ( SemanticError &e ) {
     1169                                } catch ( SemanticErrorException &e ) {
    11681170                                        errors.append( e );
    11691171                                }
     
    13441346                for ( AltList::const_iterator agg = funcFinder.alternatives.begin(); agg != funcFinder.alternatives.end(); ++agg ) {
    13451347                        // it's okay for the aggregate expression to have reference type -- cast it to the base type to treat the aggregate as the referenced value
    1346                         std::unique_ptr<Expression> aggrExpr( agg->expr->clone() );
    1347                         Type * aggrType = aggrExpr->get_result();
    1348                         if ( dynamic_cast< ReferenceType * >( aggrType ) ) {
    1349                                 aggrType = aggrType->stripReferences();
    1350                                 aggrExpr.reset( new CastExpr( aggrExpr.release(), aggrType->clone() ) );
    1351                         }
     1348                        Cost cost = agg->cost;
     1349                        Expression * aggrExpr = agg->expr->clone();
     1350                        referenceToRvalueConversion( aggrExpr, cost );
     1351                        std::unique_ptr<Expression> guard( aggrExpr );
     1352
    13521353                        // find member of the given type
    13531354                        if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->get_result() ) ) {
    1354                                 addAggMembers( structInst, aggrExpr.get(), agg->cost, agg->env, memberExpr->get_member() );
     1355                                addAggMembers( structInst, aggrExpr, cost, agg->env, memberExpr->get_member() );
    13551356                        } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->get_result() ) ) {
    1356                                 addAggMembers( unionInst, aggrExpr.get(), agg->cost, agg->env, memberExpr->get_member() );
     1357                                addAggMembers( unionInst, aggrExpr, cost, agg->env, memberExpr->get_member() );
    13571358                        } else if ( TupleType * tupleType = dynamic_cast< TupleType * >( aggrExpr->get_result() ) ) {
    1358                                 addTupleMembers( tupleType, aggrExpr.get(), agg->cost, agg->env, memberExpr->get_member() );
     1359                                addTupleMembers( tupleType, aggrExpr, cost, agg->env, memberExpr->get_member() );
    13591360                        } // if
    13601361                } // for
     
    13701371                PRINT( std::cerr << "nameExpr is " << nameExpr->name << std::endl; )
    13711372                for ( auto & data : declList ) {
    1372                         Expression * newExpr = data.combine();
    1373                         // xxx - add in extra cost for with-statement exprs?
    1374                         alternatives.push_back( Alternative( newExpr, env, Cost::zero ) );
     1373                        Cost cost = Cost::zero;
     1374                        Expression * newExpr = data.combine( cost );
     1375                        alternatives.push_back( Alternative( newExpr, env, Cost::zero, cost ) );
    13751376                        PRINT(
    13761377                                std::cerr << "decl is ";
     
    14081409                        findMinCost( finder.alternatives.begin(), finder.alternatives.end(), back_inserter( winners ) );
    14091410                        if ( winners.size() != 1 ) {
    1410                                 throw SemanticError( sizeofExpr->get_expr(), "Ambiguous expression in sizeof operand: " );
     1411                                SemanticError( sizeofExpr->get_expr(), "Ambiguous expression in sizeof operand: " );
    14111412                        } // if
    14121413                        // return the lowest cost alternative for the argument
    14131414                        Alternative &choice = winners.front();
    1414                         referenceToRvalueConversion( choice.expr );
     1415                        referenceToRvalueConversion( choice.expr, choice.cost );
    14151416                        alternatives.push_back( Alternative( new SizeofExpr( choice.expr->clone() ), choice.env, Cost::zero ) );
    14161417                } // if
     
    14291430                        findMinCost( finder.alternatives.begin(), finder.alternatives.end(), back_inserter( winners ) );
    14301431                        if ( winners.size() != 1 ) {
    1431                                 throw SemanticError( alignofExpr->get_expr(), "Ambiguous expression in alignof operand: " );
     1432                                SemanticError( alignofExpr->get_expr(), "Ambiguous expression in alignof operand: " );
    14321433                        } // if
    14331434                        // return the lowest cost alternative for the argument
    14341435                        Alternative &choice = winners.front();
    1435                         referenceToRvalueConversion( choice.expr );
     1436                        referenceToRvalueConversion( choice.expr, choice.cost );
    14361437                        alternatives.push_back( Alternative( new AlignofExpr( choice.expr->clone() ), choice.env, Cost::zero ) );
    14371438                } // if
     
    14851486                        AltList & alternatives = finder.get_alternatives();
    14861487                        if ( typesCompatibleIgnoreQualifiers( argType, function->get_parameters().front()->get_type(), indexer, env ) ) {
    1487                                 alternatives.push_back( Alternative( new AttrExpr( data.combine(), argType->clone() ), env, Cost::zero ) );
     1488                                Cost cost = Cost::zero;
     1489                                Expression * newExpr = data.combine( cost );
     1490                                alternatives.push_back( Alternative( new AttrExpr( newExpr, argType->clone() ), env, Cost::zero, cost ) );
    14881491                                for ( DeclarationWithType * retVal : function->returnVals ) {
    14891492                                        alternatives.back().expr->result = retVal->get_type()->clone();
     
    15221525                } else {
    15231526                        for ( auto & data : attrList ) {
    1524                                 alternatives.push_back( Alternative( data.combine(), env, Cost::zero ) );
     1527                                Cost cost = Cost::zero;
     1528                                Expression * newExpr = data.combine( cost );
     1529                                alternatives.push_back( Alternative( newExpr, env, Cost::zero, cost ) );
    15251530                                renameTypes( alternatives.back().expr );
    15261531                        } // for
  • src/ResolvExpr/ConversionCost.cc

    rb002261 rdcbb03b  
    170170        Cost convertToReferenceCost( Type * src, ReferenceType * dest, const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func ) {
    171171                int sdepth = src->referenceDepth(), ddepth = dest->referenceDepth();
    172                 return convertToReferenceCost( src, dest, sdepth-ddepth, indexer, env, func );
     172                Cost cost = convertToReferenceCost( src, dest, sdepth-ddepth, indexer, env, func );
     173                PRINT( std::cerr << "convertToReferenceCost result: " << cost << std::endl; )
     174                return cost;
    173175        }
    174176
  • src/ResolvExpr/CurrentObject.cc

    rb002261 rdcbb03b  
    141141                        base = at->get_base();
    142142                        memberIter = createMemberIterator( base );
    143                         if ( at->isVarLen ) throw SemanticError( at, "VLA initialization does not support @=" );
     143                        if ( at->isVarLen ) SemanticError( at, "VLA initialization does not support @=" );
    144144                        setSize( at->get_dimension() );
    145145                }
     
    155155                                        size = constExpr->intValue();
    156156                                        PRINT( std::cerr << "array type with size: " << size << std::endl; )
    157                                 } catch ( SemanticError & ) {
    158                                         throw SemanticError( expr, "Constant expression of non-integral type in array dimension: " );
     157                                } catch ( SemanticErrorException & ) {
     158                                        SemanticError( expr, "Constant expression of non-integral type in array dimension: " );
    159159                                }
    160160                        }       else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) {
     
    178178                                try {
    179179                                        index = constExpr->intValue();
    180                                 } catch( SemanticError & ) {
    181                                         throw SemanticError( expr, "Constant expression of non-integral type in array designator: " );
     180                                } catch( SemanticErrorException & ) {
     181                                        SemanticError( expr, "Constant expression of non-integral type in array designator: " );
    182182                                }
    183183                        } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) {
     
    532532                } // for
    533533                if ( desigAlts.size() > 1 ) {
    534                         throw SemanticError( designation, toString("Too many alternatives (", desigAlts.size(), ") for designation: ") );
     534                        SemanticError( designation, toString("Too many alternatives (", desigAlts.size(), ") for designation: ") );
    535535                } else if ( desigAlts.size() == 0 ) {
    536                         throw SemanticError( designation, "No reasonable alternatives for designation: " );
     536                        SemanticError( designation, "No reasonable alternatives for designation: " );
    537537                }
    538538                DesignatorChain & d = desigAlts.back();
  • src/ResolvExpr/Resolver.cc

    rb002261 rdcbb03b  
    174174                        findMinCost( candidates.begin(), candidates.end(), back_inserter( winners ) );
    175175                        if ( winners.size() == 0 ) {
    176                                 throw SemanticError( untyped, toString( "No reasonable alternatives for ", kindStr, (kindStr != "" ? " " : ""), "expression: ") );
     176                                SemanticError( untyped, toString( "No reasonable alternatives for ", kindStr, (kindStr != "" ? " " : ""), "expression: ") );
    177177                        } else if ( winners.size() != 1 ) {
    178178                                std::ostringstream stream;
     
    181181                                stream << " Alternatives are:\n";
    182182                                printAlts( winners, stream, 1 );
    183                                 throw SemanticError( untyped->location, stream.str() );
     183                                SemanticError( untyped->location, stream.str() );
    184184                        }
    185185
     
    187187                        Alternative & choice = winners.front();
    188188                        if ( findDeletedExpr( choice.expr ) ) {
    189                                 throw SemanticError( choice.expr, "Unique best alternative includes deleted identifier in " );
     189                                SemanticError( choice.expr, "Unique best alternative includes deleted identifier in " );
    190190                        }
    191191                        alt = std::move( choice );
     
    484484                                ss << strict_dynamic_cast<NameExpr*>( clause.target.function )->name;
    485485                                ss << "' in call to waitfor";
    486                                 throw SemanticError( stmt->location, ss.str() );
     486                                SemanticError( stmt->location, ss.str() );
    487487                        }
    488488
     
    501501                        //      try matching the arguments to the parameters
    502502                        //      not the other way around because we have more arguments than parameters
    503                         SemanticError errors;
     503                        SemanticErrorException errors;
    504504                        for ( Alternative & func : funcFinder.get_alternatives() ) {
    505505                                try {
    506506                                        PointerType * pointer = dynamic_cast< PointerType* >( func.expr->get_result()->stripReferences() );
    507507                                        if( !pointer ) {
    508                                                 throw SemanticError( func.expr->get_result(), "candidate not viable: not a pointer type\n" );
     508                                                SemanticError( func.expr->get_result(), "candidate not viable: not a pointer type\n" );
    509509                                        }
    510510
    511511                                        FunctionType * function = dynamic_cast< FunctionType* >( pointer->get_base() );
    512512                                        if( !function ) {
    513                                                 throw SemanticError( pointer->get_base(), "candidate not viable: not a function type\n" );
     513                                                SemanticError( pointer->get_base(), "candidate not viable: not a function type\n" );
    514514                                        }
    515515
     
    520520
    521521                                                if( !advance_to_mutex( param, param_end ) ) {
    522                                                         throw SemanticError(function, "candidate function not viable: no mutex parameters\n");
     522                                                        SemanticError(function, "candidate function not viable: no mutex parameters\n");
    523523                                                }
    524524                                        }
     
    526526                                        Alternative newFunc( func );
    527527                                        // Strip reference from function
    528                                         referenceToRvalueConversion( newFunc.expr );
     528                                        referenceToRvalueConversion( newFunc.expr, newFunc.cost );
    529529
    530530                                        // For all the set of arguments we have try to match it with the parameter of the current function alternative
     
    559559                                                                        // We ran out of parameters but still have arguments
    560560                                                                        // this function doesn't match
    561                                                                         throw SemanticError( function, "candidate function not viable: too many mutex arguments\n" );
     561                                                                        SemanticError( function, "candidate function not viable: too many mutex arguments\n" );
    562562                                                                }
    563563
     
    571571                                                                        (*param)->get_type()->print( ss );
    572572                                                                        ss << "'\n";
    573                                                                         throw SemanticError( function, ss.str() );
     573                                                                        SemanticError( function, ss.str() );
    574574                                                                }
    575575
     
    583583                                                                // We ran out of arguments but still have parameters left
    584584                                                                // this function doesn't match
    585                                                                 throw SemanticError( function, "candidate function not viable: too few mutex arguments\n" );
     585                                                                SemanticError( function, "candidate function not viable: too few mutex arguments\n" );
    586586                                                        }
    587587
     
    599599
    600600                                                }
    601                                                 catch( SemanticError &e ) {
     601                                                catch( SemanticErrorException &e ) {
    602602                                                        errors.append( e );
    603603                                                }
    604604                                        }
    605605                                }
    606                                 catch( SemanticError &e ) {
     606                                catch( SemanticErrorException &e ) {
    607607                                        errors.append( e );
    608608                                }
     
    610610
    611611                        // Make sure we got the right number of arguments
    612                         if( func_candidates.empty() )    { SemanticError top( stmt->location, "No alternatives for function in call to waitfor"  ); top.append( errors ); throw top; }
    613                         if( args_candidates.empty() )    { SemanticError top( stmt->location, "No alternatives for arguments in call to waitfor" ); top.append( errors ); throw top; }
    614                         if( func_candidates.size() > 1 ) { SemanticError top( stmt->location, "Ambiguous function in call to waitfor"            ); top.append( errors ); throw top; }
    615                         if( args_candidates.size() > 1 ) { SemanticError top( stmt->location, "Ambiguous arguments in call to waitfor"           ); top.append( errors ); throw top; }
     612                        if( func_candidates.empty() )    { SemanticErrorException top( stmt->location, "No alternatives for function in call to waitfor"  ); top.append( errors ); throw top; }
     613                        if( args_candidates.empty() )    { SemanticErrorException top( stmt->location, "No alternatives for arguments in call to waitfor" ); top.append( errors ); throw top; }
     614                        if( func_candidates.size() > 1 ) { SemanticErrorException top( stmt->location, "Ambiguous function in call to waitfor"            ); top.append( errors ); throw top; }
     615                        if( args_candidates.size() > 1 ) { SemanticErrorException top( stmt->location, "Ambiguous arguments in call to waitfor"           ); top.append( errors ); throw top; }
    616616                        // TODO: need to use findDeletedExpr to ensure no deleted identifiers are used.
    617617
  • src/ResolvExpr/typeops.h

    rb002261 rdcbb03b  
    106106
    107107        // in AlternativeFinder.cc
    108         void referenceToRvalueConversion( Expression *& expr );
     108        void referenceToRvalueConversion( Expression *& expr, Cost & cost );
    109109
    110110        // flatten tuple type into list of types
Note: See TracChangeset for help on using the changeset viewer.