00001 // Filename: cppTBDType.cxx 00002 // Created by: drose (05Nov99) 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 "cppTBDType.h" 00021 #include "cppIdentifier.h" 00022 00023 #include "cppSimpleType.h" 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Function: CPPTBDType::Constructor 00027 // Access: Public 00028 // Description: 00029 //////////////////////////////////////////////////////////////////// 00030 CPPTBDType:: 00031 CPPTBDType(CPPIdentifier *ident) : 00032 CPPType(CPPFile()), 00033 _ident(ident) 00034 { 00035 _subst_decl_recursive_protect = false; 00036 } 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Function: CPPTBDType::resolve_type 00040 // Access: Public, Virtual 00041 // Description: If this CPPType object is a forward reference or 00042 // other nonspecified reference to a type that might now 00043 // be known a real type, returns the real type. 00044 // Otherwise returns the type itself. 00045 //////////////////////////////////////////////////////////////////// 00046 CPPType *CPPTBDType:: 00047 resolve_type(CPPScope *current_scope, CPPScope *global_scope) { 00048 CPPType *type = _ident->find_type(current_scope, global_scope); 00049 if (type != NULL) { 00050 return type; 00051 } 00052 return this; 00053 } 00054 00055 //////////////////////////////////////////////////////////////////// 00056 // Function: CPPTBDType::is_tbd 00057 // Access: Public, Virtual 00058 // Description: Returns true if the type, or any nested type within 00059 // the type, is a CPPTBDType and thus isn't fully 00060 // determined right now. In this case, calling 00061 // resolve_type() may or may not resolve the type. 00062 //////////////////////////////////////////////////////////////////// 00063 bool CPPTBDType:: 00064 is_tbd() const { 00065 return true; 00066 } 00067 00068 //////////////////////////////////////////////////////////////////// 00069 // Function: CPPTBDType::get_simple_name 00070 // Access: Public, Virtual 00071 // Description: Returns a fundametal one-word name for the type. 00072 // This name will not include any scoping operators or 00073 // template parameters, so it may not be a compilable 00074 // reference to the type. 00075 //////////////////////////////////////////////////////////////////// 00076 string CPPTBDType:: 00077 get_simple_name() const { 00078 return _ident->get_simple_name(); 00079 } 00080 00081 //////////////////////////////////////////////////////////////////// 00082 // Function: CPPTBDType::get_local_name 00083 // Access: Public, Virtual 00084 // Description: Returns the compilable, correct name for this type 00085 // within the indicated scope. If the scope is NULL, 00086 // within the scope the type is declared in. 00087 //////////////////////////////////////////////////////////////////// 00088 string CPPTBDType:: 00089 get_local_name(CPPScope *scope) const { 00090 return _ident->get_local_name(scope); 00091 } 00092 00093 //////////////////////////////////////////////////////////////////// 00094 // Function: CPPTBDType::get_fully_scoped_name 00095 // Access: Public, Virtual 00096 // Description: Returns the compilable, correct name for the type, 00097 // with completely explicit scoping. 00098 //////////////////////////////////////////////////////////////////// 00099 string CPPTBDType:: 00100 get_fully_scoped_name() const { 00101 return _ident->get_fully_scoped_name(); 00102 } 00103 00104 //////////////////////////////////////////////////////////////////// 00105 // Function: CPPTBDType::substitute_decl 00106 // Access: Public, Virtual 00107 // Description: 00108 //////////////////////////////////////////////////////////////////// 00109 CPPDeclaration *CPPTBDType:: 00110 substitute_decl(CPPDeclaration::SubstDecl &subst, 00111 CPPScope *current_scope, CPPScope *global_scope) { 00112 CPPDeclaration *top = 00113 CPPDeclaration::substitute_decl(subst, current_scope, global_scope); 00114 if (top != this) { 00115 return top; 00116 } 00117 00118 // Protect against recursive entry into this function block. I know 00119 // it's ugly--have you got any better suggestions? 00120 if (_subst_decl_recursive_protect) { 00121 // We're already executing this block. 00122 return this; 00123 } 00124 _subst_decl_recursive_protect = true; 00125 00126 CPPTBDType *rep = new CPPTBDType(*this); 00127 rep->_ident = _ident->substitute_decl(subst, current_scope, global_scope); 00128 00129 if (rep->_ident == _ident) { 00130 delete rep; 00131 rep = this; 00132 } 00133 00134 rep = CPPType::new_type(rep)->as_tbd_type(); 00135 assert(rep != NULL); 00136 00137 CPPType *result = rep; 00138 00139 // Can we now define it as a real type? 00140 CPPType *type = rep->_ident->find_type(current_scope, global_scope, subst); 00141 if (type != NULL) { 00142 result = type; 00143 } 00144 00145 subst.insert(SubstDecl::value_type(this, result)); 00146 00147 _subst_decl_recursive_protect = false; 00148 return result; 00149 } 00150 00151 //////////////////////////////////////////////////////////////////// 00152 // Function: CPPTBDType::output 00153 // Access: Public, Virtual 00154 // Description: 00155 //////////////////////////////////////////////////////////////////// 00156 void CPPTBDType:: 00157 output(ostream &out, int, CPPScope *, bool) const { 00158 out /* << "typename " */ << *_ident; 00159 } 00160 00161 //////////////////////////////////////////////////////////////////// 00162 // Function: CPPTBDType::get_subtype 00163 // Access: Public, Virtual 00164 // Description: 00165 //////////////////////////////////////////////////////////////////// 00166 CPPDeclaration::SubType CPPTBDType:: 00167 get_subtype() const { 00168 return ST_tbd; 00169 } 00170 00171 //////////////////////////////////////////////////////////////////// 00172 // Function: CPPTBDType::as_tbd_type 00173 // Access: Public, Virtual 00174 // Description: 00175 //////////////////////////////////////////////////////////////////// 00176 CPPTBDType *CPPTBDType:: 00177 as_tbd_type() { 00178 return this; 00179 } 00180 00181 00182 //////////////////////////////////////////////////////////////////// 00183 // Function: CPPTBDType::is_equal 00184 // Access: Protected, Virtual 00185 // Description: Called by CPPDeclaration() to determine whether this type is 00186 // equivalent to another type of the same type. 00187 //////////////////////////////////////////////////////////////////// 00188 bool CPPTBDType:: 00189 is_equal(const CPPDeclaration *other) const { 00190 const CPPTBDType *ot = ((CPPDeclaration *)other)->as_tbd_type(); 00191 assert(ot != NULL); 00192 00193 return (*_ident) == (*ot->_ident); 00194 } 00195 00196 00197 //////////////////////////////////////////////////////////////////// 00198 // Function: CPPTBDType::is_less 00199 // Access: Protected, Virtual 00200 // Description: Called by CPPDeclaration() to determine whether this type 00201 // should be ordered before another type of the same 00202 // type, in an arbitrary but fixed ordering. 00203 //////////////////////////////////////////////////////////////////// 00204 bool CPPTBDType:: 00205 is_less(const CPPDeclaration *other) const { 00206 const CPPTBDType *ot = ((CPPDeclaration *)other)->as_tbd_type(); 00207 assert(ot != NULL); 00208 00209 return (*_ident) < (*ot->_ident); 00210 }