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

Code formatting.

This commit is contained in:
Sergey Prigogin 2008-10-12 23:48:09 +00:00
parent d2c1866cb7
commit cb5c6721aa
2 changed files with 55 additions and 57 deletions

View file

@ -274,8 +274,8 @@ public class CPPSemantics {
*/ */
if (binding instanceof ICPPClassTemplate) { if (binding instanceof ICPPClassTemplate) {
IASTNode parent= data.astName.getParent(); IASTNode parent= data.astName.getParent();
if(parent instanceof IASTNamedTypeSpecifier) { if (parent instanceof IASTNamedTypeSpecifier) {
if(parent.getParent() instanceof IASTSimpleDeclaration) { if (parent.getParent() instanceof IASTSimpleDeclaration) {
binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_INVALID_TYPE, data.name()); binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_INVALID_TYPE, data.name());
} }
} }
@ -356,7 +356,7 @@ public class CPPSemantics {
if (name.getPropertyInParent() == IASTNamedTypeSpecifier.NAME && !(binding instanceof IType || binding instanceof ICPPConstructor)) { if (name.getPropertyInParent() == IASTNamedTypeSpecifier.NAME && !(binding instanceof IType || binding instanceof ICPPConstructor)) {
IASTNode parent = name.getParent().getParent(); IASTNode parent = name.getParent().getParent();
if (parent instanceof IASTTypeId && parent.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) { if (parent instanceof IASTTypeId && parent.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) {
if(!(binding instanceof IType)) { if (!(binding instanceof IType)) {
// a type id needs to hold a type // 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.name());
} }
@ -547,7 +547,7 @@ public class CPPSemantics {
if (results instanceof IBinding) { if (results instanceof IBinding) {
data.foundItems = ArrayUtil.append(Object.class, (Object[]) data.foundItems, results); data.foundItems = ArrayUtil.append(Object.class, (Object[]) data.foundItems, results);
} else if (results instanceof Object[]) { } else if (results instanceof Object[]) {
data.foundItems = ArrayUtil.addAll(Object.class, (Object[])data.foundItems, (Object[])results); data.foundItems = ArrayUtil.addAll(Object.class, (Object[]) data.foundItems, (Object[]) results);
} }
} else { } else {
data.foundItems = mergePrefixResults((CharArrayObjectMap) data.foundItems, results, scoped); data.foundItems = mergePrefixResults((CharArrayObjectMap) data.foundItems, results, scoped);
@ -831,8 +831,8 @@ public class CPPSemantics {
return null; return null;
} }
for(ICPPBase base : bases) { for (ICPPBase base : bases) {
if(base instanceof IProblemBinding) if (base instanceof IProblemBinding)
continue; continue;
IBinding b = base.getBaseClass(); IBinding b = base.getBaseClass();
@ -841,7 +841,7 @@ public class CPPSemantics {
inherited = null; inherited = null;
final ICPPClassType cls= (ICPPClassType) b; final ICPPClassType cls = (ICPPClassType) b;
final ICPPScope parent = (ICPPScope) cls.getCompositeScope(); final ICPPScope parent = (ICPPScope) cls.getCompositeScope();
if (parent == null) if (parent == null)
@ -2086,7 +2086,6 @@ public class CPPSemantics {
currFnCost[j] = cost; currFnCost[j] = cost;
} }
hasWorse = false; hasWorse = false;
hasBetter = false; hasBetter = false;
// In order for this function to be better than the previous best, it must // In order for this function to be better than the previous best, it must
@ -2412,14 +2411,14 @@ public class CPPSemantics {
if (fieldReference.isPointerDereference()) { if (fieldReference.isPointerDereference()) {
IType type= getUltimateTypeUptoPointers(result); IType type= getUltimateTypeUptoPointers(result);
boolean needCheckClassMemberAccessOperator= true; boolean needCheckClassMemberAccessOperator= true;
if(type instanceof IPointerType) { if (type instanceof IPointerType) {
type= getUltimateTypeUptoPointers(((IPointerType) type).getType()); type= getUltimateTypeUptoPointers(((IPointerType) type).getType());
if(type instanceof ICPPClassType) { if (type instanceof ICPPClassType) {
needCheckClassMemberAccessOperator= false; needCheckClassMemberAccessOperator= false;
} }
} }
if(needCheckClassMemberAccessOperator) { if (needCheckClassMemberAccessOperator) {
IType temp= result; IType temp= result;
result= null; result= null;
@ -2438,7 +2437,7 @@ public class CPPSemantics {
CPPASTName x= new CPPASTName(); CPPASTName x= new CPPASTName();
boolean isConst= false, isVolatile= false; boolean isConst= false, isVolatile= false;
if(temp instanceof IQualifierType) { if (temp instanceof IQualifierType) {
isConst= ((IQualifierType)temp).isConst(); isConst= ((IQualifierType)temp).isConst();
isVolatile= ((IQualifierType)temp).isVolatile(); isVolatile= ((IQualifierType)temp).isVolatile();
} }

View file

@ -42,25 +42,23 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator;
*/ */
public class SemanticUtil { public class SemanticUtil {
private static final char[] OPERATOR_CHARS = Keywords.OPERATOR.toCharArray(); private static final char[] OPERATOR_CHARS = Keywords.OPERATOR.toCharArray();
/** // Cache of overloadable operator names for fast lookup. Used by isConversionOperator.
* Cache of overloadable operator names for fast lookup. Used by isConversionOperator.
*/
private static final CharArraySet cas= new CharArraySet(OverloadableOperator.values().length); private static final CharArraySet cas= new CharArraySet(OverloadableOperator.values().length);
static { static {
final int OPERATOR_SPC= OPERATOR_CHARS.length + 1; final int OPERATOR_SPC= OPERATOR_CHARS.length + 1;
for(OverloadableOperator op : OverloadableOperator.values()) { for (OverloadableOperator op : OverloadableOperator.values()) {
char[] name= op.toCharArray(); char[] name= op.toCharArray();
cas.put(CharArrayUtils.subarray(name, OPERATOR_SPC, name.length)); cas.put(CharArrayUtils.subarray(name, OPERATOR_SPC, name.length));
} }
} }
/** /**
* Returns a list of ICPPMethod objects representing all conversion operators * Returns an array of ICPPMethod objects representing all conversion operators
* declared by the specified class. This does not include inherited methods. Conversion * declared by the specified class. This does not include inherited methods. Conversion
* operators cannot be implicit. * operators cannot be implicit.
* @param clazz * @param clazz
* @return List of ICPPMethod * @return an array of conversion operators.
*/ */
public static final ICPPMethod[] getDeclaredConversionOperators(ICPPClassType clazz) throws DOMException { public static final ICPPMethod[] getDeclaredConversionOperators(ICPPClassType clazz) throws DOMException {
ICPPMethod[] methods= new ICPPMethod[0]; ICPPMethod[] methods= new ICPPMethod[0];
@ -68,9 +66,9 @@ public class SemanticUtil {
clazz= (ICPPClassType) ((ICPPDeferredClassInstance)clazz).getTemplateDefinition(); clazz= (ICPPClassType) ((ICPPDeferredClassInstance)clazz).getTemplateDefinition();
} }
ICPPMethod[] decs= clazz.getDeclaredMethods(); ICPPMethod[] decs= clazz.getDeclaredMethods();
if(decs != null) { if (decs != null) {
for(ICPPMethod method : decs) { for (ICPPMethod method : decs) {
if(isConversionOperator(method)) { if (isConversionOperator(method)) {
methods= (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, methods, method); methods= (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, methods, method);
} }
} }
@ -79,16 +77,16 @@ public class SemanticUtil {
} }
/** /**
* Returns a list of ICPPMethod objects representing all conversion operators * Returns an array of ICPPMethod objects representing all conversion operators
* declared by the specified class and its ancestors. This includes inherited * declared by the specified class and its ancestors. This includes inherited
* methods. Conversion operators cannot be implicit. * methods. Conversion operators cannot be implicit.
* @param clazz * @param clazz
* @return List of ICPPMethod * @return an array of conversion operators.
*/ */
public static ICPPMethod[] getConversionOperators(ICPPClassType clazz) throws DOMException { public static ICPPMethod[] getConversionOperators(ICPPClassType clazz) throws DOMException {
ICPPMethod[] methods= new ICPPMethod[0]; ICPPMethod[] methods= new ICPPMethod[0];
ObjectSet<ICPPClassType> ancestry= inheritanceClosure(clazz); ObjectSet<ICPPClassType> ancestry= inheritanceClosure(clazz);
for(int i=0; i<ancestry.size(); i++) { for (int i = 0; i < ancestry.size(); i++) {
methods= (ICPPMethod[]) ArrayUtil.addAll(ICPPMethod.class, methods, getDeclaredConversionOperators(ancestry.keyAt(i))); methods= (ICPPMethod[]) ArrayUtil.addAll(ICPPMethod.class, methods, getDeclaredConversionOperators(ancestry.keyAt(i)));
} }
return methods; return methods;
@ -104,18 +102,18 @@ public class SemanticUtil {
ObjectSet<ICPPClassType> current= new ObjectSet<ICPPClassType>(2); ObjectSet<ICPPClassType> current= new ObjectSet<ICPPClassType>(2);
current.put(root); current.put(root);
for(int count=0; count < CPPSemantics.MAX_INHERITANCE_DEPTH && !current.isEmpty(); count++) { for (int count = 0; count < CPPSemantics.MAX_INHERITANCE_DEPTH && !current.isEmpty(); count++) {
ObjectSet<ICPPClassType> next= new ObjectSet<ICPPClassType>(2); ObjectSet<ICPPClassType> next= new ObjectSet<ICPPClassType>(2);
for(int i=0; i<current.size(); i++) { for (int i = 0; i < current.size(); i++) {
ICPPClassType clazz= current.keyAt(i); ICPPClassType clazz= current.keyAt(i);
done.put(clazz); done.put(clazz);
for(ICPPBase base : clazz.getBases()) { for (ICPPBase base : clazz.getBases()) {
IBinding binding= base.getBaseClass(); IBinding binding= base.getBaseClass();
if(binding instanceof ICPPClassType && !(binding instanceof IProblemBinding)) { if (binding instanceof ICPPClassType && !(binding instanceof IProblemBinding)) {
ICPPClassType ct= (ICPPClassType) binding; ICPPClassType ct= (ICPPClassType) binding;
if(!done.containsKey(ct)) { if (!done.containsKey(ct)) {
next.put(ct); next.put(ct);
} }
} }
@ -134,11 +132,11 @@ public class SemanticUtil {
*/ */
public static final boolean isConversionOperator(ICPPMethod method) { public static final boolean isConversionOperator(ICPPMethod method) {
boolean result= false; boolean result= false;
if(!method.isImplicit()) { if (!method.isImplicit()) {
final char[] name= method.getNameCharArray(); final char[] name= method.getNameCharArray();
if (name.length > OPERATOR_CHARS.length + 1 && if (name.length > OPERATOR_CHARS.length + 1 &&
CharArrayUtils.equals(name, 0, OPERATOR_CHARS.length, OPERATOR_CHARS)) { CharArrayUtils.equals(name, 0, OPERATOR_CHARS.length, OPERATOR_CHARS)) {
if(name[OPERATOR_CHARS.length]==' ') { if (name[OPERATOR_CHARS.length]==' ') {
result= !cas.containsKey(name, OPERATOR_CHARS.length+1, name.length - (OPERATOR_CHARS.length+1)); result= !cas.containsKey(name, OPERATOR_CHARS.length+1, name.length - (OPERATOR_CHARS.length+1));
} }
} }
@ -167,28 +165,29 @@ public class SemanticUtil {
*/ */
static IType getUltimateType(IType type, IType[] lastPointerType, boolean stopAtPointerToMember) { static IType getUltimateType(IType type, IType[] lastPointerType, boolean stopAtPointerToMember) {
try { try {
while( true ){ while (true) {
if( type instanceof ITypedef ) { if (type instanceof ITypedef) {
IType tt= ((ITypedef)type).getType(); IType tt= ((ITypedef) type).getType();
if (tt == null) if (tt == null)
return type; return type;
type= tt; type= tt;
} else if( type instanceof IQualifierType ) { } else if (type instanceof IQualifierType) {
type= ((IQualifierType)type).getType(); type= ((IQualifierType) type).getType();
} else if( stopAtPointerToMember && type instanceof ICPPPointerToMemberType ) } else if (stopAtPointerToMember && type instanceof ICPPPointerToMemberType) {
return type; return type;
else if( type instanceof IPointerType ) { } else if (type instanceof IPointerType) {
if(lastPointerType!=null) { if (lastPointerType!=null) {
lastPointerType[0]= type; lastPointerType[0]= type;
} }
type= ((IPointerType) type).getType(); type= ((IPointerType) type).getType();
} else if( type instanceof ICPPReferenceType ) { } else if (type instanceof ICPPReferenceType) {
type= ((ICPPReferenceType)type).getType(); type= ((ICPPReferenceType) type).getType();
} else } else {
return type; return type;
}
} }
} catch ( DOMException e ) { } catch (DOMException e) {
return e.getProblem(); return e.getProblem();
} }
} }
@ -199,22 +198,23 @@ public class SemanticUtil {
* @param type * @param type
* @return the ultimate type contained inside the specified type * @return the ultimate type contained inside the specified type
*/ */
public static IType getUltimateTypeUptoPointers(IType type){ public static IType getUltimateTypeUptoPointers(IType type) {
try { try {
while( true ){ while (true) {
if( type instanceof ITypedef ) { if (type instanceof ITypedef) {
IType tt= ((ITypedef)type).getType(); IType tt= ((ITypedef) type).getType();
if (tt == null) if (tt == null)
return type; return type;
type= tt; type= tt;
} else if( type instanceof IQualifierType ) { } else if (type instanceof IQualifierType) {
type = ((IQualifierType)type).getType(); type = ((IQualifierType) type).getType();
} else if( type instanceof ICPPReferenceType ) { } else if (type instanceof ICPPReferenceType) {
type = ((ICPPReferenceType)type).getType(); type = ((ICPPReferenceType) type).getType();
} else } else {
return type; return type;
} }
} catch ( DOMException e ) { }
} catch (DOMException e) {
return e.getProblem(); return e.getProblem();
} }
} }
@ -226,13 +226,13 @@ public class SemanticUtil {
*/ */
static IType getUltimateTypeViaTypedefs(IType type) { static IType getUltimateTypeViaTypedefs(IType type) {
try { try {
while(type instanceof ITypedef) { while (type instanceof ITypedef) {
IType t= ((ITypedef)type).getType(); IType t= ((ITypedef) type).getType();
if (t == null) if (t == null)
return type; return type;
type= t; type= t;
} }
} catch(DOMException e) { } catch (DOMException e) {
type= e.getProblem(); type= e.getProblem();
} }
return type; return type;
@ -292,5 +292,4 @@ public class SemanticUtil {
} }
return result; return result;
} }
} }