| 742 | } |
| 743 | |
| 744 | static bool appendBuiltinModuleContent ( Module * target, ProgramPtr program, const string & modName ) { |
| 745 | if ( !program ) { |
| 746 | DAS_FATAL_ERROR("builtin module did not parse %s\n", modName.c_str()); |
| 747 | return false; |
| 748 | } |
| 749 | if (program->failed()) { |
| 750 | TextWriter issues; |
| 751 | for (auto & err : program->errors) { |
| 752 | issues << reportError(err.at, err.what, err.extra, err.fixme, err.cerr); |
| 753 | } |
| 754 | DAS_FATAL_ERROR("%s\nbuiltin module did not compile %s\n", issues.str().c_str(), modName.c_str()); |
| 755 | return false; |
| 756 | } |
| 757 | // append content into target module |
| 758 | program->thisModule->aliasTypes.foreach([&](auto aliasTypePtr){ |
| 759 | target->addAlias(aliasTypePtr); |
| 760 | }); |
| 761 | program->thisModule->enumerations.foreach([&](auto penum){ |
| 762 | target->addEnumeration(penum); |
| 763 | }); |
| 764 | program->thisModule->structures.foreach([&](auto pst){ |
| 765 | target->addStructure(pst); |
| 766 | }); |
| 767 | program->thisModule->generics.foreach([&](auto fn){ |
| 768 | target->addGeneric(fn); |
| 769 | }); |
| 770 | program->thisModule->globals.foreach([&](auto gvar){ |
| 771 | target->addVariable(gvar); |
| 772 | }); |
| 773 | program->thisModule->functions.foreach([&](auto fn){ |
| 774 | target->addFunction(fn); |
| 775 | }); |
| 776 | for (auto & rqm : program->thisModule->requireModule) { |
| 777 | if ( rqm.first != target ) { |
| 778 | target->requireModule[rqm.first] |= rqm.second; |
| 779 | } |
| 780 | } |
| 781 | // macros |
| 782 | auto ptm = program->thisModule.get(); |
| 783 | if ( ptm->macroContext ) { |
| 784 | swap ( target->macroContext, ptm->macroContext ); |
| 785 | for ( auto & [key, fna] : ptm->handleTypes ) { |
| 786 | target->addAnnotation(fna); |
| 787 | } |
| 788 | } |
| 789 | for (auto & m : ptm->simulateMacros) target->simulateMacros.push_back(std::move(m)); |
| 790 | for (auto & m : ptm->captureMacros) target->captureMacros.push_back(std::move(m)); |
| 791 | for (auto & m : ptm->forLoopMacros) target->forLoopMacros.push_back(std::move(m)); |
| 792 | for (auto & m : ptm->variantMacros) target->variantMacros.push_back(std::move(m)); |
| 793 | for (auto & m : ptm->macros) target->macros.push_back(std::move(m)); |
| 794 | for (auto & m : ptm->inferMacros) target->inferMacros.push_back(std::move(m)); |
| 795 | for (auto & m : ptm->optimizationMacros) target->optimizationMacros.push_back(std::move(m)); |
| 796 | for (auto & m : ptm->lintMacros) target->lintMacros.push_back(std::move(m)); |
| 797 | for (auto & m : ptm->globalLintMacros) target->globalLintMacros.push_back(std::move(m)); |
| 798 | for ( auto & rm : ptm->readMacros ) { |
| 799 | rm.second->seal(target); |
| 800 | target->readMacros[rm.first] = std::move(rm.second); |
| 801 | } |
no test coverage detected