[PATCH] D123148: [clang][extract-api] Process only APIs declared in inputs

2022-04-07 Thread Daniel Grumberg via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaebe5fc6e7d8: [clang][extract-api] Process only APIs 
declared in inputs (authored by dang).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123148/new/

https://reviews.llvm.org/D123148

Files:
  clang/include/clang/ExtractAPI/FrontendActions.h
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/test/ExtractAPI/known_files_only.c
  clang/test/ExtractAPI/known_files_only_hmap.c

Index: clang/test/ExtractAPI/known_files_only_hmap.c
===
--- /dev/null
+++ clang/test/ExtractAPI/known_files_only_hmap.c
@@ -0,0 +1,164 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
+// RUN: %t/reference.output.json
+// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/known_files_only.hmap.json.in >> \
+// RUN: %t/known_files_only.hmap.json
+// RUN: %hmaptool write %t/known_files_only.hmap.json %t/known_files_only.hmap
+// RUN: %clang -extract-api --product-name=KnownFilesOnlyHmap -target arm64-apple-macosx \
+// RUN: -I%t/known_files_only.hmap -I%t/subdir %t/subdir/subdir1/input.h \
+// RUN: %t/subdir/subdir2/known_file.h -o %t/output.json | FileCheck -allow-empty %s
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+//--- known_files_only.hmap.json.in
+{
+  "mappings" :
+{
+ "subdir2/known_file.h" : "INPUT_DIR/subdir/subdir3/unknown.h"
+}
+}
+
+//--- subdir/subdir1/input.h
+int num;
+#include "subdir2/known_file.h"
+
+//--- subdir/subdir2/known_file.h
+int known_num;
+
+//--- subdir/subdir3/unknown.h
+// Ensure that these symbols are not emitted in the Symbol Graph.
+#ifndef INPUT4_H
+#define INPUT4_H
+
+#define HELLO 1
+char not_emitted;
+void foo(int);
+struct Foo { int a; };
+
+#endif
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "KnownFilesOnlyHmap",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "num"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@num"
+  },
+  "kind": {
+"displayName": "Global Variable",
+"identifier": "c.var"
+  },
+  "location": {
+"position": {
+  "character": 5,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/subdir/subdir1/input.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "num"
+  }
+],
+"title": "num"
+  },
+  "pathComponents": [
+"num"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "known_num"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@known_num"
+  },
+  "kind": {
+"displayName": "Global Variable",
+"identifier": "c.var"
+  },
+  "location": {
+"position": {
+  "character": 5,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/subdir/subdir2/known_file.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "known_num"
+  }
+],
+"title": "known_num"
+  },
+  "pathComponents": [
+"known_num"
+  ]
+}
+  ]
+}
Index: clang/test/ExtractAPI/known_files_only.c
===
--- /dev/null
+++ clang/test/ExtractAPI/known_files_only.c
@@ -0,0 +1,100 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%/t@g" 

[PATCH] D123148: [clang][extract-api] Process only APIs declared in inputs

2022-04-07 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 421143.
dang added a comment.

Rebase on top of latest changes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123148/new/

https://reviews.llvm.org/D123148

Files:
  clang/include/clang/ExtractAPI/FrontendActions.h
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/test/ExtractAPI/known_files_only.c
  clang/test/ExtractAPI/known_files_only_hmap.c

