static size_t preproc_start(parse_frame_t *frm, chunk_t *pc) { LOG_FUNC_ENTRY(); chunk_t *next; size_t pp_level = cpd.pp_level; // Get the type of preprocessor and handle it next = chunk_get_next_ncnl(pc); if (next != nullptr) { cpd.in_preproc = next->type; // If we are in a define, push the frame stack. if (cpd.in_preproc == CT_PP_DEFINE) { pf_push(frm); // a preproc body starts a new, blank frame memset(frm, 0, sizeof(*frm)); frm->level = 1; frm->brace_level = 1; // TODO: not sure about the next 3 lines frm->pse_tos = 1; frm->pse[frm->pse_tos].type = CT_PP_DEFINE; frm->pse[frm->pse_tos].stage = brace_stage_e::NONE; } else { // Check for #if, #else, #endif, etc pp_level = pf_check(frm, pc); } } return(pp_level); }
static int path_continue(i_ctx_t *i_ctx_p) { gs_path_enum *penum = r_ptr(esp, gs_path_enum); gs_point ppts[3]; int code; /* Make sure we have room on the o-stack for the worst case */ /* before we enumerate the next path element. */ check_ostack(6); /* 3 points for curveto */ code = gs_path_enum_next(penum, ppts); switch (code) { case 0: /* all done */ esp -= 6; path_cleanup(i_ctx_p); return o_pop_estack; default: /* error */ return code; case gs_pe_moveto: esp[2] = esp[-4]; /* moveto proc */ pf_push(i_ctx_p, ppts, 1); break; case gs_pe_lineto: esp[2] = esp[-3]; /* lineto proc */ pf_push(i_ctx_p, ppts, 1); break; case gs_pe_curveto: esp[2] = esp[-2]; /* curveto proc */ pf_push(i_ctx_p, ppts, 3); break; case gs_pe_closepath: esp[2] = esp[-1]; /* closepath proc */ break; } push_op_estack(path_continue); ++esp; /* include pushed procedure */ return o_push_estack; }
static int preproc_start(struct parse_frame *frm, chunk_t *pc) { LOG_FUNC_ENTRY(); chunk_t *next; int pp_level = cpd.pp_level; /* Get the type of preprocessor and handle it */ next = chunk_get_next_ncnl(pc); if (next != NULL) { cpd.in_preproc = next->type; /** * If we are in a define, push the frame stack. */ if (cpd.in_preproc == CT_PP_DEFINE) { pf_push(frm); /* a preproc body starts a new, blank frame */ memset(frm, 0, sizeof(*frm)); frm->level = 1; frm->brace_level = 1; /*TODO: not sure about the next 3 lines */ frm->pse_tos = 1; frm->pse[frm->pse_tos].type = CT_PP_DEFINE; frm->pse[frm->pse_tos].stage = BS_NONE; } else { /* Check for #if, #else, #endif, etc */ pp_level = pf_check(frm, pc); } } return(pp_level); }
/** * Returns the pp_indent to use for this line */ int pf_check(struct parse_frame *frm, chunk_t *pc) { int in_ifdef = frm->in_ifdef; int b4_cnt = cpd.frame_count; int pp_level = cpd.pp_level; const char *txt = NULL; chunk_t *next; if (pc->type != CT_PREPROC) { return(pp_level); } next = chunk_get_next(pc); if (pc->parent_type != next->type) { LOG_FMT(LNOTE, "%s: Preproc parent not set correctly on line %d: got %s expected %s\n", __func__, pc->orig_line, get_token_name(pc->parent_type), get_token_name(next->type)); pc->parent_type = next->type; } LOG_FMT(LPFCHK, "%s: %5d] %s\n", __func__, pc->orig_line, get_token_name(pc->parent_type)); pf_log_frms(LPFCHK, "TOP", frm); if ((pc->flags & PCF_IN_PREPROC) != 0) { LOG_FMT(LPF, " <In> "); pf_log(LPF, frm); if (pc->parent_type == CT_PP_IF) { /* An #if pushes a copy of the current frame on the stack */ cpd.pp_level++; pf_push(frm); frm->in_ifdef = CT_PP_IF; txt = "if-push"; } else if (pc->parent_type == CT_PP_ELSE) { pp_level--; /** * For #else of #elif, we want to keep the #if part and throw out the * else parts. * We check to see what the top type is to see if we just push or * pop and then push. * We need to use the copy right before the if. */ if (frm->in_ifdef == CT_PP_IF) { /* we have [...] [base]-[if], so push an [else] */ pf_push(frm); frm->in_ifdef = CT_PP_ELSE; } /* we have [...] [base] [if]-[else], copy [base] over [else] */ pf_copy_2nd_tos(frm); frm->in_ifdef = CT_PP_ELSE; txt = "else-push"; } else if (pc->parent_type == CT_PP_ENDIF) { /** * we may have [...] [base] [if]-[else] or [...] [base]-[if]. * Throw out the [else]. */ cpd.pp_level--; pp_level--; if (frm->in_ifdef == CT_PP_ELSE) { /** * We have: [...] [base] [if]-[else] * We want: [...]-[if] */ pf_copy_tos(frm); /* [...] [base] [if]-[if] */ frm->in_ifdef = cpd.frames[cpd.frame_count - 2].in_ifdef; pf_trash_tos(); /* [...] [base]-[if] */ pf_trash_tos(); /* [...]-[if] */ txt = "endif-trash/pop"; } else if (frm->in_ifdef == CT_PP_IF) { /** * We have: [...] [base] [if] * We want: [...] [base] */ pf_pop(frm); txt = "endif-pop"; } else { txt = "???"; } } } if (txt != NULL) { LOG_FMT(LPF, "%s: %d> %s: %s in_ifdef=%d/%d counts=%d/%d\n", __func__, pc->orig_line, get_token_name(pc->parent_type), txt, in_ifdef, frm->in_ifdef, b4_cnt, cpd.frame_count); pf_log_all(LPF); LOG_FMT(LPF, " <Out>"); pf_log(LPF, frm); } pf_log_frms(LPFCHK, "END", frm); return(pp_level); }