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.List;
022:
023: import xtc.tree.Attribute;
024:
025: /**
026: * A production override. This class represents a modification that
027: * replaces a production's alternatives. It can also specify new
028: * attributes for a production. Either the attributes or the choice
029: * may be <code>null</code>, in which case the original production's
030: * attributes or choice, respectively, remain unmodified. If the
031: * choice is not <code>null</code>, the {@link #isComplete} flag
032: * specifies whether the choice replaces the original production's
033: * choice or only specific alternatives.
034: *
035: * @author Robert Grimm
036: * @version $Revision: 1.7 $
037: */
038: public class ProductionOverride extends PartialProduction {
039:
040: /**
041: * The flag for whether the choice overrides the entire production
042: * or only specific alternatives.
043: */
044: public boolean isComplete;
045:
046: /**
047: * Create a new production override.
048: *
049: * @param attributes The attributes.
050: * @param dType The declared type.
051: * @param name The name.
052: */
053: public ProductionOverride(List<Attribute> attributes, String dType,
054: NonTerminal name) {
055: super (attributes, dType, name, null);
056: isComplete = false;
057: }
058:
059: /**
060: * Create a new production override.
061: *
062: * @param dType The declared type.
063: * @param name The name.
064: * @param choice The choice.
065: * @param isComplete The completeness flag.
066: */
067: public ProductionOverride(String dType, NonTerminal name,
068: OrderedChoice choice, boolean isComplete) {
069: super (null, dType, name, choice);
070: this .isComplete = isComplete;
071: }
072:
073: public boolean isOverride() {
074: return true;
075: }
076:
077: public boolean equals(Object o) {
078: if (this == o)
079: return true;
080: if (!(o instanceof ProductionOverride))
081: return false;
082: ProductionOverride other = (ProductionOverride) o;
083: if (isComplete != other.isComplete)
084: return false;
085: if (!name.equals(other.name))
086: return false;
087: if (null == type) {
088: if (!dType.equals(other.dType))
089: return false;
090: } else {
091: if (!type.equals(other.type))
092: return false;
093: }
094: if (null == choice) {
095: if (choice != other.choice)
096: return false;
097: } else {
098: if (!choice.equals(other.choice))
099: return false;
100: }
101: return Attribute.areEquivalent(attributes, other.attributes);
102: }
103:
104: }
|