JSBFunction.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #pragma once
  5. #include <Atomic/IO/Log.h>
  6. #include "JSBClass.h"
  7. #include "JSBType.h"
  8. #include "JSBSymbol.h"
  9. class JSBFunctionType
  10. {
  11. public:
  12. JSBFunctionType(JSBType* type) : type_(type)
  13. {
  14. isSharedPtr_ = false;
  15. isPointer_ = false;
  16. isReference_ = false;
  17. isTemplate_ = false;
  18. }
  19. bool isSharedPtr_;
  20. bool isPointer_;
  21. bool isReference_;
  22. bool isTemplate_;
  23. String name_;
  24. String initializer_;
  25. JSBType* type_;
  26. String ToString()
  27. {
  28. String tstring = type_->ToString();
  29. if (isPointer_)
  30. tstring += "*";
  31. if (isReference_)
  32. tstring += "&";
  33. if (name_.Length())
  34. {
  35. tstring += " " + name_;
  36. }
  37. return tstring;
  38. }
  39. String ToArgString(int index)
  40. {
  41. String tstring = type_->ToString();
  42. if (isPointer_)
  43. tstring += "*";
  44. if (isReference_ && tstring != "String")
  45. tstring += "&";
  46. if (name_.Length())
  47. {
  48. tstring.AppendWithFormat(" __arg%i", index);
  49. }
  50. return tstring;
  51. }
  52. };
  53. class JSBFunction : public JSBSymbol
  54. {
  55. public:
  56. JSBClass* class_;
  57. String name_;
  58. String propertyName_;
  59. JSBFunctionType* returnType_;
  60. Vector<JSBFunctionType*> parameters_;
  61. String docString_;
  62. bool isConstructor_;
  63. bool isDestructor_;
  64. bool isGetter_;
  65. bool isSetter_;
  66. bool isOverride_;
  67. bool skip_;
  68. int FirstDefaultParameter()
  69. {
  70. for (unsigned i = 0; i < parameters_.Size(); i++)
  71. {
  72. if (parameters_[i]->initializer_.Length())
  73. return i;
  74. }
  75. return -1;
  76. }
  77. void AddParameter(JSBFunctionType* parm)
  78. {
  79. parameters_.Push(parm);
  80. }
  81. JSBFunction(JSBClass* klass) : class_(klass), returnType_(0),
  82. isConstructor_(false), isDestructor_(false),
  83. isGetter_(false), isSetter_(false),
  84. isOverride_(false), skip_(false)
  85. {
  86. }
  87. void SetSkip(bool value) { skip_ = value; }
  88. bool Skip() { return skip_; }
  89. void Process();
  90. void WriteParameterMarshal(String& source);
  91. void WriteFunction(String& source);
  92. void WriteConstructor(String& source);
  93. void Write(String& source);
  94. void Dump()
  95. {
  96. String sig;
  97. if (!returnType_)
  98. sig += "void ";
  99. else
  100. sig += returnType_->ToString() + " ";
  101. sig += name_;
  102. sig += "(";
  103. for (unsigned i = 0; i < parameters_.Size(); i++)
  104. {
  105. sig += parameters_.At(i)->ToString();
  106. if (i != parameters_.Size() - 1)
  107. sig += ", ";
  108. }
  109. sig += ");";
  110. LOGINFOF(" %s", sig.CString());
  111. }
  112. };