Merge pull request #689 from hvitved/csharp/remove-get-url

C#: Remove `getUrl()` predicates
This commit is contained in:
calumgrant 2018-12-20 18:49:15 +00:00 коммит произвёл GitHub
Родитель 1710f8db7c c66f67dfac
Коммит 7dd263b413
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
25 изменённых файлов: 148 добавлений и 133 удалений

Просмотреть файл

@ -58,7 +58,34 @@ predicate alwaysDefaultToString(ValueOrRefType t) {
)
}
from Expr e, ValueOrRefType t
where invokesToString(e, t)
and alwaysDefaultToString(t)
select e, "Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing.", t, t.getName()
newtype TDefaultToStringType =
TDefaultToStringType0(ValueOrRefType t) { alwaysDefaultToString(t) }
class DefaultToStringType extends TDefaultToStringType {
ValueOrRefType t;
DefaultToStringType() { this = TDefaultToStringType0(t) }
ValueOrRefType getType() { result = t }
string toString() { result = t.toString() }
// A workaround for generating empty URLs for non-source locations, because qltest
// does not support non-source locations
string getURL() {
exists(Location l |
l = t.getLocation() |
if l instanceof SourceLocation then
exists(string path, int a, int b, int c, int d |
l.hasLocationInfo(path, a, b, c, d) |
toUrl(path, a, b, c, d, result)
)
else
result = ""
)
}
}
from Expr e, DefaultToStringType t
where invokesToString(e, t.getType())
select e, "Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing.", t, t.getType().getName()

Просмотреть файл

@ -23,7 +23,6 @@ class Namespace extends DotNet::Namespace, TypeContainer, @namespace {
override Namespace getParent() { result = this.getParentNamespace() }
override Namespace getParentNamespace() { parent_namespace(this, result) }
override string getName() { namespaces(this,result) }
string getUrl() { result="" }
override Location getLocation() { none() }
}

Просмотреть файл

