KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > idl > TypeDef


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1997-2004 Gerald Brose.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */

20
21 package org.jacorb.idl;
22
23 /**
24  * @author Gerald Brose
25  * @version $Id: TypeDef.java,v 1.16 2004/05/06 12:39:59 nicolas Exp $
26  */

27
28 import java.io.PrintWriter JavaDoc;
29 import java.util.*;
30
31 public class TypeDef
32     extends TypeDeclaration
33 {
34     public TypeDeclarator type_declarator;
35     private Vector typeSpecs = new Vector();
36
37     public TypeDef( int num )
38     {
39         super( num );
40         pack_name = "";
41     }
42
43     public Vector getTypeSpecs()
44     {
45         return typeSpecs;
46     }
47
48     public void setPackage( String JavaDoc s )
49     {
50         s = parser.pack_replace( s );
51         if( pack_name.length() > 0 )
52             pack_name = s + "." + pack_name;
53         else
54             pack_name = s;
55         type_declarator.setPackage( s );
56     }
57
58     public void set_included( boolean i )
59     {
60         included = i;
61     }
62
63     public String JavaDoc id()
64     {
65         return type_declarator.id();
66     }
67
68     public void setEnclosingSymbol( IdlSymbol s )
69     {
70         if( enclosing_symbol != null && enclosing_symbol != s )
71         {
72             if( logger.isErrorEnabled())
73             {
74                 logger.error( "Typedef.setEnclosingSymbol: was " +
75                               enclosing_symbol.getClass().getName() +
76                               " now: " + s.getClass().getName() );
77             }
78
79             throw new RuntimeException JavaDoc( "Compiler Error: trying to reassign container for " +
80                     name );
81         }
82         enclosing_symbol = s;
83         type_declarator.setEnclosingSymbol( s );
84     }
85
86     public void parse()
87     {
88         for( Enumeration e = type_declarator.declarators.v.elements();
89              e.hasMoreElements(); )
90         {
91             Declarator d = (Declarator)e.nextElement();
92             d.escapeName();
93
94             try
95             {
96                 AliasTypeSpec alias =
97                     new AliasTypeSpec( (TypeSpec)type_declarator.type_spec() );
98
99                 /* arrays need special treatment */
100
101                 if( d.d instanceof ArrayDeclarator )
102                 {
103                     // we don't parse the declarator itself
104
// as that would result in its name getting defined
105
// we define the declarator's name as a type name indirectly
106
// through the cloned type specs.
107

108                     alias =
109                         new AliasTypeSpec(
110                                new ArrayTypeSpec( new_num(), alias.originalType(),
111                                                   (ArrayDeclarator)d.d, pack_name )
112                         );
113                     alias.parse();
114                 }
115                 else
116                 {
117                     if( !( e.hasMoreElements() ) )
118                         alias.parse();
119                 }
120                 alias.set_name( d.name() );
121                 alias.setPackage( pack_name );
122                 alias.setEnclosingSymbol( enclosing_symbol );
123                 alias.set_token( d.d.get_token() );
124                 alias.set_included( included );
125
126                 typeSpecs.addElement( alias );
127                 NameTable.define( d.full_name(), "type" );
128                 TypeMap.typedef( d.full_name(), alias );
129             }
130             catch( NameAlreadyDefined n )
131             {
132                 parser.error( "TypeDef'd name " + d.name() +
133                         " already defined. ", d.token );
134             }
135         }
136     }
137
138     public void print( PrintWriter JavaDoc ps )
139     {
140         if( included && !generateIncluded() )
141             return;
142
143         for( Enumeration e = typeSpecs.elements();
144              e.hasMoreElements(); )
145         {
146             ( (AliasTypeSpec)e.nextElement() ).print( ps );
147         }
148
149     }
150
151     /**
152      */

153
154     public void accept( IDLTreeVisitor visitor )
155     {
156         for( Enumeration e = typeSpecs.elements();
157              e.hasMoreElements(); )
158         {
159             ( (AliasTypeSpec)e.nextElement() ).accept( visitor );
160         }
161         visitor.visitTypeDef( this );
162     }
163
164
165
166 }
167
168
169
Popular Tags