1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2016-04-19 19:10:53 -07:00
parent 2114f6b108
commit 3b8da01c12

View file

@ -7,7 +7,7 @@
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates.TypeSelection.PARAMETERS; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates.TypeSelection.PARAMETERS;
@ -42,14 +42,14 @@ class FunctionCost {
private final ValueCategory[] fValueCategories; private final ValueCategory[] fValueCategories;
private final IASTNode fPoint; private final IASTNode fPoint;
private boolean fIsDirectCopyCtor; private boolean fIsDirectCopyCtor;
public FunctionCost(ICPPFunction fn, int paramCount, IASTNode point) { public FunctionCost(ICPPFunction fn, int paramCount, IASTNode point) {
fFunction= fn; fFunction= fn;
fCosts= new Cost[paramCount]; fCosts= new Cost[paramCount];
fValueCategories= new ValueCategory[paramCount]; fValueCategories= new ValueCategory[paramCount];
fPoint = point; fPoint = point;
} }
public FunctionCost(ICPPFunction fn, Cost cost, IASTNode point) { public FunctionCost(ICPPFunction fn, Cost cost, IASTNode point) {
fFunction= fn; fFunction= fn;
fCosts= new Cost[] {cost}; fCosts= new Cost[] {cost};
@ -60,11 +60,11 @@ class FunctionCost {
public int getLength() { public int getLength() {
return fCosts.length; return fCosts.length;
} }
public Cost getCost(int idx) { public Cost getCost(int idx) {
return fCosts[idx]; return fCosts[idx];
} }
public void setCost(int idx, Cost cost, ValueCategory valueCat) { public void setCost(int idx, Cost cost, ValueCategory valueCat) {
fCosts[idx]= cost; fCosts[idx]= cost;
fValueCategories[idx]= valueCat; fValueCategories[idx]= valueCat;
@ -73,7 +73,7 @@ class FunctionCost {
public ICPPFunction getFunction() { public ICPPFunction getFunction() {
return fFunction; return fFunction;
} }
public boolean hasAmbiguousUserDefinedConversion() { public boolean hasAmbiguousUserDefinedConversion() {
for (Cost cost : fCosts) { for (Cost cost : fCosts) {
if (cost.isAmbiguousUDC()) if (cost.isAmbiguousUDC())
@ -91,13 +91,13 @@ class FunctionCost {
} }
return false; return false;
} }
public boolean performUDC(IASTNode point) throws DOMException { public boolean performUDC(IASTNode point) throws DOMException {
for (int i = 0; i < fCosts.length; i++) { for (int i = 0; i < fCosts.length; i++) {
Cost cost = fCosts[i]; Cost cost = fCosts[i];
Cost udcCost= null; Cost udcCost= null;
switch (cost.isDeferredUDC()) { switch (cost.isDeferredUDC()) {
case NONE: case NONE:
continue; continue;
case COPY_INIT_OF_CLASS: case COPY_INIT_OF_CLASS:
udcCost = Conversions.copyInitializationOfClass(fValueCategories[i], cost.source, udcCost = Conversions.copyInitializationOfClass(fValueCategories[i], cost.source,
@ -109,12 +109,12 @@ class FunctionCost {
(ICPPClassType) uqSource, cost.target, false, point); (ICPPClassType) uqSource, cost.target, false, point);
break; break;
case LIST_INIT_OF_CLASS: case LIST_INIT_OF_CLASS:
udcCost = Conversions.listInitializationOfClass(((InitializerListType) cost.source).getEvaluation(), udcCost = Conversions.listInitializationOfClass(((InitializerListType) cost.source).getEvaluation(),
(ICPPClassType) cost.target, false, false, point); (ICPPClassType) cost.target, false, false, point);
break; break;
case DIRECT_LIST_INIT_OF_CLASS: case DIRECT_LIST_INIT_OF_CLASS:
udcCost = Conversions.listInitializationOfClass(((InitializerListType) cost.source).getEvaluation(), udcCost = Conversions.listInitializationOfClass(((InitializerListType) cost.source).getEvaluation(),
(ICPPClassType) cost.target, true, false, point); (ICPPClassType) cost.target, true, false, point);
break; break;
default: default:
return false; return false;
@ -134,7 +134,7 @@ class FunctionCost {
public int compareTo(IASTTranslationUnit tu, FunctionCost other) throws DOMException { public int compareTo(IASTTranslationUnit tu, FunctionCost other) throws DOMException {
if (other == null) if (other == null)
return -1; return -1;
boolean haveWorse = false; boolean haveWorse = false;
boolean haveBetter = false; boolean haveBetter = 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
@ -154,7 +154,7 @@ class FunctionCost {
haveWorse |= (cmp > 0); haveWorse |= (cmp > 0);
haveBetter |= (cmp < 0); haveBetter |= (cmp < 0);
} }
final ICPPFunction f1 = getFunction(); final ICPPFunction f1 = getFunction();
final ICPPFunction f2 = other.getFunction(); final ICPPFunction f2 = other.getFunction();
if (!haveWorse && !haveBetter) { if (!haveWorse && !haveBetter) {
@ -163,7 +163,7 @@ class FunctionCost {
ICPPFunctionTemplate otherAsTemplate= asTemplate(f2); ICPPFunctionTemplate otherAsTemplate= asTemplate(f2);
final boolean isTemplate = asTemplate != null; final boolean isTemplate = asTemplate != null;
final boolean otherIsTemplate = otherAsTemplate != null; final boolean otherIsTemplate = otherAsTemplate != null;
// Prefer normal functions over template functions // Prefer normal functions over template functions
if (isTemplate && !otherIsTemplate) { if (isTemplate && !otherIsTemplate) {
haveWorse = true; haveWorse = true;
@ -173,50 +173,50 @@ class FunctionCost {
TypeSelection ts= SemanticUtil.isConversionOperator(f1) ? RETURN_TYPE : PARAMETERS; TypeSelection ts= SemanticUtil.isConversionOperator(f1) ? RETURN_TYPE : PARAMETERS;
int order = CPPTemplates.orderFunctionTemplates(otherAsTemplate, asTemplate, ts, fPoint); int order = CPPTemplates.orderFunctionTemplates(otherAsTemplate, asTemplate, ts, fPoint);
if (order < 0) { if (order < 0) {
haveBetter= true; haveBetter= true;
} else if (order > 0) { } else if (order > 0) {
haveWorse= true; haveWorse= true;
} }
} }
} }
if (haveBetter == haveWorse) { if (haveBetter == haveWorse) {
// 7.3.3-15 Using declarations in classes can be overridden // 7.3.3-15 Using declarations in classes can be overridden
int cmp= overridesUsingDeclaration(f1, f2); int cmp= overridesUsingDeclaration(f1, f2);
if (cmp != 0) if (cmp != 0)
return cmp; return cmp;
// At this point prefer non-index bindings // At this point prefer non-index bindings
return -CPPSemantics.compareByRelevance(tu, f1, f2); return -CPPSemantics.compareByRelevance(tu, f1, f2);
} }
if (haveBetter) if (haveBetter)
return -1; return -1;
return 1; return 1;
} }
private int overridesUsingDeclaration(ICPPFunction f1, ICPPFunction f2) { private int overridesUsingDeclaration(ICPPFunction f1, ICPPFunction f2) {
if (f1.takesVarArgs() != f2.takesVarArgs()) if (f1.takesVarArgs() != f2.takesVarArgs())
return 0; return 0;
if (!(f1 instanceof ICPPMethod && f2 instanceof ICPPMethod)) if (!(f1 instanceof ICPPMethod && f2 instanceof ICPPMethod))
return 0; return 0;
final ICPPMethod m1 = (ICPPMethod) f1; final ICPPMethod m1 = (ICPPMethod) f1;
final ICPPMethod m2 = (ICPPMethod) f2; final ICPPMethod m2 = (ICPPMethod) f2;
ICPPClassType o1= m1.getClassOwner(); ICPPClassType o1= m1.getClassOwner();
ICPPClassType o2= m2.getClassOwner(); ICPPClassType o2= m2.getClassOwner();
if (o1.isSameType(o2)) if (o1.isSameType(o2))
return 0; return 0;
final ICPPFunctionType ft1 = m1.getType(); final ICPPFunctionType ft1 = m1.getType();
final ICPPFunctionType ft2 = m2.getType(); final ICPPFunctionType ft2 = m2.getType();
if (ft1.isConst() != ft2.isConst() || ft2.isVolatile() != ft2.isVolatile()) if (ft1.isConst() != ft2.isConst() || ft2.isVolatile() != ft2.isVolatile())
return 0; return 0;
if (!parameterTypesMatch(ft1, ft2)) if (!parameterTypesMatch(ft1, ft2))
return 0; return 0;
int diff= SemanticUtil.calculateInheritanceDepth(o2, o1, fPoint); int diff= SemanticUtil.calculateInheritanceDepth(o2, o1, fPoint);
if (diff >= 0) if (diff >= 0)
return diff; return diff;
@ -227,13 +227,13 @@ class FunctionCost {
IType[] p1= ft1.getParameterTypes(); IType[] p1= ft1.getParameterTypes();
IType[] p2= ft2.getParameterTypes(); IType[] p2= ft2.getParameterTypes();
if (p1.length != p2.length) { if (p1.length != p2.length) {
if (p1.length == 0) if (p1.length == 0)
return p2.length == 1 && SemanticUtil.isVoidType(p2[0]); return p2.length == 1 && SemanticUtil.isVoidType(p2[0]);
if (p2.length == 0) if (p2.length == 0)
return p1.length == 1 && SemanticUtil.isVoidType(p1[0]); return p1.length == 1 && SemanticUtil.isVoidType(p1[0]);
return false; return false;
} }
for (int i = 0; i < p2.length; i++) { for (int i = 0; i < p2.length; i++) {
if (!p1[i].isSameType(p2[i])) { if (!p1[i].isSameType(p2[i])) {
return false; return false;
@ -245,30 +245,30 @@ class FunctionCost {
public boolean mustBeWorse(FunctionCost other) { public boolean mustBeWorse(FunctionCost other) {
if (other == null) if (other == null)
return false; return false;
boolean haveWorse= false; boolean haveWorse= false;
int idx= getLength() - 1; int idx= getLength() - 1;
int idxOther= other.getLength() - 1; int idxOther= other.getLength() - 1;
for (; idx >= 0 && idxOther >= 0; idx--, idxOther--) { for (; idx >= 0 && idxOther >= 0; idx--, idxOther--) {
Cost cost= getCost(idx); Cost cost= getCost(idx);
if (!cost.converts()) if (!cost.converts())
return true; return true;
Cost otherCost= other.getCost(idxOther); Cost otherCost= other.getCost(idxOther);
int cmp; int cmp;
if (cost.isDeferredUDC() != DeferredUDC.NONE) { if (cost.isDeferredUDC() != DeferredUDC.NONE) {
cmp= cost.getRank().compareTo(otherCost.getRank()); cmp= cost.getRank().compareTo(otherCost.getRank());
} else { } else {
cmp= cost.compareTo(otherCost); cmp= cost.compareTo(otherCost);
} }
if (cmp < 0) if (cmp < 0)
return false; return false;
if (cmp > 0) if (cmp > 0)
haveWorse= true; haveWorse= true;
} }
return haveWorse; return haveWorse;
} }
@ -285,7 +285,7 @@ class FunctionCost {
public void setIsDirectInitWithCopyCtor(boolean val) { public void setIsDirectInitWithCopyCtor(boolean val) {
fIsDirectCopyCtor= val; fIsDirectCopyCtor= val;
} }
public boolean isDirectInitWithCopyCtor() { public boolean isDirectInitWithCopyCtor() {
return fIsDirectCopyCtor; return fIsDirectCopyCtor;
} }