Swift: reorganize some children in schema.yml

This commit is contained in:
Paolo Tranquilli
2022-08-29 14:52:14 +02:00
parent 898689f550
commit 0aecbc2a01
5 changed files with 23 additions and 25 deletions

View File

@@ -80,8 +80,8 @@ AstNode:
Callable:
_children:
params: ParamDecl*
self_param: ParamDecl?
params: ParamDecl*
body: BraceStmt?
ConditionElement:
@@ -545,7 +545,7 @@ RebindSelfInConstructorExpr:
_extends: Expr
_children:
sub_expr: Expr
self: VarDecl
self: VarDecl
SequenceExpr:
_extends: Expr

View File

@@ -6,6 +6,17 @@ import codeql.swift.elements.Element
import codeql.swift.elements.decl.ParamDecl
class CallableBase extends Synth::TCallable, Element {
ParamDecl getImmediateSelfParam() {
result =
Synth::convertParamDeclFromRaw(Synth::convertCallableToRaw(this)
.(Raw::Callable)
.getSelfParam())
}
final ParamDecl getSelfParam() { result = getImmediateSelfParam().resolve() }
final predicate hasSelfParam() { exists(getSelfParam()) }
ParamDecl getImmediateParam(int index) {
result =
Synth::convertParamDeclFromRaw(Synth::convertCallableToRaw(this)
@@ -19,17 +30,6 @@ class CallableBase extends Synth::TCallable, Element {
final int getNumberOfParams() { result = count(getAParam()) }
ParamDecl getImmediateSelfParam() {
result =
Synth::convertParamDeclFromRaw(Synth::convertCallableToRaw(this)
.(Raw::Callable)
.getSelfParam())
}
final ParamDecl getSelfParam() { result = getImmediateSelfParam().resolve() }
final predicate hasSelfParam() { exists(getSelfParam()) }
BraceStmt getImmediateBody() {
result =
Synth::convertBraceStmtFromRaw(Synth::convertCallableToRaw(this).(Raw::Callable).getBody())

View File

@@ -13,10 +13,10 @@ Element getAnImmediateChild(Element e) {
// * none() simplifies generation, as we can append `or ...` without a special case for the first item
none()
or
result = e.(Callable).getImmediateParam(_)
or
result = e.(Callable).getImmediateSelfParam()
or
result = e.(Callable).getImmediateParam(_)
or
result = e.(Callable).getImmediateBody()
or
result = e.(AbstractStorageDecl).getImmediateAccessorDecl(_)
@@ -123,8 +123,6 @@ Element getAnImmediateChild(Element e) {
or
result = e.(RebindSelfInConstructorExpr).getImmediateSubExpr()
or
result = e.(RebindSelfInConstructorExpr).getImmediateSelf()
or
result = e.(SelfApplyExpr).getImmediateBase()
or
result = e.(SequenceExpr).getImmediateElement(_)

View File

@@ -6,10 +6,10 @@ module Raw {
}
class Callable extends @callable, Element {
ParamDecl getParam(int index) { callable_params(this, index, result) }
ParamDecl getSelfParam() { callable_self_params(this, result) }
ParamDecl getParam(int index) { callable_params(this, index, result) }
BraceStmt getBody() { callable_bodies(this, result) }
}

View File

@@ -166,6 +166,12 @@ nominal_type_decls( //dir=decl
| @abstract_function_decl
;
#keyset[id]
callable_self_params(
int id: @callable ref,
int self_param: @param_decl ref
);
#keyset[id, index]
callable_params(
int id: @callable ref,
@@ -173,12 +179,6 @@ callable_params(
int param: @param_decl ref
);
#keyset[id]
callable_self_params(
int id: @callable ref,
int self_param: @param_decl ref
);
#keyset[id]
callable_bodies(
int id: @callable ref,