本文整理汇总了C++中chunk_get_next_ncnl函数的典型用法代码示例。如果您正苦于以下问题:C++ chunk_get_next_ncnl函数的具体用法?C++ chunk_get_next_ncnl怎么用?C++ chunk_get_next_ncnl使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了chunk_get_next_ncnl函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: LOG_FUNC_ENTRY
/**
* Remove the case brace, if allowable.
*/
static chunk_t *mod_case_brace_remove(chunk_t *br_open)
{
LOG_FUNC_ENTRY();
chunk_t *pc;
chunk_t *br_close;
chunk_t *next = chunk_get_next_ncnl(br_open, CNAV_PREPROC);
LOG_FMT(LMCB, "%s: line %lu", __func__, br_open->orig_line);
/* Find the matching brace close */
br_close = chunk_get_next_type(br_open, CT_BRACE_CLOSE, br_open->level, CNAV_PREPROC);
if (br_close == NULL)
{
LOG_FMT(LMCB, " - no close\n");
return(next);
}
/* Make sure 'break', 'return', 'goto', 'case' or '}' is after the close brace */
pc = chunk_get_next_ncnl(br_close, CNAV_PREPROC);
if ((pc == NULL) ||
((pc->type != CT_BREAK) &&
(pc->type != CT_RETURN) &&
(pc->type != CT_CASE) &&
(pc->type != CT_GOTO) &&
(pc->type != CT_BRACE_CLOSE)))
{
LOG_FMT(LMCB, " - after '%s'\n",
(pc == NULL) ? "<null>" : get_token_name(pc->type));
return(next);
}
/* scan to make sure there are no definitions at brace level between braces */
for (pc = br_open; pc != br_close; pc = chunk_get_next_ncnl(pc, CNAV_PREPROC))
{
if ((pc->level == (br_open->level + 1)) && (pc->flags & PCF_VAR_DEF))
{
LOG_FMT(LMCB, " - vardef on line %lu: '%s'\n", pc->orig_line, pc->text());
return(next);
}
}
LOG_FMT(LMCB, " - removing braces on lines %lu and %lu\n",
br_open->orig_line, br_close->orig_line);
for (pc = br_open; pc != br_close; pc = chunk_get_next_ncnl(pc, CNAV_PREPROC))
{
pc->brace_level--;
pc->level--;
}
next = chunk_get_prev(br_open, CNAV_PREPROC);
chunk_del(br_open);
chunk_del(br_close);
return(chunk_get_next(next, CNAV_PREPROC));
} // mod_case_brace_remove
开发者ID:bengardner,项目名称:uncrustify,代码行数:56,代码来源:braces.cpp
示例2: add_parens_between
/**
* Add an open paren after first and add a close paren before the last
*/
static void add_parens_between(chunk_t *first, chunk_t *last)
{
chunk_t pc;
chunk_t *first_n;
chunk_t *last_p;
chunk_t *tmp;
LOG_FMT(LPARADD, "%s: line %d between %.*s [lvl=%d] and %.*s [lvl=%d]\n",
__func__, first->orig_line,
first->len, first->str, first->level,
last->len, last->str, last->level);
/* Don't do anything if we have a bad sequence, ie "&& )" */
first_n = chunk_get_next_ncnl(first);
if (first_n == last)
{
return;
}
memset(&pc, 0, sizeof(pc));
pc.type = CT_PAREN_OPEN;
pc.str = "(";
pc.len = 1;
pc.flags = first_n->flags & PCF_COPY_FLAGS;
pc.level = first_n->level;
pc.pp_level = first_n->pp_level;
pc.brace_level = first_n->brace_level;
chunk_add_before(&pc, first_n);
last_p = chunk_get_prev_ncnl(last, CNAV_PREPROC);
pc.type = CT_PAREN_CLOSE;
pc.str = ")";
pc.flags = last_p->flags & PCF_COPY_FLAGS;
pc.level = last_p->level;
pc.pp_level = last_p->pp_level;
pc.brace_level = last_p->brace_level;
chunk_add_after(&pc, last_p);
for (tmp = first_n;
tmp != last_p;
tmp = chunk_get_next_ncnl(tmp))
{
tmp->level++;
}
last_p->level++;
}
开发者ID:echristophe,项目名称:uncrustify,代码行数:52,代码来源:parens.cpp
示例3: split_fcn_params_full
/**
* Splits the parameters at every comma that is at the fparen level.
*
* @param start the offending token
*/
static void split_fcn_params_full(chunk_t *start)
{
LOG_FMT(LSPLIT, "%s", __func__);
chunk_t *fpo;
chunk_t *pc;
/* Find the opening fparen */
fpo = start;
while (((fpo = chunk_get_prev(fpo)) != NULL) &&
(fpo->type != CT_FPAREN_OPEN))
{
/* do nothing */
}
/* Now break after every comma */
pc = fpo;
while ((pc = chunk_get_next_ncnl(pc)) != NULL)
{
if (pc->level <= fpo->level)
{
break;
}
if ((pc->level == (fpo->level + 1)) && (pc->type == CT_COMMA))
{
split_before_chunk(chunk_get_next(pc));
}
}
}
开发者ID:Limsik,项目名称:e17,代码行数:34,代码来源:width.cpp
示例4: chunk_get_next
/**
* Convert '>' + '>' into '>>'
* If we only have a single '>', then change it to CT_COMPARE.
*/
static chunk_t *handle_double_angle_close(chunk_t *pc)
{
chunk_t *next = chunk_get_next(pc);
if (next)
{
if ((pc->type == CT_ANGLE_CLOSE) &&
(next->type == CT_ANGLE_CLOSE) &&
(pc->parent_type == CT_NONE) &&
((pc->orig_col_end + 1) == next->orig_col) &&
(next->parent_type == CT_NONE))
{
pc->str.append('>');
set_chunk_type(pc, CT_ARITH);
pc->orig_col_end = next->orig_col_end;
chunk_t *tmp = chunk_get_next_ncnl(next);
chunk_del(next);
next = tmp;
}
else
{
// bug #663
set_chunk_type(pc, CT_COMPARE);
}
}
return(next);
}
开发者ID:dzenanz,项目名称:uncrustify,代码行数:32,代码来源:tokenize_cleanup.cpp
示例5: do_parens
void do_parens(void)
{
LOG_FUNC_ENTRY();
if (cpd.settings[UO_mod_full_paren_if_bool].b)
{
chunk_t *pc = chunk_get_head();
while ((pc = chunk_get_next_ncnl(pc)) != nullptr)
{
if ( pc->type != CT_SPAREN_OPEN
|| ( pc->parent_type != CT_IF
&& pc->parent_type != CT_ELSEIF
&& pc->parent_type != CT_SWITCH))
{
continue;
}
// Grab the close sparen
chunk_t *pclose = chunk_get_next_type(pc, CT_SPAREN_CLOSE, pc->level, scope_e::PREPROC);
if (pclose != nullptr)
{
check_bool_parens(pc, pclose, 0);
pc = pclose;
}
}
}
}
开发者ID:Unity-Technologies,项目名称:uncrustify,代码行数:27,代码来源:parens.cpp
示例6: chunk_get_next
/**
* Convert '>' + '>' into '>>'
* If we only have a single '>', then change it to CT_COMPARE.
*/
static chunk_t *handle_double_angle_close(chunk_t *pc)
{
chunk_t *next = chunk_get_next(pc);
if (next != NULL)
{
if ((pc->type == CT_ANGLE_CLOSE) &&
(next->type == CT_ANGLE_CLOSE) &&
(pc->parent_type == CT_NONE) &&
(memcmp(pc->str, ">>", 2) == 0) &&
(next->parent_type == CT_NONE))
{
pc->len++;
pc->type = CT_ARITH;
pc->orig_col_end = next->orig_col_end;
chunk_t *tmp = chunk_get_next_ncnl(next);
chunk_del(next);
next = tmp;
}
else
{
pc->type = CT_COMPARE;
}
}
return(next);
}
开发者ID:jscipione,项目名称:Paladin,代码行数:31,代码来源:tokenize_cleanup.cpp
示例7: preproc_start
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);
}
开发者ID:jibsen,项目名称:uncrustify,代码行数:35,代码来源:brace_cleanup.cpp
示例8: do_parens
void do_parens(void)
{
LOG_FUNC_ENTRY();
chunk_t *pc;
chunk_t *pclose;
if (cpd.settings[UO_mod_full_paren_if_bool].b)
{
pc = chunk_get_head();
while ((pc = chunk_get_next_ncnl(pc)) != NULL)
{
if ((pc->type != CT_SPAREN_OPEN) ||
((pc->parent_type != CT_IF) &&
(pc->parent_type != CT_ELSEIF) &&
(pc->parent_type != CT_SWITCH)))
{
continue;
}
/* Grab the close sparen */
pclose = chunk_get_next_type(pc, CT_SPAREN_CLOSE, pc->level, CNAV_PREPROC);
if (pclose != NULL)
{
check_bool_parens(pc, pclose, 0);
pc = pclose;
}
}
}
}
开发者ID:githhhh,项目名称:uncrustify,代码行数:29,代码来源:parens.cpp
示例9: split_fcn_params_full
static void split_fcn_params_full(chunk_t *start)
{
LOG_FUNC_ENTRY();
LOG_FMT(LSPLIT, "%s(%d): %s\n", __func__, __LINE__, start->text());
// Find the opening function parenthesis
chunk_t *fpo = start;
LOG_FMT(LSPLIT, " %s(%d): Find the opening function parenthesis\n", __func__, __LINE__);
while ((fpo = chunk_get_prev(fpo)) != nullptr)
{
LOG_FMT(LSPLIT, "%s(%d): %s, orig_col is %zu, level is %zu\n",
__func__, __LINE__, fpo->text(), fpo->orig_col, fpo->level);
if (fpo->type == CT_FPAREN_OPEN && (fpo->level == start->level - 1))
{
break; // opening parenthesis found. Issue #1020
}
}
// Now break after every comma
chunk_t *pc = fpo;
while ((pc = chunk_get_next_ncnl(pc)) != nullptr)
{
if (pc->level <= fpo->level)
{
break;
}
if ((pc->level == (fpo->level + 1)) && pc->type == CT_COMMA)
{
split_before_chunk(chunk_get_next(pc));
}
}
}
开发者ID:CDanU,项目名称:uncrustify,代码行数:32,代码来源:width.cpp
示例10: check_bool_parens
/**
* Scans between two parens and adds additional parens if needed.
* This function is recursive. If it hits another open paren, it'll call itself
* with the new bounds.
*
* Adds optional parens in an IF or SWITCH conditional statement.
*
* This basically just checks for a CT_COMPARE that isn't surrounded by parens.
* The edges for the compare are the open, close and any CT_BOOL tokens.
*
* This only handleds VERY simple patterns:
* (!a && b) => (!a && b) -- no change
* (a && b == 1) => (a && (b == 1))
* (a == 1 || b > 2) => ((a == 1) || (b > 2))
*
* FIXME: we really should bail if we transition between a preprocessor and
* a non-preprocessor
*/
static void check_bool_parens(chunk_t *popen, chunk_t *pclose, int nest)
{
chunk_t *pc;
chunk_t *ref = popen;
chunk_t *next;
bool hit_compare = false;
LOG_FMT(LPARADD, "%s(%d): popen on %d, col %d, pclose on %d, col %d, level=%d\n",
__func__, nest,
popen->orig_line, popen->orig_col,
pclose->orig_line, pclose->orig_col,
popen->level);
pc = popen;
while (((pc = chunk_get_next_ncnl(pc)) != NULL) && (pc != pclose))
{
if ((pc->type == CT_BOOL) ||
(pc->type == CT_QUESTION) ||
(pc->type == CT_COND_COLON))
{
LOG_FMT(LPARADD2, " -- %s [%.*s] at line %d col %d, level %d\n",
get_token_name(pc->type),
pc->len, pc->str, pc->orig_line, pc->orig_col, pc->level);
if (hit_compare)
{
hit_compare = false;
add_parens_between(ref, pc);
}
ref = pc;
}
else if (pc->type == CT_COMPARE)
{
LOG_FMT(LPARADD2, " -- compare [%.*s] at line %d col %d, level %d\n",
pc->len, pc->str, pc->orig_line, pc->orig_col, pc->level);
hit_compare = true;
}
else if (chunk_is_paren_open(pc))
{
next = chunk_get_next_type(pc, (c_token_t)(pc->type + 1), pc->level);
if (next != NULL)
{
check_bool_parens(pc, next, nest + 1);
pc = next;
}
}
else if ((pc->type == CT_BRACE_OPEN) ||
(pc->type == CT_SQUARE_OPEN) ||
(pc->type == CT_ANGLE_OPEN))
{
/* Skip [], {}, and <> */
pc = chunk_get_next_type(pc, (c_token_t)(pc->type + 1), pc->level);
}
}
if (hit_compare && (ref != popen))
{
add_parens_between(ref, pclose);
}
}
开发者ID:echristophe,项目名称:uncrustify,代码行数:77,代码来源:parens.cpp
示例11: remove_extra_semicolons
/**
* Removes superfluous semicolons:
* - after brace close whose parent is IF, ELSE, SWITCH, WHILE, FOR, NAMESPACE
* - after another semicolon where parent is not FOR
* - (D) after brace close whose parent is ENUM/STRUCT/UNION
* - after an open brace
* - when not in a #DEFINE
*/
void remove_extra_semicolons(void)
{
chunk_t *pc;
chunk_t *next;
chunk_t *prev;
pc = chunk_get_head();
while (pc != NULL)
{
next = chunk_get_next_ncnl(pc);
if ((pc->type == CT_SEMICOLON) && !(pc->flags & PCF_IN_PREPROC) &&
((prev = chunk_get_prev_ncnl(pc)) != NULL))
{
LOG_FMT(LSCANSEMI, "Semi on %d:%d, prev = '%s' [%s/%s]\n",
pc->orig_line, pc->orig_col, prev->str.c_str(),
get_token_name(prev->type), get_token_name(prev->parent_type));
if ((prev->type == CT_BRACE_CLOSE) &&
((prev->parent_type == CT_IF) ||
(prev->parent_type == CT_ELSEIF) ||
(prev->parent_type == CT_ELSE) ||
(prev->parent_type == CT_SWITCH) ||
(prev->parent_type == CT_WHILE) ||
(prev->parent_type == CT_USING_STMT) ||
(prev->parent_type == CT_FOR) ||
(prev->parent_type == CT_FUNC_DEF) ||
(prev->parent_type == CT_OC_MSG_DECL) ||
(prev->parent_type == CT_FUNC_CLASS) ||
(prev->parent_type == CT_NAMESPACE)))
{
remove_semicolon(pc);
}
else if ((prev->type == CT_BRACE_CLOSE) &&
(prev->parent_type == CT_NONE))
{
check_unknown_brace_close(pc, prev);
}
else if ((prev->type == CT_SEMICOLON) &&
(prev->parent_type != CT_FOR))
{
remove_semicolon(pc);
}
else if ((cpd.lang_flags & LANG_D) &&
((prev->parent_type == CT_ENUM) ||
(prev->parent_type == CT_UNION) ||
(prev->parent_type == CT_STRUCT)))
{
remove_semicolon(pc);
}
else if (prev->type == CT_BRACE_OPEN)
{
remove_semicolon(pc);
}
}
pc = next;
}
}
开发者ID:HPChen,项目名称:uncrustify,代码行数:67,代码来源:semicolons.cpp
示例12: align_oc_msg_colon
/**
* Aligns an OC message
*
* @param so the square open of the message
* @param span the span value
*/
static void align_oc_msg_colon(chunk_t *so)
{
int span = cpd.settings[UO_align_oc_msg_colon_span].n;
chunk_t *pc;
chunk_t *tmp;
AlignStack cas; /* for the colons */
AlignStack nas; /* for the parameter tag */
int level;
bool did_line;
int lcnt; /* line count with no colon for span */
bool has_colon;
nas.Reset();
nas.m_right_align = true;
cas.Start(span);
level = so->level;
pc = chunk_get_next_ncnl(so, CNAV_PREPROC);
did_line = false;
has_colon = false;
lcnt = 0;
while ((pc != NULL) && (pc->level > level))
{
if (pc->level > (level + 1))
{
/* do nothing */
}
else if (chunk_is_newline(pc))
{
if (!has_colon)
{
++lcnt;
}
did_line = false;
has_colon = !has_colon;
}
else if (!did_line && (lcnt - 1 < span) && (pc->type == CT_OC_COLON))
{
has_colon = true;
cas.Add(pc);
tmp = chunk_get_prev(pc);
if ((tmp != NULL) &&
((tmp->type == CT_OC_MSG_FUNC) ||
(tmp->type == CT_OC_MSG_NAME)))
{
nas.Add(tmp);
}
did_line = true;
}
pc = chunk_get_next(pc, CNAV_PREPROC);
}
nas.End();
cas.End();
}
开发者ID:jscipione,项目名称:Paladin,代码行数:64,代码来源:align.cpp
示例13: add_parens_between
static void add_parens_between(chunk_t *first, chunk_t *last)
{
LOG_FUNC_ENTRY();
LOG_FMT(LPARADD, "%s: line %zu between %s [lvl=%zu] and %s [lvl=%zu]\n",
__func__, first->orig_line,
first->text(), first->level,
last->text(), last->level);
// Don't do anything if we have a bad sequence, ie "&& )"
chunk_t *first_n = chunk_get_next_ncnl(first);
if (first_n == last)
{
return;
}
chunk_t pc;
pc.type = CT_PAREN_OPEN;
pc.str = "(";
pc.flags = first_n->flags & PCF_COPY_FLAGS;
pc.level = first_n->level;
pc.pp_level = first_n->pp_level;
pc.brace_level = first_n->brace_level;
chunk_add_before(&pc, first_n);
chunk_t *last_p = chunk_get_prev_ncnl(last, scope_e::PREPROC);
pc.type = CT_PAREN_CLOSE;
pc.str = ")";
pc.flags = last_p->flags & PCF_COPY_FLAGS;
pc.level = last_p->level;
pc.pp_level = last_p->pp_level;
pc.brace_level = last_p->brace_level;
chunk_add_after(&pc, last_p);
for (chunk_t *tmp = first_n;
tmp != last_p;
tmp = chunk_get_next_ncnl(tmp))
{
tmp->level++;
}
last_p->level++;
} // add_parens_between
开发者ID:Unity-Technologies,项目名称:uncrustify,代码行数:44,代码来源:parens.cpp
示例14: preproc_start
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);
}
开发者ID:bengardner,项目名称:uncrustify,代码行数:37,代码来源:brace_cleanup.cpp
示例15: handle_complex_close
/**
* Handles a close paren or brace - just progress the stage, if the end
* of the statement is hit, call close_statement()
*
* @param frm The parse frame
* @param pc The current chunk
* @return true - done with this chunk, false - keep processing
*/
static bool handle_complex_close(struct parse_frame *frm, chunk_t *pc)
{
chunk_t *next;
if (frm->pse[frm->pse_tos].stage == BS_PAREN1)
{
/* PAREN1 always => BRACE2 */
frm->pse[frm->pse_tos].stage = BS_BRACE2;
}
else if (frm->pse[frm->pse_tos].stage == BS_BRACE2)
{
/* BRACE2: IF => ELSE, anyting else => close */
if ((frm->pse[frm->pse_tos].type == CT_IF) ||
(frm->pse[frm->pse_tos].type == CT_ELSEIF))
{
frm->pse[frm->pse_tos].stage = BS_ELSE;
/* If the next chunk isn't CT_ELSE, close the statement */
next = chunk_get_next_ncnl(pc);
if ((next != NULL) && (next->type != CT_ELSE))
{
frm->pse_tos--;
print_stack(LBCSPOP, "-IF-HCS ", frm, pc);
if (close_statement(frm, pc))
{
return(true);
}
}
}
else if ((frm->pse[frm->pse_tos].type == CT_TRY) ||
(frm->pse[frm->pse_tos].type == CT_CATCH))
{
frm->pse[frm->pse_tos].stage = BS_CATCH;
/* If the next chunk isn't CT_CATCH or CT_FINALLY, close the statement */
next = chunk_get_next_ncnl(pc);
if ((next != NULL) &&
(next->type != CT_CATCH) &&
(next->type != CT_FINALLY))
{
frm->pse_tos--;
print_stack(LBCSPOP, "-TRY-HCS ", frm, pc);
if (close_statement(frm, pc))
{
return(true);
}
}
}
else
{
LOG_FMT(LNOTE, "%s: close_statement on %s BS_BRACE2\n", __func__,
get_token_name(frm->pse[frm->pse_tos].type));
frm->pse_tos--;
print_stack(LBCSPOP, "-HCC B2 ", frm, pc);
if (close_statement(frm, pc))
{
return(true);
}
}
}
else if (frm->pse[frm->pse_tos].stage == BS_BRACE_DO)
{
frm->pse[frm->pse_tos].stage = BS_WHILE;
}
else if (frm->pse[frm->pse_tos].stage == BS_WOD_PAREN)
{
LOG_FMT(LNOTE, "%s: close_statement on %s BS_WOD_PAREN\n", __func__,
get_token_name(frm->pse[frm->pse_tos].type));
frm->pse[frm->pse_tos].stage = BS_WOD_SEMI;
print_stack(LBCSPOP, "-HCC WoDP ", frm, pc);
}
else if (frm->pse[frm->pse_tos].stage == BS_WOD_SEMI)
{
LOG_FMT(LNOTE, "%s: close_statement on %s BS_WOD_SEMI\n", __func__,
get_token_name(frm->pse[frm->pse_tos].type));
frm->pse_tos--;
print_stack(LBCSPOP, "-HCC WoDS ", frm, pc);
if (close_statement(frm, pc))
{
return(true);
}
}
else
{
/* PROBLEM */
LOG_FMT(LWARN, "%s:%d Error: TOS.type='%s' TOS.stage=%d\n",
cpd.filename, pc->orig_line,
get_token_name(frm->pse[frm->pse_tos].type),
frm->pse[frm->pse_tos].stage);
cpd.error_count++;
}
//.........这里部分代码省略.........
开发者ID:aniec07,项目名称:uncrustify,代码行数:101,代码来源:brace_cleanup.cpp
示例16: parse_cleanup
//.........这里部分代码省略.........
frm->brace_level--;
}
pc->level = frm->level;
pc->brace_level = frm->brace_level;
/* Pop the entry */
frm->pse_tos--;
print_stack(LBCSPOP, "-Close ", frm, pc);
/* See if we are in a complex statement */
if (frm->pse[frm->pse_tos].stage != BS_NONE)
{
handle_complex_close(frm, pc);
}
}
}
/* In this state, we expect a semicolon, but we'll also hit the closing
* sparen, so we need to check cpd.consumed to see if the close sparen was
* aleady handled.
*/
if (frm->pse[frm->pse_tos].stage == BS_WOD_SEMI)
{
chunk_t *tmp = pc;
if (cpd.consumed)
{
/* If consumed, then we are on the close sparen.
* PAWN: Check the next chunk for a semicolon. If it isn't, then
* add a virtual semicolon, which will get handled on the next pass.
*/
if (cpd.lang_flags & LANG_PAWN)
{
tmp = chunk_get_next_ncnl(pc);
if ((tmp->type != CT_SEMICOLON) && (tmp->type != CT_VSEMICOLON))
{
pawn_add_vsemi_after(pc);
}
}
}
else
{
/* Complain if this ISN'T a semicolon, but close out WHILE_OF_DO anyway */
if ((pc->type == CT_SEMICOLON) || (pc->type == CT_VSEMICOLON))
{
cpd.consumed = true;
pc->parent_type = CT_WHILE_OF_DO;
}
else
{
LOG_FMT(LWARN, "%s:%d: Error: Expected a semicolon for WHILE_OF_DO, but got '%s'\n",
cpd.filename, pc->orig_line, get_token_name(pc->type));
cpd.error_count++;
}
handle_complex_close(frm, pc);
}
}
/* Get the parent type for brace and paren open */
parent = pc->parent_type;
if ((pc->type == CT_PAREN_OPEN) ||
(pc->type == CT_FPAREN_OPEN) ||
(pc->type == CT_SPAREN_OPEN) ||
(pc->type == CT_BRACE_OPEN))
{
开发者ID:aniec07,项目名称:uncrustify,代码行数:67,代码来源:brace_cleanup.cpp
示例17: tokenize_cleanup
void tokenize_cleanup(void)
{
LOG_FUNC_ENTRY();
chunk_t *pc = chunk_get_head();
chunk_t *prev = NULL;
chunk_t *next;
chunk_t *tmp;
chunk_t *tmp2;
bool in_type_cast = false;
cpd.unc_stage = US_TOKENIZE_CLEANUP;
/* Since [] is expected to be TSQUARE for the 'operator', we need to make
* this change in the first pass.
*/
for (pc = chunk_get_head(); pc != NULL; pc = chunk_get_next_ncnl(pc))
{
if (pc->type == CT_SQUARE_OPEN)
{
next = chunk_get_next_ncnl(pc);
if (chunk_is_token(next, CT_SQUARE_CLOSE))
{
/* Change '[' + ']' into '[]' */
set_chunk_type(pc, CT_TSQUARE);
pc->str = "[]";
// bug # 664
// The original orig_col_end of CT_SQUARE_CLOSE is stored at orig_col_end of CT_TSQUARE.
// pc->orig_col_end += 1;
pc->orig_col_end = next->orig_col_end;
chunk_del(next);
}
}
if ((pc->type == CT_SEMICOLON) &&
(pc->flags & PCF_IN_PREPROC) &&
!chunk_get_next_ncnl(pc, CNAV_PREPROC))
{
LOG_FMT(LNOTE, "%s:%d Detected a macro that ends with a semicolon. Possible failures if used.\n",
cpd.filename, pc->orig_line);
}
}
/* We can handle everything else in the second pass */
pc = chunk_get_head();
next = chunk_get_next_ncnl(pc);
while ((pc != NULL) && (next != NULL))
{
if ((pc->type == CT_DOT) && (cpd.lang_flags & LANG_ALLC))
{
set_chunk_type(pc, CT_MEMBER);
}
if ((pc->type == CT_NULLCOND) && (cpd.lang_flags & LANG_CS))
{
set_chunk_type(pc, CT_MEMBER);
}
/* Determine the version stuff (D only) */
if (pc->type == CT_D_VERSION)
{
if (next->type == CT_PAREN_OPEN)
{
set_chunk_type(pc, CT_D_VERSION_IF);
}
else
{
if (next->type != CT_ASSIGN)
{
LOG_FMT(LERR, "%s:%d %s: version: Unexpected token %s\n",
cpd.filename, pc->orig_line, __func__, get_token_name(next->type));
cpd.error_count++;
}
set_chunk_type(pc, CT_WORD);
}
}
/* Determine the scope stuff (D only) */
if (pc->type == CT_D_SCOPE)
{
if (next->type == CT_PAREN_OPEN)
{
set_chunk_type(pc, CT_D_SCOPE_IF);
}
else
{
set_chunk_type(pc, CT_TYPE);
}
}
/**
* Change CT_BASE before CT_PAREN_OPEN to CT_WORD.
* public myclass() : base() {
* }
*/
if ((pc->type == CT_BASE) && (next->type == CT_PAREN_OPEN))
{
set_chunk_type(pc, CT_WORD);
}
if ((pc->type == CT_ENUM) && (next->type == CT_CLASS))
//.........这里部分代码省略.........
开发者ID:dzenanz,项目名称:uncrustify,代码行数:101,代码来源:tokenize_cleanup.cpp
示例18: chunk_get_next_str
static chunk_t *pawn_process_func_def(chunk_t *pc)
{
/* We are on a function definition */
chunk_t *clp;
chunk_t *last;
chunk_t *next;
pc->type = CT_FUNC_DEF;
/* If we don't have a brace open right after the close fparen, then
* we need to add virtual braces around the function body.
*/
clp = chunk_get_next_str(pc, ")", 1, 0);
last = chunk_get_next_ncnl(clp);
if (last != NULL)
{
LOG_FMT(LPFUNC, "%s: %d] last is '%s' [%s]\n", __func__,
last->orig_line, last->str.c_str(), get_token_name(last->type));
}
/* See if there is a state clause after the function */
if ((last != NULL) && chunk_is_str(last, "<", 1))
{
LOG_FMT(LPFUNC, "%s: %d] '%s' has state angle open %s\n", __func__,
pc->orig_line, pc->str.c_str(), get_token_name(last->type));
last->type = CT_ANGLE_OPEN;
last->parent_type = CT_FUNC_DEF;
while (((last = chunk_get_next(last)) != NULL) &&
!chunk_is_str(last, ">", 1))
{
}
if (last != NULL)
{
LOG_FMT(LPFUNC, "%s: %d] '%s' has state angle close %s\n", __func__,
pc->orig_line, pc->str.c_str(), get_token_name(last->type));
last->type = CT_ANGLE_CLOSE;
last->parent_type = CT_FUNC_DEF;
}
last = chunk_get_next_ncnl(last);
}
if (last == NULL)
{
return(last);
}
if (last->type == CT_BRACE_OPEN)
{
last->parent_type = CT_FUNC_DEF;
last = chunk_get_next_type(last, CT_BRACE_CLOSE, last->level);
if (last != NULL)
{
last->parent_type = CT_FUNC_DEF;
}
}
else
{
LOG_FMT(LPFUNC, "%s: %d] '%s' fdef: expected brace open: %s\n", __func__,
pc->orig_line, pc->str.c_str(), get_token_name(last->type));
chunk_t chunk;
chunk = *last;
chunk.str.clear();
chunk.type = CT_VBRACE_OPEN;
chunk.parent_type = CT_FUNC_DEF;
chunk_t *prev = chunk_add_before(&chunk, last);
last = prev;
/* find the next newline at level 0 */
prev = chunk_get_next_ncnl(prev);
do
{
LOG_FMT(LPFUNC, "%s:%d] check %s, level %d\n", __func__,
prev->orig_line, get_token_name(prev->type), prev->level);
if ((prev->type == CT_NEWLINE) &&
(prev->level == 0))
{
next = chunk_get_next_ncnl(prev);
if ((next != NULL) &&
(next->type != CT_ELSE) &&
(next->type != CT_WHILE_OF_DO))
{
break;
}
}
prev->level++;
prev->brace_level++;
last = prev;
} while ((prev = chunk_get_next(prev)) != NULL);
if (last != NULL)
{
LOG_FMT(LPFUNC, "%s:%d] ended on %s, level %d\n", __func__,
last->orig_line, get_token_name(last->type), last->level);
}
chunk = *last;
//.........这里部分代码省略.........
开发者ID:AndrianDTR,项目名称:codelite,代码行数:101,代码来源:lang_pawn.cpp
示例19: do_space
//.........这里部分代码省略.........
}
if (first->type == CT_SPAREN_CLOSE)
{
if ((second->type == CT_BRACE_OPEN) &&
(cpd.settings[UO_sp_sparen_brace].a != AV_IGNORE))
{
log_rule("sp_sparen_brace");
return(cpd.settings[UO_sp_sparen_brace].a);
}
if (!chunk_is_comment(second) &&
(cpd.settings[UO_sp_after_sparen].a != AV_IGNORE))
{
log_rule("sp_after_sparen");
return(cpd.settings[UO_sp_after_sparen].a);
}
}
if ((second->type == CT_FPAREN_OPEN) &&
(first->parent_type == CT_OPERATOR) &&
(cpd.settings[UO_sp_after_operator_sym].a != AV_IGNORE))
{
log_rule("sp_after_operator_sym");
return(cpd.settings[UO_sp_after_operator_sym].a);
}
/* spaces between function and open paren */
if ((first->type == CT_FUNC_CALL) ||
(first->type == CT_FUNC_CTOR_VAR))
{
if ((cpd.settings[UO_sp_func_call_paren_empty].a != AV_IGNORE) &&
(second->type == CT_FPAREN_OPEN))
{
next = chunk_get_next_ncnl(second);
if (next && (next->type == CT_FPAREN_CLOSE))
{
log_rule("sp_func_call_paren_empty");
return(cpd.settings[UO_sp_func_call_paren_empty].a);
}
}
log_rule("sp_func_call_paren");
return(cpd.settings[UO_sp_func_call_paren].a);
}
if (first->type == CT_FUNC_CALL_USER)
{
log_rule("sp_func_call_user_paren");
return(cpd.settings[UO_sp_func_call_user_paren].a);
}
if (first->type == CT_ATTRIBUTE)
{
log_rule("sp_attribute_paren");
return(cpd.settings[UO_sp_attribute_paren].a);
}
if (first->type == CT_FUNC_DEF)
{
log_rule("sp_func_def_paren");
return(cpd.settings[UO_sp_func_def_paren].a);
}
if ((first->type == CT_CPP_CAST) || (first->type == CT_TYPE_WRAP))
{
log_rule("sp_cpp_cast_paren");
return(cpd.settings[UO_sp_cpp_cast_paren].a);
}
if ((first->type == CT_PAREN_CLOSE) &&
((second->type == CT_PAREN_OPEN) ||
开发者ID:jscipione,项目名称:Paladin,代码行数:67,代码来源:space.cpp
示例20: indent_text
//.........这里部分代码省略.........
frm.pse[frm.pse_tos].indent += parent_token_indent - indent_size;
else
{
frm.pse[frm.pse_tos].indent += cpd.settings[UO_indent_brace].n;
indent_column += cpd.settings[UO_indent_brace].n;
}
}
else if (pc->parent_type == CT_CASE)
{
/* The indent_case_brace setting affects the parent CT_CASE */
frm.pse[frm.pse_tos].indent_tmp += cpd.settings[UO_indent_case_brace].n;
frm.pse[frm.pse_tos].indent += cpd.settings[UO_indent_case_brace].n;
}
else if ((pc->parent_type == CT_CLASS) && !cpd.settings[UO_indent_class].b)
frm.pse[frm.pse_tos].indent -= indent_size;
else if ((pc->parent_type == CT_NAMESPACE) && !cpd.settings[UO_indent_namespace].b)
frm.pse[frm.pse_tos].indent -= indent_size;
}
if ((pc->flags & PCF_DONT_INDENT) != 0)
{
frm.pse[frm.pse_tos].indent = pc->column;
indent_column = pc->column;
}
else
{
/**
* If there isn't a newline between the open brace and the next
* item, just indent to wherever the next token is.
* This covers this sort of stuff:
* { a++;
* b--; };
*/
next = chunk_get_next_ncnl(pc);
if (!chunk_is_newline_between(pc, next))
frm.pse[frm.pse_tos].indent = next->column;
frm.pse[frm.pse_tos].indent_tmp = frm.pse[frm.pse_tos].indent;
frm.pse[frm.pse_tos].open_line = pc->orig_line;
/* Update the indent_column if needed */
if (cpd.settings[UO_indent_braces].n ||
(parent_token_indent != 0))
indent_column = frm.pse[frm.pse_tos].indent_tmp;
}
}
else if (pc->type == CT_CASE)
{
/* Start a case - indent UO_indent_switch_case from the switch level */
tmp = frm.pse[frm.pse_tos].indent + cpd.settings[UO_indent_switch_case].n;
indent_pse_push(frm, pc);
frm.pse[frm.pse_tos].indent = tmp;
frm.pse[frm.pse_tos].indent_tmp = tmp - indent_size;
/* Always set on case statements */
indent_column = frm.pse[frm.pse_tos].indent_tmp;
}
else if (pc->type == CT_LABEL)
{
/* Labels get sent to the left or backed up */
if (cpd.settings[UO_indent_label].n > 0)
indent_column = cpd.settings[UO_indent_label].n;
else
开发者ID:CDanU,项目名称:uncrustify,代码行数:67,代码来源:02102-indent.cpp
注:本文中的chunk_get_next_ncnl函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论