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.tree;
020:
021: /**
022: * A line marker (as used by GCC).
023: *
024: * @author Robert Grimm
025: * @version $Revision: 1.9 $
026: */
027: public class LineMarker extends Annotation {
028:
029: /** The start file flag. */
030: public static final int FLAG_START_FILE = 0x01;
031:
032: /** The return to file flag. */
033: public static final int FLAG_RETURN_TO_FILE = 0x02;
034:
035: /** The system header flag. */
036: public static final int FLAG_SYSTEM_HEADER = 0x04;
037:
038: /** The extern C flag. */
039: public static final int FLAG_EXTERN_C = 0x08;
040:
041: /** The line number. */
042: public int line;
043:
044: /** The file name. */
045: public String file;
046:
047: /** The flags. */
048: public int flags;
049:
050: /**
051: * Create a new line marker.
052: *
053: * @param line The line number.
054: * @param file The file name.
055: * @param flags The flags.
056: * @param node The marked node.
057: */
058: public LineMarker(int line, String file, int flags, Node node) {
059: super (node);
060: this .line = line;
061: this .file = file;
062: this .flags = flags;
063: }
064:
065: public boolean hasTraversal() {
066: return true;
067: }
068:
069: public int size() {
070: return 4;
071: }
072:
073: public Object get(int index) {
074: switch (index) {
075: case 0:
076: return line;
077: case 1:
078: return file;
079: case 2:
080: return flags;
081: case 3:
082: return node;
083: default:
084: throw new IndexOutOfBoundsException("Index: " + index
085: + ", Size: 4");
086: }
087: }
088:
089: public Object set(int index, Object value) {
090: Object old;
091:
092: switch (index) {
093: case 0:
094: old = line;
095: line = ((Number) value).intValue();
096: return old;
097: case 1:
098: old = file;
099: file = (String) value;
100: return old;
101: case 2:
102: old = flags;
103: flags = ((Number) value).intValue();
104: return old;
105: case 3:
106: old = node;
107: node = (Node) value;
108: return old;
109: default:
110: throw new IndexOutOfBoundsException("Index: " + index
111: + ", Size: 4");
112: }
113: }
114:
115: public int hashCode() {
116: return line;
117: }
118:
119: public boolean equals(Object o) {
120: if (this == o)
121: return true;
122: if (!(o instanceof LineMarker))
123: return false;
124: LineMarker other = (LineMarker) o;
125: if (line != other.line)
126: return false;
127: if (flags != other.flags)
128: return false;
129: if (null == file)
130: return (null == other.file);
131: if (!file.equals(other.file))
132: return false;
133: if (null == node)
134: return (null == other.node);
135: return node.equals(other.node);
136: }
137:
138: }
|