예제 #1
0
        public string CaptureTest(Action action)
        {
            string result = AphidCli.Capture(action);

            return(result);
            // TODO: add assertions to method AphidCliTest.CaptureTest(Action)
        }
예제 #2
0
        public string RedirectTest(Action action)
        {
            string result = AphidCli.Redirect(action);

            return(result);
            // TODO: add assertions to method AphidCliTest.RedirectTest(Action)
        }
예제 #3
0
        public void DumpExceptionTest(int seed)
        {
            var code = StringFactory.Create(seed);
            var ex   = AphidParserExceptionFactory.Create(seed);

            AphidCli.DumpException(ex, code);
            // TODO: add assertions to method AphidCliTest.DumpExceptionTest(AphidParserException, String)
        }
예제 #4
0
 public void DumpValueTest(
     AphidInterpreter interpreter,
     object value,
     bool ignoreNull,
     bool ignoreClrObj
     )
 {
     AphidCli.DumpValue(interpreter, value, ignoreNull, ignoreClrObj);
     // TODO: add assertions to method AphidCliTest.DumpValueTest(AphidInterpreter, Object, Boolean, Boolean)
 }
예제 #5
0
 public void WriteMessageTest(
     ConsoleColor tokenColor,
     char token,
     string format,
     object[] arg
     )
 {
     AphidCli.WriteMessage(tokenColor, token, format, arg);
     // TODO: add assertions to method AphidCliTest.WriteMessageTest(ConsoleColor, Char, String, Object[])
 }
예제 #6
0
        public bool TryActionTest(
            AphidInterpreter interpreter,
            string code,
            Action action
            )
        {
            bool result = AphidCli.TryAction(interpreter, code, action);

            return(result);
            // TODO: add assertions to method AphidCliTest.TryActionTest(AphidInterpreter, String, Action)
        }
예제 #7
0
        public bool TryActionTest01(
            AphidInterpreter interpreter,
            string code,
            Action action,
            bool allowErrorReporting
            )
        {
            bool result = AphidCli.TryAction(interpreter, code, action, allowErrorReporting)
            ;

            return(result);
            // TODO: add assertions to method AphidCliTest.TryActionTest01(AphidInterpreter, String, Action, Boolean)
        }
예제 #8
0
        public bool TryActionTest02(
            AphidInterpreter interpreter,
            Func <string> getCode,
            Action action,
            bool allowErrorReporting
            )
        {
            bool result
                = AphidCli.TryAction(interpreter, getCode, action, allowErrorReporting);

            return(result);
            // TODO: add assertions to method AphidCliTest.TryActionTest02(AphidInterpreter, Func`1<String>, Action, Boolean)
        }
예제 #9
0
 public static IEnumerable <Lazy <string> > Format(
     AphidInterpreter interpreter,
     AphidPair[] locals,
     List <AphidObject> scopes,
     int index = 0) =>
 locals
 .Select(x => new Lazy <string>(() =>
                                LineNumberFormatter.PrefixIndex(index++,
                                                                SyntaxHighlightingFormatter.Format(
                                                                    string.Format(
                                                                        "{0} {1} = {2}",
                                                                        AphidCli.GetAphidObjectTypeName(x.Value),
                                                                        x.Key,
                                                                        SerializingFormatter.Format(
                                                                            interpreter,
                                                                            x.Value,
                                                                            ignoreNull: false,
                                                                            ignoreClrObj: false,
                                                                            scopes: scopes)
                                                                        .Indent(new string(' ', 5))
                                                                        .TrimStart())))));
예제 #10
0
 public void DumpExceptionTest03(Exception exception, AphidInterpreter interpreter)
 {
     AphidCli.DumpException(exception, interpreter);
     // TODO: add assertions to method AphidCliTest.DumpExceptionTest03(Exception, AphidInterpreter)
 }
예제 #11
0
 public void WriteSubheaderTest(string text, string style)
 {
     AphidCli.WriteSubheader(text, style);
     // TODO: add assertions to method AphidCliTest.WriteSubheaderTest(String, String)
 }
