Skip to content

Commit 27e52a6

Browse files
Teemperorvgvassilev
authored andcommitted
[cxxmodules] Move foreachHeader to TClingUtils
We weant to use this functionality in other parts of ROOT, so we should move it out of rootcling.
1 parent bb3562d commit 27e52a6

File tree

3 files changed

+35
-28
lines changed

3 files changed

+35
-28
lines changed

core/clingutils/res/TClingUtils.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414

1515
#include "RConversionRuleParser.h"
1616

17+
#include <functional>
1718
#include <set>
1819
#include <string>
1920
#include <unordered_set>
2021

2122
//#include <atomic>
2223
#include <stdlib.h>
2324

25+
#include "clang/Basic/Module.h"
26+
2427
namespace llvm {
2528
class StringRef;
2629
}
@@ -38,7 +41,6 @@ namespace clang {
3841
class DeclaratorDecl;
3942
class FieldDecl;
4043
class FunctionDecl;
41-
class Module;
4244
class NamedDecl;
4345
class ParmVarDecl;
4446
class PresumedLoc;
@@ -457,6 +459,9 @@ ROOT::ESTLType IsSTLContainer(const clang::FieldDecl &m);
457459
//______________________________________________________________________________
458460
int IsSTLContainer(const clang::CXXBaseSpecifier &base);
459461

462+
void foreachHeaderInModule(const clang::Module &module,
463+
const std::function<void(const clang::Module::Header &)> &closure);
464+
460465
//______________________________________________________________________________
461466
const char *ShortTypeName(const char *typeDesc);
462467

core/clingutils/src/TClingUtils.cxx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,6 +2556,33 @@ int ROOT::TMetaUtils::IsSTLContainer(const clang::CXXBaseSpecifier &base)
25562556
else return ROOT::kNotSTL;
25572557
}
25582558

2559+
////////////////////////////////////////////////////////////////////////////////
2560+
/// Calls the given lambda on every header in the given module.
2561+
void ROOT::TMetaUtils::foreachHeaderInModule(const clang::Module &module,
2562+
const std::function<void(const clang::Module::Header &)> &closure)
2563+
{
2564+
// Iterates over all headers in a module and calls the closure on each.
2565+
2566+
// FIXME: We currently have to hardcode '4' to do this. Maybe we
2567+
// will have a nicer way to do this in the future.
2568+
// NOTE: This is on purpose '4', not '5' which is the size of the
2569+
// vector. The last element is the list of excluded headers which we
2570+
// obviously don't want to check here.
2571+
const std::size_t publicHeaderIndex = 4;
2572+
2573+
// Integrity check in case this array changes its size at some point.
2574+
const std::size_t maxArrayLength = ((sizeof module.Headers) / (sizeof *module.Headers));
2575+
static_assert(publicHeaderIndex + 1 == maxArrayLength,
2576+
"'Headers' has changed it's size, we need to update publicHeaderIndex");
2577+
2578+
for (std::size_t i = 0; i < publicHeaderIndex; i++) {
2579+
auto &headerList = module.Headers[i];
2580+
for (const clang::Module::Header &moduleHeader : headerList) {
2581+
closure(moduleHeader);
2582+
}
2583+
}
2584+
}
2585+
25592586
////////////////////////////////////////////////////////////////////////////////
25602587
/// Return the absolute type of typeDesc.
25612588
/// E.g.: typeDesc = "class TNamed**", returns "TNamed".

core/dictgen/src/rootcling_impl.cxx

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,31 +2240,6 @@ static bool GenerateAllDict(TModuleGenerator &modGen, clang::CompilerInstance *c
22402240
return WriteAST(modGen.GetModuleFileName(), compilerInstance, iSysRoot);
22412241
}
22422242

2243-
static void
2244-
foreachHeaderInModule(const clang::Module &module, const std::function<void(const clang::Module::Header &)> &closure)
2245-
{
2246-
// Iterates over all headers in a module and calls the closure on each.
2247-
2248-
// FIXME: We currently have to hardcode '4' to do this. Maybe we
2249-
// will have a nicer way to do this in the future.
2250-
// NOTE: This is on purpose '4', not '5' which is the size of the
2251-
// vector. The last element is the list of excluded headers which we
2252-
// obviously don't want to check here.
2253-
const std::size_t publicHeaderIndex = 4;
2254-
2255-
// Integrity check in case this array changes its size at some point.
2256-
const std::size_t maxArrayLength = ((sizeof module.Headers) / (sizeof *module.Headers));
2257-
static_assert(publicHeaderIndex + 1 == maxArrayLength,
2258-
"'Headers' has changed it's size, we need to update publicHeaderIndex");
2259-
2260-
for (std::size_t i = 0; i < publicHeaderIndex; i++) {
2261-
auto &headerList = module.Headers[i];
2262-
for (const clang::Module::Header &moduleHeader : headerList) {
2263-
closure(moduleHeader);
2264-
}
2265-
}
2266-
}
2267-
22682243
////////////////////////////////////////////////////////////////////////////////
22692244
/// Includes all headers in the given module from this interpreter.
22702245
static void IncludeModuleHeaders(TModuleGenerator &modGen, clang::Module *module, cling::Interpreter &interpreter)
@@ -2287,7 +2262,7 @@ static void IncludeModuleHeaders(TModuleGenerator &modGen, clang::Module *module
22872262
// of doing this and 'import' each header in its own submodule, then let
22882263
// the visibility of the decls handle this situation nicely.
22892264
for (clang::Module *module : modules) {
2290-
foreachHeaderInModule(*module, [&includes](const clang::Module::Header &h) {
2265+
ROOT::TMetaUtils::foreachHeaderInModule(*module, [&includes](const clang::Module::Header &h) {
22912266
includes << "#include \"" << h.NameAsWritten << "\"\n";
22922267
});
22932268
}
@@ -2319,7 +2294,7 @@ static bool ModuleContainsHeaders(TModuleGenerator &modGen, clang::Module *modul
23192294
// Now we collect all header files from the previously collected modules.
23202295
std::set<std::string> moduleHeaders;
23212296
for (clang::Module *module : modules) {
2322-
foreachHeaderInModule(
2297+
ROOT::TMetaUtils::foreachHeaderInModule(
23232298
*module, [&moduleHeaders](const clang::Module::Header &h) { moduleHeaders.insert(h.NameAsWritten); });
23242299
}
23252300

0 commit comments

Comments
 (0)