Esempio n. 1
0
 public ScriptRunner(string?code, ImmutableList <SyntaxTree>?syntaxTrees = null, CSharpParseOptions?parseOptions = null, OutputKind outputKind = OutputKind.DynamicallyLinkedLibrary,
                     Platform platform           = Platform.AnyCpu, IEnumerable <MetadataReference>?references   = null,
                     IEnumerable <string>?usings = null, string?filePath = null, string?workingDirectory = null,
                     MetadataReferenceResolver?metadataResolver = null, SourceReferenceResolver?sourceResolver = null,
                     InteractiveAssemblyLoader?assemblyLoader   = null,
                     OptimizationLevel optimizationLevel        = OptimizationLevel.Debug, bool checkOverflow = false, bool allowUnsafe = true,
                     bool registerDependencies = false)
 {
     _optimizationLevel    = optimizationLevel;
     _checkOverflow        = checkOverflow;
     _allowUnsafe          = allowUnsafe;
     _registerDependencies = registerDependencies;
     Code            = code;
     SyntaxTrees     = syntaxTrees;
     OutputKind      = outputKind;
     Platform        = platform;
     _assemblyLoader = assemblyLoader ?? new InteractiveAssemblyLoader();
     ParseOptions    = (parseOptions ?? new CSharpParseOptions())
                       .WithKind(SourceCodeKind.Script)
                       .WithPreprocessorSymbols(RoslynHost.PreprocessorSymbols);
     References       = references?.AsImmutable() ?? ImmutableArray <MetadataReference> .Empty;
     Usings           = usings?.AsImmutable() ?? ImmutableArray <string> .Empty;
     FilePath         = filePath ?? string.Empty;
     MetadataResolver = metadataResolver ?? ScriptMetadataResolver.Default;
     SourceResolver   = sourceResolver ??
                        (workingDirectory != null
                          ? new SourceFileResolver(ImmutableArray <string> .Empty, workingDirectory)
                          : SourceFileResolver.Default);
 }
Esempio n. 2
0
 // 15.9 BACKCOMPAT OVERLOAD -- DO NOT TOUCH
 public CSharpCompilationOptions(
     OutputKind outputKind,
     bool reportSuppressedDiagnostics,
     string?moduleName,
     string?mainTypeName,
     string?scriptClassName,
     IEnumerable <string>?usings,
     OptimizationLevel optimizationLevel,
     bool checkOverflow,
     bool allowUnsafe,
     string?cryptoKeyContainer,
     string?cryptoKeyFile,
     ImmutableArray <byte> cryptoPublicKey,
     bool?delaySign,
     Platform platform,
     ReportDiagnostic generalDiagnosticOption,
     int warningLevel,
     IEnumerable <KeyValuePair <string, ReportDiagnostic> >?specificDiagnosticOptions,
     bool concurrentBuild,
     bool deterministic,
     XmlReferenceResolver?xmlReferenceResolver,
     SourceReferenceResolver?sourceReferenceResolver,
     MetadataReferenceResolver?metadataReferenceResolver,
     AssemblyIdentityComparer?assemblyIdentityComparer,
     StrongNameProvider?strongNameProvider,
     bool publicSign,
     MetadataImportOptions metadataImportOptions
     )
     : this(
         outputKind,
         reportSuppressedDiagnostics,
         moduleName,
         mainTypeName,
         scriptClassName,
         usings,
         optimizationLevel,
         checkOverflow,
         allowUnsafe,
         cryptoKeyContainer,
         cryptoKeyFile,
         cryptoPublicKey,
         delaySign,
         platform,
         generalDiagnosticOption,
         warningLevel,
         specificDiagnosticOptions,
         concurrentBuild,
         deterministic,
         xmlReferenceResolver,
         sourceReferenceResolver,
         metadataReferenceResolver,
         assemblyIdentityComparer,
         strongNameProvider,
         publicSign,
         metadataImportOptions,
         nullableContextOptions : NullableContextOptions.Disable
         )
 {
 }
