Changes in src/Validate/Autogen.cpp [b262cb3:59c8dff]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Validate/Autogen.cpp
rb262cb3 r59c8dff 186 186 // could possibly use a new linkage type. For now we just make the 187 187 // 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; 191 196 } 192 197 … … 440 445 441 446 auto * paramType = ast::deepCopy( member->get_type() ); 442 erase_if( paramType->attributes, []( ast::Attribute const * attr ){ 443 return !attr->isValidOnFuncParam(); 444 } ); 447 paramType->attributes.clear(); 445 448 ast::ObjectDecl * param = new ast::ObjectDecl( 446 449 getLocation(), member->name, paramType ); … … 744 747 } 745 748 ); 749 // auto fname = ast::getFunctionName( callExpr ); 750 // if (fname == "posE" ) { 751 // std::cerr << "Found posE autogen" << std::endl; 752 // } 746 753 functionDecl->stmts = new ast::CompoundStmt( location, 747 754 { new ast::ExprStmt( location, callExpr ) } … … 794 801 } 795 802 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 796 854 } // namespace 797 855 798 856 void autogenerateRoutines( ast::TranslationUnit & translationUnit ) { 799 857 ast::Pass<AutogenerateRoutines>::run( translationUnit ); 858 // ast::Pass<PseudoFuncGenerateRoutine>::run( translationUnit ); 800 859 } 801 860
Note:
See TracChangeset
for help on using the changeset viewer.