Exemplo n.º 1
0
		public virtual void VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression)
		{
			DebugExpression(namedArgumentExpression);
			StartNode(namedArgumentExpression);
			WriteIdentifier(namedArgumentExpression.NameToken);
			WriteToken(Roles.Colon, BoxedTextColor.Punctuation);
			Space();
			namedArgumentExpression.Expression.AcceptVisitor(this);
			EndNode(namedArgumentExpression);
		}
Exemplo n.º 2
0
	void Argument(
#line  2379 "VBNET.ATG" 
out Expression argumentexpr) {

#line  2381 "VBNET.ATG" 
		Expression expr;
		argumentexpr = null;
		string name;
		
		if (
#line  2385 "VBNET.ATG" 
IsNamedAssign()) {
			Identifier();

#line  2385 "VBNET.ATG" 
			name = t.val;  
			Expect(11);
			Expect(10);
			Expr(
#line  2385 "VBNET.ATG" 
out expr);

#line  2387 "VBNET.ATG" 
			argumentexpr = new NamedArgumentExpression(name, expr);
			
		} else if (StartOf(29)) {
			Expr(
#line  2390 "VBNET.ATG" 
out argumentexpr);
		} else SynErr(267);
	}
Exemplo n.º 3
0
        private void BuildOperatorArgumentsList(IList <Expression> arguments, IMethod method)
        {
            if (method != null)
            {
                var parameters = method.Parameters;

                Expression[] result = new Expression[parameters.Count];
                string[]     names  = new string[result.Length];

                int i = 0;
                foreach (var arg in arguments)
                {
                    if (arg is NamedArgumentExpression)
                    {
                        NamedArgumentExpression namedArg = (NamedArgumentExpression)arg;
                        var namedParam = parameters.First(p => p.Name == namedArg.Name);
                        var index      = parameters.IndexOf(namedParam);

                        result[index] = namedArg.Expression;
                        names[index]  = namedArg.Name;
                    }
                    else
                    {
                        if (i >= result.Length)
                        {
                            var list = result.ToList();
                            list.AddRange(new Expression[arguments.Count - i]);

                            var strList = names.ToList();
                            strList.AddRange(new string[arguments.Count - i]);

                            result = list.ToArray();
                            names  = strList.ToArray();
                        }

                        result[i] = arg;
                        names[i]  = parameters[i].Name;
                    }

                    i++;
                }

                for (i = 0; i < result.Length; i++)
                {
                    if (result[i] == null)
                    {
                        var p = parameters[i];

                        if (p.Type.Kind == TypeKind.Enum)
                        {
                            result[i] = new PrimitiveExpression(Helpers.GetEnumValue(this.Emitter, p.Type, p.ConstantValue));
                        }
                        else
                        {
                            result[i] = new PrimitiveExpression(p.ConstantValue);
                        }
                        names[i] = parameters[i].Name;
                    }
                }

                this.ArgumentsExpressions = result;
                this.ArgumentsNames       = names;
                this.NamedExpressions     = this.CreateNamedExpressions(names, result);
            }
            else
            {
                this.ArgumentsExpressions = arguments.ToArray();
            }
        }
Exemplo n.º 4
0
 public virtual object VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, object data)
 {
     throw new global::System.NotImplementedException("NamedArgumentExpression");
 }
		public virtual void VisitNamedArgumentExpression (NamedArgumentExpression namedArgumentExpression)
		{
			VisitChildren (namedArgumentExpression);
		}
