Esempio n. 1
0
        public string GetScriptAssembly()
        {
            if (CompilerType == null)
            {
                return(null);
            }

            var papyrusGen = new PapyrusGen(new CommonTreeNodeStream(CompilerType.GetAst())
            {
                TokenStream = CompilerType.GetTokenStream()
            });

            using (var manifestResourceStream = papyrusGen.GetType().Assembly.GetManifestResourceStream("PCompiler.PapyrusAssembly.stg"))
            {
                var templateGroup = new StringTemplateGroup(new StreamReader(manifestResourceStream));
#if SKYRIM
                papyrusGen.TemplateLib = templateGroup;
#else
                papyrusGen.TemplateGroup = templateGroup;
#endif

                papyrusGen.AsDynamic().KnownUserFlags = _program.FlagsFile.NativeFlagsDict;
                var template = papyrusGen.script(_filePath, CompilerType).Template;
                return(template.ToString());
            }
        }
Esempio n. 2
0
        protected virtual CompileResult Compile(
            CompilerType compilerType,
            string compilerPath,
            string compilerArguments,
            string submissionFilePath,
            bool useWorkingDirectoryForProcess = false)
        {
            if (compilerType == CompilerType.None)
            {
                return(new CompileResult(true, null)
                {
                    OutputFile = submissionFilePath
                });
            }

            if (!File.Exists(compilerPath))
            {
                throw new ArgumentException($"Compiler not found in: {compilerPath}", nameof(compilerPath));
            }

            var compiler       = Compiler.CreateCompiler(compilerType, this.Type);
            var compilerResult = compiler.Compile(compilerPath, submissionFilePath, compilerArguments, useWorkingDirectoryForProcess);

            return(compilerResult);
        }
Esempio n. 3
0
 public SolutionManager(string program, string userId, int taskId, CompilerType compilerType)
 {
     this.program = program;
     this.userId = userId;
     this.taskId = taskId;
     this.compilerType = compilerType;
 }
Esempio n. 4
0
 public SolutionManager(byte[] file, string userId, int taskId, CompilerType compilerType)
 {
     program = Encoding.UTF8.GetString(file); //zmiana bitów na string
     this.userId = userId;
     this.taskId = taskId;
     this.compilerType = compilerType;
 }
Esempio n. 5
0
        public void NamedScope_WithNull(CompilerType compilerType)
        {
            var container = new StashboxContainer(c => c.WithCompiler(compilerType))
                            .Register <Test2>(config => config.InNamedScope("A"));

            Assert.Null(container.BeginScope("A").Resolve <Test2>(nullResultAllowed: true));
        }
Esempio n. 6
0
        public void DecoratorTests_Simple_Enumerable(CompilerType compilerType)
        {
            using var container = new StashboxContainer(c => c.WithCompiler(compilerType));
            container.Register <ITest1, Test1>();
            container.Register <ITest1, Test11>();
            container.RegisterDecorator <ITest1, TestDecorator1>();
            var test = container.Resolve <IEnumerable <ITest1> >();

            Assert.NotNull(test);
            Assert.IsAssignableFrom <IEnumerable <ITest1> >(test);

            var arr = test.ToArray();

            Assert.NotNull(arr[0]);
            Assert.IsType <TestDecorator1>(arr[0]);

            Assert.NotNull(arr[1]);
            Assert.IsType <TestDecorator1>(arr[1]);

            Assert.NotNull(arr[0].Test);
            Assert.IsType <Test1>(arr[0].Test);

            Assert.NotNull(arr[1].Test);
            Assert.IsType <Test11>(arr[1].Test);
        }
        private CompileResult CompileSourceFiles(
            CompilerType compilerType,
            string compilerPath,
            string compilerArguments,
            IEnumerable <string> sourceFilesToCompile)
        {
            var compilerResult         = new CompileResult(false, null);
            var compilerCommentBuilder = new StringBuilder();

            foreach (var sourceFile in sourceFilesToCompile)
            {
                compilerResult = this.Compile(compilerType, compilerPath, compilerArguments, sourceFile);

                compilerCommentBuilder.AppendLine(compilerResult.CompilerComment);

                if (!compilerResult.IsCompiledSuccessfully)
                {
                    break; // The compilation of other files is not necessary
                }
            }

            var compilerComment = compilerCommentBuilder.ToString().Trim();

            compilerResult.CompilerComment = compilerComment.Length > 0 ? compilerComment : null;

            return(compilerResult);
        }
Esempio n. 8
0
 public SolutionManager(string program, string userId, int taskId, CompilerType compilerType)
 {
     this.program      = program;
     this.userId       = userId;
     this.taskId       = taskId;
     this.compilerType = compilerType;
 }
Esempio n. 9
0
        public void Ensure_expression_built_correctly_singleton_dispose_simple(CompilerType compilerType)
        {
            C.Counter = 0;
            F inst = null;

            {
                using var container = new StashboxContainer(c =>
                {
                    c.WithDisposableTransientTracking().WithCompiler(compilerType);
                })
                                      .Register <F>(c => c.WithScopedLifetime())
                                      .Register <C>(c => c.WithSingletonLifetime());


                {
                    using var scope = container.BeginScope();
                    inst            = scope.Resolve <F>();
                }

                Assert.True(inst.Disposed);
                Assert.False(inst.C.Disposed);
            }

            Assert.True(inst.C.Disposed);

            Assert.Equal(1, C.Counter);
        }
 public GradleProjectGenerator(String SolutionName, Project Project, List <ProjectReference> ProjectReferences, PathString InputDirectory, PathString OutputDirectory, PathString SolutionOutputDirectory, String BuildGradleTemplateText, OperatingSystemType HostOperatingSystem, ArchitectureType HostArchitecture, OperatingSystemType TargetOperatingSystem, ArchitectureType?TargetArchitecture, ToolchainType Toolchain, CompilerType Compiler, CLibraryType CLibrary, CLibraryForm CLibraryForm, CppLibraryType CppLibrary, CppLibraryForm CppLibraryForm, ConfigurationType?ConfigurationType, PathString AndroidNdk)
 {
     this.SolutionName            = SolutionName;
     this.ProjectName             = Project.Name.Split(':').First();
     this.Project                 = Project;
     this.ProjectReferences       = ProjectReferences;
     this.InputDirectory          = InputDirectory.FullPath;
     this.OutputDirectory         = OutputDirectory.FullPath;
     this.SolutionOutputDirectory = SolutionOutputDirectory.FullPath;
     this.BuildGradleTemplateText = BuildGradleTemplateText;
     this.HostOperatingSystem     = HostOperatingSystem;
     this.HostArchitecture        = HostArchitecture;
     this.TargetOperatingSystem   = TargetOperatingSystem;
     this.TargetArchitecture      = TargetArchitecture;
     if (!TargetArchitecture.HasValue)
     {
         throw new NotSupportedException("ArchitectureTypeIsNull");
     }
     this.Toolchain         = Toolchain;
     this.Compiler          = Compiler;
     this.CLibrary          = CLibrary;
     this.CLibraryForm      = CLibraryForm;
     this.CppLibrary        = CppLibrary;
     this.CppLibraryForm    = CppLibraryForm;
     this.ConfigurationType = ConfigurationType;
     this.AndroidNdk        = AndroidNdk;
 }
Esempio n. 11
0
 public SolutionManager(byte[] file, string userId, int taskId, CompilerType compilerType)
 {
     program           = Encoding.UTF8.GetString(file); //zmiana bitów na string
     this.userId       = userId;
     this.taskId       = taskId;
     this.compilerType = compilerType;
 }
Esempio n. 12
0
        public static ICompiler CreateCompiler(CompilerType compilerType)
        {
            switch (compilerType)
            {
            case CompilerType.None:
                return(null);

            case CompilerType.CSharp:
                return(new CSharpCompiler());

            case CompilerType.CPlusPlusGcc:
                return(new CPlusPlusCompiler());

            case CompilerType.MsBuild:
                return(new MsBuildCompiler());

            case CompilerType.Java:
                return(new JavaCompiler());

            case CompilerType.JavaZip:
                return(new JavaZipCompiler());

            default:
                throw new ArgumentException("Unsupported compiler.");
            }
        }
Esempio n. 13
0
        public void NamedScope_Throws_ResolutionFailedException_Without_Scope(CompilerType compilerType)
        {
            var container = new StashboxContainer(c => c.WithCompiler(compilerType))
                            .Register <ITest, Test>(config => config.InNamedScope("A"));

            Assert.Throws <ResolutionFailedException>(() => container.Resolve <ITest>());
        }
Esempio n. 14
0
        public void Ensure_expression_built_correctly_scoped(CompilerType compilerType)
        {
            A.Counter = 0;
            B.Counter = 0;
            C.Counter = 0;
            D.Counter = 0;
            E.Counter = 0;
            F.Counter = 0;

            A inst = null;

            {
                using var container = new StashboxContainer(c => c.WithRuntimeCircularDependencyTracking()
                                                            .WithDisposableTransientTracking()
                                                            .WithCompiler(compilerType))
                                      .Register <A>(c => c.WithScopedLifetime())
                                      .Register <B>(c => c.WithScopedLifetime())
                                      .Register <D>(c => c.WithScopedLifetime())
                                      .Register <E>(c => c.WithScopedLifetime())
                                      .Register <F>(c => c.WithScopedLifetime())
                                      .Register <C>(c => c.WithFactory(r => new C()).WithScopedLifetime().WithoutDisposalTracking());

                using var scope = container.BeginScope();
                inst            = scope.Resolve <A>();

                Assert.NotNull(inst);
                Assert.NotNull(inst.B);
                Assert.NotNull(inst.C);
                Assert.NotNull(inst.B.D);
                Assert.NotNull(inst.B.C);
                Assert.NotNull(inst.B.D.C);
                Assert.NotNull(inst.B.D.E);
                Assert.NotNull(inst.B.D.F);
                Assert.NotNull(inst.B.D.E.C);
                Assert.NotNull(inst.B.D.F.C);

                Assert.Same(inst.C, inst.B.C);
                Assert.Same(inst.B.C, inst.B.D.C);
                Assert.Same(inst.B.D.C, inst.B.D.E.C);
                Assert.Same(inst.B.D.E.C, inst.B.D.F.C);
            }

            Assert.True(inst.Disposed);
            Assert.True(inst.B.Disposed);
            Assert.False(inst.C.Disposed);
            Assert.True(inst.B.D.Disposed);
            Assert.False(inst.B.C.Disposed);
            Assert.False(inst.B.D.C.Disposed);
            Assert.True(inst.B.D.E.Disposed);
            Assert.True(inst.B.D.F.Disposed);
            Assert.False(inst.B.D.E.C.Disposed);
            Assert.False(inst.B.D.F.C.Disposed);

            Assert.Equal(1, A.Counter);
            Assert.Equal(1, B.Counter);
            Assert.Equal(1, C.Counter);
            Assert.Equal(1, D.Counter);
            Assert.Equal(1, E.Counter);
            Assert.Equal(1, F.Counter);
        }
Esempio n. 15
0
        protected CompileResult Compile(CompilerType compilerType, string compilerPath, string compilerArguments, string submissionFilePath)
        {
            if (compilerType == CompilerType.None)
            {
                return(new CompileResult(true, null)
                {
                    OutputFile = submissionFilePath
                });
            }

            if (!File.Exists(compilerPath))
            {
                throw new ArgumentException(string.Format("Compiler not found in: {0}", compilerPath), "compilerPath");
            }

            ICompiler compiler       = Compiler.CreateCompiler(compilerType);
            var       compilerResult = compiler.Compile(compilerPath, submissionFilePath, compilerArguments);

            if (File.Exists(submissionFilePath))
            {
                File.Delete(submissionFilePath);
            }

            return(compilerResult);
        }
