Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Resolver.cc

    r2efe4b8 r6f326b1  
    2222#include "Alternative.h"                 // for Alternative, AltList
    2323#include "AlternativeFinder.h"           // for AlternativeFinder, resolveIn...
    24 #include "Common/GC.h"                   // for new_generation, collect_young
    2524#include "Common/PassVisitor.h"          // for PassVisitor
    2625#include "Common/SemanticError.h"        // for SemanticError
     
    6059                void previsit( TypeDecl *typeDecl );
    6160                void previsit( EnumDecl * enumDecl );
     61                void previsit( StaticAssertDecl * assertDecl );
    6262
    6363                void previsit( ArrayType * at );
     
    139139                                        castExpr->arg = nullptr;
    140140                                        std::swap( expr->env, castExpr->env );
     141                                        delete castExpr;
    141142                                }
    142143                        }
     
    147148                void findUnfinishedKindExpression(Expression * untyped, Alternative & alt, const SymTab::Indexer & indexer, const std::string & kindStr, std::function<bool(const Alternative &)> pred, bool adjust = false, bool prune = true, bool failFast = true) {
    148149                        assertf( untyped, "expected a non-null expression." );
    149 
    150                         auto guard = new_generation();  // set up GC generation for this top-level expression
    151 
    152150                        TypeEnvironment env;
    153151                        AlternativeFinder finder( indexer, env );
     
    177175                        findMinCost( candidates.begin(), candidates.end(), back_inserter( winners ) );
    178176                        if ( winners.size() == 0 ) {
    179                                 SemanticError( untyped, toString(
    180                                         "No reasonable alternatives for ", kindStr, (kindStr != "" ? " " : ""),
    181                                         "expression: ") );
     177                                SemanticError( untyped, toString( "No reasonable alternatives for ", kindStr, (kindStr != "" ? " " : ""), "expression: ") );
    182178                        } else if ( winners.size() != 1 ) {
    183179                                std::ostringstream stream;
    184                                 stream << "Cannot choose between " << winners.size() << " alternatives for "
    185                                         << kindStr << (kindStr != "" ? " " : "") << "expression\n";
     180                                stream << "Cannot choose between " << winners.size() << " alternatives for " << kindStr << (kindStr != "" ? " " : "") << "expression\n";
    186181                                untyped->print( stream );
    187182                                stream << " Alternatives are:\n";
    188183                                printAlts( winners, stream, 1 );
    189                                
    190184                                SemanticError( untyped->location, stream.str() );
    191185                        }
     
    194188                        Alternative & choice = winners.front();
    195189                        if ( findDeletedExpr( choice.expr ) ) {
    196                                 trace( choice.expr );
    197                                 SemanticError( choice.expr,
    198                                         "Unique best alternative includes deleted identifier in " );
     190                                SemanticError( choice.expr, "Unique best alternative includes deleted identifier in " );
    199191                        }
    200192                        alt = std::move( choice );
    201                         trace( alt );
    202193                }
    203194
     
    208199                        findUnfinishedKindExpression( untyped, choice, indexer, kindStr, pred, adjust, prune, failFast );
    209200                        finishExpr( choice.expr, choice.env, untyped->env );
     201                        delete untyped;
    210202                        untyped = choice.expr;
    211203                        choice.expr = nullptr;
     
    230222                assertf( expr, "expected a non-null expression." );
    231223
    232                 auto untyped = new CastExpr{ expr }; // cast to void
     224                static CastExpr untyped( nullptr ); // cast to void
    233225
    234226                // set up and resolve expression cast to void
     227                untyped.arg = expr;
    235228                Alternative choice;
    236                 findUnfinishedKindExpression( untyped, choice, indexer, "", standardAlternativeFilter, true );
     229                findUnfinishedKindExpression( &untyped, choice, indexer, "", standardAlternativeFilter, true );
    237230                CastExpr * castExpr = strict_dynamic_cast< CastExpr * >( choice.expr );
    238231                env = std::move( choice.env );
    239232
    240233                // clean up resolved expression
    241                 return castExpr->arg;
     234                Expression * ret = castExpr->arg;
     235                castExpr->arg = nullptr;
     236
     237                // unlink the arg so that it isn't deleted twice at the end of the program
     238                untyped.arg = nullptr;
     239                return ret;
    242240        }
    243241
     
    247245                Expression * newExpr = resolveInVoidContext( untyped, indexer, env );
    248246                finishExpr( newExpr, env, untyped->env );
     247                delete untyped;
    249248                untyped = newExpr;
    250249        }
     
    365364        }
    366365
     366        void Resolver::previsit( StaticAssertDecl * assertDecl ) {
     367                findIntegralExpression( assertDecl->condition, indexer );
     368        }
     369
    367370        void Resolver::previsit( ExprStmt *exprStmt ) {
    368371                visit_children = false;
     
    420423                        caseStmt->condition = castExpr->arg;
    421424                        castExpr->arg = nullptr;
     425                        delete castExpr;
    422426                }
    423427        }
     
    486490                                ss << "' in call to waitfor";
    487491                                SemanticError( stmt->location, ss.str() );
     492                        }
     493
     494                        if(clause.target.arguments.empty()) {
     495                                SemanticError( stmt->location, "Waitfor clause must have at least one mutex parameter");
    488496                        }
    489497
     
    536544                                                        OpenVarSet openVars;
    537545                                                        AssertionSet resultNeed, resultHave;
    538                                                         TypeEnvironment resultEnv;
     546                                                        TypeEnvironment resultEnv( func.env );
     547                                                        makeUnifiableVars( function, openVars, resultNeed );
     548                                                        // add all type variables as open variables now so that those not used in the parameter
     549                                                        // list are still considered open.
     550                                                        resultEnv.add( function->forall );
    539551
    540552                                                        // Load type variables from arguemnts into one shared space
     
    552564                                                        auto param_end = function->parameters.end();
    553565
     566                                                        int n_mutex_arg = 0;
     567
    554568                                                        // For every arguments of its set, check if it matches one of the parameter
    555569                                                        // The order is important
     
    560574                                                                        // We ran out of parameters but still have arguments
    561575                                                                        // this function doesn't match
    562                                                                         SemanticError( function, "candidate function not viable: too many mutex arguments\n" );
     576                                                                        SemanticError( function, toString("candidate function not viable: too many mutex arguments, expected ", n_mutex_arg, "\n" ));
    563577                                                                }
    564578
     579                                                                n_mutex_arg++;
     580
    565581                                                                // Check if the argument matches the parameter type in the current scope
    566                                                                 if( ! unify( (*param)->get_type(), arg.expr->get_result(), resultEnv, resultNeed, resultHave, openVars, this->indexer ) ) {
     582                                                                if( ! unify( arg.expr->get_result(), (*param)->get_type(), resultEnv, resultNeed, resultHave, openVars, this->indexer ) ) {
    567583                                                                        // Type doesn't match
    568584                                                                        stringstream ss;
    569585                                                                        ss << "candidate function not viable: no known convertion from '";
     586                                                                        (*param)->get_type()->print( ss );
     587                                                                        ss << "' to '";
    570588                                                                        arg.expr->get_result()->print( ss );
    571                                                                         ss << "' to '";
    572                                                                         (*param)->get_type()->print( ss );
     589                                                                        ss << "' with env '";
     590                                                                        resultEnv.print(ss);
    573591                                                                        ss << "'\n";
    574592                                                                        SemanticError( function, ss.str() );
     
    584602                                                                // We ran out of arguments but still have parameters left
    585603                                                                // this function doesn't match
    586                                                                 SemanticError( function, "candidate function not viable: too few mutex arguments\n" );
     604                                                                SemanticError( function, toString("candidate function not viable: too few mutex arguments, expected ", n_mutex_arg, "\n" ));
    587605                                                        }
    588606
     
    701719                std::swap( initExpr->env, newExpr->env );
    702720                std::swap( initExpr->inferParams, newExpr->inferParams ) ;
     721                delete initExpr;
    703722
    704723                // get the actual object's type (may not exactly match what comes back from the resolver due to conversions)
     
    718737                                                        ce->set_arg( nullptr );
    719738                                                        std::swap( ce->env, newExpr->env );
     739                                                        delete ce;
    720740                                                }
    721741                                        }
     
    768788                // could not find valid constructor, or found an intrinsic constructor
    769789                // fall back on C-style initializer
    770                 ctorInit->set_ctor( nullptr );
    771                 ctorInit->set_dtor( nullptr );
     790                delete ctorInit->get_ctor();
     791                ctorInit->set_ctor( NULL );
     792                delete ctorInit->get_dtor();
     793                ctorInit->set_dtor( NULL );
    772794                maybeAccept( ctorInit->get_init(), *visitor );
    773795        }
     
    795817
    796818                // found a constructor - can get rid of C-style initializer
     819                delete ctorInit->init;
    797820                ctorInit->init = nullptr;
    798821
     
    801824                // to clean up generated code.
    802825                if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->ctor ) ) {
     826                        delete ctorInit->ctor;
    803827                        ctorInit->ctor = nullptr;
    804828                }
    805829
    806830                if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->dtor ) ) {
     831                        delete ctorInit->dtor;
    807832                        ctorInit->dtor = nullptr;
    808833                }
Note: See TracChangeset for help on using the changeset viewer.