当前位置: 首页>>代码示例>>C#>>正文


C# Cil.VariableReference类代码示例

本文整理汇总了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;
 }
开发者ID:Feng2012,项目名称:JustDecompileEngine,代码行数:7,代码来源:YieldFieldsInformation.cs

示例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;
		}
开发者ID:boothead,项目名称:mono-tools,代码行数:7,代码来源:InstructionMatcher.cs

示例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;
		}
开发者ID:besturn,项目名称:JustDecompileEngine,代码行数:29,代码来源:RebuildVBForStatements.cs

示例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);
        }
开发者ID:Unity-Technologies,项目名称:cecil,代码行数:10,代码来源:GenericParameterResolver.cs

示例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;
		}
开发者ID:Feng2012,项目名称:JustDecompileEngine,代码行数:12,代码来源:CommonPatterns.cs

示例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);
        }
开发者ID:Feng2012,项目名称:JustDecompileEngine,代码行数:25,代码来源:UsedAsTypeHelper.cs

示例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;
        }
开发者ID:juancarlosbaezpozos,项目名称:JustDecompileEngine,代码行数:44,代码来源:StateMachineUtilities.cs

示例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);
        }
开发者ID:Feng2012,项目名称:JustDecompileEngine,代码行数:23,代码来源:RebuildForStatements.cs

示例9: FindVariableInExpression

		public static bool FindVariableInExpression (VariableReference variable, Expression expression)
		{
			var matcher = new VariableMatcher (variable);
			matcher.Visit (expression);
			return matcher.Match;
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:6,代码来源:Matcher.cs

示例10: VariableMatcher

		VariableMatcher (VariableReference variable)
		{
			this.variable = variable;
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:4,代码来源:Matcher.cs

示例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;
		}
开发者ID:GiGatR00n,项目名称:JustDecompileEngine,代码行数:12,代码来源:BaseImperativeLanguageWriter.cs

示例12: addVariableReference

 void addVariableReference(VariableReference v)
 {
     if (v == null)
         return;
     pushMember(v.VariableType);
 }
开发者ID:ldh0227,项目名称:de4dot,代码行数:6,代码来源:MemberRefFinder.cs

示例13: GetOriginalVariable

 public SsaVariable GetOriginalVariable(VariableReference variable)
 {
     return locals[variable.Index];
 }
开发者ID:richardschneider,项目名称:ILSpy,代码行数:4,代码来源:SsaForm.cs

示例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.");
            }
        }
开发者ID:saravanaram,项目名称:JustDecompileEngine,代码行数:79,代码来源:TypeInferer.cs

示例15: PushVariableReference

		private void PushVariableReference (VariableReference variable)
		{
			Push (new VariableReferenceExpression (variable));
		}
开发者ID:smoothfriction,项目名称:cecil,代码行数:4,代码来源:ExpressionDecompiler.cs


注:本文中的Mono.Cecil.Cil.VariableReference类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。