コード例 #1
0
        string GetArgValue(string arg, EnvDTE.Debugger debugger)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (arg.StartsWith("$"))
            {
                if (!SavedResults.ContainsKey(arg))
                {
                    throw new Exception(String.Format("Using unknown variable {0}", arg));
                }
                var indexResult = SavedResults[arg].GetResults()[0];
                if (indexResult.IsLiteral)
                {
                    return(indexResult.Expression);
                }
                else
                {
                    var expr = debugger.GetExpression(indexResult.Expression + ",d");
                    return(expr.Value);
                }
            }
            else
            {
                return(arg);
            }
        }
コード例 #2
0
        private void GetInputResultsForZip(string[] args, int offset, out DebuggerScriptResultList[] inputResults, out int minResults)
        {
            minResults   = 0;
            inputResults = new DebuggerScriptResultList[args.Count() - offset];

            for (int inputIndex = 0; inputIndex < inputResults.Count(); ++inputIndex)
            {
                if (!SavedResults.ContainsKey(args[inputIndex + offset]))
                {
                    throw new Exception(String.Format("Using unknown variable {0}", args[inputIndex + offset]));
                }
                inputResults[inputIndex] = SavedResults[args[inputIndex + offset]];

                int count = inputResults[inputIndex].GetResults().Count();
                minResults = inputIndex == 0 ? count : Math.Min(count, minResults);
            }
        }
コード例 #3
0
        DebuggerScriptResultList Concat(string[] args)
        {
            DebuggerScriptResultList newResults = new DebuggerScriptResultList();

            for (int inputIndex = 0; inputIndex < args.Count(); ++inputIndex)
            {
                if (!SavedResults.ContainsKey(args[inputIndex]))
                {
                    throw new Exception(String.Format("Using unknown variable {0}", args[inputIndex]));
                }
                var inputResults = SavedResults[args[inputIndex]];

                for (int resultIndex = 0; resultIndex < inputResults.GetResults().Count(); ++resultIndex)
                {
                    string exprString = inputResults.GetResults()[resultIndex].Expression;
                    string nameString = inputResults.GetResults()[resultIndex].Name;
                    newResults.Add(exprString, nameString, inputResults.GetResults()[resultIndex].Index);
                }
            }

            return(newResults);
        }
コード例 #4
0
        public DebuggerScriptResultList ExecuteLine(string script, EnvDTE.Debugger debugger)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            string        token;
            List <string> args;
            bool          isFunction;
            string        saveTo = null;

            DebuggerScriptResultList results = new DebuggerScriptResultList();

            string functionDeclStart = "function ";

            if (script.ToLower().StartsWith(functionDeclStart))
            {
                string functionDecl = script.Substring(functionDeclStart.Length);
                string restOfScript;
                GetNextToken(functionDecl, out FunctionBeingAdded.Name, out FunctionBeingAdded.Args, out isFunction, out restOfScript);
                if (!FunctionBeingAdded.Name.StartsWith("#"))
                {
                    throw new Exception("Function names must start with #");
                }
                FunctionBeingAdded.Script = "";
                IsAddingFunction          = true;
                return(null);
            }
            else if (IsAddingFunction)
            {
                if (script.ToLower() == "end")
                {
                    IsAddingFunction = false;
                    Functions.Add(FunctionBeingAdded);
                }
                else
                {
                    FunctionBeingAdded.Script = FunctionBeingAdded.Script + script + "\n";
                }
                return(null);
            }

            GetNextToken(script, out token, out args, out isFunction, out script);

            do
            {
                if (isFunction)
                {
                    switch (token.ToLower())
                    {
                    case ".array":
                        results = results.Array(int.Parse(GetArgValue(args[0], debugger)));
                        break;

                    case ".arrayrange":
                        results = results.ArrayRange(int.Parse(GetArgValue(args[0], debugger)), int.Parse(GetArgValue(args[1], debugger)));
                        break;

                    case ".cast":
                        results = results.Cast(args[0]);
                        break;

                    case "concat":
                    case ".concat":
                        results = Concat(args.ToArray());
                        break;

                    case ".filter":
                        if (args.Count != 1)
                        {
                            throw new Exception("filter requires 1 argument");
                        }
                        results = results.Filter(GetArgValue(args[0], debugger), debugger);
                        break;

                    case ".filterstring":
                        if (args.Count != 2)
                        {
                            throw new Exception("filterstring requires 2 arguments");
                        }
                        results = results.FilterString(GetArgValue(args[0], debugger), GetArgValue(args[1], debugger), debugger);
                        break;

                    case ".filternotstring":
                        if (args.Count != 2)
                        {
                            throw new Exception("filternotstring requires 2 arguments");
                        }
                        results = results.FilterNotString(GetArgValue(args[0], debugger), GetArgValue(args[1], debugger), debugger);
                        break;

                    case ".fold":
                        if (args.Count != 1)
                        {
                            throw new Exception("fold requires 1 argument");
                        }
                        results = results.Fold(args[0]);
                        break;

                    case ".index":
                        results = results.ArrayIndex(int.Parse(GetArgValue(args[0], debugger)));
                        break;

                    case ".members":
                        results = results.Members(args.ToArray());
                        break;

                    case ".memory":
                        results = Memory(args, results);
                        break;

                    case ".pointer":
                        results = results.Pointer();
                        break;

                    case ".reference":
                        results = results.Reference();
                        break;

                    case ".reinterpretcast":
                        results = results.ReinterpretCast(GetArgValue(args[0], debugger));
                        break;

                    case ".rename":
                        results = results.Rename(GetArgValue(args[0], debugger));
                        break;

                    case ".renamewithindex":
                        results = results.RenameWithIndex(GetArgValue(args[0], debugger));
                        break;

                    case "zip":
                    case ".zip":
                        results = Zip(args.ToArray());
                        break;

                    case "zipwith":
                    case ".zipwith":
                        results = ZipWith(args.ToArray());
                        break;

                    case "import":
                        Import(args[0], debugger);
                        break;

                    case "=":
                        saveTo = args[0];
                        if (!saveTo.StartsWith("$"))
                        {
                            throw new Exception("Variables must begin with '$'");
                        }
                        break;

                    default:
                        if (token.StartsWith("#"))
                        {
                            results = RunFunction(token, results, args, debugger);
                        }
                        else if (token.StartsWith(".#"))
                        {
                            results = RunFunction(token.Substring(1), results, args, debugger);
                        }
                        else
                        {
                            throw new Exception("Unknown function");
                        }
                        break;
                    }
                }
                else if (token.StartsWith(".") || token.StartsWith("->"))
                {
                    results = results.Members(token);
                }
                else if (token.StartsWith("$"))
                {
                    if (!SavedResults.ContainsKey(token))
                    {
                        throw new Exception(String.Format("Using unknown variable {0}", token));
                    }
                    results = SavedResults[token];
                }
                else
                {
                    results = GetVariable(token);
                }
            } while (GetNextToken(script, out token, out args, out isFunction, out script));

            if (saveTo != null)
            {
                SavedResults.Add(saveTo, results);
            }
            return(results);
        }