
public class Simplifier extends Object
| Modifier and Type | Method and Description |
|---|---|
static JExpression |
and(JBinaryOperation exp)
Simplify short circuit AND expressions.
|
static JExpression |
cast(JCastOperation exp)
Simplify cast operations.
|
static JExpression |
cast(JType type,
JExpression exp)
Simplify cast operations.
|
static JExpression |
conditional(JConditional exp)
Simplify conditional expressions.
|
static JStatement |
ifStatement(JIfStatement stmt,
JMethod currentMethod)
Simplifies an ifthenelse statement.
|
static boolean |
isEmpty(JStatement stmt)
TODO: if the AST were normalized, we wouldn't need this.
|
static JExpression |
not(JPrefixOperation expr)
Simplifies an negation expression.
|
static JExpression |
or(JBinaryOperation exp)
Simplify short circuit OR expressions.
|
public static boolean isEmpty(JStatement stmt)
public static JExpression cast(JType type, JExpression exp)
(int) 1 -> 1 (A) (a,b) -> (a, (A) b)
type - the Type to cast the expression exp to.exp - the current JExpression under the cast as it is being simplified.public static JExpression cast(JCastOperation exp)
(int) 1 -> 1 (A) (a,b) -> (a, (A) b)
exp - a JCastOperation to be simplified.exp otherwise.public static JExpression conditional(JConditional exp)
(a,b,c)?d:e -> a,b,(c?d:e) true ? then : else -> then false ? then : else -> else cond ? true : else) -> cond || else cond ? false : else -> !cond && else cond ? then : true -> !cond || then cond ? then : false -> cond && then !cond ? then : else -> cond ? else : then
exp - a JCondintional to be simplified.exp otherwise.public static JStatement ifStatement(JIfStatement stmt, JMethod currentMethod)
if(a,b,c) d [else e] -> {a; b; if(c) d [else e]; }
if(true) a [else b] -> a
if(false) a else b -> b
if(notImpl(c)) a else b -> if(c) b else a
if(true) ; else b -> true
if(false) a [else ;] -> false
if(c) ; [else ;] -> c
stmt - the statement to simplify.currentMethod - the method where the statement residesstmt
otherwise.public static JExpression not(JPrefixOperation expr)
expr - the expression to simplify.expr
otherwise.public static JExpression and(JBinaryOperation exp)
true && isWhatever() -> isWhatever() false && isWhatever() -> false isWhatever() && true -> isWhatever() isWhatever() && false -> false, unless side effects (a, b) && c -> (a, b && c)
exp - an AND JBinaryExpression to be simplified.exp otherwise.public static JExpression or(JBinaryOperation exp)
true || isWhatever() -> true false || isWhatever() -> isWhatever() isWhatever() || false isWhatever() isWhatever() || true -> true, unless side effects (a, b) || c -> (a, b || c)
exp - an OR JBinaryExpression to be simplified.exp otherwise.Copyright © 2018. All rights reserved.