本文整理汇总了C#中JSIL.Ast.JSVariable类的典型用法代码示例。如果您正苦于以下问题:C# JSVariable类的具体用法?C# JSVariable怎么用?C# JSVariable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JSVariable类属于JSIL.Ast命名空间,在下文中一共展示了JSVariable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: ILBlockTranslator
public ILBlockTranslator(AssemblyTranslator translator, DecompilerContext context, MethodReference methodReference, MethodDefinition methodDefinition, ILBlock ilb, IEnumerable<ILVariable> parameters, IEnumerable<ILVariable> allVariables)
{
Translator = translator;
Context = context;
ThisMethodReference = methodReference;
ThisMethod = methodDefinition;
Block = ilb;
SpecialIdentifiers = new JSIL.SpecialIdentifiers(TypeSystem);
if (methodReference.HasThis)
Variables.Add("this", JSThisParameter.New(methodReference.DeclaringType, methodReference));
foreach (var parameter in parameters) {
if ((parameter.Name == "this") && (parameter.OriginalParameter.Index == -1))
continue;
ParameterNames.Add(parameter.Name);
Variables.Add(parameter.Name, new JSParameter(parameter.Name, parameter.Type, methodReference));
}
foreach (var variable in allVariables) {
var v = JSVariable.New(variable, methodReference);
if (Variables.ContainsKey(v.Identifier)) {
v = new JSVariable(variable.OriginalVariable.Name, variable.Type, methodReference);
RenamedVariables[variable] = v;
Variables.Add(v.Identifier, v);
} else {
Variables.Add(v.Identifier, v);
}
}
}
示例3: MatchesConstructedReference
protected bool MatchesConstructedReference (JSExpression lhs, JSVariable rhs) {
var jsv = lhs as JSVariable;
if ((jsv != null) && (jsv.Identifier == rhs.Identifier))
return true;
return false;
}
示例4: VisitNode
public void VisitNode(JSVariable variable)
{
int count;
if (ReferenceCounts.TryGetValue(variable.Identifier, out count))
ReferenceCounts[variable.Identifier] = count + 1;
else
ReferenceCounts[variable.Identifier] = 1;
VisitChildren(variable);
}
示例5: VisitNode
public void VisitNode(JSVariable variable)
{
// If our parent node is the function, we're in the argument list
if (ParentNode is JSFunctionExpression)
return;
int count;
if (ReferenceCounts.TryGetValue(variable.Identifier, out count))
ReferenceCounts[variable.Identifier] = count + 1;
else
ReferenceCounts[variable.Identifier] = 1;
}
示例6: TransformParameterIntoReference
protected void TransformParameterIntoReference(JSVariable parameter, JSBlockStatement block)
{
var newParameter = new JSParameter("$" + parameter.Identifier, parameter.Type);
var newVariable = new JSVariable(parameter.Identifier, new ByReferenceType(parameter.Type));
var newDeclaration = new JSVariableDeclarationStatement(
new JSBinaryOperatorExpression(
JSOperator.Assignment,
// We have to use parameter here, not newVariable or newParameter, otherwise the resulting
// assignment looks like 'x.value = initializer' instead of 'x = initializer'
parameter,
JSIL.NewReference(newParameter),
newVariable.Type
)
);
if (Tracing)
Debug.WriteLine(String.Format("Transformed {0} into {1}={2}", parameter, newVariable, newParameter));
Variables[newVariable.Identifier] = newVariable;
Variables.Add(newParameter.Identifier, newParameter);
ParameterNames.Remove(parameter.Identifier);
ParameterNames.Add(newParameter.Identifier);
block.Statements.Insert(0, newDeclaration);
}
示例7: VisitNode
public void VisitNode (JSVariable variable) {
if (CurrentName == "FunctionSignature") {
// In argument list
return;
}
if (Variable.Equals(variable)) {
ParentNode.ReplaceChild(variable, Replacement);
} else {
VisitChildren(variable);
}
}
示例8: 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;
}
//.........这里部分代码省略.........
示例9: ReplaceChild
public override void ReplaceChild(JSNode oldChild, JSNode newChild)
{
if (oldChild == null)
throw new ArgumentNullException("oldChild");
if (CatchVariable == oldChild)
CatchVariable = (JSVariable)newChild;
if (Catch == oldChild)
Catch = (JSStatement)newChild;
if (Finally == oldChild)
Finally = (JSStatement)newChild;
Body.ReplaceChild(oldChild, newChild);
}
示例10: IsVarEffectivelyConstantHere
private bool IsVarEffectivelyConstantHere (JSVariable variable) {
if (variable == null)
return false;
if (variable.IsParameter)
return false;
// If we're making a copy of a local variable, and this is the last reference to
// the variable, we can eliminate the copy.
if (
!SecondPass.Data.VariablesPassedByRef.Contains(variable.Identifier) &&
SecondPass.Data.Accesses
.Where(a => a.Source == variable.Identifier)
// FIXME: This should probably be NodeIndex but that gets out of sync somehow? Outdated analysis data?
.All(a => a.StatementIndex <= StatementIndex) &&
SecondPass.Data.Assignments
.Where(a => a.Target == variable.Identifier)
// FIXME: This should probably be NodeIndex but that gets out of sync somehow? Outdated analysis data?
.All(a => a.StatementIndex < StatementIndex)
) {
return true;
}
return false;
}
示例11: VisitNode
public void VisitNode(JSVariable v)
{
SeenAlready.Add(v);
VisitChildren(v);
}
示例12: VariableReferenceAccessTransformer
public VariableReferenceAccessTransformer (JSILIdentifier jsil, JSVariable variable, IFunctionSource functionSource) {
JSIL = jsil;
Variable = variable;
FunctionSource = functionSource;
}
示例13: EmitFieldIntrinsics
private void EmitFieldIntrinsics(int heapSize)
{
// FIXME: Gross
var tis = (ITypeInfoSource)Translator.TypeInfoProvider;
Formatter.WriteRaw(";; Compiler-generated field accessors");
Formatter.NewLine();
foreach (var kvp in FieldTable.OrderBy(kvp => kvp.Value.Offset)) {
var fd = kvp.Value.Field;
var fi = (FieldInfo)tis.Get(fd);
var name = WasmUtil.FormatMemberName(fi.Member);
var typeSystem = fd.FieldType.Module.TypeSystem;
// HACK
var baseAddressParam = new JSVariable("address", typeSystem.Int32, null);
// HACK
var valueParam = new JSVariable("value", fd.FieldType, null);
JSExpression address;
if (fd.IsStatic) {
address = JSLiteral.New(kvp.Value.Offset + heapSize);
} else {
address = new JSBinaryOperatorExpression(
JSOperator.Add,
baseAddressParam,
JSLiteral.New(kvp.Value.Offset),
typeSystem.Int32
);
}
Formatter.ConditionalNewLine();
Formatter.WriteRaw(
"(func $__get_{0} (result {1}){2}(return ",
name,
WasmUtil.PickTypeKeyword(fd.FieldType),
fd.IsStatic
? " "
: " (param $address i32) "
);
var gm = new GetMemory(
fd.FieldType, /* FIXME: Align addresses */ false,
address
);
// HACK
EntryPointAstEmitter.Emit(gm);
Formatter.WriteRaw(") )");
if (fd.IsInitOnly)
continue;
Formatter.NewLine();
Formatter.WriteRaw(
"(func $__set_{0}{2}(param $value {1}) ",
name,
WasmUtil.PickTypeKeyword(fd.FieldType),
fd.IsStatic
? " "
: " (param $address i32) "
);
Formatter.Indent();
Formatter.NewLine();
var sm = new SetMemory(
fd.FieldType, /* FIXME: Align addresses */ false,
address, valueParam
);
// HACK
EntryPointAstEmitter.Emit(sm);
Formatter.Unindent();
Formatter.ConditionalNewLine();
Formatter.WriteRaw(")");
}
Formatter.NewLine();
Formatter.NewLine();
}
示例14: JSVariableReference
public JSVariableReference(JSVariable referent, MethodReference function)
: base(referent.Identifier, null, function)
{
Referent = referent;
}
示例15: TransformVariableIntoReference
protected void TransformVariableIntoReference(JSVariable variable, JSVariableDeclarationStatement statement, int declarationIndex)
{
if (variable.IsReference)
Debugger.Break();
var oldDeclaration = statement.Declarations[declarationIndex];
var newVariable = variable.Reference();
var newDeclaration = new JSBinaryOperatorExpression(
JSOperator.Assignment,
// We have to use a constructed ref to the variable here, otherwise
// the declaration will look like 'var x.value = foo'
new JSVariable(variable.Identifier, variable.Type),
JSIL.NewReference(oldDeclaration.Right),
newVariable.Type
);
if (Tracing)
Debug.WriteLine(String.Format("Transformed {0} into {1} in {2}", variable, newVariable, statement));
Variables[variable.Identifier] = newVariable;
statement.Declarations[declarationIndex] = newDeclaration;
TransformedVariables.Add(variable.Identifier);
}