summaryrefslogtreecommitdiff
path: root/src/main/java/io/devnulllabs/openjava/ptree/ArrayAccess.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io/devnulllabs/openjava/ptree/ArrayAccess.java')
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/ArrayAccess.java87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/ArrayAccess.java b/src/main/java/io/devnulllabs/openjava/ptree/ArrayAccess.java
new file mode 100644
index 0000000..9de3779
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/ArrayAccess.java
@@ -0,0 +1,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();
+ }
+
+}