Changeset 9ea38de


Ignore:
Timestamp:
Jun 25, 2019, 11:26:30 AM (5 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
bcb311b
Parents:
28af389
Message:

Fix ast::Pass guard classes

Files:
1 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Node.cpp

    r28af389 r9ea38de  
    1717#include "Fwd.hpp"
    1818
     19#include <csignal>  // MEMORY DEBUG -- for raise
    1920#include <iostream>
    2021
     
    2829
    2930#include "Print.hpp"
     31
     32/// MEMORY DEBUG -- allows breaking on construction/destruction of dynamically chosen object.
     33/// Process to use in GDB:
     34///   break ast::Node::_trap()
     35///   run
     36///   set variable MEM_TRAP_OBJ = <target>
     37///   disable <first breakpoint>
     38///   continue
     39void * MEM_TRAP_OBJ = nullptr;
     40
     41void ast::Node::_trap() {
     42        if ( this == MEM_TRAP_OBJ ) std::raise(SIGTRAP);
     43}
    3044
    3145template< typename node_t, enum ast::Node::ref_type ref_t >
  • src/AST/Node.hpp

    r28af389 r9ea38de  
    3030/// Keeps both strong and weak reference counts.
    3131class Node {
     32        /// call to debug on node creation/deletion
     33        void _trap();
    3234public:
    3335        // override defaults to ensure assignment doesn't
    3436        // change/share reference counts
    35         Node() = default;
    36         Node(const Node&) : strong_count(0), weak_count(0) {}
    37         Node(Node&&) : strong_count(0), weak_count(0) {}
     37        Node() { _trap(); }
     38        Node(const Node&) : strong_count(0), weak_count(0) { _trap(); }
     39        Node(Node&&) : strong_count(0), weak_count(0) { _trap(); }
    3840        Node& operator= (const Node&) = delete;
    3941        Node& operator= (Node&&) = delete;
    40         virtual ~Node() = default;
     42        virtual ~Node() { _trap(); }
    4143
    4244        virtual const Node * accept( Visitor & v ) const = 0;
  • src/AST/Pass.hpp

    r28af389 r9ea38de  
    209209        /// Internal RAII guard for symbol table features
    210210        struct guard_symtab {
    211                 guard_symtab( Pass<pass_t> & pass ): pass( pass ) { __pass::symtab::enter(pass, 0); }
    212                 ~guard_symtab()                                   { __pass::symtab::leave(pass, 0); }
     211                guard_symtab( Pass<pass_t> & pass ): pass( pass ) { __pass::symtab::enter(pass.pass, 0); }
     212                ~guard_symtab()                                   { __pass::symtab::leave(pass.pass, 0); }
    213213                Pass<pass_t> & pass;
    214214        };
     
    216216        /// Internal RAII guard for scope features
    217217        struct guard_scope {
    218                 guard_scope( Pass<pass_t> & pass ): pass( pass ) { __pass::scope::enter(pass, 0); }
    219                 ~guard_scope()                                   { __pass::scope::leave(pass, 0); }
     218                guard_scope( Pass<pass_t> & pass ): pass( pass ) { __pass::scope::enter(pass.pass, 0); }
     219                ~guard_scope()                                   { __pass::scope::leave(pass.pass, 0); }
    220220                Pass<pass_t> & pass;
    221221        };
  • src/AST/Pass.impl.hpp

    r28af389 r9ea38de  
    429429                        guard_symtab guard { *this };
    430430                        // implicit add __func__ identifier as specified in the C manual 6.4.2.2
    431                         static ast::ObjectDecl func(
    432                                 node->location, "__func__",
    433                                 new ast::ArrayType(
    434                                         new ast::BasicType( ast::BasicType::Char, ast::CV::Qualifiers( ast::CV::Const ) ),
     431                        static ast::ptr< ast::ObjectDecl > func{ new ast::ObjectDecl{
     432                                CodeLocation{}, "__func__",
     433                                new ast::ArrayType{
     434                                        new ast::BasicType{ ast::BasicType::Char, ast::CV::Const },
    435435                                        nullptr, VariableLen, DynamicDim
    436                                 )
    437                         );
    438                         __pass::symtab::addId( pass, 0, &func );
     436                                }
     437                        } };
     438                        __pass::symtab::addId( pass, 0, func );
    439439                        VISIT(
    440440                                maybe_accept( node, &FunctionDecl::type );
     
    610610        VISIT({
    611611                // do not enter a new scope if inFunction is true - needs to check old state before the assignment
    612                 auto guard1 = makeFuncGuard( [this, inFunction = this->inFunction]() {
    613                         if ( ! inFunction ) __pass::symtab::enter(pass, 0);
    614                 }, [this, inFunction = this->inFunction]() {
    615                         if ( ! inFunction ) __pass::symtab::leave(pass, 0);
     612                auto guard1 = makeFuncGuard( [this, inFunctionCpy = this->inFunction]() {
     613                        if ( ! inFunctionCpy ) __pass::symtab::enter(pass, 0);
     614                }, [this, inFunctionCpy = this->inFunction]() {
     615                        if ( ! inFunctionCpy ) __pass::symtab::leave(pass, 0);
    616616                });
    617617                ValueGuard< bool > guard2( inFunction );
  • src/AST/Pass.proto.hpp

    r28af389 r9ea38de  
    270270                // Some simple scoping rules
    271271                template<typename pass_t>
    272                 static inline auto enter( pass_t & pass, int ) -> decltype( pass.symtab.enterScope(), void() ) {
     272                static inline auto enter( pass_t & pass, int ) -> decltype( pass.symtab, void() ) {
    273273                        pass.symtab.enterScope();
    274274                }
     
    278278
    279279                template<typename pass_t>
    280                 static inline auto leave( pass_t & pass, int ) -> decltype( pass.symtab.leaveScope(), void() ) {
     280                static inline auto leave( pass_t & pass, int ) -> decltype( pass.symtab, void() ) {
    281281                        pass.symtab.leaveScope();
    282282                }
  • src/ResolvExpr/AdjustExprType.cc

    r28af389 r9ea38de  
    100100
    101101namespace {
    102         struct AdjustExprType_new final : public ast::WithShortCircuiting {
     102        class AdjustExprType_new final : public ast::WithShortCircuiting {
     103                const ast::SymbolTable & symtab;
     104        public:
    103105                const ast::TypeEnvironment & tenv;
    104                 const ast::SymbolTable & symtab;
    105106
    106107                AdjustExprType_new( const ast::TypeEnvironment & e, const ast::SymbolTable & syms )
    107                 : tenv( e ), symtab( syms ) {}
     108                : symtab( syms ), tenv( e ) {}
    108109
    109110                void premutate( const ast::VoidType * ) { visit_children = false; }
  • src/ResolvExpr/CandidateFinder.cpp

    r28af389 r9ea38de  
    594594
    595595        /// Actually visits expressions to find their candidate interpretations
    596         struct Finder final : public ast::WithShortCircuiting {
     596        class Finder final : public ast::WithShortCircuiting {
     597                const ast::SymbolTable & symtab;
     598        public:
    597599                CandidateFinder & selfFinder;
    598                 const ast::SymbolTable & symtab;
    599600                CandidateList & candidates;
    600601                const ast::TypeEnvironment & tenv;
     
    602603
    603604                Finder( CandidateFinder & f )
    604                 : selfFinder( f ), symtab( f.symtab ), candidates( f.candidates ), tenv( f.env ),
     605                : symtab( f.localSyms ), selfFinder( f ), candidates( f.candidates ), tenv( f.env ),
    605606                  targetType( f.targetType ) {}
    606607               
     
    15581559                std::vector< std::string > errors;
    15591560                for ( CandidateRef & candidate : candidates ) {
    1560                         satisfyAssertions( candidate, symtab, satisfied, errors );
     1561                        satisfyAssertions( candidate, localSyms, satisfied, errors );
    15611562                }
    15621563
     
    16131614                        r->expr = ast::mutate_field(
    16141615                                r->expr.get(), &ast::Expr::result,
    1615                                 adjustExprType( r->expr->result, r->env, symtab ) );
     1616                                adjustExprType( r->expr->result, r->env, localSyms ) );
    16161617                }
    16171618        }
     
    16311632
    16321633        for ( const auto & x : xs ) {
    1633                 out.emplace_back( symtab, env );
     1634                out.emplace_back( localSyms, env );
    16341635                out.back().find( x, ResolvMode::withAdjustment() );
    16351636               
  • src/ResolvExpr/CandidateFinder.hpp

    r28af389 r9ea38de  
    2828struct CandidateFinder {
    2929        CandidateList candidates;          ///< List of candidate resolutions
    30         const ast::SymbolTable & symtab;   ///< Symbol table to lookup candidates
     30        const ast::SymbolTable & localSyms;   ///< Symbol table to lookup candidates
    3131        const ast::TypeEnvironment & env;  ///< Substitutions performed in this resolution
    3232        ast::ptr< ast::Type > targetType;  ///< Target type for resolution
    3333
    3434        CandidateFinder(
    35                 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env,
     35                const ast::SymbolTable & syms, const ast::TypeEnvironment & env,
    3636                const ast::Type * tt = nullptr )
    37         : candidates(), symtab( symtab ), env( env ), targetType( tt ) {}
     37        : candidates(), localSyms( syms ), env( env ), targetType( tt ) {}
    3838
    3939        /// Fill candidates with feasible resolutions for `expr`
  • src/ResolvExpr/PolyCost.cc

    r28af389 r9ea38de  
    5858
    5959// TODO: When the old PolyCost is torn out get rid of the _new suffix.
    60 struct PolyCost_new {
     60class PolyCost_new {
     61        const ast::SymbolTable &symtab;
     62public:
    6163        int result;
    62         const ast::SymbolTable &symtab;
    6364        const ast::TypeEnvironment &env_;
    6465
    65         PolyCost_new( const ast::SymbolTable & symtab, const ast::TypeEnvironment & env ) :
    66                 result( 0 ), symtab( symtab ), env_( env ) {}
     66        PolyCost_new( const ast::SymbolTable & symtab, const ast::TypeEnvironment & env )
     67        : symtab( symtab ), result( 0 ), env_( env ) {}
    6768
    6869        void previsit( const ast::TypeInstType * type ) {
  • src/Tuples/TupleAssignment.cc

    r28af389 r9ea38de  
    464464                                        // resolve ctor/dtor for the new object
    465465                                        ast::ptr< ast::Init > ctorInit = ResolvExpr::resolveCtorInit(
    466                                                         InitTweak::genCtorInit( location, ret ), spotter.crntFinder.symtab );
     466                                                        InitTweak::genCtorInit( location, ret ), spotter.crntFinder.localSyms );
    467467                                        // remove environments from subexpressions of stmtExpr
    468468                                        ast::Pass< EnvRemover > rm{ env };
     
    559559                                        // resolve the cast expression so that rhsCand return type is bound by the cast
    560560                                        // type as needed, and transfer the resulting environment
    561                                         ResolvExpr::CandidateFinder finder{ spotter.crntFinder.symtab, env };
     561                                        ResolvExpr::CandidateFinder finder{ spotter.crntFinder.localSyms, env };
    562562                                        finder.find( rhsCand->expr, ResolvExpr::ResolvMode::withAdjustment() );
    563563                                        assert( finder.candidates.size() == 1 );
     
    608608                                        // explode the LHS so that each field of a tuple-valued expr is assigned
    609609                                        ResolvExpr::CandidateList lhs;
    610                                         explode( *lhsCand, crntFinder.symtab, back_inserter(lhs), true );
     610                                        explode( *lhsCand, crntFinder.localSyms, back_inserter(lhs), true );
    611611                                        for ( ResolvExpr::CandidateRef & cand : lhs ) {
    612612                                                // each LHS value must be a reference - some come in with a cast, if not
     
    628628                                                        if ( isTuple( rhsCand->expr ) ) {
    629629                                                                // multiple assignment
    630                                                                 explode( *rhsCand, crntFinder.symtab, back_inserter(rhs), true );
     630                                                                explode( *rhsCand, crntFinder.localSyms, back_inserter(rhs), true );
    631631                                                                matcher.reset(
    632632                                                                        new MultipleAssignMatcher{ *this, expr->location, lhs, rhs } );
     
    647647                                                        // multiple assignment
    648648                                                        ResolvExpr::CandidateList rhs;
    649                                                         explode( rhsCand, crntFinder.symtab, back_inserter(rhs), true );
     649                                                        explode( rhsCand, crntFinder.localSyms, back_inserter(rhs), true );
    650650                                                        matcher.reset(
    651651                                                                new MultipleAssignMatcher{ *this, expr->location, lhs, rhs } );
     
    677677                                )
    678678
    679                                 ResolvExpr::CandidateFinder finder{ crntFinder.symtab, matcher->env };
     679                                ResolvExpr::CandidateFinder finder{ crntFinder.localSyms, matcher->env };
    680680
    681681                                try {
  • src/main.cc

    r28af389 r9ea38de  
    2929#include <string>                           // for char_traits, operator<<
    3030
     31#include "AST/Convert.hpp"
    3132#include "CompilationState.h"
    3233#include "../config.h"                      // for CFA_LIBDIR
     
    302303                } // if
    303304
    304                 PASS( "Resolve", ResolvExpr::resolve( translationUnit ) );
     305                // PASS( "Resolve", ResolvExpr::resolve( translationUnit ) );
     306                {
     307                        auto transUnit = convert( move( translationUnit ) );
     308                        PASS( "Resolve", ResolvExpr::resolve( transUnit ) );
     309                        translationUnit = convert( move( transUnit ) );
     310                }
    305311                if ( exprp ) {
    306312                        dump( translationUnit );
Note: See TracChangeset for help on using the changeset viewer.