Esempio n. 16
0
        internal CompilerType GetCompilerInfoFromExtension(string extension, bool throwOnFail)
        {
            CompilerType compilerTypeInternal;

            this.EnsureCompilerCacheInit();
            object   obj2     = this._compilerExtensions[extension];
            Compiler compiler = obj2 as Compiler;

            if (compiler != null)
            {
                compilerTypeInternal = compiler.CompilerTypeInternal;
                this._compilerExtensions[extension] = compilerTypeInternal;
            }
            else
            {
                compilerTypeInternal = obj2 as CompilerType;
            }
            if ((compilerTypeInternal == null) && CodeDomProvider.IsDefinedExtension(extension))
            {
                CompilerInfo compilerInfo = CodeDomProvider.GetCompilerInfo(CodeDomProvider.GetLanguageFromExtension(extension));
                compilerTypeInternal = new CompilerType(compilerInfo.CodeDomProviderType, compilerInfo.CreateDefaultCompilerParameters());
                this._compilerExtensions[extension] = compilerTypeInternal;
            }
            if (compilerTypeInternal == null)
            {
                if (throwOnFail)
                {
                    throw new HttpException(System.Web.SR.GetString("Invalid_lang_extension", new object[] { extension }));
                }
                return(null);
            }
            compilerTypeInternal = compilerTypeInternal.Clone();
            compilerTypeInternal.CompilerParameters.IncludeDebugInformation = this.Debug;
            return(compilerTypeInternal);
        }
Esempio n. 17
0
        internal CompilerType GetCompilerInfoFromLanguage(string language)
        {
            CompilerType compilerTypeInternal;

            this.EnsureCompilerCacheInit();
            object   obj2     = this._compilerLanguages[language];
            Compiler compiler = obj2 as Compiler;

            if (compiler != null)
            {
                compilerTypeInternal = compiler.CompilerTypeInternal;
                this._compilerLanguages[language] = compilerTypeInternal;
            }
            else
            {
                compilerTypeInternal = obj2 as CompilerType;
            }
            if ((compilerTypeInternal == null) && CodeDomProvider.IsDefinedLanguage(language))
            {
                CompilerInfo compilerInfo = CodeDomProvider.GetCompilerInfo(language);
                compilerTypeInternal = new CompilerType(compilerInfo.CodeDomProviderType, compilerInfo.CreateDefaultCompilerParameters());
                this._compilerLanguages[language] = compilerTypeInternal;
            }
            if (compilerTypeInternal == null)
            {
                throw new HttpException(System.Web.SR.GetString("Invalid_lang", new object[] { language }));
            }
            CompilationUtil.CheckCompilerOptionsAllowed(compilerTypeInternal.CompilerParameters.CompilerOptions, true, null, 0);
            compilerTypeInternal = compilerTypeInternal.Clone();
            compilerTypeInternal.CompilerParameters.IncludeDebugInformation = this.Debug;
            return(compilerTypeInternal);
        }
Esempio n. 18
0
        private static string GetCompilerPath(CompilerType type)
        {
            switch (type)
            {
            case CompilerType.None:
                return(null);

            case CompilerType.CSharp:
                return(Settings.CSharpCompilerPath);

            case CompilerType.MsBuild:
            case CompilerType.MsBuildLibrary:
                return(Settings.MsBuildExecutablePath);

            case CompilerType.CPlusPlusGcc:
            case CompilerType.CPlusPlusZip:
                return(Settings.CPlusPlusGccCompilerPath);

            case CompilerType.Java:
            case CompilerType.JavaZip:
            case CompilerType.JavaInPlaceCompiler:
                return(Settings.JavaCompilerPath);

            case CompilerType.DotNetCompiler:
            case CompilerType.CSharpDotNetCore:
                return(Settings.DotNetCompilerPath);

            case CompilerType.SolidityCompiler:
                return(Settings.SolidityCompilerPath);

            default:
                throw new ArgumentOutOfRangeException(nameof(type));
            }
        }
 public SimpleRazorBuildProvider()
 {
     this._codeLanguage = new CSharpRazorCodeLanguage();
     this._compilerType = GetDefaultCompilerTypeForLanguage(this._codeLanguage.LanguageName);
     this._host = new SimpleRazorEngineHost(this._codeLanguage);
     this._virtualPathDependencies = null;
     this._typeName = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", this._host.DefaultNamespace, "Foot");
 }
Esempio n. 20
0
        public void ResolveFactoryTests_ParameterLess(CompilerType compilerType)
        {
            using var container = new StashboxContainer(c => c.WithCompiler(compilerType));
            container.Register <Test>();
            var factory = container.ResolveFactory <Test>();

            Assert.NotNull(factory());
        }
 /// <summary>
 /// Clone another compile environment
 /// </summary>
 /// <param name="Other">The compile environment to copy</param>
 public CompileEnvironment(CompileEnvironment Other)
 {
     Compiler     = Other.Compiler;
     CompilerType = Other.CompilerType;
     Options      = new List <CompileOption>(Other.Options);
     Definitions  = new List <string>(Other.Definitions);
     IncludePaths = new List <DirectoryReference>(Other.IncludePaths);
 }
Esempio n. 22
0
        public void NamedScope_Lifetime_Check(CompilerType compilerType)
        {
            var inst = new StashboxContainer(c => c.WithCompiler(compilerType))
                       .Register <ITest, Test>(config => config.InNamedScope("A"))
                       .ContainerContext.RegistrationRepository.GetRegistrationMappings().First(reg => reg.Key == typeof(ITest));

            Assert.IsType <NamedScopeLifetime>(inst.Value.RegistrationContext.Lifetime);
        }
Esempio n. 23
0
        public void Different_Compilers(CompilerType type, string table)
        {
            var input    = new Query("Foo");
            var expected = new Sql($"SELECT * FROM {table}");
            var output   = input.ToSql(type);

            output.Should().BeEquivalentTo(expected);
        }
 public abstract void DoWork(
     CompilerType compilerType,
     string compilerAdditionalArguments,
     byte[] compilerContent,
     string checkerAssemblyName,
     string checkerTypeName,
     string checkerParameter,
     int timeLimit,
     int memoryLimit);
Esempio n. 25
0
        public void ResolveFactoryTests_ParameterLess_Named(CompilerType compilerType)
        {
            using var container = new StashboxContainer(c => c.WithCompiler(compilerType));
            container.Register <IService, Service>(c => c.WithName("service"));
            container.Register <IService, Service1>(c => c.WithName("service1"));
            var factory = container.ResolveFactory <IService>("service");

            Assert.IsType <Service>(factory());
        }
Esempio n. 26
0
        /*
         * Return a CompilerType that a extension maps to.
         */
        internal CompilerType GetCompilerInfoFromExtension(string extension, bool throwOnFail)
        {
            EnsureCompilerCacheInit();

            // First, try the cache (i.e. old <compilers> section)
            CompilerType compilerType;
            object       obj      = _compilerExtensions[extension];
            Compiler     compiler = obj as Compiler;

            if (compiler != null)
            {
                compilerType = compiler.CompilerTypeInternal;
                _compilerExtensions[extension] = compilerType;
            }
            else
            {
                compilerType = obj as CompilerType;
            }

            if (compilerType == null)
            {
                // If not, try the <codedom> section

                if (CodeDomProvider.IsDefinedExtension(extension))
                {
                    string language = CodeDomProvider.GetLanguageFromExtension(extension);

                    CompilerInfo ci = CodeDomProvider.GetCompilerInfo(language);

                    compilerType = new CompilerType(
                        ci.CodeDomProviderType, ci.CreateDefaultCompilerParameters());

                    // Cache it
                    _compilerExtensions[extension] = compilerType;
                }
            }

            if (compilerType == null)
            {
                if (!throwOnFail)
                {
                    return(null);
                }

                // Unsupported extension: throw an exception
                throw new HttpException(SR.GetString(SR.Invalid_lang_extension, extension));
            }

            // Clone it so the original is not modified
            compilerType = compilerType.Clone();

            // Set the value of the debug flag in the copy
            compilerType.CompilerParameters.IncludeDebugInformation = Debug;

            return(compilerType);
        }
