mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-30 21:55:31 +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, x, 5 );
|
||||
}
|
||||
|
||||
public void testBug84478() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "void foo() {\n" ); //$NON-NLS-1$
|
||||
|
@ -2219,5 +2218,34 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
assertNull( whileStatement.getCondition() );
|
||||
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;
|
||||
|
||||
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.IEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||
|
@ -26,12 +27,12 @@ import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
|||
* @author aniefer
|
||||
*/
|
||||
public class CPPEnumerator implements IEnumerator, ICPPBinding {
|
||||
private IASTEnumerator enumerator;
|
||||
private IASTName enumName;
|
||||
/**
|
||||
* @param enumerator
|
||||
*/
|
||||
public CPPEnumerator( IASTEnumerator enumerator ) {
|
||||
this.enumerator = enumerator;
|
||||
public CPPEnumerator( IASTName enumerator ) {
|
||||
this.enumName = enumerator;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -45,42 +46,43 @@ public class CPPEnumerator implements IEnumerator, ICPPBinding {
|
|||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDefinition()
|
||||
*/
|
||||
public IASTNode getDefinition() {
|
||||
return enumerator;
|
||||
return enumName;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return enumerator.getName().toString();
|
||||
return enumName.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
|
||||
*/
|
||||
public char[] getNameCharArray() {
|
||||
return enumerator.getName().toCharArray();
|
||||
return enumName.toCharArray();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
|
||||
*/
|
||||
public IScope getScope() {
|
||||
return CPPVisitor.getContainingScope( enumerator );
|
||||
return CPPVisitor.getContainingScope( enumName );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getPhysicalNode()
|
||||
*/
|
||||
public IASTNode getPhysicalNode() {
|
||||
return enumerator;
|
||||
return enumName;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IEnumerator#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();
|
||||
return enumeration;
|
||||
}
|
||||
|
|
|
@ -623,7 +623,9 @@ public class CPPSemantics {
|
|||
ArrayWrapper directives = null;
|
||||
if( !data.usingDirectivesOnly ){
|
||||
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();
|
||||
mergeResults( data, lookupInScope( data, scope, blockItem, directives ), true );
|
||||
} else {
|
||||
|
@ -893,7 +895,7 @@ public class CPPSemantics {
|
|||
usingDirectives.array = ArrayUtil.append( usingDirectives.array, item );
|
||||
} else {
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
@ -1118,16 +1120,39 @@ public class CPPSemantics {
|
|||
}
|
||||
}
|
||||
|
||||
static private boolean declaredBefore( IBinding binding, IASTNode node ){
|
||||
if( binding instanceof ICPPBinding ){
|
||||
ICPPBinding cpp = (ICPPBinding) binding;
|
||||
static public boolean declaredBefore( Object obj, IASTNode node ){
|
||||
ASTNode nd = null;
|
||||
if( obj instanceof ICPPBinding ){
|
||||
ICPPBinding cpp = (ICPPBinding) obj;
|
||||
IASTNode[] n = cpp.getDeclarations();
|
||||
|
||||
if( n != null && n.length > 0 )
|
||||
return (((ASTNode) n[0]).getOffset() <= ((ASTNode)node).getOffset() );
|
||||
nd = (ASTNode) n[0];
|
||||
else if( cpp.getDefinition() != null )
|
||||
return (((ASTNode) cpp.getDefinition()).getOffset() <= ((ASTNode)node).getOffset() );
|
||||
nd = (ASTNode) cpp.getDefinition();
|
||||
else
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -226,7 +226,7 @@ public class CPPVisitor implements ICPPASTVisitor {
|
|||
try {
|
||||
enumtor = scope.getBinding( enumerator.getName() );
|
||||
if( enumtor == null ){
|
||||
enumtor = new CPPEnumerator( enumerator );
|
||||
enumtor = new CPPEnumerator( enumerator.getName() );
|
||||
scope.addBinding( enumtor );
|
||||
}
|
||||
} catch ( DOMException e ) {
|
||||
|
@ -647,6 +647,8 @@ public class CPPVisitor implements ICPPASTVisitor {
|
|||
return parent;
|
||||
} else if( parent instanceof IASTFunctionDeclarator ){
|
||||
return node;
|
||||
} else if( parent instanceof IASTEnumerationSpecifier.IASTEnumerator ){
|
||||
return parent;
|
||||
}
|
||||
node = parent;
|
||||
parent = node.getParent();
|
||||
|
@ -838,7 +840,8 @@ public class CPPVisitor implements ICPPASTVisitor {
|
|||
|
||||
return PROCESS_CONTINUE;
|
||||
case KIND_OBJ_FN:
|
||||
if( prop == IASTDeclarator.DECLARATOR_NAME )
|
||||
if( prop == IASTDeclarator.DECLARATOR_NAME ||
|
||||
prop == IASTEnumerationSpecifier.IASTEnumerator.ENUMERATOR_NAME )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue