From c69bab5a9ff730af70d989e0dbcc72a2e5bb56d8 Mon Sep 17 00:00:00 2001 From: Andrew Niefer Date: Mon, 2 May 2005 19:42:24 +0000 Subject: [PATCH] fix bug 90626- problems with using declarations --- .../tests/ast2/AST2CPPSpecFailingTest.java | 65 ------------------- .../parser/tests/ast2/AST2CPPSpecTest.java | 62 ++++++++++++++++++ .../core/dom/parser/cpp/CPPClassType.java | 7 +- .../core/dom/parser/cpp/CPPEnumeration.java | 6 +- .../core/dom/parser/cpp/CPPSemantics.java | 3 + .../dom/parser/cpp/CPPUsingDeclaration.java | 47 +++++++++++++- 6 files changed, 122 insertions(+), 68 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java index f8ce032be6c..84a5bf52957 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java @@ -269,71 +269,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest { } } - /** - [--Start Example(CPP 7.3.3-10): - namespace A { - int x; - } - namespace B { - int i; - struct g { }; - struct x { }; - void f(int); - void f(double); - void g(char); // OK: hides struct g - } - void func() - { - int i; - using B::i; // error: i declared twice - void f(char); - using B::f; // OK: each f is a function - f(3.5); //calls B::f(double) - using B::g; - g('a'); //calls B::g(char) - struct g g1; // g1 has class type B::g - using B::x; - using A::x; // OK: hides struct B::x - x = 99; // assigns to A::x - struct x x1; // x1 has class type B::x - } - --End Example] - */ - public void test7_3_3s10() { // TODO raised bug 90626 - StringBuffer buffer = new StringBuffer(); - buffer.append("namespace A {\n"); //$NON-NLS-1$ - buffer.append("int x;\n"); //$NON-NLS-1$ - buffer.append("}\n"); //$NON-NLS-1$ - buffer.append("namespace B {\n"); //$NON-NLS-1$ - buffer.append("int i;\n"); //$NON-NLS-1$ - buffer.append("struct g { };\n"); //$NON-NLS-1$ - buffer.append("struct x { };\n"); //$NON-NLS-1$ - buffer.append("void f(int);\n"); //$NON-NLS-1$ - buffer.append("void f(double);\n"); //$NON-NLS-1$ - buffer.append("void g(char); // OK: hides struct g\n"); //$NON-NLS-1$ - buffer.append("}\n"); //$NON-NLS-1$ - buffer.append("void func()\n"); //$NON-NLS-1$ - buffer.append("{\n"); //$NON-NLS-1$ - buffer.append("int i;\n"); //$NON-NLS-1$ - buffer.append("using B::i; // error: i declared twice\n"); //$NON-NLS-1$ - buffer.append("void f(char);\n"); //$NON-NLS-1$ - buffer.append("using B::f; // OK: each f is a function\n"); //$NON-NLS-1$ - buffer.append("f(3.5); //calls B::f(double)\n"); //$NON-NLS-1$ - buffer.append("using B::g;\n"); //$NON-NLS-1$ - buffer.append("g('a'); //calls B::g(char)\n"); //$NON-NLS-1$ - buffer.append("struct g g1; // g1 has class type B::g\n"); //$NON-NLS-1$ - buffer.append("using B::x;\n"); //$NON-NLS-1$ - buffer.append("using A::x; // OK: hides struct B::x\n"); //$NON-NLS-1$ - buffer.append("x = 99; // assigns to A::x\n"); //$NON-NLS-1$ - buffer.append("struct x x1; // x1 has class type B::x\n"); //$NON-NLS-1$ - buffer.append("}\n"); //$NON-NLS-1$ - try { - parse(buffer.toString(), ParserLanguage.CPP, true, 0); - assertTrue(false); - } catch (Exception e) { - } - } - /** [--Start Example(CPP 8.2-3): // #include diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java index 641f284e46d..c725e195f99 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java @@ -2635,6 +2635,68 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest { parse(buffer.toString(), ParserLanguage.CPP, true, 0); } + /** + [--Start Example(CPP 7.3.3-10): + namespace A { + int x; + } + namespace B { + int i; + struct g { }; + struct x { }; + void f(int); + void f(double); + void g(char); // OK: hides struct g + } + void func() + { + int i; + using B::i; // error: i declared twice + void f(char); + using B::f; // OK: each f is a function + f(3.5); //calls B::f(double) + using B::g; + g('a'); //calls B::g(char) + struct g g1; // g1 has class type B::g + using B::x; + using A::x; // OK: hides struct B::x + x = 99; // assigns to A::x + struct x x1; // x1 has class type B::x + } + --End Example] + */ + public void test7_3_3s10() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("namespace A {\n"); //$NON-NLS-1$ + buffer.append("int x;\n"); //$NON-NLS-1$ + buffer.append("}\n"); //$NON-NLS-1$ + buffer.append("namespace B {\n"); //$NON-NLS-1$ + buffer.append("int i;\n"); //$NON-NLS-1$ + buffer.append("struct g { };\n"); //$NON-NLS-1$ + buffer.append("struct x { };\n"); //$NON-NLS-1$ + buffer.append("void f(int);\n"); //$NON-NLS-1$ + buffer.append("void f(double);\n"); //$NON-NLS-1$ + buffer.append("void g(char); // OK: hides struct g\n"); //$NON-NLS-1$ + buffer.append("}\n"); //$NON-NLS-1$ + buffer.append("void func()\n"); //$NON-NLS-1$ + buffer.append("{\n"); //$NON-NLS-1$ + buffer.append("int i;\n"); //$NON-NLS-1$ + buffer.append("//using B::i; // error: i declared twice\n"); //$NON-NLS-1$ + buffer.append("void f(char);\n"); //$NON-NLS-1$ + buffer.append("using B::f; // OK: each f is a function\n"); //$NON-NLS-1$ + buffer.append("f(3.5); //calls B::f(double)\n"); //$NON-NLS-1$ + buffer.append("using B::g;\n"); //$NON-NLS-1$ + buffer.append("g('a'); //calls B::g(char)\n"); //$NON-NLS-1$ + buffer.append("struct g g1; // g1 has class type B::g\n"); //$NON-NLS-1$ + buffer.append("using B::x;\n"); //$NON-NLS-1$ + buffer.append("using A::x; // OK: hides struct B::x\n"); //$NON-NLS-1$ + buffer.append("x = 99; // assigns to A::x\n"); //$NON-NLS-1$ + buffer.append("struct x x1; // x1 has class type B::x\n"); //$NON-NLS-1$ + buffer.append("}\n"); //$NON-NLS-1$ + + parse(buffer.toString(), ParserLanguage.CPP, true, 0); + } + /** [--Start Example(CPP 7.3.3-11): namespace B { 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 009492362d8..acebbe5d402 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 @@ -98,7 +98,12 @@ public class CPPClassType implements ICPPClassType, ICPPInternalClassType { return ((ICPPClassType)getBinding()).getCompositeScope(); } public Object clone() { - return ((ICPPClassType)getBinding()).clone(); + CPPClassTypeDelegate d = null; + try { + d = (CPPClassTypeDelegate) super.clone(); + } catch ( CloneNotSupportedException e ) { + } + return d; } public ICPPMethod[] getConversionOperators() { IBinding binding = getBinding(); 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 87951802fad..40c2969b717 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 @@ -38,7 +38,11 @@ public class CPPEnumeration implements IEnumeration, ICPPInternalBinding { return ((IEnumeration)getBinding()).getEnumerators(); } public Object clone() { - return ((IEnumeration)getBinding()).clone(); + try { + return super.clone(); + } catch ( CloneNotSupportedException e ) { + } + return null; } public boolean isSameType( IType type ) { return ((IEnumeration)getBinding()).isSameType( type ); 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 b465fb04c70..e401ad7682e 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 @@ -1598,6 +1598,9 @@ public class CPPSemantics { } else { pointOfDecl = nd.getOffset() + nd.getLength(); } + } else if( prop == ICPPASTUsingDeclaration.NAME ){ + nd = (ASTNode) nd.getParent(); + pointOfDecl = nd.getOffset(); } else if( prop == ICPPASTNamespaceAlias.ALIAS_NAME ){ nd = (ASTNode) nd.getParent(); pointOfDecl = nd.getOffset() + nd.getLength(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDeclaration.java index 432d08e3030..684bf4e4ad8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDeclaration.java @@ -16,8 +16,10 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; @@ -26,7 +28,7 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil; /** * @author aniefer */ -public class CPPUsingDeclaration implements ICPPUsingDeclaration { +public class CPPUsingDeclaration implements ICPPUsingDeclaration, ICPPInternalBinding{ private IASTName name; private ICPPDelegate [] delegates; @@ -100,4 +102,47 @@ public class CPPUsingDeclaration implements ICPPUsingDeclaration { return CPPVisitor.getContainingScope( name.getParent() ); } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#getDeclarations() + */ + public IASTNode[] getDeclarations() { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#getDefinition() + */ + public IASTNode getDefinition() { + IASTNode n = name.getParent(); + if( n instanceof ICPPASTTemplateId ) + n = n.getParent(); + + return n; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#createDelegate(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public ICPPDelegate createDelegate( IASTName name ) { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDefinition(org.eclipse.cdt.core.dom.ast.IASTNode) + */ + public void addDefinition( IASTNode node ) { + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDeclaration(org.eclipse.cdt.core.dom.ast.IASTNode) + */ + public void addDeclaration( IASTNode node ) { + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#removeDeclaration(org.eclipse.cdt.core.dom.ast.IASTNode) + */ + public void removeDeclaration( IASTNode node ) { + } + }