Esempio n. 27
0
        public void FactoryTests_Resolve_ContainerFactory(CompilerType compilerType)
        {
            using var container = new StashboxContainer(c => c.WithCompiler(compilerType));
            container.Register <Test3>();
            container.Register <ITest>(context => context.WithFactory(c => c.Resolve <Test3>()));

            var inst = container.Resolve <ITest>();

            Assert.IsType <Test3>(inst);
        }
Esempio n. 28
0
 public Make(ToolchainType Toolchain, CompilerType Compiler, OperatingSystemType TargetOperationSystem, String SourceDirectory, String BuildDirectory, bool EnableRebuild)
 {
     this.Toolchain               = Toolchain;
     this.Compiler                = Compiler;
     this.TargetOperationSystem   = TargetOperationSystem;
     this.SourceDirectory         = SourceDirectory;
     this.BuildDirectory          = BuildDirectory;
     this.EnableRebuild           = EnableRebuild;
     this.BuildingOperatingSystem = OperatingSystemType.Windows;
 }
Esempio n. 29
0
        public void FactoryTests_Resolve_ContainerFactory_Initializer(CompilerType compilerType)
        {
            using var container = new StashboxContainer(c => c.WithCompiler(compilerType));
            container.Register <ITest4>(context =>
                                        context.WithFactory(() => new Test4()).WithInitializer((t, r) => t.Init("Test")));

            var test1 = container.Resolve <ITest4>();

            Assert.Equal("Test", test1.Name);
        }
Esempio n. 30
0
        public void NamedScope_Simple_Resolve_Get_Last_If_Scoped_Doesnt_Exist(CompilerType compilerType)
        {
            var inst = new StashboxContainer(c => c.WithCompiler(compilerType))
                       .Register <ITest, Test>()
                       .Register <ITest, Test1>()
                       .BeginScope("A")
                       .Resolve <ITest>();

            Assert.IsType <Test1>(inst);
        }
        /// <summary>
        /// Convert a <seealso cref="Query"/> object to a <seealso cref="Sql" /> object.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="compilerType"></param>
        /// <returns></returns>
        public static Sql ToSql(this Query query, CompilerType compilerType)
        {
            query = query ?? throw new ArgumentNullException(nameof(query));

            var compiler = _compilers[compilerType].Value;
            var compiled = compiler.Compile(query);
            var ppSql    = Helper.ReplaceAll(compiled.RawSql, "?", x => "@" + x);

            return(new Sql(ppSql, compiled.Bindings.ToArray()));
        }
Esempio n. 32
0
        protected internal override void ProcessExternalResource(
            IResourceBuildHelper helper,
            string url,
            out string preProcessed,
            out string compacted,
            List <ParseException> errors)
        {
            compacted = preProcessed = String.Empty;

            Uri uri;

            if (!Uri.TryCreate(url, UriKind.Absolute, out uri))
            {
                throw new ArgumentException("Invalid external URL");
            }

            string       ext      = Path.GetExtension(uri.AbsolutePath).Trim('.');
            CompilerType compiler = helper.GetDefaultCompilerTypeForLanguage(ext);

            if (!typeof(ResourceCodeProvider).IsAssignableFrom(compiler.CodeDomProviderType))
            {
                // don't know how to process any further
                return;
            }

            ResourceCodeProvider provider = (ResourceCodeProvider)Activator.CreateInstance(compiler.CodeDomProviderType);

            try
            {
                // concatenate the preprocessed source for current merge phase
                provider.ProcessExternalResource(
                    helper,
                    url,
                    out preProcessed,
                    out compacted,
                    errors);
            }
            catch (ParseException ex)
            {
                errors.Add(ex);
            }
            catch (Exception ex)
            {
                errors.Add(new ParseError(ex.Message, url, 0, 0, ex));
            }

            if (!this.isMimeSet &&
                !String.IsNullOrEmpty(provider.ContentType) &&
                !String.IsNullOrEmpty(provider.FileExtension))
            {
                this.contentType   = provider.ContentType;
                this.fileExtension = provider.FileExtension;
                this.isMimeSet     = true;
            }
        }
Esempio n. 33
0
 public static ICompiler CreateCompiler(CompilerType compilerType)
 {
     switch (compilerType)
     {
         case CompilerType.None:
             return null;
         case CompilerType.CSharp:
             return new CSharpCompiler();
         case CompilerType.CPlusPlusGcc:
             return new CPlusPlusCompiler();
         default:
             throw new ArgumentException("Unsupported compiler.");
     }
 }
        protected CompileResult Compile(CompilerType compilerType, string compilerPath, string compilerArguments, string code)
        {
            var sourceCodeFilePath = this.SaveStringToTempFile(code);

            if (compilerType == CompilerType.None)
            {
                return new CompileResult(true, null) { OutputFile = sourceCodeFilePath };
            }

            if (!File.Exists(compilerPath))
            {
                throw new ArgumentException(string.Format("Compiler not found in: {0}", compilerPath), "compilerPath");
            }

            ICompiler compiler = Compiler.CreateCompiler(compilerType);
            var compilerResult = compiler.Compile(compilerPath, sourceCodeFilePath, compilerArguments);
            File.Delete(sourceCodeFilePath);

            return compilerResult;
        }
        protected CompileResult Compile(CompilerType compilerType, string compilerPath, string compilerArguments, string submissionFilePath)
        {
            if (compilerType == CompilerType.None)
            {
                return new CompileResult(true, null) { OutputFile = submissionFilePath };
            }

            if (!File.Exists(compilerPath))
            {
                throw new ArgumentException(string.Format("Compiler not found in: {0}", compilerPath), "compilerPath");
            }

            ICompiler compiler = Compiler.CreateCompiler(compilerType);
            var compilerResult = compiler.Compile(compilerPath, submissionFilePath, compilerArguments);

            if (File.Exists(submissionFilePath))
            {
                File.Delete(submissionFilePath);
            }

            return compilerResult;
        }
Esempio n. 36
0
 /// <summary>
 /// Initializeaza o clasa pentru un compilator nou
 /// </summary>
 /// <param name="fullPath">Adresa catre executabil</param>
 /// <param name="argumentsPattern">Sablonul argumentelor</param>
 /// <param name="compilerType">Tipul compilatorului</param>
 public CompilerData(string fullPath, string argumentsPattern, CompilerType compilerType)
 {
     FullPath = fullPath;
     ArgumentsPattern = argumentsPattern;
     CompilerType = compilerType;
 }
Esempio n. 37
0
 /// <summary>
 /// Compileaza un text
 /// </summary>
 /// <param name="sourceText">Textul care trebuie compilat</param>
 /// <param name="compilerType">Tipul compilatorului</param>
 /// <returns></returns>
 public bool CompileText(string sourceText, CompilerType compilerType)
 {
     return CompileText(sourceText, GetCompilerByType(compilerType));
 }
