Extract not-null expression

This commit is contained in:
Tamas Vajk
2021-11-23 11:47:35 +01:00
committed by Ian Lynagh
parent 6603767d94
commit 716b87d200
7 changed files with 126 additions and 45 deletions

View File

@@ -534,6 +534,9 @@
| exprs.kt:193:31:193:37 | ... + ... | exprs.kt:192:16:194:9 | <obinit> | AddExpr |
| exprs.kt:193:36:193:37 | a2 | exprs.kt:192:16:194:9 | <obinit> | VarAccess |
| exprs.kt:193:40:193:49 | toString(...) | exprs.kt:192:16:194:9 | <obinit> | MethodAccess |
| exprs.kt:199:5:199:20 | y | exprs.kt:198:1:200:1 | notNullAssertion | LocalVariableDeclExpr |
| exprs.kt:199:18:199:18 | x | exprs.kt:198:1:200:1 | notNullAssertion | VarAccess |
| exprs.kt:199:19:199:20 | ...!! | exprs.kt:198:1:200:1 | notNullAssertion | NotNullExpr |
| file://:0:0:0:0 | C | exprs.kt:146:5:146:33 | foo | TypeAccess |
| file://:0:0:0:0 | Color | exprs.kt:175:6:179:1 | Color | TypeAccess |
| file://:0:0:0:0 | Direction | exprs.kt:171:6:173:1 | Direction | TypeAccess |

View File

@@ -194,3 +194,7 @@ class Class1 {
}
}
}
fun notNullAssertion(x: Any?) {
val y: Any = x!!
}

View File

@@ -0,0 +1 @@
| exprs.kt:199:19:199:20 | ...!! | exprs.kt:199:18:199:18 | x |

View File

@@ -0,0 +1,36 @@
import java
newtype TMaybeElement =
TElement(Element e) or
TNoElement()
class MaybeElement extends TMaybeElement {
abstract string toString();
abstract Location getLocation();
}
class YesMaybeElement extends MaybeElement {
Element e;
YesMaybeElement() { this = TElement(e) }
override string toString() { result = e.toString() }
override Location getLocation() { result = e.getLocation() }
}
class NoMaybeElement extends MaybeElement {
NoMaybeElement() { this = TNoElement() }
override string toString() { result = "<none>" }
override Location getLocation() { none() }
}
MaybeElement op(UnaryExpr e) {
if exists(e.getExpr()) then result = TElement(e.getExpr()) else result = TNoElement()
}
from Expr e
select e, op(e)