public void Parse() { Clear(); var editor = MonoDevelop.Ide.IdeApp.Workbench.ActiveDocument; var project = ((editor != null && editor.HasProject) ? editor.Project : MonoDevelop.Ide.IdeApp.ProjectOperations.CurrentSelectedProject) as AbstractDProject; var file = FindTraceLogFileName(project); if (file == null) { profilerPadWidget.AddTracedFunction(0, 0, 0, 0, new DVariable { Name = trace_log + " not found.." }); return; } var ctxt = ResolutionContext.Create(DResolverWrapper.CreateParseCacheView(editor), null, null); StreamReader reader = File.OpenText(file); string line; while ((line = reader.ReadLine()) != null) { var m = traceFuncRegex.Match(line); if (m.Success) { var symName = m.Groups["name"].Value; if (symName.StartsWith("=")) { continue; } bool mightBeLegalUnresolvableSymbol; var dn = ExamTraceSymbol(symName, ctxt, out mightBeLegalUnresolvableSymbol); long v; if (dn != null || mightBeLegalUnresolvableSymbol) { profilerPadWidget.AddTracedFunction( long.TryParse(m.Groups["numcalls"].Value, out v) ? v : 0, long.TryParse(m.Groups["treetime"].Value, out v) ? v : 0, long.TryParse(m.Groups["functime"].Value, out v) ? v : 0, long.TryParse(m.Groups["percall"].Value, out v) ? v : 0, dn ?? new DVariable { Name = symName }); } } } }
public static ResolutionContext CreateContext(Document doc, bool pushFirstScope = true) { if (doc != null) { var ed = DResolverWrapper.CreateEditorData(doc); if (pushFirstScope) { return(new ResolutionContext(ed.ParseCache, new ConditionalCompilationFlags(ed), ed.SyntaxTree, ed.CaretLocation)); } return(new ResolutionContext(ed.ParseCache, new ConditionalCompilationFlags(ed))); } return(new ResolutionContext(DResolverWrapper.CreateParseCacheView(), new ConditionalCompilationFlags(VersionIdEvaluation.GetOSAndCPUVersions(), 1, true))); }
public override TooltipItem GetItem(TextEditor editor, int offset) { // Note: Normally, the document already should be open var doc = IdeApp.Workbench.GetDocument(editor.Document.FileName); if (doc == null) { return(null); } var ast = doc.GetDAst(); // Due the first note, the AST already should exist if (ast == null) { return(null); } // Get code cache var codeCache = DResolverWrapper.CreateParseCacheView(doc); // Create editor context var line = editor.GetLineByOffset(offset); var ed = new EditorData { CaretOffset = offset, CaretLocation = new CodeLocation(offset - line.Offset, editor.OffsetToLineNumber(offset)), ModuleCode = editor.Text, ParseCache = codeCache, SyntaxTree = ast }; // Let the engine build all contents LooseResolution.NodeResolutionAttempt att; ISyntaxRegion sr; var rr = LooseResolution.ResolveTypeLoosely(ed, out att, out sr, true); // Create tool tip item if (rr != null) { return(new TooltipItem(new TTI { t = rr, sr = sr }, offset, 1)); } return(null); }
public static void HandleLdOutput(AbstractDProject prj, BuildResult br, string linkerOutput) { var ctxt = ResolutionContext.Create(DResolverWrapper.CreateParseCacheView(prj), null, null); ctxt.ContextIndependentOptions = ResolutionOptions.IgnoreAllProtectionAttributes | ResolutionOptions.DontResolveBaseTypes | ResolutionOptions.DontResolveBaseClasses | ResolutionOptions.DontResolveAliases; foreach (Match m in ldErrorRegex.Matches(linkerOutput)) { var error = new BuildError(); var firstSymbolOccurring = ldMangleRegex.Match(m.Groups["err"].Value); if (firstSymbolOccurring.Success) { var mangledString = "_D" + firstSymbolOccurring.Groups["mangle"].Value; var associatedSymbol = DResolver.GetResultMember(Demangler.DemangleAndResolve(mangledString, ctxt)); if (associatedSymbol != null) { error.FileName = (associatedSymbol.NodeRoot as DModule).FileName; error.Line = associatedSymbol.Location.Line; error.Column = associatedSymbol.Location.Column; } } error.ErrorText = m.Groups["msg"].Value; if (string.IsNullOrWhiteSpace(error.ErrorText)) { error.ErrorText = m.Groups["err"].Value; } error.ErrorText = DemangleLdOutput(error.ErrorText); br.Append(error); } }
public override List <Change> PerformChanges(RefactoringOptions options, object prop) { #region Init var renameProperties = prop as RenameProperties; if (renameProperties == null) { return(null); } var changes = new List <Change>(); var doc = options.Document; if (doc == null) { return(null); } var ast = doc.GetDAst(); if (ast == null) { return(null); } var n = options.SelectedItem as INode; if (n == null) { return(null); } var project = doc.HasProject ? doc.Project as AbstractDProject : null; var parseCache = DResolverWrapper.CreateParseCacheView(project); var modules = new List <DModule>(); if (project == null) { modules.Add(ast); } else { foreach (var p in project.GetSourcePaths()) { modules.AddRange(GlobalParseCache.EnumModulesRecursively(p)); } } var ctxt = ResolutionContext.Create(parseCache, null, null); #endregion // Enumerate references foreach (var mod in modules) { if (mod == null) { continue; } var references = D_Parser.Refactoring.ReferencesFinder.SearchModuleForASTNodeReferences(mod, n, ctxt).ToList(); if (((DModule)n.NodeRoot).FileName == mod.FileName) { references.Insert(0, new IdentifierDeclaration(n.NameHash) { Location = n.NameLocation }); } if (references.Count < 1) { continue; } var txt = TextFileProvider.Instance.GetEditableTextFile(new FilePath(mod.FileName)); var prevReplacement = CodeLocation.Empty; foreach (ISyntaxRegion reference in references) { if (prevReplacement == reference.Location) { continue; } prevReplacement = reference.Location; changes.Add(new TextReplaceChange { FileName = mod.FileName, InsertedText = renameProperties.NewName, RemovedChars = n.Name.Length, Description = string.Format(GettextCatalog.GetString("Replace '{0}' with '{1}'"), n.Name, renameProperties.NewName), Offset = txt.GetPositionFromLineColumn(reference.Location.Line, reference.Location.Column) }); } } return(changes); }
static IEnumerable <SearchResult> FindReferences( AbstractDProject project, INode member, ISearchProgressMonitor monitor = null) { var searchResults = new List <SearchResult>(); var modules = new List <DModule>(); if (project != null) { foreach (var p in project.GetSourcePaths(IdeApp.Workspace.ActiveConfiguration)) { modules.AddRange(GlobalParseCache.EnumModulesRecursively(p, null)); } } else { modules.Add(IdeApp.Workbench.ActiveDocument.GetDAst()); } if (monitor != null) { monitor.BeginStepTask("Scan for references", modules.Count, 1); } List <ISyntaxRegion> references = null; var ctxt = ResolutionContext.Create(DResolverWrapper.CreateParseCacheView(project), null); foreach (var mod in modules) { if (mod == null) { continue; } try { references = ReferencesFinder.SearchModuleForASTNodeReferences(mod, member, ctxt).ToList(); if (references.Count < 1) { if (monitor != null) { monitor.Step(1); } continue; } // Sort the references by code location references.Sort(new IdLocationComparer()); // Get actual document code var targetDoc = TextFileProvider.Instance.GetTextEditorData(new FilePath(mod.FileName)); foreach (var reference in references) { CodeLocation loc; if (reference is AbstractTypeDeclaration) { loc = ((AbstractTypeDeclaration)reference).NonInnerTypeDependendLocation; } else if (reference is IExpression) { loc = reference.Location; } else if (reference is TemplateParameter) { loc = (reference as TemplateParameter).NameLocation; } else if (reference is INode) { loc = (reference as INode).NameLocation; } else { continue; } searchResults.Add(new SearchResult(new FileProvider(mod.FileName, project), targetDoc.LocationToOffset(loc.Line, loc.Column), member.Name.Length)); } } catch (Exception ex) { LoggingService.LogWarning("Error during reference search", ex); } if (monitor != null) { monitor.Step(1); } } if (monitor != null) { monitor.EndTask(); } return(searchResults); }
public static void HandleOptLinkOutput(AbstractDProject Project, BuildResult br, string linkerOutput) { var ctxt = ResolutionContext.Create(DResolverWrapper.CreateParseCacheView(Project), null, null); ctxt.ContextIndependentOptions = ResolutionOptions.IgnoreAllProtectionAttributes | ResolutionOptions.DontResolveBaseTypes | ResolutionOptions.DontResolveBaseClasses | ResolutionOptions.DontResolveAliases; foreach (Match match in optlinkRegex.Matches(linkerOutput)) { var error = new BuildError(); // Get associated D source file if (match.Groups["obj"].Success) { var obj = Project.GetAbsoluteChildPath(new FilePath(match.Groups["obj"].Value)).ChangeExtension(".d"); foreach (var pf in Project.Files) { if (pf.FilePath == obj) { error.FileName = pf.FilePath; break; } } } var msg = match.Groups["message"].Value; var symUndefMatch = symbolUndefRegex.Match(msg); if (symUndefMatch.Success && symUndefMatch.Groups["mangle"].Success) { var mangledSymbol = symUndefMatch.Groups["mangle"].Value; ITypeDeclaration qualifier; try { var resSym = Demangler.DemangleAndResolve(mangledSymbol, ctxt, out qualifier); if (resSym is DSymbol) { var ds = resSym as DSymbol; var ast = ds.Definition.NodeRoot as DModule; if (ast != null) { error.FileName = ast.FileName; } error.Line = ds.Definition.Location.Line; error.Column = ds.Definition.Location.Column; msg = ds.Definition.ToString(false, true); } else { msg = qualifier.ToString(); } } catch (Exception ex) { msg = "<log analysis error> " + ex.Message; } error.ErrorText = msg + " could not be resolved - library reference missing?"; } else { error.ErrorText = "Linker error " + match.Groups["code"].Value + " - " + msg; } br.Append(error); } }