@@ -38,6 +38,7 @@ using pFileNameToGroupNameMap = std::unique_ptr<FileNameToGroupNameMap>;
3838
3939namespace {
4040class YamlGroupInputParser {
41+ ASTContext &Ctx;
4142 StringRef RecordPath;
4243 static constexpr const char * const Separator = " /" ;
4344
@@ -86,12 +87,20 @@ class YamlGroupInputParser {
8687 }
8788
8889public:
89- YamlGroupInputParser (StringRef RecordPath): RecordPath(RecordPath) {}
90+ YamlGroupInputParser (ASTContext &Ctx, StringRef RecordPath):
91+ Ctx (Ctx), RecordPath(RecordPath) {}
9092
9193 FileNameToGroupNameMap* getParsedMap () {
9294 return AllMaps[RecordPath].get ();
9395 }
9496
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+
95104 // Parse the Yaml file that contains the group information.
96105 // True on failure; false on success.
97106 bool parse () {
@@ -102,32 +111,31 @@ class YamlGroupInputParser {
102111
103112 auto Buffer = llvm::MemoryBuffer::getFile (RecordPath);
104113 if (!Buffer) {
105- // The group info file does not exist.
106- return true ;
114+ return diagnoseGroupInfoFile (/* Missing File*/ true );
107115 }
108116 llvm::SourceMgr SM;
109117 llvm::yaml::Stream YAMLStream (Buffer.get ()->getMemBufferRef (), SM);
110118 llvm::yaml::document_iterator I = YAMLStream.begin ();
111119 if (I == YAMLStream.end ()) {
112120 // Cannot parse correctly.
113- return true ;
121+ return diagnoseGroupInfoFile () ;
114122 }
115123 llvm::yaml::Node *Root = I->getRoot ();
116124 if (!Root) {
117125 // Cannot parse correctly.
118- return true ;
126+ return diagnoseGroupInfoFile () ;
119127 }
120128
121129 // The format is a map of ("group0" : ["file1", "file2"]), meaning all
122130 // symbols from file1 and file2 belong to "group0".
123131 auto *Map = dyn_cast<llvm::yaml::MappingNode>(Root);
124132 if (!Map) {
125- return true ;
133+ return diagnoseGroupInfoFile () ;
126134 }
127135 pFileNameToGroupNameMap pMap (new FileNameToGroupNameMap ());
128136 std::string Empty;
129137 if (parseRoot (*pMap, Root, Empty))
130- return true ;
138+ return diagnoseGroupInfoFile () ;
131139
132140 // Save the parsed map to the owner.
133141 AllMaps[RecordPath] = std::move (pMap);
@@ -168,7 +176,7 @@ class DeclGroupNameContext {
168176 StringRef FullPath =
169177 Ctx.SourceMgr .getIdentifierForBuffer (PathOp.getValue ());
170178 if (!pMap) {
171- YamlGroupInputParser Parser (RecordPath);
179+ YamlGroupInputParser Parser (Ctx, RecordPath);
172180 if (!Parser.parse ()) {
173181
174182 // Get the file-name to group map if parsing correctly.
0 commit comments