mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug fixes.
This commit is contained in:
parent
eaabdd84c8
commit
b4e5df991c
2 changed files with 140 additions and 85 deletions
|
@ -1544,8 +1544,9 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
} catch (ASTProblemException e) {
|
} catch (ASTProblemException e) {
|
||||||
scribe.skipToToken(Token.tRBRACKET);
|
scribe.skipToToken(Token.tRBRACKET);
|
||||||
}
|
}
|
||||||
boolean insertSpace= emptyBrackets ? preferences.insert_space_between_empty_brackets
|
boolean insertSpace= emptyBrackets ?
|
||||||
: preferences.insert_space_before_closing_bracket;
|
preferences.insert_space_between_empty_brackets :
|
||||||
|
preferences.insert_space_before_closing_bracket;
|
||||||
scribe.printNextToken(Token.tRBRACKET, insertSpace);
|
scribe.printNextToken(Token.tRBRACKET, insertSpace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2081,7 +2082,12 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
}
|
}
|
||||||
|
|
||||||
private int visit(IASTConditionalExpression node) {
|
private int visit(IASTConditionalExpression node) {
|
||||||
|
Runnable tailFormatter = scribe.takeTailFormatter();
|
||||||
|
try {
|
||||||
node.getLogicalConditionExpression().accept(this);
|
node.getLogicalConditionExpression().accept(this);
|
||||||
|
} finally {
|
||||||
|
scribe.setTailFormatter(tailFormatter);
|
||||||
|
}
|
||||||
scribe.printTrailingComment();
|
scribe.printTrailingComment();
|
||||||
if (preferences.insert_space_before_question_in_conditional) {
|
if (preferences.insert_space_before_question_in_conditional) {
|
||||||
scribe.space();
|
scribe.space();
|
||||||
|
@ -2097,23 +2103,33 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
scribe.alignFragment(alignment, 0);
|
scribe.alignFragment(alignment, 0);
|
||||||
|
final IASTExpression positiveExpression = node.getPositiveResultExpression();
|
||||||
|
final IASTExpression negativeExpression = node.getNegativeResultExpression();
|
||||||
|
final IASTExpression nextExpression = positiveExpression != null ?
|
||||||
|
positiveExpression : negativeExpression;
|
||||||
|
// In case of macros we may have already passed the question mark position.
|
||||||
|
if (scribe.scanner.getCurrentPosition() < nextExpression.getFileLocation().getNodeOffset()) {
|
||||||
scribe.printNextToken(Token.tQUESTION, false);
|
scribe.printNextToken(Token.tQUESTION, false);
|
||||||
|
|
||||||
if (preferences.insert_space_after_question_in_conditional) {
|
if (preferences.insert_space_after_question_in_conditional) {
|
||||||
scribe.space();
|
scribe.space();
|
||||||
}
|
}
|
||||||
final IASTExpression positiveExpression = node.getPositiveResultExpression();
|
}
|
||||||
|
|
||||||
if (positiveExpression != null) { // gcc-extension allows to omit the positive expression.
|
if (positiveExpression != null) { // gcc-extension allows to omit the positive expression.
|
||||||
positiveExpression.accept(this);
|
positiveExpression.accept(this);
|
||||||
}
|
}
|
||||||
scribe.printTrailingComment();
|
scribe.printTrailingComment();
|
||||||
scribe.alignFragment(alignment, 1);
|
scribe.alignFragment(alignment, 1);
|
||||||
scribe.printNextToken(Token.tCOLON, preferences.insert_space_before_colon_in_conditional);
|
|
||||||
|
|
||||||
|
// In case of macros we may have already passed the colon position.
|
||||||
|
if (scribe.scanner.getCurrentPosition() < negativeExpression.getFileLocation().getNodeOffset()) {
|
||||||
|
scribe.printNextToken(Token.tCOLON, preferences.insert_space_before_colon_in_conditional);
|
||||||
if (preferences.insert_space_after_colon_in_conditional) {
|
if (preferences.insert_space_after_colon_in_conditional) {
|
||||||
scribe.space();
|
scribe.space();
|
||||||
}
|
}
|
||||||
node.getNegativeResultExpression().accept(this);
|
}
|
||||||
|
|
||||||
|
negativeExpression.accept(this);
|
||||||
|
|
||||||
ok = true;
|
ok = true;
|
||||||
} catch (AlignmentException e) {
|
} catch (AlignmentException e) {
|
||||||
|
@ -2125,7 +2141,12 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
}
|
}
|
||||||
|
|
||||||
private int visit(IASTFunctionCallExpression node) {
|
private int visit(IASTFunctionCallExpression node) {
|
||||||
|
Runnable tailFormatter = scribe.takeTailFormatter();
|
||||||
|
try {
|
||||||
node.getFunctionNameExpression().accept(this);
|
node.getFunctionNameExpression().accept(this);
|
||||||
|
} finally {
|
||||||
|
scribe.setTailFormatter(tailFormatter);
|
||||||
|
}
|
||||||
IASTInitializerClause[] paramExpr= node.getArguments();
|
IASTInitializerClause[] paramExpr= node.getArguments();
|
||||||
if (peekNextToken() == Token.tIDENTIFIER) {
|
if (peekNextToken() == Token.tIDENTIFIER) {
|
||||||
skipNode(node);
|
skipNode(node);
|
||||||
|
@ -2455,9 +2476,11 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
scribe.printTrailingComment();
|
scribe.printTrailingComment();
|
||||||
scribe.alignFragment(expressionAlignment, 1);
|
scribe.alignFragment(expressionAlignment, 1);
|
||||||
|
|
||||||
// operator
|
// In case of macros we may have already passed the operator position.
|
||||||
|
if (scribe.scanner.getCurrentPosition() < node.getOperand2().getFileLocation().getNodeOffset()) {
|
||||||
|
// Operator
|
||||||
final int nextToken= peekNextToken();
|
final int nextToken= peekNextToken();
|
||||||
// in case of C++ alternative operators, like 'and', 'not', etc. a space
|
// In case of C++ alternative operators, like 'and', 'not', etc. a space
|
||||||
boolean forceSpace= Character.isJavaIdentifierStart(peekNextChar());
|
boolean forceSpace= Character.isJavaIdentifierStart(peekNextChar());
|
||||||
|
|
||||||
switch (node.getOperator()) {
|
switch (node.getOperator()) {
|
||||||
|
@ -2471,6 +2494,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
scribe.space();
|
scribe.space();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// operand 2
|
// operand 2
|
||||||
final IASTExpression op2= node.getOperand2();
|
final IASTExpression op2= node.getOperand2();
|
||||||
|
@ -2490,15 +2514,18 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
// operand 1
|
// operand 1
|
||||||
op1.accept(this);
|
op1.accept(this);
|
||||||
|
|
||||||
// operator
|
// In case of macros we may have already passed the equal sign position.
|
||||||
|
if (scribe.scanner.getCurrentPosition() < node.getOperand2().getFileLocation().getNodeOffset()) {
|
||||||
|
// Operator
|
||||||
final int nextToken= peekNextToken();
|
final int nextToken= peekNextToken();
|
||||||
// in case of C++ alternative operators, like 'and', 'not', etc. a space
|
// In case of C++ alternative operators, like 'and', 'not', etc. a space
|
||||||
boolean forceSpace= Character.isJavaIdentifierStart(peekNextChar());
|
boolean forceSpace= Character.isJavaIdentifierStart(peekNextChar());
|
||||||
|
|
||||||
scribe.printNextToken(nextToken, forceSpace || preferences.insert_space_before_assignment_operator);
|
scribe.printNextToken(nextToken, forceSpace || preferences.insert_space_before_assignment_operator);
|
||||||
if (forceSpace || preferences.insert_space_after_assignment_operator) {
|
if (forceSpace || preferences.insert_space_after_assignment_operator) {
|
||||||
scribe.space();
|
scribe.space();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Alignment expressionAlignment= scribe.createAlignment(
|
Alignment expressionAlignment= scribe.createAlignment(
|
||||||
Alignment.ASSIGNMENT_EXPRESSION,
|
Alignment.ASSIGNMENT_EXPRESSION,
|
||||||
|
@ -2580,7 +2607,12 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
private int visit(IASTFieldReference node) {
|
private int visit(IASTFieldReference node) {
|
||||||
IASTExpression expr= node.getFieldOwner();
|
IASTExpression expr= node.getFieldOwner();
|
||||||
if (expr != null) {
|
if (expr != null) {
|
||||||
|
Runnable tailFormatter = scribe.takeTailFormatter();
|
||||||
|
try {
|
||||||
expr.accept(this);
|
expr.accept(this);
|
||||||
|
} finally {
|
||||||
|
scribe.setTailFormatter(tailFormatter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
final IASTName fieldName= node.getFieldName();
|
final IASTName fieldName= node.getFieldName();
|
||||||
if (fieldName != null) {
|
if (fieldName != null) {
|
||||||
|
@ -2619,6 +2651,8 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
}
|
}
|
||||||
|
|
||||||
private int visit(IASTArraySubscriptExpression node) {
|
private int visit(IASTArraySubscriptExpression node) {
|
||||||
|
Runnable tailFormatter = scribe.takeTailFormatter();
|
||||||
|
try {
|
||||||
node.getArrayExpression().accept(this);
|
node.getArrayExpression().accept(this);
|
||||||
|
|
||||||
scribe.printNextToken(Token.tLBRACKET, preferences.insert_space_before_opening_bracket);
|
scribe.printNextToken(Token.tLBRACKET, preferences.insert_space_before_opening_bracket);
|
||||||
|
@ -2629,6 +2663,9 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
node.getArgument().accept(this);
|
node.getArgument().accept(this);
|
||||||
|
|
||||||
scribe.printNextToken(Token.tRBRACKET, preferences.insert_space_before_closing_bracket);
|
scribe.printNextToken(Token.tRBRACKET, preferences.insert_space_before_closing_bracket);
|
||||||
|
} finally {
|
||||||
|
scribe.setTailFormatter(tailFormatter);
|
||||||
|
}
|
||||||
return PROCESS_SKIP;
|
return PROCESS_SKIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2122,7 +2122,7 @@ public class Scribe {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the tail formatter associated with the current alignment or, if there is no current
|
* Returns the tail formatter associated with the current alignment or, if there is no current
|
||||||
* alignment, with the Scribe itself.
|
* alignment, with the scribe itself.
|
||||||
* @see #tailFormatter
|
* @see #tailFormatter
|
||||||
*/
|
*/
|
||||||
public Runnable getTailFormatter() {
|
public Runnable getTailFormatter() {
|
||||||
|
@ -2133,9 +2133,27 @@ public class Scribe {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the tail formatter associated with the current alignment or, if there is no current
|
||||||
|
* alignment, with the scribe itself. The tail formatter associated with the alignment or
|
||||||
|
* the scribe is set to {@code null}.
|
||||||
|
* @see #tailFormatter
|
||||||
|
*/
|
||||||
|
public Runnable takeTailFormatter() {
|
||||||
|
Runnable formatter;
|
||||||
|
if (currentAlignment != null) {
|
||||||
|
formatter = currentAlignment.tailFormatter;
|
||||||
|
currentAlignment.tailFormatter = null;
|
||||||
|
} else {
|
||||||
|
formatter = this.tailFormatter;
|
||||||
|
this.tailFormatter = null;
|
||||||
|
}
|
||||||
|
return formatter;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sets the tail formatter associated with the current alignment or, if there is no current
|
* Sets the tail formatter associated with the current alignment or, if there is no current
|
||||||
* alignment, with the Scribe itself.
|
* alignment, with the scribe itself.
|
||||||
* @see #tailFormatter
|
* @see #tailFormatter
|
||||||
*/
|
*/
|
||||||
public void setTailFormatter(Runnable tailFormatter) {
|
public void setTailFormatter(Runnable tailFormatter) {
|
||||||
|
@ -2148,7 +2166,7 @@ public class Scribe {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Runs the tail formatter associated with the current alignment or, if there is no current
|
* Runs the tail formatter associated with the current alignment or, if there is no current
|
||||||
* alignment, with the Scribe itself.
|
* alignment, with the scribe itself.
|
||||||
* @see #tailFormatter
|
* @see #tailFormatter
|
||||||
*/
|
*/
|
||||||
public void runTailFormatter() {
|
public void runTailFormatter() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue