OperatorMethod.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using NTERA.EmuEra.Game.EraEmu.GameData.Function;
  5. using NTERA.EmuEra.Game.EraEmu.GameData.Variable;
  6. using NTERA.EmuEra.Game.EraEmu.Sub;
  7. namespace NTERA.EmuEra.Game.EraEmu.GameData.Expression
  8. {
  9. /// <summary>
  10. /// 引数のチェック、戻り値の型チェック等は全て呼び出し元が責任を負うこと。
  11. /// </summary>
  12. internal abstract class OperatorMethod : FunctionMethod
  13. {
  14. public OperatorMethod()
  15. {
  16. argumentTypeArray = null;
  17. }
  18. public override string CheckArgumentType(string name, IOperandTerm[] arguments) { throw new ExeEE("型チェックは呼び出し元が行うこと"); }
  19. }
  20. internal static class OperatorMethodManager
  21. {
  22. static readonly Dictionary<OperatorCode, OperatorMethod> unaryDic = new Dictionary<OperatorCode, OperatorMethod>();
  23. static readonly Dictionary<OperatorCode, OperatorMethod> unaryAfterDic = new Dictionary<OperatorCode, OperatorMethod>();
  24. static readonly Dictionary<OperatorCode, OperatorMethod> binaryIntIntDic = new Dictionary<OperatorCode, OperatorMethod>();
  25. static readonly Dictionary<OperatorCode, OperatorMethod> binaryStrStrDic = new Dictionary<OperatorCode, OperatorMethod>();
  26. static readonly OperatorMethod binaryMultIntStr;
  27. static readonly OperatorMethod ternaryIntIntInt;
  28. static readonly OperatorMethod ternaryIntStrStr;
  29. static OperatorMethodManager()
  30. {
  31. unaryDic[OperatorCode.Plus] = new PlusInt();
  32. unaryDic[OperatorCode.Minus] = new MinusInt();
  33. unaryDic[OperatorCode.Not] = new NotInt();
  34. unaryDic[OperatorCode.BitNot] = new BitNotInt();
  35. unaryDic[OperatorCode.Increment] = new IncrementInt();
  36. unaryDic[OperatorCode.Decrement] = new DecrementInt();
  37. unaryAfterDic[OperatorCode.Increment] = new IncrementAfterInt();
  38. unaryAfterDic[OperatorCode.Decrement] = new DecrementAfterInt();
  39. binaryIntIntDic[OperatorCode.Plus] = new PlusIntInt();
  40. binaryIntIntDic[OperatorCode.Minus] = new MinusIntInt();
  41. binaryIntIntDic[OperatorCode.Mult] = new MultIntInt();
  42. binaryIntIntDic[OperatorCode.Div] = new DivIntInt();
  43. binaryIntIntDic[OperatorCode.Mod] = new ModIntInt();
  44. binaryIntIntDic[OperatorCode.Equal] = new EqualIntInt();
  45. binaryIntIntDic[OperatorCode.Greater] = new GreaterIntInt();
  46. binaryIntIntDic[OperatorCode.Less] = new LessIntInt();
  47. binaryIntIntDic[OperatorCode.GreaterEqual] = new GreaterEqualIntInt();
  48. binaryIntIntDic[OperatorCode.LessEqual] = new LessEqualIntInt();
  49. binaryIntIntDic[OperatorCode.NotEqual] = new NotEqualIntInt();
  50. binaryIntIntDic[OperatorCode.And] = new AndIntInt();
  51. binaryIntIntDic[OperatorCode.Or] = new OrIntInt();
  52. binaryIntIntDic[OperatorCode.Xor] = new XorIntInt();
  53. binaryIntIntDic[OperatorCode.Nand] = new NandIntInt();
  54. binaryIntIntDic[OperatorCode.Nor] = new NorIntInt();
  55. binaryIntIntDic[OperatorCode.BitAnd] = new BitAndIntInt();
  56. binaryIntIntDic[OperatorCode.BitOr] = new BitOrIntInt();
  57. binaryIntIntDic[OperatorCode.BitXor] = new BitXorIntInt();
  58. binaryIntIntDic[OperatorCode.RightShift] = new RightShiftIntInt();
  59. binaryIntIntDic[OperatorCode.LeftShift] = new LeftShiftIntInt();
  60. binaryStrStrDic[OperatorCode.Plus] = new PlusStrStr();
  61. binaryStrStrDic[OperatorCode.Equal] = new EqualStrStr();
  62. binaryStrStrDic[OperatorCode.Greater] = new GreaterStrStr();
  63. binaryStrStrDic[OperatorCode.Less] = new LessStrStr();
  64. binaryStrStrDic[OperatorCode.GreaterEqual] = new GreaterEqualStrStr();
  65. binaryStrStrDic[OperatorCode.LessEqual] = new LessEqualStrStr();
  66. binaryStrStrDic[OperatorCode.NotEqual] = new NotEqualStrStr();
  67. binaryMultIntStr = new MultStrInt();
  68. ternaryIntIntInt = new TernaryIntIntInt();
  69. ternaryIntStrStr = new TernaryIntStrStr();
  70. }
  71. public static IOperandTerm ReduceUnaryTerm(OperatorCode op, IOperandTerm o1)
  72. {
  73. OperatorMethod method = null;
  74. if (op == OperatorCode.Increment || op == OperatorCode.Decrement)
  75. {
  76. VariableTerm var = o1 as VariableTerm;
  77. if (var == null)
  78. throw new CodeEE("変数以外をインクリメントすることはできません");
  79. if (var.Identifier.IsConst)
  80. throw new CodeEE("変更できない変数をインクリメントすることはできません");
  81. }
  82. if (o1.GetOperandType() == typeof(Int64))
  83. {
  84. if (op == OperatorCode.Plus)
  85. return o1;
  86. if (unaryDic.ContainsKey(op))
  87. method = unaryDic[op];
  88. }
  89. if(method != null)
  90. return new FunctionMethodTerm(method, new[] { o1 });
  91. string errMes = "";
  92. if (o1.GetOperandType() == typeof(Int64))
  93. errMes += "数値型";
  94. else if (o1.GetOperandType() == typeof(string))
  95. errMes += "文字列型";
  96. else
  97. errMes += "不定型";
  98. errMes += "に単項演算子\'" + OperatorManager.ToOperatorString(op) + "\'は適用できません";
  99. throw new CodeEE(errMes);
  100. }
  101. public static IOperandTerm ReduceUnaryAfterTerm(OperatorCode op, IOperandTerm o1)
  102. {
  103. OperatorMethod method = null;
  104. if (op == OperatorCode.Increment || op == OperatorCode.Decrement)
  105. {
  106. VariableTerm var = o1 as VariableTerm;
  107. if (var == null)
  108. throw new CodeEE("変数以外をインクリメントすることはできません");
  109. if (var.Identifier.IsConst)
  110. throw new CodeEE("変更できない変数をインクリメントすることはできません");
  111. }
  112. if (o1.GetOperandType() == typeof(Int64))
  113. {
  114. if (unaryAfterDic.ContainsKey(op))
  115. method = unaryAfterDic[op];
  116. }
  117. if (method != null)
  118. return new FunctionMethodTerm(method, new[] { o1 });
  119. string errMes = "";
  120. if (o1.GetOperandType() == typeof(Int64))
  121. errMes += "数値型";
  122. else if (o1.GetOperandType() == typeof(string))
  123. errMes += "文字列型";
  124. else
  125. errMes += "不定型";
  126. errMes += "に後置単項演算子\'" + OperatorManager.ToOperatorString(op) + "\'は適用できません";
  127. throw new CodeEE(errMes);
  128. }
  129. public static IOperandTerm ReduceBinaryTerm(OperatorCode op, IOperandTerm left, IOperandTerm right)
  130. {
  131. OperatorMethod method = null;
  132. if ((left.GetOperandType() == typeof(Int64)) && (right.GetOperandType() == typeof(Int64)))
  133. {
  134. if (binaryIntIntDic.ContainsKey(op))
  135. method = binaryIntIntDic[op];
  136. }
  137. else if ((left.GetOperandType() == typeof(string)) && (right.GetOperandType() == typeof(string)))
  138. {
  139. if (binaryStrStrDic.ContainsKey(op))
  140. method = binaryStrStrDic[op];
  141. }
  142. else if (((left.GetOperandType() == typeof(Int64)) && (right.GetOperandType() == typeof(string)))
  143. || ((left.GetOperandType() == typeof(string)) && (right.GetOperandType() == typeof(Int64))))
  144. {
  145. if (op == OperatorCode.Mult)
  146. method = binaryMultIntStr;
  147. }
  148. if (method != null)
  149. return new FunctionMethodTerm(method, new[] { left, right });
  150. string errMes = "";
  151. if (left.GetOperandType() == typeof(Int64))
  152. errMes += "数値型と";
  153. else if (left.GetOperandType() == typeof(string))
  154. errMes += "文字列型と";
  155. else
  156. errMes += "不定型と";
  157. if (right.GetOperandType() == typeof(Int64))
  158. errMes += "数値型の";
  159. else if (right.GetOperandType() == typeof(string))
  160. errMes += "文字列型の";
  161. else
  162. errMes += "不定型の";
  163. errMes += "演算に二項演算子\'" + OperatorManager.ToOperatorString(op) + "\'は適用できません";
  164. throw new CodeEE(errMes);
  165. }
  166. public static IOperandTerm ReduceTernaryTerm(OperatorCode op, IOperandTerm o1, IOperandTerm o2, IOperandTerm o3)
  167. {
  168. OperatorMethod method = null;
  169. if ((o1.GetOperandType() == typeof(Int64)) && (o2.GetOperandType() == typeof(Int64)) && (o3.GetOperandType() == typeof(Int64)))
  170. method = ternaryIntIntInt;
  171. else if ((o1.GetOperandType() == typeof(Int64)) && (o2.GetOperandType() == typeof(string)) && (o3.GetOperandType() == typeof(string)))
  172. method = ternaryIntStrStr;
  173. if (method != null)
  174. return new FunctionMethodTerm(method, new[] { o1, o2, o3 });
  175. throw new CodeEE("三項演算子の使用法が不正です");
  176. }
  177. #region OperatorMethod SubClasses
  178. private sealed class PlusIntInt : OperatorMethod
  179. {
  180. public PlusIntInt()
  181. {
  182. CanRestructure = true;
  183. ReturnType = typeof(Int64);
  184. }
  185. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  186. {
  187. return arguments[0].GetIntValue(exm) + arguments[1].GetIntValue(exm);
  188. }
  189. }
  190. private sealed class PlusStrStr : OperatorMethod
  191. {
  192. public PlusStrStr()
  193. {
  194. CanRestructure = true;
  195. ReturnType = typeof(string);
  196. argumentTypeArray = new[] { typeof(string), typeof(string) };
  197. }
  198. public override string GetStrValue(ExpressionMediator exm, IOperandTerm[] arguments, bool tryTranslate = false)
  199. {
  200. return arguments[0].GetStrValue(exm, tryTranslate) + arguments[1].GetStrValue(exm, tryTranslate); // JVN: Would be a great idea to attempt to translate both sides instead of just one here
  201. }
  202. }
  203. private sealed class MinusIntInt : OperatorMethod
  204. {
  205. public MinusIntInt()
  206. {
  207. CanRestructure = true;
  208. ReturnType = typeof(Int64);
  209. }
  210. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  211. {
  212. return arguments[0].GetIntValue(exm) - arguments[1].GetIntValue(exm);
  213. }
  214. }
  215. private sealed class MultIntInt : OperatorMethod
  216. {
  217. public MultIntInt()
  218. {
  219. CanRestructure = true;
  220. ReturnType = typeof(Int64);
  221. }
  222. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  223. {
  224. return arguments[0].GetIntValue(exm) * arguments[1].GetIntValue(exm);
  225. }
  226. }
  227. private sealed class MultStrInt : OperatorMethod
  228. {
  229. public MultStrInt()
  230. {
  231. CanRestructure = true;
  232. ReturnType = typeof(string);
  233. }
  234. public override string GetStrValue(ExpressionMediator exm, IOperandTerm[] arguments, bool tryTranslate = false)
  235. {
  236. Int64 value = 0;
  237. string str = null;
  238. if (arguments[0].GetOperandType() == typeof(Int64))
  239. {
  240. value = arguments[0].GetIntValue(exm);
  241. str = arguments[1].GetStrValue(exm, tryTranslate);
  242. }
  243. else
  244. {
  245. str = arguments[0].GetStrValue(exm, tryTranslate);
  246. value = arguments[1].GetIntValue(exm);
  247. }
  248. if (value < 0)
  249. throw new CodeEE("文字列に負の値(" + value + ")を乗算しようとしました");
  250. if (value >= 10000)
  251. throw new CodeEE("文字列に10000以上の値(" + value + ")を乗算しようとしました");
  252. if ((str == "") || (value == 0))
  253. return "";
  254. StringBuilder builder = new StringBuilder();
  255. builder.Capacity = str.Length * (int)value;
  256. for (int i = 0; i < value; i++)
  257. {
  258. builder.Append(str);
  259. }
  260. return builder.ToString();
  261. }
  262. }
  263. private sealed class DivIntInt : OperatorMethod
  264. {
  265. public DivIntInt()
  266. {
  267. CanRestructure = true;
  268. ReturnType = typeof(Int64);
  269. }
  270. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  271. {
  272. Int64 right = arguments[1].GetIntValue(exm);
  273. if (right == 0)
  274. throw new CodeEE("0による除算が行なわれました");
  275. return arguments[0].GetIntValue(exm) / right;
  276. }
  277. }
  278. private sealed class ModIntInt : OperatorMethod
  279. {
  280. public ModIntInt()
  281. {
  282. CanRestructure = true;
  283. ReturnType = typeof(Int64);
  284. }
  285. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  286. {
  287. Int64 right = arguments[1].GetIntValue(exm);
  288. if (right == 0)
  289. throw new CodeEE("0による除算が行なわれました");
  290. return arguments[0].GetIntValue(exm) % right;
  291. }
  292. }
  293. private sealed class EqualIntInt : OperatorMethod
  294. {
  295. public EqualIntInt()
  296. {
  297. CanRestructure = true;
  298. ReturnType = typeof(Int64);
  299. }
  300. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  301. {
  302. if (arguments[0].GetIntValue(exm) == arguments[1].GetIntValue(exm))
  303. return 1L;
  304. return 0L;
  305. }
  306. }
  307. private sealed class EqualStrStr : OperatorMethod
  308. {
  309. public EqualStrStr()
  310. {
  311. CanRestructure = true;
  312. ReturnType = typeof(Int64);
  313. }
  314. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  315. {
  316. if (arguments[0].GetStrValue(exm) == arguments[1].GetStrValue(exm))
  317. return 1L;
  318. return 0L;
  319. }
  320. }
  321. private sealed class NotEqualIntInt : OperatorMethod
  322. {
  323. public NotEqualIntInt()
  324. {
  325. CanRestructure = true;
  326. ReturnType = typeof(Int64);
  327. }
  328. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  329. {
  330. if (arguments[0].GetIntValue(exm) != arguments[1].GetIntValue(exm))
  331. return 1L;
  332. return 0L;
  333. }
  334. }
  335. private sealed class NotEqualStrStr : OperatorMethod
  336. {
  337. public NotEqualStrStr()
  338. {
  339. CanRestructure = true;
  340. ReturnType = typeof(Int64);
  341. }
  342. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  343. {
  344. if (arguments[0].GetStrValue(exm) != arguments[1].GetStrValue(exm))
  345. return 1L;
  346. return 0L;
  347. }
  348. }
  349. private sealed class GreaterIntInt : OperatorMethod
  350. {
  351. public GreaterIntInt()
  352. {
  353. CanRestructure = true;
  354. ReturnType = typeof(Int64);
  355. }
  356. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  357. {
  358. if (arguments[0].GetIntValue(exm) > arguments[1].GetIntValue(exm))
  359. return 1L;
  360. return 0L;
  361. }
  362. }
  363. private sealed class GreaterStrStr : OperatorMethod
  364. {
  365. public GreaterStrStr()
  366. {
  367. CanRestructure = true;
  368. ReturnType = typeof(Int64);
  369. }
  370. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  371. {
  372. int c = string.Compare(arguments[0].GetStrValue(exm), arguments[1].GetStrValue(exm), Config.Config.SCExpression);
  373. if (c > 0)
  374. return 1L;
  375. return 0L;
  376. }
  377. }
  378. private sealed class LessIntInt : OperatorMethod
  379. {
  380. public LessIntInt()
  381. {
  382. CanRestructure = true;
  383. ReturnType = typeof(Int64);
  384. }
  385. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  386. {
  387. if (arguments[0].GetIntValue(exm) < arguments[1].GetIntValue(exm))
  388. return 1L;
  389. return 0L;
  390. }
  391. }
  392. private sealed class LessStrStr : OperatorMethod
  393. {
  394. public LessStrStr()
  395. {
  396. CanRestructure = true;
  397. ReturnType = typeof(Int64);
  398. }
  399. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  400. {
  401. int c = string.Compare(arguments[0].GetStrValue(exm), arguments[1].GetStrValue(exm), Config.Config.SCExpression);
  402. if (c < 0)
  403. return 1L;
  404. return 0L;
  405. }
  406. }
  407. private sealed class GreaterEqualIntInt : OperatorMethod
  408. {
  409. public GreaterEqualIntInt()
  410. {
  411. CanRestructure = true;
  412. ReturnType = typeof(Int64);
  413. }
  414. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  415. {
  416. if (arguments[0].GetIntValue(exm) >= arguments[1].GetIntValue(exm))
  417. return 1L;
  418. return 0L;
  419. }
  420. }
  421. private sealed class GreaterEqualStrStr : OperatorMethod
  422. {
  423. public GreaterEqualStrStr()
  424. {
  425. CanRestructure = true;
  426. ReturnType = typeof(Int64);
  427. }
  428. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  429. {
  430. int c = string.Compare(arguments[0].GetStrValue(exm), arguments[1].GetStrValue(exm), Config.Config.SCExpression);
  431. if (c < 0)
  432. return 1L;
  433. return 0L;
  434. }
  435. }
  436. private sealed class LessEqualIntInt : OperatorMethod
  437. {
  438. public LessEqualIntInt()
  439. {
  440. CanRestructure = true;
  441. ReturnType = typeof(Int64);
  442. }
  443. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  444. {
  445. if (arguments[0].GetIntValue(exm) <= arguments[1].GetIntValue(exm))
  446. return 1L;
  447. return 0L;
  448. }
  449. }
  450. private sealed class LessEqualStrStr : OperatorMethod
  451. {
  452. public LessEqualStrStr()
  453. {
  454. CanRestructure = true;
  455. ReturnType = typeof(Int64);
  456. }
  457. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  458. {
  459. int c = string.Compare(arguments[0].GetStrValue(exm), arguments[1].GetStrValue(exm), Config.Config.SCExpression);
  460. if (c < 0)
  461. return 1L;
  462. return 0L;
  463. }
  464. }
  465. private sealed class AndIntInt : OperatorMethod
  466. {
  467. public AndIntInt()
  468. {
  469. CanRestructure = true;
  470. ReturnType = typeof(Int64);
  471. }
  472. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  473. {
  474. if ((arguments[0].GetIntValue(exm) != 0) && (arguments[1].GetIntValue(exm) != 0))
  475. return 1L;
  476. return 0L;
  477. }
  478. }
  479. private sealed class OrIntInt : OperatorMethod
  480. {
  481. public OrIntInt()
  482. {
  483. CanRestructure = true;
  484. ReturnType = typeof(Int64);
  485. }
  486. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  487. {
  488. if ((arguments[0].GetIntValue(exm) != 0) || (arguments[1].GetIntValue(exm) != 0))
  489. return 1L;
  490. return 0L;
  491. }
  492. }
  493. private sealed class XorIntInt : OperatorMethod
  494. {
  495. public XorIntInt()
  496. {
  497. CanRestructure = true;
  498. ReturnType = typeof(Int64);
  499. }
  500. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  501. {
  502. Int64 i1 = arguments[0].GetIntValue(exm);
  503. Int64 i2 = arguments[1].GetIntValue(exm);
  504. if (((i1 == 0) && (i2 != 0)) || ((i1 != 0) && (i2 == 0)))
  505. return 1L;
  506. return 0L;
  507. }
  508. }
  509. private sealed class NandIntInt : OperatorMethod
  510. {
  511. public NandIntInt()
  512. {
  513. CanRestructure = true;
  514. ReturnType = typeof(Int64);
  515. }
  516. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  517. {
  518. if ((arguments[0].GetIntValue(exm) == 0) || (arguments[1].GetIntValue(exm) == 0))
  519. return 1L;
  520. return 0L;
  521. }
  522. }
  523. private sealed class NorIntInt : OperatorMethod
  524. {
  525. public NorIntInt()
  526. {
  527. CanRestructure = true;
  528. ReturnType = typeof(Int64);
  529. }
  530. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  531. {
  532. if ((arguments[0].GetIntValue(exm) == 0) && (arguments[1].GetIntValue(exm) == 0))
  533. return 1L;
  534. return 0L;
  535. }
  536. }
  537. private sealed class BitAndIntInt : OperatorMethod
  538. {
  539. public BitAndIntInt()
  540. {
  541. CanRestructure = true;
  542. ReturnType = typeof(Int64);
  543. }
  544. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  545. {
  546. return arguments[0].GetIntValue(exm) & arguments[1].GetIntValue(exm);
  547. }
  548. }
  549. private sealed class BitOrIntInt : OperatorMethod
  550. {
  551. public BitOrIntInt()
  552. {
  553. CanRestructure = true;
  554. ReturnType = typeof(Int64);
  555. }
  556. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  557. {
  558. return arguments[0].GetIntValue(exm) | arguments[1].GetIntValue(exm);
  559. }
  560. }
  561. private sealed class BitXorIntInt : OperatorMethod
  562. {
  563. public BitXorIntInt()
  564. {
  565. CanRestructure = true;
  566. ReturnType = typeof(Int64);
  567. }
  568. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  569. {
  570. return arguments[0].GetIntValue(exm) ^ arguments[1].GetIntValue(exm);
  571. }
  572. }
  573. private sealed class RightShiftIntInt : OperatorMethod
  574. {
  575. public RightShiftIntInt()
  576. {
  577. CanRestructure = true;
  578. ReturnType = typeof(Int64);
  579. }
  580. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  581. {
  582. return arguments[0].GetIntValue(exm) >> (Int32)(arguments[1].GetIntValue(exm));
  583. }
  584. }
  585. private sealed class LeftShiftIntInt : OperatorMethod
  586. {
  587. public LeftShiftIntInt()
  588. {
  589. CanRestructure = true;
  590. ReturnType = typeof(Int64);
  591. }
  592. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  593. {
  594. return arguments[0].GetIntValue(exm) << (Int32)(arguments[1].GetIntValue(exm));
  595. }
  596. }
  597. private sealed class PlusInt : OperatorMethod
  598. {
  599. public PlusInt()
  600. {
  601. CanRestructure = true;
  602. ReturnType = typeof(Int64);
  603. }
  604. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  605. {
  606. return arguments[0].GetIntValue(exm);
  607. }
  608. }
  609. private sealed class MinusInt : OperatorMethod
  610. {
  611. public MinusInt()
  612. {
  613. CanRestructure = true;
  614. ReturnType = typeof(Int64);
  615. }
  616. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  617. {
  618. return -arguments[0].GetIntValue(exm);
  619. }
  620. }
  621. private sealed class NotInt : OperatorMethod
  622. {
  623. public NotInt()
  624. {
  625. CanRestructure = true;
  626. ReturnType = typeof(Int64);
  627. }
  628. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  629. {
  630. if (arguments[0].GetIntValue(exm) == 0)
  631. return 1L;
  632. return 0L;
  633. }
  634. }
  635. private sealed class BitNotInt : OperatorMethod
  636. {
  637. public BitNotInt()
  638. {
  639. CanRestructure = true;
  640. ReturnType = typeof(Int64);
  641. }
  642. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  643. {
  644. return ~arguments[0].GetIntValue(exm);
  645. }
  646. }
  647. private sealed class IncrementInt : OperatorMethod
  648. {
  649. public IncrementInt()
  650. {
  651. CanRestructure = false;
  652. ReturnType = typeof(Int64);
  653. }
  654. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  655. {
  656. VariableTerm var = (VariableTerm)arguments[0];
  657. return var.PlusValue(1L, exm);
  658. }
  659. }
  660. private sealed class DecrementInt : OperatorMethod
  661. {
  662. public DecrementInt()
  663. {
  664. CanRestructure = false;
  665. ReturnType = typeof(Int64);
  666. }
  667. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  668. {
  669. VariableTerm var = (VariableTerm)arguments[0];
  670. return var.PlusValue(-1L, exm);
  671. }
  672. }
  673. private sealed class IncrementAfterInt : OperatorMethod
  674. {
  675. public IncrementAfterInt()
  676. {
  677. CanRestructure = false;
  678. ReturnType = typeof(Int64);
  679. }
  680. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  681. {
  682. VariableTerm var = (VariableTerm)arguments[0];
  683. return var.PlusValue(1L, exm) - 1;
  684. }
  685. }
  686. private sealed class DecrementAfterInt : OperatorMethod
  687. {
  688. public DecrementAfterInt()
  689. {
  690. CanRestructure = false;
  691. ReturnType = typeof(Int64);
  692. }
  693. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  694. {
  695. VariableTerm var = (VariableTerm)arguments[0];
  696. return var.PlusValue(-1L, exm) + 1;
  697. }
  698. }
  699. private sealed class TernaryIntIntInt : OperatorMethod
  700. {
  701. public TernaryIntIntInt()
  702. {
  703. CanRestructure = true;
  704. ReturnType = typeof(Int64);
  705. }
  706. public override Int64 GetIntValue(ExpressionMediator exm, IOperandTerm[] arguments)
  707. {
  708. return (arguments[0].GetIntValue(exm) != 0) ? arguments[1].GetIntValue(exm) : arguments[2].GetIntValue(exm);
  709. }
  710. }
  711. private sealed class TernaryIntStrStr : OperatorMethod
  712. {
  713. public TernaryIntStrStr()
  714. {
  715. CanRestructure = true;
  716. ReturnType = typeof(string);
  717. }
  718. public override string GetStrValue(ExpressionMediator exm, IOperandTerm[] arguments, bool tryTranslate = false)
  719. {
  720. return (arguments[0].GetIntValue(exm) != 0) ? arguments[1].GetStrValue(exm) : arguments[2].GetStrValue(exm);
  721. }
  722. }
  723. #endregion
  724. }
  725. }