Exemple #1
0
        /// <summary>
        /// Creates a new compilation with the specified compilation options.
        /// </summary>
        public SoalCompilation WithOptions(SoalCompilationOptions options)
        {
            var  oldOptions                       = this.Options;
            bool reuseReferenceManager            = oldOptions.CanReuseCompilationReferenceManager(options);
            bool reuseSyntaxAndDeclarationManager = oldOptions.ScriptClassName == options.ScriptClassName &&
                                                    oldOptions.SourceReferenceResolver == options.SourceReferenceResolver;

            return(new SoalCompilation(
                       this.CompilationName,
                       options,
                       this.ExternalReferences,
                       this.PreviousSubmission,
                       this.SubmissionReturnType,
                       this.HostObjectType,
                       this.IsSubmission,
                       this.GetUnboundReferenceManager(),
                       reuseReferenceManager,
                       reuseSyntaxAndDeclarationManager ?
                       this.SyntaxAndDeclarations :
                       SyntaxAndDeclarationManager.Create(
                           this.SyntaxAndDeclarations.ExternalSyntaxTrees,
                           options.ScriptClassName,
                           options.SourceReferenceResolver,
                           this.SyntaxAndDeclarations.IsSubmission)));
        }
Exemple #2
0
 /// <summary>
 /// Creates a new compilation from scratch. Methods such as AddSyntaxTrees or AddReferences
 /// on the returned object will allow to continue building up the Compilation incrementally.
 /// </summary>
 /// <param name="name">Simple compilation name.</param>
 /// <param name="syntaxTrees">The syntax trees with the source code for the new compilation.</param>
 /// <param name="references">The references for the new compilation.</param>
 /// <param name="options">The compiler options to use.</param>
 /// <returns>A new compilation.</returns>
 public static SoalCompilation Create(
     string name,
     IEnumerable <SoalSyntaxTree> syntaxTrees   = null,
     IEnumerable <MetadataReference> references = null,
     SoalCompilationOptions options             = null)
 {
     return(Create(
                name,
                options ?? s_defaultOptions,
                syntaxTrees,
                references,
                previousSubmission: null,
                returnType: null,
                hostObjectType: null,
                isSubmission: false));
 }
Exemple #3
0
        /// <summary>
        /// Creates a new compilation that can be used in scripting.
        /// </summary>
        public static SoalCompilation CreateScriptCompilation(
            string name,
            SoalSyntaxTree syntaxTree = null,
            IEnumerable <MetadataReference> references = null,
            SoalCompilationOptions options             = null,
            SoalCompilation previousScriptCompilation  = null,
            Type returnType  = null,
            Type globalsType = null)
        {
            ValidateScriptCompilationParameters(previousScriptCompilation, returnType, ref globalsType);

            return(Create(
                       name,
                       options?.WithReferencesSupersedeLowerVersions(true) ?? s_defaultSubmissionOptions,
                       (syntaxTree != null) ? new[] { syntaxTree } : EmptyCollections.Enumerable <SoalSyntaxTree>(),
                       references,
                       previousScriptCompilation,
                       returnType,
                       globalsType,
                       isSubmission: true));
        }
Exemple #4
0
        private static SoalCompilation Create(
            string name,
            SoalCompilationOptions options,
            IEnumerable <SoalSyntaxTree> syntaxTrees,
            IEnumerable <MetadataReference> references,
            SoalCompilation previousSubmission,
            Type returnType,
            Type hostObjectType,
            bool isSubmission)
        {
            Debug.Assert(options != null);
            Debug.Assert(!isSubmission || options.ReferencesSupersedeLowerVersions);

            var validatedReferences = ValidateReferences <CompilationReference>(references);

            var compilation = new SoalCompilation(
                name,
                options,
                validatedReferences,
                previousSubmission,
                returnType,
                hostObjectType,
                isSubmission,
                referenceManager: null,
                reuseReferenceManager: false,
                syntaxAndDeclarations: SyntaxAndDeclarationManager.Create(
                    ImmutableArray <SyntaxTree> .Empty,
                    options.ScriptClassName,
                    options.SourceReferenceResolver,
                    isSubmission));

            if (syntaxTrees != null)
            {
                compilation = compilation.AddSyntaxTrees(syntaxTrees);
            }

            return(compilation);
        }