mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 06:45:43 +02:00
Bug 332114: Exceptions when parsing gcc-testsuite.
This commit is contained in:
parent
1fcecce140
commit
b81cf7e199
15 changed files with 122 additions and 54 deletions
|
@ -129,6 +129,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
import org.eclipse.cdt.internal.core.index.IndexCPPSignatureUtil;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
|
||||
public class AST2CPPTests extends AST2BaseTest {
|
||||
|
@ -9290,4 +9291,19 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
parseAndCheckBindings();
|
||||
}
|
||||
|
||||
// auto f2 (); // missing late return type.
|
||||
public void testBug332114a() throws Exception {
|
||||
BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true);
|
||||
IBinding b= bh.assertNonProblem("f2", 0);
|
||||
// Must not throw a NPE
|
||||
IndexCPPSignatureUtil.getSignature(b);
|
||||
}
|
||||
|
||||
// enum E: short;
|
||||
// enum E: short;
|
||||
// enum E: short {e1, e2};
|
||||
public void testBug332114b() throws Exception {
|
||||
parseAndCheckBindings();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,8 +26,8 @@ import org.eclipse.cdt.core.dom.ast.IField;
|
|||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IPointerType;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.ISemanticProblem;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
|
@ -1208,7 +1208,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas
|
|||
ITypedef td= getBindingFromASTName("MBR_PTR", 0, ITypedef.class);
|
||||
ICPPPointerToMemberType ptrMbr= (ICPPPointerToMemberType) td.getType();
|
||||
IType t= ptrMbr.getMemberOfClass();
|
||||
assertInstance(t, IProblemBinding.class);
|
||||
assertInstance(t, ISemanticProblem.class);
|
||||
}
|
||||
|
||||
// void f255(
|
||||
|
|
|
@ -84,8 +84,16 @@ public abstract class ArithmeticConversion {
|
|||
}
|
||||
|
||||
private boolean isArithmeticOrUnscopedEnum(IType op1) {
|
||||
if (op1 instanceof IBasicType)
|
||||
return true;
|
||||
if (op1 instanceof IBasicType) {
|
||||
final Kind kind = ((IBasicType)op1).getKind();
|
||||
switch (kind) {
|
||||
case eUnspecified:
|
||||
case eVoid:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (op1 instanceof IEnumeration) {
|
||||
if (op1 instanceof ICPPEnumeration && ((ICPPEnumeration) op1).isScoped())
|
||||
return false;
|
||||
|
|
|
@ -54,6 +54,7 @@ public class CPPASTAmbiguousParameterDeclaration extends ASTAmbiguousNode implem
|
|||
|
||||
// Setup the ast to use the alternative
|
||||
owner.replace(this, fParameterDecl);
|
||||
fParameterDecl.accept(resolver);
|
||||
|
||||
IType t= CPPVisitor.createType(fParameterDecl, true);
|
||||
if (!(t instanceof ICPPParameterPackType) ||
|
||||
|
|
|
@ -220,6 +220,8 @@ public class CPPASTUnaryExpression extends ASTNode implements ICPPASTUnaryExpres
|
|||
return CPPVisitor.get_type_info(this);
|
||||
case op_bracketedPrimary:
|
||||
return getOperand().getExpressionType();
|
||||
case op_throw:
|
||||
return CPPSemantics.VOID_TYPE;
|
||||
}
|
||||
|
||||
final IASTExpression operand = getOperand();
|
||||
|
|
|
@ -80,8 +80,6 @@ public class CPPEnumeration extends PlatformObject implements ICPPEnumeration, I
|
|||
|
||||
private class FindDefinitionAction extends ASTVisitor {
|
||||
private char[] nameArray = CPPEnumeration.this.getNameCharArray();
|
||||
public IASTName result = null;
|
||||
|
||||
{
|
||||
shouldVisitNames = true;
|
||||
shouldVisitDeclarations = true;
|
||||
|
@ -94,10 +92,12 @@ public class CPPEnumeration extends PlatformObject implements ICPPEnumeration, I
|
|||
if (name instanceof ICPPASTTemplateId || name instanceof ICPPASTQualifiedName)
|
||||
return PROCESS_SKIP;
|
||||
char[] c = name.getLookupKey();
|
||||
if (name.getParent() instanceof ICPPASTEnumerationSpecifier && CharArrayUtils.equals(c, nameArray)) {
|
||||
final IASTNode parent = name.getParent();
|
||||
if (parent instanceof ICPPASTEnumerationSpecifier &&
|
||||
!((ICPPASTEnumerationSpecifier) parent).isOpaque() &&
|
||||
CharArrayUtils.equals(c, nameArray)) {
|
||||
IBinding binding = name.resolveBinding();
|
||||
if (binding == CPPEnumeration.this) {
|
||||
result= name;
|
||||
if (binding == CPPEnumeration.this && getDefinition() == name) {
|
||||
return PROCESS_ABORT;
|
||||
}
|
||||
}
|
||||
|
@ -121,12 +121,8 @@ public class CPPEnumeration extends PlatformObject implements ICPPEnumeration, I
|
|||
}
|
||||
|
||||
public IASTName getDefinition() {
|
||||
if (fDefinition == NOT_INITIALIZED) {
|
||||
FindDefinitionAction action = new FindDefinitionAction();
|
||||
IASTNode node = CPPVisitor.getContainingBlockItem(getADeclaration()).getParent();
|
||||
node.accept(action);
|
||||
fDefinition = action.result;
|
||||
}
|
||||
if (fDefinition == NOT_INITIALIZED)
|
||||
return null;
|
||||
return fDefinition;
|
||||
}
|
||||
|
||||
|
@ -259,6 +255,7 @@ public class CPPEnumeration extends PlatformObject implements ICPPEnumeration, I
|
|||
}
|
||||
|
||||
public IEnumerator[] getEnumerators() {
|
||||
findDefinition();
|
||||
final IASTName definition = getDefinition();
|
||||
if (definition == null) {
|
||||
ICPPEnumeration typeInIndex= getIndexBinding();
|
||||
|
@ -291,6 +288,7 @@ public class CPPEnumeration extends PlatformObject implements ICPPEnumeration, I
|
|||
}
|
||||
|
||||
public ICPPScope asScope() {
|
||||
findDefinition();
|
||||
IASTName def = getDefinition();
|
||||
if (def == null) {
|
||||
ICPPEnumeration indexBinding= getIndexBinding();
|
||||
|
@ -301,4 +299,12 @@ public class CPPEnumeration extends PlatformObject implements ICPPEnumeration, I
|
|||
}
|
||||
return ((ICPPASTEnumerationSpecifier) def.getParent()).getScope();
|
||||
}
|
||||
|
||||
private void findDefinition() {
|
||||
if (fDefinition == NOT_INITIALIZED) {
|
||||
FindDefinitionAction action = new FindDefinitionAction();
|
||||
IASTNode node = CPPVisitor.getContainingBlockItem(getADeclaration()).getParent();
|
||||
node.accept(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2009 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 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
|
||||
|
@ -58,7 +58,6 @@ public class CPPTemplateTypeParameter extends CPPTemplateParameter implements
|
|||
for (IASTName nd : nds) {
|
||||
if (nd != null) {
|
||||
IASTNode parent = nd.getParent();
|
||||
assert parent instanceof ICPPASTSimpleTypeTemplateParameter;
|
||||
if (parent instanceof ICPPASTSimpleTypeTemplateParameter) {
|
||||
ICPPASTSimpleTypeTemplateParameter simple = (ICPPASTSimpleTypeTemplateParameter) parent;
|
||||
IASTTypeId typeId = simple.getDefaultType();
|
||||
|
|
|
@ -2702,10 +2702,12 @@ public class CPPSemantics {
|
|||
IASTDeclarator dtor = (IASTDeclarator) parent;
|
||||
targetType= CPPVisitor.createType(dtor);
|
||||
} else if (prop == IASTEqualsInitializer.INITIALIZER) {
|
||||
IASTEqualsInitializer initExp = (IASTEqualsInitializer) parent;
|
||||
if (initExp.getParent() instanceof IASTDeclarator) {
|
||||
IASTDeclarator dtor = (IASTDeclarator) initExp.getParent();
|
||||
targetType= CPPVisitor.createType(dtor);
|
||||
final IASTNode grandpa = parent.getParent();
|
||||
if (grandpa instanceof IASTDeclarator) {
|
||||
IASTDeclarator dtor = ASTQueries.findInnermostDeclarator((IASTDeclarator) grandpa);
|
||||
IBinding var= dtor.getName().resolvePreBinding();
|
||||
if (var instanceof IVariable)
|
||||
targetType= ((IVariable) var).getType();
|
||||
}
|
||||
} else if (prop == ICPPASTConstructorInitializer.ARGUMENT) {
|
||||
ICPPASTConstructorInitializer init = (ICPPASTConstructorInitializer) parent;
|
||||
|
|
|
@ -921,6 +921,7 @@ public class CPPTemplates {
|
|||
public static IType[] instantiateTypes(IType[] types, ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within) {
|
||||
// Don't create a new array until it's really needed.
|
||||
IType[] result = types;
|
||||
int j= 0;
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
IType origType = types[i];
|
||||
IType newType;
|
||||
|
@ -932,25 +933,24 @@ public class CPPTemplates {
|
|||
} else if (packSize == PACK_SIZE_DEFER) {
|
||||
newType= origType;
|
||||
} else {
|
||||
IType[] packResult= new IType[types.length+packSize-1];
|
||||
System.arraycopy(result, 0, packResult, 0, types.length-1);
|
||||
for(int j=0; j<packSize; j++) {
|
||||
packResult[i+j]= CPPTemplates.instantiateType(origType, tpMap, j, within);
|
||||
IType[] newResult= new IType[result.length+packSize-1];
|
||||
System.arraycopy(result, 0, newResult, 0, j);
|
||||
result= newResult;
|
||||
for(int k=0; k<packSize; k++) {
|
||||
result[j++]= CPPTemplates.instantiateType(origType, tpMap, k, within);
|
||||
}
|
||||
result= packResult;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
newType = CPPTemplates.instantiateType(origType, tpMap, packOffset, within);
|
||||
}
|
||||
if (result != types) {
|
||||
result[i]= newType;
|
||||
result[j++]= newType;
|
||||
} else if (newType != origType) {
|
||||
result = new IType[types.length];
|
||||
if (i > 0) {
|
||||
System.arraycopy(types, 0, result, 0, i);
|
||||
}
|
||||
result[i]= newType;
|
||||
j= i;
|
||||
System.arraycopy(types, 0, result, 0, i);
|
||||
result[j++]= newType;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -345,9 +345,9 @@ public class CPPVisitor extends ASTQueries {
|
|||
IType ft2= e.getFixedType();
|
||||
if (fixedType == ft2 || (fixedType != null && fixedType.isSameType(ft2))) {
|
||||
if (specifier.isOpaque()) {
|
||||
e.addDeclaration(specifier);
|
||||
e.addDeclaration(name);
|
||||
} else if (e.getDefinition() == null) {
|
||||
e.addDefinition(specifier);
|
||||
e.addDefinition(name);
|
||||
} else {
|
||||
return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDEFINITION);
|
||||
}
|
||||
|
@ -1752,9 +1752,11 @@ public class CPPVisitor extends ASTQueries {
|
|||
parent = parent.getParent();
|
||||
if (parent instanceof ICPPASTNewExpression) {
|
||||
IASTInitializer initializer = ((ICPPASTNewExpression) parent).getInitializer();
|
||||
IASTInitializerClause[] arguments = ((ICPPASTConstructorInitializer) initializer).getArguments();
|
||||
if (arguments.length == 1) {
|
||||
initClause = arguments[0];
|
||||
if (initializer != null) {
|
||||
IASTInitializerClause[] arguments = ((ICPPASTConstructorInitializer) initializer).getArguments();
|
||||
if (arguments.length == 1) {
|
||||
initClause = arguments[0];
|
||||
}
|
||||
}
|
||||
} else if (parent instanceof IASTCompositeTypeSpecifier &&
|
||||
declSpec.getStorageClass() != IASTDeclSpecifier.sc_static) {
|
||||
|
|
|
@ -16,6 +16,9 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
|
|||
|
||||
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CVQualifier.*;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
|
@ -540,10 +543,10 @@ public class SemanticUtil {
|
|||
* no inheritance relation
|
||||
*/
|
||||
public static final int calculateInheritanceDepth(IType type, IType baseClass) {
|
||||
return calculateInheritanceDepth(CPPSemantics.MAX_INHERITANCE_DEPTH, type, baseClass);
|
||||
return calculateInheritanceDepth(CPPSemantics.MAX_INHERITANCE_DEPTH, new HashSet<Object>(), type, baseClass);
|
||||
}
|
||||
|
||||
private static final int calculateInheritanceDepth(int maxdepth, IType type, IType baseClass) {
|
||||
private static final int calculateInheritanceDepth(int maxdepth, Set<Object> hashSet, IType type, IType baseClass) {
|
||||
if (type == baseClass || type.isSameType(baseClass)) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -556,7 +559,7 @@ public class SemanticUtil {
|
|||
|
||||
for (ICPPBase cppBase : clazz.getBases()) {
|
||||
IBinding base= cppBase.getBaseClass();
|
||||
if (base instanceof IType) {
|
||||
if (base instanceof IType && hashSet.add(base)) {
|
||||
IType tbase= (IType) base;
|
||||
if (tbase.isSameType(baseClass) ||
|
||||
(baseClass instanceof ICPPSpecialization && // allow some flexibility with templates
|
||||
|
@ -565,7 +568,7 @@ public class SemanticUtil {
|
|||
}
|
||||
|
||||
if (tbase instanceof ICPPClassType) {
|
||||
int n= calculateInheritanceDepth(maxdepth - 1, tbase, baseClass);
|
||||
int n= calculateInheritanceDepth(maxdepth - 1, hashSet, tbase, baseClass);
|
||||
if (n > 0)
|
||||
return n + 1;
|
||||
}
|
||||
|
|
|
@ -13,10 +13,12 @@ package org.eclipse.cdt.internal.core.pdom.db;
|
|||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ISemanticProblem;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.IValue;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ISerializableType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.Value;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||
|
@ -30,6 +32,9 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer {
|
|||
public final static byte NULL_TYPE= 0;
|
||||
public final static byte INDIRECT_TYPE= (byte) -1;
|
||||
public final static byte BINDING_TYPE= (byte) -2;
|
||||
public final static byte UNSTORABLE_TYPE= (byte) -3;
|
||||
|
||||
public final static IType UNSTORABLE_TYPE_PROBLEM = new ProblemType(ISemanticProblem.TYPE_NOT_PERSISTED);
|
||||
|
||||
static {
|
||||
assert EMPTY.length == Database.TYPE_SIZE;
|
||||
|
@ -65,10 +70,12 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer {
|
|||
public void marshalBinding(IBinding binding) throws CoreException {
|
||||
if (binding instanceof ISerializableType) {
|
||||
((ISerializableType) binding).marshal(this);
|
||||
} else if (binding == null) {
|
||||
putByte(NULL_TYPE);
|
||||
} else {
|
||||
PDOMBinding pb= fLinkage.addTypeBinding(binding);
|
||||
if (pb == null) {
|
||||
putByte(NULL_TYPE);
|
||||
putByte(UNSTORABLE_TYPE);
|
||||
} else {
|
||||
putByte(BINDING_TYPE);
|
||||
putByte((byte) 0);
|
||||
|
@ -86,7 +93,7 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer {
|
|||
fPos+= 2;
|
||||
long rec= getRecordPointer();
|
||||
return (IBinding) fLinkage.getNode(rec);
|
||||
} else if (firstByte == 0) {
|
||||
} else if (firstByte == NULL_TYPE || firstByte == UNSTORABLE_TYPE) {
|
||||
fPos++;
|
||||
return null;
|
||||
}
|
||||
|
@ -103,9 +110,11 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer {
|
|||
marshalBinding((IBinding) type);
|
||||
} else if (type instanceof ISerializableType) {
|
||||
((ISerializableType) type).marshal(this);
|
||||
} else {
|
||||
assert type == null : "Cannot serialize " + ASTTypeUtil.getType(type) + "(" + type.getClass().getName() + ")"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
|
||||
} else if (type == null) {
|
||||
putByte(NULL_TYPE);
|
||||
} else {
|
||||
assert false : "Cannot serialize " + ASTTypeUtil.getType(type) + "(" + type.getClass().getName() + ")"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
|
||||
putByte(UNSTORABLE_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,9 +127,12 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer {
|
|||
fPos+= 2;
|
||||
long rec= getRecordPointer();
|
||||
return (IType) fLinkage.getNode(rec);
|
||||
} else if (firstByte == 0) {
|
||||
} else if (firstByte == NULL_TYPE) {
|
||||
fPos++;
|
||||
return null;
|
||||
} else if (firstByte == UNSTORABLE_TYPE) {
|
||||
fPos++;
|
||||
return UNSTORABLE_TYPE_PROBLEM;
|
||||
}
|
||||
|
||||
return fLinkage.unmarshalType(this);
|
||||
|
|
|
@ -476,6 +476,8 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
|||
data= new byte[len];
|
||||
db.getBytes(ptr+2, data);
|
||||
break;
|
||||
case TypeMarshalBuffer.UNSTORABLE_TYPE:
|
||||
return TypeMarshalBuffer.UNSTORABLE_TYPE_PROBLEM;
|
||||
case TypeMarshalBuffer.NULL_TYPE:
|
||||
return null;
|
||||
default:
|
||||
|
|
|
@ -127,12 +127,20 @@ final class PDOMCParameter extends PDOMNamedNode implements IParameter, IPDOMBin
|
|||
return getNodeType();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void delete(PDOMLinkage linkage) throws CoreException {
|
||||
long rec = getNextPtr();
|
||||
if (rec != 0) {
|
||||
new PDOMCParameter(linkage, rec, null).delete(linkage);
|
||||
PDOMCParameter p= this;
|
||||
for (;;) {
|
||||
long rec = p.getNextPtr();
|
||||
p.flatDelete(linkage);
|
||||
if (rec == 0)
|
||||
return;
|
||||
p= new PDOMCParameter(linkage, rec, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void flatDelete(PDOMLinkage linkage) throws CoreException {
|
||||
super.delete(linkage);
|
||||
}
|
||||
|
||||
|
|
|
@ -204,10 +204,17 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter, IPDOMBind
|
|||
|
||||
@Override
|
||||
public void delete(PDOMLinkage linkage) throws CoreException {
|
||||
long rec = getNextPtr();
|
||||
if (rec != 0) {
|
||||
new PDOMCPPParameter(linkage, rec, null).delete(linkage);
|
||||
PDOMCPPParameter p= this;
|
||||
for (;;) {
|
||||
long rec = p.getNextPtr();
|
||||
p.flatDelete(linkage);
|
||||
if (rec == 0)
|
||||
return;
|
||||
p= new PDOMCPPParameter(linkage, rec, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void flatDelete(PDOMLinkage linkage) throws CoreException {
|
||||
super.delete(linkage);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue