Changeset 332e93a for src


Ignore:
Timestamp:
Feb 4, 2025, 9:18:54 PM (11 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
090b076
Parents:
985ff5f (diff), 1ee74df (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

Location:
src
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Decl.cpp

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

    r985ff5f r332e93a  
    306306enum class EnumAttribute{ Value, Posn, Label };
    307307
    308 /// enum declaration `enum Foo { ... };`
     308/// enum declaration `enum Foo { ... };` or `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
    319323        EnumDecl( const CodeLocation& loc, const std::string& name, bool isCfa = false,
    320324                std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall,
     
    331335        const char * typeString() const override { return aggrString( Enum ); }
    332336
    333         bool isTyped() const;
    334         bool isOpaque() const;
    335337private:
    336338        EnumDecl * clone() const override { return new EnumDecl{ *this }; }
  • src/AST/Util.cpp

    r985ff5f r332e93a  
    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.
     90void isEnumerationConsistent( const EnumDecl * node ) {
     91        if ( node->is_c_enum() ) {
     92                assert( nullptr == node->base );
     93        }
    8794}
    8895
     
    135142                previsit( (const ParseNode *)node );
    136143                functionDeclMatchesType( node );
     144        }
     145
     146        void previsit( const EnumDecl * node ) {
     147                previsit( (const ParseNode *)node );
     148                isEnumerationConsistent( node );
    137149        }
    138150
  • src/CodeGen/CodeGenerator.cpp

    r985ff5f r332e93a  
    130130        // TODO: Which means the ast::Pass is just providing a default no visit?
    131131        visit_children = false;
     132        changeState_ArgToIntrinsic(false);
    132133}
    133134
     
    466467                if ( var->var->linkage == ast::Linkage::Intrinsic &&
    467468                                ( opInfo = operatorLookup( var->var->name ) ) ) {
     469                        changeState_ArgToIntrinsic(true);
    468470                        auto arg = expr->args.begin();
    469471                        switch ( opInfo->type ) {
     
    558560        if ( auto name = expr->func.as<ast::NameExpr>() ) {
    559561                if ( const OperatorInfo * opInfo = operatorLookup( name->name ) ) {
     562                        changeState_ArgToIntrinsic(true);
    560563                        auto arg = expr->args.begin();
    561564                        switch ( opInfo->type ) {
     
    743746        extension( expr );
    744747        const OperatorInfo * opInfo;
    745         if ( expr->var->linkage == ast::Linkage::Intrinsic
     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
    746756                        && ( opInfo = operatorLookup( expr->var->name ) )
    747757                        && opInfo->type == OT_CONSTANT ) {
  • src/CodeGen/CodeGenerator.hpp

    r985ff5f r332e93a  
    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        }
    183190};
    184191
  • src/CodeGen/GenType.cpp

    r985ff5f r332e93a  
    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.pretty ? "zero_t " : "long int ") + result;
     270        result = ( options.genC ? "long int /*zero_t*/ " : "zero_t " ) + 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.pretty ? "one_t " : "long int ") + result;
     276        result = ( options.genC ? "long int /*one_t*/ " : "one_t " ) + result;
    277277        handleQualifiers( type );
    278278}
  • src/CodeGen/Generate.cpp

    r985ff5f r332e93a  
    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        };
    4859} // namespace
    4960
     
    5263        erase_if( translationUnit.decls, shouldClean );
    5364        ast::Pass<TreeCleaner>::run( translationUnit );
     65        ast::Pass<ZeroOneObjectHider>::run( translationUnit );
    5466
    5567        ast::Pass<CodeGenerator> cgv( os,
  • src/Concurrency/Actors.cpp

    r985ff5f r332e93a  
    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" ) *requestDecl = decl;
    55                 else {
     53                        msgDecl = decl;
     54                } else if( decl->name == "request" ) {
     55                        requestDecl = decl;
     56                } else {
    5657                        GuardValue(insideStruct);
    5758                        insideStruct = true;
     
    7374        // this collects the derived actor and message struct decl ptrs
    7475        void postvisit( const StructInstType * node ) {
    75                 if ( ! *actorDecl || ! *msgDecl ) return;
     76                if ( !actorDecl || !msgDecl ) return;
    7677                if ( insideStruct && !namedDecl ) {
    7778                        auto actorIter = actorStructDecls.find( node->aggr() );
     
    8990  public:
    9091        CollectactorStructDecls( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls,
    91                 const StructDecl ** requestDecl, const EnumDecl ** allocationDecl, const StructDecl ** actorDecl, const StructDecl ** msgDecl )
     92                const StructDecl *& requestDecl, const EnumDecl *& allocationDecl, const StructDecl *& actorDecl, const StructDecl *& msgDecl )
    9293                : actorStructDecls( actorStructDecls ), messageStructDecls( messageStructDecls ), requestDecl( requestDecl ),
    9394                allocationDecl( allocationDecl ), actorDecl(actorDecl), msgDecl(msgDecl) {}
     
    196197struct GenFuncsCreateTables : public ast::WithDeclsToAdd {
    197198        unordered_set<const StructDecl *> & actorStructDecls;
    198         unordered_set<const StructDecl *>  & messageStructDecls;
    199         const StructDecl ** requestDecl;
    200         const EnumDecl ** allocationDecl;
    201         const StructDecl ** actorDecl;
    202         const StructDecl ** msgDecl;
     199        unordered_set<const StructDecl *> & messageStructDecls;
     200        const StructDecl *& requestDecl;
     201        const EnumDecl *& allocationDecl;
     202        const StructDecl *& actorDecl;
     203        const StructDecl *& msgDecl;
    203204        FwdDeclTable & forwardDecls;
    204205
     
    279280                                                decl->location,
    280281                                                "base_actor",
    281                                                 new PointerType( new PointerType( new StructInstType( *actorDecl ) ) )
     282                                                new PointerType( new PointerType( new StructInstType( actorDecl ) ) )
    282283                                        ),
    283284                                        new ObjectDecl(
    284285                                                decl->location,
    285286                                                "base_msg",
    286                                                 new PointerType( new PointerType( new StructInstType( *msgDecl ) ) )
     287                                                new PointerType( new PointerType( new StructInstType( msgDecl ) ) )
    287288                                        )
    288289                                },                      // params
     
    291292                                                decl->location,
    292293                                                "__CFA_receive_wrap_ret",
    293                                                 new EnumInstType( *allocationDecl )
     294                                                new EnumInstType( allocationDecl )
    294295                                        )
    295296                                },
     
    323324                                        decl->location,
    324325                                        "new_req",
    325                                         new StructInstType( *requestDecl )
     326                                        new StructInstType( requestDecl )
    326327                                )
    327328                        ));
     
    331332                        derivedReceive->params.push_back( ast::deepCopy( derivedActorRef ) );
    332333                        derivedReceive->params.push_back( ast::deepCopy( derivedMsgRef ) );
    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 ) );
     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 ) );
    336337
    337338                        // Generates: allocation (*my_work_fn)( derived_actor &, derived_msg &, actor **, message ** ) = receive;
     
    348349                        // Function type is: allocation (*)( actor &, message & )
    349350                        FunctionType * genericReceive = new FunctionType();
    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 ) );
     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 ) );
    355356
    356357                        // Generates: allocation (*fn)( actor &, message & ) = (allocation (*)( actor &, message & ))my_work_fn;
     
    378379                                        {
    379380                                                new NameExpr( decl->location, "new_req" ),
    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 ),
     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 ),
    382383                                                new NameExpr( decl->location, "fn" )
    383384                                        }
     
    443444  public:
    444445        GenFuncsCreateTables( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls,
    445                 const StructDecl ** requestDecl, const EnumDecl ** allocationDecl, const StructDecl ** actorDecl, const StructDecl ** msgDecl,
     446                const StructDecl *& requestDecl, const EnumDecl *& allocationDecl, const StructDecl *& actorDecl, const StructDecl *& msgDecl,
    446447                FwdDeclTable & forwardDecls ) : actorStructDecls(actorStructDecls), messageStructDecls(messageStructDecls),
    447448                requestDecl(requestDecl), allocationDecl(allocationDecl), actorDecl(actorDecl), msgDecl(msgDecl), forwardDecls(forwardDecls) {}
     
    453454struct FwdDeclOperator : public ast::WithDeclsToAdd {
    454455        unordered_set<const StructDecl *> & actorStructDecls;
    455         unordered_set<const StructDecl *>  & messageStructDecls;
     456        unordered_set<const StructDecl *> & messageStructDecls;
    456457        FwdDeclTable & forwardDecls;
    457458
     
    495496        // for storing through the passes
    496497        // these are populated with various important struct decls
    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;
     498        const StructDecl * requestDecl = nullptr;
     499        const EnumDecl * allocationDecl = nullptr;
     500        const StructDecl * actorDecl = nullptr;
     501        const StructDecl * msgDecl = nullptr;
    507502
    508503        // first pass collects ptrs to allocation enum, request type, and generic receive fn typedef
    509504        // also populates maps of all derived actors and messages
    510         Pass<CollectactorStructDecls>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl,
    511                 allocationDecl, actorDecl, msgDecl );
     505        Pass<CollectactorStructDecls>::run( translationUnit, actorStructDecls, messageStructDecls,
     506                requestDecl, allocationDecl, actorDecl, msgDecl );
    512507
    513508        // check that we have found all the decls we need from <actor.hfa>, if not no need to run the rest of this pass
    514         if ( !allocationDeclPtr || !requestDeclPtr || !actorDeclPtr || !msgDeclPtr )
     509        if ( !allocationDecl || !requestDecl || !actorDecl || !msgDecl )
    515510                return;
    516511
    517512        // second pass locates all receive() routines that overload the generic receive fn
    518513        // it then generates the appropriate operator '|' send routines for the receive routines
    519         Pass<GenFuncsCreateTables>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl,
    520                 allocationDecl, actorDecl, msgDecl, forwardDecls );
     514        Pass<GenFuncsCreateTables>::run( translationUnit, actorStructDecls, messageStructDecls,
     515                requestDecl, allocationDecl, actorDecl, msgDecl, forwardDecls );
    521516
    522517        // The third pass forward declares operator '|' send routines
  • src/InitTweak/GenInit.cpp

    r985ff5f r332e93a  
    164164                                ast::ObjectDecl * arrayDimension = nullptr;
    165165
    166                                 const ast::TypeExpr * ty = dynamic_cast< const ast::TypeExpr * >( arrayType->dimension.get() );
    167                                 if ( ty ) {
     166                                if ( auto ty = dynamic_cast< const ast::TypeExpr * >( arrayType->dimension.get() ) ) {
    168167                                        auto inst = ty->type.as<ast::EnumInstType>();
    169                                         if ( inst ) {
    170                                                 if ( inst->base->isCfa ) {
    171                                                         arrayDimension = new ast::ObjectDecl(
     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(
    172174                                                                arrayType->dimension->location,
    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                                                 }
     175                                                                ast::ConstantExpr::from_int( arrayType->dimension->location, inst->base->members.size() )
     176                                                        )
     177                                                );
    182178                                        }
    183179                                }
  • src/Parser/TypeData.cpp

    r985ff5f r332e93a  
    14821482                object->isHidden = ast::EnumDecl::EnumHiding::Hide == ret->hide;
    14831483                object->isMember = true;
    1484                 if ( ret->isOpaque() && cur->has_enumeratorValue() ) {
     1484                if ( ret->is_opaque_enum() && 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->isCfa && ret->base ) {
     1488                        if ( ret->is_typed_enum() ) {
    14891489                                CodeLocation location = cur->enumeratorValue->location;
    14901490                                initValue = new ast::CastExpr( location, maybeMoveBuild( cur->consume_enumeratorValue() ), ret->base );
  • src/ResolvExpr/CastCost.cpp

    r985ff5f r332e93a  
    5353                void postvisit( const ast::EnumInstType * enumInst ) {
    5454                        cost = conversionCost( enumInst, dst, srcIsLvalue, symtab, env );
    55                         if ( enumInst->base->isTyped() ) {
    56                                 auto baseConversionCost = 
     55                        if ( enumInst->base->is_typed_enum() ) {
     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

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

    r985ff5f r332e93a  
    246246                }
    247247                if (const ast::EnumInstType * srcAsInst = dynamic_cast< const ast::EnumInstType * >( src )) {
    248                         if (srcAsInst->base && !srcAsInst->base->isCfa) {
     248                        if ( srcAsInst->base && srcAsInst->base->is_c_enum() ) {
    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->isCfa ) {
     326                if ( dstAsEnumInst->base && dstAsEnumInst->base->is_c_enum() ) {
    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->isCfa ) {
     407        } else if ( inst->base->is_c_enum() ) {
    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 * varArgsType ) {
    458         (void)varArgsType;
     457void ConversionCost::postvisit( const ast::VarArgsType * ) {
    459458        if ( dynamic_cast< const ast::VarArgsType * >( dst ) ) {
    460459                cost = Cost::zero;
     
    462461}
    463462
    464 void ConversionCost::postvisit( const ast::ZeroType * zeroType ) {
    465         (void)zeroType;
     463void ConversionCost::postvisit( const ast::ZeroType * ) {
    466464        if ( dynamic_cast< const ast::ZeroType * >( dst ) ) {
    467465                cost = Cost::zero;
     
    487485                // assuming 0p is supposed to be used for pointers?
    488486        } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) {
    489                 if ( dstAsEnumInst->base && !dstAsEnumInst->base->isCfa ) {
     487                if ( dstAsEnumInst->base && dstAsEnumInst->base->is_c_enum() ) {
    490488                        cost = Cost::safe;
    491489                }
     
    493491}
    494492
    495 void ConversionCost::postvisit( const ast::OneType * oneType ) {
    496         (void)oneType;
     493void ConversionCost::postvisit( const ast::OneType * ) {
    497494        if ( dynamic_cast< const ast::OneType * >( dst ) ) {
    498495                cost = Cost::zero;
     
    508505                }
    509506        } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) {
    510                 if ( dstAsEnumInst->base && !dstAsEnumInst->base->isCfa ) {
     507                if ( dstAsEnumInst->base && dstAsEnumInst->base->is_c_enum() ) {
    511508                        cost = Cost::safe;
    512509                }
  • src/ResolvExpr/ResolveTypeof.cpp

    r985ff5f r332e93a  
    6262                        // replace basetypeof(<enum>) by int
    6363                        auto enumInst = newType.as< ast::EnumInstType >();
    64                         if ( enumInst && (!enumInst->base || !enumInst->base->isCfa) ) {
     64                        if ( enumInst && (!enumInst->base || enumInst->base->is_c_enum() ) ) {
    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->isCfa ) {
     146        if ( enumInst && !enumInst->base->is_c_enum() ) {
    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

    r985ff5f r332e93a  
    6161        ast::FunctionDecl* genLabelProto() const;
    6262        ast::FunctionDecl* genValueProto() const;
    63         ast::FunctionDecl* genQuasiValueProto() const;
    6463        ast::FunctionDecl* genTypeNameProto() const;
    6564
     
    206205
    207206ast::FunctionDecl* EnumAttrFuncGenerator::genValueProto() const {
    208         assert (decl->isTyped());
     207        assert( decl->is_typed_enum() );
    209208        return genProto(
    210209                "value",
     
    414413void EnumAttrFuncGenerator::genTypedEnumFunction(const ast::EnumAttribute attr) {
    415414        if (attr == ast::EnumAttribute::Value) {
    416                 if ( !decl->isTyped() ) return;
     415                if ( !decl->is_typed_enum() ) return;
    417416                std::vector<ast::ptr<ast::Init>> inits = genValueInit();
    418417                ast::ObjectDecl* arrayProto =
     
    483482
    484483void ImplementEnumFunc::previsit(const ast::EnumDecl* enumDecl) {
    485         if (!enumDecl->body || !enumDecl->isCfa) return;
     484        if ( !enumDecl->body || enumDecl->is_c_enum() ) return;
    486485        ast::EnumInstType enumInst(enumDecl->name);
    487486        enumInst.base = enumDecl;
Note: See TracChangeset for help on using the changeset viewer.