示例#1
0
        internal ImmutableArray <Diagnostic> GetDiagnostics(CompilationStage stage, bool includeEarlierStages, CancellationToken cancellationToken)
        {
            var diagnostics = DiagnosticBag.GetInstance();

            GetDiagnostics(stage, includeEarlierStages, diagnostics, cancellationToken);
            return(diagnostics.ToReadOnlyAndFree());
        }
示例#2
0
 public CompilationErrorInfo(int id, int level, CompilationStage stage, string messageTemplate)
 {
     Id              = id;
     Level           = level;
     Stage           = stage;
     MessageTemplate = messageTemplate;
 }
示例#3
0
 public CompilationErrorInfo(int id, int level, CompilationStage stage, string messageTemplate)
 {
     Id = id;
     Level = level;
     Stage = stage;
     MessageTemplate = messageTemplate;
 }
示例#4
0
        public void DefineError(int id, int level, CompilationStage stage, string messageTemplate)
        {
            CodeContract.RequiresArgumentInRange(!m_errorInfoStore.Contains(id), "id", "Error id is duplicated");

            var errorInfo = new CompilationErrorInfo(id, level, stage, messageTemplate);
            m_errorInfoStore.Add(errorInfo);
        }
示例#5
0
        public void DefineError(int id, int level, CompilationStage stage, string messageTemplate)
        {
            CodeContract.RequiresArgumentInRange(!m_errorInfoStore.Contains(id), "id", "Error id is duplicated");

            var errorInfo = new CompilationErrorInfo(id, level, stage, messageTemplate);

            m_errorInfoStore.Add(errorInfo);
        }
