Changeset 3bc69f2


Ignore:
Timestamp:
Mar 18, 2022, 10:53:38 AM (2 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
22226e4
Parents:
f7496c5
Message:

May have fixed the build failure, but I'm still not sure why WaitForStmt? seemed to trigger it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Resolver.cc

    rf7496c5 r3bc69f2  
    1010// Created On       : Sun May 17 12:17:01 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Mar 16 16:07:00 2022
    13 // Update Count     : 246
     12// Last Modified On : Fri Mar 18 10:41:00 2022
     13// Update Count     : 247
    1414//
    1515
     
    12451245        : public ast::WithSymbolTable, public ast::WithGuards,
    12461246          public ast::WithVisitorRef<Resolver_new>, public ast::WithShortCircuiting,
    1247           public ast::WithStmtsToAdd<>, public ast::WithConstTranslationUnit {
     1247          public ast::WithStmtsToAdd<> {
    12481248
    12491249                ast::ptr< ast::Type > functionReturn = nullptr;
     
    12511251                // for work previously in GenInit
    12521252                static InitTweak::ManagedTypes_new managedTypes;
     1253                ResolveContext context;
    12531254
    12541255                bool inEnumDecl = false;
    1255 
    1256                 ResolveContext getContext() const {
    1257                         return ResolveContext{ symtab, transUnit().global };
    1258                 }
    12591256
    12601257        public:
    12611258                static size_t traceId;
    1262                 Resolver_new() = default;
    1263                 Resolver_new( const ast::SymbolTable & syms ) { symtab = syms; }
     1259                Resolver_new( const ast::TranslationGlobal & global ) :
     1260                        context{ symtab, global } {}
     1261                Resolver_new( const ResolveContext & context ) :
     1262                        ast::WithSymbolTable{ context.symtab },
     1263                        context{ symtab, context.global } {}
    12641264
    12651265                const ast::FunctionDecl * previsit( const ast::FunctionDecl * );
     
    12781278                const ast::AsmStmt *         previsit( const ast::AsmStmt * );
    12791279                const ast::IfStmt *          previsit( const ast::IfStmt * );
    1280                 const ast::WhileDoStmt *       previsit( const ast::WhileDoStmt * );
     1280                const ast::WhileDoStmt *     previsit( const ast::WhileDoStmt * );
    12811281                const ast::ForStmt *         previsit( const ast::ForStmt * );
    12821282                const ast::SwitchStmt *      previsit( const ast::SwitchStmt * );
     
    13051305
    13061306        void resolve( ast::TranslationUnit& translationUnit ) {
    1307                 ast::Pass< Resolver_new >::run( translationUnit );
     1307                ast::Pass< Resolver_new >::run( translationUnit, translationUnit.global );
    13081308        }
    13091309
     
    13121312        ) {
    13131313                assert( ctorInit );
    1314                 ast::Pass< Resolver_new > resolver{ context.symtab };
    1315                 ast::TranslationUnit transUnit;
    1316                 transUnit.global = context.global;
    1317                 resolver.core.translationUnit = &transUnit;
     1314                ast::Pass< Resolver_new > resolver( context );
    13181315                return ctorInit->accept( resolver );
    13191316        }
     
    13231320        ) {
    13241321                assert( stmtExpr );
    1325                 ast::Pass< Resolver_new > resolver{ context.symtab };
    1326                 ast::TranslationUnit transUnit;
    1327                 transUnit.global = context.global;
    1328                 resolver.core.translationUnit = &transUnit;
     1322                ast::Pass< Resolver_new > resolver( context );
    13291323                auto ret = mutate(stmtExpr->accept(resolver));
    13301324                strict_dynamic_cast< ast::StmtExpr * >( ret )->computeResult();
     
    13811375
    13821376                        for (auto & attr: mutDecl->attributes) {
    1383                                 attr = handleAttribute(mutDecl->location, attr, getContext() );
     1377                                attr = handleAttribute(mutDecl->location, attr, context );
    13841378                        }
    13851379
     
    13941388                        }
    13951389                        for (auto & asst : mutDecl->assertions) {
    1396                                 asst = fixObjectType(asst.strict_as<ast::ObjectDecl>(), getContext());
     1390                                asst = fixObjectType(asst.strict_as<ast::ObjectDecl>(), context);
    13971391                                symtab.addId(asst);
    13981392                                mutType->assertions.emplace_back(new ast::VariableExpr(functionDecl->location, asst));
     
    14061400
    14071401                        for (auto & param : mutDecl->params) {
    1408                                 param = fixObjectType(param.strict_as<ast::ObjectDecl>(), getContext());
     1402                                param = fixObjectType(param.strict_as<ast::ObjectDecl>(), context);
    14091403                                symtab.addId(param);
    14101404                                paramTypes.emplace_back(param->get_type());
    14111405                        }
    14121406                        for (auto & ret : mutDecl->returns) {
    1413                                 ret = fixObjectType(ret.strict_as<ast::ObjectDecl>(), getContext());
     1407                                ret = fixObjectType(ret.strict_as<ast::ObjectDecl>(), context);
    14141408                                returnTypes.emplace_back(ret->get_type());
    14151409                        }
     
    14821476                        // enumerator initializers should not use the enum type to initialize, since the
    14831477                        // enum type is still incomplete at this point. Use `int` instead.
    1484                         objectDecl = fixObjectType(objectDecl, getContext());
     1478                        objectDecl = fixObjectType(objectDecl, context);
    14851479                        currentObject = ast::CurrentObject{
    14861480                                objectDecl->location, new ast::BasicType{ ast::BasicType::SignedInt } };
     
    14881482                else {
    14891483                        if (!objectDecl->isTypeFixed) {
    1490                                 auto newDecl = fixObjectType(objectDecl, getContext());
     1484                                auto newDecl = fixObjectType(objectDecl, context);
    14911485                                auto mutDecl = mutate(newDecl);
    14921486
     
    15191513                        // nested type decls are hoisted already. no need to do anything
    15201514                        if (auto obj = member.as<ast::ObjectDecl>()) {
    1521                                 member = fixObjectType(obj, getContext());
     1515                                member = fixObjectType(obj, context);
    15221516                        }
    15231517                }
     
    15421536                return ast::mutate_field(
    15431537                        assertDecl, &ast::StaticAssertDecl::cond,
    1544                         findIntegralExpression( assertDecl->cond, getContext() ) );
     1538                        findIntegralExpression( assertDecl->cond, context ) );
    15451539        }
    15461540
     
    15571551
    15581552        const ast::ArrayType * Resolver_new::previsit( const ast::ArrayType * at ) {
    1559                 return handlePtrType( at, getContext() );
     1553                return handlePtrType( at, context );
    15601554        }
    15611555
    15621556        const ast::PointerType * Resolver_new::previsit( const ast::PointerType * pt ) {
    1563                 return handlePtrType( pt, getContext() );
     1557                return handlePtrType( pt, context );
    15641558        }
    15651559
     
    15691563
    15701564                return ast::mutate_field(
    1571                         exprStmt, &ast::ExprStmt::expr, findVoidExpression( exprStmt->expr, getContext() ) );
     1565                        exprStmt, &ast::ExprStmt::expr, findVoidExpression( exprStmt->expr, context ) );
    15721566        }
    15731567
     
    15761570
    15771571                asmExpr = ast::mutate_field(
    1578                         asmExpr, &ast::AsmExpr::operand, findVoidExpression( asmExpr->operand, getContext() ) );
     1572                        asmExpr, &ast::AsmExpr::operand, findVoidExpression( asmExpr->operand, context ) );
    15791573
    15801574                return asmExpr;
     
    15901584        const ast::IfStmt * Resolver_new::previsit( const ast::IfStmt * ifStmt ) {
    15911585                return ast::mutate_field(
    1592                         ifStmt, &ast::IfStmt::cond, findIntegralExpression( ifStmt->cond, getContext() ) );
     1586                        ifStmt, &ast::IfStmt::cond, findIntegralExpression( ifStmt->cond, context ) );
    15931587        }
    15941588
    15951589        const ast::WhileDoStmt * Resolver_new::previsit( const ast::WhileDoStmt * whileDoStmt ) {
    15961590                return ast::mutate_field(
    1597                         whileDoStmt, &ast::WhileDoStmt::cond, findIntegralExpression( whileDoStmt->cond, getContext() ) );
     1591                        whileDoStmt, &ast::WhileDoStmt::cond, findIntegralExpression( whileDoStmt->cond, context ) );
    15981592        }
    15991593
     
    16011595                if ( forStmt->cond ) {
    16021596                        forStmt = ast::mutate_field(
    1603                                 forStmt, &ast::ForStmt::cond, findIntegralExpression( forStmt->cond, getContext() ) );
     1597                                forStmt, &ast::ForStmt::cond, findIntegralExpression( forStmt->cond, context ) );
    16041598                }
    16051599
    16061600                if ( forStmt->inc ) {
    16071601                        forStmt = ast::mutate_field(
    1608                                 forStmt, &ast::ForStmt::inc, findVoidExpression( forStmt->inc, getContext() ) );
     1602                                forStmt, &ast::ForStmt::inc, findVoidExpression( forStmt->inc, context ) );
    16091603                }
    16101604
     
    16161610                switchStmt = ast::mutate_field(
    16171611                        switchStmt, &ast::SwitchStmt::cond,
    1618                         findIntegralExpression( switchStmt->cond, getContext() ) );
     1612                        findIntegralExpression( switchStmt->cond, context ) );
    16191613                currentObject = ast::CurrentObject{ switchStmt->location, switchStmt->cond->result };
    16201614                return switchStmt;
     
    16291623                        ast::ptr< ast::Expr > untyped =
    16301624                                new ast::CastExpr{ caseStmt->location, caseStmt->cond, initAlts.front().type };
    1631                         ast::ptr< ast::Expr > newExpr = findSingleExpression( untyped, getContext() );
     1625                        ast::ptr< ast::Expr > newExpr = findSingleExpression( untyped, context );
    16321626
    16331627                        // case condition cannot have a cast in C, so it must be removed here, regardless of
     
    16501644                        branchStmt = ast::mutate_field(
    16511645                                branchStmt, &ast::BranchStmt::computedTarget,
    1652                                 findSingleExpression( branchStmt->computedTarget, target, getContext() ) );
     1646                                findSingleExpression( branchStmt->computedTarget, target, context ) );
    16531647                }
    16541648                return branchStmt;
     
    16601654                        returnStmt = ast::mutate_field(
    16611655                                returnStmt, &ast::ReturnStmt::expr,
    1662                                 findSingleExpression( returnStmt->expr, functionReturn, getContext() ) );
     1656                                findSingleExpression( returnStmt->expr, functionReturn, context ) );
    16631657                }
    16641658                return returnStmt;
     
    16751669                        throwStmt = ast::mutate_field(
    16761670                                throwStmt, &ast::ThrowStmt::expr,
    1677                                 findSingleExpression( throwStmt->expr, exceptType, getContext() ) );
     1671                                findSingleExpression( throwStmt->expr, exceptType, context ) );
    16781672                }
    16791673                return throwStmt;
     
    17191713
    17201714                        ast::TypeEnvironment env;
    1721                         CandidateFinder funcFinder( getContext(), env );
     1715                        CandidateFinder funcFinder( context, env );
    17221716
    17231717                        // Find all candidates for a function in canonical form
     
    19331927                                );
    19341928
    1935                                 clause2.target.args.emplace_back( findSingleExpression( init, getContext() ) );
     1929                                clause2.target.args.emplace_back( findSingleExpression( init, context ) );
    19361930                        }
    19371931
    19381932                        // Resolve the conditions as if it were an IfStmt, statements normally
    1939                         clause2.cond = findSingleExpression( clause.cond, getContext() );
     1933                        clause2.cond = findSingleExpression( clause.cond, context );
    19401934                        clause2.stmt = clause.stmt->accept( *visitor );
    19411935
     
    19521946                        ast::ptr< ast::Type > target =
    19531947                                new ast::BasicType{ ast::BasicType::LongLongUnsignedInt };
    1954                         timeout2.time = findSingleExpression( stmt->timeout.time, target, getContext() );
    1955                         timeout2.cond = findSingleExpression( stmt->timeout.cond, getContext() );
     1948                        timeout2.time = findSingleExpression( stmt->timeout.time, target, context );
     1949                        timeout2.cond = findSingleExpression( stmt->timeout.cond, context );
    19561950                        timeout2.stmt = stmt->timeout.stmt->accept( *visitor );
    19571951
     
    19661960                        ast::WaitForStmt::OrElse orElse2;
    19671961
    1968                         orElse2.cond = findSingleExpression( stmt->orElse.cond, getContext() );
     1962                        orElse2.cond = findSingleExpression( stmt->orElse.cond, context );
    19691963                        orElse2.stmt = stmt->orElse.stmt->accept( *visitor );
    19701964
     
    19871981                for (auto & expr : exprs) {
    19881982                        // only struct- and union-typed expressions are viable candidates
    1989                         expr = findKindExpression( expr, getContext(), structOrUnion, "with expression" );
     1983                        expr = findKindExpression( expr, context, structOrUnion, "with expression" );
    19901984
    19911985                        // if with expression might be impure, create a temporary so that it is evaluated once
     
    20132007                ast::ptr< ast::Expr > untyped = new ast::UntypedInitExpr{
    20142008                        singleInit->location, singleInit->value, currentObject.getOptions() };
    2015                 ast::ptr<ast::Expr> newExpr = findSingleExpression( untyped, getContext() );
     2009                ast::ptr<ast::Expr> newExpr = findSingleExpression( untyped, context );
    20162010                const ast::InitExpr * initExpr = newExpr.strict_as< ast::InitExpr >();
    20172011
Note: See TracChangeset for help on using the changeset viewer.