示例#1
0
 public override AstVisitAction VisitArrayLiteral(ArrayLiteralAst ast)
 {
     return(DoNextAction(ast));
 }
示例#2
0
        internal void BindParameters(Collection <CommandParameterInternal> parameters)
        {
            bool sawVerbatimArgumentMarker = false;
            bool first = true;

            foreach (CommandParameterInternal parameter in parameters)
            {
                if (!first)
                {
                    _arguments.Append(' ');
                }

                first = false;

                if (parameter.ParameterNameSpecified)
                {
                    Diagnostics.Assert(parameter.ParameterText.IndexOf(' ') == -1, "Parameters cannot have whitespace");
                    PossiblyGlobArg(parameter.ParameterText, usedQuotes: false);

                    if (parameter.SpaceAfterParameter)
                    {
                        _arguments.Append(' ');
                    }
                }

                if (parameter.ArgumentSpecified)
                {
                    // If this is the verbatim argument marker, we don't pass it on to the native command.
                    // We do need to remember it though - we'll expand environment variables in subsequent args.
                    object argValue = parameter.ArgumentValue;
                    if (string.Equals("--%", argValue as string, StringComparison.OrdinalIgnoreCase))
                    {
                        sawVerbatimArgumentMarker = true;
                        continue;
                    }

                    if (argValue != AutomationNull.Value && argValue != UnboundParameter.Value)
                    {
                        // ArrayLiteralAst is used to reconstruct the correct argument, e.g.
                        //    windbg  -k com:port=\\devbox\pipe\debug,pipe,resets=0,reconnect
                        // The parser produced an array of strings but marked the parameter so we
                        // can properly reconstruct the correct command line.
                        bool            usedQuotes      = false;
                        ArrayLiteralAst arrayLiteralAst = null;
                        switch (parameter?.ArgumentAst)
                        {
                        case StringConstantExpressionAst sce:
                            usedQuotes = sce.StringConstantType != StringConstantType.BareWord;
                            break;

                        case ExpandableStringExpressionAst ese:
                            usedQuotes = ese.StringConstantType != StringConstantType.BareWord;
                            break;

                        case ArrayLiteralAst ala:
                            arrayLiteralAst = ala;
                            break;
                        }

                        appendOneNativeArgument(Context, argValue,
                                                arrayLiteralAst, sawVerbatimArgumentMarker, usedQuotes);
                    }
                }
            }
        }
 public override AstVisitAction VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst)
 {
     return(Visit(arrayLiteralAst));
 }
示例#4
0
 public override AstVisitAction VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst)
 {
     Console.WriteLine("Visited an ArrayLiteralAst.");
     Console.WriteLine("    " + arrayLiteralAst.ToString().Replace(Environment.NewLine, Environment.NewLine + "    "));
     return(AstVisitAction.Continue);
 }
        public object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst)
        {
            var newArrayElements = VisitElements(arrayLiteralAst.Elements);

            return(new ArrayLiteralAst(arrayLiteralAst.Extent, newArrayElements));
        }
示例#6
0
 /// <summary/>
 public virtual AstVisitAction VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) => DefaultVisit(arrayLiteralAst);
        public object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst)
        {
            var elements = VisitAst(arrayLiteralAst.Elements).ToList();

            return(new ArrayLiteralAst(arrayLiteralAst.Extent, elements));
        }
 public static ArrayLiteralAst Update(this ArrayLiteralAst ast, IEnumerable <ExpressionAst> expressions)
 {
     return(new ArrayLiteralAst(ast.Extent, expressions.CloneAll().ToArray()));
 }
示例#9
0
        public object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst)
        {
            var items = arrayLiteralAst.Elements.Select(Visit).OfType <CodeExpression>().ToArray();

            return(new CodeArrayCreateExpression("System.Object", items));
        }
 object ICustomAstVisitor.VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst)
 => ProcessRewriter(VisitArrayLiteral, arrayLiteralAst);
示例#11
0
 public object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst)
 {
     return(arrayLiteralAst.Elements.Select(e => e.Visit(this)).ToArray());
 }
 public virtual ExpressionAst VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst)
 {
     return(new ArrayLiteralAst(
                arrayLiteralAst.Extent,
                arrayLiteralAst.Elements.RewriteAll <ExpressionAst>(this, SyntaxKind.Expression)));
 }
 object ICustomAstVisitor.VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) => VisitArrayLiteral(arrayLiteralAst);
 public virtual TResult VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) => default(TResult);
示例#15
0
 public override ExpressionAst VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst)
 => VisitExpression(base.VisitArrayLiteral(arrayLiteralAst));
示例#16
0
 public override AstVisitAction VisitArrayLiteral(ArrayLiteralAst ast)
 {
     return(AstVisitAction.Continue);
 }
示例#17
0
        public override AstVisitAction VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst)
        {
            _pipelineCommandRuntime.WriteObject(arrayLiteralAst.Elements.Select(EvaluateAst).ToArray(), true);

            return(AstVisitAction.SkipChildren);
        }
示例#18
0
 public virtual object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst)
 {
     VisitElements(arrayLiteralAst.Elements);
     return(arrayLiteralAst);
 }
 public object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) => null;
示例#20
0
 public override AstVisitAction VisitArrayLiteral(ArrayLiteralAst ast)
 {
     return(Check(ast));
 }
示例#21
0
 public object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst)
 {
     Console.WriteLine("Visited an ArrayLiteralAst.");
     return(arrayLiteralAst);
 }
示例#22
0
        internal void BindParameters(Collection <CommandParameterInternal> parameters)
        {
            bool sawVerbatimArgumentMarker = false;
            bool first = true;

            foreach (CommandParameterInternal parameter in parameters)
            {
                if (!first)
                {
                    _arguments.Append(' ');
                }

                first = false;

                if (parameter.ParameterNameSpecified)
                {
                    Diagnostics.Assert(!parameter.ParameterText.Contains(' '), "Parameters cannot have whitespace");
                    PossiblyGlobArg(parameter.ParameterText, StringConstantType.BareWord);

                    if (parameter.SpaceAfterParameter)
                    {
                        _arguments.Append(' ');
                    }
                }

                if (parameter.ArgumentSpecified)
                {
                    // If this is the verbatim argument marker, we don't pass it on to the native command.
                    // We do need to remember it though - we'll expand environment variables in subsequent args.
                    object argValue = parameter.ArgumentValue;
                    if (string.Equals("--%", argValue as string, StringComparison.OrdinalIgnoreCase))
                    {
                        sawVerbatimArgumentMarker = true;
                        continue;
                    }

                    if (argValue != AutomationNull.Value && argValue != UnboundParameter.Value)
                    {
                        // ArrayLiteralAst is used to reconstruct the correct argument, e.g.
                        //    windbg  -k com:port=\\devbox\pipe\debug,pipe,resets=0,reconnect
                        // The parser produced an array of strings but marked the parameter so we
                        // can properly reconstruct the correct command line.
                        StringConstantType stringConstantType = StringConstantType.BareWord;
                        ArrayLiteralAst    arrayLiteralAst    = null;
                        switch (parameter?.ArgumentAst)
                        {
                        case StringConstantExpressionAst sce:
                            stringConstantType = sce.StringConstantType;
                            break;

                        case ExpandableStringExpressionAst ese:
                            stringConstantType = ese.StringConstantType;
                            break;

                        case ArrayLiteralAst ala:
                            arrayLiteralAst = ala;
                            break;
                        }

                        // Prior to PSNativePSPathResolution experimental feature, a single quote worked the same as a double quote
                        // so if the feature is not enabled, we treat any quotes as double quotes.  When this feature is no longer
                        // experimental, this code here needs to be removed.
                        if (!ExperimentalFeature.IsEnabled("PSNativePSPathResolution") && stringConstantType == StringConstantType.SingleQuoted)
                        {
                            stringConstantType = StringConstantType.DoubleQuoted;
                        }

                        AppendOneNativeArgument(Context, argValue, arrayLiteralAst, sawVerbatimArgumentMarker, stringConstantType);
                    }
                }
            }
        }
