mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
fix bug 90626- problems with using declarations
This commit is contained in:
parent
2bd9664bb0
commit
c69bab5a9f
6 changed files with 122 additions and 68 deletions
|
@ -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 <cstddef>
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 ) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue