mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
Resolving method bindings
This commit is contained in:
parent
d161b57251
commit
b2f25ce249
14 changed files with 445 additions and 75 deletions
|
@ -16,12 +16,19 @@ package org.eclipse.cdt.core.parser.tests.ast2;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.IField;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
|
||||
/**
|
||||
|
@ -96,4 +103,86 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
assertSame( A, A1 );
|
||||
assertSame( A1, A2 );
|
||||
}
|
||||
|
||||
public void testField() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer( "class A { int f; };" ); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
assertEquals( decl.getDeclarators().length, 0 );
|
||||
ICPPASTCompositeTypeSpecifier comp = (ICPPASTCompositeTypeSpecifier) decl.getDeclSpecifier();
|
||||
IASTName name_A = comp.getName();
|
||||
|
||||
decl = (IASTSimpleDeclaration) comp.getMembers()[0];
|
||||
IASTDeclarator dtor = decl.getDeclarators()[0];
|
||||
IASTName name_f = dtor.getName();
|
||||
|
||||
ICPPClassType A = (ICPPClassType) name_A.resolveBinding();
|
||||
IField f = (IField) name_f.resolveBinding();
|
||||
|
||||
assertNotNull( A );
|
||||
assertNotNull( f );
|
||||
assertSame( f.getScope(), A.getCompositeScope() );
|
||||
}
|
||||
|
||||
public void testMethodDeclaration() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer( "class A { int f(); };" ); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
assertEquals( decl.getDeclarators().length, 0 );
|
||||
IASTCompositeTypeSpecifier comp = (IASTCompositeTypeSpecifier) decl.getDeclSpecifier();
|
||||
IASTName name_A = comp.getName();
|
||||
|
||||
decl = (IASTSimpleDeclaration) comp.getMembers()[0];
|
||||
IASTDeclarator dtor = decl.getDeclarators()[0];
|
||||
IASTName name_f = dtor.getName();
|
||||
|
||||
ICPPClassType A = (ICPPClassType) name_A.resolveBinding();
|
||||
ICPPMethod f = (ICPPMethod) name_f.resolveBinding();
|
||||
|
||||
assertNotNull( A );
|
||||
assertNotNull( f );
|
||||
assertSame( f.getScope(), A.getCompositeScope() );
|
||||
}
|
||||
|
||||
public void testMethodDefinition() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( " class A { void f(); }; \n" ); //$NON-NLS-1$
|
||||
buffer.append( " void A::f() { } \n" ); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
assertEquals( decl.getDeclarators().length, 0 );
|
||||
IASTCompositeTypeSpecifier comp = (IASTCompositeTypeSpecifier) decl.getDeclSpecifier();
|
||||
IASTName name_A = comp.getName();
|
||||
|
||||
decl = (IASTSimpleDeclaration) comp.getMembers()[0];
|
||||
IASTDeclarator dtor = decl.getDeclarators()[0];
|
||||
IASTName name_f1 = dtor.getName();
|
||||
|
||||
IASTFunctionDefinition def = (IASTFunctionDefinition) tu.getDeclarations()[1];
|
||||
IASTFunctionDeclarator fdtor = def.getDeclarator();
|
||||
ICPPASTQualifiedName name_f2 = (ICPPASTQualifiedName) fdtor.getName();
|
||||
|
||||
ICPPClassType A = (ICPPClassType) name_A.resolveBinding();
|
||||
ICPPMethod f1 = (ICPPMethod) name_f1.resolveBinding();
|
||||
ICPPMethod f2 = (ICPPMethod) name_f2.resolveBinding();
|
||||
|
||||
IASTName[] names = name_f2.getNames();
|
||||
assertEquals( names.length, 2 );
|
||||
IASTName qn1 = names[0];
|
||||
IASTName qn2 = names[1];
|
||||
|
||||
ICPPClassType A2 = (ICPPClassType) qn1.resolveBinding();
|
||||
ICPPMethod f3 = (ICPPMethod) qn2.resolveBinding();
|
||||
|
||||
assertNotNull( A );
|
||||
assertNotNull( f1 );
|
||||
assertSame( f1, f2 );
|
||||
assertSame( f2, f3 );
|
||||
assertSame( A, A2 );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@ package org.eclipse.cdt.core.dom.ast;
|
|||
*/
|
||||
public interface IASTName extends IASTNode {
|
||||
|
||||
public static final IASTName[] EMPTY_NAME_ARRAY = new IASTName[0];
|
||||
|
||||
/**
|
||||
* Return the semantic object this name is referring to.
|
||||
*
|
||||
|
|
|
@ -38,4 +38,6 @@ public interface ICompositeType extends IType {
|
|||
* @return
|
||||
*/
|
||||
public IField findField( String name );
|
||||
|
||||
public IScope getCompositeScope();
|
||||
}
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
**********************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
|
||||
|
@ -22,5 +20,5 @@ public interface ICPPASTQualifiedName extends IASTName {
|
|||
|
||||
public static final ASTNodeProperty SEGMENT_NAME = new ASTNodeProperty( "Segment"); //$NON-NLS-1$
|
||||
public void addName( IASTName name );
|
||||
public List getNames();
|
||||
public IASTName [] getNames();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Dec 1, 2004
|
||||
*/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public interface ICPPNamespace extends IBinding {
|
||||
public ICPPNamespaceScope getNamespaceScope();
|
||||
}
|
|
@ -153,4 +153,11 @@ public class CStructure implements ICompositeType {
|
|||
public int getKey() {
|
||||
return ( definition != null ) ? definition.getKey() : declarations[0].getKind();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getCompositeScope()
|
||||
*/
|
||||
public IScope getCompositeScope() {
|
||||
return (definition != null ) ? definition.getScope() : null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,10 +10,6 @@
|
|||
**********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser2.cpp;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
|
@ -33,8 +29,9 @@ public class CPPASTQualifiedName extends CPPASTNode implements ICPPASTQualifiedN
|
|||
* @see org.eclipse.cdt.core.dom.ast.IASTName#resolveBinding()
|
||||
*/
|
||||
public IBinding resolveBinding() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
//The full qualified name resolves to the same thing as the last name
|
||||
removeNullNames();
|
||||
return names[ names.length - 1 ].resolveBinding();
|
||||
}
|
||||
|
||||
|
||||
|
@ -102,10 +99,10 @@ public class CPPASTQualifiedName extends CPPASTNode implements ICPPASTQualifiedN
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName#getNames()
|
||||
*/
|
||||
public List getNames() {
|
||||
if( names == null ) return Collections.EMPTY_LIST;
|
||||
public IASTName[] getNames() {
|
||||
if( names == null ) return IASTName.EMPTY_NAME_ARRAY;
|
||||
removeNullNames();
|
||||
return Arrays.asList( names );
|
||||
return names;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -17,20 +17,20 @@ import java.util.List;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.IField;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class CPPCompositeType implements ICompositeType {
|
||||
public class CPPClassType implements ICPPClassType {
|
||||
private ICPPASTCompositeTypeSpecifier definition;
|
||||
private ICPPASTElaboratedTypeSpecifier [] declarations;
|
||||
|
||||
public CPPCompositeType( IASTDeclSpecifier declSpec ){
|
||||
public CPPClassType( IASTDeclSpecifier declSpec ){
|
||||
if( declSpec instanceof ICPPASTCompositeTypeSpecifier )
|
||||
definition = (ICPPASTCompositeTypeSpecifier) declSpec;
|
||||
else
|
||||
|
@ -71,10 +71,16 @@ public class CPPCompositeType implements ICompositeType {
|
|||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
|
||||
*/
|
||||
public IScope getScope() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return (definition != null ) ? CPPVisitor.getContainingScope( definition ) : CPPVisitor.getContainingScope( declarations[0] );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getCompositeScope()
|
||||
*/
|
||||
public IScope getCompositeScope() {
|
||||
return (definition != null ) ? definition.getScope() : null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getPhysicalNode()
|
||||
*/
|
||||
|
@ -109,4 +115,44 @@ public class CPPCompositeType implements ICompositeType {
|
|||
tmp[ declarations.length ] = elabSpec;
|
||||
declarations = tmp;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getBases()
|
||||
*/
|
||||
public List getBases() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getDeclaredFields()
|
||||
*/
|
||||
public List getDeclaredFields() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getMethods()
|
||||
*/
|
||||
public List getMethods() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getAllDeclaredMethods()
|
||||
*/
|
||||
public List getAllDeclaredMethods() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getDeclaredMethods()
|
||||
*/
|
||||
public List getDeclaredMethods() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Dec 1, 2004
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.parser2.cpp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class CPPFunction implements IFunction {
|
||||
protected IASTFunctionDeclarator [] declarations;
|
||||
protected IASTFunctionDeclarator definition;
|
||||
|
||||
public CPPFunction( ICPPASTFunctionDeclarator declarator ){
|
||||
IASTNode parent = declarator.getParent();
|
||||
if( parent instanceof IASTFunctionDefinition )
|
||||
definition = declarator;
|
||||
else
|
||||
declarations = new IASTFunctionDeclarator [] { declarator };
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#getParameters()
|
||||
*/
|
||||
public List getParameters() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#getFunctionScope()
|
||||
*/
|
||||
public IScope getFunctionScope() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return (definition != null ) ? definition.getName().toString() : declarations[0].getName().toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
|
||||
*/
|
||||
public char[] getNameCharArray() {
|
||||
return (definition != null ) ? definition.getName().toCharArray() : declarations[0].getName().toCharArray();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
|
||||
*/
|
||||
public IScope getScope() {
|
||||
return CPPVisitor.getContainingScope( definition != null ? definition : declarations[0] );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getPhysicalNode()
|
||||
*/
|
||||
public IASTNode getPhysicalNode() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Dec 1, 2004
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.parser2.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class CPPMethod extends CPPFunction implements ICPPMethod {
|
||||
|
||||
public CPPMethod( ICPPASTFunctionDeclarator declarator ){
|
||||
super( declarator );
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMember#getVisibility()
|
||||
*/
|
||||
public int getVisibility() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Dec 1, 2004
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.parser2.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class CPPNamespace implements ICPPNamespace {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace#getNamespaceScope()
|
||||
*/
|
||||
public ICPPNamespaceScope getNamespaceScope() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
|
||||
*/
|
||||
public char[] getNameCharArray() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
|
||||
*/
|
||||
public IScope getScope() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getPhysicalNode()
|
||||
*/
|
||||
public IASTNode getPhysicalNode() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -82,12 +82,4 @@ public class CPPNamespaceScope extends CPPScope implements ICPPNamespaceScope, I
|
|||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getPhysicalNode()
|
||||
*/
|
||||
public IASTNode getPhysicalNode() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -69,8 +69,7 @@ public class CPPVariable implements IVariable {
|
|||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
|
||||
*/
|
||||
public IScope getScope() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return CPPVisitor.getContainingScope( declarator );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -43,17 +43,18 @@ import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
|||
import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.parser.util.CharArraySet;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectSet;
|
||||
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
|
||||
import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo;
|
||||
import org.eclipse.cdt.internal.core.parser.pst.TypeFilter;
|
||||
import org.eclipse.cdt.internal.core.parser2.c.CASTFunctionDeclarator;
|
||||
|
||||
/**
|
||||
|
@ -72,7 +73,9 @@ public class CPPVisitor {
|
|||
return createBinding( (IASTDeclarator) parent );
|
||||
} else if( parent instanceof ICPPASTElaboratedTypeSpecifier ){
|
||||
return createBinding( (ICPPASTElaboratedTypeSpecifier) parent );
|
||||
} else if( parent instanceof IASTNamedTypeSpecifier ){
|
||||
} else if( parent instanceof IASTNamedTypeSpecifier ||
|
||||
parent instanceof ICPPASTQualifiedName )
|
||||
{
|
||||
return resolveBinding( name );
|
||||
}
|
||||
return null;
|
||||
|
@ -80,10 +83,10 @@ public class CPPVisitor {
|
|||
|
||||
private static IBinding createBinding( ICPPASTElaboratedTypeSpecifier elabType ){
|
||||
ICPPScope scope = (ICPPScope) getContainingScope( elabType );
|
||||
CPPCompositeType binding = (CPPCompositeType) scope.getBinding( 0, elabType.getName().toCharArray() );
|
||||
CPPClassType binding = (CPPClassType) scope.getBinding( 0, elabType.getName().toCharArray() );
|
||||
if( binding == null ){
|
||||
if( elabType.getKind() != IASTElaboratedTypeSpecifier.k_enum )
|
||||
binding = new CPPCompositeType( elabType );
|
||||
binding = new CPPClassType( elabType );
|
||||
scope.addBinding( binding );
|
||||
} else {
|
||||
binding.addDeclaration( elabType );
|
||||
|
@ -92,9 +95,9 @@ public class CPPVisitor {
|
|||
}
|
||||
private static IBinding createBinding( ICPPASTCompositeTypeSpecifier compType ){
|
||||
ICPPScope scope = (ICPPScope) getContainingScope( compType );
|
||||
CPPCompositeType binding = (CPPCompositeType) scope.getBinding( 0, compType.getName().toCharArray() );
|
||||
CPPClassType binding = (CPPClassType) scope.getBinding( 0, compType.getName().toCharArray() );
|
||||
if( binding == null ){
|
||||
binding = new CPPCompositeType( compType );
|
||||
binding = new CPPClassType( compType );
|
||||
scope.addBinding( binding );
|
||||
} else {
|
||||
binding.addDefinition( compType );
|
||||
|
@ -105,23 +108,33 @@ public class CPPVisitor {
|
|||
private static IBinding createBinding( IASTDeclarator declarator ){
|
||||
IBinding binding = null;
|
||||
IASTNode parent = declarator.getParent();
|
||||
if( parent instanceof IASTSimpleDeclaration ){
|
||||
IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) parent;
|
||||
if( simpleDecl.getParent() instanceof ICPPASTCompositeTypeSpecifier ){
|
||||
binding = new CPPField( declarator );
|
||||
} else {
|
||||
binding = new CPPVariable( declarator );
|
||||
if( declarator instanceof ICPPASTFunctionDeclarator ){
|
||||
IScope scope = getContainingScope( parent );
|
||||
if( scope instanceof ICPPClassScope )
|
||||
binding = new CPPMethod( (ICPPASTFunctionDeclarator) declarator );
|
||||
else
|
||||
binding = new CPPFunction( (ICPPASTFunctionDeclarator) declarator );
|
||||
} else {
|
||||
if( parent instanceof IASTSimpleDeclaration ){
|
||||
IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) parent;
|
||||
if( simpleDecl.getParent() instanceof ICPPASTCompositeTypeSpecifier ){
|
||||
binding = new CPPField( declarator );
|
||||
} else {
|
||||
binding = new CPPVariable( declarator );
|
||||
}
|
||||
} else if( parent instanceof IASTParameterDeclaration ){
|
||||
|
||||
} else if( parent instanceof IASTFunctionDefinition ){
|
||||
|
||||
}
|
||||
} else if( parent instanceof IASTParameterDeclaration ){
|
||||
|
||||
} else if( parent instanceof IASTFunctionDefinition ){
|
||||
|
||||
}
|
||||
return binding;
|
||||
}
|
||||
|
||||
public static IScope getContainingScope( IASTNode node ){
|
||||
if( node instanceof IASTDeclaration )
|
||||
if( node instanceof IASTName )
|
||||
return getContainingScope( (IASTName) node );
|
||||
else if( node instanceof IASTDeclaration )
|
||||
return getContainingScope( (IASTDeclaration) node );
|
||||
else if( node instanceof IASTStatement )
|
||||
return getContainingScope( (IASTStatement) node );
|
||||
|
@ -134,7 +147,27 @@ public class CPPVisitor {
|
|||
return getContainingScope( (IASTEnumerationSpecifier) node.getParent() );
|
||||
}
|
||||
|
||||
return null;
|
||||
return getContainingScope( node.getParent() );
|
||||
}
|
||||
|
||||
public static IScope getContainingScope( IASTName name ){
|
||||
IASTNode parent = name.getParent();
|
||||
if( parent instanceof ICPPASTQualifiedName ){
|
||||
IASTName [] names = ((ICPPASTQualifiedName) parent).getNames();
|
||||
int i = 0;
|
||||
for( ; i < names.length; i++ ){
|
||||
if( names[i] == name ) break;
|
||||
}
|
||||
if( i > 0 ){
|
||||
IBinding binding = names[i - 1].resolveBinding();
|
||||
if( binding instanceof ICPPClassType ){
|
||||
return ((ICPPClassType)binding).getCompositeScope();
|
||||
} else if( binding instanceof ICPPNamespace ){
|
||||
return ((ICPPNamespace)binding).getNamespaceScope();
|
||||
}
|
||||
}
|
||||
}
|
||||
return getContainingScope( parent );
|
||||
}
|
||||
/**
|
||||
* @param declaration
|
||||
|
@ -221,10 +254,6 @@ public class CPPVisitor {
|
|||
|
||||
static protected class LookupData
|
||||
{
|
||||
protected static final TypeFilter ANY_FILTER = new TypeFilter( ITypeInfo.t_any );
|
||||
protected static final TypeFilter CONSTRUCTOR_FILTER = new TypeFilter( ITypeInfo.t_constructor );
|
||||
protected static final TypeFilter FUNCTION_FILTER = new TypeFilter( ITypeInfo.t_function );
|
||||
|
||||
public char[] name;
|
||||
public ObjectMap usingDirectives;
|
||||
public ObjectSet visited = ObjectSet.EMPTY_SET; //used to ensure we don't visit things more than once
|
||||
|
@ -234,26 +263,13 @@ public class CPPVisitor {
|
|||
public boolean qualified = false;
|
||||
public boolean ignoreUsingDirectives = false;
|
||||
public boolean usingDirectivesOnly = false;
|
||||
public boolean forUserDefinedConversion = false;
|
||||
public boolean exactFunctionsOnly = false;
|
||||
public boolean returnInvisibleSymbols = false;
|
||||
public boolean forDefinition = false;
|
||||
|
||||
public List foundItems = null;
|
||||
|
||||
public LookupData( char[] n ){
|
||||
name = n;
|
||||
}
|
||||
|
||||
//the following function are optionally overloaded by anonymous classes deriving from
|
||||
//this LookupData
|
||||
public boolean isPrefixLookup(){ return false;} //prefix lookup
|
||||
public CharArraySet getAmbiguities() { return null; }
|
||||
public void addAmbiguity(char[] n ) { /*nothing*/ }
|
||||
public List getParameters() { return null; } //parameter info for resolving functions
|
||||
public ObjectSet getAssociated() { return null; } //associated namespaces for argument dependant lookup
|
||||
public ISymbol getStopAt() { return null; } //stop looking along the stack once we hit this declaration
|
||||
public List getTemplateParameters() { return null; } //template parameters
|
||||
public TypeFilter getFilter() { return ANY_FILTER; }
|
||||
}
|
||||
|
||||
static private IBinding resolveBinding( IASTName name ){
|
||||
|
@ -272,8 +288,18 @@ public class CPPVisitor {
|
|||
return null;
|
||||
}
|
||||
static private LookupData createLookupData( IASTName name ){
|
||||
//TODO
|
||||
return new LookupData( name.toCharArray() );
|
||||
LookupData data = new LookupData( name.toCharArray() );
|
||||
IASTNode parent = name.getParent();
|
||||
if( parent instanceof ICPPASTQualifiedName ){
|
||||
data.qualified = true;
|
||||
parent = parent.getParent();
|
||||
if( parent instanceof IASTDeclarator ){
|
||||
data.forDefinition = true;
|
||||
}
|
||||
} else if( parent instanceof IASTDeclarator ){
|
||||
data.forDefinition = true;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
static private IASTName collectResult( LookupData data, IASTNode declaration, boolean checkAux ){
|
||||
|
@ -354,12 +380,12 @@ public class CPPVisitor {
|
|||
IASTNode node = name;
|
||||
|
||||
while( node != null ){
|
||||
IASTNode blockItem = getContainingBlockItem( name );
|
||||
ICPPScope scope = (ICPPScope) getContainingScope( blockItem );
|
||||
IASTNode blockItem = getContainingBlockItem( node );
|
||||
ICPPScope scope = (ICPPScope) getContainingScope( node );
|
||||
|
||||
List directives = null;
|
||||
if( !data.usingDirectivesOnly )
|
||||
directives = lookupInScope( data, blockItem, blockItem.getParent() );
|
||||
directives = lookupInScope( data, scope, blockItem );
|
||||
|
||||
if( !data.ignoreUsingDirectives ) {
|
||||
data.visited.clear();
|
||||
|
@ -367,7 +393,7 @@ public class CPPVisitor {
|
|||
List transitives = lookupInNominated( data, scope, null );
|
||||
|
||||
processDirectives( data, scope, transitives );
|
||||
if( directives.size() != 0 )
|
||||
if( directives != null && directives.size() != 0 )
|
||||
processDirectives( data, scope, directives );
|
||||
|
||||
while( data.usingDirectives != null && data.usingDirectives.get( scope ) != null ){
|
||||
|
@ -453,20 +479,22 @@ public class CPPVisitor {
|
|||
* @param scope
|
||||
* @return List of encountered using directives
|
||||
*/
|
||||
static private List lookupInScope( LookupData data, IASTNode blockItem, IASTNode parent ) {
|
||||
static private List lookupInScope( LookupData data, ICPPScope scope, IASTNode blockItem ) {
|
||||
IASTName possible = null;
|
||||
IASTNode [] nodes = null;
|
||||
IASTNode parent = scope.getPhysicalNode();
|
||||
|
||||
List usingDirectives = null;
|
||||
|
||||
if( parent instanceof IASTCompoundStatement ){
|
||||
IASTCompoundStatement compound = (IASTCompoundStatement) parent;
|
||||
nodes = compound.getStatements();
|
||||
// scope = (ICPPScope) compound.getScope();
|
||||
} else if ( parent instanceof IASTTranslationUnit ){
|
||||
IASTTranslationUnit translation = (IASTTranslationUnit) parent;
|
||||
nodes = translation.getDeclarations();
|
||||
// scope = (ICPPScope) translation.getScope();
|
||||
} else if ( parent instanceof ICPPASTCompositeTypeSpecifier ){
|
||||
ICPPASTCompositeTypeSpecifier comp = (ICPPASTCompositeTypeSpecifier) parent;
|
||||
nodes = comp.getMembers();
|
||||
}
|
||||
|
||||
int idx = -1;
|
||||
|
@ -490,6 +518,8 @@ public class CPPVisitor {
|
|||
}
|
||||
if( idx > -1 && ++idx < nodes.length ){
|
||||
item = nodes[idx];
|
||||
} else {
|
||||
item = null;
|
||||
}
|
||||
}
|
||||
return usingDirectives;
|
||||
|
@ -514,7 +544,7 @@ public class CPPVisitor {
|
|||
}
|
||||
data.visited.put( temp );
|
||||
int pre = ( data.foundItems != null ) ? 0 : data.foundItems.size();
|
||||
List usings = lookupInScope( data, null, scope.getPhysicalNode() );
|
||||
List usings = lookupInScope( data, scope, null );
|
||||
int post = ( data.foundItems != null ) ? 0 : data.foundItems.size();
|
||||
|
||||
//only consider the transitive using directives if we are an unqualified
|
||||
|
|
Loading…
Add table
Reference in a new issue