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 static DNode ExamTraceSymbol(string symName, ResolutionContext ctxt, out bool mightBeLegalUnresolvableSymbol) { DSymbol ds = null; mightBeLegalUnresolvableSymbol = false; if (string.IsNullOrWhiteSpace(symName)) { return(null); } // Try to handle a probably mangled string or C function. if (symName.StartsWith("_")) { try{ ds = Demangler.DemangleAndResolve(symName, ctxt) as DSymbol; }catch {} } // Stuff like void std.stdio.File.LockingTextWriter.put!(immutable(char)[]).put(immutable(char)[]) if (ds == null && Lexer.IsIdentifierPart((int)symName[0])) { mightBeLegalUnresolvableSymbol = true; ITypeDeclaration q; var method = DParser.ParseMethodDeclarationHeader(symName, out q); q = Demangler.RemoveNestedTemplateRefsFromQualifier(q); method.Type = Demangler.RemoveNestedTemplateRefsFromQualifier(method.Type); var methodType = TypeDeclarationResolver.GetMethodReturnType(method, ctxt); var methodParameters = new List <AbstractType>(); if (method.Parameters != null && method.Parameters.Count != 0) { foreach (var parm in method.Parameters) { methodParameters.Add(TypeDeclarationResolver.ResolveSingle(Demangler.RemoveNestedTemplateRefsFromQualifier(parm.Type), ctxt)); } } ctxt.ContextIndependentOptions |= ResolutionOptions.IgnoreAllProtectionAttributes; var overloads = TypeDeclarationResolver.Resolve(q, ctxt); if (overloads == null || overloads.Length == 0) { return(null); } else if (overloads.Length == 1) { ds = overloads[0] as DSymbol; } else { foreach (var o in overloads) { ds = o as DSymbol; if (ds == null || !(ds.Definition is DMethod)) { continue; } var dm = ds.Definition as DMethod; // Compare return types if (dm.Type != null) { if (methodType == null || ds.Base == null || !ResultComparer.IsEqual(methodType, ds.Base)) { continue; } } else if (dm.Type == null && methodType != null) { return(null); } // Compare parameters if (methodParameters.Count != dm.Parameters.Count) { continue; } for (int i = 0; i < methodParameters.Count; i++) { if (!ResultComparer.IsImplicitlyConvertible(methodParameters[i], TypeDeclarationResolver.ResolveSingle(Demangler.RemoveNestedTemplateRefsFromQualifier(dm.Parameters[i].Type), ctxt))) { continue; } } } } } if (ds != null) { return(ds.Definition); } return(null); }
public static DNode ExamTraceSymbol(string symName, ResolutionContext ctxt, out bool mightBeLegalUnresolvableSymbol) { DSymbol ds = null; mightBeLegalUnresolvableSymbol = false; if (string.IsNullOrWhiteSpace(symName)) { return(null); } // Try to handle a probably mangled string or C function. if (symName.StartsWith("_")) { try{ ds = Demangler.DemangleAndResolve(symName, ctxt) as DSymbol; }catch {} } // Stuff like void std.stdio.File.LockingTextWriter.put!(immutable(char)[]).put(immutable(char)[]) if (ds == null && Lexer.IsIdentifierPart((int)symName[0])) { mightBeLegalUnresolvableSymbol = true; ITypeDeclaration q; var method = DParser.ParseMethodDeclarationHeader(symName, out q); q = Demangler.RemoveNestedTemplateRefsFromQualifier(q); AbstractType[] overloads = null; D_Parser.Completion.CodeCompletion.DoTimeoutableCompletionTask(null, ctxt, () => { try { overloads = AmbiguousType.TryDissolve(LooseResolution.LookupIdRawly(ctxt.ParseCache, q, ctxt.ScopedBlock.NodeRoot as DModule)).ToArray(); } catch (Exception ex) { MonoDevelop.Core.LoggingService.LogWarning("Error during trace.log symbol resolution of " + q.ToString(), ex); } }); if (overloads == null || overloads.Length == 0) { return(null); } else if (overloads.Length == 1) { ds = overloads[0] as DSymbol; } else { method.Type = Demangler.RemoveNestedTemplateRefsFromQualifier(method.Type); var methodType = TypeDeclarationResolver.GetMethodReturnType(method, ctxt); var methodParameters = new List <AbstractType>(); D_Parser.Completion.CodeCompletion.DoTimeoutableCompletionTask(null, ctxt, () => { if (method.Parameters != null && method.Parameters.Count != 0) { foreach (var parm in method.Parameters) { methodParameters.Add(TypeDeclarationResolver.ResolveSingle(Demangler.RemoveNestedTemplateRefsFromQualifier(parm.Type), ctxt)); } } }); foreach (var o in overloads) { ds = o as DSymbol; if (ds == null || !(ds.Definition is DMethod)) { continue; } var dm = ds.Definition as DMethod; // Compare return types if (dm.Type != null) { if (methodType == null || ds.Base == null || !ResultComparer.IsEqual(methodType, ds.Base)) { continue; } } else if (dm.Type == null && methodType != null) { return(null); } // Compare parameters if (methodParameters.Count != dm.Parameters.Count) { continue; } for (int i = 0; i < methodParameters.Count; i++) { if (!ResultComparer.IsImplicitlyConvertible(methodParameters[i], TypeDeclarationResolver.ResolveSingle(Demangler.RemoveNestedTemplateRefsFromQualifier(dm.Parameters[i].Type), ctxt))) { continue; } } } } } return(ds != null ? ds.Definition : null); }
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); } }