Skip to content

Commit c2e2770

Browse files
committed
C++: Simplify type alias class naming
1 parent 305a63b commit c2e2770

6 files changed

Lines changed: 206 additions & 184 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
22
category: feature
33
---
4-
* Added `AliasTemplateTypedefType` and `AliasTemplateInstantiationTypedefType` classes, representing C++ alias templates and their instantiations.
4+
* Added `AliasTemplateType` and `AliasTemplateInstantiationType` classes, representing C++ alias templates and their instantiations.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: deprecated
3+
---
4+
* The `UsingAliasTypedefType` class has been deprecated. Use `TypeAliasType` instead.

cpp/ql/lib/semmle/code/cpp/Element.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ private predicate isFromTemplateInstantiationRec(Element e, Element instantiatio
278278
instantiation.(Variable).isConstructedFrom(_) and
279279
e = instantiation
280280
or
281-
instantiation.(UsingAliasTypedefType).isConstructedFrom(_) and
281+
instantiation.(TypeAliasType).isConstructedFrom(_) and
282282
e = instantiation
283283
or
284284
instantiation.(TemplateTemplateParameterInstantiation).isConstructedFrom(_) and

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

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,29 @@ class CTypedefType extends TypedefType {
6464
}
6565

6666
/**
67-
* A C++ type alias or alias template. For example the type declared in the following
68-
* code:
67+
* DEPRECATED: Use `TypeAlias` instead.
68+
*
69+
* A C++ type alias or alias template.
70+
*
71+
* For example the type declared in the following code:
6972
* ```
7073
* using my_int2 = int;
7174
* ```
7275
*/
73-
class UsingAliasTypedefType extends TypedefType {
74-
UsingAliasTypedefType() { usertype_alias_kind(underlyingElement(this), 1) }
76+
deprecated class UsingAliasTypedefType = TypeAliasType;
7577

76-
override string getAPrimaryQlClass() { result = "UsingAliasTypedefType" }
78+
/**
79+
* A C++ type alias or alias template.
80+
*
81+
* For example the type declared in the following code:
82+
* ```
83+
* using my_int2 = int;
84+
* ```
85+
*/
86+
class TypeAliasType extends TypedefType {
87+
TypeAliasType() { usertype_alias_kind(underlyingElement(this), 1) }
88+
89+
override string getAPrimaryQlClass() { result = "TypeAliasType" }
7790

7891
override string explain() {
7992
result = "using {" + this.getBaseType().explain() + "} as \"" + this.getName() + "\""
@@ -83,22 +96,24 @@ class UsingAliasTypedefType extends TypedefType {
8396
* Holds if this alias is constructed from another alias as a result of
8497
* template instantiation.
8598
*/
86-
predicate isConstructedFrom(UsingAliasTypedefType t) {
99+
predicate isConstructedFrom(TypeAliasType t) {
87100
alias_instantiation(underlyingElement(this), unresolveElement(t))
88101
}
89102
}
90103

91104
/**
92-
* A C++ alias template. For example the type declared in the following code:
105+
* A C++ alias template.
106+
*
107+
* For example the type declared in the following code:
93108
* ```
94109
* template <typename T>
95110
* using my_type = T;
96111
* ```
97112
*/
98-
class AliasTemplateTypedefType extends TypedefType {
99-
AliasTemplateTypedefType() { is_alias_template(underlyingElement(this)) }
113+
class AliasTemplateType extends TypeAliasType {
114+
AliasTemplateType() { is_alias_template(underlyingElement(this)) }
100115

101-
override string getAPrimaryQlClass() { result = "AliasTemplateTypedefType" }
116+
override string getAPrimaryQlClass() { result = "AliasTemplateType" }
102117

103118
/**
104119
* Gets a alias instantiated from this template.
@@ -114,34 +129,37 @@ class AliasTemplateTypedefType extends TypedefType {
114129
* MyAliasTemplate<long> instance2;
115130
* ```
116131
*/
117-
UsingAliasTypedefType getAnInstantiation() { result.isConstructedFrom(this) }
132+
TypeAliasType getAnInstantiation() { result.isConstructedFrom(this) }
118133
}
119134

120135
/**
121-
* A C++ alias template instantiation. For example the `my_int_type` type declared in
122-
* the following code:
136+
* A C++ alias template instantiation.
137+
*
138+
* For example the `my_int_type` type declared in the following code:
123139
* ```
124140
* template <typename T>
125141
* using my_type = T;
126142
*
127143
* using my_int_type = my_type<int>;
128144
* ```
129145
*/
130-
class AliasTemplateInstantiationTypedefType extends UsingAliasTypedefType {
131-
AliasTemplateTypedefType ta;
146+
class AliasTemplateInstantiationType extends TypeAliasType {
147+
AliasTemplateType at;
132148

133-
AliasTemplateInstantiationTypedefType() { ta.getAnInstantiation() = this }
149+
AliasTemplateInstantiationType() { at.getAnInstantiation() = this }
134150

135-
override string getAPrimaryQlClass() { result = "AliasTemplateInstantiationTypedefType" }
151+
override string getAPrimaryQlClass() { result = "AliasTemplateInstantiationType" }
136152

137153
/**
138154
* Gets the alias template from which this instantiation was instantiated.
139155
*/
140-
AliasTemplateTypedefType getTemplate() { result = ta }
156+
AliasTemplateType getTemplate() { result = at }
141157
}
142158

143159
/**
144-
* A C++ `typedef` type that is directly enclosed by a function. For example the type declared inside the function `foo` in
160+
* A C++ `typedef` type that is directly enclosed by a function.
161+
*
162+
* For example the type declared inside the function `foo` in
145163
* the following code:
146164
* ```
147165
* int foo(void) { typedef int local; }

0 commit comments

Comments
 (0)