Esempio n. 3
0
        internal string GetDisplayPath(TextSpan span, SourceReferenceResolver?resolver)
        {
            var mappedSpan = GetMappedLineSpan(span);

            if (resolver == null || mappedSpan.Path.IsEmpty())
            {
                return(mappedSpan.Path);
            }

            return(resolver.NormalizePath(mappedSpan.Path, baseFilePath: mappedSpan.HasMappedPath?FilePath: null) ?? mappedSpan.Path);
        }
        public DebugDocumentsBuilder(SourceReferenceResolver?resolver, bool isDocumentNameCaseSensitive)
        {
            _resolver = resolver;

            _debugDocuments = new ConcurrentDictionary <string, Cci.DebugSourceDocument>(
                isDocumentNameCaseSensitive ?
                StringComparer.Ordinal :
                StringComparer.OrdinalIgnoreCase);

            _normalizedPathsCache = new ConcurrentCache <(string, string?), string>(16);
        }
Esempio n. 5
0
        public new CSharpCompilationOptions WithSourceReferenceResolver(SourceReferenceResolver?resolver)
        {
            if (ReferenceEquals(resolver, this.SourceReferenceResolver))
            {
                return(this);
            }

            return(new CSharpCompilationOptions(this)
            {
                SourceReferenceResolver = resolver
            });
        }
Esempio n. 6
0
 public CSharpCompilationOptions(
     OutputKind outputKind,
     bool reportSuppressedDiagnostics = false,
     string?moduleName                   = null,
     string?mainTypeName                 = null,
     string?scriptClassName              = null,
     IEnumerable <string>?usings         = null,
     OptimizationLevel optimizationLevel = OptimizationLevel.Debug,
     bool checkOverflow                  = false,
     bool allowUnsafe                      = false,
     string?cryptoKeyContainer             = null,
     string?cryptoKeyFile                  = null,
     ImmutableArray <byte> cryptoPublicKey = default,
     bool?delaySign    = null,
     Platform platform = Platform.AnyCpu,
     ReportDiagnostic generalDiagnosticOption = ReportDiagnostic.Default,
     int warningLevel = 4,
     IEnumerable <KeyValuePair <string, ReportDiagnostic> >?specificDiagnosticOptions = null,
     bool concurrentBuild = true,
     bool deterministic   = false,
     XmlReferenceResolver?xmlReferenceResolver           = null,
     SourceReferenceResolver?sourceReferenceResolver     = null,
     MetadataReferenceResolver?metadataReferenceResolver = null,
     AssemblyIdentityComparer?assemblyIdentityComparer   = null,
     StrongNameProvider?strongNameProvider = null,
     bool publicSign = false,
     MetadataImportOptions metadataImportOptions   = MetadataImportOptions.Public,
     NullableContextOptions nullableContextOptions = NullableContextOptions.Disable,
     decimal warningVersion = 0m)
     : this(outputKind, reportSuppressedDiagnostics, moduleName, mainTypeName, scriptClassName,
            usings, optimizationLevel, checkOverflow, allowUnsafe,
            cryptoKeyContainer, cryptoKeyFile, cryptoPublicKey, delaySign, platform,
            generalDiagnosticOption, warningLevel,
            specificDiagnosticOptions, concurrentBuild, deterministic,
            currentLocalTime : default,
            debugPlusMode : false,
            xmlReferenceResolver : xmlReferenceResolver,
            sourceReferenceResolver : sourceReferenceResolver,
            metadataReferenceResolver : metadataReferenceResolver,
            assemblyIdentityComparer : assemblyIdentityComparer,
            strongNameProvider : strongNameProvider,
            metadataImportOptions : metadataImportOptions,
            referencesSupersedeLowerVersions : false,
            publicSign : publicSign,
            topLevelBinderFlags : BinderFlags.None,
            nullableContextOptions : nullableContextOptions,
            warningVersion : warningVersion)
 {
 }
