1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-01 13:25:45 +02:00

Storing unknown variables in index, bug 284686.

This commit is contained in:
Markus Schorn 2009-07-28 14:06:44 +00:00
parent 669ef1b53e
commit fb29ac3b16
11 changed files with 116 additions and 75 deletions

View file

@ -1676,7 +1676,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
// vector<int> v; // vector<int> v;
// f(v.begin()); // f(v.begin());
// } // }
public void _testTemplateMetaprogramming_284686() throws Exception { public void testTemplateMetaprogramming_284686() throws Exception {
getBindingFromASTName("f(v.begin())", 1, ICPPFunction.class); getBindingFromASTName("f(v.begin())", 1, ICPPFunction.class);
} }

View file

@ -61,4 +61,5 @@ public interface IIndexCPPBindingConstants {
int CPP_FRIEND_DECLARATION = IIndexBindingConstants.LAST_CONSTANT + 45; int CPP_FRIEND_DECLARATION = IIndexBindingConstants.LAST_CONSTANT + 45;
int CPP_TEMPLATE_TEMPLATE_PARAMETER= IIndexBindingConstants.LAST_CONSTANT + 46; int CPP_TEMPLATE_TEMPLATE_PARAMETER= IIndexBindingConstants.LAST_CONSTANT + 46;
int CPP_CLASS_TEMPLATE_PARTIAL_SPEC_SPEC = IIndexBindingConstants.LAST_CONSTANT + 47; int CPP_CLASS_TEMPLATE_PARTIAL_SPEC_SPEC = IIndexBindingConstants.LAST_CONSTANT + 47;
int CPP_UNKNOWN_BINDING = IIndexBindingConstants.LAST_CONSTANT + 48;
} }

View file

