mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Fix formatter issue with semicolons in for stmt
This commit is contained in:
parent
c075878b2a
commit
1ae4154fb6
3 changed files with 20 additions and 5 deletions
|
@ -1437,8 +1437,10 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
|
||||
private int visit(IASTExpressionStatement node) {
|
||||
node.getExpression().accept(this);
|
||||
scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon);
|
||||
scribe.printTrailingComment();
|
||||
if (!fInsideFor) {
|
||||
scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon);
|
||||
scribe.printTrailingComment();
|
||||
}
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
||||
|
@ -1446,14 +1448,16 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
scribe.printNextToken(Token.t_for);
|
||||
final int line = scribe.line;
|
||||
scribe.printNextToken(Token.tLPAREN, preferences.insert_space_before_opening_paren_in_for);
|
||||
fInsideFor= true;
|
||||
|
||||
if (preferences.insert_space_after_opening_paren_in_for) {
|
||||
scribe.space();
|
||||
}
|
||||
IASTStatement initializerStmt= node.getInitializerStatement();
|
||||
fInsideFor= true;
|
||||
initializerStmt.accept(this);
|
||||
fInsideFor= false;
|
||||
if (peekNextToken() == Token.tSEMI) {
|
||||
scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon_in_for);
|
||||
}
|
||||
final IASTExpression condition = node.getConditionExpression();
|
||||
if (condition != null) {
|
||||
if (preferences.insert_space_after_semicolon_in_for) {
|
||||
|
@ -1464,8 +1468,12 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon_in_for);
|
||||
IASTExpression iterationExpr= node.getIterationExpression();
|
||||
if (iterationExpr != null) {
|
||||
if (preferences.insert_space_after_semicolon_in_for) {
|
||||
scribe.space();
|
||||
}
|
||||
iterationExpr.accept(this);
|
||||
}
|
||||
fInsideFor= false;
|
||||
scribe.printNextToken(Token.tRPAREN, preferences.insert_space_before_closing_paren_in_for);
|
||||
|
||||
formatAction(line, node.getBody(), preferences.brace_position_for_block, preferences.insert_space_before_opening_brace_in_block);
|
||||
|
|
|
@ -17,7 +17,7 @@ class AClass : public ABaseClass {
|
|||
};
|
||||
AClass::AClass(int x) throw(int) :
|
||||
ABaseClass(x) {
|
||||
for (int i=0; i < 12;i++) {
|
||||
for (int i=0; i < 12; i++) {
|
||||
}
|
||||
}
|
||||
// keep space between decl spec and declarator
|
||||
|
@ -32,3 +32,8 @@ char* s2= "this " "is "
|
|||
int main() {
|
||||
return ID(0);
|
||||
}
|
||||
// semicolons inside for
|
||||
void g() {
|
||||
for (int i=0; i<10; ++i) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,3 +17,5 @@ char* s2= "this " "is "
|
|||
// macro definition with line comment
|
||||
#define ID(x) x // identity
|
||||
int main() {return ID(0);}
|
||||
// semicolons inside for
|
||||
void g() {for(int i=0;i<10;++i){}}
|
||||
|
|
Loading…
Add table
Reference in a new issue