本文整理汇总了C#中Mono.Cecil.Cil.VariableReference类的典型用法代码示例。如果您正苦于以下问题:C# VariableReference类的具体用法?C# VariableReference怎么用?C# VariableReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VariableReference类属于Mono.Cecil.Cil命名空间,在下文中一共展示了VariableReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: YieldFieldsInformation
public YieldFieldsInformation(FieldDefinition stateHolderField, FieldDefinition currentItemField,
VariableReference returnFlagVariable)
{
this.stateHolderField = stateHolderField;
this.currentItemField = currentItemField;
this.returnFlagVariable = returnFlagVariable;
}
示例2: AreEquivalent
static bool AreEquivalent (VariableReference source, VariableReference target)
{
IList<VariableDefinition> cv = Current.Body.Variables;
IList<VariableDefinition> tv = Target.Body.Variables;
return cv.Count > source.Index && tv.Count > target.Index ?
cv [source.Index].VariableType.Equals (tv [target.Index].VariableType) : false;
}
示例3: CheckTheLoop
protected override bool CheckTheLoop(WhileStatement theWhile, VariableReference forVariable)
{
bool isProperForVBForLoop = base.CheckTheLoop(theWhile, forVariable) && theWhile.Condition is BinaryExpression;
if (!isProperForVBForLoop)
{
return false;
}
ExpressionStatement incrementCandidate = theWhile.Body.Statements[theWhile.Body.Statements.Count - 1] as ExpressionStatement;
BinaryExpression assignmentExpression = incrementCandidate.Expression as BinaryExpression;
if (assignmentExpression != null)
{
BinaryExpression incrementExpression = assignmentExpression.Right as BinaryExpression;
if (incrementExpression != null && (incrementExpression.Operator == Ast.BinaryOperator.Add || incrementExpression.Operator == Ast.BinaryOperator.Subtract))
{
VariableReferenceExpression incrementVariableExpression = incrementExpression.Left as VariableReferenceExpression;
if (incrementVariableExpression != null)
{
if (incrementVariableExpression.Variable == forVariable)
{
return true;
}
}
}
}
return false;
}
示例4: ResolveVariableTypeIfNeeded
internal static TypeReference ResolveVariableTypeIfNeeded(MethodReference method, VariableReference variable)
{
var genericInstanceMethod = method as GenericInstanceMethod;
var declaringGenericInstanceType = method.DeclaringType as GenericInstanceType;
if (genericInstanceMethod == null && declaringGenericInstanceType == null)
return variable.VariableType;
return ResolveIfNeeded (genericInstanceMethod, declaringGenericInstanceType, variable.VariableType);
}
示例5: IsAssignToVariableExpression
protected bool IsAssignToVariableExpression(BinaryExpression theAssignExpression, out VariableReference theVariable)
{
theVariable = null;
bool result = theAssignExpression != null && theAssignExpression.IsAssignmentExpression &&
(theAssignExpression.Left.CodeNodeType == CodeNodeType.VariableReferenceExpression ||
theAssignExpression.Left.CodeNodeType == CodeNodeType.VariableDeclarationExpression);
if (result)
{
theVariable = GetVariableReferenceFromExpression(theAssignExpression.Left);
}
return result;
}
示例6: GetUseExpressionTypeNode
/// <summary>
/// Determines the type of the <paramref name="variable"/> based on its usage.
/// </summary>
/// <param name="instruction">The instruction that uses the variable.</param>
/// <param name="variable">Tha variable.</param>
/// <returns>Returns the ClassHierarchyNode for the found type.</returns>
public TypeReference GetUseExpressionTypeNode(Instruction instruction, Expression instructionExpression, VariableReference variable)
{
Code instrOpCode = instruction.OpCode.Code;
if (instrOpCode == Code.Ldobj)
{
TypeReference tr = instruction.Operand as TypeReference;
return tr;
}
if (IsConditionalBranch(instrOpCode))
{
return typeSystem.Boolean;
}
if (instrOpCode == Code.Pop)
{
return null;
}
return GetUseExpressionTypeNode(instructionExpression, variable);
}
示例7: TryGetVariableFromInstruction
/// <summary>
/// Tries to get the variable that is used by the specified instruction.
/// </summary>
/// <param name="instruction"></param>
/// <param name="varReference"></param>
/// <returns>Flase if the instruction does not handle variables.</returns>
public static bool TryGetVariableFromInstruction(Instruction instruction, IList<VariableDefinition> variableCollection,
out VariableReference varReference)
{
switch (instruction.OpCode.Code)
{
case Code.Ldloc_0:
case Code.Stloc_0:
varReference = variableCollection[0];
break;
case Code.Ldloc_1:
case Code.Stloc_1:
varReference = variableCollection[1];
break;
case Code.Ldloc_2:
case Code.Stloc_2:
varReference = variableCollection[2];
break;
case Code.Ldloc_3:
case Code.Stloc_3:
varReference = variableCollection[3];
break;
case Code.Ldloc_S:
case Code.Ldloca_S:
case Code.Stloc_S:
varReference = instruction.Operand as VariableReference ?? variableCollection[(sbyte)instruction.Operand];
break;
case Code.Ldloc:
case Code.Ldloca:
case Code.Stloc:
varReference = variableCollection[(int)instruction.Operand];
break;
default:
varReference = null;
return false;
}
return true;
}
示例8: CheckTheLoop
protected virtual bool CheckTheLoop(WhileStatement theWhile, VariableReference forVariable)
{
if (theWhile == null || theWhile.Body.Statements.Count < 2)
{
return false;
}
VariableFinder variableFinder = new VariableFinder(forVariable);
if (!variableFinder.FindVariable(theWhile.Condition))
{
return false;
}
ExpressionStatement incrementCandidate = theWhile.Body.Statements[theWhile.Body.Statements.Count - 1] as ExpressionStatement;
VariableReference incrementVariable;
if (incrementCandidate == null || !TryGetAssignedVariable(incrementCandidate, out incrementVariable) || forVariable != incrementVariable)
{
return false;
}
ContinueFinder continueFinder = new ContinueFinder();
return !continueFinder.FindContinue(theWhile.Body);
}
示例9: FindVariableInExpression
public static bool FindVariableInExpression (VariableReference variable, Expression expression)
{
var matcher = new VariableMatcher (variable);
matcher.Visit (expression);
return matcher.Match;
}
示例10: VariableMatcher
VariableMatcher (VariableReference variable)
{
this.variable = variable;
}
示例11: GetVariableName
protected string GetVariableName(VariableReference variable)
{
VariableDefinition variableDefinition = variable.Resolve();
string result;
if (!GetCurrentMethodContext().VariableDefinitionToNameMap.TryGetValue(variableDefinition, out result))
{
result = variableDefinition.Name;
}
return result;
}
示例12: addVariableReference
void addVariableReference(VariableReference v)
{
if (v == null)
return;
pushMember(v.VariableType);
}
示例13: GetOriginalVariable
public SsaVariable GetOriginalVariable(VariableReference variable)
{
return locals[variable.Index];
}
示例14: AddCastIfNeeded
/// <summary>
/// Determines if the use of <paramref name="variable"/> in <paramref name="useExpression"/> requires a cast.
/// </summary>
/// <param name="useExpression">The expression being checked.</param>
/// <param name="variable">The variable that might need to be casted.</param>
private void AddCastIfNeeded(Expression useExpression, VariableReference variable)
{
switch (useExpression.CodeNodeType)
{
case CodeNodeType.MethodInvocationExpression:
MethodInvocationExpression miEx = useExpression as MethodInvocationExpression;
Expression argument = miEx.Arguments.FirstOrDefault(x => x.CodeNodeType == CodeNodeType.VariableReferenceExpression &&
(x as VariableReferenceExpression).Variable == variable);
if (argument != null)
{
///The variable is passed as argument to the method.
int argumentIndex = miEx.Arguments.IndexOf(argument);
TypeReference argumentType = miEx.MethodExpression.Method.Parameters[argumentIndex].ResolveParameterType(miEx.MethodExpression.Method);
if (!IsSubtype(argumentType, variable.VariableType))
{
if (argumentType.IsPrimitive && variable.VariableType.IsPrimitive)
{
///Integer values are not in inheritance relations. Some of them, however, can be expanded to bigger types
///automatically, without the addition of a cast, i.e. Byte variable can be passed as int parameter without the
///need to include a cast.
TypeReference containingType = ExpressionTypeInferer.GetContainingType(argumentType.Resolve(), variable.VariableType.Resolve());
if (containingType.FullName == argumentType.FullName)
{
///Then the type of the argument contains the type of the variable, thus no cast is needed.
return;
}
}
///Then a cast is needed.
miEx.Arguments[argumentIndex] = new CastExpression(argument, argumentType, null);
///This should be enough to update the expression everywhere it is seen.
}
}
else
{
/// Then the variable is the object from which the method is called
/// variable.SomeMethod(...);
Expression target = miEx.MethodExpression.Target;
if (target.CodeNodeType == CodeNodeType.VariableReferenceExpression && (target as VariableReferenceExpression).Variable == variable)
{
TypeReference targetType = miEx.MethodExpression.Method.DeclaringType;
if (!IsSubtype(targetType, variable.VariableType))
{
miEx.MethodExpression.Target = new CastExpression(target, targetType, null);
}
}
else
{
///This should not be reachable, but anyway.
AddCastIfNeeded(target, variable);
}
}
break;
case CodeNodeType.BinaryExpression:
BinaryExpression binEx = useExpression as BinaryExpression;
if (binEx.Operator == BinaryOperator.Assign)
{
if (binEx.Right.CodeNodeType == CodeNodeType.VariableReferenceExpression &&
(binEx.Right as VariableReferenceExpression).Variable == variable)
{
TypeReference assignedAs = binEx.Left.ExpressionType;
///binex.Right should be VariableReferenceExpression to 'variable'.
if (!IsSubtype(assignedAs, variable.VariableType))
{
binEx.Right = new CastExpression(binEx.Right, assignedAs, null);
}
}
}
break;
//default:
//throw new NotSupportedException("Not supported cast expression.");
}
}
示例15: PushVariableReference
private void PushVariableReference (VariableReference variable)
{
Push (new VariableReferenceExpression (variable));
}