mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 299911. Signatures for evaluations.
This commit is contained in:
parent
77e792334f
commit
9ab42da077
20 changed files with 283 additions and 26 deletions
|
@ -63,6 +63,7 @@ public interface ITypeMarshalBuffer {
|
|||
ISerializableEvaluation unmarshalEvaluation() throws CoreException;
|
||||
int getByte() throws CoreException;
|
||||
int getShort() throws CoreException;
|
||||
int getInt() throws CoreException;
|
||||
long getLong() throws CoreException;
|
||||
char[] getCharArray() throws CoreException;
|
||||
|
||||
|
@ -72,6 +73,7 @@ public interface ITypeMarshalBuffer {
|
|||
void marshalEvaluation(ISerializableEvaluation eval, boolean includeValue) throws CoreException;
|
||||
void putByte(byte data);
|
||||
void putShort(short data);
|
||||
void putInt(int data);
|
||||
void putLong(long data);
|
||||
void putCharArray(char[] data);
|
||||
}
|
||||
|
|
|
@ -158,7 +158,7 @@ public class Value implements IValue {
|
|||
return parseLong(fExpression);
|
||||
}
|
||||
|
||||
public void marshall(TypeMarshalBuffer buf) throws CoreException {
|
||||
public void marshall(ITypeMarshalBuffer buf) throws CoreException {
|
||||
if (UNKNOWN == this) {
|
||||
buf.putByte((byte) (ITypeMarshalBuffer.VALUE | ITypeMarshalBuffer.FLAG1));
|
||||
} else {
|
||||
|
@ -183,7 +183,7 @@ public class Value implements IValue {
|
|||
}
|
||||
}
|
||||
|
||||
public static IValue unmarshal(TypeMarshalBuffer buf) throws CoreException {
|
||||
public static IValue unmarshal(ITypeMarshalBuffer buf) throws CoreException {
|
||||
int firstByte= buf.getByte();
|
||||
if (firstByte == TypeMarshalBuffer.NULL_TYPE)
|
||||
return null;
|
||||
|
|
|
@ -6,9 +6,8 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory;
|
||||
|
@ -24,10 +23,40 @@ public interface ICPPEvaluation extends ISerializableEvaluation {
|
|||
boolean isInitializerList();
|
||||
boolean isFunctionSet();
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the type of the expression depends on template parameters.
|
||||
*/
|
||||
boolean isTypeDependent();
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the value of the expression depends on template parameters.
|
||||
*/
|
||||
boolean isValueDependent();
|
||||
|
||||
|
||||
/**
|
||||
* TODO Add description
|
||||
*
|
||||
* @param point determines the scope for name lookups
|
||||
*/
|
||||
IType getTypeOrFunctionSet(IASTNode point);
|
||||
|
||||
/**
|
||||
* TODO Add description
|
||||
*
|
||||
* @param point determines the scope for name lookups
|
||||
*/
|
||||
IValue getValue(IASTNode point);
|
||||
|
||||
/**
|
||||
* TODO Add description
|
||||
*
|
||||
* @param point determines the scope for name lookups
|
||||
*/
|
||||
ValueCategory getValueCategory(IASTNode point);
|
||||
|
||||
/**
|
||||
* Returns a signature uniquely identifying the evaluation. Two evaluations with identical
|
||||
* signatures are guaranteed to produce the same results.
|
||||
*/
|
||||
char[] getSignature();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,228 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 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.dom.parser.cpp.semantics;
|
||||
|
||||
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.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.IValue;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation;
|
||||
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.Value;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
public abstract class CPPEvaluation implements ICPPEvaluation {
|
||||
|
||||
private static class SignatureBuilder implements ITypeMarshalBuffer {
|
||||
private static final byte NULL_TYPE= 0;
|
||||
private static final byte UNSTORABLE_TYPE= (byte) -1;
|
||||
private static final char[] HEX_DIGITS =
|
||||
{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
|
||||
private final StringBuilder fBuffer;
|
||||
private boolean hexMode;
|
||||
|
||||
/**
|
||||
* Constructor for input buffer.
|
||||
*/
|
||||
public SignatureBuilder() {
|
||||
fBuffer= new StringBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return fBuffer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void marshalBinding(IBinding binding) throws CoreException {
|
||||
if (binding instanceof ISerializableType) {
|
||||
((ISerializableType) binding).marshal(this);
|
||||
} else if (binding == null) {
|
||||
putByte(NULL_TYPE);
|
||||
} else {
|
||||
appendSeparator();
|
||||
IBinding owner= binding.getOwner();
|
||||
if (owner instanceof IType) {
|
||||
ASTTypeUtil.appendType((IType) owner, true, fBuffer);
|
||||
fBuffer.append("::"); //$NON-NLS-1$
|
||||
}
|
||||
fBuffer.append(binding.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void marshalType(IType type) throws CoreException {
|
||||
if (type instanceof ISerializableType) {
|
||||
((ISerializableType) type).marshal(this);
|
||||
} else if (type == null) {
|
||||
putByte(NULL_TYPE);
|
||||
} else if (type instanceof IBinding) {
|
||||
marshalBinding((IBinding) type);
|
||||
} else {
|
||||
assert false : "Cannot serialize " + ASTTypeUtil.getType(type) + " (" + type.getClass().getName() + ")"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
|
||||
putByte(UNSTORABLE_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void marshalEvaluation(ISerializableEvaluation eval, boolean includeValues) throws CoreException {
|
||||
if (eval == null) {
|
||||
putByte(NULL_TYPE);
|
||||
} else {
|
||||
eval.marshal(this, includeValues);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void marshalValue(IValue value) throws CoreException {
|
||||
if (value instanceof Value) {
|
||||
((Value) value).marshall(this);
|
||||
} else {
|
||||
putByte(NULL_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putByte(byte b) {
|
||||
appendHexDigit(b >> 4);
|
||||
appendHexDigit(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putShort(short value) {
|
||||
appendHexDigit(value >> 12);
|
||||
appendHexDigit(value >> 8);
|
||||
appendHexDigit(value >> 4);
|
||||
appendHexDigit(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putInt(int value) {
|
||||
appendHexDigit(value >> 28);
|
||||
appendHexDigit(value >> 24);
|
||||
appendHexDigit(value >> 20);
|
||||
appendHexDigit(value >> 16);
|
||||
appendHexDigit(value >> 12);
|
||||
appendHexDigit(value >> 8);
|
||||
appendHexDigit(value >> 4);
|
||||
appendHexDigit(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putLong(long value) {
|
||||
appendHexDigit((int) (value >> 60));
|
||||
appendHexDigit((int) (value >> 56));
|
||||
appendHexDigit((int) (value >> 52));
|
||||
appendHexDigit((int) (value >> 48));
|
||||
appendHexDigit((int) (value >> 44));
|
||||
appendHexDigit((int) (value >> 40));
|
||||
appendHexDigit((int) (value >> 36));
|
||||
appendHexDigit((int) (value >> 32));
|
||||
appendHexDigit((int) (value >> 28));
|
||||
appendHexDigit((int) (value >> 24));
|
||||
appendHexDigit((int) (value >> 20));
|
||||
appendHexDigit((int) (value >> 16));
|
||||
appendHexDigit((int) (value >> 12));
|
||||
appendHexDigit((int) (value >> 8));
|
||||
appendHexDigit((int) (value >> 4));
|
||||
appendHexDigit((int) value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putCharArray(char[] chars) {
|
||||
appendSeparator();
|
||||
for (char c : chars) {
|
||||
fBuffer.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
private void appendHexDigit(int val) {
|
||||
if (hexMode) {
|
||||
appendSeparator();
|
||||
fBuffer.append("0x"); //$NON-NLS-1$
|
||||
hexMode = true;
|
||||
}
|
||||
fBuffer.append(HEX_DIGITS[val & 0xF]);
|
||||
}
|
||||
|
||||
private void appendSeparator() {
|
||||
if (fBuffer.length() != 0)
|
||||
fBuffer.append(' ');
|
||||
hexMode = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding unmarshalBinding() throws CoreException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IType unmarshalType() throws CoreException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISerializableEvaluation unmarshalEvaluation() throws CoreException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IValue unmarshalValue() throws CoreException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getByte() throws CoreException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CoreException unmarshallingError() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getShort() throws CoreException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt() throws CoreException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLong() throws CoreException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] getCharArray() throws CoreException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] getSignature() {
|
||||
SignatureBuilder buf = new SignatureBuilder();
|
||||
try {
|
||||
marshal(buf, true);
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return new char[] { '?' };
|
||||
}
|
||||
return buf.toString().toCharArray();
|
||||
}
|
||||
}
|
|
@ -43,7 +43,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
/**
|
||||
* Performs evaluation of an expression.
|
||||
*/
|
||||
public class EvalBinary implements ICPPEvaluation {
|
||||
public class EvalBinary extends CPPEvaluation {
|
||||
public final static int op_arrayAccess= Byte.MAX_VALUE;
|
||||
private final int fOperator;
|
||||
|
||||
|
|
|
@ -23,13 +23,12 @@ 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.dom.parser.cpp.CPPBasicType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* Performs evaluation of an expression.
|
||||
*/
|
||||
public class EvalBinaryTypeId implements ICPPEvaluation {
|
||||
public class EvalBinaryTypeId extends CPPEvaluation {
|
||||
private final Operator fOperator;
|
||||
private final IType fType1, fType2;
|
||||
|
||||
|
|
|
@ -27,11 +27,10 @@ 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.ProblemType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.Value;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
public class EvalBinding implements ICPPEvaluation {
|
||||
public class EvalBinding extends CPPEvaluation {
|
||||
private final IBinding fBinding;
|
||||
private final boolean fFixedType;
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.eclipse.cdt.internal.core.dom.parser.Value;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
public class EvalComma implements ICPPEvaluation {
|
||||
public class EvalComma extends CPPEvaluation {
|
||||
private static final ICPPFunction[] NO_FUNCTIONS = {};
|
||||
|
||||
private final ICPPEvaluation[] fArguments;
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
/**
|
||||
* Performs evaluation of an expression.
|
||||
*/
|
||||
public class EvalCompound implements ICPPEvaluation {
|
||||
public class EvalCompound extends CPPEvaluation {
|
||||
private final ICPPEvaluation fDelegate;
|
||||
|
||||
public EvalCompound(ICPPEvaluation delegate) {
|
||||
|
|
|
@ -41,7 +41,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
/**
|
||||
* Performs evaluation of an expression.
|
||||
*/
|
||||
public class EvalConditional implements ICPPEvaluation {
|
||||
public class EvalConditional extends CPPEvaluation {
|
||||
private final ICPPEvaluation fCondition, fPositive, fNegative;
|
||||
private final boolean fPositiveThrows, fNegativeThrows;
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
/**
|
||||
* Performs evaluation of an expression.
|
||||
*/
|
||||
public class EvalFixed implements ICPPEvaluation {
|
||||
public class EvalFixed extends CPPEvaluation {
|
||||
public static final ICPPEvaluation INCOMPLETE =
|
||||
new EvalFixed(ProblemType.UNKNOWN_FOR_EXPRESSION, PRVALUE, Value.UNKNOWN);
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics.LookupMode;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
public class EvalFunctionCall implements ICPPEvaluation {
|
||||
public class EvalFunctionCall extends CPPEvaluation {
|
||||
private final ICPPEvaluation[] fArguments;
|
||||
private ICPPFunction fOverload= CPPFunction.UNINITIALIZED_FUNCTION;
|
||||
private IType fType;
|
||||
|
|
|
@ -21,14 +21,13 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
|||
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.Value;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* Performs evaluation of an expression.
|
||||
*/
|
||||
public class EvalFunctionSet implements ICPPEvaluation {
|
||||
public class EvalFunctionSet extends CPPEvaluation {
|
||||
private final CPPFunctionSet fFunctionSet;
|
||||
private final boolean fAddressOf;
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
public class EvalID implements ICPPEvaluation {
|
||||
public class EvalID extends CPPEvaluation {
|
||||
private final ICPPEvaluation fFieldOwner;
|
||||
private final char[] fName;
|
||||
private final IBinding fNameOwner;
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
/**
|
||||
* Performs evaluation of an expression.
|
||||
*/
|
||||
public class EvalInitList implements ICPPEvaluation {
|
||||
public class EvalInitList extends CPPEvaluation {
|
||||
private final ICPPEvaluation[] fClauses;
|
||||
|
||||
public EvalInitList(ICPPEvaluation[] clauses) {
|
||||
|
|
|
@ -46,7 +46,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics.LookupMode;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
public class EvalMemberAccess implements ICPPEvaluation {
|
||||
public class EvalMemberAccess extends CPPEvaluation {
|
||||
private final IType fOwnerType;
|
||||
private final IBinding fMember;
|
||||
private final ValueCategory fOwnerValueCategory;
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
/**
|
||||
* Performs evaluation of an expression.
|
||||
*/
|
||||
public class EvalTypeId implements ICPPEvaluation {
|
||||
public class EvalTypeId extends CPPEvaluation {
|
||||
private final IType fInputType;
|
||||
private final ICPPEvaluation[] fArguments;
|
||||
private IType fOutputType;
|
||||
|
|
|
@ -39,7 +39,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics.LookupMode;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
public class EvalUnary implements ICPPEvaluation {
|
||||
public class EvalUnary extends CPPEvaluation {
|
||||
private static final ICPPEvaluation ZERO_EVAL = new EvalFixed(CPPSemantics.INT_TYPE, PRVALUE, Value.create(0));
|
||||
|
||||
private final int fOperator;
|
||||
|
|
|
@ -23,10 +23,9 @@ 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.dom.parser.cpp.CPPBasicType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
public class EvalUnaryTypeID implements ICPPEvaluation {
|
||||
public class EvalUnaryTypeID extends CPPEvaluation {
|
||||
private final int fOperator;
|
||||
private final IType fOrigType;
|
||||
private IType fType;
|
||||
|
|
|
@ -117,7 +117,7 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer {
|
|||
} else if (type instanceof IBinding) {
|
||||
marshalBinding((IBinding) type);
|
||||
} else {
|
||||
assert false : "Cannot serialize " + ASTTypeUtil.getType(type) + "(" + type.getClass().getName() + ")"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
|
||||
assert false : "Cannot serialize " + ASTTypeUtil.getType(type) + " (" + type.getClass().getName() + ")"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
|
||||
putByte(UNSTORABLE_TYPE);
|
||||
}
|
||||
}
|
||||
|
@ -239,6 +239,7 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer {
|
|||
return (((byte1 << 8) | (byte2 & 0xff)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putInt(int value) {
|
||||
request(4);
|
||||
fPos += 4;
|
||||
|
@ -249,6 +250,7 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer {
|
|||
fBuffer[--p]= (byte) (value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt() throws CoreException {
|
||||
if (fPos + 4 > fBuffer.length)
|
||||
throw unmarshallingError();
|
||||
|
|
Loading…
Add table
Reference in a new issue