Esempio n. 38
0
 /// <summary>
 /// Returneaza un compilator dupa tipul specificat
 /// </summary>
 /// <param name="compilerType">Tipul compilatorului</param>
 /// <returns></returns>
 public CompilerData GetCompilerByType(CompilerType compilerType)
 {
     switch (compilerType)
     {
         case CompilerType.CPP:
             return CPPCompiler;
         default:
             return null;
     }
 }
        private CompileResult CompileSourceFiles(CompilerType compilerType, string compilerPath, string compilerArguments, IEnumerable<string> sourceFilesToCompile)
        {
            var compilerResult = new CompileResult(false, null);
            var compilerCommentBuilder = new StringBuilder();

            foreach (var sourceFile in sourceFilesToCompile)
            {
                compilerResult = this.Compile(compilerType, compilerPath, compilerArguments, sourceFile);

                compilerCommentBuilder.AppendLine(compilerResult.CompilerComment);

                if (!compilerResult.IsCompiledSuccessfully)
                {
                    break; // The compilation of other files is not necessary
                }
            }

            var compilerComment = compilerCommentBuilder.ToString().Trim();
            compilerResult.CompilerComment = compilerComment.Length > 0 ? compilerComment : null;

            return compilerResult;
        }
	private static Compiler CreateCompiler(CompilerType compilerType, Logger logger, Platform platform, string monoProfile, string projectDir, string[] compilationOptions, string unityEditorDataDir)
	{
		var compilerDirectory = Path.Combine(projectDir, LANGUAGE_SUPPORT_DIR);

		switch (compilerType)
		{
			case CompilerType.Auto:
				return FindSuitableCompiler(logger, platform, monoProfile, projectDir, compilationOptions, unityEditorDataDir);

			case CompilerType.Mono3:
				var stockCompilerPath = monoProfile == "2.0"
					? Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/gmcs.exe")
					: Path.Combine(unityEditorDataDir, @"Mono/lib/mono/" + monoProfile + "/smcs.exe");
				return new Mono30Compiler(logger, stockCompilerPath);

			case CompilerType.Mono5:
				var bleedingEdgeCompilerPath = Path.Combine(unityEditorDataDir, @"MonoBleedingEdge/lib/mono/4.5/mcs.exe");
				return new Mono50Compiler(logger, bleedingEdgeCompilerPath);

			case CompilerType.Mono6:
				if (Mono60Compiler.IsAvailable(compilerDirectory))
					return new Mono60Compiler(logger, compilerDirectory);
				break;

			case CompilerType.Microsoft6:
				var roslynDirectory = Path.Combine(compilerDirectory, "Roslyn");
				if (Microsoft60Compiler.IsAvailable(roslynDirectory))
					return new Microsoft60Compiler(logger, roslynDirectory);
				break;

			case CompilerType.Incremental6:
				if (Incremental60Compiler.IsAvailable(compilerDirectory))
					return new Incremental60Compiler(logger, compilerDirectory);
				break;
		}

		return null;
	}
 private static string GetCompilerPath(CompilerType type)
 {
     switch (type)
     {
         case CompilerType.None:
             return null;
         case CompilerType.CSharp:
             return Settings.CSharpCompilerPath;
         case CompilerType.MsBuild:
             return Settings.MsBuildExecutablePath;
         case CompilerType.CPlusPlusGcc:
             return Settings.CPlusPlusGccCompilerPath;
         case CompilerType.Java:
             return Settings.JavaCompilerPath;
         default:
             throw new ArgumentOutOfRangeException("type");
     }
 }
        private CompileResult CompileSourceFiles(CompilerType compilerType, string compilerPath, string compilerArguments, IEnumerable<string> sourceFilesToCompile)
        {
            CompileResult compilerResult = null;
            foreach (var sourceFile in sourceFilesToCompile)
            {
                compilerResult = this.Compile(compilerType, compilerPath, compilerArguments, sourceFile);

                if (!compilerResult.IsCompiledSuccessfully)
                {
                    break; // The compilation of other files is not necessary
                }
            }

            return compilerResult;
        }
 private static string GetCompilerPath(CompilerType type)
 {
     switch (type)
     {
         case CompilerType.None:
             return null;
         case CompilerType.CSharp:
             return Settings.CSharpCompilerPath;
         case CompilerType.MsBuild:
             throw new NotImplementedException("Compiler not supported.");
         case CompilerType.CPlusPlusGcc:
             return Settings.CPlusPlusGccCompilerPath;
         case CompilerType.Java:
             throw new NotImplementedException("Compiler not supported.");
         default:
             throw new ArgumentOutOfRangeException("type");
     }
 }