Changeset bd06384
- Timestamp:
- Mar 22, 2018, 4:49:53 PM (7 years ago)
- Branches:
- new-env, with_gc
- Children:
- dbc2c2c
- Parents:
- 7e4b44db
- Location:
- src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r7e4b44db rbd06384 1106 1106 unsigned Indenter::tabsize = 2; 1107 1107 1108 std::ostream & operator<<( std::ostream & out, const BaseSyntaxNode * node ) {1109 if ( node ) {1110 node->print( out );1111 } else {1112 out << "nullptr";1113 }1114 return out;1115 }1116 1117 1108 // Local Variables: // 1118 1109 // tab-width: 4 // -
src/Common/GC.cc
r7e4b44db rbd06384 16 16 #include "GC.h" 17 17 18 #include "Common/PassVisitor.h" 19 20 #include "SynTree/GcTracer.h" 21 18 22 #include <algorithm> 19 23 #include <cassert> … … 24 28 } 25 29 26 GC::GC() : mark(false), old(), young(), using_young(false) {30 GC::GC() : mark(false), using_young(false), old(), young(), static_roots() { 27 31 old.reserve(70000); 28 32 } … … 55 59 } 56 60 61 void GC::register_static_root(BaseSyntaxNode* root) { 62 static_roots.push_back(root); 63 } 64 57 65 void GC::new_generation() { 58 66 using_young = true; 67 } 68 69 void GC::trace_static_roots() { 70 PassVisitor<GcTracer> tracer{ *this }; 71 for ( BaseSyntaxNode* root : static_roots ) { 72 root->accept( tracer ); 73 } 59 74 } 60 75 -
src/Common/GC.h
r7e4b44db rbd06384 20 20 class GC_Traceable; 21 21 class GC_Object; 22 class BaseSyntaxNode; 22 23 23 24 /// Manually traced and called garbage collector … … 34 35 void register_object(GC_Object*); 35 36 37 /// Adds an object to the set of static roots 38 void register_static_root(BaseSyntaxNode*); 39 36 40 /// Use young generation for subsequent new objects 37 41 void new_generation(); 42 43 /// Traces all static roots 44 void trace_static_roots(); 38 45 39 46 /// Collects the young generation, placing survivors in old generation. … … 50 57 GC(); 51 58 52 ///The current collection's mark bit53 bool mark;59 bool mark; ///< The current collection's mark bit 60 bool using_young; ///< Is the young generation in use? 54 61 55 typedef std::vector<class GC_Object*> Generation; 56 Generation old; 57 Generation young; 58 bool using_young; 62 using Generation = std::vector<GC_Object*>; 63 Generation old; ///< Old generation 64 Generation young; ///< Young generation 65 66 using StaticRoots = std::vector<BaseSyntaxNode*>; 67 StaticRoots static_roots; ///< Set of static-lifetime roots 59 68 }; 60 69 … … 80 89 GC& gc = GC::get(); 81 90 traceAll(gc, roots...); 91 gc.trace_static_roots(); 82 92 gc.collect_young(); 83 93 } … … 88 98 GC& gc = GC::get(); 89 99 traceAll(gc, roots...); 100 gc.trace_static_roots(); 90 101 gc.collect(); 102 } 103 104 /// Makes a new expression as a static root 105 template<typename T, typename... Args> 106 inline T* new_static_root( Args&&... args ) { 107 T* root = new T( std::forward<Args>(args)... ); 108 GC::get().register_static_root( root ); 109 return root; 91 110 } 92 111 -
src/Common/PassVisitor.impl.h
r7e4b44db rbd06384 38 38 MUTATE_END( type, node ); \ 39 39 40 40 #include "Common/GC.h" 41 41 42 42 template<typename T> … … 397 397 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 398 398 // implicit add __func__ identifier as specified in the C manual 6.4.2.2 399 static ObjectDecl func(399 static ObjectDecl* func = new_static_root<ObjectDecl>( 400 400 "__func__", noStorageClasses, LinkageSpec::C, nullptr, 401 401 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ), 402 402 nullptr 403 403 ); 404 indexerAddId( &func );404 indexerAddId( func ); 405 405 maybeAccept_impl( node->type, *this ); 406 406 maybeAccept_impl( node->statements, *this ); … … 427 427 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 428 428 // implicit add __func__ identifier as specified in the C manual 6.4.2.2 429 static ObjectDecl func(429 static ObjectDecl* func = new_static_root<ObjectDecl>( 430 430 "__func__", noStorageClasses, LinkageSpec::C, nullptr, 431 431 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ), 432 432 nullptr 433 433 ); 434 indexerAddId( &func );434 indexerAddId( func ); 435 435 maybeMutate_impl( node->type, *this ); 436 436 maybeMutate_impl( node->statements, *this ); -
src/Concurrency/Keywords.cc
r7e4b44db rbd06384 19 19 #include <string> // for string, operator== 20 20 21 #include "Common/GC.h" // for new_static_root 21 22 #include "Common/PassVisitor.h" // for PassVisitor 22 23 #include "Common/SemanticError.h" // for SemanticError … … 203 204 }; 204 205 205 Type* MutexKeyword::generic_func = new FunctionType{ noQualifiers, true };206 Type* MutexKeyword::generic_func = new_static_root<FunctionType>( noQualifiers, true ); 206 207 207 208 //----------------------------------------------------------------------------- -
src/Makefile.in
r7e4b44db rbd06384 250 250 SynTree/driver_cfa_cpp-TypeSubstitution.$(OBJEXT) \ 251 251 SynTree/driver_cfa_cpp-Attribute.$(OBJEXT) \ 252 SynTree/driver_cfa_cpp-BaseSyntaxNode.$(OBJEXT) \ 252 253 SynTree/driver_cfa_cpp-VarExprReplacer.$(OBJEXT) \ 253 254 Tuples/driver_cfa_cpp-TupleAssignment.$(OBJEXT) \ … … 527 528 SynTree/NamedTypeDecl.cc SynTree/TypeDecl.cc \ 528 529 SynTree/Initializer.cc SynTree/TypeSubstitution.cc \ 529 SynTree/Attribute.cc SynTree/VarExprReplacer.cc \ 530 Tuples/TupleAssignment.cc Tuples/TupleExpansion.cc \ 531 Tuples/Explode.cc Virtual/ExpandCasts.cc 530 SynTree/Attribute.cc SynTree/BaseSyntaxNode.cc \ 531 SynTree/VarExprReplacer.cc Tuples/TupleAssignment.cc \ 532 Tuples/TupleExpansion.cc Tuples/Explode.cc \ 533 Virtual/ExpandCasts.cc 532 534 MAINTAINERCLEANFILES = Parser/parser.output ${libdir}/${notdir \ 533 535 ${cfa_cpplib_PROGRAMS}} … … 915 917 SynTree/driver_cfa_cpp-Attribute.$(OBJEXT): SynTree/$(am__dirstamp) \ 916 918 SynTree/$(DEPDIR)/$(am__dirstamp) 919 SynTree/driver_cfa_cpp-BaseSyntaxNode.$(OBJEXT): \ 920 SynTree/$(am__dirstamp) SynTree/$(DEPDIR)/$(am__dirstamp) 917 921 SynTree/driver_cfa_cpp-VarExprReplacer.$(OBJEXT): \ 918 922 SynTree/$(am__dirstamp) SynTree/$(DEPDIR)/$(am__dirstamp) … … 1039 1043 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-AttrType.Po@am__quote@ 1040 1044 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-Attribute.Po@am__quote@ 1045 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Po@am__quote@ 1041 1046 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-BasicType.Po@am__quote@ 1042 1047 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-CommaExpr.Po@am__quote@ … … 2515 2520 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 2516 2521 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SynTree/driver_cfa_cpp-Attribute.obj `if test -f 'SynTree/Attribute.cc'; then $(CYGPATH_W) 'SynTree/Attribute.cc'; else $(CYGPATH_W) '$(srcdir)/SynTree/Attribute.cc'; fi` 2522 2523 SynTree/driver_cfa_cpp-BaseSyntaxNode.o: SynTree/BaseSyntaxNode.cc 2524 @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SynTree/driver_cfa_cpp-BaseSyntaxNode.o -MD -MP -MF SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Tpo -c -o SynTree/driver_cfa_cpp-BaseSyntaxNode.o `test -f 'SynTree/BaseSyntaxNode.cc' || echo '$(srcdir)/'`SynTree/BaseSyntaxNode.cc 2525 @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Tpo SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Po 2526 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='SynTree/BaseSyntaxNode.cc' object='SynTree/driver_cfa_cpp-BaseSyntaxNode.o' libtool=no @AMDEPBACKSLASH@ 2527 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 2528 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SynTree/driver_cfa_cpp-BaseSyntaxNode.o `test -f 'SynTree/BaseSyntaxNode.cc' || echo '$(srcdir)/'`SynTree/BaseSyntaxNode.cc 2529 2530 SynTree/driver_cfa_cpp-BaseSyntaxNode.obj: SynTree/BaseSyntaxNode.cc 2531 @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SynTree/driver_cfa_cpp-BaseSyntaxNode.obj -MD -MP -MF SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Tpo -c -o SynTree/driver_cfa_cpp-BaseSyntaxNode.obj `if test -f 'SynTree/BaseSyntaxNode.cc'; then $(CYGPATH_W) 'SynTree/BaseSyntaxNode.cc'; else $(CYGPATH_W) '$(srcdir)/SynTree/BaseSyntaxNode.cc'; fi` 2532 @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Tpo SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Po 2533 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='SynTree/BaseSyntaxNode.cc' object='SynTree/driver_cfa_cpp-BaseSyntaxNode.obj' libtool=no @AMDEPBACKSLASH@ 2534 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 2535 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SynTree/driver_cfa_cpp-BaseSyntaxNode.obj `if test -f 'SynTree/BaseSyntaxNode.cc'; then $(CYGPATH_W) 'SynTree/BaseSyntaxNode.cc'; else $(CYGPATH_W) '$(srcdir)/SynTree/BaseSyntaxNode.cc'; fi` 2517 2536 2518 2537 SynTree/driver_cfa_cpp-VarExprReplacer.o: SynTree/VarExprReplacer.cc -
src/ResolvExpr/Resolver.cc
r7e4b44db rbd06384 219 219 assertf( expr, "expected a non-null expression." ); 220 220 221 static CastExpr untyped( nullptr ); // cast to void221 auto untyped = new CastExpr{ expr }; // cast to void 222 222 223 223 // set up and resolve expression cast to void 224 untyped.arg = expr;225 224 Alternative choice; 226 findUnfinishedKindExpression( &untyped, choice, indexer, "", standardAlternativeFilter, true );225 findUnfinishedKindExpression( untyped, choice, indexer, "", standardAlternativeFilter, true ); 227 226 CastExpr * castExpr = strict_dynamic_cast< CastExpr * >( choice.expr ); 228 227 env = std::move( choice.env ); 229 228 230 229 // clean up resolved expression 231 Expression * ret = castExpr->arg; 232 castExpr->arg = nullptr; 233 234 // unlink the arg so that it isn't deleted twice at the end of the program 235 untyped.arg = nullptr; 236 return ret; 230 return castExpr->arg; 237 231 } 238 232 -
src/SymTab/Autogen.cc
r7e4b44db rbd06384 588 588 // must visit children (enum constants) to add them to the indexer 589 589 if ( enumDecl->has_body() ) { 590 EnumInstType enumInst( Type::Qualifiers(), enumDecl->get_name() );591 enumInst .set_baseEnum( enumDecl );592 EnumFuncGenerator gen( &enumInst, data, functionNesting, indexer );590 auto enumInst = new EnumInstType{ Type::Qualifiers(), enumDecl->get_name() }; 591 enumInst->set_baseEnum( enumDecl ); 592 EnumFuncGenerator gen( enumInst, data, functionNesting, indexer ); 593 593 generateFunctions( gen, declsToAddAfter ); 594 594 } … … 598 598 visit_children = false; 599 599 if ( structDecl->has_body() ) { 600 StructInstType structInst( Type::Qualifiers(), structDecl->name );601 structInst .set_baseStruct( structDecl );600 auto structInst = new StructInstType{ Type::Qualifiers(), structDecl->name }; 601 structInst->set_baseStruct( structDecl ); 602 602 for ( TypeDecl * typeDecl : structDecl->parameters ) { 603 structInst .parameters.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeDecl->name, typeDecl ) ) );604 } 605 StructFuncGenerator gen( structDecl, &structInst, data, functionNesting, indexer );603 structInst->parameters.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeDecl->name, typeDecl ) ) ); 604 } 605 StructFuncGenerator gen( structDecl, structInst, data, functionNesting, indexer ); 606 606 generateFunctions( gen, declsToAddAfter ); 607 607 } // if … … 611 611 visit_children = false; 612 612 if ( unionDecl->has_body() ) { 613 UnionInstType unionInst( Type::Qualifiers(), unionDecl->get_name() );614 unionInst .set_baseUnion( unionDecl );613 auto unionInst = new UnionInstType{ Type::Qualifiers(), unionDecl->get_name() }; 614 unionInst->set_baseUnion( unionDecl ); 615 615 for ( TypeDecl * typeDecl : unionDecl->get_parameters() ) { 616 unionInst .get_parameters().push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), typeDecl ) ) );617 } 618 UnionFuncGenerator gen( unionDecl, &unionInst, data, functionNesting, indexer );616 unionInst->get_parameters().push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), typeDecl ) ) ); 617 } 618 UnionFuncGenerator gen( unionDecl, unionInst, data, functionNesting, indexer ); 619 619 generateFunctions( gen, declsToAddAfter ); 620 620 } // if … … 625 625 if ( ! typeDecl->base ) return; 626 626 627 TypeInstType refType( Type::Qualifiers(), typeDecl->name, typeDecl );628 TypeFuncGenerator gen( typeDecl, &refType, data, functionNesting, indexer );627 auto refType = new TypeInstType{ Type::Qualifiers(), typeDecl->name, typeDecl }; 628 TypeFuncGenerator gen( typeDecl, refType, data, functionNesting, indexer ); 629 629 generateFunctions( gen, declsToAddAfter ); 630 630 -
src/SynTree/GcTracer.h
r7e4b44db rbd06384 20 20 #include "BaseSyntaxNode.h" 21 21 #include "Expression.h" 22 #include "Type.h" 22 23 23 24 #include "Common/GC.h" … … 47 48 maybeAccept( expr->env, *visitor ); 48 49 } 50 51 void postvisit( PointerType* pty ) { 52 maybeAccept( pty->dimension, *visitor ); 53 } 49 54 }; 50 55 -
src/SynTree/module.mk
r7e4b44db rbd06384 48 48 SynTree/TypeSubstitution.cc \ 49 49 SynTree/Attribute.cc \ 50 SynTree/BaseSyntaxNode.cc \ 50 51 SynTree/VarExprReplacer.cc 51 52 -
src/main.cc
r7e4b44db rbd06384 244 244 OPTPRINT( "validate" ) 245 245 SymTab::validate( translationUnit, symtabp ); 246 collect( translationUnit );247 246 if ( symtabp ) return 0; 247 collect( translationUnit ); 248 248 249 249 if ( expraltp ) {
Note: See TracChangeset
for help on using the changeset viewer.