Exemplo n.º 6
0
        protected virtual void WriteObjectInitializer(IEnumerable <Expression> expressions, bool changeCase, TypeDefinition type)
        {
            bool          needComma = false;
            List <string> names     = new List <string>();

            if (expressions != null)
            {
                foreach (Expression item in expressions)
                {
                    NamedExpression         namedExression          = item as NamedExpression;
                    NamedArgumentExpression namedArgumentExpression = item as NamedArgumentExpression;

                    if (needComma)
                    {
                        this.WriteComma();
                    }

                    needComma = true;
                    string name = namedExression != null ? namedExression.Name : namedArgumentExpression.Name;

                    if (changeCase)
                    {
                        name = Object.Net.Utilities.StringUtils.ToLowerCamelCase(name);
                    }

                    Expression expression = namedExression != null ? namedExression.Expression : namedArgumentExpression.Expression;

                    this.Write(name, ": ");
                    expression.AcceptVisitor(this.Emitter);

                    names.Add(name);
                }
            }

            if (this.Emitter.Validator.IsObjectLiteral(type))
            {
                var typeName = Helpers.ReplaceSpecialChars(type.FullName);
                var tinfo    = this.Emitter.Types.FirstOrDefault(t => t.GenericFullName == typeName);
                var members  = tinfo.InstanceConfig.Fields.Concat(tinfo.InstanceConfig.Properties);

                if (members.Any())
                {
                    foreach (var member in members)
                    {
                        var name = member.GetName(this.Emitter);

                        if (changeCase)
                        {
                            name = Object.Net.Utilities.StringUtils.ToLowerCamelCase(name);
                        }

                        if (names.Contains(name))
                        {
                            continue;
                        }

                        if (needComma)
                        {
                            this.WriteComma();
                        }

                        needComma = true;

                        this.Write(name, ": ");

                        var primitiveExpr = member.Initializer as PrimitiveExpression;

                        if (primitiveExpr != null && primitiveExpr.Value is AstType)
                        {
                            this.Write("new " + Helpers.TranslateTypeReference((AstType)primitiveExpr.Value, this.Emitter) + "()");
                        }
                        else
                        {
                            member.Initializer.AcceptVisitor(this.Emitter);
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
 public virtual Node VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression)
 {
     throw new System.NotImplementedException();
 }
		static void AddArgument(InvocationExpression newNode, IParameter parameterToAdd, bool isNextInSequence)
		{
			Expression defaultValue;
			if (parameterToAdd.ConstantValue == null) {
				defaultValue = new NullReferenceExpression();
			}
			else {
				defaultValue = new PrimitiveExpression(parameterToAdd.ConstantValue);
			}
			Expression newArgument;
			if (newNode.Arguments.Any(argument => argument is NamedExpression) || !isNextInSequence) {
				newArgument = new NamedArgumentExpression(parameterToAdd.Name, defaultValue);
			}
			else {
				newArgument = defaultValue;
			}
			newNode.Arguments.Add(newArgument);
		}
		public sealed override object VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, object data) {
			BeginVisit(namedArgumentExpression);
			object result = TrackedVisitNamedArgumentExpression(namedArgumentExpression, data);
			EndVisit(namedArgumentExpression);
			return result;
		}
Exemplo n.º 10
0
 public override void VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression)
 {
     namedArgumentExpression.Expression.AcceptVisitor(this);
 }
Exemplo n.º 11
0
		public virtual object TrackedVisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, object data) {
			return base.VisitNamedArgumentExpression(namedArgumentExpression, data);
		}
 public override void VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression)
 {
     HandleExpressionNode(namedArgumentExpression);
 }
Exemplo n.º 13
0
        protected virtual void WriteObjectInitializer(IEnumerable <Expression> expressions, bool preserveMemberCase, TypeDefinition type, InvocationResolveResult rr)
        {
            bool          needComma = false;
            List <string> names     = new List <string>();

            if (rr != null && this.ObjectCreateExpression.Arguments.Count > 0)
            {
                var args      = this.ObjectCreateExpression.Arguments.ToList();
                var arrIsOpen = false;
                for (int i = 0; i < args.Count; i++)
                {
                    Expression expression = args[i];
                    var        p          = rr.Member.Parameters[i < rr.Member.Parameters.Count ? i : (rr.Member.Parameters.Count - 1)];
                    var        name       = p.Name;

                    if (needComma)
                    {
                        this.WriteComma();
                    }

                    needComma = true;

                    if (p.IsParams && !arrIsOpen)
                    {
                        arrIsOpen = true;
                        this.Write("[");
                    }

                    this.Write(name, ": ");
                    expression.AcceptVisitor(this.Emitter);

                    names.Add(name);
                }

                if (arrIsOpen)
                {
                    this.Write("]");
                }
            }

            if (expressions != null)
            {
                foreach (Expression item in expressions)
                {
                    NamedExpression         namedExression          = item as NamedExpression;
                    NamedArgumentExpression namedArgumentExpression = item as NamedArgumentExpression;
                    string name = namedExression != null ? namedExression.Name : namedArgumentExpression.Name;

                    if (!preserveMemberCase)
                    {
                        name = Object.Net.Utilities.StringUtils.ToLowerCamelCase(name);
                    }

                    var itemrr = this.Emitter.Resolver.ResolveNode(item, this.Emitter) as MemberResolveResult;
                    if (itemrr != null)
                    {
                        var oc = OverloadsCollection.Create(this.Emitter, itemrr.Member);
                        oc.CancelChangeCase = this.Emitter.IsNativeMember(itemrr.Member.FullName) ? false : preserveMemberCase;
                        name = oc.GetOverloadName();
                    }

                    if (needComma)
                    {
                        this.WriteComma();
                    }

                    needComma = true;

                    Expression expression = namedExression != null ? namedExression.Expression : namedArgumentExpression.Expression;

                    this.Write(name, ": ");
                    expression.AcceptVisitor(this.Emitter);

                    names.Add(name);
                }
            }

            if (this.Emitter.Validator.IsObjectLiteral(type))
            {
                var key   = BridgeTypes.GetTypeDefinitionKey(type);
                var tinfo = this.Emitter.Types.FirstOrDefault(t => t.Key == key);

                if (tinfo == null)
                {
                    return;
                }
                var itype = tinfo.Type as ITypeDefinition;

                var mode = 0;
                if (rr != null)
                {
                    if (rr.Member.Parameters.Count == 1 &&
                        rr.Member.Parameters.First().Type.FullName == "Bridge.DefaultValueMode")
                    {
                        var arg = rr.Arguments.FirstOrDefault();
                        if (arg != null && arg.ConstantValue != null)
                        {
                            mode = (int)arg.ConstantValue;
                        }
                    }
                    else if (itype != null)
                    {
                        var attr = this.Emitter.Validator.GetAttribute(itype.Attributes, Translator.Bridge_ASSEMBLY + ".ObjectLiteralAttribute");
                        if (attr.PositionalArguments.Count > 0)
                        {
                            var value = attr.PositionalArguments.First().ConstantValue;

                            if (value != null && value is int)
                            {
                                mode = (int)value;
                            }
                        }
                    }
                }

                if (mode != 0)
                {
                    var members = tinfo.InstanceConfig.Fields.Concat(tinfo.InstanceConfig.Properties);

                    if (members.Any())
                    {
                        foreach (var member in members)
                        {
                            if (mode == 1 && (member.VarInitializer == null || member.VarInitializer.Initializer.IsNull))
                            {
                                continue;
                            }

                            var name = member.GetName(this.Emitter);

                            if (!preserveMemberCase)
                            {
                                name = Object.Net.Utilities.StringUtils.ToLowerCamelCase(name);
                            }

                            if (names.Contains(name))
                            {
                                continue;
                            }

                            if (needComma)
                            {
                                this.WriteComma();
                            }

                            needComma = true;

                            this.Write(name, ": ");

                            var primitiveExpr = member.Initializer as PrimitiveExpression;

                            if (primitiveExpr != null && primitiveExpr.Value is AstType)
                            {
                                this.Write(Inspector.GetStructDefaultValue((AstType)primitiveExpr.Value, this.Emitter));
                            }
                            else
                            {
                                member.Initializer.AcceptVisitor(this.Emitter);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 14
0
			public override object Visit (NewAnonymousType newAnonymousType)
			{
				var result = new AnonymousTypeCreateExpression ();
				foreach (var par in newAnonymousType.Parameters) {
					var location = LocationsBag.GetLocations (par);

					if (location == null) {
						result.AddChild ((Expression)par.Expr.Accept (this), AnonymousTypeCreateExpression.Roles.Expression);
					} else {
						var namedArgument = new NamedArgumentExpression ();
						namedArgument.AddChild (new Identifier (par.Name, Convert (par.Location)), AnonymousTypeCreateExpression.Roles.Identifier);
						namedArgument.AddChild (new CSharpTokenNode (Convert (location [0]), 1), AnonymousTypeCreateExpression.Roles.Assign);
						namedArgument.AddChild ((Expression)par.Expr.Accept (this), AnonymousTypeCreateExpression.Roles.Expression);
						result.AddChild (namedArgument, AnonymousTypeCreateExpression.Roles.Expression);
					}
				}
				return result;
			}
Exemplo n.º 15
0
		public virtual object VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, object data) {
			Debug.Assert((namedArgumentExpression != null));
			Debug.Assert((namedArgumentExpression.Expression != null));
			nodeStack.Push(namedArgumentExpression.Expression);
			namedArgumentExpression.Expression.AcceptVisitor(this, data);
			namedArgumentExpression.Expression = ((Expression)(nodeStack.Pop()));
			return null;
		}
        public override void VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression)
        {
            ForceSpacesAfter(namedArgumentExpression.ColonToken, policy.SpaceInNamedArgumentAfterDoubleColon);

            base.VisitNamedArgumentExpression(namedArgumentExpression);
        }
Exemplo n.º 17
0
 public RedILNode VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, State data)
 {
     //TODO: Check if needed
     throw new System.NotImplementedException();
 }
Exemplo n.º 18
0
			Expression ConvertArgument(Argument arg)
			{
				var na = arg as NamedArgument;
				if (na != null) {
					var newArg = new NamedArgumentExpression();
					newArg.AddChild(Identifier.Create(na.Name, Convert(na.Location)), Roles.Identifier);
					
					var loc = LocationsBag.GetLocations(na);
					if (loc != null)
						newArg.AddChild(new CSharpTokenNode(Convert(loc [0]), Roles.Colon), Roles.Colon);
					
					if (arg.ArgType == Argument.AType.Out || arg.ArgType == Argument.AType.Ref) {
						var direction = new DirectionExpression();
						direction.FieldDirection = arg.ArgType == Argument.AType.Out ? FieldDirection.Out : FieldDirection.Ref;
						var argLocation = LocationsBag.GetLocations(arg);
						if (argLocation != null) {
							var r = arg.ArgType == Argument.AType.Out ? DirectionExpression.OutKeywordRole : DirectionExpression.RefKeywordRole;
							direction.AddChild(new CSharpTokenNode(Convert(argLocation [0]), r), r);
						}
						direction.AddChild((Expression)arg.Expr.Accept(this), Roles.Expression);
						newArg.AddChild(direction, Roles.Expression);
					} else {
						newArg.AddChild(na.Expr != null ? (Expression)na.Expr.Accept(this) : new ErrorExpression("Named argument expression parse error"), Roles.Expression);
					}
					return newArg;
				}
				
				if (arg.ArgType == Argument.AType.Out || arg.ArgType == Argument.AType.Ref) {
					var direction = new DirectionExpression();
					direction.FieldDirection = arg.ArgType == Argument.AType.Out ? FieldDirection.Out : FieldDirection.Ref;
					var argLocation = LocationsBag.GetLocations(arg);
					if (argLocation != null) {
						var r = arg.ArgType == Argument.AType.Out ? DirectionExpression.OutKeywordRole : DirectionExpression.RefKeywordRole;
						direction.AddChild(new CSharpTokenNode(Convert(argLocation [0]), r), r);
					}
					direction.AddChild((Expression)arg.Expr.Accept(this), Roles.Expression);
					return direction;
				}
				
				return (Expression)arg.Expr.Accept(this);
			}
		public virtual object VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, object data) {
			throw new global::System.NotImplementedException("NamedArgumentExpression");
		}
Exemplo n.º 20
0
 public JsNode VisitNamedArgumentExpression(NamedArgumentExpression node)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 21
0
        public override AstNode VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, ICecilArgumentsResolver argumentsResolver)
        {
            namedArgumentExpression.Expression.AcceptVisitor(this, argumentsResolver);

            return(namedArgumentExpression);
        }
Exemplo n.º 22
0
        private void BuildArgumentsList(IList <Expression> arguments)
        {
            Expression paramsArg     = null;
            string     paramArgName  = null;
            var        resolveResult = this.ResolveResult;

            if (resolveResult != null)
            {
                var parameters       = resolveResult.Member.Parameters;
                var resolvedMethod   = resolveResult.Member as IMethod;
                var invocationResult = resolveResult as CSharpInvocationResolveResult;
                int shift            = 0;

                if (resolvedMethod != null && invocationResult != null &&
                    resolvedMethod.IsExtensionMethod && invocationResult.IsExtensionMethodInvocation)
                {
                    shift                  = 1;
                    this.ThisName          = resolvedMethod.Parameters[0].Name;
                    this.IsExtensionMethod = true;
                }

                Expression[] result = new Expression[parameters.Count - shift];
                string[]     names  = new string[result.Length];
                bool         named  = false;
                int          i      = 0;

                if (resolvedMethod != null)
                {
                    var inlineStr = this.Emitter.GetInline(resolvedMethod);
                    named = !string.IsNullOrEmpty(inlineStr);
                }

                foreach (var arg in arguments)
                {
                    if (arg is NamedArgumentExpression)
                    {
                        NamedArgumentExpression namedArg = (NamedArgumentExpression)arg;
                        var namedParam = parameters.First(p => p.Name == namedArg.Name);
                        var index      = parameters.IndexOf(namedParam) - shift;

                        result[index] = namedArg.Expression;
                        names[index]  = namedArg.Name;
                        named         = true;
                    }
                    else
                    {
                        if (paramsArg == null && (parameters.Count > (i + shift)) && parameters[i + shift].IsParams)
                        {
                            if (resolvedMethod.DeclaringTypeDefinition == null || !this.Emitter.Validator.IsIgnoreType(resolvedMethod.DeclaringTypeDefinition))
                            {
                                paramsArg = arg;
                            }

                            paramArgName = parameters[i + shift].Name;
                        }

                        if (i >= result.Length)
                        {
                            var list = result.ToList();
                            list.AddRange(new Expression[arguments.Count - i]);

                            var strList = names.ToList();
                            strList.AddRange(new string[arguments.Count - i]);

                            result = list.ToArray();
                            names  = strList.ToArray();
                        }

                        result[i] = arg;
                        names[i]  = (i + shift) < parameters.Count ? parameters[i + shift].Name : paramArgName;
                    }

                    i++;
                }

                for (i = 0; i < result.Length; i++)
                {
                    if (result[i] == null)
                    {
                        var    p = parameters[i + shift];
                        object t = null;
                        if (p.Type.Kind == TypeKind.Enum)
                        {
                            t = Helpers.GetEnumValue(this.Emitter, p.Type, p.ConstantValue);
                        }
                        else
                        {
                            t = p.ConstantValue;
                        }
                        if (named && !p.IsParams)
                        {
                            result[i] = new PrimitiveExpression(t);
                        }

                        names[i] = parameters[i + shift].Name;
                    }
                }

                this.ArgumentsExpressions = result;
                this.ArgumentsNames       = names;
                this.ParamsExpression     = paramsArg;
                this.NamedExpressions     = this.CreateNamedExpressions(names, result);
            }
            else
            {
                this.ArgumentsExpressions = arguments.ToArray();
            }
        }
Exemplo n.º 23
0
 public StringBuilder VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, int data)
 {
     throw new ASLException("ASL does not support named arguments.");
 }
Exemplo n.º 24
0
        protected override CodeAction GetAction(RefactoringContext context, Expression expression)
        {
            if (expression == null)
            {
                return(null);
            }
            if (expression.Role != Roles.Argument || expression is NamedArgumentExpression)
            {
                return(null);
            }
            var parent = expression.Parent;

            if (!(parent is CSharp.Attribute) && !(parent is IndexerExpression) && !(parent is InvocationExpression))
            {
                return(null);
            }

            if (parent is CSharp.Attribute)
            {
                var resolvedResult = context.Resolve(parent as CSharp.Attribute);
                if (resolvedResult.IsError)
                {
                    return(null);
                }
                var     arguments = (parent as CSharp.Attribute).Arguments;
                IMember member    = (resolvedResult as CSharpInvocationResolveResult).Member;

                int index = 0;
                int temp  = 0;
                List <Expression> nodes = new List <Expression>();
                foreach (var argument in arguments)
                {
                    if (argument.Equals(expression))
                    {
                        nodes = CollectNodes(parent, expression);
                        break;
                    }
                    temp++;
                }
                index = temp;
                if (!nodes.Any())
                {
                    return(null);
                }
                var method = member as IMethod;
                if (method == null || method.Parameters.Count == 0 || method.Parameters.Last().IsParams)
                {
                    return(null);
                }

                var parameterMap = (resolvedResult as CSharpInvocationResolveResult).GetArgumentToParameterMap();
                var parameters   = method.Parameters;
                if (index >= parameterMap.Count)
                {
                    return(null);
                }
                var name = parameters.ElementAt(parameterMap [index]).Name;
                return(new CodeAction(string.Format(context.TranslateString("Add argument name '{0}'"), name), script => {
                    for (int i = 0; i < nodes.Count; i++)
                    {
                        int p = index + i;
                        if (p >= parameterMap.Count)
                        {
                            break;
                        }
                        name = parameters.ElementAt(parameterMap [p]).Name;
                        var namedArgument = new NamedArgumentExpression(name, arguments.ElementAt(p).Clone());
                        script.Replace(arguments.ElementAt(p), namedArgument);
                    }
                },
                                      expression
                                      ));
            }

            if (parent is IndexerExpression)
            {
                var resolvedResult = context.Resolve(parent as IndexerExpression);
                if (resolvedResult.IsError)
                {
                    return(null);
                }
                var     arguments = (parent as IndexerExpression).Arguments;
                IMember member    = (resolvedResult as CSharpInvocationResolveResult).Member;

                int index = 0;
                int temp  = 0;
                List <Expression> nodes = new List <Expression>();
                foreach (var argument in arguments)
                {
                    if (argument.Equals(expression))
                    {
                        nodes = CollectNodes(parent, expression);
                        break;
                    }
                    temp++;
                }
                index = temp;
                if (!nodes.Any())
                {
                    return(null);
                }
                var property = member as IProperty;
                if (property == null || property.Parameters.Count == 0 || property.Parameters.Last().IsParams)
                {
                    return(null);
                }
                var parameterMap = (resolvedResult as CSharpInvocationResolveResult).GetArgumentToParameterMap();
                var parameters   = property.Parameters;
                if (index >= parameterMap.Count)
                {
                    return(null);
                }
                var name = parameters.ElementAt(parameterMap [index]).Name;
                return(new CodeAction(string.Format(context.TranslateString("Add argument name '{0}'"), name), script => {
                    for (int i = 0; i < nodes.Count; i++)
                    {
                        int p = index + i;
                        if (p >= parameterMap.Count)
                        {
                            break;
                        }
                        name = parameters.ElementAt(parameterMap [p]).Name;
                        var namedArgument = new NamedArgumentExpression(name, arguments.ElementAt(p).Clone());
                        script.Replace(arguments.ElementAt(p), namedArgument);
                    }
                },
                                      expression
                                      ));
            }

            if (parent is InvocationExpression)
            {
                var resolvedResult = context.Resolve(parent as InvocationExpression);
                if (resolvedResult.IsError)
                {
                    return(null);
                }
                var     arguments = (parent as InvocationExpression).Arguments;
                IMember member    = (resolvedResult as CSharpInvocationResolveResult).Member;

                int index = 0;
                int temp  = 0;
                List <Expression> nodes = new List <Expression>();
                foreach (var argument in arguments)
                {
                    if (argument.Equals(expression))
                    {
                        nodes = CollectNodes(parent, expression);
                        break;
                    }
                    temp++;
                }
                index = temp;
                if (!nodes.Any())
                {
                    return(null);
                }

                var method = member as IMethod;
                if (method == null || method.Parameters.Count == 0 || method.Parameters.Last().IsParams)
                {
                    return(null);
                }

                var parameterMap = (resolvedResult as CSharpInvocationResolveResult).GetArgumentToParameterMap();
                var parameters   = method.Parameters;
                if (index >= parameterMap.Count)
                {
                    return(null);
                }
                var name = parameters.ElementAt(parameterMap [index]).Name;
                return(new CodeAction(string.Format(context.TranslateString("Add argument name '{0}'"), name), script => {
                    for (int i = 0; i < nodes.Count; i++)
                    {
                        int p = index + i;
                        if (p >= parameterMap.Count)
                        {
                            break;
                        }
                        name = parameters.ElementAt(parameterMap [p]).Name;
                        var namedArgument = new NamedArgumentExpression(name, arguments.ElementAt(p).Clone());
                        script.Replace(arguments.ElementAt(p), namedArgument);
                    }
                },
                                      expression
                                      ));
            }
            return(null);
        }
 private bool IsMatch(NamedArgumentExpression left, NamedArgumentExpression data)
 {
     return(left.Name == data.Name);
 }
