1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 08:55:25 +02:00

Bug 316308 - [C++0x] Explicit conversion operators

This commit is contained in:
Markus Schorn 2010-08-30 08:15:10 +00:00
parent 6be0d2175e
commit 9505f9ea9e
46 changed files with 265 additions and 185 deletions

View file

@ -8895,5 +8895,24 @@ public class AST2CPPTests extends AST2BaseTest {
IFunction f= bh.assertNonProblem("constBegin(); //ref", 10);
bh.assertProblem("begin(); //ref", 5);
}
// template <class T> class PE {
// explicit operator bool() const;
// };
// template <class T> class P {
// operator bool() const;
// };
// void fint(int);
// void test() {
// PE<int> pe;
// P<int> p;
// fint(pe + pe); // problem
// fint(p + p); // converted to boolean and then int.
// };
public void testExplicitConversionOperators() throws Exception {
String code= getAboveComment();
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
bh.assertProblem("fint(pe + pe);", 4);
bh.assertNonProblem("fint(p + p);", 4);
}
}

View file

@ -44,7 +44,10 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTProblem;
*
* @noextend This interface is not intended to be extended by clients.
* @noinstantiate This class is not intended to be instantiated by clients.
* @deprecated The class is provided for testing purposes, only. It should not be used by clients.
* Within CDT it is recommended to use {@link ASTSignatureUtil}, instead.
*/
@Deprecated
public class ASTSignatureUtil {
private static final String COMMA_SPACE = ", "; //$NON-NLS-1$

View file

@ -17,9 +17,4 @@ package org.eclipse.cdt.core.dom.ast.cpp;
*/
public interface ICPPConstructor extends ICPPMethod {
public static final ICPPConstructor [] EMPTY_CONSTRUCTOR_ARRAY = new ICPPConstructor[0];
/**
* Whether or not this constructor was declared as explicit
*/
boolean isExplicit();
}

View file

@ -39,6 +39,12 @@ public interface ICPPMethod extends ICPPFunction, ICPPMember {
*/
public boolean isImplicit();
/**
* Returns whether this is an explicit constructor or an explicit conversion operator.
* @since 5.3
*/
boolean isExplicit();
/**
* Returns whether this is a pure abstract method
* @since 5.1

View file

@ -326,6 +326,9 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I
public boolean isImplicit() {
return false;
}
public boolean isExplicit() {
return false;
}
public boolean hasDefaultValue() {
return false;
}

View file

@ -11,9 +11,9 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.model.ASTStringUtil;
/**
* Base for all c++ declaration specifiers
@ -113,8 +113,11 @@ public abstract class CPPASTBaseDeclSpecifier extends ASTNode implements ICPPAST
other.setOffsetAndLength(this);
}
@Override
/**
* Provided for debugging purposes, only.
*/
@Override
public String toString() {
return ASTSignatureUtil.getSignature(this);
return ASTStringUtil.getSignatureString(this, null);
}
}

View file

@ -11,9 +11,7 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
@ -24,30 +22,10 @@ public class CPPConstructor extends CPPMethod implements ICPPConstructor {
public CPPConstructorProblem(ICPPClassType owner, IASTNode node, int id, char[] arg) {
super(owner, node, id, arg);
}
public boolean isExplicit() {
return false;
}
}
/**
* @param declarator
*/
public CPPConstructor(ICPPASTFunctionDeclarator declarator) {
super(declarator);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor#isExplicit()
*/
public boolean isExplicit() {
IASTDeclaration decl= getPrimaryDeclaration();
if (decl != null) {
ICPPASTDeclSpecifier declspec= getDeclSpec(decl);
if (declspec != null) {
return declspec.isExplicit();
}
}
return false;
}
}

View file

@ -24,8 +24,4 @@ public class CPPConstructorInstance extends CPPMethodInstance implements ICPPCon
CPPTemplateParameterMap tpmap, ICPPTemplateArgument[] args) {
super(orig, owner, tpmap, args);
}
public boolean isExplicit() {
return ((ICPPConstructor) getTemplateDefinition()).isExplicit();
}
}

View file

@ -25,11 +25,4 @@ public class CPPConstructorSpecialization extends CPPMethodSpecialization
ICPPTemplateParameterMap argMap) {
super(orig, owner, argMap);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor#isExplicit()
*/
public boolean isExplicit() {
return ((ICPPConstructor)getSpecializedBinding()).isExplicit();
}
}

View file