@ -22,7 +22,10 @@ class Element extends DotNet::Element, @element {
* Where an element has multiple locations (for example a source file and an assembly),
* gets only the source location.
*/
override Location getLocation() { result = bestLocation(this) }
override Location getLocation() { result = ExprOrStmtParentCached::bestLocation(this) }
/** Gets the URL of this element. */
string getURL() { result = ExprOrStmtParentCached::getURL(this) }
/** Gets a location of this element, including sources and assemblies. */
override Location getALocation() { none() }

Просмотреть файл

@ -346,7 +346,7 @@ private int getImplementationSize(ValueOrRefType t, File f) {
result = getImplementationSize1(t, f)
}
private cached module Cached {
cached module ExprOrStmtParentCached {
cached
ControlFlowElement getTopLevelChild(ExprOrStmtParent p, int i) {
result = p.(MultiImplementationsParent).getBestChild(i)
@ -363,7 +363,7 @@ private cached module Cached {
* in `f`.
*/
cached
predicate mustHaveLocationInFileCached(Declaration d, File f) {
predicate mustHaveLocationInFile(Declaration d, File f) {
exists(MultiImplementationsParent p, ValueOrRefType t |
t = getTopLevelDeclaringType(p) and
f = p.getBestFile() |
@ -381,7 +381,7 @@ private cached module Cached {
* locations, choose only one.
*/
cached
Location bestLocationCached(Element e) {
Location bestLocation(Element e) {
result = e.getALocation().(SourceLocation) and
(mustHaveLocationInFile(e, _) implies mustHaveLocationInFile(e, result.getFile()))
or
@ -391,8 +391,17 @@ private cached module Cached {
result = min(Location l | l = e.getALocation() | l order by l.getFile().toString())
)
}
}
private import Cached
predicate mustHaveLocationInFile = mustHaveLocationInFileCached/2;
predicate bestLocation = bestLocationCached/1;
cached
string getURL(Element e) {
exists(Location l, string path, int a, int b, int c, int d |
l = bestLocation(e) |
l.hasLocationInfo(path, a, b, c, d) and
toUrl(path, a, b, c, d, result)
)
or
not exists(bestLocation(e)) and
result = ""
}
}
private import ExprOrStmtParentCached

Просмотреть файл

@ -37,24 +37,16 @@ class Location extends @location
string toString() { none() }
/** Gets the start line of this location. */
int getStartLine() {
locations_default(this,_,result,_,_,_)
}
final int getStartLine() { this.hasLocationInfo(_, result, _, _, _) }
/** Gets the end line of this location. */
int getEndLine() {
locations_default(this,_,_,_,result,_)
}
final int getEndLine() { this.hasLocationInfo(_, _, _, result, _) }
/** Gets the start column of this location. */
int getStartColumn() {
locations_default(this,_,_,result,_,_)
}
final int getStartColumn() { this.hasLocationInfo(_, _, result, _, _) }
/** Gets the end column of this location. */
int getEndColumn() {
locations_default(this,_,_,_,_,result)
}
final int getEndColumn() { this.hasLocationInfo(_, _, _, _, result) }
}
/**

Просмотреть файл

@ -36,17 +36,6 @@ class Declaration extends DotNet::Declaration, Element, @declaration {
result = this.getDeclaringType().getQualifiedName() + "." + this.toStringWithTypes()
}
/** Define URL for declarations with no location. */
string getURL() {
if exists(this.getLocation()) then
exists(string path, int a, int b, int c, int d |
this.getLocation().hasLocationInfo(path, a, b, c, d) |
toUrl(path, a, b, c, d, result)
)
else
result = ""
}
/**
* Holds if this declaration has been generated by the compiler, for example
* implicit constructors or accessors.

Просмотреть файл

@ -112,8 +112,12 @@ class Namespace extends DotNet::Namespace, TypeContainer, @namespace {
override predicate fromLibrary() { not this.fromSource() }
/** Gets the URL of this namespace (which is empty in this case). */
string getURL() { result = "" }
/** Gets a declaration of this namespace, if any. */
NamespaceDeclaration getADeclaration() { result.getNamespace() = this }
override Location getALocation() {
result = this.getADeclaration().getALocation()
}
}
/**
@ -193,7 +197,7 @@ class NamespaceDeclaration extends Element, @namespace_declaration {
*/
ValueOrRefType getATypeDeclaration() { parent_namespace_declaration(result, this) }
override Location getALocation() { none() }
override Location getALocation() { namespace_declaration_location(this, result) }
override string toString() { result = "namespace ... { ... }" }
}

Просмотреть файл

@ -729,7 +729,6 @@ class Class extends RefType, @class_type {
* ```
*/
class AnonymousClass extends Class {
AnonymousClass() { this.getName().matches("<%") }
}
@ -787,8 +786,7 @@ class DelegateType extends RefType, Parameterizable, @delegate_type {
/**
* The `null` type. The type of the `null` literal.
*/
class NullType extends RefType, @null_type {
}
class NullType extends RefType, @null_type { }
/**
* A nullable type, for example `int?`.
@ -869,6 +867,13 @@ class ArrayType extends DotNet::ArrayType, RefType, @array_type {
}
override Type getChild(int n) { result = getElementType() and n = 0 }
override Location getALocation() {
type_location(this, result)
or
not type_location(this, _) and
result = this.getElementType().getALocation()
}
}
/**

Просмотреть файл

@ -159,17 +159,11 @@ class InvalidFormatString extends StringLiteral {
result = this.getValue().regexpFind(getValidFormatRegex(),0,0).length()
}
/**
* Holds if this element is at the specified location.
* The location spans column `startcolumn` of line `startline` to
* column `endcolumn` of line `endline` in file `filepath`.
* For more information, see
* [LGTM locations](https://lgtm.com/help/ql/locations).
*/
predicate hasLocationInfo(string filepath, int startline, int startcolumn, int endline, int endcolumn) {
exists(int oldstartcolumn, int padding |
override string getURL() {
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn, int oldstartcolumn, int padding |
this.getLocation().hasLocationInfo(filepath, startline, oldstartcolumn, endline, endcolumn) and
startcolumn = padding + oldstartcolumn + getInvalidOffset() |
startcolumn = padding + oldstartcolumn + getInvalidOffset() and
toUrl(filepath, startline, startcolumn, endline, endcolumn, result) |
// Single-line string literal beginning " or @"
// Figure out the correct indent.
startline = endline and

Просмотреть файл

@ -1,14 +1,14 @@
| async.cs:11:29:11:32 | Main | file://:0:0:0:0 | private |
| async.cs:11:29:11:32 | Main | file://:0:0:0:0 | static |
| async.cs:22:35:22:57 | PrintContentLengthAsync | file://:0:0:0:0 | async |
| async.cs:22:35:22:57 | PrintContentLengthAsync | file://:0:0:0:0 | private |
| async.cs:22:35:22:57 | PrintContentLengthAsync | file://:0:0:0:0 | static |
| async.cs:28:40:28:57 | ContentLengthAsync | file://:0:0:0:0 | async |
| async.cs:28:40:28:57 | ContentLengthAsync | file://:0:0:0:0 | private |
| async.cs:28:40:28:57 | ContentLengthAsync | file://:0:0:0:0 | static |
| async.cs:38:35:38:47 | AsyncIterator | file://:0:0:0:0 | async |
| async.cs:38:35:38:47 | AsyncIterator | file://:0:0:0:0 | private |
| async.cs:38:35:38:47 | AsyncIterator | file://:0:0:0:0 | static |
| async.cs:50:49:50:57 | OpenAsync | file://:0:0:0:0 | async |
| async.cs:50:49:50:57 | OpenAsync | file://:0:0:0:0 | private |
| async.cs:50:49:50:57 | OpenAsync | file://:0:0:0:0 | static |
| async.cs:11:29:11:32 | Main | | private |
| async.cs:11:29:11:32 | Main | | static |
| async.cs:22:35:22:57 | PrintContentLengthAsync | | async |
| async.cs:22:35:22:57 | PrintContentLengthAsync | | private |
| async.cs:22:35:22:57 | PrintContentLengthAsync | | static |
| async.cs:28:40:28:57 | ContentLengthAsync | | async |
| async.cs:28:40:28:57 | ContentLengthAsync | | private |
| async.cs:28:40:28:57 | ContentLengthAsync | | static |
| async.cs:38:35:38:47 | AsyncIterator | | async |
| async.cs:38:35:38:47 | AsyncIterator | | private |
| async.cs:38:35:38:47 | AsyncIterator | | static |
| async.cs:50:49:50:57 | OpenAsync | | async |
| async.cs:50:49:50:57 | OpenAsync | | private |
| async.cs:50:49:50:57 | OpenAsync | | static |

Просмотреть файл

@ -1,2 +1,2 @@
| expressions.cs:417:9:420:9 | object creation of type <>__AnonType0<String,String[]> | | String[] |
| expressions.cs:421:9:424:9 | object creation of type <>__AnonType0<String,String[]> | | String[] |
| expressions.cs:417:9:420:9 | object creation of type <>__AnonType0<String,String[]> | String[] |
| expressions.cs:421:9:424:9 | object creation of type <>__AnonType0<String,String[]> | String[] |

Просмотреть файл

@ -11,4 +11,4 @@ where assign.getLValue().(VariableAccess).getTarget().hasName("contacts2")
and p = a.getLValue().(PropertyAccess).getTarget()
and p.hasName("PhoneNumbers")
and p.getDeclaringType() = o.getObjectType()
select o, p.getType()
select o, p.getType().getName()

Просмотреть файл

@ -1,46 +1,46 @@
| Modifiers.cs:4:18:4:18 | C | file://:0:0:0:0 | internal |
| Modifiers.cs:4:18:4:18 | C | file://:0:0:0:0 | unsafe |
| Modifiers.cs:7:9:7:9 | C | file://:0:0:0:0 | private |
| Modifiers.cs:9:16:9:16 | C | file://:0:0:0:0 | public |
| Modifiers.cs:12:14:12:15 | M1 | file://:0:0:0:0 | private |
| Modifiers.cs:14:22:14:23 | M2 | file://:0:0:0:0 | private |
| Modifiers.cs:16:24:16:25 | M3 | file://:0:0:0:0 | protected |
| Modifiers.cs:18:35:18:36 | M4 | file://:0:0:0:0 | extern |
| Modifiers.cs:18:35:18:36 | M4 | file://:0:0:0:0 | public |
| Modifiers.cs:18:35:18:36 | M4 | file://:0:0:0:0 | static |
| Modifiers.cs:21:20:21:21 | M5 | file://:0:0:0:0 | async |
| Modifiers.cs:21:20:21:21 | M5 | file://:0:0:0:0 | private |
| Modifiers.cs:24:22:24:23 | C1 | file://:0:0:0:0 | private |
| Modifiers.cs:24:22:24:23 | C1 | file://:0:0:0:0 | sealed |
| Modifiers.cs:26:20:26:21 | C1 | file://:0:0:0:0 | public |
| Modifiers.cs:29:34:29:35 | C2 | file://:0:0:0:0 | abstract |
| Modifiers.cs:29:34:29:35 | C2 | file://:0:0:0:0 | protected |
| Modifiers.cs:31:23:31:24 | C2 | file://:0:0:0:0 | protected |
| Modifiers.cs:33:22:33:23 | M2 | file://:0:0:0:0 | new |
| Modifiers.cs:33:22:33:23 | M2 | file://:0:0:0:0 | private |
| Modifiers.cs:35:34:35:35 | M6 | file://:0:0:0:0 | abstract |
| Modifiers.cs:35:34:35:35 | M6 | file://:0:0:0:0 | public |
| Modifiers.cs:38:32:38:33 | C3 | file://:0:0:0:0 | internal |
| Modifiers.cs:38:32:38:33 | C3 | file://:0:0:0:0 | partial |
| Modifiers.cs:41:20:41:21 | F1 | file://:0:0:0:0 | private |
| Modifiers.cs:41:20:41:21 | F1 | file://:0:0:0:0 | static |
| Modifiers.cs:43:26:43:27 | F2 | file://:0:0:0:0 | const |
| Modifiers.cs:43:26:43:27 | F2 | file://:0:0:0:0 | public |
| Modifiers.cs:43:26:43:27 | F2 | file://:0:0:0:0 | static |
| Modifiers.cs:45:41:45:42 | F3 | file://:0:0:0:0 | internal |
| Modifiers.cs:45:41:45:42 | F3 | file://:0:0:0:0 | protected |
| Modifiers.cs:45:41:45:42 | F3 | file://:0:0:0:0 | readonly |
| Modifiers.cs:47:30:47:31 | F4 | file://:0:0:0:0 | private |
| Modifiers.cs:47:30:47:31 | F4 | file://:0:0:0:0 | volatile |
| Modifiers.cs:50:24:50:24 | I | file://:0:0:0:0 | internal |
| Modifiers.cs:52:19:52:19 | S | file://:0:0:0:0 | public |
| Modifiers.cs:52:19:52:19 | S | file://:0:0:0:0 | sealed |
| Modifiers.cs:54:20:54:21 | P1 | file://:0:0:0:0 | public |
| Modifiers.cs:54:36:54:38 | get_P1 | file://:0:0:0:0 | public |
| Modifiers.cs:54:52:54:54 | set_P1 | file://:0:0:0:0 | public |
| Modifiers.cs:55:20:55:21 | P2 | file://:0:0:0:0 | public |
| Modifiers.cs:55:36:55:38 | get_P2 | file://:0:0:0:0 | public |
| Modifiers.cs:55:49:55:51 | set_P2 | file://:0:0:0:0 | private |
| Modifiers.cs:57:13:57:14 | P3 | file://:0:0:0:0 | private |
| Modifiers.cs:57:30:57:32 | get_P3 | file://:0:0:0:0 | private |
| Modifiers.cs:57:47:57:49 | set_P3 | file://:0:0:0:0 | private |
| Modifiers.cs:4:18:4:18 | C | | internal |
| Modifiers.cs:4:18:4:18 | C | | unsafe |
| Modifiers.cs:7:9:7:9 | C | | private |
| Modifiers.cs:9:16:9:16 | C | | public |
| Modifiers.cs:12:14:12:15 | M1 | | private |
| Modifiers.cs:14:22:14:23 | M2 | | private |
| Modifiers.cs:16:24:16:25 | M3 | | protected |
| Modifiers.cs:18:35:18:36 | M4 | | extern |
| Modifiers.cs:18:35:18:36 | M4 | | public |
| Modifiers.cs:18:35:18:36 | M4 | | static |
| Modifiers.cs:21:20:21:21 | M5 | | async |
| Modifiers.cs:21:20:21:21 | M5 | | private |
| Modifiers.cs:24:22:24:23 | C1 | | private |
| Modifiers.cs:24:22:24:23 | C1 | | sealed |
| Modifiers.cs:26:20:26:21 | C1 | | public |
| Modifiers.cs:29:34:29:35 | C2 | | abstract |
| Modifiers.cs:29:34:29:35 | C2 | | protected |
| Modifiers.cs:31:23:31:24 | C2 | | protected |
| Modifiers.cs:33:22:33:23 | M2 | | new |
| Modifiers.cs:33:22:33:23 | M2 | | private |
| Modifiers.cs:35:34:35:35 | M6 | | abstract |
| Modifiers.cs:35:34:35:35 | M6 | | public |
| Modifiers.cs:38:32:38:33 | C3 | | internal |
| Modifiers.cs:38:32:38:33 | C3 | | partial |
| Modifiers.cs:41:20:41:21 | F1 | | private |
| Modifiers.cs:41:20:41:21 | F1 | | static |
| Modifiers.cs:43:26:43:27 | F2 | | const |
| Modifiers.cs:43:26:43:27 | F2 | | public |
| Modifiers.cs:43:26:43:27 | F2 | | static |
| Modifiers.cs:45:41:45:42 | F3 | | internal |
| Modifiers.cs:45:41:45:42 | F3 | | protected |
| Modifiers.cs:45:41:45:42 | F3 | | readonly |
| Modifiers.cs:47:30:47:31 | F4 | | private |
| Modifiers.cs:47:30:47:31 | F4 | | volatile |
| Modifiers.cs:50:24:50:24 | I | | internal |
| Modifiers.cs:52:19:52:19 | S | | public |
| Modifiers.cs:52:19:52:19 | S | | sealed |
| Modifiers.cs:54:20:54:21 | P1 | | public |
| Modifiers.cs:54:36:54:38 | get_P1 | | public |
| Modifiers.cs:54:52:54:54 | set_P1 | | public |
| Modifiers.cs:55:20:55:21 | P2 | | public |
| Modifiers.cs:55:36:55:38 | get_P2 | | public |
| Modifiers.cs:55:49:55:51 | set_P2 | | private |
| Modifiers.cs:57:13:57:14 | P3 | | private |
| Modifiers.cs:57:30:57:32 | get_P3 | | private |
| Modifiers.cs:57:47:57:49 | set_P3 | | private |

Просмотреть файл

@ -1 +1 @@
| | N1.N2 |
| namespaces.cs:5:11:5:15 | N1.N2 |

Просмотреть файл

@ -1 +1 @@
| | R1 | namespaces.cs:73:11:73:14 | A<> | namespaces.cs:80:11:80:11 | A |
| namespaces.cs:70:11:70:12 | R1 | namespaces.cs:73:11:73:14 | A<> | namespaces.cs:80:11:80:11 | A |

Просмотреть файл

@ -1 +1 @@
| | M1.M2 |
| namespaces.cs:16:15:16:16 | M1.M2 |

Просмотреть файл

@ -1 +1,2 @@
| | P1.P2 |
| namespaces.cs:26:11:26:15 | P1.P2 |
| namespaces.cs:33:11:33:15 | P1.P2 |

Просмотреть файл

@ -1 +1 @@
| | M1.M2 |
| namespaces.cs:16:15:16:16 | M1.M2 |

Просмотреть файл

@ -1 +1 @@
| | Empty |
| namespaces.cs:44:11:44:15 | Empty |

Просмотреть файл

@ -1 +1 @@
| | Q1 | | Q1.Q2 |
| | Q1 | namespaces.cs:50:11:50:15 | Q1.Q2 |

Просмотреть файл

@ -1 +1 @@
| | Q3 | namespaces.cs:64:11:64:11 | B | namespaces.cs:53:11:53:11 | A |
| namespaces.cs:57:11:57:12 | Q3 | namespaces.cs:64:11:64:11 | B | namespaces.cs:53:11:53:11 | A |

Просмотреть файл

@ -1 +1 @@
| | Q3 | namespaces.cs:66:11:66:11 | C | namespaces.cs:53:11:53:11 | A |
| namespaces.cs:57:11:57:12 | Q3 | namespaces.cs:66:11:66:11 | C | namespaces.cs:53:11:53:11 | A |

Просмотреть файл

@ -1,7 +1,3 @@
/**
* @name Test for null type
* @kind table
*/
import csharp
from NullLiteral l

Просмотреть файл

@ -1 +1 @@
| | Class[][] | | Class[] |
| types.cs:3:20:3:24 | Class[][] | types.cs:3:20:3:24 | Class[] |

Просмотреть файл

@ -1,7 +1,3 @@
/**
* @name Test for binding array types
* @kind table
*/
import csharp
from Method m, ArrayType t1, ArrayType t2