shader-parser.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  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;
  236. new_val = token_is(&sp->cfp, keyword);
  237. if (new_val) {
  238. if (!next_valid_token(&sp->cfp))
  239. return PARSE_EOF;
  240. if (new_val && *val)
  241. cf_adderror(&sp->cfp, "'$1' keyword already specified",
  242. LEVEL_WARNING, keyword, NULL, NULL);
  243. *val = new_val;
  244. return PARSE_CONTINUE;
  245. }
  246. return PARSE_SUCCESS;
  247. }
  248. static inline int sp_parse_func_param(struct shader_parser *sp,
  249. struct shader_func *func, struct shader_var *var)
  250. {
  251. int errcode;
  252. bool is_uniform;
  253. if (!next_valid_token(&sp->cfp))
  254. return PARSE_EOF;
  255. errcode = sp_check_for_keyword(sp, "uniform", &is_uniform);
  256. if (errcode == PARSE_EOF)
  257. return PARSE_EOF;
  258. var->var_type = is_uniform ? SHADER_VAR_UNIFORM : SHADER_VAR_NONE;
  259. errcode = get_name(&sp->cfp, &var->type, "type", ")");
  260. if (errcode != PARSE_SUCCESS)
  261. return errcode;
  262. errcode = next_name(&sp->cfp, &var->name, "name", ")");
  263. if (errcode != PARSE_SUCCESS)
  264. return errcode;
  265. if (!next_valid_token(&sp->cfp))
  266. return PARSE_EOF;
  267. if (token_is(&sp->cfp, ":")) {
  268. errcode = next_name(&sp->cfp, &var->mapping,
  269. "mapping specifier", ")");
  270. if (errcode != PARSE_SUCCESS)
  271. return errcode;
  272. if (!next_valid_token(&sp->cfp))
  273. return PARSE_EOF;
  274. }
  275. return PARSE_SUCCESS;
  276. }
  277. static bool sp_parse_func_params(struct shader_parser *sp,
  278. struct shader_func *func)
  279. {
  280. struct cf_token peek;
  281. int errcode;
  282. cf_token_clear(&peek);
  283. if (!peek_valid_token(&sp->cfp, &peek))
  284. return false;
  285. if (*peek.str.array == ')') {
  286. next_token(&sp->cfp);
  287. goto exit;
  288. }
  289. do {
  290. struct shader_var var;
  291. shader_var_init(&var);
  292. if (!token_is(&sp->cfp, "(") && !token_is(&sp->cfp, ","))
  293. cf_adderror_syntax_error(&sp->cfp);
  294. errcode = sp_parse_func_param(sp, func, &var);
  295. if (errcode != PARSE_SUCCESS) {
  296. shader_var_free(&var);
  297. if (errcode == PARSE_CONTINUE)
  298. goto exit;
  299. else if (errcode == PARSE_EOF)
  300. return false;
  301. }
  302. da_push_back(func->params, &var);
  303. } while (!token_is(&sp->cfp, ")"));
  304. exit:
  305. return true;
  306. }
  307. static void sp_parse_function(struct shader_parser *sp, char *type, char *name)
  308. {
  309. struct shader_func func;
  310. shader_func_init(&func, type, name);
  311. if (!sp_parse_func_params(sp, &func))
  312. goto error;
  313. if (!next_valid_token(&sp->cfp))
  314. goto error;
  315. /* if function is mapped to something, for example COLOR */
  316. if (token_is(&sp->cfp, ":")) {
  317. char *mapping = NULL;
  318. int errorcode = next_name(&sp->cfp, &mapping, "mapping", "{");
  319. if (errorcode != PARSE_SUCCESS)
  320. goto error;
  321. func.return_mapping = mapping;
  322. if (!next_valid_token(&sp->cfp))
  323. goto error;
  324. }
  325. if (!token_is(&sp->cfp, "{")) {
  326. cf_adderror_expecting(&sp->cfp, "{");
  327. goto error;
  328. }
  329. func.start = sp->cfp.cur_token;
  330. if (!pass_pair(&sp->cfp, '{', '}'))
  331. goto error;
  332. /* it is established that the current token is '}' if we reach this */
  333. next_token(&sp->cfp);
  334. func.end = sp->cfp.cur_token;
  335. da_push_back(sp->funcs, &func);
  336. return;
  337. error:
  338. shader_func_free(&func);
  339. }
  340. /* parses "array[count]" */
  341. static bool sp_parse_param_array(struct shader_parser *sp,
  342. struct shader_var *param)
  343. {
  344. if (!next_valid_token(&sp->cfp))
  345. return false;
  346. if (sp->cfp.cur_token->type != CFTOKEN_NUM ||
  347. !valid_int_str(sp->cfp.cur_token->str.array,
  348. sp->cfp.cur_token->str.len))
  349. return false;
  350. param->array_count = strtol(sp->cfp.cur_token->str.array, NULL, 10);
  351. if (next_token_should_be(&sp->cfp, "]", ";", NULL) == PARSE_EOF)
  352. return false;
  353. if (!next_valid_token(&sp->cfp))
  354. return false;
  355. return true;
  356. }
  357. static inline int sp_parse_param_assign_intfloat(struct shader_parser *sp,
  358. struct shader_var *param, bool is_float)
  359. {
  360. int errcode;
  361. if (!next_valid_token(&sp->cfp))
  362. return PARSE_EOF;
  363. errcode = token_is_type(&sp->cfp, CFTOKEN_NUM, "numeric value", ";");
  364. if (errcode != PARSE_SUCCESS)
  365. return errcode;
  366. if (is_float) {
  367. float f = (float)strtod(sp->cfp.cur_token->str.array, NULL);
  368. da_push_back_array(param->default_val, &f, sizeof(float));
  369. } else {
  370. long l = strtol(sp->cfp.cur_token->str.array, NULL, 10);
  371. da_push_back_array(param->default_val, &l, sizeof(long));
  372. }
  373. return PARSE_SUCCESS;
  374. }
  375. /*
  376. * parses assignment for float1, float2, float3, float4, and any combination
  377. * for float3x3, float4x4, etc
  378. */
  379. static inline int sp_parse_param_assign_float_array(struct shader_parser *sp,
  380. struct shader_var *param)
  381. {
  382. const char *float_type = param->type+5;
  383. int float_count = 0, errcode, i;
  384. /* -------------------------------------------- */
  385. if (float_type[0] < '1' || float_type[0] > '4')
  386. cf_adderror(&sp->cfp, "Invalid row count", LEVEL_ERROR,
  387. NULL, NULL, NULL);
  388. float_count = float_type[0]-'0';
  389. if (float_type[1] == 'x') {
  390. if (float_type[2] < '1' || float_type[2] > '4')
  391. cf_adderror(&sp->cfp, "Invalid column count",
  392. LEVEL_ERROR, NULL, NULL, NULL);
  393. float_count *= float_type[2]-'0';
  394. }
  395. /* -------------------------------------------- */
  396. errcode = next_token_should_be(&sp->cfp, "{", ";", NULL);
  397. if (errcode != PARSE_SUCCESS) return errcode;
  398. for (i = 0; i < float_count; i++) {
  399. char *next = ((i+1) < float_count) ? "," : "}";
  400. errcode = sp_parse_param_assign_intfloat(sp, param, true);
  401. if (errcode != PARSE_SUCCESS) return errcode;
  402. errcode = next_token_should_be(&sp->cfp, next, ";", NULL);
  403. if (errcode != PARSE_SUCCESS) return errcode;
  404. }
  405. return PARSE_SUCCESS;
  406. }
  407. static int sp_parse_param_assignment_val(struct shader_parser *sp,
  408. struct shader_var *param)
  409. {
  410. if (strcmp(param->type, "int") == 0)
  411. return sp_parse_param_assign_intfloat(sp, param, false);
  412. else if (strcmp(param->type, "float") == 0)
  413. return sp_parse_param_assign_intfloat(sp, param, true);
  414. else if (astrcmp_n(param->type, "float", 5) == 0)
  415. return sp_parse_param_assign_float_array(sp, param);
  416. cf_adderror(&sp->cfp, "Invalid type '$1' used for assignment",
  417. LEVEL_ERROR, param->type, NULL, NULL);
  418. return PARSE_CONTINUE;
  419. }
  420. static inline bool sp_parse_param_assignment(struct shader_parser *sp,
  421. struct shader_var *param)
  422. {
  423. if (sp_parse_param_assignment_val(sp, param) != PARSE_SUCCESS)
  424. return false;
  425. if (!next_valid_token(&sp->cfp))
  426. return false;
  427. return true;
  428. }
  429. static void sp_parse_param(struct shader_parser *sp,
  430. char *type, char *name, bool is_const, bool is_uniform)
  431. {
  432. struct shader_var param;
  433. shader_var_init_param(&param, type, name, is_uniform, is_const);
  434. if (token_is(&sp->cfp, ";"))
  435. goto complete;
  436. if (token_is(&sp->cfp, "[") && !sp_parse_param_array(sp, &param))
  437. goto error;
  438. if (token_is(&sp->cfp, "=") && !sp_parse_param_assignment(sp, &param))
  439. goto error;
  440. if (!token_is(&sp->cfp, ";"))
  441. goto error;
  442. complete:
  443. da_push_back(sp->params, &param);
  444. return;
  445. error:
  446. shader_var_free(&param);
  447. }
  448. static bool sp_get_var_specifiers(struct shader_parser *sp,
  449. bool *is_const, bool *is_uniform)
  450. {
  451. while(true) {
  452. int errcode;
  453. errcode = sp_check_for_keyword(sp, "const", is_const);
  454. if (errcode == PARSE_EOF)
  455. return false;
  456. else if (errcode == PARSE_CONTINUE)
  457. continue;
  458. errcode = sp_check_for_keyword(sp, "uniform", is_uniform);
  459. if (errcode == PARSE_EOF)
  460. return false;
  461. else if (errcode == PARSE_CONTINUE)
  462. continue;
  463. break;
  464. }
  465. return true;
  466. }
  467. static inline void report_invalid_func_keyword(struct shader_parser *sp,
  468. const char *name, bool val)
  469. {
  470. if (val)
  471. cf_adderror(&sp->cfp, "'$1' keyword cannot be used with a "
  472. "function", LEVEL_ERROR,
  473. name, NULL, NULL);
  474. }
  475. static void sp_parse_other(struct shader_parser *sp)
  476. {
  477. bool is_const = false, is_uniform = false;
  478. char *type = NULL, *name = NULL;
  479. if (!sp_get_var_specifiers(sp, &is_const, &is_uniform))
  480. goto error;
  481. if (get_name(&sp->cfp, &type, "type", ";") != PARSE_SUCCESS)
  482. goto error;
  483. if (next_name(&sp->cfp, &name, "name", ";") != PARSE_SUCCESS)
  484. goto error;
  485. if (!next_valid_token(&sp->cfp))
  486. goto error;
  487. if (token_is(&sp->cfp, "(")) {
  488. report_invalid_func_keyword(sp, "const", is_const);
  489. report_invalid_func_keyword(sp, "uniform", is_uniform);
  490. sp_parse_function(sp, type, name);
  491. return;
  492. } else {
  493. sp_parse_param(sp, type, name, is_const, is_uniform);
  494. return;
  495. }
  496. error:
  497. bfree(type);
  498. bfree(name);
  499. }
  500. bool shader_parse(struct shader_parser *sp, const char *shader,
  501. const char *file)
  502. {
  503. if (!cf_parser_parse(&sp->cfp, shader, file))
  504. return false;
  505. while (sp->cfp.cur_token && sp->cfp.cur_token->type != CFTOKEN_NONE) {
  506. if (token_is(&sp->cfp, ";") ||
  507. is_whitespace(*sp->cfp.cur_token->str.array)) {
  508. sp->cfp.cur_token++;
  509. } else if (token_is(&sp->cfp, "struct")) {
  510. sp_parse_struct(sp);
  511. } else if (token_is(&sp->cfp, "sampler_state")) {
  512. sp_parse_sampler_state(sp);
  513. } else if (token_is(&sp->cfp, "{")) {
  514. cf_adderror(&sp->cfp, "Unexpected code segment",
  515. LEVEL_ERROR, NULL, NULL, NULL);
  516. pass_pair(&sp->cfp, '{', '}');
  517. } else {
  518. /* parameters and functions */
  519. sp_parse_other(sp);
  520. }
  521. }
  522. return !error_data_has_errors(&sp->cfp.error_list);
  523. }