C++: Basic lib support for template param values

This commit is contained in:
Matthew Gretton-Dann
2019-10-18 11:20:48 +01:00
parent 48c7d1d7c1
commit df7d21220b
4 changed files with 35 additions and 0 deletions

View File

@@ -614,6 +614,15 @@ class Class extends UserType {
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

@@ -203,6 +203,13 @@ abstract class Declaration extends Locatable, @declaration {
*/
Type getTemplateArgument(int index) { none() }
/**
* Gets the `i`th template argument value used to instantiate this declaration
* from a template. When called on a template, this will return the `i`th template
* parameter value if it exists.
*/
Expr getTemplateArgumentValue(int index) { none() }
/** Gets the number of template arguments for this declaration. */
final int getNumberOfTemplateArguments() {
result = count(int i | exists(getTemplateArgument(i)))

View File

@@ -352,6 +352,16 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
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

@@ -164,6 +164,15 @@ class Variable extends Declaration, @variable {
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)