mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 11:38:21 +02:00
Improved deferred type name generation
This commit is contained in:
parent
fc063a65c1
commit
aafefecfa2
5 changed files with 77 additions and 56 deletions
|
@ -2722,6 +2722,11 @@ void BfCompiler::UpdateRevisedTypes()
|
||||||
++typeDefItr;
|
++typeDefItr;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((!typeDef->IsGlobalsContainer()) && (mSystem->ContainsNamespace(typeDef->mFullName, typeDef->mProject)))
|
||||||
|
{
|
||||||
|
mPassInstance->Fail(StrFormat("The name '%s' is already defined to be a namespace name", typeDef->mFullName.ToString().c_str()), typeDef->mTypeDeclaration->mNameNode);
|
||||||
|
}
|
||||||
|
|
||||||
bool removedElement = false;
|
bool removedElement = false;
|
||||||
auto nextTypeDefItr = typeDefItr;
|
auto nextTypeDefItr = typeDefItr;
|
||||||
|
@ -7082,7 +7087,7 @@ String BfCompiler::GetTypeDefList()
|
||||||
result += "c";
|
result += "c";
|
||||||
else
|
else
|
||||||
result += "v";
|
result += "v";
|
||||||
result += BfTypeUtils::TypeToString(typeDef) + "\n";
|
result += BfTypeUtils::TypeToString(typeDef, BfTypeNameFlag_InternalName) + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7381,7 +7386,7 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr)
|
||||||
if (matchHelper.CheckMemberMatch(typeDef, fieldDef->mName))
|
if (matchHelper.CheckMemberMatch(typeDef, fieldDef->mName))
|
||||||
{
|
{
|
||||||
result += "F";
|
result += "F";
|
||||||
if (BfTypeUtils::TypeToString(result, typeDef, BfTypeNameFlag_HideGlobalName))
|
if (BfTypeUtils::TypeToString(result, typeDef, (BfTypeNameFlags)(BfTypeNameFlag_HideGlobalName | BfTypeNameFlag_InternalName)))
|
||||||
result += ".";
|
result += ".";
|
||||||
result += fieldDef->mName;
|
result += fieldDef->mName;
|
||||||
matchHelper.AddFieldDef(fieldDef);
|
matchHelper.AddFieldDef(fieldDef);
|
||||||
|
@ -7397,7 +7402,7 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr)
|
||||||
if (matchHelper.CheckMemberMatch(typeDef, propDef->mName))
|
if (matchHelper.CheckMemberMatch(typeDef, propDef->mName))
|
||||||
{
|
{
|
||||||
result += "P";
|
result += "P";
|
||||||
if (BfTypeUtils::TypeToString(result, typeDef, BfTypeNameFlag_HideGlobalName))
|
if (BfTypeUtils::TypeToString(result, typeDef, (BfTypeNameFlags)(BfTypeNameFlag_HideGlobalName | BfTypeNameFlag_InternalName)))
|
||||||
result += ".";
|
result += ".";
|
||||||
matchHelper.AddPropertyDef(typeDef, propDef);
|
matchHelper.AddPropertyDef(typeDef, propDef);
|
||||||
}
|
}
|
||||||
|
@ -7418,7 +7423,7 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr)
|
||||||
if (matchHelper.CheckMemberMatch(typeDef, methodDef->mName))
|
if (matchHelper.CheckMemberMatch(typeDef, methodDef->mName))
|
||||||
{
|
{
|
||||||
result += "M";
|
result += "M";
|
||||||
if (BfTypeUtils::TypeToString(result, typeDef, BfTypeNameFlag_HideGlobalName))
|
if (BfTypeUtils::TypeToString(result, typeDef, (BfTypeNameFlags)(BfTypeNameFlag_HideGlobalName | BfTypeNameFlag_InternalName)))
|
||||||
result += ".";
|
result += ".";
|
||||||
matchHelper.AddMethodDef(methodDef);
|
matchHelper.AddMethodDef(methodDef);
|
||||||
}
|
}
|
||||||
|
@ -7447,11 +7452,7 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr)
|
||||||
if (!matchHelper.MergeFlags(matchFlags))
|
if (!matchHelper.MergeFlags(matchFlags))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//foundComposite.Set(typeDef->mFullName.mParts, matchIdx + 1, NULL, 0);
|
|
||||||
|
|
||||||
//foundComposite = typeDef->mFullName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeDef->mProject != curProject)
|
if (typeDef->mProject != curProject)
|
||||||
|
@ -7471,9 +7472,9 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr)
|
||||||
sprintf(str, "=%d\n", *projectIdPtr);
|
sprintf(str, "=%d\n", *projectIdPtr);
|
||||||
result += str;
|
result += str;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typeName = BfTypeUtils::TypeToString(typeDef);
|
typeName = BfTypeUtils::TypeToString(typeDef, BfTypeNameFlag_InternalName);
|
||||||
|
|
||||||
if (matchIdx != -1)
|
if (matchIdx != -1)
|
||||||
{
|
{
|
||||||
|
@ -7505,7 +7506,7 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result += StrFormat("<%d@", *matchIdxPtr);
|
result += StrFormat("<%d@", *matchIdxPtr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -7587,6 +7588,10 @@ String BfCompiler::GetTypeDefInfo(const StringImpl& inTypeName)
|
||||||
typeName.RemoveToEnd(typeName.length() - 8);
|
typeName.RemoveToEnd(typeName.length() - 8);
|
||||||
isGlobals = true;
|
isGlobals = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < (int)typeName.length(); i++)
|
||||||
|
if (typeName[i] == '+')
|
||||||
|
typeName[i] = '.';
|
||||||
|
|
||||||
String result;
|
String result;
|
||||||
TypeDefMatchHelper matchHelper(result);
|
TypeDefMatchHelper matchHelper(result);
|
||||||
|
|
|
@ -6343,6 +6343,11 @@ BfAstNode* BfReducer::ReadTypeMember(BfAstNode* node, int depth)
|
||||||
doExplicitInterface = true; // Qualified property
|
doExplicitInterface = true; // Qualified property
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Experimental 'more permissive' explicit interface check
|
||||||
|
if (endNodeIdx != -1)
|
||||||
|
doExplicitInterface = true;
|
||||||
|
|
||||||
if (doExplicitInterface)
|
if (doExplicitInterface)
|
||||||
{
|
{
|
||||||
auto prevEndNode = mVisitorPos.Get(endNodeIdx - 1);
|
auto prevEndNode = mVisitorPos.Get(endNodeIdx - 1);
|
||||||
|
|
|
@ -408,20 +408,7 @@ BfFieldInstance::~BfFieldInstance()
|
||||||
|
|
||||||
BfType* BfFieldInstance::GetResolvedType()
|
BfType* BfFieldInstance::GetResolvedType()
|
||||||
{
|
{
|
||||||
return mResolvedType;
|
return mResolvedType;
|
||||||
/*if (mType == NULL)
|
|
||||||
return NULL;
|
|
||||||
if (!mType->IsGenericParam())
|
|
||||||
return mType;
|
|
||||||
if (!mOwner->IsGenericTypeInstance())
|
|
||||||
return mType;
|
|
||||||
auto genericParamType = (BfGenericParamType*)mType;
|
|
||||||
auto genericTypeInst = (BfGenericTypeInstance*)mOwner;
|
|
||||||
if (genericTypeInst->mIsUnspecialized)
|
|
||||||
return mType;
|
|
||||||
if (genericParamType->mGenericParamKind == BfGenericParamKind_Type)
|
|
||||||
return genericTypeInst->mTypeGenericArguments[genericParamType->mGenericParamIdx];
|
|
||||||
return mType;*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BfFieldInstance::SetResolvedType(BfType* type)
|
void BfFieldInstance::SetResolvedType(BfType* type)
|
||||||
|
@ -429,6 +416,36 @@ void BfFieldInstance::SetResolvedType(BfType* type)
|
||||||
mResolvedType = type;
|
mResolvedType = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
int64 BfDeferredMethodCallData::GenerateMethodId(BfModule* module, int64 methodId)
|
||||||
|
{
|
||||||
|
// The mMethodId MUST be unique within a given deferred method processor. We are even more conservative, making it
|
||||||
|
// unique per module
|
||||||
|
if (module->mDeferredMethodIds.Add(methodId))
|
||||||
|
{
|
||||||
|
return methodId;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Ideally the passed in methodId just works, otherwise --
|
||||||
|
// We hope to create a hash that will hopefully be globally unique. If it isn't then it just means we will end up with two
|
||||||
|
// conflicting debug info definitions for the same name, which is not an error but may cause a debugger to show the
|
||||||
|
// wrong one to the user. Does not affect runtime correctness.
|
||||||
|
int64 checkId = Hash64(module->mModuleName.c_str(), (int)module->mModuleName.length(), module->mDeferredMethodIds.size());
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
if (!module->mDeferredMethodIds.Contains(checkId))
|
||||||
|
break;
|
||||||
|
checkId += 0x100;
|
||||||
|
}
|
||||||
|
module->mDeferredMethodIds.Add(checkId);
|
||||||
|
return checkId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
BfMethodCustomAttributes::~BfMethodCustomAttributes()
|
BfMethodCustomAttributes::~BfMethodCustomAttributes()
|
||||||
{
|
{
|
||||||
delete mCustomAttributes;
|
delete mCustomAttributes;
|
||||||
|
@ -3720,13 +3737,16 @@ String BfTypeUtils::TypeToString(BfTypeDef* typeDef, BfTypeNameFlags typeNameFla
|
||||||
bool BfTypeUtils::TypeToString(StringImpl& str, BfTypeDef* typeDef, BfTypeNameFlags typeNameFlags)
|
bool BfTypeUtils::TypeToString(StringImpl& str, BfTypeDef* typeDef, BfTypeNameFlags typeNameFlags)
|
||||||
{
|
{
|
||||||
auto checkTypeDef = typeDef;
|
auto checkTypeDef = typeDef;
|
||||||
bool needsDot = false;
|
char needsSep = 0;
|
||||||
|
|
||||||
if (checkTypeDef->mOuterType != NULL)
|
if (checkTypeDef->mOuterType != NULL)
|
||||||
{
|
{
|
||||||
if (TypeToString(str, checkTypeDef->mOuterType, typeNameFlags))
|
if (TypeToString(str, checkTypeDef->mOuterType, typeNameFlags))
|
||||||
{
|
{
|
||||||
needsDot = true;
|
if ((typeNameFlags & BfTypeNameFlag_InternalName) != 0)
|
||||||
|
needsSep = '+';
|
||||||
|
else
|
||||||
|
needsSep = '.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -3734,16 +3754,17 @@ bool BfTypeUtils::TypeToString(StringImpl& str, BfTypeDef* typeDef, BfTypeNameFl
|
||||||
if (((typeNameFlags & BfTypeNameFlag_OmitNamespace) == 0) && (!typeDef->mNamespace.IsEmpty()))
|
if (((typeNameFlags & BfTypeNameFlag_OmitNamespace) == 0) && (!typeDef->mNamespace.IsEmpty()))
|
||||||
{
|
{
|
||||||
typeDef->mNamespace.ToString(str);
|
typeDef->mNamespace.ToString(str);
|
||||||
needsDot = true;
|
needsSep = '.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (needsSep != 0)
|
||||||
|
str += needsSep;
|
||||||
|
|
||||||
if (((typeNameFlags & BfTypeNameFlag_HideGlobalName) != 0) && (typeDef->IsGlobalsContainer()))
|
if (((typeNameFlags & BfTypeNameFlag_HideGlobalName) != 0) && (typeDef->IsGlobalsContainer()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (needsDot)
|
typeDef->mName->ToString(str);
|
||||||
str += ".";
|
|
||||||
typeDef->mName->ToString(str);
|
|
||||||
|
|
||||||
if (typeDef->mGenericParamDefs.size() != 0)
|
if (typeDef->mGenericParamDefs.size() != 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -576,6 +576,8 @@ public:
|
||||||
mSize = 0;
|
mSize = 0;
|
||||||
mMethodId = 0;
|
mMethodId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int64 GenerateMethodId(BfModule* module, int64 methodId);
|
||||||
};
|
};
|
||||||
|
|
||||||
class BfMethodCustomAttributes
|
class BfMethodCustomAttributes
|
||||||
|
|
|
@ -178,7 +178,14 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc
|
||||||
|
|
||||||
if (deferredCallEntry->mDeferredBlock != NULL)
|
if (deferredCallEntry->mDeferredBlock != NULL)
|
||||||
{
|
{
|
||||||
int blockId = -deferredCallEntry->mDeferredBlock->GetSrcStart();
|
HashContext hashCtx;
|
||||||
|
hashCtx.Mixin(deferredCallEntry->mDeferredBlock->GetSrcStart());
|
||||||
|
|
||||||
|
auto parserData = deferredCallEntry->mDeferredBlock->GetParserData();
|
||||||
|
if (parserData != NULL)
|
||||||
|
hashCtx.MixinStr(parserData->mFileName);
|
||||||
|
|
||||||
|
int64 blockId = BfDeferredMethodCallData::GenerateMethodId(this, hashCtx.Finish64());
|
||||||
|
|
||||||
auto deferType = deferredCallEntryType;
|
auto deferType = deferredCallEntryType;
|
||||||
|
|
||||||
|
@ -200,7 +207,7 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc
|
||||||
|
|
||||||
SizedArray<BfIRType, 4> llvmTypes;
|
SizedArray<BfIRType, 4> llvmTypes;
|
||||||
SizedArray<BfIRMDNode, 8> diFieldTypes;
|
SizedArray<BfIRMDNode, 8> diFieldTypes;
|
||||||
|
|
||||||
typeName = StrFormat("_BF_DeferredData_%s", BfTypeUtils::HashEncode64(blockId).c_str());
|
typeName = StrFormat("_BF_DeferredData_%s", BfTypeUtils::HashEncode64(blockId).c_str());
|
||||||
|
|
||||||
auto valueType = ResolveTypeDef(mCompiler->mValueTypeTypeDef);
|
auto valueType = ResolveTypeDef(mCompiler->mValueTypeTypeDef);
|
||||||
|
@ -286,27 +293,8 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc
|
||||||
{
|
{
|
||||||
deferredMethodCallData = new BfDeferredMethodCallData();
|
deferredMethodCallData = new BfDeferredMethodCallData();
|
||||||
mDeferredMethodCallData[methodInstance] = deferredMethodCallData;
|
mDeferredMethodCallData[methodInstance] = deferredMethodCallData;
|
||||||
|
deferredMethodCallData->mMethodId = BfDeferredMethodCallData::GenerateMethodId(this, methodInstance->mIdHash);
|
||||||
if (mDeferredMethodIds.Add(methodInstance->mIdHash))
|
|
||||||
{
|
|
||||||
deferredMethodCallData->mMethodId = methodInstance->mIdHash;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Try to create a hash that will hopefully be globally unique. If it isn't then it just means we will end up with two
|
|
||||||
// conflicting debug info definitions for the same name, which is not an error but may cause a debugger to show the
|
|
||||||
// wrong one to the user. Does not affect runtime correctness.
|
|
||||||
int64 checkId = Hash64(mModuleName.c_str(), (int)mModuleName.length(), mDeferredMethodIds.size());
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
if (!mDeferredMethodIds.Contains(checkId))
|
|
||||||
break;
|
|
||||||
checkId += 0x100;
|
|
||||||
}
|
|
||||||
mDeferredMethodIds.Add(checkId);
|
|
||||||
deferredMethodCallData->mMethodId = checkId;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto int64Type = GetPrimitiveType(BfTypeCode_Int64);
|
auto int64Type = GetPrimitiveType(BfTypeCode_Int64);
|
||||||
auto methodDef = moduleMethodInstance.mMethodInstance->mMethodDef;
|
auto methodDef = moduleMethodInstance.mMethodInstance->mMethodDef;
|
||||||
auto thisType = moduleMethodInstance.mMethodInstance->mMethodInstanceGroup->mOwner;
|
auto thisType = moduleMethodInstance.mMethodInstance->mMethodInstanceGroup->mOwner;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue