1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-04 07:35:24 +02:00

Bug 406231: Fix exceptions while formatting template id in macro

Fix a couple of exceptions in formatter flow during operations on
template id in macro.

Change-Id: I768c29e1bd24b1336423b298a22b4016eb96e9c3
Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
This commit is contained in:
Marco Stornelli 2019-03-02 12:07:13 +01:00 committed by Jonah Graham
parent e39ce1fb58
commit 9e01bea8aa
2 changed files with 87 additions and 9 deletions

View file

@ -1784,10 +1784,13 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
options.fSpaceBeforeSeparator = preferences.insert_space_before_comma_in_template_parameters;
formatList(Arrays.asList(templateParameters), options, false, false, null);
}
scribe.printNextToken(new int[] { Token.tGT, Token.tSHIFTR },
preferences.insert_space_before_closing_angle_bracket_in_template_parameters);
if (preferences.insert_space_after_closing_angle_bracket_in_template_parameters) {
scribe.space();
int nextToken = peekNextToken();
if (nextToken == Token.tGT || nextToken == Token.tSHIFTR) {
scribe.printNextToken(new int[] { Token.tGT, Token.tSHIFTR },
preferences.insert_space_before_closing_angle_bracket_in_template_parameters);
if (preferences.insert_space_after_closing_angle_bracket_in_template_parameters) {
scribe.space();
}
}
// Declaration
@ -3566,9 +3569,12 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
private int visit(ICPPASTTemplateId node) {
IASTName name = node.getTemplateName();
name.accept(this);
scribe.printNextToken(Token.tLT, preferences.insert_space_before_opening_angle_bracket_in_template_arguments);
if (preferences.insert_space_after_opening_angle_bracket_in_template_arguments) {
scribe.space();
if (peekNextToken() == Token.tLT) {
scribe.printNextToken(Token.tLT,
preferences.insert_space_before_opening_angle_bracket_in_template_arguments);
if (preferences.insert_space_after_opening_angle_bracket_in_template_arguments) {
scribe.space();
}
}
final IASTNode[] templateArguments = node.getTemplateArguments();
if (templateArguments.length > 0) {
@ -3586,9 +3592,13 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
return PROCESS_SKIP;
}
scribe.printNextToken(Token.tGT, preferences.insert_space_before_closing_angle_bracket_in_template_arguments);
int nextToken = peekNextToken();
if (nextToken == Token.tGT)
scribe.printNextToken(Token.tGT,
preferences.insert_space_before_closing_angle_bracket_in_template_arguments);
nextToken = peekNextToken();
if (node.getPropertyInParent() != ICPPASTQualifiedName.SEGMENT_NAME || nextToken == Token.tGT) {
if (nextToken == Token.tLPAREN) {
if (preferences.insert_space_before_opening_paren_in_method_invocation)

View file

@ -3690,4 +3690,72 @@ public class CodeFormatterTest extends BaseUITestCase {
public void testDoeNotFormatInactiveCodeEntireFile() throws Exception {
assertFormatterResult();
}
//#define MYTMPL template<typename T>
//MYTMPL
//class Foo {
//};
//#define MYTMPL template<typename T>
//MYTMPL
//class Foo {
//};
public void testTemplateIdWithMacro1_Bug462566() throws Exception {
assertFormatterResult();
}
//template<typename T>
//struct myvec {
//};
//#define vi myvec<int>
//vi v;
//template<typename T>
//struct myvec {
//};
//#define vi myvec<int>
//vi v;
public void testTemplateIdWithMacro2_Bug462566() throws Exception {
assertFormatterResult();
}
//#define FOREACH_BAD for( Foreach_bad<int> fe; fe.i; ++fe.i )
//void bar() {
// FOREACH_BAD
// {
// printf("loop body\n");
// }
//}
//#define FOREACH_BAD for( Foreach_bad<int> fe; fe.i; ++fe.i )
//void bar() {
// FOREACH_BAD
// {
// printf("loop body\n");
// }
//}
public void testTemplateIdWithMacro3_Bug406231() throws Exception {
assertFormatterResult();
}
//#define ForIndex(I,N) for (int I=0;I<int(N);I++)
//int foo() {
// int s = 0;
// ForIndex(i, 10)
// {
// s += i;
// }
//}
//#define ForIndex(I,N) for (int I=0;I<int(N);I++)
//int foo() {
// int s = 0;
// ForIndex(i, 10)
// {
// s += i;
// }
//}
public void testTemplateIdWithMacro4_Bug406231() throws Exception {
assertFormatterResult();
}
}