HxObject.hx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (C)2005-2017 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is 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
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. package cs.internal;
  23. import cs.system.Type;
  24. import haxe.ds.Vector;
  25. private typedef StdType = std.Type;
  26. @:keep @:native('haxe.lang.HxObject')
  27. class HxObject implements IHxObject
  28. {
  29. }
  30. @:keep @:native('haxe.lang.IHxObject')
  31. interface IHxObject
  32. {
  33. }
  34. #if core_api_serialize
  35. @:meta(System.Serializable)
  36. #end
  37. @:keep @:native('haxe.lang.DynamicObject')
  38. class DynamicObject extends HxObject implements Dynamic
  39. {
  40. @:skipReflection public function toString():String
  41. {
  42. var ts = Reflect.field(this, "toString");
  43. if (ts != null)
  44. return ts();
  45. var ret = new StringBuf();
  46. ret.add("{");
  47. var first = true;
  48. for (f in Reflect.fields(this))
  49. {
  50. if( first )
  51. first = false;
  52. else
  53. ret.add(",");
  54. ret.add(" "); ret.add(f);
  55. ret.add(" : ");
  56. ret.add(Reflect.field(this, f));
  57. }
  58. if (!first) ret.add(" ");
  59. ret.add("}");
  60. return ret.toString();
  61. }
  62. }
  63. #if !erase_generics
  64. @:keep @:native('haxe.lang.IGenericObject') interface IGenericObject
  65. {
  66. }
  67. @:nativeGen @:keep @:native('haxe.lang.GenericInterface') class GenericInterface extends cs.system.Attribute
  68. {
  69. @:readOnly public var generic(default,never):cs.system.Type;
  70. public function new(generic)
  71. {
  72. super();
  73. untyped this.generic = generic;
  74. }
  75. }
  76. #end
  77. @:keep @:native('haxe.lang.Enum') @:nativeGen
  78. #if core_api_serialize
  79. @:meta(System.Serializable)
  80. #end
  81. class HxEnum {
  82. @:readOnly var _hx_index(default,never):Int;
  83. @:protected function new(index:Int) {
  84. untyped this._hx_index = index;
  85. }
  86. public function getTag():String {
  87. return throw 'Not Implemented';
  88. }
  89. public function getParams():Array<{}> {
  90. return [];
  91. }
  92. public function toString():String {
  93. return getTag();
  94. }
  95. @:protected static function paramsToString(tag:String, params:Vector<Dynamic>):String {
  96. var ret = new StringBuf();
  97. ret.add(tag);
  98. ret.add("(");
  99. var first = true;
  100. for (p in params)
  101. {
  102. if (first)
  103. first = false;
  104. else
  105. ret.add(",");
  106. ret.add(p);
  107. }
  108. ret.add(")");
  109. return ret.toString();
  110. }
  111. @:protected static function paramsGetHashCode(index:Int, params:Vector<Dynamic>):Int {
  112. var h:Int = 19;
  113. if (params != null) for (p in params)
  114. {
  115. h = h * 31;
  116. if (p != null)
  117. untyped h += p.GetHashCode();
  118. }
  119. h += index;
  120. return h;
  121. }
  122. }