diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-04-10 21:39:05 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-04-10 21:39:05 -0400 |
| commit | 05c17c6e0e8e5e9015da4d1396587c4af0ea09d3 (patch) | |
| tree | 3a2685040342447c22605f4d71b50d3e0fa3d185 /dice-lang/src/main/java/bjc/dicelang/ast/DiceASTReferenceChecker.java | |
| parent | bf726639e1bc70b30dc5e5ae2cf349a5bbdfb0ae (diff) | |
Removed old code that wasn't being used
Diffstat (limited to 'dice-lang/src/main/java/bjc/dicelang/ast/DiceASTReferenceChecker.java')
| -rw-r--r-- | dice-lang/src/main/java/bjc/dicelang/ast/DiceASTReferenceChecker.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTReferenceChecker.java b/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTReferenceChecker.java new file mode 100644 index 0000000..809243a --- /dev/null +++ b/dice-lang/src/main/java/bjc/dicelang/ast/DiceASTReferenceChecker.java @@ -0,0 +1,60 @@ +package bjc.dicelang.ast; + +import java.util.function.Consumer; + +import bjc.dicelang.ast.nodes.DiceASTType; +import bjc.dicelang.ast.nodes.IDiceASTNode; +import bjc.dicelang.ast.nodes.VariableDiceNode; +import bjc.utils.data.IHolder; + +/** + * Check if the specified node references a particular variable + * + * @author ben + * + */ +public final class DiceASTReferenceChecker + implements Consumer<IDiceASTNode> { + /** + * This is true if the specified node references the set variable + */ + private IHolder<Boolean> referencesVariable; + + private String varName; + + /** + * Create a new reference checker + * + * @param referencesVar + * The holder of whether the variable is referenced or not + * @param varName + * The variable to check for references in + */ + public DiceASTReferenceChecker(IHolder<Boolean> referencesVar, + String varName) { + this.referencesVariable = referencesVar; + this.varName = varName; + } + + @Override + public void accept(IDiceASTNode astNode) { + referencesVariable.transform((bool) -> isDirectReference(astNode)); + } + + /** + * Check if a given AST node directly references the specified variable + * + * @param astNode + * The node to check + * @return Whether or not the node directly the variable + */ + private boolean isDirectReference(IDiceASTNode astNode) { + if (astNode.getType() == DiceASTType.VARIABLE) { + VariableDiceNode node = (VariableDiceNode) astNode; + + return node.getVariable().equals(varName); + } + + return false; + } +}
\ No newline at end of file |
