FunctionIdentifier.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. using System.Collections.Generic;
  2. using NTERA.EmuEra.Game.EraEmu.GameData.Function;
  3. namespace NTERA.EmuEra.Game.EraEmu.GameProc.Function
  4. {
  5. /// <summary>
  6. /// FunctionCodeのラッパー
  7. /// BuiltInFunctionManagerを元にクラス化
  8. /// </summary>
  9. internal sealed partial class FunctionIdentifier
  10. {
  11. #region flag定義
  12. //いちいちFunctionFlag.FLOW_CONTROLとか書くのが面倒だったからenumではなくconst intで
  13. private const int FLOW_CONTROL = 0x00001;
  14. private const int EXTENDED = 0x00002;//Emuera拡張命令
  15. private const int METHOD_SAFE = 0x00004;//#Function中で呼び出してよい命令。WAITなど入力を伴うもの、CALLなど関数呼び出しを伴うものは不可。
  16. private const int DEBUG_FUNC = 0x00008;//-Debug引数付きで起動した場合にのみ実行される命令。
  17. private const int PARTIAL = 0x00010;//複数行に渡る構文の一部である命令。SIF文の次に来てはいけない。debugコマンドからの呼び出しも不適当。
  18. private const int FORCE_SETARG = 0x00020;//ロード時に必ず引数解析を行う必要のあるもの。IFやSELECTCASEなど
  19. private const int IS_JUMP = 0x00040;//JUMP命令
  20. private const int IS_TRY = 0x00080;//TRY系命令
  21. private const int IS_TRYC = 0x08000;//TRY系命令
  22. private const int PRINT_NEWLINE = 0x00100;//PRINT命令で出力後改行するもの
  23. private const int PRINT_WAITINPUT = 0x00200;//PRINT命令で出力後入力待ちするもの
  24. private const int PRINT_SINGLE = 0x00400;//PRINTSINGLE系
  25. private const int ISPRINTDFUNC = 0x00800;//PRINTD系判定用
  26. private const int ISPRINTKFUNC = 0x01000;//PRINTK系判定用
  27. private const int IS_PRINT = 0x02000;//SkipPrintにより飛ばされる命令。PRINT系及びWAIT系。DEBUGPRINTは含まない。
  28. private const int IS_INPUT = 0x04000;//userDefinedSkipを警告する命令。INPUT系。
  29. private const int IS_PRINTDATA = 0x10000;//PRINTDATA系判定用、PRINTとは一部処理が違うので、それ用。
  30. #endregion
  31. #region static
  32. //元BuiltInFunctionManager部分
  33. private static readonly Dictionary<string, FunctionIdentifier> funcDic = new Dictionary<string, FunctionIdentifier>();
  34. static readonly Dictionary<FunctionCode, string> funcMatch = new Dictionary<FunctionCode, string>();
  35. static readonly Dictionary<FunctionCode, FunctionCode> funcParent = new Dictionary<FunctionCode, FunctionCode>();
  36. static readonly AbstractInstruction methodInstruction;
  37. private static void AddFunction(FunctionCode code, AbstractInstruction inst, int additionalFlag = 0)
  38. {
  39. var key = code.ToString();
  40. if (Config.Config.ICFunction)
  41. key = key.ToUpper();
  42. funcDic.Add(key, new FunctionIdentifier(key, code, inst, additionalFlag));
  43. }
  44. private static void AddFunction(FunctionCode code, ArgumentBuilder arg)
  45. { AddFunction(code, arg, 0); }
  46. private static void AddFunction(FunctionCode code, ArgumentBuilder arg, int flag)
  47. {
  48. var key = code.ToString();
  49. if (Config.Config.ICFunction)
  50. key = key.ToUpper();
  51. funcDic.Add(key, new FunctionIdentifier(key, code, arg, flag));
  52. }
  53. public static Dictionary<string, FunctionIdentifier> GetInstructionNameDic()
  54. {
  55. return funcDic;
  56. }
  57. private static void addPrintFunction(FunctionCode code)
  58. {
  59. AddFunction(code, new PRINT_Instruction(code.ToString()));
  60. }
  61. private static void addPrintDataFunction(FunctionCode code)
  62. {
  63. AddFunction(code, new PRINT_DATA_Instruction(code.ToString()));
  64. }
  65. static FunctionIdentifier()
  66. {
  67. var argb = ArgumentParser.GetArgumentBuilderDictionary();
  68. methodInstruction = new METHOD_Instruction();
  69. SETFunction = new FunctionIdentifier("SET", FunctionCode.SET, new SET_Instruction());//代入文
  70. #region PRINT or INPUT
  71. addPrintFunction(FunctionCode.PRINT);
  72. addPrintFunction(FunctionCode.PRINTL);
  73. addPrintFunction(FunctionCode.PRINTW);
  74. addPrintFunction(FunctionCode.PRINTV);
  75. addPrintFunction(FunctionCode.PRINTVL);
  76. addPrintFunction(FunctionCode.PRINTVW);
  77. addPrintFunction(FunctionCode.PRINTS);
  78. addPrintFunction(FunctionCode.PRINTSL);
  79. addPrintFunction(FunctionCode.PRINTSW);
  80. addPrintFunction(FunctionCode.PRINTFORM);
  81. addPrintFunction(FunctionCode.PRINTFORML);
  82. addPrintFunction(FunctionCode.PRINTFORMW);
  83. addPrintFunction(FunctionCode.PRINTFORMS);
  84. addPrintFunction(FunctionCode.PRINTFORMSL);
  85. addPrintFunction(FunctionCode.PRINTFORMSW);
  86. addPrintFunction(FunctionCode.PRINTK);
  87. addPrintFunction(FunctionCode.PRINTKL);
  88. addPrintFunction(FunctionCode.PRINTKW);
  89. addPrintFunction(FunctionCode.PRINTVK);
  90. addPrintFunction(FunctionCode.PRINTVKL);
  91. addPrintFunction(FunctionCode.PRINTVKW);
  92. addPrintFunction(FunctionCode.PRINTSK);
  93. addPrintFunction(FunctionCode.PRINTSKL);
  94. addPrintFunction(FunctionCode.PRINTSKW);
  95. addPrintFunction(FunctionCode.PRINTFORMK);
  96. addPrintFunction(FunctionCode.PRINTFORMKL);
  97. addPrintFunction(FunctionCode.PRINTFORMKW);
  98. addPrintFunction(FunctionCode.PRINTFORMSK);
  99. addPrintFunction(FunctionCode.PRINTFORMSKL);
  100. addPrintFunction(FunctionCode.PRINTFORMSKW);
  101. addPrintFunction(FunctionCode.PRINTD);
  102. addPrintFunction(FunctionCode.PRINTDL);
  103. addPrintFunction(FunctionCode.PRINTDW);
  104. addPrintFunction(FunctionCode.PRINTVD);
  105. addPrintFunction(FunctionCode.PRINTVDL);
  106. addPrintFunction(FunctionCode.PRINTVDW);
  107. addPrintFunction(FunctionCode.PRINTSD);
  108. addPrintFunction(FunctionCode.PRINTSDL);
  109. addPrintFunction(FunctionCode.PRINTSDW);
  110. addPrintFunction(FunctionCode.PRINTFORMD);
  111. addPrintFunction(FunctionCode.PRINTFORMDL);
  112. addPrintFunction(FunctionCode.PRINTFORMDW);
  113. addPrintFunction(FunctionCode.PRINTFORMSD);
  114. addPrintFunction(FunctionCode.PRINTFORMSDL);
  115. addPrintFunction(FunctionCode.PRINTFORMSDW);
  116. addPrintFunction(FunctionCode.PRINTSINGLE);
  117. addPrintFunction(FunctionCode.PRINTSINGLEV);
  118. addPrintFunction(FunctionCode.PRINTSINGLES);
  119. addPrintFunction(FunctionCode.PRINTSINGLEFORM);
  120. addPrintFunction(FunctionCode.PRINTSINGLEFORMS);
  121. addPrintFunction(FunctionCode.PRINTSINGLEK);
  122. addPrintFunction(FunctionCode.PRINTSINGLEVK);
  123. addPrintFunction(FunctionCode.PRINTSINGLESK);
  124. addPrintFunction(FunctionCode.PRINTSINGLEFORMK);
  125. addPrintFunction(FunctionCode.PRINTSINGLEFORMSK);
  126. addPrintFunction(FunctionCode.PRINTSINGLED);
  127. addPrintFunction(FunctionCode.PRINTSINGLEVD);
  128. addPrintFunction(FunctionCode.PRINTSINGLESD);
  129. addPrintFunction(FunctionCode.PRINTSINGLEFORMD);
  130. addPrintFunction(FunctionCode.PRINTSINGLEFORMSD);
  131. addPrintFunction(FunctionCode.PRINTC);
  132. addPrintFunction(FunctionCode.PRINTLC);
  133. addPrintFunction(FunctionCode.PRINTFORMC);
  134. addPrintFunction(FunctionCode.PRINTFORMLC);
  135. addPrintFunction(FunctionCode.PRINTCK);
  136. addPrintFunction(FunctionCode.PRINTLCK);
  137. addPrintFunction(FunctionCode.PRINTFORMCK);
  138. addPrintFunction(FunctionCode.PRINTFORMLCK);
  139. addPrintFunction(FunctionCode.PRINTCD);
  140. addPrintFunction(FunctionCode.PRINTLCD);
  141. addPrintFunction(FunctionCode.PRINTFORMCD);
  142. addPrintFunction(FunctionCode.PRINTFORMLCD);
  143. addPrintDataFunction(FunctionCode.PRINTDATA);
  144. addPrintDataFunction(FunctionCode.PRINTDATAL);
  145. addPrintDataFunction(FunctionCode.PRINTDATAW);
  146. addPrintDataFunction(FunctionCode.PRINTDATAK);
  147. addPrintDataFunction(FunctionCode.PRINTDATAKL);
  148. addPrintDataFunction(FunctionCode.PRINTDATAKW);
  149. addPrintDataFunction(FunctionCode.PRINTDATAD);
  150. addPrintDataFunction(FunctionCode.PRINTDATADL);
  151. addPrintDataFunction(FunctionCode.PRINTDATADW);
  152. AddFunction(FunctionCode.PRINTBUTTON, argb[FunctionArgType.SP_BUTTON], METHOD_SAFE | EXTENDED);
  153. AddFunction(FunctionCode.PRINTBUTTONC, argb[FunctionArgType.SP_BUTTON], METHOD_SAFE | EXTENDED);
  154. AddFunction(FunctionCode.PRINTBUTTONLC, argb[FunctionArgType.SP_BUTTON], METHOD_SAFE | EXTENDED);
  155. AddFunction(FunctionCode.PRINTPLAIN, argb[FunctionArgType.STR_NULLABLE], METHOD_SAFE | EXTENDED);
  156. AddFunction(FunctionCode.PRINTPLAINFORM, argb[FunctionArgType.FORM_STR_NULLABLE], METHOD_SAFE | EXTENDED);
  157. AddFunction(FunctionCode.PRINT_ABL, argb[FunctionArgType.INT_EXPRESSION], METHOD_SAFE);//能力。引数は登録番号
  158. AddFunction(FunctionCode.PRINT_TALENT, argb[FunctionArgType.INT_EXPRESSION], METHOD_SAFE);//素質
  159. AddFunction(FunctionCode.PRINT_MARK, argb[FunctionArgType.INT_EXPRESSION], METHOD_SAFE);//刻印
  160. AddFunction(FunctionCode.PRINT_EXP, argb[FunctionArgType.INT_EXPRESSION], METHOD_SAFE);//経験
  161. AddFunction(FunctionCode.PRINT_PALAM, argb[FunctionArgType.INT_EXPRESSION], METHOD_SAFE);//パラメータ
  162. AddFunction(FunctionCode.PRINT_ITEM, argb[FunctionArgType.VOID], METHOD_SAFE);//所持アイテム
  163. AddFunction(FunctionCode.PRINT_SHOPITEM, argb[FunctionArgType.VOID], METHOD_SAFE);//ショップで売っているアイテム
  164. AddFunction(FunctionCode.DRAWLINE, argb[FunctionArgType.VOID], METHOD_SAFE);//画面の左端から右端まで----と線を引く。
  165. AddFunction(FunctionCode.BAR, new BAR_Instruction(false));//[*****....]のようなグラフを書く。BAR (変数) , (最大値), (長さ)
  166. AddFunction(FunctionCode.BARL, new BAR_Instruction(true));//改行付き。
  167. AddFunction(FunctionCode.TIMES, new TIMES_Instruction());//小数計算。TIMES (変数) , (小数値)という形で使う。
  168. AddFunction(FunctionCode.WAIT, new WAIT_Instruction(false));
  169. AddFunction(FunctionCode.INPUT, new INPUT_Instruction());
  170. AddFunction(FunctionCode.INPUTS, new INPUTS_Instruction());
  171. AddFunction(FunctionCode.TINPUT, new TINPUT_Instruction(false));
  172. AddFunction(FunctionCode.TINPUTS, new TINPUTS_Instruction(false));
  173. AddFunction(FunctionCode.TONEINPUT, new TINPUT_Instruction(true));
  174. AddFunction(FunctionCode.TONEINPUTS, new TINPUTS_Instruction(true));
  175. AddFunction(FunctionCode.TWAIT, new TWAIT_Instruction());
  176. AddFunction(FunctionCode.WAITANYKEY, new WAITANYKEY_Instruction());
  177. AddFunction(FunctionCode.FORCEWAIT, new WAIT_Instruction(true));
  178. AddFunction(FunctionCode.ONEINPUT, new ONEINPUT_Instruction());
  179. AddFunction(FunctionCode.ONEINPUTS, new ONEINPUTS_Instruction());
  180. AddFunction(FunctionCode.CLEARLINE, new CLEARLINE_Instruction());
  181. AddFunction(FunctionCode.REUSELASTLINE, new REUSELASTLINE_Instruction());
  182. #endregion
  183. AddFunction(FunctionCode.UPCHECK, argb[FunctionArgType.VOID], METHOD_SAFE);//パラメータの変動
  184. AddFunction(FunctionCode.CUPCHECK, argb[FunctionArgType.INT_EXPRESSION], METHOD_SAFE | EXTENDED);
  185. AddFunction(FunctionCode.ADDCHARA, new ADDCHARA_Instruction(false, false));//(キャラ番号)のキャラクタを追加
  186. AddFunction(FunctionCode.ADDSPCHARA, new ADDCHARA_Instruction(true, false));//(キャラ番号)のSPキャラクタを追加(フラグ0を1にして作成)
  187. AddFunction(FunctionCode.ADDDEFCHARA, argb[FunctionArgType.VOID], METHOD_SAFE | EXTENDED);
  188. AddFunction(FunctionCode.ADDVOIDCHARA, new ADDVOIDCHARA_Instruction());//変数に何の設定のないキャラを作成
  189. AddFunction(FunctionCode.DELCHARA, new ADDCHARA_Instruction(false, true));//(キャラ登録番号)のキャラクタを削除。
  190. AddFunction(FunctionCode.PUTFORM, argb[FunctionArgType.FORM_STR_NULLABLE], METHOD_SAFE);//@SAVEINFO関数でのみ使用可能。PRINTFORMと同様の書式でセーブデータに概要をつける。
  191. AddFunction(FunctionCode.QUIT, argb[FunctionArgType.VOID]);//ゲームを終了
  192. AddFunction(FunctionCode.OUTPUTLOG, argb[FunctionArgType.VOID]);
  193. AddFunction(FunctionCode.BEGIN, new BEGIN_Instruction());//システム関数の実行。実行するとCALLの呼び出し元などを忘れてしまう。
  194. AddFunction(FunctionCode.SAVEGAME, new SAVELOADGAME_Instruction(true));//セーブ画面を呼ぶ。ショップのみ。
  195. AddFunction(FunctionCode.LOADGAME, new SAVELOADGAME_Instruction(false));//
  196. AddFunction(FunctionCode.SAVEDATA, argb[FunctionArgType.SP_SAVEDATA], METHOD_SAFE | EXTENDED);
  197. AddFunction(FunctionCode.LOADDATA, argb[FunctionArgType.INT_EXPRESSION], EXTENDED | FLOW_CONTROL);
  198. AddFunction(FunctionCode.DELDATA, new DELDATA_Instruction());
  199. AddFunction(FunctionCode.SAVEGLOBAL, new SAVEGLOBAL_Instruction());
  200. AddFunction(FunctionCode.LOADGLOBAL, new LOADGLOBAL_Instruction());
  201. AddFunction(FunctionCode.RESETDATA, new RESETDATA_Instruction());
  202. AddFunction(FunctionCode.RESETGLOBAL, new RESETGLOBAL_Instruction());
  203. AddFunction(FunctionCode.SIF, new SIF_Instruction());//一行のみIF
  204. AddFunction(FunctionCode.IF, new IF_Instruction());
  205. AddFunction(FunctionCode.ELSE, new ELSEIF_Instruction(FunctionArgType.VOID));
  206. AddFunction(FunctionCode.ELSEIF, new ELSEIF_Instruction(FunctionArgType.INT_EXPRESSION));
  207. AddFunction(FunctionCode.ENDIF, new ENDIF_Instruction(), METHOD_SAFE);
  208. AddFunction(FunctionCode.SELECTCASE, new SELECTCASE_Instruction());
  209. AddFunction(FunctionCode.CASE, new ELSEIF_Instruction(FunctionArgType.CASE), EXTENDED);
  210. AddFunction(FunctionCode.CASEELSE, new ELSEIF_Instruction(FunctionArgType.VOID), EXTENDED);
  211. AddFunction(FunctionCode.ENDSELECT, new ENDIF_Instruction(), METHOD_SAFE | EXTENDED);
  212. AddFunction(FunctionCode.REPEAT, new REPEAT_Instruction(false));//RENDまで繰り返し。繰り返した回数がCOUNTへ。ネスト不可。
  213. AddFunction(FunctionCode.REND, new REND_Instruction());
  214. AddFunction(FunctionCode.FOR, new REPEAT_Instruction(true), EXTENDED);
  215. AddFunction(FunctionCode.NEXT, new REND_Instruction(), EXTENDED);
  216. AddFunction(FunctionCode.WHILE, new WHILE_Instruction());
  217. AddFunction(FunctionCode.WEND, new WEND_Instruction());
  218. AddFunction(FunctionCode.DO, new ENDIF_Instruction(), METHOD_SAFE | EXTENDED);
  219. AddFunction(FunctionCode.LOOP, new LOOP_Instruction());
  220. AddFunction(FunctionCode.CONTINUE, new CONTINUE_Instruction());//REPEATに戻る
  221. AddFunction(FunctionCode.BREAK, new BREAK_Instruction());//RENDの次の行まで
  222. AddFunction(FunctionCode.RETURN, new RETURN_Instruction());//関数の終了。RESULTに整数を格納可能。省略した場合、0。(次の@~~がRETURNと見なされる。)
  223. AddFunction(FunctionCode.RETURNFORM, new RETURNFORM_Instruction());//関数の終了。RESULTに整数を格納可能。省略した場合、0。(次の@~~がRETURNと見なされる。)
  224. AddFunction(FunctionCode.RETURNF, new RETURNF_Instruction());
  225. AddFunction(FunctionCode.STRLEN, new STRLEN_Instruction(false, false));
  226. AddFunction(FunctionCode.STRLENFORM, new STRLEN_Instruction(true, false));
  227. AddFunction(FunctionCode.STRLENU, new STRLEN_Instruction(false, true));
  228. AddFunction(FunctionCode.STRLENFORMU, new STRLEN_Instruction(true, true));
  229. AddFunction(FunctionCode.SWAPCHARA, new SWAPCHARA_Instruction());
  230. AddFunction(FunctionCode.COPYCHARA, new COPYCHARA_Instruction());
  231. AddFunction(FunctionCode.ADDCOPYCHARA, new ADDCOPYCHARA_Instruction());
  232. AddFunction(FunctionCode.SPLIT, argb[FunctionArgType.SP_SPLIT], METHOD_SAFE | EXTENDED);
  233. AddFunction(FunctionCode.SETCOLOR, argb[FunctionArgType.SP_COLOR], METHOD_SAFE | EXTENDED);
  234. AddFunction(FunctionCode.SETCOLORBYNAME, argb[FunctionArgType.STR], METHOD_SAFE | EXTENDED);
  235. AddFunction(FunctionCode.RESETCOLOR, new RESETCOLOR_Instruction());
  236. AddFunction(FunctionCode.SETBGCOLOR, argb[FunctionArgType.SP_COLOR], METHOD_SAFE | EXTENDED);
  237. AddFunction(FunctionCode.SETBGCOLORBYNAME, argb[FunctionArgType.STR], METHOD_SAFE | EXTENDED);
  238. AddFunction(FunctionCode.RESETBGCOLOR, new RESETBGCOLOR_Instruction());
  239. AddFunction(FunctionCode.FONTBOLD, new FONTBOLD_Instruction());
  240. AddFunction(FunctionCode.FONTITALIC, new FONTITALIC_Instruction());
  241. AddFunction(FunctionCode.FONTREGULAR, new FONTREGULAR_Instruction());
  242. AddFunction(FunctionCode.SORTCHARA, new SORTCHARA_Instruction());
  243. AddFunction(FunctionCode.FONTSTYLE, argb[FunctionArgType.INT_EXPRESSION_NULLABLE], METHOD_SAFE | EXTENDED);
  244. AddFunction(FunctionCode.ALIGNMENT, argb[FunctionArgType.STR], METHOD_SAFE | EXTENDED);
  245. AddFunction(FunctionCode.CUSTOMDRAWLINE, argb[FunctionArgType.STR], METHOD_SAFE | EXTENDED);
  246. AddFunction(FunctionCode.DRAWLINEFORM, argb[FunctionArgType.FORM_STR], METHOD_SAFE | EXTENDED);
  247. AddFunction(FunctionCode.CLEARTEXTBOX, argb[FunctionArgType.VOID], METHOD_SAFE | EXTENDED);
  248. AddFunction(FunctionCode.SETFONT, argb[FunctionArgType.STR_EXPRESSION_NULLABLE], METHOD_SAFE | EXTENDED);
  249. AddFunction(FunctionCode.SWAP, argb[FunctionArgType.SP_SWAPVAR], METHOD_SAFE | EXTENDED);
  250. AddFunction(FunctionCode.RANDOMIZE, new RANDOMIZE_Instruction());
  251. AddFunction(FunctionCode.DUMPRAND, new DUMPRAND_Instruction());
  252. AddFunction(FunctionCode.INITRAND, new INITRAND_Instruction());
  253. AddFunction(FunctionCode.REDRAW, argb[FunctionArgType.INT_EXPRESSION], METHOD_SAFE | EXTENDED);
  254. AddFunction(FunctionCode.CALLTRAIN, argb[FunctionArgType.INT_EXPRESSION], EXTENDED | FLOW_CONTROL);
  255. AddFunction(FunctionCode.STOPCALLTRAIN, argb[FunctionArgType.VOID], EXTENDED | FLOW_CONTROL);
  256. AddFunction(FunctionCode.DOTRAIN, argb[FunctionArgType.INT_EXPRESSION], EXTENDED | FLOW_CONTROL);
  257. AddFunction(FunctionCode.DATA, argb[FunctionArgType.STR_NULLABLE], METHOD_SAFE | EXTENDED | PARTIAL | PARTIAL);
  258. AddFunction(FunctionCode.DATAFORM, argb[FunctionArgType.FORM_STR_NULLABLE], METHOD_SAFE | EXTENDED | PARTIAL);
  259. AddFunction(FunctionCode.ENDDATA, new DO_NOTHING_Instruction());
  260. AddFunction(FunctionCode.DATALIST, argb[FunctionArgType.VOID], METHOD_SAFE | EXTENDED | PARTIAL);
  261. AddFunction(FunctionCode.ENDLIST, argb[FunctionArgType.VOID], METHOD_SAFE | EXTENDED | PARTIAL);
  262. AddFunction(FunctionCode.STRDATA, argb[FunctionArgType.VAR_STR], METHOD_SAFE | EXTENDED | PARTIAL);
  263. AddFunction(FunctionCode.SETBIT, new SETBIT_Instruction(1));
  264. AddFunction(FunctionCode.CLEARBIT, new SETBIT_Instruction(0));
  265. AddFunction(FunctionCode.INVERTBIT, new SETBIT_Instruction(-1));
  266. AddFunction(FunctionCode.DELALLCHARA, argb[FunctionArgType.VOID], METHOD_SAFE | EXTENDED);
  267. AddFunction(FunctionCode.PICKUPCHARA, argb[FunctionArgType.INT_ANY], METHOD_SAFE | EXTENDED);
  268. AddFunction(FunctionCode.VARSET, new VARSET_Instruction());
  269. AddFunction(FunctionCode.CVARSET, new CVARSET_Instruction());
  270. AddFunction(FunctionCode.RESET_STAIN, argb[FunctionArgType.INT_EXPRESSION], METHOD_SAFE | EXTENDED);
  271. AddFunction(FunctionCode.FORCEKANA, argb[FunctionArgType.INT_EXPRESSION], METHOD_SAFE | EXTENDED);
  272. AddFunction(FunctionCode.SKIPDISP, argb[FunctionArgType.INT_EXPRESSION], METHOD_SAFE | EXTENDED);
  273. AddFunction(FunctionCode.NOSKIP, argb[FunctionArgType.VOID], METHOD_SAFE | EXTENDED | PARTIAL);
  274. AddFunction(FunctionCode.ENDNOSKIP, argb[FunctionArgType.VOID], METHOD_SAFE | EXTENDED | PARTIAL);
  275. AddFunction(FunctionCode.ARRAYSHIFT, argb[FunctionArgType.SP_SHIFT_ARRAY], METHOD_SAFE | EXTENDED);
  276. AddFunction(FunctionCode.ARRAYREMOVE, argb[FunctionArgType.SP_CONTROL_ARRAY], METHOD_SAFE | EXTENDED);
  277. AddFunction(FunctionCode.ARRAYSORT, argb[FunctionArgType.SP_SORTARRAY], METHOD_SAFE | EXTENDED);
  278. AddFunction(FunctionCode.ARRAYCOPY, argb[FunctionArgType.SP_COPY_ARRAY], METHOD_SAFE | EXTENDED);
  279. AddFunction(FunctionCode.JUMP, new CALL_Instruction(false, true, false, false));//関数に移動
  280. AddFunction(FunctionCode.CALL, new CALL_Instruction(false, false, false, false));//関数に移動。移動元を記憶し、RETURNで帰る。
  281. AddFunction(FunctionCode.TRYJUMP, new CALL_Instruction(false, true, true, false), EXTENDED);
  282. AddFunction(FunctionCode.TRYCALL, new CALL_Instruction(false, false, true, false), EXTENDED);
  283. AddFunction(FunctionCode.JUMPFORM, new CALL_Instruction(true, true, false, false), EXTENDED);
  284. AddFunction(FunctionCode.CALLFORM, new CALL_Instruction(true, false, false, false), EXTENDED);
  285. AddFunction(FunctionCode.TRYJUMPFORM, new CALL_Instruction(true, true, true, false), EXTENDED);
  286. AddFunction(FunctionCode.TRYCALLFORM, new CALL_Instruction(true, false, true, false), EXTENDED);
  287. AddFunction(FunctionCode.TRYCJUMP, new CALL_Instruction(false, true, true, true), EXTENDED);
  288. AddFunction(FunctionCode.TRYCCALL, new CALL_Instruction(false, false, true, true), EXTENDED);
  289. AddFunction(FunctionCode.TRYCJUMPFORM, new CALL_Instruction(true, true, true, true), EXTENDED);
  290. AddFunction(FunctionCode.TRYCCALLFORM, new CALL_Instruction(true, false, true, true), EXTENDED);
  291. AddFunction(FunctionCode.CALLEVENT, new CALLEVENT_Instruction());
  292. AddFunction(FunctionCode.CALLF, new CALLF_Instruction(false));
  293. AddFunction(FunctionCode.CALLFORMF, new CALLF_Instruction(true));
  294. AddFunction(FunctionCode.RESTART, new RESTART_Instruction());//関数の再開。関数の最初に戻る。
  295. AddFunction(FunctionCode.GOTO, new GOTO_Instruction(false, false, false));//$ラベルへジャンプ
  296. AddFunction(FunctionCode.TRYGOTO, new GOTO_Instruction(false, true, false), EXTENDED);
  297. AddFunction(FunctionCode.GOTOFORM, new GOTO_Instruction(true, false, false), EXTENDED);
  298. AddFunction(FunctionCode.TRYGOTOFORM, new GOTO_Instruction(true, true, false), EXTENDED);
  299. AddFunction(FunctionCode.TRYCGOTO, new GOTO_Instruction(false, true, true), EXTENDED);
  300. AddFunction(FunctionCode.TRYCGOTOFORM, new GOTO_Instruction(true, true, true), EXTENDED);
  301. AddFunction(FunctionCode.CATCH, new CATCH_Instruction());
  302. AddFunction(FunctionCode.ENDCATCH, new ENDIF_Instruction(), METHOD_SAFE | EXTENDED);
  303. AddFunction(FunctionCode.TRYCALLLIST, argb[FunctionArgType.VOID], EXTENDED | FLOW_CONTROL | PARTIAL | IS_TRY);
  304. AddFunction(FunctionCode.TRYJUMPLIST, argb[FunctionArgType.VOID], EXTENDED | FLOW_CONTROL | PARTIAL | IS_JUMP | IS_TRY);
  305. AddFunction(FunctionCode.TRYGOTOLIST, argb[FunctionArgType.VOID], EXTENDED | FLOW_CONTROL | PARTIAL | IS_TRY);
  306. AddFunction(FunctionCode.FUNC, argb[FunctionArgType.SP_CALLFORM], EXTENDED | FLOW_CONTROL | PARTIAL | FORCE_SETARG);
  307. AddFunction(FunctionCode.ENDFUNC, new ENDIF_Instruction(), EXTENDED);
  308. AddFunction(FunctionCode.DEBUGPRINT, new DEBUGPRINT_Instruction(false, false));
  309. AddFunction(FunctionCode.DEBUGPRINTL, new DEBUGPRINT_Instruction(false, true));
  310. AddFunction(FunctionCode.DEBUGPRINTFORM, new DEBUGPRINT_Instruction(true, false));
  311. AddFunction(FunctionCode.DEBUGPRINTFORML, new DEBUGPRINT_Instruction(true, true));
  312. AddFunction(FunctionCode.DEBUGCLEAR, new DEBUGCLEAR_Instruction());
  313. AddFunction(FunctionCode.ASSERT, argb[FunctionArgType.INT_EXPRESSION], METHOD_SAFE | EXTENDED | DEBUG_FUNC);
  314. AddFunction(FunctionCode.THROW, argb[FunctionArgType.FORM_STR_NULLABLE], METHOD_SAFE | EXTENDED);
  315. AddFunction(FunctionCode.SAVEVAR, new SAVEVAR_Instruction());
  316. AddFunction(FunctionCode.LOADVAR, new LOADVAR_Instruction());
  317. AddFunction(FunctionCode.SAVECHARA, new SAVECHARA_Instruction());
  318. AddFunction(FunctionCode.LOADCHARA, new LOADCHARA_Instruction());
  319. AddFunction(FunctionCode.REF, new REF_Instruction(false));
  320. AddFunction(FunctionCode.REFBYNAME, new REF_Instruction(true));
  321. AddFunction(FunctionCode.HTML_PRINT, new HTML_PRINT_Instruction());
  322. AddFunction(FunctionCode.HTML_PRINTSL, new HTML_PRINT_Instruction(true));
  323. AddFunction(FunctionCode.HTML_TAGSPLIT, new HTML_TAGSPLIT_Instruction());
  324. AddFunction(FunctionCode.PRINT_IMG, new PRINT_IMG_Instruction());
  325. AddFunction(FunctionCode.PRINT_RECT, new PRINT_RECT_Instruction());
  326. AddFunction(FunctionCode.PRINT_SPACE, new PRINT_SPACE_Instruction());
  327. AddFunction(FunctionCode.TOOLTIP_SETCOLOR, new TOOLTIP_SETCOLOR_Instruction());
  328. AddFunction(FunctionCode.TOOLTIP_SETDELAY, new TOOLTIP_SETDELAY_Instruction());
  329. AddFunction(FunctionCode.TOOLTIP_SETDURATION, new TOOLTIP_SETDURATION_Instruction());
  330. #region 式中関数の引数違い
  331. AddFunction(FunctionCode.VARSIZE, argb[FunctionArgType.SP_VAR], METHOD_SAFE | EXTENDED);//動作が違うのでMETHOD化できない
  332. AddFunction(FunctionCode.GETTIME, argb[FunctionArgType.VOID], METHOD_SAFE | EXTENDED);//2つに代入する必要があるのでMETHOD化できない
  333. AddFunction(FunctionCode.POWER, argb[FunctionArgType.SP_POWER], METHOD_SAFE | EXTENDED);//引数が違うのでMETHOD化できない。
  334. AddFunction(FunctionCode.PRINTCPERLINE, argb[FunctionArgType.SP_GETINT], METHOD_SAFE | EXTENDED);//よく考えたら引数の仕様違うや
  335. AddFunction(FunctionCode.SAVENOS, argb[FunctionArgType.SP_GETINT], METHOD_SAFE | EXTENDED);//引数の仕様が違うので(ry
  336. AddFunction(FunctionCode.ENCODETOUNI, argb[FunctionArgType.FORM_STR_NULLABLE], METHOD_SAFE | EXTENDED);//式中関数版を追加。処理が全然違う
  337. #endregion
  338. var methodList = FunctionMethodCreator.GetMethodList();
  339. foreach (var pair in methodList)
  340. {
  341. var key = pair.Key;
  342. if (!funcDic.ContainsKey(key))
  343. {
  344. funcDic.Add(key, new FunctionIdentifier(key, pair.Value, methodInstruction));
  345. }
  346. }
  347. funcMatch[FunctionCode.IF] = "ENDIF";
  348. funcMatch[FunctionCode.SELECTCASE] = "ENDSELECT";
  349. funcMatch[FunctionCode.REPEAT] = "REND";
  350. funcMatch[FunctionCode.FOR] = "NEXT";
  351. funcMatch[FunctionCode.WHILE] = "WEND";
  352. funcMatch[FunctionCode.TRYCGOTO] = "CATCH";
  353. funcMatch[FunctionCode.TRYCJUMP] = "CATCH";
  354. funcMatch[FunctionCode.TRYCCALL] = "CATCH";
  355. funcMatch[FunctionCode.TRYCGOTOFORM] = "CATCH";
  356. funcMatch[FunctionCode.TRYCJUMPFORM] = "CATCH";
  357. funcMatch[FunctionCode.TRYCCALLFORM] = "CATCH";
  358. funcMatch[FunctionCode.CATCH] = "ENDCATCH";
  359. funcMatch[FunctionCode.DO] = "LOOP";
  360. funcMatch[FunctionCode.PRINTDATA] = "ENDDATA";
  361. funcMatch[FunctionCode.PRINTDATAL] = "ENDDATA";
  362. funcMatch[FunctionCode.PRINTDATAW] = "ENDDATA";
  363. funcMatch[FunctionCode.PRINTDATAK] = "ENDDATA";
  364. funcMatch[FunctionCode.PRINTDATAKL] = "ENDDATA";
  365. funcMatch[FunctionCode.PRINTDATAKW] = "ENDDATA";
  366. funcMatch[FunctionCode.PRINTDATAD] = "ENDDATA";
  367. funcMatch[FunctionCode.PRINTDATADL] = "ENDDATA";
  368. funcMatch[FunctionCode.PRINTDATADW] = "ENDDATA";
  369. funcMatch[FunctionCode.DATALIST] = "ENDLIST";
  370. funcMatch[FunctionCode.STRDATA] = "ENDDATA";
  371. funcMatch[FunctionCode.NOSKIP] = "ENDNOSKIP";
  372. funcMatch[FunctionCode.TRYCALLLIST] = "ENDFUNC";
  373. funcMatch[FunctionCode.TRYGOTOLIST] = "ENDFUNC";
  374. funcMatch[FunctionCode.TRYJUMPLIST] = "ENDFUNC";
  375. funcParent[FunctionCode.REND] = FunctionCode.REPEAT;
  376. funcParent[FunctionCode.NEXT] = FunctionCode.FOR;
  377. funcParent[FunctionCode.WEND] = FunctionCode.WHILE;
  378. funcParent[FunctionCode.LOOP] = FunctionCode.DO;
  379. }
  380. public static FunctionIdentifier SETFunction { get; }
  381. internal static string getMatchFunction(FunctionCode func)
  382. {
  383. funcMatch.TryGetValue(func, out var ret);
  384. return ret;
  385. }
  386. internal static FunctionCode getParentFunc(FunctionCode func)
  387. {
  388. funcParent.TryGetValue(func, out var ret);
  389. return ret;
  390. }
  391. #endregion
  392. private FunctionIdentifier(string name, FunctionCode code, AbstractInstruction instruction)
  393. : this(name, code, instruction, 0)
  394. {
  395. }
  396. private FunctionIdentifier(string name, FunctionCode code, AbstractInstruction instruction, int additionalFlag)
  397. {
  398. Code = code;
  399. ArgBuilder = instruction.ArgBuilder;
  400. flag = instruction.Flag | additionalFlag;
  401. Method = null;
  402. Name = name;
  403. Instruction = instruction;
  404. }
  405. private FunctionIdentifier(string name, FunctionCode code, ArgumentBuilder arg, int flag)
  406. {
  407. Code = code;
  408. ArgBuilder = arg;
  409. this.flag = flag;
  410. Method = null;
  411. Name = name;
  412. Instruction = null;
  413. }
  414. private FunctionIdentifier(string methodName, FunctionMethod method, AbstractInstruction instruction)
  415. {
  416. Code = FunctionCode.__NULL__;
  417. ArgBuilder = instruction.ArgBuilder;
  418. flag = instruction.Flag;
  419. Method = method;
  420. Name = methodName;
  421. Instruction = instruction;
  422. }
  423. public readonly AbstractInstruction Instruction;
  424. private readonly int flag;
  425. public FunctionCode Code { get; }
  426. public ArgumentBuilder ArgBuilder { get; }
  427. public FunctionMethod Method { get; }
  428. public string Name { get; private set; }
  429. internal bool IsFlowContorol()
  430. {
  431. return ((flag & FLOW_CONTROL) == FLOW_CONTROL);
  432. }
  433. internal bool IsExtended()
  434. {
  435. return ((flag & EXTENDED) == EXTENDED);
  436. }
  437. internal bool IsPrintDFunction()
  438. {
  439. return ((flag & ISPRINTDFUNC) == ISPRINTDFUNC);
  440. }
  441. internal bool IsPrintKFunction()
  442. {
  443. return ((flag & ISPRINTKFUNC) == ISPRINTKFUNC);
  444. }
  445. internal bool IsNewLine()
  446. {
  447. return ((flag & PRINT_NEWLINE) == PRINT_NEWLINE);
  448. }
  449. internal bool IsWaitInput()
  450. {
  451. return ((flag & PRINT_WAITINPUT) == PRINT_WAITINPUT);
  452. }
  453. internal bool IsPrintSingle()
  454. {
  455. return ((flag & PRINT_SINGLE) == PRINT_SINGLE);
  456. }
  457. internal bool IsPartial()
  458. {
  459. return ((flag & PARTIAL) == PARTIAL);
  460. }
  461. internal bool IsMethodSafe()
  462. {
  463. return ((flag & METHOD_SAFE) == METHOD_SAFE);
  464. }
  465. internal bool IsPrint()
  466. {
  467. return ((flag & IS_PRINT) == IS_PRINT);
  468. }
  469. internal bool IsInput()
  470. {
  471. return ((flag & IS_INPUT) == IS_INPUT);
  472. }
  473. internal bool IsPrintData()
  474. {
  475. return ((flag & IS_PRINTDATA) == IS_PRINTDATA);
  476. }
  477. internal bool IsForceSetArg()
  478. {
  479. return ((flag & FORCE_SETARG) == FORCE_SETARG);
  480. }
  481. internal bool IsDebug()
  482. {
  483. return ((flag & DEBUG_FUNC) == DEBUG_FUNC);
  484. }
  485. internal bool IsTry()
  486. {
  487. return ((flag & IS_TRY) == IS_TRY);
  488. }
  489. internal bool IsJump()
  490. {
  491. return ((flag & IS_JUMP) == IS_JUMP);
  492. }
  493. internal bool IsMethod()
  494. {
  495. return Method != null;
  496. }
  497. public override string ToString()
  498. {
  499. return Name;
  500. }
  501. }
  502. }