mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 299911: Directly marshall template arguments rather than their type
and value.
This commit is contained in:
parent
5f6822ec53
commit
6b971d2cac
10 changed files with 98 additions and 60 deletions
|
@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
|
||||
import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.IValue;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameterPackType;
|
||||
|
@ -27,9 +28,15 @@ import org.eclipse.core.runtime.Assert;
|
|||
public class CPPTemplateNonTypeArgument implements ICPPTemplateArgument {
|
||||
private final ICPPEvaluation fEvaluation;
|
||||
|
||||
public CPPTemplateNonTypeArgument(ICPPEvaluation evaluation) {
|
||||
public CPPTemplateNonTypeArgument(ICPPEvaluation evaluation, IASTNode point) {
|
||||
Assert.isNotNull(evaluation);
|
||||
if (evaluation instanceof EvalFixed || point == null ||
|
||||
evaluation.isTypeDependent() || evaluation.isValueDependent()) {
|
||||
fEvaluation= evaluation;
|
||||
} else {
|
||||
fEvaluation= new EvalFixed(evaluation.getTypeOrFunctionSet(point),
|
||||
evaluation.getValueCategory(point), evaluation.getValue(point));
|
||||
}
|
||||
}
|
||||
|
||||
public CPPTemplateNonTypeArgument(IValue value, IType type) {
|
||||
|
@ -84,7 +91,7 @@ public class CPPTemplateNonTypeArgument implements ICPPTemplateArgument {
|
|||
} else {
|
||||
evaluation = new EvalTypeId(t, fEvaluation);
|
||||
}
|
||||
return new CPPTemplateNonTypeArgument(evaluation);
|
||||
return new CPPTemplateNonTypeArgument(evaluation, null);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -1079,7 +1079,7 @@ public class CPPTemplates {
|
|||
final ICPPEvaluation newEval= eval.instantiate(tpMap, packOffset, within, Value.MAX_RECURSION_DEPTH, point);
|
||||
if (eval == newEval)
|
||||
return arg;
|
||||
return new CPPTemplateNonTypeArgument(newEval);
|
||||
return new CPPTemplateNonTypeArgument(newEval, point);
|
||||
}
|
||||
|
||||
final IType orig= arg.getTypeValue();
|
||||
|
@ -1677,7 +1677,7 @@ public class CPPTemplates {
|
|||
result[i]= new CPPTemplateTypeArgument(CPPVisitor.createType((IASTTypeId) arg));
|
||||
} else if (arg instanceof ICPPASTExpression) {
|
||||
ICPPASTExpression expr= (ICPPASTExpression) arg;
|
||||
result[i]= new CPPTemplateNonTypeArgument(expr.getEvaluation());
|
||||
result[i]= new CPPTemplateNonTypeArgument(expr.getEvaluation(), expr);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unexpected type: " + arg.getClass().getName()); //$NON-NLS-1$
|
||||
}
|
||||
|
@ -2282,7 +2282,7 @@ public class CPPTemplates {
|
|||
for (ICPPFunction f : functionSet.getBindings()) {
|
||||
if (p.isSameType(f.getType())) {
|
||||
functionSet.applySelectedFunction(f);
|
||||
return new CPPTemplateNonTypeArgument(new EvalBinding(f, null));
|
||||
return new CPPTemplateNonTypeArgument(new EvalBinding(f, null), point);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ public class TemplateInstanceUtil {
|
|||
ICPPEvaluation eval = arg.getNonTypeEvaluation();
|
||||
ICPPEvaluation eval2 = ((CPPCompositesFactory) cf).getCompositeEvaluation(eval);
|
||||
if (eval2 != eval) {
|
||||
return new CPPTemplateNonTypeArgument(eval2);
|
||||
return new CPPTemplateNonTypeArgument(eval2, null);
|
||||
}
|
||||
}
|
||||
return arg;
|
||||
|
|
|
@ -219,10 +219,11 @@ public class PDOM extends PlatformObject implements IPDOM {
|
|||
* #125.0# - Indexes for unresolved includes and files indexed with I/O errors. <<CDT 8.1>>
|
||||
* 126.0 - Dependent expressions, bug 299911.
|
||||
* 127.0 - Explicit virtual overrides, bug 380623.
|
||||
* 128.0 - Merged index affecting changes from the master branch.
|
||||
*/
|
||||
private static final int MIN_SUPPORTED_VERSION= version(127, 0);
|
||||
private static final int MAX_SUPPORTED_VERSION= version(127, Short.MAX_VALUE);
|
||||
private static final int DEFAULT_VERSION = version(127, 0);
|
||||
private static final int MIN_SUPPORTED_VERSION= version(128, 0);
|
||||
private static final int MAX_SUPPORTED_VERSION= version(128, Short.MAX_VALUE);
|
||||
private static final int DEFAULT_VERSION = version(128, 0);
|
||||
|
||||
private static int version(int major, int minor) {
|
||||
return (major << 16) + minor;
|
||||
|
|
|
@ -77,6 +77,7 @@ public class Database {
|
|||
public static final int PTR_SIZE = 4; // size of a pointer in the database in bytes
|
||||
public static final int TYPE_SIZE = 2+PTR_SIZE; // size of a type in the database in bytes
|
||||
public static final int VALUE_SIZE = TYPE_SIZE; // size of a value in the database in bytes
|
||||
public static final int ARGUMENT_SIZE = TYPE_SIZE; // size of a template argument in the database in bytes
|
||||
public static final long MAX_DB_SIZE= ((long) 1 << (Integer.SIZE + BLOCK_SIZE_DELTA_BITS));
|
||||
|
||||
|
||||
|
|
|
@ -201,7 +201,7 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer {
|
|||
public ICPPTemplateArgument unmarshalTemplateArgument() throws CoreException {
|
||||
int firstByte= getByte();
|
||||
if (firstByte == VALUE) {
|
||||
return new CPPTemplateNonTypeArgument((ICPPEvaluation) unmarshalEvaluation());
|
||||
return new CPPTemplateNonTypeArgument((ICPPEvaluation) unmarshalEvaluation(), null);
|
||||
} else {
|
||||
fPos--;
|
||||
return new CPPTemplateTypeArgument(unmarshalType());
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.IType;
|
|||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.IValue;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
|
||||
import org.eclipse.cdt.core.index.IIndexLinkage;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayMap;
|
||||
|
@ -496,6 +497,68 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
|||
return new TypeMarshalBuffer(this, data).unmarshalType();
|
||||
}
|
||||
|
||||
public void storeTemplateArgument(long offset, ICPPTemplateArgument arg) throws CoreException {
|
||||
final Database db= getDB();
|
||||
deleteArgument(db, offset);
|
||||
storeArgument(db, offset, arg);
|
||||
}
|
||||
|
||||
private void storeArgument(Database db, long offset, ICPPTemplateArgument arg) throws CoreException {
|
||||
if (arg != null) {
|
||||
TypeMarshalBuffer bc= new TypeMarshalBuffer(this);
|
||||
bc.marshalTemplateArgument(arg);
|
||||
int len= bc.getPosition();
|
||||
if (len > 0) {
|
||||
if (len <= Database.ARGUMENT_SIZE) {
|
||||
db.putBytes(offset, bc.getBuffer(), len);
|
||||
} else if (len <= Database.MAX_MALLOC_SIZE-2){
|
||||
long ptr= db.malloc(len+2);
|
||||
db.putShort(ptr, (short) len);
|
||||
db.putBytes(ptr+2, bc.getBuffer(), len);
|
||||
db.putByte(offset, TypeMarshalBuffer.INDIRECT_TYPE);
|
||||
db.putRecPtr(offset+2, ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteArgument(Database db, long offset) throws CoreException {
|
||||
byte firstByte= db.getByte(offset);
|
||||
if (firstByte == TypeMarshalBuffer.INDIRECT_TYPE) {
|
||||
long ptr= db.getRecPtr(offset+2);
|
||||
clearArgument(db, offset);
|
||||
db.free(ptr);
|
||||
} else {
|
||||
clearArgument(db, offset);
|
||||
}
|
||||
}
|
||||
|
||||
private void clearArgument(Database db, long offset) throws CoreException {
|
||||
db.clearBytes(offset, Database.ARGUMENT_SIZE);
|
||||
}
|
||||
|
||||
public ICPPTemplateArgument loadTemplateArgument(long offset) throws CoreException {
|
||||
final Database db= getDB();
|
||||
final byte firstByte= db.getByte(offset);
|
||||
byte[] data= null;
|
||||
switch(firstByte) {
|
||||
case TypeMarshalBuffer.INDIRECT_TYPE:
|
||||
long ptr= db.getRecPtr(offset+2);
|
||||
int len= db.getShort(ptr) & 0xffff;
|
||||
data= new byte[len];
|
||||
db.getBytes(ptr+2, data);
|
||||
break;
|
||||
case TypeMarshalBuffer.UNSTORABLE_TYPE:
|
||||
case TypeMarshalBuffer.NULL_TYPE:
|
||||
return null;
|
||||
default:
|
||||
data= new byte[Database.TYPE_SIZE];
|
||||
db.getBytes(offset, data);
|
||||
break;
|
||||
}
|
||||
return new TypeMarshalBuffer(this, data).unmarshalTemplateArgument();
|
||||
}
|
||||
|
||||
public void storeValue(long offset, IValue type) throws CoreException {
|
||||
final Database db= getDB();
|
||||
deleteValue(db, offset);
|
||||
|
|
|
@ -11,11 +11,8 @@
|
|||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||
|
||||
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.core.dom.ast.cpp.ICPPTemplateArgument;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||
|
@ -27,8 +24,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
* Collects methods to store an argument list in the database
|
||||
*/
|
||||
public class PDOMCPPArgumentList {
|
||||
private static final int VALUE_OFFSET= Database.TYPE_SIZE;
|
||||
private static final int NODE_SIZE = VALUE_OFFSET + Database.VALUE_SIZE;
|
||||
private static final int NODE_SIZE = Database.ARGUMENT_SIZE;
|
||||
|
||||
/**
|
||||
* Stores the given template arguments in the database.
|
||||
|
@ -45,13 +41,7 @@ public class PDOMCPPArgumentList {
|
|||
p += 2;
|
||||
for (int i= 0; i < len; i++, p += NODE_SIZE) {
|
||||
final ICPPTemplateArgument arg = templateArguments[i];
|
||||
final boolean isNonType= arg.isNonTypeValue();
|
||||
if (isNonType) {
|
||||
linkage.storeType(p, arg.getTypeOfNonTypeValue());
|
||||
linkage.storeValue(p + VALUE_OFFSET, arg.getNonTypeValue());
|
||||
} else {
|
||||
linkage.storeType(p, arg.getTypeValue());
|
||||
}
|
||||
linkage.storeTemplateArgument(p, arg);
|
||||
}
|
||||
return block;
|
||||
}
|
||||
|
@ -67,8 +57,7 @@ public class PDOMCPPArgumentList {
|
|||
Assert.isTrue(len >= 0 && len <= (Database.MAX_MALLOC_SIZE - 2) / NODE_SIZE);
|
||||
long p= record + 2;
|
||||
for (int i= 0; i < len; i++) {
|
||||
linkage.storeType(p, null);
|
||||
linkage.storeValue(p + VALUE_OFFSET, null);
|
||||
linkage.storeTemplateArgument(p, null);
|
||||
p+= NODE_SIZE;
|
||||
}
|
||||
db.free(record);
|
||||
|
@ -90,16 +79,11 @@ public class PDOMCPPArgumentList {
|
|||
rec += 2;
|
||||
ICPPTemplateArgument[] result= new ICPPTemplateArgument[len];
|
||||
for (int i= 0; i < len; i++) {
|
||||
IType type= linkage.loadType(rec);
|
||||
if (type == null) {
|
||||
type= new ProblemType(ISemanticProblem.TYPE_NOT_PERSISTED);
|
||||
}
|
||||
IValue val= linkage.loadValue(rec + VALUE_OFFSET);
|
||||
if (val != null) {
|
||||
result[i]= new CPPTemplateNonTypeArgument(val, type);
|
||||
} else {
|
||||
result[i]= new CPPTemplateTypeArgument(type);
|
||||
ICPPTemplateArgument arg= linkage.loadTemplateArgument(rec);
|
||||
if (arg == null) {
|
||||
arg= new CPPTemplateTypeArgument(new ProblemType(ISemanticProblem.TYPE_NOT_PERSISTED));
|
||||
}
|
||||
result[i]= arg;
|
||||
rec += NODE_SIZE;
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -39,9 +39,9 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPBinding
|
|||
implements IPDOMMemberOwner, ICPPTemplateNonTypeParameter, IPDOMCPPTemplateParameter {
|
||||
private static final int TYPE_OFFSET= PDOMCPPBinding.RECORD_SIZE;
|
||||
private static final int PARAMETERID= TYPE_OFFSET + Database.TYPE_SIZE;
|
||||
private static final int DEFAULTVAL= PARAMETERID + Database.VALUE_SIZE;
|
||||
private static final int DEFAULTVAL= PARAMETERID + 4;
|
||||
@SuppressWarnings("hiding")
|
||||
protected static final int RECORD_SIZE = DEFAULTVAL + Database.PTR_SIZE;
|
||||
protected static final int RECORD_SIZE = DEFAULTVAL + Database.VALUE_SIZE;
|
||||
|
||||
private int fCachedParamID= -1;
|
||||
private volatile IType fType;
|
||||
|
|
|
@ -11,12 +11,9 @@
|
|||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||
|
||||
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.core.dom.ast.cpp.ICPPTemplateArgument;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateNonTypeArgument;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||
|
@ -28,9 +25,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
* Collects methods to store an argument list in the database
|
||||
*/
|
||||
public class PDOMCPPTemplateParameterMap {
|
||||
private static final int TYPE_OFFSET= 0;
|
||||
private static final int VALUE_OFFSET= TYPE_OFFSET + Database.TYPE_SIZE;
|
||||
private static final int NODE_SIZE = VALUE_OFFSET + Database.VALUE_SIZE;
|
||||
private static final int NODE_SIZE = Database.ARGUMENT_SIZE;
|
||||
|
||||
/**
|
||||
* Stores the given template parameter map in the database.
|
||||
|
@ -78,12 +73,7 @@ public class PDOMCPPTemplateParameterMap {
|
|||
|
||||
private static void storeArgument(final Database db, final PDOMLinkage linkage, long p,
|
||||
final ICPPTemplateArgument arg) throws CoreException {
|
||||
if (arg.isNonTypeValue()) {
|
||||
linkage.storeType(p + TYPE_OFFSET, arg.getTypeOfNonTypeValue());
|
||||
linkage.storeValue(p + VALUE_OFFSET, arg.getNonTypeValue());
|
||||
} else {
|
||||
linkage.storeType(p + TYPE_OFFSET, arg.getTypeValue());
|
||||
}
|
||||
linkage.storeTemplateArgument(p, arg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -102,8 +92,7 @@ public class PDOMCPPTemplateParameterMap {
|
|||
if (packSize == -1)
|
||||
packSize= 1;
|
||||
for (int j = 0; j < packSize; j++) {
|
||||
linkage.storeType(p + TYPE_OFFSET, null);
|
||||
linkage.storeValue(p + VALUE_OFFSET, null);
|
||||
linkage.storeTemplateArgument(p, null);
|
||||
p+= NODE_SIZE;
|
||||
}
|
||||
}
|
||||
|
@ -143,16 +132,9 @@ public class PDOMCPPTemplateParameterMap {
|
|||
|
||||
private static ICPPTemplateArgument readArgument(long rec, final PDOMLinkage linkage, final Database db)
|
||||
throws CoreException {
|
||||
IType type= linkage.loadType(rec + TYPE_OFFSET);
|
||||
if (type == null) {
|
||||
type= new ProblemType(ISemanticProblem.TYPE_NOT_PERSISTED);
|
||||
}
|
||||
IValue val= linkage.loadValue(rec + VALUE_OFFSET);
|
||||
ICPPTemplateArgument arg;
|
||||
if (val != null) {
|
||||
arg= new CPPTemplateNonTypeArgument(val, type);
|
||||
} else {
|
||||
arg= new CPPTemplateTypeArgument(type);
|
||||
ICPPTemplateArgument arg = linkage.loadTemplateArgument(rec);
|
||||
if (arg == null) {
|
||||
arg= new CPPTemplateTypeArgument(new ProblemType(ISemanticProblem.TYPE_NOT_PERSISTED));
|
||||
}
|
||||
return arg;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue