Skip to content

Commit

Permalink
Moved LocalVariableInfo to shared (dotnet#19184)
Browse files Browse the repository at this point in the history
* File Modified

* Moved to shared

* Introducing RuntimeLocalVariableInfo

* Build Corefx change

* sealed added
  • Loading branch information
Anipik authored Aug 3, 2018
1 parent f6e2b9c commit b3db104
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/System.Private.CoreLib/System.Private.CoreLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@
<Compile Include="$(BclSourcesRoot)\System\Reflection\FieldInfo.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\INVOCATION_FLAGS.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\LoaderAllocator.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\LocalVariableInfo.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\MdConstant.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\MdFieldInfo.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\MdImport.cs" />
Expand All @@ -326,6 +325,7 @@
<Compile Include="$(BclSourcesRoot)\System\Reflection\RuntimeConstructorInfo.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\RuntimeEventInfo.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\RuntimeFieldInfo.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\RuntimeLocalVariableInfo.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\RuntimeMethodInfo.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\RuntimeModule.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\RuntimeParameterInfo.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\InvalidFilterCriteriaException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\IReflect.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\IReflectableType.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\LocalVariableInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ManifestResourceInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MemberFilter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MemberInfo.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,10 @@ namespace System.Reflection
{
public class LocalVariableInfo
{
#region Private Data Members
private RuntimeType m_type;
private int m_isPinned;
private int m_localIndex;
#endregion

#region Constructor
public virtual Type LocalType { get { Debug.Fail("type must be set!"); return null; } }
public virtual int LocalIndex => 0;
public virtual bool IsPinned => false;
protected LocalVariableInfo() { }
#endregion

#region Object Overrides
public override string ToString()
{
string toString = LocalType.ToString() + " (" + LocalIndex + ")";
Expand All @@ -28,13 +21,6 @@ public override string ToString()

return toString;
}
#endregion

#region Public Members
public virtual Type LocalType { get { Debug.Assert(m_type != null, "type must be set!"); return m_type; } }
public virtual bool IsPinned { get { return m_isPinned != 0; } }
public virtual int LocalIndex { get { return m_localIndex; } }
#endregion
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics;

namespace System.Reflection
{
internal sealed class RuntimeLocalVariableInfo : LocalVariableInfo
{
private RuntimeType _type;
private int _localIndex;
private bool _isPinned;

protected RuntimeLocalVariableInfo() { }

public override Type LocalType { get { Debug.Assert(_type != null, "type must be set!"); return _type; } }
public override int LocalIndex => _localIndex;
public override bool IsPinned => _isPinned;
}
}
10 changes: 5 additions & 5 deletions src/vm/mscorlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,11 +552,11 @@ DEFINE_FIELD_U(m_catchMetadataToken, ExceptionHandlingClause, m_cat
DEFINE_FIELD_U(m_filterOffset, ExceptionHandlingClause, m_filterOffset)
DEFINE_CLASS(EH_CLAUSE, Reflection, ExceptionHandlingClause)

DEFINE_CLASS_U(Reflection, LocalVariableInfo, LocalVariableInfo)
DEFINE_FIELD_U(m_type, LocalVariableInfo, m_type)
DEFINE_FIELD_U(m_isPinned, LocalVariableInfo, m_bIsPinned)
DEFINE_FIELD_U(m_localIndex, LocalVariableInfo, m_localIndex)
DEFINE_CLASS(LOCAL_VARIABLE_INFO, Reflection, LocalVariableInfo)
DEFINE_CLASS_U(Reflection, RuntimeLocalVariableInfo, RuntimeLocalVariableInfo)
DEFINE_FIELD_U(_type, RuntimeLocalVariableInfo, _type)
DEFINE_FIELD_U(_localIndex, RuntimeLocalVariableInfo, _localIndex)
DEFINE_FIELD_U(_isPinned, RuntimeLocalVariableInfo, _isPinned)
DEFINE_CLASS(RUNTIME_LOCAL_VARIABLE_INFO, Reflection, RuntimeLocalVariableInfo)

DEFINE_CLASS_U(Reflection, MethodBody, MethodBody)
DEFINE_FIELD_U(m_IL, MethodBody, m_IL)
Expand Down
16 changes: 8 additions & 8 deletions src/vm/runtimehandles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2430,7 +2430,7 @@ FCIMPL2(MethodBody *, RuntimeMethodHandle::GetMethodBody, ReflectMethodObject *p
{
METHODBODYREF MethodBodyObj;
EXCEPTIONHANDLINGCLAUSEREF EHClauseObj;
LOCALVARIABLEINFOREF LocalVariableInfoObj;
RUNTIMELOCALVARIABLEINFOREF RuntimeLocalVariableInfoObj;
U1ARRAYREF U1Array;
BASEARRAYREF TempArray;
REFLECTCLASSBASEREF declaringType;
Expand All @@ -2439,7 +2439,7 @@ FCIMPL2(MethodBody *, RuntimeMethodHandle::GetMethodBody, ReflectMethodObject *p

gc.MethodBodyObj = NULL;
gc.EHClauseObj = NULL;
gc.LocalVariableInfoObj = NULL;
gc.RuntimeLocalVariableInfoObj = NULL;
gc.U1Array = NULL;
gc.TempArray = NULL;
gc.declaringType = (REFLECTCLASSBASEREF)ObjectToOBJECTREF(pDeclaringTypeUNSAFE);
Expand Down Expand Up @@ -2469,7 +2469,7 @@ FCIMPL2(MethodBody *, RuntimeMethodHandle::GetMethodBody, ReflectMethodObject *p
MethodTable * pExceptionHandlingClauseMT = MscorlibBinder::GetClass(CLASS__EH_CLAUSE);
TypeHandle thEHClauseArray = ClassLoader::LoadArrayTypeThrowing(TypeHandle(pExceptionHandlingClauseMT), ELEMENT_TYPE_SZARRAY);

MethodTable * pLocalVariableMT = MscorlibBinder::GetClass(CLASS__LOCAL_VARIABLE_INFO);
MethodTable * pLocalVariableMT = MscorlibBinder::GetClass(CLASS__RUNTIME_LOCAL_VARIABLE_INFO);
TypeHandle thLocalVariableArray = ClassLoader::LoadArrayTypeThrowing(TypeHandle(pLocalVariableMT), ELEMENT_TYPE_SZARRAY);

Module* pModule = pMethod->GetModule();
Expand Down Expand Up @@ -2551,21 +2551,21 @@ FCIMPL2(MethodBody *, RuntimeMethodHandle::GetMethodBody, ReflectMethodObject *p

for (INT32 i = 0; i < cLocals; i ++)
{
gc.LocalVariableInfoObj = (LOCALVARIABLEINFOREF)AllocateObject(pLocalVariableMT);
gc.RuntimeLocalVariableInfoObj = (RUNTIMELOCALVARIABLEINFOREF)AllocateObject(pLocalVariableMT);

gc.LocalVariableInfoObj->m_localIndex = i;
gc.RuntimeLocalVariableInfoObj->_localIndex = i;

metaSig.NextArg();

CorElementType eType;
IfFailThrow(metaSig.GetArgProps().PeekElemType(&eType));
if (ELEMENT_TYPE_PINNED == eType)
gc.LocalVariableInfoObj->m_bIsPinned = TRUE;
gc.RuntimeLocalVariableInfoObj->_isPinned = TRUE;

TypeHandle tempType= metaSig.GetArgProps().GetTypeHandleThrowing(pModule, &sigTypeContext);
OBJECTREF refLocalType = tempType.GetManagedClassObject();
gc.LocalVariableInfoObj->SetType(refLocalType);
gc.MethodBodyObj->m_localVariables->SetAt(i, (OBJECTREF) gc.LocalVariableInfoObj);
gc.RuntimeLocalVariableInfoObj->SetType(refLocalType);
gc.MethodBodyObj->m_localVariables->SetAt(i, (OBJECTREF) gc.RuntimeLocalVariableInfoObj);
}
}
else
Expand Down
22 changes: 11 additions & 11 deletions src/vm/runtimehandles.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ typedef enum ReflectionCallConv {

class ExceptionHandlingClause;
class MethodBody;
class LocalVariableInfo;
class RuntimeLocalVariableInfo;

#ifdef USE_CHECKED_OBJECTREFS
typedef REF<ExceptionHandlingClause> EXCEPTIONHANDLINGCLAUSEREF;
typedef REF<MethodBody> METHODBODYREF;
typedef REF<LocalVariableInfo> LOCALVARIABLEINFOREF;
typedef REF<RuntimeLocalVariableInfo> RUNTIMELOCALVARIABLEINFOREF;
#else
typedef DPTR(ExceptionHandlingClause) EXCEPTIONHANDLINGCLAUSEREF;
typedef DPTR(MethodBody) METHODBODYREF;
typedef DPTR(LocalVariableInfo) LOCALVARIABLEINFOREF;
typedef DPTR(RuntimeLocalVariableInfo) RUNTIMELOCALVARIABLEINFOREF;
#endif

class ExceptionHandlingClause : Object
Expand Down Expand Up @@ -80,28 +80,28 @@ class MethodBody : Object
CLR_BOOL m_initLocals;
};

class LocalVariableInfo : Object
class RuntimeLocalVariableInfo : Object
{
private:
// Disallow creation and copy construction of these.
LocalVariableInfo() { }
LocalVariableInfo(LocalVariableInfo &r) { }
RuntimeLocalVariableInfo() { }
RuntimeLocalVariableInfo(RuntimeLocalVariableInfo &r) { }

public:

REFLECTCLASSBASEREF GetType()
{
return (REFLECTCLASSBASEREF)m_type;
return (REFLECTCLASSBASEREF)_type;
}

void SetType(OBJECTREF type)
{
SetObjectReference(&m_type, type, GetAppDomain());
SetObjectReference(&_type, type, GetAppDomain());
}

OBJECTREF m_type;
INT32 m_bIsPinned;
INT32 m_localIndex;
OBJECTREF _type;
INT32 _localIndex;
CLR_BOOL _isPinned;
};

class MdUtf8String {
Expand Down

0 comments on commit b3db104

Please sign in to comment.