本文整理汇总了C#中JSIL.Ast.JSVariable.Reference方法的典型用法代码示例。如果您正苦于以下问题:C# JSVariable.Reference方法的具体用法?C# JSVariable.Reference怎么用?C# JSVariable.Reference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSIL.Ast.JSVariable
的用法示例。
在下文中一共展示了JSVariable.Reference方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TransformVariableIntoReference
protected void TransformVariableIntoReference(JSVariable variable, JSVariableDeclarationStatement statement, int declarationIndex, JSBlockStatement enclosingBlock)
{
var oldDeclaration = statement.Declarations[declarationIndex];
var valueType = oldDeclaration.Right.GetActualType(JSIL.TypeSystem);
var newVariable = variable.Reference();
var enclosingFunction = Stack.OfType<JSFunctionExpression>().First();
JSExpression initialValue;
// If the declaration was in function scope originally we can hoist the initial value
// into our new variable declaration. If not, we need to initialize the ref variable
// to the default value for its type. It will get the correct value assigned later.
if (enclosingBlock == enclosingFunction.Body)
initialValue = oldDeclaration.Right;
else
initialValue = new JSDefaultValueLiteral(valueType);
var newDeclaration = new JSVariableDeclarationStatement(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.IdentifierType, variable.Function),
JSIL.NewReference(initialValue),
newVariable.IdentifierType
));
if (Tracing)
Debug.WriteLine(String.Format("Transformed {0} into {1} in {2}", variable, newVariable, statement));
// Insert the new declaration directly before the top-level block containing the original
// declaration. This ensures that if its initial value has a dependency on external state,
// the declaration will not precede the values it depends on.
// Note that for declarations that were hoisted out of inner blocks (conditionals, loops)
// it doesn't actually matter where the insert occurs, since we initialize with a default
// value in that case.
enclosingFunction.Body.InsertNearChildRecursive(
statement, newDeclaration, 0
);
// If the reference is being declared in function scope, it doesn't need a separate assignment
// for its initialization. Otherwise, we need to insert an assignment after the original variable
// declaration statement to ensure that the reference variable is initialized to the right value
// at the exact right point in the function's execution.
if (enclosingBlock != enclosingFunction.Body) {
var newAssignment = new JSExpressionStatement(
new JSBinaryOperatorExpression(
JSOperator.Assignment, newVariable, oldDeclaration.Right, valueType
)
);
var insertLocation = enclosingBlock.Statements.IndexOf(statement) + 1;
enclosingBlock.Statements.Insert(insertLocation, newAssignment);
}
Variables[variable.Identifier] = newVariable;
statement.Declarations.RemoveAt(declarationIndex);
TransformedVariables.Add(variable.Identifier);
}
示例2: 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);
}