From e843235fc4eb91d7e74a5785d466a43957b7c48a Mon Sep 17 00:00:00 2001 From: Thomas Corbat Date: Wed, 3 Jul 2013 12:55:15 +0200 Subject: [PATCH] Bug 412187 Formatting function-like macro call in equals initializer Added IASTExpressions to the exclusion in enterNode of CodeFormatterVisitor when encountering function like macro calls. Change-Id: I8ea6c5e7ba955299b0d6ca48c93fac275afa65e3 Reviewed-on: https://git.eclipse.org/r/14213 Reviewed-by: Thomas Corbat IP-Clean: Thomas Corbat Tested-by: Thomas Corbat --- .../formatter/CodeFormatterVisitor.java | 3 ++- .../resources/formatter/sample/After.cpp | 6 ++--- .../cdt/ui/tests/text/CodeFormatterTest.java | 23 +++++++++++++++++++ 3 files changed, 27 insertions(+), 5 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 b3ee92ac944..658d5bca0cd 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 @@ -3771,7 +3771,8 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, return true; } else if (!fInsideMacroArguments && locations[0] instanceof IASTMacroExpansionLocation) { IASTMacroExpansionLocation location = (IASTMacroExpansionLocation) locations[0]; - if (locations.length <= 2 && node instanceof IASTStatement) { + if (locations.length <= 2 && + (node instanceof IASTStatement || node instanceof IASTExpression)) { IASTPreprocessorMacroExpansion macroExpansion = location.getExpansion(); IASTFileLocation macroLocation = macroExpansion.getFileLocation(); int macroOffset = macroLocation.getNodeOffset(); diff --git a/core/org.eclipse.cdt.ui.tests/resources/formatter/sample/After.cpp b/core/org.eclipse.cdt.ui.tests/resources/formatter/sample/After.cpp index 674808249f7..5e98e78c616 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/formatter/sample/After.cpp +++ b/core/org.eclipse.cdt.ui.tests/resources/formatter/sample/After.cpp @@ -24,15 +24,13 @@ const SimpleStruct simpleStruct = { 1, "mySimple", 0.1232 }; \ } -const SimpleStruct array[] = { { -SIZEOF( simpleStruct, num ), +const SimpleStruct array[] = { { SIZEOF(simpleStruct, num), #if FOO "foo" # else "bar" #endif - , 0.5 }, { -SIZEOF( simpleStruct, floatNum ), "name", 1.1 } }; + , 0.5 }, { SIZEOF(simpleStruct, floatNum), "name", 1.1 } }; // single line outside scope 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 b7786cb6cb7..30c6a2e7f34 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 @@ -2965,4 +2965,27 @@ public class CodeFormatterTest extends BaseUITestCase { public void testDoWhileInMacro_Bug359658() throws Exception { assertFormatterResult(); } + + //#define macro(x) NS::convert(x) + //namespace NS { + //int convert(int arg) { + //return arg; + //} + //} + //int main() { + //int i = macro(42); + //} + + //#define macro(x) NS::convert(x) + //namespace NS { + //int convert(int arg) { + // return arg; + //} + //} + //int main() { + // int i = macro(42); + //} + public void testFunctionMacroInInitializerExpression() throws Exception { + assertFormatterResult(); + } }