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

Start of anonymous 'using' field

This commit is contained in:
Brian Fiete 2022-02-19 07:38:05 -05:00
parent b886f3d3c3
commit 79e2ff5165
13 changed files with 859 additions and 498 deletions

View file

@ -992,7 +992,7 @@ public:
SizedArray(SizedArray&& val) SizedArray(SizedArray&& val)
{ {
if (val.mVals == val.mInternalBuffer) if (val.mVals == (T*)&val.mFirstVal)
{ {
this->mVals = (T*)&this->mFirstVal; this->mVals = (T*)&this->mFirstVal;
this->mSize = 0; this->mSize = 0;

View file

@ -161,6 +161,11 @@ void BfStructuralVisitor::Visit(BfTokenPairNode* tokenPairNode)
Visit(tokenPairNode->ToBase()); Visit(tokenPairNode->ToBase());
} }
void BfStructuralVisitor::Visit(BfUsingSpecifierNode* usingSpecifier)
{
Visit(usingSpecifier->ToBase());
}
void BfStructuralVisitor::Visit(BfLiteralExpression* literalExpr) void BfStructuralVisitor::Visit(BfLiteralExpression* literalExpr)
{ {
Visit(literalExpr->ToBase()); Visit(literalExpr->ToBase());

View file

@ -41,6 +41,7 @@ class BfSource;
class BfAstNode; class BfAstNode;
class BfTokenNode; class BfTokenNode;
class BfTokenPairNode; class BfTokenPairNode;
class BfUsingSpecifierNode;
class BfTypeReference; class BfTypeReference;
class BfTypeDef; class BfTypeDef;
class BfMethodDef; class BfMethodDef;
@ -457,6 +458,7 @@ public:
virtual void Visit(BfEmptyStatement* emptyStmt); virtual void Visit(BfEmptyStatement* emptyStmt);
virtual void Visit(BfTokenNode* tokenNode); virtual void Visit(BfTokenNode* tokenNode);
virtual void Visit(BfTokenPairNode* tokenPairNode); virtual void Visit(BfTokenPairNode* tokenPairNode);
virtual void Visit(BfUsingSpecifierNode* usingSpecifier);
virtual void Visit(BfLiteralExpression* literalExpr); virtual void Visit(BfLiteralExpression* literalExpr);
virtual void Visit(BfStringInterpolationExpression* stringInterpolationExpression); virtual void Visit(BfStringInterpolationExpression* stringInterpolationExpression);
virtual void Visit(BfIdentifierNode* identifierNode); virtual void Visit(BfIdentifierNode* identifierNode);
@ -3076,6 +3078,15 @@ public:
BfFieldDtorDeclaration* mNextFieldDtor; BfFieldDtorDeclaration* mNextFieldDtor;
}; BF_AST_DECL(BfFieldDtorDeclaration, BfAstNode); }; BF_AST_DECL(BfFieldDtorDeclaration, BfAstNode);
class BfUsingSpecifierNode : public BfAstNode
{
public:
BF_AST_TYPE(BfUsingSpecifierNode, BfAstNode);
BfAstNode* mProtection;
BfTokenNode* mUsingToken;
}; BF_AST_DECL(BfUsingSpecifierNode, BfAstNode);
class BfFieldDeclaration : public BfMemberDeclaration class BfFieldDeclaration : public BfMemberDeclaration
{ {
public: public:
@ -3083,7 +3094,7 @@ public:
BfCommentNode* mDocumentation; BfCommentNode* mDocumentation;
BfTokenNode* mPrecedingComma; BfTokenNode* mPrecedingComma;
BfTokenNode* mConstSpecifier; BfAstNode* mConstSpecifier; // Could be 'const' or 'using'
BfTokenNode* mVolatileSpecifier; BfTokenNode* mVolatileSpecifier;
BfTokenNode* mNewSpecifier; BfTokenNode* mNewSpecifier;
BfTokenNode* mExternSpecifier; BfTokenNode* mExternSpecifier;

View file

@ -907,7 +907,7 @@ void BfDefBuilder::Visit(BfPropertyDeclaration* propertyDeclaration)
wantsBody = false; wantsBody = false;
} }
if (propertyDeclaration->mConstSpecifier != NULL) if ((propertyDeclaration->mConstSpecifier != NULL) && (propertyDeclaration->mConstSpecifier->mToken == BfToken_Const))
{ {
Fail("Const properties are not allowed", propertyDeclaration->mConstSpecifier); Fail("Const properties are not allowed", propertyDeclaration->mConstSpecifier);
} }
@ -920,6 +920,14 @@ void BfDefBuilder::Visit(BfPropertyDeclaration* propertyDeclaration)
propertyDef->mProtection = GetProtection(propertyDeclaration->mProtectionSpecifier); propertyDef->mProtection = GetProtection(propertyDeclaration->mProtectionSpecifier);
propertyDef->mIdx = (int)mCurTypeDef->mProperties.size() - 1; propertyDef->mIdx = (int)mCurTypeDef->mProperties.size() - 1;
propertyDef->mIsConst = false; propertyDef->mIsConst = false;
propertyDef->mIsProperty = true;
if (auto usingSpecifier = BfNodeDynCast<BfUsingSpecifierNode>(propertyDeclaration->mConstSpecifier))
{
if (usingSpecifier->mProtection != NULL)
propertyDef->mUsingProtection = GetProtection(usingSpecifier->mProtection);
else
propertyDef->mUsingProtection = propertyDef->mProtection;
}
propertyDef->mIsStatic = propertyDeclaration->mStaticSpecifier != NULL; propertyDef->mIsStatic = propertyDeclaration->mStaticSpecifier != NULL;
propertyDef->mIsReadOnly = propertyDeclaration->mReadOnlySpecifier != NULL; propertyDef->mIsReadOnly = propertyDeclaration->mReadOnlySpecifier != NULL;
if (propertyDeclaration->mNameNode != NULL) if (propertyDeclaration->mNameNode != NULL)
@ -1149,13 +1157,25 @@ void BfDefBuilder::Visit(BfFieldDeclaration* fieldDeclaration)
fieldDef->mIsReadOnly = fieldDeclaration->mReadOnlySpecifier != NULL; fieldDef->mIsReadOnly = fieldDeclaration->mReadOnlySpecifier != NULL;
fieldDef->mIsInline = (fieldDeclaration->mReadOnlySpecifier != NULL) && (fieldDeclaration->mReadOnlySpecifier->GetToken() == BfToken_Inline); fieldDef->mIsInline = (fieldDeclaration->mReadOnlySpecifier != NULL) && (fieldDeclaration->mReadOnlySpecifier->GetToken() == BfToken_Inline);
fieldDef->mIsExtern = (fieldDeclaration->mExternSpecifier != NULL); fieldDef->mIsExtern = (fieldDeclaration->mExternSpecifier != NULL);
fieldDef->mIsConst = (fieldDeclaration->mConstSpecifier != NULL) || (isEnumEntryDecl); auto constSpecifierToken = BfNodeDynCast<BfTokenNode>(fieldDeclaration->mConstSpecifier);
fieldDef->mIsConst = ((constSpecifierToken != NULL) && (constSpecifierToken->mToken == BfToken_Const)) || (isEnumEntryDecl);
if (auto usingSpecifier = BfNodeDynCast<BfUsingSpecifierNode>(fieldDeclaration->mConstSpecifier))
{
if (usingSpecifier->mProtection != NULL)
fieldDef->mUsingProtection = GetProtection(usingSpecifier->mProtection);
else
fieldDef->mUsingProtection = fieldDef->mProtection;
}
fieldDef->mIsStatic = (fieldDeclaration->mStaticSpecifier != NULL) || fieldDef->mIsConst; fieldDef->mIsStatic = (fieldDeclaration->mStaticSpecifier != NULL) || fieldDef->mIsConst;
fieldDef->mIsVolatile = (fieldDeclaration->mVolatileSpecifier != NULL); fieldDef->mIsVolatile = (fieldDeclaration->mVolatileSpecifier != NULL);
fieldDef->mTypeRef = fieldDeclaration->mTypeRef; fieldDef->mTypeRef = fieldDeclaration->mTypeRef;
if (auto varType = BfNodeDynCast<BfLetTypeReference>(fieldDef->mTypeRef)) if (auto varType = BfNodeDynCast<BfLetTypeReference>(fieldDef->mTypeRef))
fieldDef->mIsReadOnly = true; fieldDef->mIsReadOnly = true;
if (fieldDef->mUsingProtection != BfProtection_Hidden)
mCurTypeDef->mHasUsingFields = true;
if ((mCurTypeDef->mTypeCode == BfTypeCode_Enum) && (fieldDef->mTypeRef != NULL) && (!fieldDef->mIsStatic)) if ((mCurTypeDef->mTypeCode == BfTypeCode_Enum) && (fieldDef->mTypeRef != NULL) && (!fieldDef->mIsStatic))
{ {
// This check is a bit of a hack to determine the difference between a "MemberType mMember" and a proper case entry of "mMember(TupleType)" // This check is a bit of a hack to determine the difference between a "MemberType mMember" and a proper case entry of "mMember(TupleType)"

View file

@ -203,6 +203,14 @@ void BfElementVisitor::Visit(BfTokenPairNode* tokenPairNode)
VisitChild(tokenPairNode->mRight); VisitChild(tokenPairNode->mRight);
} }
void BfElementVisitor::Visit(BfUsingSpecifierNode* usingSpecifier)
{
Visit(usingSpecifier->ToBase());
VisitChild(usingSpecifier->mProtection);
VisitChild(usingSpecifier->mUsingToken);
}
void BfElementVisitor::Visit(BfLiteralExpression* literalExpr) void BfElementVisitor::Visit(BfLiteralExpression* literalExpr)
{ {
Visit(literalExpr->ToBase()); Visit(literalExpr->ToBase());

View file

@ -36,6 +36,7 @@ public:
virtual void Visit(BfEmptyStatement* emptyStmt); virtual void Visit(BfEmptyStatement* emptyStmt);
virtual void Visit(BfTokenNode* tokenNode); virtual void Visit(BfTokenNode* tokenNode);
virtual void Visit(BfTokenPairNode* tokenPairNode); virtual void Visit(BfTokenPairNode* tokenPairNode);
virtual void Visit(BfUsingSpecifierNode* usingSpecifier);
virtual void Visit(BfLiteralExpression* literalExpr); virtual void Visit(BfLiteralExpression* literalExpr);
virtual void Visit(BfStringInterpolationExpression* stringInterpolationExpression); virtual void Visit(BfStringInterpolationExpression* stringInterpolationExpression);
virtual void Visit(BfIdentifierNode* identifierNode); virtual void Visit(BfIdentifierNode* identifierNode);

File diff suppressed because it is too large Load diff

View file

@ -362,7 +362,9 @@ enum BfLookupFieldFlags
BfLookupFieldFlag_BaseLookup = 2, BfLookupFieldFlag_BaseLookup = 2,
BfLookupFieldFlag_CheckingOuter = 4, BfLookupFieldFlag_CheckingOuter = 4,
BfLookupFieldFlag_IgnoreProtection = 8, BfLookupFieldFlag_IgnoreProtection = 8,
BfLookupFieldFlag_BindOnly = 0x10 BfLookupFieldFlag_BindOnly = 0x10,
BfLookupFieldFlag_IsFailurePass = 0x20,
BfLookupFieldFlag_IsAnonymous = 0x40
}; };
enum BfUnaryOpFlags enum BfUnaryOpFlags
@ -449,6 +451,8 @@ public:
bool CheckIsBase(BfAstNode* checkNode); bool CheckIsBase(BfAstNode* checkNode);
bool CheckModifyResult(BfTypedValue typeValue, BfAstNode* refNode, const char* modifyType, bool onlyNeedsMut = false, bool emitWarning = false, bool skipCopyOnMutate = false); bool CheckModifyResult(BfTypedValue typeValue, BfAstNode* refNode, const char* modifyType, bool onlyNeedsMut = false, bool emitWarning = false, bool skipCopyOnMutate = false);
bool CheckGenericCtor(BfGenericParamType* genericParamType, BfResolvedArgs& argValues, BfAstNode* targetSrc); bool CheckGenericCtor(BfGenericParamType* genericParamType, BfResolvedArgs& argValues, BfAstNode* targetSrc);
BfTypedValue LoadProperty(BfAstNode* targetSrc, BfTypedValue target, BfTypeInstance* typeInstance, BfPropertyDef* prop, BfLookupFieldFlags flags, BfCheckedKind checkedKind, bool isInline);
BfTypedValue LoadField(BfAstNode* targetSrc, BfTypedValue target, BfTypeInstance* typeInstance, BfFieldDef* fieldDef, BfLookupFieldFlags flags);
BfTypedValue LookupField(BfAstNode* targetSrc, BfTypedValue target, const StringImpl& fieldName, BfLookupFieldFlags flags = BfLookupFieldFlag_None); BfTypedValue LookupField(BfAstNode* targetSrc, BfTypedValue target, const StringImpl& fieldName, BfLookupFieldFlags flags = BfLookupFieldFlag_None);
void CheckObjectCreateTypeRef(BfType* expectingType, BfAstNode* afterNode); void CheckObjectCreateTypeRef(BfType* expectingType, BfAstNode* afterNode);
void LookupQualifiedName(BfQualifiedNameNode* nameNode, bool ignoreInitialError = false, bool* hadError = NULL); void LookupQualifiedName(BfQualifiedNameNode* nameNode, bool ignoreInitialError = false, bool* hadError = NULL);

View file

@ -4657,7 +4657,10 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
{ {
auto resolvedFieldType = fieldInstance->GetResolvedType(); auto resolvedFieldType = fieldInstance->GetResolvedType();
if ((!typeInstance->IsBoxed()) && (fieldDef != NULL)) if ((!typeInstance->IsBoxed()) && (fieldDef != NULL))
{ {
if ((fieldDef->mUsingProtection != BfProtection_Hidden) && (!resolvedFieldType->IsStruct()) && (!resolvedFieldType->IsObject()))
Warn(0, StrFormat("Field type '%s' is not applicable for 'using'", TypeToString(resolvedFieldType).c_str()), fieldDef->mFieldDeclaration->mConstSpecifier);
if (fieldInstance->mIsEnumPayloadCase) if (fieldInstance->mIsEnumPayloadCase)
{ {
PopulateType(resolvedFieldType, BfPopulateType_Data); PopulateType(resolvedFieldType, BfPopulateType_Data);
@ -4911,7 +4914,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
fieldInstance->mDataIdx = curFieldDataIdx++; fieldInstance->mDataIdx = curFieldDataIdx++;
typeInstance->mInstAlign = std::max(typeInstance->mInstAlign, alignSize); typeInstance->mInstAlign = std::max(typeInstance->mInstAlign, alignSize);
dataPos += dataSize; dataPos += dataSize;
} }
if (unionInnerType != NULL) if (unionInnerType != NULL)

View file

@ -6287,6 +6287,7 @@ BfAstNode* BfReducer::ReadTypeMember(BfTokenNode* tokenNode, bool declStarted, i
case BfToken_Explicit: case BfToken_Explicit:
case BfToken_ReadOnly: case BfToken_ReadOnly:
case BfToken_Inline: case BfToken_Inline:
case BfToken_Using:
case BfToken_Volatile: case BfToken_Volatile:
break; break;
default: default:
@ -6335,7 +6336,7 @@ BfAstNode* BfReducer::ReadTypeMember(BfTokenNode* tokenNode, bool declStarted, i
auto fieldDecl = BfNodeDynCast<BfFieldDeclaration>(memberDecl); auto fieldDecl = BfNodeDynCast<BfFieldDeclaration>(memberDecl);
if (fieldDecl != NULL) if (fieldDecl != NULL)
{ {
if ((fieldDecl->mStaticSpecifier != NULL) && (fieldDecl->mConstSpecifier != NULL)) if ((fieldDecl->mStaticSpecifier != NULL) && (fieldDecl->mConstSpecifier != NULL) && (fieldDecl->mConstSpecifier->mToken == BfToken_Const))
Fail("Cannot use 'static' and 'const' together", fieldDecl); Fail("Cannot use 'static' and 'const' together", fieldDecl);
} }
@ -6347,6 +6348,15 @@ BfAstNode* BfReducer::ReadTypeMember(BfTokenNode* tokenNode, bool declStarted, i
(token == BfToken_Private) || (token == BfToken_Private) ||
(token == BfToken_Internal)) (token == BfToken_Internal))
{ {
if (auto fieldDecl = BfNodeDynCast<BfFieldDeclaration>(memberDecl))
{
if (auto usingSpecifier = BfNodeDynCastExact<BfUsingSpecifierNode>(fieldDecl->mConstSpecifier))
{
SetProtection(memberDecl, usingSpecifier->mProtection, tokenNode);
return memberDecl;
}
}
SetProtection(memberDecl, memberDecl->mProtectionSpecifier, tokenNode); SetProtection(memberDecl, memberDecl->mProtectionSpecifier, tokenNode);
return memberDecl; return memberDecl;
} }
@ -6463,10 +6473,36 @@ BfAstNode* BfReducer::ReadTypeMember(BfTokenNode* tokenNode, bool declStarted, i
if (token == BfToken_Const) if (token == BfToken_Const)
{ {
if ((fieldDecl->mConstSpecifier != NULL) && (fieldDecl->mConstSpecifier->mToken == BfToken_Using))
{
Fail("Const cannot be used with 'using' specified", tokenNode);
}
else if (fieldDecl->mConstSpecifier != NULL)
{
Fail("Const already specified", tokenNode);
}
MEMBER_SET(fieldDecl, mConstSpecifier, tokenNode); MEMBER_SET(fieldDecl, mConstSpecifier, tokenNode);
handled = true; handled = true;
} }
// if (token == BfToken_Using)
// {
// if ((fieldDecl->mConstSpecifier != NULL) && (fieldDecl->mConstSpecifier->mToken == BfToken_Const))
// {
// Fail("Const cannot be used with 'using' specified", tokenNode);
// }
// else if (fieldDecl->mConstSpecifier != NULL)
// {
// Fail("Using already specified", tokenNode);
// }
//
// auto usingSpecifier = mAlloc->Alloc<BfUsingSpecifierNode>();
// ReplaceNode(tokenNode, usingSpecifier);
// MEMBER_SET(usingSpecifier, mUsingToken, tokenNode);
// MEMBER_SET(fieldDecl, mConstSpecifier, usingSpecifier);
// handled = true;
// }
if (token == BfToken_ReadOnly) if (token == BfToken_ReadOnly)
{ {
if (fieldDecl->mReadOnlySpecifier == NULL) if (fieldDecl->mReadOnlySpecifier == NULL)
@ -6504,13 +6540,13 @@ BfAstNode* BfReducer::ReadTypeMember(BfTokenNode* tokenNode, bool declStarted, i
handled = true; handled = true;
} }
if ((fieldDecl->mStaticSpecifier != NULL) && (fieldDecl->mConstSpecifier != NULL)) if ((fieldDecl->mStaticSpecifier != NULL) && (fieldDecl->mConstSpecifier != NULL) && (fieldDecl->mConstSpecifier->mToken == BfToken_Const))
Fail("Cannot use 'static' and 'const' together", fieldDecl); Fail("Cannot use 'static' and 'const' together", fieldDecl);
if ((fieldDecl->mReadOnlySpecifier != NULL) && (fieldDecl->mConstSpecifier != NULL)) if ((fieldDecl->mReadOnlySpecifier != NULL) && (fieldDecl->mConstSpecifier != NULL) && (fieldDecl->mConstSpecifier->mToken == BfToken_Const))
Fail("Cannot use 'readonly' and 'const' together", fieldDecl); Fail("Cannot use 'readonly' and 'const' together", fieldDecl);
if ((fieldDecl->mVolatileSpecifier != NULL) && (fieldDecl->mConstSpecifier != NULL)) if ((fieldDecl->mVolatileSpecifier != NULL) && (fieldDecl->mConstSpecifier != NULL) && (fieldDecl->mConstSpecifier->mToken == BfToken_Const))
Fail("Cannot use 'volatile' and 'const' together", fieldDecl); Fail("Cannot use 'volatile' and 'const' together", fieldDecl);
if (handled) if (handled)

View file

@ -3145,7 +3145,7 @@ void BfResolvedTypeSet::HashGenericArguments(BfTypeReference* typeRef, LookupCon
if (auto genericTypeRef = BfNodeDynCast<BfGenericInstanceTypeRef>(typeRef)) if (auto genericTypeRef = BfNodeDynCast<BfGenericInstanceTypeRef>(typeRef))
{ {
for (auto genericArg : genericTypeRef->mGenericArguments) for (auto genericArg : genericTypeRef->mGenericArguments)
hashVal = HASH_MIX(hashVal, Hash(genericArg, ctx, BfHashFlag_AllowGenericParamConstValue, hashSeed + 1)); hashVal = HASH_MIX(hashVal, Hash(genericArg, ctx, BfHashFlag_AllowGenericParamConstValue, hashSeed + 1));
} }
} }

View file

@ -730,7 +730,7 @@ void BfTypeDef::PopulateMemberSets()
{ {
methodDef->mNextWithSameName = (BfMethodDef*)entry->mMemberDef; methodDef->mNextWithSameName = (BfMethodDef*)entry->mMemberDef;
entry->mMemberDef = methodDef; entry->mMemberDef = methodDef;
} }
} }
while (mFieldSet.mSourceSize < mFields.mSize) while (mFieldSet.mSourceSize < mFields.mSize)
@ -744,6 +744,13 @@ void BfTypeDef::PopulateMemberSets()
fieldDef->mNextWithSameName = (BfFieldDef*)entry->mMemberDef; fieldDef->mNextWithSameName = (BfFieldDef*)entry->mMemberDef;
entry->mMemberDef = fieldDef; entry->mMemberDef = fieldDef;
} }
if (fieldDef->mUsingProtection != BfProtection_Hidden)
{
if (mUsingFieldData == NULL)
mUsingFieldData = new BfUsingFieldData();
mUsingFieldData->mUsingFields.Add(fieldDef);
}
} }
while (mPropertySet.mSourceSize < mProperties.mSize) while (mPropertySet.mSourceSize < mProperties.mSize)
@ -757,6 +764,13 @@ void BfTypeDef::PopulateMemberSets()
propDef->mNextWithSameName = (BfPropertyDef*)entry->mMemberDef; propDef->mNextWithSameName = (BfPropertyDef*)entry->mMemberDef;
entry->mMemberDef = propDef; entry->mMemberDef = propDef;
} }
if (propDef->mUsingProtection != BfProtection_Hidden)
{
if (mUsingFieldData == NULL)
mUsingFieldData = new BfUsingFieldData();
mUsingFieldData->mUsingFields.Add(propDef);
}
} }
} }
@ -769,6 +783,8 @@ void BfTypeDef::ClearMemberSets()
for (auto entry : mFieldSet) for (auto entry : mFieldSet)
((BfFieldDef*)entry.mMemberDef)->mNextWithSameName = NULL; ((BfFieldDef*)entry.mMemberDef)->mNextWithSameName = NULL;
mFieldSet.Clear(); mFieldSet.Clear();
delete mUsingFieldData;
mUsingFieldData = NULL;
for (auto entry : mPropertySet) for (auto entry : mPropertySet)
((BfPropertyDef*)entry.mMemberDef)->mNextWithSameName = NULL; ((BfPropertyDef*)entry.mMemberDef)->mNextWithSameName = NULL;
@ -787,6 +803,7 @@ BfTypeDef::~BfTypeDef()
mSource->mRefCount--; mSource->mRefCount--;
BF_ASSERT(mSource->mRefCount >= 0); BF_ASSERT(mSource->mRefCount >= 0);
} }
delete mUsingFieldData;
} }
BfSource* BfTypeDef::GetLastSource() BfSource* BfTypeDef::GetLastSource()
@ -2899,6 +2916,7 @@ void BfSystem::InjectNewRevision(BfTypeDef* typeDef)
typeDef->mHasCtorNoBody = nextTypeDef->mHasCtorNoBody; typeDef->mHasCtorNoBody = nextTypeDef->mHasCtorNoBody;
typeDef->mHasOverrideMethods = nextTypeDef->mHasOverrideMethods; typeDef->mHasOverrideMethods = nextTypeDef->mHasOverrideMethods;
typeDef->mHasExtensionMethods = nextTypeDef->mHasExtensionMethods; typeDef->mHasExtensionMethods = nextTypeDef->mHasExtensionMethods;
typeDef->mHasUsingFields = nextTypeDef->mHasUsingFields;
typeDef->mIsOpaque = nextTypeDef->mIsOpaque; typeDef->mIsOpaque = nextTypeDef->mIsOpaque;
typeDef->mDupDetectedRevision = nextTypeDef->mDupDetectedRevision; typeDef->mDupDetectedRevision = nextTypeDef->mDupDetectedRevision;
@ -2950,6 +2968,8 @@ void BfSystem::InjectNewRevision(BfTypeDef* typeDef)
typeDef->mPartials = nextTypeDef->mPartials; typeDef->mPartials = nextTypeDef->mPartials;
typeDef->mMethodSet.Clear(); typeDef->mMethodSet.Clear();
typeDef->mFieldSet.Clear(); typeDef->mFieldSet.Clear();
delete typeDef->mUsingFieldData;
typeDef->mUsingFieldData = NULL;
typeDef->mPropertySet.Clear(); typeDef->mPropertySet.Clear();
delete nextTypeDef; delete nextTypeDef;
@ -3003,6 +3023,7 @@ void BfSystem::AddToCompositePartial(BfPassInstance* passInstance, BfTypeDef* co
typeDef->mHasAppendCtor = partialTypeDef->mHasAppendCtor; typeDef->mHasAppendCtor = partialTypeDef->mHasAppendCtor;
typeDef->mHasCtorNoBody = partialTypeDef->mHasCtorNoBody; typeDef->mHasCtorNoBody = partialTypeDef->mHasCtorNoBody;
typeDef->mHasExtensionMethods = partialTypeDef->mHasExtensionMethods; typeDef->mHasExtensionMethods = partialTypeDef->mHasExtensionMethods;
typeDef->mHasUsingFields = partialTypeDef->mHasUsingFields;
typeDef->mHasOverrideMethods = partialTypeDef->mHasOverrideMethods; typeDef->mHasOverrideMethods = partialTypeDef->mHasOverrideMethods;
typeDef->mIsAlwaysInclude = partialTypeDef->mIsAlwaysInclude; typeDef->mIsAlwaysInclude = partialTypeDef->mIsAlwaysInclude;
typeDef->mHasCEOnCompile = partialTypeDef->mHasCEOnCompile; typeDef->mHasCEOnCompile = partialTypeDef->mHasCEOnCompile;
@ -3042,6 +3063,7 @@ void BfSystem::AddToCompositePartial(BfPassInstance* passInstance, BfTypeDef* co
typeDef->mHasAppendCtor |= partialTypeDef->mHasAppendCtor; typeDef->mHasAppendCtor |= partialTypeDef->mHasAppendCtor;
typeDef->mHasCEOnCompile |= partialTypeDef->mHasCEOnCompile; typeDef->mHasCEOnCompile |= partialTypeDef->mHasCEOnCompile;
typeDef->mHasExtensionMethods |= partialTypeDef->mHasExtensionMethods; typeDef->mHasExtensionMethods |= partialTypeDef->mHasExtensionMethods;
typeDef->mHasUsingFields |= partialTypeDef->mHasUsingFields;
typeDef->mHasOverrideMethods |= partialTypeDef->mHasOverrideMethods; typeDef->mHasOverrideMethods |= partialTypeDef->mHasOverrideMethods;
typeDef->mProtection = BF_MIN(typeDef->mProtection, partialTypeDef->mProtection); typeDef->mProtection = BF_MIN(typeDef->mProtection, partialTypeDef->mProtection);
@ -3062,6 +3084,8 @@ void BfSystem::AddToCompositePartial(BfPassInstance* passInstance, BfTypeDef* co
typeDef->mFields.push_back(newField); typeDef->mFields.push_back(newField);
} }
typeDef->mFieldSet.Clear(); typeDef->mFieldSet.Clear();
delete typeDef->mUsingFieldData;
typeDef->mUsingFieldData = NULL;
bool hadNoDeclMethod = false; bool hadNoDeclMethod = false;
int startMethodIdx = (int)typeDef->mMethods.size(); int startMethodIdx = (int)typeDef->mMethods.size();
@ -3413,6 +3437,7 @@ void BfSystem::CopyTypeDef(BfTypeDef* typeDef, BfTypeDef* fromTypeDef)
typeDef->mHasCtorNoBody = fromTypeDef->mHasCtorNoBody; typeDef->mHasCtorNoBody = fromTypeDef->mHasCtorNoBody;
typeDef->mHasOverrideMethods = fromTypeDef->mHasOverrideMethods; typeDef->mHasOverrideMethods = fromTypeDef->mHasOverrideMethods;
typeDef->mHasExtensionMethods = fromTypeDef->mHasExtensionMethods; typeDef->mHasExtensionMethods = fromTypeDef->mHasExtensionMethods;
typeDef->mHasUsingFields = fromTypeDef->mHasUsingFields;
typeDef->mIsOpaque = fromTypeDef->mIsOpaque; typeDef->mIsOpaque = fromTypeDef->mIsOpaque;
typeDef->mDupDetectedRevision = fromTypeDef->mDupDetectedRevision; typeDef->mDupDetectedRevision = fromTypeDef->mDupDetectedRevision;

View file

@ -564,9 +564,11 @@ class BfFieldDef : public BfMemberDef
public: public:
int mIdx; int mIdx;
bool mIsConst; // Note: Consts are also all considered Static bool mIsConst; // Note: Consts are also all considered Static
BfProtection mUsingProtection;
bool mIsInline; bool mIsInline;
bool mIsVolatile; bool mIsVolatile;
bool mIsExtern; bool mIsExtern;
bool mIsProperty;
BfTypeReference* mTypeRef; BfTypeReference* mTypeRef;
BfExpression* mInitializer; BfExpression* mInitializer;
BfFieldDeclaration* mFieldDeclaration; BfFieldDeclaration* mFieldDeclaration;
@ -579,9 +581,11 @@ public:
{ {
mIdx = 0; mIdx = 0;
mIsConst = false; mIsConst = false;
mUsingProtection = BfProtection_Hidden;
mIsInline = false; mIsInline = false;
mIsExtern = false; mIsExtern = false;
mIsVolatile = false; mIsVolatile = false;
mIsProperty = false;
mTypeRef = NULL; mTypeRef = NULL;
mInitializer = NULL; mInitializer = NULL;
mFieldDeclaration = NULL; mFieldDeclaration = NULL;
@ -965,6 +969,38 @@ public:
} }
}; };
class BfUsingFieldData
{
public:
struct FieldRef
{
BfTypeInstance* mTypeInstance;
BfFieldDef* mFieldDef;
FieldRef()
{
mTypeInstance = NULL;
mFieldDef = NULL;
}
FieldRef(BfTypeInstance* typeInst, BfFieldDef* fieldDef)
{
mTypeInstance = typeInst;
mFieldDef = fieldDef;
}
};
struct Entry
{
Array<FieldRef> mConflicts;
SizedArray<FieldRef, 1> mLookup;
};
public:
Array<BfFieldDef*> mUsingFields;
Dictionary<String, Entry> mEntries;
};
// For partial classes, the first entry in the map will contain the combined data // For partial classes, the first entry in the map will contain the combined data
class BfTypeDef class BfTypeDef
{ {
@ -1007,13 +1043,14 @@ public:
Array<BfAtomComposite> mNamespaceSearch; Array<BfAtomComposite> mNamespaceSearch;
Array<BfTypeReference*> mStaticSearch; Array<BfTypeReference*> mStaticSearch;
Array<BfTypeReference*> mInternalAccessSet; Array<BfTypeReference*> mInternalAccessSet;
Array<BfFieldDef*> mFields; Array<BfFieldDef*> mFields;
BfUsingFieldData* mUsingFieldData; // Created during mFieldSet
Array<BfPropertyDef*> mProperties; Array<BfPropertyDef*> mProperties;
Array<BfMethodDef*> mMethods; Array<BfMethodDef*> mMethods;
BfTypeDefMemberSet mMethodSet; BfTypeDefMemberSet mMethodSet;
BfTypeDefMemberSet mFieldSet; BfTypeDefMemberSet mFieldSet;
BfTypeDefMemberSet mPropertySet; BfTypeDefMemberSet mPropertySet;
Array<BfOperatorDef*> mOperators; Array<BfOperatorDef*> mOperators;
Array<BfGenericParamDef*> mGenericParamDefs; Array<BfGenericParamDef*> mGenericParamDefs;
Array<BfExternalConstraintDef> mExternalConstraints; Array<BfExternalConstraintDef> mExternalConstraints;
Array<BfTypeReference*> mBaseTypes; Array<BfTypeReference*> mBaseTypes;
@ -1042,6 +1079,7 @@ public:
bool mHasCtorNoBody; bool mHasCtorNoBody;
bool mHasExtensionMethods; bool mHasExtensionMethods;
bool mHasOverrideMethods; bool mHasOverrideMethods;
bool mHasUsingFields;
bool mIsOpaque; bool mIsOpaque;
bool mIsNextRevision; bool mIsNextRevision;
bool mInDeleteQueue; bool mInDeleteQueue;
@ -1082,6 +1120,7 @@ public:
mHasCtorNoBody = false; mHasCtorNoBody = false;
mHasExtensionMethods = false; mHasExtensionMethods = false;
mHasOverrideMethods = false; mHasOverrideMethods = false;
mHasUsingFields = false;
mIsOpaque = false; mIsOpaque = false;
mPartialUsed = false; mPartialUsed = false;
mIsNextRevision = false; mIsNextRevision = false;
@ -1092,8 +1131,9 @@ public:
mEmitParent = NULL; mEmitParent = NULL;
mOuterType = NULL; mOuterType = NULL;
mTypeDeclaration = NULL; mTypeDeclaration = NULL;
mNextRevision = NULL; mNextRevision = NULL;
mProtection = BfProtection_Public; mProtection = BfProtection_Public;
mUsingFieldData = NULL;
} }
BfSource* GetLastSource(); BfSource* GetLastSource();