mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 14:12:10 +02:00
Bug 206271 - [formatter] confused by gcc __attribute__ defs
Bug 241819 - [formatter] Greater-than (>) in macros not formatted properly
This commit is contained in:
parent
55244050c6
commit
a1e03d937a
3 changed files with 94 additions and 50 deletions
|
@ -436,6 +436,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
// declarator
|
||||
final IASTDeclarator declarator= node.getDeclarator();
|
||||
if (declarator != null) {
|
||||
skipNonWhitespaceToNode(declarator);
|
||||
boolean needSpace= declarator.getPointerOperators().length > 0 && scribe.printComment();
|
||||
if (needSpace) {
|
||||
scribe.space();
|
||||
|
@ -2459,7 +2460,11 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
scribe.startNewLine();
|
||||
}
|
||||
}
|
||||
} else if (elseStatement == null && preferences.keep_simple_if_on_one_line) {
|
||||
} else {
|
||||
if (node.getFileLocation().getNodeOffset() == thenStatement.getFileLocation().getNodeOffset()) {
|
||||
startNode(thenStatement);
|
||||
}
|
||||
if (elseStatement == null && preferences.keep_simple_if_on_one_line) {
|
||||
Alignment compactIfAlignment = scribe.createAlignment(
|
||||
"compactIf", //$NON-NLS-1$
|
||||
preferences.alignment_for_compact_if,
|
||||
|
@ -2498,6 +2503,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
scribe.unIndent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (elseStatement != null) {
|
||||
if (thenStatementIsBlock) {
|
||||
|
@ -3060,8 +3066,14 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
}
|
||||
|
||||
private void formatBlock(IASTCompoundStatement block, String block_brace_position, boolean insertSpaceBeforeOpeningBrace, boolean indentStatements) {
|
||||
final boolean startsWithMacroExpansion= startsWithMacroExpansion(block);
|
||||
if (!startsWithMacroExpansion) {
|
||||
formatOpeningBrace(block_brace_position, insertSpaceBeforeOpeningBrace);
|
||||
boolean endsWithMacroExpansion= endsWithMacroExpansion(block);
|
||||
} else {
|
||||
scribe.startNewLine();
|
||||
scribe.printComment();
|
||||
}
|
||||
final boolean endsWithMacroExpansion= endsWithMacroExpansion(block);
|
||||
IASTStatement[] statements = block.getStatements();
|
||||
final int statementsLength = statements.length;
|
||||
if (statementsLength != 0) {
|
||||
|
@ -3085,7 +3097,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
}
|
||||
if (!endsWithMacroExpansion) {
|
||||
formatClosingBrace(block_brace_position);
|
||||
} else {
|
||||
} else if (!startsWithMacroExpansion) {
|
||||
if (DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED.equals(block_brace_position)) {
|
||||
scribe.unIndent();
|
||||
}
|
||||
|
|
|
@ -637,10 +637,8 @@ public class Scribe {
|
|||
try {
|
||||
scanner.resetTo(Math.max(startOffset, currentPosition), startOffset + length - 1);
|
||||
int parenLevel= 0;
|
||||
boolean lastTokenWasGT= false;
|
||||
while (true) {
|
||||
boolean hasWhitespace= printComment();
|
||||
boolean isGT= false;
|
||||
currentToken= scanner.nextToken();
|
||||
if (currentToken == null) {
|
||||
if (hasWhitespace) {
|
||||
|
@ -677,9 +675,11 @@ public class Scribe {
|
|||
for (int i= 0; i < preferences.continuation_indentation; i++) {
|
||||
indent();
|
||||
}
|
||||
if (column <= indentationLevel) {
|
||||
// HACK: avoid indent in same line
|
||||
column= indentationLevel + 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Token.tRPAREN:
|
||||
--parenLevel;
|
||||
|
@ -690,12 +690,6 @@ public class Scribe {
|
|||
}
|
||||
print(currentToken.getLength(), hasWhitespace);
|
||||
break;
|
||||
case Token.tGT:
|
||||
if (lastTokenWasGT) {
|
||||
print(currentToken.getLength(), true);
|
||||
}
|
||||
isGT= true;
|
||||
break;
|
||||
case Token.tSEMI:
|
||||
print(currentToken.getLength(), preferences.insert_space_before_semicolon);
|
||||
break;
|
||||
|
@ -723,7 +717,6 @@ public class Scribe {
|
|||
}
|
||||
}
|
||||
hasWhitespace= false;
|
||||
lastTokenWasGT= isGT;
|
||||
}
|
||||
} finally {
|
||||
scannerEndPosition= savedScannerEndPos;
|
||||
|
@ -1679,7 +1672,7 @@ public class Scribe {
|
|||
}
|
||||
|
||||
boolean shouldSkip(int offset) {
|
||||
return offset >= fSkipStartOffset && offset <= fSkipEndOffset;
|
||||
return offset >= fSkipStartOffset;
|
||||
}
|
||||
|
||||
void skipRange(int offset, int endOffset) {
|
||||
|
|
|
@ -1091,4 +1091,43 @@ public class CodeFormatterTest extends BaseUITestCase {
|
|||
public void testDotStarAndArrowStarOperators_Bug257700() throws Exception {
|
||||
assertFormatterResult();
|
||||
}
|
||||
|
||||
//void zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz1(unsigned char __attribute__((unused)) x, unsigned char __attribute__((unused)) y){;}
|
||||
|
||||
//void zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz1(
|
||||
// unsigned char __attribute__((unused)) x,
|
||||
// unsigned char __attribute__((unused)) y) {
|
||||
// ;
|
||||
//}
|
||||
public void test__attribute__InParameterDecl_Bug206271() throws Exception {
|
||||
assertFormatterResult();
|
||||
}
|
||||
|
||||
//#define assert(e) if(!(e)) printf("Failed assertion")
|
||||
//void test(){assert(1 > 0);}
|
||||
|
||||
//#define assert(e) if(!(e)) printf("Failed assertion")
|
||||
//void test() {
|
||||
// assert(1 > 0);
|
||||
//}
|
||||
|
||||
public void testMacroFormatting1_Bug241819() throws Exception {
|
||||
assertFormatterResult();
|
||||
}
|
||||
|
||||
//#define PRINT if(printswitch) printf
|
||||
//void test(){int i=0;PRINT("Watch the format");if(i>0){i=1;}}
|
||||
|
||||
//#define PRINT if(printswitch) printf
|
||||
//void test() {
|
||||
// int i = 0;
|
||||
// PRINT("Watch the format");
|
||||
// if (i > 0) {
|
||||
// i = 1;
|
||||
// }
|
||||
//}
|
||||
public void testMacroFormatting2_Bug241819() throws Exception {
|
||||
assertFormatterResult();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue