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

Bug 486915 - Unmarshalling error during indexing

Change-Id: Ifc37fe89d46e418925bf977795a99d043fd67360
This commit is contained in:
Sergey Prigogin 2016-01-31 20:57:27 -08:00
parent 09a0c248fb
commit ebf041caef
12 changed files with 157 additions and 51 deletions

View file

@ -37,9 +37,8 @@ public interface ITypeMarshalBuffer {
final static byte UNKNOWN_MEMBER = 0x0C; final static byte UNKNOWN_MEMBER = 0x0C;
final static byte UNKNOWN_MEMBER_CLASS_INSTANCE = 0x0D; final static byte UNKNOWN_MEMBER_CLASS_INSTANCE = 0x0D;
final static byte DEFERRED_CLASS_INSTANCE = 0x0E; final static byte DEFERRED_CLASS_INSTANCE = 0x0E;
final static byte ALIAS_TEMPLATE = 0x0F; final static byte TYPE_TRANSFORMATION = 0x0F;
final static byte TYPE_TRANSFORMATION = 0x10; final static byte UNKNOWN_MEMBER_TYPE = 0x10;
final static byte UNKNOWN_MEMBER_TYPE = 0x11;
// Can add more types up to 0x1C, after that it will collide with TypeMarshalBuffer.UNSTORABLE_TYPE. // Can add more types up to 0x1C, after that it will collide with TypeMarshalBuffer.UNSTORABLE_TYPE.
final static byte final static byte

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2012, 2013 Institute for Software, HSR Hochschule fuer Technik * Copyright (c) 2012, 2016 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences. * Rapperswil, University of applied sciences.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -21,16 +21,14 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplateInstance; import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ISerializableType;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
public class CPPAliasTemplateInstance extends PlatformObject public class CPPAliasTemplateInstance extends PlatformObject
implements ICPPAliasTemplateInstance, ITypeContainer, ISerializableType { implements ICPPAliasTemplateInstance, ITypeContainer {
private final char[] name; private final char[] name;
private final ICPPAliasTemplate aliasTemplate; private final ICPPAliasTemplate aliasTemplate;
private IType aliasedType; private IType aliasedType;
@ -85,7 +83,7 @@ public class CPPAliasTemplateInstance extends PlatformObject
if (name != null) { if (name != null) {
return name; return name;
} }
return new char[0]; return CharArrayUtils.EMPTY_CHAR_ARRAY;
} }
@Override @Override
@ -109,22 +107,6 @@ public class CPPAliasTemplateInstance extends PlatformObject
return null; return null;
} }
@Override
public void marshal(ITypeMarshalBuffer buffer) throws CoreException {
short firstBytes = ITypeMarshalBuffer.ALIAS_TEMPLATE;
buffer.putShort(firstBytes);
buffer.putCharArray(name);
buffer.marshalType(aliasedType);
buffer.marshalBinding(aliasTemplate);
}
public static IType unmarshal(short firstBytes, ITypeMarshalBuffer buffer) throws CoreException {
char[] name = buffer.getCharArray();
IType unmarshalledAliasedTypeInstance = buffer.unmarshalType();
ICPPAliasTemplate unmarshalledAlias = (ICPPAliasTemplate) buffer.unmarshalBinding();
return new CPPAliasTemplateInstance(name, unmarshalledAlias, unmarshalledAliasedTypeInstance);
}
@Override @Override
public String toString() { public String toString() {
return ASTTypeUtil.getQualifiedName(this) + " -> " + ASTTypeUtil.getType(aliasedType, true); //$NON-NLS-1$ return ASTTypeUtil.getQualifiedName(this) + " -> " + ASTTypeUtil.getType(aliasedType, true); //$NON-NLS-1$

View file

@ -72,8 +72,8 @@ public abstract class CPPUnknownBinding extends PlatformObject
} }
@Override @Override
public String getName() { public final String getName() {
return new String(name); return new String(getNameCharArray());
} }
@Override @Override

View file

@ -30,7 +30,7 @@ public class TypeOfDependentExpression extends CPPUnknownBinding implements ICPP
private final ICPPEvaluation fEvaluation; private final ICPPEvaluation fEvaluation;
public TypeOfDependentExpression(ICPPEvaluation evaluation) { public TypeOfDependentExpression(ICPPEvaluation evaluation) {
super(evaluation.getSignature()); super(null);
fEvaluation= evaluation; fEvaluation= evaluation;
} }
@ -78,4 +78,9 @@ public class TypeOfDependentExpression extends CPPUnknownBinding implements ICPP
// We won't know until instantiation. // We won't know until instantiation.
return null; return null;
} }
@Override
public char[] getNameCharArray() {
return fEvaluation.getSignature();
}
} }

View file

