Skip to content

Commit 628edc9

Browse files
committed
definitions.qll: Tidy up handling of type mentions
1 parent 3bc0662 commit 628edc9

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

cpp/ql/src/definitions.qll

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,16 @@ private predicate constructorCallStartLoc(ConstructorCall cc, File f, int line,
102102

103103
/**
104104
* Holds if `f`, `line`, `column` indicate the start character
105-
* of `tm`.
105+
* of `tm`, which mentions `t`.
106106
*/
107-
private predicate typeMentionStartLoc(TypeMention tm, File f, int line, int column) {
107+
private predicate typeMentionStartLoc(TypeMention tm, Type t, File f, int line, int column) {
108108
exists(Location l |
109109
l = tm.getLocation() and
110110
l.getFile() = f and
111111
l.getStartLine() = line and
112112
l.getStartColumn() = column
113-
)
113+
) and
114+
t = tm.getMentionedType()
114115
}
115116

116117
/**
@@ -119,7 +120,7 @@ private predicate typeMentionStartLoc(TypeMention tm, File f, int line, int colu
119120
private cached predicate constructorCallTypeMention(ConstructorCall cc, TypeMention tm) {
120121
exists(File f, int line, int column |
121122
constructorCallStartLoc(cc, f, line, column) and
122-
typeMentionStartLoc(tm, f, line, column)
123+
typeMentionStartLoc(tm, _, f, line, column)
123124
)
124125
}
125126

@@ -155,15 +156,16 @@ Top definitionOf(Top e, string kind) {
155156
kind = "T" and
156157
e.(TypeMention).getMentionedType() = result and
157158
not constructorCallTypeMention(_, e) and // handled elsewhere
158-
159-
// multiple mentions can be generated when a typedef is used. Exclude
160-
// all but the originating typedef.
161-
not exists(TypeMention tm, File f, int startline, int startcol |
162-
typeMentionStartLoc(e, f, startline, startcol) and
163-
typeMentionStartLoc(tm, f, startline, startcol) and
164-
(
165-
e.(TypeMention).getMentionedType() = tm.getMentionedType().(TypedefType).getBaseType() or
166-
e.(TypeMention).getMentionedType() = tm.getMentionedType().(TypedefType).getBaseType().(SpecifiedType).getBaseType()
159+
// Multiple type mentions can be generated when a typedef is used, and
160+
// in such cases we want to exclude all but the originating typedef.
161+
not exists(Type secondary |
162+
exists(TypeMention tm, File f, int startline, int startcol |
163+
typeMentionStartLoc(e, result, f, startline, startcol) and
164+
typeMentionStartLoc(tm, secondary, f, startline, startcol) and
165+
(
166+
result = secondary.(TypedefType).getBaseType() or
167+
result = secondary.(TypedefType).getBaseType().(SpecifiedType).getBaseType()
168+
)
167169
)
168170
)
169171
) or (

0 commit comments

Comments
 (0)