bool ep_parse(struct effect_parser *ep, gs_effect_t *effect, const char *effect_string, const char *file) { bool success; const char *graphics_preprocessor = gs_preprocessor_name(); if (graphics_preprocessor) { struct cf_def def; cf_def_init(&def); def.name.str.array = graphics_preprocessor; def.name.str.len = strlen(graphics_preprocessor); strref_copy(&def.name.unmerged_str, &def.name.str); cf_preprocessor_add_def(&ep->cfp.pp, &def); } ep->effect = effect; if (!cf_parser_parse(&ep->cfp, effect_string, file)) return false; while (ep->cfp.cur_token && ep->cfp.cur_token->type != CFTOKEN_NONE) { if (cf_token_is(&ep->cfp, ";") || is_whitespace(*ep->cfp.cur_token->str.array)) { /* do nothing */ ep->cfp.cur_token++; } else if (cf_token_is(&ep->cfp, "struct")) { ep_parse_struct(ep); } else if (cf_token_is(&ep->cfp, "technique")) { ep_parse_technique(ep); } else if (cf_token_is(&ep->cfp, "sampler_state")) { ep_parse_sampler_state(ep); } else if (cf_token_is(&ep->cfp, "{")) { /* add error and pass braces */ cf_adderror(&ep->cfp, "Unexpected code segment", LEX_ERROR, NULL, NULL, NULL); cf_pass_pair(&ep->cfp, '{', '}'); } else { /* parameters and functions */ ep_parse_other(ep); } } success = !error_data_has_errors(&ep->cfp.error_list); if (success) success = ep_compile(ep); return success; }
static void cf_preprocess_define(struct cf_preprocessor *pp, struct cf_token **p_cur_token) { struct cf_token *cur_token = *p_cur_token; struct cf_def def; if (pp->ignore_state) { go_to_newline(p_cur_token); return; } cf_def_init(&def); next_token(&cur_token, true); if (cur_token->type != CFTOKEN_NAME) { cf_adderror_expecting(pp, cur_token, "identifier"); go_to_newline(&cur_token); goto exit; } append_space(pp, &def.tokens.da, NULL); cf_token_copy(&def.name, cur_token); if (!next_token(&cur_token, true)) goto complete; /* process macro */ if (*cur_token->str.array == '(') { if (!cf_preprocess_macro_params(pp, &def, &cur_token)) goto error; } while (cur_token->type != CFTOKEN_NEWLINE && cur_token->type != CFTOKEN_NONE) cf_def_addtoken(&def, cur_token++); complete: append_end_token(&def.tokens.da); append_space(pp, &def.tokens.da, NULL); da_push_back(pp->defines, &def); goto exit; error: cf_def_free(&def); exit: *p_cur_token = cur_token; }