protected override bool VerifyClsCompliance() { if (!base.VerifyClsCompliance()) { return(false); } switch (UnderlyingType.BuiltinType) { case BuiltinTypeSpec.Type.UInt: case BuiltinTypeSpec.Type.ULong: case BuiltinTypeSpec.Type.UShort: Report.Warning(3009, 1, Location, "`{0}': base type `{1}' is not CLS-compliant", GetSignatureForError(), UnderlyingType.GetSignatureForError()); break; } return(true); }
protected override bool CheckBase() { if (!base.CheckBase()) { return(false); } MemberSpec candidate; bool overrides = false; var conflict_symbol = MemberCache.FindBaseMember(this, out candidate, ref overrides); if (conflict_symbol == null) { conflict_symbol = candidate; } if (conflict_symbol == null) { if ((ModFlags & Modifiers.NEW) != 0) { Report.Warning(109, 4, Location, "The member `{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError()); } } else { if ((ModFlags & (Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.BACKING_FIELD)) == 0) { Report.SymbolRelatedToPreviousError(conflict_symbol); Report.Warning(108, 2, Location, "`{0}' hides inherited member `{1}'. Use the new keyword if hiding was intended", GetSignatureForError(), conflict_symbol.GetSignatureForError()); } if (conflict_symbol.IsAbstract) { Report.SymbolRelatedToPreviousError(conflict_symbol); Report.Error(533, Location, "`{0}' hides inherited abstract member `{1}'", GetSignatureForError(), conflict_symbol.GetSignatureForError()); } } return(true); }
XmlNode GetDocCommentNode(MemberCore mc, string name) { // FIXME: It could be even optimizable as not // to use XmlDocument. But anyways the nodes // are not kept in memory. XmlDocument doc = XmlDocumentation; try { XmlElement el = doc.CreateElement("member"); el.SetAttribute("name", name); string normalized = mc.DocComment; el.InnerXml = normalized; // csc keeps lines as written in the sources // and inserts formatting indentation (which // is different from XmlTextWriter.Formatting // one), but when a start tag contains an // endline, it joins the next line. We don't // have to follow such a hacky behavior. string [] split = normalized.Split('\n'); int j = 0; for (int i = 0; i < split.Length; i++) { string s = split [i].TrimEnd(); if (s.Length > 0) { split [j++] = s; } } el.InnerXml = line_head + String.Join( line_head, split, 0, j); return(el); } catch (Exception ex) { Report.Warning(1570, 1, mc.Location, "XML documentation comment on `{0}' is not well-formed XML markup ({1})", mc.GetSignatureForError(), ex.Message); return(doc.CreateComment(String.Format("FIXME: Invalid documentation markup was found for member {0}", name))); } }
// // Generates xml doc comments (if any), and if required, // handle warning report. // internal virtual void GenerateDocComment(DocumentationBuilder builder) { if (DocComment == null) { if (IsExposedFromAssembly()) { if (!(this is Constructor c) || !c.IsDefault()) { Report.Warning(1591, 4, Location, "Missing XML comment for publicly visible type or member `{0}'", GetSignatureForError()); } } return; } try { builder.GenerateDocumentationForMember(this); } catch (Exception e) { throw new InternalErrorException(this, e); } }
// // Processes "see" or "seealso" elements from cref attribute. // void HandleXrefCommon(MemberCore mc, XmlElement xref) { string cref = xref.GetAttribute("cref"); // when, XmlReader, "if (cref == null)" if (!xref.HasAttribute("cref")) { return; } // Nothing to be resolved the reference is marked explicitly if (cref.Length > 2 && cref [1] == ':') { return; } // Additional symbols for < and > are allowed for easier XML typing cref = cref.Replace('{', '<').Replace('}', '>'); var encoding = module.Compiler.Settings.Encoding; var s = new MemoryStream(encoding.GetBytes(cref)); var source_file = new CompilationSourceFile(doc_module, mc.Location.SourceFile); var report = new Report(doc_module.Compiler, new NullReportPrinter()); if (session == null) { session = new ParserSession { UseJayGlobalArrays = true } } ; SeekableStreamReader seekable = new SeekableStreamReader(s, encoding, session.StreamReaderBuffer); var parser = new CSharpParser(seekable, source_file, report, session); ParsedParameters = null; ParsedName = null; ParsedBuiltinType = null; ParsedOperator = null; parser.Lexer.putback_char = Tokenizer.DocumentationXref; parser.Lexer.parsing_generic_declaration_doc = true; parser.parse(); if (report.Errors > 0) { Report.Warning(1584, 1, mc.Location, "XML comment on `{0}' has syntactically incorrect cref attribute `{1}'", mc.GetSignatureForError(), cref); xref.SetAttribute("cref", "!:" + cref); return; } MemberSpec member; string prefix = null; FullNamedExpression fne = null; // // Try built-in type first because we are using ParsedName as identifier of // member names on built-in types // if (ParsedBuiltinType != null && (ParsedParameters == null || ParsedName != null)) { member = ParsedBuiltinType.Type; } else { member = null; } if (ParsedName != null || ParsedOperator.HasValue) { TypeSpec type = null; string member_name = null; if (member == null) { if (ParsedOperator.HasValue) { type = mc.CurrentType; } else if (ParsedName.Left != null) { fne = ResolveMemberName(mc, ParsedName.Left); if (fne != null) { var ns = fne as NamespaceExpression; if (ns != null) { fne = ns.LookupTypeOrNamespace(mc, ParsedName.Name, ParsedName.Arity, LookupMode.Probing, Location.Null); if (fne != null) { member = fne.Type; } } else { type = fne.Type; } } } else { fne = ResolveMemberName(mc, ParsedName); if (fne == null) { type = mc.CurrentType; } else if (ParsedParameters == null) { member = fne.Type; } else if (fne.Type.MemberDefinition == mc.CurrentType.MemberDefinition) { member_name = Constructor.ConstructorName; type = fne.Type; } } } else { type = (TypeSpec)member; member = null; } if (ParsedParameters != null) { var old_printer = mc.Module.Compiler.Report.SetPrinter(new NullReportPrinter()); try { var context = new DocumentationMemberContext(mc, ParsedName ?? MemberName.Null); foreach (var pp in ParsedParameters) { pp.Resolve(context); } } finally { mc.Module.Compiler.Report.SetPrinter(old_printer); } } if (type != null) { if (member_name == null) { member_name = ParsedOperator.HasValue ? Operator.GetMetadataName(ParsedOperator.Value) : ParsedName.Name; } int parsed_param_count; if (ParsedOperator == Operator.OpType.Explicit || ParsedOperator == Operator.OpType.Implicit) { parsed_param_count = ParsedParameters.Count - 1; } else if (ParsedParameters != null) { parsed_param_count = ParsedParameters.Count; } else { parsed_param_count = 0; } int parameters_match = -1; do { var members = MemberCache.FindMembers(type, member_name, true); if (members != null) { foreach (var m in members) { if (ParsedName != null && m.Arity != ParsedName.Arity) { continue; } if (ParsedParameters != null) { IParametersMember pm = m as IParametersMember; if (pm == null) { continue; } if (m.Kind == MemberKind.Operator && !ParsedOperator.HasValue) { continue; } var pm_params = pm.Parameters; int i; for (i = 0; i < parsed_param_count; ++i) { var pparam = ParsedParameters[i]; if (i >= pm_params.Count || pparam == null || pparam.TypeSpec == null || !TypeSpecComparer.Override.IsEqual(pparam.TypeSpec, pm_params.Types[i]) || (pparam.Modifier & Parameter.Modifier.RefOutMask) != (pm_params.FixedParameters[i].ModFlags & Parameter.Modifier.RefOutMask)) { if (i > parameters_match) { parameters_match = i; } i = -1; break; } } if (i < 0) { continue; } if (ParsedOperator == Operator.OpType.Explicit || ParsedOperator == Operator.OpType.Implicit) { if (pm.MemberType != ParsedParameters[parsed_param_count].TypeSpec) { parameters_match = parsed_param_count + 1; continue; } } else { if (parsed_param_count != pm_params.Count) { continue; } } } if (member != null) { Report.Warning(419, 3, mc.Location, "Ambiguous reference in cref attribute `{0}'. Assuming `{1}' but other overloads including `{2}' have also matched", cref, member.GetSignatureForError(), m.GetSignatureForError()); break; } member = m; } } // Continue with parent type for nested types if (member == null) { type = type.DeclaringType; } else { type = null; } } while (type != null); if (member == null && parameters_match >= 0) { for (int i = parameters_match; i < parsed_param_count; ++i) { Report.Warning(1580, 1, mc.Location, "Invalid type for parameter `{0}' in XML comment cref attribute `{1}'", (i + 1).ToString(), cref); } if (parameters_match == parsed_param_count + 1) { Report.Warning(1581, 1, mc.Location, "Invalid return type in XML comment cref attribute `{0}'", cref); } } } } if (member == null) { Report.Warning(1574, 1, mc.Location, "XML comment on `{0}' has cref attribute `{1}' that could not be resolved", mc.GetSignatureForError(), cref); cref = "!:" + cref; } else if (member == InternalType.Namespace) { cref = "N:" + fne.GetSignatureForError(); } else { prefix = GetMemberDocHead(member); cref = prefix + member.GetSignatureForDocumentation(); } xref.SetAttribute("cref", cref); }
// // Processes "include" element. Check included file and // embed the document content inside this documentation node. // bool HandleInclude(MemberCore mc, XmlElement el) { bool keep_include_node = false; string file = el.GetAttribute("file"); string path = el.GetAttribute("path"); if (file == "") { Report.Warning(1590, 1, mc.Location, "Invalid XML `include' element. Missing `file' attribute"); el.ParentNode.InsertBefore(el.OwnerDocument.CreateComment(" Include tag is invalid "), el); keep_include_node = true; } else if (path.Length == 0) { Report.Warning(1590, 1, mc.Location, "Invalid XML `include' element. Missing `path' attribute"); el.ParentNode.InsertBefore(el.OwnerDocument.CreateComment(" Include tag is invalid "), el); keep_include_node = true; } else { XmlDocument doc; Exception exception = null; var full_path = Path.Combine(Path.GetDirectoryName(mc.Location.NameFullPath), file); if (!StoredDocuments.TryGetValue(full_path, out doc)) { try { doc = new XmlDocument(); doc.Load(full_path); StoredDocuments.Add(full_path, doc); } catch (Exception e) { exception = e; el.ParentNode.InsertBefore(el.OwnerDocument.CreateComment(String.Format(" Badly formed XML in at comment file `{0}': cannot be included ", file)), el); } } if (doc != null) { try { XmlNodeList nl = doc.SelectNodes(path); if (nl.Count == 0) { el.ParentNode.InsertBefore(el.OwnerDocument.CreateComment(" No matching elements were found for the include tag embedded here. "), el); keep_include_node = true; } foreach (XmlNode n in nl) { el.ParentNode.InsertBefore(el.OwnerDocument.ImportNode(n, true), el); } } catch (Exception ex) { exception = ex; el.ParentNode.InsertBefore(el.OwnerDocument.CreateComment(" Failed to insert some or all of included XML "), el); } } if (exception != null) { Report.Warning(1589, 1, mc.Location, "Unable to include XML fragment `{0}' of file `{1}'. {2}", path, file, exception.Message); } } return(keep_include_node); }
public static string GetPackageFlags (string packages, Report report) { ProcessStartInfo pi = new ProcessStartInfo (); pi.FileName = "pkg-config"; pi.RedirectStandardOutput = true; pi.UseShellExecute = false; pi.Arguments = "--libs " + packages; Process p = null; try { p = Process.Start (pi); } catch (Exception e) { if (report == null) throw; report.Error (-27, "Couldn't run pkg-config: " + e.Message); return null; } if (p.StandardOutput == null) { if (report == null) throw new ApplicationException ("Specified package did not return any information"); report.Warning (-27, 1, "Specified package did not return any information"); p.Close (); return null; } string pkgout = p.StandardOutput.ReadToEnd (); p.WaitForExit (); if (p.ExitCode != 0) { if (report == null) throw new ApplicationException (pkgout); report.Error (-27, "Error running pkg-config. Check the above output."); p.Close (); return null; } p.Close (); return pkgout; }
protected void Warning_IdentifierNotCompliant() { Report.Warning(3008, 1, MemberName.Location, "Identifier `{0}' is not CLS-compliant", GetSignatureForError()); }
/// <summary> /// The main virtual method for CLS-Compliant verifications. /// The method returns true if member is CLS-Compliant and false if member is not /// CLS-Compliant which means that CLS-Compliant tests are not necessary. A descendants override it /// and add their extra verifications. /// </summary> protected virtual bool VerifyClsCompliance() { if (HasClsCompliantAttribute) { if (!Module.DeclaringAssembly.HasCLSCompliantAttribute) { Attribute a = OptAttributes.Search(Module.PredefinedAttributes.CLSCompliant); if ((caching_flags & Flags.ClsCompliantAttributeFalse) != 0) { Report.Warning(3021, 2, a.Location, "`{0}' does not need a CLSCompliant attribute because the assembly is not marked as CLS-compliant", GetSignatureForError()); } else { Report.Warning(3014, 1, a.Location, "`{0}' cannot be marked as CLS-compliant because the assembly is not marked as CLS-compliant", GetSignatureForError()); } return(false); } if (!IsExposedFromAssembly()) { Attribute a = OptAttributes.Search(Module.PredefinedAttributes.CLSCompliant); Report.Warning(3019, 2, a.Location, "CLS compliance checking will not be performed on `{0}' because it is not visible from outside this assembly", GetSignatureForError()); return(false); } if ((caching_flags & Flags.ClsCompliantAttributeFalse) != 0) { if (Parent is Interface && Parent.IsClsComplianceRequired()) { Report.Warning(3010, 1, Location, "`{0}': CLS-compliant interfaces must have only CLS-compliant members", GetSignatureForError()); } else if (Parent.Kind == MemberKind.Class && (ModFlags & Modifiers.ABSTRACT) != 0 && Parent.IsClsComplianceRequired()) { Report.Warning(3011, 1, Location, "`{0}': only CLS-compliant members can be abstract", GetSignatureForError()); } return(false); } if (Parent.Kind != MemberKind.Namespace && Parent.Kind != 0 && !Parent.IsClsComplianceRequired()) { Attribute a = OptAttributes.Search(Module.PredefinedAttributes.CLSCompliant); Report.Warning(3018, 1, a.Location, "`{0}' cannot be marked as CLS-compliant because it is a member of non CLS-compliant type `{1}'", GetSignatureForError(), Parent.GetSignatureForError()); return(false); } } else { if (!IsExposedFromAssembly()) { return(false); } if (!Parent.IsClsComplianceRequired()) { return(false); } } if (member_name.Name [0] == '_') { Warning_IdentifierNotCompliant(); } if (member_name.TypeParameters != null) { member_name.TypeParameters.VerifyClsCompliance(); } return(true); }
public void Warning_UselessOptionalParameter (Report Report) { Report.Warning (1066, 1, Location, "The default value specified for optional parameter `{0}' will never be used", Name); }