@ -62,13 +62,14 @@ public interface IIndexCPPBindingConstants {
int CPP_UNKNOWN_FIELD = IIndexBindingConstants.LAST_CONSTANT + 48; int CPP_UNKNOWN_FIELD = IIndexBindingConstants.LAST_CONSTANT + 48;
int CPP_USING_DECLARATION_SPECIALIZATION= IIndexBindingConstants.LAST_CONSTANT + 49; int CPP_USING_DECLARATION_SPECIALIZATION= IIndexBindingConstants.LAST_CONSTANT + 49;
int CPP_UNKNOWN_METHOD = IIndexBindingConstants.LAST_CONSTANT + 50; int CPP_UNKNOWN_METHOD = IIndexBindingConstants.LAST_CONSTANT + 50;
int CPP_TEMPLATE_ALIAS = IIndexBindingConstants.LAST_CONSTANT + 51; int CPP_ALIAS_TEMPLATE = IIndexBindingConstants.LAST_CONSTANT + 51;
int CPP_ENUMERATION_SPECIALIZATION = IIndexBindingConstants.LAST_CONSTANT + 52; int CPP_ALIAS_TEMPLATE_INSTANCE = IIndexBindingConstants.LAST_CONSTANT + 52;
int CPP_ENUMERATOR_SPECIALIZATION = IIndexBindingConstants.LAST_CONSTANT + 53; int CPP_ENUMERATION_SPECIALIZATION = IIndexBindingConstants.LAST_CONSTANT + 53;
int CPP_VARIABLE_TEMPLATE = IIndexBindingConstants.LAST_CONSTANT + 54; int CPP_ENUMERATOR_SPECIALIZATION = IIndexBindingConstants.LAST_CONSTANT + 54;
int CPP_FIELD_TEMPLATE = IIndexBindingConstants.LAST_CONSTANT + 55; int CPP_VARIABLE_TEMPLATE = IIndexBindingConstants.LAST_CONSTANT + 55;
int CPP_VARIABLE_INSTANCE = IIndexBindingConstants.LAST_CONSTANT + 56; int CPP_FIELD_TEMPLATE = IIndexBindingConstants.LAST_CONSTANT + 56;
int CPP_FIELD_INSTANCE = IIndexBindingConstants.LAST_CONSTANT + 57; int CPP_VARIABLE_INSTANCE = IIndexBindingConstants.LAST_CONSTANT + 57;
int CPP_VARIABLE_TEMPLATE_PARTIAL_SPECIALIZATION = IIndexBindingConstants.LAST_CONSTANT + 58; int CPP_FIELD_INSTANCE = IIndexBindingConstants.LAST_CONSTANT + 58;
int CPP_FIELD_TEMPLATE_PARTIAL_SPECIALIZATION = IIndexBindingConstants.LAST_CONSTANT + 59; int CPP_VARIABLE_TEMPLATE_PARTIAL_SPECIALIZATION = IIndexBindingConstants.LAST_CONSTANT + 59;
int CPP_FIELD_TEMPLATE_PARTIAL_SPECIALIZATION = IIndexBindingConstants.LAST_CONSTANT + 60;
} }

View file

