Skip to content

Commit 363f7a8

Browse files
committed
Swift: fix QL warnings about overriding methods
The `getName` in `Type.qll` was issuing a warning in other generated classes having a `getName` from a `name` property in `schema.yml`. To fix the possible inconsistency, `diagnostic_name` is being renamed to `name` in the schema. Despite the scary doc comment on `swift::Type::getString` (namely `for use in diagnostics only`), that seems to be the right generic naming mechanism for types, and it coincides with the name we were extracting on types with an explicit `name` property. In case we find a case where `Type::getString` gives something wrong, we can probably just patch it on that specific type class.
1 parent c4c3a52 commit 363f7a8

32 files changed

+99
-117
lines changed

swift/codegen/schema.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Location:
3232
_pragma: qltest_skip
3333

3434
Type:
35-
diagnostics_name: string
35+
name: string
3636
canonical_type: Type
3737

3838
IterableDeclContext:
@@ -245,14 +245,12 @@ WeakStorageType:
245245

246246
ArchetypeType:
247247
_extends: SubstitutableType
248-
name: string
249248
interface_type: Type
250249
superclass: Type?
251250
protocols: ProtocolDecl*
252251

253252
GenericTypeParamType:
254253
_extends: SubstitutableType
255-
name: string
256254

257255
ParenType:
258256
_extends: SugarType

swift/extractor/visitors/TypeVisitor.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void TypeVisitor::visitGenericFunctionType(swift::GenericFunctionType* type) {
152152

153153
void TypeVisitor::visitGenericTypeParamType(swift::GenericTypeParamType* type) {
154154
auto label = dispatcher_.assignNewLabel(type);
155-
dispatcher_.emit(GenericTypeParamTypesTrap{label, type->getName().str().str()});
155+
dispatcher_.emit(GenericTypeParamTypesTrap{label});
156156
}
157157

158158
void TypeVisitor::visitLValueType(swift::LValueType* type) {
@@ -237,13 +237,12 @@ codeql::NestedArchetypeType TypeVisitor::translateNestedArchetypeType(
237237
}
238238

239239
void TypeVisitor::fillType(const swift::TypeBase& type, codeql::Type& entry) {
240-
entry.diagnostics_name = type.getString();
240+
entry.name = type.getString();
241241
entry.canonical_type = dispatcher_.fetchLabel(type.getCanonicalType());
242242
}
243243

244244
void TypeVisitor::fillArchetypeType(const swift::ArchetypeType& type, ArchetypeType& entry) {
245245
entry.interface_type = dispatcher_.fetchLabel(type.getInterfaceType());
246-
entry.name = type.getName().str().str();
247246
entry.protocols = dispatcher_.fetchRepeatedLabels(type.getConformsTo());
248247
entry.superclass = dispatcher_.fetchOptionalLabel(type.getSuperclass());
249248
}
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1+
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
12
private import codeql.swift.generated.type.AnyGenericType
2-
private import codeql.swift.elements.decl.GenericTypeDecl
33

4-
class AnyGenericType extends AnyGenericTypeBase {
5-
string getName() { result = this.getDeclaration().(GenericTypeDecl).getName() }
6-
}
4+
class AnyGenericType extends AnyGenericTypeBase { }
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
private import codeql.swift.generated.type.Type
22

33
class Type extends TypeBase {
4-
override string toString() { result = this.getDiagnosticsName() }
5-
6-
string getName() { result = this.getDiagnosticsName() }
4+
override string toString() { result = this.getName() }
75
}

swift/ql/lib/codeql/swift/generated/type/ArchetypeType.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import codeql.swift.elements.type.SubstitutableType
44
import codeql.swift.elements.type.Type
55

66
class ArchetypeTypeBase extends @archetype_type, SubstitutableType {
7-
string getName() { archetype_types(this, result, _) }
8-
97
Type getInterfaceType() {
108
exists(Type x |
11-
archetype_types(this, _, x) and
9+
archetype_types(this, x) and
1210
result = x.resolve()
1311
)
1412
}

swift/ql/lib/codeql/swift/generated/type/GenericTypeParamType.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@ import codeql.swift.elements.type.SubstitutableType
33

44
class GenericTypeParamTypeBase extends @generic_type_param_type, SubstitutableType {
55
override string getAPrimaryQlClass() { result = "GenericTypeParamType" }
6-
7-
string getName() { generic_type_param_types(this, result) }
86
}

swift/ql/lib/codeql/swift/generated/type/Type.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import codeql.swift.elements.Element
33
import codeql.swift.elements.type.Type
44

55
class TypeBase extends @type, Element {
6-
string getDiagnosticsName() { types(this, result, _) }
6+
string getName() { types(this, result, _) }
77

88
Type getCanonicalType() {
99
exists(Type x |

swift/ql/lib/swift.dbscheme

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ locations(
8282
#keyset[id]
8383
types( //dir=type
8484
int id: @type ref,
85-
string diagnostics_name: string ref,
85+
string name: string ref,
8686
int canonical_type: @type ref
8787
);
8888

@@ -593,7 +593,6 @@ weak_storage_types( //dir=type
593593
#keyset[id]
594594
archetype_types( //dir=type
595595
int id: @archetype_type ref,
596-
string name: string ref,
597596
int interface_type: @type ref
598597
);
599598

@@ -611,8 +610,7 @@ archetype_type_protocols( //dir=type
611610
);
612611

613612
generic_type_param_types( //dir=type
614-
unique int id: @generic_type_param_type,
615-
string name: string ref
613+
unique int id: @generic_type_param_type
616614
);
617615

618616
paren_types( //dir=type
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
| Builtin.Int8 | getDiagnosticsName: | Builtin.Int8 | getCanonicalType: | Builtin.Int8 |
2-
| Builtin.Int16 | getDiagnosticsName: | Builtin.Int16 | getCanonicalType: | Builtin.Int16 |
3-
| Builtin.Int32 | getDiagnosticsName: | Builtin.Int32 | getCanonicalType: | Builtin.Int32 |
4-
| Builtin.Int64 | getDiagnosticsName: | Builtin.Int64 | getCanonicalType: | Builtin.Int64 |
5-
| Builtin.Word | getDiagnosticsName: | Builtin.Word | getCanonicalType: | Builtin.Word |
1+
| Builtin.Int8 | getName: | Builtin.Int8 | getCanonicalType: | Builtin.Int8 |
2+
| Builtin.Int16 | getName: | Builtin.Int16 | getCanonicalType: | Builtin.Int16 |
3+
| Builtin.Int32 | getName: | Builtin.Int32 | getCanonicalType: | Builtin.Int32 |
4+
| Builtin.Int64 | getName: | Builtin.Int64 | getCanonicalType: | Builtin.Int64 |
5+
| Builtin.Word | getName: | Builtin.Word | getCanonicalType: | Builtin.Word |

swift/ql/test/extractor-tests/generated/type/BuiltinIntegerType/BuiltinIntegerType.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import codeql.swift.elements
33
import TestUtils
44

5-
from BuiltinIntegerType x, string getDiagnosticsName, Type getCanonicalType
5+
from BuiltinIntegerType x, string getName, Type getCanonicalType
66
where
77
toBeTested(x) and
88
not x.isUnknown() and
9-
getDiagnosticsName = x.getDiagnosticsName() and
9+
getName = x.getName() and
1010
getCanonicalType = x.getCanonicalType()
11-
select x, "getDiagnosticsName:", getDiagnosticsName, "getCanonicalType:", getCanonicalType
11+
select x, "getName:", getName, "getCanonicalType:", getCanonicalType

0 commit comments

Comments
 (0)