-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Unified: Introduce ParameterEx
#22725
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
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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /** | ||
| * Provides logic for synthesizing parameters. | ||
| */ | ||
|
|
||
| private import unified | ||
| private import AstPlugin | ||
| private import NameBinding | ||
|
|
||
| private newtype TParameterEx = | ||
| TAstParameter(Parameter p) or | ||
| TImplicitReceiverParameter(Callable c) { | ||
| exists(LocalVariable v | v.isImplicitReceiverParameter(c)) | ||
| } or | ||
| TDefaultConstructorParameter(ConstructorDeclaration cd, int i, string name) { | ||
| cd.hasModifier("generated") and | ||
| defaultConstructorParameter(cd, i, name) | ||
| } | ||
|
|
||
| final class ParameterEx = ParameterExImpl; | ||
|
|
||
| /** | ||
| * A parameter from source code or a synthesized parameter. | ||
| */ | ||
| abstract private class ParameterExImpl extends TParameterEx { | ||
| /** | ||
| * Gets the source code parameter that this entity represents, if any. | ||
| */ | ||
| Parameter asParameter() { this = TAstParameter(result) } | ||
|
|
||
| /** | ||
| * Holds if this entity represents a regular parameter from source code. | ||
| */ | ||
| predicate isParameter() { exists(this.asParameter()) } | ||
|
|
||
| /** | ||
| * Holds if this entity represents an implicit receiver parameter of `c`. | ||
| */ | ||
| predicate isImplicitReceiverParameter(Callable c) { this = TImplicitReceiverParameter(c) } | ||
|
|
||
| /** | ||
| * Holds if this entity represents the `i`th parameter of the default | ||
| * constructor `cd` with name `name`. | ||
| */ | ||
| predicate isDefaultConstructorParameter(ConstructorDeclaration cd, int i, string name) { | ||
| this = TDefaultConstructorParameter(cd, i, name) | ||
| } | ||
|
|
||
| /** Gets the callable that this parameter belongs to. */ | ||
| Callable getCallable() { | ||
| this.asParameter() = | ||
| [ | ||
| result.(FunctionDeclaration).getAParameter(), | ||
| result.(ConstructorDeclaration).getAParameter(), | ||
| result.(AccessorDeclaration).getAParameter(), | ||
| result.(FunctionExpr).getAParameter() | ||
| ] | ||
| or | ||
| this.isImplicitReceiverParameter(result) | ||
| or | ||
| this.isDefaultConstructorParameter(result, _, _) | ||
| } | ||
|
|
||
| /** Gets a textual representation of this parameter. */ | ||
| abstract string toString(); | ||
|
|
||
| /** Gets the location of this parameter. */ | ||
| abstract Location getLocation(); | ||
| } | ||
|
|
||
| private class AstParameterEx extends ParameterExImpl, TAstParameter { | ||
| Parameter p; | ||
|
|
||
| AstParameterEx() { this = TAstParameter(p) } | ||
|
|
||
| override string toString() { result = p.toString() } | ||
|
|
||
| override Location getLocation() { result = p.getLocation() } | ||
| } | ||
|
|
||
| private class ImplicitReceiverParameterEx extends ParameterExImpl, TImplicitReceiverParameter { | ||
| Callable c; | ||
|
|
||
| ImplicitReceiverParameterEx() { this = TImplicitReceiverParameter(c) } | ||
|
|
||
| override string toString() { | ||
| exists(LocalVariable v | | ||
| v.isImplicitReceiverParameter(c) and | ||
| result = v.getName() | ||
| ) | ||
| } | ||
|
|
||
| override Location getLocation() { result = c.getLocation() } | ||
| } | ||
|
|
||
| private class DefaultConstructorParameterEx extends ParameterExImpl, TDefaultConstructorParameter { | ||
| ConstructorDeclaration cd; | ||
| int i; | ||
| string name; | ||
|
|
||
| DefaultConstructorParameterEx() { this = TDefaultConstructorParameter(cd, i, name) } | ||
|
|
||
| override string toString() { result = name + " [" + cd.getName() + " default constructor]" } | ||
|
|
||
| override Location getLocation() { result = cd.getLocation() } | ||
| } |
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 |
|---|---|---|
| @@ -1,5 +1,28 @@ | ||
| generatedConstructor | ||
| | constructors.swift:1:1:1:0 | init | | ||
| | constructors.swift:3:1:3:0 | init | | ||
| | constructors.swift:19:1:19:0 | init | | ||
| | constructors.swift:31:1:31:0 | init | | ||
| | constructors.swift:39:1:39:0 | init | | ||
| implicitReceiverParameter | ||
| | constructors.swift:1:1:1:0 | self | constructors.swift:1:1:1:0 | init | | ||
| | constructors.swift:3:1:3:0 | self | constructors.swift:3:1:3:0 | init | | ||
| | constructors.swift:6:5:6:13 | self | constructors.swift:6:5:6:13 | init | | ||
| | constructors.swift:10:5:12:5 | self | constructors.swift:10:5:12:5 | init | | ||
| | constructors.swift:14:5:16:5 | self | constructors.swift:14:5:16:5 | convenience init | | ||
| | constructors.swift:19:1:19:0 | self | constructors.swift:19:1:19:0 | init | | ||
| | constructors.swift:22:5:22:25 | self | constructors.swift:22:5:22:25 | init | | ||
| | constructors.swift:24:5:24:30 | self | constructors.swift:24:5:24:30 | init | | ||
| | constructors.swift:26:5:28:5 | self | constructors.swift:26:5:28:5 | convenience init | | ||
| | constructors.swift:31:1:31:0 | self | constructors.swift:31:1:31:0 | init | | ||
| | constructors.swift:34:5:36:5 | self | constructors.swift:34:5:36:5 | convenience init | | ||
| | constructors.swift:39:1:39:0 | self | constructors.swift:39:1:39:0 | init | | ||
| | constructors.swift:46:9:48:9 | self | constructors.swift:46:9:48:9 | AccessorDeclaration | | ||
| | constructors.swift:49:9:51:9 | self | constructors.swift:49:9:51:9 | AccessorDeclaration | | ||
| | constructors.swift:54:9:56:9 | self | constructors.swift:54:9:56:9 | AccessorDeclaration | | ||
| | constructors.swift:57:9:59:9 | self | constructors.swift:57:9:59:9 | AccessorDeclaration | | ||
| callableExDefaultConstructorParameter | ||
| | constructors.swift:39:1:39:0 | init | 1 | constructors.swift:39:1:39:0 | f1 [init default constructor] | f1 | | ||
| | constructors.swift:39:1:39:0 | init | 2 | constructors.swift:39:1:39:0 | f2 [init default constructor] | f2 | | ||
| | constructors.swift:39:1:39:0 | init | 3 | constructors.swift:39:1:39:0 | f4 [init default constructor] | f4 | | ||
| | constructors.swift:39:1:39:0 | init | 4 | constructors.swift:39:1:39:0 | f7 [init default constructor] | f7 | |
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,6 +1,19 @@ | ||
| import unified | ||
| import codeql.unified.internal.ParameterEx | ||
|
|
||
| query predicate generatedConstructor(ConstructorDeclaration c) { | ||
| c = any(ClassLikeDeclaration cls | cls.fromSource()).getAMember() and | ||
| c.hasModifier("generated") | ||
| } | ||
|
|
||
| query predicate implicitReceiverParameter(ParameterEx p, Callable c) { | ||
| p.isImplicitReceiverParameter(c) and | ||
| c.getFile().fromSource() | ||
| } | ||
|
|
||
| query predicate callableExDefaultConstructorParameter( | ||
| ConstructorDeclaration cd, int i, ParameterEx p, string name | ||
| ) { | ||
| p.isDefaultConstructorParameter(cd, i, name) and | ||
| cd.getFile().fromSource() | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.