Changeset 8b11840
- Timestamp:
- Sep 22, 2017, 1:50:00 PM (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:
- b56c17c
- Parents:
- 05807e9
- Location:
- src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/GenInit.cc
r05807e9 r8b11840 115 115 116 116 void genInit( std::list< Declaration * > & translationUnit ) { 117 ReturnFixer::makeReturnTemp( translationUnit );117 fixReturnStatements( translationUnit ); 118 118 HoistArrayDimension::hoistArrayDimension( translationUnit ); 119 119 CtorDtor::generateCtorDtor( translationUnit ); 120 120 } 121 121 122 void ReturnFixer::makeReturnTemp( std::list< Declaration * > & translationUnit ) {122 void fixReturnStatements( std::list< Declaration * > & translationUnit ) { 123 123 PassVisitor<ReturnFixer> fixer; 124 124 mutateAll( translationUnit, fixer ); -
src/InitTweak/GenInit.h
r05807e9 r8b11840 25 25 void genInit( std::list< Declaration * > & translationUnit ); 26 26 27 /// generates a single ctor/dtor statement using objDecl as the 'this' parameter and arg as the optional argument 28 ImplicitCtorDtorStmt * genCtorDtor( const std::string & fname, ObjectDecl * objDecl, Expression * arg = nullptr ); 27 /// Converts return statements into copy constructor calls on the hidden return variable 28 void fixReturnStatements( std::list< Declaration * > & translationUnit ); 29 30 /// generates a single ctor/dtor statement using objDecl as the 'this' parameter and arg as the optional argument 31 ImplicitCtorDtorStmt * genCtorDtor( const std::string & fname, ObjectDecl * objDecl, Expression * arg = nullptr ); 29 32 30 33 /// creates an appropriate ConstructorInit node which contains a constructor, destructor, and C-initializer -
src/ResolvExpr/Resolver.cc
r05807e9 r8b11840 93 93 PassVisitor<Resolver> resolver; 94 94 acceptAll( translationUnit, resolver ); 95 } 96 97 void resolveDecl( Declaration * decl, const SymTab::Indexer &indexer ) { 98 PassVisitor<Resolver> resolver( indexer ); 99 maybeAccept( decl, resolver ); 95 100 } 96 101 -
src/ResolvExpr/Resolver.h
r05807e9 r8b11840 29 29 /// Checks types and binds syntactic constructs to typed representations 30 30 void resolve( std::list< Declaration * > translationUnit ); 31 void resolveDecl( Declaration *, const SymTab::Indexer &indexer ); 31 32 Expression *resolveInVoidContext( Expression *expr, const SymTab::Indexer &indexer ); 32 33 Expression *findVoidExpression( Expression *untyped, const SymTab::Indexer &indexer ); -
src/ResolvExpr/TypeEnvironment.cc
r05807e9 r8b11840 123 123 for ( std::list< EqvClass >::const_iterator theClass = env.begin(); theClass != env.end(); ++theClass ) { 124 124 for ( std::set< std::string >::const_iterator theVar = theClass->vars.begin(); theVar != theClass->vars.end(); ++theVar ) { 125 /// std::c out<< "adding " << *theVar;125 /// std::cerr << "adding " << *theVar; 126 126 if ( theClass->type ) { 127 /// std::c out<< " bound to ";128 /// theClass->type->print( std::c out);129 /// std::c out<< std::endl;127 /// std::cerr << " bound to "; 128 /// theClass->type->print( std::cerr ); 129 /// std::cerr << std::endl; 130 130 sub.add( *theVar, theClass->type ); 131 131 } else if ( theVar != theClass->vars.begin() ) { 132 132 TypeInstType *newTypeInst = new TypeInstType( Type::Qualifiers(), *theClass->vars.begin(), theClass->data.kind == TypeDecl::Ftype ); 133 /// std::c out<< " bound to variable " << *theClass->vars.begin() << std::endl;133 /// std::cerr << " bound to variable " << *theClass->vars.begin() << std::endl; 134 134 sub.add( *theVar, newTypeInst ); 135 135 delete newTypeInst; -
src/SymTab/Autogen.cc
r05807e9 r8b11840 16 16 #include "Autogen.h" 17 17 18 #include <cstddef> // for NULL19 18 #include <algorithm> // for count_if 20 19 #include <cassert> // for strict_dynamic_cast, assert, assertf … … 32 31 #include "GenPoly/DeclMutator.h" // for DeclMutator 33 32 #include "GenPoly/ScopedSet.h" // for ScopedSet, ScopedSet<>::iterator 33 #include "InitTweak/GenInit.h" // for fixReturnStatements 34 #include "ResolvExpr/Resolver.h" // for resolveDecl 34 35 #include "SymTab/Mangler.h" // for Mangler 35 36 #include "SynTree/Attribute.h" // For Attribute … … 108 109 109 110 bool isUnnamedBitfield( ObjectDecl * obj ) { 110 return obj != NULL && obj->get_name() == "" && obj->get_bitfieldWidth() != NULL;111 return obj != nullptr && obj->get_name() == "" && obj->get_bitfieldWidth() != nullptr; 111 112 } 112 113 … … 115 116 FunctionDecl * decl = functionDecl->clone(); 116 117 delete decl->get_statements(); 117 decl->set_statements( NULL);118 decl->set_statements( nullptr ); 118 119 declsToAdd.push_back( decl ); 119 120 decl->fixUniqueId(); … … 326 327 assert( ! func->get_functionType()->get_parameters().empty() ); 327 328 ObjectDecl * dstParam = dynamic_cast<ObjectDecl*>( func->get_functionType()->get_parameters().front() ); 328 ObjectDecl * srcParam = NULL;329 ObjectDecl * srcParam = nullptr; 329 330 if ( func->get_functionType()->get_parameters().size() == 2 ) { 330 331 srcParam = dynamic_cast<ObjectDecl*>( func->get_functionType()->get_parameters().back() ); … … 333 334 assert( dstParam ); 334 335 335 Expression *srcselect = srcParam ? new MemberExpr( field, new VariableExpr( srcParam ) ) : NULL;336 Expression *srcselect = srcParam ? new MemberExpr( field, new VariableExpr( srcParam ) ) : nullptr; 336 337 makeStructMemberOp( dstParam, srcselect, field, func, forward ); 337 338 } // if … … 372 373 } else { 373 374 // no matching parameter, initialize field with default ctor 374 makeStructMemberOp( dstParam, NULL, field, func );375 makeStructMemberOp( dstParam, nullptr, field, func ); 375 376 } 376 377 } … … 388 389 void makeStructFunctions( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting, std::list< Declaration * > & declsToAdd, const std::vector< FuncData > & data ) { 389 390 // Builtins do not use autogeneration. 390 if ( aggregateDecl->get_linkage() == LinkageSpec::BuiltinCFA || 391 aggregateDecl->get_linkage() == LinkageSpec::BuiltinC ) { 391 if ( LinkageSpec::isBuiltin( aggregateDecl->get_linkage() ) ) { 392 392 return; 393 393 } 394 394 395 395 // Make function polymorphic in same parameters as generic struct, if applicable 396 const std::list< TypeDecl * > & typeParams = aggregateDecl->get_parameters(); // List of type variables to be placed on the generated functions396 const std::list< TypeDecl * > & typeParams = aggregateDecl->get_parameters(); // List of type variables to be placed on the generated functions 397 397 398 398 // generate each of the functions based on the supplied FuncData objects … … 565 565 } 566 566 567 void AutogenerateRoutines::previsit( EnumDecl * enumDecl ) {567 void AutogenerateRoutines::previsit( EnumDecl * enumDecl ) { 568 568 visit_children = false; 569 569 if ( ! enumDecl->get_members().empty() ) { … … 574 574 } 575 575 576 void AutogenerateRoutines::previsit( StructDecl * structDecl ) {576 void AutogenerateRoutines::previsit( StructDecl * structDecl ) { 577 577 visit_children = false; 578 if ( structDecl->has_body() && structsDone.find( structDecl-> get_name()) == structsDone.end() ) {579 StructInstType structInst( Type::Qualifiers(), structDecl-> get_name());580 for ( TypeDecl * typeDecl : structDecl-> get_parameters()) {578 if ( structDecl->has_body() && structsDone.find( structDecl->name ) == structsDone.end() ) { 579 StructInstType structInst( Type::Qualifiers(), structDecl->name ); 580 for ( TypeDecl * typeDecl : structDecl->parameters ) { 581 581 // need to visit assertions so that they are added to the appropriate maps 582 acceptAll( typeDecl-> get_assertions(), *visitor );583 structInst. get_parameters().push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), typeDecl ) ) );582 acceptAll( typeDecl->assertions, *visitor ); 583 structInst.parameters.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeDecl->name, typeDecl ) ) ); 584 584 } 585 585 structInst.set_baseStruct( structDecl ); 586 586 makeStructFunctions( structDecl, &structInst, functionNesting, declsToAddAfter, data ); 587 structsDone.insert( structDecl-> get_name());587 structsDone.insert( structDecl->name ); 588 588 } // if 589 589 } 590 590 591 void AutogenerateRoutines::previsit( UnionDecl * unionDecl ) {591 void AutogenerateRoutines::previsit( UnionDecl * unionDecl ) { 592 592 visit_children = false; 593 593 if ( ! unionDecl->get_members().empty() ) { … … 609 609 610 610 // generate ctor/dtors/assign for typedecls, e.g., otype T = int *; 611 void AutogenerateRoutines::previsit( TypeDecl * typeDecl ) {611 void AutogenerateRoutines::previsit( TypeDecl * typeDecl ) { 612 612 visit_children = false; 613 613 if ( ! typeDecl->base ) return; … … 678 678 insert( functionDecl, destructable, InitTweak::isDestructor ); 679 679 680 maybeAccept( functionDecl-> get_functionType(), *visitor );680 maybeAccept( functionDecl->type, *visitor ); 681 681 functionNesting += 1; 682 maybeAccept( functionDecl-> get_statements(), *visitor );682 maybeAccept( functionDecl->statements, *visitor ); 683 683 functionNesting -= 1; 684 684 } -
src/SymTab/FixFunction.cc
r05807e9 r8b11840 27 27 28 28 DeclarationWithType * FixFunction::mutate(FunctionDecl *functionDecl) { 29 // can't delete function type because it may contain assertions, so transfer ownership to new object 29 30 ObjectDecl *pointer = new ObjectDecl( functionDecl->get_name(), functionDecl->get_storageClasses(), functionDecl->get_linkage(), 0, new PointerType( Type::Qualifiers(), functionDecl->get_type() ), 0, functionDecl->get_attributes() ); 30 31 functionDecl->get_attributes().clear(); 31 // can't delete function type because it may contain assertions, but can't transfer ownership without a clone since set_type checks for nullptr 32 functionDecl->set_type( functionDecl->get_type()->clone() ); 32 functionDecl->type = nullptr; 33 33 delete functionDecl; 34 34 return pointer; -
src/SymTab/Indexer.cc
r05807e9 r8b11840 40 40 41 41 namespace SymTab { 42 struct NewScope {43 NewScope( SymTab::Indexer & indexer ) : indexer( indexer ) { indexer.enterScope(); }44 ~NewScope() { indexer.leaveScope(); }45 SymTab::Indexer & indexer;46 };47 48 template< typename TreeType, typename VisitorType >49 inline void acceptNewScope( TreeType *tree, VisitorType &visitor ) {50 visitor.enterScope();51 maybeAccept( tree, visitor );52 visitor.leaveScope();53 }54 55 42 typedef std::unordered_map< std::string, DeclarationWithType* > MangleTable; 56 43 typedef std::unordered_map< std::string, MangleTable > IdTable; … … 198 185 } 199 186 200 Indexer::Indexer( bool _doDebug ) : tables( 0 ), scope( 0 ), doDebug( _doDebug) {}201 202 Indexer::Indexer( const Indexer &that ) : tables( newRef( that.tables ) ), scope( that.scope ), doDebug( that.doDebug) {}203 204 Indexer::Indexer( Indexer &&that ) : tables( that.tables ), scope( that.scope ), doDebug( that.doDebug) {187 Indexer::Indexer() : tables( 0 ), scope( 0 ) {} 188 189 Indexer::Indexer( const Indexer &that ) : doDebug( that.doDebug ), tables( newRef( that.tables ) ), scope( that.scope ) {} 190 191 Indexer::Indexer( Indexer &&that ) : doDebug( that.doDebug ), tables( that.tables ), scope( that.scope ) { 205 192 that.tables = 0; 206 193 } -
src/SymTab/Indexer.h
r05807e9 r8b11840 26 26 class Indexer { 27 27 public: 28 explicit Indexer( bool useDebug = false);28 explicit Indexer(); 29 29 30 30 Indexer( const Indexer &that ); … … 76 76 void addTrait( TraitDecl *decl ); 77 77 78 bool doDebug = false; ///< Display debugging trace? 78 79 private: 79 80 struct Impl; … … 81 82 Impl *tables; ///< Copy-on-write instance of table data structure 82 83 unsigned long scope; ///< Scope index of this pointer 83 bool doDebug; ///< Display debugging trace?84 84 85 85 /// Takes a new ref to a table (returns null if null) -
src/SymTab/Mangler.cc
r05807e9 r8b11840 31 31 32 32 namespace SymTab { 33 std::string Mangler::mangleType( Type * ty ) {33 std::string Mangler::mangleType( Type * ty ) { 34 34 Mangler mangler( false, true ); 35 35 maybeAccept( ty, mangler ); … … 48 48 } 49 49 50 void Mangler::mangleDecl( DeclarationWithType * declaration ) {50 void Mangler::mangleDecl( DeclarationWithType * declaration ) { 51 51 bool wasTopLevel = isTopLevel; 52 52 if ( isTopLevel ) { … … 79 79 } 80 80 81 void Mangler::visit( ObjectDecl * declaration ) {81 void Mangler::visit( ObjectDecl * declaration ) { 82 82 mangleDecl( declaration ); 83 83 } 84 84 85 void Mangler::visit( FunctionDecl * declaration ) {85 void Mangler::visit( FunctionDecl * declaration ) { 86 86 mangleDecl( declaration ); 87 87 } 88 88 89 void Mangler::visit( VoidType * voidType ) {89 void Mangler::visit( VoidType * voidType ) { 90 90 printQualifiers( voidType ); 91 91 mangleName << "v"; 92 92 } 93 93 94 void Mangler::visit( BasicType * basicType ) {94 void Mangler::visit( BasicType * basicType ) { 95 95 static const char *btLetter[] = { 96 96 "b", // Bool … … 121 121 } 122 122 123 void Mangler::visit( PointerType * pointerType ) {123 void Mangler::visit( PointerType * pointerType ) { 124 124 printQualifiers( pointerType ); 125 125 mangleName << "P"; … … 127 127 } 128 128 129 void Mangler::visit( ArrayType * arrayType ) {129 void Mangler::visit( ArrayType * arrayType ) { 130 130 // TODO: encode dimension 131 131 printQualifiers( arrayType ); … … 134 134 } 135 135 136 void Mangler::visit( ReferenceType * refType ) {136 void Mangler::visit( ReferenceType * refType ) { 137 137 printQualifiers( refType ); 138 138 mangleName << "R"; … … 149 149 } 150 150 151 void Mangler::visit( FunctionType * functionType ) {151 void Mangler::visit( FunctionType * functionType ) { 152 152 printQualifiers( functionType ); 153 153 mangleName << "F"; … … 160 160 } 161 161 162 void Mangler::mangleRef( ReferenceToType * refType, std::string prefix ) {162 void Mangler::mangleRef( ReferenceToType * refType, std::string prefix ) { 163 163 printQualifiers( refType ); 164 164 … … 166 166 } 167 167 168 void Mangler::mangleGenericRef( ReferenceToType * refType, std::string prefix ) {168 void Mangler::mangleGenericRef( ReferenceToType * refType, std::string prefix ) { 169 169 printQualifiers( refType ); 170 170 … … 189 189 } 190 190 191 void Mangler::visit( StructInstType * aggregateUseType ) {191 void Mangler::visit( StructInstType * aggregateUseType ) { 192 192 if ( typeMode ) mangleGenericRef( aggregateUseType, "s" ); 193 193 else mangleRef( aggregateUseType, "s" ); 194 194 } 195 195 196 void Mangler::visit( UnionInstType * aggregateUseType ) {196 void Mangler::visit( UnionInstType * aggregateUseType ) { 197 197 if ( typeMode ) mangleGenericRef( aggregateUseType, "u" ); 198 198 else mangleRef( aggregateUseType, "u" ); 199 199 } 200 200 201 void Mangler::visit( EnumInstType * aggregateUseType ) {201 void Mangler::visit( EnumInstType * aggregateUseType ) { 202 202 mangleRef( aggregateUseType, "e" ); 203 203 } 204 204 205 void Mangler::visit( TypeInstType * typeInst ) {205 void Mangler::visit( TypeInstType * typeInst ) { 206 206 VarMapType::iterator varNum = varNums.find( typeInst->get_name() ); 207 207 if ( varNum == varNums.end() ) { … … 231 231 } 232 232 233 void Mangler::visit( TupleType * tupleType ) {233 void Mangler::visit( TupleType * tupleType ) { 234 234 printQualifiers( tupleType ); 235 235 mangleName << "T"; 236 acceptAll( tupleType-> get_types(), *this );236 acceptAll( tupleType->types, *this ); 237 237 mangleName << "_"; 238 238 } 239 239 240 void Mangler::visit( VarArgsType * varArgsType ) {240 void Mangler::visit( VarArgsType * varArgsType ) { 241 241 printQualifiers( varArgsType ); 242 242 mangleName << "VARGS"; 243 243 } 244 244 245 void Mangler::visit( __attribute__((unused)) ZeroType *zeroType) {245 void Mangler::visit( ZeroType * ) { 246 246 mangleName << "Z"; 247 247 } 248 248 249 void Mangler::visit( __attribute__((unused)) OneType *oneType) {249 void Mangler::visit( OneType * ) { 250 250 mangleName << "O"; 251 251 } 252 252 253 void Mangler::visit( TypeDecl * decl ) {253 void Mangler::visit( TypeDecl * decl ) { 254 254 static const char *typePrefix[] = { "BT", "BD", "BF" }; 255 mangleName << typePrefix[ decl->get_kind() ] << ( decl-> get_name().length() + 1 ) << decl->get_name();255 mangleName << typePrefix[ decl->get_kind() ] << ( decl->name.length() + 1 ) << decl->name; 256 256 } 257 257 … … 262 262 } 263 263 264 void Mangler::printQualifiers( Type * type ) {264 void Mangler::printQualifiers( Type * type ) { 265 265 // skip if not including qualifiers 266 266 if ( typeMode ) return; … … 270 270 int tcount = 0, dcount = 0, fcount = 0, vcount = 0; 271 271 mangleName << "A"; 272 for ( Type::ForallList::iterator i = type-> get_forall().begin(); i != type->get_forall().end(); ++i ) {272 for ( Type::ForallList::iterator i = type->forall.begin(); i != type->forall.end(); ++i ) { 273 273 switch ( (*i)->get_kind() ) { 274 274 case TypeDecl::Any: … … 287 287 assert( false ); 288 288 } // switch 289 varNums[ (*i )->get_name() ] = std::pair< int, int >( nextVarNum++, (int )(*i)->get_kind() );290 for ( std::list< DeclarationWithType* >::iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) {289 varNums[ (*i)->name ] = std::pair< int, int >( nextVarNum++, (int)(*i)->get_kind() ); 290 for ( std::list< DeclarationWithType* >::iterator assert = (*i)->assertions.begin(); assert != (*i)->assertions.end(); ++assert ) { 291 291 Mangler sub_mangler( mangleOverridable, typeMode ); 292 292 sub_mangler.nextVarNum = nextVarNum; … … 311 311 // mangleName << "E"; 312 312 // } // if 313 if ( type->get_lvalue() ) {314 mangleName << "L";315 } // if316 313 if ( type->get_atomic() ) { 317 314 mangleName << "A"; -
src/SymTab/Validate.cc
r05807e9 r8b11840 56 56 #include "FixFunction.h" // for FixFunction 57 57 #include "Indexer.h" // for Indexer 58 #include "InitTweak/GenInit.h" // for fixReturnStatements 58 59 #include "InitTweak/InitTweak.h" // for isCtorDtorAssign 59 60 #include "Parser/LinkageSpec.h" // for C … … 150 151 /// Replaces array and function types in forall lists by appropriate pointer type and assigns each Object and Function declaration a unique ID. 151 152 struct ForallPointerDecay final { 152 void previsit( ObjectDecl * object );153 void previsit( FunctionDecl * func );153 void previsit( ObjectDecl * object ); 154 void previsit( FunctionDecl * func ); 154 155 }; 155 156 … … 268 269 acceptAll( translationUnit, genericParams ); // check as early as possible - can't happen before LinkReferenceToTypes 269 270 acceptAll( translationUnit, epc ); // must happen before VerifyCtorDtorAssign, because void return objects should not exist 271 acceptAll( translationUnit, fpd ); // must happen before autogenerateRoutines 270 272 VerifyCtorDtorAssign::verify( translationUnit ); // must happen before autogen, because autogen examines existing ctor/dtors 271 273 Concurrency::applyKeywords( translationUnit ); … … 275 277 ReturnChecker::checkFunctionReturns( translationUnit ); 276 278 mutateAll( translationUnit, compoundliteral ); 277 acceptAll( translationUnit, fpd );278 279 ArrayLength::computeLength( translationUnit ); 279 280 acceptAll( translationUnit, finder ); … … 579 580 580 581 /// Fix up assertions - flattens assertion lists, removing all trait instances 581 void forallFixer( Type * func) {582 for ( TypeDecl * type : f unc->get_forall()) {582 void forallFixer( std::list< TypeDecl * > & forall, BaseSyntaxNode * node ) { 583 for ( TypeDecl * type : forall ) { 583 584 std::list< DeclarationWithType * > asserts; 584 585 asserts.splice( asserts.end(), type->assertions ); … … 599 600 assertion = assertion->acceptMutator( fixer ); 600 601 if ( fixer.get_isVoid() ) { 601 throw SemanticError( "invalid type void in assertion of function ", func);602 throw SemanticError( "invalid type void in assertion of function ", node ); 602 603 } // if 603 604 } // for … … 607 608 608 609 void ForallPointerDecay::previsit( ObjectDecl *object ) { 609 forallFixer( object-> get_type());610 if ( PointerType *pointer = dynamic_cast< PointerType * >( object-> get_type()) ) {611 forallFixer( pointer-> get_base());610 forallFixer( object->type->forall, object ); 611 if ( PointerType *pointer = dynamic_cast< PointerType * >( object->type ) ) { 612 forallFixer( pointer->base->forall, object ); 612 613 } // if 613 614 object->fixUniqueId(); … … 615 616 616 617 void ForallPointerDecay::previsit( FunctionDecl *func ) { 617 forallFixer( func-> get_type());618 forallFixer( func->type->forall, func ); 618 619 func->fixUniqueId(); 619 620 } -
src/SynTree/Visitor.h
r05807e9 r8b11840 25 25 public: 26 26 // visit: Default implementation of all functions visits the children 27 27 // of the given syntax node, but performs no other action. 28 28 29 29 virtual void visit( ObjectDecl *objectDecl );
Note: See TracChangeset
for help on using the changeset viewer.