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

dtool/src/cppparser/cppConstType.cxx

Go to the documentation of this file.
00001 // Filename: cppConstType.cxx
00002 // Created by:  drose (28Oct99)
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 "cppConstType.h"
00021 
00022 ////////////////////////////////////////////////////////////////////
00023 //     Function: CPPConstType::Constructor
00024 //       Access: Public
00025 //  Description:
00026 ////////////////////////////////////////////////////////////////////
00027 CPPConstType::
00028 CPPConstType(CPPType *wrapped_around) :
00029   CPPType(CPPFile()),
00030   _wrapped_around(wrapped_around)
00031 {
00032 }
00033 
00034 ////////////////////////////////////////////////////////////////////
00035 //     Function: CPPConstType::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 CPPConstType::
00043 is_fully_specified() const {
00044   return CPPType::is_fully_specified() &&
00045     _wrapped_around->is_fully_specified();
00046 }
00047 
00048 ////////////////////////////////////////////////////////////////////
00049 //     Function: CPPConstType::substitute_decl
00050 //       Access: Public, Virtual
00051 //  Description:
00052 ////////////////////////////////////////////////////////////////////
00053 CPPDeclaration *CPPConstType::
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   CPPConstType *rep = new CPPConstType(*this);
00062   rep->_wrapped_around =
00063     _wrapped_around->substitute_decl(subst, current_scope, global_scope)
00064     ->as_type();
00065 
00066   if (rep->_wrapped_around == _wrapped_around) {
00067     delete rep;
00068     rep = this;
00069   }
00070   rep = CPPType::new_type(rep)->as_const_type();
00071   subst.insert(SubstDecl::value_type(this, rep));
00072   return rep;
00073 }
00074 
00075 ////////////////////////////////////////////////////////////////////
00076 //     Function: CPPConstType::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 *CPPConstType::
00084 resolve_type(CPPScope *current_scope, CPPScope *global_scope) {
00085   CPPType *ptype = _wrapped_around->resolve_type(current_scope, global_scope);
00086 
00087   if (ptype != _wrapped_around) {
00088     CPPConstType *rep = new CPPConstType(*this);
00089     rep->_wrapped_around = ptype;
00090     return CPPType::new_type(rep);
00091   }
00092   return this;
00093 }
00094 
00095 ////////////////////////////////////////////////////////////////////
00096 //     Function: CPPConstType::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 CPPConstType::
00104 is_tbd() const {
00105   return _wrapped_around->is_tbd();
00106 }
00107 
00108 ////////////////////////////////////////////////////////////////////
00109 //     Function: CPPConstType::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 CPPConstType::
00118 is_equivalent(const CPPType &other) const {
00119   const CPPConstType *ot = ((CPPType *)&other)->as_const_type();
00120   if (ot == (CPPConstType *)NULL) {
00121     return CPPType::is_equivalent(other);
00122   }
00123 
00124   return _wrapped_around->is_equivalent(*ot->_wrapped_around);
00125 }
00126 
00127 ////////////////////////////////////////////////////////////////////
00128 //     Function: CPPConstType::output
00129 //       Access: Public, Virtual
00130 //  Description:
00131 ////////////////////////////////////////////////////////////////////
00132 void CPPConstType::
00133 output(ostream &out, int indent_level, CPPScope *scope, bool complete) const {
00134   _wrapped_around->output(out, indent_level, scope, complete);
00135   out << " const";
00136 }
00137 
00138 ////////////////////////////////////////////////////////////////////
00139 //     Function: CPPConstType::output_instance
00140 //       Access: Public, Virtual
00141 //  Description: Formats a C++-looking line that defines an instance
00142 //               of the given type, with the indicated name.  In most
00143 //               cases this will be "type name", but some types have
00144 //               special exceptions.
00145 ////////////////////////////////////////////////////////////////////
00146 void CPPConstType::
00147 output_instance(ostream &out, int indent_level, CPPScope *scope,
00148                 bool complete, const string &prename,
00149                 const string &name) const {
00150   _wrapped_around->output_instance(out, indent_level, scope, complete,
00151                                    "const " + prename, name);
00152 }
00153 
00154 ////////////////////////////////////////////////////////////////////
00155 //     Function: CPPConstType::get_subtype
00156 //       Access: Public, Virtual
00157 //  Description:
00158 ////////////////////////////////////////////////////////////////////
00159 CPPDeclaration::SubType CPPConstType::
00160 get_subtype() const {
00161   return ST_const;
00162 }
00163 
00164 ////////////////////////////////////////////////////////////////////
00165 //     Function: CPPConstType::as_const_type
00166 //       Access: Public, Virtual
00167 //  Description:
00168 ////////////////////////////////////////////////////////////////////
00169 CPPConstType *CPPConstType::
00170 as_const_type() {
00171   return this;
00172 }
00173 
00174 
00175 ////////////////////////////////////////////////////////////////////
00176 //     Function: CPPConstType::is_equal
00177 //       Access: Protected, Virtual
00178 //  Description: Called by CPPDeclaration() to determine whether this type is
00179 //               equivalent to another type of the same type.
00180 ////////////////////////////////////////////////////////////////////
00181 bool CPPConstType::
00182 is_equal(const CPPDeclaration *other) const {
00183   const CPPConstType *ot = ((CPPDeclaration *)other)->as_const_type();
00184   assert(ot != NULL);
00185 
00186   return _wrapped_around == ot->_wrapped_around;
00187 }
00188 
00189 
00190 ////////////////////////////////////////////////////////////////////
00191 //     Function: CPPConstType::is_less
00192 //       Access: Protected, Virtual
00193 //  Description: Called by CPPDeclaration() to determine whether this type
00194 //               should be ordered before another type of the same
00195 //               type, in an arbitrary but fixed ordering.
00196 ////////////////////////////////////////////////////////////////////
00197 bool CPPConstType::
00198 is_less(const CPPDeclaration *other) const {
00199   const CPPConstType *ot = ((CPPDeclaration *)other)->as_const_type();
00200   assert(ot != NULL);
00201 
00202   return _wrapped_around < ot->_wrapped_around;
00203 }

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