Exemplo n.º 26
0
	void ObjectPropertyInitializerOrVariableInitializer(
#line  1439 "cs.ATG" 
out Expression expr) {

#line  1440 "cs.ATG" 
		expr = null; 
		if (
#line  1442 "cs.ATG" 
IdentAndAsgn()) {
			Identifier();

#line  1444 "cs.ATG" 
			NamedArgumentExpression nae = new NamedArgumentExpression(t.val, null);
			nae.StartLocation = t.Location;
			Expression r = null; 
			Expect(3);
			if (la.kind == 16) {
				CollectionOrObjectInitializer(
#line  1448 "cs.ATG" 
out r);
			} else if (StartOf(31)) {
				VariableInitializer(
#line  1449 "cs.ATG" 
out r);
			} else SynErr(195);

#line  1450 "cs.ATG" 
			nae.Expression = r; nae.EndLocation = t.EndLocation; expr = nae; 
		} else if (StartOf(31)) {
			VariableInitializer(
#line  1452 "cs.ATG" 
out expr);
		} else SynErr(196);
	}
Exemplo n.º 27
0
        protected virtual void WriteObjectInitializer(IEnumerable <Expression> expressions, TypeDefinition type, InvocationResolveResult rr, bool withCtor)
        {
            bool          needComma       = false;
            List <string> names           = new List <string>();
            var           isObjectLiteral = this.Emitter.Validator.IsObjectLiteral(type);

            if (!withCtor && rr != null && this.ObjectCreateExpression.Arguments.Count > 0)
            {
                var args      = this.ObjectCreateExpression.Arguments.ToList();
                var arrIsOpen = false;
                for (int i = 0; i < args.Count; i++)
                {
                    Expression expression = args[i];
                    var        p          = rr.Member.Parameters[i < rr.Member.Parameters.Count ? i : (rr.Member.Parameters.Count - 1)];
                    var        name       = p.Name;

                    if (p.Type.FullName == "Bridge.ObjectInitializationMode" ||
                        p.Type.FullName == "Bridge.ObjectCreateMode")
                    {
                        continue;
                    }

                    if (needComma)
                    {
                        this.WriteComma();
                    }

                    needComma = true;

                    if (p.IsParams && !arrIsOpen)
                    {
                        arrIsOpen = true;
                        this.Write("[");
                    }

                    this.Write(name, ": ");
                    expression.AcceptVisitor(this.Emitter);

                    names.Add(name);
                }

                if (arrIsOpen)
                {
                    this.Write("]");
                }
            }

            if (expressions != null)
            {
                foreach (Expression item in expressions)
                {
                    NamedExpression         namedExression          = item as NamedExpression;
                    NamedArgumentExpression namedArgumentExpression = item as NamedArgumentExpression;
                    string name = namedExression != null ? namedExression.Name : namedArgumentExpression.Name;

                    var itemrr = this.Emitter.Resolver.ResolveNode(item, this.Emitter) as MemberResolveResult;
                    if (itemrr != null)
                    {
                        var  oc = OverloadsCollection.Create(this.Emitter, itemrr.Member);
                        bool forceObjectLiteral = itemrr.Member is IProperty && !itemrr.Member.Attributes.Any(attr => attr.AttributeType.FullName == "Bridge.NameAttribute") && !this.Emitter.Validator.IsObjectLiteral(itemrr.Member.DeclaringTypeDefinition);

                        name = oc.GetOverloadName(isObjectLiteral: forceObjectLiteral);
                    }

                    if (needComma)
                    {
                        this.WriteComma();
                    }

                    needComma = true;

                    Expression expression = namedExression != null ? namedExression.Expression : namedArgumentExpression.Expression;

                    this.WriteIdentifier(name, true, true);
                    this.Write(": ");
                    expression.AcceptVisitor(this.Emitter);

                    names.Add(name);
                }
            }

            if (isObjectLiteral)
            {
                var key   = BridgeTypes.GetTypeDefinitionKey(type);
                var tinfo = this.Emitter.Types.FirstOrDefault(t => t.Key == key);

                var mode = 0;
                if (rr != null)
                {
                    if (rr.Member.Parameters.Count > 0)
                    {
                        var prm = rr.Member.Parameters.FirstOrDefault(p => p.Type.FullName == "Bridge.ObjectInitializationMode");

                        if (prm != null)
                        {
                            var prmIndex = rr.Member.Parameters.IndexOf(prm);
                            var arg      = rr.Arguments.FirstOrDefault(a =>
                            {
                                if (a is NamedArgumentResolveResult)
                                {
                                    return(((NamedArgumentResolveResult)a).ParameterName == prm.Name);
                                }

                                return(prmIndex == rr.Arguments.IndexOf(a));
                            });

                            if (arg != null && arg.ConstantValue != null && arg.ConstantValue is int)
                            {
                                mode = (int)arg.ConstantValue;
                            }
                        }
                    }
                    else if (type != null)
                    {
                        mode = this.Emitter.Validator.GetObjectInitializationMode(type);
                    }
                }

                if (tinfo == null)
                {
                    if (mode == 2)
                    {
                        var properties = rr.Member.DeclaringTypeDefinition.GetProperties(null, GetMemberOptions.IgnoreInheritedMembers);
                        foreach (var prop in properties)
                        {
                            var name = OverloadsCollection.Create(this.Emitter, prop).GetOverloadName();

                            if (names.Contains(name))
                            {
                                continue;
                            }

                            if (needComma)
                            {
                                this.WriteComma();
                            }

                            needComma = true;

                            this.WriteIdentifier(name, true, true);
                            this.Write(": ");

                            var argType  = prop.ReturnType;
                            var defValue = Inspector.GetDefaultFieldValue(argType, null);
                            if (defValue == argType)
                            {
                                this.Write(Inspector.GetStructDefaultValue(argType, this.Emitter));
                            }
                            else
                            {
                                this.Write(defValue);
                            }
                        }
                    }

                    return;
                }

                if (mode != 0)
                {
                    var members = tinfo.InstanceConfig.Fields.Concat(tinfo.InstanceConfig.Properties);

                    if (members.Any())
                    {
                        foreach (var member in members)
                        {
                            if (mode == 1 && (member.VarInitializer == null || member.VarInitializer.Initializer.IsNull) && !member.IsPropertyInitializer)
                            {
                                continue;
                            }

                            var name = member.GetName(this.Emitter);

                            if (names.Contains(name))
                            {
                                continue;
                            }

                            if (needComma)
                            {
                                this.WriteComma();
                            }

                            needComma = true;

                            this.WriteIdentifier(name, true, true);
                            this.Write(": ");
                            var primitiveExpr = member.Initializer as PrimitiveExpression;

                            if (mode == 2 && (member.Initializer == null || member.Initializer.IsNull) && !(member.VarInitializer == null || member.VarInitializer.Initializer.IsNull))
                            {
                                var argType  = this.Emitter.Resolver.ResolveNode(member.VarInitializer, this.Emitter).Type;
                                var defValue = Inspector.GetDefaultFieldValue(argType, null);
                                if (defValue == argType)
                                {
                                    this.Write(Inspector.GetStructDefaultValue(argType, this.Emitter));
                                }
                                else
                                {
                                    this.Write(defValue);
                                }
                            }
                            else
                            {
                                if (primitiveExpr != null && primitiveExpr.Value is AstType)
                                {
                                    this.Write(Inspector.GetStructDefaultValue((AstType)primitiveExpr.Value, this.Emitter));
                                }
                                else if (member.Initializer != null)
                                {
                                    member.Initializer.AcceptVisitor(this.Emitter);
                                }
                                else
                                {
                                    this.Write("null");
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 28
0
	void MemberInitializer(
#line  2324 "VBNET.ATG" 
out NamedArgumentExpression memberInitializer) {

#line  2326 "VBNET.ATG" 
		memberInitializer = new NamedArgumentExpression();
		memberInitializer.StartLocation = la.Location;
		Expression initExpr = null;
		string name = null;
		
		Expect(16);
		IdentifierOrKeyword(
#line  2331 "VBNET.ATG" 
out name);
		Expect(10);
		Expr(
#line  2331 "VBNET.ATG" 
out initExpr);

#line  2333 "VBNET.ATG" 
		memberInitializer.Name = name;
		memberInitializer.Expression = initExpr;
		memberInitializer.EndLocation = t.EndLocation;
		
	}
Exemplo n.º 29
0
 public void VisitNamedArgumentExpression(NamedArgumentExpression node)
 {
     node.Expression.AcceptVisitor(this);
     node.ReplaceWith(node.Expression);
 }
Exemplo n.º 30
0
			IEnumerable<Attribute> GetAttributes (Attributes optAttributes)
			{
				if (optAttributes == null || optAttributes.Attrs == null)
					yield break;
				
				foreach (var attr in optAttributes.Attrs) {
					Attribute result = new Attribute ();
					result.Type = ConvertToType (attr.TypeNameExpression);
					
					if (attr.PosArguments != null) {
						foreach (var arg in attr.PosArguments) {
							result.AddChild ((Expression)arg.Expr.Accept (this), Attribute.Roles.Argument);
						}
					}
					if (attr.NamedArguments != null) { 
						foreach (NamedArgument na in attr.NamedArguments) {
							NamedArgumentExpression newArg = new NamedArgumentExpression ();
							newArg.AddChild (new Identifier (na.Name, Convert (na.Location)), NamedArgumentExpression.Roles.Identifier);
							
							var loc = LocationsBag.GetLocations (na);
							if (loc != null)
								newArg.AddChild (new CSharpTokenNode (Convert (loc [0]), 1), NamedArgumentExpression.Roles.Assign);
							newArg.AddChild ((Expression)na.Expr.Accept (this), NamedArgumentExpression.Roles.Expression);
							result.AddChild (newArg, Attribute.Roles.Argument);
						}
					}
					yield return result;
				}
			}
 public object VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, object data)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 32
0
 public StringBuilder VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, int data)
 {
     throw new SLSharpException("SL# does not support named arguments.");
 }
 public virtual S VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, T data)
 {
     return(VisitChildren(namedArgumentExpression, data));
 }
 public virtual void VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression)
 {
     if (this.ThrowException)
     {
         throw (Exception)this.CreateException(namedArgumentExpression);
     }
 }
Exemplo n.º 35
0
        public void VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression)
        {
            JsonObject expression = CreateJsonExpression(namedArgumentExpression);
            expression.AddJsonValue("identifier", GetIdentifier(namedArgumentExpression.NameToken));
            expression.AddJsonValue("expression", GenExpression(namedArgumentExpression.Expression));

            Push(expression);
            throw new FirstTimeUseException();
        }
Exemplo n.º 36
0
			Expression ConvertArgument (Argument arg)
			{
				if (arg is NamedArgument) {
					var na = (NamedArgument)arg;
					NamedArgumentExpression newArg = new NamedArgumentExpression();
					newArg.AddChild (Identifier.Create (na.Name, Convert (na.Location)), NamedArgumentExpression.Roles.Identifier);
					
					var loc = LocationsBag.GetLocations (na);
					if (loc != null)
						newArg.AddChild (new CSharpTokenNode (Convert (loc[0]), 1), NamedArgumentExpression.Roles.Colon);
					
					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 (argLocation != null)
							direction.AddChild (new CSharpTokenNode (Convert (argLocation[0]), "123".Length), InvocationExpression.Roles.Keyword);
						direction.AddChild ((Expression)arg.Expr.Accept (this), InvocationExpression.Roles.Expression);
						newArg.AddChild (direction, NamedArgumentExpression.Roles.Expression);
					} else {
						newArg.AddChild ((Expression)na.Expr.Accept (this), NamedArgumentExpression.Roles.Expression);
					}
					return newArg;
				}
				
				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 (argLocation != null)
						direction.AddChild (new CSharpTokenNode (Convert (argLocation[0]), "123".Length), InvocationExpression.Roles.Keyword);
					direction.AddChild ((Expression)arg.Expr.Accept (this), InvocationExpression.Roles.Expression);
					return direction;
				}
				
				return (Expression)arg.Expr.Accept (this);
			}