示例#6
0
 public void compilationStageFinished(CompilationStage stage)
 {
     if (monitor.isCanceled())
     {
         throw new InterruptedException();
     }
     monitor.worked(1);
     ticks++;
 }
        internal ImmutableArray<Diagnostic> GetDiagnosticsForSyntaxTree(
            CompilationStage stage,
            SyntaxTree syntaxTree,
            TextSpan? filterSpanWithinTree,
            bool includeEarlierStages,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();

            var builder = DiagnosticBag.GetInstance();
            if (stage == CompilationStage.Parse || (stage > CompilationStage.Parse && includeEarlierStages))
            {
                var syntaxDiagnostics = syntaxTree.GetDiagnostics();
                syntaxDiagnostics = FilterDiagnosticsByLocation(syntaxDiagnostics, syntaxTree, filterSpanWithinTree);
                builder.AddRange(syntaxDiagnostics);
            }

            cancellationToken.ThrowIfCancellationRequested();
            if (stage == CompilationStage.Declare || (stage > CompilationStage.Declare && includeEarlierStages))
            {
                var declarationDiagnostics = GetSourceDeclarationDiagnostics(syntaxTree, filterSpanWithinTree, FilterDiagnosticsByLocation, cancellationToken);
                Debug.Assert(declarationDiagnostics.All(d => d.ContainsLocation(syntaxTree, filterSpanWithinTree)));
                builder.AddRange(declarationDiagnostics);
            }

            cancellationToken.ThrowIfCancellationRequested();

            if (stage == CompilationStage.Compile || (stage > CompilationStage.Compile && includeEarlierStages))
            {
                //remove some errors that don't have locations in the tree, like "no suitable main method."
                //Members in trees other than the one being examined are not compiled. This includes field
                //initializers which can result in 'field is never initialized' warnings for fields in partial 
                //types when the field is in a different source file than the one for which we're getting diagnostics. 
                //For that reason the bag must be also filtered by tree.
                IEnumerable<Diagnostic> methodBodyDiagnostics = GetDiagnosticsForMethodBodiesInTree(syntaxTree, filterSpanWithinTree, cancellationToken);

                // TODO: Enable the below commented assert and remove the filtering code in the next line.
                //       GetDiagnosticsForMethodBodiesInTree seems to be returning diagnostics with locations that don't satisfy the filter tree/span, this must be fixed.
                // Debug.Assert(methodBodyDiagnostics.All(d => DiagnosticContainsLocation(d, syntaxTree, filterSpanWithinTree)));
                methodBodyDiagnostics = FilterDiagnosticsByLocation(methodBodyDiagnostics, syntaxTree, filterSpanWithinTree);

                builder.AddRange(methodBodyDiagnostics);
            }

            // Before returning diagnostics, we filter warnings
            // to honor the compiler options (/nowarn, /warnaserror and /warn) and the pragmas.
            var result = DiagnosticBag.GetInstance();
            FilterAndAppendAndFreeDiagnostics(result, ref builder);
            return result.ToReadOnlyAndFree<Diagnostic>();
        }
        internal ImmutableArray<Diagnostic> GetDiagnostics(CompilationStage stage, bool includeEarlierStages, CancellationToken cancellationToken)
        {
            using (Logger.LogBlock(FunctionId.CSharp_Compilation_GetDiagnostics, message: this.AssemblyName, cancellationToken: cancellationToken))
            {
                var builder = DiagnosticBag.GetInstance();

                if (stage == CompilationStage.Parse || (stage > CompilationStage.Parse && includeEarlierStages))
                {
                    if (this.Options.ConcurrentBuild)
                    {
                        var parallelOptions = cancellationToken.CanBeCanceled
                                            ? new ParallelOptions() { CancellationToken = cancellationToken }
                                            : DefaultParallelOptions;

                        Parallel.For(0, this.SyntaxTrees.Length, parallelOptions,
                            i => builder.AddRange(this.SyntaxTrees[i].GetDiagnostics(cancellationToken)));
                    }
                    else
                    {
                        foreach (var syntaxTree in this.SyntaxTrees)
                        {
                            cancellationToken.ThrowIfCancellationRequested();
                            builder.AddRange(syntaxTree.GetDiagnostics(cancellationToken));
                        }
                    }
                }

                if (stage == CompilationStage.Declare || stage > CompilationStage.Declare && includeEarlierStages)
                {
                    builder.AddRange(Options.Errors);

                    cancellationToken.ThrowIfCancellationRequested();

                    // the set of diagnostics related to establishing references.
                    builder.AddRange(GetBoundReferenceManager().Diagnostics);

                    cancellationToken.ThrowIfCancellationRequested();

                    builder.AddRange(GetSourceDeclarationDiagnostics(cancellationToken: cancellationToken));
                }

                cancellationToken.ThrowIfCancellationRequested();

                if (stage == CompilationStage.Compile || stage > CompilationStage.Compile && includeEarlierStages)
                {
                    var methodBodyDiagnostics = DiagnosticBag.GetInstance();
                    GetDiagnosticsForAllMethodBodies(cancellationToken, methodBodyDiagnostics);
                    builder.AddRangeAndFree(methodBodyDiagnostics);
                }

                // Before returning diagnostics, we filter warnings
                // to honor the compiler options (e.g., /nowarn, /warnaserror and /warn) and the pragmas.
                var result = DiagnosticBag.GetInstance();
                FilterAndAppendAndFreeDiagnostics(result, ref builder);
                return result.ToReadOnlyAndFree<Diagnostic>();
            }
        }
示例#9
0
        internal ImmutableArray <Diagnostic> GetDiagnostics(CompilationStage stage, bool includeEarlierStages, CancellationToken cancellationToken)
        {
            var builder = DiagnosticBag.GetInstance();

            // Parse
            if (stage == CompilationStage.Parse || (stage > CompilationStage.Parse && includeEarlierStages))
            {
                var syntaxTrees = this.SyntaxTrees;
                if (this.Options.ConcurrentBuild)
                {
                    Parallel.ForEach(syntaxTrees, UICultureUtilities.WithCurrentUICulture <PhpSyntaxTree>(syntaxTree =>
                    {
                        builder.AddRange(syntaxTree.GetDiagnostics(cancellationToken));
                    }));
                }
                else
                {
                    foreach (var syntaxTree in syntaxTrees)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        builder.AddRange(syntaxTree.GetDiagnostics(cancellationToken));
                    }
                }
            }

            // Declare
            if (stage == CompilationStage.Declare || stage > CompilationStage.Declare && includeEarlierStages)
            {
                // CheckAssemblyName(builder);
                builder.AddRange(Options.Errors);
                builder.AddRange(Options.Diagnostics);

                cancellationToken.ThrowIfCancellationRequested();

                // the set of diagnostics related to establishing references.
                builder.AddRange(GetBoundReferenceManager().Diagnostics);

                //cancellationToken.ThrowIfCancellationRequested();

                try
                {
                    // TODO: cancellationToken
                    builder.AddRange(this.BindAndAnalyseTask().Result.AsImmutable());
                }
                catch (AggregateException e) when(e.InnerException != null)
                {
                    // unwrap the aggregate exception, keep original stacktrace
                    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                }

                cancellationToken.ThrowIfCancellationRequested();

                // resolve entry point
                this.GetEntryPoint(cancellationToken);

                //
                builder.AddRange(_lazyDeclarationDiagnostics?.AsEnumerable() ?? Enumerable.Empty <Diagnostic>());
            }

            cancellationToken.ThrowIfCancellationRequested();

            // Compile
            if (stage == CompilationStage.Compile || stage > CompilationStage.Compile && includeEarlierStages)
            {
                var methodBodyDiagnostics = DiagnosticBag.GetInstance();
                // TODO: perform compilation and report diagnostics
                // GetDiagnosticsForAllMethodBodies(methodBodyDiagnostics, cancellationToken);
                builder.AddRangeAndFree(methodBodyDiagnostics);
            }

            // Before returning diagnostics, we filter warnings
            // to honor the compiler options (e.g., /nowarn, /warnaserror and /warn) and the pragmas.
            var result = DiagnosticBag.GetInstance();

            FilterAndAppendAndFreeDiagnostics(result, ref builder);
            return(result.ToReadOnlyAndFree <Diagnostic>());
        }
        private void GetCodeDirectoryInformationInternal(VirtualPath virtualCodeDir,
            out Type codeDomProviderType, out CompilerParameters compilerParameters,
            out string generatedFilesDir) {

            StringSet excludedSubdirectories = null;

            CodeDirectoryType dirType;

            // Get the DirectoryType based on the path
            if (virtualCodeDir == HttpRuntime.CodeDirectoryVirtualPath) {

                // If it's the top level code directory, make sure we exclude any
                // subdirectories that are compiled separately
                EnsureExcludedCodeSubDirectoriesComputed();

                excludedSubdirectories = _excludedCodeSubdirectories;

                dirType = CodeDirectoryType.MainCode;

                _compilationStage = CompilationStage.TopLevelFiles;
            }
            else if (virtualCodeDir == HttpRuntime.ResourcesDirectoryVirtualPath) {

                dirType = CodeDirectoryType.AppResources;

                _compilationStage = CompilationStage.TopLevelFiles;
            }
            // If virtualCodeDir is a subdir of WebReference virtual path.
            else if (String.Compare(virtualCodeDir.VirtualPathString, 0,
                HttpRuntime.WebRefDirectoryVirtualPath.VirtualPathString, 0, HttpRuntime.WebRefDirectoryVirtualPath.VirtualPathString.Length,
                StringComparison.OrdinalIgnoreCase) == 0) {

                // Use the top WebReference directory info for its sub directories.
                virtualCodeDir = HttpRuntime.WebRefDirectoryVirtualPath;
                dirType = CodeDirectoryType.WebReferences;

                _compilationStage = CompilationStage.TopLevelFiles;
            }
            else if (String.Compare(virtualCodeDir.FileName, HttpRuntime.LocalResourcesDirectoryName,
                StringComparison.OrdinalIgnoreCase) == 0) {

                dirType = CodeDirectoryType.LocalResources;

                // LocalResources are compiled *after* top level files
                _compilationStage = CompilationStage.AfterTopLevelFiles;
            }
            else {
                // If all else fails, treat it as a sub directory
                // 
                dirType = CodeDirectoryType.SubCode;

                // Sub-code dirs are compiled *before* the main code dir
                _compilationStage = CompilationStage.TopLevelFiles;
            }

            Debug.Assert(virtualCodeDir.HasTrailingSlash);
            AssemblyReferenceInfo info = TheBuildManager.TopLevelAssembliesIndexTable[virtualCodeDir.VirtualPathString];
            if (info == null) {
                throw new InvalidOperationException(
                    SR.GetString(SR.Invalid_CodeSubDirectory_Not_Exist, virtualCodeDir));
            }

            // Get the info we need for this code directory
            CodeDirectoryCompiler.GetCodeDirectoryInformation(
                virtualCodeDir, dirType, excludedSubdirectories, info.ReferenceIndex,
                out codeDomProviderType, out compilerParameters,
                out generatedFilesDir);

            Assembly resultAssembly = info.Assembly;

            if (resultAssembly != null) {
                // Use the runtime generated assembly location. VSWhidbey 400335
                compilerParameters.OutputAssembly = resultAssembly.Location;
            }
        }
        internal void GetCodeDirectoryInformation(VirtualPath virtualCodeDir,
            out Type codeDomProviderType, out CompilerParameters compilerParameters,
            out string generatedFilesDir) {

            // Backup the compilation stage, since the call will modify it
            CompilationStage savedCompilationStage = _compilationStage;

            try {
                GetCodeDirectoryInformationInternal(virtualCodeDir, out codeDomProviderType,
                    out compilerParameters, out generatedFilesDir);
            }
            finally {
                // Restore the compilation stage
                _compilationStage = savedCompilationStage;
            }
        }
        internal void EnsureTopLevelFilesCompiled() {
            if (PreStartInitStage != Compilation.PreStartInitStage.AfterPreStartInit) {
                throw new InvalidOperationException(SR.GetString(SR.Method_cannot_be_called_during_pre_start_init));
            }

            // This should never get executed in non-hosted appdomains
            Debug.Assert(HostingEnvironment.IsHosted);

            // If we already tried and got an exception, just rethrow it
            if (_topLevelFileCompilationException != null && !SkipTopLevelCompilationExceptions) {
                ReportTopLevelCompilationException();
            }

            if (_topLevelFilesCompiledStarted)
                return;

            // Set impersonation to hosting identity (process or UNC)
            using (new ApplicationImpersonationContext()) {
                bool gotLock = false;
                _parseErrorReported = false;

                try {
                    // Grab the compilation mutex, since this method accesses the codegen files
                    CompilationLock.GetLock(ref gotLock);

                    // Check again if there is an exception
                    if (_topLevelFileCompilationException != null && !SkipTopLevelCompilationExceptions) {
                        ReportTopLevelCompilationException();
                    }

                    // Check again if we're done
                    if (_topLevelFilesCompiledStarted)
                        return;

                    _topLevelFilesCompiledStarted = true;
                    _topLevelAssembliesIndexTable =
                        new Dictionary<String, AssemblyReferenceInfo>(StringComparer.OrdinalIgnoreCase);

                    _compilationStage = CompilationStage.TopLevelFiles;

                    CompileResourcesDirectory();
                    CompileWebRefDirectory();
                    CompileCodeDirectories();

                    _compilationStage = CompilationStage.GlobalAsax;

                    CompileGlobalAsax();

                    _compilationStage = CompilationStage.BrowserCapabilities;

                    // Call GetBrowserCapabilitiesType() to make sure browserCap directory is compiled
                    // early on.  This avoids getting into potential deadlock situations later (VSWhidbey 530732).
                    // For the same reason, get the EmptyHttpCapabilitiesBase.
                    BrowserCapabilitiesCompiler.GetBrowserCapabilitiesType();
                    IFilterResolutionService dummy = HttpCapabilitiesBase.EmptyHttpCapabilitiesBase;

                    _compilationStage = CompilationStage.AfterTopLevelFiles;
                }
                catch (Exception e) {
                    // Remember the exception, and rethrow it
                    _topLevelFileCompilationException = e;

                    // Do not rethrow the exception since so CBM can still provide partial support
                    if (!SkipTopLevelCompilationExceptions) {

                        if (!_parseErrorReported) {
                            // Report the error if this is not a CompileException. CompileExceptions are handled
                            // directly by the AssemblyBuilder already.
                            if (!(e is HttpCompileException)) {
                                ReportTopLevelCompilationException();
                            }
                        }

                        throw;
                    }
                }
                finally {
                    _topLevelFilesCompiledCompleted = true;

                    // Always release the mutex if we had taken it
                    if (gotLock) {
                        CompilationLock.ReleaseLock();
                    }
                }
            }
        }
        public CompilerResults() {
            this.codeErrorManager = new CodeErrorManager();
            this.classFiles = new HashMap<String, byte[]>();
			this.compilationStage = CompilationStage.None;
        }
			public void compilationStageFinished(CompilationStage stage) {
				if (monitor.isCanceled()) {
					throw new InterruptedException();
				}
				monitor.worked(1);
				ticks++;
			}