001: /*
002: * xtc - The eXTensible Compiler
003: * Copyright (C) 2004-2007 Robert Grimm
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License
007: * version 2 as published by the Free Software Foundation.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
017: * USA.
018: */
019: package xtc.parser;
020:
021: import java.util.ArrayList;
022: import java.util.List;
023:
024: import xtc.type.Type;
025:
026: /**
027: * Element to set the semantic value to a list.
028: *
029: * @author Robert Grimm
030: * @version $Revision: 1.7 $
031: */
032: public class ProperListValue extends ListValue {
033:
034: /** The type of the proper list. */
035: public Type type;
036:
037: /** The list of bindings for the elements. */
038: public List<Binding> elements;
039:
040: /** The optional binding for the tail. */
041: public Binding tail;
042:
043: /**
044: * Create a new singleton list value.
045: *
046: * @param type The type.
047: * @param element The binding for the single element.
048: */
049: public ProperListValue(Type type, Binding element) {
050: this .type = type;
051: this .elements = new ArrayList<Binding>(1);
052: this .elements.add(element);
053: this .tail = null;
054: }
055:
056: /**
057: * Create a new list value.
058: *
059: * @param type The type.
060: * @param element The binding for the single element.
061: * @param tail The binding for the tail.
062: */
063: public ProperListValue(Type type, Binding element, Binding tail) {
064: this .type = type;
065: this .elements = new ArrayList<Binding>(1);
066: this .elements.add(element);
067: this .tail = tail;
068: }
069:
070: /**
071: * Create a new proper list value.
072: *
073: * @param type The type.
074: * @param elements The elements.
075: * @param tail The tail.
076: */
077: public ProperListValue(Type type, List<Binding> elements,
078: Binding tail) {
079: this .type = type;
080: this .elements = elements;
081: this .tail = tail;
082: }
083:
084: public Tag tag() {
085: return Tag.PROPER_LIST_VALUE;
086: }
087:
088: public int hashCode() {
089: int hash = null == tail ? 0 : tail.hashCode();
090: hash = 13 * hash + elements.hashCode();
091: hash = 13 * hash + type.hashCode();
092: return hash;
093: }
094:
095: public boolean equals(Object o) {
096: if (this == o)
097: return true;
098: if (!(o instanceof ProperListValue))
099: return false;
100: ProperListValue other = (ProperListValue) o;
101: if (!type.equals(other.type))
102: return false;
103: if (!elements.equals(other.elements))
104: return false;
105: return null == tail ? null == other.tail : tail
106: .equals(other.tail);
107: }
108:
109: }
|