Merge pull request #16069 from jketema/var-templ

C++: Add `VariableTemplateInstantiation` class
This commit is contained in:
Mathias Vorreiter Pedersen 2024-03-27 11:31:35 +00:00 коммит произвёл GitHub
Родитель 6cd94cf253 050682c477
Коммит 8711232a38
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 29 добавлений и 2 удалений

Просмотреть файл

@ -590,6 +590,33 @@ class TemplateVariable extends Variable {
Variable getAnInstantiation() { result.isConstructedFrom(this) }
}
/**
* A variable that is an instantiation of a template. For example
* the instantiation `myTemplateVariable<int>` in the following code:
* ```
* template<class T>
* T myTemplateVariable;
*
* void caller(int i) {
* myTemplateVariable<int> = i;
* }
* ```
*/
class VariableTemplateInstantiation extends Variable {
TemplateVariable tv;
VariableTemplateInstantiation() { tv.getAnInstantiation() = this }
override string getAPrimaryQlClass() { result = "VariableTemplateInstantiation" }
/**
* Gets the variable template from which this instantiation was instantiated.
*
* Example: For `int x<int>`, returns `T x`.
*/
TemplateVariable getTemplate() { result = tv }
}
/**
* A non-static local variable or parameter that is not part of an
* uninstantiated template. Uninstantiated templates are purely syntax, and

Просмотреть файл

@ -15605,7 +15605,7 @@ ir.cpp:
# 1934| Type = [ClassTemplateInstantiation,Struct] Bar2<int>
# 1934| ValueCategory = lvalue
# 1935| getStmt(2): [ReturnStmt] return ...
# 1938| [GlobalVariable] char global_template<char>
# 1938| [GlobalVariable,VariableTemplateInstantiation] char global_template<char>
# 1938| getInitializer(): [Initializer] initializer for global_template
# 1938| getExpr(): [Literal] 42
# 1938| Type = [IntType] int
@ -15616,7 +15616,7 @@ ir.cpp:
# 1938| Type = [PlainCharType] char
# 1938| Value = [CStyleCast] 42
# 1938| ValueCategory = prvalue
# 1938| [GlobalVariable] int global_template<int>
# 1938| [GlobalVariable,VariableTemplateInstantiation] int global_template<int>
# 1938| getInitializer(): [Initializer] initializer for global_template
# 1938| getExpr(): [Literal] 42
# 1938| Type = [IntType] int