Index: clang/test/ExtractAPI/known_files_only_hmap.c
===
--- /dev/null
+++ clang/test/ExtractAPI/known_files_only_hmap.c
@@ -0,0 +1,164 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
+// RUN: %t/reference.output.json
+// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/known_files_only.hmap.json.in >> \
+// RUN: %t/known_files_only.hmap.json
+// RUN: %hmaptool write %t/known_files_only.hmap.json %t/known_files_only.hmap
+// RUN: %clang -extract-api --product-name=KnownFilesOnlyHmap -target arm64-apple-macosx \
+// RUN: -I%t/known_files_only.hmap -I%t/subdir %t/subdir/subdir1/input.h \
+// RUN: %t/subdir/subdir2/known_file.h -o %t/output.json | FileCheck -allow-empty %s
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+//--- known_files_only.hmap.json.in
+{
+  "mappings" :
+{
+ "subdir2/known_file.h" : "INPUT_DIR/subdir/subdir3/unknown.h"
+}
+}
+
+//--- subdir/subdir1/input.h
+int num;
+#include "subdir2/known_file.h"
+
+//--- subdir/subdir2/known_file.h
+int known_num;
+
+//--- subdir/subdir3/unknown.h
+// Ensure that these symbols are not emitted in the Symbol Graph.
+#ifndef INPUT4_H
+#define INPUT4_H
+
+#define HELLO 1
+char not_emitted;
+void foo(int);
+struct Foo { int a; };
+
+#endif
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "KnownFilesOnlyHmap",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "num"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@num"
+  },
+  "kind": {
+"displayName": "Global Variable",
+"identifier": "c.var"
+  },
+  "location": {
+"position": {
+  "character": 5,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/subdir/subdir1/input.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "num"
+  }
+],
+"title": "num"
+  },
+  "pathComponents": [
+"num"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "known_num"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@known_num"
+  },
+  "kind": {
+"displayName": "Global Variable",
+"identifier": "c.var"
+  },
+  "location": {
+"position": {
+  "character": 5,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/subdir/subdir2/known_file.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "known_num"
+  }
+],
+"title": "known_num"
+  },
+  "pathComponents": [
+"known_num"
+  ]
+}
+  ]
+}
Index: clang/test/ExtractAPI/known_files_only.c
===
--- /dev/null
+++ clang/test/ExtractAPI/known_files_only.c
@@ -0,0 +1,100 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
+// RUN: %t/reference.output.json
+// RUN: %clang -extract-api --product-name=GlobalRecord -target arm64-apple-macosx \
+// RUN: 

[PATCH] D123148: [clang][extract-api] Process only APIs declared in inputs

2022-04-06 Thread Cyndy Ishida via Phabricator via cfe-commits
cishida accepted this revision.
cishida added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123148/new/

https://reviews.llvm.org/D123148

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123148: [clang][extract-api] Process only APIs declared in inputs

2022-04-06 Thread Daniel Grumberg via Phabricator via cfe-commits
dang marked 2 inline comments as done.
dang added inline comments.



Comment at: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp:72
+// primarily to resolve headers found via headermaps, as they remap
+// locations.
+const auto *FileInfo = PP.getHeaderSearchInfo().getExistingFileInfo(File);

cishida wrote:
> How is this searching by the way the header was included? It looks like 
> comparisons are based on file locations as `KnownIncludes` stores file paths. 
Upon second thought and further testing all this stuff isn't needed because we 
always construct the input buffer using `#include "ABSOLUTE_PATH"`. I have 
added a test to validate that this works when using a header map. If we ever 
move to relative includes, then we should change how this to use only include 
string comparisons (potentially caching the FileEntries as a performance 
optimization).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123148/new/

https://reviews.llvm.org/D123148

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123148: [clang][extract-api] Process only APIs declared in inputs

2022-04-06 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 420875.
dang marked 2 inline comments as done.
dang added a comment.

Address code review feedback:

- Remove unnecessary code
- Add a test to validate that everything works in the presence of header maps
- Simplify existing test
- Fix small nits


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123148/new/

https://reviews.llvm.org/D123148

Files:
  clang/include/clang/ExtractAPI/FrontendActions.h
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/test/ExtractAPI/known_files_only.c
  clang/test/ExtractAPI/known_files_only_hmap.c