Exemplo n.º 37
0
 public void VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 38
0
			IEnumerable<Attribute> GetAttributes(IEnumerable<Mono.CSharp.Attribute> optAttributes)
			{
				if (optAttributes == null)
					yield break;
				foreach (var attr in optAttributes) {
					var result = new Attribute();
					result.Type = ConvertToType(attr.TypeNameExpression);
					var loc = LocationsBag.GetLocations(attr);
					result.HasArgumentList = loc != null;
					int pos = 0;
					if (loc != null)
						result.AddChild(new CSharpTokenNode(Convert(loc [pos++]), Roles.LPar), Roles.LPar);
					
					if (attr.PositionalArguments != null) {
						foreach (var arg in attr.PositionalArguments) {
							if (arg == null)
								continue;
							var na = arg as NamedArgument;
							if (na != null) {
								var newArg = new NamedArgumentExpression();
								newArg.AddChild(Identifier.Create(na.Name, Convert(na.Location)), Roles.Identifier);
								
								var argLoc = LocationsBag.GetLocations(na);
								if (argLoc != null)
									newArg.AddChild(new CSharpTokenNode(Convert(argLoc [0]), Roles.Colon), Roles.Colon);
								if (na.Expr != null)
									newArg.AddChild((Expression)na.Expr.Accept(this), Roles.Expression);
								result.AddChild(newArg, Roles.Argument);
							} else {
								if (arg.Expr != null)
									result.AddChild((Expression)arg.Expr.Accept(this), Roles.Argument);
							}
							if (loc != null && pos + 1 < loc.Count)
								result.AddChild(new CSharpTokenNode(Convert(loc [pos++]), Roles.Comma), Roles.Comma);
						}
					}
					if (attr.NamedArguments != null) {
						foreach (var arg in attr.NamedArguments) {
							var na = (NamedArgument)arg;
							var newArg = new NamedExpression();
							newArg.AddChild(Identifier.Create(na.Name, Convert(na.Location)), Roles.Identifier);
							
							var argLoc = LocationsBag.GetLocations(na);
							if (argLoc != null)
								newArg.AddChild(new CSharpTokenNode(Convert(argLoc [0]), Roles.Assign), Roles.Assign);
							if (na.Expr != null)
								newArg.AddChild((Expression)na.Expr.Accept(this), Roles.Expression);
							result.AddChild(newArg, Roles.Argument);
							if (loc != null && pos + 1 < loc.Count)
								result.AddChild(new CSharpTokenNode(Convert(loc [pos++]), Roles.Comma), Roles.Comma);
						}
					}
					if (loc != null && pos < loc.Count)
						result.AddChild(new CSharpTokenNode(Convert(loc [pos++]), Roles.RPar), Roles.RPar);
					
					yield return result;
				}
			}
Exemplo n.º 39
0
		public virtual object VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, object data) {
			Debug.Assert((namedArgumentExpression != null));
			Debug.Assert((namedArgumentExpression.Expression != null));
			return namedArgumentExpression.Expression.AcceptVisitor(this, data);
		}
Exemplo n.º 40
0
		public void VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression)
		{
			StartNode(namedArgumentExpression);
			namedArgumentExpression.NameToken.AcceptVisitor(this);
			WriteToken(Roles.Colon);
			Space();
			namedArgumentExpression.Expression.AcceptVisitor(this);
			EndNode(namedArgumentExpression);
		}
 public object VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, object data)
 {
     AddError(namedArgumentExpression, "Named arguments are not supported in boo. (argument name was " + namedArgumentExpression.Name + ")");
     return(namedArgumentExpression.Expression.AcceptVisitor(this, data));
 }