Skip to content

Commit

Permalink
[monodoc] Move to /class instead of /tools and re-enable compilation …
Browse files Browse the repository at this point in the history
…for 4.0 profile.
  • Loading branch information
garuma authored and duncanmak committed Oct 8, 2016
1 parent 5c5f5fc commit 34ddfb9
Show file tree
Hide file tree
Showing 122 changed files with 14,306 additions and 0 deletions.
6 changes: 6 additions & 0 deletions monodoc/Assembly/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using System.Reflection;
using System.Runtime.CompilerServices;

[assembly:AssemblyVersion("1.0.0.0")]
[assembly:AssemblyDelaySign(false)]
[assembly:AssemblyKeyFile("../../class/mono.snk")]
145 changes: 145 additions & 0 deletions monodoc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
thisdir = class/monodoc
SUBDIRS =
include ../../build/rules.make

LIBRARY = monodoc.dll
LIBRARY_PACKAGE = monodoc
# Remove a bunch of "obsolete"-type warning for Lucene.NET
# also activate legacy mode to compile old monodoc.dll api
LOCAL_MCS_FLAGS = /nowarn:618,612,672,809 /define:LEGACY_MODE

JAY_FLAGS = -ct

IMAGES = \
Resources/images/bc_bg.png \
Resources/images/bc_separator.png \
Resources/images/error.png \
Resources/images/hatch.png \
Resources/images/headerbg.png \
Resources/images/help.png \
Resources/images/house.png \
Resources/images/members.png \
Resources/images/namespace.png \
Resources/images/privclass.png \
Resources/images/privdelegate.png \
Resources/images/privenumeration.png \
Resources/images/privevent.png \
Resources/images/privextension.png \
Resources/images/privfield.png \
Resources/images/privinterface.png \
Resources/images/privmethod.png \
Resources/images/privproperty.png \
Resources/images/privstructure.png \
Resources/images/protclass.png \
Resources/images/protdelegate.png \
Resources/images/protenumeration.png \
Resources/images/protevent.png \
Resources/images/protextension.png \
Resources/images/protfield.png \
Resources/images/protinterface.png \
Resources/images/protmethod.png \
Resources/images/protproperty.png \
Resources/images/protstructure.png \
Resources/images/pubclass.png \
Resources/images/pubdelegate.png \
Resources/images/pubenumeration.png \
Resources/images/pubevent.png \
Resources/images/pubextension.png \
Resources/images/pubfield.png \
Resources/images/pubinterface.png \
Resources/images/pubmethod.png \
Resources/images/pubproperty.png \
Resources/images/pubstructure.png \
Resources/images/reference.png \
Resources/images/treebg.png

IMAGE_RESOURCE_COMMAND = $(foreach file,$(IMAGES),/resource:$(file),$(notdir $(file)))

RESOURCE_FILES = \
../../docs/monodoc.xml \
Resources/base.css \
Resources/ecmaspec-html-css.xsl \
Resources/ecmaspec-html.xsl \
Resources/ecmaspec.css \
Resources/helper.js \
Resources/home.html \
Resources/Lminus.gif \
Resources/Lplus.gif \
Resources/mdoc-html-format.xsl \
Resources/mdoc-html-utils.xsl \
Resources/mdoc-sections-css.xsl \
Resources/mdoc-sections.xsl \
Resources/mono-ecma-css.xsl \
Resources/mono-ecma-impl.xsl \
Resources/mono-ecma.css \
Resources/mono-ecma.xsl \
Resources/toc-html.xsl \
$(IMAGES)

EXTRA_DISTFILES = \
monodoc.dll.config.in \
$(RESOURCE_FILES) \
Monodoc.Ecma/EcmaUrlParser.jay \
Test/monodoc_test/monodoc.xml

LIB_MCS_FLAGS = \
/unsafe \
/codepage:utf8 \
/nowarn:169,164,162,168,219,618,612 \
/resource:../../docs/monodoc.xml,monodoc.xml \
/resource:Resources/base.css,base.css \
/resource:Resources/ecmaspec-html-css.xsl,ecmaspec-html-css.xsl \
/resource:Resources/ecmaspec-html.xsl,ecmaspec-html.xsl \
/resource:Resources/ecmaspec.css,ecmaspec.css \
/resource:Resources/helper.js,helper.js \
/resource:Resources/home.html,home.html \
/resource:Resources/Lminus.gif,Lminus.gif \
/resource:Resources/Lplus.gif,Lplus.gif \
/resource:Resources/mdoc-html-format.xsl,mdoc-html-format.xsl \
/resource:Resources/mdoc-html-utils.xsl,mdoc-html-utils.xsl \
/resource:Resources/mdoc-sections-css.xsl,mdoc-sections-css.xsl \
/resource:Resources/mdoc-sections.xsl,mdoc-sections.xsl \
/resource:Resources/mono-ecma-css.xsl,mono-ecma-css.xsl \
/resource:Resources/mono-ecma-impl.xsl,mono-ecma-impl.xsl \
/resource:Resources/mono-ecma.css,mono-ecma.css \
/resource:Resources/mono-ecma.xsl,mono-ecma.xsl \
/resource:Resources/toc-html.xsl,toc-html.xsl \
$(IMAGE_RESOURCE_COMMAND) \
/r:ICSharpCode.SharpZipLib \
/r:$(corlib) \
/r:System.dll \
/r:System.Core.dll \
/r:System.Xml.dll \
/r:System.Xml.Linq.dll \
/r:System.Configuration.dll

