Changeset 69c5c00 for src/Virtual
- 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/Virtual
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
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.