Changeset 51ff278


Ignore:
Timestamp:
May 21, 2019, 2:28:00 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
e0016a5
Parents:
17a0228a (diff), 19e567dd (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/AST
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r17a0228a r51ff278  
    412412        }
    413413
     414        TypeSubstitution * convertTypeSubstitution(const ast::TypeSubstitution * src) {
     415
     416                TypeSubstitution *rslt = new TypeSubstitution();
     417
     418                for (decltype(src->begin()) src_i = src->begin(); src_i != src->end(); src_i++) {
     419                        rslt->add( src_i->first,
     420                                   get<Type>().accept1(src_i->second) );
     421                }
     422
     423                for (decltype(src->beginVar()) src_i = src->beginVar(); src_i != src->endVar(); src_i++) {
     424                        rslt->addVar( src_i->first,
     425                                      get<Expression>().accept1(src_i->second) );
     426                }
     427
     428                return rslt;
     429        }
     430
     431        void convertInferUnion(std::map<UniqueId,ParamEntry> &tgtInferParams,
     432                                                   std::vector<UniqueId>         &tgtResnSlots,
     433                                                   const ast::Expr::InferUnion   &srcInferred ) {
     434
     435                assert( tgtInferParams.empty() );
     436                assert( tgtResnSlots.empty() );
     437
     438                if ( srcInferred.mode == ast::Expr::InferUnion::Params ) {
     439                        const ast::InferredParams &srcParams = srcInferred.inferParamsConst();
     440                        for (auto srcParam : srcParams) {
     441                                tgtInferParams[srcParam.first] = ParamEntry(
     442                                        srcParam.second.decl,
     443                                        get<Type>().accept1(srcParam.second.actualType),
     444                                        get<Type>().accept1(srcParam.second.formalType),
     445                                        get<Expression>().accept1(srcParam.second.expr)
     446                                );
     447                        }
     448                } else if ( srcInferred.mode == ast::Expr::InferUnion::Slots  ) {
     449                        const ast::ResnSlots &srcSlots = srcInferred.resnSlotsConst();
     450                        for (auto srcSlot : srcSlots) {
     451                                tgtResnSlots.push_back(srcSlot);
     452                        }
     453                }
     454        }
     455
     456        Expression * visitBaseExpr(const ast::Expr * src, Expression * tgt) {
     457
     458                tgt->location = src->location;
     459
     460                tgt->result = get<Type>().accept1(src->result);
     461                tgt->env    = convertTypeSubstitution(src->env);
     462
     463                tgt->extension = src->extension;
     464                convertInferUnion(tgt->inferParams, tgt->resnSlots, src->inferred);
     465
     466                return tgt;
     467        }
     468
    414469        const ast::Expr * visit( const ast::ApplicationExpr * node ) override final {
    415                 (void)node;
     470                auto expr = visitBaseExpr( node,
     471                        new ApplicationExpr(
     472                                get<Expression>().accept1(node->func),
     473                                get<Expression>().acceptL(node->args)
     474                        )
     475                );
     476                this->node = expr;
    416477                return nullptr;
    417478        }
    418479
    419480        const ast::Expr * visit( const ast::UntypedExpr * node ) override final {
    420                 (void)node;
     481                auto expr = visitBaseExpr( node,
     482                        new UntypedExpr(
     483                                get<Expression>().accept1(node->func),
     484                                get<Expression>().acceptL(node->args)
     485                        )
     486                );
     487                this->node = expr;
    421488                return nullptr;
    422489        }
    423490
    424491        const ast::Expr * visit( const ast::NameExpr * node ) override final {
    425                 (void)node;
     492                auto expr = visitBaseExpr( node,
     493                        new NameExpr(
     494                                node->name
     495                        )
     496                );
     497                this->node = expr;
    426498                return nullptr;
    427499        }
     
    11841256                                      getAccept1<ast::Expr>(old_i->second) );
    11851257                }
    1186         }
    1187 
    1188         void convertInferUnion(ast::Expr::InferUnion &nwInferred, InferredParams oldInferParams, const std::vector<UniqueId> &oldResnSlots) {
    1189                
    1190                 (void) nwInferred;
    1191                 (void) oldInferParams;
    1192                 (void) oldResnSlots;
    1193                
    1194                 // TODO
     1258
     1259                return rslt;
     1260        }
     1261
     1262        void convertInferUnion(ast::Expr::InferUnion               &newInferred,
     1263                                                   const std::map<UniqueId,ParamEntry> &oldInferParams,
     1264                                                   const std::vector<UniqueId>         &oldResnSlots) {
     1265
     1266                assert( oldInferParams.empty() || oldResnSlots.empty() );
     1267                assert( newInferred.mode == ast::Expr::InferUnion::Empty );
     1268
     1269                if ( !oldInferParams.empty() ) {
     1270                        ast::InferredParams &tgt = newInferred.inferParams();
     1271                        for (auto old : oldInferParams) {
     1272                                tgt[old.first] = ast::ParamEntry(
     1273                                        old.second.decl,
     1274                                        getAccept1<ast::Type>(old.second.actualType),
     1275                                        getAccept1<ast::Type>(old.second.formalType),
     1276                                        getAccept1<ast::Expr>(old.second.expr)
     1277                                );
     1278                        }
     1279                } else if ( !oldResnSlots.empty() ) {
     1280                        ast::ResnSlots &tgt = newInferred.resnSlots();
     1281                        for (auto old : oldResnSlots) {
     1282                                tgt.push_back(old);
     1283                        }
     1284                }
    11951285        }
    11961286
     
    12061296        }
    12071297
    1208         virtual void visit( ApplicationExpr * ) override final {
    1209                 // TODO
    1210         }
    1211 
    1212         virtual void visit( UntypedExpr * ) override final {
    1213                 // TODO
     1298        virtual void visit( ApplicationExpr * old ) override final {
     1299                this->node = visitBaseExpr( old,
     1300                        new ast::ApplicationExpr(
     1301                                old->location,
     1302                                GET_ACCEPT_1(function, Expr),
     1303                                GET_ACCEPT_V(args, Expr)
     1304                        )
     1305                );
     1306        }
     1307
     1308        virtual void visit( UntypedExpr * old ) override final {
     1309                this->node = visitBaseExpr( old,
     1310                        new ast::UntypedExpr(
     1311                                old->location,
     1312                                GET_ACCEPT_1(function, Expr),
     1313                                GET_ACCEPT_V(args, Expr)
     1314                        )
     1315                );
    12141316        }
    12151317
     
    12231325        }
    12241326
    1225         virtual void visit( CastExpr * ) override final {
    1226                 // TODO ... (rest)
     1327        virtual void visit( CastExpr * old ) override final {
     1328                this->node = visitBaseExpr( old,
     1329                        new ast::CastExpr(
     1330                                old->location,
     1331                                nullptr, // cast's "to" type is expr's result type; converted in visitBaseExpr
     1332                                old->isGenerated ? ast::GeneratedCast : ast::ExplicitCast
     1333                        )
     1334                );
    12271335        }
    12281336
  • src/AST/Expr.hpp

    r17a0228a r51ff278  
    106106                        case Params: assert(!"Cannot return to resnSlots from Params");
    107107                        }
     108                        return *((ResnSlots*)nullptr);
     109                }
     110
     111                const ResnSlots& resnSlotsConst() const {
     112                        if (mode == Slots) {
     113                                return data.resnSlots;
     114                        }
     115                        assert(!"Mode was not already resnSlots");
     116                        return *((ResnSlots*)nullptr);
    108117                }
    109118
     
    114123                        case Params: return data.inferParams;
    115124                        }
     125                        return *((InferredParams*)nullptr);
     126                }
     127
     128                const InferredParams& inferParamsConst() const {
     129                        if (mode == Params) {
     130                                return data.inferParams;
     131                        }
     132                        assert(!"Mode was not already Params");
     133                        return *((InferredParams*)nullptr);
    116134                }
    117135        };
Note: See TracChangeset for help on using the changeset viewer.