JSBFunction.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "JSBFunction.h"
  23. namespace ToolCore
  24. {
  25. void JSBFunction::Process()
  26. {
  27. if (skip_)
  28. {
  29. return;
  30. }
  31. // if not already marked as a getter
  32. if (!isGetter_)
  33. {
  34. if (!parameters_.Size() && returnType_)
  35. {
  36. if (name_.Length() > 3 && name_.StartsWith("Get") && isupper(name_[3]))
  37. {
  38. String pname = name_.Substring(3);
  39. class_->SetSkipFunction(pname);
  40. isGetter_ = true;
  41. propertyName_ = pname;
  42. }
  43. }
  44. }
  45. if (!isSetter_)
  46. {
  47. if (parameters_.Size() == 1 && !returnType_)
  48. {
  49. if (name_.Length() > 3 && name_.StartsWith("Set") && isupper(name_[3]))
  50. {
  51. String pname = name_.Substring(3);
  52. class_->SetSkipFunction(pname);
  53. isSetter_ = true;
  54. propertyName_ = pname;
  55. }
  56. }
  57. }
  58. if (isGetter_)
  59. class_->AddPropertyFunction(this);
  60. if (isSetter_)
  61. class_->AddPropertyFunction(this);
  62. }
  63. bool JSBFunction::Match(JSBFunction* func)
  64. {
  65. if (func->Skip() || func->GetName() != name_)
  66. return false;
  67. if (!returnType_)
  68. {
  69. if (func->GetReturnType())
  70. return false;
  71. }
  72. else
  73. {
  74. if (!returnType_->Match(func->GetReturnType()))
  75. return false;
  76. }
  77. Vector<JSBFunctionType*>& fparams = func->GetParameters();
  78. if (parameters_.Size() != fparams.Size())
  79. return false;
  80. for ( unsigned j = 0; j < fparams.Size(); j++)
  81. {
  82. if (!parameters_[j]->Match(fparams[j]))
  83. return false;
  84. }
  85. return true;
  86. }
  87. JSBClass* JSBFunction::GetReturnClass()
  88. {
  89. if (!returnType_)
  90. return 0;
  91. if (!returnType_->type_->asClassType())
  92. return 0;
  93. return returnType_->type_->asClassType()->class_;
  94. }
  95. }