1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-26 10:25:32 +02:00

toString methods.

This commit is contained in:
Sergey Prigogin 2008-03-16 04:53:12 +00:00
parent c09235c6d1
commit ce309040bd
9 changed files with 1216 additions and 1149 deletions

View file

@ -74,15 +74,17 @@ public class CPPClassSpecializationScope implements ICPPClassScope, IASTInternal
public IBinding getBinding(IASTName name, boolean forceResolve, IIndexFileSet fileSet) throws DOMException {
char[] c = name.toCharArray();
if( CharArrayUtils.equals( c, specialization.getNameCharArray() ) )
if (!CPPClassScope.isConstructorReference( name ))
if (CharArrayUtils.equals(c, specialization.getNameCharArray()) &&
!CPPClassScope.isConstructorReference(name)) {
return specialization;
}
ICPPClassType specialized = (ICPPClassType) specialization.getSpecializedBinding();
IScope classScope = specialized.getCompositeScope();
IBinding[] bindings = classScope != null ? classScope.getBindings(name, forceResolve, false) : null;
if (bindings == null) return null;
if (bindings == null)
return null;
IBinding[] specs = new IBinding[0];
for (int i = 0; i < bindings.length; i++) {
@ -92,17 +94,20 @@ public class CPPClassSpecializationScope implements ICPPClassScope, IASTInternal
return CPPSemantics.resolveAmbiguities(name, specs);
}
public IBinding[] getBindings( IASTName name, boolean forceResolve, boolean prefixLookup, IIndexFileSet fileSet ) throws DOMException {
public IBinding[] getBindings(IASTName name, boolean forceResolve, boolean prefixLookup,
IIndexFileSet fileSet) throws DOMException {
char[] c = name.toCharArray();
IBinding[] result = null;
if( (!prefixLookup && CharArrayUtils.equals( c, specialization.getNameCharArray() ))
|| (prefixLookup && CharArrayUtils.equals(specialization.getNameCharArray(), 0, c.length, c, true)) )
if ((!prefixLookup && CharArrayUtils.equals(c, specialization.getNameCharArray())) ||
(prefixLookup && CharArrayUtils.equals(specialization.getNameCharArray(), 0, c.length, c, true))) {
result = new IBinding[] { specialization };
}
ICPPClassType specialized = (ICPPClassType) specialization.getSpecializedBinding();
IScope classScope = specialized.getCompositeScope();
IBinding[] bindings = classScope != null ? classScope.getBindings(name, forceResolve, prefixLookup, fileSet) : null;
IBinding[] bindings = classScope != null ?
classScope.getBindings(name, forceResolve, prefixLookup, fileSet) : null;
if (bindings != null) {
for (int i = 0; i < bindings.length; i++) {
@ -124,7 +129,7 @@ public class CPPClassSpecializationScope implements ICPPClassScope, IASTInternal
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope#getImplicitMethods()
*/
public ICPPMethod[] getImplicitMethods() {
//implicit methods shouldn't have implicit specializations
// Implicit methods shouldn't have implicit specializations
return ICPPMethod.EMPTY_CPPMETHOD_ARRAY;
}
@ -207,11 +212,17 @@ public class CPPClassSpecializationScope implements ICPPClassScope, IASTInternal
return true;
}
//this scope does not cache its own names
// This scope does not cache its own names
public void setFullyCached(boolean b) {}
public void flushCache() {}
public void addName(IASTName name) {}
public IASTNode getPhysicalNode() { return null; }
public void removeBinding(IBinding binding) {}
public void addBinding(IBinding binding) {}
@Override
public String toString() {
IName name = getScopeName();
return name != null ? name.toString() : "<unnamed scope>"; //$NON-NLS-1$
}
}

View file

@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
@ -51,7 +52,8 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP
IParameter[] params = function.getParameters();
specializedParams = new IParameter[params.length];
for (int i = 0; i < params.length; i++) {
specializedParams[i] = new CPPParameterSpecialization( (ICPPParameter)params[i], (ICPPScope) getScope(), argumentMap );
specializedParams[i] = new CPPParameterSpecialization((ICPPParameter)params[i],
(ICPPScope) getScope(), argumentMap);
}
}
return specializedParams;
@ -196,6 +198,7 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP
updateParameterBindings((ICPPASTFunctionDeclarator) n);
super.addDefinition(n);
}
@Override
public void addDeclaration(IASTNode node) {
IASTNode n = node;
@ -206,6 +209,7 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP
updateParameterBindings((ICPPASTFunctionDeclarator) n);
super.addDeclaration(n);
}
protected void updateParameterBindings(ICPPASTFunctionDeclarator fdtor) {
IParameter[] params = null;
try {
@ -227,4 +231,21 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP
}
}
}
@Override
public String toString() {
StringBuilder result = new StringBuilder();
result.append(getName());
IFunctionType t = null;
try {
t = getType();
} catch (DOMException e) {
}
result.append(t != null ? ASTTypeUtil.getParameterTypeString(t) : "()"); //$NON-NLS-1$
if (argumentMap != null) {
result.append(" ");
result.append(argumentMap.toString());
}
return result.toString();
}
}

