- Timestamp:
- Nov 24, 2021, 9:47:56 PM (4 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
- Children:
- 5235d49
- Parents:
- 94647b0b (diff), 3cc1111 (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:
-
- 1 added
- 11 edited
-
Convert.cpp (modified) (2 diffs)
-
Copy.cpp (added)
-
Copy.hpp (modified) (3 diffs)
-
Decl.hpp (modified) (2 diffs)
-
Init.hpp (modified) (1 diff)
-
Pass.hpp (modified) (4 diffs)
-
Pass.impl.hpp (modified) (1 diff)
-
Pass.proto.hpp (modified) (1 diff)
-
Stmt.hpp (modified) (1 diff)
-
TranslationUnit.hpp (modified) (1 diff)
-
module.mk (modified) (1 diff)
-
porting.md (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r94647b0b r7770cc8 1041 1041 1042 1042 const ast::Expr * visit( const ast::StmtExpr * node ) override final { 1043 auto stmts = node->stmts;1044 // disable sharing between multiple StmtExprs explicitly.1045 // this should no longer be true.1046 1047 1043 auto rslt = new StmtExpr( 1048 get<CompoundStmt>().accept1( stmts)1044 get<CompoundStmt>().accept1(node->stmts) 1049 1045 ); 1050 1046 1051 1047 rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls); 1052 1048 rslt->dtors = get<Expression>().acceptL(node->dtors); 1053 if (node->resultExpr) { 1054 // this MUST be found by children visit 1055 rslt->resultExpr = strict_dynamic_cast<ExprStmt *>(readonlyCache.at(node->resultExpr)); 1056 } 1049 1050 // is this even used after convert? 1051 //if (tmp->resultExpr) { 1052 // // this MUST be found by children visit 1053 // rslt->resultExpr = strict_dynamic_cast<ExprStmt *>(readonlyCache.at(tmp->resultExpr)); 1054 //} 1057 1055 1058 1056 auto expr = visitBaseExpr( node, rslt ); … … 1446 1444 1447 1445 std::list< Declaration * > convert( const ast::TranslationUnit && translationUnit ) { 1446 // Copy values from the global store to the local static variables. 1447 ast::sizeType = translationUnit.global.sizeType; 1448 ast::dereferenceOperator = translationUnit.global.dereference; 1449 ast::dtorStruct = translationUnit.global.dtorStruct; 1450 ast::dtorStructDestroy = translationUnit.global.dtorDestroy; 1451 1448 1452 ConverterNewToOld c; 1449 1453 std::list< Declaration * > decls; -
src/AST/Copy.hpp
r94647b0b r7770cc8 10 10 // Created On : Wed Jul 10 16:13:00 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Jun 19 16:43:00 202013 // Update Count : 112 // Last Modified On : Thr Nov 11 9:22:00 2021 13 // Update Count : 2 14 14 // 15 15 16 16 #pragma once 17 17 18 #include "Decl.hpp" 19 #include "Expr.hpp" 20 #include "Pass.hpp" 21 #include "Stmt.hpp" 22 #include "Type.hpp" 23 #include <unordered_set> 24 #include <unordered_map> 18 #include "Node.hpp" 19 #include <cassert> 25 20 26 21 namespace ast { … … 43 38 */ 44 39 45 class DeepCopyCore { 46 std::unordered_map< const Node *, const Node * > nodeCache; 47 std::unordered_set< readonly<Node> * > readonlyCache; 48 49 template<typename node_t> 50 void readonlyInsert( const readonly<node_t> * ptrptr ) { 51 readonlyCache.insert( (readonly<Node> *) ptrptr ); 52 } 53 54 public: 55 template<typename node_t> 56 const node_t * previsit( const node_t * node ) { 57 const node_t * copy = shallowCopy( node ); 58 nodeCache.insert( std::make_pair( node, copy ) ); 59 return copy; 60 } 61 62 void postvisit( const AggregateDecl * node ) { 63 readonlyInsert( &node->parent ); 64 } 65 66 void postvisit( const StructInstType * node ) { 67 readonlyInsert( &node->base ); 68 } 69 70 void postvisit( const UnionInstType * node ) { 71 readonlyInsert( &node->base ); 72 } 73 74 void postvisit( const EnumInstType * node ) { 75 readonlyInsert( &node->base ); 76 } 77 78 void postvisit( const TraitInstType * node ) { 79 readonlyInsert( &node->base ); 80 } 81 82 void postvisit( const TypeInstType * node ) { 83 readonlyInsert( &node->base ); 84 } 85 86 void postvisit( const ImplicitCtorDtorStmt * node ) { 87 readonlyInsert( (const readonly<Stmt> *) &node->callStmt ); 88 } 89 90 void postvisit( const MemberExpr * node ) { 91 readonlyInsert( &node->member ); 92 } 93 94 void postvisit( const VariableExpr * node ) { 95 readonlyInsert( &node->var ); 96 } 97 98 void postvisit( const OffsetofExpr * node ) { 99 readonlyInsert( &node->member ); 100 } 101 102 void postvisit( const DeletedExpr * node ) { 103 readonlyInsert( &node->deleteStmt ); 104 } 105 106 void readonlyUpdates() { 107 for ( readonly<Node> * ptr : readonlyCache ) { 108 auto it = nodeCache.find( ptr->get() ); 109 if ( nodeCache.end() != it ) { 110 *ptr = it->second; 111 } 112 } 113 } 114 }; 115 40 // Implementations: 116 41 template<typename node_t> 117 42 node_t * shallowCopy( const node_t * localRoot ) { … … 121 46 template<typename node_t> 122 47 node_t * deepCopy( const node_t * localRoot ) { 123 Pass< DeepCopyCore > dc; 124 node_t const * newRoot = localRoot->accept( dc ); 125 dc.core.readonlyUpdates(); 126 return const_cast< node_t * >( newRoot ); 48 return strict_dynamic_cast<node_t *>( deepCopy<Node>( localRoot ) ); 127 49 } 50 51 template<> 52 Node * deepCopy<Node>( const Node * localRoot ); 128 53 129 54 } -
src/AST/Decl.hpp
r94647b0b r7770cc8 131 131 // declared type, derived from parameter declarations 132 132 ptr<FunctionType> type; 133 /// Null for the forward declaration of a function. 133 134 ptr<CompoundStmt> stmts; 134 135 std::vector< ptr<Expr> > withExprs; … … 269 270 : AggregateDecl( loc, name, std::move(attrs), linkage ), kind( kind ) {} 270 271 271 bool is_coroutine() { return kind == Coroutine; }272 bool is_generator() { return kind == Generator; }273 bool is_monitor () { return kind == Monitor ; }274 bool is_thread () { return kind == Thread ; }272 bool is_coroutine() const { return kind == Coroutine; } 273 bool is_generator() const { return kind == Generator; } 274 bool is_monitor () const { return kind == Monitor ; } 275 bool is_thread () const { return kind == Thread ; } 275 276 276 277 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } -
src/AST/Init.hpp
r94647b0b r7770cc8 98 98 const_iterator begin() const { return initializers.begin(); } 99 99 const_iterator end() const { return initializers.end(); } 100 size_t size() const { return initializers.size(); } 100 101 101 102 const Init * accept( Visitor & v ) const override { return v.visit( this ); } -
src/AST/Pass.hpp
r94647b0b r7770cc8 109 109 static auto read( node_type const * node, Args&&... args ) { 110 110 Pass<core_t> visitor( std::forward<Args>( args )... ); 111 node_typeconst * temp = node->accept( visitor );111 auto const * temp = node->accept( visitor ); 112 112 assert( temp == node ); 113 113 return visitor.get_result(); … … 124 124 static auto read( node_type const * node ) { 125 125 Pass<core_t> visitor; 126 node_typeconst * temp = node->accept( visitor );126 auto const * temp = node->accept( visitor ); 127 127 assert( temp == node ); 128 128 return visitor.get_result(); … … 348 348 349 349 /// When this node is finished being visited, restore the value of a variable 350 /// You may assign to the return value to set the new value in the same statement. 350 351 template< typename T > 351 voidGuardValue( T& val ) {352 T& GuardValue( T& val ) { 352 353 at_cleanup( [ val ]( void * newVal ) { 353 354 * static_cast< T * >( newVal ) = val; 354 355 }, static_cast< void * >( & val ) ); 356 return val; 355 357 } 356 358 … … 394 396 }; 395 397 398 /// Used to get a pointer to the wrapping TranslationUnit. 399 struct WithConstTranslationUnit { 400 const TranslationUnit * translationUnit = nullptr; 401 402 const TranslationUnit & transUnit() const { 403 assertf( translationUnit, "WithConstTranslationUnit not set-up." ); 404 return *translationUnit; 405 } 406 }; 407 396 408 } 397 409 -
src/AST/Pass.impl.hpp
r94647b0b r7770cc8 420 420 template< typename core_t > 421 421 inline void ast::accept_all( ast::TranslationUnit & unit, ast::Pass< core_t > & visitor ) { 422 return ast::accept_all( unit.decls, visitor ); 422 if ( auto ptr = __pass::translation_unit::get_cptr( visitor.core, 0 ) ) { 423 ValueGuard<const TranslationUnit *> guard( *ptr ); 424 *ptr = &unit; 425 return ast::accept_all( unit.decls, visitor ); 426 } else { 427 return ast::accept_all( unit.decls, visitor ); 428 } 423 429 } 424 430 -
src/AST/Pass.proto.hpp
r94647b0b r7770cc8 426 426 } // namespace forall 427 427 428 // For passes that need access to the global context. Sreaches `translationUnit` 429 namespace translation_unit { 430 template<typename core_t> 431 static inline auto get_cptr( core_t & core, int ) 432 -> decltype( &core.translationUnit ) { 433 return &core.translationUnit; 434 } 435 436 template<typename core_t> 437 static inline const TranslationUnit ** get_cptr( core_t &, long ) { 438 return nullptr; 439 } 440 } 441 428 442 template<typename core_t> 429 443 static inline auto get_result( core_t & core, char ) -> decltype( core.result() ) { -
src/AST/Stmt.hpp
r94647b0b r7770cc8 175 175 class CaseStmt final : public Stmt { 176 176 public: 177 /// Null for the default label. 177 178 ptr<Expr> cond; 178 179 std::vector<ptr<Stmt>> stmts; -
src/AST/TranslationUnit.hpp
r94647b0b r7770cc8 26 26 std::list< ptr< Decl > > decls; 27 27 28 struct Global s{28 struct Global { 29 29 std::map< UniqueId, Decl * > idMap; 30 30 31 const Type *sizeType;31 ptr<Type> sizeType; 32 32 const FunctionDecl * dereference; 33 33 const StructDecl * dtorStruct; -
src/AST/module.mk
r94647b0b r7770cc8 24 24 AST/Convert.cpp \ 25 25 AST/Convert.hpp \ 26 AST/Copy.cpp \ 26 27 AST/Copy.hpp \ 27 28 AST/CVQualifiers.hpp \ -
src/AST/porting.md
r94647b0b r7770cc8 98 98 * `Initializer` => `ast::Init` 99 99 * `Statement` => `ast::Stmt` 100 * `ReferenceToType` => `ast::BaseInstType` 100 101 * any field names should follow a similar renaming 101 102 * because they don't really belong to `Type` (and for consistency with `Linkage::Spec`):
Note:
See TracChangeset
for help on using the changeset viewer.