From f47c792501d4cc080a8bc992be8211e5cc194d03 Mon Sep 17 00:00:00 2001 From: Vladimir Hirsl Date: Fri, 6 Aug 2004 21:14:55 +0000 Subject: [PATCH] Added JUnit tests for following PRs (discovered during parsing of header file): 69751, 70928, 71317, 71331, 71410, 71588, 71603. Also a small fix for parser Problem class after String to char[] optimization. --- core/org.eclipse.cdt.core.tests/ChangeLog | 11 ++ .../FailedCompleteParseASTTest.java | 119 ++++++++++++++++++ core/org.eclipse.cdt.core/ChangeLog | 5 + .../internal/core/parser/problem/Problem.java | 3 +- 4 files changed, 137 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index bdd14109afa..720e92a4a80 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,3 +1,14 @@ +2004-08-06 Vladimir Hirsl + + Parser correctness tests in FailedCompleteParseASTTest.java + testParametrizedTypeDefinition_bug69751(), + testPredefinedSymbol_bug70928(), + testUsingOverloadedName_bug71317(), + testThisInTemplatedMemberFunction_bug71331(), + testInheritsFromTemplateParameter_bug71410(), + testTemplateFunctionInsideTemplateType_bug71588(), + testGNUExternalTemplate_bug71603(). + 2004-06-09 Alain Magloire Patch from Sam Rob to resolve 64022 diff --git a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTTest.java b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTTest.java index 09bc1eef857..fc2dde925ff 100644 --- a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTTest.java +++ b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTTest.java @@ -10,6 +10,7 @@ ***********************************************************************/ package org.eclipse.cdt.core.parser.failedTests; +import java.io.StringWriter; import java.util.Iterator; import org.eclipse.cdt.core.parser.ast.IASTFunction; @@ -164,6 +165,124 @@ public class FailedCompleteParseASTTest extends CompleteParseBaseTest // Iterator i = parse("typedef int size_t; \n int __cdecl foo(); \n").getDeclarations();//$NON-NLS-1$ // IASTTypedefDeclaration td = (IASTTypedefDeclaration) i.next(); // IASTFunction fd = (IASTFunction) i.next(); +// assertFalse(i.hasNext()); + } + + public void testUsingOverloadedName_bug71317() throws Exception { + // using a globaly defined function overloaded in a namespace + try { + parse("int foo(int); \n namespace NS { \n int foo(int); \n using ::foo; \n } \n");//$NON-NLS-1$ + fail(); + } catch ( ParserException e ){ + assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$ + } +// Iterator i = parse("int foo(); \n namespace NS { int bar(); \n using ::foo; \n } \n").getDeclarations();//$NON-NLS-1$ +// IASTFunction fd1 = (IASTFunction) i.next(); +// IASTNamespaceDefinition nd = (IASTNamespaceDefinition) i.next(); +// assertFalse(i.hasNext()); +// Iterator j = nd.getDeclarations(); +// IASTFunction fd2 = (IASTFunction) j.next(); +// IASTUsingDeclaration ud = (IASTUsingDeclaration) j.next(); +// assertFalse(j.hasNext()); + } + + public void testThisInTemplatedMemberFunction_bug71331() throws Exception { + // dereferencing 'this' in a templated member function + try { + parse("class A { \n int f() {return 0;} \n template int g(T*) { return this->f(); } \n }; \n");//$NON-NLS-1$ + fail(); + } catch (ParserException e) { + assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$ + } +// Iterator i = parse("class A { \n int f() {return 0;} \n template int g(T*) { return this->f(); } \n }; \n").getDeclarations();//$NON-NLS-1$ +// IASTAbstractTypeSpecifierDeclaration cd = (IASTAbstractTypeSpecifierDeclaration) i.next(); +// assertFalse(i.hasNext()); +// IASTClassSpecifier cs = (IASTClassSpecifier) cd.getTypeSpecifier(); +// Iterator j = cs.getDeclarations(); +// IASTMethod md = (IASTMethod) j.next(); +// IASTTemplateDeclaration tmd = (IASTTemplateDeclaration) j.next(); +// assertFalse(j.hasNext()); + } + + public void testInheritsFromTemplateParameter_bug71410() throws Exception { + try { + // An inner type definition inherits from a template parameter + parse("template \n class A { \n struct B : U { T* mpT; }; \n B mB; \n T* foo() { return mB.mpT; } \n }; \n");//$NON-NLS-1$ + fail(); + } catch (ParserException e) { + assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$ + } +// Iterator i = parse("template \n class A { \n struct B : U { T* mT; }; \n B mB; \n T* getVal() { return mB.mT; } \n }; \n").getDeclarations();//$NON-NLS-1$ +// IASTTemplateDeclaration td = (IASTTemplateDeclaration)i.next(); +// assertFalse(i.hasNext()); +// IASTClassSpecifier cs = (IASTClassSpecifier) td.getOwnedDeclaration(); +// Iterator j = cs.getDeclarations(); +// IASTClassSpecifier cs2 = (IASTClassSpecifier) j.next(); +// IASTField f = (IASTField) j.next(); +// IASTMethod m = (IASTMethod) j.next(); +// assertFalse(j.hasNext()); + } + + public void testParametrizedTypeDefinition_bug69751() throws Exception { + try { + // a typedef refers to an unknown type in a template parameter + parse("template \n class A { \n typedef typename T::size_type size_type; \n void foo() { size_type i; } \n }; \n");//$NON-NLS-1$ + fail(); + } catch (ParserException e) { + assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$ + } +// Iterator i = parse("template \n class A { \n typedef typename T::size_type size_type; \n void foo() { size_type i; } \n }; \n").getDeclarations();//$NON-NLS-1$ +// IASTTemplateDeclaration td = (IASTTemplateDeclaration)i.next(); +// assertFalse(i.hasNext()); +// IASTClassSpecifier cs = (IASTClassSpecifier) td.getOwnedDeclaration(); +// Iterator j = cs.getDeclarations(); +// IASTTypedefDeclaration tdd = (IASTTypedefDeclaration) j.next(); +// IASTMethod m = (IASTMethod) j.next(); +// assertFalse(j.hasNext()); +// Iterator k = m.getDeclarations(); +// IASTVariable v = (IASTVariable) k.next(); +// assertFalse(k.hasNext()); + } + + public void testTemplateFunctionInsideTemplateType_bug71588() throws Exception { + StringWriter writer = new StringWriter(); + writer.write("template \r\n"); //$NON-NLS-1$ + writer.write("class A { \n"); //$NON-NLS-1$ + writer.write("template \n"); //$NON-NLS-1$ + writer.write("T* foo(V); \n"); //$NON-NLS-1$ + writer.write("}; \n"); //$NON-NLS-1$ + writer.write("template \n"); //$NON-NLS-1$ + writer.write("template \n"); //$NON-NLS-1$ + writer.write("T* A::foo(V) { return (T*)0; } \n"); //$NON-NLS-1$ + try { + parse(writer.toString()); + fail(); + } catch (ParserException e) { + assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$ + } +// Iterator i = parse(writer.toString()).getDeclarations(); +// IASTTemplateDeclaration td = (IASTTemplateDeclaration) i.next(); +// IASTClassSpecifier cs = (IASTClassSpecifier) td.getOwnedDeclaration(); +// Iterator j = cs.getDeclarations(); +// IASTTemplateDeclaration td2 = (IASTTemplateDeclaration) j.next(); +// assertFalse(j.hasNext()); +// IASTMethod mdec = (IASTMethod) td2.getOwnedDeclaration(); +// IASTTemplateDeclaration td3 = (IASTTemplateDeclaration) i.next(); +// assertFalse(i.hasNext()); +// IASTMethod mdef = (IASTMethod) td3.getOwnedDeclaration(); + } + + public void testGNUExternalTemplate_bug71603() throws Exception { + try { + parse("template \n class A {}; \n extern template class A; \n"); //$NON-NLS-1$ + fail(); + } catch (ParserException e) { + assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$ + } +// Iterator i = parse("template \n class A {}; \n extern template class A; \n").getDeclarations(); +// IASTTemplateDeclaration td = (IASTTemplateDeclaration) i.next(); +// IASTClassSpecifier cs = (IASTClassSpecifier) td.getOwnedDeclaration(); +// IASTTemplateInstantiation ti = (IASTTemplateInstantiation) i.next(); // assertFalse(i.hasNext()); } } diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index 02688779a10..2ade184cf54 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -1,3 +1,8 @@ +2004-08-06 Vladimir Hirsl + + A small parser Problem fix after String to char[] optimization. + * parser/org/eclipse/cdt/internal/core/parser/problem/Problem.java + 2004-08-06 Chris Wiebe Add scheduling rule to CoreModel.run diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/Problem.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/Problem.java index 2e0a2a9b578..d6524885804 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/Problem.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/Problem.java @@ -215,12 +215,13 @@ public class Problem implements IProblem { msg = ""; //$NON-NLS-1$ if( arg != null ){ - msg = MessageFormat.format( msg, new Object [] { arg } ); + msg = MessageFormat.format( msg, new Object [] { new String(arg) } ); } Object [] args = { msg, new String( originatingFileName ), new Integer( lineNumber ) }; message = ParserMessages.getFormattedString( PROBLEM_PATTERN, args ); + return message; }