Repository navigation
unified: Add ClassLikeElement #23297
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
Open
asgerf
wants to merge
9
commits into
main
Choose a base branch
from
asgerf-class-like-element-refactor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b0d5941
unified: Add ClassLikeElement
asgerf 9188273
Unified: Hide TypeSelector from public API
asgerf 61fc622
Unified: Exclude root model selector from class-like types
asgerf 50a3b0e
Unified: Resolve aliases in model extension targets
asgerf f4fa532
Unified: Qualify nested types in modeled extensions
asgerf 40c327e
Unified: Match modeled types through type aliases
asgerf 2f0935b
Unified: Resolve aliases in nested extension names
asgerf 4b95855
Unified: Remove class-like type restriction
asgerf e7576c4
Unified: Fix QL formatting
asgerf 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
87 changes: 87 additions & 0 deletions
87
unified/ql/lib/codeql/unified/internal/ClassLikeElement.qll
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,87 @@ | ||
| /** | ||
| * Provides the `ClassLikeElement` class, the canonical representative of a class, struct, enum, etc. | ||
| */ | ||
| overlay[local?] | ||
| module; | ||
|
|
||
| private import unified | ||
| private import codeql.unified.internal.StaticNameBinding as N | ||
| private import codeql.unified.internal.mad.LegacyMaD as MaD | ||
|
|
||
| /** | ||
| * Gets the model-only type extended by the extension `ext`, provided that the extended | ||
| * type could not be resolved to a declaration. | ||
| */ | ||
| pragma[nomagic] | ||
| private MaD::TypeSelector getExtendedTypeSelector(ClassLikeDeclaration ext) { | ||
| not exists(N::getExtendedDeclaration(ext)) and | ||
| N::trackTypeSelectorThroughAliases(result) = N::getNodeFromRef(ext.getExtensionTarget()) | ||
| } | ||
|
|
||
| cached | ||
| private newtype TClassLikeElement = | ||
| TClassLikeDeclarationElement(ClassLikeDeclaration decl) { not exists(decl.getExtensionTarget()) } or | ||
| TTypeSelectorElement(MaD::TypeSelector selector) { | ||
| selector != "" and | ||
| not exists(selector.getDeclaration()) and | ||
| not selector.isMetaType() | ||
| } | ||
|
|
||
| /** | ||
| * A class-like entity, such as a class, struct, enum, or protocol. | ||
| * | ||
| * This is the canonical representative of a class-like entity, unifying its | ||
| * primary declaration with any extensions of it. Types that are only known from | ||
| * a model (and have no declaration in the database) are represented by their type selector. | ||
| */ | ||
| class ClassLikeElement extends TClassLikeElement { | ||
| /** Gets the primary (non-extension) declaration of this class, if any. */ | ||
| ClassLikeDeclaration asClassLikeDeclaration() { this = TClassLikeDeclarationElement(result) } | ||
|
|
||
| /** Gets the type selector of this class, if it is only known from a model. */ | ||
| private MaD::TypeSelector asTypeSelector() { this = TTypeSelectorElement(result) } | ||
|
|
||
| /** | ||
| * Gets a declaration of this class, that is, either its primary declaration or an extension of it. | ||
| */ | ||
| cached | ||
| ClassLikeDeclaration getADeclaration() { | ||
| result = this.asClassLikeDeclaration() | ||
| or | ||
| N::getExtendedDeclaration(result) = this.asClassLikeDeclaration() | ||
| or | ||
| getExtendedTypeSelector(result) = this.asTypeSelector() | ||
| } | ||
|
|
||
| /** Gets a member of this class, including members declared in extensions. */ | ||
| Member getAMember() { result = this.getADeclaration().getAMember() } | ||
|
|
||
| /** Gets the name of this class. */ | ||
| string getName() { | ||
| result = this.asClassLikeDeclaration().getName() | ||
| or | ||
| result = this.asTypeSelector().getHead() | ||
| } | ||
|
|
||
| /** Gets the qualified name of this class. */ | ||
| string getQualifiedName() { | ||
| result = this.asClassLikeDeclaration().getQualifiedName() | ||
| or | ||
| result = this.asTypeSelector() | ||
| } | ||
|
|
||
| /** Gets a textual representation of this element. */ | ||
| string toString() { | ||
| result = this.asClassLikeDeclaration().toString() | ||
| or | ||
| result = this.asTypeSelector() | ||
| } | ||
|
|
||
| /** Gets the location of this element. */ | ||
| Location getLocation() { | ||
| result = this.asClassLikeDeclaration().getLocation() | ||
| or | ||
| exists(this.asTypeSelector()) and | ||
| result instanceof EmptyLocation | ||
| } | ||
| } |
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
Oops, something went wrong.
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.