@ -18,14 +18,4 @@ public class CPPConstructorTemplate extends CPPMethodTemplate implements ICPPCon
public CPPConstructorTemplate(IASTName name) {
super(name);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor#isExplicit()
*/
public boolean isExplicit() {
// mstodo fix that
// TODO Auto-generated method stub
return false;
}
}

View file

@ -25,11 +25,4 @@ public class CPPConstructorTemplateSpecialization extends CPPMethodTemplateSpeci
ICPPClassType owner, ICPPTemplateParameterMap tpmap) {
super(original, owner, tpmap);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor#isExplicit()
*/
public boolean isExplicit() {
return ((ICPPConstructor)getSpecializedBinding()).isExplicit();
}
}

View file

@ -30,6 +30,7 @@ import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
@ -178,15 +179,10 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition
do {
if (name != null) {
IASTNode parent = name.getParent();
while(!(parent instanceof IASTDeclaration))
while (parent != null && !(parent instanceof IASTDeclaration))
parent = parent.getParent();
IASTDeclSpecifier declSpec = null;
if (parent instanceof IASTSimpleDeclaration) {
declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
} else if (parent instanceof IASTFunctionDefinition) {
declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier();
}
IASTDeclSpecifier declSpec = getDeclSpecifier((IASTDeclaration) parent);
if (declSpec != null && declSpec.getStorageClass() == storage) {
return true;
}
@ -199,6 +195,16 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition
return false;
}
protected ICPPASTDeclSpecifier getDeclSpecifier(IASTDeclaration decl) {
if (decl instanceof IASTSimpleDeclaration) {
return (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration)decl).getDeclSpecifier();
}
if (decl instanceof IASTFunctionDefinition) {
return (ICPPASTDeclSpecifier) ((IASTFunctionDefinition)decl).getDeclSpecifier();
}
return null;
}
public IBinding resolveParameter(CPPParameter param) {
int pos= param.getParameterPosition();
@ -282,15 +288,10 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition
do {
if (name != null) {
IASTNode parent = name.getParent();
while(!(parent instanceof IASTDeclaration))
parent = parent.getParent();
while (parent != null && !(parent instanceof IASTDeclaration))
parent = parent.getParent();
IASTDeclSpecifier declSpec = null;
if (parent instanceof IASTSimpleDeclaration) {
declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
} else if (parent instanceof IASTFunctionDefinition) {
declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier();
}
IASTDeclSpecifier declSpec = getDeclSpecifier((IASTDeclaration) parent);
if (declSpec != null && declSpec.isInline())
return true;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others.
* Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -11,9 +11,9 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
@ -33,8 +33,4 @@ public class CPPImplicitConstructor extends CPPImplicitMethod implements ICPPCon
IType returnType= new CPPBasicType(Kind.eUnspecified, 0);
return CPPVisitor.createImplicitFunctionType(returnType, params, false, false);
}
public boolean isExplicit() {
return false;
}
}

View file

@ -172,6 +172,10 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod
return getPrimaryDeclaration() == null;
}
public boolean isExplicit() {
return false;
}
public boolean isPureVirtual() {
return false;
}

View file

@ -246,4 +246,14 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
return false;
}
public boolean isExplicit() {
IASTDeclaration decl= getPrimaryDeclaration();
if (decl != null) {
ICPPASTDeclSpecifier declspec= getDeclSpec(decl);
if (declspec != null) {
return declspec.isExplicit();
}
}
return false;
}
}

View file

@ -48,6 +48,10 @@ public class CPPMethodInstance extends CPPFunctionInstance implements ICPPMethod
public boolean isPureVirtual() {
return ((ICPPMethod)getTemplateDefinition()).isPureVirtual();
}
public boolean isExplicit() {
return ((ICPPMethod) getTemplateDefinition()).isExplicit();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isDestructor()

View file

@ -73,6 +73,10 @@ public class CPPMethodSpecialization extends CPPFunctionSpecialization
return false;
}
public boolean isExplicit() {
return ((ICPPMethod)getSpecializedBinding()).isExplicit();
}
public boolean isImplicit() {
return ((ICPPMethod) getSpecializedBinding()).isImplicit();
}

View file

