From ea3e1b949dcbdc09518f17eee0bcf21d41d76896 Mon Sep 17 00:00:00 2001 From: Kenny Ballou Date: Mon, 19 Nov 2018 22:59:50 -0700 Subject: OJ (aka OpenJava) modernization/mirroring Signed-off-by: Kenny Ballou --- .../io/devnulllabs/openjava/ptree/Variable.java | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/main/java/io/devnulllabs/openjava/ptree/Variable.java (limited to 'src/main/java/io/devnulllabs/openjava/ptree/Variable.java') diff --git a/src/main/java/io/devnulllabs/openjava/ptree/Variable.java b/src/main/java/io/devnulllabs/openjava/ptree/Variable.java new file mode 100644 index 0000000..cca642f --- /dev/null +++ b/src/main/java/io/devnulllabs/openjava/ptree/Variable.java @@ -0,0 +1,58 @@ +/* + * Variable.java 1.0 + * + * This interface is made to type ptree-node into the type + * specifier in the body of class. + * + * Jun 20, 1997 by mich + * Sep 29, 1997 by bv + * Oct 11, 1997 by mich + * Dec 27, 1998 by mich + * + * @see io.devnulllabs.openjava.ptree.ParseTree + * @version 1.0 last updated: Oct 11, 1997 + * @author Michiaki Tatsubori + */ +package io.devnulllabs.openjava.ptree; + +import io.devnulllabs.openjava.mop.Environment; +import io.devnulllabs.openjava.mop.OJClass; +import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor; + +/** + * The Variable class represents a type specifier + * node of parse tree. + * + * @see io.devnulllabs.openjava.ptree.ParseTree + * @see io.devnulllabs.openjava.ptree.NonLeaf + */ +public class Variable extends Leaf implements Expression { + private static int variableID = 0; + + /** + * Allocates a new object. + * + * @param name name of variable + */ + public Variable(String name) { + super(name); + } + + public OJClass getType(Environment env) throws Exception { + return env.lookupBind(toString()); + } + + /** + * Generates an uniquely named variable + */ + public static Variable generateUniqueVariable() { + String name = "oj_var" + variableID; + ++variableID; + return new Variable(name); + } + + public void accept(ParseTreeVisitor v) throws ParseTreeException { + v.visit(this); + } + +} -- cgit v1.2.1