• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ILNode类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ILNode的典型用法代码示例。如果您正苦于以下问题:C# ILNode类的具体用法?C# ILNode怎么用?C# ILNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ILNode类属于命名空间,在下文中一共展示了ILNode类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: InferTypes

		void InferTypes(ILNode node)
		{
			ILCondition cond = node as ILCondition;
			if (cond != null) {
				InferTypeForExpression(cond.Condition, typeSystem.Boolean, false);
			}
			ILWhileLoop loop = node as ILWhileLoop;
			if (loop != null && loop.Condition != null) {
				InferTypeForExpression(loop.Condition, typeSystem.Boolean, false);
			}
			ILExpression expr = node as ILExpression;
			if (expr != null) {
				ILVariable v = expr.Operand as ILVariable;
				if (v != null && v.IsGenerated && v.Type == null && expr.Code == ILCode.Stloc && !inferredVariables.Contains(v) && HasSingleLoad(v)) {
					// Don't deal with this node or its children yet,
					// wait for the expected type to be inferred first.
					// This happens with the arg_... variables introduced by the ILAst - we skip inferring the whole statement,
					// and first infer the statement that reads from the arg_... variable.
					// The ldloc inference will write the expected type to the variable, and the next InferRemainingStores() pass
					// will then infer this statement with the correct expected type.
					storedToGeneratedVariables.Add(expr);
					return;
				}
				bool anyArgumentIsMissingType = expr.Arguments.Any(a => a.InferredType == null);
				if (expr.InferredType == null || anyArgumentIsMissingType)
					expr.InferredType = InferTypeForExpression(expr, expr.ExpectedType, forceInferChildren: anyArgumentIsMissingType);
			}
			foreach (ILNode child in node.GetChildren()) {
				InferTypes(child);
			}
		}
开发者ID:hlesesne,项目名称:ILSpy,代码行数:31,代码来源:TypeAnalysis.cs


示例2: CreateDependencyGraph

		/// <summary>
		/// Creates the "ExpressionToInfer" instances (=nodes in dependency graph)
		/// </summary>
		/// <remarks>
		/// We are using a dependency graph to ensure that expressions are analyzed in the correct order.
		/// </remarks>
		void CreateDependencyGraph(ILNode node)
		{
			ILCondition cond = node as ILCondition;
			if (cond != null) {
				cond.Condition.ExpectedType = typeSystem.Boolean;
			}
			ILWhileLoop loop = node as ILWhileLoop;
			if (loop != null && loop.Condition != null) {
				loop.Condition.ExpectedType = typeSystem.Boolean;
			}
			ILTryCatchBlock.CatchBlock catchBlock = node as ILTryCatchBlock.CatchBlock;
			if (catchBlock != null && catchBlock.ExceptionVariable != null && catchBlock.ExceptionType != null && catchBlock.ExceptionVariable.Type == null) {
				catchBlock.ExceptionVariable.Type = catchBlock.ExceptionType;
			}
			ILExpression expr = node as ILExpression;
			if (expr != null) {
				ExpressionToInfer expressionToInfer = new ExpressionToInfer();
				expressionToInfer.Expression = expr;
				allExpressions.Add(expressionToInfer);
				FindNestedAssignments(expr, expressionToInfer);
				
				if (expr.Code == ILCode.Stloc && ((ILVariable)expr.Operand).Type == null)
					assignmentExpressions[(ILVariable)expr.Operand].Add(expressionToInfer);
				return;
			}
			foreach (ILNode child in node.GetChildren()) {
				CreateDependencyGraph(child);
			}
		}
开发者ID:tanujmathur,项目名称:ILSpy,代码行数:35,代码来源:TypeAnalysis.cs


