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

Initial step for adding AssemblyBuilder.Save implementation #83554

Merged
merged 37 commits into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
247cc65
Initial import AB.Save
buyaa-n Feb 13, 2023
fefba4f
Move code from S.R.Metadata to S.R.Emit
steveharter Mar 2, 2023
063a774
Merge branch 'main' of https://github.com/dotnet/runtime into ab-save
buyaa-n Mar 2, 2023
c4da1d6
Add additional proj refs for VS
steveharter Mar 6, 2023
f0056ac
Merge branch 'ab-save' of github.com:buyaa-n/runtime into ab-save
buyaa-n Mar 6, 2023
625539e
Some refactoring, handle CustomAttributes for Assembly/Module
buyaa-n Mar 14, 2023
7df8da2
Save custom attributes for method/fields
buyaa-n Mar 15, 2023
feb65a4
Remove public APIs until API shape approved
buyaa-n Mar 16, 2023
d78c7d0
Remove custom attibutes related changes
buyaa-n Mar 16, 2023
22f8bb1
Apply feedbacks
buyaa-n Mar 17, 2023
e78d118
Remove CodeDom reference
buyaa-n Mar 18, 2023
9c535d9
Add resources strings
buyaa-n Mar 20, 2023
05fbd7a
Update src/libraries/System.Reflection.Emit/src/Resources/Strings.resx
danmoseley Mar 20, 2023
e7a19e8
Fix field token issue
buyaa-n Mar 20, 2023
689418e
Merge branch 'ab-save' of github.com:buyaa-n/runtime into ab-save
buyaa-n Mar 20, 2023
6ee694c
Remove parameter testing
buyaa-n Mar 21, 2023
fbb0477
Remove unneeded SignatureHelper call
buyaa-n Mar 21, 2023
4dc0be1
Namespace, name updates
buyaa-n Mar 22, 2023
c6b65c9
Update names
buyaa-n Mar 22, 2023
98d07e6
Apply suggestions from code review
buyaa-n Mar 24, 2023
3570054
Apply more feedback
buyaa-n Mar 24, 2023
14f1141
Create the module by name and other feedbacks addressed
buyaa-n Mar 24, 2023
a5ef839
Apply feedbacks
buyaa-n Mar 25, 2023
849d929
Move validations from Runtime *Builders
buyaa-n Mar 26, 2023
c4726ea
Apply more feedback
buyaa-n Mar 27, 2023
0093baa
Update some comments
buyaa-n Mar 28, 2023
9630299
Update core assembly type handling
buyaa-n Mar 29, 2023
b84d99e
Cache the core primitives
buyaa-n Mar 29, 2023
0327112
Update src/libraries/System.Reflection.Emit/src/System/Reflection/Emi…
buyaa-n Mar 29, 2023
8a1bc21
Merge branch 'main' of https://github.com/dotnet/runtime into ab-save
buyaa-n Mar 30, 2023
b5c1df9
Apply more feedback
buyaa-n Mar 30, 2023
eda5e11
Move wrong validation
buyaa-n Mar 30, 2023
60c9ad5
Apply more feedbacks
buyaa-n Mar 31, 2023
8f3be48
Update src/libraries/System.Reflection.Emit/src/System/Reflection/Emi…
buyaa-n Mar 31, 2023
014e1fa
Merge some of the test comparisons
buyaa-n Mar 31, 2023
3e3b854
Refactor tests
buyaa-n Mar 31, 2023
e4aa8b1
Update test with meaningful name and other small changes
buyaa-n Mar 31, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,13 @@ internal static RuntimeAssemblyBuilder InternalDefineDynamicAssembly(
/// modules within an Assembly with the same name. This dynamic module is
/// a transient module.
/// </summary>
protected override ModuleBuilder DefineDynamicModuleCore(string _)
protected override ModuleBuilder DefineDynamicModuleCore(string name)
{
if (name[0] == '\0')
{
throw new ArgumentException(SR.Argument_InvalidName, nameof(name));
}

lock (SyncRoot)
{
// Create the dynamic module- only one ModuleBuilder per AssemblyBuilder can be created.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,9 @@ internal sealed class RuntimeFieldBuilder : FieldBuilder
internal RuntimeFieldBuilder(RuntimeTypeBuilder typeBuilder, string fieldName, Type type,
Type[]? requiredCustomModifiers, Type[]? optionalCustomModifiers, FieldAttributes attributes)
{
ArgumentException.ThrowIfNullOrEmpty(fieldName);

if (fieldName[0] == '\0')
throw new ArgumentException(SR.Argument_IllegalName, nameof(fieldName));

ArgumentNullException.ThrowIfNull(type);

if (type == typeof(void))
throw new ArgumentException(SR.Argument_BadFieldType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,24 +472,22 @@ private RuntimeTypeBuilder(string szName, int genParamPos, RuntimeTypeBuilder de
}

internal RuntimeTypeBuilder(
string fullname, TypeAttributes attr, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type? parent, Type[]? interfaces, RuntimeModuleBuilder module,
string name, TypeAttributes attr, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type? parent, Type[]? interfaces, RuntimeModuleBuilder module,
PackingSize iPackingSize, int iTypeSize, RuntimeTypeBuilder? enclosingType)
{
ArgumentException.ThrowIfNullOrEmpty(fullname);
if (name[0] == '\0')
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
throw new ArgumentException(SR.Argument_IllegalName, nameof(name));

if (fullname[0] == '\0')
throw new ArgumentException(SR.Argument_IllegalName, nameof(fullname));

if (fullname.Length > 1023)
throw new ArgumentException(SR.Argument_TypeNameTooLong, nameof(fullname));
if (name.Length > 1023)
throw new ArgumentException(SR.Argument_TypeNameTooLong, nameof(name));

int i;
m_module = module;
m_DeclaringType = enclosingType;
RuntimeAssemblyBuilder containingAssem = m_module.ContainingAssemblyBuilder;

// cannot have two types within the same assembly of the same name
containingAssem.CheckTypeNameConflict(fullname, enclosingType);
containingAssem.CheckTypeNameConflict(name, enclosingType);

if (enclosingType != null)
{
Expand All @@ -514,18 +512,18 @@ internal RuntimeTypeBuilder(
}
}

int iLast = fullname.LastIndexOf('.');
int iLast = name.LastIndexOf('.');
if (iLast <= 0)
{
// no name space
m_strNameSpace = string.Empty;
m_strName = fullname;
m_strName = name;
}
else
{
// split the name space
m_strNameSpace = fullname.Substring(0, iLast);
m_strName = fullname.Substring(iLast + 1);
m_strNameSpace = name.Substring(0, iLast);
m_strName = name.Substring(iLast + 1);
}

VerifyTypeAttributes(attr);
Expand All @@ -550,7 +548,7 @@ internal RuntimeTypeBuilder(
}

m_tdType = DefineType(new QCallModule(ref module),
fullname, tkParent, m_iAttr, tkEnclosingType, interfaceTokens!);
name, tkParent, m_iAttr, tkEnclosingType, interfaceTokens!);

m_iPackingSize = iPackingSize;
m_iTypeSize = iTypeSize;
Expand Down Expand Up @@ -1558,6 +1556,11 @@ protected override PropertyBuilder DefinePropertyCore(string name, PropertyAttri

protected override EventBuilder DefineEventCore(string name, EventAttributes attributes, Type eventtype)
{
if (name[0] == '\0')
{
throw new ArgumentException(SR.Argument_IllegalName, nameof(name));
}

lock (SyncRoot)
{
int tkType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ public ModuleBuilder DefineDynamicModule(string name)
{
ArgumentException.ThrowIfNullOrEmpty(name);

if (name[0] == '\0')
{
throw new ArgumentException(SR.Argument_InvalidName, nameof(name));
}

return DefineDynamicModuleCore(name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ public void CreateGlobalFunctions()
protected abstract void CreateGlobalFunctionsCore();

public EnumBuilder DefineEnum(string name, TypeAttributes visibility, Type underlyingType)
=> DefineEnumCore(name, visibility, underlyingType);
{
ArgumentException.ThrowIfNullOrEmpty(name);

return DefineEnumCore(name, visibility, underlyingType);
}

protected abstract EnumBuilder DefineEnumCore(string name, TypeAttributes visibility, Type underlyingType);

Expand Down Expand Up @@ -80,7 +84,11 @@ public TypeBuilder DefineType(string name, TypeAttributes attr,

public TypeBuilder DefineType(string name, TypeAttributes attr,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type? parent, Type[]? interfaces)
=> DefineTypeCore(name, attr, parent, interfaces, PackingSize.Unspecified, TypeBuilder.UnspecifiedTypeSize);
{
ArgumentException.ThrowIfNullOrEmpty(name);
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved

return DefineTypeCore(name, attr, parent, interfaces, PackingSize.Unspecified, TypeBuilder.UnspecifiedTypeSize);
}

public TypeBuilder DefineType(string name, TypeAttributes attr,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type? parent, int typesize)
Expand All @@ -92,7 +100,11 @@ public TypeBuilder DefineType(string name, TypeAttributes attr,

public TypeBuilder DefineType(string name, TypeAttributes attr,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type? parent, PackingSize packingSize, int typesize)
=> DefineTypeCore(name, attr, parent, null, packingSize, typesize);
{
ArgumentException.ThrowIfNullOrEmpty(name);

return DefineTypeCore(name, attr, parent, null, packingSize, typesize);
}

protected abstract TypeBuilder DefineTypeCore(string name, TypeAttributes attr,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type? parent, Type[]? interfaces, PackingSize packingSize, int typesize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ public EventBuilder DefineEvent(string name, EventAttributes attributes, Type ev
{
ArgumentException.ThrowIfNullOrEmpty(name);

if (name[0] == '\0')
throw new ArgumentException(SR.Argument_IllegalName, nameof(name));

return DefineEventCore(name, attributes, eventtype);
}

Expand All @@ -76,7 +73,12 @@ public FieldBuilder DefineField(string fieldName, Type type, FieldAttributes att

public FieldBuilder DefineField(string fieldName, Type type, Type[]? requiredCustomModifiers, Type[]? optionalCustomModifiers,
FieldAttributes attributes)
=> DefineFieldCore(fieldName, type, requiredCustomModifiers, optionalCustomModifiers, attributes);
{
ArgumentException.ThrowIfNullOrEmpty(fieldName);
ArgumentNullException.ThrowIfNull(type);

return DefineFieldCore(fieldName, type, requiredCustomModifiers, optionalCustomModifiers, attributes);
}

protected abstract FieldBuilder DefineFieldCore(string fieldName, Type type, Type[]? requiredCustomModifiers, Type[]? optionalCustomModifiers,
FieldAttributes attributes);
Expand Down Expand Up @@ -159,7 +161,11 @@ public TypeBuilder DefineNestedType(string name, TypeAttributes attr,

public TypeBuilder DefineNestedType(string name, TypeAttributes attr,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type? parent, Type[]? interfaces)
=> DefineNestedTypeCore(name, attr, parent, interfaces, PackingSize.Unspecified, UnspecifiedTypeSize);
{
ArgumentException.ThrowIfNullOrEmpty(name);

return DefineNestedTypeCore(name, attr, parent, interfaces, PackingSize.Unspecified, UnspecifiedTypeSize);
}

protected abstract TypeBuilder DefineNestedTypeCore(string name, TypeAttributes attr,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type? parent, Type[]? interfaces, PackingSize packSize, int typeSize);
Expand All @@ -174,7 +180,11 @@ public TypeBuilder DefineNestedType(string name, TypeAttributes attr,

public TypeBuilder DefineNestedType(string name, TypeAttributes attr,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type? parent, PackingSize packSize, int typeSize)
=> DefineNestedTypeCore(name, attr, parent, null, packSize, typeSize);
{
ArgumentException.ThrowIfNullOrEmpty(name);

return DefineNestedTypeCore(name, attr, parent, null, packSize, typeSize);
}

[RequiresUnreferencedCode("P/Invoke marshalling may dynamically access members that could be trimmed.")]
public MethodBuilder DefinePInvokeMethod(string name, string dllName, MethodAttributes attributes,
Expand Down
Loading