001: /*
002: * xtc - The eXTensible Compiler
003: * Copyright (C) 2007 New York University
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public License
007: * version 2.1 as published by the Free Software Foundation.
008: *
009: * This library 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 GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
017: * USA.
018: */
019: package xtc.typical;
020:
021: /**
022: * The base class of all scope kinds.
023: *
024: * @author Anh Le
025: * @version $Revision: 1.5 $
026: */
027: public abstract class ScopeKind<T extends Tuple> extends Variant<T> {
028:
029: /** The tags for subclasses. */
030: public static enum Tag {
031: NamedT, AnonymousT, TemporaryT
032: }
033:
034: /** Create a new scope_kind. */
035: protected ScopeKind() {
036: //empty
037: }
038:
039: /**
040: * Get the tag of this class
041: *
042: * @return The tag
043: */
044: public abstract Tag tag();
045:
046: /**
047: * Test if this scope is named.
048: *
049: * @return <code>true</code> if named, false otherwise.
050: */
051: public boolean isNamed() {
052: return false;
053: }
054:
055: /**
056: * Test if this scope is anonymous.
057: *
058: * @return <code>true</code> if anonymous, false otherwise.
059: */
060: public boolean isAnonymous() {
061: return false;
062: }
063:
064: /**
065: * Test if this scope is temporary.
066: *
067: * @return <code>true</code> if temporary, false otherwise.
068: */
069: public boolean isTemporary() {
070: return false;
071: }
072:
073: /** The named scope. */
074: public static class Named extends ScopeKind<Tuple.T1<Name<?>>> {
075:
076: /**
077: * Create a new named scope.
078: *
079: * @param member1 The name.
080: */
081: public Named(Name<?> member1) {
082: tuple = new Tuple.T1<Name<?>>(member1);
083: }
084:
085: public final Tag tag() {
086: return Tag.NamedT;
087: }
088:
089: public boolean isNamed() {
090: return true;
091: }
092:
093: public String getName() {
094: return "Named";
095: }
096:
097: public String toString() {
098: return "Named of " + tuple.toString();
099: }
100:
101: }
102:
103: /** The anonymous scope. */
104: public static class Anonymous extends ScopeKind<Tuple.T1<String>> {
105:
106: /**
107: * Create a new anonymous scope.
108: *
109: * @param member1 A fresh name of the new anonymous scope.
110: */
111: public Anonymous(String member1) {
112: tuple = new Tuple.T1<String>(member1);
113: }
114:
115: public final Tag tag() {
116: return Tag.AnonymousT;
117: }
118:
119: public boolean isAnonymous() {
120: return true;
121: }
122:
123: public String getName() {
124: return "Anonymous";
125: }
126:
127: public String toString() {
128: return "Anonymous of " + tuple.toString();
129: }
130:
131: }
132:
133: /** The temporary scope. */
134: public static class Temporary extends ScopeKind<Tuple.T1<String>> {
135:
136: /**
137: * Create a new temporary scope.
138: *
139: * @param member1 A fresh name of the new temporary scope.
140: */
141: public Temporary(String member1) {
142: tuple = new Tuple.T1<String>(member1);
143: }
144:
145: public final Tag tag() {
146: return Tag.TemporaryT;
147: }
148:
149: public boolean isTemporary() {
150: return true;
151: }
152:
153: public String getName() {
154: return "Temporary";
155: }
156:
157: public String toString() {
158: return "Temporary of " + tuple.toString();
159: }
160:
161: }
162:
163: }
|