mirror of
https://github.com/github/codeql.git
synced 2026-05-02 04:05:14 +02:00
adding standard C/C++ fixed width, minimum width, and maximum width types
This commit is contained in:
@@ -63,13 +63,258 @@ class Ptrdiff_t extends Type {
|
||||
override string getAPrimaryQlClass() { result = "Ptrdiff_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* A common base type for describing the C/C++ fixed-width numeric types
|
||||
*/
|
||||
abstract class FixedWidthIntegralType extends UserType {
|
||||
FixedWidthIntegralType() { this.getUnderlyingType() instanceof IntegralType }
|
||||
}
|
||||
|
||||
/**
|
||||
* A common base type for describing the C/C++ minimum-width numeric types.
|
||||
*/
|
||||
abstract class MinimumWidthIntegralType extends UserType {
|
||||
MinimumWidthIntegralType() { this.getUnderlyingType() instanceof IntegralType }
|
||||
}
|
||||
|
||||
/**
|
||||
* A common base type for describing the C/C++ maximum-width numeric types.
|
||||
*/
|
||||
abstract class MaximumWidthIntegralType extends UserType {
|
||||
MaximumWidthIntegralType() { this.getUnderlyingType() instanceof IntegralType }
|
||||
}
|
||||
|
||||
/**
|
||||
* A common base type for describing enum types that are based on fixed-width types.
|
||||
*/
|
||||
class FixedWidthEnumType extends UserType {
|
||||
FixedWidthEnumType() {
|
||||
this.(Enum).getExplicitUnderlyingType() instanceof FixedWidthIntegralType
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `int8_t` type.
|
||||
*/
|
||||
class Int8_t extends FixedWidthIntegralType {
|
||||
Int8_t() { this.hasGlobalOrStdName("int8_t") }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "Int8_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `int16_t` type.
|
||||
*/
|
||||
class Int16_t extends FixedWidthIntegralType {
|
||||
Int16_t() { this.hasGlobalOrStdName("int16_t") }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "Int16_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `int32_t` type.
|
||||
*/
|
||||
class Int32_t extends FixedWidthIntegralType {
|
||||
Int32_t() { this.hasGlobalOrStdName("int32_t") }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "Int32_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `int64_t` type.
|
||||
*/
|
||||
class Int64_t extends FixedWidthIntegralType {
|
||||
Int64_t() { this.hasGlobalOrStdName("int64_t") }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "Int64_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `uint8_t` type.
|
||||
*/
|
||||
class UInt8_t extends FixedWidthIntegralType {
|
||||
UInt8_t() { this.hasGlobalOrStdName("uint8_t") }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "UInt8_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `uint16_t` type.
|
||||
*/
|
||||
class UInt16_t extends FixedWidthIntegralType {
|
||||
UInt16_t() { this.hasGlobalOrStdName("uint16_t") }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "UInt16_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `uint32_t` type.
|
||||
*/
|
||||
class UInt32_t extends FixedWidthIntegralType {
|
||||
UInt32_t() { this.hasGlobalOrStdName("uint32_t") }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "UInt32_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `uint64_t` type.
|
||||
*/
|
||||
class UInt64_t extends FixedWidthIntegralType {
|
||||
UInt64_t() { this.hasGlobalOrStdName("uint64_t") }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "UInt64_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `int_least8_t` type.
|
||||
*/
|
||||
class Int_least8_t extends MinimumWidthIntegralType {
|
||||
Int_least8_t() { this.hasGlobalOrStdName("int_least8_t") }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "Int_least8_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `int_least16_t` type.
|
||||
*/
|
||||
class Int_least16_t extends MinimumWidthIntegralType {
|
||||
Int_least16_t() { this.hasGlobalOrStdName("int_least16_t") }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "Int_least16_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `int_least32_t` type.
|
||||
*/
|
||||
class Int_least32_t extends MinimumWidthIntegralType {
|
||||
Int_least32_t() { this.hasGlobalOrStdName("int_least32_t") }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "Int_least32_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `int_least64_t` type.
|
||||
*/
|
||||
class Int_least64_t extends MinimumWidthIntegralType {
|
||||
Int_least64_t() { this.hasGlobalOrStdName("int_least64_t") }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "Int_least64_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `uint_least8_t` type.
|
||||
*/
|
||||
class UInt_least8_t extends MinimumWidthIntegralType {
|
||||
UInt_least8_t() { this.hasGlobalOrStdName("uint_least8_t") }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "UInt_least8_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `uint_least16_t` type.
|
||||
*/
|
||||
class UInt_least16_t extends MinimumWidthIntegralType {
|
||||
UInt_least16_t() { this.hasGlobalOrStdName("uint_least16_t") }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "UInt_least16_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `uint_least32_t` type.
|
||||
*/
|
||||
class UInt_least32_t extends MinimumWidthIntegralType {
|
||||
UInt_least32_t() { this.hasGlobalOrStdName("uint_least32_t") }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "UInt_least32_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `uint_least64_t` type.
|
||||
*/
|
||||
class UInt_least64_t extends MinimumWidthIntegralType {
|
||||
UInt_least64_t() { this.hasGlobalOrStdName("uint_least64_t") }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "UInt_least64_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `int_fast8_t` type.
|
||||
*/
|
||||
class Int_fast8_t extends MinimumWidthIntegralType {
|
||||
Int_fast8_t() { this.hasGlobalOrStdName("int_fast8_t") }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "Int_fast8_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `int_fast16_t` type.
|
||||
*/
|
||||
class Int_fast16_t extends MinimumWidthIntegralType {
|
||||
Int_fast16_t() { this.hasGlobalOrStdName("int_fast16_t") }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "Int_fast16_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `int_fast32_t` type.
|
||||
*/
|
||||
class Int_fast32_t extends MinimumWidthIntegralType {
|
||||
Int_fast32_t() { this.hasGlobalOrStdName("int_fast32_t") }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "Int_fast32_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `int_fast64_t` type.
|
||||
*/
|
||||
class Int_fast64_t extends MinimumWidthIntegralType {
|
||||
Int_fast64_t() { this.hasGlobalOrStdName("int_fast64_t") }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "Int_fast64_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `uint_fast8_t` type.
|
||||
*/
|
||||
class UInt_fast8_t extends MinimumWidthIntegralType {
|
||||
UInt_fast8_t() { this.hasGlobalOrStdName("uint_fast8_t") }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "UInt_fast8_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `uint_fast16_t` type.
|
||||
*/
|
||||
class UInt_fast16_t extends MinimumWidthIntegralType {
|
||||
UInt_fast16_t() { this.hasGlobalOrStdName("uint_fast16_t") }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "UInt_fast16_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `uint_fast32_t` type.
|
||||
*/
|
||||
class UInt_fast32_t extends MinimumWidthIntegralType {
|
||||
UInt_fast32_t() { this.hasGlobalOrStdName("uint_fast32_t") }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "UInt_fast32_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `uint_fast64_t` type.
|
||||
*/
|
||||
class UInt_fast64_t extends MinimumWidthIntegralType {
|
||||
UInt_fast64_t() { this.hasGlobalOrStdName("uint_fast64_t") }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "UInt_fast64_t" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The C/C++ `intmax_t` type.
|
||||
*/
|
||||
class Intmax_t extends Type {
|
||||
class Intmax_t extends MaximumWidthIntegralType {
|
||||
Intmax_t() {
|
||||
this.getUnderlyingType() instanceof IntegralType and
|
||||
this.hasName("intmax_t")
|
||||
this.hasGlobalOrStdName("intmax_t")
|
||||
}
|
||||
|
||||
override string getAPrimaryQlClass() { result = "Intmax_t" }
|
||||
@@ -78,10 +323,9 @@ class Intmax_t extends Type {
|
||||
/**
|
||||
* The C/C++ `uintmax_t` type.
|
||||
*/
|
||||
class Uintmax_t extends Type {
|
||||
class Uintmax_t extends MaximumWidthIntegralType {
|
||||
Uintmax_t() {
|
||||
this.getUnderlyingType() instanceof IntegralType and
|
||||
this.hasName("uintmax_t")
|
||||
this.hasGlobalOrStdName("uintmax_t")
|
||||
}
|
||||
|
||||
override string getAPrimaryQlClass() { result = "Uintmax_t" }
|
||||
|
||||
77
cpp/ql/test/library-tests/types/cstd_types/cstd_types.cpp
Normal file
77
cpp/ql/test/library-tests/types/cstd_types/cstd_types.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
typedef signed char int8_t;
|
||||
typedef short int16_t;
|
||||
typedef int int32_t;
|
||||
typedef long long int64_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
|
||||
typedef signed char int_least8_t;
|
||||
typedef short int_least16_t;
|
||||
typedef int int_least32_t;
|
||||
typedef long long int_least64_t;
|
||||
typedef unsigned char uint_least8_t;
|
||||
typedef unsigned short uint_least16_t;
|
||||
typedef unsigned int uint_least32_t;
|
||||
typedef unsigned long long uint_least64_t;
|
||||
|
||||
typedef signed char int_fast8_t;
|
||||
typedef int int_fast16_t;
|
||||
typedef int int_fast32_t;
|
||||
typedef long long int_fast64_t;
|
||||
typedef unsigned char uint_fast8_t;
|
||||
typedef unsigned int uint_fast16_t;
|
||||
typedef unsigned int uint_fast32_t;
|
||||
typedef unsigned long long uint_fast64_t;
|
||||
|
||||
typedef long long intmax_t;
|
||||
typedef unsigned long long uintmax_t;
|
||||
|
||||
int8_t i8;
|
||||
int16_t i16;
|
||||
int32_t i32;
|
||||
int64_t i64;
|
||||
uint8_t ui8;
|
||||
uint16_t ui16;
|
||||
uint32_t ui32;
|
||||
uint64_t ui64;
|
||||
int_least8_t l8;
|
||||
int_least16_t l16;
|
||||
int_least32_t l32;
|
||||
int_least64_t l64;
|
||||
uint_least8_t ul8;
|
||||
uint_least16_t ul16;
|
||||
uint_least32_t ul32;
|
||||
uint_least64_t ul64;
|
||||
int_fast8_t if8;
|
||||
int_fast16_t if16;
|
||||
int_fast32_t if32;
|
||||
int_fast64_t if64;
|
||||
uint_fast8_t uf8;
|
||||
uint_fast16_t uf16;
|
||||
uint_fast32_t uf32;
|
||||
uint_fast64_t uf64;
|
||||
intmax_t im;
|
||||
uintmax_t uim;
|
||||
|
||||
enum E0 : int8_t {
|
||||
e0
|
||||
};
|
||||
|
||||
enum class E1 : int8_t {
|
||||
e1
|
||||
};
|
||||
|
||||
enum E2 {
|
||||
e2
|
||||
};
|
||||
|
||||
enum class E3 {
|
||||
e3
|
||||
};
|
||||
|
||||
E0 _e0;
|
||||
E1 _e1;
|
||||
E2 _e2;
|
||||
E3 _e3;
|
||||
@@ -0,0 +1,8 @@
|
||||
| cstd_types.cpp:31:8:31:9 | i8 | CTypedefType, Int8_t |
|
||||
| cstd_types.cpp:32:9:32:11 | i16 | CTypedefType, Int16_t |
|
||||
| cstd_types.cpp:33:9:33:11 | i32 | CTypedefType, Int32_t |
|
||||
| cstd_types.cpp:34:9:34:11 | i64 | CTypedefType, Int64_t |
|
||||
| cstd_types.cpp:35:9:35:11 | ui8 | CTypedefType, UInt8_t |
|
||||
| cstd_types.cpp:36:10:36:13 | ui16 | CTypedefType, UInt16_t |
|
||||
| cstd_types.cpp:37:10:37:13 | ui32 | CTypedefType, UInt32_t |
|
||||
| cstd_types.cpp:38:10:38:13 | ui64 | CTypedefType, UInt64_t |
|
||||
@@ -0,0 +1,5 @@
|
||||
import cpp
|
||||
|
||||
from Variable v, FixedWidthIntegralType t
|
||||
where v.getType() = t
|
||||
select v, concat(t.getAQlClass(), ", ")
|
||||
@@ -0,0 +1,2 @@
|
||||
| cstd_types.cpp:74:4:74:6 | _e0 | Enum, FixedWidthEnumType |
|
||||
| cstd_types.cpp:75:4:75:6 | _e1 | FixedWidthEnumType, ScopedEnum |
|
||||
@@ -0,0 +1,5 @@
|
||||
import cpp
|
||||
|
||||
from Variable v, FixedWidthEnumType t
|
||||
where v.getType() = t
|
||||
select v, concat(t.getAQlClass(), ", ")
|
||||
@@ -0,0 +1,2 @@
|
||||
| cstd_types.cpp:55:10:55:11 | im | CTypedefType, Intmax_t |
|
||||
| cstd_types.cpp:56:11:56:13 | uim | CTypedefType, Uintmax_t |
|
||||
@@ -0,0 +1,5 @@
|
||||
import cpp
|
||||
|
||||
from Variable v, MaximumWidthIntegralType t
|
||||
where v.getType() = t
|
||||
select v, concat(t.getAQlClass(), ", ")
|
||||
@@ -0,0 +1,16 @@
|
||||
| cstd_types.cpp:39:15:39:16 | l8 | CTypedefType, Int_least8_t |
|
||||
| cstd_types.cpp:40:15:40:17 | l16 | CTypedefType, Int_least16_t |
|
||||
| cstd_types.cpp:41:15:41:17 | l32 | CTypedefType, Int_least32_t |
|
||||
| cstd_types.cpp:42:15:42:17 | l64 | CTypedefType, Int_least64_t |
|
||||
| cstd_types.cpp:43:15:43:17 | ul8 | CTypedefType, UInt_least8_t |
|
||||
| cstd_types.cpp:44:16:44:19 | ul16 | CTypedefType, UInt_least16_t |
|
||||
| cstd_types.cpp:45:16:45:19 | ul32 | CTypedefType, UInt_least32_t |
|
||||
| cstd_types.cpp:46:16:46:19 | ul64 | CTypedefType, UInt_least64_t |
|
||||
| cstd_types.cpp:47:13:47:15 | if8 | CTypedefType, Int_fast8_t |
|
||||
| cstd_types.cpp:48:14:48:17 | if16 | CTypedefType, Int_fast16_t |
|
||||
| cstd_types.cpp:49:14:49:17 | if32 | CTypedefType, Int_fast32_t |
|
||||
| cstd_types.cpp:50:14:50:17 | if64 | CTypedefType, Int_fast64_t |
|
||||
| cstd_types.cpp:51:14:51:16 | uf8 | CTypedefType, UInt_fast8_t |
|
||||
| cstd_types.cpp:52:15:52:18 | uf16 | CTypedefType, UInt_fast16_t |
|
||||
| cstd_types.cpp:53:15:53:18 | uf32 | CTypedefType, UInt_fast32_t |
|
||||
| cstd_types.cpp:54:15:54:18 | uf64 | CTypedefType, UInt_fast64_t |
|
||||
@@ -0,0 +1,5 @@
|
||||
import cpp
|
||||
|
||||
from Variable v, MinimumWidthIntegralType t
|
||||
where v.getType() = t
|
||||
select v, concat(t.getAQlClass(), ", ")
|
||||
@@ -80,3 +80,6 @@ size_t st;
|
||||
ssize_t sst;
|
||||
ptrdiff_t pdt;
|
||||
wchar_t wct;
|
||||
|
||||
std::int8_t i8;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user