Changeset 59c8dff for src/Validate


Ignore:
Timestamp:
Jan 19, 2024, 2:42:58 AM (4 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
f988834
Parents:
8b4faf6
Message:

Draft Implementation for enum position pesudo function (posE). EnumPosExpr? is mostly irrelevant for now. It is used in development/code probing and will be removed later

Location:
src/Validate
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Validate/Autogen.cpp

    r8b4faf6 r59c8dff  
    186186                // could possibly use a new linkage type. For now we just make the
    187187                // basic ones intrinsic to code-gen them as C assignments.
    188                 const auto & real_type = decl->base;
    189                 const auto & basic = real_type.as<ast::BasicType>();
    190                 if(!real_type || (basic && basic->isInteger())) proto_linkage = ast::Linkage::Intrinsic;
     188                // const auto & real_type = decl->base;
     189                // const auto & basic = real_type.as<ast::BasicType>();
     190
     191                // if(!real_type || (basic && basic->isInteger())) proto_linkage = ast::Linkage::Intrinsic;
     192
     193                // Turns other enumeration type into Intrinstic as well to temporarily fix the recursive
     194                // construction bug
     195                proto_linkage = ast::Linkage::Intrinsic;
    191196        }
    192197
     
    742747                        }
    743748                );
     749                // auto fname = ast::getFunctionName( callExpr );
     750                // if (fname == "posE" ) {
     751                //      std::cerr << "Found posE autogen" << std::endl;
     752                // }
    744753                functionDecl->stmts = new ast::CompoundStmt( location,
    745754                        { new ast::ExprStmt( location, callExpr ) }
     
    792801}
    793802
     803struct PseudoFuncGenerateRoutine final :
     804                public ast::WithDeclsToAdd<>,
     805                public ast::WithShortCircuiting {
     806        void previsit( const ast::EnumDecl * enumDecl );
     807};
     808
     809void PseudoFuncGenerateRoutine::previsit( const ast::EnumDecl * enumDecl ) {
     810        const CodeLocation& location = enumDecl->location;
     811        if ( enumDecl->members.size() == 0 || !enumDecl->base || enumDecl->name == "" ) return;
     812
     813        std::vector<ast::ptr<ast::Init>> inits;
     814        std::vector<ast::ptr<ast::Init>> labels;
     815        for ( const ast::Decl * mem: enumDecl->members ) {
     816                auto memAsObjectDecl = dynamic_cast< const ast::ObjectDecl * >( mem );
     817                inits.emplace_back( memAsObjectDecl->init );
     818                labels.emplace_back( new ast::SingleInit(
     819                        location, ast::ConstantExpr::from_string(location, mem->name) ) );
     820        }
     821        auto init = new ast::ListInit( location, std::move( inits ) );
     822        auto label_strings = new ast::ListInit( location, std::move(labels) );
     823        auto values = new ast::ObjectDecl(
     824                location,
     825                "__enum_values_"+enumDecl->name,
     826                new ast::ArrayType(
     827                        // new ast::PointerType( new ast::BasicType{ ast::BasicType::Char} ),
     828                        enumDecl->base,
     829                        ast::ConstantExpr::from_int( location, enumDecl->members.size() ),
     830                        ast::LengthFlag::FixedLen, ast::DimensionFlag::DynamicDim
     831                )
     832                ,init
     833                ,
     834                ast::Storage::Static,
     835                ast::Linkage::AutoGen
     836        );
     837        auto label_arr = new ast::ObjectDecl(
     838                location,
     839                "__enum_labels_"+enumDecl->name,
     840                new ast::ArrayType(
     841                        new ast::PointerType( new ast::BasicType{ ast::BasicType::Char} ),
     842                        ast::ConstantExpr::from_int( location, enumDecl->members.size() ),
     843                        ast::LengthFlag::FixedLen, ast::DimensionFlag::DynamicDim
     844                ),
     845                label_strings,
     846                ast::Storage::Static,
     847                ast::Linkage::AutoGen
     848        );
     849
     850        declsToAddAfter.push_back( values );
     851        declsToAddAfter.push_back( label_arr );
     852}
     853
    794854} // namespace
    795855
    796856void autogenerateRoutines( ast::TranslationUnit & translationUnit ) {
    797857        ast::Pass<AutogenerateRoutines>::run( translationUnit );
     858        // ast::Pass<PseudoFuncGenerateRoutine>::run( translationUnit );
    798859}
    799860
  • src/Validate/module.mk

    r8b4faf6 r59c8dff  
    5252        Validate/ReturnCheck.hpp \
    5353        Validate/VerifyCtorDtorAssign.cpp \
    54         Validate/VerifyCtorDtorAssign.hpp
     54        Validate/VerifyCtorDtorAssign.hpp \
     55        Validate/ReplacePseudoFunc.cpp \
     56        Validate/ReplacePseudoFunc.hpp
    5557
    5658SRCDEMANGLE += $(SRC_VALIDATE)
Note: See TracChangeset for help on using the changeset viewer.