Skip to content

Commit

Permalink
Add ProcessLinkerXmlBase to NativeAOT (#63666)
Browse files Browse the repository at this point in the history
Add Xml Parsing linker files as a reference source to NativeAOT
Rename NativeAOT ProcessLinkerXmlBase version to ProcessXmlBase (uses XmlReader) 
Add ProcessLinkerXmlBase from linker and fix it so it can be used in NativeAOT (uses XPath)
  • Loading branch information
tlakollo committed Jan 20, 2022
1 parent f1c8b10 commit 65a5d0e
Show file tree
Hide file tree
Showing 13 changed files with 2,696 additions and 186 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Xml.XPath;
using ILLink.Shared;
using Internal.TypeSystem;

namespace ILCompiler
{
public static class FeatureSettings
{
public static bool ShouldProcessElement(XPathNavigator nav, IReadOnlyDictionary<string, bool> featureSwitchValues)
{
var feature = GetAttribute(nav, "feature");
if (string.IsNullOrEmpty(feature))
return true;

var value = GetAttribute(nav, "featurevalue");
if (string.IsNullOrEmpty(value))
{
//context.LogError(null, DiagnosticId.XmlFeatureDoesNotSpecifyFeatureValue, documentLocation, feature);
return false;
}

if (!bool.TryParse(value, out bool bValue))
{
//context.LogError(null, DiagnosticId.XmlUnsupportedNonBooleanValueForFeature, documentLocation, feature);
return false;
}

var isDefault = GetAttribute(nav, "featuredefault");
bool bIsDefault = false;
if (!string.IsNullOrEmpty(isDefault) && (!bool.TryParse(isDefault, out bIsDefault) || !bIsDefault))
{
//context.LogError(null, DiagnosticId.XmlDocumentLocationHasInvalidFeatureDefault, documentLocation);
return false;
}

if (!featureSwitchValues.TryGetValue(feature, out bool featureSetting))
return bIsDefault;

return bValue == featureSetting;
}

public static string GetAttribute(XPathNavigator nav, string attribute)
{
return nav.GetAttribute(attribute, String.Empty);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ public MethodIL EmitIL(MethodDesc method)
}
}

private class SubstitutionsReader : ProcessLinkerXmlBase
private class SubstitutionsReader : ProcessXmlBase
{
private readonly Dictionary<MethodDesc, BodySubstitution> _methodSubstitutions;
private readonly Dictionary<FieldDesc, object> _fieldSubstitutions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public AssemblyFeatureInfo(EcmaModule module, IReadOnlyDictionary<string, bool>
}
}

private class SubstitutionsReader : ProcessLinkerXmlBase
private class SubstitutionsReader : ProcessXmlBase
{
private readonly HashSet<string> _substitutions = new HashSet<string>();

Expand Down
Loading

0 comments on commit 65a5d0e

Please sign in to comment.