Skip to content

Commit 22e57a6

Browse files
authored
Merge pull request github#1860 from matt-gretton-dann/add-using-aliases
Add support for using aliases
2 parents 8989761 + 4606587 commit 22e57a6

File tree

13 files changed

+4490
-632
lines changed

13 files changed

+4490
-632
lines changed

cpp/ql/src/semmle/code/cpp/TypedefType.qll

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@ private import semmle.code.cpp.internal.ResolveClass
33

44
/**
55
* A C/C++ typedef type. See 4.9.1.
6+
*
7+
* Represents either of the following typedef styles:
8+
*
9+
* * CTypedefType: typedef <type> <name>;
10+
* * UsingAliasTypedefType: using <name> = <type>;
611
*/
712
class TypedefType extends UserType {
8-
TypedefType() { usertypes(underlyingElement(this), _, 5) }
9-
10-
override string getCanonicalQLClass() { result = "TypedefType" }
13+
TypedefType() {
14+
usertypes(underlyingElement(this), _, 5) or
15+
usertypes(underlyingElement(this), _, 14)
16+
}
1117

1218
/**
1319
* Gets the base type of this typedef type.
@@ -26,10 +32,6 @@ class TypedefType extends UserType {
2632
result = this.getBaseType().getPointerIndirectionLevel()
2733
}
2834

29-
override string explain() {
30-
result = "typedef {" + this.getBaseType().explain() + "} as \"" + this.getName() + "\""
31-
}
32-
3335
override predicate isDeeplyConst() { this.getBaseType().isDeeplyConst() } // Just an alias
3436

3537
override predicate isDeeplyConstBelow() { this.getBaseType().isDeeplyConstBelow() } // Just an alias
@@ -45,6 +47,32 @@ class TypedefType extends UserType {
4547
override Type stripType() { result = getBaseType().stripType() }
4648
}
4749

50+
/**
51+
* A traditional C/C++ typedef type. See 4.9.1.
52+
*/
53+
class CTypedefType extends TypedefType {
54+
CTypedefType() { usertypes(underlyingElement(this), _, 5) }
55+
56+
override string getCanonicalQLClass() { result = "CTypedefType" }
57+
58+
override string explain() {
59+
result = "typedef {" + this.getBaseType().explain() + "} as \"" + this.getName() + "\""
60+
}
61+
}
62+
63+
/**
64+
* A using alias C++ typedef type.
65+
*/
66+
class UsingAliasTypedefType extends TypedefType {
67+
UsingAliasTypedefType() { usertypes(underlyingElement(this), _, 14) }
68+
69+
override string getCanonicalQLClass() { result = "UsingAliasTypedefType" }
70+
71+
override string explain() {
72+
result = "using {" + this.getBaseType().explain() + "} as \"" + this.getName() + "\""
73+
}
74+
}
75+
4876
/**
4977
* A C++ typedef type that is directly enclosed by a function.
5078
*/

cpp/ql/src/semmlecode.cpp.dbscheme

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ decltypes(
675675
| 2 = class
676676
| 3 = union
677677
| 4 = enum
678-
| 5 = typedef
678+
| 5 = typedef // classic C: typedef typedef type name
679679
| 6 = template
680680
| 7 = template_parameter
681681
| 8 = template_template_parameter
@@ -684,6 +684,7 @@ decltypes(
684684
// ... 11 objc_protocol deprecated
685685
// ... 12 objc_category deprecated
686686
| 13 = scoped_enum
687+
| 14 = using_alias // a using name = type style typedef
687688
;
688689
*/
689690
usertypes(

0 commit comments

Comments
 (0)