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))); } }
public override void PostWalkIncludeDirective(IncludeDirectiveSyntax includeDirectiveSyntax) { MethodsCalled["PostWalkIncludeDirective"]=true; }
// IncludeDirectiveSyntax public override bool WalkIncludeDirective(IncludeDirectiveSyntax includeDirectiveSyntax) { MethodsCalled["WalkIncludeDirective"]=true; return true; }