00001 // Filename: cppFunctionGroup.cxx 00002 // Created by: drose (11Nov99) 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 "cppFunctionGroup.h" 00021 #include "cppFunctionType.h" 00022 #include "cppInstance.h" 00023 #include "indent.h" 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Function: CPPFunctionGroup::Constructor 00027 // Access: Public 00028 // Description: 00029 //////////////////////////////////////////////////////////////////// 00030 CPPFunctionGroup:: 00031 CPPFunctionGroup(const string &name) : 00032 CPPDeclaration(CPPFile()), 00033 _name(name) 00034 { 00035 } 00036 00037 //////////////////////////////////////////////////////////////////// 00038 // Function: CPPFunctionGroup::Destructor 00039 // Access: Public 00040 // Description: 00041 //////////////////////////////////////////////////////////////////// 00042 CPPFunctionGroup:: 00043 ~CPPFunctionGroup() { 00044 } 00045 00046 //////////////////////////////////////////////////////////////////// 00047 // Function: CPPFunctionGroup::get_return_type 00048 // Access: Public 00049 // Description: If all the functions that share this name have the 00050 // same return type, returns that type. Otherwise, if 00051 // some functions have different return types, returns 00052 // NULL. 00053 //////////////////////////////////////////////////////////////////// 00054 CPPType *CPPFunctionGroup:: 00055 get_return_type() const { 00056 CPPType *return_type = NULL; 00057 00058 if (!_instances.empty()) { 00059 Instances::const_iterator ii = _instances.begin(); 00060 return_type = (*ii)->_type->as_function_type()->_return_type; 00061 ++ii; 00062 while (ii != _instances.end()) { 00063 if ((*ii)->_type->as_function_type()->_return_type != return_type) { 00064 return (CPPType *)NULL; 00065 } 00066 ++ii; 00067 } 00068 } 00069 00070 return return_type; 00071 } 00072 00073 //////////////////////////////////////////////////////////////////// 00074 // Function: CPPFunctionGroup::output 00075 // Access: Public, Virtual 00076 // Description: 00077 //////////////////////////////////////////////////////////////////// 00078 void CPPFunctionGroup:: 00079 output(ostream &out, int indent_level, CPPScope *scope, bool complete) const { 00080 if (!_instances.empty()) { 00081 Instances::const_iterator ii = _instances.begin(); 00082 (*ii)->output(out, indent_level, scope, complete); 00083 ++ii; 00084 while (ii != _instances.end()) { 00085 out << ";\n"; 00086 indent(out, indent_level); 00087 (*ii)->output(out, indent_level, scope, complete); 00088 ++ii; 00089 } 00090 } 00091 } 00092 00093 //////////////////////////////////////////////////////////////////// 00094 // Function: CPPFunctionGroup::get_subtype 00095 // Access: Public, Virtual 00096 // Description: 00097 //////////////////////////////////////////////////////////////////// 00098 CPPDeclaration::SubType CPPFunctionGroup:: 00099 get_subtype() const { 00100 return ST_function_group; 00101 } 00102 00103 //////////////////////////////////////////////////////////////////// 00104 // Function: CPPFunctionGroup::as_function_group 00105 // Access: Public, Virtual 00106 // Description: 00107 //////////////////////////////////////////////////////////////////// 00108 CPPFunctionGroup *CPPFunctionGroup:: 00109 as_function_group() { 00110 return this; 00111 }