Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
iskiselev committed Aug 5, 2016
2 parents da1f7ee + 71c0bc1 commit e497032
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Compiler/Analyzers/DeadCodeAnalyzer/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class Configuration {
private readonly bool _DeadCodeElimination;
private readonly bool _NonAggressiveVirtualMethodElimination;
private readonly IList<string> _WhiteList;

private readonly IList<string> _AssembliesWhiteList;

public Configuration(IDictionary<string, object> configuration) {
_DeadCodeElimination = configuration.ContainsKey("DeadCodeElimination") &&
configuration["DeadCodeElimination"] is bool &&
Expand All @@ -23,6 +24,11 @@ public Configuration(IDictionary<string, object> configuration) {
configuration["WhiteList"] is IList) {
_WhiteList = ((IList) configuration["WhiteList"]).Cast<string>().ToList();
}

if (configuration.ContainsKey("AssembliesWhiteList") && configuration["AssembliesWhiteList"] is IList)
{
_AssembliesWhiteList = ((IList)configuration["AssembliesWhiteList"]).Cast<string>().ToList();
}
}

public bool DeadCodeElimination
Expand All @@ -39,5 +45,10 @@ public IList<string> WhiteList
{
get { return _WhiteList; }
}

public IList<string> AssembliesWhiteList
{
get { return _AssembliesWhiteList; }
}
}
}
19 changes: 19 additions & 0 deletions Compiler/Analyzers/DeadCodeAnalyzer/DeadCodeInfoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public bool IsIncluded(TypeDefinition typeToTest)
private readonly HashSet<EventDefinition> Events = new HashSet<EventDefinition>();

private readonly TypeMapStep TypeMapStep = new TypeMapStep();
private readonly List<Regex> AssembliesWhiteListCache;
private readonly List<Regex> WhiteListCache;
private readonly Configuration Configuration;

Expand All @@ -130,6 +131,16 @@ public DeadCodeInfoProvider(Configuration configuration) {
WhiteListCache.Add(compiledRegex);
}
}

if (configuration.AssembliesWhiteList != null && configuration.AssembliesWhiteList.Count > 0)
{
AssembliesWhiteListCache = new List<Regex>(configuration.AssembliesWhiteList.Count);
foreach (var pattern in configuration.AssembliesWhiteList)
{
var compiledRegex = new Regex(pattern, RegexOptions.ECMAScript | RegexOptions.Compiled);
AssembliesWhiteListCache.Add(compiledRegex);
}
}
}

internal TypeInfoProvider TypeInfoProvider { get; set; }
Expand Down Expand Up @@ -892,6 +903,14 @@ private void AddField(FieldReference field) {

private bool IsMemberWhiteListed(MemberReference member)
{
if (AssembliesWhiteListCache != null)
{
if (AssembliesWhiteListCache.Any(regex => regex.IsMatch(member.Module.Assembly.FullName)))
{
return true;
}
}

if (WhiteListCache != null) {
if (WhiteListCache.Any(regex => regex.IsMatch(member.FullName))) {
return true;
Expand Down

0 comments on commit e497032

Please sign in to comment.