示例3: AnalyzeNode

		/// <summary>
		/// For each variable reference, adds <paramref name="direction"/> to the num* dicts.
		/// Direction will be 1 for analysis, and -1 when removing a node from analysis.
		/// </summary>
		void AnalyzeNode(ILNode node, int direction = 1)
		{
			ILExpression expr = node as ILExpression;
			if (expr != null) {
				ILVariable locVar = expr.Operand as ILVariable;
				if (locVar != null) {
					if (expr.Code == ILCode.Stloc) {
						numStloc[locVar] = numStloc.GetOrDefault(locVar) + direction;
					} else if (expr.Code == ILCode.Ldloc) {
						numLdloc[locVar] = numLdloc.GetOrDefault(locVar) + direction;
					} else if (expr.Code == ILCode.Ldloca) {
						numLdloca[locVar] = numLdloca.GetOrDefault(locVar) + direction;
					} else {
						throw new NotSupportedException(expr.Code.ToString());
					}
				}
				foreach (ILExpression child in expr.Arguments)
					AnalyzeNode(child, direction);
			} else {
				var catchBlock = node as ILTryCatchBlock.CatchBlock;
				if (catchBlock != null && catchBlock.ExceptionVariable != null) {
					numStloc[catchBlock.ExceptionVariable] = numStloc.GetOrDefault(catchBlock.ExceptionVariable) + direction;
				}
				
				foreach (ILNode child in node.GetChildren())
					AnalyzeNode(child, direction);
			}
		}
开发者ID:GreenDamTan,项目名称:dnSpy,代码行数:32,代码来源:ILInlining.cs


示例4: addCreateNewNode

		public bool addCreateNewNode(ILNode node, int pos)
		{
			
			if (newBody.ContainsKey (pos)) {
				return addNewNode (node, maxCodePos+1);	
			} else {
				return addNewNode (node, pos);
			}
		}
开发者ID:yuro,项目名称:ILSpy-For-MacOSX,代码行数:9,代码来源:YieldReturnDecompiler.cs


示例5: Match

		public override bool Match(ILNode other)
		{
			ILExpression expr = other as ILExpression;
			if (expr != null && expr.Code == ILCode.Stloc && (!MustBeGenerated || ((ILVariable)expr.Operand).IsGenerated) && Match(this.Arguments, expr.Arguments)) {
				this.LastMatch = expr;
				return true;
			} else {
				return false;
			}
		}
开发者ID:hlesesne,项目名称:ILSpy,代码行数:10,代码来源:Pattern.cs


示例6: AddILRangesTryPreviousFirst

		public static void AddILRangesTryPreviousFirst(ILNode prev, ILNode next, ILBlockBase block, IEnumerable<ILRange> ilRanges)
		{
			if (prev != null && prev.SafeToAddToEndILRanges)
				prev.EndILRanges.AddRange(ilRanges);
			else if (next != null)
				next.ILRanges.AddRange(ilRanges);
			else if (prev != null)
				block.EndILRanges.AddRange(ilRanges);
			else
				block.ILRanges.AddRange(ilRanges);
		}
开发者ID:arkanoid1,项目名称:dnSpy,代码行数:11,代码来源:Utils.cs


示例7: addNewNode

		public bool addNewNode(ILNode node, int pos)
		{
			if (newBody.ContainsKey (pos)) {
				return false;
			}


			if (pos > maxCodePos) {
				maxCodePos = pos;
			}
			this.newBody.Add (pos,node);
			return true;
		}
开发者ID:yuro,项目名称:ILSpy-For-MacOSX,代码行数:13,代码来源:YieldReturnDecompiler.cs


示例8: InlineIfPossible

		/// <summary>
		/// Inlines 'expr' into 'next', if possible.
		/// </summary>
		public static bool InlineIfPossible(ILExpression expr, ILNode next, ILBlock method)
		{
			if (expr.Code != ILCode.Stloc)
				throw new ArgumentException("expr must be stloc");
			// ensure the variable is accessed only a single time
			if (method.GetSelfAndChildrenRecursive<ILExpression>().Count(e => e != expr && e.Operand == expr.Operand) != 1)
				return false;
			ILExpression parent;
			int pos;
			if (FindLoadInNext(next as ILExpression, (ILVariable)expr.Operand, out parent, out pos) == true) {
				parent.Arguments[pos] = expr.Arguments[0];
				return true;
			}
			return false;
		}
开发者ID:hlesesne,项目名称:ILSpy,代码行数:18,代码来源:ILInlining.cs


示例9: AddILRangesToInstruction

 public static void AddILRangesToInstruction(ILNode nodeToAddTo, ILNode prev, ILNode next, ILBlockBase block, ILNode removed)
 {
     Debug.Assert(nodeToAddTo == prev || nodeToAddTo == next || nodeToAddTo == block);
     if (nodeToAddTo != null) {
         if (nodeToAddTo == prev && prev.SafeToAddToEndILRanges) {
             removed.AddSelfAndChildrenRecursiveILRanges(prev.EndILRanges);
             return;
         }
         else if (nodeToAddTo != null && nodeToAddTo == next) {
             removed.AddSelfAndChildrenRecursiveILRanges(next.ILRanges);
             return;
         }
     }
     AddILRangesTryNextFirst(prev, next, block, removed);
 }
开发者ID:,项目名称:,代码行数:15,代码来源:


示例10: Visit

    public virtual ILNode Visit(ILNode node)
    {
        if (node == null)
            return node;

        var block = node as ILBlock;
        if (block != null)
            return VisitBlock(block);

        var basicBlock = node as ILBasicBlock;
        if (basicBlock != null)
            return VisitBasicBlock(basicBlock);

        var label = node as ILLabel;
        if (label != null)
            return VisitLabel(label);

        var tryCatchBlock = node as ILTryCatchBlock;
        if (tryCatchBlock != null)
            return VisitTryCatchBlock(tryCatchBlock);

        var expression = node as ILExpression;
        if (expression != null)
            return VisitExpression(expression);

        var whileLoop = node as ILWhileLoop;
        if (whileLoop != null)
            return VisitWhileLoop(whileLoop);

        var condition = node as ILCondition;
        if (condition != null)
            return VisitCondition(condition);

        var switchStatement = node as ILSwitch;
        if (switchStatement != null)
            return VisitSwitch(switchStatement);

        var fixedStatement = node as ILFixedStatement;
        if (fixedStatement != null)
            return VisitFixedStatement(fixedStatement);

        throw new NotSupportedException();
    }
开发者ID:ropean,项目名称:Usable,代码行数:43,代码来源:ILNodeVisitor.cs


