mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Merge pull request #18606 from jketema/typeref
C++: Support mixed `typedef`s and `using`s
This commit is contained in:
2444
cpp/downgrades/e594389175c098d7225683d0fd8cefcc47d84bc1/old.dbscheme
Normal file
2444
cpp/downgrades/e594389175c098d7225683d0fd8cefcc47d84bc1/old.dbscheme
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,4 @@
|
||||
description: Mix typedefs and usings
|
||||
compatibility: full
|
||||
usertypes.rel: run usertypes.qlo
|
||||
usertype_alias_kind.rel: delete
|
||||
@@ -0,0 +1,20 @@
|
||||
class UserType extends @usertype {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
int getTyperefKind(UserType usertype) {
|
||||
usertype_alias_kind(usertype, 0) and
|
||||
result = 5
|
||||
or
|
||||
usertype_alias_kind(usertype, 1) and
|
||||
result = 14
|
||||
}
|
||||
|
||||
bindingset[kind]
|
||||
int getKind(UserType usertype, int kind) {
|
||||
if kind = 18 then result = getTyperefKind(usertype) else result = kind
|
||||
}
|
||||
|
||||
from UserType usertype, string name, int kind
|
||||
where usertypes(usertype, name, kind)
|
||||
select usertype, name, getKind(usertype, kind)
|
||||
@@ -13,7 +13,7 @@ private import semmle.code.cpp.internal.ResolveClass
|
||||
* ```
|
||||
*/
|
||||
class TypedefType extends UserType {
|
||||
TypedefType() { usertypes(underlyingElement(this), _, [5, 14]) }
|
||||
TypedefType() { usertypes(underlyingElement(this), _, 18) }
|
||||
|
||||
/**
|
||||
* Gets the base type of this typedef type.
|
||||
@@ -54,7 +54,7 @@ class TypedefType extends UserType {
|
||||
* ```
|
||||
*/
|
||||
class CTypedefType extends TypedefType {
|
||||
CTypedefType() { usertypes(underlyingElement(this), _, 5) }
|
||||
CTypedefType() { usertype_alias_kind(underlyingElement(this), 0) }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "CTypedefType" }
|
||||
|
||||
@@ -70,7 +70,7 @@ class CTypedefType extends TypedefType {
|
||||
* ```
|
||||
*/
|
||||
class UsingAliasTypedefType extends TypedefType {
|
||||
UsingAliasTypedefType() { usertypes(underlyingElement(this), _, 14) }
|
||||
UsingAliasTypedefType() { usertype_alias_kind(underlyingElement(this), 1) }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "UsingAliasTypedefType" }
|
||||
|
||||
|
||||
@@ -776,7 +776,7 @@ case @usertype.kind of
|
||||
| 2 = @class
|
||||
| 3 = @union
|
||||
| 4 = @enum
|
||||
| 5 = @typedef // classic C: typedef typedef type name
|
||||
// ... 5 = @typedef deprecated // classic C: typedef typedef type name
|
||||
// ... 6 = @template deprecated
|
||||
| 7 = @template_parameter
|
||||
| 8 = @template_template_parameter
|
||||
@@ -785,10 +785,11 @@ case @usertype.kind of
|
||||
// ... 11 objc_protocol deprecated
|
||||
// ... 12 objc_category deprecated
|
||||
| 13 = @scoped_enum
|
||||
| 14 = @using_alias // a using name = type style typedef
|
||||
// ... 14 = @using_alias deprecated // a using name = type style typedef
|
||||
| 15 = @template_struct
|
||||
| 16 = @template_class
|
||||
| 17 = @template_union
|
||||
| 18 = @alias
|
||||
;
|
||||
*/
|
||||
|
||||
@@ -811,6 +812,17 @@ usertype_uuid(
|
||||
string uuid: string ref
|
||||
);
|
||||
|
||||
/*
|
||||
case @usertype.alias_kind of
|
||||
| 0 = @typedef
|
||||
| 1 = @alias
|
||||
*/
|
||||
|
||||
usertype_alias_kind(
|
||||
int id: @usertype ref,
|
||||
int alias_kind: int ref
|
||||
)
|
||||
|
||||
nontype_template_parameters(
|
||||
int id: @expr ref
|
||||
);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,4 @@
|
||||
description: Mix typedefs and usings
|
||||
compatibility: full
|
||||
usertypes.rel: run usertypes.qlo
|
||||
usertype_alias_kind.rel: run usertype_alias_kind.qlo
|
||||
@@ -0,0 +1,14 @@
|
||||
class UserType extends @usertype {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
bindingset[kind]
|
||||
int getKind(int kind) {
|
||||
kind = 5 and result = 0
|
||||
or
|
||||
kind = 14 and result = 1
|
||||
}
|
||||
|
||||
from UserType usertype, int kind
|
||||
where usertypes(usertype, _, kind)
|
||||
select usertype, getKind(kind)
|
||||
@@ -0,0 +1,10 @@
|
||||
class UserType extends @usertype {
|
||||
string toString() { none() }
|
||||
}
|
||||
|
||||
bindingset[kind]
|
||||
int getKind(int kind) { if kind = [5, 14] then result = 18 else result = kind }
|
||||
|
||||
from UserType usertype, string name, int kind
|
||||
where usertypes(usertype, name, kind)
|
||||
select usertype, name, getKind(kind)
|
||||
Reference in New Issue
Block a user