View file

@ -51,6 +51,9 @@ import org.eclipse.core.runtime.NullProgressMonitor;
*/
abstract public class CPPScope implements ICPPScope, IASTInternalScope {
private static final IProgressMonitor NPM = new NullProgressMonitor();
private IASTNode physicalNode;
private boolean isfull = false;
protected CharArrayObjectMap bindings = null;
public static class CPPScopeProblem extends ProblemBinding implements ICPPScope {
public CPPScopeProblem(IASTNode node, int id, char[] arg) {
@ -58,7 +61,6 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
}
}
private IASTNode physicalNode;
public CPPScope(IASTNode physicalNode) {
this.physicalNode = physicalNode;
}
@ -74,16 +76,15 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
return physicalNode;
}
protected CharArrayObjectMap bindings = null;
public void addName(IASTName name) throws DOMException {
if (bindings == null)
bindings = new CharArrayObjectMap(1);
char[] c;
if (name instanceof ICPPASTQualifiedName) {
if (physicalNode instanceof ICPPASTCompositeTypeSpecifier == false &&
physicalNode instanceof ICPPASTNamespaceDefinition == false)
if (!(physicalNode instanceof ICPPASTCompositeTypeSpecifier) &&
!(physicalNode instanceof ICPPASTNamespaceDefinition)) {
return;
}
//name belongs to a different scope, don't add it here except it names this scope
final ICPPASTQualifiedName qname = (ICPPASTQualifiedName) name;
@ -91,8 +92,7 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
if (!canDenoteScopeMember(qname))
return;
c= ns[ns.length - 1].toCharArray();
}
else {
} else {
c= name.toCharArray();
}
Object o = bindings.get(c);
@ -141,19 +141,20 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
// Try looking this up in the PDOM
if (physicalNode instanceof IASTTranslationUnit) {
try {
IBinding[] bindings= index.findBindings(name.toCharArray(), IndexFilter.CPP_DECLARED_OR_IMPLICIT, NPM);
IBinding[] bindings= index.findBindings(name.toCharArray(),
IndexFilter.CPP_DECLARED_OR_IMPLICIT, NPM);
if (fileSet != null) {
bindings= fileSet.filterFileLocalBindings(bindings);
}
binding= CPPSemantics.resolveAmbiguities(name, bindings);
if (binding instanceof ICPPUsingDeclaration) {
binding= CPPSemantics.resolveAmbiguities( name, ((ICPPUsingDeclaration)binding).getDelegates() );
binding= CPPSemantics.resolveAmbiguities(name,
((ICPPUsingDeclaration)binding).getDelegates());
}
} catch (CoreException e) {
CCorePlugin.log(e);
}
}
else if (physicalNode instanceof ICPPASTNamespaceDefinition) {
} else if (physicalNode instanceof ICPPASTNamespaceDefinition) {
ICPPASTNamespaceDefinition nsdef = (ICPPASTNamespaceDefinition)physicalNode;
IASTName nsname = nsdef.getName();
IBinding nsbinding= nsname.resolveBinding();
@ -166,7 +167,8 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
}
binding= CPPSemantics.resolveAmbiguities(name, bindings);
if (binding instanceof ICPPUsingDeclaration) {
binding= CPPSemantics.resolveAmbiguities( name, ((ICPPUsingDeclaration)binding).getDelegates() );
binding= CPPSemantics.resolveAmbiguities(name,
((ICPPUsingDeclaration)binding).getDelegates());
}
}
}
@ -198,15 +200,16 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
n = ns[ns.length - 1];
}
bs = (IBinding[]) ArrayUtil.append(IBinding.class, bs, n.getBinding());
} else
} else {
bs = (IBinding[]) ArrayUtil.append(IBinding.class, bs, o);
}
}
return CPPSemantics.resolveAmbiguities(name, bs);
} else if (obj instanceof IASTName) {
IBinding binding = null;
if( forceResolve && obj != name && obj != name.getParent())
if (forceResolve && obj != name && obj != name.getParent()) {
binding = CPPSemantics.resolveAmbiguities(name, new Object[] { obj });
else {
} else {
IASTName n = (IASTName) obj;
if (n instanceof ICPPASTQualifiedName) {
IASTName[] ns = ((ICPPASTQualifiedName)n).getNames();
@ -224,7 +227,8 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
return null;
}
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) throws DOMException {
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet)
throws DOMException {
IBinding[] result = getBindingsInAST(name, resolve, prefixLookup);
final IASTTranslationUnit tu = name.getTranslationUnit();
@ -264,7 +268,8 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
}
public IBinding[] getBindingsInAST(IASTName name, boolean forceResolve, boolean prefixLookup) throws DOMException {
public IBinding[] getBindingsInAST(IASTName name, boolean forceResolve, boolean prefixLookup)
throws DOMException {
char[] c = name.toCharArray();
IBinding[] result = null;
@ -295,14 +300,15 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
}
IBinding binding = forceResolve ? n.resolveBinding() : n.getBinding();
result = (IBinding[]) ArrayUtil.append(IBinding.class, result, binding);
} else
} else {
result = (IBinding[]) ArrayUtil.append(IBinding.class, result, o);
}
}
} else if (obj[i] instanceof IASTName) {
IBinding binding = null;
if( forceResolve && obj[i] != name && obj[i] != name.getParent())
if (forceResolve && obj[i] != name && obj[i] != name.getParent()) {
binding = ((IASTName) obj[i]).resolveBinding();
else {
} else {
IASTName n = (IASTName) obj[i];
if (n instanceof ICPPASTQualifiedName) {
IASTName[] ns = ((ICPPASTQualifiedName)n).getNames();
@ -311,7 +317,8 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
binding = n.getBinding();
}
if (binding instanceof ICPPUsingDeclaration) {
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, ((ICPPUsingDeclaration)binding).getDelegates());
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result,
((ICPPUsingDeclaration)binding).getDelegates());
}
result = (IBinding[]) ArrayUtil.append(IBinding.class, result, binding);
} else {
@ -321,7 +328,6 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
}
private boolean isfull = false;
public void setFullyCached(boolean full) {
isfull = full;
}
@ -348,16 +354,15 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
for (int i = set.size() - 1; i > 0; i--) {
Object o = set.keyAt(i);
if ((o instanceof IBinding && o == binding) ||
(o instanceof IASTName && ((IASTName)o).getBinding() == binding) )
{
(o instanceof IASTName && ((IASTName)o).getBinding() == binding)) {
set.remove(o);
}
}
if( set.size() == 0 )
if (set.isEmpty()) {
bindings.remove(key, 0, key.length);
}
} else if ((obj instanceof IBinding && obj == binding) ||
(obj instanceof IASTName && ((IASTName)obj).getBinding() == binding) )
{
(obj instanceof IASTName && ((IASTName)obj).getBinding() == binding)) {
bindings.remove(key, 0, key.length);
}
isfull = false;
@ -402,4 +407,18 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefix) throws DOMException {
return getBindings(name, resolve, prefix, IIndexFileSet.EMPTY);
}
public IName getScopeName() throws DOMException {
return null;
}
@Override
public String toString() {
IName name = null;
try {
name = getScopeName();
} catch (DOMException e) {
}
return name != null ? name.toString() : "<unnamed scope>"; //$NON-NLS-1$
}
}

