本文整理汇总了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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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 ();
}
}
示例13: Program
/* program -> ( expr )*
*/
public AstNode Program() {
AstNode programNode = new AstNode(AstNodeType.PROGRAM);
while (!End)
programNode.AddChild(Expr());
return programNode;
}
示例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);
}
}
示例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);
}
}