blob: cca642fee938c19752239093c6f18d9cd5a0908a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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 <code>Variable</code> 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);
}
}
|