예제 #12
0
        //private Task ExecuteWatchExpressionAsync(ExpressionViewModel vm) =>
        //    Task.Run(() => ExecuteWatchExpression(vm));

        private async Task ExecuteWatchExpressionAsync(ExpressionViewModel vm)
        {
            string msg = null;

            try
            {
                Interpreter.ResetState();
                Interpreter.TakeOwnership();

#if APHID_FRAME_ADD_DATA || APHID_FRAME_CATCH_POP
                try
                {
#endif

                var ast = ParseRetExpression(vm.Expression);

                if (ast == null)
                {
                    return;
                }

                Interpreter.Interpret(ast);
#if APHID_FRAME_ADD_DATA || APHID_FRAME_CATCH_POP
            }
#endif
#if APHID_FRAME_ADD_DATA || APHID_FRAME_CATCH_POP
#if APHID_FRAME_ADD_DATA
                catch (Exception e)
#else
                catch
#endif
                {
                    if (e.Source != AphidName.DebugInterpreter)
                    {
                        e.Source = AphidName.DebugInterpreter;

#if APHID_FRAME_CATCH_POP
                        Interpreter.PopQueuedFrames();
#endif

#if APHID_FRAME_ADD_DATA
                        e.Data.Add(AphidName.Interpreter, Interpreter);
                        e.Data.Add(AphidName.FramesKey, Interpreter.GetRawStackTrace());
#endif
                    }

                    throw;
                }
#endif
            }
            catch (AphidRuntimeException e)
            {
                msg = AphidCli.Redirect(() => AphidCli.DumpException(e, Interpreter));
            }
            catch (AphidParserException e)
            {
                msg = AphidCli.Redirect(() => AphidCli.DumpException(e, vm.Expression));
            }
            catch (Exception e)
            {
                msg = AphidCli.Redirect(() => AphidCli.DumpException(e, Interpreter));
            }

            await DumpFormatAsync(vm, msg);

            //    )
            //CodeViewer.Run(
            //    x => vm.Value = x,
            //    )
        }
예제 #13
0
 public void WriteLineHighlightedTest01(string text, bool escapeStyles)
 {
     AphidCli.WriteLineHighlighted(text, escapeStyles);
     // TODO: add assertions to method AphidCliTest.WriteLineHighlightedTest01(String, Boolean)
 }
예제 #14
0
 public void DumpStackTraceTest02(AphidInterpreter interpreter, AphidFrame[] trace)
 {
     AphidCli.DumpStackTrace(interpreter, trace);
     // TODO: add assertions to method AphidCliTest.DumpStackTraceTest02(AphidInterpreter, AphidFrame[])
 }
예제 #15
0
파일: Program.cs 프로젝트: 5l1v3r1/Aphid
        private static void Main(string[] argv)
        {
            //var bytes = Utf8Json.JsonSerializer.Serialize(new Request(123, "foo", "bar") { seq = 1 });

            //var msg = Utf8Json.JsonSerializer.Serialize(Utf8Json.JsonSerializer.Deserialize<ProtocolMessage>(bytes)).GetString();
            //Console.WriteLine(msg);
            //Environment.SetEnvironmentVariable("mono_debug_logfile", $@"d:\staging\vsc.{Guid.NewGuid()}.log");

            string id;

            if (!argv.Contains("--child"))
            {
#if LOG_JSON
                var file   = File.Create("d:\\staging\\vscJson.log");
                var writer = new StreamWriter(file);
#endif
                id = Guid.NewGuid().ToString();

                var proc = Process.Start(
                    typeof(Program).Assembly.Location,
                    string.Format("--child {0}", id));

                var t = new System.Threading.Thread(() =>
                {
                    var stdOutPipe = new NamedPipeClientStream(GetNamedPort(id, true));
                    stdOutPipe.Connect();
                    var stdOut = Console.OpenStandardOutput();
                    var buffer = new byte[0x1000];
                    int read;

                    while (!proc.HasExited && stdOutPipe.IsConnected)
                    {
                        if ((read = stdOutPipe.Read(buffer, 0, buffer.Length)) > 0)
                        {
#if LOG_JSON
                            if (read > 0)
                            {
                                using (new CrossProcessLock("AphidVSCDebug"))
                                {
                                    writer.WriteLine("STD Out");
                                    file.Write(buffer, 0, read);
                                    writer.WriteLine();
                                }
                            }
#endif
                            stdOut.Write(buffer, 0, read);
                            stdOut.Flush();
                        }
                    }
                })
                {
                    IsBackground = true
                };

                t.Start();

                var t2 = new System.Threading.Thread(() =>
                {
                    var stdInPipe = new NamedPipeClientStream(GetNamedPort(id, false));
                    stdInPipe.Connect();
                    var stdIn  = Console.OpenStandardInput();
                    var buffer = new byte[0x1000];
                    int read;

                    while (!proc.HasExited && stdInPipe.IsConnected)
                    {
                        if ((read = stdIn.Read(buffer, 0, buffer.Length)) > 0)
                        {
#if LOG_JSON
                            if (read > 0)
                            {
                                using (new CrossProcessLock("AphidVSCDebug"))
                                {
                                    writer.WriteLine("STD In");
                                    file.Write(buffer, 0, read);
                                    writer.WriteLine();
                                }
                            }
#endif

                            stdInPipe.Write(buffer, 0, read);
                            stdInPipe.Flush();
                        }
                    }
                })
                {
                    IsBackground = true
                };

                t2.Start();

                foreach (var x in new[] { t, t2 })
                {
                    x.Join();
                }
            }
            else
            {
                //Debugger.Launch();
                if (!Debugger.IsAttached)
                {
                    try
                    {
                        try
                        {
                            StartServer(argv);
                        }
                        catch (AphidLoadScriptException e)
                        {
                            AphidCli.DumpException(e, e.Interpreter);
                        }
                        catch (AphidParserException e)
                        {
                            AphidCli.DumpException(e, null);
                        }
                        catch (AphidRuntimeException e)
                        {
                            AphidCli.DumpException(e, e.Interpreter);
                        }
                    }
                    catch (Exception e2)
                    {
                        Cli.WriteErrorMessage("Internal exception: {0}", e2);
                    }

                    Console.WriteLine("Press enter to continue...");

                    while (Console.ReadKey(true).Key != ConsoleKey.Enter)
                    {
                    }
                }
                else
                {
                    StartServer(argv);
                }
            }
        }
예제 #16
0
 public void DumpStackTraceTest01(AphidInterpreter interpreter)
 {
     AphidCli.DumpStackTrace(interpreter);
     // TODO: add assertions to method AphidCliTest.DumpStackTraceTest01(AphidInterpreter)
 }
예제 #17
0
 public void DumpScopeTest01(Exception exception, AphidInterpreter interpreter)
 {
     AphidCli.DumpScope(exception, interpreter);
     // TODO: add assertions to method AphidCliTest.DumpScopeTest01(AphidObject, AphidInterpreter)
 }
예제 #18
0
 public void SafeWriteSubheaderTest(string text)
 {
     AphidCli.SafeWriteSubheader(text);
     // TODO: add assertions to method AphidCliTest.SafeWriteSubheaderTest(String)
 }
예제 #19
0
 public void DumpStackTraceTest(AphidInterpreter interpreter, Exception exception)
 {
     AphidCli.DumpStackTrace(interpreter, exception);
     // TODO: add assertions to method AphidCliTest.DumpStackTraceTest(AphidInterpreter, Exception)
 }
예제 #20
0
 public void WriteErrorMessageTest(string format, object[] arg)
 {
     AphidCli.WriteErrorMessage(format, arg);
     // TODO: add assertions to method AphidCliTest.WriteErrorMessageTest(String, Object[])
 }
예제 #21
0
파일: Program.cs 프로젝트: 5l1v3r1/Aphid
        private static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                DisplayDirections();
            }
            else if (!File.Exists(args[0]))
            {
                Console.WriteLine("Could not find parser script '{0}'", args[0]);
                Environment.Exit(1);
            }
            else if (args[1].Any(Path.GetInvalidPathChars().Contains))
            {
                Console.WriteLine("Invalid output file '{0}'", args[1]);
                Environment.Exit(2);
            }

            // Todo fix critical bug where include dates are not checked
            var scriptInfo = new FileInfo(args[0]);
            var outputInfo = new FileInfo(args[1]);

            //if (scriptInfo.LastWriteTimeUtc < outputInfo.LastWriteTimeUtc)
            //{
            //    Console.WriteLine("C# output update to date, not regenerating");
            //    Environment.Exit(0);
            //}

            var dir  = Path.GetDirectoryName(Path.GetFullPath(args[0]));
            var code = File.ReadAllText(args[0]);

            if (!Debugger.IsAttached)
            {
                try
                {
                    GenerateParser(code, dir, args[1]);
                    Environment.Exit(0);
                }
                catch (AphidParserException exception)
                {
                    AphidCli.DumpException(exception, code);
                }
                catch (AphidLoadScriptException exception)
                {
                    AphidCli.DumpException(exception, exception.Interpreter);
                }
                catch (AphidRuntimeException exception)
                {
                    AphidCli.DumpException(exception, exception.Interpreter);
                }
                catch (Exception exception)
                {
                    AphidCli.DumpException(exception, null);
                }

                Environment.Exit(0xbad);
            }
            else
            {
                GenerateParser(code, dir, args[1]);
            }
        }
예제 #22
0
 public void WriteLineHighlightedTest(string text)
 {
     AphidCli.WriteLineHighlighted(text);
     // TODO: add assertions to method AphidCliTest.WriteLineHighlightedTest(String)
 }
