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

C#: Remove `getUrl()` predicate
This commit is contained in:
Calum Grant
2019-02-07 10:47:56 +00:00
committed by GitHub
10 changed files with 86 additions and 104 deletions

View File

@@ -58,33 +58,22 @@ predicate alwaysDefaultToString(ValueOrRefType t) {
((t.isAbstract() or t instanceof Interface) implies not t.isEffectivelyPublic())
}
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() }
class DefaultToStringType extends ValueOrRefType {
DefaultToStringType() { alwaysDefaultToString(this) }
// 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 = ""
)
override Location getLocation() {
result = super.getLocation() and
result instanceof SourceLocation
or
not super.getLocation() instanceof SourceLocation and
result instanceof EmptyLocation
}
}
from Expr e, DefaultToStringType t
where invokesToString(e, t.getType())
where invokesToString(e, t)
select e,
"Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing.",
t, t.getType().getName()
t, t.getName()