ranger-compiler 2.1.69 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (363) hide show
  1. package/CHANGELOG.md +103 -0
  2. package/README.md +991 -96
  3. package/{compiler/Lang.clj → dist/Lang.rgr} +2345 -75
  4. package/dist/README.md +116 -0
  5. package/dist/{bin/api.d.ts → api.d.ts} +430 -154
  6. package/dist/api.js +34345 -0
  7. package/{lib/Ajax.clj → dist/lib/Ajax.rgr} +1 -1
  8. package/{lib/CmdParams.clj → dist/lib/CmdParams.rgr} +72 -72
  9. package/{lib/Crypto.clj → dist/lib/Crypto.rgr} +1 -1
  10. package/{lib/DOMLib.clj → dist/lib/DOMLib.rgr} +2 -2
  11. package/{lib/Engine3D.clj → dist/lib/Engine3D.rgr} +1 -1
  12. package/{lib/ImmutableVector.clj → dist/lib/ImmutableVector.rgr} +364 -364
  13. package/{lib/IndexedDB.clj → dist/lib/IndexedDB.rgr} +1 -1
  14. package/{lib/JSON.clj → dist/lib/JSON.rgr} +105 -2
  15. package/{lib/JinxProcess.clj → dist/lib/JinxProcess.rgr} +3 -3
  16. package/{lib/Storage.clj → dist/lib/Storage.rgr} +1 -1
  17. package/{lib/Timers.clj → dist/lib/Timers.rgr} +176 -170
  18. package/{lib/ViewLib.clj → dist/lib/ViewLib.rgr} +1 -1
  19. package/dist/lib/lib/ACEEditor.rgr +5 -0
  20. package/dist/lib/lib/Ajax.rgr +196 -0
  21. package/dist/lib/lib/CmdParams.rgr +72 -0
  22. package/dist/lib/lib/Crypto.rgr +90 -0
  23. package/dist/lib/lib/DOMLib.rgr +307 -0
  24. package/{examples/3D/Engine3D.clj → dist/lib/lib/Engine3D.rgr} +870 -857
  25. package/dist/lib/lib/ImmutableVector.rgr +364 -0
  26. package/dist/lib/lib/IndexedDB.rgr +32 -0
  27. package/{compiler/JSON.clj → dist/lib/lib/JSON.rgr} +106 -3
  28. package/dist/lib/lib/JinxProcess.rgr +838 -0
  29. package/dist/lib/lib/SQL.rgr +44 -0
  30. package/dist/lib/lib/ServiceLib.rgr +9 -0
  31. package/dist/lib/lib/Storage.rgr +89 -0
  32. package/dist/lib/lib/Time.rgr +75 -0
  33. package/dist/lib/lib/Timers.rgr +176 -0
  34. package/dist/lib/lib/TypedArrays.rgr +14 -0
  35. package/dist/lib/lib/ViewLib.rgr +851 -0
  36. package/dist/lib/lib/WebLib.rgr +47 -0
  37. package/dist/lib/lib/WebServerLib.rgr +137 -0
  38. package/{lib/ranger-dir.clj → dist/lib/lib/ranger-dir.rgr} +1 -1
  39. package/{compiler/stdlib.clj → dist/lib/lib/stdlib.rgr} +42 -19
  40. package/{lib/stdops.clj → dist/lib/lib/stdops.rgr} +1 -1
  41. package/dist/lib/ranger-dir.rgr +175 -0
  42. package/{lib/stdlib.clj → dist/lib/stdlib.rgr} +2 -2
  43. package/dist/lib/stdops.rgr +168 -0
  44. package/dist/package.json +47 -0
  45. package/{bin/output.js → dist/rgrc.js} +15377 -7935
  46. package/dist/stdops.rgr +168 -0
  47. package/package.json +196 -38
  48. package/adventofcode/day1/bin/LambdaSignature1.java +0 -3
  49. package/adventofcode/day1/bin/LambdaSignature2.java +0 -3
  50. package/adventofcode/day1/bin/LambdaSignature3.java +0 -3
  51. package/adventofcode/day1/bin/day1.cpp +0 -124
  52. package/adventofcode/day1/bin/day1.go +0 -75
  53. package/adventofcode/day1/bin/day1.js +0 -45
  54. package/adventofcode/day1/bin/day1.php +0 -46
  55. package/adventofcode/day1/bin/day1.scala +0 -48
  56. package/adventofcode/day1/bin/day1.swift +0 -48
  57. package/adventofcode/day1/bin/day1_part2.cpp +0 -180
  58. package/adventofcode/day1/bin/day1_part2.go +0 -123
  59. package/adventofcode/day1/bin/day1_part2.js +0 -76
  60. package/adventofcode/day1/bin/day1_part2.php +0 -88
  61. package/adventofcode/day1/bin/day1_part2.scala +0 -81
  62. package/adventofcode/day1/bin/day1_part2.swift +0 -91
  63. package/adventofcode/day1/bin/day_one.java +0 -38
  64. package/adventofcode/day1/bin/day_one_part_two.java +0 -57
  65. package/adventofcode/day1/bin/operatorsOf.java +0 -37
  66. package/adventofcode/day1/bin/operatorsOf_5.java +0 -10
  67. package/adventofcode/day1/bin/operatorsOfboolean_5.java +0 -10
  68. package/adventofcode/day1/bin/variant.hpp +0 -2416
  69. package/adventofcode/day1/compile.bat +0 -7
  70. package/adventofcode/day1/compile2.bat +0 -7
  71. package/adventofcode/day1/day1.clj +0 -19
  72. package/adventofcode/day1/day1_part2.clj +0 -43
  73. package/adventofcode/day1/input1.txt +0 -1
  74. package/adventofcode/day2/bin/LambdaSignature1.class +0 -0
  75. package/adventofcode/day2/bin/LambdaSignature1.java +0 -3
  76. package/adventofcode/day2/bin/LambdaSignature2.class +0 -0
  77. package/adventofcode/day2/bin/LambdaSignature2.java +0 -3
  78. package/adventofcode/day2/bin/day2.cpp +0 -133
  79. package/adventofcode/day2/bin/day2.go +0 -85
  80. package/adventofcode/day2/bin/day2.js +0 -45
  81. package/adventofcode/day2/bin/day2.php +0 -59
  82. package/adventofcode/day2/bin/day2.scala +0 -54
  83. package/adventofcode/day2/bin/day2.swift +0 -62
  84. package/adventofcode/day2/bin/day2_part2.cpp +0 -150
  85. package/adventofcode/day2/bin/day2_part2.go +0 -101
  86. package/adventofcode/day2/bin/day2_part2.js +0 -54
  87. package/adventofcode/day2/bin/day2_part2.php +0 -80
  88. package/adventofcode/day2/bin/day2_part2.scala +0 -68
  89. package/adventofcode/day2/bin/day2_part2.swift +0 -82
  90. package/adventofcode/day2/bin/day_two.java +0 -61
  91. package/adventofcode/day2/bin/day_two_part_two$1$1$1.class +0 -0
  92. package/adventofcode/day2/bin/day_two_part_two$1$1.class +0 -0
  93. package/adventofcode/day2/bin/day_two_part_two$1.class +0 -0
  94. package/adventofcode/day2/bin/day_two_part_two.class +0 -0
  95. package/adventofcode/day2/bin/day_two_part_two.java +0 -80
  96. package/adventofcode/day2/bin/operatorsOf.class +0 -0
  97. package/adventofcode/day2/bin/operatorsOf.java +0 -18
  98. package/adventofcode/day2/bin/variant.hpp +0 -2416
  99. package/adventofcode/day2/compile.bat +0 -7
  100. package/adventofcode/day2/compile2.bat +0 -7
  101. package/adventofcode/day2/day2.clj +0 -60
  102. package/adventofcode/day2/day2_part2.clj +0 -69
  103. package/adventofcode/day2/input1.txt +0 -1
  104. package/adventofcode/day3/bin/Grid.java +0 -92
  105. package/adventofcode/day3/bin/GridRow.java +0 -5
  106. package/adventofcode/day3/bin/LambdaSignature1.java +0 -3
  107. package/adventofcode/day3/bin/LambdaSignature2.java +0 -3
  108. package/adventofcode/day3/bin/LambdaSignature3.java +0 -3
  109. package/adventofcode/day3/bin/day3.cpp +0 -64
  110. package/adventofcode/day3/bin/day3.go +0 -55
  111. package/adventofcode/day3/bin/day3.js +0 -42
  112. package/adventofcode/day3/bin/day3.php +0 -41
  113. package/adventofcode/day3/bin/day3.scala +0 -52
  114. package/adventofcode/day3/bin/day3.swift +0 -43
  115. package/adventofcode/day3/bin/day3_part2.cpp +0 -216
  116. package/adventofcode/day3/bin/day3_part2.go +0 -188
  117. package/adventofcode/day3/bin/day3_part2.js +0 -123
  118. package/adventofcode/day3/bin/day3_part2.php +0 -135
  119. package/adventofcode/day3/bin/day3_part2.swift +0 -131
  120. package/adventofcode/day3/bin/day_three_part_two.java +0 -43
  121. package/adventofcode/day3/bin/day_two.java +0 -42
  122. package/adventofcode/day3/bin/operatorsOf.java +0 -14
  123. package/adventofcode/day3/bin/variant.hpp +0 -2416
  124. package/adventofcode/day3/compile.bat +0 -7
  125. package/adventofcode/day3/compile2.bat +0 -7
  126. package/adventofcode/day3/day3.clj +0 -42
  127. package/adventofcode/day3/day3_part2.clj +0 -112
  128. package/adventofcode/day4/bin/LambdaSignature1.java +0 -3
  129. package/adventofcode/day4/bin/day4.cpp +0 -118
  130. package/adventofcode/day4/bin/day4.go +0 -75
  131. package/adventofcode/day4/bin/day4.js +0 -40
  132. package/adventofcode/day4/bin/day4.php +0 -52
  133. package/adventofcode/day4/bin/day4.scala +0 -47
  134. package/adventofcode/day4/bin/day4.swift +0 -56
  135. package/adventofcode/day4/bin/day4_part2.go +0 -129
  136. package/adventofcode/day4/bin/day4_part2.js +0 -72
  137. package/adventofcode/day4/bin/day_four.java +0 -41
  138. package/adventofcode/day4/bin/inputData.java +0 -7
  139. package/adventofcode/day4/bin/operatorsOf.java +0 -11
  140. package/adventofcode/day4/bin/variant.hpp +0 -2416
  141. package/adventofcode/day4/compile.bat +0 -7
  142. package/adventofcode/day4/compile2.bat +0 -7
  143. package/adventofcode/day4/day4.clj +0 -32
  144. package/adventofcode/day4/day4_part2.clj +0 -44
  145. package/adventofcode/day4/input.clj +0 -519
  146. package/adventofcode/day4/input.txt +0 -512
  147. package/bin/api.ts +0 -24471
  148. package/bin/compiler.ts +0 -24482
  149. package/compiler/ColorConsole.clj +0 -22
  150. package/compiler/ContextOperators.clj +0 -75
  151. package/compiler/FlowEnterVarDef.clj +0 -223
  152. package/compiler/InputFileSystem.clj +0 -276
  153. package/compiler/RangerDocs.clj +0 -7
  154. package/compiler/TFactory.clj +0 -146
  155. package/compiler/TFiles.clj +0 -23
  156. package/compiler/TFlow.clj +0 -39
  157. package/compiler/TNodeFactory.clj +0 -84
  158. package/compiler/TTypes.clj +0 -188
  159. package/compiler/VirtualCompiler.clj +0 -800
  160. package/compiler/bin/ng_Compiler.js +0 -23779
  161. package/compiler/commonmark_plugin.clj +0 -359
  162. package/compiler/feat2.bat +0 -2
  163. package/compiler/feats.bat +0 -9
  164. package/compiler/feature_tests.clj +0 -192
  165. package/compiler/index.js +0 -2
  166. package/compiler/issue_57.clj +0 -25
  167. package/compiler/makefile_plugin.clj +0 -135
  168. package/compiler/markdown_plugin.clj +0 -386
  169. package/compiler/maven_plugin.clj +0 -162
  170. package/compiler/ng_AndroidPageWriter.clj +0 -299
  171. package/compiler/ng_CodeNode.clj +0 -756
  172. package/compiler/ng_CodeNodeCompilerExtensions.clj +0 -839
  173. package/compiler/ng_Compiler.clj +0 -49
  174. package/compiler/ng_CompilerGeneric.clj +0 -260
  175. package/compiler/ng_CompilerOrig.clj +0 -854
  176. package/compiler/ng_DictNode.clj +0 -346
  177. package/compiler/ng_DictNode2.clj +0 -316
  178. package/compiler/ng_Execute.clj +0 -138
  179. package/compiler/ng_Execute1.clj +0 -129
  180. package/compiler/ng_FlowWork.clj +0 -3951
  181. package/compiler/ng_LiveCompiler.clj +0 -1109
  182. package/compiler/ng_RagnerJavaScriptClassWriter.clj +0 -402
  183. package/compiler/ng_RangerActiveOperators.clj +0 -86
  184. package/compiler/ng_RangerAppClassDesc.clj +0 -400
  185. package/compiler/ng_RangerAppEnums.clj +0 -86
  186. package/compiler/ng_RangerAppFunctionDesc.clj +0 -127
  187. package/compiler/ng_RangerAppMessages.clj +0 -15
  188. package/compiler/ng_RangerAppOperatorDesc.clj +0 -20
  189. package/compiler/ng_RangerAppParamDesc.clj +0 -388
  190. package/compiler/ng_RangerAppWriterContext.clj +0 -1793
  191. package/compiler/ng_RangerArgMatch.clj +0 -638
  192. package/compiler/ng_RangerCSharpClassWriter.clj +0 -484
  193. package/compiler/ng_RangerCppClassWriter.clj +0 -1023
  194. package/compiler/ng_RangerDocGenerator.clj +0 -305
  195. package/compiler/ng_RangerFlowParser.clj +0 -4992
  196. package/compiler/ng_RangerFlowParserOrig.clj +0 -4002
  197. package/compiler/ng_RangerGenericClassWriter.clj +0 -573
  198. package/compiler/ng_RangerGolangClassWriter.clj +0 -1766
  199. package/compiler/ng_RangerImmutableExtension.clj +0 -77
  200. package/compiler/ng_RangerJava7ClassWriter.clj +0 -961
  201. package/compiler/ng_RangerJavaScriptClassWriter.clj +0 -1042
  202. package/compiler/ng_RangerKotlinClassWriter.clj +0 -372
  203. package/compiler/ng_RangerLanguageWriters.clj +0 -14
  204. package/compiler/ng_RangerLispParser.clj +0 -873
  205. package/compiler/ng_RangerPHPClassWriter.clj +0 -643
  206. package/compiler/ng_RangerPlugin.clj +0 -41
  207. package/compiler/ng_RangerRangerClassWriter.clj +0 -357
  208. package/compiler/ng_RangerRustClassWriter.clj +0 -420
  209. package/compiler/ng_RangerScalaClassWriter.clj +0 -818
  210. package/compiler/ng_RangerSerializeClass.clj +0 -502
  211. package/compiler/ng_RangerServiceBuilder.clj +0 -63
  212. package/compiler/ng_RangerSwift3ClassWriter.clj +0 -809
  213. package/compiler/ng_RangerSwiftClassWriter.clj +0 -0
  214. package/compiler/ng_RangerTypeClass.clj +0 -45
  215. package/compiler/ng_SourceParser.clj +0 -241
  216. package/compiler/ng_SourceParser2.clj +0 -214
  217. package/compiler/ng_WebPageWriter.clj +0 -39
  218. package/compiler/ng_jsonParser.clj +0 -340
  219. package/compiler/ng_p_test.clj +0 -1711
  220. package/compiler/ng_parser.clj +0 -911
  221. package/compiler/ng_parser2.clj +0 -735
  222. package/compiler/ng_parser2_backup.clj +0 -1679
  223. package/compiler/ng_parser_backup.clj +0 -886
  224. package/compiler/ng_parser_ok.clj +0 -1718
  225. package/compiler/ng_parser_ok2.clj +0 -1717
  226. package/compiler/ng_parser_std_match.clj +0 -687
  227. package/compiler/ng_parser_std_match2.clj +0 -1012
  228. package/compiler/ng_parser_v2.clj +0 -1251
  229. package/compiler/ng_ui.clj +0 -403
  230. package/compiler/ng_ui_test.clj +0 -18
  231. package/compiler/ng_writer.clj +0 -338
  232. package/compiler/ng_xmlParser.clj +0 -472
  233. package/compiler/ng_xmlParser2.clj +0 -317
  234. package/compiler/ng_xmlParser3.clj +0 -251
  235. package/compiler/opdoc.bat +0 -4
  236. package/compiler/operators.md +0 -290
  237. package/compiler/p.bat +0 -4
  238. package/compiler/package.json +0 -10
  239. package/compiler/pcmd.bat +0 -4
  240. package/compiler/pcmd2.bat +0 -3
  241. package/compiler/plaintext_plugin.clj +0 -69
  242. package/compiler/plugin.bat +0 -19
  243. package/compiler/plugin2.bat +0 -4
  244. package/compiler/plugin_app.bat +0 -3
  245. package/compiler/plugin_apps.clj +0 -27
  246. package/compiler/plugins.bat +0 -10
  247. package/compiler/reveal_plugin.clj +0 -409
  248. package/compiler/simplePlugin.clj +0 -780
  249. package/compiler/t.bat +0 -3
  250. package/compiler/test_any.clj +0 -43
  251. package/compiler/test_call.clj +0 -141
  252. package/compiler/test_chain.clj +0 -79
  253. package/compiler/test_json.clj +0 -10
  254. package/compiler/test_lambda.clj +0 -153
  255. package/compiler/test_pcmd.clj +0 -32
  256. package/compiler/test_pcmd2.clj +0 -29
  257. package/compiler/test_plugin.clj +0 -237
  258. package/compiler/test_readfile.clj +0 -13
  259. package/compiler/test_reveal.clj +0 -19
  260. package/compiler/test_slides.clj +0 -312
  261. package/compiler/test_types.clj +0 -143
  262. package/compiler/test_types2.clj +0 -49
  263. package/compiler/test_types3.clj +0 -53
  264. package/compiler/test_var.clj +0 -40
  265. package/compiler/tonpm.bat +0 -14
  266. package/compiler/tonpm2.bat +0 -12
  267. package/compiler/ui_plugin.clj +0 -507
  268. package/compiler/ui_plugin2.clj +0 -427
  269. package/compiler/update-git.bat +0 -3
  270. package/compiler/vcomp.bat +0 -4
  271. package/compiler/viewbuilder_Android.clj +0 -176
  272. package/compiler/viewbuilder_Web.clj +0 -105
  273. package/dist/bin/api.js +0 -32422
  274. package/dist/bin/api.js.map +0 -1
  275. package/dist/bin/compiler.d.ts +0 -1638
  276. package/dist/bin/compiler.js +0 -32444
  277. package/dist/bin/compiler.js.map +0 -1
  278. package/examples/3D/bin/test_3d.js +0 -329
  279. package/examples/3D/test_3d.clj +0 -385
  280. package/examples/EVGColor/EVGColor.clj +0 -310
  281. package/examples/EVGColor/EVGColorContext.clj +0 -176
  282. package/examples/EVGColor/bin/EVGColor.js +0 -286
  283. package/examples/EVGColor/bin/minimized.js +0 -286
  284. package/examples/SVGPath/SVGPath.clj +0 -625
  285. package/examples/SVGPath/Vec2.clj +0 -103
  286. package/examples/SVGPath/bin/SVGPath.cpp +0 -887
  287. package/examples/SVGPath/bin/SVGPath.js +0 -682
  288. package/examples/SVGPath/bin/minimized.js +0 -578
  289. package/examples/SVGPath/bin/variant.hpp +0 -2416
  290. package/examples/minification/Vec2.clj +0 -103
  291. package/examples/minification/bin/minified.js +0 -44
  292. package/examples/minification/bin/test.js +0 -117
  293. package/examples/minification/test.clj +0 -13
  294. package/fiddle/VirtualCompiler.js +0 -23495
  295. package/fiddle/browser_editor.js +0 -13240
  296. package/fiddle/compileEnv.js +0 -1
  297. package/fiddle/compileEnv.json +0 -1
  298. package/fiddle/lang_data.js +0 -1
  299. package/index.html +0 -18
  300. package/native/httpd/HttpTester.clj +0 -33
  301. package/native/httpd/RangerWebService.clj +0 -81
  302. package/operators.md +0 -290
  303. package/tsconfig.json +0 -29
  304. package/versions/cpp/compiler.cpp +0 -15032
  305. package/versions/es6/compiler.js +0 -12860
  306. package/versions/go/compiler.go +0 -21338
  307. package/versions/java/AfterCodeNode.java +0 -4
  308. package/versions/java/ClassJoinPoint.java +0 -6
  309. package/versions/java/CodeFile.java +0 -42
  310. package/versions/java/CodeFileSystem.java +0 -72
  311. package/versions/java/CodeNode.java +0 -807
  312. package/versions/java/CodeSlice.java +0 -13
  313. package/versions/java/CodeWriter.java +0 -185
  314. package/versions/java/ColorConsole.java +0 -8
  315. package/versions/java/CompilerInterface.java +0 -213
  316. package/versions/java/DictNode.java +0 -353
  317. package/versions/java/LiveCompiler.java +0 -772
  318. package/versions/java/NodeEvalState.java +0 -24
  319. package/versions/java/OpFindResult.java +0 -6
  320. package/versions/java/RangerAppArrayValue.java +0 -7
  321. package/versions/java/RangerAppClassDesc.java +0 -217
  322. package/versions/java/RangerAppEnum.java +0 -14
  323. package/versions/java/RangerAppFunctionDesc.java +0 -20
  324. package/versions/java/RangerAppHashValue.java +0 -11
  325. package/versions/java/RangerAppInterfaceImpl.java +0 -6
  326. package/versions/java/RangerAppMethodVariants.java +0 -6
  327. package/versions/java/RangerAppParamDesc.java +0 -321
  328. package/versions/java/RangerAppTodo.java +0 -6
  329. package/versions/java/RangerAppValue.java +0 -10
  330. package/versions/java/RangerAppWriterContext.java +0 -800
  331. package/versions/java/RangerArgMatch.java +0 -317
  332. package/versions/java/RangerBackReference.java +0 -7
  333. package/versions/java/RangerCSharpClassWriter.java +0 -287
  334. package/versions/java/RangerCompilerMessage.java +0 -9
  335. package/versions/java/RangerCppClassWriter.java +0 -725
  336. package/versions/java/RangerFlowParser.java +0 -2142
  337. package/versions/java/RangerGenericClassWriter.java +0 -367
  338. package/versions/java/RangerGolangClassWriter.java +0 -1379
  339. package/versions/java/RangerJava7ClassWriter.java +0 -652
  340. package/versions/java/RangerJavaScriptClassWriter.java +0 -305
  341. package/versions/java/RangerKotlinClassWriter.java +0 -380
  342. package/versions/java/RangerLispParser.java +0 -845
  343. package/versions/java/RangerNodeValue.java +0 -9
  344. package/versions/java/RangerPHPClassWriter.java +0 -527
  345. package/versions/java/RangerParamEventHandler.java +0 -6
  346. package/versions/java/RangerParamEventList.java +0 -5
  347. package/versions/java/RangerParamEventMap.java +0 -27
  348. package/versions/java/RangerRangerClassWriter.java +0 -268
  349. package/versions/java/RangerRefForce.java +0 -7
  350. package/versions/java/RangerScalaClassWriter.java +0 -365
  351. package/versions/java/RangerSerializeClass.java +0 -148
  352. package/versions/java/RangerSwift3ClassWriter.java +0 -548
  353. package/versions/java/RangerTypeClass.java +0 -17
  354. package/versions/java/SourceCode.java +0 -65
  355. package/versions/php/compiler.php +0 -13830
  356. package/versions/swift3/compiler.swift +0 -12542
  357. /package/{lib/ACEEditor.clj → dist/lib/ACEEditor.rgr} +0 -0
  358. /package/{lib/SQL.clj → dist/lib/SQL.rgr} +0 -0
  359. /package/{lib/ServiceLib.clj → dist/lib/ServiceLib.rgr} +0 -0
  360. /package/{lib/Time.clj → dist/lib/Time.rgr} +0 -0
  361. /package/{lib/TypedArrays.clj → dist/lib/TypedArrays.rgr} +0 -0
  362. /package/{lib/WebLib.clj → dist/lib/WebLib.rgr} +0 -0
  363. /package/{lib/WebServerLib.clj → dist/lib/WebServerLib.rgr} +0 -0
@@ -1,2142 +0,0 @@
1
- import java.util.Optional;
2
- import java.util.*;
3
- import java.io.*;
4
- import java.nio.file.Paths;
5
- import java.io.File;
6
- import java.nio.file.Files;
7
- import java.nio.charset.Charset;
8
- import java.nio.charset.StandardCharsets;
9
-
10
- class RangerFlowParser {
11
-
12
- static String readFile(String path, Charset encoding)
13
- {
14
- try {
15
- byte[] encoded = Files.readAllBytes(Paths.get(path));
16
- return new String(encoded, encoding);
17
- } catch(IOException e) {
18
- return "";
19
- }
20
- }
21
-
22
- public Optional<CodeNode> stdCommands = Optional.empty();
23
- public Optional<CodeNode> lastProcessedNode = Optional.empty();
24
- public ArrayList<CodeNode> collectWalkAtEnd = new ArrayList<CodeNode>() /** note: unused */;
25
- public ArrayList<CodeNode> walkAlso = new ArrayList<CodeNode>();
26
- public ArrayList<RangerAppClassDesc> serializedClasses = new ArrayList<RangerAppClassDesc>();
27
- public ArrayList<ClassJoinPoint> classesWithTraits = new ArrayList<ClassJoinPoint>();
28
- public ArrayList<RangerAppClassDesc> collectedIntefaces = new ArrayList<RangerAppClassDesc>();
29
- public HashMap<String,Boolean> definedInterfaces = new HashMap<String,Boolean>() /** note: unused */;
30
-
31
- public void cmdEnum( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
32
- final CodeNode fNameNode = node.children.get(1);
33
- final CodeNode enumList = node.children.get(2);
34
- final RangerAppEnum new_enum = new RangerAppEnum();
35
- for ( int i = 0; i < enumList.children.size(); i++) {
36
- CodeNode item = enumList.children.get(i);
37
- new_enum.add(item.vref);
38
- }
39
- ctx.definedEnums.put(fNameNode.vref, new_enum);
40
- }
41
-
42
- public void initStdCommands() {
43
- }
44
-
45
- public Optional<CodeNode> findLanguageOper( CodeNode details , RangerAppWriterContext ctx ) {
46
- final String langName = ctx.getTargetLang();
47
- for ( int i = 0; i < details.children.size(); i++) {
48
- CodeNode det = details.children.get(i);
49
- if ( (det.children.size()) > 0 ) {
50
- final CodeNode fc = det.children.get(0);
51
- if ( fc.vref.equals("templates") ) {
52
- final CodeNode tplList = det.children.get(1);
53
- for ( int i_1 = 0; i_1 < tplList.children.size(); i_1++) {
54
- CodeNode tpl = tplList.children.get(i_1);
55
- final CodeNode tplName = tpl.getFirst();
56
- Optional<CodeNode> tplImpl = Optional.empty();
57
- tplImpl = Optional.of(tpl.getSecond());
58
- if ( (!tplName.vref.equals("*")) && (!tplName.vref.equals(langName)) ) {
59
- continue;
60
- }
61
- Optional<CodeNode> rv = Optional.empty();
62
- rv = Optional.of(tpl);
63
- return Optional.ofNullable((rv.isPresent() ? (CodeNode)rv.get() : null ) );
64
- }
65
- }
66
- }
67
- }
68
- final Optional<CodeNode> none = Optional.empty();
69
- return Optional.ofNullable((none.isPresent() ? (CodeNode)none.get() : null ) );
70
- }
71
-
72
- public CodeNode buildMacro( Optional<CodeNode> langOper , CodeNode args , RangerAppWriterContext ctx ) {
73
- final RangerAppWriterContext subCtx = ctx.fork();
74
- final CodeWriter wr = new CodeWriter();
75
- final LiveCompiler lcc = new LiveCompiler();
76
- lcc.langWriter = Optional.of(new RangerRangerClassWriter());
77
- lcc.langWriter.get().compiler = Optional.of(lcc);
78
- subCtx.targetLangName = "ranger";
79
- subCtx.restartExpressionLevel();
80
- final CodeNode macroNode = langOper.get();
81
- final CodeNode cmdList = macroNode.getSecond();
82
- lcc.walkCommandList(cmdList, args, subCtx, wr);
83
- final String lang_str = wr.getCode();
84
- final SourceCode lang_code = new SourceCode(lang_str);
85
- lang_code.filename = ("<macro " + macroNode.vref) + ">";
86
- final RangerLispParser lang_parser = new RangerLispParser(lang_code);
87
- lang_parser.parse();
88
- final CodeNode node = lang_parser.rootNode.get();
89
- return node;
90
- }
91
-
92
- public boolean stdParamMatch( CodeNode callArgs , RangerAppWriterContext inCtx , CodeWriter wr ) {
93
- stdCommands = Optional.of(inCtx.getStdCommands());
94
- final CodeNode callFnName = callArgs.getFirst();
95
- final Optional<CodeNode> cmds = stdCommands;
96
- boolean some_matched = false;
97
- /** unused: final boolean found_fn = false **/ ;
98
- /** unused: final ArrayList<String> missed_args = new ArrayList<String>() **/ ;
99
- RangerAppWriterContext ctx = inCtx.fork();
100
- /** unused: final String lang_name = ctx.getTargetLang() **/ ;
101
- boolean expects_error = false;
102
- final int err_cnt = inCtx.getErrorCount();
103
- if ( callArgs.hasBooleanProperty("error") ) {
104
- expects_error = true;
105
- }
106
- for ( int main_index = 0; main_index < cmds.get().children.size(); main_index++) {
107
- CodeNode ch = cmds.get().children.get(main_index);
108
- final CodeNode fc = ch.getFirst();
109
- final CodeNode nameNode = ch.getSecond();
110
- final CodeNode args = ch.getThird();
111
- if ( callFnName.vref.equals(fc.vref) ) {
112
- /** unused: final int line_index = callArgs.getLine() **/ ;
113
- final int callerArgCnt = (callArgs.children.size()) - 1;
114
- final int fnArgCnt = args.children.size();
115
- boolean has_eval_ctx = false;
116
- boolean is_macro = false;
117
- if ( nameNode.hasFlag("newcontext") ) {
118
- ctx = inCtx.fork();
119
- has_eval_ctx = true;
120
- }
121
- final boolean expanding_node = nameNode.hasFlag("expands");
122
- if ( (callerArgCnt == fnArgCnt) || expanding_node ) {
123
- final CodeNode details_list = ch.children.get(3);
124
- final Optional<CodeNode> langOper = this.findLanguageOper(details_list, ctx);
125
- if ( !langOper.isPresent() ) {
126
- continue;
127
- }
128
- if ( langOper.get().hasBooleanProperty("macro") ) {
129
- is_macro = true;
130
- }
131
- final RangerArgMatch match = new RangerArgMatch();
132
- int last_walked = 0;
133
- for ( int i = 0; i < args.children.size(); i++) {
134
- CodeNode arg = args.children.get(i);
135
- final CodeNode callArg = callArgs.children.get((i + 1));
136
- if ( arg.hasFlag("define") ) {
137
- final RangerAppParamDesc p = new RangerAppParamDesc();
138
- p.name = callArg.vref;
139
- p.value_type = arg.value_type;
140
- p.node = Optional.of(callArg);
141
- p.nameNode = Optional.of(callArg);
142
- p.is_optional = false;
143
- p.init_cnt = 1;
144
- ctx.defineVariable(p.name, p);
145
- callArg.hasParamDesc = true;
146
- callArg.ownParamDesc = Optional.of(p);
147
- callArg.paramDesc = Optional.of(p);
148
- if ( (callArg.type_name.length()) == 0 ) {
149
- callArg.type_name = arg.type_name;
150
- callArg.value_type = arg.value_type;
151
- }
152
- callArg.eval_type = arg.value_type;
153
- callArg.eval_type_name = arg.type_name;
154
- }
155
- if ( arg.hasFlag("ignore") ) {
156
- continue;
157
- }
158
- ctx.setInExpr();
159
- last_walked = i + 1;
160
- this.WalkNode(callArg, ctx, wr);
161
- ctx.unsetInExpr();
162
- }
163
- if ( expanding_node ) {
164
- for ( int i2 = 0; i2 < callArgs.children.size(); i2++) {
165
- CodeNode caCh = callArgs.children.get(i2);
166
- if ( i2 > last_walked ) {
167
- ctx.setInExpr();
168
- this.WalkNode(caCh, ctx, wr);
169
- ctx.unsetInExpr();
170
- }
171
- }
172
- }
173
- final boolean all_matched = match.matchArguments(args, callArgs, ctx, 1);
174
- if ( all_matched ) {
175
- if ( is_macro ) {
176
- final CodeNode macroNode = this.buildMacro(langOper, callArgs, ctx);
177
- int arg_len = callArgs.children.size();
178
- while (arg_len > 0) {
179
- callArgs.children.remove(callArgs.children.size() - 1);
180
- arg_len = arg_len - 1;
181
- }
182
- callArgs.children.add(macroNode);
183
- macroNode.parent = Optional.of(callArgs);
184
- this.WalkNode(macroNode, ctx, wr);
185
- match.setRvBasedOn(nameNode, callArgs);
186
- return true;
187
- }
188
- if ( nameNode.hasFlag("moves") ) {
189
- final Optional<CodeNode> moves_opt = nameNode.getFlag("moves");
190
- final CodeNode moves = moves_opt.get();
191
- final Optional<CodeNode> ann = moves.vref_annotation;
192
- final CodeNode from = ann.get().getFirst();
193
- final CodeNode to = ann.get().getSecond();
194
- final CodeNode cA = callArgs.children.get(from.int_value);
195
- final CodeNode cA2 = callArgs.children.get(to.int_value);
196
- if ( cA.hasParamDesc ) {
197
- final Optional<RangerAppParamDesc> pp = cA.paramDesc;
198
- final Optional<RangerAppParamDesc> pp2 = cA2.paramDesc;
199
- pp.get().moveRefTo(callArgs, pp2.get(), ctx);
200
- }
201
- }
202
- if ( nameNode.hasFlag("returns") ) {
203
- final RangerAppFunctionDesc activeFn = ctx.getCurrentMethod();
204
- if ( !activeFn.nameNode.get().type_name.equals("void") ) {
205
- if ( (callArgs.children.size()) < 2 ) {
206
- ctx.addError(callArgs, " missing return value !!!");
207
- } else {
208
- final CodeNode returnedValue = callArgs.children.get(1);
209
- if ( match.doesMatch((activeFn.nameNode.get()), returnedValue, ctx) == false ) {
210
- if ( activeFn.nameNode.get().ifNoTypeSetToEvalTypeOf(returnedValue) ) {
211
- } else {
212
- ctx.addError(returnedValue, "invalid return value type!!!");
213
- }
214
- }
215
- final CodeNode argNode = activeFn.nameNode.get();
216
- if ( returnedValue.hasFlag("optional") ) {
217
- if ( false == argNode.hasFlag("optional") ) {
218
- ctx.addError(callArgs, "function return value optionality does not match, expected non-optional return value, optional given at " + argNode.getCode());
219
- }
220
- }
221
- if ( argNode.hasFlag("optional") ) {
222
- if ( false == returnedValue.hasFlag("optional") ) {
223
- ctx.addError(callArgs, "function return value optionality does not match, expected optional return value " + argNode.getCode());
224
- }
225
- }
226
- final Optional<RangerAppParamDesc> pp_1 = returnedValue.paramDesc;
227
- if ( pp_1.isPresent() ) {
228
- pp_1.get().moveRefTo(callArgs, activeFn, ctx);
229
- }
230
- }
231
- }
232
- if ( !callArgs.parent.isPresent() ) {
233
- ctx.addError(callArgs, "did not have parent");
234
- System.out.println(String.valueOf( "no parent => " + callArgs.getCode() ) );
235
- }
236
- callArgs.parent.get().didReturnAtIndex = callArgs.parent.get().children.indexOf(callArgs);
237
- }
238
- if ( nameNode.hasFlag("returns") == false ) {
239
- match.setRvBasedOn(nameNode, callArgs);
240
- }
241
- if ( has_eval_ctx ) {
242
- callArgs.evalCtx = Optional.of(ctx);
243
- }
244
- final Optional<CodeNode> nodeP = callArgs.parent;
245
- if ( nodeP.isPresent() ) {
246
- } else {
247
- }
248
- /** unused: final String sig = nameNode.buildTypeSignatureUsingMatch(match) **/ ;
249
- some_matched = true;
250
- callArgs.has_operator = true;
251
- callArgs.op_index = main_index;
252
- for ( int arg_index = 0; arg_index < args.children.size(); arg_index++) {
253
- CodeNode arg_1 = args.children.get(arg_index);
254
- if ( arg_1.has_vref_annotation ) {
255
- final Optional<CodeNode> anns = arg_1.vref_annotation;
256
- for ( int i_1 = 0; i_1 < anns.get().children.size(); i_1++) {
257
- CodeNode ann_1 = anns.get().children.get(i_1);
258
- if ( ann_1.vref.equals("mutates") ) {
259
- final CodeNode theArg = callArgs.children.get((arg_index + 1));
260
- if ( theArg.hasParamDesc ) {
261
- theArg.paramDesc.get().set_cnt = theArg.paramDesc.get().set_cnt + 1;
262
- }
263
- }
264
- }
265
- }
266
- }
267
- break;
268
- }
269
- }
270
- }
271
- }
272
- if ( some_matched == false ) {
273
- ctx.addError(callArgs, "stdMatch -> Could not match argument types for " + callFnName.vref);
274
- }
275
- if ( expects_error ) {
276
- final int cnt_now = ctx.getErrorCount();
277
- if ( cnt_now == err_cnt ) {
278
- ctx.addParserError(callArgs, (("LANGUAGE_PARSER_ERROR: expected generated error, err counts : " + err_cnt) + " : ") + cnt_now);
279
- }
280
- } else {
281
- final int cnt_now_1 = ctx.getErrorCount();
282
- if ( cnt_now_1 > err_cnt ) {
283
- ctx.addParserError(callArgs, (("LANGUAGE_PARSER_ERROR: did not expect generated error, err counts : " + err_cnt) + " : ") + cnt_now_1);
284
- }
285
- }
286
- return true;
287
- }
288
-
289
- public boolean cmdImport( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
290
- return false;
291
- }
292
-
293
- public String getThisName() {
294
- return "this";
295
- }
296
-
297
- public void WriteThisVar( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
298
- }
299
-
300
- public void WriteVRef( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
301
- if ( node.vref.equals("_") ) {
302
- return;
303
- }
304
- final String rootObjName = node.ns.get(0);
305
- if ( ctx.isInStatic() ) {
306
- if ( rootObjName.equals("this") ) {
307
- ctx.addError(node, "This can not be used in static context");
308
- }
309
- }
310
- if ( ctx.isEnumDefined(rootObjName) ) {
311
- final String enumName = node.ns.get(1);
312
- final Optional<RangerAppEnum> ee = ctx.getEnum(rootObjName);
313
- final RangerAppEnum e = ee.get();
314
- if ( e.values.containsKey(enumName) ) {
315
- node.eval_type = 11;
316
- node.eval_type_name = rootObjName;
317
- node.int_value = (Optional.ofNullable(e.values.get(enumName))).get();
318
- } else {
319
- ctx.addError(node, (("Undefined Enum " + rootObjName) + ".") + enumName);
320
- node.eval_type = 1;
321
- }
322
- return;
323
- }
324
- if ( node.vref.equals(this.getThisName()) ) {
325
- final Optional<RangerAppClassDesc> cd = ctx.getCurrentClass();
326
- final Optional<RangerAppClassDesc> thisClassDesc = cd;
327
- node.eval_type = 8;
328
- node.eval_type_name = thisClassDesc.get().name;
329
- node.ref_type = 4;
330
- return;
331
- }
332
- if ( ctx.isCapturing() ) {
333
- if ( ctx.isVarDefined(rootObjName) ) {
334
- if ( ctx.isLocalToCapture(rootObjName) == false ) {
335
- final RangerAppParamDesc captDef = ctx.getVariableDef(rootObjName);
336
- final Optional<RangerAppClassDesc> cd_1 = ctx.getCurrentClass();
337
- cd_1.get().capturedLocals.add(captDef);
338
- captDef.is_captured = true;
339
- ctx.addCapturedVariable(rootObjName);
340
- }
341
- }
342
- }
343
- if ( (rootObjName.equals("this")) || ctx.isVarDefined(rootObjName) ) {
344
- /** unused: final RangerAppParamDesc vDef2 = ctx.getVariableDef(rootObjName) **/ ;
345
- /** unused: final RangerAppFunctionDesc activeFn = ctx.getCurrentMethod() **/ ;
346
- final Optional<RangerAppParamDesc> vDef = this.findParamDesc(node, ctx, wr);
347
- if ( vDef.isPresent() ) {
348
- node.hasParamDesc = true;
349
- node.ownParamDesc = vDef;
350
- node.paramDesc = vDef;
351
- vDef.get().ref_cnt = 1 + vDef.get().ref_cnt;
352
- final Optional<CodeNode> vNameNode = vDef.get().nameNode;
353
- if ( vNameNode.isPresent() ) {
354
- if ( vNameNode.get().hasFlag("optional") ) {
355
- node.setFlag("optional");
356
- }
357
- node.eval_type = vNameNode.get().typeNameAsType(ctx);
358
- node.eval_type_name = vNameNode.get().type_name;
359
- if ( vNameNode.get().value_type == 6 ) {
360
- node.eval_type = 6;
361
- node.eval_array_type = vNameNode.get().array_type;
362
- }
363
- if ( vNameNode.get().value_type == 7 ) {
364
- node.eval_type = 7;
365
- node.eval_key_type = vNameNode.get().key_type;
366
- node.eval_array_type = vNameNode.get().array_type;
367
- }
368
- }
369
- }
370
- } else {
371
- boolean class_or_this = rootObjName.equals(this.getThisName());
372
- if ( ctx.isDefinedClass(rootObjName) ) {
373
- class_or_this = true;
374
- node.eval_type = 23;
375
- node.eval_type_name = rootObjName;
376
- }
377
- if ( ctx.hasTemplateNode(rootObjName) ) {
378
- class_or_this = true;
379
- }
380
- if ( false == class_or_this ) {
381
- final Optional<RangerAppClassDesc> udesc = ctx.getCurrentClass();
382
- final RangerAppClassDesc desc = udesc.get();
383
- ctx.addError(node, (("Undefined variable " + rootObjName) + " in class ") + desc.name);
384
- }
385
- return;
386
- }
387
- }
388
-
389
- public void CreateClass( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
390
- }
391
-
392
- public void DefineVar( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
393
- }
394
-
395
- public void WriteComment( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
396
- }
397
-
398
- public void cmdLog( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
399
- }
400
-
401
- public void cmdDoc( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
402
- }
403
-
404
- public void cmdGitDoc( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
405
- }
406
-
407
- public void cmdNative( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
408
- }
409
-
410
- public void LangInit( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
411
- }
412
-
413
- public String getWriterLang() {
414
- return "_";
415
- }
416
-
417
- public void StartCodeWriting( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
418
- }
419
-
420
- public void Constructor( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
421
- this.shouldHaveChildCnt(3, node, ctx, "Method expexts four arguments");
422
- /** unused: final CodeNode cn = node.children.get(1) **/ ;
423
- final CodeNode fnBody = node.children.get(2);
424
- final Optional<RangerAppClassDesc> udesc = ctx.getCurrentClass();
425
- final RangerAppClassDesc desc = udesc.get();
426
- final Optional<RangerAppFunctionDesc> m = desc.constructor_fn;
427
- final RangerAppWriterContext subCtx = m.get().fnCtx.get();
428
- subCtx.is_function = true;
429
- subCtx.currentMethod = m;
430
- subCtx.setInMethod();
431
- for ( int i = 0; i < m.get().params.size(); i++) {
432
- RangerAppParamDesc v = m.get().params.get(i);
433
- subCtx.defineVariable(v.name, v);
434
- }
435
- this.WalkNodeChildren(fnBody, subCtx, wr);
436
- subCtx.unsetInMethod();
437
- if ( fnBody.didReturnAtIndex >= 0 ) {
438
- ctx.addError(node, "constructor should not return any values!");
439
- }
440
- for ( int i_1 = 0; i_1 < subCtx.localVarNames.size(); i_1++) {
441
- String n = subCtx.localVarNames.get(i_1);
442
- final Optional<RangerAppParamDesc> p = Optional.ofNullable(subCtx.localVariables.get(n));
443
- if ( p.get().set_cnt > 0 ) {
444
- final Optional<CodeNode> defNode = p.get().node;
445
- defNode.get().setFlag("mutable");
446
- final Optional<CodeNode> nNode = p.get().nameNode;
447
- nNode.get().setFlag("mutable");
448
- }
449
- }
450
- }
451
-
452
- public void WriteScalarValue( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
453
- node.eval_type = node.value_type;
454
- switch (node.value_type ) {
455
- case 2 :
456
- node.eval_type_name = "double";
457
- break;
458
- case 4 :
459
- node.eval_type_name = "string";
460
- break;
461
- case 3 :
462
- node.eval_type_name = "int";
463
- break;
464
- case 5 :
465
- node.eval_type_name = "boolean";
466
- break;
467
- }
468
- }
469
-
470
- public void buildGenericClass( CodeNode tpl , CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
471
- final RangerAppWriterContext root = ctx.getRoot();
472
- final CodeNode cn = tpl.getSecond();
473
- final CodeNode newName = node.getSecond();
474
- final Optional<CodeNode> tplArgs = cn.vref_annotation;
475
- final Optional<CodeNode> givenArgs = newName.vref_annotation;
476
- final String sign = cn.vref + givenArgs.get().getCode();
477
- if ( root.classSignatures.containsKey(sign) ) {
478
- return;
479
- }
480
- System.out.println(String.valueOf( "could build generic class... " + cn.vref ) );
481
- final RangerArgMatch match = new RangerArgMatch();
482
- for ( int i = 0; i < tplArgs.get().children.size(); i++) {
483
- CodeNode arg = tplArgs.get().children.get(i);
484
- final CodeNode given = givenArgs.get().children.get(i);
485
- System.out.println(String.valueOf( ((" setting " + arg.vref) + " => ") + given.vref ) );
486
- if ( false == match.add(arg.vref, given.vref, ctx) ) {
487
- System.out.println(String.valueOf( "set failed!" ) );
488
- } else {
489
- System.out.println(String.valueOf( "set OK" ) );
490
- }
491
- System.out.println(String.valueOf( " T == " + match.getTypeName(arg.vref) ) );
492
- }
493
- System.out.println(String.valueOf( " T == " + match.getTypeName("T") ) );
494
- final CodeNode newClassNode = tpl.rebuildWithType(match, false);
495
- System.out.println(String.valueOf( "build done" ) );
496
- System.out.println(String.valueOf( newClassNode.getCode() ) );
497
- final String sign_2 = cn.vref + givenArgs.get().getCode();
498
- System.out.println(String.valueOf( "signature ==> " + sign_2 ) );
499
- final CodeNode cName = newClassNode.getSecond();
500
- final String friendlyName = root.createSignature(cn.vref, sign_2);
501
- System.out.println(String.valueOf( "class common name => " + friendlyName ) );
502
- cName.vref = friendlyName;
503
- cName.has_vref_annotation = false;
504
- System.out.println(String.valueOf( newClassNode.getCode() ) );
505
- this.WalkCollectMethods(newClassNode, ctx, wr);
506
- this.WalkNode(newClassNode, root, wr);
507
- System.out.println(String.valueOf( "the class collected the methods..." ) );
508
- }
509
-
510
- public void cmdNew( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
511
- if ( (node.children.size()) < 2 ) {
512
- ctx.addError(node, "the new operator expects at lest two arguments");
513
- return;
514
- }
515
- if ( (node.children.size()) < 3 ) {
516
- final CodeNode expr = new CodeNode(node.code.get(), node.sp, node.ep);
517
- expr.expression = true;
518
- node.children.add(expr);
519
- }
520
- final CodeNode obj = node.getSecond();
521
- final CodeNode params = node.getThird();
522
- Optional<RangerAppClassDesc> currC = Optional.empty();
523
- boolean b_template = false;
524
- boolean expects_error = false;
525
- final int err_cnt = ctx.getErrorCount();
526
- if ( node.hasBooleanProperty("error") ) {
527
- expects_error = true;
528
- }
529
- if ( ctx.hasTemplateNode(obj.vref) ) {
530
- System.out.println(String.valueOf( " ==> template class" ) );
531
- b_template = true;
532
- final CodeNode tpl = ctx.findTemplateNode(obj.vref);
533
- if ( obj.has_vref_annotation ) {
534
- System.out.println(String.valueOf( "generic class OK" ) );
535
- this.buildGenericClass(tpl, node, ctx, wr);
536
- currC = Optional.of(ctx.findClassWithSign(obj));
537
- if ( currC.isPresent() ) {
538
- System.out.println(String.valueOf( "@@ class was found " + obj.vref ) );
539
- }
540
- } else {
541
- ctx.addError(node, "generic class requires a type annotation");
542
- return;
543
- }
544
- }
545
- this.WalkNode(obj, ctx, wr);
546
- for ( int i = 0; i < params.children.size(); i++) {
547
- CodeNode arg = params.children.get(i);
548
- ctx.setInExpr();
549
- this.WalkNode(arg, ctx, wr);
550
- ctx.unsetInExpr();
551
- }
552
- node.eval_type = 8;
553
- node.eval_type_name = obj.vref;
554
- if ( b_template == false ) {
555
- currC = Optional.of(ctx.findClass(obj.vref));
556
- }
557
- node.hasNewOper = true;
558
- node.clDesc = currC;
559
- final Optional<RangerAppFunctionDesc> fnDescr = currC.get().constructor_fn;
560
- if ( fnDescr.isPresent() ) {
561
- for ( int i_1 = 0; i_1 < fnDescr.get().params.size(); i_1++) {
562
- RangerAppParamDesc param = fnDescr.get().params.get(i_1);
563
- boolean has_default = false;
564
- if ( param.nameNode.get().hasFlag("default") ) {
565
- has_default = true;
566
- }
567
- if ( (params.children.size()) <= i_1 ) {
568
- if ( has_default ) {
569
- continue;
570
- }
571
- ctx.addError(node, "Missing arguments for function");
572
- ctx.addError(param.nameNode.get(), "To fix the previous error: Check original function declaration");
573
- }
574
- final CodeNode argNode = params.children.get(i_1);
575
- if ( false == this.areEqualTypes((param.nameNode.get()), argNode, ctx) ) {
576
- ctx.addError(argNode, ("ERROR, invalid argument type for " + currC.get().name) + " constructor ");
577
- }
578
- final CodeNode pNode = param.nameNode.get();
579
- if ( pNode.hasFlag("optional") ) {
580
- if ( false == argNode.hasFlag("optional") ) {
581
- ctx.addError(node, "new parameter optionality does not match, expected optional parameter" + argNode.getCode());
582
- }
583
- }
584
- if ( argNode.hasFlag("optional") ) {
585
- if ( false == pNode.hasFlag("optional") ) {
586
- ctx.addError(node, "new parameter optionality does not match, expected non-optional, optional given" + argNode.getCode());
587
- }
588
- }
589
- }
590
- }
591
- if ( expects_error ) {
592
- final int cnt_now = ctx.getErrorCount();
593
- if ( cnt_now == err_cnt ) {
594
- ctx.addParserError(node, (("LANGUAGE_PARSER_ERROR: expected generated error, err counts : " + err_cnt) + " : ") + cnt_now);
595
- }
596
- } else {
597
- final int cnt_now_1 = ctx.getErrorCount();
598
- if ( cnt_now_1 > err_cnt ) {
599
- ctx.addParserError(node, (("LANGUAGE_PARSER_ERROR: did not expect generated error, err counts : " + err_cnt) + " : ") + cnt_now_1);
600
- }
601
- }
602
- }
603
-
604
- public ArrayList<CodeNode> transformParams( ArrayList<CodeNode> list , ArrayList<RangerAppParamDesc> fnArgs , RangerAppWriterContext ctx ) {
605
- ArrayList<CodeNode> res = new ArrayList<CodeNode>();
606
- for ( int i = 0; i < list.size(); i++) {
607
- CodeNode item = list.get(i);
608
- if ( item.is_block_node ) {
609
- /** unused: final CodeNode newNode = new CodeNode(item.code.get(), item.sp, item.ep) **/ ;
610
- final RangerAppParamDesc fnArg = fnArgs.get(i);
611
- final Optional<CodeNode> nn = fnArg.nameNode;
612
- if ( !nn.get().expression_value.isPresent() ) {
613
- ctx.addError(item, "Parameter is not lambda expression");
614
- break;
615
- }
616
- final CodeNode fnDef = nn.get().expression_value.get();
617
- final RangerArgMatch match = new RangerArgMatch();
618
- final CodeNode copyOf = fnDef.rebuildWithType(match, false);
619
- final CodeNode fc = copyOf.children.get(0);
620
- fc.vref = "fun";
621
- final CodeNode itemCopy = item.rebuildWithType(match, false);
622
- copyOf.children.add(itemCopy);
623
- int cnt = item.children.size();
624
- while (cnt > 0) {
625
- item.children.remove(item.children.size() - 1);
626
- cnt = cnt - 1;
627
- }
628
- for ( int i_1 = 0; i_1 < copyOf.children.size(); i_1++) {
629
- CodeNode ch = copyOf.children.get(i_1);
630
- item.children.add(ch);
631
- }
632
- }
633
- res.add(item);
634
- }
635
- return res;
636
- }
637
-
638
- public boolean cmdLocalCall( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
639
- final CodeNode fnNode = node.getFirst();
640
- final Optional<RangerAppClassDesc> udesc = ctx.getCurrentClass();
641
- final RangerAppClassDesc desc = udesc.get();
642
- boolean expects_error = false;
643
- final int err_cnt = ctx.getErrorCount();
644
- if ( node.hasBooleanProperty("error") ) {
645
- expects_error = true;
646
- }
647
- if ( (fnNode.ns.size()) > 1 ) {
648
- final String rootName = fnNode.ns.get(0);
649
- final RangerAppParamDesc vDef2 = ctx.getVariableDef(rootName);
650
- if ( ((!rootName.equals("this")) && (vDef2.init_cnt == 0)) && (vDef2.set_cnt == 0) ) {
651
- if ( (vDef2.is_class_variable == false) && (ctx.isDefinedClass(rootName) == false) ) {
652
- ctx.addError(node, "Call to uninitialized object " + rootName);
653
- }
654
- }
655
- final Optional<RangerAppFunctionDesc> vFnDef = this.findFunctionDesc(fnNode, ctx, wr);
656
- if ( vFnDef.isPresent() ) {
657
- vFnDef.get().ref_cnt = vFnDef.get().ref_cnt + 1;
658
- final RangerAppWriterContext subCtx = ctx.fork();
659
- node.hasFnCall = true;
660
- node.fnDesc = vFnDef;
661
- final RangerAppParamDesc p = new RangerAppParamDesc();
662
- p.name = fnNode.vref;
663
- p.value_type = fnNode.value_type;
664
- p.node = Optional.of(fnNode);
665
- p.nameNode = Optional.of(fnNode);
666
- p.varType = 10;
667
- subCtx.defineVariable(p.name, p);
668
- this.WalkNode(fnNode, subCtx, wr);
669
- final CodeNode callParams = node.children.get(1);
670
- final ArrayList<CodeNode> nodeList = this.transformParams(callParams.children, vFnDef.get().params, subCtx);
671
- for ( int i = 0; i < nodeList.size(); i++) {
672
- CodeNode arg = nodeList.get(i);
673
- ctx.setInExpr();
674
- this.WalkNode(arg, subCtx, wr);
675
- ctx.unsetInExpr();
676
- final RangerAppParamDesc fnArg = vFnDef.get().params.get(i);
677
- final Optional<RangerAppParamDesc> callArgP = arg.paramDesc;
678
- if ( callArgP.isPresent() ) {
679
- callArgP.get().moveRefTo(node, fnArg, ctx);
680
- }
681
- }
682
- final int cp_len = callParams.children.size();
683
- if ( cp_len > (vFnDef.get().params.size()) ) {
684
- final CodeNode lastCallParam = callParams.children.get((cp_len - 1));
685
- ctx.addError(lastCallParam, "Too many arguments for function");
686
- ctx.addError(vFnDef.get().nameNode.get(), "NOTE: To fix the previous error: Check original function declaration which was");
687
- }
688
- for ( int i_1 = 0; i_1 < vFnDef.get().params.size(); i_1++) {
689
- RangerAppParamDesc param = vFnDef.get().params.get(i_1);
690
- if ( (callParams.children.size()) <= i_1 ) {
691
- if ( param.nameNode.get().hasFlag("default") ) {
692
- continue;
693
- }
694
- ctx.addError(node, "Missing arguments for function");
695
- ctx.addError(param.nameNode.get(), "NOTE: To fix the previous error: Check original function declaration which was");
696
- break;
697
- }
698
- final CodeNode argNode = callParams.children.get(i_1);
699
- if ( false == this.areEqualTypes((param.nameNode.get()), argNode, ctx) ) {
700
- ctx.addError(argNode, "ERROR, invalid argument type for method " + vFnDef.get().name);
701
- }
702
- final CodeNode pNode = param.nameNode.get();
703
- if ( pNode.hasFlag("optional") ) {
704
- if ( false == argNode.hasFlag("optional") ) {
705
- ctx.addError(node, "function parameter optionality does not match, consider making parameter optional " + argNode.getCode());
706
- }
707
- }
708
- if ( argNode.hasFlag("optional") ) {
709
- if ( false == pNode.hasFlag("optional") ) {
710
- ctx.addError(node, "function parameter optionality does not match, consider unwrapping " + argNode.getCode());
711
- }
712
- }
713
- }
714
- final Optional<CodeNode> nn = vFnDef.get().nameNode;
715
- node.eval_type = nn.get().typeNameAsType(ctx);
716
- node.eval_type_name = nn.get().type_name;
717
- node.eval_array_type = nn.get().array_type;
718
- node.eval_key_type = nn.get().key_type;
719
- if ( nn.get().hasFlag("optional") ) {
720
- node.setFlag("optional");
721
- }
722
- if ( expects_error ) {
723
- final int cnt_now = ctx.getErrorCount();
724
- if ( cnt_now == err_cnt ) {
725
- ctx.addParserError(node, (("LANGUAGE_PARSER_ERROR: expected generated error, err counts : " + err_cnt) + " : ") + cnt_now);
726
- }
727
- } else {
728
- final int cnt_now_1 = ctx.getErrorCount();
729
- if ( cnt_now_1 > err_cnt ) {
730
- ctx.addParserError(node, (("LANGUAGE_PARSER_ERROR: did not expect generated error, err counts : " + err_cnt) + " : ") + cnt_now_1);
731
- }
732
- }
733
- return true;
734
- } else {
735
- ctx.addError(node, "Called Object or Property was not defined");
736
- }
737
- }
738
- if ( desc.hasMethod(fnNode.vref) ) {
739
- final Optional<RangerAppFunctionDesc> fnDescr = desc.findMethod(fnNode.vref);
740
- final RangerAppWriterContext subCtx_1 = ctx.fork();
741
- node.hasFnCall = true;
742
- node.fnDesc = fnDescr;
743
- final RangerAppParamDesc p_1 = new RangerAppParamDesc();
744
- p_1.name = fnNode.vref;
745
- p_1.value_type = fnNode.value_type;
746
- p_1.node = Optional.of(fnNode);
747
- p_1.nameNode = Optional.of(fnNode);
748
- p_1.varType = 10;
749
- subCtx_1.defineVariable(p_1.name, p_1);
750
- this.WriteThisVar(fnNode, subCtx_1, wr);
751
- this.WalkNode(fnNode, subCtx_1, wr);
752
- for ( int i_2 = 0; i_2 < node.children.size(); i_2++) {
753
- CodeNode arg_1 = node.children.get(i_2);
754
- if ( i_2 < 1 ) {
755
- continue;
756
- }
757
- ctx.setInExpr();
758
- this.WalkNode(arg_1, subCtx_1, wr);
759
- ctx.unsetInExpr();
760
- }
761
- for ( int i_3 = 0; i_3 < fnDescr.get().params.size(); i_3++) {
762
- RangerAppParamDesc param_1 = fnDescr.get().params.get(i_3);
763
- if ( (node.children.size()) <= (i_3 + 1) ) {
764
- ctx.addError(node, "Argument was not defined");
765
- break;
766
- }
767
- final CodeNode argNode_1 = node.children.get((i_3 + 1));
768
- if ( false == this.areEqualTypes((param_1.nameNode.get()), argNode_1, ctx) ) {
769
- ctx.addError(argNode_1, (("ERROR, invalid argument type for " + desc.name) + " method ") + fnDescr.get().name);
770
- }
771
- }
772
- final Optional<CodeNode> nn_1 = fnDescr.get().nameNode;
773
- nn_1.get().defineNodeTypeTo(node, ctx);
774
- if ( expects_error ) {
775
- final int cnt_now_2 = ctx.getErrorCount();
776
- if ( cnt_now_2 == err_cnt ) {
777
- ctx.addParserError(node, (("LANGUAGE_PARSER_ERROR: expected generated error, err counts : " + err_cnt) + " : ") + cnt_now_2);
778
- }
779
- } else {
780
- final int cnt_now_3 = ctx.getErrorCount();
781
- if ( cnt_now_3 > err_cnt ) {
782
- ctx.addParserError(node, (("LANGUAGE_PARSER_ERROR: did not expect generated error, err counts : " + err_cnt) + " : ") + cnt_now_3);
783
- }
784
- }
785
- return true;
786
- }
787
- if ( ctx.isVarDefined(fnNode.vref) ) {
788
- final RangerAppParamDesc d = ctx.getVariableDef(fnNode.vref);
789
- d.ref_cnt = 1 + d.ref_cnt;
790
- if ( d.nameNode.get().value_type == 15 ) {
791
- /** unused: final CodeNode lambdaDefArgs = d.nameNode.get().expression_value.get().children.get(1) **/ ;
792
- final CodeNode callParams_1 = node.children.get(1);
793
- for ( int i_4 = 0; i_4 < callParams_1.children.size(); i_4++) {
794
- CodeNode arg_2 = callParams_1.children.get(i_4);
795
- ctx.setInExpr();
796
- this.WalkNode(arg_2, ctx, wr);
797
- ctx.unsetInExpr();
798
- }
799
- final CodeNode lambdaDef = d.nameNode.get().expression_value.get().children.get(0);
800
- /** unused: final CodeNode lambdaArgs = d.nameNode.get().expression_value.get().children.get(1) **/ ;
801
- node.has_lambda_call = true;
802
- node.eval_type = lambdaDef.typeNameAsType(ctx);
803
- node.eval_type_name = lambdaDef.type_name;
804
- node.eval_array_type = lambdaDef.array_type;
805
- node.eval_key_type = lambdaDef.key_type;
806
- return true;
807
- }
808
- }
809
- ctx.addError(node, (("ERROR, could not find class " + desc.name) + " method ") + fnNode.vref);
810
- ctx.addError(node, "definition : " + node.getCode());
811
- if ( expects_error ) {
812
- final int cnt_now_4 = ctx.getErrorCount();
813
- if ( cnt_now_4 == err_cnt ) {
814
- ctx.addParserError(node, (("LANGUAGE_PARSER_ERROR: expected generated error, err counts : " + err_cnt) + " : ") + cnt_now_4);
815
- }
816
- } else {
817
- final int cnt_now_5 = ctx.getErrorCount();
818
- if ( cnt_now_5 > err_cnt ) {
819
- ctx.addParserError(node, (("LANGUAGE_PARSER_ERROR: did not expect generated error, err counts : " + err_cnt) + " : ") + cnt_now_5);
820
- }
821
- }
822
- return false;
823
- }
824
-
825
- public void cmdReturn( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
826
- node.has_operator = true;
827
- node.op_index = 5;
828
- System.out.println(String.valueOf( "cmdReturn" ) );
829
- if ( (node.children.size()) > 1 ) {
830
- final CodeNode fc = node.getSecond();
831
- if ( fc.vref.equals("_") ) {
832
- } else {
833
- ctx.setInExpr();
834
- this.WalkNode(fc, ctx, wr);
835
- ctx.unsetInExpr();
836
- /** unused: final RangerAppFunctionDesc activeFn = ctx.getCurrentMethod() **/ ;
837
- if ( fc.hasParamDesc ) {
838
- fc.paramDesc.get().return_cnt = 1 + fc.paramDesc.get().return_cnt;
839
- fc.paramDesc.get().ref_cnt = 1 + fc.paramDesc.get().ref_cnt;
840
- }
841
- final RangerAppFunctionDesc currFn = ctx.getCurrentMethod();
842
- if ( fc.hasParamDesc ) {
843
- System.out.println(String.valueOf( "cmdReturn move-->" ) );
844
- final Optional<RangerAppParamDesc> pp = fc.paramDesc;
845
- pp.get().moveRefTo(node, currFn, ctx);
846
- } else {
847
- System.out.println(String.valueOf( "cmdReturn had no param desc" ) );
848
- }
849
- }
850
- }
851
- }
852
-
853
- public void cmdAssign( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
854
- wr.newline();
855
- final CodeNode n1 = node.getSecond();
856
- final CodeNode n2 = node.getThird();
857
- this.WalkNode(n1, ctx, wr);
858
- ctx.setInExpr();
859
- this.WalkNode(n2, ctx, wr);
860
- ctx.unsetInExpr();
861
- if ( n1.hasParamDesc ) {
862
- n1.paramDesc.get().ref_cnt = n1.paramDesc.get().ref_cnt + 1;
863
- n1.paramDesc.get().set_cnt = n1.paramDesc.get().set_cnt + 1;
864
- }
865
- if ( n2.hasParamDesc ) {
866
- n2.paramDesc.get().ref_cnt = n2.paramDesc.get().ref_cnt + 1;
867
- }
868
- if ( n2.hasFlag("optional") ) {
869
- if ( false == n1.hasFlag("optional") ) {
870
- ctx.addError(node, "Can not assign optional to non-optional type");
871
- }
872
- }
873
- this.stdParamMatch(node, ctx, wr);
874
- }
875
-
876
- public void EnterTemplateClass( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
877
- }
878
-
879
- public void EnterClass( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
880
- if ( (node.children.size()) != 3 ) {
881
- ctx.addError(node, "Invalid class declaration");
882
- return;
883
- }
884
- if ( node.hasBooleanProperty("trait") ) {
885
- return;
886
- }
887
- final CodeNode cn = node.children.get(1);
888
- final CodeNode cBody = node.children.get(2);
889
- final RangerAppClassDesc desc = ctx.findClass(cn.vref);
890
- if ( cn.has_vref_annotation ) {
891
- System.out.println(String.valueOf( "--> generic class, not processed" ) );
892
- return;
893
- }
894
- final RangerAppWriterContext subCtx = desc.ctx.get();
895
- subCtx.setCurrentClass(desc);
896
- subCtx.class_level_context = true;
897
- for ( int i = 0; i < desc.variables.size(); i++) {
898
- RangerAppParamDesc p = desc.variables.get(i);
899
- final Optional<CodeNode> vNode = p.node;
900
- if ( (vNode.get().children.size()) > 2 ) {
901
- final CodeNode value = vNode.get().children.get(2);
902
- ctx.setInExpr();
903
- this.WalkNode(value, ctx, wr);
904
- ctx.unsetInExpr();
905
- }
906
- p.is_class_variable = true;
907
- p.nameNode.get().eval_type = p.nameNode.get().typeNameAsType(ctx);
908
- p.nameNode.get().eval_type_name = p.nameNode.get().type_name;
909
- }
910
- for ( int i_1 = 0; i_1 < cBody.children.size(); i_1++) {
911
- CodeNode fNode = cBody.children.get(i_1);
912
- if ( fNode.isFirstVref("fn") || fNode.isFirstVref("Constructor") ) {
913
- this.WalkNode(fNode, subCtx, wr);
914
- }
915
- }
916
- for ( int i_2 = 0; i_2 < cBody.children.size(); i_2++) {
917
- CodeNode fNode_1 = cBody.children.get(i_2);
918
- if ( fNode_1.isFirstVref("fn") || fNode_1.isFirstVref("PublicMethod") ) {
919
- this.WalkNode(fNode_1, subCtx, wr);
920
- }
921
- }
922
- final RangerAppWriterContext staticCtx = ctx.fork();
923
- staticCtx.setCurrentClass(desc);
924
- for ( int i_3 = 0; i_3 < cBody.children.size(); i_3++) {
925
- CodeNode fNode_2 = cBody.children.get(i_3);
926
- if ( fNode_2.isFirstVref("sfn") || fNode_2.isFirstVref("StaticMethod") ) {
927
- this.WalkNode(fNode_2, staticCtx, wr);
928
- }
929
- }
930
- node.hasClassDescription = true;
931
- node.clDesc = Optional.of(desc);
932
- desc.classNode = Optional.of(node);
933
- }
934
-
935
- public void EnterMethod( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
936
- this.shouldHaveChildCnt(4, node, ctx, "Method expexts four arguments");
937
- final CodeNode cn = node.children.get(1);
938
- final CodeNode fnBody = node.children.get(3);
939
- final Optional<RangerAppClassDesc> udesc = ctx.getCurrentClass();
940
- final RangerAppClassDesc desc = udesc.get();
941
- final Optional<RangerAppFunctionDesc> um = desc.findMethod(cn.vref);
942
- final RangerAppFunctionDesc m = um.get();
943
- final RangerAppWriterContext subCtx = m.fnCtx.get();
944
- subCtx.function_level_context = true;
945
- subCtx.currentMethod = Optional.of(m);
946
- for ( int i = 0; i < m.params.size(); i++) {
947
- RangerAppParamDesc v = m.params.get(i);
948
- v.nameNode.get().eval_type = v.nameNode.get().typeNameAsType(subCtx);
949
- v.nameNode.get().eval_type_name = v.nameNode.get().type_name;
950
- ctx.hadValidType(v.nameNode.get());
951
- }
952
- subCtx.setInMethod();
953
- this.WalkNodeChildren(fnBody, subCtx, wr);
954
- subCtx.unsetInMethod();
955
- if ( fnBody.didReturnAtIndex == -1 ) {
956
- if ( !cn.type_name.equals("void") ) {
957
- ctx.addError(node, "Function does not return any values!");
958
- }
959
- }
960
- for ( int i_1 = 0; i_1 < subCtx.localVarNames.size(); i_1++) {
961
- String n = subCtx.localVarNames.get(i_1);
962
- final Optional<RangerAppParamDesc> p = Optional.ofNullable(subCtx.localVariables.get(n));
963
- if ( p.get().set_cnt > 0 ) {
964
- final Optional<CodeNode> defNode = p.get().node;
965
- defNode.get().setFlag("mutable");
966
- final Optional<CodeNode> nNode = p.get().nameNode;
967
- nNode.get().setFlag("mutable");
968
- }
969
- }
970
- }
971
-
972
- public void EnterStaticMethod( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
973
- this.shouldHaveChildCnt(4, node, ctx, "Method expexts four arguments");
974
- final CodeNode cn = node.children.get(1);
975
- final CodeNode fnBody = node.children.get(3);
976
- final Optional<RangerAppClassDesc> udesc = ctx.getCurrentClass();
977
- final RangerAppClassDesc desc = udesc.get();
978
- final RangerAppWriterContext subCtx = ctx.fork();
979
- subCtx.is_function = true;
980
- final Optional<RangerAppFunctionDesc> um = desc.findStaticMethod(cn.vref);
981
- final RangerAppFunctionDesc m = um.get();
982
- subCtx.currentMethod = Optional.of(m);
983
- subCtx.in_static_method = true;
984
- m.fnCtx = Optional.of(subCtx);
985
- if ( cn.hasFlag("weak") ) {
986
- m.changeStrength(0, 1, node);
987
- } else {
988
- m.changeStrength(1, 1, node);
989
- }
990
- subCtx.setInMethod();
991
- for ( int i = 0; i < m.params.size(); i++) {
992
- RangerAppParamDesc v = m.params.get(i);
993
- subCtx.defineVariable(v.name, v);
994
- v.nameNode.get().eval_type = v.nameNode.get().typeNameAsType(ctx);
995
- v.nameNode.get().eval_type_name = v.nameNode.get().type_name;
996
- }
997
- this.WalkNodeChildren(fnBody, subCtx, wr);
998
- subCtx.unsetInMethod();
999
- subCtx.in_static_method = false;
1000
- subCtx.function_level_context = true;
1001
- if ( fnBody.didReturnAtIndex == -1 ) {
1002
- if ( !cn.type_name.equals("void") ) {
1003
- ctx.addError(node, "Function does not return any values!");
1004
- }
1005
- }
1006
- for ( int i_1 = 0; i_1 < subCtx.localVarNames.size(); i_1++) {
1007
- String n = subCtx.localVarNames.get(i_1);
1008
- final Optional<RangerAppParamDesc> p = Optional.ofNullable(subCtx.localVariables.get(n));
1009
- if ( p.get().set_cnt > 0 ) {
1010
- final Optional<CodeNode> defNode = p.get().node;
1011
- defNode.get().setFlag("mutable");
1012
- final Optional<CodeNode> nNode = p.get().nameNode;
1013
- nNode.get().setFlag("mutable");
1014
- }
1015
- }
1016
- }
1017
-
1018
- public void EnterLambdaMethod( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
1019
- final CodeNode args = node.children.get(1);
1020
- final CodeNode body = node.children.get(2);
1021
- final RangerAppWriterContext subCtx = ctx.fork();
1022
- subCtx.is_capturing = true;
1023
- final CodeNode cn = node.children.get(0);
1024
- final RangerAppFunctionDesc m = new RangerAppFunctionDesc();
1025
- m.name = "lambda";
1026
- m.node = Optional.of(node);
1027
- m.nameNode = Optional.of(node.children.get(0));
1028
- subCtx.is_function = true;
1029
- subCtx.currentMethod = Optional.of(m);
1030
- if ( cn.hasFlag("weak") ) {
1031
- m.changeStrength(0, 1, node);
1032
- } else {
1033
- m.changeStrength(1, 1, node);
1034
- }
1035
- m.fnBody = Optional.of(node.children.get(2));
1036
- for ( int ii = 0; ii < args.children.size(); ii++) {
1037
- CodeNode arg = args.children.get(ii);
1038
- final RangerAppParamDesc p2 = new RangerAppParamDesc();
1039
- p2.name = arg.vref;
1040
- p2.value_type = arg.value_type;
1041
- p2.node = Optional.of(arg);
1042
- p2.nameNode = Optional.of(arg);
1043
- p2.init_cnt = 1;
1044
- p2.refType = 1;
1045
- p2.initRefType = 1;
1046
- if ( args.hasBooleanProperty("strong") ) {
1047
- p2.refType = 2;
1048
- p2.initRefType = 2;
1049
- }
1050
- p2.varType = 4;
1051
- m.params.add(p2);
1052
- arg.hasParamDesc = true;
1053
- arg.paramDesc = Optional.of(p2);
1054
- arg.eval_type = arg.value_type;
1055
- arg.eval_type_name = arg.type_name;
1056
- if ( arg.hasFlag("strong") ) {
1057
- p2.changeStrength(1, 1, p2.nameNode.get());
1058
- } else {
1059
- arg.setFlag("lives");
1060
- p2.changeStrength(0, 1, p2.nameNode.get());
1061
- }
1062
- subCtx.defineVariable(p2.name, p2);
1063
- }
1064
- /** unused: final int cnt = body.children.size() **/ ;
1065
- for ( int i = 0; i < body.children.size(); i++) {
1066
- CodeNode item = body.children.get(i);
1067
- this.WalkNode(item, subCtx, wr);
1068
- if ( i == ((body.children.size()) - 1) ) {
1069
- if ( (item.children.size()) > 0 ) {
1070
- final CodeNode fc = item.getFirst();
1071
- if ( !fc.vref.equals("return") ) {
1072
- cn.type_name = "void";
1073
- }
1074
- }
1075
- }
1076
- }
1077
- node.has_lambda = true;
1078
- node.lambda_ctx = Optional.of(subCtx);
1079
- node.eval_type = 15;
1080
- node.eval_function = Optional.of(node);
1081
- }
1082
-
1083
- public void EnterVarDef( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
1084
- if ( ctx.isInMethod() ) {
1085
- if ( (node.children.size()) > 3 ) {
1086
- ctx.addError(node, "invalid variable definition");
1087
- return;
1088
- }
1089
- if ( (node.children.size()) < 2 ) {
1090
- ctx.addError(node, "invalid variable definition");
1091
- return;
1092
- }
1093
- final CodeNode cn = node.children.get(1);
1094
- final RangerAppParamDesc p = new RangerAppParamDesc();
1095
- Optional<CodeNode> defaultArg = Optional.empty();
1096
- if ( (node.children.size()) == 2 ) {
1097
- if ( (cn.value_type != 6) && (cn.value_type != 7) ) {
1098
- cn.setFlag("optional");
1099
- }
1100
- }
1101
- if ( (cn.vref.length()) == 0 ) {
1102
- ctx.addError(node, "invalid variable definition");
1103
- }
1104
- if ( cn.hasFlag("weak") ) {
1105
- p.changeStrength(0, 1, node);
1106
- } else {
1107
- p.changeStrength(1, 1, node);
1108
- }
1109
- node.hasVarDef = true;
1110
- if ( cn.value_type == 15 ) {
1111
- System.out.println(String.valueOf( "Expression node..." ) );
1112
- }
1113
- if ( (node.children.size()) > 2 ) {
1114
- p.init_cnt = 1;
1115
- p.def_value = Optional.of(node.children.get(2));
1116
- p.is_optional = false;
1117
- defaultArg = Optional.of(node.children.get(2));
1118
- ctx.setInExpr();
1119
- this.WalkNode(defaultArg.get(), ctx, wr);
1120
- ctx.unsetInExpr();
1121
- if ( defaultArg.get().hasFlag("optional") ) {
1122
- cn.setFlag("optional");
1123
- }
1124
- if ( defaultArg.get().eval_type == 6 ) {
1125
- node.op_index = 1;
1126
- }
1127
- if ( cn.value_type == 11 ) {
1128
- cn.eval_type_name = defaultArg.get().ns.get(0);
1129
- }
1130
- if ( cn.value_type == 12 ) {
1131
- if ( (defaultArg.get().eval_type != 3) && (defaultArg.get().eval_type != 12) ) {
1132
- ctx.addError(defaultArg.get(), "Char should be assigned char or integer value --> " + defaultArg.get().getCode());
1133
- } else {
1134
- defaultArg.get().eval_type = 12;
1135
- }
1136
- }
1137
- } else {
1138
- if ( ((cn.value_type != 7) && (cn.value_type != 6)) && (false == cn.hasFlag("optional")) ) {
1139
- cn.setFlag("optional");
1140
- }
1141
- }
1142
- if ( (node.children.size()) > 2 ) {
1143
- if ( ((cn.type_name.length()) == 0) && ((cn.array_type.length()) == 0) ) {
1144
- final CodeNode nodeValue = node.children.get(2);
1145
- if ( nodeValue.eval_type == 15 ) {
1146
- if ( !node.expression_value.isPresent() ) {
1147
- final CodeNode copyOf = nodeValue.rebuildWithType(new RangerArgMatch(), false);
1148
- copyOf.children.remove(copyOf.children.size() - 1);
1149
- cn.expression_value = Optional.of(copyOf);
1150
- }
1151
- }
1152
- cn.value_type = nodeValue.eval_type;
1153
- cn.type_name = nodeValue.eval_type_name;
1154
- cn.array_type = nodeValue.eval_array_type;
1155
- cn.key_type = nodeValue.eval_key_type;
1156
- }
1157
- }
1158
- ctx.hadValidType(cn);
1159
- cn.defineNodeTypeTo(cn, ctx);
1160
- p.name = cn.vref;
1161
- if ( p.value_type == 0 ) {
1162
- if ( (0 == (cn.type_name.length())) && (defaultArg.isPresent()) ) {
1163
- p.value_type = defaultArg.get().eval_type;
1164
- cn.type_name = defaultArg.get().eval_type_name;
1165
- cn.eval_type_name = defaultArg.get().eval_type_name;
1166
- cn.value_type = defaultArg.get().eval_type;
1167
- }
1168
- } else {
1169
- p.value_type = cn.value_type;
1170
- }
1171
- p.node = Optional.of(node);
1172
- p.nameNode = Optional.of(cn);
1173
- p.varType = 5;
1174
- if ( cn.has_vref_annotation ) {
1175
- ctx.log(node, "ann", "At a variable -> Found has_vref_annotation annotated reference ");
1176
- final Optional<CodeNode> ann = cn.vref_annotation;
1177
- if ( (ann.get().children.size()) > 0 ) {
1178
- final CodeNode fc = ann.get().children.get(0);
1179
- ctx.log(node, "ann", (("value of first annotation " + fc.vref) + " and variable name ") + cn.vref);
1180
- }
1181
- }
1182
- if ( cn.has_type_annotation ) {
1183
- ctx.log(node, "ann", "At a variable -> Found annotated reference ");
1184
- final Optional<CodeNode> ann_1 = cn.type_annotation;
1185
- if ( (ann_1.get().children.size()) > 0 ) {
1186
- final CodeNode fc_1 = ann_1.get().children.get(0);
1187
- ctx.log(node, "ann", (("value of first annotation " + fc_1.vref) + " and variable name ") + cn.vref);
1188
- }
1189
- }
1190
- cn.hasParamDesc = true;
1191
- cn.ownParamDesc = Optional.of(p);
1192
- cn.paramDesc = Optional.of(p);
1193
- node.hasParamDesc = true;
1194
- node.paramDesc = Optional.of(p);
1195
- cn.eval_type = cn.typeNameAsType(ctx);
1196
- cn.eval_type_name = cn.type_name;
1197
- if ( (node.children.size()) > 2 ) {
1198
- if ( cn.eval_type != defaultArg.get().eval_type ) {
1199
- if ( ((cn.eval_type == 12) && (defaultArg.get().eval_type == 3)) || ((cn.eval_type == 3) && (defaultArg.get().eval_type == 12)) ) {
1200
- } else {
1201
- ctx.addError(node, (("Variable was assigned an incompatible type. Types were " + cn.eval_type) + " vs ") + defaultArg.get().eval_type);
1202
- }
1203
- }
1204
- } else {
1205
- p.is_optional = true;
1206
- }
1207
- ctx.defineVariable(p.name, p);
1208
- this.DefineVar(node, ctx, wr);
1209
- if ( (node.children.size()) > 2 ) {
1210
- this.shouldBeEqualTypes(cn, p.def_value.get(), ctx, "Variable was assigned an incompatible type.");
1211
- }
1212
- } else {
1213
- final CodeNode cn_1 = node.children.get(1);
1214
- cn_1.eval_type = cn_1.typeNameAsType(ctx);
1215
- cn_1.eval_type_name = cn_1.type_name;
1216
- this.DefineVar(node, ctx, wr);
1217
- if ( (node.children.size()) > 2 ) {
1218
- this.shouldBeEqualTypes(node.children.get(1), node.children.get(2), ctx, "Variable was assigned an incompatible type.");
1219
- }
1220
- }
1221
- }
1222
-
1223
- public void WalkNodeChildren( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
1224
- if ( node.hasStringProperty("todo") ) {
1225
- ctx.addTodo(node, node.getStringProperty("todo"));
1226
- }
1227
- if ( node.expression ) {
1228
- for ( int i = 0; i < node.children.size(); i++) {
1229
- CodeNode item = node.children.get(i);
1230
- item.parent = Optional.of(node);
1231
- this.WalkNode(item, ctx, wr);
1232
- node.copyEvalResFrom(item);
1233
- }
1234
- }
1235
- }
1236
-
1237
- public boolean matchNode( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
1238
- if ( 0 == (node.children.size()) ) {
1239
- return false;
1240
- }
1241
- final CodeNode fc = node.getFirst();
1242
- stdCommands = Optional.of(ctx.getStdCommands());
1243
- for ( int i = 0; i < stdCommands.get().children.size(); i++) {
1244
- CodeNode cmd = stdCommands.get().children.get(i);
1245
- final CodeNode cmdName = cmd.getFirst();
1246
- if ( cmdName.vref.equals(fc.vref) ) {
1247
- this.stdParamMatch(node, ctx, wr);
1248
- if ( node.parent.isPresent() ) {
1249
- node.parent.get().copyEvalResFrom(node);
1250
- }
1251
- return true;
1252
- }
1253
- }
1254
- return false;
1255
- }
1256
-
1257
- public void StartWalk( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
1258
- this.WalkNode(node, ctx, wr);
1259
- for ( int i = 0; i < walkAlso.size(); i++) {
1260
- CodeNode ch = walkAlso.get(i);
1261
- this.WalkNode(ch, ctx, wr);
1262
- }
1263
- }
1264
-
1265
- public boolean WalkNode( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
1266
- /** unused: final int line_index = node.getLine() **/ ;
1267
- if ( node.flow_done ) {
1268
- return true;
1269
- }
1270
- node.flow_done = true;
1271
- this.lastProcessedNode = Optional.of(node);
1272
- if ( node.hasStringProperty("todo") ) {
1273
- ctx.addTodo(node, node.getStringProperty("todo"));
1274
- }
1275
- if ( node.isPrimitive() ) {
1276
- if ( ctx.expressionLevel() == 0 ) {
1277
- ctx.addError(node, "Primitive element at top level!");
1278
- }
1279
- this.WriteScalarValue(node, ctx, wr);
1280
- return true;
1281
- }
1282
- if ( node.value_type == 9 ) {
1283
- this.WriteVRef(node, ctx, wr);
1284
- return true;
1285
- }
1286
- if ( node.value_type == 10 ) {
1287
- this.WriteComment(node, ctx, wr);
1288
- return true;
1289
- }
1290
- if ( node.isFirstVref("fun") ) {
1291
- this.EnterLambdaMethod(node, ctx, wr);
1292
- return true;
1293
- }
1294
- if ( node.isFirstVref("fn") ) {
1295
- if ( ctx.isInMethod() ) {
1296
- this.EnterLambdaMethod(node, ctx, wr);
1297
- return true;
1298
- }
1299
- }
1300
- if ( node.isFirstVref("Extends") ) {
1301
- return true;
1302
- }
1303
- if ( node.isFirstVref("extension") ) {
1304
- this.EnterClass(node, ctx, wr);
1305
- return true;
1306
- }
1307
- if ( node.isFirstVref("operators") ) {
1308
- return true;
1309
- }
1310
- if ( node.isFirstVref("systemclass") ) {
1311
- return true;
1312
- }
1313
- if ( node.isFirstVref("systemunion") ) {
1314
- return true;
1315
- }
1316
- if ( node.isFirstVref("Import") ) {
1317
- this.cmdImport(node, ctx, wr);
1318
- return true;
1319
- }
1320
- if ( node.isFirstVref("def") ) {
1321
- this.EnterVarDef(node, ctx, wr);
1322
- return true;
1323
- }
1324
- if ( node.isFirstVref("let") ) {
1325
- this.EnterVarDef(node, ctx, wr);
1326
- return true;
1327
- }
1328
- if ( node.isFirstVref("TemplateClass") ) {
1329
- this.EnterTemplateClass(node, ctx, wr);
1330
- return true;
1331
- }
1332
- if ( node.isFirstVref("CreateClass") ) {
1333
- this.EnterClass(node, ctx, wr);
1334
- return true;
1335
- }
1336
- if ( node.isFirstVref("class") ) {
1337
- this.EnterClass(node, ctx, wr);
1338
- return true;
1339
- }
1340
- if ( node.isFirstVref("trait") ) {
1341
- return true;
1342
- }
1343
- if ( node.isFirstVref("PublicMethod") ) {
1344
- this.EnterMethod(node, ctx, wr);
1345
- return true;
1346
- }
1347
- if ( node.isFirstVref("StaticMethod") ) {
1348
- this.EnterStaticMethod(node, ctx, wr);
1349
- return true;
1350
- }
1351
- if ( node.isFirstVref("fn") ) {
1352
- this.EnterMethod(node, ctx, wr);
1353
- return true;
1354
- }
1355
- if ( node.isFirstVref("sfn") ) {
1356
- this.EnterStaticMethod(node, ctx, wr);
1357
- return true;
1358
- }
1359
- if ( node.isFirstVref("=") ) {
1360
- this.cmdAssign(node, ctx, wr);
1361
- return true;
1362
- }
1363
- if ( node.isFirstVref("Constructor") ) {
1364
- this.Constructor(node, ctx, wr);
1365
- return true;
1366
- }
1367
- if ( node.isFirstVref("new") ) {
1368
- this.cmdNew(node, ctx, wr);
1369
- return true;
1370
- }
1371
- if ( this.matchNode(node, ctx, wr) ) {
1372
- return true;
1373
- }
1374
- if ( (node.children.size()) > 0 ) {
1375
- final CodeNode fc = node.children.get(0);
1376
- if ( fc.value_type == 9 ) {
1377
- boolean was_called = true;
1378
- switch (fc.vref ) {
1379
- case "Enum" :
1380
- this.cmdEnum(node, ctx, wr);
1381
- break;
1382
- default:
1383
- was_called = false;
1384
- break;
1385
- }
1386
- if ( was_called ) {
1387
- return true;
1388
- }
1389
- if ( (node.children.size()) > 1 ) {
1390
- if ( this.cmdLocalCall(node, ctx, wr) ) {
1391
- return true;
1392
- }
1393
- }
1394
- }
1395
- }
1396
- if ( node.expression ) {
1397
- for ( int i = 0; i < node.children.size(); i++) {
1398
- CodeNode item = node.children.get(i);
1399
- item.parent = Optional.of(node);
1400
- this.WalkNode(item, ctx, wr);
1401
- node.copyEvalResFrom(item);
1402
- }
1403
- return true;
1404
- }
1405
- ctx.addError(node, "Could not understand this part");
1406
- return true;
1407
- }
1408
-
1409
- public void mergeImports( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
1410
- if ( node.isFirstVref("Import") ) {
1411
- final CodeNode fNameNode = node.children.get(1);
1412
- final String import_file = fNameNode.string_value;
1413
- if ( ctx.already_imported.containsKey(import_file) ) {
1414
- return;
1415
- }
1416
- ctx.already_imported.put(import_file, true);
1417
- final Optional<String> c = Optional.of(readFile("." + "/" + import_file , StandardCharsets.UTF_8 ));
1418
- final SourceCode code = new SourceCode(c.get());
1419
- code.filename = import_file;
1420
- final RangerLispParser parser = new RangerLispParser(code);
1421
- parser.parse();
1422
- node.expression = true;
1423
- node.vref = "";
1424
- node.children.remove(node.children.size() - 1);
1425
- node.children.remove(node.children.size() - 1);
1426
- final CodeNode rn = parser.rootNode.get();
1427
- this.mergeImports(rn, ctx, wr);
1428
- node.children.add(rn);
1429
- } else {
1430
- for ( int i = 0; i < node.children.size(); i++) {
1431
- CodeNode item = node.children.get(i);
1432
- this.mergeImports(item, ctx, wr);
1433
- }
1434
- }
1435
- }
1436
-
1437
- public void CollectMethods( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
1438
- this.WalkCollectMethods(node, ctx, wr);
1439
- for ( int i = 0; i < classesWithTraits.size(); i++) {
1440
- ClassJoinPoint point = classesWithTraits.get(i);
1441
- final RangerAppClassDesc cl = point.class_def.get();
1442
- /** unused: final CodeNode joinPoint = point.node.get() **/ ;
1443
- final CodeNode traitClassDef = point.node.get().children.get(1);
1444
- final String name = traitClassDef.vref;
1445
- final RangerAppClassDesc t = ctx.findClass(name);
1446
- if ( (t.extends_classes.size()) > 0 ) {
1447
- ctx.addError(point.node.get(), ("Can not join class " + name) + " because it is inherited. Currently on base classes can be used as traits.");
1448
- continue;
1449
- }
1450
- if ( t.has_constructor ) {
1451
- ctx.addError(point.node.get(), ("Can not join class " + name) + " because it has a constructor function");
1452
- } else {
1453
- final CodeNode origBody = cl.node.get().children.get(2);
1454
- final RangerArgMatch match = new RangerArgMatch();
1455
- final Optional<CodeNode> params = t.node.get().getExpressionProperty("params");
1456
- final Optional<CodeNode> initParams = point.node.get().getExpressionProperty("params");
1457
- if ( (params.isPresent()) && (initParams.isPresent()) ) {
1458
- for ( int i_1 = 0; i_1 < params.get().children.size(); i_1++) {
1459
- CodeNode typeName = params.get().children.get(i_1);
1460
- final CodeNode pArg = initParams.get().children.get(i_1);
1461
- match.add(typeName.vref, pArg.vref, ctx);
1462
- }
1463
- } else {
1464
- match.add("T", cl.name, ctx);
1465
- }
1466
- ctx.setCurrentClass(cl);
1467
- final RangerAppClassDesc traitClass = ctx.findClass(traitClassDef.vref);
1468
- for ( int i_2 = 0; i_2 < traitClass.variables.size(); i_2++) {
1469
- RangerAppParamDesc pvar = traitClass.variables.get(i_2);
1470
- final CodeNode ccopy = pvar.node.get().rebuildWithType(match, true);
1471
- this.WalkCollectMethods(ccopy, ctx, wr);
1472
- origBody.children.add(ccopy);
1473
- }
1474
- for ( int i_3 = 0; i_3 < traitClass.defined_variants.size(); i_3++) {
1475
- String fnVar = traitClass.defined_variants.get(i_3);
1476
- final Optional<RangerAppMethodVariants> mVs = Optional.ofNullable(traitClass.method_variants.get(fnVar));
1477
- for ( int i_4 = 0; i_4 < mVs.get().variants.size(); i_4++) {
1478
- RangerAppFunctionDesc variant = mVs.get().variants.get(i_4);
1479
- final CodeNode ccopy_1 = variant.node.get().rebuildWithType(match, true);
1480
- this.WalkCollectMethods(ccopy_1, ctx, wr);
1481
- origBody.children.add(ccopy_1);
1482
- }
1483
- }
1484
- }
1485
- }
1486
- for ( int i_5 = 0; i_5 < serializedClasses.size(); i_5++) {
1487
- RangerAppClassDesc cl_1 = serializedClasses.get(i_5);
1488
- cl_1.is_serialized = true;
1489
- final RangerSerializeClass ser = new RangerSerializeClass();
1490
- final CodeWriter extWr = new CodeWriter();
1491
- ser.createJSONSerializerFn(cl_1, cl_1.ctx.get(), extWr);
1492
- final String theCode = extWr.getCode();
1493
- final SourceCode code = new SourceCode(theCode);
1494
- code.filename = "extension " + ctx.currentClass.get().name;
1495
- final RangerLispParser parser = new RangerLispParser(code);
1496
- parser.parse();
1497
- final CodeNode rn = parser.rootNode.get();
1498
- this.WalkCollectMethods(rn, cl_1.ctx.get(), wr);
1499
- walkAlso.add(rn);
1500
- }
1501
- }
1502
-
1503
- public void WalkCollectMethods( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
1504
- boolean find_more = true;
1505
- if ( node.isFirstVref("systemunion") ) {
1506
- final CodeNode nameNode = node.getSecond();
1507
- final CodeNode instances = node.getThird();
1508
- final RangerAppClassDesc new_class = new RangerAppClassDesc();
1509
- new_class.name = nameNode.vref;
1510
- new_class.nameNode = Optional.of(nameNode);
1511
- ctx.addClass(nameNode.vref, new_class);
1512
- new_class.is_system_union = true;
1513
- for ( int i = 0; i < instances.children.size(); i++) {
1514
- CodeNode ch = instances.children.get(i);
1515
- new_class.is_union_of.add(ch.vref);
1516
- }
1517
- nameNode.clDesc = Optional.of(new_class);
1518
- return;
1519
- }
1520
- if ( node.isFirstVref("systemclass") ) {
1521
- final CodeNode nameNode_1 = node.getSecond();
1522
- final CodeNode instances_1 = node.getThird();
1523
- final RangerAppClassDesc new_class_1 = new RangerAppClassDesc();
1524
- new_class_1.name = nameNode_1.vref;
1525
- new_class_1.nameNode = Optional.of(nameNode_1);
1526
- ctx.addClass(nameNode_1.vref, new_class_1);
1527
- new_class_1.is_system = true;
1528
- for ( int i_1 = 0; i_1 < instances_1.children.size(); i_1++) {
1529
- CodeNode ch_1 = instances_1.children.get(i_1);
1530
- final CodeNode langName = ch_1.getFirst();
1531
- final CodeNode langClassName = ch_1.getSecond();
1532
- new_class_1.systemNames.put(langName.vref, langClassName.vref);
1533
- }
1534
- nameNode_1.is_system_class = true;
1535
- nameNode_1.clDesc = Optional.of(new_class_1);
1536
- return;
1537
- }
1538
- if ( node.isFirstVref("Extends") ) {
1539
- final CodeNode extList = node.children.get(1);
1540
- final Optional<RangerAppClassDesc> currC = ctx.currentClass;
1541
- for ( int ii = 0; ii < extList.children.size(); ii++) {
1542
- CodeNode ee = extList.children.get(ii);
1543
- currC.get().addParentClass(ee.vref);
1544
- final RangerAppClassDesc ParentClass = ctx.findClass(ee.vref);
1545
- ParentClass.is_inherited = true;
1546
- }
1547
- }
1548
- if ( node.isFirstVref("Constructor") ) {
1549
- final Optional<RangerAppClassDesc> currC_1 = ctx.currentClass;
1550
- final RangerAppWriterContext subCtx = currC_1.get().ctx.get().fork();
1551
- currC_1.get().has_constructor = true;
1552
- currC_1.get().constructor_node = Optional.of(node);
1553
- final RangerAppFunctionDesc m = new RangerAppFunctionDesc();
1554
- m.name = "Constructor";
1555
- m.node = Optional.of(node);
1556
- m.nameNode = Optional.of(node.children.get(0));
1557
- m.fnBody = Optional.of(node.children.get(2));
1558
- m.fnCtx = Optional.of(subCtx);
1559
- final CodeNode args = node.children.get(1);
1560
- for ( int ii_1 = 0; ii_1 < args.children.size(); ii_1++) {
1561
- CodeNode arg = args.children.get(ii_1);
1562
- final RangerAppParamDesc p = new RangerAppParamDesc();
1563
- p.name = arg.vref;
1564
- p.value_type = arg.value_type;
1565
- p.node = Optional.of(arg);
1566
- p.nameNode = Optional.of(arg);
1567
- p.refType = 1;
1568
- p.varType = 4;
1569
- m.params.add(p);
1570
- arg.hasParamDesc = true;
1571
- arg.paramDesc = Optional.of(p);
1572
- arg.eval_type = arg.value_type;
1573
- arg.eval_type_name = arg.type_name;
1574
- subCtx.defineVariable(p.name, p);
1575
- }
1576
- currC_1.get().constructor_fn = Optional.of(m);
1577
- find_more = false;
1578
- }
1579
- if ( node.isFirstVref("trait") ) {
1580
- final String s = node.getVRefAt(1);
1581
- final CodeNode classNameNode = node.getSecond();
1582
- final RangerAppClassDesc new_class_2 = new RangerAppClassDesc();
1583
- new_class_2.name = s;
1584
- final RangerAppWriterContext subCtx_1 = ctx.fork();
1585
- ctx.setCurrentClass(new_class_2);
1586
- subCtx_1.setCurrentClass(new_class_2);
1587
- new_class_2.ctx = Optional.of(subCtx_1);
1588
- new_class_2.nameNode = Optional.of(classNameNode);
1589
- ctx.addClass(s, new_class_2);
1590
- new_class_2.classNode = Optional.of(node);
1591
- new_class_2.node = Optional.of(node);
1592
- new_class_2.is_trait = true;
1593
- }
1594
- if ( node.isFirstVref("CreateClass") || node.isFirstVref("class") ) {
1595
- final String s_1 = node.getVRefAt(1);
1596
- final CodeNode classNameNode_1 = node.getSecond();
1597
- if ( classNameNode_1.has_vref_annotation ) {
1598
- System.out.println(String.valueOf( "%% vref_annotation" ) );
1599
- final Optional<CodeNode> ann = classNameNode_1.vref_annotation;
1600
- System.out.println(String.valueOf( (classNameNode_1.vref + " : ") + ann.get().getCode() ) );
1601
- ctx.addTemplateClass(classNameNode_1.vref, node);
1602
- find_more = false;
1603
- } else {
1604
- final RangerAppClassDesc new_class_3 = new RangerAppClassDesc();
1605
- new_class_3.name = s_1;
1606
- final RangerAppWriterContext subCtx_2 = ctx.fork();
1607
- ctx.setCurrentClass(new_class_3);
1608
- subCtx_2.setCurrentClass(new_class_3);
1609
- new_class_3.ctx = Optional.of(subCtx_2);
1610
- new_class_3.nameNode = Optional.of(classNameNode_1);
1611
- ctx.addClass(s_1, new_class_3);
1612
- new_class_3.classNode = Optional.of(node);
1613
- new_class_3.node = Optional.of(node);
1614
- if ( node.hasBooleanProperty("trait") ) {
1615
- new_class_3.is_trait = true;
1616
- }
1617
- }
1618
- }
1619
- if ( node.isFirstVref("TemplateClass") ) {
1620
- final String s_2 = node.getVRefAt(1);
1621
- ctx.addTemplateClass(s_2, node);
1622
- find_more = false;
1623
- }
1624
- if ( node.isFirstVref("Extends") ) {
1625
- final CodeNode list = node.children.get(1);
1626
- for ( int i_2 = 0; i_2 < list.children.size(); i_2++) {
1627
- CodeNode cname = list.children.get(i_2);
1628
- final RangerAppClassDesc extC = ctx.findClass(cname.vref);
1629
- for ( int i_3 = 0; i_3 < extC.variables.size(); i_3++) {
1630
- RangerAppParamDesc vv = extC.variables.get(i_3);
1631
- final Optional<RangerAppClassDesc> currC_2 = ctx.currentClass;
1632
- final Optional<RangerAppWriterContext> subCtx_3 = currC_2.get().ctx;
1633
- subCtx_3.get().defineVariable(vv.name, vv);
1634
- }
1635
- }
1636
- find_more = false;
1637
- }
1638
- if ( node.isFirstVref("def") || node.isFirstVref("let") ) {
1639
- final String s_3 = node.getVRefAt(1);
1640
- final CodeNode vDef = node.children.get(1);
1641
- final RangerAppParamDesc p_1 = new RangerAppParamDesc();
1642
- if ( !s_3.equals(ctx.transformWord(s_3)) ) {
1643
- ctx.addError(node, ("Can not use reserved word " + s_3) + " as class propery");
1644
- }
1645
- p_1.name = s_3;
1646
- p_1.value_type = vDef.value_type;
1647
- p_1.node = Optional.of(node);
1648
- p_1.is_class_variable = true;
1649
- p_1.varType = 8;
1650
- p_1.node = Optional.of(node);
1651
- p_1.nameNode = Optional.of(vDef);
1652
- vDef.hasParamDesc = true;
1653
- vDef.ownParamDesc = Optional.of(p_1);
1654
- vDef.paramDesc = Optional.of(p_1);
1655
- node.hasParamDesc = true;
1656
- node.paramDesc = Optional.of(p_1);
1657
- if ( vDef.hasFlag("weak") ) {
1658
- p_1.changeStrength(0, 2, p_1.nameNode.get());
1659
- } else {
1660
- p_1.changeStrength(2, 2, p_1.nameNode.get());
1661
- }
1662
- if ( (node.children.size()) > 2 ) {
1663
- p_1.set_cnt = 1;
1664
- p_1.init_cnt = 1;
1665
- p_1.def_value = Optional.of(node.children.get(2));
1666
- p_1.is_optional = false;
1667
- if ( p_1.def_value.get().value_type == 4 ) {
1668
- vDef.type_name = "string";
1669
- }
1670
- if ( p_1.def_value.get().value_type == 3 ) {
1671
- vDef.type_name = "int";
1672
- }
1673
- if ( p_1.def_value.get().value_type == 2 ) {
1674
- vDef.type_name = "double";
1675
- }
1676
- if ( p_1.def_value.get().value_type == 5 ) {
1677
- vDef.type_name = "boolean";
1678
- }
1679
- } else {
1680
- p_1.is_optional = true;
1681
- if ( false == ((vDef.value_type == 6) || (vDef.value_type == 7)) ) {
1682
- vDef.setFlag("optional");
1683
- }
1684
- }
1685
- final Optional<RangerAppClassDesc> currC_3 = ctx.currentClass;
1686
- currC_3.get().addVariable(p_1);
1687
- final Optional<RangerAppWriterContext> subCtx_4 = currC_3.get().ctx;
1688
- subCtx_4.get().defineVariable(p_1.name, p_1);
1689
- p_1.is_class_variable = true;
1690
- }
1691
- if ( node.isFirstVref("operators") ) {
1692
- final CodeNode listOf = node.getSecond();
1693
- for ( int i_4 = 0; i_4 < listOf.children.size(); i_4++) {
1694
- CodeNode item = listOf.children.get(i_4);
1695
- ctx.createOperator(item);
1696
- }
1697
- find_more = false;
1698
- }
1699
- if ( node.isFirstVref("Import") || node.isFirstVref("import") ) {
1700
- final CodeNode fNameNode = node.children.get(1);
1701
- final String import_file = fNameNode.string_value;
1702
- if ( ctx.already_imported.containsKey(import_file) ) {
1703
- return;
1704
- } else {
1705
- ctx.already_imported.put(import_file, true);
1706
- }
1707
- final Optional<String> c = Optional.of(readFile("." + "/" + import_file , StandardCharsets.UTF_8 ));
1708
- final SourceCode code = new SourceCode(c.get());
1709
- code.filename = import_file;
1710
- final RangerLispParser parser = new RangerLispParser(code);
1711
- parser.parse();
1712
- final Optional<CodeNode> rnode = parser.rootNode;
1713
- this.WalkCollectMethods(rnode.get(), ctx, wr);
1714
- find_more = false;
1715
- }
1716
- if ( node.isFirstVref("does") ) {
1717
- final CodeNode defName = node.getSecond();
1718
- final Optional<RangerAppClassDesc> currC_4 = ctx.currentClass;
1719
- currC_4.get().consumes_traits.add(defName.vref);
1720
- final ClassJoinPoint joinPoint = new ClassJoinPoint();
1721
- joinPoint.class_def = currC_4;
1722
- joinPoint.node = Optional.of(node);
1723
- classesWithTraits.add(joinPoint);
1724
- }
1725
- if ( node.isFirstVref("StaticMethod") || node.isFirstVref("sfn") ) {
1726
- final String s_4 = node.getVRefAt(1);
1727
- final Optional<RangerAppClassDesc> currC_5 = ctx.currentClass;
1728
- final RangerAppFunctionDesc m_1 = new RangerAppFunctionDesc();
1729
- m_1.name = s_4;
1730
- m_1.compiledName = ctx.transformWord(s_4);
1731
- m_1.node = Optional.of(node);
1732
- m_1.is_static = true;
1733
- m_1.nameNode = Optional.of(node.children.get(1));
1734
- m_1.nameNode.get().ifNoTypeSetToVoid();
1735
- final CodeNode args_1 = node.children.get(2);
1736
- m_1.fnBody = Optional.of(node.children.get(3));
1737
- for ( int ii_2 = 0; ii_2 < args_1.children.size(); ii_2++) {
1738
- CodeNode arg_1 = args_1.children.get(ii_2);
1739
- final RangerAppParamDesc p_2 = new RangerAppParamDesc();
1740
- p_2.name = arg_1.vref;
1741
- p_2.value_type = arg_1.value_type;
1742
- p_2.node = Optional.of(arg_1);
1743
- p_2.init_cnt = 1;
1744
- p_2.nameNode = Optional.of(arg_1);
1745
- p_2.refType = 1;
1746
- p_2.varType = 4;
1747
- m_1.params.add(p_2);
1748
- arg_1.hasParamDesc = true;
1749
- arg_1.paramDesc = Optional.of(p_2);
1750
- arg_1.eval_type = arg_1.value_type;
1751
- arg_1.eval_type_name = arg_1.type_name;
1752
- if ( arg_1.hasFlag("strong") ) {
1753
- p_2.changeStrength(1, 1, p_2.nameNode.get());
1754
- } else {
1755
- arg_1.setFlag("lives");
1756
- p_2.changeStrength(0, 1, p_2.nameNode.get());
1757
- }
1758
- }
1759
- currC_5.get().addStaticMethod(m_1);
1760
- find_more = false;
1761
- }
1762
- if ( node.isFirstVref("extension") ) {
1763
- final String s_5 = node.getVRefAt(1);
1764
- final RangerAppClassDesc old_class = ctx.findClass(s_5);
1765
- ctx.setCurrentClass(old_class);
1766
- System.out.println(String.valueOf( "extension for " + s_5 ) );
1767
- }
1768
- if ( node.isFirstVref("PublicMethod") || node.isFirstVref("fn") ) {
1769
- final CodeNode cn = node.getSecond();
1770
- final String s_6 = node.getVRefAt(1);
1771
- cn.ifNoTypeSetToVoid();
1772
- final Optional<RangerAppClassDesc> currC_6 = ctx.currentClass;
1773
- if ( currC_6.get().hasOwnMethod(s_6) ) {
1774
- ctx.addError(node, "Error: method of same name declared earlier. Overriding function declarations is not currently allowed!");
1775
- return;
1776
- }
1777
- if ( cn.hasFlag("main") ) {
1778
- ctx.addError(node, "Error: dynamic method declared as @(main). Use static 'sfn' instead of 'fn'.");
1779
- return;
1780
- }
1781
- final RangerAppFunctionDesc m_2 = new RangerAppFunctionDesc();
1782
- m_2.name = s_6;
1783
- m_2.compiledName = ctx.transformWord(s_6);
1784
- m_2.node = Optional.of(node);
1785
- m_2.nameNode = Optional.of(node.children.get(1));
1786
- if ( node.hasBooleanProperty("strong") ) {
1787
- m_2.refType = 2;
1788
- } else {
1789
- m_2.refType = 1;
1790
- }
1791
- final RangerAppWriterContext subCtx_5 = currC_6.get().ctx.get().fork();
1792
- subCtx_5.is_function = true;
1793
- subCtx_5.currentMethod = Optional.of(m_2);
1794
- m_2.fnCtx = Optional.of(subCtx_5);
1795
- if ( cn.hasFlag("weak") ) {
1796
- m_2.changeStrength(0, 1, node);
1797
- } else {
1798
- m_2.changeStrength(1, 1, node);
1799
- }
1800
- final CodeNode args_2 = node.children.get(2);
1801
- m_2.fnBody = Optional.of(node.children.get(3));
1802
- for ( int ii_3 = 0; ii_3 < args_2.children.size(); ii_3++) {
1803
- CodeNode arg_2 = args_2.children.get(ii_3);
1804
- final RangerAppParamDesc p2 = new RangerAppParamDesc();
1805
- p2.name = arg_2.vref;
1806
- p2.value_type = arg_2.value_type;
1807
- p2.node = Optional.of(arg_2);
1808
- p2.nameNode = Optional.of(arg_2);
1809
- p2.init_cnt = 1;
1810
- p2.refType = 1;
1811
- p2.initRefType = 1;
1812
- p2.debugString = "--> collected ";
1813
- if ( args_2.hasBooleanProperty("strong") ) {
1814
- p2.debugString = "--> collected as STRONG";
1815
- ctx.log(node, "memory5", "strong param should move local ownership to call ***");
1816
- p2.refType = 2;
1817
- p2.initRefType = 2;
1818
- }
1819
- p2.varType = 4;
1820
- m_2.params.add(p2);
1821
- arg_2.hasParamDesc = true;
1822
- arg_2.paramDesc = Optional.of(p2);
1823
- arg_2.eval_type = arg_2.value_type;
1824
- arg_2.eval_type_name = arg_2.type_name;
1825
- if ( arg_2.hasFlag("strong") ) {
1826
- p2.changeStrength(1, 1, p2.nameNode.get());
1827
- } else {
1828
- arg_2.setFlag("lives");
1829
- p2.changeStrength(0, 1, p2.nameNode.get());
1830
- }
1831
- subCtx_5.defineVariable(p2.name, p2);
1832
- }
1833
- currC_6.get().addMethod(m_2);
1834
- find_more = false;
1835
- }
1836
- if ( find_more ) {
1837
- for ( int i_5 = 0; i_5 < node.children.size(); i_5++) {
1838
- CodeNode item_1 = node.children.get(i_5);
1839
- this.WalkCollectMethods(item_1, ctx, wr);
1840
- }
1841
- }
1842
- if ( node.hasBooleanProperty("serialize") ) {
1843
- serializedClasses.add(ctx.currentClass.get());
1844
- }
1845
- }
1846
-
1847
- public void FindWeakRefs( CodeNode node , RangerAppWriterContext ctx , CodeWriter wr ) {
1848
- final ArrayList<RangerAppClassDesc> list = ctx.getClasses();
1849
- for ( int i = 0; i < list.size(); i++) {
1850
- RangerAppClassDesc classDesc = list.get(i);
1851
- for ( int i2 = 0; i2 < classDesc.variables.size(); i2++) {
1852
- RangerAppParamDesc varD = classDesc.variables.get(i2);
1853
- if ( varD.refType == 1 ) {
1854
- if ( varD.isArray() ) {
1855
- /** unused: final Optional<CodeNode> nn = varD.nameNode **/ ;
1856
- }
1857
- if ( varD.isHash() ) {
1858
- /** unused: final Optional<CodeNode> nn_1 = varD.nameNode **/ ;
1859
- }
1860
- if ( varD.isObject() ) {
1861
- /** unused: final Optional<CodeNode> nn_2 = varD.nameNode **/ ;
1862
- }
1863
- }
1864
- }
1865
- }
1866
- }
1867
-
1868
- public Optional<RangerAppFunctionDesc> findFunctionDesc( CodeNode obj , RangerAppWriterContext ctx , CodeWriter wr ) {
1869
- Optional<RangerAppParamDesc> varDesc = Optional.empty();
1870
- Optional<RangerAppFunctionDesc> varFnDesc = Optional.empty();
1871
- if ( !obj.vref.equals(this.getThisName()) ) {
1872
- if ( (obj.ns.size()) > 1 ) {
1873
- final int cnt = obj.ns.size();
1874
- Optional<RangerAppParamDesc> classRefDesc = Optional.empty();
1875
- Optional<RangerAppClassDesc> classDesc = Optional.empty();
1876
- for ( int i = 0; i < obj.ns.size(); i++) {
1877
- String strname = obj.ns.get(i);
1878
- if ( i == 0 ) {
1879
- if ( strname.equals(this.getThisName()) ) {
1880
- classDesc = ctx.getCurrentClass();
1881
- } else {
1882
- if ( ctx.isDefinedClass(strname) ) {
1883
- classDesc = Optional.of(ctx.findClass(strname));
1884
- continue;
1885
- }
1886
- classRefDesc = Optional.of(ctx.getVariableDef(strname));
1887
- if ( (!classRefDesc.isPresent()) || (!classRefDesc.get().nameNode.isPresent()) ) {
1888
- ctx.addError(obj, "Error, no description for called object: " + strname);
1889
- break;
1890
- }
1891
- classRefDesc.get().ref_cnt = 1 + classRefDesc.get().ref_cnt;
1892
- classDesc = Optional.of(ctx.findClass(classRefDesc.get().nameNode.get().type_name));
1893
- if ( !classDesc.isPresent() ) {
1894
- return Optional.ofNullable((varFnDesc.isPresent() ? (RangerAppFunctionDesc)varFnDesc.get() : null ) );
1895
- }
1896
- }
1897
- } else {
1898
- if ( !classDesc.isPresent() ) {
1899
- return Optional.ofNullable((varFnDesc.isPresent() ? (RangerAppFunctionDesc)varFnDesc.get() : null ) );
1900
- }
1901
- if ( i < (cnt - 1) ) {
1902
- varDesc = classDesc.get().findVariable(strname);
1903
- if ( !varDesc.isPresent() ) {
1904
- ctx.addError(obj, "Error, no description for refenced obj: " + strname);
1905
- }
1906
- final String subClass = varDesc.get().getTypeName();
1907
- classDesc = Optional.of(ctx.findClass(subClass));
1908
- continue;
1909
- }
1910
- if ( classDesc.isPresent() ) {
1911
- varFnDesc = classDesc.get().findMethod(strname);
1912
- if ( !varFnDesc.isPresent() ) {
1913
- varFnDesc = classDesc.get().findStaticMethod(strname);
1914
- if ( !varFnDesc.isPresent() ) {
1915
- ctx.addError(obj, " function variable not found " + strname);
1916
- }
1917
- }
1918
- }
1919
- }
1920
- }
1921
- return Optional.ofNullable((varFnDesc.isPresent() ? (RangerAppFunctionDesc)varFnDesc.get() : null ) );
1922
- }
1923
- final Optional<RangerAppClassDesc> udesc = ctx.getCurrentClass();
1924
- final RangerAppClassDesc currClass = udesc.get();
1925
- varFnDesc = currClass.findMethod(obj.vref);
1926
- if ( varFnDesc.get().nameNode.isPresent() ) {
1927
- } else {
1928
- ctx.addError(obj, "Error, no description for called function: " + obj.vref);
1929
- }
1930
- return Optional.ofNullable((varFnDesc.isPresent() ? (RangerAppFunctionDesc)varFnDesc.get() : null ) );
1931
- }
1932
- ctx.addError(obj, "Can not call 'this' like function");
1933
- varFnDesc = Optional.of(new RangerAppFunctionDesc());
1934
- return Optional.ofNullable((varFnDesc.isPresent() ? (RangerAppFunctionDesc)varFnDesc.get() : null ) );
1935
- }
1936
-
1937
- public Optional<RangerAppParamDesc> findParamDesc( CodeNode obj , RangerAppWriterContext ctx , CodeWriter wr ) {
1938
- Optional<RangerAppParamDesc> varDesc = Optional.empty();
1939
- boolean set_nsp = false;
1940
- Optional<RangerAppClassDesc> classDesc = Optional.empty();
1941
- if ( 0 == (obj.nsp.size()) ) {
1942
- set_nsp = true;
1943
- }
1944
- if ( !obj.vref.equals(this.getThisName()) ) {
1945
- if ( (obj.ns.size()) > 1 ) {
1946
- final int cnt = obj.ns.size();
1947
- Optional<RangerAppParamDesc> classRefDesc = Optional.empty();
1948
- for ( int i = 0; i < obj.ns.size(); i++) {
1949
- String strname = obj.ns.get(i);
1950
- if ( i == 0 ) {
1951
- if ( strname.equals(this.getThisName()) ) {
1952
- classDesc = ctx.getCurrentClass();
1953
- if ( set_nsp ) {
1954
- obj.nsp.add(classDesc.get());
1955
- }
1956
- } else {
1957
- if ( ctx.isDefinedClass(strname) ) {
1958
- classDesc = Optional.of(ctx.findClass(strname));
1959
- if ( set_nsp ) {
1960
- obj.nsp.add(classDesc.get());
1961
- }
1962
- continue;
1963
- }
1964
- classRefDesc = Optional.of(ctx.getVariableDef(strname));
1965
- if ( !classRefDesc.isPresent() ) {
1966
- ctx.addError(obj, "Error, no description for called object: " + strname);
1967
- break;
1968
- }
1969
- if ( set_nsp ) {
1970
- obj.nsp.add(classRefDesc.get());
1971
- }
1972
- classRefDesc.get().ref_cnt = 1 + classRefDesc.get().ref_cnt;
1973
- classDesc = Optional.of(ctx.findClass(classRefDesc.get().nameNode.get().type_name));
1974
- }
1975
- } else {
1976
- if ( i < (cnt - 1) ) {
1977
- varDesc = classDesc.get().findVariable(strname);
1978
- if ( !varDesc.isPresent() ) {
1979
- ctx.addError(obj, "Error, no description for refenced obj: " + strname);
1980
- }
1981
- final String subClass = varDesc.get().getTypeName();
1982
- classDesc = Optional.of(ctx.findClass(subClass));
1983
- if ( set_nsp ) {
1984
- obj.nsp.add(varDesc.get());
1985
- }
1986
- continue;
1987
- }
1988
- if ( classDesc.isPresent() ) {
1989
- varDesc = classDesc.get().findVariable(strname);
1990
- if ( !varDesc.isPresent() ) {
1991
- Optional<RangerAppFunctionDesc> classMethod = classDesc.get().findMethod(strname);
1992
- if ( !classMethod.isPresent() ) {
1993
- classMethod = classDesc.get().findStaticMethod(strname);
1994
- if ( !classMethod.isPresent() ) {
1995
- ctx.addError(obj, "variable not found " + strname);
1996
- }
1997
- }
1998
- if ( classMethod.isPresent() ) {
1999
- if ( set_nsp ) {
2000
- obj.nsp.add(classMethod.get());
2001
- }
2002
- return Optional.ofNullable((classMethod.isPresent() ? (RangerAppParamDesc)classMethod.get() : null ) );
2003
- }
2004
- }
2005
- if ( set_nsp ) {
2006
- obj.nsp.add(varDesc.get());
2007
- }
2008
- }
2009
- }
2010
- }
2011
- return Optional.ofNullable((varDesc.isPresent() ? (RangerAppParamDesc)varDesc.get() : null ) );
2012
- }
2013
- varDesc = Optional.of(ctx.getVariableDef(obj.vref));
2014
- if ( varDesc.get().nameNode.isPresent() ) {
2015
- } else {
2016
- System.out.println(String.valueOf( "findParamDesc : description not found for " + obj.vref ) );
2017
- if ( varDesc.isPresent() ) {
2018
- System.out.println(String.valueOf( "Vardesc was found though..." + varDesc.get().name ) );
2019
- }
2020
- ctx.addError(obj, "Error, no description for called object: " + obj.vref);
2021
- }
2022
- return Optional.ofNullable((varDesc.isPresent() ? (RangerAppParamDesc)varDesc.get() : null ) );
2023
- }
2024
- final Optional<RangerAppClassDesc> cc = ctx.getCurrentClass();
2025
- return Optional.ofNullable((cc.isPresent() ? (RangerAppParamDesc)cc.get() : null ) );
2026
- }
2027
-
2028
- public boolean areEqualTypes( CodeNode n1 , CodeNode n2 , RangerAppWriterContext ctx ) {
2029
- if ( (((n1.eval_type != 0) && (n2.eval_type != 0)) && ((n1.eval_type_name.length()) > 0)) && ((n2.eval_type_name.length()) > 0) ) {
2030
- if ( n1.eval_type_name.equals(n2.eval_type_name) ) {
2031
- } else {
2032
- boolean b_ok = false;
2033
- if ( ctx.isEnumDefined(n1.eval_type_name) && (n2.eval_type_name.equals("int")) ) {
2034
- b_ok = true;
2035
- }
2036
- if ( ctx.isEnumDefined(n2.eval_type_name) && (n1.eval_type_name.equals("int")) ) {
2037
- b_ok = true;
2038
- }
2039
- if ( (n1.eval_type_name.equals("char")) && (n2.eval_type_name.equals("int")) ) {
2040
- b_ok = true;
2041
- }
2042
- if ( (n1.eval_type_name.equals("int")) && (n2.eval_type_name.equals("char")) ) {
2043
- b_ok = true;
2044
- }
2045
- if ( ctx.isDefinedClass(n1.eval_type_name) && ctx.isDefinedClass(n2.eval_type_name) ) {
2046
- final RangerAppClassDesc c1 = ctx.findClass(n1.eval_type_name);
2047
- final RangerAppClassDesc c2 = ctx.findClass(n2.eval_type_name);
2048
- if ( c1.isSameOrParentClass(n2.eval_type_name, ctx) ) {
2049
- return true;
2050
- }
2051
- if ( c2.isSameOrParentClass(n1.eval_type_name, ctx) ) {
2052
- return true;
2053
- }
2054
- }
2055
- if ( b_ok == false ) {
2056
- return false;
2057
- }
2058
- }
2059
- }
2060
- return true;
2061
- }
2062
-
2063
- public void shouldBeEqualTypes( CodeNode n1 , CodeNode n2 , RangerAppWriterContext ctx , String msg ) {
2064
- if ( (((n1.eval_type != 0) && (n2.eval_type != 0)) && ((n1.eval_type_name.length()) > 0)) && ((n2.eval_type_name.length()) > 0) ) {
2065
- if ( n1.eval_type_name.equals(n2.eval_type_name) ) {
2066
- } else {
2067
- boolean b_ok = false;
2068
- if ( ctx.isEnumDefined(n1.eval_type_name) && (n2.eval_type_name.equals("int")) ) {
2069
- b_ok = true;
2070
- }
2071
- if ( ctx.isEnumDefined(n2.eval_type_name) && (n1.eval_type_name.equals("int")) ) {
2072
- b_ok = true;
2073
- }
2074
- if ( ctx.isDefinedClass(n2.eval_type_name) ) {
2075
- final RangerAppClassDesc cc = ctx.findClass(n2.eval_type_name);
2076
- if ( cc.isSameOrParentClass(n1.eval_type_name, ctx) ) {
2077
- b_ok = true;
2078
- }
2079
- }
2080
- if ( (n1.eval_type_name.equals("char")) && (n2.eval_type_name.equals("int")) ) {
2081
- b_ok = true;
2082
- }
2083
- if ( (n1.eval_type_name.equals("int")) && (n2.eval_type_name.equals("char")) ) {
2084
- b_ok = true;
2085
- }
2086
- if ( b_ok == false ) {
2087
- ctx.addError(n1, (((("Type mismatch " + n2.eval_type_name) + " <> ") + n1.eval_type_name) + ". ") + msg);
2088
- }
2089
- }
2090
- }
2091
- }
2092
-
2093
- public void shouldBeExpression( CodeNode n1 , RangerAppWriterContext ctx , String msg ) {
2094
- if ( n1.expression == false ) {
2095
- ctx.addError(n1, msg);
2096
- }
2097
- }
2098
-
2099
- public void shouldHaveChildCnt( int cnt , CodeNode n1 , RangerAppWriterContext ctx , String msg ) {
2100
- if ( (n1.children.size()) != cnt ) {
2101
- ctx.addError(n1, msg);
2102
- }
2103
- }
2104
-
2105
- public void shouldBeNumeric( CodeNode n1 , RangerAppWriterContext ctx , String msg ) {
2106
- if ( (n1.eval_type != 0) && ((n1.eval_type_name.length()) > 0) ) {
2107
- if ( false == ((n1.eval_type_name.equals("double")) || (n1.eval_type_name.equals("int"))) ) {
2108
- ctx.addError(n1, (("Not numeric: " + n1.eval_type_name) + ". ") + msg);
2109
- }
2110
- }
2111
- }
2112
-
2113
- public void shouldBeArray( CodeNode n1 , RangerAppWriterContext ctx , String msg ) {
2114
- if ( n1.eval_type != 6 ) {
2115
- ctx.addError(n1, "Expecting array. " + msg);
2116
- }
2117
- }
2118
-
2119
- public void shouldBeType( String type_name , CodeNode n1 , RangerAppWriterContext ctx , String msg ) {
2120
- if ( (n1.eval_type != 0) && ((n1.eval_type_name.length()) > 0) ) {
2121
- if ( n1.eval_type_name.equals(type_name) ) {
2122
- } else {
2123
- boolean b_ok = false;
2124
- if ( ctx.isEnumDefined(n1.eval_type_name) && (type_name.equals("int")) ) {
2125
- b_ok = true;
2126
- }
2127
- if ( ctx.isEnumDefined(type_name) && (n1.eval_type_name.equals("int")) ) {
2128
- b_ok = true;
2129
- }
2130
- if ( (n1.eval_type_name.equals("char")) && (type_name.equals("int")) ) {
2131
- b_ok = true;
2132
- }
2133
- if ( (n1.eval_type_name.equals("int")) && (type_name.equals("char")) ) {
2134
- b_ok = true;
2135
- }
2136
- if ( b_ok == false ) {
2137
- ctx.addError(n1, (((("Type mismatch " + type_name) + " <> ") + n1.eval_type_name) + ". ") + msg);
2138
- }
2139
- }
2140
- }
2141
- }
2142
- }