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


C# AstNode.AddChild方法代码示例

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


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

示例1: AddArguments

			void AddArguments(AstNode parent, Arguments args)
			{
				if (args == null)
					return;
				
				var commaLocations = LocationsBag.GetLocations(args);
				for (int i = 0; i < args.Count; i++) {
					parent.AddChild(ConvertArgument(args [i]), Roles.Argument);
					if (commaLocations != null && i < commaLocations.Count) {
						parent.AddChild(new CSharpTokenNode(Convert(commaLocations [i]), Roles.Comma), Roles.Comma);
					}
				}
				if (commaLocations != null && commaLocations.Count > args.Count)
					parent.AddChild(new CSharpTokenNode(Convert(commaLocations [args.Count]), Roles.Comma), Roles.Comma);
			}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:15,代码来源:CSharpParser.cs

示例2: Expr

 /* expr    ->   "print"  term
                | "input"  IDENT
                | IDENT  "="  term
                | "if" "(" add ")" "then" expr "else" expr
                | "while" "(" add ")" expr
 */
 public AstNode Expr() {
   if (IsMatch("print")) {
     Match("print");
     AstNode value = Term();
     return new AstNode(AstNodeType.PRINT, value);
   }
   else if (IsMatch("input")) {
     Match("input");
     AstNode identifier = IDENT();
     return new AstNode(AstNodeType.INPUT, identifier);
   }
   else if (IsMatch("if"))
   {
       Match("if");
       Match("(");
       AstNode ifNode = new AstNode(AstNodeType.IF, Term());
       Match(")");
       Match("then");
       ifNode.AddChild(Expr());
       if (IsMatch("else"))
       {
           Match("else");
           ifNode.AddChild(Expr());
       }
       return ifNode;
   }
   else if (IsMatch("while"))
   {
       Match("while");
       Match("(");
       AstNode whileNode = new AstNode(AstNodeType.WHILE, Term());
       Match(")");
       whileNode.AddChild(Expr());
       return whileNode;
   }
   else
   {
       AstNode identifier = IDENT();
       Match("=");
       AstNode value = Term();
       return new AstNode(AstNodeType.ASSIGN, identifier, value);
   }
 }
开发者ID:chursin-andrey,项目名称:CCompiler,代码行数:49,代码来源:MathLangParser.cs

示例3: AddExplicitInterface

			void AddExplicitInterface(AstNode parent, MemberName memberName)
			{
				if (memberName == null || memberName.ExplicitInterface == null)
					return;
				
				parent.AddChild(ConvertToType(memberName.ExplicitInterface), EntityDeclaration.PrivateImplementationTypeRole);
				var privateImplTypeLoc = LocationsBag.GetLocations(memberName.ExplicitInterface);
				if (privateImplTypeLoc != null)
					parent.AddChild(new CSharpTokenNode(Convert(privateImplTypeLoc [0]), Roles.Dot), Roles.Dot);
			}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:10,代码来源:CSharpParser.cs

示例4: AddTypeParameters

			void AddTypeParameters(AstNode parent, MemberName memberName)
			{
				if (memberName == null || memberName.TypeParameters == null)
					return;
				var chevronLocs = LocationsBag.GetLocations(memberName.TypeParameters);
				if (chevronLocs != null)
					parent.AddChild(new CSharpTokenNode(Convert(chevronLocs [chevronLocs.Count - 2]), Roles.LChevron), Roles.LChevron);
				for (int i = 0; i < memberName.TypeParameters.Count; i++) {
					if (chevronLocs != null && i > 0 && i - 1 < chevronLocs.Count)
						parent.AddChild(new CSharpTokenNode(Convert(chevronLocs [i - 1]), Roles.Comma), Roles.Comma);
					var arg = memberName.TypeParameters [i];
					if (arg == null)
						continue;
					var tp = new TypeParameterDeclaration();
					
					List<Location> varianceLocation;
					switch (arg.Variance) {
						case Variance.Contravariant:
							tp.Variance = VarianceModifier.Contravariant;
							varianceLocation = LocationsBag.GetLocations(arg);
							if (varianceLocation != null)
								tp.AddChild(new CSharpTokenNode(Convert(varianceLocation [0]), TypeParameterDeclaration.InVarianceKeywordRole), TypeParameterDeclaration.InVarianceKeywordRole);
							break;
						case Variance.Covariant:
							tp.Variance = VarianceModifier.Covariant;
							varianceLocation = LocationsBag.GetLocations(arg);
							if (varianceLocation != null)
								tp.AddChild(new CSharpTokenNode(Convert(varianceLocation [0]), TypeParameterDeclaration.OutVarianceKeywordRole), TypeParameterDeclaration.OutVarianceKeywordRole);
							break;
						default:
							tp.Variance = VarianceModifier.Invariant;
							break;
							
					}
					
					AddAttributeSection(tp, arg.OptAttributes);

					switch (arg.Variance) {
						case Variance.Covariant:
							tp.Variance = VarianceModifier.Covariant;
							break;
						case Variance.Contravariant:
							tp.Variance = VarianceModifier.Contravariant;
							break;
					}
					tp.AddChild(Identifier.Create(arg.Name, Convert(arg.Location)), Roles.Identifier);
					parent.AddChild(tp, Roles.TypeParameter);
				}
				if (chevronLocs != null)
					parent.AddChild(new CSharpTokenNode(Convert(chevronLocs [chevronLocs.Count - 1]), Roles.RChevron), Roles.RChevron);
			}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:51,代码来源:CSharpParser.cs

