Source code: com/voytechs/jnetstream/npl/ArrayReferenceNode.java
1 /*
2 * File: ArrayReferenceNode.java
3 * Auth: Mark Bednarczyk
4 * Date: DATE
5 * Id: $Id: ArrayReferenceNode.java,v 1.1.1.1 2003/09/22 16:32:20 voytechs Exp $
6 ********************************************
7 Copyright (C) 2003 Mark Bednarczyk
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 ********************************************
23 * $Log: ArrayReferenceNode.java,v $
24 * Revision 1.1.1.1 2003/09/22 16:32:20 voytechs
25 * Initial import.
26 *
27 */
28 package com.voytechs.jnetstream.npl;
29
30 import com.voytechs.jnetstream.primitive.*;
31
32 import java.lang.*;
33 import java.util.*;
34
35 /**
36 *
37 */
38 public abstract class ArrayReferenceNode
39 extends Node
40 implements Visitable {
41
42 /* Internal attributes */
43 private static final boolean debug = false;
44
45 protected ArrayDimensionNode dimensions = new ArrayDimensionNode();
46
47 protected String name;
48
49 /**
50 *
51 * @param
52 * @exception
53 */
54 public ArrayReferenceNode(String name, ArrayDimensionNode dimensions) {
55 this.name = name;
56 this.dimensions = dimensions;
57 }
58
59
60 protected abstract Context getContext();
61
62 public Primitive getPrimitive(ArrayDimensionNode dim)
63 throws NodeException {
64
65 if(getContext() == null)
66 return(null);
67
68
69 if(dimensions.checkBoundary(dim) == false)
70 throw new NodeException("Array index out of bounds", this);
71
72 Primitive[] primitives = getContext().getPrimitiveArray(name);
73
74 return(primitives[dimensions.toScalar(dim)]);
75 }
76
77 /**
78 * Get the name of the variable.
79 */
80 public String getName() {
81 return(name);
82 }
83
84 public Node optimize() {
85 return(dimensions.optimize());
86 }
87
88 public boolean canOptimize() {
89 return(dimensions.canOptimize());
90 }
91
92 public String toString() {
93 // return(name + "(" + getPrimitive() + ")" );
94 return("toString() for primitive arrays not implemented yet");
95 }
96
97 /**
98 * Test function for ArrayReferenceNode
99 * @param args command line arguments
100 */
101 public static void main(String [] args) {
102 }
103
104 } /* END OF: ArrayReferenceNode */