1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

Auto ctor fixes

This commit is contained in:
Brian Fiete 2022-04-16 16:43:21 -07:00
parent 87f3aa0335
commit 44ecb92315
12 changed files with 221 additions and 127 deletions

View file

@ -493,7 +493,7 @@ namespace IDE.ui
for (var parserDataStr in mModifiedParsers.Split('\n')) for (var parserDataStr in mModifiedParsers.Split('\n'))
{ {
if (parserDataStr == "") if (parserDataStr == "")
return; break;
var parserData = parserDataStr.Split('\t'); var parserData = parserDataStr.Split('\t');
//var projectSource = IDEApp.sApp.FindProjectSourceItem(parserData[0]); //var projectSource = IDEApp.sApp.FindProjectSourceItem(parserData[0]);
var filePath = parserData.GetNext().Get(); var filePath = parserData.GetNext().Get();
@ -549,6 +549,13 @@ namespace IDE.ui
mUpdatingProjectSources.Add(replaceSymbolData); mUpdatingProjectSources.Add(replaceSymbolData);
} }
if ((mKind == .Rename) && (mUpdatingProjectSources.IsEmpty))
{
gApp.Fail("Cannot rename element");
Close();
return;
}
if (mKind == Kind.FindAllReferences) if (mKind == Kind.FindAllReferences)
{ {
PrintAllReferences(); PrintAllReferences();

View file

@ -4474,7 +4474,16 @@ namespace IDE.ui
if (wantCursorPos != -1) if (wantCursorPos != -1)
{ {
mSelection = null; if (mWidgetWindow.IsKeyDown(.Shift))
{
if (mSelection == null)
mSelection = .(CursorTextPos, wantCursorPos);
else
mSelection.ValueRef.mEndPos = (.)wantCursorPos;
}
else
mSelection = null;
CursorTextPos = wantCursorPos; CursorTextPos = wantCursorPos;
return; return;
} }

View file

@ -758,7 +758,8 @@ void BfAutoComplete::AddField(BfTypeInstance* typeInst, BfFieldDef* fieldDef, Bf
AutoCompleteEntry entry(GetTypeName(fieldInstance->mResolvedType), fieldDef->mName, fieldDef->mNamePrefixCount - wantPrefixCount); AutoCompleteEntry entry(GetTypeName(fieldInstance->mResolvedType), fieldDef->mName, fieldDef->mNamePrefixCount - wantPrefixCount);
if (auto entryAdded = AddEntry(entry, filterStr)) if (auto entryAdded = AddEntry(entry, filterStr))
{ {
auto documentation = (fieldDef->mFieldDeclaration != NULL) ? fieldDef->mFieldDeclaration->mDocumentation : NULL; auto fieldDecl = fieldDef->GetFieldDeclaration();
auto documentation = (fieldDecl != NULL) ? fieldDecl->mDocumentation : NULL;
if (CheckDocumentation(entryAdded, documentation)) if (CheckDocumentation(entryAdded, documentation))
{ {
mModule->PopulateType(typeInst); mModule->PopulateType(typeInst);
@ -786,8 +787,8 @@ void BfAutoComplete::AddField(BfTypeInstance* typeInst, BfFieldDef* fieldDef, Bf
{ {
mDefType = typeInst->mTypeDef; mDefType = typeInst->mTypeDef;
mDefField = fieldDef; mDefField = fieldDef;
if (fieldDef->mFieldDeclaration != NULL) if (auto nameNode = fieldDef->GetNameNode())
SetDefinitionLocation(fieldDef->mFieldDeclaration->mNameNode); SetDefinitionLocation(nameNode);
} }
} }
} }
@ -802,8 +803,9 @@ void BfAutoComplete::AddProp(BfTypeInstance* typeInst, BfPropertyDef* propDef, c
wantPrefixCount++; wantPrefixCount++;
} }
BfCommentNode* documentation = NULL; BfCommentNode* documentation = NULL;
if (propDef->mFieldDeclaration != NULL) auto fieldDecl = propDef->GetFieldDeclaration();
documentation = propDef->mFieldDeclaration->mDocumentation; if (fieldDecl != NULL)
documentation = fieldDecl->mDocumentation;
AutoCompleteEntry entry("property", propDef->mName, propDef->mNamePrefixCount - wantPrefixCount); AutoCompleteEntry entry("property", propDef->mName, propDef->mNamePrefixCount - wantPrefixCount);
if (auto entryAdded = AddEntry(entry, filterStr)) if (auto entryAdded = AddEntry(entry, filterStr))
{ {
@ -861,8 +863,8 @@ void BfAutoComplete::AddProp(BfTypeInstance* typeInst, BfPropertyDef* propDef, c
} }
entryAdded->mDocumentation = mAlloc.AllocString(str); entryAdded->mDocumentation = mAlloc.AllocString(str);
} }
if ((mIsGetDefinition) && (propDef->mFieldDeclaration != NULL)) if ((mIsGetDefinition) && (fieldDecl != NULL))
SetDefinitionLocation(propDef->mFieldDeclaration->mNameNode); SetDefinitionLocation(fieldDecl->mNameNode);
} }
} }
@ -1168,7 +1170,7 @@ void BfAutoComplete::AddEnumTypeMembers(BfTypeInstance* typeInst, const StringIm
AutoCompleteEntry entry(hasPayload ? "payloadEnum" : "value", fieldDef->mName); AutoCompleteEntry entry(hasPayload ? "payloadEnum" : "value", fieldDef->mName);
if (auto entryAdded = AddEntry(entry, filter)) if (auto entryAdded = AddEntry(entry, filter))
{ {
if (CheckDocumentation(entryAdded, fieldDef->mFieldDeclaration->mDocumentation)) if (CheckDocumentation(entryAdded, fieldDef->GetFieldDeclaration()->mDocumentation))
{ {
} }
@ -1177,7 +1179,7 @@ void BfAutoComplete::AddEnumTypeMembers(BfTypeInstance* typeInst, const StringIm
mDefType = typeInst->mTypeDef; mDefType = typeInst->mTypeDef;
mDefField = fieldDef; mDefField = fieldDef;
if (fieldDef->mFieldDeclaration != NULL) if (fieldDef->mFieldDeclaration != NULL)
SetDefinitionLocation(fieldDef->mFieldDeclaration->mNameNode); SetDefinitionLocation(fieldDef->GetFieldDeclaration()->mNameNode);
} }
} }
} }
@ -1296,7 +1298,9 @@ BfProject* BfAutoComplete::GetActiveProject()
bool BfAutoComplete::WantsEntries() bool BfAutoComplete::WantsEntries()
{ {
return (mResolveType == BfResolveType_Autocomplete) || return (mResolveType == BfResolveType_Autocomplete) ||
(mResolveType == BfResolveType_Autocomplete_HighPri); (mResolveType == BfResolveType_Autocomplete_HighPri) ||
(mResolveType == BfResolveType_GetSymbolInfo) ||
(mResolveType == BfResolveType_GoToDefinition);
} }
void BfAutoComplete::AddTopLevelNamespaces(BfAstNode* identifierNode) void BfAutoComplete::AddTopLevelNamespaces(BfAstNode* identifierNode)
@ -1521,12 +1525,12 @@ void BfAutoComplete::CheckIdentifier(BfAstNode* identifierNode, bool isInExpress
{ {
if (auto entryAdded = AddEntry(AutoCompleteEntry("property", prop->mName + "="), filter)) if (auto entryAdded = AddEntry(AutoCompleteEntry("property", prop->mName + "="), filter))
{ {
if (CheckDocumentation(entryAdded, prop->mFieldDeclaration->mDocumentation)) if (CheckDocumentation(entryAdded, prop->GetFieldDeclaration()->mDocumentation))
{ {
} }
if (mIsGetDefinition) if (mIsGetDefinition)
SetDefinitionLocation(prop->mFieldDeclaration->mNameNode); SetDefinitionLocation(prop->GetFieldDeclaration()->mNameNode);
} }
} }
@ -1534,12 +1538,12 @@ void BfAutoComplete::CheckIdentifier(BfAstNode* identifierNode, bool isInExpress
{ {
if (auto entryAdded = AddEntry(AutoCompleteEntry("field", field->mName + "="), filter)) if (auto entryAdded = AddEntry(AutoCompleteEntry("field", field->mName + "="), filter))
{ {
if (CheckDocumentation(entryAdded, field->mFieldDeclaration->mDocumentation)) if (CheckDocumentation(entryAdded, field->GetFieldDeclaration()->mDocumentation))
{ {
} }
if (mIsGetDefinition) if (mIsGetDefinition)
SetDefinitionLocation(field->mFieldDeclaration->mNameNode); SetDefinitionLocation(field->GetFieldDeclaration()->mNameNode);
} }
} }
} }

