本文整理汇总了C#中JSBinaryOperatorExpression.GetExpectedType方法的典型用法代码示例。如果您正苦于以下问题:C# JSBinaryOperatorExpression.GetExpectedType方法的具体用法?C# JSBinaryOperatorExpression.GetExpectedType怎么用?C# JSBinaryOperatorExpression.GetExpectedType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSBinaryOperatorExpression
的用法示例。
在下文中一共展示了JSBinaryOperatorExpression.GetExpectedType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitNode
public void VisitNode(JSBinaryOperatorExpression boe)
{
var leftType = boe.Left.GetExpectedType(TypeSystem);
var rightType = boe.Right.GetExpectedType(TypeSystem);
bool isArithmetic = !(boe.Operator is JSAssignmentOperator);
if ((leftType.FullName == "System.Char") && isArithmetic)
boe.ReplaceChild(boe.Left, CastToInteger(boe.Left));
if ((rightType.FullName == "System.Char") && isArithmetic)
boe.ReplaceChild(boe.Right, CastToInteger(boe.Right));
var parentInvocation = ParentNode as JSInvocationExpression;
JSDotExpression parentInvocationDot = (parentInvocation != null) ? parentInvocation.Method as JSDotExpression : null;
if (
isArithmetic &&
(boe.GetExpectedType(TypeSystem).FullName == "System.Char") &&
!(
(parentInvocation != null) &&
(parentInvocationDot != null) &&
(parentInvocationDot.Target is JSStringIdentifier) &&
(((JSStringIdentifier)parentInvocationDot.Target).Identifier == "String") &&
(parentInvocationDot.Member is JSFakeMethod) &&
(((JSFakeMethod)parentInvocationDot.Member).Name == "fromCharCode")
)
) {
var castBoe = CastToChar(boe);
ParentNode.ReplaceChild(boe, castBoe);
VisitReplacement(castBoe);
} else {
VisitChildren(boe);
}
}
示例2: VisitNode
public void VisitNode(JSBinaryOperatorExpression boe)
{
JSExpression left, right, nestedLeft;
if (!JSReferenceExpression.TryDereference(JSIL, boe.Left, out left))
left = boe.Left;
if (!JSReferenceExpression.TryDereference(JSIL, boe.Right, out right))
right = boe.Right;
var nestedBoe = right as JSBinaryOperatorExpression;
var isAssignment = (boe.Operator == JSOperator.Assignment);
var leftNew = left as JSNewExpression;
var rightNew = right as JSNewExpression;
var leftVar = left as JSVariable;
if (
isAssignment && (nestedBoe != null) &&
(left.IsConstant || (leftVar != null) || left is JSDotExpression) &&
!(ParentNode is JSVariableDeclarationStatement)
) {
JSUnaryOperator prefixOperator;
JSAssignmentOperator compoundOperator;
if (!JSReferenceExpression.TryDereference(JSIL, nestedBoe.Left, out nestedLeft))
nestedLeft = nestedBoe.Left;
var rightLiteral = nestedBoe.Right as JSIntegerLiteral;
var areEqual = left.Equals(nestedLeft);
if (
areEqual &&
PrefixOperators.TryGetValue(nestedBoe.Operator, out prefixOperator) &&
(rightLiteral != null) && (rightLiteral.Value == 1)
) {
var newUoe = new JSUnaryOperatorExpression(
prefixOperator, boe.Left,
boe.GetExpectedType(TypeSystem)
);
ParentNode.ReplaceChild(boe, newUoe);
VisitReplacement(newUoe);
return;
} else if (
areEqual &&
CompoundAssignments.TryGetValue(nestedBoe.Operator, out compoundOperator)
) {
var newBoe = new JSBinaryOperatorExpression(
compoundOperator, boe.Left, nestedBoe.Right,
boe.GetExpectedType(TypeSystem)
);
ParentNode.ReplaceChild(boe, newBoe);
VisitReplacement(newBoe);
return;
}
} else if (
isAssignment && (leftNew != null) &&
(rightNew != null)
) {
var rightType = rightNew.Type as JSDotExpression;
if (
(rightType != null) &&
(rightType.Member.Identifier == "CollectionInitializer")
) {
var newInitializer = new JSInitializerApplicationExpression(
boe.Left, new JSArrayExpression(
TypeSystem.Object,
rightNew.Arguments.ToArray()
)
);
ParentNode.ReplaceChild(boe, newInitializer);
VisitReplacement(newInitializer);
return;
}
} else if (
isAssignment && (leftVar != null) &&
leftVar.IsThis
) {
var leftType = leftVar.GetExpectedType(TypeSystem);
if (!EmulateStructAssignment.IsStruct(leftType)) {
ParentNode.ReplaceChild(boe, new JSUntranslatableExpression(boe));
return;
} else {
var newInvocation = JSInvocationExpression.InvokeStatic(
JSIL.CopyMembers, new[] { boe.Right, leftVar }
);
ParentNode.ReplaceChild(boe, newInvocation);
VisitReplacement(newInvocation);
return;
}
}
VisitChildren(boe);
//.........这里部分代码省略.........