IdentifierDictionary.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. using System.Collections.Generic;
  2. using System.Text.RegularExpressions;
  3. using NTERA.EmuEra.Game.EraEmu.GameData.Expression;
  4. using NTERA.EmuEra.Game.EraEmu.GameData.Function;
  5. using NTERA.EmuEra.Game.EraEmu.GameData.Variable;
  6. using NTERA.EmuEra.Game.EraEmu.GameProc;
  7. using NTERA.EmuEra.Game.EraEmu.GameProc.Function;
  8. using NTERA.EmuEra.Game.EraEmu.Sub;
  9. using NTERA.EmuEra.Game.EraEmu._Library;
  10. namespace NTERA.EmuEra.Game.EraEmu.GameData
  11. {
  12. //1756 新設。
  13. //また、使用されている名前を記憶し衝突を検出する。
  14. internal sealed class IdentifierDictionary
  15. {
  16. private enum DefinedNameType
  17. {
  18. None = 0,
  19. Reserved,
  20. SystemVariable,
  21. SystemMethod,
  22. SystemInstrument,
  23. //UserIdentifier,
  24. UserGlobalVariable,
  25. UserMacro,
  26. UserRefMethod,
  27. NameSpace
  28. }
  29. static readonly char[] badSymbolAsIdentifier = {
  30. '+', '-', '*', '/', '%', '=', '!', '<', '>', '|', '&', '^', '~',
  31. ' ', ' ', '\t' ,
  32. '\"','(', ')', '{', '}', '[', ']', ',', '.', ':',
  33. '\\', '@', '$', '#', '?', ';', '\''
  34. //'_'はOK
  35. };
  36. static readonly Regex regexCom = new Regex("^COM[0-9]+$");
  37. static readonly Regex regexComAble = new Regex("^COM_ABLE[0-9]+$");
  38. static readonly Regex regexAblup = new Regex("^ABLUP[0-9]+$");
  39. #region static
  40. public static bool IsEventLabelName(string labelName)
  41. {
  42. switch (labelName)
  43. {
  44. case "EVENTFIRST":
  45. case "EVENTTRAIN":
  46. case "EVENTSHOP":
  47. case "EVENTBUY":
  48. case "EVENTCOM":
  49. case "EVENTTURNEND":
  50. case "EVENTCOMEND":
  51. case "EVENTEND":
  52. case "EVENTLOAD":
  53. return true;
  54. }
  55. return false;
  56. }
  57. public static bool IsSystemLabelName(string labelName)
  58. {
  59. switch (labelName)
  60. {
  61. case "EVENTFIRST":
  62. case "EVENTTRAIN":
  63. case "EVENTSHOP":
  64. case "EVENTBUY":
  65. case "EVENTCOM":
  66. case "EVENTTURNEND":
  67. case "EVENTCOMEND":
  68. case "EVENTEND":
  69. case "SHOW_STATUS":
  70. case "SHOW_USERCOM":
  71. case "USERCOM":
  72. case "SOURCE_CHECK":
  73. case "CALLTRAINEND":
  74. case "SHOW_JUEL":
  75. case "SHOW_ABLUP_SELECT":
  76. case "USERABLUP":
  77. case "SHOW_SHOP":
  78. case "SAVEINFO":
  79. case "USERSHOP":
  80. case "EVENTLOAD":
  81. case "TITLE_LOADGAME":
  82. case "SYSTEM_AUTOSAVE":
  83. case "SYSTEM_TITLE":
  84. case "SYSTEM_LOADEND":
  85. return true;
  86. }
  87. if (labelName.StartsWith("COM"))
  88. {
  89. if (regexCom.IsMatch(labelName))
  90. return true;
  91. if (regexComAble.IsMatch(labelName))
  92. return true;
  93. }
  94. if (labelName.StartsWith("ABLUP"))
  95. if (regexAblup.IsMatch(labelName))
  96. return true;
  97. return false;
  98. }
  99. #endregion
  100. Dictionary<string, DefinedNameType> nameDic = new Dictionary<string, DefinedNameType>();
  101. List<string> privateDimList = new List<string>();
  102. List<string> disableList = new List<string>();
  103. //Dictionary<string, VariableToken> userDefinedVarDic = new Dictionary<string, VariableToken>();
  104. VariableData varData;
  105. Dictionary<string, VariableToken> varTokenDic;
  106. Dictionary<string, VariableLocal> localvarTokenDic;
  107. Dictionary<string, FunctionIdentifier> instructionDic;
  108. Dictionary<string, FunctionMethod> methodDic;
  109. Dictionary<string, UserDefinedRefMethod> refmethodDic;
  110. public List<UserDefinedCharaVariableToken> CharaDimList = new List<UserDefinedCharaVariableToken>();
  111. #region initialize
  112. public IdentifierDictionary(VariableData varData)
  113. {
  114. this.varData = varData;
  115. nameDic.Clear();
  116. //予約語を登録。式中に登場すると構文解析が崩壊する名前群。
  117. //ただしeramaker用スクリプトなら特に気にすることはない。式中に出てこない単語も同様。
  118. nameDic.Add("IS", DefinedNameType.Reserved);
  119. nameDic.Add("TO", DefinedNameType.Reserved);
  120. nameDic.Add("INT", DefinedNameType.Reserved);
  121. nameDic.Add("STR", DefinedNameType.Reserved);
  122. nameDic.Add("REFFUNC", DefinedNameType.Reserved);
  123. nameDic.Add("STATIC", DefinedNameType.Reserved);
  124. nameDic.Add("DYNAMIC", DefinedNameType.Reserved);
  125. nameDic.Add("GLOBAL", DefinedNameType.Reserved);
  126. nameDic.Add("PRIVATE", DefinedNameType.Reserved);
  127. nameDic.Add("SAVEDATA", DefinedNameType.Reserved);
  128. nameDic.Add("CHARADATA", DefinedNameType.Reserved);//CHARDATAから変更
  129. nameDic.Add("REF", DefinedNameType.Reserved);
  130. nameDic.Add("__DEBUG__", DefinedNameType.Reserved);
  131. nameDic.Add("__SKIP__", DefinedNameType.Reserved);
  132. nameDic.Add("_", DefinedNameType.Reserved);
  133. instructionDic = FunctionIdentifier.GetInstructionNameDic();
  134. varTokenDic = varData.GetVarTokenDicClone();
  135. localvarTokenDic = varData.GetLocalvarTokenDic();
  136. methodDic = FunctionMethodCreator.GetMethodList();
  137. refmethodDic = new Dictionary<string, UserDefinedRefMethod>();
  138. foreach(KeyValuePair<string, FunctionMethod> pair in methodDic)
  139. {
  140. nameDic.Add(pair.Key, DefinedNameType.SystemMethod);
  141. }
  142. foreach (KeyValuePair<string, VariableToken> pair in varTokenDic)
  143. {
  144. //RANDが衝突している
  145. //1808a3 GLOBAL、PRIVATEも
  146. //1808beta009 REFも
  147. if (!nameDic.ContainsKey(pair.Key))
  148. nameDic.Add(pair.Key, DefinedNameType.SystemVariable);
  149. }
  150. foreach (KeyValuePair<string, VariableLocal> pair in localvarTokenDic)
  151. {
  152. nameDic.Add(pair.Key, DefinedNameType.SystemVariable);
  153. }
  154. foreach (KeyValuePair<string, FunctionIdentifier> pair in instructionDic)
  155. {
  156. //Methodと被る
  157. //1808a3 SAVEDATAも
  158. if (!nameDic.ContainsKey(pair.Key))
  159. nameDic.Add(pair.Key, DefinedNameType.SystemInstrument);
  160. }
  161. }
  162. //public void SetSystemInstrumentName(List<string> names)
  163. //{
  164. //}
  165. public void CheckUserLabelName(ref string errMes, ref int warnLevel, bool isFunction, string labelName)
  166. {
  167. if (labelName.Length == 0)
  168. {
  169. errMes = "Label name is missing";
  170. warnLevel = 2;
  171. return;
  172. }
  173. //1.721 記号をサポートしない方向に変更
  174. if (labelName.IndexOfAny(badSymbolAsIdentifier) >= 0)
  175. {
  176. errMes = "Label name " + labelName + " has symbols other than \"_\" included";
  177. warnLevel = 1;
  178. return;
  179. }
  180. if (char.IsDigit(labelName[0]) && (labelName[0].ToString()).Length == LangManager.GetStrlenLang(labelName[0].ToString()))
  181. {
  182. errMes = "Label name " + labelName + " begins with a half-width digit";
  183. warnLevel = 0;
  184. return;
  185. }
  186. if (!isFunction || !Config.Config.WarnFunctionOverloading)
  187. return;
  188. if (!nameDic.ContainsKey(labelName))
  189. return;
  190. if (nameDic.ContainsKey(labelName))
  191. {
  192. switch (nameDic[labelName])
  193. {
  194. case DefinedNameType.Reserved:
  195. if (Config.Config.AllowFunctionOverloading)
  196. {
  197. errMes = "Function name " + labelName + " conflicts with Emuera\'s reserved word.\n" + "There is a risk of interfering with Emuera exclusive syntax parsing";
  198. warnLevel = 1;
  199. }
  200. else
  201. {
  202. errMes = "Function name " + labelName + " is a reserved word for Emuera";
  203. warnLevel = 2;
  204. }
  205. break;
  206. case DefinedNameType.SystemMethod:
  207. if (Config.Config.AllowFunctionOverloading)
  208. {
  209. errMes = "関数名" + labelName + "はEmueraの式中関数を上書きします";
  210. warnLevel = 1;
  211. }
  212. else
  213. {
  214. errMes = "関数名" + labelName + "はEmueraの式中関数名として使われています";
  215. warnLevel = 2;
  216. }
  217. break;
  218. case DefinedNameType.SystemVariable:
  219. errMes = "関数名" + labelName + "はEmueraの変数で使われています";
  220. warnLevel = 1;
  221. break;
  222. case DefinedNameType.SystemInstrument:
  223. errMes = "関数名" + labelName + "はEmueraの変数もしくは命令で使われています";
  224. warnLevel = 1;
  225. break;
  226. case DefinedNameType.UserMacro:
  227. //字句解析がうまくいっていれば本来あり得ないはず
  228. errMes = "関数名" + labelName + "はマクロに使用されています";
  229. warnLevel = 2;
  230. break;
  231. case DefinedNameType.UserRefMethod:
  232. errMes = "関数名" + labelName + "は参照型関数の名称に使用されています";
  233. warnLevel = 2;
  234. break;
  235. }
  236. }
  237. }
  238. public void CheckUserVarName(ref string errMes, ref int warnLevel, string varName)
  239. {
  240. //if (varName.Length == 0)
  241. //{
  242. // errMes = "変数名がありません";
  243. // warnLevel = 2;
  244. // return;
  245. //}
  246. //1.721 記号をサポートしない方向に変更
  247. if (varName.IndexOfAny(badSymbolAsIdentifier) >= 0)
  248. {
  249. errMes = "変数名" + varName + "に\"_\"以外の記号が含まれています";
  250. warnLevel = 2;
  251. return;
  252. }
  253. //if (char.IsDigit(varName[0]))
  254. //{
  255. // errMes = "変数名" + varName + "が半角数字から始まっています";
  256. // warnLevel = 2;
  257. // return;
  258. //}
  259. if (nameDic.ContainsKey(varName))
  260. {
  261. switch (nameDic[varName])
  262. {
  263. case DefinedNameType.Reserved:
  264. errMes = "変数名" + varName + "はEmueraの予約語です";
  265. warnLevel = 2;
  266. break;
  267. case DefinedNameType.SystemInstrument:
  268. case DefinedNameType.SystemMethod:
  269. //代入文が使えなくなるために命令名との衝突は致命的。
  270. errMes = "変数名" + varName + "はEmueraの命令名として使われています";
  271. warnLevel = 2;
  272. break;
  273. case DefinedNameType.SystemVariable:
  274. errMes = "変数名" + varName + "はEmueraの変数名として使われています";
  275. warnLevel = 2;
  276. break;
  277. case DefinedNameType.UserMacro:
  278. errMes = "変数名" + varName + "は既にマクロ名に使用されています";
  279. warnLevel = 2;
  280. break;
  281. case DefinedNameType.UserGlobalVariable:
  282. errMes = "変数名" + varName + "はユーザー定義の広域変数名に使用されています";
  283. warnLevel = 2;
  284. break;
  285. case DefinedNameType.UserRefMethod:
  286. errMes = "変数名" + varName + "は参照型関数の名称に使用されています";
  287. warnLevel = 2;
  288. break;
  289. }
  290. }
  291. }
  292. public void CheckUserMacroName(ref string errMes, ref int warnLevel, string macroName)
  293. {
  294. if (macroName.IndexOfAny(badSymbolAsIdentifier) >= 0)
  295. {
  296. errMes = "マクロ名" + macroName + "に\"_\"以外の記号が含まれています";
  297. warnLevel = 2;
  298. return;
  299. }
  300. if (nameDic.ContainsKey(macroName))
  301. {
  302. switch (nameDic[macroName])
  303. {
  304. case DefinedNameType.Reserved:
  305. errMes = "マクロ名" + macroName + "はEmueraの予約語です";
  306. warnLevel = 2;
  307. break;
  308. case DefinedNameType.SystemInstrument:
  309. case DefinedNameType.SystemMethod:
  310. //命令名を上書きした時が面倒なのでとりあえず許可しない
  311. errMes = "マクロ名" + macroName + "はEmueraの命令名として使われています";
  312. warnLevel = 2;
  313. break;
  314. case DefinedNameType.SystemVariable:
  315. //別に上書きしてもいいがとりあえず許可しないでおく。いずれ解放するかもしれない
  316. errMes = "マクロ名" + macroName + "はEmueraの変数名として使われています";
  317. warnLevel = 2;
  318. break;
  319. case DefinedNameType.UserMacro:
  320. errMes = "マクロ名" + macroName + "は既にマクロ名に使用されています";
  321. warnLevel = 2;
  322. break;
  323. case DefinedNameType.UserGlobalVariable:
  324. errMes = "マクロ名" + macroName + "はユーザー定義の広域変数名に使用されています";
  325. warnLevel = 2;
  326. break;
  327. case DefinedNameType.UserRefMethod:
  328. errMes = "マクロ名" + macroName + "は参照型関数の名称に使用されています";
  329. warnLevel = 2;
  330. break;
  331. }
  332. }
  333. }
  334. public void CheckUserPrivateVarName(ref string errMes, ref int warnLevel, string varName)
  335. {
  336. if (varName.Length == 0)
  337. {
  338. errMes = "変数名がありません";
  339. warnLevel = 2;
  340. return;
  341. }
  342. //1.721 記号をサポートしない方向に変更
  343. if (varName.IndexOfAny(badSymbolAsIdentifier) >= 0)
  344. {
  345. errMes = "変数名" + varName + "に\"_\"以外の記号が含まれています";
  346. warnLevel = 2;
  347. return;
  348. }
  349. if (char.IsDigit(varName[0]))
  350. {
  351. errMes = "変数名" + varName + "が半角数字から始まっています";
  352. warnLevel = 2;
  353. return;
  354. }
  355. if(nameDic.ContainsKey(varName))
  356. {
  357. switch(nameDic[varName])
  358. {
  359. case DefinedNameType.Reserved:
  360. errMes = "変数名" + varName + "はEmueraの予約語です";
  361. warnLevel = 2;
  362. return;
  363. case DefinedNameType.SystemInstrument:
  364. case DefinedNameType.SystemMethod:
  365. //代入文が使えなくなるために命令名との衝突は致命的。
  366. errMes = "変数名" + varName + "はEmueraの命令名として使われています";
  367. warnLevel = 2;
  368. return;
  369. case DefinedNameType.SystemVariable:
  370. //システム変数の上書きは不可
  371. errMes = "変数名" + varName + "はEmueraの変数名として使われています";
  372. warnLevel = 2;
  373. break;
  374. case DefinedNameType.UserMacro:
  375. //字句解析がうまくいっていれば本来あり得ないはず
  376. errMes = "変数名" + varName + "はマクロに使用されています";
  377. warnLevel = 2;
  378. break;
  379. case DefinedNameType.UserGlobalVariable:
  380. //広域変数の上書きは禁止しておく
  381. errMes = "変数名" + varName + "はユーザー定義の広域変数名に使用されています";
  382. warnLevel = 2;
  383. break;
  384. case DefinedNameType.UserRefMethod:
  385. errMes = "変数名" + varName + "は参照型関数の名称に使用されています";
  386. warnLevel = 2;
  387. break;
  388. }
  389. }
  390. privateDimList.Add(varName);
  391. }
  392. #endregion
  393. #region header.erb
  394. //1807 ErbLoaderに移動
  395. Dictionary<string, DefineMacro> macroDic = new Dictionary<string, DefineMacro>();
  396. internal void AddUseDefinedVariable(VariableToken var)
  397. {
  398. varTokenDic.Add(var.Name, var);
  399. if (var.IsCharacterData)
  400. {
  401. }
  402. nameDic.Add(var.Name, DefinedNameType.UserGlobalVariable);
  403. }
  404. internal void AddMacro(DefineMacro mac)
  405. {
  406. nameDic.Add(mac.Keyword, DefinedNameType.UserMacro);
  407. macroDic.Add(mac.Keyword, mac);
  408. }
  409. internal void AddRefMethod(UserDefinedRefMethod refm)
  410. {
  411. refmethodDic.Add(refm.Name, refm);
  412. nameDic.Add(refm.Name, DefinedNameType.UserRefMethod);
  413. }
  414. #endregion
  415. #region get
  416. public bool UseMacro()
  417. {
  418. return macroDic.Count > 0;
  419. }
  420. public DefineMacro GetMacro(string key)
  421. {
  422. if (Config.Config.ICVariable)
  423. key = key.ToUpper();
  424. if (macroDic.ContainsKey(key))
  425. return macroDic[key];
  426. return null;
  427. }
  428. public VariableToken GetVariableToken(string key, string subKey, bool allowPrivate)
  429. {
  430. VariableToken ret = null;
  431. if (Config.Config.ICVariable)
  432. key = key.ToUpper();
  433. if (allowPrivate)
  434. {
  435. LogicalLine line = GlobalStatic.Process.GetScaningLine();
  436. if ((line != null) && (line.ParentLabelLine != null))
  437. {
  438. ret = line.ParentLabelLine.GetPrivateVariable(key);
  439. if(ret != null)
  440. {
  441. if (subKey != null)
  442. throw new CodeEE("プライベート変数" + key + "に対して@が使われました");
  443. return ret;
  444. }
  445. }
  446. }
  447. if (localvarTokenDic.ContainsKey(key))
  448. {
  449. if (localvarTokenDic[key].IsForbid)
  450. {
  451. throw new CodeEE("呼び出された変数\"" + key + "\"は設定により使用が禁止されています");
  452. }
  453. LogicalLine line = GlobalStatic.Process.GetScaningLine();
  454. if (string.IsNullOrEmpty(subKey))
  455. {
  456. //システムの入力待ち中にデバッグコマンドからLOCALを呼んだとき。
  457. if ((line == null) || (line.ParentLabelLine == null))
  458. throw new CodeEE("実行中の関数が存在しないため" + key + "を取得又は変更できませんでした");
  459. subKey = line.ParentLabelLine.LabelName;
  460. }
  461. else
  462. {
  463. ParserMediator.Warn("コード中でローカル変数を@付きで呼ぶことは推奨されません(代わりに*.ERHファイルの利用を検討してください)", line, 1, false, false);
  464. if (Config.Config.ICFunction)
  465. subKey = subKey.ToUpper();
  466. }
  467. LocalVariableToken retLocal = localvarTokenDic[key].GetExistLocalVariableToken(subKey);
  468. if (retLocal == null)
  469. retLocal = localvarTokenDic[key].GetNewLocalVariableToken(subKey, line.ParentLabelLine);
  470. return retLocal;
  471. }
  472. if (varTokenDic.TryGetValue(key, out ret))
  473. {
  474. //一文字変数の禁止オプションを考えた名残
  475. //if (Config.ForbidOneCodeVariable && ret.CanForbid)
  476. // throw new CodeEE("設定によりシステム一文字数値変数の使用が禁止されています(呼び出された変数:" + ret.Name +")");
  477. if (ret.IsForbid)
  478. {
  479. if(!ret.CanForbid)
  480. throw new ExeEE("CanForbidでない変数\"" + ret.Name +"\"にIsForbidがついている");
  481. throw new CodeEE("呼び出された変数\"" + ret.Name +"\"は設定により使用が禁止されています");
  482. }
  483. if (subKey != null)
  484. throw new CodeEE("ローカル変数でない変数" + key + "に対して@が使われました");
  485. return ret;
  486. }
  487. if (subKey != null)
  488. throw new CodeEE("@の使い方が不正です");
  489. return null;
  490. }
  491. public FunctionIdentifier GetFunctionIdentifier(string str)
  492. {
  493. string key = str;
  494. FunctionIdentifier ret = null;
  495. if (string.IsNullOrEmpty(key))
  496. return null;
  497. if (Config.Config.ICFunction)
  498. key = key.ToUpper();
  499. instructionDic.TryGetValue(key, out ret);
  500. return ret;
  501. }
  502. public List<string> GetOverloadedList(LabelDictionary labelDic)
  503. {
  504. List<string> list = new List<string>();
  505. foreach (KeyValuePair<string, FunctionMethod> pair in methodDic)
  506. {
  507. FunctionLabelLine func = labelDic.GetNonEventLabel(pair.Key);
  508. if (func == null)
  509. continue;
  510. if (!func.IsMethod)
  511. continue;
  512. list.Add(pair.Key);
  513. }
  514. return list;
  515. }
  516. public UserDefinedRefMethod GetRefMethod(string codeStr)
  517. {
  518. if (Config.Config.ICFunction)
  519. codeStr = codeStr.ToUpper();
  520. if (refmethodDic.ContainsKey(codeStr))
  521. return refmethodDic[codeStr];
  522. return null;
  523. }
  524. public IOperandTerm GetFunctionMethod(LabelDictionary labelDic, string codeStr, IOperandTerm[] arguments, bool userDefinedOnly)
  525. {
  526. if (Config.Config.ICFunction)
  527. codeStr = codeStr.ToUpper();
  528. if (arguments == null)//引数なし、名前のみの探索
  529. {
  530. if (refmethodDic.ContainsKey(codeStr))
  531. return new UserDefinedRefMethodNoArgTerm(refmethodDic[codeStr]);
  532. return null;
  533. }
  534. if ((labelDic != null) && (labelDic.Initialized))
  535. {
  536. if (refmethodDic.ContainsKey(codeStr))
  537. return new UserDefinedRefMethodTerm(refmethodDic[codeStr], arguments);
  538. FunctionLabelLine func = labelDic.GetNonEventLabel(codeStr);
  539. if (func != null)
  540. {
  541. if (userDefinedOnly && !func.IsMethod)
  542. {
  543. throw new CodeEE("#FUNCTIONが指定されていない関数\"@" + func.LabelName + "\"をCALLF系命令で呼び出そうとしました");
  544. }
  545. if (func.IsMethod)
  546. {
  547. string errMes;
  548. IOperandTerm ret = UserDefinedMethodTerm.Create(func, arguments, out errMes);
  549. if(ret == null)
  550. throw new CodeEE(errMes);
  551. return ret;
  552. }
  553. //1.721 #FUNCTIONが定義されていない関数は組み込み関数を上書きしない方向に。 PANCTION.ERBのRANDとか。
  554. if (!methodDic.ContainsKey(codeStr))
  555. throw new CodeEE("Function for which #FUNCTION was not declared (" + func.Position.Filename + " at line :" + func.Position.LineNo + ") has been attempted to be called inside of an expression");
  556. }
  557. }
  558. if (userDefinedOnly)
  559. return null;
  560. FunctionMethod method = null;
  561. if (!methodDic.TryGetValue(codeStr, out method))
  562. return null;
  563. string errmes = method.CheckArgumentType(codeStr, arguments);
  564. if (errmes != null)
  565. throw new CodeEE(errmes);
  566. return new FunctionMethodTerm(method, arguments);
  567. }
  568. //1756 作成中途
  569. //名前リストを元に何がやりたかったのかを推定してCodeEEを投げる
  570. public void ThrowException(string str, bool isFunc)
  571. {
  572. string idStr = str;
  573. if(Config.Config.ICFunction || Config.Config.ICVariable) //片方だけなのは互換性用オプションなのでレアケースのはず。対応しない。
  574. idStr = idStr.ToUpper();
  575. if (disableList.Contains(idStr))
  576. throw new CodeEE("\"" + str + "\" is declaring #DISABLE");
  577. if (!isFunc && privateDimList.Contains(idStr))
  578. throw new CodeEE("Variable \"" + str + "\" is not defined in this function");
  579. if (nameDic.ContainsKey(idStr))
  580. {
  581. DefinedNameType type = nameDic[idStr];
  582. switch (type)
  583. {
  584. case DefinedNameType.Reserved:
  585. throw new CodeEE("Emuera\'s reserved word \"" + str + "\" is being used in an illegal way");
  586. case DefinedNameType.SystemVariable:
  587. case DefinedNameType.UserGlobalVariable:
  588. if (isFunc)
  589. throw new CodeEE("Variable name \"" + str + "\" is used like a function");
  590. break;
  591. case DefinedNameType.SystemMethod:
  592. case DefinedNameType.UserRefMethod:
  593. if (!isFunc)
  594. throw new CodeEE("Function name \"" + str + "\" is used like a variable");
  595. break;
  596. case DefinedNameType.UserMacro:
  597. throw new CodeEE("Unexpected macro name: \"" + str + "\"");
  598. case DefinedNameType.SystemInstrument:
  599. if (isFunc)
  600. throw new CodeEE("Instruction name \"" + str + "\" is used like a function");
  601. else
  602. throw new CodeEE("Instruction name \"" + str + "\" is used like a variable");
  603. }
  604. }
  605. throw new CodeEE("\"" + idStr + "\" cannot be interpreted");
  606. }
  607. #endregion
  608. #region util
  609. public void resizeLocalVars(string key, string subKey, int newSize)
  610. {
  611. localvarTokenDic[key].ResizeLocalVariableToken(subKey, newSize);
  612. }
  613. public int getLocalDefaultSize(string key)
  614. {
  615. return localvarTokenDic[key].GetDefaultSize();
  616. }
  617. public bool getLocalIsForbid(string key)
  618. {
  619. return localvarTokenDic[key].IsForbid;
  620. }
  621. public bool getVarTokenIsForbid(string key)
  622. {
  623. if (localvarTokenDic.ContainsKey(key))
  624. return localvarTokenDic[key].IsForbid;
  625. VariableToken var = null;
  626. varTokenDic.TryGetValue(key, out var);
  627. if (var != null)
  628. return var.IsForbid;
  629. return true;
  630. }
  631. #endregion
  632. }
  633. }