Index: clang/test/ExtractAPI/known_files_only_hmap.c
===
--- /dev/null
+++ clang/test/ExtractAPI/known_files_only_hmap.c
@@ -0,0 +1,152 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
+// RUN: %t/reference.output.json
+// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/known_files_only.hmap.json.in >> \
+// RUN: %t/known_files_only.hmap.json
+// RUN: %hmaptool write %t/known_files_only.hmap.json %t/known_files_only.hmap
+// RUN: %clang -extract-api --product-name=KnownFilesOnlyHmap -target arm64-apple-macosx \
+// RUN: -I%t/known_files_only.hmap -I%t/subdir %t/subdir/subdir1/input.h \
+// RUN: %t/subdir/subdir2/known_file.h -o %t/output.json | FileCheck -allow-empty %s
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+//--- known_files_only.hmap.json.in
+{
+  "mappings" :
+{
+ "subdir2/known_file.h" : "INPUT_DIR/subdir/subdir3/unknown.h"
+}
+}
+
+//--- subdir/subdir1/input.h
+int num;
+#include "subdir2/known_file.h"
+
+//--- subdir/subdir2/known_file.h
+int known_num;
+
+//--- subdir/subdir3/unknown.h
+// Ensure that these symbols are not emitted in the Symbol Graph.
+#ifndef INPUT4_H
+#define INPUT4_H
+
+#define HELLO 1
+char not_emitted;
+void foo(int);
+struct Foo { int a; };
+
+#endif
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "KnownFilesOnlyHmap",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationhips": [],
+  "symbols": [
+{
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "num"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@num"
+  },
+  "kind": {
+"displayName": "Global Variable",
+"identifier": "c.var"
+  },
+  "location": {
+"character": 5,
+"line": 1,
+"uri": "file://INPUT_DIR/subdir/subdir1/input.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "num"
+  }
+],
+"title": "num"
+  }
+},
+{
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "known_num"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@known_num"
+  },
+  "kind": {
+"displayName": "Global Variable",
+"identifier": "c.var"
+  },
+  "location": {
+"character": 5,
+"line": 1,
+"uri": "file://INPUT_DIR/subdir/subdir2/known_file.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "known_num"
+  }
+],
+"title": "known_num"
+  }
+}
+  ]
+}
Index: clang/test/ExtractAPI/known_files_only.c
===
--- /dev/null
+++ clang/test/ExtractAPI/known_files_only.c
@@ -0,0 +1,94 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
+// RUN: %t/reference.output.json
+// RUN: %clang -extract-api --product-name=GlobalRecord -target arm64-apple-macosx \
+// RUN: %t/input1.h -o %t/output.json | FileCheck -allow-empty %s
+
+// 

[PATCH] D123148: [clang][extract-api] Process only APIs declared in inputs

2022-04-05 Thread Zixu Wang via Phabricator via cfe-commits
zixuw added inline comments.



Comment at: clang/test/ExtractAPI/known_files_only.c:20
+// Let's make sure we aren't pulling in symbols from complex.h
+#include 
+double complex build_complex(double real, double imaginary);

I would just include another header split from this test file but not passed 
into the command line to avoid pulling in extra dependencies. Makes the test 
self-contained and more consistent, also simpler.



Comment at: clang/test/ExtractAPI/known_files_only.c:166
+"line": 5,
+"uri": 
"file:///Users/dgrumberg/VersionControlledDocuments/oss/llvm-project/build/tools/clang/test/ExtractAPI/Output/known_files_only.c.tmp/input1.h"
+  },

uri not normalized.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123148/new/

https://reviews.llvm.org/D123148

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123148: [clang][extract-api] Process only APIs declared in inputs

2022-04-05 Thread Cyndy Ishida via Phabricator via cfe-commits
cishida added inline comments.



Comment at: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp:66
+// Check if we have looked up this particular file entry previously instead
+// of querying the preprocessor for externsal sources.
+if (UnknownFileEntries.count(File))

s/externsal/external



Comment at: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp:72
+// primarily to resolve headers found via headermaps, as they remap
+// locations.
+const auto *FileInfo = PP.getHeaderSearchInfo().getExistingFileInfo(File);

