Changes in / [332e93a:985ff5f]


Ignore:
Files:
3 deleted
19 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/parseargs.cfa

    r332e93a r985ff5f  
    7373//-----------------------------------------------------------------------------
    7474// Parsing args
    75 forall([opt_count])
    76 void parse_args( const array( cfa_option, opt_count ) & options, const char * usage, char ** & left ) {
    77         if ( 0p != &cfa_args_argc ) {
    78                 parse_args( cfa_args_argc, cfa_args_argv, options, usage, left );
    79         } else {
    80                 char * temp[1] = { 0p };
    81                 parse_args(0, temp, options, usage, left );
    82         }
    83 }
    84 
    85 forall([opt_count])
    86 void parse_args(
    87         int argc,
    88         char * argv[],
    89         const array( cfa_option, opt_count ) & options,
    90         const char * usage,
    91         char ** & left
    92 ) {
    93         check_args( options );
    94 
    95         int maxv = 'h';
    96         char optstring[(opt_count * 3) + 2] = { '\0' };
    97         {
    98                 int idx = 0;
    99                 for ( i; opt_count ) {
    100                         if ( options[i].short_name ) {
    101                                 maxv = max( options[i].short_name, maxv );
    102                                 optstring[idx] = options[i].short_name;
    103                                 idx++;
    104                                 if ( (intptr_t)options[i].parse != (intptr_t)parse_settrue
    105                                          && ((intptr_t)options[i].parse) != ((intptr_t)parse_setfalse) ) {
    106                                         optstring[idx] = ':';
     75forall([opt_count]) {
     76        void parse_args( const array( cfa_option, opt_count ) & options, const char * usage, char ** & left ) {
     77                if ( 0p != &cfa_args_argc ) {
     78                        parse_args( cfa_args_argc, cfa_args_argv, options, usage, left );
     79                } else {
     80                        char * temp[1] = { 0p };
     81                        parse_args(0, temp, options, usage, left );
     82                }
     83        }
     84
     85        void parse_args(
     86                int argc,
     87                char * argv[],
     88                const array( cfa_option, opt_count ) & options,
     89                const char * usage,
     90                char ** & left
     91        ) {
     92                check_args( options );
     93
     94                int maxv = 'h';
     95                char optstring[(opt_count * 3) + 2] = { '\0' };
     96                {
     97                        int idx = 0;
     98                        for ( i; opt_count ) {
     99                                if ( options[i].short_name ) {
     100                                        maxv = max( options[i].short_name, maxv );
     101                                        optstring[idx] = options[i].short_name;
     102                                        idx++;
     103                                        if ( (intptr_t)options[i].parse != (intptr_t)parse_settrue
     104                                                 && ((intptr_t)options[i].parse) != ((intptr_t)parse_setfalse) ) {
     105                                                optstring[idx] = ':';
     106                                                idx++;
     107                                        }
     108                                }
     109                        }
     110                        optstring[idx+0] = 'h';
     111                        optstring[idx+1] = '\0';
     112                }
     113
     114                struct option optarr[opt_count + 2];
     115                {
     116                        int idx = 0;
     117                        for ( i; opt_count ) {
     118                                if ( options[i].long_name ) {
     119                                        // we don't have the mutable keyword here, which is really what we would want
     120                                        int & val_ref = (int &)(const int &)options[i].val;
     121                                        val_ref = (options[i].short_name != '\0') ? ((int)options[i].short_name) : ++maxv;
     122
     123                                        optarr[idx].name = options[i].long_name;
     124                                        optarr[idx].flag = 0p;
     125                                        optarr[idx].val  = options[i].val;
     126                                        if ( ((intptr_t)options[i].parse) == ((intptr_t)parse_settrue)
     127                                                 || ((intptr_t)options[i].parse) == ((intptr_t)parse_setfalse) ) {
     128                                                optarr[idx].has_arg = no_argument;
     129                                        } else {
     130                                                optarr[idx].has_arg = required_argument;
     131                                        }
    107132                                        idx++;
    108133                                }
    109134                        }
    110                 }
    111                 optstring[idx+0] = 'h';
    112                 optstring[idx+1] = '\0';
    113         }
    114 
    115         struct option optarr[opt_count + 2];
    116         {
    117                 int idx = 0;
    118                 for ( i; opt_count ) {
    119                         if ( options[i].long_name ) {
    120                                 // we don't have the mutable keyword here, which is really what we would want
    121                                 int & val_ref = (int &)(const int &)options[i].val;
    122                                 val_ref = (options[i].short_name != '\0') ? ((int)options[i].short_name) : ++maxv;
    123 
    124                                 optarr[idx].name = options[i].long_name;
    125                                 optarr[idx].flag = 0p;
    126                                 optarr[idx].val  = options[i].val;
    127                                 if ( ((intptr_t)options[i].parse) == ((intptr_t)parse_settrue)
    128                                          || ((intptr_t)options[i].parse) == ((intptr_t)parse_setfalse) ) {
    129                                         optarr[idx].has_arg = no_argument;
    130                                 } else {
    131                                         optarr[idx].has_arg = required_argument;
    132                                 }
    133                                 idx++;
     135                        optarr[idx+0].[name, has_arg, flag, val] = ["help", no_argument, 0, 'h'];
     136                        optarr[idx+1].[name, has_arg, flag, val] = [0, no_argument, 0, 0];
     137                }
     138
     139                FILE * out = stderr;
     140                NEXT_ARG:
     141                for () {
     142                        int idx = 0;
     143                        int opt = getopt_long( argc, argv, optstring, optarr, &idx );
     144                        switch( opt ) {
     145                                case -1:
     146                                        if ( &left != 0p ) left = argv + optind;
     147                                        return;
     148                                case 'h':
     149                                        out = stdout;
     150                                case '?':
     151                                        usage( argv[0], options, usage, out );
     152                                default:
     153                                        for ( i; opt_count ) {
     154                                                if ( opt == options[i].val ) {
     155                                                        const char * arg = optarg ? optarg : "";
     156                                                        if ( arg[0] == '=' ) { arg++; }
     157                                                        // work around for some weird bug
     158                                                        void * variable = options[i].variable;
     159                                                        bool (*parse_func)(const char *, void * ) = options[i].parse;
     160                                                        bool success = parse_func( arg, variable );
     161                                                        if ( success ) continue NEXT_ARG;
     162
     163                                                        fprintf( out, "Argument '%s' for option %c could not be parsed\n\n", arg, (char)opt );
     164                                                        usage( argv[0], options, usage, out );
     165                                                }
     166                                        }
     167                                        abort( "Internal parse arg error\n" );
    134168                        }
    135                 }
    136                 optarr[idx+0].[name, has_arg, flag, val] = ["help", no_argument, 0, 'h'];
    137                 optarr[idx+1].[name, has_arg, flag, val] = [0, no_argument, 0, 0];
    138         }
    139 
    140         FILE * out = stderr;
    141         NEXT_ARG:
    142         for () {
    143                 int idx = 0;
    144                 int opt = getopt_long( argc, argv, optstring, optarr, &idx );
    145                 switch( opt ) {
    146                 case -1:
    147                         if ( &left != 0p ) left = argv + optind;
    148                         return;
    149                 case 'h':
    150                         out = stdout;
    151                 case '?':
    152                         usage( argv[0], options, usage, out );
    153                 default:
    154                         for ( i; opt_count ) {
    155                                 if ( opt == options[i].val ) {
    156                                         const char * arg = optarg ? optarg : "";
    157                                         if ( arg[0] == '=' ) { arg++; }
    158                                         // work around for some weird bug
    159                                         void * variable = options[i].variable;
    160                                         bool (*parse_func)(const char *, void * ) = options[i].parse;
    161                                         bool success = parse_func( arg, variable );
    162                                         if ( success ) continue NEXT_ARG;
    163 
    164                                         fprintf( out, "Argument '%s' for option %c could not be parsed\n\n", arg, (char)opt );
    165                                         usage( argv[0], options, usage, out );
    166                                 }
    167                         }
    168                         abort( "Internal parse arg error\n" );
     169
    169170                }
    170171        }
     
    239240}
    240241
    241 forall([N])
    242 void print_args_usage( const array(cfa_option, N ) & options, const char * usage, bool error ) {
    243         usage( cfa_args_argv[0], options, usage, error ? stderr : stdout );
    244 }
    245 
    246 forall([N])
    247 void print_args_usage( int argc, char * argv[], const array( cfa_option, N ) & options, const char * usage, bool error ) {
    248         usage( argv[0], options, usage, error ? stderr : stdout );
     242forall( [N] ) {
     243        void print_args_usage( const array(cfa_option, N ) & options, const char * usage, bool error ) {
     244                usage( cfa_args_argv[0], options, usage, error ? stderr : stdout );
     245        }
     246
     247        void print_args_usage( int argc, char * argv[], const array( cfa_option, N ) & options, const char * usage, bool error ) {
     248                usage( argv[0], options, usage, error ? stderr : stdout );
     249        }
    249250}
    250251
  • src/AST/Decl.cpp

    r332e93a r985ff5f  
    169169}
    170170
     171bool EnumDecl::isTyped() const { return base; }
     172
     173bool EnumDecl::isOpaque() const { return isCfa && !isTyped(); }
     174
    171175}
    172176
  • src/AST/Decl.hpp

    r332e93a r985ff5f  
    306306enum class EnumAttribute{ Value, Posn, Label };
    307307
    308 /// enum declaration `enum Foo { ... };` or `enum(...) Foo { ... };`
     308/// enum declaration `enum Foo { ... };`
    309309class EnumDecl final : public AggregateDecl {
    310310public:
     
    317317        std::vector< ast::ptr<ast::EnumInstType>> inlinedDecl; // child enums
    318318
    319         bool is_c_enum     () const { return !isCfa; }
    320         bool is_opaque_enum() const { return isCfa && nullptr == base; }
    321         bool is_typed_enum () const { return isCfa && nullptr != base; }
    322 
    323319        EnumDecl( const CodeLocation& loc, const std::string& name, bool isCfa = false,
    324320                std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall,
     
    335331        const char * typeString() const override { return aggrString( Enum ); }
    336332
     333        bool isTyped() const;
     334        bool isOpaque() const;
    337335private:
    338336        EnumDecl * clone() const override { return new EnumDecl{ *this }; }
  • src/AST/Util.cpp

    r332e93a r985ff5f  
    8585        // Check that `type->returns` corresponds with `decl->returns`.
    8686        assert( type->returns.size() == decl->returns.size() );
    87 }
    88 
    89 /// Check that an enumeration has not been made with an inconsistent spec.
    90 void isEnumerationConsistent( const EnumDecl * node ) {
    91         if ( node->is_c_enum() ) {
    92                 assert( nullptr == node->base );
    93         }
    9487}
    9588
     
    142135                previsit( (const ParseNode *)node );
    143136                functionDeclMatchesType( node );
    144         }
    145 
    146         void previsit( const EnumDecl * node ) {
    147                 previsit( (const ParseNode *)node );
    148                 isEnumerationConsistent( node );
    149137        }
    150138
  • src/CodeGen/CodeGenerator.cpp

    r332e93a r985ff5f  
    130130        // TODO: Which means the ast::Pass is just providing a default no visit?
    131131        visit_children = false;
    132         changeState_ArgToIntrinsic(false);
    133132}
    134133
     
    467466                if ( var->var->linkage == ast::Linkage::Intrinsic &&
    468467                                ( opInfo = operatorLookup( var->var->name ) ) ) {
    469                         changeState_ArgToIntrinsic(true);
    470468                        auto arg = expr->args.begin();
    471469                        switch ( opInfo->type ) {
     
    560558        if ( auto name = expr->func.as<ast::NameExpr>() ) {
    561559                if ( const OperatorInfo * opInfo = operatorLookup( name->name ) ) {
    562                         changeState_ArgToIntrinsic(true);
    563560                        auto arg = expr->args.begin();
    564561                        switch ( opInfo->type ) {
     
    746743        extension( expr );
    747744        const OperatorInfo * opInfo;
    748         if ( visitingArgToIntrinsic
    749                         && options.genC
    750                         && dynamic_cast<ast::ZeroType const *>( expr->var->get_type() ) ) {
    751                 // int * p; p = 0;               ==>  ?=?( p, (zero_t){} );  ==>  p = 0;
    752                 // void f( zero_t z ) { g(z); }  ==>  g(z);                  ==>  g(z);
    753                 // (we are at the last '==>')
    754                 output << "0";
    755         } else if ( expr->var->linkage == ast::Linkage::Intrinsic
     745        if ( expr->var->linkage == ast::Linkage::Intrinsic
    756746                        && ( opInfo = operatorLookup( expr->var->name ) )
    757747                        && opInfo->type == OT_CONSTANT ) {
  • src/CodeGen/CodeGenerator.hpp

    r332e93a r985ff5f  
    181181        void handleTypedef( ast::NamedTypeDecl const * type );
    182182        std::string mangleName( ast::DeclWithType const * decl );
    183 
    184         bool nextVisitedNodeIsArgToIntrinsic = false;
    185         bool visitingArgToIntrinsic = false;
    186         void changeState_ArgToIntrinsic( bool newValue ) {
    187                 GuardValue( visitingArgToIntrinsic ) = nextVisitedNodeIsArgToIntrinsic;
    188                 GuardValue( nextVisitedNodeIsArgToIntrinsic ) = newValue;
    189         }
    190183};
    191184
  • src/CodeGen/GenType.cpp

    r332e93a r985ff5f  
    268268void GenType::postvisit( ast::ZeroType const * type ) {
    269269        // Ideally these wouldn't hit codegen at all, but should be safe to make them ints.
    270         result = ( options.genC ? "long int /*zero_t*/ " : "zero_t " ) + result;
     270        result = (options.pretty ? "zero_t " : "long int ") + result;
    271271        handleQualifiers( type );
    272272}
     
    274274void GenType::postvisit( ast::OneType const * type ) {
    275275        // Ideally these wouldn't hit codegen at all, but should be safe to make them ints.
    276         result = ( options.genC ? "long int /*one_t*/ " : "one_t " ) + result;
     276        result = (options.pretty ? "one_t " : "long int ") + result;
    277277        handleQualifiers( type );
    278278}
  • src/CodeGen/Generate.cpp

    r332e93a r985ff5f  
    4646                }
    4747        };
    48 
    49         struct ZeroOneObjectHider final {
    50                 ast::ObjectDecl const * postvisit( ast::ObjectDecl const * decl ) {
    51                         if ( decl->type.as<ast::ZeroType>() || decl->type.as<ast::OneType>() ) {
    52                                 ast::ObjectDecl * mutDecl = ast::mutate( decl );
    53                                 mutDecl->attributes.push_back( new ast::Attribute( "unused" ) );
    54                                 return mutDecl;
    55                         }
    56                         return decl;
    57                 }
    58         };
    5948} // namespace
    6049
     
    6352        erase_if( translationUnit.decls, shouldClean );
    6453        ast::Pass<TreeCleaner>::run( translationUnit );
    65         ast::Pass<ZeroOneObjectHider>::run( translationUnit );
    6654
    6755        ast::Pass<CodeGenerator> cgv( os,
  • src/Concurrency/Actors.cpp

    r332e93a r985ff5f  
    2929struct CollectactorStructDecls : public ast::WithGuards {
    3030        unordered_set<const StructDecl *> & actorStructDecls;
    31         unordered_set<const StructDecl *> & messageStructDecls;
    32         const StructDecl *& requestDecl;
    33         const EnumDecl *& allocationDecl;
    34         const StructDecl *& actorDecl;
    35         const StructDecl *& msgDecl;
     31        unordered_set<const StructDecl *>  & messageStructDecls;
     32        const StructDecl ** requestDecl;
     33        const EnumDecl ** allocationDecl;
     34        const StructDecl ** actorDecl;
     35        const StructDecl ** msgDecl;
    3636        StructDecl * parentDecl;
    3737        bool insideStruct = false;
     
    4040        // finds and sets a ptr to the allocation enum, which is needed in the next pass
    4141        void previsit( const EnumDecl * decl ) {
    42                 if( decl->name == "allocation" ) allocationDecl = decl;
     42                if( decl->name == "allocation" ) *allocationDecl = decl;
    4343        }
    4444
     
    4848                if ( decl->name == "actor" ) {
    4949                        actorStructDecls.insert( decl ); // skip inserting fwd decl
    50                         actorDecl = decl;
     50                        *actorDecl = decl;
    5151                } else if( decl->name == "message" ) {
    5252                        messageStructDecls.insert( decl ); // skip inserting fwd decl
    53                         msgDecl = decl;
    54                 } else if( decl->name == "request" ) {
    55                         requestDecl = decl;
    56                 } else {
     53                        *msgDecl = decl;
     54                } else if( decl->name == "request" ) *requestDecl = decl;
     55                else {
    5756                        GuardValue(insideStruct);
    5857                        insideStruct = true;
     
    7473        // this collects the derived actor and message struct decl ptrs
    7574        void postvisit( const StructInstType * node ) {
    76                 if ( !actorDecl || !msgDecl ) return;
     75                if ( ! *actorDecl || ! *msgDecl ) return;
    7776                if ( insideStruct && !namedDecl ) {
    7877                        auto actorIter = actorStructDecls.find( node->aggr() );
     
    9089  public:
    9190        CollectactorStructDecls( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls,
    92                 const StructDecl *& requestDecl, const EnumDecl *& allocationDecl, const StructDecl *& actorDecl, const StructDecl *& msgDecl )
     91                const StructDecl ** requestDecl, const EnumDecl ** allocationDecl, const StructDecl ** actorDecl, const StructDecl ** msgDecl )
    9392                : actorStructDecls( actorStructDecls ), messageStructDecls( messageStructDecls ), requestDecl( requestDecl ),
    9493                allocationDecl( allocationDecl ), actorDecl(actorDecl), msgDecl(msgDecl) {}
     
    197196struct GenFuncsCreateTables : public ast::WithDeclsToAdd {
    198197        unordered_set<const StructDecl *> & actorStructDecls;
    199         unordered_set<const StructDecl *> & messageStructDecls;
    200         const StructDecl *& requestDecl;
    201         const EnumDecl *& allocationDecl;
    202         const StructDecl *& actorDecl;
    203         const StructDecl *& msgDecl;
     198        unordered_set<const StructDecl *>  & messageStructDecls;
     199        const StructDecl ** requestDecl;
     200        const EnumDecl ** allocationDecl;
     201        const StructDecl ** actorDecl;
     202        const StructDecl ** msgDecl;
    204203        FwdDeclTable & forwardDecls;
    205204
     
    280279                                                decl->location,
    281280                                                "base_actor",
    282                                                 new PointerType( new PointerType( new StructInstType( actorDecl ) ) )
     281                                                new PointerType( new PointerType( new StructInstType( *actorDecl ) ) )
    283282                                        ),
    284283                                        new ObjectDecl(
    285284                                                decl->location,
    286285                                                "base_msg",
    287                                                 new PointerType( new PointerType( new StructInstType( msgDecl ) ) )
     286                                                new PointerType( new PointerType( new StructInstType( *msgDecl ) ) )
    288287                                        )
    289288                                },                      // params
     
    292291                                                decl->location,
    293292                                                "__CFA_receive_wrap_ret",
    294                                                 new EnumInstType( allocationDecl )
     293                                                new EnumInstType( *allocationDecl )
    295294                                        )
    296295                                },
     
    324323                                        decl->location,
    325324                                        "new_req",
    326                                         new StructInstType( requestDecl )
     325                                        new StructInstType( *requestDecl )
    327326                                )
    328327                        ));
     
    332331                        derivedReceive->params.push_back( ast::deepCopy( derivedActorRef ) );
    333332                        derivedReceive->params.push_back( ast::deepCopy( derivedMsgRef ) );
    334                         derivedReceive->params.push_back( new PointerType( new PointerType( new StructInstType( actorDecl ) ) ) );
    335                         derivedReceive->params.push_back( new PointerType( new PointerType( new StructInstType( msgDecl ) ) ) );
    336                         derivedReceive->returns.push_back( new EnumInstType( allocationDecl ) );
     333                        derivedReceive->params.push_back( new PointerType( new PointerType( new StructInstType( *actorDecl ) ) ) );
     334                        derivedReceive->params.push_back( new PointerType( new PointerType( new StructInstType( *msgDecl ) ) ) );
     335                        derivedReceive->returns.push_back( new EnumInstType( *allocationDecl ) );
    337336
    338337                        // Generates: allocation (*my_work_fn)( derived_actor &, derived_msg &, actor **, message ** ) = receive;
     
    349348                        // Function type is: allocation (*)( actor &, message & )
    350349                        FunctionType * genericReceive = new FunctionType();
    351                         genericReceive->params.push_back( new ReferenceType( new StructInstType( actorDecl ) ) );
    352                         genericReceive->params.push_back( new ReferenceType( new StructInstType( msgDecl ) ) );
    353                         genericReceive->params.push_back( new PointerType( new PointerType( new StructInstType( actorDecl ) ) ) );
    354                         genericReceive->params.push_back( new PointerType( new PointerType( new StructInstType( msgDecl ) ) ) );
    355                         genericReceive->returns.push_back( new EnumInstType( allocationDecl ) );
     350                        genericReceive->params.push_back( new ReferenceType( new StructInstType( *actorDecl ) ) );
     351                        genericReceive->params.push_back( new ReferenceType( new StructInstType( *msgDecl ) ) );
     352                        genericReceive->params.push_back( new PointerType( new PointerType( new StructInstType( *actorDecl ) ) ) );
     353                        genericReceive->params.push_back( new PointerType( new PointerType( new StructInstType( *msgDecl ) ) ) );
     354                        genericReceive->returns.push_back( new EnumInstType( *allocationDecl ) );
    356355
    357356                        // Generates: allocation (*fn)( actor &, message & ) = (allocation (*)( actor &, message & ))my_work_fn;
     
    379378                                        {
    380379                                                new NameExpr( decl->location, "new_req" ),
    381                                                 new CastExpr( decl->location, new AddressExpr( new NameExpr( decl->location, "receiver" ) ), new PointerType( new StructInstType( actorDecl ) ), ExplicitCast ),
    382                                                 new CastExpr( decl->location, new AddressExpr( new NameExpr( decl->location, "msg" ) ), new PointerType( new StructInstType( msgDecl ) ), ExplicitCast ),
     380                                                new CastExpr( decl->location, new AddressExpr( new NameExpr( decl->location, "receiver" ) ), new PointerType( new StructInstType( *actorDecl ) ), ExplicitCast ),
     381                                                new CastExpr( decl->location, new AddressExpr( new NameExpr( decl->location, "msg" ) ), new PointerType( new StructInstType( *msgDecl ) ), ExplicitCast ),
    383382                                                new NameExpr( decl->location, "fn" )
    384383                                        }
     
    444443  public:
    445444        GenFuncsCreateTables( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls,
    446                 const StructDecl *& requestDecl, const EnumDecl *& allocationDecl, const StructDecl *& actorDecl, const StructDecl *& msgDecl,
     445                const StructDecl ** requestDecl, const EnumDecl ** allocationDecl, const StructDecl ** actorDecl, const StructDecl ** msgDecl,
    447446                FwdDeclTable & forwardDecls ) : actorStructDecls(actorStructDecls), messageStructDecls(messageStructDecls),
    448447                requestDecl(requestDecl), allocationDecl(allocationDecl), actorDecl(actorDecl), msgDecl(msgDecl), forwardDecls(forwardDecls) {}
     
    454453struct FwdDeclOperator : public ast::WithDeclsToAdd {
    455454        unordered_set<const StructDecl *> & actorStructDecls;
    456         unordered_set<const StructDecl *> & messageStructDecls;
     455        unordered_set<const StructDecl *>  & messageStructDecls;
    457456        FwdDeclTable & forwardDecls;
    458457
     
    496495        // for storing through the passes
    497496        // these are populated with various important struct decls
    498         const StructDecl * requestDecl = nullptr;
    499         const EnumDecl * allocationDecl = nullptr;
    500         const StructDecl * actorDecl = nullptr;
    501         const StructDecl * msgDecl = nullptr;
     497        const StructDecl * requestDeclPtr = nullptr;
     498        const EnumDecl * allocationDeclPtr = nullptr;
     499        const StructDecl * actorDeclPtr = nullptr;
     500        const StructDecl * msgDeclPtr = nullptr;
     501
     502        // double pointer to modify local ptrs above
     503        const StructDecl ** requestDecl = &requestDeclPtr;
     504        const EnumDecl ** allocationDecl = &allocationDeclPtr;
     505        const StructDecl ** actorDecl = &actorDeclPtr;
     506        const StructDecl ** msgDecl = &msgDeclPtr;
    502507
    503508        // first pass collects ptrs to allocation enum, request type, and generic receive fn typedef
    504509        // also populates maps of all derived actors and messages
    505         Pass<CollectactorStructDecls>::run( translationUnit, actorStructDecls, messageStructDecls,
    506                 requestDecl, allocationDecl, actorDecl, msgDecl );
     510        Pass<CollectactorStructDecls>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl,
     511                allocationDecl, actorDecl, msgDecl );
    507512
    508513        // check that we have found all the decls we need from <actor.hfa>, if not no need to run the rest of this pass
    509         if ( !allocationDecl || !requestDecl || !actorDecl || !msgDecl )
     514        if ( !allocationDeclPtr || !requestDeclPtr || !actorDeclPtr || !msgDeclPtr )
    510515                return;
    511516
    512517        // second pass locates all receive() routines that overload the generic receive fn
    513518        // it then generates the appropriate operator '|' send routines for the receive routines
    514         Pass<GenFuncsCreateTables>::run( translationUnit, actorStructDecls, messageStructDecls,
    515                 requestDecl, allocationDecl, actorDecl, msgDecl, forwardDecls );
     519        Pass<GenFuncsCreateTables>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl,
     520                allocationDecl, actorDecl, msgDecl, forwardDecls );
    516521
    517522        // The third pass forward declares operator '|' send routines
  • src/InitTweak/GenInit.cpp

    r332e93a r985ff5f  
    164164                                ast::ObjectDecl * arrayDimension = nullptr;
    165165
    166                                 if ( auto ty = dynamic_cast< const ast::TypeExpr * >( arrayType->dimension.get() ) ) {
     166                                const ast::TypeExpr * ty = dynamic_cast< const ast::TypeExpr * >( arrayType->dimension.get() );
     167                                if ( ty ) {
    167168                                        auto inst = ty->type.as<ast::EnumInstType>();
    168                                         if ( inst && !inst->base->is_c_enum() ) {
    169                                                 arrayDimension = new ast::ObjectDecl(
    170                                                         arrayType->dimension->location,
    171                                                         dimensionName.newName(),
    172                                                         new ast::BasicType( ast::BasicKind::UnsignedChar ),
    173                                                         new ast::SingleInit(
     169                                        if ( inst ) {
     170                                                if ( inst->base->isCfa ) {
     171                                                        arrayDimension = new ast::ObjectDecl(
    174172                                                                arrayType->dimension->location,
    175                                                                 ast::ConstantExpr::from_int( arrayType->dimension->location, inst->base->members.size() )
    176                                                         )
    177                                                 );
     173                                                                dimensionName.newName(),
     174                                                                new ast::BasicType( ast::BasicKind::UnsignedChar ),
     175                                                                new ast::SingleInit(
     176                                                                        arrayType->dimension->location,
     177                                                                        ast::ConstantExpr::from_int( arrayType->dimension->location, inst->base->members.size() )
     178                                                                )
     179                                                        );
     180                                                        // return arrayType;
     181                                                }
    178182                                        }
    179183                                }
  • src/Parser/TypeData.cpp

    r332e93a r985ff5f  
    14821482                object->isHidden = ast::EnumDecl::EnumHiding::Hide == ret->hide;
    14831483                object->isMember = true;
    1484                 if ( ret->is_opaque_enum() && cur->has_enumeratorValue() ) {
     1484                if ( ret->isOpaque() && cur->has_enumeratorValue() ) {
    14851485                        SemanticError( td->location, "Opague cannot have an explicit initializer value." );
    14861486                } else if ( cur->has_enumeratorValue() ) {
    14871487                        ast::Expr * initValue;
    1488                         if ( ret->is_typed_enum() ) {
     1488                        if ( ret->isCfa && ret->base ) {
    14891489                                CodeLocation location = cur->enumeratorValue->location;
    14901490                                initValue = new ast::CastExpr( location, maybeMoveBuild( cur->consume_enumeratorValue() ), ret->base );
  • src/ResolvExpr/CastCost.cpp

    r332e93a r985ff5f  
    5353                void postvisit( const ast::EnumInstType * enumInst ) {
    5454                        cost = conversionCost( enumInst, dst, srcIsLvalue, symtab, env );
    55                         if ( enumInst->base->is_typed_enum() ) {
    56                                 auto baseConversionCost =
     55                        if ( enumInst->base->isTyped() ) {
     56                                auto baseConversionCost = 
    5757                                        castCost( enumInst->base->base, dst, srcIsLvalue, symtab, env );
    58                                 cost = baseConversionCost < cost ? baseConversionCost : cost;
     58                                cost = baseConversionCost < cost? baseConversionCost: cost;
    5959                        }
    6060                        static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) };
    6161                        Cost intCost = costCalc( integer, dst, srcIsLvalue, symtab, env );
    6262                        intCost.incSafe();
    63                         cost = intCost < cost ? intCost : cost;
     63                        cost = intCost < cost? intCost: cost;
    6464                }
    6565
  • src/ResolvExpr/CommonType.cpp

    r332e93a r985ff5f  
    386386                } else if ( const ast::EnumInstType * enumInst = dynamic_cast< const ast::EnumInstType * >( type2 ) ) {
    387387                        const ast::EnumDecl* enumDecl = enumInst->base;
    388                         if ( enumDecl->is_c_enum() ) {
     388                        if ( !enumDecl->isCfa ) {
    389389                                ast::BasicKind kind = commonTypes[ basic->kind ][ ast::BasicKind::SignedInt ];
    390390                                if (
     
    654654                                result = param;
    655655                        }
    656                 } else if ( param->base && param->base->is_c_enum() ) {
     656                } else if ( param->base && !param->base->isCfa ) {
    657657                        auto basicType = new ast::BasicType( ast::BasicKind::UnsignedInt );
    658658                        result = commonType( basicType, type2, tenv, need, have, open, widen);
  • src/ResolvExpr/ConversionCost.cpp

    r332e93a r985ff5f  
    246246                }
    247247                if (const ast::EnumInstType * srcAsInst = dynamic_cast< const ast::EnumInstType * >( src )) {
    248                         if ( srcAsInst->base && srcAsInst->base->is_c_enum() ) {
     248                        if (srcAsInst->base && !srcAsInst->base->isCfa) {
    249249                                static const ast::BasicType* integer = new ast::BasicType( ast::BasicKind::UnsignedInt );
    250250                                return ast::Pass<ConversionCost>::read( integer, dst, srcIsLvalue, symtab, env, conversionCost );
     
    324324                conversionCostFromBasicToBasic( basicType, dstAsBasic );
    325325        } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) {
    326                 if ( dstAsEnumInst->base && dstAsEnumInst->base->is_c_enum() ) {
     326                if ( dstAsEnumInst->base && !dstAsEnumInst->base->isCfa ) {
    327327                        cost = Cost::safe;
    328328                }
     
    405405        if ( auto dstInst = dynamic_cast<const ast::EnumInstType *>( dst ) ) {
    406406                cost = enumCastCost(inst, dstInst, symtab, env);
    407         } else if ( inst->base->is_c_enum() ) {
     407        } else if ( !inst->base->isCfa ) {
    408408                static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) };
    409409                cost = costCalc( integer, dst, srcIsLvalue, symtab, env );
     
    455455}
    456456
    457 void ConversionCost::postvisit( const ast::VarArgsType * ) {
     457void ConversionCost::postvisit( const ast::VarArgsType * varArgsType ) {
     458        (void)varArgsType;
    458459        if ( dynamic_cast< const ast::VarArgsType * >( dst ) ) {
    459460                cost = Cost::zero;
     
    461462}
    462463
    463 void ConversionCost::postvisit( const ast::ZeroType * ) {
     464void ConversionCost::postvisit( const ast::ZeroType * zeroType ) {
     465        (void)zeroType;
    464466        if ( dynamic_cast< const ast::ZeroType * >( dst ) ) {
    465467                cost = Cost::zero;
     
    485487                // assuming 0p is supposed to be used for pointers?
    486488        } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) {
    487                 if ( dstAsEnumInst->base && dstAsEnumInst->base->is_c_enum() ) {
     489                if ( dstAsEnumInst->base && !dstAsEnumInst->base->isCfa ) {
    488490                        cost = Cost::safe;
    489491                }
     
    491493}
    492494
    493 void ConversionCost::postvisit( const ast::OneType * ) {
     495void ConversionCost::postvisit( const ast::OneType * oneType ) {
     496        (void)oneType;
    494497        if ( dynamic_cast< const ast::OneType * >( dst ) ) {
    495498                cost = Cost::zero;
     
    505508                }
    506509        } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) {
    507                 if ( dstAsEnumInst->base && dstAsEnumInst->base->is_c_enum() ) {
     510                if ( dstAsEnumInst->base && !dstAsEnumInst->base->isCfa ) {
    508511                        cost = Cost::safe;
    509512                }
  • src/ResolvExpr/ResolveTypeof.cpp

    r332e93a r985ff5f  
    6262                        // replace basetypeof(<enum>) by int
    6363                        auto enumInst = newType.as< ast::EnumInstType >();
    64                         if ( enumInst && (!enumInst->base || enumInst->base->is_c_enum() ) ) {
     64                        if ( enumInst && (!enumInst->base || !enumInst->base->isCfa) ) {
    6565                                newType = new ast::BasicType(
    6666                                        ast::BasicKind::SignedInt, newType->qualifiers, copy(newType->attributes) );
     
    144144
    145145        auto enumInst = decl->type.as<ast::EnumInstType>();
    146         if ( enumInst && !enumInst->base->is_c_enum() ) {
     146        if ( enumInst && enumInst->base->isCfa ) {
    147147                if ( auto init = decl->init.as<ast::SingleInit>() ) {
    148148                        if ( auto initExpr = init->value.as<ast::ConstantExpr>() ) {
    149149                                if ( initExpr->result.as<ast::ZeroType>() ) {
    150                                         auto newInit = new ast::SingleInit( init->location,
     150                                        auto newInit = new ast::SingleInit( init->location, 
    151151                                                ast::UntypedExpr::createCall( init->location, "lowerBound", {} )
    152152                                        );
  • src/Validate/ImplementEnumFunc.cpp

    r332e93a r985ff5f  
    6161        ast::FunctionDecl* genLabelProto() const;
    6262        ast::FunctionDecl* genValueProto() const;
     63        ast::FunctionDecl* genQuasiValueProto() const;
    6364        ast::FunctionDecl* genTypeNameProto() const;
    6465
     
    205206
    206207ast::FunctionDecl* EnumAttrFuncGenerator::genValueProto() const {
    207         assert( decl->is_typed_enum() );
     208        assert (decl->isTyped());
    208209        return genProto(
    209210                "value",
     
    413414void EnumAttrFuncGenerator::genTypedEnumFunction(const ast::EnumAttribute attr) {
    414415        if (attr == ast::EnumAttribute::Value) {
    415                 if ( !decl->is_typed_enum() ) return;
     416                if ( !decl->isTyped() ) return;
    416417                std::vector<ast::ptr<ast::Init>> inits = genValueInit();
    417418                ast::ObjectDecl* arrayProto =
     
    482483
    483484void ImplementEnumFunc::previsit(const ast::EnumDecl* enumDecl) {
    484         if ( !enumDecl->body || enumDecl->is_c_enum() ) return;
     485        if (!enumDecl->body || !enumDecl->isCfa) return;
    485486        ast::EnumInstType enumInst(enumDecl->name);
    486487        enumInst.base = enumDecl;
  • tests/.expect/zero_one.txt

    r332e93a r985ff5f  
    33It's a Number!
    442 2
    5 0 0
    6 42 42
    7 0 0
    8 1 1
    9 42 42
    10 1 1
    11 zero true
    12 zero true
    13 one false
    14 one false
  • tests/Makefile.am

    r332e93a r985ff5f  
    354354        -cp ${test} ${abspath ${@}}
    355355
    356 zero_one-ERR1 : zero_one.cfa ${CFACCBIN}
    357         ${CFACOMPILE_SYNTAX} -DERR1
    358         -cp ${test} ${abspath ${@}}
    359 
    360356ctrl-flow/loop_else : ctrl-flow/loop_else.cfa ${CFACCBIN}
    361357        ${CC} ${AM_CFLAGS} -Wno-superfluous-else $< -o $@
  • tests/zero_one.cfa

    r332e93a r985ff5f  
    3939}
    4040
    41 void testCompats() {
    42     zero_t zero = 0;
    43     one_t one = 1;
    44 
    45     int x = 0;
    46         int xx = zero;
    47 
    48         sout | x | xx;
    49 
    50         x = xx = 42;
    51         sout | x | xx;
    52 
    53         x = 0;
    54         xx = zero;
    55         sout | x | xx;
    56 
    57         int y = 1;
    58         int yy = one;
    59 
    60         sout | y | yy;
    61 
    62         y = yy = 42;
    63         sout | y | yy;
    64 
    65         y = 1;
    66         yy = one;
    67         sout | y | yy;
    68 
    69         void z_helper( int * p, zero_t z ) {
    70                 p = z;  // expect z not reported unused here; expect no missing cast from -Wint-conversion
    71                 sout | "zero" | (bool) (p == 0);
    72         }
    73 
    74         void z_call( int * p, zero_t z ) {
    75                 z_helper(p, z);
    76         }
    77 
    78         void o_helper( int * p, one_t o ) {
    79           #ifdef ERR1
    80                 p = o;
    81           #else
    82                 (void) x;  (void) o;
    83           #endif
    84                 sout | "one" | (bool) (p == 0);
    85         }
    86 
    87         void o_call( int * p, one_t o ) {
    88                 o_helper(p, o);
    89         }
    90 
    91         z_call( &x, 0 );
    92         z_call( &x, zero );
    93 
    94         o_call( &x, 1 );
    95         o_call( &x, one );
    96 }
    97 
    9841int main() {
    9942        testOverloads();
    10043        testInitAssignQueryIncrement();
    101         testCompats();
    10244        return 0;
    10345}
Note: See TracChangeset for help on using the changeset viewer.