Changeset b826e6b for src/Common
- Timestamp:
- Jul 19, 2017, 11:49:33 AM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 9cc0472
- Parents:
- fea3faa (diff), a57cb58 (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/Common
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/Assert.cc
rfea3faa rb826e6b 14 14 // 15 15 16 #include <assert.h> 17 #include <cstdarg> // varargs 18 #include <cstdio> // fprintf 19 #include <cstdlib> // abort 16 #include <cstdarg> // for va_end, va_list, va_start 17 #include <cstdio> // for fprintf, stderr, vfprintf 18 #include <cstdlib> // for abort 20 19 21 20 extern const char * __progname; // global name of running executable (argv[0]) -
src/Common/PassVisitor.h
rfea3faa rb826e6b 12 12 #include "SynTree/Expression.h" 13 13 #include "SynTree/Constant.h" 14 #include "SynTree/TypeSubstitution.h" 14 15 15 16 #include "PassVisitor.proto.h" … … 26 27 // stmtsToAddBefore or stmtsToAddAfter respectively. 27 28 // | WithShortCircuiting - provides the ability to skip visiting child nodes; set visit_children to false in pre{visit,mutate} to skip visiting children 28 // | With Scopes - provides the ability to save/restore data like a LIFO stack; to save, call GuardValue with the variable to save, the variable29 // | WithGuards - provides the ability to save/restore data like a LIFO stack; to save, call GuardValue with the variable to save, the variable 29 30 // will automatically be restored to its previous value after the corresponding postvisit/postmutate teminates. 30 31 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- … … 32 33 class PassVisitor final : public Visitor, public Mutator { 33 34 public: 34 PassVisitor() = default;35 35 36 36 template< typename... Args > … … 257 257 258 258 void set_visit_children( bool& ref ) { bool_ref * ptr = visit_children_impl(pass, 0); if(ptr) ptr->set( ref ); } 259 260 guard_value_impl init_guard() {261 guard_value_impl guard;262 auto at_cleanup = at_cleanup_impl(pass, 0);263 if( at_cleanup ) {264 *at_cleanup = [&guard]( cleanup_func_t && func, void* val ) {265 guard.push( std::move( func ), val );266 };267 }268 return guard;269 }270 259 }; 271 260 … … 283 272 284 273 public: 285 TypeSubstitution * env ;274 TypeSubstitution * env = nullptr; 286 275 }; 287 276 … … 295 284 std::list< Statement* > stmtsToAddAfter; 296 285 }; 286 287 class WithDeclsToAdd { 288 protected: 289 WithDeclsToAdd() = default; 290 ~WithDeclsToAdd() = default; 291 292 public: 293 std::list< Declaration* > declsToAddBefore; 294 std::list< Declaration* > declsToAddAfter; 295 }; 296 297 297 class WithShortCircuiting { 298 298 protected: … … 304 304 }; 305 305 306 class With Scopes {307 protected: 308 With Scopes() = default;309 ~With Scopes() = default;306 class WithGuards { 307 protected: 308 WithGuards() = default; 309 ~WithGuards() = default; 310 310 311 311 public: … … 318 318 }, static_cast< void * >( & val ) ); 319 319 } 320 321 template< typename T > 322 void GuardScope( T& val ) { 323 val.beginScope(); 324 at_cleanup( []( void * val ) { 325 static_cast< T * >( val )->endScope(); 326 }, static_cast< void * >( & val ) ); 327 } 328 329 template< typename Func > 330 void GuardAction( Func func ) { 331 at_cleanup( [func](__attribute__((unused)) void *) { func(); }, nullptr ); 332 } 320 333 }; 321 334 … … 323 336 class WithVisitorRef { 324 337 protected: 325 WithVisitorRef() = default;326 ~WithVisitorRef() = default;327 328 public: 329 PassVisitor<pass_type> * const visitor ;338 WithVisitorRef() {} 339 ~WithVisitorRef() {} 340 341 public: 342 PassVisitor<pass_type> * const visitor = nullptr; 330 343 }; 331 344 -
src/Common/PassVisitor.impl.h
rfea3faa rb826e6b 3 3 #define VISIT_START( node ) \ 4 4 __attribute__((unused)) \ 5 const auto & guard = init_guard();\5 guard_value_impl guard( at_cleanup_impl(pass, 0) ); \ 6 6 bool visit_children = true; \ 7 7 set_visit_children( visit_children ); \ … … 15 15 #define MUTATE_START( node ) \ 16 16 __attribute__((unused)) \ 17 const auto & guard = init_guard();\17 guard_value_impl guard( at_cleanup_impl(pass, 0) ); \ 18 18 bool visit_children = true; \ 19 19 set_visit_children( visit_children ); \ … … 68 68 for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) { 69 69 // splice in new declarations after previous decl 70 if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); } 70 if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); } 71 71 72 72 if ( i == decls.end() ) break; … … 88 88 for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) { 89 89 // splice in new declarations after previous decl 90 if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); } 90 if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); } 91 91 92 92 if ( i == decls.end() ) break; … … 104 104 void PassVisitor< pass_type >::handleStatementList( std::list< Statement * > & statements, func_t func ) { 105 105 SemanticError errors; 106 107 // don't want statements from outer CompoundStmts to be added to this CompoundStmt 108 ValueGuardPtr< StmtList_t > oldBeforeStmts( get_beforeStmts() ); 109 ValueGuardPtr< StmtList_t > oldAfterStmts ( get_afterStmts () ); 110 ValueGuardPtr< DeclList_t > oldBeforeDecls( get_beforeDecls() ); 111 ValueGuardPtr< DeclList_t > oldAfterDecls ( get_afterDecls () ); 106 112 107 113 StmtList_t* beforeStmts = get_beforeStmts(); … … 181 187 Statement * PassVisitor< pass_type >::visitStatement( Statement * stmt ) { 182 188 return handleStatement( stmt, [this]( Statement * stmt ) { 183 maybeAccept( stmt, *this ); 189 maybeAccept( stmt, *this ); 184 190 return stmt; 185 191 }); … … 212 218 expr->accept( *this ); 213 219 return expr; 214 }); 220 }); 215 221 } 216 222 … … 565 571 VISIT_START( node ); 566 572 573 // maybeAccept( node->get_env(), *this ); 574 maybeAccept( node->get_result(), *this ); 575 567 576 for ( auto expr : node->get_args() ) { 568 577 visitExpression( expr ); … … 575 584 Expression * PassVisitor< pass_type >::mutate( UntypedExpr * node ) { 576 585 MUTATE_START( node ); 586 587 node->set_env( maybeMutate( node->get_env(), *this ) ); 588 node->set_result( maybeMutate( node->get_result(), *this ) ); 577 589 578 590 for ( auto& expr : node->get_args() ) { -
src/Common/PassVisitor.proto.h
rfea3faa rb826e6b 5 5 6 6 typedef std::function<void( void * )> cleanup_func_t; 7 typedef std::function< void( cleanup_func_t, void * ) > at_cleanup_t; 7 8 8 9 class guard_value_impl { 9 10 public: 10 guard_value_impl() = default; 11 guard_value_impl( at_cleanup_t * at_cleanup ) { 12 if( at_cleanup ) { 13 *at_cleanup = [this]( cleanup_func_t && func, void* val ) { 14 push( std::move( func ), val ); 15 }; 16 } 17 } 11 18 12 19 ~guard_value_impl() { … … 33 40 }; 34 41 35 typedef std::function< void( cleanup_func_t, void * ) > at_cleanup_t;36 42 37 43 class bool_ref { … … 56 62 // Deep magic (a.k.a template meta programming) to make the templated visitor work 57 63 // Basically the goal is to make 2 previsit_impl 58 // 1 - Use when a pass implements a valid previsit. This uses overloading which means the any overload of 64 // 1 - Use when a pass implements a valid previsit. This uses overloading which means the any overload of 59 65 // 'pass.previsit( node )' that compiles will be used for that node for that type 60 66 // This requires that this option only compile for passes that actually define an appropriate visit. -
src/Common/SemanticError.cc
rfea3faa rb826e6b 14 14 // 15 15 16 #include < iostream>17 #include < list>18 #include < string>19 #include < algorithm>20 #include < iterator>16 #include <cstdio> // for fileno, stderr 17 #include <unistd.h> // for isatty 18 #include <iostream> // for basic_ostream, operator<<, ostream 19 #include <list> // for list, _List_iterator 20 #include <string> // for string, operator<<, operator+, to_string 21 21 22 #include "Common/utility.h" // for to_string, CodeLocation (ptr only) 22 23 #include "SemanticError.h" 23 24 #include <unistd.h>25 24 26 25 inline const std::string& error_str() { -
src/Common/SemanticError.h
rfea3faa rb826e6b 17 17 #define SEMANTICERROR_H 18 18 19 #include <exception> 20 #include <string> 21 #include <sstream> 22 #include <list> 23 #include <iostream> 19 #include <exception> // for exception 20 #include <iostream> // for ostream 21 #include <list> // for list 22 #include <string> // for string 24 23 25 #include "utility.h" 24 #include "utility.h" // for CodeLocation, toString 26 25 27 26 struct error { -
src/Common/utility.h
rfea3faa rb826e6b 305 305 // for ( val : group_iterate( container1, container2, ... ) ) {} 306 306 // syntax to have a for each that iterates multiple containers of the same length 307 // TODO: update to use variadic arguments 307 // TODO: update to use variadic arguments, perfect forwarding 308 308 309 309 template< typename T1, typename T2 >
Note: See TracChangeset
for help on using the changeset viewer.