Swift: add UnspecifiedElement

This commit is contained in:
Paolo Tranquilli
2022-11-02 16:24:56 +01:00
parent 2aa528852e
commit e17bc6c581
11 changed files with 482 additions and 168 deletions

View File

@@ -11,6 +11,7 @@ import codeql.swift.elements.Location
import codeql.swift.elements.UnknownFile
import codeql.swift.elements.UnknownLocation
import codeql.swift.elements.UnresolvedElement
import codeql.swift.elements.UnspecifiedElement
import codeql.swift.elements.decl.AbstractFunctionDecl
import codeql.swift.elements.decl.AbstractStorageDecl
import codeql.swift.elements.decl.AbstractTypeParamDecl

View File

@@ -0,0 +1,4 @@
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
private import codeql.swift.generated.UnspecifiedElement
class UnspecifiedElement extends Generated::UnspecifiedElement { }

View File

@@ -0,0 +1,4 @@
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
private import codeql.swift.generated.Raw
predicate constructUnspecifiedElement(Raw::UnspecifiedElement id) { any() }

View File

@@ -165,6 +165,21 @@ private module Impl {
)
}
private Element getImmediateChildOfUnspecifiedElement(
UnspecifiedElement e, int index, string partialPredicateCall
) {
exists(int b, int bLocatable, int n |
b = 0 and
bLocatable = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfLocatable(e, i, _)) | i) and
n = bLocatable and
(
none()
or
result = getImmediateChildOfLocatable(e, index - b, partialPredicateCall)
)
)
}
private Element getImmediateChildOfDecl(Decl e, int index, string partialPredicateCall) {
exists(int b, int bAstNode, int n |
b = 0 and
@@ -4871,6 +4886,8 @@ private module Impl {
or
result = getImmediateChildOfUnknownLocation(e, index, partialAccessor)
or
result = getImmediateChildOfUnspecifiedElement(e, index, partialAccessor)
or
result = getImmediateChildOfEnumCaseDecl(e, index, partialAccessor)
or
result = getImmediateChildOfExtensionDecl(e, index, partialAccessor)

View File

@@ -51,6 +51,18 @@ module Raw {
override string toString() { result = "DbLocation" }
}
class UnspecifiedElement extends @unspecified_element, Locatable {
override string toString() { result = "UnspecifiedElement" }
Element getParent() { unspecified_element_parents(this, result) }
string getProperty() { unspecified_elements(this, result, _) }
int getIndex() { unspecified_element_indices(this, result) }
string getError() { unspecified_elements(this, _, result) }
}
class Decl extends @decl, AstNode {
ModuleDecl getModule() { decls(this, result) }
}

View File

@@ -10,6 +10,7 @@ module Synth {
TDbLocation(Raw::DbLocation id) { constructDbLocation(id) } or
TUnknownFile() or
TUnknownLocation() or
TUnspecifiedElement(Raw::UnspecifiedElement id) { constructUnspecifiedElement(id) } or
TAccessorDecl(Raw::AccessorDecl id) { constructAccessorDecl(id) } or
TAssociatedTypeDecl(Raw::AssociatedTypeDecl id) { constructAssociatedTypeDecl(id) } or
TClassDecl(Raw::ClassDecl id) { constructClassDecl(id) } or
@@ -321,7 +322,7 @@ module Synth {
class TFile = TDbFile or TUnknownFile;
class TLocatable = TArgument or TAstNode or TComment;
class TLocatable = TArgument or TAstNode or TComment or TUnspecifiedElement;
class TLocation = TDbLocation or TUnknownLocation;
@@ -499,6 +500,11 @@ module Synth {
cached
TUnknownLocation convertUnknownLocationFromRaw(Raw::Element e) { none() }
cached
TUnspecifiedElement convertUnspecifiedElementFromRaw(Raw::Element e) {
result = TUnspecifiedElement(e)
}
cached
TAccessorDecl convertAccessorDeclFromRaw(Raw::Element e) { result = TAccessorDecl(e) }
@@ -1464,6 +1470,8 @@ module Synth {
result = convertAstNodeFromRaw(e)
or
result = convertCommentFromRaw(e)
or
result = convertUnspecifiedElementFromRaw(e)
}
cached
@@ -2199,6 +2207,11 @@ module Synth {
cached
Raw::Element convertUnknownLocationToRaw(TUnknownLocation e) { none() }
cached
Raw::Element convertUnspecifiedElementToRaw(TUnspecifiedElement e) {
e = TUnspecifiedElement(result)
}
cached
Raw::Element convertAccessorDeclToRaw(TAccessorDecl e) { e = TAccessorDecl(result) }
@@ -3162,6 +3175,8 @@ module Synth {
result = convertAstNodeToRaw(e)
or
result = convertCommentToRaw(e)
or
result = convertUnspecifiedElementToRaw(e)
}
cached

View File

@@ -2,6 +2,7 @@
import codeql.swift.elements.CommentConstructor
import codeql.swift.elements.DbFileConstructor
import codeql.swift.elements.DbLocationConstructor
import codeql.swift.elements.UnspecifiedElementConstructor
import codeql.swift.elements.decl.AccessorDeclConstructor
import codeql.swift.elements.decl.AssociatedTypeDeclConstructor
import codeql.swift.elements.decl.ClassDeclConstructor

View File

@@ -0,0 +1,60 @@
// generated by codegen/codegen.py
private import codeql.swift.generated.Synth
private import codeql.swift.generated.Raw
import codeql.swift.elements.Element
import codeql.swift.elements.Locatable
module Generated {
class UnspecifiedElement extends Synth::TUnspecifiedElement, Locatable {
override string getAPrimaryQlClass() { result = "UnspecifiedElement" }
/**
* Gets the parent of this unspecified element, if it exists.
*
* This includes nodes from the "hidden" AST. It can be overridden in subclasses to change the
* behavior of both the `Immediate` and non-`Immediate` versions.
*/
Element getImmediateParent() {
result =
Synth::convertElementFromRaw(Synth::convertUnspecifiedElementToRaw(this)
.(Raw::UnspecifiedElement)
.getParent())
}
/**
* Gets the parent of this unspecified element, if it exists.
*/
final Element getParent() { result = getImmediateParent().resolve() }
/**
* Holds if `getParent()` exists.
*/
final predicate hasParent() { exists(getParent()) }
/**
* Gets the property of this unspecified element.
*/
string getProperty() {
result = Synth::convertUnspecifiedElementToRaw(this).(Raw::UnspecifiedElement).getProperty()
}
/**
* Gets the index of this unspecified element, if it exists.
*/
int getIndex() {
result = Synth::convertUnspecifiedElementToRaw(this).(Raw::UnspecifiedElement).getIndex()
}
/**
* Holds if `getIndex()` exists.
*/
final predicate hasIndex() { exists(getIndex()) }
/**
* Gets the error of this unspecified element.
*/
string getError() {
result = Synth::convertUnspecifiedElementToRaw(this).(Raw::UnspecifiedElement).getError()
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,4 @@
// generated by codegen/codegen.py
After a swift source file is added in this directory and codegen/codegen.py is run again, test queries
will appear and this file will be deleted

View File

@@ -37,6 +37,13 @@ class Location(Element):
class Locatable(Element):
location: optional[Location] | cpp.skip | doc("location associated with this element in the code")
@use_for_null
class UnspecifiedElement(Locatable):
parent: optional[Element]
property: string
index: optional[int]
error: string
class Comment(Locatable):
text: string