Changeset 3f681b1 for src/AST


Ignore:
Timestamp:
May 11, 2022, 11:33:21 AM (2 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
7675f58
Parents:
e6bb667
Message:

Added the new invariant checks. There seems to be a few unset locations in the multi-level exit code.

Location:
src/AST
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Label.hpp

    re6bb667 r3f681b1  
    3434        std::vector< ptr<Attribute> > attributes;
    3535
    36         Label( CodeLocation loc, const std::string& name = "",
     36        Label( const CodeLocation& loc, const std::string& name = "",
    3737                std::vector<ptr<Attribute>> && attrs = std::vector<ptr<Attribute>>{} )
    3838        : location( loc ), name( name ), attributes( attrs ) {}
  • src/AST/Node.hpp

    re6bb667 r3f681b1  
    5151        bool isManaged() const { return strong_count > 0; }
    5252        bool isReferenced() const { return weak_count > 0; }
     53        bool isStable() const {
     54                return (1 == strong_count || (1 < strong_count && 0 == weak_count));
     55        }
    5356
    5457private:
  • src/AST/Pass.proto.hpp

    re6bb667 r3f681b1  
    131131        template< typename node_t >
    132132        struct result1 {
    133                 bool differs;
    134                 const node_t * value;
     133                bool differs = false;
     134                const node_t * value = nullptr;
    135135
    136136                template< typename object_t, typename super_t, typename field_t >
     
    151151                };
    152152
    153                 bool differs;
     153                bool differs = false;
    154154                container_t< delta > values;
    155155
     
    167167        template< template<class...> class container_t, typename node_t >
    168168        struct resultN {
    169                 bool differs;
     169                bool differs = false;
    170170                container_t<ptr<node_t>> values;
    171171
  • src/AST/Util.cpp

    re6bb667 r3f681b1  
    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  4 15:50:00 2022
     13// Update Count     : 2
    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
     52/// Make sure the reference counts are in a valid combination.
     53void isStable( const Node * node ) {
     54        assert( node->isStable() );
     55}
     56
     57/// Check that a FunctionDecl is synchronized with it's FunctionType.
     58void functionDeclMatchesType( const FunctionDecl * decl ) {
     59        // The type is a cache of sorts, if it is missing that is only a
     60        // problem if isTypeFixed is set.
     61        if ( decl->isTypeFixed ) {
     62                assert( decl->type );
     63        } else if ( !decl->type ) {
     64                return;
    5165        }
    52 };
     66
     67        const FunctionType * type = decl->type;
     68
     69        // Check that `type->forall` corresponds with `decl->type_params`.
     70        assert( type->forall.size() == decl->type_params.size() );
     71        // Check that `type->assertions` corresponds with `decl->assertions`.
     72        assert( type->assertions.size() == decl->assertions.size() );
     73        // Check that `type->params` corresponds with `decl->params`.
     74        assert( type->params.size() == decl->params.size() );
     75        // Check that `type->returns` corresponds with `decl->returns`.
     76        assert( type->returns.size() == decl->returns.size() );
     77}
    5378
    5479struct InvariantCore {
     
    5681        // None of the passes should make changes so ordering doesn't matter.
    5782        NoStrongCyclesCore no_strong_cycles;
    58         SetCodeLocationsCore set_code_locations;
    5983
    6084        void previsit( const Node * node ) {
    6185                no_strong_cycles.previsit( node );
     86                isStable( node );
    6287        }
    6388
    6489        void previsit( const ParseNode * node ) {
    65                 no_strong_cycles.previsit( node );
    66                 set_code_locations.previsit( node );
     90                previsit( (const Node *)node );
     91                isCodeLocationSet( node );
     92        }
     93
     94        void previsit( const FunctionDecl * node ) {
     95                previsit( (const ParseNode *)node );
     96                functionDeclMatchesType( node );
    6797        }
    6898
Note: See TracChangeset for help on using the changeset viewer.