mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
C++: Introduce usertypes for structs and unions
This commit is contained in:
@@ -869,7 +869,7 @@ class AbstractClass extends Class {
|
||||
* `FullClassTemplateSpecialization`.
|
||||
*/
|
||||
class TemplateClass extends Class {
|
||||
TemplateClass() { usertypes(underlyingElement(this), _, 6) }
|
||||
TemplateClass() { usertypes(underlyingElement(this), _, [15, 16, 17]) }
|
||||
|
||||
/**
|
||||
* Gets a class instantiated from this template.
|
||||
|
||||
@@ -20,7 +20,7 @@ import semmle.code.cpp.Class
|
||||
* ```
|
||||
*/
|
||||
class Struct extends Class {
|
||||
Struct() { usertypes(underlyingElement(this), _, 1) or usertypes(underlyingElement(this), _, 3) }
|
||||
Struct() { usertypes(underlyingElement(this), _, [1, 3, 15, 17]) }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "Struct" }
|
||||
|
||||
|
||||
@@ -52,9 +52,7 @@ deprecated class TemplateParameter = TypeTemplateParameter;
|
||||
* ```
|
||||
*/
|
||||
class TypeTemplateParameter extends UserType, TemplateParameterImpl {
|
||||
TypeTemplateParameter() {
|
||||
usertypes(underlyingElement(this), _, 7) or usertypes(underlyingElement(this), _, 8)
|
||||
}
|
||||
TypeTemplateParameter() { usertypes(underlyingElement(this), _, [7, 8]) }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "TypeTemplateParameter" }
|
||||
|
||||
|
||||
@@ -406,10 +406,7 @@ class IntegralOrEnumType extends Type {
|
||||
isIntegralType(underlyingElement(this), _)
|
||||
or
|
||||
// Enum type
|
||||
(
|
||||
usertypes(underlyingElement(this), _, 4) or
|
||||
usertypes(underlyingElement(this), _, 13)
|
||||
)
|
||||
usertypes(underlyingElement(this), _, [4, 13])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,10 +13,7 @@ private import semmle.code.cpp.internal.ResolveClass
|
||||
* ```
|
||||
*/
|
||||
class TypedefType extends UserType {
|
||||
TypedefType() {
|
||||
usertypes(underlyingElement(this), _, 5) or
|
||||
usertypes(underlyingElement(this), _, 14)
|
||||
}
|
||||
TypedefType() { usertypes(underlyingElement(this), _, [5, 14]) }
|
||||
|
||||
/**
|
||||
* Gets the base type of this typedef type.
|
||||
|
||||
@@ -15,7 +15,7 @@ import semmle.code.cpp.Struct
|
||||
* ```
|
||||
*/
|
||||
class Union extends Struct {
|
||||
Union() { usertypes(underlyingElement(this), _, 3) }
|
||||
Union() { usertypes(underlyingElement(this), _, [3, 17]) }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "Union" }
|
||||
|
||||
|
||||
@@ -227,11 +227,11 @@ class ProxyClass extends UserType {
|
||||
}
|
||||
|
||||
class TypeTemplateParameter extends UserType {
|
||||
TypeTemplateParameter() { usertypes(this, _, 7) or usertypes(this, _, 8) }
|
||||
TypeTemplateParameter() { usertypes(this, _, [7, 8]) }
|
||||
}
|
||||
|
||||
class TemplateClass extends UserType {
|
||||
TemplateClass() { usertypes(this, _, 6) }
|
||||
TemplateClass() { usertypes(this, _, [15, 16, 17]) }
|
||||
|
||||
UserType getAnInstantiation() {
|
||||
class_instantiation(result, this) and
|
||||
|
||||
@@ -114,15 +114,7 @@ private module Cached {
|
||||
* Holds if `t` is a struct, class, union, or template.
|
||||
*/
|
||||
cached
|
||||
predicate isClass(@usertype t) {
|
||||
usertypes(t, _, 1) or
|
||||
usertypes(t, _, 2) or
|
||||
usertypes(t, _, 3) or
|
||||
usertypes(t, _, 6) or
|
||||
usertypes(t, _, 10) or
|
||||
usertypes(t, _, 11) or
|
||||
usertypes(t, _, 12)
|
||||
}
|
||||
predicate isClass(@usertype t) { usertypes(t, _, [1, 2, 3, 15, 16, 17]) }
|
||||
|
||||
cached
|
||||
predicate isType(@type t) {
|
||||
|
||||
@@ -771,12 +771,13 @@ decltypes(
|
||||
|
||||
/*
|
||||
case @usertype.kind of
|
||||
1 = @struct
|
||||
| 0 = @unknown_usertype
|
||||
| 1 = @struct
|
||||
| 2 = @class
|
||||
| 3 = @union
|
||||
| 4 = @enum
|
||||
| 5 = @typedef // classic C: typedef typedef type name
|
||||
| 6 = @template
|
||||
// ... 6 = @template deprecated
|
||||
| 7 = @template_parameter
|
||||
| 8 = @template_template_parameter
|
||||
| 9 = @proxy_class // a proxy class associated with a template parameter
|
||||
@@ -785,6 +786,9 @@ case @usertype.kind of
|
||||
// ... 12 objc_category deprecated
|
||||
| 13 = @scoped_enum
|
||||
| 14 = @using_alias // a using name = type style typedef
|
||||
| 15 = @template_struct
|
||||
| 16 = @template_class
|
||||
| 17 = @template_union
|
||||
;
|
||||
*/
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ string kindstr(Class c) {
|
||||
or
|
||||
kind = 2 and result = "Class"
|
||||
or
|
||||
kind = 6 and result = "Template class"
|
||||
kind = [15, 16] and result = "Template class"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user