Ignore:
Timestamp:
Dec 16, 2020, 4:01:57 PM (3 years ago)
Author:
Colby Alexander Parsons <caparsons@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
8ba363e, c8025a21
Parents:
b3c8496 (diff), 3e5dd913 (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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    rb3c8496 r53449a4  
    5555
    5656// these need to be accessed in new FixInit now
    57 ast::Type * sizeType = nullptr;
    58 ast::FunctionDecl * dereferenceOperator = nullptr;
    59 ast::StructDecl   * dtorStruct = nullptr;
    60 ast::FunctionDecl * dtorStructDestroy = nullptr;
     57ast::ptr<ast::Type> sizeType = nullptr;
     58const ast::FunctionDecl * dereferenceOperator = nullptr;
     59const ast::StructDecl   * dtorStruct = nullptr;
     60const ast::FunctionDecl * dtorStructDestroy = nullptr;
    6161
    6262}
     
    205205                ftype->parameters = get<DeclarationWithType>().acceptL(node->params);
    206206
    207                 ftype->forall = get<TypeDecl>().acceptL( node->type->forall );
     207                ftype->forall = get<TypeDecl>().acceptL( node->type_params );
     208                if (!node->assertions.empty()) {
     209                        assert(!ftype->forall.empty());
     210                        // find somewhere to place assertions back, for convenience it is the last slot
     211                        ftype->forall.back()->assertions = get<DeclarationWithType>().acceptL(node->assertions);
     212                }
    208213
    209214                visitType(node->type, ftype);
     
    233238        const ast::Decl * namedTypePostamble( NamedTypeDecl * decl, const ast::NamedTypeDecl * node ) {
    234239                // base comes from constructor
    235                 decl->parameters = get<TypeDecl>().acceptL( node->params );
    236240                decl->assertions = get<DeclarationWithType>().acceptL( node->assertions );
    237241                declPostamble( decl, node );
     
    603607
    604608                for (decltype(src->begin()) src_i = src->begin(); src_i != src->end(); src_i++) {
    605                         rslt->add( src_i->first,
     609                        rslt->add( src_i->first.typeString(),
    606610                                   get<Type>().accept1(src_i->second) );
    607                 }
    608 
    609                 for (decltype(src->beginVar()) src_i = src->beginVar(); src_i != src->endVar(); src_i++) {
    610                         rslt->addVar( src_i->first,
    611                                       get<Expression>().accept1(src_i->second) );
    612611                }
    613612
     
    12131212                // ty->returnVals = get<DeclarationWithType>().acceptL( node->returns );
    12141213                // ty->parameters = get<DeclarationWithType>().acceptL( node->params );
    1215                 ty->forall = get<TypeDecl>().acceptL( node->forall );
     1214
     1215                auto types = get<TypeInstType>().acceptL( node->forall );
     1216                for (auto t : types) {
     1217                        auto newT = new TypeDecl(*t->baseType);
     1218                        newT->name = t->name; // converted by typeString()
     1219                        for (auto asst : newT->assertions) delete asst;
     1220                        newT->assertions.clear();
     1221                        ty->forall.push_back(newT);
     1222                }
     1223                auto assts = get<VariableExpr>().acceptL( node->assertions );
     1224                if (!assts.empty()) {
     1225                        assert(!types.empty());
     1226                        for (auto asst : assts) {
     1227                                auto newDecl = new ObjectDecl(*strict_dynamic_cast<ObjectDecl*>(asst->var));
     1228                                delete newDecl->type;
     1229                                newDecl->type = asst->result->clone();
     1230                                newDecl->storageClasses.is_extern = true; // hack
     1231                                ty->forall.back()->assertions.push_back(newDecl);
     1232                        }
     1233                }
     1234
    12161235                return visitType( node, ty );
    12171236        }
    12181237
    12191238        const ast::Type * postvisit( const ast::BaseInstType * old, ReferenceToType * ty ) {
    1220                 ty->forall = get<TypeDecl>().acceptL( old->forall );
    12211239                ty->parameters = get<Expression>().acceptL( old->params );
    12221240                ty->hoistType = old->hoistType;
     
    13011319                        ty = new TypeInstType{
    13021320                                cv( node ),
    1303                                 node->name,
     1321                                node->typeString(),
    13041322                                get<TypeDecl>().accept1( node->base ),
    13051323                                get<Attribute>().acceptL( node->attributes )
     
    13081326                        ty = new TypeInstType{
    13091327                                cv( node ),
    1310                                 node->name,
     1328                                node->typeString(),
    13111329                                node->kind == ast::TypeDecl::Ftype,
    13121330                                get<Attribute>().acceptL( node->attributes )
     
    14331451        /// at conversion stage, all created nodes are guaranteed to be unique, therefore
    14341452        /// const_casting out of smart pointers is permitted.
    1435         std::unordered_map< const BaseSyntaxNode *, ast::ptr<ast::Node> > cache = {};
     1453        std::unordered_map< const BaseSyntaxNode *, ast::readonly<ast::Node> > cache = {};
    14361454
    14371455        // Local Utilities:
     
    15671585                // can function type have attributes? seems not to be the case.
    15681586                // visitType(old->type, ftype);
     1587
     1588                // collect assertions and put directly in FunctionDecl
     1589                std::vector<ast::ptr<ast::DeclWithType>> assertions;
     1590                for (auto & param: forall) {
     1591                        for (auto & asst: param->assertions) {
     1592                                assertf(asst->unique(), "newly converted decl must be unique");
     1593                                assertions.emplace_back(asst);
     1594                        }
     1595                        auto mut = param.get_and_mutate();
     1596                        assertf(mut == param, "newly converted decl must be unique");
     1597                        mut->assertions.clear();
     1598                }
    15691599
    15701600                auto decl = new ast::FunctionDecl{
     
    15861616                cache.emplace( old, decl );
    15871617
     1618                decl->assertions = std::move(assertions);
    15881619                decl->withExprs = GET_ACCEPT_V(withExprs, Expr);
    15891620                decl->stmts = GET_ACCEPT_1(statements, CompoundStmt);
     
    17041735                cache.emplace( old, decl );
    17051736                decl->assertions = GET_ACCEPT_V(assertions, DeclWithType);
    1706                 decl->params     = GET_ACCEPT_V(parameters, TypeDecl);
    17071737                decl->extension  = old->extension;
    17081738                decl->uniqueId   = old->uniqueId;
     
    17201750                );
    17211751                decl->assertions = GET_ACCEPT_V(assertions, DeclWithType);
    1722                 decl->params     = GET_ACCEPT_V(parameters, TypeDecl);
    17231752                decl->extension  = old->extension;
    17241753                decl->uniqueId   = old->uniqueId;
     
    20702099        }
    20712100
     2101        // TypeSubstitution shouldn't exist yet in old.
    20722102        ast::TypeSubstitution * convertTypeSubstitution(const TypeSubstitution * old) {
    2073 
     2103               
    20742104                if (!old) return nullptr;
    2075 
     2105                if (old->empty()) return nullptr;
     2106                assert(false);
     2107
     2108                /*
    20762109                ast::TypeSubstitution *rslt = new ast::TypeSubstitution();
    20772110
     
    20812114                }
    20822115
    2083                 for (decltype(old->beginVar()) old_i = old->beginVar(); old_i != old->endVar(); old_i++) {
    2084                         rslt->addVar( old_i->first,
    2085                                       getAccept1<ast::Expr>(old_i->second) );
    2086                 }
    2087 
    20882116                return rslt;
     2117                */
    20892118        }
    20902119
     
    26142643                        ty->params.emplace_back(v->get_type());
    26152644                }
    2616                 ty->forall = GET_ACCEPT_V( forall, TypeDecl );
     2645                // xxx - when will this be non-null?
     2646                // will have to create dangling (no-owner) decls to be pointed to
     2647                auto foralls = GET_ACCEPT_V( forall, TypeDecl );
     2648
     2649                for (auto & param : foralls) {
     2650                        ty->forall.emplace_back(new ast::TypeInstType(param->name, param));
     2651                        for (auto asst : param->assertions) {
     2652                                ty->assertions.emplace_back(new ast::VariableExpr({}, asst));
     2653                        }
     2654                }
    26172655                visitType( old, ty );
    26182656        }
    26192657
    26202658        void postvisit( const ReferenceToType * old, ast::BaseInstType * ty ) {
    2621                 ty->forall = GET_ACCEPT_V( forall, TypeDecl );
    26222659                ty->params = GET_ACCEPT_V( parameters, Expr );
    26232660                ty->hoistType = old->hoistType;
     
    28072844        ConverterOldToNew c;
    28082845        ast::TranslationUnit unit;
     2846        if (Validate::SizeType) {
     2847                // this should be a BasicType.
     2848                auto old = strict_dynamic_cast<BasicType *>(Validate::SizeType);
     2849                ast::sizeType = new ast::BasicType{ (ast::BasicType::Kind)(unsigned)old->kind };
     2850        }
     2851
    28092852        for(auto d : translationUnit) {
    28102853                d->accept( c );
Note: See TracChangeset for help on using the changeset viewer.