00001 // Filename: cppTypedef.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 "cppTypedef.h" 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Function: CPPTypedef::Constructor 00024 // Access: Public 00025 // Description: Constructs a new CPPTypedef object based on the 00026 // indicated CPPInstance object. The CPPInstance is 00027 // deallocated. 00028 // 00029 // If global is true, the typedef is defined at the 00030 // global scope, and hence it's worth telling the type 00031 // itself about. Otherwise, it's just a locally-scoped 00032 // typedef. 00033 //////////////////////////////////////////////////////////////////// 00034 CPPTypedef:: 00035 CPPTypedef(CPPInstance *inst, bool global) : CPPInstance(*inst) 00036 { 00037 // Actually, we'll avoid deleting this for now. It causes problems 00038 // for some reason to be determined later. 00039 // delete inst; 00040 00041 assert(_type != NULL); 00042 if (global) { 00043 _type->_typedefs.push_back(this); 00044 CPPType::record_preferred_name_for(_type, inst->get_local_name()); 00045 } 00046 } 00047 00048 //////////////////////////////////////////////////////////////////// 00049 // Function: CPPTypedef::substitute_decl 00050 // Access: Public, Virtual 00051 // Description: 00052 //////////////////////////////////////////////////////////////////// 00053 CPPDeclaration *CPPTypedef:: 00054 substitute_decl(CPPDeclaration::SubstDecl &subst, 00055 CPPScope *current_scope, CPPScope *global_scope) { 00056 CPPDeclaration *decl = 00057 CPPInstance::substitute_decl(subst, current_scope, global_scope); 00058 assert(decl != NULL); 00059 if (decl->as_typedef()) { 00060 return decl; 00061 } 00062 assert(decl->as_instance() != NULL); 00063 return new CPPTypedef(new CPPInstance(*decl->as_instance()), false); 00064 } 00065 00066 //////////////////////////////////////////////////////////////////// 00067 // Function: CPPTypedef::output 00068 // Access: Public, Virtual 00069 // Description: 00070 //////////////////////////////////////////////////////////////////// 00071 void CPPTypedef:: 00072 output(ostream &out, int indent_level, CPPScope *scope, bool) const { 00073 out << "typedef "; 00074 CPPInstance::output(out, indent_level, scope, false); 00075 } 00076 00077 //////////////////////////////////////////////////////////////////// 00078 // Function: CPPTypedef::get_subtype 00079 // Access: Public, Virtual 00080 // Description: 00081 //////////////////////////////////////////////////////////////////// 00082 CPPDeclaration::SubType CPPTypedef:: 00083 get_subtype() const { 00084 return ST_typedef; 00085 } 00086 00087 //////////////////////////////////////////////////////////////////// 00088 // Function: CPPTypedef::as_typedef 00089 // Access: Public, Virtual 00090 // Description: 00091 //////////////////////////////////////////////////////////////////// 00092 CPPTypedef *CPPTypedef:: 00093 as_typedef() { 00094 return this; 00095 }