- Timestamp:
- Jul 13, 2023, 9:37:22 PM (14 months ago)
- Branches:
- master
- Children:
- b7c53a9d
- Parents:
- 09e400e (diff), a3c7bac (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
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Pass.impl.hpp
r09e400e r4acf56d 53 53 #endif 54 54 55 namespace ast { 55 namespace ast::__pass { 56 // Check if this is either a null pointer or a pointer to an empty container 57 template<typename T> 58 static inline bool empty( T * ptr ) { 59 return !ptr || ptr->empty(); 60 } 61 62 template< typename core_t, typename node_t > 63 static inline node_t* mutate(const node_t *node) { 64 return std::is_base_of<PureVisitor, core_t>::value ? ::ast::shallowCopy(node) : ::ast::mutate(node); 65 } 66 67 //------------------------------ 68 template<typename it_t, template <class...> class container_t> 69 static inline void take_all( it_t it, container_t<ast::ptr<ast::Decl>> * decls, bool * mutated = nullptr ) { 70 if ( empty( decls ) ) return; 71 72 std::transform(decls->begin(), decls->end(), it, [](const ast::Decl * decl) -> auto { 73 return new DeclStmt( decl->location, decl ); 74 }); 75 decls->clear(); 76 if ( mutated ) *mutated = true; 77 } 78 79 template<typename it_t, template <class...> class container_t> 80 static inline void take_all( it_t it, container_t<ast::ptr<ast::Stmt>> * stmts, bool * mutated = nullptr ) { 81 if ( empty( stmts ) ) return; 82 83 std::move(stmts->begin(), stmts->end(), it); 84 stmts->clear(); 85 if ( mutated ) *mutated = true; 86 } 87 88 //------------------------------ 89 /// Check if should be skipped, different for pointers and containers 56 90 template<typename node_t> 57 node_t * shallowCopy( const node_t * node ); 58 59 namespace __pass { 60 // Check if this is either a null pointer or a pointer to an empty container 61 template<typename T> 62 static inline bool empty( T * ptr ) { 63 return !ptr || ptr->empty(); 64 } 65 66 template< typename core_t, typename node_t > 67 static inline node_t* mutate(const node_t *node) { 68 return std::is_base_of<PureVisitor, core_t>::value ? ::ast::shallowCopy(node) : ::ast::mutate(node); 69 } 70 71 //------------------------------ 72 template<typename it_t, template <class...> class container_t> 73 static inline void take_all( it_t it, container_t<ast::ptr<ast::Decl>> * decls, bool * mutated = nullptr ) { 74 if ( empty( decls ) ) return; 75 76 std::transform(decls->begin(), decls->end(), it, [](const ast::Decl * decl) -> auto { 77 return new DeclStmt( decl->location, decl ); 78 }); 79 decls->clear(); 80 if ( mutated ) *mutated = true; 81 } 82 83 template<typename it_t, template <class...> class container_t> 84 static inline void take_all( it_t it, container_t<ast::ptr<ast::Stmt>> * stmts, bool * mutated = nullptr ) { 85 if ( empty( stmts ) ) return; 86 87 std::move(stmts->begin(), stmts->end(), it); 88 stmts->clear(); 89 if ( mutated ) *mutated = true; 90 } 91 92 //------------------------------ 93 /// Check if should be skipped, different for pointers and containers 94 template<typename node_t> 95 bool skip( const ast::ptr<node_t> & val ) { 96 return !val; 97 } 98 99 template< template <class...> class container_t, typename node_t > 100 bool skip( const container_t<ast::ptr< node_t >> & val ) { 101 return val.empty(); 102 } 103 104 //------------------------------ 105 /// Get the value to visit, different for pointers and containers 106 template<typename node_t> 107 auto get( const ast::ptr<node_t> & val, int ) -> decltype(val.get()) { 108 return val.get(); 109 } 110 111 template<typename node_t> 112 const node_t & get( const node_t & val, long ) { 113 return val; 114 } 115 116 //------------------------------ 117 /// Check if value was mutated, different for pointers and containers 118 template<typename lhs_t, typename rhs_t> 119 bool differs( const lhs_t * old_val, const rhs_t * new_val ) { 120 return old_val != new_val; 121 } 122 123 template< template <class...> class container_t, typename node_t > 124 bool differs( const container_t<ast::ptr< node_t >> &, const container_t<ast::ptr< node_t >> & new_val ) { 125 return !new_val.empty(); 126 } 91 bool skip( const ast::ptr<node_t> & val ) { 92 return !val; 93 } 94 95 template< template <class...> class container_t, typename node_t > 96 bool skip( const container_t<ast::ptr< node_t >> & val ) { 97 return val.empty(); 98 } 99 100 //------------------------------ 101 /// Get the value to visit, different for pointers and containers 102 template<typename node_t> 103 auto get( const ast::ptr<node_t> & val, int ) -> decltype(val.get()) { 104 return val.get(); 105 } 106 107 template<typename node_t> 108 const node_t & get( const node_t & val, long ) { 109 return val; 110 } 111 112 //------------------------------ 113 /// Check if value was mutated, different for pointers and containers 114 template<typename lhs_t, typename rhs_t> 115 bool differs( const lhs_t * old_val, const rhs_t * new_val ) { 116 return old_val != new_val; 117 } 118 119 template< template <class...> class container_t, typename node_t > 120 bool differs( const container_t<ast::ptr< node_t >> &, const container_t<ast::ptr< node_t >> & new_val ) { 121 return !new_val.empty(); 127 122 } 128 123 } … … 1920 1915 VISIT_START( node ); 1921 1916 1922 __pass::symtab::addStruct ( core, 0, node->name );1917 __pass::symtab::addStructId( core, 0, node->name ); 1923 1918 1924 1919 if ( __visit_children() ) { … … 1936 1931 VISIT_START( node ); 1937 1932 1938 __pass::symtab::addUnion ( core, 0, node->name );1933 __pass::symtab::addUnionId( core, 0, node->name ); 1939 1934 1940 1935 if ( __visit_children() ) { -
src/AST/Pass.proto.hpp
r09e400e r4acf56d 488 488 489 489 template<typename core_t> 490 static inline auto addStruct ( core_t & core, int, const std::string & str ) -> decltype( core.symtab.addStruct( str ), void() ) {490 static inline auto addStructId( core_t & core, int, const std::string & str ) -> decltype( core.symtab.addStructId( str ), void() ) { 491 491 if ( ! core.symtab.lookupStruct( str ) ) { 492 core.symtab.addStruct ( str );493 } 494 } 495 496 template<typename core_t> 497 static inline void addStruct ( core_t &, long, const std::string & ) {}498 499 template<typename core_t> 500 static inline auto addUnion ( core_t & core, int, const std::string & str ) -> decltype( core.symtab.addUnion( str ), void() ) {492 core.symtab.addStructId( str ); 493 } 494 } 495 496 template<typename core_t> 497 static inline void addStructId( core_t &, long, const std::string & ) {} 498 499 template<typename core_t> 500 static inline auto addUnionId( core_t & core, int, const std::string & str ) -> decltype( core.symtab.addUnionId( str ), void() ) { 501 501 if ( ! core.symtab.lookupUnion( str ) ) { 502 core.symtab.addUnion ( str );503 } 504 } 505 506 template<typename core_t> 507 static inline void addUnion ( core_t &, long, const std::string & ) {}502 core.symtab.addUnionId( str ); 503 } 504 } 505 506 template<typename core_t> 507 static inline void addUnionId( core_t &, long, const std::string & ) {} 508 508 509 509 #undef SYMTAB_FUNC1 -
src/AST/SymbolTable.cpp
r09e400e r4acf56d 323 323 } 324 324 325 void SymbolTable::addStruct ( const std::string &id ) {325 void SymbolTable::addStructId( const std::string &id ) { 326 326 addStruct( new StructDecl( CodeLocation(), id ) ); 327 327 } … … 365 365 } 366 366 367 void SymbolTable::addUnion ( const std::string &id ) {367 void SymbolTable::addUnionId( const std::string &id ) { 368 368 addUnion( new UnionDecl( CodeLocation(), id ) ); 369 369 } -
src/AST/SymbolTable.hpp
r09e400e r4acf56d 150 150 void addType( const NamedTypeDecl * decl ); 151 151 /// Adds a struct declaration to the symbol table by name 152 void addStruct ( const std::string & id );152 void addStructId( const std::string & id ); 153 153 /// Adds a struct declaration to the symbol table 154 154 void addStruct( const StructDecl * decl ); … … 156 156 void addEnum( const EnumDecl * decl ); 157 157 /// Adds a union declaration to the symbol table by name 158 void addUnion ( const std::string & id );158 void addUnionId( const std::string & id ); 159 159 /// Adds a union declaration to the symbol table 160 160 void addUnion( const UnionDecl * decl ); -
src/Validate/NoIdSymbolTable.hpp
r09e400e r4acf56d 46 46 FORWARD_1( addUnion , const ast::UnionDecl * ) 47 47 FORWARD_1( addTrait , const ast::TraitDecl * ) 48 FORWARD_1( addStruct, const std::string & )49 FORWARD_1( addUnion , const std::string & )50 48 FORWARD_2( addWith , const std::vector< ast::ptr<ast::Expr> > &, const ast::Decl * ) 49 FORWARD_1( addStructId, const std::string & ) 50 FORWARD_1( addUnionId , const std::string & ) 51 51 52 52 FORWARD_1( globalLookupType, const std::string & )
Note: See TracChangeset
for help on using the changeset viewer.