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; }
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); }
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); }
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; }
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; }
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); }
/// <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); }
public void CombiningWithNullSkipsNulls() { var options = new CompilerOptions { Optimize = true }; var result = CompilerOptions.Combine(options, null); Assert.True(result.Optimize.Value); }
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; }
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[] { }; }
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()); }
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); }
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; }
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; }
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; } }
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; if (tree.Nodes.Count > 0) { PreProcess(tree); CompileProgram(tree); } return part; }
public ScriptTextWriter(TextWriter writer, CompilerOptions options) : base(CultureInfo.InvariantCulture) { _writer = writer; _globalWriter = writer; #if DEBUG _minimize = options.Minimize && (options.InternalTestMode == false); #else _minimize = options.Minimize; #endif if (_minimize) { NewLine = "\n"; } _tabString = " "; _indentLevel = 0; _tabsPending = false; }
private void InvokeMethodInternal(InvokeParams invokeParams) { var invokeOptions = new InvokeOptions() { ClassName = invokeParams.TypeName, MethodName = invokeParams.MethodName, Async = true }; var compilerOptions = new CompilerOptions() { FilePath = invokeParams.FilePath, ReferencedAssemblyPaths = BuildManager.GetReferencedAssemblies().OfType<Assembly>().Select(x => x.Location).ToArray(), SignKeyPath = invokeParams.KeyPath, OutputAssemblyName = invokeParams.AsmName }; MethodInvoker.Execute(invokeOptions, compilerOptions); }
public override List<CodePart> Compile(string scriptText, string contextId, CompilerOptions options) { List<CodePart> parts = null; // make the code lowercase scriptText = MakeLowerCase(scriptText); scriptText = ReplaceIdentifiers(scriptText); //if (contextId != "interpreter") parts = _cache.GetFromCache(scriptText); // if parts is null means the code doesn't exists in the cache if (parts == null) { parts = new List<CodePart>(); ParseTree parseTree = parser.Parse(scriptText); if (parseTree.Errors.Count == 0) { var compiler = new Compiler(); LoadContext(contextId); // TODO: handle compile errors (e.g. wrong run parameter count) CodePart mainPart = compiler.Compile(parseTree, currentContext, options); // add locks and triggers parts.AddRange(currentContext.Locks.GetNewParts()); parts.AddRange(currentContext.Triggers.GetNewParts()); parts.AddRange(currentContext.Subprograms.GetNewParts()); parts.Add(mainPart); AssignInstructionId(parts); //if (contextId != "interpreter") _cache.AddToCache(scriptText, parts); } else { ParseError error = parseTree.Errors[0]; RaiseParseException(scriptText, error.Line, error.Position); } } return parts; }
public Effect(GraphicsDevice graphicsDevice, byte[] effectCode, CompilerOptions options, EffectPool pool) { int fragmentblocklength = BitConverter.ToInt32(effectCode, 0); int vertexblocklength = BitConverter.ToInt32(effectCode, fragmentblocklength + 4); if (fragmentblocklength != 0) { fragment_handle = Gl.glCreateShader(Gl.GL_FRAGMENT_SHADER); fragment = true; } if (vertexblocklength != 0) { vertex_handle = Gl.glCreateShader(Gl.GL_VERTEX_SHADER); vertex = true; } if (fragment) { string[] fragmentstring = new string[1] { Encoding.UTF8.GetString(effectCode, 4, fragmentblocklength) }; int[] fragmentLength = new int[1] { fragmentstring[0].Length }; Gl.glShaderSource(fragment_handle, 1, fragmentstring, fragmentLength); } if (vertex) { string[] vertexstring = new string[1] { Encoding.UTF8.GetString(effectCode, fragmentblocklength + 8, vertexblocklength) }; int[] vertexLength = new int[1] { vertexstring[0].Length }; Gl.glShaderSource(vertex_handle, 1, vertexstring, vertexLength); } if (fragment) { Gl.glCompileShader(fragment_handle); } if (vertex) { Gl.glCompileShader(fragment_handle); } }
public static void Main(string[] args) { // create test options if (args.Length == 0) { //--Assembly ../../../../../Libraries/System.Browser/System.Browser/System.Browser/bin/debug/System.Browser.dll; args = new String[] { "--TargetArchitecture", "JavaScript", "--TargetSubArchitecture", "Mozilla", "--TargetSubArchitectureVersion", "3.0", "--OutputPath", "./Build/", //"--Verbose", "--Assembly", "../../../../../Core/XaeiOS.Core/XaeiOS.TestSuite/bin/debug/XaeiOS.TestSuite.exe", "--Assembly", "../../../../../Core/XaeiOS.Core/OSCorlib/bin/Debug/OSCorlib.dll", "--Assembly", "../../../../../Core/XaeiOS.Core/XaeiOS.Kernel/bin/Debug/XaeiOS.Kernel.dll", "--Assembly", "../../../../../Libraries/System.Browser/System.Browser/System.Browser/bin/debug/System.Browser.dll", /* "--Assembly", "../../../../../Libraries/System/System/bin/debug/System.dll", "--Assembly", "../../../../../Libraries/System.Net/System.Net.Tests/bin/debug/System.Net.Tests.exe", "--Assembly", "../../../../../Libraries/System.Net/System.Net/bin/debug/System.Net.dll", "--Assembly", "../../../../../../MuZume/XaeiOS/Source/MuZume/MuZume/bin/Debug/MuZume.exe", //"--Assembly", "../../../../../Tests/TestCLRApplication/TestCLRApplication/bin/debug/TestCLRApplication.exe", "--Reference", "../../../XaeiO.Compiler2.Tests/bin/Debug/XaeiO.Compiler2.Tests.exe", */ }; /* args = new String[] { "--TargetArchitecture", "CLR", "--OutputPath", "./Build/", "--Assembly", "MuZume.exe" };*/ } CompilerOptions options = new CompilerOptions(args); XaeiOSCompiler compiler = new XaeiOSCompiler(options); compiler.Compile(); }
public void PropertiesAndEvents([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions) { RunForLibrary(cscOptions: cscOptions); }
public static CompilerResults CompileCSharp(string sourceFileName, CompilerOptions flags = CompilerOptions.UseDebug, string outputFileName = null) { List <string> sourceFileNames = new List <string> { sourceFileName }; foreach (Match match in Regex.Matches(File.ReadAllText(sourceFileName), @"#include ""([\w\d./]+)""")) { sourceFileNames.Add(Path.GetFullPath(Path.Combine(Path.GetDirectoryName(sourceFileName), match.Groups[1].Value))); } var preprocessorSymbols = GetPreprocessorSymbols(flags); if (flags.HasFlag(CompilerOptions.UseRoslyn)) { var parseOptions = new CSharpParseOptions( preprocessorSymbols: preprocessorSymbols.ToArray(), languageVersion: Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp8 ); var syntaxTrees = sourceFileNames.Select(f => SyntaxFactory.ParseSyntaxTree(File.ReadAllText(f), parseOptions, path: f)); if (flags.HasFlag(CompilerOptions.ReferenceCore)) { syntaxTrees = syntaxTrees.Concat(new[] { SyntaxFactory.ParseSyntaxTree(targetFrameworkAttributeSnippet) }); } IEnumerable <MetadataReference> references; if (flags.HasFlag(CompilerOptions.ReferenceCore)) { references = coreDefaultReferences.Value; } else { references = defaultReferences.Value; } if (flags.HasFlag(CompilerOptions.ReferenceVisualBasic)) { references = references.Concat(visualBasic.Value); } var compilation = CSharpCompilation.Create(Path.GetFileNameWithoutExtension(sourceFileName), syntaxTrees, references, new CSharpCompilationOptions( flags.HasFlag(CompilerOptions.Library) ? OutputKind.DynamicallyLinkedLibrary : OutputKind.ConsoleApplication, platform: flags.HasFlag(CompilerOptions.Force32Bit) ? Platform.X86 : Platform.AnyCpu, optimizationLevel: flags.HasFlag(CompilerOptions.Optimize) ? OptimizationLevel.Release : OptimizationLevel.Debug, allowUnsafe: true, deterministic: true )); CompilerResults results = new CompilerResults(new TempFileCollection()); results.PathToAssembly = outputFileName ?? Path.GetTempFileName(); var emitResult = compilation.Emit(results.PathToAssembly); if (!emitResult.Success) { StringBuilder b = new StringBuilder("Compiler error:"); foreach (var diag in emitResult.Diagnostics) { b.AppendLine(diag.ToString()); } throw new Exception(b.ToString()); } return(results); } else if (flags.HasFlag(CompilerOptions.UseMcs)) { CompilerResults results = new CompilerResults(new TempFileCollection()); results.PathToAssembly = outputFileName ?? Path.GetTempFileName(); string testBasePath = RoundtripAssembly.TestDir; if (!Directory.Exists(testBasePath)) { Assert.Ignore($"Compilation with mcs ignored: test directory '{testBasePath}' needs to be checked out separately." + Environment.NewLine + $"git clone https://github.com/icsharpcode/ILSpy-tests \"{testBasePath}\""); } string mcsPath = Path.Combine(testBasePath, @"mcs\2.6.4\bin\gmcs.bat"); string otherOptions = " -unsafe -o" + (flags.HasFlag(CompilerOptions.Optimize) ? "+ " : "- "); if (flags.HasFlag(CompilerOptions.Library)) { otherOptions += "-t:library "; } else { otherOptions += "-t:exe "; } if (flags.HasFlag(CompilerOptions.UseDebug)) { otherOptions += "-g "; } if (flags.HasFlag(CompilerOptions.Force32Bit)) { otherOptions += "-platform:x86 "; } else { otherOptions += "-platform:anycpu "; } if (preprocessorSymbols.Count > 0) { otherOptions += " \"-d:" + string.Join(";", preprocessorSymbols) + "\" "; } ProcessStartInfo info = new ProcessStartInfo(mcsPath); info.Arguments = $"{otherOptions}-out:\"{Path.GetFullPath(results.PathToAssembly)}\" {string.Join(" ", sourceFileNames.Select(fn => '"' + Path.GetFullPath(fn) + '"'))}"; info.RedirectStandardError = true; info.RedirectStandardOutput = true; info.UseShellExecute = false; Console.WriteLine($"\"{info.FileName}\" {info.Arguments}"); Process process = Process.Start(info); var outputTask = process.StandardOutput.ReadToEndAsync(); var errorTask = process.StandardError.ReadToEndAsync(); Task.WaitAll(outputTask, errorTask); process.WaitForExit(); Console.WriteLine("output: " + outputTask.Result); Console.WriteLine("errors: " + errorTask.Result); Assert.AreEqual(0, process.ExitCode, "mcs failed"); return(results); } else { var provider = new CSharpCodeProvider(new Dictionary <string, string> { { "CompilerVersion", "v4.0" } }); CompilerParameters options = new CompilerParameters(); options.GenerateExecutable = !flags.HasFlag(CompilerOptions.Library); options.CompilerOptions = "/unsafe /o" + (flags.HasFlag(CompilerOptions.Optimize) ? "+" : "-"); options.CompilerOptions += (flags.HasFlag(CompilerOptions.UseDebug) ? " /debug" : ""); options.CompilerOptions += (flags.HasFlag(CompilerOptions.Force32Bit) ? " /platform:anycpu32bitpreferred" : ""); if (preprocessorSymbols.Count > 0) { options.CompilerOptions += " /d:" + string.Join(";", preprocessorSymbols); } if (outputFileName != null) { options.OutputAssembly = outputFileName; } options.ReferencedAssemblies.Add("System.dll"); options.ReferencedAssemblies.Add("System.Core.dll"); options.ReferencedAssemblies.Add("System.Xml.dll"); options.ReferencedAssemblies.Add("Microsoft.CSharp.dll"); if (flags.HasFlag(CompilerOptions.ReferenceVisualBasic)) { options.ReferencedAssemblies.Add("Microsoft.VisualBasic.dll"); } CompilerResults results = provider.CompileAssemblyFromFile(options, sourceFileNames.ToArray()); if (results.Errors.Cast <CompilerError>().Any(e => !e.IsWarning)) { StringBuilder b = new StringBuilder("Compiler error:"); foreach (var error in results.Errors) { b.AppendLine(error.ToString()); } throw new Exception(b.ToString()); } return(results); } }
public void NoDecimalConstants([ValueSource("roslynOnlyOptions")] CompilerOptions cscOptions) { RunForLibrary(cscOptions: cscOptions, decompilerSettings: new DecompilerSettings { DecimalConstants = false }); }
void Run([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None, DecompilerSettings decompilerSettings = null) { var ilFile = Path.Combine(TestCasePath, testName) + Tester.GetSuffix(cscOptions) + ".il"; var csFile = Path.Combine(TestCasePath, testName + ".cs"); var expectedFile = Path.Combine(TestCasePath, testName + ".Expected.cs"); if (!File.Exists(ilFile)) { // re-create .il file if necessary CompilerResults output = null; try { output = Tester.CompileCSharp(csFile, cscOptions); Tester.Disassemble(output.PathToAssembly, ilFile, asmOptions); } finally { if (output != null) { output.TempFiles.Delete(); } } } var executable = Tester.AssembleIL(ilFile, asmOptions); var decompiled = Tester.DecompileCSharp(executable, decompilerSettings); CodeAssert.FilesAreEqual(expectedFile, decompiled, Tester.GetPreprocessorSymbols(cscOptions).ToArray()); }
public override void Execute(SafeSharedObjects shared) { // run() is strange. It needs two levels of args - the args to itself, and the args it is meant to // pass on to the program it's invoking. First, these are the args to run itself: object volumeId = PopValueAssert(shared, true); object pathObject = PopValueAssert(shared, true); AssertArgBottomAndConsume(shared); // Now the args it is going to be passing on to the program: var progArgs = new List <object>(); int argc = CountRemainingArgs(shared); for (int i = 0; i < argc; ++i) { progArgs.Add(PopValueAssert(shared, true)); } AssertArgBottomAndConsume(shared); if (shared.VolumeMgr == null) { return; } GlobalPath path = shared.VolumeMgr.GlobalPathFromObject(pathObject); Volume volume = shared.VolumeMgr.GetVolumeFromPath(path); VolumeFile volumeFile = volume.Open(path) as VolumeFile; FileContent content = volumeFile != null?volumeFile.ReadAll() : null; if (content == null) { throw new Exception(string.Format("File '{0}' not found", path)); } if (shared.ScriptHandler == null) { return; } if (volumeId != null) { throw new KOSObsoletionException("v1.0.2", "run [file] on [volume]", "None", ""); } else { // clear the "program" compilation context shared.Cpu.StartCompileStopwatch(); shared.ScriptHandler.ClearContext("program"); //string filePath = shared.VolumeMgr.GetVolumeRawIdentifier(shared.VolumeMgr.CurrentVolume) + "/" + fileName; var options = new CompilerOptions { LoadProgramsInSameAddressSpace = true, FuncManager = shared.FunctionManager }; var programContext = shared.Cpu.SwitchToProgramContext(); List <CodePart> codeParts; if (content.Category == FileCategory.KSM) { string prefix = programContext.Program.Count.ToString(); codeParts = content.AsParts(path, prefix); programContext.AddParts(codeParts); shared.Cpu.StopCompileStopwatch(); } else { shared.Cpu.YieldProgram(YieldFinishedCompile.RunScript(path, 1, content.String, "program", options)); } } // Because run() returns FIRST, and THEN the CPU jumps to the new program's first instruction that it set up, // it needs to put the return stack in a weird order. Its return value needs to be buried UNDER the args to the // program it's calling: UsesAutoReturn = false; shared.Cpu.PushArgumentStack(0); // dummy return that all functions have. // Put the args for the program being called back on in the same order they were in before (so read the list backward): shared.Cpu.PushArgumentStack(new KOSArgMarkerType()); for (int i = argc - 1; i >= 0; --i) { shared.Cpu.PushArgumentStack(progArgs[i]); } }
void RunForLibrary([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None, DecompilerSettings decompilerSettings = null) { Run(testName, asmOptions | AssemblerOptions.Library, cscOptions | CompilerOptions.Library, decompilerSettings); }
private bool GetBooleanOption(CompilerOptions optionID) { return GetNullableBooleanOption(optionID).GetValueOrDefault(defaultValue: false); }
public void LiftedOperators([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions) { RunForLibrary(cscOptions: cscOptions); }
public Effect ( GraphicsDevice graphicsDevice, byte[] effectCode, CompilerOptions options, EffectPool pool) { if (graphicsDevice == null) { throw new ArgumentNullException("Graphics Device Cannot Be Null"); } this.graphicsDevice = graphicsDevice; if (pool == null) { return; // TODO throw new ArgumentNullException("Effect Pool Cannot Be Null"); } int fragmentblocklength = BitConverter.ToInt32(effectCode, 0); int vertexblocklength = BitConverter.ToInt32(effectCode, fragmentblocklength + 4); if (fragmentblocklength != 0) { fragment_handle = GL.CreateShader( ShaderType.FragmentShader ); fragment = true; } if (vertexblocklength != 0) { vertex_handle = GL.CreateShader( ShaderType.VertexShader ); vertex = true; } if (fragment) { string[] fragmentstring = new string[1] { Encoding.UTF8.GetString(effectCode, 4, fragmentblocklength) }; //int[] fragmentLength = new int[1] { fragmentstring[0].Length }; int fragmentLength = fragmentstring[0].Length; GL.ShaderSource(fragment_handle, 1, fragmentstring, ref fragmentLength); } if (vertex) { string[] vertexstring = new string[1] { Encoding.UTF8.GetString(effectCode, fragmentblocklength + 8, vertexblocklength) }; // int[] vertexLength = new int[1] { vertexstring[0].Length }; int vertexLength = vertexstring[0].Length; GL.ShaderSource(vertex_handle, 1, vertexstring, ref vertexLength); } int compiled = 0; if (fragment) { GL.CompileShader(fragment_handle); GL.GetShader(fragment_handle, ShaderParameter.CompileStatus, out compiled ); if (compiled == (int)All.False) { Console.Write("Fragment Compilation Failed!"); } } if (vertex) { GL.CompileShader(vertex_handle); GL.GetShader(vertex_handle, ShaderParameter.CompileStatus, out compiled ); if (compiled == (int)All.False) { Console.Write("Vertex Compilation Failed!"); } } }
private IEnumerable<string> ParseWarningCodes(CompilerOptions compilerOptions) { Contract.ThrowIfFalse(compilerOptions == CompilerOptions.OPTID_NOWARNLIST || compilerOptions == CompilerOptions.OPTID_WARNASERRORLIST || compilerOptions == CompilerOptions.OPTID_WARNNOTASERRORLIST); foreach (var warning in GetStringOption(compilerOptions, defaultValue: "").Split(new[] { ' ', ',', ';' }, StringSplitOptions.RemoveEmptyEntries)) { int warningId; var warningStringID = warning; if (int.TryParse(warning, out warningId)) { warningStringID = GetIdForErrorCode(warningId); } yield return warningStringID; } }
public void SwitchExpressions([ValueSource(nameof(roslynOnlyOptions))] CompilerOptions cscOptions) { RunForLibrary(cscOptions: cscOptions); }
public void TypeAnalysisTests([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions) { RunForLibrary(cscOptions: cscOptions); }
public void AutoProperties([ValueSource(nameof(roslynOnlyOptions))] CompilerOptions cscOptions) { RunForLibrary(cscOptions: cscOptions); }
public static CompilableItem CompileItem( Compilable compilable, string optionalModuleName, string moduleIdentPostfix, int statementNumber, ISet<string> statementNames, ModuleCompileTimeServices moduleCompileTimeServices, CompilerOptions compilerOptions, out Assembly assembly) { var compileTimeServices = new StatementCompileTimeServices(statementNumber, moduleCompileTimeServices); // Stage 0 - parse and compile-inline-classes and walk statement var walked = ParseCompileInlinedClassesWalk(compilable, compileTimeServices); var raw = walked.StatementSpecRaw; string classNameCreateClass = null; if (raw.CreateClassProvided != null) { classNameCreateClass = DetermineClassNameCreateClass(walked.ClassesInlined); } try { // Stage 2(a) - precompile: compile annotations var annotations = AnnotationUtil.CompileAnnotations( raw.Annotations, compileTimeServices.ImportServiceCompileTime, compilable); // Stage 2(b) - walk subselects, alias expressions, declared expressions, dot-expressions ExprNodeSubselectDeclaredDotVisitor visitor; try { visitor = StatementSpecRawWalkerSubselectAndDeclaredDot.WalkSubselectAndDeclaredDotExpr(raw); } catch (ExprValidationException ex) { throw new StatementSpecCompileException(ex.Message, compilable.ToEPL()); } var subselectNodes = visitor.Subselects; // Determine a statement name var statementNameProvided = GetNameFromAnnotation(annotations); if (compilerOptions.StatementName != null) { var assignedName = compilerOptions.StatementName.Invoke( new StatementNameContext( () => compilable.ToEPL(), statementNameProvided, optionalModuleName, annotations, statementNumber)); if (assignedName != null) { statementNameProvided = assignedName; } } var statementName = statementNameProvided ?? Convert.ToString(statementNumber); if (statementNames.Contains(statementName)) { var count = 1; var newStatementName = statementName + "-" + count; while (statementNames.Contains(newStatementName)) { count++; newStatementName = statementName + "-" + count; } statementName = newStatementName; } statementName = statementName.Trim(); statementNames.Add(statementName); // Determine table access nodes var tableAccessNodes = DetermineTableAccessNodes(raw.TableExpressions, visitor); // compile scripts once in this central place, may also compile later in expression ScriptValidationPrecompileUtil.ValidateScripts( raw.ScriptExpressions, raw.ExpressionDeclDesc, compileTimeServices); // Determine subselects for compilation, and lambda-expression shortcut syntax for named windows if (!visitor.ChainedExpressionsDot.IsEmpty()) { RewriteNamedWindowSubselect( visitor.ChainedExpressionsDot, subselectNodes, compileTimeServices.NamedWindowCompileTimeResolver); } // Stage 2(c) compile context descriptor ContextCompileTimeDescriptor contextDescriptor = null; var optionalContextName = raw.OptionalContextName; if (optionalContextName != null) { var detail = compileTimeServices.ContextCompileTimeResolver.GetContextInfo(optionalContextName); if (detail == null) { throw new StatementSpecCompileException( "Context by name '" + optionalContextName + "' could not be found", compilable.ToEPL()); } contextDescriptor = new ContextCompileTimeDescriptor( optionalContextName, detail.ContextModuleName, detail.ContextVisibility, new ContextPropertyRegistry(detail), detail.ValidationInfos); } // Stage 2(d) compile raw statement spec var statementType = StatementTypeUtil.GetStatementType(raw).Value; var statementRawInfo = new StatementRawInfo( statementNumber, statementName, annotations, statementType, contextDescriptor, raw.IntoTableSpec?.Name, compilable, optionalModuleName); var compiledDesc = StatementRawCompiler.Compile( raw, compilable, false, false, annotations, subselectNodes, tableAccessNodes, statementRawInfo, compileTimeServices); var specCompiled = compiledDesc.Compiled; var statementIdentPostfix = IdentifierUtil.GetIdentifierMayStartNumeric(statementName); // get compile-time user object object userObjectCompileTime = null; if (compilerOptions.StatementUserObject != null) { userObjectCompileTime = compilerOptions.StatementUserObject.Invoke( new StatementUserObjectContext( () => compilable.ToEPL(), statementName, optionalModuleName, annotations, statementNumber)); } // handle hooks HandleStatementCompileHook(annotations, compileTimeServices, specCompiled); // Stage 3(a) - statement-type-specific forge building var @base = new StatementBaseInfo( compilable, specCompiled, userObjectCompileTime, statementRawInfo, optionalModuleName); StmtForgeMethod forgeMethod; if (raw.UpdateDesc != null) { forgeMethod = new StmtForgeMethodUpdate(@base); } else if (raw.OnTriggerDesc != null) { forgeMethod = new StmtForgeMethodOnTrigger(@base); } else if (raw.CreateIndexDesc != null) { forgeMethod = new StmtForgeMethodCreateIndex(@base); } else if (raw.CreateVariableDesc != null) { forgeMethod = new StmtForgeMethodCreateVariable(@base); } else if (raw.CreateDataFlowDesc != null) { forgeMethod = new StmtForgeMethodCreateDataflow(@base); } else if (raw.CreateTableDesc != null) { forgeMethod = new StmtForgeMethodCreateTable(@base); } else if (raw.CreateExpressionDesc != null) { forgeMethod = new StmtForgeMethodCreateExpression(@base); } else if (raw.CreateClassProvided != null) { forgeMethod = new StmtForgeMethodCreateClass(@base, walked.ClassesInlined, classNameCreateClass); } else if (raw.CreateWindowDesc != null) { forgeMethod = new StmtForgeMethodCreateWindow(@base); } else if (raw.CreateContextDesc != null) { forgeMethod = new StmtForgeMethodCreateContext(@base); } else if (raw.CreateSchemaDesc != null) { forgeMethod = new StmtForgeMethodCreateSchema(@base); } else { forgeMethod = new StmtForgeMethodSelect(@base); } // check context-validity conditions for this statement if (contextDescriptor != null) { try { foreach (var validator in contextDescriptor.ValidationInfos) { validator.ValidateStatement( contextDescriptor.ContextName, specCompiled, compileTimeServices); } } catch (ExprValidationException ex) { throw new StatementSpecCompileException(ex.Message, ex, compilable.ToEPL()); } } // Stage 3(b) - forge-factory-to-forge var classPostfix = moduleIdentPostfix + "_" + statementIdentPostfix; var forgeables = new List<StmtClassForgeable>(); // add forgeables from filter-related processing i.e. multikeys foreach (var additional in compiledDesc.AdditionalForgeables) { var namespaceScope = new CodegenNamespaceScope(compileTimeServices.Namespace, null, false); forgeables.Add(additional.Make(namespaceScope, classPostfix)); } var filterSpecCompileds = new List<FilterSpecCompiled>(); var scheduleHandleCallbackProviders = new List<ScheduleHandleCallbackProvider>(); var namedWindowConsumers = new List<NamedWindowConsumerStreamSpec>(); var filterBooleanExpressions = new List<FilterSpecParamExprNodeForge>(); var result = forgeMethod.Make(compileTimeServices.Namespace, classPostfix, compileTimeServices); forgeables.AddAll(result.Forgeables); VerifyForgeables(forgeables); filterSpecCompileds.AddAll(result.Filtereds); scheduleHandleCallbackProviders.AddAll(result.Scheduleds); namedWindowConsumers.AddAll(result.NamedWindowConsumers); filterBooleanExpressions.AddAll(result.FilterBooleanExpressions); // Stage 3(c) - filter assignments: assign filter callback ids and filter-path-num for boolean expressions var filterId = -1; foreach (var provider in filterSpecCompileds) { var assigned = ++filterId; provider.FilterCallbackId = assigned; } // Stage 3(d) - schedule assignments: assign schedule callback ids var scheduleId = 0; foreach (var provider in scheduleHandleCallbackProviders) { provider.ScheduleCallbackId = scheduleId++; } // Stage 3(e) - named window consumers: assign consumer id var namedWindowConsumerId = 0; foreach (var provider in namedWindowConsumers) { provider.NamedWindowConsumerId = namedWindowConsumerId++; } // Stage 3(f) - filter boolean expression id assignment var filterBooleanExprNum = 0; foreach (var expr in filterBooleanExpressions) { expr.FilterBoolExprId = filterBooleanExprNum++; } // Stage 3(f) - verify substitution parameters VerifySubstitutionParams(raw.SubstitutionParameters); // Stage 4 - forge-to-class (forge with statement-fields last) var classes = forgeables .Select(forgeable => forgeable.Forge(true, false)) .ToList(); // Stage 5 - refactor methods to make sure the constant pool does not grow too large for any given class CompilerHelperRefactorToStaticMethods.RefactorMethods( classes, compileTimeServices.Configuration.Compiler.ByteCode.MaxMethodsPerClass); // Stage 6 - sort to make the "fields" class first and all the rest later var sorted = classes .OrderBy(c => c.ClassType.GetSortCode()) .ToList(); // We are making sure JsonEventType receives the underlying class itself CompilableItemPostCompileLatch postCompile = CompilableItemPostCompileLatchDefault.INSTANCE; foreach (var eventType in compileTimeServices.EventTypeCompileTimeRegistry.NewTypesAdded) { if (eventType is JsonEventType) { postCompile = new CompilableItemPostCompileLatchJson( compileTimeServices.EventTypeCompileTimeRegistry.NewTypesAdded, compileTimeServices.ParentClassLoader); break; } } var container = compileTimeServices.Container; var compiler = container .RoslynCompiler() .WithCodeLogging(compileTimeServices.Configuration.Compiler.Logging.IsEnableCode) .WithCodeAuditDirectory(compileTimeServices.Configuration.Compiler.Logging.AuditDirectory) .WithCodegenClasses(sorted); assembly = compiler.Compile(); string statementProviderClassName = CodeGenerationIDGenerator.GenerateClassNameWithNamespace( compileTimeServices.Namespace, typeof(StatementProvider), classPostfix); var additionalClasses = new HashSet<Type>(); additionalClasses.AddAll(walked.ClassesInlined.Classes); compileTimeServices.ClassProvidedCompileTimeResolver.AddTo(additionalClasses); compileTimeServices.ClassProvidedCompileTimeRegistry.AddTo(additionalClasses); return new CompilableItem( statementProviderClassName, classes, postCompile, additionalClasses); } catch (StatementSpecCompileException) { throw; } catch (ExprValidationException ex) { throw new StatementSpecCompileException(ex.Message, ex, compilable.ToEPL()); } catch (EPException ex) { throw new StatementSpecCompileException(ex.Message, ex, compilable.ToEPL()); } catch (Exception ex) { var text = ex.Message ?? ex.GetType().FullName; throw new StatementSpecCompileException(text, ex, compilable.ToEPL()); } }
private string GetStringOption(CompilerOptions optionID, string defaultValue) { string value = (string)_options[(int)optionID]; if (string.IsNullOrEmpty(value)) { return defaultValue; } else { return value; } }
/// <summary> /// Compiles a list of source units into a single module. /// <c>options</c> can be <c>null</c> /// <c>errroSink</c> can be <c>null</c> /// <c>dictionary</c> can be <c>null</c> /// </summary> public IScriptModule CompileModule(string name, ScriptModuleKind kind, CompilerOptions options, ErrorSink errorSink, IAttributesCollection dictionary, params SourceUnit[] sourceUnits) { return(_manager.CompileModule(name, kind, new Scope(dictionary), options, errorSink, sourceUnits)); }
public Effect( GraphicsDevice graphicsDevice, byte[] effectCode, CompilerOptions options, EffectPool pool) { if (graphicsDevice == null) { throw new ArgumentNullException("Graphics Device Cannot Be Null"); } this.graphicsDevice = graphicsDevice; if (pool == null) { return; // TODO throw new ArgumentNullException("Effect Pool Cannot Be Null"); } int fragmentblocklength = BitConverter.ToInt32(effectCode, 0); int vertexblocklength = BitConverter.ToInt32(effectCode, fragmentblocklength + 4); if (fragmentblocklength != 0) { fragment_handle = GL.CreateShader(ShaderType.FragmentShader); fragment = true; } if (vertexblocklength != 0) { vertex_handle = GL.CreateShader(ShaderType.VertexShader); vertex = true; } if (fragment) { string[] fragmentstring = new string[1] { Encoding.UTF8.GetString(effectCode, 4, fragmentblocklength) }; //int[] fragmentLength = new int[1] { fragmentstring[0].Length }; int fragmentLength = fragmentstring[0].Length; GL.ShaderSource(fragment_handle, 1, fragmentstring, ref fragmentLength); } if (vertex) { string[] vertexstring = new string[1] { Encoding.UTF8.GetString(effectCode, fragmentblocklength + 8, vertexblocklength) }; // int[] vertexLength = new int[1] { vertexstring[0].Length }; int vertexLength = vertexstring[0].Length; GL.ShaderSource(vertex_handle, 1, vertexstring, ref vertexLength); } int compiled = 0; if (fragment) { GL.CompileShader(fragment_handle); GL.GetShader(fragment_handle, ShaderParameter.CompileStatus, out compiled); if (compiled == (int)All.False) { Console.Write("Fragment Compilation Failed!"); } } if (vertex) { GL.CompileShader(vertex_handle); GL.GetShader(vertex_handle, ShaderParameter.CompileStatus, out compiled); if (compiled == (int)All.False) { Console.Write("Vertex Compilation Failed!"); } } }
public void Lock([ValueSource(nameof(defaultOptionsWithMcs))] CompilerOptions cscOptions) { RunForLibrary(cscOptions: cscOptions); }
public void ExpressionTrees([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions) { RunForLibrary(cscOptions: cscOptions); }
public override void Execute(SafeSharedObjects shared) { // NOTE: The built-in load() function actually ends up returning // two things on the stack: on top is a boolean for whether the program // was already loaded, and under that is an integer for where to jump to // to call it. The load() function is NOT meant to be called directly from // a user script. // (unless it's being called in compile-only mode, in which case it // returns the default dummy zero on the stack like everything else does). UsesAutoReturn = true; bool defaultOutput = false; bool justCompiling = false; // is this load() happening to compile, or to run? GlobalPath outPath = null; object topStack = PopValueAssert(shared, true); // null if there's no output file (output file means compile, not run). if (topStack != null) { justCompiling = true; string outputArg = topStack.ToString(); if (outputArg.Equals("-default-compile-out-")) { defaultOutput = true; } else { outPath = shared.VolumeMgr.GlobalPathFromObject(outputArg); } } object skipAlreadyObject = PopValueAssert(shared, false); bool skipIfAlreadyCompiled = (skipAlreadyObject is bool) ? (bool)skipAlreadyObject : false; object pathObject = PopValueAssert(shared, true); AssertArgBottomAndConsume(shared); if (pathObject == null) { throw new KOSFileException("No filename to load was given."); } GlobalPath path = shared.VolumeMgr.GlobalPathFromObject(pathObject); Volume volume = shared.VolumeMgr.GetVolumeFromPath(path); VolumeFile file = volume.Open(path, !justCompiling) as VolumeFile; // if running, look for KSM first. If compiling look for KS first. if (file == null) { throw new KOSFileException(string.Format("Can't find file '{0}'.", path)); } path = GlobalPath.FromVolumePath(file.Path, shared.VolumeMgr.GetVolumeId(volume)); if (skipIfAlreadyCompiled && !justCompiling) { var programContext = shared.Cpu.SwitchToProgramContext(); int programAddress = programContext.GetAlreadyCompiledEntryPoint(path.ToString()); if (programAddress >= 0) { // TODO - The check could also have some dependancy on whether the file content changed on // disk since last time, but that would also mean having to have a way to clear out the old // copy of the compiled file from the program context, which right now doesn't exist. (Without // that, doing something like a loop that re-wrote a file and re-ran it 100 times would leave // 100 old dead copies of the compiled opcodes in memory, only the lastmost copy being really used.) // We're done here. Skip the compile. Point the caller at the already-compiled version. shared.Cpu.PushArgumentStack(programAddress); this.ReturnValue = true; // tell caller that it already existed. return; } } FileContent fileContent = file.ReadAll(); // filename is now guaranteed to have an extension. To make default output name, replace the extension with KSM: if (defaultOutput) { outPath = path.ChangeExtension(Volume.KOS_MACHINELANGUAGE_EXTENSION); } if (path.Equals(outPath)) { throw new KOSFileException("Input and output paths must differ."); } if (shared.VolumeMgr == null) { return; } if (shared.VolumeMgr.CurrentVolume == null) { throw new KOSFileException("Volume not found"); } if (shared.ScriptHandler != null) { shared.Cpu.StartCompileStopwatch(); var options = new CompilerOptions { LoadProgramsInSameAddressSpace = true, FuncManager = shared.FunctionManager }; // add this program to the address space of the parent program, // or to a file to save: if (justCompiling) { // since we've already read the file content, use the volume from outPath instead of the source path volume = shared.VolumeMgr.GetVolumeFromPath(outPath); shared.Cpu.YieldProgram(YieldFinishedCompile.CompileScriptToFile(path, 1, fileContent.String, options, volume, outPath)); } else { var programContext = shared.Cpu.SwitchToProgramContext(); List <CodePart> parts; if (fileContent.Category == FileCategory.KSM) { string prefix = programContext.Program.Count.ToString(); parts = fileContent.AsParts(path, prefix); int programAddress = programContext.AddObjectParts(parts, path.ToString()); // push the entry point address of the new program onto the stack shared.Cpu.PushArgumentStack(programAddress); } else { UsesAutoReturn = false; shared.Cpu.YieldProgram(YieldFinishedCompile.LoadScript(path, 1, fileContent.String, "program", options)); } this.ReturnValue = false; // did not already exist. } shared.Cpu.StopCompileStopwatch(); } }
public void Generics([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions) { RunForLibrary(cscOptions: cscOptions); }
public void NoExtensionMethods([ValueSource("roslynOnlyOptions")] CompilerOptions cscOptions) { RunForLibrary(cscOptions: cscOptions, decompilerSettings: new DecompilerSettings { ExtensionMethods = false }); }
public void DelegateConstruction([ValueSource(nameof(defaultOptionsWithMcs))] CompilerOptions cscOptions) { RunForLibrary(cscOptions: cscOptions | CompilerOptions.Preview); }
public void NoArrayInitializers([ValueSource("roslynOnlyOptions")] CompilerOptions cscOptions) { RunForLibrary(cscOptions: cscOptions, decompilerSettings: new DecompilerSettings { ArrayInitializers = false }); }
public void CompoundAssignmentTest([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions) { RunForLibrary(cscOptions: cscOptions); }
public void CustomShortCircuitOperators([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions) { RunForLibrary(cscOptions: cscOptions); }
public void LocalFunctions([ValueSource(nameof(roslynOnlyOptions))] CompilerOptions cscOptions) { RunForLibrary(cscOptions: cscOptions | CompilerOptions.Preview); }
public void CheckedUnchecked([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions) { RunForLibrary(cscOptions: cscOptions); }
public void ReduceNesting([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions) { RunForLibrary(cscOptions: cscOptions); }
private void WriteAssemblyAttributes(CompilerOptions options, string assemblyName, AssemblyBuilder asm) { if (!Helpers.IsNullOrEmpty(options.TargetFrameworkName)) { // get [TargetFramework] from mscorlib/equivalent and burn into the new assembly Type versionAttribType = null; try { // this is best-endeavours only versionAttribType = GetType("System.Runtime.Versioning.TargetFrameworkAttribute", MapType(typeof(string)).Assembly); } catch { /* don't stress */ } if (versionAttribType != null) { PropertyInfo[] props; object[] propValues; if (Helpers.IsNullOrEmpty(options.TargetFrameworkDisplayName)) { props = new PropertyInfo[0]; propValues = new object[0]; } else { props = new PropertyInfo[1] { versionAttribType.GetProperty("FrameworkDisplayName") }; propValues = new object[1] { options.TargetFrameworkDisplayName }; } CustomAttributeBuilder builder = new CustomAttributeBuilder( versionAttribType.GetConstructor(new Type[] { MapType(typeof(string)) }), new object[] { options.TargetFrameworkName }, props, propValues); asm.SetCustomAttribute(builder); } } // copy assembly:InternalsVisibleTo Type internalsVisibleToAttribType = null; #if !FX11 try { internalsVisibleToAttribType = MapType(typeof(System.Runtime.CompilerServices.InternalsVisibleToAttribute)); } catch { /* best endeavors only */ } #endif if (internalsVisibleToAttribType != null) { BasicList internalAssemblies = new BasicList(), consideredAssemblies = new BasicList(); foreach (MetaType metaType in types) { Assembly assembly = metaType.Type.Assembly; if (consideredAssemblies.IndexOfReference(assembly) >= 0) continue; consideredAssemblies.Add(assembly); AttributeMap[] assemblyAttribsMap = AttributeMap.Create(this, assembly); for (int i = 0; i < assemblyAttribsMap.Length; i++) { if (assemblyAttribsMap[i].AttributeType != internalsVisibleToAttribType) continue; object privelegedAssemblyObj; assemblyAttribsMap[i].TryGet("AssemblyName", out privelegedAssemblyObj); string privelegedAssemblyName = privelegedAssemblyObj as string; if (privelegedAssemblyName == assemblyName || Helpers.IsNullOrEmpty(privelegedAssemblyName)) continue; // ignore if (internalAssemblies.IndexOfString(privelegedAssemblyName) >= 0) continue; // seen it before internalAssemblies.Add(privelegedAssemblyName); CustomAttributeBuilder builder = new CustomAttributeBuilder( internalsVisibleToAttribType.GetConstructor(new Type[] { MapType(typeof(string)) }), new object[] { privelegedAssemblyName }); asm.SetCustomAttribute(builder); } } } }
public void UnsafeCode([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions) { RunForLibrary(cscOptions: cscOptions); }
public override ScriptCode CompileSourceCode(SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink) { // invariant language doesn't have a grammar: throw new NotSupportedException(); }
public void ConstructorInitializers([ValueSource(nameof(defaultOptionsWithMcs))] CompilerOptions cscOptions) { RunForLibrary(cscOptions: cscOptions); }
private bool? GetNullableBooleanOption(CompilerOptions optionID) { return (bool?)_options[(int)optionID]; }
public void PInvoke([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions) { // This tests needs our own disassembler; ildasm has a bug with marshalinfo. RunForLibrary(cscOptions: cscOptions, asmOptions: AssemblerOptions.UseOwnDisassembler); }
private string GetFilePathRelativeOption(CompilerOptions optionID) { var path = GetStringOption(optionID, defaultValue: null); if (string.IsNullOrEmpty(path)) { return null; } var directory = this.ContainingDirectoryPathOpt; if (!string.IsNullOrEmpty(directory)) { return FileUtilities.ResolveRelativePath(path, directory); } return null; }
public void OutVariables([ValueSource(nameof(roslynOnlyOptions))] CompilerOptions cscOptions) { RunForLibrary(cscOptions: cscOptions); }
public int OnImportAddedEx(string filename, string project, CompilerOptions optionID) { filename = FileUtilities.NormalizeAbsolutePath(filename); if (optionID != CompilerOptions.OPTID_IMPORTS && optionID != CompilerOptions.OPTID_IMPORTSUSINGNOPIA) { throw new ArgumentException("optionID was an unexpected value.", "optionID"); } bool embedInteropTypes = optionID == CompilerOptions.OPTID_IMPORTSUSINGNOPIA; var properties = new MetadataReferenceProperties(embedInteropTypes: embedInteropTypes); // The file may not exist, so let's return an error code. In Dev10, we were // never called us for these at all, and the project system would immediately // return an S_FALSE. Sadly, returning S_FALSE will convert back to S_OK, which // would prevent this file from ever being added again. Roslyn bug 7315 for more. return AddMetadataReferenceAndTryConvertingToProjectReferenceIfPossible(filename, properties, hResultForMissingFile: VSConstants.E_FAIL); }
public void DynamicTests([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions) { RunForLibrary(cscOptions: cscOptions); }