@ -21,6 +21,8 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
@ -139,18 +141,25 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements ICPPMethod
}
public boolean isVirtual() {
// TODO Auto-generated method stub
return false;
}
IASTDeclaration decl = getPrimaryDeclaration();
if (decl instanceof ICPPASTTemplateDeclaration) {
ICPPASTDeclSpecifier declSpec= getDeclSpecifier(((ICPPASTTemplateDeclaration) decl).getDeclaration());
if (declSpec != null) {
return declSpec.isVirtual();
}
}
return false;
}
@Override
public boolean isInline() {
IASTDeclaration decl = getPrimaryDeclaration();
if( decl instanceof ICPPASTTemplateDeclaration && ((ICPPASTTemplateDeclaration)decl).getDeclaration() instanceof IASTFunctionDefinition )
return true;
IASTDeclaration decl = getPrimaryDeclaration();
if (decl instanceof ICPPASTTemplateDeclaration
&& ((ICPPASTTemplateDeclaration) decl).getDeclaration() instanceof IASTFunctionDefinition)
return true;
return super.isInline();
}
return super.isInline();
}
public boolean isDestructor() {
char[] name = getNameCharArray();
@ -163,9 +172,34 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements ICPPMethod
public boolean isImplicit() {
return false;
}
public boolean isPureVirtual() {
public boolean isExplicit() {
IASTDeclaration decl = getPrimaryDeclaration();
if (decl instanceof ICPPASTTemplateDeclaration) {
ICPPASTDeclSpecifier declSpec= getDeclSpecifier(((ICPPASTTemplateDeclaration) decl).getDeclaration());
if (declSpec != null) {
return declSpec.isExplicit();
}
}
return false;
}
public boolean isPureVirtual() {
if (declarations != null && declarations.length > 0) {
IASTName decl= declarations[0];
if (decl != null) {
IASTNode parent = decl.getParent();
while (!(parent instanceof IASTDeclarator) && parent != null)
parent = parent.getParent();
if (parent instanceof IASTDeclarator) {
IASTDeclarator dtor= ASTQueries.findTypeRelevantDeclarator((IASTDeclarator) parent);
if (dtor instanceof ICPPASTFunctionDeclarator) {
return ((ICPPASTFunctionDeclarator) dtor).isPureVirtual();
}
}
}
}
return false;
}
}

View file

@ -28,14 +28,16 @@ public class CPPMethodTemplateSpecialization extends CPPFunctionTemplateSpeciali
}
public boolean isVirtual() {
// TODO Auto-generated method stub
IBinding m = getSpecializedBinding();
if (m instanceof ICPPMethod)
return ((ICPPMethod) m).isVirtual();
return false;
}
public int getVisibility() {
IBinding m = getSpecializedBinding();
if( m instanceof ICPPMethod )
return ((ICPPMethod)m).getVisibility();
if (m instanceof ICPPMethod)
return ((ICPPMethod) m).getVisibility();
return 0;
}
@ -52,10 +54,23 @@ public class CPPMethodTemplateSpecialization extends CPPFunctionTemplateSpeciali
}
public boolean isImplicit() {
IBinding m = getSpecializedBinding();
if (m instanceof ICPPMethod)
return ((ICPPMethod) m).isImplicit();
return false;
}
public boolean isExplicit() {
IBinding m = getSpecializedBinding();
if (m instanceof ICPPMethod)
return ((ICPPMethod) m).isExplicit();
return false;
}
public boolean isPureVirtual() {
IBinding m = getSpecializedBinding();
if (m instanceof ICPPMethod)
return ((ICPPMethod) m).isPureVirtual();
return false;
}

View file

