Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Concurrency/Keywords.cpp

    r35eef3b red96731  
    1010// Created On       : Tue Nov 16  9:53:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jan 26 15:16:16 2025
    13 // Update Count     : 15
     12// Last Modified On : Thu Dec 14 18:02:25 2023
     13// Update Count     : 6
    1414//
    1515
     
    6969}
    7070
    71 // Describe that it adds the generic parameters and the uses of the generic parameters on the
    72 // function and first "this" argument.
     71// Describe that it adds the generic parameters and the uses of the generic
     72// parameters on the 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 
    127119struct ConcurrentSueKeyword : public ast::WithDeclsToAdd {
    128120        ConcurrentSueKeyword(
     
    179171};
    180172
    181 // Handles generator type declarations:
     173// Handles thread type declarations:
    182174//
    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;
     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;
    187179// };                                        };
     180//                                           static inline thread$ * get_thread( MyThread * this ) { return &this->__thrd_d; }
    188181//
    189 struct GeneratorKeyword final : public ConcurrentSueKeyword {
    190         GeneratorKeyword() : ConcurrentSueKeyword(
    191                 "generator$",
    192                 "__generator_state",
    193                 "get_generator",
    194                 "Unable to find builtin type generator$\n",
    195                 "",
     182struct 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",
    196189                true,
    197                 ast::AggregateDecl::Generator )
     190                ast::AggregateDecl::Thread )
    198191        {}
    199192
    200         virtual ~GeneratorKeyword() {}
     193        virtual ~ThreadKeyword() {}
    201194};
    202195
     
    204197//
    205198// coroutine MyCoroutine {                   struct MyCoroutine {
     199//  int data;                                  int data;
     200//  a_struct_t more_data;                      a_struct_t more_data;
    206201//                                =>             coroutine$ __cor_d;
    207 //    int data;                                  int data;
    208 //    a_struct_t more_data;                      a_struct_t more_data;
    209202// };                                        };
    210203//                                           static inline coroutine$ * get_coroutine( MyCoroutine * this ) { return &this->__cor_d; }
     
    227220//
    228221// monitor MyMonitor {                       struct MyMonitor {
     222//  int data;                                  int data;
     223//  a_struct_t more_data;                      a_struct_t more_data;
    229224//                                =>             monitor$ __mon_d;
    230 //    int data;                                  int data;
    231 //    a_struct_t more_data;                      a_struct_t more_data;
    232225// };                                        };
    233226//                                           static inline monitor$ * get_coroutine( MyMonitor * this ) {
     
    255248};
    256249
    257 // Handles thread type declarations:
     250// Handles generator type declarations:
    258251//
    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;
     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;
    263256// };                                        };
    264 //                                           static inline thread$ * get_thread( MyThread * this ) { return &this->__thrd_d; }
    265257//
    266 struct 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",
     258struct GeneratorKeyword final : public ConcurrentSueKeyword {
     259        GeneratorKeyword() : ConcurrentSueKeyword(
     260                "generator$",
     261                "__generator_state",
     262                "get_generator",
     263                "Unable to find builtin type generator$\n",
     264                "",
    273265                true,
    274                 ast::AggregateDecl::Thread )
     266                ast::AggregateDecl::Generator )
    275267        {}
    276268
    277         virtual ~ThreadKeyword() {}
     269        virtual ~GeneratorKeyword() {}
    278270};
    279271
     
    362354
    363355        if ( !exception_name.empty() ) {
    364                 if ( !typeid_decl || !vtable_decl ) {
     356                if( !typeid_decl || !vtable_decl ) {
    365357                        SemanticError( decl, context_error );
    366358                }
     
    427419        declsToAddBefore.push_back(
    428420                Virtual::makeTypeIdInstance( location, typeid_type ) );
    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.
     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.
    431423        ast::ptr<ast::StructInstType> typeid_cleanup = typeid_type;
    432424}
     
    533525
    534526        auto mutDecl = ast::mutate( decl );
    535         // Insert at start of special aggregate structures => front of vector
    536         //mutDecl->members.insert( mutDecl->members.begin(), field );
    537527        mutDecl->members.push_back( field );
    538528
     
    927917
    928918                        // If it is a monitor, then it is a monitor.
    929                         if ( baseStruct->base->is_monitor() || baseStruct->base->is_thread() ) {
     919                        if( baseStruct->base->is_monitor() || baseStruct->base->is_thread() ) {
    930920                                SemanticError( decl, "destructors for structures declared as \"monitor\" must use mutex parameters " );
    931921                        }
     
    10411031
    10421032        // Make sure that only the outer reference is mutex.
    1043         if ( baseStruct->is_mutex() ) {
     1033        if( baseStruct->is_mutex() ) {
    10441034                SemanticError( decl, "mutex keyword may only appear once per argument " );
    10451035        }
     
    11891179}
    11901180
    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.
     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
    11931183ast::ExprStmt * MutexKeyword::genVirtLockUnlockExpr( const std::string & fnName, ast::ptr<ast::Expr> expr, const CodeLocation & location, ast::Expr * param ) {
    11941184        return new ast::ExprStmt( location,
Note: See TracChangeset for help on using the changeset viewer.