Browse Source

Conditional defines should only be added once per symbol.

pull/850/head
Siegfried Pammer 8 years ago
parent
commit
9035211d06
  1. 4
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

4
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -685,12 +685,14 @@ namespace ICSharpCode.Decompiler.CSharp @@ -685,12 +685,14 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
readonly HashSet<string> definedSymbols = new HashSet<string>();
void AddDefinesForConditionalAttributes(ILFunction function)
{
foreach (var call in function.Descendants.OfType<CallInstruction>()) {
var attr = call.Method.GetAttribute(new TopLevelTypeName("System.Diagnostics", nameof(ConditionalAttribute)));
var symbolName = attr?.PositionalArguments.FirstOrDefault()?.ConstantValue as string;
if (symbolName == null)
if (symbolName == null || !definedSymbols.Add(symbolName))
continue;
syntaxTree.InsertChildAfter(null, new PreProcessorDirective(PreProcessorDirectiveType.Define, symbolName), Roles.PreProcessorDirective);
}

Loading…
Cancel
Save