void ProcessIncludeDirective(IncludeDirectiveSyntax includeDirectiveSyntax, CancellationToken cancellationToken) { var location = includeDirectiveSyntax.StringLiteral.GetLocation(); try { var filePath = includeDirectiveSyntax.StringLiteral.ToString().Trim('"'); if(!Path.IsPathRooted(filePath)) { var directory = includeDirectiveSyntax.SyntaxTree.FileInfo?.Directory; if (directory == null || !directory.Exists) { _diagnostics.Add(new Diagnostic( location, DiagnosticDescriptors.Semantic.Nav0003SourceFileNeedsToBeSavedBeforeIncludeDirectiveCanBeProcessed)); return; } filePath = Path.Combine(directory.FullName, filePath); } if(!File.Exists(filePath)) { _diagnostics.Add(new Diagnostic( location, DiagnosticDescriptors.Semantic.Nav0004File0NotFound, filePath) ); return; } else { // FileInfo löst relative Pfadangaben auf... var fileInfo = new FileInfo(filePath); filePath = fileInfo.FullName; } // nav File inkludiert sich selbst if (String.Equals(includeDirectiveSyntax.SyntaxTree.FileInfo?.FullName, filePath, StringComparison.OrdinalIgnoreCase)) { _diagnostics.Add(new Diagnostic( location, DiagnosticDescriptors.DeadCode.Nav1006SelfReferencingIncludeNotRequired)); return; } var includeFileSyntax = SyntaxTree.FromFile(filePath, cancellationToken); var fileLocation = new Location(filePath); var result = FromCompilationUnit(includeFileSyntax.GetRoot() as CompilationUnitSyntax, processAsIncludedFile: true, cancellationToken: cancellationToken); var diagnostics = includeFileSyntax.Diagnostics.Union(result.Diagnostics).ToList(); var include = new IncludeSymbol(filePath, location, fileLocation, includeDirectiveSyntax, diagnostics, result.TaskDeklarations); AddInclude(include); } catch(OperationCanceledException) { throw; } catch(Exception ex) { _diagnostics.Add(new Diagnostic(location, DiagnosticDescriptors.NewInternalError(ex))); } }
void AddInclude(IncludeSymbol include) { var existing = _includes.TryFindSymbol(include); if (existing!=null) { _diagnostics.Add(new Diagnostic( include.Location, DiagnosticDescriptors.DeadCode.Nav1001IncludeDirectiveForFile0AppearedPreviously, include.FileName)); } else { _includes.Add(include); if(include.Diagnostics.HasErrors()) { _diagnostics.Add(new Diagnostic( include.Location, DiagnosticDescriptors.Semantic.Nav0005IncludeFile0HasSomeErrors, include.FileName)); } foreach (var decl in include.TaskDeklarations) { AddTaskDeclaration(decl); } } }