Changeset b78c54f for src


Ignore:
Timestamp:
Apr 12, 2024, 7:49:21 AM (18 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
3e1cd17, 90320ac
Parents:
feb999f (diff), ab780e6 (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
Files:
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Pass.proto.hpp

    rfeb999f rb78c54f  
    226226                // Now the original containers should still have the unchanged values
    227227                // but also contain the new values.
    228         }
    229 };
    230 
    231 /// Used by previsit implementation
    232 /// We need to reassign the result to 'node', unless the function
    233 /// returns void, then we just leave 'node' unchanged
    234 template<bool is_void>
    235 struct __assign;
    236 
    237 template<>
    238 struct __assign<true> {
    239         template<typename core_t, typename node_t>
    240         static inline void result( core_t & core, const node_t * & node ) {
    241                 core.previsit( node );
    242         }
    243 };
    244 
    245 template<>
    246 struct __assign<false> {
    247         template<typename core_t, typename node_t>
    248         static inline void result( core_t & core, const node_t * & node ) {
    249                 node = core.previsit( node );
    250                 assertf(node, "Previsit must not return NULL");
    251         }
    252 };
    253 
    254 /// Used by postvisit implementation
    255 /// We need to return the result unless the function
    256 /// returns void, then we just return the original node
    257 template<bool is_void>
    258 struct __return;
    259 
    260 template<>
    261 struct __return<true> {
    262         template<typename core_t, typename node_t>
    263         static inline const node_t * result( core_t & core, const node_t * & node ) {
    264                 core.postvisit( node );
    265                 return node;
    266         }
    267 };
    268 
    269 template<>
    270 struct __return<false> {
    271         template<typename core_t, typename node_t>
    272         static inline auto result( core_t & core, const node_t * & node ) {
    273                 return core.postvisit( node );
    274228        }
    275229};
     
    297251        );
    298252
    299         __assign<
    300                 std::is_void<
    301                         decltype( core.previsit( node ) )
    302                 >::value
    303         >::result( core, node );
     253        // We need to reassign the result to 'node', unless the function
     254        // returns void, then we just leave 'node' unchanged
     255        if constexpr ( std::is_void_v<decltype( core.previsit( node ) )> ) {
     256                core.previsit( node );
     257        } else {
     258                node = core.previsit( node );
     259                assertf(node, "Previsit must not return NULL");
     260        }
    304261}
    305262
     
    312269        decltype( core.postvisit( node ), node->accept( *(Visitor*)nullptr ) )
    313270{
    314         return __return<
    315                 std::is_void<
    316                         decltype( core.postvisit( node ) )
    317                 >::value
    318         >::result( core, node );
     271        // We need to return the result unless the function
     272        // returns void, then we just return the original node
     273        if constexpr ( std::is_void_v<decltype( core.postvisit( node ) )> ) {
     274                core.postvisit( node );
     275                return node;
     276        } else {
     277                return core.postvisit( node );
     278        }
    319279}
    320280
  • src/Parser/StatementNode.cc

    rfeb999f rb78c54f  
    122122        ast::Expr * cond = nullptr;
    123123        if ( ctl->condition ) {
    124                 // compare the provided condition against 0
    125                 cond = notZeroExpr( maybeMoveBuild( ctl->condition ) );
     124                cond = maybeMoveBuild( ctl->condition );
    126125        } else {
    127126                for ( ast::ptr<ast::Stmt> & stmt : inits ) {
     
    129128                        auto declStmt = stmt.strict_as<ast::DeclStmt>();
    130129                        auto dwt = declStmt->decl.strict_as<ast::DeclWithType>();
    131                         ast::Expr * nze = notZeroExpr( new ast::VariableExpr( dwt->location, dwt ) );
     130                        ast::Expr * nze = new ast::VariableExpr( dwt->location, dwt );
    132131                        cond = cond ? new ast::LogicalExpr( dwt->location, cond, nze, ast::AndExpr ) : nze;
    133132                }
     
    200199        // do-while cannot have declarations in the contitional, so init is always empty
    201200        return new ast::WhileDoStmt( location,
    202                 notZeroExpr( maybeMoveBuild( ctl ) ),
     201                maybeMoveBuild( ctl ),
    203202                buildMoveSingle( stmt ),
    204203                buildMoveOptional( else_ ),
     
    213212
    214213        ast::Expr * astcond = nullptr;                                          // maybe empty
    215         astcond = notZeroExpr( maybeMoveBuild( forctl->condition ) );
     214        astcond = maybeMoveBuild( forctl->condition );
    216215
    217216        ast::Expr * astincr = nullptr;                                          // maybe empty
     
    330329        clause->target = maybeBuild( targetExpr );
    331330        clause->stmt = maybeMoveBuild( stmt );
    332         clause->when_cond = notZeroExpr( maybeMoveBuild( when ) );
     331        clause->when_cond = maybeMoveBuild( when );
    333332
    334333        ExpressionNode * next = targetExpr->next;
     
    345344ast::WaitForStmt * build_waitfor_else( const CodeLocation & location, ast::WaitForStmt * existing, ExpressionNode * when, StatementNode * stmt ) {
    346345        existing->else_stmt = maybeMoveBuild( stmt );
    347         existing->else_cond = notZeroExpr( maybeMoveBuild( when ) );
     346        existing->else_cond = maybeMoveBuild( when );
    348347
    349348        (void)location;
     
    354353        existing->timeout_time = maybeMoveBuild( timeout );
    355354        existing->timeout_stmt = maybeMoveBuild( stmt );
    356         existing->timeout_cond = notZeroExpr( maybeMoveBuild( when ) );
     355        existing->timeout_cond = maybeMoveBuild( when );
    357356
    358357        (void)location;
     
    362361ast::WaitUntilStmt::ClauseNode * build_waituntil_clause( const CodeLocation & loc, ExpressionNode * when, ExpressionNode * targetExpr, StatementNode * stmt ) {
    363362        ast::WhenClause * clause = new ast::WhenClause( loc );
    364         clause->when_cond = notZeroExpr( maybeMoveBuild( when ) );
     363        clause->when_cond = maybeMoveBuild( when );
    365364        clause->stmt = maybeMoveBuild( stmt );
    366365        clause->target = maybeMoveBuild( targetExpr );
     
    369368ast::WaitUntilStmt::ClauseNode * build_waituntil_else( const CodeLocation & loc, ExpressionNode * when, StatementNode * stmt ) {
    370369        ast::WhenClause * clause = new ast::WhenClause( loc );
    371         clause->when_cond = notZeroExpr( maybeMoveBuild( when ) );
     370        clause->when_cond = maybeMoveBuild( when );
    372371        clause->stmt = maybeMoveBuild( stmt );
    373372        return new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::ELSE, clause );
     
    508507
    509508        ast::Expr * astcond = nullptr;                                          // maybe empty
    510         astcond = notZeroExpr( maybeMoveBuild( forctl->condition ) );
     509        astcond = maybeMoveBuild( forctl->condition );
    511510
    512511        ast::Expr * astincr = nullptr;                                          // maybe empty
  • src/Parser/module.mk

    rfeb999f rb78c54f  
    3131       Parser/parser.yy \
    3232       Parser/ParserTypes.h \
    33        Parser/parserutility.cc \
    3433       Parser/parserutility.h \
    3534       Parser/RunParser.cpp \
  • src/Parser/parserutility.h

    rfeb999f rb78c54f  
    1717
    1818#include "AST/Copy.hpp"            // for shallowCopy
    19 namespace ast {
    20         class Expr;
    21 }
    22 
    23 ast::Expr * notZeroExpr( const ast::Expr *orig );
    2419
    2520template< typename T >
  • src/ResolvExpr/CandidateFinder.cpp

    rfeb999f rb78c54f  
    4646#include "AST/Type.hpp"
    4747#include "Common/utility.h"       // for move, copy
    48 #include "Parser/parserutility.h" // for notZeroExpr
    4948#include "SymTab/Mangler.h"
    5049#include "Tuples/Tuples.h"        // for handleTupleAssignment
     
    15871586        void Finder::postvisit( const ast::LogicalExpr * logicalExpr ) {
    15881587                CandidateFinder finder1( context, tenv );
    1589                 ast::ptr<ast::Expr> arg1 = notZeroExpr( logicalExpr->arg1 );
     1588                ast::ptr<ast::Expr> arg1 = createCondExpr( logicalExpr->arg1 );
    15901589                finder1.find( arg1, ResolveMode::withAdjustment() );
    15911590                if ( finder1.candidates.empty() ) return;
    15921591
    15931592                CandidateFinder finder2( context, tenv );
    1594                 ast::ptr<ast::Expr> arg2 = notZeroExpr( logicalExpr->arg2 );
     1593                ast::ptr<ast::Expr> arg2 = createCondExpr( logicalExpr->arg2 );
    15951594                finder2.find( arg2, ResolveMode::withAdjustment() );
    15961595                if ( finder2.candidates.empty() ) return;
     
    16181617        void Finder::postvisit( const ast::ConditionalExpr * conditionalExpr ) {
    16191618                // candidates for condition
    1620                 ast::ptr<ast::Expr> arg1 = notZeroExpr( conditionalExpr->arg1 );
     1619                ast::ptr<ast::Expr> arg1 = createCondExpr( conditionalExpr->arg1 );
    16211620                CandidateFinder finder1( context, tenv );
    16221621                finder1.find( arg1, ResolveMode::withAdjustment() );
     
    22012200}
    22022201
     2202const ast::Expr * createCondExpr( const ast::Expr * expr ) {
     2203        assert( expr );
     2204        return new ast::CastExpr( expr->location,
     2205                ast::UntypedExpr::createCall( expr->location,
     2206                        "?!=?",
     2207                        {
     2208                                expr,
     2209                                new ast::ConstantExpr( expr->location,
     2210                                        new ast::ZeroType(), "0", std::make_optional( 0ull )
     2211                                ),
     2212                        }
     2213                ),
     2214                new ast::BasicType( ast::BasicType::SignedInt )
     2215        );
     2216}
     2217
    22032218} // namespace ResolvExpr
    22042219
  • src/ResolvExpr/CandidateFinder.hpp

    rfeb999f rb78c54f  
    7070        const ast::Expr * expr, Cost & cost );
    7171
     72/// Wrap an expression to convert the result to a conditional result.
     73const ast::Expr * createCondExpr( const ast::Expr * expr );
     74
    7275} // namespace ResolvExpr
    7376
  • src/ResolvExpr/Resolver.cc

    rfeb999f rb78c54f  
    340340        }
    341341
     342        ast::ptr< ast::Expr > findCondExpression(
     343                const ast::Expr * untyped, const ResolveContext & context
     344        ) {
     345                if ( nullptr == untyped ) return untyped;
     346                ast::ptr<ast::Expr> condExpr = createCondExpr( untyped );
     347                return findIntegralExpression( condExpr, context );
     348        }
     349
    342350        /// check if a type is a character type
    343351        bool isCharType( const ast::Type * t ) {
     
    356364                return it != end;
    357365        }
    358 }
     366} // anonymous namespace
    359367
    360368class Resolver final
     
    729737const ast::IfStmt * Resolver::previsit( const ast::IfStmt * ifStmt ) {
    730738        return ast::mutate_field(
    731                 ifStmt, &ast::IfStmt::cond, findIntegralExpression( ifStmt->cond, context ) );
     739                ifStmt, &ast::IfStmt::cond, findCondExpression( ifStmt->cond, context ) );
    732740}
    733741
    734742const ast::WhileDoStmt * Resolver::previsit( const ast::WhileDoStmt * whileDoStmt ) {
    735743        return ast::mutate_field(
    736                 whileDoStmt, &ast::WhileDoStmt::cond, findIntegralExpression( whileDoStmt->cond, context ) );
     744                whileDoStmt, &ast::WhileDoStmt::cond, findCondExpression( whileDoStmt->cond, context ) );
    737745}
    738746
     
    740748        if ( forStmt->cond ) {
    741749                forStmt = ast::mutate_field(
    742                         forStmt, &ast::ForStmt::cond, findIntegralExpression( forStmt->cond, context ) );
     750                        forStmt, &ast::ForStmt::cond, findCondExpression( forStmt->cond, context ) );
    743751        }
    744752
     
    10751083
    10761084                // Resolve the conditions as if it were an IfStmt, statements normally
    1077                 clause2->when_cond = findSingleExpression( clause.when_cond, context );
     1085                clause2->when_cond = findCondExpression( clause.when_cond, context );
    10781086                clause2->stmt = clause.stmt->accept( *visitor );
    10791087
     
    10891097                        new ast::BasicType{ ast::BasicType::LongLongUnsignedInt };
    10901098                auto timeout_time = findSingleExpression( stmt->timeout_time, target, context );
    1091                 auto timeout_cond = findSingleExpression( stmt->timeout_cond, context );
     1099                auto timeout_cond = findCondExpression( stmt->timeout_cond, context );
    10921100                auto timeout_stmt = stmt->timeout_stmt->accept( *visitor );
    10931101
     
    11021110        if ( stmt->else_stmt ) {
    11031111                // resolve the condition like IfStmt, stmts normally
    1104                 auto else_cond = findSingleExpression( stmt->else_cond, context );
     1112                auto else_cond = findCondExpression( stmt->else_cond, context );
    11051113                auto else_stmt = stmt->else_stmt->accept( *visitor );
    11061114
Note: See TracChangeset for help on using the changeset viewer.