Ignore:
Timestamp:
Oct 7, 2020, 6:08:35 PM (4 years ago)
Author:
Andrew Beach <ajbeach@…>
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
Message:

Rework exceptions mark_exception -> get_exception_vtable and the needed follow up.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Virtual/Tables.cc

    r41b8ea4 r69c5c00  
    1414//
    1515
     16#include <SynTree/Attribute.h>
    1617#include <SynTree/Declaration.h>
    1718#include <SynTree/Expression.h>
     19#include <SynTree/Statement.h>
    1820#include <SynTree/Type.h>
    1921
     
    3840}
    3941
    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 
    5042static ObjectDecl * makeVtableDeclaration(
    5143                StructInstType * type, Initializer * init ) {
     
    6658
    6759ObjectDecl * makeVtableForward( StructInstType * type ) {
     60        assert( type );
    6861        return makeVtableDeclaration( type, nullptr );
    6962}
    7063
    71 ObjectDecl * makeVtableForward(
    72                 StructDecl * polyDecl, std::list< Expression * > && parameters ) {
    73         return makeVtableForward( vtableInstType( polyDecl, std::move( parameters ) ) );
    74 }
    75 
    7664ObjectDecl * makeVtableInstance(
    77                 StructInstType * vtableType, Type * vobject_type, Initializer * init ) {
     65                StructInstType * vtableType, Type * objectType, Initializer * init ) {
     66        assert( vtableType );
     67        assert( objectType );
    7868        StructDecl * vtableStruct = vtableType->baseStruct;
    7969        // Build the initialization
     
    9282                                                new SingleInit( new AddressExpr( new NameExpr( parentInstance ) ) ) );
    9383                        } 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() ) ) );
    9585                        } 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() ) ) );
    9787                        } else {
    9888                                inits.push_back( new SingleInit( new NameExpr( field->name ) ) );
     
    10898}
    10999
    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 );
     100namespace {
     101        std::string const functionName = "get_exception_vtable";
     102}
     103
     104FunctionDecl * 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
     137FunctionDecl * 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;
    115147}
    116148
Note: See TracChangeset for help on using the changeset viewer.