Skip to content

Commit afe6665

Browse files
author
Matthew Gretton-Dann
committed
C++: Simplify getTemplateArgument*() impl.
1 parent 6b4506d commit afe6665

File tree

4 files changed

+15
-73
lines changed

4 files changed

+15
-73
lines changed

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -605,24 +605,6 @@ class Class extends UserType {
605605
class_instantiation(underlyingElement(this), unresolveElement(c))
606606
}
607607

608-
/**
609-
* Gets the `i`th template argument used to instantiate this class from a
610-
* class template. When called on a class template, this will return the
611-
* `i`th template parameter.
612-
*/
613-
override Type getTemplateArgumentType(int i) {
614-
class_template_argument(underlyingElement(this), i, unresolveElement(result))
615-
}
616-
617-
/**
618-
* Gets the `i`th template argument value used to instantiate this class from a
619-
* class template. When called on a class template, this will return the
620-
* `i`th template parameter value.
621-
*/
622-
override Expr getTemplateArgumentValue(int i) {
623-
class_template_argument_value(underlyingElement(this), i, unresolveElement(result))
624-
}
625-
626608
/**
627609
* Holds if this class/struct is polymorphic (has a virtual function, or
628610
* inherits one).

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

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -255,25 +255,22 @@ abstract class Declaration extends Locatable, @declaration {
255255
result = count(int i | exists(getTemplateArgument(i)))
256256
}
257257

258-
/**
259-
* INTERNAL: Do not use.
260-
*
261-
* Gets a Type for a template argument. May be the template argument itself
262-
* or the type of a non-type template argument.
263-
*
264-
* Use `getTemplateArgument` or `getTemplateKind` instead.
265-
*/
266-
Type getTemplateArgumentType(int index) { none() }
258+
private Type getTemplateArgumentType(int index) {
259+
class_template_argument(underlyingElement(this), index, unresolveElement(result))
260+
or
261+
function_template_argument(underlyingElement(this), index, unresolveElement(result))
262+
or
263+
variable_template_argument(underlyingElement(this), index, unresolveElement(result))
264+
}
267265

268-
/**
269-
* INTERNAL: Do not use.
270-
*
271-
* Gets an Expression representing the value of a non-type template
272-
* argument.
273-
*
274-
* Use `getTemplateArgument` or `getTemplateKind` instead.
275-
*/
276-
Expr getTemplateArgumentValue(int index) { none() }
266+
267+
private Expr getTemplateArgumentValue(int index) {
268+
class_template_argument_value(underlyingElement(this), index, unresolveElement(result))
269+
or
270+
function_template_argument_value(underlyingElement(this), index, unresolveElement(result))
271+
or
272+
variable_template_argument_value(underlyingElement(this), index, unresolveElement(result))
273+
}
277274
}
278275

279276
/**

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -343,25 +343,6 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
343343
function_instantiation(underlyingElement(this), unresolveElement(f))
344344
}
345345

346-
/**
347-
* Gets the `i`th template argument used to instantiate this function from a
348-
* function template. When called on a function template, this will return the
349-
* `i`th template parameter.
350-
*/
351-
override Type getTemplateArgumentType(int index) {
352-
function_template_argument(underlyingElement(this), index, unresolveElement(result))
353-
}
354-
355-
/**
356-
* Gets the value of the `i`th template argument used to instantiate this
357-
* function from a function template if that argument was a 'non-type'
358-
* argument. When called on a function template, this with return the value
359-
* of the `i`th template parameter.
360-
*/
361-
override Expr getTemplateArgumentValue(int index) {
362-
function_template_argument_value(underlyingElement(this), index, unresolveElement(result))
363-
}
364-
365346
/**
366347
* Holds if this function is defined in several files. This is illegal in
367348
* C (though possible in some C++ compilers), and likely indicates that

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -155,24 +155,6 @@ class Variable extends Declaration, @variable {
155155
variable_instantiation(underlyingElement(this), unresolveElement(v))
156156
}
157157

158-
/**
159-
* Gets the `i`th template argument used to instantiate this variable from a
160-
* variable template. When called on a variable template, this will return the
161-
* `i`th template parameter.
162-
*/
163-
override Type getTemplateArgumentType(int index) {
164-
variable_template_argument(underlyingElement(this), index, unresolveElement(result))
165-
}
166-
167-
/**
168-
* Gets the `i`th template argument value used to instantiate this variable from a
169-
* variable template. When called on a variable template, this will return the
170-
* `i`th template parameter value.
171-
*/
172-
override Expr getTemplateArgumentValue(int index) {
173-
variable_template_argument_value(underlyingElement(this), index, unresolveElement(result))
174-
}
175-
176158
/**
177159
* Holds if this is a compiler-generated variable. For example, a
178160
* [range-based for loop](http://en.cppreference.com/w/cpp/language/range-for)

0 commit comments

Comments
 (0)