Changeset 24d6572 for src/ResolvExpr


Ignore:
Timestamp:
Jun 12, 2023, 2:45:32 PM (2 years ago)
Author:
Fangren Yu <f37yu@…>
Branches:
ast-experimental, master
Children:
62d62db
Parents:
34b4268 (diff), 251ce80 (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' into ast-experimental

Location:
src/ResolvExpr
Files:
7 added
25 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    r34b4268 r24d6572  
    1414//
    1515
     16#include "AlternativeFinder.h"
     17
    1618#include <algorithm>               // for copy
    1719#include <cassert>                 // for strict_dynamic_cast, assert, assertf
     
    2628
    2729#include "CompilationState.h"      // for resolvep
     30#include "AdjustExprType.hpp"      // for adjustExprType
    2831#include "Alternative.h"           // for AltList, Alternative
    29 #include "AlternativeFinder.h"
    3032#include "AST/Expr.hpp"
    3133#include "AST/SymbolTable.hpp"
    3234#include "AST/Type.hpp"
     35#include "CastCost.hpp"            // for castCost
    3336#include "Common/SemanticError.h"  // for SemanticError
    3437#include "Common/utility.h"        // for deleteAll, printAll, CodeLocation
     38#include "ConversionCost.h"        // for conversionCost
    3539#include "Cost.h"                  // for Cost, Cost::zero, operator<<, Cost...
    3640#include "ExplodedActual.h"        // for ExplodedActual
    3741#include "InitTweak/InitTweak.h"   // for getFunctionName
     42#include "PolyCost.hpp"            // for polyCost
    3843#include "RenameVars.h"            // for RenameVars, global_renamer
    3944#include "ResolveAssertions.h"     // for resolveAssertions
    4045#include "ResolveTypeof.h"         // for resolveTypeof
    4146#include "Resolver.h"              // for resolveStmtExpr
     47#include "SpecCost.hpp"            // for specCost
    4248#include "SymTab/Indexer.h"        // for Indexer
    4349#include "SymTab/Mangler.h"        // for Mangler
     
    5157#include "Tuples/Explode.h"        // for explode
    5258#include "Tuples/Tuples.h"         // for isTtype, handleTupleAssignment
     59#include "typeops.h"               // for combos
    5360#include "Unify.h"                 // for unify
    54 #include "typeops.h"               // for adjustExprType, polyCost, castCost
    5561
    5662#define PRINT( text ) if ( resolvep ) { text }
  • src/ResolvExpr/AlternativeFinder.h

    r34b4268 r24d6572  
    3434namespace ResolvExpr {
    3535        struct ArgPack;
     36
     37        Cost computeConversionCost( Type * actualType, Type * formalType, bool actualIsLvalue,
     38                const SymTab::Indexer & indexer, const TypeEnvironment & env );
     39
     40        void referenceToRvalueConversion( Expression *& expr, Cost & cost );
    3641
    3742        /// First index is which argument, second index is which alternative for that argument,
  • src/ResolvExpr/Candidate.cpp

    r34b4268 r24d6572  
    1717
    1818#include <iostream>
     19#include <sstream>
    1920
    2021#include "AST/Print.hpp"
     
    4445        sorted.reserve(cands.size());
    4546        for(const auto & c : cands) {
    46                 std::stringstream ss;
     47                std::ostringstream ss;
    4748                print( ss, *c, indent );
    4849                sorted.push_back(ss.str());
  • src/ResolvExpr/CandidateFinder.cpp

    r34b4268 r24d6572  
    2323#include <vector>
    2424
     25#include "AdjustExprType.hpp"
    2526#include "Candidate.hpp"
    2627#include "CompilationState.h"
    2728#include "Cost.h"
     29#include "CastCost.hpp"
     30#include "PolyCost.hpp"
     31#include "SpecCost.hpp"
     32#include "ConversionCost.h"
    2833#include "ExplodedArg.hpp"
    2934#include "RenameVars.h"           // for renameTyVars
     
    403408                                                        unify(
    404409                                                                ttype, argType, newResult.env, newResult.need, newResult.have,
    405                                                                 newResult.open, symtab )
     410                                                                newResult.open )
    406411                                                ) {
    407412                                                        finalResults.emplace_back( std::move( newResult ) );
     
    474479                                )
    475480
    476                                 if ( unify( paramType, argType, env, need, have, open, symtab ) ) {
     481                                if ( unify( paramType, argType, env, need, have, open ) ) {
    477482                                        unsigned nextExpl = results[i].nextExpl + 1;
    478483                                        if ( nextExpl == expl.exprs.size() ) { nextExpl = 0; }
     
    493498                                        ast::OpenVarSet open = results[i].open;
    494499
    495                                         if ( unify( paramType, cnst->result, env, need, have, open, symtab ) ) {
     500                                        if ( unify( paramType, cnst->result, env, need, have, open ) ) {
    496501                                                results.emplace_back(
    497502                                                        i, new ast::DefaultArgExpr{ cnst->location, cnst }, std::move( env ),
     
    536541
    537542                                // attempt to unify types
    538                                 if ( unify( paramType, argType, env, need, have, open, symtab ) ) {
     543                                if ( unify( paramType, argType, env, need, have, open ) ) {
    539544                                        // add new result
    540545                                        results.emplace_back(
     
    703708                                if ( selfFinder.strictMode ) {
    704709                                        if ( ! unifyExact(
    705                                                 returnType, targetType, funcEnv, funcNeed, funcHave, funcOpen, noWiden(), symtab ) // xxx - is no widening correct?
     710                                                returnType, targetType, funcEnv, funcNeed, funcHave, funcOpen, noWiden() ) // xxx - is no widening correct?
    706711                                        ) {
    707712                                                // unification failed, do not pursue this candidate
     
    711716                                else {
    712717                                        if ( ! unify(
    713                                                 returnType, targetType, funcEnv, funcNeed, funcHave, funcOpen, symtab )
     718                                                returnType, targetType, funcEnv, funcNeed, funcHave, funcOpen )
    714719                                        ) {
    715720                                                // unification failed, do not pursue this candidate
     
    11561161
    11571162                                // unification run for side-effects
    1158                                 unify( toType, cand->expr->result, cand->env, need, have, open, symtab );
     1163                                unify( toType, cand->expr->result, cand->env, need, have, open );
    11591164                                Cost thisCost =
    11601165                                        (castExpr->isGenerated == ast::GeneratedFlag::GeneratedCast)
     
    14971502                                                if (
    14981503                                                        unify(
    1499                                                                 r2->expr->result, r3->expr->result, env, need, have, open, symtab,
     1504                                                                r2->expr->result, r3->expr->result, env, need, have, open,
    15001505                                                                common )
    15011506                                                ) {
     
    15711576                                        if (
    15721577                                                unify(
    1573                                                         r1->expr->result, r2->expr->result, env, need, have, open, symtab,
     1578                                                        r1->expr->result, r2->expr->result, env, need, have, open,
    15741579                                                        common )
    15751580                                        ) {
     
    16771682
    16781683                                        // unification run for side-effects
    1679                                         bool canUnify = unify( toType, cand->expr->result, env, need, have, open, symtab );
     1684                                        bool canUnify = unify( toType, cand->expr->result, env, need, have, open );
    16801685                                        (void) canUnify;
    16811686                                        Cost thisCost = computeConversionCost( cand->expr->result, toType, cand->expr->get_lvalue(),
  • src/ResolvExpr/CandidateFinder.hpp

    r34b4268 r24d6572  
    6565        const ast::SymbolTable & symtab, const ast::TypeEnvironment & env );
    6666
     67/// Create an expression that preforms reference to rvalue conversion on
     68/// the given expression and update the cost of the expression.
     69const ast::Expr * referenceToRvalueConversion(
     70        const ast::Expr * expr, Cost & cost );
     71
    6772} // namespace ResolvExpr
    6873
  • src/ResolvExpr/CastCost.cc

    r34b4268 r24d6572  
    1313// Update Count     : 9
    1414//
     15
     16#include "CastCost.hpp"
    1517
    1618#include <cassert>                       // for assert
     
    2224#include "ConversionCost.h"              // for ConversionCost
    2325#include "Cost.h"                        // for Cost, Cost::infinity
     26#include "ResolvExpr/ConversionCost.h"   // for conversionCost
     27#include "ResolvExpr/PtrsCastable.hpp"   // for ptrsCastable
    2428#include "ResolvExpr/TypeEnvironment.h"  // for TypeEnvironment, EqvClass
     29#include "ResolvExpr/typeops.h"          // for ptrsCastable
     30#include "ResolvExpr/Unify.h"            // for typesCompatibleIgnoreQualifiers
    2531#include "SymTab/Indexer.h"              // for Indexer
    2632#include "SynTree/Declaration.h"         // for TypeDecl, NamedTypeDecl
    2733#include "SynTree/Type.h"                // for PointerType, Type, TypeInstType
    28 #include "typeops.h"                     // for typesCompatibleIgnoreQualifiers
    2934
    3035#if 0
     
    160165                                if (
    161166                                        pointerType->qualifiers <= ptr->qualifiers
    162                                         && typesCompatibleIgnoreQualifiers( pointerType->base, ptr->base, symtab, env )
     167                                        && typesCompatibleIgnoreQualifiers( pointerType->base, ptr->base, env )
    163168                                ) {
    164169                                        cost = Cost::safe;
     
    227232        )
    228233
    229         if ( typesCompatibleIgnoreQualifiers( src, dst, symtab, env ) ) {
     234        if ( typesCompatibleIgnoreQualifiers( src, dst, env ) ) {
    230235                PRINT( std::cerr << "compatible!" << std::endl; )
    231236                if (dynamic_cast<const ast::ZeroType *>(dst) || dynamic_cast<const ast::OneType *>(dst)) {
  • src/ResolvExpr/CommonType.cc

    r34b4268 r24d6572  
    1414//
    1515
     16#include "CommonType.hpp"
     17
    1618#include <cassert>                       // for strict_dynamic_cast
    1719#include <map>                           // for _Rb_tree_const_iterator
     
    1921
    2022#include "AST/Decl.hpp"
     23#include "AST/Pass.hpp"
    2124#include "AST/Type.hpp"
    2225#include "Common/PassVisitor.h"
     
    673676                const ast::Type * type2;
    674677                WidenMode widen;
    675                 const ast::SymbolTable & symtab;
    676678                ast::TypeEnvironment & tenv;
    677679                const ast::OpenVarSet & open;
     
    683685
    684686                CommonType_new(
    685                         const ast::Type * t2, WidenMode w, const ast::SymbolTable & st,
     687                        const ast::Type * t2, WidenMode w,
    686688                        ast::TypeEnvironment & env, const ast::OpenVarSet & o,
    687689                        ast::AssertionSet & need, ast::AssertionSet & have )
    688                 : type2( t2 ), widen( w ), symtab( st ), tenv( env ), open( o ), need (need), have (have) ,result() {}
     690                : type2( t2 ), widen( w ), tenv( env ), open( o ), need (need), have (have) ,result() {}
    689691
    690692                void previsit( const ast::Node * ) { visit_children = false; }
     
    764766                                        ast::AssertionSet need, have;
    765767                                        if ( ! tenv.bindVar(
    766                                                 var, voidPtr->base, entry->second, need, have, open, widen, symtab )
     768                                                var, voidPtr->base, entry->second, need, have, open, widen )
    767769                                        ) return;
    768770                                }
     
    777779                                ast::OpenVarSet newOpen{ open };
    778780                                if (enumInst->base->base
    779                                 && unifyExact(type1, enumInst->base->base, tenv, need, have, newOpen, widen, symtab)) {
     781                                && unifyExact(type1, enumInst->base->base, tenv, need, have, newOpen, widen)) {
    780782                                        result = type1;
    781783                                        return true;
     
    814816
    815817                                        ast::OpenVarSet newOpen{ open };
    816                                         if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden(), symtab ) ) {
     818                                        if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden() ) ) {
    817819                                                result = pointer;
    818820                                                if ( q1.val != q2.val ) {
     
    857859                                                                if (unifyExact(
    858860                                                                        arg1, tupleFromTypes( crnt2, end2 ), tenv, need, have, open,
    859                                                                         noWiden(), symtab )) {
     861                                                                        noWiden() )) {
    860862                                                                                break;
    861863
     
    866868                                                                if (unifyExact(
    867869                                                                        tupleFromTypes( crnt1, end1 ), arg2, tenv, need, have, open,
    868                                                                         noWiden(), symtab )) {
     870                                                                        noWiden() )) {
    869871                                                                                break;
    870872
     
    890892
    891893                                                                                if ( ! unifyExact(
    892                                                                                         base1, base2, tenv, need, have, open, noWiden(), symtab )
     894                                                                                        base1, base2, tenv, need, have, open, noWiden() )
    893895                                                                                ) return;
    894896                                                                        }       
     
    910912
    911913                                                                                if ( ! unifyExact(
    912                                                                                         base1, base2, tenv, need, have, open, noWiden(), symtab )
     914                                                                                        base1, base2, tenv, need, have, open, noWiden() )
    913915                                                                                ) return;
    914916                                                                        }       
     
    918920                                                        }
    919921                                                        else if (! unifyExact(
    920                                                                 arg1, arg2, tenv, need, have, open, noWiden(), symtab )) return;
     922                                                                arg1, arg2, tenv, need, have, open, noWiden() )) return;
    921923
    922924                                                        ++crnt1; ++crnt2;
     
    928930                                                        if (! unifyExact(
    929931                                                                t1, tupleFromTypes( crnt2, end2 ), tenv, need, have, open,
    930                                                                 noWiden(), symtab )) return;
     932                                                                noWiden() )) return;
    931933                                                } else if ( crnt2 != end2 ) {
    932934                                                        // try unifying empty tuple with ttype
     
    935937                                                        if (! unifyExact(
    936938                                                                tupleFromTypes( crnt1, end1 ), t2, tenv, need, have, open,
    937                                                                 noWiden(), symtab )) return;
     939                                                                noWiden() )) return;
    938940                                                }
    939941                                                if ((f1->returns.size() == 0 && f2->returns.size() == 0)
    940                                                   || (f1->returns.size() == 1 && f2->returns.size() == 1 && unifyExact(f1->returns[0], f2->returns[0], tenv, need, have, open, noWiden(), symtab))) {
     942                                                  || (f1->returns.size() == 1 && f2->returns.size() == 1 && unifyExact(f1->returns[0], f2->returns[0], tenv, need, have, open, noWiden()))) {
    941943                                                        result = pointer;
    942944
     
    995997
    996998                                        ast::OpenVarSet newOpen{ open };
    997                                         if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden(), symtab ) ) {
     999                                        if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden() ) ) {
    9981000                                                result = ref;
    9991001                                                if ( q1.val != q2.val ) {
     
    10101012                        } else {
    10111013                                if (!dynamic_cast<const ast::EnumInstType *>(type2))
    1012                                         result = commonType( type2, ref, tenv, need, have, open, widen, symtab );
     1014                                        result = commonType( type2, ref, tenv, need, have, open, widen );
    10131015                        }
    10141016                }
     
    10281030                void postvisit( const ast::EnumInstType * enumInst ) {
    10291031                        if (!dynamic_cast<const ast::EnumInstType *>(type2))
    1030                                 result = commonType( type2, enumInst, tenv, need, have, open, widen, symtab);
     1032                                result = commonType( type2, enumInst, tenv, need, have, open, widen);
    10311033                }
    10321034
    10331035                void postvisit( const ast::TraitInstType * ) {}
    10341036
    1035                 void postvisit( const ast::TypeInstType * inst ) {
    1036                         if ( ! widen.first ) return;
    1037                         if ( const ast::NamedTypeDecl * nt = symtab.lookupType( inst->name ) ) {
    1038                                 if ( const ast::Type * base =
    1039                                                 strict_dynamic_cast< const ast::TypeDecl * >( nt )->base
    1040                                 ) {
    1041                                         ast::CV::Qualifiers q1 = inst->qualifiers, q2 = type2->qualifiers;
    1042 
    1043                                         // force t{1,2} to be cloned if their qualifiers must be mutated
    1044                                         ast::ptr< ast::Type > t1{ base }, t2{ type2 };
    1045                                         reset_qualifiers( t1, q1 );
    1046                                         reset_qualifiers( t2 );
    1047 
    1048                                         ast::OpenVarSet newOpen{ open };
    1049                                         if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden(), symtab ) ) {
    1050                                                 result = type2;
    1051                                                 reset_qualifiers( result, q1 | q2 );
    1052                                         } else {
    1053                                                 tryResolveWithTypedEnum( t1 );
    1054                                         }
    1055                                 }
    1056                         }
    1057                 }
     1037                void postvisit( const ast::TypeInstType * inst ) {}
    10581038
    10591039                void postvisit( const ast::TupleType * tuple) {
     
    11181098                ast::ptr< ast::Type > handleReference(
    11191099                        const ast::ptr< ast::Type > & t1, const ast::ptr< ast::Type > & t2, WidenMode widen,
    1120                         const ast::SymbolTable & symtab, ast::TypeEnvironment & env,
     1100                        ast::TypeEnvironment & env,
    11211101                        const ast::OpenVarSet & open
    11221102                ) {
     
    11261106
    11271107                        // need unify to bind type variables
    1128                         if ( unify( t1, t2, env, have, need, newOpen, symtab, common ) ) {
     1108                        if ( unify( t1, t2, env, have, need, newOpen, common ) ) {
    11291109                                ast::CV::Qualifiers q1 = t1->qualifiers, q2 = t2->qualifiers;
    11301110                                PRINT(
     
    11501130                        const ast::ptr< ast::Type > & type1, const ast::ptr< ast::Type > & type2,
    11511131                        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    1152                         const ast::OpenVarSet & open, WidenMode widen, const ast::SymbolTable & symtab
     1132                        const ast::OpenVarSet & open, WidenMode widen
    11531133        ) {
    11541134                unsigned depth1 = type1->referenceDepth();
     
    11651145                        if ( depth1 > depth2 ) {
    11661146                                assert( ref1 );
    1167                                 result = handleReference( ref1->base, type2, widen, symtab, env, open );
     1147                                result = handleReference( ref1->base, type2, widen, env, open );
    11681148                        } else {  // implies depth1 < depth2
    11691149                                assert( ref2 );
    1170                                 result = handleReference( type1, ref2->base, widen, symtab, env, open );
     1150                                result = handleReference( type1, ref2->base, widen, env, open );
    11711151                        }
    11721152
     
    11861166                }
    11871167                // otherwise both are reference types of the same depth and this is handled by the visitor
    1188                 ast::Pass<CommonType_new> visitor{ type2, widen, symtab, env, open, need, have };
     1168                ast::Pass<CommonType_new> visitor{ type2, widen, env, open, need, have };
    11891169                type1->accept( visitor );
    1190                 ast::ptr< ast::Type > result = visitor.core.result;
    1191 
    1192                 // handling for opaque type declarations (?)
    1193                 if ( ! result && widen.second ) {
    1194                         if ( const ast::TypeInstType * inst = type2.as< ast::TypeInstType >() ) {
    1195                                 if ( const ast::NamedTypeDecl * nt = symtab.lookupType( inst->name ) ) {
    1196                                         auto type = strict_dynamic_cast< const ast::TypeDecl * >( nt );
    1197                                         if ( type->base ) {
    1198                                                 ast::CV::Qualifiers q1 = type1->qualifiers, q2 = type2->qualifiers;
    1199                                                 ast::OpenVarSet newOpen{ open };
    1200 
    1201                                                 // force t{1,2} to be cloned if its qualifiers must be stripped, so that
    1202                                                 // type1 and type->base are left unchanged; calling convention forces
    1203                                                 // {type1,type->base}->strong_ref >= 1
    1204                                                 ast::ptr<ast::Type> t1{ type1 }, t2{ type->base };
    1205                                                 reset_qualifiers( t1 );
    1206                                                 reset_qualifiers( t2, q1 );
    1207 
    1208                                                 if ( unifyExact( t1, t2, env, have, need, newOpen, noWiden(), symtab ) ) {
    1209                                                         result = t1;
    1210                                                         reset_qualifiers( result, q1 | q2 );
    1211                                                 }
    1212                                         }
    1213                                 }
    1214                         }
    1215                 }
    1216 
    1217                 return result;
     1170                // ast::ptr< ast::Type > result = visitor.core.result;
     1171
     1172                return visitor.core.result;
    12181173        }
    12191174
  • src/ResolvExpr/ConversionCost.cc

    r34b4268 r24d6572  
    2222#include "ResolvExpr/Cost.h"             // for Cost
    2323#include "ResolvExpr/TypeEnvironment.h"  // for EqvClass, TypeEnvironment
    24 #include "ResolvExpr/Unify.h"
     24#include "ResolvExpr/Unify.h"            // for typesCompatibleIgnoreQualifiers
     25#include "ResolvExpr/PtrsAssignable.hpp" // for ptrsAssignable
    2526#include "SymTab/Indexer.h"              // for Indexer
    2627#include "SynTree/Declaration.h"         // for TypeDecl, NamedTypeDecl
    2728#include "SynTree/Type.h"                // for Type, BasicType, TypeInstType
    28 #include "typeops.h"                     // for typesCompatibleIgnoreQualifiers
    2929
    3030
     
    532532                }
    533533        }
    534         if ( typesCompatibleIgnoreQualifiers( src, dst, symtab, env ) ) {
     534        if ( typesCompatibleIgnoreQualifiers( src, dst, env ) ) {
    535535                return Cost::zero;
    536536        } else if ( dynamic_cast< const ast::VoidType * >( dst ) ) {
     
    566566                        ast::CV::Qualifiers tq2 = dstAsRef->base->qualifiers;
    567567                        if ( tq1 <= tq2 && typesCompatibleIgnoreQualifiers(
    568                                         srcAsRef->base, dstAsRef->base, symtab, env ) ) {
     568                                        srcAsRef->base, dstAsRef->base, env ) ) {
    569569                                if ( tq1 == tq2 ) {
    570570                                        return Cost::zero;
     
    587587                const ast::ReferenceType * dstAsRef = dynamic_cast< const ast::ReferenceType * >( dst );
    588588                assert( dstAsRef );
    589                 if ( typesCompatibleIgnoreQualifiers( src, dstAsRef->base, symtab, env ) ) {
     589                if ( typesCompatibleIgnoreQualifiers( src, dstAsRef->base, env ) ) {
    590590                        if ( srcIsLvalue ) {
    591591                                if ( src->qualifiers == dstAsRef->base->qualifiers ) {
     
    653653                ast::CV::Qualifiers tq2 = dstAsPtr->base->qualifiers;
    654654                if ( tq1 <= tq2 && typesCompatibleIgnoreQualifiers(
    655                                 pointerType->base, dstAsPtr->base, symtab, env ) ) {
     655                                pointerType->base, dstAsPtr->base, env ) ) {
    656656                        if ( tq1 == tq2 ) {
    657657                                cost = Cost::zero;
  • src/ResolvExpr/ConversionCost.h

    r34b4268 r24d6572  
    3232namespace ResolvExpr {
    3333        class TypeEnvironment;
     34
     35        Cost conversionCost(
     36                const Type * src, const Type * dest, bool srcIsLvalue,
     37                const SymTab::Indexer & indexer, const TypeEnvironment & env );
    3438
    3539        typedef std::function<Cost(const Type *, const Type *, bool,
     
    8084        const ast::SymbolTable &, const ast::TypeEnvironment &)>;
    8185
     86Cost conversionCost(
     87        const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,
     88        const ast::SymbolTable & symtab, const ast::TypeEnvironment & env );
     89
     90Cost convertToReferenceCost( const ast::Type * src, const ast::ReferenceType * dest,
     91        bool srcIsLvalue, const ast::SymbolTable & indexer, const ast::TypeEnvironment & env,
     92        PtrsCalculation func );
     93
    8294#warning when the old ConversionCost is removed, get ride of the _new suffix.
    8395class ConversionCost_new : public ast::WithShortCircuiting {
     
    119131};
    120132
    121 Cost convertToReferenceCost( const ast::Type * src, const ast::ReferenceType * dest,
    122         bool srcIsLvalue, const ast::SymbolTable & indexer, const ast::TypeEnvironment & env,
    123         PtrsCalculation func );
    124 
    125133} // namespace ResolvExpr
    126134
  • src/ResolvExpr/CurrentObject.cc

    r34b4268 r24d6572  
    99// Author           : Rob Schluntz
    1010// Created On       : Tue Jun 13 15:28:32 2017
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul  1 09:16:01 2022
    13 // Update Count     : 15
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Apr 10  9:40:00 2023
     13// Update Count     : 18
    1414//
    1515
     
    2626#include "AST/Init.hpp"                // for Designation
    2727#include "AST/Node.hpp"                // for readonly
    28 #include "AST/Print.hpp"                // for readonly
     28#include "AST/Print.hpp"               // for readonly
    2929#include "AST/Type.hpp"
     30#include "Common/Eval.h"               // for eval
    3031#include "Common/Indenter.h"           // for Indenter, operator<<
    3132#include "Common/SemanticError.h"      // for SemanticError
     
    592593
    593594namespace ast {
     595        /// Iterates members of a type by initializer.
     596        class MemberIterator {
     597        public:
     598                virtual ~MemberIterator() {}
     599
     600                /// Internal set position based on iterator ranges.
     601                virtual void setPosition(
     602                        std::deque< ptr< Expr > >::const_iterator it,
     603                        std::deque< ptr< Expr > >::const_iterator end ) = 0;
     604
     605                /// Walks the current object using the given designators as a guide.
     606                void setPosition( const std::deque< ptr< Expr > > & designators ) {
     607                        setPosition( designators.begin(), designators.end() );
     608                }
     609
     610                /// Retrieve the list of possible (Type,Designation) pairs for the
     611                /// current position in the current object.
     612                virtual std::deque< InitAlternative > operator* () const = 0;
     613
     614                /// True if the iterator is not currently at the end.
     615                virtual operator bool() const = 0;
     616
     617                /// Moves the iterator by one member in the current object.
     618                virtual MemberIterator & bigStep() = 0;
     619
     620                /// Moves the iterator by one member in the current subobject.
     621                virtual MemberIterator & smallStep() = 0;
     622
     623                /// The type of the current object.
     624                virtual const Type * getType() = 0;
     625
     626                /// The type of the current subobject.
     627                virtual const Type * getNext() = 0;
     628
     629                /// Helper for operator*; aggregates must add designator to each init
     630                /// alternative, but adding designators in operator* creates duplicates.
     631                virtual std::deque< InitAlternative > first() const = 0;
     632        };
     633
    594634        /// create a new MemberIterator that traverses a type correctly
    595635        MemberIterator * createMemberIterator( const CodeLocation & loc, const Type * type );
     
    631671        };
    632672
    633         /// Iterates array types
    634         class ArrayIterator final : public MemberIterator {
     673        /// Iterates over an indexed type:
     674        class IndexIterator : public MemberIterator {
     675        protected:
    635676                CodeLocation location;
    636                 const ArrayType * array = nullptr;
    637                 const Type * base = nullptr;
    638677                size_t index = 0;
    639678                size_t size = 0;
    640                 std::unique_ptr< MemberIterator > memberIter;
    641 
    642                 void setSize( const Expr * expr ) {
    643                         auto res = eval( expr );
    644                         if ( ! res.second ) {
    645                                 SemanticError( location, toString( "Array designator must be a constant expression: ", expr ) );
    646                         }
    647                         size = res.first;
    648                 }
    649 
    650         public:
    651                 ArrayIterator( const CodeLocation & loc, const ArrayType * at ) : location( loc ), array( at ), base( at->base ) {
    652                         PRINT( std::cerr << "Creating array iterator: " << at << std::endl; )
    653                         memberIter.reset( createMemberIterator( loc, base ) );
    654                         if ( at->isVarLen ) {
    655                                 SemanticError( location, at, "VLA initialization does not support @=: " );
    656                         }
    657                         setSize( at->dimension );
    658                 }
     679                std::unique_ptr<MemberIterator> memberIter;
     680        public:
     681                IndexIterator( const CodeLocation & loc, size_t size ) :
     682                        location( loc ), size( size )
     683                {}
    659684
    660685                void setPosition( const Expr * expr ) {
     
    665690                        auto arg = eval( expr );
    666691                        index = arg.first;
    667                         return;
    668692
    669693                        // if ( auto constExpr = dynamic_cast< const ConstantExpr * >( expr ) ) {
     
    683707
    684708                void setPosition(
    685                         std::deque< ptr< Expr > >::const_iterator begin,
    686                         std::deque< ptr< Expr > >::const_iterator end
     709                        std::deque<ast::ptr<ast::Expr>>::const_iterator begin,
     710                        std::deque<ast::ptr<ast::Expr>>::const_iterator end
    687711                ) override {
    688712                        if ( begin == end ) return;
     
    695719
    696720                operator bool() const override { return index < size; }
     721        };
     722
     723        /// Iterates over the members of array types:
     724        class ArrayIterator final : public IndexIterator {
     725                const ArrayType * array = nullptr;
     726                const Type * base = nullptr;
     727
     728                size_t getSize( const Expr * expr ) {
     729                        auto res = eval( expr );
     730                        if ( !res.second ) {
     731                                SemanticError( location, toString( "Array designator must be a constant expression: ", expr ) );
     732                        }
     733                        return res.first;
     734                }
     735
     736        public:
     737                ArrayIterator( const CodeLocation & loc, const ArrayType * at ) :
     738                                IndexIterator( loc, getSize( at->dimension) ),
     739                                array( at ), base( at->base ) {
     740                        PRINT( std::cerr << "Creating array iterator: " << at << std::endl; )
     741                        memberIter.reset( createMemberIterator( loc, base ) );
     742                        if ( at->isVarLen ) {
     743                                SemanticError( location, at, "VLA initialization does not support @=: " );
     744                        }
     745                }
    697746
    698747                ArrayIterator & bigStep() override {
     
    833882
    834883                const Type * getNext() final {
    835                         return ( memberIter && *memberIter ) ? memberIter->getType() : nullptr;
     884                        bool hasMember = memberIter && *memberIter;
     885                        return hasMember ? memberIter->getType() : nullptr;
    836886                }
    837887
     
    897947        };
    898948
    899         class TupleIterator final : public AggregateIterator {
    900         public:
    901                 TupleIterator( const CodeLocation & loc, const TupleType * inst )
    902                 : AggregateIterator(
    903                         loc, "TupleIterator", toString("Tuple", inst->size()), inst, inst->members
    904                 ) {}
    905 
    906                 operator bool() const override {
    907                         return curMember != members.end() || (memberIter && *memberIter);
     949        /// Iterates across the positions in a tuple:
     950        class TupleIterator final : public IndexIterator {
     951                ast::TupleType const * const tuple;
     952
     953                const ast::Type * typeAtIndex() const {
     954                        assert( index < size );
     955                        return tuple->types[ index ].get();
     956                }
     957
     958        public:
     959                TupleIterator( const CodeLocation & loc, const TupleType * type )
     960                : IndexIterator( loc, type->size() ), tuple( type ) {
     961                        PRINT( std::cerr << "Creating tuple iterator: " << type << std::endl; )
     962                        memberIter.reset( createMemberIterator( loc, typeAtIndex() ) );
    908963                }
    909964
    910965                TupleIterator & bigStep() override {
    911                         PRINT( std::cerr << "bigStep in " << kind << std::endl; )
    912                         atbegin = false;
    913                         memberIter = nullptr;
    914                         curType = nullptr;
    915                         while ( curMember != members.end() ) {
    916                                 ++curMember;
    917                                 if ( init() ) return *this;
    918                         }
     966                        ++index;
     967                        memberIter.reset( index < size ?
     968                                createMemberIterator( location, typeAtIndex() ) : nullptr );
    919969                        return *this;
     970                }
     971
     972                TupleIterator & smallStep() override {
     973                        if ( memberIter ) {
     974                                PRINT( std::cerr << "has member iter: " << *memberIter << std::endl; )
     975                                memberIter->smallStep();
     976                                if ( !memberIter ) {
     977                                        PRINT( std::cerr << "has valid member iter" << std::endl; )
     978                                        return *this;
     979                                }
     980                        }
     981                        return bigStep();
     982                }
     983
     984                const ast::Type * getType() override {
     985                        return tuple;
     986                }
     987
     988                const ast::Type * getNext() override {
     989                        bool hasMember = memberIter && *memberIter;
     990                        return hasMember ? memberIter->getType() : nullptr;
     991                }
     992
     993                std::deque< InitAlternative > first() const override {
     994                        PRINT( std::cerr << "first in TupleIterator (" << index << "/" << size << ")" << std::endl; )
     995                        if ( memberIter && *memberIter ) {
     996                                std::deque< InitAlternative > ret = memberIter->first();
     997                                for ( InitAlternative & alt : ret ) {
     998                                        alt.designation.get_and_mutate()->designators.emplace_front(
     999                                                ConstantExpr::from_ulong( location, index ) );
     1000                                }
     1001                                return ret;
     1002                        }
     1003                        return {};
    9201004                }
    9211005        };
  • src/ResolvExpr/CurrentObject.h

    r34b4268 r24d6572  
    99// Author           : Rob Schluntz
    1010// Created On       : Thu Jun  8 11:07:25 2017
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:36:48 2017
    13 // Update Count     : 3
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thu Apr  6 16:14:00 2023
     13// Update Count     : 4
    1414//
    1515
     
    6565
    6666        /// Iterates members of a type by initializer
    67         class MemberIterator {
    68         public:
    69                 virtual ~MemberIterator() {}
    70 
    71                 /// Internal set position based on iterator ranges
    72                 virtual void setPosition(
    73                         std::deque< ptr< Expr > >::const_iterator it,
    74                         std::deque< ptr< Expr > >::const_iterator end ) = 0;
    75 
    76                 /// walks the current object using the given designators as a guide
    77                 void setPosition( const std::deque< ptr< Expr > > & designators ) {
    78                         setPosition( designators.begin(), designators.end() );
    79                 }
    80 
    81                 /// retrieve the list of possible (Type,Designation) pairs for the current position in the
    82                 /// current object
    83                 virtual std::deque< InitAlternative > operator* () const = 0;
    84 
    85                 /// true if the iterator is not currently at the end
    86                 virtual operator bool() const = 0;
    87 
    88                 /// moves the iterator by one member in the current object
    89                 virtual MemberIterator & bigStep() = 0;
    90 
    91                 /// moves the iterator by one member in the current subobject
    92                 virtual MemberIterator & smallStep() = 0;
    93 
    94                 /// the type of the current object
    95                 virtual const Type * getType() = 0;
    96 
    97                 /// the type of the current subobject
    98                 virtual const Type * getNext() = 0;
    99        
    100                 /// helper for operator*; aggregates must add designator to each init alternative, but
    101                 /// adding designators in operator* creates duplicates
    102                 virtual std::deque< InitAlternative > first() const = 0;
    103         };
     67        class MemberIterator;
    10468
    10569        /// Builds initializer lists in resolution
  • src/ResolvExpr/ExplodedArg.hpp

    r34b4268 r24d6572  
    3535        ExplodedArg() : env(), cost( Cost::zero ), exprs() {}
    3636        ExplodedArg( const Candidate & arg, const ast::SymbolTable & symtab );
    37        
     37
    3838        ExplodedArg( ExplodedArg && ) = default;
    3939        ExplodedArg & operator= ( ExplodedArg && ) = default;
  • src/ResolvExpr/PolyCost.cc

    r34b4268 r24d6572  
    1515
    1616#include "AST/SymbolTable.hpp"
     17#include "AST/Pass.hpp"
    1718#include "AST/Type.hpp"
    1819#include "AST/TypeEnvironment.hpp"
  • src/ResolvExpr/PtrsAssignable.cc

    r34b4268 r24d6572  
    1414//
    1515
    16 #include "typeops.h"
     16#include "PtrsAssignable.hpp"
    1717
    1818#include "AST/Pass.hpp"
  • src/ResolvExpr/PtrsCastable.cc

    r34b4268 r24d6572  
    1414//
    1515
     16#include "PtrsCastable.hpp"
     17
    1618#include "AST/Decl.hpp"
    1719#include "AST/Pass.hpp"
     
    1921#include "AST/TypeEnvironment.hpp"
    2022#include "Common/PassVisitor.h"
     23#include "ResolvExpr/PtrsAssignable.hpp" // for ptrsAssignable
    2124#include "ResolvExpr/TypeEnvironment.h"  // for EqvClass, TypeEnvironment
    2225#include "SymTab/Indexer.h"              // for Indexer
     
    2427#include "SynTree/Type.h"                // for TypeInstType, Type, BasicType
    2528#include "SynTree/Visitor.h"             // for Visitor
    26 #include "typeops.h"                     // for ptrsAssignable
    2729
    2830namespace ResolvExpr {
     
    291293                return objectCast( src, env, symtab );
    292294        } else {
    293                 ast::Pass< PtrsCastable_new > ptrs{ dst, env, symtab };
    294                 src->accept( ptrs );
    295                 return ptrs.core.result;
     295                return ast::Pass<PtrsCastable_new>::read( src, dst, env, symtab );
    296296        }
    297297}
  • src/ResolvExpr/RenameVars.cc

    r34b4268 r24d6572  
    8383
    8484                const ast::TypeInstType * rename( const ast::TypeInstType * type ) {
    85                         // rename
    8685                        auto it = idMap.find( type->name );
    87                         if ( it != idMap.end() ) {
    88                                 // unconditionally mutate because map will *always* have different name
    89                                 ast::TypeInstType * mut = ast::shallowCopy( type );
    90                                 // reconcile base node since some copies might have been made
    91                                 mut->base = it->second.base;
    92                                 mut->formal_usage = it->second.formal_usage;
    93                                 mut->expr_id = it->second.expr_id;
    94                     type = mut;
    95                         }
    96 
    97                         return type;
     86                        if ( it == idMap.end() ) return type;
     87
     88                        // Unconditionally mutate because map will *always* have different name.
     89                        ast::TypeInstType * mut = ast::shallowCopy( type );
     90                        // Reconcile base node since some copies might have been made.
     91                        mut->base = it->second.base;
     92                        mut->formal_usage = it->second.formal_usage;
     93                        mut->expr_id = it->second.expr_id;
     94                        return mut;
    9895                }
    9996
     
    187184
    188185const ast::Type * renameTyVars( const ast::Type * t, RenameMode mode, bool reset ) {
    189         // ast::Type *tc = ast::deepCopy(t);
    190186        ast::Pass<RenameVars_new> renamer;
    191187        renamer.core.mode = mode;
  • src/ResolvExpr/ResolveAssertions.cc

    r34b4268 r24d6572  
    2626#include <vector>                   // for vector
    2727
     28#include "AdjustExprType.hpp"       // for adjustExprType
    2829#include "Alternative.h"            // for Alternative, AssertionItem, AssertionList
    2930#include "Common/FilterCombos.h"    // for filterCombos
    3031#include "Common/Indenter.h"        // for Indenter
    31 #include "Common/utility.h"         // for sort_mins
    3232#include "GenPoly/GenPoly.h"        // for getFunctionType
     33#include "ResolvExpr/AlternativeFinder.h"  // for computeConversionCost
    3334#include "ResolvExpr/RenameVars.h"  // for renameTyVars
     35#include "SpecCost.hpp"             // for specCost
    3436#include "SymTab/Indexer.h"         // for Indexer
    3537#include "SymTab/Mangler.h"         // for Mangler
    3638#include "SynTree/Expression.h"     // for InferredParams
    3739#include "TypeEnvironment.h"        // for TypeEnvironment, etc.
    38 #include "typeops.h"                // for adjustExprType, specCost
    3940#include "Unify.h"                  // for unify
    4041
  • src/ResolvExpr/Resolver.cc

    r34b4268 r24d6572  
    3838#include "AST/SymbolTable.hpp"
    3939#include "AST/Type.hpp"
     40#include "Common/Eval.h"                 // for eval
     41#include "Common/Iterate.hpp"            // for group_iterate
    4042#include "Common/PassVisitor.h"          // for PassVisitor
    4143#include "Common/SemanticError.h"        // for SemanticError
    4244#include "Common/Stats/ResolveTime.h"    // for ResolveTime::start(), ResolveTime::stop()
    43 #include "Common/utility.h"              // for ValueGuard, group_iterate
     45#include "Common/ToString.hpp"           // for toCString
    4446#include "InitTweak/GenInit.h"
    4547#include "InitTweak/InitTweak.h"         // for isIntrinsicSingleArgCallStmt
     
    11071109                void removeExtraneousCast( ast::ptr<ast::Expr> & expr, const ast::SymbolTable & symtab ) {
    11081110                        if ( const ast::CastExpr * castExpr = expr.as< ast::CastExpr >() ) {
    1109                                 if ( typesCompatible( castExpr->arg->result, castExpr->result, symtab ) ) {
     1111                                if ( typesCompatible( castExpr->arg->result, castExpr->result ) ) {
    11101112                                        // cast is to the same type as its argument, remove it
    11111113                                        swap_and_save_env( expr, castExpr->arg );
     
    17291731
    17301732                        // Find all candidates for a function in canonical form
    1731                         funcFinder.find( clause.target_func, ResolvMode::withAdjustment() );
     1733                        funcFinder.find( clause.target, ResolvMode::withAdjustment() );
    17321734
    17331735                        if ( funcFinder.candidates.empty() ) {
    17341736                                stringstream ss;
    17351737                                ss << "Use of undeclared indentifier '";
    1736                                 ss << clause.target_func.strict_as< ast::NameExpr >()->name;
     1738                                ss << clause.target.strict_as< ast::NameExpr >()->name;
    17371739                                ss << "' in call to waitfor";
    17381740                                SemanticError( stmt->location, ss.str() );
     
    18331835                                                                if (
    18341836                                                                        ! unify(
    1835                                                                                 arg->expr->result, *param, resultEnv, need, have, open,
    1836                                                                                 symtab )
     1837                                                                                arg->expr->result, *param, resultEnv, need, have, open )
    18371838                                                                ) {
    18381839                                                                        // Type doesn't match
     
    19211922                        auto clause2 = new ast::WaitForClause( clause.location );
    19221923
    1923                         clause2->target_func = funcCandidates.front()->expr;
     1924                        clause2->target = funcCandidates.front()->expr;
    19241925
    19251926                        clause2->target_args.reserve( clause.target_args.size() );
     
    19441945
    19451946                        // Resolve the conditions as if it were an IfStmt, statements normally
    1946                         clause2->cond = findSingleExpression( clause.cond, context );
     1947                        clause2->when_cond = findSingleExpression( clause.when_cond, context );
    19471948                        clause2->stmt = clause.stmt->accept( *visitor );
    19481949
  • src/ResolvExpr/Resolver.h

    r34b4268 r24d6572  
    3434        class Decl;
    3535        class DeletedExpr;
     36        class Expr;
    3637        class Init;
    3738        class StmtExpr;
  • src/ResolvExpr/SatisfyAssertions.cpp

    r34b4268 r24d6572  
    2424#include <vector>
    2525
     26#include "AdjustExprType.hpp"
    2627#include "Candidate.hpp"
    2728#include "CandidateFinder.hpp"
     29#include "CommonType.hpp"
    2830#include "Cost.h"
    2931#include "RenameVars.h"
     32#include "SpecCost.hpp"
    3033#include "typeops.h"
    3134#include "Unify.h"
     
    181184                                .strict_as<ast::FunctionType>()->params[0]
    182185                                .strict_as<ast::ReferenceType>()->base;
    183                         sat.cand->env.apply(thisArgType);
     186                        // sat.cand->env.apply(thisArgType);
     187
     188                        if (auto inst = thisArgType.as<ast::TypeInstType>()) {
     189                                auto cls = sat.cand->env.lookup(*inst);
     190                                if (cls && cls->bound) thisArgType = cls->bound;
     191                        }
    184192
    185193                        std::string otypeKey = "";
     
    218226                        ast::TypeEnvironment tempNewEnv {newEnv};
    219227
    220                         if ( unifyExact( toType, adjType, tempNewEnv, newNeed, have, newOpen, WidenMode {true, true}, sat.symtab ) ) {
     228                        if ( unifyExact( toType, adjType, tempNewEnv, newNeed, have, newOpen, WidenMode {true, true} ) ) {
    221229                                // set up binding slot for recursive assertions
    222230                                ast::UniqueId crntResnSlot = 0;
     
    234242                                // newEnv = sat.cand->env;
    235243                                // newNeed.clear();
    236                                 if ( auto c = commonType( toType, adjType, newEnv, newNeed, have, newOpen, WidenMode {true, true}, sat.symtab ) ) {
     244                                if ( auto c = commonType( toType, adjType, newEnv, newNeed, have, newOpen, WidenMode {true, true} ) ) {
    237245                                        // set up binding slot for recursive assertions
    238246                                        ast::UniqueId crntResnSlot = 0;
     
    398406                        mergeOpenVars( open, i.match.open );
    399407
    400                         if ( ! env.combine( i.match.env, open, symtab ) ) return false;
     408                        if ( ! env.combine( i.match.env, open ) ) return false;
    401409
    402410                        crnt.emplace_back( i );
  • src/ResolvExpr/Unify.cc

    r34b4268 r24d6572  
    3333#include "AST/TypeEnvironment.hpp"
    3434#include "Common/PassVisitor.h"     // for PassVisitor
     35#include "CommonType.hpp"           // for commonType
    3536#include "FindOpenVars.h"           // for findOpenVars
     37#include "SpecCost.hpp"             // for SpecCost
    3638#include "SynTree/LinkageSpec.h"    // for C
    3739#include "SynTree/Constant.h"       // for Constant
     
    4345#include "Tuples/Tuples.h"          // for isTtype
    4446#include "TypeEnvironment.h"        // for EqvClass, AssertionSet, OpenVarSet
    45 #include "typeops.h"                // for flatten, occurs, commonType
     47#include "typeops.h"                // for flatten, occurs
    4648
    4749namespace ast {
     
    5052
    5153namespace SymTab {
    52 class Indexer;
     54        class Indexer;
    5355}  // namespace SymTab
    5456
     
    5658
    5759namespace ResolvExpr {
     60
     61// Template Helpers:
     62template< typename Iterator1, typename Iterator2 >
     63bool unifyList( Iterator1 list1Begin, Iterator1 list1End, Iterator2 list2Begin, Iterator2 list2End, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer, std::list< Type* > &commonTypes ) {
     64        for ( ; list1Begin != list1End && list2Begin != list2End; ++list1Begin, ++list2Begin ) {
     65                Type *commonType = 0;
     66                if ( ! unify( *list1Begin, *list2Begin, env, needAssertions, haveAssertions, openVars, indexer, commonType ) ) {
     67                        return false;
     68                } // if
     69                commonTypes.push_back( commonType );
     70        } // for
     71        return ( list1Begin == list1End && list2Begin == list2End );
     72}
     73
     74template< typename Iterator1, typename Iterator2 >
     75bool unifyList( Iterator1 list1Begin, Iterator1 list1End, Iterator2 list2Begin, Iterator2 list2End, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer ) {
     76        std::list< Type* > commonTypes;
     77        if ( unifyList( list1Begin, list1End, list2Begin, list2End, env, needAssertions, haveAssertions,  openVars, indexer, commonTypes ) ) {
     78                deleteAll( commonTypes );
     79                return true;
     80        } else {
     81                return false;
     82        } // if
     83}
    5884
    5985        struct Unify_old : public WithShortCircuiting {
     
    102128                const ast::Type * type1, const ast::Type * type2, ast::TypeEnvironment & env,
    103129                ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open,
    104                 WidenMode widen, const ast::SymbolTable & symtab );
     130                WidenMode widen );
    105131
    106132        bool typesCompatible( const Type * first, const Type * second, const SymTab::Indexer & indexer, const TypeEnvironment & env ) {
     
    124150
    125151        bool typesCompatible(
    126                         const ast::Type * first, const ast::Type * second, const ast::SymbolTable & symtab,
     152                        const ast::Type * first, const ast::Type * second,
    127153                        const ast::TypeEnvironment & env ) {
    128154                ast::TypeEnvironment newEnv;
     
    137163                findOpenVars( newSecond, open, closed, need, have, newEnv, FirstOpen );
    138164
    139                 return unifyExact(newFirst, newSecond, newEnv, need, have, open, noWiden(), symtab );
     165                return unifyExact(newFirst, newSecond, newEnv, need, have, open, noWiden() );
    140166        }
    141167
     
    157183
    158184        bool typesCompatibleIgnoreQualifiers(
    159                         const ast::Type * first, const ast::Type * second, const ast::SymbolTable & symtab,
     185                        const ast::Type * first, const ast::Type * second,
    160186                        const ast::TypeEnvironment & env ) {
    161187                ast::TypeEnvironment newEnv;
     
    190216                        subFirst,
    191217                        subSecond,
    192                         newEnv, need, have, open, noWiden(), symtab );
     218                        newEnv, need, have, open, noWiden() );
    193219        }
    194220
     
    760786                const ast::OpenVarSet & open;
    761787                WidenMode widen;
    762                 const ast::SymbolTable & symtab;
    763788        public:
    764789                static size_t traceId;
     
    767792                Unify_new(
    768793                        const ast::Type * type2, ast::TypeEnvironment & env, ast::AssertionSet & need,
    769                         ast::AssertionSet & have, const ast::OpenVarSet & open, WidenMode widen,
    770                         const ast::SymbolTable & symtab )
     794                        ast::AssertionSet & have, const ast::OpenVarSet & open, WidenMode widen )
    771795                : type2(type2), tenv(env), need(need), have(have), open(open), widen(widen),
    772                   symtab(symtab), result(false) {}
     796                result(false) {}
    773797
    774798                void previsit( const ast::Node * ) { visit_children = false; }
     
    788812                                result = unifyExact(
    789813                                        pointer->base, pointer2->base, tenv, need, have, open,
    790                                         noWiden(), symtab );
     814                                        noWiden());
    791815                        }
    792816                }
     
    811835
    812836                        result = unifyExact(
    813                                 array->base, array2->base, tenv, need, have, open, noWiden(),
    814                                 symtab );
     837                                array->base, array2->base, tenv, need, have, open, noWiden());
    815838                }
    816839
     
    818841                        if ( auto ref2 = dynamic_cast< const ast::ReferenceType * >( type2 ) ) {
    819842                                result = unifyExact(
    820                                         ref->base, ref2->base, tenv, need, have, open, noWiden(),
    821                                         symtab );
     843                                        ref->base, ref2->base, tenv, need, have, open, noWiden());
    822844                        }
    823845                }
     
    828850                static bool unifyTypeList(
    829851                        Iter crnt1, Iter end1, Iter crnt2, Iter end2, ast::TypeEnvironment & env,
    830                         ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open,
    831                         const ast::SymbolTable & symtab
     852                        ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open
    832853                ) {
    833854                        while ( crnt1 != end1 && crnt2 != end2 ) {
     
    842863                                        return unifyExact(
    843864                                                t1, tupleFromTypes( crnt2, end2 ), env, need, have, open,
    844                                                 noWiden(), symtab );
     865                                                noWiden() );
    845866                                } else if ( ! isTuple1 && isTuple2 ) {
    846867                                        // combine remainder of list1, then unify
    847868                                        return unifyExact(
    848869                                                tupleFromTypes( crnt1, end1 ), t2, env, need, have, open,
    849                                                 noWiden(), symtab );
     870                                                noWiden() );
    850871                                }
    851872
    852873                                if ( ! unifyExact(
    853                                         t1, t2, env, need, have, open, noWiden(), symtab )
     874                                        t1, t2, env, need, have, open, noWiden() )
    854875                                ) return false;
    855876
     
    865886                                return unifyExact(
    866887                                        t1, tupleFromTypes( crnt2, end2 ), env, need, have, open,
    867                                         noWiden(), symtab );
     888                                        noWiden() );
    868889                        } else if ( crnt2 != end2 ) {
    869890                                // try unifying empty tuple with ttype
     
    872893                                return unifyExact(
    873894                                        tupleFromTypes( crnt1, end1 ), t2, env, need, have, open,
    874                                         noWiden(), symtab );
     895                                        noWiden() );
    875896                        }
    876897
     
    882903                        const std::vector< ast::ptr< ast::Type > > & list2,
    883904                        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    884                         const ast::OpenVarSet & open, const ast::SymbolTable & symtab
     905                        const ast::OpenVarSet & open
    885906                ) {
    886907                        return unifyTypeList(
    887                                 list1.begin(), list1.end(), list2.begin(), list2.end(), env, need, have, open,
    888                                 symtab );
     908                                list1.begin(), list1.end(), list2.begin(), list2.end(), env, need, have, open);
    889909                }
    890910
     
    927947                        ) return;
    928948
    929                         if ( ! unifyTypeList( params, params2, tenv, need, have, open, symtab ) ) return;
     949                        if ( ! unifyTypeList( params, params2, tenv, need, have, open ) ) return;
    930950                        if ( ! unifyTypeList(
    931                                 func->returns, func2->returns, tenv, need, have, open, symtab ) ) return;
     951                                func->returns, func2->returns, tenv, need, have, open ) ) return;
    932952
    933953                        markAssertions( have, need, func );
     
    944964                        // check that the other type is compatible and named the same
    945965                        auto otherInst = dynamic_cast< const XInstType * >( other );
    946                         if (otherInst && inst->name == otherInst->name) this->result = otherInst;
     966                        if (otherInst && inst->name == otherInst->name)
     967                                this->result = otherInst;
    947968                        return otherInst;
    948969                }
     
    10001021
    10011022                                if ( ! unifyExact(
    1002                                                 pty, pty2, tenv, need, have, open, noWiden(), symtab ) ) {
     1023                                                pty, pty2, tenv, need, have, open, noWiden() ) ) {
    10031024                                        result = false;
    10041025                                        return;
     
    10301051                void postvisit( const ast::TypeInstType * typeInst ) {
    10311052                        // assert( open.find( *typeInst ) == open.end() );
    1032                         handleRefType( typeInst, type2 );
     1053                        auto otherInst = dynamic_cast< const ast::TypeInstType * >( type2 );
     1054                        if (otherInst && typeInst->name == otherInst->name)
     1055                                this->result = otherInst;
     1056                        // return otherInst;
    10331057                }
    10341058
     
    10391063                        const std::vector< ast::ptr< ast::Type > > & list1,
    10401064                        const std::vector< ast::ptr< ast::Type > > & list2, ast::TypeEnvironment & env,
    1041                         ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open,
    1042                         const ast::SymbolTable & symtab
     1065                        ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open
    10431066                ) {
    10441067                        auto crnt1 = list1.begin();
     
    10551078                                        return unifyExact(
    10561079                                                t1, tupleFromTypes( list2 ), env, need, have, open,
    1057                                                 noWiden(), symtab );
     1080                                                noWiden() );
    10581081                                } else if ( ! isTuple1 && isTuple2 ) {
    10591082                                        // combine entirety of list1, then unify
    10601083                                        return unifyExact(
    10611084                                                tupleFromTypes( list1 ), t2, env, need, have, open,
    1062                                                 noWiden(), symtab );
     1085                                                noWiden() );
    10631086                                }
    10641087
    10651088                                if ( ! unifyExact(
    1066                                         t1, t2, env, need, have, open, noWiden(), symtab )
     1089                                        t1, t2, env, need, have, open, noWiden() )
    10671090                                ) return false;
    10681091
     
    10781101                                return unifyExact(
    10791102                                                t1, tupleFromTypes( list2 ), env, need, have, open,
    1080                                                 noWiden(), symtab );
     1103                                                noWiden() );
    10811104                        } else if ( crnt2 != list2.end() ) {
    10821105                                // try unifying empty tuple with ttype
     
    10871110                                return unifyExact(
    10881111                                                tupleFromTypes( list1 ), t2, env, need, have, open,
    1089                                                 noWiden(), symtab );
     1112                                                noWiden() );
    10901113                        }
    10911114
     
    11061129                        auto types2 = flatten( flat2 );
    11071130
    1108                         result = unifyList( types, types2, tenv, need, have, open, symtab );
     1131                        result = unifyList( types, types2, tenv, need, have, open );
    11091132                }
    11101133
     
    11301153                        const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
    11311154                        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    1132                         ast::OpenVarSet & open, const ast::SymbolTable & symtab
     1155                        ast::OpenVarSet & open
    11331156        ) {
    11341157                ast::ptr<ast::Type> common;
    1135                 return unify( type1, type2, env, need, have, open, symtab, common );
     1158                return unify( type1, type2, env, need, have, open, common );
    11361159        }
    11371160
     
    11391162                        const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
    11401163                        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    1141                         ast::OpenVarSet & open, const ast::SymbolTable & symtab, ast::ptr<ast::Type> & common
     1164                        ast::OpenVarSet & open, ast::ptr<ast::Type> & common
    11421165        ) {
    11431166                ast::OpenVarSet closed;
     
    11451168                findOpenVars( type2, open, closed, need, have, env, FirstOpen );
    11461169                return unifyInexact(
    1147                         type1, type2, env, need, have, open, WidenMode{ true, true }, symtab, common );
     1170                        type1, type2, env, need, have, open, WidenMode{ true, true }, common );
    11481171        }
    11491172
     
    11511174                        const ast::Type * type1, const ast::Type * type2, ast::TypeEnvironment & env,
    11521175                        ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open,
    1153                         WidenMode widen, const ast::SymbolTable & symtab
     1176                        WidenMode widen
    11541177        ) {
    11551178                if ( type1->qualifiers != type2->qualifiers ) return false;
     
    11701193                        return env.bindVarToVar(
    11711194                                var1, var2, ast::TypeData{ entry1->second, entry2->second }, need, have,
    1172                                 open, widen, symtab );
     1195                                open, widen );
    11731196                } else if ( isopen1 ) {
    1174                         return env.bindVar( var1, type2, entry1->second, need, have, open, widen, symtab );
     1197                        return env.bindVar( var1, type2, entry1->second, need, have, open, widen );
    11751198                } else if ( isopen2 ) {
    11761199                        return env.bindVar( var2, type1, entry2->second, need, have, open, widen, symtab );
     
    11801203                        return env.bindVarToVar(
    11811204                                var1, var2, ast::TypeData{ var1->base->kind, var1->base->sized||var2->base->sized }, need, have,
    1182                                 open, widen, symtab );
     1205                                open, widen );
    11831206                } else if ( isopen1 ) {
    1184                         return env.bindVar( var1, type2, ast::TypeData{var1->base}, need, have, open, widen, symtab );
     1207                        return env.bindVar( var1, type2, ast::TypeData{var1->base}, need, have, open, widen );
    11851208                } else if ( isopen2 ) {
    1186                         return env.bindVar( var2, type1, ast::TypeData{var2->base}, need, have, open, widen, symtab );
     1209                        return env.bindVar( var2, type1, ast::TypeData{var2->base}, need, have, open, widen );
    11871210                }else {
    11881211                        return ast::Pass<Unify_new>::read(
    1189                                 type1, type2, env, need, have, open, widen, symtab );
     1212                                type1, type2, env, need, have, open, widen );
    11901213                }
    11911214               
     
    11951218                        const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
    11961219                        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    1197                         const ast::OpenVarSet & open, WidenMode widen, const ast::SymbolTable & symtab,
     1220                        const ast::OpenVarSet & open, WidenMode widen,
    11981221                        ast::ptr<ast::Type> & common
    11991222        ) {
     
    12091232                ast::ptr< ast::Type > t2_(t2);
    12101233
    1211                 if ( unifyExact( t1, t2, env, need, have, open, widen, symtab ) ) {
     1234                if ( unifyExact( t1, t2, env, need, have, open, widen ) ) {
    12121235                        // if exact unification on unqualified types, try to merge qualifiers
    12131236                        if ( q1 == q2 || ( ( q1 > q2 || widen.first ) && ( q2 > q1 || widen.second ) ) ) {
     
    12191242                        }
    12201243
    1221                 } else if (( common = commonType( t1, t2, env, need, have, open, widen, symtab ))) {
     1244                } else if (( common = commonType( t1, t2, env, need, have, open, widen ))) {
    12221245                        // no exact unification, but common type
    12231246                        auto c = shallowCopy(common.get());
  • src/ResolvExpr/Unify.h

    r34b4268 r24d6572  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 13:09:04 2015
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Mon Jun 18 11:58:00 2018
    13 // Update Count     : 4
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tue Jan 17 11:12:00 2023
     13// Update Count     : 5
    1414//
    1515
     
    3737
    3838namespace ResolvExpr {
    39         bool unify( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer );
    40         bool unify( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer, Type *&commonType );
    41         bool unifyExact( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer );
    42         bool unifyInexact( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widen, const SymTab::Indexer &indexer, Type *&common );
    4339
    44         template< typename Iterator1, typename Iterator2 >
    45         bool unifyList( Iterator1 list1Begin, Iterator1 list1End, Iterator2 list2Begin, Iterator2 list2End, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer, std::list< Type* > &commonTypes ) {
    46                 for ( ; list1Begin != list1End && list2Begin != list2End; ++list1Begin, ++list2Begin ) {
    47                         Type *commonType = 0;
    48                         if ( ! unify( *list1Begin, *list2Begin, env, needAssertions, haveAssertions, openVars, indexer, commonType ) ) {
    49                                 return false;
    50                         } // if
    51                         commonTypes.push_back( commonType );
    52                 } // for
    53                 if ( list1Begin != list1End || list2Begin != list2End ) {
    54                         return false;
    55                 } else {
    56                         return true;
    57                 } // if
    58         }
     40bool unify( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer );
     41bool unify( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer, Type *&commonType );
     42bool unifyExact( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer );
     43bool unifyInexact( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widen, const SymTab::Indexer &indexer, Type *&common );
    5944
    60         template< typename Iterator1, typename Iterator2 >
    61         bool unifyList( Iterator1 list1Begin, Iterator1 list1End, Iterator2 list2Begin, Iterator2 list2End, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer ) {
    62                 std::list< Type* > commonTypes;
    63                 if ( unifyList( list1Begin, list1End, list2Begin, list2End, env, needAssertions, haveAssertions, openVars, indexer, commonTypes ) ) {
    64                         deleteAll( commonTypes );
    65                         return true;
    66                 } else {
    67                         return false;
    68                 } // if
    69         }
     45bool typesCompatible( const Type *, const Type *, const SymTab::Indexer & indexer, const TypeEnvironment & env );
     46bool typesCompatibleIgnoreQualifiers( const Type *, const Type *, const SymTab::Indexer & indexer, const TypeEnvironment & env );
    7047
    71         bool unify(
    72                 const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
    73                 ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    74                 ast::OpenVarSet & open, const ast::SymbolTable & symtab );
     48inline bool typesCompatible( const Type * t1, const Type * t2, const SymTab::Indexer & indexer ) {
     49        TypeEnvironment env;
     50        return typesCompatible( t1, t2, indexer, env );
     51}
    7552
    76         bool unify(
    77                 const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
    78                 ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    79                 ast::OpenVarSet & open, const ast::SymbolTable & symtab, ast::ptr<ast::Type> & common );
     53inline bool typesCompatibleIgnoreQualifiers( const Type * t1, const Type * t2, const SymTab::Indexer & indexer ) {
     54        TypeEnvironment env;
     55        return typesCompatibleIgnoreQualifiers( t1, t2, indexer, env );
     56}
    8057
    81         bool unifyExact(
    82                 const ast::Type * type1, const ast::Type * type2, ast::TypeEnvironment & env,
    83                 ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open,
    84                 WidenMode widen, const ast::SymbolTable & symtab );
     58bool unify(
     59        const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
     60        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
     61        ast::OpenVarSet & open );
    8562
    86         bool unifyInexact(
    87                 const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
    88                 ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    89                 const ast::OpenVarSet & open, WidenMode widen, const ast::SymbolTable & symtab,
    90                 ast::ptr<ast::Type> & common );
     63bool unify(
     64        const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
     65        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
     66        ast::OpenVarSet & open, ast::ptr<ast::Type> & common );
     67
     68bool unifyExact(
     69        const ast::Type * type1, const ast::Type * type2, ast::TypeEnvironment & env,
     70        ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open,
     71        WidenMode widen );
     72
     73bool unifyInexact(
     74        const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
     75        ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
     76        const ast::OpenVarSet & open, WidenMode widen,
     77        ast::ptr<ast::Type> & common );
     78
     79bool typesCompatible(
     80        const ast::Type *, const ast::Type *,
     81        const ast::TypeEnvironment & env = {} );
     82
     83bool typesCompatibleIgnoreQualifiers(
     84        const ast::Type *, const ast::Type *,
     85        const ast::TypeEnvironment & env = {} );
     86
     87/// Creates the type represented by the list of returnVals in a FunctionType.
     88/// The caller owns the return value.
     89Type * extractResultType( FunctionType * functionType );
     90/// Creates or extracts the type represented by returns in a `FunctionType`.
     91ast::ptr<ast::Type> extractResultType( const ast::FunctionType * func );
     92
     93std::vector<ast::ptr<ast::Type>> flattenList(
     94        const std::vector<ast::ptr<ast::Type>> & src, ast::TypeEnvironment & env
     95);
    9196
    9297} // namespace ResolvExpr
  • src/ResolvExpr/WidenMode.h

    r34b4268 r24d6572  
    1919        struct WidenMode {
    2020                WidenMode( bool first, bool second ): first( first ), second( second ) {}
    21                
     21
    2222                WidenMode &operator|=( const WidenMode &other ) {
    2323                        first |= other.first; second |= other.second; return *this;
     
    3535                        WidenMode newWM( *this ); newWM &= other; return newWM;
    3636                }
    37                
     37
    3838                operator bool() { return first && second; }
    3939
  • src/ResolvExpr/module.mk

    r34b4268 r24d6572  
    1717SRC_RESOLVEXPR = \
    1818      ResolvExpr/AdjustExprType.cc \
     19      ResolvExpr/AdjustExprType.hpp \
    1920      ResolvExpr/Alternative.cc \
    2021      ResolvExpr/AlternativeFinder.cc \
     
    2627      ResolvExpr/Candidate.hpp \
    2728      ResolvExpr/CastCost.cc \
     29      ResolvExpr/CastCost.hpp \
    2830      ResolvExpr/CommonType.cc \
     31      ResolvExpr/CommonType.hpp \
    2932      ResolvExpr/ConversionCost.cc \
    3033      ResolvExpr/ConversionCost.h \
     
    4043      ResolvExpr/Occurs.cc \
    4144      ResolvExpr/PolyCost.cc \
     45      ResolvExpr/PolyCost.hpp \
    4246      ResolvExpr/PtrsAssignable.cc \
     47      ResolvExpr/PtrsAssignable.hpp \
    4348      ResolvExpr/PtrsCastable.cc \
     49      ResolvExpr/PtrsCastable.hpp \
    4450      ResolvExpr/RenameVars.cc \
    4551      ResolvExpr/RenameVars.h \
     
    5460      ResolvExpr/SatisfyAssertions.hpp \
    5561      ResolvExpr/SpecCost.cc \
     62      ResolvExpr/SpecCost.hpp \
    5663      ResolvExpr/TypeEnvironment.cc \
    5764      ResolvExpr/TypeEnvironment.h \
  • src/ResolvExpr/typeops.h

    r34b4268 r24d6572  
    1010// Created On       : Sun May 17 07:28:22 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Oct  1 09:45:00 2019
    13 // Update Count     : 6
     12// Last Modified On : Wed Jan 18 11:54:00 2023
     13// Update Count     : 7
    1414//
    1515
     
    1818#include <vector>
    1919
    20 #include "Cost.h"
    21 #include "TypeEnvironment.h"
    22 #include "WidenMode.h"
    23 #include "AST/Fwd.hpp"
    24 #include "AST/Node.hpp"
    25 #include "AST/SymbolTable.hpp"
    2620#include "AST/Type.hpp"
    27 #include "AST/TypeEnvironment.hpp"
    28 #include "SynTree/SynTree.h"
    2921#include "SynTree/Type.h"
    3022
     
    3426
    3527namespace ResolvExpr {
     28        class TypeEnvironment;
     29
    3630        // combos: takes a list of sets and returns a set of lists representing every possible way of forming a list by
    3731        // picking one element out of each set
     
    6155        }
    6256
    63         // in AdjustExprType.cc
    64         /// Replaces array types with the equivalent pointer, and function types with a pointer-to-function
    65         void adjustExprType( Type *& type, const TypeEnvironment & env, const SymTab::Indexer & indexer );
    66 
    67         /// Replaces array types with the equivalent pointer, and function types with a pointer-to-function using empty TypeEnvironment and Indexer
    68         void adjustExprType( Type *& type );
    69 
    70         template< typename ForwardIterator >
    71         void adjustExprTypeList( ForwardIterator begin, ForwardIterator end, const TypeEnvironment & env, const SymTab::Indexer & indexer ) {
    72                 while ( begin != end ) {
    73                         adjustExprType( *begin++, env, indexer );
    74                 } // while
    75         }
    76 
    77         /// Replaces array types with equivalent pointer, and function types with a pointer-to-function
    78         const ast::Type * adjustExprType(
    79                 const ast::Type * type, const ast::TypeEnvironment & env, const ast::SymbolTable & symtab );
    80 
    81         // in CastCost.cc
    82         Cost castCost( const Type * src, const Type * dest, bool srcIsLvalue,
    83                 const SymTab::Indexer & indexer, const TypeEnvironment & env );
    84         Cost castCost(
    85                 const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,
    86                 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env );
    87 
    88         // in ConversionCost.cc
    89         Cost conversionCost( const Type * src, const Type * dest, bool srcIsLvalue,
    90                 const SymTab::Indexer & indexer, const TypeEnvironment & env );
    91         Cost conversionCost(
    92                 const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,
    93                 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env );
    94 
    95         // in AlternativeFinder.cc
    96         Cost computeConversionCost( Type * actualType, Type * formalType, bool actualIsLvalue,
    97                 const SymTab::Indexer & indexer, const TypeEnvironment & env );
    98 
    99         // in PtrsAssignable.cc
    100         int ptrsAssignable( const Type * src, const Type * dest, const TypeEnvironment & env );
    101         int ptrsAssignable( const ast::Type * src, const ast::Type * dst,
    102                 const ast::TypeEnvironment & env );
    103 
    104         // in PtrsCastable.cc
    105         int ptrsCastable( const Type * src, const Type * dest, const TypeEnvironment & env, const SymTab::Indexer & indexer );
    106         int ptrsCastable(
    107                 const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,
    108                 const ast::TypeEnvironment & env );
    109 
    110         // in Unify.cc
    111         bool typesCompatible( const Type *, const Type *, const SymTab::Indexer & indexer, const TypeEnvironment & env );
    112         bool typesCompatibleIgnoreQualifiers( const Type *, const Type *, const SymTab::Indexer & indexer, const TypeEnvironment & env );
    113 
    114         inline bool typesCompatible( const Type * t1, const Type * t2, const SymTab::Indexer & indexer ) {
    115                 TypeEnvironment env;
    116                 return typesCompatible( t1, t2, indexer, env );
    117         }
    118 
    119         inline bool typesCompatibleIgnoreQualifiers( const Type * t1, const Type * t2, const SymTab::Indexer & indexer ) {
    120                 TypeEnvironment env;
    121                 return typesCompatibleIgnoreQualifiers( t1, t2, indexer, env );
    122         }
    123 
    124         bool typesCompatible(
    125                 const ast::Type *, const ast::Type *, const ast::SymbolTable & symtab = {},
    126                 const ast::TypeEnvironment & env = {} );
    127 
    128         bool typesCompatibleIgnoreQualifiers(
    129                 const ast::Type *, const ast::Type *, const ast::SymbolTable &,
    130                 const ast::TypeEnvironment & env = {} );
    131 
    132         /// creates the type represented by the list of returnVals in a FunctionType. The caller owns the return value.
    133         Type * extractResultType( FunctionType * functionType );
    134         /// Creates or extracts the type represented by the list of returns in a `FunctionType`.
    135         ast::ptr<ast::Type> extractResultType( const ast::FunctionType * func );
    136 
    137         // in CommonType.cc
    138         Type * commonType( Type * type1, Type * type2, bool widenFirst, bool widenSecond, const SymTab::Indexer & indexer, TypeEnvironment & env, const OpenVarSet & openVars );
    139         ast::ptr< ast::Type > commonType(
    140                 const ast::ptr< ast::Type > & type1, const ast::ptr< ast::Type > & type2,
    141                         ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    142                         const ast::OpenVarSet & open, WidenMode widen, const ast::SymbolTable & symtab
    143         );
    144         // in Unify.cc
    145         std::vector< ast::ptr< ast::Type > > flattenList(
    146                 const std::vector< ast::ptr< ast::Type > > & src, ast::TypeEnvironment & env
    147         );
    148 
    149         // in PolyCost.cc
    150         int polyCost( Type * type, const TypeEnvironment & env, const SymTab::Indexer & indexer );
    151         int polyCost(
    152                 const ast::Type * type, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env );
    153 
    154         // in SpecCost.cc
    155         int specCost( Type * type );
    156         int specCost( const ast::Type * type );
    157 
    15857        // in Occurs.cc
    15958        bool occurs( const Type * type, const std::string & varName, const TypeEnvironment & env );
     
    16867                return false;
    16968        }
    170 
    171         // in AlternativeFinder.cc
    172         void referenceToRvalueConversion( Expression *& expr, Cost & cost );
    173         // in CandidateFinder.cpp
    174         const ast::Expr * referenceToRvalueConversion( const ast::Expr * expr, Cost & cost );
    17569
    17670        /// flatten tuple type into list of types
     
    218112                }
    219113
    220 
    221114                return new ast::TupleType{ std::move(types) };
    222115        }
     
    227120                return tupleFromTypes( tys.begin(), tys.end() );
    228121        }
    229 
    230        
    231122
    232123        // in TypeEnvironment.cc
Note: See TracChangeset for help on using the changeset viewer.