mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-30 04:15:35 +02:00
fix bug 86353
This commit is contained in:
parent
cb3e02121c
commit
f2e223947e
4 changed files with 77 additions and 19 deletions
|
@ -2199,7 +2199,6 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
assertInstances( col, j, 3 );
|
assertInstances( col, j, 3 );
|
||||||
assertInstances( col, x, 5 );
|
assertInstances( col, x, 5 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBug84478() throws Exception {
|
public void testBug84478() throws Exception {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
buffer.append( "void foo() {\n" ); //$NON-NLS-1$
|
buffer.append( "void foo() {\n" ); //$NON-NLS-1$
|
||||||
|
@ -2219,5 +2218,34 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
assertNull( whileStatement.getCondition() );
|
assertNull( whileStatement.getCondition() );
|
||||||
assertNotNull( whileStatement.getConditionDeclaration() );
|
assertNotNull( whileStatement.getConditionDeclaration() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug86353() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("void foo() { \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" const int x = 12; \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" { enum { x = x }; } \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("} \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("enum { RED }; \n"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
|
||||||
|
CPPNameCollector col = new CPPNameCollector();
|
||||||
|
tu.getVisitor().visitTranslationUnit(col);
|
||||||
|
|
||||||
|
IEnumerator enum_x = (IEnumerator) col.getName(3).resolveBinding();
|
||||||
|
IBinding x_ref = col.getName(4).resolveBinding();
|
||||||
|
IEnumerator RED = (IEnumerator) col.getName(6).resolveBinding();
|
||||||
|
|
||||||
|
IASTName [] decls = tu.getDeclarations( enum_x );
|
||||||
|
assertEquals( decls.length, 1 );
|
||||||
|
assertSame( decls[0], col.getName(3) );
|
||||||
|
|
||||||
|
decls = tu.getDeclarations( x_ref );
|
||||||
|
assertEquals( decls.length, 1 );
|
||||||
|
assertSame( decls[0], col.getName(1) );
|
||||||
|
|
||||||
|
decls = tu.getDeclarations( RED );
|
||||||
|
assertEquals( decls.length, 1 );
|
||||||
|
assertSame( decls[0], col.getName(6) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||||
|
@ -26,12 +27,12 @@ import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||||
* @author aniefer
|
* @author aniefer
|
||||||
*/
|
*/
|
||||||
public class CPPEnumerator implements IEnumerator, ICPPBinding {
|
public class CPPEnumerator implements IEnumerator, ICPPBinding {
|
||||||
private IASTEnumerator enumerator;
|
private IASTName enumName;
|
||||||
/**
|
/**
|
||||||
* @param enumerator
|
* @param enumerator
|
||||||
*/
|
*/
|
||||||
public CPPEnumerator( IASTEnumerator enumerator ) {
|
public CPPEnumerator( IASTName enumerator ) {
|
||||||
this.enumerator = enumerator;
|
this.enumName = enumerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -45,42 +46,43 @@ public class CPPEnumerator implements IEnumerator, ICPPBinding {
|
||||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDefinition()
|
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDefinition()
|
||||||
*/
|
*/
|
||||||
public IASTNode getDefinition() {
|
public IASTNode getDefinition() {
|
||||||
return enumerator;
|
return enumName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
|
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return enumerator.getName().toString();
|
return enumName.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
|
* @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
|
||||||
*/
|
*/
|
||||||
public char[] getNameCharArray() {
|
public char[] getNameCharArray() {
|
||||||
return enumerator.getName().toCharArray();
|
return enumName.toCharArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
|
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
|
||||||
*/
|
*/
|
||||||
public IScope getScope() {
|
public IScope getScope() {
|
||||||
return CPPVisitor.getContainingScope( enumerator );
|
return CPPVisitor.getContainingScope( enumName );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getPhysicalNode()
|
* @see org.eclipse.cdt.core.dom.ast.IBinding#getPhysicalNode()
|
||||||
*/
|
*/
|
||||||
public IASTNode getPhysicalNode() {
|
public IASTNode getPhysicalNode() {
|
||||||
return enumerator;
|
return enumName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IEnumerator#getType()
|
* @see org.eclipse.cdt.core.dom.ast.IEnumerator#getType()
|
||||||
*/
|
*/
|
||||||
public IType getType() {
|
public IType getType() {
|
||||||
IASTEnumerationSpecifier enumSpec = (IASTEnumerationSpecifier) enumerator.getParent();
|
IASTEnumerator etor = (IASTEnumerator) enumName.getParent();
|
||||||
|
IASTEnumerationSpecifier enumSpec = (IASTEnumerationSpecifier) etor.getParent();
|
||||||
IEnumeration enumeration = (IEnumeration) enumSpec.getName().resolveBinding();
|
IEnumeration enumeration = (IEnumeration) enumSpec.getName().resolveBinding();
|
||||||
return enumeration;
|
return enumeration;
|
||||||
}
|
}
|
||||||
|
|
|
@ -623,7 +623,9 @@ public class CPPSemantics {
|
||||||
ArrayWrapper directives = null;
|
ArrayWrapper directives = null;
|
||||||
if( !data.usingDirectivesOnly ){
|
if( !data.usingDirectivesOnly ){
|
||||||
IBinding binding = data.prefixLookup ? null : scope.getBinding( data.astName );
|
IBinding binding = data.prefixLookup ? null : scope.getBinding( data.astName );
|
||||||
if( binding == null ){
|
if( binding == null || !( CPPSemantics.declaredBefore( binding, data.astName ) ||
|
||||||
|
(scope instanceof ICPPClassScope && data.checkWholeClassScope())) )
|
||||||
|
{
|
||||||
directives = new ArrayWrapper();
|
directives = new ArrayWrapper();
|
||||||
mergeResults( data, lookupInScope( data, scope, blockItem, directives ), true );
|
mergeResults( data, lookupInScope( data, scope, blockItem, directives ), true );
|
||||||
} else {
|
} else {
|
||||||
|
@ -893,7 +895,7 @@ public class CPPSemantics {
|
||||||
usingDirectives.array = ArrayUtil.append( usingDirectives.array, item );
|
usingDirectives.array = ArrayUtil.append( usingDirectives.array, item );
|
||||||
} else {
|
} else {
|
||||||
possible = collectResult( data, scope, item, (item == parent) );
|
possible = collectResult( data, scope, item, (item == parent) );
|
||||||
if( possible != null ){
|
if( possible != null && (checkWholeClassScope || declaredBefore( possible, data.astName )) ){
|
||||||
found = (IASTName[]) ArrayUtil.append( IASTName.class, found, possible );
|
found = (IASTName[]) ArrayUtil.append( IASTName.class, found, possible );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1118,16 +1120,39 @@ public class CPPSemantics {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static private boolean declaredBefore( IBinding binding, IASTNode node ){
|
static public boolean declaredBefore( Object obj, IASTNode node ){
|
||||||
if( binding instanceof ICPPBinding ){
|
ASTNode nd = null;
|
||||||
ICPPBinding cpp = (ICPPBinding) binding;
|
if( obj instanceof ICPPBinding ){
|
||||||
|
ICPPBinding cpp = (ICPPBinding) obj;
|
||||||
IASTNode[] n = cpp.getDeclarations();
|
IASTNode[] n = cpp.getDeclarations();
|
||||||
|
|
||||||
if( n != null && n.length > 0 )
|
if( n != null && n.length > 0 )
|
||||||
return (((ASTNode) n[0]).getOffset() <= ((ASTNode)node).getOffset() );
|
nd = (ASTNode) n[0];
|
||||||
else if( cpp.getDefinition() != null )
|
else if( cpp.getDefinition() != null )
|
||||||
return (((ASTNode) cpp.getDefinition()).getOffset() <= ((ASTNode)node).getOffset() );
|
nd = (ASTNode) cpp.getDefinition();
|
||||||
else
|
else
|
||||||
return true;
|
return true;
|
||||||
|
} else if( obj instanceof IASTName ) {
|
||||||
|
nd = (ASTNode) obj;
|
||||||
|
}
|
||||||
|
if( nd != null ){
|
||||||
|
int pointOfDecl = 0;
|
||||||
|
ASTNodeProperty prop = nd.getPropertyInParent();
|
||||||
|
if( prop == IASTDeclarator.DECLARATOR_NAME ){
|
||||||
|
pointOfDecl = nd.getOffset() + nd.getLength();
|
||||||
|
} else if( prop == IASTEnumerator.ENUMERATOR_NAME) {
|
||||||
|
IASTEnumerator enumtor = (IASTEnumerator) nd.getParent();
|
||||||
|
if( enumtor.getValue() != null ){
|
||||||
|
ASTNode exp = (ASTNode) enumtor.getValue();
|
||||||
|
pointOfDecl = exp.getOffset() + exp.getLength();
|
||||||
|
} else {
|
||||||
|
pointOfDecl = nd.getOffset() + nd.getLength();
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
pointOfDecl = nd.getOffset();
|
||||||
|
|
||||||
|
return ( pointOfDecl <= ((ASTNode)node).getOffset() );
|
||||||
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,7 +226,7 @@ public class CPPVisitor implements ICPPASTVisitor {
|
||||||
try {
|
try {
|
||||||
enumtor = scope.getBinding( enumerator.getName() );
|
enumtor = scope.getBinding( enumerator.getName() );
|
||||||
if( enumtor == null ){
|
if( enumtor == null ){
|
||||||
enumtor = new CPPEnumerator( enumerator );
|
enumtor = new CPPEnumerator( enumerator.getName() );
|
||||||
scope.addBinding( enumtor );
|
scope.addBinding( enumtor );
|
||||||
}
|
}
|
||||||
} catch ( DOMException e ) {
|
} catch ( DOMException e ) {
|
||||||
|
@ -647,6 +647,8 @@ public class CPPVisitor implements ICPPASTVisitor {
|
||||||
return parent;
|
return parent;
|
||||||
} else if( parent instanceof IASTFunctionDeclarator ){
|
} else if( parent instanceof IASTFunctionDeclarator ){
|
||||||
return node;
|
return node;
|
||||||
|
} else if( parent instanceof IASTEnumerationSpecifier.IASTEnumerator ){
|
||||||
|
return parent;
|
||||||
}
|
}
|
||||||
node = parent;
|
node = parent;
|
||||||
parent = node.getParent();
|
parent = node.getParent();
|
||||||
|
@ -838,7 +840,8 @@ public class CPPVisitor implements ICPPASTVisitor {
|
||||||
|
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
case KIND_OBJ_FN:
|
case KIND_OBJ_FN:
|
||||||
if( prop == IASTDeclarator.DECLARATOR_NAME )
|
if( prop == IASTDeclarator.DECLARATOR_NAME ||
|
||||||
|
prop == IASTEnumerationSpecifier.IASTEnumerator.ENUMERATOR_NAME )
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue