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


C# AstNode.GetType方法代码示例

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


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

示例1: GetNodeTitle

		string GetNodeTitle(AstNode node)
		{
			StringBuilder b = new StringBuilder();
			b.Append(node.Role.ToString());
			b.Append(": ");
			b.Append(node.GetType().Name);
			bool hasProperties = false;
			foreach (PropertyInfo p in node.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) {
				if (p.Name == "NodeType" || p.Name == "IsNull")
					continue;
				if (p.PropertyType == typeof(string) || p.PropertyType.IsEnum || p.PropertyType == typeof(bool)) {
					if (!hasProperties) {
						hasProperties = true;
						b.Append(" (");
					} else {
						b.Append(", ");
					}
					b.Append(p.Name);
					b.Append(" = ");
					try {
						object val = p.GetValue(node, null);
						b.Append(val != null ? val.ToString() : "**null**");
					} catch (TargetInvocationException ex) {
						b.Append("**" + ex.InnerException.GetType().Name + "**");
					}
				}
			}
			if (hasProperties)
				b.Append(")");
			return b.ToString();
		}
开发者ID:ThomasZitzler,项目名称:ILSpy,代码行数:31,代码来源:MainForm.cs

示例2: AreEqual

 public static bool? AreEqual(AstNode node1, AstNode node2)
 {
     if (node1 == node2)
         return true;
     if (node1 == null || node1.IsNull || node2 == null || node2.IsNull)
         return false;
     Type nodeType = node1.GetType();
     if (nodeType != node2.GetType())
         return false;
     if (node1.Role != node2.Role)
         return false;
     AstNode child1 = node1.FirstChild;
     AstNode child2 = node2.FirstChild;
     bool? result = true;
     while (result != false && (child1 != null || child2 != null)) {
         result &= AreEqual(child1, child2);
         child1 = child1.NextSibling;
         child2 = child2.NextSibling;
     }
     if (nodeTypesWithoutExtraInfo.Contains(nodeType))
         return result;
     if (nodeType == typeof(Identifier))
         return ((Identifier)node1).Name == ((Identifier)node2).Name;
     return null;
 }
开发者ID:FriedWishes,项目名称:ILSpy,代码行数:25,代码来源:AstComparer.cs

示例3: PrintNode

		static void PrintNode (AstNode node)
		{
			Console.WriteLine ("Parent:" + node.GetType ());
			Console.WriteLine ("Children:");
			foreach (var c in node.Children)
				Console.WriteLine (c.GetType () +" at:"+ c.StartLocation +"-"+ c.EndLocation + " Role: "+ c.Role);
			Console.WriteLine ("----");
		}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:8,代码来源:ConsistencyChecker.cs

示例4: CreateException

        public virtual IVisitorException CreateException(AstNode node, string message)
        {
            if (String.IsNullOrEmpty(message))
            {
                message = String.Format("Language construction {0} is not supported", node.GetType().Name);
            }

            return new EmitterException(node, message);
        }
开发者ID:fabriciomurta,项目名称:BridgeUnified,代码行数:9,代码来源:Visitor.Exception.cs

示例5: Serialize

 public static string Serialize(AstNode Node)
 {
     var Parameters = new List<string>();
     foreach (var Child in Node.Childs)
     {
         Parameters.Add(Serialize(Child));
     }
     return Node.GetType().Name + "(" + String.Join(", ", Parameters) + ")";
 }
开发者ID:soywiz,项目名称:SafeILGenerator,代码行数:9,代码来源:AstSerializer.cs

示例6: GenerateNode

        public static void GenerateNode(JSContext context, TextWriter textWriter, AstNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (node is IJSBasicNode)
            {
                IJSBasicNode jsBasicNode = (IJSBasicNode)node;
                jsBasicNode.GenerateJavaScript(context, textWriter);
            }
            else if (node is Token)
            {
                Token t = (Token)node;
                switch (t.Terminal.Name)
                {
                    case "VARIABLE":
                        if (t.Text.EndsWith("$"))
                        {
                            textWriter.Write("s_" + t.Text.Substring(0, t.Text.Length - 1));
                        }
                        else
                        {
                            throw new BasicSyntaxErrorException("Invalid variable name: " + t.Text);
                        }
                        break;
                    case "BOOLEAN_OP":
                        {
                            switch (t.Text.ToLowerInvariant())
                            {
                                case "and":
                                    textWriter.Write("&&");
                                    break;
                                case "or":
                                    textWriter.Write("||");
                                    break;
                                default:
                                    textWriter.Write(t.Text);
                                    break;
                            }
                        }
                        break;
                    default:
                        textWriter.Write(ConvertToJavascript(t.Text));
                        break;
                }
                textWriter.Write(" ");
            }
            else
            {
                throw new ApplicationException("Unhandled statement type: " + node.GetType().FullName);
            }
        }
开发者ID:danielflower,项目名称:JSBasic,代码行数:54,代码来源:GeneratorHelper.cs

示例7: Optimize

        public AstNode Optimize(AstNode AstNode)
        {
            //if (AstNode != null)
            {
                //Console.WriteLine("Optimize.AstNode: {0}", AstNode);
                AstNode.TransformNodes(Optimize);

                var AstNodeType = AstNode.GetType();

                if (GenerateMappings.ContainsKey(AstNodeType))
                {
                    AstNode = (AstNode)GenerateMappings[AstNodeType].Invoke(this, new[] { AstNode });
                }
                else
                {
                    //throw(new NotImplementedException(String.Format("Don't know how to optimize {0}", AstNodeType)));
                }
            }

            return AstNode;
        }
开发者ID:soywiz,项目名称:SafeILGenerator,代码行数:21,代码来源:AstOptimizer.cs

示例8: SerializeAsXml

 private static void SerializeAsXml(AstNode Node, IndentedStringBuilder Out, bool Spaces)
 {
     var NodeName = Node.GetType().Name;
     Out.Write("<" + NodeName);
     var Parameters = Node.Info;
     if (Parameters != null)
     {
         foreach (var Pair in Parameters)
         {
             Out.Write(String.Format(" {0}=\"{1}\"", Pair.Key, Pair.Value));
         }
     }
     if (Node.Childs.Count() > 0)
     {
         Out.Write(">");
         if (Spaces) Out.WriteNewLine();
         if (Spaces)
         {
             Out.Indent(() =>
             {
                 foreach (var Child in Node.Childs) SerializeAsXml(Child, Out, Spaces);
             });
         }
         else
         {
             foreach (var Child in Node.Childs) SerializeAsXml(Child, Out, Spaces);
         }
         Out.Write("</" + NodeName + ">");
         if (Spaces) Out.WriteNewLine();
     }
     else
     {
         Out.Write(" />");
         if (Spaces) Out.WriteNewLine();
     }
 }
开发者ID:soywiz,项目名称:SafeILGenerator,代码行数:36,代码来源:AstSerializer.cs

示例9: CheckPositionConsistency

		public static void CheckPositionConsistency (AstNode node, string currentFileName, IDocument currentDocument = null)
		{
			if (currentDocument == null)
				currentDocument = new ReadOnlyDocument(File.ReadAllText(currentFileName));
			string comment = "(" + node.GetType ().Name + " at " + node.StartLocation + " in " + currentFileName + ")";
			var pred = node.StartLocation <= node.EndLocation;
			if (!pred)
				PrintNode (node);
			Assert.IsTrue(pred, "StartLocation must be before EndLocation " + comment);
			var prevNodeEnd = node.StartLocation;
			var prevNode = node;
			for (AstNode child = node.FirstChild; child != null; child = child.NextSibling) {
				bool assertion = child.StartLocation >= prevNodeEnd;
				if (!assertion) {
					PrintNode (prevNode);
					PrintNode (node);
				}
				Assert.IsTrue(assertion, currentFileName + ": Child " + child.GetType () +" (" + child.StartLocation  + ")" +" must start after previous sibling " + prevNode.GetType () + "(" + prevNode.StartLocation + ")");
				CheckPositionConsistency(child, currentFileName, currentDocument);
				prevNodeEnd = child.EndLocation;
				prevNode = child;
			}
			Assert.IsTrue(prevNodeEnd <= node.EndLocation, "Last child must end before parent node ends " + comment);
		}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:24,代码来源:ConsistencyChecker.cs

