ArgumentBuilder.cs 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using Microsoft.VisualBasic;
  5. using NTERA.EmuEra.Game.EraEmu.GameData;
  6. using NTERA.EmuEra.Game.EraEmu.GameData.Expression;
  7. using NTERA.EmuEra.Game.EraEmu.GameData.Function;
  8. using NTERA.EmuEra.Game.EraEmu.GameData.Variable;
  9. using NTERA.EmuEra.Game.EraEmu.Sub;
  10. namespace NTERA.EmuEra.Game.EraEmu.GameProc.Function
  11. {
  12. internal abstract class ArgumentBuilder
  13. {
  14. protected void assignwarn(string mes, InstructionLine line, int level, bool isBackComp)
  15. {
  16. bool isError = level >= 2;
  17. if (isError)
  18. {
  19. line.IsError = true;
  20. line.ErrMes = mes;
  21. }
  22. ParserMediator.Warn(mes, line, level, isError, isBackComp);
  23. }
  24. protected void warn(string mes, InstructionLine line, int level, bool isBackComp)
  25. {
  26. mes = line.Function.Name + " Instruction:" + mes;
  27. bool isError = level >= 2;
  28. if (isError)
  29. {
  30. line.IsError = true;
  31. line.ErrMes = mes;
  32. }
  33. ParserMediator.Warn(mes, line, level, isError, isBackComp);
  34. }
  35. /// <summary>
  36. /// 引数の型と数。typeof(void)で任意の型(あるいは個別にチェックするべき引数)。nullでその引数は省略可能
  37. /// </summary>
  38. protected Type[] argumentTypeArray;//
  39. /// <summary>
  40. /// 最低限必要な引数の数。設定しないと全て省略不可。
  41. /// </summary>
  42. protected int minArg = -1;
  43. /// <summary>
  44. /// 引数の数に制限なし。
  45. /// </summary>
  46. protected bool argAny;
  47. protected bool checkArgumentType(InstructionLine line, ExpressionMediator exm, IOperandTerm[] arguments)
  48. {
  49. if (arguments == null)
  50. {
  51. warn("Missing argument", line, 2, false);
  52. return false;
  53. }
  54. if ( arguments.Length < minArg ||
  55. ((arguments.Length < argumentTypeArray.Length) && (minArg < 0)) )
  56. {
  57. warn("Not enough arguments", line, 2, false);
  58. return false;
  59. }
  60. int length = arguments.Length;
  61. if ((arguments.Length > argumentTypeArray.Length)&&(!argAny))
  62. {
  63. warn("Too many arguments", line, 1, false);
  64. length = argumentTypeArray.Length;
  65. }
  66. for (int i = 0; i < length; i++)
  67. {
  68. Type allowType;
  69. if ((!argAny) && (argumentTypeArray[i] == null))
  70. continue;
  71. if (argAny && i >= argumentTypeArray.Length)
  72. allowType = argumentTypeArray[argumentTypeArray.Length - 1];
  73. else
  74. allowType = argumentTypeArray[i];
  75. if (arguments[i] == null)
  76. {
  77. if (allowType == null)
  78. continue;
  79. warn("Argument number " + (i + 1) + ": unable to recognize argument", line, 2, false);
  80. return false;
  81. }
  82. if ((allowType != typeof(void)) && (allowType != arguments[i].GetOperandType()))
  83. {
  84. warn("Argument number " + (i + 1) + ": argument type is incorrect", line, 2, false);
  85. return false;
  86. }
  87. }
  88. length = arguments.Length;
  89. for (int i = 0; i < length; i++)
  90. {
  91. if (arguments[i] == null)
  92. continue;
  93. arguments[i] = arguments[i].Restructure(exm);
  94. }
  95. return true;
  96. }
  97. protected VariableTerm getChangeableVariable(IOperandTerm[] terms, int i, InstructionLine line)
  98. {
  99. VariableTerm varTerm = terms[i - 1] as VariableTerm;
  100. if (varTerm == null)
  101. {
  102. warn("第" + i + "引数に変数以外を指定することはできません", line, 2, false);
  103. return null;
  104. }
  105. if (varTerm.Identifier.IsConst)
  106. {
  107. warn("第" + i + "引数に変更できない変数を指定することはできません", line, 2, false);
  108. return null;
  109. }
  110. return varTerm;
  111. }
  112. protected WordCollection popWords(InstructionLine line)
  113. {
  114. StringStream st = line.PopArgumentPrimitive();
  115. return LexicalAnalyzer.Analyse(st, LexEndWith.EoL, LexAnalyzeFlag.None);
  116. }
  117. protected IOperandTerm[] popTerms(InstructionLine line)
  118. {
  119. StringStream st = line.PopArgumentPrimitive();
  120. WordCollection wc = LexicalAnalyzer.Analyse(st, LexEndWith.EoL, LexAnalyzeFlag.None);
  121. return ExpressionParser.ReduceArguments(wc, ArgsEndWith.EoL, false);
  122. }
  123. public abstract Argument CreateArgument(InstructionLine line, ExpressionMediator exm);
  124. }
  125. internal static partial class ArgumentParser
  126. {
  127. static readonly Dictionary<FunctionArgType, ArgumentBuilder> argb = new Dictionary<FunctionArgType, ArgumentBuilder>();
  128. public static Dictionary<FunctionArgType, ArgumentBuilder> GetArgumentBuilderDictionary()
  129. {
  130. return argb;
  131. }
  132. public static ArgumentBuilder GetArgumentBuilder(FunctionArgType key)
  133. {
  134. return argb[key];
  135. }
  136. static ArgumentParser()
  137. {
  138. argb[FunctionArgType.METHOD] = new METHOD_ArgumentBuilder();
  139. argb[FunctionArgType.VOID] = new VOID_ArgumentBuilder();
  140. argb[FunctionArgType.INT_EXPRESSION] = new INT_EXPRESSION_ArgumentBuilder(false);
  141. argb[FunctionArgType.INT_EXPRESSION_NULLABLE] = new INT_EXPRESSION_ArgumentBuilder(true);
  142. argb[FunctionArgType.STR_EXPRESSION] = new STR_EXPRESSION_ArgumentBuilder(false);
  143. argb[FunctionArgType.STR_EXPRESSION_NULLABLE] = new STR_EXPRESSION_ArgumentBuilder(true);
  144. argb[FunctionArgType.STR] = new STR_ArgumentBuilder(false);
  145. argb[FunctionArgType.STR_NULLABLE] = new STR_ArgumentBuilder(true);
  146. argb[FunctionArgType.FORM_STR] = new FORM_STR_ArgumentBuilder(false);
  147. argb[FunctionArgType.FORM_STR_NULLABLE] = new FORM_STR_ArgumentBuilder(true);
  148. argb[FunctionArgType.SP_PRINTV] = new SP_PRINTV_ArgumentBuilder();
  149. argb[FunctionArgType.SP_TIMES] = new SP_TIMES_ArgumentBuilder();
  150. argb[FunctionArgType.SP_BAR] = new SP_BAR_ArgumentBuilder();
  151. argb[FunctionArgType.SP_SET] = new SP_SET_ArgumentBuilder();
  152. argb[FunctionArgType.SP_SETS] = new SP_SET_ArgumentBuilder();
  153. argb[FunctionArgType.SP_SWAP] = new SP_SWAP_ArgumentBuilder(false);
  154. argb[FunctionArgType.SP_VAR] = new SP_VAR_ArgumentBuilder();
  155. argb[FunctionArgType.SP_SAVEDATA] = new SP_SAVEDATA_ArgumentBuilder();
  156. argb[FunctionArgType.SP_TINPUT] = new SP_TINPUT_ArgumentBuilder();
  157. argb[FunctionArgType.SP_TINPUTS] = new SP_TINPUTS_ArgumentBuilder();
  158. argb[FunctionArgType.SP_SORTCHARA] = new SP_SORTCHARA_ArgumentBuilder();
  159. argb[FunctionArgType.SP_CALL] = new SP_CALL_ArgumentBuilder(false, false);
  160. argb[FunctionArgType.SP_CALLF] = new SP_CALL_ArgumentBuilder(true, false);
  161. argb[FunctionArgType.SP_CALLFORM] = new SP_CALL_ArgumentBuilder(false, true);
  162. argb[FunctionArgType.SP_CALLFORMF] = new SP_CALL_ArgumentBuilder(true, true);
  163. argb[FunctionArgType.SP_FOR_NEXT] = new SP_FOR_NEXT_ArgumentBuilder();
  164. argb[FunctionArgType.SP_POWER] = new SP_POWER_ArgumentBuilder();
  165. argb[FunctionArgType.SP_SWAPVAR] = new SP_SWAPVAR_ArgumentBuilder();
  166. argb[FunctionArgType.EXPRESSION] = new EXPRESSION_ArgumentBuilder(false);
  167. argb[FunctionArgType.EXPRESSION_NULLABLE] = new EXPRESSION_ArgumentBuilder(true);
  168. argb[FunctionArgType.CASE] = new CASE_ArgumentBuilder();
  169. argb[FunctionArgType.VAR_INT] = new VAR_INT_ArgumentBuilder();
  170. argb[FunctionArgType.VAR_STR] = new VAR_STR_ArgumentBuilder();
  171. argb[FunctionArgType.BIT_ARG] = new BIT_ARG_ArgumentBuilder();
  172. argb[FunctionArgType.SP_VAR_SET] = new SP_VAR_SET_ArgumentBuilder();
  173. argb[FunctionArgType.SP_BUTTON] = new SP_BUTTON_ArgumentBuilder();
  174. argb[FunctionArgType.SP_COLOR] = new SP_COLOR_ArgumentBuilder();
  175. argb[FunctionArgType.SP_SPLIT] = new SP_SPLIT_ArgumentBuilder();
  176. argb[FunctionArgType.SP_GETINT] = new SP_GETINT_ArgumentBuilder();
  177. argb[FunctionArgType.SP_CVAR_SET] = new SP_CVAR_SET_ArgumentBuilder();
  178. argb[FunctionArgType.SP_CONTROL_ARRAY] = new SP_CONTROL_ARRAY_ArgumentBuilder();
  179. argb[FunctionArgType.SP_SHIFT_ARRAY] = new SP_SHIFT_ARRAY_ArgumentBuilder();
  180. argb[FunctionArgType.SP_SORTARRAY] = new SP_SORT_ARRAY_ArgumentBuilder();
  181. argb[FunctionArgType.INT_ANY] = new INT_ANY_ArgumentBuilder();
  182. argb[FunctionArgType.FORM_STR_ANY] = new FORM_STR_ANY_ArgumentBuilder();
  183. argb[FunctionArgType.SP_COPYCHARA] = new SP_SWAP_ArgumentBuilder(true);
  184. argb[FunctionArgType.SP_INPUT] = new SP_INPUT_ArgumentBuilder();
  185. argb[FunctionArgType.SP_INPUTS] = new SP_INPUTS_ArgumentBuilder();
  186. argb[FunctionArgType.SP_COPY_ARRAY] = new SP_COPY_ARRAY_Arguments();
  187. argb[FunctionArgType.SP_SAVEVAR] = new SP_SAVEVAR_ArgumentBuilder();
  188. argb[FunctionArgType.SP_SAVECHARA] = new SP_SAVECHARA_ArgumentBuilder();
  189. argb[FunctionArgType.SP_REF] = new SP_REF_ArgumentBuilder(false);
  190. argb[FunctionArgType.SP_REFBYNAME] = new SP_REF_ArgumentBuilder(true);
  191. argb[FunctionArgType.SP_HTMLSPLIT] = new SP_HTMLSPLIT_ArgumentBuilder();
  192. }
  193. private sealed class SP_PRINTV_ArgumentBuilder : ArgumentBuilder
  194. {
  195. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  196. {
  197. StringStream st = line.PopArgumentPrimitive();
  198. WordCollection wc = LexicalAnalyzer.Analyse(st, LexEndWith.EoL, LexAnalyzeFlag.AnalyzePrintV);
  199. IOperandTerm[] args = ExpressionParser.ReduceArguments(wc, ArgsEndWith.EoL, false);
  200. for(int i = 0; i< args.Length;i++)
  201. {
  202. if(args[i] == null)
  203. {warn("Argument cannot be omitted", line, 2, false); return null;}
  204. args[i] = args[i].Restructure(exm);
  205. }
  206. return new SpPrintVArgument(args);
  207. }
  208. }
  209. private sealed class SP_TIMES_ArgumentBuilder : ArgumentBuilder
  210. {
  211. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  212. {
  213. StringStream st = line.PopArgumentPrimitive();
  214. WordCollection wc = LexicalAnalyzer.Analyse(st, LexEndWith.Comma, LexAnalyzeFlag.None);
  215. st.ShiftNext();
  216. if (st.EOS)
  217. {warn("Not enough arguments", line, 2, false); return null;}
  218. double d = 0.0;
  219. try
  220. {
  221. LexicalAnalyzer.SkipWhiteSpace(st);
  222. d = LexicalAnalyzer.ReadDouble(st);
  223. LexicalAnalyzer.SkipWhiteSpace(st);
  224. if (!st.EOS)
  225. warn("Too many arguments", line, 1, false);
  226. }
  227. catch
  228. {
  229. warn("The second argument is not a real number (it is always interpreted as 0)", line, 1, false);
  230. d = 0.0;
  231. }
  232. IOperandTerm term = ExpressionParser.ReduceExpressionTerm(wc, TermEndWith.EoL);
  233. if (term == null)
  234. { warn("The format is wrong", line, 2, false); return null; }
  235. VariableTerm varTerm = term.Restructure(exm) as VariableTerm;
  236. if (varTerm == null)
  237. { warn("You cannot specify anything other than variables for the first argument", line, 2, false); return null; }
  238. if (varTerm.IsString)
  239. { warn("The first argument cannot be a string variable", line, 2, false); return null; }
  240. if (varTerm.Identifier.IsConst)
  241. { warn("It is not possible to specify a variable that cannot be changed as the first argument", line, 2, false); return null; }
  242. return new SpTimesArgument(varTerm, d);
  243. }
  244. }
  245. private sealed class FORM_STR_ANY_ArgumentBuilder : ArgumentBuilder
  246. {
  247. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  248. {
  249. Argument ret = null;
  250. StringStream st = line.PopArgumentPrimitive();
  251. List<IOperandTerm> termList = new List<IOperandTerm>();
  252. LexicalAnalyzer.SkipHalfSpace(st);
  253. if (st.EOS)
  254. {
  255. if (line.FunctionCode == FunctionCode.RETURNFORM)
  256. {
  257. termList.Add(new SingleTerm("0"));
  258. ret = new ExpressionArrayArgument(termList);
  259. ret.IsConst = true;
  260. ret.ConstInt = 0;
  261. return ret;
  262. }
  263. warn("Argument is not set", line, 2, false);
  264. return null;
  265. }
  266. while (true)
  267. {
  268. StrFormWord sfwt = LexicalAnalyzer.AnalyseFormattedString(st, FormStrEndWith.Comma, false);
  269. IOperandTerm term = ExpressionParser.ToStrFormTerm(sfwt);
  270. term = term.Restructure(exm);
  271. termList.Add(term);
  272. st.ShiftNext();
  273. if (st.EOS)
  274. break;
  275. LexicalAnalyzer.SkipHalfSpace(st);
  276. if (st.EOS)
  277. {
  278. warn("\',\' doesn't have an argument after it", line, 1, false);
  279. break;
  280. }
  281. }
  282. return new ExpressionArrayArgument(termList);
  283. }
  284. }
  285. private sealed class VOID_ArgumentBuilder : ArgumentBuilder
  286. {
  287. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  288. {
  289. StringStream st = line.PopArgumentPrimitive();
  290. LexicalAnalyzer.SkipWhiteSpace(st);
  291. if (!st.EOS)
  292. warn("Argument is not required", line, 1, false);
  293. return new VoidArgument();
  294. }
  295. }
  296. private sealed class STR_ArgumentBuilder : ArgumentBuilder
  297. {
  298. public STR_ArgumentBuilder(bool nullable)
  299. {
  300. this.nullable = nullable;
  301. }
  302. bool nullable;
  303. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  304. {
  305. StringStream st = line.PopArgumentPrimitive();
  306. string rowStr = null;
  307. if (st.EOS)
  308. {
  309. if (!nullable)
  310. {
  311. warn("Argument is not set", line, 2, false);
  312. return null;
  313. }
  314. rowStr = "";
  315. //1756 処理変更のために完全に見分けが付かなくなってしまった
  316. //if (line.FunctionCode == FunctionCode.PRINTL)
  317. // warn("PRINTLの後ろに空白がありません(eramaker:\'PRINTL\'を表示)", line, 0, true);
  318. }
  319. else
  320. rowStr = st.Substring();
  321. if (line.FunctionCode == FunctionCode.SETCOLORBYNAME || line.FunctionCode == FunctionCode.SETBGCOLORBYNAME)
  322. {
  323. Color c = Color.FromName(rowStr);
  324. if (c.A == 0)
  325. {
  326. if (rowStr.Equals("transparent", StringComparison.OrdinalIgnoreCase))
  327. throw new CodeEE("無色透明(Transparent)は色として指定できません");
  328. throw new CodeEE("指定された色名\"" + rowStr + "\"は無効な色名です");
  329. }
  330. }
  331. Argument ret = new ExpressionArgument(new SingleTerm(rowStr));
  332. ret.ConstStr = rowStr;
  333. ret.IsConst = true;
  334. return ret;
  335. }
  336. }
  337. private sealed class FORM_STR_ArgumentBuilder : ArgumentBuilder
  338. {
  339. public FORM_STR_ArgumentBuilder(bool nullable)
  340. {
  341. this.nullable = nullable;
  342. }
  343. bool nullable;
  344. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  345. {
  346. StringStream st = line.PopArgumentPrimitive();
  347. Argument ret = null;
  348. if (st.EOS)
  349. {
  350. if(!nullable)
  351. {
  352. warn("Argument is not set", line, 2, false);
  353. return null;
  354. }
  355. //if (line.FunctionCode == FunctionCode.PRINTFORML)
  356. // warn("PRINTFORMLの後ろに空白がありません(eramaker:\'PRINTFORML\'を表示)", line, 0, true);
  357. ret = new ExpressionArgument(new SingleTerm(""));
  358. ret.ConstStr = "";
  359. ret.IsConst = true;
  360. return ret;
  361. }
  362. StrFormWord sfwt = LexicalAnalyzer.AnalyseFormattedString(st, FormStrEndWith.EoL, false);
  363. IOperandTerm term = ExpressionParser.ToStrFormTerm(sfwt);
  364. term = term.Restructure(exm);
  365. ret = new ExpressionArgument(term);
  366. if(term is SingleTerm)
  367. {
  368. ret.ConstStr = term.GetStrValue(exm);
  369. ret.IsConst = true;
  370. }
  371. return ret;
  372. }
  373. }
  374. private sealed class SP_VAR_ArgumentBuilder : ArgumentBuilder
  375. {
  376. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  377. {
  378. StringStream st = line.PopArgumentPrimitive();
  379. IdentifierWord iw = LexicalAnalyzer.ReadSingleIdentifierWord(st);
  380. if (iw == null)
  381. { warn("第1引数を読み取ることができません", line, 2, false); return null; }
  382. string idStr = iw.Code;
  383. VariableToken id = GlobalStatic.IdentifierDictionary.GetVariableToken(idStr, null, true);
  384. if (id == null)
  385. { warn("You cannot specify anything other than variables for the first argument", line, 2, false); return null; }
  386. if ((!id.IsArray1D && !id.IsArray2D && !id.IsArray3D) || (id.Code == VariableCode.RAND))
  387. { warn("第1引数に配列でない変数を指定することはできません", line, 2, false); return null; }
  388. LexicalAnalyzer.SkipWhiteSpace(st);
  389. if (!st.EOS)
  390. {
  391. warn("引数の後に余分な文字があります", line, 1, false);
  392. }
  393. return new SpVarsizeArgument(id);
  394. }
  395. }
  396. private sealed class SP_SORTCHARA_ArgumentBuilder : ArgumentBuilder
  397. {
  398. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  399. {
  400. VariableTerm varTerm = new VariableTerm(GlobalStatic.VariableData.GetSystemVariableToken("NO"), new IOperandTerm[] { new SingleTerm(0) });
  401. SortOrder order = SortOrder.ASCENDING;
  402. WordCollection wc = popWords(line);
  403. IdentifierWord id = wc.Current as IdentifierWord;
  404. if (wc.EOL)
  405. {
  406. return new SpSortcharaArgument(varTerm, order);
  407. }
  408. if ((id != null) && (id.Code.Equals("FORWARD", Config.Config.SCVariable)
  409. || (id.Code.Equals("BACK", Config.Config.SCVariable))))
  410. {
  411. if (id.Code.Equals("BACK", Config.Config.SCVariable))
  412. order = SortOrder.DESENDING;
  413. wc.ShiftNext();
  414. if (!wc.EOL)
  415. warn("Too many arguments", line, 1, false);
  416. }
  417. else
  418. {
  419. IOperandTerm term = ExpressionParser.ReduceExpressionTerm(wc, TermEndWith.Comma);
  420. if (term == null)
  421. { warn("The format is wrong", line, 2, false); return null; }
  422. varTerm = term.Restructure(exm) as VariableTerm;
  423. if (varTerm == null)
  424. { warn("You cannot specify anything other than variables for the first argument", line, 2, false); return null; }
  425. if (!varTerm.Identifier.IsCharacterData)
  426. { warn("The first argument must be a character variable", line, 2, false); return null; }
  427. wc.ShiftNext();
  428. if (!wc.EOL)
  429. {
  430. id = wc.Current as IdentifierWord;
  431. if ((id != null) && (id.Code.Equals("FORWARD", Config.Config.SCVariable)
  432. || (id.Code.Equals("BACK", Config.Config.SCVariable))))
  433. {
  434. if (id.Code.Equals("BACK", Config.Config.SCVariable))
  435. order = SortOrder.DESENDING;
  436. wc.ShiftNext();
  437. if (!wc.EOL)
  438. warn("Too many arguments", line, 1, false);
  439. }
  440. else
  441. { warn("The format is wrong", line, 2, false); return null; }
  442. }
  443. }
  444. return new SpSortcharaArgument(varTerm, order);
  445. }
  446. }
  447. private sealed class SP_SORT_ARRAY_ArgumentBuilder : ArgumentBuilder
  448. {
  449. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  450. {
  451. SortOrder order = SortOrder.ASCENDING;
  452. WordCollection wc = popWords(line);
  453. IOperandTerm term3 = new SingleTerm(0);
  454. IOperandTerm term4 = null;
  455. if (wc.EOL)
  456. {
  457. warn("The format is wrong", line, 2, false); return null;
  458. }
  459. VariableTerm varTerm;
  460. IOperandTerm term = ExpressionParser.ReduceExpressionTerm(wc, TermEndWith.Comma);
  461. if (term == null)
  462. { warn("The format is wrong", line, 2, false); return null; }
  463. varTerm = term.Restructure(exm) as VariableTerm;
  464. if (varTerm == null)
  465. { warn("You cannot specify anything other than variables for the first argument", line, 2, false); return null; }
  466. if (varTerm.Identifier.IsConst)
  467. { warn("The first argument cannot be changed", line, 2, false); return null; }
  468. if (!varTerm.Identifier.IsArray1D)
  469. { warn("You cannot specify a non-one-dimensional array or array type character variable as the first argument", line, 2, false); return null; }
  470. wc.ShiftNext();
  471. IdentifierWord id = wc.Current as IdentifierWord;
  472. if ((id != null) && (id.Code.Equals("FORWARD", Config.Config.SCVariable) || (id.Code.Equals("BACK", Config.Config.SCVariable))))
  473. {
  474. if (id.Code.Equals("BACK", Config.Config.SCVariable))
  475. order = SortOrder.DESENDING;
  476. wc.ShiftNext();
  477. }
  478. else if (id != null)
  479. { warn("第2引数にソート方法指定子(FORWARD or BACK)以外が指定されています", line, 2, false); return null; }
  480. if (id != null)
  481. {
  482. wc.ShiftNext();
  483. if (!wc.EOL)
  484. {
  485. term3 = ExpressionParser.ReduceExpressionTerm(wc, TermEndWith.Comma);
  486. if (term3 == null)
  487. { warn("The third argument cannot be interpreted", line, 2, false); return null; }
  488. if (!term3.IsInteger)
  489. { warn("The third argument is not a number", line, 2, false); return null; }
  490. wc.ShiftNext();
  491. if (!wc.EOL)
  492. {
  493. term4 = ExpressionParser.ReduceExpressionTerm(wc, TermEndWith.Comma);
  494. if (term4 == null)
  495. { warn("The fourth argument cannot be interpreted", line, 2, false); return null; }
  496. if (!term4.IsInteger)
  497. { warn("The fourth argument is not a number", line, 2, false); return null; }
  498. wc.ShiftNext();
  499. if (!wc.EOL)
  500. warn("Too many arguments", line, 1, false);
  501. }
  502. }
  503. }
  504. return new SpArraySortArgument(varTerm, order, term3, term4);
  505. }
  506. }
  507. private sealed class SP_CALL_ArgumentBuilder : ArgumentBuilder
  508. {
  509. public SP_CALL_ArgumentBuilder(bool callf, bool form)
  510. {
  511. this.form = form;
  512. this.callf = callf;
  513. }
  514. bool form;
  515. bool callf;
  516. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  517. {
  518. StringStream st = line.PopArgumentPrimitive();
  519. IOperandTerm funcname = null;
  520. if (form)
  521. {
  522. StrFormWord sfw = LexicalAnalyzer.AnalyseFormattedString(st, FormStrEndWith.LeftParenthesis_Bracket_Comma_Semicolon, true);
  523. funcname = ExpressionParser.ToStrFormTerm(sfw);
  524. funcname = funcname.Restructure(exm);
  525. }
  526. else
  527. {
  528. string str = LexicalAnalyzer.ReadString(st, StrEndWith.LeftParenthesis_Bracket_Comma_Semicolon);
  529. str = str.Trim(' ', '\t');
  530. funcname = new SingleTerm(str);
  531. }
  532. char cur = st.Current;
  533. WordCollection wc = LexicalAnalyzer.Analyse(st, LexEndWith.EoL, LexAnalyzeFlag.None);
  534. wc.ShiftNext();
  535. IOperandTerm[] subNames = null;
  536. IOperandTerm[] args = null;
  537. if (cur == '[')
  538. {
  539. subNames = ExpressionParser.ReduceArguments(wc, ArgsEndWith.RightBracket, false);
  540. if (!wc.EOL)
  541. {
  542. if (wc.Current.Type != '(')
  543. wc.ShiftNext();
  544. args = ExpressionParser.ReduceArguments(wc, ArgsEndWith.RightParenthesis, false);
  545. }
  546. }
  547. if ((cur == '(') || (cur == ','))
  548. {
  549. if (cur == '(')
  550. args = ExpressionParser.ReduceArguments(wc, ArgsEndWith.RightParenthesis, false);
  551. else
  552. args = ExpressionParser.ReduceArguments(wc, ArgsEndWith.EoL, false);
  553. if (!wc.EOL)
  554. { warn("The format is wrong", line, 2, false); return null; }
  555. }
  556. if (subNames == null)
  557. subNames = new IOperandTerm[0];
  558. if (args == null)
  559. args = new IOperandTerm[0];
  560. for(int i = 0; i < subNames.Length; i++)
  561. if (subNames != null)
  562. subNames[i] = subNames[i].Restructure(exm);
  563. for(int i = 0; i < args.Length; i++)
  564. if (args[i] != null)
  565. args[i] = args[i].Restructure(exm);
  566. Argument ret = null;
  567. if(callf)
  568. ret = new SpCallFArgment(funcname, subNames, args);
  569. else
  570. ret = new SpCallArgment(funcname, subNames, args);
  571. if (funcname is SingleTerm)
  572. {
  573. ret.IsConst = true;
  574. ret.ConstStr = funcname.GetStrValue(null);
  575. if (ret.ConstStr == "")
  576. {
  577. warn("Function name is not specified", line, 2, false);
  578. return null;
  579. }
  580. }
  581. return ret;
  582. }
  583. }
  584. private sealed class CASE_ArgumentBuilder : ArgumentBuilder
  585. {
  586. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  587. {
  588. WordCollection wc = popWords(line);
  589. CaseExpression[] args = ExpressionParser.ReduceCaseExpressions(wc);
  590. if ((!wc.EOL) || (args.Length == 0))
  591. { warn("The format is wrong", line, 2, false); return null; }
  592. for(int i = 0; i < args.Length; i++)
  593. args[i].Reduce(exm);
  594. return new CaseArgument(args);
  595. }
  596. }
  597. private sealed class SP_SET_ArgumentBuilder : ArgumentBuilder
  598. {
  599. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  600. {
  601. WordCollection destWc = line.PopAssignmentDestStr();
  602. IOperandTerm[] destTerms = ExpressionParser.ReduceArguments(destWc, ArgsEndWith.EoL, false);
  603. SpSetArgument ret = null;
  604. if ((destTerms.Length == 0) || (destTerms[0] == null))
  605. { assignwarn("Failed to read the left side of the assignment statement", line, 2, false); return null; }
  606. if (destTerms.Length != 1)
  607. {assignwarn("Left side of the assignment statement has an extra ','", line, 2, false); return null;}
  608. VariableTerm varTerm = destTerms[0] as VariableTerm;
  609. if (varTerm == null)
  610. {//
  611. assignwarn("You cannot specify anything other than variables on the left side of the assignment statement", line, 2, false);
  612. return null;
  613. }
  614. if (varTerm.Identifier.IsConst)
  615. {
  616. assignwarn("It is not possible to specify a variable that cannot be changed on the left side of the assignment statement", line, 2, false);
  617. return null;
  618. }
  619. varTerm.Restructure(exm);
  620. StringStream st = line.PopArgumentPrimitive();
  621. if (st == null)
  622. st = new StringStream("");
  623. OperatorCode op = line.AssignOperator;
  624. IOperandTerm src = null;
  625. if(varTerm.IsInteger)
  626. {
  627. if (op == OperatorCode.AssignmentStr)
  628. { assignwarn("整数型の代入に演算子"+OperatorManager.ToOperatorString(op) + "は使用できません", line, 2, false); return null; }
  629. if((op == OperatorCode.Increment)||(op == OperatorCode.Decrement))
  630. {
  631. LexicalAnalyzer.SkipWhiteSpace(st);
  632. if (!st.EOS)
  633. {
  634. if (op == OperatorCode.Increment)
  635. {assignwarn("インクリメント行でインクリメント以外の処理が定義されています", line, 2, false);return null;}
  636. assignwarn("デクリメント行でデクリメント以外の処理が定義されています", line, 2, false);return null;
  637. }
  638. ret = new SpSetArgument(varTerm, null);
  639. ret.IsConst = true;
  640. if (op == OperatorCode.Increment)
  641. ret.ConstInt = 1;
  642. else
  643. ret.ConstInt = -1;
  644. ret.AddConst = true;
  645. return ret;
  646. }
  647. WordCollection srcWc = LexicalAnalyzer.Analyse(st, LexEndWith.EoL, LexAnalyzeFlag.None);
  648. IOperandTerm[] srcTerms = ExpressionParser.ReduceArguments(srcWc, ArgsEndWith.EoL, false);
  649. if ((srcTerms.Length == 0) || (srcTerms[0] == null))
  650. {assignwarn("代入文の右辺の読み取りに失敗しました", line, 2, false); return null;}
  651. if (srcTerms.Length != 1)
  652. {
  653. if(op != OperatorCode.Assignment)
  654. {assignwarn("複合代入演算では右辺に複数の値を含めることはできません", line, 2, false); return null;}
  655. bool allConst = true;
  656. Int64[] constValues = new Int64[srcTerms.Length];
  657. for (int i = 0; i < srcTerms.Length; i++)
  658. {
  659. if (srcTerms[i] == null)
  660. { assignwarn("代入式の右辺の値は省略できません", line, 2, false); return null; }
  661. if (!srcTerms[i].IsInteger)
  662. { assignwarn("数値型変数に文字列は代入できません", line, 2, false); return null; }
  663. srcTerms[i] = srcTerms[i].Restructure(exm);
  664. if (allConst && (srcTerms[i] is SingleTerm))
  665. constValues[i] = srcTerms[i].GetIntValue(null);
  666. else
  667. allConst = false;
  668. }
  669. SpSetArrayArgument arrayarg = new SpSetArrayArgument(varTerm, srcTerms, constValues);
  670. arrayarg.IsConst = allConst;
  671. return arrayarg;
  672. }
  673. if(!srcTerms[0].IsInteger)
  674. {assignwarn("数値型変数に文字列は代入できません", line, 2, false); return null;}
  675. src = srcTerms[0].Restructure(exm);
  676. if(op == OperatorCode.Assignment)
  677. {
  678. ret = new SpSetArgument(varTerm, src);
  679. if(src is SingleTerm)
  680. {
  681. ret.IsConst = true;
  682. ret.AddConst = false;
  683. ret.ConstInt = src.GetIntValue(null);
  684. }
  685. return ret;
  686. }
  687. if((op == OperatorCode.Plus)||(op == OperatorCode.Minus))
  688. {
  689. if(src is SingleTerm)
  690. {
  691. ret = new SpSetArgument(varTerm, null);
  692. ret.IsConst = true;
  693. ret.AddConst = true;
  694. if (op == OperatorCode.Plus)
  695. ret.ConstInt = src.GetIntValue(null);
  696. else
  697. ret.ConstInt = -src.GetIntValue(null);
  698. return ret;
  699. }
  700. }
  701. src = OperatorMethodManager.ReduceBinaryTerm(op,varTerm, src);
  702. return new SpSetArgument(varTerm, src);
  703. }
  704. if (op == OperatorCode.Assignment)
  705. {
  706. LexicalAnalyzer.SkipHalfSpace(st);//文字列の代入なら半角スペースだけを読み飛ばす
  707. //eramakerは代入文では妙なTrim()をする。半端にしか再現できないがとりあえずtrim = true
  708. StrFormWord sfwt = LexicalAnalyzer.AnalyseFormattedString(st, FormStrEndWith.EoL, true);
  709. IOperandTerm term = ExpressionParser.ToStrFormTerm(sfwt);
  710. src = term.Restructure(exm);
  711. ret = new SpSetArgument(varTerm, src);
  712. if (src is SingleTerm)
  713. {
  714. ret.IsConst = true;
  715. ret.AddConst = false;
  716. ret.ConstStr = src.GetStrValue(null);
  717. }
  718. return ret;
  719. }
  720. if ((op == OperatorCode.Mult)||(op == OperatorCode.Plus)||(op == OperatorCode.AssignmentStr))
  721. {
  722. WordCollection srcWc = LexicalAnalyzer.Analyse(st, LexEndWith.EoL, LexAnalyzeFlag.None);
  723. IOperandTerm[] srcTerms = ExpressionParser.ReduceArguments(srcWc, ArgsEndWith.EoL, false);
  724. if ((srcTerms.Length == 0) || (srcTerms[0] == null))
  725. {assignwarn("代入文の右辺の読み取りに失敗しました", line, 2, false); return null;}
  726. if (op == OperatorCode.AssignmentStr)
  727. {
  728. if (srcTerms.Length == 1)
  729. {
  730. if (srcTerms[0].IsInteger)
  731. { assignwarn("文字列変数に数値型は代入できません", line, 2, false); return null; }
  732. src = srcTerms[0].Restructure(exm);
  733. ret = new SpSetArgument(varTerm, src);
  734. if (src is SingleTerm)
  735. {
  736. ret.IsConst = true;
  737. ret.AddConst = false;
  738. ret.ConstStr = src.GetStrValue(null);
  739. }
  740. return ret;
  741. }
  742. bool allConst = true;
  743. string[] constValues = new string[srcTerms.Length];
  744. for (int i = 0; i < srcTerms.Length; i++)
  745. {
  746. if (srcTerms[i] == null)
  747. { assignwarn("代入式の右辺の値は省略できません", line, 2, false); return null; }
  748. if (srcTerms[i].IsInteger)
  749. { assignwarn("文字列変数に数値型は代入できません", line, 2, false); return null; }
  750. srcTerms[i] = srcTerms[i].Restructure(exm);
  751. if (allConst && (srcTerms[i] is SingleTerm))
  752. constValues[i] = srcTerms[i].GetStrValue(null);
  753. else
  754. allConst = false;
  755. }
  756. SpSetArrayArgument arrayarg = new SpSetArrayArgument(varTerm, srcTerms, constValues);
  757. arrayarg.IsConst = allConst;
  758. return arrayarg;
  759. }
  760. if (srcTerms.Length != 1)
  761. { assignwarn("代入文の右辺に余分な','があります", line, 2, false); return null; }
  762. src = srcTerms[0].Restructure(exm);
  763. src = OperatorMethodManager.ReduceBinaryTerm(op, varTerm, src);
  764. return new SpSetArgument(varTerm, src);
  765. }
  766. assignwarn("代入式に使用できない演算子が使われました", line, 2, false);
  767. return null;
  768. }
  769. }
  770. private sealed class METHOD_ArgumentBuilder : ArgumentBuilder
  771. {
  772. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  773. {
  774. IOperandTerm[] args = popTerms(line);
  775. string errmes = line.Function.Method.CheckArgumentType(line.Function.Name, args);
  776. if (errmes != null)
  777. throw new CodeEE(errmes);
  778. IOperandTerm mTerm = new FunctionMethodTerm(line.Function.Method, args);
  779. return new MethodArgument(mTerm.Restructure(exm));
  780. }
  781. }
  782. private sealed class SP_INPUTS_ArgumentBuilder : ArgumentBuilder
  783. {
  784. public SP_INPUTS_ArgumentBuilder()
  785. {
  786. argumentTypeArray = new[] { typeof(string) };
  787. //if (nullable)妥協
  788. minArg = 0;
  789. }
  790. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  791. {
  792. StringStream st = line.PopArgumentPrimitive();
  793. Argument ret = null;
  794. if (st.EOS)
  795. {
  796. ret = new ExpressionArgument(null);
  797. return ret;
  798. }
  799. StrFormWord sfwt = LexicalAnalyzer.AnalyseFormattedString(st, FormStrEndWith.EoL, false);
  800. if (!st.EOS)
  801. {
  802. warn("Too many arguments", line, 1, false);
  803. }
  804. IOperandTerm term = ExpressionParser.ToStrFormTerm(sfwt);
  805. term = term.Restructure(exm);
  806. ret = new ExpressionArgument(term);
  807. if (term is SingleTerm)
  808. {
  809. ret.ConstStr = term.GetStrValue(exm);
  810. if (line.FunctionCode == FunctionCode.ONEINPUTS)
  811. {
  812. if (string.IsNullOrEmpty(ret.ConstStr))
  813. {
  814. warn("引数が空文字列なため、引数は無視されます", line, 1, false);
  815. return new ExpressionArgument(null);
  816. }
  817. if (ret.ConstStr.Length > 1)
  818. {
  819. warn("ONEINPUTSの引数に2文字以上の文字列が渡されています(2文字目以降は無視されます)", line, 1, false);
  820. ret.ConstStr = ret.ConstStr.Remove(1);
  821. }
  822. }
  823. ret.IsConst = true;
  824. }
  825. return ret;
  826. }
  827. }
  828. #region 正規型 popTerms()とcheckArgumentType()を両方行うもの。考えることは最低限でよい。
  829. private sealed class INT_EXPRESSION_ArgumentBuilder : ArgumentBuilder
  830. {
  831. public INT_EXPRESSION_ArgumentBuilder(bool nullable)
  832. {
  833. argumentTypeArray = new[] { typeof(Int64) };
  834. //if (nullable)妥協
  835. minArg = 0;
  836. this.nullable = nullable;
  837. }
  838. bool nullable;
  839. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  840. {
  841. IOperandTerm[] terms = popTerms(line);
  842. if (!checkArgumentType(line, exm, terms))
  843. return null;
  844. IOperandTerm term = null;
  845. if (terms.Length == 0)
  846. {
  847. term = new SingleTerm(0);
  848. if (!nullable)
  849. {
  850. if (line.Function.IsExtended())
  851. warn("Arguments that cannot be omitted were omitted.\nEmuera will add 0.", line, 1, false);
  852. else
  853. warn("Arguments that cannot be omitted were omitted.\nEmuera adds 0, but the behavior of eramaker is undefined.", line, 1, false);
  854. }
  855. }
  856. else
  857. {
  858. term = terms[0];
  859. }
  860. if (line.FunctionCode == FunctionCode.REPEAT)
  861. {
  862. if ((term is SingleTerm) && (term.GetIntValue(null) <= 0L))
  863. {
  864. warn("REPEAT of 0 times or less has been detected (eramaker will throw an error)", line, 0, true);
  865. }
  866. VariableToken count = GlobalStatic.VariableData.GetSystemVariableToken("COUNT");
  867. VariableTerm repCount = new VariableTerm(count, new IOperandTerm[] { new SingleTerm(0) });
  868. repCount.Restructure(exm);
  869. return new SpForNextArgment(repCount, new SingleTerm(0), term, new SingleTerm(1));
  870. }
  871. ExpressionArgument ret = new ExpressionArgument(term);
  872. if (term is SingleTerm)
  873. {
  874. Int64 i = term.GetIntValue(null);
  875. ret.ConstInt = i;
  876. ret.IsConst = true;
  877. if (line.FunctionCode == FunctionCode.CLEARLINE)
  878. {
  879. if (i <= 0L)
  880. warn("A value less than or equal to 0 is passed as an argument (this line does nothing)", line, 1, false);
  881. }
  882. else if (line.FunctionCode == FunctionCode.FONTSTYLE)
  883. {
  884. if (i < 0L)
  885. warn("A negative value is passed as an argument (the result is undefined)", line, 1, false);
  886. }
  887. }
  888. return ret;
  889. }
  890. }
  891. private sealed class INT_ANY_ArgumentBuilder : ArgumentBuilder
  892. {
  893. public INT_ANY_ArgumentBuilder()
  894. {
  895. argumentTypeArray = new[] { typeof(Int64) };
  896. minArg = 0;
  897. argAny = true;
  898. }
  899. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  900. {
  901. IOperandTerm[] terms = popTerms(line);
  902. if (!checkArgumentType(line, exm, terms))
  903. return null;
  904. List<IOperandTerm> termList = new List<IOperandTerm>();
  905. termList.AddRange(terms);
  906. ExpressionArrayArgument ret = new ExpressionArrayArgument(termList);
  907. if (terms.Length == 0)
  908. {
  909. if (line.FunctionCode == FunctionCode.RETURN)
  910. {
  911. termList.Add(new SingleTerm(0));
  912. ret.IsConst = true;
  913. ret.ConstInt = 0;
  914. return ret;
  915. }
  916. warn("Argument is not set", line, 2, false);
  917. return null;
  918. }
  919. if (terms.Length == 1)
  920. {
  921. SingleTerm s = terms[0] as SingleTerm;
  922. if (s != null)
  923. {
  924. ret.IsConst = true;
  925. ret.ConstInt = s.Int;
  926. return ret;
  927. }
  928. if (line.FunctionCode == FunctionCode.RETURN)
  929. {
  930. //定数式は定数化してしまうので現行システムでは見つけられない
  931. if (terms[0] is VariableTerm)
  932. warn("Variable is passed as argument to RETURN (eramaker: Always returns 0)", line, 0, true);
  933. else
  934. warn("A formula is passed as an argument to RETURN (eramaker: Emuera returns a different value)", line, 0, true);
  935. }
  936. }
  937. else
  938. {
  939. warn(line.Function.Name + ": The arguments are given to more than one value. (eramaker: Not supported)", line, 0, true);
  940. }
  941. return ret;
  942. }
  943. }
  944. private sealed class STR_EXPRESSION_ArgumentBuilder : ArgumentBuilder
  945. {
  946. public STR_EXPRESSION_ArgumentBuilder(bool nullable)
  947. {
  948. argumentTypeArray = new[] { typeof(string) };
  949. if (nullable)
  950. minArg = 0;
  951. }
  952. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  953. {
  954. IOperandTerm[] terms = popTerms(line);
  955. if (!checkArgumentType(line, exm, terms))
  956. return null;
  957. ExpressionArgument ret = null;
  958. if (terms.Length == 0)
  959. {
  960. ret = new ExpressionArgument(new SingleTerm(""));
  961. ret.ConstStr = "";
  962. ret.IsConst = true;
  963. return ret;
  964. }
  965. return new ExpressionArgument(terms[0]);
  966. }
  967. }
  968. private sealed class EXPRESSION_ArgumentBuilder : ArgumentBuilder
  969. {
  970. public EXPRESSION_ArgumentBuilder(bool nullable)
  971. {
  972. argumentTypeArray = new[] { typeof(void) };
  973. if (nullable)
  974. minArg = 0;
  975. }
  976. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  977. {
  978. IOperandTerm[] terms = popTerms(line);
  979. if (!checkArgumentType(line, exm, terms))
  980. return null;
  981. if (terms.Length == 0)
  982. {
  983. ExpressionArgument ret = new ExpressionArgument(null);
  984. ret.ConstStr = "";
  985. ret.ConstInt = 0;
  986. ret.IsConst = true;
  987. return ret;
  988. }
  989. return new ExpressionArgument(terms[0]);
  990. }
  991. }
  992. private sealed class SP_BAR_ArgumentBuilder : ArgumentBuilder
  993. {
  994. public SP_BAR_ArgumentBuilder()
  995. {
  996. argumentTypeArray = new[] { typeof(Int64), typeof(Int64), typeof(Int64) };
  997. //minArg = 3;
  998. }
  999. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1000. {
  1001. IOperandTerm[] terms = popTerms(line);
  1002. if (!checkArgumentType(line, exm, terms))
  1003. return null;
  1004. return new SpBarArgument(terms[0], terms[1], terms[2]);
  1005. }
  1006. }
  1007. private sealed class SP_SWAP_ArgumentBuilder : ArgumentBuilder
  1008. {
  1009. //emuera1803beta2+v1 第2引数省略型に対応
  1010. public SP_SWAP_ArgumentBuilder(bool nullable)
  1011. {
  1012. argumentTypeArray = new[] { typeof(Int64), typeof(Int64) };
  1013. if (nullable)
  1014. minArg = 1;
  1015. }
  1016. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1017. {
  1018. IOperandTerm[] terms = popTerms(line);
  1019. if (!checkArgumentType(line, exm, terms))
  1020. return null;
  1021. //上の判定で省略不可時はここに来ないので即さばける
  1022. if (terms.Length == 1)
  1023. terms = new[] { terms[0], null };
  1024. return new SpSwapCharaArgument(terms[0], terms[1]);
  1025. }
  1026. }
  1027. private sealed class SP_SAVEDATA_ArgumentBuilder : ArgumentBuilder
  1028. {
  1029. public SP_SAVEDATA_ArgumentBuilder()
  1030. {
  1031. argumentTypeArray = new[] { typeof(Int64), typeof(string) };
  1032. }
  1033. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1034. {
  1035. IOperandTerm[] terms = popTerms(line);
  1036. if (!checkArgumentType(line, exm, terms))
  1037. return null;
  1038. return new SpSaveDataArgument(terms[0], terms[1]);
  1039. }
  1040. }
  1041. private sealed class SP_TINPUT_ArgumentBuilder : ArgumentBuilder
  1042. {
  1043. public SP_TINPUT_ArgumentBuilder()
  1044. {
  1045. argumentTypeArray = new[] { typeof(Int64), typeof(Int64), typeof(Int64), typeof(string) };
  1046. minArg = 2;
  1047. }
  1048. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1049. {
  1050. IOperandTerm[] terms = popTerms(line);
  1051. IOperandTerm term3 = null, term4 = null;
  1052. if (!checkArgumentType(line, exm, terms))
  1053. return null;
  1054. if (terms.Length > 2)
  1055. term3 = terms[2];
  1056. if (terms.Length > 3)
  1057. term4 = terms[3];
  1058. return new SpTInputsArgument(terms[0], terms[1], term3, term4);
  1059. }
  1060. }
  1061. private sealed class SP_TINPUTS_ArgumentBuilder : ArgumentBuilder
  1062. {
  1063. public SP_TINPUTS_ArgumentBuilder()
  1064. {
  1065. argumentTypeArray = new[] { typeof(Int64), typeof(string), typeof(Int64), typeof(string) };
  1066. minArg = 2;
  1067. }
  1068. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1069. {
  1070. IOperandTerm[] terms = popTerms(line);
  1071. IOperandTerm term3 = null, term4 = null;
  1072. if (!checkArgumentType(line, exm, terms))
  1073. return null;
  1074. if (terms.Length > 2)
  1075. term3 = terms[2];
  1076. if (terms.Length > 3)
  1077. term4 = terms[3];
  1078. return new SpTInputsArgument(terms[0], terms[1], term3, term4);
  1079. }
  1080. }
  1081. private sealed class SP_FOR_NEXT_ArgumentBuilder : ArgumentBuilder
  1082. {
  1083. public SP_FOR_NEXT_ArgumentBuilder()
  1084. {
  1085. argumentTypeArray = new[] { typeof(Int64), null, typeof(Int64), typeof(Int64) };
  1086. minArg = 3;
  1087. }
  1088. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1089. {
  1090. IOperandTerm[] terms = popTerms(line);
  1091. if (!checkArgumentType(line, exm, terms))
  1092. return null;
  1093. VariableTerm varTerm = getChangeableVariable(terms, 1, line);
  1094. if (varTerm == null)
  1095. return null;
  1096. if (varTerm.Identifier.IsCharacterData)
  1097. { warn("The character variable cannot be specified as the first argument", line, 2, false); return null; }
  1098. IOperandTerm start = terms[1];
  1099. IOperandTerm end = terms[2];
  1100. IOperandTerm step = null;
  1101. if (start == null)
  1102. start = new SingleTerm(0);
  1103. if ((terms.Length > 3) && (terms[3] != null))
  1104. step = terms[3];
  1105. else
  1106. step = new SingleTerm(1);
  1107. if (!start.IsInteger)
  1108. { warn("The type of the second argument is different", line, 2, false); return null; }
  1109. return new SpForNextArgment(varTerm, start, end, step);
  1110. }
  1111. }
  1112. private sealed class SP_POWER_ArgumentBuilder : ArgumentBuilder
  1113. {
  1114. public SP_POWER_ArgumentBuilder()
  1115. {
  1116. argumentTypeArray = new[] { typeof(Int64), typeof(Int64), typeof(Int64) };
  1117. //minArg = 2;
  1118. }
  1119. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1120. {
  1121. IOperandTerm[] terms = popTerms(line);
  1122. if (!checkArgumentType(line, exm, terms))
  1123. return null;
  1124. VariableTerm varTerm = getChangeableVariable(terms, 1, line);
  1125. if (varTerm == null)
  1126. return null;
  1127. return new SpPowerArgument(varTerm, terms[1], terms[2]);
  1128. }
  1129. }
  1130. private sealed class SP_SWAPVAR_ArgumentBuilder : ArgumentBuilder
  1131. {
  1132. public SP_SWAPVAR_ArgumentBuilder()
  1133. {
  1134. argumentTypeArray = new[] { typeof(void), typeof(void) };
  1135. //minArg = 2;
  1136. }
  1137. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1138. {
  1139. IOperandTerm[] terms = popTerms(line);
  1140. if (!checkArgumentType(line, exm, terms))
  1141. return null;
  1142. VariableTerm x = getChangeableVariable(terms, 1, line);
  1143. if (x == null)
  1144. return null;
  1145. VariableTerm y = getChangeableVariable(terms, 2, line);
  1146. if (y == null)
  1147. return null;
  1148. if (x.GetOperandType() != y.GetOperandType())
  1149. {
  1150. warn("Argument type is different", line, 2, false);
  1151. return null;
  1152. }
  1153. return new SpSwapVarArgument(x, y);
  1154. }
  1155. }
  1156. private sealed class VAR_INT_ArgumentBuilder : ArgumentBuilder
  1157. {
  1158. public VAR_INT_ArgumentBuilder()
  1159. {
  1160. argumentTypeArray = new[] { typeof(Int64) };
  1161. minArg = 0;
  1162. }
  1163. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1164. {
  1165. IOperandTerm[] terms = popTerms(line);
  1166. if (terms.Length == 0)
  1167. return new PrintDataArgument(null);
  1168. if (!checkArgumentType(line, exm, terms))
  1169. return null;
  1170. VariableTerm varTerm = getChangeableVariable(terms, 1, line);
  1171. if (varTerm == null)
  1172. return null;
  1173. return new PrintDataArgument(varTerm);
  1174. }
  1175. }
  1176. private sealed class VAR_STR_ArgumentBuilder : ArgumentBuilder
  1177. {
  1178. public VAR_STR_ArgumentBuilder()
  1179. {
  1180. argumentTypeArray = new[] { typeof(string) };
  1181. minArg = 0;
  1182. }
  1183. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1184. {
  1185. IOperandTerm[] terms = popTerms(line);
  1186. if (terms.Length == 0)
  1187. {
  1188. VariableToken varToken = GlobalStatic.VariableData.GetSystemVariableToken("RESULTS");
  1189. VariableTerm varTerm = new VariableTerm(varToken, new IOperandTerm[] { new SingleTerm(0) });
  1190. return new StrDataArgument(varTerm);
  1191. }
  1192. if (!checkArgumentType(line, exm, terms))
  1193. return null;
  1194. VariableTerm x = getChangeableVariable(terms, 1, line);
  1195. if (x == null)
  1196. return null;
  1197. return new StrDataArgument(x);
  1198. }
  1199. }
  1200. private sealed class BIT_ARG_ArgumentBuilder : ArgumentBuilder
  1201. {
  1202. public BIT_ARG_ArgumentBuilder()
  1203. {
  1204. argumentTypeArray = new[] { typeof(Int64), typeof(Int64) };
  1205. minArg = 2;
  1206. argAny = true;
  1207. }
  1208. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1209. {
  1210. IOperandTerm[] terms = popTerms(line);
  1211. if (!checkArgumentType(line, exm, terms))
  1212. return null;
  1213. VariableTerm varTerm = getChangeableVariable(terms, 1, line);
  1214. if (varTerm == null)
  1215. return null;
  1216. List<IOperandTerm> termList = new List<IOperandTerm>();
  1217. termList.AddRange(terms);
  1218. //最初の項はいらない
  1219. termList.RemoveAt(0);
  1220. BitArgument ret = new BitArgument(varTerm, termList.ToArray());
  1221. for (int i = 0; i < termList.Count; i++)
  1222. {
  1223. if (termList[i] is SingleTerm)
  1224. {
  1225. Int64 bit = ((SingleTerm)termList[i]).Int;
  1226. if ((bit < 0) || (bit > 63))
  1227. {
  1228. warn("Argument number " + Strings.StrConv((i + 2).ToString(), VbStrConv.Wide, Config.Config.Language) + " argument (" + bit + ") is outside the range (0 to 63)", line, 2, false);
  1229. return null;
  1230. }
  1231. }
  1232. }
  1233. return ret;
  1234. }
  1235. }
  1236. private sealed class SP_VAR_SET_ArgumentBuilder : ArgumentBuilder
  1237. {
  1238. public SP_VAR_SET_ArgumentBuilder()
  1239. {
  1240. argumentTypeArray = new[] { typeof(void), typeof(void), typeof(Int64), typeof(Int64) };
  1241. minArg = 1;
  1242. }
  1243. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1244. {
  1245. IOperandTerm[] terms = popTerms(line);
  1246. if (!checkArgumentType(line, exm, terms))
  1247. return null;
  1248. VariableTerm varTerm = getChangeableVariable(terms, 1, line);
  1249. if (varTerm == null)
  1250. return null;
  1251. if (varTerm.Identifier.IsConst)
  1252. {
  1253. warn("A variable that cannot change its value " + varTerm.Identifier.Name + " has a specified value", line, 2, false);
  1254. return null;
  1255. }
  1256. IOperandTerm term, term3 = null, term4 = null;
  1257. if (terms.Length > 1)
  1258. term = terms[1];
  1259. else
  1260. {
  1261. if (varTerm.IsString)
  1262. term = new SingleTerm("");
  1263. else
  1264. term = new SingleTerm(0);
  1265. }
  1266. if (varTerm is VariableNoArgTerm)
  1267. {
  1268. if (terms.Length > 2)
  1269. {
  1270. warn("対象となる変数" + varTerm.Identifier.Name + "の要素を省略する場合には第3引数以降を設定できません", line, 2, false);
  1271. return null;
  1272. }
  1273. return new SpVarSetArgument(new FixedVariableTerm(varTerm.Identifier), term, null, null);
  1274. }
  1275. if (terms.Length > 2)
  1276. term3 = terms[2];
  1277. if (terms.Length > 3)
  1278. term4 = terms[3];
  1279. if (terms.Length >= 3 && !varTerm.Identifier.IsArray1D)
  1280. warn("第3引数以降は1次元配列以外では無視されます", line, 1, false);
  1281. if (term.GetOperandType() != varTerm.GetOperandType())
  1282. {
  1283. warn("2つの引数の型が一致していません", line, 2, false);
  1284. return null;
  1285. }
  1286. return new SpVarSetArgument(varTerm, term, term3, term4);
  1287. }
  1288. }
  1289. private sealed class SP_CVAR_SET_ArgumentBuilder : ArgumentBuilder
  1290. {
  1291. public SP_CVAR_SET_ArgumentBuilder()
  1292. {
  1293. argumentTypeArray = new[] { typeof(void), typeof(void), typeof(void), typeof(Int64), typeof(Int64) };
  1294. minArg = 1;
  1295. }
  1296. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1297. {
  1298. IOperandTerm[] terms = popTerms(line);
  1299. if (!checkArgumentType(line, exm, terms))
  1300. return null;
  1301. VariableTerm varTerm = getChangeableVariable(terms, 1, line);
  1302. if (varTerm == null)
  1303. return null;
  1304. if (!varTerm.Identifier.IsCharacterData)
  1305. { warn("第1引数にキャラクタ変数以外の変数を指定することはできません", line, 2, false); return null; }
  1306. //1803beta004 暫定CDFLAGを弾く
  1307. if (varTerm.Identifier.IsArray2D)
  1308. { warn("第1引数に二次元配列の変数を指定することはできません", line, 2, false); return null; }
  1309. IOperandTerm index, term, term4 = null, term5 = null;
  1310. if (terms.Length > 1)
  1311. index = terms[1];
  1312. else
  1313. index = new SingleTerm(0);
  1314. if (terms.Length > 2)
  1315. term = terms[2];
  1316. else
  1317. {
  1318. if (varTerm.IsString)
  1319. term = new SingleTerm("");
  1320. else
  1321. term = new SingleTerm(0);
  1322. }
  1323. if (terms.Length > 3)
  1324. term4 = terms[3];
  1325. if (terms.Length > 4)
  1326. term5 = terms[4];
  1327. if (index is SingleTerm && index.GetOperandType() == typeof(string) && varTerm.Identifier.IsArray1D)
  1328. {
  1329. if (!GlobalStatic.ConstantData.isDefined(varTerm.Identifier.Code, ((SingleTerm)index).Str))
  1330. { warn("文字列" + index.GetStrValue(null) + "は変数" + varTerm.Identifier.Name + "の要素ではありません", line, 2, false); return null; }
  1331. }
  1332. if (terms.Length > 3 && !varTerm.Identifier.IsArray1D)
  1333. warn("The fourth and subsequent arguments are ignored except for one-dimensional arrays", line, 1, false);
  1334. if (term.GetOperandType() != varTerm.GetOperandType())
  1335. {
  1336. warn("The types of the two arguments do not match", line, 2, false);
  1337. return null;
  1338. }
  1339. return new SpCVarSetArgument(varTerm, index, term, term4, term5);
  1340. }
  1341. }
  1342. private sealed class SP_BUTTON_ArgumentBuilder : ArgumentBuilder
  1343. {
  1344. public SP_BUTTON_ArgumentBuilder()
  1345. {
  1346. argumentTypeArray = new[] { typeof(string), typeof(void) };
  1347. }
  1348. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1349. {
  1350. IOperandTerm[] terms = popTerms(line);
  1351. if (!checkArgumentType(line, exm, terms))
  1352. return null;
  1353. return new SpButtonArgument(terms[0], terms[1]);
  1354. }
  1355. }
  1356. private sealed class SP_COLOR_ArgumentBuilder : ArgumentBuilder
  1357. {
  1358. public SP_COLOR_ArgumentBuilder()
  1359. {
  1360. argumentTypeArray = new[] { typeof(Int64), typeof(Int64), typeof(Int64) };
  1361. minArg = 1;
  1362. }
  1363. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1364. {
  1365. IOperandTerm[] terms = popTerms(line);
  1366. if (!checkArgumentType(line, exm, terms))
  1367. return null;
  1368. if (terms.Length == 2)
  1369. { warn("The number of arguments of SETCOLOR is invalid (SETCOLOR takes only 1 or 3 arguments)", line, 2, false); return null; }
  1370. SpColorArgument arg = null;
  1371. if (terms.Length == 1)
  1372. {
  1373. arg = new SpColorArgument(terms[0]);
  1374. if (terms[0] is SingleTerm)
  1375. {
  1376. arg.ConstInt = terms[0].GetIntValue(exm);
  1377. arg.IsConst = true;
  1378. }
  1379. }
  1380. else
  1381. {
  1382. arg = new SpColorArgument(terms[0], terms[1], terms[2]);
  1383. if ((terms[0] is SingleTerm) && (terms[1] is SingleTerm) && (terms[2] is SingleTerm))
  1384. {
  1385. arg.ConstInt = (terms[0].GetIntValue(exm) << 16) + (terms[1].GetIntValue(exm) << 8) + (terms[2].GetIntValue(exm));
  1386. arg.IsConst = true;
  1387. }
  1388. }
  1389. return arg;
  1390. }
  1391. }
  1392. private sealed class SP_SPLIT_ArgumentBuilder : ArgumentBuilder
  1393. {
  1394. public SP_SPLIT_ArgumentBuilder()
  1395. {
  1396. argumentTypeArray = new[] { typeof(string), typeof(string), typeof(string), typeof(Int64) };
  1397. minArg = 3;
  1398. }
  1399. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1400. {
  1401. IOperandTerm[] terms = popTerms(line);
  1402. if (!checkArgumentType(line, exm, terms))
  1403. return null;
  1404. VariableTerm x = getChangeableVariable(terms, 3, line);
  1405. if (x == null)
  1406. return null;
  1407. if (!x.Identifier.IsArray1D && !x.Identifier.IsArray2D && !x.Identifier.IsArray3D)
  1408. { warn("The third argument must be an array variable", line, 2, false); return null; }
  1409. VariableTerm term = (terms.Length >= 4) ? getChangeableVariable(terms, 4, line) : new VariableTerm(GlobalStatic.VariableData.GetSystemVariableToken("RESULT"), new IOperandTerm[]{new SingleTerm(0)});
  1410. return new SpSplitArgument(terms[0], terms[1], x.Identifier, term);
  1411. }
  1412. }
  1413. private sealed class SP_HTMLSPLIT_ArgumentBuilder : ArgumentBuilder
  1414. {
  1415. public SP_HTMLSPLIT_ArgumentBuilder()
  1416. {
  1417. argumentTypeArray = new[] { typeof(string), typeof(string), typeof(Int64) };
  1418. minArg = 1;
  1419. }
  1420. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1421. {
  1422. IOperandTerm[] terms = popTerms(line);
  1423. if (!checkArgumentType(line, exm, terms))
  1424. return null;
  1425. VariableToken destVar = null;
  1426. VariableTerm destVarTerm = null;
  1427. VariableTerm term = null;
  1428. if (terms.Length >= 2)
  1429. destVarTerm = getChangeableVariable(terms, 2, line);
  1430. if (destVarTerm != null)
  1431. destVar = destVarTerm.Identifier;
  1432. else
  1433. destVar = GlobalStatic.VariableData.GetSystemVariableToken("RESULTS");
  1434. if (!destVar.IsArray1D || destVar.IsCharacterData)
  1435. { warn("第2引数は非キャラ型の1次元配列変数でなければなりません", line, 2, false); return null; }
  1436. if (terms.Length >= 3)
  1437. term = getChangeableVariable(terms, 3, line);
  1438. if (term == null)
  1439. {
  1440. VariableToken varToken = GlobalStatic.VariableData.GetSystemVariableToken("RESULT");
  1441. term = new VariableTerm(varToken, new IOperandTerm[] { new SingleTerm(0) });
  1442. }
  1443. return new SpHtmlSplitArgument(terms[0], destVar, term);
  1444. }
  1445. }
  1446. private sealed class SP_GETINT_ArgumentBuilder : ArgumentBuilder
  1447. {
  1448. public SP_GETINT_ArgumentBuilder()
  1449. {
  1450. argumentTypeArray = new[] { typeof(Int64) };
  1451. minArg = 0;
  1452. }
  1453. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1454. {
  1455. IOperandTerm[] terms = popTerms(line);
  1456. if (terms.Length == 0)
  1457. {
  1458. VariableToken varToken = GlobalStatic.VariableData.GetSystemVariableToken("RESULT");
  1459. return new SpGetIntArgument(new VariableTerm(varToken, new IOperandTerm[]{new SingleTerm(0)}));
  1460. }
  1461. if (!checkArgumentType(line, exm, terms))
  1462. return null;
  1463. VariableTerm x = getChangeableVariable(terms, 1, line);
  1464. if (x == null)
  1465. return null;
  1466. return new SpGetIntArgument(x);
  1467. }
  1468. }
  1469. private sealed class SP_CONTROL_ARRAY_ArgumentBuilder : ArgumentBuilder
  1470. {
  1471. public SP_CONTROL_ARRAY_ArgumentBuilder()
  1472. {
  1473. argumentTypeArray = new[] { typeof(void), typeof(Int64), typeof(Int64) };
  1474. }
  1475. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1476. {
  1477. IOperandTerm[] terms = popTerms(line);
  1478. if (!checkArgumentType(line, exm, terms))
  1479. return null;
  1480. VariableTerm x = getChangeableVariable(terms, 1, line);
  1481. if (x == null)
  1482. return null;
  1483. return new SpArrayControlArgument(x, terms[1], terms[2]);
  1484. }
  1485. }
  1486. private sealed class SP_SHIFT_ARRAY_ArgumentBuilder : ArgumentBuilder
  1487. {
  1488. public SP_SHIFT_ARRAY_ArgumentBuilder()
  1489. {
  1490. argumentTypeArray = new[] { typeof(void), typeof(Int64), typeof(void), typeof(Int64), typeof(Int64) };
  1491. minArg = 3;
  1492. }
  1493. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1494. {
  1495. IOperandTerm[] terms = popTerms(line);
  1496. if (!checkArgumentType(line, exm, terms))
  1497. return null;
  1498. VariableTerm x = getChangeableVariable(terms, 1, line);
  1499. if (x == null)
  1500. return null;
  1501. if (!x.Identifier.IsArray1D)
  1502. { warn("第1引数に1次元配列もしくは配列型キャラクタ変数以外を指定することはできません", line, 2, false); return null; }
  1503. if (line.FunctionCode == FunctionCode.ARRAYSHIFT)
  1504. {
  1505. if (terms[0].GetOperandType() != terms[2].GetOperandType())
  1506. { warn("First and third argument types are different", line, 2, false); return null; }
  1507. }
  1508. IOperandTerm term4 = terms.Length >= 4 ? terms[3] : new SingleTerm(0);
  1509. IOperandTerm term5 = terms.Length >= 5 ? terms[4] : null;
  1510. return new SpArrayShiftArgument(x, terms[1], terms[2], term4, term5);
  1511. }
  1512. }
  1513. private sealed class SP_SAVEVAR_ArgumentBuilder : ArgumentBuilder
  1514. {
  1515. public SP_SAVEVAR_ArgumentBuilder()
  1516. {
  1517. argumentTypeArray = new[] { typeof(string), typeof(string), typeof(void)};
  1518. argAny = true;
  1519. minArg = 3;
  1520. }
  1521. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1522. {
  1523. IOperandTerm[] terms = popTerms(line);
  1524. if (!checkArgumentType(line, exm, terms))
  1525. return null;
  1526. List<VariableToken> varTokens = new List<VariableToken>();
  1527. for (int i = 2; i < terms.Length; i++)
  1528. {
  1529. if (terms[i] == null)
  1530. { warn("第" + (i + 1) + "引数を省略できません", line, 2, false); return null; }
  1531. VariableTerm vTerm = getChangeableVariable(terms, i + 1, line);
  1532. if (vTerm == null)
  1533. return null;
  1534. VariableToken vToken = vTerm.Identifier;
  1535. if (vToken.IsCharacterData)
  1536. { warn("キャラクタ変数"+ vToken.Name+"はセーブできません(キャラクタ変数のSAVEにはSAVECHARAを使用します)", line, 2, false); return null; }
  1537. if (vToken.IsPrivate)
  1538. { warn("プライベート変数" + vToken.Name + "はセーブできません", line, 2, false); return null; }
  1539. if (vToken.IsLocal)
  1540. { warn("ローカル変数" + vToken.Name + "はセーブできません", line, 2, false); return null; }
  1541. if (vToken.IsConst)
  1542. { warn("値を変更できない変数はセーブできません", line, 2, false); return null; }
  1543. if (vToken.IsCalc)
  1544. { warn("疑似変数はセーブできません", line, 2, false); return null; }
  1545. if (vToken.IsReference)
  1546. { warn("参照型変数はセーブできません", line, 2, false); return null; }
  1547. varTokens.Add(vToken);
  1548. }
  1549. for (int i = 0; i < varTokens.Count; i++)
  1550. {
  1551. for (int j = i + 1; j < varTokens.Count; j++)
  1552. if (varTokens[i] == varTokens[j])
  1553. {
  1554. warn("変数" + varTokens[i].Name + "を二度以上保存しようとしています", line, 1, false);
  1555. return null;
  1556. }
  1557. }
  1558. VariableToken[] arg3 = new VariableToken[varTokens.Count];
  1559. varTokens.CopyTo(arg3);
  1560. return new SpSaveVarArgument(terms[0], terms[1], arg3);
  1561. }
  1562. }
  1563. private sealed class SP_SAVECHARA_ArgumentBuilder : ArgumentBuilder
  1564. {
  1565. public SP_SAVECHARA_ArgumentBuilder()
  1566. {
  1567. argumentTypeArray = new[] { typeof(string), typeof(string), typeof(Int64) };
  1568. minArg = 3;
  1569. argAny = true;
  1570. }
  1571. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1572. {
  1573. IOperandTerm[] terms = popTerms(line);
  1574. if (!checkArgumentType(line, exm, terms))
  1575. return null;
  1576. List<IOperandTerm> termList = new List<IOperandTerm>();
  1577. termList.AddRange(terms);
  1578. ExpressionArrayArgument ret = new ExpressionArrayArgument(termList);
  1579. for (int i = 2; i < termList.Count; i++)
  1580. {
  1581. if (!(termList[i] is SingleTerm))
  1582. continue;
  1583. Int64 iValue = termList[i].GetIntValue(null);
  1584. if (iValue < 0)
  1585. { warn("Character registration number must be a positive value", line, 2, false); return null; }
  1586. if (iValue > Int32.MaxValue)
  1587. { warn("Character registration number exceeds the upper limit of the 32 bit signed integer", line, 2, false); return null; }
  1588. for (int j = i + 1; j < termList.Count; j++)
  1589. {
  1590. if (!(termList[j] is SingleTerm))
  1591. continue;
  1592. if (iValue == termList[j].GetIntValue(null))
  1593. {
  1594. warn("Character registration number " + iValue + " is being saved more than once", line, 1, false);
  1595. return null;
  1596. }
  1597. }
  1598. }
  1599. return ret;
  1600. }
  1601. }
  1602. private sealed class SP_REF_ArgumentBuilder : ArgumentBuilder
  1603. {
  1604. public SP_REF_ArgumentBuilder(bool byname)
  1605. {
  1606. argumentTypeArray = new[] { typeof(void), typeof(void) };
  1607. minArg = 2;
  1608. this.byname = byname;
  1609. }
  1610. bool byname;
  1611. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1612. {
  1613. WordCollection wc = popWords(line);
  1614. IdentifierWord id = wc.Current as IdentifierWord;
  1615. wc.ShiftNext();
  1616. if (id == null || wc.Current.Type != ',')
  1617. { warn("The format is wrong", line, 2, false); return null; }
  1618. wc.ShiftNext();
  1619. IOperandTerm name = null;
  1620. IdentifierWord id2 = null;
  1621. string srcCode = null;
  1622. if (byname)
  1623. {
  1624. name = ExpressionParser.ReduceExpressionTerm(wc, TermEndWith.EoL);
  1625. if (name == null || name.IsInteger || !wc.EOL)
  1626. { warn("The format is wrong", line, 2, false); return null; }
  1627. name = name.Restructure(exm);
  1628. if (name is SingleTerm)
  1629. srcCode = name.GetStrValue(exm);
  1630. }
  1631. else
  1632. {
  1633. id2 = wc.Current as IdentifierWord;
  1634. wc.ShiftNext();
  1635. if (id2 == null || !wc.EOL)
  1636. { warn("The format is wrong", line, 2, false); return null; }
  1637. srcCode = id2.Code;
  1638. }
  1639. UserDefinedRefMethod refm = GlobalStatic.IdentifierDictionary.GetRefMethod(id.Code);
  1640. ReferenceToken refVar = null;
  1641. if (refm == null)
  1642. {
  1643. VariableToken token = GlobalStatic.IdentifierDictionary.GetVariableToken(id.Code, null, true);
  1644. if (token == null || !token.IsReference)
  1645. { warn("The first argument must be a function reference or a reference type variable", line, 2, false); return null; }
  1646. refVar = (ReferenceToken)token;
  1647. }
  1648. if (refm != null)
  1649. {
  1650. if (srcCode == null)
  1651. return new RefArgument(refm, name);
  1652. UserDefinedRefMethod srcRef = GlobalStatic.IdentifierDictionary.GetRefMethod(srcCode);
  1653. if (srcRef != null)
  1654. {
  1655. return new RefArgument(refm, srcRef);
  1656. }
  1657. FunctionLabelLine label = GlobalStatic.LabelDictionary.GetNonEventLabel(srcCode);
  1658. if (label == null)
  1659. { warn("Function " + srcCode + " is missing", line, 2, false); return null; }
  1660. if (!label.IsMethod)
  1661. { warn("Cannot refer to functions without #FUNCTION(S) attribute" + srcCode, line, 2, false); return null; }
  1662. CalledFunction called = CalledFunction.CreateCalledFunctionMethod(label, label.LabelName);
  1663. return new RefArgument(refm, called);
  1664. }
  1665. if (srcCode == null)
  1666. return new RefArgument(refVar, name);
  1667. VariableToken srcVar = GlobalStatic.IdentifierDictionary.GetVariableToken(srcCode, null, true);
  1668. if (srcVar == null)
  1669. { warn("Variable " + srcCode + " is missing", line, 2, false); return null; }
  1670. return new RefArgument(refVar, srcVar);
  1671. }
  1672. }
  1673. private sealed class SP_INPUT_ArgumentBuilder : ArgumentBuilder
  1674. {
  1675. public SP_INPUT_ArgumentBuilder()
  1676. {
  1677. argumentTypeArray = new[] { typeof(Int64) };
  1678. //if (nullable)妥協
  1679. minArg = 0;
  1680. }
  1681. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1682. {
  1683. IOperandTerm[] terms = popTerms(line);
  1684. if (!checkArgumentType(line, exm, terms))
  1685. return null;
  1686. IOperandTerm term = null;
  1687. ExpressionArgument ret;
  1688. if (terms.Length == 0)
  1689. {
  1690. ret = new ExpressionArgument(term);
  1691. return ret;
  1692. }
  1693. term = terms[0];
  1694. ret = new ExpressionArgument(term);
  1695. if (term is SingleTerm)
  1696. {
  1697. Int64 i = term.GetIntValue(null);
  1698. if (line.FunctionCode == FunctionCode.ONEINPUT)
  1699. {
  1700. if (i < 0)
  1701. {
  1702. warn("ONEINPUTの引数にONEINPUTが受け取れない負の数数が指定されています(引数を無効とします)", line, 1, false);
  1703. ret = new ExpressionArgument(null);
  1704. return ret;
  1705. }
  1706. if (i > 9)
  1707. {
  1708. warn("ONEINPUTの引数にONEINPUTが受け取れない2桁以上の数数が指定されています(最初の桁を引数と見なします)", line, 1, false);
  1709. i = Int64.Parse(i.ToString().Remove(1));
  1710. }
  1711. }
  1712. ret.ConstInt = i;
  1713. ret.IsConst = true;
  1714. }
  1715. return ret;
  1716. }
  1717. }
  1718. private sealed class SP_COPY_ARRAY_Arguments : ArgumentBuilder
  1719. {
  1720. public SP_COPY_ARRAY_Arguments()
  1721. {
  1722. argumentTypeArray = new[] { typeof(string), typeof(string) };
  1723. minArg = 2;
  1724. }
  1725. public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
  1726. {
  1727. IOperandTerm[] terms = popTerms(line);
  1728. if (!checkArgumentType(line, exm, terms))
  1729. return null;
  1730. VariableToken[] vars = new VariableToken[2] { null, null };
  1731. if (terms[0] is SingleTerm)
  1732. {
  1733. if ((vars[0] = GlobalStatic.IdentifierDictionary.GetVariableToken(((SingleTerm)terms[0]).Str, null, true)) == null)
  1734. {
  1735. warn("ARRAYCOPY命令の第1引数\"" + ((SingleTerm)terms[0]).Str + "\"は変数名として存在しません", line, 2, false);
  1736. return null;
  1737. }
  1738. if (!vars[0].IsArray1D && !vars[0].IsArray2D && !vars[0].IsArray3D)
  1739. {
  1740. warn("ARRAYCOPY命令の第1引数\"" + ((SingleTerm)terms[0]).Str + "\"は配列変数ではありません", line, 2, false);
  1741. return null;
  1742. }
  1743. if (vars[0].IsCharacterData)
  1744. {
  1745. warn("ARRAYCOPY命令の第1引数\"" + ((SingleTerm)terms[0]).Str + "\"はキャラクタ変数です(対応していません)", line, 2, false);
  1746. return null;
  1747. }
  1748. }
  1749. if (terms[1] is SingleTerm)
  1750. {
  1751. if ((vars[1] = GlobalStatic.IdentifierDictionary.GetVariableToken(((SingleTerm)terms[1]).Str, null, true)) == null)
  1752. {
  1753. warn("ARRAYCOPY命令の第2引数\"" + ((SingleTerm)terms[1]).Str + "\"は変数名として存在しません", line, 2, false);
  1754. return null;
  1755. }
  1756. if (!vars[1].IsArray1D && !vars[1].IsArray2D && !vars[1].IsArray3D)
  1757. {
  1758. warn("ARRAYCOPY命令の第2引数\"" + ((SingleTerm)terms[1]).Str + "\"は配列変数ではありません", line, 2, false);
  1759. }
  1760. if (vars[1].IsCharacterData)
  1761. {
  1762. warn("ARRAYCOPY命令の第2引数\"" + ((SingleTerm)terms[1]).Str + "\"はキャラクタ変数です(対応していません)", line, 2, false);
  1763. return null;
  1764. }
  1765. if (vars[1].IsConst)
  1766. {
  1767. warn("ARRAYCOPY命令の第2引数\"" + ((SingleTerm)terms[1]).Str + "\"は値を変更できない変数です", line, 2, false);
  1768. return null;
  1769. }
  1770. }
  1771. if ((vars[0] != null) && (vars[1] != null))
  1772. {
  1773. if ((vars[0].IsArray1D && !vars[1].IsArray1D) || (vars[0].IsArray2D && !vars[1].IsArray2D) || (vars[0].IsArray3D && !vars[1].IsArray3D))
  1774. {
  1775. warn("ARRAYCOPY命令の2つの引数の次元が異なります", line, 2, false);
  1776. return null;
  1777. }
  1778. if ((vars[0].IsInteger && vars[1].IsString) || (vars[0].IsString && vars[1].IsInteger))
  1779. {
  1780. warn("ARRAYCOPY命令の2つの配列変数の型が一致していません", line, 2, false);
  1781. return null;
  1782. }
  1783. }
  1784. return new SpCopyArrayArgument(terms[0], terms[1]);
  1785. }
  1786. }
  1787. #endregion
  1788. }
  1789. }