Swift: add children to UnspecifiedElement

This will allow better downgrade scripts in the future.
This commit is contained in:
Paolo Tranquilli
2023-10-18 16:31:20 +02:00
parent 4246ebf9e0
commit d55289bf68
13 changed files with 10599 additions and 4 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,3 @@
description: Revert adding children to `UnspecifiedElement`
compatibility: backwards
unspecified_element_children.rel: delete

View File

@@ -376,15 +376,15 @@ lib/codeql/swift/generated/KeyPathComponent.qll c79c7bc04fc1426992ab472eedc1a20a
lib/codeql/swift/generated/Locatable.qll be20967d48a34cdba126fe298606e0adc11697831f097acba9c52a0b7ce9983e 8aa01bc376614abbc3209e25785c72f86c9b4e94bb5f471a4a0677fedaec4f61
lib/codeql/swift/generated/Location.qll c5793987e77812059a28254dadee29bfe9b38153c0399fbb1bf6a2f5c237fdab 6e6d8802b021e36bbaad81845657769dd48a798ea33080ada05e9818a20b38f7
lib/codeql/swift/generated/OtherAvailabilitySpec.qll 0e26a203b26ff0581b7396b0c6d1606feec5cc32477f676585cdec4911af91c5 0e26a203b26ff0581b7396b0c6d1606feec5cc32477f676585cdec4911af91c5
lib/codeql/swift/generated/ParentChild.qll 6415d679ce1d6fa227751ce260e4c3322494151c8df7e6e66c3d4b11878c3b9a 2e3ae6706170c1fdaaab947b55b145d50175c4e8ca669c8160bf2a4ee6524c7f
lib/codeql/swift/generated/ParentChild.qll 6e7b64896a2ad25a06130592ba27036e0e2b9bf4268a730d1bce78ebaf32607d dfe0e3c578f726cf2b7d024bf247701f12d6a79fd061a3c805d23fac85218635
lib/codeql/swift/generated/PlatformVersionAvailabilitySpec.qll f82d9ca416fe8bd59b5531b65b1c74c9f317b3297a6101544a11339a1cffce38 7f5c6d3309e66c134107afe55bae76dfc9a72cb7cdd6d4c3706b6b34cee09fa0
lib/codeql/swift/generated/PureSynthConstructors.qll 173c0dd59396a1de26fe870e3bc2766c46de689da2a4d8807cb62023bbce1a98 173c0dd59396a1de26fe870e3bc2766c46de689da2a4d8807cb62023bbce1a98
lib/codeql/swift/generated/Raw.qll 233caf2d5f8d584c20e023151aefe7be454013ed3fd73239d35528b1e74af1c5 e0d8ad912aa936d0766fdd9183d35057876d08e7cbcbbd01ff6e9d3d615f1046
lib/codeql/swift/generated/Raw.qll 349eb78e973669d9f30922399571bc31313f781c82c2993cdae4b03493440c1d 1537b15a42b35dd7e22a7e22e70dce38ed93e00e79678bbd78cfd14c1433fcbe
lib/codeql/swift/generated/Synth.qll 551fdf7e4b53f9ee1314d1bb42c2638cf82f45bfa1f40a635dfa7b6072e4418c 9ab178464700a19951fc5285acacda4913addee81515d8e072b3d7055935a814
lib/codeql/swift/generated/SynthConstructors.qll 2f801bd8b0db829b0253cd459ed3253c1fdfc55dce68ebc53e7fec138ef0aca4 2f801bd8b0db829b0253cd459ed3253c1fdfc55dce68ebc53e7fec138ef0aca4
lib/codeql/swift/generated/UnknownFile.qll 0fcf9beb8de79440bcdfff4bb6ab3dd139bd273e6c32754e05e6a632651e85f6 0fcf9beb8de79440bcdfff4bb6ab3dd139bd273e6c32754e05e6a632651e85f6
lib/codeql/swift/generated/UnknownLocation.qll e50efefa02a0ec1ff635a00951b5924602fc8cab57e5756e4a039382c69d3882 e50efefa02a0ec1ff635a00951b5924602fc8cab57e5756e4a039382c69d3882
lib/codeql/swift/generated/UnspecifiedElement.qll ad04c197266069baf505e529e62751ab3056b4bac5db378fe1f79bbdfa29e066 a5058c7e3e0ba7d52710161e349a71f3e963d4abe07ca581ad663395fc50e972
lib/codeql/swift/generated/UnspecifiedElement.qll bfe0dfb0a34fe8f7501710809cdfb82dc423bece9f3bcd23ebfb0e3ecb7aadf7 cdf7553ba0324a7670f6a275ff99bad96498f7363234f829533a27b6e97892f4
lib/codeql/swift/generated/decl/AbstractStorageDecl.qll 4e827d05b3b98c043f925a3bd9c00622da3dc6e3d3406f5a18b2c3a684e3774f 47e5767a6f9a87f848cccce651d8c40af8aa3e0e727fc147cbf4d5a2a3e483d9
lib/codeql/swift/generated/decl/AbstractTypeParamDecl.qll 1e268b00d0f2dbbd85aa70ac206c5e4a4612f06ba0091e5253483635f486ccf9 5479e13e99f68f1f347283535f8098964f7fd4a34326ff36ad5711b2de1ab0d0
lib/codeql/swift/generated/decl/Accessor.qll c93cdf7dbb87e6c9b09b5fcf469b952041f753914a892addeb24bb46eaa51d29 1e8104da2da146d3e4d8f5f96b87872e63162e53b46f9c7038c75db51a676599

