1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Correcting IASTName.toCharArray() part II, bug 258054.

This commit is contained in:
Markus Schorn 2008-12-22 13:53:40 +00:00
parent 6500b127d1
commit edc37c6d03
39 changed files with 259 additions and 289 deletions

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
* Doug Schaefer (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Andrew Ferguson (Symbian)
*******************************************************************************/
@ -109,9 +109,7 @@ import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
import org.eclipse.cdt.internal.core.parser.ParserException;
/**
* Test the new AST.
*
* @author Doug Schaefer
* Testcases on the AST.
*/
public class AST2Tests extends AST2BaseTest {
@ -5735,12 +5733,15 @@ public class AST2Tests extends AST2BaseTest {
}
buf.append(input[2].toString());
final String code= buf.toString();
long mem= memoryUsed();
for (ParserLanguage lang : ParserLanguage.values()) {
IASTTranslationUnit tu= parse(code, lang, false, true, true);
tu= null;
long mem= memoryUsed();
tu= parse(code, lang, false, true, true);
long diff= memoryUsed()-mem;
final int expected = 1024*10 + code.length()*2; // a copy of the buffer + some
final int expected = 1024*20 + code.length()*2; // a copy of the buffer + some
assertTrue(String.valueOf(diff) + " expected < " + expected, diff < expected);
assertTrue(tu.isFrozen());
}
}

View file

@ -107,5 +107,23 @@ public interface IASTName extends IASTNode, IName {
* Set the semantic object for this name to be the given binding
* @noreference This method is not intended to be referenced by clients.
*/
public void setBinding( IBinding binding );
public void setBinding(IBinding binding);
/**
* Get the key for looking up this name in a scope.
* @noreference This method is not intended to be referenced by clients.
*/
public char[] getLookupKey();
/**
* Gets the intermediate representation of the biniding, if already available.
* @noreference This method is not intended to be referenced by clients.
*/
public IBinding getPreBinding();
/**
* Resolves to an intermediate representation of the binding.
* @noreference This method is not intended to be referenced by clients.
*/
public IBinding resolvePreBinding();
}

View file

@ -19,7 +19,6 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase;
/**
* Base implementation for all ambiguous nodes.
@ -95,7 +94,7 @@ public abstract class ASTAmbiguousNode extends ASTNode {
int issues= 0;
for (IASTName name : names) {
try {
IBinding b= CPPASTNameBase.resolvePreBinding(name);
IBinding b= name.resolvePreBinding();
if (b instanceof IProblemBinding) {
issues++;
}

View file

@ -1614,8 +1614,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
}
}
}
assert dtor.getNestedDeclarator() != null || dtor.getName().getSimpleID().length > 0;
}
}
}

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* Andrew Niefer (IBM Corporation) - initial API and implementation
* Markus Schorn (Wind River Systems)
* Bryan Wilkinson (QNX)
*******************************************************************************/
@ -26,13 +26,14 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
import org.eclipse.cdt.internal.core.parser.ParserMessages;
import org.eclipse.core.runtime.PlatformObject;
/**
* @author aniefer
* Implementation of problem bindings
*/
public class ProblemBinding extends PlatformObject implements IProblemBinding, IType, IScope, IASTInternalScope {
protected final int id;
@ -108,7 +109,7 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I
* @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
*/
public char[] getNameCharArray() {
return CPPSemantics.EMPTY_NAME_ARRAY;
return CharArrayUtils.EMPTY;
}
/* (non-Javadoc)

View file

@ -34,7 +34,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator;
import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator.EvalException;
@ -334,7 +333,7 @@ public class Value implements IValue {
return CONDITIONAL_CHAR + SEPARATOR + o.toString() + SEPARATOR + po.toString() + SEPARATOR + neg.toString();
}
if (e instanceof IASTIdExpression) {
IBinding b= CPPASTNameBase.resolvePreBinding(((IASTIdExpression) e).getName());
IBinding b= ((IASTIdExpression) e).getName().resolvePreBinding();
return evaluateBinding(b, unknownSigs, unknowns, maxdepth);
}
if (e instanceof IASTLiteralExpression) {

View file

@ -63,10 +63,18 @@ public class CASTName extends ASTNode implements IASTName, IASTCompletionContext
return binding;
}
public IBinding resolvePreBinding() {
return resolveBinding();
}
public IBinding getBinding() {
return binding;
}
public IBinding getPreBinding() {
return binding;
}
public IASTCompletionContext getCompletionContext() {
IASTNode node = getParent();
@ -101,6 +109,10 @@ public class CASTName extends ASTNode implements IASTName, IASTCompletionContext
public char[] getSimpleID() {
return name;
}
public char[] getLookupKey() {
return name;
}
@Override
public boolean accept(ASTVisitor action) {

View file

@ -60,7 +60,7 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat
}
public IBinding getBinding(IASTName name, boolean forceResolve, IIndexFileSet fileSet) throws DOMException {
char[] c = name.getSimpleID();
char[] c = name.getLookupKey();
if (CharArrayUtils.equals(c, specialClass.getNameCharArray()) && !CPPClassScope.isConstructorReference(name)) {
return specialClass;
@ -83,7 +83,7 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat
public IBinding[] getBindings(IASTName name, boolean forceResolve, boolean prefixLookup,
IIndexFileSet fileSet) throws DOMException {
char[] c = name.getSimpleID();
char[] c = name.getLookupKey();
IBinding[] result = null;
if ((!prefixLookup && CharArrayUtils.equals(c, specialClass.getNameCharArray())) ||

View file

@ -12,9 +12,11 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
@ -93,8 +95,13 @@ public class CPPASTConversionName extends CPPASTNameBase implements ICPPASTConve
buf.append(Keywords.cOPERATOR);
buf.append(' ');
if (typeId != null) {
buf.append(typeId.getRawSignature());
WHITESPACE_SEQ.matcher(buf).replaceAll(" "); //$NON-NLS-1$
IType t= CPPVisitor.createType(typeId);
if (t != null) {
buf.append(ASTTypeUtil.getType(t, true));
} else {
buf.append(typeId.getRawSignature());
WHITESPACE_SEQ.matcher(buf).replaceAll(" "); //$NON-NLS-1$
}
}
final int len= buf.length();
fName= new char[len];
@ -106,4 +113,8 @@ public class CPPASTConversionName extends CPPASTNameBase implements ICPPASTConve
public char[] getSimpleID() {
return toCharArray();
}
public char[] getLookupKey() {
return Keywords.cOPERATOR;
}
}

View file

@ -205,7 +205,7 @@ public class CPPASTDeclarator extends ASTNode implements IASTDeclarator {
return r_reference;
}
if (getParent instanceof IASTParameterDeclaration)
return (n.getSimpleID().length > 0) ? r_definition : r_declaration;
return (n.getLookupKey().length > 0) ? r_definition : r_declaration;
return r_unclear;
}

View file

@ -140,6 +140,10 @@ public class CPPASTName extends CPPASTNameBase implements IASTCompletionContext
return name;
}
public char[] getLookupKey() {
return name;
}
public void setName(char[] name) {
assertNotFrozen();
this.name = name;

View file

@ -19,9 +19,6 @@ import org.eclipse.cdt.core.dom.ast.IASTNameOwner;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTInternalNameOwner;
@ -49,42 +46,6 @@ public abstract class CPPASTNameBase extends ASTNode implements IASTName {
}
}
/**
* Helper method to resolve intermediate bindings without casting the name.
*/
public static IBinding resolvePreBinding(IASTName name) {
if (name == null)
return null;
if (name instanceof CPPASTNameBase)
return ((CPPASTNameBase) name).resolvePreBinding();
return name.resolveBinding();
}
/**
* Helper method to get intermediate bindings without casting the name.
*/
public static IBinding getPreBinding(IASTName name) {
if (name == null)
return null;
if (name instanceof CPPASTNameBase)
return ((CPPASTNameBase) name).getPreBinding();
return name.getBinding();
}
/**
* Helper method, returns "operator" for conversion names, and {@code IASTName#getSimpleName()}, otherwise.
*/
public static char[] getLookupKey(IASTName name) {
name= name.getLastName();
if (name instanceof ICPPASTTemplateId)
name= ((ICPPASTTemplateId) name).getTemplateName();
if (name instanceof ICPPASTConversionName)
return Keywords.cOPERATOR;
return name.toCharArray();
}
private IBinding fBinding = null;
private byte fResolutionDepth = 0;
private boolean fIsFinal= false;

View file

@ -66,7 +66,7 @@ public class CPPASTQualifiedName extends CPPASTNameBase
@Override
public final IBinding resolvePreBinding() {
// The full qualified name resolves to the same thing as the last name
return resolvePreBinding(getLastName());
return getLastName().resolvePreBinding();
}
@Override
@ -79,7 +79,7 @@ public class CPPASTQualifiedName extends CPPASTNameBase
@Override
public final IBinding getPreBinding() {
// The full qualified name resolves to the same thing as the last name
return getPreBinding(getLastName());
return getLastName().getPreBinding();
}
@Override
@ -123,6 +123,10 @@ public class CPPASTQualifiedName extends CPPASTNameBase
return names[namesPos].getSimpleID();
}
public char[] getLookupKey() {
return names[namesPos].getLookupKey();
}
public char[] toCharArray() {
if (signature == null) {
StringBuilder buf= new StringBuilder();
@ -172,7 +176,7 @@ public class CPPASTQualifiedName extends CPPASTNameBase
final IASTName name = names[i];
if (i == namesPos) {
// pointer-to-member qualified names have a dummy name as the last part of the name, don't visit it
if (getLookupKey(name).length > 0 && !name.accept(action))
if (name.getLookupKey().length > 0 && !name.accept(action))
return false;
} else if (!name.accept(action))
return false;
@ -246,7 +250,7 @@ public class CPPASTQualifiedName extends CPPASTNameBase
List<IBinding> filtered = filterClassScopeBindings(classType, bindings, isDeclaration);
if (isDeclaration && nameMatches(classType.getNameCharArray(),
n.getSimpleID(), isPrefix)) {
n.getLookupKey(), isPrefix)) {
try {
ICPPConstructor[] constructors = classType.getConstructors();
for (int i = 0; i < constructors.length; i++) {

View file

@ -58,6 +58,10 @@ public class CPPASTTemplateId extends CPPASTNameBase implements ICPPASTTemplateI
return templateName.getSimpleID();
}
public char[] getLookupKey() {
return templateName.getLookupKey();
}
public IASTName getTemplateName() {
return templateName;
}

View file

@ -61,8 +61,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
/**
* Base implementation for c++ scopes.
*
* mstodo store user defined conversions under the same key, see {@link CPPASTNameBase#getLookupKey(IASTName)}
*/
public class CPPClassScope extends CPPScope implements ICPPClassScope {
private static final char[] CONSTRUCTOR_KEY = "!!!CTOR!!!".toCharArray(); //$NON-NLS-1$
@ -98,7 +96,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
} catch (DOMException e) {
}
}
char[] className = name.getSimpleID();
char[] className = name.getLookupKey();
IParameter[] voidPs = new IParameter[] { new CPPParameter(CPPSemantics.VOID_TYPE) };
IType pType = new CPPReferenceType(new CPPQualifierType(clsType, true, false));
@ -171,7 +169,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
final ICPPASTQualifiedName qname = (ICPPASTQualifiedName) name;
final IASTName[] names= qname.getNames();
for (int i = names.length-2; i>=0; i--) {
if (b == null || !CharArrayUtils.equals(names[i].getSimpleID(), b.getNameCharArray()))
if (b == null || !CharArrayUtils.equals(names[i].getLookupKey(), b.getNameCharArray()))
return;
b= b.getOwner();
@ -213,14 +211,14 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
*/
@Override
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) throws DOMException {
char[] c = name.getSimpleID();
char[] c = name.getLookupKey();
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
IASTName compName = compType.getName().getLastName();
if (compName instanceof ICPPASTTemplateId) {
compName= ((ICPPASTTemplateId) compName).getTemplateName();
}
if (CharArrayUtils.equals(c, compName.getSimpleID())) {
if (CharArrayUtils.equals(c, compName.getLookupKey())) {
if (isConstructorReference(name)) {
return CPPSemantics.resolveAmbiguities(name, getConstructors(bindings, resolve, name));
}
@ -232,7 +230,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
@Override
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) throws DOMException {
char[] c = name.getSimpleID();
char[] c = name.getLookupKey();
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
IASTName compName = compType.getName().getLastName();
@ -240,8 +238,8 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
compName= ((ICPPASTTemplateId) compName).getTemplateName();
}
IBinding[] result = null;
if ((!prefixLookup && CharArrayUtils.equals(c, compName.getSimpleID()))
|| (prefixLookup && CharArrayUtils.equals(compName.getSimpleID(), 0, c.length, c, true))) {
if ((!prefixLookup && CharArrayUtils.equals(c, compName.getLookupKey()))
|| (prefixLookup && CharArrayUtils.equals(compName.getLookupKey(), 0, c.length, c, true))) {
if (isConstructorReference(name)) {
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, getConstructors(bindings, resolve, name));
}
@ -324,7 +322,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
compName= ((ICPPASTTemplateId) compName).getTemplateName();
}
if (CharArrayUtils.equals(compName.getSimpleID(), n)) {
if (CharArrayUtils.equals(compName.getLookupKey(), n)) {
return new IBinding[] {compName.resolveBinding()};
}
@ -369,7 +367,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
*/
public ICPPMethod[] getImplicitMethods() {
if (implicits == null)
implicits = new ICPPMethod[] { new CPPMethod.CPPMethodProblem(null, IProblemBinding.SEMANTIC_INVALID_TYPE, CPPSemantics.EMPTY_NAME_ARRAY) };
implicits = new ICPPMethod[] { new CPPMethod.CPPMethodProblem(null, IProblemBinding.SEMANTIC_INVALID_TYPE, CharArrayUtils.EMPTY) };
return implicits;
}
@ -448,7 +446,7 @@ class ImplicitsAnalysis {
private static ICPPASTFunctionDeclarator[] getUserDeclaredCtorOrDtor(ICPPASTCompositeTypeSpecifier compSpec, boolean constructor) {
List<ICPPASTFunctionDeclarator> result= new ArrayList<ICPPASTFunctionDeclarator>();
IASTDeclaration[] members = compSpec.getMembers();
char[] name = compSpec.getName().getSimpleID();
char[] name = compSpec.getName().getLookupKey();
IASTDeclarator dcltor = null;
IASTDeclSpecifier spec = null;
for (IASTDeclaration member : members) {
@ -470,7 +468,7 @@ class ImplicitsAnalysis {
}
boolean nameEquals= false;
char[] dtorname= CPPASTNameBase.getLookupKey(CPPVisitor.findInnermostDeclarator(dcltor).getName());
char[] dtorname= CPPVisitor.findInnermostDeclarator(dcltor).getName().getLookupKey();
if (constructor) {
nameEquals= CharArrayUtils.equals(dtorname, name);
} else {
@ -503,7 +501,7 @@ class ImplicitsAnalysis {
if (dcltor instanceof ICPPASTFunctionDeclarator == false)
continue;
final char[] nchars= CPPASTNameBase.getLookupKey(CPPVisitor.findInnermostDeclarator(dcltor).getName());
final char[] nchars= CPPVisitor.findInnermostDeclarator(dcltor).getName().getLookupKey();
if (!CharArrayUtils.equals(nchars, OverloadableOperator.ASSIGN.toCharArray()))
continue;

View file

@ -100,23 +100,21 @@ public class CPPClassSpecialization extends CPPSpecialization
return PROCESS_SKIP;
if( name instanceof ICPPASTQualifiedName )
return PROCESS_CONTINUE;
char [] c = name.toCharArray();
char[] c = name.getLookupKey();
if( name.getParent() instanceof ICPPASTQualifiedName ){
IASTName [] ns = ((ICPPASTQualifiedName)name.getParent()).getNames();
if( ns[ ns.length - 1 ] != name )
if (name.getParent() instanceof ICPPASTQualifiedName) {
IASTName[] ns = ((ICPPASTQualifiedName) name.getParent()).getNames();
if (ns[ns.length - 1] != name)
return PROCESS_CONTINUE;
name = (IASTName) name.getParent();
}
if( name.getParent() instanceof ICPPASTCompositeTypeSpecifier &&
CharArrayUtils.equals( c, nameArray ) )
{
if (name.getParent() instanceof ICPPASTCompositeTypeSpecifier && CharArrayUtils.equals(c, nameArray)) {
IBinding binding = name.resolveBinding();
if( binding == CPPClassSpecialization.this ){
if( name instanceof ICPPASTQualifiedName ){
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
name = ns[ ns.length - 1 ];
if (binding == CPPClassSpecialization.this) {
if (name instanceof ICPPASTQualifiedName) {
IASTName[] ns = ((ICPPASTQualifiedName) name).getNames();
name = ns[ns.length - 1];
}
result = name;
return PROCESS_ABORT;

View file

@ -68,25 +68,20 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements
public int visit(IASTName name) {
if (name instanceof ICPPASTTemplateId || name instanceof ICPPASTQualifiedName)
return PROCESS_CONTINUE;
char[] c = name.toCharArray();
char[] c = name.getLookupKey();
if (name.getParent() instanceof ICPPASTTemplateId)
name = (IASTName) name.getParent();
if (name.getParent() instanceof ICPPASTQualifiedName) {
IASTName[] ns = ((ICPPASTQualifiedName)name.getParent()).getNames();
IASTName[] ns = ((ICPPASTQualifiedName) name.getParent()).getNames();
if (ns[ns.length - 1] != name)
return PROCESS_CONTINUE;
name = (IASTName) name.getParent();
}
if (name.getParent() instanceof ICPPASTCompositeTypeSpecifier &&
CharArrayUtils.equals(c, nameArray)) {
if (name.getParent() instanceof ICPPASTCompositeTypeSpecifier && CharArrayUtils.equals(c, nameArray)) {
IBinding binding = name.resolveBinding();
if (binding == CPPClassTemplate.this) {
if (name instanceof ICPPASTQualifiedName) {
IASTName[] ns = ((ICPPASTQualifiedName)name).getNames();
name = ns[ns.length - 1];
}
result = name;
result = name.getLastName();
return PROCESS_ABORT;
}
}

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* Andrew Niefer (IBM Corporation) - initial API and implementation
* Markus Schorn (Wind River Systems)
* Bryan Wilkinson (QNX)
* Sergey Prigogin (Google)
@ -57,8 +57,7 @@ import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.core.runtime.PlatformObject;
/**
*
* @author aniefer
* Binding for a class type.
*/
public class CPPClassType extends PlatformObject implements ICPPInternalClassTypeMixinHost {
@ -136,25 +135,19 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp
return PROCESS_SKIP;
if( name instanceof ICPPASTQualifiedName )
return PROCESS_CONTINUE;
char [] c = name.toCharArray();
char[] c = name.getLookupKey();
if( name.getParent() instanceof ICPPASTQualifiedName ){
IASTName [] ns = ((ICPPASTQualifiedName)name.getParent()).getNames();
if( ns[ ns.length - 1 ] != name )
if (name.getParent() instanceof ICPPASTQualifiedName) {
IASTName[] ns = ((ICPPASTQualifiedName) name.getParent()).getNames();
if (ns[ns.length - 1] != name)
return PROCESS_CONTINUE;
name = (IASTName) name.getParent();
}
if( name.getParent() instanceof ICPPASTCompositeTypeSpecifier &&
CharArrayUtils.equals( c, nameArray ) )
{
if (name.getParent() instanceof ICPPASTCompositeTypeSpecifier && CharArrayUtils.equals(c, nameArray)) {
IBinding binding = name.resolveBinding();
if( binding == CPPClassType.this ){
if( name instanceof ICPPASTQualifiedName ){
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
name = ns[ ns.length - 1 ];
}
result = name;
if (binding == CPPClassType.this) {
result= name.getLastName();
return PROCESS_ABORT;
}
}

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* Andrew Niefer (IBM Corporation) - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -30,7 +30,7 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
/**
* @author aniefer
* Binding for a field.
*/
public class CPPField extends CPPVariable implements ICPPField {
public static class CPPFieldProblem extends CPPVariable.CPPVariableProblem implements ICPPField {
@ -85,13 +85,11 @@ public class CPPField extends CPPVariable implements ICPPField {
ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(scope);
IASTDeclaration [] members = compSpec.getMembers();
for (IASTDeclaration member : members) {
if( member instanceof IASTSimpleDeclaration ){
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)member).getDeclarators();
if (member instanceof IASTSimpleDeclaration) {
IASTDeclarator[] dtors = ((IASTSimpleDeclaration) member).getDeclarators();
for (IASTDeclarator dtor : dtors) {
IASTName name = dtor.getName();
if( CharArrayUtils.equals( name.getSimpleID(), myName ) &&
name.resolveBinding() == this )
{
if (CharArrayUtils.equals(name.getLookupKey(), myName) && name.resolveBinding() == this) {
return member;
}
}

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* Andrew Niefer (IBM Corporation) - initial API and implementation
* Markus Schorn (Wind River Systems)
* Bryan Wilkinson (QNX)
*******************************************************************************/
@ -34,7 +34,7 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
/**
* @author aniefer
* Scope of a function, containing labels.
*/
public class CPPFunctionScope extends CPPScope implements ICPPFunctionScope {
@ -70,7 +70,7 @@ public class CPPFunctionScope extends CPPScope implements ICPPFunctionScope {
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#getBinding(int, char[])
*/
public IBinding getBinding(IASTName name) {
return (IBinding) labels.get(name.getSimpleID());
return (IBinding) labels.get(name.getLookupKey());
}
/* (non-Javadoc)

View file

@ -112,7 +112,7 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod
while( dtor != null ){
IASTName name = CPPVisitor.findInnermostDeclarator(dtor).getName();
if( CPPVisitor.findTypeRelevantDeclarator(dtor) instanceof ICPPASTFunctionDeclarator &&
CharArrayUtils.equals( name.getSimpleID(), getNameCharArray() ) )
CharArrayUtils.equals( name.getLookupKey(), getNameCharArray() ) )
{
IType t0= CPPVisitor.createType( dtor );
boolean ok= false;

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* Andrew Niefer (IBM Corporation) - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -35,7 +35,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
/**
* @author aniefer
* The binding for a method.
*/
public class CPPMethod extends CPPFunction implements ICPPMethod {
public static class CPPMethodProblem extends CPPFunctionProblem implements ICPPMethod {
@ -98,29 +98,24 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
}
}
char [] myName = getNameCharArray();
final char[] myName = getASTName().getLookupKey();
ICPPClassScope scope = (ICPPClassScope) getScope();
ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(scope);
if (compSpec != null) {
IASTDeclaration [] members = compSpec.getMembers();
for (IASTDeclaration member : members) {
if( member instanceof IASTSimpleDeclaration ){
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)member).getDeclarators();
if (member instanceof IASTSimpleDeclaration) {
IASTDeclarator[] dtors = ((IASTSimpleDeclaration) member).getDeclarators();
for (IASTDeclarator dtor : dtors) {
IASTName name = CPPVisitor.findInnermostDeclarator(dtor).getName();
if( CharArrayUtils.equals( name.getSimpleID(), myName ) &&
name.resolveBinding() == this )
{
if (CharArrayUtils.equals(name.getLookupKey(), myName) && name.resolveBinding() == this) {
return member;
}
}
} else if( member instanceof IASTFunctionDefinition ){
} else if (member instanceof IASTFunctionDefinition) {
final IASTFunctionDeclarator declarator = ((IASTFunctionDefinition) member).getDeclarator();
IASTName name = CPPVisitor.findInnermostDeclarator(declarator).getName();
if( CharArrayUtils.equals( name.getSimpleID(), myName ) &&
name.resolveBinding() == this )
{
if (CharArrayUtils.equals(name.getLookupKey(), myName) && name.resolveBinding() == this) {
return member;
}
}

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Andrew Niefer (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -32,14 +32,10 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
/**
* @author aniefer
* A template for a method.
*/
public class CPPMethodTemplate extends CPPFunctionTemplate implements
ICPPMethod {
public class CPPMethodTemplate extends CPPFunctionTemplate implements ICPPMethod {
/**
* @param name
*/
public CPPMethodTemplate(IASTName name) {
super(name);
}
@ -58,37 +54,31 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
}
}
char [] myName = getNameCharArray();
final char[] myName = getTemplateName().getLookupKey();
IScope scope = getScope();
if( scope instanceof ICPPTemplateScope )
scope = scope.getParent();
if (scope instanceof ICPPTemplateScope)
scope = scope.getParent();
ICPPClassScope clsScope = (ICPPClassScope) scope;
ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(clsScope);
IASTDeclaration [] members = compSpec.getMembers();
IASTDeclaration[] members = compSpec.getMembers();
for (IASTDeclaration member : members) {
if( member instanceof ICPPASTTemplateDeclaration ){
IASTDeclaration decl = ((ICPPASTTemplateDeclaration)member).getDeclaration();
if( decl instanceof IASTSimpleDeclaration ){
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
if (member instanceof ICPPASTTemplateDeclaration) {
IASTDeclaration decl = ((ICPPASTTemplateDeclaration) member).getDeclaration();
if (decl instanceof IASTSimpleDeclaration) {
IASTDeclarator[] dtors = ((IASTSimpleDeclaration) decl).getDeclarators();
for (IASTDeclarator dtor : dtors) {
IASTName name = CPPVisitor.findInnermostDeclarator(dtor).getName();
if( CharArrayUtils.equals( name.getSimpleID(), myName ) &&
name.resolveBinding() == this )
{
if (CharArrayUtils.equals(name.getLookupKey(), myName) && name.resolveBinding() == this) {
return member;
}
}
} else if( decl instanceof IASTFunctionDefinition ){
} else if (decl instanceof IASTFunctionDefinition) {
IASTName name = CPPVisitor.findInnermostDeclarator(((IASTFunctionDefinition) decl).getDeclarator()).getName();
if( CharArrayUtils.equals( name.getSimpleID(), myName ) &&
name.resolveBinding() == this )
{
if (CharArrayUtils.equals(name.getLookupKey(), myName) && name.resolveBinding() == this) {
return member;
}
}
}
}
}
return null;
}

View file

@ -109,7 +109,7 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI
public int visit(ICPPASTNamespaceDefinition namespace) {
ICPPASTNamespaceDefinition orig = namespaceDef, candidate = namespace;
while(candidate != null) {
if (!CharArrayUtils.equals(orig.getName().getSimpleID(), candidate.getName().getSimpleID()))
if (!CharArrayUtils.equals(orig.getName().getLookupKey(), candidate.getName().getLookupKey()))
return PROCESS_CONTINUE;
if (orig.getParent() instanceof ICPPASTNamespaceDefinition) {
if (!(candidate.getParent() instanceof ICPPASTNamespaceDefinition))

View file

@ -103,7 +103,7 @@ public class CPPNamespaceScope extends CPPScope implements ICPPNamespaceScope{
}
@Override
public int leave(ICPPASTNamespaceDefinition namespace) {
if (namespace.getName().getSimpleID().length > 0) {
if (namespace.getName().getLookupKey().length > 0) {
--depth;
}
return PROCESS_CONTINUE;

View file

@ -27,10 +27,10 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.core.runtime.PlatformObject;
@ -154,7 +154,7 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI
IASTName name = getPrimaryDeclaration();
if (name != null)
return name.getSimpleID();
return CPPSemantics.EMPTY_NAME_ARRAY;
return CharArrayUtils.EMPTY;
}
/* (non-Javadoc)

View file

@ -80,7 +80,7 @@ public class CPPPointerToMemberType extends CPPPointerType implements ICPPPointe
name = ns[ns.length - 1];
}
IBinding binding = CPPASTNameBase.resolvePreBinding(name);
IBinding binding = name.resolvePreBinding();
if (binding instanceof IType) {
classType = (IType) binding;
} else {

View file

@ -86,7 +86,7 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
if (!canDenoteScopeMember((ICPPASTQualifiedName) name))
return;
}
final char[] c= name.getSimpleID();
final char[] c= name.getLookupKey();
Object o = bindings.get(c);
if (o != null) {
if (o instanceof ObjectSet) {
@ -132,7 +132,7 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
final IASTTranslationUnit tu = name.getTranslationUnit();
IIndex index = tu == null ? null : tu.getIndex();
if (index != null) {
final char[] nchars = name.getSimpleID();
final char[] nchars = name.getLookupKey();
// Try looking this up in the PDOM
if (physicalNode instanceof IASTTranslationUnit) {
try {
@ -174,7 +174,7 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
}
public IBinding getBindingInAST(IASTName name, boolean forceResolve) throws DOMException {
char[] c = name.getSimpleID();
char[] c = name.getLookupKey();
//can't look up bindings that don't have a name
if (c.length == 0)
return null;
@ -234,7 +234,7 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
if (physicalNode instanceof IASTTranslationUnit) {
try {
IndexFilter filter = IndexFilter.CPP_DECLARED_OR_IMPLICIT_NO_INSTANCE;
final char[] nchars = name.getSimpleID();
final char[] nchars = name.getLookupKey();
IBinding[] bindings = prefixLookup ?
index.findBindingsForPrefix(nchars, true, filter, null) :
index.findBindings(nchars, filter, null);
@ -269,7 +269,7 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
public IBinding[] getBindingsInAST(IASTName name, boolean forceResolve, boolean prefixLookup)
throws DOMException {
char[] c = name.getSimpleID();
char[] c = name.getLookupKey();
IBinding[] result = null;
Object[] obj = null;

View file

@ -265,7 +265,7 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC
ICPPASTTemplateParameter[] params = CPPTemplates.getTemplateDeclaration(tdecl).getTemplateParameters();
if (pos < params.length) {
final IASTName oName = CPPTemplates.getTemplateParameterName(params[pos]);
return CPPASTNameBase.resolvePreBinding(oName);
return oName.resolvePreBinding();
}
}
return templateParameter;
@ -295,7 +295,7 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC
int end= Math.min(params.length, updateParams.length);
for (; k < end; k++) {
final IASTName oName = CPPTemplates.getTemplateParameterName(params[k]);
IBinding b= CPPASTNameBase.resolvePreBinding(oName);
IBinding b= oName.resolvePreBinding();
IASTName n = CPPTemplates.getTemplateParameterName(updateParams[k]);
n.setBinding(b);
if (b instanceof ICPPInternalBinding) {

View file

@ -147,12 +147,12 @@ public class CPPUnknownScope implements ICPPScope, ICPPInternalUnknownScope {
if (map == null)
map = new CharArrayObjectMap(2);
char[] c = name.getSimpleID();
IBinding[] o= (IBinding[]) map.get(c);
if (o == null) {
o= new IBinding[3];
map.put(c, o);
}
final char[] c = name.getLookupKey();
IBinding[] o = (IBinding[]) map.get(c);
if (o == null) {
o = new IBinding[3];
map.put(c, o);
}
int idx= type ? 0 : function ? 1 : 2;
IBinding result= o[idx];

View file

@ -2282,7 +2282,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
}
identifier= qualifiedName();
if (identifier.getSimpleID().length == 0 && LT(1) != IToken.tEOC)
if (identifier.getLookupKey().length == 0 && LT(1) != IToken.tEOC)
throwBacktrack(LA(1));
endOffset= calculateEndOffset(identifier);
@ -2395,7 +2395,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
final int len = names.length;
final IASTName lastName = names[len-1];
if (len > 1 && CharArrayUtils.equals(CPPASTNameBase.getLookupKey(names[len-2]), CPPASTNameBase.getLookupKey(lastName)))
if (len > 1 && CharArrayUtils.equals(names[len-2].getLookupKey(), lastName.getLookupKey()))
return true; // constructor
name= lastName;
@ -2406,7 +2406,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (name instanceof ICPPASTConversionName)
return true;
final char[] nchars= name.getSimpleID();
final char[] nchars= name.getLookupKey();
if (nchars.length > 0 && nchars[0] == '~')
return true; // destructor
if (declOption == DeclarationOptions.CPP_MEMBER && CharArrayUtils.equals(nchars, currentClassName))
@ -2942,7 +2942,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (coloncolon != 0) {
try {
name= qualifiedName();
if (CPPASTNameBase.getLookupKey(name).length != 0) {
if (name.getLookupKey().length != 0) {
backup(mark);
return;
}
@ -3286,7 +3286,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
int endOffset= consume().getEndOffset();
final char[] outerName= currentClassName;
currentClassName= name.getSimpleID();
currentClassName= name.getLookupKey();
try {
int declOffset= -1;

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
* Andrew Niefer (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Bryan Wilkinson (QNX)
* Andrew Ferguson (Symbian)
@ -72,6 +72,7 @@ import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTForStatement;
@ -158,7 +159,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator;
import org.eclipse.cdt.internal.core.index.IIndexScope;
/**
* @author aniefer
* Name resolution
*/
public class CPPSemantics {
/**
@ -168,7 +169,6 @@ public class CPPSemantics {
public static final ASTNodeProperty STRING_LOOKUP_PROPERTY =
new ASTNodeProperty("CPPSemantics.STRING_LOOKUP_PROPERTY - STRING_LOOKUP"); //$NON-NLS-1$
public static final char[] EMPTY_NAME_ARRAY = new char[0];
public static final String EMPTY_NAME = ""; //$NON-NLS-1$
public static final char[] OPERATOR_ = new char[] {'o','p','e','r','a','t','o','r',' '};
public static final IType VOID_TYPE = new CPPBasicType(IBasicType.t_void, 0);
@ -290,7 +290,7 @@ public class CPPSemantics {
node= node.getParent();
}
if (!ok) {
binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_INVALID_TYPE, data.name());
binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_INVALID_TYPE, data.getNameCharArray());
}
}
}
@ -364,11 +364,11 @@ public class CPPSemantics {
if (parent instanceof IASTTypeId && parent.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) {
if (!(binding instanceof IType)) {
// a type id needs to hold a type
binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_INVALID_TYPE, data.name());
binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_INVALID_TYPE, data.getNameCharArray());
}
// don't create a problem here
} else {
binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_INVALID_TYPE, data.name());
binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_INVALID_TYPE, data.getNameCharArray());
}
}
}
@ -381,9 +381,9 @@ public class CPPSemantics {
// If we're still null...
if (binding == null) {
if (name instanceof ICPPASTQualifiedName && data.forFunctionDeclaration())
binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND, data.name());
binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND, data.getNameCharArray());
else
binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, data.name());
binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, data.getNameCharArray());
}
return binding;
}
@ -915,14 +915,14 @@ public class CPPSemantics {
for (int j = 0; j < r.length && r[j] != null; j++) {
if (checkForAmbiguity(data, r[j], inherited)) {
data.problem = new ProblemBinding(data.astName,
IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name());
IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getNameCharArray());
return null;
}
}
} else {
if (checkForAmbiguity(data, result, inherited)) {
data.problem = new ProblemBinding(data.astName,
IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name());
IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getNameCharArray());
return null;
}
}
@ -1193,7 +1193,7 @@ public class CPPSemantics {
nsscope.addUsingDirective(new CPPUsingDirective(usingDirective));
}
} else if (item instanceof ICPPASTNamespaceDefinition &&
((ICPPASTNamespaceDefinition)item).getName().getSimpleID().length == 0) {
((ICPPASTNamespaceDefinition)item).getName().getLookupKey().length == 0) {
if (scope instanceof ICPPNamespaceScope) {
final ICPPNamespaceScope nsscope = (ICPPNamespaceScope)scope;
final ICPPASTNamespaceDefinition nsdef= (ICPPASTNamespaceDefinition) item;
@ -1418,7 +1418,7 @@ public class CPPSemantics {
// anonymous union? //GCC supports anonymous structs too
if (declarators.length == 0 && /*compSpec.getKey() == IASTCompositeTypeSpecifier.k_union &&*/
specName.getSimpleID().length == 0)
specName.getLookupKey().length == 0)
{
Object o = null;
IASTDeclaration[] decls = compSpec.getMembers();
@ -1522,6 +1522,9 @@ public class CPPSemantics {
}
private static final boolean nameMatches(LookupData data, IASTName potential, IScope scope) throws DOMException{
final IASTName name = data.astName;
if (name == null)
return false;
if (potential instanceof ICPPASTQualifiedName) {
IASTNode phn= ASTInternal.getPhysicalNodeOfScope(scope);
if (phn instanceof ICPPASTCompositeTypeSpecifier == false && phn instanceof ICPPASTNamespaceDefinition == false)
@ -1535,8 +1538,8 @@ public class CPPSemantics {
potential= qname.getLastName();
}
char[] c = potential.getSimpleID();
char[] n = data.name();
char[] c = potential.getLookupKey();
char[] n = name.getLookupKey();
return (data.prefixLookup && CharArrayUtils.equals(c, 0, n.length, n, true))
|| (!data.prefixLookup && CharArrayUtils.equals(c, n));
}
@ -1562,7 +1565,7 @@ public class CPPSemantics {
if (bindings[0] instanceof IBinding) {
candidate= (IBinding) bindings[0];
} else if (bindings[0] instanceof IASTName) {
candidate= CPPASTNameBase.getPreBinding((IASTName) bindings[0]);
candidate= ((IASTName) bindings[0]).getPreBinding();
} else {
return null;
}
@ -1723,9 +1726,9 @@ public class CPPSemantics {
if (o instanceof IASTName) {
IASTName on= (IASTName) o;
if (checkResolvedNamesOnly) {
temp = CPPASTNameBase.getPreBinding(on);
temp = on.getPreBinding();
} else {
temp= CPPASTNameBase.resolvePreBinding(on);
temp= on.resolvePreBinding();
}
if (temp == null)
continue;
@ -1792,7 +1795,7 @@ public class CPPSemantics {
if (type == null) {
type = temp;
} else if (type != temp && !((IType)type).isSameType((IType) temp)) {
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name());
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getNameCharArray());
}
} else {
if (obj == null) {
@ -1808,7 +1811,7 @@ public class CPPSemantics {
if (ibobj)
obj= temp;
} else {
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name());
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getNameCharArray());
}
}
}
@ -1816,7 +1819,7 @@ public class CPPSemantics {
if (data.forUsingDeclaration()) {
IBinding[] bindings = null;
if (obj != null) {
if (fns.size() > 0) return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name());
if (fns.size() > 0) return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getNameCharArray());
// if (type == null) return obj;
bindings = (IBinding[]) ArrayUtil.append(IBinding.class, bindings, obj);
bindings = (IBinding[]) ArrayUtil.append(IBinding.class, bindings, type);
@ -1856,7 +1859,7 @@ public class CPPSemantics {
if (numFns > 0) {
if (obj != null)
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name());
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getNameCharArray());
return resolveFunction(data, fns.keyArray(IFunction.class));
}
@ -2009,6 +2012,10 @@ public class CPPSemantics {
if (data.forUsingDeclaration()) {
return new CPPUsingDeclaration(data.astName, fns);
}
if (data.astName instanceof ICPPASTConversionName) {
return resolveUserDefinedConversion((ICPPASTConversionName) data.astName, fns);
}
// We don't have any arguments with which to resolve the function
if (data.functionParameters == null) {
@ -2184,12 +2191,31 @@ public class CPPSemantics {
}
if (ambiguous || bestHasAmbiguousParam) {
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name());
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getNameCharArray());
}
return bestFn;
}
private static IBinding resolveUserDefinedConversion(ICPPASTConversionName astName, IFunction[] fns) {
IType t= CPPVisitor.createType(astName.getTypeId());
if (t == null) {
return new ProblemBinding(astName, IProblemBinding.SEMANTIC_INVALID_TYPE, astName.toCharArray());
}
for (IFunction function : fns) {
if (function != null) {
try {
IType t2= function.getType().getReturnType();
if (t.isSameType(t2))
return function;
} catch (DOMException e) {
// ignore, try other candidates
}
}
}
return new ProblemBinding(astName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, astName.toCharArray());
}
private static ICPPFunctionTemplate asTemplate(IFunction function) {
if (function instanceof ICPPSpecialization) {
IBinding original= ((ICPPSpecialization) function).getSpecializedBinding();
@ -2229,7 +2255,7 @@ public class CPPSemantics {
while (type != null) {
type = getUltimateType(type, false);
if (type == null || !(type instanceof IFunctionType))
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name());
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getNameCharArray());
for (IBinding fn2 : fns) {
IFunction fn = (IFunction) fn2;
@ -2242,7 +2268,7 @@ public class CPPSemantics {
if (type.isSameType(ft)) {
if (result != null) {
return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP,
data.name());
data.getNameCharArray());
}
result = fn;
}
@ -2257,7 +2283,7 @@ public class CPPSemantics {
return result != null ?
result :
new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name());
new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.getNameCharArray());
}
private static Object getTargetType(LookupData data) {

View file

@ -31,7 +31,6 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IBasicType;
@ -49,7 +48,6 @@ import org.eclipse.cdt.core.dom.ast.IValue;
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.ICPPASTExplicitTemplateInstantiation;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
@ -85,7 +83,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
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.dom.parser.ASTInternal;
@ -1083,7 +1080,7 @@ public class CPPTemplates {
for (ICPPASTTemplateParameter par : pars) {
IASTName name= CPPTemplates.getTemplateParameterName(par);
if (name != null)
set.put(name.getSimpleID());
set.put(name.getLookupKey());
}
final IASTNode next= tdecl.getDeclaration();
if (next instanceof ICPPASTTemplateDeclaration) {
@ -1110,7 +1107,7 @@ public class CPPTemplates {
return PROCESS_CONTINUE;
}
if (names.containsKey(name.getSimpleID())) {
if (names.containsKey(name.getLookupKey())) {
IASTNode parent= name.getParent();
if (parent instanceof ICPPASTQualifiedName) {
if (((ICPPASTQualifiedName) parent).getNames()[0] != name) {
@ -1245,57 +1242,6 @@ public class CPPTemplates {
return null;
}
public static boolean isSameTemplate(ICPPTemplateDefinition definition, IASTName name) {
ICPPTemplateParameter[] defParams = null;
try {
defParams = definition.getTemplateParameters();
} catch (DOMException e1) {
return false;
}
ICPPASTTemplateDeclaration templateDecl = getTemplateDeclaration(name);
if (templateDecl == null)
return false;
ICPPASTTemplateParameter[] templateParams = templateDecl.getTemplateParameters();
if (defParams.length != templateParams.length)
return false;
IASTNode parent = name.getParent();
try {
if (parent instanceof ICPPASTFunctionDeclarator) {
IASTParameterDeclaration[] params = ((ICPPASTFunctionDeclarator) parent).getParameters();
IParameter[] ps = ((ICPPFunction) definition).getParameters();
if (ps.length == params.length) {
int i = 0;
for (; i < ps.length; i++) {
IType t1 = CPPVisitor.createType(params[i].getDeclarator());
IType t2 = ps[i].getType();
if (!t1.isSameType(t2))
return false;
}
return true;
}
return false;
}
if (parent instanceof IASTDeclSpecifier) {
if (name instanceof ICPPASTTemplateId) {
if (definition instanceof ICPPClassTemplatePartialSpecialization) {
ICPPClassTemplatePartialSpecialization spec = (ICPPClassTemplatePartialSpecialization) definition;
ICPPTemplateArgument[] args= createTemplateArgumentArray((ICPPASTTemplateId)name);
ICPPTemplateArgument[] specArgs = spec.getTemplateArguments();
if (!areSameArguments(args, specArgs))
return false;
}
return true;
}
return CharArrayUtils.equals(definition.getNameCharArray(), name.getSimpleID());
}
} catch (DOMException e) {
}
return false;
}
public static boolean areSameArguments(ICPPTemplateArgument[] args, ICPPTemplateArgument[] specArgs) {
if (args.length == specArgs.length) {
for (int i=0; i < args.length; i++) {

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* Andrew Niefer (IBM Corporation) - initial API and implementation
* Markus Schorn (Wind River Systems)
* Andrew Ferguson (Symbian)
* Sergey Prigogin (Google)
@ -148,7 +148,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPArrayType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassTemplate;
@ -184,7 +183,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
import org.eclipse.cdt.internal.core.index.IIndexScope;
/**
* @author aniefer
* Collection of methods to extract information from a c++ translation unit.
*/
public class CPPVisitor extends ASTQueries {
public static final char[] SIZE_T = "size_t".toCharArray(); //$NON-NLS-1$
@ -267,7 +266,7 @@ public class CPPVisitor extends ASTQueries {
return CPPTemplates.createBinding((ICPPASTTemplateParameter) parent);
}
if (name.getSimpleID().length > 0)
if (name.getLookupKey().length > 0)
return binding;
return null;
}
@ -444,7 +443,7 @@ public class CPPVisitor extends ASTQueries {
if (name instanceof ICPPASTTemplateId) {
return CPPTemplates.createBinding((ICPPASTTemplateId) name);
}
if (name.getSimpleID().length > 0 && scope != null) //can't lookup anonymous things
if (name.getLookupKey().length > 0 && scope != null) //can't lookup anonymous things
binding = scope.getBinding(name, false);
if (!(binding instanceof ICPPInternalBinding) || !(binding instanceof ICPPClassType)) {
if (template) {
@ -732,7 +731,7 @@ public class CPPVisitor extends ASTQueries {
return false;
IASTName name = findInnermostDeclarator(declarator).getName();
if (!CharArrayUtils.equals(CPPASTNameBase.getLookupKey(name), CPPASTNameBase.getLookupKey(parentName)))
if (!CharArrayUtils.equals(name.getLookupKey(), parentName.getLookupKey()))
return false;
IASTDeclSpecifier declSpec = null;
@ -1070,7 +1069,7 @@ public class CPPVisitor extends ASTQueries {
}
if (name != null) {
name= name.getLastName();
IBinding binding = CPPASTNameBase.getPreBinding(name);
IBinding binding = name.getPreBinding();
if (binding == null) {
binding = CPPSemantics.resolveBinding(name);
name.setBinding(binding);
@ -1690,7 +1689,7 @@ public class CPPVisitor extends ASTQueries {
}
}
if (name != null) {
IBinding binding = CPPASTNameBase.resolvePreBinding(name);
IBinding binding = name.resolvePreBinding();
if (binding instanceof ICPPConstructor) {
try {
type= ((ICPPConstructor) binding).getClassOwner();

View file

@ -61,6 +61,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ObjectSet;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit;
@ -115,10 +116,10 @@ class LookupData {
astName = null;
}
public final char[] name() {
public final char[] getNameCharArray() {
if (astName != null)
return astName.getSimpleID();
return CPPSemantics.EMPTY_NAME_ARRAY;
return astName.toCharArray();
return CharArrayUtils.EMPTY;
}
public boolean includeBlockItem(IASTNode item) {

View file

@ -40,9 +40,15 @@ class ASTPreprocessorName extends ASTPreprocessorNode implements IASTName {
public IBinding resolveBinding() {
return fBinding;
}
public IBinding resolvePreBinding() {
return fBinding;
}
public IBinding getBinding() {
return fBinding;
}
public IBinding getPreBinding() {
return fBinding;
}
public ILinkage getLinkage() {
final IASTTranslationUnit tu= getTranslationUnit();
return tu == null ? Linkage.NO_LINKAGE : tu.getLinkage();
@ -65,6 +71,9 @@ class ASTPreprocessorName extends ASTPreprocessorNode implements IASTName {
public char[] getSimpleID() {
return fName;
}
public char[] getLookupKey() {
return fName;
}
@Override
public String toString() {

View file

@ -38,7 +38,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase;
import org.eclipse.core.runtime.CoreException;
public class PDOMASTAdapter {
@ -87,6 +86,10 @@ public class PDOMASTAdapter {
return fDelegate.getBinding();
}
public IBinding getPreBinding() {
return fDelegate.getPreBinding();
}
public String getContainingFilename() {
return fLocation.getFileName();
}
@ -143,6 +146,10 @@ public class PDOMASTAdapter {
return fDelegate.resolveBinding();
}
public IBinding resolvePreBinding() {
return fDelegate.resolvePreBinding();
}
public IASTCompletionContext getCompletionContext() {
return fDelegate.getCompletionContext();
}
@ -166,6 +173,10 @@ public class PDOMASTAdapter {
public char[] getSimpleID() {
return fDelegate.getSimpleID();
}
public char[] getLookupKey() {
return fDelegate.getLookupKey();
}
public IASTImageLocation getImageLocation() {
return null;
@ -499,7 +510,7 @@ public class PDOMASTAdapter {
* it is returned unchanged.
*/
public static IASTName getAdapterIfAnonymous(IASTName name) {
if (CPPASTNameBase.getLookupKey(name).length == 0) {
if (name.getLookupKey().length == 0) {
if (name.getFileLocation() == null) {
IASTNode parent= name.getParent();
if (parent != null) {

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
* Doug Schaefer (QNX) - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Andrew Ferguson (Symbian)
* Bryan Wilkinson (QNX)
@ -47,8 +47,7 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.core.runtime.CoreException;
/**
* @author Doug Schaefer
*
* Represents the class scope for a class stored in the index.
*/
class PDOMCPPClassScope implements ICPPClassScope, IIndexScope {
private IPDOMCPPClassType fBinding;

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
* Doug Schaefer (QNX) - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Andrew Ferguson (Symbian)
* Bryan Wilkinson (QNX)
@ -43,7 +43,7 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException;
/**
* @author Doug Schaefer
* Represents a namespace scope for a namespace stored in the index.
*/
class PDOMCPPNamespace extends PDOMCPPBinding
implements ICPPNamespace, ICPPNamespaceScope, IIndexScope {
@ -129,7 +129,7 @@ class PDOMCPPNamespace extends PDOMCPPBinding
@Override
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) throws DOMException {
try {
IBinding[] bindings= getBindingsViaCache(name.getSimpleID());
IBinding[] bindings= getBindingsViaCache(name.getLookupKey());
if (fileSet != null) {
bindings= fileSet.filterFileLocalBindings(bindings);
}
@ -146,9 +146,9 @@ class PDOMCPPNamespace extends PDOMCPPBinding
IBinding[] result = null;
try {
if (!prefixLookup) {
return getBindingsViaCache(name.getSimpleID());
return getBindingsViaCache(name.getLookupKey());
}
BindingCollector visitor= new BindingCollector(getLinkageImpl(), name.getSimpleID(),
BindingCollector visitor= new BindingCollector(getLinkageImpl(), name.getLookupKey(),
IndexFilter.CPP_DECLARED_OR_IMPLICIT_NO_INSTANCE, prefixLookup, !prefixLookup);
getIndex().accept(visitor);
IBinding[] bindings = visitor.getBindings();