shader-parser.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include "shader-parser.h"
  15. enum shader_param_type get_shader_param_type(const char *type)
  16. {
  17. if (strcmp(type, "float") == 0)
  18. return SHADER_PARAM_FLOAT;
  19. else if (strcmp(type, "float2") == 0)
  20. return SHADER_PARAM_VEC2;
  21. else if (strcmp(type, "float3") == 0)
  22. return SHADER_PARAM_VEC3;
  23. else if (strcmp(type, "float4") == 0)
  24. return SHADER_PARAM_VEC4;
  25. else if (astrcmp_n(type, "texture", 7) == 0)
  26. return SHADER_PARAM_TEXTURE;
  27. else if (strcmp(type, "float4x4") == 0)
  28. return SHADER_PARAM_MATRIX4X4;
  29. else if (strcmp(type, "bool") == 0)
  30. return SHADER_PARAM_BOOL;
  31. else if (strcmp(type, "int") == 0)
  32. return SHADER_PARAM_INT;
  33. else if (strcmp(type, "string") == 0)
  34. return SHADER_PARAM_STRING;
  35. return SHADER_PARAM_UNKNOWN;
  36. }
  37. enum gs_sample_filter get_sample_filter(const char *filter)
  38. {
  39. if (astrcmpi(filter, "Anisotropy") == 0)
  40. return GS_FILTER_ANISOTROPIC;
  41. else if (astrcmpi(filter, "Point") == 0 ||
  42. strcmp(filter, "MIN_MAG_MIP_POINT") == 0)
  43. return GS_FILTER_POINT;
  44. else if (astrcmpi(filter, "Linear") == 0 ||
  45. strcmp(filter, "MIN_MAG_MIP_LINEAR") == 0)
  46. return GS_FILTER_LINEAR;
  47. else if (strcmp(filter, "MIN_MAG_POINT_MIP_LINEAR") == 0)
  48. return GS_FILTER_MIN_MAG_POINT_MIP_LINEAR;
  49. else if (strcmp(filter, "MIN_POINT_MAG_LINEAR_MIP_POINT") == 0)
  50. return GS_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT;
  51. else if (strcmp(filter, "MIN_POINT_MAG_MIP_LINEAR") == 0)
  52. return GS_FILTER_MIN_POINT_MAG_MIP_LINEAR;
  53. else if (strcmp(filter, "MIN_LINEAR_MAG_MIP_POINT") == 0)
  54. return GS_FILTER_MIN_LINEAR_MAG_MIP_POINT;
  55. else if (strcmp(filter, "MIN_LINEAR_MAG_POINT_MIP_LINEAR") == 0)
  56. return GS_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR;
  57. else if (strcmp(filter, "MIN_MAG_LINEAR_MIP_POINT") == 0)
  58. return GS_FILTER_MIN_MAG_LINEAR_MIP_POINT;
  59. return GS_FILTER_LINEAR;
  60. }
  61. extern enum gs_address_mode get_address_mode(const char *mode)
  62. {
  63. if (astrcmpi(mode, "Wrap") == 0 || astrcmpi(mode, "Repeat") == 0)
  64. return GS_ADDRESS_WRAP;
  65. else if (astrcmpi(mode, "Clamp") == 0 || astrcmpi(mode, "None") == 0)
  66. return GS_ADDRESS_CLAMP;
  67. else if (astrcmpi(mode, "Mirror") == 0)
  68. return GS_ADDRESS_MIRROR;
  69. else if (astrcmpi(mode, "Border") == 0)
  70. return GS_ADDRESS_BORDER;
  71. else if (astrcmpi(mode, "MirrorOnce") == 0)
  72. return GS_ADDRESS_MIRRORONCE;
  73. return GS_ADDRESS_CLAMP;
  74. }
  75. void shader_sampler_convert(struct shader_sampler *ss,
  76. struct gs_sampler_info *info)
  77. {
  78. size_t i;
  79. memset(info, 0, sizeof(struct gs_sampler_info));
  80. for (i = 0; i < ss->states.num; i++) {
  81. const char *state = ss->states.array[i];
  82. const char *value = ss->values.array[i];
  83. if (astrcmpi(state, "Filter") == 0)
  84. info->filter = get_sample_filter(value);
  85. else if (astrcmpi(state, "AddressU") == 0)
  86. info->address_u = get_address_mode(value);
  87. else if (astrcmpi(state, "AddressV") == 0)
  88. info->address_v = get_address_mode(value);
  89. else if (astrcmpi(state, "AddressW") == 0)
  90. info->address_w = get_address_mode(value);
  91. else if (astrcmpi(state, "MaxAnisotropy") == 0)
  92. info->max_anisotropy = (int)strtol(value, NULL, 10);
  93. /*else if (astrcmpi(state, "BorderColor") == 0)
  94. // TODO */
  95. }
  96. }
  97. /* ------------------------------------------------------------------------- */
  98. static int sp_parse_sampler_state_item(struct shader_parser *sp,
  99. struct shader_sampler *ss)
  100. {
  101. int ret;
  102. char *state = NULL, *value = NULL;
  103. ret = next_name(&sp->cfp, &state, "state name", ";");
  104. if (ret != PARSE_SUCCESS) goto fail;
  105. ret = next_token_should_be(&sp->cfp, "=", ";", NULL);
  106. if (ret != PARSE_SUCCESS) goto fail;
  107. ret = next_name(&sp->cfp, &value, "value name", ";");
  108. if (ret != PARSE_SUCCESS) goto fail;
  109. ret = next_token_should_be(&sp->cfp, ";", ";", NULL);
  110. if (ret != PARSE_SUCCESS) goto fail;
  111. da_push_back(ss->states, &state);
  112. da_push_back(ss->values, &value);
  113. return ret;
  114. fail:
  115. bfree(state);
  116. bfree(value);
  117. return ret;
  118. }
  119. static void sp_parse_sampler_state(struct shader_parser *sp)
  120. {
  121. struct shader_sampler ss;
  122. struct cf_token peek;
  123. shader_sampler_init(&ss);
  124. if (next_name(&sp->cfp, &ss.name, "name", ";") != PARSE_SUCCESS)
  125. goto error;
  126. if (next_token_should_be(&sp->cfp, "{", ";", NULL) != PARSE_SUCCESS)
  127. goto error;
  128. if (!peek_valid_token(&sp->cfp, &peek))
  129. goto error;
  130. while (strref_cmp(&peek.str, "}") != 0) {
  131. int ret = sp_parse_sampler_state_item(sp, &ss);
  132. if (ret == PARSE_EOF)
  133. goto error;
  134. if (!peek_valid_token(&sp->cfp, &peek))
  135. goto error;
  136. }
  137. if (next_token_should_be(&sp->cfp, "}", ";", NULL) != PARSE_SUCCESS)
  138. goto error;
  139. if (next_token_should_be(&sp->cfp, ";", NULL, NULL) != PARSE_SUCCESS)
  140. goto error;
  141. da_push_back(sp->samplers, &ss);
  142. return;
  143. error:
  144. shader_sampler_free(&ss);
  145. }
  146. static inline int sp_parse_struct_var(struct shader_parser *sp,
  147. struct shader_var *var)
  148. {
  149. int errcode;
  150. /* -------------------------------------- */
  151. /* variable type */
  152. if (!next_valid_token(&sp->cfp)) return PARSE_EOF;
  153. if (token_is(&sp->cfp, ";")) return PARSE_CONTINUE;
  154. if (token_is(&sp->cfp, "}")) return PARSE_BREAK;
  155. errcode = token_is_type(&sp->cfp, CFTOKEN_NAME, "type name", ";");
  156. if (errcode != PARSE_SUCCESS)
  157. return errcode;
  158. copy_token(&sp->cfp, &var->type);
  159. /* -------------------------------------- */
  160. /* variable name */
  161. if (!next_valid_token(&sp->cfp)) return PARSE_EOF;
  162. if (token_is(&sp->cfp, ";")) return PARSE_UNEXPECTED_CONTINUE;
  163. if (token_is(&sp->cfp, "}")) return PARSE_UNEXPECTED_BREAK;
  164. errcode = token_is_type(&sp->cfp, CFTOKEN_NAME, "variable name", ";");
  165. if (errcode != PARSE_SUCCESS)
  166. return errcode;
  167. copy_token(&sp->cfp, &var->name);
  168. /* -------------------------------------- */
  169. /* variable mapping if any (POSITION, TEXCOORD, etc) */
  170. if (!next_valid_token(&sp->cfp)) return PARSE_EOF;
  171. if (token_is(&sp->cfp, ":")) {
  172. if (!next_valid_token(&sp->cfp)) return PARSE_EOF;
  173. if (token_is(&sp->cfp, ";")) return PARSE_UNEXPECTED_CONTINUE;
  174. if (token_is(&sp->cfp, "}")) return PARSE_UNEXPECTED_BREAK;
  175. errcode = token_is_type(&sp->cfp, CFTOKEN_NAME,
  176. "mapping name", ";");
  177. if (errcode != PARSE_SUCCESS)
  178. return errcode;
  179. copy_token(&sp->cfp, &var->mapping);
  180. if (!next_valid_token(&sp->cfp)) return PARSE_EOF;
  181. }
  182. /* -------------------------------------- */
  183. if (!token_is(&sp->cfp, ";")) {
  184. if (!go_to_valid_token(&sp->cfp, ";", "}"))
  185. return PARSE_EOF;
  186. return PARSE_CONTINUE;
  187. }
  188. return PARSE_SUCCESS;
  189. }
  190. static void sp_parse_struct(struct shader_parser *sp)
  191. {
  192. struct shader_struct ss;
  193. shader_struct_init(&ss);
  194. if (next_name(&sp->cfp, &ss.name, "name", ";") != PARSE_SUCCESS)
  195. goto error;
  196. if (next_token_should_be(&sp->cfp, "{", ";", NULL) != PARSE_SUCCESS)
  197. goto error;
  198. /* get structure variables */
  199. while (true) {
  200. bool do_break = false;
  201. struct shader_var var;
  202. shader_var_init(&var);
  203. switch (sp_parse_struct_var(sp, &var)) {
  204. case PARSE_UNEXPECTED_CONTINUE:
  205. cf_adderror_syntax_error(&sp->cfp);
  206. case PARSE_CONTINUE:
  207. shader_var_free(&var);
  208. continue;
  209. case PARSE_UNEXPECTED_BREAK:
  210. cf_adderror_syntax_error(&sp->cfp);
  211. case PARSE_BREAK:
  212. shader_var_free(&var);
  213. do_break = true;
  214. break;
  215. case PARSE_EOF:
  216. shader_var_free(&var);
  217. goto error;
  218. }
  219. if (do_break)
  220. break;
  221. da_push_back(ss.vars, &var);
  222. }
  223. if (next_token_should_be(&sp->cfp, ";", NULL, NULL) != PARSE_SUCCESS)
  224. goto error;
  225. da_push_back(sp->structs, &ss);
  226. return;
  227. error:
  228. shader_struct_free(&ss);
  229. }
  230. static inline int sp_check_for_keyword(struct shader_parser *sp,
  231. const char *keyword, bool *val)
  232. {
  233. bool new_val = token_is(&sp->cfp, keyword);
  234. if (new_val) {
  235. if (!next_valid_token(&sp->cfp))
  236. return PARSE_EOF;
  237. if (new_val && *val)
  238. cf_adderror(&sp->cfp, "'$1' keyword already specified",
  239. LEVEL_WARNING, keyword, NULL, NULL);
  240. *val = new_val;
  241. return PARSE_CONTINUE;
  242. }
  243. return PARSE_SUCCESS;
  244. }
  245. static inline int sp_parse_func_param(struct shader_parser *sp,
  246. struct shader_var *var)
  247. {
  248. int errcode;
  249. bool is_uniform = false;
  250. if (!next_valid_token(&sp->cfp))
  251. return PARSE_EOF;
  252. errcode = sp_check_for_keyword(sp, "uniform", &is_uniform);
  253. if (errcode == PARSE_EOF)
  254. return PARSE_EOF;
  255. var->var_type = is_uniform ? SHADER_VAR_UNIFORM : SHADER_VAR_NONE;
  256. errcode = get_name(&sp->cfp, &var->type, "type", ")");
  257. if (errcode != PARSE_SUCCESS)
  258. return errcode;
  259. errcode = next_name(&sp->cfp, &var->name, "name", ")");
  260. if (errcode != PARSE_SUCCESS)
  261. return errcode;
  262. if (!next_valid_token(&sp->cfp))
  263. return PARSE_EOF;
  264. if (token_is(&sp->cfp, ":")) {
  265. errcode = next_name(&sp->cfp, &var->mapping,
  266. "mapping specifier", ")");
  267. if (errcode != PARSE_SUCCESS)
  268. return errcode;
  269. if (!next_valid_token(&sp->cfp))
  270. return PARSE_EOF;
  271. }
  272. return PARSE_SUCCESS;
  273. }
  274. static bool sp_parse_func_params(struct shader_parser *sp,
  275. struct shader_func *func)
  276. {
  277. struct cf_token peek;
  278. int errcode;
  279. cf_token_clear(&peek);
  280. if (!peek_valid_token(&sp->cfp, &peek))
  281. return false;
  282. if (*peek.str.array == ')') {
  283. next_token(&sp->cfp);
  284. goto exit;
  285. }
  286. do {
  287. struct shader_var var;
  288. shader_var_init(&var);
  289. if (!token_is(&sp->cfp, "(") && !token_is(&sp->cfp, ","))
  290. cf_adderror_syntax_error(&sp->cfp);
  291. errcode = sp_parse_func_param(sp, &var);
  292. if (errcode != PARSE_SUCCESS) {
  293. shader_var_free(&var);
  294. if (errcode == PARSE_CONTINUE)
  295. goto exit;
  296. else if (errcode == PARSE_EOF)
  297. return false;
  298. }
  299. da_push_back(func->params, &var);
  300. } while (!token_is(&sp->cfp, ")"));
  301. exit:
  302. return true;
  303. }
  304. static void sp_parse_function(struct shader_parser *sp, char *type, char *name)
  305. {
  306. struct shader_func func;
  307. shader_func_init(&func, type, name);
  308. if (!sp_parse_func_params(sp, &func))
  309. goto error;
  310. if (!next_valid_token(&sp->cfp))
  311. goto error;
  312. /* if function is mapped to something, for example COLOR */
  313. if (token_is(&sp->cfp, ":")) {
  314. char *mapping = NULL;
  315. int errorcode = next_name(&sp->cfp, &mapping, "mapping", "{");
  316. if (errorcode != PARSE_SUCCESS)
  317. goto error;
  318. func.mapping = mapping;
  319. if (!next_valid_token(&sp->cfp))
  320. goto error;
  321. }
  322. if (!token_is(&sp->cfp, "{")) {
  323. cf_adderror_expecting(&sp->cfp, "{");
  324. goto error;
  325. }
  326. func.start = sp->cfp.cur_token;
  327. if (!pass_pair(&sp->cfp, '{', '}'))
  328. goto error;
  329. /* it is established that the current token is '}' if we reach this */
  330. next_token(&sp->cfp);
  331. func.end = sp->cfp.cur_token;
  332. da_push_back(sp->funcs, &func);
  333. return;
  334. error:
  335. shader_func_free(&func);
  336. }
  337. /* parses "array[count]" */
  338. static bool sp_parse_param_array(struct shader_parser *sp,
  339. struct shader_var *param)
  340. {
  341. if (!next_valid_token(&sp->cfp))
  342. return false;
  343. if (sp->cfp.cur_token->type != CFTOKEN_NUM ||
  344. !valid_int_str(sp->cfp.cur_token->str.array,
  345. sp->cfp.cur_token->str.len))
  346. return false;
  347. param->array_count =(int)strtol(sp->cfp.cur_token->str.array, NULL, 10);
  348. if (next_token_should_be(&sp->cfp, "]", ";", NULL) == PARSE_EOF)
  349. return false;
  350. if (!next_valid_token(&sp->cfp))
  351. return false;
  352. return true;
  353. }
  354. static inline int sp_parse_param_assign_intfloat(struct shader_parser *sp,
  355. struct shader_var *param, bool is_float)
  356. {
  357. int errcode;
  358. if (!next_valid_token(&sp->cfp))
  359. return PARSE_EOF;
  360. errcode = token_is_type(&sp->cfp, CFTOKEN_NUM, "numeric value", ";");
  361. if (errcode != PARSE_SUCCESS)
  362. return errcode;
  363. if (is_float) {
  364. float f = (float)strtod(sp->cfp.cur_token->str.array, NULL);
  365. da_push_back_array(param->default_val, &f, sizeof(float));
  366. } else {
  367. long l = strtol(sp->cfp.cur_token->str.array, NULL, 10);
  368. da_push_back_array(param->default_val, &l, sizeof(long));
  369. }
  370. return PARSE_SUCCESS;
  371. }
  372. /*
  373. * parses assignment for float1, float2, float3, float4, and any combination
  374. * for float3x3, float4x4, etc
  375. */
  376. static inline int sp_parse_param_assign_float_array(struct shader_parser *sp,
  377. struct shader_var *param)
  378. {
  379. const char *float_type = param->type+5;
  380. int float_count = 0, errcode, i;
  381. /* -------------------------------------------- */
  382. if (float_type[0] < '1' || float_type[0] > '4')
  383. cf_adderror(&sp->cfp, "Invalid row count", LEVEL_ERROR,
  384. NULL, NULL, NULL);
  385. float_count = float_type[0]-'0';
  386. if (float_type[1] == 'x') {
  387. if (float_type[2] < '1' || float_type[2] > '4')
  388. cf_adderror(&sp->cfp, "Invalid column count",
  389. LEVEL_ERROR, NULL, NULL, NULL);
  390. float_count *= float_type[2]-'0';
  391. }
  392. /* -------------------------------------------- */
  393. errcode = next_token_should_be(&sp->cfp, "{", ";", NULL);
  394. if (errcode != PARSE_SUCCESS) return errcode;
  395. for (i = 0; i < float_count; i++) {
  396. char *next = ((i+1) < float_count) ? "," : "}";
  397. errcode = sp_parse_param_assign_intfloat(sp, param, true);
  398. if (errcode != PARSE_SUCCESS) return errcode;
  399. errcode = next_token_should_be(&sp->cfp, next, ";", NULL);
  400. if (errcode != PARSE_SUCCESS) return errcode;
  401. }
  402. return PARSE_SUCCESS;
  403. }
  404. static int sp_parse_param_assignment_val(struct shader_parser *sp,
  405. struct shader_var *param)
  406. {
  407. if (strcmp(param->type, "int") == 0)
  408. return sp_parse_param_assign_intfloat(sp, param, false);
  409. else if (strcmp(param->type, "float") == 0)
  410. return sp_parse_param_assign_intfloat(sp, param, true);
  411. else if (astrcmp_n(param->type, "float", 5) == 0)
  412. return sp_parse_param_assign_float_array(sp, param);
  413. cf_adderror(&sp->cfp, "Invalid type '$1' used for assignment",
  414. LEVEL_ERROR, param->type, NULL, NULL);
  415. return PARSE_CONTINUE;
  416. }
  417. static inline bool sp_parse_param_assignment(struct shader_parser *sp,
  418. struct shader_var *param)
  419. {
  420. if (sp_parse_param_assignment_val(sp, param) != PARSE_SUCCESS)
  421. return false;
  422. if (!next_valid_token(&sp->cfp))
  423. return false;
  424. return true;
  425. }
  426. static void sp_parse_param(struct shader_parser *sp,
  427. char *type, char *name, bool is_const, bool is_uniform)
  428. {
  429. struct shader_var param;
  430. shader_var_init_param(&param, type, name, is_uniform, is_const);
  431. if (token_is(&sp->cfp, ";"))
  432. goto complete;
  433. if (token_is(&sp->cfp, "[") && !sp_parse_param_array(sp, &param))
  434. goto error;
  435. if (token_is(&sp->cfp, "=") && !sp_parse_param_assignment(sp, &param))
  436. goto error;
  437. if (!token_is(&sp->cfp, ";"))
  438. goto error;
  439. complete:
  440. da_push_back(sp->params, &param);
  441. return;
  442. error:
  443. shader_var_free(&param);
  444. }
  445. static bool sp_get_var_specifiers(struct shader_parser *sp,
  446. bool *is_const, bool *is_uniform)
  447. {
  448. while(true) {
  449. int errcode;
  450. errcode = sp_check_for_keyword(sp, "const", is_const);
  451. if (errcode == PARSE_EOF)
  452. return false;
  453. else if (errcode == PARSE_CONTINUE)
  454. continue;
  455. errcode = sp_check_for_keyword(sp, "uniform", is_uniform);
  456. if (errcode == PARSE_EOF)
  457. return false;
  458. else if (errcode == PARSE_CONTINUE)
  459. continue;
  460. break;
  461. }
  462. return true;
  463. }
  464. static inline void report_invalid_func_keyword(struct shader_parser *sp,
  465. const char *name, bool val)
  466. {
  467. if (val)
  468. cf_adderror(&sp->cfp, "'$1' keyword cannot be used with a "
  469. "function", LEVEL_ERROR,
  470. name, NULL, NULL);
  471. }
  472. static void sp_parse_other(struct shader_parser *sp)
  473. {
  474. bool is_const = false, is_uniform = false;
  475. char *type = NULL, *name = NULL;
  476. if (!sp_get_var_specifiers(sp, &is_const, &is_uniform))
  477. goto error;
  478. if (get_name(&sp->cfp, &type, "type", ";") != PARSE_SUCCESS)
  479. goto error;
  480. if (next_name(&sp->cfp, &name, "name", ";") != PARSE_SUCCESS)
  481. goto error;
  482. if (!next_valid_token(&sp->cfp))
  483. goto error;
  484. if (token_is(&sp->cfp, "(")) {
  485. report_invalid_func_keyword(sp, "const", is_const);
  486. report_invalid_func_keyword(sp, "uniform", is_uniform);
  487. sp_parse_function(sp, type, name);
  488. return;
  489. } else {
  490. sp_parse_param(sp, type, name, is_const, is_uniform);
  491. return;
  492. }
  493. error:
  494. bfree(type);
  495. bfree(name);
  496. }
  497. bool shader_parse(struct shader_parser *sp, const char *shader,
  498. const char *file)
  499. {
  500. if (!cf_parser_parse(&sp->cfp, shader, file))
  501. return false;
  502. while (sp->cfp.cur_token && sp->cfp.cur_token->type != CFTOKEN_NONE) {
  503. if (token_is(&sp->cfp, ";") ||
  504. is_whitespace(*sp->cfp.cur_token->str.array)) {
  505. sp->cfp.cur_token++;
  506. } else if (token_is(&sp->cfp, "struct")) {
  507. sp_parse_struct(sp);
  508. } else if (token_is(&sp->cfp, "sampler_state")) {
  509. sp_parse_sampler_state(sp);
  510. } else if (token_is(&sp->cfp, "{")) {
  511. cf_adderror(&sp->cfp, "Unexpected code segment",
  512. LEVEL_ERROR, NULL, NULL, NULL);
  513. pass_pair(&sp->cfp, '{', '}');
  514. } else {
  515. /* parameters and functions */
  516. sp_parse_other(sp);
  517. }
  518. }
  519. return !error_data_has_errors(&sp->cfp.error_list);
  520. }