aboutsummaryrefslogtreecommitdiff
path: root/lib/llvm-ast.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/llvm-ast.js')
-rw-r--r--lib/llvm-ast.js23
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/llvm-ast.js b/lib/llvm-ast.js
index b3d239c01..0ccbd3e31 100644
--- a/lib/llvm-ast.js
+++ b/lib/llvm-ast.js
@@ -103,6 +103,17 @@ export class LlvmAstParser {
// Refers to the user's source file rather than a system header
const sourceRegex = /<source>/g;
+ const slocRegex = /<<invalid sloc>>/;
+
+ // <<invalid sloc>, /app/hell.hpp:5:1>
+ const userSource = /<<invalid sloc>, \/app\/.*:\d+:\d+>/;
+
+ // </usr/include/x86_64-linux-gnu/bits/types.h:31:1, col:23>
+ // <line:229:1, /usr/include/x86_64-linux-gnu/sys/cdefs.h:61:27> /usr/include/time.h:229:12
+ // </usr/include/x86_64-linux-gnu/sys/cdefs.h:293:44, /usr/include/time.h:258:27> 1
+ // </opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/etc...
+ const systemSource = /(<\/usr\/|,\s\/usr\/|<\/opt\/)/;
+
// Refers to whatever the most recent file specified was
const lineRegex = /<(col|line):/;
@@ -117,9 +128,13 @@ export class LlvmAstParser {
// This is a system header or implicit definition,
// remove everything up to the next top level decl
// Top level decls with invalid sloc as the file don't change the most recent file
- const slocRegex = /<<invalid sloc>>/;
- if (!slocRegex.test(output[i].text)) {
+ if (systemSource.test(output[i].text)) {
+ // skip ast from this source
+ } else if (userSource.test(output[i].text)) {
+ continue;
+ } else if (!slocRegex.test(output[i].text)) {
mostRecentIsSource = false;
+ continue;
}
let spliceMax = i + 1;
@@ -137,8 +152,8 @@ export class LlvmAstParser {
output[i].text = output[i].text.replace(addressRegex, '$1');
// Filter out <invalid sloc> and <<invalid sloc>>
- const slocRegex = / ?<?<invalid sloc>>?/g;
- output[i].text = output[i].text.replace(slocRegex, '');
+ const slocRegex2 = / ?<?<invalid sloc>>?/g;
+ output[i].text = output[i].text.replace(slocRegex2, '');
// Unify file references
output[i].text = output[i].text.replace(sourceRegex, 'line');