lscript_typecheck.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:21k
源码类别:

游戏引擎

开发平台:

C++ Builder

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