How is this searching by the way the header was included? It looks like 
comparisons are based on file locations as `KnownIncludes` stores file paths. 



Comment at: clang/test/ExtractAPI/known_files_only.c:6
+// RUN: %clang -extract-api --product-name=GlobalRecord -target 
arm64-apple-macosx \
+// RUN: %t/input1.h %t/input2.h %t/input3.h -o %t/output.json | FileCheck 
-allow-empty %s
+

It may be useful to add a test for the headermap case to ensure the remapped 
location is recognized. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123148/new/

https://reviews.llvm.org/D123148

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123148: [clang][extract-api] Process only APIs declared in inputs

2022-04-05 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added reviewers: zixuw, ributzka, QuietMisdreavus, cishida.
Herald added a project: All.
dang requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We should only process APIs declared in the command line inputs to avoid
drowning the ExtractAPI output with symbols the user doesn't care about.
This is achieved by keeping track of the provided input files and
checking that the associated Decl or Macro is declared in one of those files.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123148

Files:
  clang/include/clang/ExtractAPI/FrontendActions.h
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/test/ExtractAPI/known_files_only.c

Index: clang/test/ExtractAPI/known_files_only.c
===
--- /dev/null
+++ clang/test/ExtractAPI/known_files_only.c
@@ -0,0 +1,499 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
+// RUN: %t/reference.output.json
+// RUN: %clang -extract-api --product-name=GlobalRecord -target arm64-apple-macosx \
+// RUN: %t/input1.h %t/input2.h %t/input3.h -o %t/output.json | FileCheck -allow-empty %s
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+
+//--- input1.h
+int num;
+
+// Let's make sure we aren't pulling in symbols from complex.h
+#include 
+double complex build_complex(double real, double imaginary);
+
+//--- input2.h
+/**
+ * \brief Add two numbers.
+ * \param [in]  x   A number.
+ * \param [in]  y   Another number.
+ * \param [out] res The result of x + y.
+ */
+void add(const int x, const int y, int *res);
+
+//--- input3.h
+char unavailable __attribute__((unavailable));
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "GlobalRecord",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationhips": [],
+  "symbols": [
+{
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "num"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@num"
+  },
+  "kind": {
+"displayName": "Global Variable",
+"identifier": "c.var"
+  },
+  "location": {
+"character": 5,
+"line": 1,
+"uri": "file://INPUT_DIR/input1.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "num"
+  }
+],
+"title": "num"
+  }
+},
+{
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:
+#include 
 
 using namespace clang;
 using namespace extractapi;
 
 namespace {
 
+struct LocationFileChecker {
+  bool isLocationInKnownFile(SourceLocation Loc) {
+// If the loc refers to a macro expansion we need to first get the file
+// location of the expansion.
+auto FileLoc = SM.getFileLoc(Loc);
+FileID FID = SM.getFileID(FileLoc);
+if (FID.isInvalid())
+  return false;
+
+const auto *File = SM.getFileEntryForID(FID);
+if (!File)
+  return false;
+
+if (KnownFileEntries.count(File))
+  return true;
+
+// Check if we have looked up this particular file entry previously instead
+// of querying the preprocessor for externsal sources.
+if (UnknownFileEntries.count(File))
+  return false;
+
+// If file was not found, search by how the header was included. This is
+// primarily to resolve headers found via headermaps, as they remap
+// locations.
+const auto *FileInfo = PP.getHeaderSearchInfo().getExistingFileInfo(File);
+if (!FileInfo || !FileInfo->IsValid)
+  return false;
+
+StringRef FileName = File->getName();
+
+if (!KnownIncludes.count(FileName)) {
+  // Record that the file was found to avoid future string searches for the
+  // same file.
+  UnknownFileEntries.insert(File);
+  return false;
+}
+
+KnownFileEntries.insert(File);
+return true;
+  }
+
+  LocationFileChecker(const SourceManager , const Preprocessor ,
+  const