Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Validate/Autogen.cpp

    r59c8dff rb262cb3  
    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 
    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;
     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;
    196191        }
    197192
     
    445440
    446441                auto * paramType = ast::deepCopy( member->get_type() );
    447                 paramType->attributes.clear();
     442                erase_if( paramType->attributes, []( ast::Attribute const * attr ){
     443                        return !attr->isValidOnFuncParam();
     444                } );
    448445                ast::ObjectDecl * param = new ast::ObjectDecl(
    449446                        getLocation(), member->name, paramType );
     
    747744                        }
    748745                );
    749                 // auto fname = ast::getFunctionName( callExpr );
    750                 // if (fname == "posE" ) {
    751                 //      std::cerr << "Found posE autogen" << std::endl;
    752                 // }
    753746                functionDecl->stmts = new ast::CompoundStmt( location,
    754747                        { new ast::ExprStmt( location, callExpr ) }
     
    801794}
    802795
    803 struct PseudoFuncGenerateRoutine final :
    804                 public ast::WithDeclsToAdd<>,
    805                 public ast::WithShortCircuiting {
    806         void previsit( const ast::EnumDecl * enumDecl );
    807 };
    808 
    809 void 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 
    854796} // namespace
    855797
    856798void autogenerateRoutines( ast::TranslationUnit & translationUnit ) {
    857799        ast::Pass<AutogenerateRoutines>::run( translationUnit );
    858         // ast::Pass<PseudoFuncGenerateRoutine>::run( translationUnit );
    859800}
    860801
Note: See TracChangeset for help on using the changeset viewer.