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

Fix for bug 232086.

This commit is contained in:
Sergey Prigogin 2008-05-19 07:54:36 +00:00
parent 35a78ba53d
commit 100c6ff5d2
4 changed files with 57 additions and 42 deletions

View file

@ -2082,7 +2082,7 @@ public class AST2TemplateTests extends AST2BaseTest {
// void f(C<char>& str) {
// str.m();
// }
public void _testBug232086() throws Exception {
public void testBug232086() throws Exception {
BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true);
ICPPFunction b0 = bh.assertNonProblem("m();", 1, ICPPFunction.class);
}

View file

@ -33,55 +33,58 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
*/
public class CPPBaseClause implements ICPPBase, ICPPInternalBase {
static public class CPPBaseProblem extends ProblemBinding implements ICPPBase, ICPPInternalBase {
private ICPPClassType classProblem = null;
public CPPBaseProblem( IASTNode node, int id, char[] arg ) {
super( node, id, arg );
private ICPPClassType classProblem;
public CPPBaseProblem(IASTNode node, int id, char[] arg) {
super(node, id, arg);
}
public IBinding getBaseClass() {
if( classProblem == null ){
classProblem = new CPPClassType.CPPClassTypeProblem( node, id, arg );
if (classProblem == null) {
classProblem = new CPPClassType.CPPClassTypeProblem(node, id, arg);
}
return classProblem;
}
public int getVisibility() throws DOMException {
throw new DOMException( this );
throw new DOMException(this);
}
public boolean isVirtual() throws DOMException {
throw new DOMException( this );
throw new DOMException(this);
}
public IName getBaseClassSpecifierName() {
return (IName) node;
}
public void setBaseClass(IBinding binding) throws DOMException {
throw new DOMException( this );
throw new DOMException(this);
}
}
private ICPPASTBaseSpecifier base = null;
private IBinding baseClass = null;
private ICPPASTBaseSpecifier base;
private IBinding baseClass;
public CPPBaseClause( ICPPASTBaseSpecifier base ){
public CPPBaseClause(ICPPASTBaseSpecifier base) {
this.base = base;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBase#getBaseClass()
*/
public IBinding getBaseClass() throws DOMException {
if( baseClass == null ){
if (baseClass == null) {
IBinding b = base.getName().resolveBinding();
while( b instanceof ITypedef && ((ITypedef)b).getType() instanceof IBinding ){
b = (IBinding) ((ITypedef)b).getType();
while (b instanceof ITypedef && ((ITypedef) b).getType() instanceof IBinding) {
b = (IBinding) ((ITypedef) b).getType();
}
if( b instanceof ICPPClassType || b instanceof ICPPTemplateParameter )
if (b instanceof ICPPClassType || b instanceof ICPPTemplateParameter) {
baseClass = b;
else if( b instanceof IProblemBinding ){
baseClass = new CPPClassType.CPPClassTypeProblem( base.getName(), ((IProblemBinding)b).getID(), base.getName().toCharArray() );
} else if (b instanceof IProblemBinding) {
baseClass = new CPPClassType.CPPClassTypeProblem(base.getName(), ((IProblemBinding) b).getID(), base.getName().toCharArray());
} else {
baseClass = new CPPClassType.CPPClassTypeProblem( base.getName(), IProblemBinding.SEMANTIC_NAME_NOT_FOUND, base.getName().toCharArray() );
baseClass = new CPPClassType.CPPClassTypeProblem(base.getName(), IProblemBinding.SEMANTIC_NAME_NOT_FOUND, base.getName().toCharArray());
}
}
return baseClass;
@ -93,10 +96,10 @@ public class CPPBaseClause implements ICPPBase, ICPPInternalBase {
public int getVisibility() {
int vis = base.getVisibility();
if( vis == 0 ){
if (vis == 0) {
ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) base.getParent();
int key = compSpec.getKey();
if( key == ICPPClassType.k_class )
if (key == ICPPClassType.k_class)
vis = ICPPBase.v_private;
else
vis = ICPPBase.v_public;
@ -120,11 +123,11 @@ public class CPPBaseClause implements ICPPBase, ICPPInternalBase {
}
@Override
public Object clone(){
public Object clone() {
ICPPBase t = null;
try {
t = (ICPPBase) super.clone();
} catch ( CloneNotSupportedException e ) {
} catch (CloneNotSupportedException e) {
//not going to happen
}
return t;

View file

@ -8,10 +8,12 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
@ -36,6 +38,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
/**
* @author aniefer
@ -43,9 +46,9 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
public class CPPTemplateTemplateParameter extends CPPTemplateParameter implements
ICPPTemplateTemplateParameter, ICPPClassType, ICPPInternalTemplate, ICPPUnknownBinding {
private ICPPTemplateParameter[] templateParameters = null;
private ObjectMap instances = null;
private ICPPScope unknownScope = null;
private ICPPTemplateParameter[] templateParameters;
private ObjectMap instances;
private ICPPScope unknownScope;
/**
* @param name
@ -65,7 +68,6 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement
return unknownScope;
}
public ICPPTemplateParameter[] getTemplateParameters() {
if (templateParameters == null) {
ICPPASTTemplatedTypeTemplateParameter template = (ICPPASTTemplatedTypeTemplateParameter) getPrimaryDeclaration().getParent();
@ -90,7 +92,6 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement
return templateParameters;
}
public IBinding resolveTemplateParameter(ICPPASTTemplateParameter templateParameter) {
IASTName name = CPPTemplates.getTemplateParameterName(templateParameter);
@ -108,12 +109,19 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement
return binding;
}
public ICPPClassTemplatePartialSpecialization[] getTemplateSpecializations() throws DOMException {
return ICPPClassTemplatePartialSpecialization.EMPTY_PARTIAL_SPECIALIZATION_ARRAY;
}
public IType getDefault() throws DOMException {
IASTNode[] nds = getDeclarations();
if (nds == null || nds.length == 0)
return null;
IASTName name = (IASTName) nds[0];
ICPPASTTemplatedTypeTemplateParameter param = (ICPPASTTemplatedTypeTemplateParameter) name.getParent();
IASTExpression defaultValue = param.getDefaultValue();
if (defaultValue != null)
return CPPVisitor.createType(defaultValue);
return null;
}

View file

@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
* Andrew Ferguson (Symbian)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
@ -725,6 +726,7 @@ public class CPPVisitor {
}
return isConstructor(clsName, declarator);
}
public static boolean isConstructor(IASTName parentName, IASTDeclarator declarator) {
if (declarator == null || !(declarator instanceof IASTFunctionDeclarator))
return false;
@ -1607,6 +1609,7 @@ public class CPPVisitor {
}
return type;
}
private static IType getArrayTypes(IType type, IASTArrayDeclarator declarator) {
IASTArrayModifier[] mods = declarator.getArrayModifiers();
for (IASTArrayModifier mod : mods) {
@ -1766,20 +1769,21 @@ public class CPPVisitor {
IBinding binding = resolveBinding(expression);
try {
if (binding instanceof IVariable) {
return ((IVariable)binding).getType();
return ((IVariable) binding).getType();
} else if (binding instanceof IEnumerator) {
return ((IEnumerator)binding).getType();
return ((IEnumerator) binding).getType();
} else if (binding instanceof IProblemBinding) {
return (IType) binding;
} else if (binding instanceof IFunction) {
return ((IFunction)binding).getType();
return ((IFunction) binding).getType();
} else if (binding instanceof ICPPTemplateNonTypeParameter) {
return ((ICPPTemplateNonTypeParameter)binding).getType();
return ((ICPPTemplateNonTypeParameter) binding).getType();
} else if (binding instanceof ICPPClassType) {
return ((ICPPClassType) binding);
}
} catch (DOMException e) {
return e.getProblem();
}
} else if (expression instanceof IASTCastExpression) {
IASTTypeId id = ((IASTCastExpression)expression).getTypeId();
IType type = createType(id.getDeclSpecifier());
@ -2198,22 +2202,22 @@ public class CPPVisitor {
* @return whether the specified expression is an rvalue
*/
static boolean isRValue(IASTExpression exp) {
if(exp instanceof IASTUnaryExpression) {
if (exp instanceof IASTUnaryExpression) {
IASTUnaryExpression ue= (IASTUnaryExpression) exp;
if(ue.getOperator() == IASTUnaryExpression.op_amper) {
if (ue.getOperator() == IASTUnaryExpression.op_amper) {
return true;
}
}
if(exp instanceof IASTLiteralExpression)
if (exp instanceof IASTLiteralExpression)
return true;
if(exp instanceof IASTFunctionCallExpression) {
if (exp instanceof IASTFunctionCallExpression) {
try {
IASTFunctionCallExpression fc= (IASTFunctionCallExpression) exp;
IASTExpression fne= fc.getFunctionNameExpression();
if(fne instanceof IASTIdExpression) {
if (fne instanceof IASTIdExpression) {
IASTIdExpression ide= (IASTIdExpression) fne;
IBinding b= ide.getName().resolveBinding();
if(b instanceof IFunction) {
if (b instanceof IFunction) {
IFunctionType tp= ((IFunction)b).getType();
return !(tp.getReturnType() instanceof ICPPReferenceType);
}