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 d2fc4fb0aac..d67f88df8ed 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 @@ -836,11 +836,12 @@ public class AST2CPPTests extends AST2BaseTest { ICPPClassType C = (ICPPClassType) collector.getName( 2 ).resolveBinding(); ICPPClassType B = (ICPPClassType) collector.getName( 4 ).resolveBinding(); ICPPClassType A = (ICPPClassType) collector.getName( 6 ).resolveBinding(); - + ICPPConstructor ctor = A.getConstructors()[0]; assertInstances( collector, D, 3 ); assertInstances( collector, C, 2 ); assertInstances( collector, B, 2 ); - assertInstances( collector, A, 3 ); + assertInstances( collector, A, 2 ); + assertInstances( collector, ctor, 1 ); assertInstances( collector, x, 2 ); } @@ -866,14 +867,15 @@ public class AST2CPPTests extends AST2BaseTest { ICPPClassType C = (ICPPClassType) collector.getName( 2 ).resolveBinding(); ICPPClassType B = (ICPPClassType) collector.getName( 4 ).resolveBinding(); ICPPClassType A = (ICPPClassType) collector.getName( 6 ).resolveBinding(); - + ICPPConstructor ctor = A.getConstructors()[0]; IProblemBinding x2 = (IProblemBinding) collector.getName( 14 ).resolveBinding(); assertEquals( x2.getID(), IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP ); assertInstances( collector, D, 3 ); assertInstances( collector, C, 2 ); assertInstances( collector, B, 2 ); - assertInstances( collector, A, 3 ); + assertInstances( collector, A, 2 ); + assertInstances( collector, ctor, 1 ); assertInstances( collector, x1, 1 ); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java index 53aa96625de..4759b52c95c 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java @@ -48,6 +48,7 @@ import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.internal.core.dom.parser.c.CKnRParameter; import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; +import org.eclipse.cdt.internal.core.dom.parser.c.ICBinding; /** * @author dsteffle @@ -453,7 +454,7 @@ public class AST2KnRTests extends AST2BaseTest { IASTName A_struct_name1 = ((IASTCompositeTypeSpecifier)A_struct.getDeclSpecifier()).getName(); assertEquals( A_struct_name1.toString(), "A_struct" ); //$NON-NLS-1$ ICompositeType A_struct_type1 = (ICompositeType)A_struct_name1.resolveBinding(); - assertEquals( A_struct_type1.getPhysicalNode(), A_struct.getDeclSpecifier() ); + assertEquals( ((ICBinding)A_struct_type1).getPhysicalNode(), A_struct.getDeclSpecifier() ); List fields = A_struct_type1.getFields(); IField a1 = (IField)fields.get(0); IField c1 = (IField)fields.get(1); @@ -515,7 +516,7 @@ public class AST2KnRTests extends AST2BaseTest { IASTExpressionStatement stmt1 = (IASTExpressionStatement)f_def_body.getStatements()[0]; IASTExpressionStatement stmt2 = (IASTExpressionStatement)f_def_body.getStatements()[1]; IASTName a2 = ((IASTFieldReference)((IASTBinaryExpression)stmt1.getExpression()).getOperand1()).getFieldName(); - assertEquals( ((IASTName)a1.getPhysicalNode()).resolveBinding(), a2.resolveBinding() ); + assertEquals( ((IASTName)((ICBinding)a1).getPhysicalNode()).resolveBinding(), a2.resolveBinding() ); IASTName x3 = ((IASTIdExpression)((IASTFieldReference)((IASTBinaryExpression)stmt1.getExpression()).getOperand1()).getFieldOwner()).getName(); assertEquals( x2.resolveBinding(), x3.resolveBinding() ); assertEquals( ((IASTBinaryExpression)stmt1.getExpression()).getOperand2().toString(), "0" ); //$NON-NLS-1$ @@ -525,8 +526,8 @@ public class AST2KnRTests extends AST2BaseTest { IASTName x4 = ((IASTIdExpression)((IASTFieldReference)((IASTArraySubscriptExpression)((IASTBinaryExpression)stmt2.getExpression()).getOperand1()).getArrayExpression()).getFieldOwner()).getName(); IASTName c3 = ((IASTFieldReference)((IASTArraySubscriptExpression)((IASTBinaryExpression)stmt2.getExpression()).getOperand2()).getArrayExpression()).getFieldName(); IASTName x5 = ((IASTIdExpression)((IASTFieldReference)((IASTArraySubscriptExpression)((IASTBinaryExpression)stmt2.getExpression()).getOperand1()).getArrayExpression()).getFieldOwner()).getName(); - assertEquals( ((IASTName)c1.getPhysicalNode()).resolveBinding(), c2.resolveBinding() ); - assertEquals( ((IASTName)c1.getPhysicalNode()).resolveBinding(), c3.resolveBinding() ); + assertEquals( ((IASTName)((ICBinding)c1).getPhysicalNode()).resolveBinding(), c2.resolveBinding() ); + assertEquals( ((IASTName)((ICBinding)c1).getPhysicalNode()).resolveBinding(), c3.resolveBinding() ); assertEquals( x3.resolveBinding(), x4.resolveBinding() ); assertEquals( x4.resolveBinding(), x5.resolveBinding() ); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java index c13177de660..d28c73d028a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java @@ -67,8 +67,8 @@ import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser; import org.eclipse.cdt.internal.core.dom.parser.c.ICParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor; -import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser; +import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPParserExtensionConfiguration; import org.eclipse.cdt.internal.core.parser.ParserException; import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner; @@ -1095,10 +1095,11 @@ public class CompleteParser2Tests extends TestCase { CPPVisitor.visitTranslationUnit( tu, col ); assertEquals( col.size(), 8 ); - ICompositeType SD_01 = (ICompositeType) col.getName(0).resolveBinding(); + ICPPClassType SD_01 = (ICPPClassType) col.getName(0).resolveBinding(); ICPPMethod f_SD_01 = (ICPPMethod) col.getName(1).resolveBinding(); - - assertInstances( col, SD_01, 3 ); + ICPPConstructor ctor = SD_01.getConstructors()[0]; + assertInstances( col, SD_01, 2 ); + assertInstances( col, ctor, 1 ); assertInstances( col, f_SD_01, 2 ); } @@ -1194,13 +1195,15 @@ public class CompleteParser2Tests extends TestCase { assertEquals( col.size(), 17 ); ICompositeType SD_02 = (ICompositeType) col.getName(0).resolveBinding(); ICPPMethod f_SD_02 = (ICPPMethod) col.getName(1).resolveBinding(); - ICompositeType SD_01 = (ICompositeType) col.getName(2).resolveBinding(); + ICPPClassType SD_01 = (ICPPClassType) col.getName(2).resolveBinding(); ICPPField next = (ICPPField) col.getName(4).resolveBinding(); ICPPMethod f_SD_01 = (ICPPMethod) col.getName(5).resolveBinding(); + ICPPConstructor ctor = SD_01.getConstructors()[0]; assertInstances( col, SD_02, 2 ); assertInstances( col, f_SD_02, 2 ); - assertInstances( col, SD_01, 4 ); + assertInstances( col, SD_01, 3 ); + assertInstances( col, ctor, 1 ); assertInstances( col, next, 2 ); assertInstances( col, f_SD_01, 4 ); } @@ -1237,11 +1240,38 @@ public class CompleteParser2Tests extends TestCase { public void testBug43951() throws Exception { - parse( "class B{ B(); ~B(); }; B::B(){} B::~B(){}" ); //$NON-NLS-1$ + IASTTranslationUnit tu = parse( "class B{ B(); ~B(); }; B::B(){} B::~B(){}" ); //$NON-NLS-1$ + CPPNameCollector col = new CPPNameCollector(); + CPPVisitor.visitTranslationUnit( tu, col ); + + assertEquals( col.size(), 9 ); + ICPPClassType B = (ICPPClassType) col.getName(0).resolveBinding(); + ICPPConstructor constructor = (ICPPConstructor) col.getName(1).resolveBinding(); + ICPPMethod destructor = (ICPPMethod) col.getName(2).resolveBinding(); + + assertInstances( col, B, 3 ); + assertInstances( col, constructor, 3 ); + assertInstances( col, destructor, 3 ); } public void testBug44342() throws Exception { - parse("class A { void f(){} void f(int){} }; int main(){ A * a = new A(); a->f();} "); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("class A { void f(){} void f(int){} }; int main(){ A * a = new A(); a->f();} "); //$NON-NLS-1$ + CPPNameCollector col = new CPPNameCollector(); + CPPVisitor.visitTranslationUnit( tu, col ); + + assertEquals( col.size(), 10 ); + ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); + ICPPMethod f1 = (ICPPMethod) col.getName(1).resolveBinding(); + ICPPMethod f2 = (ICPPMethod) col.getName(2).resolveBinding(); + + ICPPConstructor ctor = A.getConstructors()[0]; + IVariable a = (IVariable) col.getName( 6 ).resolveBinding(); + + assertInstances( col, A, 2 ); + assertInstances( col, f1, 2 ); + assertInstances( col, f2, 1 ); + assertInstances( col, ctor, 1 ); + assertInstances( col, a, 2 ); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBinding.java index 18600440b27..8a429e79555 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBinding.java @@ -30,5 +30,4 @@ public interface IBinding { */ public IScope getScope(); - public IASTNode getPhysicalNode(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java index 342443d6da0..be03c843a8b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java @@ -31,7 +31,7 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils; * Created on Nov 5, 2004 * @author aniefer */ -public class CFunction implements IFunction { +public class CFunction implements IFunction, ICBinding { private IASTFunctionDeclarator [] declarators = null; private IASTFunctionDeclarator definition; IFunctionType type = null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java index 6d343224051..be4c015f6ed 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java @@ -33,7 +33,7 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier; * Created on Nov 8, 2004 * @author aniefer */ -public class CStructure implements ICompositeType { +public class CStructure implements ICompositeType, ICBinding { private IASTElaboratedTypeSpecifier[] declarations = null; private ICASTCompositeTypeSpecifier definition; //final private IASTDeclSpecifier declSpecifier; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java index c3c30221ae0..68b1208f1ed 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java @@ -23,7 +23,7 @@ import org.eclipse.cdt.core.dom.ast.IVariable; * Created on Nov 5, 2004 * @author aniefer */ -public class CVariable implements IVariable { +public class CVariable implements IVariable, ICBinding { final IASTName name; private IType type = null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java index 2a4d75511f5..2b87ed77ff0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java @@ -681,7 +681,7 @@ public class CVisitor { if ( fDtor.getName().resolveBinding() instanceof IFunction ) { // possible to have IASTParameterDeclaration whose parent is an IVariable IFunction function = (IFunction) fDtor.getName().resolveBinding(); - if( function.getPhysicalNode() != fDtor ) { + if( ((ICBinding)function).getPhysicalNode() != fDtor ) { IASTParameterDeclaration [] ps = fDtor.getParameters(); int index = -1; for( index = 0; index < ps.length; index++ ) @@ -1699,7 +1699,7 @@ public class CVisitor { if ( declarator.getName().resolveBinding() instanceof IFunction ) { // possible to have IASTParameterDeclaration whose parent is an IVariable IFunction function = (IFunction) declarator.getName().resolveBinding(); - if( function.getPhysicalNode() != declarator ) { + if( ((ICBinding)function).getPhysicalNode() != declarator ) { IASTDeclaration [] ps = declarator.getParameterDeclarations(); int index = -1; outerLoop: for( index = 0; index < ps.length; index++ ) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/ICBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/ICBinding.java new file mode 100644 index 00000000000..295a701d63a --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/ICBinding.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +/* + * Created on Jan 24, 2005 + */ +package org.eclipse.cdt.internal.core.dom.parser.c; + +import org.eclipse.cdt.core.dom.ast.IASTNode; + +/** + * @author aniefer + */ +public interface ICBinding { + //methods needed by CVisitor but not meant for public interface + public IASTNode getPhysicalNode(); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java index 8d771d4f5a8..f254deeb90e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java @@ -20,11 +20,13 @@ import java.util.List; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; @@ -169,9 +171,12 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope { private boolean isConstructorReference( IASTName name ){ IASTNode node = name.getParent(); - if( node instanceof IASTDeclSpecifier ) + if( node instanceof IASTDeclSpecifier ){ + IASTNode parent = node.getParent(); + if( parent instanceof IASTTypeId && parent.getParent() instanceof ICPPASTNewExpression ) + return true; return false; - + } return true; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java index f511af69cb4..267c1ed3fa4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java @@ -44,7 +44,7 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils; /** * @author aniefer */ -public class CPPClassType implements ICPPClassType { +public class CPPClassType implements ICPPClassType, ICPPBinding { private ICPPASTCompositeTypeSpecifier definition; private ICPPASTElaboratedTypeSpecifier [] declarations; @@ -55,6 +55,20 @@ public class CPPClassType implements ICPPClassType { declarations = new ICPPASTElaboratedTypeSpecifier[] { (ICPPASTElaboratedTypeSpecifier) declSpec }; } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDeclarations() + */ + public IASTNode[] getDeclarations() { + return declarations; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDefinition() + */ + public IASTNode getDefinition() { + return definition; + } + private class FindDefinitionAction extends CPPVisitor.CPPBaseVisitorAction { private char [] nameArray = CPPClassType.this.getNameCharArray(); public ICPPASTCompositeTypeSpecifier result = null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java index a4f4871fa28..a404c3b1d1e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java @@ -23,7 +23,7 @@ import org.eclipse.cdt.core.dom.ast.IType; /** * @author aniefer */ -public class CPPEnumeration implements IEnumeration { +public class CPPEnumeration implements IEnumeration, ICPPBinding { private IASTEnumerationSpecifier enumSpecifier; /** * @param specifier @@ -32,6 +32,20 @@ public class CPPEnumeration implements IEnumeration { this.enumSpecifier = specifier; } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDeclarations() + */ + public IASTNode[] getDeclarations() { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDefinition() + */ + public IASTNode getDefinition() { + return enumSpecifier; + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IBinding#getName() */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerator.java index 8a82dacff48..8545bacfaee 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerator.java @@ -25,7 +25,7 @@ import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; /** * @author aniefer */ -public class CPPEnumerator implements IEnumerator { +public class CPPEnumerator implements IEnumerator, ICPPBinding { private IASTEnumerator enumerator; /** * @param enumerator @@ -34,6 +34,20 @@ public class CPPEnumerator implements IEnumerator { this.enumerator = enumerator; } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDeclarations() + */ + public IASTNode[] getDeclarations() { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDefinition() + */ + public IASTNode getDefinition() { + return enumerator; + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IBinding#getName() */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java index 3c3dc87ba08..7a184990536 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java @@ -19,7 +19,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; /** * @author aniefer */ -public class CPPField extends CPPVariable implements ICPPField { +public class CPPField extends CPPVariable implements ICPPField, ICPPBinding { public CPPField( IASTDeclarator declarator ){ super( declarator ); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java index 812d8dae978..6fce8e01cf8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java @@ -28,7 +28,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; /** * @author aniefer */ -public class CPPFunction implements IFunction { +public class CPPFunction implements IFunction, ICPPBinding { protected ICPPASTFunctionDeclarator [] declarations; protected ICPPASTFunctionDeclarator definition; protected IFunctionType type = null; @@ -43,6 +43,20 @@ public class CPPFunction implements IFunction { } } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDeclarations() + */ + public IASTNode[] getDeclarations() { + return declarations; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDefinition() + */ + public IASTNode getDefinition() { + return definition; + } + public void addDefinition( ICPPASTFunctionDeclarator dtor ){ updateParameterBindings( dtor ); definition = dtor; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPLabel.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPLabel.java index cd87e53715d..40b2f3ffb84 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPLabel.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPLabel.java @@ -24,7 +24,7 @@ import org.eclipse.cdt.core.dom.ast.IScope; /** * @author aniefer */ -public class CPPLabel implements ILabel { +public class CPPLabel implements ILabel, ICPPBinding { private IASTStatement statement; /** * @param gotoStatement @@ -33,6 +33,20 @@ public class CPPLabel implements ILabel { this.statement = statement; } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDeclarations() + */ + public IASTNode[] getDeclarations() { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDefinition() + */ + public IASTNode getDefinition() { + return statement; + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.ILabel#getLabelStatement() */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java index 4d27d3baac2..5ac74fc93f1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java @@ -31,7 +31,7 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils; /** * @author aniefer */ -public class CPPNamespace implements ICPPNamespace { +public class CPPNamespace implements ICPPNamespace, ICPPBinding { private static final char[] EMPTY_CHAR_ARRAY = { }; IASTName [] namespaceDefinitions = null; @@ -42,6 +42,20 @@ public class CPPNamespace implements ICPPNamespace { findAllDefinitions( nsDef ); } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDeclarations() + */ + public IASTNode[] getDeclarations() { + return namespaceDefinitions; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDefinition() + */ + public IASTNode getDefinition() { + return ( tu != null ) ? tu : (IASTNode) namespaceDefinitions[0]; + } + static private class NamespaceCollector extends CPPVisitor.CPPBaseVisitorAction { private char [] name; public List namespaces = Collections.EMPTY_LIST; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java index df994339dbe..5705e186f90 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java @@ -23,7 +23,7 @@ import org.eclipse.cdt.core.dom.ast.IType; /** * @author aniefer */ -public class CPPParameter implements IParameter { +public class CPPParameter implements IParameter, ICPPBinding { private IType type = null; private IASTName [] declarations = null; @@ -36,6 +36,20 @@ public class CPPParameter implements IParameter { this.type = type; } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDeclarations() + */ + public IASTNode[] getDeclarations() { + return declarations; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDefinition() + */ + public IASTNode getDefinition() { + return null; + } + public void addDeclaration( IASTName name ){ if( declarations == null ){ declarations = new IASTName [] { name }; 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 5affa7221d3..3e472af0b3f 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 @@ -39,6 +39,7 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IEnumeration; @@ -56,7 +57,9 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration; @@ -264,6 +267,15 @@ public class CPPSemantics { //3: resolve ambiguities IBinding binding = resolveAmbiguities( data, name ); + + //4: post processing + if( data.considerConstructors && binding instanceof ICPPClassType ){ + ICPPClassType cls = (ICPPClassType) binding; + //force resolution of constructor bindings + cls.getConstructors(); + //then use the class scope to resolve which one. + binding = ((ICPPClassScope)cls.getCompositeScope()).getBinding( name ); + } if( binding != null && data.forDefinition && !( binding instanceof IProblemBinding ) ){ addDefinition( binding, name ); } @@ -333,6 +345,17 @@ public class CPPSemantics { } } else if( parent instanceof ICPPASTUsingDeclaration ){ data.forUsingDeclaration = true; + } else if( parent instanceof ICPPASTNamedTypeSpecifier ){ + if( parent.getParent() instanceof IASTTypeId ){ + IASTTypeId typeId = (IASTTypeId) parent.getParent(); + if( typeId.getAbstractDeclarator() instanceof IASTFunctionDeclarator ){ + ICPPASTFunctionDeclarator fdtor = (ICPPASTFunctionDeclarator) typeId.getAbstractDeclarator(); + data.functionParameters = fdtor.getParameters(); + } + if( typeId.getParent() instanceof ICPPASTNewExpression ){ + data.considerConstructors = true; + } + } } return data; } @@ -364,8 +387,14 @@ public class CPPSemantics { List directives = null; if( !data.usingDirectivesOnly ){ - directives = new ArrayList(2); - data.foundItems = lookupInScope( data, scope, blockItem, directives ); + IBinding binding = scope.getBinding( name ); + if( binding == null ){ + directives = new ArrayList(2); + data.foundItems = lookupInScope( data, scope, blockItem, directives ); + } else { + data.foundItems = new ArrayList(); + data.foundItems.add( binding ); + } } @@ -749,10 +778,6 @@ public class CPPSemantics { //check the function itself IASTName declName = declarator.getName(); if( data.considerConstructors || !CPPVisitor.isConstructor( scope, declarator ) ){ - if( declName instanceof ICPPASTQualifiedName ){ - IASTName [] names = ((ICPPASTQualifiedName)declName).getNames(); - declName = names[ names.length - 1 ]; - } if( CharArrayUtils.equals( declName.toCharArray(), data.name ) ){ return declName; } @@ -802,6 +827,20 @@ public class CPPSemantics { return resolveAmbiguities( data, name ); } + static private boolean declaredBefore( IBinding binding, IASTNode node ){ + if( binding instanceof ICPPBinding ){ + ICPPBinding cpp = (ICPPBinding) binding; + IASTNode[] n = cpp.getDeclarations(); + if( n != null && n.length > 0 ) + return (((ASTNode) n[0]).getOffset() < ((ASTNode)node).getOffset() ); + else if( cpp.getDefinition() != null ) + return (((ASTNode) cpp.getDefinition()).getOffset() < ((ASTNode)node).getOffset() ); + else + return true; + } + return false; + } + static private IBinding resolveAmbiguities( CPPSemantics.LookupData data, IASTName name ) { if( data.foundItems == null || data.foundItems.size() == 0 ) return null; @@ -815,13 +854,13 @@ public class CPPSemantics { Object o = data.foundItems.get( i ); if( o instanceof IASTName ) temp = ((IASTName) o).resolveBinding(); - else if( o instanceof IBinding ) + else if( o instanceof IBinding ){ temp = (IBinding) o; - else + if( !declaredBefore( temp, name ) ) + continue; + } else continue; - //IASTName n = (IASTName) - - //temp = n.resolveBinding(); + if( temp instanceof ICPPCompositeBinding ){ IBinding [] bindings = ((ICPPCompositeBinding) temp).getBindings(); for( int j = 0; j < bindings.length; j++ ) @@ -847,7 +886,7 @@ public class CPPSemantics { } if( type != null ) { - if( obj == null && fns == null ) + if( data.typesOnly || (obj == null && fns == null) ) return type; IScope typeScope = type.getScope(); if( obj != null && obj.getScope() != typeScope ){ @@ -893,8 +932,13 @@ public class CPPSemantics { int size = functions.size(); for( int i = 0; i < size; i++ ){ fName = (IFunction) functions.get(i); - function = (ICPPASTFunctionDeclarator) fName.getPhysicalNode(); - + function = (ICPPASTFunctionDeclarator) ((ICPPBinding)fName).getDefinition(); + if( function == null ){ + IASTNode [] nodes = ((ICPPBinding) fName).getDeclarations(); + if( nodes != null && nodes.length > 0 ) + function = (ICPPASTFunctionDeclarator) nodes[0]; + } + if( function == null ){ //implicit member function, for now, not supporting default values or var args num = fName.getParameters().length; @@ -1015,7 +1059,12 @@ public class CPPSemantics { continue; } - ICPPASTFunctionDeclarator currDtor = (ICPPASTFunctionDeclarator) currFn.getPhysicalNode(); + ICPPASTFunctionDeclarator currDtor = (ICPPASTFunctionDeclarator) ((ICPPBinding)currFn).getDefinition(); + if( currDtor == null ){ + IASTNode[] nodes = ((ICPPBinding) currFn).getDeclarations(); + if( nodes != null && nodes.length > 0 ) + currDtor = (ICPPASTFunctionDeclarator) nodes[0]; + } targetParameters = ( currDtor != null ) ? currDtor.getParameters() : null; if( targetParameters == null ){ @@ -1252,9 +1301,8 @@ public class CPPSemantics { static private boolean isCompleteType( IType type ){ type = getUltimateType( type ); - if( type instanceof ICPPClassType ){ - if( ((ICPPClassType) type).getPhysicalNode() instanceof ICPPASTElaboratedTypeSpecifier ) - return false; + if( type instanceof ICPPClassType && ((ICPPBinding)type).getDefinition() == null ){ + return false; } return true; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java index 630bfae21be..4d6e35c16ee 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java @@ -23,7 +23,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; /** * @author aniefer */ -public class CPPTypedef implements ITypedef, ITypeContainer { +public class CPPTypedef implements ITypedef, ITypeContainer, ICPPBinding { private IASTDeclarator declarator = null; private IType type = null; @@ -36,6 +36,20 @@ public class CPPTypedef implements ITypedef, ITypeContainer { // TODO Auto-generated constructor stub } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDeclarations() + */ + public IASTNode[] getDeclarations() { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDefinition() + */ + public IASTNode getDefinition() { + return declarator; + } + public boolean equals( Object o ){ if( o instanceof ITypedef ) return getType().equals( ((ITypedef)o).getType()); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java index 15c09b5320f..1adde9f3f1f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java @@ -22,7 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IVariable; /** * @author aniefer */ -public class CPPVariable implements IVariable { +public class CPPVariable implements IVariable, ICPPBinding { private IASTDeclarator declarator = null; private IType type = null; @@ -30,6 +30,20 @@ public class CPPVariable implements IVariable { declarator = dtor; } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDeclarations() + */ + public IASTNode[] getDeclarations() { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDefinition() + */ + public IASTNode getDefinition() { + return declarator; + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IVariable#getType() */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPBinding.java new file mode 100644 index 00000000000..4581e878d14 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPBinding.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +/* + * Created on Jan 24, 2005 + */ +package org.eclipse.cdt.internal.core.dom.parser.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTNode; + +/** + * @author aniefer + */ +public interface ICPPBinding { + //methods required by the CPPVisitor but not meant for the public interface + + IASTNode [] getDeclarations(); + IASTNode getDefinition(); +}