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


C# Instruction.TraceBack方法代码示例

本文整理汇总了C#中Mono.Cecil.Cil.Instruction.TraceBack方法的典型用法代码示例。如果您正苦于以下问题:C# Instruction.TraceBack方法的具体用法?C# Instruction.TraceBack怎么用?C# Instruction.TraceBack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mono.Cecil.Cil.Instruction的用法示例。


在下文中一共展示了Instruction.TraceBack方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetLoadStringFormatInstruction

		private static string GetLoadStringFormatInstruction (Instruction call, MethodDefinition method,
			int formatPosition)
		{
			Instruction loadString = call.TraceBack (method, -formatPosition);
			if (loadString == null)
				return null;

			// If we find a variable load, search the store
			while (loadString.IsLoadLocal ()) {
				Instruction storeIns = GetStoreLocal (loadString, method);
				if (storeIns == null)
					return null;
				loadString = storeIns.TraceBack (method);
				if (loadString == null)
					return null;
			}

			switch (loadString.OpCode.Code) {
			case Code.Call:
			case Code.Callvirt:
				return GetLoadStringFromCall (loadString.Operand as MethodReference);
			case Code.Ldstr:
				return loadString.Operand as string;
			default:
				return null;
			}
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:27,代码来源:ProvideCorrectArgumentsToFormattingMethodsRule.cs

示例2: CheckReturn

		void CheckReturn (Instruction ins, MethodDefinition method)
		{
			// trace back what is being returned
			Instruction previous = ins.TraceBack (method);
			while (previous != null) {
				// most of the time we'll find the null value on the first trace back call
				if (previous.OpCode.Code == Code.Ldnull) {
					Report (method, ins);
					break;
				}

				// but CSC non-optimized code generation results in strange IL that needs a few 
				// more calls. e.g. "return null" == "nop | ldnull | stloc.0 | br.s | ldloc.0 | ret"
				if ((previous.OpCode.FlowControl == FlowControl.Branch) || (previous.IsLoadLocal ()
					|| previous.IsStoreLocal ())) {
					previous = previous.TraceBack (method);
				} else
					break;
			}
		}
开发者ID:col42dev,项目名称:mono-tools,代码行数:20,代码来源:ReturnNullRule.cs

示例3: CheckOtherExceptions

		// ctors are identical for ArgumentNullException, ArgumentOutOfRangeException and DuplicateWaitObjectException
		private void CheckOtherExceptions (IMethodSignature constructor, Instruction ins, MethodDefinition method)
		{
			// OK		public ArgumentNullException ()
			if (!constructor.HasParameters)
				return;

			// OK		protected ArgumentNullException (SerializationInfo info, StreamingContext context)
			// OK		public ArgumentNullException (string message, Exception innerException)
			IList<ParameterDefinition> pdc = constructor.Parameters;
			if ((pdc.Count == 2) && (pdc [1].ParameterType.FullName != "System.String"))
				return;

			// CHECK	public ArgumentNullException (string paramName)
			// CHECK	public ArgumentNullException (string paramName, string message)
			Instruction call = ins.TraceBack (method, 0);
			string name = call.Operand as string;
			if (MatchesAnyParameter (method, name))
				return;

			Report (method, ins, name);
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:22,代码来源:InstantiateArgumentExceptionCorrectlyRule.cs

示例4: CheckArgumentException

		private void CheckArgumentException (IMethodSignature ctor, Instruction ins, MethodDefinition method)
		{
			// OK		public ArgumentException ()
			if (!ctor.HasParameters)
				return;

			// OK		public ArgumentException (string message)
			IList<ParameterDefinition> pdc = ctor.Parameters;
			if (pdc.Count < 2)
				return;

			// OK		public ArgumentException (string message, Exception innerException)
			if (pdc [1].ParameterType.FullName != "System.String")
				return;

			// CHECK	public ArgumentException (string message, string paramName)
			// CHECK	public ArgumentException (string message, string paramName, Exception innerException)
			Instruction call = ins.TraceBack (method, -1);
			string name = call.Operand as string;
			if (MatchesAnyParameter (method, name))
				return;

			Report (method, ins, name);
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:24,代码来源:InstantiateArgumentExceptionCorrectlyRule.cs

示例5: LocalTraceBack

		static Instruction LocalTraceBack (IMethodSignature method, Instruction ins)
		{
			ins = ins.TraceBack (method);
			while (ins != null) {
				if (ins.IsLoadLocal () || ins.IsStoreLocal ())
					return ins;
				ins = ins.TraceBack (method);
			}
			return null;
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:10,代码来源:EnsureLocalDisposalRule.cs

示例6: FullTraceBack

		// This is like the TraceBack rock except that it continues traversing backwards
		// until it finds an instruction which does not pop any values off the stack. This
		// allows us to check all of the instructions used to compute the method's
		// arguments.
		internal static Instruction FullTraceBack (IMethodSignature method, Instruction end)
		{
			Instruction first = end.TraceBack (method);
			
			while (first != null && first.GetPopCount (method) > 0) {
				first = first.TraceBack (method);
			}
			
			return first;
		}
开发者ID:alfredodev,项目名称:mono-tools,代码行数:14,代码来源:AvoidMethodsWithSideEffectsInConditionalCodeRule.cs

示例7: Analyze

		public override void Analyze (MethodDefinition method, MethodReference enter, Instruction ins)
		{
			Instruction locker = ins.TraceBack (method);
			if (locker.OpCode.Code == Code.Dup)
				locker = locker.TraceBack (method);

			string msg = CheckLocker (method, locker);
			if (msg.Length > 0)
				Runner.Report (method, ins, Severity.High, Confidence.High, msg);
		}
开发者ID:FreeBSD-DotNet,项目名称:mono-tools,代码行数:10,代码来源:DoNotLockOnThisOrTypesRule.cs

示例8: CheckReplace

        void CheckReplace(MethodDefinition method, Instruction ins)
        {
            string p1 = GetString (ins.TraceBack (method, -1));
            if (p1.Length != 1)
                return;

            string p2 = GetString (ins.TraceBack (method, -2));
            if (p2.Length != 1)
                return;

            string msg = String.Format (CultureInfo.InvariantCulture,
                "Prefer the use of: Replace('{0}','{1}');", p1, p2);
            // confidence is higher since there's no StringComparison to consider
            Runner.Report (method, ins, Severity.Medium, Confidence.High, msg);
        }
开发者ID:alfredodev,项目名称:mono-tools,代码行数:15,代码来源:PreferCharOverloadRule.cs

示例9: CheckString

		void CheckString (Instruction ins, int argumentOffset)
		{
			Instruction ld = ins.TraceBack (method, argumentOffset);
			if (null == ld)
				return;

			switch (ld.OpCode.Code) {
			case Code.Ldstr:
				CheckString (ins, (string) ld.Operand);
				break;
			case Code.Ldsfld:
				FieldReference f = (FieldReference) ld.Operand;
				if (f.Name == "Empty" && f.DeclaringType.FullName == "System.String")
					CheckString (ins, null);
				break;
			case Code.Ldnull:
				CheckString (ins, null);
				break;
			}
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:20,代码来源:ProvideValidXmlStringRule.cs

示例10: TryComputeArraySize

		private static bool TryComputeArraySize (Instruction call, MethodDefinition method, int lastParameterPosition,
			out int elementsPushed)
		{
			elementsPushed = 0;
			Instruction loadArray = call.TraceBack (method, -lastParameterPosition);

			if (loadArray == null)
				return false;

			while (loadArray.OpCode != OpCodes.Newarr) {
				if (loadArray.OpCode == OpCodes.Dup)
					loadArray = loadArray.TraceBack (method);
				else if (loadArray.IsLoadLocal ()) {
					Instruction storeIns = GetStoreLocal (loadArray, method);
					if (storeIns == null)
						return false;
					loadArray = storeIns.TraceBack (method);
				} else
					return false;

				if (loadArray == null)
					return false;
			}

			if (loadArray.Previous == null)
				return false;

			// Previous operand should be a ldc.I4 instruction type
			object previousOperand = loadArray.Previous.GetOperand (method);
			if (!(previousOperand is int))
				return false;
			elementsPushed = (int) previousOperand;
			return true;
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:34,代码来源:ProvideCorrectArgumentsToFormattingMethodsRule.cs

示例11: Compare

		static bool Compare (Instruction left, Instruction right, MethodDefinition method)
		{
			if (left == null)
				return (right == null);
			else if (right == null)
				return false;

			// is it on the same instance ?
			Instruction origin_left = left.TraceBack (method);
			Instruction origin_right = right.TraceBack (method);

			// if this is an array access the it must be the same element
			if (origin_left.IsLoadElement () && origin_right.IsLoadElement ()) {
				if (!CompareOperand (origin_left.Previous, origin_right.Previous, method))
					return false;
			} else {
				if (!CompareOperand (origin_left, origin_right, method))
					return false;
			}

			return Compare (origin_left, origin_right, method);
		}
开发者ID:FreeBSD-DotNet,项目名称:mono-tools,代码行数:22,代码来源:ReviewSelfAssignmentRule.cs

示例12: CheckOtherExceptions

		// ctors are identical for ArgumentNullException, ArgumentOutOfRangeException and DuplicateWaitObjectException
		private void CheckOtherExceptions (IMethodSignature constructor, Instruction ins, MethodDefinition method)
		{
			// OK		public ArgumentNullException ()
			if (!constructor.HasParameters)
				return;

			// OK		protected ArgumentNullException (SerializationInfo info, StreamingContext context)
			// OK		public ArgumentNullException (string message, Exception innerException)
			IList<ParameterDefinition> pdc = constructor.Parameters;
			if ((pdc.Count == 2) && !pdc [1].ParameterType.IsNamed ("System", "String"))
				return;

			// CHECK	public ArgumentNullException (string paramName)
			// CHECK	public ArgumentNullException (string paramName, string message)
			Instruction call = ins.TraceBack (method, 0);
			
			// call will be null if there is branching logic in the selection of a message - just fon't check in this case
			if (call == null)
				return;

			string name = call.Operand as string;
			if (MatchesAnyParameter (method, name))
				return;

			Report (method, ins, name);
		}
开发者ID:remobjects,项目名称:mono-tools,代码行数:27,代码来源:InstantiateArgumentExceptionCorrectlyRule.cs

示例13: GetLoadStringInstruction

        private static string GetLoadStringInstruction(Instruction call, MethodDefinition method, int formatPosition)
        {
            Instruction loadString = call.TraceBack(method, -formatPosition);
            if (loadString == null)
                return null;

            // If we find a variable load, search the store
            while (loadString.IsLoadLocal())
            {
                Instruction storeIns = GetStoreLocal(loadString, method);
                if (storeIns == null)
                    return null;
                loadString = storeIns.TraceBack(method);
                if (loadString == null)
                    return null;
            }

            var mr = loadString.Operand as MethodReference;
            if (mr != null && mr.DeclaringType.FullName == "System.String")
            {
                if (mr.Name == "Concat")
                {
                    return GetLoadStringInstruction(loadString, method, 0);
                }
            }

            switch (loadString.OpCode.Code)
            {
                case Code.Call:
                case Code.Callvirt:
                    return GetLoadStringFromCall(loadString.Operand as MethodReference);
                case Code.Ldstr:
                    return loadString.Operand as string;
                default:
                    return null;
            }
        }
开发者ID:sillsdev,项目名称:FwGendarmeRules,代码行数:37,代码来源:EnsureDebugDisposeMissDispStatementRule.cs

示例14: CheckCall

		void CheckCall (MethodDefinition method, Instruction ins, MethodReference call)
		{
			if (null == call) //resolution did not work
				return;
			if (!call.HasParameters)
				return;

			TypeReference type = call.DeclaringType;
			if (!type.IsNamed ("System.Text.RegularExpressions", "Regex") && !type.IsNamed ("System.Configuration", "RegexStringValidator"))
				return;

			MethodDefinition mdef = call.Resolve ();
			if (null == mdef)
				return;
			//check only constructors and static non-property methods
			if (!mdef.IsConstructor && (mdef.HasThis || mdef.IsProperty ()))
				return;

			foreach (ParameterDefinition p in mdef.Parameters) {
				string pname = p.Name;
				if ((pname == "pattern" || pname == "regex") && p.ParameterType.IsNamed ("System", "String")) {
					Instruction ld = ins.TraceBack (method, -(call.HasThis ? 0 : p.Index));
					if (ld != null)
						CheckArguments (method, ins, ld);
					return;
				}
			}
		}
开发者ID:col42dev,项目名称:mono-tools,代码行数:28,代码来源:ProvideCorrectRegexPatternRule.cs

示例15: CheckParameters

		private static bool CheckParameters (MethodDefinition method, Instruction ins)
		{
			Instruction prev;
			if (ins.IsLoadLocal ()) {
				prev = ins.Previous;
				while (null != prev) {
					// look for a STLOC* instruction and compare the variable indexes
					if (prev.IsStoreLocal () && AreMirrorInstructions (ins, prev, method))
						return IsGetNow (prev.Previous);
					prev = prev.Previous;
				}
			} else if (ins.OpCode.Code == Code.Ldobj) {
				prev = ins.TraceBack (method);
				ParameterDefinition p = prev.GetParameter (method);
				if (p == null)
					return false;
				int arg = p.GetSequence ();
				prev = prev.Previous;
				while (null != prev) {
					// look for a STOBJ instruction and compare the objects
					if (prev.OpCode.Code == Code.Stobj) {
						prev = prev.TraceBack (method);
						p = prev.GetParameter (method);
						return (p == null) ? false : (arg == p.GetSequence ());
					}
					prev = prev.Previous;
				}
			} else {
				return IsGetNow (ins);
			}
			return false;
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:32,代码来源:ConsiderUsingStopwatchRule.cs


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