001: /*
002: * xtc - The eXTensible Compiler
003: * Copyright (C) 2007 New York University
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.typical;
020:
021: import xtc.tree.Visitor;
022: import xtc.tree.GNode;
023: import xtc.tree.Node;
024:
025: /**
026: * Visitor to add all types reachable from a given type definition.
027: *
028: * @author Laune Harris, Anh Le
029: * @version $Revision: 1.1 $
030: */
031: public class TypeCollector extends Visitor {
032:
033: /** Create a new type collector. */
034: public TypeCollector() {
035: //nothing to do here.
036: }
037:
038: /**
039: * Collect the types in this type definition.
040: *
041: * @param n The type definition node.
042: */
043: public void visitTypeDefinition(GNode n) {
044: dispatch(n.getGeneric(2));
045: }
046:
047: /**
048: * Collect the types in this attribute definition.
049: *
050: * @param n The attribute definition node.
051: */
052: public void visitAttributeDefinition(GNode n) {
053: dispatch(n.getGeneric(1));
054: }
055:
056: /**
057: * Collect the types in this equal attribute definition.
058: *
059: * @param n The equal attribute definition node.
060: */
061: public void visitEqualAttributeDefinition(GNode n) {
062: dispatch(n.getGeneric(1));
063: }
064:
065: /**
066: * Collect the types in this record declaration.
067: *
068: * @param n The record declaration node.
069: */
070: public void visitRecordDeclaration(GNode n) {
071: for (int i = 0; i < n.size(); i++) {
072: dispatch(n.getGeneric(i).getGeneric(1));
073: }
074: }
075:
076: /**
077: * Collect the types in this constructed type declaration.
078: *
079: * @param n The constructed type node.
080: */
081: public void visitConstructedType(GNode n) {
082: dispatch(n.getGeneric(0));
083: }
084:
085: /**
086: * Collect the types in this variant declaration declaration.
087: *
088: * @param n The variant declaration node.
089: */
090: public void visitVariantDeclaration(GNode n) {
091: for (int i = 0; i < n.size(); i++) {
092: dispatch(n.getGeneric(i));
093: }
094: }
095:
096: /**
097: * Collect the types in this type constructor.
098: *
099: * @param n The type constructor node.
100: */
101: public void visitTypeConstructor(GNode n) {
102: dispatch(n.getGeneric(1));
103: }
104:
105: /**
106: * Collect the types in this tuple type.
107: *
108: * @param n The tuple type node.
109: */
110: public void visitTupleType(GNode n) {
111: for (int i = 0; i < n.size(); i++) {
112: dispatch(n.getGeneric(i));
113: }
114: }
115:
116: /**
117: * Collect the types in a namespace definition.
118: *
119: * @param n The namespace node.
120: */
121: public void visitNameSpaceDefinition(GNode n) {
122: for (int i = 0; i < n.size(); i++) {
123: dispatch(n.getGeneric(i));
124: }
125: }
126:
127: /**
128: * Collect the type in a other nodes.
129: *
130: * @param n The node.
131: */
132: public void visit(GNode n) {
133: //nothing to do.
134: }
135:
136: }
|