View File

@@ -0,0 +1,5 @@
---
category: minorAnalysis
---
* Added children of `UnspecifiedElement`, which will be present only in certain downgraded databases.

View File

@@ -244,15 +244,19 @@ private module Impl {
private Element getImmediateChildOfUnspecifiedElement(
UnspecifiedElement e, int index, string partialPredicateCall
) {
exists(int b, int bErrorElement, int n |
exists(int b, int bErrorElement, int n, int nChild |
b = 0 and
bErrorElement =
b + 1 + max(int i | i = -1 or exists(getImmediateChildOfErrorElement(e, i, _)) | i) and
n = bErrorElement and
nChild = n + 1 + max(int i | i = -1 or exists(e.getImmediateChild(i)) | i) and
(
none()
or
result = getImmediateChildOfErrorElement(e, index - b, partialPredicateCall)
or
result = e.getImmediateChild(index - n) and
partialPredicateCall = "Child(" + (index - n).toString() + ")"
)
)
}

View File

@@ -271,6 +271,13 @@ module Raw {
* Gets the error of this unspecified element.
*/
string getError() { unspecified_elements(this, _, result) }
/**
* Gets the `index`th child of this unspecified element (0-based).
*
* These will be present only in certain downgraded databases.
*/
AstNode getChild(int index) { unspecified_element_children(this, index, result) }
}
/**

View File

@@ -1,6 +1,7 @@
// generated by codegen/codegen.py
private import codeql.swift.generated.Synth
private import codeql.swift.generated.Raw
import codeql.swift.elements.AstNode
import codeql.swift.elements.Element
import codeql.swift.elements.ErrorElement
@@ -61,5 +62,40 @@ module Generated {
string getError() {
result = Synth::convertUnspecifiedElementToRaw(this).(Raw::UnspecifiedElement).getError()
}
/**
* Gets the `index`th child of this unspecified element (0-based).
*
* 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.
*/
AstNode getImmediateChild(int index) {
result =
Synth::convertAstNodeFromRaw(Synth::convertUnspecifiedElementToRaw(this)
.(Raw::UnspecifiedElement)
.getChild(index))
}
/**
* Gets the `index`th child of this unspecified element (0-based).
*
* These will be present only in certain downgraded databases.
*/
final AstNode getChild(int index) {
exists(AstNode immediate |
immediate = this.getImmediateChild(index) and
result = immediate.resolve()
)
}
/**
* Gets any of the children of this unspecified element.
*/
final AstNode getAChild() { result = this.getChild(_) }
/**
* Gets the number of children of this unspecified element.
*/
final int getNumberOfChildren() { result = count(int i | exists(this.getChild(i))) }
}
}

View File

@@ -217,6 +217,13 @@ unspecified_element_indices(
int index: int ref
);
#keyset[id, index]
unspecified_element_children(
int id: @unspecified_element ref,
int index: int ref,
int child: @ast_node_or_none ref
);
other_availability_specs(
unique int id: @other_availability_spec
);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
description: Add children to `UnspecifiedElement`
compatibility: full

View File

@@ -47,6 +47,7 @@ class UnspecifiedElement(ErrorElement):
property: string
index: optional[int]
error: string
children: list["AstNode"] | child | desc("These will be present only in certain downgraded databases.")
class Comment(Locatable):
text: string