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

Skip to content

Commit eb70166

Browse files
C++: Fix PR feedback
1 parent 7b54db8 commit eb70166

13 files changed

Lines changed: 484 additions & 394 deletions

File tree

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,19 @@ class TemplateClass extends Class {
886886
* A class that is an instantiation of a template.
887887
*/
888888
class ClassTemplateInstantiation extends Class {
889+
TemplateClass tc;
890+
889891
ClassTemplateInstantiation() {
890-
exists(TemplateClass tc | tc.getAnInstantiation() = this)
892+
tc.getAnInstantiation() = this
893+
}
894+
895+
/**
896+
* Gets the class template from which this instantiation was instantiated.
897+
*
898+
* Example: For `std::vector<float>()`, returns `std::vector<T>`.
899+
*/
900+
TemplateClass getTemplate() {
901+
result = tc
891902
}
892903
}
893904

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import semmle.code.cpp.Element
22
import semmle.code.cpp.Specifier
33
import semmle.code.cpp.Namespace
4-
private import semmle.code.cpp.internal.IdentityString
54

65
/**
76
* A C/C++ declaration: for example, a variable declaration, a type
@@ -89,17 +88,6 @@ abstract class Declaration extends Locatable, @declaration {
8988

9089
override string toString() { result = this.getName() }
9190

92-
/**
93-
* Gets a string that uniquely identifies this declaration, suitable for use when debugging queries. Only holds for
94-
* functions, user-defined types, global and namespace-scope variables, and member variables.
95-
*
96-
* This operation is very expensive, and should not be used in production queries. Consider using `hasName()` or
97-
* `hasQualifiedName()` for identifying known declarations in production queries.
98-
*/
99-
string getIdentityString() {
100-
none()
101-
}
102-
10391
/**
10492
* Gets the name of this declaration.
10593
*

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

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import semmle.code.cpp.Parameter
55
import semmle.code.cpp.exprs.Call
66
import semmle.code.cpp.metrics.MetricFunction
77
import semmle.code.cpp.Linkage
8-
private import semmle.code.cpp.internal.IdentityString
98
private import semmle.code.cpp.internal.ResolveClass
109

1110
/**
@@ -21,6 +20,7 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
2120
override string getName() { functions(underlyingElement(this),result,_) }
2221

2322
/**
23+
* DEPRECATED: Use `getIdentityString(Declaration)` from `semmle.code.cpp.Print` instead.
2424
* Gets the full signature of this function, including return type, parameter
2525
* types, and template arguments.
2626
*
@@ -33,7 +33,7 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
3333
* "min<int>(int, int) -> int", and the full signature of the uninstantiated
3434
* template on the first line would be "min<T>(T, T) -> T".
3535
*/
36-
string getFullSignature() {
36+
deprecated string getFullSignature() {
3737
exists(string name, string templateArgs, string args |
3838
result = name + templateArgs + args + " -> " + getType().toString() and
3939
name = getQualifiedName() and
@@ -56,48 +56,6 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
5656
)
5757
}
5858

59-
override string getIdentityString() {
60-
result = getType().getTypeSpecifier() + getType().getDeclaratorPrefix() + " " + getScopePrefix(this) + getName() + getTemplateArgumentsString() + getDeclaratorSuffixBeforeQualifiers() + getDeclaratorSuffix()
61-
}
62-
63-
language[monotonicAggregates]
64-
private string getTemplateArgumentsString() {
65-
if exists(getATemplateArgument()) then (
66-
result = "<" +
67-
concat(int i |
68-
exists(getTemplateArgument(i)) |
69-
getTemplateArgument(i).getTypeIdentityString(), ", " order by i
70-
) + ">"
71-
)
72-
else
73-
result = ""
74-
}
75-
76-
language[monotonicAggregates]
77-
private string getDeclaratorSuffixBeforeQualifiers() {
78-
result = "(" +
79-
concat(int i |
80-
exists(getParameter(i).getType()) |
81-
getParameterTypeString(getParameter(i).getType()), ", " order by i
82-
) + ")" + getQualifierString()
83-
}
84-
85-
private string getQualifierString() {
86-
if exists(getACVQualifier()) then
87-
result = " " + concat(string qualifier | qualifier = getACVQualifier() | qualifier, " ")
88-
else
89-
result = ""
90-
}
91-
92-
private string getACVQualifier() {
93-
result = getASpecifier().getName() and
94-
(result = "const" or result = "volatile")
95-
}
96-
97-
private string getDeclaratorSuffix() {
98-
result = getType().getDeclaratorSuffixBeforeQualifiers() + getType().getDeclaratorSuffix()
99-
}
100-
10159
/** Gets a specifier of this function. */
10260
override Specifier getASpecifier() {
10361
funspecifiers(underlyingElement(this),unresolveElement(result))
@@ -1137,6 +1095,11 @@ class FunctionTemplateInstantiation extends Function {
11371095
tf.getAnInstantiation() = this
11381096
}
11391097

1098+
/**
1099+
* Gets the function template from which this instantiation was instantiated.
1100+
*
1101+
* Example: For `min<int>()`, returns `min<T>`.
1102+
*/
11401103
TemplateFunction getTemplate() {
11411104
result = tf
11421105
}

0 commit comments

Comments
 (0)