View file

@ -4508,15 +4508,14 @@ void BfCompiler::ProcessAutocompleteTempType()
for (auto fieldDef : tempTypeDef->mFields) for (auto fieldDef : tempTypeDef->mFields)
{ {
BP_ZONE("ProcessAutocompleteTempType.CheckField"); BP_ZONE("ProcessAutocompleteTempType.CheckField");
auto fieldDecl = fieldDef->mFieldDeclaration; if (BfNodeIsA<BfPropertyDeclaration>(fieldDef->mFieldDeclaration))
if (BfNodeIsA<BfPropertyDeclaration>(fieldDecl))
continue; // Don't process auto-generated property fields continue; // Don't process auto-generated property fields
if (fieldDef->mTypeRef != NULL) if (fieldDef->mTypeRef != NULL)
{ {
BfResolveTypeRefFlags flags = BfResolveTypeRefFlag_None; BfResolveTypeRefFlags flags = BfResolveTypeRefFlag_None;
if ((fieldDecl != NULL) && (fieldDecl->mInitializer != NULL)) if (fieldDef->GetInitializer() != NULL)
flags = (BfResolveTypeRefFlags)(flags | BfResolveTypeRefFlag_AllowInferredSizedArray); flags = (BfResolveTypeRefFlags)(flags | BfResolveTypeRefFlag_AllowInferredSizedArray);
if ((!BfNodeIsA<BfVarTypeReference>(fieldDef->mTypeRef)) && if ((!BfNodeIsA<BfVarTypeReference>(fieldDef->mTypeRef)) &&
(!BfNodeIsA<BfLetTypeReference>(fieldDef->mTypeRef))) (!BfNodeIsA<BfLetTypeReference>(fieldDef->mTypeRef)))
@ -4544,8 +4543,9 @@ void BfCompiler::ProcessAutocompleteTempType()
autoComplete->CheckVarResolution(fieldDef->mTypeRef, fieldInstance->mResolvedType); autoComplete->CheckVarResolution(fieldDef->mTypeRef, fieldInstance->mResolvedType);
} }
auto nameNode = fieldDef->GetNameNode();
if (((autoComplete->mIsGetDefinition) || (autoComplete->mResolveType == BfResolveType_GetResultString)) && if (((autoComplete->mIsGetDefinition) || (autoComplete->mResolveType == BfResolveType_GetResultString)) &&
(fieldDef->mFieldDeclaration != NULL) && (autoComplete->IsAutocompleteNode(fieldDef->mFieldDeclaration->mNameNode))) (fieldDef->mFieldDeclaration != NULL) && (autoComplete->IsAutocompleteNode(nameNode)))
{ {
for (int i = 0; i < (int)actualTypeDef->mFields.size(); i++) for (int i = 0; i < (int)actualTypeDef->mFields.size(); i++)
{ {
@ -4557,9 +4557,9 @@ void BfCompiler::ProcessAutocompleteTempType()
autoComplete->mDefType = actualTypeDef; autoComplete->mDefType = actualTypeDef;
autoComplete->mDefField = actualFieldDef; autoComplete->mDefField = actualFieldDef;
autoComplete->SetDefinitionLocation(fieldDef->mFieldDeclaration->mNameNode); autoComplete->SetDefinitionLocation(nameNode);
autoComplete->mInsertStartIdx = fieldDef->mFieldDeclaration->mNameNode->GetSrcStart(); autoComplete->mInsertStartIdx = nameNode->GetSrcStart();
autoComplete->mInsertEndIdx = fieldDef->mFieldDeclaration->mNameNode->GetSrcEnd(); autoComplete->mInsertEndIdx = nameNode->GetSrcEnd();
} }
else if (autoComplete->mResolveType == BfResolveType_GetResultString) else if (autoComplete->mResolveType == BfResolveType_GetResultString)
{ {
@ -4577,9 +4577,10 @@ void BfCompiler::ProcessAutocompleteTempType()
} }
} }
if ((fieldDef->mFieldDeclaration != NULL) && (fieldDef->mFieldDeclaration->mAttributes != NULL)) BfFieldDeclaration* fieldDecl = fieldDef->GetFieldDeclaration();
if ((fieldDecl != NULL) && (fieldDecl->mAttributes != NULL))
{ {
auto customAttrs = module->GetCustomAttributes(fieldDef->mFieldDeclaration->mAttributes, fieldDef->mIsStatic ? BfAttributeTargets_StaticField : BfAttributeTargets_Field); auto customAttrs = module->GetCustomAttributes(fieldDecl->mAttributes, fieldDef->mIsStatic ? BfAttributeTargets_StaticField : BfAttributeTargets_Field);
delete customAttrs; delete customAttrs;
} }
@ -4588,15 +4589,12 @@ void BfCompiler::ProcessAutocompleteTempType()
module->ResolveConstField(typeInst, NULL, fieldDef); module->ResolveConstField(typeInst, NULL, fieldDef);
} }
if (fieldDef->mInitializer == NULL) if (fieldDef->GetInitializer() == NULL)
{ {
if (BfNodeIsA<BfVarTypeReference>(fieldDef->mTypeRef)) if (BfNodeIsA<BfVarTypeReference>(fieldDef->mTypeRef))
{ {
if (fieldDef->mInitializer == NULL) if ((fieldDef->mTypeRef->IsA<BfVarTypeReference>()) || (fieldDef->mTypeRef->IsA<BfLetTypeReference>()))
{ mPassInstance->Fail("Implicitly-typed fields must be initialized", fieldDef->GetRefNode());
if ((fieldDef->mTypeRef->IsA<BfVarTypeReference>()) || (fieldDef->mTypeRef->IsA<BfLetTypeReference>()))
mPassInstance->Fail("Implicitly-typed fields must be initialized", fieldDef->GetRefNode());
}
} }
} }
} }
@ -4613,17 +4611,19 @@ void BfCompiler::ProcessAutocompleteTempType()
} }
for (auto propDef : tempTypeDef->mProperties) for (auto propDef : tempTypeDef->mProperties)
{ {
if ((propDef->mFieldDeclaration != NULL) && (propDef->mFieldDeclaration->mAttributes != NULL)) auto fieldDecl = propDef->GetFieldDeclaration();
if ((fieldDecl != NULL) && (fieldDecl->mAttributes != NULL))
{ {
BfAttributeTargets target = BfAttributeTargets_Property; BfAttributeTargets target = BfAttributeTargets_Property;
if (propDef->IsExpressionBodied()) if (propDef->IsExpressionBodied())
target = (BfAttributeTargets)(target | BfAttributeTargets_Method); target = (BfAttributeTargets)(target | BfAttributeTargets_Method);
auto customAttrs = module->GetCustomAttributes(propDef->mFieldDeclaration->mAttributes, target); auto customAttrs = module->GetCustomAttributes(fieldDecl->mAttributes, target);
delete customAttrs; delete customAttrs;
} }
auto propDeclaration = BfNodeDynCast<BfPropertyDeclaration>(propDef->mFieldDeclaration); auto propDeclaration = BfNodeDynCast<BfPropertyDeclaration>(fieldDecl);
if (propDeclaration != NULL) if (propDeclaration != NULL)
autoComplete->CheckProperty(propDeclaration); autoComplete->CheckProperty(propDeclaration);
module->ResolveTypeRef(propDef->mTypeRef, BfPopulateType_Identity, BfResolveTypeRefFlag_AllowRef); module->ResolveTypeRef(propDef->mTypeRef, BfPopulateType_Identity, BfResolveTypeRefFlag_AllowRef);
@ -4636,7 +4636,7 @@ void BfCompiler::ProcessAutocompleteTempType()
} }
} }
if ((autoComplete->mIsGetDefinition) && (propDef->mFieldDeclaration != NULL) && (autoComplete->IsAutocompleteNode(propDef->mFieldDeclaration->mNameNode))) if ((autoComplete->mIsGetDefinition) && (fieldDecl != NULL) && (autoComplete->IsAutocompleteNode(fieldDecl->mNameNode)))
{ {
auto checkType = typeInst; auto checkType = typeInst;
while (checkType != NULL) while (checkType != NULL)
@ -5119,8 +5119,8 @@ void BfCompiler::GetSymbolReferences()
BfTypeInstance* checkTypeInst = rebuildTypeInst; BfTypeInstance* checkTypeInst = rebuildTypeInst;
typeState.mCurTypeDef = propDef->mDeclaringType; typeState.mCurTypeDef = propDef->mDeclaringType;
module->GetBasePropertyDef(checkPropDef, checkTypeInst); module->GetBasePropertyDef(checkPropDef, checkTypeInst);
if (propDef->mFieldDeclaration != NULL) if (auto fieldDecl = propDef->GetFieldDeclaration())
mResolvePassData->HandlePropertyReference(propDef->mFieldDeclaration->mNameNode, checkTypeInst->mTypeDef, checkPropDef); mResolvePassData->HandlePropertyReference(fieldDecl->mNameNode, checkTypeInst->mTypeDef, checkPropDef);
} }
} }
@ -5128,10 +5128,10 @@ void BfCompiler::GetSymbolReferences()
{ {
for (auto fieldDef : typeDef->mFields) for (auto fieldDef : typeDef->mFields)
{ {
if (fieldDef->mFieldDeclaration != NULL) if (auto nameNode = fieldDef->GetNameNode())
{ {
typeState.mCurTypeDef = fieldDef->mDeclaringType; typeState.mCurTypeDef = fieldDef->mDeclaringType;
mResolvePassData->HandleFieldReference(fieldDef->mFieldDeclaration->mNameNode, typeDef, fieldDef); mResolvePassData->HandleFieldReference(nameNode, typeDef, fieldDef);
} }
} }
} }
@ -5145,17 +5145,20 @@ void BfCompiler::GetSymbolReferences()
if (fieldDef->mTypeRef != NULL) if (fieldDef->mTypeRef != NULL)
CheckSymbolReferenceTypeRef(module, fieldDef->mTypeRef); CheckSymbolReferenceTypeRef(module, fieldDef->mTypeRef);
if ((fieldDef->mIsConst) && (fieldDef->mInitializer != NULL)) if ((fieldDef->mIsConst) && (fieldDef->GetInitializer() != NULL))
{ {
BfMethodState methodState; BfMethodState methodState;
methodState.mTempKind = BfMethodState::TempKind_Static; methodState.mTempKind = BfMethodState::TempKind_Static;
SetAndRestoreValue<BfMethodState*> prevMethodState(module->mCurMethodState, &methodState); SetAndRestoreValue<BfMethodState*> prevMethodState(module->mCurMethodState, &methodState);
BfConstResolver constResolver(module); BfConstResolver constResolver(module);
constResolver.Resolve(fieldDef->mInitializer); constResolver.Resolve(fieldDef->GetInitializer());
} }
if ((fieldDef->mFieldDeclaration != NULL) && (fieldDef->mFieldDeclaration->mAttributes != NULL)) if (auto fieldDecl = fieldDef->GetFieldDeclaration())
_CheckAttributes(fieldDef->mFieldDeclaration->mAttributes, fieldDef->mDeclaringType); {
if (fieldDecl->mAttributes != NULL)
_CheckAttributes(fieldDecl->mAttributes, fieldDef->mDeclaringType);
}
} }
} }

