Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4ab8729

Browse files
author
Matthew Gretton-Dann
committed
C++: Further use of TemplateArgumentValue
1 parent 6334ad9 commit 4ab8729

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

cpp/ql/src/semmle/code/cpp/Declaration.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ abstract class Declaration extends Locatable, @declaration {
197197
*/
198198
final Type getATemplateArgument() { result = getTemplateArgument(_) }
199199

200+
/**
201+
* Gets a template argument used to instantiate this declaration from a template.
202+
* When called on a template, this will return a template parameter value.
203+
*/
204+
final Expr getATemplateArgumentValue() { result = getTemplateArgumentValue(_) }
205+
200206
/**
201207
* Gets the `i`th template argument used to instantiate this declaration from a
202208
* template. When called on a template, this will return the `i`th template parameter.

cpp/ql/src/semmle/code/cpp/exprs/Call.qll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,27 @@ class FunctionCall extends Call, @funbindexpr {
141141
/** Gets an explicit template argument for this call. */
142142
Type getAnExplicitTemplateArgument() { result = getExplicitTemplateArgument(_) }
143143

144+
/** Gets an explicit template argument value for this call. */
145+
Expr getAnExplicitTemplateArgumentValue() { result = getExplicitTemplateArgumentValue(_) }
146+
144147
/** Gets a template argument for this call. */
145148
Type getATemplateArgument() { result = getTarget().getATemplateArgument() }
146149

150+
/** Gets a template argument value for this call. */
151+
Expr getATemplateArgumentValue() { result = getTarget().getATemplateArgumentValue() }
152+
147153
/** Gets the nth explicit template argument for this call. */
148154
Type getExplicitTemplateArgument(int n) {
149155
n < getNumberOfExplicitTemplateArguments() and
150156
result = getTemplateArgument(n)
151157
}
152158

159+
/** Gets the nth explicit template argument value for this call. */
160+
Expr getExplicitTemplateArgumentValue(int n) {
161+
n < getNumberOfExplicitTemplateArguments() and
162+
result = getTemplateArgumentValue(n)
163+
}
164+
153165
/** Gets the number of explicit template arguments for this call. */
154166
int getNumberOfExplicitTemplateArguments() {
155167
if numtemplatearguments(underlyingElement(this), _)
@@ -160,9 +172,15 @@ class FunctionCall extends Call, @funbindexpr {
160172
/** Gets the number of template arguments for this call. */
161173
int getNumberOfTemplateArguments() { result = count(int i | exists(getTemplateArgument(i))) }
162174

175+
/** Gets the number of template argument which are values for this call. */
176+
int getNumberOfTemplateArgumentValues() { result = count(int i | exists(getTemplateArgumentValue(i))) }
177+
163178
/** Gets the nth template argument for this call (indexed from 0). */
164179
Type getTemplateArgument(int n) { result = getTarget().getTemplateArgument(n) }
165180

181+
/** Gets the nth template argument value for this call (indexed from 0). */
182+
Expr getTemplateArgumentValue(int n) { result = getTarget().getTemplateArgumentValue(n) }
183+
166184
/** Holds if any template arguments for this call are implicit / deduced. */
167185
predicate hasImplicitTemplateArguments() {
168186
exists(int i |

0 commit comments

Comments
 (0)