public virtual string Compile(XmlNode node, int indent = 0)
        {
            string result = "";

            foreach (XmlNode child in node.ChildNodes)
            {
                INodeCompiler compiler = CompilerFactory.Create(child);
                result += compiler.Compile(child, indent);
            }
            return(result);
        }
        public string Compile(XmlNode node, int indent = 0)
        {
            string indentString = new string('\t', indent);
            string result       = indentString + "else\n";

            XmlNode       body     = node.SelectSingleNode("body");
            INodeCompiler compiler = CompilerFactory.Create(body);

            result += compiler.Compile(body, indent + 1);

            return(result);
        }
Beispiel #3
0
        protected override string ParsePath()
        {
            using (Stream source = OpenStream()) {
                XcstCompiler compiler = CompilerFactory.CreateCompiler();

                ConfigureCompiler(compiler);

                _result = compiler.Compile(source, baseUri: this.PhysicalPath);

                return(_result.Language);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Execute the build requests.
        /// </summary>
        /// <param name="buildRequest"></param>
        public void ProcessBuildRequest(BuildRequestDO buildRequest)
        {
            ICompilerService compiler = CompilerFactory.GetCompiler(buildRequest.Language);

            if (compiler != null)
            {
                compiler.Compile(buildRequest);
            }
            else
            {
                Console.WriteLine("Compiler Language not supported.");
            }
        }
Beispiel #5
0
        private SourceCodeService CreateServiceWithRealCompiler(IFeatureToggle featureToggle = null)
        {
            ILogger logger = CreateLogger();
            ISourceFileGeneratorProvider sourceFileGeneratorProvider = CreateSourceFileGeneratorProvider();

            sourceFileGeneratorProvider
            .CreateSourceFileGenerator(Arg.Is(TargetLanguage.VisualBasic))
            .Returns(new VisualBasicSourceFileGenerator(logger));

            VisualBasicCompiler vbCompiler      = new VisualBasicCompiler(logger);
            CompilerFactory     compilerFactory = new CompilerFactory(null, vbCompiler);

            return(CreateSourceCodeService(sourceFileGeneratorProvider: sourceFileGeneratorProvider, calculationsRepository: Substitute.For <ICalculationsRepository>(), logger: logger, compilerFactory: compilerFactory));
        }
Beispiel #6
0
        public ProjectMonitor(ValidationEventHandler validationEventHandler, Action <ICompilierOptions, string> beforeCompilationHandler, Action <ProgressToken, string> afterCompiliationHandler, FileSystemWatcher fileSystemWatcher)
        {
            _watcher = fileSystemWatcher ?? throw new ArgumentNullException(nameof(fileSystemWatcher));

            _watcher.Created += OnFileWasModified;
            _watcher.Changed += OnFileWasModified;
            _watcher.Renamed += OnFileWasModified;

            _validationHandler      = validationEventHandler;
            _preCompilationHandler  = beforeCompilationHandler;
            _postCompilationHandler = afterCompiliationHandler;

            _factory = new CompilerFactory();
        }
Beispiel #7
0
        public string Compile(XmlNode node, int indent = 0)
        {
            string        indentString = new string('\t', indent);
            XmlNode       checks       = node.SelectSingleNode("checks");
            INodeCompiler compiler     = CompilerFactory.Create(checks);
            string        result       = indentString + "if (" + compiler.Compile(checks) + ") then\n";

            XmlNode body = node.SelectSingleNode("body");

            compiler = CompilerFactory.Create(body);
            result  += compiler.Compile(body, indent + 1);

            return(result);
        }
        public CompilationTask(ScriptAssembly[] scriptAssemblies,
                               ScriptAssembly[] codeGenAssemblies,
                               string buildOutputDirectory,
                               object context,
                               EditorScriptCompilationOptions options,
                               CompilationTaskOptions compilationTaskOptions,
                               int maxConcurrentCompilers,
                               IILPostProcessing ilPostProcessing,
                               CompilerFactory compilerFactory)
        {
            this.scriptAssemblies = scriptAssemblies;
            pendingAssemblies     = new List <ScriptAssembly>();

            if (codeGenAssemblies != null)
            {
                this.codeGenAssemblies = new HashSet <ScriptAssembly>(codeGenAssemblies);
            }
            else
            {
                this.codeGenAssemblies = new HashSet <ScriptAssembly>();
            }

            // Try to queue codegen assemblies for compilation first,
            // so they get compiled as soon as possible.
            if (codeGenAssemblies != null && codeGenAssemblies.Count() > 0)
            {
                pendingAssemblies.AddRange(codeGenAssemblies);
            }

            pendingAssemblies.AddRange(scriptAssemblies);

            CompileErrors             = false;
            this.buildOutputDirectory = buildOutputDirectory;
            this.context = context;
            this.options = options;
            this.compilationTaskOptions = compilationTaskOptions;
            this.maxConcurrentCompilers = maxConcurrentCompilers;
            this.ilPostProcessing       = ilPostProcessing;
            this.compilerFactory        = compilerFactory;

            try
            {
                logWriter = File.CreateText(LogFilePath);
            }
            catch (Exception e)
            {
                Console.WriteLine($"Could not create text file {LogFilePath}\n{e}");
            }
        }
Beispiel #9
0
        public string Compile(XmlNode node, int indent = 0)
        {
            string result = "";

            foreach (XmlNode child in node.ChildNodes)
            {
                INodeCompiler compiler = CompilerFactory.Create(child);
                if (result != "")
                {
                    result += " " + child.Attributes["operator"].InnerText + " ";
                }
                result += compiler.Compile(child);
            }
            return(result);
        }
        public string Compile(XmlNode node, int indent = 0)
        {
            string result = "";

            foreach (XmlNode child in node.ChildNodes)
            {
                INodeCompiler compiler = CompilerFactory.Create(child);
                result += compiler.Compile(child) + ",";
            }

            if (node.ChildNodes.Count > 0)
            {
                return(Utils.ReplaceLastOccurrence(result, ",", ""));;
            }
            return(result);
        }
Beispiel #11
0
        public string Compile(XmlNode node, int indent = 0)
        {
            string indentString = new string('\t', indent);
            string result       = String.Format("{0}{1}(", indentString, node.Attributes["function"].InnerText);

            foreach (XmlNode child in node.ChildNodes)
            {
                INodeCompiler compiler = CompilerFactory.Create(child);
                result += compiler.Compile(child) + ", ";
            }

            if (node.ChildNodes.Count > 0)
            {
                return(Utils.ReplaceLastOccurrence(result, ", ", "") + ")\n");
            }
            return(result + ")\n");
        }
        static void TestNew()
        {
            CompilerFactory compilerFactory = new CompilerFactory(
                new CompilerConfiguration()
                .AddTempDirectory(@"C:\Temp\SharpKit")
                .Plugins(
                    new SharpKitPluginCollection()
                    .Add("Neptuo.SharpKit.Exugin.ExuginPlugin, Neptuo.SharpKit.Exugin")
                    )
                .AddReferences(
                    new CompilerReferenceCollection()
                    .AddDirectory(Environment.CurrentDirectory)
                    .AddAssembly("SharpKit.JavaScript.dll")
                    .AddAssembly("SharpKit.Html.dll")
                    .AddAssembly("SharpKit.jQuery.dll")
                    )
                );

            ISharpKitCompiler compiler = compilerFactory.CreateSharpKit();


            string          javascriptFilePath = Path.Combine(Environment.CurrentDirectory, "TestClass.js");
            ICompilerResult result             = compiler.FromSourceFile(@"D:\Development\Neptuo\Common\test\TestConsole\SharpKitCompilers\TestClass.cs", javascriptFilePath);

            if (result.IsSuccess)
            {
                Console.WriteLine("Successfully compiled to javascript...");
                Console.WriteLine(File.ReadAllText(javascriptFilePath));
            }
            else
            {
                Console.WriteLine("Error compiling to javascript...");

                foreach (IErrorInfo errorInfo in result.Errors)
                {
                    Console.WriteLine(
                        "{0}:{1} -> {2}",
                        errorInfo.LineNumber,
                        errorInfo.ColumnIndex,
                        errorInfo.ErrorText
                        );
                }
            }
        }
Beispiel #13
0
 public CompilationTask(ScriptAssembly[] scriptAssemblies,
                        string buildOutputDirectory,
                        object context,
                        EditorScriptCompilationOptions options,
                        CompilationTaskOptions compilationTaskOptions,
                        int maxConcurrentCompilers,
                        IILPostProcessing ilPostProcessing,
                        CompilerFactory compilerFactory)
 {
     pendingAssemblies         = new HashSet <ScriptAssembly>(scriptAssemblies);
     CompileErrors             = false;
     this.buildOutputDirectory = buildOutputDirectory;
     this.context = context;
     this.options = options;
     this.compilationTaskOptions = compilationTaskOptions;
     this.maxConcurrentCompilers = maxConcurrentCompilers;
     this.ilPostProcessing       = ilPostProcessing;
     this.compilerFactory        = compilerFactory;
 }
Beispiel #14
0
        private static void Main()
        {
            var program = new Program();

            Console.WriteLine("Enter filename with extension");
            program._sourceName = Console.ReadLine();
            var loading = program.LoadFile();

            if (loading)
            {
                var factory = new CompilerFactory();
                factory.Compile(CompilerMode.CSharp, program._codeText, program._sourceName);
            }
            if (!IsDebug)
            {
                return;
            }
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setUp() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SetUp()
        {
            GraphDatabaseQueryService cypherService = new GraphDatabaseCypherService(this.Database.GraphDatabaseAPI);

            _compilerFactory      = mock(typeof(CompilerFactory));
            _transactionalContext = mock(typeof(TransactionalContext));
            KernelStatement kernelStatement = mock(typeof(KernelStatement));

            _executor       = mock(typeof(SnapshotExecutionEngine.ParametrizedQueryExecutor));
            _versionContext = mock(typeof(VersionContext));

            _executionEngine = CreateExecutionEngine(cypherService);
            when(kernelStatement.VersionContext).thenReturn(_versionContext);
            when(_transactionalContext.statement()).thenReturn(kernelStatement);
            Result          result     = mock(typeof(Result));
            QueryStatistics statistics = mock(typeof(QueryStatistics));

            when(result.QueryStatistics).thenReturn(statistics);
            when(_executor.execute(any(), anyMap(), any())).thenReturn(result);
        }
Beispiel #16
0
        public string Compile(XmlNode node, int indent = 0)
        {
            string result       = "";
            string indentString = new string('\t', indent);

            result += String.Format("{0}for {1},{2} in pairs({3}) do\n",
                                    indentString,
                                    node.Attributes["key"].InnerText,
                                    node.Attributes["value"].InnerText,
                                    node.Attributes["variable"].InnerText
                                    );

            foreach (XmlNode child in node.ChildNodes)
            {
                INodeCompiler compiler = CompilerFactory.Create(child);
                result += compiler.Compile(child, indent + 1);
            }

            result += indentString + "end\n";
            return(result);
        }
Beispiel #17
0
        public string Compile(XmlNode node, int indent = 0)
        {
            string result       = "";
            string indentString = new string('\t', indent);

            result += String.Format("{0}for {1} = {2}, {3}, {4}  do\n",
                                    indentString,
                                    node.Attributes["variable"].InnerText,
                                    node.Attributes["start"].InnerText,
                                    node.Attributes["end"].InnerText,
                                    (node.Attributes["increments"] != null) ? node.Attributes["increments"].InnerText : "1"
                                    );

            foreach (XmlNode child in node.ChildNodes)
            {
                INodeCompiler compiler = CompilerFactory.Create(child);
                result += compiler.Compile(child, indent + 1);
            }

            result += indentString + "end\n";
            return(result);
        }
Beispiel #18
0
        public string Compile(XmlNode node, int indent = 0)
        {
            string indentString = new string('\t', indent);
            var    children     = node.ChildNodes;

            if (children.Count > 0 && children[0].NodeType != XmlNodeType.Text)
            {
                string result = "\n";

                foreach (XmlNode child in children)
                {
                    INodeCompiler compiler = CompilerFactory.Create(child);
                    result += compiler.Compile(child, indent + 1);
                }

                return(result);
            }
            else
            {
                return(indentString + node.InnerText);
            }
        }
        public override Token compile(Token currentToken, Token lastToken, NodeLinkedList nodeLinkedList, Node before)
        {
            string variableName = currentToken.value; //left hand value

            currentToken = currentToken.nextToken.nextToken;

            Node current = before;

            Compiler rightCompiled = CompilerFactory.getInstance().getCompiler(currentToken); //right hand value

            currentToken = rightCompiled.compile(currentToken, lastToken, nodeLinkedList, before);

            if (before == null)
            {
                nodeLinkedList.addLast(new NodeDirectFunction("ReturnToVariable", variableName));
            }
            else
            {
                current = current.insertPrevious(new NodeDirectFunction("ReturnToVariable", variableName));
            }

            return(currentToken.nextToken);
        }
Beispiel #20
0
        /// <summary>
        /// 评测此任务
        /// </summary>
        /// <returns>评测结果</returns>
        public JudgeResult Judge()
        {
            //判题结果
            JudgeResult result = new JudgeResult
            {
                SubmitID    = JudgeTask.SubmitID,
                ProblemID   = JudgeTask.ProblemID,
                Author      = JudgeTask.Author,
                JudgeDetail = "",
                MemoryCost  = 0,
                TimeCost    = 0,
                PassRate    = 0,
                ResultCode  = JudgeResultCode.Accepted
            };

            //正则恶意代码检查
            if (!CodeChecker.Singleton.CheckCode(JudgeTask.SourceCode, JudgeTask.Language, out string unsafeCode, out int line))
            {
                result.ResultCode   = JudgeResultCode.CompileError;
                result.JudgeDetail  = "Include unsafe code, please remove them!";
                result.JudgeDetail += "\r\n";
                result.JudgeDetail += "line " + line + ": " + unsafeCode;
                return(result);
            }

            //创建临时目录
            if (!Directory.Exists(JudgeTask.TempJudgeDirectory))
            {
                Directory.CreateDirectory(JudgeTask.TempJudgeDirectory);
            }

            //写出源代码
            string sourceFileName = JudgeTask.TempJudgeDirectory + Path.DirectorySeparatorChar + JudgeTask.LangConfig.SourceCodeFileName;

            File.WriteAllText(sourceFileName, JudgeTask.SourceCode);

            //编译代码
            if (JudgeTask.LangConfig.NeedCompile)
            {
                ICompiler compiler = CompilerFactory.Create(JudgeTask);
                //使用分配的独立处理器核心
                compiler.ProcessorAffinity = _affinity.Affinity;

                string compileRes = compiler.Compile(JudgeTask.LangConfig.CompilerArgs);

                //检查是否有编译错误(compileRes不为空则代表有错误)
                if (!string.IsNullOrEmpty(compileRes))
                {
                    result.JudgeDetail = compileRes.Replace(JudgeTask.TempJudgeDirectory, "");//去除路径信息
                    result.ResultCode  = JudgeResultCode.CompileError;
                    return(result);
                }
            }


            //创建单例Judger
            ISingleJudger judger = SingleJudgerFactory.Create(JudgeTask);

            judger.ProcessorAffinity = _affinity.Affinity;

            //获取所有测试点文件名
            Tuple <string, string>[] dataFiles = TestDataManager.GetTestDataFilesName(JudgeTask.ProblemID);
            if (dataFiles.Length == 0)//无测试数据
            {
                result.ResultCode  = JudgeResultCode.JudgeFailed;
                result.JudgeDetail = "No test data.";
                return(result);
            }

            int acceptedCasesCount = 0;//通过的测试点数

            for (int i = 0; i < dataFiles.Length; i++)
            {
                try
                {
                    TestDataManager.GetTestData(JudgeTask.ProblemID, dataFiles[i].Item1, dataFiles[i].Item2, out string input, out string output); //读入测试数据

                    SingleJudgeResult singleRes = judger.Judge(input, output);                                                                     //测试此测试点

                    //计算有时间补偿的总时间
                    result.TimeCost   = Math.Max(result.TimeCost, (int)(singleRes.TimeCost * JudgeTask.LangConfig.TimeCompensation));
                    result.MemoryCost = Math.Max(result.MemoryCost, singleRes.MemoryCost);

                    if (singleRes.ResultCode == JudgeResultCode.Accepted)
                    {
                        acceptedCasesCount++;
                    }
                    else
                    {
                        result.ResultCode  = singleRes.ResultCode;
                        result.JudgeDetail = singleRes.JudgeDetail;
                        break;
                    }
                }
                catch (Exception e)
                {
                    result.ResultCode  = JudgeResultCode.JudgeFailed;
                    result.JudgeDetail = e.ToString();
                    break;
                }
            }

            //去除目录信息
            result.JudgeDetail = result.JudgeDetail.Replace(JudgeTask.TempJudgeDirectory, "");

            //通过率
            result.PassRate = (double)acceptedCasesCount / dataFiles.Length;

            return(result);
        }
Beispiel #21
0
 static Compiler()
 {
     CompilerFactory.Initialize(f => new BytecodeCompiler(f));
 }
Beispiel #22
0
 public CompilersTests()
 {
     compilers = new CompilerFactory(new WindsorContainer());
     TestUtils.ClearExeDirectory();
 }
Beispiel #23
0
        /// <summary>
        /// Creates an execution engine around the give graph database </summary>
        /// <param name="queryService"> The database to wrap </param>
        /// <param name="logProvider"> A <seealso cref="LogProvider"/> for cypher-statements </param>
        public ExecutionEngine(GraphDatabaseQueryService queryService, LogProvider logProvider, CompilerFactory compilerFactory)
        {
            DependencyResolver  resolver            = queryService.DependencyResolver;
            Monitors            monitors            = resolver.ResolveDependency(typeof(Monitors));
            CacheTracer         cacheTracer         = new MonitoringCacheTracer(monitors.NewMonitor(typeof(StringCacheMonitor)));
            Config              config              = resolver.ResolveDependency(typeof(Config));
            CypherConfiguration cypherConfiguration = CypherConfiguration.fromConfig(config);
            CompilationTracer   tracer              = new TimingCompilationTracer(monitors.NewMonitor(typeof(TimingCompilationTracer.EventListener)));

            _inner = new [email protected](queryService, monitors, tracer, cacheTracer, cypherConfiguration, compilerFactory, logProvider, Clock.systemUTC());
        }
Beispiel #24
0
 internal SnapshotExecutionEngine(GraphDatabaseQueryService queryService, Config config, LogProvider logProvider, CompilerFactory compilerFactory) : base(queryService, logProvider, compilerFactory)
 {
     this._maxQueryExecutionAttempts = config.Get(GraphDatabaseSettings.snapshot_query_retries);
 }
 internal TestSnapshotExecutionEngine(SnapshotExecutionEngineTest outerInstance, GraphDatabaseQueryService queryService, Config config, LogProvider logProvider, CompilerFactory compatibilityFactory) : base(queryService, config, logProvider, compatibilityFactory)
 {
     this._outerInstance = outerInstance;
 }