示例#23
0
 public override object VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst)
 {
     VisitElements(arrayLiteralAst.Elements, ", ");
     return(arrayLiteralAst);
 }
示例#24
0
 public override AstVisitAction VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst)
 {
     throw new NotImplementedException(); //VisitArrayLiteral(arrayLiteralAst);
 }
示例#25
0
        /// <summary>
        /// Stringize a non-IEnum argument to a native command, adding quotes
        /// and trailing spaces as appropriate. An array gets added as multiple arguments
        /// each of which will be stringized.
        /// </summary>
        /// <param name="context">Execution context instance.</param>
        /// <param name="obj">The object to append.</param>
        /// <param name="argArrayAst">If the argument was an array literal, the Ast, otherwise null.</param>
        /// <param name="sawVerbatimArgumentMarker">True if the argument occurs after --%.</param>
        /// <param name="usedQuotes">True if the argument was a quoted string (single or double).</param>
        private void appendOneNativeArgument(ExecutionContext context, object obj, ArrayLiteralAst argArrayAst, bool sawVerbatimArgumentMarker, bool usedQuotes)
        {
            IEnumerator list = LanguagePrimitives.GetEnumerator(obj);

            Diagnostics.Assert(argArrayAst == null ||
                               obj is object[] && ((object[])obj).Length == argArrayAst.Elements.Count,
                               "array argument and ArrayLiteralAst differ in number of elements");

            int    currentElement = -1;
            string separator      = string.Empty;

            do
            {
                string arg;
                if (list == null)
                {
                    arg = PSObject.ToStringParser(context, obj);
                }
                else
                {
                    if (!ParserOps.MoveNext(context, null, list))
                    {
                        break;
                    }

                    arg = PSObject.ToStringParser(context, ParserOps.Current(null, list));

                    currentElement += 1;
                    if (currentElement != 0)
                    {
                        separator = GetEnumerableArgSeparator(argArrayAst, currentElement);
                    }
                }

                if (!string.IsNullOrEmpty(arg))
                {
                    _arguments.Append(separator);

                    if (sawVerbatimArgumentMarker)
                    {
                        arg = Environment.ExpandEnvironmentVariables(arg);
                        _arguments.Append(arg);
                    }
                    else
                    {
                        // We need to add quotes if the argument has unquoted spaces.  The
                        // quotes could appear anywhere inside the string, not just at the start,
                        // e.g.
                        //    $a = 'a"b c"d'
                        //    echoargs $a 'a"b c"d' a"b c"d
                        //
                        // The above should see 3 identical arguments in argv (the command line will
                        // actually have quotes in different places, but the Win32 command line=>argv parser
                        // erases those differences.
                        //
                        // We need to check quotes that the win32 argument parser checks which is currently
                        // just the normal double quotes, no other special quotes.  Also note that mismatched
                        // quotes are supported
                        if (NeedQuotes(arg))
                        {
                            _arguments.Append('"');
                            // need to escape all trailing backslashes so the native command receives it correctly
                            // according to http://www.daviddeley.com/autohotkey/parameters/parameters.htm#WINCRULESDOC
                            _arguments.Append(arg);
                            for (int i = arg.Length - 1; i >= 0 && arg[i] == '\\'; i--)
                            {
                                _arguments.Append('\\');
                            }

                            _arguments.Append('"');
                        }
                        else
                        {
                            PossiblyGlobArg(arg, usedQuotes);
                        }
                    }
                }
            } while (list != null);
        }
 public override AstVisitAction VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst)
 {
     // SKIP
     AstExplainer(arrayLiteralAst);
     return(base.VisitArrayLiteral(arrayLiteralAst));
 }
        /// <summary>
        /// Stringize a non-IEnum argument to a native command, adding quotes
        /// and trailing spaces as appropriate. An array gets added as multiple arguments
        /// each of which will be stringized.
        /// </summary>
        /// <param name="context">Execution context instance.</param>
        /// <param name="parameter">The parameter associated with the operation.</param>
        /// <param name="obj">The object to append.</param>
        /// <param name="argArrayAst">If the argument was an array literal, the Ast, otherwise null.</param>
        /// <param name="sawVerbatimArgumentMarker">True if the argument occurs after --%.</param>
        /// <param name="usedQuotes">True if the argument was a quoted string (single or double).</param>
        private void AppendOneNativeArgument(ExecutionContext context, CommandParameterInternal parameter, object obj, ArrayLiteralAst argArrayAst, bool sawVerbatimArgumentMarker, bool usedQuotes)
        {
            IEnumerator list = LanguagePrimitives.GetEnumerator(obj);

            Diagnostics.Assert((argArrayAst == null) || (obj is object[] && ((object[])obj).Length == argArrayAst.Elements.Count), "array argument and ArrayLiteralAst differ in number of elements");

            int    currentElement = -1;
            string separator      = string.Empty;

            do
            {
                string arg;
                object currentObj;
                if (list == null)
                {
                    arg        = PSObject.ToStringParser(context, obj);
                    currentObj = obj;
                }
                else
                {
                    if (!ParserOps.MoveNext(context, null, list))
                    {
                        break;
                    }

                    currentObj = ParserOps.Current(null, list);
                    arg        = PSObject.ToStringParser(context, currentObj);

                    currentElement += 1;
                    if (currentElement != 0)
                    {
                        separator = GetEnumerableArgSeparator(argArrayAst, currentElement);
                    }
                }

                if (!string.IsNullOrEmpty(arg))
                {
                    // Only add the separator to the argument string rather than adding a separator to the ArgumentList.
                    _arguments.Append(separator);

                    if (sawVerbatimArgumentMarker)
                    {
                        arg = Environment.ExpandEnvironmentVariables(arg);
                        _arguments.Append(arg);

                        // we need to split the argument on spaces
                        _argumentList.AddRange(arg.Split(' ', StringSplitOptions.RemoveEmptyEntries));
                    }
                    else
                    {
                        // We need to add quotes if the argument has unquoted spaces.  The
                        // quotes could appear anywhere inside the string, not just at the start,
                        // e.g.
                        //    $a = 'a"b c"d'
                        //    echoargs $a 'a"b c"d' a"b c"d
                        //
                        // The above should see 3 identical arguments in argv (the command line will
                        // actually have quotes in different places, but the Win32 command line=>argv parser
                        // erases those differences.
                        //
                        // We need to check quotes that the win32 argument parser checks which is currently
                        // just the normal double quotes, no other special quotes.  Also note that mismatched
                        // quotes are supported
                        if (NeedQuotes(arg))
                        {
                            _arguments.Append('"');
                            AddToArgumentList(parameter, arg);

                            // need to escape all trailing backslashes so the native command receives it correctly
                            // according to http://www.daviddeley.com/autohotkey/parameters/parameters.htm#WINCRULESDOC
                            _arguments.Append(arg);
                            for (int i = arg.Length - 1; i >= 0 && arg[i] == '\\'; i--)
                            {
                                _arguments.Append('\\');
                            }

                            _arguments.Append('"');
                        }
                        else
                        {
                            if (argArrayAst != null && ArgumentPassingStyle != NativeArgumentPassingStyle.Legacy)
                            {
                                // We have a literal array, so take the extent, break it on spaces and add them to the argument list.
                                foreach (string element in argArrayAst.Extent.Text.Split(' ', StringSplitOptions.RemoveEmptyEntries))
                                {
                                    PossiblyGlobArg(element, parameter, usedQuotes);
                                }

                                break;
                            }
                            else
                            {
                                PossiblyGlobArg(arg, parameter, usedQuotes);
                            }
                        }
                    }
                }
                else if (ArgumentPassingStyle != NativeArgumentPassingStyle.Legacy && currentObj != null)
                {
                    // add empty strings to arglist, but not nulls
                    AddToArgumentList(parameter, arg);
                }
            }while (list != null);
        }
示例#28
0
 public override AstVisitAction VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) => VisitAst(arrayLiteralAst);