@ -689,6 +689,8 @@ public class CPPCompositesFactory extends AbstractCompositeFactory {
result = new CompositeCPPFunction(this, (ICPPFunction) binding); result = new CompositeCPPFunction(this, (ICPPFunction) binding);
} else if (binding instanceof ICPPInternalEnumerator) { } else if (binding instanceof ICPPInternalEnumerator) {
result = new CompositeCPPEnumerator(this, (ICPPInternalEnumerator) binding); result = new CompositeCPPEnumerator(this, (ICPPInternalEnumerator) binding);
} else if (binding instanceof ICPPAliasTemplateInstance) {
return new CompositeCPPAliasTemplateInstance(this, (ICPPBinding) binding);
} else if (binding instanceof ITypedef) { } else if (binding instanceof ITypedef) {
result = new CompositeCPPTypedef(this, (ICPPBinding) binding); result = new CompositeCPPTypedef(this, (ICPPBinding) binding);
} else if (binding instanceof IIndexMacroContainer) { } else if (binding instanceof IIndexMacroContainer) {

View file

@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2016 Google, 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Sergey Prigogin (Google) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCPPAliasTemplateInstance extends CompositeCPPTypedef implements ICPPAliasTemplateInstance {
public CompositeCPPAliasTemplateInstance(ICompositesFactory cf, ICPPBinding delegate) {
super(cf, delegate);
}
@Override
public Object clone() {
fail(); return null;
}
@Override
public ICPPAliasTemplate getTemplateDefinition() {
ICPPAliasTemplate templateDefinition = ((ICPPAliasTemplateInstance) rbinding).getTemplateDefinition();
return (ICPPAliasTemplate) cf.getCompositeBinding((IIndexFragmentBinding) templateDefinition);
}
}

View file

@ -266,11 +266,14 @@ public class PDOM extends PlatformObject implements IPDOM {
* *
* CDT 8.8 development (versions not supported on the 8.7.x branch) * CDT 8.8 development (versions not supported on the 8.7.x branch)
* 190.0 - Signature change for methods with ref-qualifiers, bug 470014. * 190.0 - Signature change for methods with ref-qualifiers, bug 470014.
* 191.0 - Added EvalID.fIsPointerDeref, bug 472436. * 191.0 - Added EvalID.fIsPointerDeref, bug 472436. <<CDT 8.8>>
*
* CDT 9.0 development (versions not supported on the 8.8.x branch)
* 200.0 - Added PDOMCPPAliasTemplateInstance, bug 486915.
*/ */
private static final int MIN_SUPPORTED_VERSION= version(191, 0); private static final int MIN_SUPPORTED_VERSION= version(200, 0);
private static final int MAX_SUPPORTED_VERSION= version(191, Short.MAX_VALUE); private static final int MAX_SUPPORTED_VERSION= version(200, Short.MAX_VALUE);
private static final int DEFAULT_VERSION = version(191, 0); private static final int DEFAULT_VERSION = version(200, 0);
private static int version(int major, int minor) { private static int version(int major, int minor) {
return (major << 16) + minor; return (major << 16) + minor;

View file

@ -64,12 +64,12 @@ class PDOMCPPAliasTemplate extends PDOMCPPBinding implements ICPPAliasTemplate,
@Override @Override
public int getNodeType() { public int getNodeType() {
return IIndexCPPBindingConstants.CPP_TEMPLATE_ALIAS; return IIndexCPPBindingConstants.CPP_ALIAS_TEMPLATE;
} }
@Override @Override
public boolean isSameType(IType type) { public boolean isSameType(IType type) {
if(type == null){ if (type == null){
return false; return false;
} }
IType aliasedType = getType(); IType aliasedType = getType();

View file

@ -0,0 +1,66 @@
/*******************************************************************************
* Copyright (c) 2016 Google, 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Sergey Prigogin (Google) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplateInstance;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException;
/**
* PDOM binding for alias template instance.
*/
class PDOMCPPAliasTemplateInstance extends PDOMCPPTypedef implements ICPPAliasTemplateInstance {
private static final int TEMPLATE_DEFINITION_OFFSET = PDOMCPPTypedef.RECORD_SIZE;
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = TEMPLATE_DEFINITION_OFFSET + Database.TYPE_SIZE;
private volatile ICPPAliasTemplate fTemplateDefinition;
public PDOMCPPAliasTemplateInstance(PDOMCPPLinkage linkage, PDOMNode parent, PDOMBinding templateDefinition,
ICPPAliasTemplateInstance binding) throws CoreException, DOMException {
super(linkage, parent, binding);
getDB().putRecPtr(record + TEMPLATE_DEFINITION_OFFSET, templateDefinition.getRecord());
}
public PDOMCPPAliasTemplateInstance(PDOMCPPLinkage linkage, long record) {
super(linkage, record);
}
@Override
public int getNodeType() {
return IIndexCPPBindingConstants.CPP_ALIAS_TEMPLATE_INSTANCE;
}
@Override
public ICPPAliasTemplate getTemplateDefinition() {
if (fTemplateDefinition == null) {
try {
long templateRec = getDB().getRecPtr(record + TEMPLATE_DEFINITION_OFFSET);
fTemplateDefinition = (ICPPAliasTemplate) PDOMNode.load(getPDOM(), templateRec);
} catch (CoreException e) {
CCorePlugin.log(e);
}
}
return fTemplateDefinition;
}
@Override
protected int getRecordSize() {
return RECORD_SIZE;
}
}

View file

@ -10,6 +10,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp; package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.ISemanticProblem; import org.eclipse.cdt.core.dom.ast.ISemanticProblem;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
import org.eclipse.cdt.internal.core.dom.parser.ProblemType; import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
@ -67,6 +68,11 @@ public class PDOMCPPArgumentList {
* Restores an array of template arguments from the database. * Restores an array of template arguments from the database.
*/ */
public static ICPPTemplateArgument[] getArguments(PDOMNode parent, long rec) throws CoreException { public static ICPPTemplateArgument[] getArguments(PDOMNode parent, long rec) throws CoreException {
if (rec == 0) {
CCorePlugin.log(new IllegalArgumentException(
"Trying to access template arguments before they have been stored.")); //$NON-NLS-1$
return ICPPTemplateArgument.EMPTY_ARGUMENTS;
}
final PDOMLinkage linkage= parent.getLinkage(); final PDOMLinkage linkage= parent.getLinkage();
final Database db= linkage.getDB(); final Database db= linkage.getDB();
final short len= db.getShort(rec); final short len= db.getShort(rec);

View file

@ -89,7 +89,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation;
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; 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.ProblemType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPAliasTemplateInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPArrayType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPArrayType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClosureType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClosureType;
@ -622,10 +621,17 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
parent2= this; parent2= this;
} }
} }
} else if (binding instanceof ITypedef) {
pdomBinding = new PDOMCPPTypedef(this, parent, (ITypedef) binding);
} else if (binding instanceof ICPPAliasTemplate) { } else if (binding instanceof ICPPAliasTemplate) {
pdomBinding = new PDOMCPPAliasTemplate(this, parent, (ICPPAliasTemplate) binding); pdomBinding = new PDOMCPPAliasTemplate(this, parent, (ICPPAliasTemplate) binding);
} else if (binding instanceof ICPPAliasTemplateInstance) {
IBinding template = ((ICPPAliasTemplateInstance) binding).getTemplateDefinition();
PDOMBinding pdomTemplate = addBinding(template, null);
if (pdomTemplate == null)
return null;
pdomBinding = new PDOMCPPAliasTemplateInstance(this, parent, pdomTemplate,
(ICPPAliasTemplateInstance) binding);
} else if (binding instanceof ITypedef) {
pdomBinding = new PDOMCPPTypedef(this, parent, (ITypedef) binding);
} }
if (pdomBinding != null) { if (pdomBinding != null) {
@ -899,7 +905,9 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
} else if (binding instanceof ITypedef) { } else if (binding instanceof ITypedef) {
return CPPTYPEDEF; return CPPTYPEDEF;
} else if (binding instanceof ICPPAliasTemplate) { } else if (binding instanceof ICPPAliasTemplate) {
return CPP_TEMPLATE_ALIAS; return CPP_ALIAS_TEMPLATE;
} else if (binding instanceof ICPPAliasTemplateInstance) {
return CPP_ALIAS_TEMPLATE_INSTANCE;
} }
return 0; return 0;
@ -907,7 +915,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
@Override @Override
protected boolean cannotAdapt(final IBinding inputBinding) throws CoreException { protected boolean cannotAdapt(final IBinding inputBinding) throws CoreException {
return super.cannotAdapt(inputBinding) || inputBinding instanceof ICPPAliasTemplateInstance; return super.cannotAdapt(inputBinding);
} }
@Override @Override
@ -1119,8 +1127,10 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
return new PDOMCPPTypedefSpecialization(this, record); return new PDOMCPPTypedefSpecialization(this, record);
case CPP_USING_DECLARATION_SPECIALIZATION: case CPP_USING_DECLARATION_SPECIALIZATION:
return new PDOMCPPUsingDeclarationSpecialization(this, record); return new PDOMCPPUsingDeclarationSpecialization(this, record);
case CPP_TEMPLATE_ALIAS: case CPP_ALIAS_TEMPLATE:
return new PDOMCPPAliasTemplate(this, record); return new PDOMCPPAliasTemplate(this, record);
case CPP_ALIAS_TEMPLATE_INSTANCE:
return new PDOMCPPAliasTemplateInstance(this, record);
case CPP_ENUMERATION_SPECIALIZATION: case CPP_ENUMERATION_SPECIALIZATION:
return new PDOMCPPEnumerationSpecialization(this, record); return new PDOMCPPEnumerationSpecialization(this, record);
case CPP_ENUMERATOR_SPECIALIZATION: case CPP_ENUMERATOR_SPECIALIZATION:
@ -1370,8 +1380,6 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
return CPPUnknownClassInstance.unmarshal(getPDOM(), firstBytes, buffer); return CPPUnknownClassInstance.unmarshal(getPDOM(), firstBytes, buffer);
case ITypeMarshalBuffer.DEFERRED_CLASS_INSTANCE: case ITypeMarshalBuffer.DEFERRED_CLASS_INSTANCE:
return CPPDeferredClassInstance.unmarshal(getPDOM(), firstBytes, buffer); return CPPDeferredClassInstance.unmarshal(getPDOM(), firstBytes, buffer);
case ITypeMarshalBuffer.ALIAS_TEMPLATE:
return CPPAliasTemplateInstance.unmarshal(firstBytes, buffer);
case ITypeMarshalBuffer.TYPE_TRANSFORMATION: case ITypeMarshalBuffer.TYPE_TRANSFORMATION:
return CPPUnaryTypeTransformation.unmarshal(firstBytes, buffer); return CPPUnaryTypeTransformation.unmarshal(firstBytes, buffer);
case ITypeMarshalBuffer.UNKNOWN_MEMBER_TYPE: case ITypeMarshalBuffer.UNKNOWN_MEMBER_TYPE: