Changeset 4b30318b


Ignore:
Timestamp:
Sep 2, 2023, 3:07:49 PM (8 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
6e93819
Parents:
389fbf5 (diff), 8a9a3ab (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Files:
12 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/coroutine.cfa

    r389fbf5 r4b30318b  
    344344bool poll() libcfa_public { return poll( active_coroutine() ); }
    345345coroutine$ * resumer() libcfa_public { return active_coroutine()->last; }
     346coroutine$ * first_resumer() libcfa_public { return active_coroutine()->starter; }
    346347
    347348// user facing ehm operations
     
    358359
    359360    coroutine$ * resumer( T & cor ) libcfa_public { return get_coroutine( cor )->last; }
     361    coroutine$ * first_resumer( T & cor ) libcfa_public { return get_coroutine( cor )->starter; }
    360362}
    361363
  • libcfa/src/concurrency/coroutine.hfa

    r389fbf5 r4b30318b  
    124124        src->state = Active;
    125125
    126         if( unlikely(src->cancellation != 0p) ) {
     126        if( unlikely(src->cancellation != 0p && src->cancellation != 1p) ) {
    127127                __cfactx_coroutine_unwind(src->cancellation, src);
    128128        }
     
    169169        coroutine$ * dst = get_coroutine(cor);
    170170
     171    // printf("FROM RES src: %p, dest: %p\n", src, dst);
     172
    171173        if( unlikely(dst->context.SP == 0p) ) {
    172174                __stack_prepare(&dst->stack, DEFAULT_STACK_SIZE);
     
    188190        // always done for performance testing
    189191        $ctx_switch( src, dst );
    190         if ( unlikely(dst->cancellation) ) {
     192
     193        if ( unlikely(src->cancellation == 1p) ) {
     194        src->cancellation = 0p;
     195        // we know dst hasn't been deallocated
    191196                __cfaehm_cancelled_coroutine( cor, dst, _default_vtable );
    192197        }
     
    222227bool poll();
    223228coroutine$ * resumer();
     229coroutine$ * first_resumer();
    224230
    225231forall(T & | is_coroutine(T)) {
     
    229235    bool checked_poll( T & cor );
    230236    coroutine$ * resumer( T & cor );
     237    coroutine$ * first_resumer( T & cor );
    231238}
    232239
  • libcfa/src/concurrency/exception.cfa

    r389fbf5 r4b30318b  
    5757        struct coroutine$ * src = (coroutine$ *)stop_param;
    5858        struct coroutine$ * dst = src->last;
    59 
     59    dst->cancellation = 1p;
    6060        $ctx_switch( src, dst );
    6161        abort();
  • src/InitTweak/FixInitNew.cpp

    r389fbf5 r4b30318b  
    573573        assertf( global.dtorDestroy, "Destructor generation requires __destroy_Destructor." );
    574574
    575         const CodeLocation loc = ret->location;
     575        const CodeLocation & loc = ret->location;
    576576
    577577        // generate a __Destructor for ret that calls the destructor
  • src/Parser/parser.yy

    r389fbf5 r4b30318b  
    26912691        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt
    26922692                {
    2693                         if ( $3->storageClasses.any() || $3->type->qualifiers.val != 0 ) {
     2693                        if ( $3 && ($3->storageClasses.any() || $3->type->qualifiers.val != 0 )) {
    26942694                                SemanticError( yylloc, "syntax error, storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." );
    26952695                        }
     
    28292829
    28302830cfa_abstract_parameter_declaration:                                             // CFA, new & old style parameter declaration
    2831         abstract_parameter_declaration
     2831        // empty
     2832                { $$ = nullptr; }
     2833        | abstract_parameter_declaration
    28322834        | cfa_identifier_parameter_declarator_no_tuple
    28332835        | cfa_abstract_tuple
     
    38543856                // { SemanticError( yylloc, "New array dimension is currently unimplemented." ); $$ = nullptr; }
    38553857        | '[' push array_type_list pop ']'                                      // CFA
    3856                 { SemanticError( yylloc, "Type array dimension is currently unimplemented." ); $$ = nullptr; }
     3858                { $$ = DeclarationNode::newArray( $3, nullptr, false ); }
    38573859        | multi_array_dimension
    38583860        ;
  • src/ResolvExpr/CurrentObject.cc

    r389fbf5 r4b30318b  
    10451045                        PRINT( std::cerr << "____untyped: " << expr << std::endl; )
    10461046                        auto dit = desigAlts.begin();
    1047                         if ( auto nexpr = dynamic_cast< const NameExpr * >( expr ) ) {
    1048                                 for ( const Type * t : curTypes ) {
    1049                                         assert( dit != desigAlts.end() );
    1050 
    1051                                         DesignatorChain & d = *dit;
     1047
     1048                        for ( const Type * t : curTypes ) {
     1049                                assert( dit != desigAlts.end() );
     1050                                DesignatorChain & d = *dit;
     1051                                if ( auto nexpr = dynamic_cast< const NameExpr *>( expr ) ) {
    10521052                                        PRINT( std::cerr << "____actual: " << t << std::endl; )
    10531053                                        if ( auto refType = dynamic_cast< const BaseInstType * >( t ) ) {
     
    10621062                                                        }
    10631063                                                }
     1064                                        } else if ( auto at = dynamic_cast< const ArrayType * >( t ) ) {
     1065                                                auto nexpr = dynamic_cast< const NameExpr *>( expr );
     1066                                                auto res = eval( nexpr );
     1067                                                for ( const Decl * mem : refType->lookup( nexpr->name ) ) {
     1068                                                        if ( auto field = dynamic_cast< const ObjectDecl * >( mem ) ) {
     1069                                                                DesignatorChain d2 = d;
     1070                                                                d2.emplace_back( new VariableExpr{ expr->location, field } );
     1071                                                                newDesigAlts.emplace_back( std::move( d2 ) );
     1072                                                                // newTypes.emplace_back( field->type );
     1073                                                                newTypes.emplace_back( at->base );
     1074                                                        }
     1075                                                }
     1076
     1077                                                // d.emplace_back( expr );
     1078                                                // newDesigAlts.emplace_back( d );
     1079                                                // newTypes.emplace_back( at->base );
    10641080                                        }
    10651081
    10661082                                        ++dit;
    1067                                 }
    1068                         } else {
    1069                                 for ( const Type * t : curTypes ) {
    1070                                         assert( dit != desigAlts.end() );
    1071 
    1072                                         DesignatorChain & d = *dit;
     1083                                } else {
    10731084                                        if ( auto at = dynamic_cast< const ArrayType * >( t ) ) {
    10741085                                                PRINT( std::cerr << "____alt: " << at->get_base() << std::endl; )
  • src/ResolvExpr/ResolveTypeof.cc

    r389fbf5 r4b30318b  
    1515
    1616#include "ResolveTypeof.h"
    17 #include "RenameVars.h"
    18 
    19 #include <cassert>               // for assert
     17
     18#include <cassert>  // for assert
    2019
    2120#include "AST/CVQualifiers.hpp"
     
    2524#include "AST/Type.hpp"
    2625#include "AST/TypeEnvironment.hpp"
    27 #include "Common/PassVisitor.h"  // for PassVisitor
    28 #include "Common/utility.h"      // for copy
    29 #include "Resolver.h"            // for resolveInVoidContext
     26#include "Common/PassVisitor.h"   // for PassVisitor
     27#include "Common/utility.h"       // for copy
     28#include "InitTweak/InitTweak.h"  // for isConstExpr
     29#include "RenameVars.h"
     30#include "Resolver.h"  // for resolveInVoidContext
     31#include "SymTab/Mangler.h"
    3032#include "SynTree/Expression.h"  // for Expression
    3133#include "SynTree/Mutator.h"     // for Mutator
    3234#include "SynTree/Type.h"        // for TypeofType, Type
    33 #include "SymTab/Mangler.h"
    34 #include "InitTweak/InitTweak.h" // for isConstExpr
    3535
    3636namespace SymTab {
     
    3939
    4040namespace ResolvExpr {
    41         namespace {
     41namespace {
    4242#if 0
    4343                void
     
    5252        }
    5353
    54         class ResolveTypeof_old : public WithShortCircuiting {
    55           public:
     54class ResolveTypeof_old : public WithShortCircuiting {
     55   public:
    5656                ResolveTypeof_old( const SymTab::Indexer &indexer ) : indexer( indexer ) {}
    5757                void premutate( TypeofType *typeofType );
    5858                Type * postmutate( TypeofType *typeofType );
    5959
    60           private:
    61                 const SymTab::Indexer &indexer;
    62         };
     60   private:
     61    const SymTab::Indexer &indexer;
     62};
    6363
    6464        Type * resolveTypeof( Type *type, const SymTab::Indexer &indexer ) {
     
    7171        }
    7272
    73         Type * ResolveTypeof_old::postmutate( TypeofType *typeofType ) {
     73    Type * ResolveTypeof_old::postmutate( TypeofType *typeofType ) {
    7474#if 0
    7575                std::cerr << "resolving typeof: ";
     
    7777                std::cerr << std::endl;
    7878#endif
    79                 // pass on null expression
     79    // pass on null expression
    8080                if ( ! typeofType->expr ) return typeofType;
    8181
    82                 bool isBasetypeof = typeofType->is_basetypeof;
    83                 auto oldQuals = typeofType->get_qualifiers().val;
    84 
    85                 Type* newType;
     82    bool isBasetypeof = typeofType->is_basetypeof;
     83    auto oldQuals = typeofType->get_qualifiers().val;
     84
     85    Type* newType;
    8686                if ( TypeExpr* tyExpr = dynamic_cast<TypeExpr*>(typeofType->expr) ) {
    87                         // typeof wrapping type
    88                         newType = tyExpr->type;
    89                         tyExpr->type = nullptr;
    90                         delete tyExpr;
    91                 } else {
    92                         // typeof wrapping expression
     87        // typeof wrapping type
     88        newType = tyExpr->type;
     89        tyExpr->type = nullptr;
     90        delete tyExpr;
     91    } else {
     92        // typeof wrapping expression
    9393                        Expression * newExpr = resolveInVoidContext( typeofType->expr, indexer );
    9494                        assert( newExpr->result && ! newExpr->result->isVoid() );
    95                         newType = newExpr->result;
    96                         newExpr->result = nullptr;
    97                         delete typeofType;
    98                         delete newExpr;
    99                 }
    100 
    101                 // clear qualifiers for base, combine with typeoftype quals in any case
    102                 if ( isBasetypeof ) {
     95        newType = newExpr->result;
     96        newExpr->result = nullptr;
     97        delete typeofType;
     98        delete newExpr;
     99    }
     100
     101    // clear qualifiers for base, combine with typeoftype quals in any case
     102    if ( isBasetypeof ) {
    103103                        // replace basetypeof(<enum>) by int
    104104                        if ( dynamic_cast<EnumInstType*>(newType) ) {
     
    112112                                = ( newType->get_qualifiers().val & ~Type::Qualifiers::Mask ) | oldQuals;
    113113                } else {
    114                         newType->get_qualifiers().val |= oldQuals;
    115                 }
    116 
    117                 return newType;
    118         }
     114        newType->get_qualifiers().val |= oldQuals;
     115    }
     116
     117    return newType;
     118}
    119119
    120120namespace {
    121         struct ResolveTypeof_new : public ast::WithShortCircuiting {
    122                 const ResolveContext & context;
     121struct ResolveTypeof_new : public ast::WithShortCircuiting {
     122    const ResolveContext & context;
    123123
    124124                ResolveTypeof_new( const ResolveContext & context ) :
     
    127127                void previsit( const ast::TypeofType * ) { visit_children = false; }
    128128
    129                 const ast::Type * postvisit( const ast::TypeofType * typeofType ) {
    130                         // pass on null expression
    131                         if ( ! typeofType->expr ) return typeofType;
    132 
    133                         ast::ptr< ast::Type > newType;
    134                         if ( auto tyExpr = typeofType->expr.as< ast::TypeExpr >() ) {
    135                                 // typeof wrapping type
    136                                 newType = tyExpr->type;
    137                         } else {
    138                                 // typeof wrapping expression
    139                                 ast::TypeEnvironment dummy;
    140                                 ast::ptr< ast::Expr > newExpr =
    141                                         resolveInVoidContext( typeofType->expr, context, dummy );
    142                                 assert( newExpr->result && ! newExpr->result->isVoid() );
    143                                 newType = newExpr->result;
    144                         }
    145 
    146                         // clear qualifiers for base, combine with typeoftype quals regardless
    147                         if ( typeofType->kind == ast::TypeofType::Basetypeof ) {
    148                                 // replace basetypeof(<enum>) by int
     129        const ast::Type * postvisit( const ast::TypeofType * typeofType ) {
     130        // pass on null expression
     131            if ( ! typeofType->expr ) return typeofType;
     132
     133            ast::ptr< ast::Type > newType;
     134            if ( auto tyExpr = typeofType->expr.as< ast::TypeExpr >() ) {
     135            // typeof wrapping type
     136            newType = tyExpr->type;
     137        } else {
     138            // typeof wrapping expression
     139            ast::TypeEnvironment dummy;
     140            ast::ptr< ast::Expr > newExpr =
     141                resolveInVoidContext( typeofType->expr, context, dummy );
     142            assert( newExpr->result && ! newExpr->result->isVoid() );
     143            newType = newExpr->result;
     144        }
     145
     146        // clear qualifiers for base, combine with typeoftype quals regardless
     147        if ( typeofType->kind == ast::TypeofType::Basetypeof ) {
     148            // replace basetypeof(<enum>) by int
    149149                                if ( newType.as< ast::EnumInstType >() ) {
    150150                                        newType = new ast::BasicType{
    151151                                                ast::BasicType::SignedInt, newType->qualifiers, copy(newType->attributes) };
    152                                 }
     152            }
    153153                                reset_qualifiers(
    154154                                        newType,
    155155                                        ( newType->qualifiers & ~ast::CV::EquivQualifiers ) | typeofType->qualifiers );
    156                         } else {
     156        } else {
    157157                                add_qualifiers( newType, typeofType->qualifiers );
    158                         }
    159 
    160                         return newType.release();
    161                 }
    162         };
     158        }
     159
     160        return newType.release();
     161    }
     162};
    163163} // anonymous namespace
    164164
     
    195195
    196196const ast::ObjectDecl * fixObjectType( const ast::ObjectDecl * decl , const ResolveContext & context ) {
    197         if (decl->isTypeFixed) {
    198                 return decl;
    199         }
    200 
    201         auto mutDecl = mutate(decl);
    202         {
    203                 auto resolvedType = resolveTypeof(decl->type, context);
    204                 resolvedType = fixArrayType(resolvedType, context);
    205                 mutDecl->type = resolvedType;
    206         }
    207 
    208         // Do not mangle unnamed variables.
    209         if (!mutDecl->name.empty()) {
    210                 mutDecl->mangleName = Mangle::mangle(mutDecl);
    211         }
    212 
    213         mutDecl->type = renameTyVars(mutDecl->type, RenameMode::GEN_EXPR_ID);
    214         mutDecl->isTypeFixed = true;
    215         return mutDecl;
    216 }
    217 
    218 } // namespace ResolvExpr
     197    if (decl->isTypeFixed) {
     198        return decl;
     199    }
     200
     201    auto mutDecl = mutate(decl);
     202    fixObjectInit(decl, context);
     203    {
     204        auto resolvedType = resolveTypeof(decl->type, context);
     205        resolvedType = fixArrayType(resolvedType, context);
     206        mutDecl->type = resolvedType;
     207    }
     208
     209    // Do not mangle unnamed variables.
     210    if (!mutDecl->name.empty()) {
     211        mutDecl->mangleName = Mangle::mangle(mutDecl);
     212    }
     213
     214    mutDecl->type = renameTyVars(mutDecl->type, RenameMode::GEN_EXPR_ID);
     215    mutDecl->isTypeFixed = true;
     216    return mutDecl;
     217}
     218
     219const ast::ObjectDecl *fixObjectInit(const ast::ObjectDecl *decl,
     220                                     const ResolveContext &context) {
     221    if (decl->isTypeFixed) {
     222        return decl;
     223    }
     224
     225    auto mutDecl = mutate(decl);
     226
     227    if ( auto mutListInit = mutDecl->init.as<ast::ListInit>() ) {
     228        // std::list<ast::Designation *> newDesignations;       
     229
     230        for ( size_t k = 0; k < mutListInit->designations.size(); k++ ) {
     231            const ast::Designation *des = mutListInit->designations[k].get();
     232            // Desination here
     233            ast::Designation * newDesination = new ast::Designation(des->location);
     234
     235            if (des->designators.size() == 0) continue;
     236
     237            // The designator I want to replace
     238            const ast::Expr * designator = des->designators.at(0);
     239
     240            if ( const ast::NameExpr * designatorName = dynamic_cast<const ast::NameExpr *>(designator) ) {
     241                auto candidates = context.symtab.lookupId(designatorName->name);
     242                // Does not work for the overloading case currently
     243                // assert( candidates.size() == 1 );
     244                if ( candidates.size() != 1 ) return mutDecl;
     245                auto candidate = candidates.at(0);
     246                if ( const ast::EnumInstType * enumInst = dynamic_cast<const ast::EnumInstType *>(candidate.id->get_type()) ) {
     247                    // determine that is an enumInst, swap it with its const value
     248                    assert( candidates.size() == 1 );
     249                    const ast::EnumDecl * baseEnum = enumInst->base;
     250                    // Need to iterate over all enum value to find the initializer to swap
     251                    for ( size_t m = 0; m < baseEnum->members.size(); ++m ) {
     252                        if ( baseEnum->members.at(m)->name == designatorName->name ) {
     253                            const ast::ObjectDecl * mem = baseEnum->members.at(m).as<const ast::ObjectDecl>();
     254                            assert(mem);
     255                            if ( mem->init ) {
     256                                const ast::SingleInit * memInit = mem->init.as<const ast::SingleInit>();
     257                                ast::Expr * initValue = shallowCopy( memInit->value.get() );
     258                                newDesination->designators.push_back( initValue );
     259                            } else {
     260                                SemanticError(des->location, "TODO: Enum Array Designation with no explicit value is not implemented");
     261                            }
     262                        }
     263                    }
     264                    if ( newDesination->designators.size() == 0 ) {
     265                        SemanticError(des->location, "Resolution Error: Resolving array designation as Enum Instance value, but cannot find a desgination value");
     266                    }
     267                } else {
     268                    newDesination->designators.push_back( des->designators.at(0) );
     269                }
     270            } else {
     271                newDesination->designators.push_back( des->designators.at(0) );
     272            }
     273            mutListInit = ast::mutate_field_index(mutListInit, &ast::ListInit::designations, k, newDesination);
     274        }
     275    }
     276    return mutDecl;
     277}
     278
     279}  // namespace ResolvExpr
    219280
    220281// Local Variables: //
  • src/ResolvExpr/ResolveTypeof.h

    r389fbf5 r4b30318b  
    3232        const ast::Type * fixArrayType( const ast::Type *, const ResolveContext & );
    3333        const ast::ObjectDecl * fixObjectType( const ast::ObjectDecl * decl , const ResolveContext & );
     34        const ast::ObjectDecl * fixObjectInit( const ast::ObjectDecl * decl , const ResolveContext &);
    3435} // namespace ResolvExpr
    3536
  • src/ResolvExpr/Resolver.cc

    r389fbf5 r4b30318b  
    15071507                                if ( InitTweak::tryConstruct( mutDecl ) && ( managedTypes.isManaged( mutDecl ) || ((! isInFunction() || mutDecl->storage.is_static ) && ! InitTweak::isConstExpr( mutDecl->init ) ) ) ) {
    15081508                                        // constructed objects cannot be designated
    1509                                         if ( InitTweak::isDesignated( mutDecl->init ) ) SemanticError( mutDecl, "Cannot include designations in the initializer for a managed Object. If this is really what you want, then initialize with @=.\n" );
     1509                                        // if ( InitTweak::isDesignated( mutDecl->init ) ) SemanticError( mutDecl, "Cannot include designations in the initializer for a managed Object. If this is really what you want, then initialize with @=.\n" );
     1510                                        if ( InitTweak::isDesignated( mutDecl->init ) ) {
     1511                                                SemanticError( mutDecl, "Cannot include designations in the initializer for a managed Object. If this is really what you want, then initialize with @=.\n" );
     1512                                        }
    15101513                                        // constructed objects should not have initializers nested too deeply
    15111514                                        if ( ! InitTweak::checkInitDepth( mutDecl ) ) SemanticError( mutDecl, "Managed object's initializer is too deep " );
  • src/Validate/GenericParameter.cpp

    r389fbf5 r4b30318b  
    301301const ast::Expr * TranslateDimensionCore::postvisit(
    302302                const ast::TypeExpr * expr ) {
    303         // Does nothing, except prevents matching ast::Expr (above).
     303        if ( auto instType = dynamic_cast<const ast::EnumInstType *>( expr->type.get() ) ) {
     304                const ast::EnumDecl * baseEnum = instType->base.get();
     305                return ast::ConstantExpr::from_int( expr->location, baseEnum->members.size() );
     306        }
    304307        return expr;
    305308}
  • tests/pybin/settings.py

    r389fbf5 r4b30318b  
    141141        all_install  = [Install(o)      for o in list(dict.fromkeys(options.install))]
    142142        archive      = os.path.abspath(os.path.join(original_path, options.archive_errors)) if options.archive_errors else None
    143         invariant    = options.no_invariant
     143        invariant    = options.invariant
    144144        continue_    = options.continue_
    145145        dry_run      = options.dry_run # must be called before tools.config_hash()
  • tests/test.py

    r389fbf5 r4b30318b  
    114114        parser.add_argument('--install', help='Run all tests based on installed binaries or tree binaries', type=comma_separated(yes_no), default='no')
    115115        parser.add_argument('--continue', help='When multiple specifications are passed (debug/install/arch), sets whether or not to continue if the last specification failed', type=yes_no, default='yes', dest='continue_')
    116         parser.add_argument('--invariant', help='Tell the compiler to check invariants.', action='store_true')
    117         parser.add_argument('--no-invariant', help='Tell the compiler not to check invariants.', action='store_false')
     116        parser.add_argument('--no-invariant', help='Tell the compiler not to check invariants.', action='store_false', dest='invariant')
     117        parser.add_argument('--invariant', help='Tell the compiler to check invariants.', action='store_const', const=True)
    118118        parser.add_argument('--timeout', help='Maximum duration in seconds after a single test is considered to have timed out', type=int, default=180)
    119119        parser.add_argument('--global-timeout', help='Maximum cumulative duration in seconds after the ALL tests are considered to have timed out', type=int, default=7200)
Note: See TracChangeset for help on using the changeset viewer.