1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-03 13:43:31 +02:00

Fix for 201204.

This commit is contained in:
Sergey Prigogin 2008-05-20 21:56:58 +00:00
parent 69ea8a3218
commit 17ed4692de
25 changed files with 652 additions and 568 deletions

View file

@ -1743,8 +1743,7 @@ public class AST2CPPTests extends AST2BaseTest {
def = (IASTFunctionDefinition) tu.getDeclarations()[2];
expStatement = (IASTExpressionStatement) ((IASTCompoundStatement) def
.getBody()).getStatements()[0];
IASTUnaryExpression ue = (IASTUnaryExpression) expStatement
.getExpression();
IASTUnaryExpression ue = (IASTUnaryExpression) expStatement.getExpression();
type = CPPVisitor.getExpressionType(ue);
assertTrue(type instanceof IQualifierType);
@ -1896,7 +1895,7 @@ public class AST2CPPTests extends AST2BaseTest {
IType t = pm.getType();
assertNotNull(t);
assertTrue(t instanceof ICPPPointerToMemberType);
ICPPClassType cls = ((ICPPPointerToMemberType) t).getMemberOfClass();
IType cls = ((ICPPPointerToMemberType) t).getMemberOfClass();
assertSame(S, cls);
assertTrue(((ICPPPointerToMemberType) t).getType() instanceof IBasicType);
}
@ -1937,9 +1936,8 @@ public class AST2CPPTests extends AST2BaseTest {
IType t = pm.getType();
assertTrue(t instanceof ICPPPointerToMemberType);
IFunctionType ft = (IFunctionType) ((ICPPPointerToMemberType) t)
.getType();
ICPPClassType ST = ((ICPPPointerToMemberType) t).getMemberOfClass();
IFunctionType ft = (IFunctionType) ((ICPPPointerToMemberType) t).getType();
IType ST = ((ICPPPointerToMemberType) t).getMemberOfClass();
assertTrue(ft.getReturnType() instanceof IPointerType);
assertSame(ST, ((IPointerType) ft.getReturnType()).getType());

View file

@ -2009,14 +2009,14 @@ public class AST2TemplateTests extends AST2BaseTest {
assertTrue(col.getName(2).resolveBinding() instanceof ICPPSpecialization);
}
// template<class T>
// template<class T1>
// struct Closure {
// Closure(T* obj, void (T::*method)()) {}
// Closure(T1* obj1, void (T1::*method1)()) {}
// };
//
// template<class T>
// Closure<T>* makeClosure(T* obj, void (T::*method)()) {
// return new Closure<T>(obj, method);
// template<class T2>
// Closure<T2>* makeClosure(T2* obj2, void (T2::*method2)()) {
// return new Closure<T2>(obj2, method2);
// }
//
// struct A {
@ -2025,7 +2025,7 @@ public class AST2TemplateTests extends AST2BaseTest {
// makeClosure(this, &A::m1);
// }
// };
public void _testBug201204() throws Exception {
public void testBug201204() throws Exception {
BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true);
ICPPFunction fn= bh.assertNonProblem("makeClosure(this", 11, ICPPFunction.class);
}

View file

@ -1400,7 +1400,7 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
try {
assertTrue(type instanceof ICPPPointerToMemberType);
ICPPPointerToMemberType ptmt = (ICPPPointerToMemberType) type;
ICPPClassType classType = ptmt.getMemberOfClass();
ICPPClassType classType = (ICPPClassType) ptmt.getMemberOfClass();
assertQNEquals(cqn, classType);
if(qn!=null) {
assert(ptmt.getType() instanceof ICPPBinding);

View file

@ -348,7 +348,6 @@ public class ASTTypeUtil {
}
}
try {
if (((IPointerType) type).isConst()) {
if (needSpace) {
result.append(SPACE); needSpace = false;
@ -361,8 +360,6 @@ public class ASTTypeUtil {
}
result.append(Keywords.VOLATILE); needSpace = true;
}
} catch (DOMException e) {
}
} else if (type instanceof IQualifierType) {
if (type instanceof ICQualifierType) {
if (((ICQualifierType) type).isRestrict()) {

View file

@ -28,11 +28,11 @@ public interface IPointerType extends IType {
* is this a const pointer
* @throws DOMException
*/
public boolean isConst() throws DOMException;
public boolean isConst();
/**
* is this a volatile pointer
* @throws DOMException
*/
public boolean isVolatile() throws DOMException;
public boolean isVolatile();
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* Copyright (c) 2005-2008 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
@ -7,7 +7,7 @@
*
* Contributors:
* IBM - Initial API and implementation
* /
* Sergey Prigogin (Google)
*******************************************************************************/
/*
* Created on Apr 22, 2005
@ -15,20 +15,26 @@
package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IPointerType;
/**
* @author aniefer
*
*/
public interface ICPPFunctionType extends IFunctionType {
/**
* returns true for a constant method
* Returns type of implicit <code>this</code>. parameter, or null, if the function
* is not a class method or a static method.
*/
public IPointerType getThisType();
/**
* Returns <code>true</code> for a constant method
*/
public boolean isConst();
/**
* returns true for a volatile method
* Returns <code>true</code> for a volatile method
*/
public boolean isVolatile();
}

View file

@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
/*
@ -15,6 +16,7 @@
package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IType;
/**
* @author aniefer
@ -22,8 +24,8 @@ import org.eclipse.cdt.core.dom.ast.IPointerType;
public interface ICPPPointerToMemberType extends IPointerType {
/**
* Get the class to whose members this points to
*
* Get the class to whose members this points to.
* @return Either ICPPClassType or ICPPTeplateTypeParameter.
*/
public ICPPClassType getMemberOfClass();
public IType getMemberOfClass();
}

View file

@ -50,11 +50,9 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBas
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
/**
* A utility that prints an AST to the console, useful for debugging purposes.
*
*
* @author Mike Kucera
*/
@SuppressWarnings("nls")
@ -101,8 +99,6 @@ public class ASTPrinter {
return false;
}
/**
* Prints the AST to stdout.
*
@ -113,7 +109,6 @@ public class ASTPrinter {
return print(root, System.out);
}
/**
* Prints problem nodes in the AST to the given printstream.
*
@ -140,7 +135,6 @@ public class ASTPrinter {
return false;
}
/**
* Prints problem nodes in the AST to stdout.
*
@ -151,8 +145,6 @@ public class ASTPrinter {
return printProblems(root, System.out);
}
private static void print(PrintStream out, int indentLevel, Object n) {
for (int i = 0; i < indentLevel; i++)
out.print(" ");
@ -188,8 +180,7 @@ public class ASTPrinter {
if (n instanceof IASTName) {
out.print(" " + ((IASTName)n).toString());
}
else if(n instanceof ICASTPointer) {
} else if (n instanceof ICASTPointer) {
ICASTPointer pointer = (ICASTPointer) n;
if (pointer.isConst())
out.print(" const");
@ -197,33 +188,25 @@ public class ASTPrinter {
out.print(" volatile");
if (pointer.isRestrict())
out.print(" restrict");
}
else if(n instanceof ICPointerType) {
} else if (n instanceof ICPointerType) {
ICPointerType pointer = (ICPointerType)n;
try {
if (pointer.isConst())
out.print(" const");
if (pointer.isVolatile())
out.print(" volatile");
if (pointer.isRestrict())
out.print(" restrict");
} catch (DOMException e) {
e.printStackTrace();
}
out.println();
try {
print(out, indentLevel, ((ITypeContainer)n).getType());
} catch(Exception e) {}
}
else if(n instanceof ICASTArrayModifier) {
} else if (n instanceof ICASTArrayModifier) {
if (((ICASTArrayModifier)n).isRestrict()) {
out.print(" restrict");
}
}
else if(n instanceof IASTComment) {
} else if (n instanceof IASTComment) {
out.print("'" + new String(((IASTComment)n).getComment()) + "'");
}
// else if(n instanceof ICompositeType) {
// } else if (n instanceof ICompositeType) {
// try {
// IField[] fields = ((ICompositeType)n).getFields();
// if (fields == null || fields.length == 0) {
@ -236,14 +219,12 @@ public class ASTPrinter {
// } catch (DOMException e) {
// e.printStackTrace();
// }
// }
else if(n instanceof ITypeContainer) {
} else if (n instanceof ITypeContainer) {
out.println();
try {
print(out, indentLevel, ((ITypeContainer)n).getType());
} catch(Exception e) {}
}
else if(n instanceof IVariable) {
} else if (n instanceof IVariable) {
IVariable var = (IVariable) n;
IType t;
try {
@ -254,17 +235,14 @@ public class ASTPrinter {
//e.printStackTrace();
}
}
else if(n instanceof IProblemBinding) {
} else if (n instanceof IProblemBinding) {
IProblemBinding problem = (IProblemBinding)n;
out.print(problem.getMessage());
}
out.println();
}
private static class ProblemVisitor extends ASTVisitor {
private PrintStream out;
@ -304,7 +282,6 @@ public class ASTPrinter {
}
}
/**
* This visitor extends from CPPASTVisitor but you can still
* apply it to a plain C AST and it will print everything
@ -335,7 +312,6 @@ public class ASTPrinter {
shouldVisitTemplateParameters = true;
}
private void print(IASTNode node) {
ASTPrinter.print(out, indentLevel, node);
}
@ -475,7 +451,6 @@ public class ASTPrinter {
return super.visit(templateParameter);
}
// @Override
// public int leave(ICASTDesignator designator) {
// indentLevel--;
@ -571,6 +546,5 @@ public class ASTPrinter {
indentLevel--;
return super.leave(templateParameter);
}
}
}

View file

@ -11,6 +11,7 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
@ -360,4 +361,13 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
public boolean isStatic( boolean resolveAll ) {
return hasStorageClass( IASTDeclSpecifier.sc_static );
}
@Override
public String toString() {
StringBuilder result = new StringBuilder();
result.append(getName());
IFunctionType t = getType();
result.append(t != null ? ASTTypeUtil.getParameterTypeString(t) : "()"); //$NON-NLS-1$
return result.toString();
}
}

View file

@ -14,8 +14,10 @@
*/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
@ -24,10 +26,9 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
* @author aniefer
*/
public class CPPFunctionType implements ICPPFunctionType {
private IType[] parameters = null;
private IType returnType = null;
private boolean isConst = false;
private boolean isVolatile = false;
private IType[] parameters;
private IType returnType;
private IPointerType thisType;
/**
* @param returnType
@ -37,11 +38,11 @@ public class CPPFunctionType implements ICPPFunctionType {
this.returnType = returnType;
this.parameters = types;
}
public CPPFunctionType( IType returnType, IType [] types, boolean isConst, boolean isVolatile ) {
public CPPFunctionType(IType returnType, IType[] types, IPointerType thisType) {
this.returnType = returnType;
this.parameters = types;
this.isConst = isConst;
this.isVolatile = isVolatile;
this.thisType = thisType;
}
public boolean isSameType(IType o) {
@ -84,13 +85,15 @@ public class CPPFunctionType implements ICPPFunctionType {
return false;
}
if( isConst != ft.isConst() || isVolatile != ft.isVolatile() )
if (isConst() != ft.isConst() || isVolatile() != ft.isVolatile()) {
return false;
}
return true;
}
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunctionType#getReturnType()
*/
@ -116,11 +119,23 @@ public class CPPFunctionType implements ICPPFunctionType {
return t;
}
public boolean isConst() {
return isConst;
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.ICPPFunctionType#getThisType()
*/
public IPointerType getThisType() {
return thisType;
}
public boolean isVolatile() {
return isVolatile;
public final boolean isConst() {
return thisType != null && thisType.isConst();
}
public final boolean isVolatile() {
return thisType != null && thisType.isVolatile();
}
@Override
public String toString() {
return ASTTypeUtil.getType(this);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2006 IBM Corporation and others.
* Copyright (c) 2005, 2008 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
@ -8,6 +8,7 @@
* Contributors:
* IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
*******************************************************************************/
/*
* Created on Feb 11, 2005
@ -28,10 +29,10 @@ import org.eclipse.cdt.internal.core.index.IIndexType;
/**
* @author aniefer
*/
public class CPPPointerToMemberType extends CPPPointerType implements
ICPPPointerToMemberType {
private ICPPASTPointerToMember operator = null;
private ICPPClassType clsType = null;
public class CPPPointerToMemberType extends CPPPointerType implements ICPPPointerToMemberType {
private ICPPASTPointerToMember operator;
private IType classType; // Can be either ICPPClassType or ICPPTemplateTypeParameter
/**
* @param type
* @param operator
@ -41,6 +42,11 @@ public class CPPPointerToMemberType extends CPPPointerType implements
this.operator = operator;
}
public CPPPointerToMemberType(IType type, ICPPClassType thisType, boolean isConst, boolean isVolatile) {
super(type, isConst, isVolatile);
this.classType = thisType;
}
@Override
public boolean isSameType(IType o) {
if (o == this)
@ -55,7 +61,7 @@ public class CPPPointerToMemberType extends CPPPointerType implements
return false;
CPPPointerToMemberType pt = (CPPPointerToMemberType) o;
ICPPClassType cls = pt.getMemberOfClass();
IType cls = pt.getMemberOfClass();
if (cls != null)
return cls.isSameType(getMemberOfClass());
return false;
@ -64,8 +70,8 @@ public class CPPPointerToMemberType extends CPPPointerType implements
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType#getMemberOfClass()
*/
public ICPPClassType getMemberOfClass() {
if( clsType == null ){
public IType getMemberOfClass() {
if (classType == null) {
ICPPASTPointerToMember pm = operator;
IASTName name = pm.getName();
if (name instanceof ICPPASTQualifiedName) {
@ -77,13 +83,12 @@ public class CPPPointerToMemberType extends CPPPointerType implements
}
IBinding binding = name.resolveBinding();
if( binding instanceof ICPPClassType ){
clsType = (ICPPClassType) binding;
if (binding instanceof IType) {
classType = (IType) binding;
} else {
clsType = new CPPClassType.CPPClassTypeProblem( name, IProblemBinding.SEMANTIC_INVALID_TYPE, name.toCharArray() );
classType = new CPPClassType.CPPClassTypeProblem(name, IProblemBinding.SEMANTIC_INVALID_TYPE, name.toCharArray());
}
}
return clsType;
return classType;
}
}

View file

@ -30,14 +30,12 @@ public class CPPPointerType implements IPointerType, ITypeContainer {
private boolean isConst = false;
private boolean isVolatile = false;
public CPPPointerType(IType type, IASTPointer operator) {
this.type = type;
this.isConst = operator.isConst();
this.isVolatile = operator.isVolatile();
}
public CPPPointerType(IType type, boolean isConst, boolean isVolatile) {
this.type = type;
this.isConst = isConst;

View file

@ -159,7 +159,7 @@ public class CPPSemantics {
public static final IType VOID_TYPE = new CPPBasicType(IBasicType.t_void, 0);
// Set to true for debugging.
public static boolean traceBindingResolution = false;
public static boolean traceBindingResolution = true;
static protected IBinding resolveBinding(IASTName name) {
if (traceBindingResolution) {
@ -489,10 +489,8 @@ public class CPPSemantics {
getAssociatedScopes(getUltimateType(element, true), namespaces, classes, tu);
}
} else if (t instanceof ICPPPointerToMemberType) {
IBinding binding = ((ICPPPointerToMemberType)t).getMemberOfClass();
if (binding instanceof IType)
getAssociatedScopes((IType)binding, namespaces, classes, tu);
getAssociatedScopes(getUltimateType(((ICPPPointerToMemberType)t).getType(), true), namespaces, classes, tu);
IType binding = ((ICPPPointerToMemberType) t).getMemberOfClass();
getAssociatedScopes(binding, namespaces, classes, tu);
}
return;
}

View file

@ -106,6 +106,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPMethodInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPMethodSpecialization;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPMethodTemplateSpecialization;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPParameter;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerToMemberType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateDefinition;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTemplateParameter;
@ -701,8 +702,7 @@ public class CPPTemplates {
}
} catch (DOMException e) {
}
return new CPPFunctionType(ret, params, ((ICPPFunctionType) type).isConst(),
((ICPPFunctionType) type).isVolatile());
return new CPPFunctionType(ret, params, ((ICPPFunctionType) type).getThisType());
}
if (type instanceof ICPPTemplateParameter) {
@ -750,6 +750,16 @@ public class CPPTemplates {
try {
IType temp = ((ITypeContainer) type).getType();
IType newType = instantiateType(temp, argMap, instantiationScope);
if (type instanceof ICPPPointerToMemberType) {
ICPPPointerToMemberType ptm = (ICPPPointerToMemberType) type;
IType memberOfClass = ptm.getMemberOfClass();
IType newMemberOfClass = instantiateType(memberOfClass, argMap, instantiationScope);
if ((newType != temp || newMemberOfClass != memberOfClass) &&
newMemberOfClass instanceof ICPPClassType) {
return new CPPPointerToMemberType(newType, (ICPPClassType) newMemberOfClass,
ptm.isConst(), ptm.isVolatile());
}
}
if (newType != temp) {
temp = (IType) type.clone();
((ITypeContainer) temp).setType(newType);
@ -1319,7 +1329,7 @@ public class CPPTemplates {
return false;
p = ((ICPPPointerToMemberType) p).getType();
p = ((ICPPPointerToMemberType) a).getType();
a = ((ICPPPointerToMemberType) a).getType();
} else if (p instanceof IPointerType) {
if (!(a instanceof IPointerType)) {
return false;
@ -1651,8 +1661,7 @@ public class CPPTemplates {
}
//14.1s8 function to pointer and array to pointer conversions
if (pType instanceof IFunctionType)
{
if (pType instanceof IFunctionType) {
pType = new CPPPointerType(pType);
} else if (pType instanceof IArrayType) {
try {

View file

@ -124,6 +124,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
@ -1565,7 +1566,18 @@ public class CPPVisitor {
returnType = getPointerTypes(returnType, fnDtor);
}
IType type = new CPPFunctionType(returnType, pTypes, fnDtor.isConst(), fnDtor.isVolatile());
IScope scope = fnDtor.getFunctionScope();
IType thisType = getThisType(scope);
if (thisType instanceof IPointerType) {
try {
IType classType = ((IPointerType) thisType).getType();
thisType = new CPPPointerType(classType, fnDtor.isConst(), fnDtor.isVolatile());
} catch (DOMException e) {
}
} else {
thisType = null;
}
IType type = new CPPFunctionType(returnType, pTypes, (IPointerType) thisType);
IASTDeclarator nested = fnDtor.getNestedDeclarator();
if (nested != null) {
return createType(type, nested);
@ -1726,22 +1738,28 @@ public class CPPVisitor {
try {
IASTNode node = null;
while (scope != null) {
if (scope instanceof ICPPBlockScope) {
if (scope instanceof ICPPBlockScope || scope instanceof ICPPFunctionScope) {
node = ASTInternal.getPhysicalNodeOfScope(scope);
if (node instanceof IASTFunctionDeclarator)
break;
if (node.getParent() instanceof IASTFunctionDefinition)
break;
}
scope = scope.getParent();
}
if (node != null && node.getParent() instanceof IASTFunctionDefinition) {
if (node != null) {
if (node.getParent() instanceof IASTFunctionDefinition) {
IASTFunctionDefinition def = (IASTFunctionDefinition) node.getParent();
IASTName fName = def.getDeclarator().getName();
node = def.getDeclarator();
}
if (node instanceof IASTFunctionDeclarator) {
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) node;
IASTName fName = dtor.getName();
if (fName instanceof ICPPASTQualifiedName) {
IASTName[] ns = ((ICPPASTQualifiedName)fName).getNames();
fName = ns[ns.length - 1];
}
IScope s = getContainingScope(fName);
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) def.getDeclarator();
if (s instanceof ICPPTemplateScope)
s = getParentScope(s, fName.getTranslationUnit());
if (s instanceof ICPPClassScope) {
@ -1756,6 +1774,7 @@ public class CPPVisitor {
return type;
}
}
}
} catch (DOMException e) {
return e.getProblem();
}
@ -1956,11 +1975,26 @@ public class CPPVisitor {
return e.getProblem();
}
} else if (op == IASTUnaryExpression.op_amper) {
if (type instanceof ICPPReferenceType)
if (type instanceof ICPPReferenceType) {
try {
return new CPPPointerType(((ICPPReferenceType)type).getType());
type = ((ICPPReferenceType) type).getType();
} catch (DOMException e) {
}
}
if (type instanceof ICPPFunctionType) {
ICPPFunctionType functionType = (ICPPFunctionType) type;
IPointerType thisType = functionType.getThisType();
if (thisType != null) {
ICPPClassType classType;
try {
classType = (ICPPClassType) thisType.getType();
} catch (DOMException e) {
return e.getProblem();
}
return new CPPPointerToMemberType(type, classType,
thisType.isConst(), thisType.isVolatile());
}
}
return new CPPPointerType(type);
} else if (type instanceof CPPBasicType) {
((CPPBasicType) type).setValue(expression);

View file

@ -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.semantics;
@ -104,8 +105,7 @@ public class Conversions {
if (operatorCost == null) {
operatorCost= cost2;
conv= op;
}
else {
} else {
int cmp= operatorCost.compare(cost2);
if (cmp >= 0) {
ambiguousConversionOperator= cmp == 0;
@ -264,7 +264,7 @@ public class Conversions {
t2= t2 instanceof IQualifierType ? ((IQualifierType)t2).getType() : t2;
if (t1 instanceof ICPPClassType && t2 instanceof ICPPClassType) {
return calculateInheritanceDepth(CPPSemantics.MAX_INHERITANCE_DEPTH, (ICPPClassType) t2, (ICPPClassType) t1) >= 0;
return calculateInheritanceDepth(CPPSemantics.MAX_INHERITANCE_DEPTH, t2, t1) >= 0;
}
return t1 != null && t2 != null ? t1.isSameType(t2) : t1 == t2;
@ -438,16 +438,17 @@ public class Conversions {
* <code>ancestorToFind</code>, returning -1 if no inheritance relationship is found.
* @param clazz the class to search upwards from
* @param ancestorToFind the class to find in the inheritance graph
* @return the number of edges in the inheritance graph, or -1 if the specifide classes have
* @return the number of edges in the inheritance graph, or -1 if the specified classes have
* no inheritance relation
* @throws DOMException
*/
private static final int calculateInheritanceDepth(int maxdepth, ICPPClassType clazz, ICPPClassType ancestorToFind) throws DOMException {
if (clazz == ancestorToFind || clazz.isSameType(ancestorToFind)) {
private static final int calculateInheritanceDepth(int maxdepth, IType type, IType ancestorToFind) throws DOMException {
if (type == ancestorToFind || type.isSameType(ancestorToFind)) {
return 0;
}
if (maxdepth>0) {
if (maxdepth > 0 && type instanceof ICPPClassType && ancestorToFind instanceof ICPPClassType) {
ICPPClassType clazz = (ICPPClassType) type;
ICPPBase[] bases= clazz.getBases();
for (ICPPBase cppBase : bases) {
IBinding base= cppBase.getBaseClass();
@ -455,14 +456,13 @@ public class Conversions {
IType tbase= (IType) base;
if (tbase.isSameType(ancestorToFind) ||
(ancestorToFind instanceof ICPPSpecialization && /*allow some flexibility with templates*/
((IType)((ICPPSpecialization)ancestorToFind).getSpecializedBinding()).isSameType(tbase) ) )
{
((IType)((ICPPSpecialization)ancestorToFind).getSpecializedBinding()).isSameType(tbase))) {
return 1;
}
tbase= getUltimateTypeViaTypedefs(tbase);
if (tbase instanceof ICPPClassType) {
int n= calculateInheritanceDepth(maxdepth-1, (ICPPClassType) tbase, ancestorToFind );
int n= calculateInheritanceDepth(maxdepth-1, tbase, ancestorToFind);
if (n > 0)
return n + 1;
}
@ -501,12 +501,10 @@ public class Conversions {
//4.3 function to pointer conversion
if (target instanceof IPointerType && ((IPointerType)target).getType() instanceof IFunctionType &&
source instanceof IFunctionType )
{
source instanceof IFunctionType) {
source = new CPPPointerType(source);
}
} else if (target instanceof IPointerType && source instanceof IArrayType) {
//4.2 Array-To-Pointer conversion
else if( target instanceof IPointerType && source instanceof IArrayType ){
source = new CPPPointerType(((IArrayType)source).getType());
}
@ -519,8 +517,7 @@ public class Conversions {
source = t;
}
} else if (source instanceof IPointerType &&
( ((IPointerType)source).isConst() || ((IPointerType)source).isVolatile() ) )
{
(((IPointerType)source).isConst() || ((IPointerType)source).isVolatile())) {
IType t= ((IPointerType) source).getType();
while (t instanceof ITypedef)
t= ((ITypedef) t).getType();
@ -585,8 +582,7 @@ public class Conversions {
}
//if cv1,j and cv2,j are different then const is in every cv2,k for 0<k<j
if (!constInEveryCV2k && (op1.isConst() != op2.isConst() ||
op1.isVolatile() != op2.isVolatile() ) )
{
op1.isVolatile() != op2.isVolatile())) {
canConvert = false;
requiredConversion = Cost.NO_MATCH_RANK;
break;
@ -602,8 +598,7 @@ public class Conversions {
if (!constInEveryCV2k) {
canConvert= false;
requiredConversion= Cost.NO_MATCH_RANK;
}
else {
} else {
canConvert = true;
requiredConversion = Cost.CONVERSION_RANK;
}
@ -631,22 +626,21 @@ public class Conversions {
IQualifierType qs = (IQualifierType) s, qt = (IQualifierType) t;
if (qs.isConst() == qt.isConst() && qs.isVolatile() == qt.isVolatile()) {
requiredConversion = Cost.IDENTITY_RANK;
}
else if( (qs.isConst() && !qt.isConst()) || (qs.isVolatile() && !qt.isVolatile()) || !constInEveryCV2k ) {
} else if ((qs.isConst() && !qt.isConst()) || (qs.isVolatile() && !qt.isVolatile()) || !constInEveryCV2k) {
requiredConversion = Cost.NO_MATCH_RANK;
canConvert= false;
}
else
} else {
requiredConversion = Cost.CONVERSION_RANK;
}
} else if (constInEveryCV2k && !canConvert) {
canConvert = true;
requiredConversion = Cost.CONVERSION_RANK;
int i = 1;
for (IType type = s; canConvert == true && i == 1; type = t, i++) {
while (type instanceof ITypeContainer) {
if( type instanceof IQualifierType )
if (type instanceof IQualifierType) {
canConvert = false;
else if( type instanceof IPointerType ){
} else if (type instanceof IPointerType) {
canConvert = !((IPointerType)type).isConst() && !((IPointerType)type).isVolatile();
}
if (!canConvert) {
@ -691,14 +685,12 @@ public class Conversions {
sType == ICPPBasicType.t_bool ||
sType == ICPPBasicType.t_wchar_t ||
sType == IBasicType.t_unspecified)) || //treat unspecified as int
( tType == IBasicType.t_double && sType == IBasicType.t_float ) )
{
(tType == IBasicType.t_double && sType == IBasicType.t_float)) {
cost.promotion = 1;
}
} else if (src instanceof IEnumeration && trg instanceof IBasicType &&
(((IBasicType)trg).getType() == IBasicType.t_int ||
((IBasicType)trg).getType() == IBasicType.t_unspecified ) )
{
((IBasicType)trg).getType() == IBasicType.t_unspecified)) {
cost.promotion = 1;
}
@ -730,8 +722,7 @@ public class Conversions {
//4.10-1 an integral constant expression of integer type that evaluates to 0 can be converted to a pointer type
IASTExpression exp = ((IBasicType)src).getValue();
if (exp instanceof IASTLiteralExpression &&
((IASTLiteralExpression)exp).getKind() == IASTLiteralExpression.lk_integer_constant )
{
((IASTLiteralExpression)exp).getKind() == IASTLiteralExpression.lk_integer_constant) {
try {
String val = exp.toString().toLowerCase().replace('u', '0');
val.replace('l', '0');
@ -754,7 +745,7 @@ public class Conversions {
//4.10-3 An rvalue of type "pointer to cv D", where D is a class type can be converted
//to an rvalue of type "pointer to cv B", where B is a base class of D.
else if (s instanceof ICPPClassType && tPrev instanceof IPointerType && t instanceof ICPPClassType) {
int depth= calculateInheritanceDepth(CPPSemantics.MAX_INHERITANCE_DEPTH, (ICPPClassType)s, (ICPPClassType) t );
int depth= calculateInheritanceDepth(CPPSemantics.MAX_INHERITANCE_DEPTH, s, t);
cost.rank= (depth > -1) ? Cost.CONVERSION_RANK : Cost.NO_MATCH_RANK;
cost.conversion= (depth > -1) ? depth : 0;
cost.detail= 1;
@ -802,7 +793,7 @@ public class Conversions {
IType t = getUltimateType(cost.target, true);
if (cost.targetHadReference && s instanceof ICPPClassType && t instanceof ICPPClassType) {
int depth= calculateInheritanceDepth(CPPSemantics.MAX_INHERITANCE_DEPTH, (ICPPClassType) s, (ICPPClassType) t);
int depth= calculateInheritanceDepth(CPPSemantics.MAX_INHERITANCE_DEPTH, s, t);
if (depth > -1) {
cost.rank = Cost.DERIVED_TO_BASE_CONVERSION;
cost.conversion = depth;
@ -841,8 +832,7 @@ public class Conversions {
IType t = getUltimateType(cost.target, false);
if ((s instanceof ICPPTemplateTypeParameter && t instanceof ICPPTemplateTypeParameter) ||
(s instanceof ICPPTemplateTemplateParameter && t instanceof ICPPTemplateTemplateParameter ) )
{
(s instanceof ICPPTemplateTemplateParameter && t instanceof ICPPTemplateTemplateParameter)) {
cost.rank = Cost.FUZZY_TEMPLATE_PARAMETERS;
}
}

View file

@ -109,25 +109,28 @@ class LookupData {
considerConstructors = considerConstructors();
checkWholeClassScope = checkWholeClassScope();
}
public LookupData() {
astName = null;
}
public final char[] name () {
if (astName != null)
return astName.toCharArray();
return CPPSemantics.EMPTY_NAME_ARRAY;
}
public boolean includeBlockItem(IASTNode item) {
if (astName.getPropertyInParent() == CPPSemantics.STRING_LOOKUP_PROPERTY) return true;
if ((astName != null && astName.getParent() instanceof IASTIdExpression) ||
item instanceof ICPPASTNamespaceDefinition ||
(item instanceof IASTSimpleDeclaration && ((IASTSimpleDeclaration)item).getDeclSpecifier() instanceof IASTCompositeTypeSpecifier) ||
item instanceof ICPPASTTemplateDeclaration )
{
item instanceof ICPPASTTemplateDeclaration) {
return true;
}
return false;
}
private boolean typesOnly() {
if (astName == null) return false;
if (astName.getPropertyInParent() == CPPSemantics.STRING_LOOKUP_PROPERTY) return false;
@ -141,6 +144,7 @@ class LookupData {
}
return false;
}
public boolean forUsingDeclaration() {
if (astName == null) return false;
if (astName.getPropertyInParent() == CPPSemantics.STRING_LOOKUP_PROPERTY) return false;
@ -157,6 +161,7 @@ class LookupData {
}
return false;
}
public boolean forDefinition() {
if (astName == null) return false;
if (astName.getPropertyInParent() == CPPSemantics.STRING_LOOKUP_PROPERTY) return false;
@ -207,9 +212,9 @@ class LookupData {
if (p1 instanceof ICPPASTConstructorChainInitializer)
return true;
if( p1 instanceof ICPPASTNamedTypeSpecifier && p2 instanceof IASTTypeId )
if (p1 instanceof ICPPASTNamedTypeSpecifier && p2 instanceof IASTTypeId) {
return p2.getParent() instanceof ICPPASTNewExpression;
else if( p1 instanceof ICPPASTQualifiedName ){
} else if (p1 instanceof ICPPASTQualifiedName) {
if (p2 instanceof ICPPASTFunctionDeclarator) {
IASTName[] names = ((ICPPASTQualifiedName)p1).getNames();
if (names.length >= 2 && names[names.length - 1] == astName)
@ -220,10 +225,12 @@ class LookupData {
} else if (p2 instanceof IASTIdExpression) {
return p2.getParent() instanceof IASTFunctionCallExpression;
}
} else if( p1 instanceof IASTFunctionCallExpression || p2 instanceof IASTFunctionCallExpression )
} else if (p1 instanceof IASTFunctionCallExpression || p2 instanceof IASTFunctionCallExpression) {
return true;
}
return false;
}
public boolean qualified() {
if (forceQualified) return true;
if (astName == null) return false;
@ -235,6 +242,7 @@ class LookupData {
}
return p1 instanceof ICPPASTFieldReference;
}
public boolean functionCall() {
if (astName == null) return false;
if (astName.getPropertyInParent() == CPPSemantics.STRING_LOOKUP_PROPERTY) return false;
@ -243,6 +251,7 @@ class LookupData {
p1 = p1.getParent();
return (p1 instanceof IASTIdExpression && p1.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME);
}
private boolean checkWholeClassScope() {
if (astName == null) return false;
if (astName.getPropertyInParent() == CPPSemantics.STRING_LOOKUP_PROPERTY) return true;
@ -267,8 +276,7 @@ class LookupData {
prop == ICPPASTUsingDeclaration.NAME ||
prop == IASTFunctionCallExpression.FUNCTION_NAME ||
prop == IASTNamedTypeSpecifier.NAME ||
prop == ICPPASTConstructorChainInitializer.MEMBER_ID )
{
prop == ICPPASTConstructorChainInitializer.MEMBER_ID) {
return true;
}
}
@ -284,8 +292,9 @@ class LookupData {
return ((CharArrayObjectMap)foundItems).size() != 0;
return false;
}
/**
* an IType[] of function arguments, inluding the implied object argument
* an IType[] of function arguments, including the implied object argument
*/
public IType getImpliedObjectArgument() {
IType implied = null;
@ -301,12 +310,12 @@ class LookupData {
IASTExpression oprd= unaryExp.getOperand();
return CPPVisitor.getExpressionType(oprd);
} else if (prop == IASTFieldReference.FIELD_NAME ||
(prop == CPPSemantics.STRING_LOOKUP_PROPERTY && tempName.getParent() instanceof ICPPASTFieldReference) )
{
(prop == CPPSemantics.STRING_LOOKUP_PROPERTY && tempName.getParent() instanceof ICPPASTFieldReference)) {
ICPPASTFieldReference fieldRef = (ICPPASTFieldReference) tempName.getParent();
implied = CPPVisitor.getExpressionType(fieldRef.getFieldOwner());
IType ultimateImplied= SemanticUtil.getUltimateTypeUptoPointers(implied);
if( prop != CPPSemantics.STRING_LOOKUP_PROPERTY && fieldRef.isPointerDereference() && ultimateImplied instanceof ICPPClassType) {
if (prop != CPPSemantics.STRING_LOOKUP_PROPERTY && fieldRef.isPointerDereference() &&
ultimateImplied instanceof ICPPClassType) {
ICPPFunction operator= CPPSemantics.findOperator(fieldRef, (ICPPClassType) ultimateImplied);
try {
if (operator!=null) {
@ -343,6 +352,7 @@ class LookupData {
}
return implied;
}
public boolean forFriendship() {
if (astName == null)
return false;
@ -391,6 +401,7 @@ class LookupData {
}
return functionCall() && (associated.size() > 0);
}
public boolean checkClassContainingFriend() {
if (astName == null || astName instanceof ICPPASTQualifiedName)
return false;
@ -420,6 +431,7 @@ class LookupData {
}
return false;
}
public boolean preferTemplateFunctions() {
if (astName == null)
return false;

View file

@ -240,8 +240,7 @@ public class SemanticUtil {
if (ret == r && params == ps) {
return type;
}
return new CPPFunctionType(ret, params, ((ICPPFunctionType) type).isConst(),
((ICPPFunctionType) type).isVolatile());
return new CPPFunctionType(ret, params, ((ICPPFunctionType) type).getThisType());
}
if (type instanceof ITypeContainer) {

View file

@ -26,18 +26,22 @@ public class PointerTypeClone implements IPointerType, ITypeContainer, IIndexTyp
public PointerTypeClone(IPointerType pointer) {
this.delegate = pointer;
}
public IType getType() throws DOMException {
if (type == null) {
return delegate.getType();
}
return type;
}
public boolean isConst() throws DOMException {
public boolean isConst() {
return delegate.isConst();
}
public boolean isVolatile() throws DOMException {
public boolean isVolatile() {
return delegate.isVolatile();
}
public boolean isSameType(IType type) {
if (type instanceof ITypedef)
return ((ITypedef)type).isSameType(this);
@ -57,9 +61,11 @@ public class PointerTypeClone implements IPointerType, ITypeContainer, IIndexTyp
}
return false;
}
public void setType(IType type) {
this.type = type;
}
@Override
public Object clone() {
return new PointerTypeClone(this);

View file

@ -21,11 +21,11 @@ public class CompositePointerType extends CompositeTypeContainer implements IPoi
super((ITypeContainer) pointerType, cf);
}
public boolean isConst() throws DOMException {
public boolean isConst() {
return ((IPointerType) type).isConst();
}
public boolean isVolatile() throws DOMException {
public boolean isVolatile() {
return ((IPointerType) type).isVolatile();
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 Symbian Software Systems and others.
* Copyright (c) 2007, 2008 Symbian Software Systems 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
@ -7,20 +7,26 @@
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.internal.core.index.composite.CompositeFunctionType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
public class CompositeCPPFunctionType extends CompositeFunctionType implements ICPPFunctionType {
public CompositeCPPFunctionType(ICPPFunctionType rtype,
ICompositesFactory cf) {
public CompositeCPPFunctionType(ICPPFunctionType rtype, ICompositesFactory cf) {
super(rtype, cf);
}
public IPointerType getThisType() {
return ((ICPPFunctionType) type).getThisType();
}
public boolean isConst() {
return ((ICPPFunctionType) type).isConst();
}

View file

@ -74,7 +74,6 @@ public class PDOMCFunctionType extends PDOMNode implements IIndexType, IFunction
list.addMember(typeNode);
}
} catch(DOMException de) {
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 Symbian Software Systems and others.
* Copyright (c) 2007, 2008 Symbian Software Systems 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
@ -7,25 +7,27 @@
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial Implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCAnnotation;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCFunctionType;
import org.eclipse.core.runtime.CoreException;
public class PDOMCPPFunctionType extends PDOMCFunctionType implements ICPPFunctionType {
/**
* Offset for return type of this function (relative to
* Offset for <code>this</code> type of this function (relative to
* the beginning of the record).
*/
private static final int FLAGS= PDOMCFunctionType.RECORD_SIZE;
private static final int THIS_TYPE= PDOMCFunctionType.RECORD_SIZE;
/**
* The size in bytes of a PDOMCFunctionType record in the database.
@ -33,6 +35,8 @@ public class PDOMCPPFunctionType extends PDOMCFunctionType implements ICPPFuncti
@SuppressWarnings("hiding")
private static final int RECORD_SIZE= PDOMCFunctionType.RECORD_SIZE + 4;
IPointerType thisType; // Cached value
protected PDOMCPPFunctionType(PDOM pdom, int offset) {
super(pdom, offset);
}
@ -40,16 +44,36 @@ public class PDOMCPPFunctionType extends PDOMCFunctionType implements ICPPFuncti
protected PDOMCPPFunctionType(PDOM pdom, PDOMNode parent, ICPPFunctionType type)
throws CoreException {
super(pdom, parent, type);
int modifiers= PDOMCAnnotation.encodeCVQualifiers(type);
pdom.getDB().putInt(getRecord()+FLAGS, modifiers);
setThisType(type.getThisType());
}
public boolean isConst() {
return getBit(getInt(record + FLAGS), PDOMCAnnotation.CONST_OFFSET);
private void setThisType(IPointerType type) throws CoreException {
PDOMNode typeNode = getLinkageImpl().addType(this, type);
if (typeNode != null) {
pdom.getDB().putInt(record + THIS_TYPE, typeNode.getRecord());
}
}
public boolean isVolatile() {
return getBit(getInt(record + FLAGS), PDOMCAnnotation.VOLATILE_OFFSET);
public IPointerType getThisType() {
if (thisType == null) {
try {
PDOMNode node = getLinkageImpl().getNode(pdom.getDB().getInt(record + THIS_TYPE));
if (node instanceof IPointerType) {
thisType = (IPointerType) node;
}
} catch (CoreException e) {
CCorePlugin.log(e);
}
}
return thisType;
}
public final boolean isConst() {
return getThisType() != null && getThisType().isConst();
}
public final boolean isVolatile() {
return getThisType() != null && getThisType().isVolatile();
}
@Override
@ -62,8 +86,9 @@ public class PDOMCPPFunctionType extends PDOMCFunctionType implements ICPPFuncti
if (type instanceof ICPPFunctionType) {
if (super.isSameType(type)) {
ICPPFunctionType ft= (ICPPFunctionType) type;
if( isConst() != ft.isConst() || isVolatile() != ft.isVolatile() )
if (isConst() != ft.isConst() || isVolatile() != ft.isVolatile()) {
return false;
}
return true;
}
}

View file

@ -13,6 +13,7 @@
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
@ -39,7 +40,7 @@ class PDOMCPPPointerToMemberType extends PDOMPointerType implements ICPPPointerT
Database db = pdom.getDB();
// type
ICPPClassType ct = type.getMemberOfClass();
IType ct = type.getMemberOfClass();
int typeRec = 0;
if (ct != null) {
PDOMNode targetTypeNode = getLinkageImpl().addType(this, ct);
@ -81,7 +82,7 @@ class PDOMCPPPointerToMemberType extends PDOMPointerType implements ICPPPointerT
public PDOMCPPPointerToMemberTypeClone(ICPPPointerToMemberType pointer) {
super(pointer);
}
public ICPPClassType getMemberOfClass() {
public IType getMemberOfClass() {
return ((ICPPPointerToMemberType) delegate).getMemberOfClass();
}
@Override