-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang-query] Load queries and matchers from file during REPL cycle #90603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9b1fe59
Load queries and matchers from file during REPL cycle
cwarner-8702 38f7f6f
CR: add tests for non-existant or empty file
cwarner-8702 5e3b8f2
CR: add additional commands to dyn file
cwarner-8702 e199cbc
CR: add release note
cwarner-8702 478f048
Update clang-tools-extra/test/clang-query/file-query.c
AaronBallman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# This file intentionally has no queries |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
f DIRECTORY/runtime_file.script |
5 changes: 5 additions & 0 deletions
5
clang-tools-extra/test/clang-query/Inputs/runtime_file.script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
set bind-root false | ||
|
||
l func functionDecl(hasName("bar")) | ||
m func.bind("f") | ||
m varDecl().bind("v") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
// RUN: not clang-query -c foo -c bar %s -- | FileCheck %s | ||
// RUN: not clang-query -f %S/Inputs/foo.script %s -- | FileCheck %s | ||
// RUN: not clang-query -f %S/Inputs/nonexistent.script %s -- 2>&1 | FileCheck --check-prefix=CHECK-NONEXISTENT %s | ||
// RUN: not clang-query -c 'file %S/Inputs/nonexistent.script' %s -- 2>&1 | FileCheck --check-prefix=CHECK-NONEXISTENT-FILEQUERY %s | ||
// RUN: not clang-query -c foo -f foo %s -- 2>&1 | FileCheck --check-prefix=CHECK-BOTH %s | ||
|
||
// CHECK: unknown command: foo | ||
// CHECK-NOT: unknown command: bar | ||
|
||
// CHECK-NONEXISTENT: cannot open {{.*}}nonexistent.script | ||
// CHECK-NONEXISTENT-FILEQUERY: cannot open {{.*}}nonexistent.script | ||
// CHECK-BOTH: cannot specify both -c and -f |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// RUN: clang-query -c 'file %S/Inputs/empty.script' %s -- | ||
// COM: no output expected; nothing to CHECK |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// RUN: rm -rf %/t | ||
// RUN: mkdir %/t | ||
// RUN: cp %/S/Inputs/file.script %/t/file.script | ||
// RUN: cp %/S/Inputs/runtime_file.script %/t/runtime_file.script | ||
// Need to embed the correct temp path in the actual JSON-RPC requests. | ||
// RUN: sed -e "s|DIRECTORY|%/t|" %/t/file.script > %/t/file.script.temp | ||
|
||
// RUN: clang-query -c 'file %/t/file.script.temp' %s -- | FileCheck %s | ||
|
||
// CHECK: file-query.c:11:1: note: "f" binds here | ||
void bar(void) {} | ||
|
||
// CHECK: file-query.c:14:1: note: "v" binds here | ||
int baz{1}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than printing directly to
errs()
, I think you should construct aTextDiagnostic
object and use that to emit the diagnostic.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got any tips on using
TextDiagnostic
? I am struggling to figure out what to pass as theLangOptions
andDiagnosticOptions
considering the error isn't coming from code per-se (getting theASTContext
from one of theASTUnit
objects and the options from it seems too hacky)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of pulling the information from the
ASTUnit
as that's howMatchQuery
works, but then I realized this suggestion isn't fantastic because there's no source location to emit the diagnostic for. That got me looking atInvalidQuery
and I see we emit directly to the passedraw_ostream
, which isllvm::outs()
.Curiously,
runCommandsInFile()
emits tollvm::errs()
instead, so we sometimes emit to the output stream and sometimes to the error stream. I'd say this case can continue to output to the error stream and maybe someday we should make this a bit more consistent across the tool.