PlatformConfig.hx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package haxe.macro;
  2. import haxe.macro.Expr;
  3. /**
  4. Represents the internal structure generated with options assigned based on
  5. the target platform.
  6. Warning: `PlatformConfig` and the typedefs unique to its fields correspond to
  7. compiler-internal data structures and might change in minor Haxe releases in
  8. order to adapt to internal changes.
  9. **/
  10. typedef PlatformConfig = {
  11. /**
  12. Has a static type system, with not-nullable basic types (Int/Float/Bool)
  13. **/
  14. final staticTypeSystem:Bool;
  15. /**
  16. Has access to the "sys" package
  17. **/
  18. final sys:Bool;
  19. /**
  20. Captured variables handling (see before)
  21. **/
  22. final capturePolicy:CapturePolicy;
  23. /**
  24. When calling a method with optional args, do we replace the missing args with "null" constants
  25. **/
  26. final padNulls:Bool;
  27. /**
  28. Add a final return to methods not having one already - prevent some compiler warnings
  29. **/
  30. final addFinalReturn:Bool;
  31. /**
  32. Does the platform natively support overloaded functions
  33. **/
  34. final overloadFunctions:Bool;
  35. /**
  36. Type paths that are reserved on the platform
  37. **/
  38. final reservedTypePaths:Array<TypePath>;
  39. /**
  40. Supports function == function
  41. **/
  42. final supportsFunctionEquality:Bool;
  43. /**
  44. Uses utf16 encoding with ucs2 api
  45. **/
  46. final usesUtf16:Bool;
  47. /**
  48. Target supports accessing `this` before calling `super(...)`
  49. **/
  50. final thisBeforeSuper:Bool;
  51. /**
  52. Target supports threads
  53. **/
  54. final supportsThreads:Bool;
  55. /**
  56. Target supports Unicode
  57. **/
  58. final supportsUnicode:Bool;
  59. /**
  60. Target supports rest arguments
  61. **/
  62. final supportsRestArgs:Bool;
  63. /**
  64. Exceptions handling config
  65. **/
  66. final exceptions:ExceptionsConfig;
  67. /**
  68. The scoping of local variables
  69. **/
  70. final scoping:VarScopingConfig;
  71. /**
  72. Target supports atomic operations via haxe.Atomic
  73. **/
  74. final supportsAtomics:Bool;
  75. }
  76. enum CapturePolicy {
  77. /**
  78. Do nothing, let the platform handle it
  79. **/
  80. None;
  81. /**
  82. Wrap all captured variables into a single-element array to allow modifications
  83. **/
  84. WrapRef;
  85. /**
  86. Similar to wrap ref, but will only apply to the locals that are declared in loops
  87. **/
  88. LoopVars;
  89. }
  90. typedef VarScopingConfig = {
  91. final scope:VarScope;
  92. final flags:Array<VarScopingFlags>;
  93. }
  94. enum VarScope {
  95. FunctionScope;
  96. BlockScope;
  97. }
  98. enum VarScopingFlags {
  99. /**
  100. Variables are hoisted in their scope
  101. **/
  102. VarHoisting;
  103. /**
  104. It's not allowed to shadow existing variables in a scope.
  105. **/
  106. NoShadowing;
  107. /**
  108. It's not allowed to shadow a `catch` variable.
  109. **/
  110. NoCatchVarShadowing;
  111. /**
  112. Local vars cannot have the same name as the current top-level package or
  113. (if in the root package) current class name
  114. **/
  115. ReserveCurrentTopLevelSymbol;
  116. /**
  117. Local vars cannot have a name used for any top-level symbol
  118. (packages and classes in the root package)
  119. **/
  120. ReserveAllTopLevelSymbols;
  121. /**
  122. Reserve all type-paths converted to "flat path" with `Path.flat_path`
  123. **/
  124. ReserveAllTypesFlat;
  125. /**
  126. List of names cannot be taken by local vars
  127. **/
  128. ReserveNames(names:Array<String>);
  129. /**
  130. Cases in a `switch` won't have blocks, but will share the same outer scope.
  131. **/
  132. SwitchCasesNoBlocks;
  133. }
  134. typedef ExceptionsConfig = {
  135. /**
  136. Base types which may be thrown from Haxe code without wrapping.
  137. **/
  138. final nativeThrows:Array<TypePath>;
  139. /**
  140. Base types which may be caught from Haxe code without wrapping.
  141. **/
  142. final nativeCatches:Array<TypePath>;
  143. /**
  144. Hint exceptions filter to avoid wrapping for targets, which can throw/catch any type
  145. Ignored on targets with a specific native base type for exceptions.
  146. **/
  147. final avoidWrapping:Bool;
  148. /**
  149. Path of a native class or interface, which can be used for wildcard catches.
  150. **/
  151. final wildcardCatch:TypePath;
  152. /**
  153. Path of a native base class or interface, which can be thrown.
  154. This type is used to cast `haxe.Exception.thrown(v)` calls to.
  155. For example `throw 123` is compiled to `throw (cast Exception.thrown(123):ec_base_throw)`
  156. **/
  157. final baseThrow:TypePath;
  158. /**
  159. Checks if throwing this expression is a special case for current target
  160. and should not be modified.
  161. **/
  162. // final specialThrow:(TypedExpr)->Bool;
  163. }