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


C# ParseTree.FindChildByName方法代码示例

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


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

示例1: GetNodeDeclaration

	private static SymbolDeclaration GetNodeDeclaration(ParseTree.Node node, string fileName = null)
	{
		if (node.declaration == null)
		{
			var declarationSemantics = node.semantics & SemanticFlags.SymbolDeclarationsMask;

			var enclosingScopeNode = EnclosingSemanticNode(node.parent, SemanticFlags.ScopesMask);
			var enclosingScope = GetNodeScope(enclosingScopeNode, fileName);
			
			if (enclosingScope == null)
				return null;

			ParseTree.BaseNode modifiersNode = null;
			ParseTree.BaseNode partialNode = null;
			ParseTree.Node typeParamsNode = null;

			switch (declarationSemantics)
			{
				case SemanticFlags.NamespaceDeclaration:
					node.declaration = new NamespaceDeclaration { parseTreeNode = node, kind = SymbolKind.Namespace };
					break;

				case SemanticFlags.UsingNamespace:
					node.declaration = new SymbolDeclaration { parseTreeNode = node, kind = SymbolKind.ImportedNamespace };
					break;
					//var namespaceToImport = node.Print();
					//(enclosingScope as NamespaceScope).declaration.importedNamespaces[namespaceToImport] = new SymbolReference(node.ChildAt(0));
					//return null;

				case SemanticFlags.UsingAlias:
					node.declaration = new SymbolDeclaration { parseTreeNode = node, kind = SymbolKind.TypeAlias };
					break;
					//var name = node.ChildAt(0).Print();
					//((NamespaceScope) enclosingScope).declaration.typeAliases[name] = new SymbolReference(node.ChildAt(2));
					//return null;

				case SemanticFlags.ExternAlias:
					break;
				case SemanticFlags.ClassDeclaration:
					modifiersNode = node.parent.FindChildByName("modifiers");
					partialNode = node.parent.FindChildByName("PARTIAL");
					node.declaration = new SymbolDeclaration { parseTreeNode = node, kind = SymbolKind.Class };
					typeParamsNode = node.FindChildByName("typeParameterList") as ParseTree.Node;
				//	Debug.Log(node.declaration + " mods: " + node.declaration.modifiers);
					break;
				case SemanticFlags.TypeParameterDeclaration:
					node.declaration = new SymbolDeclaration { parseTreeNode = node, kind = SymbolKind.TypeParameter };
					break;
				case SemanticFlags.BaseListDeclaration:
					node.declaration = new SymbolDeclaration { parseTreeNode = node, kind = SymbolKind.BaseTypesList };
					break;
				case SemanticFlags.ConstantDeclarator:
					modifiersNode = node.parent.parent.parent.FindChildByName("modifiers");
					node.declaration = new SymbolDeclaration {
						parseTreeNode = node,
						kind =
							node.parent.parent.RuleName == "constantDeclaration" ?
							SymbolKind.ConstantField :
							SymbolKind.LocalConstant
					};
					break;
				case SemanticFlags.ConstructorDeclarator:
					modifiersNode = node.parent.FindChildByName("modifiers");
					node.declaration = new SymbolDeclaration { parseTreeNode = node, kind = SymbolKind.Constructor };
					break;
				case SemanticFlags.DestructorDeclarator:
					node.declaration = new SymbolDeclaration { parseTreeNode = node, kind = SymbolKind.Destructor };
					break;
				case SemanticFlags.OperatorDeclarator:
				case SemanticFlags.ConversionOperatorDeclarator:
					modifiersNode = node.parent.parent.FindChildByName("modifiers");
					node.declaration = new SymbolDeclaration { parseTreeNode = node, kind = SymbolKind.Operator };
					break;
				case SemanticFlags.MethodDeclarator:
					modifiersNode = node.parent.FindChildByName("modifiers");
					typeParamsNode = node.NodeAt(0);
					if (typeParamsNode != null)
						typeParamsNode = typeParamsNode.NodeAt(0);
					if (typeParamsNode != null)
						typeParamsNode = typeParamsNode.NodeAt(0);
					if (typeParamsNode != null)
						typeParamsNode = typeParamsNode.NodeAt(-1);
					if (typeParamsNode != null)
						typeParamsNode = typeParamsNode.FindChildByName("typeParameterList") as ParseTree.Node;
					node.declaration = new SymbolDeclaration { parseTreeNode = node, kind = SymbolKind.Method };
					break;
				case SemanticFlags.LocalVariableDeclarator:
					node.declaration = new SymbolDeclaration { parseTreeNode = node, kind = SymbolKind.Variable };
					break;
				case SemanticFlags.ForEachVariableDeclaration:
					node.declaration = new SymbolDeclaration { parseTreeNode = node, kind = SymbolKind.ForEachVariable };
					break;
				case SemanticFlags.FromClauseVariableDeclaration:
					node.declaration = new SymbolDeclaration { parseTreeNode = node, kind = SymbolKind.FromClauseVariable };
					break;
				case SemanticFlags.LabeledStatement:
					node.declaration = new SymbolDeclaration { parseTreeNode = node, kind = SymbolKind.Label };
					break;
				case SemanticFlags.CatchExceptionParameterDeclaration:
					node.declaration = new SymbolDeclaration { parseTreeNode = node, kind = SymbolKind.CatchParameter };
//.........这里部分代码省略.........
开发者ID:JuanJosePol,项目名称:ggjmallorca2016,代码行数:101,代码来源:CsGrammar.cs


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