1616import cpp
1717import codingstandards.cpp.autosar
1818
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 )
2323
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 ) }
2630
27- TemplateFunction asTemplateFunction ( ) { this = TFunctionTemplate ( result ) }
31+ TemplateFunction asTemplateFunction ( ) { this = TTemplateFunction ( result ) }
2832
29- TemplateVariable asTemplateVariable ( ) { this = TVariableTemplate ( result ) }
33+ TemplateVariable asTemplateVariable ( ) { this = TTemplateVariable ( result ) }
3034
3135 string toString ( ) {
3236 result = this .asTemplateClass ( ) .toString ( ) or
@@ -52,6 +56,10 @@ newtype TTemplateInstantiation =
5256 TFunctionTemplateInstantiation ( FunctionTemplateInstantiation f ) or
5357 TVariableTemplateInstantiation ( VariableTemplateInstantiation v )
5458
59+ /**
60+ * An instantiation of a templated element, either a templated class, templated
61+ * function, or templated variable.
62+ */
5563class TemplateInstantiation extends TTemplateInstantiation {
5664 ClassTemplateInstantiation asClassTemplateInstantiation ( ) {
5765 this = TClassTemplateInstantiation ( result )
@@ -83,7 +91,11 @@ class TemplateInstantiation extends TTemplateInstantiation {
8391 result = this .asVariableTemplateInstantiation ( )
8492 }
8593
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 ( ) {
8799 result .asTemplateClass ( ) = this .asClassTemplateInstantiation ( ) .getTemplate ( ) or
88100 result .asTemplateFunction ( ) = this .asFunctionTemplateInstantiation ( ) .getTemplate ( ) or
89101 result .asTemplateVariable ( ) = this .asVariableTemplateInstantiation ( ) .getTemplate ( )
@@ -102,6 +114,13 @@ class TemplateInstantiation extends TTemplateInstantiation {
102114 }
103115}
104116
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+ */
105124class ImplicitConversionFromPlainCharType extends Conversion {
106125 ImplicitConversionFromPlainCharType ( ) {
107126 this .isImplicit ( ) and
@@ -126,6 +145,16 @@ newtype TImplicitConversionElement =
126145 implicitConversion .getEnclosingElement + ( ) = templateInstantiation .asElement ( )
127146 }
128147
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+ */
129158class ImplicitConversionLocation extends TImplicitConversionElement {
130159 ImplicitConversionFromPlainCharType asImplicitConversionOutsideTemplate ( ) {
131160 this = TImplicitConversionOutsideTemplate ( result )
@@ -137,10 +166,17 @@ class ImplicitConversionLocation extends TImplicitConversionElement {
137166 this = TInstantiationOfImplicitConversionTemplate ( result , implicitConversion )
138167 }
139168
169+ /**
170+ * Holds if this is a location of a conversion happening outside of a template.
171+ */
140172 predicate isImplicitConversionOutsideTemplate ( ) {
141173 exists ( this .asImplicitConversionOutsideTemplate ( ) )
142174 }
143175
176+ /**
177+ * Holds if this is a location of a conversion happening due to instantiating a
178+ * template.
179+ */
144180 predicate isInstantiationOfImplicitConversionTemplate ( ) {
145181 exists (
146182 TemplateInstantiation templateInstantiation ,
@@ -150,6 +186,13 @@ class ImplicitConversionLocation extends TImplicitConversionElement {
150186 )
151187 }
152188
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+ */
153196 ImplicitConversionFromPlainCharType getImplicitConversion ( ) {
154197 result = this .asImplicitConversionOutsideTemplate ( ) or
155198 exists ( TemplateInstantiation templateInstantiation |
0 commit comments