mirror of
https://github.com/github/codeql.git
synced 2026-04-28 10:15:14 +02:00
Swift: extract DynamicSelfType
This commit is contained in:
@@ -93,6 +93,7 @@ DependentMemberType:
|
||||
|
||||
DynamicSelfType:
|
||||
_extends: Type
|
||||
static_self_type: Type
|
||||
|
||||
ErrorType:
|
||||
_extends: Type
|
||||
|
||||
@@ -253,11 +253,18 @@ void TypeVisitor::fillArchetypeType(const swift::ArchetypeType& type, ArchetypeT
|
||||
entry.superclass = dispatcher_.fetchOptionalLabel(type.getSuperclass());
|
||||
fillType(type, entry);
|
||||
}
|
||||
|
||||
codeql::ExistentialType TypeVisitor::translateExistentialType(const swift::ExistentialType& type) {
|
||||
codeql::ExistentialType entry{dispatcher_.assignNewLabel(type)};
|
||||
entry.constraint = dispatcher_.fetchLabel(type.getConstraintType());
|
||||
fillType(type, entry);
|
||||
return entry;
|
||||
}
|
||||
codeql::DynamicSelfType TypeVisitor::translateDynamicSelfType(const swift::DynamicSelfType& type) {
|
||||
codeql::DynamicSelfType entry{dispatcher_.assignNewLabel(type)};
|
||||
entry.static_self_type = dispatcher_.fetchLabel(type.getSelfType());
|
||||
fillType(type, entry);
|
||||
return entry;
|
||||
}
|
||||
|
||||
} // namespace codeql
|
||||
|
||||
@@ -39,6 +39,7 @@ class TypeVisitor : public TypeVisitorBase<TypeVisitor> {
|
||||
const swift::PrimaryArchetypeType& type);
|
||||
codeql::NestedArchetypeType translateNestedArchetypeType(const swift::NestedArchetypeType& type);
|
||||
codeql::ExistentialType translateExistentialType(const swift::ExistentialType& type);
|
||||
codeql::DynamicSelfType translateDynamicSelfType(const swift::DynamicSelfType& type);
|
||||
|
||||
private:
|
||||
void fillType(const swift::TypeBase& type, codeql::Type& entry);
|
||||
|
||||
@@ -3,4 +3,11 @@ import codeql.swift.elements.type.Type
|
||||
|
||||
class DynamicSelfTypeBase extends @dynamic_self_type, Type {
|
||||
override string getAPrimaryQlClass() { result = "DynamicSelfType" }
|
||||
|
||||
Type getStaticSelfType() {
|
||||
exists(Type x |
|
||||
dynamic_self_types(this, x) and
|
||||
result = x.resolve()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,7 +244,8 @@ dependent_member_types( //dir=type
|
||||
);
|
||||
|
||||
dynamic_self_types( //dir=type
|
||||
unique int id: @dynamic_self_type
|
||||
unique int id: @dynamic_self_type,
|
||||
int static_self_type: @type ref
|
||||
);
|
||||
|
||||
error_types( //dir=type
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
| Self | getDiagnosticsName: | Self | getCanonicalType: | Self | getStaticSelfType: | X |
|
||||
@@ -0,0 +1,13 @@
|
||||
// generated by codegen/codegen.py
|
||||
import codeql.swift.elements
|
||||
import TestUtils
|
||||
|
||||
from DynamicSelfType x, string getDiagnosticsName, Type getCanonicalType, Type getStaticSelfType
|
||||
where
|
||||
toBeTested(x) and
|
||||
not x.isUnknown() and
|
||||
getDiagnosticsName = x.getDiagnosticsName() and
|
||||
getCanonicalType = x.getCanonicalType() and
|
||||
getStaticSelfType = x.getStaticSelfType()
|
||||
select x, "getDiagnosticsName:", getDiagnosticsName, "getCanonicalType:", getCanonicalType,
|
||||
"getStaticSelfType:", getStaticSelfType
|
||||
@@ -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,4 @@
|
||||
class X {
|
||||
class func create() -> Self { return Self() }
|
||||
required init() {}
|
||||
}
|
||||
Reference in New Issue
Block a user