TEST_MCS_FLAGS = /r:System.Core.dll /r:System.Xml.dll

DOC_SOURCE_DIRS = \
../../docs \
../../../docs

DOC_SOURCES = $(foreach dir,$(DOC_SOURCE_DIRS),$(wildcard $(dir)/*.source $(dir)/*.tree $(dir)/*.zip))

include ../../build/library.make

$(the_lib): Makefile $(RESOURCE_FILES)

all-local: $(the_lib).config Monodoc.Ecma/EcmaUrlParser.cs

test-local: setup-doc-sources

dist-local: Monodoc.Ecma/EcmaUrlParser.cs

$(the_lib).config: Makefile monodoc.dll.config.in
sed 's,@monodoc_refdir@,$(mono_libdir)/monodoc,g' monodoc.dll.config.in > $@

Monodoc.Ecma/EcmaUrlParser.cs: Monodoc.Ecma/EcmaUrlParser.jay $(topdir)/jay/skeleton.cs
$(topdir)/jay/jay $(JAY_FLAGS) < $(topdir)/jay/skeleton.cs $< > jay-tmp.out && mv jay-tmp.out $@

parser.exe: Monodoc.Ecma/EcmaUrlParser.cs Monodoc.Ecma/EcmaUrlTokenizer.cs Monodoc.Ecma/EcmaUrlParserDriver.cs Monodoc.Ecma/EcmaDesc.cs
mcs /out:$@ /debug $^

setup-doc-sources: $(DOC_SOURCES)
mkdir -p ./Test/monodoc_test/sources/
cp $(DOC_SOURCES) ./Test/monodoc_test/sources/
42 changes: 42 additions & 0 deletions monodoc/Mono.Documentation/ManifestResourceResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.IO;
using System.Reflection;
using System.Xml;

namespace Mono.Documentation {
public class ManifestResourceResolver : XmlUrlResolver {
private string[] dirs;

public ManifestResourceResolver (params string[] dirs)
{
this.dirs = (string[]) dirs.Clone ();
}

public override Uri ResolveUri (Uri baseUri, string relativeUri)
{
if (Array.IndexOf (
Assembly.GetExecutingAssembly ().GetManifestResourceNames (),
relativeUri) >= 0)
return new Uri ("x-resource:///" + relativeUri);
foreach (var dir in dirs) {
if (File.Exists (Path.Combine (dir, relativeUri)))
return base.ResolveUri (new Uri ("file://" + new DirectoryInfo (dir).FullName + "/"),
relativeUri);
}
return base.ResolveUri (baseUri, relativeUri);
}

public override object GetEntity (Uri absoluteUri, string role, Type ofObjectToReturn)
{
if (ofObjectToReturn == null)
ofObjectToReturn = typeof(Stream);
if (ofObjectToReturn != typeof(Stream))
throw new XmlException ("This object type is not supported.");
if (absoluteUri.Scheme != "x-resource")
return base.GetEntity (absoluteUri, role, ofObjectToReturn);
return Assembly.GetExecutingAssembly().GetManifestResourceStream (
absoluteUri.Segments [1]);
}
}
}

200 changes: 200 additions & 0 deletions monodoc/Mono.Documentation/XmlDocUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
using System;
using System.Collections;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Xml;

namespace Mono.Documentation {

public delegate XmlDocument DocLoader (string escapedTypeName);

public static class XmlDocUtils
{
public static XmlNodeList GetMemberGenericParameters (XmlNode member)
{
return member.SelectNodes ("Docs/typeparam");
}

public static XmlNodeList GetTypeGenericParameters (XmlNode member)
{
return member.SelectNodes ("/Type/TypeParameters/TypeParameter");
}

public static string ToTypeName (string type, XmlNode member)
{
return ToTypeName (type, GetTypeGenericParameters (member),
GetMemberGenericParameters (member));
}

public static string ToTypeName (string type, XmlNodeList typeGenParams, XmlNodeList memberGenParams)
{
type = type.Replace ("&", "@").Replace ("<", "{").Replace (">", "}");
for (int i = 0; i < typeGenParams.Count; ++i) {
string name = typeGenParams [i].InnerText;
type = Regex.Replace (type, @"\b" + name + @"\b", "`" + i);
}
for (int i = 0; i < memberGenParams.Count; ++i) {
string name = memberGenParams [i].Attributes ["name"].Value;
type = Regex.Replace (type, @"\b" + name + @"\b", "``" + i);
}
return type;
}

public static string ToEscapedTypeName (string name)
{
return GetCountedName (name, "`");
}

private static string GetCountedName (string name, string escape)
{
int lt = name.IndexOf ("<");
if (lt == -1)
return name;
StringBuilder type = new StringBuilder (name.Length);
int start = 0;
do {
type.Append (name.Substring (start, lt - start));
type.Append (escape);
type.Append (GetGenericCount (name, lt, out start));
} while ((lt = name.IndexOf ('<', start)) >= 0);
if (start < name.Length)
type.Append (name.Substring (start));
return type.ToString ().Replace ("+", ".");
}

private static int GetGenericCount (string name, int start, out int end)
{
int n = 1;
bool r = true;
int i = start;
int depth = 1;
for ( ++i; r && i < name.Length; ++i) {
switch (name [i]) {
case ',': if (depth == 1) ++n; break;
case '<': ++depth; break;
case '>': --depth; if (depth == 0) r = false; break;
}
}
end = i;
return n;
}

public static string ToEscapedMemberName (string member)
{
// Explicitly implemented interface members contain '.'s in the member
// name, e.g. System.Collections.Generic.IEnumerable<A>.GetEnumerator.
// CSC does a s/\./#/g for these.
member = member.Replace (".", "#");
if (member [member.Length-1] == '>') {
int i = member.LastIndexOf ("<");
int ignore;
return member.Substring (0, i).Replace ("<", "{").Replace (">", "}") +
"``" + GetGenericCount (member, i, out ignore);
}
return member.Replace ("<", "{").Replace (">", "}");
}

public static void AddExtensionMethods (XmlDocument typexml, ArrayList/*<XmlNode>*/ extensions, DocLoader loader)
{
// if no members (enum, delegate) don't add extensions
XmlNode m = typexml.SelectSingleNode ("/Type/Members");
if (m == null)
return;

// static classes can't be targets:
if (typexml.SelectSingleNode (
"/Type/TypeSignature[@Language='C#']/@Value")
.Value.IndexOf (" static ") >= 0)
return;

foreach (string s in GetSupportedTypes (typexml, loader)) {
foreach (XmlNode extension in extensions) {
bool add = false;
foreach (XmlNode target in extension.SelectNodes ("Targets/Target")) {
if (target.Attributes ["Type"].Value == s) {
add = true;
break;
}
}
if (!add) {
continue;
}
foreach (XmlNode c in extension.SelectNodes ("Member")) {
XmlNode cm = typexml.ImportNode (c, true);
m.AppendChild (cm);
}
}
}
}

private static IEnumerable GetSupportedTypes (XmlDocument type, DocLoader loader)
{
yield return "System.Object";
yield return GetEscapedPath (type, "Type/@FullName");

Hashtable h = new Hashtable ();
GetInterfaces (h, type, loader);

string s = GetEscapedPath (type, "Type/Base/BaseTypeName");
if (s != null) {
yield return s;
XmlDocument d;
string p = s;
while (s != null && (d = loader (s)) != null) {
GetInterfaces (h, d, loader);
s = GetEscapedPath (d, "Type/Base/BaseTypeName");
if (p == s)
break;
yield return s;
}
}

foreach (object o in h.Keys)
yield return o.ToString ();
}

private static string GetEscapedPath (XmlDocument d, string path)
{
XmlNode n = d.SelectSingleNode (path);
if (n == null)
return null;
return "T:" + ToEscapedTypeName (n.InnerText);
}

private static void GetInterfaces (Hashtable ifaces, XmlDocument doc, DocLoader loader)
{
foreach (XmlNode n in doc.SelectNodes ("Type/Interfaces/Interface/InterfaceName")) {
string t = ToEscapedTypeName (n.InnerText);
string tk = "T:" + t;
if (!ifaces.ContainsKey (tk)) {
ifaces.Add (tk, null);
try {
XmlDocument d = loader (t);
if (d != null)
GetInterfaces (ifaces, d, loader);
}
catch (FileNotFoundException e) {
// ignore; interface documentation couldn't be found.
}
}
}
}

// Turns e.g. sources/netdocs into sources/cache/netdocs
public static string GetCacheDirectory (string assembledBase)
{
return Path.Combine (
Path.Combine (Path.GetDirectoryName (assembledBase), "cache"),
Path.GetFileName (assembledBase));
}

public static string GetCachedFileName (string cacheDir, string url)
{
return Path.Combine (cacheDir,
Uri.EscapeUriString (url).Replace ('/', '+').Replace ("*", "%2a"));
}
}
}

Loading

0 comments on commit 34ddfb9

Please sign in to comment.