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

dtool/src/cppparser/cppReferenceType.cxx

Go to the documentation of this file.
00001 // Filename: cppReferenceType.cxx
00002 // Created by:  drose (19Oct99)
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 "cppReferenceType.h"
00021 
00022 ////////////////////////////////////////////////////////////////////
00023 //     Function: CPPReferenceType::Constructor
00024 //       Access: Public
00025 //  Description:
00026 ////////////////////////////////////////////////////////////////////
00027 CPPReferenceType::
00028 CPPReferenceType(CPPType *pointing_at) :
00029   CPPType(CPPFile()),
00030   _pointing_at(pointing_at)
00031 {
00032 }
00033 
00034 ////////////////////////////////////////////////////////////////////
00035 //     Function: CPPReferenceType::is_fully_specified
00036 //       Access: Public, Virtual
00037 //  Description: Returns true if this declaration is an actual,
00038 //               factual declaration, or false if some part of the
00039 //               declaration depends on a template parameter which has
00040 //               not yet been instantiated.
00041 ////////////////////////////////////////////////////////////////////
00042 bool CPPReferenceType::
00043 is_fully_specified() const {
00044   return CPPType::is_fully_specified() &&
00045     _pointing_at->is_fully_specified();
00046 }
00047 
00048 ////////////////////////////////////////////////////////////////////
00049 //     Function: CPPReferenceType::substitute_decl
00050 //       Access: Public, Virtual
00051 //  Description:
00052 ////////////////////////////////////////////////////////////////////
00053 CPPDeclaration *CPPReferenceType::
00054 substitute_decl(CPPDeclaration::SubstDecl &subst,
00055                 CPPScope *current_scope, CPPScope *global_scope) {
00056   SubstDecl::const_iterator si = subst.find(this);
00057   if (si != subst.end()) {
00058     return (*si).second;
00059   }
00060 
00061   CPPReferenceType *rep = new CPPReferenceType(*this);
00062   rep->_pointing_at =
00063     _pointing_at->substitute_decl(subst, current_scope, global_scope)
00064     ->as_type();
00065 
00066   if (rep->_pointing_at == _pointing_at) {
00067     delete rep;
00068     rep = this;
00069   }
00070   rep = CPPType::new_type(rep)->as_reference_type();
00071   subst.insert(SubstDecl::value_type(this, rep));
00072   return rep;
00073 }
00074 
00075 ////////////////////////////////////////////////////////////////////
00076 //     Function: CPPReferenceType::resolve_type
00077 //       Access: Public, Virtual
00078 //  Description: If this CPPType object is a forward reference or
00079 //               other nonspecified reference to a type that might now
00080 //               be known a real type, returns the real type.
00081 //               Otherwise returns the type itself.
00082 ////////////////////////////////////////////////////////////////////
00083 CPPType *CPPReferenceType::
00084 resolve_type(CPPScope *current_scope, CPPScope *global_scope) {
00085   CPPType *ptype = _pointing_at->resolve_type(current_scope, global_scope);
00086 
00087   if (ptype != _pointing_at) {
00088     CPPReferenceType *rep = new CPPReferenceType(*this);
00089     rep->_pointing_at = ptype;
00090     return CPPType::new_type(rep);
00091   }
00092   return this;
00093 }
00094 
00095 ////////////////////////////////////////////////////////////////////
00096 //     Function: CPPReferenceType::is_tbd
00097 //       Access: Public, Virtual
00098 //  Description: Returns true if the type, or any nested type within
00099 //               the type, is a CPPTBDType and thus isn't fully
00100 //               determined right now.  In this case, calling
00101 //               resolve_type() may or may not resolve the type.
00102 ////////////////////////////////////////////////////////////////////
00103 bool CPPReferenceType::
00104 is_tbd() const {
00105   return _pointing_at->is_tbd();
00106 }
00107 
00108 ////////////////////////////////////////////////////////////////////
00109 //     Function: CPPReferenceType::is_equivalent
00110 //       Access: Public, Virtual
00111 //  Description: This is a little more forgiving than is_equal(): it
00112 //               returns true if the types appear to be referring to
00113 //               the same thing, even if they may have different
00114 //               pointers or somewhat different definitions.  It's
00115 //               useful for parameter matching, etc.
00116 ////////////////////////////////////////////////////////////////////
00117 bool CPPReferenceType::
00118 is_equivalent(const CPPType &other) const {
00119   const CPPReferenceType *ot = ((CPPType *)&other)->as_reference_type();
00120   if (ot == (CPPReferenceType *)NULL) {
00121     return CPPType::is_equivalent(other);
00122   }
00123 
00124   return _pointing_at->is_equivalent(*ot->_pointing_at);
00125 }
00126 
00127 ////////////////////////////////////////////////////////////////////
00128 //     Function: CPPReferenceType::output
00129 //       Access: Public, Virtual
00130 //  Description:
00131 ////////////////////////////////////////////////////////////////////
00132 void CPPReferenceType::
00133 output(ostream &out, int indent_level, CPPScope *scope, bool complete) const {
00134   /*
00135   _pointing_at->output(out, indent_level, scope, complete);
00136   out << " &";
00137   */
00138   output_instance(out, indent_level, scope, complete, "", "");
00139 }
00140 
00141 ////////////////////////////////////////////////////////////////////
00142 //     Function: CPPReferenceType::output_instance
00143 //       Access: Public, Virtual
00144 //  Description: Formats a C++-looking line that defines an instance
00145 //               of the given type, with the indicated name.  In most
00146 //               cases this will be "type name", but some types have
00147 //               special exceptions.
00148 ////////////////////////////////////////////////////////////////////
00149 void CPPReferenceType::
00150 output_instance(ostream &out, int indent_level, CPPScope *scope,
00151                 bool complete, const string &prename,
00152                 const string &name) const {
00153   _pointing_at->output_instance(out, indent_level, scope, complete,
00154                                 "&" + prename, name);
00155 }
00156 
00157 ////////////////////////////////////////////////////////////////////
00158 //     Function: CPPReferenceType::get_subtype
00159 //       Access: Public, Virtual
00160 //  Description:
00161 ////////////////////////////////////////////////////////////////////
00162 CPPDeclaration::SubType CPPReferenceType::
00163 get_subtype() const {
00164   return ST_reference;
00165 }
00166 
00167 ////////////////////////////////////////////////////////////////////
00168 //     Function: CPPReferenceType::as_reference_type
00169 //       Access: Public, Virtual
00170 //  Description:
00171 ////////////////////////////////////////////////////////////////////
00172 CPPReferenceType *CPPReferenceType::
00173 as_reference_type() {
00174   return this;
00175 }
00176 
00177 
00178 ////////////////////////////////////////////////////////////////////
00179 //     Function: CPPReferenceType::is_equal
00180 //       Access: Protected, Virtual
00181 //  Description: Called by CPPDeclaration() to determine whether this type is
00182 //               equivalent to another type of the same type.
00183 ////////////////////////////////////////////////////////////////////
00184 bool CPPReferenceType::
00185 is_equal(const CPPDeclaration *other) const {
00186   const CPPReferenceType *ot = ((CPPDeclaration *)other)->as_reference_type();
00187   assert(ot != NULL);
00188 
00189   return _pointing_at == ot->_pointing_at;
00190 }
00191 
00192 
00193 ////////////////////////////////////////////////////////////////////
00194 //     Function: CPPReferenceType::is_less
00195 //       Access: Protected, Virtual
00196 //  Description: Called by CPPDeclaration() to determine whether this type
00197 //               should be ordered before another type of the same
00198 //               type, in an arbitrary but fixed ordering.
00199 ////////////////////////////////////////////////////////////////////
00200 bool CPPReferenceType::
00201 is_less(const CPPDeclaration *other) const {
00202   const CPPReferenceType *ot = ((CPPDeclaration *)other)->as_reference_type();
00203   assert(ot != NULL);
00204 
00205   return _pointing_at < ot->_pointing_at;
00206 }

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