Skip to content

Commit a72fff7

Browse files
author
Robert Marsh
committed
C++: add getUnspecifiedType() for exprs and decls
1 parent 8256f2e commit a72fff7

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,16 @@ abstract class DeclarationEntry extends Locatable {
270270
*/
271271
abstract Type getType();
272272

273+
/**
274+
* Gets the type associated with this declaration entrry after specifiers
275+
* have been deeply stripped and typedefs have been resolved.
276+
*
277+
* For variable declarations, get the type of the variable.
278+
* For function declarations, get the return type of the function.
279+
* For type declarations, get the type being declared.
280+
*/
281+
Type getUnspecifiedType() { result = this.getType().getUnspecifiedType() }
282+
273283
/**
274284
* Holds if this declaration entry has a specifier with the given name.
275285
*/

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
133133
/** Gets the return type of this function. */
134134
Type getType() { function_return_type(underlyingElement(this),unresolveElement(result)) }
135135

136+
/**
137+
* Gets the return type of this function after specifiers have been deeply
138+
* stripped and typedefs have been resolved.
139+
*/
140+
Type getUnspecifiedType() { result = getType().getUnspecifiedType() }
141+
136142
/** Gets the nth parameter of this function. */
137143
Parameter getParameter(int n) { params(unresolveElement(result),underlyingElement(this),n,_) }
138144

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ class Variable extends Declaration, @variable {
4747
/** Gets the type of this variable, after typedefs have been resolved. */
4848
Type getUnderlyingType() { result = this.getType().getUnderlyingType() }
4949

50+
/**
51+
* Gets the type of this variable, after specifiers have been deeply
52+
* stripped and typedefs have been resolved.
53+
*/
54+
Type getUnspecifiedType() { result = this.getType().getUnspecifiedType() }
55+
5056
/**
5157
* Gets the type of this variable prior to deduction caused by the C++11
5258
* `auto` keyword.

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ class Expr extends StmtParent, @expr {
6868
*/
6969
Type getUnderlyingType() { result = this.getType().getUnderlyingType() }
7070

71+
/**
72+
* Gets the type of this expression after specifiers have been deeply
73+
* stripped and typedefs have been resolved.
74+
*
75+
* In most cases, this predicate will be the same as getType(). It will
76+
* only differ when the result of getType() is a TypedefType, in which
77+
* case this predicate will (possibly recursively) resolve the typedef.
78+
*/
79+
Type getUnspecifiedType() { result = this.getType().getUnspecifiedType() }
80+
7181
/**
7282
* Gets an integer indicating the type of expression that this represents.
7383
*

0 commit comments

Comments
 (0)