mirror of
https://github.com/github/codeql.git
synced 2026-04-27 17:55:19 +02:00
Swift: extract InoutType
This commit is contained in:
@@ -100,6 +100,7 @@ ErrorType:
|
||||
|
||||
InOutType:
|
||||
_extends: Type
|
||||
object_type: Type
|
||||
|
||||
LValueType:
|
||||
_extends: Type
|
||||
|
||||
@@ -271,4 +271,11 @@ codeql::VariadicSequenceType TypeVisitor::translateVariadicSequenceType(
|
||||
return entry;
|
||||
}
|
||||
|
||||
codeql::InOutType TypeVisitor::translateInOutType(const swift::InOutType& type) {
|
||||
codeql::InOutType entry{dispatcher_.assignNewLabel(type)};
|
||||
entry.object_type = dispatcher_.fetchLabel(type.getObjectType());
|
||||
fillType(type, entry);
|
||||
return entry;
|
||||
}
|
||||
|
||||
} // namespace codeql
|
||||
|
||||
@@ -42,6 +42,7 @@ class TypeVisitor : public TypeVisitorBase<TypeVisitor> {
|
||||
codeql::DynamicSelfType translateDynamicSelfType(const swift::DynamicSelfType& type);
|
||||
codeql::VariadicSequenceType translateVariadicSequenceType(
|
||||
const swift::VariadicSequenceType& type);
|
||||
codeql::InOutType translateInOutType(const swift::InOutType& type);
|
||||
|
||||
private:
|
||||
void fillType(const swift::TypeBase& type, codeql::Type& entry);
|
||||
|
||||
@@ -3,4 +3,11 @@ import codeql.swift.elements.type.Type
|
||||
|
||||
class InOutTypeBase extends @in_out_type, Type {
|
||||
override string getAPrimaryQlClass() { result = "InOutType" }
|
||||
|
||||
Type getObjectType() {
|
||||
exists(Type x |
|
||||
in_out_types(this, x) and
|
||||
result = x.resolve()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,7 +253,8 @@ error_types( //dir=type
|
||||
);
|
||||
|
||||
in_out_types( //dir=type
|
||||
unique int id: @in_out_type
|
||||
unique int id: @in_out_type,
|
||||
int object_type: @type ref
|
||||
);
|
||||
|
||||
l_value_types( //dir=type
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
| inout Int | getDiagnosticsName: | inout Int | getCanonicalType: | inout Int | getObjectType: | Int |
|
||||
| inout S | getDiagnosticsName: | inout S | getCanonicalType: | inout S | getObjectType: | S |
|
||||
@@ -0,0 +1,13 @@
|
||||
// generated by codegen/codegen.py
|
||||
import codeql.swift.elements
|
||||
import TestUtils
|
||||
|
||||
from InOutType x, string getDiagnosticsName, Type getCanonicalType, Type getObjectType
|
||||
where
|
||||
toBeTested(x) and
|
||||
not x.isUnknown() and
|
||||
getDiagnosticsName = x.getDiagnosticsName() and
|
||||
getCanonicalType = x.getCanonicalType() and
|
||||
getObjectType = x.getObjectType()
|
||||
select x, "getDiagnosticsName:", getDiagnosticsName, "getCanonicalType:", getCanonicalType,
|
||||
"getObjectType:", getObjectType
|
||||
@@ -1,4 +0,0 @@
|
||||
// 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
|
||||
@@ -0,0 +1,12 @@
|
||||
func foo(_: inout Int) {}
|
||||
|
||||
var x: Int = 42
|
||||
|
||||
foo(&x)
|
||||
|
||||
struct S {
|
||||
mutating func bar() {}
|
||||
}
|
||||
|
||||
var s: S
|
||||
s.bar()
|
||||
Reference in New Issue
Block a user