当前位置: 首页>>代码示例>>C#>>正文


C# CompilerOptions类代码示例

本文整理汇总了C#中CompilerOptions的典型用法代码示例。如果您正苦于以下问题:C# CompilerOptions类的具体用法?C# CompilerOptions怎么用?C# CompilerOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CompilerOptions类属于命名空间,在下文中一共展示了CompilerOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CombiningWithOtherOptionsOverwrites

        public void CombiningWithOtherOptionsOverwrites()
        {
            var options = new CompilerOptions
            {
                AllowUnsafe = false,
                Optimize = true,
                WarningsAsErrors = true,
                LanguageVersion = "x"
            };

            var options2 = new CompilerOptions
            {
                AllowUnsafe = true,
                Optimize = false,
                WarningsAsErrors = false,
                LanguageVersion = "y",
            };

            var result = CompilerOptions.Combine(options, options2);

            Assert.True(result.AllowUnsafe.Value);
            Assert.False(result.Optimize.Value);
            Assert.False(result.WarningsAsErrors.Value);
            Assert.Equal("y", result.LanguageVersion);
        }
开发者ID:leloulight,项目名称:dnx,代码行数:25,代码来源:CompilerOptionsFacts.cs

示例2: GetParser

        private Parser GetParser()
        {
            if (_parser == null)
                {
                    using (var options = new CompilerOptions())
                    {
                        var sourceItems = new SourceItem[]{
                            new TextItem()
                            {

                                Name = "GdlGrammer", ContentType = TextItemType.MGrammar, Reader = new StringReader(Language)
                            }
                        };

                        options.AddSourceItems(sourceItems);

                        CompilationResults results = Compiler.Compile(options);
                        if (results.HasErrors)
                        {
                            //TODO: show meaningful error message
                            throw new Exception("Failed to compile GDL ....");
                        }
                        else
                        {
                            foreach (var parserFactory in results.ParserFactories)
                            {
                                //TODO: Why inside foreach loop!!!
                                _parser = parserFactory.Value.Create();
                            }
                        }
                    }
                }
                return _parser;
        }
开发者ID:tuliosouza,项目名称:ASG,代码行数:34,代码来源:GestureDefinitionLanguage.cs

示例3: Compile

        public CodePart Compile(int startLineNum, ParseTree tree, Context context, CompilerOptions options)
        {
            InitCompileFlags();

            part = new CodePart();
            this.context = context;
            this.options = options;
            this.startLineNum = startLineNum;

            ++context.NumCompilesSoFar;

            try
            {
                if (tree.Nodes.Count > 0)
                {
                    PreProcess(tree);
                    CompileProgram(tree);
                }
            }
            catch (KOSException kosException)
            {
                if (lastNode != null)
                {
                    throw;  // TODO something more sophisticated will go here that will
                    // attach source/line information to the exception before throwing it upward.
                    // that's why this seemingly pointless "catch and then throw again" is here.
                }
                SafeHouse.Logger.Log("Exception in Compiler: " + kosException.Message);
                SafeHouse.Logger.Log(kosException.StackTrace);
                throw;  // throw it up in addition to logging the stack trace, so the kOS terminal will also give the user some message.
            }

            return part;
        }
开发者ID:gisikw,项目名称:KOS,代码行数:34,代码来源:Compiler.cs

示例4: Compile

        public CodePart Compile(ParseTree tree, Context context, CompilerOptions options)
        {
            _part = new CodePart();
            _context = context;
            _options = options;

            try
            {
                if (tree.Nodes.Count > 0)
                {
                    PreProcess(tree);
                    CompileProgram(tree);
                }
            }
            catch (Exception e)
            {
                if (_lastNode != null)
                {
                    throw new Exception(string.Format("Error parsing {0}: {1}", ConcatenateNodes(_lastNode), e.Message));
                }
                else
                {
                    throw;
                }
            }

            return _part;
        }
开发者ID:ElasticRaven,项目名称:KOS,代码行数:28,代码来源:Compiler.cs

示例5: Test_That_Compiler_Returns_Response_As_Expected

        public void Test_That_Compiler_Returns_Response_As_Expected()
        {
            // Arrange
            const string ExpectedCompiledJavaScript = "{\"compiledCode\":\"alert(2);var a\\u003d(void 0).a.value,b\\u003d\\\"\\\";if(\\\"\\\"\\u003d\\u003da||-1\\u003d\\u003da.indexOf(\\\"@\\\"))b\\u003d\\\"please do something\\\";alert(\\\"\\\"\\u003d\\u003db);\",\"warnings\":[{\"type\":\"JSC_POSSIBLE_INEXISTENT_PROPERTY\",\"file\":\"Input_0\",\"lineno\":8,\"charno\":22,\"warning\":\"Property something never defined on frm\",\"line\":\"    var somevar \\u003d frm.something.value;\"},{\"type\":\"JSC_WRONG_ARGUMENT_COUNT\",\"file\":\"Input_0\",\"lineno\":19,\"charno\":6,\"warning\":\"Function dosomething: called with 0 argument(s). Function requires at least 1 argument(s) and no more than 1 argument(s).\",\"line\":\"alert(dosomething());\"}],\"statistics\":{\"originalSize\":372,\"originalGzipSize\":219,\"compressedSize\":103,\"compressedGzipSize\":113,\"compileTime\":0},\"outputFilePath\":\"/code/jsc533f6c7203b8d05105e273ac53810976/default.js\"}";

            // request and response data that will be used by the mock webrequest
            var requestStreamMock = new Mock<Stream>();
            var webResponseMock = new Mock<WebResponse>();
            var responseStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(ExpectedCompiledJavaScript));
            webResponseMock.Setup(m => m.GetResponseStream()).Returns(responseStream);

            // Mock of the webrequest tht will make the call to GCC
            var webRequestMock = new Mock<WebRequest>();
            webRequestMock.Setup(m => m.GetRequestStream()).Returns(requestStreamMock.Object);
            webRequestMock.Setup(m => m.GetResponse()).Returns(webResponseMock.Object);

            // Mock of file that will be read by the compiler
            var textReaderMock = new Mock<TextReader>();
            textReaderMock.Setup(m => m.ReadToEnd()).Returns("var x = 0;");

            var compilerOptions = new CompilerOptions(textReaderMock.Object, webRequestMock.Object, "A");
            var compiler = new JavaScriptCompiler(compilerOptions, new CompilationLevelHelper());

            // Act
            var actualCompiledJavaScript = compiler.Compile();

            Assert.Equal(ExpectedCompiledJavaScript, actualCompiledJavaScript);
        }
开发者ID:jameswiseman76,项目名称:JsGoogleCompile,代码行数:28,代码来源:JavaScriptCompilerTests.cs

示例6: GetOption

        public void GetOption(CompilerOptions optionID, IntPtr variant)
        {
            if (optionID < 0 || optionID >= CompilerOptions.LARGEST_OPTION_ID)
            {
                throw new ArgumentOutOfRangeException(nameof(optionID));
            }

            Marshal.GetNativeVariantForObject(_options[(int)optionID], variant);
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:9,代码来源:CSharpProjectShim.ICSCompilerConfig.cs

示例7: Process

        /// <summary>
        /// Process a file
        /// </summary>
        /// <param name="file">File name</param>
        /// <param name="options">Compilation options</param>
        public void Process(string file, CompilerOptions options = CompilerOptions.None)
        {
            // clear compilation info if compilation
              if (options != CompilerOptions.ContinueCompilation)
            Init();

              ParseFile(file);
              Emitter.Prepare();
              Emitter.RootNode.Compile(Emitter);
        }
开发者ID:menozz,项目名称:mirelle,代码行数:15,代码来源:Compiler.cs

示例8: CombiningWithNullSkipsNulls

        public void CombiningWithNullSkipsNulls()
        {
            var options = new CompilerOptions
            {
                Optimize = true
            };

            var result = CompilerOptions.Combine(options, null);

            Assert.True(result.Optimize.Value);
        }
开发者ID:leloulight,项目名称:dnx,代码行数:11,代码来源:CompilerOptionsFacts.cs

示例9: CompilerContext

        public CompilerContext(SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink, ParserSink parserSink) {
            ContractUtils.RequiresNotNull(sourceUnit, "sourceUnit");
            ContractUtils.RequiresNotNull(errorSink, "errorSink");
            ContractUtils.RequiresNotNull(parserSink, "parserSink");
            ContractUtils.RequiresNotNull(options, "options");

            _sourceUnit = sourceUnit;
            _options = options;
            _errors = errorSink;
            _parserSink = parserSink;
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:11,代码来源:CompilerContext.cs

示例10: Compilation

        public Compilation(CompilationTest test)
        {
            _test = test;

            _references = new List<string>();
            _sources = new List<CompilationInput>();
            _resources = new List<CompilationInput>();

            _options = new CompilerOptions();
            _options.Minimize = false;
            _options.InternalTestMode = true;
            _options.Defines = new string[] { };
        }
开发者ID:jimmygilles,项目名称:scriptsharp,代码行数:13,代码来源:Compilation.cs

示例11: source_directory_is_mirrored_in_output

        public void source_directory_is_mirrored_in_output([ValueSource("OutputFolderParameters")] string outputFolder)
        {
            var sourceDir = ExampleScripts.Valid.Hierarchy;

            var compilerOptions = new CompilerOptions
                                      {
                                          Compile = true,
                                          OutputDir = outputFolder,
                                          Path = sourceDir.ToString()
                                      };

            new Compiler().Compile(compilerOptions);

            AssertOutputMirrorsSource(compilerOptions.Path.AsDirectory(), compilerOptions.OutputDir.AsDirectory());
        }
开发者ID:mlidbom,项目名称:coffeescript-dotnet,代码行数:15,代码来源:when_building_directory.cs

示例12: SetOptionWithMarshaledValue

        public int SetOptionWithMarshaledValue(CompilerOptions optionID, object value)
        {
            SetOption(ref _options[(int)optionID], value);

            if (optionID == CompilerOptions.OPTID_COMPATIBILITY)
            {
                // HACK: we want the project system to use the out-of-proc compiler rather than
                // us, because we really don't build much of anything yet. We can say we don't
                // support pretty much anything we want to do this. Let's just say we don't
                // support any version of C# yet

                return VSConstants.S_FALSE;
            }

            return VSConstants.S_OK;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:16,代码来源:CSharpProjectShim.ICSCompilerConfig.cs

示例13: CombiningConcatsDefines

        public void CombiningConcatsDefines()
        {
            var options = new CompilerOptions
            {
                Defines = new[] { "OPT1" }
            };

            var options2 = new CompilerOptions
            {
                Defines = new[] { "OPT2" }
            };

            var result = CompilerOptions.Combine(options, options2);

            Assert.Equal(new[] { "OPT1", "OPT2" }, result.Defines);
        }
开发者ID:leloulight,项目名称:dnx,代码行数:16,代码来源:CompilerOptionsFacts.cs

示例14: Compile

        public override List<CodePart> Compile(GlobalPath filePath, int startLineNum, string scriptText, string contextId, CompilerOptions options)
        {
            var parts = new List<CodePart>();
            ParseTree parseTree = parser.Parse(scriptText);
            if (parseTree.Errors.Count == 0)
            {
                var compiler = new Compiler();
                LoadContext(contextId);

                CodePart mainPart;
                try
                {
                    mainPart = compiler.Compile(startLineNum, parseTree, currentContext, options);
                }
                catch (KOSCompileException e)
                {
                    e.AddSourceText((short)startLineNum, scriptText);
                    throw;
                }

                // add locks and triggers
                parts.AddRange(currentContext.UserFunctions.GetNewParts());
                parts.AddRange(currentContext.Triggers.GetNewParts());
                parts.AddRange(currentContext.Subprograms.GetNewParts());

                parts.Add(mainPart);

                AssignSourceId(parts, filePath);

                //if (contextId != "interpreter") _cache.AddToCache(scriptText, parts);
            }
            else
            {
                // TODO: Come back here and check on the possibility of reporting more
                // errors than just the first one.  It appears that TinyPG builds a
                // whole array of error messages so people could see multiple syntax
                // errors in one go if we supported the reporting of it.  It may be that
                // it was deliberately not done because it might be too verbose that way
                // for the small text terminal.

                ParseError error = parseTree.Errors[0];
                throw new KOSParseException(error, scriptText);
            }

            return parts;
        }
开发者ID:KSP-KOS,项目名称:KOS,代码行数:46,代码来源:KSScript.cs

示例15: ParseOptions

        internal static CompilerOptions ParseOptions(string[] args, TextWriter infoWriter, TextWriter errorWriter)
        {
            if (args.Length == 0) {
                ShowHelp(infoWriter);
                return null;
            }

            try {
                bool showHelp = false;
                var result = new CompilerOptions() { MinimizeScript = true };
                var opts = new OptionSet {
                    { "outasm=",       v => result.OutputAssemblyPath = v },
                    { "outscript=",    v => result.OutputScriptPath = v },
                    { "doc=",          v => result.DocumentationFile = v },
                    { "d|define=",     v => result.DefineConstants.AddRange(v.Split(new[] { ';' }).Select(s => s.Trim()).Where(s => s != "" && !result.DefineConstants.Contains(s))) },
                    { "lib=",          v => result.AdditionalLibPaths.AddRange(v.Split(new[] { ',' }).Select(s => s.Trim()).Where(s => s != "" && !result.AdditionalLibPaths.Contains(s))) },
                    { "m|main=",       v => result.EntryPointClass = v },
                    { "r|reference=",  v => HandleReferences(result, v) },
                    { "debug",         f => result.MinimizeScript = f == null || f.EndsWith("-") },
                    { "w|warn=",       (int v) => { if (v < 0 || v > 4) throw new OptionException("Warning level must be between 0 and 4", "/warn"); result.WarningLevel = v; } },
                    { "nowarn=",       v => DisableWarnings(result, v) },
                    { "warnaserror:",  v => HandleWarningsAsErrors(result, v) },
                    { "warnaserror-:", v => HandleWarningsNotAsErrors(result, v) },
                    { "keyfile=",      v => result.KeyFile = v },
                    { "keycontainer=", v => result.KeyContainer = v },
                    { "t|target=",     v => result.HasEntryPoint = ParseTargetForHasEntryPoint(v) },
                    { "?|help",        v => showHelp = true },
                };

                var extra = opts.Parse(args);
                foreach (var file in extra)
                    result.SourceFiles.Add(file);

                if (showHelp) {
                    ShowHelp(infoWriter);
                    return null;
                }

                return result;
            }
            catch (OptionException ex) {
                errorWriter.WriteLine(ex.Message);
                return null;
            }
        }
开发者ID:JimmyJune,项目名称:SaltarelleCompiler,代码行数:45,代码来源:Program.cs


注:本文中的CompilerOptions类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。