Changeset ecfd758 for src/Concurrency


Ignore:
Timestamp:
Apr 9, 2021, 2:11:43 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:
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/Concurrency/Keywords.cc

    re07b589 recfd758  
    4242
    4343namespace Concurrency {
     44        inline static std::string getTypeIdName( std::string const & exception_name ) {
     45                return exception_name.empty() ? std::string() : Virtual::typeIdType( exception_name );
     46        }
    4447        inline static std::string getVTableName( std::string const & exception_name ) {
    45                 return exception_name.empty() ? std::string() : Virtual::vtableTypeName(exception_name);
     48                return exception_name.empty() ? std::string() : Virtual::vtableTypeName( exception_name );
    4649        }
    4750
     
    7578                  type_name( type_name ), field_name( field_name ), getter_name( getter_name ),
    7679                  context_error( context_error ), exception_name( exception_name ),
     80                  typeid_name( getTypeIdName( exception_name ) ),
    7781                  vtable_name( getVTableName( exception_name ) ),
    7882                  needs_main( needs_main ), cast_target( cast_target ) {}
     
    8488
    8589                void handle( StructDecl * );
     90                void addTypeId( StructDecl * );
    8691                void addVtableForward( StructDecl * );
    8792                FunctionDecl * forwardDeclare( StructDecl * );
     
    99104                const std::string context_error;
    100105                const std::string exception_name;
     106                const std::string typeid_name;
    101107                const std::string vtable_name;
    102108                bool needs_main;
     
    106112                FunctionDecl * dtor_decl = nullptr;
    107113                StructDecl * except_decl = nullptr;
     114                StructDecl * typeid_decl = nullptr;
    108115                StructDecl * vtable_decl = nullptr;
    109116        };
     
    392399                else if ( !except_decl && exception_name == decl->name && decl->body ) {
    393400                        except_decl = decl;
     401                }
     402                else if ( !typeid_decl && typeid_name == decl->name && decl->body ) {
     403                        typeid_decl = decl;
    394404                }
    395405                else if ( !vtable_decl && vtable_name == decl->name && decl->body ) {
     
    448458                if( !dtor_decl ) SemanticError( decl, context_error );
    449459
    450                 addVtableForward( decl );
     460                if ( !exception_name.empty() ) {
     461                        if( !typeid_decl ) SemanticError( decl, context_error );
     462                        if( !vtable_decl ) SemanticError( decl, context_error );
     463
     464                        addTypeId( decl );
     465                        addVtableForward( decl );
     466                }
    451467                FunctionDecl * func = forwardDeclare( decl );
    452468                ObjectDecl * field = addField( decl );
     
    454470        }
    455471
     472        void ConcurrentSueKeyword::addTypeId( StructDecl * decl ) {
     473                assert( typeid_decl );
     474                StructInstType typeid_type( Type::Const, typeid_decl );
     475                typeid_type.parameters.push_back( new TypeExpr(
     476                        new StructInstType( noQualifiers, decl )
     477                        ) );
     478                declsToAddBefore.push_back( Virtual::makeTypeIdInstance( &typeid_type ) );
     479        }
     480
    456481        void ConcurrentSueKeyword::addVtableForward( StructDecl * decl ) {
    457                 if ( vtable_decl ) {
    458                         std::list< Expression * > poly_args = {
    459                                 new TypeExpr( new StructInstType( noQualifiers, decl ) ),
    460                         };
    461                         declsToAddBefore.push_back( Virtual::makeGetExceptionForward(
    462                                 vtable_decl->makeInst( poly_args ),
    463                                 except_decl->makeInst( poly_args )
    464                         ) );
    465                         declsToAddBefore.push_back( Virtual::makeVtableForward(
    466                                 vtable_decl->makeInst( move( poly_args ) ) ) );
    467                 // Its only an error if we want a vtable and don't have one.
    468                 } else if ( ! vtable_name.empty() ) {
    469                         SemanticError( decl, context_error );
    470                 }
     482                assert( vtable_decl );
     483                std::list< Expression * > poly_args = {
     484                        new TypeExpr( new StructInstType( noQualifiers, decl ) ),
     485                };
     486                declsToAddBefore.push_back( Virtual::makeGetExceptionForward(
     487                        vtable_decl->makeInst( poly_args ),
     488                        except_decl->makeInst( poly_args )
     489                ) );
     490                declsToAddBefore.push_back( Virtual::makeVtableForward(
     491                        vtable_decl->makeInst( move( poly_args ) ) ) );
    471492        }
    472493
Note: See TracChangeset for help on using the changeset viewer.