mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 03:28:20 +02:00
Reflection support for method param attributes, return attributes
This commit is contained in:
parent
19513d3310
commit
c10565678e
4 changed files with 38 additions and 14 deletions
|
@ -37,11 +37,22 @@ namespace System.Reflection
|
|||
return mMethodData.mParamData[paramIdx].mName;
|
||||
}
|
||||
|
||||
public Result<T> GetParamCustomAttribute<T>(int paramIdx) where T : Attribute
|
||||
{
|
||||
Debug.Assert((uint)paramIdx < (uint)mMethodData.mParamCount);
|
||||
return mTypeInstance.[Friend]GetCustomAttribute<T>(mMethodData.mParamData[paramIdx].mCustomAttributesIdx);
|
||||
}
|
||||
|
||||
public Result<T> GetCustomAttribute<T>() where T : Attribute
|
||||
{
|
||||
return mTypeInstance.[Friend]GetCustomAttribute<T>(mMethodData.mCustomAttributesIdx);
|
||||
}
|
||||
|
||||
public Result<T> GetReturnCustomAttribute<T>() where T : Attribute
|
||||
{
|
||||
return mTypeInstance.[Friend]GetCustomAttribute<T>(mMethodData.mReturnCustomAttributesIdx);
|
||||
}
|
||||
|
||||
public enum CallError
|
||||
{
|
||||
case None;
|
||||
|
|
|
@ -718,6 +718,7 @@ namespace System.Reflection
|
|||
public int32 mMethodIdx;
|
||||
public int32 mVirtualIdx;
|
||||
public int32 mCustomAttributesIdx;
|
||||
public int32 mReturnCustomAttributesIdx;
|
||||
}
|
||||
|
||||
public enum ParamFlags : int16
|
||||
|
@ -734,6 +735,7 @@ namespace System.Reflection
|
|||
public TypeId mType;
|
||||
public ParamFlags mParamFlags;
|
||||
public int32 mDefaultIdx;
|
||||
public int32 mCustomAttributesIdx;
|
||||
}
|
||||
|
||||
public struct InterfaceData
|
||||
|
|
|
@ -679,6 +679,7 @@ namespace System.Reflection
|
|||
public int32 mMethodIdx;
|
||||
public int32 mVirtualIdx;
|
||||
public int32 mCustomAttributesIdx;
|
||||
public int32 mReturnCustomAttributesIdx;
|
||||
}
|
||||
|
||||
public enum ParamFlags : int16
|
||||
|
@ -695,6 +696,7 @@ namespace System.Reflection
|
|||
public TypeId mType;
|
||||
public ParamFlags mParamFlags;
|
||||
public int32 mDefaultIdx;
|
||||
public int32 mCustomAttributesIdx;
|
||||
}
|
||||
|
||||
public struct InterfaceData
|
||||
|
|
|
@ -6501,7 +6501,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
|
|||
struct _SortedMethodInfo
|
||||
{
|
||||
BfMethodDef* mMethodDef;
|
||||
BfCustomAttributes* mMethodCustomAttributes;
|
||||
BfMethodCustomAttributes* mMethodCustomAttributes;
|
||||
};
|
||||
|
||||
Array<_SortedMethodInfo> sortedMethodList;
|
||||
|
@ -6542,10 +6542,10 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
|
|||
|
||||
bool includeMethod = reflectIncludeAllMethods;
|
||||
|
||||
BfCustomAttributes* methodCustomAttributes = NULL;
|
||||
BfMethodCustomAttributes* methodCustomAttributes = NULL;
|
||||
if ((defaultMethod->mMethodInfoEx != NULL) && (defaultMethod->mMethodInfoEx->mMethodCustomAttributes != NULL) && (defaultMethod->mMethodInfoEx->mMethodCustomAttributes->mCustomAttributes != NULL))
|
||||
{
|
||||
methodCustomAttributes = defaultMethod->mMethodInfoEx->mMethodCustomAttributes->mCustomAttributes;
|
||||
methodCustomAttributes = defaultMethod->mMethodInfoEx->mMethodCustomAttributes;
|
||||
for (auto& customAttr : defaultMethod->mMethodInfoEx->mMethodCustomAttributes->mCustomAttributes->mAttributes)
|
||||
{
|
||||
if (customAttr.mType->mTypeDef->mName->ToString() == "ReflectAttribute")
|
||||
|
@ -6643,7 +6643,13 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
|
|||
|
||||
BfMethodFlags methodFlags = defaultMethod->GetMethodFlags();
|
||||
|
||||
int customAttrIdx = _HandleCustomAttrs(methodInfo.mMethodCustomAttributes);
|
||||
int customAttrIdx = -1;
|
||||
int returnCustomAttrIdx = -1;
|
||||
if (methodInfo.mMethodCustomAttributes != NULL)
|
||||
{
|
||||
customAttrIdx = _HandleCustomAttrs(methodInfo.mMethodCustomAttributes->mCustomAttributes);
|
||||
returnCustomAttrIdx = _HandleCustomAttrs(methodInfo.mMethodCustomAttributes->mReturnCustomAttributes);
|
||||
}
|
||||
|
||||
enum ParamFlags
|
||||
{
|
||||
|
@ -6664,13 +6670,18 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
|
|||
|
||||
BfIRValue paramNameConst = GetStringObjectValue(paramName, !mIsComptimeModule);
|
||||
|
||||
int paramCustomAttrIdx = -1;
|
||||
if ((methodInfo.mMethodCustomAttributes != NULL) && (paramIdx < (int)methodInfo.mMethodCustomAttributes->mParamCustomAttributes.mSize))
|
||||
paramCustomAttrIdx = _HandleCustomAttrs(methodInfo.mMethodCustomAttributes->mParamCustomAttributes[paramIdx]);
|
||||
|
||||
SizedArray<BfIRValue, 8> paramDataVals =
|
||||
{
|
||||
emptyValueType,
|
||||
paramNameConst,
|
||||
GetConstValue(paramType->mTypeId, typeIdType),
|
||||
GetConstValue((int32)paramFlags, shortType),
|
||||
GetConstValue(customAttrIdx, intType) // defaultIdx
|
||||
GetConstValue(-1, intType), // defaultIdx
|
||||
GetConstValue(paramCustomAttrIdx, intType) // customAttrIdx
|
||||
};
|
||||
auto paramData = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapType(reflectParamDataType, BfIRPopulateType_Full), paramDataVals);
|
||||
paramVals.Add(paramData);
|
||||
|
@ -6739,6 +6750,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
|
|||
GetConstValue(methodIdx, intType),
|
||||
GetConstValue(vDataVal, intType),
|
||||
GetConstValue(customAttrIdx, intType),
|
||||
GetConstValue(returnCustomAttrIdx, intType),
|
||||
};
|
||||
auto methodData = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectMethodDataType->ToTypeInstance(), BfIRPopulateType_Full), methodDataVals);
|
||||
methodTypes.push_back(methodData);
|
||||
|
@ -11369,14 +11381,13 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri
|
|||
{
|
||||
Fail(StrFormat("'%s' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are '%s'. All attributes in this block will be ignored.",
|
||||
GetAttributesTargetListString(targetOverride).c_str(), GetAttributesTargetListString(attrTarget).c_str()), attributesDirective->mAttributeTargetSpecifier); // CS0657
|
||||
}
|
||||
|
||||
success = false;
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ((success) && (targetOverride != (BfAttributeTargets)0))
|
||||
{
|
||||
if ((targetOverride == BfAttributeTargets_ReturnValue) && (attrTarget == BfAttributeTargets_Method))
|
||||
if ((mCurMethodInstance != NULL) && (targetOverride == BfAttributeTargets_ReturnValue) && (attrTarget == BfAttributeTargets_Method))
|
||||
{
|
||||
auto methodInfoEx = mCurMethodInstance->GetMethodInfoEx();
|
||||
|
||||
|
@ -11389,11 +11400,9 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri
|
|||
methodInfoEx->mMethodCustomAttributes->mReturnCustomAttributes->mAttributes.push_back(customAttribute);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Failed - ignore
|
||||
success = false;
|
||||
}
|
||||
|
||||
// Mark as failed since we don't actually want to add this to the custom attributes set
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (success)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue