Changeset 9ea38de
- Timestamp:
- Jun 25, 2019, 11:26:30 AM (6 years ago)
- 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
- Files:
-
- 1 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Node.cpp
r28af389 r9ea38de 17 17 #include "Fwd.hpp" 18 18 19 #include <csignal> // MEMORY DEBUG -- for raise 19 20 #include <iostream> 20 21 … … 28 29 29 30 #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 39 void * MEM_TRAP_OBJ = nullptr; 40 41 void ast::Node::_trap() { 42 if ( this == MEM_TRAP_OBJ ) std::raise(SIGTRAP); 43 } 30 44 31 45 template< typename node_t, enum ast::Node::ref_type ref_t > -
src/AST/Node.hpp
r28af389 r9ea38de 30 30 /// Keeps both strong and weak reference counts. 31 31 class Node { 32 /// call to debug on node creation/deletion 33 void _trap(); 32 34 public: 33 35 // override defaults to ensure assignment doesn't 34 36 // 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(); } 38 40 Node& operator= (const Node&) = delete; 39 41 Node& operator= (Node&&) = delete; 40 virtual ~Node() = default;42 virtual ~Node() { _trap(); } 41 43 42 44 virtual const Node * accept( Visitor & v ) const = 0; -
src/AST/Pass.hpp
r28af389 r9ea38de 209 209 /// Internal RAII guard for symbol table features 210 210 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); } 213 213 Pass<pass_t> & pass; 214 214 }; … … 216 216 /// Internal RAII guard for scope features 217 217 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); } 220 220 Pass<pass_t> & pass; 221 221 }; -
src/AST/Pass.impl.hpp
r28af389 r9ea38de 429 429 guard_symtab guard { *this }; 430 430 // 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 }, 435 435 nullptr, VariableLen, DynamicDim 436 )437 );438 __pass::symtab::addId( pass, 0, &func );436 } 437 } }; 438 __pass::symtab::addId( pass, 0, func ); 439 439 VISIT( 440 440 maybe_accept( node, &FunctionDecl::type ); … … 610 610 VISIT({ 611 611 // 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); 616 616 }); 617 617 ValueGuard< bool > guard2( inFunction ); -
src/AST/Pass.proto.hpp
r28af389 r9ea38de 270 270 // Some simple scoping rules 271 271 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() ) { 273 273 pass.symtab.enterScope(); 274 274 } … … 278 278 279 279 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() ) { 281 281 pass.symtab.leaveScope(); 282 282 } -
src/ResolvExpr/AdjustExprType.cc
r28af389 r9ea38de 100 100 101 101 namespace { 102 struct AdjustExprType_new final : public ast::WithShortCircuiting { 102 class AdjustExprType_new final : public ast::WithShortCircuiting { 103 const ast::SymbolTable & symtab; 104 public: 103 105 const ast::TypeEnvironment & tenv; 104 const ast::SymbolTable & symtab;105 106 106 107 AdjustExprType_new( const ast::TypeEnvironment & e, const ast::SymbolTable & syms ) 107 : tenv( e ), symtab( syms) {}108 : symtab( syms ), tenv( e ) {} 108 109 109 110 void premutate( const ast::VoidType * ) { visit_children = false; } -
src/ResolvExpr/CandidateFinder.cpp
r28af389 r9ea38de 594 594 595 595 /// 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: 597 599 CandidateFinder & selfFinder; 598 const ast::SymbolTable & symtab;599 600 CandidateList & candidates; 600 601 const ast::TypeEnvironment & tenv; … … 602 603 603 604 Finder( CandidateFinder & f ) 604 : s elfFinder( f ), symtab( f.symtab), candidates( f.candidates ), tenv( f.env ),605 : symtab( f.localSyms ), selfFinder( f ), candidates( f.candidates ), tenv( f.env ), 605 606 targetType( f.targetType ) {} 606 607 … … 1558 1559 std::vector< std::string > errors; 1559 1560 for ( CandidateRef & candidate : candidates ) { 1560 satisfyAssertions( candidate, symtab, satisfied, errors );1561 satisfyAssertions( candidate, localSyms, satisfied, errors ); 1561 1562 } 1562 1563 … … 1613 1614 r->expr = ast::mutate_field( 1614 1615 r->expr.get(), &ast::Expr::result, 1615 adjustExprType( r->expr->result, r->env, symtab) );1616 adjustExprType( r->expr->result, r->env, localSyms ) ); 1616 1617 } 1617 1618 } … … 1631 1632 1632 1633 for ( const auto & x : xs ) { 1633 out.emplace_back( symtab, env );1634 out.emplace_back( localSyms, env ); 1634 1635 out.back().find( x, ResolvMode::withAdjustment() ); 1635 1636 -
src/ResolvExpr/CandidateFinder.hpp
r28af389 r9ea38de 28 28 struct CandidateFinder { 29 29 CandidateList candidates; ///< List of candidate resolutions 30 const ast::SymbolTable & symtab; ///< Symbol table to lookup candidates30 const ast::SymbolTable & localSyms; ///< Symbol table to lookup candidates 31 31 const ast::TypeEnvironment & env; ///< Substitutions performed in this resolution 32 32 ast::ptr< ast::Type > targetType; ///< Target type for resolution 33 33 34 34 CandidateFinder( 35 const ast::SymbolTable & sym tab, const ast::TypeEnvironment & env,35 const ast::SymbolTable & syms, const ast::TypeEnvironment & env, 36 36 const ast::Type * tt = nullptr ) 37 : candidates(), symtab( symtab), env( env ), targetType( tt ) {}37 : candidates(), localSyms( syms ), env( env ), targetType( tt ) {} 38 38 39 39 /// Fill candidates with feasible resolutions for `expr` -
src/ResolvExpr/PolyCost.cc
r28af389 r9ea38de 58 58 59 59 // TODO: When the old PolyCost is torn out get rid of the _new suffix. 60 struct PolyCost_new { 60 class PolyCost_new { 61 const ast::SymbolTable &symtab; 62 public: 61 63 int result; 62 const ast::SymbolTable &symtab;63 64 const ast::TypeEnvironment &env_; 64 65 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 ) {} 67 68 68 69 void previsit( const ast::TypeInstType * type ) { -
src/Tuples/TupleAssignment.cc
r28af389 r9ea38de 464 464 // resolve ctor/dtor for the new object 465 465 ast::ptr< ast::Init > ctorInit = ResolvExpr::resolveCtorInit( 466 InitTweak::genCtorInit( location, ret ), spotter.crntFinder. symtab);466 InitTweak::genCtorInit( location, ret ), spotter.crntFinder.localSyms ); 467 467 // remove environments from subexpressions of stmtExpr 468 468 ast::Pass< EnvRemover > rm{ env }; … … 559 559 // resolve the cast expression so that rhsCand return type is bound by the cast 560 560 // type as needed, and transfer the resulting environment 561 ResolvExpr::CandidateFinder finder{ spotter.crntFinder. symtab, env };561 ResolvExpr::CandidateFinder finder{ spotter.crntFinder.localSyms, env }; 562 562 finder.find( rhsCand->expr, ResolvExpr::ResolvMode::withAdjustment() ); 563 563 assert( finder.candidates.size() == 1 ); … … 608 608 // explode the LHS so that each field of a tuple-valued expr is assigned 609 609 ResolvExpr::CandidateList lhs; 610 explode( *lhsCand, crntFinder. symtab, back_inserter(lhs), true );610 explode( *lhsCand, crntFinder.localSyms, back_inserter(lhs), true ); 611 611 for ( ResolvExpr::CandidateRef & cand : lhs ) { 612 612 // each LHS value must be a reference - some come in with a cast, if not … … 628 628 if ( isTuple( rhsCand->expr ) ) { 629 629 // multiple assignment 630 explode( *rhsCand, crntFinder. symtab, back_inserter(rhs), true );630 explode( *rhsCand, crntFinder.localSyms, back_inserter(rhs), true ); 631 631 matcher.reset( 632 632 new MultipleAssignMatcher{ *this, expr->location, lhs, rhs } ); … … 647 647 // multiple assignment 648 648 ResolvExpr::CandidateList rhs; 649 explode( rhsCand, crntFinder. symtab, back_inserter(rhs), true );649 explode( rhsCand, crntFinder.localSyms, back_inserter(rhs), true ); 650 650 matcher.reset( 651 651 new MultipleAssignMatcher{ *this, expr->location, lhs, rhs } ); … … 677 677 ) 678 678 679 ResolvExpr::CandidateFinder finder{ crntFinder. symtab, matcher->env };679 ResolvExpr::CandidateFinder finder{ crntFinder.localSyms, matcher->env }; 680 680 681 681 try { -
src/main.cc
r28af389 r9ea38de 29 29 #include <string> // for char_traits, operator<< 30 30 31 #include "AST/Convert.hpp" 31 32 #include "CompilationState.h" 32 33 #include "../config.h" // for CFA_LIBDIR … … 302 303 } // if 303 304 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 } 305 311 if ( exprp ) { 306 312 dump( translationUnit );
Note: See TracChangeset
for help on using the changeset viewer.