Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

dtool/src/cppparser/cppExtensionType.cxx

Go to the documentation of this file.
00001 // Filename: cppExtensionType.cxx
00002 // Created by:  drose (21Oct99)
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 "cppExtensionType.h"
00021 #include "cppTypedef.h"
00022 #include "cppIdentifier.h"
00023 #include "cppParser.h"
00024 #include "indent.h"
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //     Function: CPPExtensionType::Conextensionor
00028 //       Access: Public
00029 //  Description:
00030 ////////////////////////////////////////////////////////////////////
00031 CPPExtensionType::
00032 CPPExtensionType(CPPExtensionType::Type type,
00033                  CPPIdentifier *ident, CPPScope *current_scope,
00034                  const CPPFile &file) :
00035   CPPType(file),
00036   _type(type), _ident(ident)
00037 {
00038   if (_ident != NULL) {
00039     _ident->_native_scope = current_scope;
00040   }
00041 }
00042 
00043 ////////////////////////////////////////////////////////////////////
00044 //     Function: CPPExtensionType::get_simple_name
00045 //       Access: Public, Virtual
00046 //  Description:
00047 ////////////////////////////////////////////////////////////////////
00048 string CPPExtensionType::
00049 get_simple_name() const {
00050   if (_ident == NULL) {
00051     return "";
00052   }
00053   return _ident->get_simple_name();
00054 }
00055 
00056 ////////////////////////////////////////////////////////////////////
00057 //     Function: CPPExtensionType::get_local_name
00058 //       Access: Public, Virtual
00059 //  Description:
00060 ////////////////////////////////////////////////////////////////////
00061 string CPPExtensionType::
00062 get_local_name(CPPScope *scope) const {
00063   if (_ident == NULL) {
00064     return "";
00065   }
00066   return _ident->get_local_name(scope);
00067 }
00068 
00069 ////////////////////////////////////////////////////////////////////
00070 //     Function: CPPExtensionType::get_fully_scoped_name
00071 //       Access: Public, Virtual
00072 //  Description:
00073 ////////////////////////////////////////////////////////////////////
00074 string CPPExtensionType::
00075 get_fully_scoped_name() const {
00076   if (_ident == NULL) {
00077     return "";
00078   }
00079   return _ident->get_fully_scoped_name();
00080 }
00081 
00082 ////////////////////////////////////////////////////////////////////
00083 //     Function: CPPExtensionType::is_incomplete
00084 //       Access: Public, Virtual
00085 //  Description: Returns true if the type has not yet been fully
00086 //               specified, false if it has.
00087 ////////////////////////////////////////////////////////////////////
00088 bool CPPExtensionType::
00089 is_incomplete() const {
00090   return true;
00091 }
00092 
00093 ////////////////////////////////////////////////////////////////////
00094 //     Function: CPPExtensionType::is_tbd
00095 //       Access: Public, Virtual
00096 //  Description: Returns true if the type, or any nested type within
00097 //               the type, is a CPPTBDType and thus isn't fully
00098 //               determined right now.  In this case, calling
00099 //               resolve_type() may or may not resolve the type.
00100 ////////////////////////////////////////////////////////////////////
00101 bool CPPExtensionType::
00102 is_tbd() const {
00103   if (_ident != (CPPIdentifier *)NULL) {
00104     return _ident->is_tbd();
00105   }
00106   return false;
00107 }
00108 
00109 ////////////////////////////////////////////////////////////////////
00110 //     Function: CPPExtensionType::substitute_decl
00111 //       Access: Public, Virtual
00112 //  Description:
00113 ////////////////////////////////////////////////////////////////////
00114 CPPDeclaration *CPPExtensionType::
00115 substitute_decl(CPPDeclaration::SubstDecl &subst,
00116                 CPPScope *current_scope, CPPScope *global_scope) {
00117   SubstDecl::const_iterator si = subst.find(this);
00118   if (si != subst.end()) {
00119     return (*si).second;
00120   }
00121 
00122   CPPExtensionType *rep = new CPPExtensionType(*this);
00123   if (_ident != NULL) {
00124     rep->_ident =
00125       _ident->substitute_decl(subst, current_scope, global_scope);
00126   }
00127 
00128   if (rep->_ident == _ident) {
00129     delete rep;
00130     rep = this;
00131   }
00132   rep = CPPType::new_type(rep)->as_extension_type();
00133   subst.insert(SubstDecl::value_type(this, rep));
00134   return rep;
00135 }
00136 
00137 
00138 ////////////////////////////////////////////////////////////////////
00139 //     Function: CPPExtensionType::is_equivalent_type
00140 //       Access: Public, Virtual
00141 //  Description: This is a little more forgiving than is_equal(): it
00142 //               returns true if the types appear to be referring to
00143 //               the same thing, even if they may have different
00144 //               pointers or somewhat different definitions.  It's
00145 //               useful for parameter matching, etc.
00146 ////////////////////////////////////////////////////////////////////
00147 bool CPPExtensionType::
00148 is_equivalent(const CPPType &other) const {
00149   const CPPExtensionType *ot = ((CPPType *)&other)->as_extension_type();
00150   if (ot == (CPPExtensionType *)NULL) {
00151     return CPPType::is_equivalent(other);
00152   }
00153 
00154   // We consider two different extension types to be equivalent if
00155   // they have the same name.
00156 
00157   return *_ident == *ot->_ident;
00158 }
00159 
00160 ////////////////////////////////////////////////////////////////////
00161 //     Function: CPPExtensionType::output
00162 //       Access: Public, Virtual
00163 //  Description:
00164 ////////////////////////////////////////////////////////////////////
00165 void CPPExtensionType::
00166 output(ostream &out, int, CPPScope *scope, bool) const {
00167   if (_ident != NULL) {
00168     // If we have a name, use it.
00169     if (cppparser_output_class_keyword) {
00170       out << _type << " ";
00171     }
00172     out << _ident->get_local_name(scope);
00173 
00174   } else if (!_typedefs.empty()) {
00175     // If we have a typedef name, use it.
00176     out << _typedefs.front()->get_local_name(scope);
00177 
00178   } else {
00179     out << "(**unknown forward-reference type**)";
00180   }
00181 }
00182 
00183 ////////////////////////////////////////////////////////////////////
00184 //     Function: CPPExtensionType::get_subtype
00185 //       Access: Public, Virtual
00186 //  Description:
00187 ////////////////////////////////////////////////////////////////////
00188 CPPDeclaration::SubType CPPExtensionType::
00189 get_subtype() const {
00190   return ST_extension;
00191 }
00192 
00193 ////////////////////////////////////////////////////////////////////
00194 //     Function: CPPExtensionType::as_extension_type
00195 //       Access: Public, Virtual
00196 //  Description:
00197 ////////////////////////////////////////////////////////////////////
00198 CPPExtensionType *CPPExtensionType::
00199 as_extension_type() {
00200   return this;
00201 }
00202 
00203 ostream &
00204 operator << (ostream &out, CPPExtensionType::Type type) {
00205   switch (type) {
00206   case CPPExtensionType::T_enum:
00207     return out << "enum";
00208 
00209   case CPPExtensionType::T_class:
00210     return out << "class";
00211 
00212   case CPPExtensionType::T_struct:
00213     return out << "struct";
00214 
00215   case CPPExtensionType::T_union:
00216     return out << "union";
00217 
00218   default:
00219     return out << "***invalid extension type***";
00220   }
00221 }

Generated on Thu May 1 22:12:51 2003 for DTool by doxygen1.3