mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Code streamlining.
This commit is contained in:
parent
35044af3ee
commit
11f921e614
7 changed files with 135 additions and 154 deletions
|
@ -446,11 +446,11 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
|
|||
|
||||
IBinding b1 = getBindingFromASTName("c; ", 1);
|
||||
assertVariable(b1, "c", ICPPClassType.class, "C");
|
||||
ICPPClassType b1type = (ICPPClassType)((ICPPVariable)b1).getType();
|
||||
ICPPClassType b1type = (ICPPClassType) ((ICPPVariable) b1).getType();
|
||||
assertClassTypeBinding(b1type, "C", ICPPClassType.k_class, 0, 0, 0, 4, 0, 0, 0, 2, 0);
|
||||
assertTrue(b1type.getScope() == null);
|
||||
assertTrue(b1type.getCompositeScope() instanceof ICPPClassScope);
|
||||
assertClassTypeBinding(((ICPPClassScope)b1type.getCompositeScope()).getClassType(), "C", ICPPClassType.k_class, 0, 0, 0, 4, 0, 0, 0, 2, 0);
|
||||
assertClassTypeBinding(((ICPPClassScope) b1type.getCompositeScope()).getClassType(), "C", ICPPClassType.k_class, 0, 0, 0, 4, 0, 0, 0, 2, 0);
|
||||
}
|
||||
{
|
||||
IBinding b2 = getBindingFromASTName("S s;", 1);
|
||||
|
@ -458,7 +458,7 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
|
|||
|
||||
IBinding b3 = getBindingFromASTName("s;", 1);
|
||||
assertVariable(b3, "s", ICPPClassType.class, "S");
|
||||
ICPPClassType b3type = (ICPPClassType)((ICPPVariable)b3).getType();
|
||||
ICPPClassType b3type = (ICPPClassType) ((ICPPVariable) b3).getType();
|
||||
assertClassTypeBinding(b3type, "S", ICompositeType.k_struct, 0, 0, 0, 4, 0, 0, 0, 2, 0);
|
||||
}
|
||||
{
|
||||
|
@ -467,7 +467,7 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
|
|||
|
||||
IBinding b5 = getBindingFromASTName("u; ", 1);
|
||||
assertVariable(b5, "u", ICPPClassType.class, "U");
|
||||
ICPPClassType b5type = (ICPPClassType)((ICPPVariable)b5).getType();
|
||||
ICPPClassType b5type = (ICPPClassType) ((ICPPVariable) b5).getType();
|
||||
assertClassTypeBinding(b5type, "U", ICompositeType.k_union, 0, 0, 0, 4, 0, 0, 0, 2, 0);
|
||||
}
|
||||
{
|
||||
|
@ -476,7 +476,7 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
|
|||
|
||||
IBinding b7 = getBindingFromASTName("e; ", 1);
|
||||
assertVariable(b7, "e", IEnumeration.class, "E");
|
||||
IEnumeration b5type = (IEnumeration)((ICPPVariable)b7).getType();
|
||||
IEnumeration b5type = (IEnumeration) ((ICPPVariable) b7).getType();
|
||||
assertEnumeration(b5type, "E", new String[] {"ER1","ER2","ER3"});
|
||||
assertTrue(b5type.getScope() == null);
|
||||
}
|
||||
|
@ -487,13 +487,13 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
|
|||
{
|
||||
IBinding b9 = getBindingFromASTName("var2 = c;", 4);
|
||||
assertVariable(b9, "var2", ICPPClassType.class, "C");
|
||||
ICPPClassType b9type = (ICPPClassType)((ICPPVariable)b9).getType();
|
||||
ICPPClassType b9type = (ICPPClassType) ((ICPPVariable) b9).getType();
|
||||
assertClassTypeBinding(b9type, "C", ICPPClassType.k_class, 0, 0, 0, 4, 0, 0, 0, 2, 0);
|
||||
}
|
||||
{
|
||||
IBinding b10 = getBindingFromASTName("var3 = &s;", 4);
|
||||
assertVariable(b10, "var3", IPointerType.class, null);
|
||||
IPointerType b10type = (IPointerType) ((ICPPVariable)b10).getType();
|
||||
IPointerType b10type = (IPointerType) ((ICPPVariable) b10).getType();
|
||||
assertClassTypeBinding((ICPPClassType) b10type.getType(), "S", ICompositeType.k_struct, 0, 0, 0, 4, 0, 0, 0, 2, 0);
|
||||
}
|
||||
{
|
||||
|
|
|
@ -102,8 +102,7 @@ public class ASTTypeUtil {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return Whether the function matching the given function binding takes
|
||||
* parameters or not.
|
||||
* Returns whether the function matching the given function binding takes parameters or not.
|
||||
*
|
||||
* @since 5.1
|
||||
*/
|
||||
|
@ -120,9 +119,8 @@ public class ASTTypeUtil {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation for the type array. The representation is
|
||||
* a comma-separated list of the normalized string representations of the
|
||||
* provided types.
|
||||
* Returns a string representation for the type array. The representation is a comma-separated
|
||||
* list of the normalized string representations of the provided types.
|
||||
* @see #getTypeListString(IType[], boolean)
|
||||
*/
|
||||
public static String getTypeListString(IType[] types) {
|
||||
|
@ -133,6 +131,7 @@ public class ASTTypeUtil {
|
|||
* Returns a String representation of the type array as a
|
||||
* comma-separated list.
|
||||
* @param types
|
||||
* @param normalize indicates whether normalization shall be performed
|
||||
* @return representation of the type array as a comma-separated list
|
||||
* @since 5.1
|
||||
*/
|
||||
|
@ -164,14 +163,12 @@ public class ASTTypeUtil {
|
|||
}
|
||||
|
||||
private static void appendArgumentList(ICPPTemplateArgument[] args, boolean normalize, StringBuilder result) {
|
||||
boolean first= true;
|
||||
result.append('<');
|
||||
for (ICPPTemplateArgument arg : args) {
|
||||
if (!first) {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
if (i != 0) {
|
||||
result.append(',');
|
||||
}
|
||||
first= false;
|
||||
appendArgument(arg, normalize, result);
|
||||
appendArgument(args[i], normalize, result);
|
||||
}
|
||||
result.append('>');
|
||||
}
|
||||
|
@ -507,40 +504,41 @@ public class ASTTypeUtil {
|
|||
*/
|
||||
public static void appendType(IType type, boolean normalize, StringBuilder result) {
|
||||
IType[] types = new IType[DEAULT_ITYPE_SIZE];
|
||||
int numTypes = 0;
|
||||
|
||||
// Push all of the types onto the stack
|
||||
// Push all of the types onto the stack.
|
||||
int i = 0;
|
||||
IQualifierType cvq= null;
|
||||
ICPPReferenceType ref= null;
|
||||
while (type != null && ++i < 100) {
|
||||
if (type instanceof ITypedef) {
|
||||
if (normalize) {
|
||||
// Skip the typedef and proceed with its target type.
|
||||
} else {
|
||||
// If normalization was not requested, skip the typedef and proceed with its target
|
||||
// type.
|
||||
if (!normalize) {
|
||||
// Output reference, qualifier and typedef, then stop.
|
||||
if (ref != null) {
|
||||
types = ArrayUtil.append(IType.class, types, ref);
|
||||
types = ArrayUtil.appendAt(types, numTypes++, ref);
|
||||
ref= null;
|
||||
}
|
||||
if (cvq != null) {
|
||||
types = ArrayUtil.append(IType.class, types, cvq);
|
||||
types = ArrayUtil.appendAt(types, numTypes++, cvq);
|
||||
cvq= null;
|
||||
}
|
||||
types = ArrayUtil.append(IType.class, types, type);
|
||||
types = ArrayUtil.appendAt(types, numTypes++, type);
|
||||
type= null;
|
||||
}
|
||||
} else {
|
||||
if (type instanceof ICPPReferenceType) {
|
||||
// Reference types ignore cv-qualifiers
|
||||
// Reference types ignore cv-qualifiers.
|
||||
cvq= null;
|
||||
// Lvalue references win over rvalue references
|
||||
// Lvalue references win over rvalue references.
|
||||
if (ref == null || ref.isRValueReference()) {
|
||||
// Delay reference to see if there are more
|
||||
// Delay reference to see if there are more.
|
||||
ref= (ICPPReferenceType) type;
|
||||
}
|
||||
} else {
|
||||
if (cvq != null) {
|
||||
// Merge cv qualifiers
|
||||
// Merge cv qualifiers.
|
||||
if (type instanceof IQualifierType || type instanceof IPointerType) {
|
||||
type= SemanticUtil.addQualifiers(type, cvq.isConst(), cvq.isVolatile(), false);
|
||||
cvq= null;
|
||||
|
@ -550,16 +548,16 @@ public class ASTTypeUtil {
|
|||
// Delay cv qualifier to merge it with others
|
||||
cvq= (IQualifierType) type;
|
||||
} else {
|
||||
// No reference, no cv qualifier: output reference and cv-qualifier
|
||||
// No reference, no cv qualifier: output reference and cv-qualifier.
|
||||
if (ref != null) {
|
||||
types = ArrayUtil.append(IType.class, types, ref);
|
||||
types = ArrayUtil.appendAt(types, numTypes++, ref);
|
||||
ref= null;
|
||||
}
|
||||
if (cvq != null) {
|
||||
types = ArrayUtil.append(IType.class, types, cvq);
|
||||
types = ArrayUtil.appendAt(types, numTypes++, cvq);
|
||||
cvq= null;
|
||||
}
|
||||
types = ArrayUtil.append(IType.class, types, type);
|
||||
types = ArrayUtil.appendAt(types, numTypes++, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -572,12 +570,12 @@ public class ASTTypeUtil {
|
|||
}
|
||||
}
|
||||
|
||||
// Pop all of the types off of the stack, and build the string representation while doing so.
|
||||
// Pop all of the types from the stack, and build the string representation while doing so.
|
||||
List<IType> postfix= null;
|
||||
BitSet parenthesis= null;
|
||||
boolean needParenthesis= false;
|
||||
boolean needSpace= false;
|
||||
for (int j = types.length; --j >= 0;) {
|
||||
for (int j = numTypes; --j >= 0;) {
|
||||
IType tj = types[j];
|
||||
if (tj != null) {
|
||||
if (j > 0 && types[j - 1] instanceof IQualifierType) {
|
||||
|
@ -589,7 +587,7 @@ public class ASTTypeUtil {
|
|||
needSpace= true;
|
||||
--j;
|
||||
} else {
|
||||
// Handle post-fix
|
||||
// Handle post-fix.
|
||||
if (tj instanceof IFunctionType || tj instanceof IArrayType) {
|
||||
if (j == 0) {
|
||||
if (needSpace)
|
||||
|
@ -639,7 +637,7 @@ public class ASTTypeUtil {
|
|||
* @noreference This method is not intended to be referenced by clients.
|
||||
*/
|
||||
public static String getType(IASTDeclarator declarator) {
|
||||
// get the most nested declarator
|
||||
// Get the most nested declarator.
|
||||
while (declarator.getNestedDeclarator() != null) {
|
||||
declarator = declarator.getNestedDeclarator();
|
||||
}
|
||||
|
|
|
@ -143,79 +143,51 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I
|
|||
return msg;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return node instanceof IASTName ? new String(((IASTName) node).getSimpleID()) : CPPSemantics.EMPTY_NAME;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
|
||||
*/
|
||||
@Override
|
||||
public char[] getNameCharArray() {
|
||||
return node instanceof IASTName ? ((IASTName) node).getSimpleID() : CharArrayUtils.EMPTY;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
|
||||
*/
|
||||
@Override
|
||||
public IScope getScope() throws DOMException {
|
||||
throw new DOMException(this);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getPhysicalNode()
|
||||
*/
|
||||
@Override
|
||||
public IASTNode getPhysicalNode() {
|
||||
return getASTNode();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object clone() {
|
||||
// Don't clone problems
|
||||
// Don't clone problems.
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IScope#getParent()
|
||||
*/
|
||||
@Override
|
||||
public IScope getParent() throws DOMException {
|
||||
throw new DOMException(this);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public IBinding[] find(String name) {
|
||||
return IBinding.EMPTY_BINDING_ARRAY;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IScope#getScopeName()
|
||||
*/
|
||||
@Override
|
||||
public IName getScopeName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IScope#addName(org.eclipse.cdt.core.dom.ast.IASTName)
|
||||
*/
|
||||
@Override
|
||||
public void addName(IASTName name) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IScope#getBinding(org.eclipse.cdt.core.dom.ast.IASTName, boolean)
|
||||
*/
|
||||
@Override
|
||||
public IBinding getBinding(IASTName name, boolean resolve) {
|
||||
return null;
|
||||
|
@ -226,37 +198,22 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I
|
|||
return IBinding.EMPTY_BINDING_ARRAY;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IScope#getBinding(org.eclipse.cdt.core.dom.ast.IASTName, boolean)
|
||||
*/
|
||||
@Override
|
||||
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IScope#getBinding(org.eclipse.cdt.core.dom.ast.IASTName, boolean)
|
||||
*/
|
||||
/**
|
||||
* @deprecated Use {@link #getBindings(ScopeLookupData)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) {
|
||||
return getBindings(new ScopeLookupData(name, resolve, prefixLookup));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IScope#getBinding(org.eclipse.cdt.core.dom.ast.IASTName, boolean)
|
||||
*/
|
||||
@Override
|
||||
public IBinding[] getBindings(ScopeLookupData lookup) {
|
||||
return IBinding.EMPTY_BINDING_ARRAY;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
|
||||
*/
|
||||
@Override
|
||||
public boolean isSameType(IType type) {
|
||||
return type == this;
|
||||
|
@ -320,76 +277,99 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I
|
|||
public void removeNestedFromCache(IASTNode container) {
|
||||
}
|
||||
|
||||
// Dummy methods for derived classes
|
||||
// Dummy methods for derived classes.
|
||||
public IType getType() {
|
||||
return new ProblemType(getID());
|
||||
}
|
||||
|
||||
public boolean isStatic() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String[] getQualifiedName() throws DOMException {
|
||||
throw new DOMException(this);
|
||||
}
|
||||
|
||||
public char[][] getQualifiedNameCharArray() throws DOMException {
|
||||
throw new DOMException(this);
|
||||
}
|
||||
|
||||
public boolean isGloballyQualified() throws DOMException {
|
||||
throw new DOMException(this);
|
||||
}
|
||||
|
||||
public boolean isMutable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isExtern() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isExternC() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isAuto() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isRegister() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public IValue getInitialValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isAnonymous() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isInline() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean takesVarArgs() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public IType[] getExceptionSpecification() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasParameterPack() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isVirtual() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isPureVirtual() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isImplicit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isExplicit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasDefaultValue() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public IValue getDefaultValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isParameterPack() {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.IName;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.EScopeKind;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
|
@ -84,7 +83,7 @@ public class CPPFunctionScope extends CPPScope implements ICPPFunctionScope {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IScope getParent() throws DOMException {
|
||||
public IScope getParent() {
|
||||
//we can't just resolve the function and get its parent scope, since there are cases where that
|
||||
//could loop since resolving functions requires resolving their parameter types
|
||||
IASTFunctionDeclarator fdtor = (IASTFunctionDeclarator) getPhysicalNode();
|
||||
|
|
|
@ -17,7 +17,6 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.IName;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
|
@ -78,7 +77,7 @@ abstract public class CPPScope implements ICPPASTInternalScope {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IScope getParent() throws DOMException {
|
||||
public IScope getParent() {
|
||||
return CPPVisitor.getContainingNonTemplateScope(physicalNode);
|
||||
}
|
||||
|
||||
|
|
|
@ -118,6 +118,7 @@ public class CPPScopeMapper {
|
|||
public IBinding[] getBindings(ScopeLookupData lookup) {
|
||||
return fScope.getBindings(lookup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScope getParent() throws DOMException {
|
||||
IScope parent= fScope.getParent();
|
||||
|
|
|
@ -14,15 +14,19 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
|
||||
|
||||
/**
|
||||
* Non API methods for cpp bindings.
|
||||
* Non API methods for C++ bindings.
|
||||
*/
|
||||
public interface ICPPInternalBinding extends ICPPBinding {
|
||||
|
||||
/**
|
||||
* Returns the definition of the binding, or {@code null} if the binding doesn't have
|
||||
* a definition.
|
||||
*/
|
||||
IASTNode getDefinition();
|
||||
|
||||
/** Implementors must keep the node with the lowest offset in declarations[0] */
|
||||
IASTNode[] getDeclarations();
|
||||
|
||||
void addDefinition(IASTNode node);
|
||||
|
||||
void addDeclaration(IASTNode node);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue