mirror of
https://github.com/github/codeql.git
synced 2026-04-28 02:05:14 +02:00
Swift: extract ModuleType
This commit is contained in:
@@ -112,6 +112,7 @@ LValueType:
|
||||
|
||||
ModuleType:
|
||||
_extends: Type
|
||||
module: ModuleDecl
|
||||
|
||||
PlaceholderType:
|
||||
_extends: Type
|
||||
|
||||
@@ -381,4 +381,14 @@ codeql::OpenedArchetypeType TypeVisitor::translateOpenedArchetypeType(
|
||||
fillArchetypeType(type, entry);
|
||||
return entry;
|
||||
}
|
||||
|
||||
codeql::ModuleType TypeVisitor::translateModuleType(const swift::ModuleType& type) {
|
||||
auto key = type.getModule()->getRealName().str().str();
|
||||
if (type.getModule()->isNonSwiftModule()) {
|
||||
key += "|clang";
|
||||
}
|
||||
auto entry = createTypeEntry(type, key);
|
||||
entry.module = dispatcher_.fetchLabel(type.getModule());
|
||||
return entry;
|
||||
}
|
||||
} // namespace codeql
|
||||
|
||||
@@ -71,6 +71,7 @@ class TypeVisitor : public TypeVisitorBase<TypeVisitor> {
|
||||
const swift::BuiltinUnsafeValueBufferType& type);
|
||||
codeql::BuiltinVectorType translateBuiltinVectorType(const swift::BuiltinVectorType& type);
|
||||
codeql::OpenedArchetypeType translateOpenedArchetypeType(const swift::OpenedArchetypeType& type);
|
||||
codeql::ModuleType translateModuleType(const swift::ModuleType& type);
|
||||
|
||||
private:
|
||||
void fillType(const swift::TypeBase& type, codeql::Type& entry);
|
||||
@@ -83,9 +84,9 @@ class TypeVisitor : public TypeVisitorBase<TypeVisitor> {
|
||||
void emitBoundGenericType(swift::BoundGenericType* type, TrapLabel<BoundGenericTypeTag> label);
|
||||
void emitAnyGenericType(swift::AnyGenericType* type, TrapLabel<AnyGenericTypeTag> label);
|
||||
|
||||
template <typename T>
|
||||
auto createTypeEntry(const T& type) {
|
||||
auto entry = dispatcher_.createEntry(type);
|
||||
template <typename T, typename... Args>
|
||||
auto createTypeEntry(const T& type, const Args&... args) {
|
||||
auto entry = dispatcher_.createEntry(type, args...);
|
||||
fillType(type, entry);
|
||||
return entry;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
// generated by codegen/codegen.py
|
||||
import codeql.swift.elements.decl.ModuleDecl
|
||||
import codeql.swift.elements.type.Type
|
||||
|
||||
class ModuleTypeBase extends @module_type, Type {
|
||||
override string getAPrimaryQlClass() { result = "ModuleType" }
|
||||
|
||||
ModuleDecl getModule() {
|
||||
exists(ModuleDecl x |
|
||||
module_types(this, x) and
|
||||
result = x.resolve()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,7 +264,8 @@ l_value_types( //dir=type
|
||||
);
|
||||
|
||||
module_types( //dir=type
|
||||
unique int id: @module_type
|
||||
unique int id: @module_type,
|
||||
int module: @module_decl ref
|
||||
);
|
||||
|
||||
placeholder_types( //dir=type
|
||||
|
||||
@@ -4,7 +4,11 @@ cached
|
||||
predicate toBeTested(Element e) {
|
||||
e instanceof File
|
||||
or
|
||||
exists(ModuleDecl m | m = e and not m.isBuiltinModule() and not m.isSystemModule())
|
||||
exists(ModuleDecl m |
|
||||
not m.isBuiltinModule() and
|
||||
not m.isSystemModule() and
|
||||
(m = e or m.getInterfaceType() = e)
|
||||
)
|
||||
or
|
||||
exists(Locatable loc |
|
||||
loc.getLocation().getFile().getName().matches("%swift/ql/test%") and
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
| file://:0:0:0:0 | Foo | getInterfaceType: | module<Foo> | getName: | Foo | isBuiltinModule: | no | isSystemModule: | no |
|
||||
| file://:0:0:0:0 | default_module_name | getInterfaceType: | module<default_module_name> | getName: | default_module_name | isBuiltinModule: | no | isSystemModule: | no |
|
||||
|
||||
@@ -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,2 @@
|
||||
| module<Foo> | getName: | module<Foo> | getCanonicalType: | module<Foo> | getModule: | file://:0:0:0:0 | Foo |
|
||||
| module<default_module_name> | getName: | module<default_module_name> | getCanonicalType: | module<default_module_name> | getModule: | file://:0:0:0:0 | default_module_name |
|
||||
@@ -0,0 +1,12 @@
|
||||
// generated by codegen/codegen.py
|
||||
import codeql.swift.elements
|
||||
import TestUtils
|
||||
|
||||
from ModuleType x, string getName, Type getCanonicalType, ModuleDecl getModule
|
||||
where
|
||||
toBeTested(x) and
|
||||
not x.isUnknown() and
|
||||
getName = x.getName() and
|
||||
getCanonicalType = x.getCanonicalType() and
|
||||
getModule = x.getModule()
|
||||
select x, "getName:", getName, "getCanonicalType:", getCanonicalType, "getModule:", getModule
|
||||
@@ -0,0 +1 @@
|
||||
//codeql-extractor-options: -module-name Foo
|
||||
Reference in New Issue
Block a user