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

TypeName parsing API #100094

Merged
merged 52 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
22d131e
TypeNameParser first ref and configurable input validation
adamsitnik Jan 23, 2024
5de9526
assembly name parsing
adamsitnik Jan 24, 2024
6dbcd59
initial generic type info parsing
adamsitnik Jan 25, 2024
6f1f161
decorator parsing
adamsitnik Jan 26, 2024
4ec4ea5
Handle single dimensional array indexing
adamsitnik Jan 29, 2024
f5a8716
implement TypeName.GetType
adamsitnik Jan 29, 2024
52cb351
nested types support
adamsitnik Jan 30, 2024
60ad6f0
support ignore case
adamsitnik Jan 31, 2024
b5349bd
integrate with System.Private.CoreLib:
adamsitnik Jan 31, 2024
2dbd091
integrate with System.Private.CoreLib:
adamsitnik Feb 1, 2024
bd78637
integrate with System.Private.CoreLib for Mono and clr tools, improve…
adamsitnik Feb 2, 2024
8fda94a
build fix 1/n
adamsitnik Feb 2, 2024
745e7bb
make TypeNameParser internal, extend TypeName with Parse and TryParse…
adamsitnik Feb 7, 2024
ee43e71
introduce TotalComplexity
adamsitnik Feb 7, 2024
a3a7f26
introduce FullName, so we have Name, FullName and AssemblyQualifiedNa…
adamsitnik Feb 7, 2024
a2296d0
back tick error handling
adamsitnik Feb 9, 2024
4c8a6f7
move helper methods to a standalone helper type, include it as a link…
adamsitnik Feb 9, 2024
eadf970
increase test coverage, improve edge case handling
adamsitnik Feb 12, 2024
abf7543
sample SerializationBinder that uses the new APIs
adamsitnik Feb 12, 2024
281c4f3
cover more serialization binder scenarios with the tests to ensure th…
adamsitnik Feb 13, 2024
dc58cce
strict mode parsing: type names
adamsitnik Feb 19, 2024
b947977
strict mode parsing: assembly names
adamsitnik Feb 20, 2024
4c9a7d5
Merge remote-tracking branch 'upstream/main' into typeNameParser
adamsitnik Feb 22, 2024
c63f3a8
fix the build and apply some design changes
adamsitnik Feb 22, 2024
83cdd1b
add escaping support
adamsitnik Feb 22, 2024
23ad44f
fix the last failing tests, increase test coverage, fix the perf, fix…
adamsitnik Feb 23, 2024
96b04f4
Merge remote-tracking branch 'upstream/main' into typeNameParser
adamsitnik Mar 19, 2024
c8014fd
apply changes based on the 1st API Design Review
adamsitnik Mar 19, 2024
1c76366
apply changes based on the final API Design Review
adamsitnik Mar 20, 2024
8cd205a
solve the TODOs
adamsitnik Mar 20, 2024
ae514ec
implement IEquatable, add missing exception messages, set default Max…
adamsitnik Mar 21, 2024
c7c67c8
address code review feedback, make some tests conditional, remove inv…
adamsitnik Mar 22, 2024
87804e9
Apply suggestions from code review
adamsitnik Mar 22, 2024
97aad27
supress IL3050:RequiresDynamicCode
adamsitnik Mar 22, 2024
f940723
remove everything related to strict parsing (it will come back in a s…
adamsitnik Mar 22, 2024
b1ed250
remove special handling for Array.MaxLength-many generic args
adamsitnik Mar 22, 2024
90a5582
remove the unused property, use the new names for non-public APIs as …
adamsitnik Mar 22, 2024
9a5d01b
make the allocations happen when they are actually needed for the fir…
adamsitnik Apr 2, 2024
cfb2216
don't pre-allocate full names for all declaring types, just store the…
adamsitnik Apr 3, 2024
d63365f
build fix
adamsitnik Apr 3, 2024
7d685c8
Merge remote-tracking branch 'upstream/main' into typeNameParser
adamsitnik Apr 9, 2024
04731fb
address part of the code review feedback
adamsitnik Apr 9, 2024
113a87f
fix the build
adamsitnik Apr 11, 2024
7005164
AssemblyNameInfo
adamsitnik Apr 15, 2024
cd8a9c2
don't enforce the back tick convention
adamsitnik Apr 16, 2024
1143a3e
Merge remote-tracking branch 'upstream/main' into typeNameParser
adamsitnik Apr 17, 2024
afdbc5f
address API and code review feedback:
adamsitnik Apr 17, 2024
413be9e
minor tweaks after reading the code again
adamsitnik Apr 17, 2024
b424d76
try to improve the escaping handling
adamsitnik Apr 18, 2024
da203c0
address code review feedback:
adamsitnik Apr 23, 2024
7979e27
address code review feedback:
adamsitnik Apr 24, 2024
22de761
Apply suggestions from code review
adamsitnik Apr 24, 2024
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
Prev Previous commit
Next Next commit
remove everything related to strict parsing (it will come back in a s…
…imilar form but with a different name)
  • Loading branch information
adamsitnik committed Mar 22, 2024
commit f9407232f6a4582d853e869082cd41cb051c1f5e
3 changes: 0 additions & 3 deletions src/coreclr/tools/ILVerification/ILVerification.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@
<Compile Include="$(LibrariesProjectRoot)\Common\src\System\Reflection\AssemblyNameParser.cs">
<Link>Utilities\AssemblyNameParser.cs</Link>
</Compile>
<Compile Include="$(LibrariesProjectRoot)\Common\src\System\Reflection\AssemblyNameParser.netstandard.cs" Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<Link>Utilities\AssemblyNameParser.netstandard.cs</Link>
</Compile>
<Compile Include="$(LibrariesProjectRoot)\Common\src\System\Reflection\Metadata\TypeName.cs">
<Link>Utilities\TypeName.cs</Link>
</Compile>
Expand Down
38 changes: 6 additions & 32 deletions src/libraries/Common/src/System/Reflection/AssemblyNameParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ private enum AttributeKind
}

private readonly ReadOnlySpan<char> _input;
private readonly bool _strict;
private int _index;

private AssemblyNameParser(ReadOnlySpan<char> input, bool strict = false)
private AssemblyNameParser(ReadOnlySpan<char> input)
{
#if SYSTEM_PRIVATE_CORELIB
if (input.Length == 0)
Expand All @@ -70,7 +69,6 @@ private AssemblyNameParser(ReadOnlySpan<char> input, bool strict = false)
#endif

_input = input;
_strict = strict;
_index = 0;
}

Expand All @@ -89,9 +87,9 @@ public static AssemblyNameParts Parse(ReadOnlySpan<char> name)
}
#endif

internal static bool TryParse(ReadOnlySpan<char> name, bool strict, ref AssemblyNameParts parts)
internal static bool TryParse(ReadOnlySpan<char> name, ref AssemblyNameParts parts)
{
AssemblyNameParser parser = new(name, strict);
AssemblyNameParser parser = new(name);
return parser.TryParse(ref parts);
}

Expand Down Expand Up @@ -170,11 +168,6 @@ private bool TryParse(ref AssemblyNameParts result)
return false;
}
}
else if (_strict)
{
// it's either unrecognized or not on the allow list (Version, Culture and PublicKeyToken)
return false;
}
else if (IsAttribute(attributeName, "PublicKey"))
{
if (!TryRecordNewSeen(ref alreadySeen, AttributeKind.PublicKeyOrToken))
Expand Down Expand Up @@ -250,8 +243,8 @@ private bool TryParse(ref AssemblyNameParts result)
return true;
}

private bool IsAttribute(string candidate, string attributeKind)
=> candidate.Equals(attributeKind, _strict ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase);
private static bool IsAttribute(string candidate, string attributeKind)
=> candidate.Equals(attributeKind, StringComparison.OrdinalIgnoreCase);

private static bool TryParseVersion(string attributeValue, ref Version? version)
{
Expand Down Expand Up @@ -302,18 +295,13 @@ private static bool TryParseVersion(string attributeValue, ref Version? version)
return true;
}

private bool TryParseCulture(string attributeValue, out string? result)
private static bool TryParseCulture(string attributeValue, out string? result)
{
if (attributeValue.Equals("Neutral", StringComparison.OrdinalIgnoreCase))
{
result = "";
return true;
}
else if (_strict && !IsPredefinedCulture(attributeValue))
{
result = null;
return false;
}

result = attributeValue;
return true;
Expand Down Expand Up @@ -537,19 +525,5 @@ private bool TryGetNextToken(out string tokenString, out Token token)
token = Token.String;
return true;
}

#if NET8_0_OR_GREATER
private static bool IsPredefinedCulture(string cultureName)
{
try
{
return CultureInfo.GetCultureInfo(cultureName, predefinedOnly: true) is not null;
}
catch (CultureNotFoundException)
{
return false;
}
}
#endif
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ private TypeNameParser(ReadOnlySpan<char> name, bool throwOnError, TypeNameParse
}

ReadOnlySpan<char> fullTypeName = _inputString.Slice(0, fullTypeNameLength);
int invalidCharIndex = GetIndexOfFirstInvalidTypeNameCharacter(fullTypeName, _parseOptions.StrictValidation);
if (invalidCharIndex >= 0)
{
return null;
}
_inputString = _inputString.Slice(fullTypeNameLength);

int genericArgIndex = 0;
Expand Down Expand Up @@ -264,8 +259,7 @@ private bool TryParseAssemblyName(ref AssemblyName? assemblyName)
ReadOnlySpan<char> candidate = _inputString.Slice(0, assemblyNameLength);
AssemblyNameParser.AssemblyNameParts parts = default;

if (GetIndexOfFirstInvalidAssemblyNameCharacter(candidate, _parseOptions.StrictValidation) >= 0
|| !AssemblyNameParser.TryParse(candidate, _parseOptions.StrictValidation, ref parts))
if (!AssemblyNameParser.TryParse(candidate, ref parts))
{
return false;
}
Expand Down
Loading