private SyntaxTree?ParseFile( CSharpParseOptions parseOptions, CSharpParseOptions scriptParseOptions, ref bool addedDiagnostics, CommandLineSourceFile file, DiagnosticBag diagnostics, out string normalizedFilePath) { var fileDiagnostics = new List <DiagnosticInfo>(); var content = TryReadFileContent(file, fileDiagnostics, out normalizedFilePath); if (content == null) { foreach (var info in fileDiagnostics) { diagnostics.Add(MessageProvider.CreateDiagnostic(info)); } fileDiagnostics.Clear(); addedDiagnostics = true; return(null); } else { Debug.Assert(fileDiagnostics.Count == 0); return(ParseFile(parseOptions, scriptParseOptions, content, file)); } }
private PhpSyntaxTree ParseFile( TextWriter consoleOutput, PhpParseOptions parseOptions, PhpParseOptions scriptParseOptions, ref bool hadErrors, CommandLineSourceFile file, ErrorLogger errorLogger) { var diagnosticInfos = new List <DiagnosticInfo>(); var content = ReadFileContent(file, diagnosticInfos); if (diagnosticInfos.Count != 0) { ReportErrors(diagnosticInfos, consoleOutput, errorLogger); hadErrors = true; } PhpSyntaxTree result = null; if (content != null) { result = PhpSyntaxTree.ParseCode(content.ToString(), parseOptions, scriptParseOptions, file.Path); } if (result != null && result.Diagnostics.Length != 0) { ReportErrors(result.Diagnostics, consoleOutput, errorLogger); hadErrors = true; } return(result); }
private static SourceUnit ParseFile( TextWriter consoleOutput, PhpParseOptions parseOptions, PhpParseOptions scriptParseOptions, SourceText content, CommandLineSourceFile file) { // TODO: new parser implementation based on Roslyn // TODO: file.IsScript ? scriptParseOptions : parseOptions var tree = CodeSourceUnit.ParseCode(content.ToString(), file.Path, new TextErrorSink(consoleOutput)); return(tree); }
private static SyntaxTree ParseFile( CSharpParseOptions parseOptions, CSharpParseOptions scriptParseOptions, SourceText content, CommandLineSourceFile file) { var tree = SyntaxFactory.ParseSyntaxTree( content, file.IsScript ? scriptParseOptions : parseOptions, file.Path); // prepopulate line tables. // we will need line tables anyways and it is better to not wait until we are in emit // where things run sequentially. bool isHiddenDummy; tree.GetMappedLineSpanAndVisibility(default(TextSpan), out isHiddenDummy); return tree; }
private SyntaxTree ParseFile(TextWriter consoleOutput, CSharpParseOptions parseOptions, CSharpParseOptions scriptParseOptions, ref bool hadErrors, CommandLineSourceFile file, out string normalizedFilePath) { var fileReadDiagnostics = new List <DiagnosticInfo>(); var content = ReadFileContent(file, fileReadDiagnostics, Arguments.Encoding, out normalizedFilePath); if (content == null) { PrintErrors(fileReadDiagnostics, consoleOutput); fileReadDiagnostics.Clear(); hadErrors = true; return(null); } else { return(ParseFile(parseOptions, scriptParseOptions, content, file)); } }
private SourceUnit ParseFile( TextWriter consoleOutput, PhpParseOptions parseOptions, PhpParseOptions scriptParseOptions, ref bool hadErrors, CommandLineSourceFile file, ErrorLogger errorLogger) { var fileReadDiagnostics = new List <DiagnosticInfo>(); var content = ReadFileContent(file, fileReadDiagnostics); if (content == null) { ReportErrors(fileReadDiagnostics, consoleOutput, errorLogger); fileReadDiagnostics.Clear(); hadErrors = true; return(null); } else { return(ParseFile(consoleOutput, parseOptions, scriptParseOptions, content, file)); } }
private static SyntaxTree ParseFile( CSharpParseOptions parseOptions, CSharpParseOptions scriptParseOptions, SourceText content, CommandLineSourceFile file, AnalyzerConfigOptionsResult?analyzerConfigOptionsResult) { ImmutableDictionary <string, ReportDiagnostic> diagnosticOptions; bool?isUserConfiguredGeneratedCode; if (analyzerConfigOptionsResult.HasValue) { diagnosticOptions = analyzerConfigOptionsResult.Value.TreeOptions; isUserConfiguredGeneratedCode = GeneratedCodeUtilities.GetIsGeneratedCodeFromOptions(analyzerConfigOptionsResult.Value.AnalyzerOptions); } else { diagnosticOptions = null; isUserConfiguredGeneratedCode = null; } var tree = SyntaxFactory.ParseSyntaxTree( content, file.IsScript ? scriptParseOptions : parseOptions, file.Path, diagnosticOptions, isUserConfiguredGeneratedCode); // prepopulate line tables. // we will need line tables anyways and it is better to not wait until we are in emit // where things run sequentially. bool isHiddenDummy; tree.GetMappedLineSpanAndVisibility(default(TextSpan), out isHiddenDummy); return(tree); }
private ParsedSource ParseFile( TextWriter consoleOutput, PhpParseOptions parseOptions, PhpParseOptions scriptParseOptions, ref bool hadErrors, CommandLineSourceFile file, ErrorLogger errorLogger) { if (file.Path.IsPharFile()) { // phar file archive var phar = Devsense.PHP.Phar.PharFile.OpenPharFile(file.Path); // TODO: report exception // treat the stub as a regular source code: var stub = PhpSyntaxTree.ParseCode(SourceText.From(GetPharStub(phar), Encoding.UTF8), parseOptions, scriptParseOptions, file.Path); // TODO: ConcurrentBuild -> Parallel var prefix = PhpFileUtilities.NormalizeSlashes(PhpFileUtilities.GetRelativePath(file.Path, Arguments.BaseDirectory)); var trees = new List <PhpSyntaxTree>(); var content = new List <Devsense.PHP.Phar.Entry>(); foreach (var entry in phar.Manifest.Entries.Values) { var entryName = PhpFileUtilities.NormalizeSlashes(entry.Name); if (entry.IsCompileEntry()) { var tree = PhpSyntaxTree.ParseCode(SourceText.From(entry.Code, Encoding.UTF8), parseOptions, scriptParseOptions, prefix + "/" + entryName); tree.PharStubFile = stub; trees.Add(tree); } else { content.Add(entry); } } // create resource file var resources = new ResourceDescription($"phar://{prefix}.resources", () => { var stream = new MemoryStream(); var writer = new System.Resources.ResourceWriter(stream); foreach (var entry in content) { var entryName = PhpFileUtilities.NormalizeSlashes(entry.Name); writer.AddResource(entryName, entry.Code); } // writer.Generate(); stream.Position = 0; return(stream); }, isPublic: true); // TODO: report errors if any return(new ParsedSource { SyntaxTree = stub, Manifest = phar.Manifest, Trees = trees, Resources = resources, }); } else { // single source file var diagnosticInfos = new List <DiagnosticInfo>(); var content = TryReadFileContent(file, diagnosticInfos); if (diagnosticInfos.Count != 0) { ReportErrors(diagnosticInfos, consoleOutput, errorLogger); hadErrors = true; } PhpSyntaxTree result = null; if (content != null) { result = PhpSyntaxTree.ParseCode(content, parseOptions, scriptParseOptions, file.Path); } if (result != null && result.Diagnostics.HasAnyErrors()) { ReportErrors(result.Diagnostics, consoleOutput, errorLogger); hadErrors = true; } return(new ParsedSource { SyntaxTree = result }); } }
private SyntaxTree ParseFile( TextWriter consoleOutput, CSharpParseOptions parseOptions, CSharpParseOptions scriptParseOptions, ref bool hadErrors, CommandLineSourceFile file, ErrorLogger errorLogger, out string normalizedFilePath) { var fileReadDiagnostics = new List<DiagnosticInfo>(); var content = ReadFileContent(file, fileReadDiagnostics, out normalizedFilePath); if (content == null) { ReportErrors(fileReadDiagnostics, consoleOutput, errorLogger); fileReadDiagnostics.Clear(); hadErrors = true; return null; } else { return ParseFile(parseOptions, scriptParseOptions, content, file); } }
private SyntaxTree ParseFile( CSharpParseOptions parseOptions, CSharpParseOptions scriptParseOptions, ref bool addedDiagnostics, CommandLineSourceFile file, DiagnosticBag diagnostics, out string normalizedFilePath) { var fileDiagnostics = new List<DiagnosticInfo>(); var content = TryReadFileContent(file, fileDiagnostics, out normalizedFilePath); if (content == null) { foreach (var info in fileDiagnostics) { diagnostics.Add(MessageProvider.CreateDiagnostic(info)); } fileDiagnostics.Clear(); addedDiagnostics = true; return null; } else { Debug.Assert(fileDiagnostics.Count == 0); return ParseFile(parseOptions, scriptParseOptions, content, file); } }
private SyntaxTree ParseFile( TextWriter consoleOutput, CSharpParseOptions parseOptions, CSharpParseOptions scriptParseOptions, ref bool hadErrors, CommandLineSourceFile file, out string normalizedFilePath) { var fileReadDiagnostics = new List<DiagnosticInfo>(); var content = ReadFileContent(file, fileReadDiagnostics, Arguments.Encoding, Arguments.ChecksumAlgorithm, out normalizedFilePath); if (content == null) { PrintErrors(fileReadDiagnostics, consoleOutput); fileReadDiagnostics.Clear(); hadErrors = true; return null; } else { return ParseFile(parseOptions, scriptParseOptions, content, file); } }