mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Code streamlining.
This commit is contained in:
parent
d3477152cd
commit
79c2c87814
3 changed files with 33 additions and 41 deletions
|
@ -74,18 +74,18 @@ public class CPPASTQualifiedName extends CPPASTNode implements
|
|||
|
||||
public void addName(IASTName name) {
|
||||
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.setPropertyInParent(SEGMENT_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
private void removeNullNames() {
|
||||
names = (IASTName[]) ArrayUtil.removeNullsAfter( IASTName.class, names, namesPos );
|
||||
names = (IASTName[]) ArrayUtil.removeNullsAfter(IASTName.class, names, namesPos);
|
||||
}
|
||||
|
||||
private IASTName[] names = null;
|
||||
private int namesPos=-1;
|
||||
private int namesPos= -1;
|
||||
private boolean isFullyQualified;
|
||||
private String signature;
|
||||
|
||||
|
@ -145,7 +145,6 @@ public class CPPASTQualifiedName extends CPPASTNode implements
|
|||
|
||||
public void setSignature(String signature) {
|
||||
this.signature = signature;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -188,7 +187,7 @@ public class CPPASTQualifiedName extends CPPASTNode implements
|
|||
IASTNode parent = getParent();
|
||||
if (parent instanceof IASTNameOwner) {
|
||||
int role = ((IASTNameOwner) parent).getRoleForName(this);
|
||||
if( role == IASTNameOwner.r_reference ) return false;
|
||||
if (role == IASTNameOwner.r_reference) return false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -198,21 +197,21 @@ public class CPPASTQualifiedName extends CPPASTNode implements
|
|||
IASTNode parent = getParent();
|
||||
if (parent instanceof IASTNameOwner) {
|
||||
int role = ((IASTNameOwner) parent).getRoleForName(this);
|
||||
if( role == IASTNameOwner.r_reference ) return true;
|
||||
if (role == IASTNameOwner.r_reference) return true;
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getRoleForName(IASTName n) {
|
||||
IASTName [] namez = getNames();
|
||||
for( int i = 0; i < names.length; ++i )
|
||||
if( namez[i] == n )
|
||||
IASTName[] namez = getNames();
|
||||
for(int i = 0; i < names.length; ++i)
|
||||
if (namez[i] == n)
|
||||
{
|
||||
if( i < names.length - 1 )
|
||||
if (i < names.length - 1)
|
||||
return r_reference;
|
||||
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 r_unclear;
|
||||
}
|
||||
|
@ -226,20 +225,20 @@ public class CPPASTQualifiedName extends CPPASTNode implements
|
|||
|
||||
public void setBinding(IBinding binding) {
|
||||
removeNullNames();
|
||||
names[names.length - 1].setBinding( binding );
|
||||
names[names.length - 1].setBinding(binding);
|
||||
}
|
||||
|
||||
public boolean isConversionOrOperator() {
|
||||
IASTName[] nonNullNames = getNames(); // ensure no null names
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// check templateId's name
|
||||
if (nonNullNames[len-1] instanceof ICPPASTTemplateId) {
|
||||
IASTName tempName = ((ICPPASTTemplateId)nonNullNames[len-1]).getTemplateName();
|
||||
if (nonNullNames[len - 1] instanceof ICPPASTTemplateId) {
|
||||
IASTName tempName = ((ICPPASTTemplateId)nonNullNames[len - 1]).getTemplateName();
|
||||
if (tempName instanceof ICPPASTConversionName || tempName instanceof ICPPASTOperatorName) {
|
||||
return true;
|
||||
}
|
||||
|
@ -252,7 +251,7 @@ public class CPPASTQualifiedName extends CPPASTNode implements
|
|||
IASTNode parent = getParent();
|
||||
if (parent instanceof IASTNameOwner) {
|
||||
int role = ((IASTNameOwner) parent).getRoleForName(this);
|
||||
if( role == IASTNameOwner.r_definition ) return true;
|
||||
if (role == IASTNameOwner.r_definition) return true;
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
* Markus Schorn (Wind River Systems)
|
||||
* Bryan Wilkinson (QNX)
|
||||
* Andrew Ferguson (Symbian)
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
|
@ -78,8 +79,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
|||
|
||||
IASTName name = compTypeSpec.getName();
|
||||
if (name instanceof ICPPASTQualifiedName) {
|
||||
IASTName[] ns = ((ICPPASTQualifiedName) name).getNames();
|
||||
name = ns[ns.length - 1];
|
||||
name = ((ICPPASTQualifiedName) name).getLastName();
|
||||
}
|
||||
|
||||
IBinding binding = name.resolveBinding();
|
||||
|
@ -142,8 +142,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
|||
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
|
||||
IASTName compName = compType.getName();
|
||||
if (compName instanceof ICPPASTQualifiedName) {
|
||||
IASTName[] ns = ((ICPPASTQualifiedName)compName).getNames();
|
||||
compName = ns[ns.length - 1];
|
||||
compName = ((ICPPASTQualifiedName) compName).getLastName();
|
||||
}
|
||||
return CPPVisitor.getContainingScope(compName);
|
||||
}
|
||||
|
@ -162,14 +161,13 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
|||
|
||||
@Override
|
||||
public void addName(IASTName name) throws DOMException {
|
||||
IASTNode parent = name.getParent();
|
||||
if (name instanceof ICPPASTQualifiedName) {
|
||||
final IASTName[] qn= ((ICPPASTQualifiedName) name).getNames();
|
||||
final IASTName ln= qn[qn.length-1];
|
||||
IASTName ln= ((ICPPASTQualifiedName) name).getLastName();
|
||||
if (CPPVisitor.getContainingScope(name) != CPPVisitor.getContainingScope(ln)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
IASTNode parent = name.getParent();
|
||||
if (parent instanceof IASTDeclarator) {
|
||||
if (CPPVisitor.isConstructor(this, (IASTDeclarator) parent)) {
|
||||
addConstructor(name);
|
||||
|
@ -208,8 +206,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
|||
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
|
||||
IASTName compName = compType.getName();
|
||||
if (compName instanceof ICPPASTQualifiedName) {
|
||||
IASTName[] ns = ((ICPPASTQualifiedName)compName).getNames();
|
||||
compName = ns[ns.length - 1];
|
||||
compName = ((ICPPASTQualifiedName) compName).getLastName();
|
||||
}
|
||||
if (CharArrayUtils.equals(c, compName.toCharArray())) {
|
||||
if (isConstructorReference(name)) {
|
||||
|
@ -228,8 +225,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
|||
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
|
||||
IASTName compName = compType.getName();
|
||||
if (compName instanceof ICPPASTQualifiedName) {
|
||||
IASTName[] ns = ((ICPPASTQualifiedName)compName).getNames();
|
||||
compName = ns[ns.length - 1];
|
||||
compName = ((ICPPASTQualifiedName) compName).getLastName();
|
||||
}
|
||||
IBinding[] result = null;
|
||||
if ((!prefixLookup && CharArrayUtils.equals(c, compName.toCharArray()))
|
||||
|
@ -313,12 +309,11 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
|||
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
|
||||
IASTName compName = compType.getName();
|
||||
if (compName instanceof ICPPASTQualifiedName) {
|
||||
IASTName[] ns = ((ICPPASTQualifiedName)compName).getNames();
|
||||
compName = ns[ns.length - 1];
|
||||
compName = ((ICPPASTQualifiedName) compName).getLastName();
|
||||
}
|
||||
|
||||
if (CharArrayUtils.equals(compName.toCharArray(), n)) {
|
||||
return new IBinding[] {getClassType()};
|
||||
return new IBinding[] { getClassType() };
|
||||
}
|
||||
|
||||
return super.find(name);
|
||||
|
@ -330,8 +325,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
|||
if (node instanceof ICPPASTTemplateId)
|
||||
node = node.getParent();
|
||||
if (node instanceof ICPPASTQualifiedName) {
|
||||
IASTName[] ns = ((ICPPASTQualifiedName)node).getNames();
|
||||
if (ns[ns.length - 1] == name)
|
||||
if (((ICPPASTQualifiedName) node).getLastName() == name)
|
||||
node = node.getParent();
|
||||
else
|
||||
return false;
|
||||
|
@ -494,8 +488,7 @@ class ImplicitsAnalysis {
|
|||
dcltor = ((IASTFunctionDefinition)member).getDeclarator();
|
||||
}
|
||||
if (!(dcltor instanceof ICPPASTFunctionDeclarator) ||
|
||||
!CharArrayUtils.equals(dcltor.getName().toCharArray(), OverloadableOperator.ASSIGN.toCharArray()))
|
||||
{
|
||||
!CharArrayUtils.equals(dcltor.getName().toCharArray(), OverloadableOperator.ASSIGN.toCharArray())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -517,12 +510,12 @@ class ImplicitsAnalysis {
|
|||
private static boolean paramHasTypeReferenceToTheAssociatedClassType(IASTParameterDeclaration dec, String name) {
|
||||
boolean result= false;
|
||||
IASTDeclarator pdtor= dec.getDeclarator();
|
||||
if (pdtor.getPointerOperators().length == 1 && pdtor.getPointerOperators()[0] instanceof ICPPASTReferenceOperator) {
|
||||
if (dec.getDeclSpecifier() instanceof ICPPASTNamedTypeSpecifier) {
|
||||
ICPPASTNamedTypeSpecifier nts= (ICPPASTNamedTypeSpecifier) dec.getDeclSpecifier();
|
||||
if (name == null || name.equals(nts.getName().getRawSignature())) {
|
||||
result= true;
|
||||
}
|
||||
if (pdtor.getPointerOperators().length == 1 &&
|
||||
pdtor.getPointerOperators()[0] instanceof ICPPASTReferenceOperator &&
|
||||
dec.getDeclSpecifier() instanceof ICPPASTNamedTypeSpecifier) {
|
||||
ICPPASTNamedTypeSpecifier nts= (ICPPASTNamedTypeSpecifier) dec.getDeclSpecifier();
|
||||
if (name == null || name.equals(nts.getName().getRawSignature())) {
|
||||
result= true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -114,7 +114,7 @@ class LookupData {
|
|||
astName = null;
|
||||
}
|
||||
|
||||
public final char[] name () {
|
||||
public final char[] name() {
|
||||
if (astName != null)
|
||||
return astName.toCharArray();
|
||||
return CPPSemantics.EMPTY_NAME_ARRAY;
|
||||
|
|
Loading…
Add table
Reference in a new issue