Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attributes -> FrameworkAlternate support #272

Merged
merged 2 commits into from
Jun 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mdoc/Consts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Mono.Documentation
{
public static class Consts
{
public static string MonoVersion = "5.7.0.1";
public static string MonoVersion = "5.7.1";
public const string DocId = "DocId";
public const string CppCli = "C++ CLI";
public const string CppCx = "C++ CX";
Expand Down
195 changes: 142 additions & 53 deletions mdoc/Mono.Documentation/MDocUpdater.cs

Large diffs are not rendered by default.

19 changes: 18 additions & 1 deletion mdoc/Mono.Documentation/Updater/Frameworks/AssemblySet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Mono.Documentation.Updater.Frameworks
/// <summary>
/// Represents a set of assemblies that we want to document
/// </summary>
class AssemblySet : IDisposable
public class AssemblySet : IDisposable
{
static readonly BaseAssemblyResolver resolver = new Frameworks.MDocResolver ();
static IAssemblyResolver cachedResolver;
Expand All @@ -23,6 +23,23 @@ class AssemblySet : IDisposable
IEnumerable<string> importPaths;
public IEnumerable<DocumentationImporter> Importers { get; private set; }

FrameworkEntry fx;
public FrameworkEntry Framework
{
get => fx;
set
{
fx = value;
fx.AddAssemblySet (this);
}
}

/// <summary>This is meant only for unit test access</summary>
public IDictionary<string, bool> AssemblyMapsPath
{
get => assemblyPathsMap;
}

public AssemblySet (IEnumerable<string> paths) : this ("Default", paths, new string[0]) { }

public AssemblySet (string name, IEnumerable<string> paths, IEnumerable<string> resolverSearchPaths, IEnumerable<string> imports = null, string version = null, string id = null)
Expand Down
78 changes: 74 additions & 4 deletions mdoc/Mono.Documentation/Updater/Frameworks/FXUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,36 @@ public static class FXUtils
{
public static string AddFXToList (string existingValue, string newFX)
{
var cachedValue = GetCache (existingValue, newFX, CacheAction.Add);
if (!string.IsNullOrWhiteSpace (cachedValue))
return cachedValue;

var splitValue = SplitList (existingValue);
if (!splitValue.Contains (newFX)) splitValue.Add (newFX);
return JoinList (splitValue);
var returnVal = JoinList (splitValue);

SetCache (existingValue, newFX, returnVal, CacheAction.Add);

return returnVal;
}

public static string RemoveFXFromList (string existingValue, string FXToRemove)
{
var cachedValue = GetCache (existingValue, FXToRemove, CacheAction.Remove);
if (!string.IsNullOrWhiteSpace (cachedValue))
return cachedValue;

var splitValue = SplitList (existingValue);
splitValue.Remove (FXToRemove);
return JoinList (splitValue);
var returnVal = JoinList (splitValue);

SetCache (existingValue, FXToRemove, returnVal, CacheAction.Remove);

return returnVal;
}

/// <summary>Returns a list of all previously processed frameworks (not including the current)</summary>
internal static string PreviouslyProcessedFXString (FrameworkTypeEntry typeEntry)
internal static string PreviouslyProcessedFXString (FrameworkTypeEntry typeEntry)
{
if (typeEntry == null)
return string.Empty;
Expand All @@ -31,7 +47,7 @@ internal static string PreviouslyProcessedFXString (FrameworkTypeEntry typeEntry
.Where (n => !string.IsNullOrWhiteSpace (n))
.ToArray ());
}


static List<string> SplitList (string existingValue)
{
Expand All @@ -44,5 +60,59 @@ static string JoinList (List<string> splitValue)
{
return string.Join (";", splitValue.ToArray ());
}

#region Framework String Cache Stuff

/// <summary>Cache for modified framework strings</summary>
static Dictionary<string, ValueTuple<Dictionary<string, string>, Dictionary<string, string>>> map = new Dictionary<string, ValueTuple<Dictionary<string, string>, Dictionary<string, string>>> ();
enum CacheAction { Add, Remove }

static string GetCache (string currentValue, string value, CacheAction action)
{
ValueTuple<Dictionary<string, string>, Dictionary<string, string>> cacheKey;
if (map.TryGetValue (currentValue, out cacheKey))
{
string cachedValue = string.Empty;
switch (action)
{
case CacheAction.Add:
cacheKey.Item1.TryGetValue (value, out cachedValue);
break;
case CacheAction.Remove:
cacheKey.Item2.TryGetValue (value, out cachedValue);
break;
}
return cachedValue;
}
return string.Empty;
}
static void SetCache (string currentValue, string value, string newValue, CacheAction action)
{
ValueTuple<Dictionary<string, string>, Dictionary<string, string>> outerCacheValue;
if (!map.TryGetValue (currentValue, out outerCacheValue))
{
outerCacheValue = new ValueTuple<Dictionary<string, string>, Dictionary<string, string>> (new Dictionary<string, string> (), new Dictionary<string, string> ());
map.Add (currentValue, outerCacheValue);
}

Dictionary<string, string> innerCacheContainer = null;
switch (action)
{
case CacheAction.Add:
innerCacheContainer = outerCacheValue.Item1;
break;
case CacheAction.Remove:
innerCacheContainer = outerCacheValue.Item2;
break;
}

if (!innerCacheContainer.ContainsKey (value))
{
innerCacheContainer.Add (value, newValue);
}

}

#endregion
}
}
52 changes: 48 additions & 4 deletions mdoc/Mono.Documentation/Updater/Frameworks/FrameworkEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,65 @@ public class FrameworkEntry
SortedSet<FrameworkTypeEntry> types = new SortedSet<FrameworkTypeEntry> ();

IList<FrameworkEntry> allframeworks;
public int index = 0;
ISet<AssemblySet> allAssemblies = new SortedSet<AssemblySet> ();

public FrameworkEntry (IList<FrameworkEntry> frameworks)
public int Index = 0;
int _fxCount;
public int FrameworksCount {
get => _fxCount < 1 ? allframeworks.Count : _fxCount;
}

public FrameworkEntry (IList<FrameworkEntry> frameworks) : this(frameworks, -1) {}

public FrameworkEntry (IList<FrameworkEntry> frameworks, int fxCount)
{
allframeworks = frameworks;
if (allframeworks == null)
allframeworks = new List<FrameworkEntry> (0);

index = allframeworks.Count;
Index = allframeworks.Count;
_fxCount = fxCount;
}

public string Name { get; set; }
public string Version { get; set; }
public string Id { get; set; }

/// <summary>Gets a value indicating whether this <see cref="T:Mono.Documentation.Updater.Frameworks.FrameworkEntry"/> is last framework being processed.</summary>
public bool IsLastFramework {
get => Index == FrameworksCount - 1;
}

string _allFxString = "";
public string AllFrameworksString {
get
{
Lazy<string> fxString = new Lazy<string>(() => string.Join (";", allframeworks.Select (f => f.Name).ToArray ()));

if (!this.IsLastFramework) return fxString.Value;
if (string.IsNullOrWhiteSpace(_allFxString))
{
_allFxString = fxString.Value;
}
return _allFxString;
}
}
public IEnumerable<FrameworkEntry> PreviousFrameworks {
get => allframeworks.Where (f => f.Index < this.Index);
}

public ISet<AssemblySet> AllProcessedAssemblies { get => allAssemblies; }

public void AddAssemblySet (AssemblySet assemblySet)
{
allAssemblies.Add (assemblySet);
}

/// <summary>Gets a value indicating whether this <see cref="T:Mono.Documentation.Updater.Frameworks.FrameworkEntry"/> is first framework being processed.</summary>
public bool IsFirstFramework {
get => this.Index == 0;
}

/// <summary>Only Use in Unit Tests</summary>
public string Replace="";

Expand Down Expand Up @@ -90,7 +134,7 @@ private string GetNamespace (TypeDefinition type)

class EmptyFrameworkEntry : FrameworkEntry
{
public EmptyFrameworkEntry () : base (null) { }
public EmptyFrameworkEntry () : base (null, 1) { }
public override FrameworkTypeEntry ProcessType (TypeDefinition type) { return FrameworkTypeEntry.Empty; }
}
}
Expand Down
20 changes: 15 additions & 5 deletions mdoc/Mono.Documentation/Updater/Frameworks/FrameworkIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,29 @@ public class FrameworkIndex
List<FrameworkEntry> frameworks = new List<FrameworkEntry> ();
string path;

public FrameworkIndex (string pathToFrameworks)
public FrameworkIndex (string pathToFrameworks, int fxCount)
{
path = pathToFrameworks;
FrameworksCount = fxCount;
}

public int FrameworksCount {
get; private set;
}

public IList<FrameworkEntry> Frameworks {
get {
return this.frameworks;
}
}

public FrameworkEntry StartProcessingAssembly (AssemblyDefinition assembly, IEnumerable<DocumentationImporter> importers, string Id, string Version)
public FrameworkEntry StartProcessingAssembly (AssemblySet set, AssemblyDefinition assembly, IEnumerable<DocumentationImporter> importers, string Id, string Version)
{
if (string.IsNullOrWhiteSpace (this.path))
return FrameworkEntry.Empty;
if (string.IsNullOrWhiteSpace (this.path))
{
set.Framework = FrameworkEntry.Empty;
return FrameworkEntry.Empty;
}

string assemblyPath = assembly.MainModule.FileName;
var frameworksDirectory = this.path.EndsWith ("frameworks.xml", StringComparison.OrdinalIgnoreCase)
Expand All @@ -42,9 +50,11 @@ public FrameworkEntry StartProcessingAssembly (AssemblyDefinition assembly, IEnu

var entry = frameworks.FirstOrDefault (f => f.Name.Equals (shortPath));
if (entry == null) {
entry = new FrameworkEntry (frameworks) { Name = shortPath, Importers = importers, Id = Id, Version = Version};
entry = new FrameworkEntry (frameworks, FrameworksCount) { Name = shortPath, Importers = importers, Id = Id, Version = Version};
frameworks.Add (entry);
}

set.Framework = entry;
return entry;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class FrameworkTypeEntry : IComparable<FrameworkTypeEntry>
{
previouslyProcessedFXTypes = new Lazy<FrameworkTypeEntry[]> (
() => this.Framework.Frameworks
.Where (f => f.index < this.Framework.index)
.Where (f => f.Index < this.Framework.Index)
.Select (f => f.FindTypeEntry (this))
.ToArray ()
);
Expand Down
6 changes: 6 additions & 0 deletions mdoc/Test/DocTest-frameworkalternate.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
using System;

namespace Monodoc.Test
{
public class FirstAttribute : Attribute {}
public class SecondAttribute : Attribute {}
public class MyClass
{
#if FXONE
[First]
public void Meth(int a, string b, int c) {}
#endif

#if FXTWO
[First, Second]
public void Meth(int a, string d, int c) {}
#endif
}
Expand Down
8 changes: 4 additions & 4 deletions mdoc/Test/en.expected-cppcli/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
<Assemblies>
<Assembly Name="DocTest-DropNS-classic" Version="0.0.0.0">
<Attributes>
<Attribute>
<Attribute FrameworkAlternate="One">
<AttributeName>System.Diagnostics.Debuggable(System.Diagnostics.DebuggableAttribute+DebuggingModes.IgnoreSymbolStoreSequencePoints)</AttributeName>
</Attribute>
<Attribute>
<Attribute FrameworkAlternate="One">
<AttributeName>System.Runtime.CompilerServices.RuntimeCompatibility(WrapNonExceptionThrows=true)</AttributeName>
</Attribute>
</Attributes>
</Assembly>
<Assembly Name="DocTest-DropNS-classic-secondary" Version="0.0.0.0">
<Attributes>
<Attribute>
<Attribute FrameworkAlternate="Two">
<AttributeName>System.Diagnostics.Debuggable(System.Diagnostics.DebuggableAttribute+DebuggingModes.IgnoreSymbolStoreSequencePoints)</AttributeName>
</Attribute>
<Attribute>
<Attribute FrameworkAlternate="Two">
<AttributeName>System.Runtime.CompilerServices.RuntimeCompatibility(WrapNonExceptionThrows=true)</AttributeName>
</Attribute>
</Attributes>
Expand Down
8 changes: 4 additions & 4 deletions mdoc/Test/en.expected-cppcx/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
<Assemblies>
<Assembly Name="DocTest-DropNS-classic" Version="0.0.0.0">
<Attributes>
<Attribute>
<Attribute FrameworkAlternate="One">
<AttributeName>System.Diagnostics.Debuggable(System.Diagnostics.DebuggableAttribute+DebuggingModes.IgnoreSymbolStoreSequencePoints)</AttributeName>
</Attribute>
<Attribute>
<Attribute FrameworkAlternate="One">
<AttributeName>System.Runtime.CompilerServices.RuntimeCompatibility(WrapNonExceptionThrows=true)</AttributeName>
</Attribute>
</Attributes>
</Assembly>
<Assembly Name="DocTest-DropNS-classic-secondary" Version="0.0.0.0">
<Attributes>
<Attribute>
<Attribute FrameworkAlternate="Two">
<AttributeName>System.Diagnostics.Debuggable(System.Diagnostics.DebuggableAttribute+DebuggingModes.IgnoreSymbolStoreSequencePoints)</AttributeName>
</Attribute>
<Attribute>
<Attribute FrameworkAlternate="Two">
<AttributeName>System.Runtime.CompilerServices.RuntimeCompatibility(WrapNonExceptionThrows=true)</AttributeName>
</Attribute>
</Attributes>
Expand Down
8 changes: 4 additions & 4 deletions mdoc/Test/en.expected-cppwinrt/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
<Assemblies>
<Assembly Name="DocTest-DropNS-classic" Version="0.0.0.0">
<Attributes>
<Attribute>
<Attribute FrameworkAlternate="One">
<AttributeName>System.Diagnostics.Debuggable(System.Diagnostics.DebuggableAttribute+DebuggingModes.IgnoreSymbolStoreSequencePoints)</AttributeName>
</Attribute>
<Attribute>
<Attribute FrameworkAlternate="One">
<AttributeName>System.Runtime.CompilerServices.RuntimeCompatibility(WrapNonExceptionThrows=true)</AttributeName>
</Attribute>
</Attributes>
</Assembly>
<Assembly Name="DocTest-DropNS-classic-secondary" Version="0.0.0.0">
<Attributes>
<Attribute>
<Attribute FrameworkAlternate="Two">
<AttributeName>System.Diagnostics.Debuggable(System.Diagnostics.DebuggableAttribute+DebuggingModes.IgnoreSymbolStoreSequencePoints)</AttributeName>
</Attribute>
<Attribute>
<Attribute FrameworkAlternate="Two">
<AttributeName>System.Runtime.CompilerServices.RuntimeCompatibility(WrapNonExceptionThrows=true)</AttributeName>
</Attribute>
</Attributes>
Expand Down
Loading