Changeset 69c5c00 for src/Virtual/Tables.cc
- 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
- File:
-
- 1 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
Note: See TracChangeset
for help on using the changeset viewer.