@@ -38,6 +38,7 @@ using pFileNameToGroupNameMap = std::unique_ptr<FileNameToGroupNameMap>;
38
38
39
39
namespace {
40
40
class YamlGroupInputParser {
41
+ ASTContext &Ctx;
41
42
StringRef RecordPath;
42
43
static constexpr const char * const Separator = " /" ;
43
44
@@ -86,12 +87,20 @@ class YamlGroupInputParser {
86
87
}
87
88
88
89
public:
89
- YamlGroupInputParser (StringRef RecordPath): RecordPath(RecordPath) {}
90
+ YamlGroupInputParser (ASTContext &Ctx, StringRef RecordPath):
91
+ Ctx (Ctx), RecordPath(RecordPath) {}
90
92
91
93
FileNameToGroupNameMap* getParsedMap () {
92
94
return AllMaps[RecordPath].get ();
93
95
}
94
96
97
+ bool diagnoseGroupInfoFile (bool FileMissing = false ) {
98
+ Ctx.Diags .diagnose (SourceLoc (),
99
+ FileMissing ? diag::cannot_find_group_info_file:
100
+ diag::cannot_parse_group_info_file, RecordPath);
101
+ return true ;
102
+ }
103
+
95
104
// Parse the Yaml file that contains the group information.
96
105
// True on failure; false on success.
97
106
bool parse () {
@@ -102,32 +111,31 @@ class YamlGroupInputParser {
102
111
103
112
auto Buffer = llvm::MemoryBuffer::getFile (RecordPath);
104
113
if (!Buffer) {
105
- // The group info file does not exist.
106
- return true ;
114
+ return diagnoseGroupInfoFile (/* Missing File*/ true );
107
115
}
108
116
llvm::SourceMgr SM;
109
117
llvm::yaml::Stream YAMLStream (Buffer.get ()->getMemBufferRef (), SM);
110
118
llvm::yaml::document_iterator I = YAMLStream.begin ();
111
119
if (I == YAMLStream.end ()) {
112
120
// Cannot parse correctly.
113
- return true ;
121
+ return diagnoseGroupInfoFile () ;
114
122
}
115
123
llvm::yaml::Node *Root = I->getRoot ();
116
124
if (!Root) {
117
125
// Cannot parse correctly.
118
- return true ;
126
+ return diagnoseGroupInfoFile () ;
119
127
}
120
128
121
129
// The format is a map of ("group0" : ["file1", "file2"]), meaning all
122
130
// symbols from file1 and file2 belong to "group0".
123
131
auto *Map = dyn_cast<llvm::yaml::MappingNode>(Root);
124
132
if (!Map) {
125
- return true ;
133
+ return diagnoseGroupInfoFile () ;
126
134
}
127
135
pFileNameToGroupNameMap pMap (new FileNameToGroupNameMap ());
128
136
std::string Empty;
129
137
if (parseRoot (*pMap, Root, Empty))
130
- return true ;
138
+ return diagnoseGroupInfoFile () ;
131
139
132
140
// Save the parsed map to the owner.
133
141
AllMaps[RecordPath] = std::move (pMap);
@@ -168,7 +176,7 @@ class DeclGroupNameContext {
168
176
StringRef FullPath =
169
177
Ctx.SourceMgr .getIdentifierForBuffer (PathOp.getValue ());
170
178
if (!pMap) {
171
- YamlGroupInputParser Parser (RecordPath);
179
+ YamlGroupInputParser Parser (Ctx, RecordPath);
172
180
if (!Parser.parse ()) {
173
181
174
182
// Get the file-name to group map if parsing correctly.
0 commit comments