示例5: AddTypeArguments

			void AddTypeArguments (AstNode parent, Mono.CSharp.TypeArguments typeArguments)
			{
				if (typeArguments == null || typeArguments.IsEmpty)
					return;
				var chevronLocs = LocationsBag.GetLocations (typeArguments);
				if (chevronLocs != null)
					parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 2]), 1), InvocationExpression.Roles.LChevron);
				
				for (int i = 0; i < typeArguments.Count; i++) {
					var arg = typeArguments.Args[i];
					if (arg == null)
						continue;
					parent.AddChild (ConvertToType (arg), InvocationExpression.Roles.TypeArgument);
					if (chevronLocs != null && i < chevronLocs.Count - 2)
						parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[i]), 1), InvocationExpression.Roles.Comma);
				}
				
				if (chevronLocs != null)
					parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 1]), 1), InvocationExpression.Roles.RChevron);
			}
开发者ID:N3X15,项目名称:ILSpy,代码行数:20,代码来源:CSharpParser.cs

示例6: AddConstraints

            void AddConstraints(AstNode parent, TypeParameters d)
            {
                if (d == null)
                    return;
                for (int i = d.Count - 1; i >= 0; i--) {
                    var typeParameter = d [i];
                    if (typeParameter == null)
                        continue;
                    var c = typeParameter.Constraints;
                    if (c == null)
                        continue;
                    var location = LocationsBag.GetLocations (c);
                    var constraint = new Constraint ();
                    constraint.AddChild (new CSharpTokenNode (Convert (c.Location), Roles.WhereKeyword), Roles.WhereKeyword);
                    constraint.AddChild (new SimpleType (Identifier.Create (c.TypeParameter.Value, Convert (c.TypeParameter.Location))), Roles.ConstraintTypeParameter);
                    if (location != null)
                        constraint.AddChild (new CSharpTokenNode (Convert (location [0]), Roles.Colon), Roles.Colon);
                    var commaLocs = LocationsBag.GetLocations (c.ConstraintExpressions);
                    int curComma = 0;
                    if (c.ConstraintExpressions != null) {
                        foreach (var expr in c.ConstraintExpressions) {
                            constraint.AddChild (ConvertToType (expr), Roles.BaseType);
                            if (commaLocs != null && curComma < commaLocs.Count)
                                constraint.AddChild (new CSharpTokenNode (Convert (commaLocs [curComma++]), Roles.Comma), Roles.Comma);
                        }
                    }

                    parent.AddChild (constraint, Roles.Constraint);
                }
            }
开发者ID:kaagati,项目名称:NRefactory,代码行数:30,代码来源:CSharpParser.cs

示例7: AddTypeArguments

			void AddTypeArguments (AstNode parent, LocationsBag.MemberLocations location, Mono.CSharp.TypeArguments typeArguments)
			{
				if (typeArguments == null || typeArguments.IsEmpty)
					return;
				for (int i = 0; i < typeArguments.Count; i++) {
					if (location != null && i > 0 && i - 1 < location.Count)
						parent.AddChild (new CSharpTokenNode (Convert (location[i - 1]), 1), InvocationExpression.Roles.Comma);
					var arg = typeArguments.Args[i];
					if (arg == null)
						continue;
					parent.AddChild ((AstNode)arg.Accept (this), InvocationExpression.Roles.TypeParameter);
				}
			}
