00001 // Filename: parameterRemapPTToPointer.cxx 00002 // Created by: drose (10Aug00) 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 #include "parameterRemapPTToPointer.h" 00020 #include "interrogate.h" 00021 #include "interrogateBuilder.h" 00022 #include "typeManager.h" 00023 00024 #include <cppType.h> 00025 #include <cppStructType.h> 00026 #include <cppDeclaration.h> 00027 #include <notify.h> 00028 00029 //////////////////////////////////////////////////////////////////// 00030 // Function: ParameterRemapPTToPointer::Constructor 00031 // Access: Public 00032 // Description: 00033 //////////////////////////////////////////////////////////////////// 00034 ParameterRemapPTToPointer:: 00035 ParameterRemapPTToPointer(CPPType *orig_type) : 00036 ParameterRemap(orig_type) 00037 { 00038 CPPStructType *pt_type = TypeManager::unwrap(_orig_type)->as_struct_type(); 00039 assert(pt_type != (CPPStructType *)NULL); 00040 00041 // A horrible hack around a CPPParser bug. We don't trust the 00042 // CPPStructType pointer we were given; instead, we ask CPPParser to 00043 // parse a new type of the same name. This has a better chance of 00044 // fully resolving templates. 00045 string name = pt_type->get_local_name(&parser); 00046 CPPType *new_type = parser.parse_type(name); 00047 if (new_type == (CPPType *)NULL) { 00048 nout << "Type " << name << " is unknown to parser.\n"; 00049 } else { 00050 new_type = new_type->resolve_type(&parser, &parser); 00051 pt_type = new_type->as_struct_type(); 00052 assert(pt_type != (CPPStructType *)NULL); 00053 } 00054 00055 _pointer_type = TypeManager::get_pointer_type(pt_type); 00056 if (_pointer_type == (CPPType *)NULL) { 00057 // If we couldn't figure out the pointer type, forget it. 00058 nout << "Couldn't figure out pointer type for " << *pt_type << "\n"; 00059 _is_valid = false; 00060 return; 00061 } 00062 00063 _new_type = _pointer_type; 00064 00065 // We must use an actual PointerTo to hold any temporary values, 00066 // until we can safely ref it. 00067 _temporary_type = pt_type; 00068 } 00069 00070 //////////////////////////////////////////////////////////////////// 00071 // Function: ParameterRemapPTToPointer::pass_parameter 00072 // Access: Public, Virtual 00073 // Description: Outputs an expression that converts the indicated 00074 // variable from the new type to the original type, for 00075 // passing into the actual C++ function. 00076 //////////////////////////////////////////////////////////////////// 00077 void ParameterRemapPTToPointer:: 00078 pass_parameter(ostream &out, const string &variable_name) { 00079 out << variable_name; 00080 } 00081 00082 //////////////////////////////////////////////////////////////////// 00083 // Function: ParameterRemapPTToPointer::get_return_expr 00084 // Access: Public, Virtual 00085 // Description: Returns an expression that evalutes to the 00086 // appropriate value type for returning from the 00087 // function, given an expression of the original type. 00088 //////////////////////////////////////////////////////////////////// 00089 string ParameterRemapPTToPointer:: 00090 get_return_expr(const string &expression) { 00091 return expression; 00092 } 00093 00094 //////////////////////////////////////////////////////////////////// 00095 // Function: ParameterRemapPTToPointer::temporary_to_return 00096 // Access: Public, Virtual 00097 // Description: Returns the string that converts the expression 00098 // stored in the indicated temporary variable to the 00099 // appropriate return value type. This is normally a 00100 // pass-through, but in cases when the temporary 00101 // variable type must be different than the return type 00102 // (i.e. get_temporary_type() != get_new_type()), this 00103 // might perform some operation. 00104 //////////////////////////////////////////////////////////////////// 00105 string ParameterRemapPTToPointer:: 00106 temporary_to_return(const string &temporary) { 00107 return temporary + ".p()"; 00108 } 00109