示例#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();
        }
示例#2
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));
 }
示例#3
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);
        }
示例#4
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)
 {
 }