- Timestamp:
- Feb 23, 2022, 11:24:34 AM (4 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
- Children:
- 08ed947
- Parents:
- f5a51db (diff), 3a038fa (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
- 8 edited
-
AssertAcyclic.cpp (deleted)
-
AssertAcyclic.hpp (deleted)
-
Convert.hpp (modified) (1 diff)
-
Decl.cpp (modified) (1 diff)
-
Fwd.hpp (modified) (1 diff)
-
Pass.hpp (modified) (1 diff)
-
Pass.impl.hpp (modified) (13 diffs)
-
Pass.proto.hpp (modified) (2 diffs)
-
TranslationUnit.hpp (modified) (1 diff)
-
Util.cpp (added)
-
Util.hpp (added)
-
module.mk (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.hpp
rf5a51db rcc7bbe6 20 20 class Declaration; 21 21 namespace ast { 22 structTranslationUnit;22 class TranslationUnit; 23 23 }; 24 24 -
src/AST/Decl.cpp
rf5a51db rcc7bbe6 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; -
src/AST/Fwd.hpp
rf5a51db rcc7bbe6 140 140 typedef unsigned int UniqueId; 141 141 142 structTranslationUnit;142 class TranslationUnit; 143 143 // TODO: Get from the TranslationUnit: 144 144 extern ptr<Type> sizeType; -
src/AST/Pass.hpp
rf5a51db rcc7bbe6 239 239 private: 240 240 241 // Regular nodes 241 __pass::result1<ast::Stmt> call_accept( const ast::Stmt * ); 242 __pass::result1<ast::Expr> call_accept( const ast::Expr * ); 243 244 /// This has a `type` member that is the return type for the 245 /// generic call_accept if the generic call_accept is defined. 242 246 template< typename node_t > 243 struct result1 { 244 bool differs; 245 const node_t * value; 246 247 template< typename object_t, typename super_t, typename field_t > 248 void apply(object_t *, field_t super_t::* field); 249 }; 250 251 result1<ast::Stmt> call_accept( const ast::Stmt * ); 252 result1<ast::Expr> call_accept( const ast::Expr * ); 247 using generic_call_accept_result = 248 std::enable_if< 249 !std::is_base_of<ast::Expr, node_t>::value && 250 !std::is_base_of<ast::Stmt, node_t>::value 251 , __pass::result1< 252 typename std::remove_pointer< typename std::result_of< 253 decltype(&node_t::accept)(node_t*, type&) >::type >::type 254 > 255 >; 253 256 254 257 template< typename node_t > 255 258 auto call_accept( const node_t * node ) 256 -> typename std::enable_if< 257 !std::is_base_of<ast::Expr, node_t>::value && 258 !std::is_base_of<ast::Stmt, node_t>::value 259 , result1< 260 typename std::remove_pointer< decltype( node->accept(*this) ) >::type 261 > 262 >::type; 259 -> typename generic_call_accept_result<node_t>::type; 263 260 264 261 // requests WithStmtsToAdd directly add to this statement, as if it is a compound. 265 result1<ast::Stmt> call_accept_as_compound(const ast::Stmt *); 266 267 template<typename it_t, template <class...> class container_t> 268 static inline void take_all_delta( it_t it, container_t<ast::ptr<ast::Decl>> * decls, bool * mutated = nullptr ) { 269 if(empty(decls)) return; 270 271 std::transform(decls->begin(), decls->end(), it, [](ast::ptr<ast::Decl>&& decl) -> auto { 272 auto loc = decl->location; 273 auto stmt = new DeclStmt( loc, decl.release() ); 274 return { {stmt}, -1, false }; 275 }); 276 decls->clear(); 277 if(mutated) *mutated = true; 278 } 279 280 // Container of statements 262 __pass::result1<ast::Stmt> call_accept_as_compound(const ast::Stmt *); 263 281 264 template< template <class...> class container_t > 282 struct resultNstmt { 283 struct delta { 284 ptr<Stmt> nval; 285 ssize_t old_idx; 286 bool is_old; 287 288 delta(const Stmt * s, ssize_t i, bool old) : nval{s}, old_idx{i}, is_old{old} {} 289 }; 290 291 bool differs; 292 container_t< delta > values; 293 294 resultNstmt() : differs(false), values{} {} 295 resultNstmt(bool diff, container_t< delta > && vals) : differs(diff), values(vals) {} 296 297 template< typename object_t, typename super_t, typename field_t > 298 void apply(object_t *, field_t super_t::* field); 299 300 template< template <class...> class incontainer_t > 301 void take_all( incontainer_t<ast::ptr<ast::Stmt>> * stmts ) { 302 if(!stmts || stmts->empty()) return; 303 304 std::transform(stmts->begin(), stmts->end(), std::back_inserter( values ), [](ast::ptr<ast::Stmt>& decl) -> delta { 305 return delta( decl.release(), -1, false ); 306 }); 307 stmts->clear(); 308 differs = true; 309 } 310 311 template< template <class...> class incontainer_t > 312 void take_all( incontainer_t<ast::ptr<ast::Decl>> * decls ) { 313 if(!decls || decls->empty()) return; 314 315 std::transform(decls->begin(), decls->end(), std::back_inserter( values ), [](ast::ptr<ast::Decl>& decl) -> auto { 316 auto loc = decl->location; 317 auto stmt = new DeclStmt( loc, decl.release() ); 318 return delta( stmt, -1, false ); 319 }); 320 decls->clear(); 321 differs = true; 322 } 323 }; 324 325 template< template <class...> class container_t > 326 resultNstmt<container_t> call_accept( const container_t< ptr<Stmt> > & ); 327 328 // Container of something 265 __pass::resultNstmt<container_t> call_accept( const container_t< ptr<Stmt> > & ); 266 329 267 template< template <class...> class container_t, typename node_t > 330 struct resultN { 331 bool differs; 332 container_t<ptr<node_t>> values; 333 334 template< typename object_t, typename super_t, typename field_t > 335 void apply(object_t *, field_t super_t::* field); 336 }; 337 338 template< template <class...> class container_t, typename node_t > 339 resultN< container_t, node_t > call_accept( const container_t< ptr<node_t> > & container ); 268 __pass::resultN< container_t, node_t > call_accept( const container_t< ptr<node_t> > & container ); 340 269 341 270 public: -
src/AST/Pass.impl.hpp
rf5a51db rcc7bbe6 111 111 } 112 112 113 114 113 //------------------------------ 115 114 /// Check if value was mutated, different for pointers and containers … … 125 124 } 126 125 127 128 template< typename core_t >129 126 template< typename node_t > 130 127 template< typename object_t, typename super_t, typename field_t > 131 void ast::Pass< core_t >::result1< node_t >::apply(object_t * object, field_t super_t::* field) {128 void __pass::result1< node_t >::apply( object_t * object, field_t super_t::* field ) { 132 129 object->*field = value; 133 130 } … … 136 133 template< typename node_t > 137 134 auto ast::Pass< core_t >::call_accept( const node_t * node ) 138 -> typename std::enable_if< 139 !std::is_base_of<ast::Expr, node_t>::value && 140 !std::is_base_of<ast::Stmt, node_t>::value 141 , ast::Pass< core_t >::result1< 142 typename std::remove_pointer< decltype( node->accept(*this) ) >::type 143 > 144 >::type 135 -> typename ast::Pass< core_t >::template generic_call_accept_result<node_t>::type 145 136 { 146 137 __pedantic_pass_assert( __visit_children() ); … … 151 142 152 143 auto nval = node->accept( *this ); 153 ast::Pass< core_t >::result1<144 __pass::result1< 154 145 typename std::remove_pointer< decltype( node->accept(*this) ) >::type 155 146 > res; … … 160 151 161 152 template< typename core_t > 162 ast::Pass< core_t >::result1<ast::Expr> ast::Pass< core_t >::call_accept( const ast::Expr * expr ) {153 __pass::template result1<ast::Expr> ast::Pass< core_t >::call_accept( const ast::Expr * expr ) { 163 154 __pedantic_pass_assert( __visit_children() ); 164 155 __pedantic_pass_assert( expr ); … … 174 165 175 166 template< typename core_t > 176 ast::Pass< core_t >::result1<ast::Stmt> ast::Pass< core_t >::call_accept( const ast::Stmt * stmt ) {167 __pass::template result1<ast::Stmt> ast::Pass< core_t >::call_accept( const ast::Stmt * stmt ) { 177 168 __pedantic_pass_assert( __visit_children() ); 178 169 __pedantic_pass_assert( stmt ); … … 183 174 184 175 template< typename core_t > 185 ast::Pass< core_t >::result1<ast::Stmt> ast::Pass< core_t >::call_accept_as_compound( const ast::Stmt * stmt ) {176 __pass::template result1<ast::Stmt> ast::Pass< core_t >::call_accept_as_compound( const ast::Stmt * stmt ) { 186 177 __pedantic_pass_assert( __visit_children() ); 187 178 __pedantic_pass_assert( stmt ); … … 233 224 } 234 225 235 template< typename core_t >236 226 template< template <class...> class container_t > 237 227 template< typename object_t, typename super_t, typename field_t > 238 void ast::Pass< core_t >::resultNstmt<container_t>::apply(object_t * object, field_t super_t::* field) {228 void __pass::resultNstmt<container_t>::apply(object_t * object, field_t super_t::* field) { 239 229 auto & container = object->*field; 240 230 __pedantic_pass_assert( container.size() <= values.size() ); … … 243 233 244 234 container_t<ptr<Stmt>> nvals; 245 for (delta & d : values) {246 if ( d.is_old ) {235 for (delta & d : values) { 236 if ( d.is_old ) { 247 237 __pedantic_pass_assert( cit.idx <= d.old_idx ); 248 238 std::advance( cit, d.old_idx - cit.idx ); 249 239 nvals.push_back( std::move( (*cit).val) ); 250 240 } else { 251 nvals.push_back( std::move(d.n val) );241 nvals.push_back( std::move(d.new_val) ); 252 242 } 253 243 } 254 244 255 object->*field = std::move(nvals); 245 container = std::move(nvals); 246 } 247 248 template< template <class...> class container_t > 249 template< template <class...> class incontainer_t > 250 void __pass::resultNstmt< container_t >::take_all( incontainer_t<ptr<Stmt>> * stmts ) { 251 if (!stmts || stmts->empty()) return; 252 253 std::transform(stmts->begin(), stmts->end(), std::back_inserter( values ), 254 [](ast::ptr<ast::Stmt>& stmt) -> delta { 255 return delta( stmt.release(), -1, false ); 256 }); 257 stmts->clear(); 258 differs = true; 259 } 260 261 template< template<class...> class container_t > 262 template< template<class...> class incontainer_t > 263 void __pass::resultNstmt< container_t >::take_all( incontainer_t<ptr<Decl>> * decls ) { 264 if (!decls || decls->empty()) return; 265 266 std::transform(decls->begin(), decls->end(), std::back_inserter( values ), 267 [](ast::ptr<ast::Decl>& decl) -> delta { 268 auto loc = decl->location; 269 auto stmt = new DeclStmt( loc, decl.release() ); 270 return delta( stmt, -1, false ); 271 }); 272 decls->clear(); 273 differs = true; 256 274 } 257 275 258 276 template< typename core_t > 259 277 template< template <class...> class container_t > 260 ast::Pass< core_t >::resultNstmt<container_t> ast::Pass< core_t >::call_accept( const container_t< ptr<Stmt> > & statements ) {278 __pass::template resultNstmt<container_t> ast::Pass< core_t >::call_accept( const container_t< ptr<Stmt> > & statements ) { 261 279 __pedantic_pass_assert( __visit_children() ); 262 280 if( statements.empty() ) return {}; … … 285 303 pass_visitor_stats.avg->push(pass_visitor_stats.depth); 286 304 287 resultNstmt<container_t> new_kids;305 __pass::resultNstmt<container_t> new_kids; 288 306 for( auto value : enumerate( statements ) ) { 289 307 try { … … 327 345 } 328 346 329 template< typename core_t >330 347 template< template <class...> class container_t, typename node_t > 331 348 template< typename object_t, typename super_t, typename field_t > 332 void ast::Pass< core_t >::resultN<container_t, node_t>::apply(object_t * object, field_t super_t::* field) {349 void __pass::resultN<container_t, node_t>::apply(object_t * object, field_t super_t::* field) { 333 350 auto & container = object->*field; 334 351 __pedantic_pass_assert( container.size() == values.size() ); … … 346 363 template< typename core_t > 347 364 template< template <class...> class container_t, typename node_t > 348 ast::Pass< core_t >::resultN<container_t, node_t> ast::Pass< core_t >::call_accept( const container_t< ast::ptr<node_t> > & container ) {365 __pass::template resultN<container_t, node_t> ast::Pass< core_t >::call_accept( const container_t< ast::ptr<node_t> > & container ) { 349 366 __pedantic_pass_assert( __visit_children() ); 350 367 if( container.empty() ) return {}; … … 378 395 if ( ! errors.isEmpty() ) { throw errors; } 379 396 380 return ast:: Pass< core_t >::resultN<container_t, node_t>{ mutated,new_kids };397 return ast::__pass::resultN<container_t, node_t>{ mutated, new_kids }; 381 398 } 382 399 -
src/AST/Pass.proto.hpp
rf5a51db rcc7bbe6 23 23 class Pass; 24 24 25 structTranslationUnit;25 class TranslationUnit; 26 26 27 27 struct PureVisitor; … … 123 123 static constexpr bool value = std::is_void< ret_t >::value || 124 124 std::is_base_of<const node_t, typename std::remove_pointer<ret_t>::type >::value; 125 }; 126 127 /// The result is a single node. 128 template< typename node_t > 129 struct result1 { 130 bool differs; 131 const node_t * value; 132 133 template< typename object_t, typename super_t, typename field_t > 134 void apply( object_t *, field_t super_t::* field ); 135 }; 136 137 /// The result is a container of statements. 138 template< template<class...> class container_t > 139 struct resultNstmt { 140 /// The delta/change on a single node. 141 struct delta { 142 ptr<Stmt> new_val; 143 ssize_t old_idx; 144 bool is_old; 145 146 delta(const Stmt * s, ssize_t i, bool old) : 147 new_val(s), old_idx(i), is_old(old) {} 148 }; 149 150 bool differs; 151 container_t< delta > values; 152 153 template< typename object_t, typename super_t, typename field_t > 154 void apply( object_t *, field_t super_t::* field ); 155 156 template< template<class...> class incontainer_t > 157 void take_all( incontainer_t<ptr<Stmt>> * stmts ); 158 159 template< template<class...> class incontainer_t > 160 void take_all( incontainer_t<ptr<Decl>> * decls ); 161 }; 162 163 /// The result is a container of nodes. 164 template< template<class...> class container_t, typename node_t > 165 struct resultN { 166 bool differs; 167 container_t<ptr<node_t>> values; 168 169 template< typename object_t, typename super_t, typename field_t > 170 void apply( object_t *, field_t super_t::* field ); 125 171 }; 126 172 -
src/AST/TranslationUnit.hpp
rf5a51db rcc7bbe6 23 23 namespace ast { 24 24 25 struct TranslationUnit { 25 class TranslationUnit { 26 public: 26 27 std::list< ptr< Decl > > decls; 27 28 -
src/AST/module.mk
rf5a51db rcc7bbe6 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.