16
16
import cpp
17
17
import codingstandards.cpp.autosar
18
18
19
- newtype TTemplatedElement =
20
- TClassTemplate ( TemplateClass c ) or
21
- TFunctionTemplate ( TemplateFunction f ) or
22
- TVariableTemplate ( TemplateVariable v )
19
+ newtype TTemplateElement =
20
+ TTemplateClass ( TemplateClass c ) or
21
+ TTemplateFunction ( TemplateFunction f ) or
22
+ TTemplateVariable ( TemplateVariable v )
23
23
24
- class TemplatedElement extends TTemplatedElement {
25
- TemplateClass asTemplateClass ( ) { this = TClassTemplate ( result ) }
24
+ /**
25
+ * A templated element. These are either templated classes, templated functions,
26
+ * or templated variables.
27
+ */
28
+ class TemplateElement extends TTemplateElement {
29
+ TemplateClass asTemplateClass ( ) { this = TTemplateClass ( result ) }
26
30
27
- TemplateFunction asTemplateFunction ( ) { this = TFunctionTemplate ( result ) }
31
+ TemplateFunction asTemplateFunction ( ) { this = TTemplateFunction ( result ) }
28
32
29
- TemplateVariable asTemplateVariable ( ) { this = TVariableTemplate ( result ) }
33
+ TemplateVariable asTemplateVariable ( ) { this = TTemplateVariable ( result ) }
30
34
31
35
string toString ( ) {
32
36
result = this .asTemplateClass ( ) .toString ( ) or
@@ -52,6 +56,10 @@ newtype TTemplateInstantiation =
52
56
TFunctionTemplateInstantiation ( FunctionTemplateInstantiation f ) or
53
57
TVariableTemplateInstantiation ( VariableTemplateInstantiation v )
54
58
59
+ /**
60
+ * An instantiation of a templated element, either a templated class, templated
61
+ * function, or templated variable.
62
+ */
55
63
class TemplateInstantiation extends TTemplateInstantiation {
56
64
ClassTemplateInstantiation asClassTemplateInstantiation ( ) {
57
65
this = TClassTemplateInstantiation ( result )
@@ -83,7 +91,11 @@ class TemplateInstantiation extends TTemplateInstantiation {
83
91
result = this .asVariableTemplateInstantiation ( )
84
92
}
85
93
86
- TemplatedElement getTemplate ( ) {
94
+ /**
95
+ * Gets the template this instantiation is from, depending on the kind of the element
96
+ * this instantiation is for.
97
+ */
98
+ TemplateElement getTemplate ( ) {
87
99
result .asTemplateClass ( ) = this .asClassTemplateInstantiation ( ) .getTemplate ( ) or
88
100
result .asTemplateFunction ( ) = this .asFunctionTemplateInstantiation ( ) .getTemplate ( ) or
89
101
result .asTemplateVariable ( ) = this .asVariableTemplateInstantiation ( ) .getTemplate ( )
@@ -102,6 +114,13 @@ class TemplateInstantiation extends TTemplateInstantiation {
102
114
}
103
115
}
104
116
117
+ /**
118
+ * An implicit conversion from a plain char type to an explicitly signed or unsigned char
119
+ * type. `std::uint8_t` and `std::int8_t` are also considered as these char types.
120
+ *
121
+ * Note that this class only includes implicit conversions and does not include explicit
122
+ * type conversions, i.e. casts.
123
+ */
105
124
class ImplicitConversionFromPlainCharType extends Conversion {
106
125
ImplicitConversionFromPlainCharType ( ) {
107
126
this .isImplicit ( ) and
@@ -126,6 +145,16 @@ newtype TImplicitConversionElement =
126
145
implicitConversion .getEnclosingElement + ( ) = templateInstantiation .asElement ( )
127
146
}
128
147
148
+ /**
149
+ * The locations where the implicit conversion from a plain char to an explicitly signed / unsigned
150
+ * char is taking place on a high level. It splits case on whether the conversion is caused by
151
+ * instantiating a template:
152
+ *
153
+ * - For conversions not due to template usage (i.e. outside a templated element), this refers to
154
+ * the same element as the one associated with the conversion.
155
+ * - For conversions due to template usage, this refers to the element that uses the instantiation
156
+ * of a template where an implicit char conversion happens.
157
+ */
129
158
class ImplicitConversionLocation extends TImplicitConversionElement {
130
159
ImplicitConversionFromPlainCharType asImplicitConversionOutsideTemplate ( ) {
131
160
this = TImplicitConversionOutsideTemplate ( result )
@@ -137,10 +166,17 @@ class ImplicitConversionLocation extends TImplicitConversionElement {
137
166
this = TInstantiationOfImplicitConversionTemplate ( result , implicitConversion )
138
167
}
139
168
169
+ /**
170
+ * Holds if this is a location of a conversion happening outside of a template.
171
+ */
140
172
predicate isImplicitConversionOutsideTemplate ( ) {
141
173
exists ( this .asImplicitConversionOutsideTemplate ( ) )
142
174
}
143
175
176
+ /**
177
+ * Holds if this is a location of a conversion happening due to instantiating a
178
+ * template.
179
+ */
144
180
predicate isInstantiationOfImplicitConversionTemplate ( ) {
145
181
exists (
146
182
TemplateInstantiation templateInstantiation ,
@@ -150,6 +186,13 @@ class ImplicitConversionLocation extends TImplicitConversionElement {
150
186
)
151
187
}
152
188
189
+ /**
190
+ * Gets the implicit conversion that this location is associated with.
191
+ * - In cases of conversions not involving a template, this is the same as the
192
+ * location associated with the conversion.
193
+ * - In cases of conversions due to using a template, this is the conversion that
194
+ * happens in the instantiated template.
195
+ */
153
196
ImplicitConversionFromPlainCharType getImplicitConversion ( ) {
154
197
result = this .asImplicitConversionOutsideTemplate ( ) or
155
198
exists ( TemplateInstantiation templateInstantiation |
0 commit comments