00001 // Filename: cppTypeProxy.cxx 00002 // Created by: drose (07Dec99) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 00020 #include "cppTypeProxy.h" 00021 #include "cppFile.h" 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Function: CPPTypeProxy::Constructor 00025 // Access: Public 00026 // Description: 00027 //////////////////////////////////////////////////////////////////// 00028 CPPTypeProxy:: 00029 CPPTypeProxy() : 00030 CPPType(CPPFile()) 00031 { 00032 _actual_type = (CPPType *)NULL; 00033 } 00034 00035 //////////////////////////////////////////////////////////////////// 00036 // Function: CPPTypeProxy::resolve_type 00037 // Access: Public, Virtual 00038 // Description: If this CPPType object is a forward reference or 00039 // other nonspecified reference to a type that might now 00040 // be known a real type, returns the real type. 00041 // Otherwise returns the type itself. 00042 //////////////////////////////////////////////////////////////////// 00043 CPPType *CPPTypeProxy:: 00044 resolve_type(CPPScope *, CPPScope *) { 00045 if (_actual_type == (CPPType *)NULL) { 00046 return this; 00047 } 00048 return _actual_type; 00049 } 00050 00051 //////////////////////////////////////////////////////////////////// 00052 // Function: CPPTypeProxy::is_tbd 00053 // Access: Public, Virtual 00054 // Description: Returns true if the type, or any nested type within 00055 // the type, is a CPPTBDType and thus isn't fully 00056 // determined right now. In this case, calling 00057 // resolve_type() may or may not resolve the type. 00058 //////////////////////////////////////////////////////////////////// 00059 bool CPPTypeProxy:: 00060 is_tbd() const { 00061 if (_actual_type == (CPPType *)NULL) { 00062 return false; 00063 } 00064 return _actual_type->is_tbd(); 00065 } 00066 00067 //////////////////////////////////////////////////////////////////// 00068 // Function: CPPTypeProxy::has_typedef_name 00069 // Access: Public 00070 // Description: Returns true if the type has even been typedef'ed and 00071 // therefore has a simple name available to stand for 00072 // it. Extension types are all implicitly typedef'ed on 00073 // declaration. 00074 //////////////////////////////////////////////////////////////////// 00075 bool CPPTypeProxy:: 00076 has_typedef_name() const { 00077 if (_actual_type == (CPPType *)NULL) { 00078 return false; 00079 } 00080 return _actual_type->has_typedef_name(); 00081 } 00082 00083 //////////////////////////////////////////////////////////////////// 00084 // Function: CPPTypeProxy::get_typedef_name 00085 // Access: Public 00086 // Description: Returns a string that can be used to name the type, 00087 // if has_typedef_name() returned true. This will be 00088 // the first typedef name applied to the type. 00089 //////////////////////////////////////////////////////////////////// 00090 string CPPTypeProxy:: 00091 get_typedef_name(CPPScope *) const { 00092 if (_actual_type == (CPPType *)NULL) { 00093 return string(); 00094 } 00095 return _actual_type->get_typedef_name(); 00096 } 00097 00098 00099 //////////////////////////////////////////////////////////////////// 00100 // Function: CPPTypeProxy::get_simple_name 00101 // Access: Public, Virtual 00102 // Description: Returns a fundametal one-word name for the type. 00103 // This name will not include any scoping operators or 00104 // template parameters, so it may not be a compilable 00105 // reference to the type. 00106 //////////////////////////////////////////////////////////////////// 00107 string CPPTypeProxy:: 00108 get_simple_name() const { 00109 if (_actual_type == (CPPType *)NULL) { 00110 return "unknown"; 00111 } 00112 return _actual_type->get_simple_name(); 00113 } 00114 00115 //////////////////////////////////////////////////////////////////// 00116 // Function: CPPTypeProxy::get_local_name 00117 // Access: Public, Virtual 00118 // Description: Returns the compilable, correct name for this type 00119 // within the indicated scope. If the scope is NULL, 00120 // within the scope the type is declared in. 00121 //////////////////////////////////////////////////////////////////// 00122 string CPPTypeProxy:: 00123 get_local_name(CPPScope *scope) const { 00124 if (_actual_type == (CPPType *)NULL) { 00125 return "unknown"; 00126 } 00127 return _actual_type->get_local_name(scope); 00128 } 00129 00130 //////////////////////////////////////////////////////////////////// 00131 // Function: CPPTypeProxy::get_fully_scoped_name 00132 // Access: Public, Virtual 00133 // Description: Returns the compilable, correct name for the type, 00134 // with completely explicit scoping. 00135 //////////////////////////////////////////////////////////////////// 00136 string CPPTypeProxy:: 00137 get_fully_scoped_name() const { 00138 if (_actual_type == (CPPType *)NULL) { 00139 return "unknown"; 00140 } 00141 return _actual_type->get_fully_scoped_name(); 00142 } 00143 00144 //////////////////////////////////////////////////////////////////// 00145 // Function: CPPTypeProxy::get_preferred_name 00146 // Access: Public, Virtual 00147 // Description: Returns the best name to use for the type from a 00148 // programmer's point of view. This will typically be a 00149 // typedef name if one is available, or the full C++ 00150 // name if it is not. The typedef may or may not be 00151 // visible within the current scope, so this type name 00152 // may not be compilable. 00153 //////////////////////////////////////////////////////////////////// 00154 string CPPTypeProxy:: 00155 get_preferred_name() const { 00156 if (_actual_type == (CPPType *)NULL) { 00157 return "unknown"; 00158 } 00159 return _actual_type->get_preferred_name(); 00160 } 00161 00162 //////////////////////////////////////////////////////////////////// 00163 // Function: CPPTypeProxy::is_incomplete 00164 // Access: Public, Virtual 00165 // Description: Returns true if the type has not yet been fully 00166 // specified, false if it has. 00167 //////////////////////////////////////////////////////////////////// 00168 bool CPPTypeProxy:: 00169 is_incomplete() const { 00170 if (_actual_type == (CPPType *)NULL) { 00171 return true; 00172 } 00173 return _actual_type->is_incomplete(); 00174 } 00175 00176 //////////////////////////////////////////////////////////////////// 00177 // Function: CPPTypeProxy::output_instance 00178 // Access: Public, Virtual 00179 // Description: Formats a C++-looking line that defines an instance 00180 // of the given type, with the indicated name. In most 00181 // cases this will be "type name", but some types have 00182 // special exceptions. 00183 //////////////////////////////////////////////////////////////////// 00184 void CPPTypeProxy:: 00185 output_instance(ostream &out, int indent_level, CPPScope *scope, 00186 bool complete, const string &prename, 00187 const string &name) const { 00188 if (_actual_type == (CPPType *)NULL) { 00189 out << "unknown " << prename << name; 00190 return; 00191 } 00192 _actual_type->output_instance(out, indent_level, scope, complete, 00193 prename, name); 00194 } 00195 00196 //////////////////////////////////////////////////////////////////// 00197 // Function: CPPTypeProxy::output 00198 // Access: Public, Virtual 00199 // Description: 00200 //////////////////////////////////////////////////////////////////// 00201 void CPPTypeProxy:: 00202 output(ostream &out, int indent_level, CPPScope *scope, bool complete) const { 00203 if (_actual_type == (CPPType *)NULL) { 00204 out << "unknown"; 00205 return; 00206 } 00207 _actual_type->output(out, indent_level, scope, complete); 00208 } 00209 00210 00211 //////////////////////////////////////////////////////////////////// 00212 // Function: CPPTypeProxy::get_subtype 00213 // Access: Public, Virtual 00214 // Description: 00215 //////////////////////////////////////////////////////////////////// 00216 CPPDeclaration::SubType CPPTypeProxy:: 00217 get_subtype() const { 00218 return ST_type_proxy; 00219 } 00220 00221 //////////////////////////////////////////////////////////////////// 00222 // Function: CPPTypeProxy::as_type 00223 // Access: Public, Virtual 00224 // Description: 00225 //////////////////////////////////////////////////////////////////// 00226 CPPType *CPPTypeProxy:: 00227 as_type() { 00228 if (_actual_type == (CPPType *)NULL) { 00229 return this; 00230 } 00231 return _actual_type; 00232 } 00233 00234 //////////////////////////////////////////////////////////////////// 00235 // Function: CPPTypeProxy::as_simple_type 00236 // Access: Public, Virtual 00237 // Description: 00238 //////////////////////////////////////////////////////////////////// 00239 CPPSimpleType *CPPTypeProxy:: 00240 as_simple_type() { 00241 if (_actual_type == (CPPType *)NULL) { 00242 return (CPPSimpleType *)NULL; 00243 } 00244 return _actual_type->as_simple_type(); 00245 } 00246 00247 //////////////////////////////////////////////////////////////////// 00248 // Function: CPPTypeProxy::as_pointer_type 00249 // Access: Public, Virtual 00250 // Description: 00251 //////////////////////////////////////////////////////////////////// 00252 CPPPointerType *CPPTypeProxy:: 00253 as_pointer_type() { 00254 if (_actual_type == (CPPType *)NULL) { 00255 return (CPPPointerType *)NULL; 00256 } 00257 return _actual_type->as_pointer_type(); 00258 } 00259 00260 //////////////////////////////////////////////////////////////////// 00261 // Function: CPPTypeProxy::as_reference_type 00262 // Access: Public, Virtual 00263 // Description: 00264 //////////////////////////////////////////////////////////////////// 00265 CPPReferenceType *CPPTypeProxy:: 00266 as_reference_type() { 00267 if (_actual_type == (CPPType *)NULL) { 00268 return (CPPReferenceType *)NULL; 00269 } 00270 return _actual_type->as_reference_type(); 00271 } 00272 00273 //////////////////////////////////////////////////////////////////// 00274 // Function: CPPTypeProxy::as_array_type 00275 // Access: Public, Virtual 00276 // Description: 00277 //////////////////////////////////////////////////////////////////// 00278 CPPArrayType *CPPTypeProxy:: 00279 as_array_type() { 00280 if (_actual_type == (CPPType *)NULL) { 00281 return (CPPArrayType *)NULL; 00282 } 00283 return _actual_type->as_array_type(); 00284 } 00285 00286 //////////////////////////////////////////////////////////////////// 00287 // Function: CPPTypeProxy::as_const_type 00288 // Access: Public, Virtual 00289 // Description: 00290 //////////////////////////////////////////////////////////////////// 00291 CPPConstType *CPPTypeProxy:: 00292 as_const_type() { 00293 if (_actual_type == (CPPType *)NULL) { 00294 return (CPPConstType *)NULL; 00295 } 00296 return _actual_type->as_const_type(); 00297 } 00298 00299 //////////////////////////////////////////////////////////////////// 00300 // Function: CPPTypeProxy::as_function_type 00301 // Access: Public, Virtual 00302 // Description: 00303 //////////////////////////////////////////////////////////////////// 00304 CPPFunctionType *CPPTypeProxy:: 00305 as_function_type() { 00306 if (_actual_type == (CPPType *)NULL) { 00307 return (CPPFunctionType *)NULL; 00308 } 00309 return _actual_type->as_function_type(); 00310 } 00311 00312 //////////////////////////////////////////////////////////////////// 00313 // Function: CPPTypeProxy::as_extension_type 00314 // Access: Public, Virtual 00315 // Description: 00316 //////////////////////////////////////////////////////////////////// 00317 CPPExtensionType *CPPTypeProxy:: 00318 as_extension_type() { 00319 if (_actual_type == (CPPType *)NULL) { 00320 return (CPPExtensionType *)NULL; 00321 } 00322 return _actual_type->as_extension_type(); 00323 } 00324 00325 //////////////////////////////////////////////////////////////////// 00326 // Function: CPPTypeProxy::as_struct_type 00327 // Access: Public, Virtual 00328 // Description: 00329 //////////////////////////////////////////////////////////////////// 00330 CPPStructType *CPPTypeProxy:: 00331 as_struct_type() { 00332 if (_actual_type == (CPPType *)NULL) { 00333 return (CPPStructType *)NULL; 00334 } 00335 return _actual_type->as_struct_type(); 00336 } 00337 00338 //////////////////////////////////////////////////////////////////// 00339 // Function: CPPTypeProxy::as_enum_type 00340 // Access: Public, Virtual 00341 // Description: 00342 //////////////////////////////////////////////////////////////////// 00343 CPPEnumType *CPPTypeProxy:: 00344 as_enum_type() { 00345 if (_actual_type == (CPPType *)NULL) { 00346 return (CPPEnumType *)NULL; 00347 } 00348 return _actual_type->as_enum_type(); 00349 } 00350 00351 //////////////////////////////////////////////////////////////////// 00352 // Function: CPPTypeProxy::as_tbd_type 00353 // Access: Public, Virtual 00354 // Description: 00355 //////////////////////////////////////////////////////////////////// 00356 CPPTBDType *CPPTypeProxy:: 00357 as_tbd_type() { 00358 if (_actual_type == (CPPType *)NULL) { 00359 return (CPPTBDType *)NULL; 00360 } 00361 return _actual_type->as_tbd_type(); 00362 } 00363 00364 //////////////////////////////////////////////////////////////////// 00365 // Function: CPPTypeProxy::as_type_proxy 00366 // Access: Public, Virtual 00367 // Description: 00368 //////////////////////////////////////////////////////////////////// 00369 CPPTypeProxy *CPPTypeProxy:: 00370 as_type_proxy() { 00371 return this; 00372 } 00373