Esempio n. 7
0
 internal CSharpCompilationOptions(
     OutputKind outputKind,
     bool reportSuppressedDiagnostics,
     string?moduleName,
     string?mainTypeName,
     string?scriptClassName,
     IEnumerable <string>?usings,
     OptimizationLevel optimizationLevel,
     bool checkOverflow,
     bool allowUnsafe,
     string?cryptoKeyContainer,
     string?cryptoKeyFile,
     ImmutableArray <byte> cryptoPublicKey,
     bool?delaySign,
     Platform platform,
     ReportDiagnostic generalDiagnosticOption,
     int warningLevel,
     IEnumerable <KeyValuePair <string, ReportDiagnostic> >?specificDiagnosticOptions,
     bool concurrentBuild,
     bool deterministic,
     DateTime currentLocalTime,
     bool debugPlusMode,
     XmlReferenceResolver?xmlReferenceResolver,
     SourceReferenceResolver?sourceReferenceResolver,
     MetadataReferenceResolver?metadataReferenceResolver,
     AssemblyIdentityComparer?assemblyIdentityComparer,
     StrongNameProvider?strongNameProvider,
     MetadataImportOptions metadataImportOptions,
     bool referencesSupersedeLowerVersions,
     bool publicSign,
     BinderFlags topLevelBinderFlags,
     NullableContextOptions nullableContextOptions,
     decimal warningVersion = 0m)
     : base(outputKind, reportSuppressedDiagnostics, moduleName, mainTypeName, scriptClassName,
            cryptoKeyContainer, cryptoKeyFile, cryptoPublicKey, delaySign, publicSign, optimizationLevel, checkOverflow,
            platform, generalDiagnosticOption, warningLevel, specificDiagnosticOptions.ToImmutableDictionaryOrEmpty(),
            concurrentBuild, deterministic, currentLocalTime, debugPlusMode, xmlReferenceResolver,
            sourceReferenceResolver, metadataReferenceResolver, assemblyIdentityComparer,
            strongNameProvider, metadataImportOptions, referencesSupersedeLowerVersions)
 {
     this.Usings                 = usings.AsImmutableOrEmpty();
     this.AllowUnsafe            = allowUnsafe;
     this.TopLevelBinderFlags    = topLevelBinderFlags;
     this.NullableContextOptions = nullableContextOptions;
     this.WarningVersion         = warningVersion;
 }
Esempio n. 8
0
 public CSharpCompilationOptions(
     OutputKind outputKind,
     bool reportSuppressedDiagnostics,
     string?moduleName,
     string?mainTypeName,
     string?scriptClassName,
     IEnumerable <string>?usings,
     OptimizationLevel optimizationLevel,
     bool checkOverflow,
     bool allowUnsafe,
     string?cryptoKeyContainer,
     string?cryptoKeyFile,
     ImmutableArray <byte> cryptoPublicKey,
     bool?delaySign,
     Platform platform,
     ReportDiagnostic generalDiagnosticOption,
     int warningLevel,
     IEnumerable <KeyValuePair <string, ReportDiagnostic> >?specificDiagnosticOptions,
     bool concurrentBuild,
     bool deterministic,
     XmlReferenceResolver?xmlReferenceResolver,
     SourceReferenceResolver?sourceReferenceResolver,
     MetadataReferenceResolver?metadataReferenceResolver,
     AssemblyIdentityComparer?assemblyIdentityComparer,
     StrongNameProvider?strongNameProvider)
     : this(outputKind, false, moduleName, mainTypeName, scriptClassName, usings, optimizationLevel,
            checkOverflow, allowUnsafe, cryptoKeyContainer, cryptoKeyFile, cryptoPublicKey,
            delaySign, platform, generalDiagnosticOption, warningLevel,
            specificDiagnosticOptions, concurrentBuild,
            deterministic : deterministic,
            currentLocalTime : default,
            debugPlusMode : false,
            xmlReferenceResolver : xmlReferenceResolver,
            sourceReferenceResolver : sourceReferenceResolver,
            syntaxTreeOptionsProvider : null,
            metadataReferenceResolver : metadataReferenceResolver,
            assemblyIdentityComparer : assemblyIdentityComparer,
            strongNameProvider : strongNameProvider,
            metadataImportOptions : MetadataImportOptions.Public,
            referencesSupersedeLowerVersions : false,
            publicSign : false,
            topLevelBinderFlags : BinderFlags.None,
            nullableContextOptions : NullableContextOptions.Disable)
 {
 }
Esempio n. 9
0
 public Compiler(ImmutableList <SyntaxTree> syntaxTrees, CSharpParseOptions parseOptions,
                 OutputKind outputKind                  = OutputKind.DynamicallyLinkedLibrary,
                 Platform platform                      = Platform.AnyCpu, IEnumerable <MetadataReference>?references = null,
                 IEnumerable <string>?usings            = null, string?workingDirectory = null,
                 SourceReferenceResolver?sourceResolver = null,
                 OptimizationLevel optimizationLevel    = OptimizationLevel.Debug,
                 bool checkOverflow                     = false, bool allowUnsafe = true)
 {
     OptimizationLevel = optimizationLevel;
     CheckOverflow     = checkOverflow;
     AllowUnsafe       = allowUnsafe;
     SyntaxTrees       = syntaxTrees;
     OutputKind        = outputKind;
     Platform          = platform;
     ParseOptions      = parseOptions;
     References        = references?.AsImmutable() ?? ImmutableArray <MetadataReference> .Empty;
     Usings            = usings?.AsImmutable() ?? ImmutableArray <string> .Empty;
     SourceResolver    = sourceResolver ??
                         (workingDirectory != null
                          ? new SourceFileResolver(ImmutableArray <string> .Empty, workingDirectory)
                          : SourceFileResolver.Default);
 }
