Swift: Add integral type classes.

This commit is contained in:
Mathias Vorreiter Pedersen
2023-01-09 09:43:09 +00:00
parent 9be9636816
commit 6bb09ef289
3 changed files with 48 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
private import swift
/**
* A floating-point type. This includes the `Float` type, the `Double`, and
* builtin floating-point types.
*/
class FloatingPointType extends Type {
FloatingPointType() {
this.getName() = ["Float", "Double"] or
this instanceof BuiltinFloatType
}
}

View File

@@ -0,0 +1,35 @@
private import swift
/** The `Character` type. */
class CharacterType extends StructType {
CharacterType() { this.getName() = "Character" }
}
/**
* An integer-like type. For example, `Int`, `Int16`, `Uint16`, etc.
*/
class IntegerType extends Type {
IntegerType() {
this.getName() =
["Int", "Int8", "Int16", "Int32", "Int64", "UInt", "UInt8", "Uint16", "Uint32", "UInt64"]
or
this instanceof BuiltinIntegerType
}
}
/** The `Bool` type. */
class BooleanType extends Type {
BooleanType() { this.getName() = "Bool" }
}
/**
* A numeric-like type. This includes the types `Character`, `Bool`, and all
* the integer-like types.
*/
class NumericOrCharType extends Type {
NumericOrCharType() {
this instanceof CharacterType or
this instanceof IntegerType or
this instanceof BooleanType
}
}

View File

@@ -10,4 +10,5 @@ import codeql.swift.elements.expr.InitializerCallExpr
import codeql.swift.elements.expr.SelfRefExpr
import codeql.swift.elements.decl.MethodDecl
import codeql.swift.elements.decl.ClassOrStructDecl
import codeql.swift.elements.type.NumericOrCharType
import codeql.swift.Unit