diff options
author | Anton Leherbauer | 2008-07-25 09:05:23 +0000 |
---|---|---|
committer | Anton Leherbauer | 2008-07-25 09:05:23 +0000 |
commit | a620f396b903639933d68bd01ecefba245036c75 (patch) | |
tree | e26a35964749c3127a2ff8e6dbb7f5a0c27b2a77 | |
parent | 1bcb22dc40da717e6524233cf5a00b9cf85395b2 (diff) | |
download | org.eclipse.cdt-a620f396b903639933d68bd01ecefba245036c75.tar.gz org.eclipse.cdt-a620f396b903639933d68bd01ecefba245036c75.tar.xz org.eclipse.cdt-a620f396b903639933d68bd01ecefba245036c75.zip |
Fix for 240564: Improve handling of parsing problems in conditional expressions
Fix for 241058: Code Style Formatter for C++ invalidates code for nested templated argument with namespace.
3 files changed, 46 insertions, 6 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 95dec14503c..d67880beecb 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 @@ -2382,7 +2382,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor { scribe.space(); } IASTExpression condExpr= node.getConditionExpression(); - if (condExpr instanceof IASTProblemExpression) { + if (condExpr == null || condExpr instanceof IASTProblemExpression) { scribe.skipToToken(Token.tRPAREN); } else { condExpr.accept(this); @@ -2500,7 +2500,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor { // destructor scribe.printNextToken(Token.tCOMPL, false); } - scribe.printNextToken(Token.tIDENTIFIER, false); + names[names.length-1].accept(this); return PROCESS_SKIP; } @@ -2519,10 +2519,10 @@ public class CodeFormatterVisitor extends CPPASTVisitor { formatList(Arrays.asList(templateArguments), align, false, false); } scribe.printNextToken(Token.tGT, preferences.insert_space_before_closing_angle_bracket_in_template_arguments); - if (node.getPropertyInParent() != ICPPASTQualifiedName.SEGMENT_NAME) { + int nextToken= peekNextToken(); + if (node.getPropertyInParent() != ICPPASTQualifiedName.SEGMENT_NAME || nextToken == Token.tGT) { if (preferences.insert_space_after_closing_angle_bracket_in_template_arguments) { // avoid explicit space if followed by pointer operator - int nextToken= peekNextToken(); if (nextToken != Token.tSTAR && nextToken != Token.tAMPER) { scribe.space(); } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java index 20c6b1fdfb7..ca00e95944d 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java @@ -1618,6 +1618,14 @@ public class Scribe { } int braceLevel= 0; int parenLevel= 0; + switch (expectedTokenType) { + case Token.tRBRACE: + ++braceLevel; + break; + case Token.tRPAREN: + ++parenLevel; + break; + } while ((currentToken= scanner.nextToken()) != null) { switch (currentToken.type) { case Token.tLBRACE: 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 3988386d462..26812fccad0 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 @@ -408,14 +408,14 @@ public class CodeFormatterTest extends BaseUITestCase { //void f() { //int *px= :: new int( 0 ); - //int py [] = new int [5 ] (0, 1,2,3, 4); + //int* py [] = new int [5 ] (0, 1,2,3, 4); //int *pz[ ] =new ( px)int(0); //delete [] py; //:: delete px;} //void f() { // int *px = ::new int(0); - // int py[] = new int[5](0, 1, 2, 3, 4); + // int* py[] = new int[5](0, 1, 2, 3, 4); // int *pz[] = new (px) int(0); // delete[] py; // ::delete px; @@ -760,4 +760,36 @@ public class CodeFormatterTest extends BaseUITestCase { assertFormatterResult(); } + //void A::a(C e) { if (D::iterator it = m.find (e)) m.erase(it);} + //T* A::b(T* t) { S::iterator it = m.find(t); if (!it) return NULL; else return *it; } + //M* A::c(M* tm) { N::iterator it = myN.find(tm); if (!it) return NULL; else return *it; } + + //void A::a(C e) { + // if (D::iterator it = m.find (e)) + // m.erase(it); + //} + //T* A::b(T* t) { + // S::iterator it = m.find(t); + // if (!it) + // return NULL; + // else + // return *it; + //} + //M* A::c(M* tm) { + // N::iterator it = myN.find(tm); + // if (!it) + // return NULL; + // else + // return *it; + //} + public void testHandleParsingProblemsInIfCondition_Bug240564() throws Exception { + assertFormatterResult(); + } + + //TestType1<TESTNS::TestType2<3> > test_variable; + + //TestType1<TESTNS::TestType2<3> > test_variable; + public void testNestedTemplatedArgument_Bug241058() throws Exception { + assertFormatterResult(); + } } |