开发者ID:tech-uday-mca,项目名称:monodevelop,代码行数:13,代码来源:CSharpParser.cs

示例8: AddAttributeSection

			public void AddAttributeSection (AstNode parent, Attributable a)
			{
				if (a.OptAttributes == null)
					return;
				foreach (var attr in a.OptAttributes.Sections) {
					parent.AddChild (ConvertAttributeSection (attr), AttributedNode.AttributeRole);
				}
			}
开发者ID:aleksandersumowski,项目名称:monodevelop,代码行数:8,代码来源:CSharpParser.cs

示例9: AddTypeParameters

			void AddTypeParameters (AstNode parent, List<Location> location, Mono.CSharp.TypeArguments typeArguments)
			{
				if (typeArguments == null || typeArguments.IsEmpty)
					return;
				for (int i = 0; i < typeArguments.Count; i++) {
					if (location != null && i > 0 && i - 1 < location.Count)
						parent.AddChild (new CSharpTokenNode (Convert (location[i - 1]), 1), InvocationExpression.Roles.Comma);
					var arg = (TypeParameterName)typeArguments.Args[i];
					if (arg == null)
						continue;
					TypeParameterDeclaration tp = new TypeParameterDeclaration();
					// TODO: attributes
					if (arg.Variance != Variance.None)
						throw new NotImplementedException(); // TODO: variance
					tp.AddChild (new Identifier (arg.Name, Convert (arg.Location)), InvocationExpression.Roles.Identifier);
					parent.AddChild (tp, InvocationExpression.Roles.TypeParameter);
				}
			}
开发者ID:madkat,项目名称:NRefactory,代码行数:18,代码来源:CSharpParser.cs

示例10: AddParameter

			void AddParameter (AstNode parent, Mono.CSharp.AParametersCollection parameters)
			{
				if (parameters == null)
					return;
				var paramLocation = LocationsBag.GetLocations (parameters);
			
				for (int i = 0; i < parameters.Count; i++) {
					if (paramLocation != null && i > 0 && i - 1 < paramLocation.Count) 
						parent.AddChild (new CSharpTokenNode (Convert (paramLocation[i - 1]), 1), ParameterDeclaration.Roles.Comma);
					var p = (Parameter)parameters.FixedParameters[i];
					var location = LocationsBag.GetLocations (p);
					
					ParameterDeclaration parameterDeclarationExpression = new ParameterDeclaration ();
					switch (p.ModFlags) {
					case Parameter.Modifier.OUT:
						parameterDeclarationExpression.ParameterModifier = ParameterModifier.Out;
						if (location != null)
							parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location[0]), "out".Length), ParameterDeclaration.Roles.Keyword);
						break;
					case Parameter.Modifier.REF:
						parameterDeclarationExpression.ParameterModifier = ParameterModifier.Ref;
						if (location != null)
							parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location[0]), "ref".Length), ParameterDeclaration.Roles.Keyword);
						break;
					case Parameter.Modifier.PARAMS:
						parameterDeclarationExpression.ParameterModifier = ParameterModifier.Params;
						if (location != null)
							parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location[0]), "params".Length), ParameterDeclaration.Roles.Keyword);
						break;
					case Parameter.Modifier.This:
						parameterDeclarationExpression.ParameterModifier = ParameterModifier.This;
						if (location != null)
							parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location[0]), "this".Length), ParameterDeclaration.Roles.Keyword);
						break;
					}
					if (p.TypeExpression != null) // lambdas may have no types (a, b) => ...
						parameterDeclarationExpression.AddChild ((AstNode)p.TypeExpression.Accept (this), ParameterDeclaration.Roles.ReturnType);
					parameterDeclarationExpression.AddChild (new Identifier (p.Name, Convert (p.Location)), ParameterDeclaration.Roles.Identifier);
					if (p.HasDefaultValue) {
						if (location != null)
							parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location[1]), 1), ParameterDeclaration.Roles.Assign);
						parameterDeclarationExpression.AddChild ((AstNode)p.DefaultValue.Accept (this), ParameterDeclaration.Roles.Expression);
					}
					parent.AddChild (parameterDeclarationExpression, InvocationExpression.Roles.Parameter);
				}
			}
