本文整理汇总了C#中JSExpression.GetActualType方法的典型用法代码示例。如果您正苦于以下问题:C# JSExpression.GetActualType方法的具体用法?C# JSExpression.GetActualType怎么用?C# JSExpression.GetActualType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSExpression
的用法示例。
在下文中一共展示了JSExpression.GetActualType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FilterInvocationResult
public static JSExpression FilterInvocationResult(
MethodReference methodReference, MethodInfo method,
JSExpression result,
ITypeInfoSource typeInfo, TypeSystem typeSystem
)
{
if (method == null)
return result;
var resultType = result.GetActualType(typeSystem);
var resultIsPackedArray = PackedArrayUtil.IsPackedArrayType(resultType);
var returnValueAttribute = method.Metadata.GetAttribute("JSIL.Meta.JSPackedArrayReturnValueAttribute");
if (returnValueAttribute != null) {
if (TypeUtil.IsOpenType(resultType)) {
// FIXME: We need to restrict substitution to when the result type is a generic parameter owned by the invocation...
resultType = JSExpression.SubstituteTypeArgs(typeInfo, resultType, methodReference);
}
if (!resultIsPackedArray)
return JSChangeTypeExpression.New(result, PackedArrayUtil.MakePackedArrayType(resultType, returnValueAttribute.Entries.First().Type), typeSystem);
}
return result;
}
示例2: FixupThisArgument
protected JSExpression FixupThisArgument(JSExpression thisArgument, TypeSystem typeSystem)
{
var expectedType = thisArgument.GetActualType(typeSystem);
if (expectedType.FullName == "System.Type")
return new JSPublicInterfaceOfExpression(thisArgument);
return thisArgument;
}
示例3: FilterInvocationResult
public static JSExpression FilterInvocationResult(MethodInfo method, JSExpression result, TypeSystem typeSystem)
{
if (method == null)
return result;
var resultType = result.GetActualType(typeSystem);
var resultIsPackedArray = PackedArrayUtil.IsPackedArrayType(resultType);
var returnValueAttribute = method.Metadata.GetAttribute("JSIL.Meta.JSPackedArrayReturnValueAttribute");
if (returnValueAttribute != null) {
if (!resultIsPackedArray)
return JSChangeTypeExpression.New(result, PackedArrayUtil.MakePackedArrayType(resultType, returnValueAttribute.Entries.First().Type), typeSystem);
}
return result;
}
示例4: CheckReturnValue
public static void CheckReturnValue(MethodInfo method, JSExpression returnValue, TypeSystem typeSystem)
{
if (method == null)
return;
var resultType = returnValue.GetActualType(typeSystem);
var resultIsPackedArray = PackedArrayUtil.IsPackedArrayType(resultType);
var returnValueAttribute = method.Metadata.GetAttribute("JSIL.Meta.JSPackedArrayReturnValueAttribute");
if (returnValueAttribute != null) {
if (!resultIsPackedArray)
throw new ArgumentException(
"Return value of method '" + method.Name + "' must be a packed array."
);
} else {
if (resultIsPackedArray)
throw new ArgumentException(
"Return value of method '" + method.Name + "' is a packed array. " +
"For this to be valid you must attach a JSPackedArrayReturnValueAttribute to the method."
);
}
}
示例5: IsCopyNeeded
protected bool IsCopyNeeded(JSExpression value)
{
if ((value == null) || (value.IsNull))
return false;
while (value is JSReferenceExpression)
value = ((JSReferenceExpression)value).Referent;
var valueType = value.GetActualType(TypeSystem);
if (!TypeUtil.IsStruct(valueType))
return false;
if (valueType.FullName.StartsWith("System.Nullable"))
return false;
if (
(value is JSLiteral) ||
(value is JSNewExpression) ||
(value is JSPassByReferenceExpression)
) {
return false;
}
// If the expression is a parameter that is only used once and isn't aliased,
// we don't need to copy it.
var rightVar = value as JSVariable;
if (rightVar != null) {
int referenceCount;
if (
ReferenceCounts.TryGetValue(rightVar.Identifier, out referenceCount) &&
(referenceCount == 1) && !rightVar.IsReference && rightVar.IsParameter &&
!SecondPass.VariableAliases.ContainsKey(rightVar.Identifier)
) {
if (Tracing)
Debug.WriteLine(String.Format("Returning false from IsCopyNeeded for parameter {0} because reference count is 1 and it has no aliases", value));
return false;
}
}
var rightInvocation = value as JSInvocationExpression;
if (rightInvocation == null)
return true;
var invokeMethod = rightInvocation.JSMethod;
if (invokeMethod == null)
return true;
var secondPass = FunctionSource.GetSecondPass(invokeMethod);
if (secondPass == null)
return true;
// If this expression is the return value of a function invocation, we can eliminate struct
// copies if the return value is a 'new' expression.
if (secondPass.ResultIsNew)
return false;
// We can also eliminate a return value copy if the return value is one of the function's
// arguments, and we are sure that argument does not need a copy either.
if (secondPass.ResultVariable != null) {
var parameters = invokeMethod.Method.Parameters;
int parameterIndex = -1;
for (var i = 0; i < parameters.Length; i++) {
if (parameters[i].Name != secondPass.ResultVariable)
continue;
parameterIndex = i;
break;
}
if (parameterIndex < 0)
return true;
return IsCopyNeeded(rightInvocation.Arguments[parameterIndex]);
}
return true;
}
示例6: ValueOfNullable
public JSInvocationExpression ValueOfNullable(JSExpression nullableExpression)
{
var valueType = nullableExpression.GetActualType(TypeSystem);
valueType = TypeUtil.StripNullable(valueType);
return JSInvocationExpression.InvokeStatic(
Dot("ValueOfNullable", valueType),
new[] { nullableExpression }, true
);
}
示例7: NewReference
public JSNewExpression NewReference(JSExpression initialValue)
{
var resultType = new ByReferenceType(initialValue.GetActualType(TypeSystem));
return new JSNewExpression(
Dot("Variable", resultType),
null, null, initialValue
);
}
示例8: NewElementReference
public JSNewArrayElementReference NewElementReference (JSExpression target, JSExpression index) {
var arrayType = TypeUtil.DereferenceType(target.GetActualType(TypeSystem));
TypeReference resultType;
if (PackedArrayUtil.IsPackedArrayType(arrayType)) {
resultType = new ByReferenceType(
PackedArrayUtil.GetElementType(arrayType)
);
} else if (TypeUtil.IsArray(arrayType)) {
resultType = new ByReferenceType(
TypeUtil.GetElementType(arrayType, true)
);
} else {
throw new ArgumentException("Cannot create a reference to an element of a value of type '" + arrayType.FullName + "'", target.ToString());
}
if (PackedArrayUtil.IsPackedArrayType(target.GetActualType(TypeSystem)))
return new JSNewPackedArrayElementReference(resultType, target, index);
else
return new JSNewArrayElementReference(resultType, target, index);
}
示例9: IsCopyNeeded
protected bool IsCopyNeeded (
JSExpression value,
out GenericParameter relevantParameter,
bool allowImmutabilityOptimizations = true
) {
relevantParameter = null;
if ((value == null) || (value.IsNull))
return false;
value = JSReferenceExpression.Strip(value);
var sce = value as JSStructCopyExpression;
if (sce != null)
return false;
var valueType = value.GetActualType(TypeSystem);
var valueTypeDerefed = TypeUtil.DereferenceType(valueType) ?? valueType;
var cte = value as JSChangeTypeExpression;
var cast = value as JSCastExpression;
TypeReference originalType;
int temp;
if (cte != null) {
originalType = cte.Expression.GetActualType(TypeSystem);
} else if (cast != null) {
originalType = cast.Expression.GetActualType(TypeSystem);
} else {
originalType = null;
}
if (originalType != null) {
originalType = TypeUtil.FullyDereferenceType(originalType, out temp);
if (!IsStructOrGenericParameter(valueTypeDerefed) && !IsStructOrGenericParameter(originalType))
return false;
relevantParameter = (originalType as GenericParameter) ?? (valueTypeDerefed as GenericParameter);
} else {
if (!IsStructOrGenericParameter(valueTypeDerefed))
return false;
relevantParameter = (valueTypeDerefed as GenericParameter);
}
if (value is JSValueOfNullableExpression)
return true;
if (IsTypeExcludedFromCopies(valueType))
return false;
if (
(value is JSLiteral) ||
(value is JSNewExpression) ||
(value is JSPassByReferenceExpression) ||
(value is JSNewBoxedVariable) ||
(value is JSDefaultValueLiteral) ||
(value is JSFieldOfExpression)
) {
return false;
}
if (!OptimizeCopies)
return true;
if (IsImmutable(value) && allowImmutabilityOptimizations)
return false;
var valueDot = value as JSDotExpressionBase;
// The value is being read out of an element proxy
if (
(valueDot != null) &&
PackedArrayUtil.IsElementProxy(valueDot.Target)
) {
// BROKEN: no copy is necessary - the read unpacks the value on demand from the packed array.
// return false;
// HACK: Currently struct fields are proxies so that writes to them work correctly.
// FIXME: Maybe return true here always?
// return true;
}
var valueTypeInfo = TypeInfo.GetExisting(valueType);
if ((valueTypeInfo != null) && valueTypeInfo.IsImmutable && allowImmutabilityOptimizations)
return false;
// If the expression is a parameter that is only used once and isn't aliased,
// we don't need to copy it.
var rightVar = value as JSVariable;
if (rightVar != null) {
int referenceCount;
if (
ReferenceCounts.TryGetValue(rightVar.Identifier, out referenceCount) &&
(referenceCount == 1) &&
!rightVar.IsReference &&
rightVar.IsParameter &&
!SecondPass.VariableAliases.ContainsKey(rightVar.Identifier)
//.........这里部分代码省略.........
示例10: Translate_PropertyCall
protected JSExpression Translate_PropertyCall(JSExpression thisExpression, JSMethod method, JSExpression[] arguments, bool @virtual, bool @static)
{
var propertyInfo = method.Method.DeclaringProperty;
if (propertyInfo == null)
return null;
if (propertyInfo.IsIgnored)
return new JSIgnoredMemberReference(true, propertyInfo, arguments);
// JS provides no way to override [], so keep it as a regular method call
if (propertyInfo.Member.IsIndexer())
return null;
var parms = method.Method.Metadata.GetAttributeParameters("JSIL.Meta.JSReplacement") ??
propertyInfo.Metadata.GetAttributeParameters("JSIL.Meta.JSReplacement");
if (parms != null) {
var argsDict = new Dictionary<string, JSExpression>();
argsDict["this"] = thisExpression;
argsDict["typeof(this)"] = Translate_TypeOf(thisExpression.GetActualType(TypeSystem));
foreach (var kvp in method.Method.Parameters.Zip(arguments, (p, v) => new { p.Name, Value = v })) {
argsDict.Add(kvp.Name, kvp.Value);
}
return new JSVerbatimLiteral(method, (string)parms[0].Value, argsDict, propertyInfo.ReturnType);
}
var thisType = TypeUtil.GetTypeDefinition(thisExpression.GetActualType(TypeSystem));
Func<JSExpression> generate = () => {
var actualThis = @static ? new JSType(method.Method.DeclaringType.Definition) : thisExpression;
if ((method.Reference.DeclaringType is GenericInstanceType) && !method.Reference.HasThis) {
actualThis = new JSType(method.Reference.DeclaringType);
}
if ((propertyInfo.Member.GetMethod != null) && (method.Method.Member.Name == propertyInfo.Member.GetMethod.Name)) {
return new JSPropertyAccess(
actualThis, new JSProperty(method.Reference, propertyInfo)
);
} else {
if (arguments.Length == 0) {
throw new InvalidOperationException(String.Format(
"The property setter '{0}' was invoked without arguments",
method
));
}
return new JSBinaryOperatorExpression(
JSOperator.Assignment,
new JSPropertyAccess(
actualThis, new JSProperty(method.Reference, propertyInfo)
),
arguments[0], propertyInfo.ReturnType
);
}
};
// Accesses to a base property should go through a regular method invocation, since
// javascript properties do not have a mechanism for base access
if (method.Method.Member.HasThis) {
if (!TypeUtil.TypesAreEqual(method.Method.DeclaringType.Definition, thisType) && [email protected]) {
return null;
} else {
return generate();
}
}
return generate();
}
示例11: Translate_MethodReplacement
protected JSExpression Translate_MethodReplacement(
JSMethod method, JSExpression thisExpression,
JSExpression[] arguments, bool @virtual, bool @static, bool explicitThis
)
{
var methodInfo = method.Method;
var metadata = methodInfo.Metadata;
if (metadata != null) {
var parms = metadata.GetAttributeParameters("JSIL.Meta.JSReplacement");
if (parms != null) {
var argsDict = new Dictionary<string, JSExpression>();
argsDict["this"] = thisExpression;
argsDict["typeof(this)"] = Translate_TypeOf(thisExpression.GetActualType(TypeSystem));
foreach (var kvp in methodInfo.Parameters.Zip(arguments, (p, v) => new { p.Name, Value = v })) {
argsDict.Add(kvp.Name, kvp.Value);
}
return new JSVerbatimLiteral(
method, (string)parms[0].Value, argsDict, method.Method.ReturnType
);
}
}
if (methodInfo.IsIgnored)
return new JSIgnoredMemberReference(true, methodInfo, new[] { thisExpression }.Concat(arguments).ToArray());
switch (method.Method.Member.FullName) {
case "System.Object JSIL.Builtins::Eval(System.String)":
return JSInvocationExpression.InvokeStatic(
JS.eval, arguments
);
case "System.Object JSIL.Verbatim::Expression(System.String)": {
var expression = arguments[0] as JSStringLiteral;
if (expression == null)
throw new InvalidOperationException("JSIL.Verbatim.Expression must recieve a string literal as an argument");
return new JSVerbatimLiteral(
method, expression.Value, null, null
);
}
case "System.Object JSIL.JSGlobal::get_Item(System.String)": {
var expression = arguments[0] as JSStringLiteral;
if (expression != null)
return new JSDotExpression(
JSIL.GlobalNamespace, new JSStringIdentifier(expression.Value, TypeSystem.Object)
);
else
return new JSIndexerExpression(
JSIL.GlobalNamespace, arguments[0], TypeSystem.Object
);
}
case "System.Object JSIL.JSLocal::get_Item(System.String)": {
var expression = arguments[0] as JSStringLiteral;
if (expression == null)
throw new InvalidOperationException("JSLocal must recieve a string literal as an index");
return new JSStringIdentifier(expression.Value, TypeSystem.Object);
}
case "System.Object JSIL.Builtins::get_This()":
return new JSIndirectVariable(Variables, "this", ThisMethodReference);
}
JSExpression result = Translate_PropertyCall(thisExpression, method, arguments, @virtual, @static);
if (result == null) {
if (@static)
result = JSInvocationExpression.InvokeStatic(method.Reference.DeclaringType, method, arguments);
else if (explicitThis)
result = JSInvocationExpression.InvokeBaseMethod(method.Reference.DeclaringType, method, thisExpression, arguments);
else
result = JSInvocationExpression.InvokeMethod(method.Reference.DeclaringType, method, thisExpression, arguments);
}
return result;
}
示例12: Translate_Conv
protected JSExpression Translate_Conv(JSExpression value, TypeReference expectedType)
{
var currentType = value.GetActualType(TypeSystem);
if (TypeUtil.TypesAreEqual(expectedType, currentType))
return value;
int currentDepth, expectedDepth;
var currentDerefed = TypeUtil.FullyDereferenceType(currentType, out currentDepth);
var expectedDerefed = TypeUtil.FullyDereferenceType(expectedType, out expectedDepth);
// Handle assigning a value of type 'T&&' to a variable of type 'T&', etc.
// 'AreTypesAssignable' will return false, because the types are not equivalent, but no cast is necessary.
if (TypeUtil.TypesAreEqual(expectedDerefed, currentDerefed)) {
if (currentDepth > expectedDepth) {
// If the current expression has more levels of reference than the target type, we must dereference
// the current expression one or more times to strip off the reference levels.
var result = value;
JSExpression dereferenced;
while (currentDepth > expectedDepth) {
bool ok = JSReferenceExpression.TryDereference(JSIL, result, out dereferenced);
if (!ok)
break;
currentDepth -= 1;
result = dereferenced;
}
return result;
} else {
return value;
}
}
if (TypeUtil.IsDelegateType(expectedType) && TypeUtil.IsDelegateType(currentType))
return value;
if (TypeUtil.IsNumericOrEnum(currentType) && TypeUtil.IsNumericOrEnum(expectedType)) {
return JSCastExpression.New(value, expectedType, TypeSystem);
} else if (!TypeUtil.TypesAreAssignable(TypeInfo, expectedType, currentType)) {
if (expectedType.FullName == "System.Boolean") {
if (TypeUtil.IsIntegral(currentType)) {
// i != 0 sometimes becomes (bool)i, so we want to generate the explicit form
return new JSBinaryOperatorExpression(
JSOperator.NotEqual, value, JSLiteral.New(0), TypeSystem.Boolean
);
} else if (!currentType.IsValueType) {
// We need to detect any attempts to cast object references to boolean and not generate a cast
// for them, so that our logic in Translate_UnaryOp for detecting (x != null) will still work
return value;
}
}
// Never cast AnyType to another type since the implication is that the proxy author will ensure the correct
// type is returned.
if (currentType.FullName == "JSIL.Proxy.AnyType")
return value;
return JSCastExpression.New(value, expectedType, TypeSystem);
} else
return value;
}
示例13: ValueOfNullableOrDefault
public JSExpression ValueOfNullableOrDefault (JSExpression nullableExpression, JSExpression defaultValue) {
var valueType = nullableExpression.GetActualType(TypeSystem);
valueType = TypeUtil.StripNullable(valueType);
return JSInvocationExpression.InvokeStatic(
Dot("Nullable_ValueOrDefault", valueType),
new[] { nullableExpression, defaultValue }, true
);
}
示例14: NewReference
public JSNewBoxedVariable NewReference (JSExpression initialValue) {
var valueType = initialValue.GetActualType(TypeSystem);
return new JSNewBoxedVariable(
initialValue, valueType
);
}
示例15: IsCopyNeeded
protected bool IsCopyNeeded (JSExpression value, out GenericParameter relevantParameter) {
relevantParameter = null;
if ((value == null) || (value.IsNull))
return false;
while (value is JSReferenceExpression)
value = ((JSReferenceExpression)value).Referent;
var sce = value as JSStructCopyExpression;
if (sce != null)
return false;
var valueType = value.GetActualType(TypeSystem);
var valueTypeDerefed = TypeUtil.DereferenceType(valueType) ?? valueType;
var cte = value as JSChangeTypeExpression;
var cast = value as JSCastExpression;
TypeReference originalType;
int temp;
if (cte != null) {
originalType = cte.Expression.GetActualType(TypeSystem);
} else if (cast != null) {
originalType = cast.Expression.GetActualType(TypeSystem);
} else {
originalType = null;
}
if (originalType != null) {
originalType = TypeUtil.FullyDereferenceType(originalType, out temp);
if (!IsStructOrGenericParameter(valueTypeDerefed) && !IsStructOrGenericParameter(originalType))
return false;
relevantParameter = (originalType as GenericParameter) ?? (valueTypeDerefed as GenericParameter);
} else {
if (!IsStructOrGenericParameter(valueTypeDerefed))
return false;
relevantParameter = (valueTypeDerefed as GenericParameter);
}
if (IsTypeExcludedFromCopies(valueType))
return false;
var iae = value as JSInitializerApplicationExpression;
if (
(value is JSLiteral) ||
(value is JSNewExpression) ||
(value is JSPassByReferenceExpression) ||
(value is JSNewBoxedVariable) ||
(value is JSDefaultValueLiteral) ||
((iae != null) && ((iae.Target is JSNewExpression) || (iae.Target is JSDefaultValueLiteral)))
) {
return false;
}
if (!OptimizeCopies)
return true;
if (IsImmutable(value)) {
return false;
}
var valueDot = value as JSDotExpressionBase;
// The value is being read out of an element proxy, so no copy is necessary - the read unpacks the value
// on demand from the packed array.
if ((valueDot != null) && PackedArrayUtil.IsElementProxy(valueDot.Target))
return false;
var valueTypeInfo = TypeInfo.GetExisting(valueType);
if ((valueTypeInfo != null) && valueTypeInfo.IsImmutable)
return false;
// If the expression is a parameter that is only used once and isn't aliased,
// we don't need to copy it.
var rightVar = value as JSVariable;
if (rightVar != null) {
int referenceCount;
if (
ReferenceCounts.TryGetValue(rightVar.Identifier, out referenceCount) &&
(referenceCount == 1) && !rightVar.IsReference && rightVar.IsParameter &&
!SecondPass.VariableAliases.ContainsKey(rightVar.Identifier)
) {
if (Tracing)
Debug.WriteLine(String.Format("Returning false from IsCopyNeeded for parameter {0} because reference count is 1 and it has no aliases", value));
return false;
}
}
var rightInvocation = value as JSInvocationExpression;
if (rightInvocation == null)
return true;
var invokeMethod = rightInvocation.JSMethod;
if (invokeMethod == null)
//.........这里部分代码省略.........