void AddArguments (AbstractCSharpNode parent, object location, Mono.CSharp.Arguments args) { if (args == null) return; var commaLocations = LocationsBag.GetLocations (args); for (int i = 0; i < args.Count; i++) { parent.AddChild ((INode)args[i].Expr.Accept (this), InvocationExpression.Roles.Argument); if (commaLocations != null && i > 0) { int idx = commaLocations.Count - i; if (idx >= 0) parent.AddChild (new CSharpTokenNode (Convert (commaLocations[idx]), 1), InvocationExpression.Roles.Comma); } } if (commaLocations != null && commaLocations.Count > args.Count) parent.AddChild (new CSharpTokenNode (Convert (commaLocations[0]), 1), InvocationExpression.Roles.Comma); }
void AddConstraints (AbstractCSharpNode 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 ((INode)expr.Accept (this), InvocationExpression.Roles.TypeArgument); } }
void AddTypeArguments (AbstractCSharpNode parent, LocationsBag.MemberLocations location, Mono.CSharp.TypeArguments typeArguments) { if (typeArguments == null) 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); parent.AddChild ((INode)typeArguments.Args[i].Accept (this), InvocationExpression.Roles.TypeArgument); } }
void AddParameter (AbstractCSharpNode parent, Mono.CSharp.AParametersCollection parameters) { // if (parameters == null || !parameters.HasParams) // return; // var paramLocation = LocationsBag.GetLocations (parameters); // // for (int i = 0; i < parameters.Count; i++) { // if (paramLocation.LocationList != null && i > 0 && i - 1 < paramLocation.LocationList.Count) // parent.AddChild (new CSharpTokenNode (Convert (paramLocation.LocationList[i - 1]), 1), ParameterDeclarationExpression.Roles.Comma); // var p = parameters.FixedParameters[i]; // var location = LocationsBag.GetLocations (p); // // ParameterDeclarationExpression parameterDeclarationExpression = new ParameterDeclarationExpression (); // switch (p.ModFlags) { // case Parameter.Modifier.OUT: // parameterDeclarationExpression.ParameterModifier = ParameterModifier.Out; // parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location.LocationList[0]), "out".Length), ParameterDeclarationExpression.Roles.Keyword); // break; // case Parameter.Modifier.REF: // parameterDeclarationExpression.ParameterModifier = ParameterModifier.Ref; // parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location.LocationList[0]), "ref".Length), ParameterDeclarationExpression.Roles.Keyword); // break; // case Parameter.Modifier.PARAMS: // parameterDeclarationExpression.ParameterModifier = ParameterModifier.Params; // parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location.LocationList[0]), "params".Length), ParameterDeclarationExpression.Roles.Keyword); // break; // case Parameter.Modifier.This: // parameterDeclarationExpression.ParameterModifier = ParameterModifier.This; // parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location.LocationList[0]), "this".Length), ParameterDeclarationExpression.Roles.Keyword); // break; // } // //// TODO: type spec //// parameterDeclarationExpression.AddChild ((INode)parameters.Types[i].Accept (this), ParameterDeclarationExpression.Roles.ReturnType); //// TODO: Identifier location. // parameterDeclarationExpression.AddChild (new Identifier (p.Name, DomLocation.Empty), ParameterDeclarationExpression.Roles.Identifier); //// parameterDeclarationExpression.AddChild (new Identifier (p.Name, Convert (p.)), ParameterDeclarationExpression.Roles.Identifier); // if (p.HasDefaultValue) { // parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ParameterDeclarationExpression.Roles.Assign); // parameterDeclarationExpression.AddChild ((INode)p.DefaultValue.Accept (this), ParameterDeclarationExpression.Roles.Expression); // } // parent.AddChild (parameterDeclarationExpression, InvocationExpression.Roles.Argument); // } }
void AddArguments (AbstractCSharpNode parent, object location, Mono.CSharp.Arguments args) { if (args == null) return; var commaLocations = LocationsBag.GetLocations (args); for (int i = 0; i < args.Count; i++) { Argument arg = args[i]; if (arg.ArgType == Argument.AType.Out || arg.ArgType == Argument.AType.Ref) { DirectionExpression direction = new DirectionExpression (); direction.FieldDirection = arg.ArgType == Argument.AType.Out ? FieldDirection.Out : FieldDirection.Ref; var argLocation = LocationsBag.GetLocations (arg); if (location != null) direction.AddChild (new CSharpTokenNode (Convert (argLocation[0]), "123".Length), InvocationExpression.Roles.Keyword); direction.AddChild ((INode)arg.Expr.Accept (this), InvocationExpression.Roles.Expression); parent.AddChild (direction, InvocationExpression.Roles.Argument); } else { parent.AddChild ((INode)arg.Expr.Accept (this), InvocationExpression.Roles.Argument); } if (commaLocations != null && i > 0) { int idx = commaLocations.Count - i; if (idx >= 0) parent.AddChild (new CSharpTokenNode (Convert (commaLocations[idx]), 1), InvocationExpression.Roles.Comma); } } if (commaLocations != null && commaLocations.Count > args.Count) parent.AddChild (new CSharpTokenNode (Convert (commaLocations[0]), 1), InvocationExpression.Roles.Comma); }
void AddParameter (AbstractCSharpNode 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), ParameterDeclarationExpression.Roles.Comma); var p = (Parameter)parameters.FixedParameters[i]; var location = LocationsBag.GetLocations (p); ParameterDeclarationExpression parameterDeclarationExpression = new ParameterDeclarationExpression (); switch (p.ModFlags) { case Parameter.Modifier.OUT: parameterDeclarationExpression.ParameterModifier = ParameterModifier.Out; if (location != null) parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location[0]), "out".Length), ParameterDeclarationExpression.Roles.Keyword); break; case Parameter.Modifier.REF: parameterDeclarationExpression.ParameterModifier = ParameterModifier.Ref; if (location != null) parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location[0]), "ref".Length), ParameterDeclarationExpression.Roles.Keyword); break; case Parameter.Modifier.PARAMS: parameterDeclarationExpression.ParameterModifier = ParameterModifier.Params; if (location != null) parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location[0]), "params".Length), ParameterDeclarationExpression.Roles.Keyword); break; case Parameter.Modifier.This: parameterDeclarationExpression.ParameterModifier = ParameterModifier.This; if (location != null) parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location[0]), "this".Length), ParameterDeclarationExpression.Roles.Keyword); break; } if (p.TypeExpression != null) // lambdas may have no types (a, b) => ... parameterDeclarationExpression.AddChild ((INode)p.TypeExpression.Accept (this), ParameterDeclarationExpression.Roles.ReturnType); parameterDeclarationExpression.AddChild (new Identifier (p.Name, Convert (p.Location)), ParameterDeclarationExpression.Roles.Identifier); if (p.HasDefaultValue) { if (location != null) parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location[1]), 1), ParameterDeclarationExpression.Roles.Assign); parameterDeclarationExpression.AddChild ((INode)p.DefaultValue.Accept (this), ParameterDeclarationExpression.Roles.Expression); } parent.AddChild (parameterDeclarationExpression, InvocationExpression.Roles.Argument); } }