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


C# ILNode.GetType方法代码示例

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


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

示例1: 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

示例2: TranslateNode

        public JSNode TranslateNode(ILNode node)
        {
            Console.Error.WriteLine("Node        NYI: {0}", node.GetType().Name);

            return new JSUntranslatableStatement(node.GetType().Name);
        }
开发者ID:aprishchepov,项目名称:JSIL,代码行数:6,代码来源:ILBlockTranslator.cs

示例3: 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 == GMCode.B)
                {
                    ILLabel target = (ILLabel)expr.Operand;
                    return Enter(target, visitedNodes);
                }
                else if (expr.Code == GMCode.BadOp  || expr.Code == GMCode.Constant || expr.Code == GMCode.Var)
                {
                    return Exit(expr, visitedNodes);
                }
                else if (expr.Code == GMCode.LoopOrSwitchBreak)
                {
                    ILNode breakBlock = GetParents(expr).First(n => n is ILWhileLoop || n is ILSwitch || n is ILWithStatement);
                    return Exit(breakBlock, new HashSet<ILNode>() { expr });
                }
                else if (expr.Code == GMCode.LoopContinue)
                {
                    ILNode continueBlock = GetParents(expr).First(n => n is ILWhileLoop || n is ILWithStatement);
                    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.Body, visitedNodes);
                }
            }

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

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

示例4: TranslateNode

        public JSNode TranslateNode(ILNode node)
        {
            Translator.WarningFormat("Node        NYI: {0}", node.GetType().Name);

            return new JSUntranslatableStatement(node.GetType().Name);
        }
开发者ID:shreedharcva,项目名称:JSIL,代码行数:6,代码来源:ILBlockTranslator.cs

示例5: Enter

		/// <summary>
		/// Get the first expression to be excecuted if the instruction pointer is at the start of the given node
		/// </summary>
		ILExpression 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) {
					return Enter((ILLabel)expr.Operand, visitedNodes);
				} else if (expr.Code == ILCode.Nop) {
					return Exit(expr, visitedNodes);
				} 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 Enter(tryCatch.TryBlock, visitedNodes);
			}
			
			ILSwitch ilSwitch = node as ILSwitch;
			if (ilSwitch != null) {
				return ilSwitch.Condition;
			}
			
			throw new NotSupportedException(node.GetType().ToString());
		}
开发者ID:stgwilli,项目名称:ILSpy,代码行数:64,代码来源:GotoRemoval.cs


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