Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Concurrency/Keywords.cc

    r8edbe40 r43cedfb1  
    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         }
    4744        inline static std::string getVTableName( std::string const & exception_name ) {
    48                 return exception_name.empty() ? std::string() : Virtual::vtableTypeName( exception_name );
     45                return exception_name.empty() ? std::string() : Virtual::vtableTypeName(exception_name);
    4946        }
    5047
     
    7875                  type_name( type_name ), field_name( field_name ), getter_name( getter_name ),
    7976                  context_error( context_error ), exception_name( exception_name ),
    80                   typeid_name( getTypeIdName( exception_name ) ),
    8177                  vtable_name( getVTableName( exception_name ) ),
    8278                  needs_main( needs_main ), cast_target( cast_target ) {}
     
    8884
    8985                void handle( StructDecl * );
    90                 void addTypeId( StructDecl * );
    9186                void addVtableForward( StructDecl * );
    9287                FunctionDecl * forwardDeclare( StructDecl * );
     
    10499                const std::string context_error;
    105100                const std::string exception_name;
    106                 const std::string typeid_name;
    107101                const std::string vtable_name;
    108102                bool needs_main;
     
    112106                FunctionDecl * dtor_decl = nullptr;
    113107                StructDecl * except_decl = nullptr;
    114                 StructDecl * typeid_decl = nullptr;
    115108                StructDecl * vtable_decl = nullptr;
    116109        };
     
    400393                        except_decl = decl;
    401394                }
    402                 else if ( !typeid_decl && typeid_name == decl->name && decl->body ) {
    403                         typeid_decl = decl;
    404                 }
    405395                else if ( !vtable_decl && vtable_name == decl->name && decl->body ) {
    406396                        vtable_decl = decl;
     
    414404                if ( type_decl && isDestructorFor( decl, type_decl ) )
    415405                        dtor_decl = decl;
    416                 else if ( vtable_name.empty() || !decl->has_body() )
     406                else if ( vtable_name.empty() )
     407                        ;
     408                else if( !decl->has_body() )
    417409                        ;
    418410                else if ( auto param = isMainFor( decl, cast_target ) ) {
     
    426418                        std::list< Expression * > poly_args = { new TypeExpr( struct_type->clone() ) };
    427419                        ObjectDecl * vtable_object = Virtual::makeVtableInstance(
    428                                 "_default_vtable_object_declaration",
    429420                                vtable_decl->makeInst( poly_args ), struct_type, nullptr );
    430421                        declsToAddAfter.push_back( vtable_object );
    431                         declsToAddAfter.push_back(
    432                                 new ObjectDecl(
    433                                         Virtual::concurrentDefaultVTableName(),
    434                                         Type::Const,
    435                                         LinkageSpec::Cforall,
    436                                         /* bitfieldWidth */ nullptr,
    437                                         new ReferenceType( Type::Const, vtable_object->type->clone() ),
    438                                         new SingleInit( new VariableExpr( vtable_object ) )
    439                                 )
    440                         );
    441422                        declsToAddAfter.push_back( Virtual::makeGetExceptionFunction(
    442423                                vtable_object, except_decl->makeInst( std::move( poly_args ) )
     
    467448                if( !dtor_decl ) SemanticError( decl, context_error );
    468449
    469                 if ( !exception_name.empty() ) {
    470                         if( !typeid_decl ) SemanticError( decl, context_error );
    471                         if( !vtable_decl ) SemanticError( decl, context_error );
    472 
    473                         addTypeId( decl );
    474                         addVtableForward( decl );
    475                 }
     450                addVtableForward( decl );
    476451                FunctionDecl * func = forwardDeclare( decl );
    477452                ObjectDecl * field = addField( decl );
     
    479454        }
    480455
    481         void ConcurrentSueKeyword::addTypeId( StructDecl * decl ) {
    482                 assert( typeid_decl );
    483                 StructInstType typeid_type( Type::Const, typeid_decl );
    484                 typeid_type.parameters.push_back( new TypeExpr(
    485                         new StructInstType( noQualifiers, decl )
     456        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 )
    486464                        ) );
    487                 declsToAddBefore.push_back( Virtual::makeTypeIdInstance( &typeid_type ) );
    488         }
    489 
    490         void ConcurrentSueKeyword::addVtableForward( StructDecl * decl ) {
    491                 assert( vtable_decl );
    492                 std::list< Expression * > poly_args = {
    493                         new TypeExpr( new StructInstType( noQualifiers, decl ) ),
    494                 };
    495                 declsToAddBefore.push_back( Virtual::makeGetExceptionForward(
    496                         vtable_decl->makeInst( poly_args ),
    497                         except_decl->makeInst( poly_args )
    498                 ) );
    499                 ObjectDecl * vtable_object = Virtual::makeVtableForward(
    500                         "_default_vtable_object_declaration",
    501                         vtable_decl->makeInst( move( poly_args ) ) );
    502                 declsToAddBefore.push_back( vtable_object );
    503                 declsToAddBefore.push_back(
    504                         new ObjectDecl(
    505                                 Virtual::concurrentDefaultVTableName(),
    506                                 Type::Const,
    507                                 LinkageSpec::Cforall,
    508                                 /* bitfieldWidth */ nullptr,
    509                                 new ReferenceType( Type::Const, vtable_object->type->clone() ),
    510                                 /* init */ nullptr
    511                         )
    512                 );
     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                }
    513471        }
    514472
Note: See TracChangeset for help on using the changeset viewer.