@ -39,6 +39,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPArithmeticConversion;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBuiltinParameter;
@ -348,14 +349,11 @@ class BuiltinOperators {
IType t2= SemanticUtil.getNestedType(memPtr.getMemberOfClass(), TDEF);
if (t2 instanceof ICPPClassType) {
ICPPClassType c2= (ICPPClassType) t2;
try {
if (SemanticUtil.calculateInheritanceDepth(c1, c2) >= 0) {
IType cvt= SemanticUtil.getNestedType(memPtr.getType(), TDEF);
IType rt= new CPPReferenceType(
SemanticUtil.addQualifiers(cvt, cv1.isConst(), cv1.isVolatile()), false);
addFunction(rt, clsPtr, memPtr);
}
} catch (DOMException e) {
if (SemanticUtil.calculateInheritanceDepth(c1, c2) >= 0) {
IType cvt= SemanticUtil.getNestedType(memPtr.getType(), TDEF);
IType rt= new CPPReferenceType(
SemanticUtil.addQualifiers(cvt, cv1.isConst(), cv1.isVolatile()), false);
addFunction(rt, clsPtr, memPtr);
}
}
}
@ -646,12 +644,19 @@ class BuiltinOperators {
try {
ICPPMethod[] ops = SemanticUtil.getConversionOperators((ICPPClassType) type);
result= new IType[ops.length];
for (int i = 0; i < result.length; i++) {
final ICPPFunctionType functionType = ops[i].getType();
int j= -1;
for (ICPPMethod op : ops) {
if (op.isExplicit())
continue;
final ICPPFunctionType functionType = op.getType();
if (functionType != null) {
result[i]= functionType.getReturnType();
IType retType= functionType.getReturnType();
if (retType != null) {
result[++j]= retType;
}
}
}
result= ArrayUtil.trimAt(IType.class, result, j);
} catch (DOMException e) {
}
}

View file

@ -2950,6 +2950,32 @@ public class CPPSemantics {
type = SemanticUtil.getNestedType(((ICPPVariable) binding).getType(), TDEF | CVTYPE);
if (!(type instanceof ICPPClassType))
return null;
// Copy initialization
if (initializer instanceof IASTEqualsInitializer) {
IASTEqualsInitializer eqInit= (IASTEqualsInitializer) initializer;
IASTInitializerClause initClause = eqInit.getInitializerClause();
IType sourceType= null;
boolean isLValue= false;
if (initClause instanceof IASTExpression) {
final IASTExpression expr = (IASTExpression) initClause;
isLValue= expr.isLValue();
sourceType= SemanticUtil.getSimplifiedType(expr.getExpressionType());
} else if (initClause instanceof ICPPASTInitializerList) {
sourceType= new InitializerListType((ICPPASTInitializerList) initClause);
}
if (sourceType != null) {
Cost c= Conversions.checkUserDefinedConversionSequence(isLValue, sourceType, type, false, false);
if (c.converts()) {
IFunction f= c.getUserDefinedConversion();
if (f instanceof ICPPConstructor)
return (ICPPConstructor) f;
}
return null;
}
}
// Direct Initialization
ICPPClassType classType = (ICPPClassType) type;
CPPASTName astName = new CPPASTName();
astName.setName(classType.getNameCharArray());
@ -2961,9 +2987,7 @@ public class CPPSemantics {
LookupData data = new LookupData(astName);
if (initializer == null) {
data.setFunctionArguments(IASTExpression.EMPTY_EXPRESSION_ARRAY);
} else if (initializer instanceof IASTEqualsInitializer) {
data.setFunctionArguments(((IASTEqualsInitializer) initializer).getInitializerClause());
} else if (initializer instanceof ICPPASTConstructorInitializer) {
} else if (initializer instanceof ICPPASTConstructorInitializer) {
data.setFunctionArguments(((ICPPASTConstructorInitializer) initializer).getArguments());
} else {
return null;
@ -3195,6 +3219,8 @@ public class CPPSemantics {
// 13.3.1.1.2 call to object of class type
ICPPMethod[] ops = SemanticUtil.getConversionOperators(callToObjectOfClassType);
for (ICPPMethod op : ops) {
if (op.isExplicit())
continue;
IFunctionType ft= op.getType();
if (ft != null) {
IType rt= SemanticUtil.getNestedType(ft.getReturnType(), SemanticUtil.TDEF);

View file

@ -126,8 +126,8 @@ public class Conversions {
}
}
// ... or has a class type (i.e., T2 is a class type), where T1 is not reference-related to T2, and can be
// implicitly converted to an lvalue of type cv3 T3, where cv1 T1 is reference-compatible with
// cv3 T3 (this conversion is selected by enumerating the applicable conversion functions (13.3.1.6)
// implicitly converted to an lvalue of type 'cv3 T3', where 'cv1 T1' is reference-compatible with
// 'cv3 T3' (this conversion is selected by enumerating the applicable conversion functions (13.3.1.6)
// and choosing the best one through overload resolution (13.3)),
if (T2 instanceof ICPPClassType && udc != UDCMode.noUDC && isReferenceRelated(T1, T2) < 0) {
Cost cost= conversionFuncForDirectReference(cv1T1, cv2T2, T2, true);
@ -340,7 +340,7 @@ public class Conversions {
return Cost.NO_CONVERSION;
}
static IType getInitListType(IType target) throws DOMException {
static IType getInitListType(IType target) {
if (target instanceof ICPPClassType && target instanceof ICPPTemplateInstance) {
ICPPTemplateInstance inst = (ICPPTemplateInstance) target;
if (CharArrayUtils.equals(INITIALIZER_LIST_NAME, inst.getNameCharArray())) {
@ -372,9 +372,8 @@ public class Conversions {
* <li>EQ 0 if cv1 == cv2
* <li>LT -1 if cv1 is less qualified than cv2 or not comparable
* </ul>
* @throws DOMException
*/
private static final int compareQualifications(IType t1, IType t2) throws DOMException {
private static final int compareQualifications(IType t1, IType t2) {
CVQualifier cv1= getCVQualifier(t1);
CVQualifier cv2= getCVQualifier(t2);
@ -407,7 +406,7 @@ public class Conversions {
* Note this is not a symmetric relation.
* @return inheritance distance, or -1, if <code>cv1t1</code> is not reference-related to <code>cv2t2</code>
*/
private static final int isReferenceRelated(IType cv1Target, IType cv2Source) throws DOMException {
private static final int isReferenceRelated(IType cv1Target, IType cv2Source) {
IType t= SemanticUtil.getNestedType(cv1Target, TDEF | REF);
IType s= SemanticUtil.getNestedType(cv2Source, TDEF | REF);
@ -458,7 +457,7 @@ public class Conversions {
* @return The cost for converting or <code>null</code> if <code>cv1t1</code> is not
* reference-compatible with <code>cv2t2</code>
*/
private static final Cost isReferenceCompatible(IType cv1Target, IType cv2Source, boolean isImpliedObject) throws DOMException {
private static final Cost isReferenceCompatible(IType cv1Target, IType cv2Source, boolean isImpliedObject) {
int inheritanceDist= isReferenceRelated(cv1Target, cv2Source);
if (inheritanceDist < 0)
return null;
@ -483,10 +482,9 @@ public class Conversions {
* @param isImplicitThis handles the special case when members of different
* classes are nominated via using-declarations. In such a situation the derived to
* base conversion does not cause any costs.
* @throws DOMException
*/
private static final Cost checkStandardConversionSequence(IType source, boolean isLValue, IType target,
boolean isImplicitThis) throws DOMException {
boolean isImplicitThis) {
final Cost cost= new Cost(source, target, Rank.IDENTITY);
if (lvalue_to_rvalue(cost, isLValue))
return cost;
@ -533,7 +531,7 @@ public class Conversions {
if (s instanceof ICPPClassType) {
// 13.3.1.5 Initialization by conversion function
return initializationByConversion(source, (ICPPClassType) s, target);
return initializationByConversion(source, (ICPPClassType) s, target, isDirect);
}
return Cost.NO_CONVERSION;
}
@ -669,6 +667,8 @@ public class Conversions {
CPPTemplates.instantiateConversionTemplates(ops, target);
for (final ICPPMethod op : ops) {
if (op != null && !(op instanceof IProblemBinding)) {
if (op.isExplicit())
continue;
final IType returnType = op.getType().getReturnType();
final IType uqReturnType= getNestedType(returnType, REF | TDEF | CVTYPE);
final int dist = SemanticUtil.calculateInheritanceDepth(uqReturnType, t);
@ -705,19 +705,25 @@ public class Conversions {
/**
* 13.3.1.5 Initialization by conversion function [over.match.conv]
*/
private static Cost initializationByConversion(IType source, ICPPClassType s, IType target) throws DOMException {
private static Cost initializationByConversion(IType source, ICPPClassType s, IType target, boolean direct) throws DOMException {
ICPPMethod[] ops = SemanticUtil.getConversionOperators(s);
CPPTemplates.instantiateConversionTemplates(ops, target);
FunctionCost cost1= null;
Cost cost2= null;
for (final ICPPMethod op : ops) {
if (op != null && !(op instanceof IProblemBinding)) {
final boolean isExplicitConversion= op.isExplicit();
if (isExplicitConversion && !direct)
continue;
final IType returnType = op.getType().getReturnType();
IType uqReturnType= getNestedType(returnType, TDEF | ALLCVQ);
boolean isLValue = uqReturnType instanceof ICPPReferenceType
&& !((ICPPReferenceType) uqReturnType).isRValueReference();
Cost c2= checkImplicitConversionSequence(target, uqReturnType, isLValue, UDCMode.noUDC, false);
if (c2.converts()) {
if (isExplicitConversion && c2.getRank() != Rank.IDENTITY)
continue;
ICPPFunctionType ftype = op.getType();
IType implicitType= CPPSemantics.getImplicitType(op, ftype.isConst(), ftype.isVolatile());
final Cost udcCost = isReferenceCompatible(getNestedType(implicitType, TDEF | REF), source, true);
@ -749,7 +755,7 @@ public class Conversions {
* [4.2] array-to-ptr
* [4.3] function-to-ptr
*/
private static final boolean lvalue_to_rvalue(final Cost cost, boolean isLValue) throws DOMException {
private static final boolean lvalue_to_rvalue(final Cost cost, boolean isLValue) {
// target should not be a reference here.
boolean isConverted= false;
IType target = getNestedType(cost.target, REF | TDEF);
@ -824,9 +830,8 @@ public class Conversions {
/**
* [4.4] Qualifications
* @param cost
* @throws DOMException
*/
private static final boolean qualificationConversion(Cost cost) throws DOMException{
private static final boolean qualificationConversion(Cost cost) {
IType s = cost.source;
IType t = cost.target;
boolean constInEveryCV2k = true;
@ -894,9 +899,8 @@ public class Conversions {
* following that can hold it: int, unsigned int, long unsigned long.
* 4.5-4 bool can be promoted to int
* 4.6 float can be promoted to double
* @throws DOMException
*/
private static final boolean promotion(Cost cost) throws DOMException{
private static final boolean promotion(Cost cost) {
IType src = cost.source;
IType trg = cost.target;
@ -980,7 +984,7 @@ public class Conversions {
* [4.10] Pointer conversions
* [4.11] Pointer to member conversions
*/
private static final boolean conversion(Cost cost, boolean forImplicitThis) throws DOMException{
private static final boolean conversion(Cost cost, boolean forImplicitThis){
final IType s = cost.source;
final IType t = cost.target;

View file

@ -15,8 +15,8 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
@ -259,4 +259,8 @@ class Cost {
public void setCouldNarrow() {
fCouldNarrow= true;
}
public ICPPFunction getUserDefinedConversion() {
return fUserDefinedConversion;
}
}

View file

@ -537,14 +537,12 @@ public class SemanticUtil {
* @param baseClass the class to find in the inheritance graph
* @return the number of edges in the inheritance graph, or -1 if the specified classes have
* no inheritance relation
* @throws DOMException
*/
public static final int calculateInheritanceDepth(IType type, IType baseClass) throws DOMException {
public static final int calculateInheritanceDepth(IType type, IType baseClass) {
return calculateInheritanceDepth(CPPSemantics.MAX_INHERITANCE_DEPTH, type, baseClass);
}
private static final int calculateInheritanceDepth(int maxdepth, IType type, IType baseClass)
throws DOMException {
private static final int calculateInheritanceDepth(int maxdepth, IType type, IType baseClass) {
if (type == baseClass || type.isSameType(baseClass)) {
return 0;
}

View file

@ -18,8 +18,4 @@ class CompositeCPPConstructor extends CompositeCPPMethod implements ICPPConstruc
public CompositeCPPConstructor(ICompositesFactory cf, ICPPFunction rbinding) {
super(cf, rbinding);
}
public boolean isExplicit() {
return ((ICPPConstructor)rbinding).isExplicit();
}
}

View file

@ -17,8 +17,4 @@ public class CompositeCPPConstructorInstance extends CompositeCPPMethodInstance
public CompositeCPPConstructorInstance(ICompositesFactory cf, ICPPConstructor rbinding) {
super(cf, rbinding);
}
public boolean isExplicit() {
return ((ICPPConstructor)rbinding).isExplicit();
}
}

View file

@ -13,15 +13,10 @@ package org.eclipse.cdt.internal.core.index.composite.cpp;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
public class CompositeCPPConstructorSpecialization extends
CompositeCPPMethodSpecialization implements ICPPConstructor {
public class CompositeCPPConstructorSpecialization extends CompositeCPPMethodSpecialization implements
ICPPConstructor {
public CompositeCPPConstructorSpecialization(ICompositesFactory cf, ICPPConstructor cons) {
super(cf, cons);
}
public boolean isExplicit() {
return ((ICPPConstructor)rbinding).isExplicit();
}
}
}

View file

@ -18,9 +18,4 @@ public class CompositeCPPConstructorTemplate extends CompositeCPPMethodTemplate
public CompositeCPPConstructorTemplate(ICompositesFactory cf, ICPPConstructor rbinding) {
super(cf, rbinding);
}
public boolean isExplicit() {
return ((ICPPConstructor)rbinding).isExplicit();
}
}

View file

@ -22,8 +22,4 @@ public class CompositeCPPConstructorTemplateSpecialization
ICPPFunction ft) {
super(cf, ft);
}
public boolean isExplicit() {
return ((ICPPConstructor)rbinding).isExplicit();
}
}

View file

@ -30,6 +30,10 @@ class CompositeCPPMethod extends CompositeCPPFunction implements ICPPMethod {
return ((ICPPMethod)rbinding).isImplicit();
}
public boolean isExplicit() {
return ((ICPPMethod)rbinding).isExplicit();
}
public boolean isVirtual() {
return ((ICPPMethod)rbinding).isVirtual();
}

View file

@ -29,6 +29,10 @@ public class CompositeCPPMethodInstance extends CompositeCPPFunctionInstance imp
return ((ICPPMethod)rbinding).isImplicit();
}
public boolean isExplicit() {
return ((ICPPMethod)rbinding).isExplicit();
}
public boolean isVirtual() {
return ((ICPPMethod)rbinding).isDestructor();
}

View file

@ -30,6 +30,10 @@ implements ICPPMethod {
return ((ICPPMethod)rbinding).isImplicit();
}
public boolean isExplicit() {
return ((ICPPMethod)rbinding).isExplicit();
}
public boolean isVirtual() {
return ((ICPPMethod)rbinding).isVirtual();
}

View file

@ -29,6 +29,10 @@ public class CompositeCPPMethodTemplate extends CompositeCPPFunctionTemplate imp
return ((ICPPMethod)rbinding).isImplicit();
}
public boolean isExplicit() {
return ((ICPPMethod)rbinding).isExplicit();
}
public boolean isVirtual() {
return ((ICPPMethod)rbinding).isVirtual();
}

View file

@ -33,6 +33,10 @@ public class CompositeCPPMethodTemplateSpecialization
return ((ICPPMethod)rbinding).isImplicit();
}
public boolean isExplicit() {
return ((ICPPMethod)rbinding).isExplicit();
}
public boolean isVirtual() {
return ((ICPPMethod)rbinding).isVirtual();
}

View file

@ -13,7 +13,6 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
@ -37,7 +36,7 @@ class PDOMCPPAnnotation {
public static final int VIRTUAL_OFFSET = 0;
public static final int DESTRUCTOR_OFFSET = 1;
public static final int IMPLICIT_METHOD_OFFSET = 2;
public static final int EXPLICIT_CONSTRUCTOR_OFFSET = 3;
public static final int EXPLICIT_METHOD_OFFSET = 3;
public static final int PURE_VIRTUAL_OFFSET = 4;
public static final int MAX_EXTRA_OFFSET= PURE_VIRTUAL_OFFSET;
@ -92,12 +91,7 @@ class PDOMCPPAnnotation {
modifiers |= (method.isDestructor() ? 1 : 0) << DESTRUCTOR_OFFSET;
modifiers |= (method.isImplicit() ? 1 : 0) << IMPLICIT_METHOD_OFFSET;
modifiers |= (method.isPureVirtual() ? 1 : 0) << PURE_VIRTUAL_OFFSET;
}
if (binding instanceof ICPPConstructor) {
ICPPConstructor constructor= (ICPPConstructor) binding;
if (constructor.isExplicit()) {
modifiers |= (1 << EXPLICIT_CONSTRUCTOR_OFFSET);
}
modifiers |= (method.isExplicit() ? 1 : 0) << EXPLICIT_METHOD_OFFSET;
}
return modifiers;
}

View file

@ -29,10 +29,6 @@ class PDOMCPPConstructor extends PDOMCPPMethod implements ICPPConstructor {
super(linkage, record);
}
public boolean isExplicit() {
return getBit(getAnnotation1(), PDOMCPPAnnotation.EXPLICIT_CONSTRUCTOR_OFFSET);
}
@Override
public int getNodeType() {
return IIndexCPPBindingConstants.CPP_CONSTRUCTOR;

View file

@ -49,8 +49,4 @@ public class PDOMCPPConstructorInstance extends PDOMCPPMethodInstance implements
public int getNodeType() {
return IIndexCPPBindingConstants.CPP_CONSTRUCTOR_INSTANCE;
}
public boolean isExplicit() {
return ((ICPPConstructor)getTemplateDefinition()).isExplicit();
}
}

View file

@ -47,8 +47,4 @@ class PDOMCPPConstructorSpecialization extends
public int getNodeType() {
return IIndexCPPBindingConstants.CPP_CONSTRUCTOR_SPECIALIZATION;
}
public boolean isExplicit() {
return getBit(getByte(record + ANNOTATION1), PDOMCPPAnnotation.EXPLICIT_CONSTRUCTOR_OFFSET);
}
}

View file

@ -32,10 +32,6 @@ class PDOMCPPConstructorTemplate extends PDOMCPPMethodTemplate implements
public PDOMCPPConstructorTemplate(PDOMLinkage linkage, long record) {
super(linkage, record);
}
public boolean isExplicit() {
return getBit(getAnnotation1(), PDOMCPPAnnotation.EXPLICIT_CONSTRUCTOR_OFFSET);
}
@Override
public int getNodeType() {

View file

@ -48,8 +48,4 @@ class PDOMCPPConstructorTemplateSpecialization extends
public int getNodeType() {
return IIndexCPPBindingConstants.CPP_CONSTRUCTOR_TEMPLATE_SPECIALIZATION;
}
public boolean isExplicit() {
return ((ICPPConstructor)getSpecializedBinding()).isExplicit();
}
}

View file

@ -130,6 +130,10 @@ class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod {
return getBit(getAnnotation1(), PDOMCPPAnnotation.IMPLICIT_METHOD_OFFSET);
}
public boolean isExplicit() {
return getBit(getAnnotation1(), PDOMCPPAnnotation.EXPLICIT_METHOD_OFFSET);
}
@Override
public IScope getFunctionScope() throws DOMException {
throw new PDOMNotImplementedError();

View file

@ -71,6 +71,10 @@ class PDOMCPPMethodInstance extends PDOMCPPFunctionInstance implements ICPPMetho
return ((ICPPMethod)getTemplateDefinition()).isPureVirtual();
}
public boolean isExplicit() {
return ((ICPPMethod)getTemplateDefinition()).isExplicit();
}
public ICPPClassType getClassOwner() {
return (ICPPClassType) getOwner();
}

View file

@ -86,6 +86,10 @@ class PDOMCPPMethodSpecialization extends PDOMCPPFunctionSpecialization
return getBit(getByte(record + ANNOTATION1), PDOMCPPAnnotation.IMPLICIT_METHOD_OFFSET);
}
public boolean isExplicit() {
return getBit(getByte(record + ANNOTATION1), PDOMCPPAnnotation.EXPLICIT_METHOD_OFFSET);
}
public boolean isVirtual() {
return getBit(getByte(record + ANNOTATION1), PDOMCPPAnnotation.VIRTUAL_OFFSET);
}

View file

@ -93,6 +93,10 @@ class PDOMCPPMethodTemplate extends PDOMCPPFunctionTemplate implements ICPPMetho
return getBit(getAnnotation1(), PDOMCPPAnnotation.IMPLICIT_METHOD_OFFSET);
}
public boolean isExplicit() {
return getBit(getAnnotation1(), PDOMCPPAnnotation.EXPLICIT_METHOD_OFFSET);
}
public boolean isVirtual() {
return getBit(getAnnotation1(), PDOMCPPAnnotation.VIRTUAL_OFFSET);
}

View file

@ -57,6 +57,14 @@ class PDOMCPPMethodTemplateSpecialization extends
}
return false;
}
public boolean isExplicit() {
IBinding spec = getSpecializedBinding();
if (spec instanceof ICPPMethod) {
((ICPPMethod)spec).isExplicit();
}
return false;
}
public boolean isVirtual() {
IBinding spec = getSpecializedBinding();

View file

@ -16,20 +16,20 @@ import java.net.URI;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
import org.eclipse.search.ui.text.AbstractTextSearchResult;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.ui.browser.typeinfo.TypeInfoLabelProvider;
import org.eclipse.cdt.internal.core.dom.parser.ASTProblem;
import org.eclipse.cdt.internal.core.model.TranslationUnit;
import org.eclipse.cdt.internal.ui.CPluginImages;
@ -121,7 +121,7 @@ public class PDOMSearchLabelProvider extends LabelProvider implements IStyledLab
}
else if (element instanceof ProblemSearchElement) {
ProblemSearchElement pse= (ProblemSearchElement) element;
return ASTSignatureUtil.getProblemMessage(pse.getProblemID(), pse.getDetail());
return ASTProblem.getMessage(pse.getProblemID(), pse.getDetail());
}
if (element instanceof IPath) {