View file

@ -49,7 +49,7 @@ BfTypedValue BfConstResolver::Resolve(BfExpression* expr, BfType* wantType, BfCo
if (mModule->mContext->mCurTypeState != NULL) if (mModule->mContext->mCurTypeState != NULL)
{ {
if (mModule->mContext->mCurTypeState->mCurFieldDef != NULL) if (mModule->mContext->mCurTypeState->mCurFieldDef != NULL)
initializer = mModule->mContext->mCurTypeState->mCurFieldDef->mInitializer; initializer = mModule->mContext->mCurTypeState->mCurFieldDef->GetInitializer();
if (mModule->mContext->mCurTypeState->mCurVarInitializer != NULL) if (mModule->mContext->mCurTypeState->mCurVarInitializer != NULL)
initializer = mModule->mContext->mCurTypeState->mCurVarInitializer; initializer = mModule->mContext->mCurTypeState->mCurVarInitializer;
if (mModule->mContext->mCurTypeState->mArrayInitializerSize != -1) if (mModule->mContext->mCurTypeState->mArrayInitializerSize != -1)

View file

@ -1964,7 +1964,7 @@ void BfContext::UpdateRevisedTypes()
{ {
if (fieldDef->mIsStatic) if (fieldDef->mIsStatic)
continue; continue;
if (fieldDef->mInitializer != NULL) if (fieldDef->GetInitializer() != NULL)
return false; return false;
} }

View file

@ -706,6 +706,7 @@ BfMethodDef* BfDefBuilder::CreateMethodDef(BfMethodDeclaration* methodDeclaratio
for (auto paramDef : methodDef->mParams) for (auto paramDef : methodDef->mParams)
{ {
auto fieldDef = new BfFieldDef(); auto fieldDef = new BfFieldDef();
fieldDef->mFieldDeclaration = paramDef->mParamDeclaration;
fieldDef->mName = paramDef->mName; fieldDef->mName = paramDef->mName;
while (fieldDef->mName.StartsWith("@")) while (fieldDef->mName.StartsWith("@"))
{ {
@ -940,8 +941,7 @@ void BfDefBuilder::Visit(BfPropertyDeclaration* propertyDeclaration)
{ {
propertyDef->mName = "[]"; propertyDef->mName = "[]";
} }
propertyDef->mTypeRef = propertyDeclaration->mTypeRef; propertyDef->mTypeRef = propertyDeclaration->mTypeRef;
propertyDef->mInitializer = NULL;
propertyDef->mFieldDeclaration = propertyDeclaration; propertyDef->mFieldDeclaration = propertyDeclaration;
BF_ASSERT(mCurDeclaringTypeDef != NULL); BF_ASSERT(mCurDeclaringTypeDef != NULL);
propertyDef->mDeclaringType = mCurDeclaringTypeDef; propertyDef->mDeclaringType = mCurDeclaringTypeDef;
@ -979,7 +979,6 @@ void BfDefBuilder::Visit(BfPropertyDeclaration* propertyDeclaration)
fieldDef->mTypeRef = refTypeRef->mElementType; fieldDef->mTypeRef = refTypeRef->mElementType;
fieldDef->mName = mCurTypeDef->GetAutoPropertyName(propertyDeclaration); fieldDef->mName = mCurTypeDef->GetAutoPropertyName(propertyDeclaration);
fieldDef->mIdx = (int)mCurTypeDef->mFields.size(); fieldDef->mIdx = (int)mCurTypeDef->mFields.size();
fieldDef->mInitializer = propertyDeclaration->mInitializer;
mCurTypeDef->mFields.push_back(fieldDef); mCurTypeDef->mFields.push_back(fieldDef);
mCurTypeDef->mSignatureHash = HashString(fieldDef->mName, mCurTypeDef->mSignatureHash + fieldDef->mNamePrefixCount); mCurTypeDef->mSignatureHash = HashString(fieldDef->mName, mCurTypeDef->mSignatureHash + fieldDef->mNamePrefixCount);
@ -1190,7 +1189,6 @@ void BfDefBuilder::Visit(BfFieldDeclaration* fieldDeclaration)
} }
fieldDef->mIdx = (int)mCurTypeDef->mFields.size() - 1; fieldDef->mIdx = (int)mCurTypeDef->mFields.size() - 1;
fieldDef->mInitializer = fieldDeclaration->mInitializer;
//mCurTypeDef->mSignatureHash = HashNode(fieldDeclaration, mCurTypeDef->mSignatureHash); //mCurTypeDef->mSignatureHash = HashNode(fieldDeclaration, mCurTypeDef->mSignatureHash);
if (mSignatureHashCtx != NULL) if (mSignatureHashCtx != NULL)
@ -2168,18 +2166,18 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
hasStaticField = true; hasStaticField = true;
if (field->mFieldDeclaration != NULL) if (field->mFieldDeclaration != NULL)
{ {
if (field->mFieldDeclaration->mInitializer != NULL) if (field->GetFieldDeclaration()->mInitializer != NULL)
{ {
needsStaticInit = true; needsStaticInit = true;
} }
if (field->mFieldDeclaration->mFieldDtor != NULL) if (field->GetFieldDeclaration()->mFieldDtor != NULL)
needsStaticDtor = true; needsStaticDtor = true;
} }
} }
if (field->mFieldDeclaration != NULL) if (field->mFieldDeclaration != NULL)
{ {
auto attributes = field->mFieldDeclaration->mAttributes; auto attributes = field->GetFieldDeclaration()->mAttributes;
while (attributes != NULL) while (attributes != NULL)
{ {
if (attributes->mAttributeTypeRef != NULL) if (attributes->mAttributeTypeRef != NULL)
@ -2197,10 +2195,13 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
else else
{ {
hasNonStaticField = true; hasNonStaticField = true;
if (field->mInitializer != NULL) if (field->GetInitializer() != NULL)
needsDefaultCtor = true; needsDefaultCtor = true;
if ((field->mFieldDeclaration != NULL) && (field->mFieldDeclaration->mFieldDtor != NULL)) if (auto fieldDecl = field->GetFieldDeclaration())
needsDtor = true; {
if (fieldDecl->mFieldDtor != NULL)
needsDtor = true;
}
} }
} }

View file

@ -4804,7 +4804,7 @@ BfTypedValue BfExprEvaluator::LoadField(BfAstNode* targetSrc, BfTypedValue targe
} }
} }
auto fieldDecl = fieldInstance->GetFieldDef()->mFieldDeclaration; auto fieldDecl = fieldInstance->GetFieldDef()->GetFieldDeclaration();
if ((fieldDecl != NULL) && (fieldDecl->mDocumentation != NULL)) if ((fieldDecl != NULL) && (fieldDecl->mDocumentation != NULL))
{ {
String docString; String docString;

View file

@ -2300,7 +2300,7 @@ void BfModule::LocalVariableDone(BfLocalVariable* localVar, bool isMethodExit)
continue; continue;
} }
if ((fieldDef->mFieldDeclaration != NULL) && (fieldDef->mFieldDeclaration->mInitializer != NULL)) if (fieldDef->GetInitializer() != NULL)
{ {
// This initializer was handled in CtorNoBody // This initializer was handled in CtorNoBody
foundFields = true; foundFields = true;
@ -4051,7 +4051,7 @@ void BfModule::CreateStaticField(BfFieldInstance* fieldInstance, bool isThreadLo
void BfModule::ResolveConstField(BfTypeInstance* typeInstance, BfFieldInstance* fieldInstance, BfFieldDef* fieldDef, bool forceResolve) void BfModule::ResolveConstField(BfTypeInstance* typeInstance, BfFieldInstance* fieldInstance, BfFieldDef* fieldDef, bool forceResolve)
{ {
bool autoCompleteOnly = mCompiler->IsAutocomplete(); bool autoCompleteOnly = mCompiler->IsAutocomplete();
BfType* fieldType = NULL; BfType* fieldType = NULL;
if (fieldInstance != NULL) if (fieldInstance != NULL)
{ {
@ -4074,7 +4074,7 @@ void BfModule::ResolveConstField(BfTypeInstance* typeInstance, BfFieldInstance*
if (isLet || isVar) if (isLet || isVar)
fieldType = GetPrimitiveType(BfTypeCode_Var); fieldType = GetPrimitiveType(BfTypeCode_Var);
else else
fieldType = ResolveTypeRef(fieldDef->mTypeRef,BfPopulateType_Identity, BfResolveTypeRefFlag_AllowInferredSizedArray); fieldType = ResolveTypeRef(fieldDef->mTypeRef, BfPopulateType_Identity, BfResolveTypeRefFlag_AllowInferredSizedArray);
if (fieldType == NULL) if (fieldType == NULL)
fieldType = mContext->mBfObjectType; fieldType = mContext->mBfObjectType;
} }
@ -4116,16 +4116,16 @@ void BfModule::ResolveConstField(BfTypeInstance* typeInstance, BfFieldInstance*
if (!fieldDef->mTypeRef->IsA<BfPointerTypeRef>()) if (!fieldDef->mTypeRef->IsA<BfPointerTypeRef>())
{ {
SetAndRestoreValue<BfTypeInstance*> prevTypeInstance(mCurTypeInstance, typeInstance); SetAndRestoreValue<BfTypeInstance*> prevTypeInstance(mCurTypeInstance, typeInstance);
Fail("Extern consts must be pointer types", fieldDef->mFieldDeclaration->mTypeRef); Fail("Extern consts must be pointer types", fieldDef->mTypeRef);
} }
if (fieldDef->mInitializer != NULL) if (fieldDef->GetInitializer() != NULL)
{ {
SetAndRestoreValue<BfTypeInstance*> prevTypeInstance(mCurTypeInstance, typeInstance); SetAndRestoreValue<BfTypeInstance*> prevTypeInstance(mCurTypeInstance, typeInstance);
Fail("Extern consts cannot have initializers", fieldDef->mFieldDeclaration->mNameNode); Fail("Extern consts cannot have initializers", fieldDef->GetNameNode());
} }
} }
else if (fieldDef->mInitializer == NULL) else if (fieldDef->GetInitializer() == NULL)
{ {
if (fieldDef->IsEnumCaseEntry()) if (fieldDef->IsEnumCaseEntry())
{ {
@ -4163,7 +4163,7 @@ void BfModule::ResolveConstField(BfTypeInstance* typeInstance, BfFieldInstance*
} }
else else
{ {
Fail("Const requires initializer", fieldDef->mFieldDeclaration->mNameNode); Fail("Const requires initializer", fieldDef->GetNameNode());
} }
} }
else if (mBfIRBuilder != NULL) else if (mBfIRBuilder != NULL)
@ -4181,7 +4181,7 @@ void BfModule::ResolveConstField(BfTypeInstance* typeInstance, BfFieldInstance*
if ((fieldType->IsVar()) || (fieldType->IsUndefSizedArray())) if ((fieldType->IsVar()) || (fieldType->IsUndefSizedArray()))
{ {
auto initValue = GetFieldInitializerValue(fieldInstance, fieldDef->mInitializer, fieldDef, fieldType); auto initValue = GetFieldInitializerValue(fieldInstance, fieldDef->GetInitializer(), fieldDef, fieldType);
if (!initValue) if (!initValue)
{ {
AssertErrorState(); AssertErrorState();
@ -4203,7 +4203,7 @@ void BfModule::ResolveConstField(BfTypeInstance* typeInstance, BfFieldInstance*
} }
else else
{ {
auto uncastedInitValue = GetFieldInitializerValue(fieldInstance, fieldDef->mInitializer, fieldDef, fieldType); auto uncastedInitValue = GetFieldInitializerValue(fieldInstance, fieldDef->GetInitializer(), fieldDef, fieldType);
constValue = uncastedInitValue.mValue; constValue = uncastedInitValue.mValue;
} }
@ -4243,7 +4243,7 @@ void BfModule::ResolveConstField(BfTypeInstance* typeInstance, BfFieldInstance*
BfType* BfModule::ResolveVarFieldType(BfTypeInstance* typeInstance, BfFieldInstance* fieldInstance, BfFieldDef* field) BfType* BfModule::ResolveVarFieldType(BfTypeInstance* typeInstance, BfFieldInstance* fieldInstance, BfFieldDef* field)
{ {
bool isDeclType = (field->mFieldDeclaration != NULL) && BfNodeDynCastExact<BfExprModTypeRef>(field->mFieldDeclaration->mTypeRef) != NULL; bool isDeclType = (field->mFieldDeclaration != NULL) && BfNodeDynCastExact<BfExprModTypeRef>(field->mTypeRef) != NULL;
auto fieldType = fieldInstance->GetResolvedType(); auto fieldType = fieldInstance->GetResolvedType();
if ((field->mIsConst) && (!isDeclType)) if ((field->mIsConst) && (!isDeclType))
@ -4297,7 +4297,7 @@ BfType* BfModule::ResolveVarFieldType(BfTypeInstance* typeInstance, BfFieldInsta
SetAndRestoreValue<bool> prevResolvingVar(typeInstance->mResolvingVarField, true); SetAndRestoreValue<bool> prevResolvingVar(typeInstance->mResolvingVarField, true);
SetAndRestoreValue<bool> prevCtxResolvingVar(mContext->mResolvingVarField, true); SetAndRestoreValue<bool> prevCtxResolvingVar(mContext->mResolvingVarField, true);
if ((field->mInitializer == NULL) && (!isDeclType)) if ((field->GetInitializer() == NULL) && (!isDeclType))
{ {
if ((field->mTypeRef->IsA<BfVarTypeReference>()) || (field->mTypeRef->IsA<BfLetTypeReference>())) if ((field->mTypeRef->IsA<BfVarTypeReference>()) || (field->mTypeRef->IsA<BfLetTypeReference>()))
Fail("Implicitly-typed fields must be initialized", field->GetRefNode()); Fail("Implicitly-typed fields must be initialized", field->GetRefNode());
@ -4428,7 +4428,7 @@ BfTypedValue BfModule::GetFieldInitializerValue(BfFieldInstance* fieldInstance,
{ {
if (fieldDef == NULL) if (fieldDef == NULL)
return BfTypedValue(); return BfTypedValue();
initializer = fieldDef->mInitializer; initializer = fieldDef->GetInitializer();
} }
BfTypedValue staticVarRef; BfTypedValue staticVarRef;
@ -15194,10 +15194,18 @@ BfLocalVariable* BfModule::AddLocalVariableDef(BfLocalVariable* localVarDef, boo
BF_ASSERT(rootMethodState->mCurLocalVarId >= 0); BF_ASSERT(rootMethodState->mCurLocalVarId >= 0);
localVarDef->mLocalVarId = rootMethodState->mCurLocalVarId++; localVarDef->mLocalVarId = rootMethodState->mCurLocalVarId++;
} }
if ((localVarDef->mNameNode != NULL) && (mCompiler->mResolvePassData != NULL) && (mCompiler->mResolvePassData->mAutoComplete != NULL) && (!mIsComptimeModule))
mCompiler->mResolvePassData->mAutoComplete->CheckLocalDef(localVarDef->mNameNode, localVarDef);
if ((localVarDef->mNameNode != NULL) && (mCurMethodInstance != NULL)) bool checkLocal = true;
if ((mCurMethodInstance != NULL) && (mCurMethodInstance->mMethodDef->mMethodType == BfMethodType_Ctor))
{
if (auto autoCtorDecl = BfNodeDynCast<BfAutoConstructorDeclaration>(mCurMethodInstance->mMethodDef->mMethodDeclaration))
checkLocal = false;
}
if ((localVarDef->mNameNode != NULL) && (mCompiler->mResolvePassData != NULL) && (mCompiler->mResolvePassData->mAutoComplete != NULL) && (!mIsComptimeModule) && (checkLocal))
mCompiler->mResolvePassData->mAutoComplete->CheckLocalDef(localVarDef->mNameNode, localVarDef);
if (((localVarDef->mNameNode != NULL) && (mCurMethodInstance != NULL)) && (checkLocal))
{ {
bool isClosureProcessing = (mCurMethodState->mClosureState != NULL) && (!mCurMethodState->mClosureState->mCapturing); bool isClosureProcessing = (mCurMethodState->mClosureState != NULL) && (!mCurMethodState->mClosureState->mCapturing);
if ((!isClosureProcessing) && (mCompiler->mResolvePassData != NULL) && (localVarDef->mNameNode != NULL) && (rootMethodState->mMethodInstance != NULL) && (!mIsComptimeModule)) if ((!isClosureProcessing) && (mCompiler->mResolvePassData != NULL) && (localVarDef->mNameNode != NULL) && (rootMethodState->mMethodInstance != NULL) && (!mIsComptimeModule))
@ -16616,13 +16624,13 @@ void BfModule::CreateStaticCtor()
{ {
for (auto fieldDef : typeDef->mFields) for (auto fieldDef : typeDef->mFields)
{ {
if ((!fieldDef->mIsConst) && (fieldDef->mIsStatic) && (fieldDef->mInitializer != NULL)) if ((!fieldDef->mIsConst) && (fieldDef->mIsStatic) && (fieldDef->GetInitializer() != NULL))
{ {
// For extensions, only handle these fields in the appropriate extension // For extensions, only handle these fields in the appropriate extension
if ((fieldDef->mDeclaringType->mTypeDeclaration != methodDef->mDeclaringType->mTypeDeclaration)) if ((fieldDef->mDeclaringType->mTypeDeclaration != methodDef->mDeclaringType->mTypeDeclaration))
continue; continue;
UpdateSrcPos(fieldDef->mInitializer); UpdateSrcPos(fieldDef->GetInitializer());
auto fieldInst = &mCurTypeInstance->mFieldInstances[fieldDef->mIdx]; auto fieldInst = &mCurTypeInstance->mFieldInstances[fieldDef->mIdx];
if (!fieldInst->mFieldIncluded) if (!fieldInst->mFieldIncluded)
@ -16651,19 +16659,19 @@ void BfModule::CreateStaticCtor()
{ {
if ((fieldDef->mIsStatic) && (!fieldDef->mIsConst)) if ((fieldDef->mIsStatic) && (!fieldDef->mIsConst))
{ {
if (fieldDef->mInitializer != NULL) if (fieldDef->GetInitializer() != NULL)
{ {
if (auto sourceClassifier = mCompiler->mResolvePassData->GetSourceClassifier(fieldDef->mInitializer)) if (auto sourceClassifier = mCompiler->mResolvePassData->GetSourceClassifier(fieldDef->GetInitializer()))
{ {
sourceClassifier->SetElementType(fieldDef->mInitializer, BfSourceElementType_Normal); sourceClassifier->SetElementType(fieldDef->GetInitializer(), BfSourceElementType_Normal);
sourceClassifier->VisitChild(fieldDef->mInitializer); sourceClassifier->VisitChildNoRef(fieldDef->GetInitializer());
} }
BfType* wantType = NULL; BfType* wantType = NULL;
if ((!BfNodeIsA<BfVarTypeReference>(fieldDef->mTypeRef)) && (!BfNodeIsA<BfLetTypeReference>(fieldDef->mTypeRef))) if ((!BfNodeIsA<BfVarTypeReference>(fieldDef->mTypeRef)) && (!BfNodeIsA<BfLetTypeReference>(fieldDef->mTypeRef)))
{ {
wantType = ResolveTypeRef(fieldDef->mTypeRef, BfPopulateType_Identity, BfResolveTypeRefFlag_AllowInferredSizedArray); wantType = ResolveTypeRef(fieldDef->mTypeRef, BfPopulateType_Identity, BfResolveTypeRefFlag_AllowInferredSizedArray);
} }
CreateValueFromExpression(fieldDef->mInitializer, wantType, BfEvalExprFlags_FieldInitializer); CreateValueFromExpression(fieldDef->GetInitializer(), wantType, BfEvalExprFlags_FieldInitializer);
} }
} }
} }
@ -16745,7 +16753,9 @@ void BfModule::EmitDtorBody()
{ {
auto fieldInst = &mCurTypeInstance->mFieldInstances[fieldIdx]; auto fieldInst = &mCurTypeInstance->mFieldInstances[fieldIdx];
auto fieldDef = fieldInst->GetFieldDef(); auto fieldDef = fieldInst->GetFieldDef();
if ((fieldDef != NULL) && (fieldDef->mIsStatic == methodDef->mIsStatic) && (fieldDef->mFieldDeclaration != NULL) && (fieldDef->mFieldDeclaration->mFieldDtor != NULL)) auto fieldDecl = fieldDef->GetFieldDeclaration();
if ((fieldDef != NULL) && (fieldDef->mIsStatic == methodDef->mIsStatic) && (fieldDecl != NULL) && (fieldDecl->mFieldDtor != NULL))
{ {
if (fieldDef->mDeclaringType != mCurMethodInstance->mMethodDef->mDeclaringType) if (fieldDef->mDeclaringType != mCurMethodInstance->mMethodDef->mDeclaringType)
{ {
@ -16755,12 +16765,12 @@ void BfModule::EmitDtorBody()
if ((!methodDef->mIsStatic) && (mCurTypeInstance->IsValueType())) if ((!methodDef->mIsStatic) && (mCurTypeInstance->IsValueType()))
{ {
Fail("Structs cannot have field destructors", fieldDef->mFieldDeclaration->mFieldDtor->mTildeToken, true); Fail("Structs cannot have field destructors", fieldDecl->mFieldDtor->mTildeToken, true);
} }
SetAndRestoreValue<BfFilePosition> prevFilePos(mCurFilePosition); SetAndRestoreValue<BfFilePosition> prevFilePos(mCurFilePosition);
auto fieldDtor = fieldDef->mFieldDeclaration->mFieldDtor; auto fieldDtor = fieldDecl->mFieldDtor;
if ((fieldDef->mIsStatic) != (methodDef->mIsStatic)) if ((fieldDef->mIsStatic) != (methodDef->mIsStatic))
continue; continue;
@ -16915,8 +16925,10 @@ void BfModule::EmitDtorBody()
{ {
for (auto fieldDef : tempTypeDef->mFields) for (auto fieldDef : tempTypeDef->mFields)
{ {
auto fieldDecl = fieldDef->GetFieldDeclaration();
if ((fieldDef->mIsStatic == methodDef->mIsStatic) && (fieldDef->mFieldDeclaration != NULL) && if ((fieldDef->mIsStatic == methodDef->mIsStatic) && (fieldDef->mFieldDeclaration != NULL) &&
(fieldDef->mFieldDeclaration->mFieldDtor != NULL) && (mCompiler->mResolvePassData->mIsClassifying)) (fieldDecl->mFieldDtor != NULL) && (mCompiler->mResolvePassData->mIsClassifying))
{ {
BfType* fieldType = NULL; BfType* fieldType = NULL;
@ -16930,7 +16942,7 @@ void BfModule::EmitDtorBody()
if (fieldType == NULL) if (fieldType == NULL)
fieldType = GetPrimitiveType(BfTypeCode_Var); fieldType = GetPrimitiveType(BfTypeCode_Var);
auto fieldDtor = fieldDef->mFieldDeclaration->mFieldDtor; auto fieldDtor = fieldDecl->mFieldDtor;
BfScopeData scopeData; BfScopeData scopeData;
mCurMethodState->AddScope(&scopeData); mCurMethodState->AddScope(&scopeData);
@ -17595,8 +17607,9 @@ void BfModule::EmitCtorBody(bool& skipBody)
continue; continue;
if (fieldInst->mDataIdx < 0) if (fieldInst->mDataIdx < 0)
continue; continue;
auto initializer = fieldDef->GetInitializer();
if (fieldDef->mInitializer == NULL) if (initializer == NULL)
{ {
continue; continue;
@ -17612,9 +17625,9 @@ void BfModule::EmitCtorBody(bool& skipBody)
continue; continue;
} }
if (fieldDef->mInitializer != NULL) if (initializer != NULL)
{ {
_CheckInitBlock(fieldDef->mInitializer); _CheckInitBlock(initializer);
} }
BfIRValue fieldAddr; BfIRValue fieldAddr;
@ -17668,12 +17681,14 @@ void BfModule::EmitCtorBody(bool& skipBody)
{ {
for (auto fieldDef : tempTypeDef->mFields) for (auto fieldDef : tempTypeDef->mFields)
{ {
if ((!fieldDef->mIsStatic) && (fieldDef->mInitializer != NULL) && (mCompiler->mResolvePassData->mIsClassifying)) auto initializer = fieldDef->GetInitializer();
if ((!fieldDef->mIsStatic) && (initializer != NULL) && (mCompiler->mResolvePassData->mIsClassifying))
{ {
if (auto sourceClassifier = mCompiler->mResolvePassData->GetSourceClassifier(fieldDef->mInitializer)) if (auto sourceClassifier = mCompiler->mResolvePassData->GetSourceClassifier(initializer))
{ {
sourceClassifier->SetElementType(fieldDef->mInitializer, BfSourceElementType_Normal); sourceClassifier->SetElementType(initializer, BfSourceElementType_Normal);
sourceClassifier->VisitChild(fieldDef->mInitializer); sourceClassifier->VisitChild(initializer);
} }
BfType* wantType = NULL; BfType* wantType = NULL;
@ -17683,7 +17698,7 @@ void BfModule::EmitCtorBody(bool& skipBody)
if ((wantType != NULL) && if ((wantType != NULL) &&
((wantType->IsVar()) || (wantType->IsLet()) || (wantType->IsRef()))) ((wantType->IsVar()) || (wantType->IsLet()) || (wantType->IsRef())))
wantType = NULL; wantType = NULL;
CreateValueFromExpression(fieldDef->mInitializer, wantType, BfEvalExprFlags_FieldInitializer); CreateValueFromExpression(initializer, wantType, BfEvalExprFlags_FieldInitializer);
} }
} }
@ -17708,10 +17723,10 @@ void BfModule::EmitCtorBody(bool& skipBody)
// Mark fields from full type with initializers as initialized, to give proper initialization errors within ctor // Mark fields from full type with initializers as initialized, to give proper initialization errors within ctor
for (auto fieldDef : typeDef->mFields) for (auto fieldDef : typeDef->mFields)
{ {
if ((!fieldDef->mIsConst) && (!fieldDef->mIsStatic) && (fieldDef->mInitializer != NULL)) if ((!fieldDef->mIsConst) && (!fieldDef->mIsStatic) && (fieldDef->GetInitializer() != NULL))
{ {
auto fieldInst = &mCurTypeInstance->mFieldInstances[fieldDef->mIdx]; auto fieldInst = &mCurTypeInstance->mFieldInstances[fieldDef->mIdx];
if (fieldDef->mInitializer != NULL) if (fieldDef->GetInitializer() != NULL)
MarkFieldInitialized(fieldInst); MarkFieldInitialized(fieldInst);
} }
} }
@ -18022,8 +18037,9 @@ void BfModule::EmitEnumToStringBody()
continue; continue;
// Only allow compact 'ValA, ValB' enum declaration fields through // Only allow compact 'ValA, ValB' enum declaration fields through
auto fieldDecl = fieldInstance.GetFieldDef()->mFieldDeclaration; auto fieldDef = fieldInstance.GetFieldDef();
if ((fieldDecl == NULL) || (fieldDecl->mTypeRef != NULL)) auto fieldDecl = fieldDef->mFieldDeclaration;
if ((fieldDecl == NULL) || (fieldDef->mTypeRef != NULL))
continue; continue;
auto constant = mCurTypeInstance->mConstHolder->GetConstantById(fieldInstance.mConstIdx); auto constant = mCurTypeInstance->mConstHolder->GetConstantById(fieldInstance.mConstIdx);

View file

@ -821,8 +821,9 @@ void BfModule::CheckMemberNames(BfTypeInstance* typeInst)
memberRef.mProtection = prop->mProtection; memberRef.mProtection = prop->mProtection;
memberRef.mName = prop->mName; memberRef.mName = prop->mName;
memberRef.mKindName = "property"; memberRef.mKindName = "property";
if (prop->mFieldDeclaration != NULL) auto fieldDecl = prop->GetFieldDeclaration();
memberRef.mNameNode = prop->mFieldDeclaration->mNameNode; if (fieldDecl != NULL)
memberRef.mNameNode = fieldDecl->mNameNode;
memberRef.mDeclaringType = prop->mDeclaringType; memberRef.mDeclaringType = prop->mDeclaringType;
auto propertyDeclaration = BfNodeDynCast<BfPropertyDeclaration>(prop->mFieldDeclaration); auto propertyDeclaration = BfNodeDynCast<BfPropertyDeclaration>(prop->mFieldDeclaration);
if (propertyDeclaration != NULL) if (propertyDeclaration != NULL)
@ -843,11 +844,16 @@ void BfModule::CheckMemberNames(BfTypeInstance* typeInst)
memberRef.mName = field->mName; memberRef.mName = field->mName;
memberRef.mKindName = "field"; memberRef.mKindName = "field";
memberRef.mDeclaringType = field->mDeclaringType; memberRef.mDeclaringType = field->mDeclaringType;
if (field->mFieldDeclaration != NULL) if (auto fieldDecl = field->GetFieldDeclaration())
{ {
memberRef.mNameNode = field->mFieldDeclaration->mNameNode; memberRef.mNameNode = fieldDecl->mNameNode;
memberRef.mIsOverride = field->mFieldDeclaration->mNewSpecifier != NULL; memberRef.mIsOverride = fieldDecl->mNewSpecifier != NULL;
} }
else if (auto paramDecl = field->GetParamDeclaration())
{
memberRef.mNameNode = paramDecl->mNameNode;
}
memberList.push_back(memberRef); memberList.push_back(memberRef);
} }
@ -1045,7 +1051,7 @@ bool BfModule::CheckCircularDataError()
else if ((checkTypeState->mCurFieldDef != NULL) && (checkTypeState->mCurFieldDef->mFieldDeclaration != NULL)) else if ((checkTypeState->mCurFieldDef != NULL) && (checkTypeState->mCurFieldDef->mFieldDeclaration != NULL))
{ {
Fail(StrFormat("Field '%s.%s' causes a data cycle", TypeToString(checkTypeState->mType).c_str(), checkTypeState->mCurFieldDef->mName.c_str()), Fail(StrFormat("Field '%s.%s' causes a data cycle", TypeToString(checkTypeState->mType).c_str(), checkTypeState->mCurFieldDef->mName.c_str()),
checkTypeState->mCurFieldDef->mFieldDeclaration->mTypeRef, true); checkTypeState->mCurFieldDef->mTypeRef, true);
} }
else if (checkTypeState->mCurFieldDef != NULL) else if (checkTypeState->mCurFieldDef != NULL)
{ {
@ -4387,7 +4393,9 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
SetAndRestoreValue<BfTypeState::ResolveKind> prevResolveKind(mContext->mCurTypeState->mResolveKind, BfTypeState::ResolveKind_FieldType); SetAndRestoreValue<BfTypeState::ResolveKind> prevResolveKind(mContext->mCurTypeState->mResolveKind, BfTypeState::ResolveKind_FieldType);
BfType* resolvedFieldType = NULL; BfType* resolvedFieldType = NULL;
auto initializer = field->GetInitializer();
if (field->IsEnumCaseEntry()) if (field->IsEnumCaseEntry())
{ {
if (typeInstance->IsEnum()) if (typeInstance->IsEnum())
@ -4432,7 +4440,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
else else
{ {
BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_NoResolveGenericParam; BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_NoResolveGenericParam;
if (field->mInitializer != NULL) if (initializer != NULL)
resolveFlags = (BfResolveTypeRefFlags)(resolveFlags | BfResolveTypeRefFlag_AllowInferredSizedArray); resolveFlags = (BfResolveTypeRefFlags)(resolveFlags | BfResolveTypeRefFlag_AllowInferredSizedArray);
resolvedFieldType = ResolveTypeRef(field->mTypeRef, BfPopulateType_Declaration, resolveFlags); resolvedFieldType = ResolveTypeRef(field->mTypeRef, BfPopulateType_Declaration, resolveFlags);
if (resolvedFieldType == NULL) if (resolvedFieldType == NULL)
@ -4449,7 +4457,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
{ {
if (arrayTypeRef->IsInferredSize()) if (arrayTypeRef->IsInferredSize())
{ {
if (field->mInitializer != NULL) if (initializer != NULL)
{ {
DeferredResolveEntry resolveEntry; DeferredResolveEntry resolveEntry;
resolveEntry.mFieldDef = field; resolveEntry.mFieldDef = field;
@ -4523,7 +4531,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
{ {
// Already handled // Already handled
} }
else if ((fieldDef != NULL) && (fieldDef->mFieldDeclaration != NULL) && (fieldDef->mFieldDeclaration->mAttributes != NULL) && (!typeInstance->mTypeFailed)) else if ((fieldDef != NULL) && (fieldDef->GetFieldDeclaration() != NULL) && (fieldDef->GetFieldDeclaration()->mAttributes != NULL) && (!typeInstance->mTypeFailed))
{ {
if (auto propDecl = BfNodeDynCast<BfPropertyDeclaration>(fieldDef->mFieldDeclaration)) if (auto propDecl = BfNodeDynCast<BfPropertyDeclaration>(fieldDef->mFieldDeclaration))
{ {
@ -4533,14 +4541,14 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
{ {
SetAndRestoreValue<BfFieldDef*> prevTypeRef(mContext->mCurTypeState->mCurFieldDef, fieldDef); SetAndRestoreValue<BfFieldDef*> prevTypeRef(mContext->mCurTypeState->mCurFieldDef, fieldDef);
fieldInstance->mCustomAttributes = GetCustomAttributes(fieldDef->mFieldDeclaration->mAttributes, fieldDef->mIsStatic ? BfAttributeTargets_StaticField : BfAttributeTargets_Field); fieldInstance->mCustomAttributes = GetCustomAttributes(fieldDef->GetFieldDeclaration()->mAttributes, fieldDef->mIsStatic ? BfAttributeTargets_StaticField : BfAttributeTargets_Field);
for (auto customAttr : fieldInstance->mCustomAttributes->mAttributes) for (auto customAttr : fieldInstance->mCustomAttributes->mAttributes)
{ {
if (TypeToString(customAttr.mType) == "System.ThreadStaticAttribute") if (TypeToString(customAttr.mType) == "System.ThreadStaticAttribute")
{ {
if ((!fieldDef->mIsStatic) || (fieldDef->mIsConst)) if ((!fieldDef->mIsStatic) || (fieldDef->mIsConst))
{ {
Fail("ThreadStatic attribute can only be used on static fields", fieldDef->mFieldDeclaration->mAttributes); Fail("ThreadStatic attribute can only be used on static fields", fieldDef->GetFieldDeclaration()->mAttributes);
} }
} }
} }
@ -4750,9 +4758,9 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
if (propDef->IsExpressionBodied()) if (propDef->IsExpressionBodied())
target = (BfAttributeTargets)(target | BfAttributeTargets_Method); target = (BfAttributeTargets)(target | BfAttributeTargets_Method);
if ((propDef->mFieldDeclaration->mAttributes != NULL) && (!typeInstance->mTypeFailed)) if ((propDef->GetFieldDeclaration()->mAttributes != NULL) && (!typeInstance->mTypeFailed))
{ {
auto customAttrs = GetCustomAttributes(propDef->mFieldDeclaration->mAttributes, target); auto customAttrs = GetCustomAttributes(propDef->GetFieldDeclaration()->mAttributes, target);
delete customAttrs; delete customAttrs;
} }
@ -4845,7 +4853,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
if ((!typeInstance->IsBoxed()) && (fieldDef != NULL)) if ((!typeInstance->IsBoxed()) && (fieldDef != NULL))
{ {
if ((fieldDef->mUsingProtection != BfProtection_Hidden) && (!resolvedFieldType->IsStruct()) && (!resolvedFieldType->IsObject())) 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); Warn(0, StrFormat("Field type '%s' is not applicable for 'using'", TypeToString(resolvedFieldType).c_str()), fieldDef->GetFieldDeclaration()->mConstSpecifier);
if (fieldInstance->mIsEnumPayloadCase) if (fieldInstance->mIsEnumPayloadCase)
{ {
@ -4871,12 +4879,14 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
if (fieldDef->mIsExtern) if (fieldDef->mIsExtern)
{ {
Fail("Cannot declare instance member as 'extern'", fieldDef->mFieldDeclaration->mExternSpecifier, true); Fail("Cannot declare instance member as 'extern'", fieldDef->GetFieldDeclaration()->mExternSpecifier, true);
} }
BfAstNode* nameRefNode = NULL; BfAstNode* nameRefNode = NULL;
if (fieldDef->mFieldDeclaration != NULL) if (auto fieldDecl = fieldDef->GetFieldDeclaration())
nameRefNode = fieldDef->mFieldDeclaration->mNameNode; nameRefNode = fieldDecl->mNameNode;
else if (auto paramDecl = fieldDef->GetParamDeclaration())
nameRefNode = paramDecl->mNameNode;
if (nameRefNode == NULL) if (nameRefNode == NULL)
nameRefNode = fieldDef->mTypeRef; nameRefNode = fieldDef->mTypeRef;

View file

@ -3244,8 +3244,15 @@ void BfSystem::FinishCompositePartial(BfTypeDef* compositeTypeDef)
for (auto fieldDef : partialTypeDef->mFields) for (auto fieldDef : partialTypeDef->mFields)
{ {
if ((!fieldDef->mIsStatic) && (fieldDef->mFieldDeclaration != NULL) && (fieldDef->mFieldDeclaration->mInitializer != NULL)) if (!fieldDef->mIsStatic)
hasInitializers = true; {
if (auto fieldDeclaration = BfNodeDynCast<BfFieldDeclaration>(fieldDef->mFieldDeclaration))
if (fieldDeclaration->mInitializer != NULL)
hasInitializers = true;
if (auto paramDeclaration = BfNodeDynCast<BfParameterDeclaration>(fieldDef->mFieldDeclaration))
if (paramDeclaration->mInitializer != NULL)
hasInitializers = true;
}
} }
if (hasInitializers) if (hasInitializers)

View file

@ -564,14 +564,13 @@ 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
BfTypeReference* mTypeRef;
BfProtection mUsingProtection; BfProtection mUsingProtection;
bool mIsInline; bool mIsInline;
bool mIsVolatile; bool mIsVolatile;
bool mIsExtern; bool mIsExtern;
bool mIsProperty; bool mIsProperty;
BfTypeReference* mTypeRef; BfAstNode* mFieldDeclaration;
BfExpression* mInitializer;
BfFieldDeclaration* mFieldDeclaration;
// It may seem that fields and properties don't need a 'mNextWithSameName', but with extensions it's possible // It may seem that fields and properties don't need a 'mNextWithSameName', but with extensions it's possible
// to have two libraries which each add a field to a type with the same name // to have two libraries which each add a field to a type with the same name
BfFieldDef* mNextWithSameName; BfFieldDef* mNextWithSameName;
@ -581,13 +580,12 @@ public:
{ {
mIdx = 0; mIdx = 0;
mIsConst = false; mIsConst = false;
mTypeRef = NULL;
mUsingProtection = BfProtection_Hidden; mUsingProtection = BfProtection_Hidden;
mIsInline = false; mIsInline = false;
mIsExtern = false; mIsExtern = false;
mIsVolatile = false; mIsVolatile = false;
mIsProperty = false; mIsProperty = false;
mTypeRef = NULL;
mInitializer = NULL;
mFieldDeclaration = NULL; mFieldDeclaration = NULL;
mNextWithSameName = NULL; mNextWithSameName = NULL;
} }
@ -611,10 +609,49 @@ public:
{ {
if (mFieldDeclaration == NULL) if (mFieldDeclaration == NULL)
return NULL; return NULL;
if (mFieldDeclaration->mNameNode != NULL)
return mFieldDeclaration->mNameNode; if (auto fieldDeclaration = BfNodeDynCast<BfFieldDeclaration>(mFieldDeclaration))
{
if (fieldDeclaration->mNameNode != NULL)
return fieldDeclaration->mNameNode;
}
if (auto paramDeclaration = BfNodeDynCast<BfParameterDeclaration>(mFieldDeclaration))
{
if (paramDeclaration->mNameNode != NULL)
return paramDeclaration->mNameNode;
}
return mFieldDeclaration; return mFieldDeclaration;
} }
BfFieldDeclaration* GetFieldDeclaration()
{
return BfNodeDynCast<BfFieldDeclaration>(mFieldDeclaration);
}
BfParameterDeclaration* GetParamDeclaration()
{
return BfNodeDynCast<BfParameterDeclaration>(mFieldDeclaration);
}
BfExpression* GetInitializer()
{
if (auto fieldDecl = GetFieldDeclaration())
return fieldDecl->mInitializer;
if (auto paramDecl = GetParamDeclaration())
return paramDecl->mInitializer;
return NULL;
}
BfAstNode* GetNameNode()
{
if (auto fieldDecl = GetFieldDeclaration())
return fieldDecl->mNameNode;
if (auto paramDecl = GetParamDeclaration())
return paramDecl->mNameNode;
return NULL;
}
}; };
class BfPropertyDef : public BfFieldDef class BfPropertyDef : public BfFieldDef