开发者ID:tech-uday-mca,项目名称:monodevelop,代码行数:46,代码来源:CSharpParser.cs

示例11: AddConstraints

			void AddConstraints (AstNode parent, DeclSpace d)
			{
				if (d == null || d.Constraints == null)
					return;
				for (int i = 0; i < d.PlainConstraints.Count; i++) {
					Constraints c = d.PlainConstraints [i];
					var location = LocationsBag.GetLocations (c);
					var constraint = new Constraint ();
					if (location != null)
						constraint.AddChild (new CSharpTokenNode (Convert (location [0]), "where".Length), InvocationExpression.Roles.Keyword);
					constraint.AddChild (new Identifier (c.TypeParameter.Value, Convert (c.TypeParameter.Location)), InvocationExpression.Roles.Identifier);
					if (location != null && location.Count > 1)
						constraint.AddChild (new CSharpTokenNode (Convert (location [1]), 1), Constraint.ColonRole);
					foreach (var expr in c.ConstraintExpressions)
						constraint.AddChild (ConvertToType (expr), Constraint.BaseTypeRole);
					parent.AddChild (constraint, AstNode.Roles.Constraint);
				}
			}
开发者ID:rmattuschka,项目名称:ILSpy,代码行数:18,代码来源:CSharpParser.cs

示例12: Run

			public void Run (AstNode compilationUnit)
			{
				var ns = compilationUnit.Children.OfType<NamespaceDeclaration> ();

				foreach (var d in ns.SelectMany (x => x.Members)) {
					d.Remove ();
					compilationUnit.AddChild (d, SyntaxTree.MemberRole);
				}

				foreach (var n in ns) {
					n.Remove ();
				}

			}
开发者ID:RReverser,项目名称:Netjs,代码行数:14,代码来源:CsToTs.cs

示例13: Program

 /*  program ->   (  expr  )*
 */
 public AstNode Program() {
   AstNode programNode = new AstNode(AstNodeType.PROGRAM);
   while (!End)
     programNode.AddChild(Expr());
   return programNode;
 }
开发者ID:chursin-andrey,项目名称:CCompiler,代码行数:8,代码来源:MathLangParser.cs

示例14: AddTypeArguments

			void AddTypeArguments (AstNode parent, List<Location> location, Mono.CSharp.TypeArguments typeArguments)
			{
				if (typeArguments == null || typeArguments.IsEmpty)
					return;
				for (int i = 0; i < typeArguments.Count; i++) {
					if (location != null && i > 0 && i - 1 < location.Count)
						parent.AddChild (new CSharpTokenNode (Convert (location[i - 1]), 1), InvocationExpression.Roles.Comma);
					var arg = typeArguments.Args[i];
					if (arg == null)
						continue;
					parent.AddChild (ConvertToType (arg), InvocationExpression.Roles.TypeArgument);
				}
			}
开发者ID:aleksandersumowski,项目名称:monodevelop,代码行数:13,代码来源:CSharpParser.cs

示例15: AddConstraints

			void AddConstraints (AstNode parent, DeclSpace d)
			{
				if (d == null || d.Constraints == null)
					return;
				for (int i = 0; i < d.Constraints.Count; i++) {
					Constraints c = d.Constraints[i];
					var location = LocationsBag.GetLocations (c);
//					var constraint = new Constraint ();
					parent.AddChild (new CSharpTokenNode (Convert (location[0]), "where".Length), InvocationExpression.Roles.Keyword);
					parent.AddChild (new Identifier (c.TypeParameter.Value, Convert (c.TypeParameter.Location)), InvocationExpression.Roles.Identifier);
					parent.AddChild (new CSharpTokenNode (Convert (location[1]), 1), InvocationExpression.Roles.Colon);
					foreach (var expr in c.ConstraintExpressions)
						parent.AddChild ((AstNode)expr.Accept (this), InvocationExpression.Roles.TypeParameter);
				}
			}
开发者ID:tech-uday-mca,项目名称:monodevelop,代码行数:15,代码来源:CSharpParser.cs


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