View file

@ -125,4 +125,14 @@ public abstract class CPPSpecialization extends PlatformObject
public ObjectMap getArgumentMap() {
return argumentMap;
}
@Override
public String toString() {
StringBuilder result = new StringBuilder(getName());
if (argumentMap != null) {
result.append(" ");
result.append(argumentMap.toString());
}
return result.toString();
}
}

View file

@ -72,12 +72,13 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC
throw new DOMException(this);
}
}
//private IASTName templateName;
protected IASTName [] declarations = null;
protected IASTName definition = null;
private ICPPTemplateParameter [] templateParameters = null;
private ObjectMap instances = null;
//private IASTName templateName;
protected IASTName[] declarations;
protected IASTName definition;
private ICPPTemplateParameter[] templateParameters;
private ObjectMap instances;
public CPPTemplateDefinition(IASTName name) {
if (name != null) {
@ -93,13 +94,14 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC
IASTNode parent = name.getParent();
while (!(parent instanceof IASTDeclaration))
parent = parent.getParent();
if( parent instanceof IASTFunctionDefinition )
if (parent instanceof IASTFunctionDefinition) {
definition = name;
else
} else {
declarations = new IASTName[] { name };
}
}
}
}
public abstract ICPPSpecialization deferredInstance(IType[] arguments);
@ -119,8 +121,9 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC
}
}
if( template instanceof IProblemBinding )
if (template instanceof IProblemBinding) {
return template;
}
if (template != null && template instanceof ICPPClassTemplatePartialSpecialization) {
return ((ICPPInternalTemplateInstantiator)template).instantiate(arguments);
}
@ -156,9 +159,10 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC
public void addSpecialization(IType[] types, ICPPSpecialization spec) {
if (types == null)
return;
for( int i = 0; i < types.length; i++ )
for (int i = 0; i < types.length; i++) {
if (types[i] == null)
return;
}
if (instances == null)
instances = new ObjectMap(2);
instances.put(types, spec);
@ -195,12 +199,13 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC
}
}
//create a new binding and set it for the corresponding parameter in all known decls
if( templateParameter instanceof ICPPASTSimpleTypeTemplateParameter )
if (templateParameter instanceof ICPPASTSimpleTypeTemplateParameter) {
binding = new CPPTemplateTypeParameter(name);
else if( templateParameter instanceof ICPPASTParameterDeclaration )
} else if (templateParameter instanceof ICPPASTParameterDeclaration) {
binding = new CPPTemplateNonTypeParameter(name);
else
} else {
binding = new CPPTemplateTemplateParameter(name);
}
int length = (declarations != null) ? declarations.length : 0;
int j = (definition != null) ? -1 : 0;
@ -229,6 +234,7 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC
public IASTName getTemplateName() {
return definition != null ? definition : declarations[0];
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
*/
@ -332,9 +338,9 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC
return;
IASTName declName = (IASTName) node;
updateTemplateParameterBindings(declName);
if( declarations == null )
if (declarations == null) {
declarations = new IASTName[] { declName };
else {
} else {
// keep the lowest offset declaration in[0]
if (declarations.length > 0 && ((ASTNode) node).getOffset() < ((ASTNode) declarations[0]).getOffset()) {
declarations = (IASTName[]) ArrayUtil.prepend(IASTName.class, declarations, declName);

View file

@ -73,7 +73,8 @@ public class CPPTemplateScope extends CPPScope implements ICPPTemplateScope {
IASTName[] names = qual.getNames();
int i = 0;
for (; i < names.length; i++) {
if( names[i] == name ) break;
if (names[i] == name)
break;
}
if (i > 0) {
try {
@ -87,14 +88,16 @@ public class CPPTemplateScope extends CPPScope implements ICPPTemplateScope {
} else if (binding instanceof IProblemBinding) {
if (binding instanceof ICPPScope)
return (IScope) binding;
return new CPPScope.CPPScopeProblem( names[i-1], IProblemBinding.SEMANTIC_BAD_SCOPE, names[i-1].toCharArray() );
return new CPPScope.CPPScopeProblem(names[i - 1], IProblemBinding.SEMANTIC_BAD_SCOPE,
names[i - 1].toCharArray());
}
} catch (DOMException e) {
IScope result = e.getProblem();
if (result instanceof ICPPScope) {
return result;
}
return new CPPScope.CPPScopeProblem( names[i-1], IProblemBinding.SEMANTIC_BAD_SCOPE, names[i-1].toCharArray() );
return new CPPScope.CPPScopeProblem(names[i - 1], IProblemBinding.SEMANTIC_BAD_SCOPE,
names[i - 1].toCharArray());
}
} else if (qual.isFullyQualified()) {
return qual.getTranslationUnit().getScope();

View file

@ -21,23 +21,22 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
/**
* @author aniefer
*/
public class CPPTypedefSpecialization extends CPPSpecialization implements
ITypedef, ITypeContainer {
public class CPPTypedefSpecialization extends CPPSpecialization implements ITypedef, ITypeContainer {
private IType type = null;
/**
* @param specialized
* @param scope
* @param argumentMap
*/
public CPPTypedefSpecialization( IBinding specialized, ICPPScope scope,
ObjectMap argumentMap ) {
public CPPTypedefSpecialization(IBinding specialized, ICPPScope scope, ObjectMap argumentMap) {
super(specialized, scope, argumentMap);
}
private ITypedef getTypedef() {
return (ITypedef) getSpecializedBinding();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.ITypedef#getType()
*/
@ -68,7 +67,7 @@ public class CPPTypedefSpecialization extends CPPSpecialization implements
public boolean isSameType(IType o) {
if (o == this)
return true;
if( o instanceof ITypedef )
if (o instanceof ITypedef) {
try {
IType t = getType();
if (t != null)
@ -77,6 +76,7 @@ public class CPPTypedefSpecialization extends CPPSpecialization implements
} catch (DOMException e) {
return false;
}
}
try {
IType t = getType();
@ -91,5 +91,4 @@ public class CPPTypedefSpecialization extends CPPSpecialization implements
public void setType(IType type) {
this.type = type;
}
}

View file

@ -161,12 +161,10 @@ public class CPPVisitor {
parent instanceof ICPPASTBaseSpecifier ||
parent instanceof ICPPASTConstructorChainInitializer ||
name.getPropertyInParent() == ICPPASTNamespaceAlias.MAPPING_NAME ||
parent instanceof ICPPASTTemplateId )
{
parent instanceof ICPPASTTemplateId) {
binding = CPPSemantics.resolveBinding(name);
if( binding instanceof IProblemBinding && parent instanceof ICPPASTQualifiedName
&& !(parent.getParent() instanceof ICPPASTNamespaceAlias))
{
if (binding instanceof IProblemBinding && parent instanceof ICPPASTQualifiedName &&
!(parent.getParent() instanceof ICPPASTNamespaceAlias)) {
final ICPPASTQualifiedName qname = (ICPPASTQualifiedName)parent;
final IASTName[] ns = qname.getNames();
if (ns[ns.length - 1] != name)
@ -176,8 +174,10 @@ public class CPPVisitor {
if (((IProblemBinding)binding).getID() == IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND) {
IASTNode node = getContainingBlockItem(name.getParent());
ASTNodeProperty prop= node.getPropertyInParent();
if (prop != IASTCompositeTypeSpecifier.MEMBER_DECLARATION && prop != ICPPASTNamespaceDefinition.OWNED_DECLARATION)
if (prop != IASTCompositeTypeSpecifier.MEMBER_DECLARATION &&
prop != ICPPASTNamespaceDefinition.OWNED_DECLARATION) {
return binding;
}
if (getContainingScope(qname) != getContainingScope(name))
return binding;
@ -308,14 +308,13 @@ public class CPPVisitor {
}
} else if (parent instanceof IASTParameterDeclaration ||
parent instanceof IASTDeclaration ||
parent instanceof IASTTypeId )
{
parent instanceof IASTTypeId) {
binding = CPPSemantics.resolveBinding(elabType.getName());
}
if (binding != null &&
(!(binding instanceof IProblemBinding) ||((IProblemBinding)binding).getID() != IProblemBinding.SEMANTIC_NAME_NOT_FOUND) )
{
(!(binding instanceof IProblemBinding) ||
((IProblemBinding)binding).getID() != IProblemBinding.SEMANTIC_NAME_NOT_FOUND)) {
return binding;
}
@ -374,6 +373,7 @@ public class CPPVisitor {
return binding;
}
private static IBinding createBinding(ICPPASTCompositeTypeSpecifier compType) {
IASTName name = compType.getName();
if (name instanceof ICPPASTQualifiedName) {
@ -399,18 +399,22 @@ public class CPPVisitor {
if (name.toCharArray().length > 0 && scope != null) //can't lookup anonymous things
binding = scope.getBinding(name, false);
if (!(binding instanceof ICPPInternalBinding) || !(binding instanceof ICPPClassType)) {
if( template )
if (template) {
binding = new CPPClassTemplate(name);
else
} else {
binding = new CPPClassType(name, binding);
if( scope != null )
}
if (scope != null) {
ASTInternal.addName(scope, compType.getName());
}
} else {
ICPPInternalBinding internal = (ICPPInternalBinding) binding;
if( internal.getDefinition() == null )
if (internal.getDefinition() == null) {
internal.addDefinition(compType);
else
binding = new ProblemBinding( name, IProblemBinding.SEMANTIC_INVALID_REDEFINITION, name.toCharArray() );
} else {
binding = new ProblemBinding(name,
IProblemBinding.SEMANTIC_INVALID_REDEFINITION, name.toCharArray());
}
}
} catch (DOMException e) {
binding = e.getProblem();
@ -445,13 +449,15 @@ public class CPPVisitor {
IBinding namespace = alias.getMappingName().resolveBinding();
if (namespace instanceof IProblemBinding) {
IProblemBinding problem = (IProblemBinding) namespace;
namespace = new CPPNamespace.CPPNamespaceProblem( problem.getASTNode(), problem.getID(), alias.getMappingName().toCharArray());
namespace = new CPPNamespace.CPPNamespaceProblem(problem.getASTNode(),
problem.getID(), alias.getMappingName().toCharArray());
}
if (namespace instanceof ICPPNamespace) {
binding = new CPPNamespaceAlias(alias.getAlias(), (ICPPNamespace) namespace);
ASTInternal.addName(scope, alias.getAlias());
} else {
binding = new ProblemBinding( alias.getAlias(), IProblemBinding.SEMANTIC_NAME_NOT_FOUND, alias.getAlias().toCharArray() );
binding = new ProblemBinding(alias.getAlias(),
IProblemBinding.SEMANTIC_NAME_NOT_FOUND, alias.getAlias().toCharArray());
}
}
} catch(DOMException e) {
@ -461,7 +467,6 @@ public class CPPVisitor {
return binding;
}
return null;
}
private static IBinding createBinding(IASTDeclarator declarator) {
@ -495,14 +500,14 @@ public class CPPVisitor {
}
ASTNodeProperty prop = parent.getPropertyInParent();
if( parent instanceof IASTTypeId )
if (parent instanceof IASTTypeId) {
return CPPSemantics.resolveBinding(name);
else if( prop == ICPPASTTemplateSpecialization.OWNED_DECLARATION ||
prop == ICPPASTExplicitTemplateInstantiation.OWNED_DECLARATION )
{
} else if (prop == ICPPASTTemplateSpecialization.OWNED_DECLARATION ||
prop == ICPPASTExplicitTemplateInstantiation.OWNED_DECLARATION) {
return CPPTemplates.createFunctionSpecialization(name);
} else if( prop == ICPPASTTemplateDeclaration.PARAMETER )
} else if (prop == ICPPASTTemplateDeclaration.PARAMETER) {
return CPPTemplates.createBinding((ICPPASTTemplateParameter) parent);
}
boolean template = false;
ICPPScope scope = (ICPPScope) getContainingScope((IASTNode) name);
@ -532,7 +537,8 @@ public class CPPVisitor {
binding = null;
}
IASTSimpleDeclaration simpleDecl = ( parent instanceof IASTSimpleDeclaration ) ? (IASTSimpleDeclaration)parent : null;
IASTSimpleDeclaration simpleDecl = (parent instanceof IASTSimpleDeclaration) ?
(IASTSimpleDeclaration)parent : null;
if (parent instanceof ICPPASTParameterDeclaration) {
ICPPASTParameterDeclaration param = (ICPPASTParameterDeclaration) parent;
parent = param.getParent();
@ -552,7 +558,8 @@ public class CPPVisitor {
} else if (parent instanceof ICPPASTTemplateDeclaration) {
return CPPTemplates.createBinding(param);
}
} else if( simpleDecl != null && simpleDecl.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef ){
} else if (simpleDecl != null &&
simpleDecl.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef) {
if (binding instanceof ICPPInternalBinding && binding instanceof ITypedef) {
try {
IType t1 = ((ITypedef)binding).getType();
@ -573,19 +580,18 @@ public class CPPVisitor {
IFunction function = (IFunction) binding;
if (CPPSemantics.isSameFunction(function, funcDeclarator)) {
ICPPInternalBinding internal = (ICPPInternalBinding) function;
if( parent instanceof IASTSimpleDeclaration )
if (parent instanceof IASTSimpleDeclaration) {
internal.addDeclaration(name);
else {
if( internal.getDefinition() == null )
} else if (internal.getDefinition() == null) {
internal.addDefinition(name);
else {
} else {
IASTNode def = internal.getDefinition();
if (def instanceof IASTDeclarator)
def = ((IASTDeclarator)def).getName();
if( def != name )
return new ProblemBinding( name, IProblemBinding.SEMANTIC_INVALID_REDEFINITION, name.toCharArray() );
if (def != name) {
return new ProblemBinding(name,
IProblemBinding.SEMANTIC_INVALID_REDEFINITION, name.toCharArray());
}
}
return function;
@ -606,12 +612,13 @@ public class CPPVisitor {
}
if (scope instanceof ICPPClassScope) {
if( isConstructor( scope, funcDeclarator) )
if (isConstructor(scope, funcDeclarator)) {
binding = template ? (ICPPConstructor) new CPPConstructorTemplate(name)
: new CPPConstructor((ICPPASTFunctionDeclarator) funcDeclarator);
else
} else {
binding = template ? (ICPPMethod) new CPPMethodTemplate(name)
: new CPPMethod((ICPPASTFunctionDeclarator) funcDeclarator);
}
} else {
binding = template ? (ICPPFunction) new CPPFunctionTemplate(name)
: new CPPFunction((ICPPASTFunctionDeclarator) funcDeclarator);
@ -820,13 +827,15 @@ public class CPPVisitor {
}
node = node.getParent();
}
return new CPPScope.CPPScopeProblem( inputNode, IProblemBinding.SEMANTIC_BAD_SCOPE, inputNode.getRawSignature().toCharArray() );
return new CPPScope.CPPScopeProblem(inputNode, IProblemBinding.SEMANTIC_BAD_SCOPE,
inputNode.getRawSignature().toCharArray());
}
public static IScope getContainingScope(IASTName name) {
IScope scope= getContainingScopeOrNull(name);
if (scope == null) {
return new CPPScope.CPPScopeProblem( name, IProblemBinding.SEMANTIC_BAD_SCOPE, name.toCharArray() );
return new CPPScope.CPPScopeProblem(name, IProblemBinding.SEMANTIC_BAD_SCOPE,
name.toCharArray());
}
return scope;
@ -868,13 +877,13 @@ public class CPPVisitor {
} else if (binding instanceof IProblemBinding) {
if (binding instanceof ICPPScope)
scope= (IScope) binding;
}
else {
} else {
done= false;
}
if (done) {
if (scope == null) {
return new CPPScope.CPPScopeProblem( names[i-1], IProblemBinding.SEMANTIC_BAD_SCOPE, names[i-1].toCharArray() );
return new CPPScope.CPPScopeProblem(names[i - 1],
IProblemBinding.SEMANTIC_BAD_SCOPE, names[i-1].toCharArray());
}
return scope;
}
@ -942,8 +951,6 @@ public class CPPVisitor {
return getContainingScope(name);
}
if (scope == null)
return getContainingScope(parent);
return scope;
@ -995,9 +1002,10 @@ public class CPPVisitor {
node = ((IASTUnaryExpression)node).getOperand();
} else if (node instanceof IASTBinaryExpression) {
node = ((IASTBinaryExpression)node).getOperand2();
} else
} else {
node = null;
}
}
if (name != null) {
if (name instanceof ICPPASTQualifiedName) {
IASTName ns[] = ((ICPPASTQualifiedName)name).getNames();
@ -1039,8 +1047,7 @@ public class CPPVisitor {
}
private void addProblem(IASTProblem problem) {
if( problems.length == numFound ) // if the found array is full, then double the array
{
if (problems.length == numFound) { // if the found array is full, then double the array
IASTProblem[] old = problems;
problems = new IASTProblem[old.length * 2];
for (int j = 0; j < old.length; ++j)
@ -1134,23 +1141,20 @@ public class CPPVisitor {
if (binding instanceof ICPPUsingDeclaration) {
this.bindings= ((ICPPUsingDeclaration) binding).getDelegates();
kind= KIND_COMPOSITE;
}
else if( binding instanceof ILabel )
} else if (binding instanceof ILabel) {
kind = KIND_LABEL;
else if( binding instanceof ICPPTemplateParameter )
} else if (binding instanceof ICPPTemplateParameter) {
kind = KIND_TEMPLATE_PARAMETER;
else if( binding instanceof ICompositeType ||
} else if (binding instanceof ICompositeType ||
binding instanceof ITypedef ||
binding instanceof IEnumeration)
{
binding instanceof IEnumeration) {
kind = KIND_TYPE;
}
else if( binding instanceof ICPPNamespace) {
} else if (binding instanceof ICPPNamespace) {
kind = KIND_NAMESPACE;
}
else
} else {
kind = KIND_OBJ_FN;
}
}
@Override
public int visit(IASTName name) {
@ -1163,8 +1167,7 @@ public class CPPVisitor {
switch(kind) {
case KIND_TEMPLATE_PARAMETER:
if (prop == ICPPASTSimpleTypeTemplateParameter.PARAMETER_NAME ||
prop == ICPPASTTemplatedTypeTemplateParameter.PARAMETER_NAME )
{
prop == ICPPASTTemplatedTypeTemplateParameter.PARAMETER_NAME) {
break;
} else if (prop == IASTDeclarator.DECLARATOR_NAME) {
IASTNode d = name.getParent();
@ -1175,16 +1178,17 @@ public class CPPVisitor {
}
}
return PROCESS_CONTINUE;
case KIND_LABEL:
if (prop == IASTLabelStatement.NAME)
break;
return PROCESS_CONTINUE;
case KIND_TYPE:
case KIND_COMPOSITE:
if (prop == IASTCompositeTypeSpecifier.TYPE_NAME ||
prop == IASTEnumerationSpecifier.ENUMERATION_NAME ||
prop == ICPPASTUsingDeclaration.NAME )
{
prop == ICPPASTUsingDeclaration.NAME) {
break;
} else if (prop == IASTElaboratedTypeSpecifier.TYPE_NAME) {
IASTNode p = name.getParent().getParent();
@ -1207,18 +1211,18 @@ public class CPPVisitor {
if (kind == KIND_TYPE)
return PROCESS_CONTINUE;
case KIND_OBJ_FN:
if (prop == IASTDeclarator.DECLARATOR_NAME ||
prop == IASTEnumerationSpecifier.IASTEnumerator.ENUMERATOR_NAME ||
prop == ICPPASTUsingDeclaration.NAME )
{
prop == ICPPASTUsingDeclaration.NAME) {
break;
}
return PROCESS_CONTINUE;
case KIND_NAMESPACE:
if (prop == ICPPASTNamespaceDefinition.NAMESPACE_NAME ||
prop == ICPPASTNamespaceAlias.ALIAS_NAME )
{
prop == ICPPASTNamespaceAlias.ALIAS_NAME) {
break;
}
return PROCESS_CONTINUE;
@ -1318,7 +1322,8 @@ public class CPPVisitor {
@Override
public int visit(IASTName name) {
if( name instanceof ICPPASTQualifiedName || name instanceof ICPPASTTemplateId ) return PROCESS_CONTINUE;
if (name instanceof ICPPASTQualifiedName || name instanceof ICPPASTTemplateId)
return PROCESS_CONTINUE;
ASTNodeProperty prop = name.getPropertyInParent();
ASTNodeProperty p2 = null;
@ -1340,12 +1345,9 @@ public class CPPVisitor {
prop == ICPPASTUsingDeclaration.NAME ||
prop == ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier.NAME ||
prop == ICPPASTTemplateId.TEMPLATE_NAME ||
p2 == ICPPASTQualifiedName.SEGMENT_NAME )
{
p2 == ICPPASTQualifiedName.SEGMENT_NAME) {
break;
}
else if( prop == IASTElaboratedTypeSpecifier.TYPE_NAME )
{
} else if (prop == IASTElaboratedTypeSpecifier.TYPE_NAME) {
IASTNode p = name.getParent().getParent();
if (!(p instanceof IASTSimpleDeclaration) ||
((IASTSimpleDeclaration)p).getDeclarators().length > 0)
@ -1364,8 +1366,7 @@ public class CPPVisitor {
prop == ICPPASTUsingDeclaration.NAME ||
prop == IASTNamedTypeSpecifier.NAME ||
prop == ICPPASTConstructorChainInitializer.MEMBER_ID ||
prop == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT )
{
prop == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) {
break;
}
return PROCESS_CONTINUE;
@ -1373,8 +1374,7 @@ public class CPPVisitor {
if (prop == ICPPASTUsingDirective.QUALIFIED_NAME ||
prop == ICPPASTNamespaceAlias.MAPPING_NAME ||
prop == ICPPASTUsingDeclaration.NAME ||
p2 == ICPPASTQualifiedName.SEGMENT_NAME )
{
p2 == ICPPASTQualifiedName.SEGMENT_NAME) {
break;
}
return PROCESS_CONTINUE;
@ -1778,7 +1778,8 @@ public class CPPVisitor {
} catch (DOMException e) {
return e.getProblem();
}
return new ProblemBinding(expression, IProblemBinding.SEMANTIC_BAD_SCOPE, binding.getName().toCharArray());
return new ProblemBinding(expression, IProblemBinding.SEMANTIC_BAD_SCOPE,
binding.getName().toCharArray());
} else if (binding instanceof IFunction) {
IFunctionType fType;
try {
@ -1862,9 +1863,7 @@ public class CPPVisitor {
((CPPBasicType)result).setValue(expression);
}
return result;
}
else if( expression instanceof IASTUnaryExpression )
{
} else if (expression instanceof IASTUnaryExpression) {
int op = ((IASTUnaryExpression)expression).getOperator();
if (op == IASTUnaryExpression.op_sizeof) {
IScope scope = getContainingScope(expression);

View file

@ -44,8 +44,7 @@ public class TemplateInstanceUtil {
if(specd instanceof ICPPTemplateDefinition) {
keysToAdapt= ((ICPPTemplateDefinition)specd).getTemplateParameters();
}
final int length= Math.min(keys.length, keysToAdapt.length);
for(int i=0; i<length; i++) {
for(int i = 0; i < keys.length && i < keysToAdapt.length; i++) {
IType type= (IType) preresult.get(keys[i]);
result.put(
cf.getCompositeBinding((IIndexFragmentBinding)keysToAdapt[i]),