Changeset 35eef3b


Ignore:
Timestamp:
Jan 26, 2025, 3:19:11 PM (2 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
11f92fac
Parents:
1fb0a883
Message:

updates to prepare for moving location of inline data for new kinds of types

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/Concurrency/Keywords.cpp

    r1fb0a883 r35eef3b  
    1010// Created On       : Tue Nov 16  9:53:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Dec 14 18:02:25 2023
    13 // Update Count     : 6
     12// Last Modified On : Sun Jan 26 15:16:16 2025
     13// Update Count     : 15
    1414//
    1515
     
    6969}
    7070
    71 // Describe that it adds the generic parameters and the uses of the generic
    72 // parameters on the function and first "this" argument.
     71// Describe that it adds the generic parameters and the uses of the generic parameters on the
     72// function and first "this" argument.
    7373ast::FunctionDecl * fixupGenerics(
    7474                const ast::FunctionDecl * func, const ast::StructDecl * decl ) {
     
    117117
    118118// --------------------------------------------------------------------------
     119
     120// This type describes the general information used to transform a generator, coroutine, monitor, or
     121// thread aggregate kind.  A pass is made over the AST in ConcurrentSueKeyword::postvisit looking
     122// for each of these kinds. When found, this data structure is filled in with the information from
     123// the specific structures below, and handleStruct is called to perform the common changes that
     124// augment the aggregate kind with fields and generate appropriate companion routines.  The location
     125// of any extra fields is specified in addField.
     126
    119127struct ConcurrentSueKeyword : public ast::WithDeclsToAdd {
    120128        ConcurrentSueKeyword(
     
    171179};
    172180
    173 // Handles thread type declarations:
     181// Handles generator type declarations:
    174182//
    175 // thread Mythread {                         struct MyThread {
    176 //  int data;                                  int data;
    177 //  a_struct_t more_data;                      a_struct_t more_data;
    178 //                                =>             thread$ __thrd_d;
     183// generator MyGenerator {                   struct MyGenerator {
     184//                                =>             int __generator_state;
     185//    int data;                                  int data;
     186//    a_struct_t more_data;                      a_struct_t more_data;
    179187// };                                        };
    180 //                                           static inline thread$ * get_thread( MyThread * this ) { return &this->__thrd_d; }
    181188//
    182 struct ThreadKeyword final : public ConcurrentSueKeyword {
    183         ThreadKeyword() : ConcurrentSueKeyword(
    184                 "thread$",
    185                 "__thrd",
    186                 "get_thread",
    187                 "thread keyword requires threads to be in scope, add #include <thread.hfa>\n",
    188                 "ThreadCancelled",
     189struct GeneratorKeyword final : public ConcurrentSueKeyword {
     190        GeneratorKeyword() : ConcurrentSueKeyword(
     191                "generator$",
     192                "__generator_state",
     193                "get_generator",
     194                "Unable to find builtin type generator$\n",
     195                "",
    189196                true,
    190                 ast::AggregateDecl::Thread )
     197                ast::AggregateDecl::Generator )
    191198        {}
    192199
    193         virtual ~ThreadKeyword() {}
     200        virtual ~GeneratorKeyword() {}
    194201};
    195202
     
    197204//
    198205// coroutine MyCoroutine {                   struct MyCoroutine {
    199 //  int data;                                  int data;
    200 //  a_struct_t more_data;                      a_struct_t more_data;
    201206//                                =>             coroutine$ __cor_d;
     207//    int data;                                  int data;
     208//    a_struct_t more_data;                      a_struct_t more_data;
    202209// };                                        };
    203210//                                           static inline coroutine$ * get_coroutine( MyCoroutine * this ) { return &this->__cor_d; }
     
    220227//
    221228// monitor MyMonitor {                       struct MyMonitor {
    222 //  int data;                                  int data;
    223 //  a_struct_t more_data;                      a_struct_t more_data;
    224229//                                =>             monitor$ __mon_d;
     230//    int data;                                  int data;
     231//    a_struct_t more_data;                      a_struct_t more_data;
    225232// };                                        };
    226233//                                           static inline monitor$ * get_coroutine( MyMonitor * this ) {
     
    248255};
    249256
    250 // Handles generator type declarations:
     257// Handles thread type declarations:
    251258//
    252 // generator MyGenerator {                   struct MyGenerator {
    253 //  int data;                                  int data;
    254 //  a_struct_t more_data;                      a_struct_t more_data;
    255 //                                =>             int __generator_state;
     259// thread Mythread {                         struct MyThread {
     260//                                =>             thread$ __thrd_d;
     261//    int data;                                  int data;
     262//    a_struct_t more_data;                      a_struct_t more_data;
    256263// };                                        };
     264//                                           static inline thread$ * get_thread( MyThread * this ) { return &this->__thrd_d; }
    257265//
    258 struct GeneratorKeyword final : public ConcurrentSueKeyword {
    259         GeneratorKeyword() : ConcurrentSueKeyword(
    260                 "generator$",
    261                 "__generator_state",
    262                 "get_generator",
    263                 "Unable to find builtin type generator$\n",
    264                 "",
     266struct ThreadKeyword final : public ConcurrentSueKeyword {
     267        ThreadKeyword() : ConcurrentSueKeyword(
     268                "thread$",
     269                "__thrd",
     270                "get_thread",
     271                "thread keyword requires threads to be in scope, add #include <thread.hfa>\n",
     272                "ThreadCancelled",
    265273                true,
    266                 ast::AggregateDecl::Generator )
     274                ast::AggregateDecl::Thread )
    267275        {}
    268276
    269         virtual ~GeneratorKeyword() {}
     277        virtual ~ThreadKeyword() {}
    270278};
    271279
     
    354362
    355363        if ( !exception_name.empty() ) {
    356                 if( !typeid_decl || !vtable_decl ) {
     364                if ( !typeid_decl || !vtable_decl ) {
    357365                        SemanticError( decl, context_error );
    358366                }
     
    419427        declsToAddBefore.push_back(
    420428                Virtual::makeTypeIdInstance( location, typeid_type ) );
    421         // If the typeid_type is going to be kept, the other reference will have
    422         // been made by now, but we also get to avoid extra mutates.
     429        // If the typeid_type is going to be kept, the other reference will have been made by now, but
     430        // we also get to avoid extra mutates.
    423431        ast::ptr<ast::StructInstType> typeid_cleanup = typeid_type;
    424432}
     
    525533
    526534        auto mutDecl = ast::mutate( decl );
     535        // Insert at start of special aggregate structures => front of vector
     536        //mutDecl->members.insert( mutDecl->members.begin(), field );
    527537        mutDecl->members.push_back( field );
    528538
     
    917927
    918928                        // If it is a monitor, then it is a monitor.
    919                         if( baseStruct->base->is_monitor() || baseStruct->base->is_thread() ) {
     929                        if ( baseStruct->base->is_monitor() || baseStruct->base->is_thread() ) {
    920930                                SemanticError( decl, "destructors for structures declared as \"monitor\" must use mutex parameters " );
    921931                        }
     
    10311041
    10321042        // Make sure that only the outer reference is mutex.
    1033         if( baseStruct->is_mutex() ) {
     1043        if ( baseStruct->is_mutex() ) {
    10341044                SemanticError( decl, "mutex keyword may only appear once per argument " );
    10351045        }
     
    11791189}
    11801190
    1181 // generates a cast to the void ptr to the appropriate lock type and dereferences it before calling lock or unlock on it
    1182 // used to undo the type erasure done by storing all the lock pointers as void
     1191// Generates a cast to the void ptr to the appropriate lock type and dereferences it before calling
     1192// lock or unlock on it used to undo the type erasure done by storing all the lock pointers as void.
    11831193ast::ExprStmt * MutexKeyword::genVirtLockUnlockExpr( const std::string & fnName, ast::ptr<ast::Expr> expr, const CodeLocation & location, ast::Expr * param ) {
    11841194        return new ast::ExprStmt( location,
Note: See TracChangeset for help on using the changeset viewer.