C++: Simplify getTemplateArgument*() impl.

This commit is contained in:
Matthew Gretton-Dann
2019-11-05 11:34:37 +00:00
parent 6b4506dbea
commit afe666500f
4 changed files with 15 additions and 73 deletions

View File

@@ -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).

View File

@@ -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))
}
}
/**

View File

@@ -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

View File

@@ -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)