using System.Collections.Generic;
using NTERA.EmuEra.Game.EraEmu.GameData.Function;
namespace NTERA.EmuEra.Game.EraEmu.GameProc.Function
{
///
/// FunctionCodeのラッパー
/// BuiltInFunctionManagerを元にクラス化
///
internal sealed partial class FunctionIdentifier
{
#region flag定義
//いちいちFunctionFlag.FLOW_CONTROLとか書くのが面倒だったからenumではなくconst intで
private const int FLOW_CONTROL = 0x00001;
private const int EXTENDED = 0x00002;//Emuera拡張命令
private const int METHOD_SAFE = 0x00004;//#Function中で呼び出してよい命令。WAITなど入力を伴うもの、CALLなど関数呼び出しを伴うものは不可。
private const int DEBUG_FUNC = 0x00008;//-Debug引数付きで起動した場合にのみ実行される命令。
private const int PARTIAL = 0x00010;//複数行に渡る構文の一部である命令。SIF文の次に来てはいけない。debugコマンドからの呼び出しも不適当。
private const int FORCE_SETARG = 0x00020;//ロード時に必ず引数解析を行う必要のあるもの。IFやSELECTCASEなど
private const int IS_JUMP = 0x00040;//JUMP命令
private const int IS_TRY = 0x00080;//TRY系命令
private const int IS_TRYC = 0x08000;//TRY系命令
private const int PRINT_NEWLINE = 0x00100;//PRINT命令で出力後改行するもの
private const int PRINT_WAITINPUT = 0x00200;//PRINT命令で出力後入力待ちするもの
private const int PRINT_SINGLE = 0x00400;//PRINTSINGLE系
private const int ISPRINTDFUNC = 0x00800;//PRINTD系判定用
private const int ISPRINTKFUNC = 0x01000;//PRINTK系判定用
private const int IS_PRINT = 0x02000;//SkipPrintにより飛ばされる命令。PRINT系及びWAIT系。DEBUGPRINTは含まない。
private const int IS_INPUT = 0x04000;//userDefinedSkipを警告する命令。INPUT系。
private const int IS_PRINTDATA = 0x10000;//PRINTDATA系判定用、PRINTとは一部処理が違うので、それ用。
#endregion
#region static
//元BuiltInFunctionManager部分
private static readonly Dictionary funcDic = new Dictionary();
static readonly Dictionary funcMatch = new Dictionary();
static readonly Dictionary funcParent = new Dictionary();
static readonly AbstractInstruction methodInstruction;
private static void AddFunction(FunctionCode code, AbstractInstruction inst, int additionalFlag = 0)
{
var key = code.ToString();
if (Config.Config.ICFunction)
key = key.ToUpper();
funcDic.Add(key, new FunctionIdentifier(key, code, inst, additionalFlag));
}
private static void AddFunction(FunctionCode code, ArgumentBuilder arg)
{ AddFunction(code, arg, 0); }
private static void AddFunction(FunctionCode code, ArgumentBuilder arg, int flag)
{
var key = code.ToString();
if (Config.Config.ICFunction)
key = key.ToUpper();
funcDic.Add(key, new FunctionIdentifier(key, code, arg, flag));
}
public static Dictionary GetInstructionNameDic()
{
return funcDic;
}
private static void addPrintFunction(FunctionCode code)
{
AddFunction(code, new PRINT_Instruction(code.ToString()));
}
private static void addPrintDataFunction(FunctionCode code)
{
AddFunction(code, new PRINT_DATA_Instruction(code.ToString()));
}
static FunctionIdentifier()
{
var argb = ArgumentParser.GetArgumentBuilderDictionary();
methodInstruction = new METHOD_Instruction();
SETFunction = new FunctionIdentifier("SET", FunctionCode.SET, new SET_Instruction());//代入文
#region PRINT or INPUT
addPrintFunction(FunctionCode.PRINT);
addPrintFunction(FunctionCode.PRINTL);
addPrintFunction(FunctionCode.PRINTW);
addPrintFunction(FunctionCode.PRINTV);
addPrintFunction(FunctionCode.PRINTVL);
addPrintFunction(FunctionCode.PRINTVW);
addPrintFunction(FunctionCode.PRINTS);
addPrintFunction(FunctionCode.PRINTSL);
addPrintFunction(FunctionCode.PRINTSW);
addPrintFunction(FunctionCode.PRINTFORM);
addPrintFunction(FunctionCode.PRINTFORML);
addPrintFunction(FunctionCode.PRINTFORMW);
addPrintFunction(FunctionCode.PRINTFORMS);
addPrintFunction(FunctionCode.PRINTFORMSL);
addPrintFunction(FunctionCode.PRINTFORMSW);
addPrintFunction(FunctionCode.PRINTK);
addPrintFunction(FunctionCode.PRINTKL);
addPrintFunction(FunctionCode.PRINTKW);
addPrintFunction(FunctionCode.PRINTVK);
addPrintFunction(FunctionCode.PRINTVKL);
addPrintFunction(FunctionCode.PRINTVKW);
addPrintFunction(FunctionCode.PRINTSK);
addPrintFunction(FunctionCode.PRINTSKL);
addPrintFunction(FunctionCode.PRINTSKW);
addPrintFunction(FunctionCode.PRINTFORMK);
addPrintFunction(FunctionCode.PRINTFORMKL);
addPrintFunction(FunctionCode.PRINTFORMKW);
addPrintFunction(FunctionCode.PRINTFORMSK);
addPrintFunction(FunctionCode.PRINTFORMSKL);
addPrintFunction(FunctionCode.PRINTFORMSKW);
addPrintFunction(FunctionCode.PRINTD);
addPrintFunction(FunctionCode.PRINTDL);
addPrintFunction(FunctionCode.PRINTDW);
addPrintFunction(FunctionCode.PRINTVD);
addPrintFunction(FunctionCode.PRINTVDL);
addPrintFunction(FunctionCode.PRINTVDW);
addPrintFunction(FunctionCode.PRINTSD);
addPrintFunction(FunctionCode.PRINTSDL);
addPrintFunction(FunctionCode.PRINTSDW);
addPrintFunction(FunctionCode.PRINTFORMD);
addPrintFunction(FunctionCode.PRINTFORMDL);
addPrintFunction(FunctionCode.PRINTFORMDW);
addPrintFunction(FunctionCode.PRINTFORMSD);
addPrintFunction(FunctionCode.PRINTFORMSDL);
addPrintFunction(FunctionCode.PRINTFORMSDW);
addPrintFunction(FunctionCode.PRINTSINGLE);
addPrintFunction(FunctionCode.PRINTSINGLEV);
addPrintFunction(FunctionCode.PRINTSINGLES);
addPrintFunction(FunctionCode.PRINTSINGLEFORM);
addPrintFunction(FunctionCode.PRINTSINGLEFORMS);
addPrintFunction(FunctionCode.PRINTSINGLEK);
addPrintFunction(FunctionCode.PRINTSINGLEVK);
addPrintFunction(FunctionCode.PRINTSINGLESK);
addPrintFunction(FunctionCode.PRINTSINGLEFORMK);
addPrintFunction(FunctionCode.PRINTSINGLEFORMSK);
addPrintFunction(FunctionCode.PRINTSINGLED);
addPrintFunction(FunctionCode.PRINTSINGLEVD);
addPrintFunction(FunctionCode.PRINTSINGLESD);
addPrintFunction(FunctionCode.PRINTSINGLEFORMD);
addPrintFunction(FunctionCode.PRINTSINGLEFORMSD);
addPrintFunction(FunctionCode.PRINTC);
addPrintFunction(FunctionCode.PRINTLC);
addPrintFunction(FunctionCode.PRINTFORMC);
addPrintFunction(FunctionCode.PRINTFORMLC);
addPrintFunction(FunctionCode.PRINTCK);
addPrintFunction(FunctionCode.PRINTLCK);
addPrintFunction(FunctionCode.PRINTFORMCK);
addPrintFunction(FunctionCode.PRINTFORMLCK);
addPrintFunction(FunctionCode.PRINTCD);
addPrintFunction(FunctionCode.PRINTLCD);
addPrintFunction(FunctionCode.PRINTFORMCD);
addPrintFunction(FunctionCode.PRINTFORMLCD);
addPrintDataFunction(FunctionCode.PRINTDATA);
addPrintDataFunction(FunctionCode.PRINTDATAL);
addPrintDataFunction(FunctionCode.PRINTDATAW);
addPrintDataFunction(FunctionCode.PRINTDATAK);
addPrintDataFunction(FunctionCode.PRINTDATAKL);
addPrintDataFunction(FunctionCode.PRINTDATAKW);
addPrintDataFunction(FunctionCode.PRINTDATAD);
addPrintDataFunction(FunctionCode.PRINTDATADL);
addPrintDataFunction(FunctionCode.PRINTDATADW);
AddFunction(FunctionCode.PRINTBUTTON, argb[FunctionArgType.SP_BUTTON], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.PRINTBUTTONC, argb[FunctionArgType.SP_BUTTON], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.PRINTBUTTONLC, argb[FunctionArgType.SP_BUTTON], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.PRINTPLAIN, argb[FunctionArgType.STR_NULLABLE], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.PRINTPLAINFORM, argb[FunctionArgType.FORM_STR_NULLABLE], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.PRINT_ABL, argb[FunctionArgType.INT_EXPRESSION], METHOD_SAFE);//能力。引数は登録番号
AddFunction(FunctionCode.PRINT_TALENT, argb[FunctionArgType.INT_EXPRESSION], METHOD_SAFE);//素質
AddFunction(FunctionCode.PRINT_MARK, argb[FunctionArgType.INT_EXPRESSION], METHOD_SAFE);//刻印
AddFunction(FunctionCode.PRINT_EXP, argb[FunctionArgType.INT_EXPRESSION], METHOD_SAFE);//経験
AddFunction(FunctionCode.PRINT_PALAM, argb[FunctionArgType.INT_EXPRESSION], METHOD_SAFE);//パラメータ
AddFunction(FunctionCode.PRINT_ITEM, argb[FunctionArgType.VOID], METHOD_SAFE);//所持アイテム
AddFunction(FunctionCode.PRINT_SHOPITEM, argb[FunctionArgType.VOID], METHOD_SAFE);//ショップで売っているアイテム
AddFunction(FunctionCode.DRAWLINE, argb[FunctionArgType.VOID], METHOD_SAFE);//画面の左端から右端まで----と線を引く。
AddFunction(FunctionCode.BAR, new BAR_Instruction(false));//[*****....]のようなグラフを書く。BAR (変数) , (最大値), (長さ)
AddFunction(FunctionCode.BARL, new BAR_Instruction(true));//改行付き。
AddFunction(FunctionCode.TIMES, new TIMES_Instruction());//小数計算。TIMES (変数) , (小数値)という形で使う。
AddFunction(FunctionCode.WAIT, new WAIT_Instruction(false));
AddFunction(FunctionCode.INPUT, new INPUT_Instruction());
AddFunction(FunctionCode.INPUTS, new INPUTS_Instruction());
AddFunction(FunctionCode.TINPUT, new TINPUT_Instruction(false));
AddFunction(FunctionCode.TINPUTS, new TINPUTS_Instruction(false));
AddFunction(FunctionCode.TONEINPUT, new TINPUT_Instruction(true));
AddFunction(FunctionCode.TONEINPUTS, new TINPUTS_Instruction(true));
AddFunction(FunctionCode.TWAIT, new TWAIT_Instruction());
AddFunction(FunctionCode.WAITANYKEY, new WAITANYKEY_Instruction());
AddFunction(FunctionCode.FORCEWAIT, new WAIT_Instruction(true));
AddFunction(FunctionCode.ONEINPUT, new ONEINPUT_Instruction());
AddFunction(FunctionCode.ONEINPUTS, new ONEINPUTS_Instruction());
AddFunction(FunctionCode.CLEARLINE, new CLEARLINE_Instruction());
AddFunction(FunctionCode.REUSELASTLINE, new REUSELASTLINE_Instruction());
#endregion
AddFunction(FunctionCode.UPCHECK, argb[FunctionArgType.VOID], METHOD_SAFE);//パラメータの変動
AddFunction(FunctionCode.CUPCHECK, argb[FunctionArgType.INT_EXPRESSION], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.ADDCHARA, new ADDCHARA_Instruction(false, false));//(キャラ番号)のキャラクタを追加
AddFunction(FunctionCode.ADDSPCHARA, new ADDCHARA_Instruction(true, false));//(キャラ番号)のSPキャラクタを追加(フラグ0を1にして作成)
AddFunction(FunctionCode.ADDDEFCHARA, argb[FunctionArgType.VOID], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.ADDVOIDCHARA, new ADDVOIDCHARA_Instruction());//変数に何の設定のないキャラを作成
AddFunction(FunctionCode.DELCHARA, new ADDCHARA_Instruction(false, true));//(キャラ登録番号)のキャラクタを削除。
AddFunction(FunctionCode.PUTFORM, argb[FunctionArgType.FORM_STR_NULLABLE], METHOD_SAFE);//@SAVEINFO関数でのみ使用可能。PRINTFORMと同様の書式でセーブデータに概要をつける。
AddFunction(FunctionCode.QUIT, argb[FunctionArgType.VOID]);//ゲームを終了
AddFunction(FunctionCode.OUTPUTLOG, argb[FunctionArgType.VOID]);
AddFunction(FunctionCode.BEGIN, new BEGIN_Instruction());//システム関数の実行。実行するとCALLの呼び出し元などを忘れてしまう。
AddFunction(FunctionCode.SAVEGAME, new SAVELOADGAME_Instruction(true));//セーブ画面を呼ぶ。ショップのみ。
AddFunction(FunctionCode.LOADGAME, new SAVELOADGAME_Instruction(false));//
AddFunction(FunctionCode.SAVEDATA, argb[FunctionArgType.SP_SAVEDATA], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.LOADDATA, argb[FunctionArgType.INT_EXPRESSION], EXTENDED | FLOW_CONTROL);
AddFunction(FunctionCode.DELDATA, new DELDATA_Instruction());
AddFunction(FunctionCode.SAVEGLOBAL, new SAVEGLOBAL_Instruction());
AddFunction(FunctionCode.LOADGLOBAL, new LOADGLOBAL_Instruction());
AddFunction(FunctionCode.RESETDATA, new RESETDATA_Instruction());
AddFunction(FunctionCode.RESETGLOBAL, new RESETGLOBAL_Instruction());
AddFunction(FunctionCode.SIF, new SIF_Instruction());//一行のみIF
AddFunction(FunctionCode.IF, new IF_Instruction());
AddFunction(FunctionCode.ELSE, new ELSEIF_Instruction(FunctionArgType.VOID));
AddFunction(FunctionCode.ELSEIF, new ELSEIF_Instruction(FunctionArgType.INT_EXPRESSION));
AddFunction(FunctionCode.ENDIF, new ENDIF_Instruction(), METHOD_SAFE);
AddFunction(FunctionCode.SELECTCASE, new SELECTCASE_Instruction());
AddFunction(FunctionCode.CASE, new ELSEIF_Instruction(FunctionArgType.CASE), EXTENDED);
AddFunction(FunctionCode.CASEELSE, new ELSEIF_Instruction(FunctionArgType.VOID), EXTENDED);
AddFunction(FunctionCode.ENDSELECT, new ENDIF_Instruction(), METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.REPEAT, new REPEAT_Instruction(false));//RENDまで繰り返し。繰り返した回数がCOUNTへ。ネスト不可。
AddFunction(FunctionCode.REND, new REND_Instruction());
AddFunction(FunctionCode.FOR, new REPEAT_Instruction(true), EXTENDED);
AddFunction(FunctionCode.NEXT, new REND_Instruction(), EXTENDED);
AddFunction(FunctionCode.WHILE, new WHILE_Instruction());
AddFunction(FunctionCode.WEND, new WEND_Instruction());
AddFunction(FunctionCode.DO, new ENDIF_Instruction(), METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.LOOP, new LOOP_Instruction());
AddFunction(FunctionCode.CONTINUE, new CONTINUE_Instruction());//REPEATに戻る
AddFunction(FunctionCode.BREAK, new BREAK_Instruction());//RENDの次の行まで
AddFunction(FunctionCode.RETURN, new RETURN_Instruction());//関数の終了。RESULTに整数を格納可能。省略した場合、0。(次の@~~がRETURNと見なされる。)
AddFunction(FunctionCode.RETURNFORM, new RETURNFORM_Instruction());//関数の終了。RESULTに整数を格納可能。省略した場合、0。(次の@~~がRETURNと見なされる。)
AddFunction(FunctionCode.RETURNF, new RETURNF_Instruction());
AddFunction(FunctionCode.STRLEN, new STRLEN_Instruction(false, false));
AddFunction(FunctionCode.STRLENFORM, new STRLEN_Instruction(true, false));
AddFunction(FunctionCode.STRLENU, new STRLEN_Instruction(false, true));
AddFunction(FunctionCode.STRLENFORMU, new STRLEN_Instruction(true, true));
AddFunction(FunctionCode.SWAPCHARA, new SWAPCHARA_Instruction());
AddFunction(FunctionCode.COPYCHARA, new COPYCHARA_Instruction());
AddFunction(FunctionCode.ADDCOPYCHARA, new ADDCOPYCHARA_Instruction());
AddFunction(FunctionCode.SPLIT, argb[FunctionArgType.SP_SPLIT], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.SETCOLOR, argb[FunctionArgType.SP_COLOR], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.SETCOLORBYNAME, argb[FunctionArgType.STR], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.RESETCOLOR, new RESETCOLOR_Instruction());
AddFunction(FunctionCode.SETBGCOLOR, argb[FunctionArgType.SP_COLOR], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.SETBGCOLORBYNAME, argb[FunctionArgType.STR], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.RESETBGCOLOR, new RESETBGCOLOR_Instruction());
AddFunction(FunctionCode.FONTBOLD, new FONTBOLD_Instruction());
AddFunction(FunctionCode.FONTITALIC, new FONTITALIC_Instruction());
AddFunction(FunctionCode.FONTREGULAR, new FONTREGULAR_Instruction());
AddFunction(FunctionCode.SORTCHARA, new SORTCHARA_Instruction());
AddFunction(FunctionCode.FONTSTYLE, argb[FunctionArgType.INT_EXPRESSION_NULLABLE], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.ALIGNMENT, argb[FunctionArgType.STR], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.CUSTOMDRAWLINE, argb[FunctionArgType.STR], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.DRAWLINEFORM, argb[FunctionArgType.FORM_STR], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.CLEARTEXTBOX, argb[FunctionArgType.VOID], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.SETFONT, argb[FunctionArgType.STR_EXPRESSION_NULLABLE], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.SWAP, argb[FunctionArgType.SP_SWAPVAR], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.RANDOMIZE, new RANDOMIZE_Instruction());
AddFunction(FunctionCode.DUMPRAND, new DUMPRAND_Instruction());
AddFunction(FunctionCode.INITRAND, new INITRAND_Instruction());
AddFunction(FunctionCode.REDRAW, argb[FunctionArgType.INT_EXPRESSION], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.CALLTRAIN, argb[FunctionArgType.INT_EXPRESSION], EXTENDED | FLOW_CONTROL);
AddFunction(FunctionCode.STOPCALLTRAIN, argb[FunctionArgType.VOID], EXTENDED | FLOW_CONTROL);
AddFunction(FunctionCode.DOTRAIN, argb[FunctionArgType.INT_EXPRESSION], EXTENDED | FLOW_CONTROL);
AddFunction(FunctionCode.DATA, argb[FunctionArgType.STR_NULLABLE], METHOD_SAFE | EXTENDED | PARTIAL | PARTIAL);
AddFunction(FunctionCode.DATAFORM, argb[FunctionArgType.FORM_STR_NULLABLE], METHOD_SAFE | EXTENDED | PARTIAL);
AddFunction(FunctionCode.ENDDATA, new DO_NOTHING_Instruction());
AddFunction(FunctionCode.DATALIST, argb[FunctionArgType.VOID], METHOD_SAFE | EXTENDED | PARTIAL);
AddFunction(FunctionCode.ENDLIST, argb[FunctionArgType.VOID], METHOD_SAFE | EXTENDED | PARTIAL);
AddFunction(FunctionCode.STRDATA, argb[FunctionArgType.VAR_STR], METHOD_SAFE | EXTENDED | PARTIAL);
AddFunction(FunctionCode.SETBIT, new SETBIT_Instruction(1));
AddFunction(FunctionCode.CLEARBIT, new SETBIT_Instruction(0));
AddFunction(FunctionCode.INVERTBIT, new SETBIT_Instruction(-1));
AddFunction(FunctionCode.DELALLCHARA, argb[FunctionArgType.VOID], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.PICKUPCHARA, argb[FunctionArgType.INT_ANY], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.VARSET, new VARSET_Instruction());
AddFunction(FunctionCode.CVARSET, new CVARSET_Instruction());
AddFunction(FunctionCode.RESET_STAIN, argb[FunctionArgType.INT_EXPRESSION], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.FORCEKANA, argb[FunctionArgType.INT_EXPRESSION], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.SKIPDISP, argb[FunctionArgType.INT_EXPRESSION], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.NOSKIP, argb[FunctionArgType.VOID], METHOD_SAFE | EXTENDED | PARTIAL);
AddFunction(FunctionCode.ENDNOSKIP, argb[FunctionArgType.VOID], METHOD_SAFE | EXTENDED | PARTIAL);
AddFunction(FunctionCode.ARRAYSHIFT, argb[FunctionArgType.SP_SHIFT_ARRAY], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.ARRAYREMOVE, argb[FunctionArgType.SP_CONTROL_ARRAY], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.ARRAYSORT, argb[FunctionArgType.SP_SORTARRAY], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.ARRAYCOPY, argb[FunctionArgType.SP_COPY_ARRAY], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.JUMP, new CALL_Instruction(false, true, false, false));//関数に移動
AddFunction(FunctionCode.CALL, new CALL_Instruction(false, false, false, false));//関数に移動。移動元を記憶し、RETURNで帰る。
AddFunction(FunctionCode.TRYJUMP, new CALL_Instruction(false, true, true, false), EXTENDED);
AddFunction(FunctionCode.TRYCALL, new CALL_Instruction(false, false, true, false), EXTENDED);
AddFunction(FunctionCode.JUMPFORM, new CALL_Instruction(true, true, false, false), EXTENDED);
AddFunction(FunctionCode.CALLFORM, new CALL_Instruction(true, false, false, false), EXTENDED);
AddFunction(FunctionCode.TRYJUMPFORM, new CALL_Instruction(true, true, true, false), EXTENDED);
AddFunction(FunctionCode.TRYCALLFORM, new CALL_Instruction(true, false, true, false), EXTENDED);
AddFunction(FunctionCode.TRYCJUMP, new CALL_Instruction(false, true, true, true), EXTENDED);
AddFunction(FunctionCode.TRYCCALL, new CALL_Instruction(false, false, true, true), EXTENDED);
AddFunction(FunctionCode.TRYCJUMPFORM, new CALL_Instruction(true, true, true, true), EXTENDED);
AddFunction(FunctionCode.TRYCCALLFORM, new CALL_Instruction(true, false, true, true), EXTENDED);
AddFunction(FunctionCode.CALLEVENT, new CALLEVENT_Instruction());
AddFunction(FunctionCode.CALLF, new CALLF_Instruction(false));
AddFunction(FunctionCode.CALLFORMF, new CALLF_Instruction(true));
AddFunction(FunctionCode.RESTART, new RESTART_Instruction());//関数の再開。関数の最初に戻る。
AddFunction(FunctionCode.GOTO, new GOTO_Instruction(false, false, false));//$ラベルへジャンプ
AddFunction(FunctionCode.TRYGOTO, new GOTO_Instruction(false, true, false), EXTENDED);
AddFunction(FunctionCode.GOTOFORM, new GOTO_Instruction(true, false, false), EXTENDED);
AddFunction(FunctionCode.TRYGOTOFORM, new GOTO_Instruction(true, true, false), EXTENDED);
AddFunction(FunctionCode.TRYCGOTO, new GOTO_Instruction(false, true, true), EXTENDED);
AddFunction(FunctionCode.TRYCGOTOFORM, new GOTO_Instruction(true, true, true), EXTENDED);
AddFunction(FunctionCode.CATCH, new CATCH_Instruction());
AddFunction(FunctionCode.ENDCATCH, new ENDIF_Instruction(), METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.TRYCALLLIST, argb[FunctionArgType.VOID], EXTENDED | FLOW_CONTROL | PARTIAL | IS_TRY);
AddFunction(FunctionCode.TRYJUMPLIST, argb[FunctionArgType.VOID], EXTENDED | FLOW_CONTROL | PARTIAL | IS_JUMP | IS_TRY);
AddFunction(FunctionCode.TRYGOTOLIST, argb[FunctionArgType.VOID], EXTENDED | FLOW_CONTROL | PARTIAL | IS_TRY);
AddFunction(FunctionCode.FUNC, argb[FunctionArgType.SP_CALLFORM], EXTENDED | FLOW_CONTROL | PARTIAL | FORCE_SETARG);
AddFunction(FunctionCode.ENDFUNC, new ENDIF_Instruction(), EXTENDED);
AddFunction(FunctionCode.DEBUGPRINT, new DEBUGPRINT_Instruction(false, false));
AddFunction(FunctionCode.DEBUGPRINTL, new DEBUGPRINT_Instruction(false, true));
AddFunction(FunctionCode.DEBUGPRINTFORM, new DEBUGPRINT_Instruction(true, false));
AddFunction(FunctionCode.DEBUGPRINTFORML, new DEBUGPRINT_Instruction(true, true));
AddFunction(FunctionCode.DEBUGCLEAR, new DEBUGCLEAR_Instruction());
AddFunction(FunctionCode.ASSERT, argb[FunctionArgType.INT_EXPRESSION], METHOD_SAFE | EXTENDED | DEBUG_FUNC);
AddFunction(FunctionCode.THROW, argb[FunctionArgType.FORM_STR_NULLABLE], METHOD_SAFE | EXTENDED);
AddFunction(FunctionCode.SAVEVAR, new SAVEVAR_Instruction());
AddFunction(FunctionCode.LOADVAR, new LOADVAR_Instruction());
AddFunction(FunctionCode.SAVECHARA, new SAVECHARA_Instruction());
AddFunction(FunctionCode.LOADCHARA, new LOADCHARA_Instruction());
AddFunction(FunctionCode.REF, new REF_Instruction(false));
AddFunction(FunctionCode.REFBYNAME, new REF_Instruction(true));
AddFunction(FunctionCode.HTML_PRINT, new HTML_PRINT_Instruction());
AddFunction(FunctionCode.HTML_PRINTSL, new HTML_PRINT_Instruction(true));
AddFunction(FunctionCode.HTML_TAGSPLIT, new HTML_TAGSPLIT_Instruction());
AddFunction(FunctionCode.PRINT_IMG, new PRINT_IMG_Instruction());
AddFunction(FunctionCode.PRINT_RECT, new PRINT_RECT_Instruction());
AddFunction(FunctionCode.PRINT_SPACE, new PRINT_SPACE_Instruction());
AddFunction(FunctionCode.TOOLTIP_SETCOLOR, new TOOLTIP_SETCOLOR_Instruction());
AddFunction(FunctionCode.TOOLTIP_SETDELAY, new TOOLTIP_SETDELAY_Instruction());
AddFunction(FunctionCode.TOOLTIP_SETDURATION, new TOOLTIP_SETDURATION_Instruction());
#region 式中関数の引数違い
AddFunction(FunctionCode.VARSIZE, argb[FunctionArgType.SP_VAR], METHOD_SAFE | EXTENDED);//動作が違うのでMETHOD化できない
AddFunction(FunctionCode.GETTIME, argb[FunctionArgType.VOID], METHOD_SAFE | EXTENDED);//2つに代入する必要があるのでMETHOD化できない
AddFunction(FunctionCode.POWER, argb[FunctionArgType.SP_POWER], METHOD_SAFE | EXTENDED);//引数が違うのでMETHOD化できない。
AddFunction(FunctionCode.PRINTCPERLINE, argb[FunctionArgType.SP_GETINT], METHOD_SAFE | EXTENDED);//よく考えたら引数の仕様違うや
AddFunction(FunctionCode.SAVENOS, argb[FunctionArgType.SP_GETINT], METHOD_SAFE | EXTENDED);//引数の仕様が違うので(ry
AddFunction(FunctionCode.ENCODETOUNI, argb[FunctionArgType.FORM_STR_NULLABLE], METHOD_SAFE | EXTENDED);//式中関数版を追加。処理が全然違う
#endregion
var methodList = FunctionMethodCreator.GetMethodList();
foreach (var pair in methodList)
{
var key = pair.Key;
if (!funcDic.ContainsKey(key))
{
funcDic.Add(key, new FunctionIdentifier(key, pair.Value, methodInstruction));
}
}
funcMatch[FunctionCode.IF] = "ENDIF";
funcMatch[FunctionCode.SELECTCASE] = "ENDSELECT";
funcMatch[FunctionCode.REPEAT] = "REND";
funcMatch[FunctionCode.FOR] = "NEXT";
funcMatch[FunctionCode.WHILE] = "WEND";
funcMatch[FunctionCode.TRYCGOTO] = "CATCH";
funcMatch[FunctionCode.TRYCJUMP] = "CATCH";
funcMatch[FunctionCode.TRYCCALL] = "CATCH";
funcMatch[FunctionCode.TRYCGOTOFORM] = "CATCH";
funcMatch[FunctionCode.TRYCJUMPFORM] = "CATCH";
funcMatch[FunctionCode.TRYCCALLFORM] = "CATCH";
funcMatch[FunctionCode.CATCH] = "ENDCATCH";
funcMatch[FunctionCode.DO] = "LOOP";
funcMatch[FunctionCode.PRINTDATA] = "ENDDATA";
funcMatch[FunctionCode.PRINTDATAL] = "ENDDATA";
funcMatch[FunctionCode.PRINTDATAW] = "ENDDATA";
funcMatch[FunctionCode.PRINTDATAK] = "ENDDATA";
funcMatch[FunctionCode.PRINTDATAKL] = "ENDDATA";
funcMatch[FunctionCode.PRINTDATAKW] = "ENDDATA";
funcMatch[FunctionCode.PRINTDATAD] = "ENDDATA";
funcMatch[FunctionCode.PRINTDATADL] = "ENDDATA";
funcMatch[FunctionCode.PRINTDATADW] = "ENDDATA";
funcMatch[FunctionCode.DATALIST] = "ENDLIST";
funcMatch[FunctionCode.STRDATA] = "ENDDATA";
funcMatch[FunctionCode.NOSKIP] = "ENDNOSKIP";
funcMatch[FunctionCode.TRYCALLLIST] = "ENDFUNC";
funcMatch[FunctionCode.TRYGOTOLIST] = "ENDFUNC";
funcMatch[FunctionCode.TRYJUMPLIST] = "ENDFUNC";
funcParent[FunctionCode.REND] = FunctionCode.REPEAT;
funcParent[FunctionCode.NEXT] = FunctionCode.FOR;
funcParent[FunctionCode.WEND] = FunctionCode.WHILE;
funcParent[FunctionCode.LOOP] = FunctionCode.DO;
}
public static FunctionIdentifier SETFunction { get; }
internal static string getMatchFunction(FunctionCode func)
{
funcMatch.TryGetValue(func, out var ret);
return ret;
}
internal static FunctionCode getParentFunc(FunctionCode func)
{
funcParent.TryGetValue(func, out var ret);
return ret;
}
#endregion
private FunctionIdentifier(string name, FunctionCode code, AbstractInstruction instruction)
: this(name, code, instruction, 0)
{
}
private FunctionIdentifier(string name, FunctionCode code, AbstractInstruction instruction, int additionalFlag)
{
Code = code;
ArgBuilder = instruction.ArgBuilder;
flag = instruction.Flag | additionalFlag;
Method = null;
Name = name;
Instruction = instruction;
}
private FunctionIdentifier(string name, FunctionCode code, ArgumentBuilder arg, int flag)
{
Code = code;
ArgBuilder = arg;
this.flag = flag;
Method = null;
Name = name;
Instruction = null;
}
private FunctionIdentifier(string methodName, FunctionMethod method, AbstractInstruction instruction)
{
Code = FunctionCode.__NULL__;
ArgBuilder = instruction.ArgBuilder;
flag = instruction.Flag;
Method = method;
Name = methodName;
Instruction = instruction;
}
public readonly AbstractInstruction Instruction;
private readonly int flag;
public FunctionCode Code { get; }
public ArgumentBuilder ArgBuilder { get; }
public FunctionMethod Method { get; }
public string Name { get; private set; }
internal bool IsFlowContorol()
{
return ((flag & FLOW_CONTROL) == FLOW_CONTROL);
}
internal bool IsExtended()
{
return ((flag & EXTENDED) == EXTENDED);
}
internal bool IsPrintDFunction()
{
return ((flag & ISPRINTDFUNC) == ISPRINTDFUNC);
}
internal bool IsPrintKFunction()
{
return ((flag & ISPRINTKFUNC) == ISPRINTKFUNC);
}
internal bool IsNewLine()
{
return ((flag & PRINT_NEWLINE) == PRINT_NEWLINE);
}
internal bool IsWaitInput()
{
return ((flag & PRINT_WAITINPUT) == PRINT_WAITINPUT);
}
internal bool IsPrintSingle()
{
return ((flag & PRINT_SINGLE) == PRINT_SINGLE);
}
internal bool IsPartial()
{
return ((flag & PARTIAL) == PARTIAL);
}
internal bool IsMethodSafe()
{
return ((flag & METHOD_SAFE) == METHOD_SAFE);
}
internal bool IsPrint()
{
return ((flag & IS_PRINT) == IS_PRINT);
}
internal bool IsInput()
{
return ((flag & IS_INPUT) == IS_INPUT);
}
internal bool IsPrintData()
{
return ((flag & IS_PRINTDATA) == IS_PRINTDATA);
}
internal bool IsForceSetArg()
{
return ((flag & FORCE_SETARG) == FORCE_SETARG);
}
internal bool IsDebug()
{
return ((flag & DEBUG_FUNC) == DEBUG_FUNC);
}
internal bool IsTry()
{
return ((flag & IS_TRY) == IS_TRY);
}
internal bool IsJump()
{
return ((flag & IS_JUMP) == IS_JUMP);
}
internal bool IsMethod()
{
return Method != null;
}
public override string ToString()
{
return Name;
}
}
}