Esempio n. 10
0
 protected abstract CompilationOptions CommonWithSourceReferenceResolver(SourceReferenceResolver?resolver);
Esempio n. 11
0
 public CompilationOptions WithSourceReferenceResolver(SourceReferenceResolver?resolver)
 {
     return(CommonWithSourceReferenceResolver(resolver));
 }
Esempio n. 12
0
        internal CompilationOptions(
            OutputKind outputKind,
            bool reportSuppressedDiagnostics,
            string?moduleName,
            string?mainTypeName,
            string?scriptClassName,
            string?cryptoKeyContainer,
            string?cryptoKeyFile,
            ImmutableArray <byte> cryptoPublicKey,
            bool?delaySign,
            bool publicSign,
            OptimizationLevel optimizationLevel,
            bool checkOverflow,
            Platform platform,
            ReportDiagnostic generalDiagnosticOption,
            int warningLevel,
            ImmutableDictionary <string, ReportDiagnostic> specificDiagnosticOptions,
            bool concurrentBuild,
            bool deterministic,
            DateTime currentLocalTime,
            bool debugPlusMode,
            XmlReferenceResolver?xmlReferenceResolver,
            SourceReferenceResolver?sourceReferenceResolver,
            MetadataReferenceResolver?metadataReferenceResolver,
            AssemblyIdentityComparer assemblyIdentityComparer,
            StrongNameProvider?strongNameProvider,
            MetadataImportOptions metadataImportOptions,
            bool referencesSupersedeLowerVersions)
        {
            this.OutputKind                       = outputKind;
            this.ModuleName                       = moduleName;
            this.MainTypeName                     = mainTypeName;
            this.ScriptClassName                  = scriptClassName ?? WellKnownMemberNames.DefaultScriptClassName;
            this.CryptoKeyContainer               = cryptoKeyContainer;
            this.CryptoKeyFile                    = string.IsNullOrEmpty(cryptoKeyFile) ? null : cryptoKeyFile;
            this.CryptoPublicKey                  = cryptoPublicKey.NullToEmpty();
            this.DelaySign                        = delaySign;
            this.CheckOverflow                    = checkOverflow;
            this.Platform                         = platform;
            this.GeneralDiagnosticOption          = generalDiagnosticOption;
            this.WarningLevel                     = warningLevel;
            this.SpecificDiagnosticOptions        = specificDiagnosticOptions;
            this.ReportSuppressedDiagnostics      = reportSuppressedDiagnostics;
            this.OptimizationLevel                = optimizationLevel;
            this.ConcurrentBuild                  = concurrentBuild;
            this.Deterministic                    = deterministic;
            this.CurrentLocalTime                 = currentLocalTime;
            this.DebugPlusMode                    = debugPlusMode;
            this.XmlReferenceResolver             = xmlReferenceResolver;
            this.SourceReferenceResolver          = sourceReferenceResolver;
            this.MetadataReferenceResolver        = metadataReferenceResolver;
            this.StrongNameProvider               = strongNameProvider;
            this.AssemblyIdentityComparer         = assemblyIdentityComparer ?? AssemblyIdentityComparer.Default;
            this.MetadataImportOptions            = metadataImportOptions;
            this.ReferencesSupersedeLowerVersions = referencesSupersedeLowerVersions;
            this.PublicSign                       = publicSign;

            _lazyErrors = new Lazy <ImmutableArray <Diagnostic> >(() =>
            {
                var builder = ArrayBuilder <Diagnostic> .GetInstance();
                ValidateOptions(builder);
                return(builder.ToImmutableAndFree());
            });
        }
Esempio n. 13
0
 protected override CompilationOptions CommonWithSourceReferenceResolver(SourceReferenceResolver?resolver) =>
 WithSourceReferenceResolver(resolver);