示例11: Enter

        /// <summary>
        /// Get the first expression to be excecuted if the instruction pointer is at the start of the given node.
        /// Try blocks may not be entered in any way.  If possible, the try block is returned as the node to be executed.
        /// </summary>
        ILNode Enter(ILNode node, HashSet<ILNode> visitedNodes)
        {
            if (node == null)
                throw new ArgumentNullException();

            if (!visitedNodes.Add(node))
                return null;  // Infinite loop

            ILLabel label = node as ILLabel;
            if (label != null) {
                return Exit(label, visitedNodes);
            }

            ILExpression expr = node as ILExpression;
            if (expr != null) {
                if (expr.Code == ILCode.Br || expr.Code == ILCode.Leave) {
                    ILLabel target = (ILLabel)expr.Operand;
                    // Early exit - same try-block
                    if (GetParents(expr).OfType<ILTryCatchBlock>().FirstOrDefault() == GetParents(target).OfType<ILTryCatchBlock>().FirstOrDefault())
                        return Enter(target, visitedNodes);
                    // Make sure we are not entering any try-block
                    var srcTryBlocks = GetParents(expr).OfType<ILTryCatchBlock>().Reverse().ToList();
                    var dstTryBlocks = GetParents(target).OfType<ILTryCatchBlock>().Reverse().ToList();
                    // Skip blocks that we are already in
                    int i = 0;
                    while(i < srcTryBlocks.Count && i < dstTryBlocks.Count && srcTryBlocks[i] == dstTryBlocks[i]) i++;
                    if (i == dstTryBlocks.Count) {
                        return Enter(target, visitedNodes);
                    } else {
                        ILTryCatchBlock dstTryBlock = dstTryBlocks[i];
                        // Check that the goto points to the start
                        ILTryCatchBlock current = dstTryBlock;
                        while(current != null) {
                            foreach(ILNode n in current.TryBlock.Body) {
                                if (n is ILLabel) {
                                    if (n == target)
                                        return dstTryBlock;
                                } else if (!n.Match(ILCode.Nop)) {
                                    current = n as ILTryCatchBlock;
                                    break;
                                }
                            }
                        }
                        return null;
                    }
                } else if (expr.Code == ILCode.Nop) {
                    return Exit(expr, visitedNodes);
                } else if (expr.Code == ILCode.LoopOrSwitchBreak) {
                    ILNode breakBlock = GetParents(expr).First(n => n is ILWhileLoop || n is ILSwitch);
                    return Exit(breakBlock, new HashSet<ILNode>() { expr });
                } else if (expr.Code == ILCode.LoopContinue) {
                    ILNode continueBlock = GetParents(expr).First(n => n is ILWhileLoop);
                    return Enter(continueBlock, new HashSet<ILNode>() { expr });
                } else {
                    return expr;
                }
            }

            ILBlock block = node as ILBlock;
            if (block != null) {
                if (block.EntryGoto != null) {
                    return Enter(block.EntryGoto, visitedNodes);
                } else if (block.Body.Count > 0) {
                    return Enter(block.Body[0], visitedNodes);
                } else {
                    return Exit(block, visitedNodes);
                }
            }

            ILCondition cond = node as ILCondition;
            if (cond != null) {
                return cond.Condition;
            }

            ILWhileLoop loop = node as ILWhileLoop;
            if (loop != null) {
                if (loop.Condition != null) {
                    return loop.Condition;
                } else {
                    return Enter(loop.BodyBlock, visitedNodes);
                }
            }

            ILTryCatchBlock tryCatch = node as ILTryCatchBlock;
            if (tryCatch != null) {
                return tryCatch;
            }

            ILSwitch ilSwitch = node as ILSwitch;
            if (ilSwitch != null) {
                return ilSwitch.Condition;
            }

            throw new NotSupportedException(node.GetType().ToString());
        }
开发者ID:n017,项目名称:dnSpy,代码行数:99,代码来源:GotoRemoval.cs


示例12: ToLNode

		/// <summary>Converts <see cref="ILNode"/> to <see cref="LNode"/> recursively.
		/// If the specified node is already an <see cref="LNode"/>, this method simply
		/// does a cast.</summary>
		public static LNode ToLNode(ILNode node)
		{
			return node is LNode ? (LNode)node : ToLNodeCore(node);
		}
开发者ID:qwertie,项目名称:ecsharp,代码行数:7,代码来源:LNodeExt.cs


示例13: ToLNodeCore

		static LNode ToLNodeCore(ILNode node)
		{
			var attrs = VList<LNode>.Empty;
			for (int i = node.Min; i < -1; i++)
				attrs.Add(ToLNodeCore(node[i]));

			switch (node.Kind) {
				case LNodeKind.Id:
					return LNode.Id(attrs, node.Name, node.Range, node.Style);
				case LNodeKind.Literal:
					return LNode.Literal(attrs, node.Value, node.Range, node.Style);
				default:
					var args = VList<LNode>.Empty;
					for (int i = 0, max = node.Max; i <= max; i++)
						args.Add(ToLNodeCore(node[i]));
					var target = ToLNodeCore(node.Target);
					return LNode.Call(attrs, target, args, node.Range, node.Style);
			}
		}
开发者ID:qwertie,项目名称:ecsharp,代码行数:19,代码来源:LNodeExt.cs


示例14: ContainsLabels

 protected bool ContainsLabels(ILNode root)
 {
     var label = root.GetSelfAndChildrenRecursive<ILLabel>().FirstOrDefault();
     return label != null;
 }
开发者ID:aprishchepov,项目名称:JSIL,代码行数:5,代码来源:ILBlockTranslator.cs


