definitions.qll: Tidy up handling of type mentions

This commit is contained in:
Pavel Avgustinov
2018-08-10 16:54:14 +01:00
parent 3bc06627e1
commit 628edc9577

View File

@@ -102,15 +102,16 @@ private predicate constructorCallStartLoc(ConstructorCall cc, File f, int line,
/** /**
* Holds if `f`, `line`, `column` indicate the start character * Holds if `f`, `line`, `column` indicate the start character
* of `tm`. * of `tm`, which mentions `t`.
*/ */
private predicate typeMentionStartLoc(TypeMention tm, File f, int line, int column) { private predicate typeMentionStartLoc(TypeMention tm, Type t, File f, int line, int column) {
exists(Location l | exists(Location l |
l = tm.getLocation() and l = tm.getLocation() and
l.getFile() = f and l.getFile() = f and
l.getStartLine() = line and l.getStartLine() = line and
l.getStartColumn() = column l.getStartColumn() = column
) ) and
t = tm.getMentionedType()
} }
/** /**
@@ -119,7 +120,7 @@ private predicate typeMentionStartLoc(TypeMention tm, File f, int line, int colu
private cached predicate constructorCallTypeMention(ConstructorCall cc, TypeMention tm) { private cached predicate constructorCallTypeMention(ConstructorCall cc, TypeMention tm) {
exists(File f, int line, int column | exists(File f, int line, int column |
constructorCallStartLoc(cc, f, line, column) and constructorCallStartLoc(cc, f, line, column) and
typeMentionStartLoc(tm, f, line, column) typeMentionStartLoc(tm, _, f, line, column)
) )
} }
@@ -155,15 +156,16 @@ Top definitionOf(Top e, string kind) {
kind = "T" and kind = "T" and
e.(TypeMention).getMentionedType() = result and e.(TypeMention).getMentionedType() = result and
not constructorCallTypeMention(_, e) and // handled elsewhere not constructorCallTypeMention(_, e) and // handled elsewhere
// Multiple type mentions can be generated when a typedef is used, and
// multiple mentions can be generated when a typedef is used. Exclude // in such cases we want to exclude all but the originating typedef.
// all but the originating typedef. not exists(Type secondary |
not exists(TypeMention tm, File f, int startline, int startcol | exists(TypeMention tm, File f, int startline, int startcol |
typeMentionStartLoc(e, f, startline, startcol) and typeMentionStartLoc(e, result, f, startline, startcol) and
typeMentionStartLoc(tm, f, startline, startcol) and typeMentionStartLoc(tm, secondary, f, startline, startcol) and
( (
e.(TypeMention).getMentionedType() = tm.getMentionedType().(TypedefType).getBaseType() or result = secondary.(TypedefType).getBaseType() or
e.(TypeMention).getMentionedType() = tm.getMentionedType().(TypedefType).getBaseType().(SpecifiedType).getBaseType() result = secondary.(TypedefType).getBaseType().(SpecifiedType).getBaseType()
)
) )
) )
) or ( ) or (