예제 #23
0
        private static void WriteLog(
            Exception exception,
            AphidInterpreter interpreter,
            int number,
            string dumpFile,
            StringBuilder sb)
        {
            var tag = number >= 0 ? $"{number.ToString()}." : "";
            AphidInterpreter exInterpreter = null;

            if (exception is AphidLoadScriptException ale)
            {
                exInterpreter = ale.Interpreter;
                AphidCli.DumpException(ale, ale.Interpreter);
            }
            else if (exception is AphidRuntimeException are)
            {
                exInterpreter = are.Interpreter;
                AphidCli.DumpException(are, are.Interpreter);
            }
            else
            {
                AphidCli.DumpException(exception, null);
            }

            var i = exInterpreter ?? interpreter;

            if (dumpFile != null && i != null)
            {
                File.WriteAllText(
                    Path.ChangeExtension(dumpFile, $"{tag}alxd"),
                    new AphidSerializer(i).Serialize(i.CurrentScope));
            }

            if (dumpFile != null)
            {
                var logFile = Path.ChangeExtension(dumpFile, $"{tag}log");

                using (var writer = new StreamWriter(File.Create(logFile)))
                {
                    writer.AutoFlush = true;
                    writer.WriteLine(sb.ToString().Trim());
                    writer.WriteLine();

                    void writeValue(string name, Func <object> getValue) =>
                    TryWriteValue(writer, name, getValue);

                    writeValue("Command Line", () => Environment.CommandLine);

                    writeValue(
                        "Command Line Arguments",
                        () => Environment.GetCommandLineArgs().JoinLines());

                    writeValue("Current Directory", () => Environment.CurrentDirectory);

                    writeValue("Machine Name", () => Environment.MachineName);
                    writeValue("OS Version", () => Environment.OSVersion);
                    writeValue("64-bit OS", () => Environment.Is64BitOperatingSystem);
                    writeValue("64-bit Process", () => Environment.Is64BitProcess);
                    writeValue("CLR Version", () => Environment.Version);
                    writeValue("Processor Count", () => Environment.ProcessorCount);
                    writeValue("User", () => Environment.UserName);
                    writeValue("Domain", () => Environment.UserDomainName);

                    writeValue(
                        "Environment Variables",
                        () => Environment
                        .GetEnvironmentVariables()
                        .Cast <DictionaryEntry>()
                        .Select(x => string.Format("{0}: {1}", x.Key, x.Value))
                        .JoinLines());

                    writeValue(
                        "Assemblies",
                        () => AppDomain.CurrentDomain
                        .GetAssemblies()
                        .Select(x => string.Format(
                                    "{0}\r\n{1}",
                                    x,
                                    !x.IsDynamic ? x.Location : "Dynamic Assembly"))
                        .JoinLines());

                    WalkExceptions(exception, writer);
                }
            }
        }
예제 #24
0
        private static void RunScript(string[] args)
        {
            if (!File.Exists(args[0]))
            {
                Console.WriteLine("Could not find {0}", args[0]);
                Environment.Exit(1);
            }

            var ext            = Path.GetExtension(args[0]).ToLower();
            var isTextDocument = ext == ".alxt";
            var file           = Path.GetFullPath(args[0]);
            var interpreter    = new AphidInterpreter();

            interpreter.SetScriptFilename(file);
            EnvironmentLibrary.SetEnvArgs(true);
            var result = true;

#if !APHID_DEBUGGING_ENABLED
            if (AphidConfig.Current.ScriptCaching)
            {
                var cache = new AphidByteCodeCache(interpreter.Loader.SearchPaths.ToArray())
                {
                    DisableConstantFolding = false,
                    InlineScripts          = true,
                };

                if (AphidErrorHandling.HandleErrors)
                {
                    result = AphidCli.TryAction(
                        interpreter,
                        () => AphidScript.Read(file),
                        () => interpreter.Interpret(cache.Read(file)),
                        allowErrorReporting: true);
                }
                else
                {
                    interpreter.Interpret(cache.Read(file));
                }
            }
            else
            {
#endif
            var code = AphidScript.Read(file);

            if (AphidErrorHandling.HandleErrors)
            {
                result = AphidCli.TryAction(
                    interpreter,
                    code,
                    () => interpreter.Interpret(code, file, isTextDocument),
                    allowErrorReporting: true);
            }
            else
            {
                interpreter.Interpret(code, file, isTextDocument);
            }

            if (interpreter.CurrentScope.ResolveBool(AphidName.OpenRepl))
            {
                new AphidRepl {
                    Interpreter = interpreter
                }.Run();
            }
#if !APHID_DEBUGGING_ENABLED
        }
#endif
            if (!result)
            {
                Environment.Exit(0xbad5230);
            }
        }