Changeset 9d5eacb for src


Ignore:
Timestamp:
Jul 10, 2024, 6:55:54 PM (8 days ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
236f133, 3be81a4
Parents:
725f777f
Message:

Fix the bug with typed anomynous enum got incorrect forward declaration

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.hpp

    r725f777f r9d5eacb  
    2727        static DeclarationNode * newFunction( const std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body );
    2828        static DeclarationNode * newAggregate( ast::AggregateDecl::Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body );
    29         static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, bool typed, DeclarationNode * base = nullptr, EnumHiding hiding = EnumHiding::Visible );
     29        static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, bool isCfa = false, DeclarationNode * base = nullptr, EnumHiding hiding = EnumHiding::Visible );
    3030        static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant );
    3131        static DeclarationNode * newEnumValueGeneric( const std::string * name, InitializerNode * init );
  • src/ResolvExpr/ResolveTypeof.cpp

    r725f777f r9d5eacb  
    6161                if ( typeofType->kind == ast::TypeofType::Basetypeof ) {
    6262                        // replace basetypeof(<enum>) by int
    63                         // if ( newType.as< ast::EnumInstType >() ) {
    64                         //      newType = new ast::BasicType(
    65                         //              ast::BasicKind::SignedInt, newType->qualifiers, copy(newType->attributes) );
    66                         // }
     63                        auto enumInst = newType.as< ast::EnumInstType >();
     64                        if ( enumInst && (!enumInst->base || !enumInst->base->isCfa) ) {
     65                                newType = new ast::BasicType(
     66                                        ast::BasicKind::SignedInt, newType->qualifiers, copy(newType->attributes) );
     67                        }
    6768                        reset_qualifiers(
    6869                                newType,
  • src/Validate/Autogen.cpp

    r725f777f r9d5eacb  
    245245        ast::EnumInstType enumInst( enumDecl->name );
    246246        enumInst.base = enumDecl;
    247         EnumFuncGenerator gen( enumDecl, &enumInst, functionNesting );
    248         gen.generateAndPrependDecls( declsToAddBefore );
     247        if ( enumDecl->isCfa ) {
     248                EnumFuncGenerator gen( enumDecl, &enumInst, functionNesting );
     249                gen.generateAndPrependDecls( declsToAddBefore );
     250        }
    249251
    250252        EnumFuncGenerator gen2( enumDecl, &enumInst, functionNesting );
     
    742744        for ( auto & generator : standardProtos ) {
    743745                ast::FunctionDecl * decl = (this->*generator)();
    744                 // produceForwardDecl( decl ); Done in genForwards
     746                produceForwardDecl( decl );
    745747                genFuncBody( decl );
    746748                if ( CodeGen::isAssignment( decl->name ) ) {
  • src/Validate/ImplementEnumFunc.cpp

    r725f777f r9d5eacb  
    105105                assert(memAsObjectDecl);
    106106                if (auto& init = memAsObjectDecl->init) {
    107                         auto singleInit = init.strict_as<ast::SingleInit>();
    108                         auto nameExpr = singleInit->value.as<ast::NameExpr>();
    109                         if (nameExpr) {
    110                                 auto name = nameExpr->name;
    111                                 if (auto it = std::find_if(decl->members.begin(), decl->members.end(),
    112                                         [name](ast::ptr<ast::Decl> mem_decl) {
    113                                                 return (mem_decl->name == name);
    114                                         }); it != std::end(decl->members)
    115                                 ) {
    116                                         // ast::SingleInit* newInit = new ast::SingleInit(
    117                                         //      init->location, new ast::CastExpr( nameExpr->location,
    118                                         //      nameExpr, new ast::BasicType( ast::BasicKind::UnsignedInt ), ast::ExplicitCast )
    119                                         // );
    120                                         // auto targetInit = (*it).strict_as<ast::ObjectDecl>()->init;
    121                                         // inits.emplace_back( targetInit );
    122                                         auto index = std::distance( decl->members.begin(), it );
    123                                         auto targetInit = inits.at(index).strict_as<ast::SingleInit>();
    124                                         auto targetExpr = targetInit->value;
    125                                         inits.push_back( new ast::SingleInit( targetExpr->location, targetExpr ) );
    126                                         continue;
     107                        if ( auto singleInit = init.as<ast::SingleInit>() ) {
     108                                if ( auto nameExpr = singleInit->value.as<ast::NameExpr>() ) {
     109                                        auto name = nameExpr->name;
     110                                        if (auto it = std::find_if(decl->members.begin(), decl->members.end(),
     111                                                [name](ast::ptr<ast::Decl> mem_decl) {
     112                                                        return (mem_decl->name == name);
     113                                                }); it != std::end(decl->members)
     114                                        ) {
     115                                                auto index = std::distance( decl->members.begin(), it );
     116                                                auto targetInit = inits.at(index).strict_as<ast::SingleInit>();
     117                                                auto targetExpr = targetInit->value;
     118                                                inits.push_back( new ast::SingleInit( targetExpr->location, targetExpr ) );
     119                                                continue;
     120                                        }
    127121                                }
    128122                        }
    129 
    130123                        inits.emplace_back(memAsObjectDecl->init);
    131124                } else {
Note: See TracChangeset for help on using the changeset viewer.