Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Stornelli2019-04-06 04:42:44 -0400
committerJeff Johnston2019-04-10 10:36:29 -0400
commitce60ebbbf6ce252c4acd2408cee70ac57f42b424 (patch)
treee10bb98f1048a2116115f69082dfc2d47dbe7cea
parent3dc407d008c3f085a1418e12533a885a6459b752 (diff)
downloadorg.eclipse.cdt-ce60ebbbf6ce252c4acd2408cee70ac57f42b424.tar.gz
org.eclipse.cdt-ce60ebbbf6ce252c4acd2408cee70ac57f42b424.tar.xz
org.eclipse.cdt-ce60ebbbf6ce252c4acd2408cee70ac57f42b424.zip
Bug 397710 - Fix bool macro used in struct/class
Change-Id: Ifc900b4b5f522ce778c49072eb9ceac7be9234ed Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java29
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java15
2 files changed, 33 insertions, 11 deletions
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java
index 307faf2735..e71e9c5a82 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java
@@ -2003,7 +2003,8 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
scribe.startNewLine();
IASTDeclaration[] memberDecls = node.getMembers();
- for (IASTDeclaration declaration : memberDecls) {
+ for (int i = 0; i < memberDecls.length; i++) {
+ IASTDeclaration declaration = memberDecls[i];
if (preferences.indent_body_declarations_compare_to_access_specifier) {
scribe.indent();
}
@@ -2012,18 +2013,24 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
if (preferences.indent_body_declarations_compare_to_access_specifier) {
scribe.unIndent();
}
- if (enterNode(declaration)) {
- scribe.startNewLine();
- visit((ICPPASTVisibilityLabel) declaration);
- scribe.startNewLine();
- exitNode(declaration);
- }
- } else {
- if (enterNode(declaration)) {
+ IASTDeclaration next = null;
+ if (i < memberDecls.length - 1 && !(memberDecls[i + 1] instanceof IASTProblemHolder))
+ next = memberDecls[i + 1];
+ if (i == memberDecls.length - 1 || next == null || !doNodeLocationsOverlap(declaration, next)) {
if (getCurrentPosition() <= nodeOffset(declaration))
scribe.startNewLine();
- formatDeclaration(declaration);
- exitNode(declaration);
+ }
+ declaration.accept(this);
+ } else {
+ if (!(declaration instanceof IASTProblemHolder)) {
+ IASTDeclaration next = null;
+ if (i < memberDecls.length - 1 && !(memberDecls[i + 1] instanceof IASTProblemHolder))
+ next = memberDecls[i + 1];
+ if (i == memberDecls.length - 1 || next == null || !doNodeLocationsOverlap(declaration, next)) {
+ if (getCurrentPosition() <= nodeOffset(declaration))
+ scribe.startNewLine();
+ }
+ declaration.accept(this);
} else {
skipNode(declaration);
}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java
index bd8d67485c..021b5a813e 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java
@@ -4003,4 +4003,19 @@ public class CodeFormatterTest extends BaseUITestCase {
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_SEMICOLON_IN_FOR, CCorePlugin.INSERT);
assertFormatterResult();
}
+
+ //#define bool bool
+ //struct ARGS {
+ // bool _unprune;
+ // bool _distributed_timing;
+ //};
+
+ //#define bool bool
+ //struct ARGS {
+ // bool _unprune;
+ // bool _distributed_timing;
+ //};
+ public void testBoolInStructWithMacro_Bug397710() throws Exception {
+ assertFormatterResult();
+ }
}

Back to the top