shader-parser.c 17 KB

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