// Copyright 2004 Novell, Inc.
//
//
-#if ! BOOTSTRAP_WITH_OLDLIB
+
using System;
-using System.Collections;
-using System.Collections.Specialized;
+using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
//
// Support class for XML documentation.
//
-#if NET_2_0
- static
-#else
- abstract
-#endif
- public class DocUtil
+ static class DocUtil
{
-#if !NET_2_0
- private DocUtil () {}
-#endif
// TypeContainer
//
// handle warning report.
//
internal static void GenerateTypeDocComment (TypeContainer t,
- DeclSpace ds)
+ DeclSpace ds, Report Report)
{
- GenerateDocComment (t, ds);
+ GenerateDocComment (t, ds, Report);
if (t.DefaultStaticConstructor != null)
t.DefaultStaticConstructor.GenerateDocComment (t);
Environment.NewLine + " ";
private static XmlNode GetDocCommentNode (MemberCore mc,
- string name)
+ string name, Report Report)
{
// FIXME: It could be even optimizable as not
// to use XmlDocument. But anyways the nodes
// handle warning report.
//
internal static void GenerateDocComment (MemberCore mc,
- DeclSpace ds)
+ DeclSpace ds, Report Report)
{
if (mc.DocComment != null) {
string name = mc.GetDocCommentName (ds);
- XmlNode n = GetDocCommentNode (mc, name);
+ XmlNode n = GetDocCommentNode (mc, name, Report);
XmlElement el = n as XmlElement;
if (el != null) {
XmlNodeList nl = n.SelectNodes (".//include");
if (nl.Count > 0) {
// It could result in current node removal, so prepare another list to iterate.
- ArrayList al = new ArrayList (nl.Count);
+ var al = new List<XmlNode> (nl.Count);
foreach (XmlNode inc in nl)
al.Add (inc);
foreach (XmlElement inc in al)
- if (!HandleInclude (mc, inc))
+ if (!HandleInclude (mc, inc, Report))
inc.ParentNode.RemoveChild (inc);
}
ds_target = ds;
foreach (XmlElement see in n.SelectNodes (".//see"))
- HandleSee (mc, ds_target, see);
+ HandleSee (mc, ds_target, see, Report);
foreach (XmlElement seealso in n.SelectNodes (".//seealso"))
- HandleSeeAlso (mc, ds_target, seealso);
+ HandleSeeAlso (mc, ds_target, seealso ,Report);
foreach (XmlElement see in n.SelectNodes (".//exception"))
- HandleException (mc, ds_target, see);
+ HandleException (mc, ds_target, see, Report);
}
n.WriteTo (RootContext.Documentation.XmlCommentOutput);
// Processes "include" element. Check included file and
// embed the document content inside this documentation node.
//
- private static bool HandleInclude (MemberCore mc, XmlElement el)
+ private static bool HandleInclude (MemberCore mc, XmlElement el, Report Report)
{
bool keep_include_node = false;
string file = el.GetAttribute ("file");
keep_include_node = true;
}
else {
- XmlDocument doc = RootContext.Documentation.StoredDocuments [file] as XmlDocument;
- if (doc == null) {
+ XmlDocument doc;
+ if (!RootContext.Documentation.StoredDocuments.TryGetValue (file, out doc)) {
try {
doc = new XmlDocument ();
doc.Load (file);
// Handles <see> elements.
//
private static void HandleSee (MemberCore mc,
- DeclSpace ds, XmlElement see)
+ DeclSpace ds, XmlElement see, Report r)
{
- HandleXrefCommon (mc, ds, see);
+ HandleXrefCommon (mc, ds, see, r);
}
//
// Handles <seealso> elements.
//
private static void HandleSeeAlso (MemberCore mc,
- DeclSpace ds, XmlElement seealso)
+ DeclSpace ds, XmlElement seealso, Report r)
{
- HandleXrefCommon (mc, ds, seealso);
+ HandleXrefCommon (mc, ds, seealso, r);
}
//
// Handles <exception> elements.
//
private static void HandleException (MemberCore mc,
- DeclSpace ds, XmlElement seealso)
+ DeclSpace ds, XmlElement seealso, Report r)
{
- HandleXrefCommon (mc, ds, seealso);
+ HandleXrefCommon (mc, ds, seealso, r);
}
static readonly char [] wsChars =
// returns a full runtime type name from a name which might
// be C# specific type name.
//
- private static Type FindDocumentedType (MemberCore mc, string name, DeclSpace ds, string cref)
+ private static Type FindDocumentedType (MemberCore mc, string name, DeclSpace ds, string cref, Report r)
{
bool is_array = false;
string identifier = name;
is_array = true;
}
}
- Type t = FindDocumentedTypeNonArray (mc, identifier, ds, cref);
+ Type t = FindDocumentedTypeNonArray (mc, identifier, ds, cref, r);
if (t != null && is_array)
t = Array.CreateInstance (t, 0).GetType ();
return t;
}
private static Type FindDocumentedTypeNonArray (MemberCore mc,
- string identifier, DeclSpace ds, string cref)
+ string identifier, DeclSpace ds, string cref, Report r)
{
switch (identifier) {
case "int":
if (index < 0)
return null;
int warn;
- Type parent = FindDocumentedType (mc, identifier.Substring (0, index), ds, cref);
+ Type parent = FindDocumentedType (mc, identifier.Substring (0, index), ds, cref, r);
if (parent == null)
return null;
// no need to detect warning 419 here
return FindDocumentedMember (mc, parent,
identifier.Substring (index + 1),
- null, ds, out warn, cref, false, null).Member as Type;
+ null, ds, out warn, cref, false, null, r).Member as Type;
}
private static MemberInfo [] empty_member_infos =
if (ml == null)
return empty_member_infos;
- ArrayList al = new ArrayList (ml.Length);
+ var al = new List<MemberInfo> (ml.Length);
for (int i = 0; i < ml.Length; i++) {
MethodBase mx = ml [i] as MethodBase;
PropertyInfo px = ml [i] as PropertyInfo;
}
al.Add (ml [i]);
}
- return al.ToArray (typeof (MemberInfo)) as MemberInfo [];
+ return al.ToArray ();
}
struct FoundMember
private static FoundMember FindDocumentedMember (MemberCore mc,
Type type, string member_name, Type [] param_list,
DeclSpace ds, out int warning_type, string cref,
- bool warn419, string name_for_error)
+ bool warn419, string name_for_error, Report r)
{
for (; type != null; type = type.DeclaringType) {
MemberInfo mi = FindDocumentedMemberNoNest (
mc, type, member_name, param_list, ds,
out warning_type, cref, warn419,
- name_for_error);
+ name_for_error, r);
if (mi != null)
return new FoundMember (type, mi);
}
private static MemberInfo FindDocumentedMemberNoNest (
MemberCore mc, Type type, string member_name,
Type [] param_list, DeclSpace ds, out int warning_type,
- string cref, bool warn419, string name_for_error)
+ string cref, bool warn419, string name_for_error, Report Report)
{
warning_type = 0;
MemberInfo [] mis;
if (mis == null || mis.Length == 0)
return null;
if (warn419 && IsAmbiguous (mis))
- Report419 (mc, name_for_error, mis);
+ Report419 (mc, name_for_error, mis, Report);
return mis [0];
}
if (warn419 && mis.Length > 0) {
if (IsAmbiguous (mis))
- Report419 (mc, name_for_error, mis);
+ Report419 (mc, name_for_error, mis, Report);
return mis [0];
}
((PropertyInfo) mi).PropertyType :
null;
if (return_type_name != null) {
- Type returnType = FindDocumentedType (mc, return_type_name, ds, cref);
+ Type returnType = FindDocumentedType (mc, return_type_name, ds, cref, Report);
if (returnType == null || returnType != expected) {
warning_type = 1581;
Report.Warning (1581, 1, mc.Location, "Invalid return type in XML comment cref attribute `{0}'", cref);
// Checks cref attribute.
//
private static void HandleXrefCommon (MemberCore mc,
- DeclSpace ds, XmlElement xref)
+ DeclSpace ds, XmlElement xref, Report Report)
{
string cref = xref.GetAttribute ("cref").Trim (wsChars);
// when, XmlReader, "if (cref == null)"
name = signature;
parameters = null;
}
- Normalize (mc, ref name);
+ Normalize (mc, ref name, Report);
string identifier = GetBodyIdentifierFromName (name);
for (int i = 0; i < name_elems.Length; i++) {
string nameElem = GetBodyIdentifierFromName (name_elems [i]);
if (i > 0)
- Normalize (mc, ref nameElem);
+ Normalize (mc, ref nameElem, Report);
if (!Tokenizer.IsValidIdentifier (nameElem)
&& nameElem.IndexOf ("operator") < 0) {
Report.Warning (1584, 1, mc.Location, "XML comment on `{0}' has syntactically incorrect cref attribute `{1}'",
parameter_types = Type.EmptyTypes;
else {
string [] param_list = parameters.Split (',');
- ArrayList plist = new ArrayList ();
+ var plist = new List<Type> ();
for (int i = 0; i < param_list.Length; i++) {
string param_type_name = param_list [i].Trim (wsChars);
- Normalize (mc, ref param_type_name);
- Type param_type = FindDocumentedType (mc, param_type_name, ds, cref);
+ Normalize (mc, ref param_type_name, Report);
+ Type param_type = FindDocumentedType (mc, param_type_name, ds, cref, Report);
if (param_type == null) {
Report.Warning (1580, 1, mc.Location, "Invalid type for parameter `{0}' in XML comment cref attribute `{1}'",
(i + 1).ToString (), cref);
}
plist.Add (param_type);
}
- parameter_types = plist.ToArray (typeof (Type)) as Type [];
+ parameter_types = plist.ToArray ();
}
- Type type = FindDocumentedType (mc, name, ds, cref);
+ Type type = FindDocumentedType (mc, name, ds, cref, Report);
if (type != null
// delegate must not be referenced with args
&& (!TypeManager.IsDelegateType (type)
if (period > 0) {
string typeName = name.Substring (0, period);
string member_name = name.Substring (period + 1);
- Normalize (mc, ref member_name);
- type = FindDocumentedType (mc, typeName, ds, cref);
+ Normalize (mc, ref member_name, Report);
+ type = FindDocumentedType (mc, typeName, ds, cref, Report);
int warn_result;
if (type != null) {
- FoundMember fm = FindDocumentedMember (mc, type, member_name, parameter_types, ds, out warn_result, cref, true, name);
+ FoundMember fm = FindDocumentedMember (mc, type, member_name, parameter_types, ds, out warn_result, cref, true, name, Report);
if (warn_result > 0)
return;
if (!fm.IsEmpty) {
}
else {
int warn_result;
- FoundMember fm = FindDocumentedMember (mc, ds.TypeBuilder, name, parameter_types, ds, out warn_result, cref, true, name);
+ FoundMember fm = FindDocumentedMember (mc, ds.TypeBuilder, name, parameter_types, ds, out warn_result, cref, true, name, Report);
if (warn_result > 0)
return;
if (!fm.IsEmpty) {
xref.SetAttribute ("cref", "N:" + ns.GetSignatureForError ());
return; // a namespace
}
- if (RootNamespace.Global.IsNamespace (name)) {
+ if (GlobalRootNamespace.Instance.IsNamespace (name)) {
xref.SetAttribute ("cref", "N:" + name);
return; // a namespace
}
return identifier;
}
- static void Report419 (MemberCore mc, string member_name, MemberInfo [] mis)
+ static void Report419 (MemberCore mc, string member_name, MemberInfo [] mis, Report Report)
{
Report.Warning (419, 3, mc.Location,
"Ambiguous reference in cref attribute `{0}'. Assuming `{1}' but other overloads including `{2}' have also matched",
paramSpec += ")";
string name = mc is Constructor ? "#ctor" : mc.Name;
-#if GMCS_SOURCE
if (mc.MemberName.IsGeneric)
name += "``" + mc.MemberName.CountTypeArguments;
-#endif
+
string suffix = String.Empty;
Operator op = mc as Operator;
if (op != null) {
static string GetSignatureForDoc (Type type)
{
-#if GMCS_SOURCE
if (TypeManager.IsGenericParameter (type))
return (type.DeclaringMethod != null ? "``" : "`") + TypeManager.GenericParameterPosition (type);
g += '}';
return g;
}
-#endif
string name = type.FullName != null ? type.FullName : type.Name;
return name.Replace ("+", ".").Replace ('&', '@');
// that means removal of DOM use.
//
internal static void OnMethodGenerateDocComment (
- MethodCore mc, XmlElement el)
+ MethodCore mc, XmlElement el, Report Report)
{
- Hashtable paramTags = new Hashtable ();
+ var paramTags = new Dictionary<string, string> ();
foreach (XmlElement pelem in el.SelectNodes ("param")) {
string xname = pelem.GetAttribute ("name");
if (xname.Length == 0)
if (xname != "" && mc.Parameters.GetParameterIndexByName (xname) < 0)
Report.Warning (1572, 2, mc.Location, "XML comment on `{0}' has a param tag for `{1}', but there is no parameter by that name",
mc.GetSignatureForError (), xname);
- else if (paramTags [xname] != null)
+ else if (paramTags.ContainsKey (xname))
Report.Warning (1571, 2, mc.Location, "XML comment on `{0}' has a duplicate param tag for `{1}'",
mc.GetSignatureForError (), xname);
paramTags [xname] = xname;
}
IParameterData [] plist = mc.Parameters.FixedParameters;
foreach (Parameter p in plist) {
- if (paramTags.Count > 0 && paramTags [p.Name] == null)
+ if (paramTags.Count > 0 && !paramTags.ContainsKey (p.Name))
Report.Warning (1573, 4, mc.Location, "Parameter `{0}' has no matching param tag in the XML comment for `{1}'",
p.Name, mc.GetSignatureForError ());
}
}
- private static void Normalize (MemberCore mc, ref string name)
+ private static void Normalize (MemberCore mc, ref string name, Report Report)
{
if (name.Length > 0 && name [0] == '@')
name = name.Substring (1);
// Stores XmlDocuments that are included in XML documentation.
// Keys are included filenames, values are XmlDocuments.
//
- public Hashtable StoredDocuments = new Hashtable ();
+ public Dictionary<string, XmlDocument> StoredDocuments = new Dictionary<string, XmlDocument> ();
//
// Outputs XML documentation comment from tokenized comments.
//
- public bool OutputDocComment (string asmfilename)
+ public bool OutputDocComment (string asmfilename, Report Report)
{
XmlTextWriter w = null;
try {
w.WriteEndElement (); // assembly
w.WriteStartElement ("members");
XmlCommentOutput = w;
- GenerateDocComment ();
+ GenerateDocComment (Report);
w.WriteFullEndElement (); // members
w.WriteEndElement ();
w.WriteWhitespace (Environment.NewLine);
//
// Fixes full type name of each documented types/members up.
//
- public void GenerateDocComment ()
+ public void GenerateDocComment (Report r)
{
TypeContainer root = RootContext.ToplevelTypes;
if (root.Types != null)
foreach (TypeContainer tc in root.Types)
- DocUtil.GenerateTypeDocComment (tc, null);
+ DocUtil.GenerateTypeDocComment (tc, null, r);
if (root.Delegates != null)
foreach (Delegate d in root.Delegates)
- DocUtil.GenerateDocComment (d, null);
+ DocUtil.GenerateDocComment (d, null, r);
}
}
}
-#endif