Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Util.cpp

    r7675f58 r33b7d49  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Util.cpp -- General utilities for working with the AST.
     7// Util.hpp -- 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 : Wed May 11 16:16:00 2022
    13 // Update Count     : 3
     12// Last Modified On : Fri Mar 11 18:07:00 2022
     13// Update Count     : 1
    1414//
    1515
     
    4646
    4747/// Check that every note that can has a set CodeLocation.
    48 void isCodeLocationSet( const ParseNode * node ) {
    49         assert( node->location.isSet() );
    50 }
    51 
    52 void areLabelLocationsSet( const Stmt * stmt ) {
    53         for ( const Label& label : stmt->labels ) {
    54                 assert( label.location.isSet() );
     48struct SetCodeLocationsCore {
     49        void previsit( const ParseNode * node ) {
     50                assert( node->location.isSet() );
    5551        }
    56 }
    57 
    58 /// Make sure the reference counts are in a valid combination.
    59 void isStable( const Node * node ) {
    60         assert( node->isStable() );
    61 }
    62 
    63 /// Check that a FunctionDecl is synchronized with it's FunctionType.
    64 void 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 }
     52};
    8453
    8554struct InvariantCore {
     
    8756        // None of the passes should make changes so ordering doesn't matter.
    8857        NoStrongCyclesCore no_strong_cycles;
     58        SetCodeLocationsCore set_code_locations;
    8959
    9060        void previsit( const Node * node ) {
    9161                no_strong_cycles.previsit( node );
    92                 isStable( node );
    9362        }
    9463
    9564        void previsit( const ParseNode * 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 );
     65                no_strong_cycles.previsit( node );
     66                set_code_locations.previsit( node );
    10867        }
    10968
Note: See TracChangeset for help on using the changeset viewer.