- Timestamp:
- Apr 10, 2022, 2:53:18 PM (4 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- d8e2a09
- Parents:
- 4559b34 (diff), 6256891 (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. - Location:
- src/AST
- Files:
-
- 2 added
- 2 deleted
- 16 edited
-
AssertAcyclic.cpp (deleted)
-
AssertAcyclic.hpp (deleted)
-
Convert.cpp (modified) (14 diffs)
-
Decl.cpp (modified) (2 diffs)
-
Fwd.hpp (modified) (2 diffs)
-
GenericSubstitution.cpp (modified) (1 diff)
-
Node.cpp (modified) (5 diffs)
-
Node.hpp (modified) (6 diffs)
-
Pass.hpp (modified) (1 diff)
-
Pass.impl.hpp (modified) (10 diffs)
-
Print.cpp (modified) (5 diffs)
-
Stmt.hpp (modified) (6 diffs)
-
TranslationUnit.hpp (modified) (2 diffs)
-
Type.cpp (modified) (1 diff)
-
Type.hpp (modified) (1 diff)
-
TypeSubstitution.hpp (modified) (4 diffs)
-
Util.cpp (added)
-
Util.hpp (added)
-
Visitor.hpp (modified) (1 diff)
-
module.mk (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r4559b34 r92538ab 9 9 // Author : Thierry Delisle 10 10 // Created On : Thu May 09 15::37::05 2019 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Wed Feb 2 13:19:22202213 // Update Count : 4 111 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Mar 16 15:01:00 2022 13 // Update Count : 42 14 14 // 15 15 … … 49 49 //================================================================================================ 50 50 namespace ast { 51 52 // This is to preserve the FindSpecialDecls hack. It does not (and perhaps should not) 53 // allow us to use the same stratagy in the new ast. 54 // xxx - since convert back pass works, this concern seems to be unnecessary. 55 56 // these need to be accessed in new FixInit now 57 ast::ptr<ast::Type> sizeType = nullptr; 58 const ast::FunctionDecl * dereferenceOperator = nullptr; 59 const ast::StructDecl * dtorStruct = nullptr; 60 const ast::FunctionDecl * dtorStructDestroy = nullptr; 51 // These are the shared local information used by ConverterNewToOld and 52 // ConverterOldToNew to update the global information in the two versions. 53 54 static ast::ptr<ast::Type> sizeType = nullptr; 55 static const ast::FunctionDecl * dereferenceOperator = nullptr; 56 static const ast::StructDecl * dtorStruct = nullptr; 57 static const ast::FunctionDecl * dtorStructDestroy = nullptr; 61 58 62 59 } … … 357 354 } 358 355 356 void clausePostamble( Statement * stmt, const ast::StmtClause * node ) { 357 stmt->location = node->location; 358 this->node = stmt; 359 } 360 359 361 const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final { 360 362 if ( inCache( node ) ) return nullptr; … … 405 407 auto stmt = new SwitchStmt( 406 408 get<Expression>().accept1( node->cond ), 407 get<Statement>().acceptL( node-> stmts )409 get<Statement>().acceptL( node->cases ) 408 410 ); 409 411 return stmtPostamble( stmt, node ); 410 412 } 411 413 412 const ast:: Stmt * visit( const ast::CaseStmt* node ) override final {414 const ast::CaseClause * visit( const ast::CaseClause * node ) override final { 413 415 if ( inCache( node ) ) return nullptr; 414 416 auto stmt = new CaseStmt( … … 417 419 node->isDefault() 418 420 ); 419 return stmtPostamble( stmt, node ); 421 clausePostamble( stmt, node ); 422 return nullptr; 420 423 } 421 424 … … 513 516 } 514 517 515 const ast:: Stmt * visit( const ast::CatchStmt* node ) override final {518 const ast::CatchClause * visit( const ast::CatchClause * node ) override final { 516 519 if ( inCache( node ) ) return nullptr; 517 520 CatchStmt::Kind kind; … … 524 527 break; 525 528 default: 526 assertf(false, "Invalid ast:: CatchStmt::Kind: %d\n", node->kind);529 assertf(false, "Invalid ast::ExceptionKind: %d\n", node->kind); 527 530 } 528 531 auto stmt = new CatchStmt( … … 532 535 get<Statement>().accept1( node->body ) 533 536 ); 534 return stmtPostamble( stmt, node );535 } 536 537 const ast:: Stmt * visit( const ast::FinallyStmt* node ) override final {537 return clausePostamble( stmt, node ), nullptr; 538 } 539 540 const ast::FinallyClause * visit( const ast::FinallyClause * node ) override final { 538 541 if ( inCache( node ) ) return nullptr; 539 542 auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) ); 540 return stmtPostamble( stmt, node );543 return clausePostamble( stmt, node ), nullptr; 541 544 } 542 545 … … 1894 1897 old->location, 1895 1898 GET_ACCEPT_1(condition, Expr), 1896 GET_ACCEPT_V(statements, Stmt),1899 GET_ACCEPT_V(statements, CaseClause), 1897 1900 GET_LABELS_V(old->labels) 1898 1901 ); … … 1902 1905 virtual void visit( const CaseStmt * old ) override final { 1903 1906 if ( inCache( old ) ) return; 1904 this->node = new ast::Case Stmt(1907 this->node = new ast::CaseClause( 1905 1908 old->location, 1906 1909 GET_ACCEPT_1(condition, Expr), 1907 GET_ACCEPT_V(stmts, Stmt), 1908 GET_LABELS_V(old->labels) 1909 ); 1910 GET_ACCEPT_V(stmts, Stmt) 1911 ); 1912 auto labels = GET_LABELS_V(old->labels); 1913 assertf(labels.empty(), "Labels found on CaseStmt."); 1910 1914 cache.emplace( old, this->node ); 1911 1915 } … … 2015 2019 old->location, 2016 2020 GET_ACCEPT_1(block, CompoundStmt), 2017 GET_ACCEPT_V(handlers, Catch Stmt),2018 GET_ACCEPT_1(finallyBlock, Finally Stmt),2021 GET_ACCEPT_V(handlers, CatchClause), 2022 GET_ACCEPT_1(finallyBlock, FinallyClause), 2019 2023 GET_LABELS_V(old->labels) 2020 2024 ); … … 2036 2040 } 2037 2041 2038 this->node = new ast::Catch Stmt(2042 this->node = new ast::CatchClause( 2039 2043 old->location, 2040 2044 kind, 2041 2045 GET_ACCEPT_1(decl, Decl), 2042 2046 GET_ACCEPT_1(cond, Expr), 2043 GET_ACCEPT_1(body, Stmt), 2044 GET_LABELS_V(old->labels) 2045 ); 2047 GET_ACCEPT_1(body, Stmt) 2048 ); 2049 auto labels = GET_LABELS_V(old->labels); 2050 assertf(labels.empty(), "Labels found on CatchStmt."); 2046 2051 cache.emplace( old, this->node ); 2047 2052 } … … 2049 2054 virtual void visit( const FinallyStmt * old ) override final { 2050 2055 if ( inCache( old ) ) return; 2051 this->node = new ast::FinallyStmt( 2052 old->location, 2053 GET_ACCEPT_1(block, CompoundStmt), 2054 GET_LABELS_V(old->labels) 2055 ); 2056 this->node = new ast::FinallyClause( 2057 old->location, 2058 GET_ACCEPT_1(block, CompoundStmt) 2059 ); 2060 auto labels = GET_LABELS_V(old->labels); 2061 assertf(labels.empty(), "Labels found on FinallyStmt."); 2056 2062 cache.emplace( old, this->node ); 2057 2063 } … … 2718 2724 2719 2725 for (auto & param : foralls) { 2720 ty->forall.emplace_back(new ast::TypeInstType(param ->name, param));2726 ty->forall.emplace_back(new ast::TypeInstType(param)); 2721 2727 for (auto asst : param->assertions) { 2722 2728 ty->assertions.emplace_back(new ast::VariableExpr({}, asst)); -
src/AST/Decl.cpp
r4559b34 r92538ab 39 39 if ( uniqueId ) return; // ensure only set once 40 40 uniqueId = ++lastUniqueId; 41 idMap[ uniqueId ] = this; 41 // The extra readonly pointer is causing some reference counting issues. 42 // idMap[ uniqueId ] = this; 42 43 } 43 44 44 45 readonly<Decl> Decl::fromId( UniqueId id ) { 46 // Right now this map is always empty, so don't use it. 47 assert( false ); 45 48 IdMapType::const_iterator i = idMap.find( id ); 46 49 if ( i != idMap.end() ) return i->second; … … 65 68 } 66 69 for (auto & tp : this->type_params) { 67 ftype->forall.emplace_back(new TypeInstType(tp ->name, tp));70 ftype->forall.emplace_back(new TypeInstType(tp)); 68 71 for (auto & ap: tp->assertions) { 69 72 ftype->assertions.emplace_back(new VariableExpr(loc, ap)); -
src/AST/Fwd.hpp
r4559b34 r92538ab 47 47 class ForStmt; 48 48 class SwitchStmt; 49 class Case Stmt;49 class CaseClause; 50 50 class BranchStmt; 51 51 class ReturnStmt; 52 52 class ThrowStmt; 53 53 class TryStmt; 54 class Catch Stmt;55 class Finally Stmt;54 class CatchClause; 55 class FinallyClause; 56 56 class SuspendStmt; 57 57 class WaitForStmt; … … 141 141 142 142 class TranslationUnit; 143 // TODO: Get from the TranslationUnit: 144 extern ptr<Type> sizeType; 145 extern const FunctionDecl * dereferenceOperator; 146 extern const StructDecl * dtorStruct; 147 extern const FunctionDecl * dtorStructDestroy; 143 class TranslationGlobal; 148 144 149 145 } -
src/AST/GenericSubstitution.cpp
r4559b34 r92538ab 45 45 visit_children = false; 46 46 const AggregateDecl * aggr = ty->aggr(); 47 sub = TypeSubstitution { aggr->params.begin(), aggr->params.end(), ty->params.begin() };47 sub = TypeSubstitution( aggr->params, ty->params ); 48 48 } 49 49 -
src/AST/Node.cpp
r4559b34 r92538ab 9 9 // Author : Thierry Delisle 10 10 // Created On : Thu May 16 14:16:00 2019 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue Feb 1 09:09:39202213 // Update Count : 311 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Mar 25 10:30:00 2022 13 // Update Count : 4 14 14 // 15 15 … … 19 19 #include <csignal> // MEMORY DEBUG -- for raise 20 20 #include <iostream> 21 #include <utility> 21 22 22 23 #include "Attribute.hpp" … … 76 77 void ast::ptr_base<node_t, ref_t>::_check() const { 77 78 // if(node) assert(node->was_ever_strong == false || node->strong_count > 0); 79 } 80 81 template< typename node_t, enum ast::Node::ref_type ref_t > 82 void ast::ptr_base<node_t, ref_t>::swap( ptr_base & other ) noexcept { 83 std::swap( this->node, other.node ); 84 _trap( this->node ); 85 _trap( other.node ); 78 86 } 79 87 … … 152 160 template class ast::ptr_base< ast::SwitchStmt, ast::Node::ref_type::weak >; 153 161 template class ast::ptr_base< ast::SwitchStmt, ast::Node::ref_type::strong >; 154 template class ast::ptr_base< ast::Case Stmt, ast::Node::ref_type::weak >;155 template class ast::ptr_base< ast::Case Stmt, ast::Node::ref_type::strong >;162 template class ast::ptr_base< ast::CaseClause, ast::Node::ref_type::weak >; 163 template class ast::ptr_base< ast::CaseClause, ast::Node::ref_type::strong >; 156 164 template class ast::ptr_base< ast::BranchStmt, ast::Node::ref_type::weak >; 157 165 template class ast::ptr_base< ast::BranchStmt, ast::Node::ref_type::strong >; … … 162 170 template class ast::ptr_base< ast::TryStmt, ast::Node::ref_type::weak >; 163 171 template class ast::ptr_base< ast::TryStmt, ast::Node::ref_type::strong >; 164 template class ast::ptr_base< ast::Catch Stmt, ast::Node::ref_type::weak >;165 template class ast::ptr_base< ast::Catch Stmt, ast::Node::ref_type::strong >;166 template class ast::ptr_base< ast::Finally Stmt, ast::Node::ref_type::weak >;167 template class ast::ptr_base< ast::Finally Stmt, ast::Node::ref_type::strong >;172 template class ast::ptr_base< ast::CatchClause, ast::Node::ref_type::weak >; 173 template class ast::ptr_base< ast::CatchClause, ast::Node::ref_type::strong >; 174 template class ast::ptr_base< ast::FinallyClause, ast::Node::ref_type::weak >; 175 template class ast::ptr_base< ast::FinallyClause, ast::Node::ref_type::strong >; 168 176 template class ast::ptr_base< ast::WaitForStmt, ast::Node::ref_type::weak >; 169 177 template class ast::ptr_base< ast::WaitForStmt, ast::Node::ref_type::strong >; -
src/AST/Node.hpp
r4559b34 r92538ab 10 10 // Created On : Wed May 8 10:27:04 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Jun 5 9:47:00 202013 // Update Count : 612 // Last Modified On : Fri Mar 25 10:33:00 2022 13 // Update Count : 7 14 14 // 15 15 … … 103 103 104 104 /// Mutate a node field (only clones if not equal to existing value) 105 template<typename node_t, typename parent_t, typename field_t, typename assn_t>106 const node_t * mutate_field( const node_t * node, field_t parent_t::* field, assn_t && val ) {105 template<typename node_t, typename super_t, typename field_t, typename assn_t> 106 const node_t * mutate_field( const node_t * node, field_t super_t::* field, assn_t && val ) { 107 107 // skip mutate if equivalent 108 108 if ( node->*field == val ) return node; … … 115 115 116 116 /// Mutate a single index of a node field (only clones if not equal to existing value) 117 template<typename node_t, typename parent_t, typename coll_t, typename ind_t, typename field_t>117 template<typename node_t, typename super_t, typename coll_t, typename ind_t, typename field_t> 118 118 const node_t * mutate_field_index( 119 const node_t * node, coll_t parent_t::* field, ind_t i, field_t && val119 const node_t * node, coll_t super_t::* field, ind_t i, field_t && val 120 120 ) { 121 121 // skip mutate if equivalent … … 129 129 130 130 /// Mutate an entire indexed collection by cloning to accepted value 131 template<typename node_t, typename parent_t, typename coll_t>132 const node_t * mutate_each( const node_t * node, coll_t parent_t::* field, Visitor & v ) {131 template<typename node_t, typename super_t, typename coll_t> 132 const node_t * mutate_each( const node_t * node, coll_t super_t::* field, Visitor & v ) { 133 133 for ( unsigned i = 0; i < (node->*field).size(); ++i ) { 134 134 node = mutate_field_index( node, field, i, (node->*field)[i]->accept( v ) ); … … 230 230 } 231 231 232 /// Swaps the nodes contained within two pointers. 233 void swap( ptr_base & other ) noexcept; 234 232 235 const node_t * get() const { _check(); return node; } 233 236 const node_t * operator->() const { _check(); return node; } … … 292 295 template< typename node_t > 293 296 using readonly = ptr_base< node_t, Node::ref_type::weak >; 297 298 /// Non-member swap that an participate in overload resolution. 299 template< typename node_t, enum Node::ref_type ref_t > 300 void swap( ptr_base< node_t, ref_t > & l, ptr_base< node_t, ref_t > & r ) { 301 l.swap( r ); 302 } 303 294 304 } 295 305 -
src/AST/Pass.hpp
r4559b34 r92538ab 149 149 const ast::Stmt * visit( const ast::ForStmt * ) override final; 150 150 const ast::Stmt * visit( const ast::SwitchStmt * ) override final; 151 const ast:: Stmt * visit( const ast::CaseStmt* ) override final;151 const ast::CaseClause * visit( const ast::CaseClause * ) override final; 152 152 const ast::Stmt * visit( const ast::BranchStmt * ) override final; 153 153 const ast::Stmt * visit( const ast::ReturnStmt * ) override final; 154 154 const ast::Stmt * visit( const ast::ThrowStmt * ) override final; 155 155 const ast::Stmt * visit( const ast::TryStmt * ) override final; 156 const ast:: Stmt * visit( const ast::CatchStmt* ) override final;157 const ast:: Stmt * visit( const ast::FinallyStmt* ) override final;156 const ast::CatchClause * visit( const ast::CatchClause * ) override final; 157 const ast::FinallyClause * visit( const ast::FinallyClause * ) override final; 158 158 const ast::Stmt * visit( const ast::SuspendStmt * ) override final; 159 159 const ast::Stmt * visit( const ast::WaitForStmt * ) override final; -
src/AST/Pass.impl.hpp
r4559b34 r92538ab 354 354 // Take all the elements that are different in 'values' 355 355 // and swap them into 'container' 356 if( values[i] != nullptr ) s td::swap(container[i], values[i]);356 if( values[i] != nullptr ) swap(container[i], values[i]); 357 357 } 358 358 … … 399 399 400 400 template< typename core_t > 401 template<typename node_t, typename parent_t, typename child_t>401 template<typename node_t, typename super_t, typename field_t> 402 402 void ast::Pass< core_t >::maybe_accept( 403 403 const node_t * & parent, 404 child_t parent_t::*child404 field_t super_t::*field 405 405 ) { 406 static_assert( std::is_base_of< parent_t, node_t>::value, "Error deducing member object" );407 408 if(__pass::skip(parent->* child)) return;409 const auto & old_val = __pass::get(parent->* child, 0);406 static_assert( std::is_base_of<super_t, node_t>::value, "Error deducing member object" ); 407 408 if(__pass::skip(parent->*field)) return; 409 const auto & old_val = __pass::get(parent->*field, 0); 410 410 411 411 static_assert( !std::is_same<const ast::Node * &, decltype(old_val)>::value, "ERROR"); … … 417 417 if( new_val.differs ) { 418 418 auto new_parent = __pass::mutate<core_t>(parent); 419 new_val.apply(new_parent, child);419 new_val.apply(new_parent, field); 420 420 parent = new_parent; 421 421 } … … 423 423 424 424 template< typename core_t > 425 template<typename node_t, typename parent_t, typename child_t>425 template<typename node_t, typename super_t, typename field_t> 426 426 void ast::Pass< core_t >::maybe_accept_as_compound( 427 427 const node_t * & parent, 428 child_t parent_t::*child428 field_t super_t::*child 429 429 ) { 430 static_assert( std::is_base_of< parent_t, node_t>::value, "Error deducing member object" );430 static_assert( std::is_base_of<super_t, node_t>::value, "Error deducing member object" ); 431 431 432 432 if(__pass::skip(parent->*child)) return; … … 893 893 if ( __visit_children() ) { 894 894 maybe_accept( node, &SwitchStmt::cond ); 895 maybe_accept( node, &SwitchStmt:: stmts );895 maybe_accept( node, &SwitchStmt::cases ); 896 896 } 897 897 … … 900 900 901 901 //-------------------------------------------------------------------------- 902 // Case Stmt903 template< typename core_t > 904 const ast:: Stmt * ast::Pass< core_t >::visit( const ast::CaseStmt* node ) {905 VISIT_START( node ); 906 907 if ( __visit_children() ) { 908 maybe_accept( node, &Case Stmt::cond );909 maybe_accept( node, &Case Stmt::stmts );910 } 911 912 VISIT_END( Stmt, node );902 // CaseClause 903 template< typename core_t > 904 const ast::CaseClause * ast::Pass< core_t >::visit( const ast::CaseClause * node ) { 905 VISIT_START( node ); 906 907 if ( __visit_children() ) { 908 maybe_accept( node, &CaseClause::cond ); 909 maybe_accept( node, &CaseClause::stmts ); 910 } 911 912 VISIT_END( CaseClause, node ); 913 913 } 914 914 … … 964 964 965 965 //-------------------------------------------------------------------------- 966 // Catch Stmt967 template< typename core_t > 968 const ast:: Stmt * ast::Pass< core_t >::visit( const ast::CatchStmt* node ) {966 // CatchClause 967 template< typename core_t > 968 const ast::CatchClause * ast::Pass< core_t >::visit( const ast::CatchClause * node ) { 969 969 VISIT_START( node ); 970 970 … … 972 972 // catch statements introduce a level of scope (for the caught exception) 973 973 guard_symtab guard { *this }; 974 maybe_accept( node, &Catch Stmt::decl );975 maybe_accept( node, &Catch Stmt::cond );976 maybe_accept_as_compound( node, &Catch Stmt::body );977 } 978 979 VISIT_END( Stmt, node );980 } 981 982 //-------------------------------------------------------------------------- 983 // Finally Stmt984 template< typename core_t > 985 const ast:: Stmt * ast::Pass< core_t >::visit( const ast::FinallyStmt* node ) {986 VISIT_START( node ); 987 988 if ( __visit_children() ) { 989 maybe_accept( node, &Finally Stmt::body );990 } 991 992 VISIT_END( Stmt, node );974 maybe_accept( node, &CatchClause::decl ); 975 maybe_accept( node, &CatchClause::cond ); 976 maybe_accept_as_compound( node, &CatchClause::body ); 977 } 978 979 VISIT_END( CatchClause, node ); 980 } 981 982 //-------------------------------------------------------------------------- 983 // FinallyClause 984 template< typename core_t > 985 const ast::FinallyClause * ast::Pass< core_t >::visit( const ast::FinallyClause * node ) { 986 VISIT_START( node ); 987 988 if ( __visit_children() ) { 989 maybe_accept( node, &FinallyClause::body ); 990 } 991 992 VISIT_END( FinallyClause, node ); 993 993 } 994 994 … … 1054 1054 auto n = __pass::mutate<core_t>(node); 1055 1055 for(size_t i = 0; i < new_clauses.size(); i++) { 1056 if(new_clauses.at(i).target.func != nullptr) s td::swap(n->clauses.at(i).target.func, new_clauses.at(i).target.func);1056 if(new_clauses.at(i).target.func != nullptr) swap(n->clauses.at(i).target.func, new_clauses.at(i).target.func); 1057 1057 1058 1058 for(size_t j = 0; j < new_clauses.at(i).target.args.size(); j++) { 1059 if(new_clauses.at(i).target.args.at(j) != nullptr) s td::swap(n->clauses.at(i).target.args.at(j), new_clauses.at(i).target.args.at(j));1059 if(new_clauses.at(i).target.args.at(j) != nullptr) swap(n->clauses.at(i).target.args.at(j), new_clauses.at(i).target.args.at(j)); 1060 1060 } 1061 1061 1062 if(new_clauses.at(i).stmt != nullptr) s td::swap(n->clauses.at(i).stmt, new_clauses.at(i).stmt);1063 if(new_clauses.at(i).cond != nullptr) s td::swap(n->clauses.at(i).cond, new_clauses.at(i).cond);1062 if(new_clauses.at(i).stmt != nullptr) swap(n->clauses.at(i).stmt, new_clauses.at(i).stmt); 1063 if(new_clauses.at(i).cond != nullptr) swap(n->clauses.at(i).cond, new_clauses.at(i).cond); 1064 1064 } 1065 1065 node = n; … … 2151 2151 2152 2152 if ( __visit_children() ) { 2153 { 2154 bool mutated = false; 2155 std::unordered_map< ast::TypeInstType::TypeEnvKey, ast::ptr< ast::Type > > new_map; 2156 for ( const auto & p : node->typeEnv ) { 2157 guard_symtab guard { *this }; 2158 auto new_node = p.second->accept( *this ); 2159 if (new_node != p.second) mutated = true; 2160 new_map.insert({ p.first, new_node }); 2161 } 2162 if (mutated) { 2163 auto new_node = __pass::mutate<core_t>( node ); 2164 new_node->typeEnv.swap( new_map ); 2165 node = new_node; 2166 } 2153 bool mutated = false; 2154 std::unordered_map< ast::TypeInstType::TypeEnvKey, ast::ptr< ast::Type > > new_map; 2155 for ( const auto & p : node->typeEnv ) { 2156 guard_symtab guard { *this }; 2157 auto new_node = p.second->accept( *this ); 2158 if (new_node != p.second) mutated = true; 2159 new_map.insert({ p.first, new_node }); 2160 } 2161 if (mutated) { 2162 auto new_node = __pass::mutate<core_t>( node ); 2163 new_node->typeEnv.swap( new_map ); 2164 node = new_node; 2167 2165 } 2168 2166 } -
src/AST/Print.cpp
r4559b34 r92538ab 597 597 598 598 ++indent; 599 for ( const ast:: Stmt * stmt : node->stmts ) {599 for ( const ast::CaseClause * stmt : node->cases ) { 600 600 stmt->accept( *this ); 601 601 } … … 605 605 } 606 606 607 virtual const ast:: Stmt * visit( const ast::CaseStmt* node ) override final {607 virtual const ast::CaseClause * visit( const ast::CaseClause * node ) override final { 608 608 if ( node->isDefault() ) { 609 609 os << indent << "Default "; … … 687 687 688 688 os << indent-1 << "... and handlers:" << endl; 689 for ( const ast::Catch Stmt* stmt : node->handlers ) {689 for ( const ast::CatchClause * stmt : node->handlers ) { 690 690 os << indent; 691 691 stmt->accept( *this ); … … 701 701 } 702 702 703 virtual const ast:: Stmt * visit( const ast::CatchStmt* node ) override final {703 virtual const ast::CatchClause * visit( const ast::CatchClause * node ) override final { 704 704 os << "Catch "; 705 705 switch ( node->kind ) { … … 726 726 } 727 727 728 virtual const ast:: Stmt * visit( const ast::FinallyStmt* node ) override final {728 virtual const ast::FinallyClause * visit( const ast::FinallyClause * node ) override final { 729 729 os << "Finally Statement" << endl; 730 730 os << indent << "... with block:" << endl; -
src/AST/Stmt.hpp
r4559b34 r92538ab 9 9 // Author : Aaron B. Moss 10 10 // Created On : Wed May 8 13:00:00 2019 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Wed Feb 2 20:06:41202213 // Update Count : 3 411 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Mar 28 9:50:00 2022 13 // Update Count : 35 14 14 // 15 15 … … 47 47 private: 48 48 Stmt * clone() const override = 0; 49 MUTATE_FRIEND 50 }; 51 52 // Base statement component node (only serves to group them). 53 class StmtClause : public ParseNode { 54 public: 55 // This is for non-statements that still belong with the statements, 56 // but are not statements, usually some sort of clause. Often these can 57 // (and should) be folded into the approprate parent node, but if they 58 // cannot be, they are sub-types of this type, for organization. 59 60 StmtClause( const CodeLocation & loc ) 61 : ParseNode(loc) {} 62 63 private: 64 StmtClause * clone() const override = 0; 49 65 MUTATE_FRIEND 50 66 }; … … 158 174 public: 159 175 ptr<Expr> cond; 176 std::vector<ptr<CaseClause>> cases; 177 178 SwitchStmt( const CodeLocation & loc, const Expr * cond, 179 const std::vector<ptr<CaseClause>> && cases, 180 const std::vector<Label> && labels = {} ) 181 : Stmt(loc, std::move(labels)), cond(cond), cases(std::move(cases)) {} 182 183 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 184 private: 185 SwitchStmt * clone() const override { return new SwitchStmt{ *this }; } 186 MUTATE_FRIEND 187 }; 188 189 // Case label: case ...: or default: 190 class CaseClause final : public StmtClause { 191 public: 192 // Null for the default label. 193 ptr<Expr> cond; 160 194 std::vector<ptr<Stmt>> stmts; 161 195 162 SwitchStmt( const CodeLocation & loc, const Expr * cond, const std::vector<ptr<Stmt>> && stmts, 163 const std::vector<Label> && labels = {} ) 164 : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {} 165 166 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 167 private: 168 SwitchStmt * clone() const override { return new SwitchStmt{ *this }; } 169 MUTATE_FRIEND 170 }; 171 172 // Case label: case ...: or default: 173 class CaseStmt final : public Stmt { 174 public: 175 // Null for the default label. 176 ptr<Expr> cond; 177 std::vector<ptr<Stmt>> stmts; 178 179 CaseStmt( const CodeLocation & loc, const Expr * cond, const std::vector<ptr<Stmt>> && stmts, 180 const std::vector<Label> && labels = {} ) 181 : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {} 196 CaseClause( const CodeLocation & loc, const Expr * cond, const std::vector<ptr<Stmt>> && stmts ) 197 : StmtClause(loc), cond(cond), stmts(std::move(stmts)) {} 182 198 183 199 bool isDefault() const { return !cond; } 184 200 185 const Stmt* accept( Visitor & v ) const override { return v.visit( this ); }186 private: 187 Case Stmt * clone() const override { return new CaseStmt{ *this }; }201 const CaseClause * accept( Visitor & v ) const override { return v.visit( this ); } 202 private: 203 CaseClause * clone() const override { return new CaseClause{ *this }; } 188 204 MUTATE_FRIEND 189 205 }; … … 298 314 public: 299 315 ptr<CompoundStmt> body; 300 std::vector<ptr<Catch Stmt>> handlers;301 ptr<Finally Stmt> finally;316 std::vector<ptr<CatchClause>> handlers; 317 ptr<FinallyClause> finally; 302 318 303 319 TryStmt( const CodeLocation & loc, const CompoundStmt * body, 304 const std::vector<ptr<Catch Stmt>> && handlers, const FinallyStmt* finally,320 const std::vector<ptr<CatchClause>> && handlers, const FinallyClause * finally, 305 321 const std::vector<Label> && labels = {} ) 306 322 : Stmt(loc, std::move(labels)), body(body), handlers(std::move(handlers)), finally(finally) {} … … 313 329 314 330 // Catch clause of try statement 315 class Catch Stmt final : public Stmt{331 class CatchClause final : public StmtClause { 316 332 public: 317 333 ptr<Decl> decl; … … 320 336 ExceptionKind kind; 321 337 322 Catch Stmt( const CodeLocation & loc, ExceptionKind kind, const Decl * decl, const Expr * cond,323 const Stmt * body , const std::vector<Label> && labels = {})324 : Stmt (loc, std::move(labels)), decl(decl), cond(cond), body(body), kind(kind) {}325 326 const Stmt* accept( Visitor & v ) const override { return v.visit( this ); }327 private: 328 Catch Stmt * clone() const override { return new CatchStmt{ *this }; }338 CatchClause( const CodeLocation & loc, ExceptionKind kind, const Decl * decl, const Expr * cond, 339 const Stmt * body ) 340 : StmtClause(loc), decl(decl), cond(cond), body(body), kind(kind) {} 341 342 const CatchClause * accept( Visitor & v ) const override { return v.visit( this ); } 343 private: 344 CatchClause * clone() const override { return new CatchClause{ *this }; } 329 345 MUTATE_FRIEND 330 346 }; 331 347 332 348 // Finally clause of try statement 333 class Finally Stmt final : public Stmt{349 class FinallyClause final : public StmtClause { 334 350 public: 335 351 ptr<CompoundStmt> body; 336 352 337 FinallyStmt( const CodeLocation & loc, const CompoundStmt * body, 338 std::vector<Label> && labels = {} ) 339 : Stmt(loc, std::move(labels)), body(body) {} 340 341 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 342 private: 343 FinallyStmt * clone() const override { return new FinallyStmt{ *this }; } 353 FinallyClause( const CodeLocation & loc, const CompoundStmt * body ) 354 : StmtClause(loc), body(body) {} 355 356 const FinallyClause * accept( Visitor & v ) const override { return v.visit( this ); } 357 private: 358 FinallyClause * clone() const override { return new FinallyClause{ *this }; } 344 359 MUTATE_FRIEND 345 360 }; -
src/AST/TranslationUnit.hpp
r4559b34 r92538ab 10 10 // Created On : Tue Jun 11 15:30:00 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tue Jun 11 15:42:00 201913 // Update Count : 012 // Last Modified On : Tue Mar 11 11:19:00 2022 13 // Update Count : 1 14 14 // 15 15 … … 23 23 namespace ast { 24 24 25 class TranslationGlobal { 26 public: 27 std::map< UniqueId, Decl * > idMap; 28 29 ptr<Type> sizeType; 30 const FunctionDecl * dereference; 31 const StructDecl * dtorStruct; 32 const FunctionDecl * dtorDestroy; 33 }; 34 25 35 class TranslationUnit { 26 36 public: 27 37 std::list< ptr< Decl > > decls; 28 29 struct Global { 30 std::map< UniqueId, Decl * > idMap; 31 32 ptr<Type> sizeType; 33 const FunctionDecl * dereference; 34 const StructDecl * dtorStruct; 35 const FunctionDecl * dtorDestroy; 36 } global; 38 TranslationGlobal global; 37 39 }; 38 40 -
src/AST/Type.cpp
r4559b34 r92538ab 147 147 // --- TypeInstType 148 148 149 TypeInstType::TypeInstType( const TypeDecl * b, 150 CV::Qualifiers q, std::vector<ptr<Attribute>> && as ) 151 : BaseInstType( b->name, q, move(as) ), base( b ), kind( b->kind ) {} 152 149 153 void TypeInstType::set_base( const TypeDecl * b ) { 150 154 base = b; -
src/AST/Type.hpp
r4559b34 r92538ab 421 421 std::vector<ptr<Attribute>> && as = {} ) 422 422 : BaseInstType( n, q, std::move(as) ), base( b ), kind( b->kind ) {} 423 424 TypeInstType( const TypeDecl * b, 425 CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} ); 426 423 427 TypeInstType( const std::string& n, TypeDecl::Kind k, CV::Qualifiers q = {}, 424 428 std::vector<ptr<Attribute>> && as = {} ) -
src/AST/TypeSubstitution.hpp
r4559b34 r92538ab 37 37 public: 38 38 TypeSubstitution(); 39 template< typename FormalContainer, typename ActualContainer > 40 TypeSubstitution( FormalContainer formals, ActualContainer actuals ); 39 41 template< typename FormalIterator, typename ActualIterator > 40 42 TypeSubstitution( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ); … … 76 78 bool empty() const; 77 79 80 template< typename FormalContainer, typename ActualContainer > 81 void addAll( FormalContainer formals, ActualContainer actuals ); 78 82 template< typename FormalIterator, typename ActualIterator > 79 void add ( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin );83 void addAll( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ); 80 84 81 85 /// create a new TypeSubstitution using bindings from env containing all of the type variables in expr … … 112 116 }; 113 117 118 template< typename FormalContainer, typename ActualContainer > 119 TypeSubstitution::TypeSubstitution( FormalContainer formals, ActualContainer actuals ) { 120 assert( formals.size() == actuals.size() ); 121 addAll( formals.begin(), formals.end(), actuals.begin() ); 122 } 123 124 template< typename FormalIterator, typename ActualIterator > 125 TypeSubstitution::TypeSubstitution( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ) { 126 addAll( formalBegin, formalEnd, actualBegin ); 127 } 128 129 template< typename FormalContainer, typename ActualContainer > 130 void TypeSubstitution::addAll( FormalContainer formals, ActualContainer actuals ) { 131 assert( formals.size() == actuals.size() ); 132 addAll( formals.begin(), formals.end(), actuals.begin() ); 133 } 134 114 135 // this is the only place where type parameters outside a function formal may be substituted. 115 136 template< typename FormalIterator, typename ActualIterator > 116 void TypeSubstitution::add ( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ) {137 void TypeSubstitution::addAll( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ) { 117 138 // FormalIterator points to a TypeDecl 118 139 // ActualIterator points to a Type … … 129 150 } // if 130 151 } else { 131 152 // Is this an error? 132 153 } // if 133 154 } // for 134 155 } 135 136 137 138 template< typename FormalIterator, typename ActualIterator >139 TypeSubstitution::TypeSubstitution( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ) {140 add( formalBegin, formalEnd, actualBegin );141 }142 143 156 144 157 } // namespace ast -
src/AST/Visitor.hpp
r4559b34 r92538ab 41 41 virtual const ast::Stmt * visit( const ast::ForStmt * ) = 0; 42 42 virtual const ast::Stmt * visit( const ast::SwitchStmt * ) = 0; 43 virtual const ast:: Stmt * visit( const ast::CaseStmt* ) = 0;43 virtual const ast::CaseClause * visit( const ast::CaseClause * ) = 0; 44 44 virtual const ast::Stmt * visit( const ast::BranchStmt * ) = 0; 45 45 virtual const ast::Stmt * visit( const ast::ReturnStmt * ) = 0; 46 46 virtual const ast::Stmt * visit( const ast::ThrowStmt * ) = 0; 47 47 virtual const ast::Stmt * visit( const ast::TryStmt * ) = 0; 48 virtual const ast:: Stmt * visit( const ast::CatchStmt* ) = 0;49 virtual const ast:: Stmt * visit( const ast::FinallyStmt* ) = 0;48 virtual const ast::CatchClause * visit( const ast::CatchClause * ) = 0; 49 virtual const ast::FinallyClause * visit( const ast::FinallyClause * ) = 0; 50 50 virtual const ast::Stmt * visit( const ast::SuspendStmt * ) = 0; 51 51 virtual const ast::Stmt * visit( const ast::WaitForStmt * ) = 0; -
src/AST/module.mk
r4559b34 r92538ab 16 16 17 17 SRC_AST = \ 18 AST/AssertAcyclic.cpp \19 AST/AssertAcyclic.hpp \20 18 AST/Attribute.cpp \ 21 19 AST/Attribute.hpp \ … … 64 62 AST/TypeSubstitution.cpp \ 65 63 AST/TypeSubstitution.hpp \ 64 AST/Util.cpp \ 65 AST/Util.hpp \ 66 66 AST/Visitor.hpp 67 67
Note:
See TracChangeset
for help on using the changeset viewer.