示例10: CompileRecursive

 private void CompileRecursive(AstNode node, Syt syt, StringBuilder sb)
 {
     if (node is AstBinOp) CompileBinOp((AstBinOp)node, syt, sb);
     else if (node is AstBoolLit) CompileBoolLit((AstBoolLit)node, syt, sb);
     else if (node is AstCall) CompileCall((AstCall)node, syt, sb);
     else if (node is AstClass) CompileClass((AstClass)node, syt, sb);
     else if (node is AstClassDecl) CompileClassDecl((AstClassDecl)node, syt, sb);
     else if (node is AstDo) CompileDo((AstDo)node, syt, sb);
     else if (node is AstDot) CompileDot((AstDot)node, syt, sb);
     else if (node is AstIf) CompileIf((AstIf)node, syt, sb);
     else if (node is AstIndex) CompileIndex((AstIndex)node, syt, sb);
     else if (node is AstIntLit) CompileIntLit((AstIntLit)node, syt, sb);
     else if (node is AstLet) CompileLet((AstLet)node, syt, sb);
     else if (node is AstNull) CompileNull((AstNull)node, syt, sb);
     else if (node is AstReturn) CompileReturn((AstReturn)node, syt, sb);
     else if (node is AstStringLit) CompileStringLit((AstStringLit)node, syt, sb);
     else if (node is AstSubroutine) CompileSubroutine((AstSubroutine)node, syt, sb);
     else if (node is AstThis) CompileThis((AstThis)node, syt, sb);
     else if (node is AstUnOp) CompileUnOp((AstUnOp)node, syt, sb);
     else if (node is AstVarDecl) CompileVarDecl((AstVarDecl)node, syt, sb);
     else if (node is AstVarRef) CompileVarRef((AstVarRef)node, syt, sb);
     else if (node is AstWhile) CompileWhile((AstWhile)node, syt, sb);
     else throw new ArgumentException("Unkonwn node " + node.GetType());
 }
开发者ID:encse,项目名称:nand2tetris,代码行数:24,代码来源:JackCompiler.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>
		AstNode Enter(AstNode node, HashSet<AstNode> visitedNodes)
		{
			if (node == null)
				throw new ArgumentNullException();
			
			if (!visitedNodes.Add(node))
				return null;  // Infinite loop
			
			AstLabel label = node as AstLabel;
			if (label != null) {
				return Exit(label, visitedNodes);
			}
			
			AstExpression expr = node as AstExpression;
			if (expr != null) {
				if (expr.Code == AstCode.Br || expr.Code == AstCode.Leave) {
					AstLabel target = (AstLabel)expr.Operand;
					// Early exit - same try-block
					if (GetParents(expr).OfType<AstTryCatchBlock>().FirstOrDefault() == GetParents(target).OfType<AstTryCatchBlock>().FirstOrDefault())
						return Enter(target, visitedNodes);
					// Make sure we are not entering any try-block
					var srcTryBlocks = GetParents(expr).OfType<AstTryCatchBlock>().Reverse().ToList();
					var dstTryBlocks = GetParents(target).OfType<AstTryCatchBlock>().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 {
						AstTryCatchBlock dstTryBlock = dstTryBlocks[i];
						// Check that the goto points to the start
						AstTryCatchBlock current = dstTryBlock;
						while(current != null) {
							foreach(AstNode n in current.TryBlock.Body) {
								if (n is AstLabel) {
									if (n == target)
										return dstTryBlock;
								} else if (!n.Match(AstCode.Nop)) {
									current = n as AstTryCatchBlock;
									break;
								}
							}
						}
						return null;
					}
				} else if (expr.Code == AstCode.Nop) {
					return Exit(expr, visitedNodes);
				} else if (expr.Code == AstCode.LoopOrSwitchBreak) {
					AstNode breakBlock = GetParents(expr).First(n => n is AstSwitch);
					return Exit(breakBlock, new HashSet<AstNode>() { expr });
				} else {
					return expr;
				}
			}
			
			AstBlock block = node as AstBlock;
			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);
				}
			}
					
			AstTryCatchBlock tryCatch = node as AstTryCatchBlock;
			if (tryCatch != null) {
				return tryCatch;
			}
			
			AstSwitch astSwitch = node as AstSwitch;
			if (astSwitch != null) {
				return astSwitch.Condition;
			}
			
			throw new NotSupportedException(node.GetType().ToString());
		}
开发者ID:Xtremrules,项目名称:dot42,代码行数:82,代码来源:GotoRemoval.cs

示例12: StartNew

            public static JavaScriptSymbol StartNew(AstNode node, int startLine, int startColumn, int sourceFileId)
            {
                if (startLine == int.MaxValue)
                {
                    throw new ArgumentOutOfRangeException("startLine");
                }

                if (startColumn == int.MaxValue)
                {
                    throw new ArgumentOutOfRangeException("startColumn");
                }

                return new JavaScriptSymbol
                {
                    // destination line/col number are fed to us as zero-based, so add one to get to
                    // the one-based values we desire. Context objects store the source line/col as
                    // one-based already.
                    m_startLine = startLine + 1,
                    m_startColumn = startColumn + 1,
                    m_sourceContext = node != null ? node.Context : null,
                    m_symbolType = node != null ? node.GetType().Name : "[UNKNOWN]",
                    m_sourceFileId = sourceFileId,
                };
            }
开发者ID:Aliceljm1,项目名称:kiss-project.web,代码行数:24,代码来源:ScriptSharpSourceMap.cs

示例13: GetDefaultXMLNamespace

 private string GetDefaultXMLNamespace(AstNode astNode)
 {
     return GetDefaultXMLNamespace(astNode.GetType());
 }
开发者ID:japj,项目名称:vulcan,代码行数:4,代码来源:XmlToAstParserPhase.cs

示例14: GetPropertyBinding

 private PropertyBindingAttributePair GetPropertyBinding(AstNode astNode, XName xObjectName, bool patchDefaultNamespace)
 {
     Type astNodeType = astNode.GetType();
     if (this._PropertyMappingDictionary.ContainsKey(astNodeType))
     {
         Dictionary<XName, PropertyBindingAttributePair> propertyBinding = this._PropertyMappingDictionary[astNodeType];
         if (propertyBinding.ContainsKey(xObjectName))
         {
             return propertyBinding[xObjectName];
         }
         else if (patchDefaultNamespace && xObjectName.NamespaceName.Equals(String.Empty))
         {
             // targetNamespace is not applied to attributes, so this code will use the DefaultXMLNamespace to perform XName matching when specified (i.e. for attributes)
             return GetPropertyBinding(astNode, XName.Get(xObjectName.LocalName, GetDefaultXMLNamespace(astNode)), false);
         }
     }
     return null;
 }
开发者ID:japj,项目名称:vulcan,代码行数:18,代码来源:XmlToAstParserPhase.cs

示例15: NotSupported

 private void NotSupported(AstNode node)
 {
     context.ReportError(node.Region, node.GetType().Name + " is unsupported");
     wasSuccessful = false;
 }
开发者ID:evanw,项目名称:minisharp,代码行数:5,代码来源:Lower.cs


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