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

Follow up for 184500, fixes a ClassCastException.

This commit is contained in:
Markus Schorn 2007-05-04 08:01:48 +00:00
parent 39e4ee536e
commit c7548e8313
7 changed files with 40 additions and 85 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 2007 Wind River Systems, Inc. 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
@ -15,8 +15,10 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction;
/**
* Access to methods on scopes and bindings internal to the parser.
@ -75,4 +77,11 @@ public class ASTInternal {
((IASTInternalScope) scope).addName(name);
}
}
public static boolean isStatic(IFunction func, boolean resolveAll) throws DOMException {
if (func instanceof ICPPInternalFunction) {
return ((ICPPInternalFunction)func).isStatic(resolveAll);
}
return func.isStatic();
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* Copyright (c) 2005, 2007 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,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
/*
* Created on Apr 14, 2005
@ -17,6 +18,7 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope;
@ -29,6 +31,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
/**
* @author aniefer
@ -173,7 +176,11 @@ public class CPPDeferredFunctionInstance extends CPPInstance implements ICPPFunc
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean)
*/
public boolean isStatic( boolean resolveAll ) {
return ((ICPPInternalFunction)getTemplateDefinition()).isStatic( resolveAll );
try {
return ASTInternal.isStatic((IFunction) getTemplateDefinition(), resolveAll);
} catch (DOMException e) {
return false;
}
}
/* (non-Javadoc)

View file

@ -27,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope;
@ -85,7 +86,11 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
return ((ICPPFunction)getBinding()).takesVarArgs();
}
public boolean isStatic( boolean resolveAll ) {
return ((ICPPInternalFunction)getBinding()).isStatic( resolveAll );
try {
return ASTInternal.isStatic((IFunction) getBinding(), resolveAll);
} catch (DOMException e) {
return false;
}
}
public IBinding resolveParameter( IASTParameterDeclaration param ) {
return ((ICPPInternalFunction)getBinding()).resolveParameter( param );

View file

@ -7,6 +7,7 @@
*
* Contributors:
* IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
/*
* Created on Mar 29, 2005
@ -29,6 +30,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
/**
* @author aniefer
@ -140,15 +142,11 @@ public class CPPFunctionInstance extends CPPInstance implements ICPPFunction, IC
*/
public boolean isStatic( boolean resolveAll ) {
ICPPFunction func = (ICPPFunction) getTemplateDefinition();
if (func instanceof ICPPInternalFunction) {
return ((ICPPInternalFunction)getTemplateDefinition()).isStatic( resolveAll );
} else {
try {
return func.isStatic();
} catch (DOMException e) {
return false;
}
}
try {
return ASTInternal.isStatic(func, resolveAll);
} catch (DOMException e) {
return false;
}
}
/* (non-Javadoc)

View file

@ -1336,7 +1336,7 @@ public class CPPSemantics {
}
//it is not ambiguous if they are the same thing and it is static or an enumerator
if( binding instanceof IEnumerator ||
(binding instanceof IFunction && ((ICPPInternalFunction)binding).isStatic( false )) ||
(binding instanceof IFunction && ASTInternal.isStatic((IFunction) binding, false)) ||
(binding instanceof IVariable && ((IVariable)binding).isStatic()) )
{
ok = true;
@ -2367,11 +2367,7 @@ public class CPPSemantics {
} else
varArgs = true;
if( useImplicitObj && j == 0 &&
(currFn instanceof ICPPInternalFunction
? ((ICPPInternalFunction)currFn).isStatic(false)
: currFn.isStatic())
) {
if( useImplicitObj && j == 0 && ASTInternal.isStatic(currFn, false)) {
//13.3.1-4 for static member functions, the implicit object parameter is considered to match any object
cost = new Cost( source, target );
cost.rank = Cost.IDENTITY_RANK; //exact match, no cost

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006 IBM Corporation.
* Copyright (c) 2006, 2007 IBM Corporation.
* 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,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.c;
@ -16,7 +17,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
/**
* A utility class for packing various annotations into bit fields. This
@ -59,8 +60,7 @@ public class PDOMCAnnotation {
modifiers |= (function.isAuto() ? 1 : 0) << PDOMCAnnotation.AUTO_OFFSET;
modifiers |= (function.isExtern() ? 1 : 0) << PDOMCAnnotation.EXTERN_OFFSET;
modifiers |= (function.isRegister() ? 1 : 0) << PDOMCAnnotation.REGISTER_OFFSET;
if (binding instanceof ICPPInternalFunction)
modifiers |= (((ICPPInternalFunction)function).isStatic(false) ? 1 : 0) << PDOMCAnnotation.STATIC_OFFSET;
modifiers |= (ASTInternal.isStatic(function, false) ? 1 : 0) << PDOMCAnnotation.STATIC_OFFSET;
modifiers |= (function.isInline() ? 1 : 0) << PDOMCAnnotation.INLINE_OFFSET;
modifiers |= (function.takesVarArgs() ? 1 : 0) << PDOMCAnnotation.VARARGS_OFFSET;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2006 QNX Software Systems and others.
* Copyright (c) 2005, 2007 QNX 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
@ -16,21 +16,13 @@ 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.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPParameter;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction;
import org.eclipse.cdt.internal.core.index.IndexCPPSignatureUtil;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.Database;
@ -45,8 +37,7 @@ import org.eclipse.core.runtime.CoreException;
* @author Doug Schaefer
*
*/
class PDOMCPPFunction extends PDOMCPPBinding
implements ICPPFunction, ICPPInternalFunction, IPDOMOverloader {
class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverloader {
/**
* Offset of total number of function parameters (relative to the
@ -242,55 +233,4 @@ class PDOMCPPFunction extends PDOMCPPBinding
}
return 0;
}
// Internal binding stuff, not implemented/needed
public void addDeclaration(IASTNode node) {
// Do nothing
}
public void addDefinition(IASTNode node) {
// Do nothing
}
public ICPPDelegate createDelegate(IASTName name) {
throw new PDOMNotImplementedError(getClass().toString());
}
public IASTNode[] getDeclarations() {
return null;
}
public IASTNode getDefinition() {
return null;
}
public void removeDeclaration(IASTNode node) {
// Do nothing
}
// ICPPInternalFunction
public boolean isStatic(boolean resolveAll) {
try {
return isStatic();
} catch (DOMException e) {
return false;
}
}
public IBinding resolveParameter(IASTParameterDeclaration param) {
try {
for (PDOMCPPParameter pp = getFirstParameter(); pp != null; pp = pp.getNextParameter()) {
if (CharArrayUtils.equals(param.getDeclarator().getName().toCharArray(),
pp.getNameCharArray()))
return pp;
}
} catch (CoreException e) {
CCorePlugin.log(e);
}
// TODO - this points to a problem with overloads, I think...
return new CPPParameter(param.getDeclarator().getName());
}
}