diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index 12b26a5d3bc..699327071d4 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -3791,6 +3791,30 @@ public class AST2Tests extends AST2BaseTest { assertEquals("AA", ((ICPPMethod)methodAA).getClassOwner().getName()); } + // class B { + // public: + // void bar() {} + // }; + // class A { + // public: + // B* operator->() { return new B(); } + // void foo() {} + // }; + // + // void main() { + // A a, &aa=a, *ap= new A(); + // a.foo(); + // ap->foo(); + // aa.foo(); + // (*ap)->bar(); + // (&aa)->foo(); + // (&a)->foo(); + // } + public void test186736_variant2() throws Exception { + StringBuffer buffer = getContents(1)[0]; + IASTTranslationUnit tu= parseAndCheckBindings(buffer.toString(), ParserLanguage.CPP); + } + // typedef int int32; // int32 f(int32 (*p)) { // return *p; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java index a147e1db6be..aae203d5b5d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java @@ -369,7 +369,7 @@ public class CPPSemantics { { ICPPASTFieldReference fieldRef = (ICPPASTFieldReference) tempName.getParent(); implied = CPPVisitor.getExpressionType( fieldRef.getFieldOwner() ); - IType ultimateImplied= getUltimateType(implied, true); + IType ultimateImplied= getUltimateTypeUptoPointers(implied); if( prop != STRING_LOOKUP_PROPERTY && fieldRef.isPointerDereference() && ultimateImplied instanceof ICPPClassType) { ICPPFunction operator= findOperator(fieldRef, (ICPPClassType) ultimateImplied); try { @@ -2891,6 +2891,29 @@ public class CPPSemantics { } } + /** + * Descends into type containers, stopping at pointer or + * pointer-to-member types. + * @param type + * @return the ultimate type contained inside the specified type + */ + public static IType getUltimateTypeUptoPointers(IType type){ + try { + while( true ){ + if( type instanceof ITypedef ) + type = ((ITypedef)type).getType(); + else if( type instanceof IQualifierType ) + type = ((IQualifierType)type).getType(); + else if( type instanceof ICPPReferenceType ) + type = ((ICPPReferenceType)type).getType(); + else + return type; + } + } catch ( DOMException e ) { + return e.getProblem(); + } + } + static private boolean isCompleteType( IType type ){ type = getUltimateType( type, false ); if( type instanceof ICPPClassType && type instanceof ICPPInternalBinding ) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java index d4063769bea..290020c6b21 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java @@ -863,7 +863,7 @@ public class CPPVisitor { IASTExpression owner = ((ICPPASTFieldReference)parent).getFieldOwner(); IType type = getExpressionType( owner ); if( ((ICPPASTFieldReference)parent).isPointerDereference() ){ - type= CPPSemantics.getUltimateType(type, true); + type= CPPSemantics.getUltimateTypeUptoPointers(type); if( type instanceof ICPPClassType ){ ICPPFunction op = CPPSemantics.findOperator( (IASTFieldReference)parent, (ICPPClassType) type ); if( op != null ){ diff --git a/core/org.eclipse.cdt.ui.tests/resources/contentassist/CompletionTestStart.h b/core/org.eclipse.cdt.ui.tests/resources/contentassist/CompletionTestStart.h index 31c77dfd667..33da8f2c080 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/contentassist/CompletionTestStart.h +++ b/core/org.eclipse.cdt.ui.tests/resources/contentassist/CompletionTestStart.h @@ -68,3 +68,5 @@ namespace xNamespace { void xNamespaceFunction(){ } }; + + diff --git a/core/org.eclipse.cdt.ui.tests/resources/contentassist/CompletionTestStart41.cpp b/core/org.eclipse.cdt.ui.tests/resources/contentassist/CompletionTestStart41.cpp new file mode 100644 index 00000000000..3fceafaa635 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/contentassist/CompletionTestStart41.cpp @@ -0,0 +1,9 @@ +#include "CompletionTestStart41.h" + +void main() { + A a, &aa=a, *ap= new A(); + a.foo(); + ap-> +} + +// end \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui.tests/resources/contentassist/CompletionTestStart41.h b/core/org.eclipse.cdt.ui.tests/resources/contentassist/CompletionTestStart41.h new file mode 100644 index 00000000000..637a9bdb766 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/contentassist/CompletionTestStart41.h @@ -0,0 +1,11 @@ + +class B { +public: + void bar() {} +}; + +class A { + public: + B* operator->() { return new B(); } + void foo() {} +}; \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui.tests/resources/contentassist/CompletionTestStart42.cpp b/core/org.eclipse.cdt.ui.tests/resources/contentassist/CompletionTestStart42.cpp new file mode 100644 index 00000000000..a7e00e99ad5 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/contentassist/CompletionTestStart42.cpp @@ -0,0 +1,9 @@ +#include "CompletionTestStart41.h" + +void main() { + A a, &aa=a, *ap= new A(); + a.foo(); + a-> +} + +// end \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTest_MemberReference_Arrow_NoPrefix2.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTest_MemberReference_Arrow_NoPrefix2.java new file mode 100644 index 00000000000..50ddfeced90 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTest_MemberReference_Arrow_NoPrefix2.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 Symbian Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Symbian - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.tests.text.contentassist2; +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * Test operator is followed during member reference + */ +public class CompletionTest_MemberReference_Arrow_NoPrefix2 extends CompletionProposalsBaseTest{ + private final String fileName = "CompletionTestStart41.cpp"; + private final String fileFullPath ="resources/contentassist/" + fileName; + private final String headerFileName = "CompletionTestStart41.h"; + private final String headerFileFullPath ="resources/contentassist/" + headerFileName; + private final String expectedPrefix = ""; + private final String[] expectedResults = { + "A", "foo(void) void", + "operator ->(void) B *" + }; + + public CompletionTest_MemberReference_Arrow_NoPrefix2(String name) { + super(name); + } + + public static Test suite() { + TestSuite suite= new TestSuite(CompletionTest_MemberReference_Arrow_NoPrefix2.class.getName()); + suite.addTest(new CompletionTest_MemberReference_Arrow_NoPrefix2("testCompletionProposals")); + return suite; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getCompletionPosition() + */ + protected int getCompletionPosition() { + return getBuffer().indexOf(" ap-> ") + 5; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedPrefix() + */ + protected String getExpectedPrefix() { + return expectedPrefix; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedResultsValues() + */ + protected String[] getExpectedResultsValues() { + return expectedResults; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileName() + */ + protected String getFileName() { + return fileName; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileFullPath() + */ + protected String getFileFullPath() { + return fileFullPath; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileFullPath() + */ + protected String getHeaderFileFullPath() { + return headerFileFullPath; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileName() + */ + protected String getHeaderFileName() { + return headerFileName; + } + +} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTest_MemberReference_Arrow_NoPrefix3.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTest_MemberReference_Arrow_NoPrefix3.java new file mode 100644 index 00000000000..71b3f85c2e6 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTest_MemberReference_Arrow_NoPrefix3.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 Symbian Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Symbian - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.ui.tests.text.contentassist2; +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * Testing operator is not followed on pointer to class with overloaded operator -> + */ +public class CompletionTest_MemberReference_Arrow_NoPrefix3 extends CompletionProposalsBaseTest{ + private final String fileName = "CompletionTestStart42.cpp"; + private final String fileFullPath ="resources/contentassist/" + fileName; + private final String headerFileName = "CompletionTestStart41.h"; + private final String headerFileFullPath ="resources/contentassist/" + headerFileName; + private final String expectedPrefix = ""; + private final String[] expectedResults = { + "B", "bar(void) void" + }; + + public CompletionTest_MemberReference_Arrow_NoPrefix3(String name) { + super(name); + } + + public static Test suite() { + TestSuite suite= new TestSuite(CompletionTest_MemberReference_Arrow_NoPrefix3.class.getName()); + suite.addTest(new CompletionTest_MemberReference_Arrow_NoPrefix3("testCompletionProposals")); + return suite; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getCompletionPosition() + */ + protected int getCompletionPosition() { + return getBuffer().indexOf("a->")+3; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedPrefix() + */ + protected String getExpectedPrefix() { + return expectedPrefix; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedResultsValues() + */ + protected String[] getExpectedResultsValues() { + return expectedResults; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileName() + */ + protected String getFileName() { + return fileName; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileFullPath() + */ + protected String getFileFullPath() { + return fileFullPath; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileFullPath() + */ + protected String getHeaderFileFullPath() { + return headerFileFullPath; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileName() + */ + protected String getHeaderFileName() { + return headerFileName; + } + +} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/ContentAssist2TestSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/ContentAssist2TestSuite.java index 53fb3375b7c..0d38ad40d29 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/ContentAssist2TestSuite.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/ContentAssist2TestSuite.java @@ -42,6 +42,8 @@ public class ContentAssist2TestSuite extends TestSuite { addTest(CompletionTest_MacroRef_NoPrefix.suite()); addTest(CompletionTest_MacroRef_Prefix.suite()); addTest(CompletionTest_MemberReference_Arrow_NoPrefix.suite()); + addTest(CompletionTest_MemberReference_Arrow_NoPrefix2.suite()); + addTest(CompletionTest_MemberReference_Arrow_NoPrefix3.suite()); addTest(CompletionTest_MemberReference_Arrow_Prefix.suite()); addTest(CompletionTest_MemberReference_Arrow_Prefix2.suite()); addTest(CompletionTest_MemberReference_Dot_NoPrefix.suite());