mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
fix Bug 86371
- when a binding gets added to a scope, and it is the first binding of that name, then the scope will check to see if that name is overloaded and if there are any other bindings it needs to know about. - The IASTNode that bindings hold onto is now more generally an IASTName - The CPPASTName's binding will now be set upon construction of the binding instead of later
This commit is contained in:
parent
8edeb9629e
commit
67cc9c5ad7
13 changed files with 208 additions and 83 deletions
|
@ -418,6 +418,15 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
assertSame(a.getType(), cA);
|
||||
assertInstances(collector, vA, 2);
|
||||
assertInstances(collector, cA, 2);
|
||||
|
||||
tu = parse(buffer.toString(), ParserLanguage.CPP);
|
||||
collector = new CPPNameCollector();
|
||||
tu.getVisitor().visitTranslationUnit( collector);
|
||||
|
||||
cA = (ICompositeType) collector.getName(1).resolveBinding();
|
||||
IBinding A = collector.getName(3).resolveBinding();
|
||||
vA = (IVariable) collector.getName(0).resolveBinding();
|
||||
assertSame(vA, A);
|
||||
}
|
||||
|
||||
public void testBlockTraversal() throws Exception {
|
||||
|
@ -2336,5 +2345,34 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
assertSame( decls[0], col.getName(2) );
|
||||
assertSame( decls[1], col.getName(5) );
|
||||
}
|
||||
|
||||
public void test86371() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("struct B { \n"); //$NON-NLS-1$
|
||||
buffer.append(" void f ( char ); \n"); //$NON-NLS-1$
|
||||
buffer.append(" void g ( char ); \n"); //$NON-NLS-1$
|
||||
buffer.append("}; \n"); //$NON-NLS-1$
|
||||
buffer.append("struct D : B { \n"); //$NON-NLS-1$
|
||||
buffer.append(" using B::f; \n"); //$NON-NLS-1$
|
||||
buffer.append(" void f( int ) { f('c'); } \n"); //$NON-NLS-1$
|
||||
buffer.append(" void g( int ) { g('c'); } \n"); //$NON-NLS-1$
|
||||
buffer.append("}; \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.getVisitor().visitTranslationUnit(col);
|
||||
|
||||
IFunction f_ref = (IFunction) col.getName(12).resolveBinding();
|
||||
IFunction g_ref = (IFunction) col.getName(15).resolveBinding();
|
||||
|
||||
IFunction f = (IFunction) col.getName(1).resolveBinding();
|
||||
assertSame( f_ref, f );
|
||||
|
||||
IFunction g = (IFunction) col.getName(13).resolveBinding();
|
||||
assertSame( g, g_ref );
|
||||
|
||||
assertInstances( col, f_ref, 4 );
|
||||
assertInstances( col, g_ref, 2 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -161,5 +161,9 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier
|
|||
|
||||
return scope;
|
||||
}
|
||||
|
||||
public void setScope( IScope scope ){
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
|||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics.LookupData;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
@ -38,10 +39,11 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
|||
public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
||||
private CharArrayObjectMap bindings = CharArrayObjectMap.EMPTY_MAP;
|
||||
private ICPPConstructor [] constructors = null;
|
||||
boolean checkForAdditionalBindings = true;
|
||||
|
||||
public CPPClassScope( ICPPASTCompositeTypeSpecifier physicalNode ) {
|
||||
super( physicalNode );
|
||||
|
||||
((CPPASTCompositeTypeSpecifier)physicalNode).setScope( this );
|
||||
createImplicitMembers();
|
||||
}
|
||||
|
||||
|
@ -60,6 +62,8 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
|||
|
||||
char [] className = compTypeSpec.getName().toCharArray();
|
||||
|
||||
checkForAdditionalBindings = false;
|
||||
|
||||
//default constructor: A()
|
||||
addBinding( new CPPImplicitConstructor( this, className, IParameter.EMPTY_PARAMETER_ARRAY ) );
|
||||
|
||||
|
@ -77,6 +81,8 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
|||
//destructor: ~A()
|
||||
char [] dtorName = CharArrayUtils.concat( "~".toCharArray(), className ); //$NON-NLS-1$
|
||||
addBinding( new CPPImplicitMethod( this, dtorName, new CPPBasicType( IBasicType.t_unspecified, 0 ), IParameter.EMPTY_PARAMETER_ARRAY ) );
|
||||
|
||||
checkForAdditionalBindings = true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -99,6 +105,22 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
|||
}
|
||||
} else {
|
||||
bindings.put( c, binding );
|
||||
if( checkForAdditionalBindings ){
|
||||
//need to ensure we have all bindings that correspond to this char[]
|
||||
checkForAdditionalBindings = false;
|
||||
LookupData data = new LookupData( c );
|
||||
try {
|
||||
data.foundItems = CPPSemantics.lookupInScope( data, this, null, null );
|
||||
} catch ( DOMException e ) {
|
||||
}
|
||||
if( data.foundItems != null ){
|
||||
IASTName [] ns = (IASTName[]) data.foundItems;
|
||||
for( int i = 0; i < ns.length && ns[i] != null; i++ ){
|
||||
ns[i].resolveBinding();
|
||||
}
|
||||
}
|
||||
checkForAdditionalBindings = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,9 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
|
@ -99,14 +101,21 @@ public class CPPClassType implements ICPPClassType, ICPPBinding {
|
|||
}
|
||||
}
|
||||
|
||||
private ICPPASTCompositeTypeSpecifier definition;
|
||||
private ICPPASTElaboratedTypeSpecifier [] declarations;
|
||||
private IASTName definition;
|
||||
private IASTName [] declarations;
|
||||
|
||||
public CPPClassType( IASTDeclSpecifier declSpec ){
|
||||
if( declSpec instanceof ICPPASTCompositeTypeSpecifier )
|
||||
definition = (ICPPASTCompositeTypeSpecifier) declSpec;
|
||||
public CPPClassType( IASTName name ){
|
||||
ASTNodeProperty prop = name.getPropertyInParent();
|
||||
if( name instanceof ICPPASTQualifiedName ){
|
||||
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
|
||||
name = ns[ ns.length - 1 ];
|
||||
}
|
||||
|
||||
if( prop == IASTCompositeTypeSpecifier.TYPE_NAME )
|
||||
definition = name;
|
||||
else
|
||||
declarations = new ICPPASTElaboratedTypeSpecifier[] { (ICPPASTElaboratedTypeSpecifier) declSpec };
|
||||
declarations = new IASTName[] { name };
|
||||
((CPPASTName)name).setBinding( this );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -125,7 +134,7 @@ public class CPPClassType implements ICPPClassType, ICPPBinding {
|
|||
|
||||
private class FindDefinitionAction extends CPPVisitor.CPPBaseVisitorAction {
|
||||
private char [] nameArray = CPPClassType.this.getNameCharArray();
|
||||
public ICPPASTCompositeTypeSpecifier result = null;
|
||||
public IASTName result = null;
|
||||
|
||||
{
|
||||
processNames = true;
|
||||
|
@ -141,7 +150,7 @@ public class CPPClassType implements ICPPClassType, ICPPBinding {
|
|||
{
|
||||
IBinding binding = name.resolveBinding();
|
||||
if( binding == CPPClassType.this ){
|
||||
result = (ICPPASTCompositeTypeSpecifier) name.getParent();
|
||||
result = name;
|
||||
return PROCESS_ABORT;
|
||||
}
|
||||
}
|
||||
|
@ -178,6 +187,17 @@ public class CPPClassType implements ICPPClassType, ICPPBinding {
|
|||
return;
|
||||
}
|
||||
|
||||
private ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier(){
|
||||
if( definition != null ){
|
||||
return (ICPPASTCompositeTypeSpecifier) definition.getParent();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private ICPPASTElaboratedTypeSpecifier getElaboratedTypeSpecifier() {
|
||||
if( declarations != null )
|
||||
return (ICPPASTElaboratedTypeSpecifier) declarations[0].getParent();
|
||||
return null;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getFields()
|
||||
*/
|
||||
|
@ -188,7 +208,7 @@ public class CPPClassType implements ICPPClassType, ICPPBinding {
|
|||
return new IField [] { new CPPField.CPPFieldProblem( IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, getNameCharArray() ) };
|
||||
}
|
||||
|
||||
IASTDeclaration[] members = definition.getMembers();
|
||||
IASTDeclaration[] members = getCompositeTypeSpecifier().getMembers();
|
||||
int size = members.length;
|
||||
IField[] fields = null;
|
||||
if( size > 0 ){
|
||||
|
@ -222,31 +242,28 @@ public class CPPClassType implements ICPPClassType, ICPPBinding {
|
|||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return ( definition != null ) ? definition.getName().toString() : declarations[0].getName().toString();
|
||||
return ( definition != null ) ? definition.toString() : declarations[0].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();
|
||||
return ( definition != null ) ? definition.toCharArray() : declarations[0].toCharArray();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
|
||||
*/
|
||||
public IScope getScope() {
|
||||
IASTName name = definition != null ? definition.getName() : declarations[0].getName();
|
||||
if( name instanceof ICPPASTQualifiedName ){
|
||||
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
|
||||
name = ns[ ns.length - 1 ];
|
||||
}
|
||||
IASTName name = definition != null ? definition : declarations[0];
|
||||
|
||||
IScope scope = CPPVisitor.getContainingScope( name );
|
||||
if( definition == null && name.getPropertyInParent() != ICPPASTQualifiedName.SEGMENT_NAME ){
|
||||
IASTNode node = declarations[0].getParent();
|
||||
IASTNode node = declarations[0].getParent().getParent();
|
||||
if( node instanceof IASTFunctionDefinition || node instanceof IASTParameterDeclaration ||
|
||||
( node instanceof IASTSimpleDeclaration &&
|
||||
( ((IASTSimpleDeclaration) node).getDeclarators().length > 0 || declarations[0].isFriend() ) ) )
|
||||
( ((IASTSimpleDeclaration) node).getDeclarators().length > 0 || getElaboratedTypeSpecifier().isFriend() ) ) )
|
||||
{
|
||||
while( scope instanceof ICPPClassScope || scope instanceof ICPPFunctionScope ){
|
||||
try {
|
||||
|
@ -263,7 +280,7 @@ public class CPPClassType implements ICPPClassType, ICPPBinding {
|
|||
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getCompositeScope()
|
||||
*/
|
||||
public IScope getCompositeScope() {
|
||||
return (definition != null ) ? definition.getScope() : null;
|
||||
return (definition != null ) ? getCompositeTypeSpecifier().getScope() : null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -277,27 +294,30 @@ public class CPPClassType implements ICPPClassType, ICPPBinding {
|
|||
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getKey()
|
||||
*/
|
||||
public int getKey() {
|
||||
return (definition != null ) ? definition.getKey() : declarations[0].getKind();
|
||||
if( definition != null )
|
||||
return getCompositeTypeSpecifier().getKey();
|
||||
|
||||
return getElaboratedTypeSpecifier().getKind();
|
||||
}
|
||||
|
||||
public void addDefinition( ICPPASTCompositeTypeSpecifier compSpec ){
|
||||
definition = compSpec;
|
||||
definition = compSpec.getName();
|
||||
}
|
||||
public void addDeclaration( ICPPASTElaboratedTypeSpecifier elabSpec ) {
|
||||
if( declarations == null ){
|
||||
declarations = new ICPPASTElaboratedTypeSpecifier [] { elabSpec };
|
||||
declarations = new IASTName[] { elabSpec.getName() };
|
||||
return;
|
||||
}
|
||||
|
||||
for( int i = 0; i < declarations.length; i++ ){
|
||||
if( declarations[i] == null ){
|
||||
declarations[i] = elabSpec;
|
||||
declarations[i] = elabSpec.getName();
|
||||
return;
|
||||
}
|
||||
}
|
||||
ICPPASTElaboratedTypeSpecifier tmp [] = new ICPPASTElaboratedTypeSpecifier[ declarations.length * 2 ];
|
||||
IASTName tmp [] = new IASTName[ declarations.length * 2 ];
|
||||
System.arraycopy( declarations, 0, tmp, 0, declarations.length );
|
||||
tmp[ declarations.length ] = elabSpec;
|
||||
tmp[ declarations.length ] = elabSpec.getName();
|
||||
declarations = tmp;
|
||||
}
|
||||
|
||||
|
@ -311,7 +331,7 @@ public class CPPClassType implements ICPPClassType, ICPPBinding {
|
|||
return new ICPPBase [] { new CPPBaseClause.CPPBaseProblem( IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, getNameCharArray() ) };
|
||||
}
|
||||
}
|
||||
ICPPASTBaseSpecifier [] bases = definition.getBaseSpecifiers();
|
||||
ICPPASTBaseSpecifier [] bases = getCompositeTypeSpecifier().getBaseSpecifiers();
|
||||
if( bases.length == 0 )
|
||||
return ICPPBase.EMPTY_BASE_ARRAY;
|
||||
|
||||
|
@ -377,7 +397,7 @@ public class CPPClassType implements ICPPClassType, ICPPBinding {
|
|||
}
|
||||
|
||||
ICPPClassScope scope = (ICPPClassScope) getCompositeScope();
|
||||
IASTDeclaration [] members = definition.getMembers();
|
||||
IASTDeclaration [] members = getCompositeTypeSpecifier().getMembers();
|
||||
for( int i = 0; i < members.length; i++ ){
|
||||
if( members[i] instanceof IASTSimpleDeclaration ){
|
||||
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)members[i]).getDeclarators();
|
||||
|
@ -407,7 +427,7 @@ public class CPPClassType implements ICPPClassType, ICPPBinding {
|
|||
}
|
||||
}
|
||||
ObjectSet resultSet = new ObjectSet(2);
|
||||
IASTDeclaration [] members = definition.getMembers();
|
||||
IASTDeclaration [] members = getCompositeTypeSpecifier().getMembers();
|
||||
for( int i = 0; i < members.length; i++ ){
|
||||
if( members[i] instanceof IASTSimpleDeclaration ){
|
||||
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration)members[i]).getDeclSpecifier();
|
||||
|
|
|
@ -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;
|
||||
|
@ -25,12 +26,13 @@ import org.eclipse.cdt.core.dom.ast.IType;
|
|||
* @author aniefer
|
||||
*/
|
||||
public class CPPEnumeration implements IEnumeration, ICPPBinding {
|
||||
private IASTEnumerationSpecifier enumSpecifier;
|
||||
private IASTName enumName;
|
||||
/**
|
||||
* @param specifier
|
||||
*/
|
||||
public CPPEnumeration( IASTEnumerationSpecifier specifier ) {
|
||||
this.enumSpecifier = specifier;
|
||||
public CPPEnumeration( IASTName name ) {
|
||||
this.enumName = name;
|
||||
((CPPASTName)name).setBinding( this );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -44,35 +46,35 @@ public class CPPEnumeration implements IEnumeration, ICPPBinding {
|
|||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDefinition()
|
||||
*/
|
||||
public IASTNode getDefinition() {
|
||||
return enumSpecifier;
|
||||
return enumName;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return enumSpecifier.getName().toString();
|
||||
return enumName.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
|
||||
*/
|
||||
public char[] getNameCharArray() {
|
||||
return enumSpecifier.getName().toCharArray();
|
||||
return enumName.toCharArray();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
|
||||
*/
|
||||
public IScope getScope() {
|
||||
return CPPVisitor.getContainingScope( enumSpecifier );
|
||||
return CPPVisitor.getContainingScope( enumName );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getPhysicalNode()
|
||||
*/
|
||||
public IASTNode getPhysicalNode() {
|
||||
return enumSpecifier;
|
||||
return enumName;
|
||||
}
|
||||
|
||||
public Object clone(){
|
||||
|
@ -89,7 +91,7 @@ public class CPPEnumeration implements IEnumeration, ICPPBinding {
|
|||
* @see org.eclipse.cdt.core.dom.ast.IEnumeration#getEnumerators()
|
||||
*/
|
||||
public IEnumerator[] getEnumerators() {
|
||||
IASTEnumerationSpecifier.IASTEnumerator[] enums = enumSpecifier.getEnumerators();
|
||||
IASTEnumerationSpecifier.IASTEnumerator[] enums = ((IASTEnumerationSpecifier)enumName.getParent()).getEnumerators();
|
||||
IEnumerator [] bindings = new IEnumerator [ enums.length ];
|
||||
|
||||
for( int i = 0; i < enums.length; i++ ){
|
||||
|
|
|
@ -33,6 +33,7 @@ public class CPPEnumerator implements IEnumerator, ICPPBinding {
|
|||
*/
|
||||
public CPPEnumerator( IASTName enumerator ) {
|
||||
this.enumName = enumerator;
|
||||
((CPPASTName)enumerator).setBinding( this );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -79,6 +79,13 @@ public class CPPFunction implements IFunction, ICPPBinding {
|
|||
definition = declarator;
|
||||
else
|
||||
declarations = new ICPPASTFunctionDeclarator [] { declarator };
|
||||
|
||||
IASTName name = declarator.getName();
|
||||
if( name instanceof ICPPASTQualifiedName ){
|
||||
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
|
||||
name = ns[ ns.length - 1 ];
|
||||
}
|
||||
((CPPASTName)name).setBinding( this );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,10 +14,9 @@
|
|||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.ILabel;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
|
||||
|
@ -25,12 +24,13 @@ import org.eclipse.cdt.core.dom.ast.IScope;
|
|||
* @author aniefer
|
||||
*/
|
||||
public class CPPLabel implements ILabel, ICPPBinding {
|
||||
private IASTStatement statement;
|
||||
private IASTName statement;
|
||||
/**
|
||||
* @param gotoStatement
|
||||
*/
|
||||
public CPPLabel( IASTStatement statement ) {
|
||||
public CPPLabel( IASTName statement ) {
|
||||
this.statement = statement;
|
||||
((CPPASTName)statement).setBinding( this );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -62,20 +62,14 @@ public class CPPLabel implements ILabel, ICPPBinding {
|
|||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
if( statement instanceof IASTLabelStatement )
|
||||
return ((IASTLabelStatement) statement).getName().toString();
|
||||
|
||||
return ((IASTGotoStatement) statement).getName().toString();
|
||||
return statement.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
|
||||
*/
|
||||
public char[] getNameCharArray() {
|
||||
if( statement instanceof IASTLabelStatement )
|
||||
return ((IASTLabelStatement) statement).getName().toCharArray();
|
||||
|
||||
return ((IASTGotoStatement) statement).getName().toCharArray();
|
||||
return statement.toCharArray();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -95,7 +89,7 @@ public class CPPLabel implements ILabel, ICPPBinding {
|
|||
/**
|
||||
* @param labelStatement
|
||||
*/
|
||||
public void setLabelStatement( IASTLabelStatement labelStatement ) {
|
||||
public void setLabelStatement( IASTName labelStatement ) {
|
||||
statement = labelStatement;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,19 +13,21 @@
|
|||
*/
|
||||
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.cpp.ICPPASTUsingDirective;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics.LookupData;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class CPPNamespaceScope extends CPPScope implements ICPPNamespaceScope{
|
||||
private CharArrayObjectMap bindings = CharArrayObjectMap.EMPTY_MAP;
|
||||
private boolean checkForAdditionalBindings = true;
|
||||
|
||||
public CPPNamespaceScope( IASTNode physicalNode ) {
|
||||
super( physicalNode );
|
||||
|
@ -46,6 +48,22 @@ public class CPPNamespaceScope extends CPPScope implements ICPPNamespaceScope{
|
|||
}
|
||||
} else {
|
||||
bindings.put( c, binding );
|
||||
if( checkForAdditionalBindings ){
|
||||
//need to ensure we have all bindings that correspond to this char[]
|
||||
checkForAdditionalBindings = false;
|
||||
LookupData data = new LookupData( c );
|
||||
try {
|
||||
data.foundItems = CPPSemantics.lookupInScope( data, this, null, null );
|
||||
} catch ( DOMException e ) {
|
||||
}
|
||||
if( data.foundItems != null ){
|
||||
IASTName [] ns = (IASTName[]) data.foundItems;
|
||||
for( int i = 0; i < ns.length && ns[i] != null; i++ ){
|
||||
ns[i].resolveBinding();
|
||||
}
|
||||
}
|
||||
checkForAdditionalBindings = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,11 +88,4 @@ public class CPPNamespaceScope extends CPPScope implements ICPPNamespaceScope{
|
|||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope#getUsingDirectives()
|
||||
*/
|
||||
public ICPPASTUsingDirective[] getUsingDirectives() {
|
||||
// TODO Auto-generated method stub
|
||||
return ICPPASTUsingDirective.EMPTY_USINGDIRECTIVE_ARRAY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,7 +149,8 @@ public class CPPSemantics {
|
|||
public boolean typesOnly(){
|
||||
if( astName == null ) return false;
|
||||
IASTNode parent = astName.getParent();
|
||||
if( parent instanceof ICPPASTBaseSpecifier || parent instanceof ICPPASTElaboratedTypeSpecifier )
|
||||
if( parent instanceof ICPPASTBaseSpecifier || parent instanceof ICPPASTElaboratedTypeSpecifier ||
|
||||
parent instanceof ICPPASTCompositeTypeSpecifier )
|
||||
return true;
|
||||
if( parent instanceof ICPPASTQualifiedName ){
|
||||
IASTName [] ns = ((ICPPASTQualifiedName)parent).getNames();
|
||||
|
@ -364,10 +365,7 @@ public class CPPSemantics {
|
|||
}
|
||||
}
|
||||
|
||||
static protected IBinding resolveBinding( IASTName name ){
|
||||
// if( name instanceof ICPPASTQualifiedName && ((ICPPASTQualifiedName)name).isFullyQualified() )
|
||||
// return ((ICPPASTTranslationUnit)name.getTranslationUnit()).resolveBinding();
|
||||
|
||||
static protected IBinding resolveBinding( IASTName name ){
|
||||
//1: get some context info off of the name to figure out what kind of lookup we want
|
||||
LookupData data = createLookupData( name, true );
|
||||
|
||||
|
@ -437,8 +435,26 @@ public class CPPSemantics {
|
|||
binding = new ProblemBinding( IProblemBinding.SEMANTIC_INVALID_TYPE, data.name );
|
||||
}
|
||||
|
||||
if( binding != null && data.forDefinition() && !( binding instanceof IProblemBinding ) ){
|
||||
addDefinition( binding, data.astName );
|
||||
if( binding != null && !( binding instanceof IProblemBinding ) ){
|
||||
if( data.forDefinition() ){
|
||||
addDefinition( binding, data.astName );
|
||||
} else if( data.forUsingDeclaration() ){
|
||||
IASTNode node = CPPVisitor.getContainingBlockItem( data.astName );
|
||||
ICPPScope scope = (ICPPScope) CPPVisitor.getContainingScope( node );
|
||||
try {
|
||||
if( binding instanceof ICPPCompositeBinding ){
|
||||
IBinding [] bs = ((ICPPCompositeBinding)binding).getBindings();
|
||||
for( int i = 0; i < bs.length; i++ ) {
|
||||
scope.addBinding( binding );
|
||||
}
|
||||
} else {
|
||||
scope.addBinding( binding );
|
||||
}
|
||||
} catch ( DOMException e ) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if( binding == null )
|
||||
binding = new ProblemBinding(IProblemBinding.SEMANTIC_NAME_NOT_FOUND, data.name );
|
||||
|
@ -831,7 +847,7 @@ public class CPPSemantics {
|
|||
* @return List of encountered using directives
|
||||
* @throws DOMException
|
||||
*/
|
||||
static private IASTName[] lookupInScope( CPPSemantics.LookupData data, ICPPScope scope, IASTNode blockItem, ArrayWrapper usingDirectives ) throws DOMException {
|
||||
static protected IASTName[] lookupInScope( CPPSemantics.LookupData data, ICPPScope scope, IASTNode blockItem, ArrayWrapper usingDirectives ) throws DOMException {
|
||||
IASTName possible = null;
|
||||
IASTNode [] nodes = null;
|
||||
IASTNode parent = scope.getPhysicalNode();
|
||||
|
@ -1121,6 +1137,8 @@ public class CPPSemantics {
|
|||
}
|
||||
|
||||
static public boolean declaredBefore( Object obj, IASTNode node ){
|
||||
if( node == null ) return true;
|
||||
|
||||
ASTNode nd = null;
|
||||
if( obj instanceof ICPPBinding ){
|
||||
ICPPBinding cpp = (ICPPBinding) obj;
|
||||
|
|
|
@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
|
@ -25,14 +26,15 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
|
|||
* @author aniefer
|
||||
*/
|
||||
public class CPPTypedef implements ITypedef, ITypeContainer, ICPPBinding {
|
||||
private IASTDeclarator declarator = null;
|
||||
private IASTName typedefName = null;
|
||||
private IType type = null;
|
||||
|
||||
/**
|
||||
* @param declarator
|
||||
*/
|
||||
public CPPTypedef(IASTDeclarator declarator) {
|
||||
this.declarator = declarator;
|
||||
public CPPTypedef(IASTName name) {
|
||||
this.typedefName = name;
|
||||
((CPPASTName)name).setBinding( this );
|
||||
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
@ -48,7 +50,7 @@ public class CPPTypedef implements ITypedef, ITypeContainer, ICPPBinding {
|
|||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDefinition()
|
||||
*/
|
||||
public IASTNode getDefinition() {
|
||||
return declarator;
|
||||
return typedefName;
|
||||
}
|
||||
|
||||
public boolean equals( Object o ){
|
||||
|
@ -70,7 +72,7 @@ public class CPPTypedef implements ITypedef, ITypeContainer, ICPPBinding {
|
|||
*/
|
||||
public IType getType() {
|
||||
if( type == null )
|
||||
type = CPPVisitor.createType( declarator );
|
||||
type = CPPVisitor.createType( (IASTDeclarator) typedefName.getParent() );
|
||||
return type;
|
||||
}
|
||||
|
||||
|
@ -82,28 +84,28 @@ public class CPPTypedef implements ITypedef, ITypeContainer, ICPPBinding {
|
|||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return declarator.getName().toString();
|
||||
return typedefName.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
|
||||
*/
|
||||
public char[] getNameCharArray() {
|
||||
return declarator.getName().toCharArray();
|
||||
return typedefName.toCharArray();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
|
||||
*/
|
||||
public IScope getScope() {
|
||||
return CPPVisitor.getContainingScope( declarator );
|
||||
return CPPVisitor.getContainingScope( typedefName.getParent() );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getPhysicalNode()
|
||||
*/
|
||||
public IASTNode getPhysicalNode() {
|
||||
return declarator;
|
||||
return typedefName;
|
||||
}
|
||||
|
||||
public Object clone(){
|
||||
|
|
|
@ -49,10 +49,16 @@ public class CPPVariable implements IVariable, ICPPBinding {
|
|||
private IType type = null;
|
||||
|
||||
public CPPVariable( IASTName name ){
|
||||
if( name instanceof ICPPASTQualifiedName ){
|
||||
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
|
||||
name = ns[ ns.length - 1 ];
|
||||
}
|
||||
|
||||
if( isDefinition( name ) )
|
||||
definition = name;
|
||||
else
|
||||
declarations = new IASTName [] { name };
|
||||
((CPPASTName)name).setBinding( this );
|
||||
}
|
||||
|
||||
protected boolean isDefinition( IASTName name ){
|
||||
|
|
|
@ -191,7 +191,7 @@ public class CPPVisitor implements ICPPASTVisitor {
|
|||
try {
|
||||
binding = functionScope.getBinding( name );
|
||||
if( binding == null ){
|
||||
binding = new CPPLabel( gotoStatement );
|
||||
binding = new CPPLabel( gotoStatement.getName() );
|
||||
functionScope.addBinding( binding );
|
||||
}
|
||||
} catch ( DOMException e ) {
|
||||
|
@ -208,10 +208,10 @@ public class CPPVisitor implements ICPPASTVisitor {
|
|||
try {
|
||||
binding = functionScope.getBinding( name );
|
||||
if( binding == null ){
|
||||
binding = new CPPLabel( labelStatement );
|
||||
binding = new CPPLabel( labelStatement.getName() );
|
||||
functionScope.addBinding( binding );
|
||||
} else {
|
||||
((CPPLabel)binding).setLabelStatement( labelStatement );
|
||||
((CPPLabel)binding).setLabelStatement( labelStatement.getName() );
|
||||
}
|
||||
} catch ( DOMException e ) {
|
||||
binding = e.getProblem();
|
||||
|
@ -243,7 +243,7 @@ public class CPPVisitor implements ICPPASTVisitor {
|
|||
try {
|
||||
enumeration = scope.getBinding( specifier.getName() );
|
||||
if( enumeration == null ){
|
||||
enumeration = new CPPEnumeration( specifier );
|
||||
enumeration = new CPPEnumeration( specifier.getName() );
|
||||
scope.addBinding( enumeration );
|
||||
}
|
||||
} catch ( DOMException e ) {
|
||||
|
@ -309,7 +309,7 @@ public class CPPVisitor implements ICPPASTVisitor {
|
|||
binding = scope.getBinding( elabType.getName() );
|
||||
if( binding == null ){
|
||||
if( elabType.getKind() != IASTElaboratedTypeSpecifier.k_enum )
|
||||
binding = new CPPClassType( elabType );
|
||||
binding = new CPPClassType( elabType.getName() );
|
||||
scope.addBinding( binding );
|
||||
} else {
|
||||
((CPPClassType)binding).addDeclaration( elabType );
|
||||
|
@ -331,7 +331,7 @@ public class CPPVisitor implements ICPPASTVisitor {
|
|||
try {
|
||||
binding = scope.getBinding( compType.getName() );
|
||||
if( binding == null || !(binding instanceof ICPPClassType) ){
|
||||
binding = new CPPClassType( compType );
|
||||
binding = new CPPClassType( compType.getName() );
|
||||
scope.addBinding( binding );
|
||||
} else {
|
||||
((CPPClassType)binding).addDefinition( compType );
|
||||
|
@ -446,7 +446,7 @@ public class CPPVisitor implements ICPPASTVisitor {
|
|||
|
||||
IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) parent;
|
||||
if( simpleDecl.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef ){
|
||||
binding = new CPPTypedef( declarator );
|
||||
binding = new CPPTypedef( declarator.getName() );
|
||||
} else {
|
||||
IType t1 = null, t2 = null;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue