From afe666500f54db4dc7aa7c688bcab1c1a12b7264 Mon Sep 17 00:00:00 2001 From: Matthew Gretton-Dann Date: Tue, 5 Nov 2019 11:34:37 +0000 Subject: [PATCH] C++: Simplify getTemplateArgument*() impl. --- cpp/ql/src/semmle/code/cpp/Class.qll | 18 ------------ cpp/ql/src/semmle/code/cpp/Declaration.qll | 33 ++++++++++------------ cpp/ql/src/semmle/code/cpp/Function.qll | 19 ------------- cpp/ql/src/semmle/code/cpp/Variable.qll | 18 ------------ 4 files changed, 15 insertions(+), 73 deletions(-) diff --git a/cpp/ql/src/semmle/code/cpp/Class.qll b/cpp/ql/src/semmle/code/cpp/Class.qll index 5ccf6193c4f..297654a1afa 100644 --- a/cpp/ql/src/semmle/code/cpp/Class.qll +++ b/cpp/ql/src/semmle/code/cpp/Class.qll @@ -605,24 +605,6 @@ class Class extends UserType { class_instantiation(underlyingElement(this), unresolveElement(c)) } - /** - * Gets the `i`th template argument used to instantiate this class from a - * class template. When called on a class template, this will return the - * `i`th template parameter. - */ - override Type getTemplateArgumentType(int i) { - class_template_argument(underlyingElement(this), i, unresolveElement(result)) - } - - /** - * Gets the `i`th template argument value used to instantiate this class from a - * class template. When called on a class template, this will return the - * `i`th template parameter value. - */ - override Expr getTemplateArgumentValue(int i) { - class_template_argument_value(underlyingElement(this), i, unresolveElement(result)) - } - /** * Holds if this class/struct is polymorphic (has a virtual function, or * inherits one). diff --git a/cpp/ql/src/semmle/code/cpp/Declaration.qll b/cpp/ql/src/semmle/code/cpp/Declaration.qll index 9c8ce250d8d..89f52f174de 100644 --- a/cpp/ql/src/semmle/code/cpp/Declaration.qll +++ b/cpp/ql/src/semmle/code/cpp/Declaration.qll @@ -255,25 +255,22 @@ abstract class Declaration extends Locatable, @declaration { result = count(int i | exists(getTemplateArgument(i))) } - /** - * INTERNAL: Do not use. - * - * Gets a Type for a template argument. May be the template argument itself - * or the type of a non-type template argument. - * - * Use `getTemplateArgument` or `getTemplateKind` instead. - */ - Type getTemplateArgumentType(int index) { none() } + private Type getTemplateArgumentType(int index) { + class_template_argument(underlyingElement(this), index, unresolveElement(result)) + or + function_template_argument(underlyingElement(this), index, unresolveElement(result)) + or + variable_template_argument(underlyingElement(this), index, unresolveElement(result)) + } - /** - * INTERNAL: Do not use. - * - * Gets an Expression representing the value of a non-type template - * argument. - * - * Use `getTemplateArgument` or `getTemplateKind` instead. - */ - Expr getTemplateArgumentValue(int index) { none() } + + private Expr getTemplateArgumentValue(int index) { + class_template_argument_value(underlyingElement(this), index, unresolveElement(result)) + or + function_template_argument_value(underlyingElement(this), index, unresolveElement(result)) + or + variable_template_argument_value(underlyingElement(this), index, unresolveElement(result)) + } } /** diff --git a/cpp/ql/src/semmle/code/cpp/Function.qll b/cpp/ql/src/semmle/code/cpp/Function.qll index 5436c3ba218..14edf014b21 100644 --- a/cpp/ql/src/semmle/code/cpp/Function.qll +++ b/cpp/ql/src/semmle/code/cpp/Function.qll @@ -343,25 +343,6 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function { function_instantiation(underlyingElement(this), unresolveElement(f)) } - /** - * Gets the `i`th template argument used to instantiate this function from a - * function template. When called on a function template, this will return the - * `i`th template parameter. - */ - override Type getTemplateArgumentType(int index) { - function_template_argument(underlyingElement(this), index, unresolveElement(result)) - } - - /** - * Gets the value of the `i`th template argument used to instantiate this - * function from a function template if that argument was a 'non-type' - * argument. When called on a function template, this with return the value - * of the `i`th template parameter. - */ - override Expr getTemplateArgumentValue(int index) { - function_template_argument_value(underlyingElement(this), index, unresolveElement(result)) - } - /** * Holds if this function is defined in several files. This is illegal in * C (though possible in some C++ compilers), and likely indicates that diff --git a/cpp/ql/src/semmle/code/cpp/Variable.qll b/cpp/ql/src/semmle/code/cpp/Variable.qll index 689f1c3bfa5..194cc5333c7 100644 --- a/cpp/ql/src/semmle/code/cpp/Variable.qll +++ b/cpp/ql/src/semmle/code/cpp/Variable.qll @@ -155,24 +155,6 @@ class Variable extends Declaration, @variable { variable_instantiation(underlyingElement(this), unresolveElement(v)) } - /** - * Gets the `i`th template argument used to instantiate this variable from a - * variable template. When called on a variable template, this will return the - * `i`th template parameter. - */ - override Type getTemplateArgumentType(int index) { - variable_template_argument(underlyingElement(this), index, unresolveElement(result)) - } - - /** - * Gets the `i`th template argument value used to instantiate this variable from a - * variable template. When called on a variable template, this will return the - * `i`th template parameter value. - */ - override Expr getTemplateArgumentValue(int index) { - variable_template_argument_value(underlyingElement(this), index, unresolveElement(result)) - } - /** * Holds if this is a compiler-generated variable. For example, a * [range-based for loop](http://en.cppreference.com/w/cpp/language/range-for)