Skip to content

Commit 088a1a9

Browse files
committed
C#: Simplify TriedControlFlowElement::getAThrownException()
1 parent 3162e12 commit 088a1a9

File tree

1 file changed

+1
-48
lines changed

1 file changed

+1
-48
lines changed

csharp/ql/src/semmle/code/csharp/controlflow/internal/Completion.qll

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -293,18 +293,6 @@ private class Overflowable extends UnaryOperation {
293293
}
294294
}
295295

296-
private class CoreLib extends Assembly {
297-
CoreLib() { this = any(SystemExceptionClass c).getALocation() }
298-
}
299-
300-
/**
301-
* Holds if assembly `a` was definitely compiled with core library `core`.
302-
*/
303-
pragma[noinline]
304-
private predicate assemblyCompiledWithCoreLib(Assembly a, CoreLib core) {
305-
a.getAnAttribute().getType().getBaseClass*().(SystemAttributeClass).getALocation() = core
306-
}
307-
308296
/** A control flow element that is inside a `try` block. */
309297
private class TriedControlFlowElement extends ControlFlowElement {
310298
TryStmt try;
@@ -317,7 +305,7 @@ private class TriedControlFlowElement extends ControlFlowElement {
317305
/**
318306
* Gets an exception class that is potentially thrown by this element, if any.
319307
*/
320-
private Class getAThrownException0() {
308+
Class getAThrownException() {
321309
this instanceof Overflowable and
322310
result instanceof SystemOverflowExceptionClass
323311
or
@@ -376,41 +364,6 @@ private class TriedControlFlowElement extends ControlFlowElement {
376364
this instanceof DynamicExpr and
377365
result instanceof SystemExceptionClass
378366
}
379-
380-
private CoreLib getCoreLibFromACatchClause() {
381-
exists(SpecificCatchClause scc | scc = try.getACatchClause() |
382-
result = scc.getCaughtExceptionType().getBaseClass*().(SystemExceptionClass).getALocation()
383-
)
384-
}
385-
386-
private CoreLib getCoreLib() {
387-
result = this.getCoreLibFromACatchClause()
388-
or
389-
not exists(this.getCoreLibFromACatchClause()) and
390-
assemblyCompiledWithCoreLib(this.getAssembly(), result)
391-
}
392-
393-
pragma[noinline]
394-
private Class getAThrownExceptionFromPlausibleCoreLib(string name) {
395-
result = this.getAThrownException0() and
396-
name = result.getQualifiedName() and
397-
(
398-
not exists(this.getCoreLib())
399-
or
400-
this.getCoreLib() = result.getALocation()
401-
)
402-
}
403-
404-
Class getAThrownException() {
405-
exists(string name | result = this.getAThrownExceptionFromPlausibleCoreLib(name) |
406-
result =
407-
min(Class c |
408-
c = this.getAThrownExceptionFromPlausibleCoreLib(name)
409-
|
410-
c order by c.getLocation().(Assembly).getFullName()
411-
)
412-
)
413-
}
414367
}
415368

416369
pragma[nomagic]

0 commit comments

Comments
 (0)