示例15: TranslateStatement

        protected JSStatement TranslateStatement(ILNode node)
        {
            var translated = TranslateNode(node as dynamic);

            var statement = translated as JSStatement;
            if (statement == null) {
                var expression = (JSExpression)translated;

                if (expression != null)
                    statement = new JSExpressionStatement(expression);
                else
                    Console.Error.WriteLine("Warning: Null statement: {0}", node);
            }

            return statement;
        }
开发者ID:aprishchepov,项目名称:JSIL,代码行数:16,代码来源:ILBlockTranslator.cs


示例16: FlattenNestedMovableBlocks

 /// <summary>
 /// Flattens all nested movable blocks, except the the top level 'node' argument
 /// </summary>
 void FlattenNestedMovableBlocks(ILNode node)
 {
     ILBlock block = node as ILBlock;
     if (block != null) {
         List<ILNode> flatBody = new List<ILNode>();
         if (block.EntryPoint != null) {
             flatBody.Add(new ILExpression(OpCodes.Br, block.EntryPoint));
             block.EntryPoint = null;
         }
         foreach (ILNode child in block.Body) {
             FlattenNestedMovableBlocks(child);
             if (child is ILMoveableBlock) {
                 flatBody.AddRange(((ILMoveableBlock)child).Body);
             } else {
                 flatBody.Add(child);
             }
         }
         block.Body = flatBody;
     } else if (node is ILExpression) {
         // Optimization - no need to check expressions
     } else if (node != null) {
         // Recursively find all ILBlocks
         foreach(ILNode child in node.GetChildren()) {
             FlattenNestedMovableBlocks(child);
         }
     }
 }
开发者ID:FriedWishes,项目名称:ILSpy,代码行数:30,代码来源:ILAstOptimizer.cs


示例17: MatchStateAssignment

 bool MatchStateAssignment(ILNode stfld, out int stateID)
 {
     // stfld(StateMachine::<>1__state, ldloc(this), ldc.i4(stateId))
     stateID = 0;
     IField fieldRef;
     ILExpression target, val;
     if (stfld.Match(ILCode.Stfld, out fieldRef, out target, out val)) {
         return fieldRef.ResolveFieldWithinSameModule() == stateField
             && target.MatchThis()
             && val.Match(ILCode.Ldc_I4, out stateID);
     }
     return false;
 }
开发者ID:n017,项目名称:dnSpy,代码行数:13,代码来源:AsyncDecompiler.cs


示例18: Info

 public static void Info(string msg, ILNode node, params object[] o)
 {
     ErrorContext.Out.Info(msg,node, o);
 }
开发者ID:WarlockD,项目名称:GMdsam,代码行数:4,代码来源:GMContext.cs


示例19: Warning

 public static void Warning(string msg, ILNode node, params object[] o)
 {
     ErrorContext.Out.Warning(msg, node, o);
 }
开发者ID:WarlockD,项目名称:GMdsam,代码行数:4,代码来源:GMContext.cs


示例20: FlattenBasicBlocks

 /// <summary>
 /// Flattens all nested basic blocks, except the the top level 'node' argument
 /// </summary>
 void FlattenBasicBlocks(ILNode node)
 {
     ILBlock block = node as ILBlock;
     if (block != null) {
         List<ILNode> flatBody = new List<ILNode>();
         foreach (ILNode child in block.GetChildren()) {
             FlattenBasicBlocks(child);
             if (child is ILBasicBlock) {
                 flatBody.AddRange(child.GetChildren());
             } else {
                 flatBody.Add(child);
             }
         }
         block.EntryGoto = null;
         block.Body = flatBody;
     } else if (node is ILExpression) {
         // Optimization - no need to check expressions
     } else if (node != null) {
         // Recursively find all ILBlocks
         foreach(ILNode child in node.GetChildren()) {
             FlattenBasicBlocks(child);
         }
     }
 }
开发者ID:petr-k,项目名称:ILSpy,代码行数:27,代码来源:ILAstOptimizer.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ILOpCode类代码示例发布时间:2022-05-24
下一篇:
C# ILLabel类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap