Example #1
0
        public void Compile()
        {
            if (_compilation == null)
            {
                ImmutableModel coreModel = MetaInstance.MModel;
                string         text      = File.ReadAllText(_inputFilePath);
                var            tree      = MetaSyntaxTree.ParseText(text, path: _inputFilePath);

                BinderFlags binderFlags = BinderFlags.IgnoreAccessibility;
                if (_compileMetaModelCore)
                {
                    BinderFlags binderFlags2 = BinderFlags.IgnoreMetaLibraryDuplicatedTypes;
                    binderFlags = binderFlags.UnionWith(binderFlags2);
                }
                MetaCompilationOptions options = new MetaCompilationOptions(MetaLanguage.Instance, OutputKind.NetModule, deterministic: true, concurrentBuild: true,
                                                                            topLevelBinderFlags: binderFlags);
                //MetaCompilationOptions options = new MetaCompilationOptions(MetaLanguage.Instance, OutputKind.NetModule, deterministic: true, concurrentBuild: false);
                var compilation = MetaCompilation.
                                  Create("MetaModelCompilation").
                                  AddSyntaxTrees(tree).
                                  AddReferences(
                    ModelReference.CreateFromModel(coreModel)
                    ).
                                  WithOptions(options);
                Interlocked.CompareExchange(ref _compilation, compilation, null);
            }
            _compilation.ForceComplete();
        }
Example #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="assemblyName">Simple assembly 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 MetaCompilation Create(
     string assemblyName,
     IEnumerable <SyntaxTree> syntaxTrees       = null,
     IEnumerable <MetadataReference> references = null,
     MetaCompilationOptions options             = null)
 {
     return(Create(
                assemblyName,
                options ?? s_defaultOptions,
                syntaxTrees,
                references,
                previousSubmission: null,
                returnType: null,
                hostObjectType: null,
                isSubmission: false));
 }
Example #3
0
 /// <summary>
 /// Creates a new compilation that can be used in scripting.
 /// </summary>
 public static MetaCompilation CreateScriptCompilation(
     string assemblyName,
     SyntaxTree syntaxTree = null,
     IEnumerable <MetadataReference> references = null,
     MetaCompilationOptions options             = null,
     MetaCompilation previousScriptCompilation  = null,
     Type returnType  = null,
     Type globalsType = null)
 {
     CheckSubmissionOptions(options);
     ValidateScriptCompilationParameters(previousScriptCompilation, returnType, ref globalsType);
     return(Create(
                assemblyName,
                options?.WithReferencesSupersedeLowerVersions(true) ?? s_defaultSubmissionOptions,
                (syntaxTree != null) ? new[] { syntaxTree } : NoSyntaxTrees,
                references,
                previousScriptCompilation,
                returnType,
                globalsType,
                isSubmission: true));
 }
Example #4
0
        private static MetaCompilation Create(
            string assemblyName,
            MetaCompilationOptions options,
            IEnumerable <SyntaxTree> syntaxTrees,
            IEnumerable <MetadataReference> references,
            MetaCompilation previousSubmission,
            Type returnType,
            Type hostObjectType,
            bool isSubmission)
        {
            Debug.Assert(options != null);
            Debug.Assert(!isSubmission || options.ReferencesSupersedeLowerVersions);
            var compilation = new MetaCompilation(
                assemblyName,
                options,
                references,
                previousSubmission,
                returnType,
                hostObjectType,
                isSubmission,
                referenceManager: null,
                reuseReferenceManager: false,
                syntaxAndDeclarations: new SyntaxAndDeclarationManager(
                    ImmutableArray <SyntaxTree> .Empty,
                    options.ScriptClassName,
                    options.SourceReferenceResolver,
                    options.Language,
                    isSubmission,
                    state: null));

            if (syntaxTrees != null)
            {
                compilation = compilation.AddSyntaxTrees(syntaxTrees);
            }
            return(compilation);
        }
Example #5
0
 /// <summary>
 /// Creates a new compilation with the specified compilation options.
 /// </summary>
 public MetaCompilation WithOptions(MetaCompilationOptions options) => (MetaCompilation)base.WithOptions(options);
Example #6
0
 protected MetaCompilation(string assemblyName, MetaCompilationOptions options, IEnumerable <MetadataReference> references, MetaCompilation previousSubmission, Type submissionReturnType, Type hostObjectType, bool isSubmission, ReferenceManager referenceManager, bool reuseReferenceManager, SyntaxAndDeclarationManager syntaxAndDeclarations, AsyncQueue <CompilationEvent> eventQueue = null)
     : base(assemblyName, options, references, previousSubmission, submissionReturnType, hostObjectType, isSubmission, referenceManager, reuseReferenceManager, syntaxAndDeclarations, eventQueue)
 {
 }
 public bool Equals(MetaCompilationOptions other)
 {
     return(base.Equals(other));
 }