mirror of
https://github.com/github/codeql.git
synced 2026-04-27 09:45:15 +02:00
C++: Hoist getTemplateArgument() and friends into Declaration
This commit is contained in:
@@ -583,26 +583,12 @@ class Class extends UserType {
|
||||
class_instantiation(underlyingElement(this), unresolveElement(c))
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a template argument used to instantiate this class from a class
|
||||
* template. When called on a class template, this will return a template
|
||||
* parameter.
|
||||
*/
|
||||
Type getATemplateArgument() {
|
||||
exists(int i | this.getTemplateArgument(i) = result )
|
||||
}
|
||||
|
||||
/** Gets the number of template arguments for this class. */
|
||||
int getNumberOfTemplateArguments() {
|
||||
result = count(int i | exists(getTemplateArgument(i)))
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
Type getTemplateArgument(int i) {
|
||||
override Type getTemplateArgument(int i) {
|
||||
class_template_argument(underlyingElement(this),i,unresolveElement(result))
|
||||
}
|
||||
|
||||
@@ -895,7 +881,7 @@ class ClassTemplateInstantiation extends Class {
|
||||
/**
|
||||
* Gets the class template from which this instantiation was instantiated.
|
||||
*
|
||||
* Example: For `std::vector<float>()`, returns `std::vector<T>`.
|
||||
* Example: For `std::vector<float>`, returns `std::vector<T>`.
|
||||
*/
|
||||
TemplateClass getTemplate() {
|
||||
result = tc
|
||||
|
||||
@@ -187,6 +187,27 @@ abstract class Declaration extends Locatable, @declaration {
|
||||
Class getDeclaringType() {
|
||||
this = result.getAMember()
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a template argument used to instantiate this declaration from a template.
|
||||
* When called on a template, this will return a template parameter.
|
||||
*/
|
||||
final Type getATemplateArgument() {
|
||||
result = getTemplateArgument(_)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the `i`th template argument used to instantiate this declaration from a
|
||||
* template. When called on a template, this will return the `i`th template parameter.
|
||||
*/
|
||||
Type getTemplateArgument(int index) {
|
||||
none()
|
||||
}
|
||||
|
||||
/** Gets the number of template arguments for this declaration. */
|
||||
final int getNumberOfTemplateArguments() {
|
||||
result = count(int i | exists(getTemplateArgument(i)))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -333,18 +333,11 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an argument used to instantiate this class from a template
|
||||
* class.
|
||||
* 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.
|
||||
*/
|
||||
Type getATemplateArgument() {
|
||||
exists(int i | this.getTemplateArgument(i) = result )
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a particular argument used to instantiate this class from a
|
||||
* template class.
|
||||
*/
|
||||
Type getTemplateArgument(int index) {
|
||||
override Type getTemplateArgument(int index) {
|
||||
function_template_argument(underlyingElement(this),index,unresolveElement(result))
|
||||
}
|
||||
|
||||
@@ -1098,7 +1091,7 @@ class FunctionTemplateInstantiation extends Function {
|
||||
/**
|
||||
* Gets the function template from which this instantiation was instantiated.
|
||||
*
|
||||
* Example: For `min<int>()`, returns `min<T>`.
|
||||
* Example: For `int const& std::min<int>(int const&, int const&)`, returns `T const& min<T>(T const&, T const&)`.
|
||||
*/
|
||||
TemplateFunction getTemplate() {
|
||||
result = tf
|
||||
|
||||
@@ -46,6 +46,19 @@ private abstract class DumpDeclaration extends Declaration {
|
||||
string getIdentityString() {
|
||||
none()
|
||||
}
|
||||
|
||||
language[monotonicAggregates]
|
||||
final string getTemplateArgumentsString() {
|
||||
if exists(this.getATemplateArgument()) then (
|
||||
result = "<" +
|
||||
strictconcat(int i |
|
||||
exists(this.getTemplateArgument(i)) |
|
||||
this.getTemplateArgument(i).(DumpType).getTypeIdentityString(), ", " order by i
|
||||
) + ">"
|
||||
)
|
||||
else
|
||||
result = ""
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -342,19 +355,6 @@ private class UserDumpType extends DumpType, DumpDeclaration, UserType {
|
||||
)
|
||||
}
|
||||
|
||||
language[monotonicAggregates]
|
||||
private string getTemplateArgumentsString() {
|
||||
if exists(this.(Class).getATemplateArgument()) then (
|
||||
result = "<" +
|
||||
strictconcat(int i |
|
||||
exists(this.(Class).getTemplateArgument(i)) |
|
||||
this.(Class).getTemplateArgument(i).(DumpType).getTypeIdentityString(), ", " order by i
|
||||
) + ">"
|
||||
)
|
||||
else
|
||||
result = ""
|
||||
}
|
||||
|
||||
override string getTypeSpecifier() {
|
||||
result = getIdentityString()
|
||||
}
|
||||
@@ -368,19 +368,6 @@ private class DumpVariable extends DumpDeclaration, Variable {
|
||||
result = type.getTypeSpecifier() + type.getDeclaratorPrefix() + " " + getScopePrefix(this) + this.getName() + this.getTemplateArgumentsString() + type.getDeclaratorSuffixBeforeQualifiers() + type.getDeclaratorSuffix()
|
||||
)
|
||||
}
|
||||
|
||||
language[monotonicAggregates]
|
||||
private string getTemplateArgumentsString() {
|
||||
if exists(getATemplateArgument()) then (
|
||||
result = "<" +
|
||||
strictconcat(int i |
|
||||
exists(getTemplateArgument(i)) |
|
||||
getTemplateArgument(i).(DumpType).getTypeIdentityString(), ", " order by i
|
||||
) + ">"
|
||||
)
|
||||
else
|
||||
result = ""
|
||||
}
|
||||
}
|
||||
|
||||
private class DumpFunction extends DumpDeclaration, Function {
|
||||
@@ -388,19 +375,6 @@ private class DumpFunction extends DumpDeclaration, Function {
|
||||
result = getType().(DumpType).getTypeSpecifier() + getType().(DumpType).getDeclaratorPrefix() + " " + getScopePrefix(this) + getName() + getTemplateArgumentsString() + getDeclaratorSuffixBeforeQualifiers() + getDeclaratorSuffix()
|
||||
}
|
||||
|
||||
language[monotonicAggregates]
|
||||
private string getTemplateArgumentsString() {
|
||||
if exists(getATemplateArgument()) then (
|
||||
result = "<" +
|
||||
strictconcat(int i |
|
||||
exists(getTemplateArgument(i)) |
|
||||
getTemplateArgument(i).(DumpType).getTypeIdentityString(), ", " order by i
|
||||
) + ">"
|
||||
)
|
||||
else
|
||||
result = ""
|
||||
}
|
||||
|
||||
language[monotonicAggregates]
|
||||
private string getDeclaratorSuffixBeforeQualifiers() {
|
||||
result = "(" +
|
||||
|
||||
@@ -131,18 +131,11 @@ class Variable extends Declaration, @variable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an argument used to instantiate this variable from a template
|
||||
* variable.
|
||||
* 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.
|
||||
*/
|
||||
Type getATemplateArgument() {
|
||||
exists(int i | this.getTemplateArgument(i) = result)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a particular argument used to instantiate this variable from a
|
||||
* template variable.
|
||||
*/
|
||||
Type getTemplateArgument(int index) {
|
||||
override Type getTemplateArgument(int index) {
|
||||
variable_template_argument(underlyingElement(this), index, unresolveElement(result))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user