mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-09 19:43:27 +02:00
fix bug 84615
This commit is contained in:
parent
893ef31135
commit
1362e388a1
2 changed files with 69 additions and 20 deletions
|
@ -28,6 +28,7 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IArrayType;
|
import org.eclipse.cdt.core.dom.ast.IArrayType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||||
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;
|
||||||
|
@ -1082,5 +1083,31 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
assertInstances( col, x2, 2 );
|
assertInstances( col, x2, 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug84615() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("class A { public : static int n; }; \n" ); //$NON-NLS-1$
|
||||||
|
buffer.append("int main() { \n" ); //$NON-NLS-1$
|
||||||
|
buffer.append(" int A; \n" ); //$NON-NLS-1$
|
||||||
|
buffer.append(" A::n = 42; \n" ); //$NON-NLS-1$
|
||||||
|
buffer.append(" A b; \n" ); //$NON-NLS-1$
|
||||||
|
buffer.append("} \n" ); //$NON-NLS-1$
|
||||||
|
|
||||||
|
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
|
||||||
|
CPPNameCollector col = new CPPNameCollector();
|
||||||
|
CPPVisitor.visitTranslationUnit(tu, col);
|
||||||
|
|
||||||
|
assertEquals(col.size(), 9);
|
||||||
|
|
||||||
|
ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding();
|
||||||
|
ICPPField n = (ICPPField) col.getName(1).resolveBinding();
|
||||||
|
IBinding Aref = col.getName(5).resolveBinding();
|
||||||
|
IBinding nref = col.getName(6).resolveBinding();
|
||||||
|
IProblemBinding prob = (IProblemBinding) col.getName(7).resolveBinding();
|
||||||
|
|
||||||
|
assertSame( A, Aref );
|
||||||
|
assertSame( n, nref );
|
||||||
|
assertNotNull( prob );
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
||||||
|
@ -100,7 +101,7 @@ public class CPPSemantics {
|
||||||
|
|
||||||
static protected class LookupData
|
static protected class LookupData
|
||||||
{
|
{
|
||||||
private IASTName astName;
|
protected IASTName astName;
|
||||||
public char[] name;
|
public char[] name;
|
||||||
public ObjectMap usingDirectives = ObjectMap.EMPTY_MAP;
|
public ObjectMap usingDirectives = ObjectMap.EMPTY_MAP;
|
||||||
public ObjectSet visited = ObjectSet.EMPTY_SET; //used to ensure we don't visit things more than once
|
public ObjectSet visited = ObjectSet.EMPTY_SET; //used to ensure we don't visit things more than once
|
||||||
|
@ -134,7 +135,13 @@ public class CPPSemantics {
|
||||||
public boolean typesOnly(){
|
public boolean typesOnly(){
|
||||||
if( astName == null ) return false;
|
if( astName == null ) return false;
|
||||||
IASTNode parent = astName.getParent();
|
IASTNode parent = astName.getParent();
|
||||||
return ( parent instanceof ICPPASTBaseSpecifier || parent instanceof ICPPASTElaboratedTypeSpecifier);
|
if( parent instanceof ICPPASTBaseSpecifier || parent instanceof ICPPASTElaboratedTypeSpecifier )
|
||||||
|
return true;
|
||||||
|
if( parent instanceof ICPPASTQualifiedName ){
|
||||||
|
IASTName [] ns = ((ICPPASTQualifiedName)parent).getNames();
|
||||||
|
return ( astName != ns[ ns.length -1 ] );
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
public boolean forUsingDeclaration(){
|
public boolean forUsingDeclaration(){
|
||||||
if( astName == null ) return false;
|
if( astName == null ) return false;
|
||||||
|
@ -342,27 +349,42 @@ public class CPPSemantics {
|
||||||
binding = e2.getProblem();
|
binding = e2.getProblem();
|
||||||
}
|
}
|
||||||
//4: post processing
|
//4: post processing
|
||||||
if( binding instanceof ICPPClassType && data.considerConstructors() ){
|
binding = postResolution( binding, data );
|
||||||
|
return binding;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param binding
|
||||||
|
* @param data
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static IBinding postResolution( IBinding binding, LookupData data ) {
|
||||||
|
if( binding instanceof ICPPClassType && data.considerConstructors() ){
|
||||||
ICPPClassType cls = (ICPPClassType) binding;
|
ICPPClassType cls = (ICPPClassType) binding;
|
||||||
try {
|
try {
|
||||||
//force resolution of constructor bindings
|
//force resolution of constructor bindings
|
||||||
cls.getConstructors();
|
cls.getConstructors();
|
||||||
//then use the class scope to resolve which one.
|
//then use the class scope to resolve which one.
|
||||||
binding = ((ICPPClassScope)cls.getCompositeScope()).getBinding( name );
|
binding = ((ICPPClassScope)cls.getCompositeScope()).getBinding( data.astName );
|
||||||
} catch ( DOMException e ) {
|
} catch ( DOMException e ) {
|
||||||
binding = e.getProblem();
|
binding = e.getProblem();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if( data.astName.getPropertyInParent() == IASTNamedTypeSpecifier.NAME && !( binding instanceof IType || binding instanceof ICPPConstructor) ){
|
||||||
|
binding = new ProblemBinding( IProblemBinding.SEMANTIC_INVALID_TYPE, data.name );
|
||||||
|
}
|
||||||
|
|
||||||
if( binding != null && data.forDefinition() && !( binding instanceof IProblemBinding ) ){
|
if( binding != null && data.forDefinition() && !( binding instanceof IProblemBinding ) ){
|
||||||
addDefinition( binding, name );
|
addDefinition( binding, data.astName );
|
||||||
}
|
}
|
||||||
if( binding == null )
|
if( binding == null )
|
||||||
binding = new ProblemBinding(IProblemBinding.SEMANTIC_NAME_NOT_FOUND, name.toCharArray() );
|
binding = new ProblemBinding(IProblemBinding.SEMANTIC_NAME_NOT_FOUND, data.name );
|
||||||
return binding;
|
return binding;
|
||||||
}
|
}
|
||||||
|
|
||||||
static private CPPSemantics.LookupData createLookupData( IASTName name ){
|
static private CPPSemantics.LookupData createLookupData( IASTName name ){
|
||||||
CPPSemantics.LookupData data = new CPPSemantics.LookupData( name );
|
CPPSemantics.LookupData data = new CPPSemantics.LookupData( name );
|
||||||
IASTNode parent = name.getParent();
|
IASTNode parent = name.getParent();
|
||||||
if( parent instanceof ICPPASTQualifiedName ){
|
if( parent instanceof ICPPASTQualifiedName ){
|
||||||
|
@ -853,8 +875,16 @@ public class CPPSemantics {
|
||||||
if( CharArrayUtils.equals( name.toCharArray(), data.name ) ){
|
if( CharArrayUtils.equals( name.toCharArray(), data.name ) ){
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
} else if( declaration instanceof ICPPASTNamespaceDefinition ){
|
||||||
|
IASTName namespaceName = ((ICPPASTNamespaceDefinition) declaration).getName();
|
||||||
|
if( CharArrayUtils.equals( namespaceName.toCharArray(), data.name ) )
|
||||||
|
return namespaceName;
|
||||||
|
} else if( declaration instanceof ICPPASTNamespaceAlias ){
|
||||||
|
IASTName alias = ((ICPPASTNamespaceAlias) declaration).getAlias();
|
||||||
|
if( CharArrayUtils.equals( alias.toCharArray(), data.name ) )
|
||||||
|
return alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( data.typesOnly() )
|
if( data.typesOnly() )
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
@ -883,15 +913,7 @@ public class CPPSemantics {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if( declaration instanceof ICPPASTNamespaceDefinition ){
|
}
|
||||||
IASTName namespaceName = ((ICPPASTNamespaceDefinition) declaration).getName();
|
|
||||||
if( CharArrayUtils.equals( namespaceName.toCharArray(), data.name ) )
|
|
||||||
return namespaceName;
|
|
||||||
} else if( declaration instanceof ICPPASTNamespaceAlias ){
|
|
||||||
IASTName alias = ((ICPPASTNamespaceAlias) declaration).getAlias();
|
|
||||||
if( CharArrayUtils.equals( alias.toCharArray(), data.name ) )
|
|
||||||
return alias;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue