Skip to content

Commit 6bb09ef

Browse files
committed
Swift: Add integral type classes.
1 parent 9be9636 commit 6bb09ef

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
private import swift
2+
3+
/**
4+
* A floating-point type. This includes the `Float` type, the `Double`, and
5+
* builtin floating-point types.
6+
*/
7+
class FloatingPointType extends Type {
8+
FloatingPointType() {
9+
this.getName() = ["Float", "Double"] or
10+
this instanceof BuiltinFloatType
11+
}
12+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
private import swift
2+
3+
/** The `Character` type. */
4+
class CharacterType extends StructType {
5+
CharacterType() { this.getName() = "Character" }
6+
}
7+
8+
/**
9+
* An integer-like type. For example, `Int`, `Int16`, `Uint16`, etc.
10+
*/
11+
class IntegerType extends Type {
12+
IntegerType() {
13+
this.getName() =
14+
["Int", "Int8", "Int16", "Int32", "Int64", "UInt", "UInt8", "Uint16", "Uint32", "UInt64"]
15+
or
16+
this instanceof BuiltinIntegerType
17+
}
18+
}
19+
20+
/** The `Bool` type. */
21+
class BooleanType extends Type {
22+
BooleanType() { this.getName() = "Bool" }
23+
}
24+
25+
/**
26+
* A numeric-like type. This includes the types `Character`, `Bool`, and all
27+
* the integer-like types.
28+
*/
29+
class NumericOrCharType extends Type {
30+
NumericOrCharType() {
31+
this instanceof CharacterType or
32+
this instanceof IntegerType or
33+
this instanceof BooleanType
34+
}
35+
}

swift/ql/lib/swift.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ import codeql.swift.elements.expr.InitializerCallExpr
1010
import codeql.swift.elements.expr.SelfRefExpr
1111
import codeql.swift.elements.decl.MethodDecl
1212
import codeql.swift.elements.decl.ClassOrStructDecl
13+
import codeql.swift.elements.type.NumericOrCharType
1314
import codeql.swift.Unit

0 commit comments

Comments
 (0)