mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 02:06:01 +02:00
Fix formatter issues with macro substitutions
This commit is contained in:
parent
a353091fbe
commit
5ca620d1e3
1 changed files with 28 additions and 23 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006 Wind River Systems, Inc. and others.
|
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -284,7 +284,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
int indentLevel= scribe.indentationLevel;
|
int indentLevel= scribe.indentationLevel;
|
||||||
try {
|
try {
|
||||||
if (node.getNodeLocations()[0] instanceof IASTMacroExpansion) {
|
if (node.getNodeLocations()[0] instanceof IASTMacroExpansion) {
|
||||||
formatNode(node);
|
skipNode(node);
|
||||||
} else
|
} else
|
||||||
if (node instanceof IASTFunctionDefinition) {
|
if (node instanceof IASTFunctionDefinition) {
|
||||||
return visit((IASTFunctionDefinition)node);
|
return visit((IASTFunctionDefinition)node);
|
||||||
|
@ -481,7 +481,9 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
if (locations.length == 0) {
|
if (locations.length == 0) {
|
||||||
return PROCESS_SKIP;
|
return PROCESS_SKIP;
|
||||||
} else if (locations[0] instanceof IASTMacroExpansion) {
|
} else if (locations[0] instanceof IASTMacroExpansion) {
|
||||||
formatNode(node);
|
skipNode(node);
|
||||||
|
} else if (locations[0].getNodeOffset()+locations[0].getNodeLength() < scribe.scanner.getCurrentPosition()) {
|
||||||
|
return PROCESS_SKIP;
|
||||||
} else
|
} else
|
||||||
if (node instanceof IASTConditionalExpression) {
|
if (node instanceof IASTConditionalExpression) {
|
||||||
visit((IASTConditionalExpression)node);
|
visit((IASTConditionalExpression)node);
|
||||||
|
@ -514,8 +516,8 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
if (locations.length == 0) {
|
if (locations.length == 0) {
|
||||||
return PROCESS_SKIP;
|
return PROCESS_SKIP;
|
||||||
} else if (locations[0] instanceof IASTMacroExpansion) {
|
} else if (locations[0] instanceof IASTMacroExpansion) {
|
||||||
formatNode(node);
|
skipNode(node);
|
||||||
} else if (locations[0].getNodeOffset()+locations[0].getNodeLength() < scribe.scanner.getCurrentTokenStartPosition()) {
|
} else if (locations[0].getNodeOffset()+locations[0].getNodeLength() < scribe.scanner.getCurrentPosition()) {
|
||||||
return PROCESS_SKIP;
|
return PROCESS_SKIP;
|
||||||
} else
|
} else
|
||||||
if (node instanceof IASTCompoundStatement) {
|
if (node instanceof IASTCompoundStatement) {
|
||||||
|
@ -847,6 +849,10 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
final ListAlignment align= new ListAlignment(Alignment.M_COMPACT_SPLIT);
|
final ListAlignment align= new ListAlignment(Alignment.M_COMPACT_SPLIT);
|
||||||
formatList(declarators, align, false, false);
|
formatList(declarators, align, false, false);
|
||||||
}
|
}
|
||||||
|
if (peekNextToken() == Token.tIDENTIFIER) {
|
||||||
|
// there may be a macro
|
||||||
|
scribe.skipToToken(Token.tSEMI);
|
||||||
|
}
|
||||||
scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon);
|
scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon);
|
||||||
scribe.printTrailingComment();
|
scribe.printTrailingComment();
|
||||||
scribe.startNewLine();
|
scribe.startNewLine();
|
||||||
|
@ -1322,6 +1328,10 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int visit(IASTNullStatement node) {
|
private int visit(IASTNullStatement node) {
|
||||||
|
if (peekNextToken() == Token.tIDENTIFIER) {
|
||||||
|
// probably a macro with empty expansion
|
||||||
|
skipToNode(node);
|
||||||
|
}
|
||||||
scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon);
|
scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon);
|
||||||
scribe.printTrailingComment();
|
scribe.printTrailingComment();
|
||||||
return PROCESS_SKIP;
|
return PROCESS_SKIP;
|
||||||
|
@ -1710,7 +1720,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
if (maxLocation != null) {
|
if (maxLocation != null) {
|
||||||
final int startOffset= minLocation.getNodeOffset();
|
final int startOffset= minLocation.getNodeOffset();
|
||||||
final int endOffset= maxLocation.getNodeOffset() + maxLocation.getNodeLength();
|
final int endOffset= maxLocation.getNodeOffset() + maxLocation.getNodeLength();
|
||||||
scribe.printRaw(minLocation.getNodeOffset(), endOffset - startOffset);
|
scribe.printRaw(startOffset, endOffset - startOffset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1927,7 +1937,18 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
|
|
||||||
protected int peekNextToken() {
|
protected int peekNextToken() {
|
||||||
localScanner.resetTo(scribe.scanner.getCurrentPosition(), scribe.scannerEndPosition - 1);
|
localScanner.resetTo(scribe.scanner.getCurrentPosition(), scribe.scannerEndPosition - 1);
|
||||||
return localScanner.getNextToken();
|
int token = localScanner.getNextToken();
|
||||||
|
loop: while(true) {
|
||||||
|
switch(token) {
|
||||||
|
case Token.tBLOCKCOMMENT :
|
||||||
|
case Token.tLINECOMMENT :
|
||||||
|
token = localScanner.getNextToken();
|
||||||
|
continue loop;
|
||||||
|
default:
|
||||||
|
break loop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isClosingTemplateToken() {
|
protected boolean isClosingTemplateToken() {
|
||||||
|
@ -1973,22 +1994,6 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isNextToken(int tokenType) {
|
|
||||||
localScanner.resetTo(scribe.scanner.getCurrentPosition(), scribe.scannerEndPosition - 1);
|
|
||||||
int token = localScanner.getNextToken();
|
|
||||||
loop: while(true) {
|
|
||||||
switch(token) {
|
|
||||||
case Token.tBLOCKCOMMENT :
|
|
||||||
case Token.tLINECOMMENT :
|
|
||||||
token = localScanner.getNextToken();
|
|
||||||
continue loop;
|
|
||||||
default:
|
|
||||||
break loop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return token == tokenType;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collect source positions of preprocessor-hidden branches
|
* Collect source positions of preprocessor-hidden branches
|
||||||
* in the given translation unit.
|
* in the given translation unit.
|
||||||
|
|
Loading…
Add table
Reference in a new issue