1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 04:22:20 +02:00

Fixed string literal issues with import

This commit is contained in:
Brian Fiete 2021-02-09 16:24:02 -08:00
parent e3803ed007
commit e6a918600b
2 changed files with 70 additions and 66 deletions

View file

@ -5970,11 +5970,6 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
BfType* reflectFieldDataType = ResolveTypeDef(mCompiler->mReflectFieldDataDef); BfType* reflectFieldDataType = ResolveTypeDef(mCompiler->mReflectFieldDataDef);
BfIRValue emptyValueType = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType->ToTypeInstance()->mBaseType), SizedArray<BfIRValue, 1>()); BfIRValue emptyValueType = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType->ToTypeInstance()->mBaseType), SizedArray<BfIRValue, 1>());
if (typeInstance->mTypeDef->mName->ToString() == "TestProgram")
{
NOP;
}
auto _HandleCustomAttrs = [&](BfCustomAttributes* customAttributes) auto _HandleCustomAttrs = [&](BfCustomAttributes* customAttributes)
{ {
if (customAttributes == NULL) if (customAttributes == NULL)
@ -11001,11 +10996,6 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri
continue; continue;
} }
if (mModuleName == "BeefTest_TestProgram")
{
NOP;
}
if ((mIsReified) && (attrTypeInst->mAttributeData != NULL) && ((attrTypeInst->mAttributeData->mFlags & BfAttributeFlag_ReflectAttribute) != 0)) if ((mIsReified) && (attrTypeInst->mAttributeData != NULL) && ((attrTypeInst->mAttributeData->mFlags & BfAttributeFlag_ReflectAttribute) != 0))
{ {
// Reify attribute // Reify attribute
@ -18377,6 +18367,35 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
BfLogSysM("ProcessMethod %p Unspecialized: %d Module: %p IRFunction: %d Reified: %d Incomplete:%d\n", methodInstance, mCurTypeInstance->IsUnspecializedType(), this, methodInstance->mIRFunction.mId, methodInstance->mIsReified, mIncompleteMethodCount); BfLogSysM("ProcessMethod %p Unspecialized: %d Module: %p IRFunction: %d Reified: %d Incomplete:%d\n", methodInstance, mCurTypeInstance->IsUnspecializedType(), this, methodInstance->mIRFunction.mId, methodInstance->mIsReified, mIncompleteMethodCount);
int importStrNum = -1;
auto importKind = methodInstance->GetImportKind();
if ((!mCompiler->mIsResolveOnly) &&
((importKind == BfImportKind_Import_Static) || (importKind == BfImportKind_Import_Dynamic)))
{
if (auto customAttr = methodInstance->GetCustomAttributes()->Get(mCompiler->mImportAttributeTypeDef))
{
if (customAttr->mCtorArgs.size() == 1)
{
auto fileNameArg = customAttr->mCtorArgs[0];
auto constant = mCurTypeInstance->mConstHolder->GetConstant(fileNameArg);
if (constant != NULL)
{
if (!constant->IsNull())
importStrNum = constant->mInt32;
}
else
{
importStrNum = GetStringPoolIdx(fileNameArg, mCurTypeInstance->mConstHolder);
}
if (importStrNum != -1)
{
if (!mStringPoolRefs.Contains(importStrNum))
mStringPoolRefs.Add(importStrNum);
}
}
}
}
if (methodInstance->GetImportCallKind() != BfImportCallKind_None) if (methodInstance->GetImportCallKind() != BfImportCallKind_None)
{ {
if (mBfIRBuilder->mIgnoreWrites) if (mBfIRBuilder->mIgnoreWrites)
@ -19558,34 +19577,19 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
} }
bool isDllImport = false; bool isDllImport = false;
if (methodInstance->GetImportKind() == BfImportKind_Import_Static) if ((importKind == BfImportKind_Import_Static) || (importKind == BfImportKind_Import_Dynamic))
{ {
for (auto customAttr : methodInstance->GetCustomAttributes()->mAttributes) if (importStrNum != -1)
{ {
if (customAttr.mType->mTypeDef->mFullName.ToString() == "System.ImportAttribute") if (importKind == BfImportKind_Import_Static)
{ {
if (customAttr.mCtorArgs.size() == 1) if (!mImportFileNames.Contains(importStrNum))
{ {
auto fileNameArg = customAttr.mCtorArgs[0]; mImportFileNames.Add(importStrNum);
int strNum = 0;
auto constant = mCurTypeInstance->mConstHolder->GetConstant(fileNameArg);
if (constant != NULL)
{
if (constant->IsNull())
continue; // Invalid
strNum = constant->mInt32;
}
else
{
strNum = GetStringPoolIdx(fileNameArg, mCurTypeInstance->mConstHolder);
}
if (!mImportFileNames.Contains(strNum))
mImportFileNames.Add(strNum);
}
} }
} }
//mImportFileNames }
} }
else if (methodInstance->GetImportKind() == BfImportKind_Import_Dynamic) else if (methodInstance->GetImportKind() == BfImportKind_Import_Dynamic)
{ {

View file

@ -239,6 +239,32 @@ namespace Tests
switch (methodIdx) switch (methodIdx)
{ {
case 0: case 0:
Test.Assert(methodInfo.Name == "__BfCtor");
Test.Assert(methodInfo.IsConstructor);
case 1:
Test.Assert(methodInfo.Name == "__BfStaticCtor");
Test.Assert(methodInfo.IsConstructor);
case 2:
Test.Assert(methodInfo.Name == "GetA");
var result = methodInfo.Invoke(ca, 123).Get();
Test.Assert(result.Get<int>() == 1123);
result.Dispose();
result = methodInfo.Invoke(ca2, 123).Get();
Test.Assert(result.Get<int>() == 2123);
result.Dispose();
result = methodInfo.Invoke(.Create(ca2), .Create(123)).Get();
Test.Assert(result.Get<int>() == 2123);
result.Dispose();
case 3:
Test.Assert(methodInfo.Name == "MemberMethodA");
var result = methodInfo.Invoke(ca, 100, (int32)20, 3.0f).Get();
Test.Assert(result.Get<float>() == 123);
result.Dispose();
result = methodInfo.Invoke(.Create(ca), .Create(100), .Create((int32)20), .Create(3.0f)).Get();
Test.Assert(result.Get<float>() == 123);
result.Dispose();
case 4:
StructA sa = .() { mA = 1, mB = 2 }; StructA sa = .() { mA = 1, mB = 2 };
Test.Assert(methodInfo.Name == "StaticMethodA"); Test.Assert(methodInfo.Name == "StaticMethodA");
@ -291,7 +317,7 @@ namespace Tests
let attrC = methodInfo.GetCustomAttribute<AttrCAttribute>().Get(); let attrC = methodInfo.GetCustomAttribute<AttrCAttribute>().Get();
Test.Assert(attrC.mA == 71); Test.Assert(attrC.mA == 71);
Test.Assert(attrC.mB == 72); Test.Assert(attrC.mB == 72);
case 1: case 5:
Test.Assert(methodInfo.Name == "StaticMethodB"); Test.Assert(methodInfo.Name == "StaticMethodB");
var fieldA = typeInfo.GetField("mA").Value; var fieldA = typeInfo.GetField("mA").Value;
@ -337,33 +363,6 @@ namespace Tests
res.Dispose(); res.Dispose();
fieldSAV.Dispose(); fieldSAV.Dispose();
fieldSStrV.Dispose(); fieldSStrV.Dispose();
case 2:
Test.Assert(methodInfo.Name == "MemberMethodA");
var result = methodInfo.Invoke(ca, 100, (int32)20, 3.0f).Get();
Test.Assert(result.Get<float>() == 123);
result.Dispose();
result = methodInfo.Invoke(.Create(ca), .Create(100), .Create((int32)20), .Create(3.0f)).Get();
Test.Assert(result.Get<float>() == 123);
result.Dispose();
case 3:
Test.Assert(methodInfo.Name == "GetA");
var result = methodInfo.Invoke(ca, 123).Get();
Test.Assert(result.Get<int>() == 1123);
result.Dispose();
result = methodInfo.Invoke(ca2, 123).Get();
Test.Assert(result.Get<int>() == 2123);
result.Dispose();
result = methodInfo.Invoke(.Create(ca2), .Create(123)).Get();
Test.Assert(result.Get<int>() == 2123);
result.Dispose();
case 4:
Test.Assert(methodInfo.Name == "__BfStaticCtor");
Test.Assert(methodInfo.IsConstructor);
case 5:
Test.Assert(methodInfo.Name == "__BfCtor");
Test.Assert(methodInfo.IsConstructor);
case 6: case 6:
Test.FatalError(); // Shouldn't have any more Test.FatalError(); // Shouldn't have any more
} }
@ -445,6 +444,8 @@ namespace Tests
switch (methodIdx) switch (methodIdx)
{ {
case 0: case 0:
Test.Assert(methodInfo.Name == "__BfCtor");
case 1:
Test.Assert(methodInfo.Name == "GetA"); Test.Assert(methodInfo.Name == "GetA");
var result = methodInfo.Invoke(sa, 34).Get(); var result = methodInfo.Invoke(sa, 34).Get();
@ -464,7 +465,7 @@ namespace Tests
result = methodInfo.Invoke(.Create(&sa), .Create(34)); result = methodInfo.Invoke(.Create(&sa), .Create(34));
Test.Assert(result.Get<int32>() == 1234); Test.Assert(result.Get<int32>() == 1234);
result.Dispose(); result.Dispose();
case 1: case 2:
Test.Assert(methodInfo.Name == "GetB"); Test.Assert(methodInfo.Name == "GetB");
var result = methodInfo.Invoke(sa, 34).Get(); var result = methodInfo.Invoke(sa, 34).Get();
@ -489,16 +490,15 @@ namespace Tests
Test.Assert(sa.mB == 91); Test.Assert(sa.mB == 91);
result.Dispose(); result.Dispose();
case 2:
Test.Assert(methodInfo.Name == "MethodA0");
case 3: case 3:
Test.Assert(methodInfo.Name == "MethodA1"); Test.Assert(methodInfo.Name == "MethodA0");
case 4: case 4:
Test.Assert(methodInfo.Name == "__BfCtor"); Test.Assert(methodInfo.Name == "MethodA1");
case 5: case 5:
Test.Assert(methodInfo.Name == "__Equals"); Test.Assert(methodInfo.Name == "__Equals");
case 6: case 6:
Test.Assert(methodInfo.Name == "__StrictEquals"); Test.Assert(methodInfo.Name == "__StrictEquals");
default: default:
Test.FatalError(); // Shouldn't have any more Test.FatalError(); // Shouldn't have any more
} }