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

Code streamlining.

This commit is contained in:
Sergey Prigogin 2008-05-26 21:08:35 +00:00
parent d3477152cd
commit 79c2c87814
3 changed files with 33 additions and 41 deletions

View file

@ -74,18 +74,18 @@ public class CPPASTQualifiedName extends CPPASTNode implements
public void addName(IASTName name) { public void addName(IASTName name) {
if (name != null) { if (name != null) {
names = (IASTName[]) ArrayUtil.append( IASTName.class, names, ++namesPos, name ); names = (IASTName[]) ArrayUtil.append(IASTName.class, names, ++namesPos, name);
name.setParent(this); name.setParent(this);
name.setPropertyInParent(SEGMENT_NAME); name.setPropertyInParent(SEGMENT_NAME);
} }
} }
private void removeNullNames() { private void removeNullNames() {
names = (IASTName[]) ArrayUtil.removeNullsAfter( IASTName.class, names, namesPos ); names = (IASTName[]) ArrayUtil.removeNullsAfter(IASTName.class, names, namesPos);
} }
private IASTName[] names = null; private IASTName[] names = null;
private int namesPos=-1; private int namesPos= -1;
private boolean isFullyQualified; private boolean isFullyQualified;
private String signature; private String signature;
@ -145,7 +145,6 @@ public class CPPASTQualifiedName extends CPPASTNode implements
public void setSignature(String signature) { public void setSignature(String signature) {
this.signature = signature; this.signature = signature;
} }
@Override @Override
@ -188,7 +187,7 @@ public class CPPASTQualifiedName extends CPPASTNode implements
IASTNode parent = getParent(); IASTNode parent = getParent();
if (parent instanceof IASTNameOwner) { if (parent instanceof IASTNameOwner) {
int role = ((IASTNameOwner) parent).getRoleForName(this); int role = ((IASTNameOwner) parent).getRoleForName(this);
if( role == IASTNameOwner.r_reference ) return false; if (role == IASTNameOwner.r_reference) return false;
return true; return true;
} }
return false; return false;
@ -198,21 +197,21 @@ public class CPPASTQualifiedName extends CPPASTNode implements
IASTNode parent = getParent(); IASTNode parent = getParent();
if (parent instanceof IASTNameOwner) { if (parent instanceof IASTNameOwner) {
int role = ((IASTNameOwner) parent).getRoleForName(this); int role = ((IASTNameOwner) parent).getRoleForName(this);
if( role == IASTNameOwner.r_reference ) return true; if (role == IASTNameOwner.r_reference) return true;
return false; return false;
} }
return false; return false;
} }
public int getRoleForName(IASTName n) { public int getRoleForName(IASTName n) {
IASTName [] namez = getNames(); IASTName[] namez = getNames();
for( int i = 0; i < names.length; ++i ) for(int i = 0; i < names.length; ++i)
if( namez[i] == n ) if (namez[i] == n)
{ {
if( i < names.length - 1 ) if (i < names.length - 1)
return r_reference; return r_reference;
IASTNode p = getParent(); IASTNode p = getParent();
if( i == names.length - 1 && p instanceof IASTNameOwner ) if (i == names.length - 1 && p instanceof IASTNameOwner)
return ((IASTNameOwner)p).getRoleForName(this); return ((IASTNameOwner)p).getRoleForName(this);
return r_unclear; return r_unclear;
} }
@ -226,20 +225,20 @@ public class CPPASTQualifiedName extends CPPASTNode implements
public void setBinding(IBinding binding) { public void setBinding(IBinding binding) {
removeNullNames(); removeNullNames();
names[names.length - 1].setBinding( binding ); names[names.length - 1].setBinding(binding);
} }
public boolean isConversionOrOperator() { public boolean isConversionOrOperator() {
IASTName[] nonNullNames = getNames(); // ensure no null names IASTName[] nonNullNames = getNames(); // ensure no null names
int len=nonNullNames.length; int len=nonNullNames.length;
if (nonNullNames[len-1] instanceof ICPPASTConversionName || nonNullNames[len-1] instanceof ICPPASTOperatorName) { if (nonNullNames[len - 1] instanceof ICPPASTConversionName || nonNullNames[len - 1] instanceof ICPPASTOperatorName) {
return true; return true;
} }
// check templateId's name // check templateId's name
if (nonNullNames[len-1] instanceof ICPPASTTemplateId) { if (nonNullNames[len - 1] instanceof ICPPASTTemplateId) {
IASTName tempName = ((ICPPASTTemplateId)nonNullNames[len-1]).getTemplateName(); IASTName tempName = ((ICPPASTTemplateId)nonNullNames[len - 1]).getTemplateName();
if (tempName instanceof ICPPASTConversionName || tempName instanceof ICPPASTOperatorName) { if (tempName instanceof ICPPASTConversionName || tempName instanceof ICPPASTOperatorName) {
return true; return true;
} }
@ -252,7 +251,7 @@ public class CPPASTQualifiedName extends CPPASTNode implements
IASTNode parent = getParent(); IASTNode parent = getParent();
if (parent instanceof IASTNameOwner) { if (parent instanceof IASTNameOwner) {
int role = ((IASTNameOwner) parent).getRoleForName(this); int role = ((IASTNameOwner) parent).getRoleForName(this);
if( role == IASTNameOwner.r_definition ) return true; if (role == IASTNameOwner.r_definition) return true;
return false; return false;
} }
return false; return false;

View file

@ -10,6 +10,7 @@
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Bryan Wilkinson (QNX) * Bryan Wilkinson (QNX)
* Andrew Ferguson (Symbian) * Andrew Ferguson (Symbian)
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -78,8 +79,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
IASTName name = compTypeSpec.getName(); IASTName name = compTypeSpec.getName();
if (name instanceof ICPPASTQualifiedName) { if (name instanceof ICPPASTQualifiedName) {
IASTName[] ns = ((ICPPASTQualifiedName) name).getNames(); name = ((ICPPASTQualifiedName) name).getLastName();
name = ns[ns.length - 1];
} }
IBinding binding = name.resolveBinding(); IBinding binding = name.resolveBinding();
@ -142,8 +142,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
IASTName compName = compType.getName(); IASTName compName = compType.getName();
if (compName instanceof ICPPASTQualifiedName) { if (compName instanceof ICPPASTQualifiedName) {
IASTName[] ns = ((ICPPASTQualifiedName)compName).getNames(); compName = ((ICPPASTQualifiedName) compName).getLastName();
compName = ns[ns.length - 1];
} }
return CPPVisitor.getContainingScope(compName); return CPPVisitor.getContainingScope(compName);
} }
@ -162,14 +161,13 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
@Override @Override
public void addName(IASTName name) throws DOMException { public void addName(IASTName name) throws DOMException {
IASTNode parent = name.getParent();
if (name instanceof ICPPASTQualifiedName) { if (name instanceof ICPPASTQualifiedName) {
final IASTName[] qn= ((ICPPASTQualifiedName) name).getNames(); IASTName ln= ((ICPPASTQualifiedName) name).getLastName();
final IASTName ln= qn[qn.length-1];
if (CPPVisitor.getContainingScope(name) != CPPVisitor.getContainingScope(ln)) { if (CPPVisitor.getContainingScope(name) != CPPVisitor.getContainingScope(ln)) {
return; return;
} }
} }
IASTNode parent = name.getParent();
if (parent instanceof IASTDeclarator) { if (parent instanceof IASTDeclarator) {
if (CPPVisitor.isConstructor(this, (IASTDeclarator) parent)) { if (CPPVisitor.isConstructor(this, (IASTDeclarator) parent)) {
addConstructor(name); addConstructor(name);
@ -208,8 +206,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
IASTName compName = compType.getName(); IASTName compName = compType.getName();
if (compName instanceof ICPPASTQualifiedName) { if (compName instanceof ICPPASTQualifiedName) {
IASTName[] ns = ((ICPPASTQualifiedName)compName).getNames(); compName = ((ICPPASTQualifiedName) compName).getLastName();
compName = ns[ns.length - 1];
} }
if (CharArrayUtils.equals(c, compName.toCharArray())) { if (CharArrayUtils.equals(c, compName.toCharArray())) {
if (isConstructorReference(name)) { if (isConstructorReference(name)) {
@ -228,8 +225,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
IASTName compName = compType.getName(); IASTName compName = compType.getName();
if (compName instanceof ICPPASTQualifiedName) { if (compName instanceof ICPPASTQualifiedName) {
IASTName[] ns = ((ICPPASTQualifiedName)compName).getNames(); compName = ((ICPPASTQualifiedName) compName).getLastName();
compName = ns[ns.length - 1];
} }
IBinding[] result = null; IBinding[] result = null;
if ((!prefixLookup && CharArrayUtils.equals(c, compName.toCharArray())) if ((!prefixLookup && CharArrayUtils.equals(c, compName.toCharArray()))
@ -313,12 +309,11 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
IASTName compName = compType.getName(); IASTName compName = compType.getName();
if (compName instanceof ICPPASTQualifiedName) { if (compName instanceof ICPPASTQualifiedName) {
IASTName[] ns = ((ICPPASTQualifiedName)compName).getNames(); compName = ((ICPPASTQualifiedName) compName).getLastName();
compName = ns[ns.length - 1];
} }
if (CharArrayUtils.equals(compName.toCharArray(), n)) { if (CharArrayUtils.equals(compName.toCharArray(), n)) {
return new IBinding[] {getClassType()}; return new IBinding[] { getClassType() };
} }
return super.find(name); return super.find(name);
@ -330,8 +325,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
if (node instanceof ICPPASTTemplateId) if (node instanceof ICPPASTTemplateId)
node = node.getParent(); node = node.getParent();
if (node instanceof ICPPASTQualifiedName) { if (node instanceof ICPPASTQualifiedName) {
IASTName[] ns = ((ICPPASTQualifiedName)node).getNames(); if (((ICPPASTQualifiedName) node).getLastName() == name)
if (ns[ns.length - 1] == name)
node = node.getParent(); node = node.getParent();
else else
return false; return false;
@ -494,8 +488,7 @@ class ImplicitsAnalysis {
dcltor = ((IASTFunctionDefinition)member).getDeclarator(); dcltor = ((IASTFunctionDefinition)member).getDeclarator();
} }
if (!(dcltor instanceof ICPPASTFunctionDeclarator) || if (!(dcltor instanceof ICPPASTFunctionDeclarator) ||
!CharArrayUtils.equals(dcltor.getName().toCharArray(), OverloadableOperator.ASSIGN.toCharArray())) !CharArrayUtils.equals(dcltor.getName().toCharArray(), OverloadableOperator.ASSIGN.toCharArray())) {
{
continue; continue;
} }
@ -517,12 +510,12 @@ class ImplicitsAnalysis {
private static boolean paramHasTypeReferenceToTheAssociatedClassType(IASTParameterDeclaration dec, String name) { private static boolean paramHasTypeReferenceToTheAssociatedClassType(IASTParameterDeclaration dec, String name) {
boolean result= false; boolean result= false;
IASTDeclarator pdtor= dec.getDeclarator(); IASTDeclarator pdtor= dec.getDeclarator();
if (pdtor.getPointerOperators().length == 1 && pdtor.getPointerOperators()[0] instanceof ICPPASTReferenceOperator) { if (pdtor.getPointerOperators().length == 1 &&
if (dec.getDeclSpecifier() instanceof ICPPASTNamedTypeSpecifier) { pdtor.getPointerOperators()[0] instanceof ICPPASTReferenceOperator &&
ICPPASTNamedTypeSpecifier nts= (ICPPASTNamedTypeSpecifier) dec.getDeclSpecifier(); dec.getDeclSpecifier() instanceof ICPPASTNamedTypeSpecifier) {
if (name == null || name.equals(nts.getName().getRawSignature())) { ICPPASTNamedTypeSpecifier nts= (ICPPASTNamedTypeSpecifier) dec.getDeclSpecifier();
result= true; if (name == null || name.equals(nts.getName().getRawSignature())) {
} result= true;
} }
} }
return result; return result;

View file

@ -114,7 +114,7 @@ class LookupData {
astName = null; astName = null;
} }
public final char[] name () { public final char[] name() {
if (astName != null) if (astName != null)
return astName.toCharArray(); return astName.toCharArray();
return CPPSemantics.EMPTY_NAME_ARRAY; return CPPSemantics.EMPTY_NAME_ARRAY;