Changeset e5c3811 for src/ResolvExpr
- Timestamp:
- Nov 25, 2020, 3:12:17 AM (3 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 4702a2c
- Parents:
- 7192145
- Location:
- src/ResolvExpr
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CandidateFinder.cpp
r7192145 re5c3811 43 43 #include "SymTab/Validate.h" // for validateType 44 44 #include "Tuples/Tuples.h" // for handleTupleAssignment 45 #include "InitTweak/InitTweak.h" // for getPointerBase 46 47 #include "Common/Stats/Counter.h" 45 48 46 49 #define PRINT( text ) if ( resolvep ) { text } … … 864 867 865 868 void postvisit( const ast::UntypedExpr * untypedExpr ) { 866 CandidateFinder funcFinder{ symtab, tenv };867 funcFinder.find( untypedExpr->func, ResolvMode::withAdjustment() );868 // short-circuit if no candidates869 if ( funcFinder.candidates.empty() ) return;870 871 reason.code = NoMatch;872 873 869 std::vector< CandidateFinder > argCandidates = 874 870 selfFinder.findSubExprs( untypedExpr->args ); … … 877 873 // if not tuple assignment, handled as normal function call 878 874 Tuples::handleTupleAssignment( selfFinder, untypedExpr, argCandidates ); 875 876 CandidateFinder funcFinder{ symtab, tenv }; 877 if (auto nameExpr = untypedExpr->func.as<ast::NameExpr>()) { 878 auto kind = ast::SymbolTable::getSpecialFunctionKind(nameExpr->name); 879 if (kind != ast::SymbolTable::SpecialFunctionKind::NUMBER_OF_KINDS) { 880 assertf(!argCandidates.empty(), "special function call without argument"); 881 for (auto & firstArgCand: argCandidates[0]) { 882 ast::ptr<ast::Type> argType = firstArgCand->expr->result; 883 firstArgCand->env.apply(argType); 884 // strip references 885 // xxx - is this correct? 886 while (argType.as<ast::ReferenceType>()) argType = argType.as<ast::ReferenceType>()->base; 887 888 // convert 1-tuple to plain type 889 if (auto tuple = argType.as<ast::TupleType>()) { 890 if (tuple->size() == 1) { 891 argType = tuple->types[0]; 892 } 893 } 894 895 // if argType is an unbound type parameter, all special functions need to be searched. 896 if (isUnboundType(argType)) { 897 funcFinder.otypeKeys.clear(); 898 break; 899 } 900 901 if (argType.as<ast::PointerType>()) funcFinder.otypeKeys.insert(Mangle::Encoding::pointer); 902 else funcFinder.otypeKeys.insert(Mangle::mangle(argType, Mangle::NoGenericParams | Mangle::Type)); 903 } 904 } 905 } 906 // if candidates are already produced, do not fail 907 // xxx - is it possible that handleTupleAssignment and main finder both produce candidates? 908 // this means there exists ctor/assign functions with a tuple as first parameter. 909 funcFinder.find( untypedExpr->func, selfFinder.candidates.empty() ? ResolvMode::withAdjustment() : ResolvMode::withoutFailFast() ); 910 // short-circuit if no candidates 911 // if ( funcFinder.candidates.empty() ) return; 912 913 reason.code = NoMatch; 879 914 880 915 // find function operators … … 1187 1222 1188 1223 void postvisit( const ast::NameExpr * nameExpr ) { 1189 std::vector< ast::SymbolTable::IdData > declList = symtab.lookupId( nameExpr->name ); 1224 std::vector< ast::SymbolTable::IdData > declList; 1225 if (!selfFinder.otypeKeys.empty()) { 1226 auto kind = ast::SymbolTable::getSpecialFunctionKind(nameExpr->name); 1227 assertf(kind != ast::SymbolTable::SpecialFunctionKind::NUMBER_OF_KINDS, "special lookup with non-special target: %s", nameExpr->name.c_str()); 1228 1229 for (auto & otypeKey: selfFinder.otypeKeys) { 1230 auto result = symtab.specialLookupId(kind, otypeKey); 1231 declList.insert(declList.end(), std::make_move_iterator(result.begin()), std::make_move_iterator(result.end())); 1232 } 1233 } 1234 else { 1235 declList = symtab.lookupId( nameExpr->name ); 1236 } 1190 1237 PRINT( std::cerr << "nameExpr is " << nameExpr->name << std::endl; ) 1238 1191 1239 if( declList.empty() ) return; 1192 1240 … … 1558 1606 } 1559 1607 } 1608 1560 1609 } 1561 1610 -
src/ResolvExpr/CandidateFinder.hpp
r7192145 re5c3811 31 31 const ast::TypeEnvironment & env; ///< Substitutions performed in this resolution 32 32 ast::ptr< ast::Type > targetType; ///< Target type for resolution 33 std::set< std::string > otypeKeys; /// different type may map to same key 33 34 34 35 CandidateFinder( -
src/ResolvExpr/SatisfyAssertions.cpp
r7192145 re5c3811 167 167 // find candidates that unify with the desired type 168 168 AssnCandidateList matches; 169 for ( const ast::SymbolTable::IdData & cdata : sat.symtab.lookupId( assn.first->name ) ) { 169 170 std::vector<ast::SymbolTable::IdData> candidates; 171 auto kind = ast::SymbolTable::getSpecialFunctionKind(assn.first->name); 172 if (kind != ast::SymbolTable::SpecialFunctionKind::NUMBER_OF_KINDS) { 173 // prefilter special decls by argument type, if already known 174 ast::ptr<ast::Type> thisArgType = strict_dynamic_cast<const ast::PointerType *>(assn.first->get_type())->base 175 .strict_as<ast::FunctionType>()->params[0] 176 .strict_as<ast::ReferenceType>()->base; 177 sat.cand->env.apply(thisArgType); 178 179 std::string otypeKey = ""; 180 if (thisArgType.as<ast::PointerType>()) otypeKey = Mangle::Encoding::pointer; 181 else if (!isUnboundType(thisArgType)) otypeKey = Mangle::mangle(thisArgType, Mangle::Type | Mangle::NoGenericParams); 182 183 candidates = sat.symtab.specialLookupId(kind, otypeKey); 184 } 185 else { 186 candidates = sat.symtab.lookupId(assn.first->name); 187 } 188 for ( const ast::SymbolTable::IdData & cdata : candidates ) { 170 189 const ast::DeclWithType * candidate = cdata.id; 171 190
Note: See TracChangeset
for help on using the changeset viewer.