Changeset 25a1cb0 for src/ResolvExpr


Ignore:
Timestamp:
Sep 1, 2020, 1:18:10 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
86c1f1c3, a77496cb
Parents:
8d8ac3b (diff), d3aa64f1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

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

Location:
src/ResolvExpr
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    r8d8ac3b r25a1cb0  
    10891089                }
    10901090
     1091                void postvisit( const ast::KeywordCastExpr * castExpr ) {
     1092                        const auto & loc = castExpr->location;
     1093                        assertf( castExpr->result, "Cast target should have been set in Validate." );
     1094                        auto ref = castExpr->result.strict_as<ast::ReferenceType>();
     1095                        auto inst = ref->base.strict_as<ast::StructInstType>();
     1096                        auto target = inst->base.get();
     1097
     1098                        CandidateFinder finder{ symtab, tenv };
     1099
     1100                        auto pick_alternatives = [target, this](CandidateList & found, bool expect_ref) {
     1101                                for(auto & cand : found) {
     1102                                        const ast::Type * expr = cand->expr->result.get();
     1103                                        if(expect_ref) {
     1104                                                auto res = dynamic_cast<const ast::ReferenceType*>(expr);
     1105                                                if(!res) { continue; }
     1106                                                expr = res->base.get();
     1107                                        }
     1108
     1109                                        if(auto insttype = dynamic_cast<const ast::TypeInstType*>(expr)) {
     1110                                                auto td = cand->env.lookup(insttype->name);
     1111                                                if(!td) { continue; }
     1112                                                expr = td->bound.get();
     1113                                        }
     1114
     1115                                        if(auto base = dynamic_cast<const ast::StructInstType*>(expr)) {
     1116                                                if(base->base == target) {
     1117                                                        candidates.push_back( std::move(cand) );
     1118                                                        reason.code = NoReason;
     1119                                                }
     1120                                        }
     1121                                }
     1122                        };
     1123
     1124                        try {
     1125                                // Attempt 1 : turn (thread&)X into ($thread&)X.__thrd
     1126                                // Clone is purely for memory management
     1127                                std::unique_ptr<const ast::Expr> tech1 { new ast::UntypedMemberExpr(loc, new ast::NameExpr(loc, castExpr->concrete_target.field), castExpr->arg) };
     1128
     1129                                // don't prune here, since it's guaranteed all alternatives will have the same type
     1130                                finder.find( tech1.get(), ResolvMode::withoutPrune() );
     1131                                pick_alternatives(finder.candidates, false);
     1132
     1133                                return;
     1134                        } catch(SemanticErrorException & ) {}
     1135
     1136                        // Fallback : turn (thread&)X into ($thread&)get_thread(X)
     1137                        std::unique_ptr<const ast::Expr> fallback { ast::UntypedExpr::createDeref(loc,  new ast::UntypedExpr(loc, new ast::NameExpr(loc, castExpr->concrete_target.getter), { castExpr->arg })) };
     1138                        // don't prune here, since it's guaranteed all alternatives will have the same type
     1139                        finder.find( fallback.get(), ResolvMode::withoutPrune() );
     1140
     1141                        pick_alternatives(finder.candidates, true);
     1142
     1143                        // Whatever happens here, we have no more fallbacks
     1144                }
     1145
    10911146                void postvisit( const ast::UntypedMemberExpr * memberExpr ) {
    10921147                        CandidateFinder aggFinder{ symtab, tenv };
  • src/ResolvExpr/Unify.cc

    r8d8ac3b r25a1cb0  
    767767                /// If this isn't done when satifying ttype assertions, then argument lists can have
    768768                /// different size and structure when they should be compatible.
    769                 struct TtypeExpander_new : public ast::WithShortCircuiting {
     769                struct TtypeExpander_new : public ast::WithShortCircuiting, public ast::PureVisitor {
    770770                        ast::TypeEnvironment & tenv;
    771771
     
    793793                                // TtypeExpander pass is impure (may mutate nodes in place)
    794794                                // need to make nodes shared to prevent accidental mutation
    795                                 ast::ptr<ast::DeclWithType> dc = d;
    796                                 dc = dc->accept( expander );
     795                                ast::ptr<ast::DeclWithType> dc = d->accept(expander);
    797796                                auto types = flatten( dc->get_type() );
    798797                                for ( ast::ptr< ast::Type > & t : types ) {
     
    11141113                        ast::Pass<TtypeExpander_new> expander{ tenv };
    11151114
    1116                         ast::ptr<ast::TupleType> tuplec = tuple;
    1117                         ast::ptr<ast::TupleType> tuple2c = tuple2;
    1118                         const ast::Type * flat = tuplec->accept( expander );
    1119                         const ast::Type * flat2 = tuple2c->accept( expander );
     1115                        // ast::ptr<ast::TupleType> tuplec = tuple;
     1116                        // ast::ptr<ast::TupleType> tuple2c = tuple2;
     1117                        const ast::Type * flat = tuple->accept( expander );
     1118                        const ast::Type * flat2 = tuple2->accept( expander );
    11201119
    11211120                        auto types = flatten( flat );
  • src/ResolvExpr/module.mk

    r8d8ac3b r25a1cb0  
    1919      ResolvExpr/Alternative.cc \
    2020      ResolvExpr/AlternativeFinder.cc \
     21      ResolvExpr/AlternativeFinder.h \
     22      ResolvExpr/Alternative.h \
    2123      ResolvExpr/Candidate.cpp \
    2224      ResolvExpr/CandidateFinder.cpp \
     25      ResolvExpr/CandidateFinder.hpp \
     26      ResolvExpr/Candidate.hpp \
    2327      ResolvExpr/CastCost.cc \
    2428      ResolvExpr/CommonType.cc \
    2529      ResolvExpr/ConversionCost.cc \
     30      ResolvExpr/ConversionCost.h \
     31      ResolvExpr/Cost.h \
    2632      ResolvExpr/CurrentObject.cc \
     33      ResolvExpr/CurrentObject.h \
    2734      ResolvExpr/ExplodedActual.cc \
     35      ResolvExpr/ExplodedActual.h \
    2836      ResolvExpr/ExplodedArg.cpp \
     37      ResolvExpr/ExplodedArg.hpp \
    2938      ResolvExpr/FindOpenVars.cc \
     39      ResolvExpr/FindOpenVars.h \
    3040      ResolvExpr/Occurs.cc \
    3141      ResolvExpr/PolyCost.cc \
     
    3343      ResolvExpr/PtrsCastable.cc \
    3444      ResolvExpr/RenameVars.cc \
     45      ResolvExpr/RenameVars.h \
    3546      ResolvExpr/ResolveAssertions.cc \
     47      ResolvExpr/ResolveAssertions.h \
    3648      ResolvExpr/Resolver.cc \
     49      ResolvExpr/Resolver.h \
    3750      ResolvExpr/ResolveTypeof.cc \
     51      ResolvExpr/ResolveTypeof.h \
     52      ResolvExpr/ResolvMode.h \
    3853      ResolvExpr/SatisfyAssertions.cpp \
     54      ResolvExpr/SatisfyAssertions.hpp \
    3955      ResolvExpr/SpecCost.cc \
    4056      ResolvExpr/TypeEnvironment.cc \
    41       ResolvExpr/Unify.cc
     57      ResolvExpr/TypeEnvironment.h \
     58      ResolvExpr/typeops.h \
     59      ResolvExpr/Unify.cc \
     60      ResolvExpr/Unify.h \
     61      ResolvExpr/WidenMode.h
    4262
    43 SRC += $(SRC_RESOLVEXPR) ResolvExpr/AlternativePrinter.cc
     63
     64SRC += $(SRC_RESOLVEXPR) ResolvExpr/AlternativePrinter.cc ResolvExpr/AlternativePrinter.h
    4465SRCDEMANGLE += $(SRC_RESOLVEXPR)
Note: See TracChangeset for help on using the changeset viewer.