@ -182,10 +182,11 @@ public class PDOM extends PlatformObject implements IPDOM {
* *
* CDT 7.0 development (versions not supported on the 6.0.x branch) * CDT 7.0 development (versions not supported on the 6.0.x branch)
* 90.0 - support for array sizes, bug 269926 * 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 MIN_SUPPORTED_VERSION= version(91, 0);
private static final int MAX_SUPPORTED_VERSION= version(90, Short.MAX_VALUE); private static final int MAX_SUPPORTED_VERSION= version(91, Short.MAX_VALUE);
private static final int DEFAULT_VERSION = version(90, 0); private static final int DEFAULT_VERSION = version(91, 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

@ -175,8 +175,14 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
return null; return null;
} }
public PDOMNode getNode(long record) throws CoreException { public final PDOMNode getNode(long record) throws CoreException {
switch (PDOMNode.getNodeType(fDatabase, record)) { if (record == 0) {
return null;
}
final int nodeType= PDOMNode.getNodeType(fDatabase, record);
switch (nodeType) {
case LINKAGE:
return null;
case POINTER_TYPE: case POINTER_TYPE:
return new PDOMPointerType(this, record); return new PDOMPointerType(this, record);
case ARRAY_TYPE: case ARRAY_TYPE:
@ -184,9 +190,11 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
case QUALIFIER_TYPE: case QUALIFIER_TYPE:
return new PDOMQualifierType(this, record); 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 { public PDOMNode addType(PDOMNode parent, IType type) throws CoreException {
if (type instanceof IPointerType) if (type instanceof IPointerType)
return new PDOMPointerType(this, parent, (IPointerType)type); return new PDOMPointerType(this, parent, (IPointerType)type);

View file

@ -17,7 +17,6 @@ package org.eclipse.cdt.internal.core.pdom.dom;
import java.util.Arrays; import java.util.Arrays;
import org.eclipse.cdt.core.CCorePlugin; 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.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.db.Database;
@ -123,7 +122,7 @@ public abstract class PDOMNamedNode extends PDOMNode {
public IIndexFragmentBinding getParentBinding() throws CoreException { public IIndexFragmentBinding getParentBinding() throws CoreException {
PDOMNode parent= getParentNode(); PDOMNode parent= getParentNode();
if (parent instanceof IIndexBinding) { if (parent instanceof IIndexFragmentBinding) {
return (IIndexFragmentBinding) parent; return (IIndexFragmentBinding) parent;
} }
return null; return null;

View file

@ -296,11 +296,8 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
} }
@Override @Override
public PDOMNode getNode(long record) throws CoreException { public PDOMNode getNode(long record, int nodeType) throws CoreException {
if (record == 0) switch (nodeType) {
return null;
switch (PDOMNode.getNodeType(getDB(), record)) {
case CVARIABLE: case CVARIABLE:
return new PDOMCVariable(this, record); return new PDOMCVariable(this, record);
case CFUNCTION: case CFUNCTION:
@ -323,7 +320,8 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
return new PDOMCFunctionType(this, record); return new PDOMCFunctionType(this, record);
} }
return super.getNode(record); assert false;
return null;
} }
@Override @Override

View file

@ -76,18 +76,17 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP
Database db = getDB(); Database db = getDB();
try { try {
IParameter[] params= function.getParameters();
IType[] paramTypes= IType.EMPTY_TYPE_ARRAY;
IFunctionType ft= function.getType(); IFunctionType ft= function.getType();
if (ft != null) { if (ft != null) {
PDOMNode typeNode = getLinkage().addType(this, ft); PDOMNode typeNode = getLinkage().addType(this, ft);
if (typeNode != null) { if (typeNode != null) {
db.putRecPtr(record + FUNCTION_TYPE, typeNode.getRecord()); 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(); ICPPFunction sFunc= (ICPPFunction) ((ICPPSpecialization)function).getSpecializedBinding();
IParameter[] sParams= sFunc.getParameters(); IParameter[] sParams= sFunc.getParameters();
IType[] sParamTypes= sFunc.getType().getParameterTypes(); IType[] sParamTypes= sFunc.getType().getParameterTypes();
@ -95,11 +94,13 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP
final int length= Math.min(sParams.length, params.length); final int length= Math.min(sParams.length, params.length);
db.putInt(record + NUM_PARAMS, length); db.putInt(record + NUM_PARAMS, length);
for (int i=0; i<length; ++i) { 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; 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 ICPPParameter param = (ICPPParameter) params[i];
final IType type= i<sParamTypes.length ? sParamTypes[i] : null; setFirstParameter(new PDOMCPPParameterSpecialization(getLinkage(), this, param, sParam, typeRecord));
PDOMCPPParameter sParam = new PDOMCPPParameter(getLinkage(), this, sParams[i], type);
setFirstParameter(new PDOMCPPParameterSpecialization(getLinkage(), this, (ICPPParameter) params[i], sParam, typeRecord));
} }
db.putByte(record + ANNOTATION, PDOMCPPAnnotation.encodeAnnotation(function)); db.putByte(record + ANNOTATION, PDOMCPPAnnotation.encodeAnnotation(function));
} catch (DOMException e) { } catch (DOMException e) {

View file

@ -313,6 +313,18 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
if (parent instanceof PDOMCPPClassType || parent instanceof PDOMCPPClassSpecialization) { if (parent instanceof PDOMCPPClassType || parent instanceof PDOMCPPClassSpecialization) {
pdomBinding = new PDOMCPPField(this, parent, (ICPPField) binding); 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) { } else if (binding instanceof ICPPVariable) {
ICPPVariable var= (ICPPVariable) binding; ICPPVariable var= (ICPPVariable) binding;
pdomBinding = new PDOMCPPVariable(this, parent, var); pdomBinding = new PDOMCPPVariable(this, parent, var);
@ -334,16 +346,6 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
} }
} else if (binding instanceof ICPPFunction) { } else if (binding instanceof ICPPFunction) {
pdomBinding = new PDOMCPPFunction(this, parent, (ICPPFunction) binding, true); 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) { } else if (binding instanceof ICPPNamespaceAlias) {
pdomBinding = new PDOMCPPNamespaceAlias(this, parent, (ICPPNamespaceAlias) binding); pdomBinding = new PDOMCPPNamespaceAlias(this, parent, (ICPPNamespaceAlias) binding);
} else if (binding instanceof ICPPNamespace) { } else if (binding instanceof ICPPNamespace) {
@ -731,11 +733,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
} }
@Override @Override
public PDOMNode getNode(long record) throws CoreException { public PDOMNode getNode(long record, int nodeType) throws CoreException {
if (record == 0) switch (nodeType) {
return null;
switch (PDOMNode.getNodeType(getDB(), record)) {
case CPPVARIABLE: case CPPVARIABLE:
return new PDOMCPPVariable(this, record); return new PDOMCPPVariable(this, record);
case CPPFUNCTION: case CPPFUNCTION:
@ -792,6 +791,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
return new PDOMCPPClassInstance(this, record); return new PDOMCPPClassInstance(this, record);
case CPP_DEFERRED_CLASS_INSTANCE: case CPP_DEFERRED_CLASS_INSTANCE:
return new PDOMCPPDeferredClassInstance(this, record); return new PDOMCPPDeferredClassInstance(this, record);
case CPP_UNKNOWN_BINDING:
return new PDOMCPPUnknownBinding(this, record);
case CPP_UNKNOWN_CLASS_TYPE: case CPP_UNKNOWN_CLASS_TYPE:
return new PDOMCPPUnknownClassType(this, record); return new PDOMCPPUnknownClassType(this, record);
case CPP_UNKNOWN_CLASS_INSTANCE: case CPP_UNKNOWN_CLASS_INSTANCE:
@ -826,9 +827,9 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
return new PDOMCPPFunctionType(this, record); return new PDOMCPPFunctionType(this, record);
case CPP_PARAMETER_SPECIALIZATION: case CPP_PARAMETER_SPECIALIZATION:
return new PDOMCPPParameterSpecialization(this, record); return new PDOMCPPParameterSpecialization(this, record);
default:
return super.getNode(record);
} }
assert false : "nodeid= " + nodeType; //$NON-NLS-1$
return null;
} }
@Override @Override

View file

@ -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.IValue;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.index.IIndexFile; 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.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.index.IIndexFragment; import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.index.IIndexScope; import org.eclipse.cdt.internal.core.index.IIndexScope;
@ -77,30 +76,6 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter, IPDOMBind
super(linkage, record); 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) public PDOMCPPParameter(PDOMLinkage linkage, PDOMNode parent, IParameter param, long typeRecord)
throws CoreException { throws CoreException {
super(linkage, parent, param.getNameCharArray()); super(linkage, parent, param.getNameCharArray());
@ -265,7 +240,7 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter, IPDOMBind
@Override @Override
public void delete(PDOMLinkage linkage) throws CoreException { 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(); PDOMCPPParameter next= getNextParameter();
if (next != null) { if (next != null) {
next.delete(linkage); next.delete(linkage);

View file

@ -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());
}
}

View file

@ -31,7 +31,6 @@ import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet; import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.Util; 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.ICPPDeferredClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassType; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassType;
@ -48,18 +47,18 @@ import org.eclipse.core.runtime.CoreException;
/** /**
* @author Sergey Prigogin * @author Sergey Prigogin
*/ */
class PDOMCPPUnknownClassType extends PDOMCPPBinding implements ICPPClassScope, ICPPUnknownClassType, class PDOMCPPUnknownClassType extends PDOMCPPUnknownBinding implements ICPPClassScope, ICPPUnknownClassType,
IPDOMMemberOwner, IIndexType, IIndexScope { IPDOMMemberOwner, IIndexType, IIndexScope {
private static final int KEY = PDOMCPPBinding.RECORD_SIZE + 0; // byte private static final int KEY = PDOMCPPBinding.RECORD_SIZE + 0; // byte
private static final int MEMBERLIST = PDOMCPPBinding.RECORD_SIZE + 4; private static final int MEMBERLIST = PDOMCPPBinding.RECORD_SIZE + 4;
@SuppressWarnings("hiding") @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; private ICPPScope unknownScope;
public PDOMCPPUnknownClassType(PDOMLinkage linkage, PDOMNode parent, ICPPUnknownClassType classType) throws CoreException { public PDOMCPPUnknownClassType(PDOMLinkage linkage, PDOMNode parent, ICPPUnknownClassType classType) throws CoreException {
super(linkage, parent, classType.getNameCharArray()); super(linkage, parent, classType);
setKind(classType); setKind(classType);
// linked list is initialized by storage being zero'd by malloc // linked list is initialized by storage being zero'd by malloc
@ -121,6 +120,7 @@ class PDOMCPPUnknownClassType extends PDOMCPPBinding implements ICPPClassScope,
return this; return this;
} }
@Override
public ICPPScope asScope() { public ICPPScope asScope() {
if (unknownScope == null) { if (unknownScope == null) {
unknownScope= new PDOMCPPUnknownScope(this, getUnknownName()); unknownScope= new PDOMCPPUnknownScope(this, getUnknownName());
@ -262,10 +262,6 @@ class PDOMCPPUnknownClassType extends PDOMCPPBinding implements ICPPClassScope,
return ICPPClassType.EMPTY_CLASS_ARRAY; return ICPPClassType.EMPTY_CLASS_ARRAY;
} }
public IASTName getUnknownName() {
return new CPPASTName(getNameCharArray());
}
public boolean isAnonymous() { public boolean isAnonymous() {
return false; return false;
} }