summaryrefslogtreecommitdiff
path: root/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTUtils.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2016-07-27 17:42:35 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2016-07-27 17:42:35 -0400
commit67fee39e6dd22fce8dfaa800f0a5ddbe0ede0be3 (patch)
tree76db8ccbfb360ce1e4abe8b293fd86a5a95ce923 /dice-lang/src/main/java/bjc/dicelang/ast/DiceASTUtils.java
parentbfa7c67f491d8f693308e6299266f527b49be600 (diff)
General cleanup
Diffstat (limited to 'dice-lang/src/main/java/bjc/dicelang/ast/DiceASTUtils.java')
-rw-r--r--dice-lang/src/main/java/bjc/dicelang/ast/DiceASTUtils.java28
1 files changed, 15 insertions, 13 deletions
diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTUtils.java b/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTUtils.java
index 8d70af8..d98c8fe 100644
--- a/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTUtils.java
+++ b/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTUtils.java
@@ -21,13 +21,14 @@ public class DiceASTUtils {
* Check if a dice AST contains a simple variable reference
*
* @param nameTree
+ * The tree to check for a reference in
* @return Whether or not a dice AST contains a simple variable
* reference
*/
public static boolean containsSimpleVariable(
ITree<IDiceASTNode> nameTree) {
- return nameTree.transformHead((nameNod) -> {
- if (nameNod.getType() != DiceASTType.VARIABLE) {
+ return nameTree.transformHead((nameNode) -> {
+ if (nameNode.getType() != DiceASTType.VARIABLE) {
return false;
}
@@ -36,10 +37,10 @@ public class DiceASTUtils {
}
/**
- * Convert an AST tree to a dice expression, if possible.
+ * Convert an literal AST node to a dice expression, if possible.
*
* @param tree
- * The tree to convert
+ * The node to convert in tree form
* @return The tree as a dice expression
*
* @throws ClassCastException
@@ -48,15 +49,16 @@ public class DiceASTUtils {
* @throws UnsupportedOperationException
* if the head of the tree is not optimizable
*/
- public static IDiceExpression toExpression(ITree<IDiceASTNode> tree) {
- ILiteralDiceNode litNode = (ILiteralDiceNode) tree.getHead();
+ public static IDiceExpression literalToExpression(
+ ITree<IDiceASTNode> tree) {
+ ILiteralDiceNode literalNode = (ILiteralDiceNode) tree.getHead();
- switch (litNode.getLiteralType()) {
+ switch (literalNode.getLiteralType()) {
case DICE:
- return ((DiceLiteralNode) litNode).getValue();
+ return ((DiceLiteralNode) literalNode).getValue();
case INTEGER:
return new ScalarDie(
- ((IntegerLiteralNode) litNode).getValue());
+ ((IntegerLiteralNode) literalNode).getValue());
default:
throw new UnsupportedOperationException(
"This type of literal isn't convertable to an expression");
@@ -64,11 +66,11 @@ public class DiceASTUtils {
}
/**
- * Convert an AST tree to an integer, if possible.
+ * Convert an literal AST node to an integer, if possible.
*
* @param tree
- * The tree to convert
- * @return The tree as an integer
+ * The literal node to convert, as a tree
+ * @return The node as an integer
*
* @throws ClassCastException
* if the head of the tree is not a literal (implements
@@ -76,7 +78,7 @@ public class DiceASTUtils {
* @throws UnsupportedOperationException
* if the head of the tree is not optimizable
*/
- public static int toInt(ITree<IDiceASTNode> tree) {
+ public static int literalToInteger(ITree<IDiceASTNode> tree) {
return tree.transformHead((node) -> {
return ((ILiteralDiceNode) node).optimize();
});