1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
|
/******************************************************************************
Copyright (C) 2023 by Lain Bailey <lain@obsproject.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#include "../util/platform.h"
#include "shader-parser.h"
enum gs_shader_param_type get_shader_param_type(const char *type)
{
if (strcmp(type, "float") == 0)
return GS_SHADER_PARAM_FLOAT;
else if (strcmp(type, "float2") == 0)
return GS_SHADER_PARAM_VEC2;
else if (strcmp(type, "float3") == 0)
return GS_SHADER_PARAM_VEC3;
else if (strcmp(type, "float4") == 0)
return GS_SHADER_PARAM_VEC4;
else if (strcmp(type, "int2") == 0)
return GS_SHADER_PARAM_INT2;
else if (strcmp(type, "int3") == 0)
return GS_SHADER_PARAM_INT3;
else if (strcmp(type, "int4") == 0)
return GS_SHADER_PARAM_INT4;
else if (astrcmp_n(type, "texture", 7) == 0)
return GS_SHADER_PARAM_TEXTURE;
else if (strcmp(type, "float4x4") == 0)
return GS_SHADER_PARAM_MATRIX4X4;
else if (strcmp(type, "bool") == 0)
return GS_SHADER_PARAM_BOOL;
else if (strcmp(type, "int") == 0)
return GS_SHADER_PARAM_INT;
else if (strcmp(type, "string") == 0)
return GS_SHADER_PARAM_STRING;
return GS_SHADER_PARAM_UNKNOWN;
}
enum gs_sample_filter get_sample_filter(const char *filter)
{
if (astrcmpi(filter, "Anisotropy") == 0)
return GS_FILTER_ANISOTROPIC;
else if (astrcmpi(filter, "Point") == 0 ||
strcmp(filter, "MIN_MAG_MIP_POINT") == 0)
return GS_FILTER_POINT;
else if (astrcmpi(filter, "Linear") == 0 ||
strcmp(filter, "MIN_MAG_MIP_LINEAR") == 0)
return GS_FILTER_LINEAR;
else if (strcmp(filter, "MIN_MAG_POINT_MIP_LINEAR") == 0)
return GS_FILTER_MIN_MAG_POINT_MIP_LINEAR;
else if (strcmp(filter, "MIN_POINT_MAG_LINEAR_MIP_POINT") == 0)
return GS_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT;
else if (strcmp(filter, "MIN_POINT_MAG_MIP_LINEAR") == 0)
return GS_FILTER_MIN_POINT_MAG_MIP_LINEAR;
else if (strcmp(filter, "MIN_LINEAR_MAG_MIP_POINT") == 0)
return GS_FILTER_MIN_LINEAR_MAG_MIP_POINT;
else if (strcmp(filter, "MIN_LINEAR_MAG_POINT_MIP_LINEAR") == 0)
return GS_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR;
else if (strcmp(filter, "MIN_MAG_LINEAR_MIP_POINT") == 0)
return GS_FILTER_MIN_MAG_LINEAR_MIP_POINT;
return GS_FILTER_LINEAR;
}
extern enum gs_address_mode get_address_mode(const char *mode)
{
if (astrcmpi(mode, "Wrap") == 0 || astrcmpi(mode, "Repeat") == 0)
return GS_ADDRESS_WRAP;
else if (astrcmpi(mode, "Clamp") == 0 || astrcmpi(mode, "None") == 0)
return GS_ADDRESS_CLAMP;
else if (astrcmpi(mode, "Mirror") == 0)
return GS_ADDRESS_MIRROR;
else if (astrcmpi(mode, "Border") == 0)
return GS_ADDRESS_BORDER;
else if (astrcmpi(mode, "MirrorOnce") == 0)
return GS_ADDRESS_MIRRORONCE;
return GS_ADDRESS_CLAMP;
}
void shader_sampler_convert(struct shader_sampler *ss,
struct gs_sampler_info *info)
{
size_t i;
memset(info, 0, sizeof(struct gs_sampler_info));
info->max_anisotropy = 1;
for (i = 0; i < ss->states.num; i++) {
const char *state = ss->states.array[i];
const char *value = ss->values.array[i];
if (astrcmpi(state, "Filter") == 0)
info->filter = get_sample_filter(value);
else if (astrcmpi(state, "AddressU") == 0)
info->address_u = get_address_mode(value);
else if (astrcmpi(state, "AddressV") == 0)
info->address_v = get_address_mode(value);
else if (astrcmpi(state, "AddressW") == 0)
info->address_w = get_address_mode(value);
else if (astrcmpi(state, "MaxAnisotropy") == 0)
info->max_anisotropy = (int)strtol(value, NULL, 10);
else if (astrcmpi(state, "BorderColor") == 0)
info->border_color = strtol(value + 1, NULL, 16);
}
}
/* ------------------------------------------------------------------------- */
static int sp_parse_sampler_state_item(struct shader_parser *sp,
struct shader_sampler *ss)
{
int ret;
char *state = NULL, *value = NULL;
ret = cf_next_name(&sp->cfp, &state, "state name", ";");
if (ret != PARSE_SUCCESS)
goto fail;
ret = cf_next_token_should_be(&sp->cfp, "=", ";", NULL);
if (ret != PARSE_SUCCESS)
goto fail;
ret = cf_next_token_copy(&sp->cfp, &value);
if (ret != PARSE_SUCCESS)
goto fail;
ret = cf_next_token_should_be(&sp->cfp, ";", ";", NULL);
if (ret != PARSE_SUCCESS)
goto fail;
da_push_back(ss->states, &state);
da_push_back(ss->values, &value);
return ret;
fail:
bfree(state);
bfree(value);
return ret;
}
static void sp_parse_sampler_state(struct shader_parser *sp)
{
struct shader_sampler ss;
struct cf_token peek;
shader_sampler_init(&ss);
if (cf_next_name(&sp->cfp, &ss.name, "name", ";") != PARSE_SUCCESS)
goto error;
if (cf_next_token_should_be(&sp->cfp, "{", ";", NULL) != PARSE_SUCCESS)
goto error;
if (!cf_peek_valid_token(&sp->cfp, &peek))
goto error;
while (strref_cmp(&peek.str, "}") != 0) {
int ret = sp_parse_sampler_state_item(sp, &ss);
if (ret == PARSE_EOF)
goto error;
if (!cf_peek_valid_token(&sp->cfp, &peek))
goto error;
}
if (cf_next_token_should_be(&sp->cfp, "}", ";", NULL) != PARSE_SUCCESS)
goto error;
if (cf_next_token_should_be(&sp->cfp, ";", NULL, NULL) != PARSE_SUCCESS)
goto error;
da_push_back(sp->samplers, &ss);
return;
error:
shader_sampler_free(&ss);
}
static inline int sp_parse_struct_var(struct shader_parser *sp,
struct shader_var *var)
{
int code;
/* -------------------------------------- */
/* variable type */
if (!cf_next_valid_token(&sp->cfp))
return PARSE_EOF;
if (cf_token_is(&sp->cfp, ";"))
return PARSE_CONTINUE;
if (cf_token_is(&sp->cfp, "}"))
return PARSE_BREAK;
code = cf_token_is_type(&sp->cfp, CFTOKEN_NAME, "type name", ";");
if (code != PARSE_SUCCESS)
return code;
cf_copy_token(&sp->cfp, &var->type);
/* -------------------------------------- */
/* variable name */
if (!cf_next_valid_token(&sp->cfp))
return PARSE_EOF;
if (cf_token_is(&sp->cfp, ";"))
return PARSE_UNEXPECTED_CONTINUE;
if (cf_token_is(&sp->cfp, "}"))
return PARSE_UNEXPECTED_BREAK;
code = cf_token_is_type(&sp->cfp, CFTOKEN_NAME, "variable name", ";");
if (code != PARSE_SUCCESS)
return code;
cf_copy_token(&sp->cfp, &var->name);
/* -------------------------------------- */
/* variable mapping if any (POSITION, TEXCOORD, etc) */
if (!cf_next_valid_token(&sp->cfp))
return PARSE_EOF;
if (cf_token_is(&sp->cfp, ":")) {
if (!cf_next_valid_token(&sp->cfp))
return PARSE_EOF;
if (cf_token_is(&sp->cfp, ";"))
return PARSE_UNEXPECTED_CONTINUE;
if (cf_token_is(&sp->cfp, "}"))
return PARSE_UNEXPECTED_BREAK;
code = cf_token_is_type(&sp->cfp, CFTOKEN_NAME, "mapping name",
";");
if (code != PARSE_SUCCESS)
return code;
cf_copy_token(&sp->cfp, &var->mapping);
if (!cf_next_valid_token(&sp->cfp))
return PARSE_EOF;
}
/* -------------------------------------- */
if (!cf_token_is(&sp->cfp, ";")) {
if (!cf_go_to_valid_token(&sp->cfp, ";", "}"))
return PARSE_EOF;
return PARSE_CONTINUE;
}
return PARSE_SUCCESS;
}
static void sp_parse_struct(struct shader_parser *sp)
{
struct shader_struct ss;
shader_struct_init(&ss);
if (cf_next_name(&sp->cfp, &ss.name, "name", ";") != PARSE_SUCCESS)
goto error;
if (cf_next_token_should_be(&sp->cfp, "{", ";", NULL) != PARSE_SUCCESS)
goto error;
/* get structure variables */
while (true) {
bool do_break = false;
struct shader_var var;
shader_var_init(&var);
switch (sp_parse_struct_var(sp, &var)) {
case PARSE_UNEXPECTED_CONTINUE:
cf_adderror_syntax_error(&sp->cfp);
/* Falls through. */
case PARSE_CONTINUE:
shader_var_free(&var);
continue;
case PARSE_UNEXPECTED_BREAK:
cf_adderror_syntax_error(&sp->cfp);
/* Falls through. */
case PARSE_BREAK:
shader_var_free(&var);
do_break = true;
break;
case PARSE_EOF:
shader_var_free(&var);
goto error;
}
if (do_break)
break;
da_push_back(ss.vars, &var);
}
if (cf_next_token_should_be(&sp->cfp, ";", NULL, NULL) != PARSE_SUCCESS)
goto error;
da_push_back(sp->structs, &ss);
return;
error:
shader_struct_free(&ss);
}
static inline int sp_check_for_keyword(struct shader_parser *sp,
const char *keyword, bool *val)
{
bool new_val = cf_token_is(&sp->cfp, keyword);
if (new_val) {
if (!cf_next_valid_token(&sp->cfp))
return PARSE_EOF;
if (new_val && *val)
cf_adderror(&sp->cfp, "'$1' keyword already specified",
LEX_WARNING, keyword, NULL, NULL);
*val = new_val;
return PARSE_CONTINUE;
}
return PARSE_SUCCESS;
}
static inline int sp_parse_func_param(struct shader_parser *sp,
struct shader_var *var)
{
int code;
bool var_type_keyword = false;
if (!cf_next_valid_token(&sp->cfp))
return PARSE_EOF;
code = sp_check_for_keyword(sp, "in", &var_type_keyword);
if (code == PARSE_EOF)
return PARSE_EOF;
else if (var_type_keyword)
var->var_type = SHADER_VAR_IN;
if (!var_type_keyword) {
code = sp_check_for_keyword(sp, "inout", &var_type_keyword);
if (code == PARSE_EOF)
return PARSE_EOF;
else if (var_type_keyword)
var->var_type = SHADER_VAR_INOUT;
}
if (!var_type_keyword) {
code = sp_check_for_keyword(sp, "out", &var_type_keyword);
if (code == PARSE_EOF)
return PARSE_EOF;
else if (var_type_keyword)
var->var_type = SHADER_VAR_OUT;
}
if (!var_type_keyword) {
code = sp_check_for_keyword(sp, "uniform", &var_type_keyword);
if (code == PARSE_EOF)
return PARSE_EOF;
else if (var_type_keyword)
var->var_type = SHADER_VAR_UNIFORM;
}
code = cf_get_name(&sp->cfp, &var->type, "type", ")");
if (code != PARSE_SUCCESS)
return code;
code = cf_next_name(&sp->cfp, &var->name, "name", ")");
if (code != PARSE_SUCCESS)
return code;
if (!cf_next_valid_token(&sp->cfp))
return PARSE_EOF;
if (cf_token_is(&sp->cfp, ":")) {
code = cf_next_name(&sp->cfp, &var->mapping,
"mapping specifier", ")");
if (code != PARSE_SUCCESS)
return code;
if (!cf_next_valid_token(&sp->cfp))
return PARSE_EOF;
}
return PARSE_SUCCESS;
}
static bool sp_parse_func_params(struct shader_parser *sp,
struct shader_func *func)
{
struct cf_token peek;
int code;
cf_token_clear(&peek);
if (!cf_peek_valid_token(&sp->cfp, &peek))
return false;
if (*peek.str.array == ')') {
cf_next_token(&sp->cfp);
goto exit;
}
do {
struct shader_var var;
shader_var_init(&var);
if (!cf_token_is(&sp->cfp, "(") && !cf_token_is(&sp->cfp, ","))
cf_adderror_syntax_error(&sp->cfp);
code = sp_parse_func_param(sp, &var);
if (code != PARSE_SUCCESS) {
shader_var_free(&var);
if (code == PARSE_CONTINUE)
goto exit;
else if (code == PARSE_EOF)
return false;
}
da_push_back(func->params, &var);
} while (!cf_token_is(&sp->cfp, ")"));
exit:
return true;
}
static void sp_parse_function(struct shader_parser *sp, char *type, char *name)
{
struct shader_func func;
shader_func_init(&func, type, name);
if (!sp_parse_func_params(sp, &func))
goto error;
if (!cf_next_valid_token(&sp->cfp))
goto error;
/* if function is mapped to something, for example COLOR */
if (cf_token_is(&sp->cfp, ":")) {
char *mapping = NULL;
int errorcode =
cf_next_name(&sp->cfp, &mapping, "mapping", "{");
if (errorcode != PARSE_SUCCESS)
goto error;
func.mapping = mapping;
if (!cf_next_valid_token(&sp->cfp))
goto error;
}
if (!cf_token_is(&sp->cfp, "{")) {
cf_adderror_expecting(&sp->cfp, "{");
goto error;
}
func.start = sp->cfp.cur_token;
if (!cf_pass_pair(&sp->cfp, '{', '}'))
goto error;
/* it is established that the current token is '}' if we reach this */
cf_next_token(&sp->cfp);
func.end = sp->cfp.cur_token;
da_push_back(sp->funcs, &func);
return;
error:
shader_func_free(&func);
}
/* parses "array[count]" */
static bool sp_parse_param_array(struct shader_parser *sp,
struct shader_var *param)
{
if (!cf_next_valid_token(&sp->cfp))
return false;
if (sp->cfp.cur_token->type != CFTOKEN_NUM ||
!valid_int_str(sp->cfp.cur_token->str.array,
sp->cfp.cur_token->str.len))
return false;
param->array_count =
(int)strtol(sp->cfp.cur_token->str.array, NULL, 10);
if (cf_next_token_should_be(&sp->cfp, "]", ";", NULL) == PARSE_EOF)
return false;
if (!cf_next_valid_token(&sp->cfp))
return false;
return true;
}
static inline int sp_parse_param_assign_intfloat(struct shader_parser *sp,
struct shader_var *param,
bool is_float)
{
int code;
bool is_negative = false;
if (!cf_next_valid_token(&sp->cfp))
return PARSE_EOF;
if (cf_token_is(&sp->cfp, "-")) {
is_negative = true;
if (!cf_next_token(&sp->cfp))
return PARSE_EOF;
}
code = cf_token_is_type(&sp->cfp, CFTOKEN_NUM, "numeric value", ";");
if (code != PARSE_SUCCESS)
return code;
if (is_float) {
float f = (float)os_strtod(sp->cfp.cur_token->str.array);
if (is_negative)
f = -f;
da_push_back_array(param->default_val, (uint8_t *)&f,
sizeof(float));
} else {
long l = strtol(sp->cfp.cur_token->str.array, NULL, 10);
if (is_negative)
l = -l;
da_push_back_array(param->default_val, (uint8_t *)&l,
sizeof(long));
}
return PARSE_SUCCESS;
}
/*
* parses assignment for float1, float2, float3, float4, and any combination
* for float3x3, float4x4, etc
*/
static inline int sp_parse_param_assign_float_array(struct shader_parser *sp,
struct shader_var *param)
{
const char *float_type = param->type + 5;
int float_count = 0, code, i;
/* -------------------------------------------- */
if (float_type[0] < '1' || float_type[0] > '4')
cf_adderror(&sp->cfp, "Invalid row count", LEX_ERROR, NULL,
NULL, NULL);
float_count = float_type[0] - '0';
if (float_type[1] == 'x') {
if (float_type[2] < '1' || float_type[2] > '4')
cf_adderror(&sp->cfp, "Invalid column count", LEX_ERROR,
NULL, NULL, NULL);
float_count *= float_type[2] - '0';
}
/* -------------------------------------------- */
code = cf_next_token_should_be(&sp->cfp, "{", ";", NULL);
if (code != PARSE_SUCCESS)
return code;
for (i = 0; i < float_count; i++) {
char *next = ((i + 1) < float_count) ? "," : "}";
code = sp_parse_param_assign_intfloat(sp, param, true);
if (code != PARSE_SUCCESS)
return code;
code = cf_next_token_should_be(&sp->cfp, next, ";", NULL);
if (code != PARSE_SUCCESS)
return code;
}
return PARSE_SUCCESS;
}
static int sp_parse_param_assignment_val(struct shader_parser *sp,
struct shader_var *param)
{
if (strcmp(param->type, "int") == 0)
return sp_parse_param_assign_intfloat(sp, param, false);
else if (strcmp(param->type, "float") == 0)
return sp_parse_param_assign_intfloat(sp, param, true);
else if (astrcmp_n(param->type, "float", 5) == 0)
return sp_parse_param_assign_float_array(sp, param);
cf_adderror(&sp->cfp, "Invalid type '$1' used for assignment",
LEX_ERROR, param->type, NULL, NULL);
return PARSE_CONTINUE;
}
static inline bool sp_parse_param_assign(struct shader_parser *sp,
struct shader_var *param)
{
if (sp_parse_param_assignment_val(sp, param) != PARSE_SUCCESS)
return false;
if (!cf_next_valid_token(&sp->cfp))
return false;
return true;
}
static void sp_parse_param(struct shader_parser *sp, char *type, char *name,
bool is_const, bool is_uniform)
{
struct shader_var param;
shader_var_init_param(¶m, type, name, is_uniform, is_const);
if (cf_token_is(&sp->cfp, ";"))
goto complete;
if (cf_token_is(&sp->cfp, "[") && !sp_parse_param_array(sp, ¶m))
goto error;
if (cf_token_is(&sp->cfp, "=") && !sp_parse_param_assign(sp, ¶m))
goto error;
if (!cf_token_is(&sp->cfp, ";"))
goto error;
complete:
da_push_back(sp->params, ¶m);
return;
error:
shader_var_free(¶m);
}
static bool sp_get_var_specifiers(struct shader_parser *sp, bool *is_const,
bool *is_uniform)
{
while (true) {
int code = sp_check_for_keyword(sp, "const", is_const);
if (code == PARSE_EOF)
return false;
else if (code == PARSE_CONTINUE)
continue;
code = sp_check_for_keyword(sp, "uniform", is_uniform);
if (code == PARSE_EOF)
return false;
else if (code == PARSE_CONTINUE)
continue;
break;
}
return true;
}
static inline void report_invalid_func_keyword(struct shader_parser *sp,
const char *name, bool val)
{
if (val)
cf_adderror(&sp->cfp,
"'$1' keyword cannot be used with a "
"function",
LEX_ERROR, name, NULL, NULL);
}
static void sp_parse_other(struct shader_parser *sp)
{
bool is_const = false, is_uniform = false;
char *type = NULL, *name = NULL;
if (!sp_get_var_specifiers(sp, &is_const, &is_uniform))
goto error;
if (cf_get_name(&sp->cfp, &type, "type", ";") != PARSE_SUCCESS)
goto error;
if (cf_next_name(&sp->cfp, &name, "name", ";") != PARSE_SUCCESS)
goto error;
if (!cf_next_valid_token(&sp->cfp))
goto error;
if (cf_token_is(&sp->cfp, "(")) {
report_invalid_func_keyword(sp, "const", is_const);
report_invalid_func_keyword(sp, "uniform", is_uniform);
sp_parse_function(sp, type, name);
return;
} else {
sp_parse_param(sp, type, name, is_const, is_uniform);
return;
}
error:
bfree(type);
bfree(name);
}
bool shader_parse(struct shader_parser *sp, const char *shader,
const char *file)
{
if (!cf_parser_parse(&sp->cfp, shader, file))
return false;
while (sp->cfp.cur_token && sp->cfp.cur_token->type != CFTOKEN_NONE) {
if (cf_token_is(&sp->cfp, ";") ||
is_whitespace(*sp->cfp.cur_token->str.array)) {
sp->cfp.cur_token++;
} else if (cf_token_is(&sp->cfp, "struct")) {
sp_parse_struct(sp);
} else if (cf_token_is(&sp->cfp, "sampler_state")) {
sp_parse_sampler_state(sp);
} else if (cf_token_is(&sp->cfp, "{")) {
cf_adderror(&sp->cfp, "Unexpected code segment",
LEX_ERROR, NULL, NULL, NULL);
cf_pass_pair(&sp->cfp, '{', '}');
} else {
/* parameters and functions */
sp_parse_other(sp);
}
}
return !error_data_has_errors(&sp->cfp.error_list);
}
|