parameterRemapConcreteToPointer.cxx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Filename: parameterRemapConcreteToPointer.C
  2. // Created by: drose (01Aug00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. #include "parameterRemapConcreteToPointer.h"
  6. #include "interrogate.h"
  7. #include "interrogateBuilder.h"
  8. #include "typeManager.h"
  9. #include <cppType.h>
  10. #include <cppDeclaration.h>
  11. #include <cppConstType.h>
  12. #include <cppPointerType.h>
  13. ////////////////////////////////////////////////////////////////////
  14. // Function: ParameterRemapConcreteToPointer::Constructor
  15. // Access: Public
  16. // Description:
  17. ////////////////////////////////////////////////////////////////////
  18. ParameterRemapConcreteToPointer::
  19. ParameterRemapConcreteToPointer(CPPType *orig_type) :
  20. ParameterRemap(orig_type)
  21. {
  22. _new_type = TypeManager::wrap_pointer(orig_type);
  23. }
  24. ////////////////////////////////////////////////////////////////////
  25. // Function: ParameterRemapConcreteToPointer::pass_parameter
  26. // Access: Public, Virtual
  27. // Description: Outputs an expression that converts the indicated
  28. // variable from the new type to the original type, for
  29. // passing into the actual C++ function.
  30. ////////////////////////////////////////////////////////////////////
  31. void ParameterRemapConcreteToPointer::
  32. pass_parameter(ostream &out, const string &variable_name) {
  33. out << "*" << variable_name;
  34. }
  35. ////////////////////////////////////////////////////////////////////
  36. // Function: ParameterRemapConcreteToPointer::get_return_expr
  37. // Access: Public, Virtual
  38. // Description: Returns an expression that evalutes to the
  39. // appropriate value type for returning from the
  40. // function, given an expression of the original type.
  41. ////////////////////////////////////////////////////////////////////
  42. string ParameterRemapConcreteToPointer::
  43. get_return_expr(const string &expression) {
  44. return
  45. "new " + _orig_type->get_local_name(&parser) +
  46. "(" + expression + ")";
  47. }
  48. ////////////////////////////////////////////////////////////////////
  49. // Function: ParameterRemapConcreteToPointer::return_value_needs_management
  50. // Access: Public, Virtual
  51. // Description: Returns true if the return value represents a value
  52. // that was newly allocated, and hence must be
  53. // explicitly deallocated later by the caller.
  54. ////////////////////////////////////////////////////////////////////
  55. bool ParameterRemapConcreteToPointer::
  56. return_value_needs_management() {
  57. return true;
  58. }
  59. ////////////////////////////////////////////////////////////////////
  60. // Function: ParameterRemapConcreteToPointer::get_return_value_destructor
  61. // Access: Public, Virtual
  62. // Description: If return_value_needs_management() returns true, this
  63. // should return the index of the function that should
  64. // be called when it is time to destruct the return
  65. // value. It will generally be the same as the
  66. // destructor for the class we just returned a pointer
  67. // to.
  68. ////////////////////////////////////////////////////////////////////
  69. FunctionIndex ParameterRemapConcreteToPointer::
  70. get_return_value_destructor() {
  71. return builder.get_destructor_for(_orig_type);
  72. }
  73. ////////////////////////////////////////////////////////////////////
  74. // Function: ParameterRemapConcreteToPointer::return_value_should_be_simple
  75. // Access: Public, Virtual
  76. // Description: This is a hack around a problem VC++ has with
  77. // overly-complex expressions, particularly in
  78. // conjunction with the 'new' operator. If this
  79. // parameter type is one that will probably give VC++ a
  80. // headache, this should be set true to indicate that
  81. // the code generator should save the return value
  82. // expression into a temporary variable first, and pass
  83. // the temporary variable name in instead.
  84. ////////////////////////////////////////////////////////////////////
  85. bool ParameterRemapConcreteToPointer::
  86. return_value_should_be_simple() {
  87. return true;
  88. }