Skip to content

Commit f4ff65e

Browse files
committed
Module groups: Teach group info parser to handle sub-groups recursively.
1 parent eabf6ee commit f4ff65e

File tree

1 file changed

+40
-17
lines changed

1 file changed

+40
-17
lines changed

Diff for: lib/Serialization/Serialization.cpp

+40-17
Original file line numberDiff line numberDiff line change
@@ -3483,9 +3483,46 @@ typedef std::unique_ptr<FileNameToGroupNameMap> pFileNameToGroupNameMap;
34833483

34843484
class YamlGroupInputParser {
34853485
StringRef RecordPath;
3486-
3486+
std::string Separator = ".";
34873487
static llvm::StringMap<pFileNameToGroupNameMap> AllMaps;
34883488

3489+
bool parseRoot(FileNameToGroupNameMap &Map, llvm::yaml::Node *Root,
3490+
StringRef ParentName) {
3491+
llvm::yaml::MappingNode *MapNode = dyn_cast<llvm::yaml::MappingNode>(Root);
3492+
if (!MapNode) {
3493+
return true;
3494+
}
3495+
for (auto Pair : *MapNode) {
3496+
auto *Key = dyn_cast_or_null<llvm::yaml::ScalarNode>(Pair.getKey());
3497+
auto *Value = dyn_cast_or_null<llvm::yaml::SequenceNode>(Pair.getValue());
3498+
3499+
if (!Key || !Value) {
3500+
return true;
3501+
}
3502+
llvm::SmallString<16> GroupNameStorage;
3503+
llvm::SmallString<16> CombinedNameStorage;
3504+
StringRef GroupName = Key->getValue(GroupNameStorage);
3505+
if (!ParentName.empty()) {
3506+
CombinedNameStorage.append(ParentName);
3507+
CombinedNameStorage.append(Separator);
3508+
}
3509+
CombinedNameStorage.append(GroupName);
3510+
StringRef CombinedName = CombinedNameStorage.str();
3511+
for (llvm::yaml::Node &Entry : *Value) {
3512+
if (auto *FileEntry= dyn_cast<llvm::yaml::ScalarNode>(&Entry)) {
3513+
llvm::SmallString<16> FileNameStorage;
3514+
StringRef FileName = FileEntry->getValue(FileNameStorage);
3515+
Map[FileName] = CombinedName;
3516+
} else if (Entry.getType() == llvm::yaml::Node::NodeKind::NK_Mapping) {
3517+
if(parseRoot(Map, &Entry, CombinedName))
3518+
return true;
3519+
} else
3520+
return true;
3521+
}
3522+
}
3523+
return false;
3524+
}
3525+
34893526
public:
34903527
YamlGroupInputParser(StringRef RecordPath): RecordPath(RecordPath) {}
34913528

@@ -3526,22 +3563,8 @@ class YamlGroupInputParser {
35263563
return true;
35273564
}
35283565
pFileNameToGroupNameMap pMap(new FileNameToGroupNameMap());
3529-
for (auto Pair : *Map) {
3530-
auto *Key = dyn_cast_or_null<llvm::yaml::ScalarNode>(Pair.getKey());
3531-
auto *Value = dyn_cast_or_null<llvm::yaml::SequenceNode>(Pair.getValue());
3532-
3533-
if (!Key || !Value) {
3534-
return true;
3535-
}
3536-
llvm::SmallString<16> GroupNameStorage;
3537-
StringRef GroupName = Key->getValue(GroupNameStorage);
3538-
for (llvm::yaml::Node &Entry : *Value) {
3539-
auto *FileEntry= dyn_cast<llvm::yaml::ScalarNode>(&Entry);
3540-
llvm::SmallString<16> FileNameStorage;
3541-
StringRef FileName = FileEntry->getValue(FileNameStorage);
3542-
(*pMap)[FileName] = GroupName;
3543-
}
3544-
}
3566+
if(parseRoot(*pMap, Root, ""))
3567+
return true;
35453568

35463569
// Save the parsed map to the owner.
35473570
AllMaps[RecordPath] = std::move(pMap);

0 commit comments

Comments
 (0)