mirror of
https://github.com/github/codeql.git
synced 2026-04-29 10:45:15 +02:00
Swift: add new children to VarDecl
This commit is contained in:
@@ -680,15 +680,39 @@ private module Impl {
|
||||
}
|
||||
|
||||
private Element getImmediateChildOfVarDecl(VarDecl e, int index, string partialPredicateCall) {
|
||||
exists(int b, int bAbstractStorageDecl, int n |
|
||||
exists(
|
||||
int b, int bAbstractStorageDecl, int n, int nPropertyWrapperBackingVarBinding,
|
||||
int nPropertyWrapperBackingVar, int nPropertyWrapperProjectionVarBinding,
|
||||
int nPropertyWrapperProjectionVar
|
||||
|
|
||||
b = 0 and
|
||||
bAbstractStorageDecl =
|
||||
b + 1 + max(int i | i = -1 or exists(getImmediateChildOfAbstractStorageDecl(e, i, _)) | i) and
|
||||
n = bAbstractStorageDecl and
|
||||
nPropertyWrapperBackingVarBinding = n + 1 and
|
||||
nPropertyWrapperBackingVar = nPropertyWrapperBackingVarBinding + 1 and
|
||||
nPropertyWrapperProjectionVarBinding = nPropertyWrapperBackingVar + 1 and
|
||||
nPropertyWrapperProjectionVar = nPropertyWrapperProjectionVarBinding + 1 and
|
||||
(
|
||||
none()
|
||||
or
|
||||
result = getImmediateChildOfAbstractStorageDecl(e, index - b, partialPredicateCall)
|
||||
or
|
||||
index = n and
|
||||
result = e.getImmediatePropertyWrapperBackingVarBinding() and
|
||||
partialPredicateCall = "PropertyWrapperBackingVarBinding()"
|
||||
or
|
||||
index = nPropertyWrapperBackingVarBinding and
|
||||
result = e.getImmediatePropertyWrapperBackingVar() and
|
||||
partialPredicateCall = "PropertyWrapperBackingVar()"
|
||||
or
|
||||
index = nPropertyWrapperBackingVar and
|
||||
result = e.getImmediatePropertyWrapperProjectionVarBinding() and
|
||||
partialPredicateCall = "PropertyWrapperProjectionVarBinding()"
|
||||
or
|
||||
index = nPropertyWrapperProjectionVarBinding and
|
||||
result = e.getImmediatePropertyWrapperProjectionVar() and
|
||||
partialPredicateCall = "PropertyWrapperProjectionVar()"
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -809,14 +833,27 @@ private module Impl {
|
||||
}
|
||||
|
||||
private Element getImmediateChildOfParamDecl(ParamDecl e, int index, string partialPredicateCall) {
|
||||
exists(int b, int bVarDecl, int n |
|
||||
exists(
|
||||
int b, int bVarDecl, int n, int nPropertyWrapperLocalWrappedVarBinding,
|
||||
int nPropertyWrapperLocalWrappedVar
|
||||
|
|
||||
b = 0 and
|
||||
bVarDecl = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfVarDecl(e, i, _)) | i) and
|
||||
n = bVarDecl and
|
||||
nPropertyWrapperLocalWrappedVarBinding = n + 1 and
|
||||
nPropertyWrapperLocalWrappedVar = nPropertyWrapperLocalWrappedVarBinding + 1 and
|
||||
(
|
||||
none()
|
||||
or
|
||||
result = getImmediateChildOfVarDecl(e, index - b, partialPredicateCall)
|
||||
or
|
||||
index = n and
|
||||
result = e.getImmediatePropertyWrapperLocalWrappedVarBinding() and
|
||||
partialPredicateCall = "PropertyWrapperLocalWrappedVarBinding()"
|
||||
or
|
||||
index = nPropertyWrapperLocalWrappedVarBinding and
|
||||
result = e.getImmediatePropertyWrapperLocalWrappedVar() and
|
||||
partialPredicateCall = "PropertyWrapperLocalWrappedVar()"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -235,6 +235,20 @@ module Raw {
|
||||
Pattern getParentPattern() { var_decl_parent_patterns(this, result) }
|
||||
|
||||
Expr getParentInitializer() { var_decl_parent_initializers(this, result) }
|
||||
|
||||
PatternBindingDecl getPropertyWrapperBackingVarBinding() {
|
||||
var_decl_property_wrapper_backing_var_bindings(this, result)
|
||||
}
|
||||
|
||||
VarDecl getPropertyWrapperBackingVar() { var_decl_property_wrapper_backing_vars(this, result) }
|
||||
|
||||
PatternBindingDecl getPropertyWrapperProjectionVarBinding() {
|
||||
var_decl_property_wrapper_projection_var_bindings(this, result)
|
||||
}
|
||||
|
||||
VarDecl getPropertyWrapperProjectionVar() {
|
||||
var_decl_property_wrapper_projection_vars(this, result)
|
||||
}
|
||||
}
|
||||
|
||||
class AccessorDecl extends @accessor_decl, FuncDecl {
|
||||
@@ -285,6 +299,14 @@ module Raw {
|
||||
override string toString() { result = "ParamDecl" }
|
||||
|
||||
predicate isInout() { param_decl_is_inout(this) }
|
||||
|
||||
PatternBindingDecl getPropertyWrapperLocalWrappedVarBinding() {
|
||||
param_decl_property_wrapper_local_wrapped_var_bindings(this, result)
|
||||
}
|
||||
|
||||
VarDecl getPropertyWrapperLocalWrappedVar() {
|
||||
param_decl_property_wrapper_local_wrapped_vars(this, result)
|
||||
}
|
||||
}
|
||||
|
||||
class TypeAliasDecl extends @type_alias_decl, GenericTypeDecl {
|
||||
|
||||
@@ -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.decl.PatternBindingDecl
|
||||
import codeql.swift.elements.decl.VarDecl
|
||||
|
||||
module Generated {
|
||||
@@ -11,5 +12,65 @@ module Generated {
|
||||
* Holds if this is an `inout` parameter.
|
||||
*/
|
||||
predicate isInout() { Synth::convertParamDeclToRaw(this).(Raw::ParamDecl).isInout() }
|
||||
|
||||
/**
|
||||
* Gets the property wrapper local wrapped var binding of this parameter declaration, 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.
|
||||
*/
|
||||
PatternBindingDecl getImmediatePropertyWrapperLocalWrappedVarBinding() {
|
||||
result =
|
||||
Synth::convertPatternBindingDeclFromRaw(Synth::convertParamDeclToRaw(this)
|
||||
.(Raw::ParamDecl)
|
||||
.getPropertyWrapperLocalWrappedVarBinding())
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the property wrapper local wrapped var binding of this parameter declaration, if it exists.
|
||||
*
|
||||
* This is the synthesized binding introducing the property wrapper local wrapped projection
|
||||
* variable for this variable, if any.
|
||||
*/
|
||||
final PatternBindingDecl getPropertyWrapperLocalWrappedVarBinding() {
|
||||
result = getImmediatePropertyWrapperLocalWrappedVarBinding().resolve()
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `getPropertyWrapperLocalWrappedVarBinding()` exists.
|
||||
*/
|
||||
final predicate hasPropertyWrapperLocalWrappedVarBinding() {
|
||||
exists(getPropertyWrapperLocalWrappedVarBinding())
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the property wrapper local wrapped var of this parameter declaration, 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.
|
||||
*/
|
||||
VarDecl getImmediatePropertyWrapperLocalWrappedVar() {
|
||||
result =
|
||||
Synth::convertVarDeclFromRaw(Synth::convertParamDeclToRaw(this)
|
||||
.(Raw::ParamDecl)
|
||||
.getPropertyWrapperLocalWrappedVar())
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the property wrapper local wrapped var of this parameter declaration, if it exists.
|
||||
*
|
||||
* This is the synthesized local wrapped value, shadowing this parameter declaration in case it
|
||||
* has a property wrapper.
|
||||
*/
|
||||
final VarDecl getPropertyWrapperLocalWrappedVar() {
|
||||
result = getImmediatePropertyWrapperLocalWrappedVar().resolve()
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `getPropertyWrapperLocalWrappedVar()` exists.
|
||||
*/
|
||||
final predicate hasPropertyWrapperLocalWrappedVar() {
|
||||
exists(getPropertyWrapperLocalWrappedVar())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ private import codeql.swift.generated.Raw
|
||||
import codeql.swift.elements.decl.AbstractStorageDecl
|
||||
import codeql.swift.elements.expr.Expr
|
||||
import codeql.swift.elements.pattern.Pattern
|
||||
import codeql.swift.elements.decl.PatternBindingDecl
|
||||
import codeql.swift.elements.type.Type
|
||||
|
||||
module Generated {
|
||||
@@ -98,5 +99,121 @@ module Generated {
|
||||
* Holds if `getParentInitializer()` exists.
|
||||
*/
|
||||
final predicate hasParentInitializer() { exists(getParentInitializer()) }
|
||||
|
||||
/**
|
||||
* Gets the property wrapper backing var binding of this var declaration, 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.
|
||||
*/
|
||||
PatternBindingDecl getImmediatePropertyWrapperBackingVarBinding() {
|
||||
result =
|
||||
Synth::convertPatternBindingDeclFromRaw(Synth::convertVarDeclToRaw(this)
|
||||
.(Raw::VarDecl)
|
||||
.getPropertyWrapperBackingVarBinding())
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the property wrapper backing var binding of this var declaration, if it exists.
|
||||
*
|
||||
* This is the synthesized binding introducing the property wrapper backing variable for this
|
||||
* variable, if any.
|
||||
*/
|
||||
final PatternBindingDecl getPropertyWrapperBackingVarBinding() {
|
||||
result = getImmediatePropertyWrapperBackingVarBinding().resolve()
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `getPropertyWrapperBackingVarBinding()` exists.
|
||||
*/
|
||||
final predicate hasPropertyWrapperBackingVarBinding() {
|
||||
exists(getPropertyWrapperBackingVarBinding())
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the property wrapper backing var of this var declaration, 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.
|
||||
*/
|
||||
VarDecl getImmediatePropertyWrapperBackingVar() {
|
||||
result =
|
||||
Synth::convertVarDeclFromRaw(Synth::convertVarDeclToRaw(this)
|
||||
.(Raw::VarDecl)
|
||||
.getPropertyWrapperBackingVar())
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the property wrapper backing var of this var declaration, if it exists.
|
||||
*
|
||||
* This is the synthesized variable holding the property wrapper for this variable, if any.
|
||||
*/
|
||||
final VarDecl getPropertyWrapperBackingVar() {
|
||||
result = getImmediatePropertyWrapperBackingVar().resolve()
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `getPropertyWrapperBackingVar()` exists.
|
||||
*/
|
||||
final predicate hasPropertyWrapperBackingVar() { exists(getPropertyWrapperBackingVar()) }
|
||||
|
||||
/**
|
||||
* Gets the property wrapper projection var binding of this var declaration, 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.
|
||||
*/
|
||||
PatternBindingDecl getImmediatePropertyWrapperProjectionVarBinding() {
|
||||
result =
|
||||
Synth::convertPatternBindingDeclFromRaw(Synth::convertVarDeclToRaw(this)
|
||||
.(Raw::VarDecl)
|
||||
.getPropertyWrapperProjectionVarBinding())
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the property wrapper projection var binding of this var declaration, if it exists.
|
||||
*
|
||||
* This is the synthesized binding introducing the property wrapper projection variable for this
|
||||
* variable, if any.
|
||||
*/
|
||||
final PatternBindingDecl getPropertyWrapperProjectionVarBinding() {
|
||||
result = getImmediatePropertyWrapperProjectionVarBinding().resolve()
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `getPropertyWrapperProjectionVarBinding()` exists.
|
||||
*/
|
||||
final predicate hasPropertyWrapperProjectionVarBinding() {
|
||||
exists(getPropertyWrapperProjectionVarBinding())
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the property wrapper projection var of this var declaration, 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.
|
||||
*/
|
||||
VarDecl getImmediatePropertyWrapperProjectionVar() {
|
||||
result =
|
||||
Synth::convertVarDeclFromRaw(Synth::convertVarDeclToRaw(this)
|
||||
.(Raw::VarDecl)
|
||||
.getPropertyWrapperProjectionVar())
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the property wrapper projection var of this var declaration, if it exists.
|
||||
*
|
||||
* If this variable has a property wrapper with a projected value, this is the corresponding
|
||||
* synthesized variable holding that projected value, accessible with this variable's name
|
||||
* prefixed with `$`.
|
||||
*/
|
||||
final VarDecl getPropertyWrapperProjectionVar() {
|
||||
result = getImmediatePropertyWrapperProjectionVar().resolve()
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `getPropertyWrapperProjectionVar()` exists.
|
||||
*/
|
||||
final predicate hasPropertyWrapperProjectionVar() { exists(getPropertyWrapperProjectionVar()) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -483,6 +483,30 @@ var_decl_parent_initializers( //dir=decl
|
||||
int parent_initializer: @expr_or_none ref
|
||||
);
|
||||
|
||||
#keyset[id]
|
||||
var_decl_property_wrapper_backing_var_bindings( //dir=decl
|
||||
int id: @var_decl ref,
|
||||
int property_wrapper_backing_var_binding: @pattern_binding_decl_or_none ref
|
||||
);
|
||||
|
||||
#keyset[id]
|
||||
var_decl_property_wrapper_backing_vars( //dir=decl
|
||||
int id: @var_decl ref,
|
||||
int property_wrapper_backing_var: @var_decl_or_none ref
|
||||
);
|
||||
|
||||
#keyset[id]
|
||||
var_decl_property_wrapper_projection_var_bindings( //dir=decl
|
||||
int id: @var_decl ref,
|
||||
int property_wrapper_projection_var_binding: @pattern_binding_decl_or_none ref
|
||||
);
|
||||
|
||||
#keyset[id]
|
||||
var_decl_property_wrapper_projection_vars( //dir=decl
|
||||
int id: @var_decl ref,
|
||||
int property_wrapper_projection_var: @var_decl_or_none ref
|
||||
);
|
||||
|
||||
accessor_decls( //dir=decl
|
||||
unique int id: @accessor_decl
|
||||
);
|
||||
@@ -558,6 +582,18 @@ param_decl_is_inout( //dir=decl
|
||||
int id: @param_decl ref
|
||||
);
|
||||
|
||||
#keyset[id]
|
||||
param_decl_property_wrapper_local_wrapped_var_bindings( //dir=decl
|
||||
int id: @param_decl ref,
|
||||
int property_wrapper_local_wrapped_var_binding: @pattern_binding_decl_or_none ref
|
||||
);
|
||||
|
||||
#keyset[id]
|
||||
param_decl_property_wrapper_local_wrapped_vars( //dir=decl
|
||||
int id: @param_decl ref,
|
||||
int property_wrapper_local_wrapped_var: @var_decl_or_none ref
|
||||
);
|
||||
|
||||
type_alias_decls( //dir=decl
|
||||
unique int id: @type_alias_decl
|
||||
);
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// generated by codegen/codegen.py
|
||||
import codeql.swift.elements
|
||||
import TestUtils
|
||||
|
||||
from ConcreteVarDecl x
|
||||
where toBeTested(x) and not x.isUnknown()
|
||||
select x, x.getPropertyWrapperBackingVar()
|
||||
@@ -0,0 +1,7 @@
|
||||
// generated by codegen/codegen.py
|
||||
import codeql.swift.elements
|
||||
import TestUtils
|
||||
|
||||
from ConcreteVarDecl x
|
||||
where toBeTested(x) and not x.isUnknown()
|
||||
select x, x.getPropertyWrapperBackingVarBinding()
|
||||
@@ -0,0 +1,7 @@
|
||||
// generated by codegen/codegen.py
|
||||
import codeql.swift.elements
|
||||
import TestUtils
|
||||
|
||||
from ConcreteVarDecl x
|
||||
where toBeTested(x) and not x.isUnknown()
|
||||
select x, x.getPropertyWrapperProjectionVar()
|
||||
@@ -0,0 +1,7 @@
|
||||
// generated by codegen/codegen.py
|
||||
import codeql.swift.elements
|
||||
import TestUtils
|
||||
|
||||
from ConcreteVarDecl x
|
||||
where toBeTested(x) and not x.isUnknown()
|
||||
select x, x.getPropertyWrapperProjectionVarBinding()
|
||||
@@ -0,0 +1,7 @@
|
||||
// generated by codegen/codegen.py
|
||||
import codeql.swift.elements
|
||||
import TestUtils
|
||||
|
||||
from ParamDecl x
|
||||
where toBeTested(x) and not x.isUnknown()
|
||||
select x, x.getPropertyWrapperBackingVar()
|
||||
@@ -0,0 +1,7 @@
|
||||
// generated by codegen/codegen.py
|
||||
import codeql.swift.elements
|
||||
import TestUtils
|
||||
|
||||
from ParamDecl x
|
||||
where toBeTested(x) and not x.isUnknown()
|
||||
select x, x.getPropertyWrapperBackingVarBinding()
|
||||
@@ -0,0 +1,7 @@
|
||||
// generated by codegen/codegen.py
|
||||
import codeql.swift.elements
|
||||
import TestUtils
|
||||
|
||||
from ParamDecl x
|
||||
where toBeTested(x) and not x.isUnknown()
|
||||
select x, x.getPropertyWrapperLocalWrappedVar()
|
||||
@@ -0,0 +1,7 @@
|
||||
// generated by codegen/codegen.py
|
||||
import codeql.swift.elements
|
||||
import TestUtils
|
||||
|
||||
from ParamDecl x
|
||||
where toBeTested(x) and not x.isUnknown()
|
||||
select x, x.getPropertyWrapperLocalWrappedVarBinding()
|
||||
@@ -0,0 +1,7 @@
|
||||
// generated by codegen/codegen.py
|
||||
import codeql.swift.elements
|
||||
import TestUtils
|
||||
|
||||
from ParamDecl x
|
||||
where toBeTested(x) and not x.isUnknown()
|
||||
select x, x.getPropertyWrapperProjectionVar()
|
||||
@@ -0,0 +1,7 @@
|
||||
// generated by codegen/codegen.py
|
||||
import codeql.swift.elements
|
||||
import TestUtils
|
||||
|
||||
from ParamDecl x
|
||||
where toBeTested(x) and not x.isUnknown()
|
||||
select x, x.getPropertyWrapperProjectionVarBinding()
|
||||
305
swift/schema.py
305
swift/schema.py
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user