|
| 1 | +/* |
| 2 | + * A library customize models that model the flow of exceptions through the program. |
| 3 | + */ |
| 4 | + |
1 | 5 | import cpp
|
2 | 6 | private import codingstandards.cpp.exceptions.ExceptionFlow
|
3 | 7 |
|
4 | 8 | /** A `ThrowingExpr` which is the origin of a exceptions in the program. */
|
5 | 9 | abstract class OriginThrowingExpr extends ThrowingExpr { }
|
6 | 10 |
|
| 11 | +/** |
| 12 | + * A `FunctionCall` to an external function without an exception specification that * |
| 13 | + * may throw an exception. |
| 14 | + */ |
| 15 | +abstract class ExternalUnderspecifiedFunctionCallThrowingExpr extends FunctionCall, ThrowingExpr { } |
| 16 | + |
| 17 | +/** |
| 18 | + * An extensible predicate that describes functions that when called may throw an exception. |
| 19 | + */ |
| 20 | +extensible predicate throwingFunctionModel( |
| 21 | + string functionNamespaceQualifier, string functionTypeQualifier, string functionName, |
| 22 | + string exceptionNamespaceQualifier, string exceptionType |
| 23 | +); |
| 24 | + |
| 25 | +/** |
| 26 | + * A `FunctionCall` that may throw an exception of type `ExceptionType` as provded by |
| 27 | + * the extensible predicate `throwingFunctionModel`. |
| 28 | + */ |
| 29 | +private class ExternalFunctionCallThrowingExpr extends FunctionCall, ThrowingExpr { |
| 30 | + ExceptionType exceptionType; |
| 31 | + |
| 32 | + ExternalFunctionCallThrowingExpr() { |
| 33 | + exists( |
| 34 | + string functionNamespaceQualifier, string functionTypeQualifier, string functionName, |
| 35 | + string exceptionNamespaceQualifier, string exceptionTypeSpec |
| 36 | + | |
| 37 | + throwingFunctionModel(functionNamespaceQualifier, functionTypeQualifier, functionName, |
| 38 | + exceptionNamespaceQualifier, exceptionTypeSpec) and |
| 39 | + this.getTarget() |
| 40 | + .hasQualifiedName(functionNamespaceQualifier, functionTypeQualifier, functionName) and |
| 41 | + exceptionType.(Class).hasQualifiedName(exceptionNamespaceQualifier, exceptionTypeSpec) |
| 42 | + ) |
| 43 | + } |
| 44 | + |
| 45 | + override ExceptionType getAnExceptionType() { result = exceptionType } |
| 46 | +} |
| 47 | + |
7 | 48 | /** An expression which directly throws. */
|
8 | 49 | class DirectThrowExprThrowingExpr extends DirectThrowExpr, OriginThrowingExpr {
|
9 | 50 | override ExceptionType getAnExceptionType() { result = getExceptionType() }
|
@@ -46,6 +87,10 @@ class FunctionCallThrowingExpr extends FunctionCall, ThrowingExpr {
|
46 | 87 | isNoExceptTrue(target)
|
47 | 88 | )
|
48 | 89 | )
|
| 90 | + or |
| 91 | + result = this.(ExternalUnderspecifiedFunctionCallThrowingExpr).getAnExceptionType() |
| 92 | + or |
| 93 | + result = this.(ExternalFunctionCallThrowingExpr).getAnExceptionType() |
49 | 94 | }
|
50 | 95 | }
|
51 | 96 |
|
|
0 commit comments