mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +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
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -284,7 +284,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
int indentLevel= scribe.indentationLevel;
|
||||
try {
|
||||
if (node.getNodeLocations()[0] instanceof IASTMacroExpansion) {
|
||||
formatNode(node);
|
||||
skipNode(node);
|
||||
} else
|
||||
if (node instanceof IASTFunctionDefinition) {
|
||||
return visit((IASTFunctionDefinition)node);
|
||||
|
@ -481,7 +481,9 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
if (locations.length == 0) {
|
||||
return PROCESS_SKIP;
|
||||
} 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
|
||||
if (node instanceof IASTConditionalExpression) {
|
||||
visit((IASTConditionalExpression)node);
|
||||
|
@ -514,8 +516,8 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
if (locations.length == 0) {
|
||||
return PROCESS_SKIP;
|
||||
} else if (locations[0] instanceof IASTMacroExpansion) {
|
||||
formatNode(node);
|
||||
} else if (locations[0].getNodeOffset()+locations[0].getNodeLength() < scribe.scanner.getCurrentTokenStartPosition()) {
|
||||
skipNode(node);
|
||||
} else if (locations[0].getNodeOffset()+locations[0].getNodeLength() < scribe.scanner.getCurrentPosition()) {
|
||||
return PROCESS_SKIP;
|
||||
} else
|
||||
if (node instanceof IASTCompoundStatement) {
|
||||
|
@ -847,6 +849,10 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
final ListAlignment align= new ListAlignment(Alignment.M_COMPACT_SPLIT);
|
||||
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.printTrailingComment();
|
||||
scribe.startNewLine();
|
||||
|
@ -1322,6 +1328,10 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
}
|
||||
|
||||
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.printTrailingComment();
|
||||
return PROCESS_SKIP;
|
||||
|
@ -1710,7 +1720,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
if (maxLocation != null) {
|
||||
final int startOffset= minLocation.getNodeOffset();
|
||||
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() {
|
||||
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() {
|
||||
|
@ -1973,22 +1994,6 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
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
|
||||
* in the given translation unit.
|
||||
|
|
Loading…
Add table
Reference in a new issue