// Dual licensed under the terms of the MIT X11 or GNU GPL
//
// Copyright 2004 Novell, Inc.
+// Copyright 2011 Xamarin Inc
//
//
readonly XmlDocument XmlDocumentation;
readonly ModuleContainer module;
+ readonly ModuleContainer doc_module;
//
// The output for XML documentation.
public DocumentationBuilder (ModuleContainer module)
{
+ doc_module = new ModuleContainer (module.Compiler);
+ doc_module.DocumentationBuilder = this;
+
this.module = module;
XmlDocumentation = new XmlDocument ();
XmlDocumentation.PreserveWhitespace = false;
}
// FIXME: it could be done with XmlReader
- DeclSpace ds_target = mc as DeclSpace;
+ var ds_target = mc as TypeContainer;
if (ds_target == null)
ds_target = mc.Parent;
HandleSeeAlso (mc, ds_target, seealso);
foreach (XmlElement see in n.SelectNodes (".//exception"))
HandleException (mc, ds_target, see);
+ foreach (XmlElement node in n.SelectNodes (".//typeparam"))
+ HandleTypeParam (mc, node);
+ foreach (XmlElement node in n.SelectNodes (".//typeparamref"))
+ HandleTypeParamRef (mc, node);
}
n.WriteTo (XmlCommentOutput);
//
// Handles <see> elements.
//
- void HandleSee (MemberCore mc, DeclSpace ds, XmlElement see)
+ void HandleSee (MemberCore mc, TypeContainer ds, XmlElement see)
{
HandleXrefCommon (mc, ds, see);
}
//
// Handles <seealso> elements.
//
- void HandleSeeAlso (MemberCore mc, DeclSpace ds, XmlElement seealso)
+ void HandleSeeAlso (MemberCore mc, TypeContainer ds, XmlElement seealso)
{
HandleXrefCommon (mc, ds, seealso);
}
//
// Handles <exception> elements.
//
- void HandleException (MemberCore mc, DeclSpace ds, XmlElement seealso)
+ void HandleException (MemberCore mc, TypeContainer ds, XmlElement seealso)
{
HandleXrefCommon (mc, ds, seealso);
}
+ //
+ // Handles <typeparam /> node
+ //
+ void HandleTypeParam (MemberCore mc, XmlElement node)
+ {
+ if (!node.HasAttribute ("name"))
+ return;
+
+ string tp_name = node.GetAttribute ("name");
+ if (mc.CurrentTypeParameters != null) {
+ if (mc.CurrentTypeParameters.Find (tp_name) != null)
+ return;
+ }
+
+ // TODO: CS1710, CS1712
+
+ mc.Compiler.Report.Warning (1711, 2, mc.Location,
+ "XML comment on `{0}' has a typeparam name `{1}' but there is no type parameter by that name",
+ mc.GetSignatureForError (), tp_name);
+ }
+
+ //
+ // Handles <typeparamref /> node
+ //
+ void HandleTypeParamRef (MemberCore mc, XmlElement node)
+ {
+ if (!node.HasAttribute ("name"))
+ return;
+
+ string tp_name = node.GetAttribute ("name");
+ var member = mc;
+ do {
+ if (member.CurrentTypeParameters != null) {
+ if (member.CurrentTypeParameters.Find (tp_name) != null)
+ return;
+ }
+
+ member = member.Parent;
+ } while (member != null);
+
+ mc.Compiler.Report.Warning (1735, 2, mc.Location,
+ "XML comment on `{0}' has a typeparamref name `{1}' that could not be resolved",
+ mc.GetSignatureForError (), tp_name);
+ }
+
FullNamedExpression ResolveMemberName (IMemberContext context, MemberName mn)
{
if (mn.Left == null)
- return context.LookupNamespaceOrType (mn.Name, mn.Arity, Location.Null, /*ignore_cs0104=*/ false);
+ return context.LookupNamespaceOrType (mn.Name, mn.Arity, LookupMode.Probing, Location.Null);
var left = ResolveMemberName (context, mn.Left);
var ns = left as Namespace;
if (ns != null)
- return ns.Lookup (context, mn.Name, mn.Arity, Location.Null);
+ return ns.LookupTypeOrNamespace (context, mn.Name, mn.Arity, LookupMode.Probing, Location.Null);
TypeExpr texpr = left as TypeExpr;
if (texpr != null) {
//
// Processes "see" or "seealso" elements from cref attribute.
//
- void HandleXrefCommon (MemberCore mc, DeclSpace ds, XmlElement xref)
+ void HandleXrefCommon (MemberCore mc, TypeContainer ds, XmlElement xref)
{
string cref = xref.GetAttribute ("cref");
// when, XmlReader, "if (cref == null)"
var s = new MemoryStream (encoding.GetBytes (cref));
SeekableStreamReader seekable = new SeekableStreamReader (s, encoding);
- var source_file = new CompilationSourceFile ("{documentation}", "", 1);
- var doc_module = new ModuleContainer (module.Compiler);
- doc_module.DocumentationBuilder = this;
- source_file.NamespaceContainer = new NamespaceContainer (null, doc_module, null, source_file);
+ var source_file = new CompilationSourceFile (doc_module);
+ var report = new Report (doc_module.Compiler, new NullReportPrinter ());
- Report parse_report = new Report (new NullReportPrinter ());
- var parser = new CSharpParser (seekable, source_file, parse_report);
+ var parser = new CSharpParser (seekable, source_file, report);
ParsedParameters = null;
ParsedName = null;
ParsedBuiltinType = null;
parser.Lexer.putback_char = Tokenizer.DocumentationXref;
parser.Lexer.parsing_generic_declaration_doc = true;
parser.parse ();
- if (parse_report.Errors > 0) {
+ if (report.Errors > 0) {
Report.Warning (1584, 1, mc.Location, "XML comment on `{0}' has syntactically incorrect cref attribute `{1}'",
mc.GetSignatureForError (), cref);
if (fne != null) {
var ns = fne as Namespace;
if (ns != null) {
- fne = ns.Lookup (mc, ParsedName.Name, ParsedName.Arity, Location.Null);
+ fne = ns.LookupTypeOrNamespace (mc, ParsedName.Name, ParsedName.Arity, LookupMode.Probing, Location.Null);
if (fne != null) {
member = fne.Type;
}
}
if (ParsedParameters != null) {
+ var old_printer = mc.Module.Compiler.Report.SetPrinter (new NullReportPrinter ());
foreach (var pp in ParsedParameters) {
pp.Resolve (mc);
}
+ mc.Module.Compiler.Report.SetPrinter (old_printer);
}
if (type != null) {
{
public readonly Parameter.Modifier Modifier;
public FullNamedExpression Type;
+ TypeSpec type;
public DocumentationParameter (Parameter.Modifier modifier, FullNamedExpression type)
: this (type)
public TypeSpec TypeSpec {
get {
- return Type == null ? null : Type.Type;
+ return type;
}
}
public void Resolve (IMemberContext context)
{
- Type = Type.ResolveAsTypeTerminal (context, true);
+ type = Type.ResolveAsType (context);
}
}
}