Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Virtual/Tables.cc

    r69c5c00 rb583113  
    1010// Created On       : Mon Aug 31 11:11:00 2020
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Sep  3 14:56:00 2020
    13 // Update Count     : 0
     12// Last Modified On : Wed Apr 21 15:36:00 2021
     13// Update Count     : 2
    1414//
    1515
     
    2222namespace Virtual {
    2323
     24std::string typeIdType( std::string const & type_name ) {
     25        return "__cfatid_struct_" + type_name;
     26}
     27
     28std::string typeIdName( std::string const & type_name ) {
     29        return "__cfatid_" + type_name;
     30}
     31
     32static std::string typeIdTypeToInstance( std::string const & type_name ) {
     33        return typeIdName(type_name.substr(16));
     34}
     35
    2436std::string vtableTypeName( std::string const & name ) {
    2537        return name + "_vtable";
    2638}
    2739
     40std::string baseTypeName( std::string const & vtable_type_name ) {
     41        return vtable_type_name.substr(0, vtable_type_name.size() - 7);
     42}
     43
    2844std::string instanceName( std::string const & name ) {
    2945        return std::string("_") + name + "_instance";
     
    3248std::string vtableInstanceName( std::string const & name ) {
    3349        return instanceName( vtableTypeName( name ) );
     50}
     51
     52std::string concurrentDefaultVTableName() {
     53        return "_default_vtable";
    3454}
    3555
     
    4161
    4262static ObjectDecl * makeVtableDeclaration(
     63                std::string const & name,
    4364                StructInstType * type, Initializer * init ) {
    44         std::string const & name = instanceName( type->name );
    4565        Type::StorageClasses storage = noStorageClasses;
    4666        if ( nullptr == init ) {
     
    5777}
    5878
    59 ObjectDecl * makeVtableForward( StructInstType * type ) {
     79ObjectDecl * makeVtableForward( std::string const & name, StructInstType * type ) {
    6080        assert( type );
    61         return makeVtableDeclaration( type, nullptr );
     81        return makeVtableDeclaration( name, type, nullptr );
    6282}
    6383
    6484ObjectDecl * makeVtableInstance(
    65                 StructInstType * vtableType, Type * objectType, Initializer * init ) {
     85                std::string const & name, StructInstType * vtableType,
     86                Type * objectType, Initializer * init ) {
    6687        assert( vtableType );
    6788        assert( objectType );
     
    81102                                inits.push_back(
    82103                                                new SingleInit( new AddressExpr( new NameExpr( parentInstance ) ) ) );
     104                        } else if ( std::string( "__cfavir_typeid" ) == field->name ) {
     105                                std::string const & baseType = baseTypeName( vtableType->name );
     106                                std::string const & typeId = typeIdName( baseType );
     107                                inits.push_back( new SingleInit( new AddressExpr( new NameExpr( typeId ) ) ) );
    83108                        } else if ( std::string( "size" ) == field->name ) {
    84109                                inits.push_back( new SingleInit( new SizeofExpr( objectType->clone() ) ) );
     
    95120                assert(false);
    96121        }
    97         return makeVtableDeclaration( vtableType, init );
     122        return makeVtableDeclaration( name, vtableType, init );
    98123}
    99124
     
    147172}
    148173
    149 }
     174Attribute * linkonce( const std::string & subsection ) {
     175        const std::string section = ".gnu.linkonce." + subsection;
     176        return new Attribute( "section", {
     177                new ConstantExpr( Constant::from_string( section ) ),
     178        } );
     179}
     180
     181ObjectDecl * makeTypeIdInstance( StructInstType const * typeIdType ) {
     182        assert( typeIdType );
     183        StructInstType * type = typeIdType->clone();
     184        type->tq.is_const = true;
     185        std::string const & typeid_name = typeIdTypeToInstance( typeIdType->name );
     186        return new ObjectDecl(
     187                typeid_name,
     188                noStorageClasses,
     189                LinkageSpec::Cforall,
     190                /* bitfieldWidth */ nullptr,
     191                type,
     192                new ListInit( { new SingleInit(
     193                        new AddressExpr( new NameExpr( "__cfatid_exception_t" ) )
     194                        ) } ),
     195                { linkonce( typeid_name ) },
     196                noFuncSpecifiers
     197        );
     198}
     199
     200}
Note: See TracChangeset for help on using the changeset viewer.