Changeset 933f32f for src/Common
- Timestamp:
- May 24, 2019, 10:19:41 AM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- d908563
- Parents:
- 6a9d4b4 (diff), 292642a (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:
-
- 10 added
- 1 deleted
- 7 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/Common/Assert.cc
r6a9d4b4 r933f32f 39 39 } 40 40 41 void abort(const char *fmt, ... ) noexcept __attribute__((noreturn, format(printf, 1, 2))); 42 void abort(const char *fmt, ... ) noexcept { 43 va_list args; 44 va_start( args, fmt ); 45 vfprintf( stderr, fmt, args ); 46 va_end( args ); 47 fprintf( stderr, "\n" ); 48 abort(); 49 } 50 41 51 // Local Variables: // 42 52 // tab-width: 4 // -
src/Common/PassVisitor.h
r6a9d4b4 r933f32f 4 4 5 5 #include <stack> 6 6 #include <type_traits> 7 8 #include "Common/Stats.h" 7 9 #include "Common/utility.h" 8 10 … … 153 155 virtual void visit( ConstructorInit * ctorInit ) override final; 154 156 155 virtual void visit( Subrange * subrange ) override final;156 157 157 virtual void visit( Constant * constant ) override final; 158 158 … … 255 255 virtual Initializer * mutate( ConstructorInit * ctorInit ) override final; 256 256 257 virtual Subrange * mutate( Subrange * subrange ) override final;258 259 257 virtual Constant * mutate( Constant * constant ) override final; 260 258 … … 300 298 301 299 302 TypeSubstitution ** get_env_ptr () { return env_impl( pass, 0); }300 auto get_env_ptr () -> decltype(env_impl( pass, 0)) { return env_impl( pass, 0); } 303 301 std::list< Statement* > * get_beforeStmts() { return stmtsToAddBefore_impl( pass, 0); } 304 302 std::list< Statement* > * get_afterStmts () { return stmtsToAddAfter_impl ( pass, 0); } … … 347 345 }; 348 346 347 class WithConstTypeSubstitution { 348 protected: 349 WithConstTypeSubstitution() = default; 350 ~WithConstTypeSubstitution() = default; 351 352 public: 353 const TypeSubstitution * env = nullptr; 354 }; 355 349 356 class WithStmtsToAdd { 350 357 protected: … … 426 433 }; 427 434 435 #include "Common/Stats.h" 436 437 extern struct PassVisitorStats { 438 size_t depth = 0; 439 Stats::Counters::MaxCounter<double> * max = nullptr; 440 Stats::Counters::AverageCounter<double> * avg = nullptr; 441 } pass_visitor_stats; 442 428 443 #include "SynTree/TypeSubstitution.h" 429 444 #include "PassVisitor.impl.h" -
src/Common/PassVisitor.impl.h
r6a9d4b4 r933f32f 20 20 21 21 #define MUTATE_END( type, node ) \ 22 return call_postmutate< type * >( node ); \ 22 auto __return = call_postmutate< type * >( node ); \ 23 assert( __return ); \ 24 return __return; 23 25 24 26 … … 67 69 SemanticErrorException errors; 68 70 71 pass_visitor_stats.depth++; 72 pass_visitor_stats.max->push(pass_visitor_stats.depth); 73 pass_visitor_stats.avg->push(pass_visitor_stats.depth); 69 74 for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) { 75 76 70 77 // splice in new declarations after previous decl 71 78 if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); } … … 83 90 if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); } 84 91 } 92 pass_visitor_stats.depth--; 85 93 if ( ! errors.isEmpty() ) { 86 94 throw errors; … … 94 102 SemanticErrorException errors; 95 103 104 pass_visitor_stats.depth++; 105 pass_visitor_stats.max->push(pass_visitor_stats.depth); 106 pass_visitor_stats.avg->push(pass_visitor_stats.depth); 96 107 for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) { 97 108 // splice in new declarations after previous decl … … 109 120 if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); } 110 121 } 122 pass_visitor_stats.depth--; 111 123 if ( ! errors.isEmpty() ) { 112 124 throw errors; … … 126 138 if ( ! visitor.get_visit_children() ) return; 127 139 SemanticErrorException errors; 140 141 pass_visitor_stats.depth++; 142 pass_visitor_stats.max->push(pass_visitor_stats.depth); 143 pass_visitor_stats.avg->push(pass_visitor_stats.depth); 128 144 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 129 145 try { … … 135 151 } 136 152 } 153 pass_visitor_stats.depth--; 137 154 if ( ! errors.isEmpty() ) { 138 155 throw errors; … … 151 168 template< typename Container, typename pass_type > 152 169 inline void maybeMutate_impl( Container & container, PassVisitor< pass_type > & mutator ) { 170 153 171 if ( ! mutator.get_visit_children() ) return; 154 172 SemanticErrorException errors; 173 174 pass_visitor_stats.depth++; 175 pass_visitor_stats.max->push(pass_visitor_stats.depth); 176 pass_visitor_stats.avg->push(pass_visitor_stats.depth); 155 177 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 156 178 try { … … 163 185 } // try 164 186 } // for 187 pass_visitor_stats.depth--; 165 188 if ( ! errors.isEmpty() ) { 166 189 throw errors; … … 185 208 DeclList_t* afterDecls = get_afterDecls(); 186 209 210 pass_visitor_stats.depth++; 211 pass_visitor_stats.max->push(pass_visitor_stats.depth); 212 pass_visitor_stats.avg->push(pass_visitor_stats.depth); 187 213 for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) { 188 214 … … 192 218 try { 193 219 func( *i ); 220 assert( *i ); 194 221 assert(( empty( beforeStmts ) && empty( afterStmts )) 195 222 || ( empty( beforeDecls ) && empty( afterDecls )) ); … … 202 229 if ( !empty( beforeStmts ) ) { statements.splice( i, *beforeStmts ); } 203 230 } 231 pass_visitor_stats.depth--; 204 232 205 233 if ( !empty( afterDecls ) ) { splice( std::back_inserter( statements ), afterDecls); } … … 229 257 230 258 // don't want statements from outer CompoundStmts to be added to this CompoundStmt 231 ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr() );259 ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type > oldEnv( get_env_ptr() ); 232 260 ValueGuardPtr< DeclList_t > oldBeforeDecls( get_beforeDecls() ); 233 261 ValueGuardPtr< DeclList_t > oldAfterDecls ( get_afterDecls () ); … … 1965 1993 1966 1994 // don't want statements from outer CompoundStmts to be added to this StmtExpr 1967 ValueGuardPtr< TypeSubstitution * > oldEnv( get_env_ptr() );1995 ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type > oldEnv( get_env_ptr() ); 1968 1996 ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() ); 1969 1997 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () ); … … 1982 2010 1983 2011 // don't want statements from outer CompoundStmts to be added to this StmtExpr 1984 ValueGuardPtr< TypeSubstitution * > oldEnv( get_env_ptr() );2012 ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type > oldEnv( get_env_ptr() ); 1985 2013 ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() ); 1986 2014 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () ); … … 2678 2706 2679 2707 //-------------------------------------------------------------------------- 2680 // Subrange2681 template< typename pass_type >2682 void PassVisitor< pass_type >::visit( Subrange * node ) {2683 VISIT_START( node );2684 2685 VISIT_END( node );2686 }2687 2688 template< typename pass_type >2689 Subrange * PassVisitor< pass_type >::mutate( Subrange * node ) {2690 MUTATE_START( node );2691 2692 MUTATE_END( Subrange, node );2693 }2694 2695 //--------------------------------------------------------------------------2696 2708 // Attribute 2697 2709 template< typename pass_type > -
src/Common/PassVisitor.proto.h
r6a9d4b4 r933f32f 165 165 static inline type * name##_impl( __attribute__((unused)) pass_type& pass, __attribute__((unused)) long unused ) { return nullptr;} \ 166 166 167 FIELD_PTR( TypeSubstitution *, env )167 FIELD_PTR( const TypeSubstitution *, env ) 168 168 FIELD_PTR( std::list< Statement* >, stmtsToAddBefore ) 169 169 FIELD_PTR( std::list< Statement* >, stmtsToAddAfter ) … … 174 174 FIELD_PTR( PassVisitor<pass_type> * const, visitor ) 175 175 176 #undef FIELD_PTR 177 176 178 //--------------------------------------------------------- 177 179 // Indexer … … 220 222 INDEXER_FUNC2( addWith , std::list< Expression * > &, BaseSyntaxNode * ); 221 223 224 #undef INDEXER_FUNC1 225 #undef INDEXER_FUNC2 222 226 223 227 template<typename pass_type> -
src/Common/SemanticError.h
r6a9d4b4 r933f32f 17 17 18 18 #include "ErrorObjects.h" 19 #include "AST/Node.hpp" 19 20 #include <cstring> 20 21 -
src/Common/Stats/Heap.h
r6a9d4b4 r933f32f 16 16 #pragma once 17 17 18 namespace HeapStats { 19 void newPass( const char * const name ); 20 void printStats(); 18 namespace Stats { 19 namespace Heap { 20 void newPass( const char * const name ); 21 void print(); 22 } 21 23 } -
src/Common/module.mk
r6a9d4b4 r933f32f 15 15 ############################################################################### 16 16 17 SRC += Common/SemanticError.cc \ 18 Common/UniqueName.cc \ 19 Common/DebugMalloc.cc \ 20 Common/Assert.cc \ 21 Common/Heap.cc \ 22 Common/Eval.cc 17 SRC_COMMON = \ 18 Common/Assert.cc \ 19 Common/Eval.cc \ 20 Common/PassVisitor.cc \ 21 Common/SemanticError.cc \ 22 Common/Stats/Counter.cc \ 23 Common/Stats/Heap.cc \ 24 Common/Stats/Stats.cc \ 25 Common/Stats/Time.cc \ 26 Common/UniqueName.cc 27 28 SRC += $(SRC_COMMON) Common/DebugMalloc.cc 29 SRCDEMANGLE += $(SRC_COMMON) -
src/Common/utility.h
r6a9d4b4 r933f32f 463 463 std::pair<long long int, bool> eval(Expression * expr); 464 464 465 // ----------------------------------------------------------------------------- 466 /// Reorders the input range in-place so that the minimal-value elements according to the 467 /// comparator are in front; 465 namespace ast { 466 class Expr; 467 } 468 469 std::pair<long long int, bool> eval(const ast::Expr * expr); 470 471 // ----------------------------------------------------------------------------- 472 /// Reorders the input range in-place so that the minimal-value elements according to the 473 /// comparator are in front; 468 474 /// returns the iterator after the last minimal-value element. 469 475 template<typename Iter, typename Compare> 470 476 Iter sort_mins( Iter begin, Iter end, Compare& lt ) { 471 477 if ( begin == end ) return end; 472 478 473 479 Iter min_pos = begin; 474 480 for ( Iter i = begin + 1; i != end; ++i ) {
Note:
See TracChangeset
for help on using the changeset viewer.