Changeset 74ec742 for src/AST/Util.cpp


Ignore:
Timestamp:
May 20, 2022, 10:36:45 AM (3 years ago)
Author:
m3zulfiq <m3zulfiq@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
25fa20a
Parents:
29d8c02 (diff), 7831e8fb (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/Util.cpp

    r29d8c02 r74ec742  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Util.hpp -- General utilities for working with the AST.
     7// Util.cpp -- General utilities for working with the AST.
    88//
    99// Author           : Andrew Beach
    1010// Created On       : Wed Jan 19  9:46:00 2022
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Mar 11 18:07:00 2022
    13 // Update Count     : 1
     12// Last Modified On : Wed May 11 16:16:00 2022
     13// Update Count     : 3
    1414//
    1515
     
    4646
    4747/// Check that every note that can has a set CodeLocation.
    48 struct SetCodeLocationsCore {
    49         void previsit( const ParseNode * node ) {
    50                 assert( node->location.isSet() );
     48void isCodeLocationSet( const ParseNode * node ) {
     49        assert( node->location.isSet() );
     50}
     51
     52void areLabelLocationsSet( const Stmt * stmt ) {
     53        for ( const Label& label : stmt->labels ) {
     54                assert( label.location.isSet() );
    5155        }
    52 };
     56}
     57
     58/// Make sure the reference counts are in a valid combination.
     59void isStable( const Node * node ) {
     60        assert( node->isStable() );
     61}
     62
     63/// Check that a FunctionDecl is synchronized with it's FunctionType.
     64void functionDeclMatchesType( const FunctionDecl * decl ) {
     65        // The type is a cache of sorts, if it is missing that is only a
     66        // problem if isTypeFixed is set.
     67        if ( decl->isTypeFixed ) {
     68                assert( decl->type );
     69        } else if ( !decl->type ) {
     70                return;
     71        }
     72
     73        const FunctionType * type = decl->type;
     74
     75        // Check that `type->forall` corresponds with `decl->type_params`.
     76        assert( type->forall.size() == decl->type_params.size() );
     77        // Check that `type->assertions` corresponds with `decl->assertions`.
     78        assert( type->assertions.size() == decl->assertions.size() );
     79        // Check that `type->params` corresponds with `decl->params`.
     80        assert( type->params.size() == decl->params.size() );
     81        // Check that `type->returns` corresponds with `decl->returns`.
     82        assert( type->returns.size() == decl->returns.size() );
     83}
    5384
    5485struct InvariantCore {
     
    5687        // None of the passes should make changes so ordering doesn't matter.
    5788        NoStrongCyclesCore no_strong_cycles;
    58         SetCodeLocationsCore set_code_locations;
    5989
    6090        void previsit( const Node * node ) {
    6191                no_strong_cycles.previsit( node );
     92                isStable( node );
    6293        }
    6394
    6495        void previsit( const ParseNode * node ) {
    65                 no_strong_cycles.previsit( node );
    66                 set_code_locations.previsit( node );
     96                previsit( (const Node *)node );
     97                isCodeLocationSet( node );
     98        }
     99
     100        void previsit( const FunctionDecl * node ) {
     101                previsit( (const ParseNode *)node );
     102                functionDeclMatchesType( node );
     103        }
     104
     105        void previsit( const Stmt * node ) {
     106                previsit( (const ParseNode *)node );
     107                areLabelLocationsSet( node );
    67108        }
    68109
Note: See TracChangeset for help on using the changeset viewer.