Changeset 06d75931 for src/Validate


Ignore:
Timestamp:
Oct 26, 2024, 8:17:20 AM (14 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
14c31eb
Parents:
3a08cb1 (diff), d031f7f (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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Validate/ImplementEnumFunc.cpp

    r3a08cb1 r06d75931  
    7878        std::vector<ast::ptr<ast::Init>> genValueInit() const;
    7979        ast::ObjectDecl* genAttrArrayProto(
    80                 const ast::EnumAttribute attr, const CodeLocation& location,
    81                 std::vector<ast::ptr<ast::Init>>& inits) const;
     80                const CodeLocation& location, const std::string& prefix,
     81                const ast::Type * type, std::vector<ast::ptr<ast::Init>>& inits ) const;
    8282};
    8383
     
    351351
    352352ast::ObjectDecl* EnumAttrFuncGenerator::genAttrArrayProto(
    353         const ast::EnumAttribute attr, const CodeLocation& location,
    354         std::vector<ast::ptr<ast::Init>>& inits) const {
     353                const CodeLocation& location, const std::string& prefix,
     354                const ast::Type * type, std::vector<ast::ptr<ast::Init>>& inits ) const {
    355355        ast::ArrayType* arrT = new ast::ArrayType(
    356                 attr == ast::EnumAttribute::Value
    357                         ? decl->base
    358                         : new ast::PointerType(
    359                                 new ast::BasicType(ast::BasicKind::Char, ast::CV::Const)),
     356                type,
    360357                ast::ConstantExpr::from_int(decl->location, decl->members.size()),
    361358                ast::LengthFlag::FixedLen, ast::DimensionFlag::DynamicDim);
     
    363360        ast::ObjectDecl* objDecl =
    364361                new ast::ObjectDecl(
    365                         decl->location, decl->getUnmangeldArrayName( attr ),
     362                        decl->location, prefix + decl->name,
    366363                        arrT, new ast::ListInit( location, std::move( inits ) ),
    367364                        ast::Storage::Static, ast::Linkage::AutoGen );
     
    417414void EnumAttrFuncGenerator::genTypedEnumFunction(const ast::EnumAttribute attr) {
    418415        if (attr == ast::EnumAttribute::Value) {
    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                 // }
     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);
    437426        } else if (attr == ast::EnumAttribute::Label) {
    438427                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 ) );
    439430                ast::ObjectDecl* arrayProto =
    440                         genAttrArrayProto(attr, getLocation(), inits);
     431                        genAttrArrayProto( getLocation(), "labels_", type, inits );
    441432                forwards.push_back(arrayProto);
    442433                ast::FunctionDecl* funcProto = genLabelProto();
     
    445436                produceDecl(funcProto);
    446437        } else {
     438                assert( attr == ast::EnumAttribute::Posn );
    447439                ast::FunctionDecl* funcProto = genPosnProto();
    448440                produceForwardDecl(funcProto);
Note: See TracChangeset for help on using the changeset viewer.