1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-05 08:46:02 +02:00

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 <tcorbat@hsr.ch>
IP-Clean: Thomas Corbat <tcorbat@hsr.ch>
Tested-by: Thomas Corbat <tcorbat@hsr.ch>
This commit is contained in:
Thomas Corbat 2013-07-03 12:55:15 +02:00
parent c658e9df68
commit e843235fc4
3 changed files with 27 additions and 5 deletions

View file

@ -3771,7 +3771,8 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
return true; return true;
} else if (!fInsideMacroArguments && locations[0] instanceof IASTMacroExpansionLocation) { } else if (!fInsideMacroArguments && locations[0] instanceof IASTMacroExpansionLocation) {
IASTMacroExpansionLocation location = (IASTMacroExpansionLocation) locations[0]; 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(); IASTPreprocessorMacroExpansion macroExpansion = location.getExpansion();
IASTFileLocation macroLocation = macroExpansion.getFileLocation(); IASTFileLocation macroLocation = macroExpansion.getFileLocation();
int macroOffset = macroLocation.getNodeOffset(); int macroOffset = macroLocation.getNodeOffset();

View file

@ -24,15 +24,13 @@ const SimpleStruct simpleStruct = { 1, "mySimple", 0.1232 };
\ \
} }
const SimpleStruct array[] = { { const SimpleStruct array[] = { { SIZEOF(simpleStruct, num),
SIZEOF( simpleStruct, num ),
#if FOO #if FOO
"foo" "foo"
# else # else
"bar" "bar"
#endif #endif
, 0.5 }, { , 0.5 }, { SIZEOF(simpleStruct, floatNum), "name", 1.1 } };
SIZEOF( simpleStruct, floatNum ), "name", 1.1 } };
// single line outside scope // single line outside scope

View file

@ -2965,4 +2965,27 @@ public class CodeFormatterTest extends BaseUITestCase {
public void testDoWhileInMacro_Bug359658() throws Exception { public void testDoWhileInMacro_Bug359658() throws Exception {
assertFormatterResult(); 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();
}
} }