diff options
Diffstat (limited to 'core/org.eclipse.cdt.core.tests')
7 files changed, 254 insertions, 3 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 7465d5db67b..506f6a13c0f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -56,6 +56,7 @@ import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNameOwner; import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration; import org.eclipse.cdt.core.dom.ast.IASTReturnStatement; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; @@ -128,6 +129,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassType; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPMethod; import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator; @@ -9768,4 +9771,161 @@ public class AST2CPPTests extends AST2BaseTest { public void testFriendTemplateParameter() throws Exception { parseAndCheckBindings(); } + + // struct S { + // virtual void mFuncDecl() final; + // virtual void mFuncDef() final {} + // }; + public void testFinalFunction() throws Exception { + String code = getAboveComment(); + parseAndCheckBindings(code); + + BindingAssertionHelper bindingHelper = new BindingAssertionHelper(code, true); + + CPPMethod functionDeclarationBinding = bindingHelper.assertNonProblem("mFuncDecl()", 9); + assertFalse(functionDeclarationBinding.isOverride()); + assertTrue(functionDeclarationBinding.isFinal()); + IASTNode[] functionDeclarators = functionDeclarationBinding.getDeclarations(); + assertEquals(1, functionDeclarators.length); + assertInstance(functionDeclarators[0], ICPPASTFunctionDeclarator.class); + assertVirtualSpecifiers((ICPPASTFunctionDeclarator)functionDeclarators[0], false, true); + + CPPMethod functionDefinitionBinding = bindingHelper.assertNonProblem("mFuncDef()", 8); + assertFalse(functionDefinitionBinding.isOverride()); + assertTrue(functionDefinitionBinding.isFinal()); + IASTFunctionDeclarator declarator = functionDefinitionBinding.getDefinition(); + assertInstance(declarator, ICPPASTFunctionDeclarator.class); + assertVirtualSpecifiers((ICPPASTFunctionDeclarator)declarator, false, true); + } + + // struct Base { + // virtual void mFuncDecl(); + // virtual void mFuncDef(){} + // }; + // struct S : public Base { + // void mFuncDecl() override; + // void mFuncDef() override {} + // }; + public void testOverrideFunction() throws Exception { + String code = getAboveComment(); + parseAndCheckBindings(code); + + BindingAssertionHelper bindingHelper = new BindingAssertionHelper(code, true); + + CPPMethod functionDeclarationBinding = bindingHelper.assertNonProblem("mFuncDecl() override", 9); + assertTrue(functionDeclarationBinding.isOverride()); + assertFalse(functionDeclarationBinding.isFinal()); + IASTDeclarator[] functionDeclarators = functionDeclarationBinding.getDeclarations(); + assertEquals(1, functionDeclarators.length); + assertInstance(functionDeclarators[0], ICPPASTFunctionDeclarator.class); + assertVirtualSpecifiers((ICPPASTFunctionDeclarator)functionDeclarators[0], true, false); + + CPPMethod functionDefinitionBinding = bindingHelper.assertNonProblem("mFuncDef() override", 8); + assertTrue(functionDefinitionBinding.isOverride()); + assertFalse(functionDefinitionBinding.isFinal()); + IASTFunctionDeclarator declarator = functionDefinitionBinding.getDefinition(); + assertInstance(declarator, ICPPASTFunctionDeclarator.class); + assertVirtualSpecifiers((ICPPASTFunctionDeclarator)declarator, true, false); + } + + // struct Base { + // virtual void mFuncDecl(); + // virtual void mFuncDef(){} + // }; + // struct S : public Base { + // void mFuncDecl() final override; + // void mFuncDef() final override {} + // }; + public void testOverrideFinalFunction() throws Exception { + String code = getAboveComment(); + parseAndCheckBindings(code); + + BindingAssertionHelper bindingHelper = new BindingAssertionHelper(code, true); + + CPPMethod functionDeclarationBinding = bindingHelper.assertNonProblem("mFuncDecl() final", 9); + assertTrue(functionDeclarationBinding.isOverride()); + assertTrue(functionDeclarationBinding.isFinal()); + IASTDeclarator[] functionDeclarators = functionDeclarationBinding.getDeclarations(); + assertEquals(1, functionDeclarators.length); + assertInstance(functionDeclarators[0], ICPPASTFunctionDeclarator.class); + assertVirtualSpecifiers((ICPPASTFunctionDeclarator)functionDeclarators[0], true, true); + + CPPMethod functionDefinitionBinding = bindingHelper.assertNonProblem("mFuncDef() final", 8); + assertTrue(functionDefinitionBinding.isOverride()); + assertTrue(functionDefinitionBinding.isFinal()); + IASTFunctionDeclarator declarator = functionDefinitionBinding.getDefinition(); + assertInstance(declarator, ICPPASTFunctionDeclarator.class); + assertVirtualSpecifiers((ICPPASTFunctionDeclarator)declarator, true, true); + } + + private void assertVirtualSpecifiers(ICPPASTFunctionDeclarator declarator, boolean expectOverride, boolean expectFinal) { + assertEquals(expectOverride, declarator.isOverride()); + assertEquals(expectFinal, declarator.isFinal()); + } + + // struct Base { + // }; + // struct S final : public Base { + // }; + public void testFinalClass() throws Exception { + String code = getAboveComment(); + parseAndCheckBindings(code); + + BindingAssertionHelper bh = new BindingAssertionHelper(code, true); + + CPPClassType structBase = bh.assertNonProblem("Base {", 4); + assertFalse(structBase.isFinal()); + IASTNode baseDefinitionName = structBase.getDefinition(); + IASTNode baseDefinition = baseDefinitionName.getParent(); + assertInstance(baseDefinition, ICPPASTCompositeTypeSpecifier.class); + assertFalse(((ICPPASTCompositeTypeSpecifier)baseDefinition).isFinal()); + + CPPClassType structS = bh.assertNonProblem("S", 1); + assertTrue(structS.isFinal()); + IASTNode sDefinitionName = structS.getDefinition(); + IASTNode sDefinition = sDefinitionName.getParent(); + assertInstance(sDefinition, ICPPASTCompositeTypeSpecifier.class); + assertTrue(((ICPPASTCompositeTypeSpecifier)sDefinition).isFinal()); + } + + + // struct S{ + // template<typename T> + // void foo(T t) final { + // } + // }; + // + // int main() { + // S s; + // s.foo(1); + // } + public void testFinalTemplateMethod() throws Exception { + String code = getAboveComment(); + parseAndCheckBindings(code); + + BindingAssertionHelper bindingHelper = new BindingAssertionHelper(code, true); + + ICPPMethod fooTemplate = bindingHelper.assertNonProblem("foo(T", 3); + assertFalse(fooTemplate.isOverride()); + assertTrue(fooTemplate.isFinal()); + } + + // void foo(){ + // int final, override; + // final = 4; + // override = 2; + // } + public void testFinalAndOverrideVariables() throws Exception { + parseAndCheckBindings(); + } + + // struct S{ + // int i; + // }; + // void foo(struct S final){ + // final.i = 23; + // } + public void testFinalParameter() throws Exception { + parseAndCheckBindings(); + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ClassTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ClassTests.java index 19bf1599cdf..8be5291ac3f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ClassTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ClassTests.java @@ -6,9 +6,10 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation - * Markus Schorn (Wind River Systems) - * IBM Corporation + * QNX - Initial API and implementation + * Markus Schorn (Wind River Systems) + * IBM Corporation + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; @@ -232,4 +233,14 @@ public class ClassTests extends PDOMTestBase { assertTrue(bindings[0] instanceof ICPPClassType); return (ICPPClassType) bindings[0]; } + + public void testFinalClass() throws Exception { + char[][] name = {"E".toCharArray()}; + IBinding[] bindings = pdom.findBindings(name, IndexFilter.ALL, npm()); + assertEquals(1, bindings.length); + assertInstance(bindings[0], ICPPClassType.class); + ICPPClassType classBinding = (ICPPClassType) bindings[0]; + + assertTrue(classBinding.isFinal()); + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/MethodTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/MethodTests.java index 088fc7b816a..e47de9c7eaa 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/MethodTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/MethodTests.java @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; @@ -302,4 +303,31 @@ public class MethodTests extends PDOMTestBase { assertEquals(IBasicType.t_int, Math.min(t1, t2)); assertEquals(IBasicType.t_double, Math.max(t1, t2)); } + + public void testVirtualMemberFunction() throws Exception { + IBinding[] bindings = findQualifiedName(pdom, "E::virtualMemberFunction"); + assertEquals(1, bindings.length); + assertInstance(bindings[0], ICPPMethod.class); + ICPPMethod virtMemFun = (ICPPMethod) bindings[0]; + assertFalse(virtMemFun.isOverride()); + assertFalse(virtMemFun.isFinal()); + } + + public void testOverrideVirtualMemberFunction() throws Exception { + IBinding[] bindings = findQualifiedName(pdom, "F::virtualMemberFunction"); + assertEquals(1, bindings.length); + assertInstance(bindings[0], ICPPMethod.class); + ICPPMethod virtMemFun = (ICPPMethod) bindings[0]; + assertTrue(virtMemFun.isOverride()); + assertFalse(virtMemFun.isFinal()); + } + + public void testOverrideFinalVirtualMemberFunction() throws Exception { + IBinding[] bindings = findQualifiedName(pdom, "G::virtualMemberFunction"); + assertEquals(1, bindings.length); + assertInstance(bindings[0], ICPPMethod.class); + ICPPMethod virtMemFun = (ICPPMethod) bindings[0]; + assertTrue(virtMemFun.isOverride()); + assertTrue(virtMemFun.isFinal()); + } } diff --git a/core/org.eclipse.cdt.core.tests/resources/pdomtests/classTests/class.cpp b/core/org.eclipse.cdt.core.tests/resources/pdomtests/classTests/class.cpp index 401a5a257d1..6a606e8e3df 100644 --- a/core/org.eclipse.cdt.core.tests/resources/pdomtests/classTests/class.cpp +++ b/core/org.eclipse.cdt.core.tests/resources/pdomtests/classTests/class.cpp @@ -32,3 +32,6 @@ class D { public: D(D &) {} }; + +class E final : public A { +}; diff --git a/core/org.eclipse.cdt.core.tests/resources/pdomtests/methodTests/inheritance.cpp b/core/org.eclipse.cdt.core.tests/resources/pdomtests/methodTests/inheritance.cpp index 9c218bf5bce..06996a5b229 100644 --- a/core/org.eclipse.cdt.core.tests/resources/pdomtests/methodTests/inheritance.cpp +++ b/core/org.eclipse.cdt.core.tests/resources/pdomtests/methodTests/inheritance.cpp @@ -39,6 +39,18 @@ struct B { struct D : public A, public B {}; +struct E { + virtual void virtualMemberFunction(){} +}; + +struct F : public E { + void virtualMemberFunction() override{} +}; + +struct G : public F { + void virtualMemberFunction() override final{} +}; + class Class2 : public Class1 { public: void pureVirtualMethod(); diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterDeclSpecTestSource.awts b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterDeclSpecTestSource.awts index 542373ff4c8..bb20b9eae41 100644 --- a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterDeclSpecTestSource.awts +++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterDeclSpecTestSource.awts @@ -181,3 +181,11 @@ decltype(i) j = 3; int i; typeof i j = 3; +//!CPPCompositeTypeSpecifier declared final +//%CPP +class Base +{ +}; +class TestClass final : public Base +{ +}; diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterDeclaratorTestSource.awts b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterDeclaratorTestSource.awts index 97c1ba19ac8..bb26697b63e 100644 --- a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterDeclaratorTestSource.awts +++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterDeclaratorTestSource.awts @@ -117,3 +117,32 @@ int&& foo(int&& a) char&& b; } +//!ICPPASTFunctionDeclarator in member function declared final +//%CPP +struct S +{ + virtual void memFun() final; +}; + +//!ICPPASTFunctionDeclarator in member function declared override +//%CPP +struct S +{ + virtual void memFun() override; +}; + +//!ICPPASTFunctionDeclarator in member function declared override final +//%CPP +struct S +{ + virtual void memFun() override final; +}; + +//!ICPPASTFunctionDeclarator in member function definition declared final +//%CPP +struct S +{ + virtual void memFun() final + { + } +};
\ No newline at end of file |