1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-10 09:45:39 +02:00

Bug 398706 - 'T' in 'new T' gets resolved to CPPConstructor instead of

CPPClassType

Change-Id: I7fecc996736cfacb40ad4ee7af8619bd3b6d2a2a
Reviewed-on: https://git.eclipse.org/r/9824
Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
IP-Clean: Sergey Prigogin <eclipse.sprigogin@gmail.com>
Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
Nathan Ridge 2013-01-22 04:19:40 -05:00 committed by Sergey Prigogin
parent ca712e679a
commit 8fcd01b3c7
12 changed files with 233 additions and 117 deletions

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2012 IBM Corporation and others. * Copyright (c) 2004, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -329,9 +329,15 @@ public class AST2BaseTest extends BaseTestCase {
} }
static protected class CPPNameCollector extends ASTVisitor { static protected class CPPNameCollector extends ASTVisitor {
{ public CPPNameCollector() {
shouldVisitNames = true; this(false); // don't visit implicit names by default
} }
public CPPNameCollector(boolean shouldVisitImplicitNames) {
this.shouldVisitNames = true;
this.shouldVisitImplicitNames = shouldVisitImplicitNames;
}
public List<IASTName> nameList = new ArrayList<IASTName>(); public List<IASTName> nameList = new ArrayList<IASTName>();
@Override @Override

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2009, 2010 IBM Corporation and others. * Copyright (c) 2009, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -9,6 +9,7 @@
* Mike Kucera (IBM) * Mike Kucera (IBM)
* Sergey Prigogin (Google) * Sergey Prigogin (Google)
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Nathan Ridge
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser.tests.ast2; package org.eclipse.cdt.core.parser.tests.ast2;
@ -445,11 +446,11 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest {
IBinding f= bh.assertNonProblem("operator new(size_t b)", 12); IBinding f= bh.assertNonProblem("operator new(size_t b)", 12);
IASTImplicitName[] names = bh.getImplicitNames("new A;", 3); IASTImplicitName[] names = bh.getImplicitNames("new A;", 3);
assertEquals(1, names.length); assertEquals(2, names.length);
assertSame(m, names[0].resolveBinding()); assertSame(m, names[0].resolveBinding());
names = bh.getImplicitNames("new B;", 3); names = bh.getImplicitNames("new B;", 3);
assertEquals(1, names.length); assertEquals(2, names.length);
assertSame(f, names[0].resolveBinding()); assertSame(f, names[0].resolveBinding());
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2012 IBM Corporation and others. * Copyright (c) 2004, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -1201,10 +1201,10 @@ public class AST2CPPTests extends AST2BaseTest {
// } // }
public void testVirtualParentLookup() throws Exception { public void testVirtualParentLookup() throws Exception {
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP);
CPPNameCollector collector = new CPPNameCollector(); CPPNameCollector collector = new CPPNameCollector(true);
tu.accept(collector); tu.accept(collector);
assertEquals(collector.size(), 15); assertEquals(collector.size(), 16);
ICPPClassType D = (ICPPClassType) collector.getName(0).resolveBinding(); ICPPClassType D = (ICPPClassType) collector.getName(0).resolveBinding();
ICPPField x = (ICPPField) collector.getName(1).resolveBinding(); ICPPField x = (ICPPField) collector.getName(1).resolveBinding();
@ -1215,7 +1215,7 @@ public class AST2CPPTests extends AST2BaseTest {
assertInstances(collector, D, 3); assertInstances(collector, D, 3);
assertInstances(collector, C, 2); assertInstances(collector, C, 2);
assertInstances(collector, B, 2); assertInstances(collector, B, 2);
assertInstances(collector, A, 2); assertInstances(collector, A, 3);
assertInstances(collector, ctor, 1); assertInstances(collector, ctor, 1);
assertInstances(collector, x, 2); assertInstances(collector, x, 2);
} }
@ -1230,10 +1230,10 @@ public class AST2CPPTests extends AST2BaseTest {
// } // }
public void testAmbiguousVirtualParentLookup() throws Exception { public void testAmbiguousVirtualParentLookup() throws Exception {
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP);
CPPNameCollector collector = new CPPNameCollector(); CPPNameCollector collector = new CPPNameCollector(true);
tu.accept(collector); tu.accept(collector);
assertEquals(collector.size(), 15); assertEquals(collector.size(), 16);
ICPPClassType D = (ICPPClassType) collector.getName(0).resolveBinding(); ICPPClassType D = (ICPPClassType) collector.getName(0).resolveBinding();
ICPPField x1 = (ICPPField) collector.getName(1).resolveBinding(); ICPPField x1 = (ICPPField) collector.getName(1).resolveBinding();
@ -1241,13 +1241,13 @@ public class AST2CPPTests extends AST2BaseTest {
ICPPClassType B = (ICPPClassType) collector.getName(4).resolveBinding(); ICPPClassType B = (ICPPClassType) collector.getName(4).resolveBinding();
ICPPClassType A = (ICPPClassType) collector.getName(6).resolveBinding(); ICPPClassType A = (ICPPClassType) collector.getName(6).resolveBinding();
ICPPConstructor ctor = A.getConstructors()[0]; ICPPConstructor ctor = A.getConstructors()[0];
IProblemBinding x2 = (IProblemBinding) collector.getName(14).resolveBinding(); IProblemBinding x2 = (IProblemBinding) collector.getName(15).resolveBinding();
assertEquals(x2.getID(), IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP); assertEquals(x2.getID(), IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP);
assertInstances(collector, D, 3); assertInstances(collector, D, 3);
assertInstances(collector, C, 2); assertInstances(collector, C, 2);
assertInstances(collector, B, 2); assertInstances(collector, B, 2);
assertInstances(collector, A, 2); assertInstances(collector, A, 3);
assertInstances(collector, ctor, 1); assertInstances(collector, ctor, 1);
assertInstances(collector, x1, 1); assertInstances(collector, x1, 1);
} }
@ -1843,7 +1843,7 @@ public class AST2CPPTests extends AST2BaseTest {
ICPPMethod dtor = (ICPPMethod) col.getName(13).resolveBinding(); ICPPMethod dtor = (ICPPMethod) col.getName(13).resolveBinding();
assertNotNull(dtor); assertNotNull(dtor);
assertEquals(dtor.getName(), "~C"); //$NON-NLS-1$ assertEquals(dtor.getName(), "~C"); //$NON-NLS-1$
assertInstances(col, C, 6); assertInstances(col, C, 7);
assertInstances(col, op, 3); assertInstances(col, op, 3);
assertInstances(col, other, 4); assertInstances(col, other, 4);
@ -1993,7 +1993,7 @@ public class AST2CPPTests extends AST2BaseTest {
assertInstances(col, pb, 2); assertInstances(col, pb, 2);
assertInstances(col, mutate, 2); assertInstances(col, mutate, 2);
assertInstances(col, B, 2); assertInstances(col, B, 3);
} }
// struct S { int i; }; // struct S { int i; };
@ -2511,7 +2511,7 @@ public class AST2CPPTests extends AST2BaseTest {
// } // }
public void testBug86267() throws Exception { public void testBug86267() throws Exception {
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP);
CPPNameCollector col = new CPPNameCollector(); CPPNameCollector col = new CPPNameCollector(true);
tu.accept(col); tu.accept(col);
ICPPClassType D1 = (ICPPClassType) col.getName(2).resolveBinding(); ICPPClassType D1 = (ICPPClassType) col.getName(2).resolveBinding();
@ -2549,7 +2549,7 @@ public class AST2CPPTests extends AST2BaseTest {
ICPPMethod op = (ICPPMethod) col.getName(3).resolveBinding(); ICPPMethod op = (ICPPMethod) col.getName(3).resolveBinding();
IParameter other = (IParameter) col.getName(5).resolveBinding(); IParameter other = (IParameter) col.getName(5).resolveBinding();
assertInstances(col, C, 6); assertInstances(col, C, 7);
assertInstances(col, f, 2); assertInstances(col, f, 2);
assertInstances(col, op, 3); assertInstances(col, op, 3);
assertInstances(col, other, 4); assertInstances(col, other, 4);
@ -4052,11 +4052,11 @@ public class AST2CPPTests extends AST2BaseTest {
// X x = new X(y); // X x = new X(y);
public void testBug90654_1() throws Exception { public void testBug90654_1() throws Exception {
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP);
CPPNameCollector col = new CPPNameCollector(); CPPNameCollector col = new CPPNameCollector(true);
tu.accept(col); tu.accept(col);
ICPPConstructor ctor1 = (ICPPConstructor) col.getName(1).resolveBinding(); ICPPConstructor ctor1 = (ICPPConstructor) col.getName(1).resolveBinding();
ICPPConstructor ctor = (ICPPConstructor) col.getName(11).resolveBinding(); ICPPConstructor ctor = (ICPPConstructor) col.getName(12).resolveBinding();
assertSame(ctor, ctor1); assertSame(ctor, ctor1);
} }
@ -8382,20 +8382,24 @@ public class AST2CPPTests extends AST2BaseTest {
// fH({1}); // H(G(1)) // fH({1}); // H(G(1))
// } // }
public void testListInitialization_302412f() throws Exception { public void testListInitialization_302412f() throws Exception {
ICPPConstructor ctor;
IProblemBinding problem; IProblemBinding problem;
String code= getAboveComment(); String code= getAboveComment();
BindingAssertionHelper bh= new BindingAssertionHelper(code, true); BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
bh.assertProblem("f({1,1})", 1); bh.assertProblem("f({1,1})", 1);
ctor= bh.assertNonProblem("F({1,1})", 1); bh.assertImplicitName("F({1,1})", 1, ICPPConstructor.class);
bh.assertNonProblem("fF({1,1})", 2); bh.assertNonProblem("fF({1,1})", 2);
bh.assertNonProblem("fG(1)", 2); bh.assertNonProblem("fG(1)", 2);
bh.assertNonProblem("fG({1})", 2); bh.assertNonProblem("fG({1})", 2);
ctor= bh.assertNonProblem("H(1)", 1); bh.assertImplicitName("H(1)", 1, ICPPConstructor.class);
problem= bh.assertProblem("H({1})", 1); bh.assertNoImplicitName("H({1})", 1);
assertEquals(IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, problem.getID()); // TODO(nathanridge): Perhaps we should store implicit names even if they
// resolve to ProblemBindings. Then we can do the stronger check in the
// 3 commented lines below.
//IASTImplicitName n= bh.assertImplicitName("H({1})", 1, IProblemBinding.class);
//problem= (IProblemBinding) n.resolveBinding();
//assertEquals(IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, problem.getID());
bh.assertProblem("fH(1)", 2); bh.assertProblem("fH(1)", 2);
bh.assertNonProblem("fH({1})", 2); bh.assertNonProblem("fH({1})", 2);
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2010 IBM Corporation and others. * Copyright (c) 2005, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Nathan Ridge
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser.tests.ast2; package org.eclipse.cdt.core.parser.tests.ast2;
@ -26,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IField;
@ -352,9 +354,10 @@ public class AST2SelectionParseTest extends AST2SelectionParseBaseTest {
assertTrue(node instanceof IASTTypeId); assertTrue(node instanceof IASTTypeId);
assertEquals(((IASTNamedTypeSpecifier)((IASTTypeId)node).getDeclSpecifier()).getName().toString(), "Gonzo"); //$NON-NLS-1$ assertEquals(((IASTNamedTypeSpecifier)((IASTTypeId)node).getDeclSpecifier()).getName().toString(), "Gonzo"); //$NON-NLS-1$
name = ((IASTNamedTypeSpecifier)((IASTTypeId)node).getDeclSpecifier()).getName(); name = ((IASTNamedTypeSpecifier)((IASTTypeId)node).getDeclSpecifier()).getName();
assertNotNull(name.resolveBinding()); name = TestUtil.findImplicitName(name);
assertTrue(name.resolveBinding() instanceof ICPPConstructor); IBinding binding = name.resolveBinding();
assertEquals(((ICPPConstructor)name.resolveBinding()).getName(), "Gonzo"); //$NON-NLS-1$ assertTrue(binding instanceof ICPPConstructor);
assertEquals(((ICPPConstructor)binding).getName(), "Gonzo"); //$NON-NLS-1$
break; break;
default: default:
assertTrue(node instanceof IASTName); assertTrue(node instanceof IASTName);
@ -736,9 +739,10 @@ public class AST2SelectionParseTest extends AST2SelectionParseBaseTest {
assertTrue(node instanceof IASTTypeId); assertTrue(node instanceof IASTTypeId);
assertEquals(((IASTNamedTypeSpecifier)((IASTTypeId)node).getDeclSpecifier()).getName().toString(), "B"); //$NON-NLS-1$ assertEquals(((IASTNamedTypeSpecifier)((IASTTypeId)node).getDeclSpecifier()).getName().toString(), "B"); //$NON-NLS-1$
IASTName name = ((IASTNamedTypeSpecifier)((IASTTypeId)node).getDeclSpecifier()).getName(); IASTName name = ((IASTNamedTypeSpecifier)((IASTTypeId)node).getDeclSpecifier()).getName();
assertNotNull(name.resolveBinding()); name = TestUtil.findImplicitName(name);
assertTrue(name.resolveBinding() instanceof ICPPConstructor); IBinding binding = name.resolveBinding();
assertEquals(((ICPPConstructor)name.resolveBinding()).getName(), "B"); //$NON-NLS-1$ assertTrue(binding instanceof ICPPConstructor);
assertEquals(((ICPPConstructor)binding).getName(), "B"); //$NON-NLS-1$
} }
public void testBug72712_2() throws Exception{ public void testBug72712_2() throws Exception{

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2012 IBM Corporation and others. * Copyright (c) 2005, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -2373,11 +2373,11 @@ public class AST2TemplateTests extends AST2BaseTest {
public void testCPPConstructorTemplateSpecialization() throws Exception { public void testCPPConstructorTemplateSpecialization() throws Exception {
IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true);
CPPNameCollector col = new CPPNameCollector(); CPPNameCollector col = new CPPNameCollector(true);
tu.accept(col); tu.accept(col);
ICPPASTTemplateId tid= (ICPPASTTemplateId) col.getName(20); IASTImplicitName tid= (IASTImplicitName) col.getName(20);
IASTName cn= col.getName(21); IASTName cn= col.getName(22);
assertInstance(cn.resolveBinding(), ICPPClassTemplate.class); // *D*<int>(5, 6) assertInstance(cn.resolveBinding(), ICPPClassTemplate.class); // *D*<int>(5, 6)
assertInstance(cn.resolveBinding(), ICPPClassType.class); // *D*<int>(5, 6) assertInstance(cn.resolveBinding(), ICPPClassType.class); // *D*<int>(5, 6)
assertInstance(tid.resolveBinding(), ICPPTemplateInstance.class); // *D<int>*(5, 6) assertInstance(tid.resolveBinding(), ICPPTemplateInstance.class); // *D<int>*(5, 6)
@ -3842,7 +3842,7 @@ public class AST2TemplateTests extends AST2BaseTest {
// }; // };
public void testNestedTemplates_259872_1() throws Exception { public void testNestedTemplates_259872_1() throws Exception {
BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP);
bh.assertNonProblem("A<B, int>", 9, ICPPConstructor.class); bh.assertNonProblem("A<B, int>", 9, ICPPClassType.class);
} }
// template <typename CL, typename T> // template <typename CL, typename T>
@ -3867,7 +3867,7 @@ public class AST2TemplateTests extends AST2BaseTest {
// }; // };
public void testNestedTemplates_259872_2() throws Exception { public void testNestedTemplates_259872_2() throws Exception {
BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP);
bh.assertNonProblem("A<B, int>", 9, ICPPConstructor.class); bh.assertNonProblem("A<B, int>", 9, ICPPClassType.class);
} }
// template <class T> // template <class T>

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2010 IBM Corporation and others. * Copyright (c) 2004, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -8,6 +8,7 @@
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Nathan Ridge
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser.tests.ast2; package org.eclipse.cdt.core.parser.tests.ast2;
@ -102,8 +103,12 @@ public class CompleteParser2Tests extends BaseTestCase {
} }
static private class CPPNameCollector extends ASTVisitor { static private class CPPNameCollector extends ASTVisitor {
{ public CPPNameCollector() {
shouldVisitNames = true; this(false); // don't visit implicit names by default
}
public CPPNameCollector(boolean shouldVisitImplicitNames) {
this.shouldVisitNames = true;
this.shouldVisitImplicitNames = shouldVisitImplicitNames;
} }
public List nameList = new ArrayList(); public List nameList = new ArrayList();
@Override @Override
@ -141,7 +146,7 @@ public class CompleteParser2Tests extends BaseTestCase {
if (nameCollector.getName(i).resolveBinding() == binding) if (nameCollector.getName(i).resolveBinding() == binding)
count++; count++;
assertEquals(count, num); assertEquals(num, count);
} }
protected void assertInstances(CNameCollector nameCollector, IBinding binding, int num) throws Exception { protected void assertInstances(CNameCollector nameCollector, IBinding binding, int num) throws Exception {
int count = 0; int count = 0;
@ -149,7 +154,7 @@ public class CompleteParser2Tests extends BaseTestCase {
if (nameCollector.getName(i).resolveBinding() == binding) if (nameCollector.getName(i).resolveBinding() == binding)
count++; count++;
assertEquals(count, num); assertEquals(num, count);
} }
protected IASTTranslationUnit parse(String code, boolean expectedToPass, protected IASTTranslationUnit parse(String code, boolean expectedToPass,
ParserLanguage lang) throws Exception { ParserLanguage lang) throws Exception {
@ -1112,14 +1117,14 @@ public class CompleteParser2Tests extends BaseTestCase {
public void testBug43503A() throws Exception { public void testBug43503A() throws Exception {
IASTTranslationUnit tu = parse("class SD_01 { void f_SD_01() {}}; int main(){ SD_01 * a = new SD_01(); a->f_SD_01(); } "); IASTTranslationUnit tu = parse("class SD_01 { void f_SD_01() {}}; int main(){ SD_01 * a = new SD_01(); a->f_SD_01(); } ");
CPPNameCollector col = new CPPNameCollector(); CPPNameCollector col = new CPPNameCollector(true);
tu.accept(col); tu.accept(col);
assertEquals(col.size(), 8); assertEquals(col.size(), 9);
ICPPClassType SD_01 = (ICPPClassType) col.getName(0).resolveBinding(); ICPPClassType SD_01 = (ICPPClassType) col.getName(0).resolveBinding();
ICPPMethod f_SD_01 = (ICPPMethod) col.getName(1).resolveBinding(); ICPPMethod f_SD_01 = (ICPPMethod) col.getName(1).resolveBinding();
ICPPConstructor ctor = SD_01.getConstructors()[0]; ICPPConstructor ctor = SD_01.getConstructors()[0];
assertInstances(col, SD_01, 2); assertInstances(col, SD_01, 3);
assertInstances(col, ctor, 1); assertInstances(col, ctor, 1);
assertInstances(col, f_SD_01, 2); assertInstances(col, f_SD_01, 2);
} }
@ -1204,10 +1209,10 @@ public class CompleteParser2Tests extends BaseTestCase {
buff.append("} \n"); buff.append("} \n");
IASTTranslationUnit tu = parse(buff.toString()); IASTTranslationUnit tu = parse(buff.toString());
CPPNameCollector col = new CPPNameCollector(); CPPNameCollector col = new CPPNameCollector(true);
tu.accept(col); tu.accept(col);
assertEquals(col.size(), 17); assertEquals(col.size(), 18);
ICompositeType SD_02 = (ICompositeType) col.getName(0).resolveBinding(); ICompositeType SD_02 = (ICompositeType) col.getName(0).resolveBinding();
ICPPMethod f_SD_02 = (ICPPMethod) col.getName(1).resolveBinding(); ICPPMethod f_SD_02 = (ICPPMethod) col.getName(1).resolveBinding();
ICPPClassType SD_01 = (ICPPClassType) col.getName(2).resolveBinding(); ICPPClassType SD_01 = (ICPPClassType) col.getName(2).resolveBinding();
@ -1217,7 +1222,7 @@ public class CompleteParser2Tests extends BaseTestCase {
assertInstances(col, SD_02, 2); assertInstances(col, SD_02, 2);
assertInstances(col, f_SD_02, 2); assertInstances(col, f_SD_02, 2);
assertInstances(col, SD_01, 3); assertInstances(col, SD_01, 4);
assertInstances(col, ctor, 1); assertInstances(col, ctor, 1);
assertInstances(col, next, 2); assertInstances(col, next, 2);
assertInstances(col, f_SD_01, 4); assertInstances(col, f_SD_01, 4);
@ -1268,10 +1273,10 @@ public class CompleteParser2Tests extends BaseTestCase {
public void testBug44342() throws Exception { public void testBug44342() throws Exception {
IASTTranslationUnit tu = parse("class A { void f(){} void f(int){} }; int main(){ A * a = new A(); a->f();} "); IASTTranslationUnit tu = parse("class A { void f(){} void f(int){} }; int main(){ A * a = new A(); a->f();} ");
CPPNameCollector col = new CPPNameCollector(); CPPNameCollector col = new CPPNameCollector(true);
tu.accept(col); tu.accept(col);
assertEquals(col.size(), 10); assertEquals(col.size(), 11);
ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding();
ICPPMethod f1 = (ICPPMethod) col.getName(1).resolveBinding(); ICPPMethod f1 = (ICPPMethod) col.getName(1).resolveBinding();
ICPPMethod f2 = (ICPPMethod) col.getName(2).resolveBinding(); ICPPMethod f2 = (ICPPMethod) col.getName(2).resolveBinding();
@ -1279,7 +1284,7 @@ public class CompleteParser2Tests extends BaseTestCase {
ICPPConstructor ctor = A.getConstructors()[0]; ICPPConstructor ctor = A.getConstructors()[0];
IVariable a = (IVariable) col.getName(6).resolveBinding(); IVariable a = (IVariable) col.getName(6).resolveBinding();
assertInstances(col, A, 2); assertInstances(col, A, 3);
assertInstances(col, f1, 2); assertInstances(col, f1, 2);
assertInstances(col, f2, 1); assertInstances(col, f2, 1);
assertInstances(col, ctor, 1); assertInstances(col, ctor, 1);
@ -1420,23 +1425,23 @@ public class CompleteParser2Tests extends BaseTestCase {
buffer.append("void main() { N::A * a = new N::A(); a->f(); } "); buffer.append("void main() { N::A * a = new N::A(); a->f(); } ");
IASTTranslationUnit tu = parse(buffer.toString()); IASTTranslationUnit tu = parse(buffer.toString());
CPPNameCollector col = new CPPNameCollector(); CPPNameCollector col = new CPPNameCollector(true);
tu.accept(col); tu.accept(col);
assertEquals(col.size(), 13); assertEquals(col.size(), 14);
ICPPNamespace N = (ICPPNamespace) col.getName(0).resolveBinding(); ICPPNamespace N = (ICPPNamespace) col.getName(0).resolveBinding();
IFunction f = (IFunction) col.getName(1).resolveBinding(); IFunction f = (IFunction) col.getName(1).resolveBinding();
ICPPClassType A = (ICPPClassType) col.getName(2).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(2).resolveBinding();
ICPPConstructor ctor = A.getConstructors()[0]; ICPPConstructor ctor = A.getConstructors()[0];
IProblemBinding fp = (IProblemBinding) col.getName(12).resolveBinding(); IProblemBinding fp = (IProblemBinding) col.getName(13).resolveBinding();
assertEquals(fp.getID(), IProblemBinding.SEMANTIC_NAME_NOT_FOUND); assertEquals(fp.getID(), IProblemBinding.SEMANTIC_NAME_NOT_FOUND);
assertInstances(col, N, 3); assertInstances(col, N, 3);
assertInstances(col, f, 1); assertInstances(col, f, 1);
assertInstances(col, A, 3); assertInstances(col, A, 5);
assertInstances(col, ctor, 2); assertInstances(col, ctor, 1);
} }
public void testBug43110() throws Exception { public void testBug43110() throws Exception {

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2002, 2010 IBM Corporation and others. * Copyright (c) 2002, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -8,6 +8,7 @@
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Nathan Ridge
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser.tests.ast2; package org.eclipse.cdt.core.parser.tests.ast2;
@ -37,6 +38,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
import org.eclipse.cdt.internal.core.model.CProject; import org.eclipse.cdt.internal.core.model.CProject;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
@ -296,8 +298,12 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest {
} }
IASTNode node = parse( code, startOffset, endOffset ); IASTNode node = parse( code, startOffset, endOffset );
assertTrue( node instanceof IASTName ); assertTrue( node instanceof IASTName );
assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPMethod );
IBinding binding = ((IASTName)node).resolveBinding(); IBinding binding = ((IASTName)node).resolveBinding();
if (binding instanceof ICPPClassType) {
node = TestUtil.findImplicitName(node);
binding = ((IASTName)node).resolveBinding();
}
assertTrue( binding instanceof ICPPMethod );
IName[] decls = null; IName[] decls = null;
switch( i ) switch( i )
{ {
@ -599,14 +605,15 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest {
int startIndex = code.indexOf( "new B" ) + 4; //$NON-NLS-1$ int startIndex = code.indexOf( "new B" ) + 4; //$NON-NLS-1$
IASTNode node = parse( code, startIndex, startIndex + 1 ); IASTNode node = parse( code, startIndex, startIndex + 1 );
node = TestUtil.findImplicitName(node);
assertTrue( node instanceof IASTName ); assertTrue( node instanceof IASTName );
assertTrue( ((IASTName) node).resolveBinding() instanceof ICPPConstructor ); assertTrue( ((IASTName) node).resolveBinding() instanceof ICPPConstructor );
assertEquals( ((IASTName)node).toString(), "B" ); //$NON-NLS-1$ assertEquals( ((IASTName)node).toString(), "B" ); //$NON-NLS-1$
IName[] decls = getDeclarationOffTU((IASTName)node); IName[] decls = getDeclarationOffTU((IASTName)node);
assertEquals(decls.length, 1); assertEquals(decls.length, 1);
assertEquals( decls[0].toString(), "B" ); //$NON-NLS-1$ assertEquals( decls[0].toString(), "B" ); //$NON-NLS-1$
assertEquals( ((ASTNode)decls[0]).getOffset(), 17); assertEquals( 17, ((ASTNode)decls[0]).getOffset() );
assertEquals( ((ASTNode)decls[0]).getLength(), 1); assertEquals( 1, ((ASTNode)decls[0]).getLength() );
} }
public void testBug72712_2() throws Exception{ public void testBug72712_2() throws Exception{
@ -1111,6 +1118,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest {
int index = code.indexOf("Point(10)"); //$NON-NLS-1$ int index = code.indexOf("Point(10)"); //$NON-NLS-1$
IASTNode node = parse( code, index, index + 5, true ); IASTNode node = parse( code, index, index + 5, true );
node = TestUtil.findImplicitName(node);
assertTrue( node instanceof IASTName ); assertTrue( node instanceof IASTName );
assertTrue( ((IASTName) node).resolveBinding() instanceof ICPPConstructor ); assertTrue( ((IASTName) node).resolveBinding() instanceof ICPPConstructor );
assertEquals( ((IASTName)node).toString(), "Point" ); //$NON-NLS-1$ assertEquals( ((IASTName)node).toString(), "Point" ); //$NON-NLS-1$

View file

@ -0,0 +1,36 @@
/*******************************************************************************
* Copyright (c) 2013 Nathan Ridge.
* 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:
* Nathan Ridge - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.ast2;
import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
public class TestUtil {
/**
* Searches the AST upward from the given starting node to find the
* nearest IASTImplicitNameOwner and returns its first implicit name,
* or null if it has no implicit names.
*/
public static IASTName findImplicitName(IASTNode node) {
while (node != null) {
if (node instanceof IASTImplicitNameOwner) {
IASTImplicitName[] implicitNames = ((IASTImplicitNameOwner) node).getImplicitNames();
if (implicitNames != null && implicitNames.length > 0) {
return implicitNames[0];
}
}
node = node.getParent();
}
return null;
}
}

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006, 2012 Symbian Software Systems and others. * Copyright (c) 2006, 2013 Symbian Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -10,6 +10,7 @@
* IBM Corporation * IBM Corporation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google) * Sergey Prigogin (Google)
* Nathan Ridge
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.index.tests; package org.eclipse.cdt.internal.index.tests;
@ -83,7 +84,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
super.tearDown(); super.tearDown();
} }
protected IASTName findName(String section, int len) { protected IASTName findName(String section, int len, boolean preferImplicitName) {
if (len == 0) if (len == 0)
len= section.length(); len= section.length();
for (int i = 0; i < strategy.getAstCount(); i++) { for (int i = 0; i < strategy.getAstCount(); i++) {
@ -91,16 +92,28 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
final IASTNodeSelector nodeSelector = ast.getNodeSelector(null); final IASTNodeSelector nodeSelector = ast.getNodeSelector(null);
final int offset = strategy.getAstSource(i).indexOf(section); final int offset = strategy.getAstSource(i).indexOf(section);
if (offset >= 0) { if (offset >= 0) {
if (preferImplicitName) {
return nodeSelector.findImplicitName(offset, len);
} else {
IASTName name= nodeSelector.findName(offset, len); IASTName name= nodeSelector.findName(offset, len);
if (name == null) if (name == null)
name= nodeSelector.findImplicitName(offset, len); name= nodeSelector.findImplicitName(offset, len);
return name; return name;
} }
} }
}
return null; return null;
} }
protected IASTName findName(String section, int len) {
return findName(section, len, false);
}
protected IASTName findImplicitName(String section, int len) {
return findName(section, len, true);
}
/** /**
* Attempts to get an IBinding from the initial specified number of characters * Attempts to get an IBinding from the initial specified number of characters
* from the specified code fragment. Fails the test if * from the specified code fragment. Fails the test if
@ -130,8 +143,36 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
return clazz.cast(binding); return clazz.cast(binding);
} }
/**
* Attempts to get an IBinding attached to an implicit name from the initial specified
* number of characters from the specified code fragment. Fails the test if
* <ul>
* <li> There is not a unique implicit name with the specified criteria
* <li> The binding associated with the implicit name is null or a problem binding
* <li> The binding is not an instance of the specified class
* </ul>
* @param section the code fragment to search for in the AST. The first occurrence of an identical section is used.
* @param len the length of the specified section to use as a name
* @param clazz an expected class type or interface that the binding should extend/implement
* @return the associated implicit name's binding
*/
protected <T> T getBindingFromImplicitASTName(String section, int len, Class<T> clazz, Class ... cs) {
if (len < 1) {
len= section.length()+len;
}
IASTName name= findImplicitName(section, len);
assertNotNull("Name not found for \"" + section + "\"", name);
assertEquals(section.substring(0, len), name.getRawSignature());
IBinding binding = name.resolveBinding();
assertNotNull("No binding for " + name.getRawSignature(), binding);
assertFalse("Binding is a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass()));
assertInstance(binding, clazz, cs);
return clazz.cast(binding);
}
/* /*
* @see IndexBindingResolutionTestBase#getBindingFromASTName(Class, String, int) * @see IndexBindingResolutionTestBase#getBindingFromASTName(String, int, Class<T>, Class ...)
*/ */
protected <T extends IBinding> T getBindingFromASTName(String section, int len) { protected <T extends IBinding> T getBindingFromASTName(String section, int len) {
if (len <= 0) if (len <= 0)
@ -147,6 +188,23 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
return (T) binding; return (T) binding;
} }
/*
* @see IndexBindingResolutionTestBase#getBindingFromImplicitASTName(String, int, Class<T>, Class ...)
*/
protected <T extends IBinding> T getBindingFromImplicitASTName(String section, int len) {
if (len <= 0)
len += section.length();
IASTName name= findImplicitName(section, len);
assertNotNull("Name not found for \"" + section + "\"", name);
assertEquals(section.substring(0, len), name.getRawSignature());
IBinding binding = name.resolveBinding();
assertNotNull("No binding for " + name.getRawSignature(), binding);
assertFalse("Binding is a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass()));
return (T) binding;
}
/** /**
* Attempts to verify that the resolved binding for a name is a problem binding. * Attempts to verify that the resolved binding for a name is a problem binding.
* @param section the code fragment to search for in the AST. The first occurrence of an identical section is used. * @param section the code fragment to search for in the AST. The first occurrence of an identical section is used.

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007, 2010 Symbian Software Systems and others. * Copyright (c) 2007, 2013 Symbian Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -9,6 +9,7 @@
* Andrew Ferguson (Symbian) - Initial implementation * Andrew Ferguson (Symbian) - Initial implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google) * Sergey Prigogin (Google)
* Nathan Ridge
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.index.tests; package org.eclipse.cdt.internal.index.tests;
@ -1490,9 +1491,7 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
assertFalse(b0 instanceof IIndexBinding); assertFalse(b0 instanceof IIndexBinding);
ICPPConstructor b1 = getBindingFromASTName("B(int x)", 1, ICPPConstructor.class); ICPPConstructor b1 = getBindingFromASTName("B(int x)", 1, ICPPConstructor.class);
assertFalse(b1 instanceof IIndexBinding); assertFalse(b1 instanceof IIndexBinding);
ICPPConstructor b2 = getBindingFromASTName("B(0)", 1, ICPPConstructor.class); ICPPClassType b2 = getBindingFromASTName("B(0)", 1, ICPPClassType.class);
assertFalse(b2 instanceof IIndexBinding);
assertEquals(b1, b2);
ICPPMethod b3 = getBindingFromASTName("m(0)", 1, ICPPMethod.class); ICPPMethod b3 = getBindingFromASTName("m(0)", 1, ICPPMethod.class);
assertFalse(b3 instanceof IIndexBinding); assertFalse(b3 instanceof IIndexBinding);
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007, 2012 Symbian Software Systems and others. * Copyright (c) 2007, 2013 Symbian Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -300,7 +300,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
// X<A> xa= new X<A>(); // X<A> xa= new X<A>();
// } // }
public void testUnindexedConstructorInstance() { public void testUnindexedConstructorInstance() {
IBinding b0= getBindingFromASTName("X<A>()", 4); IBinding b0= getBindingFromImplicitASTName("X<A>()", 4);
assertInstance(b0, ICPPConstructor.class); assertInstance(b0, ICPPConstructor.class);
} }
@ -409,7 +409,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
// assertEquals(3, _ctcs.length); // two implicit plus the constructor template // assertEquals(3, _ctcs.length); // two implicit plus the constructor template
IBinding b2= getBindingFromASTName("D<int>(", 1); IBinding b2= getBindingFromASTName("D<int>(", 1);
IBinding b3= getBindingFromASTName("D<int>(", 6); IBinding b3= getBindingFromImplicitASTName("D<int>(", 6);
assertInstance(b2, ICPPClassTemplate.class); // *D*<int>(5, 6) assertInstance(b2, ICPPClassTemplate.class); // *D*<int>(5, 6)
assertInstance(b2, ICPPClassType.class); // *D*<int>(5, 6) assertInstance(b2, ICPPClassType.class); // *D*<int>(5, 6)

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2012 IBM Corporation and others. * Copyright (c) 2004, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -550,14 +550,6 @@ public class CPPSemantics {
if (parent instanceof ICPPASTConstructorChainInitializer) { if (parent instanceof ICPPASTConstructorChainInitializer) {
return true; return true;
} }
if (parent instanceof ICPPASTNamedTypeSpecifier) {
parent= parent.getParent();
if (parent instanceof IASTTypeId && parent.getParent() instanceof ICPPASTNewExpression) {
IASTDeclarator dtor = ((IASTTypeId) parent).getAbstractDeclarator();
if (dtor != null && dtor.getPointerOperators().length == 0)
return true;
}
}
return false; return false;
} }
@ -3103,27 +3095,43 @@ public class CPPSemantics {
return null; return null;
IType type = ((ICPPVariable) binding).getType(); IType type = ((ICPPVariable) binding).getType();
try {
type = SemanticUtil.getNestedType(type, TDEF | CVTYPE); type = SemanticUtil.getNestedType(type, TDEF | CVTYPE);
if (!(type instanceof ICPPClassType)) if (!(type instanceof ICPPClassType))
return null; return null;
if (type instanceof ICPPClassTemplate || type instanceof ICPPUnknownType || type instanceof ISemanticProblem) if (type instanceof ICPPClassTemplate || type instanceof ICPPUnknownType || type instanceof ISemanticProblem)
return null; return null;
final ICPPClassType classType = (ICPPClassType) type; return findImplicitlyCalledConstructor((ICPPClassType) type, initializer, name);
}
public static ICPPConstructor findImplicitlyCalledConstructor(ICPPASTNewExpression expr) {
IType type = getNestedType(expr.getExpressionType(), TDEF | REF | CVTYPE);
if (!(type instanceof IPointerType))
return null;
type = ((IPointerType) type).getType();
if (type instanceof ICPPClassType) {
return findImplicitlyCalledConstructor((ICPPClassType) type,
expr.getInitializer(), expr.getTypeId());
}
return null;
}
private static ICPPConstructor findImplicitlyCalledConstructor(ICPPClassType type, IASTInitializer initializer,
IASTNode typeId) {
try {
if (initializer instanceof IASTEqualsInitializer) { if (initializer instanceof IASTEqualsInitializer) {
// Copy initialization. // Copy initialization.
IASTEqualsInitializer eqInit= (IASTEqualsInitializer) initializer; IASTEqualsInitializer eqInit= (IASTEqualsInitializer) initializer;
ICPPASTInitializerClause initClause = (ICPPASTInitializerClause) eqInit.getInitializerClause(); ICPPASTInitializerClause initClause = (ICPPASTInitializerClause) eqInit.getInitializerClause();
final ICPPEvaluation evaluation = initClause.getEvaluation(); final ICPPEvaluation evaluation = initClause.getEvaluation();
IType sourceType= evaluation.getTypeOrFunctionSet(name); IType sourceType= evaluation.getTypeOrFunctionSet(typeId);
ValueCategory isLValue= evaluation.getValueCategory(name); ValueCategory isLValue= evaluation.getValueCategory(typeId);
if (sourceType != null) { if (sourceType != null) {
Cost c; Cost c;
if (calculateInheritanceDepth(sourceType, classType, name) >= 0) { if (calculateInheritanceDepth(sourceType, type, typeId) >= 0) {
c = Conversions.copyInitializationOfClass(isLValue, sourceType, classType, false, name); c = Conversions.copyInitializationOfClass(isLValue, sourceType, type, false, typeId);
} else { } else {
c = Conversions.checkImplicitConversionSequence(type, sourceType, isLValue, UDCMode.ALLOWED, Context.ORDINARY, name); c = Conversions.checkImplicitConversionSequence(type, sourceType, isLValue, UDCMode.ALLOWED, Context.ORDINARY, typeId);
} }
if (c.converts()) { if (c.converts()) {
ICPPFunction f = c.getUserDefinedConversion(); ICPPFunction f = c.getUserDefinedConversion();
@ -3136,7 +3144,7 @@ public class CPPSemantics {
// List initialization. // List initialization.
ICPPEvaluation eval= ((ICPPASTInitializerList) initializer).getEvaluation(); ICPPEvaluation eval= ((ICPPASTInitializerList) initializer).getEvaluation();
if (eval instanceof EvalInitList) { if (eval instanceof EvalInitList) {
Cost c= Conversions.listInitializationSequence((EvalInitList) eval, type, UDCMode.ALLOWED, true, name); Cost c= Conversions.listInitializationSequence((EvalInitList) eval, type, UDCMode.ALLOWED, true, typeId);
if (c.converts()) { if (c.converts()) {
ICPPFunction f = c.getUserDefinedConversion(); ICPPFunction f = c.getUserDefinedConversion();
if (f instanceof ICPPConstructor) if (f instanceof ICPPConstructor)
@ -3145,11 +3153,11 @@ public class CPPSemantics {
} }
} else if (initializer instanceof ICPPASTConstructorInitializer) { } else if (initializer instanceof ICPPASTConstructorInitializer) {
// Direct initialization. // Direct initialization.
return findImplicitlyCalledConstructor(classType, return findImplicitlyCalledConstructor(type,
(ICPPASTConstructorInitializer) initializer, name); (ICPPASTConstructorInitializer) initializer, typeId);
} else if (initializer == null) { } else if (initializer == null) {
// Default initialization. // Default initialization.
ICPPConstructor[] ctors = ClassTypeHelper.getConstructors(classType, name); ICPPConstructor[] ctors = ClassTypeHelper.getConstructors(type, typeId);
for (ICPPConstructor ctor : ctors) { for (ICPPConstructor ctor : ctors) {
if (ctor.getRequiredArgumentCount() == 0) if (ctor.getRequiredArgumentCount() == 0)
return ctor; return ctor;
@ -3161,19 +3169,6 @@ public class CPPSemantics {
return null; return null;
} }
public static ICPPConstructor findImplicitlyCalledConstructor(ICPPASTNewExpression expr) {
IType type = getNestedType(expr.getExpressionType(), TDEF | REF | CVTYPE);
if (!(type instanceof IPointerType))
return null;
type = ((IPointerType) type).getType();
IASTInitializer initializer = expr.getInitializer();
if (type instanceof ICPPClassType && initializer instanceof ICPPASTConstructorInitializer) {
return findImplicitlyCalledConstructor((ICPPClassType) type,
(ICPPASTConstructorInitializer) initializer, expr.getTypeId());
}
return null;
}
private static ICPPConstructor findImplicitlyCalledConstructor(ICPPClassType classType, private static ICPPConstructor findImplicitlyCalledConstructor(ICPPClassType classType,
ICPPASTConstructorInitializer initializer, IASTNode typeId) { ICPPASTConstructorInitializer initializer, IASTNode typeId) {
final IASTInitializerClause[] arguments = initializer.getArguments(); final IASTInitializerClause[] arguments = initializer.getArguments();