Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Validate/ImplementEnumFunc.cpp

    r90be0cf r63d5b9c8  
    7878        std::vector<ast::ptr<ast::Init>> genValueInit() const;
    7979        ast::ObjectDecl* genAttrArrayProto(
    80                 const CodeLocation& location, const std::string& prefix,
    81                 const ast::Type * type, std::vector<ast::ptr<ast::Init>>& inits ) const;
     80                const ast::EnumAttribute attr, const CodeLocation& location,
     81                std::vector<ast::ptr<ast::Init>>& inits) const;
    8282};
    8383
     
    351351
    352352ast::ObjectDecl* EnumAttrFuncGenerator::genAttrArrayProto(
    353                 const CodeLocation& location, const std::string& prefix,
    354                 const ast::Type * type, std::vector<ast::ptr<ast::Init>>& inits ) const {
     353        const ast::EnumAttribute attr, const CodeLocation& location,
     354        std::vector<ast::ptr<ast::Init>>& inits) const {
    355355        ast::ArrayType* arrT = new ast::ArrayType(
    356                 type,
     356                attr == ast::EnumAttribute::Value
     357                        ? decl->base
     358                        : new ast::PointerType(
     359                                new ast::BasicType(ast::BasicKind::Char, ast::CV::Const)),
    357360                ast::ConstantExpr::from_int(decl->location, decl->members.size()),
    358361                ast::LengthFlag::FixedLen, ast::DimensionFlag::DynamicDim);
     
    360363        ast::ObjectDecl* objDecl =
    361364                new ast::ObjectDecl(
    362                         decl->location, prefix + decl->name,
     365                        decl->location, decl->getUnmangeldArrayName( attr ),
    363366                        arrT, new ast::ListInit( location, std::move( inits ) ),
    364367                        ast::Storage::Static, ast::Linkage::AutoGen );
     
    414417void EnumAttrFuncGenerator::genTypedEnumFunction(const ast::EnumAttribute attr) {
    415418        if (attr == ast::EnumAttribute::Value) {
    416                 if ( !decl->isTyped() ) return;
    417                 std::vector<ast::ptr<ast::Init>> inits = genValueInit();
    418                 ast::ObjectDecl* arrayProto =
    419                         genAttrArrayProto( getLocation(), "values_", decl->base, inits );
    420                 forwards.push_back(arrayProto);
    421 
    422                 ast::FunctionDecl* funcProto = genValueProto();
    423                 produceForwardDecl(funcProto);
    424                 genValueOrLabelBody(funcProto, arrayProto);
    425                 produceDecl(funcProto);
     419                if (decl->isTyped()) {
     420                        // TypedEnum's backing arrays
     421                        std::vector<ast::ptr<ast::Init>> inits = genValueInit();
     422                        ast::ObjectDecl* arrayProto =
     423                                genAttrArrayProto(attr, getLocation(), inits);
     424                        forwards.push_back(arrayProto);
     425
     426                        ast::FunctionDecl* funcProto = genValueProto();
     427                        produceForwardDecl(funcProto);
     428                        genValueOrLabelBody(funcProto, arrayProto);
     429                        produceDecl(funcProto);
     430                } 
     431                // else {
     432                //      ast::FunctionDecl* funcProto = genQuasiValueProto();
     433                //      produceForwardDecl(funcProto);
     434                //      // genQuasiValueBody(funcProto);
     435                //      produceDecl(funcProto);
     436                // }
    426437        } else if (attr == ast::EnumAttribute::Label) {
    427438                std::vector<ast::ptr<ast::Init>> inits = genLabelInit();
    428                 const ast::Type * type = new ast::PointerType(
    429                         new ast::BasicType( ast::BasicKind::Char, ast::CV::Const ) );
    430439                ast::ObjectDecl* arrayProto =
    431                         genAttrArrayProto( getLocation(), "labels_", type, inits );
     440                        genAttrArrayProto(attr, getLocation(), inits);
    432441                forwards.push_back(arrayProto);
    433442                ast::FunctionDecl* funcProto = genLabelProto();
     
    436445                produceDecl(funcProto);
    437446        } else {
    438                 assert( attr == ast::EnumAttribute::Posn );
    439447                ast::FunctionDecl* funcProto = genPosnProto();
    440448                produceForwardDecl(funcProto);
Note: See TracChangeset for help on using the changeset viewer.