PageRenderTime 37ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/lscript/lscript_compile/lscript_typecheck.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 586 lines | 438 code | 48 blank | 100 comment | 24 complexity | cf11431d6203123dbf56b14f98340a0b MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lscript_typecheck.cpp
  3. * @brief typechecks script
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "linden_common.h"
  27. #include "lscript_tree.h"
  28. /*
  29. LScript automatic type casting
  30. LST_INTEGER -> LST_INTEGER
  31. LST_FLOATINGPOINT -> LST_FLOATINGPOINT
  32. LST_INTEGER -> LST_FLOATINGPOINT
  33. LST_FLOATINGPOINT -> LST_STRING
  34. LST_INTEGER -> LST_STRING
  35. LST_STRING -> LST_STRING
  36. LST_VECTOR -> LST_STRING
  37. LST_QUATERNION -> LST_STRING
  38. LST_LIST -> LST_STRING
  39. LST_VECTOR -> LST_VECTOR
  40. LST_QUATERNION -> LST_QUATERNION
  41. LST_FLOATINGPOINT -> LST_LIST
  42. LST_INTEGER -> LST_LIST
  43. LST_STRING -> LST_LIST
  44. LST_VECTOR -> LST_LIST
  45. LST_QUATERNION -> LST_LIST
  46. LST_LIST -> LST_LIST
  47. */
  48. LSCRIPTType implicit_casts(LSCRIPTType left_side, LSCRIPTType right_side)
  49. {
  50. switch(left_side)
  51. {
  52. // shouldn't be doing an operation on void types
  53. case LST_NULL:
  54. switch(right_side)
  55. {
  56. case LST_NULL:
  57. return LST_NULL;
  58. default:
  59. return LST_UNDEFINED;
  60. }
  61. // shouldn't be doing an operation on undefined types
  62. case LST_UNDEFINED:
  63. return LST_UNDEFINED;
  64. // only integers can become integers
  65. case LST_INTEGER:
  66. switch(right_side)
  67. {
  68. case LST_INTEGER:
  69. return LST_INTEGER;
  70. default:
  71. return LST_UNDEFINED;
  72. }
  73. // only integers and floats can become floats
  74. case LST_FLOATINGPOINT:
  75. switch(right_side)
  76. {
  77. case LST_INTEGER:
  78. case LST_FLOATINGPOINT:
  79. return LST_FLOATINGPOINT;
  80. default:
  81. return LST_UNDEFINED;
  82. }
  83. // only strings and keys can become strings
  84. case LST_STRING:
  85. switch(right_side)
  86. {
  87. case LST_STRING:
  88. case LST_KEY:
  89. return LST_STRING;
  90. default:
  91. return LST_UNDEFINED;
  92. }
  93. // only strings and keys can become keys
  94. case LST_KEY:
  95. switch(right_side)
  96. {
  97. case LST_STRING:
  98. case LST_KEY:
  99. return LST_KEY;
  100. default:
  101. return LST_UNDEFINED;
  102. }
  103. // only vectors can become vectors
  104. case LST_VECTOR:
  105. switch(right_side)
  106. {
  107. case LST_VECTOR:
  108. return LST_VECTOR;
  109. default:
  110. return LST_UNDEFINED;
  111. }
  112. // only quaternions can become quaternions
  113. case LST_QUATERNION:
  114. switch(right_side)
  115. {
  116. case LST_QUATERNION:
  117. return LST_QUATERNION;
  118. default:
  119. return LST_UNDEFINED;
  120. }
  121. // only lists can become lists
  122. case LST_LIST:
  123. switch(right_side)
  124. {
  125. case LST_LIST:
  126. return LST_LIST;
  127. default:
  128. return LST_UNDEFINED;
  129. }
  130. default:
  131. return LST_UNDEFINED;
  132. }
  133. }
  134. LSCRIPTType promote(LSCRIPTType left_side, LSCRIPTType right_side)
  135. {
  136. LSCRIPTType type;
  137. type = implicit_casts(left_side, right_side);
  138. if (type != LST_UNDEFINED)
  139. {
  140. return type;
  141. }
  142. type = implicit_casts(right_side, left_side);
  143. if (type != LST_UNDEFINED)
  144. {
  145. return type;
  146. }
  147. return LST_UNDEFINED;
  148. }
  149. BOOL legal_assignment(LSCRIPTType left_side, LSCRIPTType right_side)
  150. {
  151. // this is to prevent cascading errors
  152. if ( (left_side == LST_UNDEFINED)
  153. ||(right_side == LST_UNDEFINED))
  154. {
  155. return TRUE;
  156. }
  157. if (implicit_casts(left_side, right_side) != LST_UNDEFINED)
  158. {
  159. return TRUE;
  160. }
  161. else
  162. {
  163. return FALSE;
  164. }
  165. }
  166. BOOL legal_casts(LSCRIPTType cast, LSCRIPTType base)
  167. {
  168. switch(base)
  169. {
  170. // shouldn't be doing an operation on void types
  171. case LST_NULL:
  172. return FALSE;
  173. // shouldn't be doing an operation on undefined types
  174. case LST_UNDEFINED:
  175. return FALSE;
  176. case LST_INTEGER:
  177. switch(cast)
  178. {
  179. case LST_INTEGER:
  180. case LST_FLOATINGPOINT:
  181. case LST_STRING:
  182. case LST_LIST:
  183. return TRUE;
  184. break;
  185. default:
  186. return FALSE;
  187. break;
  188. }
  189. break;
  190. case LST_FLOATINGPOINT:
  191. switch(cast)
  192. {
  193. case LST_INTEGER:
  194. case LST_FLOATINGPOINT:
  195. case LST_STRING:
  196. case LST_LIST:
  197. return TRUE;
  198. break;
  199. default:
  200. return FALSE;
  201. break;
  202. }
  203. break;
  204. case LST_STRING:
  205. switch(cast)
  206. {
  207. case LST_INTEGER:
  208. case LST_FLOATINGPOINT:
  209. case LST_STRING:
  210. case LST_KEY:
  211. case LST_VECTOR:
  212. case LST_QUATERNION:
  213. case LST_LIST:
  214. return TRUE;
  215. break;
  216. default:
  217. return FALSE;
  218. break;
  219. }
  220. break;
  221. case LST_KEY:
  222. switch(cast)
  223. {
  224. case LST_STRING:
  225. case LST_KEY:
  226. case LST_LIST:
  227. return TRUE;
  228. break;
  229. default:
  230. return FALSE;
  231. break;
  232. }
  233. break;
  234. case LST_VECTOR:
  235. switch(cast)
  236. {
  237. case LST_VECTOR:
  238. case LST_STRING:
  239. case LST_LIST:
  240. return TRUE;
  241. break;
  242. default:
  243. return FALSE;
  244. break;
  245. }
  246. break;
  247. case LST_QUATERNION:
  248. switch(cast)
  249. {
  250. case LST_QUATERNION:
  251. case LST_STRING:
  252. case LST_LIST:
  253. return TRUE;
  254. break;
  255. default:
  256. return FALSE;
  257. break;
  258. }
  259. break;
  260. // lists can only be cast to lists and strings
  261. case LST_LIST:
  262. switch(cast)
  263. {
  264. case LST_LIST:
  265. case LST_STRING:
  266. return TRUE;
  267. break;
  268. default:
  269. return FALSE;
  270. break;
  271. }
  272. break;
  273. default:
  274. return FALSE;
  275. break;
  276. }
  277. }
  278. LSCRIPTType gSupportedExpressionArray[LET_EOF][LST_EOF][LST_EOF];
  279. void init_supported_expressions(void)
  280. {
  281. S32 i, j, k;
  282. // zero out, then set the ones that matter
  283. for (i = 0; i < LET_EOF; i++)
  284. {
  285. for (j = 0; j < LST_EOF; j++)
  286. {
  287. for (k = 0; k < LST_EOF; k++)
  288. {
  289. gSupportedExpressionArray[i][j][k] = LST_NULL;
  290. }
  291. }
  292. }
  293. // LET_ASSIGNMENT
  294. gSupportedExpressionArray[LET_ASSIGNMENT][LST_INTEGER][LST_INTEGER] = LST_INTEGER;
  295. gSupportedExpressionArray[LET_ASSIGNMENT][LST_FLOATINGPOINT][LST_INTEGER] = LST_FLOATINGPOINT;
  296. gSupportedExpressionArray[LET_ASSIGNMENT][LST_INTEGER][LST_FLOATINGPOINT] = LST_FLOATINGPOINT;
  297. gSupportedExpressionArray[LET_ASSIGNMENT][LST_FLOATINGPOINT][LST_FLOATINGPOINT] = LST_FLOATINGPOINT;
  298. gSupportedExpressionArray[LET_ASSIGNMENT][LST_STRING][LST_STRING] = LST_STRING;
  299. gSupportedExpressionArray[LET_ASSIGNMENT][LST_KEY][LST_KEY] = LST_KEY;
  300. gSupportedExpressionArray[LET_ASSIGNMENT][LST_VECTOR][LST_VECTOR] = LST_VECTOR;
  301. gSupportedExpressionArray[LET_ASSIGNMENT][LST_QUATERNION][LST_QUATERNION] = LST_QUATERNION;
  302. gSupportedExpressionArray[LET_ASSIGNMENT][LST_LIST][LST_INTEGER] = LST_LIST;
  303. gSupportedExpressionArray[LET_ASSIGNMENT][LST_LIST][LST_FLOATINGPOINT] = LST_LIST;
  304. gSupportedExpressionArray[LET_ASSIGNMENT][LST_LIST][LST_STRING] = LST_LIST;
  305. gSupportedExpressionArray[LET_ASSIGNMENT][LST_LIST][LST_KEY] = LST_LIST;
  306. gSupportedExpressionArray[LET_ASSIGNMENT][LST_LIST][LST_VECTOR] = LST_LIST;
  307. gSupportedExpressionArray[LET_ASSIGNMENT][LST_LIST][LST_QUATERNION] = LST_LIST;
  308. gSupportedExpressionArray[LET_ASSIGNMENT][LST_LIST][LST_LIST] = LST_LIST;
  309. // LET_ADD_ASSIGN
  310. gSupportedExpressionArray[LET_ADD_ASSIGN][LST_INTEGER][LST_INTEGER] = LST_INTEGER;
  311. gSupportedExpressionArray[LET_ADD_ASSIGN][LST_FLOATINGPOINT][LST_INTEGER] = LST_FLOATINGPOINT;
  312. gSupportedExpressionArray[LET_ADD_ASSIGN][LST_FLOATINGPOINT][LST_FLOATINGPOINT] = LST_FLOATINGPOINT;
  313. gSupportedExpressionArray[LET_ADD_ASSIGN][LST_STRING][LST_STRING] = LST_STRING;
  314. gSupportedExpressionArray[LET_ADD_ASSIGN][LST_VECTOR][LST_VECTOR] = LST_VECTOR;
  315. gSupportedExpressionArray[LET_ADD_ASSIGN][LST_QUATERNION][LST_QUATERNION] = LST_QUATERNION;
  316. gSupportedExpressionArray[LET_ADD_ASSIGN][LST_LIST][LST_INTEGER] = LST_LIST;
  317. gSupportedExpressionArray[LET_ADD_ASSIGN][LST_LIST][LST_FLOATINGPOINT] = LST_LIST;
  318. gSupportedExpressionArray[LET_ADD_ASSIGN][LST_LIST][LST_STRING] = LST_LIST;
  319. gSupportedExpressionArray[LET_ADD_ASSIGN][LST_LIST][LST_KEY] = LST_LIST;
  320. gSupportedExpressionArray[LET_ADD_ASSIGN][LST_LIST][LST_VECTOR] = LST_LIST;
  321. gSupportedExpressionArray[LET_ADD_ASSIGN][LST_LIST][LST_QUATERNION] = LST_LIST;
  322. gSupportedExpressionArray[LET_ADD_ASSIGN][LST_LIST][LST_LIST] = LST_LIST;
  323. // LET_SUB_ASSIGN
  324. gSupportedExpressionArray[LET_SUB_ASSIGN][LST_INTEGER][LST_INTEGER] = LST_INTEGER;
  325. gSupportedExpressionArray[LET_SUB_ASSIGN][LST_FLOATINGPOINT][LST_INTEGER] = LST_FLOATINGPOINT;
  326. gSupportedExpressionArray[LET_SUB_ASSIGN][LST_FLOATINGPOINT][LST_FLOATINGPOINT] = LST_FLOATINGPOINT;
  327. gSupportedExpressionArray[LET_SUB_ASSIGN][LST_VECTOR][LST_VECTOR] = LST_VECTOR;
  328. gSupportedExpressionArray[LET_SUB_ASSIGN][LST_QUATERNION][LST_QUATERNION] = LST_QUATERNION;
  329. // LET_MUL_ASSIGN
  330. gSupportedExpressionArray[LET_MUL_ASSIGN][LST_INTEGER][LST_INTEGER] = LST_INTEGER;
  331. gSupportedExpressionArray[LET_MUL_ASSIGN][LST_FLOATINGPOINT][LST_INTEGER] = LST_FLOATINGPOINT;
  332. gSupportedExpressionArray[LET_MUL_ASSIGN][LST_INTEGER][LST_FLOATINGPOINT] = LST_FLOATINGPOINT;
  333. gSupportedExpressionArray[LET_MUL_ASSIGN][LST_FLOATINGPOINT][LST_FLOATINGPOINT] = LST_FLOATINGPOINT;
  334. gSupportedExpressionArray[LET_MUL_ASSIGN][LST_VECTOR][LST_INTEGER] = LST_VECTOR;
  335. //gSupportedExpressionArray[LET_MUL_ASSIGN][LST_INTEGER][LST_VECTOR] = LST_VECTOR;
  336. gSupportedExpressionArray[LET_MUL_ASSIGN][LST_VECTOR][LST_FLOATINGPOINT] = LST_VECTOR;
  337. //gSupportedExpressionArray[LET_MUL_ASSIGN][LST_FLOATINGPOINT][LST_VECTOR] = LST_VECTOR;
  338. //gSupportedExpressionArray[LET_MUL_ASSIGN][LST_VECTOR][LST_VECTOR] = LST_FLOATINGPOINT;
  339. gSupportedExpressionArray[LET_MUL_ASSIGN][LST_VECTOR][LST_QUATERNION] = LST_VECTOR;
  340. gSupportedExpressionArray[LET_MUL_ASSIGN][LST_QUATERNION][LST_QUATERNION] = LST_QUATERNION;
  341. // LET_DIV_ASSIGN
  342. gSupportedExpressionArray[LET_DIV_ASSIGN][LST_INTEGER][LST_INTEGER] = LST_INTEGER;
  343. gSupportedExpressionArray[LET_DIV_ASSIGN][LST_FLOATINGPOINT][LST_INTEGER] = LST_FLOATINGPOINT;
  344. gSupportedExpressionArray[LET_DIV_ASSIGN][LST_FLOATINGPOINT][LST_FLOATINGPOINT] = LST_FLOATINGPOINT;
  345. gSupportedExpressionArray[LET_DIV_ASSIGN][LST_VECTOR][LST_INTEGER] = LST_VECTOR;
  346. gSupportedExpressionArray[LET_DIV_ASSIGN][LST_VECTOR][LST_FLOATINGPOINT] = LST_VECTOR;
  347. gSupportedExpressionArray[LET_DIV_ASSIGN][LST_VECTOR][LST_QUATERNION] = LST_VECTOR;
  348. gSupportedExpressionArray[LET_DIV_ASSIGN][LST_QUATERNION][LST_QUATERNION] = LST_QUATERNION;
  349. // LET_MOD_ASSIGN
  350. gSupportedExpressionArray[LET_MOD_ASSIGN][LST_INTEGER][LST_INTEGER] = LST_INTEGER;
  351. gSupportedExpressionArray[LET_MOD_ASSIGN][LST_VECTOR][LST_VECTOR] = LST_VECTOR;
  352. // LET_EQUALITY
  353. gSupportedExpressionArray[LET_EQUALITY][LST_INTEGER][LST_INTEGER] = LST_INTEGER;
  354. gSupportedExpressionArray[LET_EQUALITY][LST_INTEGER][LST_FLOATINGPOINT] = LST_INTEGER;
  355. gSupportedExpressionArray[LET_EQUALITY][LST_FLOATINGPOINT][LST_INTEGER] = LST_INTEGER;
  356. gSupportedExpressionArray[LET_EQUALITY][LST_FLOATINGPOINT][LST_FLOATINGPOINT] = LST_INTEGER;
  357. gSupportedExpressionArray[LET_EQUALITY][LST_STRING][LST_STRING] = LST_INTEGER;
  358. gSupportedExpressionArray[LET_EQUALITY][LST_STRING][LST_KEY] = LST_INTEGER;
  359. gSupportedExpressionArray[LET_EQUALITY][LST_KEY][LST_STRING] = LST_INTEGER;
  360. gSupportedExpressionArray[LET_EQUALITY][LST_KEY][LST_KEY] = LST_INTEGER;
  361. gSupportedExpressionArray[LET_EQUALITY][LST_VECTOR][LST_VECTOR] = LST_INTEGER;
  362. gSupportedExpressionArray[LET_EQUALITY][LST_QUATERNION][LST_QUATERNION] = LST_INTEGER;
  363. gSupportedExpressionArray[LET_EQUALITY][LST_LIST][LST_LIST] = LST_INTEGER;
  364. // LET_NOT_EQUALS
  365. gSupportedExpressionArray[LET_NOT_EQUALS][LST_INTEGER][LST_INTEGER] = LST_INTEGER;
  366. gSupportedExpressionArray[LET_NOT_EQUALS][LST_INTEGER][LST_FLOATINGPOINT] = LST_INTEGER;
  367. gSupportedExpressionArray[LET_NOT_EQUALS][LST_FLOATINGPOINT][LST_INTEGER] = LST_INTEGER;
  368. gSupportedExpressionArray[LET_NOT_EQUALS][LST_FLOATINGPOINT][LST_FLOATINGPOINT] = LST_INTEGER;
  369. gSupportedExpressionArray[LET_NOT_EQUALS][LST_STRING][LST_STRING] = LST_INTEGER;
  370. gSupportedExpressionArray[LET_NOT_EQUALS][LST_STRING][LST_KEY] = LST_INTEGER;
  371. gSupportedExpressionArray[LET_NOT_EQUALS][LST_KEY][LST_STRING] = LST_INTEGER;
  372. gSupportedExpressionArray[LET_NOT_EQUALS][LST_KEY][LST_KEY] = LST_INTEGER;
  373. gSupportedExpressionArray[LET_NOT_EQUALS][LST_VECTOR][LST_VECTOR] = LST_INTEGER;
  374. gSupportedExpressionArray[LET_NOT_EQUALS][LST_QUATERNION][LST_QUATERNION] = LST_INTEGER;
  375. gSupportedExpressionArray[LET_NOT_EQUALS][LST_LIST][LST_LIST] = LST_INTEGER;
  376. // LET_LESS_EQUALS
  377. gSupportedExpressionArray[LET_LESS_EQUALS][LST_INTEGER][LST_INTEGER] = LST_INTEGER;
  378. gSupportedExpressionArray[LET_LESS_EQUALS][LST_INTEGER][LST_FLOATINGPOINT] = LST_INTEGER;
  379. gSupportedExpressionArray[LET_LESS_EQUALS][LST_FLOATINGPOINT][LST_INTEGER] = LST_INTEGER;
  380. gSupportedExpressionArray[LET_LESS_EQUALS][LST_FLOATINGPOINT][LST_FLOATINGPOINT] = LST_INTEGER;
  381. // LET_GREATER_EQUALS
  382. gSupportedExpressionArray[LET_GREATER_EQUALS][LST_INTEGER][LST_INTEGER] = LST_INTEGER;
  383. gSupportedExpressionArray[LET_GREATER_EQUALS][LST_INTEGER][LST_FLOATINGPOINT] = LST_INTEGER;
  384. gSupportedExpressionArray[LET_GREATER_EQUALS][LST_FLOATINGPOINT][LST_INTEGER] = LST_INTEGER;
  385. gSupportedExpressionArray[LET_GREATER_EQUALS][LST_FLOATINGPOINT][LST_FLOATINGPOINT] = LST_INTEGER;
  386. // LET_LESS_THAN
  387. gSupportedExpressionArray[LET_LESS_THAN][LST_INTEGER][LST_INTEGER] = LST_INTEGER;
  388. gSupportedExpressionArray[LET_LESS_THAN][LST_INTEGER][LST_FLOATINGPOINT] = LST_INTEGER;
  389. gSupportedExpressionArray[LET_LESS_THAN][LST_FLOATINGPOINT][LST_INTEGER] = LST_INTEGER;
  390. gSupportedExpressionArray[LET_LESS_THAN][LST_FLOATINGPOINT][LST_FLOATINGPOINT] = LST_INTEGER;
  391. // LET_GREATER_THAN
  392. gSupportedExpressionArray[LET_GREATER_THAN][LST_INTEGER][LST_INTEGER] = LST_INTEGER;
  393. gSupportedExpressionArray[LET_GREATER_THAN][LST_INTEGER][LST_FLOATINGPOINT] = LST_INTEGER;
  394. gSupportedExpressionArray[LET_GREATER_THAN][LST_FLOATINGPOINT][LST_INTEGER] = LST_INTEGER;
  395. gSupportedExpressionArray[LET_GREATER_THAN][LST_FLOATINGPOINT][LST_FLOATINGPOINT] = LST_INTEGER;
  396. // LET_PLUS
  397. gSupportedExpressionArray[LET_PLUS][LST_INTEGER][LST_INTEGER] = LST_INTEGER;
  398. gSupportedExpressionArray[LET_PLUS][LST_FLOATINGPOINT][LST_INTEGER] = LST_FLOATINGPOINT;
  399. gSupportedExpressionArray[LET_PLUS][LST_INTEGER][LST_FLOATINGPOINT] = LST_FLOATINGPOINT;
  400. gSupportedExpressionArray[LET_PLUS][LST_FLOATINGPOINT][LST_FLOATINGPOINT] = LST_FLOATINGPOINT;
  401. gSupportedExpressionArray[LET_PLUS][LST_STRING][LST_STRING] = LST_STRING;
  402. gSupportedExpressionArray[LET_PLUS][LST_VECTOR][LST_VECTOR] = LST_VECTOR;
  403. gSupportedExpressionArray[LET_PLUS][LST_QUATERNION][LST_QUATERNION] = LST_QUATERNION;
  404. gSupportedExpressionArray[LET_PLUS][LST_LIST][LST_INTEGER] = LST_LIST;
  405. gSupportedExpressionArray[LET_PLUS][LST_LIST][LST_FLOATINGPOINT] = LST_LIST;
  406. gSupportedExpressionArray[LET_PLUS][LST_LIST][LST_STRING] = LST_LIST;
  407. gSupportedExpressionArray[LET_PLUS][LST_LIST][LST_KEY] = LST_LIST;
  408. gSupportedExpressionArray[LET_PLUS][LST_LIST][LST_VECTOR] = LST_LIST;
  409. gSupportedExpressionArray[LET_PLUS][LST_LIST][LST_QUATERNION] = LST_LIST;
  410. gSupportedExpressionArray[LET_PLUS][LST_INTEGER][LST_LIST] = LST_LIST;
  411. gSupportedExpressionArray[LET_PLUS][LST_FLOATINGPOINT][LST_LIST] = LST_LIST;
  412. gSupportedExpressionArray[LET_PLUS][LST_STRING][LST_LIST] = LST_LIST;
  413. gSupportedExpressionArray[LET_PLUS][LST_KEY][LST_LIST] = LST_LIST;
  414. gSupportedExpressionArray[LET_PLUS][LST_VECTOR][LST_LIST] = LST_LIST;
  415. gSupportedExpressionArray[LET_PLUS][LST_QUATERNION][LST_LIST] = LST_LIST;
  416. gSupportedExpressionArray[LET_PLUS][LST_LIST][LST_LIST] = LST_LIST;
  417. // LET_MINUS
  418. gSupportedExpressionArray[LET_MINUS][LST_INTEGER][LST_INTEGER] = LST_INTEGER;
  419. gSupportedExpressionArray[LET_MINUS][LST_FLOATINGPOINT][LST_INTEGER] = LST_FLOATINGPOINT;
  420. gSupportedExpressionArray[LET_MINUS][LST_INTEGER][LST_FLOATINGPOINT] = LST_FLOATINGPOINT;
  421. gSupportedExpressionArray[LET_MINUS][LST_FLOATINGPOINT][LST_FLOATINGPOINT] = LST_FLOATINGPOINT;
  422. gSupportedExpressionArray[LET_MINUS][LST_VECTOR][LST_VECTOR] = LST_VECTOR;
  423. gSupportedExpressionArray[LET_MINUS][LST_QUATERNION][LST_QUATERNION] = LST_QUATERNION;
  424. // LET_TIMES
  425. gSupportedExpressionArray[LET_TIMES][LST_INTEGER][LST_INTEGER] = LST_INTEGER;
  426. gSupportedExpressionArray[LET_TIMES][LST_FLOATINGPOINT][LST_INTEGER] = LST_FLOATINGPOINT;
  427. gSupportedExpressionArray[LET_TIMES][LST_INTEGER][LST_FLOATINGPOINT] = LST_FLOATINGPOINT;
  428. gSupportedExpressionArray[LET_TIMES][LST_FLOATINGPOINT][LST_FLOATINGPOINT] = LST_FLOATINGPOINT;
  429. gSupportedExpressionArray[LET_TIMES][LST_VECTOR][LST_INTEGER] = LST_VECTOR;
  430. gSupportedExpressionArray[LET_TIMES][LST_INTEGER][LST_VECTOR] = LST_VECTOR;
  431. gSupportedExpressionArray[LET_TIMES][LST_VECTOR][LST_FLOATINGPOINT] = LST_VECTOR;
  432. gSupportedExpressionArray[LET_TIMES][LST_FLOATINGPOINT][LST_VECTOR] = LST_VECTOR;
  433. gSupportedExpressionArray[LET_TIMES][LST_VECTOR][LST_VECTOR] = LST_FLOATINGPOINT;
  434. gSupportedExpressionArray[LET_TIMES][LST_VECTOR][LST_QUATERNION] = LST_VECTOR;
  435. gSupportedExpressionArray[LET_TIMES][LST_QUATERNION][LST_QUATERNION] = LST_QUATERNION;
  436. // LET_DIVIDE
  437. gSupportedExpressionArray[LET_DIVIDE][LST_INTEGER][LST_INTEGER] = LST_INTEGER;
  438. gSupportedExpressionArray[LET_DIVIDE][LST_INTEGER][LST_FLOATINGPOINT] = LST_FLOATINGPOINT;
  439. gSupportedExpressionArray[LET_DIVIDE][LST_FLOATINGPOINT][LST_INTEGER] = LST_FLOATINGPOINT;
  440. gSupportedExpressionArray[LET_DIVIDE][LST_FLOATINGPOINT][LST_FLOATINGPOINT] = LST_FLOATINGPOINT;
  441. gSupportedExpressionArray[LET_DIVIDE][LST_VECTOR][LST_INTEGER] = LST_VECTOR;
  442. gSupportedExpressionArray[LET_DIVIDE][LST_VECTOR][LST_FLOATINGPOINT] = LST_VECTOR;
  443. gSupportedExpressionArray[LET_DIVIDE][LST_VECTOR][LST_QUATERNION] = LST_VECTOR;
  444. gSupportedExpressionArray[LET_DIVIDE][LST_QUATERNION][LST_QUATERNION] = LST_QUATERNION;
  445. // LET_MOD
  446. gSupportedExpressionArray[LET_MOD][LST_INTEGER][LST_INTEGER] = LST_INTEGER;
  447. gSupportedExpressionArray[LET_MOD][LST_VECTOR][LST_VECTOR] = LST_VECTOR;
  448. // LET_BIT_AND
  449. gSupportedExpressionArray[LET_BIT_AND][LST_INTEGER][LST_INTEGER] = LST_INTEGER;
  450. // LET_BIT_OR
  451. gSupportedExpressionArray[LET_BIT_OR][LST_INTEGER][LST_INTEGER] = LST_INTEGER;
  452. // LET_BIT_XOR
  453. gSupportedExpressionArray[LET_BIT_XOR][LST_INTEGER][LST_INTEGER] = LST_INTEGER;
  454. // LET_BOOLEAN_AND
  455. gSupportedExpressionArray[LET_BOOLEAN_AND][LST_INTEGER][LST_INTEGER] = LST_INTEGER;
  456. // LET_BOOLEAN_OR
  457. gSupportedExpressionArray[LET_BOOLEAN_OR][LST_INTEGER][LST_INTEGER] = LST_INTEGER;
  458. // LET_SHIFT_LEFT
  459. gSupportedExpressionArray[LET_SHIFT_LEFT][LST_INTEGER][LST_INTEGER] = LST_INTEGER;
  460. // LET_SHIFT_RIGHT
  461. gSupportedExpressionArray[LET_SHIFT_RIGHT][LST_INTEGER][LST_INTEGER] = LST_INTEGER;
  462. // LET_PARENTHESIS
  463. gSupportedExpressionArray[LET_PARENTHESIS][LST_INTEGER][LST_NULL] = LST_INTEGER;
  464. gSupportedExpressionArray[LET_PARENTHESIS][LST_FLOATINGPOINT][LST_NULL] = LST_INTEGER;
  465. gSupportedExpressionArray[LET_PARENTHESIS][LST_STRING][LST_NULL] = LST_INTEGER;
  466. gSupportedExpressionArray[LET_PARENTHESIS][LST_LIST][LST_NULL] = LST_INTEGER;
  467. // LET_UNARY_MINUS
  468. gSupportedExpressionArray[LET_UNARY_MINUS][LST_INTEGER][LST_NULL] = LST_INTEGER;
  469. gSupportedExpressionArray[LET_UNARY_MINUS][LST_FLOATINGPOINT][LST_NULL] = LST_FLOATINGPOINT;
  470. gSupportedExpressionArray[LET_UNARY_MINUS][LST_VECTOR][LST_NULL] = LST_VECTOR;
  471. gSupportedExpressionArray[LET_UNARY_MINUS][LST_QUATERNION][LST_NULL] = LST_QUATERNION;
  472. // LET_BOOLEAN_NOT
  473. gSupportedExpressionArray[LET_BOOLEAN_NOT][LST_INTEGER][LST_NULL] = LST_INTEGER;
  474. // LET_BIT_NOT
  475. gSupportedExpressionArray[LET_BIT_NOT][LST_INTEGER][LST_NULL] = LST_INTEGER;
  476. // LET_PRE_INCREMENT
  477. gSupportedExpressionArray[LET_PRE_INCREMENT][LST_INTEGER][LST_NULL] = LST_INTEGER;
  478. gSupportedExpressionArray[LET_PRE_INCREMENT][LST_FLOATINGPOINT][LST_NULL] = LST_FLOATINGPOINT;
  479. // LET_PRE_DECREMENT
  480. gSupportedExpressionArray[LET_PRE_DECREMENT][LST_INTEGER][LST_NULL] = LST_INTEGER;
  481. gSupportedExpressionArray[LET_PRE_DECREMENT][LST_FLOATINGPOINT][LST_NULL] = LST_FLOATINGPOINT;
  482. // LET_POST_INCREMENT
  483. gSupportedExpressionArray[LET_POST_INCREMENT][LST_INTEGER][LST_NULL] = LST_INTEGER;
  484. gSupportedExpressionArray[LET_POST_INCREMENT][LST_FLOATINGPOINT][LST_NULL] = LST_FLOATINGPOINT;
  485. // LET_POST_DECREMENT
  486. gSupportedExpressionArray[LET_POST_DECREMENT][LST_INTEGER][LST_NULL] = LST_INTEGER;
  487. gSupportedExpressionArray[LET_POST_DECREMENT][LST_FLOATINGPOINT][LST_NULL] = LST_FLOATINGPOINT;
  488. }
  489. BOOL legal_binary_expression(LSCRIPTType &result, LSCRIPTType left_side, LSCRIPTType right_side, LSCRIPTExpressionType expression)
  490. {
  491. if ( (left_side == LST_UNDEFINED)
  492. ||(right_side == LST_UNDEFINED))
  493. {
  494. result = LST_UNDEFINED;
  495. return TRUE;
  496. }
  497. if ( (left_side == LST_NULL)
  498. ||(right_side == LST_NULL))
  499. {
  500. result = LST_UNDEFINED;
  501. return FALSE;
  502. }
  503. result = gSupportedExpressionArray[expression][left_side][right_side];
  504. if (result)
  505. return TRUE;
  506. else
  507. {
  508. result = LST_UNDEFINED;
  509. return FALSE;
  510. }
  511. }
  512. BOOL legal_unary_expression(LSCRIPTType &result, LSCRIPTType left_side, LSCRIPTExpressionType expression)
  513. {
  514. if (left_side == LST_UNDEFINED)
  515. {
  516. result = LST_UNDEFINED;
  517. return TRUE;
  518. }
  519. if (left_side == LST_NULL)
  520. {
  521. result = LST_UNDEFINED;
  522. return FALSE;
  523. }
  524. result = gSupportedExpressionArray[expression][left_side][LST_NULL];
  525. if (result)
  526. return TRUE;
  527. else
  528. {
  529. result = LST_UNDEFINED;
  530. return FALSE;
  531. }
  532. }