本文整理汇总了C#中JSIL.Ast.JSVariable.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# JSVariable.Equals方法的具体用法?C# JSVariable.Equals怎么用?C# JSVariable.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSIL.Ast.JSVariable
的用法示例。
在下文中一共展示了JSVariable.Equals方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EliminateVariable
protected void EliminateVariable (JSNode context, JSVariable variable, JSExpression replaceWith, QualifiedMemberIdentifier method) {
{
var replacer = new VariableEliminator(
variable,
JSChangeTypeExpression.New(replaceWith, variable.GetActualType(TypeSystem), TypeSystem)
);
replacer.Visit(context);
}
{
var replacer = new VariableEliminator(variable, replaceWith);
var assignments = (from a in FirstPass.Assignments where
variable.Equals(a.NewValue) ||
a.NewValue.SelfAndChildrenRecursive.Any(variable.Equals)
select a).ToArray();
foreach (var a in assignments) {
if (!variable.Equals(a.NewValue))
replacer.Visit(a.NewValue);
}
}
Variables.Remove(variable.Identifier);
FunctionSource.InvalidateFirstPass(method);
}
示例2: IsEffectivelyConstant
protected bool IsEffectivelyConstant(JSVariable target, JSExpression source)
{
if ((source == null) || (source.IsNull))
return false;
// Can't eliminate struct temporaries, since that might eliminate some implied copies.
if (TypeUtil.IsStruct(target.IdentifierType))
return false;
// Handle special cases where our interpretation of 'constant' needs to be more flexible
{
var ie = source as JSIndexerExpression;
if (ie != null) {
if (
IsEffectivelyConstant(target, ie.Target) &&
IsEffectivelyConstant(target, ie.Index)
)
return true;
}
}
{
var ae = source as JSArrayExpression;
if (
(ae != null) &&
(from av in ae.Values select IsEffectivelyConstant(target, av)).All((b) => b)
)
return true;
}
{
var de = source as JSDotExpressionBase;
if (
(de != null) &&
IsEffectivelyConstant(target, de.Target) &&
IsEffectivelyConstant(target, de.Member)
)
return true;
}
{
var ie = source as JSInvocationExpression;
if (
(ie != null) && ie.ConstantIfArgumentsAre &&
IsEffectivelyConstant(target, ie.ThisReference) &&
ie.Arguments.All((a) => IsEffectivelyConstant(target, a))
)
return true;
if ((ie != null) && (ie.JSMethod != null)) {
var sa = GetSecondPass(ie.JSMethod);
if (sa != null) {
if (sa.IsPure) {
if (ie.Arguments.All((a) => IsEffectivelyConstant(target, a)))
return true;
else
return false;
}
}
}
}
if ((source is JSUnaryOperatorExpression) || (source is JSBinaryOperatorExpression)) {
if (source.Children.OfType<JSExpression>().All((_v) => IsEffectivelyConstant(target, _v)))
return true;
}
if (source.IsConstant)
return true;
// Try to find a spot between the source variable's assignments where all of our
// copies and accesses can fit. If we find one, our variable is effectively constant.
// FIXME: I think this section might be fundamentally flawed. Do let me know if you agree. :)
var v = source as JSVariable;
if (v != null) {
// Ensure that we never treat a local variable as constant if functions we call allow it to escape
// or modify it, because that can completely invalidate our purity analysis.
if (VariablesExemptedFromEffectivelyConstantStatus.Contains(v.Identifier))
return false;
var sourceAssignments = (from a in FirstPass.Assignments where v.Equals(a.Target) select a).ToArray();
if (sourceAssignments.Length < 1)
return v.IsParameter;
var sourceAccesses = (from a in FirstPass.Accesses where v.Equals(a.Source) select a).ToArray();
if (sourceAccesses.Length < 1)
return false;
var targetAssignmentIndices = (from a in FirstPass.Assignments where target.Equals(a.Target) select a.StatementIndex);
var targetAccessIndices = (from a in FirstPass.Accesses where target.Equals(a.Source) select a.StatementIndex).ToArray();
var targetUseIndices = targetAccessIndices.Concat(targetAssignmentIndices).ToArray();
if (sourceAssignments.Length == 1) {
if (targetAccessIndices.All((tai) => tai > sourceAssignments[0].StatementIndex))
return true;
}
var sourceFirstAssigned = sourceAssignments.First();
var sourceLastAssigned = sourceAssignments.Last();
//.........这里部分代码省略.........
示例3: EliminateVariable
protected void EliminateVariable(JSNode context, JSVariable variable, JSExpression replaceWith)
{
{
var replacer = new VariableEliminator(
variable,
JSChangeTypeExpression.New(replaceWith, TypeSystem, variable.GetExpectedType(TypeSystem))
);
replacer.Visit(context);
}
{
var replacer = new VariableEliminator(variable, replaceWith);
var assignments = (from a in FirstPass.Assignments where
variable.Equals(a.NewValue) ||
a.NewValue.AllChildrenRecursive.Any((_n) => variable.Equals(_n))
select a).ToArray();
foreach (var a in assignments) {
if (variable.Equals(a.NewValue)) {
FirstPass.Assignments.Remove(a);
FirstPass.Assignments.Add(
new FunctionAnalysis1stPass.Assignment(
a.StatementIndex, a.NodeIndex,
a.Target, replaceWith, a.Operator,
a.TargetType, a.SourceType
)
);
} else {
replacer.Visit(a.NewValue);
}
}
}
Variables.Remove(variable.Identifier);
}
示例4: IsEffectivelyConstant
protected bool IsEffectivelyConstant(JSVariable target, JSExpression source)
{
if ((source == null) || (source.IsNull))
return false;
// Handle special cases where our interpretation of 'constant' needs to be more flexible
{
var ie = source as JSIndexerExpression;
if (ie != null) {
if (
IsEffectivelyConstant(target, ie.Target) &&
IsEffectivelyConstant(target, ie.Index)
)
return true;
}
}
{
var ae = source as JSArrayExpression;
if (
(ae != null) &&
(from av in ae.Values select IsEffectivelyConstant(target, av)).All((b) => b)
)
return true;
}
{
var de = source as JSDotExpression;
if (
(de != null) &&
IsEffectivelyConstant(target, de.Target) &&
IsEffectivelyConstant(target, de.Member)
)
return true;
}
{
var ie = source as JSInvocationExpression;
if (
(ie != null) && ie.ConstantIfArgumentsAre &&
IsEffectivelyConstant(target, ie.ThisReference) &&
ie.Arguments.All((a) => IsEffectivelyConstant(target, a))
)
return true;
}
if ((source is JSUnaryOperatorExpression) || (source is JSBinaryOperatorExpression)) {
if (source.Children.OfType<JSExpression>().All((_v) => IsEffectivelyConstant(target, _v)))
return true;
}
if (source.IsConstant)
return true;
// Try to find a spot between the source variable's assignments where all of our
// copies and accesses can fit. If we find one, our variable is effectively constant.
var v = source as JSVariable;
if (v != null) {
var assignments = (from a in FirstPass.Assignments where v.Equals(a.Target) select a).ToArray();
if (assignments.Length < 1)
return v.IsParameter;
var targetAssignments = (from a in FirstPass.Assignments where v.Equals(a.Target) select a).ToArray();
if (targetAssignments.Length < 1)
return false;
var targetAccesses = (from a in FirstPass.Accesses where target.Equals(a.Source) select a).ToArray();
if (targetAccesses.Length < 1)
return false;
var targetFirstAssigned = targetAssignments.FirstOrDefault();
var targetLastAssigned = targetAssignments.LastOrDefault();
var targetFirstAccessed = targetAccesses.FirstOrDefault();
var targetLastAccessed = targetAccesses.LastOrDefault();
bool foundAssignmentSlot = false;
for (int i = 0, c = assignments.Length; i < c; i++) {
int assignment = assignments[i].StatementIndex, nextAssignment = int.MaxValue;
if (i < c - 1)
nextAssignment = assignments[i + 1].StatementIndex;
if (
(targetFirstAssigned.StatementIndex >= assignment) &&
(targetFirstAssigned.StatementIndex < nextAssignment) &&
(targetFirstAccessed.StatementIndex >= assignment) &&
(targetLastAccessed.StatementIndex <= nextAssignment)
) {
foundAssignmentSlot = true;
break;
}
}
if (!foundAssignmentSlot)
return false;
return true;
}
//.........这里部分代码省略.........
示例5: IsEffectivelyConstant
protected bool IsEffectivelyConstant(JSVariable target, JSExpression source)
{
if ((source == null) || (source.IsNull))
return false;
// Can't eliminate struct temporaries, since that might eliminate some implied copies.
if (TypeUtil.IsStruct(target.IdentifierType))
return false;
// Handle special cases where our interpretation of 'constant' needs to be more flexible
{
var ie = source as JSIndexerExpression;
if (ie != null) {
if (
IsEffectivelyConstant(target, ie.Target) &&
IsEffectivelyConstant(target, ie.Index)
)
return true;
}
}
{
var ae = source as JSArrayExpression;
if (
(ae != null) &&
(from av in ae.Values select IsEffectivelyConstant(target, av)).All((b) => b)
)
return true;
}
{
var de = source as JSDotExpressionBase;
if (
(de != null) &&
IsEffectivelyConstant(target, de.Target) &&
IsEffectivelyConstant(target, de.Member)
)
return true;
}
{
var ie = source as JSInvocationExpression;
if (
(ie != null) && ie.ConstantIfArgumentsAre &&
IsEffectivelyConstant(target, ie.ThisReference) &&
ie.Arguments.All((a) => IsEffectivelyConstant(target, a))
)
return true;
if ((ie != null) && (ie.JSMethod != null)) {
var sa = GetSecondPass(ie.JSMethod);
if (sa != null) {
if (sa.IsPure) {
if (ie.Arguments.All((a) => IsEffectivelyConstant(target, a)))
return true;
else
return false;
}
}
}
}
if ((source is JSUnaryOperatorExpression) || (source is JSBinaryOperatorExpression)) {
if (source.Children.OfType<JSExpression>().All((_v) => IsEffectivelyConstant(target, _v)))
return true;
}
if (source.IsConstant)
return true;
// Try to find a spot between the source variable's assignments where all of our
// copies and accesses can fit. If we find one, our variable is effectively constant.
var v = source as JSVariable;
if (v != null) {
var assignments = (from a in FirstPass.Assignments where v.Equals(a.Target) select a).ToArray();
if (assignments.Length < 1)
return v.IsParameter;
var targetAssignments = (from a in FirstPass.Assignments where v.Equals(a.Target) select a).ToArray();
if (targetAssignments.Length < 1)
return false;
var targetAccesses = (from a in FirstPass.Accesses where target.Equals(a.Source) select a).ToArray();
if (targetAccesses.Length < 1)
return false;
var targetFirstAssigned = targetAssignments.FirstOrDefault();
var targetLastAssigned = targetAssignments.LastOrDefault();
var targetFirstAccessed = targetAccesses.FirstOrDefault();
var targetLastAccessed = targetAccesses.LastOrDefault();
bool foundAssignmentSlot = false;
for (int i = 0, c = assignments.Length; i < c; i++) {
int assignment = assignments[i].StatementIndex, nextAssignment = int.MaxValue;
if (i < c - 1)
nextAssignment = assignments[i + 1].StatementIndex;
if (
//.........这里部分代码省略.........