mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
Storing unknown variables in index, bug 284686.
This commit is contained in:
parent
669ef1b53e
commit
fb29ac3b16
11 changed files with 116 additions and 75 deletions
|
@ -1676,7 +1676,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
|||
// vector<int> v;
|
||||
// f(v.begin());
|
||||
// }
|
||||
public void _testTemplateMetaprogramming_284686() throws Exception {
|
||||
public void testTemplateMetaprogramming_284686() throws Exception {
|
||||
getBindingFromASTName("f(v.begin())", 1, ICPPFunction.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -61,4 +61,5 @@ public interface IIndexCPPBindingConstants {
|
|||
int CPP_FRIEND_DECLARATION = IIndexBindingConstants.LAST_CONSTANT + 45;
|
||||
int CPP_TEMPLATE_TEMPLATE_PARAMETER= IIndexBindingConstants.LAST_CONSTANT + 46;
|
||||
int CPP_CLASS_TEMPLATE_PARTIAL_SPEC_SPEC = IIndexBindingConstants.LAST_CONSTANT + 47;
|
||||
int CPP_UNKNOWN_BINDING = IIndexBindingConstants.LAST_CONSTANT + 48;
|
||||
}
|
||||
|
|
|
@ -182,10 +182,11 @@ public class PDOM extends PlatformObject implements IPDOM {
|
|||
*
|
||||
* CDT 7.0 development (versions not supported on the 6.0.x branch)
|
||||
* 90.0 - support for array sizes, bug 269926
|
||||
* 91.0 - storing unknown bindings other than unknown class types, bug 284686.
|
||||
*/
|
||||
private static final int MIN_SUPPORTED_VERSION= version(90, 0);
|
||||
private static final int MAX_SUPPORTED_VERSION= version(90, Short.MAX_VALUE);
|
||||
private static final int DEFAULT_VERSION = version(90, 0);
|
||||
private static final int MIN_SUPPORTED_VERSION= version(91, 0);
|
||||
private static final int MAX_SUPPORTED_VERSION= version(91, Short.MAX_VALUE);
|
||||
private static final int DEFAULT_VERSION = version(91, 0);
|
||||
|
||||
private static int version(int major, int minor) {
|
||||
return (major << 16) + minor;
|
||||
|
|
|
@ -175,8 +175,14 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
|||
return null;
|
||||
}
|
||||
|
||||
public PDOMNode getNode(long record) throws CoreException {
|
||||
switch (PDOMNode.getNodeType(fDatabase, record)) {
|
||||
public final PDOMNode getNode(long record) throws CoreException {
|
||||
if (record == 0) {
|
||||
return null;
|
||||
}
|
||||
final int nodeType= PDOMNode.getNodeType(fDatabase, record);
|
||||
switch (nodeType) {
|
||||
case LINKAGE:
|
||||
return null;
|
||||
case POINTER_TYPE:
|
||||
return new PDOMPointerType(this, record);
|
||||
case ARRAY_TYPE:
|
||||
|
@ -184,9 +190,11 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
|||
case QUALIFIER_TYPE:
|
||||
return new PDOMQualifierType(this, record);
|
||||
}
|
||||
return null;
|
||||
return getNode(record, nodeType);
|
||||
}
|
||||
|
||||
abstract public PDOMNode getNode(long record, int nodeType) throws CoreException;
|
||||
|
||||
public PDOMNode addType(PDOMNode parent, IType type) throws CoreException {
|
||||
if (type instanceof IPointerType)
|
||||
return new PDOMPointerType(this, parent, (IPointerType)type);
|
||||
|
|
|
@ -17,7 +17,6 @@ package org.eclipse.cdt.internal.core.pdom.dom;
|
|||
import java.util.Arrays;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||
|
@ -123,7 +122,7 @@ public abstract class PDOMNamedNode extends PDOMNode {
|
|||
|
||||
public IIndexFragmentBinding getParentBinding() throws CoreException {
|
||||
PDOMNode parent= getParentNode();
|
||||
if (parent instanceof IIndexBinding) {
|
||||
if (parent instanceof IIndexFragmentBinding) {
|
||||
return (IIndexFragmentBinding) parent;
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -296,11 +296,8 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
|
|||
}
|
||||
|
||||
@Override
|
||||
public PDOMNode getNode(long record) throws CoreException {
|
||||
if (record == 0)
|
||||
return null;
|
||||
|
||||
switch (PDOMNode.getNodeType(getDB(), record)) {
|
||||
public PDOMNode getNode(long record, int nodeType) throws CoreException {
|
||||
switch (nodeType) {
|
||||
case CVARIABLE:
|
||||
return new PDOMCVariable(this, record);
|
||||
case CFUNCTION:
|
||||
|
@ -323,7 +320,8 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
|
|||
return new PDOMCFunctionType(this, record);
|
||||
}
|
||||
|
||||
return super.getNode(record);
|
||||
assert false;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -76,18 +76,17 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP
|
|||
|
||||
Database db = getDB();
|
||||
try {
|
||||
IParameter[] params= function.getParameters();
|
||||
IType[] paramTypes= IType.EMPTY_TYPE_ARRAY;
|
||||
IFunctionType ft= function.getType();
|
||||
if (ft != null) {
|
||||
PDOMNode typeNode = getLinkage().addType(this, ft);
|
||||
if (typeNode != null) {
|
||||
db.putRecPtr(record + FUNCTION_TYPE, typeNode.getRecord());
|
||||
paramTypes= ((IFunctionType) typeNode).getParameterTypes();
|
||||
}
|
||||
}
|
||||
|
||||
ft= getType();
|
||||
IParameter[] params= function.getParameters();
|
||||
IType[] paramTypes= ft.getParameterTypes();
|
||||
|
||||
ICPPFunction sFunc= (ICPPFunction) ((ICPPSpecialization)function).getSpecializedBinding();
|
||||
IParameter[] sParams= sFunc.getParameters();
|
||||
IType[] sParamTypes= sFunc.getType().getParameterTypes();
|
||||
|
@ -95,11 +94,13 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP
|
|||
final int length= Math.min(sParams.length, params.length);
|
||||
db.putInt(record + NUM_PARAMS, length);
|
||||
for (int i=0; i<length; ++i) {
|
||||
final PDOMNode stype= linkage.addType(this, i<sParamTypes.length ? sParamTypes[i] : null);
|
||||
final long stypeRec= stype == null ? 0 : stype.getRecord();
|
||||
PDOMCPPParameter sParam = new PDOMCPPParameter(getLinkage(), this, sParams[i], stypeRec);
|
||||
|
||||
long typeRecord= i<paramTypes.length && paramTypes[i]!=null ? ((PDOMNode)paramTypes[i]).getRecord() : 0;
|
||||
//TODO shouldn't need to make new parameter (find old one)
|
||||
final IType type= i<sParamTypes.length ? sParamTypes[i] : null;
|
||||
PDOMCPPParameter sParam = new PDOMCPPParameter(getLinkage(), this, sParams[i], type);
|
||||
setFirstParameter(new PDOMCPPParameterSpecialization(getLinkage(), this, (ICPPParameter) params[i], sParam, typeRecord));
|
||||
final ICPPParameter param = (ICPPParameter) params[i];
|
||||
setFirstParameter(new PDOMCPPParameterSpecialization(getLinkage(), this, param, sParam, typeRecord));
|
||||
}
|
||||
db.putByte(record + ANNOTATION, PDOMCPPAnnotation.encodeAnnotation(function));
|
||||
} catch (DOMException e) {
|
||||
|
|
|
@ -313,6 +313,18 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
|
|||
if (parent instanceof PDOMCPPClassType || parent instanceof PDOMCPPClassSpecialization) {
|
||||
pdomBinding = new PDOMCPPField(this, parent, (ICPPField) binding);
|
||||
}
|
||||
} else if (binding instanceof ICPPClassTemplate) {
|
||||
pdomBinding= new PDOMCPPClassTemplate(this, parent, (ICPPClassTemplate) binding);
|
||||
} else if (binding instanceof ICPPClassType) {
|
||||
if (binding instanceof ICPPUnknownClassInstance) {
|
||||
pdomBinding= new PDOMCPPUnknownClassInstance(this, parent, (ICPPUnknownClassInstance) binding);
|
||||
} else if (binding instanceof ICPPUnknownClassType) {
|
||||
pdomBinding= new PDOMCPPUnknownClassType(this, parent, (ICPPUnknownClassType) binding);
|
||||
} else {
|
||||
pdomBinding= new PDOMCPPClassType(this, parent, (ICPPClassType) binding);
|
||||
}
|
||||
} else if (binding instanceof ICPPUnknownBinding) {
|
||||
pdomBinding= new PDOMCPPUnknownBinding(this, parent, (ICPPUnknownBinding) binding);
|
||||
} else if (binding instanceof ICPPVariable) {
|
||||
ICPPVariable var= (ICPPVariable) binding;
|
||||
pdomBinding = new PDOMCPPVariable(this, parent, var);
|
||||
|
@ -334,16 +346,6 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
|
|||
}
|
||||
} else if (binding instanceof ICPPFunction) {
|
||||
pdomBinding = new PDOMCPPFunction(this, parent, (ICPPFunction) binding, true);
|
||||
} else if (binding instanceof ICPPClassTemplate) {
|
||||
pdomBinding= new PDOMCPPClassTemplate(this, parent, (ICPPClassTemplate) binding);
|
||||
} else if (binding instanceof ICPPClassType) {
|
||||
if (binding instanceof ICPPUnknownClassInstance) {
|
||||
pdomBinding= new PDOMCPPUnknownClassInstance(this, parent, (ICPPUnknownClassInstance) binding);
|
||||
} else if (binding instanceof ICPPUnknownClassType) {
|
||||
pdomBinding= new PDOMCPPUnknownClassType(this, parent, (ICPPUnknownClassType) binding);
|
||||
} else {
|
||||
pdomBinding= new PDOMCPPClassType(this, parent, (ICPPClassType) binding);
|
||||
}
|
||||
} else if (binding instanceof ICPPNamespaceAlias) {
|
||||
pdomBinding = new PDOMCPPNamespaceAlias(this, parent, (ICPPNamespaceAlias) binding);
|
||||
} else if (binding instanceof ICPPNamespace) {
|
||||
|
@ -731,11 +733,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
|
|||
}
|
||||
|
||||
@Override
|
||||
public PDOMNode getNode(long record) throws CoreException {
|
||||
if (record == 0)
|
||||
return null;
|
||||
|
||||
switch (PDOMNode.getNodeType(getDB(), record)) {
|
||||
public PDOMNode getNode(long record, int nodeType) throws CoreException {
|
||||
switch (nodeType) {
|
||||
case CPPVARIABLE:
|
||||
return new PDOMCPPVariable(this, record);
|
||||
case CPPFUNCTION:
|
||||
|
@ -792,6 +791,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
|
|||
return new PDOMCPPClassInstance(this, record);
|
||||
case CPP_DEFERRED_CLASS_INSTANCE:
|
||||
return new PDOMCPPDeferredClassInstance(this, record);
|
||||
case CPP_UNKNOWN_BINDING:
|
||||
return new PDOMCPPUnknownBinding(this, record);
|
||||
case CPP_UNKNOWN_CLASS_TYPE:
|
||||
return new PDOMCPPUnknownClassType(this, record);
|
||||
case CPP_UNKNOWN_CLASS_INSTANCE:
|
||||
|
@ -826,9 +827,9 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
|
|||
return new PDOMCPPFunctionType(this, record);
|
||||
case CPP_PARAMETER_SPECIALIZATION:
|
||||
return new PDOMCPPParameterSpecialization(this, record);
|
||||
default:
|
||||
return super.getNode(record);
|
||||
}
|
||||
assert false : "nodeid= " + nodeType; //$NON-NLS-1$
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,7 +19,6 @@ import org.eclipse.cdt.core.dom.ast.IType;
|
|||
import org.eclipse.cdt.core.dom.ast.IValue;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
|
||||
import org.eclipse.cdt.core.index.IIndexFile;
|
||||
import org.eclipse.cdt.internal.core.Util;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
||||
|
@ -77,30 +76,6 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter, IPDOMBind
|
|||
super(linkage, record);
|
||||
}
|
||||
|
||||
public PDOMCPPParameter(PDOMLinkage linkage, PDOMNode parent, IParameter param, IType type)
|
||||
throws CoreException {
|
||||
super(linkage, parent, param.getNameCharArray());
|
||||
|
||||
Database db = getDB();
|
||||
|
||||
db.putRecPtr(record + NEXT_PARAM, 0);
|
||||
byte flags= encodeFlags(param);
|
||||
db.putByte(record + FLAGS, flags);
|
||||
|
||||
try {
|
||||
if (type == null)
|
||||
type= param.getType();
|
||||
if (type != null) {
|
||||
PDOMNode typeNode = getLinkage().addType(this, type);
|
||||
db.putRecPtr(record + TYPE, typeNode != null ? typeNode.getRecord() : 0);
|
||||
}
|
||||
byte annotations = PDOMCPPAnnotation.encodeAnnotation(param);
|
||||
db.putByte(record + ANNOTATIONS, annotations);
|
||||
} catch (DOMException e) {
|
||||
throw new CoreException(Util.createStatus(e));
|
||||
}
|
||||
}
|
||||
|
||||
public PDOMCPPParameter(PDOMLinkage linkage, PDOMNode parent, IParameter param, long typeRecord)
|
||||
throws CoreException {
|
||||
super(linkage, parent, param.getNameCharArray());
|
||||
|
@ -265,7 +240,7 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter, IPDOMBind
|
|||
|
||||
@Override
|
||||
public void delete(PDOMLinkage linkage) throws CoreException {
|
||||
linkage.deleteType(getType(), record);
|
||||
// the parameter reuses the type from the function type, so do not delete it.
|
||||
PDOMCPPParameter next= getNextParameter();
|
||||
if (next != null) {
|
||||
next.delete(linkage);
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn (Wind River Systems) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* Models unknown bindings. The class is directly used for objects (variables, functions, ...) and
|
||||
* serves as a base for unknown types.
|
||||
*/
|
||||
class PDOMCPPUnknownBinding extends PDOMCPPBinding implements ICPPUnknownBinding {
|
||||
|
||||
@SuppressWarnings("hiding")
|
||||
protected static final int RECORD_SIZE = PDOMCPPBinding.RECORD_SIZE;
|
||||
|
||||
public PDOMCPPUnknownBinding(PDOMLinkage linkage, PDOMNode parent, ICPPUnknownBinding binding) throws CoreException {
|
||||
super(linkage, parent, binding.getNameCharArray());
|
||||
}
|
||||
|
||||
public PDOMCPPUnknownBinding(PDOMLinkage linkage, long bindingRecord) {
|
||||
super(linkage, bindingRecord);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getRecordSize() {
|
||||
return RECORD_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNodeType() {
|
||||
return IIndexCPPBindingConstants.CPP_UNKNOWN_BINDING;
|
||||
}
|
||||
|
||||
public ICPPScope asScope() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mayHaveChildren() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public IASTName getUnknownName() {
|
||||
return new CPPASTName(getNameCharArray());
|
||||
}
|
||||
}
|
|
@ -31,7 +31,6 @@ import org.eclipse.cdt.core.index.IIndexBinding;
|
|||
import org.eclipse.cdt.core.index.IIndexFileSet;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.Util;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassInstance;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassType;
|
||||
|
@ -48,18 +47,18 @@ import org.eclipse.core.runtime.CoreException;
|
|||
/**
|
||||
* @author Sergey Prigogin
|
||||
*/
|
||||
class PDOMCPPUnknownClassType extends PDOMCPPBinding implements ICPPClassScope, ICPPUnknownClassType,
|
||||
class PDOMCPPUnknownClassType extends PDOMCPPUnknownBinding implements ICPPClassScope, ICPPUnknownClassType,
|
||||
IPDOMMemberOwner, IIndexType, IIndexScope {
|
||||
|
||||
private static final int KEY = PDOMCPPBinding.RECORD_SIZE + 0; // byte
|
||||
private static final int MEMBERLIST = PDOMCPPBinding.RECORD_SIZE + 4;
|
||||
@SuppressWarnings("hiding")
|
||||
protected static final int RECORD_SIZE = PDOMCPPBinding.RECORD_SIZE + 8;
|
||||
protected static final int RECORD_SIZE = PDOMCPPUnknownBinding.RECORD_SIZE + 8;
|
||||
|
||||
private ICPPScope unknownScope;
|
||||
|
||||
public PDOMCPPUnknownClassType(PDOMLinkage linkage, PDOMNode parent, ICPPUnknownClassType classType) throws CoreException {
|
||||
super(linkage, parent, classType.getNameCharArray());
|
||||
super(linkage, parent, classType);
|
||||
|
||||
setKind(classType);
|
||||
// linked list is initialized by storage being zero'd by malloc
|
||||
|
@ -121,7 +120,8 @@ class PDOMCPPUnknownClassType extends PDOMCPPBinding implements ICPPClassScope,
|
|||
return this;
|
||||
}
|
||||
|
||||
public ICPPScope asScope() {
|
||||
@Override
|
||||
public ICPPScope asScope() {
|
||||
if (unknownScope == null) {
|
||||
unknownScope= new PDOMCPPUnknownScope(this, getUnknownName());
|
||||
}
|
||||
|
@ -262,10 +262,6 @@ class PDOMCPPUnknownClassType extends PDOMCPPBinding implements ICPPClassScope,
|
|||
return ICPPClassType.EMPTY_CLASS_ARRAY;
|
||||
}
|
||||
|
||||
public IASTName getUnknownName() {
|
||||
return new CPPASTName(getNameCharArray());
|
||||
}
|
||||
|
||||
public boolean isAnonymous() {
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue