================
@@ -390,18 +396,43 @@ void HeaderIncludesDirectPerFileCallback::EndOfMainFile()
{
std::string Str;
llvm::raw_string_ostream OS(Str);
llvm::json::OStream JOS(OS);
- JOS.array([&] {
- for (auto S = SourceFiles.begin(), SE = SourceFiles.end(); S != SE; ++S) {
- JOS.object([&] {
- SmallVector<FileEntryRef> &Deps = Dependencies[*S];
- JOS.attribute("source", S->getName().str());
- JOS.attributeArray("includes", [&] {
- for (unsigned I = 0, N = Deps.size(); I != N; ++I)
- JOS.value(Deps[I].getName().str());
+ JOS.object([&] {
+ JOS.attribute("version", "2.0.0");
+ JOS.attributeArray("dependencies", [&] {
+ for (auto S = SourceFiles.begin(), SE = SourceFiles.end(); S != SE; ++S)
{
+ JOS.object([&] {
+ SmallVector<HeaderIncludeInfo> &Deps = Dependencies[*S];
+ JOS.attribute("source", S->getName().str());
+ JOS.attributeArray("includes", [&] {
+ for (unsigned I = 0, N = Deps.size(); I != N; ++I) {
+ if (!Deps[I].importedModule) {
+ JOS.object([&] {
+ PresumedLoc PLoc = SM.getPresumedLoc(Deps[I].location);
----------------
jansvoboda11 wrote:
Presumed source locations reflect `#line` directives which overwrite the line
number and may also overwrite the file name. So using the actual file entry as
the value for `"source"` and then using the presumed source location for
`"location"` can get you into situations where the actual source location
exists, the presumed source location exists, but your output points into a
non-existent combination of the two:
```c
/* line 1 */ // a.h
/* line 2 */ #line 5 "b.h"
/* line 3 */ #include "reported-header.h"
```
```c
/* line 1 */ // b.h
/* line 2 */
/* line 3 */
/* line 4 */
/* line 5 */ #include "reported-header.h"
```
Your output:
```json
{
"source": "a.h",
"includes": [
{
"location": "5:10", // (in the presumed "b.h" file)
"file": "reported-header.h"
}
]
}
```
At least that's my theory until we have a test that disproves it.
https://github.com/llvm/llvm-project/pull/156756
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits