Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / TAO_IDL / ast / ast_string.cpp
blob18366d6d89f3fabe5cfd4e47967d2d9b9877e315
1 /*
3 COPYRIGHT
5 Copyright 1992, 1993, 1994 Sun Microsystems, Inc. Printed in the United
6 States of America. All Rights Reserved.
8 This product is protected by copyright and distributed under the following
9 license restricting its use.
11 The Interface Definition Language Compiler Front End (CFE) is made
12 available for your use provided that you include this license and copyright
13 notice on all media and documentation and the software program in which
14 this product is incorporated in whole or part. You may copy and extend
15 functionality (but may not remove functionality) of the Interface
16 Definition Language CFE without charge, but you are not authorized to
17 license or distribute it to anyone else except as part of a product or
18 program developed by you or with the express written consent of Sun
19 Microsystems, Inc. ("Sun").
21 The names of Sun Microsystems, Inc. and any of its subsidiaries or
22 affiliates may not be used in advertising or publicity pertaining to
23 distribution of Interface Definition Language CFE as permitted herein.
25 This license is effective until terminated by Sun for failure to comply
26 with this license. Upon termination, you shall destroy or return all code
27 and documentation for the Interface Definition Language CFE.
29 INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED AS IS WITH NO WARRANTIES OF
30 ANY KIND INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS
31 FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR ARISING FROM A COURSE OF
32 DEALING, USAGE OR TRADE PRACTICE.
34 INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED WITH NO SUPPORT AND WITHOUT
35 ANY OBLIGATION ON THE PART OF Sun OR ANY OF ITS SUBSIDIARIES OR AFFILIATES
36 TO ASSIST IN ITS USE, CORRECTION, MODIFICATION OR ENHANCEMENT.
38 SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES SHALL HAVE NO LIABILITY WITH
39 RESPECT TO THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY
40 INTERFACE DEFINITION LANGUAGE CFE OR ANY PART THEREOF.
42 IN NO EVENT WILL SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES BE LIABLE FOR
43 ANY LOST REVENUE OR PROFITS OR OTHER SPECIAL, INDIRECT AND CONSEQUENTIAL
44 DAMAGES, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
46 Use, duplication, or disclosure by the government is subject to
47 restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
48 Technical Data and Computer Software clause at DFARS 252.227-7013 and FAR
49 52.227-19.
51 Sun, Sun Microsystems and the Sun logo are trademarks or registered
52 trademarks of Sun Microsystems, Inc.
54 SunSoft, Inc.
55 2550 Garcia Avenue
56 Mountain View, California 94043
58 NOTE:
60 SunOS, SunSoft, Sun, Solaris, Sun Microsystems or the Sun logo are
61 trademarks or registered trademarks of Sun Microsystems, Inc.
65 // AST_String nodes represent IDL string declarations.
66 // AST_String is a subclass of AST_ConcreteType.
67 // AST_String nodes have a maximum size (an AST_Expression which must
68 // evaluate to a positive integer).
70 #include "ast_string.h"
71 #include "ast_expression.h"
72 #include "ast_visitor.h"
73 #include "ace/OS_NS_stdio.h"
74 #include "ace/OS_NS_string.h"
75 #include "utl_identifier.h"
76 #include "idl_defines.h"
77 #include "global_extern.h"
79 // Note we are overlooking the wstring case here.
80 AST_Decl::NodeType const
81 AST_String::NT = AST_Decl::NT_string;
83 AST_String::AST_String (AST_Decl::NodeType nt,
84 UTL_ScopedName *n,
85 AST_Expression *ms,
86 long wide)
87 : COMMON_Base (),
88 AST_Decl (nt, n, true),
89 AST_Type (nt, n),
90 AST_ConcreteType (nt, n),
91 pd_max_size (ms),
92 pd_width (wide)
94 // Always the case.
95 this->size_type (AST_Type::VARIABLE);
97 Identifier *id = 0;
98 UTL_ScopedName *new_name = 0;
99 UTL_ScopedName *conc_name = 0;
100 bool narrow = this->width () == (ssize_t) sizeof (char);
102 ACE_NEW (id,
103 Identifier (narrow ? "char *" : "WChar *"));
105 ACE_NEW (conc_name,
106 UTL_ScopedName (id,
107 0));
109 if (narrow)
111 new_name = conc_name;
113 else
115 ACE_NEW (id,
116 Identifier ("CORBA"));
118 ACE_NEW (new_name,
119 UTL_ScopedName (id,
120 conc_name));
123 this->set_name (new_name);
125 unsigned long bound = ms->ev ()->u.ulval;
127 static char namebuf[NAMEBUFSIZE];
128 static char boundbuf[NAMEBUFSIZE];
129 ACE_OS::memset (namebuf,
130 '\0',
131 NAMEBUFSIZE);
132 ACE_OS::memset (boundbuf,
133 '\0',
134 NAMEBUFSIZE);
136 if (bound)
138 ACE_OS::sprintf (boundbuf,
139 "_%ld",
140 bound);
143 ACE_OS::sprintf (namebuf,
144 "CORBA_%sSTRING%s",
145 (wide == 1 ? "" : "W"),
146 boundbuf);
148 this->flat_name_ = ACE::strnew (namebuf);
151 AST_String::~AST_String (void)
155 // Redefinition of inherited virtual operations.
157 // Dump this AST_String node to the ostream o.
158 void
159 AST_String::dump (ACE_OSTREAM_TYPE &o)
161 this->dump_i (o, "string <");
162 this->pd_max_size->dump (o);
163 this->dump_i (o, ">");
167 AST_String::ast_accept (ast_visitor *visitor)
169 return visitor->visit_string (this);
172 void
173 AST_String::destroy (void)
175 this->pd_max_size->destroy ();
176 delete this->pd_max_size;
177 this->pd_max_size = 0;
179 this->AST_ConcreteType::destroy ();
182 // Data accessors.
184 AST_Expression *
185 AST_String::max_size (void)
187 return this->pd_max_size;
190 long
191 AST_String::width (void)
193 return this->pd_width;
198 IMPL_NARROW_FROM_DECL(AST_String)