- Timestamp:
- Oct 7, 2020, 6:08:35 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 6fbe9a5
- Parents:
- 41b8ea4
- Location:
- src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Concurrency/Keywords.cc
r41b8ea4 r69c5c00 66 66 bool needs_main, AggregateDecl::Aggregate cast_target ) : 67 67 type_name( type_name ), field_name( field_name ), getter_name( getter_name ), 68 context_error( context_error ), vtable_name( getVTableName( exception_name ) ), 68 context_error( context_error ), exception_name( exception_name ), 69 vtable_name( getVTableName( exception_name ) ), 69 70 needs_main( needs_main ), cast_target( cast_target ) {} 70 71 … … 89 90 const std::string getter_name; 90 91 const std::string context_error; 92 const std::string exception_name; 91 93 const std::string vtable_name; 92 94 bool needs_main; … … 95 97 StructDecl * type_decl = nullptr; 96 98 FunctionDecl * dtor_decl = nullptr; 99 StructDecl * except_decl = nullptr; 97 100 StructDecl * vtable_decl = nullptr; 98 101 }; … … 376 379 else if ( is_target(decl) ) { 377 380 handle( decl ); 381 } 382 else if ( !except_decl && exception_name == decl->name && decl->body ) { 383 except_decl = decl; 378 384 } 379 385 else if ( !vtable_decl && vtable_name == decl->name && decl->body ) { … … 398 404 assert( struct_type ); 399 405 400 declsToAddAfter.push_back( Virtual::makeVtableInstance( vtable_decl, { 401 new TypeExpr( struct_type->clone() ), 402 }, struct_type, nullptr ) ); 406 std::list< Expression * > poly_args = { new TypeExpr( struct_type->clone() ) }; 407 ObjectDecl * vtable_object = Virtual::makeVtableInstance( 408 vtable_decl->makeInst( poly_args ), struct_type, nullptr ); 409 declsToAddAfter.push_back( vtable_object ); 410 declsToAddAfter.push_back( Virtual::makeGetExceptionFunction( 411 vtable_object, except_decl->makeInst( std::move( poly_args ) ) 412 ) ); 403 413 } 404 414 … … 434 444 void ConcurrentSueKeyword::addVtableForward( StructDecl * decl ) { 435 445 if ( vtable_decl ) { 436 declsToAddBefore.push_back( Virtual::makeVtableForward( vtable_decl,{446 std::list< Expression * > poly_args = { 437 447 new TypeExpr( new StructInstType( noQualifiers, decl ) ), 438 } ) ); 448 }; 449 declsToAddBefore.push_back( Virtual::makeGetExceptionForward( 450 vtable_decl->makeInst( poly_args ), 451 except_decl->makeInst( poly_args ) 452 ) ); 453 declsToAddBefore.push_back( Virtual::makeVtableForward( 454 vtable_decl->makeInst( move( poly_args ) ) ) ); 439 455 // Its only an error if we want a vtable and don't have one. 440 456 } else if ( ! vtable_name.empty() ) { -
src/SynTree/AggregateDecl.cc
r41b8ea4 r69c5c00 21 21 #include "Common/utility.h" // for printAll, cloneAll, deleteAll 22 22 #include "Declaration.h" // for AggregateDecl, TypeDecl, Declaration 23 #include "Expression.h" 23 24 #include "Initializer.h" 24 25 #include "LinkageSpec.h" // for Spec, linkageName, Cforall … … 88 89 const char * StructDecl::typeString() const { return aggrString( kind ); } 89 90 91 StructInstType * StructDecl::makeInst( std::list< Expression * > const & new_parameters ) { 92 std::list< Expression * > copy_parameters; 93 cloneAll( new_parameters, copy_parameters ); 94 return makeInst( move( copy( copy_parameters ) ) ); 95 } 96 97 StructInstType * StructDecl::makeInst( std::list< Expression * > && new_parameters ) { 98 assert( parameters.size() == new_parameters.size() ); 99 StructInstType * type = new StructInstType( noQualifiers, this ); 100 type->parameters = std::move( new_parameters ); 101 return type; 102 } 103 90 104 const char * UnionDecl::typeString() const { return aggrString( Union ); } 91 105 -
src/SynTree/Declaration.h
r41b8ea4 r69c5c00 306 306 bool is_thread () { return kind == Thread ; } 307 307 308 // Make a type instance of this declaration. 309 StructInstType * makeInst( std::list< Expression * > const & parameters ); 310 StructInstType * makeInst( std::list< Expression * > && parameters ); 311 308 312 virtual StructDecl * clone() const override { return new StructDecl( *this ); } 309 313 virtual void accept( Visitor & v ) override { v.visit( this ); } -
src/Virtual/Tables.cc
r41b8ea4 r69c5c00 14 14 // 15 15 16 #include <SynTree/Attribute.h> 16 17 #include <SynTree/Declaration.h> 17 18 #include <SynTree/Expression.h> 19 #include <SynTree/Statement.h> 18 20 #include <SynTree/Type.h> 19 21 … … 38 40 } 39 41 40 // Fuse base polymorphic declaration and forall arguments into a new type.41 static StructInstType * vtableInstType(42 StructDecl * polyDecl, std::list< Expression * > && parameters ) {43 assert( parameters.size() == polyDecl->parameters.size() );44 StructInstType * type = new StructInstType(45 Type::Qualifiers( /* Type::Const */ ), polyDecl );46 type->parameters = std::move( parameters );47 return type;48 }49 50 42 static ObjectDecl * makeVtableDeclaration( 51 43 StructInstType * type, Initializer * init ) { … … 66 58 67 59 ObjectDecl * makeVtableForward( StructInstType * type ) { 60 assert( type ); 68 61 return makeVtableDeclaration( type, nullptr ); 69 62 } 70 63 71 ObjectDecl * makeVtableForward(72 StructDecl * polyDecl, std::list< Expression * > && parameters ) {73 return makeVtableForward( vtableInstType( polyDecl, std::move( parameters ) ) );74 }75 76 64 ObjectDecl * makeVtableInstance( 77 StructInstType * vtableType, Type * vobject_type, Initializer * init ) { 65 StructInstType * vtableType, Type * objectType, Initializer * init ) { 66 assert( vtableType ); 67 assert( objectType ); 78 68 StructDecl * vtableStruct = vtableType->baseStruct; 79 69 // Build the initialization … … 92 82 new SingleInit( new AddressExpr( new NameExpr( parentInstance ) ) ) ); 93 83 } else if ( std::string( "size" ) == field->name ) { 94 inits.push_back( new SingleInit( new SizeofExpr( vobject_type->clone() ) ) );84 inits.push_back( new SingleInit( new SizeofExpr( objectType->clone() ) ) ); 95 85 } else if ( std::string( "align" ) == field->name ) { 96 inits.push_back( new SingleInit( new AlignofExpr( vobject_type->clone() ) ) );86 inits.push_back( new SingleInit( new AlignofExpr( objectType->clone() ) ) ); 97 87 } else { 98 88 inits.push_back( new SingleInit( new NameExpr( field->name ) ) ); … … 108 98 } 109 99 110 ObjectDecl * makeVtableInstance( 111 StructDecl * polyDecl, std::list< Expression * > && parameters, 112 Type * vobject, Initializer * init ) { 113 return makeVtableInstance( 114 vtableInstType( polyDecl, std::move( parameters ) ), vobject, init ); 100 namespace { 101 std::string const functionName = "get_exception_vtable"; 102 } 103 104 FunctionDecl * makeGetExceptionForward( 105 Type * vtableType, Type * exceptType ) { 106 assert( vtableType ); 107 assert( exceptType ); 108 FunctionType * type = new FunctionType( noQualifiers, false ); 109 vtableType->tq.is_const = true; 110 type->returnVals.push_back( new ObjectDecl( 111 "_retvalue", 112 noStorageClasses, 113 LinkageSpec::Cforall, 114 nullptr, 115 new ReferenceType( noQualifiers, vtableType ), 116 nullptr, 117 { new Attribute("unused") } 118 ) ); 119 type->parameters.push_back( new ObjectDecl( 120 "__unused", 121 noStorageClasses, 122 LinkageSpec::Cforall, 123 nullptr, 124 new PointerType( noQualifiers, exceptType ), 125 nullptr, 126 { new Attribute("unused") } 127 ) ); 128 return new FunctionDecl( 129 functionName, 130 noStorageClasses, 131 LinkageSpec::Cforall, 132 type, 133 nullptr 134 ); 135 } 136 137 FunctionDecl * makeGetExceptionFunction( 138 ObjectDecl * vtableInstance, Type * exceptType ) { 139 assert( vtableInstance ); 140 assert( exceptType ); 141 FunctionDecl * func = makeGetExceptionForward( 142 vtableInstance->type->clone(), exceptType ); 143 func->statements = new CompoundStmt( { 144 new ReturnStmt( new VariableExpr( vtableInstance ) ), 145 } ); 146 return func; 115 147 } 116 148 -
src/Virtual/Tables.h
r41b8ea4 r69c5c00 27 27 bool isVTableInstanceName( std::string const & name ); 28 28 29 /// Converts exceptions into regular structures. 30 //void ( std::list< Declaration * > & translationUnit ); 31 32 ObjectDecl * makeVtableForward( StructInstType * ); 33 ObjectDecl * makeVtableForward( StructDecl *, std::list< Expression * > && ); 34 /* Create a forward definition of a vtable of the given type. 35 * 36 * Instead of the virtual table type you may provide the declaration and all 37 * the forall parameters. 29 ObjectDecl * makeVtableForward( StructInstType * vtableType ); 30 /* Create a forward declaration of a vtable of the given type. 31 * vtableType node is consumed. 38 32 */ 39 33 40 ObjectDecl * makeVtableInstance( StructInstType *, Type *, Initializer * ); 41 ObjectDecl * makeVtableInstance( 42 StructDecl *, std::list< Expression * > &&, Type *, Initializer * ); 34 ObjectDecl * makeVtableInstance( StructInstType * vtableType, Type * objectType, 35 Initializer * init = nullptr ); 43 36 /* Create an initialized definition of a vtable. 44 * 45 * The parameters are the virtual table type (or the base declaration and the 46 * forall parameters), the object type and optionally an initializer. 47 * 48 * Instead of the virtual table type you may provide the declaration and all 49 * the forall parameters. 37 * vtableType and init (if provided) nodes are consumed. 38 */ 39 40 // Some special code for how exceptions interact with virtual tables. 41 FunctionDecl * makeGetExceptionForward( Type * vtableType, Type * exceptType ); 42 /* Create a forward declaration of the exception virtual function 43 * linking the vtableType to the exceptType. Both nodes are consumed. 44 */ 45 46 FunctionDecl * makeGetExceptionFunction( 47 ObjectDecl * vtableInstance, Type * exceptType ); 48 /* Create the definition of the exception virtual function. 49 * exceptType node is consumed. 50 50 */ 51 51
Note: See TracChangeset
for help on using the changeset viewer.