blob: 9de3779e66b66bde15faaf5597073614e90e9ef4 (
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
/*
* ArrayAccess.java 1.0
*
* Jun 20, 1997 by mich
* Sep 29, 1997 by bv
* Oct 10, 1997 by mich
*
* @see io.devnulllabs.openjava.ptree.ParseTree
* @version 1.0 last updated: Oct 10, 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>ArrayAccess</code> represents
* an array access.
* <p>
* An array access is like :
* <br><blockquote><pre>
* a.m[i + 1]
* </pre></blockquote><br>
* In this array access expression,
* you can get <code>a.m</code> by <code>getReferenceExpr()</code>
* and can get <code>i + 1</code> by <code>getIndexExpr()</code> .
*
* @see io.devnulllabs.openjava.ptree.Expression
*/
public class ArrayAccess extends NonLeaf implements Expression {
public ArrayAccess(Expression expr, Expression index_expr) {
super();
set(expr, index_expr);
}
ArrayAccess() {
super();
}
/**
* Gets the expression of array.
*
* @return the experssion accessed as array.
*/
public Expression getReferenceExpr() {
return (Expression) elementAt(0);
}
/**
* Sets the expression accessed as array.
*
* @param expr the experssion of array.
*/
public void setReferenceExpr(Expression expr) {
setElementAt(expr, 0);
}
/**
* Gets the dimexpr list.
*
* @return the dimexpr list.
*/
public Expression getIndexExpr() {
return (Expression) elementAt(1);
}
/**
* Sets the dimexpr list.
*
* @param dimexprs the dimexpr list.
*/
public void setIndexExpr(Expression dimexprs) {
setElementAt(dimexprs, 1);
}
public void accept(ParseTreeVisitor v) throws ParseTreeException {
v.visit(this);
}
public OJClass getType(Environment env) throws Exception {
OJClass reftype = getReferenceExpr().getType(env);
return reftype.getComponentType();
}
}
|