Ignore:
Timestamp:
Apr 9, 2021, 2:11:43 PM (3 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:
b91bfde
Parents:
e07b589
Message:

Major exception update, seperating type-ids from virtual tables. The major interface changes are done. There is a regression of ?Cancelled(T) to Some?Cancelled. There is some bits of code for the new verion of the ?Cancelled(T) interface already there. Not connected yet but I just reached the limit of what I wanted to do in one commit and then spent over a day cleaning up, so it will replace Some?Cancelled in a future commit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Virtual/Tables.cc

    re07b589 recfd758  
    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 : Thr Apr  8 15:51:00 2021
     13// Update Count     : 1
    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";
     38}
     39
     40std::string baseTypeName( std::string const & vtable_type_name ) {
     41        return vtable_type_name.substr(0, vtable_type_name.size() - 7);
    2642}
    2743
     
    8197                                inits.push_back(
    8298                                                new SingleInit( new AddressExpr( new NameExpr( parentInstance ) ) ) );
     99                        } else if ( std::string( "__cfavir_typeid" ) == field->name ) {
     100                                std::string const & baseType = baseTypeName( vtableType->name );
     101                                std::string const & typeId = typeIdName( baseType );
     102                                inits.push_back( new SingleInit( new AddressExpr( new NameExpr( typeId ) ) ) );
    83103                        } else if ( std::string( "size" ) == field->name ) {
    84104                                inits.push_back( new SingleInit( new SizeofExpr( objectType->clone() ) ) );
     
    147167}
    148168
    149 }
     169ObjectDecl * makeTypeIdForward() {
     170        return nullptr;
     171}
     172
     173Attribute * linkonce( const std::string & subsection ) {
     174        const std::string section = "\".gnu.linkonce." + subsection + "\"";
     175        // Adjust for terminator and quotes.
     176        size_t str_size = section.size() + 1 - 2;
     177        return new Attribute( "section", {
     178                new ConstantExpr( Constant(
     179                        new ArrayType(
     180                                noQualifiers,
     181                                new BasicType( noQualifiers, BasicType::Char ),
     182                                new ConstantExpr( Constant::from_ulong( str_size ) ),
     183                                false, false ),
     184                        section,
     185                        std::nullopt
     186                ) ),
     187        } );
     188}
     189
     190ObjectDecl * makeTypeIdInstance( StructInstType const * typeIdType ) {
     191        assert( typeIdType );
     192        StructInstType * type = typeIdType->clone();
     193        type->tq.is_const = true;
     194        std::string const & typeid_name = typeIdTypeToInstance( typeIdType->name );
     195        return new ObjectDecl(
     196                typeid_name,
     197                noStorageClasses,
     198                LinkageSpec::Cforall,
     199                /* bitfieldWidth */ nullptr,
     200                type,
     201                new ListInit( { new SingleInit(
     202                        new AddressExpr( new NameExpr( "__cfatid_exception_t" ) )
     203                        ) } ),
     204                { linkonce( typeid_name ) },
     205                noFuncSpecifiers
     206        );
     207}
     208
     209}
Note: See TracChangeset for help on using the changeset viewer.