Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / TAO_IDL / util / utl_identifier.cpp
blob9ee1561e12be2c93c27ce1e8746cdc167c277475
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 #include "utl_identifier.h"
66 #include "global_extern.h"
67 #include "utl_err.h"
68 #include "utl_string.h"
69 #include "fe_private.h"
71 // FUZZ: disable check_for_streams_include
72 #include "ace/streams.h"
73 #include "ace/OS_NS_string.h"
75 Identifier::Identifier (void)
76 : pv_string (0),
77 escaped_ (false)
81 Identifier::Identifier (const char *s)
82 : pv_string (0),
83 escaped_ (false)
85 preprocess_and_replace_string (s);
88 Identifier::Identifier (const Identifier &other)
89 : pv_string (0),
90 escaped_ (other.escaped ())
92 *this = other;
95 Identifier::~Identifier (void)
97 if (this->pv_string != 0)
99 ACE::strdelete (this->pv_string);
103 // Operations.
105 char *
106 Identifier::get_string (void)
108 return this->pv_string;
111 const char *
112 Identifier::get_string (void) const
114 return this->pv_string;
117 void
118 Identifier::replace_string (const char * s)
120 if (pv_string)
122 delete [] this->pv_string;
124 this->pv_string = s ? ACE::strnew (s) : 0;
127 void
128 Identifier::preprocess_and_replace_string (const char * s)
130 bool shift = false;
132 if (*s == '_')
134 // Only one leading underscore is allowed.
135 if (s[1] == '_')
137 idl_global->err ()->error0 (UTL_Error::EIDL_UNDERSCORE);
140 shift = true;
141 this->escaped_ = true;
142 ACE_CString str (s);
143 const char *c_prefix = "_cxx_";
145 if (str.find ("_tc_") == 0
146 || str.find ("_tao_") == 0)
148 shift = false;
150 else if (str.find (c_prefix) == 0)
152 str = str.substr (ACE_OS::strlen (c_prefix));
153 const char *eh_suffix = "_excep";
154 ACE_CString::size_type pos =
155 str.length () - ACE_OS::strlen (eh_suffix);
157 // If we have an AMI exception holder suffix, strip it off.
158 if (str.find (eh_suffix) == pos)
160 str = str.substr (0, pos);
163 TAO_IDL_CPP_Keyword_Table cpp_key_tbl;
164 unsigned int len =
165 static_cast<unsigned int> (str.length ());
166 const TAO_IDL_CPP_Keyword_Entry *entry =
167 cpp_key_tbl.lookup (str.c_str (), len);
169 if (entry != 0)
171 shift = false;
176 replace_string (shift ? s + 1 : s);
179 // Compare two Identifier *
180 bool
181 Identifier::compare (Identifier *o)
183 if (!o ||
184 !o->pv_string ||
185 !this->pv_string ||
186 this->escaped_ ^ o->escaped_)
188 return false;
191 return !ACE_OS::strcmp (this->pv_string, o->pv_string);
194 // Report the appropriate error if the two identifiers differ only in case.
195 bool
196 Identifier::case_compare (Identifier *o)
198 return UTL_String::compare (this->pv_string, o->pv_string);
201 // Report no error if the two identifiers differ only in case.
202 bool
203 Identifier::case_compare_quiet (Identifier *o)
205 return UTL_String::compare_quiet (this->pv_string, o->pv_string);
208 Identifier *
209 Identifier::copy (void)
211 Identifier *retval = 0;
212 ACE_NEW_RETURN (retval,
213 Identifier (this->pv_string),
216 retval->escaped_ = this->escaped_;
218 return retval;
221 bool
222 Identifier::escaped (void) const
224 return this->escaped_;
227 // Dumping.
228 void
229 Identifier::dump (ACE_OSTREAM_TYPE &o)
231 if (this->pv_string == 0)
233 return;
237 * Annotation ids are prefixed with '@' to effectively create an alternative
238 * namespace for them. This hides that hack from dumping.
240 o << ((pv_string[0] == '@') ? pv_string + 1 : pv_string);
243 void
244 Identifier::destroy (void)
248 bool
249 Identifier::operator== (const Identifier &other) const
251 return !ACE_OS::strcmp (pv_string, other.get_string ());
254 Identifier &
255 Identifier::operator= (const Identifier &other)
257 replace_string (other.get_string ());
258 return *this;