mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-03 23:25:26 +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:
parent
e39ce1fb58
commit
9e01bea8aa
2 changed files with 87 additions and 9 deletions
|
@ -1784,11 +1784,14 @@ 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);
|
||||
}
|
||||
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
|
||||
final IASTDeclaration declaration = node.getDeclaration();
|
||||
|
@ -3566,10 +3569,13 @@ 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 (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) {
|
||||
final ListOptions options = new ListOptions(Alignment.M_COMPACT_SPLIT);
|
||||
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue