diff --git a/IDEHelper/COFFData.h b/IDEHelper/COFFData.h index 440a96d2..d0b19a4d 100644 --- a/IDEHelper/COFFData.h +++ b/IDEHelper/COFFData.h @@ -7,7 +7,6 @@ struct CV_LVAR_ADDR_GAP; NS_BF_BEGIN - #define PE_SIZEOF_SHORT_NAME 8 #define PE_DIRECTORY_ENTRY_EXPORT 0 // Export Directory #define PE_NUMBEROF_DIRECTORY_ENTRIES 16 @@ -17,7 +16,6 @@ NS_BF_BEGIN #define PE_MACHINE_X86 0x14c #define PE_MACHINE_X64 0x8664 - // DOS .EXE header struct PEHeader { @@ -174,8 +172,8 @@ struct PE_NTHeaders64 struct PESectionHeader { - char mName[IMAGE_SIZEOF_SHORT_NAME]; - DWORD mVirtualSize; + char mName[IMAGE_SIZEOF_SHORT_NAME]; + DWORD mVirtualSize; DWORD mVirtualAddress; DWORD mSizeOfRawData; DWORD mPointerToRawData; @@ -234,8 +232,8 @@ struct PE_SymInfoAux // int GetPrologSize() const { return mAttributes & 0xF; } // // // # regs saved -// int GetNumSavedRegs() const { return (mAttributes >> 8) & 0x7; } -// bool HasSEH() const { return (mAttributes >> 9) & 1; } +// int GetNumSavedRegs() const { return (mAttributes >> 8) & 0x7; } +// bool HasSEH() const { return (mAttributes >> 9) & 1; } // bool UseBP() const { return (mAttributes >> 10) & 1; } // // // cbFrame: frame pointer @@ -279,7 +277,7 @@ struct COFFFrameProgram Command_Align, Command_Set, Command_Deref, - Command_Value, + Command_Value, Command_Value8 }; diff --git a/IDEHelper/Compiler/BfAst.cpp b/IDEHelper/Compiler/BfAst.cpp index f7682d36..7b850f08 100644 --- a/IDEHelper/Compiler/BfAst.cpp +++ b/IDEHelper/Compiler/BfAst.cpp @@ -17,11 +17,11 @@ BfStructuralVisitor::BfStructuralVisitor() } void BfStructuralVisitor::VisitMembers(BfBlock* node) -{ +{ for (auto& child : *node) - { + { child->Accept(this); - } + } } void BfStructuralVisitor::VisitChildNoRef(BfAstNode* node) @@ -673,7 +673,7 @@ void BfStructuralVisitor::Visit(BfNamespaceDeclaration* namespaceDeclaration) void BfStructuralVisitor::Visit(BfBlock* block) { - Visit(block->ToBase()); + Visit(block->ToBase()); } void BfStructuralVisitor::Visit(BfUnscopedBlock* block) @@ -688,7 +688,7 @@ void BfStructuralVisitor::Visit(BfBlockExtension* block) void BfStructuralVisitor::Visit(BfRootNode* rootNode) { - Visit(rootNode->ToBase()); + Visit(rootNode->ToBase()); } void BfStructuralVisitor::Visit(BfInlineAsmStatement* asmStmt) @@ -715,7 +715,7 @@ BfAstTypeInfo::BfAstTypeInfo(const char* name, BfAstTypeInfo* baseType, BfAstAcc if (mBaseType != NULL) { mBaseType->mDerivedTypes.Add(this); - } + } sTypeCount++; #ifdef _DEBUG @@ -800,7 +800,7 @@ bool BfAstNode::IsMissingSemicolon() return (attribExpr->mStatement == NULL) || (attribExpr->mStatement->IsMissingSemicolon()); if (auto stmt = BfNodeDynCast(this)) - return stmt->mTrailingSemicolon == NULL; + return stmt->mTrailingSemicolon == NULL; return false; } @@ -832,7 +832,7 @@ bool BfAstNode::WantsWarning(int warningNumber) } bool BfAstNode::LocationEquals(BfAstNode* otherNode) -{ +{ return (GetSourceData() == otherNode->GetSourceData()) && (GetSrcStart() == otherNode->GetSrcStart()) && (GetSrcEnd() == otherNode->GetSrcEnd()); @@ -851,7 +851,7 @@ String BfAstNode::LocationToString() return String(); String loc; - + int line = -1; int lineChar = -1; parserData->GetLineCharAtIdx(mSrcStart, line, lineChar); @@ -864,10 +864,10 @@ String BfAstNode::LocationToString() } void BfAstNode::Add(BfAstNode* bfAstNode) -{ +{ #ifdef BF_AST_HAS_PARENT_MEMBER BF_ASSERT(bfAstNode->mParent == NULL); - bfAstNode->mParent = this; + bfAstNode->mParent = this; #endif if (!IsInitialized()) @@ -897,7 +897,7 @@ void BfAstNode::Add(BfAstNode* bfAstNode) SetSrcStart(childSrcStart); if (childSrcEnd > prevSrcEnd) SetSrcEnd(childSrcEnd); -#else +#else BF_ASSERT(mSrcStart >= 0); BF_ASSERT(bfAstNode->mSrcStart >= 0); @@ -934,14 +934,14 @@ void BfAstNode::RemoveNextSibling() } void BfAstNode::DeleteNextSibling() -{ +{ //mNext->DeleteSelf(); } void BfAstNode::Init(BfParser* bfParser) { BF_ASSERT(GetSourceData() == bfParser->mSourceData); - Init(bfParser->mTriviaStart, bfParser->mTokenStart, bfParser->mTokenEnd); + Init(bfParser->mTriviaStart, bfParser->mTokenStart, bfParser->mTokenEnd); } void BfAstNode::Accept(BfStructuralVisitor* bfVisitor) @@ -960,7 +960,7 @@ bool BfAstNode::IsTemporary() int BfAstNode::GetStartCharId() { - if (!IsTemporary()) + if (!IsTemporary()) { auto bfParser = GetSourceData()->ToParserData(); if (bfParser != NULL) @@ -970,8 +970,8 @@ int BfAstNode::GetStartCharId() } BfSourceData* BfAstNode::GetSourceData() -{ -#ifdef BF_AST_ALLOCATOR_USE_PAGES +{ +#ifdef BF_AST_ALLOCATOR_USE_PAGES //BF_ASSERT((intptr)this > 0x4200000000); BfAstPageHeader* pageHeader = (BfAstPageHeader*)((intptr)this & ~(BfAstAllocManager::PAGE_SIZE - 1)); return pageHeader->mSourceData; @@ -1021,14 +1021,14 @@ String BfAstNode::ToString() int srcLen = GetSrcLength(); if (srcLen <= 0) { - if (auto namedTypeRef = BfNodeDynCast(this)) - return namedTypeRef->mNameNode->ToString(); + if (auto namedTypeRef = BfNodeDynCast(this)) + return namedTypeRef->mNameNode->ToString(); return ""; } auto source = GetSourceData(); - String str(source->mSrc + GetSrcStart(), srcLen); + String str(source->mSrc + GetSrcStart(), srcLen); return str; } @@ -1057,7 +1057,7 @@ void BfAstNode::ToString(StringImpl& str) } auto source = GetSourceData(); - str.Append(source->mSrc + GetSrcStart(), srcLen); + str.Append(source->mSrc + GetSrcStart(), srcLen); } bool BfAstNode::Equals(const StringImpl& str) @@ -1079,7 +1079,7 @@ bool BfAstNode::Equals(const StringView& str) } bool BfAstNode::Equals(const char* str) -{ +{ auto source = GetSourceData(); const char* ptrLhs = source->mSrc + mSrcStart; const char* ptrLhsEnd = source->mSrc + mSrcEnd; @@ -1087,7 +1087,7 @@ bool BfAstNode::Equals(const char* str) while (true) { - char cRhs = *(ptrRhs++); + char cRhs = *(ptrRhs++); if (cRhs == 0) return ptrLhs == ptrLhsEnd; if (ptrLhs == ptrLhsEnd) @@ -1098,7 +1098,6 @@ bool BfAstNode::Equals(const char* str) } } - ////////////////////////////////////////////////////////////////////////// void BfBlock::Init(const SizedArrayImpl& vec, BfAstAllocator* alloc) @@ -1112,18 +1111,18 @@ void BfBlock::Init(const SizedArrayImpl& vec, BfAstAllocator* alloc) { int bytesLeft = alloc->GetCurPageBytesLeft(); int useElems = std::min(bytesLeft / (int)sizeof(ASTREF(BfAstNode*)), elemsLeft); - BfBlockExtension* nextExt = NULL; + BfBlockExtension* nextExt = NULL; BfSizedArray& childArrRef = (curExt != NULL) ? curExt->mChildArr : mChildArr; childArrRef.mVals = (ASTREF(BfAstNode*)*)alloc->AllocBytes(useElems * sizeof(ASTREF(BfAstNode*)), sizeof(ASTREF(BfAstNode*))); childArrRef.mSize = useElems; - if (useElems < elemsLeft) + if (useElems < elemsLeft) { nextExt = alloc->Alloc(); useElems--; } for (int i = 0; i < useElems; i++) - childArrRef[i] = vec[curIdx++]; + childArrRef[i] = vec[curIdx++]; if (nextExt != NULL) { childArrRef[useElems] = nextExt; @@ -1131,7 +1130,7 @@ void BfBlock::Init(const SizedArrayImpl& vec, BfAstAllocator* alloc) } elemsLeft -= useElems; } -#else +#else BfSizedArrayInitIndirect(mChildArr, vec, alloc); #endif } @@ -1157,10 +1156,10 @@ int BfBlock::GetSize() { int size = mChildArr.mSize; if (mChildArr.mSize == 0) - return size; + return size; BfAstNode* backNode = mChildArr.mVals[mChildArr.mSize - 1]; while (true) - { + { if (auto blockExt = BfNodeDynCastExact(backNode)) { size--; @@ -1172,12 +1171,12 @@ int BfBlock::GetSize() break; } } - + return size; } void BfBlock::SetSize(int wantSize) -{ +{ int size = mChildArr.mSize; if (wantSize == size) return; @@ -1390,7 +1389,7 @@ const char* Beefy::BfTokenToString(BfToken token) case BfToken_Extension: return "extension"; case BfToken_Fallthrough: - return "fallthrough"; + return "fallthrough"; case BfToken_Finally: return "finally"; case BfToken_Fixed: @@ -1426,7 +1425,7 @@ const char* Beefy::BfTokenToString(BfToken token) case BfToken_Namespace: return "namespace"; case BfToken_New: - return "new"; + return "new"; case BfToken_Null: return "null"; case BfToken_Nullable: @@ -1578,7 +1577,7 @@ const char* Beefy::BfTokenToString(BfToken token) case BfToken_Colon: return ":"; case BfToken_Comma: - return ","; + return ","; case BfToken_Dot: case BfToken_AutocompleteDot: return "."; @@ -1645,7 +1644,7 @@ bool Beefy::BfTokenIsKeyword(BfToken token) BfBinaryOp Beefy::BfAssignOpToBinaryOp(BfAssignmentOp assignmentOp) { switch (assignmentOp) - { + { case BfAssignmentOp_Add: return BfBinaryOp_Add; case BfAssignmentOp_Subtract: @@ -1681,9 +1680,9 @@ BfBinaryOp Beefy::BfAssignOpToBinaryOp(BfAssignmentOp assignmentOp) } int Beefy::BfGetBinaryOpPrecendence(BfBinaryOp binOp) -{ +{ switch (binOp) - { + { case BfBinaryOp_Multiply: case BfBinaryOp_OverflowMultiply: case BfBinaryOp_Divide: @@ -1693,7 +1692,7 @@ int Beefy::BfGetBinaryOpPrecendence(BfBinaryOp binOp) case BfBinaryOp_Subtract: case BfBinaryOp_OverflowAdd: case BfBinaryOp_OverflowSubtract: - return 13; + return 13; case BfBinaryOp_LeftShift: case BfBinaryOp_RightShift: return 12; @@ -1722,7 +1721,7 @@ int Beefy::BfGetBinaryOpPrecendence(BfBinaryOp binOp) case BfBinaryOp_StrictInEquality: return 4; case BfBinaryOp_ConditionalAnd: - return 3; + return 3; case BfBinaryOp_ConditionalOr: return 2; case BfBinaryOp_NullCoalesce: @@ -1797,7 +1796,7 @@ const char* Beefy::BfGetOpName(BfUnaryOp unaryOp) case BfUnaryOp_FromEnd: return "^"; case BfUnaryOp_PartialRangeUpTo: return "..<"; case BfUnaryOp_PartialRangeThrough: return "..."; - case BfUnaryOp_PartialRangeFrom: return "..."; + case BfUnaryOp_PartialRangeFrom: return "..."; default: return "???"; } } @@ -1929,7 +1928,6 @@ bool Beefy::BfCanOverloadOperator(BfUnaryOp unaryOp) } } - BfAssignmentOp Beefy::BfTokenToAssignmentOp(BfToken token) { switch (token) @@ -1941,7 +1939,7 @@ BfAssignmentOp Beefy::BfTokenToAssignmentOp(BfToken token) case BfToken_MinusEquals: return BfAssignmentOp_Subtract; case BfToken_MultiplyEquals: - return BfAssignmentOp_Multiply; + return BfAssignmentOp_Multiply; case BfToken_AndPlusEquals: return BfAssignmentOp_OverflowAdd; case BfToken_AndMinusEquals: @@ -2143,4 +2141,4 @@ String BfInlineAsmInstruction::AsmInst::ToString() } return s; -} +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfAst.h b/IDEHelper/Compiler/BfAst.h index 0522edd1..ec526882 100644 --- a/IDEHelper/Compiler/BfAst.h +++ b/IDEHelper/Compiler/BfAst.h @@ -53,7 +53,7 @@ class BfPassInstance; enum BfProtection : uint8 { BfProtection_Hidden, - BfProtection_Private, + BfProtection_Private, BfProtection_Internal, BfProtection_Protected, BfProtection_ProtectedInternal, @@ -70,7 +70,7 @@ enum BfCheckedKind : int8 }; static bool CheckProtection(BfProtection protection, bool allowProtected, bool allowPrivate) -{ +{ return (protection == BfProtection_Public) || ((protection == BfProtection_Protected) && (allowProtected)) || ((protection == BfProtection_Private) && (allowPrivate)); @@ -92,10 +92,10 @@ struct BfVariant int64 mInt64; uint64 mUInt64; float mSingle; - double mDouble; + double mDouble; String* mString; void* mPtr; - }; + }; double ToDouble() { if (mTypeCode == BfTypeCode_Double) @@ -145,15 +145,15 @@ enum BfToken : uint8 BfToken_Explicit, BfToken_Extern, BfToken_Extension, - BfToken_Fallthrough, + BfToken_Fallthrough, BfToken_Finally, BfToken_Fixed, BfToken_For, BfToken_Function, BfToken_Goto, - BfToken_If, + BfToken_If, BfToken_Implicit, - BfToken_In, + BfToken_In, BfToken_Inline, BfToken_Interface, BfToken_Internal, @@ -164,14 +164,14 @@ enum BfToken : uint8 BfToken_Mut, BfToken_NameOf, BfToken_Namespace, - BfToken_New, + BfToken_New, BfToken_Null, BfToken_Nullable, BfToken_OffsetOf, BfToken_Operator, BfToken_Out, BfToken_Override, - BfToken_Params, + BfToken_Params, BfToken_Private, BfToken_Protected, BfToken_Public, @@ -179,10 +179,10 @@ enum BfToken : uint8 BfToken_Repeat, BfToken_Ref, BfToken_RetType, - BfToken_Return, + BfToken_Return, BfToken_Scope, BfToken_Sealed, - BfToken_SizeOf, + BfToken_SizeOf, BfToken_Stack, BfToken_Static, BfToken_StrideOf, @@ -200,10 +200,10 @@ enum BfToken : uint8 BfToken_Virtual, BfToken_Volatile, BfToken_When, - BfToken_Where, - BfToken_While, + BfToken_Where, + BfToken_While, BfToken_Yield, - BfToken_AssignEquals, + BfToken_AssignEquals, BfToken_CompareEquals, BfToken_CompareStrictEquals, BfToken_CompareNotEquals, @@ -238,7 +238,7 @@ enum BfToken : uint8 BfToken_RChevron, BfToken_LDblChevron, BfToken_RDblChevron, - BfToken_Semicolon, + BfToken_Semicolon, BfToken_Colon, BfToken_Comma, BfToken_Dot, @@ -251,9 +251,9 @@ enum BfToken : uint8 BfToken_Plus, BfToken_Minus, BfToken_DblPlus, - BfToken_DblMinus, + BfToken_DblMinus, BfToken_Star, - BfToken_ForwardSlash, + BfToken_ForwardSlash, BfToken_Modulus, BfToken_Ampersand, BfToken_At, @@ -409,7 +409,7 @@ public: bool mCapturingChildRef; BfAstNode** mCurChildRef; -public: +public: void VisitMembers(BfBlock* node); void VisitChildNoRef(BfAstNode* nodeRef); void DoVisitChild(BfAstNode*& nodeRef); @@ -430,7 +430,7 @@ public: } nodeRef->Accept(this); mCurChildRef = NULL; - } + } template void VisitChildNoRef(const T& nodeRef) { @@ -442,7 +442,7 @@ public: public: BfStructuralVisitor(); - virtual void Visit(BfAstNode* bfAstNode) {} + virtual void Visit(BfAstNode* bfAstNode) {} virtual void Visit(BfErrorNode* bfErrorNode); virtual void Visit(BfScopeNode* scopeNode); virtual void Visit(BfNewNode* newNode); @@ -450,7 +450,7 @@ public: virtual void Visit(BfExpression* expr); virtual void Visit(BfExpressionStatement* exprStmt); virtual void Visit(BfNamedExpression* namedExpr); - virtual void Visit(BfAttributedExpression* attribExpr); + virtual void Visit(BfAttributedExpression* attribExpr); virtual void Visit(BfStatement* stmt); virtual void Visit(BfAttributedStatement* attribStmt); virtual void Visit(BfLabelableStatement* labelableStmt); @@ -467,21 +467,21 @@ public: virtual void Visit(BfGenericConstraintsDeclaration* genericConstraints); virtual void Visit(BfGenericArgumentsNode* genericArgumentsNode); - virtual void Visit(BfEmptyStatement* emptyStmt); - virtual void Visit(BfTokenNode* tokenNode); - virtual void Visit(BfTokenPairNode* tokenPairNode); + virtual void Visit(BfEmptyStatement* emptyStmt); + virtual void Visit(BfTokenNode* tokenNode); + virtual void Visit(BfTokenPairNode* tokenPairNode); virtual void Visit(BfUsingSpecifierNode* usingSpecifier); virtual void Visit(BfLiteralExpression* literalExpr); virtual void Visit(BfStringInterpolationExpression* stringInterpolationExpression); virtual void Visit(BfIdentifierNode* identifierNode); virtual void Visit(BfAttributedIdentifierNode* attrIdentifierNode); - virtual void Visit(BfQualifiedNameNode* nameNode); + virtual void Visit(BfQualifiedNameNode* nameNode); virtual void Visit(BfThisExpression* thisExpr); virtual void Visit(BfBaseExpression* baseExpr); virtual void Visit(BfMixinExpression* thisExpr); virtual void Visit(BfSizedArrayCreateExpression* createExpr); virtual void Visit(BfInitializerExpression* collectionInitExpr); - virtual void Visit(BfCollectionInitializerExpression* collectionInitExpr); + virtual void Visit(BfCollectionInitializerExpression* collectionInitExpr); virtual void Visit(BfTypeReference* typeRef); virtual void Visit(BfNamedTypeReference* typeRef); virtual void Visit(BfQualifiedTypeReference* qualifiedType); @@ -496,18 +496,18 @@ public: virtual void Visit(BfArrayTypeRef* typeRef); virtual void Visit(BfGenericInstanceTypeRef* typeRef); virtual void Visit(BfTupleTypeRef* typeRef); - virtual void Visit(BfDelegateTypeRef* typeRef); + virtual void Visit(BfDelegateTypeRef* typeRef); virtual void Visit(BfExprModTypeRef* declTypeRef); virtual void Visit(BfPointerTypeRef* typeRef); virtual void Visit(BfNullableTypeRef* typeRef); - virtual void Visit(BfVariableDeclaration* varDecl); + virtual void Visit(BfVariableDeclaration* varDecl); virtual void Visit(BfLocalMethodDeclaration* methodDecl); - virtual void Visit(BfParameterDeclaration* paramDecl); + virtual void Visit(BfParameterDeclaration* paramDecl); virtual void Visit(BfTypeAttrExpression* typeAttrExpr); virtual void Visit(BfTypeOfExpression* typeOfExpr); - virtual void Visit(BfSizeOfExpression* sizeOfExpr); + virtual void Visit(BfSizeOfExpression* sizeOfExpr); virtual void Visit(BfAlignOfExpression* alignOfExpr); - virtual void Visit(BfStrideOfExpression* strideOfExpr); + virtual void Visit(BfStrideOfExpression* strideOfExpr); virtual void Visit(BfOffsetOfExpression* offsetOfExpr); virtual void Visit(BfNameOfExpression* nameOfExpr); virtual void Visit(BfIsConstExpression* isConstExpr); @@ -519,9 +519,9 @@ public: virtual void Visit(BfDelegateBindExpression* delegateBindExpr); virtual void Visit(BfLambdaBindExpression* lambdaBindExpr); virtual void Visit(BfObjectCreateExpression* objCreateExpr); - virtual void Visit(BfBoxExpression* boxExpr); + virtual void Visit(BfBoxExpression* boxExpr); virtual void Visit(BfScopedInvocationTarget* scopedTarget); - virtual void Visit(BfInvocationExpression* invocationExpr); + virtual void Visit(BfInvocationExpression* invocationExpr); virtual void Visit(BfEnumCaseBindExpression* caseBindExpr); virtual void Visit(BfCaseExpression* caseExpr); virtual void Visit(BfSwitchCase* switchCase); @@ -534,7 +534,7 @@ public: virtual void Visit(BfUncheckedStatement* uncheckedStmt); virtual void Visit(BfIfStatement* ifStmt); virtual void Visit(BfThrowStatement* throwStmt); - virtual void Visit(BfDeleteStatement* deleteStmt); + virtual void Visit(BfDeleteStatement* deleteStmt); virtual void Visit(BfReturnStatement* returnStmt); virtual void Visit(BfYieldStatement* returnStmt); virtual void Visit(BfBreakStatement* breakStmt); @@ -543,7 +543,7 @@ public: virtual void Visit(BfUsingStatement* whileStmt); virtual void Visit(BfDoStatement* whileStmt); virtual void Visit(BfRepeatStatement* repeatStmt); - virtual void Visit(BfWhileStatement* whileStmt); + virtual void Visit(BfWhileStatement* whileStmt); virtual void Visit(BfForStatement* forStmt); virtual void Visit(BfForEachStatement* forEachStmt); virtual void Visit(BfDeferStatement* deferStmt); @@ -595,14 +595,14 @@ enum BfTypedValueKind BfTypedValueKind_ReadOnlyBaseAddr, BfTypedValueKind_Value, - BfTypedValueKind_ThisValue, - BfTypedValueKind_BaseValue, - BfTypedValueKind_ReadOnlyThisValue, + BfTypedValueKind_ThisValue, + BfTypedValueKind_BaseValue, + BfTypedValueKind_ReadOnlyThisValue, BfTypedValueKind_ReadOnlyBaseValue, BfTypedValueKind_MutableValue, // Only applicable for generic params BfTypedValueKind_SplatHead, BfTypedValueKind_ThisSplatHead, - BfTypedValueKind_BaseSplatHead, + BfTypedValueKind_BaseSplatHead, BfTypedValueKind_SplatHead_NeedsCasting, BfTypedValueKind_ParamsSplat, BfTypedValueKind_Params, @@ -618,11 +618,11 @@ public: //llvm::Value* mValue; BfIRValue mValue; BfType* mType; - BfTypedValueKind mKind; // Is address of variable + BfTypedValueKind mKind; // Is address of variable public: BfTypedValue() - { + { mType = NULL; mKind = BfTypedValueKind_NoValue; } @@ -643,7 +643,7 @@ public: { BF_ASSERT((!val) || (resolvedType != NULL)); mValue = val; - mType = resolvedType; + mType = resolvedType; mKind = isAddr ? BfTypedValueKind_Addr : BfTypedValueKind_Value; #ifdef _DEBUG //DbgCheckType(); @@ -661,7 +661,7 @@ public: } BfTypedValue(BfIRValue val, BfType* resolvedType, BfTypedValueKind kind = BfTypedValueKind_Value) - { + { BF_ASSERT((!val) || (resolvedType != NULL)); mValue = val; mType = resolvedType; @@ -733,13 +733,13 @@ public: bool IsThis() const { - return (mKind == BfTypedValueKind_ThisValue) || (mKind == BfTypedValueKind_ThisAddr) || (mKind == BfTypedValueKind_ReadOnlyThisValue) || + return (mKind == BfTypedValueKind_ThisValue) || (mKind == BfTypedValueKind_ThisAddr) || (mKind == BfTypedValueKind_ReadOnlyThisValue) || (mKind == BfTypedValueKind_ReadOnlyThisAddr) || (mKind == BfTypedValueKind_ThisSplatHead); } bool IsBase() const { - return (mKind == BfTypedValueKind_BaseValue) || (mKind == BfTypedValueKind_BaseAddr) || (mKind == BfTypedValueKind_ReadOnlyBaseValue) || + return (mKind == BfTypedValueKind_BaseValue) || (mKind == BfTypedValueKind_BaseAddr) || (mKind == BfTypedValueKind_ReadOnlyBaseValue) || (mKind == BfTypedValueKind_ReadOnlyBaseAddr) || (mKind == BfTypedValueKind_BaseSplatHead); } @@ -764,7 +764,7 @@ public: { return (mKind >= BfTypedValueKind_SplatHead) && (mKind <= BfTypedValueKind_ParamsSplat); } - + bool IsUntypedValue() const { return (mKind == BfTypedValueKind_UntypedValue); @@ -1005,7 +1005,7 @@ public: } ~BfDeferredSizedArray() - { + { mSizedArray->mSize = (int)this->size(); if (mSizedArray->mSize > 0) { @@ -1023,7 +1023,7 @@ public: template static void BfSizedArrayInitIndirect(BfSizedArray& sizedArray, const SizedArrayImpl& vec, BfAstAllocator* alloc) -{ +{ sizedArray.mSize = (int)vec.size(); BF_ASSERT(sizedArray.mSize >= 0); if (sizedArray.mSize > 0) @@ -1031,26 +1031,26 @@ static void BfSizedArrayInitIndirect(BfSizedArray& sizedArray, const SizedArr sizedArray.mVals = (T*)alloc->AllocBytes(sizedArray.mSize * sizeof(T), sizeof(T)); for (int i = 0; i < sizedArray.mSize; i++) sizedArray.mVals[i] = vec[i]; - } + } } template class BfDeferredAstSizedArray : public SizedArray { -public: +public: BfSizedArray* mSizedArray; BfAstAllocator* mAlloc; public: BfDeferredAstSizedArray(BfSizedArray& arr, BfAstAllocator* alloc) - { + { mSizedArray = &arr; - mAlloc = alloc; + mAlloc = alloc; } ~BfDeferredAstSizedArray() - { - BfSizedArrayInitIndirect(*mSizedArray, *this, mAlloc); + { + BfSizedArrayInitIndirect(*mSizedArray, *this, mAlloc); } }; @@ -1086,38 +1086,38 @@ struct BfAstInfo class BfAstNode { public: - static BfAstTypeInfo sTypeInfo; - + static BfAstTypeInfo sTypeInfo; + #ifndef BF_AST_ALLOCATOR_USE_PAGES BfSourceData* mSourceData; #endif #ifdef BF_AST_HAS_PARENT_MEMBER - BfAstNode* mParent; + BfAstNode* mParent; #endif #ifdef BF_AST_COMPACT union { struct - { + { uint8 mCompact_TriviaLen; uint8 mCompact_SrcLen; uint8 mCompact_TypeId; BfToken mCompact_Token; int mCompact_SrcStart : 31; - int mIsCompact : 1; + int mIsCompact : 1; }; BfAstInfo* mAstInfo; }; #else int mTriviaStart; int mSrcStart; - int mSrcEnd; + int mSrcEnd; uint8 mTypeId; BfToken mToken; #endif -public: +public: BfAstNode() { #ifdef BF_AST_COMPACT @@ -1137,7 +1137,7 @@ public: { } #endif - + void RemoveSelf(); void DeleteSelf(); void RemoveNextSibling(); @@ -1165,16 +1165,16 @@ public: bool IsMissingSemicolon(); bool IsExpression(); bool WantsWarning(int warningNumber); - + template bool IsA() - { - return (uint)GetTypeId() - (uint)T::sTypeInfo.mTypeId <= (uint)T::sTypeInfo.mFullDerivedCount; + { + return (uint)GetTypeId() - (uint)T::sTypeInfo.mTypeId <= (uint)T::sTypeInfo.mFullDerivedCount; } template bool IsExact() - { + { return (uint)GetTypeId() == (uint)T::sTypeInfo.mTypeId; } @@ -1182,7 +1182,7 @@ public: BfAstInfo* AllocAstInfo(); void InitEmpty() - { + { mIsCompact = true; mCompact_SrcStart = 0; mCompact_SrcLen = 0; @@ -1218,7 +1218,7 @@ public: { int triviaLen = srcStart - triviaStart; int srcLen = srcEnd - srcStart; - if ((triviaLen <= 255) && (srcLen <= 255)) + if ((triviaLen <= 255) && (srcLen <= 255)) { mCompact_SrcStart = srcStart; mIsCompact = 1; @@ -1234,8 +1234,8 @@ public: astInfo->mSrcStart = srcStart; astInfo->mSrcEnd = srcEnd; mAstInfo = astInfo; - } - } + } + } int GetTypeId() { @@ -1277,7 +1277,7 @@ public: mCompact_TriviaLen = (uint8)triviaLen; return; } - + auto astInfo = AllocAstInfo(); astInfo->mTypeId = mCompact_TypeId; astInfo->mToken = mCompact_Token; @@ -1285,7 +1285,7 @@ public: astInfo->mSrcEnd = mCompact_SrcStart + mCompact_SrcLen; mAstInfo = astInfo; } - + mAstInfo->mTriviaStart = triviaStart; } @@ -1318,7 +1318,7 @@ public: astInfo->mTriviaStart = srcStart - triviaLen; astInfo->mSrcEnd = srcStart + srcLen; mAstInfo = astInfo; - } + } } else mAstInfo->mSrcStart = srcStart; @@ -1377,7 +1377,7 @@ public: { mTriviaStart = 0; mSrcStart = 0; - mSrcEnd = 0; + mSrcEnd = 0; } void InitWithTypeId(int typeId) @@ -1477,7 +1477,6 @@ public: } #endif - #ifdef BF_AST_HAS_PARENT_MEMBER template T* FindParentOfType() @@ -1517,13 +1516,13 @@ public: template static void Zero(T* val) - { + { #ifdef BF_AST_COMPACT memset((uint8*)val + offsetof(T, mAstInfo), 0, sizeof(T) - offsetof(T, mAstInfo)); #else memset((uint8*)val + offsetof(T, mTriviaStart), 0, sizeof(T) - offsetof(T, mTriviaStart)); #endif - val->InitWithTypeId(T::sTypeInfo.mTypeId); + val->InitWithTypeId(T::sTypeInfo.mTypeId); } #endif }; @@ -1532,11 +1531,11 @@ BfAstTypeInfo BfAstNode::sTypeInfo("BfAstNode", NULL, &BfAstNode::ClassAccept); #endif template -bool BfNodeIsA(BfAstNode* node) -{ +bool BfNodeIsA(BfAstNode* node) +{ if (node == NULL) return false; - + bool canCast = (uint)node->GetTypeId() - (uint)T::sTypeInfo.mTypeId <= (uint)T::sTypeInfo.mFullDerivedCount; return canCast; } @@ -1555,8 +1554,8 @@ template T* BfNodeDynCast(BfAstNode* node) { if (node == NULL) - return NULL; - + return NULL; + bool canCast = (uint)node->GetTypeId() - (uint)T::sTypeInfo.mTypeId <= (uint)T::sTypeInfo.mFullDerivedCount; //BF_ASSERT(canCast == (node->DynCast(T::TypeId) != NULL)); return canCast ? (T*)node : NULL; @@ -1567,7 +1566,7 @@ T* BfNodeDynCastExact(BfAstNode* node) { if (node == NULL) return NULL; - + bool canCast = node->GetTypeId() == T::sTypeInfo.mTypeId; //BF_ASSERT(canCast == (node->GetTypeId() == T::TypeId)); return canCast ? (T*)node : NULL; @@ -1706,12 +1705,12 @@ public: } bool operator!=(const Iterator& itr) const - { + { return itr.mPtr != mPtr; } bool operator==(const Iterator& itr) const - { + { return itr.mPtr == mPtr; } @@ -1741,7 +1740,7 @@ public: //BfDebugArray mChildArr; BfSizedArray mChildArr; -public: +public: using BfAstNode::Init; void Init(const SizedArrayImpl& vec, BfAstAllocator* alloc); BfAstNode* GetFirst(); @@ -1773,7 +1772,7 @@ public: BfBlockExtension* blockExt = (BfBlockExtension*)(BfAstNode*)childArr->mVals[childArr->mSize - 1]; BF_ASSERT(blockExt->GetTypeId() == BfBlockExtension::TypeId); childArr = &blockExt->mChildArr; - } + } #else return mChildArr.mVals[idx]; #endif @@ -1810,7 +1809,7 @@ public: mTypedValue = typedValue; mRefNode = NULL; #ifdef BF_AST_HAS_PARENT_MEMBER - mParent = NULL; + mParent = NULL; #endif } }; BF_AST_DECL(BfTypedValueExpression, BfExpression); @@ -1930,7 +1929,7 @@ enum BfUnaryOp class BfTokenNode : public BfAstNode { public: - BF_AST_TYPE(BfTokenNode, BfAstNode); + BF_AST_TYPE(BfTokenNode, BfAstNode); }; BF_AST_DECL(BfTokenNode, BfAstNode); class BfScopeNode : public BfAstNode @@ -1950,7 +1949,7 @@ public: BF_AST_TYPE(BfNewNode, BfAstNode); BfTokenNode* mNewToken; - BfTokenNode* mColonToken; + BfTokenNode* mColonToken; BfAstNode* mAllocNode; // Expression or BfScopedInvocationTarget BfAttributeDirective* mAttributes; }; BF_AST_DECL(BfNewNode, BfAstNode); @@ -1962,7 +1961,7 @@ enum BfCommentKind BfCommentKind_Documentation_Block_Pre, BfCommentKind_Documentation_Line_Pre, BfCommentKind_Documentation_Block_Post, - BfCommentKind_Documentation_Line_Post, + BfCommentKind_Documentation_Line_Post, }; class BfCommentNode : public BfAstNode @@ -1995,15 +1994,15 @@ public: BF_AST_TYPE(BfPreprocessorNode, BfAstNode); BfIdentifierNode* mCommand; - BfBlock* mArgument; + BfBlock* mArgument; }; BF_AST_DECL(BfPreprocessorNode, BfAstNode); class BfPreprocessorDefinedExpression : public BfExpression -{ +{ public: BF_AST_TYPE(BfPreprocessorDefinedExpression, BfExpression); - BfIdentifierNode* mIdentifier; + BfIdentifierNode* mIdentifier; }; BF_AST_DECL(BfPreprocessorDefinedExpression, BfExpression); class BfReplaceNode : public BfAstNode @@ -2025,7 +2024,7 @@ public: BF_AST_TYPE(BfAttributedIdentifierNode, BfExpression); BfIdentifierNode* mIdentifier; - BfAttributeDirective* mAttributes; + BfAttributeDirective* mAttributes; }; BF_AST_DECL(BfAttributedIdentifierNode, BfExpression); class BfQualifiedNameNode : public BfIdentifierNode @@ -2043,8 +2042,8 @@ class BfUsingDirective : public BfStatement public: BF_AST_TYPE(BfUsingDirective, BfStatement); - BfTokenNode* mUsingToken; - BfIdentifierNode* mNamespace; + BfTokenNode* mUsingToken; + BfIdentifierNode* mNamespace; }; BF_AST_DECL(BfUsingDirective, BfStatement); class BfUsingModDirective : public BfStatement @@ -2068,7 +2067,7 @@ public: class BfAttributeDirective : public BfAstNode { -public: +public: BF_AST_TYPE(BfAttributeDirective, BfAstNode); ASTREF(BfTokenNode*) mAttrOpenToken; // [ @ , @@ -2225,7 +2224,7 @@ public: BfTokenNode* mOpenBrace; BfSizedArray mValues; BfSizedArray mCommas; - BfTokenNode* mCloseBrace; + BfTokenNode* mCloseBrace; }; BF_AST_DECL(BfCollectionInitializerExpression, BfExpression); class BfSizedArrayCreateExpression : public BfExpression @@ -2262,7 +2261,7 @@ public: BF_AST_TYPE(BfTupleExpression, BfExpression); BfTokenNode* mOpenParen; - BfSizedArray mNames; + BfSizedArray mNames; BfSizedArray mValues; BfSizedArray mCommas; ASTREF(BfTokenNode*) mCloseParen; @@ -2306,7 +2305,7 @@ public: BfTokenNode* mCaseToken; BfSizedArray mCaseExpressions; BfSizedArray mCaseCommas; - BfTokenNode* mColonToken; + BfTokenNode* mColonToken; BfBlock* mCodeBlock; // May or may not have braces set BfTokenNode* mEndingToken; // Null, Fallthrough, or Break BfTokenNode* mEndingSemicolonToken; @@ -2363,14 +2362,14 @@ public: BfCommentNode* mDocumentation; BfAttributeDirective* mAttributes; - BfTokenNode* mAbstractSpecifier; - BfTokenNode* mSealedSpecifier; + BfTokenNode* mAbstractSpecifier; + BfTokenNode* mSealedSpecifier; BfAstNode* mProtectionSpecifier; BfTokenNode* mStaticSpecifier; BfTokenNode* mPartialSpecifier; BfTokenNode* mTypeNode; - BfIdentifierNode* mNameNode; - BfAstNode* mDefineNode; + BfIdentifierNode* mNameNode; + BfAstNode* mDefineNode; BfAutoConstructorDeclaration* mAutoCtor; BfGenericParamsDeclaration* mGenericParams; BfGenericConstraintsDeclaration* mGenericConstraintsDeclaration; @@ -2379,7 +2378,6 @@ public: BfTokenNode* mColonToken; BfSizedArray mBaseClasses; BfSizedArray mBaseClassCommas; - }; BF_AST_DECL(BfTypeDeclaration, BfAstNode); class BfTypeAliasDeclaration : public BfTypeDeclaration @@ -2390,32 +2388,29 @@ public: BfTokenNode* mEqualsToken; BfTypeReference* mAliasToType; BfTokenNode* mEndSemicolon; - }; BF_AST_DECL(BfTypeAliasDeclaration, BfTypeDeclaration); class BfTypeReference : public BfAstNode { public: - BF_AST_TYPE(BfTypeReference, BfAstNode); + BF_AST_TYPE(BfTypeReference, BfAstNode); bool IsNamedTypeReference(); bool IsTypeDefTypeReference(); String ToCleanAttributeString(); - }; BF_AST_DECL(BfTypeReference, BfAstNode); class BfDirectTypeReference : public BfTypeReference { public: - BF_AST_TYPE(BfDirectTypeReference, BfAstNode); + BF_AST_TYPE(BfDirectTypeReference, BfAstNode); BfType* mType; void Init(BfType* type) { mType = type; InitEmpty(); - } - + } }; BF_AST_DECL(BfDirectTypeReference, BfAstNode); class BfDirectTypeDefReference : public BfTypeReference @@ -2429,14 +2424,13 @@ public: mTypeDef = type; InitEmpty(); } - }; BF_AST_DECL(BfDirectTypeDefReference, BfTypeReference); // class BfTypeDefTypeReference : public BfTypeReference // { // public: // BF_AST_TYPE(BfTypeDefTypeReference, BfTypeReference); -// +// // BfTypeDef* mTypeDef; // }; BF_AST_DECL(BfTypeDefTypeReference, BfTypeReference); @@ -2456,8 +2450,8 @@ public: mParent = NULL; #endif InitEmpty(); - //mTypeDef = NULL; - } + //mTypeDef = NULL; + } }; BF_AST_DECL(BfDirectStrTypeReference, BfTypeReference); class BfDotTypeReference : public BfTypeReference @@ -2578,7 +2572,7 @@ public: BF_AST_TYPE(BfGenericInstanceTypeRef, BfElementedTypeRef); BfTokenNode* mOpenChevron; - BfSizedArray mGenericArguments; + BfSizedArray mGenericArguments; BfSizedArray mCommas; BfTokenNode* mCloseChevron; int GetGenericArgCount() @@ -2634,7 +2628,7 @@ public: }; BF_AST_DECL(BfExprModTypeRef, BfTypeReference); enum BfGenericParamKind -{ +{ BfGenericParamKind_Type, BfGenericParamKind_Method }; @@ -2652,7 +2646,7 @@ class BfPointerTypeRef : public BfElementedTypeRef { public: BF_AST_TYPE(BfPointerTypeRef, BfElementedTypeRef); - + BfTokenNode* mStarNode; }; BF_AST_DECL(BfPointerTypeRef, BfElementedTypeRef); @@ -2711,7 +2705,7 @@ public: class BfAlignOfExpression : public BfTypeAttrExpression { public: - BF_AST_TYPE(BfAlignOfExpression, BfTypeAttrExpression); + BF_AST_TYPE(BfAlignOfExpression, BfTypeAttrExpression); }; BF_AST_DECL(BfAlignOfExpression, BfTypeAttrExpression); class BfStrideOfExpression : public BfTypeAttrExpression @@ -2720,7 +2714,6 @@ public: BF_AST_TYPE(BfStrideOfExpression, BfTypeAttrExpression); }; BF_AST_DECL(BfStrideOfExpression, BfTypeAttrExpression); - class BfOffsetOfExpression : public BfTypeAttrExpression { public: @@ -2733,7 +2726,7 @@ public: class BfNameOfExpression : public BfExpression { public: - BF_AST_TYPE(BfNameOfExpression, BfExpression); + BF_AST_TYPE(BfNameOfExpression, BfExpression); BfTokenNode* mToken; BfTokenNode* mOpenParen; BfAstNode* mTarget; @@ -2787,17 +2780,17 @@ public: BfExpression* mTarget; BfTokenNode* mAsToken; - BfTypeReference* mTypeRef; + BfTypeReference* mTypeRef; }; BF_AST_DECL(BfDynamicCastExpression, BfExpression); class BfCastExpression : public BfUnaryOperatorExpression { public: BF_AST_TYPE(BfCastExpression, BfUnaryOperatorExpression); - + BfTokenNode* mOpenParen; BfTypeReference* mTypeRef; - BfTokenNode* mCloseParen; + BfTokenNode* mCloseParen; }; BF_AST_DECL(BfCastExpression, BfUnaryOperatorExpression); class BfDelegateBindExpression : public BfMethodBoundExpression @@ -2816,12 +2809,12 @@ class BfLambdaBindExpression : public BfExpression public: BF_AST_TYPE(BfLambdaBindExpression, BfExpression); - BfAstNode* mNewToken; + BfAstNode* mNewToken; BfTokenNode* mOpenParen; - BfTokenNode* mCloseParen; + BfTokenNode* mCloseParen; BfSizedArray mParams; BfSizedArray mCommas; - BfTokenNode* mFatArrowToken; + BfTokenNode* mFatArrowToken; BfAstNode* mBody; // Either expression or block BfFieldDtorDeclaration* mDtor; }; BF_AST_DECL(BfLambdaBindExpression, BfExpression); @@ -2861,11 +2854,11 @@ public: BfAstNode* mNewNode; BfTokenNode* mStarToken; - BfTypeReference* mTypeRef; + BfTypeReference* mTypeRef; BfTokenNode* mOpenToken; - BfTokenNode* mCloseToken; + BfTokenNode* mCloseToken; BfSizedArray mArguments; - BfSizedArray mCommas; + BfSizedArray mCommas; }; BF_AST_DECL(BfObjectCreateExpression, BfMethodBoundExpression); class BfBoxExpression : public BfExpression @@ -2883,7 +2876,7 @@ class BfDeleteStatement : public BfStatement public: BF_AST_TYPE(BfDeleteStatement, BfStatement); - BfTokenNode* mDeleteToken; + BfTokenNode* mDeleteToken; BfTokenNode* mTargetTypeToken; // colon token BfAstNode* mAllocExpr; BfAttributeDirective* mAttributes; @@ -2894,11 +2887,11 @@ class BfDeferBindNode : public BfAstNode { public: BF_AST_TYPE(BfDeferBindNode, BfAstNode); - + BfTokenNode* mOpenBracket; BfTokenNode* mCloseBracket; BfSizedArray mParams; - BfSizedArray mCommas; + BfSizedArray mCommas; }; BF_AST_DECL(BfDeferBindNode, BfAstNode); class BfDeferStatement : public BfStatement @@ -2954,7 +2947,7 @@ public: ASTREF(BfTokenNode*) mCloseParen; ASTREF(BfGenericArgumentsNode*) mGenericArgs; BfSizedArray mArguments; - BfSizedArray mCommas; + BfSizedArray mCommas; }; BF_AST_DECL(BfInvocationExpression, BfMethodBoundExpression); class BfEnumCaseDeclaration : public BfAstNode @@ -2964,7 +2957,7 @@ public: ASTREF(BfTokenNode*) mCaseToken; BfSizedArray mEntries; - BfSizedArray mCommas; + BfSizedArray mCommas; }; BF_AST_DECL(BfEnumCaseDeclaration, BfAstNode); class BfMemberDeclaration : public BfAstNode @@ -2972,9 +2965,9 @@ class BfMemberDeclaration : public BfAstNode public: BF_AST_TYPE(BfMemberDeclaration, BfAstNode); - BfAttributeDirective* mAttributes; + BfAttributeDirective* mAttributes; BfAstNode* mProtectionSpecifier; - BfTokenNode* mStaticSpecifier; + BfTokenNode* mStaticSpecifier; BfTokenNode* mReadOnlySpecifier; // Also stores 'inline' }; BF_AST_DECL(BfMemberDeclaration, BfAstNode); @@ -2989,7 +2982,7 @@ public: ASTREF(BfTokenNode*) mPrecedingComma; BfAstNode* mNameNode; // Either BfIdentifierNode or BfTupleExpression ASTREF(BfTokenNode*) mEqualsNode; - ASTREF(BfExpression*) mInitializer; + ASTREF(BfExpression*) mInitializer; }; BF_AST_DECL(BfVariableDeclaration, BfExpression); class BfLocalMethodDeclaration : public BfCompoundStatement @@ -3042,7 +3035,7 @@ class BfGenericOperatorConstraint : public BfAstNode { public: BF_AST_TYPE(BfGenericOperatorConstraint, BfAstNode); - + BfTokenNode* mOperatorToken; BfTypeReference* mLeftType; BfTokenNode* mOpToken; @@ -3058,7 +3051,7 @@ public: BfTypeReference* mTypeRef; BfTokenNode* mColonToken; BfSizedArray mConstraintTypes; - BfSizedArray mCommas; + BfSizedArray mCommas; }; BF_AST_DECL(BfGenericConstraint, BfAstNode); class BfGenericConstraintExpression : public BfAstNode @@ -3082,8 +3075,8 @@ class BfMethodDeclaration : public BfMemberDeclaration { public: BF_AST_TYPE(BfMethodDeclaration, BfMemberDeclaration); - - BfCommentNode* mDocumentation; + + BfCommentNode* mDocumentation; BfTokenNode* mExternSpecifier; BfTokenNode* mVirtualSpecifier; // either 'virtual', 'override', or 'abstract' BfTokenNode* mNewSpecifier; @@ -3093,7 +3086,7 @@ public: BfTypeReference* mReturnType; BfTypeReference* mExplicitInterface; BfTokenNode* mExplicitInterfaceDotToken; - BfIdentifierNode* mNameNode; + BfIdentifierNode* mNameNode; BfTokenNode* mOpenParen; BfTokenNode* mThisToken; BfSizedArray mParams; @@ -3103,7 +3096,7 @@ public: BfGenericConstraintsDeclaration* mGenericConstraintsDeclaration; BfAstNode* mEndSemicolon; BfTokenNode* mFatArrowToken; - BfAstNode* mBody; // Either expression or block + BfAstNode* mBody; // Either expression or block //BfMethodDef* mMethodDef; @@ -3114,13 +3107,13 @@ class BfOperatorDeclaration : public BfMethodDeclaration { public: BF_AST_TYPE(BfOperatorDeclaration, BfMethodDeclaration); - + BfTokenNode* mExplicitToken; // Explicit or Implicit BfTokenNode* mOperatorToken; BfTokenNode* mOpTypeToken; bool mIsConvOperator; BfUnaryOp mUnaryOp; - BfBinaryOp mBinOp; + BfBinaryOp mBinOp; BfAssignmentOp mAssignOp; }; BF_AST_DECL(BfOperatorDeclaration, BfMethodDeclaration); @@ -3130,10 +3123,9 @@ public: BF_AST_TYPE(BfConstructorDeclaration, BfMethodDeclaration); BfTokenNode* mThisToken; - + BfTokenNode* mInitializerColonToken; BfExpression* mInitializer; - }; BF_AST_DECL(BfConstructorDeclaration, BfMethodDeclaration); class BfAutoConstructorDeclaration : public BfConstructorDeclaration @@ -3144,7 +3136,7 @@ public: class BfDestructorDeclaration : public BfMethodDeclaration { -public: +public: BF_AST_TYPE(BfDestructorDeclaration, BfMethodDeclaration); BfTokenNode* mTildeToken; @@ -3175,10 +3167,10 @@ class BfFieldDeclaration : public BfMemberDeclaration { public: BF_AST_TYPE(BfFieldDeclaration, BfMemberDeclaration); - + BfCommentNode* mDocumentation; BfTokenNode* mPrecedingComma; - BfAstNode* mConstSpecifier; // Could be 'const' or 'using' + BfAstNode* mConstSpecifier; // Could be 'const' or 'using' BfTokenNode* mVolatileSpecifier; BfTokenNode* mNewSpecifier; BfTokenNode* mExternSpecifier; // Could be 'extern' or 'append' @@ -3187,7 +3179,7 @@ public: BfTokenNode* mEqualsNode; BfExpression* mInitializer; BfFieldDtorDeclaration* mFieldDtor; - + BfFieldDef* mFieldDef; }; BF_AST_DECL(BfFieldDeclaration, BfMemberDeclaration); @@ -3195,7 +3187,6 @@ class BfEnumEntryDeclaration : public BfFieldDeclaration { public: BF_AST_TYPE(BfEnumEntryDeclaration, BfFieldDeclaration); - }; BF_AST_DECL(BfEnumEntryDeclaration, BfFieldDeclaration); class BfPropertyMethodDeclaration : public BfAstNode @@ -3206,10 +3197,10 @@ public: BfAttributeDirective* mAttributes; BfAstNode* mProtectionSpecifier; BfTokenNode* mSetRefSpecifier; - BfTokenNode* mMutSpecifier; + BfTokenNode* mMutSpecifier; BfIdentifierNode* mNameNode; BfTokenNode* mFatArrowToken; - BfAstNode* mBody; + BfAstNode* mBody; BfAstNode* mEndSemicolon; }; BF_AST_DECL(BfPropertyMethodDeclaration, BfAstNode); @@ -3218,7 +3209,7 @@ class BfPropertyBodyExpression : public BfAstNode public: BF_AST_TYPE(BfPropertyBodyExpression, BfAstNode); BfTokenNode* mMutSpecifier; - BfTokenNode* mFatTokenArrow; + BfTokenNode* mFatTokenArrow; }; BF_AST_DECL(BfPropertyBodyExpression, BfAstNode); class BfPropertyDeclaration : public BfFieldDeclaration @@ -3228,10 +3219,10 @@ public: BfTokenNode* mVirtualSpecifier; // either 'virtual', 'override', or 'abstract' BfTypeReference* mExplicitInterface; - BfTokenNode* mExplicitInterfaceDotToken; + BfTokenNode* mExplicitInterfaceDotToken; BfAstNode* mDefinitionBlock; - BfSizedArray mMethods; + BfSizedArray mMethods; BfPropertyMethodDeclaration* GetMethod(const StringImpl& name); }; BF_AST_DECL(BfPropertyDeclaration, BfFieldDeclaration); @@ -3360,7 +3351,7 @@ public: BfTokenNode* mUsingToken; BfTokenNode* mOpenParen; - BfVariableDeclaration* mVariableDeclaration; + BfVariableDeclaration* mVariableDeclaration; BfTokenNode* mCloseParen; BfAstNode* mEmbeddedStatement; }; BF_AST_DECL(BfUsingStatement, BfCompoundStatement); @@ -3384,7 +3375,7 @@ public: BfTokenNode* mWhileToken; BfTokenNode* mOpenParen; BfExpression* mCondition; - BfTokenNode* mCloseParen; + BfTokenNode* mCloseParen; }; BF_AST_DECL(BfRepeatStatement, BfLabelableStatement); class BfWhileStatement : public BfLabelableStatement @@ -3463,7 +3454,7 @@ public: String ToString(); }; - + class AsmInst { public: diff --git a/IDEHelper/Compiler/BfAstAllocator.cpp b/IDEHelper/Compiler/BfAstAllocator.cpp index 7b3243c6..2d749c1e 100644 --- a/IDEHelper/Compiler/BfAstAllocator.cpp +++ b/IDEHelper/Compiler/BfAstAllocator.cpp @@ -24,36 +24,35 @@ void BfBitSet::Init(int numBits) memset(mBits, 0, numInts * 4); } - bool BfBitSet::IsSet(int idx) { return (mBits[idx / 32] & (1 << (idx % 32))) != 0; } void BfBitSet::Set(int idx) -{ +{ mBits[idx / 32] |= (1 << (idx % 32)); } void BfBitSet::Clear(int idx) -{ +{ mBits[idx / 32] &= ~(1 << (idx % 32)); } ////////////////////////////////////////////////////////////////////////// BfAstAllocator::BfAstAllocator() -{ +{ mSourceData = NULL; - mCurPtr = NULL; - mCurPageEnd = mCurPtr; + mCurPtr = NULL; + mCurPageEnd = mCurPtr; mLargeAllocSizes = 0; - mNumPagesUsed = 0; + mNumPagesUsed = 0; mUsedSize = 0; } BfAstAllocator::~BfAstAllocator() -{ +{ for (auto addr : mLargeAllocs) delete [] (uint8*)addr; if (mPages.size() != 0) @@ -61,16 +60,16 @@ BfAstAllocator::~BfAstAllocator() } void BfAstAllocator::InitChunkHead(int wantSize) -{ +{ mCurPtr = mSourceData->mAstAllocManager->AllocPage(); mPages.push_back(mCurPtr); mCurPageEnd = mCurPtr + BfAstAllocManager::PAGE_SIZE; mNumPagesUsed++; -#ifdef BF_AST_ALLOCATOR_USE_PAGES +#ifdef BF_AST_ALLOCATOR_USE_PAGES BfAstPageHeader* pageHeader = (BfAstPageHeader*)mCurPtr; pageHeader->mSourceData = mSourceData; BF_ASSERT(sizeof(BfAstPageHeader) <= 16); - mCurPtr += 16; + mCurPtr += 16; #endif } @@ -95,28 +94,28 @@ BfAstAllocManager::~BfAstAllocManager() #endif } -//TODO: Remove this +//TODO: Remove this //static int gAstChunkAllocCount = 0; uint8* BfAstAllocManager::AllocPage() { #ifdef BF_AST_ALLOCATOR_USE_PAGES AutoCrit autoCrit(mCritSect); - if (mFreePageCount != 0) + if (mFreePageCount != 0) { mFreePageCount--; return (uint8*)mFreePages.PopFront(); } - + BF_ASSERT(mFreePages.mHead == NULL); - + //auto newChunk = (uint8*)::VirtualAlloc((void*)(0x4200000000 + gAstChunkAllocCount*CHUNK_SIZE), CHUNK_SIZE, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); //gAstChunkAllocCount++; auto newChunk = (uint8*)::VirtualAlloc(NULL, CHUNK_SIZE, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); BF_ASSERT(newChunk != NULL); - BF_ASSERT(((intptr)newChunk & (PAGE_SIZE - 1)) == 0); - mAllocChunks.push_back(newChunk); + BF_ASSERT(((intptr)newChunk & (PAGE_SIZE - 1)) == 0); + mAllocChunks.push_back(newChunk); //BfLog("BfAstAllocManager alloc %p\n", newChunk); @@ -128,7 +127,7 @@ uint8* BfAstAllocManager::AllocPage() } mFreePageCount--; - return (uint8*)mFreePages.PopFront(); + return (uint8*)mFreePages.PopFront(); #else return new uint8[PAGE_SIZE]; #endif diff --git a/IDEHelper/Compiler/BfAstAllocator.h b/IDEHelper/Compiler/BfAstAllocator.h index 163cdf82..4be75bfe 100644 --- a/IDEHelper/Compiler/BfAstAllocator.h +++ b/IDEHelper/Compiler/BfAstAllocator.h @@ -49,14 +49,13 @@ public: class BfAstPageHeader { public: - BfSourceData* mSourceData; + BfSourceData* mSourceData; }; #endif class BfAstAllocChunk; class BfAstAllocManager; - struct BfAstFreePage { BfAstFreePage* mNext; @@ -75,7 +74,7 @@ public: Array mAllocChunks; #endif -public: +public: BfAstAllocManager(); ~BfAstAllocManager(); @@ -90,7 +89,7 @@ public: // { // int mCount; // int mSize; -// +// // BumpAllocTrackedEntry() // { // mCount = 0; @@ -103,9 +102,9 @@ class BfAstAllocator { public: static const int LARGE_ALLOC_SIZE = 2048; - BfSourceData* mSourceData; - uint8* mCurPtr; - uint8* mCurPageEnd; + BfSourceData* mSourceData; + uint8* mCurPtr; + uint8* mCurPageEnd; Array mLargeAllocs; Array mPages; int mLargeAllocSizes; @@ -117,8 +116,8 @@ public: public: BfAstAllocator(); - ~BfAstAllocator(); - + ~BfAstAllocator(); + void InitChunkHead(int wantSize); int GetAllocSize() const @@ -141,7 +140,7 @@ public: { int alignSize = alignof(T); mCurPtr = (uint8*)(((intptr)mCurPtr + alignSize - 1) & ~(alignSize - 1)); - int wantSize = sizeof(T) + extraBytes; + int wantSize = sizeof(T) + extraBytes; #ifdef BUMPALLOC_TRACKALLOCS const char* name = typeid(T).name(); @@ -152,10 +151,10 @@ public: #endif if (mCurPtr + wantSize >= mCurPageEnd) - InitChunkHead(wantSize); + InitChunkHead(wantSize); memset(mCurPtr, 0, wantSize); - T* retVal = new (mCurPtr) T(); - mCurPtr += wantSize; + T* retVal = new (mCurPtr) T(); + mCurPtr += wantSize; #ifndef BF_AST_ALLOCATOR_USE_PAGES retVal->mSourceData = this->mSourceData; @@ -165,8 +164,8 @@ public: } uint8* AllocBytes(int wantSize, int alignSize, const char* dbgName = "AllocBytes") - { -#ifdef BUMPALLOC_TRACKALLOCS + { +#ifdef BUMPALLOC_TRACKALLOCS BumpAllocTrackedEntry* allocSizePtr; mTrackedAllocs.TryAdd(dbgName, NULL, &allocSizePtr); allocSizePtr->mCount++; @@ -188,13 +187,13 @@ public: InitChunkHead(wantSize); memset(mCurPtr, 0, wantSize); uint8* retVal = mCurPtr; - mCurPtr += wantSize; + mCurPtr += wantSize; return retVal; } uint8* AllocBytes(int wantSize, const char* dbgName = "AllocBytes") { -#ifdef BUMPALLOC_TRACKALLOCS +#ifdef BUMPALLOC_TRACKALLOCS BumpAllocTrackedEntry* allocSizePtr; mTrackedAllocs.TryAdd(dbgName, NULL, &allocSizePtr); allocSizePtr->mCount++; @@ -211,12 +210,10 @@ public: if (mCurPtr + wantSize >= mCurPageEnd) InitChunkHead(wantSize); memset(mCurPtr, 0, wantSize); - uint8* retVal = mCurPtr; + uint8* retVal = mCurPtr; mCurPtr += wantSize; return retVal; } }; NS_BF_END - - diff --git a/IDEHelper/Compiler/BfAutoComplete.cpp b/IDEHelper/Compiler/BfAutoComplete.cpp index 0add68bd..964d9c35 100644 --- a/IDEHelper/Compiler/BfAutoComplete.cpp +++ b/IDEHelper/Compiler/BfAutoComplete.cpp @@ -35,7 +35,7 @@ AutoCompleteBase::~AutoCompleteBase() AutoCompleteEntry* AutoCompleteBase::AddEntry(const AutoCompleteEntry& entry, const StringImpl& filter) { uint8 matches[256]; - + if (!DoesFilterMatch(entry.mDisplay, filter.c_str(), entry.mScore, matches, 256) || (entry.mNamePrefixCount < 0)) return NULL; @@ -43,7 +43,7 @@ AutoCompleteEntry* AutoCompleteBase::AddEntry(const AutoCompleteEntry& entry, co entry.mMatches = (entry.mMatchesLength > 0) ? matches : nullptr; auto result = AddEntry(entry); - + // Reset matches because the array will be invalid after return entry.mMatches = nullptr; entry.mMatchesLength = 0; @@ -82,13 +82,13 @@ AutoCompleteEntry* AutoCompleteBase::AddEntry(const AutoCompleteEntry& entry) { insertedEntry->mEntryType = entry.mEntryType; - const char* display = entry.mDisplay; + const char* display = entry.mDisplay; int size = (int)strlen(display) + 1; insertedEntry->mDisplay = (char*)mAlloc.AllocBytes(size); memcpy((char*)insertedEntry->mDisplay, display, size); if (entry.mMatchesLength > 0) - { + { insertedEntry->mMatches = (uint8*)mAlloc.AllocBytes(insertedEntry->mMatchesLength); memcpy((char*)insertedEntry->mMatches, entry.mMatches, insertedEntry->mMatchesLength); } @@ -105,8 +105,8 @@ bool AutoCompleteBase::DoesFilterMatch(const char* entry, const char* filter, in if (entry[entryLen - 1] == '=') return (strncmp(filter, entry, entryLen - 1) == 0); return (strcmp(filter, entry) == 0); - } - + } + if (!mIsAutoComplete) return false; @@ -176,7 +176,7 @@ bool AutoCompleteBase::DoesFilterMatch(const char* entry, const char* filter, in } void AutoCompleteBase::Clear() -{ +{ //mEntries.clear(); mAlloc.Clear(); mEntriesSet.Clear(); @@ -195,8 +195,8 @@ BfAutoComplete::BfAutoComplete(BfResolveType resolveType, bool doFuzzyAutoComple mHasFriendSet = false; mUncertain = false; mForceAllowNonStatic = false; - mMethodMatchInfo = NULL; - mIsGetDefinition = + mMethodMatchInfo = NULL; + mIsGetDefinition = (resolveType == BfResolveType_GetSymbolInfo) || (resolveType == BfResolveType_GoToDefinition); mIsAutoComplete = (resolveType == BfResolveType_Autocomplete); @@ -253,18 +253,18 @@ void BfAutoComplete::Clear() else { // Keep mBestIdx - for when we match but then backspace - mMethodMatchInfo->mPrevBestIdx = mMethodMatchInfo->mBestIdx; + mMethodMatchInfo->mPrevBestIdx = mMethodMatchInfo->mBestIdx; mMethodMatchInfo->mMostParamsMatched = 0; mMethodMatchInfo->mHadExactMatch = false; mMethodMatchInfo->mInstanceList.Clear(); mMethodMatchInfo->mSrcPositions.Clear(); } } - + mInsertStartIdx = -1; mInsertEndIdx = -1; mIsCapturingMethodMatchInfo = false; - + AutoCompleteBase::Clear(); } @@ -306,7 +306,7 @@ bool BfAutoComplete::IsAutocompleteNode(BfAstNode* node, int lengthAdd, int star return false; if (node == NULL) return false; - + // if (!node->IsFromParser(mCompiler->mResolvePassData->mParser)) // return false; @@ -317,13 +317,13 @@ bool BfAutoComplete::IsAutocompleteNode(BfAstNode* node, int lengthAdd, int star return false; if ((bfParser->mParserFlags & ParserFlag_Autocomplete) == 0) return false; - + //if (mCompiler->mResolvePassData->mResolveType != BfResolveType_Autocomplete) lengthAdd++; int cursorIdx = bfParser->mCursorCheckIdx; - int nodeSrcStart = node->GetSrcStart(); - if ((cursorIdx < nodeSrcStart + startAdd) || (cursorIdx >= node->GetSrcEnd() + lengthAdd)) + int nodeSrcStart = node->GetSrcStart(); + if ((cursorIdx < nodeSrcStart + startAdd) || (cursorIdx >= node->GetSrcEnd() + lengthAdd)) return false; return true; } @@ -371,7 +371,7 @@ bool BfAutoComplete::IsAutocompleteLineNode(BfAstNode* node) return false; int startAdd = 0; - + if (mCursorLineStart == -1) { auto nodeSource = node->GetSourceData(); @@ -388,7 +388,7 @@ bool BfAutoComplete::IsAutocompleteLineNode(BfAstNode* node) while (mCursorLineEnd < nodeSource->mSrcLength) { if (nodeSource->mSrc[mCursorLineEnd] == '\n') - break; + break; mCursorLineEnd++; } } @@ -414,7 +414,7 @@ BfTypedValue BfAutoComplete::LookupTypeRefOrIdentifier(BfAstNode* node, bool* is }; if (auto typeRef = BfNodeDynCast(node)) - { + { if (auto namedTypeRef = BfNodeDynCast(typeRef)) { BfExprEvaluator exprEvaluator(mModule); @@ -466,16 +466,16 @@ BfTypedValue BfAutoComplete::LookupTypeRefOrIdentifier(BfAstNode* node, bool* is *isStatic = true; return _FixType(BfTypedValue(type)); } - } + } if (auto identifier = BfNodeDynCast(node)) - { + { BfExprEvaluator exprEvaluator(mModule); auto identifierResult = exprEvaluator.LookupIdentifier(identifier, false, NULL); if (!identifierResult) identifierResult = exprEvaluator.GetResult(); if (identifierResult) return _FixType(identifierResult); - + if (auto qualifiedIdentifier = BfNodeDynCast(node)) { bool leftIsStatic = false; @@ -506,12 +506,12 @@ BfTypedValue BfAutoComplete::LookupTypeRefOrIdentifier(BfAstNode* node, bool* is } } else if (auto memberRefExpr = BfNodeDynCast(node)) - { + { return _FixType(mModule->CreateValueFromExpression(memberRefExpr, expectingType, evalExprFlags)); } else if (auto parenExpr = BfNodeDynCast(node)) { - // Don't pass BfEvalExprFlags_IgnoreNullConditional, since parenExprs end nullable chains and we actually + // Don't pass BfEvalExprFlags_IgnoreNullConditional, since parenExprs end nullable chains and we actually // DO want the nullable at this point return _FixType(mModule->CreateValueFromExpression(parenExpr)); } @@ -521,7 +521,6 @@ BfTypedValue BfAutoComplete::LookupTypeRefOrIdentifier(BfAstNode* node, bool* is } return BfTypedValue(); - } void BfAutoComplete::SetDefinitionLocation(BfAstNode* astNode, bool force) @@ -529,7 +528,7 @@ void BfAutoComplete::SetDefinitionLocation(BfAstNode* astNode, bool force) if (mIsGetDefinition) { if ((mGetDefinitionNode == NULL) || (force)) - mGetDefinitionNode = astNode; + mGetDefinitionNode = astNode; } } @@ -554,7 +553,7 @@ void BfAutoComplete::AddMethod(BfTypeInstance* typeInstance, BfMethodDef* method { filterStr++; wantPrefixCount++; - } + } String replaceName; AutoCompleteEntry entry("method", methodName, methodDef->mNamePrefixCount - wantPrefixCount); if (methodDecl != NULL) @@ -565,15 +564,15 @@ void BfAutoComplete::AddMethod(BfTypeInstance* typeInstance, BfMethodDef* method replaceName += "!"; entry.mDisplay = replaceName.c_str(); entry.mEntryType = "mixin"; - } - } + } + } if (methodDef->mMethodType == BfMethodType_Extension) entry.mEntryType = "extmethod"; if (auto entryAdded = AddEntry(entry, filterStr)) { if (methodDecl != NULL) - { + { if ((methodInstance != NULL) && (methodInstance->mMethodDef->mIsLocalMethod) && (methodDecl->mReturnType != NULL) && (GetCursorIdx(methodDecl) == methodDecl->mReturnType->mSrcEnd)) { // This isn't really a local method decl, it just looks like one @@ -601,7 +600,7 @@ void BfAutoComplete::AddMethod(BfTypeInstance* typeInstance, BfMethodDef* method { if (!str.IsEmpty()) str += "\x05"; - methodDecl->mDocumentation->GetDocString(str); + methodDecl->mDocumentation->GetDocString(str); } if (!str.IsEmpty()) entryAdded->mDocumentation = mAlloc.AllocString(str); @@ -624,9 +623,9 @@ void BfAutoComplete::AddTypeDef(BfTypeDef* typeDef, const StringImpl& filter, bo if (name == "@") return; int gravePos = (int)name.IndexOf('`'); - if (gravePos != -1) + if (gravePos != -1) name = name.Substring(0, gravePos) + "<>"; - + if (onlyAttribute) { if ((mIsGetDefinition) && (name == filter + "Attribute")) @@ -638,7 +637,7 @@ void BfAutoComplete::AddTypeDef(BfTypeDef* typeDef, const StringImpl& filter, bo int score; uint8 matches[256]; if (!DoesFilterMatch(name.c_str(), filter.c_str(), score, matches, sizeof(matches))) - return; + return; auto type = mModule->ResolveTypeDef(typeDef, BfPopulateType_Declaration); if (type != NULL) @@ -669,7 +668,7 @@ void BfAutoComplete::AddTypeDef(BfTypeDef* typeDef, const StringImpl& filter, bo { if ((CheckDocumentation(entryAdded, NULL)) && (entryAdded->mDocumentation == NULL)) { - auto type = mModule->ResolveTypeDef(typeDef, BfPopulateType_IdentityNoRemapAlias); + auto type = mModule->ResolveTypeDef(typeDef, BfPopulateType_IdentityNoRemapAlias); StringT<1024> str; if (type != NULL) { @@ -681,7 +680,7 @@ void BfAutoComplete::AddTypeDef(BfTypeDef* typeDef, const StringImpl& filter, bo { if (!str.IsEmpty()) str += "\x05"; - typeDef->mTypeDeclaration->mDocumentation->GetDocString(str); + typeDef->mTypeDeclaration->mDocumentation->GetDocString(str); } entryAdded->mDocumentation = mAlloc.AllocString(str); } @@ -689,7 +688,7 @@ void BfAutoComplete::AddTypeDef(BfTypeDef* typeDef, const StringImpl& filter, bo } bool BfAutoComplete::CheckProtection(BfProtection protection, BfTypeDef* typeDef, bool allowProtected, bool allowPrivate) -{ +{ if (mResolveType == BfResolveType_GetSymbolInfo) { // This is needed for nameof on private inner types @@ -698,7 +697,7 @@ bool BfAutoComplete::CheckProtection(BfProtection protection, BfTypeDef* typeDef if ((protection == BfProtection_Internal) && (typeDef != NULL)) { - return mModule->CheckProtection(protection, typeDef, allowProtected, allowPrivate); + return mModule->CheckProtection(protection, typeDef, allowProtected, allowPrivate); } return (mHasFriendSet) || (protection == BfProtection_Public) || @@ -752,7 +751,7 @@ void BfAutoComplete::AddInnerTypes(BfTypeInstance* typeInst, const StringImpl& f } void BfAutoComplete::AddCurrentTypes(BfTypeInstance* typeInst, const StringImpl& filter, bool allowProtected, bool allowPrivate, bool onlyAttribute) -{ +{ if (typeInst != mModule->mCurTypeInstance) AddTypeDef(typeInst->mTypeDef->GetDefinition(), filter, onlyAttribute); @@ -781,14 +780,14 @@ void BfAutoComplete::AddCurrentTypes(BfTypeInstance* typeInst, const StringImpl& } void BfAutoComplete::AddField(BfTypeInstance* typeInst, BfFieldDef* fieldDef, BfFieldInstance* fieldInstance, const StringImpl& filter) -{ +{ int wantPrefixCount = 0; const char* filterStr = filter.c_str(); while (filterStr[0] == '@') { filterStr++; wantPrefixCount++; - } + } AutoCompleteEntry entry(GetTypeName(fieldInstance->mResolvedType), fieldDef->mName, fieldDef->mNamePrefixCount - wantPrefixCount); if (auto entryAdded = AddEntry(entry, filterStr)) { @@ -797,10 +796,10 @@ void BfAutoComplete::AddField(BfTypeInstance* typeInst, BfFieldDef* fieldDef, Bf if (CheckDocumentation(entryAdded, documentation)) { mModule->PopulateType(typeInst); - - String str; + + String str; str += mModule->TypeToString(fieldInstance->mResolvedType); - str += " "; + str += " "; str += mModule->TypeToString(typeInst); str += "."; str += fieldDef->mName; @@ -835,7 +834,7 @@ void BfAutoComplete::AddProp(BfTypeInstance* typeInst, BfPropertyDef* propDef, c { filterStr++; wantPrefixCount++; - } + } BfCommentNode* documentation = NULL; auto fieldDecl = propDef->GetFieldDeclaration(); if (fieldDecl != NULL) @@ -857,7 +856,7 @@ void BfAutoComplete::AddProp(BfTypeInstance* typeInst, BfPropertyDef* propDef, c if (methodDef->mMethodType == BfMethodType_PropertyGetter) { hasGetter = true; - propType = methodInstance->mReturnType; + propType = methodInstance->mReturnType; } if (methodDef->mMethodType == BfMethodType_PropertySetter) { @@ -905,7 +904,7 @@ void BfAutoComplete::AddProp(BfTypeInstance* typeInst, BfPropertyDef* propDef, c void BfAutoComplete::AddTypeMembers(BfTypeInstance* typeInst, bool addStatic, bool addNonStatic, const StringImpl& filter, BfTypeInstance* startType, bool allowInterfaces, bool allowImplicitThis, bool checkOuterType) { bool isInterface = false; - + if (mForceAllowNonStatic) addNonStatic = true; @@ -924,7 +923,7 @@ void BfAutoComplete::AddTypeMembers(BfTypeInstance* typeInst, bool addStatic, bo BfProtectionCheckFlags protectionCheckFlags = BfProtectionCheckFlag_None; for (auto& fieldInst : typeInst->mFieldInstances) - { + { auto fieldDef = fieldInst.GetFieldDef(); if (fieldDef == NULL) continue; @@ -932,16 +931,16 @@ void BfAutoComplete::AddTypeMembers(BfTypeInstance* typeInst, bool addStatic, bo if (fieldDef->mShow >= checkShow) continue; - if ((CHECK_STATIC(fieldDef->mIsStatic)) && + if ((CHECK_STATIC(fieldDef->mIsStatic)) && ((mIsGetDefinition) || (mModule->CheckProtection(protectionCheckFlags, typeInst, fieldDef->mDeclaringType->mProject, fieldDef->mProtection, startType)))) { if ((!typeInst->IsTypeMemberIncluded(fieldDef->mDeclaringType, activeTypeDef, mModule)) || (!typeInst->IsTypeMemberAccessible(fieldDef->mDeclaringType, activeTypeDef))) continue; - + AddField(typeInst, fieldDef, &fieldInst, filter); } - } + } for (auto methodDef : typeInst->mTypeDef->mMethods) { @@ -968,11 +967,11 @@ void BfAutoComplete::AddTypeMembers(BfTypeInstance* typeInst, bool addStatic, bo else { canUseMethod &= (CHECK_STATIC(methodDef->mIsStatic) && - (mModule->CheckProtection(protectionCheckFlags, typeInst, methodDef->mDeclaringType->mProject, methodDef->mProtection, startType))); + (mModule->CheckProtection(protectionCheckFlags, typeInst, methodDef->mDeclaringType->mProject, methodDef->mProtection, startType))); } if (canUseMethod) { - AddMethod(typeInst, methodDef, NULL, methodDef->GetMethodDeclaration(), methodDef->mName, filter); + AddMethod(typeInst, methodDef, NULL, methodDef->GetMethodDeclaration(), methodDef->mName, filter); } } @@ -995,7 +994,7 @@ void BfAutoComplete::AddTypeMembers(BfTypeInstance* typeInst, bool addStatic, bo AddProp(typeInst, propDef, filter); } } - + if (allowInterfaces) { for (auto iface : typeInst->mInterfaces) @@ -1102,7 +1101,7 @@ void BfAutoComplete::AddSelfResultTypeMembers(BfTypeInstance* typeInst, BfTypeIn if (fieldDef->mShow > checkShow) continue; - + if ((fieldDef->mIsStatic) && (CheckProtection(fieldDef->mProtection, fieldDef->mDeclaringType, allowProtected, allowPrivate))) { if (!mModule->CanCast(BfTypedValue(mModule->mBfIRBuilder->GetFakeVal(), fieldInst.mResolvedType), selfType)) @@ -1112,7 +1111,7 @@ void BfAutoComplete::AddSelfResultTypeMembers(BfTypeInstance* typeInst, BfTypeIn (!typeInst->IsTypeMemberAccessible(fieldDef->mDeclaringType, activeTypeDef))) continue; - AddField(typeInst, fieldDef, &fieldInst, filter); + AddField(typeInst, fieldDef, &fieldInst, filter); } } @@ -1135,9 +1134,9 @@ void BfAutoComplete::AddSelfResultTypeMembers(BfTypeInstance* typeInst, BfTypeIn continue; bool canUseMethod; - canUseMethod = (methodDef->mMethodType == BfMethodType_Normal) || (methodDef->mMethodType == BfMethodType_Mixin); + canUseMethod = (methodDef->mMethodType == BfMethodType_Normal) || (methodDef->mMethodType == BfMethodType_Mixin); canUseMethod &= CheckProtection(methodDef->mProtection, methodDef->mDeclaringType, allowProtected, allowPrivate); - + if (methodDef->mMethodType != BfMethodType_Normal) continue; @@ -1199,16 +1198,16 @@ void BfAutoComplete::AddSelfResultTypeMembers(BfTypeInstance* typeInst, BfTypeIn AddProp(typeInst, propDef, filter); } } - + auto outerType = mModule->GetOuterType(typeInst); if (outerType != NULL) { AddSelfResultTypeMembers(outerType, selfType, filter, false); - } + } } bool BfAutoComplete::InitAutocomplete(BfAstNode* dotNode, BfAstNode* nameNode, String& filter) -{ +{ bool isDot = (dotNode != NULL) && (dotNode->mToken == BfToken_Dot); if (IsAutocompleteNode(nameNode)) { @@ -1252,8 +1251,8 @@ void BfAutoComplete::AddEnumTypeMembers(BfTypeInstance* typeInst, const StringIm for (auto& fieldInst : typeInst->mFieldInstances) { auto fieldDef = fieldInst.GetFieldDef(); - if ((fieldDef != NULL) && (fieldDef->mIsConst) && - ((fieldInst.mResolvedType == typeInst) || (fieldInst.mIsEnumPayloadCase)) && + if ((fieldDef != NULL) && (fieldDef->mIsConst) && + ((fieldInst.mResolvedType == typeInst) || (fieldInst.mIsEnumPayloadCase)) && (CheckProtection(fieldDef->mProtection, fieldDef->mDeclaringType, allowProtected, allowPrivate))) { if ((!typeInst->IsTypeMemberIncluded(fieldDef->mDeclaringType, activeTypeDef, mModule)) || @@ -1284,7 +1283,7 @@ void BfAutoComplete::AddEnumTypeMembers(BfTypeInstance* typeInst, const StringIm } } } - } + } } void BfAutoComplete::AddExtensionMethods(BfTypeInstance* targetType, BfTypeInstance* extensionContainer, const StringImpl & filter, bool allowProtected, bool allowPrivate) @@ -1299,15 +1298,15 @@ void BfAutoComplete::AddExtensionMethods(BfTypeInstance* targetType, BfTypeInsta for (auto methodDef : extensionContainer->mTypeDef->mMethods) { if (methodDef->mMethodType != BfMethodType_Extension) - continue; + continue; if (methodDef->mShow >= checkShow) continue; if (methodDef->mName.IsEmpty()) continue; - - bool canUseMethod = true; + + bool canUseMethod = true; canUseMethod &= CheckProtection(methodDef->mProtection, methodDef->mDeclaringType, allowProtected, allowPrivate); - + auto methodInstance = mModule->GetRawMethodInstanceAtIdx(extensionContainer, methodDef->mIdx); if (methodInstance == NULL) continue; @@ -1318,7 +1317,7 @@ void BfAutoComplete::AddExtensionMethods(BfTypeInstance* targetType, BfTypeInsta if (!DoesFilterMatch(methodDef->mName.c_str(), filter.c_str(), score, matches, sizeof(matches))) continue; - auto thisType = methodInstance->GetParamType(0); + auto thisType = methodInstance->GetParamType(0); bool paramValidated = false; if (methodInstance->GetNumGenericParams() > 0) { @@ -1403,7 +1402,7 @@ bool BfAutoComplete::WantsEntries() if (mModule == NULL) return false; - return (mResolveType == BfResolveType_Autocomplete) || + return (mResolveType == BfResolveType_Autocomplete) || (mResolveType == BfResolveType_Autocomplete_HighPri) || (mResolveType == BfResolveType_GetSymbolInfo) || (mResolveType == BfResolveType_GoToDefinition) || @@ -1411,7 +1410,7 @@ bool BfAutoComplete::WantsEntries() } void BfAutoComplete::AddTopLevelNamespaces(BfAstNode* identifierNode) -{ +{ String filter; if (identifierNode != NULL) { @@ -1420,8 +1419,8 @@ void BfAutoComplete::AddTopLevelNamespaces(BfAstNode* identifierNode) mInsertEndIdx = identifierNode->GetSrcEnd(); } - BfProject* bfProject = GetActiveProject(); - + BfProject* bfProject = GetActiveProject(); + auto _AddProjectNamespaces = [&](BfProject* project) { for (auto namespacePair : project->mNamespaces) @@ -1452,7 +1451,7 @@ void BfAutoComplete::AddTopLevelNamespaces(BfAstNode* identifierNode) void BfAutoComplete::AddTopLevelTypes(BfAstNode* identifierNode, bool onlyAttribute) { String filter; - + if (identifierNode != NULL) { filter = identifierNode->ToString(); @@ -1463,7 +1462,7 @@ void BfAutoComplete::AddTopLevelTypes(BfAstNode* identifierNode, bool onlyAttrib AddEntry(AutoCompleteEntry("token", "function"), filter); AddEntry(AutoCompleteEntry("token", "delegate"), filter); AddEntry(AutoCompleteEntry("token", "decltype"), filter); - + if (mModule->mCurTypeInstance != NULL) { if (!onlyAttribute) @@ -1472,7 +1471,7 @@ void BfAutoComplete::AddTopLevelTypes(BfAstNode* identifierNode, bool onlyAttrib for (auto genericParam : activeTypeDef->mGenericParamDefs) AddEntry(AutoCompleteEntry("generic", genericParam->mName), filter); } - + AddCurrentTypes(mModule->mCurTypeInstance, filter, true, true, onlyAttribute); } @@ -1487,14 +1486,14 @@ void BfAutoComplete::AddTopLevelTypes(BfAstNode* identifierNode, bool onlyAttrib if (!onlyAttribute) { - BfTypeDef* showTypeDef = NULL; + BfTypeDef* showTypeDef = NULL; for (auto& systemTypeDefEntry : mModule->mSystem->mSystemTypeDefs) { auto systemTypeDef = systemTypeDefEntry.mValue; if ((systemTypeDef->mTypeCode == BfTypeCode_IntUnknown) || (systemTypeDef->mTypeCode == BfTypeCode_UIntUnknown)) continue; if ((AddEntry(AutoCompleteEntry("valuetype", systemTypeDef->mName->mString.mPtr), filter)) && (mIsGetDefinition)) - showTypeDef = systemTypeDef; + showTypeDef = systemTypeDef; } AddEntry(AutoCompleteEntry("valuetype", "SelfBase"), filter); AddEntry(AutoCompleteEntry("valuetype", "SelfOuter"), filter); @@ -1516,7 +1515,7 @@ void BfAutoComplete::AddTopLevelTypes(BfAstNode* identifierNode, bool onlyAttrib if (activeTypeDef != NULL) { BfProject* curProject = activeTypeDef->mProject; - + if (mModule->mCurTypeInstance != NULL) { for (auto innerTypeDef : mModule->mCurTypeInstance->mTypeDef->mNestedTypes) @@ -1527,14 +1526,14 @@ void BfAutoComplete::AddTopLevelTypes(BfAstNode* identifierNode, bool onlyAttrib } } - auto& namespaceSearch = activeTypeDef->mNamespaceSearch; + auto& namespaceSearch = activeTypeDef->mNamespaceSearch; String prevName; for (auto typeDef : mModule->mSystem->mTypeDefs) - { + { if (typeDef->mIsPartial) continue; //TODO :Check protection - if ((curProject != NULL) && (curProject->ContainsReference(typeDef->mProject))) + if ((curProject != NULL) && (curProject->ContainsReference(typeDef->mProject))) { bool matches = false; if (typeDef->mOuterType == NULL) @@ -1542,7 +1541,7 @@ void BfAutoComplete::AddTopLevelTypes(BfAstNode* identifierNode, bool onlyAttrib if (((typeDef->mNamespace.IsEmpty()) || (namespaceSearch.Contains(typeDef->mNamespace)))) matches = true; - } + } if (matches) { @@ -1582,7 +1581,7 @@ void BfAutoComplete::AddTopLevelTypes(BfAstNode* identifierNode, bool onlyAttrib } void BfAutoComplete::CheckIdentifier(BfAstNode* identifierNode, bool isInExpression, bool isUsingDirective) -{ +{ if ((identifierNode != NULL) && (!IsAutocompleteNode(identifierNode))) return; @@ -1595,7 +1594,7 @@ void BfAutoComplete::CheckIdentifier(BfAstNode* identifierNode, bool isInExpress auto parentBlock = mModule->mCurMethodState->mCurScope->mAstBlock; if ((identifierNode == binExpr->mRight) && (binExpr->mOp == BfBinaryOp_Multiply) && (parentBlock != NULL)) { - // If we are the last identifier in a block then we MAY be a partially-typed variable declaration + // If we are the last identifier in a block then we MAY be a partially-typed variable declaration if (parentBlock->mChildArr.back() == binExpr) { mUncertain = true; @@ -1603,7 +1602,7 @@ void BfAutoComplete::CheckIdentifier(BfAstNode* identifierNode, bool isInExpress } } } - + if (auto qualifiedNameNode = BfNodeDynCast(identifierNode)) { CheckMemberReference(qualifiedNameNode->mLeft, qualifiedNameNode->mDot, qualifiedNameNode->mRight, false, NULL, isUsingDirective); @@ -1613,7 +1612,7 @@ void BfAutoComplete::CheckIdentifier(BfAstNode* identifierNode, bool isInExpress AddTopLevelNamespaces(identifierNode); if (isUsingDirective) return; // Only do namespaces - + AddTopLevelTypes(identifierNode); String filter; @@ -1632,10 +1631,9 @@ void BfAutoComplete::CheckIdentifier(BfAstNode* identifierNode, bool isInExpress for (auto prop : showAttrTypeDef->mProperties) { if (auto entryAdded = AddEntry(AutoCompleteEntry("property", prop->mName + "="), filter)) - { + { if (CheckDocumentation(entryAdded, prop->GetFieldDeclaration()->mDocumentation)) { - } if (mIsGetDefinition) SetDefinitionLocation(prop->GetFieldDeclaration()->mNameNode); @@ -1643,12 +1641,11 @@ void BfAutoComplete::CheckIdentifier(BfAstNode* identifierNode, bool isInExpress } for (auto field : showAttrTypeDef->mFields) - { + { if (auto entryAdded = AddEntry(AutoCompleteEntry("field", field->mName + "="), filter)) - { + { if (CheckDocumentation(entryAdded, field->GetFieldDeclaration()->mDocumentation)) { - } if (mIsGetDefinition) SetDefinitionLocation(field->GetFieldDeclaration()->mNameNode); @@ -1669,7 +1666,7 @@ void BfAutoComplete::CheckIdentifier(BfAstNode* identifierNode, bool isInExpress AddTypeMembers(globalContainer.mTypeInst, true, false, filter, globalContainer.mTypeInst, true, true, false); } } - + BfStaticSearch* staticSearch = mModule->GetStaticSearch(); if (staticSearch != NULL) { @@ -1679,7 +1676,7 @@ void BfAutoComplete::CheckIdentifier(BfAstNode* identifierNode, bool isInExpress AddInnerTypes(typeInst, filter, typeInst, false, false); } } - + if (auto ceDbgState = mModule->GetCeDbgState()) { auto ceDebugger = mModule->mCompiler->mCeMachine->mDebugger; @@ -1693,7 +1690,7 @@ void BfAutoComplete::CheckIdentifier(BfAstNode* identifierNode, bool isInExpress if ((instIdx >= dbgVar.mStartCodePos) && (instIdx < dbgVar.mEndCodePos)) AddEntry(AutoCompleteEntry(GetTypeName(dbgVar.mType), dbgVar.mName), filter); } - } + } } ////////////////////////////////////////////////////////////////////////// @@ -1702,7 +1699,7 @@ void BfAutoComplete::CheckIdentifier(BfAstNode* identifierNode, bool isInExpress if (mModule->mCurMethodState != NULL) curMethodInstance = mModule->mCurMethodState->GetRootMethodState()->mMethodInstance; if (curMethodInstance != NULL) - { + { if (!curMethodInstance->mMethodDef->mIsStatic) { if (mModule->mCurTypeInstance->IsObject()) @@ -1781,7 +1778,7 @@ void BfAutoComplete::CheckIdentifier(BfAstNode* identifierNode, bool isInExpress (varMethodState->mMixinState != NULL) || ((varMethodState->mClosureState != NULL) && (!varMethodState->mClosureState->mCapturing))) break; - } + } } } } @@ -1797,9 +1794,9 @@ void BfAutoComplete::CheckIdentifier(BfAstNode* identifierNode, bool isInExpress auto checkMethodState = mModule->mCurMethodState; while (checkMethodState != NULL) - { + { for (auto localMethod : checkMethodState->mLocalMethods) - { + { if (localMethod->mMethodInstanceGroup != NULL) AddMethod(mModule->mCurTypeInstance, localMethod->mMethodDef, localMethod->mMethodInstanceGroup->mDefault, localMethod->mMethodDeclaration, localMethod->mMethodName, filter); } @@ -1807,17 +1804,17 @@ void BfAutoComplete::CheckIdentifier(BfAstNode* identifierNode, bool isInExpress } if (isInExpression) - { + { const char* tokens [] = { "alignof", "append", "as", "asm", "base", "break", "case", "catch", "checked", "continue", "const", "default", "defer", - "delegate", "delete", "do", "else", "false", "finally", + "delegate", "delete", "do", "else", "false", "finally", "fixed", "for", "function", "if", "implicit", "in", "internal", "is", "isconst", "new", "mixin", "null", "offsetof", "out", "params", "readonly", "ref", "rettype", "return", "sealed", "sizeof", "scope", "static", "strideof", "struct", "switch", /*"this",*/ "try", "true", "typeof", "unchecked", "using", "var", "virtual", "volatile", "where", "while", "alloctype", "comptype", "decltype", "nullable", - }; + }; for (int i = 0; i < sizeof(tokens) / sizeof(char*); i++) AddEntry(AutoCompleteEntry("token", tokens[i]), filter); @@ -1831,7 +1828,7 @@ void BfAutoComplete::CheckIdentifier(BfAstNode* identifierNode, bool isInExpress { const char* tokens[] = { - "abstract", "append", "base", "class", "const", + "abstract", "append", "base", "class", "const", "delegate", "extern", "enum", "explicit", "extension", "function", "interface", "in", "implicit", "internal", "mixin", "namespace", "new", "operator", "out", "override", "params", "private", "protected", "public", "readonly", "ref", "rettype", "return", @@ -1841,15 +1838,15 @@ void BfAutoComplete::CheckIdentifier(BfAstNode* identifierNode, bool isInExpress for (int i = 0; i < sizeof(tokens)/sizeof(char*); i++) AddEntry(AutoCompleteEntry("token", tokens[i]), filter); } - + //if ((identifierNode != NULL) && ((mModule->mCurMethodInstance == NULL) || (BfNodeDynCast(identifierNode->mParent) != NULL))) /*if ((identifierNode != NULL) && ((mModule->mCurMethodInstance == NULL) || (isInExpression))) { AddEntry(AutoCompleteEntry("token", "#if"), filter); AddEntry(AutoCompleteEntry("token", "#elif"), filter); AddEntry(AutoCompleteEntry("token", "#endif"), filter); - }*/ - + }*/ + //OutputDebugStrF("Autocomplete: %s\n", str.c_str()); } @@ -1867,14 +1864,14 @@ String BfAutoComplete::GetFilter(BfAstNode* node) auto bfParser = node->GetSourceData()->ToParser(); int cursorIdx = bfParser->mCursorIdx; filter = filter.Substring(0, BF_CLAMP(cursorIdx - node->GetSrcStart(), 0, (int)filter.length())); - mInsertEndIdx = cursorIdx; + mInsertEndIdx = cursorIdx; } const char* cPtr = filter.c_str(); while (cPtr[0] == '@') { mInsertStartIdx++; - cPtr++; + cPtr++; } return filter; @@ -1892,7 +1889,7 @@ bool BfAutoComplete::CheckMemberReference(BfAstNode* target, BfAstNode* dotToken memberName = attrIdentifier->mIdentifier; if (IsAutocompleteNode(attrIdentifier->mAttributes)) { - auto bfParser = attrIdentifier->mAttributes->GetSourceData()->ToParser(); + auto bfParser = attrIdentifier->mAttributes->GetSourceData()->ToParser(); int cursorIdx = bfParser->mCursorIdx; if (cursorIdx == attrIdentifier->mAttributes->GetSrcEnd()) isAutocompletingName = true; @@ -1909,8 +1906,8 @@ bool BfAutoComplete::CheckMemberReference(BfAstNode* target, BfAstNode* dotToken BfLogSys(mModule->mSystem, "Triggered autocomplete\n"); bool isFriend = false; - - mInsertStartIdx = dotToken->GetSrcEnd(); + + mInsertStartIdx = dotToken->GetSrcEnd(); if (attrIdentifier != NULL) { BfAttributeState attributeState; @@ -1924,7 +1921,7 @@ bool BfAutoComplete::CheckMemberReference(BfAstNode* target, BfAstNode* dotToken mInsertStartIdx = attrIdentifier->mAttributes->GetSrcEnd(); } - + if (memberName != NULL) { //Member name MAY be incorrectly identified in cases like: @@ -1943,7 +1940,7 @@ bool BfAutoComplete::CheckMemberReference(BfAstNode* target, BfAstNode* dotToken filter = GetFilter(memberName); } else if (mResolveType != BfResolveType_Autocomplete) - mInsertStartIdx = -1; // Require a full span for everything but autocomplete + mInsertStartIdx = -1; // Require a full span for everything but autocomplete SetAndRestoreValue prevIgnoreErrors(mModule->mIgnoreErrors, true); @@ -1954,7 +1951,7 @@ bool BfAutoComplete::CheckMemberReference(BfAstNode* target, BfAstNode* dotToken SetAndRestoreValue prevIgnoreClassifying(mModule->mIsInsideAutoComplete, true); BfExprEvaluator exprEvaluator(mModule); auto arrowValue = exprEvaluator.PerformUnaryOperation_TryOperator(targetValue, NULL, BfUnaryOp_Arrow, BfNodeDynCast(dotToken), BfUnaryOpFlag_None); - if (arrowValue) + if (arrowValue) targetValue = arrowValue; } @@ -1984,13 +1981,13 @@ bool BfAutoComplete::CheckMemberReference(BfAstNode* target, BfAstNode* dotToken targetValue = mModule->MakeAddressable(targetValue); BfIRValue valuePtr = mModule->mBfIRBuilder->CreateInBoundsGEP(targetValue.mValue, 0, 1); // mValue targetValue = BfTypedValue(valuePtr, nullableType->mGenericTypeInfo->mTypeGenericArguments[0], true); - } + } } } // Statics, inner types - - auto checkType = targetValue.mType; + + auto checkType = targetValue.mType; if (checkType->IsConcreteInterfaceType()) checkType = checkType->GetUnderlyingType(); @@ -1998,7 +1995,7 @@ bool BfAutoComplete::CheckMemberReference(BfAstNode* target, BfAstNode* dotToken { auto genericParamType = (BfGenericParamType*)checkType; auto genericParamInstance = mModule->GetGenericParamInstance(genericParamType); - + auto _HandleGenericParamInstance = [&](BfGenericParamInstance* genericParamInstance) { bool showStatics = !targetValue.mValue; @@ -2044,7 +2041,7 @@ bool BfAutoComplete::CheckMemberReference(BfAstNode* target, BfAstNode* dotToken checkType = underlyingType; } auto typeInst = checkType->ToTypeInstance(); - if ((typeInst == NULL) && + if ((typeInst == NULL) && ((checkType->IsPrimitiveType()) || (checkType->IsSizedArray()))) typeInst = mModule->GetWrappedStructType(checkType); @@ -2064,7 +2061,7 @@ bool BfAutoComplete::CheckMemberReference(BfAstNode* target, BfAstNode* dotToken AddTypeMembers(typeInst, isStatic, !isStatic, filter, typeInst, false, false, false); if (!isStatic) - { + { auto checkTypeInst = mModule->mCurTypeInstance; while (checkTypeInst != NULL) { @@ -2110,9 +2107,9 @@ bool BfAutoComplete::CheckMemberReference(BfAstNode* target, BfAstNode* dotToken BfProject* bfProject = GetActiveProject(); auto _CheckProject = [&](BfProject* project) - { + { if ((isValid) && (project->mNamespaces.ContainsKey(targetComposite))) - { + { for (auto namespacePair : project->mNamespaces) { const BfAtomComposite& namespaceComposite = namespacePair.mKey; @@ -2125,7 +2122,7 @@ bool BfAutoComplete::CheckMemberReference(BfAstNode* target, BfAstNode* dotToken } if (!isUsingDirective) - { + { BfProject* activeProject = GetActiveProject(); for (auto typeDef : mSystem->mTypeDefs) { @@ -2135,7 +2132,7 @@ bool BfAutoComplete::CheckMemberReference(BfAstNode* target, BfAstNode* dotToken { AddTypeDef(typeDef, filter, onlyAttribute); } - } + } } hadResults = true; @@ -2160,7 +2157,7 @@ bool BfAutoComplete::CheckMemberReference(BfAstNode* target, BfAstNode* dotToken return hadResults; } else - { + { auto identifierNode = BfNodeDynCast(target); if (identifierNode != NULL) CheckIdentifier(identifierNode); @@ -2187,7 +2184,7 @@ bool BfAutoComplete::CheckExplicitInterface(BfTypeInstance* interfaceType, BfAst } else return false; - + mModule->PopulateType(interfaceType, BfPopulateType_DataAndMethods); String filter; @@ -2217,14 +2214,13 @@ bool BfAutoComplete::CheckExplicitInterface(BfTypeInstance* interfaceType, BfAst continue; bool canUseMethod; - canUseMethod = (methodDef->mMethodType == BfMethodType_Normal); + canUseMethod = (methodDef->mMethodType == BfMethodType_Normal); if (canUseMethod) { AddMethod(interfaceType, methodDef, NULL, methodDef->GetMethodDeclaration(), methodDef->mName, filter); } } - return false; } @@ -2298,13 +2294,13 @@ void BfAutoComplete::CheckTypeRef(BfTypeReference* typeRef, bool mayBeIdentifier } if (auto qualifiedTypeRef = BfNodeDynCast(typeRef)) - { + { // Only consider the left side as an identifier if there's space after the dot. Consider this: // mVal. // Type a = null; // vs // mVal.Type a = null; - // The first one is clearly a member reference being typed out even though it looks the same + // The first one is clearly a member reference being typed out even though it looks the same // to the parser except for the spacing if ((qualifiedTypeRef->mRight == NULL) || (qualifiedTypeRef->mDot->GetSrcEnd() < qualifiedTypeRef->mRight->GetSrcStart())) { @@ -2352,11 +2348,11 @@ void BfAutoComplete::CheckInvocation(BfAstNode* invocationNode, BfTokenNode* ope else { // Ignore close paren - lenAdd = -1; + lenAdd = -1; } - + if (!IsAutocompleteNode(invocationNode, lenAdd)) - return; + return; if (openParen == NULL) { @@ -2397,14 +2393,14 @@ void BfAutoComplete::CheckInvocation(BfAstNode* invocationNode, BfTokenNode* ope bool doCapture = (bfParser->mCursorIdx >= openParen->GetSrcStart()); if (mIsGetDefinition) - { + { doCapture |= (target != NULL) && (bfParser->mCursorIdx >= target->GetSrcStart()); } if (doCapture) - { + { mIsCapturingMethodMatchInfo = true; - + delete mMethodMatchInfo; mMethodMatchInfo = new MethodMatchInfo(); @@ -2449,7 +2445,7 @@ bool BfAutoComplete::GetMethodInfo(BfMethodInstance* methodInst, StringImpl* sho { StringT<128> methodPrefix; StringT<128> methodName; - StringT<256> impString; + StringT<256> impString; bool isAbstract = (methodDef->mIsAbstract) || (isInterface) || (!methodDef->mIsVirtual); @@ -2459,22 +2455,22 @@ bool BfAutoComplete::GetMethodInfo(BfMethodInstance* methodInst, StringImpl* sho impString += "return default;"; } else if (!isAbstract) - { + { if (!methodInst->mReturnType->IsVoid()) impString = "return "; impString += "base."; impString += methodDef->mName; - impString += "("; + impString += "("; } auto methodDeclaration = methodDef->GetMethodDeclaration(); if (isInterface) - { + { if (!isExplicitInterface) methodPrefix += "public "; - } + } else if (methodDeclaration->mProtectionSpecifier != NULL) methodPrefix += methodDeclaration->mProtectionSpecifier->ToString() + " "; if (!isInterface) @@ -2541,14 +2537,14 @@ bool BfAutoComplete::GetMethodInfo(BfMethodInstance* methodInst, StringImpl* sho methodName += ")"; if (methodInst->GetNumGenericArguments() > 0) - { + { for (int genericArgIdx = 0; genericArgIdx < (int)methodInst->mMethodInfoEx->mGenericParams.size(); genericArgIdx++) - { + { auto genericParam = methodInst->mMethodInfoEx->mGenericParams[genericArgIdx]; - - if (genericParam->mTypeConstraint != NULL) + + if (genericParam->mTypeConstraint != NULL) methodName += " where " + genericParam->GetName() + " : " + mModule->TypeToString(genericParam->mTypeConstraint, nameFlags); - + for (auto ifaceConstraint : genericParam->mInterfaceConstraints) methodName += " where " + genericParam->GetName() + " : " + mModule->TypeToString(ifaceConstraint, nameFlags); @@ -2563,15 +2559,15 @@ bool BfAutoComplete::GetMethodInfo(BfMethodInstance* methodInst, StringImpl* sho if ((genericParam->mGenericParamFlags & BfGenericParamFlag_Delete) != 0) methodName += " where " + genericParam->GetName() + " : delete"; if ((genericParam->mGenericParamFlags & BfGenericParamFlag_Var) != 0) - methodName += " where " + genericParam->GetName() + " : var"; - } + methodName += " where " + genericParam->GetName() + " : var"; + } } if (!isAbstract) impString += ");"; if (showString != NULL) - *showString += methodName; + *showString += methodName; if (insertString != NULL) { if (showString == insertString) @@ -2595,7 +2591,7 @@ bool BfAutoComplete::GetMethodInfo(BfMethodInstance* methodInst, StringImpl* sho if (propDeclaration->mNameNode != NULL) propDeclaration->mNameNode->ToString(propName); - else + else { StringT<128> args; @@ -2665,7 +2661,7 @@ bool BfAutoComplete::GetMethodInfo(BfMethodInstance* methodInst, StringImpl* sho impl += "set\t"; if (!isAbstract) { - if (!isInterface) + if (!isInterface) { impl += "base."; impl += propName; @@ -2683,7 +2679,7 @@ bool BfAutoComplete::GetMethodInfo(BfMethodInstance* methodInst, StringImpl* sho if (showString == insertString) *insertString += "\t"; *insertString += impl; - } + } return true; } @@ -2725,7 +2721,7 @@ void BfAutoComplete::AddOverrides(const StringImpl& filter) if (methodDef->mIsExtern) allowInternalOverride = true; } - + auto& methodGroup = curType->mMethodInstanceGroups[methodDef->mIdx]; if (methodGroup.mDefault == NULL) { @@ -2739,12 +2735,12 @@ void BfAutoComplete::AddOverrides(const StringImpl& filter) } else if ((!methodDef->mIsVirtual) || (methodDef->mIsOverride)) continue; - + if ((methodDef->mMethodType != BfMethodType_Normal) && (methodDef->mMethodType != BfMethodType_PropertyGetter) && (methodDef->mMethodType != BfMethodType_PropertySetter)) continue; - + if ((methodInst->mVirtualTableIdx >= 0) && (methodInst->mVirtualTableIdx < mModule->mCurTypeInstance->mVirtualMethodTable.size())) { auto& vEntry = mModule->mCurTypeInstance->mVirtualMethodTable[methodInst->mVirtualTableIdx]; @@ -2768,14 +2764,13 @@ void BfAutoComplete::AddOverrides(const StringImpl& filter) void BfAutoComplete::UpdateReplaceData() { - } void BfAutoComplete::CheckMethod(BfMethodDeclaration* methodDeclaration, bool isLocalMethod) { if (/*(propertyDeclaration->mDefinitionBlock == NULL) &&*/ (methodDeclaration->mVirtualSpecifier != NULL) && (methodDeclaration->mVirtualSpecifier->GetToken() == BfToken_Override)) - { + { auto bfParser = methodDeclaration->mVirtualSpecifier->GetSourceData()->ToParser(); if (bfParser == NULL) return; @@ -2838,8 +2833,8 @@ void BfAutoComplete::CheckProperty(BfPropertyDeclaration* propertyDeclaration) if (type != NULL) typeInst = type->ToTypeInstance(); - if (typeInst != NULL) - CheckExplicitInterface(typeInst, propertyDeclaration->mExplicitInterfaceDotToken, propertyDeclaration->mNameNode); + if (typeInst != NULL) + CheckExplicitInterface(typeInst, propertyDeclaration->mExplicitInterfaceDotToken, propertyDeclaration->mNameNode); } if ((propertyDeclaration->mVirtualSpecifier != NULL) && @@ -2858,7 +2853,7 @@ void BfAutoComplete::CheckProperty(BfPropertyDeclaration* propertyDeclaration) if (((IsAutocompleteNode(propertyDeclaration, 1)) && (cursorIdx == propertyDeclaration->mVirtualSpecifier->GetSrcEnd())) || (isInTypeRef) || (isInNameNode)) - { + { mInsertStartIdx = propertyDeclaration->mVirtualSpecifier->GetSrcStart(); String filter; @@ -2869,17 +2864,17 @@ void BfAutoComplete::CheckProperty(BfPropertyDeclaration* propertyDeclaration) defNode = propertyDeclaration->mNameNode; else if (isInTypeRef) defNode = propertyDeclaration->mTypeRef; - - filter = defNode->ToString(); + + filter = defNode->ToString(); mInsertEndIdx = defNode->GetSrcEnd(); - } + } else if (propertyDeclaration->mTypeRef != NULL) { - // We're just inside 'override' - we may be inserting a new method + // We're just inside 'override' - we may be inserting a new method mInsertEndIdx = propertyDeclaration->mVirtualSpecifier->GetSrcEnd(); } else - { + { mInsertEndIdx = propertyDeclaration->mVirtualSpecifier->GetSrcEnd(); } AddOverrides(filter); @@ -2894,14 +2889,14 @@ void BfAutoComplete::CheckProperty(BfPropertyDeclaration* propertyDeclaration) } void BfAutoComplete::CheckVarResolution(BfAstNode* varTypeRef, BfType* resolvedType) -{ +{ if (IsAutocompleteNode(varTypeRef)) - { + { if ((resolvedType == NULL) || (resolvedType->IsVar()) || (resolvedType->IsLet())) return; if (mIsGetDefinition) - { + { auto typeInst = resolvedType->ToTypeInstance(); if (typeInst != NULL) { @@ -2942,7 +2937,7 @@ void BfAutoComplete::CheckResult(BfAstNode* node, const BfTypedValue& typedValue else if (BfIRConstHolder::IsFloat(constant->mTypeCode)) { mResultString = StrFormat(":%f", constant->mDouble); - } + } } void BfAutoComplete::CheckLocalDef(BfAstNode* identifierNode, BfLocalVariable* varDecl) @@ -2958,7 +2953,7 @@ void BfAutoComplete::CheckLocalRef(BfAstNode* identifierNode, BfLocalVariable* v if (mResolveType == BfResolveType_GoToDefinition) { if (IsAutocompleteNode(identifierNode)) - { + { if (varDecl->mNameNode != NULL) SetDefinitionLocation(varDecl->mNameNode, true); else if (varDecl->mIsThis) @@ -2967,9 +2962,9 @@ void BfAutoComplete::CheckLocalRef(BfAstNode* identifierNode, BfLocalVariable* v } else if (mResolveType == BfResolveType_GetSymbolInfo) { - if ((IsAutocompleteNode(identifierNode)) && + if ((IsAutocompleteNode(identifierNode)) && ((!varDecl->mIsShadow) || (varDecl->mShadowedLocal != NULL))) - { + { if ((mModule->mCurMethodState != NULL) && (mModule->mCurMethodState->mClosureState != NULL) && (!mModule->mCurMethodState->mClosureState->mCapturing)) { @@ -2980,13 +2975,13 @@ void BfAutoComplete::CheckLocalRef(BfAstNode* identifierNode, BfLocalVariable* v auto rootMethodInstance = mModule->mCurMethodState->GetRootMethodState()->mMethodInstance; if (rootMethodInstance == NULL) return; - + if (varDecl->mIsThis) return; - auto resolvePassData = mModule->mCompiler->mResolvePassData; + auto resolvePassData = mModule->mCompiler->mResolvePassData; mDefType = mModule->mCurTypeInstance->mTypeDef; - + mReplaceLocalId = varDecl->mLocalVarId; mDefMethod = rootMethodInstance->mMethodDef; if (mInsertStartIdx == -1) @@ -2995,28 +2990,28 @@ void BfAutoComplete::CheckLocalRef(BfAstNode* identifierNode, BfLocalVariable* v mInsertEndIdx = identifierNode->GetSrcEnd(); } } - } + } else if (mResolveType == BfResolveType_GetResultString) { if (IsAutocompleteNode(identifierNode)) - { + { String constStr; if (varDecl->mConstValue.IsConst()) - constStr = ConstantToString(mModule->mBfIRBuilder, varDecl->mConstValue); + constStr = ConstantToString(mModule->mBfIRBuilder, varDecl->mConstValue); if (!constStr.IsEmpty()) { mResultString = constStr; } else { - SetResultStringType(varDecl->mResolvedType); + SetResultStringType(varDecl->mResolvedType); } } - } + } } void BfAutoComplete::CheckFieldRef(BfAstNode* identifierNode, BfFieldInstance* fieldInst) -{ +{ if (mResolveType == BfResolveType_GetSymbolInfo) { if (mDefField != NULL) @@ -3053,14 +3048,14 @@ void BfAutoComplete::CheckLabel(BfIdentifierNode* identifierNode, BfAstNode* pre if (identifierNode != NULL) { if ((mModule->mCompiler->mResolvePassData != NULL) && (scopeData != NULL)) - { + { auto rootMethodState = mModule->mCurMethodState->GetRootMethodState(); mModule->mCompiler->mResolvePassData->HandleLocalReference(identifierNode, rootMethodState->mMethodInstance->GetOwner()->mTypeDef, rootMethodState->mMethodInstance->mMethodDef, scopeData->mScopeLocalId); } if (!IsAutocompleteNode(identifierNode)) return; - + if (scopeData != NULL) { if (mResolveType == BfResolveType_GoToDefinition) @@ -3104,7 +3099,7 @@ void BfAutoComplete::CheckLabel(BfIdentifierNode* identifierNode, BfAstNode* pre if (!IsAutocompleteNode(precedingNode, expectSpacing)) return; - + auto bfParser = precedingNode->GetSourceData()->ToParser(); if (bfParser->mCursorIdx != precedingNode->GetSrcEnd() + expectSpacing - 1) return; @@ -3125,12 +3120,12 @@ void BfAutoComplete::CheckLabel(BfIdentifierNode* identifierNode, BfAstNode* pre void BfAutoComplete::CheckNamespace(BfAstNode* node, const BfAtomComposite& namespaceName) { if (mResolveType == BfResolveType_GetSymbolInfo) - { + { if (IsAutocompleteNode(node)) - { + { int namespaceCount = namespaceName.mSize; auto checkNode = node; - + while (auto qualifiedTypeRef = BfNodeDynCast(checkNode)) { if (!IsAutocompleteNode(qualifiedTypeRef->mLeft)) @@ -3145,9 +3140,9 @@ void BfAutoComplete::CheckNamespace(BfAstNode* node, const BfAtomComposite& name namespaceCount--; checkNode = qualifiedNameNode->mLeft; } - - while (auto qualifiedTypeRef = BfNodeDynCast(checkNode)) - checkNode = qualifiedTypeRef->mRight; + + while (auto qualifiedTypeRef = BfNodeDynCast(checkNode)) + checkNode = qualifiedTypeRef->mRight; while (auto qualifiedNameNode = BfNodeDynCast(checkNode)) checkNode = qualifiedNameNode->mRight; @@ -3156,13 +3151,13 @@ void BfAutoComplete::CheckNamespace(BfAstNode* node, const BfAtomComposite& name mInsertStartIdx = checkNode->GetSrcStart(); mInsertEndIdx = checkNode->GetSrcEnd(); mDefNamespace.Set(namespaceName.mParts, namespaceCount, NULL, 0); - } + } } - } + } } void BfAutoComplete::AddTypeInstanceEntry(BfTypeInstance* typeInst) -{ +{ String bestTypeName = mModule->TypeToString(typeInst, BfTypeNameFlag_ReduceName); if (typeInst->IsValueType()) @@ -3176,16 +3171,16 @@ bool BfAutoComplete::CheckDocumentation(AutoCompleteEntry* entry, BfCommentNode* { if (mDocumentationEntryName.IsEmpty()) return false; - + if (mDocumentationEntryName != entry->mDisplay) return false; if (documentation != NULL) { StringT<128> str; - documentation->GetDocString(str); + documentation->GetDocString(str); entry->mDocumentation = mAlloc.AllocString(str); - } + } return true; } @@ -3206,9 +3201,9 @@ void BfAutoComplete::CheckEmptyStart(BfAstNode* prevNode, BfType* type) wantCursorIdx++; if (prevNode->GetSourceData()->ToParser()->mCursorIdx != wantCursorIdx) return; - + AddTypeInstanceEntry(type->ToTypeInstance()); - CheckIdentifier(NULL); + CheckIdentifier(NULL); mInsertStartIdx = wantCursorIdx + 1; mInsertEndIdx = mInsertStartIdx; } @@ -3267,7 +3262,7 @@ void BfAutoComplete::CheckInterfaceFixit(BfTypeInstance* typeInstance, BfAstNode if (!CheckFixit(node)) return; if (typeInstance == NULL) - return; + return; if (typeInstance->IsInterface()) return; @@ -3297,7 +3292,7 @@ void BfAutoComplete::CheckInterfaceFixit(BfTypeInstance* typeInstance, BfAstNode continue; // Don't consider overrides here // If we have "ProjA depends on LibBase", "ProjB depends on LibBase", then a type ClassC in LibBase implementing IFaceD, - // where IFaceD gets extended with MethodE in ProjA, an implementing MethodE is still required to exist on ClassC -- + // where IFaceD gets extended with MethodE in ProjA, an implementing MethodE is still required to exist on ClassC -- // the visibility is bidirectional. A type ClassF implementing IFaceD inside ProjB will not be required to implement // MethodE, however if ((!ifaceInst->IsTypeMemberAccessible(ifaceMethodInst->mMethodDef->mDeclaringType, ifaceTypeInst.mDeclaringType)) && @@ -3316,7 +3311,7 @@ void BfAutoComplete::CheckInterfaceFixit(BfTypeInstance* typeInstance, BfAstNode } if (!missingMethods.IsEmpty()) - { + { BfParserData* parser = declTypeDef->mTypeDeclaration->GetSourceData()->ToParserData(); if (parser != NULL) { @@ -3511,16 +3506,16 @@ void BfAutoComplete::FixitAddCase(BfTypeInstance* typeInst, const StringImpl& ca } } - bool isSimpleCase = false; + bool isSimpleCase = false; if (!typeInst->mTypeDef->mFields.IsEmpty()) - { + { if (auto block = BfNodeDynCast(typeInst->mTypeDef->mTypeDeclaration->mDefineNode)) { bool endsInComma = false; if (!block->mChildArr.IsEmpty()) - { - auto lastNode = block->mChildArr.back(); + { + auto lastNode = block->mChildArr.back(); if (auto tokenNode = BfNodeDynCast(lastNode)) { if (tokenNode->mToken == BfToken_Comma) @@ -3553,7 +3548,7 @@ void BfAutoComplete::FixitAddCase(BfTypeInstance* typeInst, const StringImpl& ca } } - if (!isSimpleCase) + if (!isSimpleCase) { fieldStr += "|case "; fieldStr += caseName; @@ -3561,13 +3556,13 @@ void BfAutoComplete::FixitAddCase(BfTypeInstance* typeInst, const StringImpl& ca if (!fieldTypes.IsEmpty()) { fieldStr += "("; - FixitGetParamString(fieldTypes, fieldStr); + FixitGetParamString(fieldTypes, fieldStr); fieldStr += ")"; } fieldStr += ";"; - } + } - AddEntry(AutoCompleteEntry("fixit", StrFormat("Create case '%s' in '%s'\taddField|%s|%s", caseName.c_str(), fullName.c_str(), + AddEntry(AutoCompleteEntry("fixit", StrFormat("Create case '%s' in '%s'\taddField|%s|%s", caseName.c_str(), fullName.c_str(), FixitGetLocation(parser->mParserData, fileLoc).c_str(), fieldStr.c_str()).c_str())); } @@ -3615,7 +3610,7 @@ void BfAutoComplete::FixitGetParamString(const BfTypeVector& paramTypes, StringI { checkName[0] = tolower(checkName[0]); for (int i = 1; i < (int)checkName.length(); i++) - { + { if ((i + 1 < (int)checkName.length()) && (islower(checkName[i + 1]))) break; @@ -3663,56 +3658,56 @@ String BfAutoComplete::FixitGetLocation(BfParserData* parser, int insertPos) String BfAutoComplete::ConstantToString(BfIRConstHolder* constHolder, BfIRValue id) { char str[32]; - + int stringId = mModule->GetStringPoolIdx(id, constHolder); if (stringId != -1) { BfStringPoolEntry* entry; if (mModule->mContext->mStringObjectIdMap.TryGetValue(stringId, &entry)) { - String result = "\""; + String result = "\""; result += SlashString(entry->mString, true, true, true); result += "\""; return result; - } + } } - + auto constant = constHolder->GetConstant(id); switch (constant->mTypeCode) { case BfTypeCode_Boolean: return StrFormat(":(bool) %s", constant->mBool ? "true" : "false"); case BfTypeCode_UInt8: - return StrFormat(":(uint8) %llu", constant->mUInt64); + return StrFormat(":(uint8) %llu", constant->mUInt64); case BfTypeCode_UInt16: - return StrFormat(":(uint16) %llu", constant->mUInt64); + return StrFormat(":(uint16) %llu", constant->mUInt64); case BfTypeCode_UInt32: - return StrFormat(":(uint32) %llu", constant->mUInt64); + return StrFormat(":(uint32) %llu", constant->mUInt64); case BfTypeCode_UInt64: - return StrFormat(":(uint64) %llu", constant->mUInt64); + return StrFormat(":(uint64) %llu", constant->mUInt64); case BfTypeCode_Int8: - return StrFormat(":(int8) %lld", constant->mInt64); + return StrFormat(":(int8) %lld", constant->mInt64); case BfTypeCode_Int16: return StrFormat(":(int16) %lld", constant->mInt64); case BfTypeCode_Int32: - return StrFormat(":(int32) %lld", constant->mInt64); + return StrFormat(":(int32) %lld", constant->mInt64); case BfTypeCode_Int64: - return StrFormat(":(int64) %lld", constant->mInt64); + return StrFormat(":(int64) %lld", constant->mInt64); - case BfTypeCode_Float: - { + case BfTypeCode_Float: + { ExactMinimalFloatToStr((float)constant->mDouble, str); String result; - result += str; + result += str; result += "f"; return result; - } + } case BfTypeCode_Double: { ExactMinimalDoubleToStr(constant->mDouble, str); String result; - result += str; + result += str; return result; } default: @@ -3795,7 +3790,7 @@ void BfAutoComplete::FixitCheckNamespace(BfTypeDef* activeTypeDef, BfAstNode* ty BfSizedAtomComposite namespaceComposite; String namespaceString = typeRef->ToString(); bool isValid = mSystem->ParseAtomComposite(namespaceString, namespaceComposite); - + bool hasNamespace = false; if (activeTypeDef != NULL) hasNamespace = activeTypeDef->mNamespaceSearch.Contains(namespaceComposite); @@ -3806,7 +3801,7 @@ void BfAutoComplete::FixitCheckNamespace(BfTypeDef* activeTypeDef, BfAstNode* ty FixitGetLocation(parserData, typeRef->GetSrcStart()).c_str(), nextDotToken->GetSrcEnd() - typeRef->GetSrcStart()).c_str())); } else - { + { FixitAddNamespace(typeRef, namespaceString); } } @@ -3829,7 +3824,7 @@ void BfAutoComplete::FixitAddConstructor(BfTypeInstance *typeInstance) auto methodInstance = mModule->GetRawMethodInstanceAtIdx(baseType, methodDef->mIdx); String ctorShowName; - + int insertPos = FixitGetMemberInsertPos(mModule->mCurTypeInstance->mTypeDef); String methodStr = "\f\a"; if (methodInstance->mMethodDef->mHasAppend) @@ -3850,7 +3845,7 @@ void BfAutoComplete::FixitAddConstructor(BfTypeInstance *typeInstance) case BfParamKind_Params: methodStr += "params "; break; - default: + default: break; } methodStr += mModule->TypeToString(methodInstance->GetParamType(paramIdx), BfTypeNameFlag_ReduceName); @@ -3858,7 +3853,7 @@ void BfAutoComplete::FixitAddConstructor(BfTypeInstance *typeInstance) methodStr += methodInstance->GetParamName(paramIdx); useParamIdx++; } - methodStr += ") : base("; + methodStr += ") : base("; ctorShowName += "this("; useParamIdx = 0; @@ -3931,10 +3926,10 @@ void BfAutoComplete::FixitAddFullyQualify(BfAstNode* refNode, const StringImpl& for (int entryIdx = 0; entryIdx < foundList.mSize - 1; entryIdx++) { auto& entry = foundList[entryIdx]; - if (entryIdx > 0) - fullName += "."; - if (!mModule->CheckProtection(protectionCheckFlags, entry.mTypeInstance, entry.GetDeclaringType(mModule)->mProject, entry.GetProtection(), mModule->mCurTypeInstance)) - fullName += "[Friend]"; + if (entryIdx > 0) + fullName += "."; + if (!mModule->CheckProtection(protectionCheckFlags, entry.mTypeInstance, entry.GetDeclaringType(mModule)->mProject, entry.GetProtection(), mModule->mCurTypeInstance)) + fullName += "[Friend]"; fullName += entry.GetName(mModule); } @@ -3946,4 +3941,4 @@ void BfAutoComplete::FixitAddFullyQualify(BfAstNode* refNode, const StringImpl& parser->mFileName.c_str(), refNode->mSrcStart, fullName.c_str()).c_str())); } -} +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfAutoComplete.h b/IDEHelper/Compiler/BfAutoComplete.h index 6e7f30f9..adb40c3f 100644 --- a/IDEHelper/Compiler/BfAutoComplete.h +++ b/IDEHelper/Compiler/BfAutoComplete.h @@ -62,7 +62,7 @@ public: } bool operator==(const AutoCompleteEntry& other) const - { + { return strcmp(mDisplay, other.mDisplay) == 0; } }; @@ -73,7 +73,7 @@ template <> struct BeefHash { size_t operator()(const Beefy::AutoCompleteEntry& val) - { + { intptr hash = 0; const char* curPtr = val.mDisplay; while (true) @@ -92,7 +92,7 @@ NS_BF_BEGIN class AutoCompleteBase { -public: +public: class EntryLess { public: @@ -103,7 +103,7 @@ public: result = strcmp(left.mDisplay, right.mDisplay); return result < 0; } - }; + }; public: BumpAllocator mAlloc; @@ -128,13 +128,13 @@ public: class BfAutoComplete : public AutoCompleteBase { -public: +public: class MethodMatchEntry { - public: + public: BfMethodDef* mMethodDef; BfFieldInstance* mPayloadEnumField; - BfTypeInstance* mTypeInstance; + BfTypeInstance* mTypeInstance; BfTypeVector mGenericArguments; BfMethodInstance* mCurMethodInstance; @@ -142,34 +142,34 @@ public: { mMethodDef = NULL; mPayloadEnumField = NULL; - mTypeInstance = NULL; + mTypeInstance = NULL; mCurMethodInstance = NULL; } }; class MethodMatchInfo { - public: + public: BfTypeInstance* mCurTypeInstance; BfMethodInstance* mCurMethodInstance; Array mInstanceList; int mInvocationSrcIdx; - int mBestIdx; - int mPrevBestIdx; + int mBestIdx; + int mPrevBestIdx; bool mHadExactMatch; - int mMostParamsMatched; + int mMostParamsMatched; Array mSrcPositions; // start, commas, end - + public: MethodMatchInfo() { mInvocationSrcIdx = -1; mCurTypeInstance = NULL; mCurMethodInstance = NULL; - mBestIdx = 0; - mPrevBestIdx = -1; + mBestIdx = 0; + mPrevBestIdx = -1; mHadExactMatch = false; - mMostParamsMatched = 0; + mMostParamsMatched = 0; } ~MethodMatchInfo() @@ -177,10 +177,10 @@ public: } }; -public: +public: BfModule* mModule; BfCompiler* mCompiler; - BfSystem* mSystem; + BfSystem* mSystem; MethodMatchInfo* mMethodMatchInfo; bool mIsCapturingMethodMatchInfo; String mDefaultSelection; @@ -196,8 +196,8 @@ public: bool mForceAllowNonStatic; int mCursorLineStart; int mCursorLineEnd; - - int mReplaceLocalId; + + int mReplaceLocalId; BfMethodDef* mDefMethod; BfTypeDef* mDefType; BfFieldDef* mDefField; @@ -206,7 +206,7 @@ public: int mDefMethodGenericParamIdx; int mDefTypeGenericParamIdx; -public: +public: BfProject* GetActiveProject(); bool WantsEntries(); bool CheckProtection(BfProtection protection, BfTypeDef* typeDef, bool allowProtected, bool allowPrivate); @@ -216,9 +216,9 @@ public: bool IsAutocompleteNode(BfAstNode* node, int lengthAdd = 0, int startAdd = 0); bool IsAutocompleteNode(BfAstNode* startNode, BfAstNode* endNode, int lengthAdd = 0, int startAdd = 0); bool IsAutocompleteLineNode(BfAstNode* node); - BfTypedValue LookupTypeRefOrIdentifier(BfAstNode* node, bool* isStatic, BfEvalExprFlags evalExprFlags = BfEvalExprFlags_None, BfType* expectingType = NULL); + BfTypedValue LookupTypeRefOrIdentifier(BfAstNode* node, bool* isStatic, BfEvalExprFlags evalExprFlags = BfEvalExprFlags_None, BfType* expectingType = NULL); void SetDefinitionLocation(BfAstNode* astNode, bool force = false); - bool IsAttribute(BfTypeInstance* typeInst); + bool IsAttribute(BfTypeInstance* typeInst); void AddMethod(BfTypeInstance* typeInstance, BfMethodDef* methodDef, BfMethodInstance* methodInstance, BfMethodDeclaration* methodDecl, const StringImpl& methodName, const StringImpl& filter); void AddField(BfTypeInstance* typeInst, BfFieldDef* fieldDef, BfFieldInstance* fieldInstance, const StringImpl& filter); void AddProp(BfTypeInstance* typeInst, BfPropertyDef* propDef, const StringImpl& filter); @@ -228,26 +228,26 @@ public: void AddTypeMembers(BfTypeInstance* typeInst, bool addStatic, bool addNonStatic, const StringImpl& filter, BfTypeInstance* startType, bool allowInterfaces, bool allowImplicitThis, bool checkOuterType); void AddSelfResultTypeMembers(BfTypeInstance* typeInst, BfTypeInstance* selfType, const StringImpl& filter, bool allowPrivate); bool InitAutocomplete(BfAstNode* dotNode, BfAstNode* nameNode, String& filter); - void AddEnumTypeMembers(BfTypeInstance* typeInst, const StringImpl& filter, bool allowProtected, bool allowPrivate); + void AddEnumTypeMembers(BfTypeInstance* typeInst, const StringImpl& filter, bool allowProtected, bool allowPrivate); void AddExtensionMethods(BfTypeInstance* targetType, BfTypeInstance* extensionContainer, const StringImpl& filter, bool allowProtected, bool allowPrivate); void AddTopLevelNamespaces(BfAstNode* identifierNode); void AddTopLevelTypes(BfAstNode* identifierNode, bool onlyAttribute = false); void AddOverrides(const StringImpl& filter); - void UpdateReplaceData(); + void UpdateReplaceData(); void AddTypeInstanceEntry(BfTypeInstance* typeInst); bool CheckDocumentation(AutoCompleteEntry* entry, BfCommentNode* documentation); bool GetMethodInfo(BfMethodInstance* methodInst, StringImpl* methodName, StringImpl* insertString, bool isImplementing, bool isExplicitInterface); void FixitGetParamString(const BfTypeVector& paramTypes, StringImpl& outStr); int FixitGetMemberInsertPos(BfTypeDef* typeDef); String FixitGetLocation(BfParserData* parserData, int insertPos); - String ConstantToString(BfIRConstHolder* constHolder, BfIRValue id); + String ConstantToString(BfIRConstHolder* constHolder, BfIRValue id); public: BfAutoComplete(BfResolveType resolveType = BfResolveType_Autocomplete, bool doFuzzyAutoComplete = false); ~BfAutoComplete(); void SetModule(BfModule* module); - void Clear(); + void Clear(); void RemoveMethodMatchInfo(); void ClearMethodMatchEntries(); @@ -256,21 +256,21 @@ public: bool CheckExplicitInterface(BfTypeInstance* interfaceType, BfAstNode* dotToken, BfAstNode* memberName); void CheckTypeRef(BfTypeReference* typeRef, bool mayBeIdentifier, bool isInExpression = false, bool onlyAttribute = false); void CheckAttributeTypeRef(BfTypeReference* typeRef); - void CheckInvocation(BfAstNode* invocationNode, BfTokenNode* openParen, BfTokenNode* closeParen, const BfSizedArray& commas); + void CheckInvocation(BfAstNode* invocationNode, BfTokenNode* openParen, BfTokenNode* closeParen, const BfSizedArray& commas); void CheckNode(BfAstNode* node, bool mayBeIdentifier, bool isInExpression = false); void CheckMethod(BfMethodDeclaration* methodDeclaration, bool isLocalMethod); - void CheckProperty(BfPropertyDeclaration* propertyDeclaration); + void CheckProperty(BfPropertyDeclaration* propertyDeclaration); void CheckVarResolution(BfAstNode* varTypeRef, BfType* resolvedTypeRef); void CheckResult(BfAstNode* node, const BfTypedValue& typedValue); void CheckLocalDef(BfAstNode* identifierNode, BfLocalVariable* varDecl); void CheckLocalRef(BfAstNode* identifierNode, BfLocalVariable* varDecl); - void CheckFieldRef(BfAstNode* identifierNode, BfFieldInstance* fieldInst); + void CheckFieldRef(BfAstNode* identifierNode, BfFieldInstance* fieldInst); void CheckLabel(BfIdentifierNode* identifierNode, BfAstNode* precedingNode, BfScopeData* scopeData); void CheckNamespace(BfAstNode* node, const BfAtomComposite& namespaceName); - void CheckEmptyStart(BfAstNode* prevNode, BfType* type); - bool CheckFixit(BfAstNode* node); + void CheckEmptyStart(BfAstNode* prevNode, BfType* type); + bool CheckFixit(BfAstNode* node); void CheckInterfaceFixit(BfTypeInstance* typeInstance, BfAstNode* node); - + void FixitAddMember(BfTypeInstance* typeInst, BfType* fieldType, const StringImpl& fieldName, bool isStatic, BfTypeInstance* referencedFrom); void FixitAddCase(BfTypeInstance * typeInst, const StringImpl & caseName, const BfTypeVector & fieldTypes); void FixitAddMethod(BfTypeInstance* typeInst, const StringImpl& methodName, BfType* returnType, const BfTypeVector& paramTypes, bool wantStatic); diff --git a/IDEHelper/Compiler/BfCodeGen.cpp b/IDEHelper/Compiler/BfCodeGen.cpp index dc1a8040..4bd41ff6 100644 --- a/IDEHelper/Compiler/BfCodeGen.cpp +++ b/IDEHelper/Compiler/BfCodeGen.cpp @@ -57,7 +57,6 @@ USING_NS_BF; using namespace llvm; - String BfCodeGenDirectoryData::GetDataFileName() { return mDirectoryName + "/build.dat"; @@ -89,7 +88,7 @@ void BfCodeGenDirectoryData::Read() for (int fileIdx = 0; fileIdx < numFiles; fileIdx++) { String fileName = fileStream.ReadAscii32SizedString(); - BfCodeGenFileData fileData; + BfCodeGenFileData fileData; fileStream.Read(&fileData.mIRHash, sizeof(Val128)); fileStream.Read(&fileData.mIROrderedHash, sizeof(Val128)); fileStream.Read(&fileData.mLastWasObjectWrite, sizeof(bool)); @@ -159,7 +158,7 @@ void BfCodeGenDirectoryData::Write() } void BfCodeGenDirectoryData::Verify() -{ +{ if (!mError.empty()) return; @@ -171,12 +170,12 @@ void BfCodeGenDirectoryData::Verify() } else { - mError = "Build directory corrupted, perform clean"; - } + mError = "Build directory corrupted, perform clean"; + } } void BfCodeGenDirectoryData::Clear() -{ +{ mFileMap.Clear(); mBuildSettings.Clear(); } @@ -187,16 +186,16 @@ bool BfCodeGenDirectoryData::CheckCache(const StringImpl& fileName, Val128 hash, Verify(); BfCodeGenFileData* fileData = NULL; - + if (!mFileMap.TryAdd(fileName, NULL, &fileData)) - { + { if ((fileData->mLastWasObjectWrite) && (disallowObjectWrite)) return false; if (outOrderedHash != NULL) *outOrderedHash = fileData->mIROrderedHash; - if (fileData->mIRHash == hash) - return true; - fileData->mIRHash = hash; + if (fileData->mIRHash == hash) + return true; + fileData->mIRHash = hash; return false; } @@ -212,9 +211,9 @@ void BfCodeGenDirectoryData::SetHash(const StringImpl& fileName, Val128 hash, Va BfCodeGenFileData* fileData = NULL; - mFileMap.TryAdd(fileName, NULL, &fileData); + mFileMap.TryAdd(fileName, NULL, &fileData); fileData->mIRHash = hash; - fileData->mIROrderedHash = orderedHash; + fileData->mIROrderedHash = orderedHash; fileData->mLastWasObjectWrite = isObjectWrite; } @@ -223,7 +222,6 @@ void BfCodeGenDirectoryData::ClearHash(const StringImpl& fileName) mFileMap.Remove(fileName); } - void BfCodeGenDirectoryData::FileFailed() { mFileFailed = true; @@ -240,7 +238,7 @@ String BfCodeGenDirectoryData::GetValue(const StringImpl& key) } void BfCodeGenDirectoryData::SetValue(const StringImpl& key, const StringImpl& value) -{ +{ mBuildSettings[key] = value; } @@ -265,16 +263,16 @@ void DbgSaveData(BfCodeGenRequest* genRequest) ////////////////////////////////////////////////////////////////////////// BfCodeGenThread::BfCodeGenThread() -{ +{ mShuttingDown = false; - mRunning = false; + mRunning = false; mThreadIdx = 0; mCodeGen = NULL; } BfCodeGenThread::~BfCodeGenThread() { - Shutdown(); + Shutdown(); } void BfCodeGenThread::RunLoop() @@ -282,21 +280,21 @@ void BfCodeGenThread::RunLoop() String threadName = StrFormat("CodeGen/Worker %d", mThreadIdx); BpSetThreadName(threadName.c_str()); BfpThread_SetName(NULL, threadName.c_str(), NULL); - + while (!mShuttingDown) - { + { BfCodeGenRequest* request = NULL; { AutoCrit autoCrit(mCodeGen->mPendingRequestCritSect); if (!mCodeGen->mPendingRequests.IsEmpty()) { request = mCodeGen->mPendingRequests[0]; - mCodeGen->mPendingRequests.RemoveAt(0); + mCodeGen->mPendingRequests.RemoveAt(0); } } if (request == NULL) - { + { mCodeGen->mRequestEvent.WaitFor(20); continue; } @@ -318,7 +316,7 @@ void BfCodeGenThread::RunLoop() #ifndef CODEGEN_DISABLE_CACHE { - AutoCrit autoCrit(mCodeGen->mCacheCritSect); + AutoCrit autoCrit(mCodeGen->mCacheCritSect); dirCache = mCodeGen->GetDirCache(cacheDir); //For testing only! @@ -328,11 +326,11 @@ void BfCodeGenThread::RunLoop() fileStr.Write(request->mData.mVals, request->mData.mSize); }*/ - HashContext hashCtx; + HashContext hashCtx; hashCtx.Mixin(request->mOptions.mHash); - hashCtx.Mixin(request->mData.mVals, request->mData.mSize); + hashCtx.Mixin(request->mData.mVals, request->mData.mSize); hash = hashCtx.Finish128(); - + hasCacheMatch = dirCache->CheckCache(cacheFileName, hash, &orderedHash, isLibWrite); #ifdef BF_PLATFORM_WINDOWS @@ -346,10 +344,9 @@ void BfCodeGenThread::RunLoop() hash = Val128(); hasCacheMatch = false; } - } + } #endif - } #endif @@ -360,7 +357,7 @@ void BfCodeGenThread::RunLoop() hasCacheMatch = false; #endif - String errorMsg; + String errorMsg; bool doBEProcessing = true; // TODO: Normally 'true' so we do ordered cache check for LLVM too if (request->mOptions.mOptLevel == BfOptLevel_OgPlus) @@ -375,7 +372,7 @@ void BfCodeGenThread::RunLoop() } else { -#ifdef BF_PLATFORM_WINDOWS +#ifdef BF_PLATFORM_WINDOWS BeIRCodeGen* beIRCodeGen = new BeIRCodeGen(); defer ( delete beIRCodeGen; ); @@ -383,17 +380,17 @@ void BfCodeGenThread::RunLoop() beIRCodeGen->SetConfigConst(BfIRConfigConst_DynSlotOfs, request->mOptions.mDynSlotOfs); if (doBEProcessing) - { - BP_ZONE("ProcessBfIRData"); + { + BP_ZONE("ProcessBfIRData"); beIRCodeGen->Init(request->mData); BeHashContext hashCtx; hashCtx.Mixin(request->mOptions.mHash); - beIRCodeGen->Hash(hashCtx); + beIRCodeGen->Hash(hashCtx); auto newOrderedHash = hashCtx.Finish128(); BfLogX(2, "Ordered hash for %s New:%s Old:%s\n", cacheFileName.c_str(), newOrderedHash.ToString().c_str(), orderedHash.ToString().c_str()); hasCacheMatch = newOrderedHash == orderedHash; - + errorMsg = beIRCodeGen->mErrorMsg; orderedHash = newOrderedHash; } @@ -402,10 +399,10 @@ void BfCodeGenThread::RunLoop() { result.mType = BfCodeGenResult_DoneCached; } - + #ifndef CODEGEN_DISABLE_CACHE { - AutoCrit autoCrit(mCodeGen->mCacheCritSect); + AutoCrit autoCrit(mCodeGen->mCacheCritSect); dirCache->SetHash(cacheFileName, hash, orderedHash, !isLibWrite); } #endif @@ -416,7 +413,7 @@ void BfCodeGenThread::RunLoop() // } else if (request->mOptions.mOptLevel == BfOptLevel_OgPlus) - { + { #ifdef BF_PLATFORM_WINDOWS BP_ZONE("BfCodeGen::RunLoop.Beef"); @@ -432,7 +429,7 @@ void BfCodeGenThread::RunLoop() { if (!errorMsg.empty()) errorMsg += "\n"; - errorMsg += "Failed writing IR '" + fileName + "': " + ec.message(); + errorMsg += "Failed writing IR '" + fileName + "': " + ec.message(); } else fs.WriteSNZ(str); @@ -445,9 +442,9 @@ void BfCodeGenThread::RunLoop() BfLogX(2, "Generating obj %s\n", request->mOutFileName.c_str()); BeCOFFObject coffObject; - coffObject.mWriteToLib = request->mOptions.mWriteToLib; + coffObject.mWriteToLib = request->mOptions.mWriteToLib; if (!coffObject.Generate(beIRCodeGen->mBeModule, objFileName)) - errorMsg = StrFormat("Failed to write object file: %s", objFileName.c_str()); + errorMsg = StrFormat("Failed to write object file: %s", objFileName.c_str()); if (!beIRCodeGen->mErrorMsg.IsEmpty()) { @@ -467,14 +464,14 @@ void BfCodeGenThread::RunLoop() BfIRCodeGen* llvmIRCodeGen = new BfIRCodeGen(); llvmIRCodeGen->SetCodeGenOptions(request->mOptions); llvmIRCodeGen->SetConfigConst(BfIRConfigConst_VirtualMethodOfs, request->mOptions.mVirtualMethodOfs); - llvmIRCodeGen->SetConfigConst(BfIRConfigConst_DynSlotOfs, request->mOptions.mDynSlotOfs); + llvmIRCodeGen->SetConfigConst(BfIRConfigConst_DynSlotOfs, request->mOptions.mDynSlotOfs); llvmIRCodeGen->ProcessBfIRData(request->mData); - + errorMsg = llvmIRCodeGen->mErrorMsg; llvmIRCodeGen->mErrorMsg.Clear(); if (errorMsg.IsEmpty()) - { + { if (request->mOptions.mWriteLLVMIR) { BP_ZONE("BfCodeGen::RunLoop.LLVM.IR"); @@ -503,16 +500,16 @@ void BfCodeGenThread::RunLoop() result.mType = BfCodeGenResult_Failed; dirCache->FileFailed(); } - } + } } - + if (!llvmIRCodeGen->mErrorMsg.IsEmpty()) { if (!errorMsg.IsEmpty()) errorMsg += "\n"; errorMsg += llvmIRCodeGen->mErrorMsg; } - + delete llvmIRCodeGen; } } @@ -538,9 +535,9 @@ void BfCodeGenThread::RunLoop() // It's an extern request, so we own this bool deleteRequest = false; if (request->mExternResultPtr != NULL) - { + { *request->mExternResultPtr = result; - deleteRequest = true; + deleteRequest = true; } // We need this fence for BF_USE_CODEGEN_RELEASE_THUNK usage- because we can't access the request anymore after setting @@ -549,21 +546,21 @@ void BfCodeGenThread::RunLoop() AutoCrit autoCrit(mCodeGen->mPendingRequestCritSect); request->mResult = result; - mCodeGen->mDoneEvent.Set(); + mCodeGen->mDoneEvent.Set(); if (deleteRequest) delete request; - } + } } mRunning = false; - mCodeGen->mDoneEvent.Set(); + mCodeGen->mDoneEvent.Set(); } void BfCodeGenThread::Shutdown() { mShuttingDown = true; if (mRunning) - mCodeGen->mRequestEvent.Set(true); + mCodeGen->mRequestEvent.Set(true); while (mRunning) { @@ -580,11 +577,11 @@ static void BFP_CALLTYPE RunLoopThunk(void* codeGenThreadP) void BfCodeGenThread::Start() { - mRunning = true; + mRunning = true; //TODO: How much mem do we need? WTF- we have 32MB set before! auto mThread = BfpThread_Create(RunLoopThunk, (void*)this, 1024 * 1024, BfpThreadCreateFlag_StackSizeReserve); BfpThread_SetPriority(mThread, BfpThreadPriority_Low, NULL); - BfpThread_Release(mThread); + BfpThread_Release(mThread); } ////////////////////////////////////////////////////////////////////////// @@ -592,7 +589,7 @@ void BfCodeGenThread::Start() BfCodeGen::BfCodeGen() { mAttemptedReleaseThunkLoad = false; - mIsUsingReleaseThunk = false; + mIsUsingReleaseThunk = false; mReleaseModule = NULL; mClearCacheFunc = NULL; mGetVersionFunc = NULL; @@ -600,10 +597,10 @@ BfCodeGen::BfCodeGen() mCancelFunc = NULL; mFinishFunc = NULL; mGenerateObjFunc = NULL; - + mRequestIdx = 0; #ifdef MAX_THREADS - mMaxThreadCount = MAX_THREADS; + mMaxThreadCount = MAX_THREADS; #else mMaxThreadCount = 6; #endif @@ -703,7 +700,7 @@ void BfCodeGen::UpdateStats() auto request = mRequests[0]; if (request->mResult.mType == BfCodeGenResult_NotDone) return; - + RequestComplete(request); delete request; mRequests.RemoveAt(0); @@ -732,7 +729,7 @@ void BfCodeGen::ClearBuildCache() for (auto& dirCachePair : mDirectoryCache) { auto dirData = dirCachePair.mValue; - dirData->Clear(); + dirData->Clear(); } // This just disables reading the cache file, but it does not disable creating // the cache structes in memory and writing them out, thus it's valid to leave @@ -747,9 +744,9 @@ void BfCodeGen::ClearBuildCache() } void BfCodeGen::DoWriteObjectFile(BfCodeGenRequest* codeGenRequest, const void* ptr, int size, const StringImpl& outFileName, BfCodeGenResult* externResultPtr) -{ +{ codeGenRequest->mData.mVals = (uint8*)ptr; - codeGenRequest->mData.mSize = size; + codeGenRequest->mData.mSize = size; codeGenRequest->mOutFileName = outFileName; codeGenRequest->mResult.mType = BfCodeGenResult_NotDone; codeGenRequest->mResult.mErrorMsgBufLen = 0; @@ -769,11 +766,11 @@ void BfCodeGen::DoWriteObjectFile(BfCodeGenRequest* codeGenRequest, const void* auto thread = mThreads[threadIdx]; BP_ZONE("WriteObjectFile_CritSect"); - AutoCrit autoCrit(mPendingRequestCritSect); + AutoCrit autoCrit(mPendingRequestCritSect); mPendingRequests.push_back(codeGenRequest); #ifdef BF_PLATFORM_WINDOWS - BF_ASSERT(!mRequestEvent.mEvent->mManualReset); // Make sure it's out of the SignalAll state + BF_ASSERT(!mRequestEvent.mEvent->mManualReset); // Make sure it's out of the SignalAll state #endif mRequestEvent.Set(); @@ -843,11 +840,11 @@ bool BfCodeGen::ExternWriteObjectFile(BfCodeGenRequest* codeGenRequest) #ifndef BF_USE_CODEGEN_RELEASE_THUNK return false; #endif - + BindReleaseThunks(); if (!mIsUsingReleaseThunk) - return false; + return false; mGenerateObjFunc(codeGenRequest->mData.mVals, codeGenRequest->mData.mSize, codeGenRequest->mOutFileName.c_str(), &codeGenRequest->mResult, codeGenRequest->mOptions); @@ -855,15 +852,15 @@ bool BfCodeGen::ExternWriteObjectFile(BfCodeGenRequest* codeGenRequest) } void BfCodeGen::WriteObjectFile(BfModule* bfModule, const StringImpl& outFileName, const BfCodeGenOptions& options) -{ +{ mQueuedCount++; - + BfLogSys(bfModule->mSystem, "WriteObjectFile %s\n", outFileName.c_str()); - BfCodeGenRequest* codeGenRequest = new BfCodeGenRequest(); + BfCodeGenRequest* codeGenRequest = new BfCodeGenRequest(); mRequests.push_back(codeGenRequest); - - { + + { BP_ZONE("WriteObjectFile_GetBufferData"); bfModule->mBfIRBuilder->GetBufferData(codeGenRequest->mOutBuffer); } @@ -873,13 +870,13 @@ void BfCodeGen::WriteObjectFile(BfModule* bfModule, const StringImpl& outFileNam rootModule = rootModule->mParentModule; codeGenRequest->mSrcModule = rootModule; - codeGenRequest->mOutFileName = outFileName; - codeGenRequest->mData = codeGenRequest->mOutBuffer; + codeGenRequest->mOutFileName = outFileName; + codeGenRequest->mData = codeGenRequest->mOutBuffer; codeGenRequest->mOptions = options; if (ExternWriteObjectFile(codeGenRequest)) - return; + return; - DoWriteObjectFile(codeGenRequest, (void*)&codeGenRequest->mOutBuffer[0], (int)codeGenRequest->mOutBuffer.size(), codeGenRequest->mOutFileName, NULL); + DoWriteObjectFile(codeGenRequest, (void*)&codeGenRequest->mOutBuffer[0], (int)codeGenRequest->mOutBuffer.size(), codeGenRequest->mOutFileName, NULL); #ifdef DBG_FORCE_SYNCHRONIZED while (mRequests.size() != 0) @@ -918,7 +915,7 @@ void BfCodeGen::RequestComplete(BfCodeGenRequest* request) if ((request->mResult.mType == BfCodeGenResult_Failed) || (request->mResult.mType == BfCodeGenResult_Aborted)) { BfCodeGenErrorEntry errorEntry; - errorEntry.mSrcModule = request->mSrcModule; + errorEntry.mSrcModule = request->mSrcModule; errorEntry.mOutFileName = request->mOutFileName; int errorPos = 0; @@ -928,7 +925,7 @@ void BfCodeGen::RequestComplete(BfCodeGenRequest* request) errorEntry.mErrorMessages.push_back(errorStr); errorPos += (int)strlen(errorStr) + 1; } - + mFailedRequests.push_back(errorEntry); } else @@ -970,7 +967,7 @@ void BfCodeGen::ProcessErrors(BfPassInstance* passInstance, bool canceled) { passInstance->Fail(dirEntry->mError); showedCacheError = true; - } + } dirEntry->mError.clear(); } } @@ -1000,7 +997,7 @@ void BfCodeGen::Cancel() { for (auto thread : mThreads) { - thread->mShuttingDown = true; + thread->mShuttingDown = true; } mRequestEvent.Set(true); @@ -1016,9 +1013,9 @@ void BfCodeGen::ClearResults() } bool BfCodeGen::Finish() -{ +{ BP_ZONE("BfCodeGen::Finish"); - + while (mRequests.size() != 0) { auto request = mRequests[0]; @@ -1047,7 +1044,7 @@ bool BfCodeGen::Finish() return false; } - if (mIsUsingReleaseThunk) + if (mIsUsingReleaseThunk) { // Make the thunk release its threads (and more important, its LLVM contexts) mFinishFunc(); @@ -1056,14 +1053,14 @@ bool BfCodeGen::Finish() // We need to shut down these threads to remove their memory for (auto thread : mThreads) { - thread->mShuttingDown = true; - mOldThreads.push_back(thread); + thread->mShuttingDown = true; + mOldThreads.push_back(thread); } mThreads.Clear(); mRequestEvent.Set(true); ClearOldThreads(false); - + // for (auto request : mPendingRequests) // { // if (request->mExternResultPtr != NULL) @@ -1073,7 +1070,7 @@ bool BfCodeGen::Finish() // } // //request->mResult.mType = BfCodeGenResult_Aborted; // //delete request; -// } +// } // mPendingRequests.Clear(); /// @@ -1113,8 +1110,8 @@ BF_EXPORT int BF_CALLTYPE BfCodeGen_GetVersion() BF_EXPORT void BF_CALLTYPE BfCodeGen_ClearCache() { - GetExternCodeGen(); - gExternCodeGen->ClearBuildCache(); + GetExternCodeGen(); + gExternCodeGen->ClearBuildCache(); } BF_EXPORT void BF_CALLTYPE BfCodeGen_Finish() @@ -1129,7 +1126,7 @@ BF_EXPORT void BF_CALLTYPE BfCodeGen_Finish() BF_EXPORT void BF_CALLTYPE BfCodeGen_Kill() { delete gExternCodeGen; - gExternCodeGen = NULL; + gExternCodeGen = NULL; Targets_Delete(); } @@ -1140,11 +1137,10 @@ BF_EXPORT void BF_CALLTYPE BfCodeGen_Cancel() } BF_EXPORT void BF_CALLTYPE BfCodeGen_GenerateObj(const void* ptr, int size, const char* outFileName, BfCodeGenResult* resultPtr, const BfCodeGenOptions& options) -{ +{ GetExternCodeGen(); - BfCodeGenRequest* codeGenRequest = new BfCodeGenRequest(); + BfCodeGenRequest* codeGenRequest = new BfCodeGenRequest(); codeGenRequest->mOptions = options; gExternCodeGen->DoWriteObjectFile(codeGenRequest, ptr, size, outFileName, resultPtr); -} - +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfCodeGen.h b/IDEHelper/Compiler/BfCodeGen.h index e8edec6b..8ae8b955 100644 --- a/IDEHelper/Compiler/BfCodeGen.h +++ b/IDEHelper/Compiler/BfCodeGen.h @@ -45,16 +45,15 @@ public: Array mErrorMessages; }; - class BfCodeGenRequest { -public: +public: BfModule* mSrcModule; BfCodeGenOptions mOptions; BfCodeGenResult mResult; Array mOutBuffer; BfSizedArray mData; - String mOutFileName; + String mOutFileName; BfCodeGenResult* mExternResultPtr; @@ -64,13 +63,13 @@ public: mSrcModule = NULL; mResult.mType = BfCodeGenResult_NotDone; mResult.mErrorMsgBufLen = 0; - mExternResultPtr = NULL; + mExternResultPtr = NULL; } ~BfCodeGenRequest() - { + { } - + void DbgSaveData(); }; @@ -78,18 +77,18 @@ class BfCodeGen; class BfCodeGenThread { -public: - BfCodeGen* mCodeGen; +public: + BfCodeGen* mCodeGen; int mThreadIdx; - //std::vector mRequests; + //std::vector mRequests; volatile bool mShuttingDown; volatile bool mRunning; public: bool RawWriteObjectFile(llvm::Module* module, const StringImpl& outFileName, const BfCodeGenOptions& codeGenOptions); - -public: + +public: BfCodeGenThread(); ~BfCodeGenThread(); @@ -103,7 +102,7 @@ class BfCodeGenFileData { public: Val128 mIRHash; // Equal when exact IR bits are equal - Val128 mIROrderedHash; // Equal when isomorphic (when alphabetically reordered functions hash equally) + Val128 mIROrderedHash; // Equal when isomorphic (when alphabetically reordered functions hash equally) bool mLastWasObjectWrite; }; @@ -115,7 +114,7 @@ public: Dictionary mBuildSettings; String mDirectoryName; bool mDirty; - bool mVerified; + bool mVerified; int64 mFileTime; String mError; bool mFileFailed; @@ -163,18 +162,18 @@ public: typedef void (BF_CALLTYPE* FinishFunc)(); typedef void (BF_CALLTYPE* GenerateObjFunc)(const void* ptr, int size, const char* outFileName, BfCodeGenResult* resultPtr, const BfCodeGenOptions& options); -public: +public: BfpDynLib* mReleaseModule; bool mAttemptedReleaseThunkLoad; bool mIsUsingReleaseThunk; ClearCacheFunc mClearCacheFunc; GetVersionFunc mGetVersionFunc; - KillFunc mKillFunc; + KillFunc mKillFunc; CancelFunc mCancelFunc; FinishFunc mFinishFunc; - GenerateObjFunc mGenerateObjFunc; + GenerateObjFunc mGenerateObjFunc; - Val128 mBackendHash; + Val128 mBackendHash; int mMaxThreadCount; CritSect mThreadsCritSect; Array mThreads; @@ -184,19 +183,19 @@ public: Deque mPendingRequests; SyncEvent mRequestEvent; int mRequestIdx; - SyncEvent mDoneEvent; + SyncEvent mDoneEvent; int mQueuedCount; - int mCompletionCount; + int mCompletionCount; Array mFailedRequests; Array mCodeGenFiles; - + CritSect mCacheCritSect; bool mDisableCacheReads; Dictionary mDirectoryCache; -public: +public: void SetMaxThreads(int maxThreads); void BindReleaseThunks(); void ClearResults(); @@ -208,13 +207,13 @@ public: void ProcessErrors(BfPassInstance* passInstance, bool canceled); BfCodeGenDirectoryData* GetDirCache(const StringImpl& cacheDir); -public: +public: BfCodeGen(); ~BfCodeGen(); void ResetStats(); void UpdateStats(); - void WriteObjectFile(BfModule* module, const StringImpl& outFileName, const BfCodeGenOptions& options); + void WriteObjectFile(BfModule* module, const StringImpl& outFileName, const BfCodeGenOptions& options); String GetBuildValue(const StringImpl& buildDir, const StringImpl& key); void SetBuildValue(const StringImpl& buildDir, const StringImpl& key, const StringImpl& value); void WriteBuildCache(const StringImpl& buildDir); diff --git a/IDEHelper/Compiler/BfCompiler.cpp b/IDEHelper/Compiler/BfCompiler.cpp index 074e4863..d13b9bef 100644 --- a/IDEHelper/Compiler/BfCompiler.cpp +++ b/IDEHelper/Compiler/BfCompiler.cpp @@ -40,7 +40,7 @@ namespace llvm extern bool DebugFlag; } -#define SPLIT_CONTEXTS +#define SPLIT_CONTEXTS Beefy::BfCompiler* gBfCompiler = NULL; @@ -50,11 +50,11 @@ void pt(llvm::Type* t) Beefy::debug_ostream os; t->print(os); - os << "\n"; + os << "\n"; os << " isSized: " << t->isSized() << "\n"; os.flush(); - if (auto pointerType = llvm::dyn_cast(t)) + if (auto pointerType = llvm::dyn_cast(t)) { Beefy::OutputDebugStrF("Element: "); pt(pointerType->getElementType()); @@ -76,7 +76,7 @@ void pt(llvm::DINode* t) { Beefy::debug_ostream os; t->print(os); - os << "\n"; + os << "\n"; os.flush(); } @@ -145,13 +145,13 @@ void PrintUsers(llvm::MDNode* md) return L.second.second < R.second.second; }); for (const auto &Pair : Uses) - { + { auto Owner = Pair.second.first; os << Beefy::StrFormat(" %d %p %d\n", Pair.second.first.isNull(), Pair.first, Pair.second.second, Pair).c_str(); } os << "\n"; - } + } os.flush();*/ } @@ -205,13 +205,12 @@ GlobalVariable* AllocGlobalVariable(Module &M, Type *Ty, bool isConstant, GlobalValue::ThreadLocalMode tlm = GlobalValue::NotThreadLocal, unsigned AddressSpace = 0, bool isExternallyInitialized = false); - #include "BeefySysLib/util/AllocDebug.h" ////////////////////////////////////////////////////////////////////////// BfCompiler::HotData::~HotData() -{ +{ for (auto& kv : mMethodMap) { auto hotMethod = kv.mValue; @@ -229,8 +228,8 @@ BfCompiler::HotData::~HotData() kv.mValue->Deref(); for (auto& kv : mInnerMethods) kv.mValue->Deref(); - for (auto& kv : mMethodMap) - kv.mValue->Deref(); + for (auto& kv : mMethodMap) + kv.mValue->Deref(); } template @@ -257,7 +256,7 @@ static typename TDict::value_type AllocFromMap(TDict& dict, TElement* elem) typename TDict::value_type* valuePtr; if (dict.TryAdd(elem, NULL, &valuePtr)) { - auto val = new typename std::remove_pointer::type(elem); + auto val = new typename std::remove_pointer::type(elem); val->mRefCount++; *valuePtr = val; } @@ -270,7 +269,7 @@ void BfCompiler::HotData::ClearUnused(bool isHotCompile) DeleteUnused(mThisType); DeleteUnused(mAllocation); - DeleteUnused(mDevirtualizedMethods); + DeleteUnused(mDevirtualizedMethods); DeleteUnused(mVirtualDecls); DeleteUnused(mInnerMethods); @@ -297,7 +296,7 @@ BfHotDevirtualizedMethod* BfCompiler::HotData::GetDevirtualizedMethod(BfHotMetho } BfHotFunctionReference* BfCompiler::HotData::GetFunctionReference(BfHotMethod* hotMethod) -{ +{ return AllocFromMap(mFuncPtrs, hotMethod); } @@ -308,12 +307,11 @@ BfHotInnerMethod* BfCompiler::HotData::GetInnerMethod(BfHotMethod* hotMethod) BfHotVirtualDeclaration* BfCompiler::HotData::GetVirtualDeclaration(BfHotMethod* hotMethod) { - return AllocFromMap(mVirtualDecls, hotMethod); + return AllocFromMap(mVirtualDecls, hotMethod); } BfCompiler::HotState::~HotState() { - } bool BfCompiler::HotState::HasPendingChanges(BfTypeInstance* type) @@ -326,7 +324,7 @@ void BfCompiler::HotState::RemovePendingChanges(BfTypeInstance* type) BF_ASSERT(type->mHotTypeData->mPendingDataChange); if (!type->mHotTypeData->mPendingDataChange) return; - type->mHotTypeData->mPendingDataChange = false; + type->mHotTypeData->mPendingDataChange = false; bool didRemove = mPendingDataChanges.Remove(type->mTypeId); BF_ASSERT(didRemove); } @@ -344,7 +342,7 @@ BfCompiler::HotResolveData::~HotResolveData() BfCompiler::BfCompiler(BfSystem* bfSystem, bool isResolveOnly) { memset(&mStats, 0, sizeof(mStats)); - mCompletionPct = 0; + mCompletionPct = 0; mCanceling = false; mHasRequiredTypes = false; mNeedsFullRefresh = false; @@ -358,26 +356,26 @@ BfCompiler::BfCompiler(BfSystem* bfSystem, bool isResolveOnly) mLastRevisionAborted = false; gBfCompiler = this; mSystem = bfSystem; - mCurTypeId = 1; + mCurTypeId = 1; mTypeInitCount = 0; //mMaxInterfaceSlots = 16; mMaxInterfaceSlots = -1; mInterfaceSlotCountChanged = false; mLastHadComptimeRebuilds = false; mHasComptimeRebuilds = false; - mDepsMayHaveDeletedTypes = false; - + mDepsMayHaveDeletedTypes = false; + mHSPreserveIdx = 0; mCompileLogFP = NULL; - mWantsDeferMethodDecls = false; + mWantsDeferMethodDecls = false; mHadCancel = false; mCompileState = CompileState_None; - //mMaxInterfaceSlots = 4; + //mMaxInterfaceSlots = 4; mHotData = NULL; - mHotState = NULL; + mHotState = NULL; mHotResolveData = NULL; - + mBfObjectTypeDef = NULL; mChar32TypeDef = NULL; mFloatTypeDef = NULL; @@ -393,7 +391,7 @@ BfCompiler::BfCompiler(BfSystem* bfSystem, bool isResolveOnly) mIndexTypeDef = NULL; mIndexRangeTypeDef = NULL; mAttributeTypeDef = NULL; - mAttributeUsageAttributeTypeDef = NULL; + mAttributeUsageAttributeTypeDef = NULL; mClassVDataTypeDef = NULL; mCLinkAttributeTypeDef = NULL; mImportAttributeTypeDef = NULL; @@ -407,7 +405,7 @@ BfCompiler::BfCompiler(BfSystem* bfSystem, bool isResolveOnly) mDisableObjectAccessChecksAttributeTypeDef = NULL; mDbgRawAllocDataTypeDef = NULL; mDeferredCallTypeDef = NULL; - mDelegateTypeDef = NULL; + mDelegateTypeDef = NULL; mFunctionTypeDef = NULL; mActionTypeDef = NULL; mEnumTypeDef = NULL; @@ -416,7 +414,7 @@ BfCompiler::BfCompiler(BfSystem* bfSystem, bool isResolveOnly) mConstEvalAttributeTypeDef = NULL; mNoExtensionAttributeTypeDef = NULL; mCheckedAttributeTypeDef = NULL; - mUncheckedAttributeTypeDef = NULL; + mUncheckedAttributeTypeDef = NULL; mGCTypeDef = NULL; mGenericIEnumerableTypeDef = NULL; mGenericIEnumeratorTypeDef = NULL; @@ -433,7 +431,7 @@ BfCompiler::BfCompiler(BfSystem* bfSystem, bool isResolveOnly) mIPrintableTypeDef = NULL; mIHashableTypeDef = NULL; mIComptimeTypeApply = NULL; - mIComptimeMethodApply = NULL; + mIComptimeMethodApply = NULL; mIOnTypeInitTypeDef = NULL; mIOnTypeDoneTypeDef = NULL; mIOnFieldInitTypeDef = NULL; @@ -463,13 +461,13 @@ BfCompiler::BfCompiler(BfSystem* bfSystem, bool isResolveOnly) mReflectFieldInfoTypeDef = NULL; mReflectMethodInfoTypeDef = NULL; mSizedArrayTypeDef = NULL; - mStaticInitAfterAttributeTypeDef = NULL; + mStaticInitAfterAttributeTypeDef = NULL; mStaticInitPriorityAttributeTypeDef = NULL; mStringTypeDef = NULL; mStringViewTypeDef = NULL; mThreadStaticAttributeTypeDef = NULL; mTypeTypeDef = NULL; - mUnboundAttributeTypeDef = NULL; + mUnboundAttributeTypeDef = NULL; mValueTypeTypeDef = NULL; mResultTypeDef = NULL; mObsoleteAttributeTypeDef = NULL; @@ -482,10 +480,10 @@ BfCompiler::BfCompiler(BfSystem* bfSystem, bool isResolveOnly) mLastAutocompleteModule = NULL; - mContext = new BfContext(this); + mContext = new BfContext(this); mCeMachine = new CeMachine(this); mCurCEExecuteId = -1; - mLastMidCompileRefreshRevision = -1; + mLastMidCompileRefreshRevision = -1; } BfCompiler::~BfCompiler() @@ -494,15 +492,15 @@ BfCompiler::~BfCompiler() mCeMachine = NULL; delete mContext; delete mHotData; - delete mHotState; - delete mHotResolveData; + delete mHotState; + delete mHotResolveData; } bool BfCompiler::IsTypeAccessible(BfType* checkType, BfProject* curProject) { if (checkType->IsBoxed()) return IsTypeAccessible(((BfBoxedType*)checkType)->mElementType, curProject); - + BfTypeInstance* typeInst = checkType->ToTypeInstance(); if (typeInst != NULL) { @@ -525,17 +523,17 @@ bool BfCompiler::IsTypeAccessible(BfType* checkType, BfProject* curProject) return curProject->ContainsReference(typeInst->mTypeDef->mProject); } - + if (checkType->IsPointer()) return IsTypeAccessible(((BfPointerType*)checkType)->mElementType, curProject); if (checkType->IsRef()) return IsTypeAccessible(((BfPointerType*)checkType)->mElementType, curProject); - + return true; } bool BfCompiler::IsTypeUsed(BfType* checkType, BfProject* curProject) -{ +{ if (mOptions.mCompileOnDemandKind == BfCompileOnDemandKind_AlwaysInclude) return IsTypeAccessible(checkType, curProject); @@ -551,7 +549,7 @@ bool BfCompiler::IsTypeUsed(BfType* checkType, BfProject* curProject) if (checkType->IsInterface()) return typeInst->mIsReified; - + //TODO: We could check to see if this project has any reified specialized instances... if (checkType->IsUnspecializedType()) return typeInst->mIsReified; @@ -613,17 +611,17 @@ void BfCompiler::FixVDataHash(BfModule* bfModule) } void BfCompiler::CheckModuleStringRefs(BfModule* module, BfVDataModule* vdataModule, int lastModuleRevision, HashSet& foundStringIds, HashSet& dllNameSet, Array& dllMethods, Array& stringValueEntries) -{ +{ for (int stringId : module->mStringPoolRefs) - { + { if (foundStringIds.Add(stringId)) - { + { BfStringPoolEntry& stringPoolEntry = module->mContext->mStringObjectIdMap[stringId]; - + if (IsHotCompile()) { if (vdataModule->mDefinedStrings.Contains(stringId)) - continue; + continue; } StringValueEntry stringEntry; @@ -663,13 +661,13 @@ void BfCompiler::HashModuleVData(BfModule* module, HashContext& vdataHash) module->mStringPoolRefs.Sort([](int lhs, int rhs) { return lhs < rhs; }); vdataHash.Mixin(&module->mStringPoolRefs[0], (int)module->mStringPoolRefs.size() * (int)sizeof(int)); } - + if (module->mImportFileNames.size() > 0) { module->mImportFileNames.Sort([](int lhs, int rhs) { return lhs < rhs; }); vdataHash.Mixin(&module->mImportFileNames[0], (int)module->mImportFileNames.size() * (int)sizeof(int)); } - + auto altModule = module->mNextAltModule; while (altModule != NULL) { @@ -772,7 +770,7 @@ BfIRFunction BfCompiler::CreateLoadSharedLibraries(BfVDataModule* bfModule, Arra if (constant != NULL) { if (constant->IsNull()) - continue; // Invalid + continue; // Invalid strNum = constant->mInt32; } else @@ -792,8 +790,8 @@ BfIRFunction BfCompiler::CreateLoadSharedLibraries(BfVDataModule* bfModule, Arra args.push_back(namePtr); args.push_back(dllHandleVar); BfIRValue dllHandleValue = bfModule->mBfIRBuilder->CreateCall(loadSharedLibraryProc.mFunc, args); - - dllHandleMap[strNum] = dllHandleVar; + + dllHandleMap[strNum] = dllHandleVar; } String methodImportName; @@ -828,7 +826,7 @@ BfIRFunction BfCompiler::CreateLoadSharedLibraries(BfVDataModule* bfModule, Arra } } } - } + } bfModule->mBfIRBuilder->CreateRetVoid(); @@ -907,7 +905,6 @@ void BfCompiler::GetTestMethods(BfVDataModule* bfModule, Array& test vdataHashCtx.Mixin(methodInstance->mMethodDef->mIdx); }; - for (auto type : mContext->mResolvedTypes) { auto typeInstance = type->ToTypeInstance(); @@ -919,8 +916,8 @@ void BfCompiler::GetTestMethods(BfVDataModule* bfModule, Array& test for (auto& methodInstanceGroup : typeInstance->mMethodInstanceGroups) { - if (methodInstanceGroup.mDefault != NULL) - _CheckMethod(typeInstance, methodInstanceGroup.mDefault); + if (methodInstanceGroup.mDefault != NULL) + _CheckMethod(typeInstance, methodInstanceGroup.mDefault); } } } @@ -1041,7 +1038,7 @@ void BfCompiler::EmitTestMethod(BfVDataModule* bfModule, Array& test else { for (int defaultIdx = 0; defaultIdx < (int)methodInstance->mDefaultValues.size(); defaultIdx++) - { + { auto constHolder = methodInstance->GetOwner()->mConstHolder; auto defaultTypedValue = methodInstance->mDefaultValues[defaultIdx]; auto defaultVal = bfModule->ConstantToCurrent(constHolder->GetConstant(defaultTypedValue.mValue), constHolder, defaultTypedValue.mType); @@ -1074,18 +1071,18 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) { bool isHotCompile = IsHotCompile(); if ((isHotCompile) && (bfModule->mProject != mOptions.mHotProject)) - return; - + return; + BP_ZONE("BfCompiler::CreateVData"); BfLogSysM("CreateVData %s\n", bfModule->mProject->mName.c_str()); CompileLog("CreateVData %s\n", bfModule->mProject->mName.c_str()); - + BF_ASSERT_REL(!bfModule->mIsDeleting); bfModule->mProject->mUsedModules.Add(bfModule); auto project = bfModule->mProject; - auto vdataContext = bfModule->mContext; - BF_ASSERT(bfModule->mModuleName == "vdata"); + auto vdataContext = bfModule->mContext; + BF_ASSERT(bfModule->mModuleName == "vdata"); ////////////////////////////////////////////////////////////////////////// @@ -1093,34 +1090,34 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) // Create types we'll need for vdata, so we won't change the vdata hash afterward // bfModule->CreatePointerType(bfModule->GetPrimitiveType(BfTypeCode_NullPtr)); -// +// // /// -// +// // auto typeDefType = bfModule->ResolveTypeDef(mTypeTypeDef)->ToTypeInstance(); // if (!typeDefType) // return; // BF_ASSERT(typeDefType != NULL); // vdataContext->mBfTypeType = typeDefType->ToTypeInstance(); -// +// // auto typeInstanceDefType = bfModule->ResolveTypeDef(mReflectTypeInstanceTypeDef); // if (!typeInstanceDefType) // return; // auto typeInstanceDefTypeInstance = typeInstanceDefType->ToTypeInstance(); -// +// // auto typeDef = mSystem->FindTypeDef("System.ClassVData"); // BF_ASSERT(typeDef != NULL); -// auto bfClassVDataType = bfModule->ResolveTypeDef(typeDef)->ToTypeInstance(); +// auto bfClassVDataType = bfModule->ResolveTypeDef(typeDef)->ToTypeInstance(); // vdataContext->mBfClassVDataPtrType = bfModule->CreatePointerType(bfClassVDataType); ////////////////////////////////////////////////////////////////////////// int numEntries = 0; - int numConcreteTypes = 0; + int numConcreteTypes = 0; Array orderedTypes; for (auto type : mContext->mResolvedTypes) { - numEntries++; + numEntries++; BF_ASSERT((type != NULL) || (mPassInstance->HasFailed())); if (!type->IsReified()) @@ -1141,7 +1138,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) continue; } } - } + } { BP_ZONE("BfCompiler::CreateVData sort orderedTypes"); @@ -1152,12 +1149,12 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) } BfLogSysM("TypeEntries: %d ConcreteTypes: %d\n", numEntries, numConcreteTypes); - + HashContext vdataHashCtx; //vdataHashCtx.mDbgViz = true; vdataHashCtx.Mixin(bfModule->mProject->mVDataConfigHash); - + Array testMethods; if (project->mTargetType == BfTargetType_BeefTest) GetTestMethods(bfModule, testMethods, vdataHashCtx); @@ -1170,7 +1167,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) }); struct _SortedTypeEntry - { + { BfTypeInstance* mTypeInstance; String* mTypeName; int mPriority; @@ -1184,7 +1181,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) _SortedTypeEntry(BfModule* module, BfTypeInstance* typeInstance, Array& nameList, String*& namePtr) { - if (namePtr == NULL) + if (namePtr == NULL) { namePtr = new String(module->TypeToString(typeInstance)); nameList.Add(namePtr); @@ -1216,18 +1213,18 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) }); } }; - Array<_SortedTypeEntry> preStaticInitList; + Array<_SortedTypeEntry> preStaticInitList; Array<_SortedTypeEntry> staticMarkList; Array<_SortedTypeEntry> staticTLSList; - Array vdataTypeList; + Array vdataTypeList; HashSet usedModuleSet; HashSet reflectTypeSet; HashSet reflectFieldTypeSet; vdataHashCtx.MixinStr(project->mStartupObject); vdataHashCtx.Mixin(project->mTargetType); - + for (auto type : orderedTypes) { if (type == NULL) @@ -1252,11 +1249,11 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) BF_ASSERT((type != NULL) || (mPassInstance->HasFailed())); if ((type != NULL) && (typeInst != NULL)) - { + { auto module = typeInst->mModule; if (module == NULL) continue; - + if (type->IsEnum()) { for (auto& fieldInst : typeInst->mFieldInstances) @@ -1283,22 +1280,22 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) if (usedModuleSet.Add(module)) { CompileLog("UsedModule %p %s\n", module, module->mModuleName.c_str()); - + HashModuleVData(module, vdataHashCtx); } } - + vdataHashCtx.MixinStr(module->mModuleName); vdataHashCtx.Mixin(typeInst->mTypeDef->mSignatureHash); vdataHashCtx.Mixin(module->mHasForceLinkMarker); - + for (auto iface : typeInst->mInterfaces) { vdataHashCtx.Mixin(iface.mInterfaceType->mTypeId); vdataHashCtx.Mixin(iface.mDeclaringType->mTypeCode); vdataHashCtx.Mixin(iface.mDeclaringType->mProject); } - + if (!typeInst->IsUnspecializedType()) { for (auto& methodInstGroup : typeInst->mMethodInstanceGroups) @@ -1314,11 +1311,11 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) auto baseType = typeInst->mBaseType; while (baseType != NULL) { - vdataHashCtx.Mixin(baseType->mTypeDef->mSignatureHash); + vdataHashCtx.Mixin(baseType->mTypeDef->mSignatureHash); baseType = baseType->mBaseType; } - //TODO: What was this for? + //TODO: What was this for? // if (module->mProject != bfModule->mProject) // { // if ((module->mProject != NULL) && (module->mProject->mTargetType == BfTargetType_BeefDynLib)) @@ -1327,7 +1324,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) String* typeName = NULL; if ((typeInst->mHasStaticInitMethod) || (typeInst->mHasStaticDtorMethod)) - preStaticInitList.Add(_SortedTypeEntry(bfModule, typeInst, typeNameList, typeName)); + preStaticInitList.Add(_SortedTypeEntry(bfModule, typeInst, typeNameList, typeName)); if ((typeInst->mHasStaticMarkMethod) && (mOptions.mEnableRealtimeLeakCheck)) staticMarkList.Add(_SortedTypeEntry(bfModule, typeInst, typeNameList, typeName)); if ((typeInst->mHasTLSFindMethod) && (mOptions.mEnableRealtimeLeakCheck)) @@ -1337,22 +1334,22 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) int lastModuleRevision = bfModule->mRevision; Val128 vdataHash = vdataHashCtx.Finish128(); - bool wantsRebuild = vdataHash != bfModule->mDataHash; + bool wantsRebuild = vdataHash != bfModule->mDataHash; if (bfModule->mHadBuildError) wantsRebuild = true; // If we did one of those 'hot compile' partial vdata builds, now build the whole thing if ((!IsHotCompile()) && (bfModule->mHadHotObjectWrites)) wantsRebuild = true; - if (mOptions.mHotProject != NULL) + if (mOptions.mHotProject != NULL) { HashContext vdataHashCtxEx; vdataHashCtxEx.Mixin(mOptions.mHotProject->mName); - + vdataHashCtxEx.Mixin((int)mHotState->mNewlySlottedTypeIds.size()); for (auto typeId : mHotState->mNewlySlottedTypeIds) vdataHashCtxEx.Mixin(typeId); - + vdataHashCtxEx.Mixin((int)mHotState->mSlotDefineTypeIds.size()); for (auto typeId : mHotState->mSlotDefineTypeIds) vdataHashCtxEx.Mixin(typeId); @@ -1390,7 +1387,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) CompileLog("VData unchanged, skipping\n"); return; } - + BfTypeInstance* stringType = bfModule->ResolveTypeDef(mStringTypeDef, BfPopulateType_Data)->ToTypeInstance(); BfTypeInstance* stringViewType = bfModule->ResolveTypeDef(mStringViewTypeDef, BfPopulateType_Data)->ToTypeInstance(); BfTypeInstance* reflectSpecializedTypeInstance = bfModule->ResolveTypeDef(mReflectSpecializedGenericType)->ToTypeInstance(); @@ -1398,23 +1395,23 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) BfTypeInstance* reflectArrayTypeInstance = bfModule->ResolveTypeDef(mReflectArrayType)->ToTypeInstance(); bool madeBfTypeData = false; - + auto typeDefType = mContext->mBfTypeType; bool needsTypeList = bfModule->IsMethodImplementedAndReified(typeDefType, "GetType"); - bool needsObjectTypeData = needsTypeList || bfModule->IsMethodImplementedAndReified(vdataContext->mBfObjectType, "RawGetType") || bfModule->IsMethodImplementedAndReified(vdataContext->mBfObjectType, "GetType"); + bool needsObjectTypeData = needsTypeList || bfModule->IsMethodImplementedAndReified(vdataContext->mBfObjectType, "RawGetType") || bfModule->IsMethodImplementedAndReified(vdataContext->mBfObjectType, "GetType"); bool needsTypeNames = bfModule->IsMethodImplementedAndReified(typeDefType, "GetName") || bfModule->IsMethodImplementedAndReified(typeDefType, "GetFullName"); bool needsStringLiteralList = (mOptions.mAllowHotSwapping) || (bfModule->IsMethodImplementedAndReified(stringType, "Intern")) || (bfModule->IsMethodImplementedAndReified(stringViewType, "Intern")); Dictionary usedStringIdMap; - + reflectTypeSet.Add(vdataContext->mUnreifiedModule->ResolveTypeDef(mReflectTypeInstanceTypeDef)); reflectTypeSet.Add(vdataContext->mUnreifiedModule->ResolveTypeDef(mReflectSpecializedGenericType)); reflectTypeSet.Add(vdataContext->mUnreifiedModule->ResolveTypeDef(mReflectUnspecializedGenericType)); reflectTypeSet.Add(vdataContext->mUnreifiedModule->ResolveTypeDef(mReflectArrayType)); reflectTypeSet.Add(vdataContext->mUnreifiedModule->ResolveTypeDef(mReflectGenericParamType)); - - SmallVector typeDataVector; - for (auto type : vdataTypeList) + + SmallVector typeDataVector; + for (auto type : vdataTypeList) { if (type->IsTypeAlias()) continue; @@ -1423,7 +1420,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) BF_ASSERT(!type->IsIncomplete()); auto typeInst = type->ToTypeInstance(); - + if ((typeInst != NULL) && (!typeInst->IsReified()) && (!typeInst->IsUnspecializedType())) continue; @@ -1436,11 +1433,11 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) { needsTypeData = true; if (type->IsEnum()) - forceReflectFields = true; + forceReflectFields = true; } - + BfIRValue typeVariable; - + if ((needsTypeData) || (needsVData)) { if (reflectFieldTypeSet.Contains(type)) @@ -1453,11 +1450,11 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) needsTypeData = true; needsVData = true; } - + typeVariable = bfModule->CreateTypeData(type, usedStringIdMap, forceReflectFields, needsTypeData, needsTypeNames, needsVData); } type->mDirty = false; - + if (needsTypeList) { int typeId = type->mTypeId; @@ -1476,7 +1473,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) } // We only need 'sTypes' if we actually reference it - // + // { auto typeDefPtrType = bfModule->CreatePointerType(typeDefType); StringT<128> typesVariableName; @@ -1491,7 +1488,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) bfModule->mBfIRBuilder->CreateGlobalVariable(bfModule->mBfIRBuilder->MapType(bfModule->GetPrimitiveType(BfTypeCode_Int32)), true, BfIRLinkageType_External, bfModule->mBfIRBuilder->CreateConst(BfTypeCode_Int32, (int)typeDataVector.size()), typeCountVariableName); } - + HashSet foundStringIds; for (int stringId : bfModule->mStringPoolRefs) foundStringIds.Add(stringId); @@ -1499,8 +1496,8 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) Array orderedUsedModules; for (auto module : usedModuleSet) orderedUsedModules.push_back(module); - std::sort(orderedUsedModules.begin(), orderedUsedModules.end(), [] (BfModule* lhs, BfModule* rhs) - { + std::sort(orderedUsedModules.begin(), orderedUsedModules.end(), [] (BfModule* lhs, BfModule* rhs) + { return lhs->mModuleName < rhs->mModuleName; }); @@ -1511,7 +1508,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) HashSet dllNameSet; Array stringValueEntries; for (auto module : orderedUsedModules) - { + { CheckModuleStringRefs(module, bfModule, lastModuleRevision, foundStringIds, dllNameSet, dllMethods, stringValueEntries); if ((module->mHasForceLinkMarker) && @@ -1528,7 +1525,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) BfIRValue typeDataArray = bfModule->mBfIRBuilder->CreateGlobalVariable(arrayType, true, BfIRLinkageType_Internal, typeDataConst, "FORCELINK_MODULES"); } - + // Generate strings array { if (!needsStringLiteralList) @@ -1541,10 +1538,10 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) { return lhs.mId < rhs.mId; }); - + auto stringPtrType = bfModule->CreatePointerType(stringType); auto stringPtrIRType = bfModule->mBfIRBuilder->MapTypeInstPtr(stringType); - + StringT<128> stringsVariableName; BfMangler::MangleStaticFieldName(stringsVariableName, GetMangleKind(), stringType->ToTypeInstance(), "sStringLiterals", stringPtrType); Array stringList; @@ -1555,9 +1552,9 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) BfIRType stringArrayType = bfModule->mBfIRBuilder->GetSizedArrayType(stringPtrIRType, (int)stringList.size()); auto stringArray = bfModule->mBfIRBuilder->CreateConstAgg_Value(stringArrayType, stringList); - + auto stringArrayVar = bfModule->mBfIRBuilder->CreateGlobalVariable(stringArrayType, true, BfIRLinkageType_External, stringArray, stringsVariableName); - + if (bfModule->mBfIRBuilder->DbgHasInfo()) { auto dbgArrayType = bfModule->mBfIRBuilder->DbgCreateArrayType(stringList.size() * mSystem->mPtrSize * 8, mSystem->mPtrSize * 8, bfModule->mBfIRBuilder->DbgGetType(stringPtrType), (int)stringList.size()); @@ -1566,10 +1563,10 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) } // Generate string ID array - { + { auto stringType = bfModule->ResolveTypeDef(mStringTypeDef, BfPopulateType_Data)->ToTypeInstance(); auto stringPtrType = bfModule->CreatePointerType(stringType); - auto stringPtrIRType = bfModule->mBfIRBuilder->MapTypeInstPtr(stringType); + auto stringPtrIRType = bfModule->mBfIRBuilder->MapTypeInstPtr(stringType); StringT<128> stringsVariableName; BfMangler::MangleStaticFieldName(stringsVariableName, GetMangleKind(), stringType->ToTypeInstance(), "sIdStringLiterals", stringPtrType); @@ -1577,7 +1574,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) stringList.Resize(usedStringIdMap.size()); for (auto& kv : usedStringIdMap) - { + { stringList[kv.mValue] = bfModule->mStringObjectPool[kv.mKey]; } @@ -1594,14 +1591,14 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) } BfIRFunction loadSharedLibFunc = CreateLoadSharedLibraries(bfModule, dllMethods); - + BfIRType nullPtrType = bfModule->mBfIRBuilder->MapType(bfModule->GetPrimitiveType(BfTypeCode_NullPtr)); BfIRType voidType = bfModule->mBfIRBuilder->MapType(bfModule->GetPrimitiveType(BfTypeCode_None)); BfIRType int32Type = bfModule->mBfIRBuilder->MapType(bfModule->GetPrimitiveType(BfTypeCode_Int32)); Array<_SortedTypeEntry> staticInitList; // Populate staticInitList - { + { Dictionary pendingIDToInstanceMap; HashSet handledTypes; BfType* staticInitPriorityAttributeType = vdataContext->mUnreifiedModule->ResolveTypeDef(mStaticInitPriorityAttributeTypeDef); @@ -1639,7 +1636,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) } if (!hadInitAfterAttribute) - { + { mapEntry.mPriority = priority; staticInitList.Add(mapEntry); mapEntry.mTypeInstance = NULL; @@ -1692,7 +1689,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) if (pass == 0) { - _SortedTypeEntry::Sort(staticInitList); + _SortedTypeEntry::Sort(staticInitList); } if ((pass > 0) && (!hadAdd) && (pendingIDToInstanceMap.size() > 0)) // Circular ref? @@ -1702,7 +1699,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) break; } } - + /// Generate "BfCallAllStaticDtors" BfIRFunction dtorFunc; { @@ -1714,7 +1711,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) bfModule->mBfIRBuilder->SetActiveFunction(dtorFunc); auto entryBlock = bfModule->mBfIRBuilder->CreateBlock("entry", true); bfModule->mBfIRBuilder->SetInsertPoint(entryBlock); - + for (int i = staticInitList.mSize - 1; i >= 0; i--) { auto typeInst = staticInitList[i].mTypeInstance; @@ -1749,9 +1746,9 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) isConsoleApplication = true; bool isDllMain = (targetType == BfTargetType_BeefLib_DynamicLib) && (mOptions.mPlatformType == BfPlatformType_Windows); - bool isPosixDynLib = ((targetType == BfTargetType_BeefLib_DynamicLib) || (targetType == BfTargetType_BeefLib_StaticLib)) && + bool isPosixDynLib = ((targetType == BfTargetType_BeefLib_DynamicLib) || (targetType == BfTargetType_BeefLib_StaticLib)) && (mOptions.mPlatformType != BfPlatformType_Windows); - + bool mainHasArgs = (targetType != BfTargetType_BeefLib_DynamicLib) && (targetType != BfTargetType_BeefLib_StaticLib) && (mOptions.mPlatformType != BfPlatformType_Wasm); bool mainHasRet = ((targetType != BfTargetType_BeefLib_DynamicLib) && (targetType != BfTargetType_BeefLib_StaticLib)) || (isDllMain); @@ -1771,15 +1768,15 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) paramTypes.push_back(int32Type); paramTypes.push_back(nullPtrType); mainFuncType = bfModule->mBfIRBuilder->CreateFunctionType(int32Type, paramTypes, false); - mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "main"); + mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "main"); bfModule->SetupIRMethod(NULL, mainFunc, false); } else if (isDllMain) - { + { SmallVector paramTypes; - paramTypes.push_back(nullPtrType); // hinstDLL + paramTypes.push_back(nullPtrType); // hinstDLL paramTypes.push_back(int32Type); // fdwReason - paramTypes.push_back(nullPtrType); // lpvReserved + paramTypes.push_back(nullPtrType); // lpvReserved mainFuncType = bfModule->mBfIRBuilder->CreateFunctionType(int32Type, paramTypes, false); mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "DllMain"); if (mOptions.mMachineType == BfMachineType_x86) @@ -1788,7 +1785,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) rtFlags = 0x10; // BfRtFlags_NoThreadExitWait } else if (targetType == BfTargetType_BeefWindowsApplication) - { + { SmallVector paramTypes; paramTypes.push_back(nullPtrType); // hInstance paramTypes.push_back(nullPtrType); // hPrevInstance @@ -1797,14 +1794,14 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) mainFuncType = bfModule->mBfIRBuilder->CreateFunctionType(int32Type, paramTypes, false); mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "WinMain"); if (mOptions.mMachineType == BfMachineType_x86) - bfModule->mBfIRBuilder->SetFuncCallingConv(mainFunc, BfIRCallingConv_StdCall); + bfModule->mBfIRBuilder->SetFuncCallingConv(mainFunc, BfIRCallingConv_StdCall); bfModule->SetupIRMethod(NULL, mainFunc, false); - } + } else { BfIRFunction combinedFunc; - SmallVector paramTypes; + SmallVector paramTypes; if (mainHasArgs) { paramTypes.push_back(int32Type); @@ -1844,7 +1841,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) bfModule->mBfIRBuilder->SetActiveFunction(mainFunc); auto entryBlock = bfModule->mBfIRBuilder->CreateBlock("entry", true); bfModule->mBfIRBuilder->SetInsertPoint(entryBlock); - + if (rtFlags != 0) { auto addRtFlagMethod = bfModule->GetInternalMethod("AddRtFlags", 1); @@ -1869,10 +1866,10 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) SmallVector args; args.push_back(bfModule->mBfIRBuilder->GetArgument(0)); - args.push_back(bfModule->mBfIRBuilder->GetArgument(1)); + args.push_back(bfModule->mBfIRBuilder->GetArgument(1)); bfModule->mBfIRBuilder->CreateCall(setCmdLineFunc, args); } - + BfIRBlock initSkipBlock; if (isDllMain) { @@ -1910,9 +1907,9 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) continue; if (staticInitEntry.mPriority < 100) - _CheckSharedLibLoad(); + _CheckSharedLibLoad(); for (auto& methodGroup : typeInst->mMethodInstanceGroups) - { + { auto methodInstance = methodGroup.mDefault; if ((methodInstance != NULL) && (methodInstance->mMethodDef->mIsStatic) && @@ -1954,7 +1951,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) BF_ASSERT((type != NULL) || (mPassInstance->HasFailed())); if (type != NULL) { - BfType* stringType = vdataContext->mUnreifiedModule->ResolveTypeDef(mStringTypeDef); + BfType* stringType = vdataContext->mUnreifiedModule->ResolveTypeDef(mStringTypeDef); BfType* int32Type = bfModule->GetPrimitiveType(BfTypeCode_Int32); BfType* intType = bfModule->GetPrimitiveType(BfTypeCode_IntPtr); @@ -1974,7 +1971,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) mPassInstance->Fail("Main method must be static", methodDef->GetRefNode()); hadValidMainMethod = false; } - + if ((moduleMethodInst.mMethodInstance->mReturnType != int32Type) && (moduleMethodInst.mMethodInstance->mReturnType != intType) && (moduleMethodInst.mMethodInstance->mReturnType != voidType)) @@ -1982,7 +1979,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) mPassInstance->Fail("Main method must return void, int, or int32", methodDef->GetRefNode()); hadValidMainMethod = false; } - + if (moduleMethodInst.mMethodInstance->GetParamCount() == 0) { // No params @@ -1998,24 +1995,24 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) } } } - + if (moduleMethodInst) { if (hadValidMainMethod) { bool hasArgs = moduleMethodInst.mMethodInstance->GetParamCount() != 0; - + BfIRType intType = bfModule->mBfIRBuilder->MapType(bfModule->GetPrimitiveType(BfTypeCode_IntPtr)); BfIRType int32Type = bfModule->mBfIRBuilder->MapType(bfModule->GetPrimitiveType(BfTypeCode_Int32)); // Create BeefEntry thunk - SmallVector paramTypes; + SmallVector paramTypes; if (hasArgs) { paramTypes.push_back(bfModule->mBfIRBuilder->MapType(moduleMethodInst.mMethodInstance->GetParamType(0))); } BfIRFunctionType thunkFuncType = bfModule->mBfIRBuilder->CreateFunctionType(int32Type, paramTypes, false); - + BfIRFunction thunkMainFunc = bfModule->mBfIRBuilder->CreateFunction(thunkFuncType, BfIRLinkageType_External, "BeefStartProgram"); bfModule->SetupIRMethod(NULL, thunkMainFunc, false); bfModule->mBfIRBuilder->SetActiveFunction(thunkMainFunc); @@ -2042,8 +2039,8 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) hadRet = true; - auto internalType = bfModule->ResolveTypeDef(mInternalTypeDef); - + auto internalType = bfModule->ResolveTypeDef(mInternalTypeDef); + args.clear(); // Call BeefEntry thunk @@ -2051,11 +2048,11 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) if (hasArgs) { auto createParamsMethodInstance = bfModule->GetMethodByName(internalType->ToTypeInstance(), "CreateParamsArray"); - auto callValue = bfModule->mBfIRBuilder->CreateCall(createParamsMethodInstance.mFunc, SmallVector()); + auto callValue = bfModule->mBfIRBuilder->CreateCall(createParamsMethodInstance.mFunc, SmallVector()); args.push_back(callValue); } - retValue = bfModule->mBfIRBuilder->CreateCall(thunkMainFunc, args); + retValue = bfModule->mBfIRBuilder->CreateCall(thunkMainFunc, args); if (hasArgs) { @@ -2093,7 +2090,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) if (targetType == BfTargetType_BeefTest) EmitTestMethod(bfModule, testMethods, retValue); - + BfIRBlock deinitSkipBlock; if (isDllMain) { @@ -2167,25 +2164,25 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) SmallVector startArgs; bfModule->mBfIRBuilder->CreateCall(mainFunc, startArgs); - bfModule->mBfIRBuilder->CreateRetVoid(); + bfModule->mBfIRBuilder->CreateRetVoid(); ////////////////////////////////////////////////////////////////////////// - + func = bfModule->mBfIRBuilder->CreateFunction(funcType, BfIRLinkageType_Internal, "BfDynLib__Shutdown"); bfModule->mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_Destructor); bfModule->mBfIRBuilder->SetActiveFunction(func); entryBlock = bfModule->mBfIRBuilder->CreateBlock("main", true); bfModule->mBfIRBuilder->SetInsertPoint(entryBlock); - SmallVector stopArgs; + SmallVector stopArgs; bfModule->mBfIRBuilder->CreateCall(shutdownFunc, startArgs); bfModule->mBfIRBuilder->CreateRetVoid(); } } - - // Generate "System.GC.MarkAllStaticMembers" + + // Generate "System.GC.MarkAllStaticMembers" auto gcType = vdataContext->mUnreifiedModule->ResolveTypeDef(mGCTypeDef); if (bfModule->IsMethodImplementedAndReified(gcType->ToTypeInstance(), "MarkAllStaticMembers")) - { + { bfModule->PopulateType(gcType); auto moduleMethodInstance = bfModule->GetMethodByName(gcType->ToTypeInstance(), "MarkAllStaticMembers"); bfModule->mBfIRBuilder->SetActiveFunction(moduleMethodInstance.mFunc); @@ -2204,7 +2201,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) auto typeInst = mapEntry.mTypeInstance; if (typeInst->IsUnspecializedType()) continue; - + for (auto& methodGroup : typeInst->mMethodInstanceGroups) { auto methodInstance = methodGroup.mDefault; @@ -2266,7 +2263,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) } bfModule->mBfIRBuilder->CreateRetVoid(); } - } + } if (bfModule->mHadBuildError) { @@ -2277,7 +2274,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) // This method clears out unused generic types AFTER compilation of reified types has occurred void BfCompiler::UpdateDependencyMap(bool deleteUnusued, bool& didWork) { - BP_ZONE("BfCompiler::UpdateDependencyMap"); + BP_ZONE("BfCompiler::UpdateDependencyMap"); BfLogSysM("Compiler::UpdateDependencyMap %d\n", deleteUnusued); bool madeFullPass = true; @@ -2285,12 +2282,12 @@ void BfCompiler::UpdateDependencyMap(bool deleteUnusued, bool& didWork) madeFullPass = false; if ((mResolvePassData != NULL) && (!mResolvePassData->mParsers.IsEmpty())) madeFullPass = false; - + SetAndRestoreValue prevAssertOnPopulateType(mContext->mAssertOnPopulateType, deleteUnusued && madeFullPass); if ((deleteUnusued) && (madeFullPass)) { - // Work queues should be empty if we're not canceling + // Work queues should be empty if we're not canceling BF_ASSERT(mContext->mPopulateTypeWorkList.size() == 0); BF_ASSERT(mContext->mMethodWorkList.size() == 0); } @@ -2298,13 +2295,13 @@ void BfCompiler::UpdateDependencyMap(bool deleteUnusued, bool& didWork) // Remove old data in dependency maps, and find types which don't have any references (direct or indirect) // to a non-generic type and remove them for (int pass = 0; true; pass++) - { + { // This assert can fail if we have a dependency error, where deleting a type causes a dependent type // to be rebuilt BF_ASSERT(pass < 100); - bool foundNew = false; - + bool foundNew = false; + for (auto type : mContext->mResolvedTypes) { if (type != NULL) @@ -2319,14 +2316,14 @@ void BfCompiler::UpdateDependencyMap(bool deleteUnusued, bool& didWork) #ifdef _DEBUG for (auto itr = depType->mDependencyMap.begin(); itr != depType->mDependencyMap.end(); ++itr) { - auto dependentType = itr->mKey; + auto dependentType = itr->mKey; if (dependentType->IsIncomplete()) - { + { BF_ASSERT(dependentType->IsDeleting() || dependentType->IsOnDemand() || !dependentType->HasBeenReferenced() || mCanceling || !madeFullPass || dependentType->IsSpecializedByAutoCompleteMethod()); } } #endif - + depType->mDependencyMap.mFlagsUnion = BfDependencyMap::DependencyFlag_None; // Not combined with previous loop because PopulateType could modify typeInst->mDependencyMap @@ -2335,16 +2332,16 @@ void BfCompiler::UpdateDependencyMap(bool deleteUnusued, bool& didWork) auto dependentType = itr->mKey; auto depTypeInst = dependentType->ToTypeInstance(); auto& depData = itr->mValue; - + bool isInvalidVersion = (dependentType->mRevision > depData.mRevision);// && (deleteUnusued) && (madeFullPass); - + //TODO: Just to cause crash if dependentType is deleted bool isIncomplete = dependentType->IsIncomplete(); if ((isInvalidVersion) && (!dependentType->IsDeleting())) { if (!dependentType->HasBeenReferenced()) - { + { BfLogSysM("Skipping remove of old dependent %p from %p\n", dependentType, typeInst); //BF_ASSERT(dependentType->IsGenericTypeInstance()); // We have a pending type rebuild but we're not sure whether we're being deleted or not yet... @@ -2354,7 +2351,7 @@ void BfCompiler::UpdateDependencyMap(bool deleteUnusued, bool& didWork) } if ((dependentType->IsDeleting()) || (isInvalidVersion)) - { + { if (dependentType->IsDeleting() || ((deleteUnusued) && (madeFullPass))) { // If we're deleting the type, OR the dependency of the type has been removed. @@ -2369,10 +2366,10 @@ void BfCompiler::UpdateDependencyMap(bool deleteUnusued, bool& didWork) else { // There needs to be more usage than just being used as part of the method specialization's MethodGenericArg. - // Keep in mind that actually invoking a generic method creates a DependencyFlag_LocalUsage dependency. The + // Keep in mind that actually invoking a generic method creates a DependencyFlag_LocalUsage dependency. The // DependencyFlag_MethodGenericArg is just used by the owner during creation of the method specialization bool isDependentUsage = (depData.mFlags & BfDependencyMap::DependencyFlag_DependentUsageMask) != 0; - + // We need to consider specialized generic types separately, to remove unused specializations if (typeInst != NULL) { @@ -2380,10 +2377,10 @@ void BfCompiler::UpdateDependencyMap(bool deleteUnusued, bool& didWork) if ((depTypeInst != NULL) && (typeInst->mLastNonGenericUsedRevision != mRevision) && (isDependentUsage) && ((isDirectReference) || (dependentType->IsUnspecializedType()) || (depTypeInst->mLastNonGenericUsedRevision == mRevision))) - { + { typeInst->mLastNonGenericUsedRevision = mRevision; foundNew = true; - + if (!typeInst->HasBeenReferenced()) { mContext->AddTypeToWorkList(typeInst); @@ -2391,19 +2388,19 @@ void BfCompiler::UpdateDependencyMap(bool deleteUnusued, bool& didWork) } } } - + ++itr; } depType->mDependencyMap.mFlagsUnion = (BfDependencyMap::DependencyFlags)(depType->mDependencyMap.mFlagsUnion | depData.mFlags); } - if ((!depType->IsGenericTypeInstance() && (!depType->IsBoxed())) || + if ((!depType->IsGenericTypeInstance() && (!depType->IsBoxed())) || (depType->IsUnspecializedType()) || - ((typeInst != NULL) && (typeInst->mLastNonGenericUsedRevision == mRevision))) + ((typeInst != NULL) && (typeInst->mLastNonGenericUsedRevision == mRevision))) { if ((depType->mRebuildFlags & BfTypeRebuildFlag_AwaitingReference) != 0) - { + { mContext->MarkAsReferenced(depType); } } @@ -2412,7 +2409,7 @@ void BfCompiler::UpdateDependencyMap(bool deleteUnusued, bool& didWork) } if (mCanceling) - madeFullPass = false; + madeFullPass = false; if (!madeFullPass) { @@ -2429,8 +2426,8 @@ void BfCompiler::UpdateDependencyMap(bool deleteUnusued, bool& didWork) didWork |= DoWorkLoop(false, false); } else if (deleteUnusued) - { - // Work queues should be empty if we're not canceling + { + // Work queues should be empty if we're not canceling BF_ASSERT(mContext->mPopulateTypeWorkList.size() == 0); BF_ASSERT(mContext->mMethodWorkList.size() == 0); @@ -2439,16 +2436,16 @@ void BfCompiler::UpdateDependencyMap(bool deleteUnusued, bool& didWork) // deletion, so we must set BfTypeRebuildFlag_DeleteQueued first to avoid that Array deleteQueue; - // We bubble out + // We bubble out for (auto type : mContext->mResolvedTypes) - { + { auto depType = type->ToDependedType(); // Delete if we're a generic if ((depType != NULL) && (!depType->IsDeleting())) { auto typeInst = depType->ToTypeInstance(); - + bool wantDelete = false; if (typeInst != NULL) { @@ -2464,7 +2461,7 @@ void BfCompiler::UpdateDependencyMap(bool deleteUnusued, bool& didWork) depType->mRebuildFlags = (BfTypeRebuildFlags)(depType->mRebuildFlags | BfTypeRebuildFlag_DeleteQueued); foundNew = true; } - } + } } for (auto depType : deleteQueue) @@ -2478,16 +2475,16 @@ void BfCompiler::UpdateDependencyMap(bool deleteUnusued, bool& didWork) mContext->ValidateDependencies(); mContext->UpdateAfterDeletingTypes(); mContext->ValidateDependencies(); - } + } } if (!foundNew) break; - } + } #ifdef _DEBUG if (deleteUnusued) - { + { for (auto type : mContext->mResolvedTypes) { // This flag should be handled by now @@ -2496,7 +2493,6 @@ void BfCompiler::UpdateDependencyMap(bool deleteUnusued, bool& didWork) } #endif - BP_ZONE("UpdateDependencyMap QueuedSpecializedMethodRebuildTypes"); HashSet specializerSet; @@ -2519,7 +2515,7 @@ void BfCompiler::UpdateDependencyMap(bool deleteUnusued, bool& didWork) if ((depData.mFlags & BfDependencyMap::DependencyFlag_Calls) != 0) { specializerSet.Add(depTypeInst); - } + } } } } @@ -2546,8 +2542,8 @@ void BfCompiler::SanitizeDependencyMap() { if (type == NULL) continue; - - auto depType = type->ToDependedType(); + + auto depType = type->ToDependedType(); if (depType == NULL) continue; @@ -2555,16 +2551,16 @@ void BfCompiler::SanitizeDependencyMap() for (auto itr = depType->mDependencyMap.begin(); itr != depType->mDependencyMap.end();) { auto dependentType = itr->mKey; - auto depTypeInst = dependentType->ToTypeInstance(); + auto depTypeInst = dependentType->ToTypeInstance(); if (dependentType->IsDeleting()) { BfLogSysM("SanitizeDependencyMap removing old dependent %p from %p\n", dependentType, depType); - itr = depType->mDependencyMap.erase(itr); + itr = depType->mDependencyMap.erase(itr); } else ++itr; } - } + } mContext->RemoveInvalidWorkItems(); mDepsMayHaveDeletedTypes = false; @@ -2577,20 +2573,20 @@ void BfCompiler::SanitizeDependencyMap() // 3) It stays undefined and we need to build it here bool BfCompiler::ProcessPurgatory(bool reifiedOnly) { - BP_ZONE("BfCompiler::ProcessPurgatory"); + BP_ZONE("BfCompiler::ProcessPurgatory"); bool didWork = false; while (true) - { - mContext->RemoveInvalidWorkItems(); - + { + mContext->RemoveInvalidWorkItems(); + //for (auto type : mGenericInstancePurgatory) for (int i = 0; i < (int)mGenericInstancePurgatory.size(); i++) { auto type = mGenericInstancePurgatory[i]; if ((reifiedOnly) && (!type->IsReified())) - continue; + continue; if ((reifiedOnly) && ((type->mRebuildFlags & BfTypeRebuildFlag_AwaitingReference) != 0)) continue; @@ -2599,9 +2595,9 @@ bool BfCompiler::ProcessPurgatory(bool reifiedOnly) { auto module = type->GetModule(); if (module != NULL) - { + { if (!module->mIsModuleMutable) - module->StartExtension(); + module->StartExtension(); module->PopulateType(type, BfPopulateType_Full); } } @@ -2627,9 +2623,9 @@ bool BfCompiler::ProcessPurgatory(bool reifiedOnly) bool BfCompiler::VerifySlotNums() { - BP_ZONE("BfCompiler::VerifySlotNums"); + BP_ZONE("BfCompiler::VerifySlotNums"); - SmallVector isSlotUsed; + SmallVector isSlotUsed; for (auto type : mContext->mResolvedTypes) { if (!type->IsReified()) @@ -2661,7 +2657,7 @@ bool BfCompiler::VerifySlotNums() auto checkType = typeInst; while (checkType != NULL) - { + { for (auto iface : checkType->mInterfaces) { int slotNum = iface.mInterfaceType->mSlotNum; @@ -2672,17 +2668,17 @@ bool BfCompiler::VerifySlotNums() isSlotUsed[slotNum] = iface.mInterfaceType; } } - + checkType = checkType->mBaseType; } - } + } return true; } bool BfCompiler::QuickGenerateSlotNums() -{ - /*SmallVector isSlotUsed; +{ + /*SmallVector isSlotUsed; for (auto globalTypeEntry : mResolvedTypes) { BfType* type = globalTypeEntry->mType; @@ -2700,7 +2696,7 @@ bool BfCompiler::QuickGenerateSlotNums() } continue; - } + } } return VerifySlotNums();*/ @@ -2714,7 +2710,7 @@ class BfSlotEntry public: BfTypeInstance* mTypeInstance; int mRefCount; - Array mConcurrentRefs; + Array mConcurrentRefs; }; typedef std::pair InterfacePair; @@ -2727,7 +2723,7 @@ static BfSlotEntry* GetSlotEntry(SlotEntryMap& slotEntryMap, BfTypeInstance* typ BfSlotEntry** slotEntryPtr = NULL; if (!slotEntryMap.TryAdd(typeInst, NULL, &slotEntryPtr)) return *slotEntryPtr; - + BfSlotEntry* slotEntry = new BfSlotEntry(); slotEntry->mTypeInstance = typeInst; slotEntry->mRefCount = 0; @@ -2744,7 +2740,7 @@ static InterfacePair MakeInterfacePair(BfTypeInstance* iface1, BfTypeInstance* i } struct InterfacePairHash -{ +{ size_t operator()(const InterfacePair& val) const { return (((size_t)val.first) >> 2) ^ ((size_t)val.second); @@ -2753,13 +2749,13 @@ struct InterfacePairHash bool BfCompiler::SlowGenerateSlotNums() { - BP_ZONE("BfCompiler::SlowGenerateSlotNums"); - + BP_ZONE("BfCompiler::SlowGenerateSlotNums"); + SlotEntryMap ifaceUseMap; - + std::unordered_set concurrentInterfaceSet; HashSet foundIFaces; - + if (mMaxInterfaceSlots < 0) { mMaxInterfaceSlots = 0; @@ -2768,7 +2764,7 @@ bool BfCompiler::SlowGenerateSlotNums() bool isHotCompile = IsHotCompile(); for (auto type : mContext->mResolvedTypes) - { + { if (!type->IsReified()) continue; @@ -2793,7 +2789,7 @@ bool BfCompiler::SlowGenerateSlotNums() } foundIFaces.Clear(); - auto checkTypeInst = typeInst; + auto checkTypeInst = typeInst; while (checkTypeInst != NULL) { for (auto iface : checkTypeInst->mInterfaces) @@ -2824,7 +2820,7 @@ bool BfCompiler::SlowGenerateSlotNums() { auto iface1 = *itr1; auto iface2 = *itr2; - + InterfacePair ifacePair = MakeInterfacePair(iface1, iface2); if (concurrentInterfaceSet.insert(ifacePair).second) { @@ -2832,29 +2828,29 @@ bool BfCompiler::SlowGenerateSlotNums() BfSlotEntry* entry2 = GetSlotEntry(ifaceUseMap, iface2); entry1->mConcurrentRefs.push_back(iface2); entry2->mConcurrentRefs.push_back(iface1); - } + } } - } - } - - Array sortedIfaceUseMap; + } + } + + Array sortedIfaceUseMap; for (auto& entry : ifaceUseMap) { if (!isHotCompile) BF_ASSERT(entry.mValue->mTypeInstance->mSlotNum == -1); sortedIfaceUseMap.push_back(entry.mValue); - } - - std::sort(sortedIfaceUseMap.begin(), sortedIfaceUseMap.end(), [] (BfSlotEntry* lhs, BfSlotEntry* rhs) - { + } + + std::sort(sortedIfaceUseMap.begin(), sortedIfaceUseMap.end(), [] (BfSlotEntry* lhs, BfSlotEntry* rhs) + { if (lhs->mRefCount != rhs->mRefCount) - return lhs->mRefCount > rhs->mRefCount; + return lhs->mRefCount > rhs->mRefCount; return lhs->mTypeInstance->mTypeId < rhs->mTypeInstance->mTypeId; }); bool failed = false; - SmallVector isSlotUsed; + SmallVector isSlotUsed; for (auto slotEntry : sortedIfaceUseMap) { BfTypeInstance* iface = slotEntry->mTypeInstance; @@ -2866,7 +2862,7 @@ bool BfCompiler::SlowGenerateSlotNums() isSlotUsed.clear(); if (mMaxInterfaceSlots > 0) - isSlotUsed.resize(mMaxInterfaceSlots); + isSlotUsed.resize(mMaxInterfaceSlots); BF_ASSERT(iface->mSlotNum == -1); @@ -2942,8 +2938,8 @@ bool BfCompiler::SlowGenerateSlotNums() void BfCompiler::GenerateSlotNums() { - BP_ZONE("BfCompiler::GenerateSlotNums"); - + BP_ZONE("BfCompiler::GenerateSlotNums"); + if (mMaxInterfaceSlots < 0) { if (mOptions.mIncrementalBuild) @@ -2953,16 +2949,16 @@ void BfCompiler::GenerateSlotNums() } bool isHotCompile = IsHotCompile(); - + for (auto type : mContext->mResolvedTypes) - { + { if (!type->IsInterface()) continue; auto typeInstance = type->ToTypeInstance(); if ((typeInstance->mSlotNum <= 0) || (!isHotCompile)) { - if ((mContext->mReferencedIFaceSlots.Contains(typeInstance)) || + if ((mContext->mReferencedIFaceSlots.Contains(typeInstance)) || (typeInstance->mHasBeenInstantiated) || (typeInstance->IncludeAllMethods())) { if (typeInstance->mSlotNum == -2) @@ -2973,11 +2969,11 @@ void BfCompiler::GenerateSlotNums() } } - if (VerifySlotNums()) + if (VerifySlotNums()) return; - + if (!QuickGenerateSlotNums()) - SlowGenerateSlotNums(); + SlowGenerateSlotNums(); BfLogSysM("GenerateSlotNums mMaxInterfaceSlots: %d\n", mMaxInterfaceSlots); } @@ -2993,17 +2989,17 @@ void BfCompiler::GenerateDynCastData() nextSiblingIds.Resize(mCurTypeId); for (auto type : mContext->mResolvedTypes) - { + { if (type->IsBoxed()) continue; auto typeInst = type->ToTypeInstance(); if (typeInst == NULL) continue; - + if (typeInst->mBaseType == NULL) continue; - + int baseId = typeInst->mBaseType->mTypeId; int firstDerivedId = firstDerivedIds[baseId]; @@ -3046,8 +3042,8 @@ void BfCompiler::GenerateDynCastData() void BfCompiler::UpdateRevisedTypes() { BfLogSysM("BfCompiler::UpdateRevisedTypes\n"); - BP_ZONE("BfCompiler::UpdateRevisedTypes"); - + BP_ZONE("BfCompiler::UpdateRevisedTypes"); + // See if we have any name conflicts and remove those auto typeDefItr = mSystem->mTypeDefs.begin(); while (typeDefItr != mSystem->mTypeDefs.end()) @@ -3060,7 +3056,7 @@ void BfCompiler::UpdateRevisedTypes() { ++typeDefItr; continue; - } + } typeDef->mDupDetectedRevision = -1; if ((typeDef->mIsCombinedPartial) || (typeDef->mDefState == BfTypeDef::DefState_Deleted) || (typeDef->mTypeCode == BfTypeCode_Extension)) @@ -3071,16 +3067,16 @@ void BfCompiler::UpdateRevisedTypes() 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); + 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; auto nextTypeDefItr = typeDefItr; nextTypeDefItr.MoveToNextHashMatch(); while (nextTypeDefItr) { - auto nextTypeDef = *nextTypeDefItr; + auto nextTypeDef = *nextTypeDefItr; if (nextTypeDef->mNextRevision != NULL) nextTypeDef = nextTypeDef->mNextRevision; if ((nextTypeDef->mIsCombinedPartial) || (nextTypeDef->mDefState == BfTypeDef::DefState_Deleted) || (nextTypeDef->mTypeCode == BfTypeCode_Extension) || @@ -3088,9 +3084,9 @@ void BfCompiler::UpdateRevisedTypes() { nextTypeDefItr.MoveToNextHashMatch(); continue; - } + } - if ((typeDef->mIsPartial) && (nextTypeDef->mIsPartial) && + if ((typeDef->mIsPartial) && (nextTypeDef->mIsPartial) && (!typeDef->IsGlobalsContainer()) && (typeDef->mProject != nextTypeDef->mProject)) { @@ -3111,15 +3107,15 @@ void BfCompiler::UpdateRevisedTypes() if (typeA != NULL) { - error = mPassInstance->Fail(StrFormat("Partial type in project '%s' cannot extend a type from a referenced project", typeA->mProject->mName.c_str()).c_str(), + error = mPassInstance->Fail(StrFormat("Partial type in project '%s' cannot extend a type from a referenced project", typeA->mProject->mName.c_str()).c_str(), typeA->mTypeDeclaration->mNameNode); - mPassInstance->MoreInfo(StrFormat("Previous definition in project '%s'", typeB->mProject->mName.c_str()), + mPassInstance->MoreInfo(StrFormat("Previous definition in project '%s'", typeB->mProject->mName.c_str()), typeB->mTypeDeclaration->mNameNode); } if (error != NULL) error->mIsPersistent = true; } - + if (((!typeDef->mIsPartial) || (!nextTypeDef->mIsPartial)) && (!typeDef->IsGlobalsContainer()) && (!nextTypeDef->IsGlobalsContainer()) && (typeDef->mProject->ReferencesOrReferencedBy(nextTypeDef->mProject))) @@ -3128,17 +3124,17 @@ void BfCompiler::UpdateRevisedTypes() BfError* error = NULL; /*if ((typeDef->mIsPartial) && (typeDef->mTypeCode != BfTypeCode_Extension)) - { + { error = mPassInstance->Fail("Missing 'partial' modifier; another partial definition of this type exists", nextTypeDef->mTypeDeclaration->mNameNode); mPassInstance->MoreInfo("Previous definition", typeDef->mTypeDeclaration->mNameNode); } else if ((nextTypeDef->mIsPartial) && (nextTypeDef->mTypeCode != BfTypeCode_Extension)) - { + { error = mPassInstance->Fail("Missing 'partial' modifier; another partial definition of this type exists", typeDef->mTypeDeclaration->mNameNode); - mPassInstance->MoreInfo("Previous definition", nextTypeDef->mTypeDeclaration->mNameNode); + mPassInstance->MoreInfo("Previous definition", nextTypeDef->mTypeDeclaration->mNameNode); } else */if (nextTypeDef->mOuterType != NULL) - { + { error = mPassInstance->Fail(StrFormat("The type '%s.%s' already has a definition for '%s'", nextTypeDef->mOuterType->mNamespace.ToString().c_str(), nextTypeDef->mOuterType->mName->mString.mPtr, nextTypeDef->mName->mString.mPtr), nextTypeDef->mTypeDeclaration->mNameNode); mPassInstance->MoreInfo("Previous definition", typeDef->mTypeDeclaration->mNameNode); @@ -3150,35 +3146,35 @@ void BfCompiler::UpdateRevisedTypes() mPassInstance->MoreInfo("Previous definition", typeDef->mTypeDeclaration->mNameNode); } else - { - error = mPassInstance->Fail(StrFormat("The global namespace already has a definition for '%s'", + { + error = mPassInstance->Fail(StrFormat("The global namespace already has a definition for '%s'", nextTypeDef->mName->mString.mPtr), nextTypeDef->mTypeDeclaration->mNameNode); mPassInstance->MoreInfo("Previous definition", typeDef->mTypeDeclaration->mNameNode); } if (error != NULL) error->mIsPersistent = true; } - + nextTypeDefItr.MoveToNextHashMatch(); } ++typeDefItr; } - - mContext->PreUpdateRevisedTypes(); + + mContext->PreUpdateRevisedTypes(); // If we missed out on required types previously, now we should be 'okay' mInInvalidState = false; // We can't do any yields in here - the compiler state is invalid from the time we inject a new - // typedef revision up until we finish the associated RebuildType + // typedef revision up until we finish the associated RebuildType int compositeBucket = 0; - + // These are "extension" defs that were unmatched last run through Array prevSoloExtensions; mSystem->mTypeDefs.CheckRehash(); - + Array corlibProjects; // { @@ -3200,11 +3196,11 @@ void BfCompiler::UpdateRevisedTypes() { bool hadPartials = false; bool hadChanges = false; - + if (mSystem->mTypeDefs.mHashHeads == NULL) break; - // Partials combiner + // Partials combiner auto outerTypeDefEntryIdx = mSystem->mTypeDefs.mHashHeads[bucketIdx]; while (outerTypeDefEntryIdx != -1) { @@ -3222,20 +3218,20 @@ void BfCompiler::UpdateRevisedTypes() } if (outerTypeDef->mNextRevision != NULL) - hadChanges = true; + hadChanges = true; BfTypeDefMap::Entry* rootTypeDefEntry = NULL; BfTypeDef* rootTypeDef = NULL; BfTypeDef* compositeTypeDef = NULL; BfProject* compositeProject = NULL; - + auto latestOuterTypeDef = outerTypeDef->GetLatest(); if ((outerTypeDef->mTypeCode == BfTypeCode_Extension) && (!outerTypeDef->mIsPartial)) { prevSoloExtensions.Add(outerTypeDef); outerTypeDef->mIsPartial = true; } - + if ((outerTypeDef->mIsPartial) || (outerTypeDef->mIsCombinedPartial)) { // Initialize mPartialUsed flags @@ -3243,7 +3239,7 @@ void BfCompiler::UpdateRevisedTypes() { auto checkTypeDefEntryIdx = mSystem->mTypeDefs.mHashHeads[bucketIdx]; while (checkTypeDefEntryIdx != -1) - { + { // This clears the mPartialUsed flag for the whole bucket auto checkTypeDef = mSystem->mTypeDefs.mEntries[checkTypeDefEntryIdx].mValue; if ((checkTypeDef->mIsPartial) || (checkTypeDef->mIsCombinedPartial)) @@ -3257,11 +3253,11 @@ void BfCompiler::UpdateRevisedTypes() bool isExplicitPartial = outerTypeDef->mIsExplicitPartial; bool failedToFindRootType = false; if ((outerTypeDef->mTypeCode == BfTypeCode_Extension) && (!outerTypeDef->mPartialUsed)) - { + { // Find root type, and we assume the composite type follows this auto checkTypeDefEntryIdx = mSystem->mTypeDefs.mHashHeads[bucketIdx]; while (checkTypeDefEntryIdx != -1) - { + { auto checkTypeDefEntry = &mSystem->mTypeDefs.mEntries[checkTypeDefEntryIdx]; auto checkTypeDef = checkTypeDefEntry->mValue; if ((checkTypeDefEntry->mHashCode != outerTypeDefEntry->mHashCode) || @@ -3278,16 +3274,16 @@ void BfCompiler::UpdateRevisedTypes() } // Only allow extending structs, objects, and interfaces - if ((checkTypeDef->mTypeCode == BfTypeCode_Struct) || + if ((checkTypeDef->mTypeCode == BfTypeCode_Struct) || (checkTypeDef->mTypeCode == BfTypeCode_Object) || (checkTypeDef->mTypeCode == BfTypeCode_Enum) || (checkTypeDef->mTypeCode == BfTypeCode_Interface)) - { + { rootTypeDef = checkTypeDef; rootTypeDefEntry = checkTypeDefEntry; compositeProject = rootTypeDef->mProject; } - + checkTypeDefEntryIdx = checkTypeDefEntry->mNext; if (compositeTypeDef != NULL) @@ -3298,26 +3294,26 @@ void BfCompiler::UpdateRevisedTypes() if (rootTypeDef == NULL) { - failedToFindRootType = true; + failedToFindRootType = true; isExplicitPartial = true; } } - + if ((isExplicitPartial) && (!outerTypeDef->mPartialUsed)) { // For explicit partials there is no 'root type' so we want to select any partial in the 'innermost' project - rootTypeDef = outerTypeDef; + rootTypeDef = outerTypeDef; rootTypeDefEntry = outerTypeDefEntry; compositeProject = rootTypeDef->mProject; - + // Find composite type, there is no explicit position for this auto checkTypeDefEntryIdx = mSystem->mTypeDefs.mHashHeads[bucketIdx]; while (checkTypeDefEntryIdx != -1) - { + { auto checkTypeDefEntry = &mSystem->mTypeDefs.mEntries[checkTypeDefEntryIdx]; auto checkTypeDef = checkTypeDefEntry->mValue; - if ((checkTypeDefEntry->mHashCode != outerTypeDefEntry->mHashCode) || + if ((checkTypeDefEntry->mHashCode != outerTypeDefEntry->mHashCode) || (checkTypeDef->mPartialUsed) || (checkTypeDef->mDefState == BfTypeDef::DefState_Deleted) || (!checkTypeDef->NameEquals(outerTypeDef)) || @@ -3343,7 +3339,7 @@ void BfCompiler::UpdateRevisedTypes() compositeProject = rootTypeDef->mProject; } else - { + { // Try 'corlib' for (auto corlibProject : corlibProjects) { @@ -3411,10 +3407,10 @@ void BfCompiler::UpdateRevisedTypes() compositeTypeDef->mNameEx->Ref(); compositeTypeDef->mProtection = rootTypeDef->mProtection; compositeTypeDef->mNamespace = rootTypeDef->mNamespace; - if (rootTypeDef->mTypeCode == BfTypeCode_Extension) - compositeTypeDef->mTypeCode = BfTypeCode_Struct; + if (rootTypeDef->mTypeCode == BfTypeCode_Extension) + compositeTypeDef->mTypeCode = BfTypeCode_Struct; else - compositeTypeDef->mTypeCode = rootTypeDef->mTypeCode; + compositeTypeDef->mTypeCode = rootTypeDef->mTypeCode; compositeTypeDef->mFullName = rootTypeDef->mFullName; compositeTypeDef->mFullNameEx = rootTypeDef->mFullNameEx; compositeTypeDef->mIsFunction = rootTypeDef->mIsFunction; @@ -3446,8 +3442,8 @@ void BfCompiler::UpdateRevisedTypes() if (compositeTypeDef->mNextRevision != NULL) { // This is an old 'next revision' - mSystem->InjectNewRevision(compositeTypeDef); - BF_ASSERT(compositeTypeDef->mNextRevision == NULL); + mSystem->InjectNewRevision(compositeTypeDef); + BF_ASSERT(compositeTypeDef->mNextRevision == NULL); } } } @@ -3463,11 +3459,11 @@ void BfCompiler::UpdateRevisedTypes() } } } - + // Collect the partials BfSizedVector typeParts; typeParts.push_back(rootTypeDef); - auto checkTypeDefEntryIdx = mSystem->mTypeDefs.mHashHeads[bucketIdx]; + auto checkTypeDefEntryIdx = mSystem->mTypeDefs.mHashHeads[bucketIdx]; while (checkTypeDefEntryIdx != -1) { auto checkTypeDefEntry = &mSystem->mTypeDefs.mEntries[checkTypeDefEntryIdx]; @@ -3488,7 +3484,7 @@ void BfCompiler::UpdateRevisedTypes() continue; } } - + if (checkTypeDef->mTypeCode == BfTypeCode_Extension) { // This was an extension that was orphaned but now we're taking it back @@ -3497,13 +3493,13 @@ void BfCompiler::UpdateRevisedTypes() compositeTypeDef->mPartialUsed = true; checkTypeDef->mPartialUsed = true; - + if (checkTypeDef->mDefState == BfTypeDef::DefState_Deleted) { - partialsHadChanges = true; + partialsHadChanges = true; hadSignatureChange = true; - } - else + } + else { if (checkTypeDef != rootTypeDef) typeParts.push_back(checkTypeDef); @@ -3522,7 +3518,7 @@ void BfCompiler::UpdateRevisedTypes() } // Set this down here, because the InjectNewRevision will clear this flag rootTypeDef->mIsPartial = true; - + if (partialsHadChanges) { BF_ASSERT(compositeTypeDef->mNextRevision == NULL); @@ -3576,7 +3572,7 @@ void BfCompiler::UpdateRevisedTypes() } } - // We use the root typedef's namespace search for the composite, but this should only be + // We use the root typedef's namespace search for the composite, but this should only be // used for cases where we CANNOT specify a typeref on an extension. IE: custom attributes // for a type can only be added on the root typedef. If this changes then we need to make // sure that we attach a definingType to attributes @@ -3589,7 +3585,7 @@ void BfCompiler::UpdateRevisedTypes() if (rootTypeDef != NULL) compositeTypeDef->mNamespaceSearch = rootTypeDef->mNamespaceSearch; else - compositeTypeDef->mNamespaceSearch.Clear(); + compositeTypeDef->mNamespaceSearch.Clear(); //BfLogSysM("Composite type %p updating. isNew: %d\n", compositeTypeDef, compositeIsNew); @@ -3625,13 +3621,13 @@ void BfCompiler::UpdateRevisedTypes() compositeTypeDef->mTypeCode = BfTypeCode_Object; }*/ - auto latestCompositeTypeDef = compositeTypeDef->GetLatest(); + auto latestCompositeTypeDef = compositeTypeDef->GetLatest(); if (latestCompositeTypeDef->mTypeCode == BfTypeCode_Extension) { BF_ASSERT(rootTypeDef == NULL); latestCompositeTypeDef->mTypeCode = BfTypeCode_Struct; } - + BfLogSysM("Partial combined type typedef %p updated from parser %p\n", compositeTypeDef, latestCompositeTypeDef->mTypeDeclaration->GetSourceData()); } @@ -3649,13 +3645,13 @@ void BfCompiler::UpdateRevisedTypes() } } } - } + } outerTypeDefEntryIdx = outerTypeDefEntry->mNext; } // Handle unused partials, apply any new revisions, process pending deletes - + if ((hadPartials) || (hadChanges)) { BfTypeDef* checkMasterTypeDef = NULL; @@ -3717,7 +3713,7 @@ void BfCompiler::UpdateRevisedTypes() outerTypeDef->mDefState = BfTypeDef::DefState_New; } } - } + } } outerTypeDefEntryIdx = nextTypeDefEntryIdx; @@ -3729,27 +3725,27 @@ void BfCompiler::UpdateRevisedTypes() { // If this got added to a composite partial then delete the previous solo type if (typeDef->mIsPartial) - { + { BfLogSysM("Solo partial going back to normal partial %p\n", typeDef); typeDef->mIsPartial = false; auto type = mContext->mScratchModule->ResolveTypeDef(typeDef, BfPopulateType_Identity); mContext->DeleteType(type); - typeDef->mIsPartial = true; + typeDef->mIsPartial = true; } } - + mContext->UpdateRevisedTypes(); - mContext->VerifyTypeLookups(); - + mContext->VerifyTypeLookups(); + mContext->ValidateDependencies(); if (mStats.mTypesDeleted != 0) { mContext->UpdateAfterDeletingTypes(); mContext->ValidateDependencies(); } - mContext->RemoveInvalidWorkItems(); - + mContext->RemoveInvalidWorkItems(); + mSystem->mNeedsTypesHandledByCompiler = false; //TODO: @@ -3786,7 +3782,7 @@ void BfCompiler::VisitAutocompleteExteriorIdentifiers() BF_ASSERT(mContext->mScratchModule->mCurTypeInstance == NULL); SetAndRestoreValue prevCurTypeInstance(mContext->mScratchModule->mCurTypeInstance, NULL); - SetAndRestoreValue prevIgnoreErrors(mContext->mScratchModule->mIgnoreErrors, true); + SetAndRestoreValue prevIgnoreErrors(mContext->mScratchModule->mIgnoreErrors, true); mContext->mScratchModule->ResolveTypeRef(usingDirective->mTypeRef, NULL); if (mResolvePassData->mAutoComplete != NULL) mResolvePassData->mAutoComplete->CheckTypeRef(usingDirective->mTypeRef, false, isUsingDirective); @@ -3801,7 +3797,7 @@ void BfCompiler::VisitAutocompleteExteriorIdentifiers() if (mResolvePassData->mAutoComplete != NULL) mResolvePassData->mAutoComplete->CheckIdentifier(checkIdentifier, false, isUsingDirective); - + if (auto sourceClassifier = mResolvePassData->GetSourceClassifier(checkIdentifier)) { if (isUsingDirective) @@ -3846,7 +3842,7 @@ void BfCompiler::VisitSourceExteriorNodes() if (!_AddName(qualifedTypeRef->mRight, wantErrors)) return false; return true; - } + } else if ((node->IsA()) || (node->IsA())) { srcNodes.Add(node); @@ -3892,7 +3888,7 @@ void BfCompiler::VisitSourceExteriorNodes() prevNamespace.mParts = &namespaceParts[0]; prevNamespace.mSize = i; if (wantErrors) - { + { if (i == 0) mPassInstance->Fail(StrFormat("The namespace '%s' does not exist", namespaceParts[i]->mString.ToString().c_str()), srcNodes[i]); else @@ -3909,7 +3905,7 @@ void BfCompiler::VisitSourceExteriorNodes() while (parser->mNextRevision != NULL) parser = parser->mNextRevision; if (parser->mAwaitingDelete) - return; + return; if (parser->mParserData == NULL) return; @@ -3918,7 +3914,7 @@ void BfCompiler::VisitSourceExteriorNodes() bool failed = false; for (auto& node : parser->mParserData->mExteriorNodes) - { + { SetAndRestoreValue*> prevCurNamespaceNodes(mContext->mCurNamespaceNodes, &node.mNamespaceNodes); auto exteriorAstNode = node.mNode; @@ -3927,7 +3923,7 @@ void BfCompiler::VisitSourceExteriorNodes() { srcNodes.Clear(); namespaceParts.Clear(); - bool success = _AddName(usingDirective->mNamespace, true); + bool success = _AddName(usingDirective->mNamespace, true); _CheckNamespace(parser, true, failed); } else if (auto usingDirective = BfNodeDynCast(exteriorAstNode)) @@ -3973,7 +3969,7 @@ void BfCompiler::VisitSourceExteriorNodes() for (auto parser : mResolvePassData->mParsers) _CheckParser(parser); } - else + else { for (auto parser : mSystem->mParsers) { @@ -3984,18 +3980,18 @@ void BfCompiler::VisitSourceExteriorNodes() void BfCompiler::ProcessAutocompleteTempType() { - BP_ZONE_F("BfCompiler::ProcessAutocompleteTempType %d", mResolvePassData->mResolveType); + BP_ZONE_F("BfCompiler::ProcessAutocompleteTempType %d", mResolvePassData->mResolveType); String& autoCompleteResultString = *gTLStrReturn.Get(); autoCompleteResultString.clear(); - + if (mContext->mBfObjectType == NULL) return; // Not initialized yet auto module = mContext->mScratchModule; auto autoComplete = mResolvePassData->mAutoComplete; BfLogSysM("ProcessAutocompleteTempType %d\n", autoComplete->mResolveType); - + SetAndRestoreValue prevCanceling(mCanceling, false); BF_ASSERT(mResolvePassData->mAutoComplete->mDefMethod == NULL); @@ -4022,7 +4018,7 @@ void BfCompiler::ProcessAutocompleteTempType() } for (auto tempTypeDef : mResolvePassData->mAutoCompleteTempTypes) - { + { String typeName = tempTypeDef->ToString(); BfLogSysM("BfResolveType_GetNavigationData TypeDef:%p %s\n", tempTypeDef, typeName.c_str()); @@ -4052,7 +4048,7 @@ void BfCompiler::ProcessAutocompleteTempType() String methodText; for (auto methodDef : tempTypeDef->mMethods) - { + { if (((methodDef->mMethodType == BfMethodType_Normal) || (methodDef->mMethodType == BfMethodType_Operator) || (methodDef->mMethodType == BfMethodType_Ctor) || (methodDef->mMethodType == BfMethodType_Dtor) || (methodDef->mMethodType == BfMethodType_Mixin) || (methodDef->mMethodType == BfMethodType_Extension)) && @@ -4060,7 +4056,7 @@ void BfCompiler::ProcessAutocompleteTempType() { methodText = methodDef->ToString(); if (typeName != "@") - methodText = typeName + "." + methodText; + methodText = typeName + "." + methodText; if (!autoCompleteResultString.empty()) autoCompleteResultString += "\n"; @@ -4094,7 +4090,7 @@ void BfCompiler::ProcessAutocompleteTempType() if (!autoCompleteResultString.empty()) autoCompleteResultString += "\n"; - BfAstNode* refNode = propDeclaration->mNameNode; + BfAstNode* refNode = propDeclaration->mNameNode; module->UpdateSrcPos(refNode, (BfSrcPosFlags)(BfSrcPosFlag_NoSetDebugLoc | BfSrcPosFlag_Force)); propText += StrFormat("\tproperty\t%d\t%d", module->mCurFilePosition.mCurLine, module->mCurFilePosition.mCurColumn); @@ -4119,7 +4115,7 @@ void BfCompiler::ProcessAutocompleteTempType() autoCompleteResultString = typeName; for (auto methodDef : tempTypeDef->mMethods) - { + { BfAstNode* defNode = methodDef->mMethodDeclaration; if (auto propertyDeclaration = methodDef->GetPropertyDeclaration()) defNode = propertyDeclaration; @@ -4131,7 +4127,7 @@ void BfCompiler::ProcessAutocompleteTempType() if ((parser == NULL) || (parser->mCursorIdx == -1)) continue; - if ((defNode != NULL) && + if ((defNode != NULL) && (defNode->Contains(parser->mCursorIdx))) { String methodText = methodDef->ToString(); @@ -4141,7 +4137,7 @@ void BfCompiler::ProcessAutocompleteTempType() autoCompleteResultString = methodText; break; } - } + } } if (mResolvePassData->mAutoCompleteTempTypes.IsEmpty()) @@ -4161,17 +4157,17 @@ void BfCompiler::ProcessAutocompleteTempType() if (mResolvePassData->mParsers.IsEmpty()) break; - + autoCompleteResultString = mContext->mScratchModule->TypeToString(typeInst); for (auto methodDef : typeInst->mTypeDef->mMethods) - { + { BfAstNode* defNode = methodDef->mMethodDeclaration; if (auto propertyDeclaration = methodDef->GetPropertyDeclaration()) defNode = propertyDeclaration; if (defNode == NULL) - continue; + continue; if ((defNode != NULL) && (defNode->Contains(kv.mValue.mCursorIdx))) @@ -4182,9 +4178,9 @@ void BfCompiler::ProcessAutocompleteTempType() if (!defParser->mIsEmitted) continue; - + autoCompleteResultString += "."; - autoCompleteResultString += methodDef->ToString(); + autoCompleteResultString += methodDef->ToString(); break; } } @@ -4204,16 +4200,16 @@ void BfCompiler::ProcessAutocompleteTempType() // >>> VisitExteriorIdentifiers mResolvePassData->mAutoComplete->SetModule(module); - { - BP_ZONE("VisitExteriorIdentifiers"); + { + BP_ZONE("VisitExteriorIdentifiers"); VisitAutocompleteExteriorIdentifiers(); - } + } VisitSourceExteriorNodes(); if (autoComplete->mResolveType == BfResolveType_GetFixits) { BfAstNode* conflictStart = NULL; - BfAstNode* conflictSplit = NULL; + BfAstNode* conflictSplit = NULL; for (auto parser : mResolvePassData->mParsers) { @@ -4266,7 +4262,6 @@ void BfCompiler::ProcessAutocompleteTempType() } } } - } if (autoComplete->mResolveType == BfResolveType_GetSymbolInfo) @@ -4277,7 +4272,7 @@ void BfCompiler::ProcessAutocompleteTempType() for (auto parser : mResolvePassData->mParsers) namespaceVisitor.Visit(parser->mRootNode); } - + auto _FindAcutalTypeDef = [&](BfTypeDef* tempTypeDef) { auto typeName = tempTypeDef->mFullName; @@ -4366,7 +4361,7 @@ void BfCompiler::ProcessAutocompleteTempType() GenerateAutocompleteInfo(); BfLogSysM("ProcessAutocompleteTempType - no tempTypeDef\n"); return; - } + } if (tempTypeDef->mProject->mDisabled) { @@ -4406,7 +4401,7 @@ void BfCompiler::ProcessAutocompleteTempType() if (mSystem->ParseAtomComposite(checkNamespaceStr, checkNamespace)) { if (mSystem->ContainsNamespace(checkNamespace, tempTypeDef->mProject)) - { + { internalAccessSet->mNamespaces.Add(checkNamespace); continue; } @@ -4425,10 +4420,10 @@ void BfCompiler::ProcessAutocompleteTempType() internalAccessSet->mTypes.Add(typeInst); } } - } + } if (tempTypeDef->mTypeCode == BfTypeCode_Extension) - { + { BfTypeInstance* outerTypeInstance = NULL; if (tempTypeDef->mOuterType != NULL) @@ -4447,25 +4442,25 @@ void BfCompiler::ProcessAutocompleteTempType() auto autoComplete = mResolvePassData->mAutoComplete; if (autoComplete->IsAutocompleteNode(tempTypeDef->mTypeDeclaration->mNameNode)) { - BfIdentifierNode* nameNode = tempTypeDef->mTypeDeclaration->mNameNode; + BfIdentifierNode* nameNode = tempTypeDef->mTypeDeclaration->mNameNode; autoComplete->AddTopLevelNamespaces(nameNode); autoComplete->AddTopLevelTypes(nameNode); autoComplete->mInsertStartIdx = nameNode->GetSrcStart(); - autoComplete->mInsertEndIdx = nameNode->GetSrcEnd(); + autoComplete->mInsertEndIdx = nameNode->GetSrcEnd(); } } - + // while (actualTypeDef == NULL) // { // checkT // } if ((actualTypeDef == NULL) || (actualTypeDef->mTypeDeclaration == NULL)) - { + { GenerateAutocompleteInfo(); return; } - + auto sourceClassifier = mResolvePassData->GetSourceClassifier(tempTypeDef->mTypeDeclaration); if (tempTypeDef->mTypeCode == BfTypeCode_Extension) sourceClassifier->SetElementType(tempTypeDef->mTypeDeclaration->mNameNode, actualTypeDef->mTypeCode); @@ -4474,7 +4469,7 @@ void BfCompiler::ProcessAutocompleteTempType() BfTypeInstance* typeInst; { - BP_ZONE("ProcessAutocompleteTempType.ResolveTypeDef"); + BP_ZONE("ProcessAutocompleteTempType.ResolveTypeDef"); typeInst = (BfTypeInstance*)module->ResolveTypeDef(actualTypeDef, BfPopulateType_IdentityNoRemapAlias); if ((typeInst != NULL) && (typeInst->IsIncomplete())) @@ -4482,8 +4477,8 @@ void BfCompiler::ProcessAutocompleteTempType() } if (typeInst == NULL) - { - return; + { + return; } BF_ASSERT((typeInst->mSize != -1) || (typeInst->IsTypeAlias())); @@ -4492,17 +4487,17 @@ void BfCompiler::ProcessAutocompleteTempType() if ((typeInst->mModule != NULL) && (!typeInst->mModule->mIsScratchModule)) mLastAutocompleteModule = typeInst->mModule; #endif - + SetAndRestoreValue prevType(module->mCurTypeInstance, typeInst); typeState.mType = typeInst; - + BfGenericExtensionEntry* genericExEntry = NULL; bool hadTempExtensionInfo = false; if ((tempTypeDef->IsExtension()) && (actualTypeDef->mIsCombinedPartial) && (typeInst->IsGenericTypeInstance())) { // Add to our extension info map and then take it out at the end... auto genericTypeInst = (BfTypeInstance*)typeInst; - module->BuildGenericExtensionInfo(genericTypeInst, tempTypeDef); + module->BuildGenericExtensionInfo(genericTypeInst, tempTypeDef); genericTypeInst->mGenericTypeInfo->mGenericExtensionInfo->mExtensionMap.TryGetValue(tempTypeDef, &genericExEntry); BF_ASSERT(genericExEntry != NULL); hadTempExtensionInfo = true; @@ -4521,7 +4516,7 @@ void BfCompiler::ProcessAutocompleteTempType() autoComplete->AddTopLevelTypes(tempTypeDef->mTypeDeclaration->mNameNode); autoComplete->SetDefinitionLocation(actualTypeDef->mTypeDeclaration->mNameNode); } - else + else autoComplete->SetDefinitionLocation(nameNode); autoComplete->mDefType = actualTypeDef; autoComplete->mInsertStartIdx = nameNode->GetSrcStart(); @@ -4532,8 +4527,8 @@ void BfCompiler::ProcessAutocompleteTempType() autoComplete->mResultString = ":"; autoComplete->mResultString += module->TypeToString(typeInst, (BfTypeNameFlags)(BfTypeNameFlag_ExtendedInfo | BfTypeNameFlag_ResolveGenericParamNames)); } - } - } + } + } autoComplete->CheckInterfaceFixit(typeInst, tempTypeDef->mTypeDeclaration->mNameNode); if (tempTypeDef->mTypeCode == BfTypeCode_TypeAlias) @@ -4555,9 +4550,9 @@ void BfCompiler::ProcessAutocompleteTempType() auto customAttrs = module->GetCustomAttributes(tempTypeDef); delete customAttrs; } - + for (int genericParamIdx = 0; genericParamIdx < (int)tempTypeDef->mGenericParamDefs.size(); genericParamIdx++) - { + { auto genericParamDef = tempTypeDef->mGenericParamDefs[genericParamIdx]; auto genericParamInstance = new BfGenericTypeParamInstance(tempTypeDef, genericParamIdx); @@ -4565,16 +4560,16 @@ void BfCompiler::ProcessAutocompleteTempType() module->ResolveGenericParamConstraints(genericParamInstance, true); delete genericParamInstance; - for (auto nameNode : genericParamDef->mNameNodes) - module->HandleTypeGenericParamRef(nameNode, tempTypeDef, genericParamIdx); + for (auto nameNode : genericParamDef->mNameNodes) + module->HandleTypeGenericParamRef(nameNode, tempTypeDef, genericParamIdx); } //TODO: Do extern constraint stuff here for (auto fieldDef : tempTypeDef->mFields) { - BP_ZONE("ProcessAutocompleteTempType.CheckField"); - + BP_ZONE("ProcessAutocompleteTempType.CheckField"); + if (BfNodeIsA(fieldDef->mFieldDeclaration)) continue; // Don't process auto-generated property fields @@ -4588,14 +4583,14 @@ void BfCompiler::ProcessAutocompleteTempType() module->ResolveTypeRef(fieldDef->mTypeRef, BfPopulateType_Identity, flags); } mResolvePassData->mAutoComplete->CheckTypeRef(fieldDef->mTypeRef, true); - + actualTypeDef->PopulateMemberSets(); - BfFieldDef* actualFieldDef = NULL; + BfFieldDef* actualFieldDef = NULL; BfMemberSetEntry* memberSetEntry = NULL; if (actualTypeDef->mFieldSet.TryGetWith((StringImpl&)fieldDef->mName, &memberSetEntry)) { - auto checkFieldDef = (BfFieldDef*)memberSetEntry->mMemberDef; + auto checkFieldDef = (BfFieldDef*)memberSetEntry->mMemberDef; if ((checkFieldDef->mIsConst == fieldDef->mIsConst) && (checkFieldDef->mIsStatic == fieldDef->mIsStatic)) { @@ -4629,18 +4624,18 @@ void BfCompiler::ProcessAutocompleteTempType() } else if (autoComplete->mResolveType == BfResolveType_GetResultString) { - auto fieldInstance = &typeInst->mFieldInstances[actualFieldDef->mIdx]; + auto fieldInstance = &typeInst->mFieldInstances[actualFieldDef->mIdx]; if (fieldInstance->mConstIdx != -1) - { + { auto constant = typeInst->mConstHolder->GetConstantById(fieldInstance->mConstIdx); auto retVal = module->ConstantToCurrent(constant, typeInst->mConstHolder, fieldInstance->mResolvedType); BfTypedValue typedValue = BfTypedValue(retVal, fieldInstance->mResolvedType); - autoComplete->CheckResult(fieldDef->GetRefNode(), typedValue); + autoComplete->CheckResult(fieldDef->GetRefNode(), typedValue); } } break; } - } + } } BfFieldDeclaration* fieldDecl = fieldDef->GetFieldDeclaration(); @@ -4651,20 +4646,20 @@ void BfCompiler::ProcessAutocompleteTempType() } if (fieldDef->mIsConst) - { - module->ResolveConstField(typeInst, NULL, fieldDef); + { + module->ResolveConstField(typeInst, NULL, fieldDef); } - + if (fieldDef->GetInitializer() == NULL) { if (BfNodeIsA(fieldDef->mTypeRef)) - { + { if ((fieldDef->mTypeRef->IsA()) || (fieldDef->mTypeRef->IsA())) - mPassInstance->Fail("Implicitly-typed fields must be initialized", fieldDef->GetRefNode()); + mPassInstance->Fail("Implicitly-typed fields must be initialized", fieldDef->GetRefNode()); } } } - + auto checkTypeDef = tempTypeDef; while (checkTypeDef != NULL) { @@ -4675,9 +4670,9 @@ void BfCompiler::ProcessAutocompleteTempType() } checkTypeDef = checkTypeDef->mOuterType; } - + for (auto propDef : tempTypeDef->mProperties) - { + { auto fieldDecl = propDef->GetFieldDeclaration(); if ((fieldDecl != NULL) && (fieldDecl->mAttributes != NULL)) @@ -4688,7 +4683,7 @@ void BfCompiler::ProcessAutocompleteTempType() auto customAttrs = module->GetCustomAttributes(fieldDecl->mAttributes, target); delete customAttrs; } - + auto propDeclaration = BfNodeDynCast(fieldDecl); if (propDeclaration != NULL) autoComplete->CheckProperty(propDeclaration); @@ -4703,7 +4698,7 @@ void BfCompiler::ProcessAutocompleteTempType() if (auto indexerDeclaration = BfNodeDynCast(propDef->mFieldDeclaration)) { for (auto paramDecl : indexerDeclaration->mParams) - { + { module->ResolveTypeRef(paramDecl->mTypeRef, BfPopulateType_Identity); } } @@ -4731,11 +4726,11 @@ void BfCompiler::ProcessAutocompleteTempType() if (checkType != NULL) checkType = checkType->mBaseType; - } + } } } - - Array methodInstances; + + Array methodInstances; for (auto methodDef : tempTypeDef->mMethods) { @@ -4744,7 +4739,7 @@ void BfCompiler::ProcessAutocompleteTempType() autoComplete->CheckMethod(methodDeclaration, false); if (!methodDef->mWantsBody) - { + { if (methodDeclaration != NULL) { if (methodDeclaration->mAttributes != NULL) @@ -4756,16 +4751,16 @@ void BfCompiler::ProcessAutocompleteTempType() else if (auto methodPropertyDeclaration = methodDef->GetPropertyMethodDeclaration()) { if (methodPropertyDeclaration->mAttributes != NULL) - { + { auto customAttrs = module->GetCustomAttributes(methodPropertyDeclaration->mAttributes, BfAttributeTargets_Method); - delete customAttrs; - } + delete customAttrs; + } } - + continue; } - BP_ZONE("ProcessAutocompleteTempType.CheckMethod"); + BP_ZONE("ProcessAutocompleteTempType.CheckMethod"); BfMethodInstanceGroup methodInstanceGroup; methodInstanceGroup.mOwner = typeInst; methodInstanceGroup.mOnDemandKind = BfMethodOnDemandKind_AlwaysInclude; @@ -4778,13 +4773,13 @@ void BfCompiler::ProcessAutocompleteTempType() methodInstanceGroup.mDefault = methodInstance; defer(methodInstanceGroup.mDefault = NULL); - + for (int genericParamIdx = 0; genericParamIdx < (int)methodDef->mGenericParams.size(); genericParamIdx++) { auto genericParamType = module->GetGenericParamType(BfGenericParamKind_Method, genericParamIdx); methodInstance->GetMethodInfoEx()->mMethodGenericArguments.push_back(genericParamType); - auto genericParamInstance = new BfGenericMethodParamInstance(methodDef, genericParamIdx); + auto genericParamInstance = new BfGenericMethodParamInstance(methodDef, genericParamIdx); methodInstance->GetMethodInfoEx()->mGenericParams.push_back(genericParamInstance); } @@ -4797,14 +4792,14 @@ void BfCompiler::ProcessAutocompleteTempType() bool wantsProcess = !actualTypeDef->mIsFunction; SetAndRestoreValue prevFilePos(module->mCurFilePosition); - SetAndRestoreValue prevMethodInst(module->mCurMethodInstance, methodInstance); + SetAndRestoreValue prevMethodInst(module->mCurMethodInstance, methodInstance); module->DoMethodDeclaration(methodDeclaration, true, wantsProcess); if (wantsProcess) { module->mIncompleteMethodCount++; module->ProcessMethod(methodInstance); } - + if (methodInstance->mIRFunction) { BfLogSysM("Autocomplete removing IRFunction %d\n", methodInstance->mIRFunction.mId); @@ -4812,10 +4807,10 @@ void BfCompiler::ProcessAutocompleteTempType() module->mBfIRBuilder->Func_SafeRename(methodInstance->mIRFunction); } } - - if ((mResolvePassData->mAutoComplete->mDefType != NULL) && (mResolvePassData->mAutoComplete->mDefType->GetDefinition() == actualTypeDef) && + + if ((mResolvePassData->mAutoComplete->mDefType != NULL) && (mResolvePassData->mAutoComplete->mDefType->GetDefinition() == actualTypeDef) && (mResolvePassData->mAutoComplete->mDefMethod != NULL)) - { + { BfMethodDef* tempDefMethod = NULL; for (auto checkMethod : tempTypeDef->mMethods) { @@ -4857,7 +4852,7 @@ void BfCompiler::ProcessAutocompleteTempType() for (auto checkNode : mResolvePassData->mExteriorAutocompleteCheckNodes) { - BP_ZONE("ProcessAutocompleteTempType.CheckIdentifier"); + BP_ZONE("ProcessAutocompleteTempType.CheckIdentifier"); bool isUsingDirective = false; BfIdentifierNode* checkIdentifier = NULL; @@ -4869,26 +4864,26 @@ void BfCompiler::ProcessAutocompleteTempType() else checkIdentifier = BfNodeDynCast(checkNode); mResolvePassData->mAutoComplete->CheckIdentifier(checkIdentifier, false, isUsingDirective); - } + } GenerateAutocompleteInfo(); for (auto methodInstance : methodInstances) delete methodInstance; - methodInstances.Clear(); - - module->CleanupFileInstances(); + methodInstances.Clear(); - prevTypeInstance.Restore(); + module->CleanupFileInstances(); + + prevTypeInstance.Restore(); if (module->mCurTypeInstance == NULL) module->ClearConstData(); - + BfLogSysM("ProcessAutocompleteTempType end\n"); } BfType* BfCompiler::CheckSymbolReferenceTypeRef(BfModule* module, BfTypeReference* typeRef) { - //auto resolvedType = module->ResolveTypeRef(typeRef, BfPopulateType_Declaration, + //auto resolvedType = module->ResolveTypeRef(typeRef, BfPopulateType_Declaration, //(BfResolveTypeRefFlags)(BfResolveTypeRefFlag_AllowRef | BfResolveTypeRefFlag_AllowGenericMethodParamConstValue | BfResolveTypeRefFlag_AllowGenericTypeParamConstValue)); auto resolvedType = module->ResolveTypeRef(typeRef, BfPopulateType_Declaration, BfResolveTypeRefFlag_AllowRef); if ((resolvedType != NULL) && (resolvedType->IsTypeInstance())) @@ -4934,8 +4929,8 @@ void BfCompiler::AddDepsToRebuildTypeList(BfTypeInstance* replaceTypeInst, HashS if (depTypeInst == NULL) continue; - AddToRebuildTypeList(depTypeInst, rebuildTypeInstList); - } + AddToRebuildTypeList(depTypeInst, rebuildTypeInstList); + } } void BfCompiler::GetSymbolReferences() @@ -4948,11 +4943,11 @@ void BfCompiler::GetSymbolReferences() auto context = mContext; if (context->mBfObjectType == NULL) return; // Not initialized yet - auto module = context->mScratchModule; + auto module = context->mScratchModule; if (mResolvePassData->mAutoComplete != NULL) mResolvePassData->mAutoComplete->SetModule(module); - + BfTypeDef* typeDef = NULL; HashSet rebuildTypeInstList; if (!mResolvePassData->mQueuedSymbolReferenceNamespace.IsEmpty()) @@ -4964,10 +4959,10 @@ void BfCompiler::GetSymbolReferences() { auto typeInst = type->ToTypeInstance(); if (typeInst == NULL) - continue; + continue; for (auto& lookupKV : typeInst->mLookupResults) - { + { auto typeDef = lookupKV.mValue.mTypeDef; if ((typeDef != NULL) && (typeDef->mNamespace.StartsWith(mResolvePassData->mSymbolReferenceNamespace))) { @@ -4996,7 +4991,7 @@ void BfCompiler::GetSymbolReferences() auto replaceType = module->ResolveTypeDef(typeDef, BfPopulateType_IdentityNoRemapAlias); module->PopulateType(replaceType); auto replaceTypeInst = replaceType->ToTypeInstance(); - + if (mResolvePassData->mGetSymbolReferenceKind != BfGetSymbolReferenceKind_Local) { AddDepsToRebuildTypeList(replaceTypeInst, rebuildTypeInstList); @@ -5029,11 +5024,11 @@ void BfCompiler::GetSymbolReferences() while (attrib != NULL) { if (attrib->mAttributeTypeRef != NULL) - { + { auto attrType = module->ResolveTypeRef(attrib->mAttributeTypeRef, BfPopulateType_Identity, BfResolveTypeRefFlag_Attribute); BfTypeDef* attrTypeDef = NULL; if ((attrType != NULL) && (attrType->IsTypeInstance())) - attrTypeDef = attrType->ToTypeInstance()->mTypeDef; + attrTypeDef = attrType->ToTypeInstance()->mTypeDef; if (attrTypeDef != NULL) { mResolvePassData->HandleTypeReference(attrib->mAttributeTypeRef, attrTypeDef); @@ -5055,7 +5050,7 @@ void BfCompiler::GetSymbolReferences() } } } - } + } } attrib = attrib->mNextAttribute; @@ -5063,7 +5058,7 @@ void BfCompiler::GetSymbolReferences() }; for (auto rebuildTypeInst : rebuildTypeInstList) - { + { // These never have a definition. Also note that BfGenericDelegateType does not have proper generic defs if (rebuildTypeInst->IsOnDemand()) continue; @@ -5086,7 +5081,7 @@ void BfCompiler::GetSymbolReferences() for (auto parser : mResolvePassData->mParsers) { if (nameNode->IsFromParser(parser)) - { + { mResolvePassData->HandleTypeReference(nameNode, typeDef); break; } @@ -5101,7 +5096,7 @@ void BfCompiler::GetSymbolReferences() { BfTypeState typeState; typeState.mCurTypeDef = checkTypeDef; - SetAndRestoreValue prevTypeState(module->mContext->mCurTypeState, &typeState); + SetAndRestoreValue prevTypeState(module->mContext->mCurTypeState, &typeState); for (auto baseTypeRef : checkTypeDef->mBaseTypes) CheckSymbolReferenceTypeRef(module, baseTypeRef); @@ -5126,7 +5121,7 @@ void BfCompiler::GetSymbolReferences() } } else - { + { mResolvePassData->HandleTypeReference(typeDef->mTypeDeclaration->mNameNode, typeDef); } } @@ -5143,13 +5138,13 @@ void BfCompiler::GetSymbolReferences() { if ((typeDef->mTypeDeclaration != NULL) && (typeDef->mTypeDeclaration->mAttributes != NULL)) _CheckAttributes(typeDef->mTypeDeclaration->mAttributes, typeDef); - } + } if (auto typeAliasDeclaration = BfNodeDynCast(typeDef->mTypeDeclaration)) { CheckSymbolReferenceTypeRef(module, typeAliasDeclaration->mAliasToType); } - + if (mResolvePassData != NULL) { if (rebuildTypeInst->IsGenericTypeInstance()) @@ -5169,24 +5164,23 @@ void BfCompiler::GetSymbolReferences() } rebuildModule->ResolveGenericParamConstraints(&genericParamInstance, genericTypeInstance->IsGenericTypeInstance()); - } + } } } - if (mResolvePassData->mGetSymbolReferenceKind == BfGetSymbolReferenceKind_Type) { - for (auto baseTypeRef : typeDef->mBaseTypes) + for (auto baseTypeRef : typeDef->mBaseTypes) CheckSymbolReferenceTypeRef(module, baseTypeRef); } BfTypeState typeState; - SetAndRestoreValue prevTypeState(module->mContext->mCurTypeState, &typeState); + SetAndRestoreValue prevTypeState(module->mContext->mCurTypeState, &typeState); if (mResolvePassData->mGetSymbolReferenceKind == BfGetSymbolReferenceKind_Property) { for (auto propDef : typeDef->mProperties) - { + { BfPropertyDef* checkPropDef = propDef; BfTypeInstance* checkTypeInst = rebuildTypeInst; typeState.mCurTypeDef = propDef->mDeclaringType; @@ -5197,7 +5191,7 @@ void BfCompiler::GetSymbolReferences() } if (mResolvePassData->mGetSymbolReferenceKind == BfGetSymbolReferenceKind_Field) - { + { for (auto fieldDef : typeDef->mFields) { if (auto nameNode = fieldDef->GetNameNode()) @@ -5207,7 +5201,7 @@ void BfCompiler::GetSymbolReferences() } } } - + for (auto& fieldInst : rebuildTypeInst->mFieldInstances) { auto fieldDef = fieldInst.GetFieldDef(); @@ -5221,8 +5215,8 @@ void BfCompiler::GetSymbolReferences() { BfMethodState methodState; methodState.mTempKind = BfMethodState::TempKind_Static; - SetAndRestoreValue prevMethodState(module->mCurMethodState, &methodState); - BfConstResolver constResolver(module); + SetAndRestoreValue prevMethodState(module->mCurMethodState, &methodState); + BfConstResolver constResolver(module); constResolver.Resolve(fieldDef->GetInitializer()); } @@ -5239,8 +5233,8 @@ void BfCompiler::GetSymbolReferences() typeState.mCurTypeDef = propDef->mDeclaringType; if (propDef->mTypeRef != NULL) CheckSymbolReferenceTypeRef(module, propDef->mTypeRef); - } - + } + if (rebuildModule == NULL) continue; rebuildModule->EnsureIRBuilder(); @@ -5248,12 +5242,12 @@ void BfCompiler::GetSymbolReferences() for (auto& methodInstGroup : rebuildTypeInst->mMethodInstanceGroups) { - // Run through all methods + // Run through all methods bool isDefault = true; - + BfMethodInstanceGroup::MapType::iterator methodItr; if (methodInstGroup.mMethodSpecializationMap != NULL) - methodItr = methodInstGroup.mMethodSpecializationMap->begin(); + methodItr = methodInstGroup.mMethodSpecializationMap->begin(); while (true) { BfMethodInstance* rebuildMethodInstance; @@ -5277,23 +5271,23 @@ void BfCompiler::GetSymbolReferences() // rebuildMethodInstance = methodItr->mValue; // ++methodItr; } - + if ((rebuildMethodInstance->IsOrInUnspecializedVariation()) || (rebuildMethodInstance->IsSpecializedGenericMethod())) - continue; - + continue; + SetAndRestoreValue prevTypeInstance(rebuildModule->mCurMethodInstance, rebuildMethodInstance); auto methodDef = rebuildMethodInstance->mMethodDef; auto methodDeclaration = methodDef->GetMethodDeclaration(); typeState.mCurTypeDef = methodDef->mDeclaringType; - + if ((methodDeclaration != NULL) && (methodDeclaration->mAttributes != NULL)) - _CheckAttributes(methodDeclaration->mAttributes, methodDef->mDeclaringType); + _CheckAttributes(methodDeclaration->mAttributes, methodDef->mDeclaringType); if ((mResolvePassData->mGetSymbolReferenceKind == BfGetSymbolReferenceKind_Type) || (mResolvePassData->mGetSymbolReferenceKind == BfGetSymbolReferenceKind_MethodGenericParam) || (mResolvePassData->mGetSymbolReferenceKind == BfGetSymbolReferenceKind_TypeGenericParam)) - { + { if (methodDef->mExplicitInterface != NULL) CheckSymbolReferenceTypeRef(rebuildModule, methodDef->mExplicitInterface); @@ -5312,7 +5306,7 @@ void BfCompiler::GetSymbolReferences() if (methodDeclaration != NULL) mResolvePassData->HandleMethodReference(methodDeclaration->mNameNode, typeDef, methodDef); - for (int paramIdx = 0; paramIdx < (int)methodDef->mParams.size(); paramIdx++) + for (int paramIdx = 0; paramIdx < (int)methodDef->mParams.size(); paramIdx++) { auto param = methodDef->mParams[paramIdx]; if (param->mParamDeclaration != NULL) @@ -5332,14 +5326,14 @@ void BfCompiler::GetSymbolReferences() } else { - for (int paramIdx = 0; paramIdx < (int)methodDef->mParams.size(); paramIdx++) + for (int paramIdx = 0; paramIdx < (int)methodDef->mParams.size(); paramIdx++) { - auto param = methodDef->mParams[paramIdx]; + auto param = methodDef->mParams[paramIdx]; if ((param->mParamDeclaration != NULL) && (param->mParamDeclaration->mInitializer != NULL)) { auto paramType = rebuildMethodInstance->GetParamType(paramIdx); - BfConstResolver constResolver(rebuildModule); + BfConstResolver constResolver(rebuildModule); constResolver.Resolve(param->mParamDeclaration->mInitializer, paramType); } } @@ -5347,7 +5341,7 @@ void BfCompiler::GetSymbolReferences() if (rebuildMethodInstance->mHasBeenProcessed) { if (rebuildMethodInstance->mIRFunction) - rebuildModule->mBfIRBuilder->Func_DeleteBody(rebuildMethodInstance->mIRFunction); + rebuildModule->mBfIRBuilder->Func_DeleteBody(rebuildMethodInstance->mIRFunction); rebuildMethodInstance->mHasBeenProcessed = false; rebuildModule->mIncompleteMethodCount++; } @@ -5358,7 +5352,7 @@ void BfCompiler::GetSymbolReferences() BF_FATAL("Shouldn't be processing this method"); } } - + for (int genericParamIdx = 0; genericParamIdx < (int)rebuildMethodInstance->GetNumGenericArguments(); genericParamIdx++) { BfGenericMethodParamInstance genericParamInstance(rebuildMethodInstance->mMethodDef, genericParamIdx); @@ -5381,7 +5375,7 @@ void BfCompiler::GetSymbolReferences() CheckSymbolReferenceTypeRef(module, externConstraintDef.mTypeRef); rebuildModule->ResolveGenericParamConstraints(&genericParamInstance, rebuildMethodInstance->mIsUnspecialized); } - + rebuildModule->ProcessMethod(rebuildMethodInstance); } } @@ -5395,7 +5389,7 @@ void BfCompiler::UpdateCompletion() return; float typeScale = 10.0f; - float methodScale = 1.0f; + float methodScale = 1.0f; float queueModuleScale = 50.0f; float genModuleScale = 50.0f; @@ -5405,9 +5399,9 @@ void BfCompiler::UpdateCompletion() BF_ASSERT(mStats.mModulesFinished <= mStats.mModulesStarted); BF_ASSERT(mCodeGen.mCompletionCount <= mStats.mModulesStarted); - float numerator = ((mStats.mQueuedTypesProcessed * typeScale) + //(mStats.mMethodsProcessed * methodScale) + + float numerator = ((mStats.mQueuedTypesProcessed * typeScale) + //(mStats.mMethodsProcessed * methodScale) + (mStats.mModulesFinished * queueModuleScale) + (mCodeGen.mCompletionCount * genModuleScale)); - float divisor = ((mStats.mTypesQueued * typeScale) + //(mStats.mMethodsQueued * methodScale) + + float divisor = ((mStats.mTypesQueued * typeScale) + //(mStats.mMethodsQueued * methodScale) + (mStats.mModulesStarted * queueModuleScale) + (mStats.mReifiedModuleCount * genModuleScale)); float checkPct = 0; if (divisor > 0) @@ -5428,8 +5422,8 @@ void BfCompiler::UpdateCompletion() void BfCompiler::MarkStringPool(BfModule* module) { for (int stringId : module->mStringPoolRefs) - { - BfStringPoolEntry& stringPoolEntry = module->mContext->mStringObjectIdMap[stringId]; + { + BfStringPoolEntry& stringPoolEntry = module->mContext->mStringObjectIdMap[stringId]; stringPoolEntry.mLastUsedRevision = mRevision; } @@ -5471,11 +5465,11 @@ void BfCompiler::MarkStringPool(BfIRConstHolder* constHolder, BfIRValue irValue) void BfCompiler::ClearUnusedStringPoolEntries() { BF_ASSERT(!IsHotCompile()); - + for (auto module : mContext->mModules) - { + { MarkStringPool(module); - } + } for (auto type : mContext->mResolvedTypes) { @@ -5500,14 +5494,14 @@ void BfCompiler::ClearUnusedStringPoolEntries() int strId = itr->mKey; BfStringPoolEntry& stringPoolEntry = itr->mValue; if (stringPoolEntry.mLastUsedRevision != mRevision) - { + { CompileLog("Clearing unused string: %d %s\n", itr->mKey, stringPoolEntry.mString.c_str()); mContext->mStringObjectPool.Remove(stringPoolEntry.mString); itr = mContext->mStringObjectIdMap.Remove(itr); } else ++itr; - } + } } void BfCompiler::ClearBuildCache() @@ -5521,7 +5515,7 @@ void BfCompiler::ClearBuildCache() } int BfCompiler::GetDynCastVDataCount() -{ +{ int dynElements = 1 + mMaxInterfaceSlots; return ((dynElements * 4) + mSystem->mPtrSize - 1) / mSystem->mPtrSize; } @@ -5538,7 +5532,7 @@ bool BfCompiler::IsDataResolvePass() bool BfCompiler::WantsClassifyNode(BfAstNode* node) { - return (mResolvePassData != NULL) && (mResolvePassData->GetSourceClassifier(node) != NULL); + return (mResolvePassData != NULL) && (mResolvePassData->GetSourceClassifier(node) != NULL); } BfAutoComplete* BfCompiler::GetAutoComplete() @@ -5568,10 +5562,10 @@ int BfCompiler::GetVTableMethodOffset() bool BfCompiler::DoWorkLoop(bool onlyReifiedTypes, bool onlyReifiedMethods) { bool hadAnyWork = false; - + while (true) { - bool didWork = false; + bool didWork = false; didWork |= mContext->ProcessWorkList(onlyReifiedTypes, onlyReifiedMethods); if (!didWork) break; @@ -5590,7 +5584,6 @@ BfMangler::MangleKind BfCompiler::GetMangleKind() ////////////////////////////////////////////////////////////////////////// - int ArrTest() { //SizedArray intArr; @@ -5603,12 +5596,12 @@ int ArrTest() intArr.push_back(123); intArr.pop_back(); intArr.push_back(234); - + intArr.push_back(345); //intArr.push_back(567); //auto itr = std::find(intArr.begin(), intArr.end(), 234); - //intArr.erase(itr); + //intArr.erase(itr); for (auto itr = intArr.begin(); itr != intArr.end(); ) { @@ -5639,7 +5632,7 @@ void BfCompiler::PopulateReified() while (true) { BP_ZONE("Compile_PopulateTypes"); - + int startTypeInitCount = mTypeInitCount; bool didWork = false; @@ -5675,7 +5668,7 @@ void BfCompiler::PopulateReified() } auto typeInst = type->ToTypeInstance(); - + if ((typeInst != NULL) && (typeInst->IsGenericTypeInstance()) && (!typeInst->IsUnspecializedType()) && (!typeInst->IsDelegateFromTypeRef()) && (!typeInst->IsFunctionFromTypeRef()) && (!typeInst->IsTuple())) { @@ -5753,7 +5746,7 @@ void BfCompiler::PopulateReified() { auto& checkMethodInstanceGroup = typeInst->mMethodInstanceGroups[checkMethodDef->mIdx]; auto checkMethodInstance = checkMethodInstanceGroup.mDefault; - if (checkMethodInstance != NULL) + if (checkMethodInstance != NULL) { if ((checkMethodDef->mIsExtern) && (checkMethodInstance->IsReifiedAndImplemented())) forceMethod = true; @@ -5807,11 +5800,11 @@ void BfCompiler::PopulateReified() } } } - + // Only check virtual stuff if we have been instantiated if ((typeInst->HasBeenInstantiated()) && (!mCanceling)) { - // If we have any virtual methods overrides that are unreified but the declaring virtual method is reified then we also need to reify + // If we have any virtual methods overrides that are unreified but the declaring virtual method is reified then we also need to reify for (int virtIdx = 0; virtIdx < typeInst->mVirtualMethodTable.mSize; virtIdx++) { auto& vEntry = typeInst->mVirtualMethodTable[virtIdx]; @@ -5853,7 +5846,7 @@ void BfCompiler::PopulateReified() } } } - + methodDef = methodDef->mNextWithSameName; } } @@ -5904,7 +5897,7 @@ void BfCompiler::PopulateReified() if (typeInst->IsObject()) { - // If the implementor is an object then this can be dynamically dispatched + // If the implementor is an object then this can be dynamically dispatched } else { @@ -5947,7 +5940,7 @@ void BfCompiler::PopulateReified() if ((depMethod->mIsReified) && (depMethod->mMethodInstanceGroup->IsImplemented())) { auto methodDef = typeInst->mTypeDef->mMethods[reifyDep.mMethodIdx]; - typeInst->mModule->GetMethodInstance(typeInst, methodDef, BfTypeVector()); + typeInst->mModule->GetMethodInstance(typeInst, methodDef, BfTypeVector()); } } } @@ -6044,12 +6037,12 @@ void BfCompiler::HotCommit() mHotState->mCommittedHotCompileIdx = mOptions.mHotCompileIdx; for (auto type : mContext->mResolvedTypes) - { + { auto typeInst = type->ToTypeInstance(); if (typeInst == NULL) continue; if (typeInst->mHotTypeData == NULL) - continue; + continue; for (int typeIdx = (int)typeInst->mHotTypeData->mTypeVersions.size() - 1; typeIdx >= 0; typeIdx--) { @@ -6063,9 +6056,9 @@ void BfCompiler::HotCommit() if ((hotVersionHead != hotVersion) && (hotVersionHead->mDataHash == hotVersion->mDataHash)) { // When we have a slot failure, the data hash will match but we actually do need to use the new mInterfaceMapping entries - // So we copy them over to the + // So we copy them over to the hotVersionHead->mInterfaceMapping = hotVersion->mInterfaceMapping; - } + } } } } @@ -6074,11 +6067,11 @@ void BfCompiler::HotCommit() void BfCompiler::HotResolve_Start(HotResolveFlags flags) { BfLogSysM("BfCompiler::HotResolve_Start\n"); - + delete mHotResolveData; mHotResolveData = new HotResolveData(); mHotResolveData->mFlags = flags; - + mHotResolveData->mHotTypeIdFlags.Resize(mCurTypeId); mHotResolveData->mReasons.Resize(mCurTypeId); @@ -6102,7 +6095,7 @@ bool BfCompiler::HotResolve_AddReachableMethod(BfHotMethod* hotMethod, HotTypeFl HotResolve_PopulateMethodNameMap(); String* namePtr = NULL; if (mHotData->mMethodNameMap.TryGetValue(hotMethod, &namePtr)) - { + { } #endif @@ -6112,7 +6105,7 @@ bool BfCompiler::HotResolve_AddReachableMethod(BfHotMethod* hotMethod, HotTypeFl hotMethod->mRefCount++; } else - { + { hotReachableData->mTypeFlags = (HotTypeFlags)(hotReachableData->mTypeFlags | flags); if ((!devirtualized) && (!hotReachableData->mHadNonDevirtualizedCall)) { @@ -6126,14 +6119,14 @@ bool BfCompiler::HotResolve_AddReachableMethod(BfHotMethod* hotMethod, HotTypeFl hotReachableData->mTypeFlags = (HotTypeFlags)(hotReachableData->mTypeFlags | flags); if (!devirtualized) hotReachableData->mHadNonDevirtualizedCall = true; - + for (auto hotDepData : hotMethod->mReferences) { if (hotDepData->mDataKind == BfHotDepDataKind_ThisType) { auto hotThisType = (BfHotThisType*)hotDepData; auto hotTypeVersion = hotThisType->mTypeVersion; - + HotTypeFlags hotTypeFlags = mHotResolveData->mHotTypeIdFlags[hotTypeVersion->mTypeId]; bool isAllocated = (hotTypeFlags & (HotTypeFlag_Heap | HotTypeFlag_CanAllocate)) != 0; if (!isAllocated) @@ -6157,11 +6150,11 @@ bool BfCompiler::HotResolve_AddReachableMethod(BfHotMethod* hotMethod, HotTypeFl auto hotAllocation = (BfHotAllocation*)hotDepData; auto hotTypeVersion = hotAllocation->mTypeVersion; HotResolve_ReportType(hotTypeVersion, flags, hotMethod); - HotResolve_ReportType(hotTypeVersion, HotTypeFlag_CanAllocate, hotMethod); + HotResolve_ReportType(hotTypeVersion, HotTypeFlag_CanAllocate, hotMethod); } else if (hotDepData->mDataKind == BfHotDepDataKind_TypeVersion) { - auto hotTypeVersion = (BfHotTypeVersion*)hotDepData; + auto hotTypeVersion = (BfHotTypeVersion*)hotDepData; HotResolve_ReportType(hotTypeVersion, flags, hotMethod); } else if (hotDepData->mDataKind == BfHotDepDataKind_Method) @@ -6173,7 +6166,7 @@ bool BfCompiler::HotResolve_AddReachableMethod(BfHotMethod* hotMethod, HotTypeFl { auto checkMethod = (BfHotDevirtualizedMethod*)hotDepData; HotResolve_AddReachableMethod(checkMethod->mMethod, flags, true); - } + } else if (hotDepData->mDataKind == BfHotDepDataKind_DupMethod) { auto checkMethod = (BfHotDupMethod*)hotDepData; @@ -6231,13 +6224,13 @@ void BfCompiler::HotResolve_AddActiveMethod(BfHotMethod* hotMethod) if ((hotMethod->mFlags & BfHotDepDataFlag_HasDup) != 0) { for (auto depData : hotMethod->mReferences) - { + { if (depData->mDataKind != BfHotDepDataKind_DupMethod) continue; auto hotDupMethod = (BfHotDupMethod*)depData; HotResolve_AddActiveMethod(hotDupMethod->mMethod); } - } + } } void BfCompiler::HotResolve_AddActiveMethod(const StringImpl& methodName) @@ -6246,7 +6239,7 @@ void BfCompiler::HotResolve_AddActiveMethod(const StringImpl& methodName) StringT<512> mangledName; int hotCompileIdx = 0; - + int tabIdx = (int)methodName.IndexOf('\t'); if (tabIdx != -1) { @@ -6255,8 +6248,8 @@ void BfCompiler::HotResolve_AddActiveMethod(const StringImpl& methodName) } else mangledName = methodName; - - bool isDelegateRef = false; + + bool isDelegateRef = false; BfHotMethod** hotMethodPtr; if (!mHotData->mMethodMap.TryGetValue(mangledName, &hotMethodPtr)) { @@ -6287,13 +6280,13 @@ void BfCompiler::HotResolve_AddDelegateMethod(const StringImpl& methodName) BfLogSysM("Hot method not found\n"); return; } - + BfHotMethod* hotMethod = *hotMethodPtr; HotResolve_AddReachableMethod(hotMethod, HotTypeFlag_Delegate, true); } void BfCompiler::HotResolve_ReportType(BfHotTypeVersion* hotTypeVersion, HotTypeFlags flags, BfHotDepData* reason) -{ +{ auto& flagsRef = mHotResolveData->mHotTypeFlags[hotTypeVersion]; if (flagsRef == (flagsRef | flags)) return; @@ -6301,7 +6294,7 @@ void BfCompiler::HotResolve_ReportType(BfHotTypeVersion* hotTypeVersion, HotType bool applyFlags = true; if ((flags & (BfCompiler::HotTypeFlag_ActiveFunction | BfCompiler::HotTypeFlag_Delegate | BfCompiler::HotTypeFlag_FuncPtr)) != 0) - { + { applyFlags = (hotTypeVersion->mCommittedHotCompileIdx != -1) && (mHotState->mPendingDataChanges.Contains(hotTypeVersion->mTypeId)); if ((!applyFlags) && (hotTypeVersion->mCommittedHotCompileIdx != -1)) @@ -6314,21 +6307,21 @@ void BfCompiler::HotResolve_ReportType(BfHotTypeVersion* hotTypeVersion, HotType } } if (applyFlags) - { + { auto& flagsIdRef = mHotResolveData->mHotTypeIdFlags[hotTypeVersion->mTypeId]; - flagsIdRef = (HotTypeFlags)(flags | flagsIdRef); + flagsIdRef = (HotTypeFlags)(flags | flagsIdRef); } - + BfLogSysM("HotResolve_ReportType %p %s Flags:%X DeclHotIdx:%d\n", hotTypeVersion, mContext->TypeIdToString(hotTypeVersion->mTypeId).c_str(), flags, hotTypeVersion->mDeclHotCompileIdx); - + for (auto member : hotTypeVersion->mMembers) { HotResolve_ReportType(member, flags, reason); - } + } } void BfCompiler::HotResolve_ReportType(int typeId, HotTypeFlags flags) -{ +{ if ((uint)typeId >= mHotResolveData->mHotTypeIdFlags.size()) { BF_DBG_FATAL("Invalid typeId"); @@ -6345,7 +6338,7 @@ void BfCompiler::HotResolve_ReportType(int typeId, HotTypeFlags flags) BF_ASSERT(hotTypeVersion != NULL); if (hotTypeVersion != NULL) HotResolve_ReportType(hotTypeVersion, flags, NULL); - } + } mHotResolveData->mHotTypeIdFlags[typeId] = (HotTypeFlags)(flags | mHotResolveData->mHotTypeIdFlags[typeId]); } @@ -6354,7 +6347,7 @@ void BfCompiler::HotResolve_PopulateMethodNameMap() { if (!mHotData->mMethodNameMap.IsEmpty()) return; - + for (auto& kv : mHotData->mMethodMap) { auto hotMethod = kv.mValue; @@ -6363,7 +6356,7 @@ void BfCompiler::HotResolve_PopulateMethodNameMap() mHotData->mMethodNameMap[hotMethod] = &kv.mKey; hotMethod = hotMethod->mPrevVersion; } - } + } } String BfCompiler::HotResolve_Finish() @@ -6386,7 +6379,7 @@ String BfCompiler::HotResolve_Finish() { BF_ASSERT(mHotState->mPendingDataChanges.IsEmpty() && mHotState->mPendingFailedSlottings.IsEmpty()); } - + if ((mHotResolveData->mFlags & HotResolveFlag_HadDataChanges) != 0) { auto _AddUsedType = [&](BfTypeDef* typeDef) @@ -6394,7 +6387,7 @@ String BfCompiler::HotResolve_Finish() auto type = mContext->mUnreifiedModule->ResolveTypeDef(mReflectTypeInstanceTypeDef); if (type != NULL) HotResolve_ReportType(type->mTypeId, BfCompiler::HotTypeFlag_Heap); - }; + }; // We have some types that can be allocated in a read-only section- pretend they are on the heap _AddUsedType(mReflectTypeInstanceTypeDef); @@ -6403,9 +6396,9 @@ String BfCompiler::HotResolve_Finish() // Find any virtual method overrides that may have been called. // These can cause new reachable virtual methods to be called, which may take more than one iteration to fully resolve for (int methodPass = 0; true; methodPass++) - { + { bool didWork = false; - + for (auto hotMethod : mHotResolveData->mDeferredThisCheckMethods) { if (HotResolve_AddReachableMethod(hotMethod, BfCompiler::HotTypeFlag_ActiveFunction, true, true)) @@ -6417,17 +6410,17 @@ String BfCompiler::HotResolve_Finish() { String& methodName = kv.mKey; auto hotMethod = kv.mValue; - + bool doCall = false; - bool forceAdd = false; - + bool forceAdd = false; + if (mHotResolveData->mReachableMethods.ContainsKey(hotMethod)) continue; for (auto ref : hotMethod->mReferences) { - if (ref->mDataKind == BfHotDepDataKind_ThisType) - continue; + if (ref->mDataKind == BfHotDepDataKind_ThisType) + continue; if (ref->mDataKind != BfHotDepDataKind_VirtualDecl) break; @@ -6439,7 +6432,7 @@ String BfCompiler::HotResolve_Finish() HotResolve_PopulateMethodNameMap(); String* namePtr = NULL; if (mHotData->mMethodNameMap.TryGetValue(hotVirtualDecl->mMethod, &namePtr)) - { + { } #endif @@ -6450,7 +6443,7 @@ String BfCompiler::HotResolve_Finish() } } } - + if (!doCall) { if ((hotMethod->mFlags & BfHotDepDataFlag_AlwaysCalled) != 0) @@ -6481,7 +6474,7 @@ String BfCompiler::HotResolve_Finish() Dictionary methodNameMap; - if ((flags > BfCompiler::HotTypeFlag_UserNotUsed) && + if ((flags > BfCompiler::HotTypeFlag_UserNotUsed) && ((mHotState->mPendingDataChanges.Contains(typeId)) || (mHotState->mPendingFailedSlottings.Contains(typeId)))) { bool isBadTypeUsed = false; @@ -6491,8 +6484,8 @@ String BfCompiler::HotResolve_Finish() { // If we detect an old version being used, it's only an issue if this type can actually be allocated if ((flags & HotTypeFlag_CanAllocate) != 0) - { - isBadTypeUsed = true; + { + isBadTypeUsed = true; } } @@ -6517,7 +6510,7 @@ String BfCompiler::HotResolve_Finish() errorCount++; if (errorCount >= 1000) - { + { result += "\n (more errors)..."; break; } @@ -6528,7 +6521,7 @@ String BfCompiler::HotResolve_Finish() result += mContext->TypeIdToString(typeId); result += "'"; if ((flags & BfCompiler::HotTypeFlag_Heap) != 0) - result += " allocated on the heap"; + result += " allocated on the heap"; else if ((flags & BfCompiler::HotTypeFlag_ActiveFunction) != 0) { if (reasonIsActiveMethod) @@ -6572,14 +6565,14 @@ String BfCompiler::HotResolve_Finish() typeInstance->mHotTypeData->mPendingDataChange = false; typeInstance->mHotTypeData->mHadDataChange = true; typeInstance->mHotTypeData->mVTableOrigLength = -1; - typeInstance->mHotTypeData->mOrigInterfaceMethodsLength = -1; + typeInstance->mHotTypeData->mOrigInterfaceMethodsLength = -1; BfLogSysM("Pending data change applied to type %p\n", typeInstance); } mHotState->mPendingDataChanges.Clear(); - mHotState->mPendingFailedSlottings.Clear(); - } + mHotState->mPendingFailedSlottings.Clear(); + } } ClearOldHotData(); @@ -6616,7 +6609,7 @@ String BfCompiler::HotResolve_Finish() delete mHotResolveData; mHotResolveData = NULL; - + return result; } @@ -6627,17 +6620,17 @@ void BfCompiler::ClearOldHotData() // TODO: Get rid of old hot data during hot compiles, too // if (IsHotCompile()) -// return; +// return; BP_ZONE("BfCompiler::ClearOldHotData"); - + bool isHotCompile = IsHotCompile(); auto itr = mHotData->mMethodMap.begin(); while (itr != mHotData->mMethodMap.end()) { String& methodName = itr->mKey; - auto hotMethod = itr->mValue; + auto hotMethod = itr->mValue; bool doDelete = false; @@ -6650,7 +6643,7 @@ void BfCompiler::ClearOldHotData() BF_ASSERT((mHotResolveData != NULL) && (mHotResolveData->mActiveMethods.Contains(prevMethod))); break; } - + hotMethod->mPrevVersion = prevMethod->mPrevVersion; prevMethod->mPrevVersion = NULL; prevMethod->Deref(); @@ -6658,7 +6651,7 @@ void BfCompiler::ClearOldHotData() BF_ASSERT(hotMethod->mRefCount >= 1); if (hotMethod->mPrevVersion == NULL) - { + { if (hotMethod->mRefCount <= 1) { doDelete = true; @@ -6671,8 +6664,8 @@ void BfCompiler::ClearOldHotData() bool doRemove = doDelete; if ((hotMethod->mFlags & BfHotDepDataFlag_HasDup) != 0) - { - bool hasDupMethod = false; + { + bool hasDupMethod = false; for (int idx = 0; idx < (int)hotMethod->mReferences.size(); idx++) { auto depData = hotMethod->mReferences[idx]; @@ -6681,13 +6674,13 @@ void BfCompiler::ClearOldHotData() auto dupMethod = (BfHotDupMethod*)depData; if (doDelete) { - doRemove = false; + doRemove = false; dupMethod->mMethod->mRefCount++; itr->mValue = dupMethod->mMethod; } else { - if ((dupMethod->mMethod->mRefCount == 1) || + if ((dupMethod->mMethod->mRefCount == 1) || ((!IsHotCompile()) && (dupMethod->mMethod->mFlags & BfHotDepDataFlag_IsBound) == 0)) { dupMethod->Deref(); @@ -6700,14 +6693,14 @@ void BfCompiler::ClearOldHotData() } if (doDelete) - { + { BfLogSysM("Deleting hot method %p %s\n", hotMethod, methodName.c_str()); //BF_ASSERT(hotMethod->mRefCount == 1); hotMethod->Clear(); - hotMethod->Deref(); + hotMethod->Deref(); if (doRemove) itr = mHotData->mMethodMap.Remove(itr); - } + } else ++itr; } @@ -6724,7 +6717,7 @@ void BfCompiler::ClearOldHotData() bool foundCommittedVersion = false; - auto latestVersionHead = typeInst->mHotTypeData->GetLatestVersionHead(); + auto latestVersionHead = typeInst->mHotTypeData->GetLatestVersionHead(); for (int typeIdx = (int)typeInst->mHotTypeData->mTypeVersions.size() - 1; typeIdx >= 0; typeIdx--) { auto hotVersion = typeInst->mHotTypeData->mTypeVersions[typeIdx]; @@ -6796,7 +6789,7 @@ void BfCompiler::CompileReified() deferTypeDefs.Add(typeDef); continue; } - + scratchModule->ResolveTypeDef(typeDef, BfPopulateType_Full); } @@ -6815,8 +6808,8 @@ void BfCompiler::CompileReified() mContext->mUnreifiedModule->PopulateType(typeInst, BfPopulateType_Interfaces_Direct); if (typeInst->mCustomAttributes == NULL) continue; - - bool alwaysInclude = false; + + bool alwaysInclude = false; for (auto& customAttribute : typeInst->mCustomAttributes->mAttributes) { if (customAttribute.mType->mAttributeData != NULL) @@ -6826,18 +6819,18 @@ void BfCompiler::CompileReified() if ((customAttribute.mType->mAttributeData->mFlags & BfAttributeFlag_AlwaysIncludeTarget) != 0) alwaysInclude = true; } - } + } if (alwaysInclude) mContext->mScratchModule->PopulateType(typeInst, BfPopulateType_Full); } - - PopulateReified(); + + PopulateReified(); } bool BfCompiler::DoCompile(const StringImpl& outputDirectory) { BP_ZONE("BfCompiler::Compile"); - + if (mSystem->mTypeDefs.mCount == 0) { // No-source bailout @@ -6849,7 +6842,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) mPassInstance->Fail(mOptions.mErrorString); return false; } - + { String hotSwapErrors; String toolsetErrors; @@ -6863,13 +6856,13 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) { if (!hotSwapErrors.IsEmpty()) hotSwapErrors += ", "; - hotSwapErrors += project->mName; + hotSwapErrors += project->mName; } if (mOptions.mToolsetType != BfToolsetType_LLVM) { if (!toolsetErrors.IsEmpty()) toolsetErrors += ", "; - toolsetErrors += project->mName; + toolsetErrors += project->mName; } } } @@ -6904,8 +6897,8 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) mRevision++; mHasComptimeRebuilds = false; int revision = mRevision; - BfLogSysM("Compile Start. Revision: %d. HasParser:%d AutoComplete:%d\n", revision, - (mResolvePassData != NULL) && (!mResolvePassData->mParsers.IsEmpty()), + BfLogSysM("Compile Start. Revision: %d. HasParser:%d AutoComplete:%d\n", revision, + (mResolvePassData != NULL) && (!mResolvePassData->mParsers.IsEmpty()), (mResolvePassData != NULL) && (mResolvePassData->mAutoComplete != NULL)); if (mOptions.mCompileOnDemandKind == BfCompileOnDemandKind_AlwaysInclude) @@ -6964,8 +6957,8 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) // This will get rid of any old method data so we don't have any more mPrevVersions ClearOldHotData(); } - - int prevUnfinishedModules = mStats.mModulesStarted - mStats.mModulesFinished; + + int prevUnfinishedModules = mStats.mModulesStarted - mStats.mModulesFinished; mCompletionPct = 0; memset(&mStats, 0, sizeof(mStats)); mCodeGen.ClearResults(); @@ -6979,7 +6972,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) if (module->mAddedToCount) { if (module->mIsReified) - mStats.mReifiedModuleCount++; + mStats.mReifiedModuleCount++; } }; @@ -6992,11 +6985,10 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) } } } - if (IsHotCompile()) { - mContext->EnsureHotMangledVirtualMethodNames(); + mContext->EnsureHotMangledVirtualMethodNames(); } mOutputDirectory = outputDirectory; @@ -7014,17 +7006,17 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) } #endif - BfTypeDef* typeDef; + BfTypeDef* typeDef; - BfLogSysM("UpdateRevisedTypes Revision %d. ResolvePass:%d CursorIdx:%d\n", mRevision, mIsResolveOnly, + BfLogSysM("UpdateRevisedTypes Revision %d. ResolvePass:%d CursorIdx:%d\n", mRevision, mIsResolveOnly, ((mResolvePassData == NULL) || (mResolvePassData->mParsers.IsEmpty())) ? - 1 : mResolvePassData->mParsers[0]->mCursorIdx); - + mCompileState = CompileState_Normal; - UpdateRevisedTypes(); + UpdateRevisedTypes(); // We need to defer processing the graveyard until here, because mLookupResults contain atom references so we need to make sure // those aren't deleted until we can properly handle it. mSystem->ProcessAtomGraveyard(); - + BpEnter("Compile_Start"); mHasRequiredTypes = true; @@ -7033,18 +7025,17 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) auto _GetRequiredType = [&](const StringImpl& typeName, int genericArgCount = 0) { - auto typeDef = mSystem->FindTypeDef(typeName, genericArgCount); + auto typeDef = mSystem->FindTypeDef(typeName, genericArgCount); if (typeDef == NULL) { mPassInstance->Fail(StrFormat("Unable to find system type: %s", typeName.c_str())); mHasRequiredTypes = false; - } + } return typeDef; }; - _GetRequiredType("System.Void"); - _GetRequiredType("System.Boolean"); + _GetRequiredType("System.Boolean"); _GetRequiredType("System.Int"); _GetRequiredType("System.Int8"); _GetRequiredType("System.Int16"); @@ -7054,7 +7045,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) _GetRequiredType("System.UInt8"); _GetRequiredType("System.UInt16"); _GetRequiredType("System.UInt32"); - _GetRequiredType("System.UInt64"); + _GetRequiredType("System.UInt64"); _GetRequiredType("System.Char8"); _GetRequiredType("System.Char16"); mChar32TypeDef = _GetRequiredType("System.Char32"); @@ -7062,7 +7053,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) mDoubleTypeDef = _GetRequiredType("System.Double"); mMathTypeDef = _GetRequiredType("System.Math"); - mBfObjectTypeDef = _GetRequiredType("System.Object"); + mBfObjectTypeDef = _GetRequiredType("System.Object"); mArray1TypeDef = _GetRequiredType("System.Array1", 1); mArray2TypeDef = _GetRequiredType("System.Array2", 1); mArray3TypeDef = _GetRequiredType("System.Array3", 1); @@ -7073,7 +7064,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) mIndexTypeDef = _GetRequiredType("System.Index"); mIndexRangeTypeDef = _GetRequiredType("System.IndexRange"); mAttributeTypeDef = _GetRequiredType("System.Attribute"); - mAttributeUsageAttributeTypeDef = _GetRequiredType("System.AttributeUsageAttribute"); + mAttributeUsageAttributeTypeDef = _GetRequiredType("System.AttributeUsageAttribute"); mClassVDataTypeDef = _GetRequiredType("System.ClassVData"); mCLinkAttributeTypeDef = _GetRequiredType("System.CLinkAttribute"); mImportAttributeTypeDef = _GetRequiredType("System.ImportAttribute"); @@ -7097,11 +7088,11 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) mNoExtensionAttributeTypeDef = _GetRequiredType("System.NoExtensionAttribute"); mCheckedAttributeTypeDef = _GetRequiredType("System.CheckedAttribute"); mUncheckedAttributeTypeDef = _GetRequiredType("System.UncheckedAttribute"); - mResultTypeDef = _GetRequiredType("System.Result", 1); - mGCTypeDef = _GetRequiredType("System.GC"); + mResultTypeDef = _GetRequiredType("System.Result", 1); + mGCTypeDef = _GetRequiredType("System.GC"); mGenericIEnumerableTypeDef = _GetRequiredType("System.Collections.IEnumerable", 1); mGenericIEnumeratorTypeDef = _GetRequiredType("System.Collections.IEnumerator", 1); - mGenericIRefEnumeratorTypeDef = _GetRequiredType("System.Collections.IRefEnumerator", 1); + mGenericIRefEnumeratorTypeDef = _GetRequiredType("System.Collections.IRefEnumerator", 1); mInlineAttributeTypeDef = _GetRequiredType("System.InlineAttribute"); mThreadTypeDef = _GetRequiredType("System.Threading.Thread"); mInternalTypeDef = _GetRequiredType("System.Internal"); @@ -7114,7 +7105,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) mIPrintableTypeDef = _GetRequiredType("System.IPrintable"); mIHashableTypeDef = _GetRequiredType("System.IHashable"); mIComptimeTypeApply = _GetRequiredType("System.IComptimeTypeApply"); - mIComptimeMethodApply = _GetRequiredType("System.IComptimeMethodApply"); + mIComptimeMethodApply = _GetRequiredType("System.IComptimeMethodApply"); mIOnTypeInitTypeDef = _GetRequiredType("System.IOnTypeInit"); mIOnTypeDoneTypeDef = _GetRequiredType("System.IOnTypeDone"); mIOnFieldInitTypeDef = _GetRequiredType("System.IOnFieldInit"); @@ -7144,7 +7135,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) mReflectUnspecializedGenericType = _GetRequiredType("System.Reflection.UnspecializedGenericType"); mReflectFieldInfoTypeDef = _GetRequiredType("System.Reflection.FieldInfo"); mReflectMethodInfoTypeDef = _GetRequiredType("System.Reflection.MethodInfo"); - mSizedArrayTypeDef = _GetRequiredType("System.SizedArray", 2); + mSizedArrayTypeDef = _GetRequiredType("System.SizedArray", 2); mStaticInitAfterAttributeTypeDef = _GetRequiredType("System.StaticInitAfterAttribute"); mStaticInitPriorityAttributeTypeDef = _GetRequiredType("System.StaticInitPriorityAttribute"); mStringTypeDef = _GetRequiredType("System.String"); @@ -7152,7 +7143,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) mTestAttributeTypeDef = _GetRequiredType("System.TestAttribute"); mThreadStaticAttributeTypeDef = _GetRequiredType("System.ThreadStaticAttribute"); mTypeTypeDef = _GetRequiredType("System.Type"); - mUnboundAttributeTypeDef = _GetRequiredType("System.UnboundAttribute"); + mUnboundAttributeTypeDef = _GetRequiredType("System.UnboundAttribute"); mValueTypeTypeDef = _GetRequiredType("System.ValueType"); mObsoleteAttributeTypeDef = _GetRequiredType("System.ObsoleteAttribute"); mErrorAttributeTypeDef = _GetRequiredType("System.ErrorAttribute"); @@ -7173,13 +7164,13 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) // Force rebuilding BfLogSysM("Compile missing required types\n"); mOptions.mForceRebuildIdx++; - } - + } + mSystem->CheckLockYield(); if (mBfObjectTypeDef != NULL) mContext->mScratchModule->ResolveTypeDef(mBfObjectTypeDef); - VisitSourceExteriorNodes(); + VisitSourceExteriorNodes(); if (!mIsResolveOnly) { @@ -7234,7 +7225,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) mVDataModules.push_back(module); foundVDataModuleSet.Add(module); - } + } } // Remove old vdata @@ -7246,18 +7237,18 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) delete module; mVDataModules.erase(mVDataModules.begin() + moduleIdx); moduleIdx--; - + mContext->mModules.Remove(module); } } } if (mIsResolveOnly) - VisitAutocompleteExteriorIdentifiers(); - + VisitAutocompleteExteriorIdentifiers(); + mStats.mTypesQueued = 0; mStats.mMethodsQueued = 0; - + mStats.mTypesQueued += (int)mContext->mPopulateTypeWorkList.size(); mStats.mMethodsQueued += (int)mContext->mMethodWorkList.size(); @@ -7296,7 +7287,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) bool didWork = false; UpdateDependencyMap(mOptions.mCompileOnDemandKind != BfCompileOnDemandKind_ResolveUnused, didWork); - + // If UpdateDependencyMap caused methods to be reified, then we need to run PopulateReified again- // because those methods may be virtual and we need to reify overrides (for example). // We use the DoWorkLoop result to determine if there were actually any changes from UpdateDependencyMap @@ -7311,7 +7302,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) BfLogSysM("DoCompile looping over CompileReified due to mHasReifiedQueuedRebuildTypes\n"); } - + // Handle purgatory (ie: old generic types) { bool didWork = ProcessPurgatory(true); @@ -7393,22 +7384,22 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) HashSet projectSet; for (auto type : mContext->mResolvedTypes) - { + { auto typeInstance = type->ToTypeInstance(); if (typeInstance != NULL) - { + { for (auto& methodInstanceGroup : typeInstance->mMethodInstanceGroups) { if (methodInstanceGroup.mDefault != NULL) { auto methodInstance = methodInstanceGroup.mDefault; - auto project = methodInstance->mMethodDef->mDeclaringType->mProject; + auto project = methodInstance->mMethodDef->mDeclaringType->mProject; if (project->mTargetType != BfTargetType_BeefTest) continue; if ((methodInstance->GetCustomAttributes() != NULL) && (methodInstance->GetCustomAttributes()->Contains(mTestAttributeTypeDef))) { - projectSet.Add(project); + projectSet.Add(project); } } } @@ -7433,9 +7424,9 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) if ((!mIsResolveOnly) && (!mCanceling)) { if ((!IsHotCompile()) || (mHotState->mHasNewInterfaceTypes)) - { + { int prevSlotCount = mMaxInterfaceSlots; - GenerateSlotNums(); + GenerateSlotNums(); if ((prevSlotCount != -1) && (prevSlotCount != mMaxInterfaceSlots)) { mInterfaceSlotCountChanged = true; @@ -7448,18 +7439,18 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) // Resolve unused types if ((mOptions.mCompileOnDemandKind == BfCompileOnDemandKind_ResolveUnused) && (!mCanceling)) { - // Finish off any outstanding modules so we can code generate in parallel with handling the unreified stuff + // Finish off any outstanding modules so we can code generate in parallel with handling the unreified stuff for (auto module : mContext->mModules) { if (!module->mIsSpecialModule) { if ((module->HasCompiledOutput()) && (module->mIsModuleMutable)) - { + { module->Finish(); } } - } - + } + DoWorkLoop(); BfLogSysM("Compile QueueUnused\n"); @@ -7475,7 +7466,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) bool queuedMoreMethods = false; int startTypeInitCount = mTypeInitCount; - + for (auto typeDef : mSystem->mTypeDefs) { mSystem->CheckLockYield(); @@ -7487,19 +7478,19 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) if (typeDef->mProject->mDisabled) continue; - + if (typeDef->mIsPartial) continue; if (typeDef->mTypeCode == BfTypeCode_Extension) continue; - + mContext->mUnreifiedModule->ResolveTypeDef(typeDef, BfPopulateType_Full); } Array typeWorkList; for (auto type : mContext->mResolvedTypes) - { + { auto module = type->GetModule(); if (module == NULL) @@ -7514,13 +7505,13 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) auto typeInst = type->ToTypeInstance(); if (typeInst == NULL) continue; - + if (typeInst->IsUnspecializedTypeVariation()) continue; if (!typeInst->IsSpecializedType()) - { - typeWorkList.Add(typeInst); + { + typeWorkList.Add(typeInst); } } @@ -7553,8 +7544,8 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) if ((!queuedMoreMethods) && (startTypeInitCount == mTypeInitCount)) break; - - DoWorkLoop(); + + DoWorkLoop(); } bool didWork = false; @@ -7568,19 +7559,19 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) { DoWorkLoop(); } - + ProcessPurgatory(false); // ProcessPurgatory MAY cause type rebuilds which we need to handle DoWorkLoop(); - + BfLogSysM("Checking mDepsMayHaveDeletedTypes for SanitizeDependencyMap\n"); if (mDepsMayHaveDeletedTypes) - SanitizeDependencyMap(); + SanitizeDependencyMap(); - // Old Mark used modules + // Old Mark used modules if (!mIsResolveOnly) - { + { // if ((!mPassInstance->HasFailed()) && (!mCanceling)) // { // if ((!IsHotCompile()) || (mHotState->mHasNewInterfaceTypes)) @@ -7595,8 +7586,8 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) { if (!mOptions.mAllowHotSwapping) { - GenerateDynCastData(); - mContext->ProcessWorkList(false, false); + GenerateDynCastData(); + mContext->ProcessWorkList(false, false); } mCompileState = BfCompiler::CompileState_VData; @@ -7613,11 +7604,11 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) // to still be the same pointer if it's erased and then put back if ((!IsHotCompile()) && (!mCanceling)) ClearUnusedStringPoolEntries(); - + mContext->ValidateDependencies(); - mContext->UpdateAfterDeletingTypes(); + mContext->UpdateAfterDeletingTypes(); } - + // We need to check the specialized errors before writing out modules -- // this call is responsible for deleting dead method specializations that contained errors, or for setting // the mHadBuildErrors on the module if there was a method specialization error that didn't die @@ -7625,12 +7616,12 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) mContext->Finish(); if ((!mIsResolveOnly) && (!IsHotCompile())) ClearOldHotData(); - + mPassInstance->TryFlushDeferredError(); BpLeave(); BpEnter("Compile_Finish"); - + //TODO:!! //mCanceling = true; @@ -7641,7 +7632,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) if (!mIsResolveOnly) { int idx = 0; - + BF_ASSERT(mContext->mMethodWorkList.IsEmpty()); //bfContext->mLockModules = true; @@ -7650,7 +7641,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) //bool clearModule = false; auto mainModule = mContext->mModules[moduleIdx]; BfModule* bfModule = mainModule; - if (bfModule->mIsReified) + if (bfModule->mIsReified) { auto itr = mainModule->mSpecializedMethodModules.begin(); while (true) @@ -7693,39 +7684,39 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) } } } - + mainModule->ClearModule(); } - //bfContext->mLockModules = false; + //bfContext->mLockModules = false; } else { bool isTargeted = (mResolvePassData != NULL) && (!mResolvePassData->mParsers.IsEmpty()); if (!isTargeted) - { + { for (auto bfModule : mContext->mModules) { if (bfModule->mIsModuleMutable) { - bfModule->Finish(); + bfModule->Finish(); bfModule->mRevision = std::max(bfModule->mRevision, bfModule->mRevision); bfModule->ClearModuleData(); } - } + } } } } /*if (!moduleListStr.empty()) mPassInstance->OutputLine(StrFormat("%d modules generated: %s", numModulesWritten, moduleListStr.c_str()));*/ - + //CompileLog("%d object files written: %s\n", numModulesWritten, moduleListStr.c_str()); - + //printf("Compile done, waiting for finish\n"); - + while (true) - { + { if (mCanceling) mCodeGen.Cancel(); bool isDone = mCodeGen.Finish(); @@ -7737,8 +7728,8 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) mCeMachine->CompileDone(); - // This has to happen after codegen because we may delete modules that are referenced in codegen - mContext->Cleanup(); + // This has to happen after codegen because we may delete modules that are referenced in codegen + mContext->Cleanup(); if ((!IsHotCompile()) && (!mIsResolveOnly) && (!mCanceling)) { // Only save 'saved type data' for temporarily-deleted types like on-demand types. @@ -7788,15 +7779,15 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) } libManager->mErrors.Clear(); } -#endif - +#endif + int numObjFilesWritten = 0; for (auto& fileEntry : mCodeGen.mCodeGenFiles) { if (!fileEntry.mWasCached) numObjFilesWritten++; } - mPassInstance->OutputLine(StrFormat(":low %d module%s built, %d object file%s generated", + mPassInstance->OutputLine(StrFormat(":low %d module%s built, %d object file%s generated", numModulesWritten, (numModulesWritten != 1) ? "s" : "", numObjFilesWritten, (numObjFilesWritten != 1) ? "s" : "")); @@ -7804,8 +7795,8 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) { mPassInstance->OutputLine(StrFormat(":med Comptime execution time: %0.2fs", mCeMachine->mRevisionExecuteTime / 1000.0f)); } - - BpLeave(); + + BpLeave(); mPassInstance->WriteErrorSummary(); if ((mCanceling) && (!mIsResolveOnly)) @@ -7815,19 +7806,19 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) CompileLog("Compile canceled\n"); } - BfLogSysM("Compile Done. Revision:%d TypesPopulated:%d MethodsDeclared:%d MethodsProcessed:%d Canceled? %d\n", revision, mStats.mTypesPopulated, mStats.mMethodDeclarations, mStats.mMethodsProcessed, mCanceling); - + BfLogSysM("Compile Done. Revision:%d TypesPopulated:%d MethodsDeclared:%d MethodsProcessed:%d Canceled? %d\n", revision, mStats.mTypesPopulated, mStats.mMethodDeclarations, mStats.mMethodsProcessed, mCanceling); + UpdateCompletion(); if ((!mIsResolveOnly) && (!mPassInstance->HasFailed()) && (!mCanceling)) { //BF_ASSERT(mCompletionPct >= 0.99999f); } - + if (mCompileLogFP != NULL) { fclose(mCompileLogFP); mCompileLogFP = NULL; - } + } UpdateCompletion(); mStats.mTotalTypes = mContext->mResolvedTypes.GetCount(); @@ -7845,7 +7836,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) for (auto& fileEntry : mCodeGen.mCodeGenFiles) { if (fileEntry.mWasCached) - continue; + continue; mHotState->mQueuedOutFiles.Add(fileEntry); } @@ -7855,7 +7846,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) mHotState->mNewlySlottedTypeIds.Clear(); mHotState->mSlotDefineTypeIds.Clear(); } - } + } mCompileState = BfCompiler::CompileState_None; @@ -7879,7 +7870,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) if (didCancel) mLastHadComptimeRebuilds = mHasComptimeRebuilds || mLastHadComptimeRebuilds; else - mLastHadComptimeRebuilds = mHasComptimeRebuilds; + mLastHadComptimeRebuilds = mHasComptimeRebuilds; return !didCancel && !mHasQueuedTypeRebuilds; } @@ -7896,7 +7887,7 @@ bool BfCompiler::Compile(const StringImpl& outputDirectory) BfLogSysM("Interface slot count increased. Rebuilding relevant modules.\n"); mPassInstance->OutputLine("Interface slot count increased. Rebuilding relevant modules."); // Recompile with the increased slot count - success = DoCompile(outputDirectory); + success = DoCompile(outputDirectory); BF_ASSERT(!mInterfaceSlotCountChanged); return success; } @@ -7919,7 +7910,7 @@ void BfCompiler::Cancel() mHadCancel = true; if (mCeMachine != NULL) { - AutoCrit autoCrit(mCeMachine->mCritSect); + AutoCrit autoCrit(mCeMachine->mCritSect); mCeMachine->mSpecialCheck = true; mFastFinish = true; } @@ -7941,12 +7932,12 @@ void BfCompiler::RequestFastFinish() void BfCompiler::CompileLog(const char* fmt ...) { #ifdef WANT_COMPILE_LOG - if (mCompileLogFP == NULL) + if (mCompileLogFP == NULL) return; //static int lineNum = 0; //lineNum++; - + va_list argList; va_start(argList, fmt); String aResult = vformat(fmt, argList); @@ -7954,7 +7945,7 @@ void BfCompiler::CompileLog(const char* fmt ...) //aResult = StrFormat("%d ", lineNum) + aResult; - fwrite(aResult.c_str(), 1, aResult.length(), mCompileLogFP); + fwrite(aResult.c_str(), 1, aResult.length(), mCompileLogFP); #endif } @@ -7973,23 +7964,22 @@ void BfCompiler::ReportMemory(MemReporter* memReporter) type->ReportMemory(memReporter); } - for (auto module : mContext->mModules) { AutoMemReporter autoMemReporter(memReporter, "Modules"); module->ReportMemory(memReporter); - } + } { AutoMemReporter autoMemReporter(memReporter, "ScratchModule"); mContext->mScratchModule->ReportMemory(memReporter); - } - + } + for (auto vdataModule : mVDataModules) { AutoMemReporter autoMemReporter(memReporter, "VDataModules"); vdataModule->ReportMemory(memReporter); - } + } if (mHotData != NULL) { @@ -8016,18 +8006,18 @@ void BfCompiler::ReportMemory(MemReporter* memReporter) { memReporter->AddStr(kv.mKey, false); } - } + } } ////////////////////////////////////////////////////////////////////////// void BfCompiler::GenerateAutocompleteInfo() -{ - BP_ZONE("BfCompiler::GetAutocompleteInfo"); - +{ + BP_ZONE("BfCompiler::GetAutocompleteInfo"); + String& autoCompleteResultString = *gTLStrReturn.Get(); autoCompleteResultString.Clear(); - + auto bfModule = mResolvePassData->mAutoComplete->mModule; if (bfModule != NULL) { @@ -8045,7 +8035,7 @@ void BfCompiler::GenerateAutocompleteInfo() autoCompleteResultString += "uncertain\n"; if (autoComplete->mDefaultSelection.length() != 0) - autoCompleteResultString += StrFormat("select\t%s\n", autoComplete->mDefaultSelection.c_str()); + autoCompleteResultString += StrFormat("select\t%s\n", autoComplete->mDefaultSelection.c_str()); auto _EncodeTypeDef = [] (BfTypeDef* typeDef) { @@ -8058,7 +8048,7 @@ void BfCompiler::GenerateAutocompleteInfo() }; if (autoComplete->mResolveType == BfResolveType_GetSymbolInfo) - { + { if (autoComplete->mDefTypeGenericParamIdx != -1) { autoCompleteResultString += StrFormat("typeGenericParam\t%d\n", autoComplete->mDefTypeGenericParamIdx); @@ -8167,7 +8157,7 @@ void BfCompiler::GenerateAutocompleteInfo() int idx = 0; for (auto& methodEntry : methodMatchInfo->mInstanceList) - { + { String methodText; if (methodEntry.mPayloadEnumField != NULL) { @@ -8204,7 +8194,7 @@ void BfCompiler::GenerateAutocompleteInfo() { BfMethodInstance* methodInstance = NULL; if (methodEntry.mMethodDef->mIdx < 0) - { + { for (auto localMethod : mContext->mLocalMethodGraveyard) { if (localMethod->mMethodDef == methodEntry.mMethodDef) @@ -8212,12 +8202,12 @@ void BfCompiler::GenerateAutocompleteInfo() methodInstance = localMethod->mMethodInstanceGroup->mDefault; break; } - } + } } else methodInstance = bfModule->GetRawMethodInstanceAtIdx(methodEntry.mTypeInstance, methodEntry.mMethodDef->mIdx); auto curMethodInstance = methodInstance; - curMethodInstance = methodMatchInfo->mCurMethodInstance; + curMethodInstance = methodMatchInfo->mCurMethodInstance; SetAndRestoreValue prevTypeInstance(bfModule->mCurTypeInstance, methodMatchInfo->mCurTypeInstance); SetAndRestoreValue prevMethodInstance(bfModule->mCurMethodInstance, curMethodInstance); @@ -8277,7 +8267,7 @@ void BfCompiler::GenerateAutocompleteInfo() } methodText += ">"; } - + //TODO: Show default param values also methodText += "(\x1"; if (methodInstance->GetParamCount() == 0) @@ -8302,7 +8292,7 @@ void BfCompiler::GenerateAutocompleteInfo() { auto paramKind = methodInstance->GetParamKind(paramIdx); if ((paramKind == BfParamKind_ImplicitCapture) || (paramKind == BfParamKind_AppendIdx)) - continue; + continue; if (dispParamIdx > 0) methodText += ",\x1 "; @@ -8310,7 +8300,7 @@ void BfCompiler::GenerateAutocompleteInfo() if ((paramIdx == 0) && (methodInstance->mMethodDef->mMethodType == BfMethodType_Extension)) continue; - auto type = methodInstance->GetParamType(paramIdx); + auto type = methodInstance->GetParamType(paramIdx); BfExpression* paramInitializer = methodInstance->GetParamInitializer(paramIdx); if (paramInitializer != NULL) @@ -8413,7 +8403,7 @@ void BfCompiler::GenerateAutocompleteInfo() return lhs->mScore > rhs->mScore; }); - + String docString; for (auto entry : entries) { @@ -8460,7 +8450,7 @@ String BfCompiler::GetTypeDefList() Dictionary projectIds; for (auto typeDef : mSystem->mTypeDefs) - { + { if (typeDef->mProject != curProject) { curProject = typeDef->mProject; @@ -8479,7 +8469,7 @@ String BfCompiler::GetTypeDefList() result += str; } } - + if (((!typeDef->mIsPartial) || (typeDef->mIsCombinedPartial))) { if (typeDef->IsGlobalsContainer()) @@ -8507,7 +8497,7 @@ String BfCompiler::GetTypeDefList() } String BfCompiler::GetGeneratorString(BfTypeDef* typeDef, BfTypeInstance* typeInst, const StringImpl& generatorMethodName, const StringImpl* args) -{ +{ if (typeInst == NULL) { auto type = mContext->mUnreifiedModule->ResolveTypeDef(typeDef, BfPopulateType_BaseType); @@ -8550,7 +8540,7 @@ void BfCompiler::HandleGeneratorErrors(StringImpl& result) return; result.Clear(); - + for (auto& msg : mPassInstance->mOutStream) { String error = msg; @@ -8567,9 +8557,9 @@ String BfCompiler::GetGeneratorTypeDefList() BfProject* curProject = NULL; Dictionary projectIds; - - BfResolvePassData resolvePassData; - SetAndRestoreValue prevResolvePassData(mResolvePassData, &resolvePassData); + + BfResolvePassData resolvePassData; + SetAndRestoreValue prevResolvePassData(mResolvePassData, &resolvePassData); BfPassInstance passInstance(mSystem); SetAndRestoreValue prevPassInstance(mPassInstance, &passInstance); @@ -8592,7 +8582,7 @@ String BfCompiler::GetGeneratorTypeDefList() result += BfTypeUtils::TypeToString(typeDef, BfTypeNameFlag_InternalName); String nameString = GetGeneratorString(typeDef, typeInst, "GetName", NULL); if (!nameString.IsEmpty()) - result += "\t" + nameString; + result += "\t" + nameString; result += "\n"; } } @@ -8605,7 +8595,7 @@ String BfCompiler::GetGeneratorTypeDefList() String BfCompiler::GetGeneratorInitData(const StringImpl& typeName, const StringImpl& args) { - BfResolvePassData resolvePassData; + BfResolvePassData resolvePassData; SetAndRestoreValue prevResolvePassData(mResolvePassData, &resolvePassData); BfPassInstance passInstance(mSystem); SetAndRestoreValue prevPassInstance(mPassInstance, &passInstance); @@ -8615,7 +8605,7 @@ String BfCompiler::GetGeneratorInitData(const StringImpl& typeName, const String String result; for (auto typeDef : typeDefs) - { + { result += GetGeneratorString(typeDef, NULL, "InitUI", &args); if (!result.IsEmpty()) break; @@ -8638,7 +8628,7 @@ String BfCompiler::GetGeneratorGenData(const StringImpl& typeName, const StringI String result; for (auto typeDef : typeDefs) - { + { result += GetGeneratorString(typeDef, NULL, "Generate", &args); if (!result.IsEmpty()) break; @@ -8739,7 +8729,7 @@ public: } void AddPropertyDef(BfTypeDef* typeDef, BfPropertyDef* propDef) - { + { if (propDef->mName == "[]") { mResult += "["; @@ -8866,7 +8856,7 @@ public: if (countIdx > 0) { int genericCount = atoi(str.mPtr + countIdx + 1); - genericMatches = ((genericCount == search.mGenericCount) || (search.mGenericCount == 1)) && + genericMatches = ((genericCount == search.mGenericCount) || (search.mGenericCount == 1)) && (countIdx == (int)search.mStr.length()); } } @@ -8885,19 +8875,19 @@ public: bool CheckCompletesMatch(BfAtomComposite& name) { for (int i = 0; i < name.mSize; i++) - { + { CheckMatch(name.mParts[i]->mString); if (mFoundCount == mSearch.mSize) return true; } - return false; + return false; } bool IsFullMatch() { return mFoundCount == mSearch.mSize; } - + bool CheckMemberMatch(BfTypeDef* typeDef, const StringView& str) { if (CheckMatch(str) == 0) @@ -8936,14 +8926,14 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr) { int spacePos = (int)searchStr.IndexOf(' ', searchIdx); String str; - if (spacePos == -1) - str = searchStr.Substring(searchIdx); - else + if (spacePos == -1) + str = searchStr.Substring(searchIdx); + else str = searchStr.Substring(searchIdx, (int)(spacePos - searchIdx)); str.Trim(); - + TypeDefMatchHelper::SearchEntry searchEntry; - + for (int i = 0; i < (int)str.length(); i++) { char c = str[i]; @@ -8956,7 +8946,7 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr) { if (c == ',') searchEntry.mGenericCount++; - } + } } if (searchEntry.mStr.IsEmpty()) searchEntry.mStr = str; @@ -8968,7 +8958,7 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr) if (openParenIdx == -1) openParenIdx = matchHelper.mSearch.mSize; } - + if (!searchEntry.mStr.IsEmpty()) matchHelper.mSearch.Add(searchEntry); if (str.Contains('.')) @@ -8978,7 +8968,7 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr) searchIdx = spacePos + 1; } - //// We sort from longest to shortest to make sure longer strings match before shorter, which + //// We sort from longest to shortest to make sure longer strings match before shorter, which //// matters when the shorter string is a subset of the longer string //matchHelper.mSearch.Sort([](const String& lhs, const String& rhs) // { @@ -9001,13 +8991,13 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr) Array projectInfos; projectInfos.Resize(mSystem->mProjects.size()); - + String typeName; String foundName; int partialIdx = 0; for (auto typeDef : mSystem->mTypeDefs) - { + { if (typeDef->mIsPartial) continue; @@ -9017,14 +9007,14 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr) { matchHelper.mCurTypeName.Clear(); typeDef->mFullNameEx.ToString(matchHelper.mCurTypeName); - + matchHelper.ClearResults(); matchHelper.CheckMatch(matchHelper.mCurTypeName); - fullyMatchesName = matchHelper.IsFullMatch(); + fullyMatchesName = matchHelper.IsFullMatch(); } int matchIdx = -1; - + String tempStr; if (!fullyMatchesName) @@ -9058,7 +9048,7 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr) matchHelper.AddPropertyDef(typeDef, propDef); } } - + for (auto methodDef : typeDef->mMethods) { if ((methodDef->mMethodType != BfMethodType_Normal) && @@ -9069,7 +9059,7 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr) if (methodDef->mMethodDeclaration == NULL) continue; - + matchHelper.ClearResults(); bool matches = matchHelper.CheckMemberMatch(typeDef, methodDef->mName); bool hasTypeString = false; @@ -9086,7 +9076,7 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr) if (BfTypeUtils::TypeToString(tempStr, typeDef, (BfTypeNameFlags)(BfTypeNameFlag_HideGlobalName | BfTypeNameFlag_InternalName))) tempStr += "."; } - matchHelper.GetMethodDefString(methodDef, tempStr, &genericMethodParamIdx); + matchHelper.GetMethodDefString(methodDef, tempStr, &genericMethodParamIdx); matchHelper.CheckMatch(tempStr, openParenIdx); matches = matchHelper.IsFullMatch(); } @@ -9119,7 +9109,7 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr) matchHelper.AddMethodDef(methodDef); } } - + uint32 matchFlags = 0; for (int atomIdx = typeDef->mFullNameEx.mSize - 1; atomIdx >= 0; atomIdx--) { @@ -9143,9 +9133,9 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr) if (!matchHelper.MergeFlags(matchFlags)) { continue; - } + } } - + if (typeDef->mProject != curProject) { curProject = typeDef->mProject; @@ -9185,7 +9175,7 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr) break; } - dotCount++; + dotCount++; } } @@ -9197,13 +9187,13 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr) else { result += StrFormat("<%d@", *matchIdxPtr); - } + } } else { result += ":"; } - + if (typeDef->IsGlobalsContainer()) { result += "g"; @@ -9221,7 +9211,7 @@ String BfCompiler::GetTypeDefMatches(const StringImpl& searchStr) result += "c"; else result += "v"; - result += typeName + "\n"; + result += typeName + "\n"; } return result; @@ -9285,8 +9275,8 @@ void BfCompiler::GetTypeDefs(const StringImpl& inTypeName, Array& ty for (int i = 0; i < (int)typeName.length(); i++) if (typeName[i] == '+') typeName[i] = '.'; - - BfAtomComposite nameComposite; + + BfAtomComposite nameComposite; if ((typeName.IsEmpty()) || (mSystem->ParseAtomComposite(typeName, nameComposite))) { auto itr = mSystem->mTypeDefs.TryGet(nameComposite); @@ -9311,11 +9301,11 @@ String BfCompiler::GetTypeDefInfo(const StringImpl& inTypeName) { Array typeDefs; GetTypeDefs(inTypeName, typeDefs); - + String result; TypeDefMatchHelper matchHelper(result); - - for (auto typeDef : typeDefs) + + for (auto typeDef : typeDefs) { auto refNode = typeDef->GetRefNode(); result += "S"; @@ -9330,12 +9320,12 @@ String BfCompiler::GetTypeDefInfo(const StringImpl& inTypeName) } for (auto propDef : typeDef->mProperties) - { + { if (propDef->GetRefNode() == NULL) continue; result += "P"; - matchHelper.AddPropertyDef(typeDef, propDef); + matchHelper.AddPropertyDef(typeDef, propDef); } for (auto methodDef : typeDef->mMethods) @@ -9347,17 +9337,17 @@ String BfCompiler::GetTypeDefInfo(const StringImpl& inTypeName) continue; if (methodDef->mMethodDeclaration == NULL) - continue; + continue; result += "M"; - matchHelper.AddMethodDef(methodDef); + matchHelper.AddMethodDef(methodDef); } } return result; } int BfCompiler::GetTypeId(const StringImpl& typeName) -{ +{ auto type = GetType(typeName); if (type != NULL) return type->mTypeId; @@ -9371,7 +9361,7 @@ BfType* BfCompiler::GetType(const StringImpl& fullTypeName) BfPassInstance passInstance(mSystem); BfProject* activeProject = NULL; - + String typeName = fullTypeName; int colonPos = (int)typeName.LastIndexOf(':'); if (colonPos != -1) @@ -9420,12 +9410,12 @@ BfType* BfCompiler::GetType(const StringImpl& fullTypeName) } int BfCompiler::GetEmitSource(const StringImpl& fileName, StringImpl* outBuffer) -{ +{ int lastDollarPos = (int)fileName.LastIndexOf('$'); if (lastDollarPos == -1) - return -1; - - String typeName = fileName.Substring(lastDollarPos + 1); + return -1; + + String typeName = fileName.Substring(lastDollarPos + 1); int typeId = GetTypeId(typeName); if ((typeId <= 0) || (typeId >= mContext->mTypes.mSize)) return -1; @@ -9495,7 +9485,7 @@ String BfCompiler::GetEmitLocation(const StringImpl& typeName, int emitLine, int outHash = Hash64(emitParser->mSrc + kv.mValue.mSrcStart, kv.mValue.mSrcEnd - kv.mValue.mSrcStart); if ((emitLine >= startLine) && (emitLine <= endLine)) - { + { origParser->GetLineCharAtIdx(charIdx, outEmbedLine, outEmbedLineChar); return origParser->mFileName; } @@ -9553,7 +9543,7 @@ PerfManager* BfGetPerfManager(BfParser* bfParser); BF_EXPORT bool BF_CALLTYPE BfCompiler_Compile(BfCompiler* bfCompiler, BfPassInstance* bfPassInstance, const char* outputPath) { BP_ZONE("BfCompiler_Compile"); - + SetAndRestoreValue prevPassInstance(bfCompiler->mPassInstance, bfPassInstance); bfCompiler->mPassInstance = bfPassInstance; bfCompiler->Compile(outputPath); @@ -9567,29 +9557,29 @@ BF_EXPORT void BF_CALLTYPE BfCompiler_ClearResults(BfCompiler* bfCompiler) BF_EXPORT bool BF_CALLTYPE BfCompiler_ClassifySource(BfCompiler* bfCompiler, BfPassInstance* bfPassInstance, BfResolvePassData* resolvePassData) { - BP_ZONE("BfCompiler_ClassifySource"); - + BP_ZONE("BfCompiler_ClassifySource"); + bfCompiler->mSystem->AssertWeHaveLock(); String& autoCompleteResultString = *gTLStrReturn.Get(); autoCompleteResultString.clear(); - + bfPassInstance->mCompiler = bfCompiler; for (auto parser : resolvePassData->mParsers) - bfPassInstance->mFilterErrorsTo.Add(parser->mSourceData); + bfPassInstance->mFilterErrorsTo.Add(parser->mSourceData); bfPassInstance->mTrimMessagesToCursor = true; SetAndRestoreValue prevCompilerResolvePassData(bfCompiler->mResolvePassData, resolvePassData); SetAndRestoreValue prevPassInstance(bfCompiler->mPassInstance, bfPassInstance); bool canceled = false; - + if ((resolvePassData->mAutoComplete != NULL) && (!resolvePassData->mParsers.IsEmpty())) { bfCompiler->ProcessAutocompleteTempType(); } else canceled = !bfCompiler->Compile(""); - + return !canceled; } @@ -9599,7 +9589,7 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetCollapseRegions(BfCompiler* bfCo String& outString = *gTLStrReturn.Get(); outString.Clear(); - + class CollapseVisitor : public BfElementVisitor { public: @@ -9639,7 +9629,7 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetCollapseRegions(BfCompiler* bfCo } void FlushSeries() - { + { if (mStartSeriesIdx != -1) { bool ownsLine = true; @@ -9724,12 +9714,12 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetCollapseRegions(BfCompiler* bfCo void Add(BfAstNode* anchor, BfAstNode* end, char kind = '?', int minLines = 2) { if ((anchor == NULL) || (end == NULL)) - return; + return; Add(anchor->mSrcStart, end->mSrcEnd - 1, kind, minLines); } - + virtual void Visit(BfMethodDeclaration* methodDeclaration) override - { + { int anchorIdx = methodDeclaration->mSrcStart; if (methodDeclaration->mNameNode != NULL) @@ -9737,14 +9727,14 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetCollapseRegions(BfCompiler* bfCo if (methodDeclaration->mCloseParen != NULL) anchorIdx = methodDeclaration->mCloseParen->mSrcEnd - 1; - if (methodDeclaration->mBody != NULL) + if (methodDeclaration->mBody != NULL) Add(anchorIdx, methodDeclaration->mBody->mSrcEnd - 1, 'M'); BfElementVisitor::Visit(methodDeclaration); } virtual void Visit(BfNamespaceDeclaration* namespaceDeclaration) override - { + { Add(namespaceDeclaration->mNamespaceNode, namespaceDeclaration->mBody, 'N'); BfElementVisitor::Visit(namespaceDeclaration); @@ -9768,7 +9758,7 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetCollapseRegions(BfCompiler* bfCo } virtual void Visit(BfPropertyDeclaration* properyDeclaration) override - { + { Add(properyDeclaration->mNameNode, properyDeclaration->mDefinitionBlock, 'P'); BfElementVisitor::Visit(properyDeclaration); @@ -9782,14 +9772,14 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetCollapseRegions(BfCompiler* bfCo } virtual void Visit(BfPropertyMethodDeclaration* methodDeclaration) override - { + { Add(methodDeclaration->mNameNode, methodDeclaration->mBody); BfElementVisitor::Visit(methodDeclaration); } virtual void Visit(BfIfStatement* ifStatement) override - { + { Add(ifStatement->mCloseParen, ifStatement->mTrueStatement); if (auto elseBlock = BfNodeDynCast(ifStatement->mFalseStatement)) Add(ifStatement->mElseToken, elseBlock); @@ -9819,13 +9809,13 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetCollapseRegions(BfCompiler* bfCo } virtual void Visit(BfForStatement* forStatement) override - { + { Add(forStatement->mCloseParen, forStatement->mEmbeddedStatement); BfElementVisitor::Visit(forStatement); } virtual void Visit(BfForEachStatement* forStatement) override - { + { Add(forStatement->mCloseParen, forStatement->mEmbeddedStatement); BfElementVisitor::Visit(forStatement); } @@ -9837,7 +9827,7 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetCollapseRegions(BfCompiler* bfCo } virtual void Visit(BfSwitchStatement* switchStatement) override - { + { Add(switchStatement->mOpenParen, switchStatement->mCloseBrace); BfElementVisitor::Visit(switchStatement); } @@ -9849,7 +9839,7 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetCollapseRegions(BfCompiler* bfCo } virtual void Visit(BfBlock* block) override - { + { Add(block->mOpenBrace, block->mCloseBrace); BfElementVisitor::Visit(block); } @@ -9895,7 +9885,7 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetCollapseRegions(BfCompiler* bfCo if (regionStart != NULL) collapseVisitor.Add(regionStart->mSrcStart, preprocessorNode->mCommand->mSrcStart, 'R'); regionStart = NULL; - } + } else if (sv == "if") { condStart = preprocessorNode->mCommand; @@ -9927,7 +9917,7 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetCollapseRegions(BfCompiler* bfCo ignoredSectionStart = i + 1; break; } - } + } } } @@ -9970,7 +9960,7 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetCollapseRegions(BfCompiler* bfCo bool mIsPrimary; }; Dictionary> emitLocMap; - + bool mayHaveMissedEmits = false; for (auto type : bfCompiler->mContext->mResolvedTypes) @@ -9978,7 +9968,7 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetCollapseRegions(BfCompiler* bfCo auto typeInst = type->ToTypeInstance(); if (typeInst == NULL) continue; - + if (typeHashSet.Contains(typeInst->mTypeDef->GetDefinition()->GetLatest())) { if (typeInst->mCeTypeInfo == NULL) @@ -9998,7 +9988,7 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetCollapseRegions(BfCompiler* bfCo auto typeDef = typeInst->mTypeDef; if (partialIdx > 0) typeDef = typeDef->mPartials[partialIdx]; - + auto emitParser = typeInst->mTypeDef->GetLastSource()->ToParser(); Dictionary* map = NULL; @@ -10037,7 +10027,7 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetCollapseRegions(BfCompiler* bfCo else { int dollarPos = (int)emitParser->mFileName.LastIndexOf('$'); - if (dollarPos != -1) + if (dollarPos != -1) outString += emitParser->mFileName.Substring(dollarPos + 1); } outString += "\n"; @@ -10165,7 +10155,7 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetCollapseRegions(BfCompiler* bfCo } } } - + return outString.c_str(); } @@ -10184,7 +10174,7 @@ BF_EXPORT bool BF_CALLTYPE BfCompiler_VerifyTypeName(BfCompiler* bfCompiler, cha BfPassInstance passInstance(bfCompiler->mSystem); BfParser parser(bfCompiler->mSystem); - parser.SetSource(typeName.c_str(), (int)typeName.length()); + parser.SetSource(typeName.c_str(), (int)typeName.length()); parser.Parse(&passInstance); parser.mCursorIdx = cursorPos; parser.mCursorCheckIdx = cursorPos; @@ -10193,7 +10183,7 @@ BF_EXPORT bool BF_CALLTYPE BfCompiler_VerifyTypeName(BfCompiler* bfCompiler, cha reducer.mAlloc = parser.mAlloc; reducer.mPassInstance = &passInstance; reducer.mAllowTypeWildcard = true; - + if (parser.mRootNode->mChildArr.mSize == 0) return false; @@ -10222,7 +10212,7 @@ BF_EXPORT bool BF_CALLTYPE BfCompiler_VerifyTypeName(BfCompiler* bfCompiler, cha reducer.mVisitorPos.MoveNext(); } } - + reducer.mVisitorPos.MoveNext(); auto typeRef = reducer.CreateTypeRef(firstNode); if (typeRef == NULL) @@ -10232,15 +10222,15 @@ BF_EXPORT bool BF_CALLTYPE BfCompiler_VerifyTypeName(BfCompiler* bfCompiler, cha if (cursorPos != -1) { resolvePassData.mResolveType = BfResolveType_Autocomplete; - parser.mParserFlags = (BfParserFlag)(parser.mParserFlags | ParserFlag_Autocomplete); - resolvePassData.mAutoComplete = new BfAutoComplete(); + parser.mParserFlags = (BfParserFlag)(parser.mParserFlags | ParserFlag_Autocomplete); + resolvePassData.mAutoComplete = new BfAutoComplete(); resolvePassData.mAutoComplete->mResolveType = BfResolveType_VerifyTypeName; resolvePassData.mAutoComplete->mSystem = bfCompiler->mSystem; resolvePassData.mAutoComplete->mCompiler = bfCompiler; resolvePassData.mAutoComplete->mModule = bfCompiler->mContext->mScratchModule; } resolvePassData.mParsers.Add(&parser); - + SetAndRestoreValue prevCompilerResolvePassData(bfCompiler->mResolvePassData, &resolvePassData); SetAndRestoreValue prevPassInstance(bfCompiler->mPassInstance, &passInstance); @@ -10326,13 +10316,13 @@ BF_EXPORT void BF_CALLTYPE BfCompiler_WriteBuildCache(BfCompiler* bfCompiler, ch } BF_EXPORT void BF_CALLTYPE BfCompiler_Delete(BfCompiler* bfCompiler) -{ - delete bfCompiler; +{ + delete bfCompiler; } BF_EXPORT void BF_CALLTYPE BfCompiler_ProgramDone() { -#ifdef BF_PLATFORM_WINDOWS +#ifdef BF_PLATFORM_WINDOWS BeLibManager::Get()->Clear(); #endif } @@ -10387,7 +10377,7 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetTypeDefInfo(BfCompiler* bfCompil BF_EXPORT int BF_CALLTYPE BfCompiler_GetTypeId(BfCompiler* bfCompiler, const char* name) { - return bfCompiler->GetTypeId(name); + return bfCompiler->GetTypeId(name); } BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetTypeInfo(BfCompiler* bfCompiler, const char* name) @@ -10453,7 +10443,7 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetTypeInfo(BfCompiler* bfCompiler, BfResolvePassData resolvePass; SetAndRestoreValue prevIgnoreError(bfCompiler->mContext->mScratchModule->mIgnoreErrors, true); SetAndRestoreValue prevIgnoreWarnings(bfCompiler->mContext->mScratchModule->mIgnoreWarnings, true); - SetAndRestoreValue prevResolvePass(bfCompiler->mResolvePassData, &resolvePass); + SetAndRestoreValue prevResolvePass(bfCompiler->mResolvePassData, &resolvePass); auto type = bfCompiler->mContext->mScratchModule->ResolveTypeRef(typeRef, BfPopulateType_Identity, BfResolveTypeRefFlag_NoCreate); if (type != NULL) @@ -10530,7 +10520,7 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetGenericTypeInstances(BfCompiler* continue; if (typeInst->mTypeDef->GetDefinition()->GetLatest() == lookupTypeInst->mTypeDef->GetDefinition()->GetLatest()) - { + { outString += bfCompiler->mContext->mScratchModule->TypeToString(typeInst, BfTypeNameFlag_AddProjectName); outString += "\n"; } @@ -10547,40 +10537,40 @@ enum BfUsedOutputFlags }; BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetUsedOutputFileNames(BfCompiler* bfCompiler, BfProject* bfProject, BfUsedOutputFlags flags, bool* hadOutputChanges) -{ +{ bfCompiler->mSystem->AssertWeHaveLock(); BP_ZONE("BfCompiler_GetUsedOutputFileNames"); - + *hadOutputChanges = false; String& outString = *gTLStrReturn.Get(); outString.clear(); - + Array moduleList; moduleList.Reserve(bfProject->mUsedModules.size()); if (bfCompiler->mOptions.mCompileOnDemandKind == BfCompileOnDemandKind_AlwaysInclude) { for (auto mainModule : bfCompiler->mContext->mModules) - { + { if ((!mainModule->mIsReified) || (mainModule->mIsScratchModule)) continue; if (bfCompiler->mOptions.mHotProject != NULL) continue; // Only add new objs from mCodeGen.mCodeGenFiles during hot reload if (!bfCompiler->IsModuleAccessible(mainModule, bfProject)) continue; - + moduleList.push_back(mainModule); } } else { for (auto mainModule : bfProject->mUsedModules) - { + { if ((!mainModule->mIsReified) || (mainModule->mIsScratchModule)) continue; if (bfCompiler->mOptions.mHotProject != NULL) - continue; // Only add new objs from mCodeGen.mCodeGenFiles during hot reload + continue; // Only add new objs from mCodeGen.mCodeGenFiles during hot reload moduleList.push_back(mainModule); } @@ -10630,19 +10620,19 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetUsedOutputFileNames(BfCompiler* } if (!canReference) continue; - + String fileName = moduleFileName.mFileName; #ifdef BF_PLATFORM_WINDOWS if (moduleFileName.mWroteToLib) fileName = BeLibManager::GetLibFilePath(fileName); -#endif +#endif if (!usedFileNames.TryAdd(fileName, NULL)) continue; if (!outString.empty()) outString += "\n"; - outString += fileName; + outString += fileName; } } @@ -10723,7 +10713,7 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetSymbolReferences(BfCompiler* bfC SetAndRestoreValue prevPassInstance(bfCompiler->mPassInstance, bfPassInstance); bfCompiler->GetSymbolReferences(); - std::map sortedParserMap; + std::map sortedParserMap; for (auto& parserDataPair : resolvePassData->mFoundSymbolReferencesParserData) { if (!parserDataPair.mKey->mFileName.Contains('|')) @@ -10741,7 +10731,7 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetSymbolReferences(BfCompiler* bfC BF_EXPORT bool BF_CALLTYPE BfCompiler_GetHasHotPendingDataChanges(BfCompiler* bfCompiler) { - return (bfCompiler->mHotState != NULL) && + return (bfCompiler->mHotState != NULL) && ((!bfCompiler->mHotState->mPendingDataChanges.IsEmpty()) || (!bfCompiler->mHotState->mPendingFailedSlottings.IsEmpty())); } @@ -10785,7 +10775,7 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_HotResolve_Finish(BfCompiler* bfCom } static BfPlatformType GetPlatform(StringView str) -{ +{ while (!str.IsEmpty()) { char c = str[str.mLength - 1]; @@ -10796,7 +10786,7 @@ static BfPlatformType GetPlatform(StringView str) } bool hasLinux = false; - + for (auto elem : str.Split('-')) { if (elem == "linux") @@ -10825,9 +10815,9 @@ BF_EXPORT void BF_CALLTYPE BfCompiler_SetOptions(BfCompiler* bfCompiler, BfProje BfLogSys(bfCompiler->mSystem, "BfCompiler_SetOptions\n"); //printf("BfCompiler_SetOptions Threads:%d\n", maxWorkerThreads); - - auto options = &bfCompiler->mOptions; - + + auto options = &bfCompiler->mOptions; + options->mErrorString.Clear(); options->mHotProject = hotProject; options->mHotCompileIdx = hotIdx; @@ -10857,7 +10847,7 @@ BF_EXPORT void BF_CALLTYPE BfCompiler_SetOptions(BfCompiler* bfCompiler, BfProje if (options->mPlatformType != BfPlatformType_Windows) options->mCLongSize = 8; } - + bfCompiler->mCodeGen.SetMaxThreads(maxWorkerThreads); if (!bfCompiler->mIsResolveOnly) @@ -10867,10 +10857,10 @@ BF_EXPORT void BF_CALLTYPE BfCompiler_SetOptions(BfCompiler* bfCompiler, BfProje // These settings only matter for code generation, they are not applicable for resolveOnly options->mCompileOnDemandKind = BfCompileOnDemandKind_ResolveUnused; - //options->mCompileOnDemandKind = BfCompileOnDemandKind_AlwaysInclude; + //options->mCompileOnDemandKind = BfCompileOnDemandKind_AlwaysInclude; options->mToolsetType = (BfToolsetType)toolsetType; options->mSIMDSetting = (BfSIMDSetting)simdSetting; - options->mIncrementalBuild = (optionFlags & BfCompilerOptionFlag_IncrementalBuild) != 0; + options->mIncrementalBuild = (optionFlags & BfCompilerOptionFlag_IncrementalBuild) != 0; options->mWriteIR = (optionFlags & BfCompilerOptionFlag_WriteIR) != 0; options->mGenerateObj = (optionFlags & BfCompilerOptionFlag_GenerateOBJ) != 0; options->mGenerateBitcode = (optionFlags & BfCompilerOptionFlag_GenerateBitcode) != 0; @@ -10893,12 +10883,12 @@ BF_EXPORT void BF_CALLTYPE BfCompiler_SetOptions(BfCompiler* bfCompiler, BfProje // { // options->mErrorString = "Toolset 'Microsoft' is not available on this platform. Consider changing 'Workspace/General/Toolset'."; // } - BF_ASSERT(!options->mEnableRealtimeLeakCheck); + BF_ASSERT(!options->mEnableRealtimeLeakCheck); #endif options->mEmitObjectAccessCheck = (optionFlags & BfCompilerOptionFlag_EmitObjectAccessCheck) != 0; options->mArithmeticChecks = (optionFlags & BfCompilerOptionFlag_ArithmeticChecks) != 0; options->mAllocStackCount = allocStackCount; - + if (hotProject != NULL) { String errorName; @@ -10921,14 +10911,14 @@ BF_EXPORT void BF_CALLTYPE BfCompiler_SetOptions(BfCompiler* bfCompiler, BfProje else { options->mAllowHotSwapping = allowHotSwapping; - options->mHasVDataExtender = options->mAllowHotSwapping; + options->mHasVDataExtender = options->mAllowHotSwapping; options->mMallocLinkName = mallocLinkName; options->mFreeLinkName = freeLinkName; options->mEmitDebugInfo = emitDebugInfo; options->mEmitLineInfo = (optionFlags & BfCompilerOptionFlag_EmitLineInfo) != 0;; options->mEnableCustodian = (optionFlags & BfCompilerOptionFlag_EnableCustodian) != 0; options->mEnableSideStack = (optionFlags & BfCompilerOptionFlag_EnableSideStack) != 0; - } + } } else { @@ -10936,11 +10926,11 @@ BF_EXPORT void BF_CALLTYPE BfCompiler_SetOptions(BfCompiler* bfCompiler, BfProje options->mAllowHotSwapping = false; options->mObjectHasDebugFlags = false; options->mEnableRealtimeLeakCheck = false; - options->mEmitObjectAccessCheck = false; + options->mEmitObjectAccessCheck = false; options->mArithmeticChecks = false; options->mEmitDynamicCastCheck = false; options->mRuntimeChecks = (optionFlags & BfCompilerOptionFlag_RuntimeChecks) != 0; - } + } } BF_EXPORT void BF_CALLTYPE BfCompiler_ForceRebuild(BfCompiler* bfCompiler) @@ -10974,4 +10964,4 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetEmitLocation(BfCompiler* bfCompi BF_EXPORT bool BF_CALLTYPE BfCompiler_WriteEmitData(BfCompiler* bfCompiler, char* filePath, BfProject* project) { return bfCompiler->WriteEmitData(filePath, project); -} +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfCompiler.h b/IDEHelper/Compiler/BfCompiler.h index 3a8a9ab9..5c8ca6d7 100644 --- a/IDEHelper/Compiler/BfCompiler.h +++ b/IDEHelper/Compiler/BfCompiler.h @@ -50,7 +50,7 @@ enum BfCompileOnDemandKind BfCompileOnDemandKind_SkipUnused }; -class BfCompiler +class BfCompiler { public: enum CompileState @@ -63,22 +63,22 @@ public: }; struct Stats - { + { int mTotalTypes; int mMethodDeclarations; int mTypesPopulated; int mMethodsProcessed; - int mUnreifiedMethodsProcessed; + int mUnreifiedMethodsProcessed; int mQueuedTypesProcessed; int mTypesQueued; int mTypesDeleted; - int mMethodsQueued; + int mMethodsQueued; int mModulesStarted; int mModulesFinished; - + int mModulesReified; int mModulesUnreified; @@ -94,19 +94,19 @@ public: { BfProject* mHotProject; int mHotCompileIdx; - + int32 mForceRebuildIdx; - BfCompileOnDemandKind mCompileOnDemandKind; + BfCompileOnDemandKind mCompileOnDemandKind; String mTargetTriple; String mTargetCPU; BfPlatformType mPlatformType; BfMachineType mMachineType; int mCLongSize; BfToolsetType mToolsetType; - BfSIMDSetting mSIMDSetting; + BfSIMDSetting mSIMDSetting; String mMallocLinkName; String mFreeLinkName; - bool mIncrementalBuild; + bool mIncrementalBuild; bool mEmitDebugInfo; bool mEmitLineInfo; @@ -116,15 +116,15 @@ public: bool mRuntimeChecks; bool mAllowStructByVal; bool mEmitDynamicCastCheck; - + bool mAllowHotSwapping; - bool mObjectHasDebugFlags; + bool mObjectHasDebugFlags; bool mEnableRealtimeLeakCheck; bool mEmitObjectAccessCheck; // Only valid with mObjectHasDebugFlags bool mArithmeticChecks; bool mEnableCustodian; bool mEnableSideStack; - bool mHasVDataExtender; + bool mHasVDataExtender; bool mDebugAlloc; bool mOmitDebugHelpers; @@ -167,7 +167,7 @@ public: mAllowHotSwapping = false; mEmitObjectAccessCheck = false; mArithmeticChecks = false; - mObjectHasDebugFlags = false; + mObjectHasDebugFlags = false; mEnableRealtimeLeakCheck = false; mWriteIR = false; mGenerateObj = true; @@ -195,19 +195,19 @@ public: } }; Options mOptions; - + enum HotTypeFlags { HotTypeFlag_None = 0, HotTypeFlag_UserNotUsed = 1, - HotTypeFlag_UserUsed = 2, - + HotTypeFlag_UserUsed = 2, + HotTypeFlag_Heap = 4, HotTypeFlag_ActiveFunction = 8, // Only set for a type version mismatch HotTypeFlag_Delegate = 0x10, // Only set for a type version mismatch HotTypeFlag_FuncPtr = 0x20, // Only set for a type version mismatch HotTypeFlag_CanAllocate = 0x40 - }; + }; enum HotResolveFlags { @@ -237,7 +237,7 @@ public: Array mHotTypeIdFlags; Array mReasons; HashSet mDeferredThisCheckMethods; - + ~HotResolveData(); }; @@ -261,7 +261,7 @@ public: BfHotThisType* GetThisType(BfHotTypeVersion* hotVersion); BfHotAllocation* GetAllocation(BfHotTypeVersion* hotVersion); BfHotDevirtualizedMethod* GetDevirtualizedMethod(BfHotMethod* hotMethod); - BfHotFunctionReference* GetFunctionReference(BfHotMethod* hotMethod); + BfHotFunctionReference* GetFunctionReference(BfHotMethod* hotMethod); BfHotVirtualDeclaration* GetVirtualDeclaration(BfHotMethod* hotMethod); BfHotInnerMethod* GetInnerMethod(BfHotMethod* hotMethod); }; @@ -270,10 +270,10 @@ public: { public: BfProject* mHotProject; - int mLastStringId; + int mLastStringId; int mCommittedHotCompileIdx; bool mHasNewTypes; - bool mHasNewInterfaceTypes; + bool mHasNewInterfaceTypes; Array mQueuedOutFiles; // Queues up when we have failed hot compiles HashSet mSlotDefineTypeIds; HashSet mNewlySlottedTypeIds; @@ -284,7 +284,7 @@ public: public: HotState() - { + { mHotProject = NULL; mLastStringId = -1; mCommittedHotCompileIdx = 0; @@ -298,28 +298,28 @@ public: void RemovePendingChanges(BfTypeInstance* type); }; HotData* mHotData; - HotState* mHotState; + HotState* mHotState; HotResolveData* mHotResolveData; struct StringValueEntry { int mId; BfIRValue mStringVal; - }; + }; struct TestMethod { String mName; BfMethodInstance* mMethodInstance; - }; + }; -public: - BfPassInstance* mPassInstance; +public: + BfPassInstance* mPassInstance; FILE* mCompileLogFP; CeMachine* mCeMachine; int mCurCEExecuteId; - BfSystem* mSystem; + BfSystem* mSystem; bool mIsResolveOnly; BfResolvePassData* mResolvePassData; Dictionary> mAttributeTypeOptionMap; @@ -343,13 +343,13 @@ public: bool mDepsMayHaveDeletedTypes; float mCompletionPct; int mHSPreserveIdx; - BfModule* mLastAutocompleteModule; + BfModule* mLastAutocompleteModule; CompileState mCompileState; HashSet mRebuildFileSet; HashSet mRebuildChangedFileSet; // Files we had actual changes from - Array mVDataModules; - + Array mVDataModules; + BfTypeDef* mBfObjectTypeDef; BfTypeDef* mChar32TypeDef; BfTypeDef* mFloatTypeDef; @@ -360,16 +360,16 @@ public: BfTypeDef* mArray2TypeDef; BfTypeDef* mArray3TypeDef; BfTypeDef* mArray4TypeDef; - BfTypeDef* mSpanTypeDef; + BfTypeDef* mSpanTypeDef; BfTypeDef* mRangeTypeDef; BfTypeDef* mClosedRangeTypeDef; BfTypeDef* mIndexTypeDef; BfTypeDef* mIndexRangeTypeDef; - - BfTypeDef* mClassVDataTypeDef; - + + BfTypeDef* mClassVDataTypeDef; + BfTypeDef* mDbgRawAllocDataTypeDef; - BfTypeDef* mDeferredCallTypeDef; + BfTypeDef* mDeferredCallTypeDef; BfTypeDef* mDelegateTypeDef; BfTypeDef* mFunctionTypeDef; BfTypeDef* mActionTypeDef; @@ -377,13 +377,13 @@ public: BfTypeDef* mStringTypeDef; BfTypeDef* mStringViewTypeDef; BfTypeDef* mTypeTypeDef; - BfTypeDef* mValueTypeTypeDef; - BfTypeDef* mResultTypeDef; - BfTypeDef* mGCTypeDef; + BfTypeDef* mValueTypeTypeDef; + BfTypeDef* mResultTypeDef; + BfTypeDef* mGCTypeDef; BfTypeDef* mGenericIEnumerableTypeDef; BfTypeDef* mGenericIEnumeratorTypeDef; BfTypeDef* mGenericIRefEnumeratorTypeDef; - + BfTypeDef* mThreadTypeDef; BfTypeDef* mInternalTypeDef; BfTypeDef* mPlatformTypeDef; @@ -395,15 +395,15 @@ public: BfTypeDef* mIPrintableTypeDef; BfTypeDef* mIHashableTypeDef; BfTypeDef* mIComptimeTypeApply; - BfTypeDef* mIComptimeMethodApply; + BfTypeDef* mIComptimeMethodApply; BfTypeDef* mIOnTypeInitTypeDef; BfTypeDef* mIOnTypeDoneTypeDef; BfTypeDef* mIOnFieldInitTypeDef; BfTypeDef* mIOnMethodInitTypeDef; - + BfTypeDef* mMethodRefTypeDef; BfTypeDef* mNullableTypeDef; - + BfTypeDef* mPointerTTypeDef; BfTypeDef* mPointerTypeDef; BfTypeDef* mReflectTypeIdTypeDef; @@ -420,17 +420,17 @@ public: BfTypeDef* mReflectConstExprType; BfTypeDef* mReflectSpecializedGenericType; BfTypeDef* mReflectTypeInstanceTypeDef; - BfTypeDef* mReflectUnspecializedGenericType; + BfTypeDef* mReflectUnspecializedGenericType; BfTypeDef* mReflectFieldInfoTypeDef; BfTypeDef* mReflectMethodInfoTypeDef; - + BfTypeDef* mSizedArrayTypeDef; BfTypeDef* mAttributeTypeDef; BfTypeDef* mAttributeUsageAttributeTypeDef; BfTypeDef* mLinkNameAttributeTypeDef; BfTypeDef* mCallingConventionAttributeTypeDef; - BfTypeDef* mOrderedAttributeTypeDef; - BfTypeDef* mInlineAttributeTypeDef; + BfTypeDef* mOrderedAttributeTypeDef; + BfTypeDef* mInlineAttributeTypeDef; BfTypeDef* mCLinkAttributeTypeDef; BfTypeDef* mImportAttributeTypeDef; BfTypeDef* mExportAttributeTypeDef; @@ -446,30 +446,30 @@ public: BfTypeDef* mConstEvalAttributeTypeDef; BfTypeDef* mNoExtensionAttributeTypeDef; BfTypeDef* mCheckedAttributeTypeDef; - BfTypeDef* mUncheckedAttributeTypeDef; + BfTypeDef* mUncheckedAttributeTypeDef; BfTypeDef* mStaticInitAfterAttributeTypeDef; - BfTypeDef* mStaticInitPriorityAttributeTypeDef; + BfTypeDef* mStaticInitPriorityAttributeTypeDef; BfTypeDef* mTestAttributeTypeDef; - BfTypeDef* mThreadStaticAttributeTypeDef; + BfTypeDef* mThreadStaticAttributeTypeDef; BfTypeDef* mUnboundAttributeTypeDef; BfTypeDef* mObsoleteAttributeTypeDef; BfTypeDef* mErrorAttributeTypeDef; BfTypeDef* mWarnAttributeTypeDef; BfTypeDef* mConstSkipAttributeTypeDef; BfTypeDef* mIgnoreErrorsAttributeTypeDef; - BfTypeDef* mReflectAttributeTypeDef; + BfTypeDef* mReflectAttributeTypeDef; BfTypeDef* mOnCompileAttributeTypeDef; - int mCurTypeId; + int mCurTypeId; int mTypeInitCount; String mOutputPath; - Array mGenericInstancePurgatory; + Array mGenericInstancePurgatory; Array mTypeIdFreeList; int mMaxInterfaceSlots; bool mInterfaceSlotCountChanged; -public: +public: bool IsTypeAccessible(BfType* checkType, BfProject* curProject); bool IsTypeUsed(BfType* checkType, BfProject* curProject); bool IsModuleAccessible(BfModule* module, BfProject* curProject); @@ -479,22 +479,22 @@ public: BfIRFunction CreateLoadSharedLibraries(BfVDataModule* bfModule, Array& dllMethods); void GetTestMethods(BfVDataModule* bfModule, Array& testMethods, HashContext& vdataHashCtx); void EmitTestMethod(BfVDataModule* bfModule, Array& testMethods, BfIRValue& retValue); - void CreateVData(BfVDataModule* bfModule); + void CreateVData(BfVDataModule* bfModule); void UpdateDependencyMap(bool deleteUnusued, bool& didWork); void SanitizeDependencyMap(); bool ProcessPurgatory(bool reifiedOnly); bool VerifySlotNums(); bool QuickGenerateSlotNums(); bool SlowGenerateSlotNums(); - void GenerateSlotNums(); + void GenerateSlotNums(); void GenerateDynCastData(); void UpdateRevisedTypes(); - void VisitAutocompleteExteriorIdentifiers(); + void VisitAutocompleteExteriorIdentifiers(); void VisitSourceExteriorNodes(); void UpdateCompletion(); bool DoWorkLoop(bool onlyReifiedTypes = false, bool onlyReifiedMethods = false); BfMangler::MangleKind GetMangleKind(); - + BfTypeDef* GetArrayTypeDef(int dimensions); void GenerateAutocompleteInfo(); void MarkStringPool(BfModule* module); @@ -517,7 +517,7 @@ public: bool IsCePaused(); bool EnsureCeUnpaused(BfType* refType); - void HotCommit(); + void HotCommit(); void HotResolve_Start(HotResolveFlags flags); void HotResolve_PopulateMethodNameMap(); bool HotResolve_AddReachableMethod(BfHotMethod* hotMethod, HotTypeFlags flags, bool devirtualized, bool forceProcess = false); @@ -532,24 +532,24 @@ public: public: BfCompiler(BfSystem* bfSystem, bool isResolveOnly); - ~BfCompiler(); + ~BfCompiler(); - bool Compile(const StringImpl& outputPath); + bool Compile(const StringImpl& outputPath); bool DoCompile(const StringImpl& outputPath); void ClearResults(); - void ProcessAutocompleteTempType(); - void GetSymbolReferences(); + void ProcessAutocompleteTempType(); + void GetSymbolReferences(); void Cancel(); - void RequestFastFinish(); + void RequestFastFinish(); String GetTypeDefList(); String GetGeneratorString(BfTypeDef* typeDef, BfTypeInstance* typeInst, const StringImpl& generatorMethodName, const StringImpl* args); void HandleGeneratorErrors(StringImpl& result); String GetGeneratorTypeDefList(); String GetGeneratorInitData(const StringImpl& typeName, const StringImpl& args); String GetGeneratorGenData(const StringImpl& typeName, const StringImpl& args); - String GetTypeDefMatches(const StringImpl& searchSrc); + String GetTypeDefMatches(const StringImpl& searchSrc); void GetTypeDefs(const StringImpl& typeName, Array& typeDefs); - String GetTypeDefInfo(const StringImpl& typeName); + String GetTypeDefInfo(const StringImpl& typeName); int GetTypeId(const StringImpl& typeName); BfType* GetType(const StringImpl& typeName); int GetEmitSource(const StringImpl& fileName, StringImpl* outBuffer); @@ -561,4 +561,3 @@ public: }; NS_BF_END - diff --git a/IDEHelper/Compiler/BfConstResolver.cpp b/IDEHelper/Compiler/BfConstResolver.cpp index 300b0db9..0a92b9aa 100644 --- a/IDEHelper/Compiler/BfConstResolver.cpp +++ b/IDEHelper/Compiler/BfConstResolver.cpp @@ -64,25 +64,25 @@ BfTypedValue BfConstResolver::Resolve(BfExpression* expr, BfType* wantType, BfCo // Dot-initialized if (memberRefExpr->mTarget == NULL) arraySize = (int)invocationExpr->mArguments.size(); - } + } else if (auto indexerExpr = BfNodeDynCast(invocationExpr->mTarget)) { if (indexerExpr->mArguments.size() == 0) { // Inferred-type sized array initializer arraySize = (int)invocationExpr->mArguments.size(); - } + } } } } if (arraySize != -1) - { + { mResult = BfTypedValue(mModule->GetConstValue(arraySize), mModule->GetPrimitiveType(BfTypeCode_IntPtr)); return mResult; } else - { + { mResult = BfTypedValue(mModule->mBfIRBuilder->GetUndefConstValue(mModule->mBfIRBuilder->GetPrimitiveType(BfTypeCode_IntPtr)), mModule->GetPrimitiveType(BfTypeCode_IntPtr)); return mResult; } @@ -103,16 +103,16 @@ BfTypedValue BfConstResolver::Resolve(BfExpression* expr, BfType* wantType, BfCo } SetAndRestoreValue prevIgnoreWrites(mModule->mBfIRBuilder->mIgnoreWrites, wantIgnoreWrites); - + auto prevInsertBlock = mModule->mBfIRBuilder->GetInsertBlock(); mNoBind = true; if (wantType != NULL) mExpectingType = wantType; VisitChildNoRef(expr); - + mResult = GetResult(); - + auto compilerVal = mModule->GetCompilerFieldValue(mResult); if (compilerVal) mResult = compilerVal; @@ -131,14 +131,14 @@ BfTypedValue BfConstResolver::Resolve(BfExpression* expr, BfType* wantType, BfCo (toType == mResult.mType))) { auto constant = mModule->mBfIRBuilder->GetConstant(mResult.mValue); - + if (constant->mTypeCode == BfTypeCode_NullPtr) { return mModule->GetDefaultTypedValue(toType); } else { - int stringId = mModule->GetStringPoolIdx(mResult.mValue); + int stringId = mModule->GetStringPoolIdx(mResult.mValue); if (stringId != -1) { if ((flags & BfConstResolveFlag_ActualizeValues) != 0) @@ -166,9 +166,9 @@ BfTypedValue BfConstResolver::Resolve(BfExpression* expr, BfType* wantType, BfCo mResult = convValue; } else - { + { mResult = mModule->Cast(expr, mResult, wantType, (BfCastFlags)(BfCastFlags_NoConversionOperator | (explicitCast ? BfCastFlags_Explicit : BfCastFlags_None))); - } + } } if (mResult.mKind == BfTypedValueKind_GenericConstValue) @@ -195,9 +195,9 @@ BfTypedValue BfConstResolver::Resolve(BfExpression* expr, BfType* wantType, BfCo isConst = false; } } - + if ((!isConst) && ((mBfEvalExprFlags & BfEvalExprFlags_AllowNonConst) == 0)) - { + { mModule->Fail("Expression does not evaluate to a constant value", expr); if (wantType != NULL) @@ -210,7 +210,7 @@ BfTypedValue BfConstResolver::Resolve(BfExpression* expr, BfType* wantType, BfCo { if (wantType != NULL) mResult = mModule->GetDefaultTypedValue(wantType); - } + } if (prevInsertBlock) mModule->mBfIRBuilder->SetInsertPoint(prevInsertBlock); @@ -221,7 +221,7 @@ BfTypedValue BfConstResolver::Resolve(BfExpression* expr, BfType* wantType, BfCo mModule->mBfIRBuilder->SetInsertPoint(prevInsertBlock); }*/ - mModule->FixIntUnknown(mResult); + mModule->FixIntUnknown(mResult); if ((flags & BfConstResolveFlag_NoActualizeValues) == 0) { @@ -240,10 +240,10 @@ bool BfConstResolver::PrepareMethodArguments(BfAstNode* targetSrc, BfMethodMatch int extendedParamIdx = 0; SetAndRestoreValue ignoreWrites(mModule->mBfIRBuilder->mIgnoreWrites, true); - + llvm::SmallVector expandedParamsConstValues; BfType* expandedParamsElementType = NULL; - + // We don't do GetMethodInstance in mModule, because our module may not have init finished yet //auto targetModule = methodMatcher->mBestMethodTypeInstance->mModule; auto targetModule = mModule->mContext->mUnreifiedModule; @@ -260,7 +260,7 @@ bool BfConstResolver::PrepareMethodArguments(BfAstNode* targetSrc, BfMethodMatch auto& arguments = methodMatcher->mArguments; mModule->AddDependency(methodInstance->mReturnType, mModule->mCurTypeInstance, BfDependencyMap::DependencyFlag_LocalUsage); - for (int paramIdx = 0; paramIdx < methodInstance->GetParamCount(); paramIdx++) + for (int paramIdx = 0; paramIdx < methodInstance->GetParamCount(); paramIdx++) { auto paramType = methodInstance->GetParamType(paramIdx); mModule->AddDependency(paramType, mModule->mCurTypeInstance, BfDependencyMap::DependencyFlag_LocalUsage); @@ -271,7 +271,7 @@ bool BfConstResolver::PrepareMethodArguments(BfAstNode* targetSrc, BfMethodMatch if (paramIdx >= (int)methodInstance->GetParamCount()) { if (argIdx < (int)arguments.size()) - { + { BfAstNode* errorRef = arguments[methodInstance->GetParamCount()].mExpression; if (errorRef->GetSourceData() == NULL) errorRef = targetSrc; @@ -281,7 +281,7 @@ bool BfConstResolver::PrepareMethodArguments(BfAstNode* targetSrc, BfMethodMatch return false; } break; - } + } BfType* wantType = NULL; if (expandedParamsElementType != NULL) @@ -351,7 +351,7 @@ bool BfConstResolver::PrepareMethodArguments(BfAstNode* targetSrc, BfMethodMatch if (attributeDirective->mCtorCloseParen != NULL) refNode = attributeDirective->mCtorCloseParen; } - } + } auto autoComplete = GetAutoComplete(); if (autoComplete != NULL) @@ -361,14 +361,14 @@ bool BfConstResolver::PrepareMethodArguments(BfAstNode* targetSrc, BfMethodMatch autoComplete->CheckEmptyStart(prevNode, wantType); } } - + if (mModule->PreFail()) mModule->Fail(StrFormat("Not enough parameters specified. Expected %d more.", methodInstance->GetParamCount() - (int)arguments.size()), refNode); return false; } auto foreignDefaultVal = methodInstance->mDefaultValues[argIdx]; - auto foreignConst = methodInstance->GetOwner()->mConstHolder->GetConstant(foreignDefaultVal.mValue); + auto foreignConst = methodInstance->GetOwner()->mConstHolder->GetConstant(foreignDefaultVal.mValue); argValue = mModule->GetTypedValueFromConstant(foreignConst, methodInstance->GetOwner()->mConstHolder, foreignDefaultVal.mType); } @@ -387,7 +387,7 @@ bool BfConstResolver::PrepareMethodArguments(BfAstNode* targetSrc, BfMethodMatch arg.mArgFlags = BfArgFlag_None; } } - + if (!argValue) return BfTypedValue(); @@ -410,14 +410,14 @@ bool BfConstResolver::PrepareMethodArguments(BfAstNode* targetSrc, BfMethodMatch extendedParamIdx++; } else - { + { bool requiresConst = false; if ((mModule->mCurMethodInstance == NULL) || (mModule->mCurMethodInstance->mMethodDef->mMethodType != BfMethodType_Mixin)) requiresConst = true; if ((requiresConst) && (argValue.mValue.IsFake()) && (!argValue.mType->IsValuelessType())) - { - mModule->Fail("Expression does not evaluate to a constant value", argExpr); + { + mModule->Fail("Expression does not evaluate to a constant value", argExpr); } if (!argValue.mType->IsVar()) @@ -433,11 +433,11 @@ bool BfConstResolver::PrepareMethodArguments(BfAstNode* targetSrc, BfMethodMatch } if (expandedParamsElementType != NULL) - { + { auto arrayType = mModule->mBfIRBuilder->GetSizedArrayType(mModule->mBfIRBuilder->MapType(expandedParamsElementType), (int)expandedParamsConstValues.size()); auto constArray = mModule->mBfIRBuilder->CreateConstAgg(arrayType, expandedParamsConstValues); llvmArgs.push_back(constArray); - } + } return true; } \ No newline at end of file diff --git a/IDEHelper/Compiler/BfConstResolver.h b/IDEHelper/Compiler/BfConstResolver.h index 0f988c77..7f5efd60 100644 --- a/IDEHelper/Compiler/BfConstResolver.h +++ b/IDEHelper/Compiler/BfConstResolver.h @@ -24,13 +24,13 @@ enum BfConstResolveFlags class BfConstResolver : public BfExprEvaluator { public: - bool mIsInvalidConstExpr; + bool mIsInvalidConstExpr; public: virtual bool CheckAllowValue(const BfTypedValue& typedValue, BfAstNode* refNode) override; public: - BfConstResolver(BfModule* bfModule); + BfConstResolver(BfModule* bfModule); BfTypedValue Resolve(BfExpression* expr, BfType* wantType = NULL, BfConstResolveFlags flags = BfConstResolveFlag_None); bool PrepareMethodArguments(BfAstNode* targetSrc, BfMethodMatcher* methodMatcher, Array& llvmArgs); diff --git a/IDEHelper/Compiler/BfContext.cpp b/IDEHelper/Compiler/BfContext.cpp index c2be9a8e..35bcad81 100644 --- a/IDEHelper/Compiler/BfContext.cpp +++ b/IDEHelper/Compiler/BfContext.cpp @@ -37,9 +37,9 @@ BfContext::BfContext(BfCompiler* compiler) : mTypeDefTypeRefPool(true, true) { mCompiler = compiler; - mSystem = compiler->mSystem; - mBfTypeType = NULL; - mBfClassVDataPtrType = NULL; + mSystem = compiler->mSystem; + mBfTypeType = NULL; + mBfClassVDataPtrType = NULL; mBfObjectType = NULL; mCanSkipObjectCtor = true; mCanSkipValueTypeCtor = true; @@ -53,7 +53,7 @@ BfContext::BfContext(BfCompiler* compiler) : mCurConstraintState = NULL; mResolvingVarField = false; mAssertOnPopulateType = false; - + for (int i = 0; i < BfTypeCode_Length; i++) { mPrimitiveTypes[i] = NULL; @@ -65,14 +65,14 @@ BfContext::BfContext(BfCompiler* compiler) : mScratchModule->mIsScratchModule = true; mScratchModule->mIsReified = true; mScratchModule->mGeneratesCode = false; - mScratchModule->Init(); + mScratchModule->Init(); mUnreifiedModule = new BfModule(this, ""); - mUnreifiedModule->mIsSpecialModule = true; + mUnreifiedModule->mIsSpecialModule = true; mUnreifiedModule->mIsScratchModule = true; mUnreifiedModule->mIsReified = false; mUnreifiedModule->mGeneratesCode = false; - mUnreifiedModule->Init(); + mUnreifiedModule->Init(); mValueTypeDeinitSentinel = (BfMethodInstance*)1; @@ -83,7 +83,7 @@ BfContext::BfContext(BfCompiler* compiler) : void BfReportMemory(); BfContext::~BfContext() -{ +{ BfLogSysM("Deleting Context...\n"); mDeleting = true; @@ -96,21 +96,21 @@ BfContext::~BfContext() int numTypesDeleted = 0; for (auto type : mResolvedTypes) - { + { //_CrtCheckMemory(); delete type; - } - + } + delete mScratchModule; delete mUnreifiedModule; for (auto module : mModules) delete module; - + BfReportMemory(); } void BfContext::ReportMemory(MemReporter* memReporter) -{ +{ memReporter->Add(sizeof(BfContext)); } @@ -124,7 +124,7 @@ void BfContext::ProcessMethod(BfMethodInstance* methodInstance) defModule = mUnreifiedModule; auto typeInst = methodInstance->GetOwner(); - defModule->ProcessMethod(methodInstance); + defModule->ProcessMethod(methodInstance); mCompiler->mStats.mMethodsProcessed++; if (!methodInstance->mIsReified) mCompiler->mStats.mUnreifiedMethodsProcessed++; @@ -133,7 +133,7 @@ void BfContext::ProcessMethod(BfMethodInstance* methodInstance) int BfContext::GetStringLiteralId(const StringImpl& str) { - // Note: We do need string pooling in resolve, for intrinsic names and such + // Note: We do need string pooling in resolve, for intrinsic names and such int* idPtr = NULL; if (mStringObjectPool.TryGetValue(str, &idPtr)) @@ -174,15 +174,15 @@ void BfContext::AssignModule(BfType* type) BfTypeProcessRequest* typeProcessEntry = mPopulateTypeWorkList.Alloc(); typeProcessEntry->mType = type; BF_ASSERT(typeProcessEntry->mType->mContext == this); - BfLogSysM("HandleTypeWorkItem: %p -> %p\n", type, typeProcessEntry->mType); + BfLogSysM("HandleTypeWorkItem: %p -> %p\n", type, typeProcessEntry->mType); mCompiler->mStats.mTypesQueued++; - mCompiler->UpdateCompletion(); + mCompiler->UpdateCompletion(); } else { auto typeInst = type->ToTypeInstance(); BF_ASSERT(typeInst != NULL); - + auto project = typeInst->mTypeDef->mProject; if ((project->mSingleModule) && (typeInst->mIsReified)) { @@ -200,7 +200,7 @@ void BfContext::AssignModule(BfType* type) needsModuleInit = true; } else - { + { module = *modulePtr; typeInst->mModule = module; } @@ -210,7 +210,7 @@ void BfContext::AssignModule(BfType* type) StringT<256> moduleName; GenerateModuleName(typeInst, moduleName); module = new BfModule(this, moduleName); - module->mIsReified = typeInst->mIsReified; + module->mIsReified = typeInst->mIsReified; module->mProject = project; typeInst->mModule = module; BF_ASSERT(!mLockModules); @@ -235,7 +235,7 @@ void BfContext::AssignModule(BfType* type) } void BfContext::HandleTypeWorkItem(BfType* type) -{ +{ AssignModule(type); } @@ -251,7 +251,7 @@ void BfContext::EnsureHotMangledVirtualMethodNames() BP_ZONE("BfContext::EnsureHotMangledVirtualMethodNames"); for (auto type : mResolvedTypes) - { + { auto typeInst = type->ToTypeInstance(); if (typeInst == NULL) continue; @@ -322,11 +322,11 @@ void BfContext::CancelWorkItems() BfLogSysM("BfContext::CancelWorkItems\n"); for (int workIdx = 0; workIdx < (int)mMethodSpecializationWorkList.size(); workIdx++) - { + { auto workItemRef = mMethodSpecializationWorkList[workIdx]; - if (workItemRef != NULL) - workItemRef->mFromModule->mHadBuildError = true; - workIdx = mMethodSpecializationWorkList.RemoveAt(workIdx); + if (workItemRef != NULL) + workItemRef->mFromModule->mHadBuildError = true; + workIdx = mMethodSpecializationWorkList.RemoveAt(workIdx); } mMethodSpecializationWorkList.Clear(); @@ -350,24 +350,24 @@ void BfContext::CancelWorkItems() } bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) -{ - bool didAnyWork = false; +{ + bool didAnyWork = false; while (!mCompiler->mCanceling) - { + { BfParser* resolveParser = NULL; if ((mCompiler->mResolvePassData != NULL) && (!mCompiler->mResolvePassData->mParsers.IsEmpty())) resolveParser = mCompiler->mResolvePassData->mParsers[0]; - bool didWork = false; - + bool didWork = false; + //for (auto itr = mReifyModuleWorkList.begin(); itr != mReifyModuleWorkList.end(); ) for (int workIdx = 0; workIdx < mReifyModuleWorkList.size(); workIdx++) { - BP_ZONE("PWL_ReifyModule"); + BP_ZONE("PWL_ReifyModule"); if (IsCancellingAndYield()) - break; - + break; + BfModule* module = mReifyModuleWorkList[workIdx]; if (module == NULL) { @@ -382,7 +382,7 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) didWork = true; } - + // Do this before mPopulateTypeWorkList so we can populate any types that need rebuilding // in the mPopulateTypeWorkList loop next - this is required for mFinishedModuleWorkList handling for (int workIdx = 0; workIdx < (int)mMidCompileWorkList.size(); workIdx++) @@ -424,7 +424,7 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) { //BP_ZONE("PWL_PopulateType"); if (IsCancellingAndYield()) - break; + break; auto workItemRef = mPopulateTypeWorkList[workIdx]; if (workItemRef == NULL) @@ -437,25 +437,25 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) bool rebuildType = workItemRef->mRebuildType; if ((onlyReifiedTypes) && (!type->IsReified())) - { + { continue; } auto typeInst = type->ToTypeInstance(); if ((typeInst != NULL) && (resolveParser != NULL)) - { + { if (!typeInst->mTypeDef->GetLatest()->HasSource(resolveParser)) - { + { continue; } - } - + } + workIdx = mPopulateTypeWorkList.RemoveAt(workIdx); - + if (rebuildType) RebuildType(type); - BF_ASSERT(this == type->mContext); + BF_ASSERT(this == type->mContext); auto useModule = type->GetModule(); if (useModule == NULL) { @@ -469,7 +469,7 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) mCompiler->mStats.mQueuedTypesProcessed++; mCompiler->UpdateCompletion(); didWork = true; - } + } for (int workIdx = 0; workIdx < (int)mTypeRefVerifyWorkList.size(); workIdx++) { @@ -481,7 +481,7 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) { workIdx = mTypeRefVerifyWorkList.RemoveAt(workIdx); continue; - } + } SetAndRestoreValue prevTypeInstance(workItemRef->mFromModule->mCurTypeInstance, workItemRef->mCurTypeInstance); @@ -508,14 +508,14 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) { if (IsCancellingAndYield()) break; - + auto workItemRef = mMethodSpecializationWorkList[workIdx]; if ((workItemRef == NULL) || (!IsWorkItemValid(workItemRef))) { workIdx = mMethodSpecializationWorkList.RemoveAt(workIdx); continue; } - + if (wantsReified != workItemRef->mFromModule->mIsReified) continue; @@ -523,9 +523,9 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) auto module = workItemRef->mFromModule; workIdx = mMethodSpecializationWorkList.RemoveAt(workIdx); - + auto typeInst = methodSpecializationRequest.mType->ToTypeInstance(); - + if (typeInst->IsDeleting()) continue; @@ -551,14 +551,14 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) for (int workIdx = 0; workIdx < mMethodWorkList.size(); workIdx++) { - BP_ZONE("PWL_ProcessMethod"); - + BP_ZONE("PWL_ProcessMethod"); + mSystem->CheckLockYield(); - // Don't allow canceling out of the first pass - otherwise we'll just keep reprocessing the + // Don't allow canceling out of the first pass - otherwise we'll just keep reprocessing the // head of the file over and over if ((resolveParser == NULL) && (mCompiler->mCanceling)) - break; - + break; + auto workItem = mMethodWorkList[workIdx]; if (workItem == NULL) { @@ -569,9 +569,9 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) intptr prevPopulateTypeWorkListSize = mPopulateTypeWorkList.size(); intptr prevInlineMethodWorkListSize = mInlineMethodWorkList.size(); - auto module = workItem->mFromModule; + auto module = workItem->mFromModule; auto methodInstance = workItem->mMethodInstance; - + bool wantProcessMethod = methodInstance != NULL; if ((workItem->mFromModuleRebuildIdx != -1) && (workItem->mFromModuleRebuildIdx != module->mRebuildIdx)) wantProcessMethod = false; @@ -581,7 +581,7 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) wantProcessMethod = false; if (methodInstance != NULL) BF_ASSERT(methodInstance->mMethodProcessRequest == workItem); - + bool hasBeenProcessed = true; if (wantProcessMethod) { @@ -640,7 +640,7 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) if (!allow) continue; } - + hasBeenProcessed = methodInstance->mHasBeenProcessed; BF_ASSERT(module->mContext == this); @@ -651,7 +651,7 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) { if (!mCompiler->mIsResolveOnly) BF_ASSERT(!methodInstance->mIsReified || methodInstance->mDeclModule->mIsModuleMutable); - + if ((autoComplete != NULL) && (autoComplete->mModule == NULL)) { autoComplete->SetModule(methodInstance->mDeclModule); @@ -662,19 +662,19 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) ProcessMethod(methodInstance); } } - + workIdx = mMethodWorkList.RemoveAt(workIdx); - + if (methodInstance != NULL) methodInstance->mMethodProcessRequest = NULL; if ((!module->mAwaitingFinish) && (module->WantsFinishModule()) && (wantProcessMethod)) - { - BfLogSysM("Module finished: %p %s HadBuildErrors:%d\n", module, module->mModuleName.c_str(), module->mHadBuildError); - QueueFinishModule(module); + { + BfLogSysM("Module finished: %p %s HadBuildErrors:%d\n", module, module->mModuleName.c_str(), module->mHadBuildError); + QueueFinishModule(module); } - didWork = true; + didWork = true; } // for (int workIdx = 0; workIdx < (int)mFinishedSlotAwaitModuleWorkList.size(); workIdx++) @@ -685,13 +685,13 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) // workIdx = mFinishedSlotAwaitModuleWorkList.RemoveAt(workIdx); // continue; // } -// +// // auto module = moduleRef; // if (mCompiler->mMaxInterfaceSlots >= 0) -// { +// { // mFinishedModuleWorkList.Add(module); // } -// +// // workIdx = mFinishedSlotAwaitModuleWorkList.RemoveAt(workIdx); // didWork = true; // } @@ -711,7 +711,7 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) if (!module->mAwaitingFinish) { BfLogSysM("mFinishedModuleWorkList removing old:%p\n", module); - workIdx = mFinishedModuleWorkList.RemoveAt(workIdx); + workIdx = mFinishedModuleWorkList.RemoveAt(workIdx); continue; } @@ -727,8 +727,8 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) break; } - BP_ZONE("PWL_ProcessFinishedModule"); - + BP_ZONE("PWL_ProcessFinishedModule"); + bool hasUnfinishedSpecModule = false; for (auto& specModulePair : module->mSpecializedMethodModules) { @@ -738,10 +738,10 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) } if (hasUnfinishedSpecModule) - { + { continue; } - + if (!module->mIsSpecialModule) { module->Finish(); @@ -756,10 +756,10 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) for (int workIdx = 0; workIdx < (int)mInlineMethodWorkList.size(); workIdx++) { - BP_ZONE("PWL_ProcessMethod"); + BP_ZONE("PWL_ProcessMethod"); mSystem->CheckLockYield(); - // Don't allow canceling out of the first pass - otherwise we'll just keep reprocessing the + // Don't allow canceling out of the first pass - otherwise we'll just keep reprocessing the // head of the file over and over if ((resolveParser == NULL) && (mCompiler->mCanceling)) break; @@ -783,8 +783,8 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) BfLogSysM("Module %p inlining method %p into func:%p\n", module, methodInstance, workItem.mFunc); BfMethodInstance dupMethodInstance; - dupMethodInstance.CopyFrom(methodInstance); - dupMethodInstance.mIRFunction = workItem.mFunc; + dupMethodInstance.CopyFrom(methodInstance); + dupMethodInstance.mIRFunction = workItem.mFunc; dupMethodInstance.mIsReified = true; dupMethodInstance.mInCEMachine = false; // Only have the original one BF_ASSERT(module->mIsReified); // We should only bother inlining in reified modules @@ -803,14 +803,14 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) static int sMethodIdx = 0; module->mBfIRBuilder->Func_SetLinkage(workItem.mFunc, BfIRLinkageType_Internal); - + BF_ASSERT(module->mContext == this); BF_ASSERT(module->mIsModuleMutable); if ((wantProcessMethod) && (!module->mAwaitingFinish) && (module->WantsFinishModule())) { BfLogSysM("Module finished: %s (from inlining)\n", module->mModuleName.c_str()); - QueueFinishModule(module); + QueueFinishModule(module); } didWork = true; @@ -820,7 +820,7 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) { if ((mPopulateTypeWorkList.size() == 0) && (resolveParser == NULL)) { - BP_ZONE("PWL_CheckIncompleteGenerics"); + BP_ZONE("PWL_CheckIncompleteGenerics"); for (auto type : mResolvedTypes) { @@ -851,7 +851,7 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods) if (!didWork) break; didAnyWork = true; - } + } return didAnyWork; } @@ -865,9 +865,9 @@ void BfContext::HandleChangedTypeDef(BfTypeDef* typeDef, bool isAutoCompleteTemp return; if (typeDef->mDefState != BfTypeDef::DefState_Defined) - { - if (mCompiler->mResolvePassData->mIsClassifying) - { + { + if (mCompiler->mResolvePassData->mIsClassifying) + { auto _CheckSource = [&](BfTypeDef* checkTypeDef) { auto typeDecl = checkTypeDef->mTypeDeclaration; @@ -878,7 +878,7 @@ void BfContext::HandleChangedTypeDef(BfTypeDef* typeDef, bool isAutoCompleteTemp if (auto sourceClassifier = mCompiler->mResolvePassData->GetSourceClassifier(typeDecl)) { - SetAndRestoreValue prevSkipTypeDeclaration(sourceClassifier->mSkipTypeDeclarations, true); + SetAndRestoreValue prevSkipTypeDeclaration(sourceClassifier->mSkipTypeDeclarations, true); sourceClassifier->mSkipMethodInternals = isAutoCompleteTempType; sourceClassifier->Handle(typeDecl); } @@ -892,8 +892,8 @@ void BfContext::HandleChangedTypeDef(BfTypeDef* typeDef, bool isAutoCompleteTemp else { _CheckSource(typeDef); - } - } + } + } } if ((!typeDef->mIsPartial) && (!isAutoCompleteTempType)) @@ -910,7 +910,7 @@ void BfContext::HandleChangedTypeDef(BfTypeDef* typeDef, bool isAutoCompleteTemp BfType * BfContext::FindTypeById(int typeId) { for (auto type : mResolvedTypes) - { + { if (type->mTypeId == typeId) return type; } @@ -924,7 +924,7 @@ void BfContext::AddTypeToWorkList(BfType* type) BF_ASSERT((type->mRebuildFlags & BfTypeRebuildFlag_InTempPool) == 0); if ((type->mRebuildFlags & BfTypeRebuildFlag_AddedToWorkList) == 0) - { + { type->mRebuildFlags = (BfTypeRebuildFlags)(type->mRebuildFlags | BfTypeRebuildFlag_AddedToWorkList); BfTypeProcessRequest* typeProcessRequest = mPopulateTypeWorkList.Alloc(); @@ -939,22 +939,22 @@ void BfContext::ValidateDependencies() #if _DEBUG // BP_ZONE("BfContext::ValidateDependencies"); // BfLogSysM("ValidateDependencies\n"); -// +// // bool deletedNewTypes = false; -// for (auto type : mResolvedTypes) -// { +// for (auto type : mResolvedTypes) +// { // if (type->IsDeleting()) // continue; -// +// // if (type->IsGenericTypeInstance()) // { // // We can't contain deleted generic arguments without being deleted ourselves // BfTypeInstance* genericType = (BfTypeInstance*)type; -// +// // for (auto genericTypeArg : genericType->mGenericTypeInfo->mTypeGenericArguments) // { // BF_ASSERT((!genericTypeArg->IsDeleting())); -// +// // auto argDepType = genericTypeArg->ToDependedType(); // if (argDepType != NULL) // { @@ -964,22 +964,22 @@ void BfContext::ValidateDependencies() // BF_ASSERT((depEntry->mFlags & BfDependencyMap::DependencyFlag_TypeGenericArg) != 0); // } // } -// } +// } // } #endif } void BfContext::RebuildType(BfType* type, bool deleteOnDemandTypes, bool rebuildModule, bool placeSpecializiedInPurgatory) { - BfTypeInstance* typeInst = type->ToTypeInstance(); - + BfTypeInstance* typeInst = type->ToTypeInstance(); + if (type->IsDeleting()) { return; } - + type->mDirty = true; - + bool wantDeleteType = (type->IsOnDemand()) && (deleteOnDemandTypes); if (type->IsConstExprValue()) { @@ -998,14 +998,14 @@ void BfContext::RebuildType(BfType* type, bool deleteOnDemandTypes, bool rebuild } if (typeInst == NULL) - { + { type->mDefineState = BfTypeDefineState_Undefined; BfTypeProcessRequest* typeProcessRequest = mPopulateTypeWorkList.Alloc(); - typeProcessRequest->mType = type; + typeProcessRequest->mType = type; mCompiler->mStats.mTypesQueued++; mCompiler->UpdateCompletion(); - + return; } @@ -1026,12 +1026,12 @@ void BfContext::RebuildType(BfType* type, bool deleteOnDemandTypes, bool rebuild } if ((typeInst->IsTypeAlias()) != (typeInst->mTypeDef->mTypeCode == BfTypeCode_TypeAlias)) - { + { BfLogSysM("TypeAlias %p status changed - deleting\n", typeInst); DeleteType(type); - return; + return; } - + if ((typeInst->IsBoxed()) && (typeInst->mTypeDef->mEmitParent != NULL)) typeInst->mTypeDef = typeInst->mTypeDef->mEmitParent; @@ -1044,18 +1044,18 @@ void BfContext::RebuildType(BfType* type, bool deleteOnDemandTypes, bool rebuild { // The type definition failed, so we need to rebuild everyone that was depending on us RebuildDependentTypes(typeInst); - } - + } + if (typeInst->mTypeDef->GetDefinition()->mDefState == BfTypeDef::DefState_Deleted) - return; - + return; + if (typeInst->mDefineState == BfTypeDefineState_Undefined) { // If we haven't added this type the worklist yet then we reprocess the type rebuilding if ((typeInst->mRebuildFlags & BfTypeRebuildFlag_AddedToWorkList) != 0) - return; - } - + return; + } + if (typeInst->mIsReified) mHasReifiedQueuedRebuildTypes = true; @@ -1067,12 +1067,12 @@ void BfContext::RebuildType(BfType* type, bool deleteOnDemandTypes, bool rebuild mCompiler->mGenericInstancePurgatory.push_back(typeInst); addToWorkList = false; } - + String typeName = mScratchModule->TypeToString(typeInst, BfTypeNameFlags_None); BfLogSysM("%p Rebuild Type: %p %s deleted:%d\n", this, typeInst, typeName.c_str(), typeInst->IsDeleting()); if (addToWorkList) { - AddTypeToWorkList(typeInst); + AddTypeToWorkList(typeInst); } // Why did we need to do this? This caused all struct types to be rebuilt when we needed to rebuild ValueType due to @@ -1089,7 +1089,7 @@ void BfContext::RebuildType(BfType* type, bool deleteOnDemandTypes, bool rebuild RebuildType(dependentType); } }*/ - + if ((mCompiler->IsHotCompile()) && (!typeInst->IsTypeAlias())) { BF_ASSERT(typeInst->mHotTypeData != NULL); @@ -1110,7 +1110,7 @@ void BfContext::RebuildType(BfType* type, bool deleteOnDemandTypes, bool rebuild typeInst->mHotTypeData = NULL; } - auto typeDef = typeInst->mTypeDef; + auto typeDef = typeInst->mTypeDef; // Process deps before clearing mMethodInstanceGroups, to make sure we delete any methodrefs pointing to us before // deleting those methods @@ -1134,7 +1134,7 @@ void BfContext::RebuildType(BfType* type, bool deleteOnDemandTypes, bool rebuild { // Rebuild undefined type. This isn't necessary when we modify the typeDef, but when we change configurations then // the specialized types will rebuild - + //TODO: WE just added "no rebuild module" to this. I'm not sure what this is all about anyway... RebuildType(depType, true, false); } @@ -1161,7 +1161,7 @@ void BfContext::RebuildType(BfType* type, bool deleteOnDemandTypes, bool rebuild auto methodInstance = methodSpecializationItr.mValue; if ((!methodInstance->mIsUnspecialized) && (methodInstance->mHasFailed)) { - // A specialized generic method has failed, but the unspecialized version did not. This + // A specialized generic method has failed, but the unspecialized version did not. This // can only happen for 'var' constrained methods, and we need to cause all referring // types to rebuild to ensure we're really specializing only the correct methods needMethodCallsRebuild = true; @@ -1170,14 +1170,14 @@ void BfContext::RebuildType(BfType* type, bool deleteOnDemandTypes, bool rebuild } } if (needMethodCallsRebuild) - { - TypeMethodSignaturesChanged(typeInst); + { + TypeMethodSignaturesChanged(typeInst); } } } typeInst->ReleaseData(); - type->mDefineState = BfTypeDefineState_Undefined; + type->mDefineState = BfTypeDefineState_Undefined; typeInst->mSpecializedMethodReferences.Clear(); typeInst->mAlwaysIncludeFlags = BfAlwaysIncludeFlag_None; typeInst->mHasBeenInstantiated = false; @@ -1195,14 +1195,14 @@ void BfContext::RebuildType(BfType* type, bool deleteOnDemandTypes, bool rebuild typeInst->mHasBeenInstantiated = false; typeInst->mHasParameterizedBase = false; typeInst->mTypeFailed = false; - typeInst->mTypeWarned = false; + typeInst->mTypeWarned = false; typeInst->mHasUnderlyingArray = false; - typeInst->mHasPackingHoles = false; + typeInst->mHasPackingHoles = false; typeInst->mWantsGCMarking = false; typeInst->mHasDeclError = false; delete typeInst->mTypeInfoEx; typeInst->mTypeInfoEx = NULL; - + if (typeInst->mCeTypeInfo != NULL) typeInst->mCeTypeInfo->mRebuildMap.Clear(); @@ -1229,7 +1229,7 @@ void BfContext::RebuildType(BfType* type, bool deleteOnDemandTypes, bool rebuild RebuildType(typeInst); } } - } + } } //typeInst->mTypeDef->ClearEmitted(); @@ -1250,7 +1250,7 @@ void BfContext::RebuildType(BfType* type, bool deleteOnDemandTypes, bool rebuild if (genericTypeInstance->mGenericTypeInfo->mGenericExtensionInfo != NULL) genericTypeInstance->mGenericTypeInfo->mGenericExtensionInfo->Clear(); genericTypeInstance->mGenericTypeInfo->mProjectsReferenced.Clear(); - } + } typeInst->mStaticSearchMap.Clear(); typeInst->mInternalAccessMap.Clear(); @@ -1272,7 +1272,7 @@ void BfContext::RebuildType(BfType* type, bool deleteOnDemandTypes, bool rebuild delete typeInst->mCustomAttributes; typeInst->mCustomAttributes = NULL; delete typeInst->mAttributeData; - typeInst->mAttributeData = NULL; + typeInst->mAttributeData = NULL; typeInst->mVirtualMethodTableSize = 0; typeInst->mVirtualMethodTable.Clear(); typeInst->mReifyMethodDependencies.Clear(); @@ -1286,9 +1286,9 @@ void BfContext::RebuildType(BfType* type, bool deleteOnDemandTypes, bool rebuild if ((typeInst->mModule != NULL) && (rebuildModule)) { - typeInst->mModule->StartNewRevision(); + typeInst->mModule->StartNewRevision(); typeInst->mRevision = mCompiler->mRevision; - } + } } void BfContext::RebuildDependentTypes(BfDependedType* dType) @@ -1317,7 +1317,7 @@ void BfContext::RebuildDependentTypes_MidCompile(BfDependedType* dType, const St BF_ASSERT(!module->mIsDeleting); BF_ASSERT(!module->mOwnedTypeInstances.IsEmpty()); } - + mCompiler->mStats.mMidCompileRebuilds++; dType->mRebuildFlags = (BfTypeRebuildFlags)(dType->mRebuildFlags | BfTypeRebuildFlag_ChangedMidCompile); int prevDeletedTypes = mCompiler->mStats.mTypesDeleted; @@ -1332,13 +1332,12 @@ void BfContext::RebuildDependentTypes_MidCompile(BfDependedType* dType, const St mCompiler->mNeedsFullRefresh = true; mCompiler->mLastMidCompileRefreshRevision = mCompiler->mRevision; } - } BfLogSysM("Rebuilding dependent types MidCompile Type:%p Reason:%s\n", dType, reason.c_str()); RebuildDependentTypes(dType); if (mCompiler->mStats.mTypesDeleted != prevDeletedTypes) - { + { BfLogSysM("Rebuilding dependent types MidCompile Type:%p Reason:%s - updating after deleting types\n", dType, reason.c_str()); UpdateAfterDeletingTypes(); } @@ -1365,20 +1364,20 @@ bool BfContext::CanRebuild(BfType* type) // (obviously) doesn't change the data layout of ClassC // Calls: non-cascading dependency, since it's independent of data layout ConstValue: non-cascading data change void BfContext::TypeDataChanged(BfDependedType* dType, bool isNonStaticDataChange) -{ +{ BfLogSysM("TypeDataChanged %p\n", dType); - + auto rebuildFlag = isNonStaticDataChange ? BfTypeRebuildFlag_NonStaticChange : BfTypeRebuildFlag_StaticChange; if ((dType->mRebuildFlags & rebuildFlag) != 0) // Already did this change? return; dType->mRebuildFlags = (BfTypeRebuildFlags)(dType->mRebuildFlags | rebuildFlag); - + // We need to rebuild all other types that rely on our data layout for (auto& depItr : dType->mDependencyMap) { auto dependentType = depItr.mKey; auto dependencyFlags = depItr.mValue.mFlags; - + auto dependentDType = dependentType->ToDependedType(); if (dependentDType != NULL) { @@ -1387,16 +1386,16 @@ void BfContext::TypeDataChanged(BfDependedType* dType, bool isNonStaticDataChang { bool hadChange = false; - if ((dependencyFlags & + if ((dependencyFlags & (BfDependencyMap::DependencyFlag_DerivedFrom | BfDependencyMap::DependencyFlag_ValueTypeMemberData | BfDependencyMap::DependencyFlag_NameReference | BfDependencyMap::DependencyFlag_ValueTypeSizeDep)) != 0) { - hadChange = true; + hadChange = true; } - // This case is for when we were declared as a class on a previous compilation, + // This case is for when we were declared as a class on a previous compilation, // but then we were changed to a struct if ((dType->IsValueType()) && (dependencyFlags & BfDependencyMap::DependencyFlag_PtrMemberData)) @@ -1420,15 +1419,15 @@ void BfContext::TypeDataChanged(BfDependedType* dType, bool isNonStaticDataChang if (dependencyFlags & BfDependencyMap::DependencyFlag_ConstValue) { TypeDataChanged(dependentDType, false); - + // The ConstValue dependency may be that dependentType used one of our consts as // a default value to a method param, so assume callsites need rebuilding if (dependentTypeInstance != NULL) TypeMethodSignaturesChanged(dependentTypeInstance); } - if (CanRebuild(dependentType)) - { + if (CanRebuild(dependentType)) + { // We need to include DependencyFlag_ParamOrReturnValue because it could be a struct that changes its splatting ability // We can't ONLY check against structs, though, because a type could change from a class to a struct if (dependencyFlags & @@ -1438,7 +1437,7 @@ void BfContext::TypeDataChanged(BfDependedType* dType, bool isNonStaticDataChang { RebuildType(dependentType); } - else if (((dependencyFlags & BfDependencyMap::DependencyFlag_NameReference) != 0) && + else if (((dependencyFlags & BfDependencyMap::DependencyFlag_NameReference) != 0) && ((dType->mRebuildFlags & BfTypeRebuildFlag_ChangedMidCompile) != 0) && (dType->IsTypeAlias())) { @@ -1455,9 +1454,9 @@ void BfContext::TypeDataChanged(BfDependedType* dType, bool isNonStaticDataChang } } } - + if (CanRebuild(dType)) - RebuildType(dType); + RebuildType(dType); } void BfContext::TypeMethodSignaturesChanged(BfTypeInstance* typeInst) @@ -1501,7 +1500,7 @@ void BfContext::TypeInlineMethodInternalsChanged(BfTypeInstance* typeInst) for (auto& depItr : typeInst->mDependencyMap) { auto dependentType = depItr.mKey; - + auto dependencyFlags = depItr.mValue.mFlags; if (dependentType->mRevision != mCompiler->mRevision) @@ -1558,7 +1557,7 @@ void BfContext::TypeConstEvalFieldChanged(BfTypeInstance* typeInst) { auto dependentType = depItr.mKey; auto dependencyFlags = depItr.mValue.mFlags; - + if ((dependencyFlags & BfDependencyMap::DependencyFlag_ConstEvalConstField) != 0) { auto depTypeInst = dependentType->ToTypeInstance(); @@ -1581,12 +1580,12 @@ void BfContext::PopulateHotTypeDataVTable(BfTypeInstance* typeInstance) auto hotTypeData = typeInstance->mHotTypeData; if (hotTypeData == NULL) return; - - if (typeInstance->IsIncomplete()) + + if (typeInstance->IsIncomplete()) return; if (hotTypeData->mVTableOrigLength == -1) - { + { auto committedHotTypeVersion = typeInstance->mHotTypeData->GetTypeVersion(mCompiler->mHotState->mCommittedHotCompileIdx); if (committedHotTypeVersion != NULL) { @@ -1594,7 +1593,7 @@ void BfContext::PopulateHotTypeDataVTable(BfTypeInstance* typeInstance) hotTypeData->mOrigInterfaceMethodsLength = typeInstance->GetIFaceVMethodSize(); } BfLogSysM("PopulateHotTypeDataVTable set %p HotDataType->mVTableOrigLength To %d\n", typeInstance, hotTypeData->mVTableOrigLength); - } + } int vTableStart = -1; int primaryVTableSize = 0; @@ -1609,8 +1608,8 @@ void BfContext::PopulateHotTypeDataVTable(BfTypeInstance* typeInstance) { auto& methodRef = typeInstance->mVirtualMethodTable[vIdx].mDeclaringMethod; if (methodRef.mMethodNum == -1) - { - BF_DBG_FATAL("Shouldn't have vext marker"); + { + BF_DBG_FATAL("Shouldn't have vext marker"); } } #endif @@ -1637,11 +1636,11 @@ void BfContext::PopulateHotTypeDataVTable(BfTypeInstance* typeInstance) primaryVTableSize = (int)typeInstance->mVirtualMethodTable.size() - vTableStart; BF_ASSERT(vTableStart != -1); - + if (primaryVTableSize > (int)hotTypeData->mVTableEntries.size()) hotTypeData->mVTableEntries.Resize(primaryVTableSize); - int methodIdx = -1; + int methodIdx = -1; for (int vIdx = 0; vIdx < primaryVTableSize; vIdx++) { auto& methodRef = typeInstance->mVirtualMethodTable[vTableStart + vIdx].mDeclaringMethod; @@ -1649,7 +1648,7 @@ void BfContext::PopulateHotTypeDataVTable(BfTypeInstance* typeInstance) auto methodInstance = (BfMethodInstance*)methodRef; if (methodInstance == NULL) continue; - + BF_ASSERT(methodRef.mTypeInstance == typeInstance); BF_ASSERT(methodInstance->mVirtualTableIdx != -1); BF_ASSERT(!methodInstance->mMethodDef->mIsOverride); @@ -1667,7 +1666,7 @@ void BfContext::PopulateHotTypeDataVTable(BfTypeInstance* typeInstance) auto& entry = hotTypeData->mVTableEntries[vIdx]; if (entry.mFuncName.empty()) - { + { entry.mFuncName = methodInstance->mMethodInfoEx->mMangledName; } else @@ -1700,7 +1699,7 @@ void BfContext::SaveDeletingType(BfType* type) else { // This can happen if we have a conflicting type definition - savedTypeData = *savedTypeDataPtr; + savedTypeData = *savedTypeDataPtr; } savedTypeData->mTypeId = type->mTypeId; while ((int)mSavedTypeData.size() <= savedTypeData->mTypeId) @@ -1709,7 +1708,7 @@ void BfContext::SaveDeletingType(BfType* type) auto typeInst = type->ToTypeInstance(); if (typeInst != NULL) - { + { delete savedTypeData->mHotTypeData; if (mCompiler->IsHotCompile()) savedTypeData->mHotTypeData = typeInst->mHotTypeData; @@ -1799,13 +1798,13 @@ void BfContext::ReflectInit() void BfContext::DeleteType(BfType* type, bool deferDepRebuilds) { if (type == mBfObjectType) - mBfObjectType = NULL; - if (type == mBfTypeType) + mBfObjectType = NULL; + if (type == mBfTypeType) mBfObjectType = NULL; if (type->mRebuildFlags & BfTypeRebuildFlag_Deleted) - return; - + return; + mCompiler->mDepsMayHaveDeletedTypes = true; mCompiler->mStats.mTypesDeleted++; @@ -1831,7 +1830,7 @@ void BfContext::DeleteType(BfType* type, bool deferDepRebuilds) BF_ASSERT(module->mOwnedTypeInstances.size() == 0); } else - { + { module->mOwnedTypeInstances.Remove(typeInst); if ((module->mOwnedTypeInstances.size() == 0) && (module != mScratchModule)) @@ -1842,22 +1841,22 @@ void BfContext::DeleteType(BfType* type, bool deferDepRebuilds) module->RemoveModuleData(); module->mIsDeleting = true; mModules.Remove(module); - + // This was only needed for 'zombie modules', which we don't need anymore? // To avoid linking errors. Used instead of directly removing from mModules. mDeletingModules.Add(module); } } } - } + } type->mRebuildFlags = (BfTypeRebuildFlags)((type->mRebuildFlags | BfTypeRebuildFlag_Deleted) & ~BfTypeRebuildFlag_DeleteQueued); SaveDeletingType(type); - + mTypes[type->mTypeId] = NULL; BfLogSysM("Deleting Type: %p %s\n", type, mScratchModule->TypeToString(type).c_str()); - + if (typeInst != NULL) { for (auto& methodInstGroup : typeInst->mMethodInstanceGroups) @@ -1876,28 +1875,28 @@ void BfContext::DeleteType(BfType* type, bool deferDepRebuilds) } } - // All dependencies cause rebuilds when we delete types + // All dependencies cause rebuilds when we delete types if (dType != NULL) { //TODO: Do PopulateHotTypeDataVTable then store the HotTypeDataData - + if (dType->IsUnspecializedType()) - { + { /*auto itr = mScratchModule->mClassVDataRefs.find(typeInst); if (itr != mScratchModule->mClassVDataRefs.end()) mScratchModule->mClassVDataRefs.erase(itr);*/ - + mScratchModule->mClassVDataRefs.Remove(typeInst); - } - + } + //UH - I think this is not true. // If A derives from B, and C derives from B, if we delete 'A' then it's true that // 'C' won't rebuild otherwise, BUT 'B' would fail to build but it would do a TypeDataChanged once it WAS able to built. Right? // Even though we do rebuilds on all types below, we specifically need to call - // TypeDataChanged here for cascading data dependencies + // TypeDataChanged here for cascading data dependencies /*if (!deferDepRebuilds) TypeDataChanged(typeInst, true);*/ - + Array rebuildTypeQueue; for (auto& depItr : dType->mDependencyMap) @@ -1910,7 +1909,7 @@ void BfContext::DeleteType(BfType* type, bool deferDepRebuilds) if ((dependencyEntry.mFlags & (BfDependencyMap::DependencyFlag_MethodGenericArg)) != 0) { if (!dependentType->IsDeleting()) - { + { if ((deferDepRebuilds) && (dependentTypeInst != NULL)) mQueuedSpecializedMethodRebuildTypes.Add(dependentTypeInst); } @@ -1922,7 +1921,7 @@ void BfContext::DeleteType(BfType* type, bool deferDepRebuilds) DeleteType(dependentType, deferDepRebuilds); continue; } - + if (dependentTypeInst == NULL) { // This was something like a sized array @@ -1952,10 +1951,10 @@ void BfContext::DeleteType(BfType* type, bool deferDepRebuilds) { rebuildTypeQueue.Add(dependentType); } - } + } if (type->IsMethodRef()) - { + { // Detach auto methodRefType = (BfMethodRefType*)type; BfMethodInstance* methodInstance = methodRefType->mMethodRef; @@ -1970,15 +1969,15 @@ void BfContext::DeleteType(BfType* type, bool deferDepRebuilds) if (CanRebuild(dependentType)) RebuildType(dependentType); } - } + } } void BfContext::UpdateAfterDeletingTypes() { BP_ZONE("BfContext::UpdateAfterDeletingTypes"); BfLogSysM("UpdateAfterDeletingTypes\n"); - - int graveyardStart = (int)mTypeGraveyard.size(); + + int graveyardStart = (int)mTypeGraveyard.size(); while (true) { @@ -1999,11 +1998,11 @@ void BfContext::UpdateAfterDeletingTypes() deletedNewTypes = true; isDeleting = true; DeleteType(type); - } + } } if (isDeleting) - { + { doDelete = true; } else @@ -2054,14 +2053,14 @@ void BfContext::UpdateAfterDeletingTypes() // ++itr; // } #endif - + if (!mCompiler->mIsResolveOnly) { BP_ZONE("BfContext::UpdateAfterDeletingTypes saving typeData"); for (int graveyardIdx = graveyardStart; graveyardIdx < (int)mTypeGraveyard.size(); graveyardIdx++) { - auto type = mTypeGraveyard[graveyardIdx]; - SaveDeletingType(type); + auto type = mTypeGraveyard[graveyardIdx]; + SaveDeletingType(type); } } } @@ -2077,22 +2076,21 @@ void BfContext::PreUpdateRevisedTypes() // auto typeInst = type->ToTypeInstance(); // if (typeInst == NULL) // continue; -// +// // auto typeDef = typeInst->mTypeDef; // if ((typeDef->mDefState != BfTypeDef::DefState_New) && (typeDef->mDefState != BfTypeDef::DefState_Defined)) // { // if (typeInst->mHotTypeData == NULL) // { -// typeInst->mHotTypeData = new BfHotTypeData(); -// typeInst->CalcHotVirtualData(&typeInst->mHotTypeData->mInterfaceMapping); +// typeInst->mHotTypeData = new BfHotTypeData(); +// typeInst->CalcHotVirtualData(&typeInst->mHotTypeData->mInterfaceMapping); // } // PopulateHotTypeDataVTable(typeInst); // } -// } +// } // } } - // Note that this method can also cause modules to be build in other contexts. // That's why we do our UpdateAfterDeletingTypes after all the contexts' UpdateRevisedTypes void BfContext::UpdateRevisedTypes() @@ -2133,7 +2131,7 @@ void BfContext::UpdateRevisedTypes() { BfTypeDef* typeDef = *itr; if ((typeDef->mDefState != BfTypeDef::DefState_Deleted) && - (!typeDef->mIsCombinedPartial)) + (!typeDef->mIsCombinedPartial)) { if (typeDef->mFullNameEx == qualifiedFindName) if (!_CheckCanSkipCtor(typeDef)) @@ -2144,7 +2142,7 @@ void BfContext::UpdateRevisedTypes() return true; }; - + bool wantsCanSkipObjectCtor = _CheckCanSkipCtorByName("System.Object"); bool wantsCanSkipValueTypeCtor = _CheckCanSkipCtorByName("System.ValueType"); @@ -2166,7 +2164,7 @@ void BfContext::UpdateRevisedTypes() auto uintPtrType = mScratchModule->GetPrimitiveType(BfTypeCode_UIntPtr); if (intPtrType != NULL) { - RebuildType(intPtrType); + RebuildType(intPtrType); mScratchModule->PopulateType(intPtrType); } if (uintPtrType != NULL) @@ -2177,17 +2175,17 @@ void BfContext::UpdateRevisedTypes() // Rebuild all types for (auto type : mResolvedTypes) - { + { RebuildType(type); } } // Temporarily store failTypes - we may need to re-insert into them after another failure auto failTypes = mFailTypes; - mFailTypes.Clear(); + mFailTypes.Clear(); bool wantsDebugInfo = (mCompiler->mOptions.mEmitDebugInfo); - + Array defStateChangedQueue; Array defEmitParentCheckQueue; @@ -2207,22 +2205,22 @@ void BfContext::UpdateRevisedTypes() /*if ((!mCompiler->mIsResolveOnly) && (!type->IsNull()) && (!type->IsUnspecializedType())) { - // We need to completely rebuild all types if we switch from having debug info to not having debug info - if ((typeInst != NULL) && (typeInst->mModule != NULL) && (typeInst->mModule->mHasDebugInfo != wantsDebugInfo)) + // We need to completely rebuild all types if we switch from having debug info to not having debug info + if ((typeInst != NULL) && (typeInst->mModule != NULL) && (typeInst->mModule->mHasDebugInfo != wantsDebugInfo)) { RebuildType(type); } }*/ - + if (typeInst == NULL) continue; - + if (typeInst->IsDeleting()) continue; - auto typeDef = typeInst->mTypeDef; + auto typeDef = typeInst->mTypeDef; - if (typeDef->mEmitParent != NULL) + if (typeDef->mEmitParent != NULL) defEmitParentCheckQueue.Add(typeInst); if (typeDef->mProject->mDisabled) @@ -2230,10 +2228,10 @@ void BfContext::UpdateRevisedTypes() DeleteType(type); continue; } - + // Clear flags we don't want to propagate typeInst->mRebuildFlags = (BfTypeRebuildFlags)(typeInst->mRebuildFlags & (BfTypeRebuildFlag_UnderlyingTypeDeferred | BfTypeRebuildFlag_PendingGenericArgDep)); - + if (typeDef->mIsPartial) { // This was a type that wasn't marked as partial before but now it is, so it doesn't need its own typedef @@ -2260,7 +2258,7 @@ void BfContext::UpdateRevisedTypes() if (*valuePtr != kv.mValue.mInt) changed = true; mCompiler->mRebuildFileSet.Add(kv.mKey.mString); - } + } if ((kv.mKey.mKind == CeRebuildKey::Kind_File) || (kv.mKey.mKind == CeRebuildKey::Kind_Directory)) { @@ -2300,7 +2298,7 @@ void BfContext::UpdateRevisedTypes() if (checkTypeDef->mDefState != BfTypeDef::DefState_New) { - defStateChangedQueue.Add(typeInst); + defStateChangedQueue.Add(typeInst); } } @@ -2313,7 +2311,7 @@ void BfContext::UpdateRevisedTypes() auto typeDef = typeInst->mTypeDef; - bool isTypeDefinedInContext = true; + bool isTypeDefinedInContext = true; if (typeDef->mEmitParent != NULL) { @@ -2321,12 +2319,12 @@ void BfContext::UpdateRevisedTypes() } if (typeDef->mDefState == BfTypeDef::DefState_Deleted) - { + { HandleChangedTypeDef(typeDef); DeleteType(typeInst); continue; } - + if (typeDef->mDefState == BfTypeDef::DefState_InlinedInternals_Changed) { TypeInlineMethodInternalsChanged(typeInst); @@ -2357,7 +2355,7 @@ void BfContext::UpdateRevisedTypes() RebuildType(typeInst); } - + for (auto typeInst : failTypes) { if (!typeInst->IsDeleting()) @@ -2400,7 +2398,7 @@ void BfContext::UpdateRevisedTypes() AutoCrit autoCrit(mSystem->mDataLock); auto options = &mCompiler->mOptions; - HashContext workspaceConfigHashCtx; + HashContext workspaceConfigHashCtx; workspaceConfigHashCtx.MixinStr(options->mTargetTriple); workspaceConfigHashCtx.MixinStr(options->mTargetCPU); @@ -2408,15 +2406,15 @@ void BfContext::UpdateRevisedTypes() workspaceConfigHashCtx.Mixin(options->mMachineType); workspaceConfigHashCtx.Mixin(options->mToolsetType); - workspaceConfigHashCtx.Mixin(options->mSIMDSetting); + workspaceConfigHashCtx.Mixin(options->mSIMDSetting); workspaceConfigHashCtx.Mixin(options->mEmitDebugInfo); - workspaceConfigHashCtx.Mixin(options->mEmitLineInfo); + workspaceConfigHashCtx.Mixin(options->mEmitLineInfo); workspaceConfigHashCtx.Mixin(options->mNoFramePointerElim); workspaceConfigHashCtx.Mixin(options->mInitLocalVariables); workspaceConfigHashCtx.Mixin(options->mRuntimeChecks); - workspaceConfigHashCtx.Mixin(options->mAllowStructByVal); + workspaceConfigHashCtx.Mixin(options->mAllowStructByVal); workspaceConfigHashCtx.Mixin(options->mEmitDynamicCastCheck); workspaceConfigHashCtx.Mixin(options->mAllowHotSwapping); @@ -2456,7 +2454,7 @@ void BfContext::UpdateRevisedTypes() workspaceConfigHashCtx.Mixin(typeOptions.mOrFlags); workspaceConfigHashCtx.Mixin(typeOptions.mReflectMethodFilters.size()); for (auto& filter : typeOptions.mReflectMethodFilters) - { + { workspaceConfigHashCtx.MixinStr(filter.mFilter); workspaceConfigHashCtx.Mixin(filter.mAndFlags); workspaceConfigHashCtx.Mixin(filter.mOrFlags); @@ -2486,23 +2484,23 @@ void BfContext::UpdateRevisedTypes() mSystem->mMergedTypeOptions.Clear(); mSystem->mWorkspaceConfigHash = workspaceConfigHash; } - + for (auto project : mSystem->mProjects) { HashContext buildConfigHashCtx; buildConfigHashCtx.Mixin(workspaceConfigHash); - + if (!mCompiler->mIsResolveOnly) { - auto& codeGenOptions = project->mCodeGenOptions; - + auto& codeGenOptions = project->mCodeGenOptions; + buildConfigHashCtx.MixinStr(mCompiler->mOutputDirectory); buildConfigHashCtx.Mixin(project->mAlwaysIncludeAll); buildConfigHashCtx.Mixin(project->mSingleModule); bool isTestConfig = project->mTargetType == BfTargetType_BeefTest; buildConfigHashCtx.Mixin(isTestConfig); - + buildConfigHashCtx.Mixin(codeGenOptions.mOptLevel); buildConfigHashCtx.Mixin(codeGenOptions.mSizeLevel); buildConfigHashCtx.Mixin(codeGenOptions.mUseCFLAA); @@ -2548,18 +2546,18 @@ void BfContext::UpdateRevisedTypes() auto vDataConfigHash = vDataConfigHashCtx.Finish128(); project->mBuildConfigChanged = buildConfigHash != project->mBuildConfigHash; - project->mBuildConfigHash = buildConfigHash; + project->mBuildConfigHash = buildConfigHash; project->mVDataConfigHash = vDataConfigHash; } - } - + } + Array moduleRebuildList; for (int moduleIdx = 0; moduleIdx < (int)mModules.size(); moduleIdx++) { //mCompiler->mOutputDirectory auto module = mModules[moduleIdx]; - + // This logic needs to run on both us and our mOptModule //for (int subModuleIdx = 0; subModuleIdx < 2; subModuleIdx++) auto subModule = module; @@ -2591,7 +2589,7 @@ void BfContext::UpdateRevisedTypes() subModule = subModule->mNextAltModule; } - + if ((module->mProject != NULL) && (module->mProject->mDisabled)) { continue; @@ -2605,7 +2603,7 @@ void BfContext::UpdateRevisedTypes() needsModuleRebuild = true; } if (module->mProject != NULL) - { + { if ((module->mIsHotModule) && (mCompiler->mOptions.mHotProject == NULL)) needsModuleRebuild = true; if (module->mProject->mBuildConfigChanged) @@ -2619,11 +2617,11 @@ void BfContext::UpdateRevisedTypes() } if (needsModuleRebuild) - moduleRebuildList.push_back(module); + moduleRebuildList.push_back(module); if (module->mIsSpecialModule) // vdata, external, data continue; - + bool wantMethodSpecializations = !mCompiler->mIsResolveOnly; // We don't really need this on for resolveOnly passes, but this is useful to force on for debugging. @@ -2645,7 +2643,7 @@ void BfContext::UpdateRevisedTypes() if (mSystem->mWorkspaceConfigChanged) { for (auto type : mResolvedTypes) - { + { RebuildType(type); } } @@ -2657,7 +2655,7 @@ void BfContext::VerifyTypeLookups(BfTypeInstance* typeInst) { BfTypeLookupEntry& lookupEntry = lookupEntryPair.mKey; bool isDirty = false; - if (lookupEntry.mName.IsEmpty()) + if (lookupEntry.mName.IsEmpty()) { // If the name lookup failed before, thats because we didn't have the right atoms. Are there new atoms now? if (lookupEntry.mAtomUpdateIdx != mSystem->mAtomUpdateIdx) @@ -2667,10 +2665,10 @@ void BfContext::VerifyTypeLookups(BfTypeInstance* typeInst) { // If any atoms have been placed in the graveyard, typesHash will be zero and thus cause a rebuild uint32 atomUpdateIdx = lookupEntry.mName.GetAtomUpdateIdx(); - + if (atomUpdateIdx == 0) { - isDirty = true; + isDirty = true; } else { @@ -2703,10 +2701,10 @@ void BfContext::VerifyTypeLookups(BfTypeInstance* typeInst) lookupEntry.mAtomUpdateIdx = atomUpdateIdx; } } - } + } if (isDirty) - { + { // Clear lookup results to avoid infinite recursion typeInst->mLookupResults.Clear(); @@ -2733,7 +2731,7 @@ void BfContext::GenerateModuleName_TypeInst(BfTypeInstance* typeInst, StringImpl name += '_';*/ } else - { + { for (int i = 0; i < typeInst->mTypeDef->mNamespace.mSize; i++) { auto atom = typeInst->mTypeDef->mNamespace.mParts[i]; @@ -2753,7 +2751,7 @@ void BfContext::GenerateModuleName_TypeInst(BfTypeInstance* typeInst, StringImpl if (typeInst->IsClosure()) { - auto closureType = (BfClosureType*)typeInst; + auto closureType = (BfClosureType*)typeInst; name += closureType->mNameAdd; return; } @@ -2795,14 +2793,14 @@ void BfContext::GenerateModuleName_Type(BfType* type, StringImpl& name) { auto ptrType = (BfPointerType*)type; name += "PTR_"; - GenerateModuleName_Type(ptrType->mElementType, name); + GenerateModuleName_Type(ptrType->mElementType, name); return; } if (type->IsTuple()) { auto tupleType = (BfTypeInstance*)type; - name += "TUPLE_"; + name += "TUPLE_"; for (int fieldIdx = 0; fieldIdx < (int)tupleType->mFieldInstances.size(); fieldIdx++) { BfFieldInstance* fieldInstance = &tupleType->mFieldInstances[fieldIdx]; @@ -2820,7 +2818,7 @@ void BfContext::GenerateModuleName_Type(BfType* type, StringImpl& name) auto typeInst = type->ToTypeInstance(); auto delegateInfo = type->GetDelegateInfo(); - auto methodDef = typeInst->mTypeDef->mMethods[0]; + auto methodDef = typeInst->mTypeDef->mMethods[0]; if (type->IsDelegateFromTypeRef()) name += "DELEGATE_"; @@ -2833,7 +2831,7 @@ void BfContext::GenerateModuleName_Type(BfType* type, StringImpl& name) if (paramIdx > 0) name += "_"; auto paramDef = methodDef->mParams[paramIdx]; - GenerateModuleName_Type(mScratchModule->ResolveTypeRef(paramDef->mTypeRef), name); + GenerateModuleName_Type(mScratchModule->ResolveTypeRef(paramDef->mTypeRef), name); name += "_"; name += paramDef->mName; } @@ -2866,7 +2864,7 @@ void BfContext::GenerateModuleName_Type(BfType* type, StringImpl& name) else name += StrFormat("%ld", constExprType->mValue.mInt64); return; - } + } } auto typeInst = type->ToTypeInstance(); @@ -2874,11 +2872,11 @@ void BfContext::GenerateModuleName_Type(BfType* type, StringImpl& name) { GenerateModuleName_TypeInst(typeInst, name); return; - } + } } void BfContext::GenerateModuleName(BfTypeInstance* typeInst, StringImpl& name) -{ +{ GenerateModuleName_Type(typeInst, name); int maxChars = 80; @@ -2893,7 +2891,7 @@ void BfContext::GenerateModuleName(BfTypeInstance* typeInst, StringImpl& name) if (c == '@') name[i] = '_'; } - + for (int i = 2; true; i++) { StringT<256> upperName = name; @@ -2917,25 +2915,25 @@ bool BfContext::IsSentinelMethod(BfMethodInstance* methodInstance) void BfContext::VerifyTypeLookups() { - BP_ZONE("BfContext::VerifyTypeLookups"); + BP_ZONE("BfContext::VerifyTypeLookups"); for (auto type : mResolvedTypes) - { + { auto typeInst = type->ToTypeInstance(); if ((typeInst != NULL) && (!typeInst->IsDeleting()) && (!typeInst->IsIncomplete())) { - VerifyTypeLookups(typeInst); + VerifyTypeLookups(typeInst); } } } -// When we are rebuilding 'typeInst' and we want to make sure that we rebuild all the methods that were +// When we are rebuilding 'typeInst' and we want to make sure that we rebuild all the methods that were // actively referenced previously, this method will generate BfMethodSpecializationRequest for all used // methods from previously-built modules void BfContext::QueueMethodSpecializations(BfTypeInstance* typeInst, bool checkSpecializedMethodRebuildFlag) { BF_ASSERT(!typeInst->IsDeleting()); - + BP_ZONE("BfContext::QueueMethodSpecializations"); auto module = typeInst->mModule; @@ -2956,10 +2954,10 @@ void BfContext::QueueMethodSpecializations(BfTypeInstance* typeInst, bool checkS // modules that are NOT rebuilding to be sure we generate those. Failure to do this // will cause a link error from an old module for (auto& methodRefKV : typeInst->mSpecializedMethodReferences) - { + { auto& methodRef = methodRefKV.mKey; auto& specializedMethodRefInfo = methodRefKV.mValue; - + if (checkSpecializedMethodRebuildFlag) { if ((methodRef.mTypeInstance->mRebuildFlags & BfTypeRebuildFlag_SpecializedMethodRebuild) == 0) @@ -2970,7 +2968,7 @@ void BfContext::QueueMethodSpecializations(BfTypeInstance* typeInst, bool checkS if ((methodRef.mTypeInstance->mModule == NULL) || (methodRef.mTypeInstance->mModule->mRevision != mCompiler->mRevision)) continue; - } + } bool allowMismatch = false; if ((methodRef.mTypeInstance->IsInstanceOf(mCompiler->mInternalTypeDef)) || (methodRef.mTypeInstance->IsInstanceOf(mCompiler->mGCTypeDef))) @@ -2995,7 +2993,7 @@ void BfContext::QueueMethodSpecializations(BfTypeInstance* typeInst, bool checkS specializationRequest->mMethodIdx = methodRef.mMethodNum; //specializationRequest->mMethodDef = methodRef.mTypeInstance->mTypeDef->mMethods[methodRef.mMethodNum]; specializationRequest->mMethodGenericArguments = methodRef.mMethodGenericArguments; - specializationRequest->mType = methodRef.mTypeInstance; + specializationRequest->mType = methodRef.mTypeInstance; BfLogSysM("QueueMethodSpecializations typeInst %p specializationRequest %p methodDef %p fromModule %p\n", typeInst, specializationRequest, methodDef, specializationRequest->mFromModule); } @@ -3083,7 +3081,7 @@ bool BfContext::IsWorkItemValid(BfMethodSpecializationRequest* item) template void DoRemoveInvalidWorkItems(BfContext* bfContext, WorkQueue& workList, bool requireValidType) -{ +{ //auto itr = workList.begin(); //while (itr != workList.end()) @@ -3095,11 +3093,11 @@ void DoRemoveInvalidWorkItems(BfContext* bfContext, WorkQueue& workList, bool auto workItem = workList[workIdx]; if (workItem == NULL) continue; - + BfTypeInstance* typeInst = workItem->mType->ToTypeInstance(); if ((workItem->mType->IsDeleting()) || - (workItem->mType->mRebuildFlags & BfTypeRebuildFlag_Deleted) || + (workItem->mType->mRebuildFlags & BfTypeRebuildFlag_Deleted) || ((workItem->mRevision != -1) && (typeInst != NULL) && (workItem->mRevision != typeInst->mRevision)) || ((workItem->mSignatureRevision != -1) && (typeInst != NULL) && (workItem->mSignatureRevision != typeInst->mSignatureRevision)) || ((workItem->mFromModuleRevision != -1) && (workItem->mFromModuleRevision != workItem->mFromModule->mRevision)) || @@ -3118,15 +3116,15 @@ void DoRemoveInvalidWorkItems(BfContext* bfContext, WorkQueue& workList, bool BfLogSys(bfContext->mSystem, "Removing work item: %p ReqId:%d\n", workItem, workItem->mReqId); ReportRemovedItem(workItem); workIdx = workList.RemoveAt(workIdx); - //itr = workList.erase(itr); + //itr = workList.erase(itr); } //else - //++itr; + //++itr; } } void BfContext::RemoveInvalidFailTypes() -{ +{ for (auto itr = mFailTypes.begin(); itr != mFailTypes.end(); ) { auto typeInst = *itr; @@ -3138,13 +3136,13 @@ void BfContext::RemoveInvalidFailTypes() } else itr++; - } + } } // These work items are left over from a previous canceled run, OR from explicit method // specializations being rebuilt when the type is rebuilt void BfContext::RemoveInvalidWorkItems() -{ +{ BfLogSysM("RemoveInvalidWorkItems %p\n", this); // Delete any request that include deleted types. @@ -3152,20 +3150,20 @@ void BfContext::RemoveInvalidWorkItems() // whether or not the type has been reset since these work items were requested DoRemoveInvalidWorkItems(this, mMethodWorkList, true); - DoRemoveInvalidWorkItems(this, mInlineMethodWorkList, true); + DoRemoveInvalidWorkItems(this, mInlineMethodWorkList, true); //TODO: We used to pass true into requireValidType, but this gets populated from UpdateRevisedTypes right before RemoveInvalidWorkItems, // so we're passing false in here now. Don't just switch it back and forth - find why 'false' was causing an issue. - // Same with mMethodSpecializationWorkList - DoRemoveInvalidWorkItems(this, mPopulateTypeWorkList, false); + // Same with mMethodSpecializationWorkList + DoRemoveInvalidWorkItems(this, mPopulateTypeWorkList, false); DoRemoveInvalidWorkItems(this, mMidCompileWorkList, false); DoRemoveInvalidWorkItems(this, mMethodSpecializationWorkList, false/*true*/); DoRemoveInvalidWorkItems(this, mTypeRefVerifyWorkList, false); - + #ifdef _DEBUG for (auto& workItem : mMethodWorkList) { - //BF_ASSERT(workItem.mMethodInstance->mDeclModule != NULL); + //BF_ASSERT(workItem.mMethodInstance->mDeclModule != NULL); } for (auto workItem : mMethodSpecializationWorkList) @@ -3186,40 +3184,40 @@ void BfContext::RemoveInvalidWorkItems() for (auto workListItem : mMethodWorkList) { if ((workListItem != NULL) && (workListItem->mType->IsUnspecializedType())) - { - workListItem->mMethodInstance->mIRFunction = BfIRFunction(); - } + { + workListItem->mMethodInstance->mIRFunction = BfIRFunction(); + } } - } - + } + RemoveInvalidFailTypes(); } void BfContext::RemapObject() -{ +{ if (mCompiler->mBfObjectTypeDef == NULL) return; - // There are several types that get their LLVM type mapped to Object, so make sure to remap that + // There are several types that get their LLVM type mapped to Object, so make sure to remap that // for when Object itself gets recreated - + auto objectType = mScratchModule->ResolveTypeDef(mCompiler->mBfObjectTypeDef, BfPopulateType_Declaration); auto objectTypeInst = objectType->ToTypeInstance(); if (objectTypeInst->mRevision == mMappedObjectRevision) return; mMappedObjectRevision = objectTypeInst->mRevision; - + for (int paramKind = 0; paramKind < 2; paramKind++) { for (int paramIdx = 0; paramIdx < (int)mGenericParamTypes[paramKind].size(); paramIdx++) { - auto genericParam = mGenericParamTypes[paramKind][paramIdx]; + auto genericParam = mGenericParamTypes[paramKind][paramIdx]; genericParam->mSize = objectType->mSize; genericParam->mAlign = objectType->mAlign; } } - auto varType = mScratchModule->GetPrimitiveType(BfTypeCode_Var); + auto varType = mScratchModule->GetPrimitiveType(BfTypeCode_Var); varType->mSize = objectType->mSize; varType->mAlign = objectType->mAlign; } @@ -3260,7 +3258,7 @@ void BfContext::TryUnreifyModules() BP_ZONE("BfContext::TryUnreifyModules"); for (auto module : mModules) - { + { if (module->mIsSpecialModule) continue; @@ -3276,7 +3274,7 @@ void BfContext::TryUnreifyModules() if (typeInst->mTypeDef->IsGlobalsContainer()) isRequired = true; - if (typeInst->IsAlwaysInclude()) + if (typeInst->IsAlwaysInclude()) isRequired = true; } @@ -3296,8 +3294,8 @@ void BfContext::MarkUsedModules(BfProject* project, BfModule* module) if (module->mIsScratchModule) return; - if (project->mUsedModules.Contains(module)) - return; + if (project->mUsedModules.Contains(module)) + return; if (!mCompiler->IsModuleAccessible(module, project)) return; @@ -3305,7 +3303,7 @@ void BfContext::MarkUsedModules(BfProject* project, BfModule* module) project->mUsedModules.Add(module); for (auto& typeDataKV : module->mTypeDataRefs) - project->mReferencedTypeData.Add(typeDataKV.mKey); + project->mReferencedTypeData.Add(typeDataKV.mKey); for (auto& slotKV : module->mInterfaceSlotRefs) { @@ -3314,7 +3312,7 @@ void BfContext::MarkUsedModules(BfProject* project, BfModule* module) mCompiler->mHotState->mHasNewInterfaceTypes = true; mReferencedIFaceSlots.Add(typeInstance); } - + for (auto& kv : module->mStaticFieldRefs) { auto& fieldRef = kv.mKey; @@ -3327,7 +3325,7 @@ void BfContext::MarkUsedModules(BfProject* project, BfModule* module) module->mLastUsedRevision = mCompiler->mRevision; for (auto usedModule : module->mModuleRefs) - { + { MarkUsedModules(project, usedModule); } @@ -3338,8 +3336,7 @@ void BfContext::MarkUsedModules(BfProject* project, BfModule* module) } void BfContext::Finish() -{ - +{ } void BfContext::Cleanup() @@ -3347,7 +3344,7 @@ void BfContext::Cleanup() BfLogSysM("BfContext::Cleanup() MethodWorkList: %d LocalMethodGraveyard: %d\n", mMethodWorkList.size(), mLocalMethodGraveyard.size()); // Can't clean up LLVM types, they are allocated with a bump allocator - RemoveInvalidFailTypes(); + RemoveInvalidFailTypes(); mCompiler->mCompileState = BfCompiler::CompileState_Cleanup; @@ -3397,7 +3394,7 @@ void BfContext::Cleanup() // These need to get deleted before the modules because we access mModule in the MethodInstance dtors for (int pass = 0; pass < 2; pass++) { - for (int i = 0; i < (int)mTypeGraveyard.size(); i++) + for (int i = 0; i < (int)mTypeGraveyard.size(); i++) { auto type = mTypeGraveyard[i]; if (type == NULL) @@ -3421,7 +3418,7 @@ void BfContext::Cleanup() for (auto itr = project->mUsedModules.begin(); itr != project->mUsedModules.end(); ) { auto module = *itr; - + if (module->mIsDeleting) itr = project->mUsedModules.Remove(itr); else @@ -3436,8 +3433,8 @@ void BfContext::Cleanup() for (auto module : mDeletingModules) { int idx = (int)mFinishedModuleWorkList.IndexOf(module); - if (idx != -1) - mFinishedModuleWorkList.RemoveAt(idx); + if (idx != -1) + mFinishedModuleWorkList.RemoveAt(idx); idx = (int)mFinishedSlotAwaitModuleWorkList.IndexOf(module); if (idx != -1) @@ -3445,15 +3442,14 @@ void BfContext::Cleanup() delete module; } - mDeletingModules.Clear(); - + mDeletingModules.Clear(); + for (auto typeDef : mTypeDefGraveyard) delete typeDef; - mTypeDefGraveyard.Clear(); - + mTypeDefGraveyard.Clear(); + mScratchModule->Cleanup(); mUnreifiedModule->Cleanup(); - for (auto module : mModules) + for (auto module : mModules) module->Cleanup(); -} - +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfContext.h b/IDEHelper/Compiler/BfContext.h index 57db1d36..d3c8e42f 100644 --- a/IDEHelper/Compiler/BfContext.h +++ b/IDEHelper/Compiler/BfContext.h @@ -12,22 +12,22 @@ public: BfModule* mFromModule; int mRevision; int mSignatureRevision; - int mFromModuleRevision; + int mFromModuleRevision; int mFromModuleRebuildIdx; - int mReqId; - static int sCurReqId; + int mReqId; + static int sCurReqId; public: BfWorkListEntry() { mType = NULL; mFromModule = NULL; - mRevision = -1; + mRevision = -1; mSignatureRevision = -1; mFromModuleRevision = -1; mFromModuleRebuildIdx = -1; - mReqId = ++sCurReqId; - } + mReqId = ++sCurReqId; + } }; class BfTypeProcessRequest : public BfWorkListEntry @@ -43,7 +43,7 @@ public: class BfMethodSpecializationRequest : public BfWorkListEntry { -public: +public: int32 mMethodIdx; BfTypeVector mMethodGenericArguments; BfGetMethodInstanceFlags mFlags; @@ -51,7 +51,7 @@ public: public: BfMethodSpecializationRequest() - { + { mMethodIdx = -1; mFlags = BfGetMethodInstanceFlag_None; mForeignType = NULL; @@ -97,9 +97,9 @@ public: class BfInlineMethodRequest : public BfMethodProcessRequest { -public: +public: BfIRFunction mFunc; - + ~BfInlineMethodRequest() { mMethodInstance = NULL; @@ -110,12 +110,12 @@ class BfTypeRefVerifyRequest : public BfWorkListEntry { public: BfTypeInstance* mCurTypeInstance; - BfAstNode* mRefNode; + BfAstNode* mRefNode; }; class BfMidCompileRequest : public BfWorkListEntry { -public: +public: String mReason; }; @@ -153,15 +153,15 @@ public: BfType* mType; BfTypeDef* mGlobalContainerCurUserTypeDef; - Array mGlobalContainers; // All global containers that are visible + Array mGlobalContainers; // All global containers that are visible BfPopulateType mPopulateType; BfTypeReference* mCurBaseTypeRef; BfTypeInstance* mCurBaseType; BfTypeReference* mCurAttributeTypeRef; - BfFieldDef* mCurFieldDef; + BfFieldDef* mCurFieldDef; BfTypeDef* mCurTypeDef; - BfTypeDef* mForceActiveTypeDef; + BfTypeDef* mForceActiveTypeDef; BfProject* mActiveProject; ResolveKind mResolveKind; BfAstNode* mCurVarInitializer; @@ -209,7 +209,7 @@ public: class BfSavedTypeData { public: - BfHotTypeData* mHotTypeData; + BfHotTypeData* mHotTypeData; int mTypeId; public: @@ -221,7 +221,7 @@ public: struct SpecializedErrorData { - // We need to store errors during type specialization and method specialization, + // We need to store errors during type specialization and method specialization, // because if the type is deleted we need to clear the errors BfTypeInstance* mRefType; BfModule* mModule; @@ -241,8 +241,8 @@ struct BfCaseInsensitiveStringHash { size_t operator()(const StringImpl& str) const { - int curHash = 0; - for (int i = 0; i < (int)str.length(); i++) + int curHash = 0; + for (int i = 0; i < (int)str.length(); i++) curHash = ((curHash ^ (int)(intptr)toupper(str[i])) << 5) - curHash; return curHash; } @@ -251,7 +251,7 @@ struct BfCaseInsensitiveStringHash struct BfCaseInsensitiveStringEquals { bool operator()(const StringImpl& lhs, const StringImpl& rhs) const - { + { if (lhs.length() != rhs.length()) return false; return _stricmp(lhs.c_str(), rhs.c_str()) == 0; @@ -270,7 +270,7 @@ public: { T*& ref = (*this)[idx]; if (ref != NULL) - (*ref).~T(); + (*ref).~T(); Deque::RemoveAt(0); if (this->mSize == 0) { @@ -303,7 +303,7 @@ public: T* item = mWorkAlloc.Alloc(); this->Add(item); return item; - } + } }; template @@ -348,7 +348,7 @@ public: bool operator==(const BfConstraintState& other) const { - return + return (mGenericParamInstance == other.mGenericParamInstance) && (mLeftType == other.mLeftType) && (mRightType == other.mRightType); @@ -358,9 +358,9 @@ public: class BfContext { public: - CritSect mCritSect; - bool mDeleting; - + CritSect mCritSect; + bool mDeleting; + BfTypeState* mCurTypeState; BfSizedArray* mCurNamespaceNodes; BfConstraintState* mCurConstraintState; @@ -369,25 +369,25 @@ public: bool mAssertOnPopulateType; BfSystem* mSystem; - BfCompiler* mCompiler; - + BfCompiler* mCompiler; + bool mAllowLockYield; bool mLockModules; BfModule* mScratchModule; - BfModule* mUnreifiedModule; + BfModule* mUnreifiedModule; HashSet mUsedModuleNames; Dictionary mProjectModule; Array mModules; - Array mDeletingModules; - HashSet mFailTypes; // All types handled after a failure need to be rebuild on subsequent compile + Array mDeletingModules; + HashSet mFailTypes; // All types handled after a failure need to be rebuild on subsequent compile HashSet mReferencedIFaceSlots; BfMethodInstance* mValueTypeDeinitSentinel; Array mTempNodes; - BfResolvedTypeSet mResolvedTypes; + BfResolvedTypeSet mResolvedTypes; Array mTypes; // Can contain NULLs for deleted types - Array mFieldResolveReentrys; // For detecting 'var' field circular refs + Array mFieldResolveReentrys; // For detecting 'var' field circular refs Dictionary mSavedTypeDataMap; Array mSavedTypeData; @@ -399,7 +399,7 @@ public: PtrWorkQueue mReifyModuleWorkList; WorkQueue mMethodWorkList; - WorkQueue mInlineMethodWorkList; + WorkQueue mInlineMethodWorkList; WorkQueue mPopulateTypeWorkList; WorkQueue mMethodSpecializationWorkList; WorkQueue mTypeRefVerifyWorkList; @@ -409,7 +409,7 @@ public: bool mHasReifiedQueuedRebuildTypes; Array mGenericParamTypes[3]; - + Array mTypeGraveyard; Array mTypeDefGraveyard; Array mLocalMethodGraveyard; @@ -418,9 +418,9 @@ public: Dictionary mStringObjectIdMap; int mCurStringObjectPoolId; - HashSet mQueuedSpecializedMethodRebuildTypes; + HashSet mQueuedSpecializedMethodRebuildTypes; - BfAllocPool mPointerTypePool; + BfAllocPool mPointerTypePool; BfAllocPool mArrayTypePool; BfAllocPool mSizedArrayTypePool; BfAllocPool mUnknownSizedArrayTypePool; @@ -429,13 +429,13 @@ public: BfAllocPool mAliasTypePool; BfAllocPool mRefTypePool; BfAllocPool mModifiedTypeTypePool; - BfAllocPool mGenericTypeInstancePool; + BfAllocPool mGenericTypeInstancePool; BfAllocPool mArrayTypeInstancePool; BfAllocPool mGenericParamTypePool; BfAllocPool mTypeDefTypeRefPool; BfAllocPool mConcreteInterfaceTypePool; BfAllocPool mConstExprValueTypePool; - BfAllocPool mDelegateTypePool; + BfAllocPool mDelegateTypePool; BfPrimitiveType* mPrimitiveTypes[BfTypeCode_Length]; BfPrimitiveType* mPrimitiveStructTypes[BfTypeCode_Length]; @@ -447,15 +447,15 @@ public: void PopulateHotTypeDataVTable(BfTypeInstance* typeInstance); void DeleteType(BfType* type, bool deferDepRebuilds = false); void UpdateAfterDeletingTypes(); - void VerifyTypeLookups(BfTypeInstance* typeInst); + void VerifyTypeLookups(BfTypeInstance* typeInst); void GenerateModuleName_TypeInst(BfTypeInstance* typeInst, StringImpl& name); void GenerateModuleName_Type(BfType* type, StringImpl& name); void GenerateModuleName(BfTypeInstance* typeInst, StringImpl& name); bool IsSentinelMethod(BfMethodInstance* methodInstance); - void SaveDeletingType(BfType* type); + void SaveDeletingType(BfType* type); BfType* FindType(const StringImpl& typeName); String TypeIdToString(int typeId); - BfHotTypeData* GetHotTypeData(int typeId); + BfHotTypeData* GetHotTypeData(int typeId); void ReflectInit(); public: @@ -464,28 +464,28 @@ public: void ReportMemory(MemReporter* memReporter); void ProcessMethod(BfMethodInstance* methodInstance); - int GetStringLiteralId(const StringImpl& str); + int GetStringLiteralId(const StringImpl& str); void CheckLockYield(); bool IsCancellingAndYield(); void QueueFinishModule(BfModule * module); void CancelWorkItems(); bool ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods); void HandleChangedTypeDef(BfTypeDef* typeDef, bool isAutoCompleteTempType = false); - void PreUpdateRevisedTypes(); - void UpdateRevisedTypes(); - void VerifyTypeLookups(); + void PreUpdateRevisedTypes(); + void UpdateRevisedTypes(); + void VerifyTypeLookups(); void QueueMethodSpecializations(BfTypeInstance* typeInst, bool checkSpecializedMethodRebuildFlag); void MarkAsReferenced(BfDependedType* depType); void RemoveInvalidFailTypes(); bool IsWorkItemValid(BfWorkListEntry* item); bool IsWorkItemValid(BfMethodProcessRequest* item); bool IsWorkItemValid(BfMethodSpecializationRequest* item); - void RemoveInvalidWorkItems(); + void RemoveInvalidWorkItems(); BfType* FindTypeById(int typeId); void AddTypeToWorkList(BfType* type); void ValidateDependencies(); void RebuildType(BfType* type, bool deleteOnDemandTypes = true, bool rebuildModule = true, bool placeSpecializiedInPurgatory = true); - void RebuildDependentTypes(BfDependedType* dType); + void RebuildDependentTypes(BfDependedType* dType); void QueueMidCompileRebuildDependentTypes(BfDependedType* dType, const String& reason); void RebuildDependentTypes_MidCompile(BfDependedType* dType, const String& reason); bool CanRebuild(BfType* type); diff --git a/IDEHelper/Compiler/BfDefBuilder.cpp b/IDEHelper/Compiler/BfDefBuilder.cpp index 7451842e..366ce1d3 100644 --- a/IDEHelper/Compiler/BfDefBuilder.cpp +++ b/IDEHelper/Compiler/BfDefBuilder.cpp @@ -73,8 +73,8 @@ BfDefBuilder::BfDefBuilder(BfSystem* bfSystem) BfDefBuilder::~BfDefBuilder() { - for (auto& usingNamespace : mNamespaceSearch) - mSystem->ReleaseAtomComposite(usingNamespace); + for (auto& usingNamespace : mNamespaceSearch) + mSystem->ReleaseAtomComposite(usingNamespace); } void BfDefBuilder::Process(BfPassInstance* passInstance, BfSource* bfSource, bool fullRefresh) @@ -92,19 +92,19 @@ void BfDefBuilder::Process(BfPassInstance* passInstance, BfSource* bfSource, boo mSystem->mNeedsTypesHandledByCompiler = true; mPassInstance = passInstance; - + bool isAutocomplete = false; if ((mResolvePassData != NULL) && (mResolvePassData->mAutoComplete != NULL)) - { + { mCurSource = bfSource; - Visit(bfSource->mRootNode); + Visit(bfSource->mRootNode); mCurSource = NULL; mPassInstance = NULL; return; } mFullRefresh = fullRefresh; - + if (bfSource->mPrevRevision != NULL) { for (auto typeDef : bfSource->mPrevRevision->mTypeDefs) @@ -123,7 +123,7 @@ void BfDefBuilder::Process(BfPassInstance* passInstance, BfSource* bfSource, boo mCurSource = NULL; } } - + if (bfSource->mPrevRevision != NULL) { for (auto typeDef : bfSource->mPrevRevision->mTypeDefs) @@ -146,15 +146,15 @@ void BfDefBuilder::Process(BfPassInstance* passInstance, BfSource* bfSource, boo void BfDefBuilder::Visit(BfIdentifierNode* identifier) { - if (mResolvePassData != NULL) - mResolvePassData->mExteriorAutocompleteCheckNodes.push_back(identifier); + if (mResolvePassData != NULL) + mResolvePassData->mExteriorAutocompleteCheckNodes.push_back(identifier); } // We need to be aware of the startNode because the reducer adds specifiers like 'static' and 'public' AFTER the method has // already been handled, so we need to ignore that space while determining if we're "inside" this method or not during // autocompletion bool BfDefBuilder::WantsNode(BfAstNode* wholeNode, BfAstNode* startNode, int addLen) -{ +{ if ((mResolvePassData == NULL) || (!mResolvePassData->mHasCursorIdx)) return true; @@ -173,13 +173,13 @@ bool BfDefBuilder::WantsNode(BfAstNode* wholeNode, BfAstNode* startNode, int add if ((startNode == NULL) || (parser->mCursorIdx >= startNode->GetSrcStart())) return true; } - return false; + return false; } static int sGenericParamIdx = 0; void BfDefBuilder::ParseGenericParams(BfGenericParamsDeclaration* genericParamsDecl, BfGenericConstraintsDeclaration* genericConstraints, Array& genericParams, Array* externConstraintDefs, int outerGenericSize, bool isInGeneric) -{ +{ if (genericParamsDecl != NULL) { int startIdx = (int)genericParams.size(); @@ -200,11 +200,11 @@ void BfDefBuilder::ParseGenericParams(BfGenericParamsDeclaration* genericParamsD while (checkTypeDef != NULL) { if (&genericParams != &checkTypeDef->mGenericParamDefs) - { + { for (int checkParamsIdx = 0; checkParamsIdx < (int)checkTypeDef->mGenericParamDefs.size(); checkParamsIdx++) { if (checkTypeDef->mGenericParamDefs[checkParamsIdx]->mName == name) - { + { mPassInstance->Warn(0, "Generic param name has same name as generic param from outer type", genericParamNode); } } @@ -212,13 +212,13 @@ void BfDefBuilder::ParseGenericParams(BfGenericParamsDeclaration* genericParamsD checkTypeDef = checkTypeDef->mOuterType; } - - auto genericParamDef = new BfGenericParamDef(); + + auto genericParamDef = new BfGenericParamDef(); genericParamDef->mName = name; genericParamDef->mNameNodes.Add(genericParamNode); - genericParamDef->mGenericParamFlags = BfGenericParamFlag_None; - genericParams.push_back(genericParamDef); - } + genericParamDef->mGenericParamFlags = BfGenericParamFlag_None; + genericParams.push_back(genericParamDef); + } } if (genericConstraints == NULL) @@ -245,7 +245,7 @@ void BfDefBuilder::ParseGenericParams(BfGenericParamsDeclaration* genericParamsD genericParamDef = checkGenericParam; } } - + BfConstraintDef* constraintDef = genericParamDef; if (genericParamDef == NULL) @@ -271,7 +271,7 @@ void BfDefBuilder::ParseGenericParams(BfGenericParamsDeclaration* genericParamsD constraintDef = externConstraintDef; } } - + if (genericParamDef != NULL) genericParamDef->mNameNodes.Add(nameNode); @@ -287,14 +287,14 @@ void BfDefBuilder::ParseGenericParams(BfGenericParamsDeclaration* genericParamsD { name = tokenPairNode->mLeft->ToString() + tokenPairNode->mRight->ToString(); } - + if (!name.empty()) { if ((name == "class") || (name == "struct") || (name == "struct*") || (name == "const") || (name == "var") || (name == "concrete") || (name == "interface") || (name == "enum")) { - int prevFlags = constraintDef->mGenericParamFlags & + int prevFlags = constraintDef->mGenericParamFlags & (BfGenericParamFlag_Class | BfGenericParamFlag_Struct | BfGenericParamFlag_StructPtr | BfGenericParamFlag_Interface | BfGenericParamFlag_Enum); - if (prevFlags != 0) + if (prevFlags != 0) { String prevFlagName; if (prevFlags & BfGenericParamFlag_Class) @@ -331,20 +331,20 @@ void BfDefBuilder::ParseGenericParams(BfGenericParamsDeclaration* genericParamsD constraintDef->mGenericParamFlags = (BfGenericParamFlags)(constraintDef->mGenericParamFlags | BfGenericParamFlag_Enum); else //if (name == "var") constraintDef->mGenericParamFlags = (BfGenericParamFlags)(constraintDef->mGenericParamFlags | BfGenericParamFlag_Var); - + continue; - } + } else if (name == "new") { constraintDef->mGenericParamFlags = (BfGenericParamFlags)(constraintDef->mGenericParamFlags | BfGenericParamFlag_New); continue; - } + } else if (name == "delete") { constraintDef->mGenericParamFlags = (BfGenericParamFlags)(constraintDef->mGenericParamFlags | BfGenericParamFlag_Delete); continue; } - } + } if (auto genericOpConstraint = BfNodeDynCast(constraintNode)) { @@ -357,22 +357,22 @@ void BfDefBuilder::ParseGenericParams(BfGenericParamsDeclaration* genericParamsD { Fail("Invalid constraint", constraintNode); return; - } + } } - + constraintDef->mConstraints.Add(constraintNode); } } } BfProtection BfDefBuilder::GetProtection(BfAstNode* protectionNode) -{ +{ if (auto tokenPair = BfNodeDynCast(protectionNode)) { return BfProtection_ProtectedInternal; } else if (auto protectionToken = BfNodeDynCast(protectionNode)) - { + { if (protectionToken->GetToken() == BfToken_Public) return BfProtection_Public; if (protectionToken->GetToken() == BfToken_Protected) @@ -381,11 +381,11 @@ BfProtection BfDefBuilder::GetProtection(BfAstNode* protectionNode) return BfProtection_Internal; return BfProtection_Private; } - + if (mCurTypeDef->mTypeCode == BfTypeCode_Interface) return BfProtection_Public; else - return BfProtection_Private; + return BfProtection_Private; } void BfDefBuilder::Visit(BfConstructorDeclaration* ctorDeclaration) @@ -397,7 +397,7 @@ void BfDefBuilder::Visit(BfConstructorDeclaration* ctorDeclaration) } BfMethodDef* BfDefBuilder::CreateMethodDef(BfMethodDeclaration* methodDeclaration, BfMethodDef* outerMethodDef) -{ +{ BfMethodDef* methodDef; if (auto operatorDecl = BfNodeDynCast(methodDeclaration)) @@ -405,7 +405,7 @@ BfMethodDef* BfDefBuilder::CreateMethodDef(BfMethodDeclaration* methodDeclaratio auto operatorDef = new BfOperatorDef(); operatorDef->mOperatorDeclaration = operatorDecl; operatorDef->mIsOperator = true; - methodDef = operatorDef; + methodDef = operatorDef; } else methodDef = new BfMethodDef(); @@ -414,12 +414,12 @@ BfMethodDef* BfDefBuilder::CreateMethodDef(BfMethodDeclaration* methodDeclaratio methodDef->mDeclaringType = mCurDeclaringTypeDef; methodDef->mMethodDeclaration = methodDeclaration; methodDef->mExplicitInterface = methodDeclaration->mExplicitInterface; - methodDef->mReturnTypeRef = methodDeclaration->mReturnType; - methodDef->mProtection = GetProtection(methodDeclaration->mProtectionSpecifier); + methodDef->mReturnTypeRef = methodDeclaration->mReturnType; + methodDef->mProtection = GetProtection(methodDeclaration->mProtectionSpecifier); methodDef->mIsReadOnly = methodDeclaration->mReadOnlySpecifier != NULL; methodDef->mIsStatic = methodDeclaration->mStaticSpecifier != NULL; - methodDef->mIsVirtual = methodDeclaration->mVirtualSpecifier != NULL; - methodDef->mIsPartial = methodDeclaration->mPartialSpecifier != NULL; + methodDef->mIsVirtual = methodDeclaration->mVirtualSpecifier != NULL; + methodDef->mIsPartial = methodDeclaration->mPartialSpecifier != NULL; methodDef->mIsNew = methodDeclaration->mNewSpecifier != NULL; methodDef->mIsMutating = methodDeclaration->mMutSpecifier != NULL; methodDef->mIsExtern = methodDeclaration->mExternSpecifier != NULL; @@ -450,7 +450,7 @@ BfMethodDef* BfDefBuilder::CreateMethodDef(BfMethodDeclaration* methodDeclaratio { methodDef->mIsConcrete = true; methodDef->mIsVirtual = false; - } + } if (methodDef->mIsAbstract) { @@ -462,12 +462,12 @@ BfMethodDef* BfDefBuilder::CreateMethodDef(BfMethodDeclaration* methodDeclaratio { methodDef->mIsOverride = false; methodDef->mIsAbstract = false; - } + } if (mCurTypeDef->mTypeCode == BfTypeCode_Interface) { if ((!methodDef->mIsConcrete) && (!methodDef->mIsStatic) && (!methodDef->mGenericParams.empty()) && (methodDef->mProtection == BfProtection_Public)) - methodDef->mIsVirtual = true; + methodDef->mIsVirtual = true; } bool isAutoCtor = false; @@ -495,12 +495,12 @@ BfMethodDef* BfDefBuilder::CreateMethodDef(BfMethodDeclaration* methodDeclaratio } } else if (methodDeclaration->IsA()) - { + { methodDef->mMethodType = BfMethodType_Dtor; if (methodDef->mIsStatic) methodDef->mName = "__BfStaticDtor"; else - { + { methodDef->mName = "~this"; if (!methodDef->mIsVirtual) { @@ -515,7 +515,7 @@ BfMethodDef* BfDefBuilder::CreateMethodDef(BfMethodDeclaration* methodDeclaratio /*if (propertyDecl->mStaticSpecifier == NULL) { Fail("Operators must be declared as static", methodDeclaration); - }*/ + }*/ String declError; if (methodDef->mProtection != BfProtection_Public) @@ -554,7 +554,7 @@ BfMethodDef* BfDefBuilder::CreateMethodDef(BfMethodDeclaration* methodDeclaratio methodDef->mMethodType = BfMethodType_Normal; methodDef->mProtection = BfProtection_Public; methodDef->mIsStatic = mCurTypeDef->mIsFunction; - + auto attributes = mCurTypeDef->mTypeDeclaration->mAttributes; while (attributes != NULL) { @@ -566,13 +566,13 @@ BfMethodDef* BfDefBuilder::CreateMethodDef(BfMethodDeclaration* methodDeclaratio methodDef->mCallingConvention = BfCallingConvention_Stdcall; } attributes = attributes->mNextAttribute; - } + } } else if (methodDeclaration->mMixinSpecifier != NULL) { if (methodDeclaration->mNameNode != NULL) methodDef->SetName(methodDeclaration->mNameNode); - methodDef->mMethodType = BfMethodType_Mixin; + methodDef->mMethodType = BfMethodType_Mixin; } else { @@ -621,8 +621,8 @@ BfMethodDef* BfDefBuilder::CreateMethodDef(BfMethodDeclaration* methodDeclaratio bool hadParams = false; bool hasDefault = false; for (int paramIdx = 0; paramIdx < (int)methodDeclaration->mParams.size(); paramIdx++) - { - BfParameterDeclaration* paramDecl = methodDeclaration->mParams[paramIdx]; + { + BfParameterDeclaration* paramDecl = methodDeclaration->mParams[paramIdx]; auto paramDef = new BfParameterDef(); paramDef->mParamDeclaration = paramDecl; @@ -667,8 +667,8 @@ BfMethodDef* BfDefBuilder::CreateMethodDef(BfMethodDeclaration* methodDeclaratio hadParams = true; } else if (hadParams) - { - methodDef->mParams[paramIdx - 1]->mParamKind = BfParamKind_Normal; + { + methodDef->mParams[paramIdx - 1]->mParamKind = BfParamKind_Normal; hadParams = false; Fail("Params parameter must be the last parameter", methodDef->mParams[paramIdx - 1]->mParamDeclaration); } @@ -684,7 +684,7 @@ BfMethodDef* BfDefBuilder::CreateMethodDef(BfMethodDeclaration* methodDeclaratio } methodDef->mParams.push_back(paramDef); - } + } if ((mCurTypeDef->mIsFunction) && (!methodDef->mParams.IsEmpty()) && (methodDef->mParams[0]->mName == "this")) { @@ -696,7 +696,7 @@ BfMethodDef* BfDefBuilder::CreateMethodDef(BfMethodDeclaration* methodDeclaratio { if (refTypeRef->mRefToken->mToken != BfToken_Mut) { - Fail("Only 'mut' is allowed here", refTypeRef->mRefToken); + Fail("Only 'mut' is allowed here", refTypeRef->mRefToken); } methodDef->mIsMutating = true; } @@ -717,7 +717,7 @@ BfMethodDef* BfDefBuilder::CreateMethodDef(BfMethodDeclaration* methodDeclaratio fieldDef->mTypeRef = paramDef->mTypeRef; fieldDef->mProtection = BfProtection_Public; BF_ASSERT(mCurDeclaringTypeDef != NULL); - fieldDef->mDeclaringType = mCurDeclaringTypeDef; + fieldDef->mDeclaringType = mCurDeclaringTypeDef; fieldDef->mIdx = mCurTypeDef->mFields.mSize; if ((paramDef->mParamDeclaration->mModToken != NULL) && (paramDef->mParamDeclaration->mModToken->mToken == BfToken_ReadOnly)) @@ -726,7 +726,7 @@ BfMethodDef* BfDefBuilder::CreateMethodDef(BfMethodDeclaration* methodDeclaratio } } - ParseAttributes(methodDeclaration->mAttributes, methodDef); + ParseAttributes(methodDeclaration->mAttributes, methodDef); return methodDef; } @@ -747,7 +747,7 @@ void BfDefBuilder::Visit(BfMethodDeclaration* methodDeclaration) int addLen = 0; if ((methodDeclaration->mNameNode == NULL) && (methodDeclaration->mBody == NULL)) - addLen = 1; + addLen = 1; mSystem->CheckLockYield(); @@ -774,12 +774,12 @@ void BfDefBuilder::Visit(BfMethodDeclaration* methodDeclaration) auto methodDef = CreateMethodDef(methodDeclaration); methodDef->mWantsBody = wantsBody; - if (methodDef->mMethodType == BfMethodType_Operator) - mCurTypeDef->mOperators.push_back((BfOperatorDef*)methodDef); - mCurTypeDef->mMethods.push_back(methodDef); + if (methodDef->mMethodType == BfMethodType_Operator) + mCurTypeDef->mOperators.push_back((BfOperatorDef*)methodDef); + mCurTypeDef->mMethods.push_back(methodDef); if (methodDef->mCommutableKind == BfCommutableKind_Forward) - { + { auto revMethodDef = CreateMethodDef(methodDeclaration); revMethodDef->mWantsBody = wantsBody; if (revMethodDef->mMethodType == BfMethodType_Operator) @@ -789,15 +789,15 @@ void BfDefBuilder::Visit(BfMethodDeclaration* methodDeclaration) { BF_SWAP(revMethodDef->mParams[0], revMethodDef->mParams[1]); } - revMethodDef->mCommutableKind = BfCommutableKind_Reverse; - mCurTypeDef->mMethods.push_back(revMethodDef); - } + revMethodDef->mCommutableKind = BfCommutableKind_Reverse; + mCurTypeDef->mMethods.push_back(revMethodDef); + } } void BfDefBuilder::ParseAttributes(BfAttributeDirective* attributes, BfMethodDef* methodDef) { while (attributes != NULL) - { + { if (attributes->mAttributeTypeRef != NULL) { auto typeRefName = attributes->mAttributeTypeRef->ToCleanAttributeString(); @@ -805,7 +805,7 @@ void BfDefBuilder::ParseAttributes(BfAttributeDirective* attributes, BfMethodDef if (typeRefName == "CLink") methodDef->mCLink = true; else if (typeRefName == "StdCall") - methodDef->mCallingConvention = BfCallingConvention_Stdcall; + methodDef->mCallingConvention = BfCallingConvention_Stdcall; else if (typeRefName == "Inline") { if (methodDef->mIsExtern) @@ -837,7 +837,7 @@ void BfDefBuilder::ParseAttributes(BfAttributeDirective* attributes, BfMethodDef if (literalExpr->mValue.mTypeCode == BfTypeCode_CharPtr) { String filePath = *literalExpr->mValue.mString; - methodDef->mImportKind = BfMethodDef::GetImportKindFromPath(filePath); + methodDef->mImportKind = BfMethodDef::GetImportKindFromPath(filePath); } } } @@ -880,10 +880,10 @@ void BfDefBuilder::ParseAttributes(BfAttributeDirective* attributes, BfMethodDef else methodDef->mCommutableKind = BfCommutableKind_Forward; } - } + } else if (typeRefName == "OnCompile") { - mCurTypeDef->mHasCEOnCompile = true; + mCurTypeDef->mHasCEOnCompile = true; } } @@ -932,10 +932,10 @@ void BfDefBuilder::Visit(BfPropertyDeclaration* propertyDeclaration) if (!WantsNode(propertyDeclaration, propertyDeclaration->mTypeRef, addLen)) { if (!WantsNode(propertyDeclaration, NULL, addLen)) - return; + return; // The cursor is inside some exterior specifiers, don't process body - wantsBody = false; - } + wantsBody = false; + } if ((propertyDeclaration->mConstSpecifier != NULL) && (propertyDeclaration->mConstSpecifier->mToken == BfToken_Const)) { @@ -943,11 +943,11 @@ void BfDefBuilder::Visit(BfPropertyDeclaration* propertyDeclaration) } if (mSignatureHashCtx != NULL) - HashNode(*mSignatureHashCtx, propertyDeclaration, propertyDeclaration->mDefinitionBlock); + HashNode(*mSignatureHashCtx, propertyDeclaration, propertyDeclaration->mDefinitionBlock); BfPropertyDef* propertyDef = new BfPropertyDef(); mCurTypeDef->mProperties.push_back(propertyDef); - propertyDef->mProtection = GetProtection(propertyDeclaration->mProtectionSpecifier); + propertyDef->mProtection = GetProtection(propertyDeclaration->mProtectionSpecifier); propertyDef->mIdx = (int)mCurTypeDef->mProperties.size() - 1; propertyDef->mIsConst = false; propertyDef->mIsProperty = true; @@ -963,20 +963,20 @@ void BfDefBuilder::Visit(BfPropertyDeclaration* propertyDeclaration) if (propertyDeclaration->mNameNode != NULL) propertyDef->SetName(propertyDeclaration->mNameNode); else if (propertyDeclaration->IsA()) - { + { propertyDef->mName = "[]"; } - propertyDef->mTypeRef = propertyDeclaration->mTypeRef; + propertyDef->mTypeRef = propertyDeclaration->mTypeRef; propertyDef->mFieldDeclaration = propertyDeclaration; BF_ASSERT(mCurDeclaringTypeDef != NULL); - propertyDef->mDeclaringType = mCurDeclaringTypeDef; + propertyDef->mDeclaringType = mCurDeclaringTypeDef; - if (auto varType = BfNodeDynCast(propertyDef->mTypeRef)) + if (auto varType = BfNodeDynCast(propertyDef->mTypeRef)) propertyDef->mIsReadOnly = true; //HashNode(*mSignatureHashCtx, propertyDeclaration, propertyDeclaration->mDefinitionBlock); - //mCurTypeDef->mSignatureHash = HashNode(propertyDeclaration, propertyDeclaration->mDefinitionBlock, mCurTypeDef->mSignatureHash); + //mCurTypeDef->mSignatureHash = HashNode(propertyDeclaration, propertyDeclaration->mDefinitionBlock, mCurTypeDef->mSignatureHash); if (propertyDeclaration->mDefinitionBlock == NULL) // To differentiate between autocompleting partial property if it transitions to a field { //mCurTypeDef->mSignatureHash = HashString("nullprop", mCurTypeDef->mSignatureHash); @@ -984,10 +984,10 @@ void BfDefBuilder::Visit(BfPropertyDeclaration* propertyDeclaration) mSignatureHashCtx->MixinStr("nullprop"); } - auto indexerDeclaration = BfNodeDynCast(propertyDeclaration); - + auto indexerDeclaration = BfNodeDynCast(propertyDeclaration); + bool isAbstract = false; - if (propertyDeclaration->mVirtualSpecifier != NULL) + if (propertyDeclaration->mVirtualSpecifier != NULL) isAbstract = propertyDeclaration->mVirtualSpecifier->GetToken() == BfToken_Abstract; bool needsAutoProperty = mCurTypeDef->HasAutoProperty(propertyDeclaration); @@ -1002,7 +1002,7 @@ void BfDefBuilder::Visit(BfPropertyDeclaration* propertyDeclaration) fieldDef->mTypeRef = propertyDef->mTypeRef; if (auto refTypeRef = BfNodeDynCast(fieldDef->mTypeRef)) fieldDef->mTypeRef = refTypeRef->mElementType; - fieldDef->mName = mCurTypeDef->GetAutoPropertyName(propertyDeclaration); + fieldDef->mName = mCurTypeDef->GetAutoPropertyName(propertyDeclaration); fieldDef->mIdx = (int)mCurTypeDef->mFields.size(); mCurTypeDef->mFields.push_back(fieldDef); @@ -1079,7 +1079,7 @@ void BfDefBuilder::Visit(BfPropertyDeclaration* propertyDeclaration) else methodDef->mIsOverride = false; methodDef->mIsNew = propertyDeclaration->mNewSpecifier != NULL; - + if (indexerDeclaration != NULL) { for (int paramIdx = 0; paramIdx < (int)indexerDeclaration->mParams.size(); paramIdx++) @@ -1098,7 +1098,7 @@ void BfDefBuilder::Visit(BfPropertyDeclaration* propertyDeclaration) } } - String methodName; + String methodName; if (auto propExprBody = BfNodeDynCast(propertyDeclaration->mDefinitionBlock)) { methodName = "get"; @@ -1110,7 +1110,7 @@ void BfDefBuilder::Visit(BfPropertyDeclaration* propertyDeclaration) } else if ((methodDeclaration != NULL) && (methodDeclaration->mNameNode != NULL)) methodName = methodDeclaration->mNameNode->ToString(); - + if (methodName == "get") { methodDef->mName = "get__"; @@ -1131,7 +1131,7 @@ void BfDefBuilder::Visit(BfPropertyDeclaration* propertyDeclaration) if (BfNodeDynCast(methodDeclaration->mBody) != NULL) methodDef->mIsMutating = true; // Don't require "set mut;", just "set;" - + auto paramDef = new BfParameterDef(); paramDef->mName = "value"; paramDef->mTypeRef = propertyDeclaration->mTypeRef; @@ -1145,7 +1145,7 @@ void BfDefBuilder::Visit(BfPropertyDeclaration* propertyDeclaration) if (methodDeclaration->mSetRefSpecifier != NULL) Fail("Property setter 'ref' can only be used with a 'ref' property type", methodDeclaration->mSetRefSpecifier); } - methodDef->mParams.Insert(0, paramDef); + methodDef->mParams.Insert(0, paramDef); propertyDef->mMethods.Add(methodDef); } else @@ -1163,7 +1163,7 @@ void BfDefBuilder::Visit(BfFieldDeclaration* fieldDeclaration) mSystem->CheckLockYield(); int endingAdd = 1;// Add '1' for autocompletion of 'new' initializer - + if (!WantsNode(fieldDeclaration, NULL, endingAdd)) { return; @@ -1173,35 +1173,35 @@ void BfDefBuilder::Visit(BfFieldDeclaration* fieldDeclaration) bool isEnumEntryDecl = fieldDeclaration->IsA(); auto fieldDef = new BfFieldDef(); - mCurTypeDef->mFields.push_back(fieldDef); + mCurTypeDef->mFields.push_back(fieldDef); fieldDef->mFieldDeclaration = fieldDeclaration; BF_ASSERT(mCurDeclaringTypeDef != NULL); fieldDef->mDeclaringType = mCurDeclaringTypeDef; if (fieldDeclaration->mNameNode != NULL) fieldDef->SetName(fieldDeclaration->mNameNode); - fieldDef->mProtection = GetProtection(fieldDeclaration->mProtectionSpecifier); + fieldDef->mProtection = GetProtection(fieldDeclaration->mProtectionSpecifier); if (isEnumEntryDecl) - fieldDef->mProtection = BfProtection_Public; - fieldDef->mIsReadOnly = fieldDeclaration->mReadOnlySpecifier != NULL; + fieldDef->mProtection = BfProtection_Public; + fieldDef->mIsReadOnly = fieldDeclaration->mReadOnlySpecifier != NULL; fieldDef->mIsInline = (fieldDeclaration->mReadOnlySpecifier != NULL) && (fieldDeclaration->mReadOnlySpecifier->GetToken() == BfToken_Inline); fieldDef->mIsExtern = (fieldDeclaration->mExternSpecifier != NULL) && (fieldDeclaration->mExternSpecifier->mToken == BfToken_Extern); fieldDef->mIsAppend = (fieldDeclaration->mExternSpecifier != NULL) && (fieldDeclaration->mExternSpecifier->mToken == BfToken_Append); auto constSpecifierToken = BfNodeDynCast(fieldDeclaration->mConstSpecifier); - fieldDef->mIsConst = ((constSpecifierToken != NULL) && (constSpecifierToken->mToken == BfToken_Const)) || (isEnumEntryDecl); + fieldDef->mIsConst = ((constSpecifierToken != NULL) && (constSpecifierToken->mToken == BfToken_Const)) || (isEnumEntryDecl); if (auto usingSpecifier = BfNodeDynCast(fieldDeclaration->mConstSpecifier)) { if (usingSpecifier->mProtection != NULL) fieldDef->mUsingProtection = GetProtection(usingSpecifier->mProtection); else fieldDef->mUsingProtection = fieldDef->mProtection; - } + } fieldDef->mIsStatic = (fieldDeclaration->mStaticSpecifier != NULL) || fieldDef->mIsConst; fieldDef->mIsVolatile = (fieldDeclaration->mVolatileSpecifier != NULL); fieldDef->mTypeRef = fieldDeclaration->mTypeRef; - if (auto varType = BfNodeDynCast(fieldDef->mTypeRef)) + if (auto varType = BfNodeDynCast(fieldDef->mTypeRef)) fieldDef->mIsReadOnly = true; - + if (fieldDef->mUsingProtection != BfProtection_Hidden) mCurTypeDef->mHasUsingFields = true; @@ -1214,7 +1214,7 @@ void BfDefBuilder::Visit(BfFieldDeclaration* fieldDeclaration) } } - fieldDef->mIdx = (int)mCurTypeDef->mFields.size() - 1; + fieldDef->mIdx = (int)mCurTypeDef->mFields.size() - 1; //mCurTypeDef->mSignatureHash = HashNode(fieldDeclaration, mCurTypeDef->mSignatureHash); if (mSignatureHashCtx != NULL) @@ -1222,7 +1222,7 @@ void BfDefBuilder::Visit(BfFieldDeclaration* fieldDeclaration) } void BfDefBuilder::Visit(BfEnumCaseDeclaration* enumCaseDeclaration) -{ +{ // Using `enumCaseDeclaration->mCaseToken` breaks attribute autocompletion //if (!WantsNode(enumCaseDeclaration, enumCaseDeclaration->mCaseToken, 0)) @@ -1244,8 +1244,8 @@ BfFieldDef* BfDefBuilder::AddField(BfTypeDef* typeDef, BfTypeReference* fieldTyp fieldDef->mDeclaringType = typeDef; fieldDef->mTypeRef = fieldType; fieldDef->mName = fieldName; - fieldDef->mIdx = (int)typeDef->mFields.size(); - typeDef->mFields.push_back(fieldDef); + fieldDef->mIdx = (int)typeDef->mFields.size(); + typeDef->mFields.push_back(fieldDef); return fieldDef; } @@ -1255,9 +1255,9 @@ BfMethodDef* BfDefBuilder::AddMethod(BfTypeDef* typeDef, BfMethodType methodType auto methodDef = new BfMethodDef(); methodDef->mIdx = (int)typeDef->mMethods.size(); - typeDef->mMethods.push_back(methodDef); + typeDef->mMethods.push_back(methodDef); methodDef->mDeclaringType = typeDef; - methodDef->mMethodType = methodType; + methodDef->mMethodType = methodType; methodDef->mAddedAfterEmit = addedAfterEmit; if (name.empty()) { @@ -1292,13 +1292,13 @@ BfMethodDef* BfDefBuilder::AddMethod(BfTypeDef* typeDef, BfMethodType methodType { methodDef->mName = "~this"; methodDef->mIsVirtual = true; - methodDef->mIsOverride = true; + methodDef->mIsOverride = true; } } else { BF_FATAL("Method name expected"); - } + } } else methodDef->mName = name; @@ -1316,13 +1316,13 @@ BfMethodDef* BfDefBuilder::AddDtor(BfTypeDef* typeDef) methodDef->mProtection = BfProtection_Public; methodDef->mMethodType = BfMethodType_Dtor; methodDef->mIsVirtual = true; - methodDef->mIsOverride = true; + methodDef->mIsOverride = true; return methodDef; } void BfDefBuilder::AddDynamicCastMethods(BfTypeDef* typeDef) -{ - // +{ + // { auto methodDef = new BfMethodDef(); methodDef->mIdx = (int)typeDef->mMethods.size(); @@ -1343,7 +1343,7 @@ void BfDefBuilder::AddDynamicCastMethods(BfTypeDef* typeDef) methodDef->mIsNoReflect = true; } - // + // { auto methodDef = new BfMethodDef(); methodDef->mIdx = (int)typeDef->mMethods.size(); @@ -1366,9 +1366,9 @@ void BfDefBuilder::AddDynamicCastMethods(BfTypeDef* typeDef) } void BfDefBuilder::AddParam(BfMethodDef* methodDef, BfTypeReference* typeRef, const StringImpl& paramName) -{ +{ auto paramDef = new BfParameterDef(); - paramDef->mName = paramName; + paramDef->mName = paramName; paramDef->mTypeRef = typeRef; methodDef->mParams.push_back(paramDef); } @@ -1421,7 +1421,7 @@ BfTypeDef* BfDefBuilder::ComparePrevTypeDef(BfTypeDef* prevTypeDef, BfTypeDef* c if ((!prevMatches) && (checkMatches)) return checkTypeDef; - return prevTypeDef; + return prevTypeDef; } void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration) @@ -1504,7 +1504,7 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration) mCurTypeDef->mNamespace = mNamespace; mSystem->AddNamespaceUsage(mCurTypeDef->mNamespace, mCurTypeDef->mProject); if (typeDeclaration->mTypeNode == NULL) - { + { mCurTypeDef->mIsPartial = true; mCurTypeDef->mIsExplicitPartial = true; } @@ -1523,13 +1523,13 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration) Fail(StrFormat("Type name '%s' is reserved", typeDeclaration->mNameNode->ToString().c_str()), typeDeclaration->mNameNode); } } - + BfLogSys(mCurSource->mSystem, "DefBuilder %p %p TypeDecl:%s\n", mCurTypeDef, mCurSource, mCurTypeDef->mName->ToString().mPtr); - mCurTypeDef->mProtection = (outerTypeDef == NULL) ? BfProtection_Public : BfProtection_Private; + mCurTypeDef->mProtection = (outerTypeDef == NULL) ? BfProtection_Public : BfProtection_Private; if (typeDeclaration->mProtectionSpecifier != NULL) { - if ((outerTypeDef == NULL) && + if ((outerTypeDef == NULL) && (typeDeclaration->mProtectionSpecifier->GetToken() != BfToken_Public) && (typeDeclaration->mProtectionSpecifier->GetToken() != BfToken_Internal)) { @@ -1563,15 +1563,15 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration) HashNode(*mSignatureHashCtx, baseClassNode); HashNode(*mSignatureHashCtx, typeDeclaration->mAttributes); HashNode(*mSignatureHashCtx, typeDeclaration->mAbstractSpecifier); - HashNode(*mSignatureHashCtx, typeDeclaration->mSealedSpecifier); + HashNode(*mSignatureHashCtx, typeDeclaration->mSealedSpecifier); HashNode(*mSignatureHashCtx, typeDeclaration->mProtectionSpecifier); HashNode(*mSignatureHashCtx, typeDeclaration->mPartialSpecifier); HashNode(*mSignatureHashCtx, typeDeclaration->mNameNode); HashNode(*mSignatureHashCtx, typeDeclaration->mGenericParams); HashNode(*mSignatureHashCtx, typeDeclaration->mGenericConstraintsDeclaration); - + HashNode(*mFullHashCtx, typeDeclaration); - + // Allow internal preprocessor flags to change a full hash change if (bfParser != NULL) { @@ -1604,7 +1604,7 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration) //int randomCrap = rand(); //HASH128_MIXIN(mCurTypeDef->mFullHash, randomCrap); - // To cause a type rebuild when we change pragma settings or #if resolves + // To cause a type rebuild when we change pragma settings or #if resolves //mCurTypeDef->mFullHash = Hash128(&typeDeclaration->mParser->mStateHash, sizeof(Val128), mCurTypeDef->mFullHash); //BfParser* bfParser = typeDeclaration->mParser; @@ -1664,7 +1664,7 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration) BfGenericParamDef* copiedGenericParamDef = new BfGenericParamDef(); *copiedGenericParamDef = *outerGenericParamDef; mCurTypeDef->mGenericParamDefs.Add(copiedGenericParamDef); - } + } BfTypeDef* parentType = outerTypeDef; while (parentType != NULL) @@ -1680,56 +1680,56 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration) mCurTypeDef->mStaticSearch = mStaticSearch; mCurTypeDef->mInternalAccessSet = mInternalAccessSet; } - + // We need to mix the namespace search into the signature hash because it can change how type references are resolved for (auto& usingName : mCurTypeDef->mNamespaceSearch) - { + { mSystem->RefAtomComposite(usingName); mSignatureHashCtx->MixinStr(usingName.ToString()); } - for (auto& usingName : mCurTypeDef->mStaticSearch) + for (auto& usingName : mCurTypeDef->mStaticSearch) HashNode(*mSignatureHashCtx, usingName); for (auto& usingName : mCurTypeDef->mInternalAccessSet) HashNode(*mSignatureHashCtx, usingName); - + if ((typeDeclaration->mPartialSpecifier != NULL) && (!isAutoCompleteTempType)) { mCurTypeDef->mIsExplicitPartial = true; mCurTypeDef->mIsPartial = true; } - + bool isExtension = false; if ((typeDeclaration->mTypeNode != NULL) && (typeDeclaration->mTypeNode->GetToken() == BfToken_Extension)) { mCurTypeDef->mIsPartial = true; isExtension = true; } - + BfAtomComposite fullName; if (!expandedName.IsEmpty()) fullName.Set(mCurTypeDef->mNamespace.mParts, mCurTypeDef->mNamespace.mSize, &expandedName[0], (int)expandedName.size()); else fullName = mCurTypeDef->mNamespace; - + String fullNameStr = fullName.ToString(); mCurTypeDef->mHash = 0xBEEF123; // Salt the hash for (char c : fullNameStr) mCurTypeDef->mHash = ((mCurTypeDef->mHash ^ c) << 4) - mCurTypeDef->mHash; - mCurTypeDef->mFullName = fullName; + mCurTypeDef->mFullName = fullName; BfTypeDef* prevRevisionTypeDef = NULL; BfTypeDef* otherDefinitionTypeDef = NULL; - + int numGenericParams = 0; if (typeDeclaration->mGenericParams != NULL) numGenericParams = (int)typeDeclaration->mGenericParams->mGenericParams.size(); if (outerTypeDef != NULL) numGenericParams += (int)outerTypeDef->mGenericParamDefs.size(); - + mCurTypeDef->mSource = mCurSource; mCurTypeDef->mSource->mRefCount++; mCurTypeDef->mTypeDeclaration = typeDeclaration; - mCurTypeDef->mIsAbstract = (typeDeclaration->mAbstractSpecifier != NULL) && (typeDeclaration->mAbstractSpecifier->GetToken() == BfToken_Abstract); + mCurTypeDef->mIsAbstract = (typeDeclaration->mAbstractSpecifier != NULL) && (typeDeclaration->mAbstractSpecifier->GetToken() == BfToken_Abstract); mCurTypeDef->mIsStatic = typeDeclaration->mStaticSpecifier != NULL; mCurTypeDef->mIsDelegate = false; mCurTypeDef->mIsFunction = false; @@ -1794,7 +1794,7 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration) mCurTypeDef->mIsAbstract = false; } } - + int outerGenericSize = 0; if (actualOuterTypeDef != NULL) { @@ -1807,25 +1807,25 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration) if (!isAutoCompleteTempType) { BfTypeDef* prevDef = NULL; - - auto itr = mSystem->mTypeDefs.TryGet(fullName); + + auto itr = mSystem->mTypeDefs.TryGet(fullName); while (itr) { BfTypeDef* checkTypeDef = *itr; - + if (checkTypeDef->mDefState == BfTypeDef::DefState_Deleted) { itr.MoveToNextHashMatch(); continue; } - if ((checkTypeDef->NameEquals(mCurTypeDef)) && + if ((checkTypeDef->NameEquals(mCurTypeDef)) && (checkTypeDef->mGenericParamDefs.size() == numGenericParams) && (mCurTypeDef->mProject == checkTypeDef->mProject)) { if (checkTypeDef->mIsCombinedPartial) { - // Ignore + // Ignore } else { @@ -1833,13 +1833,13 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration) { // We don't allow "new revision" semantics if the 'isExtension' state changes, or // if the outer type did not use "new revision" semantics (for isExtension change on itself or other outer type) - + bool isCompatible = (isExtension == (checkTypeDef->mTypeCode == BfTypeCode_Extension)) && (checkTypeDef->mTypeCode == mCurTypeDef->mTypeCode) && (checkTypeDef->mIsDelegate == mCurTypeDef->mIsDelegate) && (checkTypeDef->mIsFunction == mCurTypeDef->mIsFunction) && (checkTypeDef->mOuterType == actualOuterTypeDef); - + if (isCompatible) { if (prevRevisionTypeDef == NULL) @@ -1881,12 +1881,12 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration) BF_ASSERT(mCurTypeDef->mSystem != NULL); mCurActualTypeDef = prevRevisionTypeDef; doInsertNew = false; - } + } } else { mSystem->TrackName(mCurTypeDef); - bfParser->mTypeDefs.Add(mCurTypeDef); + bfParser->mTypeDefs.Add(mCurTypeDef); } if (doInsertNew) @@ -1909,14 +1909,14 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration) outerTypeDef->mNestedTypes.push_back(mCurActualTypeDef); } - BfLogSysM("Creating TypeDef %p Hash:%d from TypeDecl: %p Source: %p ResolvePass: %d AutoComplete:%d PrevRevision:%d\n", mCurTypeDef, mCurTypeDef->mHash, typeDeclaration, - typeDeclaration->GetSourceData(), mResolvePassData != NULL, isAutoCompleteTempType, prevRevisionTypeDef); - + BfLogSysM("Creating TypeDef %p Hash:%d from TypeDecl: %p Source: %p ResolvePass: %d AutoComplete:%d PrevRevision:%d\n", mCurTypeDef, mCurTypeDef->mHash, typeDeclaration, + typeDeclaration->GetSourceData(), mResolvePassData != NULL, isAutoCompleteTempType, prevRevisionTypeDef); + BF_ASSERT(mCurTypeDef->mNameEx == NULL); - + if (mCurTypeDef->mGenericParamDefs.size() != 0) { - mCurTypeDef->mNameEx = mSystem->GetAtom(StrFormat("%s`%d", mCurTypeDef->mName->mString.mPtr, numGenericParams)); + mCurTypeDef->mNameEx = mSystem->GetAtom(StrFormat("%s`%d", mCurTypeDef->mName->mString.mPtr, numGenericParams)); } else { @@ -1924,7 +1924,7 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration) mCurTypeDef->mNameEx->mRefCount++; } if (!fullName.IsEmpty()) - { + { if (mCurTypeDef->IsGlobalsContainer()) { mCurTypeDef->mFullNameEx.Set(fullName.mParts, fullName.mSize, &mCurTypeDef->mNameEx, 1); @@ -1932,10 +1932,10 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration) else { mCurTypeDef->mFullNameEx = fullName; - mCurTypeDef->mFullNameEx.mParts[mCurTypeDef->mFullNameEx.mSize - 1] = mCurTypeDef->mNameEx; + mCurTypeDef->mFullNameEx.mParts[mCurTypeDef->mFullNameEx.mSize - 1] = mCurTypeDef->mNameEx; } } - + if (typeDeclaration->mAutoCtor != NULL) VisitChildNoRef(typeDeclaration->mAutoCtor); @@ -1949,7 +1949,7 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration) else if (auto defineTokenNode = BfNodeDynCast(typeDeclaration->mDefineNode)) { if (defineTokenNode->GetToken() == BfToken_Semicolon) - { + { if (typeDeclaration->mAutoCtor == NULL) mCurTypeDef->mIsOpaque = true; } @@ -1983,19 +1983,19 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration) else prevRevisionTypeDef->mDefState = BfTypeDef::DefState_Internals_Changed; } - + // There's a new type with this name... if ((prevRevisionTypeDef == NULL) && (!isAutoCompleteTempType)) { mCurTypeDef->mName->mAtomUpdateIdx = ++mSystem->mAtomUpdateIdx; - } + } } void BfDefBuilder::FinishTypeDef(bool wantsToString) { auto bfSource = mCurTypeDef->mSource; bool isAlias = mCurTypeDef->mTypeCode == BfTypeCode_TypeAlias; - bool hasCtor = false; + bool hasCtor = false; bool needsDefaultCtor = (mCurTypeDef->mTypeCode != BfTypeCode_Interface) && (!mCurTypeDef->mIsStatic) && (!isAlias); bool hasDefaultCtor = false; BfMethodDef* ctorClear = NULL; @@ -2007,16 +2007,16 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) BfMethodDef* dynamicCastMethod = NULL; BfMethodDef* toStringMethod = NULL; BfMethodDef* getUnderlyingMethod = NULL; - bool needsEqualsMethod = ((mCurTypeDef->mTypeCode == BfTypeCode_Struct) || (mCurTypeDef->mTypeCode == BfTypeCode_Enum)) && (!mCurTypeDef->mIsStatic); + bool needsEqualsMethod = ((mCurTypeDef->mTypeCode == BfTypeCode_Struct) || (mCurTypeDef->mTypeCode == BfTypeCode_Enum)) && (!mCurTypeDef->mIsStatic); BfMethodDef* equalsOpMethod = NULL; BfMethodDef* equalsMethod = NULL; - BfMethodDef* strictEqualsMethod = NULL; + BfMethodDef* strictEqualsMethod = NULL; bool needsStaticInit = false; for (int methodIdx = 0; methodIdx < (int)mCurTypeDef->mMethods.size(); methodIdx++) { auto method = mCurTypeDef->mMethods[methodIdx]; - + auto _SetMethod = [&](BfMethodDef*& setMethodDef, BfMethodDef* methodDef) { if ((setMethodDef != NULL) && (setMethodDef->mMethodDeclaration == NULL)) @@ -2045,7 +2045,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) _SetMethod(staticCtor, method); } - else + else { hasCtor = true; if (method->mParams.size() == 0) @@ -2053,19 +2053,19 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) auto ctorDeclaration = (BfConstructorDeclaration*)method->mMethodDeclaration; if (method->mHasAppend) - { + { mCurTypeDef->mHasAppendCtor = true; auto methodDef = new BfMethodDef(); mCurTypeDef->mMethods.Insert(methodIdx + 1, methodDef); BF_ASSERT(mCurDeclaringTypeDef != NULL); - methodDef->mDeclaringType = mCurDeclaringTypeDef; + methodDef->mDeclaringType = mCurDeclaringTypeDef; methodDef->mName = BF_METHODNAME_CALCAPPEND; - methodDef->mProtection = BfProtection_Public; + methodDef->mProtection = BfProtection_Public; methodDef->mMethodType = BfMethodType_CtorCalcAppend; methodDef->mIsMutating = method->mIsMutating; methodDef->mIsNoSplat = true; - + methodDef->mMethodDeclaration = method->mMethodDeclaration; methodDef->mReturnTypeRef = mSystem->mDirectIntTypeRef; methodDef->mIsStatic = true; @@ -2082,7 +2082,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) methodDef->mParams.push_back(newParam); } - // Insert a 'appendIdx' + // Insert a 'appendIdx' BfParameterDef* newParam = new BfParameterDef(); newParam->mName = "appendIdx"; newParam->mTypeRef = mSystem->mDirectRefIntTypeRef; @@ -2109,7 +2109,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) Fail("Only one static constructor is allowed", method->mMethodDeclaration); method->mIsStatic = false; } - + _SetMethod(staticDtor, method); } else @@ -2119,10 +2119,10 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) Fail("Only one destructor is allowed", method->mMethodDeclaration); method->mIsStatic = false; } - _SetMethod(dtor, method); + _SetMethod(dtor, method); } - if (method->mParams.size() != 0) + if (method->mParams.size() != 0) Fail("Destructors cannot declare parameters", method->GetMethodDeclaration()->mParams[0]); } else if (method->mMethodType == BfMethodType_Normal) @@ -2143,7 +2143,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) if (method->mName == BF_METHODNAME_DYNAMICCAST) _SetMethod(dynamicCastMethod, method); if (method->mName == BF_METHODNAME_TO_STRING) - _SetMethod(toStringMethod, method); + _SetMethod(toStringMethod, method); } } else if (method->mMethodType == BfMethodType_PropertyGetter) @@ -2152,13 +2152,13 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) _SetMethod(getUnderlyingMethod, method); } else if ((method->mMethodType == BfMethodType_Operator) && - (method->mIsStatic) && + (method->mIsStatic) && (method->mParams.size() == 2)) { if (auto operatorDecl = BfNodeDynCast(method->mMethodDeclaration)) { if (operatorDecl->mBinOp == BfBinaryOp_Equality) - { + { // This is a conservative check. It's okay to add a system-defined equals method even if we don't need it. if ((method->mParams[0]->mTypeRef->ToString() == mCurTypeDef->mName->ToString()) && (method->mParams[1]->mTypeRef->ToString() == mCurTypeDef->mName->ToString())) @@ -2166,13 +2166,13 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) _SetMethod(equalsOpMethod, method); } } - } + } } if ((method->mImportKind == BfImportKind_Import_Dynamic) || (method->mImportKind == BfImportKind_Import_Unknown)) needsStaticInit = true; } - + if (mCurTypeDef->IsExtension()) needsDefaultCtor = false; @@ -2185,7 +2185,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) { if (field->mIsStatic) { - // Resolve-only compiler wants to visit const initializers in a static ctor method, but we don't + // Resolve-only compiler wants to visit const initializers in a static ctor method, but we don't // want to create it for the actual binary if ((!field->mIsConst) || (mSystem->mIsResolveOnly)) { @@ -2193,7 +2193,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) if (field->mFieldDeclaration != NULL) { if (field->GetFieldDeclaration()->mInitializer != NULL) - { + { needsStaticInit = true; } if (field->GetFieldDeclaration()->mFieldDtor != NULL) @@ -2223,7 +2223,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) } } } - else + else { hasNonStaticField = true; if (field->GetInitializer() != NULL) @@ -2240,38 +2240,38 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) } } } - + bool needsDynamicCastMethod = dynamicCastMethod == NULL; if (mCurTypeDef->mIsFunction) { wantsToString = false; needsEqualsMethod = false; - needsDefaultCtor = false; + needsDefaultCtor = false; needsDynamicCastMethod = false; } if ((mCurTypeDef->mTypeCode == BfTypeCode_Object) && (!mCurTypeDef->mIsStatic) && (ctorClear == NULL)) - { + { auto methodDef = AddMethod(mCurTypeDef, BfMethodType_CtorClear, BfProtection_Private, false, "", mIsComptime); - methodDef->mIsMutating = true; + methodDef->mIsMutating = true; } if ((needsDtor) && (dtor == NULL)) - { + { auto methodDef = AddMethod(mCurTypeDef, BfMethodType_Dtor, BfProtection_Public, false, "", mIsComptime); } if ((needsStaticDtor) && (staticDtor == NULL)) - { + { auto methodDef = AddMethod(mCurTypeDef, BfMethodType_Dtor, BfProtection_Public, true, "", mIsComptime); } if ((needsStaticInit) && (staticCtor == NULL)) - { + { auto methodDef = AddMethod(mCurTypeDef, BfMethodType_Ctor, BfProtection_Public, true, "", mIsComptime); } - + bool makeCtorPrivate = hasCtor; if (mCurTypeDef->mTypeCode == BfTypeCode_TypeAlias) @@ -2286,22 +2286,21 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) prot = BfProtection_Hidden; // Create default constructor. If it's the only constructor then make it public, - // otherwise make it private so we can still internally use it but the user can't + // otherwise make it private so we can still internally use it but the user can't auto methodDef = AddMethod(mCurTypeDef, BfMethodType_Ctor, prot, false, "", mIsComptime); methodDef->mIsMutating = true; } - bool isAutocomplete = false; if ((mResolvePassData != NULL) && (mResolvePassData->mAutoComplete != NULL)) isAutocomplete = true; - - //TODO: Don't do this for the autocomplete pass + + //TODO: Don't do this for the autocomplete pass if ((needsDynamicCastMethod) && (mCurTypeDef->mTypeCode != BfTypeCode_Interface) && (mCurTypeDef->mTypeCode != BfTypeCode_Extension) && (!mCurTypeDef->mIsStatic) && (!isAutocomplete) && (!isAlias)) - { + { AddDynamicCastMethods(mCurTypeDef); - } + } bool isPayloadEnum = false; if (mCurTypeDef->mTypeCode == BfTypeCode_Enum) @@ -2322,7 +2321,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) if (mCurTypeDef->mTypeCode != BfTypeCode_Interface) { if ((hasStaticField) && (staticMarkMethod == NULL)) - { + { auto methodDef = AddMethod(mCurTypeDef, BfMethodType_Normal, BfProtection_Protected, true, BF_METHODNAME_MARKMEMBERS_STATIC, mIsComptime); methodDef->mIsNoReflect = true; } @@ -2334,7 +2333,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) } if ((hasNonStaticField) && (markMethod == NULL)) - { + { auto methodDef = AddMethod(mCurTypeDef, BfMethodType_Normal, BfProtection_Protected, false, BF_METHODNAME_MARKMEMBERS, mIsComptime); methodDef->mIsVirtual = true; methodDef->mIsOverride = true; @@ -2343,12 +2342,12 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) mCurTypeDef->mHasOverrideMethods = true; } } - + if (toStringMethod != NULL) wantsToString = false; - + if ((mCurTypeDef->mTypeCode == BfTypeCode_Enum) && (!isPayloadEnum) && (getUnderlyingMethod == NULL)) - { + { auto methodDef = new BfMethodDef(); mCurTypeDef->mMethods.push_back(methodDef); BF_ASSERT(mCurDeclaringTypeDef != NULL); @@ -2420,9 +2419,9 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) mCurTypeDef->mHasOverrideMethods = true; methodDef->mAddedAfterEmit = mIsComptime; } - + if ((needsEqualsMethod) && (equalsMethod == NULL) && (equalsOpMethod == NULL)) - { + { auto methodDef = new BfMethodDef(); mCurTypeDef->mMethods.push_back(methodDef); BF_ASSERT(mCurDeclaringTypeDef != NULL); @@ -2430,7 +2429,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) methodDef->mName = BF_METHODNAME_DEFAULT_EQUALS; methodDef->mReturnTypeRef = mSystem->mDirectBoolTypeRef; methodDef->mProtection = BfProtection_Private; - methodDef->mIsStatic = true; + methodDef->mIsStatic = true; AddParam(methodDef, mSystem->mDirectSelfTypeRef, "lhs"); AddParam(methodDef, mSystem->mDirectSelfTypeRef, "rhs"); methodDef->mAddedAfterEmit = mIsComptime; @@ -2465,12 +2464,12 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) { // Add in name so the hand-created methods can be compared by hash auto methodDef = mCurTypeDef->mMethods[methodIdx]; - methodDef->mIdx = methodIdx; - methodDef->mFullHash = HashString(methodDef->mName, methodDef->mFullHash); + methodDef->mIdx = methodIdx; + methodDef->mFullHash = HashString(methodDef->mName, methodDef->mFullHash); if (mSignatureHashCtx != NULL) mSignatureHashCtx->MixinStr(methodDef->mName); - - if ((methodDef->mAlwaysInline) || + + if ((methodDef->mAlwaysInline) || (methodDef->mHasAppend) || (methodDef->mMethodType == BfMethodType_Mixin)) inlineHashCtx.Mixin(methodDef->mFullHash); @@ -2478,14 +2477,14 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) if (mFullRefresh) methodDef->mCodeChanged = true; } - + mCurTypeDef->mInlineHash = inlineHashCtx.Finish128(); if (mSignatureHashCtx != NULL) { mCurTypeDef->mSignatureHash = mSignatureHashCtx->Finish128(); // We need to hash the signature in here because the preprocessor settings - // may change so the text is the same but the signature changes + // may change so the text is the same but the signature changes // so fullHash needs to change too mFullHashCtx->Mixin(mCurTypeDef->mSignatureHash); } @@ -2505,21 +2504,21 @@ void BfDefBuilder::Visit(BfUsingDirective* usingDirective) if (mResolvePassData != NULL) mResolvePassData->mExteriorAutocompleteCheckNodes.push_back(usingDirective); - String usingString = usingDirective->mNamespace->ToString(); + String usingString = usingDirective->mNamespace->ToString(); BfAtomComposite usingComposite; - mSystem->ParseAtomComposite(usingString, usingComposite, true); - + mSystem->ParseAtomComposite(usingString, usingComposite, true); + if (!mNamespaceSearch.Contains(usingComposite)) mNamespaceSearch.Insert(0, usingComposite); else - mSystem->ReleaseAtomComposite(usingComposite); + mSystem->ReleaseAtomComposite(usingComposite); } void BfDefBuilder::Visit(BfUsingModDirective* usingDirective) { if (mResolvePassData != NULL) mResolvePassData->mExteriorAutocompleteCheckNodes.push_back(usingDirective); - + if (usingDirective->mModToken->mToken == BfToken_Internal) { if (usingDirective->mTypeRef != NULL) @@ -2544,7 +2543,7 @@ void BfDefBuilder::Visit(BfNamespaceDeclaration* namespaceDeclaration) { auto blockNode = BfNodeDynCast(namespaceDeclaration->mBody); bool isFileLevel = (blockNode == NULL) && (namespaceDeclaration->mBody != NULL); - + if (mNamespaceBlockDepth < mFileLevelNamespaceState.mSize) { auto& prevNamespaceState = mFileLevelNamespaceState[mNamespaceBlockDepth]; @@ -2558,7 +2557,7 @@ void BfDefBuilder::Visit(BfNamespaceDeclaration* namespaceDeclaration) NamespaceState namespaceState; namespaceState.mNamespace = mNamespace; namespaceState.mNamespaceSearchCount = (int)mNamespaceSearch.size(); - + if (isFileLevel) { while (mNamespaceBlockDepth >= mFileLevelNamespaceState.mSize) @@ -2577,28 +2576,28 @@ void BfDefBuilder::Visit(BfNamespaceDeclaration* namespaceDeclaration) { BfAtom* namespaceAtom = mSystem->GetAtom(namespaceLeft); mNamespace.Set(mNamespace.mParts, mNamespace.mSize, &namespaceAtom, 1); - + if (!mNamespaceSearch.Contains(mNamespace)) { mSystem->RefAtomComposite(mNamespace); - mNamespaceSearch.Insert(0, mNamespace); + mNamespaceSearch.Insert(0, mNamespace); } mSystem->ReleaseAtom(namespaceAtom); break; } BfAtom* namespaceAtom = mSystem->GetAtom(namespaceLeft.Substring(0, dotIdx)); - mNamespace.Set(mNamespace.mParts, mNamespace.mSize, &namespaceAtom, 1); + mNamespace.Set(mNamespace.mParts, mNamespace.mSize, &namespaceAtom, 1); namespaceLeft = namespaceLeft.Substring(dotIdx + 1); - + if (!mNamespaceSearch.Contains(mNamespace)) { mSystem->RefAtomComposite(mNamespace); mNamespaceSearch.Insert(0, mNamespace); } - mSystem->ReleaseAtom(namespaceAtom); + mSystem->ReleaseAtom(namespaceAtom); } - + if (blockNode != NULL) { mNamespaceBlockDepth++; @@ -2618,4 +2617,4 @@ void BfDefBuilder::Visit(BfBlock* block) void BfDefBuilder::Visit(BfRootNode* rootNode) { VisitMembers(rootNode); -} +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfDefBuilder.h b/IDEHelper/Compiler/BfDefBuilder.h index 39fc134f..15ef96e1 100644 --- a/IDEHelper/Compiler/BfDefBuilder.h +++ b/IDEHelper/Compiler/BfDefBuilder.h @@ -39,14 +39,14 @@ public: Array mInternalAccessSet; HashContext* mFullHashCtx; HashContext* mSignatureHashCtx; - + Array mFileLevelNamespaceState; - int mNamespaceBlockDepth; + int mNamespaceBlockDepth; public: void ParseGenericParams(BfGenericParamsDeclaration* genericParamsDecl, BfGenericConstraintsDeclaration* genericConstraints, Array& genericParams, Array* externConstraintDefs, int outerGenericSize, bool isInGeneric); BfProtection GetProtection(BfAstNode* protectionNode); - bool WantsNode(BfAstNode* wholeNode, BfAstNode* startNode = NULL, int addLen = 0); + bool WantsNode(BfAstNode* wholeNode, BfAstNode* startNode = NULL, int addLen = 0); //static BfNamedTypeReference* AllocTypeReference(BfSource* bfSource, const StringImpl& typeName); //static BfResolvedTypeReference* AllocTypeReference(BfSource* bfSource, BfType* type); static BfFieldDef* AddField(BfTypeDef* typeDef, BfTypeReference* typeRef, const StringImpl& name); @@ -67,18 +67,18 @@ public: ~BfDefBuilder(); void Process(BfPassInstance* passInstance, BfSource* bfSource, bool fullRefresh); - void RemoveDefsFrom(BfSource* bfSource); - + void RemoveDefsFrom(BfSource* bfSource); + virtual void Visit(BfIdentifierNode* identifier) override; virtual void Visit(BfMethodDeclaration* methodDeclaration) override; virtual void Visit(BfConstructorDeclaration* ctorDeclaration) override; virtual void Visit(BfPropertyDeclaration* propertyDeclaration) override; - virtual void Visit(BfFieldDeclaration* fieldDeclaration) override; + virtual void Visit(BfFieldDeclaration* fieldDeclaration) override; virtual void Visit(BfEnumCaseDeclaration* enumCaseDeclaration) override; virtual void Visit(BfTypeDeclaration* typeDeclaration) override; virtual void Visit(BfUsingDirective* usingDirective) override; virtual void Visit(BfUsingModDirective* usingDirective) override; - virtual void Visit(BfNamespaceDeclaration* namespaceDeclaration) override; + virtual void Visit(BfNamespaceDeclaration* namespaceDeclaration) override; virtual void Visit(BfBlock* block) override; virtual void Visit(BfRootNode* rootNode) override; }; diff --git a/IDEHelper/Compiler/BfDeferEvalChecker.cpp b/IDEHelper/Compiler/BfDeferEvalChecker.cpp index 6a53b437..b583237f 100644 --- a/IDEHelper/Compiler/BfDeferEvalChecker.cpp +++ b/IDEHelper/Compiler/BfDeferEvalChecker.cpp @@ -8,14 +8,14 @@ BfDeferEvalChecker::BfDeferEvalChecker() mRootNode = NULL; mNeedsDeferEval = false; mDeferLiterals = true; - mDeferDelegateBind = true; + mDeferDelegateBind = true; } void BfDeferEvalChecker::Check(BfAstNode* node) { if (auto namedNode = BfNodeDynCastExact(node)) node = namedNode->mExpression; - + if (node == NULL) return; @@ -46,16 +46,16 @@ void BfDeferEvalChecker::Visit(BfLiteralExpression* literalExpr) case BfTypeCode_Boolean: case BfTypeCode_Char8: case BfTypeCode_Int8: - case BfTypeCode_UInt8: - case BfTypeCode_Int16: + case BfTypeCode_UInt8: + case BfTypeCode_Int16: case BfTypeCode_UInt16: case BfTypeCode_Int32: - case BfTypeCode_UInt32: - case BfTypeCode_Int64: + case BfTypeCode_UInt32: + case BfTypeCode_Int64: case BfTypeCode_UInt64: - case BfTypeCode_IntPtr: + case BfTypeCode_IntPtr: case BfTypeCode_UIntPtr: - case BfTypeCode_IntUnknown: + case BfTypeCode_IntUnknown: case BfTypeCode_UIntUnknown: if (mDeferLiterals) mNeedsDeferEval = true; @@ -63,11 +63,10 @@ void BfDeferEvalChecker::Visit(BfLiteralExpression* literalExpr) default: mNeedsDeferEval = false; } - } void BfDeferEvalChecker::Visit(BfCastExpression* castExpr) -{ +{ if (auto namedTypeRef = BfNodeDynCastExact(castExpr->mTypeRef)) { if (namedTypeRef->ToString() == "ExpectedType") @@ -122,11 +121,11 @@ void BfDeferEvalChecker::Visit(BfDelegateBindExpression* delegateBindExpr) } void BfDeferEvalChecker::Visit(BfConditionalExpression* condExpr) -{ +{ VisitChild(condExpr->mConditionExpression); bool prev = mNeedsDeferEval; VisitChild(condExpr->mTrueExpression); - prev |= mNeedsDeferEval; + prev |= mNeedsDeferEval; VisitChild(condExpr->mFalseExpression); mNeedsDeferEval |= prev; } @@ -154,7 +153,7 @@ void BfDeferEvalChecker::Visit(BfObjectCreateExpression * objCreateExpr) { if (objCreateExpr->mTypeRef->IsExact()) mNeedsDeferEval = true; - } + } } void BfDeferEvalChecker::Visit(BfBinaryOperatorExpression* binOpExpr) @@ -170,14 +169,14 @@ void BfDeferEvalChecker::Visit(BfBinaryOperatorExpression* binOpExpr) case BfBinaryOp_BitwiseOr: case BfBinaryOp_ExclusiveOr: case BfBinaryOp_LeftShift: - case BfBinaryOp_RightShift: + case BfBinaryOp_RightShift: case BfBinaryOp_GreaterThan: case BfBinaryOp_LessThan: case BfBinaryOp_GreaterThanOrEqual: case BfBinaryOp_LessThanOrEqual: { VisitChild(binOpExpr->mLeft); - bool prev = mNeedsDeferEval; + bool prev = mNeedsDeferEval; VisitChild(binOpExpr->mRight); mNeedsDeferEval |= prev; } @@ -188,7 +187,7 @@ void BfDeferEvalChecker::Visit(BfBinaryOperatorExpression* binOpExpr) } void BfDeferEvalChecker::Visit(BfDefaultExpression* defaultExpr) -{ +{ if (defaultExpr->mTypeRef == NULL) mNeedsDeferEval = true; } @@ -197,5 +196,4 @@ void BfDeferEvalChecker::Visit(BfVariableDeclaration* varDecl) { if (varDecl != mRootNode) mNeedsDeferEval = true; -} - +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfDeferEvalChecker.h b/IDEHelper/Compiler/BfDeferEvalChecker.h index 05877119..7d46fb15 100644 --- a/IDEHelper/Compiler/BfDeferEvalChecker.h +++ b/IDEHelper/Compiler/BfDeferEvalChecker.h @@ -11,7 +11,7 @@ public: BfAstNode* mRootNode; bool mNeedsDeferEval; bool mDeferDelegateBind; - bool mDeferLiterals; + bool mDeferLiterals; public: BfDeferEvalChecker(); @@ -19,7 +19,7 @@ public: void Check(BfAstNode* node); virtual void Visit(BfAstNode* node) override; - + virtual void Visit(BfAttributedExpression* attributedExpr) override; virtual void Visit(BfInitializerExpression* collectionInitExpr) override; virtual void Visit(BfLiteralExpression* literalExpr) override; @@ -38,5 +38,4 @@ public: virtual void Visit(BfVariableDeclaration* varDecl) override; }; - NS_BF_END \ No newline at end of file diff --git a/IDEHelper/Compiler/BfDemangler.cpp b/IDEHelper/Compiler/BfDemangler.cpp index 9df61596..4747d6f1 100644 --- a/IDEHelper/Compiler/BfDemangler.cpp +++ b/IDEHelper/Compiler/BfDemangler.cpp @@ -11,7 +11,7 @@ static char SafeGetChar(const StringImpl& str, int idx) DemangleBase::DemangleBase() { - mCurIdx = 0; + mCurIdx = 0; mFailed = false; mLanguage = DbgLanguage_Unknown; mInArgs = false; @@ -20,30 +20,30 @@ DemangleBase::DemangleBase() bool DemangleBase::Failed() { - //BF_DBG_FATAL("DwDemangler::Failed"); + //BF_DBG_FATAL("DwDemangler::Failed"); mFailed = true; return false; } void DemangleBase::Require(bool result) { - //BF_ASSERT(result); + //BF_ASSERT(result); if (!result) { - mFailed = true; + mFailed = true; } } ////////////////////////////////////////////////////////////////////////// DwDemangler::DwDemangler() -{ +{ mOmitSubstituteAdd = false; mIsFirstName = true; mTemplateDepth = 0; mCaptureTargetType = false; mFunctionPopSubstitute = false; - mRawDemangle = false; + mRawDemangle = false; } #define RETURN_STR(strVal) do { outName = strVal; return true; } while(false) @@ -54,11 +54,11 @@ bool DwDemangler::DemangleBuiltinType(StringImpl& outName) switch (firstChar) { case 'v': - RETURN_STR("void"); + RETURN_STR("void"); case 'w': RETURN_STR("wchar_t"); case 'b': - RETURN_STR("bool"); + RETURN_STR("bool"); case 'a': if (mLanguage == DbgLanguage_Beef) RETURN_STR("int8"); @@ -95,7 +95,7 @@ bool DwDemangler::DemangleBuiltinType(StringImpl& outName) RETURN_STR("uint32"); else RETURN_STR("uint"); - case 'y': + case 'y': RETURN_STR("ulong"); case 'c': if (mLanguage == DbgLanguage_Beef) @@ -149,9 +149,8 @@ bool DwDemangler::DemangleArrayType(StringImpl& outName) /*auto firstChar = SafeGetChar(mMangledName, mCurIdx++); switch (firstChar) { - case 'A': + case 'A': { - } break; default: @@ -169,7 +168,7 @@ bool DwDemangler::DemangleClassEnumType(StringImpl& outName) } bool DwDemangler::DemangleFunction(StringImpl& outName) -{ +{ bool wantsReturnValue = false; //String outName; bool hasTemplateArgs; @@ -189,7 +188,7 @@ bool DwDemangler::DemangleFunction(StringImpl& outName) { DwDemangler subDemangler; outName.Remove(0, lastAt + 1); - outName = subDemangler.Demangle(outName); + outName = subDemangler.Demangle(outName); return true; } int lastDot = (int)outName.LastIndexOf('.'); @@ -197,7 +196,7 @@ bool DwDemangler::DemangleFunction(StringImpl& outName) outName.RemoveToEnd(lastDot); return true; } - + // New if (mFunctionPopSubstitute) { @@ -206,7 +205,7 @@ bool DwDemangler::DemangleFunction(StringImpl& outName) mSubstituteList.pop_back(); mFunctionPopSubstitute = false; } - + if (mCurIdx < (int) mMangledName.length()) { //TODO: Needed? Caused a crash. mSubstituteList.pop_back(); // Remove method name @@ -231,15 +230,15 @@ bool DwDemangler::DemangleFunction(StringImpl& outName) for (int paramIdx = 0; mCurIdx < (int)mMangledName.length(); paramIdx++) { - if (SafeGetChar(mMangledName, mCurIdx) == 'E') - break; + if (SafeGetChar(mMangledName, mCurIdx) == 'E') + break; if (needsComma) outName += ", "; - + StringT<256> paramType; Require(DemangleType(paramType)); - + bool atEnd = mCurIdx >= (int) mMangledName.length(); if ((paramIdx == 0) && (wantsReturnValue)) { @@ -323,7 +322,7 @@ bool DwDemangler::DemangleType(StringImpl& outName) auto firstChar = SafeGetChar(mMangledName, mCurIdx++); switch (firstChar) - { + { case 'D': { auto nextChar = SafeGetChar(mMangledName, mCurIdx++); @@ -376,13 +375,13 @@ bool DwDemangler::DemangleType(StringImpl& outName) outName = modName + " " + outName; return true; } - break; - //TODO: 'C', 'G', 'U' + break; + //TODO: 'C', 'G', 'U' default: mCurIdx--; break; - } - + } + if (DemangleBuiltinType(outName)) return true; if (DemangleFunctionType(outName)) @@ -402,11 +401,11 @@ bool DwDemangler::DemangleType(StringImpl& outName) if (DemangleClassEnumType(outName)) return true; //TODO: DemangleArrayType - //TODO: DemanglePointerToMemberType + //TODO: DemanglePointerToMemberType if (DemangleTemplateParam(outName)) return true; //TODO: TemplateTemplateParam - //TODO: DeclType + //TODO: DeclType return false; } @@ -447,9 +446,8 @@ bool DwDemangler::DemangleNestedName(StringImpl& outName) { case 'N': { - } - break; + break; } mCurIdx--; @@ -480,18 +478,17 @@ bool DwDemangler::DemangleRefQualifier(StringImpl& outName) case 'R': RETURN_STR("&"); case 'O': - RETURN_STR("&&"); + RETURN_STR("&&"); } mCurIdx--; return false; } - bool DwDemangler::DemangleOperatorName(StringImpl& outName) { - auto firstChar = SafeGetChar(mMangledName, mCurIdx++); + auto firstChar = SafeGetChar(mMangledName, mCurIdx++); StringT<64> opCode; - opCode += firstChar; + opCode += firstChar; opCode += SafeGetChar(mMangledName, mCurIdx++); StringT<64> opName; @@ -544,7 +541,7 @@ bool DwDemangler::DemangleOperatorName(StringImpl& outName) else if (opCode == "eq") opName = "=="; else if (opCode == "ne") - opName = "!="; + opName = "!="; else if (opCode == "lt") opName = "<"; else if (opCode == "gt") @@ -612,15 +609,15 @@ bool DwDemangler::DemangleOperatorName(StringImpl& outName) if (!opName.empty()) outName += "operator" + opName; //mSubstituteList.push_back(outName); - + return true; } bool DwDemangler::DemangleSourceName(StringImpl& outName) { - auto c = SafeGetChar(mMangledName, mCurIdx); + auto c = SafeGetChar(mMangledName, mCurIdx); if ((c >= '0') && (c <= '9')) - { + { int nameLen = 0; while (mCurIdx < (int) mMangledName.length()) { @@ -644,7 +641,7 @@ bool DwDemangler::DemangleSourceName(StringImpl& outName) return true; } - return false; + return false; } bool DwDemangler::DemangleUnqualifiedName(StringImpl& outName) @@ -652,12 +649,12 @@ bool DwDemangler::DemangleUnqualifiedName(StringImpl& outName) if (DemangleOperatorName(outName)) // Also handles ctor/dtor return true; if (DemangleSourceName(outName)) - return true; + return true; return false; } bool DwDemangler::DemangleEnd() -{ +{ auto firstChar = SafeGetChar(mMangledName, mCurIdx++); if (firstChar == 'E') return true; @@ -704,7 +701,6 @@ bool DwDemangler::DemangleExprPriamry(StringImpl& outName) return false; } - bool DwDemangler::DemangleTemplateArg(StringImpl& outName) { if (DemangleType(outName)) @@ -716,7 +712,7 @@ bool DwDemangler::DemangleTemplateArg(StringImpl& outName) } bool DwDemangler::DemangleTemplateArgs(StringImpl& outName) -{ +{ auto firstChar = SafeGetChar(mMangledName, mCurIdx++); if (firstChar == 'I') { @@ -728,7 +724,7 @@ bool DwDemangler::DemangleTemplateArgs(StringImpl& outName) bool inParamPack = false; bool foundEnd = false; bool needsComma = false; - + outName = "<"; for (int argIdx = 0; true; argIdx++) { @@ -737,9 +733,9 @@ bool DwDemangler::DemangleTemplateArgs(StringImpl& outName) if (DemangleEnd()) { - if (inParamPack) + if (inParamPack) { - inParamPack = false; + inParamPack = false; continue; } else @@ -782,7 +778,7 @@ bool DwDemangler::DemangleSubstitution(StringImpl& outName) bool hadChars = 0; while (true) { - char idxChar = SafeGetChar(mMangledName, mCurIdx++); + char idxChar = SafeGetChar(mMangledName, mCurIdx++); if (idxChar == 't') { DemangleUnqualifiedName(outName); @@ -804,7 +800,7 @@ bool DwDemangler::DemangleSubstitution(StringImpl& outName) { RETURN_STR("std.string"); } - if (idxChar == 'i') + if (idxChar == 'i') { RETURN_STR("std.basic_istream>"); } @@ -853,7 +849,7 @@ bool DwDemangler::DemangleTemplateParam(StringImpl& outName) bool hadChars = 0; while (true) { - char idxChar = SafeGetChar(mMangledName, mCurIdx++); + char idxChar = SafeGetChar(mMangledName, mCurIdx++); if (idxChar == '?') break; if (idxChar == '_') @@ -887,7 +883,7 @@ bool DwDemangler::DemangleUnscopedName(StringImpl& outName) if (DemangleUnqualifiedName(outName)) return true; if (DemangleSubstitution(outName)) - return true; + return true; return false; } @@ -899,17 +895,17 @@ bool DwDemangler::DemangleName(StringImpl& outName, bool* outHasTemplateArgs) switch (firstChar) { case 'N': // NestedName - { + { StringT<64> cvQualifier; if (DemangleCVQualifiers(cvQualifier)) outName += cvQualifier + " "; StringT<64> refQualifier; if (DemangleRefQualifier(refQualifier)) - outName += refQualifier + " "; + outName += refQualifier + " "; int nameCount = 0; while ((!DemangleEnd()) && (!mFailed)) - { + { StringT<128> unqualifiedName; mOmitSubstituteAdd = false; if ((DemangleUnscopedName(unqualifiedName)) || @@ -917,7 +913,7 @@ bool DwDemangler::DemangleName(StringImpl& outName, bool* outHasTemplateArgs) { if (outHasTemplateArgs != NULL) *outHasTemplateArgs = false; - if (nameCount > 0) + if (nameCount > 0) { if (mLanguage == DbgLanguage_Beef) outName += "."; @@ -932,7 +928,7 @@ bool DwDemangler::DemangleName(StringImpl& outName, bool* outHasTemplateArgs) nameCount++; continue; } - + StringT<128> templateArgs; if (DemangleTemplateArgs(templateArgs)) { @@ -974,11 +970,11 @@ bool DwDemangler::DemangleName(StringImpl& outName, bool* outHasTemplateArgs) } continue; } - + Failed(); break; } - + return true; } break; @@ -997,7 +993,7 @@ bool DwDemangler::DemangleName(StringImpl& outName, bool* outHasTemplateArgs) { if (outHasTemplateArgs != NULL) *outHasTemplateArgs = true; - outName += templateArgs; + outName += templateArgs; } if ((outName.length() > 0) && (outName[outName.length() - 1] == '.')) @@ -1012,11 +1008,11 @@ bool DwDemangler::DemangleName(StringImpl& outName, bool* outHasTemplateArgs) else { Failed(); - } + } } return true; - } + } if (DemangleLocalName(outName)) return true; @@ -1026,7 +1022,7 @@ bool DwDemangler::DemangleName(StringImpl& outName, bool* outHasTemplateArgs) String DwDemangler::Demangle(const StringImpl& mangledName) { - BF_ASSERT(mCurIdx == 0); + BF_ASSERT(mCurIdx == 0); /*String overrideVal = "_ZZL9DumpStatsP16TCMalloc_PrinteriE3MiB"; //String overrideVal = "_ZN3Hey4Dude3Bro9TestClass7MethodBEivf"; @@ -1047,16 +1043,16 @@ String DwDemangler::Demangle(const StringImpl& mangledName) //"__ZN6System6String6ConcatEU6paramsPNS_6Array1INS_6ObjectEEE"; //_ZNSt3mapI3HeyfSt4lessIiESaISt4pairIKifEEEixES_S0_S1_S2_S3_S4_S5_S6_ String overrideDemangled; - if (mangledName != overrideVal) + if (mangledName != overrideVal) { BfDemangler demangler; overrideDemangled = demangler.Demangle(overrideVal); }*/ - - mMangledName = mangledName; + + mMangledName = mangledName; String outStr; - + if (mangledName.length() < 3) return mangledName; @@ -1098,7 +1094,7 @@ String DwDemangler::Demangle(const StringImpl& mangledName) { mCurIdx++; char typeChar2 = SafeGetChar(mangledName, mCurIdx++); - if (typeChar2 == 'S') + if (typeChar2 == 'S') { // typeinfo } @@ -1110,7 +1106,7 @@ String DwDemangler::Demangle(const StringImpl& mangledName) { return mangledName; } - } + } else if (typeChar == 'S') { mayHaveParams = false; @@ -1148,12 +1144,12 @@ MsDemangler::MsDemangler() } bool MsDemangler::DemangleString(StringImpl& outName) -{ +{ while (true) { char c = SafeGetChar(mMangledName, mCurIdx++); if ((c == '!') || (c == '?')) - return Failed(); + return Failed(); if (c == '@') break; outName.Append(c); @@ -1175,7 +1171,7 @@ bool MsDemangler::DemangleTemplateName(StringImpl& outName, String* primaryName) { String paramType; if (!DemangleType(paramType)) - break; + break; if (paramIdx > 0) outName += ", "; outName += paramType; @@ -1185,21 +1181,20 @@ bool MsDemangler::DemangleTemplateName(StringImpl& outName, String* primaryName) return true; } - bool MsDemangler::DemangleScopedName(StringImpl& outName, String* primaryName) -{ +{ for (int nameIdx = 0; true; nameIdx++) { if (mFailed) return false; - char c = SafeGetChar(mMangledName, mCurIdx++); + char c = SafeGetChar(mMangledName, mCurIdx++); if (c == '@') return true; /*{ - if (curScope.length() == 0) - return true; + if (curScope.length() == 0) + return true; if (nameIdx == 0) { if (primaryName != NULL) @@ -1220,11 +1215,11 @@ bool MsDemangler::DemangleScopedName(StringImpl& outName, String* primaryName) { c = SafeGetChar(mMangledName, mCurIdx++); if (c == '$') - { + { SubstituteList oldSubList = mSubstituteList; mSubstituteList.Clear(); DemangleTemplateName(namePart, /*primaryName*/NULL); - mSubstituteList = oldSubList; + mSubstituteList = oldSubList; } else if (c == '?') { @@ -1236,10 +1231,9 @@ bool MsDemangler::DemangleScopedName(StringImpl& outName, String* primaryName) int num = DemangleNumber(); outName = StrFormat("%d", num); } - } else if ((c >= '0') && (c <= '9')) - { + { int subIdx = c - '0'; if (subIdx < mSubstituteList.size()) { @@ -1252,25 +1246,25 @@ bool MsDemangler::DemangleScopedName(StringImpl& outName, String* primaryName) } else { - mCurIdx--; - Require(DemangleString(namePart)); + mCurIdx--; + Require(DemangleString(namePart)); } if (nameIdx == 0) - { + { //We moved this down so we get the template args for the ctor name /*if ((primaryName != NULL) && (primaryName->empty())) *primaryName = namePart;*/ outName = namePart; if ((primaryName != NULL) && (primaryName->empty())) - *primaryName = namePart; + *primaryName = namePart; } else if (mLanguage == DbgLanguage_Beef) { if ((mBeefFixed) && (namePart == "bf")) namePart.Clear(); - if (!namePart.IsEmpty()) + if (!namePart.IsEmpty()) outName = namePart + "." + outName; } else @@ -1285,7 +1279,7 @@ bool MsDemangler::DemangleScopedName(StringImpl& outName, String* primaryName) bool MsDemangler::DemangleModifiedType(StringImpl& outName, bool isPtr) { String modifier; - DemangleCV(modifier); + DemangleCV(modifier); char c = SafeGetChar(mMangledName, mCurIdx); if (c == 'Y') // Sized array @@ -1323,7 +1317,7 @@ bool MsDemangler::DemangleType(StringImpl& outName) return false; switch (c) - { + { case '0': case '1': case '2': @@ -1418,7 +1412,7 @@ bool MsDemangler::DemangleType(StringImpl& outName) char c = SafeGetChar(mMangledName, mCurIdx++); if (c == 'C') { - String modifier; + String modifier; DemangleCV(modifier); DemangleType(outName); outName = modifier + " " + outName; @@ -1426,7 +1420,7 @@ bool MsDemangler::DemangleType(StringImpl& outName) } else if (c == 'Q') { - String modifier; + String modifier; DemangleCV(modifier); DemangleType(outName); outName = modifier + " " + outName; @@ -1435,7 +1429,6 @@ bool MsDemangler::DemangleType(StringImpl& outName) } break; } - } break; @@ -1443,7 +1436,7 @@ bool MsDemangler::DemangleType(StringImpl& outName) { c = SafeGetChar(mMangledName, mCurIdx++); switch (c) - { + { case 'D': outName = "int8"; return true; @@ -1485,20 +1478,20 @@ bool MsDemangler::DemangleType(StringImpl& outName) break; } } - break; + break; case 'A': { DemangleModifiedType(outName, false); - outName += "&"; + outName += "&"; } return true; case 'B': DemangleModifiedType(outName, false); outName = "volatile " + outName + "&"; return true; - case 'P': - DemangleModifiedType(outName, true); + case 'P': + DemangleModifiedType(outName, true); return true; case 'Q': DemangleModifiedType(outName, true); @@ -1587,7 +1580,7 @@ bool MsDemangler::DemangleType(StringImpl& outName) case 'X': outName += "void"; return true; - case '?': + case '?': if (mInArgs) { int num = DemangleNumber(); @@ -1607,13 +1600,13 @@ bool MsDemangler::DemangleType(StringImpl& outName) } int MsDemangler::DemangleNumber() -{ +{ char c = SafeGetChar(mMangledName, mCurIdx++); bool isSigned = false; if (c == '?') - { + { isSigned = true; - c = SafeGetChar(mMangledName, mCurIdx++); + c = SafeGetChar(mMangledName, mCurIdx++); } if ((c >= '0') && (c <= '9')) @@ -1625,7 +1618,7 @@ int MsDemangler::DemangleNumber() while ((c >= 'A') && (c <= 'P')) { val = (val * 0x10) + (c - 'A'); - c = SafeGetChar(mMangledName, mCurIdx++); + c = SafeGetChar(mMangledName, mCurIdx++); } if (c != '@') @@ -1721,7 +1714,7 @@ bool MsDemangler::DemangleName(StringImpl& outName) char c = SafeGetChar(mMangledName, mCurIdx++); if (c == '?') - { + { c = SafeGetChar(mMangledName, mCurIdx++); if (c == '$') { @@ -1736,7 +1729,7 @@ bool MsDemangler::DemangleName(StringImpl& outName) switch (c) { case '0': - // Ctor + // Ctor Require(DemangleScopedName(outName, &primaryName)); if (mLanguage == DbgLanguage_Beef) outName += ".this"; @@ -1747,9 +1740,9 @@ bool MsDemangler::DemangleName(StringImpl& outName) // Dtor Require(DemangleScopedName(outName, &primaryName)); if (mLanguage == DbgLanguage_Beef) - outName += ".~this"; + outName += ".~this"; else - outName += "::~" + primaryName; + outName += "::~" + primaryName; break; case '2': funcName = "operator new"; break; case '3': funcName = "operator delete"; break; @@ -1760,7 +1753,7 @@ bool MsDemangler::DemangleName(StringImpl& outName) case '8': funcName = "operator=="; break; case '9': funcName = "operator!="; break; case 'A': funcName = "operator[]"; break; - case 'B': + case 'B': funcName = "operator "; appendRetType = true; break; @@ -1818,15 +1811,15 @@ bool MsDemangler::DemangleName(StringImpl& outName) case 'M': funcName = "`eh vector destructor iterator'"; break; case 'N': funcName = "`eh vector vbase constructor iterator'"; break; case 'O': funcName = "`copy constructor closure'"; break; - case 'R': + case 'R': c = SafeGetChar(mMangledName, mCurIdx++); switch (c) { case 0: funcName = "`RTTI Type Descriptor'"; break; - case 1: funcName = "`RTTI Class Descriptor'"; break; + case 1: funcName = "`RTTI Class Descriptor'"; break; case '2': funcName = "`RTTI Base Class Array'"; break; case '3': funcName = "`RTTI Class Hierarchy Descriptor'"; break; - case '4': funcName = "`RTTI Complete Object Locater"; break; + case '4': funcName = "`RTTI Complete Object Locater"; break; } break; case 'S': funcName = "`local vftable'"; break; @@ -1834,12 +1827,12 @@ bool MsDemangler::DemangleName(StringImpl& outName) case 'U': funcName = "operator new[]"; break; case 'V': funcName = "operator delete[]"; break; case 'X': funcName = "`placement delete closure'"; break; - case 'Y': funcName = "`placement delete[] closure'"; break; + case 'Y': funcName = "`placement delete[] closure'"; break; } } - break; + break; default: - mCurIdx -= 2; + mCurIdx -= 2; break; } @@ -1876,7 +1869,7 @@ bool MsDemangler::DemangleName(StringImpl& outName) if (!scopeName.empty()) { if (mLanguage == DbgLanguage_Beef) - { + { scopeName += "."; } else @@ -1967,7 +1960,7 @@ bool MsDemangler::DemangleName(StringImpl& outName) { // Global variable / static member String varType; - Require(DemangleType(varType)); + Require(DemangleType(varType)); c = SafeGetChar(mMangledName, mCurIdx++); // 0 = private, 1 = protected, 2 = public @@ -1975,11 +1968,11 @@ bool MsDemangler::DemangleName(StringImpl& outName) } return true; - } + } - // Method attribute + // Method attribute if (c == 0) - return true; + return true; struct { @@ -1993,7 +1986,7 @@ bool MsDemangler::DemangleName(StringImpl& outName) //int funcTypeVal = c - 'A'; //int accessType = funcTypeVal >> 3; - //bool isNonMember = c == 'Y'; + //bool isNonMember = c == 'Y'; //bool isVirtual = (c == 'E') || (c == 'M') || (c == 'U'); //bool hasThis = isVirtual || (c == 'A') || (c == 'I') || (c == 'Q'); @@ -2010,15 +2003,15 @@ bool MsDemangler::DemangleName(StringImpl& outName) } // Calling convention - c = SafeGetChar(mMangledName, mCurIdx++); + c = SafeGetChar(mMangledName, mCurIdx++); union - { + { uint8 mDllExport : 1; - uint8 mCallingConv : 7; // cdecl, pascal, thiscall, stdcall, fastcall + uint8 mCallingConv : 7; // cdecl, pascal, thiscall, stdcall, fastcall } callType; *((uint8*)&callType) = (c - 'A'); - if (callType.mCallingConv > 6) + if (callType.mCallingConv > 6) return Failed(); String retType; @@ -2071,7 +2064,6 @@ String MsDemangler::Demangle(const StringImpl& mangledName) return outName; } - ////////////////////////////////////////////////////////////////////////// MsDemangleScanner::MsDemangleScanner() @@ -2081,14 +2073,14 @@ MsDemangleScanner::MsDemangleScanner() } bool MsDemangleScanner::DemangleString() -{ +{ while (true) { char c = SafeGetChar(mMangledName, mCurIdx++); if ((c == '!') || (c == '?')) - return Failed(); + return Failed(); if (c == '@') - break; + break; } //mSubstituteList.push_back(outName); @@ -2097,26 +2089,25 @@ bool MsDemangleScanner::DemangleString() bool MsDemangleScanner::DemangleTemplateName() { - DemangleString(); - + DemangleString(); + for (int paramIdx = 0; true; paramIdx++) - { + { if (!DemangleType()) - break; - } + break; + } return true; } - bool MsDemangleScanner::DemangleScopedName() -{ +{ for (int nameIdx = 0; true; nameIdx++) { if (mFailed) return false; - char c = SafeGetChar(mMangledName, mCurIdx++); + char c = SafeGetChar(mMangledName, mCurIdx++); if (c == '@') return true; @@ -2125,7 +2116,7 @@ bool MsDemangleScanner::DemangleScopedName() c = SafeGetChar(mMangledName, mCurIdx++); if (c == '$') { - DemangleTemplateName(); + DemangleTemplateName(); } else if (c == '?') { @@ -2134,12 +2125,11 @@ bool MsDemangleScanner::DemangleScopedName() else { mCurIdx--; - int num = DemangleNumber(); + int num = DemangleNumber(); } - } else if ((c >= '0') && (c <= '9')) - { + { int subIdx = c - '0'; if (subIdx < mSubstituteList.size()) { @@ -2152,33 +2142,33 @@ bool MsDemangleScanner::DemangleScopedName() } else { - mCurIdx--; + mCurIdx--; Require(DemangleString()); - } + } } } bool MsDemangleScanner::DemangleModifiedType(bool isPtr) -{ - DemangleCV(); +{ + DemangleCV(); char c = SafeGetChar(mMangledName, mCurIdx); if (c == 'Y') // Sized array - { + { mCurIdx++; int dimCount = DemangleNumber(); for (int dim = 0; dim < dimCount; dim++) { - int dimSize = DemangleNumber(); + int dimSize = DemangleNumber(); } - DemangleType(); + DemangleType(); } else { - DemangleType(); + DemangleType(); } - + return true; } @@ -2189,7 +2179,7 @@ bool MsDemangleScanner::DemangleType() return false; switch (c) - { + { case '0': case '1': case '2': @@ -2205,11 +2195,11 @@ bool MsDemangleScanner::DemangleType() return false; int subIdx = c - '0'; if ((subIdx < 0) || (subIdx >= (int)mSubstituteList.size())) - return Failed(); + return Failed(); return true; } break; - + case '$': { char c = SafeGetChar(mMangledName, mCurIdx++); @@ -2249,79 +2239,78 @@ bool MsDemangleScanner::DemangleType() { char c = SafeGetChar(mMangledName, mCurIdx++); if (c == 'C') - { + { DemangleCV(); - DemangleType(); + DemangleType(); return true; } else if (c == 'Q') - { + { DemangleCV(); - DemangleType(); + DemangleType(); return true; } } break; } - } break; - + case '_': { c = SafeGetChar(mMangledName, mCurIdx++); switch (c) - { - case 'D': + { + case 'D': return true; - case 'E': + case 'E': return true; - case 'F': + case 'F': return true; - case 'G': + case 'G': return true; - case 'H': + case 'H': return true; - case 'I': + case 'I': return true; - case 'J': + case 'J': return true; - case 'K': + case 'K': return true; - case 'L': + case 'L': return true; - case 'M': + case 'M': return true; - case 'W': + case 'W': return true; - case 'N': + case 'N': return true; default: return Failed(); break; } } - break; + break; case 'A': { - DemangleModifiedType(false); + DemangleModifiedType(false); } return true; case 'B': - DemangleModifiedType(false); + DemangleModifiedType(false); return true; - case 'P': - DemangleModifiedType(true); + case 'P': + DemangleModifiedType(true); return true; case 'Q': - DemangleModifiedType(true); + DemangleModifiedType(true); return true; case 'R': - DemangleModifiedType(true); + DemangleModifiedType(true); return true; case 'S': - DemangleModifiedType(true); + DemangleModifiedType(true); return true; case 'T': // union @@ -2341,20 +2330,20 @@ bool MsDemangleScanner::DemangleType() Require((c >= '0') && (c <= '8')); DemangleScopedName(); return true; - - case 'C': + + case 'C': return true; - case 'D': + case 'D': return true; - case 'E': + case 'E': return true; - case 'F': + case 'F': return true; - case 'G': + case 'G': return true; - case 'H': + case 'H': return true; - case 'I': + case 'I': return true; case 'J': return true; @@ -2362,13 +2351,13 @@ bool MsDemangleScanner::DemangleType() return true; case 'M': return true; - case 'N': + case 'N': return true; - case 'O': + case 'O': return true; - case 'X': + case 'X': return true; - case '?': + case '?': if (mInArgs) { int num = DemangleNumber(); @@ -2388,13 +2377,13 @@ bool MsDemangleScanner::DemangleType() } int MsDemangleScanner::DemangleNumber() -{ +{ char c = SafeGetChar(mMangledName, mCurIdx++); bool isSigned = false; if (c == '?') - { + { isSigned = true; - c = SafeGetChar(mMangledName, mCurIdx++); + c = SafeGetChar(mMangledName, mCurIdx++); } if ((c >= '0') && (c <= '9')) @@ -2406,7 +2395,7 @@ int MsDemangleScanner::DemangleNumber() while ((c >= 'A') && (c <= 'P')) { val = (val * 10) + (c - 'A'); - c = SafeGetChar(mMangledName, mCurIdx++); + c = SafeGetChar(mMangledName, mCurIdx++); } if (c != '@') @@ -2416,7 +2405,7 @@ int MsDemangleScanner::DemangleNumber() } bool MsDemangleScanner::DemangleCV() -{ +{ while (true) { char c = SafeGetChar(mMangledName, mCurIdx++); @@ -2437,9 +2426,9 @@ bool MsDemangleScanner::DemangleCV() break; } mCurIdx--; - + char c = SafeGetChar(mMangledName, mCurIdx++); - int constVal = 0; + int constVal = 0; if ((c < 'A') || (c > 'X')) { return Failed(); @@ -2455,7 +2444,7 @@ bool MsDemangleScanner::DemangleName() char c = SafeGetChar(mMangledName, mCurIdx++); if (c == '?') - { + { // A ?? is always a function return true; } @@ -2469,16 +2458,16 @@ bool MsDemangleScanner::DemangleName() if ((c >= '0') && (c <= '9')) { // Global variable / static member - mIsData = true; + mIsData = true; return true; - } + } // Not data - return true; + return true; } void MsDemangleScanner::Process(const StringImpl& mangledName) -{ +{ mMangledName = mangledName; char c = mangledName[mCurIdx++]; @@ -2489,13 +2478,13 @@ void MsDemangleScanner::Process(const StringImpl& mangledName) if (mFailed) { mIsData = false; - } + } } ////////////////////////////////////////////////////////////////////////// String BfDemangler::Demangle(const StringImpl& mangledName, DbgLanguage language, Flags flags) -{ +{ if (mangledName.IsEmpty()) return ""; if (mangledName[0] == '?') @@ -2525,5 +2514,4 @@ bool BfDemangler::IsData(const StringImpl& mangledName) return demangler.mIsData; } return false; -} - +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfDemangler.h b/IDEHelper/Compiler/BfDemangler.h index 1173153c..ac771dcf 100644 --- a/IDEHelper/Compiler/BfDemangler.h +++ b/IDEHelper/Compiler/BfDemangler.h @@ -14,7 +14,7 @@ public: int mCurIdx; String mResult; bool mFailed; - String mMangledName; + String mMangledName; SubstituteList mSubstituteList; bool mInArgs; bool mBeefFixed; @@ -28,25 +28,25 @@ public: class DwDemangler : public DemangleBase { -public: +public: SubstituteList mTemplateList; bool mIsFirstName; - int mTemplateDepth; - bool mOmitSubstituteAdd; + int mTemplateDepth; + bool mOmitSubstituteAdd; bool mCaptureTargetType; bool mFunctionPopSubstitute; - bool mRawDemangle; + bool mRawDemangle; -public: +public: bool DemangleEnd(); bool DemangleArrayType(StringImpl& outName); bool DemangleBuiltinType(StringImpl& outName); bool DemangleFunctionType(StringImpl& outName); bool DemangleSourceName(StringImpl& outName); - bool DemangleRefQualifier(StringImpl& outName); + bool DemangleRefQualifier(StringImpl& outName); bool DemangleType(StringImpl& outName); bool DemangleNestedName(StringImpl& outName); - bool DemangleCVQualifiers(StringImpl& outName); + bool DemangleCVQualifiers(StringImpl& outName); bool DemangleOperatorName(StringImpl& outName); bool DemangleExprPriamry(StringImpl& outName); bool DemangleTemplateArgPack(StringImpl& outName); @@ -62,7 +62,7 @@ public: bool DemangleName(StringImpl& outName, bool* outHasTemplateArgs = NULL); bool DemangleFunction(StringImpl& outName); -public: +public: DwDemangler(); String Demangle(const StringImpl& mangledName); @@ -104,7 +104,7 @@ public: bool DemangleType(); bool DemangleScopedName(); bool DemangleName(); - + public: MsDemangleScanner(); diff --git a/IDEHelper/Compiler/BfElementVisitor.cpp b/IDEHelper/Compiler/BfElementVisitor.cpp index e977e1d9..edcf2070 100644 --- a/IDEHelper/Compiler/BfElementVisitor.cpp +++ b/IDEHelper/Compiler/BfElementVisitor.cpp @@ -6,7 +6,6 @@ USING_NS_BF; BfElementVisitor::BfElementVisitor() { - } void BfElementVisitor::Visit(BfTypedValueExpression* typedValueExpr) @@ -36,7 +35,7 @@ void BfElementVisitor::Visit(BfPreprocessorDefinedExpression* definedExpr) { Visit(definedExpr->ToBase()); - VisitChild(definedExpr->mIdentifier); + VisitChild(definedExpr->mIdentifier); } void BfElementVisitor::Visit(BfAttributeDirective* attributeDirective) @@ -65,7 +64,7 @@ void BfElementVisitor::Visit(BfGenericParamsDeclaration* genericParams) for (auto& val : genericParams->mGenericParams) VisitChild(val); for (auto& val : genericParams->mCommas) - VisitChild(val); + VisitChild(val); VisitChild(genericParams->mCloseChevron); } @@ -84,7 +83,7 @@ void BfElementVisitor::Visit(BfGenericConstraintsDeclaration* genericConstraints Visit(genericConstraints->ToBase()); for (auto genericConstraintNode : genericConstraints->mGenericConstraints) - { + { if (auto genericConstraint = BfNodeDynCast(genericConstraintNode)) { VisitChild(genericConstraint->mWhereToken); @@ -100,7 +99,7 @@ void BfElementVisitor::Visit(BfGenericConstraintsDeclaration* genericConstraints VisitChild(genericConstraintExpr->mWhereToken); VisitChild(genericConstraintExpr->mExpression); } - } + } } void BfElementVisitor::Visit(BfGenericArgumentsNode* genericArgumentsNode) @@ -111,7 +110,7 @@ void BfElementVisitor::Visit(BfGenericArgumentsNode* genericArgumentsNode) for (auto& val : genericArgumentsNode->mGenericArgs) VisitChild(val); for (auto& val : genericArgumentsNode->mCommas) - VisitChild(val); + VisitChild(val); VisitChild(genericArgumentsNode->mCloseChevron); } @@ -169,7 +168,7 @@ void BfElementVisitor::Visit(BfNewNode* newNode) void BfElementVisitor::Visit(BfLabeledBlock* labeledBlock) { Visit(labeledBlock->ToBase()); - + VisitChild(labeledBlock->mBlock); } @@ -266,7 +265,7 @@ void BfElementVisitor::Visit(BfQualifiedNameNode* nameNode) void BfElementVisitor::Visit(BfThisExpression* thisExpr) { - Visit(thisExpr->ToBase()); + Visit(thisExpr->ToBase()); } void BfElementVisitor::Visit(BfBaseExpression* baseExpr) @@ -306,9 +305,9 @@ void BfElementVisitor::Visit(BfCollectionInitializerExpression* collectionInitEx VisitChild(collectionInitExpr->mOpenBrace); for (auto& val : collectionInitExpr->mValues) - VisitChild(val); + VisitChild(val); for (auto& val : collectionInitExpr->mCommas) - VisitChild(val); + VisitChild(val); VisitChild(collectionInitExpr->mCloseBrace); } @@ -327,7 +326,7 @@ void BfElementVisitor::Visit(BfNamedTypeReference* typeRef) void BfElementVisitor::Visit(BfQualifiedTypeReference* qualifiedTypeRef) { Visit(qualifiedTypeRef->ToBase()); - + VisitChild(qualifiedTypeRef->mLeft); VisitChild(qualifiedTypeRef->mDot); VisitChild(qualifiedTypeRef->mRight); @@ -381,17 +380,17 @@ void BfElementVisitor::Visit(BfConstExprTypeRef* typeRef) void BfElementVisitor::Visit(BfRefTypeRef* typeRef) { Visit((BfTypeReference*)typeRef); // Skip the Elemented part so we can put the element in the right spot - + VisitChild(typeRef->mRefToken); VisitChild(typeRef->mElementType); } void BfElementVisitor::Visit(BfModifiedTypeRef * typeRef) -{ +{ Visit((BfTypeReference*)typeRef); // Skip the Elemented part so we can put the element in the right spot VisitChild(typeRef->mRetTypeToken); - VisitChild(typeRef->mOpenParen); + VisitChild(typeRef->mOpenParen); VisitChild(typeRef->mElementType); VisitChild(typeRef->mCloseParen); } @@ -399,11 +398,11 @@ void BfElementVisitor::Visit(BfModifiedTypeRef * typeRef) void BfElementVisitor::Visit(BfArrayTypeRef* typeRef) { Visit((BfTypeReference*)typeRef); // Skip the Elemented part so we can put the element in the right spot - + VisitChild(typeRef->mElementType); VisitChild(typeRef->mOpenBracket); for (auto& val : typeRef->mParams) - VisitChild(val); + VisitChild(val); VisitChild(typeRef->mCloseBracket); } @@ -413,7 +412,7 @@ void BfElementVisitor::Visit(BfGenericInstanceTypeRef* typeRef) VisitChild(typeRef->mOpenChevron); for (auto& val : typeRef->mGenericArguments) - VisitChild(val); + VisitChild(val); if (typeRef->mCommas.mVals != NULL) { for (auto& val : typeRef->mCommas) @@ -428,7 +427,7 @@ void BfElementVisitor::Visit(BfTupleTypeRef* typeRef) VisitChild(typeRef->mOpenParen); for (auto& val : typeRef->mFieldNames) - VisitChild(val); + VisitChild(val); for (auto& val : typeRef->mFieldTypes) VisitChild(val); if (typeRef->mCommas.mVals != NULL) @@ -535,7 +534,7 @@ void BfElementVisitor::Visit(BfNameOfExpression* nameOfExpr) VisitChild(nameOfExpr->mToken); VisitChild(nameOfExpr->mOpenParen); - VisitChild(nameOfExpr->mTarget); + VisitChild(nameOfExpr->mTarget); VisitChild(nameOfExpr->mCloseParen); } @@ -608,16 +607,16 @@ void BfElementVisitor::Visit(BfLambdaBindExpression* lambdaBindExpr) Visit(lambdaBindExpr->ToBase()); VisitChild(lambdaBindExpr->mNewToken); - + VisitChild(lambdaBindExpr->mOpenParen); VisitChild(lambdaBindExpr->mCloseParen); for (auto& val : lambdaBindExpr->mParams) VisitChild(val); for (auto& val : lambdaBindExpr->mCommas) - VisitChild(val); + VisitChild(val); VisitChild(lambdaBindExpr->mFatArrowToken); VisitChild(lambdaBindExpr->mBody); // Either expression or block - + VisitChild(lambdaBindExpr->mDtor); } @@ -627,13 +626,13 @@ void BfElementVisitor::Visit(BfObjectCreateExpression* newExpr) VisitChild(newExpr->mNewNode); VisitChild(newExpr->mStarToken); - VisitChild(newExpr->mTypeRef); + VisitChild(newExpr->mTypeRef); VisitChild(newExpr->mOpenToken); - VisitChild(newExpr->mCloseToken); + VisitChild(newExpr->mCloseToken); for (auto& val : newExpr->mArguments) VisitChild(val); for (auto& val : newExpr->mCommas) - VisitChild(val); + VisitChild(val); } void BfElementVisitor::Visit(BfBoxExpression* boxExpr) @@ -665,7 +664,7 @@ void BfElementVisitor::Visit(BfThrowStatement* throwStmt) void BfElementVisitor::Visit(BfDeleteStatement* deleteStmt) { Visit(deleteStmt->ToBase()); - + VisitChild(deleteStmt->mDeleteToken); VisitChild(deleteStmt->mTargetTypeToken); VisitChild(deleteStmt->mAllocExpr); @@ -683,7 +682,7 @@ void BfElementVisitor::Visit(BfInvocationExpression* invocationExpr) for (auto& val : invocationExpr->mArguments) VisitChild(val); for (auto& val : invocationExpr->mCommas) - VisitChild(val); + VisitChild(val); } void BfElementVisitor::Visit(BfEnumCaseBindExpression* caseBindExpr) @@ -713,7 +712,7 @@ void BfElementVisitor::Visit(BfSwitchCase* switchCase) for (auto& val : switchCase->mCaseExpressions) VisitChild(val); for (auto& val : switchCase->mCaseCommas) - VisitChild(val); + VisitChild(val); VisitChild(switchCase->mColonToken); VisitChild(switchCase->mCodeBlock); VisitChild(switchCase->mEndingToken); @@ -808,13 +807,13 @@ void BfElementVisitor::Visit(BfDeferStatement* deferStmt) if (deferStmt->mBind != NULL) { auto bind = deferStmt->mBind; - - VisitChild(bind->mOpenBracket); + + VisitChild(bind->mOpenBracket); VisitChild(bind->mCloseBracket); for (auto& val : bind->mParams) VisitChild(val); for (auto& val : bind->mCommas) - VisitChild(val); + VisitChild(val); } VisitChild(deferStmt->mOpenParen); @@ -849,7 +848,6 @@ void BfElementVisitor::Visit(BfUsingStatement* usingStmt) VisitChild(usingStmt->mVariableDeclaration); VisitChild(usingStmt->mCloseParen); VisitChild(usingStmt->mEmbeddedStatement); - } void BfElementVisitor::Visit(BfDoStatement* doStmt) @@ -857,7 +855,7 @@ void BfElementVisitor::Visit(BfDoStatement* doStmt) Visit(doStmt->ToBase()); VisitChild(doStmt->mDoToken); - VisitChild(doStmt->mEmbeddedStatement); + VisitChild(doStmt->mEmbeddedStatement); } void BfElementVisitor::Visit(BfRepeatStatement* repeatStmt) @@ -915,14 +913,14 @@ void BfElementVisitor::Visit(BfForStatement* forStmt) for (auto& val : forStmt->mInitializers) VisitChild(val); for (auto& val : forStmt->mInitializerCommas) - VisitChild(val); + VisitChild(val); VisitChild(forStmt->mInitializerSemicolon); VisitChild(forStmt->mCondition); VisitChild(forStmt->mConditionSemicolon); for (auto& val : forStmt->mIterators) VisitChild(val); for (auto& val : forStmt->mIteratorCommas) - VisitChild(val); + VisitChild(val); VisitChild(forStmt->mCloseParen); VisitChild(forStmt->mEmbeddedStatement); } @@ -982,12 +980,12 @@ void BfElementVisitor::Visit(BfTupleExpression* tupleExpr) { VisitChild(val->mNameNode); VisitChild(val->mColonToken); - } + } } for (auto& val : tupleExpr->mValues) VisitChild(val); for (auto& val : tupleExpr->mCommas) - VisitChild(val); + VisitChild(val); VisitChild(tupleExpr->mCloseParen); } @@ -1006,11 +1004,11 @@ void BfElementVisitor::Visit(BfIndexerExpression* indexerExpr) VisitChild(indexerExpr->mTarget); VisitChild(indexerExpr->mOpenBracket); - VisitChild(indexerExpr->mCloseBracket); + VisitChild(indexerExpr->mCloseBracket); for (auto& arg : indexerExpr->mArguments) VisitChild(arg); for (auto& comma : indexerExpr->mCommas) - VisitChild(comma); + VisitChild(comma); } void BfElementVisitor::Visit(BfUnaryOperatorExpression* binOpExpr) @@ -1052,11 +1050,11 @@ void BfElementVisitor::Visit(BfMethodDeclaration* methodDeclaration) { Visit(methodDeclaration->ToBase()); - VisitChild(methodDeclaration->mAttributes); + VisitChild(methodDeclaration->mAttributes); VisitChild(methodDeclaration->mProtectionSpecifier); VisitChild(methodDeclaration->mReadOnlySpecifier); VisitChild(methodDeclaration->mStaticSpecifier); - + VisitChild(methodDeclaration->mExternSpecifier); VisitChild(methodDeclaration->mVirtualSpecifier); // either 'virtual', 'override', or 'abstract' VisitChild(methodDeclaration->mNewSpecifier); @@ -1072,7 +1070,7 @@ void BfElementVisitor::Visit(BfMethodDeclaration* methodDeclaration) for (auto& param : methodDeclaration->mParams) VisitChild(param); for (auto& comma : methodDeclaration->mCommas) - VisitChild(comma); + VisitChild(comma); VisitChild(methodDeclaration->mCloseParen); VisitChild(methodDeclaration->mGenericParams); VisitChild(methodDeclaration->mGenericConstraintsDeclaration); @@ -1109,26 +1107,26 @@ void BfElementVisitor::Visit(BfPropertyBodyExpression* propertyBodyExpression) Visit(propertyBodyExpression->ToBase()); VisitChild(propertyBodyExpression->mMutSpecifier); - VisitChild(propertyBodyExpression->mFatTokenArrow); + VisitChild(propertyBodyExpression->mFatTokenArrow); } void BfElementVisitor::Visit(BfPropertyDeclaration* propertyDeclaration) { Visit(propertyDeclaration->ToBase()); - VisitChild(propertyDeclaration->mAttributes); + VisitChild(propertyDeclaration->mAttributes); VisitChild(propertyDeclaration->mProtectionSpecifier); VisitChild(propertyDeclaration->mStaticSpecifier); VisitChild(propertyDeclaration->mVirtualSpecifier); // either 'virtual', 'override', or 'abstract' VisitChild(propertyDeclaration->mExplicitInterface); VisitChild(propertyDeclaration->mExplicitInterfaceDotToken); - + if (auto block = BfNodeDynCast(propertyDeclaration->mDefinitionBlock)) { VisitChild(block->mOpenBrace); for (auto& method : propertyDeclaration->mMethods) - VisitChild(method); + VisitChild(method); VisitChild(block->mCloseBrace); } else @@ -1156,7 +1154,7 @@ void BfElementVisitor::Visit(BfFieldDeclaration* fieldDeclaration) { Visit(fieldDeclaration->ToBase()); - VisitChild(fieldDeclaration->mAttributes); + VisitChild(fieldDeclaration->mAttributes); VisitChild(fieldDeclaration->mProtectionSpecifier); VisitChild(fieldDeclaration->mStaticSpecifier); @@ -1181,7 +1179,7 @@ void BfElementVisitor::Visit(BfEnumCaseDeclaration* enumCaseDeclaration) for (auto& entry : enumCaseDeclaration->mEntries) VisitChild(entry); for (auto& comma : enumCaseDeclaration->mCommas) - VisitChild(comma); + VisitChild(comma); } void BfElementVisitor::Visit(BfFieldDtorDeclaration* fieldDtorDeclaration) @@ -1199,7 +1197,7 @@ void BfElementVisitor::Visit(BfTypeDeclaration* typeDeclaration) VisitChild(typeDeclaration->mAttributes); VisitChild(typeDeclaration->mAbstractSpecifier); - VisitChild(typeDeclaration->mSealedSpecifier); + VisitChild(typeDeclaration->mSealedSpecifier); VisitChild(typeDeclaration->mProtectionSpecifier); VisitChild(typeDeclaration->mStaticSpecifier); VisitChild(typeDeclaration->mPartialSpecifier); @@ -1210,7 +1208,7 @@ void BfElementVisitor::Visit(BfTypeDeclaration* typeDeclaration) for (auto& baseClass : typeDeclaration->mBaseClasses) VisitChild(baseClass); for (auto& comma : typeDeclaration->mBaseClassCommas) - VisitChild(comma); + VisitChild(comma); VisitChild(typeDeclaration->mGenericParams); VisitChild(typeDeclaration->mGenericConstraintsDeclaration); @@ -1221,7 +1219,6 @@ void BfElementVisitor::Visit(BfTypeDeclaration* typeDeclaration) for (auto& member : *typeDeclaration->mDefineBlock) VisitChild(member); }*/ - } void BfElementVisitor::Visit(BfTypeAliasDeclaration* typeDeclaration) @@ -1237,7 +1234,7 @@ void BfElementVisitor::Visit(BfUsingDirective* usingDirective) { Visit(usingDirective->ToBase()); - VisitChild(usingDirective->mUsingToken); + VisitChild(usingDirective->mUsingToken); VisitChild(usingDirective->mNamespace); } diff --git a/IDEHelper/Compiler/BfElementVisitor.h b/IDEHelper/Compiler/BfElementVisitor.h index c71ab888..e863fd8b 100644 --- a/IDEHelper/Compiler/BfElementVisitor.h +++ b/IDEHelper/Compiler/BfElementVisitor.h @@ -48,7 +48,7 @@ public: virtual void Visit(BfMixinExpression* thisExpr); virtual void Visit(BfSizedArrayCreateExpression* createExpr); virtual void Visit(BfInitializerExpression* initExpr); - virtual void Visit(BfCollectionInitializerExpression* collectionInitExpr); + virtual void Visit(BfCollectionInitializerExpression* collectionInitExpr); virtual void Visit(BfTypeReference* typeRef); virtual void Visit(BfNamedTypeReference* typeRef); virtual void Visit(BfQualifiedTypeReference* qualifiedType); @@ -69,8 +69,8 @@ public: virtual void Visit(BfNullableTypeRef* typeRef); virtual void Visit(BfVariableDeclaration* varDecl); virtual void Visit(BfLocalMethodDeclaration* methodDecl); - virtual void Visit(BfParameterDeclaration* paramDecl); - virtual void Visit(BfTypeAttrExpression* typeAttrExpr); + virtual void Visit(BfParameterDeclaration* paramDecl); + virtual void Visit(BfTypeAttrExpression* typeAttrExpr); virtual void Visit(BfOffsetOfExpression* offsetOfExpr); virtual void Visit(BfNameOfExpression* nameOfExpr); virtual void Visit(BfDefaultExpression* defaultExpr); @@ -85,7 +85,7 @@ public: virtual void Visit(BfBoxExpression* boxExpr); virtual void Visit(BfScopedInvocationTarget* scopedTarget); virtual void Visit(BfInvocationExpression* invocationExpr); - virtual void Visit(BfDeferStatement* deferStmt); + virtual void Visit(BfDeferStatement* deferStmt); virtual void Visit(BfEnumCaseBindExpression* caseBindExpr); virtual void Visit(BfCaseExpression* caseExpr); virtual void Visit(BfSwitchCase* switchCase); diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index ec5b294f..f79ed37f 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -762,7 +762,6 @@ void BfMethodMatcher::CompareMethods(BfMethodInstance* prevMethodInstance, BfTyp return; } - if (newMethodDef->mExplicitInterface != prevMethodDef->mExplicitInterface) { if (mModule->CompareMethodSignatures(newMethodInstance, prevMethodInstance)) @@ -1594,7 +1593,6 @@ bool BfMethodMatcher::InferFromGenericConstraints(BfMethodInstance* methodInstan if (checkOpConstraint.mCastToken == BfToken_Implicit) { - } else { @@ -1603,7 +1601,6 @@ bool BfMethodMatcher::InferFromGenericConstraints(BfMethodInstance* methodInstan if (checkOpConstraint.mCastToken == BfToken_Explicit) { - } else { @@ -1755,7 +1752,6 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* targetTypeInstance, BfTypeInst } } - if (mHasArgNames) { checkMethod->BuildParamNameMap(); @@ -1788,7 +1784,6 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* targetTypeInstance, BfTypeInst } } - for (auto& checkGenericArgRef : mCheckMethodGenericArguments) checkGenericArgRef = NULL; @@ -3068,7 +3063,6 @@ void BfMethodMatcher::TryDevirtualizeCall(BfTypedValue target, BfTypedValue* ori // Failed mFakeConcreteTarget = true; } - } } } @@ -3796,7 +3790,6 @@ void BfExprEvaluator::Visit(BfCaseExpression* caseExpr) if (mResult) return; - } if ((caseValAddr) && (IsVar(caseValAddr.mType))) @@ -5523,7 +5516,6 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar else findName.Reference(fieldName); - auto activeTypeDef = mModule->GetActiveTypeDef(); for (int pass = 0; pass < 2; pass++) { @@ -6990,8 +6982,6 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, BfMethodInstance* return result; } - - BfTypedValue BfExprEvaluator::CreateCall(BfMethodMatcher* methodMatcher, BfTypedValue target) { auto moduleMethodInstance = GetSelectedMethod(*methodMatcher); @@ -7273,7 +7263,6 @@ void BfExprEvaluator::PushThis(BfAstNode* targetSrc, BfTypedValue argVal, BfMeth } } } - } if (argVal.mType->IsValuelessType()) @@ -7921,7 +7910,6 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, const BfTypedValu mModule->Warn(BfWarning_BF4205_StringInterpolationParam, "Expanded string interpolation argument not used as 'params'. If string allocation was intended then consider adding a specifier such as 'scope'.", errorRef); } - // if ((arg == NULL) && (argValues[argExprIdx].mExpression != NULL)) // hadMissingArg = true; @@ -8009,7 +7997,6 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, const BfTypedValu if (auto typerDecl = BfNodeDynCast(mModule->mParentNodeEntry->mNode)) showCtorError = true; - if (showCtorError) { if (mModule->PreFail()) @@ -8848,7 +8835,6 @@ BfTypedValue BfExprEvaluator::ResolveArgValue(BfResolvedArg& resolvedArg, BfType } } - if (wantType->IsRef()) { auto refType = (BfRefType*)wantType; @@ -9587,7 +9573,6 @@ BfTypedValue BfExprEvaluator::MatchMethod(BfAstNode* targetSrc, BfMethodBoundExp else if (isUnboundCall) { //auto resolvedType = mModule->ResolveGenericType(lookupType); - } else if (lookupType->IsGenericParam()) { @@ -9869,7 +9854,6 @@ BfTypedValue BfExprEvaluator::MatchMethod(BfAstNode* targetSrc, BfMethodBoundExp if (resolvedType != NULL) resolvedTypeInstance = resolvedType->ToTypeInstance(); } - } else { @@ -10198,7 +10182,6 @@ BfTypedValue BfExprEvaluator::MatchMethod(BfAstNode* targetSrc, BfMethodBoundExp if (methodDef == NULL) { - } // This will flush out any new ambiguity errors from extension methods @@ -10587,7 +10570,6 @@ BfTypedValue BfExprEvaluator::MatchMethod(BfAstNode* targetSrc, BfMethodBoundExp mModule->MethodToString(moduleMethodInstance.mMethodInstance).c_str(), mModule->MethodToString(mModule->mCurMethodInstance).c_str()), targetSrc); } - BfTypedValue result; BfTypedValue argCascade; @@ -10950,7 +10932,6 @@ void BfExprEvaluator::LookupQualifiedName(BfAstNode* nameNode, BfIdentifierNode* { if (mResult.mType->IsSizedArray()) { - if (mResult.mType->IsValuelessType()) { mResult.mType = mModule->GetWrappedStructType(mResult.mType); @@ -12935,7 +12916,6 @@ BfTypedValue BfExprEvaluator::DoImplicitArgCapture(BfAstNode* refNode, BfIdentif BfLocalVarEntry* entry; if (checkMethodState->mLocalVarSet.TryGetWith(findName, &entry)) { - auto varDecl = entry->mLocalVar; while (varDecl != NULL) @@ -12961,7 +12941,6 @@ BfTypedValue BfExprEvaluator::DoImplicitArgCapture(BfAstNode* refNode, BfIdentif varDecl = varDecl->mShadowedLocal; } - } // Check for the captured locals. It's important we do it here so we get local-first precedence still @@ -13233,7 +13212,6 @@ void BfExprEvaluator::Visit(BfDelegateBindExpression* delegateBindExpr) else delegateTypeInstance = mExpectingType->ToTypeInstance(); - if ((delegateTypeInstance == NULL) || ((!delegateTypeInstance->IsDelegate()) && (!delegateTypeInstance->IsFunction()))) { @@ -14713,7 +14691,6 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam mModule->mBfIRBuilder->PopulateType(useTypeInstance); mModule->PopulateType(useTypeInstance); - methodDef->mIsStatic = closureTypeInst == NULL; SizedArray origParamTypes; @@ -14860,7 +14837,6 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam mModule->mBfIRBuilder->SaveDebugLocation(); // { - BfGetSymbolReferenceKind prevSymbolRefKind = BfGetSymbolReferenceKind_None; if (mModule->mCompiler->mResolvePassData != NULL) { @@ -15642,7 +15618,6 @@ void BfExprEvaluator::CreateObject(BfObjectCreateExpression* objCreateExpr, BfAs BfInitContext(BfModule* module, BfType* resultType, int dimensions, SizedArray& dimLengthVals, BfIRValue arraySize, int& writeIdx) : mModule(module), resultType(resultType), dimensions(dimensions), dimLengthVals(dimLengthVals), arraySize(arraySize), writeIdx(writeIdx) { - } void Handle(BfIRValue addr, int curDim, const BfSizedArray& valueExprs) @@ -16160,7 +16135,6 @@ void BfExprEvaluator::CreateObject(BfObjectCreateExpression* objCreateExpr, BfAs /*if (typeInstance != NULL) { - mModule->InitTypeInst(mResult, scopeData, true); } if (isStackAlloc) @@ -18089,11 +18063,9 @@ void BfExprEvaluator::DoInvocation(BfAstNode* target, BfMethodBoundExpression* m { if (mExpectingType->IsVar()) { - } mResult = BfTypedValue(mExpectingType); - } else if (!gaveUnqualifiedDotError) mModule->Fail("Unqualified dot syntax can only be used when the result type can be inferred", memberRefExpression->mDotToken); @@ -18135,7 +18107,6 @@ void BfExprEvaluator::DoInvocation(BfAstNode* target, BfMethodBoundExpression* m thisValue = mResult; mResult = BfTypedValue(); } - } if (mPropDef != NULL) thisValue = GetResult(true); @@ -18220,7 +18191,6 @@ void BfExprEvaluator::DoInvocation(BfAstNode* target, BfMethodBoundExpression* m flags = (BfEvalExprFlags)(flags | BfEvalExprFlags_AllowRefExpr); expr = paranExpr->mExpression; } - } if (expr != NULL) mResult = mModule->CreateValueFromExpression(expr, expectingTargetType, flags); @@ -18349,7 +18319,6 @@ void BfExprEvaluator::DoInvocation(BfAstNode* target, BfMethodBoundExpression* m mResult = BfTypedValue(); } } - } if (mPropDef != NULL) thisValue = GetResult(true); @@ -18940,7 +18909,6 @@ BfMethodDef* BfExprEvaluator::GetPropertyMethodDef(BfPropertyDef* propDef, BfMet if (methodDef->mMethodType != methodType) continue; - if (methodDef->mCheckedKind == checkedKind) { matchedMethod = methodDef; @@ -19623,8 +19591,6 @@ bool BfExprEvaluator::CheckModifyResult(BfTypedValue& typedVal, BfAstNode* refNo break; } } - - } } @@ -20098,7 +20064,6 @@ BfTypedValue BfExprEvaluator::PerformAssignment_CheckOp(BfAssignmentExpression* return leftValue; } - checkTypeInst = mModule->GetBaseType(checkTypeInst); } @@ -21945,7 +21910,6 @@ void BfExprEvaluator::Visit(BfIndexerExpression* indexerExpr) } else { - auto indexResult = mModule->CreateIndexedValue(underlyingType, target.mValue, indexArgument.mValue); mResult = BfTypedValue(indexResult, underlyingType, target.IsReadOnly() ? BfTypedValueKind_ReadOnlyAddr : BfTypedValueKind_Addr); } @@ -22037,7 +22001,6 @@ void BfExprEvaluator::PerformUnaryOperation(BfExpression* unaryOpExpr, BfUnaryOp mExpectingType = prevExpedcting; } - BfExprEvaluator::PerformUnaryOperation_OnResult(unaryOpExpr, unaryOp, opToken, opFlags); } @@ -22998,7 +22961,6 @@ bool BfExprEvaluator::PerformBinaryOperation_NullCoalesce(BfTokenNode* opToken, mModule->AddBasicBlock(rhsBB); BfTypedValue rightValue; - if (assignTo != NULL) rightValue = mModule->CreateValueFromExpression(rightExpression, wantType, (BfEvalExprFlags)((mBfEvalExprFlags & BfEvalExprFlags_InheritFlags) | BfEvalExprFlags_CreateConditionalScope)); else @@ -25079,4 +25041,4 @@ void BfExprEvaluator::Visit(BfBinaryOperatorExpression* binOpExpr) } PerformBinaryOperation(binOpExpr->mLeft, binOpExpr->mRight, binOpExpr->mOp, binOpExpr->mOpToken, BfBinOpFlag_None); -} +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfExprEvaluator.h b/IDEHelper/Compiler/BfExprEvaluator.h index 76c0308d..630ab57e 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.h +++ b/IDEHelper/Compiler/BfExprEvaluator.h @@ -7,7 +7,7 @@ NS_BF_BEGIN enum BfArgFlags { - BfArgFlag_None = 0, + BfArgFlag_None = 0, BfArgFlag_DelegateBindAttempt = 1, BfArgFlag_LambdaBindAttempt = 2, BfArgFlag_UnqualifiedDotAttempt = 4, @@ -62,7 +62,7 @@ public: BfIdentifierNode* mNameNode; BfType* mResolvedType; BfAstNode* mExpression; - BfArgFlags mArgFlags; + BfArgFlags mArgFlags; BfType* mExpectedType; BfType* mBestBoundType; bool mWantsRecalc; @@ -87,10 +87,10 @@ public: struct BfResolvedArgs { - SizedArray mResolvedArgs; + SizedArray mResolvedArgs; BfTokenNode* mOpenToken; const BfSizedArray* mArguments; - const BfSizedArray* mCommas; + const BfSizedArray* mCommas; BfTokenNode* mCloseToken; public: @@ -134,8 +134,7 @@ public: mCloseToken = NULL; } - void HandleFixits(BfModule* module); - + void HandleFixits(BfModule* module); }; class BfGenericInferContext @@ -145,13 +144,13 @@ public: BfModule* mModule; BfTypeVector* mCheckMethodGenericArguments; SizedArray mPrevArgValues; - int mInferredCount; + int mInferredCount; public: BfGenericInferContext() { mModule = NULL; - mInferredCount = 0; + mInferredCount = 0; } bool AddToCheckedSet(BfType* argType, BfType* wantType); @@ -166,13 +165,13 @@ public: struct BfMethodGenericArguments { - BfSizedArray* mArguments; + BfSizedArray* mArguments; bool mIsPartial; bool mIsOpen; // Ends with ... BfMethodGenericArguments() { - mArguments = NULL; + mArguments = NULL; mIsPartial = false; mIsOpen = false; } @@ -198,17 +197,17 @@ public: { BackupMatchKind_None, BackupMatchKind_TooManyArgs, - BackupMatchKind_EarlyMismatch, + BackupMatchKind_EarlyMismatch, BackupMatchKind_PartialLastArgMatch }; - + public: BfAstNode* mTargetSrc; BfTypedValue mTarget; BfTypedValue mOrigTarget; BfModule* mModule; BfTypeDef* mActiveTypeDef; - String mMethodName; + String mMethodName; BfMethodInstance* mInterfaceMethodInstance; SizedArrayImpl& mArguments; BfType* mCheckReturnType; @@ -216,32 +215,32 @@ public: BfCheckedKind mCheckedKind; Array*>* mUsingLists; bool mHasArgNames; - bool mHadExplicitGenericArguments; + bool mHadExplicitGenericArguments; bool mHadOpenGenericArguments; bool mHadPartialGenericArguments; - bool mHasVarArguments; + bool mHasVarArguments; bool mHadVarConflictingReturnType; bool mBypassVirtual; bool mAllowImplicitThis; bool mAllowImplicitRef; bool mAllowImplicitWrap; bool mAllowStatic; - bool mAllowNonStatic; - bool mSkipImplicitParams; + bool mAllowNonStatic; + bool mSkipImplicitParams; bool mAutoFlushAmbiguityErrors; BfEvalExprFlags mBfEvalExprFlags; - int mMethodCheckCount; - BfType* mExplicitInterfaceCheck; + int mMethodCheckCount; + BfType* mExplicitInterfaceCheck; MatchFailKind mMatchFailKind; - - BfTypeVector mCheckMethodGenericArguments; + + BfTypeVector mCheckMethodGenericArguments; BfType* mSelfType; // Only when matching interfaces when 'Self' needs to refer back to the implementing type BfMethodDef* mBackupMethodDef; - BackupMatchKind mBackupMatchKind; + BackupMatchKind mBackupMatchKind; int mBackupArgMatchCount; BfMethodDef* mBestMethodDef; - BfTypeInstance* mBestMethodTypeInstance; + BfTypeInstance* mBestMethodTypeInstance; BfMethodInstance* mBestRawMethodInstance; BfModuleMethodInstance mBestMethodInstance; SizedArray mBestMethodGenericArgumentSrcs; @@ -254,9 +253,9 @@ public: BfTypedValue ResolveArgTypedValue(BfResolvedArg& resolvedArg, BfType* checkType, BfTypeVector* genericArgumentsSubstitute, BfType *origCheckType = NULL, BfResolveArgFlags flags = BfResolveArgFlag_None); bool InferFromGenericConstraints(BfMethodInstance* methodInstance, BfGenericParamInstance* genericParamInst, BfTypeVector* methodGenericArgs); void CompareMethods(BfMethodInstance* prevMethodInstance, BfTypeVector* prevGenericArgumentsSubstitute, - BfMethodInstance* newMethodInstance, BfTypeVector* genericArgumentsSubstitute, + BfMethodInstance* newMethodInstance, BfTypeVector* genericArgumentsSubstitute, bool* outNewIsBetter, bool* outNewIsWorse, bool allowSpecializeFail); - void FlushAmbiguityError(); + void FlushAmbiguityError(); bool IsType(BfTypedValue& val, BfType* type); int GetMostSpecificType(BfType* lhs, BfType* rhs); // 0, 1, or -1 @@ -317,8 +316,8 @@ class BfFunctionBindResult { public: BfTypedValue mOrigTarget; - BfTypedValue mTarget; - BfIRValue mFunc; + BfTypedValue mTarget; + BfIRValue mFunc; BfMethodInstance* mMethodInstance; BfType* mBindType; bool mSkipThis; @@ -329,7 +328,7 @@ public: public: BfFunctionBindResult() - { + { mMethodInstance = NULL; mBindType = NULL; mSkipMutCheck = false; @@ -342,7 +341,7 @@ public: struct DeferredTupleAssignData { struct Entry - { + { BfExpression* mExpr; BfType* mVarType; BfAstNode* mVarNameNode; @@ -359,8 +358,8 @@ struct DeferredTupleAssignData enum BfImplicitParamKind { BfImplicitParamKind_General, - BfImplicitParamKind_GenericMethodMember, - BfImplicitParamKind_GenericTypeMember, + BfImplicitParamKind_GenericMethodMember, + BfImplicitParamKind_GenericTypeMember, BfImplicitParamKind_GenericTypeMember_Addr, }; @@ -409,11 +408,11 @@ public: BfGetMethodInstanceFlags mPropGetMethodFlags; BfCheckedKind mPropCheckedKind; BfPropertyDef* mPropDef; - BfType* mExpectingType; + BfType* mExpectingType; BfAttributeState* mPrefixedAttributeState; - BfTypedValue* mReceivingValue; + BfTypedValue* mReceivingValue; BfFunctionBindResult* mFunctionBindResult; - SizedArray mIndexerValues; + SizedArray mIndexerValues; BfAstNode* mDeferCallRef; BfScopeData* mDeferScopeAlloc; bool mUsedAsStatement; @@ -434,18 +433,18 @@ public: bool CheckForMethodName(BfAstNode* refNode, BfTypeInstance* typeInst, const StringImpl& findName); bool IsVar(BfType* type, bool forceIgnoreWrites = false); void GetLiteral(BfAstNode* refNode, const BfVariant& variant); - void FinishExpressionResult(); - virtual bool CheckAllowValue(const BfTypedValue& typedValue, BfAstNode* refNode); - BfAutoComplete* GetAutoComplete(); + void FinishExpressionResult(); + virtual bool CheckAllowValue(const BfTypedValue& typedValue, BfAstNode* refNode); + BfAutoComplete* GetAutoComplete(); bool IsComptime(); bool IsConstEval(); bool IsComptimeEntry(); int GetStructRetIdx(BfMethodInstance* methodInstance, bool forceStatic = false); BfTypedValue SetupNullConditional(BfTypedValue target, BfTokenNode* dotToken); - void Evaluate(BfAstNode* astNode, bool propogateNullConditional = false, bool ignoreNullConditional = false, bool allowSplat = true); + void Evaluate(BfAstNode* astNode, bool propogateNullConditional = false, bool ignoreNullConditional = false, bool allowSplat = true); BfType* BindGenericType(BfAstNode* node, BfType* bindType); BfType* ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType populateType = BfPopulateType_Data, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0); - void ResolveGenericType(); + void ResolveGenericType(); void ResolveArgValues(BfResolvedArgs& resolvedArgs, BfResolveArgsFlags flags = BfResolveArgsFlag_None); void ResolveAllocTarget(BfAllocTarget& allocTarget, BfAstNode* newNode, BfTokenNode*& newToken, BfCustomAttributes** outCustomAttributes = NULL); BfTypedValue ResolveArgValue(BfResolvedArg& resolvedArg, BfType* wantType, BfTypedValue* receivingValue = NULL, BfParamKind paramKind = BfParamKind_Normal, BfIdentifierNode* paramNameNode = NULL); @@ -453,21 +452,21 @@ public: BfModuleMethodInstance GetPropertyMethodInstance(BfMethodDef* methodDef); void CheckPropFail(BfMethodDef* propMethodDef, BfMethodInstance* methodInstance, bool checkProt); bool HasResult(); - BfTypedValue GetResult(bool clearResult = false, bool resolveGenericType = false); + BfTypedValue GetResult(bool clearResult = false, bool resolveGenericType = false); void CheckResultForReading(BfTypedValue& typedValue); void MarkResultUsed(); void MarkResultAssigned(); - void MakeResultAsValue(); + void MakeResultAsValue(); bool CheckIsBase(BfAstNode* checkNode); 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); 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 LookupQualifiedName(BfQualifiedNameNode* nameNode, bool ignoreInitialError = false, bool* hadError = NULL); void LookupQualifiedName(BfAstNode* nameNode, BfIdentifierNode* nameLeft, BfIdentifierNode* nameRight, bool ignoreInitialError, bool* hadError = NULL); - void LookupQualifiedStaticField(BfQualifiedNameNode* nameNode, bool ignoreIdentifierNotFoundError); + void LookupQualifiedStaticField(BfQualifiedNameNode* nameNode, bool ignoreIdentifierNotFoundError); void LookupQualifiedStaticField(BfAstNode* nameNode, BfIdentifierNode* nameLeft, BfIdentifierNode* nameRight, bool ignoreIdentifierNotFoundError); bool CheckConstCompare(BfBinaryOp binaryOp, BfAstNode* opToken, const BfTypedValue& leftValue, const BfTypedValue& rightValue); void AddStrings(const BfTypedValue& leftValue, const BfTypedValue& rightValue, BfAstNode* refNode); @@ -489,41 +488,41 @@ public: void SplatArgs(BfTypedValue value, SizedArrayImpl& irArgs); void PushArg(BfTypedValue argVal, SizedArrayImpl& irArgs, bool disableSplat = false, bool disableLowering = false, bool isIntrinsic = false, bool createCompositeCopy = false); void PushThis(BfAstNode* targetSrc, BfTypedValue callTarget, BfMethodInstance* methodInstance, SizedArrayImpl& irArgs, bool skipMutCheck = false); - BfTypedValue MatchConstructor(BfAstNode* targetSrc, BfMethodBoundExpression* methodBoundExpr, BfTypedValue target, BfTypeInstance* targetType, + BfTypedValue MatchConstructor(BfAstNode* targetSrc, BfMethodBoundExpression* methodBoundExpr, BfTypedValue target, BfTypeInstance* targetType, BfResolvedArgs& argValues, bool callCtorBodyOnly, bool allowAppendAlloc, BfTypedValue* appendIndexValue = NULL); BfTypedValue CheckEnumCreation(BfAstNode* targetSrc, BfTypeInstance* enumType, const StringImpl& caseName, BfResolvedArgs& argValues); - BfTypedValue MatchMethod(BfAstNode* targetSrc, BfMethodBoundExpression* methodBoundExpr, BfTypedValue target, bool allowImplicitThis, bool bypassVirtual, const StringImpl& name, + BfTypedValue MatchMethod(BfAstNode* targetSrc, BfMethodBoundExpression* methodBoundExpr, BfTypedValue target, bool allowImplicitThis, bool bypassVirtual, const StringImpl& name, BfResolvedArgs& argValue, const BfMethodGenericArguments& methodGenericArguments, BfCheckedKind checkedKind = BfCheckedKind_NotSet); - BfTypedValue MakeCallableTarget(BfAstNode* targetSrc, BfTypedValue target); + BfTypedValue MakeCallableTarget(BfAstNode* targetSrc, BfTypedValue target); BfModuleMethodInstance GetSelectedMethod(BfAstNode* targetSrc, BfTypeInstance* curTypeInst, BfMethodDef* methodDef, BfMethodMatcher& methodMatcher, BfType** overrideReturnType = NULL); BfModuleMethodInstance GetSelectedMethod(BfMethodMatcher& methodMatcher); bool CheckVariableDeclaration(BfAstNode* checkNode, bool requireSimpleIfExpr, bool exprMustBeTrue, bool silentFail); bool HasVariableDeclaration(BfAstNode* checkNode); - void DoInvocation(BfAstNode* target, BfMethodBoundExpression* methodBoundExpr, const BfSizedArray& args, const BfMethodGenericArguments& methodGenericArgs, BfTypedValue* outCascadeValue = NULL); - int GetMixinVariable(); + void DoInvocation(BfAstNode* target, BfMethodBoundExpression* methodBoundExpr, const BfSizedArray& args, const BfMethodGenericArguments& methodGenericArgs, BfTypedValue* outCascadeValue = NULL); + int GetMixinVariable(); void CheckLocalMethods(BfAstNode* targetSrc, BfTypeInstance* typeInstance, const StringImpl& methodName, BfMethodMatcher& methodMatcher, BfMethodType methodType); void InjectMixin(BfAstNode* targetSrc, BfTypedValue target, bool allowImplicitThis, const StringImpl& name, const BfSizedArray& arguments, const BfMethodGenericArguments& methodGenericArgs); void SetMethodElementType(BfAstNode* target); BfTypedValue DoImplicitArgCapture(BfAstNode* refNode, BfIdentifierNode* identifierNode, int shadowIdx); BfTypedValue DoImplicitArgCapture(BfAstNode* refNode, BfMethodInstance* methodInstance, int paramIdx, bool& failed, BfImplicitParamKind paramKind = BfImplicitParamKind_General, const BfTypedValue& methodRefTarget = BfTypedValue()); bool CanBindDelegate(BfDelegateBindExpression* delegateBindExpr, BfMethodInstance** boundMethod = NULL, BfType* origMethodExpectingType = NULL, BfTypeVector* methodGenericArgumentsSubstitute = NULL); - bool IsExactMethodMatch(BfMethodInstance* methodA, BfMethodInstance* methodB, bool ignoreImplicitParams = false); - BfTypeInstance* VerifyBaseDelegateType(BfTypeInstance* delegateType); + bool IsExactMethodMatch(BfMethodInstance* methodA, BfMethodInstance* methodB, bool ignoreImplicitParams = false); + BfTypeInstance* VerifyBaseDelegateType(BfTypeInstance* delegateType); void ConstResolve(BfExpression* expr); void ProcessArrayInitializer(BfTokenNode* openToken, const BfSizedArray& values, const BfSizedArray& commas, BfTokenNode* closeToken, int dimensions, SizedArrayImpl& dimLengths, int dim, bool& hasFailed); BfLambdaInstance* GetLambdaInstance(BfLambdaBindExpression* lambdaBindExpr, BfAllocTarget& allocTarget); - void VisitLambdaBodies(BfAstNode* body, BfFieldDtorDeclaration* fieldDtor); - void FixitAddMember(BfTypeInstance* typeInst, BfType* fieldType, const StringImpl& fieldName, bool isStatic); + void VisitLambdaBodies(BfAstNode* body, BfFieldDtorDeclaration* fieldDtor); + void FixitAddMember(BfTypeInstance* typeInst, BfType* fieldType, const StringImpl& fieldName, bool isStatic); BfTypedValue TryArrowLookup(BfTypedValue typedValue, BfTokenNode* arrowToken); void PerformUnaryOperation(BfExpression* unaryOpExpr, BfUnaryOp unaryOp, BfTokenNode* opToken, BfUnaryOpFlags opFlags); BfTypedValue PerformUnaryOperation_TryOperator(const BfTypedValue& inValue, BfExpression* unaryOpExpr, BfUnaryOp unaryOp, BfTokenNode* opToken, BfUnaryOpFlags opFlags); - void PerformUnaryOperation_OnResult(BfExpression* unaryOpExpr, BfUnaryOp unaryOp, BfTokenNode* opToken, BfUnaryOpFlags opFlags); - BfTypedValue PerformAssignment_CheckOp(BfAssignmentExpression* assignExpr, bool deferBinop, BfTypedValue& leftValue, BfTypedValue& rightValue, bool& evaluatedRight); - void PerformAssignment(BfAssignmentExpression* assignExpr, bool evaluatedLeft, BfTypedValue rightValue, BfTypedValue* outCascadeValue = NULL); + void PerformUnaryOperation_OnResult(BfExpression* unaryOpExpr, BfUnaryOp unaryOp, BfTokenNode* opToken, BfUnaryOpFlags opFlags); + BfTypedValue PerformAssignment_CheckOp(BfAssignmentExpression* assignExpr, bool deferBinop, BfTypedValue& leftValue, BfTypedValue& rightValue, bool& evaluatedRight); + void PerformAssignment(BfAssignmentExpression* assignExpr, bool evaluatedLeft, BfTypedValue rightValue, BfTypedValue* outCascadeValue = NULL); void PopulateDeferrredTupleAssignData(BfTupleExpression* tupleExr, DeferredTupleAssignData& deferredTupleAssignData); void AssignDeferrredTupleAssignData(BfAssignmentExpression* assignExpr, DeferredTupleAssignData& deferredTupleAssignData, BfTypedValue rightValue); - void DoTupleAssignment(BfAssignmentExpression* assignExpr); - void FinishDeferredEvals(SizedArrayImpl& argValues); + void DoTupleAssignment(BfAssignmentExpression* assignExpr); + void FinishDeferredEvals(SizedArrayImpl& argValues); void FinishDeferredEvals(BfResolvedArgs& argValues); bool LookupTypeProp(BfTypeOfExpression* typeOfExpr, BfIdentifierNode* propName); void DoTypeIntAttr(BfTypeReference* typeRef, BfTokenNode* commaToken, BfIdentifierNode* memberName, BfToken token); @@ -534,7 +533,7 @@ public: void CreateObject(BfObjectCreateExpression* objCreateExpr, BfAstNode* allocNode, BfType* allocType); ////////////////////////////////////////////////////////////////////////// - + virtual void Visit(BfErrorNode* errorNode) override; virtual void Visit(BfTypeReference* typeRef) override; virtual void Visit(BfAttributedExpression* attribExpr) override; @@ -543,7 +542,7 @@ public: virtual void Visit(BfVariableDeclaration* varDecl) override; virtual void Visit(BfCaseExpression* caseExpr) override; virtual void Visit(BfTypedValueExpression* typedValueExpr) override; - virtual void Visit(BfLiteralExpression* literalExpr) override; + virtual void Visit(BfLiteralExpression* literalExpr) override; virtual void Visit(BfStringInterpolationExpression* stringInterpolationExpression) override; virtual void Visit(BfIdentifierNode* identifierNode) override; virtual void Visit(BfAttributedIdentifierNode* attrIdentifierNode) override; @@ -553,7 +552,7 @@ public: virtual void Visit(BfMixinExpression* mixinExpr) override; virtual void Visit(BfSizedArrayCreateExpression* createExpr) override; virtual void Visit(BfInitializerExpression* initExpr) override; - virtual void Visit(BfCollectionInitializerExpression* initExpr) override; + virtual void Visit(BfCollectionInitializerExpression* initExpr) override; virtual void Visit(BfTypeOfExpression* typeOfExpr) override; virtual void Visit(BfSizeOfExpression* sizeOfExpr) override; virtual void Visit(BfAlignOfExpression* alignOfExpr) override; @@ -570,7 +569,7 @@ public: virtual void Visit(BfLambdaBindExpression* lambdaBindExpr) override; virtual void Visit(BfObjectCreateExpression* objCreateExpr) override; virtual void Visit(BfBoxExpression* boxExpr) override; - virtual void Visit(BfInvocationExpression* invocationExpr) override; + virtual void Visit(BfInvocationExpression* invocationExpr) override; virtual void Visit(BfConditionalExpression* condExpr) override; virtual void Visit(BfAssignmentExpression* assignExpr) override; virtual void Visit(BfParenthesizedExpression* parenExpr) override; @@ -578,7 +577,7 @@ public: virtual void Visit(BfMemberReferenceExpression* memberRefExpr) override; virtual void Visit(BfIndexerExpression* indexerExpr) override; virtual void Visit(BfUnaryOperatorExpression* unaryOpExpr) override; - virtual void Visit(BfBinaryOperatorExpression* binOpExpr) override; + virtual void Visit(BfBinaryOperatorExpression* binOpExpr) override; }; NS_BF_END \ No newline at end of file diff --git a/IDEHelper/Compiler/BfFixits.h b/IDEHelper/Compiler/BfFixits.h index cbd47d8d..13634e73 100644 --- a/IDEHelper/Compiler/BfFixits.h +++ b/IDEHelper/Compiler/BfFixits.h @@ -19,7 +19,7 @@ public: { idx++; break; - } + } idx++; } return idx; @@ -37,10 +37,10 @@ public: { char c = source->mSrc[idx]; if (c == '\n') - { + { idx++; break; - } + } idx--; } return idx; @@ -67,13 +67,13 @@ public: virtual void Visit(BfUsingDirective* usingDirective) override { - mLastIdx = FindLineStartAfter(usingDirective->GetSourceData(), usingDirective->GetSrcEnd()); + mLastIdx = FindLineStartAfter(usingDirective->GetSourceData(), usingDirective->GetSrcEnd()); } virtual void Visit(BfNamespaceDeclaration* namespaceDecl) override { if (mFromIdx != -1) - { + { if ((mFromIdx < namespaceDecl->mSrcStart) || (mFromIdx >= namespaceDecl->mSrcEnd)) { // Not inside diff --git a/IDEHelper/Compiler/BfIRBuilder.cpp b/IDEHelper/Compiler/BfIRBuilder.cpp index 00179bd4..82fb6564 100644 --- a/IDEHelper/Compiler/BfIRBuilder.cpp +++ b/IDEHelper/Compiler/BfIRBuilder.cpp @@ -236,17 +236,17 @@ bool BfIRValue::IsFake() const } bool BfIRValue::IsConst() const -{ +{ return (mFlags & BfIRValueFlags_Const) != 0; } bool BfIRValue::IsArg() const -{ +{ return (mFlags & BfIRValueFlags_Arg) != 0; } bool BfIRValue::IsFromLLVM() const -{ +{ return (mFlags & BfIRValueFlags_FromLLVM) != 0; } @@ -261,15 +261,15 @@ BfIRFunction::BfIRFunction() ////////////////////////////////////////////////////////////////////////// BfIRFunctionType::BfIRFunctionType() -{ - mId = -1; +{ + mId = -1; } ////////////////////////////////////////////////////////////////////////// BfIRBlock::BfIRBlock() { - mFlags = BfIRValueFlags_None; + mFlags = BfIRValueFlags_None; mId = -1; } @@ -277,11 +277,11 @@ BfIRBlock::BfIRBlock() BfIRConstHolder::BfIRConstHolder(BfModule* module) { - mModule = module; + mModule = module; } BfIRConstHolder::~BfIRConstHolder() -{ +{ } String BfIRConstHolder::ToString(BfIRValue irValue) @@ -326,7 +326,7 @@ String BfIRConstHolder::ToString(BfIRValue irValue) } else if (constant->mConstType == BfConstType_GlobalVar) { - auto gvConst = (BfGlobalVar*)constant; + auto gvConst = (BfGlobalVar*)constant; return String("GlobalVar ") + gvConst->mName; } else if (constant->mConstType == BfConstType_BitCast) @@ -424,7 +424,7 @@ String BfIRConstHolder::ToString(BfIRValue irValue) return StrFormat("Arg %d", irValue.mId); } else if (irValue.mFlags != 0) - { + { return "Value???"; } else @@ -585,14 +585,13 @@ const char* BfIRConstHolder::AllocStr(const StringImpl& str) return strCopy; } - BfConstant* BfIRConstHolder::GetConstantById(int id) { return (BfConstant*)mTempAlloc.GetChunkedPtr(id); } BfConstant* BfIRConstHolder::GetConstant(BfIRValue id) -{ +{ if (!id.IsConst()) return NULL; #ifdef CHECK_CONSTHOLDER @@ -661,12 +660,12 @@ int BfIRConstHolder::CheckConstEquality(BfIRValue lhs, BfIRValue rhs) auto constRHS = GetConstant(rhs); if (constRHS == NULL) return -1; - + if (constLHS == constRHS) return 1; if (constLHS->mConstType == BfConstType_BitCast) - return CheckConstEquality(BfIRValue(BfIRValueFlags_Const, ((BfConstantBitCast*)constLHS)->mTarget), rhs); + return CheckConstEquality(BfIRValue(BfIRValueFlags_Const, ((BfConstantBitCast*)constLHS)->mTarget), rhs); if (constRHS->mConstType == BfConstType_BitCast) return CheckConstEquality(lhs, BfIRValue(BfIRValueFlags_Const, ((BfConstantBitCast*)constRHS)->mTarget)); @@ -691,17 +690,17 @@ int BfIRConstHolder::CheckConstEquality(BfIRValue lhs, BfIRValue rhs) if (constLHS->mTypeCode != constRHS->mTypeCode) return -1; - + if ((constLHS->mTypeCode >= BfTypeCode_Boolean) && (constLHS->mTypeCode <= BfTypeCode_Double)) { return (constLHS->mUInt64 == constRHS->mUInt64) ? 1 : 0; } - + if (constLHS->mConstType == BfConstType_Agg) { auto aggLHS = (BfConstantAgg*)constLHS; auto aggRHS = (BfConstantAgg*)constRHS; - + if (aggLHS->mValues.mSize != aggRHS->mValues.mSize) return -1; @@ -712,7 +711,7 @@ int BfIRConstHolder::CheckConstEquality(BfIRValue lhs, BfIRValue rhs) return elemResult; } return 1; - } + } //TODO: Why did we do this? This made global variable comparisons (ie: sA != sB) const-evaluate to false always // if (constLHS->mConstType == BfConstType_GlobalVar) @@ -720,7 +719,7 @@ int BfIRConstHolder::CheckConstEquality(BfIRValue lhs, BfIRValue rhs) // // We would have already caught the (constLHS == constRHS) case further up // return 0; // } - + return -1; } @@ -745,7 +744,7 @@ BfIRValue BfIRConstHolder::CreateConst(BfTypeCode typeCode, uint64 val) typeCode = BfTypeCode_Int64; else if (typeCode == BfTypeCode_UIntUnknown) typeCode = BfTypeCode_UInt64; - + FixTypeCode(typeCode); BfConstant* constant = mTempAlloc.Alloc(); constant->mTypeCode = typeCode; @@ -756,7 +755,7 @@ BfIRValue BfIRConstHolder::CreateConst(BfTypeCode typeCode, uint64 val) case BfTypeCode_Int8: constant->mInt64 = (int8)val; break; - case BfTypeCode_Int16: + case BfTypeCode_Int16: constant->mInt64 = (int16)val; break; case BfTypeCode_Int32: @@ -796,7 +795,7 @@ BfIRValue BfIRConstHolder::CreateConst(BfTypeCode typeCode, int val) { case BfTypeCode_Int8: constant->mInt64 = (int8)val; - break; + break; case BfTypeCode_Int16: constant->mInt64 = (int16)val; break; @@ -811,10 +810,10 @@ BfIRValue BfIRConstHolder::CreateConst(BfTypeCode typeCode, int val) break; default: constant->mInt64 = val; - break; + break; } - auto irValue = BfIRValue(BfIRValueFlags_Const, mTempAlloc.GetChunkedId(constant)); + auto irValue = BfIRValue(BfIRValueFlags_Const, mTempAlloc.GetChunkedId(constant)); #ifdef CHECK_CONSTHOLDER irValue.mHolder = this; #endif @@ -827,25 +826,25 @@ BfIRValue BfIRConstHolder::CreateConst(BfTypeCode typeCode, double val) BfConstant* constant = mTempAlloc.Alloc(); constant->mTypeCode = typeCode; constant->mDouble = val; - auto irValue = BfIRValue(BfIRValueFlags_Const, mTempAlloc.GetChunkedId(constant)); + auto irValue = BfIRValue(BfIRValueFlags_Const, mTempAlloc.GetChunkedId(constant)); #ifdef CHECK_CONSTHOLDER irValue.mHolder = this; #endif - + return irValue; } BfIRValue BfIRConstHolder::CreateConst(BfConstant* fromConst, BfIRConstHolder* fromHolder) -{ +{ BfConstant* copiedConst = NULL; - + int chunkId = -1; if ((fromConst->mConstType == BfConstType_BitCast) || (fromConst->mConstType == BfConstType_BitCastNull)) - { + { //HMM- This should never happen? Is that true? We always just store string refs as ints //BF_FATAL("Bad"); - auto fromConstBitCast = (BfConstantBitCast*)fromConst; + auto fromConstBitCast = (BfConstantBitCast*)fromConst; BfIRValue copiedTarget; if (fromConstBitCast->mTarget) { @@ -873,7 +872,7 @@ BfIRValue BfIRConstHolder::CreateConst(BfConstant* fromConst, BfIRConstHolder* f constGEP->mTarget = copiedTarget.mId; constGEP->mIdx0 = fromConstGEP->mIdx0; constGEP->mIdx1 = fromConstGEP->mIdx1; - copiedConst = (BfConstant*)constGEP; + copiedConst = (BfConstant*)constGEP; } else if (fromConst->mConstType == BfConstType_ExtractValue) { @@ -892,7 +891,7 @@ BfIRValue BfIRConstHolder::CreateConst(BfConstant* fromConst, BfIRConstHolder* f return CreateTypeOf(typeOf->mType); } else if (fromConst->mConstType == BfConstType_TypeOf_WithData) - { + { auto typeOf = (BfTypeOf_WithData_Const*)fromConst; auto dataConstant = fromHolder->GetConstant(typeOf->mTypeData); return CreateTypeOf(typeOf->mType, CreateConst(dataConstant, fromHolder)); @@ -928,13 +927,13 @@ BfIRValue BfIRConstHolder::CreateConst(BfConstant* fromConst, BfIRConstHolder* f return CreateConstArrayZero(fromConst->mInt32); } else if ((IsInt(fromConst->mTypeCode)) || (fromConst->mTypeCode == BfTypeCode_Boolean) || (fromConst->mTypeCode == BfTypeCode_StringId)) - { - return CreateConst(fromConst->mTypeCode, fromConst->mUInt64); + { + return CreateConst(fromConst->mTypeCode, fromConst->mUInt64); } else if ((fromConst->mTypeCode == BfTypeCode_Float) || (fromConst->mTypeCode == BfTypeCode_Double)) { return CreateConst(fromConst->mTypeCode, fromConst->mDouble); - } + } else if (fromConst->mTypeCode == BfTypeCode_NullPtr) { if (fromConst->mIRType) @@ -969,12 +968,12 @@ BfIRValue BfIRConstHolder::CreateConst(BfConstant* fromConst, BfIRConstHolder* f { BF_FATAL("not handled"); } - + BfIRValue retVal; retVal.mFlags = BfIRValueFlags_Const; if (chunkId == -1) chunkId = mTempAlloc.GetChunkedId(copiedConst); - retVal.mId = chunkId; + retVal.mId = chunkId; BF_ASSERT(retVal.mId >= 0); #ifdef CHECK_CONSTHOLDER retVal.mHolder = this; @@ -985,9 +984,9 @@ BfIRValue BfIRConstHolder::CreateConst(BfConstant* fromConst, BfIRConstHolder* f BfIRValue BfIRConstHolder::CreateConstNull() { BfConstant* constant = mTempAlloc.Alloc(); - constant->mTypeCode = BfTypeCode_NullPtr; + constant->mTypeCode = BfTypeCode_NullPtr; constant->mIRType = BfIRType(); - auto irValue = BfIRValue(BfIRValueFlags_Const, mTempAlloc.GetChunkedId(constant)); + auto irValue = BfIRValue(BfIRValueFlags_Const, mTempAlloc.GetChunkedId(constant)); #ifdef CHECK_CONSTHOLDER irValue.mHolder = this; #endif @@ -999,7 +998,7 @@ BfIRValue BfIRConstHolder::CreateConstNull(BfIRType ptrType) BfConstant* constant = mTempAlloc.Alloc(); constant->mTypeCode = BfTypeCode_NullPtr; constant->mIRType = ptrType; - auto irValue = BfIRValue(BfIRValueFlags_Const, mTempAlloc.GetChunkedId(constant)); + auto irValue = BfIRValue(BfIRValueFlags_Const, mTempAlloc.GetChunkedId(constant)); #ifdef CHECK_CONSTHOLDER irValue.mHolder = this; #endif @@ -1026,7 +1025,7 @@ BfIRValue BfIRConstHolder::CreateConstAgg(BfIRType type, const BfSizedArray(); constant->mConstType = BfConstType_Agg; constant->mType = type = type; @@ -1063,7 +1062,7 @@ BfIRValue BfIRConstHolder::CreateConstArrayZero(BfIRType type, int count) constant->mType = type = type; constant->mCount = count; auto irValue = BfIRValue(BfIRValueFlags_Const, mTempAlloc.GetChunkedId(constant)); - + #ifdef CHECK_CONSTHOLDER irValue.mHolder = this; #endif @@ -1108,7 +1107,7 @@ BfIRValue BfIRConstHolder::CreateConstBox(BfIRValue val, BfIRType type) { auto constVal = GetConstant(val); - auto box = mTempAlloc.Alloc(); + auto box = mTempAlloc.Alloc(); box->mConstType = BfConstType_Box; BF_ASSERT(val.mId != -1); box->mTarget = val.mId; @@ -1126,7 +1125,7 @@ BfIRValue BfIRConstHolder::CreateTypeOf(BfType* type) { BfTypeOf_Const* typeOf = mTempAlloc.Alloc(); typeOf->mConstType = BfConstType_TypeOf; - typeOf->mType = type; + typeOf->mType = type; auto irValue = BfIRValue(BfIRValueFlags_Const, mTempAlloc.GetChunkedId(typeOf)); #ifdef CHECK_CONSTHOLDER irValue.mHolder = this; @@ -1148,12 +1147,12 @@ BfIRValue BfIRConstHolder::CreateTypeOf(BfType* type, BfIRValue typeData) } BfIRValue BfIRConstHolder::GetUndefConstValue(BfIRType irType) -{ +{ auto constUndef = mTempAlloc.Alloc(); - constUndef->mConstType = BfConstType_Undef; + constUndef->mConstType = BfConstType_Undef; constUndef->mType = irType; - BfIRValue undefVal(BfIRValueFlags_Const, mTempAlloc.GetChunkedId(constUndef)); + BfIRValue undefVal(BfIRValueFlags_Const, mTempAlloc.GetChunkedId(constUndef)); #ifdef CHECK_CONSTHOLDER castedVal.mHolder = this; #endif @@ -1227,7 +1226,7 @@ bool BfIRConstHolder::WriteConstant(BfIRValue val, void* ptr, BfType* type) int idx = 0; if (typeInst->mBaseType != NULL) - { + { if (!WriteConstant(aggConstant->mValues[0], ptr, typeInst->mBaseType)) return false; } @@ -1282,7 +1281,7 @@ bool BfIRConstHolder::WriteConstant(BfIRValue val, void* ptr, BfType* type) if (strncmp(constGV->mName, strObjPrefix, strlen(strObjPrefix)) == 0) { *(int32*)ptr = atoi(constGV->mName + strlen(strObjPrefix)); - return true; + return true; } } @@ -1290,7 +1289,7 @@ bool BfIRConstHolder::WriteConstant(BfIRValue val, void* ptr, BfType* type) } BfIRValue BfIRConstHolder::ReadConstant(void* ptr, BfType* type) -{ +{ if (type->IsPrimitiveType()) { auto primType = (BfPrimitiveType*)type; @@ -1329,7 +1328,7 @@ BfIRValue BfIRConstHolder::ReadConstant(void* ptr, BfType* type) return BfIRValue(); } } - + if (type->IsTypedPrimitive()) { return ReadConstant(ptr, type->GetUnderlyingType()); @@ -1355,7 +1354,7 @@ BfIRValue BfIRConstHolder::ReadConstant(void* ptr, BfType* type) } if (type->IsStruct()) - { + { mModule->PopulateType(type); auto typeInst = type->ToTypeInstance(); int idx = 0; @@ -1394,14 +1393,14 @@ BfIRValue BfIRConstHolder::ReadConstant(void* ptr, BfType* type) BfIRType irType; irType.mKind = BfIRTypeData::TypeKind_TypeId; irType.mId = type->mTypeId; - return CreateConstAgg(irType, irValues); + return CreateConstAgg(irType, irValues); } if (type->IsInstanceOf(mModule->mCompiler->mStringTypeDef)) { return CreateConst(BfTypeCode_StringId, *(int32*)ptr); } - + return BfIRValue(); } @@ -1469,7 +1468,7 @@ int32 BfIRBuilder::CheckedAdd(int32 a, int32 b) OpFailed(); } else if (result > a) - OpFailed(); + OpFailed(); return (uint32)result; } @@ -1482,7 +1481,7 @@ int64 BfIRBuilder::CheckedAdd(int64 a, int64 b) OpFailed(); } else if (result > a) - OpFailed(); + OpFailed(); return (uint64)result; } @@ -1545,7 +1544,7 @@ int32 BfIRBuilder::CheckedSub(int32 a, int32 b) OpFailed(); } else if (result < a) - OpFailed(); + OpFailed(); return (uint32)result; } @@ -1558,7 +1557,7 @@ int64 BfIRBuilder::CheckedSub(int64 a, int64 b) OpFailed(); } else if (result < a) - OpFailed(); + OpFailed(); return (uint64)result; } @@ -1585,7 +1584,7 @@ uint32 BfIRBuilder::CheckedMul(uint32 a, uint32 b) uint64 result = (uint64)a * b; uint32 upper = (uint32)(result >> 32); if ((upper != 0) && (upper != 0xFFFFFFFF)) - OpFailed(); + OpFailed(); return (uint32)result; } @@ -1596,7 +1595,7 @@ uint64 BfIRBuilder::CheckedMul(uint64 a, uint64 b) uint32 bHigh; uint32 bLow; - // a*b can be decomposed to + // a*b can be decomposed to // (aHigh * bHigh * 2^64) + (aLow * bHigh * 2^32) + (aHigh * bLow * 2^32) + (aLow * bLow) aHigh = (uint32)(a >> 32); @@ -1608,8 +1607,8 @@ uint64 BfIRBuilder::CheckedMul(uint64 a, uint64 b) if (aHigh == 0) { - if (bHigh != 0) - ret = (uint64)aLow * (uint64)bHigh; + if (bHigh != 0) + ret = (uint64)aLow * (uint64)bHigh; } else if (bHigh == 0) { @@ -1617,26 +1616,26 @@ uint64 BfIRBuilder::CheckedMul(uint64 a, uint64 b) ret = (uint64)aHigh * (uint64)bLow; } else - OpFailed(); + OpFailed(); if (ret != 0) { uint64 tmp; - if((uint32)(ret >> 32) != 0) - OpFailed(); + if((uint32)(ret >> 32) != 0) + OpFailed(); ret <<= 32; tmp = (uint64)aLow * (uint64)bLow; ret += tmp; - if (ret < tmp) - OpFailed(); + if (ret < tmp) + OpFailed(); return ret; } - return (uint64)aLow * (uint64)bLow; + return (uint64)aLow * (uint64)bLow; } int8 BfIRBuilder::CheckedMul(int8 a, int8 b) @@ -1660,14 +1659,14 @@ int32 BfIRBuilder::CheckedMul(int32 a, int32 b) int64 result = (int64)a * b; int32 upper = (int32)(result >> 32); if ((upper != 0) && (upper != 0xFFFFFFFF)) - OpFailed(); + OpFailed(); return (int32)result; } int64 BfIRBuilder::CheckedMul(int64 a, int64 b) { - bool aNegative = false; - int64 aAbs = a; + bool aNegative = false; + int64 aAbs = a; if (aAbs < 0) { aNegative = true; @@ -1686,12 +1685,12 @@ int64 BfIRBuilder::CheckedMul(int64 a, int64 b) // Don't allow overflow into sign flag if (tmp & 0x8000000000000000LL) - OpFailed(); + OpFailed(); - if (aNegative ^ bNegative) - return -(int64)tmp; + if (aNegative ^ bNegative) + return -(int64)tmp; - return (int64)tmp; + return (int64)tmp; } /// @@ -1790,7 +1789,7 @@ BfIRBuilder::BfIRBuilder(BfModule* module) : BfIRConstHolder(module) mBeIRCodeGen = NULL; mBfIRCodeGen = NULL; mDbgVerifyCodeGen = false; - + mIgnoreWrites = false; mCurFakeId = -32; mOpFailed = false; @@ -1798,7 +1797,7 @@ BfIRBuilder::BfIRBuilder(BfModule* module) : BfIRConstHolder(module) mHasGlobalDefs = false; mNumFunctionsWithBodies = 0; mActiveFunctionHasBody = false; - mHasStarted = false; + mHasStarted = false; mCmdCount = 0; mIsBeefBackend = false; } @@ -1826,7 +1825,7 @@ String BfIRBuilder::ToString(BfIRValue irValue) } else if ((irValue.mFlags & BfIRValueFlags_Arg) != 0) { - return StrFormat("Arg %d in %s", irValue.mId, ActiveFuncToString().c_str()); + return StrFormat("Arg %d in %s", irValue.mId, ActiveFuncToString().c_str()); } else if (irValue.mFlags != 0) { @@ -1845,7 +1844,7 @@ String BfIRBuilder::ToString(BfIRValue irValue) { auto val = mBeIRCodeGen->GetBeValue(irValue.mId); String str; - BeDumpContext dc; + BeDumpContext dc; dc.ToString(str, val); auto type = val->GetType(); @@ -1856,7 +1855,7 @@ String BfIRBuilder::ToString(BfIRValue irValue) } return str; - } + } else return "Value???"; } @@ -1875,7 +1874,7 @@ String BfIRBuilder::ToString(BfIRType irType) if (irType.mKind == BfIRTypeData::TypeKind_Stream) { llvmType = mBfIRCodeGen->GetLLVMType(irType.mId); - } + } else if (irType.mKind == BfIRType::TypeKind::TypeKind_TypeCode) { bool isSigned = false; @@ -1891,14 +1890,14 @@ String BfIRBuilder::ToString(BfIRType irType) else if (irType.mKind == BfIRType::TypeKind::TypeKind_TypeInstPtrId) llvmType = typeEntry.mInstLLVMType->getPointerTo(); } - + if (llvmType == NULL) return "null"; std::string outStr; llvm::raw_string_ostream strStream(outStr); - llvmType->print(strStream); - - if (auto pointerType = llvm::dyn_cast(llvmType)) + llvmType->print(strStream); + + if (auto pointerType = llvm::dyn_cast(llvmType)) { strStream << "\n ElementType: "; pointerType->getElementType()->print(strStream); @@ -1920,7 +1919,7 @@ String BfIRBuilder::ToString(BfIRType irType) } else { - auto& typeEntry = mBeIRCodeGen->GetTypeEntry(irType.mId); + auto& typeEntry = mBeIRCodeGen->GetTypeEntry(irType.mId); if (irType.mKind == BfIRType::TypeKind::TypeKind_TypeId) beType = typeEntry.mBeType; else if (irType.mKind == BfIRType::TypeKind::TypeKind_TypeInstId) @@ -1928,9 +1927,9 @@ String BfIRBuilder::ToString(BfIRType irType) else if (irType.mKind == BfIRType::TypeKind::TypeKind_TypeInstPtrId) beType = mBeIRCodeGen->mBeContext->GetPointerTo(typeEntry.mInstBeType); } - + String str; - BeDumpContext dc; + BeDumpContext dc; dc.ToString(str, beType); return str; } @@ -1954,7 +1953,7 @@ String BfIRBuilder::ToString(BfIRType irType) else { return "Type ???"; - } + } } String BfIRBuilder::ToString(BfIRFunction irFunc) @@ -1966,7 +1965,7 @@ String BfIRBuilder::ToString(BfIRFunction irFunc) return "null"; std::string outStr; llvm::raw_string_ostream strStream(outStr); - val->print(strStream); + val->print(strStream); strStream.flush(); return outStr; } @@ -1977,7 +1976,7 @@ String BfIRBuilder::ToString(BfIRFunction irFunc) return "null"; String str; - BeDumpContext dc; + BeDumpContext dc; dc.ToString(str, val); return str; } @@ -2003,7 +2002,7 @@ String BfIRBuilder::ToString(BfIRFunctionType irType) } String BfIRBuilder::ToString(BfIRMDNode irMDNode) -{ +{ if (mBfIRCodeGen != NULL) { auto md = mBfIRCodeGen->GetLLVMMetadata(irMDNode.mId); @@ -2021,7 +2020,7 @@ String BfIRBuilder::ToString(BfIRMDNode irMDNode) if (md == NULL) return "null"; String str; - BeDumpContext dc; + BeDumpContext dc; dc.ToString(str, md); return str; } @@ -2037,7 +2036,7 @@ String BfIRBuilder::ActiveFuncToString() llvm::raw_string_ostream strStream(outStr); mBfIRCodeGen->mActiveFunction->print(strStream); return outStr; - } + } else return "???"; } @@ -2095,7 +2094,7 @@ void BfIRBuilder::pmd(const BfIRMDNode& irMDNode) } void BfIRBuilder::GetBufferData(Array& outBuffer) -{ +{ if (mStream.GetSize() == 0) return; @@ -2135,21 +2134,21 @@ void BfIRBuilder::ClearNonConstData() } void BfIRBuilder::Start(const StringImpl& moduleName, int ptrSize, bool isOptimized) -{ +{ mHasStarted = true; WriteCmd(BfIRCmd_Module_Start, moduleName, ptrSize, isOptimized); NEW_CMD_INSERTED; } void BfIRBuilder::SetBackend(bool isBeefBackend) -{ +{ mIsBeefBackend = isBeefBackend; BF_ASSERT(mIRCodeGen == NULL); if (mDbgVerifyCodeGen) { if (isBeefBackend) - { + { mBeIRCodeGen = new BeIRCodeGen(); mBeIRCodeGen->mStream = &mStream; mBeIRCodeGen->mBfIRBuilder = this; @@ -2167,7 +2166,7 @@ void BfIRBuilder::SetBackend(bool isBeefBackend) while (mStream.GetReadPos() < mStream.GetSize()) mIRCodeGen->HandleNextCmd(); - } + } } void BfIRBuilder::RemoveIRCodeGen() @@ -2187,7 +2186,7 @@ void BfIRBuilder::WriteIR(const StringImpl& fileName) } void BfIRBuilder::Module_SetTargetTriple(const StringImpl& targetTriple, const StringImpl& targetCPU) -{ +{ WriteCmd(BfIRCmd_Module_SetTargetTriple, targetTriple, targetCPU); NEW_CMD_INSERTED; } @@ -2211,15 +2210,15 @@ void BfIRBuilder::WriteSLEB128(int64 value) bool hasMore; do { - uint8 curByte = (uint8)(value & 0x7f); + uint8 curByte = (uint8)(value & 0x7f); value >>= 7; hasMore = !((((value == 0) && ((curByte & 0x40) == 0)) || ((value == -1) && ((curByte & 0x40) != 0)))); if (hasMore) - curByte |= 0x80; + curByte |= 0x80; mStream.Write(curByte); } - while (hasMore); + while (hasMore); } void BfIRBuilder::WriteSLEB128(int32 value) @@ -2231,7 +2230,7 @@ void BfIRBuilder::WriteSLEB128(int32 value) // mStream.Write((uint8)value); // return; // } -// +// // if (value >= -0x2000) // { // uint16 val = @@ -2240,7 +2239,7 @@ void BfIRBuilder::WriteSLEB128(int32 value) // mStream.Write_2(val); // return; // } -// +// // if (value >= -0x100000) // { // uint32 val = @@ -2250,7 +2249,7 @@ void BfIRBuilder::WriteSLEB128(int32 value) // mStream.Write_3(val); // return; // } -// +// // if (value >= -0x8000000) // { // uint32 val = @@ -2278,7 +2277,7 @@ void BfIRBuilder::WriteSLEB128(int32 value) mStream.Write_2(val); return; } -// +// // if (value <= 0x0FFFFF) // { // uint32 val = @@ -2288,7 +2287,7 @@ void BfIRBuilder::WriteSLEB128(int32 value) // mStream.Write_3(val); // return; // } -// +// // if (value <= 0x7FFFFF) // { // uint32 val = @@ -2316,12 +2315,12 @@ void BfIRBuilder::WriteSLEB128(int32 value) void BfIRBuilder::Write(uint8 val) { - mStream.Write(val); + mStream.Write(val); } void BfIRBuilder::Write(bool val) { - mStream.Write(val ? 1 : 0); + mStream.Write(val ? 1 : 0); } void BfIRBuilder::Write(int intVal) @@ -2343,18 +2342,18 @@ void BfIRBuilder::Write(Val128 val) void BfIRBuilder::Write(const StringImpl&str) { WriteSLEB128((int)str.length()); - mStream.Write(str.c_str(), (int)str.length()); + mStream.Write(str.c_str(), (int)str.length()); } void BfIRBuilder::Write(const BfIRValue& irValue) -{ +{ if ((irValue.mFlags & BfIRValueFlags_Const) != 0) { auto constant = GetConstantById(irValue.mId); - + mStream.Write(BfIRParamType_Const); mStream.Write((uint8)constant->mTypeCode); - + switch ((int)constant->mTypeCode) { case (int)BfTypeCode_Float: @@ -2363,7 +2362,7 @@ void BfIRBuilder::Write(const BfIRValue& irValue) mStream.Write(&f, sizeof(float)); } break; - case (int)BfTypeCode_Double: + case (int)BfTypeCode_Double: { mStream.Write(&constant->mDouble, sizeof(double)); } @@ -2382,7 +2381,7 @@ void BfIRBuilder::Write(const BfIRValue& irValue) case (int)BfTypeCode_UIntUnknown: case (int)BfTypeCode_Char8: case (int)BfTypeCode_Char16: - case (int)BfTypeCode_Char32: + case (int)BfTypeCode_Char32: { WriteSLEB128(constant->mInt64); } @@ -2451,7 +2450,7 @@ void BfIRBuilder::Write(const BfIRValue& irValue) auto gepConst = (BfConstantExtractValue*)constant; BfIRValue targetConst(BfIRValueFlags_Const, gepConst->mTarget); Write(targetConst); - Write(gepConst->mIdx0); + Write(gepConst->mIdx0); } break; case (int)BfConstType_PtrToInt: @@ -2462,7 +2461,7 @@ void BfIRBuilder::Write(const BfIRValue& irValue) Write(ptrToIntConst->mToTypeCode); } break; - case (int)BfConstType_IntToPtr: + case (int)BfConstType_IntToPtr: { auto intToPtrConst = (BfConstantIntToPtr*)constant; BfIRValue targetConst(BfIRValueFlags_Const, intToPtrConst->mTarget); @@ -2486,7 +2485,7 @@ void BfIRBuilder::Write(const BfIRValue& irValue) { Write(constant->mInt64); } - break; + break; case (int)BfConstType_TypeOf: { auto typeofConst = (BfTypeOf_Const*)constant; @@ -2506,7 +2505,7 @@ void BfIRBuilder::Write(const BfIRValue& irValue) Write(typeofConst->mTypeData); } break; - default: + default: { BF_FATAL("Unhandled"); } @@ -2552,7 +2551,7 @@ void BfIRBuilder::Write(const BfIRValue& irValue) void BfIRBuilder::Write(BfTypeCode typeCode) { - mStream.Write((uint8)typeCode); + mStream.Write((uint8)typeCode); } void BfIRBuilder::Write(const BfIRTypeData& type) @@ -2567,9 +2566,9 @@ void BfIRBuilder::Write(const BfIRTypeData& type) else if (type.mKind != BfIRTypeData::TypeKind_None) WriteSLEB128(type.mId); } - + void BfIRBuilder::Write(BfIRFunctionType funcType) -{ +{ WriteSLEB128(funcType.mId); } @@ -2592,18 +2591,18 @@ void BfIRBuilder::Write(BfIRMDNode node) } BfIRValue BfIRBuilder::WriteCmd(BfIRCmd cmd) -{ +{ if (mIgnoreWrites) - return GetFakeVal(); + return GetFakeVal(); mStream.Write((uint8)cmd); return BfIRValue(BfIRValueFlags_Value, mCmdCount++); } void BfIRBuilder::NewCmdInserted() -{ +{ BF_ASSERT(mIgnoreWrites || mHasStarted); if (mIgnoreWrites) - return; + return; if (mIRCodeGen == NULL) return; @@ -2614,9 +2613,9 @@ void BfIRBuilder::NewCmdInserted() } BfIRMDNode BfIRBuilder::CreateNamespaceScope(BfType* type, BfIRMDNode fileDIScope) -{ +{ BfIRMDNode curDIScope = fileDIScope; - auto typeInstance = type->ToTypeInstance(); + auto typeInstance = type->ToTypeInstance(); if (mModule->mCompiler->mOptions.IsCodeView()) { @@ -2626,7 +2625,7 @@ BfIRMDNode BfIRBuilder::CreateNamespaceScope(BfType* type, BfIRMDNode fileDIScop if (typeInstance != NULL) { - auto typeDef = typeInstance->mTypeDef; + auto typeDef = typeInstance->mTypeDef; if (!typeInstance->IsBoxed()) { @@ -2639,7 +2638,7 @@ BfIRMDNode BfIRBuilder::CreateNamespaceScope(BfType* type, BfIRMDNode fileDIScop curNamespace = innerTypeInst->mTypeDef->mNamespace; } else - curNamespace = typeDef->mNamespace; + curNamespace = typeDef->mNamespace; for (int partCount = 0; partCount < curNamespace.GetPartsCount(); partCount++) { @@ -2665,7 +2664,7 @@ String BfIRBuilder::GetDebugTypeName(BfTypeInstance* typeInstance, bool includeO if (boxedType->IsBoxedStructPtr()) typeName += "*"; typeName = "Box<" + typeName + ">"; - } + } else if (includeOuterTypeName) { typeName = mModule->TypeToString(typeInstance, (BfTypeNameFlags)(typeNameFlags | BfTypeNameFlag_OmitNamespace)); @@ -2683,7 +2682,7 @@ String BfIRBuilder::GetDebugTypeName(BfTypeInstance* typeInstance, bool includeO typeName.Insert(i, ":"); } } - + //DbgAddPrefix(typeName); return typeName; } @@ -2711,22 +2710,22 @@ public: #endif void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine) -{ +{ auto populateModule = mModule->mContext->mUnreifiedModule; auto typeInstance = type->ToTypeInstance(); if ((typeInstance != NULL) && (typeInstance->mModule != NULL)) populateModule = typeInstance->mModule; bool wantDIData = DbgHasInfo() && (!type->IsUnspecializedType()); - - // Types that don't have a proper 'defining module' need to be defined in every module they are used + + // Types that don't have a proper 'defining module' need to be defined in every module they are used bool wantsDIForwardDecl = (type->GetModule() != mModule) && (!type->IsFunction()); // Forward declarations of valuetypes don't work in LLVM backend for Win32..... //TODO: Why was this commented out? bool wantsDIPartialDef = false; if (wantsDIForwardDecl) - { + { if ((!mIsBeefBackend) && (type->IsValueType())) { wantsDIPartialDef = true; @@ -2744,7 +2743,7 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine) populateModule->PopulateType(type, BfPopulateType_Declaration); BF_ASSERT(type->IsDeclared()); - + #ifdef BFIR_RENTRY_CHECK ReEntryCheck reEntryCheck(&mDeclReentrySet, type); #endif @@ -2752,7 +2751,7 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine) BfIRType irType; BfIRMDNode diType; bool trackDIType = false; - + BfType* underlyingArrayType = NULL; int underlyingArraySize = -1; bool underlyingArrayIsVector = false; @@ -2761,61 +2760,60 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine) if (type->IsPointer()) { - BfPointerType* pointerType = (BfPointerType*)type; + BfPointerType* pointerType = (BfPointerType*)type; populateModule->PopulateType(pointerType->mElementType, BfPopulateType_Data); if (pointerType->mElementType->IsValuelessType()) { irType = GetPrimitiveType(BfTypeCode_NullPtr); } else - { + { irType = GetPointerTo(MapType(pointerType->mElementType)); } - + if (wantDIData) - { - diType = DbgCreatePointerType(DbgGetType(pointerType->mElementType, BfIRPopulateType_Declaration)); + { + diType = DbgCreatePointerType(DbgGetType(pointerType->mElementType, BfIRPopulateType_Declaration)); trackDIType = true; } } else if (type->IsRef()) { - BfRefType* refType = (BfRefType*)type; - + BfRefType* refType = (BfRefType*)type; + if (refType->mElementType->IsValuelessType()) irType = GetPrimitiveType(BfTypeCode_NullPtr); else { //mModule->PopulateType(refType->mElementType, BfPopulateType_Declaration); - irType = GetPointerTo(MapType(refType->mElementType)); + irType = GetPointerTo(MapType(refType->mElementType)); } if ((wantDIData) && (!type->IsUnspecializedType())) - { - diType = DbgCreateReferenceType(DbgGetType(refType->mElementType)); - trackDIType = true; + { + diType = DbgCreateReferenceType(DbgGetType(refType->mElementType)); + trackDIType = true; } } else if ((type->IsGenericParam()) || (type->IsModifiedTypeType())) { //mModule->PopulateType(mModule->mContext->mBfObjectType, BfPopulateType_Declaration); - irType = MapType(mModule->mContext->mBfObjectType); + irType = MapType(mModule->mContext->mBfObjectType); if (wantDIData) diType = DbgGetType(mModule->mContext->mBfObjectType); } else if (type->IsConcreteInterfaceType()) { BfConcreteInterfaceType* concreteInterfaceType = (BfConcreteInterfaceType*)type; - irType = MapType(concreteInterfaceType->mInterface); + irType = MapType(concreteInterfaceType->mInterface); if (wantDIData) { diType = DbgGetType(concreteInterfaceType->mInterface); - - } + } } else if (type->IsMethodRef()) { - auto methodRefType = (BfMethodRefType*)type; + auto methodRefType = (BfMethodRefType*)type; BfMethodInstance* methodInstance = methodRefType->mMethodRef; String name = "_BF_MethodRef_"; @@ -2826,8 +2824,8 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine) BF_ASSERT(methodInstance != NULL); if ((wantDIData) && (methodInstance != NULL)) - { - auto typeDeclaration = methodInstance->GetOwner()->mTypeDef->mTypeDeclaration; + { + auto typeDeclaration = methodInstance->GetOwner()->mTypeDef->mTypeDeclaration; BfFileInstance* bfFileInstance; if (typeDeclaration != NULL) @@ -2835,18 +2833,18 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine) else bfFileInstance = mModule->GetFileFromNode(mModule->mContext->mBfObjectType->mTypeDef->mTypeDeclaration); - auto namespaceScope = DbgCreateNameSpace(bfFileInstance->mDIFile, "_bf", bfFileInstance->mDIFile, 0); - + auto namespaceScope = DbgCreateNameSpace(bfFileInstance->mDIFile, "_bf", bfFileInstance->mDIFile, 0); + StringT<128> mangledName; BfMangler::Mangle(mangledName, mModule->mCompiler->GetMangleKind(), methodInstance); - + int captureSize = 0; int captureAlign = 0; BfIRMDNode derivedFrom; Array elements; - + diType = DbgCreateReplaceableCompositeType(llvm::dwarf::DW_TAG_structure_type, name, namespaceScope, bfFileInstance->mDIFile, 0, captureSize * 8, captureAlign * 8, 0); - + auto int64Type = mModule->GetPrimitiveType(BfTypeCode_Int64); auto memberType = DbgCreateMemberType(diType, mangledName, bfFileInstance->mDIFile, 0, 0, 0, -1, 0, DbgGetType(int64Type)); elements.Add(memberType); @@ -2867,19 +2865,19 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine) offset = BF_ALIGN(offset, methodRefType->mAlign); BF_ASSERT(offset == methodRefType->mSize); - + DbgMakePermanent(diType, derivedFrom, elements); } - Array members; + Array members; for (int dataIdx = 0; dataIdx < methodRefType->GetCaptureDataCount(); dataIdx++) { - BfType* paramType = methodRefType->GetCaptureType(dataIdx); + BfType* paramType = methodRefType->GetCaptureType(dataIdx); if (paramType->IsValueType()) PopulateType(paramType, BfIRPopulateType_Eventually_Full); members.Add(MapType(paramType)); } - + irType = CreateStructType(name); StructSetBody(irType, members, type->mSize, type->mAlign, false); } @@ -2888,7 +2886,7 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine) BfSizedArrayType* arrayType = (BfSizedArrayType*)type; auto elementType = arrayType->mElementType; BfIRType elementIrType; - + if (elementType->IsValueType()) { //mModule->PopulateType(arrayType->mElementType, BfPopulateType_Data); @@ -2899,9 +2897,9 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine) //mModule->PopulateType(arrayType->mElementType, BfPopulateType_Declaration); elementIrType = MapType(arrayType->mElementType); } - - if (arrayType->mElementType->IsValuelessType()) - irType = elementIrType; + + if (arrayType->mElementType->IsValuelessType()) + irType = elementIrType; else irType = GetSizedArrayType(MapType(arrayType->mElementType), BF_MAX(arrayType->mElementCount, 0)); // else if (arrayType->mElementType->IsSizeAligned()) @@ -2909,7 +2907,7 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine) // else // irType = GetSizedArrayType(MapType(mModule->GetPrimitiveType(BfTypeCode_Int8)), BF_MAX(arrayType->mSize, 0)); - if (wantDIData) + if (wantDIData) diType = DbgCreateArrayType((int64)arrayType->mSize * 8, arrayType->mAlign * 8, DbgGetType(arrayType->mElementType), arrayType->mElementCount); } else if (type->IsPrimitiveType()) @@ -2919,12 +2917,12 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine) if ((typeCode == BfTypeCode_Var) || (typeCode == BfTypeCode_Let) || (typeCode == BfTypeCode_Self)) { //mModule->PopulateType(mModule->mContext->mBfObjectType, BfPopulateType_Declaration); - irType = MapType(mModule->mContext->mBfObjectType); + irType = MapType(mModule->mContext->mBfObjectType); if (wantDIData) diType = DbgGetType(mModule->mContext->mBfObjectType); } else if (typeCode == BfTypeCode_NullPtr) - { + { irType = GetPrimitiveType(typeCode); if (wantDIData) @@ -2935,7 +2933,7 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine) } else { - irType = GetPrimitiveType(typeCode); + irType = GetPrimitiveType(typeCode); if (wantDIData) { int dwarfType = 0; @@ -2958,7 +2956,7 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine) case BfTypeCode_UInt16: case BfTypeCode_UInt32: case BfTypeCode_UInt64: - case BfTypeCode_UIntPtr: + case BfTypeCode_UIntPtr: dwarfType = llvm::dwarf::DW_ATE_unsigned; break; case BfTypeCode_Char8: @@ -2977,11 +2975,11 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine) diType = DbgCreateBasicType(primType->mTypeDef->mName->ToString(), primType->mSize * 8, primType->mAlign * 8, dwarfType); } } - } + } else if (type->IsTypeInstance()) - { + { auto typeDef = typeInstance->mTypeDef; - + BfIRMDNode diForwardDecl; if (wantDIData) { @@ -3012,14 +3010,14 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine) curDIScope = CreateNamespaceScope(checkType, fileDIScope); String typeName = GetDebugTypeName(typeInstance, false); if (wantsDIForwardDecl) - { + { if (type->IsInterface()) { int flags = 0; diForwardDecl = DbgCreateReplaceableCompositeType(llvm::dwarf::DW_TAG_structure_type, typeName, curDIScope, fileDIScope, 0, (int64)0 * 8, (int64)0 * 8, flags); auto derivedFrom = DbgGetTypeInst(mModule->mContext->mBfObjectType); - SizedArray diFieldTypes; + SizedArray diFieldTypes; auto inheritanceType = DbgCreateInheritance(diForwardDecl, derivedFrom, 0, llvm::DINode::FlagPublic); diFieldTypes.push_back(inheritanceType); DbgMakePermanent(diForwardDecl, derivedFrom, diFieldTypes); @@ -3031,15 +3029,15 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine) } } else - { + { if (wantsDIPartialDef) typeName += "$part"; - // Will fill in later (during definition phase) + // Will fill in later (during definition phase) int flags = 0; diForwardDecl = DbgCreateReplaceableCompositeType(llvm::dwarf::DW_TAG_structure_type, typeName, curDIScope, fileDIScope, 0, (int64)BF_ALIGN(typeInstance->mInstSize, typeInstance->mInstAlign) * 8, (int64)typeInstance->mInstAlign * 8, flags); - + mDITemporaryTypes.push_back(typeInstance); if (!type->IsUnspecializedType()) @@ -3047,16 +3045,16 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine) BF_ASSERT(!mDeferredDbgTypeDefs.Contains(type)); mDeferredDbgTypeDefs.Add(type); } - } + } - DbgSetInstType(type, diForwardDecl); + DbgSetInstType(type, diForwardDecl); BfIRMDNode diType; - if (type->IsValueType()) - diType = diForwardDecl; - else + if (type->IsValueType()) + diType = diForwardDecl; + else diType = DbgCreatePointerType(diForwardDecl); - DbgSetType(type, diType); + DbgSetType(type, diType); } if (underlyingArraySize != -1) @@ -3068,14 +3066,14 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine) irType = GetVectorType(MapType(underlyingArrayType), underlyingArraySize); } else - irType = GetSizedArrayType(MapType(underlyingArrayType), underlyingArraySize); + irType = GetSizedArrayType(MapType(underlyingArrayType), underlyingArraySize); SetType(type, irType); } else if (type->IsTypedPrimitive()) { populateModule->PopulateType(type); - auto underlyingType = type->GetUnderlyingType(); - irType = MapType(underlyingType); + auto underlyingType = type->GetUnderlyingType(); + irType = MapType(underlyingType); SetType(type, irType); SetInstType(type, irType); } @@ -3097,8 +3095,8 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine) SetType(type, irStructType); SetInstType(type, irStructType); } - } - return; + } + return; } if (irType) @@ -3120,10 +3118,10 @@ void BfIRBuilder::CreateDbgTypeDefinition(BfType* type) bool isPrimEnum = (type->IsEnum()) && (type->IsTypedPrimitive()); auto typeDef = typeInstance->mTypeDef; bool wantDIData = true; - + BfModuleOptions moduleOptions = mModule->GetModuleOptions(); bool isOptimized = (moduleOptions.mOptLevel != BfOptLevel_O0) && (moduleOptions.mOptLevel != BfOptLevel_OgPlus); - + BfIRMDNode fileDIScope; if (wantDIData) { @@ -3139,9 +3137,9 @@ void BfIRBuilder::CreateDbgTypeDefinition(BfType* type) #ifdef BFIR_RENTRY_CHECK ReEntryCheck reEntryCheck(&mDefReentrySet, type); #endif - + //BF_ASSERT(WantsDbgDefinition(type)); - + SizedArray diFieldTypes; int packing = 0; @@ -3150,10 +3148,9 @@ void BfIRBuilder::CreateDbgTypeDefinition(BfType* type) BfType* underlyingArrayType = NULL; int underlyingArraySize = -1; bool underlyingArrayIsVector = false; - + if (typeInstance->IsBoxed()) { - } else { @@ -3187,8 +3184,8 @@ void BfIRBuilder::CreateDbgTypeDefinition(BfType* type) diFieldTypes.push_back(memberType); } - bool isPayloadEnum = (typeInstance->IsEnum()) && (!typeInstance->IsTypedPrimitive()); - for (int fieldIdx = 0; fieldIdx < typeInstance->mFieldInstances.mSize; fieldIdx++) + bool isPayloadEnum = (typeInstance->IsEnum()) && (!typeInstance->IsTypedPrimitive()); + for (int fieldIdx = 0; fieldIdx < typeInstance->mFieldInstances.mSize; fieldIdx++) { auto fieldInstance = &typeInstance->mFieldInstances[fieldIdx]; if (!fieldInstance->mFieldIncluded) @@ -3198,13 +3195,13 @@ void BfIRBuilder::CreateDbgTypeDefinition(BfType* type) if ((fieldInstance->mResolvedType == NULL) || (typeInstance->IsBoxed())) continue; - auto resolvedFieldType = fieldInstance->GetResolvedType(); + auto resolvedFieldType = fieldInstance->GetResolvedType(); mModule->PopulateType(resolvedFieldType, BfPopulateType_Declaration); BfIRType resolvedFieldIRType = MapType(resolvedFieldType); BfIRMDNode resolvedFieldDIType; if ((fieldDef != NULL) && (!fieldDef->mIsStatic) && (resolvedFieldType->IsStruct())) - PopulateType(resolvedFieldType, BfIRPopulateType_Eventually_Full); + PopulateType(resolvedFieldType, BfIRPopulateType_Eventually_Full); resolvedFieldDIType = DbgGetType(resolvedFieldType); if (fieldInstance->IsAppendedObject()) @@ -3213,7 +3210,7 @@ void BfIRBuilder::CreateDbgTypeDefinition(BfType* type) if ((fieldDef == NULL) && (typeInstance->IsPayloadEnum())) { orderedFields.push_back(fieldInstance); - + int lineNum = 0; int flags = llvm::DINode::FlagPublic; auto fieldType = fieldInstance->mResolvedType; @@ -3234,7 +3231,7 @@ void BfIRBuilder::CreateDbgTypeDefinition(BfType* type) { auto payloadType = fieldInstance->mResolvedType; if (payloadType == NULL) - payloadType = mModule->CreateTupleType(BfTypeVector(), Array()); + payloadType = mModule->CreateTupleType(BfTypeVector(), Array()); String fieldName = StrFormat("_%d_%s", -fieldInstance->mDataIdx - 1, fieldDef->mName.c_str()); @@ -3288,7 +3285,7 @@ void BfIRBuilder::CreateDbgTypeDefinition(BfType* type) bool useIntConstant = false; bool wasMadeAddr = false; - + StringT<128> staticVarName; BfMangler::Mangle(staticVarName, mModule->mCompiler->GetMangleKind(), fieldInstance); @@ -3303,18 +3300,18 @@ void BfIRBuilder::CreateDbgTypeDefinition(BfType* type) if ((constant->mConstType == BfConstType_Agg) || (constant->mConstType == BfConstType_AggZero) || (constant->mTypeCode == BfTypeCode_NullPtr)) - { + { staticValue = ConstToMemory(staticValue); - wasMadeAddr = true; + wasMadeAddr = true; } else if (constant->mTypeCode == BfTypeCode_StringId) { int stringId = constant->mInt32; const StringImpl& str = mModule->mContext->mStringObjectIdMap[stringId].mString; if (resolvedFieldType->IsPointer()) - staticValue = mModule->GetStringCharPtr(str); - else - staticValue = mModule->GetStringObjectValue(str); + staticValue = mModule->GetStringCharPtr(str); + else + staticValue = mModule->GetStringObjectValue(str); } else { @@ -3322,9 +3319,9 @@ void BfIRBuilder::CreateDbgTypeDefinition(BfType* type) continue; } } - + if (!useIntConstant) - { + { auto useType = resolvedFieldType; if (wasMadeAddr) useType = mModule->CreatePointerType(useType); @@ -3348,7 +3345,7 @@ void BfIRBuilder::CreateDbgTypeDefinition(BfType* type) { int flags = 0; String fieldName = fieldDef->mName; - if ((constant != NULL) && + if ((constant != NULL) && ((IsIntable(constant->mTypeCode)) || (IsFloat(constant->mTypeCode)))) { int64 writeVal = constant->mInt64; @@ -3361,7 +3358,7 @@ void BfIRBuilder::CreateDbgTypeDefinition(BfType* type) if (writeVal < 0) fieldName += StrFormat("$_%llu", -writeVal); else - fieldName += StrFormat("$%llu", writeVal); + fieldName += StrFormat("$%llu", writeVal); } auto memberType = DbgCreateStaticMemberType(diForwardDecl, fieldName, fileDIScope, 0, constDIType, flags, staticValue); @@ -3406,7 +3403,7 @@ void BfIRBuilder::CreateDbgTypeDefinition(BfType* type) bool useForUnion = false; BF_ASSERT(!fieldInstance->mIsEnumPayloadCase); - + if (wantDIData) { int lineNum = 0; @@ -3431,16 +3428,16 @@ void BfIRBuilder::CreateDbgTypeDefinition(BfType* type) int unionSize = 0; if (typeInstance->mIsUnion) { - auto unionInnerType = typeInstance->GetUnionInnerType(); + auto unionInnerType = typeInstance->GetUnionInnerType(); unionSize = unionInnerType->mSize; dataPos += unionSize; } - + bool wantsMethods = true; // We can't directly call boxed methods from the debugger if (type->IsBoxed()) - wantsMethods = false; + wantsMethods = false; if (!isDefiningModule) wantsMethods = false; @@ -3451,8 +3448,8 @@ void BfIRBuilder::CreateDbgTypeDefinition(BfType* type) { auto& methodGroup = typeInstance->mMethodInstanceGroups[methodIdx]; auto methodInstance = methodGroup.mDefault; - - // We're only adding non-generic methods at the moment + + // We're only adding non-generic methods at the moment if ((methodInstance == NULL) || (methodInstance->mIsUnspecialized)) continue; @@ -3529,7 +3526,7 @@ void BfIRBuilder::CreateDbgTypeDefinition(BfType* type) /*if (isPrimEnum) { - // Handled below + // Handled below } else*/ if (type->IsBoxed()) { @@ -3549,9 +3546,9 @@ void BfIRBuilder::CreateDbgTypeDefinition(BfType* type) flags, DbgGetType(underlyingType)); diFieldTypes.push_back(memberType); } - } + } else - { + { auto baseType = typeInstance->mBaseType; if (baseType != NULL) @@ -3610,7 +3607,7 @@ void BfIRBuilder::CreateDbgTypeDefinition(BfType* type) BfIRMDNode diType; /*if ((typeInstance->IsEnum()) && (typeInstance->IsTypedPrimitive())) - { + { llvm::SmallVector diEnumValues; for (auto& fieldInst : typeInstance->mFieldInstances) @@ -3632,10 +3629,10 @@ void BfIRBuilder::CreateDbgTypeDefinition(BfType* type) DbgSetInstType(type, diType); } else*/ - { + { BfIRMDNode diCompositeType = DbgMakePermanent(diForwardDecl, BfIRMDNode(), diFieldTypes); diType = diCompositeType; - } + } } bool BfIRBuilder::WantsDbgDefinition(BfType* type) @@ -3746,7 +3743,6 @@ void BfIRBuilder::CreateTypeDefinition_Data(BfModule* populateModule, BfTypeInst orderedFields.push_back(NULL); orderedFields[fieldInstance->mDataIdx] = fieldInstance; } - } } } @@ -3804,7 +3800,7 @@ void BfIRBuilder::CreateTypeDefinition_Data(BfModule* populateModule, BfTypeInst BF_ASSERT((int)irFieldTypes.size() == fieldInstance->mDataIdx); irFieldTypes.push_back(resolvedFieldIRType); - } + } if (isCRepr) { @@ -3821,7 +3817,6 @@ void BfIRBuilder::CreateTypeDefinition_Data(BfModule* populateModule, BfTypeInst if (typeInstance->mIsUnion) { - } else if ((typeInstance->IsEnum()) && (typeInstance->IsStruct())) { @@ -3843,7 +3838,7 @@ void BfIRBuilder::CreateTypeDefinition_Data(BfModule* populateModule, BfTypeInst } void BfIRBuilder::CreateTypeDefinition(BfType* type, bool forceDbgDefine) -{ +{ auto populateModule = mModule->mContext->mUnreifiedModule; auto typeInstance = type->ToTypeInstance(); if (typeInstance != NULL) @@ -3852,7 +3847,7 @@ void BfIRBuilder::CreateTypeDefinition(BfType* type, bool forceDbgDefine) // This PopulateType is generally NOT needed, but here is a scenario in which it is: // ClassB derives from ClassA. ClassC uses ClassB. A method inside ClassA gets modified, // marking ClassA as incomplete, and then ClassC rebuilds and calls MapType on ClassB. - // "ClassB" itself is still populated, but its base class (ClassA) is not -- until we call + // "ClassB" itself is still populated, but its base class (ClassA) is not -- until we call // this PopulateType below. if (type->IsDataIncomplete()) populateModule->PopulateType(type, BfPopulateType_Data); @@ -3860,7 +3855,7 @@ void BfIRBuilder::CreateTypeDefinition(BfType* type, bool forceDbgDefine) bool isDefiningModule = ((type->GetModule() == mModule) || (type->IsFunction())); if (mModule->mExtensionCount != 0) isDefiningModule = false; - + // if (mModule->mModuleName == "vdata") // isDefiningModule = true; @@ -3879,14 +3874,14 @@ void BfIRBuilder::CreateTypeDefinition(BfType* type, bool forceDbgDefine) { DbgSetTypeSize(DbgGetType(type), BF_ALIGN(type->mSize, type->mAlign) * 8, type->mAlign * 8); } - + bool isPrimEnum = (type->IsEnum()) && (type->IsTypedPrimitive()); - + if (typeInstance == NULL) - return; + return; BfType* underlyingArrayType = NULL; - int underlyingArraySize = -1; + int underlyingArraySize = -1; bool underlyingIsVector = false; typeInstance->GetUnderlyingArray(underlyingArrayType, underlyingArraySize, underlyingIsVector); if (underlyingArraySize > 0) @@ -3919,7 +3914,7 @@ void BfIRBuilder::CreateTypeDefinition(BfType* type, bool forceDbgDefine) //if ((fieldDef != NULL) && (!fieldDef->mIsStatic) && (resolvedFieldType->IsStruct())) //PopulateType(resolvedFieldType, BfIRPopulateType_Eventually_Full); - + if ((!typeInstance->IsBoxed()) && (fieldDef != NULL)) { if (fieldDef->mIsConst) @@ -3960,10 +3955,8 @@ void BfIRBuilder::ReplaceDITemporaryTypes() mDITemporaryTypes.Clear(); } - void BfIRBuilder::PushDbgLoc(BfTypeInstance* typeInst) { - } BfIRPopulateType BfIRBuilder::GetPopulateTypeState(BfType* type) @@ -3978,7 +3971,7 @@ void BfIRBuilder::PopulateType(BfType* type, BfIRPopulateType populateType) { if (mIgnoreWrites) return; - + BF_ASSERT(!mModule->mIsScratchModule); if (populateType == BfIRPopulateType_Identity) @@ -3993,19 +3986,19 @@ void BfIRBuilder::PopulateType(BfType* type, BfIRPopulateType populateType) return; if (curPopulateType == BfIRPopulateType_Full) return; - + auto typeInst = type->ToTypeInstance(); if ((curPopulateType < BfIRPopulateType_Declaration) && (populateType >= BfIRPopulateType_Declaration)) - { + { CreateTypeDeclaration(type, populateType == BfIRPopulateType_Full_ForceDefinition); - + mTypeMap[type] = BfIRPopulateType_Declaration; } - + if ((curPopulateType < populateType) && (populateType >= BfIRPopulateType_Eventually_Full)) { - mTypeMap[type] = BfIRPopulateType_Eventually_Full; + mTypeMap[type] = BfIRPopulateType_Eventually_Full; CreateTypeDefinition(type, populateType == BfIRPopulateType_Full_ForceDefinition); mTypeMap[type] = BfIRPopulateType_Full; } @@ -4050,14 +4043,14 @@ BfIRValue BfIRBuilder::GetFakeConst() BfIRType BfIRBuilder::GetFakeType() { - BfIRType type; + BfIRType type; type.mId = GetFakeId(); return type; } BfIRType BfIRBuilder::GetFakeBlock() { - BfIRBlock block; + BfIRBlock block; block.mFlags = BfIRValueFlags_Block; block.mId = GetFakeId(); return block; @@ -4109,9 +4102,9 @@ void BfIRBuilder::StructSetBody(BfIRType type, const BfSizedArray& mem } BfIRType BfIRBuilder::MapType(BfType* type, BfIRPopulateType populateType) -{ +{ if (!mIgnoreWrites) - { + { PopulateType(type, populateType); } BF_ASSERT(type->mTypeId > 0); @@ -4122,9 +4115,9 @@ BfIRType BfIRBuilder::MapType(BfType* type, BfIRPopulateType populateType) } BfIRType BfIRBuilder::MapTypeInst(BfTypeInstance* typeInst, BfIRPopulateType populateType) -{ +{ if (!mIgnoreWrites) - { + { PopulateType(typeInst, populateType); } @@ -4137,7 +4130,7 @@ BfIRType BfIRBuilder::MapTypeInst(BfTypeInstance* typeInst, BfIRPopulateType pop } BfIRType BfIRBuilder::MapTypeInstPtr(BfTypeInstance* typeInst) -{ +{ if (!mIgnoreWrites) { PopulateType(typeInst, BfIRPopulateType_Declaration); @@ -4155,7 +4148,7 @@ BfIRType BfIRBuilder::GetType(BfIRValue val) return GetFakeType(); BfIRType retType = WriteCmd(BfIRCmd_GetType, val); - NEW_CMD_INSERTED_IRTYPE; + NEW_CMD_INSERTED_IRTYPE; return retType; } @@ -4191,7 +4184,7 @@ BfIRType BfIRBuilder::GetSizedArrayType(BfIRType elementType, int length) return retType; } else - { + { BfIRType retType = WriteCmd(BfIRCmd_GetSizedArrayType, elementType, length); NEW_CMD_INSERTED_IRTYPE; return retType; @@ -4199,10 +4192,10 @@ BfIRType BfIRBuilder::GetSizedArrayType(BfIRType elementType, int length) } BfIRType BfIRBuilder::GetVectorType(BfIRType elementType, int length) -{ +{ BfIRType retType = WriteCmd(BfIRCmd_GetVectorType, elementType, length); NEW_CMD_INSERTED_IRTYPE; - return retType; + return retType; } BfIRValue BfIRBuilder::CreateConstAgg_Value(BfIRType type, const BfSizedArray& values) @@ -4225,7 +4218,7 @@ BfIRValue BfIRBuilder::ConstToMemory(BfIRValue constVal) BfIRValue* value = NULL; if (mConstMemMap.TryGetValue(constVal.mId, &value)) return *value; - + BfIRType constType; if (constant->mConstType == BfConstType_Agg) constType = ((BfConstantAgg*)constant)->mType; @@ -4249,7 +4242,7 @@ BfIRValue BfIRBuilder::GetConfigConst(BfIRConfigConst constType, BfTypeCode type BfIRValue BfIRBuilder::GetArgument(int argIdx) { - BfIRValue retVal(BfIRValueFlags_Arg, argIdx); + BfIRValue retVal(BfIRValueFlags_Arg, argIdx); return retVal; } @@ -4345,8 +4338,8 @@ BfIRValue BfIRBuilder::CreateNumericCast(BfIRValue val, bool valIsSigned, BfType // Float -> Float return CreateConst(typeCode, constVal->mDouble); } - } - + } + auto retVal = WriteCmd(BfIRCmd_NumericCast, val, valIsSigned, typeCode); NEW_CMD_INSERTED_IRVALUE; return retVal; @@ -4355,14 +4348,14 @@ BfIRValue BfIRBuilder::CreateNumericCast(BfIRValue val, bool valIsSigned, BfType BfIRValue BfIRBuilder::CreateCmpEQ(BfIRValue lhs, BfIRValue rhs) { if ((lhs.IsConst()) && (rhs.IsConst())) - { + { CMP_APPLY(lhs, rhs, ==); int eqVal = CheckConstEquality(lhs, rhs); if (eqVal != -1) return CreateConst(BfTypeCode_Boolean, (eqVal == 1) ? (uint64)1 : (uint64)0); } - auto retVal = WriteCmd(BfIRCmd_CmpEQ, lhs, rhs); + auto retVal = WriteCmd(BfIRCmd_CmpEQ, lhs, rhs); NEW_CMD_INSERTED_IRVALUE; return retVal; } @@ -4370,7 +4363,7 @@ BfIRValue BfIRBuilder::CreateCmpEQ(BfIRValue lhs, BfIRValue rhs) BfIRValue BfIRBuilder::CreateCmpNE(BfIRValue lhs, BfIRValue rhs) { if ((lhs.IsConst()) && (rhs.IsConst())) - { + { CMP_APPLY(lhs, rhs, !=); int eqVal = CheckConstEquality(lhs, rhs); if (eqVal != -1) @@ -4385,18 +4378,17 @@ BfIRValue BfIRBuilder::CreateCmpNE(BfIRValue lhs, BfIRValue rhs) BfIRValue BfIRBuilder::CreateCmpLT(BfIRValue lhs, BfIRValue rhs, bool isSigned) { if ((lhs.IsConst()) && (rhs.IsConst())) - { + { CMP_APPLY(lhs, rhs, <); } else if ((!isSigned) && (rhs.IsConst())) - { + { // "unsigned < 0" is always false - auto constant = GetConstant(rhs); + auto constant = GetConstant(rhs); if ((IsInt(constant->mTypeCode)) && (constant->mUInt64 == 0)) return CreateConst(BfTypeCode_Boolean, 0); } - auto retVal = WriteCmd(isSigned ? BfIRCmd_CmpSLT : BfIRCmd_CmpULT, lhs, rhs); NEW_CMD_INSERTED_IRVALUE; return retVal; @@ -4405,10 +4397,10 @@ BfIRValue BfIRBuilder::CreateCmpLT(BfIRValue lhs, BfIRValue rhs, bool isSigned) BfIRValue BfIRBuilder::CreateCmpLTE(BfIRValue lhs, BfIRValue rhs, bool isSigned) { if ((lhs.IsConst()) && (rhs.IsConst())) - { + { CMP_APPLY(lhs, rhs, <=); } - + auto retVal = WriteCmd(isSigned ? BfIRCmd_CmpSLE : BfIRCmd_CmpULE, lhs, rhs); NEW_CMD_INSERTED; return retVal; @@ -4417,7 +4409,7 @@ BfIRValue BfIRBuilder::CreateCmpLTE(BfIRValue lhs, BfIRValue rhs, bool isSigned) BfIRValue BfIRBuilder::CreateCmpGT(BfIRValue lhs, BfIRValue rhs, bool isSigned) { if ((lhs.IsConst()) && (rhs.IsConst())) - { + { CMP_APPLY(lhs, rhs, >); } @@ -4429,13 +4421,13 @@ BfIRValue BfIRBuilder::CreateCmpGT(BfIRValue lhs, BfIRValue rhs, bool isSigned) BfIRValue BfIRBuilder::CreateCmpGTE(BfIRValue lhs, BfIRValue rhs, bool isSigned) { if ((lhs.IsConst()) && (rhs.IsConst())) - { + { CMP_APPLY(lhs, rhs, >=); } else if ((!isSigned) && (lhs.IsConst())) - { + { // "0 >= unsigned" is always true - auto constant = GetConstant(lhs); + auto constant = GetConstant(lhs); if ((IsInt(constant->mTypeCode)) && (constant->mUInt64 == 0)) return CreateConst(BfTypeCode_Boolean, 1); } @@ -4456,7 +4448,7 @@ BfIRValue BfIRBuilder::CreateAdd(BfIRValue lhs, BfIRValue rhs, BfOverflowCheckKi BINOPFUNC_APPLY(lhs, rhs, CheckedAdd); } } - + auto retVal = WriteCmd(BfIRCmd_Add, lhs, rhs, overflowCheckKind); NEW_CMD_INSERTED_IRVALUE; @@ -4473,7 +4465,7 @@ BfIRValue BfIRBuilder::CreateSub(BfIRValue lhs, BfIRValue rhs, BfOverflowCheckKi { mOpFailed = false; if ((lhs.IsConst()) && (rhs.IsConst())) - { + { BINOPFUNC_APPLY(lhs, rhs, CheckedSub); } @@ -4493,7 +4485,7 @@ BfIRValue BfIRBuilder::CreateMul(BfIRValue lhs, BfIRValue rhs, BfOverflowCheckKi { mOpFailed = false; if ((lhs.IsConst()) && (rhs.IsConst())) - { + { BINOPFUNC_APPLY(lhs, rhs, CheckedMul); } @@ -4524,7 +4516,7 @@ BfIRValue BfIRBuilder::CreateDiv(BfIRValue lhs, BfIRValue rhs, bool isSigned) if (constRHS->mInt64 != 0) { - INT_BINOP_APPLY(constLHS, constRHS, /); + INT_BINOP_APPLY(constLHS, constRHS, /); } } @@ -4536,7 +4528,7 @@ BfIRValue BfIRBuilder::CreateDiv(BfIRValue lhs, BfIRValue rhs, bool isSigned) BfIRValue BfIRBuilder::CreateRem(BfIRValue lhs, BfIRValue rhs, bool isSigned) { if ((lhs.IsConst()) && (rhs.IsConst())) - { + { auto constLHS = GetConstantById(lhs.mId); auto constRHS = GetConstantById(rhs.mId); @@ -4548,7 +4540,7 @@ BfIRValue BfIRBuilder::CreateRem(BfIRValue lhs, BfIRValue rhs, bool isSigned) if (constRHS->mInt64 != 0) { - INT_BINOP_APPLY(constLHS, constRHS, %); + INT_BINOP_APPLY(constLHS, constRHS, %); } } @@ -4560,7 +4552,7 @@ BfIRValue BfIRBuilder::CreateRem(BfIRValue lhs, BfIRValue rhs, bool isSigned) BfIRValue BfIRBuilder::CreateAnd(BfIRValue lhs, BfIRValue rhs) { if ((lhs.IsConst()) && (rhs.IsConst())) - { + { auto constLHS = GetConstantById(lhs.mId); auto constRHS = GetConstantById(rhs.mId); INT_BINOP_APPLY(constLHS, constRHS, &); @@ -4574,7 +4566,7 @@ BfIRValue BfIRBuilder::CreateAnd(BfIRValue lhs, BfIRValue rhs) BfIRValue BfIRBuilder::CreateOr(BfIRValue lhs, BfIRValue rhs) { if ((lhs.IsConst()) && (rhs.IsConst())) - { + { auto constLHS = GetConstantById(lhs.mId); auto constRHS = GetConstantById(rhs.mId); INT_BINOP_APPLY(constLHS, constRHS, |); @@ -4588,7 +4580,7 @@ BfIRValue BfIRBuilder::CreateOr(BfIRValue lhs, BfIRValue rhs) BfIRValue BfIRBuilder::CreateXor(BfIRValue lhs, BfIRValue rhs) { if ((lhs.IsConst()) && (rhs.IsConst())) - { + { auto constLHS = GetConstantById(lhs.mId); auto constRHS = GetConstantById(rhs.mId); INT_BINOP_APPLY(constLHS, constRHS, ^); @@ -4603,7 +4595,7 @@ BfIRValue BfIRBuilder::CreateShl(BfIRValue lhs, BfIRValue rhs) { mOpFailed = false; if ((lhs.IsConst()) && (rhs.IsConst())) - { + { INT_BINOPFUNC_APPLY(lhs, rhs, CheckedShl); } @@ -4615,10 +4607,10 @@ BfIRValue BfIRBuilder::CreateShl(BfIRValue lhs, BfIRValue rhs) BfIRValue BfIRBuilder::CreateShr(BfIRValue lhs, BfIRValue rhs, bool isSigned) { if ((lhs.IsConst()) && (rhs.IsConst())) - { + { auto constLHS = GetConstantById(lhs.mId); auto constRHS = GetConstantById(rhs.mId); - + uint64 val; if (isSigned) val = (uint64)(constLHS->mInt64 >> constRHS->mInt32); @@ -4635,7 +4627,7 @@ BfIRValue BfIRBuilder::CreateShr(BfIRValue lhs, BfIRValue rhs, bool isSigned) BfIRValue BfIRBuilder::CreateNeg(BfIRValue val) { if (val.IsConst()) - { + { UNARYOP_APPLY(val, -); } @@ -4665,7 +4657,7 @@ BfIRValue BfIRBuilder::CreateNot(BfIRValue val) BfIRValue BfIRBuilder::CreateBitCast(BfIRValue val, BfIRType type) { if (val.IsConst()) - return CreateConstBitCast(val, type); + return CreateConstBitCast(val, type); auto retVal = WriteCmd(BfIRCmd_BitCast, val, type); NEW_CMD_INSERTED_IRVALUE; return retVal; @@ -4680,7 +4672,7 @@ BfIRValue BfIRBuilder::CreatePtrToInt(BfIRValue val, BfTypeCode typeCode) ptrToInt->mConstType = BfConstType_PtrToInt; ptrToInt->mTarget = val.mId; ptrToInt->mToTypeCode = typeCode; - + BfIRValue castedVal(BfIRValueFlags_Const, mTempAlloc.GetChunkedId(ptrToInt)); #ifdef CHECK_CONSTHOLDER castedVal.mHolder = this; @@ -4726,7 +4718,7 @@ BfIRValue BfIRBuilder::CreateInBoundsGEP(BfIRValue val, int idx0) auto constGEP = mTempAlloc.Alloc(); constGEP->mConstType = BfConstType_GEP32_1; constGEP->mTarget = val.mId; - constGEP->mIdx0 = idx0; + constGEP->mIdx0 = idx0; BfIRValue retVal; retVal.mFlags = BfIRValueFlags_Const; @@ -4756,7 +4748,7 @@ BfIRValue BfIRBuilder::CreateInBoundsGEP(BfIRValue val, int idx0, int idx1) BfIRValue retVal; retVal.mFlags = BfIRValueFlags_Const; retVal.mId = mTempAlloc.GetChunkedId(constGEP); - + #ifdef CHECK_CONSTHOLDER retVal.mHolder = this; #endif @@ -4852,7 +4844,7 @@ BfIRValue BfIRBuilder::CreateIsNotNull(BfIRValue val) if (constant->mConstType == BfConstType_BitCastNull) return CreateConst(BfTypeCode_Boolean, 0); if (constant->mConstType == BfConstType_GlobalVar) - return CreateConst(BfTypeCode_Boolean, 1); + return CreateConst(BfTypeCode_Boolean, 1); } BfIRValue retVal = WriteCmd(BfIRCmd_IsNotNull, val); @@ -4861,7 +4853,7 @@ BfIRValue BfIRBuilder::CreateIsNotNull(BfIRValue val) } BfIRValue BfIRBuilder::CreateExtractValue(BfIRValue val, int idx) -{ +{ auto aggConstant = GetConstant(val); if (aggConstant != NULL) { @@ -4870,7 +4862,7 @@ BfIRValue BfIRBuilder::CreateExtractValue(BfIRValue val, int idx) auto arrayConstant = (BfConstantAgg*)aggConstant; return arrayConstant->mValues[idx]; } - + auto constGEP = mTempAlloc.Alloc(); constGEP->mConstType = BfConstType_ExtractValue; constGEP->mTarget = val.mId; @@ -4883,7 +4875,7 @@ BfIRValue BfIRBuilder::CreateExtractValue(BfIRValue val, int idx) #ifdef CHECK_CONSTHOLDER retVal.mHolder = this; #endif - return retVal; + return retVal; } BfIRValue retVal = WriteCmd(BfIRCmd_ExtractValue, val, idx); @@ -4892,11 +4884,11 @@ BfIRValue BfIRBuilder::CreateExtractValue(BfIRValue val, int idx) } BfIRValue BfIRBuilder::CreateExtractValue(BfIRValue val, BfIRValue idx) -{ +{ auto idxConst = GetConstant(idx); if (idxConst != NULL) { - BF_ASSERT(IsInt(idxConst->mTypeCode)); + BF_ASSERT(IsInt(idxConst->mTypeCode)); return CreateExtractValue(val, idxConst->mInt32); } @@ -4973,7 +4965,7 @@ BfIRValue BfIRBuilder::CreateLifetimeStart(BfIRValue val) } BfIRValue BfIRBuilder::CreateLifetimeEnd(BfIRValue val) -{ +{ BfIRValue retVal = WriteCmd(BfIRCmd_LifetimeEnd, val); NEW_CMD_INSERTED; return retVal; @@ -5019,7 +5011,7 @@ void BfIRBuilder::CreateValueScopeHardEnd(BfIRValue scopeStart) } BfIRValue BfIRBuilder::CreateLoad(BfIRValue val, bool isVolatile) -{ +{ BfIRValue retVal = WriteCmd(BfIRCmd_Load, val, isVolatile); NEW_CMD_INSERTED_IRVALUE; return retVal; @@ -5040,7 +5032,7 @@ BfIRValue BfIRBuilder::CreateStore(BfIRValue val, BfIRValue ptr, bool isVolatile } BfIRValue BfIRBuilder::CreateAlignedStore(BfIRValue val, BfIRValue ptr, int align, bool isVolatile) -{ +{ BfIRValue retVal = WriteCmd(BfIRCmd_AlignedStore, val, ptr, align, isVolatile); NEW_CMD_INSERTED_IRVALUE; return retVal; @@ -5076,7 +5068,7 @@ BfIRValue BfIRBuilder::CreateStackRestore(BfIRValue stackVal) void BfIRBuilder::CreateGlobalVariable(BfIRValue irValue) { auto globalVar = (BfGlobalVar*)GetConstant(irValue); - + if ((!mIgnoreWrites) && (globalVar->mStreamId == -1)) { if (globalVar->mInitializer) @@ -5085,7 +5077,7 @@ void BfIRBuilder::CreateGlobalVariable(BfIRValue irValue) BfIRValue retVal = WriteCmd(BfIRCmd_GlobalVariable, globalVar->mType, globalVar->mIsConst, (uint8)globalVar->mLinkageType, String(globalVar->mName), globalVar->mIsTLS, globalVar->mInitializer); globalVar->mStreamId = retVal.mId; - NEW_CMD_INSERTED_IRVALUE; + NEW_CMD_INSERTED_IRVALUE; } } @@ -5117,14 +5109,14 @@ BfIRValue BfIRConstHolder::CreateGlobalVariableConstant(BfIRType varType, bool i BfIRValue BfIRBuilder::CreateGlobalVariable(BfIRType varType, bool isConstant, BfIRLinkageType linkageType, BfIRValue initializer, const StringImpl& name, bool isTLS) { - auto irValue = CreateGlobalVariableConstant(varType, isConstant, linkageType, initializer, name, isTLS); + auto irValue = CreateGlobalVariableConstant(varType, isConstant, linkageType, initializer, name, isTLS); CreateGlobalVariable(irValue); return irValue; } void BfIRBuilder::GlobalVar_SetUnnamedAddr(BfIRValue val, bool unnamedAddr) { - BfIRValue retVal = WriteCmd(BfIRCmd_GlobalVar_SetUnnamedAddr, val, unnamedAddr); + BfIRValue retVal = WriteCmd(BfIRCmd_GlobalVar_SetUnnamedAddr, val, unnamedAddr); NEW_CMD_INSERTED; } @@ -5157,7 +5149,7 @@ BfIRValue BfIRBuilder::CreateGlobalStringPtr(const StringImpl& str) void BfIRBuilder::SetReflectTypeData(BfIRType type, BfIRValue globalVar) { BfIRValue retVal = WriteCmd(BfIRCmd_SetReflectTypeData, type, globalVar); - NEW_CMD_INSERTED_IRVALUE; + NEW_CMD_INSERTED_IRVALUE; } BfIRBlock BfIRBuilder::CreateBlock(const StringImpl& name, bool addNow) @@ -5165,7 +5157,7 @@ BfIRBlock BfIRBuilder::CreateBlock(const StringImpl& name, bool addNow) if (addNow) mActiveFunctionHasBody = true; mBlockCount++; - BfIRBlock retBlock = WriteCmd(BfIRCmd_CreateBlock, name, addNow); + BfIRBlock retBlock = WriteCmd(BfIRCmd_CreateBlock, name, addNow); NEW_CMD_INSERTED_IRBLOCK; return retBlock; } @@ -5204,12 +5196,12 @@ void BfIRBuilder::MergeBlockDown(BfIRBlock fromBlock, BfIRBlock intoBlock) void BfIRBuilder::SetInsertPoint(BfIRValue value) { - BfIRValue retVal = WriteCmd(BfIRCmd_SetInsertPoint, value); + BfIRValue retVal = WriteCmd(BfIRCmd_SetInsertPoint, value); NEW_CMD_INSERTED; } void BfIRBuilder::SetInsertPoint(BfIRBlock block) -{ +{ BfIRValue retVal = WriteCmd(BfIRCmd_SetInsertPoint, block); if (!mIgnoreWrites) { @@ -5278,7 +5270,7 @@ void BfIRBuilder::CreateCondBr(BfIRValue val, BfIRBlock trueBlock, BfIRBlock fal } BfIRBlock BfIRBuilder::GetInsertBlock() -{ +{ if (!mIgnoreWrites) { BF_ASSERT(!mActualInsertBlock.IsFake()); @@ -5343,7 +5335,7 @@ BfIRFunctionType BfIRBuilder::MapMethod(BfMethodInstance* methodInstance) bool useCache = (!mModule->mIsSpecialModule) && (methodInstance->mMethodDef->mIdx >= 0); if (useCache) - { + { BfIRFunctionType* funcType = NULL; if (mMethodTypeMap.TryGetValue(methodInstance, &funcType)) return *funcType; @@ -5362,23 +5354,23 @@ BfIRFunctionType BfIRBuilder::MapMethod(BfMethodInstance* methodInstance) BfIRFunctionType BfIRBuilder::CreateFunctionType(BfIRType resultType, const BfSizedArray& paramTypes, bool isVarArg) { - BfIRFunctionType retType = WriteCmd(BfIRCmd_CreateFunctionType, resultType, paramTypes, isVarArg); + BfIRFunctionType retType = WriteCmd(BfIRCmd_CreateFunctionType, resultType, paramTypes, isVarArg); NEW_CMD_INSERTED_IRFUNCTYPE; return retType; } BfIRFunction BfIRBuilder::CreateFunction(BfIRFunctionType funcType, BfIRLinkageType linkageType, const StringImpl& name) -{ +{ if (mIgnoreWrites) { - auto fakeVal = GetFakeVal(); + auto fakeVal = GetFakeVal(); return fakeVal; } BF_ASSERT(mModule->mIsModuleMutable); - BfIRFunction retVal = WriteCmd(BfIRCmd_CreateFunction, funcType, (uint8)linkageType, name); - NEW_CMD_INSERTED_IRVALUE; + BfIRFunction retVal = WriteCmd(BfIRCmd_CreateFunction, funcType, (uint8)linkageType, name); + NEW_CMD_INSERTED_IRVALUE; StringView nameSV = StringView(AllocStr(name), name.mLength); mFunctionMap[nameSV] = retVal; @@ -5391,7 +5383,7 @@ BfIRFunction BfIRBuilder::CreateFunction(BfIRFunctionType funcType, BfIRLinkageT void BfIRBuilder::SetFunctionName(BfIRValue func, const StringImpl& name) { WriteCmd(BfIRCmd_SetFunctionName, func, name); - NEW_CMD_INSERTED_IRVALUE; + NEW_CMD_INSERTED_IRVALUE; } void BfIRBuilder::EnsureFunctionPatchable() @@ -5408,7 +5400,7 @@ BfIRValue BfIRBuilder::RemapBindFunction(BfIRValue func) } void BfIRBuilder::SetActiveFunction(BfIRFunction func) -{ +{ //BfLogSys(mModule->mSystem, "BfIRBuilder::SetActiveFunction: %d\n", func.mId); if (mActiveFunctionHasBody) @@ -5416,17 +5408,17 @@ void BfIRBuilder::SetActiveFunction(BfIRFunction func) WriteCmd(BfIRCmd_SetActiveFunction, func); mActiveFunction = func; - mActiveFunctionHasBody = false; + mActiveFunctionHasBody = false; NEW_CMD_INSERTED; } BfIRFunction BfIRBuilder::GetActiveFunction() -{ +{ return mActiveFunction; } BfIRFunction BfIRBuilder::GetFunction(const StringImpl& name) -{ +{ BfIRFunction* funcPtr = NULL; if (mFunctionMap.TryGetValue(name, &funcPtr)) return *funcPtr; @@ -5496,7 +5488,7 @@ void BfIRBuilder::CreateUnreachable() void BfIRBuilder::Call_AddAttribute(BfIRValue callInst, int argIdx, BfIRAttribute attr) { - WriteCmd(BfIRCmd_Call_AddAttribute, callInst, argIdx, attr); + WriteCmd(BfIRCmd_Call_AddAttribute, callInst, argIdx, attr); NEW_CMD_INSERTED; } @@ -5534,7 +5526,7 @@ void BfIRBuilder::Func_DeleteBody(BfIRFunction func) } void BfIRBuilder::Func_SafeRename(BfIRFunction func) -{ +{ WriteCmd(BfIRCmd_Func_SafeRename, func); // We don't actually remove it from the named map. It doesn't matter for us. @@ -5601,7 +5593,7 @@ BfIRValue BfIRBuilder::Comptime_GetInterfaceFunc(BfIRValue value, int typeId, in } void BfIRBuilder::SaveDebugLocation() -{ +{ if (!mIgnoreWrites) { mSavedDebugLocs.push_back(mModule->mCurFilePosition); @@ -5611,7 +5603,7 @@ void BfIRBuilder::SaveDebugLocation() } void BfIRBuilder::RestoreDebugLocation() -{ +{ if (!mIgnoreWrites) { mModule->mCurFilePosition = mSavedDebugLocs.back(); @@ -5624,12 +5616,12 @@ void BfIRBuilder::RestoreDebugLocation() void BfIRBuilder::DupDebugLocation() { - WriteCmd(BfIRCmd_DupDebugLocation); + WriteCmd(BfIRCmd_DupDebugLocation); NEW_CMD_INSERTED; } bool BfIRBuilder::HasDebugLocation() -{ +{ return mHasDebugLoc; } @@ -5690,7 +5682,7 @@ void BfIRBuilder::CreateStatementStart() void BfIRBuilder::CreateObjectAccessCheck(BfIRValue value, bool useAsm) { - auto retBlock = WriteCmd(BfIRCmd_ObjectAccessCheck, value, useAsm); + auto retBlock = WriteCmd(BfIRCmd_ObjectAccessCheck, value, useAsm); NEW_CMD_INSERTED_IRBLOCK; if (!mIgnoreWrites) { @@ -5704,14 +5696,14 @@ void BfIRBuilder::DbgInit() { mHasDebugInfo = true; mHasDebugLineInfo = true; - WriteCmd(BfIRCmd_DbgInit); + WriteCmd(BfIRCmd_DbgInit); NEW_CMD_INSERTED; } void BfIRBuilder::DbgFinalize() -{ +{ while ((!mDeferredDbgTypeDefs.IsEmpty()) || (!mDITemporaryTypes.IsEmpty())) - { + { //for (auto deferredType : mDeferredDbgTypeDefs) for (int i = 0; i < (int)mDeferredDbgTypeDefs.size(); i++) CreateDbgTypeDefinition(mDeferredDbgTypeDefs[i]); @@ -5726,7 +5718,7 @@ void BfIRBuilder::DbgFinalize() bool BfIRBuilder::DbgHasInfo() { - return mHasDebugInfo; + return mHasDebugInfo; } bool BfIRBuilder::DbgHasLineInfo() @@ -5741,7 +5733,7 @@ String BfIRBuilder::DbgGetStaticFieldName(BfFieldInstance* fieldInstance) auto typeInstance = fieldInstance->mOwner; auto typeDef = typeInstance->mTypeDef; if (mModule->mCompiler->mOptions.IsCodeView()) - { + { fieldName += "_bf"; for (int partIdx = 0; partIdx < typeInstance->mTypeDef->mNamespace.GetPartsCount(); partIdx++) { @@ -5777,12 +5769,12 @@ BfIRMDNode BfIRBuilder::DbgCreateCompileUnit(int lang, const StringImpl& fileNam } BfIRMDNode BfIRBuilder::DbgCreateFile(const StringImpl& fileName, const StringImpl& directory, const Val128& md5Hash) -{ +{ BfIRMDNode retVal = WriteCmd(BfIRCmd_DbgCreateFile, fileName, directory, md5Hash); NEW_CMD_INSERTED_IRMD; if (mDbgVerifyCodeGen && gDebugDbgLoc) - { + { OutputDebugStrF("DbgCreateFile %s %d\n", fileName.c_str(), retVal.mId); } @@ -5838,7 +5830,7 @@ BfIRMDNode BfIRBuilder::DbgGetTypeInst(BfTypeInstance* typeInst, BfIRPopulateTyp void BfIRBuilder::DbgTrackDITypes(BfType* type) { BfIRMDNode retVal = WriteCmd(BfIRCmd_DbgTrackDITypes, type->mTypeId); - NEW_CMD_INSERTED; + NEW_CMD_INSERTED; } BfIRMDNode BfIRBuilder::DbgCreateNameSpace(BfIRMDNode scope, const StringImpl& name, BfIRMDNode file, int lineNum) @@ -5863,7 +5855,7 @@ BfIRMDNode BfIRBuilder::DbgCreateBasicType(const StringImpl& name, int64 sizeInB } BfIRMDNode BfIRBuilder::DbgCreateStructType(BfIRMDNode context, const StringImpl& name, BfIRMDNode file, int lineNum, int64 sizeInBits, int64 alignInBits, int flags, BfIRMDNode derivedFrom, const BfSizedArray& elements) -{ +{ BfIRMDNode retVal = WriteCmd(BfIRCmd_DbgCreateStructType, context, name, file, lineNum, (int32)sizeInBits, (int32)alignInBits, flags, derivedFrom, elements); NEW_CMD_INSERTED_IRMD; return retVal; @@ -5912,7 +5904,7 @@ BfIRMDNode BfIRBuilder::DbgCreateArrayType(int64 sizeInBits, int64 alignInBits, } BfIRMDNode BfIRBuilder::DbgCreateReplaceableCompositeType(int tag, const StringImpl& name, BfIRMDNode scope, BfIRMDNode file, int line, int64 sizeInBits, int64 alignInBits, int flags) -{ +{ BfIRMDNode retVal = WriteCmd(BfIRCmd_DbgCreateReplaceableCompositeType, tag, name, scope, file, line, (int32)sizeInBits, (int32)alignInBits, flags); NEW_CMD_INSERTED_IRMD; return retVal; @@ -5987,12 +5979,12 @@ BfIRMDNode BfIRBuilder::DbgCreateInheritance(BfIRMDNode type, BfIRMDNode baseTyp return retVal; } -BfIRMDNode BfIRBuilder::DbgCreateMethod(BfIRMDNode context, const StringImpl& name, const StringImpl& linkageName, BfIRMDNode file, int lineNum, BfIRMDNode type, bool isLocalToUnit, bool isDefinition, int vk, int vIndex, BfIRMDNode vTableHolder, int flags, +BfIRMDNode BfIRBuilder::DbgCreateMethod(BfIRMDNode context, const StringImpl& name, const StringImpl& linkageName, BfIRMDNode file, int lineNum, BfIRMDNode type, bool isLocalToUnit, bool isDefinition, int vk, int vIndex, BfIRMDNode vTableHolder, int flags, bool isOptimized, BfIRValue fn, const BfSizedArray& genericArgs, const BfSizedArray& genericConstValueArgs) { BfIRMDNode retVal = WriteCmd(BfIRCmd_DbgCreateMethod, context, name, linkageName, file, lineNum, type, isLocalToUnit, isDefinition, vk, vIndex, vTableHolder, flags, isOptimized, fn, genericArgs, genericConstValueArgs); NEW_CMD_INSERTED_IRMD; - + // if (mDbgVerifyCodeGen && gDebugDbgLoc) // { // OutputDebugStrF("DbgCreateFunction Context:%d name:%s = %d\n", context.mId, name.c_str(), retVal.mId); @@ -6002,14 +5994,14 @@ BfIRMDNode BfIRBuilder::DbgCreateMethod(BfIRMDNode context, const StringImpl& na } BfIRMDNode BfIRBuilder::DbgCreateFunction(BfIRMDNode context, const StringImpl& name, const StringImpl& linkageName, BfIRMDNode file, int lineNum, BfIRMDNode type, bool isLocalToUnit, bool isDefinition, int scopeLine, int flags, bool isOptimized, BfIRValue fn) -{ +{ BfIRMDNode retVal = WriteCmd(BfIRCmd_DbgCreateFunction, context, name, linkageName, file, lineNum, type, isLocalToUnit, isDefinition, scopeLine, flags, isOptimized, fn); NEW_CMD_INSERTED_IRMD; // if (mDbgVerifyCodeGen && gDebugDbgLoc) // { // OutputDebugStrF("DbgCreateFunction Context:%d name:%s = %d\n", context.mId, name.c_str(), retVal.mId); -// } +// } return retVal; } @@ -6096,8 +6088,8 @@ BfIRValue BfIRBuilder::DbgLifetimeEnd(BfIRMDNode varInfo) } void BfIRBuilder::DbgCreateGlobalVariable(BfIRMDNode context, const StringImpl& name, const StringImpl& linkageName, BfIRMDNode file, int lineNumber, BfIRMDNode type, bool isLocalToUnit, BfIRValue val, BfIRMDNode decl) -{ - WriteCmd(BfIRCmd_DbgCreateGlobalVariable, context, name, linkageName, file, lineNumber, type, isLocalToUnit, val, decl); +{ + WriteCmd(BfIRCmd_DbgCreateGlobalVariable, context, name, linkageName, file, lineNumber, type, isLocalToUnit, val, decl); NEW_CMD_INSERTED; } @@ -6138,4 +6130,4 @@ void BfIRBuilder::SetState(const BfIRState& state) mActiveFunction = state.mActiveFunction; mActiveFunctionHasBody = state.mActiveFunctionHasBody; mSavedDebugLocs = state.mSavedDebugLocs; -} +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfIRBuilder.h b/IDEHelper/Compiler/BfIRBuilder.h index b634b692..2374ea81 100644 --- a/IDEHelper/Compiler/BfIRBuilder.h +++ b/IDEHelper/Compiler/BfIRBuilder.h @@ -60,16 +60,16 @@ public: mCurSrcPos = 0; mCurLine = 0; mCurColumn = 0; - } + } }; enum BfTypeCode : uint8 -{ +{ BfTypeCode_None, BfTypeCode_CharPtr, BfTypeCode_StringId, BfTypeCode_Pointer, - BfTypeCode_NullPtr, + BfTypeCode_NullPtr, BfTypeCode_Self, BfTypeCode_Dot, BfTypeCode_Var, @@ -123,7 +123,7 @@ enum BfTypeCode : uint8 enum BfConstType { - BfConstType_GlobalVar = BfTypeCode_Length, + BfConstType_GlobalVar = BfTypeCode_Length, BfConstType_BitCast, BfConstType_BitCastNull, BfConstType_GEP32_1, @@ -145,13 +145,13 @@ enum BfConstType enum BfIRValueFlags : uint8 { - BfIRValueFlags_None, + BfIRValueFlags_None, BfIRValueFlags_Value = 1, BfIRValueFlags_Arg = 2, BfIRValueFlags_Const = 4, BfIRValueFlags_FromLLVM = 8, BfIRValueFlags_Block = 16, - BfIRValueFlags_Func = 32 + BfIRValueFlags_Func = 32 }; enum BfIRCmd : uint8 @@ -162,7 +162,7 @@ enum BfIRCmd : uint8 BfIRCmd_WriteIR, BfIRCmd_SetType, - BfIRCmd_SetInstType, + BfIRCmd_SetInstType, BfIRCmd_PrimitiveType, BfIRCmd_CreateAnonymousStruct, BfIRCmd_CreateStruct, @@ -175,7 +175,7 @@ enum BfIRCmd : uint8 BfIRCmd_GetPointerToType, BfIRCmd_GetSizedArrayType, BfIRCmd_GetVectorType, - + BfIRCmd_CreateConstStructZero, BfIRCmd_CreateConstAgg, BfIRCmd_CreateConstArrayZero, @@ -228,10 +228,10 @@ enum BfIRCmd : uint8 BfIRCmd_SetAllocaNoChkStkHint, BfIRCmd_SetAllocaForceMem, BfIRCmd_AliasValue, - BfIRCmd_LifetimeStart, + BfIRCmd_LifetimeStart, BfIRCmd_LifetimeEnd, BfIRCmd_LifetimeSoftEnd, - BfIRCmd_LifetimeExtend, + BfIRCmd_LifetimeExtend, BfIRCmd_ValueScopeStart, BfIRCmd_ValueScopeRetain, BfIRCmd_ValueScopeSoftEnd, @@ -255,9 +255,9 @@ enum BfIRCmd : uint8 BfIRCmd_CreateBlock, BfIRCmd_MaybeChainNewBlock, - BfIRCmd_AddBlock, + BfIRCmd_AddBlock, BfIRCmd_DropBlocks, - BfIRCmd_MergeBlockDown, + BfIRCmd_MergeBlockDown, BfIRCmd_GetInsertBlock, BfIRCmd_SetInsertPoint, BfIRCmd_SetInsertPointAtStart, @@ -276,9 +276,9 @@ enum BfIRCmd : uint8 BfIRCmd_CreatePhi, BfIRCmd_AddPhiIncoming, - BfIRCmd_GetIntrinsic, - BfIRCmd_CreateFunctionType, - BfIRCmd_CreateFunction, + BfIRCmd_GetIntrinsic, + BfIRCmd_CreateFunctionType, + BfIRCmd_CreateFunction, BfIRCmd_SetFunctionName, BfIRCmd_EnsureFunctionPatchable, BfIRCmd_RemapBindFunction, @@ -293,10 +293,10 @@ enum BfIRCmd : uint8 BfIRCmd_CreateRetVoid, BfIRCmd_CreateUnreachable, BfIRCmd_Call_AddAttribute, - BfIRCmd_Call_AddAttribute1, + BfIRCmd_Call_AddAttribute1, BfIRCmd_Func_AddAttribute, BfIRCmd_Func_AddAttribute1, - BfIRCmd_Func_SetParamName, + BfIRCmd_Func_SetParamName, BfIRCmd_Func_DeleteBody, BfIRCmd_Func_SafeRename, BfIRCmd_Func_SafeRenameFrom, @@ -385,7 +385,7 @@ enum BfIRParamType : uint8 BfIRParamType_Arg, BfIRParamType_StreamId_Abs8, BfIRParamType_StreamId_Rel, - BfIRParamType_StreamId_Back1, + BfIRParamType_StreamId_Back1, BfIRParamType_StreamId_Back_LAST = 0xFF, // Use remaining encoding }; @@ -425,9 +425,9 @@ enum BfIRIntrinsic : uint8 BfIRIntrinsic_AtomicAnd, BfIRIntrinsic_AtomicCmpStore, BfIRIntrinsic_AtomicCmpStore_Weak, - BfIRIntrinsic_AtomicCmpXChg, + BfIRIntrinsic_AtomicCmpXChg, BfIRIntrinsic_AtomicFence, - BfIRIntrinsic_AtomicLoad, + BfIRIntrinsic_AtomicLoad, BfIRIntrinsic_AtomicMax, BfIRIntrinsic_AtomicMin, BfIRIntrinsic_AtomicNAnd, @@ -440,14 +440,14 @@ enum BfIRIntrinsic : uint8 BfIRIntrinsic_AtomicXor, BfIRIntrinsic_BSwap, BfIRIntrinsic_Cast, - BfIRIntrinsic_Cos, + BfIRIntrinsic_Cos, BfIRIntrinsic_DebugTrap, BfIRIntrinsic_Div, BfIRIntrinsic_Eq, BfIRIntrinsic_Floor, - BfIRIntrinsic_Free, + BfIRIntrinsic_Free, BfIRIntrinsic_Gt, - BfIRIntrinsic_GtE, + BfIRIntrinsic_GtE, BfIRIntrinsic_Index, BfIRIntrinsic_Log, BfIRIntrinsic_Log10, @@ -459,7 +459,7 @@ enum BfIRIntrinsic : uint8 BfIRIntrinsic_MemMove, BfIRIntrinsic_MemSet, BfIRIntrinsic_Mod, - BfIRIntrinsic_Mul, + BfIRIntrinsic_Mul, BfIRIntrinsic_Neq, BfIRIntrinsic_Not, BfIRIntrinsic_Or, @@ -472,8 +472,8 @@ enum BfIRIntrinsic : uint8 BfIRIntrinsic_SHR, BfIRIntrinsic_Shuffle, BfIRIntrinsic_Sin, - BfIRIntrinsic_Sqrt, - BfIRIntrinsic_Sub, + BfIRIntrinsic_Sqrt, + BfIRIntrinsic_Sub, BfIRIntrinsic_VAArg, BfIRIntrinsic_VAEnd, BfIRIntrinsic_VAStart, @@ -537,7 +537,7 @@ public: ID_IMPLICIT = -3 }; -public: +public: int mId; BfIRValueFlags mFlags; static BfIRValue sValueless; @@ -548,7 +548,7 @@ public: public: BfIRValue() - { + { mId = -1; mFlags = BfIRValueFlags_None; #ifdef CHECK_CONSTHOLDER @@ -557,7 +557,7 @@ public: } BfIRValue(const BfIRValue& from) - { + { mFlags = from.mFlags; mId = from.mId; #ifdef CHECK_CONSTHOLDER @@ -566,23 +566,23 @@ public: } BfIRValue(BfIRValueFlags flags, int id) - { + { mFlags = flags; - mId = id; + mId = id; } - + operator bool() const - { + { return mFlags != BfIRValueFlags_None; - } - + } + bool IsFake() const; bool IsConst() const; - bool IsArg() const; + bool IsArg() const; bool IsFromLLVM() const; bool operator==(const BfIRValue& rhs) const - { + { if (mFlags != rhs.mFlags) return false; if (mId != rhs.mId) @@ -591,7 +591,7 @@ public: } bool operator!=(const BfIRValue& rhs) const - { + { if (mFlags != rhs.mFlags) return true; if (mId != rhs.mId) @@ -608,7 +608,7 @@ struct BfIRTypeData TypeKind_TypeId, TypeKind_TypeCode, TypeKind_TypeInstId, - TypeKind_TypeInstPtrId, + TypeKind_TypeInstPtrId, TypeKind_Stream, TypeKind_SizedArray }; @@ -624,12 +624,12 @@ struct BfIRTypeData struct BfIRType : public BfIRTypeData { -public: +public: BfIRType() { mKind = TypeKind_None; mId = -1; - } + } BfIRType(BfIRTypeData typeData) { @@ -637,17 +637,17 @@ public: mId = typeData.mId; } - BfIRType(const BfIRValue& val) { mKind = TypeKind_Stream; mId = val.mId; } + BfIRType(const BfIRValue& val) { mKind = TypeKind_Stream; mId = val.mId; } }; struct BfIRBlock : public BfIRValue { -public: +public: BfIRBlock(); - BfIRBlock(const BfIRValue& fromVal) : BfIRValue(fromVal) {} + BfIRBlock(const BfIRValue& fromVal) : BfIRValue(fromVal) {} }; -enum BfIRAttribute +enum BfIRAttribute { BfIRAttribute_NoReturn, BfIRAttribute_NoAlias, @@ -670,83 +670,83 @@ enum BfIRAttribute struct BfIRFunctionType { -public: - int mId; +public: + int mId; -public: +public: BfIRFunctionType(); - BfIRFunctionType(const BfIRValue& val) { mId = val.mId; } + BfIRFunctionType(const BfIRValue& val) { mId = val.mId; } operator bool() const { return mId != -1; - } + } }; struct BfIRFunction : public BfIRRawValue { -public: +public: BfIRFunction(); BfIRFunction(const BfIRValue& val) { BF_ASSERT((val.mFlags == BfIRValueFlags_None) || (val.mFlags == BfIRValueFlags_Value)); mId = val.mId; - } + } //: BfIRValue(val) {} - + bool operator==(const BfIRFunction& rhs) const - { + { if (mId != rhs.mId) return false; return true; } bool operator!=(const BfIRFunction& rhs) const - { + { if (mId == rhs.mId) return false; return true; } operator bool() const - { + { return mId != -1; } operator BfIRValue() const - { + { return BfIRValue((mId == -1) ? BfIRValueFlags_None : BfIRValueFlags_Value, mId); } }; struct BfIRMDNode { -public: +public: int mId; BfIRMDNode() - { + { mId = -1; } BfIRMDNode(const BfIRValue& val) - { + { mId = val.mId; } - + operator bool() const - { + { return mId != -1; - } + } bool operator==(const BfIRMDNode& rhs) const - { + { if (mId != rhs.mId) return false; return true; } bool operator!=(const BfIRMDNode& rhs) const - { + { if (mId == rhs.mId) return false; return true; @@ -763,7 +763,7 @@ public: public: BfFileInstance() { - mParser = NULL; + mParser = NULL; } }; @@ -776,7 +776,7 @@ struct BfGlobalVar BfIRLinkageType mLinkageType; int mStreamId; BfIRValue mInitializer; - bool mIsTLS; + bool mIsTLS; int mAlignment; }; @@ -789,7 +789,7 @@ struct BfGlobalVar_TypeInst BfIRLinkageType mLinkageType; int mStreamId; BfIRValue mInitializer; - bool mIsTLS; + bool mIsTLS; }; struct BfTypeOf_Const @@ -813,7 +813,7 @@ public: { BfTypeCode mTypeCode; BfConstType mConstType; - }; + }; union { bool mBool; @@ -886,7 +886,7 @@ struct BfConstantGEP32_1 { BfConstType mConstType; int mTarget; - int mIdx0; + int mIdx0; }; struct BfConstantGEP32_2 @@ -901,7 +901,7 @@ struct BfConstantExtractValue { BfConstType mConstType; int mTarget; - int mIdx0; + int mIdx0; }; struct BfConstantAgg @@ -931,15 +931,15 @@ public: BumpAllocatorT<256> mTempAlloc; BfModule* mModule; Dictionary mGlobalVarMap; - + public: void FixTypeCode(BfTypeCode& typeCode); int GetSize(BfTypeCode typeCode); static int GetSize(BfTypeCode typeCode, int ptrSize); - static bool IsInt(BfTypeCode typeCode); + static bool IsInt(BfTypeCode typeCode); static bool IsChar(BfTypeCode typeCode); static bool IsIntable(BfTypeCode typeCode); - static bool IsSigned(BfTypeCode typeCode); + static bool IsSigned(BfTypeCode typeCode); static bool IsFloat(BfTypeCode typeCode); const char* AllocStr(const StringImpl& str); @@ -951,7 +951,7 @@ public: String ToString(BfIRType irType); void pv(const BfIRValue& irValue); - BfConstant* GetConstantById(int id); + BfConstant* GetConstantById(int id); BfConstant* GetConstant(BfIRValue id); bool TryGetBool(BfIRValue id, bool& boolVal); int IsZero(BfIRValue val); @@ -961,7 +961,7 @@ public: BfIRType GetSizedArrayType(BfIRType elementType, int length); - BfIRValue CreateConst(BfTypeCode typeCode, uint64 val); + BfIRValue CreateConst(BfTypeCode typeCode, uint64 val); BfIRValue CreateConst(BfTypeCode typeCode, int val); BfIRValue CreateConst(BfTypeCode typeCode, double val); BfIRValue CreateConst(BfConstant* fromConst, BfIRConstHolder* fromHolder); @@ -976,11 +976,11 @@ public: BfIRValue CreateConstBox(BfIRValue val, BfIRType type); BfIRValue CreateTypeOf(BfType* type); BfIRValue CreateTypeOf(BfType* type, BfIRValue typeData); - BfIRValue GetUndefConstValue(BfIRType type); + BfIRValue GetUndefConstValue(BfIRType type); BfIRValue CreateGlobalVariableConstant(BfIRType varType, bool isConstant, BfIRLinkageType linkageType, BfIRValue initializer, const StringImpl& name, bool isTLS = false); bool WriteConstant(BfIRValue val, void* ptr, BfType* type); - BfIRValue ReadConstant(void* ptr, BfType* type); + BfIRValue ReadConstant(void* ptr, BfType* type); }; enum BfIRPopulateType @@ -1011,16 +1011,16 @@ enum BfOverflowCheckKind : int8 class BfIRBuilder : public BfIRConstHolder { -public: +public: bool mIgnoreWrites; bool mDbgVerifyCodeGen; int mCurFakeId; bool mHasGlobalDefs; bool mIsBeefBackend; - int mNumFunctionsWithBodies; + int mNumFunctionsWithBodies; int mBlockCount; - bool mHasStarted; - int mCmdCount; + bool mHasStarted; + int mCmdCount; ChunkedDataBuffer mStream; BfIRBlock mActualInsertBlock; // Only when not ignoring writes @@ -1032,12 +1032,12 @@ public: Dictionary mFunctionMap; Dictionary mTypeMap; Dictionary mConstMemMap; - Array mDITemporaryTypes; + Array mDITemporaryTypes; BfIRFunction mActiveFunction; bool mActiveFunctionHasBody; Array mSavedDebugLocs; Array mDeferredDbgTypeDefs; - + BfIRCodeGenBase* mIRCodeGen; BfIRCodeGen* mBfIRCodeGen; BeIRCodeGen* mBeIRCodeGen; @@ -1050,7 +1050,7 @@ public: public: ~BfIRBuilder(); - + void WriteSLEB128(int64 val); void WriteSLEB128(int32 val); void Write(uint8 val); @@ -1061,24 +1061,24 @@ public: void Write(const StringImpl& str); void Write(const BfIRValue& irValue); void Write(BfTypeCode typeCode); - void Write(const BfIRTypeData& type); + void Write(const BfIRTypeData& type); void Write(BfIRFunctionType func); void Write(BfIRFunction funcType); void Write(BfIRBlock block); - void Write(BfIRMDNode node); + void Write(BfIRMDNode node); template void Write(const BfSizedArray& sizedArray) { - WriteSLEB128(sizedArray.mSize); + WriteSLEB128(sizedArray.mSize); for (int i = 0; i < sizedArray.mSize; i++) Write(sizedArray.mVals[i]); - } - BfIRValue WriteCmd(BfIRCmd cmd); + } + BfIRValue WriteCmd(BfIRCmd cmd); template void WriteArg(const T& first) { - Write(first); + Write(first); } template @@ -1090,17 +1090,17 @@ public: template BfIRValue WriteCmd(BfIRCmd cmd, const Args&... args) - { + { if (mIgnoreWrites) return GetFakeVal(); //int dataPos = mStream.GetSize(); - auto result = WriteCmd(cmd); - WriteArg(args...); + auto result = WriteCmd(cmd); + WriteArg(args...); return result; //return BfIRValue(BfIRValueFlags_Value, dataPos); } -public: +public: void NewCmdInserted(); BfIRMDNode CreateNamespaceScope(BfType* type, BfIRMDNode fileDIScope); String GetDebugTypeName(BfTypeInstance* typeInstance, bool includeOuterTypeName); @@ -1114,18 +1114,18 @@ public: BfIRPopulateType GetPopulateTypeState(BfType* type); void PopulateType(BfType* type, BfIRPopulateType populateType = BfIRPopulateType_Full); void SetType(BfType* type, BfIRType irType); - void SetInstType(BfType* type, BfIRType irType); + void SetInstType(BfType* type, BfIRType irType); int GetFakeId(); BfIRValue GetFakeVal(); BfIRValue GetFakeConst(); - BfIRType GetFakeType(); - BfIRType GetFakeBlock(); - BfIRFunctionType GetFakeFunctionType(); - BfIRFunction GetFakeFunction(); + BfIRType GetFakeType(); + BfIRType GetFakeBlock(); + BfIRFunctionType GetFakeFunctionType(); + BfIRFunction GetFakeFunction(); public: void OpFailed(); - + uint8 CheckedAdd(uint8 a, uint8 b); uint16 CheckedAdd(uint16 a, uint16 b); uint32 CheckedAdd(uint32 a, uint32 b); @@ -1169,7 +1169,7 @@ public: int64 CheckedShl(int64 a, int64 b); public: - BfIRBuilder(BfModule* module); + BfIRBuilder(BfModule* module); bool HasExports(); // Contains non-empty functions and/or non-empty globals String ToString(BfIRValue irValue); @@ -1183,9 +1183,9 @@ public: void pt(const BfIRType& irType); void pbft(BfType* type); void pt(const BfIRFunction& irFun); - void pft(const BfIRFunctionType& irType); + void pft(const BfIRFunctionType& irType); void pmd(const BfIRMDNode& irMDNode); - + void GetBufferData(Array& outBuffer); void ClearConstData(); void ClearNonConstData(); @@ -1194,11 +1194,11 @@ public: void SetBackend(bool isBeefBackend); void RemoveIRCodeGen(); void WriteIR(const StringImpl& fileName); - + void Module_SetTargetTriple(const StringImpl& targetTriple, const StringImpl& targetCPU); void Module_AddModuleFlag(const StringImpl& flag, int val); - BfIRType GetPrimitiveType(BfTypeCode typeCode); + BfIRType GetPrimitiveType(BfTypeCode typeCode); BfIRType CreateStructType(const StringImpl& name); BfIRType CreateStructType(const BfSizedArray& memberTypes); void StructSetBody(BfIRType type, const BfSizedArray& memberTypes, int size, int align, bool isPacked); @@ -1210,7 +1210,7 @@ public: BfIRType GetPointerTo(BfIRType type); BfIRType GetSizedArrayType(BfIRType elementType, int length); BfIRType GetVectorType(BfIRType elementType, int length); - + BfIRValue CreateConstAgg_Value(BfIRType type, const BfSizedArray& values); BfIRValue CreateConstString(const StringImpl& string); BfIRValue ConstToMemory(BfIRValue constVal); @@ -1252,13 +1252,13 @@ public: BfIRValue CreateExtractValue(BfIRValue val, int idx); BfIRValue CreateExtractValue(BfIRValue val, BfIRValue idx); BfIRValue CreateInsertValue(BfIRValue agg, BfIRValue val, int idx); - + BfIRValue CreateAlloca(BfIRType type); BfIRValue CreateAlloca(BfIRType type, BfIRValue arraySize); void SetAllocaAlignment(BfIRValue val, int alignment); // When we do a dynamic alloca where we know the memory access patterns will not cause a page fault, we can omit the __chkstk call // Generally, this is when we allocate less than 4k and we know there will be a write on this memory before the next alloca - void SetAllocaNoChkStkHint(BfIRValue val); + void SetAllocaNoChkStkHint(BfIRValue val); void SetAllocaForceMem(BfIRValue val); BfIRValue CreateAliasValue(BfIRValue val); BfIRValue CreateLifetimeStart(BfIRValue val); @@ -1277,8 +1277,8 @@ public: void CreateFence(BfIRFenceType fenceType); BfIRValue CreateStackSave(); BfIRValue CreateStackRestore(BfIRValue stackVal); - - BfIRValue CreateGlobalVariable(BfIRType varType, bool isConstant, BfIRLinkageType linkageType, BfIRValue initializer, const StringImpl& name, bool isTLS = false); + + BfIRValue CreateGlobalVariable(BfIRType varType, bool isConstant, BfIRLinkageType linkageType, BfIRValue initializer, const StringImpl& name, bool isTLS = false); void CreateGlobalVariable(BfIRValue irValue); void GlobalVar_SetUnnamedAddr(BfIRValue val, bool unnamedAddr); void GlobalVar_SetInitializer(BfIRValue globalVar, BfIRValue initVal); @@ -1289,32 +1289,32 @@ public: BfIRBlock CreateBlock(const StringImpl& name, bool addNow = false); BfIRBlock MaybeChainNewBlock(const StringImpl& name); // Creates new block if current block isn't empty - void AddBlock(BfIRBlock block); + void AddBlock(BfIRBlock block); void DropBlocks(BfIRBlock block); - void MergeBlockDown(BfIRBlock fromBlock, BfIRBlock intoBlock); + void MergeBlockDown(BfIRBlock fromBlock, BfIRBlock intoBlock); void SetInsertPoint(BfIRValue value); void SetInsertPoint(BfIRBlock block); void SetInsertPointAtStart(BfIRBlock block); - void EraseFromParent(BfIRBlock block); + void EraseFromParent(BfIRBlock block); void DeleteBlock(BfIRBlock block); void EraseInstFromParent(BfIRValue val); BfIRValue CreateBr(BfIRBlock block); BfIRValue CreateBr_Fake(BfIRBlock block); BfIRValue CreateBr_NoCollapse(BfIRBlock block); void CreateCondBr(BfIRValue val, BfIRBlock trueBlock, BfIRBlock falseBlock); - BfIRBlock GetInsertBlock(); - void MoveBlockToEnd(BfIRBlock block); + BfIRBlock GetInsertBlock(); + void MoveBlockToEnd(BfIRBlock block); BfIRValue CreateSwitch(BfIRValue value, BfIRBlock dest, int numCases); BfIRValue AddSwitchCase(BfIRValue switchVal, BfIRValue caseVal, BfIRBlock caseBlock); void SetSwitchDefaultDest(BfIRValue switchVal, BfIRBlock caseBlock); BfIRValue CreatePhi(BfIRType type, int incomingCount); void AddPhiIncoming(BfIRValue phi, BfIRValue value, BfIRBlock comingFrom); - - BfIRFunction GetIntrinsic(String intrinName, int intrinId, BfIRType returnType, const BfSizedArray& paramTypes); + + BfIRFunction GetIntrinsic(String intrinName, int intrinId, BfIRType returnType, const BfSizedArray& paramTypes); BfIRFunctionType MapMethod(BfMethodInstance* methodInstance); BfIRFunctionType CreateFunctionType(BfIRType resultType, const BfSizedArray& paramTypes, bool isVarArg = false); - BfIRFunction CreateFunction(BfIRFunctionType funcType, BfIRLinkageType linkageType, const StringImpl& name); + BfIRFunction CreateFunction(BfIRFunctionType funcType, BfIRLinkageType linkageType, const StringImpl& name); void SetFunctionName(BfIRValue func, const StringImpl& name); void EnsureFunctionPatchable(); BfIRValue RemapBindFunction(BfIRValue func); @@ -1328,18 +1328,18 @@ public: void SetCallAttribute(BfIRValue callInst, int paramIdx, BfIRAttribute attribute); BfIRValue CreateRet(BfIRValue val); BfIRValue CreateSetRet(BfIRValue val, int returnTypeId); - void CreateRetVoid(); + void CreateRetVoid(); void CreateUnreachable(); void Call_AddAttribute(BfIRValue callInst, int argIdx, BfIRAttribute attr); - void Call_AddAttribute(BfIRValue callInst, int argIdx, BfIRAttribute attr, int arg); + void Call_AddAttribute(BfIRValue callInst, int argIdx, BfIRAttribute attr, int arg); void Func_AddAttribute(BfIRFunction func, int argIdx, BfIRAttribute attr); void Func_AddAttribute(BfIRFunction func, int argIdx, BfIRAttribute attr, int arg); - void Func_SetParamName(BfIRFunction func, int argIdx, const StringImpl& name); + void Func_SetParamName(BfIRFunction func, int argIdx, const StringImpl& name); void Func_DeleteBody(BfIRFunction func); void Func_SafeRename(BfIRFunction func); void Func_SafeRenameFrom(BfIRFunction func, const StringImpl& prevName); void Func_SetLinkage(BfIRFunction func, BfIRLinkageType linkage); - + void Comptime_Error(int errorKind); BfIRValue Comptime_GetBfType(int typeId, BfIRType resultType); BfIRValue Comptime_GetReflectType(int typeId, BfIRType resultType); @@ -1351,7 +1351,7 @@ public: void RestoreDebugLocation(); void DupDebugLocation(); bool HasDebugLocation(); - void ClearDebugLocation(); + void ClearDebugLocation(); void ClearDebugLocation(BfIRValue inst); void ClearDebugLocation_Last(); void UpdateDebugLocation(BfIRValue inst); @@ -1360,29 +1360,29 @@ public: void CreateEnsureInstructionAt(); void CreateStatementStart(); void CreateObjectAccessCheck(BfIRValue value, bool useAsm); - + void DbgInit(); - void DbgFinalize(); + void DbgFinalize(); bool DbgHasInfo(); bool DbgHasLineInfo(); String DbgGetStaticFieldName(BfFieldInstance* fieldInstance); void DbgAddPrefix(String& name); - BfIRMDNode DbgCreateCompileUnit(int lang, const StringImpl& filename, const StringImpl& directory, const StringImpl& producer, bool isOptimized, - const StringImpl& flags, int runtimeVer, bool linesOnly); + BfIRMDNode DbgCreateCompileUnit(int lang, const StringImpl& filename, const StringImpl& directory, const StringImpl& producer, bool isOptimized, + const StringImpl& flags, int runtimeVer, bool linesOnly); BfIRMDNode DbgCreateFile(const StringImpl& fileName, const StringImpl& directory, const Val128& md5Hash); BfIRMDNode DbgGetCurrentLocation(); void DbgSetType(BfType * type, BfIRMDNode diType); - void DbgSetInstType(BfType * type, BfIRMDNode diType); + void DbgSetInstType(BfType * type, BfIRMDNode diType); BfIRMDNode DbgCreateConstValue(int64 val); - BfIRMDNode DbgGetType(BfType* type, BfIRPopulateType populateType = BfIRPopulateType_Declaration); + BfIRMDNode DbgGetType(BfType* type, BfIRPopulateType populateType = BfIRPopulateType_Declaration); BfIRMDNode DbgGetTypeInst(BfTypeInstance* typeInst, BfIRPopulateType populateType = BfIRPopulateType_Declaration); void DbgTrackDITypes(BfType* type); BfIRMDNode DbgCreateNameSpace(BfIRMDNode scope, const StringImpl& name, BfIRMDNode file, int lineNum); BfIRMDNode DbgCreateImportedModule(BfIRMDNode context, BfIRMDNode namespaceNode, int line); BfIRMDNode DbgCreateBasicType(const StringImpl& name, int64 sizeInBits, int64 alignInBits, int encoding); - BfIRMDNode DbgCreateStructType(BfIRMDNode context, const StringImpl& name, BfIRMDNode file, int lineNum, int64 sizeInBits, int64 alignInBits, + BfIRMDNode DbgCreateStructType(BfIRMDNode context, const StringImpl& name, BfIRMDNode file, int lineNum, int64 sizeInBits, int64 alignInBits, int flags, BfIRMDNode derivedFrom, const BfSizedArray& elements); - BfIRMDNode DbgCreateEnumerationType(BfIRMDNode scope, const StringImpl& name, BfIRMDNode file, int lineNumber, int64 SizeInBits, int64 alignInBits, + BfIRMDNode DbgCreateEnumerationType(BfIRMDNode scope, const StringImpl& name, BfIRMDNode file, int lineNumber, int64 SizeInBits, int64 alignInBits, const BfSizedArray& elements, BfIRMDNode underlyingType); BfIRMDNode DbgCreatePointerType(BfIRMDNode diType); BfIRMDNode DbgCreateReferenceType(BfIRMDNode diType); @@ -1397,14 +1397,14 @@ public: void DbgDeleteTemporary(BfIRMDNode diNode); BfIRMDNode DbgMakePermanent(BfIRMDNode diNode, BfIRMDNode diBaseType, const BfSizedArray& elements); BfIRMDNode DbgCreateEnumerator(const StringImpl& name, int64 val); - BfIRMDNode DbgCreateMemberType(BfIRMDNode scope, const StringImpl& name, BfIRMDNode file, int lineNumber, int64 sizeInBits, int64 alignInBits, + BfIRMDNode DbgCreateMemberType(BfIRMDNode scope, const StringImpl& name, BfIRMDNode file, int lineNumber, int64 sizeInBits, int64 alignInBits, int64 offsetInBits, int flags, BfIRMDNode type); BfIRMDNode DbgCreateStaticMemberType(BfIRMDNode scope, const StringImpl& name, BfIRMDNode file, int lineNumber, BfIRMDNode type, int flags, BfIRValue val); BfIRMDNode DbgCreateInheritance(BfIRMDNode type, BfIRMDNode baseType, int64 baseOffset, int flags); BfIRMDNode DbgCreateMethod(BfIRMDNode context, const StringImpl& name, const StringImpl& linkageName, BfIRMDNode file, int lineNum, BfIRMDNode type, - bool isLocalToUnit, bool isDefinition, int vk, int vIndex, BfIRMDNode vTableHolder, int flags, bool isOptimized, BfIRValue fn, + bool isLocalToUnit, bool isDefinition, int vk, int vIndex, BfIRMDNode vTableHolder, int flags, bool isOptimized, BfIRValue fn, const BfSizedArray& genericArgs, const BfSizedArray& genericConstValueArgs); - BfIRMDNode DbgCreateFunction(BfIRMDNode context, const StringImpl& name, const StringImpl& linkageName, BfIRMDNode file, int lineNum, BfIRMDNode type, + BfIRMDNode DbgCreateFunction(BfIRMDNode context, const StringImpl& name, const StringImpl& linkageName, BfIRMDNode file, int lineNum, BfIRMDNode type, bool isLocalToUnit, bool isDefinition, int scopeLine, int flags, bool isOptimized, BfIRValue fn); BfIRMDNode DbgCreateParameterVariable(BfIRMDNode scope, const StringImpl& name, int argNo, BfIRMDNode file, int lineNum, BfIRMDNode type, bool AlwaysPreserve = false, int flags = 0); @@ -1414,14 +1414,13 @@ public: BfIRValue DbgInsertValueIntrinsic(BfIRValue val, BfIRMDNode varInfo); BfIRValue DbgInsertDeclare(BfIRValue val, BfIRMDNode varInfo, BfIRValue declareBefore = BfIRValue()); BfIRValue DbgLifetimeEnd(BfIRMDNode varInfo); - void DbgCreateGlobalVariable(BfIRMDNode context, const StringImpl& name, const StringImpl& linkageName, BfIRMDNode file, int lineNumber, + void DbgCreateGlobalVariable(BfIRMDNode context, const StringImpl& name, const StringImpl& linkageName, BfIRMDNode file, int lineNumber, BfIRMDNode type, bool isLocalToUnit, BfIRValue val, BfIRMDNode Decl = BfIRMDNode()); - BfIRMDNode DbgCreateLexicalBlock(BfIRMDNode scope, BfIRMDNode file, int line, int col); - void DbgCreateAnnotation(BfIRMDNode scope, const StringImpl& name, BfIRValue value); + BfIRMDNode DbgCreateLexicalBlock(BfIRMDNode scope, BfIRMDNode file, int line, int col); + void DbgCreateAnnotation(BfIRMDNode scope, const StringImpl& name, BfIRValue value); BfIRState GetState(); void SetState(const BfIRState& state); }; NS_BF_END - diff --git a/IDEHelper/Compiler/BfIRCodeGen.cpp b/IDEHelper/Compiler/BfIRCodeGen.cpp index a7784802..65fb165b 100644 --- a/IDEHelper/Compiler/BfIRCodeGen.cpp +++ b/IDEHelper/Compiler/BfIRCodeGen.cpp @@ -141,9 +141,9 @@ static const BuiltinEntry gIntrinEntries[] = {"atomic_and"}, {"atomic_cmpstore"}, {"atomic_cmpstore_weak"}, - {"atomic_cmpxchg"}, + {"atomic_cmpxchg"}, {"atomic_fence"}, - {"atomic_load"}, + {"atomic_load"}, {"atomic_max"}, {"atomic_min"}, {"atomic_nand"}, @@ -153,10 +153,10 @@ static const BuiltinEntry gIntrinEntries[] = {"atomic_umax"}, {"atomic_umin"}, {"atomic_xchg"}, - {"atomic_xor"}, + {"atomic_xor"}, {"bswap"}, {"cast"}, - {"cos"}, + {"cos"}, {"debugtrap"}, {"div"}, {"eq"}, @@ -192,7 +192,7 @@ static const BuiltinEntry gIntrinEntries[] = {"sub"}, {"va_arg"}, {"va_end"}, - {"va_start"}, + {"va_start"}, {"xor"}, }; @@ -264,19 +264,19 @@ struct BfTempFile String mContents; String mFilePath; CritSect mCritSect; - FILE* mFP; + FILE* mFP; BfTempFile() { - mFP = NULL; + mFP = NULL; } ~BfTempFile() { if (mFP != NULL) - fclose(mFP); - if (!mFilePath.IsEmpty()) - ::DeleteFileW(UTF8Decode(mFilePath).c_str()); + fclose(mFP); + if (!mFilePath.IsEmpty()) + ::DeleteFileW(UTF8Decode(mFilePath).c_str()); } bool Create() @@ -311,7 +311,7 @@ struct BfTempFile char* str = new char[size]; int readSize = (int)fread(str, 1, size, mFP); mContents.Append(str, readSize); - delete [] str; + delete [] str; fclose(mFP); mFP = NULL; @@ -324,10 +324,10 @@ struct BfTempFile static BfTempFile gTempFile; static void AddStdErrCrashInfo() -{ - String tempContents = gTempFile.GetContents(); - if (!tempContents.IsEmpty()) - BfpSystem_AddCrashInfo(tempContents.c_str()); +{ + String tempContents = gTempFile.GetContents(); + if (!tempContents.IsEmpty()) + BfpSystem_AddCrashInfo(tempContents.c_str()); } #endif @@ -356,13 +356,13 @@ BfIRCodeGen::BfIRCodeGen() mHadDLLExport = false; mConstValIdx = 0; mCmdCount = 0; - + #ifdef BF_PLATFORM_WINDOWS if (::GetStdHandle(STD_ERROR_HANDLE) == 0) { if (gTempFile.Create()) - { - _dup2(fileno(gTempFile.mFP), 2); + { + _dup2(fileno(gTempFile.mFP), 2); BfpSystem_AddCrashInfoFunc(AddStdErrCrashInfo); } } @@ -384,11 +384,11 @@ BfIRCodeGen::~BfIRCodeGen() void BfIRCodeGen::FatalError(const StringImpl &err) { - String failStr = "Fatal Error in Module: "; + String failStr = "Fatal Error in Module: "; failStr += mModuleName; failStr += "\n"; if (mLLVMModule != NULL) - { + { if (mActiveFunction != NULL) { failStr += "Function: "; @@ -396,7 +396,7 @@ void BfIRCodeGen::FatalError(const StringImpl &err) failStr += "\n"; } - auto loc = mIRBuilder->getCurrentDebugLocation(); + auto loc = mIRBuilder->getCurrentDebugLocation(); auto dbgLoc = loc.getAsMDNode(); if (dbgLoc != NULL) { @@ -417,7 +417,7 @@ void BfIRCodeGen::FatalError(const StringImpl &err) failStr += str; failStr += "\n"; } - } + } } failStr += err; @@ -477,7 +477,7 @@ void BfIRCodeGen::FixValues(llvm::StructType* structType, llvm::SmallVectorgetElementType(i)->isArrayTy()) - { + { values[i] = llvm::ConstantAggregateZero::get(structType->getElementType(i)); } else @@ -502,7 +502,7 @@ BfTypeCode BfIRCodeGen::GetTypeCode(llvm::Type* type, bool isSigned) case 1: return BfTypeCode_Boolean; case 8: - return isSigned ? BfTypeCode_Int8 : BfTypeCode_UInt8; + return isSigned ? BfTypeCode_Int8 : BfTypeCode_UInt8; case 16: return isSigned ? BfTypeCode_Int16 : BfTypeCode_UInt16; case 32: @@ -604,7 +604,7 @@ llvm::Type* BfIRCodeGen::GetLLVMType(BfTypeCode typeCode, bool& isSigned) return llvm::Type::getInt64Ty(*mLLVMContext);*/ case BfTypeCode_Float: return llvm::Type::getFloatTy(*mLLVMContext); - case BfTypeCode_Double: + case BfTypeCode_Double: return llvm::Type::getDoubleTy(*mLLVMContext); case BfTypeCode_Float2: return llvm::FixedVectorType::get(llvm::Type::getFloatTy(*mLLVMContext), 2); @@ -664,9 +664,9 @@ void BfIRCodeGen::SetResultAligned(int id, llvm::Value* value) } void BfIRCodeGen::SetResult(int id, llvm::Type* type) -{ +{ BfIRCodeGenEntry entry; - entry.mKind = BfIRCodeGenEntryKind_LLVMType; + entry.mKind = BfIRCodeGenEntryKind_LLVMType; entry.mLLVMType = type; mResults.TryAdd(id, entry); } @@ -692,19 +692,19 @@ void BfIRCodeGen::ProcessBfIRData(const BfSizedArray& buffer) // Diagnostic handlers were unified in LLVM change 5de2d189e6ad, so starting // with LLVM 13 this function is gone. /*struct InlineAsmErrorHook - { + { static void StaticHandler(const llvm::SMDiagnostic& diag, void *context, unsigned locCookie) { if (diag.getKind() == llvm::SourceMgr::DK_Error) { BfIRCodeGen* irCodeGen = (BfIRCodeGen*)context; - + if (!irCodeGen->mErrorMsg.empty()) irCodeGen->mErrorMsg += "\n"; irCodeGen->mErrorMsg += StrFormat("Inline assembly error: \"%s\" : %s", diag.getMessage().data(), diag.getLineContents().data()); } - } - }; + } + }; mLLVMContext->setInlineAsmDiagnosticHandler(InlineAsmErrorHook::StaticHandler, this);*/ BF_ASSERT(mStream == NULL); @@ -712,7 +712,7 @@ void BfIRCodeGen::ProcessBfIRData(const BfSizedArray& buffer) mStream->InitFlatRef(buffer.mVals, buffer.mSize); while (mStream->GetReadPos() < buffer.mSize) - { + { if (mFailed) break; HandleNextCmd(); @@ -731,7 +731,6 @@ int64 BfIRCodeGen::ReadSLEB128() byteVal = mStream->Read(); val |= ((int64)(byteVal & 0x7f)) << shift; shift += 7; - } while (byteVal >= 128); // Sign extend negative numbers. if ((byteVal & 0x40) && (shift < 64)) @@ -740,8 +739,8 @@ int64 BfIRCodeGen::ReadSLEB128() } void BfIRCodeGen::Read(StringImpl& str) -{ - int len = (int)ReadSLEB128(); +{ + int len = (int)ReadSLEB128(); str.Append('?', len); mStream->Read((void*)str.c_str(), len); } @@ -853,7 +852,7 @@ void BfIRCodeGen::Read(llvm::Value*& llvmValue, BfIRCodeGenEntry** codeGenEntry, CMD_PARAM(int, streamId); if (streamId == -1) { - int streamId = mCmdCount++; + int streamId = mCmdCount++; CMD_PARAM(llvm::Type*, varType); CMD_PARAM(bool, isConstant); @@ -935,8 +934,8 @@ void BfIRCodeGen::Read(llvm::Value*& llvmValue, BfIRCodeGenEntry** codeGenEntry, else if (constType == BfConstType_GEP32_1) { CMD_PARAM(llvm::Constant*, target); - CMD_PARAM(int, idx0); - llvm::Value* gepArgs[] = { + CMD_PARAM(int, idx0); + llvm::Value* gepArgs[] = { llvm::ConstantInt::get(llvm::Type::getInt32Ty(*mLLVMContext), idx0)}; llvmValue = FixGEP(target, llvm::ConstantExpr::getInBoundsGetElementPtr(target->getType()->getPointerElementType(), target, gepArgs)); @@ -947,7 +946,7 @@ void BfIRCodeGen::Read(llvm::Value*& llvmValue, BfIRCodeGenEntry** codeGenEntry, CMD_PARAM(llvm::Constant*, target); CMD_PARAM(int, idx0); CMD_PARAM(int, idx1); - llvm::Value* gepArgs[] = { + llvm::Value* gepArgs[] = { llvm::ConstantInt::get(llvm::Type::getInt32Ty(*mLLVMContext), idx0), llvm::ConstantInt::get(llvm::Type::getInt32Ty(*mLLVMContext), idx1)}; @@ -957,7 +956,7 @@ void BfIRCodeGen::Read(llvm::Value*& llvmValue, BfIRCodeGenEntry** codeGenEntry, else if (constType == BfConstType_ExtractValue) { CMD_PARAM(llvm::Constant*, target); - CMD_PARAM(int, idx0); + CMD_PARAM(int, idx0); unsigned int gepArgs[] = { (unsigned int)idx0 }; llvmValue = FixGEP(target, llvm::ConstantExpr::getExtractValue(target, gepArgs)); @@ -985,7 +984,7 @@ void BfIRCodeGen::Read(llvm::Value*& llvmValue, BfIRCodeGenEntry** codeGenEntry, BfIRTypeEntry* typeEntry = NULL; llvm::Type* type = NULL; Read(type, &typeEntry); - if ((sizeAlignKind == BfIRSizeAlignKind_Aligned) && (typeEntry != NULL)) + if ((sizeAlignKind == BfIRSizeAlignKind_Aligned) && (typeEntry != NULL)) llvmValue = llvm::ConstantAggregateZero::get(GetSizeAlignedType(typeEntry)); else llvmValue = llvm::ConstantAggregateZero::get(type); @@ -1002,7 +1001,7 @@ void BfIRCodeGen::Read(llvm::Value*& llvmValue, BfIRCodeGenEntry** codeGenEntry, { BfIRTypeEntry* typeEntry = NULL; llvm::Type* type = NULL; - Read(type, &typeEntry); + Read(type, &typeEntry); CmdParamVec values; Read(values, type->isArrayTy() ? BfIRSizeAlignKind_Aligned : BfIRSizeAlignKind_Original); @@ -1023,7 +1022,7 @@ void BfIRCodeGen::Read(llvm::Value*& llvmValue, BfIRCodeGenEntry** codeGenEntry, { if (values[i]->getType() != structType->getElementType(i)) { - auto valArrayType = llvm::dyn_cast(values[i]->getType()); + auto valArrayType = llvm::dyn_cast(values[i]->getType()); if (valArrayType != NULL) { if (valArrayType->getNumElements() == 0) @@ -1053,7 +1052,7 @@ void BfIRCodeGen::Read(llvm::Value*& llvmValue, BfIRCodeGenEntry** codeGenEntry, llvmValue = NULL; Fail("Bad type"); } - + return; } else if (constType == BfConstType_Undef) @@ -1100,7 +1099,7 @@ void BfIRCodeGen::Read(llvm::Value*& llvmValue, BfIRCodeGenEntry** codeGenEntry, } else if (typeCode == BfTypeCode_None) { - llvmValue = NULL; + llvmValue = NULL; } else if (typeCode == BfTypeCode_NullPtr) { @@ -1111,7 +1110,7 @@ void BfIRCodeGen::Read(llvm::Value*& llvmValue, BfIRCodeGenEntry** codeGenEntry, llvmValue = llvm::ConstantPointerNull::get((llvm::PointerType*)llvmConstType); } else if (BfIRBuilder::IsInt(typeCode)) - { + { int64 intVal = ReadSLEB128(); auto constVal = llvm::ConstantInt::get(llvmConstType, intVal); auto constInt = (llvm::ConstantInt*)constVal; @@ -1141,16 +1140,16 @@ void BfIRCodeGen::Read(llvm::Value*& llvmValue, BfIRCodeGenEntry** codeGenEntry, int cmdId = -1; if (paramType == BfIRParamType_StreamId_Abs8) { - cmdId = mStream->Read(); + cmdId = mStream->Read(); } else if (paramType == BfIRParamType_StreamId_Rel) { - cmdId = mCmdCount - (int)ReadSLEB128(); - } + cmdId = mCmdCount - (int)ReadSLEB128(); + } else { - cmdId = mCmdCount - (paramType - BfIRParamType_StreamId_Back1) - 1; - } + cmdId = mCmdCount - (paramType - BfIRParamType_StreamId_Back1) - 1; + } auto& result = mResults[cmdId]; if (result.mKind != BfIRCodeGenEntryKind_LLVMValue) @@ -1208,7 +1207,7 @@ void BfIRCodeGen::Read(llvm::Function*& llvmFunc) return; } auto& result = mResults[streamId]; - BF_ASSERT(result.mKind == BfIRCodeGenEntryKind_LLVMValue); + BF_ASSERT(result.mKind == BfIRCodeGenEntryKind_LLVMValue); BF_ASSERT(llvm::isa(result.mLLVMValue)); llvmFunc = (llvm::Function*)result.mLLVMValue; } @@ -1309,7 +1308,7 @@ llvm::Value* BfIRCodeGen::TryToVector(llvm::Value* value, llvm::Type* elemType) { auto ptrElemType = ptrType->getElementType(); if (auto arrType = llvm::dyn_cast(ptrElemType)) - { + { auto vecType = llvm::FixedVectorType::get(arrType->getArrayElementType(), (uint)arrType->getArrayNumElements()); auto vecPtrType = vecType->getPointerTo(); @@ -1347,7 +1346,7 @@ llvm::Type* BfIRCodeGen::GetElemType(llvm::Value* value) auto ptrElemType = ptrType->getElementType(); if (auto arrType = llvm::dyn_cast(ptrElemType)) return arrType->getArrayElementType(); - + if (auto vecType = llvm::dyn_cast(ptrElemType)) return vecType->getElementType(); } @@ -1355,7 +1354,6 @@ llvm::Type* BfIRCodeGen::GetElemType(llvm::Value* value) return NULL; } - bool BfIRCodeGen::TryMemCpy(llvm::Value* ptr, llvm::Value* val) { auto valType = val->getType(); @@ -1370,17 +1368,17 @@ bool BfIRCodeGen::TryMemCpy(llvm::Value* ptr, llvm::Value* val) auto int8Ty = llvm::Type::getInt8Ty(*mLLVMContext); auto int32Ty = llvm::Type::getInt32Ty(*mLLVMContext); - auto int8PtrTy = int8Ty->getPointerTo(); + auto int8PtrTy = int8Ty->getPointerTo(); if (auto loadInst = llvm::dyn_cast(val)) - { + { mIRBuilder->CreateMemCpy( mIRBuilder->CreateBitCast(ptr, int8PtrTy), llvm::MaybeAlign(1), mIRBuilder->CreateBitCast(loadInst->getPointerOperand(), int8PtrTy), llvm::MaybeAlign(1), llvm::ConstantInt::get(int32Ty, arrayBytes)); - return true; + return true; } auto constVal = llvm::dyn_cast(val); @@ -1392,7 +1390,7 @@ bool BfIRCodeGen::TryMemCpy(llvm::Value* ptr, llvm::Value* val) mIRBuilder->CreateMemSet( mIRBuilder->CreateBitCast(ptr, int8PtrTy), llvm::ConstantInt::get(int8Ty, 0), - llvm::ConstantInt::get(int32Ty, arrayBytes), + llvm::ConstantInt::get(int32Ty, arrayBytes), llvm::MaybeAlign(1)); return true; } @@ -1403,10 +1401,10 @@ bool BfIRCodeGen::TryMemCpy(llvm::Value* ptr, llvm::Value* val) true, llvm::GlobalValue::InternalLinkage, constVal, - StrFormat("__ConstVal__%d", mConstValIdx++).c_str(), - NULL, + StrFormat("__ConstVal__%d", mConstValIdx++).c_str(), + NULL, llvm::GlobalValue::NotThreadLocal); - + mIRBuilder->CreateMemCpy( mIRBuilder->CreateBitCast(ptr, int8PtrTy), llvm::MaybeAlign(1), @@ -1434,16 +1432,16 @@ bool BfIRCodeGen::TryVectorCpy(llvm::Value* ptr, llvm::Value* val) // auto vecType = llvm::dyn_cast(valType); // if (vecType == NULL) // return false; -// +// // for (int i = 0; i < (int)vecType->getVectorNumElements(); i++) -// { +// { // auto extract = mIRBuilder->CreateExtractElement(val, i); -// +// // llvm::Value* gepArgs[] = { // llvm::ConstantInt::get(llvm::Type::getInt32Ty(*mLLVMContext), 0), // llvm::ConstantInt::get(llvm::Type::getInt32Ty(*mLLVMContext), i) }; // auto gep = mIRBuilder->CreateInBoundsGEP(ptr, llvm::makeArrayRef(gepArgs)); -// +// // mIRBuilder->CreateStore(extract, gep); // } @@ -1451,7 +1449,7 @@ bool BfIRCodeGen::TryVectorCpy(llvm::Value* ptr, llvm::Value* val) } llvm::Type* BfIRCodeGen::GetSizeAlignedType(BfIRTypeEntry* typeEntry) -{ +{ if ((typeEntry->mAlignLLVMType == NULL) && ((typeEntry->mSize & (typeEntry->mAlign - 1)) != 0)) { auto structType = llvm::dyn_cast(typeEntry->mLLVMType); @@ -1492,7 +1490,7 @@ llvm::Value* BfIRCodeGen::GetAlignedPtr(llvm::Value* val) auto alignedType = GetSizeAlignedType(typeEntry); if (alignedType != elemType) { - return mIRBuilder->CreateBitCast(val, alignedType->getPointerTo()); + return mIRBuilder->CreateBitCast(val, alignedType->getPointerTo()); } } } @@ -1517,7 +1515,7 @@ llvm::Value* BfIRCodeGen::FixGEP(llvm::Value* fromValue, llvm::Value* result) } llvm::Value* BfIRCodeGen::DoCheckedIntrinsic(llvm::Intrinsic::ID intrin, llvm::Value* lhs, llvm::Value* rhs, bool useAsm) -{ +{ if ((mTargetTriple.GetMachineType() != BfMachineType_x86) && (mTargetTriple.GetMachineType() != BfMachineType_x64)) useAsm = false; @@ -1687,7 +1685,7 @@ void BfIRCodeGen::InitTarget() { llvm::SMDiagnostic Err; llvm::Triple theTriple = llvm::Triple(mLLVMModule->getTargetTriple()); - llvm::CodeGenOpt::Level optLvl = llvm::CodeGenOpt::None; + llvm::CodeGenOpt::Level optLvl = llvm::CodeGenOpt::None; String cpuName = mTargetCPU; String arch = ""; @@ -1729,7 +1727,7 @@ void BfIRCodeGen::InitTarget() else if (mCodeGenOptions.mSIMDSetting == BfSIMDSetting_AVX) featuresStr = "+avx"; else if (mCodeGenOptions.mSIMDSetting == BfSIMDSetting_AVX2) - featuresStr = "+avx2"; + featuresStr = "+avx2"; llvm::Optional relocModel; llvm::CodeModel::Model cmModel = llvm::CodeModel::Small; @@ -1776,11 +1774,10 @@ void BfIRCodeGen::InitTarget() Options, relocModel, cmModel, optLvl); mLLVMModule->setDataLayout(mLLVMTargetMachine->createDataLayout()); - } void BfIRCodeGen::HandleNextCmd() -{ +{ int curId = mCmdCount; BfIRCmd cmd = (BfIRCmd)mStream->Read(); @@ -1788,8 +1785,8 @@ void BfIRCodeGen::HandleNextCmd() switch (cmd) { - case BfIRCmd_Module_Start: - { + case BfIRCmd_Module_Start: + { CMD_PARAM(String, moduleName); CMD_PARAM(int, ptrSize); CMD_PARAM(bool, isOptimized); @@ -1845,7 +1842,7 @@ void BfIRCodeGen::HandleNextCmd() case BfIRCmd_SetType: { CMD_PARAM(int, typeId); - CMD_PARAM(llvm::Type*, type); + CMD_PARAM(llvm::Type*, type); auto& typeEntry = GetTypeEntry(typeId); typeEntry.mLLVMType = type; if (typeEntry.mInstLLVMType == NULL) @@ -1859,7 +1856,7 @@ void BfIRCodeGen::HandleNextCmd() CMD_PARAM(llvm::Type*, type); GetTypeEntry(typeId).mInstLLVMType = type; } - break; + break; case BfIRCmd_PrimitiveType: { BfTypeCode typeCode = (BfTypeCode)mStream->Read(); @@ -1870,7 +1867,7 @@ void BfIRCodeGen::HandleNextCmd() case BfIRCmd_CreateAnonymousStruct: { CMD_PARAM(CmdParamVec, members); - llvm::StructType* structType = llvm::StructType::get(*mLLVMContext, members); + llvm::StructType* structType = llvm::StructType::get(*mLLVMContext, members); SetResult(curId, structType); } break; @@ -1879,8 +1876,8 @@ void BfIRCodeGen::HandleNextCmd() CMD_PARAM(String, typeName); SetResult(curId, llvm::StructType::create(*mLLVMContext, typeName.c_str())); } - break; - case BfIRCmd_StructSetBody: + break; + case BfIRCmd_StructSetBody: { llvm::Type* type = NULL; BfIRTypeEntry* typeEntry = NULL; @@ -1890,7 +1887,7 @@ void BfIRCodeGen::HandleNextCmd() CMD_PARAM(int, instSize); CMD_PARAM(int, instAlign); CMD_PARAM(bool, isPacked); - + BF_ASSERT(llvm::isa(type)); auto structType = (llvm::StructType*)type; if (structType->isOpaque()) @@ -1920,14 +1917,14 @@ void BfIRCodeGen::HandleNextCmd() CMD_PARAM(BfIRTypeEntry*, typeEntry); SetResult(curId, typeEntry->mInstLLVMType->getPointerTo()); } - break; + break; case BfIRCmd_GetType: { CMD_PARAM(llvm::Value*, value); auto type = value->getType(); SetResult(curId, type); } - break; + break; case BfIRCmd_GetPointerToFuncType: { CMD_PARAM(llvm::FunctionType*, funcType); @@ -1952,19 +1949,19 @@ void BfIRCodeGen::HandleNextCmd() else SetResult(curId, llvm::ArrayType::get(elementType, length)); } - break; + break; case BfIRCmd_GetVectorType: { CMD_PARAM(llvm::Type*, elementType); CMD_PARAM(int, length); SetResult(curId, llvm::FixedVectorType::get(elementType, length)); } - break; + break; case BfIRCmd_CreateConstAgg: { CMD_PARAM(llvm::Type*, type); CMD_PARAM(CmdParamVec, values) - llvm::SmallVector copyValues; + llvm::SmallVector copyValues; if (auto arrayType = llvm::dyn_cast(type)) { @@ -2004,7 +2001,7 @@ void BfIRCodeGen::HandleNextCmd() CMD_PARAM(llvm::Type*, type); SetResult(curId, llvm::ConstantAggregateZero::get(type)); } - break; + break; case BfIRCmd_CreateConstString: { CMD_PARAM(String, str); @@ -2037,18 +2034,18 @@ void BfIRCodeGen::HandleNextCmd() } break; case BfIRCmd_NumericCast: - { + { CMD_PARAM(llvm::Value*, val); CMD_PARAM(bool, valIsSigned); BfTypeCode typeCode = (BfTypeCode)mStream->Read(); - BfTypeCode valTypeCode = GetTypeCode(val->getType(), valIsSigned); + BfTypeCode valTypeCode = GetTypeCode(val->getType(), valIsSigned); bool toSigned; - auto toLLVMType = GetLLVMType(typeCode, toSigned); + auto toLLVMType = GetLLVMType(typeCode, toSigned); llvm::Value* retVal = NULL; if (BfIRBuilder::IsInt(typeCode)) - { + { // Int -> Int if ((BfIRBuilder::IsInt(valTypeCode)) || (valTypeCode == BfTypeCode_Boolean)) { @@ -2066,7 +2063,7 @@ void BfIRCodeGen::HandleNextCmd() { // Int -> Float if ((BfIRBuilder::IsInt(valTypeCode)) || (valTypeCode == BfTypeCode_Boolean)) - { + { if (BfIRBuilder::IsSigned(valTypeCode)) retVal = mIRBuilder->CreateSIToFP(val, toLLVMType); else @@ -2113,7 +2110,7 @@ void BfIRCodeGen::HandleNextCmd() case BfIRCmd_CmpULT: { CMD_PARAM(llvm::Value*, lhs); - CMD_PARAM(llvm::Value*, rhs); + CMD_PARAM(llvm::Value*, rhs); if (lhs->getType()->isFloatingPointTy()) SetResult(curId, mIRBuilder->CreateFCmpOLT(lhs, rhs)); else @@ -2133,7 +2130,7 @@ void BfIRCodeGen::HandleNextCmd() case BfIRCmd_CmpULE: { CMD_PARAM(llvm::Value*, lhs); - CMD_PARAM(llvm::Value*, rhs); + CMD_PARAM(llvm::Value*, rhs); if (lhs->getType()->isFloatingPointTy()) SetResult(curId, mIRBuilder->CreateFCmpOLE(lhs, rhs)); else @@ -2153,7 +2150,7 @@ void BfIRCodeGen::HandleNextCmd() case BfIRCmd_CmpUGT: { CMD_PARAM(llvm::Value*, lhs); - CMD_PARAM(llvm::Value*, rhs); + CMD_PARAM(llvm::Value*, rhs); if (lhs->getType()->isFloatingPointTy()) SetResult(curId, mIRBuilder->CreateFCmpOGT(lhs, rhs)); else @@ -2173,14 +2170,14 @@ void BfIRCodeGen::HandleNextCmd() case BfIRCmd_CmpUGE: { CMD_PARAM(llvm::Value*, lhs); - CMD_PARAM(llvm::Value*, rhs); + CMD_PARAM(llvm::Value*, rhs); if (lhs->getType()->isFloatingPointTy()) SetResult(curId, mIRBuilder->CreateFCmpOGE(lhs, rhs)); else SetResult(curId, mIRBuilder->CreateICmpUGE(lhs, rhs)); } break; - + case BfIRCmd_Add: { CMD_PARAM(llvm::Value*, lhs); @@ -2192,7 +2189,7 @@ void BfIRCodeGen::HandleNextCmd() SetResult(curId, DoCheckedIntrinsic(((overflowCheckKind & BfOverflowCheckKind_Signed) != 0) ? llvm::Intrinsic::sadd_with_overflow : llvm::Intrinsic::uadd_with_overflow, lhs, rhs, (overflowCheckKind & BfOverflowCheckKind_Flag_UseAsm) != 0)); else - SetResult(curId, mIRBuilder->CreateAdd(lhs, rhs)); + SetResult(curId, mIRBuilder->CreateAdd(lhs, rhs)); } break; case BfIRCmd_Sub: @@ -2236,7 +2233,7 @@ void BfIRCodeGen::HandleNextCmd() case BfIRCmd_UDiv: { CMD_PARAM(llvm::Value*, lhs); - CMD_PARAM(llvm::Value*, rhs); + CMD_PARAM(llvm::Value*, rhs); SetResult(curId, mIRBuilder->CreateUDiv(lhs, rhs)); } break; @@ -2253,49 +2250,49 @@ void BfIRCodeGen::HandleNextCmd() case BfIRCmd_URem: { CMD_PARAM(llvm::Value*, lhs); - CMD_PARAM(llvm::Value*, rhs); + CMD_PARAM(llvm::Value*, rhs); SetResult(curId, mIRBuilder->CreateURem(lhs, rhs)); } break; case BfIRCmd_And: { CMD_PARAM(llvm::Value*, lhs); - CMD_PARAM(llvm::Value*, rhs); + CMD_PARAM(llvm::Value*, rhs); SetResult(curId, mIRBuilder->CreateAnd(lhs, rhs)); } break; case BfIRCmd_Or: { CMD_PARAM(llvm::Value*, lhs); - CMD_PARAM(llvm::Value*, rhs); + CMD_PARAM(llvm::Value*, rhs); SetResult(curId, mIRBuilder->CreateOr(lhs, rhs)); } break; case BfIRCmd_Xor: { CMD_PARAM(llvm::Value*, lhs); - CMD_PARAM(llvm::Value*, rhs); + CMD_PARAM(llvm::Value*, rhs); SetResult(curId, mIRBuilder->CreateXor(lhs, rhs)); } break; case BfIRCmd_Shl: { CMD_PARAM(llvm::Value*, lhs); - CMD_PARAM(llvm::Value*, rhs); + CMD_PARAM(llvm::Value*, rhs); SetResult(curId, mIRBuilder->CreateShl(lhs, rhs)); } break; case BfIRCmd_AShr: { CMD_PARAM(llvm::Value*, lhs); - CMD_PARAM(llvm::Value*, rhs); + CMD_PARAM(llvm::Value*, rhs); SetResult(curId, mIRBuilder->CreateAShr(lhs, rhs)); } break; case BfIRCmd_LShr: { CMD_PARAM(llvm::Value*, lhs); - CMD_PARAM(llvm::Value*, rhs); + CMD_PARAM(llvm::Value*, rhs); SetResult(curId, mIRBuilder->CreateLShr(lhs, rhs)); } break; @@ -2303,14 +2300,14 @@ void BfIRCodeGen::HandleNextCmd() { CMD_PARAM(llvm::Value*, val); if (val->getType()->isFloatingPointTy()) - SetResult(curId, mIRBuilder->CreateFNeg(val)); + SetResult(curId, mIRBuilder->CreateFNeg(val)); else SetResult(curId, mIRBuilder->CreateNeg(val)); } break; case BfIRCmd_Not: { - CMD_PARAM(llvm::Value*, val); + CMD_PARAM(llvm::Value*, val); SetResult(curId, mIRBuilder->CreateNot(val)); } break; @@ -2395,7 +2392,7 @@ void BfIRCodeGen::HandleNextCmd() CMD_PARAM(llvm::Value*, idx1); FixIndexer(idx0); FixIndexer(idx1); - llvm::Value* indices[2] = { idx0, idx1 }; + llvm::Value* indices[2] = { idx0, idx1 }; SetResult(curId, FixGEP(val, mIRBuilder->CreateInBoundsGEP(val, llvm::makeArrayRef(indices)))); } break; @@ -2438,10 +2435,10 @@ void BfIRCodeGen::HandleNextCmd() { CMD_PARAM(llvm::Type*, type); if (type->isStructTy()) - { + { BF_ASSERT(!((llvm::StructType*)type)->isOpaque()); } - + SetResult(curId, mIRBuilder->CreateAlloca(type)); } break; @@ -2463,7 +2460,7 @@ void BfIRCodeGen::HandleNextCmd() break; case BfIRCmd_SetAllocaAlignment: { - CMD_PARAM_NOTRANS(llvm::Value*, val); + CMD_PARAM_NOTRANS(llvm::Value*, val); CMD_PARAM(int, alignment); auto inst = llvm::dyn_cast(val); inst->setAlignment(llvm::Align(alignment)); @@ -2499,7 +2496,7 @@ void BfIRCodeGen::HandleNextCmd() break; case BfIRCmd_Load: { - CMD_PARAM(llvm::Value*, val); + CMD_PARAM(llvm::Value*, val); CMD_PARAM(bool, isVolatile); SetResult(curId, mIRBuilder->CreateLoad(val, isVolatile)); } @@ -2517,7 +2514,7 @@ void BfIRCodeGen::HandleNextCmd() CMD_PARAM(llvm::Value*, val); CMD_PARAM(llvm::Value*, ptr); CMD_PARAM(bool, isVolatile); - + if ((!TryMemCpy(ptr, val)) && (!TryVectorCpy(ptr, val))) SetResult(curId, mIRBuilder->CreateStore(val, ptr, isVolatile)); @@ -2562,7 +2559,7 @@ void BfIRCodeGen::HandleNextCmd() { CMD_PARAM(llvm::Value*, stackVal); auto intrin = llvm::Intrinsic::getDeclaration(mLLVMModule, llvm::Intrinsic::stackrestore); - auto callInst = mIRBuilder->CreateCall(intrin, llvm::SmallVector {stackVal }); + auto callInst = mIRBuilder->CreateCall(intrin, llvm::SmallVector {stackVal }); SetResult(curId, callInst); } break; @@ -2570,7 +2567,7 @@ void BfIRCodeGen::HandleNextCmd() { CMD_PARAM(llvm::Type*, varType); CMD_PARAM(bool, isConstant); - BfIRLinkageType linkageType = (BfIRLinkageType)mStream->Read(); + BfIRLinkageType linkageType = (BfIRLinkageType)mStream->Read(); CMD_PARAM(String, name); CMD_PARAM(bool, isTLS); CMD_PARAM(llvm::Constant*, initializer); @@ -2647,9 +2644,9 @@ void BfIRCodeGen::HandleNextCmd() if (!newBlock->empty()) { auto bb = llvm::BasicBlock::Create(*mLLVMContext, name.c_str()); - mIRBuilder->CreateBr(bb); + mIRBuilder->CreateBr(bb); mActiveFunction->getBasicBlockList().push_back(bb); - mIRBuilder->SetInsertPoint(bb); + mIRBuilder->SetInsertPoint(bb); newBlock = bb; } SetResult(curId, newBlock); @@ -2667,7 +2664,7 @@ void BfIRCodeGen::HandleNextCmd() auto& basicBlockList = mActiveFunction->getBasicBlockList(); int postExitBlockIdx = -1; - auto itr = basicBlockList.rbegin(); + auto itr = basicBlockList.rbegin(); int blockIdx = (int)basicBlockList.size() - 1; while (itr != basicBlockList.rend()) { @@ -2677,13 +2674,13 @@ void BfIRCodeGen::HandleNextCmd() { postExitBlockIdx = blockIdx; break; - } + } blockIdx--; } while ((int)basicBlockList.size() > postExitBlockIdx) { - auto& block = basicBlockList.back(); + auto& block = basicBlockList.back(); block.eraseFromParent(); } } @@ -2691,7 +2688,7 @@ void BfIRCodeGen::HandleNextCmd() case BfIRCmd_MergeBlockDown: { CMD_PARAM(llvm::BasicBlock*, fromBlock); - CMD_PARAM(llvm::BasicBlock*, intoBlock); + CMD_PARAM(llvm::BasicBlock*, intoBlock); llvm::BasicBlock::InstListType& fromInstList = fromBlock->getInstList(); llvm::BasicBlock::InstListType& intoInstList = intoBlock->getInstList(); intoInstList.splice(intoInstList.begin(), fromInstList, fromInstList.begin(), fromInstList.end()); @@ -2704,7 +2701,7 @@ void BfIRCodeGen::HandleNextCmd() } break; case BfIRCmd_SetInsertPoint: - { + { CMD_PARAM(llvm::BasicBlock*, block); if (mLockedBlocks.Contains(block)) Fail("Attempt to modify locked block"); @@ -2716,7 +2713,7 @@ void BfIRCodeGen::HandleNextCmd() CMD_PARAM(llvm::BasicBlock*, block); mIRBuilder->SetInsertPoint(block, block->begin()); } - break; + break; case BfIRCmd_EraseFromParent: { CMD_PARAM(llvm::BasicBlock*, block); @@ -2728,7 +2725,7 @@ void BfIRCodeGen::HandleNextCmd() CMD_PARAM(llvm::BasicBlock*, block); delete block; } - break; + break; case BfIRCmd_EraseInstFromParent: { CMD_PARAM(llvm::Value*, instVal); @@ -2783,8 +2780,8 @@ void BfIRCodeGen::HandleNextCmd() break; case BfIRCmd_SetSwitchDefaultDest: { - CMD_PARAM(llvm::Value*, switchVal); - CMD_PARAM(llvm::BasicBlock*, caseBlock); + CMD_PARAM(llvm::Value*, switchVal); + CMD_PARAM(llvm::BasicBlock*, caseBlock); ((llvm::SwitchInst*)switchVal)->setDefaultDest(caseBlock); } break; @@ -2810,9 +2807,9 @@ void BfIRCodeGen::HandleNextCmd() CMD_PARAM(int, intrinId); CMD_PARAM(llvm::Type*, returnType); CMD_PARAM(CmdParamVec, paramTypes); - + llvm::Function* func = NULL; - + struct _Intrinsics { llvm::Intrinsic::ID mID; @@ -2833,7 +2830,7 @@ void BfIRCodeGen::HandleNextCmd() { (llvm::Intrinsic::ID)-2, -1}, // AtomicCmpStore_Weak, { (llvm::Intrinsic::ID)-2, -1}, // AtomicCmpXChg, { (llvm::Intrinsic::ID)-2, -1}, // AtomicFence, - { (llvm::Intrinsic::ID)-2, -1}, // AtomicLoad, + { (llvm::Intrinsic::ID)-2, -1}, // AtomicLoad, { (llvm::Intrinsic::ID)-2, -1}, // AtomicMax, { (llvm::Intrinsic::ID)-2, -1}, // AtomicMin, { (llvm::Intrinsic::ID)-2, -1}, // AtomicNAnd, @@ -2851,7 +2848,7 @@ void BfIRCodeGen::HandleNextCmd() { (llvm::Intrinsic::ID)-2, -1}, // div { (llvm::Intrinsic::ID)-2, -1}, // eq { llvm::Intrinsic::floor, 0, -1}, - { (llvm::Intrinsic::ID)-2, -1}, // free + { (llvm::Intrinsic::ID)-2, -1}, // free { (llvm::Intrinsic::ID)-2, -1}, // gt { (llvm::Intrinsic::ID)-2, -1}, // gte { (llvm::Intrinsic::ID)-2, -1}, // index @@ -2879,7 +2876,7 @@ void BfIRCodeGen::HandleNextCmd() { (llvm::Intrinsic::ID)-2, -1}, // shuffle { llvm::Intrinsic::sin, 0, -1}, { llvm::Intrinsic::sqrt, 0, -1}, - { (llvm::Intrinsic::ID)-2, -1}, // sub, + { (llvm::Intrinsic::ID)-2, -1}, // sub, { (llvm::Intrinsic::ID)-2, -1}, // va_arg, { llvm::Intrinsic::vaend, -1}, // va_end, { llvm::Intrinsic::vastart, -1}, // va_start, @@ -2901,21 +2898,21 @@ void BfIRCodeGen::HandleNextCmd() } } - bool isFakeIntrinsic = (int)intrinsics[intrinId].mID == -2; + bool isFakeIntrinsic = (int)intrinsics[intrinId].mID == -2; if (isFakeIntrinsic) { auto intrinsicData = mIntrinsicData.Alloc(); intrinsicData->mName = intrinName; intrinsicData->mIntrinsic = (BfIRIntrinsic)intrinId; intrinsicData->mReturnType = returnType; - + BfIRCodeGenEntry entry; entry.mKind = BfIRCodeGenEntryKind_IntrinsicData; entry.mIntrinsicData = intrinsicData; mResults.TryAdd(curId, entry); break; - } - + } + if (intrinId == BfIRIntrinsic__PLATFORM) { int colonPos = (int)intrinName.IndexOf(':'); @@ -2947,8 +2944,8 @@ void BfIRCodeGen::HandleNextCmd() BF_ASSERT(intrinsics[intrinId].mID != (llvm::Intrinsic::ID)-1); func = llvm::Intrinsic::getDeclaration(mLLVMModule, intrinsics[intrinId].mID, useParams); } - mIntrinsicReverseMap[func] = intrinId; - + mIntrinsicReverseMap[func] = intrinId; + SetResult(curId, func); } break; @@ -2961,7 +2958,7 @@ void BfIRCodeGen::HandleNextCmd() } break; case BfIRCmd_CreateFunction: - { + { CMD_PARAM(llvm::FunctionType*, type); BfIRLinkageType linkageType = (BfIRLinkageType)mStream->Read(); CMD_PARAM(String, name); @@ -2969,7 +2966,7 @@ void BfIRCodeGen::HandleNextCmd() auto func = mLLVMModule->getFunction(name.c_str()); if ((func == NULL) || (func->getFunctionType() != type)) func = llvm::Function::Create(type, LLVMMapLinkageType(linkageType), name.c_str(), mLLVMModule); - + SetResult(curId, func); } break; @@ -2982,7 +2979,7 @@ void BfIRCodeGen::HandleNextCmd() } break; case BfIRCmd_EnsureFunctionPatchable: - { + { int minPatchSize = 5; int guessInstBytes = 1; // ret @@ -2994,21 +2991,21 @@ void BfIRCodeGen::HandleNextCmd() { for (auto& inst : block) { - if (auto loadInst = llvm::dyn_cast(&inst)) + if (auto loadInst = llvm::dyn_cast(&inst)) guessInstBytes += 2; else if (auto storeInst = llvm::dyn_cast(&inst)) guessInstBytes += 2; else if (auto callInst = llvm::dyn_cast(&inst)) { auto calledValue = callInst->getCalledOperand(); - + if (calledValue == mNopInlineAsm) guessInstBytes += 1; else if (auto func = llvm::dyn_cast(calledValue)) { if (!func->isIntrinsic()) guessInstBytes += 4; - } + } else guessInstBytes += 4; } @@ -3052,12 +3049,12 @@ void BfIRCodeGen::HandleNextCmd() break; case BfIRCmd_SetActiveFunction: { - CMD_PARAM(llvm::Function*, func); + CMD_PARAM(llvm::Function*, func); mActiveFunction = func; } break; case BfIRCmd_CreateCall: - { + { llvm::Value* func = NULL; BfIRCodeGenEntry* codeGenEntry = NULL; Read(func, &codeGenEntry); @@ -3091,11 +3088,11 @@ void BfIRCodeGen::HandleNextCmd() case BfIRIntrinsic_Div: case BfIRIntrinsic_Eq: case BfIRIntrinsic_Gt: - case BfIRIntrinsic_GtE: + case BfIRIntrinsic_GtE: case BfIRIntrinsic_Lt: case BfIRIntrinsic_LtE: case BfIRIntrinsic_Mod: - case BfIRIntrinsic_Mul: + case BfIRIntrinsic_Mul: case BfIRIntrinsic_Neq: case BfIRIntrinsic_Or: case BfIRIntrinsic_Sub: @@ -3103,14 +3100,14 @@ void BfIRCodeGen::HandleNextCmd() { auto val0 = TryToVector(args[0]); if (val0 != NULL) - { + { auto vecType = llvm::dyn_cast(val0->getType()); auto elemType = vecType->getElementType(); bool isFP = elemType->isFloatTy(); - + llvm::Value* val1; if (args.size() < 2) - { + { llvm::Value* val; if (isFP) val = llvm::ConstantFP::get(elemType, 1); @@ -3125,11 +3122,11 @@ void BfIRCodeGen::HandleNextCmd() { auto ptrVal1 = mIRBuilder->CreateBitCast(args[1], vecType->getPointerTo()); val1 = mIRBuilder->CreateAlignedLoad(ptrVal1, llvm::MaybeAlign(1)); - } + } else if (args[1]->getType()->isVectorTy()) - { + { val1 = args[1]; - } + } else { val1 = mIRBuilder->CreateInsertElement(llvm::UndefValue::get(vecType), args[1], (uint64)0); @@ -3196,7 +3193,7 @@ void BfIRCodeGen::HandleNextCmd() SetResult(curId, result); } - } + } else { llvm::Value* result = NULL; @@ -3273,21 +3270,21 @@ void BfIRCodeGen::HandleNextCmd() { auto vecType = llvm::FixedVectorType::get(arrType->getArrayElementType(), (uint)arrType->getArrayNumElements()); auto vecPtrType = vecType->getPointerTo(); - - llvm::Value* val0; + + llvm::Value* val0; val0 = mIRBuilder->CreateInsertElement(llvm::UndefValue::get(vecType), args[0], (uint64)0); val0 = mIRBuilder->CreateInsertElement(val0, args[0], (uint64)1); val0 = mIRBuilder->CreateInsertElement(val0, args[0], (uint64)2); - val0 = mIRBuilder->CreateInsertElement(val0, args[0], (uint64)3); + val0 = mIRBuilder->CreateInsertElement(val0, args[0], (uint64)3); auto ptrVal1 = mIRBuilder->CreateBitCast(args[1], vecPtrType); auto val1 = mIRBuilder->CreateAlignedLoad(ptrVal1, llvm::MaybeAlign(1)); switch (intrinsicData->mIntrinsic) - { + { case BfIRIntrinsic_Div: SetResult(curId, mIRBuilder->CreateFDiv(val0, val1)); - break; + break; case BfIRIntrinsic_Mod: SetResult(curId, mIRBuilder->CreateFRem(val0, val1)); break; @@ -3308,7 +3305,7 @@ void BfIRCodeGen::HandleNextCmd() SetResult(curId, mIRBuilder->CreateNot(val0)); } break; - case BfIRIntrinsic_Shuffle: + case BfIRIntrinsic_Shuffle: { llvm::SmallVector intMask; for (int i = 7; i < (int)intrinsicData->mName.length(); i++) @@ -3317,7 +3314,7 @@ void BfIRCodeGen::HandleNextCmd() auto val0 = TryToVector(args[0]); if (val0 != NULL) - { + { SetResult(curId, mIRBuilder->CreateShuffleVector(val0, val0, intMask)); } else @@ -3327,7 +3324,7 @@ void BfIRCodeGen::HandleNextCmd() } break; case BfIRIntrinsic_Index: - { + { llvm::Value* gepArgs[] = { llvm::ConstantInt::get(llvm::Type::getInt32Ty(*mLLVMContext), 0), args[1] }; @@ -3354,7 +3351,7 @@ void BfIRCodeGen::HandleNextCmd() auto successOrdering = llvm::AtomicOrdering::Unordered; auto failOrdering = llvm::AtomicOrdering::Unordered; switch (memoryKind & BfIRAtomicOrdering_ORDERMASK) - { + { case BfIRAtomicOrdering_Acquire: successOrdering = llvm::AtomicOrdering::Acquire; failOrdering = llvm::AtomicOrdering::Acquire; @@ -3390,14 +3387,14 @@ void BfIRCodeGen::HandleNextCmd() } auto memoryKind = (BfIRAtomicOrdering)memoryKindConst->getSExtValue(); switch (memoryKind & BfIRAtomicOrdering_ORDERMASK) - { - case BfIRAtomicOrdering_Acquire: + { + case BfIRAtomicOrdering_Acquire: failOrdering = llvm::AtomicOrdering::Acquire; - break; - case BfIRAtomicOrdering_Relaxed: + break; + case BfIRAtomicOrdering_Relaxed: failOrdering = llvm::AtomicOrdering::Monotonic; - break; - case BfIRAtomicOrdering_SeqCst: + break; + case BfIRAtomicOrdering_SeqCst: failOrdering = llvm::AtomicOrdering::SequentiallyConsistent; break; default: @@ -3420,7 +3417,7 @@ void BfIRCodeGen::HandleNextCmd() { auto successVal = mIRBuilder->CreateExtractValue(inst, 1); SetResult(curId, successVal); - } + } } break; case BfIRIntrinsic_AtomicFence: @@ -3460,7 +3457,7 @@ void BfIRCodeGen::HandleNextCmd() break; case BfIRAtomicOrdering_AcqRel: ordering = llvm::AtomicOrdering::AcquireRelease; - break; + break; case BfIRAtomicOrdering_Release: ordering = llvm::AtomicOrdering::Release; break; @@ -3482,9 +3479,9 @@ void BfIRCodeGen::HandleNextCmd() { FatalError("Non-constant success ordering on AtomicLoad"); break; - } + } auto memoryKind = (BfIRAtomicOrdering)memoryKindConst->getSExtValue(); - auto ptrType = llvm::dyn_cast(args[0]->getType()); + auto ptrType = llvm::dyn_cast(args[0]->getType()); auto loadInst = mIRBuilder->CreateAlignedLoad(args[0], llvm::MaybeAlign((uint)ptrType->getElementType()->getPrimitiveSizeInBits() / 8)); switch (memoryKind & BfIRAtomicOrdering_ORDERMASK) { @@ -3505,8 +3502,8 @@ void BfIRCodeGen::HandleNextCmd() SetResult(curId, loadInst); } break; - case BfIRIntrinsic_AtomicStore: - { + case BfIRIntrinsic_AtomicStore: + { auto memoryKindConst = llvm::dyn_cast(args[1]); if (memoryKindConst == NULL) { @@ -3533,15 +3530,15 @@ void BfIRCodeGen::HandleNextCmd() SetResult(curId, storeInst); } break; - case BfIRIntrinsic_AtomicAdd: + case BfIRIntrinsic_AtomicAdd: case BfIRIntrinsic_AtomicAnd: case BfIRIntrinsic_AtomicMax: case BfIRIntrinsic_AtomicMin: case BfIRIntrinsic_AtomicNAnd: case BfIRIntrinsic_AtomicOr: - case BfIRIntrinsic_AtomicSub: - case BfIRIntrinsic_AtomicUMax: - case BfIRIntrinsic_AtomicUMin: + case BfIRIntrinsic_AtomicSub: + case BfIRIntrinsic_AtomicUMax: + case BfIRIntrinsic_AtomicUMin: case BfIRIntrinsic_AtomicXChg: case BfIRIntrinsic_AtomicXor: { @@ -3550,13 +3547,13 @@ void BfIRCodeGen::HandleNextCmd() auto op = llvm::AtomicRMWInst::BinOp::Add; switch (intrinsicData->mIntrinsic) { - case BfIRIntrinsic_AtomicAdd: + case BfIRIntrinsic_AtomicAdd: op = llvm::AtomicRMWInst::BinOp::Add; break; case BfIRIntrinsic_AtomicAnd: op = llvm::AtomicRMWInst::BinOp::And; break; - case BfIRIntrinsic_AtomicMax: + case BfIRIntrinsic_AtomicMax: op = llvm::AtomicRMWInst::BinOp::Max; break; case BfIRIntrinsic_AtomicMin: @@ -3584,7 +3581,7 @@ void BfIRCodeGen::HandleNextCmd() op = llvm::AtomicRMWInst::BinOp::Xor; break; default: break; - } + } auto memoryKindConst = llvm::dyn_cast(args[2]); if (memoryKindConst == NULL) @@ -3598,25 +3595,25 @@ void BfIRCodeGen::HandleNextCmd() switch (memoryKind & BfIRAtomicOrdering_ORDERMASK) { case BfIRAtomicOrdering_Acquire: - ordering = llvm::AtomicOrdering::Acquire; + ordering = llvm::AtomicOrdering::Acquire; break; case BfIRAtomicOrdering_AcqRel: - ordering = llvm::AtomicOrdering::AcquireRelease; + ordering = llvm::AtomicOrdering::AcquireRelease; break; case BfIRAtomicOrdering_Relaxed: - ordering = llvm::AtomicOrdering::Monotonic; + ordering = llvm::AtomicOrdering::Monotonic; break; case BfIRAtomicOrdering_Release: - ordering = llvm::AtomicOrdering::Release; + ordering = llvm::AtomicOrdering::Release; break; case BfIRAtomicOrdering_SeqCst: - ordering = llvm::AtomicOrdering::SequentiallyConsistent; + ordering = llvm::AtomicOrdering::SequentiallyConsistent; break; default: Fail("Invalid ordering on atomic operation"); break; } - + auto atomicRMW = mIRBuilder->CreateAtomicRMW(op, args[0], args[1], llvm::MaybeAlign(), ordering); if ((memoryKind & BfIRAtomicOrdering_Volatile) != 0) atomicRMW->setVolatile(true); @@ -3664,7 +3661,7 @@ void BfIRCodeGen::HandleNextCmd() } result = mIRBuilder->CreateSelect(cmpVal, atomicRMW, args[1]); } - break; + break; case BfIRIntrinsic_AtomicNAnd: result = mIRBuilder->CreateAnd(atomicRMW, args[1]); result = mIRBuilder->CreateNot(result); @@ -3722,7 +3719,7 @@ void BfIRCodeGen::HandleNextCmd() auto resultPtr = mIRBuilder->CreateBitCast(args[1], argType->getPointerTo()); mIRBuilder->CreateStore(vaArgVal, resultPtr); } - break; + break; default: FatalError("Unhandled intrinsic"); } @@ -3744,22 +3741,22 @@ void BfIRCodeGen::HandleNextCmd() int align = 1; BF_ASSERT(args.size() == 5); - auto alignConst = llvm::dyn_cast(args[3]); + auto alignConst = llvm::dyn_cast(args[3]); if (alignConst != NULL) - align = (int)alignConst->getSExtValue(); + align = (int)alignConst->getSExtValue(); bool isVolatile = false; auto volatileConst = llvm::dyn_cast(args[4]); if ((volatileConst != NULL) && (volatileConst->getSExtValue() != 0)) isVolatile = true; - CreateMemSet(args[0], args[1], args[2], align, isVolatile); - break; + CreateMemSet(args[0], args[1], args[2], align, isVolatile); + break; } else if ((intrinId == BfIRIntrinsic_MemCpy) || (intrinId == BfIRIntrinsic_MemMove)) { int align = 1; BF_ASSERT(args.size() == 5); - auto alignConst = llvm::dyn_cast(args[3]); + auto alignConst = llvm::dyn_cast(args[3]); if (alignConst != NULL) align = (int)alignConst->getSExtValue(); bool isVolatile = false; @@ -3771,7 +3768,7 @@ void BfIRCodeGen::HandleNextCmd() else mIRBuilder->CreateMemMove(args[0], llvm::MaybeAlign(align), args[1], llvm::MaybeAlign(align), args[2], isVolatile); break; - } + } } } @@ -3803,7 +3800,7 @@ void BfIRCodeGen::HandleNextCmd() case BfIRCmd_SetFuncCallingConv: { CMD_PARAM(llvm::Function*, func); - BfIRCallingConv callingConv = (BfIRCallingConv)mStream->Read(); + BfIRCallingConv callingConv = (BfIRCallingConv)mStream->Read(); ((llvm::Function*)func)->setCallingConv(GetLLVMCallingConv(callingConv, mTargetTriple)); } break; @@ -3816,10 +3813,10 @@ void BfIRCodeGen::HandleNextCmd() break; case BfIRCmd_SetCallAttribute: { - CMD_PARAM(llvm::Value*, callInst); + CMD_PARAM(llvm::Value*, callInst); CMD_PARAM(int, paramIdx); BfIRAttribute attribute = (BfIRAttribute)mStream->Read(); - BF_ASSERT(llvm::isa(callInst)); + BF_ASSERT(llvm::isa(callInst)); llvm::Attribute::AttrKind attr = llvm::Attribute::None; if (attribute == BfIRAttribute_NoReturn) attr = llvm::Attribute::NoReturn; @@ -3889,7 +3886,7 @@ void BfIRCodeGen::HandleNextCmd() { CMD_PARAM(llvm::Function*, func); CMD_PARAM(int, argIdx); - BfIRAttribute attribute = (BfIRAttribute)mStream->Read(); + BfIRAttribute attribute = (BfIRAttribute)mStream->Read(); if (attribute == BFIRAttribute_DllImport) { func->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass); @@ -3914,9 +3911,9 @@ void BfIRCodeGen::HandleNextCmd() CmdParamVec structVals; structVals.push_back(llvm::ConstantInt::get(llvm::Type::getInt32Ty(*mLLVMContext), 0x7FFFFF00)); structVals.push_back(func); - structVals.push_back(llvm::ConstantPointerNull::get(llvm::Type::getInt8PtrTy(*mLLVMContext))); + structVals.push_back(llvm::ConstantPointerNull::get(llvm::Type::getInt8PtrTy(*mLLVMContext))); auto constStruct = llvm::ConstantStruct::get(structType, structVals); - + CmdParamVec structArrVals; structArrVals.push_back(constStruct); @@ -3930,8 +3927,8 @@ void BfIRCodeGen::HandleNextCmd() llvm::GlobalValue::AppendingLinkage, constArr, (attribute == BFIRAttribute_Constructor) ? "llvm.global_ctors" : "llvm.global_dtors", - NULL, llvm::GlobalValue::NotThreadLocal); - } + NULL, llvm::GlobalValue::NotThreadLocal); + } else { auto attr = LLVMMapAttribute(attribute); @@ -3951,15 +3948,15 @@ void BfIRCodeGen::HandleNextCmd() CMD_PARAM(llvm::Function*, func); CMD_PARAM(int, argIdx); BfIRAttribute attribute = (BfIRAttribute)mStream->Read(); - CMD_PARAM(int, arg); + CMD_PARAM(int, arg); if (attribute == BfIRAttribute_Dereferencable) { - ((llvm::Function*)func)->addDereferenceableAttr(argIdx, arg); + ((llvm::Function*)func)->addDereferenceableAttr(argIdx, arg); } else if (attribute == BfIRAttribute_ByVal) { auto funcType = func->getFunctionType(); - llvm::Attribute byValAttr = llvm::Attribute::getWithByValType(*mLLVMContext, funcType->getFunctionParamType(argIdx - 1)->getPointerElementType()); + llvm::Attribute byValAttr = llvm::Attribute::getWithByValType(*mLLVMContext, funcType->getFunctionParamType(argIdx - 1)->getPointerElementType()); llvm::Attribute alignAttr = llvm::Attribute::getWithAlignment(*mLLVMContext, llvm::Align(arg)); func->addAttribute(argIdx, byValAttr); func->addAttribute(argIdx, alignAttr); @@ -3983,7 +3980,7 @@ void BfIRCodeGen::HandleNextCmd() ++argItr; argItr->setName(name.c_str()); } - break; + break; case BfIRCmd_Func_DeleteBody: { CMD_PARAM(llvm::Function*, func); @@ -4008,7 +4005,7 @@ void BfIRCodeGen::HandleNextCmd() case BfIRCmd_Func_SetLinkage: { CMD_PARAM(llvm::Function*, func); - BfIRLinkageType linkageType = (BfIRLinkageType)mStream->Read(); + BfIRLinkageType linkageType = (BfIRLinkageType)mStream->Read(); ((llvm::Function*)func)->setLinkage(LLVMMapLinkageType(linkageType)); } break; @@ -4070,7 +4067,7 @@ void BfIRCodeGen::HandleNextCmd() } break; case BfIRCmd_Nop: - case BfIRCmd_EnsureInstructionAt: + case BfIRCmd_EnsureInstructionAt: AddNop(); break; case BfIRCmd_StatementStart: @@ -4093,7 +4090,7 @@ void BfIRCodeGen::HandleNextCmd() mLockedBlocks.Add(irBuilder->GetInsertBlock()); // This is generates slower code than the inline asm in debug mode, but can optimize well in release - auto int8Ty = llvm::Type::getInt8Ty(*mLLVMContext); + auto int8Ty = llvm::Type::getInt8Ty(*mLLVMContext); auto int8Ptr = irBuilder->CreateBitCast(val, int8Ty->getPointerTo()); auto int8Val = irBuilder->CreateLoad(int8Ptr); auto cmpResult = irBuilder->CreateICmpUGE(int8Val, llvm::ConstantInt::get(int8Ty, 0x80)); @@ -4104,9 +4101,9 @@ void BfIRCodeGen::HandleNextCmd() irBuilder->CreateCondBr(cmpResult, failBB, passBB); curLLVMFunc->getBasicBlockList().push_back(failBB); - irBuilder->SetInsertPoint(failBB); + irBuilder->SetInsertPoint(failBB); - auto trapDecl = llvm::Intrinsic::getDeclaration(mLLVMModule, llvm::Intrinsic::trap); + auto trapDecl = llvm::Intrinsic::getDeclaration(mLLVMModule, llvm::Intrinsic::trap); auto callInst = irBuilder->CreateCall(trapDecl); callInst->addAttribute(llvm::AttributeList::FunctionIndex, llvm::Attribute::NoReturn); irBuilder->CreateBr(passBB); @@ -4143,12 +4140,12 @@ void BfIRCodeGen::HandleNextCmd() callInst->addAttribute(llvm::AttributeList::FunctionIndex, llvm::Attribute::NoUnwind); SetResult(curId, mIRBuilder->GetInsertBlock()); - } + } } break; case BfIRCmd_DbgInit: { - mDIBuilder = new llvm::DIBuilder(*mLLVMModule); + mDIBuilder = new llvm::DIBuilder(*mLLVMModule); } break; case BfIRCmd_DbgFinalize: @@ -4188,7 +4185,7 @@ void BfIRCodeGen::HandleNextCmd() for (int i = 0; i < 16; i++) sprintf(&hashStr[i * 2], "%.2x", ((uint8*)&md5Hash)[i]); - SetResult(curId, mDIBuilder->createFile(fileName.c_str(), directory.c_str(), + SetResult(curId, mDIBuilder->createFile(fileName.c_str(), directory.c_str(), llvm::DIFile::ChecksumInfo(llvm::DIFile::CSK_MD5, hashStr))); } break; @@ -4199,7 +4196,7 @@ void BfIRCodeGen::HandleNextCmd() } break; case BfIRCmd_DbgGetCurrentLocation: - { + { SetResult(curId, mIRBuilder->getCurrentDebugLocation()); } break; @@ -4289,7 +4286,7 @@ void BfIRCodeGen::HandleNextCmd() //OutputDebugStrF("BfIRCmd_DbgCreateStructType %p\n", mdStruct); } - break; + break; case BfIRCmd_DbgCreateEnumerationType: { CMD_PARAM(llvm::MDNode*, context); @@ -4297,7 +4294,7 @@ void BfIRCodeGen::HandleNextCmd() CMD_PARAM(llvm::MDNode*, file); CMD_PARAM(int, lineNum); CMD_PARAM(int64, sizeInBits); - CMD_PARAM(int64, alignInBits); + CMD_PARAM(int64, alignInBits); CMD_PARAM(CmdParamVec, members); CMD_PARAM(llvm::MDNode*, underlyingType); auto diMembersArray = mDIBuilder->getOrCreateArray(members); @@ -4316,7 +4313,7 @@ void BfIRCodeGen::HandleNextCmd() break; case BfIRCmd_DbgCreatePointerType: { - CMD_PARAM(llvm::MDNode*, diType); + CMD_PARAM(llvm::MDNode*, diType); SetResult(curId, mDIBuilder->createPointerType((llvm::DIType*)diType, mPtrSize*8, (uint32)mPtrSize * 8)); } break; @@ -4344,7 +4341,7 @@ void BfIRCodeGen::HandleNextCmd() CMD_PARAM(int64, alignInBits); CMD_PARAM(llvm::MDNode*, elementType); CMD_PARAM(int64, numElements); - + llvm::SmallVector diSizeVec; diSizeVec.push_back(mDIBuilder->getOrCreateSubrange(0, numElements)); auto diSizeArray = mDIBuilder->getOrCreateArray(diSizeVec); @@ -4378,7 +4375,7 @@ void BfIRCodeGen::HandleNextCmd() auto diType = mDIBuilder->createForwardDecl(tag, name.c_str(), (llvm::DIScope*)scope, (llvm::DIFile*)file, line); SetResult(curId, diType); } - break; + break; case BfIRCmd_DbgCreateSizedForwardDecl: { CMD_PARAM(int, tag); @@ -4391,7 +4388,7 @@ void BfIRCodeGen::HandleNextCmd() BF_ASSERT(file != NULL); SetResult(curId, mDIBuilder->createForwardDecl(tag, name.c_str(), (llvm::DIScope*)scope, (llvm::DIFile*)file, line, 0, sizeInBits, (uint32)alignInBits)); } - break; + break; case BeIRCmd_DbgSetTypeSize: { CMD_PARAM(llvm::MDNode*, mdType); @@ -4412,10 +4409,10 @@ void BfIRCodeGen::HandleNextCmd() } break; case BfIRCmd_DbgReplaceAllUses: - { + { CMD_PARAM(llvm::MDNode*, diPrevNode); CMD_PARAM(llvm::MDNode*, diNewNode); - diPrevNode->replaceAllUsesWith(diNewNode); + diPrevNode->replaceAllUsesWith(diNewNode); } break; case BfIRCmd_DbgDeleteTemporary: @@ -4425,14 +4422,14 @@ void BfIRCodeGen::HandleNextCmd() } break; case BfIRCmd_DbgMakePermanent: - { + { CMD_PARAM(llvm::MDNode*, diNode); CMD_PARAM(llvm::MDNode*, diBaseType); CMD_PARAM(CmdParamVec, members); llvm::MDNode* newNode = diNode; if (auto diComposite = llvm::dyn_cast(diNode)) - { + { //diComposite->getBaseType() if (diBaseType != NULL) @@ -4540,8 +4537,8 @@ void BfIRCodeGen::HandleNextCmd() CMD_PARAM(String, name); CMD_PARAM(String, linkageName); CMD_PARAM(llvm::MDNode*, file); - CMD_PARAM(int, lineNum); - CMD_PARAM(llvm::MDNode*, type); + CMD_PARAM(int, lineNum); + CMD_PARAM(llvm::MDNode*, type); CMD_PARAM(bool, isLocalToUnit); CMD_PARAM(bool, isDefinition); CMD_PARAM(int, vk); @@ -4553,7 +4550,7 @@ void BfIRCodeGen::HandleNextCmd() CMD_PARAM(CmdParamVec, genericArgs); CMD_PARAM(CmdParamVec, genericConstValueArgs); BF_ASSERT(file != NULL); - + llvm::DITemplateParameterArray templateParamArr = NULL; llvm::DINodeArray templateParamNodes; if (genericArgs.size() != 0) @@ -4568,14 +4565,14 @@ void BfIRCodeGen::HandleNextCmd() if (i < genericConstValueArgs.size()) constant = genericConstValueArgs[i]; - if (constant != NULL) - templateParams.push_back(mDIBuilder->createTemplateValueParameter(mDICompileUnit, name.c_str(), genericArg, false, constant)); + if (constant != NULL) + templateParams.push_back(mDIBuilder->createTemplateValueParameter(mDICompileUnit, name.c_str(), genericArg, false, constant)); else templateParams.push_back(mDIBuilder->createTemplateTypeParameter(mDICompileUnit, name.c_str(), genericArg, false)); } templateParamNodes = mDIBuilder->getOrCreateArray(templateParams); templateParamArr = templateParamNodes.get(); - } + } llvm::DINode::DIFlags diFlags = (llvm::DINode::DIFlags)flags; llvm::DISubprogram::DISPFlags dispFlags = llvm::DISubprogram::DISPFlags::SPFlagZero; @@ -4589,7 +4586,7 @@ void BfIRCodeGen::HandleNextCmd() dispFlags = (llvm::DISubprogram::DISPFlags)(dispFlags | llvm::DISubprogram::DISPFlags::SPFlagVirtual); auto diSubProgram = mDIBuilder->createMethod((llvm::DIScope*)context, name.c_str(), linkageName.c_str(), (llvm::DIFile*)file, lineNum, - (llvm::DISubroutineType*)type, vIndex, 0, (llvm::DIType*)vTableHolder, diFlags, dispFlags, templateParamArr); + (llvm::DISubroutineType*)type, vIndex, 0, (llvm::DIType*)vTableHolder, diFlags, dispFlags, templateParamArr); if (fn != NULL) ((llvm::Function*)fn)->setSubprogram(diSubProgram); @@ -4604,10 +4601,10 @@ void BfIRCodeGen::HandleNextCmd() CMD_PARAM(String, name); CMD_PARAM(String, linkageName); CMD_PARAM(llvm::MDNode*, file); - CMD_PARAM(int, lineNum); - CMD_PARAM(llvm::MDNode*, type); + CMD_PARAM(int, lineNum); + CMD_PARAM(llvm::MDNode*, type); CMD_PARAM(bool, isLocalToUnit); - CMD_PARAM(bool, isDefinition); + CMD_PARAM(bool, isDefinition); CMD_PARAM(int, scopeLine); CMD_PARAM(int, flags); CMD_PARAM(bool, isOptimized); @@ -4650,7 +4647,7 @@ void BfIRCodeGen::HandleNextCmd() break; case BfIRCmd_DbgCreateSubroutineType: { - CMD_PARAM(CmdParamVec, elements); + CMD_PARAM(CmdParamVec, elements); auto diArray = mDIBuilder->getOrCreateTypeArray(elements); SetResult(curId, mDIBuilder->createSubroutineType(diArray)); } @@ -4678,7 +4675,7 @@ void BfIRCodeGen::HandleNextCmd() CMD_PARAM(llvm::MDNode*, varInfo); auto diVariable = (llvm::DILocalVariable*)varInfo; - + if (val == NULL) { val = llvm::ConstantInt::get(llvm::Type::getInt32Ty(*mLLVMContext), 0); @@ -4692,7 +4689,7 @@ void BfIRCodeGen::HandleNextCmd() { writeVal = constantInt->getSExtValue(); } - + auto nameRef = diVariable->getName(); if (writeVal < 0) @@ -4702,7 +4699,7 @@ void BfIRCodeGen::HandleNextCmd() } } - mDIBuilder->insertDbgValueIntrinsic(val, diVariable, mDIBuilder->createExpression(), + mDIBuilder->insertDbgValueIntrinsic(val, diVariable, mDIBuilder->createExpression(), mIRBuilder->getCurrentDebugLocation(), (llvm::BasicBlock*)mIRBuilder->GetInsertBlock()); } break; @@ -4724,13 +4721,13 @@ void BfIRCodeGen::HandleNextCmd() { SetResult(curId, mDIBuilder->insertDeclare(val, (llvm::DILocalVariable*)varInfo, mDIBuilder->createExpression(), mIRBuilder->getCurrentDebugLocation(), mIRBuilder->GetInsertBlock())); - } + } } - break; + break; case BfIRCmd_DbgLifetimeEnd: { CMD_PARAM(llvm::MDNode*, varInfo); - } + } break; case BfIRCmd_DbgCreateGlobalVariable: { @@ -4740,21 +4737,21 @@ void BfIRCodeGen::HandleNextCmd() CMD_PARAM(llvm::MDNode*, file); CMD_PARAM(int, lineNum); CMD_PARAM(llvm::MDNode*, type); - CMD_PARAM(bool, isLocalToUnit); + CMD_PARAM(bool, isLocalToUnit); CMD_PARAM(llvm::Constant*, val); CMD_PARAM(llvm::MDNode*, decl); //BF_ASSERT(file != NULL); - llvm::DIExpression* diExpr = NULL; + llvm::DIExpression* diExpr = NULL; auto gve = mDIBuilder->createGlobalVariableExpression((llvm::DIScope*)context, name.c_str(), linkageName.c_str(), (llvm::DIFile*)file, lineNum, (llvm::DIType*)type, isLocalToUnit, true, diExpr, decl); - + if (val != NULL) { if (auto globalVar = llvm::dyn_cast(val)) { globalVar->addDebugInfo(gve); } - } + } SetResult(curId, diExpr); } @@ -4768,7 +4765,7 @@ void BfIRCodeGen::HandleNextCmd() BF_ASSERT(file != NULL); SetResult(curId, mDIBuilder->createLexicalBlock((llvm::DIScope*)scope, (llvm::DIFile*)file, (unsigned)lineNum, (unsigned)col)); } - break; + break; case BfIRCmd_DbgCreateAnnotation: { CMD_PARAM(llvm::MDNode*, scope); @@ -4794,7 +4791,7 @@ void BfIRCodeGen::HandleNextCmd() { writeVal = constant->getSExtValue(); } - + if (writeVal < 0) dbgName += StrFormat("$_%llu", -writeVal); else @@ -4852,7 +4849,7 @@ llvm::BasicBlock * BfIRCodeGen::GetLLVMBlock(int id) llvm::MDNode* BfIRCodeGen::GetLLVMMetadata(int id) { - auto& result = mResults[id]; + auto& result = mResults[id]; BF_ASSERT(result.mKind == BfIRCodeGenEntryKind_LLVMMetadata); return result.mLLVMMetadata; } @@ -4905,7 +4902,7 @@ static void AddInstructionCombiningPass(llvm::legacy::PassManagerBase &PM, const PM.add(llvm::createInstructionCombiningPass(options.mExpensiveCombines)); } -static void AddFunctionSimplificationPasses(llvm::legacy::PassManagerBase &MPM, const BfCodeGenOptions& options) +static void AddFunctionSimplificationPasses(llvm::legacy::PassManagerBase &MPM, const BfCodeGenOptions& options) { // Start of function pass. // Break up aggregate allocas, using SSAUpdater. @@ -4914,7 +4911,7 @@ static void AddFunctionSimplificationPasses(llvm::legacy::PassManagerBase &MPM, //if (EnableGVNHoist) if (options.mEnableGVNHoist) MPM.add(llvm::createGVNHoistPass()); - if (options.mEnableGVNSink) + if (options.mEnableGVNSink) { MPM.add(llvm::createGVNSinkPass()); MPM.add(llvm::createCFGSimplificationPass()); @@ -5054,7 +5051,7 @@ static void PopulateModulePassManager(llvm::legacy::PassManagerBase &MPM, const // else if (GlobalExtensionsNotEmpty() || !Extensions.empty()) // MPM.add(createBarrierNoopPass()); - if (performThinLTO) + if (performThinLTO) { // Drop available_externally and unreferenced globals. This is necessary // with ThinLTO in order to avoid leaving undefined references to dead @@ -5360,7 +5357,6 @@ static void PopulateModulePassManager(llvm::legacy::PassManagerBase &MPM, const } } - namespace { struct BfPass : public llvm::MachineFunctionPass @@ -5422,13 +5418,13 @@ bool BfIRCodeGen::WriteObjectFile(const StringImpl& outFileName) { // { // PassManagerBuilderWrapper pmBuilder; - // - // + // + // // } - + mHasDebugLoc = false; // So fails don't show a line number - bool enableLTO = mCodeGenOptions.mLTOType != BfLTOType_None; + bool enableLTO = mCodeGenOptions.mLTOType != BfLTOType_None; if (enableLTO) { @@ -5441,7 +5437,7 @@ bool BfIRCodeGen::WriteObjectFile(const StringImpl& outFileName) if (mHadDLLExport) // LTO bug in LLVM-link? enableLTO = false; } - + std::error_code EC; llvm::sys::fs::OpenFlags OpenFlags = llvm::sys::fs::OF_None; @@ -5453,18 +5449,18 @@ bool BfIRCodeGen::WriteObjectFile(const StringImpl& outFileName) llvm::legacy::PassManager PM; llvm::Triple theTriple = llvm::Triple(mLLVMModule->getTargetTriple()); - // Add an appropriate TargetLibraryInfo pass for the module's triple. + // Add an appropriate TargetLibraryInfo pass for the module's triple. llvm::TargetLibraryInfoImpl TLII(theTriple); PM.add(new llvm::TargetLibraryInfoWrapperPass(TLII)); - // Add the target data from the target machine, if it exists, or the module. + // Add the target data from the target machine, if it exists, or the module. //PM.add(new DataLayoutPass()); PopulateModulePassManager(PM, mCodeGenOptions); llvm::raw_fd_ostream* outStream = NULL; defer ( delete outStream; ); - + if ((enableLTO) || (mCodeGenOptions.mWriteBitcode)) { std::error_code ec; @@ -5473,12 +5469,12 @@ bool BfIRCodeGen::WriteObjectFile(const StringImpl& outFileName) { return false; } - + if (enableLTO) PM.add(createWriteThinLTOBitcodePass(*outStream, NULL)); else PM.add(createBitcodeWriterPass(*outStream, false, false, false)); - } + } //TargetPassConfig *PassConfig = target->createPassConfig(PM); //PM.add(new BfPass()); @@ -5498,7 +5494,7 @@ bool BfIRCodeGen::WriteObjectFile(const StringImpl& outFileName) llvm::AnalysisID StopAfterID = nullptr; const llvm::PassRegistry *PR = llvm::PassRegistry::getPassRegistry(); - //WriteBitcode + //WriteBitcode bool noVerify = false; // Option if ((!enableLTO) && (!mCodeGenOptions.mWriteBitcode)) @@ -5528,7 +5524,7 @@ bool BfIRCodeGen::WriteObjectFile(const StringImpl& outFileName) fileName += "_OPT.ll"; String irError; - WriteIR(fileName, irError); + WriteIR(fileName, irError); } } @@ -5537,25 +5533,25 @@ bool BfIRCodeGen::WriteObjectFile(const StringImpl& outFileName) bool BfIRCodeGen::WriteIR(const StringImpl& outFileName, StringImpl& error) { - std::error_code ec; + std::error_code ec; llvm::raw_fd_ostream outStream(outFileName.c_str(), ec, llvm::sys::fs::OpenFlags::OF_Text); if (ec) { error = ec.message(); return false; - } + } mLLVMModule->print(outStream, NULL); return true; } int BfIRCodeGen::GetIntrinsicId(const StringImpl& name) -{ +{ auto itr = std::lower_bound(std::begin(gIntrinEntries), std::end(gIntrinEntries), name); if (itr != std::end(gIntrinEntries) && strcmp(itr->mName, name.c_str()) == 0) { int id = (int)(itr - gIntrinEntries); return id; - } + } if (name.StartsWith("shuffle")) return BfIRIntrinsic_Shuffle; @@ -5607,7 +5603,7 @@ int BF_AARC64_Linkage() { LLVMInitializeAArch64TargetInfo(); LLVMInitializeAArch64Target(); - LLVMInitializeAArch64TargetMC(); + LLVMInitializeAArch64TargetMC(); return 0; } #endif diff --git a/IDEHelper/Compiler/BfIRCodeGen.h b/IDEHelper/Compiler/BfIRCodeGen.h index 049ca8d7..28773467 100644 --- a/IDEHelper/Compiler/BfIRCodeGen.h +++ b/IDEHelper/Compiler/BfIRCodeGen.h @@ -20,7 +20,7 @@ namespace llvm class AttributeList; class Module; class LLVMContext; - class TargetMachine; + class TargetMachine; }; NS_BF_BEGIN @@ -41,7 +41,7 @@ class BfIRIntrinsicData public: String mName; BfIRIntrinsic mIntrinsic; - llvm::Type* mReturnType; + llvm::Type* mReturnType; }; struct BfIRCodeGenEntry @@ -52,7 +52,7 @@ struct BfIRCodeGenEntry llvm::Value* mLLVMValue; llvm::Type* mLLVMType; llvm::BasicBlock* mLLVMBlock; - llvm::MDNode* mLLVMMetadata; + llvm::MDNode* mLLVMMetadata; BfIRIntrinsicData* mIntrinsicData; }; }; @@ -67,7 +67,7 @@ public: llvm::DIType* mInstDIType; llvm::Type* mLLVMType; llvm::Type* mAlignLLVMType; - llvm::Type* mInstLLVMType; + llvm::Type* mInstLLVMType; public: BfIRTypeEntry() @@ -87,14 +87,14 @@ enum BfIRSizeAlignKind { BfIRSizeAlignKind_NoTransform, BfIRSizeAlignKind_Original, - BfIRSizeAlignKind_Aligned, + BfIRSizeAlignKind_Aligned, }; class BfIRCodeGen : public BfIRCodeGenBase { -public: - BfIRBuilder* mBfIRBuilder; - +public: + BfIRBuilder* mBfIRBuilder; + BumpAllocator mAlloc; BfTargetTriple mTargetTriple; String mTargetCPU; @@ -113,7 +113,7 @@ public: llvm::InlineAsm* mOverflowCheckAsm; llvm::DebugLoc mDebugLoc; BfCodeGenOptions mCodeGenOptions; - bool mHasDebugLoc; + bool mHasDebugLoc; bool mIsCodeView; bool mHadDLLExport; int mConstValIdx; @@ -122,7 +122,7 @@ public: Dictionary mResults; Dictionary mTypes; Dictionary mIntrinsicMap; - Dictionary mIntrinsicReverseMap; + Dictionary mIntrinsicReverseMap; Array mConfigConsts32; Array mConfigConsts64; Dictionary mReflectDataMap; @@ -131,7 +131,7 @@ public: HashSet mLockedBlocks; OwnedArray mIntrinsicData; -public: +public: void InitTarget(); void FixValues(llvm::StructType* structType, llvm::SmallVector& values); void FixIndexer(llvm::Value*& val); @@ -141,15 +141,15 @@ public: BfIRTypeEntry* GetTypeEntry(llvm::Type* type); void SetResult(int id, llvm::Value* value); void SetResultAligned(int id, llvm::Value* value); - void SetResult(int id, llvm::Type* value); + void SetResult(int id, llvm::Type* value); void SetResult(int id, llvm::BasicBlock* value); - void SetResult(int id, llvm::MDNode* value); + void SetResult(int id, llvm::MDNode* value); void CreateMemSet(llvm::Value* addr, llvm::Value* val, llvm::Value* size, int alignment, bool isVolatile = false); void AddNop(); llvm::Value* TryToVector(llvm::Value* value); llvm::Value* TryToVector(llvm::Value* value, llvm::Type* elemType); llvm::Type* GetElemType(llvm::Value* value); - bool TryMemCpy(llvm::Value* ptr, llvm::Value* val); + bool TryMemCpy(llvm::Value* ptr, llvm::Value* val); bool TryVectorCpy(llvm::Value* ptr, llvm::Value* val); llvm::Type* GetSizeAlignedType(BfIRTypeEntry* typeEntry); llvm::Value* GetAlignedPtr(llvm::Value* val); @@ -168,7 +168,7 @@ public: void PrintFunction(); int64 ReadSLEB128(); - void Read(StringImpl& str); + void Read(StringImpl& str); void Read(int& i); void Read(int64& i); void Read(Val128& i); @@ -227,14 +227,14 @@ public: llvm::BasicBlock* GetLLVMBlock(int streamId); llvm::MDNode* GetLLVMMetadata(int streamId); - llvm::Type* GetLLVMTypeById(int id); + llvm::Type* GetLLVMTypeById(int id); /// bool WriteObjectFile(const StringImpl& outFileName); bool WriteIR(const StringImpl& outFileName, StringImpl& error); - static int GetIntrinsicId(const StringImpl& name); + static int GetIntrinsicId(const StringImpl& name); static const char* GetIntrinsicName(int intrinId); static void SetAsmKind(BfAsmKind asmKind); @@ -242,4 +242,3 @@ public: }; NS_BF_END - diff --git a/IDEHelper/Compiler/BfMangler.cpp b/IDEHelper/Compiler/BfMangler.cpp index c3330d71..6954585f 100644 --- a/IDEHelper/Compiler/BfMangler.cpp +++ b/IDEHelper/Compiler/BfMangler.cpp @@ -16,7 +16,7 @@ int BfGNUMangler::ParseSubIdx(StringImpl& name, int strIdx) void BfGNUMangler::AddSubIdx(StringImpl& name, int subIdx) { - name += 'S'; + name += 'S'; if (subIdx != 0) { int showIdx = subIdx - 1; @@ -29,7 +29,7 @@ void BfGNUMangler::AddSubIdx(StringImpl& name, int subIdx) name += '0' + showIdx; else name += 'A' + (showIdx - 10); - } + } name += '_'; } @@ -60,20 +60,20 @@ BfTypeCode BfGNUMangler::GetPrimTypeAt(MangleContext& mangleContext, StringImpl& case 'm': return BfTypeCode_UInt64; case 'x': return BfTypeCode_Int64; case 'y': return BfTypeCode_UInt64; - case 'u': + case 'u': if (name[strIdx + 1] == '3') return BfTypeCode_IntPtr; if (name[strIdx + 1] == '4') return BfTypeCode_UIntPtr; - break; + break; case 'c': return BfTypeCode_Char8; - case 'D': + case 'D': if (name[strIdx + 1] == 'i') return BfTypeCode_Char32; else if (name[strIdx + 1] == 's') return BfTypeCode_Char16; break; - case 'f': return BfTypeCode_Float; + case 'f': return BfTypeCode_Float; case 'd': return BfTypeCode_Double; } return (BfTypeCode)-1; @@ -93,7 +93,7 @@ void BfGNUMangler::AddPrefix(MangleContext& mangleContext, StringImpl& name, int { BF_ASSERT(name.EndsWith('_')); name.RemoveToEnd(startIdx); - AddSubIdx(name, matchIdx); + AddSubIdx(name, matchIdx); return; } } @@ -107,9 +107,9 @@ void BfGNUMangler::AddPrefix(MangleContext& mangleContext, StringImpl& name, int { auto& entry = mangleContext.mSubstituteList[matchIdx]; if ((entry.mKind == NameSubstitute::Kind_PrimitivePrefix) && (entry.mExtendsTypeCode == typeCode) && (entry.mPrefix == prefix)) - { + { name.RemoveToEnd(startIdx); - AddSubIdx(name, matchIdx); + AddSubIdx(name, matchIdx); return; } } @@ -125,7 +125,7 @@ void BfGNUMangler::AddPrefix(MangleContext& mangleContext, StringImpl& name, int } else { - // Applies to last-added one + // Applies to last-added one subIdx = (int)mangleContext.mSubstituteList.size() - 1; BF_ASSERT(isdigit(startChar) || (startChar == 'A') || (startChar == 'N') || (startChar == 'P') || (startChar == 'R') || (startChar == 'U')); } @@ -146,35 +146,35 @@ void BfGNUMangler::FindOrCreateNameSub(MangleContext& mangleContext, StringImpl& bool matchFailed = false; FindOrCreateNameSub(mangleContext, name, newNameSub, curMatchIdx, matchFailed); if (!matchFailed) - AddSubIdx(name, curMatchIdx); + AddSubIdx(name, curMatchIdx); } void BfGNUMangler::FindOrCreateNameSub(MangleContext& mangleContext, StringImpl& name, const NameSubstitute& newNameSub, int& curMatchIdx, bool& matchFailed) -{ +{ int parentIdx = curMatchIdx; if (!matchFailed) - { + { curMatchIdx++; for ( ; curMatchIdx < (int)mangleContext.mSubstituteList.size(); curMatchIdx++) { auto& entry = mangleContext.mSubstituteList[curMatchIdx]; if ((entry.mExtendsIdx == parentIdx) && (entry.mKind == newNameSub.mKind) && (entry.mParam == newNameSub.mParam)) - { + { return; } } - + matchFailed = true; if (newNameSub.mKind != BfGNUMangler::NameSubstitute::Kind_GenericParam) name += "N"; if (parentIdx != -1) - AddSubIdx(name, parentIdx); + AddSubIdx(name, parentIdx); } - + if (newNameSub.mKind == NameSubstitute::Kind_NamespaceAtom) { AddSizedString(name, newNameSub.mAtom->mString.mPtr); - } + } else if (newNameSub.mKind == NameSubstitute::Kind_TypeInstName) { auto typeDef = newNameSub.mTypeInst->mTypeDef; @@ -182,15 +182,15 @@ void BfGNUMangler::FindOrCreateNameSub(MangleContext& mangleContext, StringImpl& // when we remove the "incorrect" version. I believe this is no longer needed since our compilation model has changed /*if (typeDef->mDupDetectedRevision != -1) { - char str[64]; + char str[64]; sprintf(str, "_%p", typeDef); name += str; }*/ if ((typeDef->mIsDelegate) && (newNameSub.mTypeInst->IsClosure())) - { + { auto closureType = (BfClosureType*)newNameSub.mTypeInst; - if (!closureType->mCreatedTypeDef) - name += closureType->mNameAdd; + if (!closureType->mCreatedTypeDef) + name += closureType->mNameAdd; } AddSizedString(name, typeDef->mName->mString.mPtr); } @@ -199,7 +199,7 @@ void BfGNUMangler::FindOrCreateNameSub(MangleContext& mangleContext, StringImpl& int genericParamStart = 0; if (newNameSub.mTypeInst->mTypeDef->mOuterType != NULL) genericParamStart = (int)newNameSub.mTypeInst->mTypeDef->mOuterType->mGenericParamDefs.size(); - + name += "I"; auto typeDef = newNameSub.mTypeInst->mTypeDef; @@ -214,10 +214,10 @@ void BfGNUMangler::FindOrCreateNameSub(MangleContext& mangleContext, StringImpl& BfTypeInstance* genericTypeInstance = (BfTypeInstance*)checkType; for (int genericParamIdx = genericParamStart; genericParamIdx < (int) typeDef->mGenericParamDefs.size(); genericParamIdx++) - { + { auto genericParam = genericTypeInstance->mGenericTypeInfo->mTypeGenericArguments[genericParamIdx]; - Mangle(mangleContext, name, genericParam); + Mangle(mangleContext, name, genericParam); } name += "E"; @@ -229,18 +229,18 @@ void BfGNUMangler::FindOrCreateNameSub(MangleContext& mangleContext, StringImpl& if (genericParamType->mGenericParamIdx < 10) name += "3"; else - name += "4"; + name += "4"; if (genericParamType->mGenericParamKind == BfGenericParamKind_Method) name += "`M"; else - name += "`T"; + name += "`T"; itoa(genericParamType->mGenericParamIdx, str, 10); name += str; } - + curMatchIdx = (int)mangleContext.mSubstituteList.size(); mangleContext.mSubstituteList.push_back(newNameSub); - + auto& nameSubRef = mangleContext.mSubstituteList.back(); nameSubRef.mExtendsIdx = parentIdx; } @@ -269,17 +269,17 @@ void BfGNUMangler::FindOrCreateNameSub(MangleContext& mangleContext, StringImpl& if (typeDef->mGenericParamDefs.size() != numOuterGenericParams) { - FindOrCreateNameSub(mangleContext, name, NameSubstitute(NameSubstitute::Kind_TypeGenericArgs, typeInst), curMatchIdx, matchFailed); + FindOrCreateNameSub(mangleContext, name, NameSubstitute(NameSubstitute::Kind_TypeGenericArgs, typeInst), curMatchIdx, matchFailed); } } void BfGNUMangler::MangleTypeInst(MangleContext& mangleContext, StringImpl& name, BfTypeInstance* typeInst, BfTypeInstance* postfixTypeInstance, bool* isEndOpen) -{ +{ static int sCallCount = 0; sCallCount++; - + if (typeInst->IsTuple()) - { + { auto tupleType = (BfTypeInstance*)typeInst; name += "N7__TUPLEI"; mangleContext.mSubstituteList.push_back(NameSubstitute(BfGNUMangler::NameSubstitute::Kind_None, NULL)); // Insert entry for '__TUPLE' @@ -294,7 +294,7 @@ void BfGNUMangler::MangleTypeInst(MangleContext& mangleContext, StringImpl& name } name += "E"; mangleContext.mSubstituteList.push_back(NameSubstitute(BfGNUMangler::NameSubstitute::Kind_None, NULL)); // Insert entry for '__TUPLE' - if (isEndOpen != NULL) + if (isEndOpen != NULL) *isEndOpen = true; else name += "E"; @@ -311,7 +311,7 @@ void BfGNUMangler::MangleTypeInst(MangleContext& mangleContext, StringImpl& name else name += "N8functionI"; SizedArray typeVec; - typeVec.push_back(BfNodeDynCast(methodDef->mReturnTypeRef)->mType); + typeVec.push_back(BfNodeDynCast(methodDef->mReturnTypeRef)->mType); if (methodDef->mIsMutating) name += "_mut_"; if (delegateInfo->mCallingConvention == BfCallingConvention_Cdecl) @@ -342,15 +342,15 @@ void BfGNUMangler::MangleTypeInst(MangleContext& mangleContext, StringImpl& name name += "E"; name += "E"; } - else if (typeInst->IsBoxed()) + else if (typeInst->IsBoxed()) { - auto boxedType = (BfBoxedType*)typeInst; + auto boxedType = (BfBoxedType*)typeInst; name += "N3BoxI"; - mangleContext.mSubstituteList.push_back(NameSubstitute(BfGNUMangler::NameSubstitute::Kind_None, NULL)); // Insert entry for 'Box' + mangleContext.mSubstituteList.push_back(NameSubstitute(BfGNUMangler::NameSubstitute::Kind_None, NULL)); // Insert entry for 'Box' Mangle(mangleContext, name, boxedType->GetModifiedElementType(), postfixTypeInstance); - name += "E"; + name += "E"; mangleContext.mSubstituteList.push_back(NameSubstitute(BfGNUMangler::NameSubstitute::Kind_None, NULL)); // Insert entry for 'Box' - if (isEndOpen != NULL) + if (isEndOpen != NULL) *isEndOpen = true; else name += "E"; @@ -373,20 +373,20 @@ void BfGNUMangler::MangleTypeInst(MangleContext& mangleContext, StringImpl& name if (!mangleContext.mCPPMangle) FindOrCreateNameSub(mangleContext, name, NameSubstitute(NameSubstitute::Kind_NamespaceAtom, typeInst->mModule->mSystem->mBfAtom), curMatchIdx, matchFailed); - + for (int i = 0; i < typeDef->mNamespace.mSize; i++) FindOrCreateNameSub(mangleContext, name, NameSubstitute(NameSubstitute::Kind_NamespaceAtom, typeDef->mNamespace.mParts[i]), curMatchIdx, matchFailed); - + FindOrCreateNameSub(mangleContext, name, useTypeInst, curMatchIdx, matchFailed); } if (isEndOpen != NULL) - { + { if (!matchFailed) - { + { if (curMatchIdx != -1) { name += "N"; - AddSubIdx(name, curMatchIdx); + AddSubIdx(name, curMatchIdx); *isEndOpen = true; } else @@ -403,30 +403,30 @@ void BfGNUMangler::MangleTypeInst(MangleContext& mangleContext, StringImpl& name } else { - AddSubIdx(name, curMatchIdx); + AddSubIdx(name, curMatchIdx); } } void BfGNUMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType* type, BfType* postfixType, bool isConst) -{ +{ static int sCallCount = 0; sCallCount++; - + if (type->IsPrimitiveType()) { - auto primType = (BfPrimitiveType*)type; + auto primType = (BfPrimitiveType*)type; switch (primType->mTypeDef->mTypeCode) { case BfTypeCode_NullPtr: { auto pointerType = (BfPointerType*)type; - int startIdx = (int)name.length(); + int startIdx = (int)name.length(); name += "v"; - AddPrefix(mangleContext, name, startIdx, "P"); + AddPrefix(mangleContext, name, startIdx, "P"); } return; - case BfTypeCode_Dot: + case BfTypeCode_Dot: name += "U3dot"; return; case BfTypeCode_None: @@ -434,7 +434,7 @@ void BfGNUMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType name += "v"; else name += "U4void"; - return; + return; case BfTypeCode_Self: if ((mangleContext.mCCompat) || (mangleContext.mInArgs)) name += "U8concrete"; @@ -519,28 +519,28 @@ void BfGNUMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType //name += Mangle(primType->mTypeDef, NULL, addName, NULL, substituteList); } else if (type->IsTypeInstance()) - { + { BfTypeInstance* postfixTypeInst = NULL; if (postfixType != NULL) postfixTypeInst = postfixType->ToTypeInstance(); - auto typeInstance = (BfTypeInstance*)type; + auto typeInstance = (BfTypeInstance*)type; int startIdx = (int)name.length(); MangleTypeInst(mangleContext, name, typeInstance, postfixTypeInst); if ((type->IsObjectOrInterface()) && (mangleContext.mPrefixObjectPointer)) - AddPrefix(mangleContext, name, startIdx, "P"); - } + AddPrefix(mangleContext, name, startIdx, "P"); + } else if (type->IsGenericParam()) - { + { FindOrCreateNameSub(mangleContext, name, NameSubstitute(NameSubstitute::Kind_GenericParam, type)); } else if (type->IsPointer()) - { + { auto pointerType = (BfPointerType*)type; - int startIdx = (int)name.length(); + int startIdx = (int)name.length(); Mangle(mangleContext, name, pointerType->mElementType); - AddPrefix(mangleContext, name, startIdx, "P"); + AddPrefix(mangleContext, name, startIdx, "P"); return; } else if (type->IsRef()) @@ -555,15 +555,15 @@ void BfGNUMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType name += "U3mut"; Mangle(mangleContext, name, refType->mElementType); return; - } + } else if ((refType->mRefKind == BfRefType::RefKind_Out) && (!mangleContext.mCCompat)) { name += "U3out"; Mangle(mangleContext, name, refType->mElementType); return; } - int startIdx = (int)name.length(); - Mangle(mangleContext, name, refType->mElementType); + int startIdx = (int)name.length(); + Mangle(mangleContext, name, refType->mElementType); AddPrefix(mangleContext, name, startIdx, isConst ? "RK" : "R"); return; } @@ -609,7 +609,7 @@ void BfGNUMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType } else if (type->IsMethodRef()) { - auto methodRefType = (BfMethodRefType*)type; + auto methodRefType = (BfMethodRefType*)type; String mrefName = "mref_"; String mangleName; BfMethodInstance* methodInstance = methodRefType->mMethodRef; @@ -618,7 +618,7 @@ void BfGNUMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType BF_ASSERT(!methodRefType->mMangledMethodName.IsEmpty()); mangleName = methodRefType->mMangledMethodName; } - else + else { if (methodInstance->mIsAutocompleteMethod) name += "AUTOCOMPLETE"; @@ -629,7 +629,7 @@ void BfGNUMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType // There are cases where we will reprocess a method in ResolveOnly for things like // GetSymbolReferences, so we will have duplicate live local methodInstances in those cases mrefName += HashEncode64((uint64)methodRefType->mMethodRef); - } + } else { mangleName = Mangle(methodInstance); @@ -638,7 +638,7 @@ void BfGNUMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType } if (!mangleName.IsEmpty()) - { + { Val128 val128 = Hash128(mangleName.c_str(), (int)mangleName.length()); mrefName += HashEncode128(val128); } @@ -647,9 +647,9 @@ void BfGNUMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType name += mrefName; } else if (type->IsConstExprValue()) - { + { BfConstExprValueType* constExprValueType = (BfConstExprValueType*)type; - int64 val = constExprValueType->mValue.mInt64; + int64 val = constExprValueType->mValue.mInt64; if ((!constExprValueType->mType->IsPrimitiveType()) || (((BfPrimitiveType*)constExprValueType->mType)->mTypeDef->mTypeCode != BfTypeCode_IntPtr)) @@ -657,7 +657,7 @@ void BfGNUMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType Mangle(mangleContext, name, constExprValueType->mType); } - name += "$0"; + name += "$0"; if (val < 0) { @@ -677,27 +677,27 @@ void BfGNUMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType while (val > 0) { *(--strP) = (char)((val % 0x10) + 'A'); - val /= 0x10; + val /= 0x10; } name += strP; name += '`'; - } + } if (constExprValueType->mValue.mTypeCode == BfTypeCode_Let) name += "Undef"; } else { - BF_FATAL("Not handled"); + BF_FATAL("Not handled"); } } String BfGNUMangler::Mangle(BfType* type, BfModule* module) { - StringT<256> name; + StringT<256> name; name += "_ZTS"; - MangleContext mangleContext; + MangleContext mangleContext; mangleContext.mModule = module; Mangle(mangleContext, name, type); return name; @@ -706,9 +706,9 @@ String BfGNUMangler::Mangle(BfType* type, BfModule* module) String BfGNUMangler::Mangle(BfMethodInstance* methodInst) { StringT<256> name; - + if ((methodInst->mMethodDef->mCLink) && (!methodInst->mMangleWithIdx)) - { + { return methodInst->mMethodDef->mName; } @@ -717,13 +717,13 @@ String BfGNUMangler::Mangle(BfMethodInstance* methodInst) auto typeInst = methodInst->GetOwner(); auto typeDef = typeInst->mTypeDef; - MangleContext mangleContext; + MangleContext mangleContext; mangleContext.mModule = methodInst->GetOwner()->mModule; if (methodInst->mCallingConvention != BfCallingConvention_Unspecified) - mangleContext.mCCompat = true; - bool isCMangle = false; + mangleContext.mCCompat = true; + bool isCMangle = false; HandleCustomAttributes(methodInst->GetCustomAttributes(), typeInst->mConstHolder, mangleContext.mModule, name, isCMangle, mangleContext.mCPPMangle); - if (isCMangle) + if (isCMangle) name += methodInst->mMethodDef->mName; if (!name.IsEmpty()) return name; @@ -732,7 +732,7 @@ String BfGNUMangler::Mangle(BfMethodInstance* methodInst) bool prefixLen = false; bool isNameOpen = false; - name += "_Z"; + name += "_Z"; MangleTypeInst(mangleContext, name, methodInst->mMethodInstanceGroup->mOwner, methodInst->GetExplicitInterface(), &isNameOpen); if (methodInst->GetForeignType() != NULL) @@ -740,7 +740,7 @@ String BfGNUMangler::Mangle(BfMethodInstance* methodInst) // This won't demangle correctly. TODO: Do this 'correctly' MangleTypeInst(mangleContext, name, methodInst->GetForeignType()); } - + mangleContext.mPrefixObjectPointer = true; StringT<128> methodName = methodInst->mMethodDef->mName; for (int i = 0; i < (int)methodName.length(); i++) @@ -834,7 +834,7 @@ String BfGNUMangler::Mangle(BfMethodInstance* methodInst) break; case BfBinaryOp_As: methodName = "2as"; - break; + break; default: break; } @@ -886,7 +886,7 @@ String BfGNUMangler::Mangle(BfMethodInstance* methodInst) else if (methodInst->mMethodDef->mMethodType == BfMethodType_Ctor) { if (methodInst->mMethodDef->mIsStatic) - { + { methodName = "__BfStaticCtor"; prefixLen = true; } @@ -896,7 +896,7 @@ String BfGNUMangler::Mangle(BfMethodInstance* methodInst) else if (methodInst->mMethodDef->mMethodType == BfMethodType_Dtor) { if (methodInst->mMethodDef->mIsStatic) - { + { methodName = "__BfStaticDtor"; prefixLen = true; } @@ -922,10 +922,10 @@ String BfGNUMangler::Mangle(BfMethodInstance* methodInst) if (methodDef->mHasComptime) name += "`COMPTIME"; - if (((methodInst->GetOwner()->mTypeDef->IsGlobalsContainer()) && + if (((methodInst->GetOwner()->mTypeDef->IsGlobalsContainer()) && ((methodDef->mMethodType == BfMethodType_Ctor) || (methodDef->mMethodType == BfMethodType_Dtor) || (methodDef->mName == BF_METHODNAME_MARKMEMBERS_STATIC))) || - ((methodInst->mMethodDef->mDeclaringType->mPartialIdx != -1) && (methodInst->mMethodDef->mDeclaringType->IsExtension()) && - (!methodInst->mIsForeignMethodDef) && (!methodInst->mMethodDef->mIsExtern) && + ((methodInst->mMethodDef->mDeclaringType->mPartialIdx != -1) && (methodInst->mMethodDef->mDeclaringType->IsExtension()) && + (!methodInst->mIsForeignMethodDef) && (!methodInst->mMethodDef->mIsExtern) && ((!methodInst->mMethodDef->mIsOverride) || (methodDef->mName == BF_METHODNAME_MARKMEMBERS) || (methodDef->mMethodType == BfMethodType_Dtor)))) { auto declType = methodInst->mMethodDef->mDeclaringType; @@ -968,22 +968,22 @@ String BfGNUMangler::Mangle(BfMethodInstance* methodInst) methodName += methodInst->mMethodInstanceGroup->mOwner->mTypeDef->mProject->mName; } - if (prefixLen) - AddSizedString(name, methodName); - else + if (prefixLen) + AddSizedString(name, methodName); + else name += methodName; - + if (methodInst->GetNumGenericArguments() != 0) - { + { auto& methodGenericArguments = methodInst->mMethodInfoEx->mMethodGenericArguments; NameSubstitute nameSub(NameSubstitute::Kind_MethodName, methodInst); - nameSub.mExtendsIdx = (int)mangleContext.mSubstituteList.size() - 1; + nameSub.mExtendsIdx = (int)mangleContext.mSubstituteList.size() - 1; mangleContext.mSubstituteList.push_back(nameSub); name += 'I'; for (auto genericArg : methodGenericArguments) Mangle(mangleContext, name, genericArg); - name += 'E'; + name += 'E'; } else if (methodInst->mMethodDef->mGenericParams.size() != 0) { @@ -999,7 +999,7 @@ String BfGNUMangler::Mangle(BfMethodInstance* methodInst) if (isNameOpen) name += 'E'; - + if (methodInst->mMethodDef->mGenericParams.size() != 0) Mangle(mangleContext, name, methodInst->mReturnType); @@ -1010,8 +1010,8 @@ String BfGNUMangler::Mangle(BfMethodInstance* methodInst) if (doExplicitThis) // Explicit "_this" Mangle(mangleContext, name, typeInst->GetUnderlyingType()); - for (int paramIdx = 0; paramIdx < (int)methodInst->GetParamCount(); paramIdx++) - { + for (int paramIdx = 0; paramIdx < (int)methodInst->GetParamCount(); paramIdx++) + { BfType* paramType = methodInst->GetParamType(paramIdx); bool isConst = false; @@ -1035,20 +1035,20 @@ String BfGNUMangler::Mangle(BfMethodInstance* methodInst) } String BfGNUMangler::MangleMethodName(BfTypeInstance* type, const StringImpl& methodName) -{ +{ MangleContext mangleContext; mangleContext.mModule = type->mModule; - StringT<256> name = "_Z"; + StringT<256> name = "_Z"; auto typeInst = type->ToTypeInstance(); BF_ASSERT(typeInst != NULL); - + bool isNameOpen; - MangleTypeInst(mangleContext, name, typeInst, NULL, &isNameOpen); - AddSizedString(name, methodName); + MangleTypeInst(mangleContext, name, typeInst, NULL, &isNameOpen); + AddSizedString(name, methodName); if (isNameOpen) name += "E"; - name += "v"; + name += "v"; return name; } @@ -1061,11 +1061,11 @@ String BfGNUMangler::MangleStaticFieldName(BfTypeInstance* type, const StringImp auto typeDef = typeInst->mTypeDef; if ((typeDef->IsGlobalsContainer()) && (typeDef->mNamespace.IsEmpty())) return fieldName; - - StringT<256> name = "_Z"; + + StringT<256> name = "_Z"; bool isNameOpen; MangleTypeInst(mangleContext, name, typeInst, NULL, &isNameOpen); - AddSizedString(name, fieldName); + AddSizedString(name, fieldName); if (isNameOpen) name += "E"; return name; @@ -1076,7 +1076,7 @@ String BfGNUMangler::Mangle(BfFieldInstance* fieldInstance) StringT<256> name; MangleContext mangleContext; mangleContext.mModule = fieldInstance->mOwner->mModule; - + bool isCMangle = false; HandleCustomAttributes(fieldInstance->mCustomAttributes, fieldInstance->mOwner->mConstHolder, mangleContext.mModule, name, isCMangle, mangleContext.mCPPMangle); if (isCMangle) @@ -1117,12 +1117,12 @@ void BfMSMangler::AddGenericArgs(MangleContext& mangleContext, StringImpl& name, auto prevSubList = mangleContext.mSubstituteList; auto prevSubTypeList = mangleContext.mSubstituteTypeList; mangleContext.mSubstituteList.clear(); - + for (int genericIdx = numOuterGenericParams; genericIdx < (int)genericArgs.size(); genericIdx++) - Mangle(mangleContext, name, genericArgs[genericIdx]); - + Mangle(mangleContext, name, genericArgs[genericIdx]); + mangleContext.mSubstituteList = prevSubList; - mangleContext.mSubstituteTypeList = prevSubTypeList; + mangleContext.mSubstituteTypeList = prevSubTypeList; } void BfMSMangler::AddStr(MangleContext& mangleContext, StringImpl& name, const StringImpl& str) @@ -1176,7 +1176,7 @@ void BfMSMangler::AddTypeStart(MangleContext& mangleContext, StringImpl& name, B BF_ASSERT(type->mSize >= 0); // The enum size is supposed to be encoded, but VC always uses '4' - //name += "W"; + //name += "W"; //name += ('0' + type->mSize); name += "W4"; return; @@ -1195,7 +1195,7 @@ bool BfMSMangler::FindOrCreateNameSub(MangleContext& mangleContext, StringImpl& AddSubIdx(name, curMatchIdx); return true; } - } + } if (newNameSub.mKind == NameSubstitute::Kind_NamespaceAtom) { @@ -1205,7 +1205,7 @@ bool BfMSMangler::FindOrCreateNameSub(MangleContext& mangleContext, StringImpl& else if (newNameSub.mKind == NameSubstitute::Kind_TypeInstName) { if (mangleContext.mWantsGroupStart) - { + { AddTypeStart(mangleContext, name, newNameSub.mTypeInst); mangleContext.mWantsGroupStart = false; } @@ -1231,9 +1231,9 @@ bool BfMSMangler::FindOrCreateNameSub(MangleContext& mangleContext, StringImpl& else if ((newNameSub.mTypeInst->IsDelegateFromTypeRef()) || (newNameSub.mTypeInst->IsFunctionFromTypeRef())) { BF_ASSERT(newNameSub.mTypeInst->mTypeDef->mMethods[0]->mName == "Invoke"); - + auto delegateInfo = newNameSub.mTypeInst->GetDelegateInfo(); - + auto methodDef = newNameSub.mTypeInst->mTypeDef->mMethods[0]; if (newNameSub.mTypeInst->IsDelegate()) name += "?$delegate"; @@ -1250,9 +1250,9 @@ bool BfMSMangler::FindOrCreateNameSub(MangleContext& mangleContext, StringImpl& SizedArray typeVec; typeVec.push_back(BfNodeDynCast(methodDef->mReturnTypeRef)->mType); - + for (int paramIdx = 0; paramIdx < (int)methodDef->mParams.size(); paramIdx++) - { + { name += "_"; name += methodDef->mParams[paramIdx]->mName; if (methodDef->mParams[paramIdx]->mParamKind == BfParamKind_VarArgs) @@ -1265,14 +1265,14 @@ bool BfMSMangler::FindOrCreateNameSub(MangleContext& mangleContext, StringImpl& name += '@'; if (!typeVec.empty()) AddGenericArgs(mangleContext, name, typeVec); - name += '@'; + name += '@'; } else if (newNameSub.mTypeInst->IsBoxed()) { auto boxedType = (BfBoxedType*)newNameSub.mTypeInst; name += "?$Box@"; SizedArray typeVec; - typeVec.push_back(boxedType->GetModifiedElementType()); + typeVec.push_back(boxedType->GetModifiedElementType()); AddGenericArgs(mangleContext, name, typeVec); name += '@'; } @@ -1281,8 +1281,8 @@ bool BfMSMangler::FindOrCreateNameSub(MangleContext& mangleContext, StringImpl& auto typeDef = newNameSub.mTypeInst->mTypeDef; BfTypeInstance* genericTypeInst = NULL; - if (newNameSub.mTypeInst->IsGenericTypeInstance()) - genericTypeInst = (BfTypeInstance*)newNameSub.mTypeInst; + if (newNameSub.mTypeInst->IsGenericTypeInstance()) + genericTypeInst = (BfTypeInstance*)newNameSub.mTypeInst; int numOuterGenericParams = 0; if ((!mangleContext.mIsSafeMangle) && (typeDef->mOuterType != NULL)) @@ -1300,16 +1300,16 @@ bool BfMSMangler::FindOrCreateNameSub(MangleContext& mangleContext, StringImpl& if (genericTypeInst != NULL) { name += "?$"; - mangleContext.mWantsGroupStart = false; + mangleContext.mWantsGroupStart = false; } - -// name += *typeDef->mName->mString; + +// name += *typeDef->mName->mString; // if ((typeDef->mIsDelegate) && (newNameSub.mTypeInst->IsClosure())) // { // auto closureType = (BfClosureType*)newNameSub.mTypeInst; // if (!closureType->mCreatedTypeDef) // name += closureType->mNameAdd; -// } +// } if (newNameSub.mTypeInst->IsClosure()) { @@ -1330,11 +1330,11 @@ bool BfMSMangler::FindOrCreateNameSub(MangleContext& mangleContext, StringImpl& name += '@'; } } - } + } else if (newNameSub.mKind == BfGNUMangler::NameSubstitute::Kind_GenericParam) { name += "U"; // Struct - auto genericParamType = (BfGenericParamType*)newNameSub.mType; + auto genericParamType = (BfGenericParamType*)newNameSub.mType; if (genericParamType->mGenericParamKind == BfGenericParamKind_Method) name += "_M"; else @@ -1345,14 +1345,14 @@ bool BfMSMangler::FindOrCreateNameSub(MangleContext& mangleContext, StringImpl& name += '@'; name += '@'; } - + mangleContext.mSubstituteList.push_back(newNameSub); return false; } void BfMSMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfTypeInstance* typeInstance, bool isAlreadyStarted, bool isOuterType) -{ +{ BfTypeInstance* genericTypeInst = NULL; if (typeInstance->IsGenericTypeInstance()) { @@ -1365,7 +1365,7 @@ void BfMSMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfTypeI { if ((hasNamespace) || (typeDef->mOuterType != NULL)) { - AddTypeStart(mangleContext, name, typeInstance); + AddTypeStart(mangleContext, name, typeInstance); } else { @@ -1377,14 +1377,14 @@ void BfMSMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfTypeI if (!typeDef->IsGlobalsContainer()) FindOrCreateNameSub(mangleContext, name, NameSubstitute(BfMangler::NameSubstitute::Kind_TypeInstName, typeInstance)); - mangleContext.mWantsGroupStart = false; + mangleContext.mWantsGroupStart = false; auto useModule = typeInstance->mModule; if (useModule == NULL) useModule = mangleContext.mModule; - + if ((typeDef->mOuterType != NULL) && (!typeInstance->IsBoxed())) - { + { if (mangleContext.mIsSafeMangle) { auto outerType = typeDef->mOuterType; @@ -1401,7 +1401,7 @@ void BfMSMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfTypeI auto outerType = unreifiedModule->GetOuterType(typeInstance); if (outerType != NULL) Mangle(mangleContext, name, outerType, true, true); - else + else useModule->Fail("Failed to mangle name in BfMSMangler::Mangle"); } } @@ -1501,7 +1501,7 @@ void BfMSMangler::AddPrefix(MangleContext& mangleContext, StringImpl& name, int } else { - // Applies to last-added one + // Applies to last-added one subIdx = (int)mangleContext.mSubstituteList.size() - 1; BF_ASSERT(isdigit(startChar) || (startChar == 'N') || (startChar == 'P') || (startChar == 'R')); } @@ -1517,7 +1517,7 @@ void BfMSMangler::AddPrefix(MangleContext& mangleContext, StringImpl& name, int } void BfMSMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType* type, bool useTypeList, bool isConst) -{ +{ bool isLongPrim = false; if (type->IsPrimitiveType()) @@ -1536,7 +1536,7 @@ void BfMSMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType* } return; case BfTypeCode_None: - name += "X"; return; + name += "X"; return; case BfTypeCode_Int8: name += "C"; return; case BfTypeCode_UInt8: @@ -1548,7 +1548,7 @@ void BfMSMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType* case BfTypeCode_Int32: name += "H"; return; case BfTypeCode_UInt32: - name += "I"; return; + name += "I"; return; case BfTypeCode_Char8: name += "D"; return; case BfTypeCode_Char16: @@ -1559,10 +1559,10 @@ void BfMSMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType* name += "N"; return; case BfTypeCode_Int64: case BfTypeCode_UInt64: - case BfTypeCode_Boolean: - case BfTypeCode_Char32: + case BfTypeCode_Boolean: + case BfTypeCode_Char32: isLongPrim = true; - break; + break; case BfTypeCode_IntPtr: if ((primType->mSize == 4) && (mangleContext.mCCompat)) { @@ -1603,9 +1603,9 @@ void BfMSMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType* default: name += "?"; return; - } - } - + } + } + if (useTypeList) { for (int checkIdx = 0; checkIdx < (int)mangleContext.mSubstituteTypeList.size(); checkIdx++) @@ -1643,7 +1643,7 @@ void BfMSMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType* else if (mangleContext.mCCompat) name += "_J"; else - name += "Tint@@"; + name += "Tint@@"; break; case BfTypeCode_Char32: name += "_U"; break; @@ -1665,7 +1665,7 @@ void BfMSMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType* else if (((type->IsGenericTypeInstance()) || (type->IsComposite()) || (type->IsEnum())) && (mangleContext.mInRet)) name += "?A"; - Mangle(mangleContext, name, typeInstance, false); + Mangle(mangleContext, name, typeInstance, false); } else if (type->IsGenericParam()) { @@ -1680,12 +1680,12 @@ void BfMSMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType* if (mangleContext.mIs64Bit) name += "PE"; else - name += "P"; + name += "P"; if (isConst) name += "B"; else name += "A"; - Mangle(mangleContext, name, pointerType->mElementType); + Mangle(mangleContext, name, pointerType->mElementType); } else if (type->IsRef()) { @@ -1698,11 +1698,11 @@ void BfMSMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType* else name += "A"; if (refType->mRefKind == BfRefType::RefKind_Mut) - name += "mut$"; + name += "mut$"; else if (refType->mRefKind == BfRefType::RefKind_Out) name += "out$"; Mangle(mangleContext, name, refType->mElementType); - } + } else if (type->IsModifiedTypeType()) { auto retType = (BfModifiedTypeType*)type; @@ -1734,12 +1734,12 @@ void BfMSMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType* } else { - // We can't use MS mangling of "_O" because it isn't size-specific + // We can't use MS mangling of "_O" because it isn't size-specific auto arrType = (BfSizedArrayType*)type; //name += StrFormat("arr_%d$", arrType->mSize); //Mangle(mangleContext, name, arrType->mElementType); - name += "?$_ARRAY@"; + name += "?$_ARRAY@"; Mangle(mangleContext, name, arrType->mElementType); MangleConst(mangleContext, name, arrType->mElementCount); name += '@'; @@ -1747,9 +1747,9 @@ void BfMSMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType* } else if (type->IsMethodRef()) { - auto methodRefType = (BfMethodRefType*)type; + auto methodRefType = (BfMethodRefType*)type; name += "Tmref_"; - + StringT<128> mangleName; BfMethodInstance* methodInstance = methodRefType->mMethodRef; if (methodInstance == NULL) @@ -1783,10 +1783,10 @@ void BfMSMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType* } // if (methodInstance->mIsAutocompleteMethod) -// name += "AUTOCOMPLETE"; -// +// name += "AUTOCOMPLETE"; +// // String mangleAdd = Mangle(mangleContext.mIs64Bit, methodInstance); -// +// // auto module = methodInstance->GetOwner()->mModule; // if (module->mCompiler->mIsResolveOnly) // { @@ -1799,19 +1799,19 @@ void BfMSMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType* // Val128 val128 = Hash128(mangleAdd.c_str(), (int)mangleAdd.length()); // name += HashEncode128(val128); // } - name += "@@"; + name += "@@"; } else if (type->IsConstExprValue()) { BfConstExprValueType* constExprValueType = (BfConstExprValueType*)type; int64 val = constExprValueType->mValue.mInt64; - if ((!constExprValueType->mType->IsPrimitiveType()) || + if ((!constExprValueType->mType->IsPrimitiveType()) || (((BfPrimitiveType*)constExprValueType->mType)->mTypeDef->mTypeCode != BfTypeCode_IntPtr)) { Mangle(mangleContext, name, constExprValueType->mType); name += "$"; } - MangleConst(mangleContext, name, val); + MangleConst(mangleContext, name, val); if (constExprValueType->mValue.mTypeCode == BfTypeCode_Let) name += "Undef"; } @@ -1819,7 +1819,7 @@ void BfMSMangler::Mangle(MangleContext& mangleContext, StringImpl& name, BfType* { BF_ASSERT("Unhandled"); } - + if ((useTypeList) && (!mangleContext.mInRet) && ((int)mangleContext.mSubstituteTypeList.size() < 10)) mangleContext.mSubstituteTypeList.push_back(type); } @@ -1841,7 +1841,7 @@ void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfType* type, BfModule* mangleContext.mModule = module; auto typeInst = type->ToTypeInstance(); if ((typeInst != NULL) && (typeInst->mModule != NULL)) - mangleContext.mModule = typeInst->mModule; + mangleContext.mModule = typeInst->mModule; if (typeInst != NULL) Mangle(mangleContext, name, typeInst, true); else @@ -1854,7 +1854,7 @@ void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfMethodInstance* metho { static int mangleIdx = 0; mangleIdx++; - + int startNameLen = name.mLength; if ((methodInst->mMethodDef->mCLink) && (!methodInst->mMangleWithIdx)) { @@ -1865,20 +1865,20 @@ void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfMethodInstance* metho auto methodDef = methodInst->mMethodDef; auto methodDeclaration = BfNodeDynCastExact(methodDef->mMethodDeclaration); auto typeInst = methodInst->GetOwner(); - auto typeDef = typeInst->mTypeDef; - + auto typeDef = typeInst->mTypeDef; + MangleContext mangleContext; mangleContext.mIs64Bit = is64Bit; - mangleContext.mModule = methodInst->GetOwner()->mModule; + mangleContext.mModule = methodInst->GetOwner()->mModule; if (methodInst->mCallingConvention != BfCallingConvention_Unspecified) mangleContext.mCCompat = true; - bool isCMangle = false; + bool isCMangle = false; HandleCustomAttributes(methodInst->GetCustomAttributes(), typeInst->mConstHolder, mangleContext.mModule, name, isCMangle, mangleContext.mCPPMangle); if (isCMangle) name += methodInst->mMethodDef->mName; if (name.mLength > startNameLen) return; - + name += '?'; if (methodInst->GetNumGenericArguments() != 0) @@ -2020,7 +2020,7 @@ void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfMethodInstance* metho } switch (operatorDef->mOperatorDeclaration->mAssignOp) - { + { case BfAssignmentOp_Assign: methodName += "__a__"; break; @@ -2061,7 +2061,7 @@ void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfMethodInstance* metho if (!methodName.empty()) { AddStr(mangleContext, name, methodName); - } + } } /*else if ((methodDef->mMethodType == BfMethodType_Ctor) && (!methodDef->mIsStatic)) { @@ -2078,7 +2078,7 @@ void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfMethodInstance* metho else if (methodInst->GetNumGenericArguments() != 0) { AddStr(mangleContext, name, methodDef->mName); - AddGenericArgs(mangleContext, name, methodInst->mMethodInfoEx->mMethodGenericArguments); + AddGenericArgs(mangleContext, name, methodInst->mMethodInfoEx->mMethodGenericArguments); name += '@'; } else @@ -2086,13 +2086,13 @@ void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfMethodInstance* metho if ((!mangleContext.mCPPMangle) && (!methodDef->mIsMutating) && (!methodDef->mIsStatic) && (methodInst->GetOwner()->IsValueType())) AddStr(mangleContext, name, methodDef->mName + "__im"); else - AddStr(mangleContext, name, methodDef->mName); + AddStr(mangleContext, name, methodDef->mName); } - if (((methodInst->GetOwner()->mTypeDef->IsGlobalsContainer()) && + if (((methodInst->GetOwner()->mTypeDef->IsGlobalsContainer()) && ((methodDef->mMethodType == BfMethodType_Ctor) || (methodDef->mMethodType == BfMethodType_Dtor) || (methodDef->mName == BF_METHODNAME_MARKMEMBERS_STATIC))) || - ((methodInst->mMethodDef->mDeclaringType->mPartialIdx != -1) && (methodInst->mMethodDef->mDeclaringType->IsExtension()) && - (!methodInst->mIsForeignMethodDef) && (!methodInst->mMethodDef->mIsExtern) && + ((methodInst->mMethodDef->mDeclaringType->mPartialIdx != -1) && (methodInst->mMethodDef->mDeclaringType->IsExtension()) && + (!methodInst->mIsForeignMethodDef) && (!methodInst->mMethodDef->mIsExtern) && ((!methodInst->mMethodDef->mIsOverride) || (methodDef->mName == BF_METHODNAME_MARKMEMBERS) || (methodDef->mMethodType == BfMethodType_Dtor)))) { auto declType = methodInst->mMethodDef->mDeclaringType; @@ -2100,9 +2100,9 @@ void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfMethodInstance* metho auto declProject = declType->mProject; bool addProjectName = (declProject != typeInst->mTypeDef->mProject); bool addIndex = true; - + if (typeInst->mTypeDef->IsGlobalsContainer()) - { + { addProjectName = true; if ((methodInst->mCallingConvention == BfCallingConvention_Cdecl) || @@ -2110,9 +2110,9 @@ void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfMethodInstance* metho { addProjectName = false; addIndex = false; - } + } } - + if (addProjectName) { name += declProject->mName; @@ -2129,7 +2129,7 @@ void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfMethodInstance* metho if (methodDef->mCheckedKind == BfCheckedKind_Checked) name += "CHK$"; else if (methodDef->mCheckedKind == BfCheckedKind_Unchecked) - name += "UCHK$"; + name += "UCHK$"; if (methodDef->mHasComptime) name += "COMPTIME$"; @@ -2145,7 +2145,7 @@ void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfMethodInstance* metho Mangle(mangleContext, name, methodInst->GetForeignType(), true); if (methodInst->GetExplicitInterface() != NULL) Mangle(mangleContext, name, methodInst->GetExplicitInterface(), true); - + /// { // Only use CCompat for params, not for the owning type name - unless we're doing an explicit CPP mangle @@ -2177,14 +2177,14 @@ void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfMethodInstance* metho if ((methodDef->mIsVirtual) && (!methodDef->mIsOverride)) attrib += 4; - + name += attrib; auto bfSystem = methodInst->GetOwner()->mModule->mSystem; if ((!methodDef->mIsStatic) && (!doExplicitThis)) - { + { /*char cvQualifier = 'A'; - if (mangleContext.mIs64Bit) + if (mangleContext.mIs64Bit) cvQualifier = 'E'; name += cvQualifier;*/ if (mangleContext.mIs64Bit) @@ -2192,7 +2192,7 @@ void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfMethodInstance* metho char qualifier = 'A'; // const / volatile name += qualifier; - } + } auto callingConvention = mangleContext.mModule->GetIRCallingConvention(methodInst); @@ -2229,7 +2229,7 @@ void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfMethodInstance* metho mangleContext.mInArgs = true; if (doExplicitThis) - { + { Mangle(mangleContext, name, typeInst->GetUnderlyingType(), true); } for (auto& param : methodInst->mParams) @@ -2237,7 +2237,7 @@ void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfMethodInstance* metho bool isConst = false; if ((param.mParamDefIdx >= 0) && (methodDeclaration != NULL) && (param.mParamDefIdx < methodDeclaration->mParams.mSize)) { - auto paramDecl = methodDeclaration->mParams[param.mParamDefIdx]; + auto paramDecl = methodDeclaration->mParams[param.mParamDefIdx]; HandleParamCustomAttributes(paramDecl->mAttributes, false, isConst); } @@ -2247,7 +2247,7 @@ void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfMethodInstance* metho } name += 'Z'; - + bool wantLog = false; if (wantLog) { @@ -2258,8 +2258,7 @@ void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfMethodInstance* metho String demangled = BfDemangler::Demangle(name, DbgLanguage_Beef); BfLog2(" Demangled %d: %s\n", mangleIdx, demangled.c_str()); } - } - + } } void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfFieldInstance* fieldInstance) @@ -2278,41 +2277,41 @@ void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfFieldInstance* fieldI BF_ASSERT(fieldDef->mIsStatic); MangleContext mangleContext; mangleContext.mIs64Bit = is64Bit; - mangleContext.mModule = fieldInstance->mOwner->mModule; + mangleContext.mModule = fieldInstance->mOwner->mModule; - bool isCMangle = false; + bool isCMangle = false; HandleCustomAttributes(fieldInstance->mCustomAttributes, fieldInstance->mOwner->mConstHolder, mangleContext.mModule, name, isCMangle, mangleContext.mCPPMangle); if (isCMangle) name += fieldInstance->GetFieldDef()->mName; if (!name.IsEmpty()) return; - + name += '?'; - AddStr(mangleContext, name, fieldDef->mName); + AddStr(mangleContext, name, fieldDef->mName); Mangle(mangleContext, name, fieldInstance->mOwner, true); name += '2'; //TODO: Don't always mark as 'public' Mangle(mangleContext, name, fieldInstance->mResolvedType); - name += ('A' + /*(fieldDef->mIsConst ? 1 : 0) +*/ (fieldDef->mIsVolatile ? 2 : 0)); + name += ('A' + /*(fieldDef->mIsConst ? 1 : 0) +*/ (fieldDef->mIsVolatile ? 2 : 0)); } void BfMSMangler::MangleMethodName(StringImpl& name, bool is64Bit, BfTypeInstance* type, const StringImpl& methodName) { MangleContext mangleContext; mangleContext.mIs64Bit = is64Bit; - mangleContext.mModule = type->GetModule(); + mangleContext.mModule = type->GetModule(); name += '?'; - AddStr(mangleContext, name, methodName); - Mangle(mangleContext, name, type, true); - name += "SAXXZ"; + AddStr(mangleContext, name, methodName); + Mangle(mangleContext, name, type, true); + name += "SAXXZ"; } void BfMSMangler::MangleStaticFieldName(StringImpl& name, bool is64Bit, BfTypeInstance* owner, const StringImpl& fieldName, BfType* fieldType) -{ +{ MangleContext mangleContext; mangleContext.mIs64Bit = is64Bit; - mangleContext.mModule = owner->GetModule(); + mangleContext.mModule = owner->GetModule(); name += '?'; - AddStr(mangleContext, name, fieldName); + AddStr(mangleContext, name, fieldName); Mangle(mangleContext, name, owner, true); //name += "@@"; name += '2'; // public @@ -2320,7 +2319,7 @@ void BfMSMangler::MangleStaticFieldName(StringImpl& name, bool is64Bit, BfTypeIn name += 'H'; else Mangle(mangleContext, name, fieldType); - name += "A"; // static + name += "A"; // static } ////////////////////////////////////////////////////////////////////////// @@ -2331,7 +2330,7 @@ String BfSafeMangler::Mangle(BfType* type, BfModule* module) mangleContext.mIs64Bit = true; mangleContext.mModule = module; mangleContext.mIsSafeMangle = true; - auto typeInst = type->ToTypeInstance(); + auto typeInst = type->ToTypeInstance(); String name; if (typeInst != NULL) BfMSMangler::Mangle(mangleContext, name, typeInst, true); @@ -2359,9 +2358,9 @@ void BfMangler::Mangle(StringImpl& outStr, MangleKind mangleKind, BfMethodInstan } void BfMangler::Mangle(StringImpl& outStr, MangleKind mangleKind, BfFieldInstance* fieldInstance) -{ +{ if (mangleKind == BfMangler::MangleKind_GNU) - { + { outStr += BfGNUMangler::Mangle(fieldInstance); } else @@ -2388,7 +2387,7 @@ void BfMangler::HandleCustomAttributes(BfCustomAttributes* customAttributes, BfI { if (customAttributes == NULL) return; - + auto linkNameAttr = customAttributes->Get(module->mCompiler->mLinkNameAttributeTypeDef); if (linkNameAttr != NULL) { @@ -2402,7 +2401,7 @@ void BfMangler::HandleCustomAttributes(BfCustomAttributes* customAttributes, BfI if (constant != NULL) { if (constant->mInt32 == 1) // C - { + { isCMangle = true; } else if (constant->mInt32 == 2) // CPP @@ -2411,7 +2410,7 @@ void BfMangler::HandleCustomAttributes(BfCustomAttributes* customAttributes, BfI } } } - } + } } void BfMangler::HandleParamCustomAttributes(BfAttributeDirective* attributes, bool isReturn, bool& isConst) @@ -2427,4 +2426,4 @@ void BfMangler::HandleParamCustomAttributes(BfAttributeDirective* attributes, bo attributes = attributes->mNextAttribute; } -} +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfMangler.h b/IDEHelper/Compiler/BfMangler.h index c3f0794e..5b362d2f 100644 --- a/IDEHelper/Compiler/BfMangler.h +++ b/IDEHelper/Compiler/BfMangler.h @@ -33,7 +33,7 @@ public: Kind_MethodName, Kind_Prefix, Kind_PrimitivePrefix, - Kind_GenericParam + Kind_GenericParam }; public: @@ -54,7 +54,7 @@ public: BfTypeInstance* mTypeInst; BfMethodInstance* mMethodInstance; const char* mPrefix; - }; + }; public: NameSubstitute(Kind kind, void* param) @@ -90,7 +90,7 @@ public: class BfGNUMangler : public BfMangler { -public: +public: class MangleContext { public: @@ -111,22 +111,22 @@ public: mPrefixObjectPointer = false; } }; - + static int ParseSubIdx(StringImpl& name, int strIdx); static void AddSubIdx(StringImpl& name, int strIdx); static void AddSizedString(StringImpl& name, const StringImpl& addStr); static BfTypeCode GetPrimTypeAt(MangleContext& mangleContext, StringImpl& name, int strIdx); - static void AddPrefix(MangleContext& mangleContext, StringImpl& name, int startIdx, const char* prefix); + static void AddPrefix(MangleContext& mangleContext, StringImpl& name, int startIdx, const char* prefix); static void FindOrCreateNameSub(MangleContext& mangleContext, StringImpl& name, const NameSubstitute& newNameSub, int& curMatchIdx, bool& matchFailed); static void FindOrCreateNameSub(MangleContext& mangleContext, StringImpl& name, BfTypeInstance* typeInst, int& curMatchIdx, bool& matchFailed); - static void FindOrCreateNameSub(MangleContext& mangleContext, StringImpl& name, const NameSubstitute& newNameSub); + static void FindOrCreateNameSub(MangleContext& mangleContext, StringImpl& name, const NameSubstitute& newNameSub); public: static void MangleTypeInst(MangleContext& mangleContext, StringImpl& name, BfTypeInstance* typeInst, BfTypeInstance* postfixTypeInst = NULL, bool* isEndOpen = NULL); static void Mangle(MangleContext& mangleContext, StringImpl& name, BfType* type, BfType* postfixType = NULL, bool isConst = false); static String Mangle(BfType* type, BfModule* module = NULL); - static String Mangle(BfMethodInstance* methodRef); + static String Mangle(BfMethodInstance* methodRef); static String MangleMethodName(BfTypeInstance* type, const StringImpl& methodName); static String Mangle(BfFieldInstance* methodRef); static String MangleStaticFieldName(BfTypeInstance* type, const StringImpl& fieldName); @@ -138,12 +138,12 @@ public: class MangleContext { public: - bool mIsSafeMangle; + bool mIsSafeMangle; BfModule* mModule; bool mCCompat; bool mCPPMangle; - bool mIs64Bit; + bool mIs64Bit; SizedArray mSubstituteList; SizedArray mSubstituteTypeList; @@ -154,7 +154,7 @@ public: public: MangleContext() { - mIsSafeMangle = false; + mIsSafeMangle = false; mModule = NULL; mCCompat = false; mIs64Bit = false; @@ -164,11 +164,11 @@ public: mInRet = false; } - BfModule* GetUnreifiedModule(); + BfModule* GetUnreifiedModule(); }; static void AddGenericArgs(MangleContext& mangleContext, StringImpl& name, const SizedArrayImpl& genericArgs, int numOuterGenericParams = 0); - + static void AddStr(MangleContext& mangleContext, StringImpl& name, const StringImpl& str); static void Mangle(MangleContext& mangleContext, StringImpl& name, BfType* type, bool useTypeList = false, bool isConst = false); static void Mangle(MangleContext& mangleContext, StringImpl& name, BfTypeInstance* typeInst, bool isAlreadyStarted, bool isOuterType = false); @@ -176,8 +176,8 @@ public: void AddPrefix(MangleContext & mangleContext, StringImpl& name, int startIdx, const char * prefix); - static void AddSubIdx(StringImpl& name, int strIdx); - static void AddTypeStart(MangleContext & mangleContext, StringImpl& name, BfType* type); + static void AddSubIdx(StringImpl& name, int strIdx); + static void AddTypeStart(MangleContext & mangleContext, StringImpl& name, BfType* type); static bool FindOrCreateNameSub(MangleContext& mangleContext, StringImpl& name, const NameSubstitute& newNameSub); public: @@ -188,7 +188,7 @@ public: static void MangleStaticFieldName(StringImpl& outStr, bool is64Bit, BfTypeInstance* type, const StringImpl& fieldName, BfType* fieldType = NULL); }; -// A "safe mangle" is used for reconnecting deleted types to their previous id. We make sure we never force a +// A "safe mangle" is used for reconnecting deleted types to their previous id. We make sure we never force a // PopulateType with this kind of mangle, as referenced types may be deleted and marked as undefined class BfSafeMangler : public BfMSMangler { diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index ac4677fe..19b4e770 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -40,7 +40,7 @@ USING_NS_BF; ////////////////////////////////////////////////////////////////////////// void BfLocalVariable::Init() -{ +{ if (mResolvedType->IsValuelessType()) { mAssignedKind = BfLocalVarAssignKind_Unconditional; @@ -79,13 +79,13 @@ BfLocalMethod::~BfLocalMethod() { BfLogSys(mSystem, "~BfLocalMethod %p\n", this); if (mMethodDeclaration != NULL) - { + { mSource->mRefCount--; BF_ASSERT(mSource->mRefCount >= 0); } - + delete mMethodInstanceGroup; - delete mMethodDef; + delete mMethodDef; } void BfLocalMethod::Dispose() @@ -94,7 +94,7 @@ void BfLocalMethod::Dispose() return; if (mMethodInstanceGroup->mDefault != NULL) mMethodInstanceGroup->mDefault->Dispose(); - + if (mMethodInstanceGroup->mMethodSpecializationMap != NULL) { for (auto& kv : *mMethodInstanceGroup->mMethodSpecializationMap) @@ -106,17 +106,17 @@ void BfDeferredLocalAssignData::ExtendFrom(BfDeferredLocalAssignData* outerLocal { mIsChained = doChain; if (outerLocalAssignData == NULL) - return; + return; mChainedAssignData = outerLocalAssignData; - if (!doChain) + if (!doChain) { outerLocalAssignData->BreakExtendChain(); - mAssignedLocals = outerLocalAssignData->mAssignedLocals; + mAssignedLocals = outerLocalAssignData->mAssignedLocals; } mVarIdBarrier = outerLocalAssignData->mVarIdBarrier; } -// The "extend chain" is broken when we have a conditional where the variable may not be defined after the block. +// The "extend chain" is broken when we have a conditional where the variable may not be defined after the block. // IE: "a" will be defined after the following, but "b" will not necessarily be defined. // if ((GetValue(out a)) && (GetValue(out b)) {} void BfDeferredLocalAssignData::BreakExtendChain() @@ -127,13 +127,13 @@ void BfDeferredLocalAssignData::BreakExtendChain() if (mChainedAssignData == NULL) return; mChainedAssignData->BreakExtendChain(); - mAssignedLocals = mChainedAssignData->mAssignedLocals; + mAssignedLocals = mChainedAssignData->mAssignedLocals; } void BfDeferredLocalAssignData::SetIntersection(const BfDeferredLocalAssignData& otherLocalAssignData) -{ +{ BreakExtendChain(); - + if (otherLocalAssignData.mLeftBlockUncond) { // Intersection of self and infinity is self @@ -187,7 +187,7 @@ void BfDeferredLocalAssignData::SetIntersection(const BfDeferredLocalAssignData& } mHadFallthrough = mHadFallthrough && otherLocalAssignData.mHadFallthrough; - mLeftBlockUncond = mLeftBlockUncond && otherLocalAssignData.mLeftBlockUncond; + mLeftBlockUncond = mLeftBlockUncond && otherLocalAssignData.mLeftBlockUncond; } void BfDeferredLocalAssignData::Validate() const @@ -204,10 +204,10 @@ void BfDeferredLocalAssignData::SetUnion(const BfDeferredLocalAssignData& otherL Validate(); otherLocalAssignData.Validate(); - + auto otherItr = otherLocalAssignData.mAssignedLocals.begin(); while (otherItr != otherLocalAssignData.mAssignedLocals.end()) - { + { if (!mAssignedLocals.Contains(*otherItr)) mAssignedLocals.push_back(*otherItr); ++otherItr; @@ -217,15 +217,15 @@ void BfDeferredLocalAssignData::SetUnion(const BfDeferredLocalAssignData& otherL } BfMethodState::~BfMethodState() -{ - BF_ASSERT(mPendingNullConditional == NULL); +{ + BF_ASSERT(mPendingNullConditional == NULL); if (mPrevMethodState != NULL) { BF_ASSERT(mCurAccessId == 1); BF_ASSERT(mCurLocalVarId <= 0); } - + for (auto local : mLocals) { if (local->mIsBumpAlloc) @@ -254,13 +254,13 @@ BfMethodState* BfMethodState::GetMethodStateForLocal(BfLocalVariable* localVar) } void BfMethodState::LocalDefined(BfLocalVariable* localVar, int fieldIdx, BfLocalVarAssignKind assignKind, bool isFromDeferredAssignData) -{ +{ auto localVarMethodState = GetMethodStateForLocal(localVar); if (localVarMethodState != this) { return; } - + if (localVar->mAssignedKind == BfLocalVarAssignKind_None) { BfDeferredLocalAssignData* ifDeferredLocalAssignData = NULL; @@ -273,15 +273,15 @@ void BfMethodState::LocalDefined(BfLocalVariable* localVar, int fieldIdx, BfLoca (!deferredLocalAssignData->mIfMayBeSkipped)) { ifDeferredLocalAssignData = deferredLocalAssignData; - deferredLocalAssignData = deferredLocalAssignData->mChainedAssignData; + deferredLocalAssignData = deferredLocalAssignData->mChainedAssignData; } - while ((deferredLocalAssignData != NULL) && + while ((deferredLocalAssignData != NULL) && ((deferredLocalAssignData->mIsChained) || (deferredLocalAssignData->mIsUnconditional))) deferredLocalAssignData = deferredLocalAssignData->mChainedAssignData; if (assignKind == BfLocalVarAssignKind_None) - assignKind = ((deferredLocalAssignData != NULL) && (deferredLocalAssignData->mLeftBlock)) ? BfLocalVarAssignKind_Conditional : BfLocalVarAssignKind_Unconditional; + assignKind = ((deferredLocalAssignData != NULL) && (deferredLocalAssignData->mLeftBlock)) ? BfLocalVarAssignKind_Conditional : BfLocalVarAssignKind_Unconditional; if (localVar->mAssignedKind >= assignKind) { @@ -292,7 +292,7 @@ void BfMethodState::LocalDefined(BfLocalVariable* localVar, int fieldIdx, BfLoca if (fieldIdx >= 0) { localVar->mUnassignedFieldFlags &= ~((int64)1 << fieldIdx); - + if (localVar->mResolvedType->IsUnion()) { // We need more 'smarts' to determine assignment of unions @@ -314,7 +314,7 @@ void BfMethodState::LocalDefined(BfLocalVariable* localVar, int fieldIdx, BfLoca { BF_ASSERT(deferredLocalAssignData->mVarIdBarrier != -1); - BfAssignedLocal defineVal = {localVar, fieldIdx, assignKind}; + BfAssignedLocal defineVal = {localVar, fieldIdx, assignKind}; if (!deferredLocalAssignData->Contains(defineVal)) deferredLocalAssignData->mAssignedLocals.push_back(defineVal); @@ -347,11 +347,11 @@ void BfMethodState::ApplyDeferredLocalAssignData(const BfDeferredLocalAssignData hadAssignment = true; } if (!hadAssignment) - { + { LocalDefined(localDef); } } - } + } } else { @@ -372,8 +372,8 @@ void BfMethodState::Reset() void BfAmbiguityContext::Add(int id, BfTypeInterfaceEntry* interfaceEntry, int methodIdx, BfMethodInstance* candidateA, BfMethodInstance* candidateB) { Entry* entry = NULL; - - if (mEntries.TryAdd(id, NULL, &entry)) + + if (mEntries.TryAdd(id, NULL, &entry)) { entry->mInterfaceEntry = interfaceEntry; entry->mMethodIdx = methodIdx; @@ -385,7 +385,7 @@ void BfAmbiguityContext::Add(int id, BfTypeInterfaceEntry* interfaceEntry, int m } void BfAmbiguityContext::Remove(int id) -{ +{ mEntries.Remove(id); } @@ -548,7 +548,7 @@ public: else if (auto arrayTypeRef = BfNodeDynCast(objCreateExpr->mTypeRef)) { isArrayAlloc = true; - + bool handled = false; if (auto dotTypeRef = BfNodeDynCast(arrayTypeRef->mElementType)) @@ -564,7 +564,7 @@ public: handled = true; } } - + if (!handled) { origResolvedTypeRef = mModule->ResolveTypeRef(arrayTypeRef->mElementType); @@ -621,7 +621,7 @@ public: } dimLengthVals.push_back(dimLength.mValue); } - } + } if (!isRawArrayAlloc) arrayType = mModule->CreateArrayType(origResolvedTypeRef, dimensions); @@ -716,7 +716,7 @@ public: if (arrayType == NULL) arrayType = mModule->CreateArrayType(resultType, 1); - // Array is a special case where the total size isn't aligned with mAlign + // Array is a special case where the total size isn't aligned with mAlign // since we add arbitrary elements to the end without padding the end to align EmitAppendAlign(arrayType->mAlign, resultType->mAlign); curAlign = arrayType->mAlign; @@ -772,16 +772,16 @@ public: calcAppendArgs.RemoveRange(0, 2); // Remove 'this' and 'appendIdx' auto calcAppendMethodModule = mModule->GetMethodInstanceAtIdx(bindResult.mMethodInstance->GetOwner(), bindResult.mMethodInstance->mMethodDef->mIdx + 1, BF_METHODNAME_CALCAPPEND); - + auto subDependSize = mModule->TryConstCalcAppend(calcAppendMethodModule.mMethodInstance, calcAppendArgs); if (calcAppendMethodModule.mMethodInstance->mAppendAllocAlign > 0) - { + { EmitAppendAlign(calcAppendMethodModule.mMethodInstance->mAppendAllocAlign); BF_ASSERT(calcAppendMethodModule.mMethodInstance->mEndingAppendAllocAlign > -1); mModule->mCurMethodState->mCurAppendAlign = BF_MAX(calcAppendMethodModule.mMethodInstance->mEndingAppendAllocAlign, 0); } - curAlign = std::max(curAlign, (int)calcAppendMethodModule.mMethodInstance->mAppendAllocAlign); + curAlign = std::max(curAlign, (int)calcAppendMethodModule.mMethodInstance->mAppendAllocAlign); if ((!subDependSize) && (!mConstAccum)) { BF_ASSERT(calcAppendMethodModule.mFunc); @@ -795,7 +795,7 @@ public: mFailed = true; } } - } + } if (sizeValue) { @@ -816,7 +816,7 @@ public: auto addedVal = mModule->mBfIRBuilder->CreateAdd(sizeValue, prevVal); mModule->mBfIRBuilder->CreateAlignedStore(addedVal, accumValuePtr, intPtrType->mAlign); } - } + } } } } @@ -837,10 +837,10 @@ public: if (varDecl->mNameNode != NULL) { - BfLocalVariable* localDef = new BfLocalVariable(); + BfLocalVariable* localDef = new BfLocalVariable(); localDef->mName = varDecl->mNameNode->ToString(); - localDef->mNameNode = BfNodeDynCast(varDecl->mNameNode); - localDef->mResolvedType = mModule->GetPrimitiveType(BfTypeCode_None); + localDef->mNameNode = BfNodeDynCast(varDecl->mNameNode); + localDef->mResolvedType = mModule->GetPrimitiveType(BfTypeCode_None); localDef->mIsReadOnly = true; localDef->mParamFailed = true; localDef->mReadFromId = 0; @@ -897,8 +897,8 @@ public: BfModule* gLastCreatedModule = NULL; -BfModule::BfModule(BfContext* context, const StringImpl& moduleName) -{ +BfModule::BfModule(BfContext* context, const StringImpl& moduleName) +{ BfLogSys(context->mSystem, "BfModule::BFModule %p %s\n", this, moduleName.c_str()); gLastCreatedModule = this; @@ -918,34 +918,34 @@ BfModule::BfModule(BfContext* context, const StringImpl& moduleName) mBfIRBuilder = NULL; mWantsIRIgnoreWrites = false; mModuleOptions = NULL; - mLastUsedRevision = -1; + mLastUsedRevision = -1; mUsedSlotCount = -1; - + mIsReified = true; mGeneratesCode = true; mReifyQueued = false; mIsSpecialModule = false; mIsComptimeModule = false; - mIsScratchModule = false; - mIsSpecializedMethodModuleRoot = false; // There may be mNextAltModules extending from this + mIsScratchModule = false; + mIsSpecializedMethodModuleRoot = false; // There may be mNextAltModules extending from this mHadBuildError = false; mHadBuildWarning = false; mIgnoreErrors = false; mHadIgnoredError = false; - mIgnoreWarnings = false; + mIgnoreWarnings = false; mReportErrors = true; mIsInsideAutoComplete = false; mIsDeleting = false; mSkipInnerLookup = false; - mIsHotModule = false; + mIsHotModule = false; mSetIllegalSrcPosition = false; mNoResolveGenericParams = false; mWroteToLib = false; mContext = context; mCompiler = context->mCompiler; - mSystem = mCompiler->mSystem; - mProject = NULL; - mCurMethodState = NULL; + mSystem = mCompiler->mSystem; + mProject = NULL; + mCurMethodState = NULL; mAttributeState = NULL; mCurLocalMethodId = 0; mParentNodeEntry = NULL; @@ -959,7 +959,7 @@ BfModule::BfModule(BfContext* context, const StringImpl& moduleName) mOnDemandMethodCount = 0; mHasGenericMethods = false; mCurMethodInstance = NULL; - mCurTypeInstance = NULL; + mCurTypeInstance = NULL; mAwaitingInitFinish = false; mAwaitingFinish = false; mHasFullDebugInfo = false; @@ -974,13 +974,13 @@ BfModule::BfModule(BfContext* context, const StringImpl& moduleName) void BfReportMemory(); BfModule::~BfModule() -{ +{ mRevision = -2; BfLogSysM("Deleting module %p: %s \n", this, mModuleName.c_str()); if (!mIsDeleting) - RemoveModuleData(); + RemoveModuleData(); } void BfModule::RemoveModuleData() @@ -990,7 +990,7 @@ void BfModule::RemoveModuleData() if (!mModuleName.empty()) { // Note: module names not necessarily unique - mContext->mUsedModuleNames.Remove(ToUpper(mModuleName)); + mContext->mUsedModuleNames.Remove(ToUpper(mModuleName)); } CleanupFileInstances(); @@ -1069,7 +1069,7 @@ void BfModule::Init(bool isFullRebuild) mCurMethodState = NULL; mAwaitingInitFinish = true; mOnDemandMethodCount = 0; - mAwaitingFinish = false; + mAwaitingFinish = false; mHasForceLinkMarker = false; mUsedSlotCount = -1; } @@ -1094,7 +1094,7 @@ void BfModule::FinishInit() mBfIRBuilder->Module_SetTargetTriple(mCompiler->mOptions.mTargetTriple, mCompiler->mOptions.mTargetCPU); - mBfIRBuilder->SetBackend(IsTargetingBeefBackend()); + mBfIRBuilder->SetBackend(IsTargetingBeefBackend()); if (moduleOptions.mOptLevel == BfOptLevel_OgPlus) { @@ -1106,7 +1106,7 @@ void BfModule::FinishInit() if (mIsComptimeModule) mHasFullDebugInfo = true; - + if (((!mCompiler->mIsResolveOnly) && (!mIsScratchModule) && (moduleOptions.mEmitDebugInfo != 0) && (mIsReified)) || (mIsComptimeModule)) { @@ -1114,7 +1114,7 @@ void BfModule::FinishInit() } else mHasFullDebugInfo = false; - + if ((mBfIRBuilder->DbgHasInfo()) && (mModuleName != "") && ((moduleOptions.mEmitDebugInfo != 0))) { @@ -1125,13 +1125,13 @@ void BfModule::FinishInit() else { mBfIRBuilder->Module_AddModuleFlag("Dwarf Version", 4); - } + } mBfIRBuilder->Module_AddModuleFlag("Debug Info Version", 3); mDICompileUnit = mBfIRBuilder->DbgCreateCompileUnit(llvm::dwarf::DW_LANG_C_plus_plus, mModuleName, ".", "Beef Compiler 0.42.3", /*moduleOptions.mOptLevel > 0*/false, "", 0, !mHasFullDebugInfo); - } + } - mAwaitingInitFinish = false; + mAwaitingInitFinish = false; } void BfModule::CalcGeneratesCode() @@ -1149,7 +1149,7 @@ void BfModule::CalcGeneratesCode() } void BfModule::ReifyModule() -{ +{ BF_ASSERT((mCompiler->mCompileState != BfCompiler::CompileState_Unreified) && (mCompiler->mCompileState != BfCompiler::CompileState_VData)); BfLogSysM("ReifyModule %@ %s\n", this, mModuleName.c_str()); @@ -1158,14 +1158,14 @@ void BfModule::ReifyModule() CalcGeneratesCode(); mReifyQueued = false; StartNewRevision(RebuildKind_SkipOnDemandTypes, true); - mCompiler->mStats.mModulesReified++; + mCompiler->mStats.mModulesReified++; } void BfModule::UnreifyModule() { BfLogSysM("UnreifyModule %p %s\n", this, mModuleName.c_str()); BF_ASSERT((this != mContext->mScratchModule) && (this != mContext->mUnreifiedModule)); - mIsReified = false; + mIsReified = false; CalcGeneratesCode(); mReifyQueued = false; StartNewRevision(RebuildKind_None, true); @@ -1193,7 +1193,7 @@ void BfModule::PrepareForIRWriting(BfTypeInstance* typeInst) { if (HasCompiledOutput()) { - // It's possible that the target's code hasn't changed but we're requesting a new generic method specialization + // It's possible that the target's code hasn't changed but we're requesting a new generic method specialization if ((!mIsModuleMutable) && (!typeInst->IsUnspecializedType()) && (!typeInst->mResolvingVarField)) { StartExtension(); @@ -1210,7 +1210,7 @@ void BfModule::SetupIRBuilder(bool dbgVerifyCodeGen) if (mIsScratchModule) { mBfIRBuilder->mIgnoreWrites = true; - BF_ASSERT(!dbgVerifyCodeGen); + BF_ASSERT(!dbgVerifyCodeGen); } #ifdef _DEBUG if (mCompiler->mIsResolveOnly) @@ -1228,7 +1228,7 @@ void BfModule::SetupIRBuilder(bool dbgVerifyCodeGen) // The only purpose of not ignoring writes is so we can verify the codegen one instruction at a time mBfIRBuilder->mDbgVerifyCodeGen = true; } - } + } else if (!mGeneratesCode) { mBfIRBuilder->mIgnoreWrites = true; @@ -1275,10 +1275,10 @@ void BfModule::EnsureIRBuilder(bool dbgVerifyCodeGen) if ((!mIsScratchModule) && (!mAddedToCount)) { mCompiler->mStats.mModulesStarted++; - mAddedToCount = true; + mAddedToCount = true; } BF_ASSERT(mStaticFieldRefs.GetCount() == 0); - + /*if (mCompiler->mIsResolveOnly) BF_ASSERT(mIsResolveOnly);*/ mBfIRBuilder = new BfIRBuilder(this); @@ -1290,7 +1290,7 @@ void BfModule::EnsureIRBuilder(bool dbgVerifyCodeGen) BfIRValue BfModule::CreateForceLinkMarker(BfModule* module, String* outName) { - String name = "FORCELINKMOD_" + module->mModuleName; + String name = "FORCELINKMOD_" + module->mModuleName; if (outName != NULL) *outName = name; auto markerType = GetPrimitiveType(BfTypeCode_Int8); @@ -1299,7 +1299,7 @@ BfIRValue BfModule::CreateForceLinkMarker(BfModule* module, String* outName) void BfModule::StartNewRevision(RebuildKind rebuildKind, bool force) { - BP_ZONE("BfModule::StartNewRevision"); + BP_ZONE("BfModule::StartNewRevision"); // The project MAY be deleted because disabling a project can cause types to be deleted which // causes other types rebuild BEFORE they get deleted, which is okay (though wasteful) @@ -1314,13 +1314,13 @@ void BfModule::StartNewRevision(RebuildKind rebuildKind, bool force) // Already on new revision? if ((mRevision == mCompiler->mRevision) && (!force)) return; - + mHadBuildError = false; - mHadBuildWarning = false; + mHadBuildWarning = false; mExtensionCount = 0; mRevision = mCompiler->mRevision; mRebuildIdx++; - ClearModuleData(!force); + ClearModuleData(!force); // Clear this here, not in ClearModuleData, so we preserve those references even after writing out module if (rebuildKind != BfModule::RebuildKind_None) // Leave string pool refs for when we need to use things like [LinkName("")] methods bofore re-reification @@ -1335,7 +1335,7 @@ void BfModule::StartNewRevision(RebuildKind rebuildKind, bool force) mDeferredMethodCallData.Clear(); mDeferredMethodIds.Clear(); mModuleRefs.Clear(); - mOutFileNames.Clear(); + mOutFileNames.Clear(); mTypeDataRefs.Clear(); mInterfaceSlotRefs.Clear(); @@ -1372,7 +1372,7 @@ void BfModule::StartNewRevision(RebuildKind rebuildKind, bool force) mNextAltModule = NULL; BF_ASSERT(mModuleOptions == NULL); - BfLogSysM("Mod:%p StartNewRevision: %s Revision: %d\n", this, mModuleName.c_str(), mRevision); + BfLogSysM("Mod:%p StartNewRevision: %s Revision: %d\n", this, mModuleName.c_str(), mRevision); bool needsTypePopulated = false; int oldOnDemandCount = 0; @@ -1384,7 +1384,7 @@ void BfModule::StartNewRevision(RebuildKind rebuildKind, bool force) { for (int typeIdx = 0; typeIdx < (int)mOwnedTypeInstances.size(); typeIdx++) { - auto typeInst = mOwnedTypeInstances[typeIdx]; + auto typeInst = mOwnedTypeInstances[typeIdx]; if (!typeInst->IsDeleting()) { typeInst->mIsReified = mIsReified; @@ -1434,7 +1434,7 @@ void BfModule::StartNewRevision(RebuildKind rebuildKind, bool force) } } } - + if (!mIsDeleting) Init(); mOnDemandMethodCount += oldOnDemandCount; @@ -1448,12 +1448,12 @@ void BfModule::StartExtension() BfLogSysM("Extension started of module %p\n", this); mExtensionCount++; - + if (mBfIRBuilder != NULL) - mPrevIRBuilders.push_back(mBfIRBuilder); + mPrevIRBuilders.push_back(mBfIRBuilder); mBfIRBuilder = NULL; mWantsIRIgnoreWrites = false; - + mFuncReferences.Clear(); mClassVDataRefs.Clear(); mClassVDataExtRefs.Clear(); @@ -1490,22 +1490,22 @@ void BfModule::GetConstClassValueParam(BfIRValue classVData, SizedArrayImplCreatePtrToInt(classVData, BfTypeCode_IntPtr); else - vDataValue = mBfIRBuilder->CreateBitCast(classVData, mBfIRBuilder->MapType(mContext->mBfClassVDataPtrType)); + vDataValue = mBfIRBuilder->CreateBitCast(classVData, mBfIRBuilder->MapType(mContext->mBfClassVDataPtrType)); typeValueParams.push_back(vDataValue); if (hasObjectDebugFlags) { auto primType = GetPrimitiveType(BfTypeCode_IntPtr); - typeValueParams.push_back(GetDefaultValue(primType)); + typeValueParams.push_back(GetDefaultValue(primType)); } } BfIRValue BfModule::GetConstValue(int64 val) -{ +{ return mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, (uint64)val); } BfIRValue BfModule::GetConstValue(int64 val, BfType* type) -{ +{ BfType* checkType = type; if (type->IsTypedPrimitive()) { @@ -1523,7 +1523,7 @@ BfIRValue BfModule::GetConstValue(int64 val, BfType* type) } BfIRValue BfModule::GetConstValue8(int val) -{ +{ return mBfIRBuilder->CreateConst(BfTypeCode_Int8, (uint64)val); } @@ -1549,7 +1549,7 @@ BfIRValue BfModule::GetDefaultValue(BfType* type) return mBfIRBuilder->CreateConst(BfTypeCode_Int64, 0); return GetDefaultValue(type->GetUnderlyingType()); } - + if (type->IsPointer() || type->IsObjectOrInterface() || type->IsGenericParam() || type->IsVar() || type->IsRef() || type->IsNull() || type->IsModifiedTypeType() || type->IsConcreteInterfaceType()) return mBfIRBuilder->CreateConstNull(mBfIRBuilder->MapType(type)); @@ -1561,7 +1561,7 @@ BfIRValue BfModule::GetDefaultValue(BfType* type) if (type->IsFloat()) { auto primType = (BfPrimitiveType*)type; - return mBfIRBuilder->CreateConst(primType->mTypeDef->mTypeCode, 0.0); + return mBfIRBuilder->CreateConst(primType->mTypeDef->mTypeCode, 0.0); } return mBfIRBuilder->CreateConstAggZero(mBfIRBuilder->MapType(type)); } @@ -1601,9 +1601,9 @@ BfTypedValue BfModule::GetDefaultTypedValue(BfType* type, bool allowRef, BfDefau } else { - typedValue = BfTypedValue(CreateAlloca(type), type, BfTypedValueKind_Addr); + typedValue = BfTypedValue(CreateAlloca(type), type, BfTypedValueKind_Addr); } - + if (!mBfIRBuilder->mIgnoreWrites) { mBfIRBuilder->CreateMemSet(typedValue.mValue, GetConstValue(0, GetPrimitiveType(BfTypeCode_Int8)), @@ -1617,7 +1617,7 @@ BfTypedValue BfModule::GetDefaultTypedValue(BfType* type, bool allowRef, BfDefau } if ((type->IsRef()) && (!allowRef)) - { + { BfRefType* refType = (BfRefType*)type; BfType* underlyingType = refType->GetUnderlyingType(); if (underlyingType->IsValuelessType()) @@ -1627,29 +1627,29 @@ BfTypedValue BfModule::GetDefaultTypedValue(BfType* type, bool allowRef, BfDefau } else { - typedValue = BfTypedValue(GetDefaultValue(type), type, (defaultValueKind == BfDefaultValueKind_Addr) ? BfTypedValueKind_Addr : BfTypedValueKind_Value); + typedValue = BfTypedValue(GetDefaultValue(type), type, (defaultValueKind == BfDefaultValueKind_Addr) ? BfTypedValueKind_Addr : BfTypedValueKind_Value); } return typedValue; } BfIRValue BfModule::CreateStringCharPtr(const StringImpl& str, int stringId, bool define) -{ +{ String stringDataName = StrFormat("__bfStrData%d", stringId); auto charType = GetPrimitiveType(BfTypeCode_Char8); BfIRType irStrCharType = mBfIRBuilder->GetSizedArrayType(mBfIRBuilder->MapType(charType), (int)str.length() + 1); - + BfIRValue strConstant; if (define) - { - strConstant = mBfIRBuilder->CreateConstString(str); + { + strConstant = mBfIRBuilder->CreateConstString(str); } BfIRValue gv = mBfIRBuilder->CreateGlobalVariable(irStrCharType, true, BfIRLinkageType_External, strConstant, stringDataName); if (define) - mBfIRBuilder->GlobalVar_SetUnnamedAddr(gv, true); + mBfIRBuilder->GlobalVar_SetUnnamedAddr(gv, true); return mBfIRBuilder->CreateInBoundsGEP(gv, 0, 0); } @@ -1668,18 +1668,18 @@ void BfModule::FixConstValueParams(BfTypeInstance* typeInst, SizedArrayImplmFieldInstances.size(); fieldIdx++) { auto fieldInstance = &typeInst->mFieldInstances[fieldIdx]; if (fieldInstance->mDataIdx < 0) continue; - + BF_ASSERT(fieldInstance->mDataIdx > prevDataIdx); if (fillInPadding) { - for (int i = prevDataIdx + 1; i < fieldInstance->mDataIdx; i++) + for (int i = prevDataIdx + 1; i < fieldInstance->mDataIdx; i++) valueParams.Insert(valueParamIdx++, mBfIRBuilder->CreateConstArrayZero(0)); } @@ -1689,7 +1689,7 @@ void BfModule::FixConstValueParams(BfTypeInstance* typeInst, SizedArrayImplmResolvedType)); } } @@ -1707,11 +1707,11 @@ BfIRValue BfModule::CreateStringObjectValue(const StringImpl& str, int stringId, if (define) { - BfIRValue stringCharsVal = CreateStringCharPtr(str, stringId, define); + BfIRValue stringCharsVal = CreateStringCharPtr(str, stringId, define); mStringCharPtrPool[stringId] = stringCharsVal; - + SizedArray typeValueParams; - GetConstClassValueParam(classVDataGlobal, typeValueParams); + GetConstClassValueParam(classVDataGlobal, typeValueParams); FixConstValueParams(stringTypeInst->mBaseType, typeValueParams); auto objData = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(stringTypeInst->mBaseType, BfIRPopulateType_Full), typeValueParams); @@ -1723,19 +1723,19 @@ BfIRValue BfModule::CreateStringObjectValue(const StringImpl& str, int stringId, if (lenByteCount == 4) { typeValueParams.push_back(GetConstValue32((int)str.length())); // mLength - typeValueParams.push_back(GetConstValue32((int32)(0x40000000 + str.length() + 1))); // mAllocSizeAndFlags + typeValueParams.push_back(GetConstValue32((int32)(0x40000000 + str.length() + 1))); // mAllocSizeAndFlags } else { typeValueParams.push_back(GetConstValue64(str.length())); // mLength - typeValueParams.push_back(GetConstValue64(0x4000000000000000LL + str.length() + 1)); // mAllocSizeAndFlags + typeValueParams.push_back(GetConstValue64(0x4000000000000000LL + str.length() + 1)); // mAllocSizeAndFlags } typeValueParams.push_back(stringCharsVal); // mPtr FixConstValueParams(stringTypeInst, typeValueParams); - + stringValData = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(stringTypeInst, BfIRPopulateType_Full), typeValueParams); } - + mBfIRBuilder->PopulateType(stringTypeInst); auto stringValLiteral = mBfIRBuilder->CreateGlobalVariable( mBfIRBuilder->MapTypeInst(stringTypeInst, BfIRPopulateType_Full), @@ -1748,7 +1748,7 @@ BfIRValue BfModule::CreateStringObjectValue(const StringImpl& str, int stringId, } int BfModule::GetStringPoolIdx(BfIRValue constantStr, BfIRConstHolder* constHolder) -{ +{ BF_ASSERT(constantStr.IsConst()); if (constHolder == NULL) @@ -1765,24 +1765,24 @@ int BfModule::GetStringPoolIdx(BfIRValue constantStr, BfIRConstHolder* constHold auto constBitCast = (BfConstantBitCast*)constant; constant = constHolder->GetConstantById(constBitCast->mTarget); } - + if (constant->mConstType == BfConstType_GEP32_2) { auto constGEP = (BfConstantGEP32_2*)constant; constant = constHolder->GetConstantById(constGEP->mTarget); } - + if (constant->mConstType == BfConstType_GlobalVar) { auto constGV = (BfGlobalVar*)constant; - const char* strDataPrefix = "__bfStrData"; + const char* strDataPrefix = "__bfStrData"; if (strncmp(constGV->mName, strDataPrefix, strlen(strDataPrefix)) == 0) return atoi(constGV->mName + strlen(strDataPrefix)); - const char* strObjPrefix = "__bfStrObj"; + const char* strObjPrefix = "__bfStrObj"; if (strncmp(constGV->mName, strObjPrefix, strlen(strObjPrefix)) == 0) return atoi(constGV->mName + strlen(strObjPrefix)); - } + } return -1; } @@ -1792,9 +1792,9 @@ String* BfModule::GetStringPoolString(BfIRValue constantStr, BfIRConstHolder * c int strId = GetStringPoolIdx(constantStr, constHolder); if (strId != -1) { - auto& entry = mContext->mStringObjectIdMap[strId]; + auto& entry = mContext->mStringObjectIdMap[strId]; return &entry.mString; - } + } return NULL; } @@ -1811,7 +1811,7 @@ BfIRValue BfModule::GetStringCharPtr(int stringId, bool force) { if ((mBfIRBuilder->mIgnoreWrites) && (!force)) { - mUnreifiedStringPoolRefs.Add(stringId); + mUnreifiedStringPoolRefs.Add(stringId); return mBfIRBuilder->CreateConst(BfTypeCode_StringId, stringId); } @@ -1825,7 +1825,7 @@ BfIRValue BfModule::GetStringCharPtr(int stringId, bool force) const StringImpl& str = mContext->mStringObjectIdMap[stringId].mString; BfIRValue strCharPtrConst = CreateStringCharPtr(str, stringId, false); - *irValue = strCharPtrConst; + *irValue = strCharPtrConst; return strCharPtrConst; } @@ -1838,8 +1838,8 @@ BfIRValue BfModule::GetStringCharPtr(BfIRValue strValue, bool force) return GetStringCharPtr(stringId, force); } - BfIRValue charPtrPtr = mBfIRBuilder->CreateInBoundsGEP(strValue, 0, 1); - BfIRValue charPtr = mBfIRBuilder->CreateLoad(charPtrPtr); + BfIRValue charPtrPtr = mBfIRBuilder->CreateInBoundsGEP(strValue, 0, 1); + BfIRValue charPtr = mBfIRBuilder->CreateLoad(charPtrPtr); return charPtr; } @@ -1849,7 +1849,7 @@ BfIRValue BfModule::GetStringCharPtr(const StringImpl& str, bool force) } BfIRValue BfModule::GetStringObjectValue(int strId, bool define, bool force) -{ +{ BfIRValue* objValue; if (mStringObjectPool.TryGetValue(strId, &objValue)) return *objValue; @@ -1859,11 +1859,11 @@ BfIRValue BfModule::GetStringObjectValue(int strId, bool define, bool force) } BfIRValue BfModule::GetStringObjectValue(const StringImpl& str, bool define, bool force) -{ +{ auto stringType = ResolveTypeDef(mCompiler->mStringTypeDef, define ? BfPopulateType_Data : BfPopulateType_Declaration); mBfIRBuilder->PopulateType(stringType); - int strId = mContext->GetStringLiteralId(str); + int strId = mContext->GetStringLiteralId(str); if ((mBfIRBuilder->mIgnoreWrites) && (!force)) { @@ -1884,15 +1884,15 @@ BfIRValue BfModule::GetStringObjectValue(const StringImpl& str, bool define, boo BfIRValue strObject = CreateStringObjectValue(str, strId, define); mStringObjectPool[strId] = strObject; - + mStringPoolRefs.Add(strId); - + return strObject; } BfIRValue BfModule::CreateGlobalConstValue(const StringImpl& name, BfIRValue constant, BfIRType type, bool external) { - auto newConst = mBfIRBuilder->CreateGlobalVariable( + auto newConst = mBfIRBuilder->CreateGlobalVariable( type, true, external ? BfIRLinkageType_External : BfIRLinkageType_Internal, @@ -1912,7 +1912,7 @@ void BfModule::NewScopeState(bool createLexicalBlock, bool flushValueScope) curScope->mScopeLocalId = rootMethodState->mCurLocalVarId++; auto autoComplete = mCompiler->GetAutoComplete(); if (autoComplete != NULL) - autoComplete->CheckLabel(curScope->mLabelNode, NULL, curScope); + autoComplete->CheckLabel(curScope->mLabelNode, NULL, curScope); } if (!mCurMethodState->mCurScope->mLabel.IsEmpty()) @@ -1940,7 +1940,7 @@ void BfModule::NewScopeState(bool createLexicalBlock, bool flushValueScope) else mBfIRBuilder->CreateValueScopeHardEnd(prevScope->mValueScopeStart); } - + mCurMethodState->mBlockNestLevel++; if ((createLexicalBlock) && (mBfIRBuilder->DbgHasInfo()) && (mHasFullDebugInfo)) { @@ -1948,7 +1948,7 @@ void BfModule::NewScopeState(bool createLexicalBlock, bool flushValueScope) if (mCurMethodState->mCurScope->mDIScope) mCurMethodState->mCurScope->mDIScope = mBfIRBuilder->DbgCreateLexicalBlock(mCurMethodState->mCurScope->mDIScope, mCurFilePosition.mFileInstance->mDIFile, mCurFilePosition.mCurLine, mCurFilePosition.mCurColumn); } - mCurMethodState->mCurScope->mLocalVarStart = (int)mCurMethodState->mLocals.size(); + mCurMethodState->mCurScope->mLocalVarStart = (int)mCurMethodState->mLocals.size(); mCurMethodState->mCurScope->mBlock = mBfIRBuilder->MaybeChainNewBlock((!mCurMethodState->mCurScope->mLabel.empty()) ? mCurMethodState->mCurScope->mLabel : "newScope"); mCurMethodState->mCurScope->mMixinState = mCurMethodState->mMixinState; } @@ -1982,16 +1982,16 @@ void BfModule::RestoreScoreState_LocalVariables() } void BfModule::RestoreScopeState() -{ +{ BfScopeData* prevScopeData = mCurMethodState->mCurScope->mPrevScope; mCurMethodState->mBlockNestLevel--; - + if (!mCurMethodState->mCurScope->mAtEndBlocks.empty()) { BfIRBlock afterEndBlock; if (!mCurMethodState->mLeftBlockUncond) - { - afterEndBlock = mBfIRBuilder->CreateBlock("scopeAfterEnd"); + { + afterEndBlock = mBfIRBuilder->CreateBlock("scopeAfterEnd"); mBfIRBuilder->CreateBr(afterEndBlock); mBfIRBuilder->ClearDebugLocation_Last(); } @@ -2034,11 +2034,11 @@ BfIRValue BfModule::CreateAlloca(BfType* type, bool addLifetime, const char* nam allocaInst = mBfIRBuilder->CreateAlloca(mBfIRBuilder->MapType(type), arraySize); else allocaInst = mBfIRBuilder->CreateAlloca(mBfIRBuilder->MapType(type)); - mBfIRBuilder->SetAllocaAlignment(allocaInst, type->mAlign); + mBfIRBuilder->SetAllocaAlignment(allocaInst, type->mAlign); mBfIRBuilder->ClearDebugLocation(allocaInst); if (name != NULL) mBfIRBuilder->SetName(allocaInst, name); - mBfIRBuilder->SetInsertPoint(prevInsertBlock); + mBfIRBuilder->SetInsertPoint(prevInsertBlock); if ((addLifetime) && (WantsLifetimes())) { auto lifetimeStart = mBfIRBuilder->CreateLifetimeStart(allocaInst); @@ -2058,7 +2058,7 @@ BfIRValue BfModule::CreateAllocaInst(BfTypeInstance* typeInst, bool addLifetime, auto prevInsertBlock = mBfIRBuilder->GetInsertBlock(); mBfIRBuilder->SetInsertPoint(mCurMethodState->mIRHeadBlock); auto allocaInst = mBfIRBuilder->CreateAlloca(mBfIRBuilder->MapTypeInst(typeInst)); - mBfIRBuilder->SetAllocaAlignment(allocaInst, typeInst->mInstAlign); + mBfIRBuilder->SetAllocaAlignment(allocaInst, typeInst->mInstAlign); mBfIRBuilder->ClearDebugLocation(allocaInst); if (name != NULL) mBfIRBuilder->SetName(allocaInst, name); @@ -2075,24 +2075,24 @@ BfIRValue BfModule::CreateAllocaInst(BfTypeInstance* typeInst, bool addLifetime, BfDeferredCallEntry* BfModule::AddStackAlloc(BfTypedValue val, BfIRValue arraySize, BfAstNode* refNode, BfScopeData* scopeData, bool condAlloca, bool mayEscape, BfIRBlock valBlock) { //This was removed because we want the alloc to be added to the __deferred list if it's actually a "stack" - // 'stack' in a head scopeData is really the same as 'scopeData', so use the simpler scopeData handling + // 'stack' in a head scopeData is really the same as 'scopeData', so use the simpler scopeData handling /*if (mCurMethodState->mInHeadScope) isScopeAlloc = true;*/ if (scopeData == NULL) return NULL; - + auto checkBaseType = val.mType->ToTypeInstance(); if ((checkBaseType != NULL) && (checkBaseType->IsObject()) && (!arraySize)) - { + { bool hadDtorCall = false; while (checkBaseType != NULL) - { + { BfMethodDef* dtorMethodDef = checkBaseType->mTypeDef->GetMethodByName("~this"); if (dtorMethodDef != NULL) - { + { auto dtorMethodInstance = GetMethodInstance(checkBaseType, dtorMethodDef, BfTypeVector()); - if (dtorMethodInstance) + if (dtorMethodInstance) { bool isDynAlloc = (scopeData != NULL) && (mCurMethodState->mCurScope->IsDyn(scopeData)); BfIRValue useVal = val.mValue; @@ -2100,7 +2100,7 @@ BfDeferredCallEntry* BfModule::AddStackAlloc(BfTypedValue val, BfIRValue arraySi BfIRBlock prevBlock = mBfIRBuilder->GetInsertBlock(); if (valBlock) mBfIRBuilder->SetInsertPoint(valBlock); - useVal = mBfIRBuilder->CreateBitCast(val.mValue, mBfIRBuilder->MapTypeInstPtr(checkBaseType)); + useVal = mBfIRBuilder->CreateBitCast(val.mValue, mBfIRBuilder->MapTypeInstPtr(checkBaseType)); if (!useVal.IsConst()) mBfIRBuilder->ClearDebugLocation(useVal); if (valBlock) @@ -2139,17 +2139,17 @@ BfDeferredCallEntry* BfModule::AddStackAlloc(BfTypedValue val, BfIRValue arraySi checkBaseType = checkBaseType->mBaseType; } return NULL; - } - - //TODO: In the future we could be smarter about statically determining that our value hasn't escaped and eliding this + } + + //TODO: In the future we could be smarter about statically determining that our value hasn't escaped and eliding this if (mayEscape) { if ((!IsOptimized()) && (!mIsComptimeModule) && (!val.mType->IsValuelessType()) && (!mBfIRBuilder->mIgnoreWrites) && (!mCompiler->mIsResolveOnly)) - { + { auto nullPtrType = GetPrimitiveType(BfTypeCode_NullPtr); bool isDyn = mCurMethodState->mCurScope->IsDyn(scopeData); if (!isDyn) - { + { const char* methodName = arraySize ? "SetDeletedArray" : "SetDeleted"; BfModuleMethodInstance dtorMethodInstance = GetInternalMethod(methodName); BF_ASSERT(dtorMethodInstance.mMethodInstance != NULL); @@ -2173,14 +2173,14 @@ BfDeferredCallEntry* BfModule::AddStackAlloc(BfTypedValue val, BfIRValue arraySi llvmArgs.push_back(arraySize); return AddDeferredCall(dtorMethodInstance, llvmArgs, scopeData, refNode, true); } - } + } else { if ((arraySize) && (!arraySize.IsConst()) && (val.mType->mSize < mSystem->mPtrSize)) { BfIRValue clearSize = arraySize; if (val.mType->GetStride() > 1) - clearSize = mBfIRBuilder->CreateMul(clearSize, GetConstValue(val.mType->GetStride())); + clearSize = mBfIRBuilder->CreateMul(clearSize, GetConstValue(val.mType->GetStride())); const char* methodName = "SetDeletedX"; BfModuleMethodInstance dtorMethodInstance = GetInternalMethod(methodName); @@ -2248,27 +2248,27 @@ bool BfModule::TryLocalVariableInit(BfLocalVariable* localVar) { int64 checkMask = (int64)1 << fieldInstance.mMergedDataIdx; if ((localVar->mUnassignedFieldFlags & checkMask) != 0) - { + { // For fields added in extensions, we automatically initialize those if necessary auto fieldDef = fieldInstance.GetFieldDef(); if (!fieldDef->mDeclaringType->IsExtension()) - return false; - + return false; + if ((fieldInstance.mDataIdx != -1) && (!mBfIRBuilder->mIgnoreWrites) && (!mCompiler->mIsResolveOnly) && (!mIsComptimeModule)) - { - auto curInsertBlock = mBfIRBuilder->GetInsertBlock(); - + { + auto curInsertBlock = mBfIRBuilder->GetInsertBlock(); + mBfIRBuilder->SaveDebugLocation(); if (localVar->IsParam()) mBfIRBuilder->SetInsertPointAtStart(mCurMethodState->mIRInitBlock); - else + else { BF_ASSERT(localVar->mDeclBlock); mBfIRBuilder->SetInsertPointAtStart(localVar->mDeclBlock); - } - + } + mBfIRBuilder->ClearDebugLocation(); - + BfIRValue curVal; if (localVar->mIsThis) curVal = mBfIRBuilder->GetArgument(0); @@ -2284,7 +2284,7 @@ bool BfModule::TryLocalVariableInit(BfLocalVariable* localVar) auto fieldPtr = mBfIRBuilder->CreateInBoundsGEP(curVal, 0, fieldInstance.mDataIdx); auto defVal = GetDefaultValue(fieldInstance.mResolvedType); auto storeInst = mBfIRBuilder->CreateStore(defVal, fieldPtr); - + mBfIRBuilder->SetInsertPoint(curInsertBlock); mBfIRBuilder->RestoreDebugLocation(); } @@ -2306,7 +2306,7 @@ void BfModule::LocalVariableDone(BfLocalVariable* localVar, bool isMethodExit) BfAstNode* localNameNode = localVar->mNameNode; if (localVar->mIsThis) { - localNameNode = mCurMethodInstance->mMethodDef->GetRefNode(); + localNameNode = mCurMethodInstance->mMethodDef->GetRefNode(); } if (localNameNode != NULL) @@ -2331,10 +2331,10 @@ void BfModule::LocalVariableDone(BfLocalVariable* localVar, bool isMethodExit) deferFullAnalysis = true; //bool deferFullAnalysis = true; - bool deferUsageWarning = deferFullAnalysis && (mCompiler->IsAutocomplete()) && + bool deferUsageWarning = deferFullAnalysis && (mCompiler->IsAutocomplete()) && (mCompiler->mResolvePassData->mAutoComplete->mResolveType != BfResolveType_GetFixits); - if (((localVar->mAssignedKind != BfLocalVarAssignKind_Unconditional) || (localVar->mHadExitBeforeAssign)) && + if (((localVar->mAssignedKind != BfLocalVarAssignKind_Unconditional) || (localVar->mHadExitBeforeAssign)) && (!localVar->mIsImplicitParam)) { if (deferUsageWarning) @@ -2372,9 +2372,9 @@ void BfModule::LocalVariableDone(BfLocalVariable* localVar, bool isMethodExit) // This initializer was handled in CtorNoBody foundFields = true; continue; - } + } } - + if (auto propertyDeclaration = BfNodeDynCast(fieldDef->mFieldDeclaration)) { String propName; @@ -2427,7 +2427,7 @@ void BfModule::LocalVariableDone(BfLocalVariable* localVar, bool isMethodExit) } else if ((localVar->mReadFromId == -1) && (!localVar->IsParam()) && (!deferUsageWarning)) Warn(BfWarning_CS0168_VariableDeclaredButNeverUsed, StrFormat("The variable '%s' is assigned but its value is never used", localVar->mName.c_str()), localNameNode, deferFullAnalysis); - } + } } } @@ -2439,7 +2439,7 @@ void BfModule::CreateRetValLocal() localDef->mName = "return"; localDef->mResolvedType = mCurMethodState->mRetVal.mType; localDef->mAddr = mCurMethodState->mRetVal.mValue; - localDef->mAssignedKind = BfLocalVarAssignKind_Unconditional; + localDef->mAssignedKind = BfLocalVarAssignKind_Unconditional; AddLocalVariableDef(localDef); } else if (mCurMethodState->mRetValAddr) @@ -2460,7 +2460,7 @@ void BfModule::MarkDynStack(BfScopeData* scopeData) { if (checkScope == scopeData) break; - + checkScope->mHadOuterDynStack = true; checkScope = checkScope->mPrevScope; } @@ -2476,14 +2476,14 @@ void BfModule::SaveStackState(BfScopeData* scopeData) if (checkScope == scopeData) { if ((!checkScope->mSavedStack) && (checkScope->mBlock) && (!checkScope->mIsScopeHead) && (!checkScope->mHadOuterDynStack)) - { + { if (mBfIRBuilder->mHasDebugInfo) mBfIRBuilder->SaveDebugLocation(); auto prevPos = mBfIRBuilder->GetInsertBlock(); mBfIRBuilder->SetInsertPointAtStart(checkScope->mBlock); checkScope->mSavedStack = mBfIRBuilder->CreateStackSave(); mBfIRBuilder->ClearDebugLocation(checkScope->mSavedStack); - mBfIRBuilder->SetInsertPoint(prevPos); + mBfIRBuilder->SetInsertPoint(prevPos); if (mBfIRBuilder->mHasDebugInfo) mBfIRBuilder->RestoreDebugLocation(); } @@ -2496,8 +2496,8 @@ void BfModule::SaveStackState(BfScopeData* scopeData) checkScope->mSavedStackUses.Clear(); mBfIRBuilder->EraseInstFromParent(checkScope->mSavedStack); - checkScope->mSavedStack = BfIRValue(); - } + checkScope->mSavedStack = BfIRValue(); + } checkScope = checkScope->mPrevScope; } } @@ -2519,7 +2519,7 @@ BfProjectSet* BfModule::GetVisibleProjectSet() { if (mCurMethodState == NULL) return NULL; - + if (mCurMethodState->mVisibleProjectSet.IsEmpty()) { HashSet seenTypes; @@ -2555,14 +2555,14 @@ BfProjectSet* BfModule::GetVisibleProjectSet() return; for (auto type : typeInstance->mGenericTypeInfo->mTypeGenericArguments) { - if (seenTypes.Add(type)) + if (seenTypes.Add(type)) _AddType(type); - } + } }; if (mCurTypeInstance != NULL) _AddType(mCurTypeInstance); - + auto methodState = mCurMethodState; while (methodState != NULL) { @@ -2572,11 +2572,11 @@ BfProjectSet* BfModule::GetVisibleProjectSet() if (methodState->mMethodInstance->mMethodInfoEx != NULL) { for (auto type : methodState->mMethodInstance->mMethodInfoEx->mMethodGenericArguments) - _AddType(type); + _AddType(type); } } - methodState = methodState->mPrevMethodState; + methodState = methodState->mPrevMethodState; } } @@ -2596,7 +2596,7 @@ BfFileInstance* BfModule::GetFileFromNode(BfAstNode* astNode) return *fileInstancePtr; } else - { + { // It's possible two parsers have the same file name (ie: mNextRevision) BfFileInstance** namedFileInstancePtr = NULL; if (!mNamedFileInstanceMap.TryAdd(bfParser->mFileName, NULL, &namedFileInstancePtr)) @@ -2607,7 +2607,7 @@ BfFileInstance* BfModule::GetFileFromNode(BfAstNode* astNode) } int slashPos = (int)bfParser->mFileName.LastIndexOf(DIR_SEP_CHAR); - + auto bfFileInstance = new BfFileInstance(); *fileInstancePtr = bfFileInstance; *namedFileInstancePtr = bfFileInstance; @@ -2629,7 +2629,7 @@ BfFileInstance* BfModule::GetFileFromNode(BfAstNode* astNode) bfFileInstance->mDIFile = mBfIRBuilder->DbgCreateFile(fileName.Substring(slashPos + 1), fileName.Substring(0, BF_MAX(slashPos, 0)), bfParser->mMD5Hash); } - return bfFileInstance; + return bfFileInstance; } } @@ -2654,7 +2654,7 @@ void BfModule::UpdateSrcPos(BfAstNode* astNode, BfSrcPosFlags flags, int debugLo BF_ASSERT(mFileInstanceMap.GetCount() != 0); mCurFilePosition.mFileInstance->mPrevPosition = mCurFilePosition; } - + auto bfFileInstance = GetFileFromNode(astNode); if (bfFileInstance->mPrevPosition.mFileInstance != NULL) { @@ -2666,7 +2666,7 @@ void BfModule::UpdateSrcPos(BfAstNode* astNode, BfSrcPosFlags flags, int debugLo mCurFilePosition.mCurLine = 0; mCurFilePosition.mCurSrcPos = 0; } - } + } int srcPos = astNode->GetSrcStart() + debugLocOffset; @@ -2676,11 +2676,11 @@ void BfModule::UpdateSrcPos(BfAstNode* astNode, BfSrcPosFlags flags, int debugLo if (jumpEntry->mCharIdx > srcPos) jumpEntry--; mCurFilePosition.mCurLine = jumpEntry->mLineNum; - mCurFilePosition.mCurSrcPos = jumpEntry->mCharIdx; + mCurFilePosition.mCurSrcPos = jumpEntry->mCharIdx; mCurFilePosition.mCurColumn = 0; while (mCurFilePosition.mCurSrcPos < srcPos) - { + { if (bfParser->mSrc[mCurFilePosition.mCurSrcPos] == '\n') { mCurFilePosition.mCurLine++; @@ -2696,10 +2696,10 @@ void BfModule::UpdateSrcPos(BfAstNode* astNode, BfSrcPosFlags flags, int debugLo //TODO: if we bail on the "mCurMethodState == NULL" case then we don't get it set during type declarations if (((flags & BfSrcPosFlag_NoSetDebugLoc) == 0) && (mBfIRBuilder->DbgHasLineInfo()) && (mCurMethodState != NULL)) - { + { int column = mCurFilePosition.mCurColumn + 1; if ((mCurMethodInstance != NULL) && (mCurMethodInstance->mMethodDef->mMethodType == BfMethodType_CtorCalcAppend)) - { + { // Set to illegal position column = 0; } @@ -2726,14 +2726,14 @@ void BfModule::UpdateSrcPos(BfAstNode* astNode, BfSrcPosFlags flags, int debugLo { mCurMethodState->mCurScope->mAltDIFile = BfIRMDNode(); mCurMethodState->mCurScope->mAltDIScope = BfIRMDNode(); - } + } } auto inlineAt = mCurMethodState->mCurScope->mDIInlinedAt; if (mCurMethodState->mCrossingMixin) inlineAt = BfIRMDNode(); - if ((!useDIScope) && (mIsComptimeModule)) + if ((!useDIScope) && (mIsComptimeModule)) useDIScope = wantDIFile; if (!useDIScope) @@ -2762,7 +2762,7 @@ void BfModule::SetIllegalSrcPos(BfSrcPosFlags flags) { if ((mBfIRBuilder->DbgHasInfo()) && (mCurMethodState != NULL)) { - auto curScope = mCurMethodState->mCurScope->mDIScope; + auto curScope = mCurMethodState->mCurScope->mDIScope; if (curScope) { if ((mCurMethodState->mCurScope->mDIInlinedAt) && (mCompiler->mOptions.IsCodeView())) @@ -2772,7 +2772,7 @@ void BfModule::SetIllegalSrcPos(BfSrcPosFlags flags) } else { - // Set to whatever it previously was but at column zero, which we will know to be illegal + // Set to whatever it previously was but at column zero, which we will know to be illegal mBfIRBuilder->SetCurrentDebugLocation(mCurFilePosition.mCurLine + 1, 0, curScope, mCurMethodState->mCurScope->mDIInlinedAt); } } @@ -2797,7 +2797,7 @@ bool BfModule::CheckProtection(BfProtection protection, BfTypeDef* checkType, bo if ((mAttributeState != NULL) && (mAttributeState->mCustomAttributes != NULL) && (mAttributeState->mCustomAttributes->Contains(mCompiler->mFriendAttributeTypeDef))) { mAttributeState->mUsed = true; - return true; + return true; } if (((protection == BfProtection_Internal) || (protection == BfProtection_ProtectedInternal)) && (checkType != NULL)) { @@ -2824,7 +2824,7 @@ bool BfModule::CheckProtection(BfProtectionCheckFlags& flags, BfTypeInstance* me return false; if (memberProtection == BfProtection_Public) return true; - + if ((flags & BfProtectionCheckFlag_CheckedPrivate) == 0) { BfTypeInstance* curCheckType = mCurTypeInstance; @@ -2933,7 +2933,7 @@ bool BfModule::CheckProtection(BfProtectionCheckFlags& flags, BfTypeInstance* me if (((memberProtection == BfProtection_Internal) || (memberProtection == BfProtection_ProtectedInternal)) && (memberOwner != NULL)) { if (CheckInternalProtection(memberOwner->mTypeDef)) - return true; + return true; } return false; @@ -2941,7 +2941,7 @@ bool BfModule::CheckProtection(BfProtectionCheckFlags& flags, BfTypeInstance* me void BfModule::SetElementType(BfAstNode* astNode, BfSourceElementType elementType) { - if (mCompiler->mResolvePassData != NULL) + if (mCompiler->mResolvePassData != NULL) { if (auto sourceClassifier = mCompiler->mResolvePassData->GetSourceClassifier(astNode)) sourceClassifier->SetElementType(astNode, elementType); @@ -2961,8 +2961,8 @@ void BfModule::SetFail() if (mIgnoreErrors) { if (mAttributeState != NULL) - mAttributeState->mFlags = (BfAttributeState::Flags)(mAttributeState->mFlags | BfAttributeState::Flag_HadError); - } + mAttributeState->mFlags = (BfAttributeState::Flags)(mAttributeState->mFlags | BfAttributeState::Flag_HadError); + } } void BfModule::VerifyOnDemandMethods() @@ -2974,7 +2974,7 @@ void BfModule::VerifyOnDemandMethods() // mParentModule->VerifyOnDemandMethods(); // return; // } -// +// // int onDemandCount = 0; // for (auto type : mOwnedTypeInstances) // { @@ -2988,7 +2988,7 @@ void BfModule::VerifyOnDemandMethods() // onDemandCount++; // } // } -// +// // BF_ASSERT(mOnDemandMethodCount == onDemandCount); #endif } @@ -3107,7 +3107,7 @@ bool BfModule::AddErrorContext(StringImpl& errorString, BfAstNode* refNode, BfWh errorString += StrFormat("\n while specializing type '%s'", TypeToString(mCurTypeInstance).c_str()); isWhileSpecializing = (BfWhileSpecializingFlags)(isWhileSpecializing | BfWhileSpecializingFlag_Type); } - + return true; } @@ -3116,8 +3116,8 @@ BfError* BfModule::Fail(const StringImpl& error, BfAstNode* refNode, bool isPers BP_ZONE("BfModule::Fail"); if (mIgnoreErrors) - { - mHadIgnoredError = true; + { + mHadIgnoredError = true; if (mAttributeState != NULL) mAttributeState->mFlags = (BfAttributeState::Flags)(mAttributeState->mFlags | BfAttributeState::Flag_HadError); return NULL; @@ -3147,7 +3147,7 @@ BfError* BfModule::Fail(const StringImpl& error, BfAstNode* refNode, bool isPers if ((mCompiler->mCeMachine->mCurContext != NULL) && (mCompiler->mCeMachine->mCurContext->mCurCallSource != NULL) && (mCompiler->mCeMachine->mCurContext->mCurCallSource->mRefNode != NULL)) { - BfError* bfError = mCompiler->mPassInstance->Fail("Comptime method generation had errors", + BfError* bfError = mCompiler->mPassInstance->Fail("Comptime method generation had errors", mCompiler->mCeMachine->mCurContext->mCurCallSource->mRefNode); if (bfError != NULL) mCompiler->mPassInstance->MoreInfo(error, refNode); @@ -3181,12 +3181,12 @@ BfError* BfModule::Fail(const StringImpl& error, BfAstNode* refNode, bool isPers AddFailType(mCurTypeInstance); BfLogSysM("BfModule::Fail module %p type %p %s\n", this, mCurTypeInstance, error.c_str()); - - String errorString = error; + + String errorString = error; BfWhileSpecializingFlags isWhileSpecializing = BfWhileSpecializingFlag_None; if (!AddErrorContext(errorString, refNode, isWhileSpecializing, false)) return NULL; - + BfError* bfError = NULL; if (isWhileSpecializing) deferError = true; @@ -3207,13 +3207,13 @@ BfError* BfModule::Fail(const StringImpl& error, BfAstNode* refNode, bool isPers bfError = mCompiler->mPassInstance->DeferFail(mixinErr, rootMixinState->mSource); else bfError = mCompiler->mPassInstance->Fail(mixinErr, rootMixinState->mSource); - + if (bfError == NULL) return NULL; - + bfError->mIsWhileSpecializing = isWhileSpecializing; mCompiler->mPassInstance->MoreInfo(errorString, refNode); - + auto mixinState = checkMethodState->mMixinState; while ((mixinState != NULL) && (mixinState->mPrevMixinState != NULL)) { @@ -3227,18 +3227,18 @@ BfError* BfModule::Fail(const StringImpl& error, BfAstNode* refNode, bool isPers checkMethodState = checkMethodState->mPrevMethodState; } } - + if (deferError) - bfError = mCompiler->mPassInstance->Fail(errorString, refNode); - else if (refNode == NULL) - bfError = mCompiler->mPassInstance->Fail(errorString); - else - bfError = mCompiler->mPassInstance->Fail(errorString, refNode); + bfError = mCompiler->mPassInstance->Fail(errorString, refNode); + else if (refNode == NULL) + bfError = mCompiler->mPassInstance->Fail(errorString); + else + bfError = mCompiler->mPassInstance->Fail(errorString, refNode); if (bfError != NULL) { bfError->mIsWhileSpecializing = isWhileSpecializing; bfError->mProject = mProject; - bfError->mIsPersistent = isPersistent; + bfError->mIsPersistent = isPersistent; if ((mCurMethodState != NULL) && (mCurMethodState->mDeferredCallEmitState != NULL) && (mCurMethodState->mDeferredCallEmitState->mCloseNode != NULL)) mCompiler->mPassInstance->MoreInfo("Error during deferred statement handling", mCurMethodState->mDeferredCallEmitState->mCloseNode); @@ -3265,7 +3265,7 @@ BfError* BfModule::FailAfter(const StringImpl& error, BfAstNode* refNode) if (refNode != NULL) refNode = BfNodeToNonTemporary(refNode); - mHadBuildError = true; + mHadBuildError = true; BfError* bfError = mCompiler->mPassInstance->FailAfter(error, refNode); if (bfError != NULL) bfError->mProject = mProject; @@ -3294,19 +3294,19 @@ BfError* BfModule::Warn(int warningNum, const StringImpl& warning, BfAstNode* re unwarnNode = parentNodeEntry->mNode; parentNodeEntry = parentNodeEntry->mPrev; } - } + } auto parser = unwarnNode->GetSourceData()->ToParserData(); if ((parser != NULL) && (parser->IsUnwarnedAt(unwarnNode))) - { + { return NULL; } - + // Right now we're only warning on the unspecialized declarations, we may revisit this if (mCurMethodInstance != NULL) { if (mCurMethodInstance->IsSpecializedGenericMethodOrType()) { - if (!showInSpecialized) + if (!showInSpecialized) return NULL; } if (mCurMethodInstance->mMethodDef->mMethodType == BfMethodType_CtorCalcAppend) @@ -3314,7 +3314,7 @@ BfError* BfModule::Warn(int warningNum, const StringImpl& warning, BfAstNode* re } if ((mCurTypeInstance != NULL) && (mCurTypeInstance->IsSpecializedType())) { - if (!showInSpecialized) + if (!showInSpecialized) return NULL; } @@ -3366,10 +3366,10 @@ BfError* BfModule::Warn(int warningNum, const StringImpl& warning, BfAstNode* re if (warningNum != 0) { - mCompiler->mResolvePassData->mAutoComplete->AddEntry(AutoCompleteEntry("fixit", StrFormat("#pragma warning disable %d\t.pragma|%s|%d||#pragma warning disable %d", + mCompiler->mResolvePassData->mAutoComplete->AddEntry(AutoCompleteEntry("fixit", StrFormat("#pragma warning disable %d\t.pragma|%s|%d||#pragma warning disable %d", warningNum, parser->mFileName.c_str(), 0, warningNum).c_str())); } - } + } } } return bfError; @@ -3390,7 +3390,7 @@ void BfModule::CheckErrorAttributes(BfTypeInstance* typeInstance, BfMethodInstan methodInstance->mMethodDef->GetRefNode()); } else - { + { mCompiler->mPassInstance->MoreInfo( StrFormat("See type declaration '%s'", TypeToString(typeInstance, BfTypeNameFlag_UseUnspecializedGenericParamNames).c_str()), typeInstance->mTypeDef->GetRefNode()); @@ -3476,8 +3476,6 @@ void BfModule::CheckRangeError(BfType* type, BfAstNode* refNode) Fail(StrFormat("Result out of range for type '%s'", TypeToString(type).c_str()), refNode); } - - void BfModule::FatalError(const StringImpl& error, const char* file, int line) { static bool sHadFatalError = false; @@ -3496,15 +3494,15 @@ void BfModule::FatalError(const StringImpl& error, const char* file, int line) fullError += StrFormat(" at %s:%d", file, line); fullError += StrFormat("\nModule: %s", mModuleName.c_str()); - + if (mCurTypeInstance != NULL) fullError += StrFormat("\nType: %s", TypeToString(mCurTypeInstance).c_str()); if (mCurMethodInstance != NULL) fullError += StrFormat("\nMethod: %s", MethodToString(mCurMethodInstance).c_str()); - if ((mCurFilePosition.mFileInstance != NULL) && (mCurFilePosition.mFileInstance->mParser != NULL)) - fullError += StrFormat("\nSource Location: %s:%d", mCurFilePosition.mFileInstance->mParser->mFileName.c_str(), mCurFilePosition.mCurLine + 1); - + if ((mCurFilePosition.mFileInstance != NULL) && (mCurFilePosition.mFileInstance->mParser != NULL)) + fullError += StrFormat("\nSource Location: %s:%d", mCurFilePosition.mFileInstance->mParser->mFileName.c_str(), mCurFilePosition.mCurLine + 1); + if (sHadReentrancy) fullError += "\nError had reentrancy"; @@ -3543,7 +3541,7 @@ bool BfModule::CheckDefineMemberProtection(BfProtection protection, BfType* memb { auto underlyingType = memberType->GetUnderlyingType(); if (underlyingType != NULL) - return CheckDefineMemberProtection(protection, underlyingType); + return CheckDefineMemberProtection(protection, underlyingType); return true; } @@ -3567,7 +3565,7 @@ bool BfModule::CheckDefineMemberProtection(BfProtection protection, BfType* memb void BfModule::AddDependency(BfType* usedType, BfType* userType, BfDependencyMap::DependencyFlags flags, BfDepContext* depContext) { if (usedType == userType) - return; + return; if (((flags & BfDependencyMap::DependencyFlag_ConstValue) != 0) && (mContext->mCurTypeState != NULL) && (mContext->mCurTypeState->mResolveKind == BfTypeState::ResolveKind_FieldType)) { @@ -3579,7 +3577,7 @@ void BfModule::AddDependency(BfType* usedType, BfType* userType, BfDependencyMap { if (userType->IsMethodRef()) { - // We cannot short-circuit dependencies because of method group ref counting + // We cannot short-circuit dependencies because of method group ref counting } else return; @@ -3622,7 +3620,7 @@ void BfModule::AddDependency(BfType* usedType, BfType* userType, BfDependencyMap if ((mCurMethodState != NULL) && (mCurMethodState->mHotDataReferenceBuilder != NULL) && (usedType != mCurTypeInstance) && (isDataAccess)) { bool addType = true; - auto checkType = usedType; + auto checkType = usedType; PopulateType(checkType, BfPopulateType_Data); if (checkType->IsValuelessType()) addType = false; @@ -3641,7 +3639,7 @@ void BfModule::AddDependency(BfType* usedType, BfType* userType, BfDependencyMap addType = false; } } - + if (addType) { auto checkTypeInst = checkType->ToTypeInstance(); @@ -3669,7 +3667,7 @@ void BfModule::AddDependency(BfType* usedType, BfType* userType, BfDependencyMap if ((!mCompiler->mIsResolveOnly) && (mIsReified)) { - auto usingModule = userType->GetModule(); + auto usingModule = userType->GetModule(); BfModule* usedModule; if (usedType->IsFunction()) { @@ -3695,7 +3693,7 @@ void BfModule::AddDependency(BfType* usedType, BfType* userType, BfDependencyMap } } } - + if ((mCurMethodInstance != NULL) && (mCurMethodInstance->mMethodInfoEx != NULL) && (flags != BfDependencyMap::DependencyFlag_MethodGenericArg)) { // When we are specializing a method, usage of that specialized type is already handled with DependencyFlag_MethodGenericArg @@ -3711,7 +3709,7 @@ void BfModule::AddDependency(BfType* usedType, BfType* userType, BfDependencyMap { // Cause a rebuild but not an outright deletion of the type // We can only do this if the 'usedType' can actually hold the dependency which can actually trigger a deletion chain - depFlag = BfDependencyMap::DependencyFlag_GenericArgRef; + depFlag = BfDependencyMap::DependencyFlag_GenericArgRef; } } @@ -3731,7 +3729,7 @@ void BfModule::AddDependency(BfType* usedType, BfType* userType, BfDependencyMap } AddDependency(underlyingType, userType, depFlag); - } + } } else if (!usedType->IsGenericTypeInstance()) { @@ -3803,7 +3801,7 @@ void BfModule::AddCallDependency(BfMethodInstance* methodInstance, bool devirtua if (devirtualized) mCurMethodState->mHotDataReferenceBuilder->mDevirtualizedCalledMethods.Add(methodInstance->mHotMethod); else - mCurMethodState->mHotDataReferenceBuilder->mCalledMethods.Add(methodInstance->mHotMethod); + mCurMethodState->mHotDataReferenceBuilder->mCalledMethods.Add(methodInstance->mHotMethod); } } @@ -3832,7 +3830,7 @@ void BfModule::PopulateGlobalContainersList(const BfGlobalLookup& globalLookup) userTypeDef = mCurMethodInstance->mMethodDef->mDeclaringType; if (userTypeDef == NULL) userTypeDef = mCurTypeInstance->mTypeDef; - + if (mContext->mCurTypeState->mGlobalContainerCurUserTypeDef != userTypeDef) { mContext->mCurTypeState->mGlobalContainers.Clear(); @@ -3926,14 +3924,14 @@ bool BfModule::CheckInternalProtection(BfTypeDef* usingTypeDef) { if ((mCurTypeInstance != NULL) && (mCurTypeInstance->IsSpecializedType())) return true; - if ((mCurMethodInstance != NULL) && + if ((mCurMethodInstance != NULL) && ((mCurMethodInstance->mIsUnspecializedVariation) || (mCurMethodInstance->IsSpecializedGenericMethod()))) return true; auto internalAccessSet = GetInternalAccessSet(); if (internalAccessSet == NULL) return false; - + for (auto& nameComposite : internalAccessSet->mNamespaces) { if (usingTypeDef->mNamespace.StartsWith(nameComposite)) @@ -3966,9 +3964,9 @@ BfModuleOptions BfModule::GetModuleOptions() moduleOptions.mEmitDebugInfo = mCompiler->mOptions.mEmitDebugInfo ? 1 : mCompiler->mOptions.mEmitLineInfo ? 2 : 0; if (mProject != NULL) { - moduleOptions.mSIMDSetting = mProject->mCodeGenOptions.mSIMDSetting; - moduleOptions.mOptLevel = mProject->mCodeGenOptions.mOptLevel; - } + moduleOptions.mSIMDSetting = mProject->mCodeGenOptions.mSIMDSetting; + moduleOptions.mOptLevel = mProject->mCodeGenOptions.mOptLevel; + } auto headModule = this; while (headModule->mParentModule != NULL) @@ -3985,7 +3983,7 @@ BfModuleOptions BfModule::GetModuleOptions() { auto typeOptions = mSystem->GetTypeOptions(typeInst->mTypeOptionsIdx); moduleOptions.mSIMDSetting = (BfSIMDSetting)BfTypeOptions::Apply((int)moduleOptions.mSIMDSetting, typeOptions->mSIMDSetting); - moduleOptions.mEmitDebugInfo = BfTypeOptions::Apply(moduleOptions.mEmitDebugInfo, typeOptions->mEmitDebugInfo); + moduleOptions.mEmitDebugInfo = BfTypeOptions::Apply(moduleOptions.mEmitDebugInfo, typeOptions->mEmitDebugInfo); moduleOptions.mOptLevel = (BfOptLevel)BfTypeOptions::Apply((int)moduleOptions.mOptLevel, (int)typeOptions->mOptimizationLevel); } } @@ -4038,7 +4036,7 @@ void BfModule::CheckAddFailType() // constantly warning-aware if ((mHadBuildError) || (mHadBuildWarning /*&& !mCompiler->mIsResolveOnly*/)) - { + { //mContext->mFailTypes.Add(mCurTypeInstance); } } @@ -4049,12 +4047,12 @@ void BfModule::MarkDerivedDirty(BfTypeInstance* typeInst) return; typeInst->mDirty = true; - + for (auto& dep : typeInst->mDependencyMap) { auto depType = dep.mKey; auto depFlags = dep.mValue.mFlags; - + if ((depFlags & BfDependencyMap::DependencyFlag_DerivedFrom) != 0) { MarkDerivedDirty(depType->ToTypeInstance()); @@ -4063,18 +4061,18 @@ void BfModule::MarkDerivedDirty(BfTypeInstance* typeInst) } void BfModule::CreateStaticField(BfFieldInstance* fieldInstance, bool isThreadLocal) -{ +{ auto fieldType = fieldInstance->GetResolvedType(); auto field = fieldInstance->GetFieldDef(); if (fieldType->IsVar()) return; - + BfIRValue initValue; if (field->mIsConst) { if (fieldType->IsPointer()) - fieldType = fieldType->GetUnderlyingType(); + fieldType = fieldType->GetUnderlyingType(); } BfIRStorageKind storageKind = BfIRStorageKind_Normal; @@ -4085,14 +4083,14 @@ void BfModule::CreateStaticField(BfFieldInstance* fieldInstance, bool isThreadLo if ((!field->mIsExtern) && (storageKind != BfIRStorageKind_Import)) initValue = GetDefaultValue(fieldType); - + if (fieldInstance->mOwner->IsUnspecializedType()) { // Placeholder auto ptrVal = CreatePointerType(fieldType); mStaticFieldRefs[fieldInstance] = GetDefaultValue(ptrVal); } - else + else { BfLogSysM("Creating static field Module:%p Type:%p\n", this, fieldType); StringT<4096> staticVarName; @@ -4109,27 +4107,27 @@ void BfModule::CreateStaticField(BfFieldInstance* fieldInstance, bool isThreadLo else irType = mBfIRBuilder->MapType(fieldType, BfIRPopulateType_Eventually_Full); - BfIRValue globalVar = mBfIRBuilder->CreateGlobalVariable( + BfIRValue globalVar = mBfIRBuilder->CreateGlobalVariable( irType, false, BfIRLinkageType_External, initValue, - staticVarName, + staticVarName, isThreadLocal); - mBfIRBuilder->GlobalVar_SetAlignment(globalVar, fieldType->mAlign); + mBfIRBuilder->GlobalVar_SetAlignment(globalVar, fieldType->mAlign); if (storageKind != BfIRStorageKind_Normal) mBfIRBuilder->GlobalVar_SetStorageKind(globalVar, storageKind); BF_ASSERT(globalVar); - mStaticFieldRefs[fieldInstance] = globalVar; + mStaticFieldRefs[fieldInstance] = globalVar; } - } + } } void BfModule::ResolveConstField(BfTypeInstance* typeInstance, BfFieldInstance* fieldInstance, BfFieldDef* fieldDef, bool forceResolve) { bool autoCompleteOnly = mCompiler->IsAutocomplete(); - + BfType* fieldType = NULL; if (fieldInstance != NULL) { @@ -4159,8 +4157,8 @@ void BfModule::ResolveConstField(BfTypeInstance* typeInstance, BfFieldInstance* } if ((fieldInstance != NULL) && (fieldInstance->mConstIdx != -1) && (!forceResolve)) - return; - + return; + if (mContext->mFieldResolveReentrys.size() > 1) { if (mContext->mFieldResolveReentrys.IndexOf(fieldInstance, 1) != -1) @@ -4179,18 +4177,17 @@ void BfModule::ResolveConstField(BfTypeInstance* typeInstance, BfFieldInstance* } } - - mContext->mFieldResolveReentrys.push_back(fieldInstance); + mContext->mFieldResolveReentrys.push_back(fieldInstance); AutoPopBackmFieldResolveReentrys)> popTypeResolveReentry(&mContext->mFieldResolveReentrys); if (fieldInstance == NULL) popTypeResolveReentry.Pop(); - + auto typeDef = typeInstance->mTypeDef; BfIRValue constValue; if (fieldDef->mIsExtern) - { + { if (!fieldDef->mTypeRef->IsA()) { SetAndRestoreValue prevTypeInstance(mCurTypeInstance, typeInstance); @@ -4245,12 +4242,12 @@ void BfModule::ResolveConstField(BfTypeInstance* typeInstance, BfFieldInstance* } } else if (mBfIRBuilder != NULL) - { + { SetAndRestoreValue prevTypeInstance(mCurTypeInstance, typeInstance); SetAndRestoreValue prevIgnoreWrite(mBfIRBuilder->mIgnoreWrites, true); SetAndRestoreValue prevMethodInstance(mCurMethodInstance, NULL); - + BfMethodState methodState; SetAndRestoreValue prevMethodState(mCurMethodState, &methodState); methodState.mTempKind = BfMethodState::TempKind_Static; @@ -4320,7 +4317,7 @@ void BfModule::ResolveConstField(BfTypeInstance* typeInstance, BfFieldInstance* } BfType* BfModule::ResolveVarFieldType(BfTypeInstance* typeInstance, BfFieldInstance* fieldInstance, BfFieldDef* field) -{ +{ bool isDeclType = (field->mFieldDeclaration != NULL) && BfNodeDynCastExact(field->mTypeRef) != NULL; auto fieldType = fieldInstance->GetResolvedType(); @@ -4331,12 +4328,12 @@ BfType* BfModule::ResolveVarFieldType(BfTypeInstance* typeInstance, BfFieldInsta } bool staticOnly = (field->mIsStatic) && (!isDeclType); - + if (!fieldInstance->mIsInferredType) return fieldType; if ((!fieldType->IsVar()) && (!fieldType->IsUndefSizedArray())) - return fieldType; - + return fieldType; + SetAndRestoreValue prevTypeInstance(mCurTypeInstance, typeInstance); BfTypeState typeState(mCurTypeInstance, mContext->mCurTypeState); @@ -4346,13 +4343,13 @@ BfType* BfModule::ResolveVarFieldType(BfTypeInstance* typeInstance, BfFieldInsta if ((!field->mIsStatic) && (typeDef->mIsStatic)) { - AssertErrorState(); + AssertErrorState(); return fieldType; } - + bool hadInferenceCycle = false; if (mContext->mFieldResolveReentrys.size() > 1) - { + { if (mContext->mFieldResolveReentrys.IndexOf(fieldInstance, 1) != -1) { for (int i = 1; i < (int)mContext->mFieldResolveReentrys.size(); i++) @@ -4363,28 +4360,28 @@ BfType* BfModule::ResolveVarFieldType(BfTypeInstance* typeInstance, BfFieldInsta auto fieldModule = fieldOwner->mModule; SetAndRestoreValue prevIgnoreError(fieldModule->mIgnoreErrors, false); - fieldModule->Fail(StrFormat("Field '%s.%s' creates a type inference cycle", TypeToString(fieldOwner).c_str(), fieldDef->mName.c_str()), fieldDef->mTypeRef, true); + fieldModule->Fail(StrFormat("Field '%s.%s' creates a type inference cycle", TypeToString(fieldOwner).c_str(), fieldDef->mName.c_str()), fieldDef->mTypeRef, true); } - + return fieldType; } } mContext->mFieldResolveReentrys.push_back(fieldInstance); AutoPopBackmFieldResolveReentrys)> popTypeResolveReentry(&mContext->mFieldResolveReentrys); - SetAndRestoreValue prevResolvingVar(typeInstance->mResolvingVarField, true); - SetAndRestoreValue prevCtxResolvingVar(mContext->mResolvingVarField, true); - + SetAndRestoreValue prevResolvingVar(typeInstance->mResolvingVarField, true); + SetAndRestoreValue prevCtxResolvingVar(mContext->mResolvingVarField, true); + if ((field->GetInitializer() == NULL) && (!isDeclType)) { if ((field->mTypeRef->IsA()) || (field->mTypeRef->IsA())) - Fail("Implicitly-typed fields must be initialized", field->GetRefNode()); + Fail("Implicitly-typed fields must be initialized", field->GetRefNode()); return fieldType; } BfType* resolvedType = NULL; if (!hadInferenceCycle) - { + { BfTypeState typeState; typeState.mPrevState = mContext->mCurTypeState; typeState.mType = typeInstance; @@ -4392,9 +4389,9 @@ BfType* BfModule::ResolveVarFieldType(BfTypeInstance* typeInstance, BfFieldInsta typeState.mResolveKind = BfTypeState::ResolveKind_ResolvingVarType; SetAndRestoreValue prevTypeState(mContext->mCurTypeState, &typeState); - SetAndRestoreValue prevIgnoreWrite(mBfIRBuilder->mIgnoreWrites, true); + SetAndRestoreValue prevIgnoreWrite(mBfIRBuilder->mIgnoreWrites, true); SetAndRestoreValue prevMethodInstance(mCurMethodInstance, NULL/*ctorMethod.mMethodInstance*/); - + auto prevInsertBlock = mBfIRBuilder->GetInsertBlock(); BfMethodState methodState; @@ -4402,14 +4399,14 @@ BfType* BfModule::ResolveVarFieldType(BfTypeInstance* typeInstance, BfFieldInsta methodState.mTempKind = staticOnly ? BfMethodState::TempKind_Static : BfMethodState::TempKind_NonStatic; if (!staticOnly) { - //BfLocalVariable localVar; + //BfLocalVariable localVar; //methodState.mLocals.push_back(localVar); } - + if (isDeclType) { auto fieldDef = fieldInstance->GetFieldDef(); - resolvedType = ResolveTypeRef(fieldDef->mTypeRef, BfPopulateType_Identity); + resolvedType = ResolveTypeRef(fieldDef->mTypeRef, BfPopulateType_Identity); } else { @@ -4431,22 +4428,20 @@ BfType* BfModule::ResolveVarFieldType(BfTypeInstance* typeInstance, BfFieldInsta if (resolvedType == NULL) return fieldType; - + fieldInstance->SetResolvedType(resolvedType); if (field->mIsStatic) { - } else if (fieldInstance->mDataIdx >= 0) { - } else { BF_ASSERT(typeInstance->IsIncomplete()); } - + return resolvedType; } @@ -4465,7 +4460,7 @@ void BfModule::MarkFieldInitialized(BfFieldInstance* fieldInstance) int count = fieldCount; if (fieldIdx == -1) count = 1; - + //TODO: Under what circumstances could 'thisVariable' be NULL? auto thisVariable = GetThisVariable(); if (thisVariable != NULL) @@ -4490,14 +4485,14 @@ bool BfModule::IsThreadLocal(BfFieldInstance * fieldInstance) for (auto customAttr : fieldInstance->mCustomAttributes->mAttributes) { if (customAttr.mType->ToTypeInstance()->IsInstanceOf(mCompiler->mThreadStaticAttributeTypeDef)) - return true; + return true; } } return false; } BfTypedValue BfModule::GetFieldInitializerValue(BfFieldInstance* fieldInstance, BfExpression* initializer, BfFieldDef* fieldDef, BfType* fieldType, bool doStore) -{ +{ if (fieldDef == NULL) fieldDef = fieldInstance->GetFieldDef(); if (fieldType == NULL) @@ -4543,13 +4538,13 @@ BfTypedValue BfModule::GetFieldInitializerValue(BfFieldInstance* fieldInstance, int ceExecuteId = -1; if (mCompiler->mCeMachine != NULL) ceExecuteId = mCompiler->mCeMachine->mExecuteId; - - BfTypeState typeState; + + BfTypeState typeState; typeState.mType = mCurTypeInstance; typeState.mCurTypeDef = fieldDef->mDeclaringType; typeState.mCurFieldDef = fieldDef; SetAndRestoreValue prevTypeState(mContext->mCurTypeState, &typeState); - + BfConstResolver constResolver(this); if (fieldType->IsVar()) return constResolver.Resolve(initializer); @@ -4571,9 +4566,9 @@ BfTypedValue BfModule::GetFieldInitializerValue(BfFieldInstance* fieldInstance, fieldInstance->mHadConstEval = true; } return result; - } + } } - + BfExprEvaluator exprEvaluator(this); if (doStore) { @@ -4593,7 +4588,7 @@ BfTypedValue BfModule::GetFieldInitializerValue(BfFieldInstance* fieldInstance, if (fieldInstance != NULL) MarkFieldInitialized(fieldInstance); - + if ((doStore) && (result)) { if (fieldInstance->mResolvedType->IsUndefSizedArray()) @@ -4692,8 +4687,7 @@ void BfModule::AppendedObjectInit(BfFieldInstance* fieldInst) } void BfModule::CheckInterfaceMethod(BfMethodInstance* methodInstance) -{ - +{ } void BfModule::FindSubTypes(BfTypeInstance* classType, SizedArrayImpl* outVals, SizedArrayImpl* exChecks, bool isInterfacePass) @@ -4708,7 +4702,7 @@ void BfModule::FindSubTypes(BfTypeInstance* classType, SizedArrayImpl* outV continue; if (outVals->Contains(ifaceInst.mInterfaceType->mTypeId)) continue; - + if (ifaceInst.mDeclaringType->IsExtension()) { bool needsExCheck = false; @@ -4725,14 +4719,14 @@ void BfModule::FindSubTypes(BfTypeInstance* classType, SizedArrayImpl* outV // We can only do an 'exCheck' if we're actually going to slot this interface } } - } + } outVals->push_back(ifaceInst.mInterfaceType->mTypeId); } } else { - outVals->push_back(classType->mTypeId); + outVals->push_back(classType->mTypeId); } if (classType->mBaseType != NULL) @@ -4749,18 +4743,18 @@ void BfModule::CreateDynamicCastMethod() { // The main reason to punt on this method for ResolveOnly is because types can be created // and destroyed quickly during autocomplete and the typeId creep can generate lots of - // entries in the LLVM ConstantInt pool, primarily from the FindSubTypes call. We can + // entries in the LLVM ConstantInt pool, primarily from the FindSubTypes call. We can // remove this punt when we recycle typeId's mBfIRBuilder->CreateRet(mBfIRBuilder->CreateConstNull(mBfIRBuilder->MapTypeInstPtr(objType))); - mCurMethodState->mHadReturn = true; + mCurMethodState->mHadReturn = true; return; } bool isInterfacePass = mCurMethodInstance->mMethodDef->mName == BF_METHODNAME_DYNAMICCAST_INTERFACE; - - auto func = mCurMethodState->mIRFunction; - auto thisValue = mBfIRBuilder->GetArgument(0); - auto typeIdValue = mBfIRBuilder->GetArgument(1); + + auto func = mCurMethodState->mIRFunction; + auto thisValue = mBfIRBuilder->GetArgument(0); + auto typeIdValue = mBfIRBuilder->GetArgument(1); auto intPtrType = GetPrimitiveType(BfTypeCode_IntPtr); auto int32Type = GetPrimitiveType(BfTypeCode_Int32); @@ -4771,7 +4765,7 @@ void BfModule::CreateDynamicCastMethod() auto trueBB = mBfIRBuilder->CreateBlock("check.true"); //auto falseBB = mBfIRBuilder->CreateBlock("check.false"); auto exitBB = mBfIRBuilder->CreateBlock("exit"); - + SizedArray typeMatches; SizedArray exChecks; FindSubTypes(mCurTypeInstance, &typeMatches, &exChecks, isInterfacePass); @@ -4791,7 +4785,7 @@ void BfModule::CreateDynamicCastMethod() { BfBoxedType* boxedType = (BfBoxedType*)mCurTypeInstance; BfTypeInstance* innerType = boxedType->mElementType->ToTypeInstance(); - + FindSubTypes(innerType, &typeMatches, &exChecks, isInterfacePass); if (innerType->IsTypedPrimitive()) @@ -4825,27 +4819,27 @@ void BfModule::CreateDynamicCastMethod() auto switchStatement = mBfIRBuilder->CreateSwitch(typeIdValue, exitBB, (int)typeMatches.size() + (int)exChecks.size()); for (auto typeMatch : typeMatches) mBfIRBuilder->AddSwitchCase(switchStatement, GetConstValue32(typeMatch), trueBB); - + Array incomingFalses; for (auto ifaceTypeInst : exChecks) - { + { BfIRBlock nextBB = mBfIRBuilder->CreateBlock("exCheck", true); mBfIRBuilder->AddSwitchCase(switchStatement, GetConstValue32(ifaceTypeInst->mTypeId), nextBB); - mBfIRBuilder->SetInsertPoint(nextBB); + mBfIRBuilder->SetInsertPoint(nextBB); BfIRValue slotOfs = GetInterfaceSlotNum(ifaceTypeInst); auto ifacePtrPtr = mBfIRBuilder->CreateInBoundsGEP(vDataPtr, slotOfs/*, "iface"*/); - auto ifacePtr = mBfIRBuilder->CreateLoad(ifacePtrPtr); + auto ifacePtr = mBfIRBuilder->CreateLoad(ifacePtrPtr); auto cmpResult = mBfIRBuilder->CreateCmpNE(ifacePtr, mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, 0)); - mBfIRBuilder->CreateCondBr(cmpResult, trueBB, exitBB); + mBfIRBuilder->CreateCondBr(cmpResult, trueBB, exitBB); incomingFalses.push_back(nextBB); - } + } - mBfIRBuilder->AddBlock(trueBB); - mBfIRBuilder->SetInsertPoint(trueBB); + mBfIRBuilder->AddBlock(trueBB); + mBfIRBuilder->SetInsertPoint(trueBB); mBfIRBuilder->CreateBr(exitBB); mBfIRBuilder->AddBlock(exitBB); @@ -4855,9 +4849,9 @@ void BfModule::CreateDynamicCastMethod() auto nullValue = mBfIRBuilder->CreateConstNull(mBfIRBuilder->MapTypeInstPtr(objType)); for (auto incomingFalseBlock : incomingFalses) mBfIRBuilder->AddPhiIncoming(phi, nullValue, incomingFalseBlock); - mBfIRBuilder->AddPhiIncoming(phi, nullValue, curBlock); + mBfIRBuilder->AddPhiIncoming(phi, nullValue, curBlock); mBfIRBuilder->CreateRet(phi); - mCurMethodState->mHadReturn = true; + mCurMethodState->mHadReturn = true; } void BfModule::EmitEquals(BfTypedValue leftValue, BfTypedValue rightValue, BfIRBlock exitBB, bool strictEquals) @@ -4865,7 +4859,7 @@ void BfModule::EmitEquals(BfTypedValue leftValue, BfTypedValue rightValue, BfIRB BfExprEvaluator exprEvaluator(this); exprEvaluator.mExpectingType = mCurMethodInstance->mReturnType; - auto typeInst = rightValue.mType->ToTypeInstance(); + auto typeInst = rightValue.mType->ToTypeInstance(); exprEvaluator.PerformBinaryOperation((BfAstNode*)NULL, (BfAstNode*)NULL, strictEquals ? BfBinaryOp_StrictEquality : BfBinaryOp_Equality, NULL, BfBinOpFlag_IgnoreOperatorWithWrongResult, leftValue, rightValue); BfTypedValue result = exprEvaluator.GetResult(); if (result.mType != GetPrimitiveType(BfTypeCode_Boolean)) @@ -4882,23 +4876,23 @@ void BfModule::EmitEquals(BfTypedValue leftValue, BfTypedValue rightValue, BfIRB } void BfModule::CreateFakeCallerMethod(const String& funcName) -{ +{ if (mCurMethodInstance->mHasFailed) return; if (mCurMethodInstance->mMethodDef->mIsSkipCall) return; BF_ASSERT(mCurMethodInstance->mIRFunction); - + auto voidType = mBfIRBuilder->MapType(GetPrimitiveType(BfTypeCode_None)); SizedArray paramTypes; BfIRFunctionType funcType = mBfIRBuilder->CreateFunctionType(voidType, paramTypes); - BfIRFunction func = mBfIRBuilder->CreateFunction(funcType, BfIRLinkageType_Internal, "FORCELINK_" + funcName); + BfIRFunction func = mBfIRBuilder->CreateFunction(funcType, BfIRLinkageType_Internal, "FORCELINK_" + funcName); mBfIRBuilder->SetActiveFunction(func); auto entryBlock = mBfIRBuilder->CreateBlock("main", true); mBfIRBuilder->SetInsertPoint(entryBlock); - - BfMethodState methodState; + + BfMethodState methodState; methodState.mIRHeadBlock = entryBlock; SetAndRestoreValue prevMethodState(mCurMethodState, &methodState); @@ -4907,7 +4901,7 @@ void BfModule::CreateFakeCallerMethod(const String& funcName) if (mCurMethodInstance->GetStructRetIdx() == 0) { - auto retPtrType = CreatePointerType(mCurMethodInstance->mReturnType); + auto retPtrType = CreatePointerType(mCurMethodInstance->mReturnType); exprEvaluator.PushArg(GetDefaultTypedValue(retPtrType, true, BfDefaultValueKind_Const), args); } @@ -4927,7 +4921,7 @@ void BfModule::CreateFakeCallerMethod(const String& funcName) { auto paramType = mCurMethodInstance->GetParamType(paramIdx); if (paramType->IsValuelessType()) - continue; + continue; exprEvaluator.PushArg(GetDefaultTypedValue(paramType, true, paramType->IsComposite() ? BfDefaultValueKind_Addr : BfDefaultValueKind_Const), args); } @@ -4962,7 +4956,7 @@ void BfModule::CreateDelegateEqualsMethod() BfTypedValue rhsDelegate = exprEvaluator.LoadLocal(mCurMethodState->mLocals[1]); rhsDelegate = LoadValue(rhsDelegate); BfTypedValue rightTypedVal = BfTypedValue(mBfIRBuilder->CreateBitCast(rhsDelegate.mValue, mBfIRBuilder->MapType(mCurTypeInstance)), mCurTypeInstance); - + auto& targetFieldInstance = delegateType->mFieldInstances[0]; BfTypedValue leftValue = BfTypedValue(mBfIRBuilder->CreateInBoundsGEP(lhsDelegate.mValue, 0, targetFieldInstance.mDataIdx), targetFieldInstance.mResolvedType, true); @@ -4980,15 +4974,15 @@ void BfModule::CreateDelegateEqualsMethod() auto fieldType = fieldInstance->mResolvedType; if (fieldType->IsValuelessType()) - continue; + continue; if (fieldType->IsVar()) continue; if (fieldType->IsMethodRef()) continue; - + if (fieldType->IsRef()) fieldType = CreatePointerType(fieldType->GetUnderlyingType()); - + BfTypedValue leftValue = BfTypedValue(mBfIRBuilder->CreateInBoundsGEP(leftTypedVal.mValue, 0, fieldInstance->mDataIdx), fieldType, true); BfTypedValue rightValue = BfTypedValue(mBfIRBuilder->CreateInBoundsGEP(rightTypedVal.mValue, 0, fieldInstance->mDataIdx), fieldType, true); @@ -5003,30 +4997,30 @@ void BfModule::CreateDelegateEqualsMethod() mBfIRBuilder->CreateStore(GetConstValue(1, boolType), resultVal); mBfIRBuilder->CreateBr(exitBB); - + mBfIRBuilder->AddBlock(exitBB); mBfIRBuilder->SetInsertPoint(exitBB); - + auto loadedResult = mBfIRBuilder->CreateLoad(resultVal); ClearLifetimeEnds(); mBfIRBuilder->CreateRet(loadedResult); - mCurMethodState->mHadReturn = true; + mCurMethodState->mHadReturn = true; } void BfModule::CreateValueTypeEqualsMethod(bool strictEquals) -{ +{ if (mCurMethodInstance->mIsUnspecialized) return; - + if (mBfIRBuilder->mIgnoreWrites) return; - + BF_ASSERT(!mCurTypeInstance->IsBoxed()); - auto compareType = mCurMethodInstance->mParams[0].mResolvedType; + auto compareType = mCurMethodInstance->mParams[0].mResolvedType; bool isValid = true; auto boolType = GetPrimitiveType(BfTypeCode_Boolean); @@ -5035,7 +5029,7 @@ void BfModule::CreateValueTypeEqualsMethod(bool strictEquals) mBfIRBuilder->CreateRet(GetDefaultValue(boolType)); return; } - + if (compareType->IsTypedPrimitive()) { BfExprEvaluator exprEvaluator(this); @@ -5049,7 +5043,7 @@ void BfModule::CreateValueTypeEqualsMethod(bool strictEquals) auto compareDType = compareType->ToDependedType(); BfTypeInstance* compareTypeInst = compareType->ToTypeInstance(); if (compareTypeInst != NULL) - { + { if (compareType->IsPrimitiveType()) compareTypeInst = GetWrappedStructType(compareType); if ((compareTypeInst == NULL) || (!compareTypeInst->IsValueType())) @@ -5058,7 +5052,7 @@ void BfModule::CreateValueTypeEqualsMethod(bool strictEquals) } mBfIRBuilder->PopulateType(compareTypeInst); } - + if (!isValid) { ClearLifetimeEnds(); @@ -5071,7 +5065,7 @@ void BfModule::CreateValueTypeEqualsMethod(bool strictEquals) auto refNode = mCurTypeInstance->mTypeDef->GetRefNode(); if (refNode == NULL) refNode = mCompiler->mValueTypeTypeDef->GetRefNode(); - UpdateSrcPos(refNode); + UpdateSrcPos(refNode); SetIllegalSrcPos(); auto resultVal = CreateAlloca(boolType); @@ -5086,7 +5080,7 @@ void BfModule::CreateValueTypeEqualsMethod(bool strictEquals) else if (compareType->IsSizedArray()) { auto sizedArrayType = (BfSizedArrayType*)compareType; - + auto _SizedIndex = [&](BfIRValue target, BfIRValue index) { BfTypedValue result; @@ -5129,9 +5123,9 @@ void BfModule::CreateValueTypeEqualsMethod(bool strictEquals) else { for (int dataIdx = 0; dataIdx < sizedArrayType->mElementCount; dataIdx++) - { + { BfTypedValue leftValue = _SizedIndex(mCurMethodState->mLocals[0]->mValue, mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, dataIdx)); - BfTypedValue rightValue = _SizedIndex(mCurMethodState->mLocals[1]->mValue, mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, dataIdx)); + BfTypedValue rightValue = _SizedIndex(mCurMethodState->mLocals[1]->mValue, mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, dataIdx)); EmitEquals(leftValue, rightValue, exitBB, strictEquals); } } @@ -5148,8 +5142,8 @@ void BfModule::CreateValueTypeEqualsMethod(bool strictEquals) // We only need to compare the 'this' capture. The rationale is that it's impossible to capture any other non-matching // values for the same method reference -- they will always refer back to the same local variables. int dataIdx = methodRefType->GetDataIdxFromParamIdx(-1); - if (dataIdx != -1) - { + if (dataIdx != -1) + { bool failed = false; BfTypedValue leftValue = exprEvaluator.DoImplicitArgCapture(NULL, methodInstance, methodRefType->GetParamIdxFromDataIdx(dataIdx), failed, BfImplicitParamKind_General, leftTypedVal); BfTypedValue rightValue = exprEvaluator.DoImplicitArgCapture(NULL, methodInstance, methodRefType->GetParamIdxFromDataIdx(dataIdx), failed, BfImplicitParamKind_General, rightTypedVal); @@ -5166,7 +5160,7 @@ void BfModule::CreateValueTypeEqualsMethod(bool strictEquals) BfTypedValue rightTypedVal = exprEvaluator.LoadLocal(mCurMethodState->mLocals[1]); auto dscrType = compareTypeInst->GetDiscriminatorType(); - + BfTypedValue leftValue = ExtractValue(leftTypedVal, NULL, 2); leftValue = LoadValue(leftValue); BfTypedValue rightValue = ExtractValue(rightTypedVal, NULL, 2); @@ -5176,7 +5170,7 @@ void BfModule::CreateValueTypeEqualsMethod(bool strictEquals) BfTypedValue rightPayload = ExtractValue(rightTypedVal, NULL, 1); EmitEquals(leftValue, rightValue, exitBB, strictEquals); - + int enumCount = 0; for (auto& fieldRef : compareTypeInst->mFieldInstances) { @@ -5187,7 +5181,7 @@ void BfModule::CreateValueTypeEqualsMethod(bool strictEquals) enumCount = -fieldInstance->mDataIdx; } } - + if (enumCount > 0) { BfIRBlock matchedBlock = mBfIRBuilder->CreateBlock("matched"); @@ -5223,7 +5217,7 @@ void BfModule::CreateValueTypeEqualsMethod(bool strictEquals) leftTuple = Cast(NULL, leftPayload, fieldInstance->mResolvedType, BfCastFlags_Force); rightTuple = Cast(NULL, rightPayload, fieldInstance->mResolvedType, BfCastFlags_Force); } - + EmitEquals(leftTuple, rightTuple, exitBB, strictEquals); mBfIRBuilder->CreateBr(matchedBlock); @@ -5235,7 +5229,7 @@ void BfModule::CreateValueTypeEqualsMethod(bool strictEquals) mBfIRBuilder->AddBlock(matchedBlock); mBfIRBuilder->SetInsertPoint(matchedBlock); } - } + } else if (compareTypeInst->IsUnion()) { auto innerType = compareTypeInst->GetUnionInnerType(); @@ -5255,7 +5249,7 @@ void BfModule::CreateValueTypeEqualsMethod(bool strictEquals) } } else - { + { BfExprEvaluator exprEvaluator(this); BfTypedValue leftTypedVal = exprEvaluator.LoadLocal(mCurMethodState->mLocals[0]); BfTypedValue rightTypedVal = exprEvaluator.LoadLocal(mCurMethodState->mLocals[1]); @@ -5269,11 +5263,11 @@ void BfModule::CreateValueTypeEqualsMethod(bool strictEquals) if (fieldInstance->mResolvedType->IsValuelessType()) continue; - + if (fieldInstance->mResolvedType->IsVar()) continue; - BfTypedValue leftValue = ExtractValue(leftTypedVal, fieldInstance, fieldInstance->mDataIdx); + BfTypedValue leftValue = ExtractValue(leftTypedVal, fieldInstance, fieldInstance->mDataIdx); BfTypedValue rightValue = ExtractValue(rightTypedVal, fieldInstance, fieldInstance->mDataIdx); if (!fieldInstance->mResolvedType->IsComposite()) @@ -5287,7 +5281,7 @@ void BfModule::CreateValueTypeEqualsMethod(bool strictEquals) auto baseTypeInst = compareTypeInst->mBaseType; if ((baseTypeInst != NULL) && (baseTypeInst->mTypeDef != mCompiler->mValueTypeTypeDef)) - { + { BfTypedValue leftValue = Cast(NULL, leftTypedVal, baseTypeInst); BfTypedValue rightValue = Cast(NULL, rightTypedVal, baseTypeInst); EmitEquals(leftValue, rightValue, exitBB, strictEquals); @@ -5296,21 +5290,21 @@ void BfModule::CreateValueTypeEqualsMethod(bool strictEquals) mBfIRBuilder->CreateStore(GetConstValue(1, boolType), resultVal); mBfIRBuilder->CreateBr(exitBB); - + mBfIRBuilder->AddBlock(exitBB); mBfIRBuilder->SetInsertPoint(exitBB); - + auto loadedResult = mBfIRBuilder->CreateLoad(resultVal); ClearLifetimeEnds(); mBfIRBuilder->CreateRet(loadedResult); - mCurMethodState->mHadReturn = true; + mCurMethodState->mHadReturn = true; } BfIRValue BfModule::CreateClassVDataGlobal(BfTypeInstance* typeInstance, int* outNumElements, String* outMangledName) -{ +{ if (mBfIRBuilder->mIgnoreWrites) return mBfIRBuilder->GetFakeVal(); @@ -5322,8 +5316,8 @@ BfIRValue BfModule::CreateClassVDataGlobal(BfTypeInstance* typeInstance, int* ou { auto idVal = mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, typeInstance->mTypeId); return mBfIRBuilder->CreateIntToPtr(idVal, mBfIRBuilder->MapType(CreatePointerType(classVDataType))); - } - + } + BfIRValue* globalVariablePtr = NULL; mClassVDataRefs.TryGetValue(typeInstance, &globalVariablePtr); @@ -5336,17 +5330,17 @@ BfIRValue BfModule::CreateClassVDataGlobal(BfTypeInstance* typeInstance, int* ou auto maxIFaceVirtIdx = 0; if (!typeInstance->IsInterface()) - { + { int dynCastDataElems = 1 + mCompiler->mMaxInterfaceSlots; numElements += ((dynCastDataElems * 4) + mSystem->mPtrSize - 1) / mSystem->mPtrSize; - numElements += typeInstance->GetOrigVTableSize(); + numElements += typeInstance->GetOrigVTableSize(); int ifaceMethodLen = typeInstance->GetIFaceVMethodSize(); if (typeInstance->mHotTypeData != NULL) - { + { if (typeInstance->mHotTypeData->mOrigInterfaceMethodsLength != -1) ifaceMethodLen = typeInstance->mHotTypeData->mOrigInterfaceMethodsLength; - } + } numElements += ifaceMethodLen; } @@ -5358,7 +5352,7 @@ BfIRValue BfModule::CreateClassVDataGlobal(BfTypeInstance* typeInstance, int* ou String memberName = "sBfClassVData"; if ((typeInstance->mHotTypeData != NULL) && ((typeInstance->mHotTypeData->mHadDataChange) || (typeInstance->mHotTypeData->mPendingDataChange))) - { + { auto curVersion = typeInstance->mHotTypeData->GetLatestVersion(); memberName += "_"; memberName += BfTypeUtils::HashEncode64(curVersion->mDataHash.mLow); @@ -5383,14 +5377,14 @@ BfIRValue BfModule::CreateClassVDataGlobal(BfTypeInstance* typeInstance, int* ou { BfLogSysM("Creating VData %s\n", classVDataName.c_str()); auto arrayType = mBfIRBuilder->GetSizedArrayType(mBfIRBuilder->GetPrimitiveType(BfTypeCode_NullPtr), numElements); - globalVariable = mBfIRBuilder->CreateGlobalVariable( + globalVariable = mBfIRBuilder->CreateGlobalVariable( arrayType, true, BfIRLinkageType_External, BfIRValue(), - classVDataName); + classVDataName); - mClassVDataRefs[typeInstance] = globalVariable; + mClassVDataRefs[typeInstance] = globalVariable; } return globalVariable; } @@ -5404,7 +5398,7 @@ BfIRValue BfModule::GetClassVDataPtr(BfTypeInstance* typeInstance) } BfIRValue BfModule::CreateClassVDataExtGlobal(BfTypeInstance* declTypeInst, BfTypeInstance* implTypeInst, int startVirtIdx) -{ +{ if (mBfIRBuilder->mIgnoreWrites) return mBfIRBuilder->GetFakeVal(); @@ -5420,7 +5414,7 @@ BfIRValue BfModule::CreateClassVDataExtGlobal(BfTypeInstance* declTypeInst, BfTy BF_ASSERT(declTypeInst == implTypeInst); else BF_ASSERT(implTypeInst->mInheritDepth > declTypeInst->mInheritDepth); - + if (declTypeInst != implTypeInst) { BfTypeInstance* highestImpl = declTypeInst; @@ -5432,7 +5426,7 @@ BfIRValue BfModule::CreateClassVDataExtGlobal(BfTypeInstance* declTypeInst, BfTy auto checkImplTypeInst = implTypeInst->mVirtualMethodTable[virtIdx].mImplementingMethod.mTypeInstance; if ((checkImplTypeInst != NULL) && (checkImplTypeInst->mInheritDepth > highestImpl->mInheritDepth)) - highestImpl = checkImplTypeInst; + highestImpl = checkImplTypeInst; } if (highestImpl != implTypeInst) @@ -5445,7 +5439,7 @@ BfIRValue BfModule::CreateClassVDataExtGlobal(BfTypeInstance* declTypeInst, BfTy BfIRValue* irValuePtr = NULL; if (mClassVDataExtRefs.TryGetValue(mapEntry, &irValuePtr)) - return *irValuePtr; + return *irValuePtr; PopulateType(declTypeInst, BfPopulateType_DataAndMethods); PopulateType(implTypeInst, BfPopulateType_DataAndMethods); @@ -5454,8 +5448,8 @@ BfIRValue BfModule::CreateClassVDataExtGlobal(BfTypeInstance* declTypeInst, BfTy if (declTypeInst != implTypeInst) { classVDataName += StrFormat("_%d", implTypeInst->mInheritDepth - declTypeInst->mInheritDepth); - } - + } + auto voidPtrType = GetPrimitiveType(BfTypeCode_NullPtr); auto voidPtrIRType = mBfIRBuilder->MapType(voidPtrType); @@ -5467,7 +5461,6 @@ BfIRValue BfModule::CreateClassVDataExtGlobal(BfTypeInstance* declTypeInst, BfTy if (implTypeInst->mVirtualMethodTable[virtIdx].mDeclaringMethod.mMethodNum == -1) break; // Start of an ext entry for another type - BfIRValue vValue; auto& entry = implTypeInst->mVirtualMethodTable[virtIdx]; BfMethodInstance* declaringMethodInstance = (BfMethodInstance*)entry.mDeclaringMethod; @@ -5495,7 +5488,7 @@ BfIRValue BfModule::CreateClassVDataExtGlobal(BfTypeInstance* declTypeInst, BfTy auto arrayType = mBfIRBuilder->GetSizedArrayType(mBfIRBuilder->GetPrimitiveType(BfTypeCode_NullPtr), numElements); auto globalVariable = mBfIRBuilder->CreateGlobalVariable(arrayType, true, - BfIRLinkageType_External, BfIRValue(), classVDataName); + BfIRLinkageType_External, BfIRValue(), classVDataName); BfIRType extVTableType = mBfIRBuilder->GetSizedArrayType(voidPtrIRType, (int)vData.size()); BfIRValue extVTableConst = mBfIRBuilder->CreateConstAgg_Value(extVTableType, vData); @@ -5506,7 +5499,7 @@ BfIRValue BfModule::CreateClassVDataExtGlobal(BfTypeInstance* declTypeInst, BfTy } BfIRValue BfModule::CreateTypeDataRef(BfType* type) -{ +{ if (mBfIRBuilder->mIgnoreWrites) { return mBfIRBuilder->CreateTypeOf(type); @@ -5518,18 +5511,18 @@ BfIRValue BfModule::CreateTypeDataRef(BfType* type) auto typeTypeInst = typeTypeDef->ToTypeInstance(); return mBfIRBuilder->Comptime_GetReflectType(type->mTypeId, mBfIRBuilder->MapType(typeTypeInst)); } - + PopulateType(type); BfIRValue globalVariable; - + BfIRValue* globalVariablePtr = NULL; if (mTypeDataRefs.TryGetValue(type, &globalVariablePtr)) { if (*globalVariablePtr) return mBfIRBuilder->CreateTypeOf(type, *globalVariablePtr); } - + auto typeTypeDef = ResolveTypeDef(mCompiler->mTypeTypeDef); auto typeTypeInst = typeTypeDef->ToTypeInstance(); auto typeInstance = type->ToTypeInstance(); @@ -5542,11 +5535,11 @@ BfIRValue BfModule::CreateTypeDataRef(BfType* type) else { typeDataName += "sBfTypeData."; - BfMangler::Mangle(typeDataName, mCompiler->GetMangleKind(), type, this); + BfMangler::Mangle(typeDataName, mCompiler->GetMangleKind(), type, this); } BfLogSysM("Creating TypeData %s\n", typeDataName.c_str()); - + globalVariable = mBfIRBuilder->CreateGlobalVariable(mBfIRBuilder->MapTypeInst(typeTypeInst, BfIRPopulateType_Full), true, BfIRLinkageType_External, BfIRValue(), typeDataName); mBfIRBuilder->SetReflectTypeData(mBfIRBuilder->MapType(type), globalVariable); @@ -5666,7 +5659,7 @@ void BfModule::EncodeAttributeData(BfTypeInstance* typeInstance, BfType* argType else { Fail(StrFormat("Unhandled attribute constant data in '%s'", TypeToString(typeInstance).c_str())); - } + } } BfIRValue BfModule::CreateFieldData(BfFieldInstance* fieldInstance, int customAttrIdx) @@ -5675,14 +5668,14 @@ BfIRValue BfModule::CreateFieldData(BfFieldInstance* fieldInstance, int customAt BfFieldDef* fieldDef = fieldInstance->GetFieldDef(); auto typeInstance = fieldInstance->mOwner; - + BfType* intType = GetPrimitiveType(BfTypeCode_Int32); BfType* intPtrType = GetPrimitiveType(BfTypeCode_IntPtr); BfType* shortType = GetPrimitiveType(BfTypeCode_Int16); BfType* typeIdType = intType; BfTypeInstance* reflectFieldDataType = ResolveTypeDef(mCompiler->mReflectFieldDataDef)->ToTypeInstance(); - BfIRValue emptyValueType = mBfIRBuilder->mIgnoreWrites ? + BfIRValue emptyValueType = mBfIRBuilder->mIgnoreWrites ? mBfIRBuilder->CreateConstAgg(mBfIRBuilder->MapTypeInst(reflectFieldDataType->mBaseType), SizedArray()) : mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType->mBaseType), SizedArray()); BfIRValue fieldNameConst = GetStringObjectValue(fieldDef->mName, !mIsComptimeModule); @@ -5692,7 +5685,7 @@ BfIRValue BfModule::CreateFieldData(BfFieldInstance* fieldInstance, int customAt auto fieldType = fieldInstance->GetResolvedType(); if (fieldType->IsGenericParam()) { - //TODO: + //TODO: } else typeId = fieldType->mTypeId; @@ -5713,7 +5706,7 @@ BfIRValue BfModule::CreateFieldData(BfFieldInstance* fieldInstance, int customAt fieldFlags = (BfFieldFlags)(fieldFlags | BfFieldFlags_ReadOnly); if (fieldInstance->IsAppendedObject()) fieldFlags = (BfFieldFlags)(fieldFlags | BfFieldFlags_Appended); - + BfIRValue constValue; BfIRValue constValue2; if (fieldInstance->GetFieldDef()->mIsConst) @@ -5771,29 +5764,29 @@ BfIRValue BfModule::CreateFieldData(BfFieldInstance* fieldInstance, int customAt SizedArray fieldVals = { emptyValueType, - fieldNameConst, // mName - GetConstValue(typeId, typeIdType), // mFieldTypeId + fieldNameConst, // mName + GetConstValue(typeId, typeIdType), // mFieldTypeId constValue, // mData constValue2, // mDataHi GetConstValue(fieldFlags, shortType), // mFlags GetConstValue((isComptimeArg || mIsComptimeModule) ? fieldInstance->mFieldIdx : customAttrIdx, intType), // mCustomAttributesIdx - }; + }; FixConstValueParams(reflectFieldDataType, fieldVals, isComptimeArg); result = isComptimeArg ? mBfIRBuilder->CreateConstAgg(mBfIRBuilder->MapTypeInst(reflectFieldDataType, BfIRPopulateType_Full), fieldVals) : - mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType, BfIRPopulateType_Full), fieldVals); + mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType, BfIRPopulateType_Full), fieldVals); } else { SizedArray fieldVals = { emptyValueType, - fieldNameConst, // mName - GetConstValue(typeId, typeIdType), // mFieldTypeId + fieldNameConst, // mName + GetConstValue(typeId, typeIdType), // mFieldTypeId constValue, // mData GetConstValue(fieldFlags, shortType), // mFlags GetConstValue((isComptimeArg || mIsComptimeModule) ? fieldInstance->mFieldIdx : customAttrIdx, intType), // mCustomAttributesIdx - }; + }; FixConstValueParams(reflectFieldDataType, fieldVals, isComptimeArg); result = isComptimeArg ? mBfIRBuilder->CreateConstAgg(mBfIRBuilder->MapTypeInst(reflectFieldDataType, BfIRPopulateType_Full), fieldVals) : @@ -5806,14 +5799,14 @@ BfIRValue BfModule::CreateFieldData(BfFieldInstance* fieldInstance, int customAt BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStringIdMap, bool forceReflectFields, bool needsTypeData, bool needsTypeNames, bool needsVData) { if ((IsHotCompile()) && (!type->mDirty)) - return BfIRValue(); + return BfIRValue(); BfIRValue* irValuePtr = NULL; if (mTypeDataRefs.TryGetValue(type, &irValuePtr)) - { + { return *irValuePtr; } - + BfTypeInstance* typeInstance = type->ToTypeInstance(); BfType* typeInstanceType = ResolveTypeDef(mCompiler->mReflectTypeInstanceTypeDef); mBfIRBuilder->PopulateType(typeInstanceType, BfIRPopulateType_Full_ForceDefinition); @@ -5823,9 +5816,9 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin AssertErrorState(); return BfIRValue(); } - + BfIRValue typeTypeData; - int typeFlags = 0; + int typeFlags = 0; if (needsTypeData) { BfTypeInstance* typeInstanceTypeInstance = typeInstanceType->ToTypeInstance(); @@ -5866,15 +5859,15 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin typeDataSource = ResolveTypeDef(mCompiler->mReflectGenericParamType)->ToTypeInstance(); } else - typeDataSource = mContext->mBfTypeType; - + typeDataSource = mContext->mBfTypeType; + if ((!mTypeDataRefs.ContainsKey(typeDataSource)) && (typeDataSource != type) && (!mIsComptimeModule)) { CreateTypeData(typeDataSource, usedStringIdMap, false, true, needsTypeNames, true); - } + } typeTypeData = CreateClassVDataGlobal(typeDataSource); - } + } else typeTypeData = CreateClassVDataGlobal(typeInstanceType->ToTypeInstance()); @@ -5882,7 +5875,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin BfType* intType = GetPrimitiveType(BfTypeCode_Int32); BfType* intPtrType = GetPrimitiveType(BfTypeCode_IntPtr); BfType* shortType = GetPrimitiveType(BfTypeCode_Int16); - BfType* byteType = GetPrimitiveType(BfTypeCode_Int8); + BfType* byteType = GetPrimitiveType(BfTypeCode_Int8); BfType* typeIdType = intType; @@ -5891,9 +5884,9 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin auto voidPtrPtrIRType = mBfIRBuilder->GetPointerTo(voidPtrIRType); auto voidPtrNull = GetDefaultValue(voidPtrType); - SizedArray typeValueParams; + SizedArray typeValueParams; GetConstClassValueParam(typeTypeData, typeValueParams); - + FixConstValueParams(mContext->mBfObjectType, typeValueParams); BfIRValue objectData = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(mContext->mBfObjectType, BfIRPopulateType_Full), typeValueParams); @@ -5910,8 +5903,8 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin BfMangler::Mangle(typeDataName, mCompiler->GetMangleKind(), type, mContext->mScratchModule); } - int typeCode = BfTypeCode_None; - + int typeCode = BfTypeCode_None; + if (typeInstance != NULL) { BF_ASSERT((type->mDefineState >= BfTypeDefineState_DefinedAndMethodsSlotted) || mIsComptimeModule); @@ -5932,7 +5925,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin typeCode = BfTypeCode_Pointer; typeFlags |= BfTypeFlags_Pointer; } - + if (type->IsObject()) { typeFlags |= BfTypeFlags_Object; @@ -5943,7 +5936,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin typeFlags |= BfTypeFlags_HasDestructor; } } - if (type->IsStruct()) + if (type->IsStruct()) typeFlags |= BfTypeFlags_Struct; if (type->IsInterface()) typeFlags |= BfTypeFlags_Interface; @@ -5953,14 +5946,14 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin if (((BfBoxedType*)type)->IsBoxedStructPtr()) typeFlags |= BfTypeFlags_Pointer; } - if (type->IsPrimitiveType()) + if (type->IsPrimitiveType()) typeFlags |= BfTypeFlags_Primitive; if (type->IsTypedPrimitive()) typeFlags |= BfTypeFlags_TypedPrimitive; if (type->IsTuple()) typeFlags |= BfTypeFlags_Tuple; if (type->IsNullable()) - typeFlags |= BfTypeFlags_Nullable; + typeFlags |= BfTypeFlags_Nullable; if (type->IsSizedArray()) typeFlags |= BfTypeFlags_SizedArray; if (type->IsConstExprValue()) @@ -6017,18 +6010,18 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin GetConstValue(type->mTypeId, typeIdType), // mTypeId GetConstValue(boxedTypeId, typeIdType), // mBoxedType GetConstValue(typeFlags, intType), // mTypeFlags - GetConstValue(memberDataOffset, intType), // mMemberDataOffset + GetConstValue(memberDataOffset, intType), // mMemberDataOffset GetConstValue(typeCode, byteType), // mTypeCode GetConstValue(type->mAlign, byteType), // mAlign GetConstValue(stackCount, byteType), // mAllocStackCountOverride }; FixConstValueParams(mContext->mBfTypeType, typeDataParams); auto typeData = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(mContext->mBfTypeType, BfIRPopulateType_Full), typeDataParams); - + if (typeInstance == NULL) { BfIRValue typeDataVar; - + if (needsTypeData) { if (type->IsPointer()) @@ -6037,14 +6030,14 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin SizedArray pointerTypeDataParms = { typeData, - GetConstValue(pointerType->mElementType->mTypeId, typeIdType), + GetConstValue(pointerType->mElementType->mTypeId, typeIdType), }; auto reflectPointerType = ResolveTypeDef(mCompiler->mReflectPointerType)->ToTypeInstance(); FixConstValueParams(reflectPointerType, pointerTypeDataParms); auto pointerTypeData = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectPointerType, BfIRPopulateType_Full), pointerTypeDataParms); typeDataVar = mBfIRBuilder->CreateGlobalVariable(mBfIRBuilder->MapTypeInst(reflectPointerType), true, - BfIRLinkageType_External, pointerTypeData, typeDataName); + BfIRLinkageType_External, pointerTypeData, typeDataName); mBfIRBuilder->GlobalVar_SetAlignment(typeDataVar, mSystem->mPtrSize); typeDataVar = mBfIRBuilder->CreateBitCast(typeDataVar, mBfIRBuilder->MapType(mContext->mBfTypeType)); } @@ -6053,7 +6046,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin auto refType = (BfRefType*)type; SizedArray refTypeDataParms = { - typeData, + typeData, GetConstValue(refType->mElementType->mTypeId, typeIdType), GetConstValue((int8)refType->mRefKind, byteType), }; @@ -6069,7 +6062,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin else if (type->IsSizedArray()) { auto sizedArrayType = (BfSizedArrayType*)type; - SizedArray sizedArrayTypeDataParms = + SizedArray sizedArrayTypeDataParms = { typeData, GetConstValue(sizedArrayType->mElementType->mTypeId, typeIdType), @@ -6127,21 +6120,21 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin } else typeDataVar = mBfIRBuilder->CreateConstNull(mBfIRBuilder->MapType(mContext->mBfTypeType)); - + mTypeDataRefs[type] = typeDataVar; return typeDataVar; } - + // Reserve position mTypeDataRefs[typeInstance] = BfIRValue(); - + if ((typeInstance->IsReified()) && (!mIsComptimeModule)) PopulateType(typeInstance, BfPopulateType_DataAndMethods); - + BfTypeDef* typeDef = typeInstance->mTypeDef; StringT<512> mangledName; BfMangler::Mangle(mangledName, mCompiler->GetMangleKind(), typeInstance, typeInstance->mModule); - + if (!mIsComptimeModule) { for (int methodIdx = 0; methodIdx < (int)typeDef->mMethods.size(); methodIdx++) @@ -6169,13 +6162,13 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin } } } - + SizedArray vData; BfIRValue classVDataVar; String classVDataName; if (typeInstance->mSlotNum >= 0) { - // For interfaces we ONLY emit the slot num + // For interfaces we ONLY emit the slot num StringT<512> slotVarName; BfMangler::MangleStaticFieldName(slotVarName, mCompiler->GetMangleKind(), typeInstance, "sBfSlotOfs"); auto intType = GetPrimitiveType(BfTypeCode_Int32); @@ -6183,28 +6176,28 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin GetConstValue32(virtSlotIdx), slotVarName); } else if ((typeInstance->IsObject()) && (!typeInstance->IsUnspecializedType()) && (needsVData)) - { + { int dynCastDataElems = 0; int numElements = 1; int vDataOfs = 1; // The number of intptrs before the iface slot map - numElements += mCompiler->mMaxInterfaceSlots; + numElements += mCompiler->mMaxInterfaceSlots; if (!typeInstance->IsInterface()) { dynCastDataElems = 1 + mCompiler->mMaxInterfaceSlots; numElements += mCompiler->GetDynCastVDataCount(); numElements += typeInstance->mVirtualMethodTableSize; } - + int expectNumElements = 0; if (!typeDef->mIsStatic) { - classVDataVar = CreateClassVDataGlobal(typeInstance, &expectNumElements, &classVDataName); + classVDataVar = CreateClassVDataGlobal(typeInstance, &expectNumElements, &classVDataName); } - - vData.push_back(BfIRValue()); // Type* - + + vData.push_back(BfIRValue()); // Type* + SizedArray extVTableData; - + SizedArrayImpl* vFuncDataExt = &extVTableData; if (!typeInstance->IsInterface()) @@ -6216,11 +6209,11 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin dynCastData.Add(underlyingType->mInheritanceId); } else - dynCastData.Add(typeInstance->mInheritanceId); + dynCastData.Add(typeInstance->mInheritanceId); for (int i = 0; i < mCompiler->mMaxInterfaceSlots; i++) dynCastData.Add(0); dynCastData.Add(0); - + auto checkTypeInst = typeInstance; while (checkTypeInst != NULL) { @@ -6234,7 +6227,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin } checkTypeInst = checkTypeInst->GetImplBaseType(); } - + if (mSystem->mPtrSize == 8) { int intPtrCount = (dynCastDataElems + 1) / 2; @@ -6327,13 +6320,13 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin isBetter = true; isWorse = false; } - if (isBetter == isWorse) + if (isBetter == isWorse) CompareDeclTypes(checkTypeInst, interfaceEntry.mDeclaringType, prevEntry->mDeclaringType, isBetter, isWorse); if (isBetter == isWorse) { if (matchEntry->mAmbiguousEntries.empty()) matchEntry->mAmbiguousEntries.push_back(prevEntry); - matchEntry->mAmbiguousEntries.push_back(&interfaceEntry); + matchEntry->mAmbiguousEntries.push_back(&interfaceEntry); continue; } else if (isBetter) @@ -6355,7 +6348,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin } checkTypeInst = checkTypeInst->GetImplBaseType(); - } + } for (auto interfacePair : interfaceMap) { @@ -6366,7 +6359,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin if (error != NULL) { for (auto ambiguiousEntry : interfaceMatchEntry.mAmbiguousEntries) - mCompiler->mPassInstance->MoreInfo("See other declaration", ambiguiousEntry->mDeclaringType->GetRefNode()); + mCompiler->mPassInstance->MoreInfo("See other declaration", ambiguiousEntry->mDeclaringType->GetRefNode()); } } } @@ -6374,7 +6367,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin if ((!mIsComptimeModule) && (!typeInstance->IsInterface()) && (typeInstance->mVirtualMethodTableSize > 0) && (needsVData)) { int startTabIdx = (int)vData.size(); - + SizedArray origVirtTypeStack; BfTypeInstance* checkTypeInst = typeInstance; while (checkTypeInst != NULL) @@ -6385,17 +6378,17 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin Array origVTable; - int origVirtIdx = 0; + int origVirtIdx = 0; if (typeInstance->mTypeDef->mIsCombinedPartial) { - HashSet reslotNames; + HashSet reslotNames; for (int virtIdx = 0; virtIdx < (int)typeInstance->mVirtualMethodTable.size(); virtIdx++) { auto& entry = typeInstance->mVirtualMethodTable[virtIdx]; if (entry.mDeclaringMethod.mMethodNum == -1) continue; BfMethodInstance* methodInstance = (BfMethodInstance*)entry.mImplementingMethod; - if ((methodInstance == NULL) || + if ((methodInstance == NULL) || ((!mIsComptimeModule) && (!typeInstance->IsTypeMemberAccessible(methodInstance->mMethodDef->mDeclaringType, mProject)))) { if (origVTable.empty()) @@ -6439,7 +6432,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin if ((methodInstance->mChainType != BfMethodChainType_None) && (methodInstance->mChainType != BfMethodChainType_ChainHead)) continue; SlotVirtualMethod(methodInstance, &ambiguityContext); - } + } ambiguityContext.Finish(); } @@ -6463,7 +6456,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin else { BfMethodInstance* declaringMethodInstance = (BfMethodInstance*)entry.mDeclaringMethod; - if ((declaringMethodInstance != NULL) && (declaringMethodInstance->mMethodInstanceGroup->IsImplemented()) && (declaringMethodInstance->mIsReified)) + if ((declaringMethodInstance != NULL) && (declaringMethodInstance->mMethodInstanceGroup->IsImplemented()) && (declaringMethodInstance->mIsReified)) { BF_ASSERT(entry.mImplementingMethod.mTypeInstance->mMethodInstanceGroups[entry.mImplementingMethod.mMethodNum].IsImplemented()); BF_ASSERT(entry.mImplementingMethod.mTypeInstance->mMethodInstanceGroups[entry.mImplementingMethod.mMethodNum].mDefault->mIsReified); @@ -6492,7 +6485,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin { // We are within the original vtable size int idx = startTabIdx + origVirtIdx; - origVirtIdx++; + origVirtIdx++; vData.push_back(vValue); } else @@ -6501,7 +6494,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin BF_ASSERT(isInExts); } break; - } + } } if (!origVTable.empty()) @@ -6510,13 +6503,13 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin int ifaceMethodExtStart = (int)typeInstance->GetIFaceVMethodSize(); if (typeInstance->mHotTypeData != NULL) - { + { if (typeInstance->mHotTypeData->mOrigInterfaceMethodsLength != -1) ifaceMethodExtStart = typeInstance->mHotTypeData->mOrigInterfaceMethodsLength; } SizedArray ifaceMethodExtData; - + int iFaceMethodStartIdx = (int)vData.size(); vData.resize(iFaceMethodStartIdx + ifaceMethodExtStart); for (int i = iFaceMethodStartIdx; i < iFaceMethodStartIdx + ifaceMethodExtStart; i++) @@ -6529,7 +6522,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin // for (int i = 0; i < (int)typeInstance->mInterfaceMethodTable.size() - ifaceMethodExtStart; i++) // ifaceMethodExtData.Add(voidPtrNull); - + int ifaceEntryIdx = iFaceMethodStartIdx; for (auto& interfacePair : interfaceMap) { @@ -6544,14 +6537,14 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin bool makeEmpty = false; if ((!mIsComptimeModule) && (!typeInstance->IsTypeMemberAccessible(interfaceEntry->mDeclaringType, mProject))) makeEmpty = true; - + int endVirtualIdx = interfaceEntry->mStartVirtualIdx + interfaceEntry->mInterfaceType->mVirtualMethodTableSize; bool useExt = endVirtualIdx > ifaceMethodExtStart; for (int methodIdx = 0; methodIdx < (int)interfaceEntry->mInterfaceType->mMethodInstanceGroups.size(); methodIdx++) - { + { BfIRValue pushValue; - + BfMethodInstance* ifaceMethodInstance = interfaceEntry->mInterfaceType->mMethodInstanceGroups[methodIdx].mDefault; if ((ifaceMethodInstance == NULL) || (ifaceMethodInstance->mVirtualTableIdx == -1)) continue; @@ -6572,7 +6565,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin BF_ASSERT(methodInstance->mIsReified); // This doesn't work because we may have FOREIGN methods from implicit interface methods - //auto moduleMethodInst = GetMethodInstanceAtIdx(methodRef.mTypeInstance, methodRef.mMethodNum); + //auto moduleMethodInst = GetMethodInstanceAtIdx(methodRef.mTypeInstance, methodRef.mMethodNum); auto moduleMethodInst = ReferenceExternalMethodInstance(methodInstance, BfGetMethodInstanceFlag_NoInline); auto funcPtr = mBfIRBuilder->CreateBitCast(moduleMethodInst.mFunc, voidPtrIRType); pushValue = funcPtr; @@ -6598,7 +6591,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin ifaceMethodExtData[extIdx] = pushValue; } } - } + } if (typeInstance->IsBoxed()) { @@ -6607,7 +6600,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin { // Force override of GetHashCode so we use the pointer address as the hash code checkTypeInst = CreateBoxedType(ResolveTypeDef(mCompiler->mPointerTypeDef)); - + // Force override of GetHashCode so we use the pointer address as the hash code for (auto& checkIFace : checkTypeInst->mInterfaces) { @@ -6623,22 +6616,21 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin continue; auto& methodRef = checkTypeInst->mInterfaceMethodTable[checkIFace.mStartInterfaceTableIdx + methodIdx].mMethodRef; - + auto methodInstance = (BfMethodInstance*)methodRef; BF_ASSERT(methodInstance->mIsReified); // This doesn't work because we may have FOREIGN methods from implicit interface methods - //auto moduleMethodInst = GetMethodInstanceAtIdx(methodRef.mTypeInstance, methodRef.mMethodNum); + //auto moduleMethodInst = GetMethodInstanceAtIdx(methodRef.mTypeInstance, methodRef.mMethodNum); auto moduleMethodInst = ReferenceExternalMethodInstance(methodInstance, BfGetMethodInstanceFlag_NoInline); auto funcPtr = mBfIRBuilder->CreateBitCast(moduleMethodInst.mFunc, voidPtrIRType); int idx = checkIFace.mStartVirtualIdx + ifaceMethodInstance->mVirtualTableIdx; vData[iFaceMethodStartIdx + idx] = funcPtr; } - } } } - + if ((needsVData) && (!typeInstance->mTypeDef->mIsStatic) && (!mIsComptimeModule)) { BfIRValue ifaceMethodExtVar; @@ -6656,7 +6648,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin } for (auto& ifaceInstPair : interfaceMap) - { + { auto interfaceEntry = ifaceInstPair.mValue.mEntry; int slotNum = interfaceEntry->mInterfaceType->mSlotNum; if (slotNum >= 0) @@ -6680,7 +6672,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin if (mCompiler->IsHotCompile()) Fail("Interface slot collision error. Restart program or undo interface changes.", typeDef->GetRefNode()); else - Fail("Interface slot collision error", typeDef->GetRefNode()); + Fail("Interface slot collision error", typeDef->GetRefNode()); } } } @@ -6702,12 +6694,12 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin namespaceConst = mBfIRBuilder->CreateConstNull(mBfIRBuilder->MapType(stringType)); } - int baseTypeId = 0; + int baseTypeId = 0; if (typeInstance->mBaseType != NULL) - { + { baseTypeId = typeInstance->mBaseType->mTypeId; - } - + } + BfTypeOptions* typeOptions = NULL; if (typeInstance->mTypeOptionsIdx >= 0) typeOptions = mSystem->GetTypeOptions(typeInstance->mTypeOptionsIdx); @@ -6715,7 +6707,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin SizedArray customAttrs; BfTypeInstance* attributeType = mContext->mUnreifiedModule->ResolveTypeDef(mCompiler->mAttributeTypeDef)->ToTypeInstance(); - + BfIRValue castedClassVData; if (classVDataVar) castedClassVData = mBfIRBuilder->CreateBitCast(classVDataVar, mBfIRBuilder->MapType(mContext->mBfClassVDataPtrType)); @@ -6724,8 +6716,8 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin bool freflectIncludeTypeData = false; bool reflectIncludeAllFields = false; - bool reflectIncludeAllMethods = false; - + bool reflectIncludeAllMethods = false; + if (TypeIsSubTypeOf(typeInstance, attributeType)) { reflectIncludeAllFields = true; @@ -6750,9 +6742,9 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin }; reflectKind = GetReflectKind(reflectKind, typeInstance); - + // Fields - BfType* reflectFieldDataType = ResolveTypeDef(mCompiler->mReflectFieldDataDef); + BfType* reflectFieldDataType = ResolveTypeDef(mCompiler->mReflectFieldDataDef); BfIRValue emptyValueType = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType->ToTypeInstance()->mBaseType), SizedArray()); auto _HandleCustomAttrs = [&](BfCustomAttributes* customAttributes) @@ -6797,11 +6789,11 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin SizedArray data; int customAttrIdx = (int)customAttrs.size(); - + data.push_back((uint8)reflectAttributes.size()); for (auto attr : reflectAttributes) - { + { // Size prefix int sizeIdx = (int)data.size(); PUSH_INT16(0); // mSize @@ -6811,7 +6803,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin int ctorIdx = -1; int ctorCount = 0; - attr->mType->mTypeDef->PopulateMemberSets(); + attr->mType->mTypeDef->PopulateMemberSets(); BfMemberSetEntry* entry; if (attr->mType->mTypeDef->mMethodSet.TryGetWith(String("__BfCtor"), &entry)) { @@ -6832,14 +6824,14 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin auto ctorMethodInstance = GetRawMethodInstanceAtIdx(attr->mType, attr->mCtor->mIdx); int argIdx = 0; - + for (auto arg : attr->mCtorArgs) { auto argType = ctorMethodInstance->GetParamType(argIdx); EncodeAttributeData(typeInstance, argType, arg, data, usedStringIdMap); argIdx++; } - + int size = (int)data.size() - sizeIdx; *((uint16*)&data[sizeIdx]) = size; } @@ -6902,7 +6894,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin includeField = true; if ((fieldDef->mIsStatic) && ((fieldReflectKind & BfReflectKind_StaticFields) != 0)) includeField = true; - + if ((!fieldDef->mIsStatic) && (typeOptions != NULL)) includeField = typeOptions->Apply(includeField, BfOptionFlags_ReflectNonStaticFields); if ((fieldDef->mIsStatic) && (typeOptions != NULL)) @@ -6920,26 +6912,26 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin } // For a splattable type, we need to either include all fields or zero fields. This is to allow us to correctly splat - // params for reflected method calls even if we don't have reflection field info for the splatted type. This is + // params for reflected method calls even if we don't have reflection field info for the splatted type. This is // possible because we write out a SplatData structure containing just TypeIds in that case if (pass == 0) { if (!typeInstance->IsSplattable()) - break; + break; if (!skippedField) break; if (reflectFieldIndices.size() == 0) break; - } + } } - - SizedArray fieldTypes; + + SizedArray fieldTypes; bool is32Bit = mCompiler->mSystem->mPtrSize == 4; if ((typeInstance->IsPayloadEnum()) && (!typeInstance->IsBoxed())) - { - BfType* payloadType = typeInstance->GetUnionInnerType(); + { + BfType* payloadType = typeInstance->GetUnionInnerType(); if (!payloadType->IsValuelessType()) { BfIRValue payloadNameConst = GetStringObjectValue("$payload", !mIsComptimeModule); @@ -6964,7 +6956,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin emptyValueType, payloadNameConst, // mName GetConstValue(payloadType->mTypeId, typeIdType), // mFieldTypeId - GetConstValue(0, intPtrType), // mData + GetConstValue(0, intPtrType), // mData GetConstValue(BfFieldFlags_SpecialName | BfFieldFlags_EnumPayload, shortType), // mFlags GetConstValue(-1, intType), // mCustomAttributesIdx }; @@ -6982,7 +6974,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin dscrFieldVals = { emptyValueType, - dscrNameConst, // mName + dscrNameConst, // mName GetConstValue(dscrType->mTypeId, typeIdType), // mFieldTypeId GetConstValue(BF_ALIGN(payloadType->mSize, dscrType->mAlign), intPtrType), // mData GetConstValue(0, intPtrType), // mDataHi @@ -6995,7 +6987,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin dscrFieldVals = { emptyValueType, - dscrNameConst, // mName + dscrNameConst, // mName GetConstValue(dscrType->mTypeId, typeIdType), // mFieldTypeId GetConstValue(BF_ALIGN(payloadType->mSize, dscrType->mAlign), intPtrType), // mData GetConstValue(BfFieldFlags_SpecialName | BfFieldFlags_EnumDiscriminator, shortType), // mFlags @@ -7004,7 +6996,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin } auto dscrFieldData = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType->ToTypeInstance(), BfIRPopulateType_Full), dscrFieldVals); fieldTypes.push_back(dscrFieldData); - } + } for (auto fieldIdx : reflectFieldIndices) { @@ -7013,7 +7005,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin BfFieldInstance* fieldInstance = &typeInstance->mFieldInstances[fieldIdx]; fieldTypes.push_back(CreateFieldData(fieldInstance, _HandleCustomAttrs(fieldInstance->mCustomAttributes))); - } + } auto reflectFieldDataIRType = mBfIRBuilder->MapType(reflectFieldDataType); BfIRValue fieldDataPtr; @@ -7023,10 +7015,10 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin if ((type->IsSplattable()) && (type->IsStruct()) && (!type->IsValuelessType()) && (!typeInstance->mIsCRepr)) { BfTypeInstance* reflectFieldSplatDataType = ResolveTypeDef(mCompiler->mReflectFieldSplatDataDef)->ToTypeInstance(); - + SizedArray splatTypes; SizedArray splatOffsets; - + std::function _CheckSplat = [&](BfType* checkType, int offset) { auto checkTypeInstance = checkType->ToTypeInstance(); @@ -7091,7 +7083,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin { splatTypes.Add(GetConstValue(0, typeIdType)); splatOffsets.Add(GetConstValue(0, intType)); - } + } BfIRValue splatTypesConst = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapType(reflectFieldSplatDataType->mFieldInstances[0].mResolvedType), splatTypes); BfIRValue splatOffsetsConst = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapType(reflectFieldSplatDataType->mFieldInstances[1].mResolvedType), splatOffsets); @@ -7121,19 +7113,19 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin /// Methods - BfType* reflectMethodDataType = ResolveTypeDef(mCompiler->mReflectMethodDataDef); + BfType* reflectMethodDataType = ResolveTypeDef(mCompiler->mReflectMethodDataDef); BfType* reflectParamDataType = ResolveTypeDef(mCompiler->mReflectParamDataDef); BfType* reflectParamDataPtrType = CreatePointerType(reflectParamDataType); struct _SortedMethodInfo { BfMethodDef* mMethodDef; - BfMethodCustomAttributes* mMethodCustomAttributes; + BfMethodCustomAttributes* mMethodCustomAttributes; }; Array<_SortedMethodInfo> sortedMethodList; - SizedArray methodTypes; + SizedArray methodTypes; for (int methodIdx = 0; methodIdx < (int)typeDef->mMethods.size(); methodIdx++) { if (!needsTypeData) @@ -7169,10 +7161,10 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin bool includeMethod = reflectIncludeAllMethods; - BfMethodCustomAttributes* methodCustomAttributes = NULL; + BfMethodCustomAttributes* methodCustomAttributes = NULL; if ((defaultMethod->mMethodInfoEx != NULL) && (defaultMethod->mMethodInfoEx->mMethodCustomAttributes != NULL) && (defaultMethod->mMethodInfoEx->mMethodCustomAttributes->mCustomAttributes != NULL)) { - methodCustomAttributes = defaultMethod->mMethodInfoEx->mMethodCustomAttributes; + methodCustomAttributes = defaultMethod->mMethodInfoEx->mMethodCustomAttributes; for (auto& customAttr : defaultMethod->mMethodInfoEx->mMethodCustomAttributes->mCustomAttributes->mAttributes) { if (customAttr.mType->mTypeDef->mName->ToString() == "ReflectAttribute") @@ -7207,14 +7199,14 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin includeMethod = true; if ((methodDef->mIsStatic) && ((methodReflectKind & BfReflectKind_StaticMethods) != 0)) includeMethod = true; - + if ((methodDef->mMethodType == BfMethodType_Ctor) || (methodDef->mMethodType == BfMethodType_CtorCalcAppend)) { if ((methodReflectKind & BfReflectKind_Constructors) != 0) includeMethod = true; if ((methodDef->IsDefaultCtor()) && ((methodReflectKind & BfReflectKind_DefaultConstructor) != 0)) includeMethod = true; - } + } if ((!includeMethod) && (typeOptions != NULL)) includeMethod = ApplyTypeOptionMethodFilters(includeMethod, methodDef, typeOptions); @@ -7236,7 +7228,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin { int lhsKind = _GetMethodKind(lhs.mMethodDef); int rhsKind = _GetMethodKind(rhs.mMethodDef); - + if (lhsKind != rhsKind) return lhsKind < rhsKind; if (lhs.mMethodDef->mName != rhs.mMethodDef->mName) @@ -7253,7 +7245,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin BfModuleMethodInstance moduleMethodInstance; BfIRValue funcVal = voidPtrNull; - + if (((!typeInstance->IsBoxed()) || (!methodDef->mIsStatic)) && (!typeInstance->IsUnspecializedType()) && (methodDef->mMethodType != BfMethodType_Ignore) && @@ -7265,12 +7257,12 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin if (moduleMethodInstance.mFunc) funcVal = mBfIRBuilder->CreateBitCast(moduleMethodInstance.mFunc, voidPtrIRType); } - + BfIRValue methodNameConst = GetStringObjectValue(methodDef->mName, !mIsComptimeModule); - + BfMethodFlags methodFlags = defaultMethod->GetMethodFlags(); - - int customAttrIdx = -1; + + int customAttrIdx = -1; int returnCustomAttrIdx = -1; if (methodInfo.mMethodCustomAttributes != NULL) { @@ -7300,7 +7292,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin paramFlags = (ParamFlags)(paramFlags | ParamFlag_Implicit | ParamFlag_AppendIdx); if (defaultMethod->GetParamKind(paramIdx) == BfParamKind_Params) paramFlags = (ParamFlags)(paramFlags | ParamFlag_Params); - + BfIRValue paramNameConst = GetStringObjectValue(paramName, !mIsComptimeModule); int paramCustomAttrIdx = -1; @@ -7319,7 +7311,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin auto paramData = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapType(reflectParamDataType, BfIRPopulateType_Full), paramDataVals); paramVals.Add(paramData); } - + BfIRValue paramsVal; if (paramVals.size() > 0) { @@ -7333,7 +7325,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin else paramsVal = mBfIRBuilder->CreateConstNull(mBfIRBuilder->MapType(reflectParamDataPtrType)); - int vDataVal = -1; + int vDataVal = -1; if (defaultMethod->mVirtualTableIdx != -1) { int vDataIdx = -1; @@ -7370,11 +7362,11 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin if (vDataVal == -1) vDataVal = vDataIdx * mSystem->mPtrSize; } - + SizedArray methodDataVals = { emptyValueType, - methodNameConst, // mName + methodNameConst, // mName funcVal, // mFuncPtr paramsVal, GetConstValue(defaultMethod->mReturnType->mTypeId, typeIdType), @@ -7401,7 +7393,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin methodDataConst, "methods." + typeDataName); methodDataPtr = mBfIRBuilder->CreateBitCast(methodDataArray, methodDataPtrType); } - + ///// int interfaceCount = 0; @@ -7452,17 +7444,17 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin interfaceDataPtr = mBfIRBuilder->CreateBitCast(interfaceDataArray, interfaceDataPtrType); interfaceCount = (int)interfaces.size(); } - + BfIRValue interfaceMethodTable; int ifaceMethodTableSize = 0; - if ((wantsIfaceMethods) && (!typeInstance->IsInterface()) && (typeInstance->mIsReified) && (!typeInstance->IsUnspecializedType()) - && (!typeInstance->mInterfaceMethodTable.IsEmpty())) - { + if ((wantsIfaceMethods) && (!typeInstance->IsInterface()) && (typeInstance->mIsReified) && (!typeInstance->IsUnspecializedType()) + && (!typeInstance->mInterfaceMethodTable.IsEmpty())) + { SizedArray methods; - for (int tableIdx = 0; tableIdx < (int)typeInstance->mInterfaceMethodTable.size(); tableIdx++) + for (int tableIdx = 0; tableIdx < (int)typeInstance->mInterfaceMethodTable.size(); tableIdx++) { BfIRValue funcVal = voidPtrNull; - if ((tableIdx < (int)wantsIfaceMethod.size()) && (wantsIfaceMethod[tableIdx])) + if ((tableIdx < (int)wantsIfaceMethod.size()) && (wantsIfaceMethod[tableIdx])) { auto methodEntry = typeInstance->mInterfaceMethodTable[tableIdx]; if (!methodEntry.mMethodRef.IsNull()) @@ -7492,25 +7484,25 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin interfaceMethodTable = mBfIRBuilder->CreateBitCast(methodDataArray, voidPtrPtrIRType); ifaceMethodTableSize = (int)methods.size(); } - } + } if (!interfaceMethodTable) interfaceMethodTable = mBfIRBuilder->CreateConstNull(voidPtrPtrIRType); ///// - int underlyingType = 0; + int underlyingType = 0; if ((typeInstance->IsTypedPrimitive()) || (typeInstance->IsBoxed())) - { + { underlyingType = typeInstance->GetUnderlyingType()->mTypeId; - } + } int outerTypeId = 0; auto outerType = mContext->mUnreifiedModule->GetOuterType(typeInstance); if (outerType != NULL) - { + { outerTypeId = outerType->mTypeId; - } - + } + // BfIRValue customAttrDataPtr; @@ -7535,11 +7527,11 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin typeNameConst, // mName namespaceConst, // mNamespace GetConstValue(typeInstance->mInstSize, intType), // mInstSize - GetConstValue(typeInstance->mInstAlign, intType), // mInstAlign + GetConstValue(typeInstance->mInstAlign, intType), // mInstAlign GetConstValue(typeCustomAttrIdx, intType), // mCustomAttributes GetConstValue(baseTypeId, typeIdType), // mBaseType - GetConstValue(underlyingType, typeIdType), // mUnderlyingType - GetConstValue(outerTypeId, typeIdType), // mOuterType + GetConstValue(underlyingType, typeIdType), // mUnderlyingType + GetConstValue(outerTypeId, typeIdType), // mOuterType GetConstValue(typeInstance->mInheritanceId, intType), // mInheritanceId GetConstValue(typeInstance->mInheritanceCount, intType), // mInheritanceCount @@ -7548,13 +7540,13 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin GetConstValue(ifaceMethodTableSize, shortType), // mInterfaceMethodCount GetConstValue((int)methodTypes.size(), shortType), // mMethodDataCount GetConstValue(0, shortType), // mPropertyDataCount - GetConstValue((int)fieldTypes.size(), shortType), // mFieldDataCount + GetConstValue((int)fieldTypes.size(), shortType), // mFieldDataCount interfaceDataPtr, // mInterfaceDataPtr interfaceMethodTable, // mInterfaceMethodTable methodDataPtr, // mMethodDataPtr voidPtrNull, // mPropertyDataPtr - fieldDataPtr, // mFieldDataPtr + fieldDataPtr, // mFieldDataPtr customAttrDataPtr, // mCustomAttrDataPtr }; @@ -7562,7 +7554,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin BfIRType typeInstanceDataType = mBfIRBuilder->MapTypeInst(typeInstanceType->ToTypeInstance(), BfIRPopulateType_Full); FixConstValueParams(typeInstanceType->ToTypeInstance(), typeDataVals); auto typeInstanceData = mBfIRBuilder->CreateConstAgg_Value(typeInstanceDataType, typeDataVals); - + if (!needsTypeData) { // No need for anything beyond typeInstanceData @@ -7570,11 +7562,11 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin else if ((typeInstance->IsGenericTypeInstance()) && (typeInstance->IsUnspecializedType())) { auto genericTypeInstance = typeInstance->ToGenericTypeInstance(); - + SizedArray unspecializedData = { - typeInstanceData, - GetConstValue((int)genericTypeInstance->mGenericTypeInfo->mTypeGenericArguments.size(), byteType), // mGenericParamCount + typeInstanceData, + GetConstValue((int)genericTypeInstance->mGenericTypeInfo->mTypeGenericArguments.size(), byteType), // mGenericParamCount }; auto reflectUnspecializedGenericType = ResolveTypeDef(mCompiler->mReflectUnspecializedGenericType); typeInstanceDataType = mBfIRBuilder->MapTypeInst(reflectUnspecializedGenericType->ToTypeInstance(), BfIRPopulateType_Full); @@ -7600,14 +7592,14 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin SizedArray specGenericData = { - typeInstanceData, - GetConstValue(unspecializedType->mTypeId, typeIdType), // mUnspecialziedType + typeInstanceData, + GetConstValue(unspecializedType->mTypeId, typeIdType), // mUnspecialziedType resovledTypesPtr, // mFieldDataPtr }; typeInstanceDataType = mBfIRBuilder->MapTypeInst(reflectSpecializedGenericType->ToTypeInstance(), BfIRPopulateType_Full); typeInstanceData = mBfIRBuilder->CreateConstAgg_Value(typeInstanceDataType, specGenericData); - + if (typeInstance->IsArray()) { auto arrayType = (BfArrayType*)typeInstance; @@ -7620,14 +7612,14 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin typeInstanceData, GetConstValue(elementType->mSize, intType), // mElementSize GetConstValue(1, byteType), // mRank - GetConstValue(elementFieldInstance->mDataOffset, byteType), // mElementsDataOffset + GetConstValue(elementFieldInstance->mDataOffset, byteType), // mElementsDataOffset }; auto reflectArrayType = ResolveTypeDef(mCompiler->mReflectArrayType); typeInstanceDataType = mBfIRBuilder->MapTypeInst(reflectArrayType->ToTypeInstance(), BfIRPopulateType_Full); typeInstanceData = mBfIRBuilder->CreateConstAgg_Value(typeInstanceDataType, arrayData); } } - + BfIRValue typeDataVar; if (needsTypeData) { @@ -7646,40 +7638,40 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin } typeDataVar = mBfIRBuilder->CreateBitCast(typeDataVar, mBfIRBuilder->MapType(mContext->mBfTypeType)); - mTypeDataRefs[typeInstance] = typeDataVar; + mTypeDataRefs[typeInstance] = typeDataVar; if ((!mIsComptimeModule) && (classVDataVar)) - { + { BF_ASSERT(!classVDataName.IsEmpty()); vData[0] = mBfIRBuilder->CreateBitCast(typeDataVar, voidPtrIRType); auto classVDataConstDataType = mBfIRBuilder->GetSizedArrayType(voidPtrIRType, (int)vData.size()); auto classVDataConstData = mBfIRBuilder->CreateConstAgg_Value(classVDataConstDataType, vData); - mBfIRBuilder->GlobalVar_SetInitializer(classVDataVar, classVDataConstData); + mBfIRBuilder->GlobalVar_SetInitializer(classVDataVar, classVDataConstData); if (mCompiler->mOptions.mObjectHasDebugFlags) mBfIRBuilder->GlobalVar_SetAlignment(classVDataVar, 256); else mBfIRBuilder->GlobalVar_SetAlignment(classVDataVar, mContext->mBfClassVDataPtrType->mAlign); - + if (mBfIRBuilder->DbgHasInfo()) { BfType* voidType = GetPrimitiveType(BfTypeCode_None); BfType* voidPtrType = CreatePointerType(voidType); - + BfType* classVDataType = ResolveTypeDef(mCompiler->mClassVDataTypeDef); BfIRMDNode arrayType = mBfIRBuilder->DbgCreateArrayType(vData.size() * mSystem->mPtrSize * 8, mSystem->mPtrSize * 8, mBfIRBuilder->DbgGetType(voidPtrType), vData.size()); mBfIRBuilder->DbgCreateGlobalVariable(mDICompileUnit, classVDataName, classVDataName, BfIRMDNode(), 0, arrayType, false, classVDataVar); } } - + return typeDataVar; } BfIRValue BfModule::FixClassVData(BfIRValue value) { if ((!mCompiler->mOptions.mObjectHasDebugFlags) || (mIsComptimeModule)) - return value; + return value; auto intptrValue = mBfIRBuilder->CreatePtrToInt(value, BfTypeCode_IntPtr); auto maskedValue = mBfIRBuilder->CreateAnd(intptrValue, mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, (uint64)~0xFFULL)); return mBfIRBuilder->CreateIntToPtr(maskedValue, mBfIRBuilder->GetType(value)); @@ -7706,7 +7698,7 @@ void BfModule::CheckStaticAccess(BfTypeInstance* typeInstance) return; if (mCurMethodInstance->mMethodInstanceGroup->mOwner == typeInstance) return; - + auto checkTypeDef = typeInstance->mTypeDef; checkTypeDef->PopulateMemberSets(); BfMethodDef* nextMethodDef = NULL; @@ -7716,8 +7708,8 @@ void BfModule::CheckStaticAccess(BfTypeInstance* typeInstance) while (nextMethodDef != NULL) { auto checkMethod = nextMethodDef; - nextMethodDef = nextMethodDef->mNextWithSameName; - auto methodModule = GetMethodInstance(typeInstance, checkMethod, BfTypeVector()); + nextMethodDef = nextMethodDef->mNextWithSameName; + auto methodModule = GetMethodInstance(typeInstance, checkMethod, BfTypeVector()); if (methodModule) { auto methodInstance = methodModule.mMethodInstance; @@ -7738,13 +7730,13 @@ BfIRFunction BfModule::GetIntrinsic(BfMethodInstance* methodInstance, bool repor auto methodOwner = methodInstance->GetOwner(); auto methodDef = methodInstance->mMethodDef; auto methodDeclaration = methodDef->GetMethodDeclaration(); - + if (!methodDef->mIsExtern) return BfIRFunction(); - + if (methodInstance->GetCustomAttributes() == NULL) return BfIRFunction(); - + for (auto& customAttribute : methodInstance->GetCustomAttributes()->mAttributes) { String typeName = TypeToString(customAttribute.mType); @@ -7752,15 +7744,15 @@ BfIRFunction BfModule::GetIntrinsic(BfMethodInstance* methodInstance, bool repor { methodInstance->mIsIntrinsic = true; - auto constant = methodOwner->mConstHolder->GetConstant(customAttribute.mCtorArgs[0]); + auto constant = methodOwner->mConstHolder->GetConstant(customAttribute.mCtorArgs[0]); String error; - + if ((constant != NULL) && (constant->mTypeCode == BfTypeCode_StringId)) { int stringId = constant->mInt32; auto entry = mContext->mStringObjectIdMap[stringId]; String intrinName = entry.mString; - + // if (intrinName.StartsWith(":")) // { // SizedArray paramTypes; @@ -7795,10 +7787,10 @@ BfIRFunction BfModule::GetIntrinsic(BfMethodInstance* methodInstance, bool repor error = "Intrinsic name must be a constant string"; if (reportFailure) - { + { Fail(error, customAttribute.mRef); - } - } + } + } } return BfIRFunction(); @@ -7810,7 +7802,7 @@ BfIRFunction BfModule::GetBuiltInFunc(BfBuiltInFuncType funcTypeId) return mBfIRBuilder->GetFakeFunction(); if (!mBuiltInFuncs[(int)funcTypeId]) - { + { SizedArray paramTypes; auto nullPtrType = mBfIRBuilder->MapType(GetPrimitiveType(BfTypeCode_NullPtr)); auto intType = mBfIRBuilder->MapType(GetPrimitiveType(BfTypeCode_IntPtr)); @@ -7830,7 +7822,7 @@ BfIRFunction BfModule::GetBuiltInFunc(BfBuiltInFuncType funcTypeId) funcType = mBfIRBuilder->CreateFunctionType(int32Type, paramTypes, true); func = mBfIRBuilder->CreateFunction(funcType, BfIRLinkageType_External, "PrintF"); break; - case BfBuiltInFuncType_Malloc: + case BfBuiltInFuncType_Malloc: { if ((mCompiler->mOptions.mDebugAlloc) && (!mIsComptimeModule)) { @@ -7845,7 +7837,7 @@ BfIRFunction BfModule::GetBuiltInFunc(BfBuiltInFuncType funcTypeId) if (!func) { paramTypes.clear(); - paramTypes.push_back(intType); + paramTypes.push_back(intType); funcType = mBfIRBuilder->CreateFunctionType(nullPtrType, paramTypes); func = mBfIRBuilder->CreateFunction(funcType, BfIRLinkageType_External, funcName); mBfIRBuilder->Func_SetParamName(func, 1, "size"); @@ -7853,8 +7845,8 @@ BfIRFunction BfModule::GetBuiltInFunc(BfBuiltInFuncType funcTypeId) } } break; - case BfBuiltInFuncType_Free: - { + case BfBuiltInFuncType_Free: + { if ((mCompiler->mOptions.mDebugAlloc) && (!mIsComptimeModule)) { func = GetInternalMethod("Dbg_RawFree").mFunc; @@ -7875,9 +7867,9 @@ BfIRFunction BfModule::GetBuiltInFunc(BfBuiltInFuncType funcTypeId) } } } - break; + break; case BfBuiltInFuncType_LoadSharedLibraries: - paramTypes.clear(); + paramTypes.clear(); funcType = mBfIRBuilder->CreateFunctionType(voidType, paramTypes); func = mBfIRBuilder->CreateFunction(funcType, BfIRLinkageType_External, "BfLoadSharedLibraries"); break; @@ -7892,8 +7884,8 @@ BfIRFunction BfModule::GetBuiltInFunc(BfBuiltInFuncType funcTypeId) } void BfModule::ResolveGenericParamConstraints(BfGenericParamInstance* genericParamInstance, bool isUnspecialized, Array* deferredResolveTypes) -{ - BfGenericParamDef* genericParamDef = genericParamInstance->GetGenericParamDef(); +{ + BfGenericParamDef* genericParamDef = genericParamInstance->GetGenericParamDef(); BfExternalConstraintDef* externConstraintDef = genericParamInstance->GetExternConstraintDef(); BfConstraintDef* constraintDef = genericParamInstance->GetConstraintDef(); @@ -7901,11 +7893,11 @@ void BfModule::ResolveGenericParamConstraints(BfGenericParamInstance* genericPar BfAutoComplete* bfAutocomplete = NULL; if ((mCompiler->mResolvePassData != NULL) && (isUnspecialized)) - bfAutocomplete = mCompiler->mResolvePassData->mAutoComplete; + bfAutocomplete = mCompiler->mResolvePassData->mAutoComplete; if ((bfAutocomplete != NULL) && (genericParamDef != NULL)) - { - for (int nameIdx = 0; nameIdx < (int)genericParamDef->mNameNodes.size(); nameIdx++) + { + for (int nameIdx = 0; nameIdx < (int)genericParamDef->mNameNodes.size(); nameIdx++) { auto nameNode = genericParamDef->mNameNodes[nameIdx]; if (bfAutocomplete->IsAutocompleteNode(nameNode)) @@ -7915,11 +7907,11 @@ void BfModule::ResolveGenericParamConstraints(BfGenericParamInstance* genericPar bfAutocomplete->mInsertEndIdx = nameNode->GetSrcEnd(); if (nameIdx != 0) - { + { bfAutocomplete->AddEntry(AutoCompleteEntry("generic", nameNode->ToString().c_str()), filter); } } - } + } } for (auto constraint : constraintDef->mConstraints) @@ -7927,7 +7919,7 @@ void BfModule::ResolveGenericParamConstraints(BfGenericParamInstance* genericPar if (auto opConstraint = BfNodeDynCast(constraint)) { BfGenericOperatorConstraintInstance opConstraintInstance; - + if (opConstraint->mLeftType != NULL) { if (bfAutocomplete != NULL) @@ -7953,7 +7945,7 @@ void BfModule::ResolveGenericParamConstraints(BfGenericParamInstance* genericPar } if (opConstraint->mOpToken == NULL) - { + { FailAfter("Missing operator", (opConstraint->mLeftType != NULL) ? (BfAstNode*)opConstraint->mLeftType : (BfAstNode*)opConstraint->mOperatorToken); continue; } @@ -7986,7 +7978,7 @@ void BfModule::ResolveGenericParamConstraints(BfGenericParamInstance* genericPar continue; } } - + genericParamInstance->mOperatorConstraints.Add(opConstraintInstance); continue; @@ -8006,7 +7998,7 @@ void BfModule::ResolveGenericParamConstraints(BfGenericParamInstance* genericPar // `where T : Dictionay and TElem : IHashable` and we don't want to throw the error on `T` before we build `TElem` auto constraintType = ResolveTypeRef(constraintTypeRef, (deferredResolveTypes != NULL) ? BfPopulateType_Identity : BfPopulateType_Declaration, resolveFlags); if (constraintType != NULL) - { + { if (deferredResolveTypes != NULL) { PopulateType(constraintType, BfPopulateType_Declaration); @@ -8016,11 +8008,11 @@ void BfModule::ResolveGenericParamConstraints(BfGenericParamInstance* genericPar if ((constraintDef->mGenericParamFlags & BfGenericParamFlag_Const) != 0) { - bool isValidTypeCode = false; + bool isValidTypeCode = false; BfTypeCode typeCode = BfTypeCode_None; if (constraintType->IsTypedPrimitive()) - { + { auto underlyingType = constraintType->GetUnderlyingType(); if (underlyingType->IsPrimitiveType()) typeCode = ((BfPrimitiveType*)underlyingType)->mTypeDef->mTypeCode; @@ -8056,7 +8048,7 @@ void BfModule::ResolveGenericParamConstraints(BfGenericParamInstance* genericPar break; default: break; } - + if (isValidTypeCode) { genericParamInstance->mTypeConstraint = constraintType; @@ -8069,7 +8061,7 @@ void BfModule::ResolveGenericParamConstraints(BfGenericParamInstance* genericPar else { bool checkEquality = false; - + if (constraintType->IsVar()) { // From a `comptype` generic undef resolution. Ignore. @@ -8078,18 +8070,18 @@ void BfModule::ResolveGenericParamConstraints(BfGenericParamInstance* genericPar continue; } else if (constraintType->IsPrimitiveType()) - { + { if (isUnspecialized) { Fail("Primitive constraints are not allowed unless preceded with 'const'", constraintTypeRef); continue; - } + } checkEquality = true; } if (constraintType->IsArray()) { - if (isUnspecialized) + if (isUnspecialized) { Fail("Array constraints are not allowed. If a constant-sized array was intended, an type parameterized by a const generic param can be used (ie: where T : int[T2] where T2 : const int)", constraintTypeRef); continue; @@ -8110,13 +8102,13 @@ void BfModule::ResolveGenericParamConstraints(BfGenericParamInstance* genericPar } checkEquality = true; } - + if (checkEquality) { genericParamInstance->mTypeConstraint = constraintType; } else if (constraintType->IsInterface()) - { + { genericParamInstance->mInterfaceConstraints.push_back(constraintType->ToTypeInstance()); } else @@ -8159,7 +8151,7 @@ void BfModule::ResolveGenericParamConstraints(BfGenericParamInstance* genericPar String BfModule::GenericParamSourceToString(const BfGenericParamSource & genericParamSource) { if (genericParamSource.mMethodInstance != NULL) - { + { //auto methodInst = GetUnspecializedMethodInstance(genericParamSource.mMethodInstance, false); //SetAndRestoreValue prevMethodInst(mCurMethodInstance, methodInst); return MethodToString(genericParamSource.mMethodInstance); @@ -8199,7 +8191,7 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS origCheckArgType = origCheckArgType->GetUnderlyingType(); bool argIsReferenceType = false; - + int checkGenericParamFlags = 0; if (checkArgType->IsGenericParam()) { @@ -8207,7 +8199,7 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS checkGenericParamFlags = checkGenericParamInst->mGenericParamFlags; if (checkGenericParamInst->mTypeConstraint != NULL) checkArgType = checkGenericParamInst->mTypeConstraint; - + // if ((checkGenericParamFlags & (BfGenericParamFlag_Struct | BfGenericParamFlag_StructPtr)) != 0) // { // argMayBeReferenceType = false; @@ -8224,8 +8216,8 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS BfTypeInstance* typeConstraintInst = NULL; if (genericParamInst->mTypeConstraint != NULL) typeConstraintInst = genericParamInst->mTypeConstraint->ToTypeInstance(); - - if ((genericParamInst->mGenericParamFlags & BfGenericParamFlag_Struct) && + + if ((genericParamInst->mGenericParamFlags & BfGenericParamFlag_Struct) && ((checkGenericParamFlags & (BfGenericParamFlag_Struct | BfGenericParamFlag_Enum | BfGenericParamFlag_Var)) == 0) && (!checkArgType->IsValueType())) { if ((!ignoreErrors) && (PreFail())) @@ -8233,8 +8225,8 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS TypeToString(origCheckArgType).c_str(), genericParamInst->GetName().c_str(), GenericParamSourceToString(genericParamSource).c_str()), checkArgTypeRef); return false; } - - if ((genericParamInst->mGenericParamFlags & BfGenericParamFlag_StructPtr) && + + if ((genericParamInst->mGenericParamFlags & BfGenericParamFlag_StructPtr) && ((checkGenericParamFlags & (BfGenericParamFlag_StructPtr | BfGenericParamFlag_Var)) == 0) && (!checkArgType->IsPointer())) { if ((!ignoreErrors) && (PreFail())) @@ -8243,7 +8235,7 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS return false; } - if ((genericParamInst->mGenericParamFlags & BfGenericParamFlag_Class) && + if ((genericParamInst->mGenericParamFlags & BfGenericParamFlag_Class) && ((checkGenericParamFlags & (BfGenericParamFlag_Class | BfGenericParamFlag_Var)) == 0) && (!argIsReferenceType)) { if ((!ignoreErrors) && (PreFail())) @@ -8332,7 +8324,7 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS if (checkArgType->IsPointer()) { - auto ptrType = (BfPointerType*)checkArgType; + auto ptrType = (BfPointerType*)checkArgType; checkArgType = ptrType->mElementType; } @@ -8390,7 +8382,7 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS // Any primitive types and stuff can be allocated canAlloc = true; } - + if (!canAlloc) { if ((!ignoreErrors) && (PreFail())) @@ -8407,7 +8399,7 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS } if ((genericParamInst->mInterfaceConstraints.IsEmpty()) && (genericParamInst->mOperatorConstraints.IsEmpty()) && (genericParamInst->mTypeConstraint == NULL)) - return true; + return true; if (genericParamInst->mTypeConstraint != NULL) { @@ -8422,7 +8414,7 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS if (genericParamInst->mTypeConstraint->IsPrimitiveType()) { auto primType = (BfPrimitiveType*)genericParamInst->mTypeConstraint; - + // Let either an exact typematch or an undef pass through. Eventually instead of undefs we may want to do // actual expression comparisons, but we are overly permissive now and then we may fail on specialization if ((constExprValueType->mValue.mTypeCode != primType->mTypeDef->mTypeCode) && @@ -8505,7 +8497,7 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS constraintMatched = true; } else if (origCheckArgType->IsWrappableType()) - { + { if (origCheckArgType->IsSizedArray()) { auto sizedArrayType = (BfSizedArrayType*)origCheckArgType; @@ -8519,7 +8511,7 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS auto constExprValueType = (BfConstExprValueType*)convCheckConstraintInst->mGenericTypeInfo->mTypeGenericArguments[1]; if (sizedArrayType->mElementCount == constExprValueType->mValue.mInt64) constraintMatched = true; - } + } } } } @@ -8551,8 +8543,8 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS if (convCheckConstraint == NULL) return false; - BfTypeInstance* typeConstraintInst = convCheckConstraint->ToTypeInstance(); - + BfTypeInstance* typeConstraintInst = convCheckConstraint->ToTypeInstance(); + bool implementsInterface = false; if (origCheckArgType != checkArgType) { @@ -8563,7 +8555,7 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS implementsInterface = CanCast(BfTypedValue(BfIRValue::sValueless, checkArgType), convCheckConstraint); if ((!implementsInterface) && (origCheckArgType->IsWrappableType())) - { + { BfTypeInstance* wrappedStructType = GetWrappedStructType(origCheckArgType, false); if (TypeIsSubTypeOf(wrappedStructType, typeConstraintInst)) implementsInterface = true; @@ -8576,11 +8568,11 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS if (TypeIsSubTypeOf(wrappedStructType, typeConstraintInst)) implementsInterface = true; } - + if (!implementsInterface) { if ((!ignoreErrors) && (PreFail())) - *errorOut = Fail(StrFormat("Generic argument '%s', declared to be '%s' for '%s', must implement '%s'", genericParamInst->GetName().c_str(), + *errorOut = Fail(StrFormat("Generic argument '%s', declared to be '%s' for '%s', must implement '%s'", genericParamInst->GetName().c_str(), TypeToString(origCheckArgType).c_str(), GenericParamSourceToString(genericParamSource).c_str(), TypeToString(checkConstraint).c_str()), checkArgTypeRef); return false; } @@ -8592,8 +8584,8 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS if ((leftType != NULL) && (leftType->IsUnspecializedType())) leftType = ResolveGenericType(leftType, NULL, methodGenericArgs, mCurTypeInstance); if (leftType != NULL) - leftType = FixIntUnknown(leftType); - + leftType = FixIntUnknown(leftType); + auto rightType = checkOpConstraint.mRightType; if ((rightType != NULL) && (rightType->IsUnspecializedType())) rightType = ResolveGenericType(rightType, NULL, methodGenericArgs, mCurTypeInstance); @@ -8610,8 +8602,8 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS return false; if (checkOpConstraint.mBinaryOp != BfBinaryOp_None) - { - BfExprEvaluator exprEvaluator(this); + { + BfExprEvaluator exprEvaluator(this); BfTypedValue leftValue(mBfIRBuilder->GetFakeVal(), leftType); BfTypedValue rightValue(mBfIRBuilder->GetFakeVal(), rightType); @@ -8623,7 +8615,7 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS exprEvaluator.PerformBinaryOperation(NULL, NULL, checkOpConstraint.mBinaryOp, NULL, (BfBinOpFlags)(BfBinOpFlag_NoClassify | BfBinOpFlag_IsConstraintCheck), leftValue, rightValue); } - if ((!exprEvaluator.mResult) || + if ((!exprEvaluator.mResult) || (!CanCast(exprEvaluator.mResult, origCheckArgType, BfCastFlags_NoConversionOperator))) { if ((!ignoreErrors) && (PreFail())) @@ -8641,12 +8633,11 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS } return false; } - } else { BfTypedValue rightValue(mBfIRBuilder->GetFakeVal(), rightType); - + StringT<128> failedOpName; if (checkOpConstraint.mCastToken == BfToken_Implicit) @@ -8662,7 +8653,7 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS if (checkOpConstraint.mCastToken == BfToken_Explicit) { if (!CastToValue(NULL, rightValue, origCheckArgType, (BfCastFlags)(BfCastFlags_Explicit | BfCastFlags_SilentFail | BfCastFlags_IsConstraintCheck))) - failedOpName = "explicit conversion from '"; + failedOpName = "explicit conversion from '"; } else { @@ -8688,7 +8679,7 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS ), checkArgTypeRef); return false; } - } + } } return true; @@ -8698,18 +8689,18 @@ BfGenericParamType* BfModule::GetGenericParamType(BfGenericParamKind paramKind, { if (paramIdx < (int)mContext->mGenericParamTypes[paramKind].size()) { - auto genericParamType = mContext->mGenericParamTypes[paramKind][paramIdx]; + auto genericParamType = mContext->mGenericParamTypes[paramKind][paramIdx]; return genericParamType; } auto genericParamType = new BfGenericParamType(); - + genericParamType->mContext = mContext; genericParamType->mGenericParamKind = paramKind; - genericParamType->mGenericParamIdx = paramIdx; + genericParamType->mGenericParamIdx = paramIdx; PopulateType(genericParamType); - + BF_ASSERT(paramIdx == (int)mContext->mGenericParamTypes[paramKind].size()); mContext->mGenericParamTypes[paramKind].push_back(genericParamType); @@ -8736,7 +8727,7 @@ BfTypedValue BfModule::FlushNullConditional(BfTypedValue result, bool ignoreNull auto notNullBB = mBfIRBuilder->GetInsertBlock(); - //TODO: Make this work, needed for 'void' and such + //TODO: Make this work, needed for 'void' and such BfType* nullableType = NULL; if ((result.mType->IsValueType()) && (!result.mType->IsNullable())) { @@ -8768,9 +8759,9 @@ BfTypedValue BfModule::FlushNullConditional(BfTypedValue result, bool ignoreNull // Do nothing } else if (elementType->IsValuelessType()) - { + { BfIRValue ptrValue = mBfIRBuilder->CreateInBoundsGEP(nullableTypedValue.mValue, 0, 1); // mHasValue - mBfIRBuilder->CreateStore(GetConstValue(1, GetPrimitiveType(BfTypeCode_Boolean)), ptrValue); + mBfIRBuilder->CreateStore(GetConstValue(1, GetPrimitiveType(BfTypeCode_Boolean)), ptrValue); } else { @@ -8778,7 +8769,7 @@ BfTypedValue BfModule::FlushNullConditional(BfTypedValue result, bool ignoreNull mBfIRBuilder->CreateAlignedStore(result.mValue, ptrValue, result.mType->mAlign); ptrValue = mBfIRBuilder->CreateInBoundsGEP(nullableTypedValue.mValue, 0, 2); // mHasValue mBfIRBuilder->CreateAlignedStore(GetConstValue(1, GetPrimitiveType(BfTypeCode_Boolean)), ptrValue, 1); - } + } result = nullableTypedValue; } mBfIRBuilder->CreateBr(pendingNullCond->mDoneBB); @@ -8797,10 +8788,10 @@ BfTypedValue BfModule::FlushNullConditional(BfTypedValue result, bool ignoreNull } result.mValue = phi; - } + } } else - { + { mBfIRBuilder->CreateBr(pendingNullCond->mDoneBB); mBfIRBuilder->SetInsertPoint(pendingNullCond->mPrevBB); @@ -8827,7 +8818,7 @@ BF_NOINLINE void BfModule::EvaluateWithNewConditionalScope(BfExprEvaluator& expr deferredLocalAssignData.mVarIdBarrier = mCurMethodState->GetRootMethodState()->mCurLocalVarId; mCurMethodState->mDeferredLocalAssignData = &deferredLocalAssignData; } - + BfScopeData newScope; newScope.mOuterIsConditional = true; newScope.mAllowTargeting = false; @@ -8835,7 +8826,7 @@ BF_NOINLINE void BfModule::EvaluateWithNewConditionalScope(BfExprEvaluator& expr { mCurMethodState->AddScope(&newScope); NewScopeState(true, false); - } + } exprEvaluator.mBfEvalExprFlags = (BfEvalExprFlags)(exprEvaluator.mBfEvalExprFlags | flags); exprEvaluator.Evaluate(expr, (flags & BfEvalExprFlags_PropogateNullConditional) != 0, (flags & BfEvalExprFlags_IgnoreNullConditional) != 0, (flags & BfEvalExprFlags_AllowSplat) != 0); @@ -8869,7 +8860,7 @@ BfTypedValue BfModule::CreateValueFromExpression(BfExprEvaluator& exprEvaluator, if (outOrigType != NULL) *outOrigType = NULL; - + exprEvaluator.mExpectingType = wantTypeRef; exprEvaluator.mBfEvalExprFlags = (BfEvalExprFlags)(exprEvaluator.mBfEvalExprFlags | flags); exprEvaluator.mExplicitCast = (flags & BfEvalExprFlags_ExplicitCast) != 0; @@ -8909,13 +8900,13 @@ BfTypedValue BfModule::CreateValueFromExpression(BfExprEvaluator& exprEvaluator, bool handled = false; if ((genericParamDef->mGenericParamFlags & BfGenericParamFlag_Const) != 0) - { + { auto genericTypeConstraint = genericParamDef->mTypeConstraint; if (genericTypeConstraint != NULL) { auto underlyingConstraint = genericTypeConstraint; if ((underlyingConstraint != NULL) && (underlyingConstraint->IsBoxed())) - underlyingConstraint = underlyingConstraint->GetUnderlyingType(); + underlyingConstraint = underlyingConstraint->GetUnderlyingType(); if (underlyingConstraint != NULL) { BfTypedValue result; @@ -8924,8 +8915,8 @@ BfTypedValue BfModule::CreateValueFromExpression(BfExprEvaluator& exprEvaluator, result.mValue = mBfIRBuilder->GetUndefConstValue(mBfIRBuilder->MapType(underlyingConstraint)); typedVal = result; handled = true; - } - } + } + } } if (!handled) @@ -8972,7 +8963,7 @@ BfTypedValue BfModule::CreateValueFromExpression(BfExprEvaluator& exprEvaluator, if (!allowRef) typedVal = RemoveRef(typedVal); } - } + } if ((!typedVal.mType->IsComposite()) && (!typedVal.mType->IsGenericParam())) // Load non-structs by default { @@ -9004,13 +8995,13 @@ BfTypedValue BfModule::CreateValueFromExpression(BfExprEvaluator& exprEvaluator, } if ((typedVal.mType->IsValueType()) && ((flags & BfEvalExprFlags_NoValueAddr) != 0)) - typedVal = LoadValue(typedVal, 0, exprEvaluator.mIsVolatileReference); + typedVal = LoadValue(typedVal, 0, exprEvaluator.mIsVolatileReference); return typedVal; } BfTypedValue BfModule::CreateValueFromExpression(BfExpression* expr, BfType* wantTypeRef, BfEvalExprFlags flags, BfType** outOrigType) -{ +{ BfExprEvaluator exprEvaluator(this); return CreateValueFromExpression(exprEvaluator, expr, wantTypeRef, flags, outOrigType); } @@ -9018,7 +9009,7 @@ BfTypedValue BfModule::CreateValueFromExpression(BfExpression* expr, BfType* wan BfTypedValue BfModule::GetOrCreateVarAddr(BfExpression* expr) { BfExprEvaluator exprEvaluator(this); - exprEvaluator.Evaluate(expr); + exprEvaluator.Evaluate(expr); if (!exprEvaluator.mResult) { Fail("Invalid expression type", expr); @@ -9045,14 +9036,14 @@ void BfModule::InitTypeInst(BfTypedValue typedValue, BfScopeData* scopeData, boo } if (!typedValue.mType->IsObject()) - { + { return; } if ((scopeData == NULL) && (mCurMethodState != NULL)) return; // Handled in heap alloc funcs - - auto typeDef = typeInstance->mTypeDef; + + auto typeDef = typeInstance->mTypeDef; mBfIRBuilder->PopulateType(typedValue.mType); auto vObjectAddr = mBfIRBuilder->CreateInBoundsGEP(typedValue.mValue, 0, 0); @@ -9072,30 +9063,30 @@ void BfModule::InitTypeInst(BfTypedValue typedValue, BfScopeData* scopeData, boo PopulateType(ptrType, BfPopulateType_Declaration); auto destAddr = mBfIRBuilder->CreateBitCast(vObjectAddr, mBfIRBuilder->MapType(ptrPtrType)); if (!isAutocomplete) - { + { if ((mCompiler->mOptions.mObjectHasDebugFlags) && (!mIsComptimeModule)) { auto objectPtr = mBfIRBuilder->CreateBitCast(destAddr, mBfIRBuilder->MapType(mContext->mBfObjectType)); SizedArray llvmArgs; - llvmArgs.push_back(objectPtr); - llvmArgs.push_back(vDataRef); + llvmArgs.push_back(objectPtr); + llvmArgs.push_back(vDataRef); auto objectStackInitMethod = GetInternalMethod("Dbg_ObjectStackInit"); if (objectStackInitMethod) mBfIRBuilder->CreateCall(objectStackInitMethod.mFunc, llvmArgs); } else - { + { auto srcVal = mBfIRBuilder->CreateBitCast(vDataRef, mBfIRBuilder->MapType(ptrType)); auto objectPtr = mBfIRBuilder->CreateBitCast(destAddr, mBfIRBuilder->MapType(ptrType)); - mBfIRBuilder->CreateStore(srcVal, destAddr); + mBfIRBuilder->CreateStore(srcVal, destAddr); } } } bool BfModule::IsAllocatorAligned() -{ +{ if (mCompiler->mOptions.mMallocLinkName == "StompAlloc") return false; return true; @@ -9130,13 +9121,13 @@ BfIRValue BfModule::AllocBytes(BfAstNode* refNode, const BfAllocTarget& allocTar BfTypedValue allocResult; if (allocTarget.mScopedInvocationTarget != NULL) - { + { SizedArray genericArgs; exprEvaluator.DoInvocation(allocTarget.mScopedInvocationTarget, NULL, argExprs, BfMethodGenericArguments()); allocResult = LoadValue(exprEvaluator.mResult); } else if (allocTarget.mCustomAllocator) - { + { auto customTypeInst = allocTarget.mCustomAllocator.mType->ToTypeInstance(); if (customTypeInst == NULL) { @@ -9157,7 +9148,7 @@ BfIRValue BfModule::AllocBytes(BfAstNode* refNode, const BfAllocTarget& allocTar allocMethodName = "AllocTyped"; auto typeType = ResolveTypeDef(mCompiler->mTypeTypeDef); auto typeRefVal = CreateTypeDataRef(type); - + typeValueExpr.Init(BfTypedValue(typeRefVal, typeType)); typeValueExpr.mRefNode = refNode; argExprs.Insert(0, &typeValueExpr); @@ -9180,7 +9171,7 @@ BfIRValue BfModule::AllocBytes(BfAstNode* refNode, const BfAllocTarget& allocTar SetAndRestoreValue prevNoBind(mCurMethodState->mNoBind, true); allocResult = exprEvaluator.MatchMethod(refNode, NULL, allocTarget.mCustomAllocator, false, false, allocMethodName, argValues, BfMethodGenericArguments()); } - } + } } if (allocResult) @@ -9195,12 +9186,12 @@ BfIRValue BfModule::AllocBytes(BfAstNode* refNode, const BfAllocTarget& allocTar if ((allocFlags & BfAllocFlags_NoDefaultToMalloc) != 0) return result; - + if ((mCompiler->mOptions.mDebugAlloc) && (!mIsComptimeModule)) { BfIRValue allocData = GetDbgRawAllocData(type); BfModuleMethodInstance allocMethod = GetInternalMethod("Dbg_RawAlloc", 2); - + SizedArray llvmArgs; llvmArgs.push_back(sizeValue); llvmArgs.push_back(allocData); @@ -9210,10 +9201,10 @@ BfIRValue BfModule::AllocBytes(BfAstNode* refNode, const BfAllocTarget& allocTar BfModuleMethodInstance moduleMethodInstance; moduleMethodInstance = GetInternalMethod("Malloc"); - + SizedArray llvmArgs; llvmArgs.push_back(sizeValue); - + auto func = moduleMethodInstance.mFunc; if ((!func) || (func.IsFake())) @@ -9221,7 +9212,7 @@ BfIRValue BfModule::AllocBytes(BfAstNode* refNode, const BfAllocTarget& allocTar BF_ASSERT((mCompiler->mIsResolveOnly) || (mBfIRBuilder->mIgnoreWrites)); return mBfIRBuilder->CreateUndefValue(mBfIRBuilder->MapType(ptrType)); } - BfIRValue bitData = mBfIRBuilder->CreateCall(func, llvmArgs); + BfIRValue bitData = mBfIRBuilder->CreateCall(func, llvmArgs); if ((allocFlags & BfAllocFlags_ZeroMemory) != 0) mBfIRBuilder->CreateMemSet(bitData, GetConstValue8(0), sizeValue, alignValue); result = mBfIRBuilder->CreateBitCast(bitData, mBfIRBuilder->MapType(ptrType)); @@ -9240,15 +9231,15 @@ BfIRValue BfModule::GetMarkFuncPtr(BfType* type) else if (type->IsObjectOrInterface()) { auto gcType = ResolveTypeDef(mCompiler->mGCTypeDef)->ToTypeInstance(); - BfModuleMethodInstance moduleMethodInst = GetMethodByName(gcType, "MarkDerefedObject"); + BfModuleMethodInstance moduleMethodInst = GetMethodByName(gcType, "MarkDerefedObject"); BF_ASSERT(moduleMethodInst.mFunc); return mBfIRBuilder->CreateBitCast(moduleMethodInst.mFunc, mBfIRBuilder->MapType(GetPrimitiveType(BfTypeCode_NullPtr))); } else { auto gcType = ResolveTypeDef(mCompiler->mGCTypeDef)->ToTypeInstance(); - - BfExprEvaluator exprEvaluator(this); + + BfExprEvaluator exprEvaluator(this); SizedArray resolvedArgs; BfResolvedArg resolvedArg; resolvedArg.mTypedValue = BfTypedValue(mBfIRBuilder->GetFakeVal(), type, type->IsComposite()); @@ -9269,7 +9260,7 @@ BfIRValue BfModule::GetDbgRawAllocData(BfType* type) BfIRValue allocDataValue; if (mDbgRawAllocDataRefs.TryGetValue(type, &allocDataValue)) return allocDataValue; - + BfIRValue markFuncPtr; if (type->WantsGCMarking()) markFuncPtr = GetMarkFuncPtr(type); @@ -9316,7 +9307,7 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget BF_ASSERT(!type->IsVar()); - auto typeInstance = type->ToTypeInstance(); + auto typeInstance = type->ToTypeInstance(); if ((typeInstance == NULL) && (type->IsGenericParam())) typeInstance = mContext->mBfObjectType; @@ -9331,9 +9322,9 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget if ((type->IsValuelessType()) && ((!arraySize) || (isRawArrayAlloc))) { - BfPointerType* ptrType = CreatePointerType(type); + BfPointerType* ptrType = CreatePointerType(type); auto val = mBfIRBuilder->CreateIntToPtr(mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, 1), mBfIRBuilder->MapType(ptrType)); - return val; + return val; } if (typeInstance != NULL) @@ -9353,7 +9344,7 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget int allocSize = type->mSize; int allocAlign = type->mAlign; if (typeInstance != NULL) - { + { if ((!mBfIRBuilder->mIgnoreWrites) && (!mIsComptimeModule)) typeInstance->mHasBeenInstantiated = true; allocSize = typeInstance->mInstSize; @@ -9362,7 +9353,7 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget //if (typeInstance->IsEnum()) //allocType = typeInstance->mIRType; allocType = mBfIRBuilder->MapTypeInst(typeInstance); - } + } if (alignOverride != -1) allocAlign = alignOverride; @@ -9371,7 +9362,7 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget // If we are not dyn, but we are a variable size and could be looped over multiple times then we attempt to reuse // the last stack space. We won't use StackSave and StackRestore because a scoped alloc that occurs after this but // needs to be retained after the current scopeData (ie: scopeData::), then it would cause these allocs to accumulate even - // though we'd expect their stack space to be released + // though we'd expect their stack space to be released auto _CreateDynAlloc = [&](const BfIRValue& sizeValue, int align) { MarkDynStack(scopeData); @@ -9392,7 +9383,6 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget mBfIRBuilder->SetInsertPoint(prevInsertBlock); } - auto byteType = GetPrimitiveType(BfTypeCode_Int8); auto bytePtrType = CreatePointerType(byteType); @@ -9416,7 +9406,7 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget mBfIRBuilder->SetAllocaForceMem(dynSizeAllocaInst); mBfIRBuilder->SetAllocaForceMem(dynPtrAllocaInst); } - + auto resizeBB = mBfIRBuilder->CreateBlock("dynAlloc.resize"); auto endBB = mBfIRBuilder->CreateBlock("dynAlloc.end"); auto verCheckBB = mBfIRBuilder->CreateBlock("dynAlloc.verCheck"); @@ -9434,7 +9424,7 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget mBfIRBuilder->CreateCondBr(dynStackChanged, resizeBB, endBB); mBfIRBuilder->AddBlock(resizeBB); - mBfIRBuilder->SetInsertPoint(resizeBB); + mBfIRBuilder->SetInsertPoint(resizeBB); auto allocaInst = mBfIRBuilder->CreateAlloca(mBfIRBuilder->MapType(byteType), sizeValue); mBfIRBuilder->SetAllocaAlignment(allocaInst, align); mBfIRBuilder->CreateStore(allocaInst, dynPtrAllocaInst); @@ -9451,12 +9441,12 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget { if (arraySize) { - bool isConstantArraySize = arraySize.IsConst(); + bool isConstantArraySize = arraySize.IsConst(); if (isRawArrayAlloc) { BfPointerType* ptrType = CreatePointerType(type); if ((!isDynAlloc) && (!isConstantArraySize) && (mCurMethodState->mCurScope->IsLooped(NULL))) - { + { BfIRValue sizeValue = mBfIRBuilder->CreateMul(GetConstValue(type->GetStride()), arraySize); auto loadedPtr = _CreateDynAlloc(sizeValue, type->mAlign); InitTypeInst(BfTypedValue(loadedPtr, ptrType), scopeData, zeroMemory, sizeValue); @@ -9464,23 +9454,23 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget } else { - auto prevInsertBlock = mBfIRBuilder->GetInsertBlock(); + auto prevInsertBlock = mBfIRBuilder->GetInsertBlock(); isDynAlloc = (isDynAlloc) || (!arraySize.IsConst()); if (!isDynAlloc) - mBfIRBuilder->SetInsertPoint(mCurMethodState->mIRHeadBlock); + mBfIRBuilder->SetInsertPoint(mCurMethodState->mIRHeadBlock); else { MarkDynStack(scopeData); SaveStackState(scopeData); } - + int typeSize = type->GetStride(); BfIRValue allocaInst; BfIRValue result; if ((typeInstance == NULL) || (typeInstance->mIsCRepr)) - { - allocaInst = mBfIRBuilder->CreateAlloca(mBfIRBuilder->MapType(type), arraySize); + { + allocaInst = mBfIRBuilder->CreateAlloca(mBfIRBuilder->MapType(type), arraySize); result = allocaInst; } else @@ -9497,7 +9487,7 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget } if (!isDynAlloc) mBfIRBuilder->ClearDebugLocation(allocaInst); - mBfIRBuilder->SetAllocaAlignment(allocaInst, allocAlign); + mBfIRBuilder->SetAllocaAlignment(allocaInst, allocAlign); if (!isDynAlloc) mBfIRBuilder->SetInsertPoint(prevInsertBlock); auto typedVal = BfTypedValue(result, type, BfTypedValueKind_Addr); @@ -9514,7 +9504,7 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget bool isConstSize = arraySize.IsConst(); BfIRBlock clearBlock; BfIRBlock contBlock; - + bool wantsDeinit = ((!IsOptimized()) && (!mIsComptimeModule) && (!mBfIRBuilder->mIgnoreWrites) && (!mCompiler->mIsResolveOnly)); if (wantsDeinit) @@ -9526,7 +9516,7 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget clearBlock = mBfIRBuilder->CreateBlock("clear"); contBlock = mBfIRBuilder->CreateBlock("clearCont"); - prevBlock = mBfIRBuilder->GetInsertBlock(); + prevBlock = mBfIRBuilder->GetInsertBlock(); mBfIRBuilder->AddBlock(clearBlock); mBfIRBuilder->SetInsertPoint(clearBlock); @@ -9555,15 +9545,15 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget mBfIRBuilder->SetInsertPoint(contBlock); } } - } + } return result; } } else - { + { if ((!isDynAlloc) && (!arraySize.IsConst()) && (mCurMethodState->mCurScope->IsLooped(NULL))) - { + { // Generate and check new size BfArrayType* arrayType = CreateArrayType(type, arrayDim); auto firstElementField = &arrayType->mFieldInstances.back(); @@ -9582,7 +9572,7 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget else { BfArrayType* arrayType = CreateArrayType(type, arrayDim); - auto firstElementField = &arrayType->mFieldInstances.back(); + auto firstElementField = &arrayType->mFieldInstances.back(); if (!type->IsValuelessType()) { @@ -9593,7 +9583,7 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget } else sizeValue = GetConstValue(arrayType->mInstSize); - + auto prevBlock = mBfIRBuilder->GetInsertBlock(); isDynAlloc = (isDynAlloc) || (!sizeValue.IsConst()); if (!isDynAlloc) @@ -9603,15 +9593,15 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget MarkDynStack(scopeData); SaveStackState(scopeData); } - + BfType* byteType = GetPrimitiveType(BfTypeCode_Int8); auto allocaInst = mBfIRBuilder->CreateAlloca(mBfIRBuilder->MapType(byteType), sizeValue); if (!isDynAlloc) mBfIRBuilder->ClearDebugLocation(allocaInst); auto allocaBlock = mBfIRBuilder->GetInsertBlock(); mBfIRBuilder->SetAllocaAlignment(allocaInst, allocAlign); - - BfTypedValue typedVal; + + BfTypedValue typedVal; if (!isDynAlloc) { mBfIRBuilder->SetInsertPoint(mCurMethodState->mIRInitBlock); @@ -9621,7 +9611,7 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget allocaBlock = mCurMethodState->mIRInitBlock; } else - typedVal = BfTypedValue(mBfIRBuilder->CreateBitCast(allocaInst, mBfIRBuilder->MapType(arrayType)), arrayType); + typedVal = BfTypedValue(mBfIRBuilder->CreateBitCast(allocaInst, mBfIRBuilder->MapType(arrayType)), arrayType); if (!noDtorCall) AddStackAlloc(typedVal, BfIRValue(), NULL, scopeData, false, true, allocaBlock); @@ -9637,19 +9627,19 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget // use the "dynSize" version conservatively if ((!isDynAlloc) && (!appendSizeValue.IsConst()) && (mCurMethodState->mCurScope->IsLooped(NULL))) { - // Generate and check new size + // Generate and check new size sizeValue = GetConstValue(typeInstance->mInstSize); sizeValue = mBfIRBuilder->CreateAdd(sizeValue, appendSizeValue); auto loadedPtr = _CreateDynAlloc(sizeValue, typeInstance->mAlign); - auto typedVal = BfTypedValue(mBfIRBuilder->CreateBitCast(loadedPtr, mBfIRBuilder->MapTypeInstPtr(typeInstance)), typeInstance); + auto typedVal = BfTypedValue(mBfIRBuilder->CreateBitCast(loadedPtr, mBfIRBuilder->MapTypeInstPtr(typeInstance)), typeInstance); if (!noDtorCall) AddStackAlloc(typedVal, arraySize, NULL, scopeData, mCurMethodState->mInConditionalBlock, true); InitTypeInst(typedVal, scopeData, zeroMemory, sizeValue); return typedVal.mValue; } else // stack alloc, unlooped, with append - { + { sizeValue = GetConstValue(typeInstance->mInstSize); sizeValue = mBfIRBuilder->CreateAdd(sizeValue, appendSizeValue); auto prevBlock = mBfIRBuilder->GetInsertBlock(); @@ -9666,17 +9656,17 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget auto allocaInst = mBfIRBuilder->CreateAlloca(mBfIRBuilder->MapType(sbyteType), sizeValue); if (!isDynAlloc) { - mBfIRBuilder->ClearDebugLocation(allocaInst); + mBfIRBuilder->ClearDebugLocation(allocaInst); } mBfIRBuilder->SetAllocaAlignment(allocaInst, allocAlign); - - bool mayBeLarge = false; + + bool mayBeLarge = false; if (sizeValue.IsConst()) { auto constantInt = mBfIRBuilder->GetConstant(sizeValue); if (constantInt->mInt64 >= 4096) mayBeLarge = true; - } + } else mayBeLarge = true; @@ -9704,7 +9694,7 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget { castedVal = mBfIRBuilder->CreateBitCast(allocaInst, mBfIRBuilder->MapTypeInstPtr(typeInstance)); } - + auto typedVal = BfTypedValue(castedVal, typeInstance); if (!noDtorCall) { @@ -9713,15 +9703,15 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget doCondAlloca = !wasDynAlloc && isDynAlloc && mCurMethodState->mInConditionalBlock; AddStackAlloc(typedVal, arraySize, NULL, scopeData, doCondAlloca, true); } - InitTypeInst(typedVal, scopeData, zeroMemory, sizeValue); - + InitTypeInst(typedVal, scopeData, zeroMemory, sizeValue); + return typedVal.mValue; } } else // "Normal" stack alloc { BF_ASSERT(!sizeValue); - //TODO: If sizeValue is a constant then do this in the head IR builder + //TODO: If sizeValue is a constant then do this in the head IR builder auto prevBlock = mBfIRBuilder->GetInsertBlock(); if (!isLoopedAlloc) mBfIRBuilder->SetInsertPoint(mCurMethodState->mIRHeadBlock); @@ -9730,7 +9720,7 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget MarkDynStack(scopeData); SaveStackState(scopeData); } - auto allocaInst = mBfIRBuilder->CreateAlloca(allocType); + auto allocaInst = mBfIRBuilder->CreateAlloca(allocType); if (!isLoopedAlloc) mBfIRBuilder->ClearDebugLocation(allocaInst); mBfIRBuilder->SetAllocaAlignment(allocaInst, allocAlign); @@ -9739,7 +9729,7 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget // If we create a memset that can fill in backwards (or at least 4k chunked backward) then we can remove the '!mayBeLarge' cond ((zeroMemory) && (!mayBeLarge))) { - // With an object, we know we will at least set the vdata pointer which will probe the start of the new address, + // With an object, we know we will at least set the vdata pointer which will probe the start of the new address, // and memset is always safe mBfIRBuilder->SetAllocaNoChkStkHint(allocaInst); } @@ -9764,35 +9754,35 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget { mBfIRBuilder->CreateMemSet(allocaInst, GetConstValue8(0), GetConstValue(allocSize), allocAlign); } - return allocaInst; - } + return allocaInst; + } } else if (arraySize) - { + { if (isRawArrayAlloc) - { + { sizeValue = mBfIRBuilder->CreateMul(GetConstValue(type->GetStride()), arraySize); return AllocBytes(allocTarget.mRefNode, allocTarget, type, sizeValue, GetConstValue(allocAlign), allocFlags); } else - { + { BfArrayType* arrayType = CreateArrayType(type, arrayDim); typeInstance = arrayType; BfIRValue arraySizeMinusOne = mBfIRBuilder->CreateSub(arraySize, GetConstValue(1)); BfIRValue elementDataSize = mBfIRBuilder->CreateMul(GetConstValue(type->GetStride()), arraySizeMinusOne); appendSizeValue = elementDataSize; - + if (!type->IsSizeAligned()) { appendSizeValue = mBfIRBuilder->CreateAdd(appendSizeValue, GetConstValue(type->GetStride() - type->mSize)); - } + } } } - + if ((typeInstance != NULL) && (typeInstance->IsObject())) { - auto vDataRef = GetClassVDataPtr(typeInstance); - BfIRValue result; + auto vDataRef = GetClassVDataPtr(typeInstance); + BfIRValue result; bool isResultInitialized = false; int stackCount = mCompiler->mOptions.mAllocStackCount; @@ -9823,7 +9813,7 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget auto addlBytes = mBfIRBuilder->CreateCall(prepareStackTraceMethod.mFunc, irArgs); sizeValue = mBfIRBuilder->CreateAdd(sizeValue, addlBytes); } - } + } if (allocTarget.mCustomAllocator) { @@ -9839,10 +9829,10 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget auto typePtr = mBfIRBuilder->CreateLoad(typePtrPtr); auto typeInstPtr = mBfIRBuilder->CreateBitCast(typePtr, mBfIRBuilder->MapTypeInstPtr(typeInstType)); - BfTypedValueExpression typedValueExpr; + BfTypedValueExpression typedValueExpr; typedValueExpr.Init(BfTypedValue(typeInstPtr, typeInstType)); typedValueExpr.mRefNode = allocTarget.mRefNode; - + BfExprEvaluator exprEvaluator(this); SizedArray argExprs; argExprs.push_back(&typedValueExpr); @@ -9858,7 +9848,7 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget exprEvaluator.mNoBind = true; BfTypedValue allocResult = exprEvaluator.MatchMethod(allocTarget.mRefNode, NULL, allocTarget.mCustomAllocator, false, false, "AllocObject", argValues, BfMethodGenericArguments()); if (allocResult) - { + { if ((allocResult.mType->IsVoidPtr()) || (allocResult.mType == mContext->mBfObjectType)) result = mBfIRBuilder->CreateBitCast(allocResult.mValue, mBfIRBuilder->MapType(typeInstance)); else @@ -9866,13 +9856,13 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget isResultInitialized = true; } } - } + } bool wasAllocated = false; if (!result) - { + { if (hasCustomAllocator) - result = AllocBytes(allocTarget.mRefNode, allocTarget, typeInstance, sizeValue, GetConstValue(typeInstance->mInstAlign), (BfAllocFlags)(BfAllocFlags_ZeroMemory | BfAllocFlags_NoDefaultToMalloc)); + result = AllocBytes(allocTarget.mRefNode, allocTarget, typeInstance, sizeValue, GetConstValue(typeInstance->mInstAlign), (BfAllocFlags)(BfAllocFlags_ZeroMemory | BfAllocFlags_NoDefaultToMalloc)); else if ((mCompiler->mOptions.mObjectHasDebugFlags) && (!mCompiler->mOptions.mDebugAlloc) && (!mIsComptimeModule)) { SizedArray llvmArgs; @@ -9885,7 +9875,7 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget } if (result) - { + { if ((mCompiler->mOptions.mObjectHasDebugFlags) && (!mIsComptimeModule)) { auto objectPtr = mBfIRBuilder->CreateBitCast(result, mBfIRBuilder->MapTypeInstPtr(mContext->mBfObjectType)); @@ -9893,8 +9883,8 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget llvmArgs.push_back(objectPtr); llvmArgs.push_back(origSizeValue); llvmArgs.push_back(vDataRef); - auto objectCreatedMethod = GetInternalMethod(isAllocEx ? - (isResultInitialized ? "Dbg_ObjectCreatedEx" : "Dbg_ObjectAllocatedEx") : + auto objectCreatedMethod = GetInternalMethod(isAllocEx ? + (isResultInitialized ? "Dbg_ObjectCreatedEx" : "Dbg_ObjectAllocatedEx") : (isResultInitialized ? "Dbg_ObjectCreated" : "Dbg_ObjectAllocated")); mBfIRBuilder->CreateCall(objectCreatedMethod.mFunc, llvmArgs); @@ -9909,21 +9899,21 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget } } else - { + { auto ptrType = mBfIRBuilder->GetPrimitiveType(BfTypeCode_NullPtr); auto vDataPtr = mBfIRBuilder->CreateBitCast(vDataRef, ptrType); - auto vDataMemberPtr = mBfIRBuilder->CreateBitCast(result, mBfIRBuilder->GetPointerTo(ptrType)); + auto vDataMemberPtr = mBfIRBuilder->CreateBitCast(result, mBfIRBuilder->GetPointerTo(ptrType)); mBfIRBuilder->CreateStore(vDataPtr, vDataMemberPtr); } - } + } else - { - if ((mBfIRBuilder->mIgnoreWrites) || + { + if ((mBfIRBuilder->mIgnoreWrites) || ((mCompiler->mIsResolveOnly) && (!mIsComptimeModule))) return GetDefaultValue(typeInstance); - auto classVDataType = ResolveTypeDef(mCompiler->mClassVDataTypeDef); - auto vData = mBfIRBuilder->CreateBitCast(vDataRef, mBfIRBuilder->MapTypeInstPtr(classVDataType->ToTypeInstance())); + auto classVDataType = ResolveTypeDef(mCompiler->mClassVDataTypeDef); + auto vData = mBfIRBuilder->CreateBitCast(vDataRef, mBfIRBuilder->MapTypeInstPtr(classVDataType->ToTypeInstance())); if ((mCompiler->mOptions.mObjectHasDebugFlags) && (!mIsComptimeModule)) { @@ -9947,18 +9937,18 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget irFunc = moduleMethodInstance.mFunc; } if (!irFunc) - irFunc = GetBuiltInFunc(BfBuiltInFuncType_Malloc); + irFunc = GetBuiltInFunc(BfBuiltInFuncType_Malloc); BfIRValue objectVal = mBfIRBuilder->CreateCall(irFunc, llvmArgs); auto objResult = mBfIRBuilder->CreateBitCast(objectVal, mBfIRBuilder->MapType(mContext->mBfObjectType, BfIRPopulateType_Full)); auto vdataPtr = mBfIRBuilder->CreateInBoundsGEP(objResult, 0, 0); if (mIsComptimeModule) - { + { vdataPtr = mBfIRBuilder->CreateBitCast(vdataPtr, mBfIRBuilder->GetPointerTo(mBfIRBuilder->MapTypeInstPtr(classVDataType->ToTypeInstance()))); } mBfIRBuilder->CreateStore(vData, vdataPtr); - result = mBfIRBuilder->CreateBitCast(objectVal, mBfIRBuilder->MapType(typeInstance)); + result = mBfIRBuilder->CreateBitCast(objectVal, mBfIRBuilder->MapType(typeInstance)); } } @@ -9969,7 +9959,7 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget auto firstElementField = &arrayType->mFieldInstances.back(); int arrayClassSize = firstElementField->mDataOffset; - BfIRValue elementDataSize; + BfIRValue elementDataSize; bool skipZero = false; if (arraySize.IsConst()) { @@ -9998,13 +9988,13 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget } } - return result; - } + return result; + } else - { + { if (!sizeValue) sizeValue = GetConstValue(allocSize); - return AllocBytes(allocTarget.mRefNode, allocTarget, type, sizeValue, GetConstValue(allocAlign), zeroMemory ? BfAllocFlags_ZeroMemory : BfAllocFlags_None); + return AllocBytes(allocTarget.mRefNode, allocTarget, type, sizeValue, GetConstValue(allocAlign), zeroMemory ? BfAllocFlags_ZeroMemory : BfAllocFlags_None); } } @@ -10018,7 +10008,7 @@ void BfModule::ValidateAllocation(BfType* type, BfAstNode* refNode) } void BfModule::EmitAppendAlign(int align, int sizeMultiple) -{ +{ if (sizeMultiple == 0) sizeMultiple = align; if ((mCurMethodState->mCurAppendAlign != 0) && (mCurMethodState->mCurAppendAlign % align != 0)) @@ -10031,7 +10021,7 @@ void BfModule::EmitAppendAlign(int align, int sizeMultiple) { auto localVar = mCurMethodState->GetRootMethodState()->mLocals[1]; BF_ASSERT(localVar->mName == "appendIdx"); - auto appendIdxVal = BfTypedValue(localVar->mValue, localVar->mResolvedType, true); + auto appendIdxVal = BfTypedValue(localVar->mValue, localVar->mResolvedType, true); BfIRValue appendCurIdx = mBfIRBuilder->CreateLoad(appendIdxVal.mValue); if (align > 1) { @@ -10044,15 +10034,15 @@ void BfModule::EmitAppendAlign(int align, int sizeMultiple) { BF_ASSERT(mCurMethodInstance->mMethodDef->mMethodType == BfMethodType_CtorCalcAppend); BfIRValue appendCurIdxPtr = mCurMethodState->mRetVal.mValue; - BfIRValue appendCurIdx = mBfIRBuilder->CreateLoad(appendCurIdxPtr); + BfIRValue appendCurIdx = mBfIRBuilder->CreateLoad(appendCurIdxPtr); appendCurIdx = mBfIRBuilder->CreateAdd(appendCurIdx, GetConstValue(align - 1)); appendCurIdx = mBfIRBuilder->CreateAnd(appendCurIdx, GetConstValue(~(align - 1))); mBfIRBuilder->CreateStore(appendCurIdx, appendCurIdxPtr); - } + } } - if (mCurMethodState->mCurAppendAlign == 0) - mCurMethodState->mCurAppendAlign = sizeMultiple; + if (mCurMethodState->mCurAppendAlign == 0) + mCurMethodState->mCurAppendAlign = sizeMultiple; else { if (sizeMultiple % align == 0) @@ -10063,9 +10053,9 @@ void BfModule::EmitAppendAlign(int align, int sizeMultiple) } BfIRValue BfModule::AppendAllocFromType(BfType* type, BfIRValue appendSizeValue, int appendAllocAlign, BfIRValue arraySize, int arrayDim, bool isRawArrayAlloc, bool zeroMemory) -{ +{ auto localVar = mCurMethodState->GetRootMethodState()->mLocals[1]; - BF_ASSERT(localVar->mName == "appendIdx"); + BF_ASSERT(localVar->mName == "appendIdx"); BfTypedValue appendIdxVal(localVar->mValue, localVar->mResolvedType, true); BfIRValue retValue; @@ -10074,7 +10064,7 @@ BfIRValue BfModule::AppendAllocFromType(BfType* type, BfIRValue appendSizeValue, auto voidPtrType = GetPrimitiveType(BfTypeCode_NullPtr); if (arraySize) - { + { if (isRawArrayAlloc) { EmitAppendAlign(type->mAlign); @@ -10085,7 +10075,7 @@ BfIRValue BfModule::AppendAllocFromType(BfType* type, BfIRValue appendSizeValue, sizeValue = mBfIRBuilder->CreateNumericCast(sizeValue, true, (intPtrType->mSize == 4) ? BfTypeCode_Int32 : BfTypeCode_Int64); auto newIdxVal = mBfIRBuilder->CreateAdd(curIdxVal, sizeValue); mBfIRBuilder->CreateStore(newIdxVal, appendIdxVal.mValue); - + if (zeroMemory) { auto ptr = mBfIRBuilder->CreateIntToPtr(curIdxVal, mBfIRBuilder->MapType(voidPtrType)); @@ -10101,7 +10091,7 @@ BfIRValue BfModule::AppendAllocFromType(BfType* type, BfIRValue appendSizeValue, auto firstElementField = &arrayType->mFieldInstances.back(); int arrayClassSize = arrayType->mInstSize - firstElementField->mDataSize; - + BfIRValue sizeValue = GetConstValue(arrayClassSize); BfIRValue elementDataSize = mBfIRBuilder->CreateMul(GetConstValue(type->mSize), arraySize); sizeValue = mBfIRBuilder->CreateAdd(sizeValue, elementDataSize); @@ -10136,11 +10126,11 @@ BfIRValue BfModule::AppendAllocFromType(BfType* type, BfIRValue appendSizeValue, EmitAppendAlign(typeInst->mInstAlign, typeInst->mInstSize); sizeValue = GetConstValue(typeInst->mInstSize); toType = mBfIRBuilder->MapTypeInstPtr(typeInst); - } + } else { EmitAppendAlign(type->mAlign, type->mSize); - sizeValue = GetConstValue(type->mSize); + sizeValue = GetConstValue(type->mSize); auto toPtrType = CreatePointerType(type); toType = mBfIRBuilder->MapType(toPtrType); } @@ -10174,7 +10164,7 @@ BfIRValue BfModule::AppendAllocFromType(BfType* type, BfIRValue appendSizeValue, auto vObjectAddr = mBfIRBuilder->CreateInBoundsGEP(retValue, 0, 0); auto vDataRef = CreateClassVDataGlobal(retTypeInstance); - + auto destAddr = mBfIRBuilder->CreateBitCast(vObjectAddr, ptrPtrType); auto srcVal = mBfIRBuilder->CreateBitCast(vDataRef, ptrType); mBfIRBuilder->CreateStore(srcVal, destAddr); @@ -10198,7 +10188,7 @@ BfIRValue BfModule::AppendAllocFromType(BfType* type, BfIRValue appendSizeValue, } bool BfModule::IsOptimized() -{ +{ if (mProject == NULL) return false; if (mIsComptimeModule) @@ -10245,7 +10235,7 @@ void BfModule::SkipObjectAccessCheck(BfTypedValue typedVal) if ((!mCompiler->mOptions.mObjectHasDebugFlags) || (mIsComptimeModule)) return; - + if ((typedVal.mValue.mFlags & BfIRValueFlags_Value) == 0) return; @@ -10277,13 +10267,13 @@ void BfModule::EmitObjectAccessCheck(BfTypedValue typedVal) if (typeOptions != NULL) emitObjectAccessCheck = typeOptions->Apply(emitObjectAccessCheck, BfOptionFlags_EmitObjectAccessCheck); if (!emitObjectAccessCheck) - return; + return; if ((typedVal.mValue.mFlags & BfIRValueFlags_Value) != 0) - { + { if (mCurMethodState->mSkipObjectAccessChecks.Contains(typedVal.mValue.mId)) return; - } + } if (typedVal.IsAddr()) typedVal = LoadValue(typedVal); @@ -10307,10 +10297,10 @@ void BfModule::EmitEnsureInstructionAt() } void BfModule::EmitDynamicCastCheck(const BfTypedValue& targetValue, BfType* targetType, BfIRBlock trueBlock, BfIRBlock falseBlock, bool nullSucceeds) -{ +{ if (mBfIRBuilder->mIgnoreWrites) return; // Nothing needed here - + auto irb = mBfIRBuilder; auto checkBB = irb->CreateBlock("as.check"); @@ -10324,7 +10314,7 @@ void BfModule::EmitDynamicCastCheck(const BfTypedValue& targetValue, BfType* tar auto cmpResult = mBfIRBuilder->CreateCmpNE(callResult, GetDefaultValue(mContext->mBfObjectType)); irb->CreateCondBr(cmpResult, trueBlock, falseBlock); return; - } + } auto intType = GetPrimitiveType(BfTypeCode_IntPtr); auto intPtrType = CreatePointerType(intType); @@ -10333,9 +10323,9 @@ void BfModule::EmitDynamicCastCheck(const BfTypedValue& targetValue, BfType* tar auto int32PtrType = CreatePointerType(int32Type); auto typeTypeInstance = ResolveTypeDef(mCompiler->mReflectTypeInstanceTypeDef)->ToTypeInstance(); - + if (mCompiler->mOptions.mAllowHotSwapping) - { + { BfExprEvaluator exprEvaluator(this); AddBasicBlock(checkBB); @@ -10355,7 +10345,7 @@ void BfModule::EmitDynamicCastCheck(const BfTypedValue& targetValue, BfType* tar vDataPtr = irb->CreateLoad(vDataPtr); if ((mCompiler->mOptions.mObjectHasDebugFlags) && (!mIsComptimeModule)) vDataPtr = irb->CreateAnd(vDataPtr, irb->CreateConst(BfTypeCode_IntPtr, (uint64)~0xFFULL)); - + if (targetType->IsInterface()) { auto targetTypeInst = targetType->ToTypeInstance(); @@ -10413,7 +10403,7 @@ void BfModule::EmitDynamicCastCheck(BfTypedValue typedVal, BfType* type, bool al emitDynamicCastCheck = typeOptions->Apply(emitDynamicCastCheck, BfOptionFlags_EmitDynamicCastCheck); if (emitDynamicCastCheck) - { + { int wantTypeId = 0; if (!type->IsGenericParam()) wantTypeId = type->mTypeId; @@ -10453,7 +10443,7 @@ BfTypedValue BfModule::BoxValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp { bool callDtor = (castFlags & BfCastFlags_NoBoxDtor) == 0; bool wantConst = ((castFlags & BfCastFlags_WantsConst) != 0) && (typedVal.mValue.IsConst()); - + if ((mBfIRBuilder->mIgnoreWrites) && (!wantConst)) { if (toType == mContext->mBfObjectType) @@ -10475,7 +10465,7 @@ BfTypedValue BfModule::BoxValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp BfTypeInstance* fromStructTypeInstance = typedVal.mType->ToTypeInstance(); if (typedVal.mType->IsNullable()) - { + { typedVal = MakeAddressable(typedVal); auto innerType = typedVal.mType->GetUnderlyingType(); @@ -10485,7 +10475,7 @@ BfTypedValue BfModule::BoxValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp Fail("Only value types can be boxed", srcNode); return BfTypedValue(); } - + auto boxedType = CreateBoxedType(innerType); auto resultType = toType; if (resultType == NULL) @@ -10503,16 +10493,16 @@ BfTypedValue BfModule::BoxValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp auto hasValue = mBfIRBuilder->CreateLoad(hasValueAddr); mBfIRBuilder->CreateCondBr(hasValue, boxBB, endBB); - + AddDependency(boxedType, mCurTypeInstance, BfDependencyMap::DependencyFlag_ReadFields); - + mBfIRBuilder->AddBlock(boxBB); mBfIRBuilder->SetInsertPoint(boxBB); BfScopeData newScope; newScope.mOuterIsConditional = true; mCurMethodState->AddScope(&newScope); NewScopeState(); - + BfIRValue nullableValueAddr; BfIRValue loadedVal; if (innerType->IsValuelessType()) @@ -10524,11 +10514,11 @@ BfTypedValue BfModule::BoxValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp nullableValueAddr = mBfIRBuilder->CreateInBoundsGEP(typedVal.mValue, 0, 1); // value loadedVal = mBfIRBuilder->CreateLoad(nullableValueAddr); } - + auto boxedVal = BoxValue(srcNode, BfTypedValue(loadedVal, fromStructTypeInstance->GetUnderlyingType()), resultType, allocTarget, callDtor ? BfCastFlags_None : BfCastFlags_NoBoxDtor); RestoreScopeState(); if (!boxedVal) - return BfTypedValue(); + return BfTypedValue(); mBfIRBuilder->CreateBr(endBB); auto boxBBEnd = mBfIRBuilder->GetInsertBlock(); @@ -10537,10 +10527,10 @@ BfTypedValue BfModule::BoxValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp auto phi = mBfIRBuilder->CreatePhi(mBfIRBuilder->MapType(resultType), 2); mBfIRBuilder->AddPhiIncoming(phi, boxedVal.mValue, boxBBEnd); mBfIRBuilder->AddPhiIncoming(phi, GetDefaultValue(resultType), prevBB); - - return BfTypedValue(phi, resultType); - } - + + return BfTypedValue(phi, resultType); + } + bool alreadyCheckedCast = false; BfTypeInstance* toTypeInstance = NULL; @@ -10548,10 +10538,10 @@ BfTypedValue BfModule::BoxValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp toTypeInstance = toType->ToTypeInstance(); bool isStructPtr = typedVal.mType->IsStructPtr(); - if (fromStructTypeInstance == NULL) - { - auto primType = (BfPrimitiveType*)typedVal.mType; - + if (fromStructTypeInstance == NULL) + { + auto primType = (BfPrimitiveType*)typedVal.mType; + if ((typedVal.mType->IsPointer()) && (toTypeInstance->IsInstanceOf(mCompiler->mIHashableTypeDef))) { // Can always do IHashable @@ -10573,23 +10563,23 @@ BfTypedValue BfModule::BoxValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp alreadyCheckedCast = true; fromStructTypeInstance = typedVal.mType->GetUnderlyingType()->ToTypeInstance(); - } - + } + if ((fromStructTypeInstance == NULL) && (alreadyCheckedCast)) fromStructTypeInstance = GetWrappedStructType(typedVal.mType); } if (fromStructTypeInstance == NULL) - return BfTypedValue(); + return BfTypedValue(); - // Need to box it + // Need to box it bool isBoxedType = (fromStructTypeInstance != NULL) && (toType->IsBoxed()); - + if ((toType == NULL) || (toType == mContext->mBfObjectType) || (isBoxedType) || (alreadyCheckedCast) || (TypeIsSubTypeOf(fromStructTypeInstance, toTypeInstance))) { if ((mBfIRBuilder->mIgnoreWrites) && (!wantConst)) return BfTypedValue(mBfIRBuilder->GetFakeVal(), (toType != NULL) ? toType : CreateBoxedType(typedVal.mType)); - auto boxedType = CreateBoxedType(typedVal.mType); + auto boxedType = CreateBoxedType(typedVal.mType); mBfIRBuilder->PopulateType(boxedType); if (wantConst) @@ -10597,10 +10587,10 @@ BfTypedValue BfModule::BoxValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp AddDependency(boxedType, mCurTypeInstance, BfDependencyMap::DependencyFlag_ReadFields); auto allocaInst = AllocFromType(boxedType, allocTarget, BfIRValue(), BfIRValue(), 0, callDtor ? BfAllocFlags_None : BfAllocFlags_NoDtorCall); - - BfTypedValue boxedTypedValue(allocaInst, boxedType); + + BfTypedValue boxedTypedValue(allocaInst, boxedType); mBfIRBuilder->SetName(allocaInst, "boxed." + fromStructTypeInstance->mTypeDef->mName->ToString()); - + if (boxedType->IsUnspecializedType()) { BF_ASSERT((srcNode == NULL) || (mCurMethodInstance->mIsUnspecialized)); @@ -10623,9 +10613,9 @@ BfTypedValue BfModule::BoxValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp { AggregateSplatIntoAddr(typedVal, valPtr); } - else + else mBfIRBuilder->CreateStore(typedVal.mValue, valPtr, typedVal.mType->mAlign); - } + } } if (toType == NULL) @@ -10636,14 +10626,14 @@ BfTypedValue BfModule::BoxValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp { auto castedValue = mBfIRBuilder->CreateBitCast(allocaInst, mBfIRBuilder->MapType(toType)); return BfTypedValue(castedValue, toType); - } + } } return BfTypedValue(); } bool BfModule::GetBasePropertyDef(BfPropertyDef*& propDef, BfTypeInstance*& typeInst) -{ +{ BfTypeInstance* checkTypeInst = typeInst; while (checkTypeInst != NULL) { @@ -10653,14 +10643,14 @@ bool BfModule::GetBasePropertyDef(BfPropertyDef*& propDef, BfTypeInstance*& type { auto checkPropDeclaration = BfNodeDynCast(checkProp->mFieldDeclaration); if ((checkPropDeclaration == NULL) || (checkPropDeclaration->mVirtualSpecifier == NULL) || (checkPropDeclaration->mVirtualSpecifier->GetToken() == BfToken_Virtual)) - { + { propDef = checkProp; typeInst = checkTypeInst; return true; } } } - + checkTypeInst = checkTypeInst->mBaseType; } return false; @@ -10686,7 +10676,7 @@ BfMethodInstance* BfModule::GetRawMethodInstanceAtIdx(BfTypeInstance* typeInstan { BF_ASSERT(typeInstance->mTypeDef->mMethods[methodIdx]->mName == assertName); } - + if (methodIdx >= typeInstance->mMethodInstanceGroups.mSize) { if (mCompiler->EnsureCeUnpaused(typeInstance)) @@ -10699,7 +10689,7 @@ BfMethodInstance* BfModule::GetRawMethodInstanceAtIdx(BfTypeInstance* typeInstan auto& methodGroup = typeInstance->mMethodInstanceGroups[methodIdx]; if (methodGroup.mDefault == NULL) { - if (!mCompiler->mIsResolveOnly) + if (!mCompiler->mIsResolveOnly) { // Get it from the owning module so we don't create a reference prematurely... auto declModule = typeInstance->mModule; @@ -10711,11 +10701,11 @@ BfMethodInstance* BfModule::GetRawMethodInstanceAtIdx(BfTypeInstance* typeInstan declModule->mOnDemandMethodCount++; } - BF_ASSERT((methodGroup.mOnDemandKind == BfMethodOnDemandKind_AlwaysInclude) || (methodGroup.mOnDemandKind == BfMethodOnDemandKind_NoDecl_AwaitingReference) || (methodGroup.mOnDemandKind == BfMethodOnDemandKind_Decl_AwaitingDecl) || + BF_ASSERT((methodGroup.mOnDemandKind == BfMethodOnDemandKind_AlwaysInclude) || (methodGroup.mOnDemandKind == BfMethodOnDemandKind_NoDecl_AwaitingReference) || (methodGroup.mOnDemandKind == BfMethodOnDemandKind_Decl_AwaitingDecl) || (typeInstance->mTypeFailed) || (typeInstance->mDefineState < BfTypeDefineState_DefinedAndMethodsSlotted)); if ((methodGroup.mOnDemandKind == BfMethodOnDemandKind_NoDecl_AwaitingReference) || (methodGroup.mOnDemandKind == BfMethodOnDemandKind_Decl_AwaitingDecl)) methodGroup.mOnDemandKind = BfMethodOnDemandKind_Decl_AwaitingDecl; - + BfGetMethodInstanceFlags useFlags = (BfGetMethodInstanceFlags)(BfGetMethodInstanceFlag_MethodInstanceOnly | BfGetMethodInstanceFlag_UnspecializedPass | BfGetMethodInstanceFlag_Unreified); return declModule->GetMethodInstance(typeInstance, typeInstance->mTypeDef->mMethods[methodIdx], BfTypeVector(), useFlags).mMethodInstance; } @@ -10728,7 +10718,7 @@ BfMethodInstance* BfModule::GetRawMethodInstanceAtIdx(BfTypeInstance* typeInstan } auto methodInstance = typeInstance->mMethodInstanceGroups[methodIdx].mDefault; - //TODO: Why did we have this adding methods to the work list? This should only happen if we actually attempt to USE the method, which should + //TODO: Why did we have this adding methods to the work list? This should only happen if we actually attempt to USE the method, which should // be from a call to the NON-raw version // if (!methodInstance->mMethodInstanceGroup->IsImplemented()) // { @@ -10750,7 +10740,7 @@ BfMethodInstance* BfModule::GetRawMethodInstance(BfTypeInstance* typeInstance, B } BfMethodInstance* BfModule::GetRawMethodByName(BfTypeInstance* typeInstance, const StringImpl& methodName, int paramCount, bool checkBase, bool allowMixin) -{ +{ PopulateType(typeInstance, BfPopulateType_DataAndMethods); while (typeInstance != NULL) @@ -10778,14 +10768,14 @@ BfMethodInstance* BfModule::GetRawMethodByName(BfTypeInstance* typeInstance, con } BfMethodInstance* BfModule::GetUnspecializedMethodInstance(BfMethodInstance* methodInstance, bool useUnspecializedType) -{ +{ if ((methodInstance->mMethodInfoEx != NULL) && (methodInstance->mMethodInfoEx->mMethodGenericArguments.size() != 0)) methodInstance = methodInstance->mMethodInstanceGroup->mDefault; - + auto owner = methodInstance->mMethodInstanceGroup->mOwner; - if (!useUnspecializedType) - return methodInstance; + if (!useUnspecializedType) + return methodInstance; if (!owner->IsGenericTypeInstance()) return methodInstance; @@ -10800,29 +10790,29 @@ BfMethodInstance* BfModule::GetUnspecializedMethodInstance(BfMethodInstance* met auto genericType = (BfTypeInstance*)owner; if ((genericType->IsUnspecializedType()) && (!genericType->IsUnspecializedTypeVariation())) return methodInstance; - + if (methodInstance->mMethodDef->mIsLocalMethod) return methodInstance; if (methodInstance->mMethodDef->mDeclaringType->IsEmitted()) return methodInstance; - auto unspecializedType = ResolveTypeDef(genericType->mTypeDef->GetDefinition()); + auto unspecializedType = ResolveTypeDef(genericType->mTypeDef->GetDefinition()); if (unspecializedType == NULL) { AssertErrorState(); return methodInstance; - } + } if (unspecializedType == NULL) return methodInstance; auto unspecializedTypeInst = unspecializedType->ToTypeInstance(); - return GetRawMethodInstanceAtIdx(unspecializedTypeInst, methodInstance->mMethodDef->mIdx); + return GetRawMethodInstanceAtIdx(unspecializedTypeInst, methodInstance->mMethodDef->mIdx); } int BfModule::GetGenericParamAndReturnCount(BfMethodInstance* methodInstance) { int genericCount = 0; auto unspecializedMethodInstance = GetUnspecializedMethodInstance(methodInstance); - for (int paramIdx = 0; paramIdx < unspecializedMethodInstance->GetParamCount(); paramIdx++) + for (int paramIdx = 0; paramIdx < unspecializedMethodInstance->GetParamCount(); paramIdx++) { auto param = unspecializedMethodInstance->GetParamType(paramIdx); if (param->IsGenericParam()) @@ -10842,17 +10832,17 @@ BfModule* BfModule::GetSpecializedMethodModule(const SizedArrayImpl& if (mParentModule != NULL) mainModule = mParentModule; - BfModule* specModule = NULL; + BfModule* specModule = NULL; BfModule** specModulePtr = NULL; if (mainModule->mSpecializedMethodModules.TryGetValueWith(projectList, &specModulePtr)) { return *specModulePtr; } else - { + { String specModuleName = mModuleName; for (auto bfProject : projectList) - { + { specModuleName += StrFormat("@%s", bfProject->mSafeName.c_str()); } specModule = new BfModule(mContext, specModuleName); @@ -10870,7 +10860,7 @@ BfModule* BfModule::GetSpecializedMethodModule(const SizedArrayImpl& } BfIRValue BfModule::CreateFunctionFrom(BfMethodInstance* methodInstance, bool tryExisting, bool isInlined) -{ +{ if (IsSkippingExtraResolveChecks()) return BfIRValue(); @@ -10901,7 +10891,7 @@ BfIRValue BfModule::CreateFunctionFrom(BfMethodInstance* methodInstance, bool tr auto intrinsic = GetIntrinsic(methodInstance); if (intrinsic) return intrinsic; - + if (methodInstance->GetImportCallKind() != BfImportCallKind_None) { return CreateDllImportGlobalVar(methodInstance, false); @@ -10926,17 +10916,17 @@ BfIRValue BfModule::CreateFunctionFrom(BfMethodInstance* methodInstance, bool tr // mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_DllImport); // } // } - + return func; } BfModuleMethodInstance BfModule::GetMethodInstanceAtIdx(BfTypeInstance* typeInstance, int methodIdx, const char* assertName, BfGetMethodInstanceFlags flags) -{ +{ if (assertName != NULL) { BF_ASSERT(typeInstance->mTypeDef->mMethods[methodIdx]->mName == assertName); - } - + } + PopulateType(typeInstance, BfPopulateType_DataAndMethods); auto methodInstance = typeInstance->mMethodInstanceGroups[methodIdx].mDefault; @@ -10962,10 +10952,10 @@ BfModuleMethodInstance BfModule::GetMethodInstanceAtIdx(BfTypeInstance* typeInst BfIRFunction func(mBfIRBuilder->GetFakeVal()); return BfModuleMethodInstance(methodInstance, func); } - + if (foreignType != NULL) return GetMethodInstance(typeInstance, methodDef, BfTypeVector(), (BfGetMethodInstanceFlags)(flags | BfGetMethodInstanceFlag_ForeignMethodDef), foreignType); - return GetMethodInstance(typeInstance, typeInstance->mTypeDef->mMethods[methodIdx], BfTypeVector(), flags); + return GetMethodInstance(typeInstance, typeInstance->mTypeDef->mMethods[methodIdx], BfTypeVector(), flags); } BfModuleMethodInstance BfModule::GetMethodByName(BfTypeInstance* typeInstance, const StringImpl& methodName, int paramCount, bool checkBase) @@ -10974,7 +10964,7 @@ BfModuleMethodInstance BfModule::GetMethodByName(BfTypeInstance* typeInstance, c while (typeInstance != NULL) { - typeInstance->mTypeDef->PopulateMemberSets(); + typeInstance->mTypeDef->PopulateMemberSets(); BfMemberSetEntry* entry = NULL; BfMethodDef* methodDef = NULL; if (typeInstance->mTypeDef->mMethodSet.TryGetWith(methodName, &entry)) @@ -10993,7 +10983,6 @@ BfModuleMethodInstance BfModule::GetMethodByName(BfTypeInstance* typeInstance, c methodDef = methodDef->mNextWithSameName; } - if (!checkBase) break; typeInstance = typeInstance->mBaseType; @@ -11014,11 +11003,11 @@ BfModuleMethodInstance BfModule::GetMethodByName(BfTypeInstance* typeInstance, c methodDef = (BfMethodDef*)entry->mMemberDef; while (methodDef != NULL) - { + { if ((methodDef->mMethodType != BfMethodType_Mixin) && (methodDef->mGenericParams.size() == 0) && (paramTypes.size() == methodDef->mParams.size())) - { + { auto moduleMethodInstance = GetMethodInstanceAtIdx(typeInstance, methodDef->mIdx); if (moduleMethodInstance.mMethodInstance != NULL) { @@ -11059,14 +11048,14 @@ BfOperatorInfo* BfModule::GetOperatorInfo(BfTypeInstance* typeInstance, BfOperat { while (operatorDef->mIdx >= typeInstance->mOperatorInfo.size()) typeInstance->mOperatorInfo.Add(NULL); - + if (typeInstance->mOperatorInfo[operatorDef->mIdx] == NULL) { SetAndRestoreValue ignoreErrors(mIgnoreErrors, true); SetAndRestoreValue prevTypeInstance(mCurTypeInstance, typeInstance); SetAndRestoreValue prevMethodInstance(mCurMethodInstance, NULL); - BfTypeState typeState; + BfTypeState typeState; typeState.mType = typeInstance; typeState.mCurTypeDef = operatorDef->mDeclaringType; SetAndRestoreValue prevTypeState(mContext->mCurTypeState, &typeState); @@ -11106,7 +11095,7 @@ BfType* BfModule::CheckOperator(BfTypeInstance* typeInstance, BfOperatorDef* ope if (rhs) { if (operatorInfo->mRHSType == NULL) - return NULL; + return NULL; if (!CanCast(rhs, operatorInfo->mRHSType, castFlags)) return NULL; } @@ -11466,26 +11455,26 @@ static void AddAttributeTargetName(BfAttributeTargets& flagsLeft, BfAttributeTar } static String GetAttributesTargetListString(BfAttributeTargets attrTarget) -{ +{ String resultStr; auto flagsLeft = attrTarget; - AddAttributeTargetName(flagsLeft, BfAttributeTargets_Assembly, resultStr, "assembly declarations"); + AddAttributeTargetName(flagsLeft, BfAttributeTargets_Assembly, resultStr, "assembly declarations"); AddAttributeTargetName(flagsLeft, BfAttributeTargets_Module, resultStr, "module declarations"); - AddAttributeTargetName(flagsLeft, BfAttributeTargets_Class, resultStr, "class declarations"); - AddAttributeTargetName(flagsLeft, BfAttributeTargets_Struct, resultStr, "struct declarations"); - AddAttributeTargetName(flagsLeft, BfAttributeTargets_Enum, resultStr, "enum declarations"); - AddAttributeTargetName(flagsLeft, BfAttributeTargets_Constructor, resultStr, "constructor declarations"); - AddAttributeTargetName(flagsLeft, BfAttributeTargets_Method, resultStr, "method declarations"); - AddAttributeTargetName(flagsLeft, BfAttributeTargets_Property, resultStr, "property declarations"); - AddAttributeTargetName(flagsLeft, BfAttributeTargets_Field, resultStr, "field declarations"); - AddAttributeTargetName(flagsLeft, BfAttributeTargets_StaticField, resultStr, "static field declarations"); - AddAttributeTargetName(flagsLeft, BfAttributeTargets_Interface, resultStr, "interface declarations"); - AddAttributeTargetName(flagsLeft, BfAttributeTargets_Parameter, resultStr, "parameter declarations"); + AddAttributeTargetName(flagsLeft, BfAttributeTargets_Class, resultStr, "class declarations"); + AddAttributeTargetName(flagsLeft, BfAttributeTargets_Struct, resultStr, "struct declarations"); + AddAttributeTargetName(flagsLeft, BfAttributeTargets_Enum, resultStr, "enum declarations"); + AddAttributeTargetName(flagsLeft, BfAttributeTargets_Constructor, resultStr, "constructor declarations"); + AddAttributeTargetName(flagsLeft, BfAttributeTargets_Method, resultStr, "method declarations"); + AddAttributeTargetName(flagsLeft, BfAttributeTargets_Property, resultStr, "property declarations"); + AddAttributeTargetName(flagsLeft, BfAttributeTargets_Field, resultStr, "field declarations"); + AddAttributeTargetName(flagsLeft, BfAttributeTargets_StaticField, resultStr, "static field declarations"); + AddAttributeTargetName(flagsLeft, BfAttributeTargets_Interface, resultStr, "interface declarations"); + AddAttributeTargetName(flagsLeft, BfAttributeTargets_Parameter, resultStr, "parameter declarations"); AddAttributeTargetName(flagsLeft, BfAttributeTargets_Delegate, resultStr, "delegate declarations"); - AddAttributeTargetName(flagsLeft, BfAttributeTargets_Function, resultStr, "function declarations"); - AddAttributeTargetName(flagsLeft, BfAttributeTargets_ReturnValue, resultStr, "return value"); - AddAttributeTargetName(flagsLeft, BfAttributeTargets_GenericParameter, resultStr, "generic parameters"); - AddAttributeTargetName(flagsLeft, BfAttributeTargets_Invocation, resultStr, "invocations"); + AddAttributeTargetName(flagsLeft, BfAttributeTargets_Function, resultStr, "function declarations"); + AddAttributeTargetName(flagsLeft, BfAttributeTargets_ReturnValue, resultStr, "return value"); + AddAttributeTargetName(flagsLeft, BfAttributeTargets_GenericParameter, resultStr, "generic parameters"); + AddAttributeTargetName(flagsLeft, BfAttributeTargets_Invocation, resultStr, "invocations"); AddAttributeTargetName(flagsLeft, BfAttributeTargets_MemberAccess, resultStr, "member access"); AddAttributeTargetName(flagsLeft, BfAttributeTargets_Alloc, resultStr, "allocations"); AddAttributeTargetName(flagsLeft, BfAttributeTargets_Alias, resultStr, "aliases"); @@ -11509,7 +11498,7 @@ BfIRType BfModule::CurrentAddToConstHolder(BfIRType irType) void BfModule::CurrentAddToConstHolder(BfIRValue& irVal) { auto constant = mBfIRBuilder->GetConstant(irVal); - + int stringPoolIdx = GetStringPoolIdx(irVal, mBfIRBuilder); if (stringPoolIdx != -1) { @@ -11520,23 +11509,23 @@ void BfModule::CurrentAddToConstHolder(BfIRValue& irVal) if (constant->mConstType == BfConstType_Agg) { auto constArray = (BfConstantAgg*)constant; - + SizedArray newVals; for (auto val : constArray->mValues) { auto newVal = val; CurrentAddToConstHolder(newVal); - newVals.push_back(newVal); + newVals.push_back(newVal); } irVal = mCurTypeInstance->GetOrCreateConstHolder()->CreateConstAgg(CurrentAddToConstHolder(constArray->mType), newVals); return; } - auto origConst = irVal; + auto origConst = irVal; if ((constant->mConstType == BfConstType_BitCast) || (constant->mConstType == BfConstType_BitCastNull)) { - auto bitcast = (BfConstantBitCast*)constant; + auto bitcast = (BfConstantBitCast*)constant; BfIRValue newVal; if (bitcast->mTarget) { @@ -11549,7 +11538,7 @@ void BfModule::CurrentAddToConstHolder(BfIRValue& irVal) return; } - irVal = mCurTypeInstance->CreateConst(constant, mBfIRBuilder); + irVal = mCurTypeInstance->CreateConst(constant, mBfIRBuilder); } void BfModule::ClearConstData() @@ -11563,7 +11552,7 @@ void BfModule::ClearConstData() } BfTypedValue BfModule::GetTypedValueFromConstant(BfConstant* constant, BfIRConstHolder* constHolder, BfType* wantType) -{ +{ switch (constant->mTypeCode) { case BfTypeCode_StringId: @@ -11602,7 +11591,7 @@ BfTypedValue BfModule::GetTypedValueFromConstant(BfConstant* constant, BfIRConst auto stringType = ResolveTypeDef(mCompiler->mStringTypeDef); typedValue = BfTypedValue(ConstantToCurrent(constant, constHolder, stringType, allowUnactualized), stringType); } - + if (!typedValue) { auto constVal = mBfIRBuilder->CreateConst(constant, constHolder); @@ -11618,15 +11607,15 @@ BfTypedValue BfModule::GetTypedValueFromConstant(BfConstant* constant, BfIRConst typedValue.mType = wantType; return typedValue; } - } - auto castedTypedValue = Cast(NULL, typedValue, wantType, (BfCastFlags)(BfCastFlags_SilentFail | BfCastFlags_Explicit)); + } + auto castedTypedValue = Cast(NULL, typedValue, wantType, (BfCastFlags)(BfCastFlags_SilentFail | BfCastFlags_Explicit)); if (!castedTypedValue) - return BfTypedValue(); + return BfTypedValue(); return castedTypedValue; } break; default: break; - } + } BfIRValue irValue = ConstantToCurrent(constant, constHolder, wantType); BF_ASSERT(irValue); if (!irValue) @@ -11704,13 +11693,13 @@ BfIRValue BfModule::ConstantToCurrent(BfConstant* constant, BfIRConstHolder* con if (constant->mConstType == BfConstType_PtrToInt) { auto fromPtrToInt = (BfConstantPtrToInt*)constant; - auto fromTarget = constHolder->GetConstantById(fromPtrToInt->mTarget); + auto fromTarget = constHolder->GetConstantById(fromPtrToInt->mTarget); return mBfIRBuilder->CreatePtrToInt(ConstantToCurrent(fromTarget, constHolder, NULL), fromPtrToInt->mToTypeCode); } if (constant->mConstType == BfConstType_IntToPtr) { - auto fromPtrToInt = (BfConstantIntToPtr*)constant; + auto fromPtrToInt = (BfConstantIntToPtr*)constant; auto fromTarget = constHolder->GetConstantById(fromPtrToInt->mTarget); BfIRType toIRType = fromPtrToInt->mToType; if (toIRType.mKind == BfIRTypeData::TypeKind_TypeId) @@ -11740,8 +11729,8 @@ BfIRValue BfModule::ConstantToCurrent(BfConstant* constant, BfIRConstHolder* con if ((wantType == NULL) && (constArray->mType.mKind == BfIRTypeData::TypeKind_TypeId)) wantType = mContext->mTypes[constArray->mType.mId]; - - if (wantType->IsArray()) + + if (wantType->IsArray()) wantType = CreateSizedArrayType(wantType->GetUnderlyingType(), (int)constArray->mValues.mSize); SizedArray newVals; @@ -11752,7 +11741,7 @@ BfIRValue BfModule::ConstantToCurrent(BfConstant* constant, BfIRConstHolder* con { newVals.Add(ConstantToCurrent(constHolder->GetConstant(val), constHolder, elementType)); } - } + } else { auto wantTypeInst = wantType->ToTypeInstance(); @@ -11801,7 +11790,7 @@ BfIRValue BfModule::ConstantToCurrent(BfConstant* constant, BfIRConstHolder* con return mBfIRBuilder->CreateConstAgg(mBfIRBuilder->MapType(wantType, BfIRPopulateType_Identity), newVals); } - return mBfIRBuilder->CreateConst(constant, constHolder); + return mBfIRBuilder->CreateConst(constant, constHolder); } void BfModule::ValidateCustomAttributes(BfCustomAttributes* customAttributes, BfAttributeTargets attrTarget) @@ -11810,7 +11799,7 @@ void BfModule::ValidateCustomAttributes(BfCustomAttributes* customAttributes, Bf return; for (auto& customAttribute : customAttributes->mAttributes) - { + { if (!customAttribute.mAwaitingValidation) continue; @@ -11818,7 +11807,7 @@ void BfModule::ValidateCustomAttributes(BfCustomAttributes* customAttributes, Bf { Fail(StrFormat("Attribute '%s' is not valid on this declaration type. It is only valid on %s.", customAttribute.GetRefNode()->ToString().c_str(), GetAttributesTargetListString(customAttribute.mType->mAttributeData->mAttributeTargets).c_str()), customAttribute.mRef->mAttributeTypeRef); // CS0592 - } + } customAttribute.mAwaitingValidation = false; } @@ -11832,7 +11821,7 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri if (!mCompiler->mHasRequiredTypes) return; - if ((attributesDirective != NULL) && (mCompiler->mResolvePassData != NULL)) + if ((attributesDirective != NULL) && (mCompiler->mResolvePassData != NULL)) { if (auto sourceClassifier = mCompiler->mResolvePassData->GetSourceClassifier(attributesDirective)) sourceClassifier->VisitChild(attributesDirective); @@ -11841,7 +11830,7 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri SetAndRestoreValue prevIsCapturingMethodMatchInfo; if (mCompiler->IsAutocomplete()) prevIsCapturingMethodMatchInfo.Init(mCompiler->mResolvePassData->mAutoComplete->mIsCapturingMethodMatchInfo, false); - + BfTypeInstance* baseAttrTypeInst = mContext->mUnreifiedModule->ResolveTypeDef(mCompiler->mAttributeTypeDef)->ToTypeInstance(); BfAttributeTargets targetOverride = (BfAttributeTargets)0; @@ -11891,15 +11880,15 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri BfType* attrType; if (mContext->mCurTypeState != NULL) { - SetAndRestoreValue prevTypeRef(mContext->mCurTypeState->mCurAttributeTypeRef, attributesDirective->mAttributeTypeRef); + SetAndRestoreValue prevTypeRef(mContext->mCurTypeState->mCurAttributeTypeRef, attributesDirective->mAttributeTypeRef); attrType = ResolveTypeRef(attributesDirective->mAttributeTypeRef, BfPopulateType_Identity, (BfResolveTypeRefFlags)(BfResolveTypeRefFlag_Attribute | BfResolveTypeRefFlag_NoReify)); } else { attrType = ResolveTypeRef(attributesDirective->mAttributeTypeRef, BfPopulateType_Identity, (BfResolveTypeRefFlags)(BfResolveTypeRefFlag_Attribute | BfResolveTypeRefFlag_NoReify)); } - - BfTypeDef* attrTypeDef = NULL; + + BfTypeDef* attrTypeDef = NULL; if ((attrType != NULL) && (attrType->IsTypeInstance())) attrTypeDef = attrType->ToTypeInstance()->mTypeDef; @@ -11913,13 +11902,13 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri bool isBypassedAttr = false; if (attrTypeDef != NULL) - { + { // 'Object' has some dependencies on some attributes, but those attributes are classes so we have a circular dependency issue // We solve it by having a 'bypass' for known attributes that Object depends on if ((attributesDirective->mArguments.empty()) && (autoComplete == NULL) && (attrType != NULL) && (attrType->IsTypeInstance())) { if (attrType->IsInstanceOf(mCompiler->mCReprAttributeTypeDef)) - { + { for (auto methodDef : attrTypeDef->mMethods) { if ((methodDef->mMethodType == BfMethodType_Ctor) && (methodDef->mProtection == BfProtection_Public)) @@ -11932,7 +11921,7 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri } } } - + if (isBypassedAttr) { customAttribute.mAwaitingValidation = false; @@ -11944,22 +11933,22 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri SetAndRestoreValue prevCurMethodInst(mContext->mUnreifiedModule->mCurMethodInstance, mCurMethodInstance); if (mContext->mCurTypeState != NULL) { - SetAndRestoreValue prevTypeRef(mContext->mCurTypeState->mCurAttributeTypeRef, attributesDirective->mAttributeTypeRef); + SetAndRestoreValue prevTypeRef(mContext->mCurTypeState->mCurAttributeTypeRef, attributesDirective->mAttributeTypeRef); mContext->mUnreifiedModule->ResolveTypeResult(attributesDirective->mAttributeTypeRef, attrType, BfPopulateType_BaseType, (BfResolveTypeRefFlags)0); } else { mContext->mUnreifiedModule->ResolveTypeResult(attributesDirective->mAttributeTypeRef, attrType, BfPopulateType_BaseType, (BfResolveTypeRefFlags)0); } - } - + } + BfTypeInstance* attrTypeInst = NULL; if (attrType == NULL) continue; attrTypeInst = attrType->ToTypeInstance(); if ((attrTypeInst != NULL) && (attrTypeInst->mDefineState != BfTypeDefineState_DefinedAndMethodsSlotting)) - mContext->mUnreifiedModule->PopulateType(attrType, BfPopulateType_DataAndMethods); - + mContext->mUnreifiedModule->PopulateType(attrType, BfPopulateType_DataAndMethods); + if ((attrTypeInst == NULL) || (!TypeIsSubTypeOf(attrTypeInst, baseAttrTypeInst)) || (attrTypeInst->mAttributeData == NULL)) { Fail(StrFormat("'%s' is not an attribute class", TypeToString(attrType).c_str()), attributesDirective->mAttributeTypeRef); //CS0616 @@ -11976,8 +11965,8 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri AddDependency(attrTypeInst, mCurTypeInstance, BfDependencyMap::DependencyFlag_CustomAttribute); customAttribute.mType = attrTypeInst; - - bool allocatedMethodState = NULL; + + bool allocatedMethodState = NULL; defer( { if (allocatedMethodState) @@ -12015,11 +12004,11 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri inPropSet = true; if (autoComplete != NULL) autoComplete->CheckNode(assignExpr->mLeft, true); - + String findName = assignExpr->mLeft->ToString(); BfPropertyDef* bestProp = NULL; BfTypeInstance* bestPropTypeInst = NULL; - BfFieldDef* bestField = NULL; + BfFieldDef* bestField = NULL; BfTypeInstance* bestFieldTypeInst = NULL; auto checkTypeInst = attrTypeInst; while (checkTypeInst != NULL) @@ -12055,10 +12044,10 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri checkTypeInst = checkTypeInst->mBaseType; } - + bool handledExpr = false; - if (bestField != NULL) + if (bestField != NULL) { handledExpr = true; @@ -12077,12 +12066,12 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri AddDependency(bestFieldTypeInst, mCurTypeInstance, BfDependencyMap::DependencyFlag_CustomAttribute); - BfCustomAttributeSetField setField; + BfCustomAttributeSetField setField; setField.mFieldRef = BfFieldRef(bestFieldTypeInst, bestField); auto& fieldTypeInst = checkTypeInst->mFieldInstances[bestField->mIdx]; if (assignExpr->mRight != NULL) - { + { BfTypedValue result = constResolver.Resolve(assignExpr->mRight, fieldTypeInst.mResolvedType, BfConstResolveFlag_NoActualizeValues); if (result) { @@ -12096,7 +12085,7 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri else if (bestProp == NULL) { Fail(StrFormat("'%s' does not contain a field or property named '%s'", TypeToString(attrTypeInst).c_str(), findName.c_str()), assignExpr->mLeft); - } + } else { BfMethodDef* setMethod = NULL; @@ -12183,7 +12172,7 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri resolvedArg.mTypedValue = constResolver.Resolve(arg, NULL, BfConstResolveFlag_NoActualizeValues); if (!inPropSet) - { + { argValues.push_back(resolvedArg); } } @@ -12191,21 +12180,21 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri if (autoComplete != NULL) autoComplete->mShowAttributeProperties = NULL; } - + auto wasCapturingMethodInfo = false; if (autoComplete != NULL) { wasCapturingMethodInfo = autoComplete->mIsCapturingMethodMatchInfo; if (attributesDirective->mCtorOpenParen != NULL) autoComplete->CheckInvocation(attributesDirective, attributesDirective->mCtorOpenParen, attributesDirective->mCtorCloseParen, attributesDirective->mCommas); - } - + } + BfMethodMatcher methodMatcher(attributesDirective, this, "", argValues, BfMethodGenericArguments()); methodMatcher.mBfEvalExprFlags = constResolver.mBfEvalExprFlags; attrTypeDef = attrTypeInst->mTypeDef; bool success = true; - + bool isFailurePass = false; for (int pass = 0; pass < 2; pass++) { @@ -12241,9 +12230,9 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri } if (methodMatcher.mBestMethodDef == NULL) - methodMatcher.mBestMethodDef = methodMatcher.mBackupMethodDef; + methodMatcher.mBestMethodDef = methodMatcher.mBackupMethodDef; - BF_ASSERT(methodMatcher.mBestMethodDef != NULL); + BF_ASSERT(methodMatcher.mBestMethodDef != NULL); customAttribute.mCtor = methodMatcher.mBestMethodDef; if (methodMatcher.mBestMethodTypeInstance == mCurTypeInstance) @@ -12256,7 +12245,7 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri if (!constResolver.PrepareMethodArguments(attributesDirective->mAttributeTypeRef, &methodMatcher, customAttribute.mCtorArgs)) success = false; - + for (auto& arg : argValues) { if ((arg.mArgFlags & BfArgFlag_DeferredEval) != 0) @@ -12275,7 +12264,7 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri CurrentAddToConstHolder(ctorArg); } } - + if (attributesDirective->mAttributeTargetSpecifier != NULL) { targetOverride = BfAttributeTargets_ReturnValue; @@ -12284,7 +12273,7 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri Fail(StrFormat("'%s' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are '%s'. All attributes in this block will be ignored.", GetAttributesTargetListString(targetOverride).c_str(), GetAttributesTargetListString(attrTarget).c_str()), attributesDirective->mAttributeTargetSpecifier); // CS0657 success = false; - } + } } if ((success) && (targetOverride != (BfAttributeTargets)0)) @@ -12302,11 +12291,11 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri methodInfoEx->mMethodCustomAttributes->mReturnCustomAttributes->mAttributes.push_back(customAttribute); } } - + // Mark as failed since we don't actually want to add this to the custom attributes set - success = false; + success = false; } - + if (success) { if ((attrTypeInst->mAttributeData->mFlags & BfAttributeFlag_DisallowAllowMultiple) != 0) @@ -12315,14 +12304,14 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri { if (prevCustomAttribute.mType == attrTypeInst) { - Fail(StrFormat("Duplicate '%s' attribute", attributesDirective->mAttributeTypeRef->ToCleanAttributeString().c_str()), attributesDirective->mAttributeTypeRef); // CS0579 + Fail(StrFormat("Duplicate '%s' attribute", attributesDirective->mAttributeTypeRef->ToCleanAttributeString().c_str()), attributesDirective->mAttributeTypeRef); // CS0579 } } } } if (success) - { + { customAttributes->mAttributes.push_back(customAttribute); } } @@ -12396,7 +12385,7 @@ void BfModule::ProcessTypeInstCustomAttributes(int& packing, bool& isUnion, bool isOrdered = true; } else if (typeName == "System.OrderedAttribute") - { + { isOrdered = true; } else if (typeName == "System.AlwaysIncludeAttribute") @@ -12410,7 +12399,7 @@ void BfModule::ProcessTypeInstCustomAttributes(int& packing, bool& isUnion, bool { auto constant = mCurTypeInstance->mConstHolder->GetConstant(setProp.mParam.mValue); if ((constant != NULL) && (constant->mBool)) - mCurTypeInstance->mAlwaysIncludeFlags = (BfAlwaysIncludeFlags)(mCurTypeInstance->mAlwaysIncludeFlags | BfAlwaysIncludeFlag_AssumeInstantiated); + mCurTypeInstance->mAlwaysIncludeFlags = (BfAlwaysIncludeFlags)(mCurTypeInstance->mAlwaysIncludeFlags | BfAlwaysIncludeFlag_AssumeInstantiated); } else if (propertyDef->mName == "IncludeAllMethods") { @@ -12453,7 +12442,7 @@ void BfModule::ProcessTypeInstCustomAttributes(int& packing, bool& isUnion, bool if ((customAttribute.mType->mAttributeData != NULL) && ((customAttribute.mType->mAttributeData->mAlwaysIncludeUser & BfAlwaysIncludeFlag_AssumeInstantiated) != 0)) mCurTypeInstance->mAlwaysIncludeFlags = (BfAlwaysIncludeFlags)(mCurTypeInstance->mAlwaysIncludeFlags | customAttribute.mType->mAttributeData->mAlwaysIncludeUser); } - } + } } // Checking to see if we're an attribute or not @@ -12479,14 +12468,14 @@ void BfModule::ProcessCustomAttributeData() if (mCurTypeInstance->mCustomAttributes != NULL) { for (auto& customAttribute : mCurTypeInstance->mCustomAttributes->mAttributes) - { + { if (customAttribute.mType->IsInstanceOf(mCompiler->mAttributeUsageAttributeTypeDef)) { if (customAttribute.mCtorArgs.size() > 0) { auto constant = mCurTypeInstance->mConstHolder->GetConstant(customAttribute.mCtorArgs[0]); if ((constant != NULL) && (mBfIRBuilder->IsInt(constant->mTypeCode))) - attributeData->mAttributeTargets = (BfAttributeTargets)constant->mInt32; + attributeData->mAttributeTargets = (BfAttributeTargets)constant->mInt32; } if (customAttribute.mCtorArgs.size() == 2) @@ -12503,7 +12492,7 @@ void BfModule::ProcessCustomAttributeData() BfPropertyDef* propDef = setProp.mPropertyRef; if (propDef->mName == "AllowMultiple") - { + { auto constant = mCurTypeInstance->mConstHolder->GetConstant(setProp.mParam.mValue); if ((constant != NULL) && (constant->mBool)) attributeData->mFlags = (BfAttributeFlags)(attributeData->mFlags & ~BfAttributeFlag_DisallowAllowMultiple); @@ -12528,7 +12517,7 @@ void BfModule::ProcessCustomAttributeData() { auto constant = mCurTypeInstance->mConstHolder->GetConstant(setProp.mParam.mValue); if (constant != NULL) - attributeData->mAlwaysIncludeUser = (BfAlwaysIncludeFlags)constant->mInt32; + attributeData->mAlwaysIncludeUser = (BfAlwaysIncludeFlags)constant->mInt32; } } @@ -12538,9 +12527,9 @@ void BfModule::ProcessCustomAttributeData() } if ((!hasCustomAttribute) && (mCurTypeInstance->mBaseType->mAttributeData != NULL)) - { + { attributeData->mAttributeTargets = mCurTypeInstance->mBaseType->mAttributeData->mAttributeTargets; - attributeData->mFlags = mCurTypeInstance->mBaseType->mAttributeData->mFlags; + attributeData->mFlags = mCurTypeInstance->mBaseType->mAttributeData->mFlags; attributeData->mAlwaysIncludeUser = mCurTypeInstance->mBaseType->mAttributeData->mAlwaysIncludeUser; } @@ -12641,7 +12630,7 @@ BfVariant BfModule::TypedValueToVariant(BfAstNode* refNode, const BfTypedValue& } BfTypedValue BfModule::RemoveRef(BfTypedValue typedValue) -{ +{ if ((typedValue.mType != NULL) && (typedValue.mType->IsRef())) { auto refType = (BfRefType*)typedValue.mType; @@ -12727,7 +12716,7 @@ BfTypedValue BfModule::LoadValue(BfTypedValue typedValue, BfAstNode* refNode, bo { auto globalVar = (BfGlobalVar*)constantValue; if (globalVar->mName[0] == '#') - { + { BfTypedValue result = GetCompilerFieldValue(globalVar->mName); if (result) { @@ -12793,10 +12782,10 @@ BfTypedValue BfModule::LoadValue(BfTypedValue typedValue, BfAstNode* refNode, bo if (loadedVal) { if (typedValue.mType->IsVar()) - { + { return BfTypedValue(loadedVal, typedValue.mType, false); } - + PopulateType(typedValue.mType, BfPopulateType_Data); loadedVal = mBfIRBuilder->CreateAlignedLoad(loadedVal, std::max(1, (int)typedValue.mType->mAlign), isVolatile || typedValue.IsVolatile()); } @@ -12841,7 +12830,7 @@ BfTypedValue BfModule::AggregateSplat(BfTypedValue typedValue, BfIRValue* valueA }; std::function checkTypeLambda = [&](BfType* checkType) - { + { if (checkType->IsStruct()) { BfIRValue curValue = mBfIRBuilder->CreateUndefValue(mBfIRBuilder->MapType(checkType, BfIRPopulateType_Full)); @@ -12899,7 +12888,7 @@ BfTypedValue BfModule::AggregateSplat(BfTypedValue typedValue, BfIRValue* valueA } else { - fieldValue = _ExtractValue(checkType); + fieldValue = _ExtractValue(checkType); } curValue = mBfIRBuilder->CreateInsertValue(curValue, fieldValue, dataIdx); } @@ -12913,7 +12902,7 @@ BfTypedValue BfModule::AggregateSplat(BfTypedValue typedValue, BfIRValue* valueA return BfIRValue(); }; - BfIRValue value = checkTypeLambda(typedValue.mType); + BfIRValue value = checkTypeLambda(typedValue.mType); return BfTypedValue(value, typedValue.mType, typedValue.IsThis() ? BfTypedValueKind_ThisValue : BfTypedValueKind_Value); } @@ -12929,7 +12918,7 @@ void BfModule::AggregateSplatIntoAddr(BfTypedValue typedValue, BfIRValue addrVal /*static int sCallIdx = 0; if (!mCompiler->mIsResolveOnly) sCallIdx++; - int callIdx = sCallIdx;*/ + int callIdx = sCallIdx;*/ int elementIdx = 0; @@ -12996,7 +12985,7 @@ void BfModule::AggregateSplatIntoAddr(BfTypedValue typedValue, BfIRValue addrVal // NOP; // } - auto val = ExtractSplatValue(typedValue, elementIdx++, dataType); + auto val = ExtractSplatValue(typedValue, elementIdx++, dataType); mBfIRBuilder->CreateStore(val, fieldAddrVal); } } @@ -13006,10 +12995,9 @@ void BfModule::AggregateSplatIntoAddr(BfTypedValue typedValue, BfIRValue addrVal auto val = ExtractSplatValue(typedValue, elementIdx++, checkType); mBfIRBuilder->CreateStore(val, curAddrVal); } - }; - checkTypeLambda(typedValue.mType, addrVal); + checkTypeLambda(typedValue.mType, addrVal); } BfTypedValue BfModule::MakeAddressable(BfTypedValue typedVal, bool forceMutable, bool forceAddressable) @@ -13021,12 +13009,12 @@ BfTypedValue BfModule::MakeAddressable(BfTypedValue typedVal, bool forceMutable, (!typedVal.mType->IsValuelessType()))) { wasReadOnly = true; // Any non-addr is implicitly read-only - + //static int gCallIdx = 0; FixValueActualization(typedVal); if (typedVal.IsAddr()) return typedVal; - BfType* type = typedVal.mType; + BfType* type = typedVal.mType; PopulateType(type); BfIRValue tempVar; if (typedVal.mValue.IsFake()) @@ -13039,7 +13027,7 @@ BfTypedValue BfModule::MakeAddressable(BfTypedValue typedVal, bool forceMutable, else mBfIRBuilder->CreateAlignedStore(typedVal.mValue, tempVar, type->mAlign); } - + if (forceMutable) wasReadOnly = false; @@ -13054,7 +13042,7 @@ BfTypedValue BfModule::MakeAddressable(BfTypedValue typedVal, bool forceMutable, BfTypedValue BfModule::RemoveReadOnly(BfTypedValue typedValue) { if (typedValue.mKind == BfTypedValueKind_ReadOnlyAddr) - typedValue.mKind = BfTypedValueKind_Addr; + typedValue.mKind = BfTypedValueKind_Addr; return typedValue; } @@ -13093,7 +13081,7 @@ BfIRValue BfModule::ExtractSplatValue(BfTypedValue typedValue, int componentIdx, if (decompAddr == typedValue.mValue) { val = checkMethodState->mSplatDecompAddrs[idx + componentIdx]; - + if ((wantType->IsComposite()) && (typedValue.mType->IsMethodRef())) { // This is really backing for a POINTER to a composite inside a methodRef @@ -13129,7 +13117,7 @@ BfIRValue BfModule::ExtractSplatValue(BfTypedValue typedValue, int componentIdx, if (val) { if (typedValue.mKind == BfTypedValueKind_SplatHead_NeedsCasting) - { + { BF_ASSERT(wantType != NULL); if (wantType != NULL) return mBfIRBuilder->CreateBitCast(val, mBfIRBuilder->MapType(wantType)); @@ -13139,7 +13127,7 @@ BfIRValue BfModule::ExtractSplatValue(BfTypedValue typedValue, int componentIdx, } BFMODULE_FATAL(this, "Splat not found"); - return BfIRValue(); + return BfIRValue(); } BfTypedValue BfModule::ExtractValue(BfTypedValue typedValue, BfFieldInstance* fieldInstance, int fieldIdx) @@ -13149,7 +13137,7 @@ BfTypedValue BfModule::ExtractValue(BfTypedValue typedValue, BfFieldInstance* fi BfType* fieldType = NULL; if (fieldInstance != NULL) { - fieldType = fieldInstance->mResolvedType; + fieldType = fieldInstance->mResolvedType; if (typedValue.mType->IsUnion()) { if (fieldIdx == 1) @@ -13167,12 +13155,12 @@ BfTypedValue BfModule::ExtractValue(BfTypedValue typedValue, BfFieldInstance* fi { if (typedValue.mType->IsPayloadEnum()) { - auto typeInst = typedValue.mType->ToTypeInstance(); + auto typeInst = typedValue.mType->ToTypeInstance(); if (fieldIdx == 1) fieldType = typeInst->GetUnionInnerType(); else if (fieldIdx == 2) { - fieldType = typeInst->GetDiscriminatorType(&useFieldIdx); + fieldType = typeInst->GetDiscriminatorType(&useFieldIdx); } } else if (typedValue.mType->IsUnion()) @@ -13193,16 +13181,16 @@ BfTypedValue BfModule::ExtractValue(BfTypedValue typedValue, BfFieldInstance* fi BF_ASSERT(typedValue.mType->IsStruct()); if (typedValue.IsSplat()) - { + { if (typedValue.mType->IsPayloadEnum()) - { + { if (fieldIdx == 1) { // Payload auto typeInst = typedValue.mType->ToTypeInstance(); auto unionInnerType = typeInst->GetUnionInnerType(); bool isAddr = false; - BfIRValue irVal = ExtractSplatValue(typedValue, 0, unionInnerType, &isAddr); + BfIRValue irVal = ExtractSplatValue(typedValue, 0, unionInnerType, &isAddr); return BfTypedValue(irVal, unionInnerType, BfTypedValueKind_SplatHead); } @@ -13222,7 +13210,7 @@ BfTypedValue BfModule::ExtractValue(BfTypedValue typedValue, BfFieldInstance* fi BfIRValue irVal = ExtractSplatValue(typedValue, componentIdx, dscrType, &isAddr); return BfTypedValue(irVal, dscrType, isAddr); } - } + } int componentIdx = 0; @@ -13234,7 +13222,7 @@ BfTypedValue BfModule::ExtractValue(BfTypedValue typedValue, BfFieldInstance* fi { auto checkTypeInstance = checkType->ToTypeInstance(); if ((checkType->IsUnion()) || (checkType->IsEnum())) - { + { //TODO: Why did we have this removed? It messed up an extraction from a nullable splattable fieldType = checkTypeInstance->GetUnionInnerType(); checkTypeLambda(fieldType); @@ -13242,10 +13230,10 @@ BfTypedValue BfModule::ExtractValue(BfTypedValue typedValue, BfFieldInstance* fi if (checkType->IsEnum()) { // Past discriminator... - componentIdx++; - } + componentIdx++; + } return; - } + } if (checkTypeInstance->mBaseType != NULL) checkTypeLambda(checkTypeInstance->mBaseType); @@ -13294,8 +13282,8 @@ BfTypedValue BfModule::ExtractValue(BfTypedValue typedValue, BfFieldInstance* fi if (typedValue.IsAddr()) { BF_ASSERT(fieldType != NULL); - auto valRef = mBfIRBuilder->CreateInBoundsGEP(typedValue.mValue, 0, useFieldIdx); - return BfTypedValue(valRef, fieldType, BfTypedValueKind_ReadOnlyAddr); + auto valRef = mBfIRBuilder->CreateInBoundsGEP(typedValue.mValue, 0, useFieldIdx); + return BfTypedValue(valRef, fieldType, BfTypedValueKind_ReadOnlyAddr); } else { @@ -13310,7 +13298,7 @@ BfIRValue BfModule::ExtractValue(BfTypedValue typedValue, int dataIdx) { auto addrVal = mBfIRBuilder->CreateInBoundsGEP(typedValue.mValue, 0, dataIdx); return mBfIRBuilder->CreateAlignedLoad(addrVal, typedValue.mType->mAlign); - } + } return mBfIRBuilder->CreateExtractValue(typedValue.mValue, dataIdx); } @@ -13328,7 +13316,7 @@ BfIRValue BfModule::CreateIndexedValue(BfType* elementType, BfIRValue value, BfI // else // return mBfIRBuilder->CreateInBoundsGEP(value, indexValue); // } -// +// // auto ptrType = CreatePointerType(elementType); // auto ofsVal = mBfIRBuilder->CreateNumericCast(indexValue, true, BfTypeCode_IntPtr); // auto ofsScaledVal = mBfIRBuilder->CreateMul(ofsVal, mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, elementType->GetStride())); @@ -13357,7 +13345,7 @@ bool BfModule::CheckModifyValue(BfTypedValue& typedValue, BfAstNode* refNode, co if (typedValue.mType->IsVar()) return true; - + if (typedValue.IsReadOnly()) { Fail(StrFormat("Cannot %s read-only variable", modifyType), refNode); @@ -13396,7 +13384,7 @@ bool BfModule::CompareMethodSignatures(BfMethodInstance* methodA, BfMethodInstan else if (methodA->mMethodDef->mName != methodB->mMethodDef->mName) return false; if (methodA->mMethodDef->mCheckedKind != methodB->mMethodDef->mCheckedKind) - return false; + return false; if (methodA->mMethodDef->mHasComptime != methodB->mMethodDef->mHasComptime) return false; if ((methodA->mMethodDef->mMethodType == BfMethodType_Mixin) != (methodB->mMethodDef->mMethodType == BfMethodType_Mixin)) @@ -13406,7 +13394,7 @@ bool BfModule::CompareMethodSignatures(BfMethodInstance* methodA, BfMethodInstan { if (methodA->mMethodDef->mIsStatic != methodB->mMethodDef->mIsStatic) return false; - } + } if (methodA->mMethodDef->mMethodType == BfMethodType_Operator) { @@ -13417,7 +13405,7 @@ bool BfModule::CompareMethodSignatures(BfMethodInstance* methodA, BfMethodInstan if (operatorA->mOperatorDeclaration->mUnaryOp != operatorB->mOperatorDeclaration->mUnaryOp) return false; if (operatorA->mOperatorDeclaration->mBinOp != operatorB->mOperatorDeclaration->mBinOp) - return false; + return false; if (operatorA->mOperatorDeclaration->mAssignOp != operatorB->mOperatorDeclaration->mAssignOp) return false; if (operatorA->mOperatorDeclaration->mIsConvOperator) @@ -13436,16 +13424,16 @@ bool BfModule::CompareMethodSignatures(BfMethodInstance* methodA, BfMethodInstan if (methodA->mHadGenericDelegateParams != methodB->mHadGenericDelegateParams) return false; - for (int paramIdx = 0; paramIdx < (int)methodA->GetParamCount() - implicitParamCountA; paramIdx++) + for (int paramIdx = 0; paramIdx < (int)methodA->GetParamCount() - implicitParamCountA; paramIdx++) { if ((!BfTypeUtils::TypeEquals(methodA->GetParamType(paramIdx + implicitParamCountA), methodB->GetParamType(paramIdx + implicitParamCountB), implOwner)) || (methodA->GetParamKind(paramIdx + implicitParamCountA) != methodB->GetParamKind(paramIdx + implicitParamCountB))) return false; } - + // Compare generic params. Generic params are part of the method signature here if (methodA->GetNumGenericParams() != methodB->GetNumGenericParams()) - return false; + return false; for (int genericParamIdx = 0; genericParamIdx < (int)methodA->GetNumGenericParams(); genericParamIdx++) { auto genericParamA = methodA->mMethodInfoEx->mGenericParams[genericParamIdx]; @@ -13460,7 +13448,7 @@ bool BfModule::CompareMethodSignatures(BfMethodInstance* methodA, BfMethodInstan for (int interfaceIdx = 0; interfaceIdx < (int)genericParamA->mInterfaceConstraints.size(); interfaceIdx++) if (genericParamA->mInterfaceConstraints[interfaceIdx] != genericParamB->mInterfaceConstraints[interfaceIdx]) return false; - } + } return true; } @@ -13495,11 +13483,11 @@ bool BfModule::IsCompatibleInterfaceMethod(BfMethodInstance* iMethodInst, BfMeth if (iOperatorDef->mOperatorDeclaration->mUnaryOp != operatorDef->mOperatorDeclaration->mUnaryOp) return false; if (iOperatorDef->mOperatorDeclaration->mBinOp != operatorDef->mOperatorDeclaration->mBinOp) - return false; + return false; } if (iMethodInst->GetParamCount() != methodInstance->GetParamCount()) - return false; + return false; auto selfType = methodInstance->GetOwner(); for (int paramIdx = 0; paramIdx < (int)iMethodInst->GetParamCount(); paramIdx++) @@ -13541,23 +13529,23 @@ bool BfModule::IsCompatibleInterfaceMethod(BfMethodInstance* iMethodInst, BfMeth } void BfModule::AddMethodReference(const BfMethodRef& methodRef, BfGetMethodInstanceFlags flags) -{ +{ BfMethodInstance* methodInstance = methodRef; if ((mCurTypeInstance != NULL) && (!mCompiler->IsAutocomplete())) { auto methodInstanceGroup = methodInstance->mMethodInstanceGroup; if ((methodInstance->IsSpecializedGenericMethod()) || (methodInstanceGroup->mOnDemandKind != BfMethodOnDemandKind_AlwaysInclude)) - { + { BF_ASSERT(!methodRef.mTypeInstance->IsFunction()); // This ensures we rebuild - there are some cases where we get a method reference but never call it, so this is required here AddDependency(methodInstance->GetOwner(), mCurTypeInstance, BfDependencyMap::DependencyFlag_Calls); - BfMethodRef methodRef = methodInstance; + BfMethodRef methodRef = methodInstance; BfSpecializedMethodRefInfo* specializedMethodRefInfo = NULL; bool isNew = mCurTypeInstance->mSpecializedMethodReferences.TryAdd(methodRef, NULL, &specializedMethodRefInfo); - + if (((flags & BfGetMethodInstanceFlag_Unreified) == 0) && ((flags & BfGetMethodInstanceFlag_NoForceReification) == 0) && (mIsReified)) @@ -13569,7 +13557,7 @@ void BfModule::AddMethodReference(const BfMethodRef& methodRef, BfGetMethodInsta } BfModuleMethodInstance BfModule::ReferenceExternalMethodInstance(BfMethodInstance* methodInstance, BfGetMethodInstanceFlags flags) -{ +{ if ((flags & BfGetMethodInstanceFlag_ResultNotUsed) != 0) return BfModuleMethodInstance(methodInstance, BfIRValue()); @@ -13595,8 +13583,8 @@ BfModuleMethodInstance BfModule::ReferenceExternalMethodInstance(BfMethodInstanc if (methodInstance->mMethodDef->mMethodType == BfMethodType_Mixin) { return BfModuleMethodInstance(methodInstance, BfIRFunction()); - } - + } + bool isInlined = (methodInstance->mAlwaysInline) || ((flags & BfGetMethodInstanceFlag_ForceInline) != 0); if ((methodInstance->mIsIntrinsic) || (methodInstance->mMethodDef->mIsExtern)) isInlined = false; @@ -13606,12 +13594,12 @@ BfModuleMethodInstance BfModule::ReferenceExternalMethodInstance(BfMethodInstanc methodRef.mMethodRefFlags = (BfMethodRefFlags)(methodRef.mMethodRefFlags | BfMethodRefFlag_AlwaysInclude); else methodRef.mMethodRefFlags = BfMethodRefFlag_None; - + if (!isGenFunction) - { + { BfIRValue* irFuncPtr = NULL; if (mFuncReferences.TryGetValue(methodRef, &irFuncPtr)) - return BfModuleMethodInstance(methodInstance, *irFuncPtr); + return BfModuleMethodInstance(methodInstance, *irFuncPtr); } if (mAwaitingInitFinish) @@ -13644,13 +13632,13 @@ BfModuleMethodInstance BfModule::ReferenceExternalMethodInstance(BfMethodInstanc inlineMethodRequest->mFromModule = this; inlineMethodRequest->mFunc = func; inlineMethodRequest->mFromModuleRevision = mRevision; - inlineMethodRequest->mMethodInstance = methodInstance; + inlineMethodRequest->mMethodInstance = methodInstance; BF_ASSERT(mIsModuleMutable); - + BfLogSysM("mInlineMethodWorkList %p for method %p in module %p in ReferenceExternalMethodInstance\n", inlineMethodRequest, methodInstance, this); } } - + return BfModuleMethodInstance(methodInstance, func); } @@ -13676,7 +13664,7 @@ BfModule* BfModule::GetOrCreateMethodModule(BfMethodInstance* methodInstance) if (methodDecl != NULL) { auto attributesDirective = methodDecl->mAttributes; - if ((attributesDirective != NULL) && (mCompiler->mResolvePassData != NULL)) + if ((attributesDirective != NULL) && (mCompiler->mResolvePassData != NULL)) { if (auto sourceClassifier = mCompiler->mResolvePassData->GetSourceClassifier(attributesDirective)) sourceClassifier->VisitChild(attributesDirective); @@ -13688,7 +13676,7 @@ BfModule* BfModule::GetOrCreateMethodModule(BfMethodInstance* methodInstance) // Only allow attributes on System.Object methods that can be handled inside the DefBuilder GetMethodCustomAttributes(methodInstance); } - BF_ASSERT(mModuleOptions == NULL); + BF_ASSERT(mModuleOptions == NULL); if (methodInstance->GetCustomAttributes() != NULL) { auto project = typeInst->mTypeDef->mProject; @@ -13748,24 +13736,24 @@ BfModule* BfModule::GetOrCreateMethodModule(BfMethodInstance* methodInstance) specModuleName += StrFormat("O%d", wantOptions.mOptLevel); if (wantOptions.mSIMDSetting != moduleOptions.mSIMDSetting) specModuleName += StrFormat("SIMD%d", wantOptions.mSIMDSetting); - + declareModule = new BfModule(mContext, specModuleName); declareModule->mProject = project; declareModule->mModuleOptions = new BfModuleOptions(); *declareModule->mModuleOptions = wantOptions; - declareModule->mParentModule = lastCheckModule; + declareModule->mParentModule = lastCheckModule; declareModule->Init(); lastCheckModule->mNextAltModule = declareModule; } } - } + } declareModule->PrepareForIRWriting(typeInst); return declareModule; } BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfMethodDef* methodDef, const BfTypeVector& methodGenericArguments, BfGetMethodInstanceFlags flags, BfTypeInstance* foreignType) -{ +{ if (methodDef->mMethodType == BfMethodType_Init) return BfModuleMethodInstance(); @@ -13795,7 +13783,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM BfLocalMethod* localMethod; if (rootMethodState->mLocalMethodCache.TryGetValue(methodDef->mName, &localMethod)) { - // Handle the def in the correct method state + // Handle the def in the correct method state return GetLocalMethodInstance(localMethod, methodGenericArguments); } @@ -13809,8 +13797,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM #endif BF_ASSERT(methodDef->mMethodType != BfMethodType_Ignore); - - + // We need to do the 'mNeedsMethodProcessing' check because we want to do a proper initial "awaiting reference" population // on the methods before we handle an on-demand situation. This also ensures that our type options are set before doing // a FinishInit @@ -13836,21 +13823,21 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM } } } - + bool tryModuleMethodLookup = false; BfModuleMethodInstance moduleMethodInst; - + BfModule* instModule = typeInst->mModule; - + if (keepInCurrentModule) { // Stay here instModule = this; } - + if (this == mContext->mUnreifiedModule) { - // Stay in this 'resolve only' module here + // Stay in this 'resolve only' module here } else if (flags & BfGetMethodInstanceFlag_ExplicitResolveOnlyPass) { @@ -13861,14 +13848,14 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM BF_ASSERT(instModule == mParentModule); } else if (instModule != this) - { + { if ((mCurMethodInstance != NULL) && (mCurMethodInstance->mMethodInfoEx != NULL) && (mCurMethodInstance->mMethodInfoEx->mMinDependDepth >= 32)) flags = (BfGetMethodInstanceFlags)(flags | BfGetMethodInstanceFlag_DepthExceeded); if ((!mIsComptimeModule) && (!mIsReified) && (instModule->mIsReified)) { BF_ASSERT(!mCompiler->mIsResolveOnly); - // A resolve-only module is specializing a method from a type in a reified module, + // A resolve-only module is specializing a method from a type in a reified module, // we need to take care that this doesn't cause anything new to become reified BfModuleMethodInstance moduleMethodInstance = mContext->mUnreifiedModule->GetMethodInstance(typeInst, methodDef, methodGenericArguments, (BfGetMethodInstanceFlags)(flags | BfGetMethodInstanceFlag_ExplicitResolveOnlyPass), foreignType); if (!moduleMethodInstance) @@ -13899,16 +13886,16 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM //specializationRequest->mMethodDef = methodDef; specializationRequest->mMethodGenericArguments = methodGenericArguments; specializationRequest->mType = typeInst; - specializationRequest->mFlags = flags; + specializationRequest->mFlags = flags; } } auto defFlags = (BfGetMethodInstanceFlags)(flags & ~BfGetMethodInstanceFlag_ForceInline); - + defFlags = (BfGetMethodInstanceFlags)(flags | BfGetMethodInstanceFlag_NoReference); if (mIsComptimeModule) - { + { defFlags = (BfGetMethodInstanceFlags)(flags | BfGetMethodInstanceFlag_MethodInstanceOnly); if (!mCompiler->mIsResolveOnly) defFlags = (BfGetMethodInstanceFlags)(flags | BfGetMethodInstanceFlag_NoForceReification | BfGetMethodInstanceFlag_Unreified | BfGetMethodInstanceFlag_MethodInstanceOnly); @@ -13926,7 +13913,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM CheckHotMethod(moduleMethodInst.mMethodInstance, ""); } } - } + } if (tryModuleMethodLookup) { @@ -13937,7 +13924,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM if (((flags & BfGetMethodInstanceFlag_ForceInline) != 0) && (!methodDef->mAlwaysInline)) { auto moduleMethodInstance = GetMethodInstance(typeInst, methodDef, methodGenericArguments, (BfGetMethodInstanceFlags)(flags & ~BfGetMethodInstanceFlag_ForceInline), foreignType); - if (moduleMethodInstance) + if (moduleMethodInstance) return ReferenceExternalMethodInstance(moduleMethodInstance.mMethodInstance, flags); return moduleMethodInst; } @@ -13946,22 +13933,22 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM bool hadConcreteInterfaceGenericArgument = false; if ((flags & BfGetMethodInstanceFlag_Unreified) != 0) - isReified = false; + isReified = false; if ((flags & BfGetMethodInstanceFlag_ExplicitResolveOnlyPass) != 0) { - isReified = false; + isReified = false; } - BfTypeVector sanitizedMethodGenericArguments; + BfTypeVector sanitizedMethodGenericArguments; SizedArray projectList; - + bool isUnspecializedPass = (flags & BfGetMethodInstanceFlag_UnspecializedPass) != 0; if ((isUnspecializedPass) && (methodDef->mGenericParams.size() == 0)) isUnspecializedPass = false; // Check for whether we are an extension method from a project that does not hold the root type, AND that isn't already the project for this type - bool isExternalExtensionMethod = false; + bool isExternalExtensionMethod = false; if ((!typeInst->IsUnspecializedType()) && (!isUnspecializedPass)) { if (((flags & BfGetMethodInstanceFlag_ForeignMethodDef) == 0) && @@ -13987,7 +13974,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM { BF_ASSERT(typeInst->mTypeDef->mIsCombinedPartial); projectList.push_back(methodDef->mDeclaringType->mProject); - } + } } } @@ -13998,7 +13985,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM { auto genericTypeInst = (BfTypeInstance*)typeInst; if (genericTypeInst->mGenericTypeInfo->mProjectsReferenced.empty()) - genericTypeInst->GenerateProjectsReferenced(); + genericTypeInst->GenerateProjectsReferenced(); typeProjectsCounts = (int)genericTypeInst->mGenericTypeInfo->mProjectsReferenced.size(); projectList.Insert(0, &genericTypeInst->mGenericTypeInfo->mProjectsReferenced[0], genericTypeInst->mGenericTypeInfo->mProjectsReferenced.size()); } @@ -14008,8 +13995,8 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM projectList.Insert(0, typeInst->mTypeDef->mProject); } - isUnspecializedPass = true; - + isUnspecializedPass = true; + for (int genericArgIdx = 0; genericArgIdx < (int) methodGenericArguments.size(); genericArgIdx++) { auto genericArgType = methodGenericArguments[genericArgIdx]; @@ -14029,14 +14016,14 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM isUnspecializedPass = false; } else - { + { BfTypeUtils::GetProjectList(genericArgType, &projectList, typeProjectsCounts); isUnspecializedPass = false; } sanitizedMethodGenericArguments.push_back(genericArgType); } - + if ((int)projectList.size() > typeProjectsCounts) { // Just leave the new items @@ -14051,8 +14038,8 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM projectList.Clear(); } } - - const BfTypeVector& lookupMethodGenericArguments = isUnspecializedPass ? BfTypeVector() : sanitizedMethodGenericArguments; + + const BfTypeVector& lookupMethodGenericArguments = isUnspecializedPass ? BfTypeVector() : sanitizedMethodGenericArguments; BfMethodInstanceGroup* methodInstGroup = NULL; if ((flags & BfGetMethodInstanceFlag_ForeignMethodDef) != 0) { @@ -14108,20 +14095,20 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM } else { - methodInstGroup = &typeInst->mMethodInstanceGroups[methodDef->mIdx]; + methodInstGroup = &typeInst->mMethodInstanceGroups[methodDef->mIdx]; } if (methodInstGroup->mOnDemandKind == BfMethodOnDemandKind_NotSet) { - if (typeInst->mDefineState > BfTypeDefineState_DefinedAndMethodsSlotted) + if (typeInst->mDefineState > BfTypeDefineState_DefinedAndMethodsSlotted) { BfLogSysM("Forcing BfMethodOnDemandKind_NotSet to BfMethodOnDemandKind_AlwaysInclude for Method:%s in Type:%p\n", methodDef->mName.c_str(), typeInst); - methodInstGroup->mOnDemandKind = BfMethodOnDemandKind_AlwaysInclude; + methodInstGroup->mOnDemandKind = BfMethodOnDemandKind_AlwaysInclude; } } - + BfIRFunction prevIRFunc; - + bool doingRedeclare = false; BfMethodInstance* methodInstance = NULL; @@ -14129,7 +14116,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM { if (!mCompiler->mIsResolveOnly) BF_ASSERT(mCompiler->mCompileState <= BfCompiler::CompileState_Normal); - methodInstance->mIsReified = true; + methodInstance->mIsReified = true; }; if (lookupMethodGenericArguments.size() == 0) @@ -14192,7 +14179,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM { if (methodInstance->mMethodProcessRequest != NULL) { - // Disconnect method process request + // Disconnect method process request methodInstance->mMethodProcessRequest->mMethodInstance = NULL; methodInstance->mMethodProcessRequest = NULL; } @@ -14220,7 +14207,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM methodInstance->mIRFunction = BfIRFunction(); if (!mIsModuleMutable) StartExtension(); - + if ((!mBfIRBuilder->mIgnoreWrites) && (methodInstance->mDeclModule != NULL)) { StringT<512> mangledName; @@ -14234,14 +14221,14 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM AddMethodToWorkList(methodInstance); } - } + } } } else { if (methodInstGroup->mDefault == NULL) - { - auto defaultMethodInstance = GetMethodInstance(typeInst, methodDef, BfTypeVector(), + { + auto defaultMethodInstance = GetMethodInstance(typeInst, methodDef, BfTypeVector(), (BfGetMethodInstanceFlags)((flags & (BfGetMethodInstanceFlag_ForeignMethodDef)) | BfGetMethodInstanceFlag_UnspecializedPass | BfGetMethodInstanceFlag_MethodInstanceOnly), foreignType); methodInstGroup = defaultMethodInstance.mMethodInstance->mMethodInstanceGroup; } @@ -14249,7 +14236,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM BF_ASSERT(lookupMethodGenericArguments.size() != 0); if (methodInstGroup->mMethodSpecializationMap == NULL) methodInstGroup->mMethodSpecializationMap = new BfMethodInstanceGroup::MapType(); - + BfMethodInstance** methodInstancePtr = NULL; if (methodInstGroup->mMethodSpecializationMap->TryGetValue(lookupMethodGenericArguments, &methodInstancePtr)) { @@ -14301,9 +14288,9 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM } } } - + if ((methodInstance != NULL) && (!doingRedeclare)) - { + { SetMethodDependency(methodInstance); if (methodInstance->mMethodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_Decl_AwaitingReference) @@ -14337,7 +14324,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM AddMethodToWorkList(methodInstance); } else - { + { methodInstance->mMethodInstanceGroup->mOnDemandKind = BfMethodOnDemandKind_Referenced; auto owningModule = methodInstance->GetOwner()->mModule; if (!owningModule->mIsScratchModule) @@ -14375,8 +14362,8 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM inlineMethodRequest->mFromModule = this; inlineMethodRequest->mFunc = methodInstance->mIRFunction; inlineMethodRequest->mFromModuleRevision = mRevision; - inlineMethodRequest->mMethodInstance = methodInstance; - + inlineMethodRequest->mMethodInstance = methodInstance; + BfLogSysM("mInlineMethodWorkList %p for method %p in module %p in GetMethodInstance\n", inlineMethodRequest, methodInstance, this); BF_ASSERT(mIsModuleMutable); } @@ -14391,7 +14378,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM return methodInstance; if (methodInstance->mDeclModule != this) - return ReferenceExternalMethodInstance(methodInstance, flags); + return ReferenceExternalMethodInstance(methodInstance, flags); if ((!methodInstance->mIRFunction) && (mIsModuleMutable) && (!mBfIRBuilder->mIgnoreWrites)) { @@ -14403,7 +14390,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM auto func = CreateDllImportGlobalVar(methodInstance, true); BF_ASSERT(func); mFuncReferences[methodInstance] = func; - } + } } return BfModuleMethodInstance(methodInstance); @@ -14434,7 +14421,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM GetMethodInstance(typeInst, methodDef, BfTypeVector(), BfGetMethodInstanceFlag_UnspecializedPass); } } - + if (methodInstance == NULL) { if (!mCompiler->EnsureCeUnpaused(typeInst)) @@ -14454,7 +14441,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM BfLogSysM("Created Default MethodInst: %p TypeInst: %p Group: %p\n", methodInstance, typeInst, methodInstGroup); } else - { + { bool depthExceeded = ((flags & BfGetMethodInstanceFlag_DepthExceeded) != 0); if ((mCurMethodInstance != NULL) && (mCurMethodInstance->mMethodInfoEx != NULL) && (mCurMethodInstance->mMethodInfoEx->mMinDependDepth >= 32)) @@ -14471,21 +14458,21 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM BF_ASSERT(added); methodInstance = new BfMethodInstance(); *methodInstancePtr = methodInstance; - - if (mCompiler->IsAutocomplete()) - methodInstance->mRequestedByAutocomplete = true; - + + if (mCompiler->IsAutocomplete()) + methodInstance->mRequestedByAutocomplete = true; + BfLogSysM("Created Specialized MethodInst: %p TypeInst: %p\n", methodInstance, typeInst); } if ((prevIRFunc) && (!prevIRFunc.IsFake())) - methodInstance->mIRFunction = prevIRFunc; // Take it over + methodInstance->mIRFunction = prevIRFunc; // Take it over } methodInstance->mMethodDef = methodDef; methodInstance->mAlwaysInline = methodDef->mAlwaysInline; methodInstance->mMethodInstanceGroup = methodInstGroup; - methodInstance->mIsReified = isReified; + methodInstance->mIsReified = isReified; SetupMethodIdHash(methodInstance); @@ -14497,7 +14484,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM BF_ASSERT(foreignType != NULL); methodInstance->GetMethodInfoEx()->mForeignType = foreignType; } - + if ((typeInst->IsInstanceOf(mCompiler->mValueTypeTypeDef)) && (methodDef->mName == BF_METHODNAME_EQUALS)) { if (!lookupMethodGenericArguments.empty()) @@ -14513,7 +14500,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM { methodInstance->mMangleWithIdx = true; } - + BF_ASSERT(typeInst == methodInstance->GetOwner()); auto methodDeclaration = methodDef->GetMethodDeclaration(); @@ -14523,10 +14510,10 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM { auto genericParamType = GetGenericParamType(BfGenericParamKind_Method, genericParamIdx); methodInstance->GetMethodInfoEx()->mMethodGenericArguments.Add(genericParamType); - } + } } else if ((methodDeclaration != NULL) && (methodDeclaration->mGenericParams != NULL)) - { + { if (!sanitizedMethodGenericArguments.IsEmpty()) methodInstance->GetMethodInfoEx()->mMethodGenericArguments = sanitizedMethodGenericArguments; if (methodDef->mGenericParams.size() != sanitizedMethodGenericArguments.size()) @@ -14541,7 +14528,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM if (genericArg->IsPrimitiveType()) genericArg = GetWrappedStructType(genericArg); if (genericArg != NULL) - AddDependency(genericArg, typeInst, BfDependencyMap::DependencyFlag_MethodGenericArg); + AddDependency(genericArg, typeInst, BfDependencyMap::DependencyFlag_MethodGenericArg); } } @@ -14553,20 +14540,20 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM { auto genericParamInstance = new BfGenericMethodParamInstance(methodDef, genericParamIdx); methodInstance->GetMethodInfoEx()->mGenericParams.push_back(genericParamInstance); - } + } } for (int externConstraintIdx = 0; externConstraintIdx < (int)methodDef->mExternalConstraints.size(); externConstraintIdx++) { auto genericParamInstance = new BfGenericMethodParamInstance(methodDef, externConstraintIdx + (int)methodDef->mGenericParams.size()); methodInstance->GetMethodInfoEx()->mGenericParams.push_back(genericParamInstance); - } - + } + bool addToWorkList = !processNow; if (mCompiler->GetAutoComplete() != NULL) { if (typeInst->IsSpecializedByAutoCompleteMethod()) - addToWorkList = false; + addToWorkList = false; if (methodInstance->mRequestedByAutocomplete) addToWorkList = false; } @@ -14585,9 +14572,9 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM if ((!methodInstance->mIsReified) && (mCompiler->mCompileState != BfCompiler::CompileState_Normal)) { - // We can be sure this method won't become reified later. Normally we can "go either way" with an unreified method + // We can be sure this method won't become reified later. Normally we can "go either way" with an unreified method // of a reified module - - // If we declare it in the reified module then we can switch it to "reified" before actual processing without any extra work, + // If we declare it in the reified module then we can switch it to "reified" before actual processing without any extra work, // BUT if we don't reify it then we have to remove the body after processing. // But if we declare it in the unreified module module and then end up needing to reify it then we need to re-declare it in // the proper reified module. @@ -14603,7 +14590,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM { declareModule->PrepareForIRWriting(methodInstance->GetOwner()); } - } + } SetMethodDependency(methodInstance); @@ -14624,8 +14611,8 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM // if ((flags & BfGetMethodInstanceFlag_NoReference) != 0) // addToWorkList = false; - - declareModule->DoMethodDeclaration(methodDef->GetMethodDeclaration(), false, addToWorkList); + + declareModule->DoMethodDeclaration(methodDef->GetMethodDeclaration(), false, addToWorkList); if (processNow) { @@ -14633,7 +14620,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM ProcessMethod(methodInstance); } - if (IsSkippingExtraResolveChecks()) + if (IsSkippingExtraResolveChecks()) return BfModuleMethodInstance(methodInstance, BfIRFunction()); if (methodInstance->mDeclModule != this) @@ -14653,7 +14640,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfMethodInstance* methodInsta BfMethodInstance* BfModule::GetOuterMethodInstance(BfMethodInstance* methodInstance) { if (!methodInstance->mMethodDef->mIsLocalMethod) - return NULL; + return NULL; auto outerLocal = methodInstance->mMethodInfoEx->mClosureInstanceInfo->mLocalMethod->mOuterLocalMethod; if (outerLocal == NULL) return NULL; @@ -14667,9 +14654,9 @@ BfMethodInstance* BfModule::GetOuterMethodInstance(BfMethodInstance* methodInsta void BfModule::SetupMethodIdHash(BfMethodInstance* methodInstance) { HashContext hashCtx; - + std::function _MixinMethodInstance = [&](BfMethodInstance* methodInstance) - { + { hashCtx.Mixin(methodInstance->GetOwner()->mTypeId); hashCtx.Mixin(methodInstance->mMethodDef->mIdx); @@ -14682,7 +14669,7 @@ void BfModule::SetupMethodIdHash(BfMethodInstance* methodInstance) }; _MixinMethodInstance(methodInstance); - + if (methodInstance->mMethodDef->mIsLocalMethod) { auto outmostMethodInstance = mCurMethodState->GetRootMethodState()->mMethodInstance; @@ -14691,7 +14678,7 @@ void BfModule::SetupMethodIdHash(BfMethodInstance* methodInstance) BF_ASSERT((outmostMethodInstance->mIdHash != 0) || (outmostMethodInstance->mIsAutocompleteMethod)); hashCtx.Mixin(outmostMethodInstance->mIdHash); } - } + } methodInstance->mIdHash = (int64)hashCtx.Finish64(); } @@ -14707,21 +14694,21 @@ bool BfModule::CheckUseMethodInstance(BfMethodInstance* methodInstance, BfAstNod BfIRValue BfModule::GetInterfaceSlotNum(BfTypeInstance* ifaceType) { BfIRValue globalValue; - + BfIRValue* globalValuePtr = NULL; if (mInterfaceSlotRefs.TryGetValue(ifaceType, &globalValuePtr)) { globalValue = *globalValuePtr; } - + if (!globalValue) { // This is necessary to reify the interface type - PopulateType(ifaceType); - + PopulateType(ifaceType); + StringT<512> slotVarName; BfMangler::MangleStaticFieldName(slotVarName, mCompiler->GetMangleKind(), ifaceType, "sBfSlotOfs"); - BfType* intType = GetPrimitiveType(BfTypeCode_Int32); + BfType* intType = GetPrimitiveType(BfTypeCode_Int32); BfIRValue value; if ((mCompiler->mHotState != NULL) && (ifaceType->mSlotNum >= 0)) @@ -14747,7 +14734,7 @@ void BfModule::HadSlotCountDependency() return; BF_ASSERT(!mBfIRBuilder->mIgnoreWrites); BF_ASSERT((mUsedSlotCount == BF_MAX(mCompiler->mMaxInterfaceSlots, 0)) || (mUsedSlotCount == -1)); - mUsedSlotCount = BF_MAX(mCompiler->mMaxInterfaceSlots, 0); + mUsedSlotCount = BF_MAX(mCompiler->mMaxInterfaceSlots, 0); } BfTypedValue BfModule::GetCompilerFieldValue(const StringImpl& str) @@ -14846,7 +14833,7 @@ BfTypedValue BfModule::GetCompilerFieldValue(const StringImpl& str) if (project != NULL) return BfTypedValue(GetStringObjectValue(mProject->mName), ResolveTypeDef(mCompiler->mStringTypeDef)); } - } + } if (str == "#TimeLocal") { @@ -14891,11 +14878,10 @@ BfTypedValue BfModule::GetCompilerFieldValue(BfTypedValue typedValue) return BfTypedValue(); } - BfTypedValue BfModule::ReferenceStaticField(BfFieldInstance* fieldInstance) -{ +{ BfIRValue globalValue; - + auto fieldDef = fieldInstance->GetFieldDef(); if ((fieldDef->mIsConst) && (!fieldDef->mIsExtern)) @@ -14909,15 +14895,15 @@ BfTypedValue BfModule::ReferenceStaticField(BfFieldInstance* fieldInstance) { return GetDefaultTypedValue(fieldInstance->GetResolvedType()); } - } + } if ((mIsScratchModule) && (mCompiler->mIsResolveOnly) && (!fieldInstance->mOwner->IsInstanceOf(mCompiler->mCompilerTypeDef))) - { + { // Just fake it for the extern and unspecialized modules // We can't do this for compilation because unreified methods with default params need to get actual global variable refs - return BfTypedValue(mBfIRBuilder->CreateConstNull(), fieldInstance->GetResolvedType(), true); + return BfTypedValue(mBfIRBuilder->CreateConstNull(), fieldInstance->GetResolvedType(), true); } - + BfIRValue* globalValuePtr = NULL; if (mStaticFieldRefs.TryGetValue(fieldInstance, &globalValuePtr)) { @@ -14932,7 +14918,7 @@ BfTypedValue BfModule::ReferenceStaticField(BfFieldInstance* fieldInstance) } } else - { + { StringT<512> staticVarName; BfMangler::Mangle(staticVarName, mCompiler->GetMangleKind(), fieldInstance); @@ -14943,7 +14929,7 @@ BfTypedValue BfModule::ReferenceStaticField(BfFieldInstance* fieldInstance) } if (mIsComptimeModule) - { + { mCompiler->mCeMachine->QueueStaticField(fieldInstance, staticVarName); } @@ -14964,13 +14950,13 @@ BfTypedValue BfModule::ReferenceStaticField(BfFieldInstance* fieldInstance) BfIRValue(), staticVarName, IsThreadLocal(fieldInstance)); - + BF_ASSERT(globalValue); mStaticFieldRefs[fieldInstance] = globalValue; - + BfLogSysM("Mod:%p Type:%p ReferenceStaticField %p -> %p\n", this, fieldInstance->mOwner, fieldInstance, globalValue); } - } + } auto type = fieldInstance->GetResolvedType(); if (type->IsValuelessType()) @@ -14990,17 +14976,17 @@ BfFieldInstance* BfModule::GetFieldInstance(BfTypeInstance* typeInst, int fieldI Fail(StrFormat("Invalid field data in type '%s'", TypeToString(typeInst).c_str())); return 0; } - return &typeInst->mFieldInstances[fieldIdx]; + return &typeInst->mFieldInstances[fieldIdx]; } void BfModule::MarkUsingThis() { auto useMethodState = mCurMethodState; - while ((useMethodState != NULL) && (useMethodState->mClosureState != NULL) && (useMethodState->mClosureState->mCapturing)) + while ((useMethodState != NULL) && (useMethodState->mClosureState != NULL) && (useMethodState->mClosureState->mCapturing)) { useMethodState = useMethodState->mPrevMethodState; } - + if ((useMethodState != NULL) && (!useMethodState->mLocals.IsEmpty())) { auto localVar = useMethodState->mLocals[0]; @@ -15010,7 +14996,7 @@ void BfModule::MarkUsingThis() } BfTypedValue BfModule::GetThis(bool markUsing) -{ +{ if ((mIsComptimeModule) && (mCompiler->mCeMachine->mDebugger != NULL) && (mCompiler->mCeMachine->mDebugger->mCurDbgState != NULL)) { if (mCompiler->mCeMachine->mDebugger->mCurDbgState->mExplicitThis) @@ -15023,7 +15009,7 @@ BfTypedValue BfModule::GetThis(bool markUsing) for (auto& dbgVar : activeFrame->mFunction->mDbgInfo->mVariables) { if (dbgVar.mName == "this") - return BfTypedValue(mBfIRBuilder->CreateConstAggCE(mBfIRBuilder->MapType(dbgVar.mType), activeFrame->mFrameAddr + dbgVar.mValue.mFrameOfs), dbgVar.mType, + return BfTypedValue(mBfIRBuilder->CreateConstAggCE(mBfIRBuilder->MapType(dbgVar.mType), activeFrame->mFrameAddr + dbgVar.mValue.mFrameOfs), dbgVar.mType, dbgVar.mIsConst ? BfTypedValueKind_ReadOnlyAddr : BfTypedValueKind_Addr); } } @@ -15032,10 +15018,10 @@ BfTypedValue BfModule::GetThis(bool markUsing) } auto useMethodState = mCurMethodState; - while ((useMethodState != NULL) && (useMethodState->mClosureState != NULL) && (useMethodState->mClosureState->mCapturing)) + while ((useMethodState != NULL) && (useMethodState->mClosureState != NULL) && (useMethodState->mClosureState->mCapturing)) { useMethodState = useMethodState->mPrevMethodState; - } + } if (useMethodState != NULL) { @@ -15043,8 +15029,8 @@ BfTypedValue BfModule::GetThis(bool markUsing) if (useMethodState->mTempKind == BfMethodState::TempKind_NonStatic) { auto thisType = mCurTypeInstance; - if (thisType->IsValueType()) - return BfTypedValue(mBfIRBuilder->CreateConstNull(mBfIRBuilder->MapTypeInstPtr(thisType)), thisType, BfTypedValueKind_ThisAddr); + if (thisType->IsValueType()) + return BfTypedValue(mBfIRBuilder->CreateConstNull(mBfIRBuilder->MapTypeInstPtr(thisType)), thisType, BfTypedValueKind_ThisAddr); else return BfTypedValue(mBfIRBuilder->CreateConstNull(mBfIRBuilder->MapTypeInst(thisType)), thisType, BfTypedValueKind_ThisValue); } @@ -15054,7 +15040,7 @@ BfTypedValue BfModule::GetThis(bool markUsing) } } else - { + { //TODO: Do we allow useMethodState to be NULL anymore? return BfTypedValue(); } @@ -15097,7 +15083,7 @@ BfTypedValue BfModule::GetThis(bool markUsing) return BfTypedValue(); } - + if (useMethodState->mLocals.IsEmpty()) { // This can happen in rare non-capture cases, such as when we need to do a const expression resolve for a sized-array return type on a local method @@ -15111,7 +15097,7 @@ BfTypedValue BfModule::GetThis(bool markUsing) bool preferValue = !IsTargetingBeefBackend(); if (!thisLocal->mAddr) preferValue = true; - + bool usedVal = false; BfIRValue thisValue; if ((preferValue) && (!thisLocal->mIsLowered)) @@ -15147,10 +15133,10 @@ BfTypedValue BfModule::GetThis(bool markUsing) auto refType = (BfRefType*)field.mResolvedType; auto underlyingType = refType->GetUnderlyingType(); result = BfTypedValue(mBfIRBuilder->CreateLoad(result.mValue), underlyingType, true); - } + } if (field.mResolvedType->IsObject()) { - result = LoadValue(result); + result = LoadValue(result); result.mKind = BfTypedValueKind_ThisValue; } else @@ -15176,20 +15162,20 @@ BfTypedValue BfModule::GetThis(bool markUsing) return BfTypedValue(GetDefaultValue(thisType), thisType, BfTypedValueKind_ThisValue); } } - + if (mCurMethodInstance == NULL) return BfTypedValue(); - auto localDef = useMethodState->mLocals[0]; - auto curMethodOwner = mCurMethodInstance->mMethodInstanceGroup->mOwner; + auto localDef = useMethodState->mLocals[0]; + auto curMethodOwner = mCurMethodInstance->mMethodInstanceGroup->mOwner; if ((curMethodOwner->IsStruct()) || (curMethodOwner->IsTypedPrimitive())) - { + { if ((localDef->mResolvedType->IsTypedPrimitive()) && (!mCurMethodInstance->mMethodDef->mIsMutating)) { return BfTypedValue(thisValue, useMethodState->mLocals[0]->mResolvedType, BfTypedValueKind_ReadOnlyThisValue); } if (localDef->mIsSplat) - { + { return BfTypedValue(thisValue, useMethodState->mLocals[0]->mResolvedType, BfTypedValueKind_ThisSplatHead); } return BfTypedValue(thisValue, useMethodState->mLocals[0]->mResolvedType, localDef->mIsReadOnly ? BfTypedValueKind_ReadOnlyThisAddr : BfTypedValueKind_ThisAddr); @@ -15208,7 +15194,7 @@ BfLocalVariable* BfModule::GetThisVariable() } bool BfModule::IsInGeneric() -{ +{ return ((mCurMethodInstance != NULL) && (mCurMethodInstance->GetNumGenericArguments() != 0)) || (mCurTypeInstance->IsGenericTypeInstance()); } @@ -15217,13 +15203,13 @@ bool BfModule::InDefinitionSection() if (mCurTypeInstance != NULL) { if (mCurTypeInstance->IsUnspecializedTypeVariation()) - return false; + return false; } return !IsInSpecializedSection(); } bool BfModule::IsInSpecializedGeneric() -{ +{ if ((mCurTypeInstance != NULL) && (mCurTypeInstance->IsSpecializedType())) return true; if ((mCurMethodInstance == NULL) || (mCurMethodInstance->mIsUnspecialized)) @@ -15233,7 +15219,7 @@ bool BfModule::IsInSpecializedGeneric() bool BfModule::IsInSpecializedSection() { - return IsInSpecializedGeneric() || + return IsInSpecializedGeneric() || ((mCurMethodState != NULL) && (mCurMethodState->mMixinState != NULL)); } @@ -15248,12 +15234,11 @@ bool BfModule::IsInUnspecializedGeneric() ////////////////////////////////////////////////////////////////////////// - BfIRValue BfModule::AllocLocalVariable(BfType* type, const StringImpl& name, bool doLifetimeEnd) { //if ((type->IsValuelessType()) || (type->IsMethodRef())) if (type->IsValuelessType()) - return mBfIRBuilder->GetFakeVal(); + return mBfIRBuilder->GetFakeVal(); auto allocaInst = CreateAlloca(type, doLifetimeEnd, name.c_str()); if ((!doLifetimeEnd) && (WantsLifetimes())) @@ -15268,12 +15253,12 @@ BfIRValue BfModule::AllocLocalVariable(BfType* type, const StringImpl& name, boo initLocalVariables = typeOptions->Apply(initLocalVariables, BfOptionFlags_InitLocalVariables); // Local variable inits are implicitly handled in the Beef Backend if ((initLocalVariables) && (!IsTargetingBeefBackend())) - { + { auto prevBlock = mBfIRBuilder->GetInsertBlock(); mBfIRBuilder->SetInsertPoint(mCurMethodState->mIRInitBlock); auto storeInst = mBfIRBuilder->CreateAlignedStore(GetDefaultValue(type), allocaInst, type->mAlign); - mBfIRBuilder->ClearDebugLocation(storeInst); - mBfIRBuilder->SetInsertPoint(prevBlock); + mBfIRBuilder->ClearDebugLocation(storeInst); + mBfIRBuilder->SetInsertPoint(prevBlock); } return allocaInst; } @@ -15317,7 +15302,6 @@ void BfModule::DoLocalVariableDebugInfo(BfLocalVariable* localVarDef, bool doAli if (localVarDef->mResolvedType->IsValuelessType()) { - } else { @@ -15366,7 +15350,7 @@ void BfModule::DoLocalVariableDebugInfo(BfLocalVariable* localVarDef, bool doAli // { // diValue = mBfIRBuilder->CreateAliasValue(constMem); // didConstToMem = true; -// +// // diType = mBfIRBuilder->DbgCreateReferenceType(diType); // } //else @@ -15414,7 +15398,7 @@ void BfModule::DoLocalVariableDebugInfo(BfLocalVariable* localVarDef, bool doAli if (mBfIRBuilder->HasDebugLocation()) { if ((isConstant) && (!didConstToMem)) - { + { BfTypedValue result(localVarDef->mConstValue, localVarDef->mResolvedType); FixValueActualization(result); localVarDef->mDbgDeclareInst = mBfIRBuilder->DbgInsertValueIntrinsic(result.mValue, diVariable); @@ -15430,7 +15414,7 @@ void BfModule::DoLocalVariableDebugInfo(BfLocalVariable* localVarDef, bool doAli if (isByAddr) localVarDef->mDbgDeclareInst = mBfIRBuilder->DbgInsertDeclare(diValue, diVariable, declareBefore); else if (diValue) - { + { localVarDef->mDbgDeclareInst = mBfIRBuilder->DbgInsertValueIntrinsic(diValue, diVariable); } else if (mCompiler->mOptions.mToolsetType != BfToolsetType_GNU) // DWARF chokes on this: @@ -15443,10 +15427,10 @@ void BfModule::DoLocalVariableDebugInfo(BfLocalVariable* localVarDef, bool doAli } BfLocalVariable* BfModule::AddLocalVariableDef(BfLocalVariable* localVarDef, bool addDebugInfo, bool doAliasValue, BfIRValue declareBefore, BfIRInitType initType) -{ +{ if ((localVarDef->mValue) && (!localVarDef->mAddr) && (IsTargetingBeefBackend()) && (!localVarDef->mResolvedType->IsValuelessType())) { - if ((!localVarDef->mValue.IsConst()) && + if ((!localVarDef->mValue.IsConst()) && (!localVarDef->mValue.IsArg()) && (!localVarDef->mValue.IsFake())) { mBfIRBuilder->CreateValueScopeRetain(localVarDef->mValue); @@ -15456,10 +15440,10 @@ BfLocalVariable* BfModule::AddLocalVariableDef(BfLocalVariable* localVarDef, boo if (addDebugInfo) DoLocalVariableDebugInfo(localVarDef, doAliasValue, declareBefore, initType); - + localVarDef->mDeclBlock = mBfIRBuilder->GetInsertBlock(); DoAddLocalVariable(localVarDef); - + auto rootMethodState = mCurMethodState->GetRootMethodState(); if (localVarDef->mLocalVarId == -1) @@ -15473,18 +15457,18 @@ BfLocalVariable* BfModule::AddLocalVariableDef(BfLocalVariable* localVarDef, boo { if (auto autoCtorDecl = BfNodeDynCast(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); + 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)) mCompiler->mResolvePassData->HandleLocalReference(localVarDef->mNameNode, rootMethodState->mMethodInstance->GetOwner()->mTypeDef, rootMethodState->mMethodInstance->mMethodDef, localVarDef->mLocalVarId); } - + return localVarDef; } @@ -15500,7 +15484,7 @@ void BfModule::CreateDIRetVal() }*/ if ((mCurMethodState->mRetVal) || (mCurMethodState->mRetValAddr)) - { + { BfType* dbgType = mCurMethodInstance->mReturnType; BfIRValue dbgValue = mCurMethodState->mRetVal.mValue; if ((!mIsComptimeModule) && (mCurMethodInstance->GetStructRetIdx() != -1)) @@ -15517,7 +15501,7 @@ void BfModule::CreateDIRetVal() mCurMethodState->mDIRetVal = mBfIRBuilder->DbgCreateAutoVariable(mCurMethodState->mCurScope->mDIScope, "@return", mCurFilePosition.mFileInstance->mDIFile, mCurFilePosition.mCurLine, mBfIRBuilder->DbgGetType(dbgType)); auto declareCall = mBfIRBuilder->DbgInsertDeclare(dbgValue, mCurMethodState->mDIRetVal); - } + } } BfTypedValue BfModule::CreateTuple(const Array& values, const Array& fieldNames) @@ -15525,7 +15509,7 @@ BfTypedValue BfModule::CreateTuple(const Array& values, const Arra BfTypeVector fieldTypes; for (auto arg : values) fieldTypes.Add(arg.mType); - + auto tupleType = CreateTupleType(fieldTypes, fieldNames); auto tupleTypedValue = BfTypedValue(CreateAlloca(tupleType), tupleType, true); @@ -15544,14 +15528,14 @@ BfTypedValue BfModule::CreateTuple(const Array& values, const Arra } void BfModule::CheckVariableDef(BfLocalVariable* variableDef) -{ +{ if (variableDef->mName.IsEmpty()) return; BfLocalVarEntry* localVarEntryPtr = NULL; if ((mCurMethodState != NULL) && (mCurMethodState->mLocalVarSet.TryGet(BfLocalVarEntry(variableDef), &localVarEntryPtr))) { - auto checkLocal = localVarEntryPtr->mLocalVar; + auto checkLocal = localVarEntryPtr->mLocalVar; if ((checkLocal->mLocalVarIdx >= mCurMethodState->GetLocalStartIdx()) && (!checkLocal->mIsShadow)) { BfError* error; @@ -15571,7 +15555,7 @@ void BfModule::CheckVariableDef(BfLocalVariable* variableDef) if ((checkLocal->mNameNode != NULL) && (error != NULL)) mCompiler->mPassInstance->MoreInfo("Previous declaration", checkLocal->mNameNode); return; - } + } } } @@ -15592,14 +15576,14 @@ BfScopeData* BfModule::FindScope(BfAstNode* scopeName, BfMixinState* fromMixinSt return &mCurMethodState->mHeadScope; } else if (tokenNode->GetToken() == BfToken_Mixin) - { + { if (fromMixinState == NULL) { if (mCurMethodInstance->mMethodDef->mMethodType != BfMethodType_Mixin) Fail("'mixin' scope specifier can only be used within a mixin declaration", scopeName); return mCurMethodState->mCurScope; } - + fromMixinState->mUsedInvocationScope = true; return fromMixinState->mTargetScope; } @@ -15639,7 +15623,7 @@ BfScopeData* BfModule::FindScope(BfAstNode* scopeName, BfMixinState* fromMixinSt { return FindScope(scopeNode->mTargetNode, allowAcrossDeferredBlock); } - + return mCurMethodState->mCurScope; } @@ -15689,7 +15673,7 @@ void BfModule::ClearLifetimeEnds() bool BfModule::WantsDebugInfo() { - if ((mCurMethodInstance != NULL) && + if ((mCurMethodInstance != NULL) && ((mCurMethodInstance->mIsUnspecialized) || (mCurMethodInstance->mMethodDef->mMethodType == BfMethodType_Mixin))) return false; @@ -15747,7 +15731,7 @@ BfReflectKind BfModule::GetUserReflectKind(BfTypeInstance* attrType) } BfReflectKind BfModule::GetReflectKind(BfReflectKind reflectKind, BfTypeInstance* typeInstance) -{ +{ auto checkTypeInstance = typeInstance; while (checkTypeInstance != NULL) { @@ -15790,7 +15774,7 @@ BfReflectKind BfModule::GetReflectKind(BfReflectKind reflectKind, BfTypeInstance auto iface = ifaceEntry.mInterfaceType; auto customAttr = iface->mCustomAttributes->Get(mCompiler->mReflectAttributeTypeDef); if (customAttr != NULL) - { + { for (auto& prop : customAttr->mSetProperties) { auto propDef = prop.mPropertyRef.mTypeInstance->mTypeDef->mProperties[prop.mPropertyRef.mPropIdx]; @@ -15825,7 +15809,7 @@ bool BfModule::HasDeferredScopeCalls(BfScopeData* scope) checkScope = checkScope->mPrevScope; } - return false; + return false; } void BfModule::EmitDeferredScopeCalls(bool useSrcPositions, BfScopeData* scopeData, BfIRBlock doneBlock) @@ -15862,7 +15846,7 @@ void BfModule::EmitDeferredScopeCalls(bool useSrcPositions, BfScopeData* scopeDa } // Why did we want to do SetIllegalSrcPos here? - // Don't we always want to step onto these instances? + // Don't we always want to step onto these instances? // Find a case where we don't and perhaps only do it there. // The downside was that 'EmitEnsureInstructionAt' on the end of block statements causes // a (seemingly) unneeded NOP when we do SetIllegalSrcPos @@ -15900,15 +15884,15 @@ void BfModule::EmitDeferredScopeCalls(bool useSrcPositions, BfScopeData* scopeDa while (checkScope != NULL) { if (checkScope->mCloseNode != NULL) - deferCloseNode = checkScope->mCloseNode; - + deferCloseNode = checkScope->mCloseNode; + if (doneBlock) { // Try to find a match where we've already emitted these calls and then jumped to the correct block for (auto& checkHandler : checkScope->mDeferredHandlers) { if (checkHandler.mDoneBlock == doneBlock) - { + { scopeJumpBlock = checkScope; mBfIRBuilder->CreateBr(checkHandler.mHandlerBlock); mBfIRBuilder->ClearDebugLocation_Last(); @@ -15922,16 +15906,16 @@ void BfModule::EmitDeferredScopeCalls(bool useSrcPositions, BfScopeData* scopeDa } bool hasWork = (checkScope->mSavedStack) || (checkScope->mDeferredCallEntries.mHead != NULL); - + if (checkScope != scopeData) // Only emit a block for deferred lifetimes if we're going back beyond this entry hasWork |= (!deferredLifetimeEnds.IsEmpty()); if (hasWork) { SetAndRestoreValue prevScope(mCurMethodState->mCurScope, checkScope); - + if (deferCloseNode != NULL) - { + { UpdateSrcPos(deferCloseNode); } @@ -15940,9 +15924,9 @@ void BfModule::EmitDeferredScopeCalls(bool useSrcPositions, BfScopeData* scopeDa if (doneBlock) { - bool crossingMixin = mCurMethodState->mCurScope->mMixinDepth != checkScope->mMixinDepth; + bool crossingMixin = mCurMethodState->mCurScope->mMixinDepth != checkScope->mMixinDepth; - String blockName = "deferredCalls"; + String blockName = "deferredCalls"; //blockName += StrFormat("_%d", mBfIRBuilder->mBlockCount); BfDeferredHandler deferredHandler; @@ -15963,32 +15947,32 @@ void BfModule::EmitDeferredScopeCalls(bool useSrcPositions, BfScopeData* scopeDa mBfIRBuilder->AddBlock(deferredHandler.mHandlerBlock); mBfIRBuilder->SetInsertPoint(deferredHandler.mHandlerBlock); } - + deferredHandler.mDoneBlock = doneBlock; - + if (!mBfIRBuilder->mIgnoreWrites) checkScope->mDeferredHandlers.push_back(deferredHandler); - + if (checkScope == &mCurMethodState->mHeadScope) { if (!mCurMethodState->mDIRetVal) - { - // Weird case- if we have a return from a mixin, we need the DbgLoc to be for the mixin but we need the DIRetVal to + { + // Weird case- if we have a return from a mixin, we need the DbgLoc to be for the mixin but we need the DIRetVal to // be scoped to the physical method - + /*if (deferCloseNode != NULL) - { - UpdateSrcPos(deferCloseNode); + { + UpdateSrcPos(deferCloseNode); }*/ CreateDIRetVal(); - } + } } if (checkScope != mCurMethodState->mTailScope) { if (deferredHandler.mHandlerBlock.IsFake()) { - BF_ASSERT(mBfIRBuilder->mIgnoreWrites); + BF_ASSERT(mBfIRBuilder->mIgnoreWrites); } if (!mBfIRBuilder->mIgnoreWrites) @@ -16007,8 +15991,8 @@ void BfModule::EmitDeferredScopeCalls(bool useSrcPositions, BfScopeData* scopeDa SetAndRestoreValue prevMixinState(mCurMethodState->mMixinState, checkScope->mMixinState); if (deferCloseNode != NULL) - { - UpdateSrcPos(deferCloseNode); + { + UpdateSrcPos(deferCloseNode); } if (wantsNop) EmitEnsureInstructionAt(); @@ -16021,7 +16005,7 @@ void BfModule::EmitDeferredScopeCalls(bool useSrcPositions, BfScopeData* scopeDa { // Already handled, can happen if we defer again within the block deferredCallEntry = deferredCallEntry->mNext; - continue; + continue; } auto prevHead = checkScope->mDeferredCallEntries.mHead; @@ -16043,7 +16027,7 @@ void BfModule::EmitDeferredScopeCalls(bool useSrcPositions, BfScopeData* scopeDa if (checkScope->mSavedStack) { - checkScope->mSavedStackUses.Add(mBfIRBuilder->CreateStackRestore(checkScope->mSavedStack)); + checkScope->mSavedStackUses.Add(mBfIRBuilder->CreateStackRestore(checkScope->mSavedStack)); if (mCurMethodState->mDynStackRevIdx) { @@ -16056,7 +16040,7 @@ void BfModule::EmitDeferredScopeCalls(bool useSrcPositions, BfScopeData* scopeDa if (!checkScope->mIsScopeHead) { - // We manually emit function-level lifetime ends after the 'ret' in ProcessMethod + // We manually emit function-level lifetime ends after the 'ret' in ProcessMethod if (!IsTargetingBeefBackend()) { for (auto lifetimeEnd : checkScope->mDeferredLifetimeEnds) @@ -16096,16 +16080,16 @@ void BfModule::EmitDeferredScopeCalls(bool useSrcPositions, BfScopeData* scopeDa BfScopeData* checkScope = mCurMethodState->mCurScope; while (checkScope != NULL) - { + { if (checkScope == scopeJumpBlock) break; - if (!checkScope->mIsScopeHead) + if (!checkScope->mIsScopeHead) { for (auto lifetimeEnd : checkScope->mDeferredLifetimeEnds) { if (needsEnsureInst) - { + { needsEnsureInst = false; } @@ -16121,7 +16105,7 @@ void BfModule::EmitDeferredScopeCalls(bool useSrcPositions, BfScopeData* scopeDa } void BfModule::MarkScopeLeft(BfScopeData* scopeData, bool isNoReturn) -{ +{ if ((mCurMethodState->mDeferredLocalAssignData != NULL) && (!isNoReturn)) { auto deferredLocalAssignData = mCurMethodState->mDeferredLocalAssignData; @@ -16133,13 +16117,13 @@ void BfModule::MarkScopeLeft(BfScopeData* scopeData, bool isNoReturn) if ((deferredLocalAssignData->mScopeData != NULL) && (deferredLocalAssignData->mScopeData->mScopeDepth == scopeData->mScopeDepth)) deferredLocalAssignData->mIsUnconditional = false; deferredLocalAssignData = deferredLocalAssignData->mChainedAssignData; - } + } } - + // When we leave a scope, mark those as assigned for deferred assignment purposes for (int localIdx = scopeData->mLocalVarStart; localIdx < (int)mCurMethodState->mLocals.size(); localIdx++) { - auto localDef = mCurMethodState->mLocals[localIdx]; + auto localDef = mCurMethodState->mLocals[localIdx]; if (localDef->mAssignedKind == BfLocalVarAssignKind_None) { bool hadAssignment = false; @@ -16147,7 +16131,7 @@ void BfModule::MarkScopeLeft(BfScopeData* scopeData, bool isNoReturn) { for (auto& entry : mCurMethodState->mDeferredLocalAssignData->mAssignedLocals) if (entry.mLocalVar == localDef) - hadAssignment = true; + hadAssignment = true; } if (!hadAssignment) { @@ -16168,7 +16152,7 @@ void BfModule::CreateReturn(BfIRValue val) mBfIRBuilder->CreateStore(val, mBfIRBuilder->GetArgument(mCurMethodInstance->GetStructRetIdx())); mBfIRBuilder->CreateRetVoid(); return; - } + } if (mCurMethodInstance->mReturnType->IsVar()) return; @@ -16178,7 +16162,7 @@ void BfModule::CreateReturn(BfIRValue val) mBfIRBuilder->CreateRetVoid(); return; } - + if (mCurMethodInstance->mReturnType->IsStruct()) { BfTypeCode loweredReturnType = BfTypeCode_None; @@ -16197,11 +16181,11 @@ void BfModule::CreateReturn(BfIRValue val) auto loadedReturnValue = mBfIRBuilder->CreateLoad(ptrReturnValue); mBfIRBuilder->CreateRet(loadedReturnValue); return; - } + } } - + BF_ASSERT(val); - mBfIRBuilder->CreateRet(val); + mBfIRBuilder->CreateRet(val); } void BfModule::EmitReturn(const BfTypedValue& val) @@ -16255,7 +16239,7 @@ void BfModule::EmitDefaultReturn() return; if (mCurMethodState->mIRExitBlock) - { + { EmitDeferredScopeCalls(true, NULL, mCurMethodState->mIRExitBlock); } else @@ -16275,7 +16259,7 @@ void BfModule::EmitDefaultReturn() } void BfModule::AssertErrorState() -{ +{ if (mIgnoreErrors) return; if (mHadBuildError) @@ -16310,11 +16294,11 @@ void BfModule::AssertErrorState() } if (mCurMethodInstance != NULL) { - if ((mCurMethodInstance->mMethodDef->mDeclaringType != NULL) && - (mCurMethodInstance->mMethodDef->mDeclaringType->mSource != NULL) && + if ((mCurMethodInstance->mMethodDef->mDeclaringType != NULL) && + (mCurMethodInstance->mMethodDef->mDeclaringType->mSource != NULL) && (mCurMethodInstance->mMethodDef->mDeclaringType->mSource->mParsingFailed)) return; - if ((mCurMethodState != NULL) && (mCurMethodState->mMixinState != NULL) && + if ((mCurMethodState != NULL) && (mCurMethodState->mMixinState != NULL) && (mCurMethodState->mMixinState->mMixinMethodInstance->mMethodDef->mDeclaringType->mSource != NULL) && (mCurMethodState->mMixinState->mMixinMethodInstance->mMethodDef->mDeclaringType->mSource->mParsingFailed)) return; @@ -16360,7 +16344,7 @@ void BfModule::CreateDelegateInvokeMethod() SizedArray staticParamTypes; SizedArray staticFuncArgs; SizedArray memberFuncArgs; - + auto multicastDelegateType = typeInstance->mBaseType; if (multicastDelegateType->mFieldInstances.size() != 2) { @@ -16370,10 +16354,10 @@ void BfModule::CreateDelegateInvokeMethod() auto multicastDelegate = mBfIRBuilder->CreateBitCast(mCurMethodState->mLocals[0]->mValue, mBfIRBuilder->MapType(multicastDelegateType)); auto fieldPtr = mBfIRBuilder->CreateInBoundsGEP(multicastDelegate, 0, 2); // Load 'delegate.mTarget' - auto fieldVal = mBfIRBuilder->CreateAlignedLoad(fieldPtr, mSystem->mPtrSize); - + auto fieldVal = mBfIRBuilder->CreateAlignedLoad(fieldPtr, mSystem->mPtrSize); + BfExprEvaluator exprEvaluator(this); - + SizedArray origParamTypes; BfIRType origReturnType; BfIRType staticReturnType; @@ -16381,14 +16365,14 @@ void BfModule::CreateDelegateInvokeMethod() if (mCurMethodInstance->mReturnType->IsValueType()) mBfIRBuilder->PopulateType(mCurMethodInstance->mReturnType, BfIRPopulateType_Full); - + if ((mIsComptimeModule) || (mCurMethodInstance->GetStructRetIdx() != 0)) memberFuncArgs.push_back(BfIRValue()); // Push 'target' int thisIdx = 0; if ((!mIsComptimeModule) && (mCurMethodInstance->GetStructRetIdx() != -1)) - { - thisIdx = mCurMethodInstance->GetStructRetIdx() ^ 1; + { + thisIdx = mCurMethodInstance->GetStructRetIdx() ^ 1; memberFuncArgs.push_back(mBfIRBuilder->GetArgument(mCurMethodInstance->GetStructRetIdx())); } @@ -16399,12 +16383,12 @@ void BfModule::CreateDelegateInvokeMethod() memberFuncArgs.push_back(BfIRValue()); // Push 'target' mCurMethodInstance->GetIRFunctionInfo(this, staticReturnType, staticParamTypes, true); - + for (int i = 1; i < (int)mCurMethodState->mLocals.size(); i++) { BfTypedValue localVal = exprEvaluator.LoadLocal(mCurMethodState->mLocals[i], true); exprEvaluator.PushArg(localVal, staticFuncArgs); - exprEvaluator.PushArg(localVal, memberFuncArgs); + exprEvaluator.PushArg(localVal, memberFuncArgs); } auto staticFunc = mBfIRBuilder->CreateFunctionType(staticReturnType, staticParamTypes, false); @@ -16412,11 +16396,11 @@ void BfModule::CreateDelegateInvokeMethod() auto staticFuncPtrPtr = mBfIRBuilder->GetPointerTo(staticFuncPtr); auto trueBB = mBfIRBuilder->CreateBlock("if.then", true); - auto falseBB = mBfIRBuilder->CreateBlock("if.else"); + auto falseBB = mBfIRBuilder->CreateBlock("if.else"); auto doneBB = mBfIRBuilder->CreateBlock("done"); auto checkTargetNull = mBfIRBuilder->CreateIsNotNull(fieldVal); - mBfIRBuilder->CreateCondBr(checkTargetNull, trueBB, falseBB); + mBfIRBuilder->CreateCondBr(checkTargetNull, trueBB, falseBB); BfIRValue nonStaticResult; BfIRValue staticResult; @@ -16424,10 +16408,10 @@ void BfModule::CreateDelegateInvokeMethod() auto callingConv = GetIRCallingConvention(mCurMethodInstance); /// Non-static invocation - { + { auto memberFuncPtr = mBfIRBuilder->GetPointerTo(mBfIRBuilder->MapMethod(mCurMethodInstance)); auto memberFuncPtrPtr = mBfIRBuilder->GetPointerTo(memberFuncPtr); - + mBfIRBuilder->SetInsertPoint(trueBB); memberFuncArgs[thisIdx] = mBfIRBuilder->CreateBitCast(fieldVal, mBfIRBuilder->MapType(mCurTypeInstance)); auto fieldPtr = mBfIRBuilder->CreateInBoundsGEP(multicastDelegate, 0, 1); // Load 'delegate.mFuncPtr' @@ -16450,7 +16434,7 @@ void BfModule::CreateDelegateInvokeMethod() mBfIRBuilder->SetInsertPoint(falseBB); auto fieldPtr = mBfIRBuilder->CreateInBoundsGEP(multicastDelegate, 0, 1); // Load 'delegate.mFuncPtr' auto funcPtrPtr = mBfIRBuilder->CreateBitCast(fieldPtr, staticFuncPtrPtr); - auto funcPtr = mBfIRBuilder->CreateAlignedLoad(funcPtrPtr, mSystem->mPtrSize); + auto funcPtr = mBfIRBuilder->CreateAlignedLoad(funcPtrPtr, mSystem->mPtrSize); staticResult = mBfIRBuilder->CreateCall(funcPtr, staticFuncArgs); if ((!mIsComptimeModule) && (mCurMethodInstance->GetStructRetIdx(true) != -1)) { @@ -16482,7 +16466,7 @@ void BfModule::CreateDelegateInvokeMethod() { // Do nothing } - else if ((mCurMethodInstance->mReturnType->IsValuelessType()) || + else if ((mCurMethodInstance->mReturnType->IsValuelessType()) || ((!mIsComptimeModule) && (mCurMethodInstance->GetStructRetIdx() != -1))) { mBfIRBuilder->CreateRetVoid(); @@ -16498,21 +16482,20 @@ void BfModule::CreateDelegateInvokeMethod() loweredIRReturnType = mBfIRBuilder->MapType(mCurMethodInstance->mReturnType); auto phi = mBfIRBuilder->CreatePhi(loweredIRReturnType, 2); mBfIRBuilder->AddPhiIncoming(phi, nonStaticResult, trueBB); - mBfIRBuilder->AddPhiIncoming(phi, staticResult, falseBB); + mBfIRBuilder->AddPhiIncoming(phi, staticResult, falseBB); mBfIRBuilder->CreateRet(phi); } } // "Interested" here means every method for a normal compile, and just the method the cursor is on for autocompletion bool BfModule::IsInterestedInMethod(BfTypeInstance* typeInstance, BfMethodDef* methodDef) -{ +{ auto typeDef = typeInstance->mTypeDef; - auto methodDeclaration = methodDef->mMethodDeclaration; - + auto methodDeclaration = methodDef->mMethodDeclaration; if (!mCompiler->mIsResolveOnly) return true; - + if (typeInstance->IsGenericTypeInstance()) { // We only really want to process the unspecialized type for autocompletion @@ -16523,12 +16506,12 @@ bool BfModule::IsInterestedInMethod(BfTypeInstance* typeInstance, BfMethodDef* m BfAstNode* checkNode = methodDeclaration; if (methodDeclaration == NULL) checkNode = methodDef->mBody; - + if ((!mCompiler->mResolvePassData->mParsers.IsEmpty()) && (typeDef->mTypeDeclaration->IsFromParser(mCompiler->mResolvePassData->mParsers[0]))) { if (mCompiler->mResolvePassData->mAutoComplete == NULL) - return true; - } + return true; + } return false; } @@ -16569,11 +16552,11 @@ BfTypedValue BfModule::TryConstCalcAppend(BfMethodInstance* methodInst, SizedArr { if (argIdx >= (int)args.size()) break; - auto paramType = methodInst->GetParamType(paramIdx); + auto paramType = methodInst->GetParamType(paramIdx); PopulateType(paramType); int argCount = 0; - if (!paramType->IsValuelessType()) - { + if (!paramType->IsValuelessType()) + { if ((!mIsComptimeModule) && (methodInst->GetParamIsSplat(paramIdx))) argCount = paramType->GetSplatCount(); else @@ -16601,9 +16584,9 @@ BfTypedValue BfModule::TryConstCalcAppend(BfMethodInstance* methodInst, SizedArr } paramIdx++; - argIdx += argCount; - } - + argIdx += argCount; + } + auto methodDef = methodInst->mMethodDef; auto methodDecl = methodDef->GetMethodDeclaration(); auto methodDeclBlock = BfNodeDynCast(methodDecl->mBody); @@ -16613,7 +16596,7 @@ BfTypedValue BfModule::TryConstCalcAppend(BfMethodInstance* methodInst, SizedArr BfTypedValue constValue; auto prevBlock = mBfIRBuilder->GetInsertBlock(); - + auto checkState = mCurMethodState->mConstResolveState; while (checkState != NULL) { @@ -16650,7 +16633,7 @@ BfTypedValue BfModule::TryConstCalcAppend(BfMethodInstance* methodInst, SizedArr auto paramType = methodInst->GetParamType(paramIdx); // Fix this after we allow structs to be consts //BF_ASSERT(!paramType->IsSplattable()); - + BfLocalVariable* localVar = new BfLocalVariable(); localVar->mName = methodInst->GetParamName(paramIdx); localVar->mResolvedType = paramType; @@ -16660,7 +16643,7 @@ BfTypedValue BfModule::TryConstCalcAppend(BfMethodInstance* methodInst, SizedArr argIdx++; } - AppendAllocVisitor appendAllocVisitor; + AppendAllocVisitor appendAllocVisitor; appendAllocVisitor.mConstAccum = GetDefaultTypedValue(GetPrimitiveType(BfTypeCode_IntPtr)); appendAllocVisitor.mIsFirstConstPass = isFirstRun; @@ -16672,10 +16655,10 @@ BfTypedValue BfModule::TryConstCalcAppend(BfMethodInstance* methodInst, SizedArr else appendAllocVisitor.mConstAccum = baseCtorAppendValue; } - + appendAllocVisitor.mModule = this; - - appendAllocVisitor.VisitChild(methodDecl->mBody); + + appendAllocVisitor.VisitChild(methodDecl->mBody); if (constResolveState.mFailed) appendAllocVisitor.mFailed = true; if (!appendAllocVisitor.mFailed) @@ -16699,16 +16682,16 @@ BfTypedValue BfModule::TryConstCalcAppend(BfMethodInstance* methodInst, SizedArr } } } - } + } mBfIRBuilder->SetInsertPoint(prevBlock); - if (!constValue) + if (!constValue) { // If we did a 'force' then some params may not have been const -- only clear mMayBeConst if we had // all-const args if (wasAllConst) - { + { methodInst->mMayBeConst = false; } } @@ -16720,10 +16703,10 @@ BfTypedValue BfModule::CallBaseCtorCalc(bool constOnly) { // Any errors should only be shown in the actual CTOR call SetAndRestoreValue prevIgnoreWrites(mIgnoreErrors, true); - + auto methodDef = mCurMethodInstance->mMethodDef; BF_ASSERT((methodDef->mMethodType == BfMethodType_Ctor) || (methodDef->mMethodType == BfMethodType_CtorCalcAppend)); - auto ctorDeclaration = (BfConstructorDeclaration*)methodDef->mMethodDeclaration; + auto ctorDeclaration = (BfConstructorDeclaration*)methodDef->mMethodDeclaration; BfCustomAttributes* customAttributes = NULL; defer(delete customAttributes); @@ -16753,17 +16736,16 @@ BfTypedValue BfModule::CallBaseCtorCalc(bool constOnly) BfType* targetThisType = targetType; BfTypedValue target(mBfIRBuilder->GetFakeVal(), targetThisType); - + BfExprEvaluator exprEvaluator(this); BfResolvedArgs argValues; if ((ctorDeclaration != NULL) && (ctorInvocation != NULL)) { argValues.Init(&ctorInvocation->mArguments); } - + // { - } BfFunctionBindResult bindResult; bindResult.mSkipThis = true; @@ -16774,7 +16756,7 @@ BfTypedValue BfModule::CallBaseCtorCalc(bool constOnly) SetAndRestoreValue prevBindResult(exprEvaluator.mFunctionBindResult, &bindResult); exprEvaluator.MatchConstructor(targetRefNode, NULL, target, targetType, argValues, true, true); } - + if (bindResult.mMethodInstance == NULL) { AssertErrorState(); @@ -16785,10 +16767,10 @@ BfTypedValue BfModule::CallBaseCtorCalc(bool constOnly) { return BfTypedValue(); } - + BF_ASSERT(bindResult.mIRArgs[0].IsFake()); bindResult.mIRArgs.RemoveAt(0); - auto calcAppendMethodModule = GetMethodInstanceAtIdx(bindResult.mMethodInstance->GetOwner(), bindResult.mMethodInstance->mMethodDef->mIdx + 1, BF_METHODNAME_CALCAPPEND); + auto calcAppendMethodModule = GetMethodInstanceAtIdx(bindResult.mMethodInstance->GetOwner(), bindResult.mMethodInstance->mMethodDef->mIdx + 1, BF_METHODNAME_CALCAPPEND); BfTypedValue appendSizeTypedValue = TryConstCalcAppend(calcAppendMethodModule.mMethodInstance, bindResult.mIRArgs, true); BF_ASSERT(calcAppendMethodModule.mMethodInstance->mAppendAllocAlign >= 0); mCurMethodInstance->mAppendAllocAlign = BF_MAX((int)mCurMethodInstance->mAppendAllocAlign, calcAppendMethodModule.mMethodInstance->mAppendAllocAlign); @@ -16797,7 +16779,7 @@ BfTypedValue BfModule::CallBaseCtorCalc(bool constOnly) if (appendSizeTypedValue) return appendSizeTypedValue; - + if (constOnly) return BfTypedValue(mBfIRBuilder->GetFakeVal(), GetPrimitiveType(BfTypeCode_IntPtr)); @@ -16819,15 +16801,14 @@ BfTypedValue BfModule::CallBaseCtorCalc(bool constOnly) bindResult.mSkipThis = true; bindResult.mWantsArgs = true; SetAndRestoreValue prevBindResult(exprEvaluator.mFunctionBindResult, &bindResult); - exprEvaluator.MatchConstructor(targetRefNode, NULL, target, targetType, argValues, true, true); + exprEvaluator.MatchConstructor(targetRefNode, NULL, target, targetType, argValues, true, true); BF_ASSERT(bindResult.mIRArgs[0].IsFake()); bindResult.mIRArgs.RemoveAt(0); calcAppendArgs = bindResult.mIRArgs; - } + } BF_ASSERT(calcAppendMethodModule.mFunc); appendSizeTypedValue = exprEvaluator.CreateCall(NULL, calcAppendMethodModule.mMethodInstance, calcAppendMethodModule.mFunc, false, calcAppendArgs); - BF_ASSERT(appendSizeTypedValue.mType == GetPrimitiveType(BfTypeCode_IntPtr)); return appendSizeTypedValue; } @@ -16840,45 +16821,45 @@ void BfModule::EmitCtorCalcAppend() auto methodDef = mCurMethodInstance->mMethodDef; auto methodDecl = methodDef->GetMethodDeclaration(); - + Array deferredNodeList; auto methodDeclBlock = BfNodeDynCast(methodDecl->mBody); if (methodDeclBlock == NULL) - return; - + return; + AppendAllocVisitor appendAllocVisitor; auto baseCalcAppend = CallBaseCtorCalc(false); if (baseCalcAppend) - { - mBfIRBuilder->CreateStore(baseCalcAppend.mValue, mCurMethodState->mRetVal.mValue); - } + { + mBfIRBuilder->CreateStore(baseCalcAppend.mValue, mCurMethodState->mRetVal.mValue); + } appendAllocVisitor.mModule = this; appendAllocVisitor.VisitChild(methodDecl->mBody); } void BfModule::CreateStaticCtor() -{ +{ auto typeDef = mCurTypeInstance->mTypeDef; auto methodDef = mCurMethodInstance->mMethodDef; - + BfIRBlock exitBB; if ((HasCompiledOutput()) && (!mCurMethodInstance->mIsUnspecialized) && (mCurMethodInstance->mChainType != BfMethodChainType_ChainMember)) { auto boolType = GetPrimitiveType(BfTypeCode_Boolean); - auto didStaticInitVarAddr = mBfIRBuilder->CreateGlobalVariable( + auto didStaticInitVarAddr = mBfIRBuilder->CreateGlobalVariable( mBfIRBuilder->MapType(boolType), false, BfIRLinkageType_Internal, GetDefaultValue(boolType), "didStaticInit"); - auto initBB = mBfIRBuilder->CreateBlock("init", true); + auto initBB = mBfIRBuilder->CreateBlock("init", true); mCurMethodState->mIRExitBlock = mBfIRBuilder->CreateBlock("exit", true); - + auto didStaticInitVar = mBfIRBuilder->CreateLoad(didStaticInitVarAddr); mBfIRBuilder->CreateCondBr(didStaticInitVar, mCurMethodState->mIRExitBlock, initBB); - + mBfIRBuilder->SetInsertPoint(initBB); mBfIRBuilder->CreateStore(GetConstValue(1, boolType), didStaticInitVarAddr); } @@ -16893,10 +16874,10 @@ void BfModule::CreateStaticCtor() { if (!mCompiler->mPassInstance->HasFailed()) Fail("Internal error: System.Internal doesn't contain LoadSharedLibrary method"); - } + } } - // Fill in initializer values + // Fill in initializer values if ((!mCompiler->mIsResolveOnly) || (mCompiler->mResolvePassData->mAutoComplete == NULL)) { for (auto fieldDef : typeDef->mFields) @@ -16906,7 +16887,7 @@ void BfModule::CreateStaticCtor() // For extensions, only handle these fields in the appropriate extension if ((fieldDef->mDeclaringType->mTypeDeclaration != methodDef->mDeclaringType->mTypeDeclaration)) continue; - + auto initializer = fieldDef->GetInitializer(); auto fieldInst = &mCurTypeInstance->mFieldInstances[fieldDef->mIdx]; if (!fieldInst->mFieldIncluded) @@ -16962,7 +16943,7 @@ void BfModule::CreateStaticCtor() exprFlags = (BfEvalExprFlags)(exprFlags | BfEvalExprFlags_AppendFieldInitializer); CreateValueFromExpression(fieldDef->GetInitializer(), wantType, exprFlags); - } + } } } } @@ -16970,11 +16951,11 @@ void BfModule::CreateStaticCtor() } if (mCurMethodInstance->mChainType == BfMethodChainType_ChainHead) - CallChainedMethods(mCurMethodInstance, false); + CallChainedMethods(mCurMethodInstance, false); } void BfModule::EmitDtorBody() -{ +{ if (!mCurMethodState->mIRExitBlock) mCurMethodState->mIRExitBlock = mBfIRBuilder->CreateBlock("exit", true); @@ -16988,14 +16969,14 @@ void BfModule::EmitDtorBody() auto funcPtrType = mBfIRBuilder->GetPointerTo(mBfIRBuilder->MapMethod(mCurMethodInstance)); auto dtorPtr = mBfIRBuilder->CreateBitCast(dtorThunk, funcPtrType); - + SizedArray args; args.push_back(thisVal.mValue); auto result = mBfIRBuilder->CreateCall(dtorPtr, args); mBfIRBuilder->SetCallCallingConv(result, BfIRCallingConv_CDecl); // Fall through to Object::~this call - + auto dtorFunc = GetMethodByName(mContext->mBfObjectType, "~this"); if (mIsComptimeModule) mCompiler->mCeMachine->QueueMethod(dtorFunc.mMethodInstance, dtorFunc.mFunc); @@ -17003,24 +16984,24 @@ void BfModule::EmitDtorBody() SizedArray vals = { basePtr }; result = mBfIRBuilder->CreateCall(dtorFunc.mFunc, vals); mBfIRBuilder->SetCallCallingConv(result, GetIRCallingConvention(dtorFunc.mMethodInstance)); - mBfIRBuilder->SetTailCall(result); + mBfIRBuilder->SetTailCall(result); - return; + return; } auto typeDef = mCurTypeInstance->mTypeDef; - auto methodDef = mCurMethodInstance->mMethodDef; - auto methodDeclaration = methodDef->GetMethodDeclaration(); + auto methodDef = mCurMethodInstance->mMethodDef; + auto methodDeclaration = methodDef->GetMethodDeclaration(); if (mCurMethodInstance->mChainType == BfMethodChainType_ChainHead) CallChainedMethods(mCurMethodInstance, true); if (auto bodyBlock = BfNodeDynCast(methodDef->mBody)) - { - VisitEmbeddedStatement(bodyBlock); + { + VisitEmbeddedStatement(bodyBlock); if (bodyBlock->mCloseBrace != NULL) { - UpdateSrcPos(bodyBlock->mCloseBrace); + UpdateSrcPos(bodyBlock->mCloseBrace); } } else @@ -17035,10 +17016,10 @@ void BfModule::EmitDtorBody() { Fail("Destructors cannot have expression bodies", methodDeclaration->mFatArrowToken, true); } - } + } if ((!mCompiler->mIsResolveOnly) || (mCompiler->mResolvePassData->mAutoComplete == NULL)) - { + { for (int fieldIdx = (int)mCurTypeInstance->mFieldInstances.size() - 1; fieldIdx >= 0; fieldIdx--) { auto fieldInst = &mCurTypeInstance->mFieldInstances[fieldIdx]; @@ -17047,7 +17028,7 @@ void BfModule::EmitDtorBody() BfFieldDeclaration* fieldDecl = NULL; if (fieldDef != NULL) fieldDecl = fieldDef->GetFieldDeclaration(); - + if ((fieldDef != NULL) && (fieldDef->mIsStatic == methodDef->mIsStatic) && (fieldDecl != NULL) && (fieldDecl->mFieldDtor != NULL)) { if (fieldDef->mDeclaringType != mCurMethodInstance->mMethodDef->mDeclaringType) @@ -17085,8 +17066,8 @@ void BfModule::EmitDtorBody() BfIRValue value; if (fieldDef->mIsStatic) - { - value = ReferenceStaticField(fieldInst).mValue; + { + value = ReferenceStaticField(fieldInst).mValue; } else { @@ -17098,25 +17079,25 @@ void BfModule::EmitDtorBody() else if (!mCurTypeInstance->IsValueType()) { auto thisValue = GetThis(); - value = mBfIRBuilder->CreateInBoundsGEP(thisValue.mValue, 0, fieldInst->mDataIdx); + value = mBfIRBuilder->CreateInBoundsGEP(thisValue.mValue, 0, fieldInst->mDataIdx); } else - { + { AssertErrorState(); value = mBfIRBuilder->CreateAlloca(mBfIRBuilder->MapType(fieldInst->mResolvedType)); } } BfIRValue staticVal; - + if (hasDbgInfo) { BfIRValue dbgShowValue = value; - + BfLocalVariable* localDef = new BfLocalVariable(); localDef->mName = "_"; localDef->mResolvedType = fieldInst->mResolvedType; - + if (fieldInst->IsAppendedObject()) { localDef->mValue = mBfIRBuilder->CreateBitCast(value, mBfIRBuilder->MapType(fieldInst->mResolvedType)); @@ -17137,9 +17118,9 @@ void BfModule::EmitDtorBody() localDef->mAddr = allocaInst; } } - + mBfIRBuilder->RestoreDebugLocation(); - + auto defLocalVar = AddLocalVariableDef(localDef, true); if (!fieldInst->IsAppendedObject()) @@ -17148,7 +17129,7 @@ void BfModule::EmitDtorBody() defLocalVar->mResolvedType = fieldInst->mResolvedType; defLocalVar->mAddr = value; } - } + } while (fieldDtor != NULL) { @@ -17161,7 +17142,7 @@ void BfModule::EmitDtorBody() } } - UpdateSrcPos(fieldDtor); + UpdateSrcPos(fieldDtor); VisitEmbeddedStatement(fieldDtor->mBody); fieldDtor = fieldDtor->mNextFieldDtor; } @@ -17201,7 +17182,7 @@ void BfModule::EmitDtorBody() { if (!CheckProtection(dtorMethodDef->mProtection, checkTypeInst->mTypeDef, allowProtected, allowPrivate)) { - auto error = Fail(StrFormat("'%s.~this()' is inaccessible due to its protection level", TypeToString(checkTypeInst).c_str()), refNode); // CS0122 + auto error = Fail(StrFormat("'%s.~this()' is inaccessible due to its protection level", TypeToString(checkTypeInst).c_str()), refNode); // CS0122 } } checkTypeInst = checkTypeInst->mBaseType; @@ -17251,7 +17232,7 @@ void BfModule::EmitDtorBody() UpdateSrcPos(typeDef->mTypeDeclaration->mNameNode); } - BfMethodDef* dtorMethodDef = checkBaseType->mTypeDef->GetMethodByName("~this"); + BfMethodDef* dtorMethodDef = checkBaseType->mTypeDef->GetMethodByName("~this"); if (dtorMethodDef != NULL) { auto dtorMethodInstance = GetMethodInstance(checkBaseType, dtorMethodDef, BfTypeVector()); @@ -17279,15 +17260,15 @@ void BfModule::EmitDtorBody() break; } checkBaseType = checkBaseType->mBaseType; - } + } } - EmitLifetimeEnds(&mCurMethodState->mHeadScope); + EmitLifetimeEnds(&mCurMethodState->mHeadScope); } else { - // The reason we can't just do the 'normal' path for this is that the BfTypeInstance here is NOT the - // autocomplete type instance, so FieldInstance initializer values contain expressions from the full + // The reason we can't just do the 'normal' path for this is that the BfTypeInstance here is NOT the + // autocomplete type instance, so FieldInstance initializer values contain expressions from the full // resolve pass, NOT the autocomplete expression for (auto tempTypeDef : mCompiler->mResolvePassData->mAutoCompleteTempTypes) { @@ -17297,7 +17278,7 @@ void BfModule::EmitDtorBody() { auto fieldDecl = fieldDef->GetFieldDeclaration(); - if ((fieldDef->mIsStatic == methodDef->mIsStatic) && (fieldDef->mFieldDeclaration != NULL) && + if ((fieldDef->mIsStatic == methodDef->mIsStatic) && (fieldDef->mFieldDeclaration != NULL) && (fieldDecl->mFieldDtor != NULL) && (mCompiler->mResolvePassData->mIsClassifying)) { BfType* fieldType = NULL; @@ -17307,15 +17288,15 @@ void BfModule::EmitDtorBody() auto curFieldInstance = &mCurTypeInstance->mFieldInstances[curFieldIdx]; auto curFieldDef = curFieldInstance->GetFieldDef(); if ((curFieldDef != NULL) && (fieldDef->mName == curFieldDef->mName)) - fieldType = curFieldInstance->GetResolvedType(); + fieldType = curFieldInstance->GetResolvedType(); } if (fieldType == NULL) fieldType = GetPrimitiveType(BfTypeCode_Var); - + auto fieldDtor = fieldDecl->mFieldDtor; BfScopeData scopeData; - mCurMethodState->AddScope(&scopeData); + mCurMethodState->AddScope(&scopeData); NewScopeState(); // This is just for autocomplete, it doesn't matter that mAddr is incorrect @@ -17323,7 +17304,7 @@ void BfModule::EmitDtorBody() { BfLocalVariable* localDef = new BfLocalVariable(); localDef->mName = "_"; - localDef->mResolvedType = fieldType; + localDef->mResolvedType = fieldType; localDef->mAddr = mBfIRBuilder->CreateAlloca(mBfIRBuilder->MapType(fieldType)); localDef->mAssignedKind = BfLocalVarAssignKind_Unconditional; AddLocalVariableDef(localDef); @@ -17337,13 +17318,13 @@ void BfModule::EmitDtorBody() sourceClassifier->VisitChild(fieldDtor); } - UpdateSrcPos(fieldDtor); + UpdateSrcPos(fieldDtor); VisitEmbeddedStatement(fieldDtor->mBody); fieldDtor = fieldDtor->mNextFieldDtor; } RestoreScopeState(); - } + } } } } @@ -17362,7 +17343,7 @@ BfIRValue BfModule::CreateDllImportGlobalVar(BfMethodInstance* methodInstance, b { if (customAttr.mType->mTypeDef->mFullName.ToString() == "System.ImportAttribute") { - foundDllImportAttr = true; + foundDllImportAttr = true; } } if (!foundDllImportAttr) @@ -17374,21 +17355,21 @@ BfIRValue BfModule::CreateDllImportGlobalVar(BfMethodInstance* methodInstance, b StringT<512> name = "bf_hs_preserve@"; BfMangler::Mangle(name, mCompiler->GetMangleKind(), methodInstance); name += "__imp"; - + BfIRType returnType; SizedArray paramTypes; methodInstance->GetIRFunctionInfo(this, returnType, paramTypes); - + BfIRFunctionType externFunctionType = mBfIRBuilder->CreateFunctionType(returnType, paramTypes, methodInstance->IsVarArgs()); auto ptrType = mBfIRBuilder->GetPointerTo(externFunctionType); BfIRValue initVal; if (define) { - if (methodInstance->GetImportCallKind() != BfImportCallKind_None) + if (methodInstance->GetImportCallKind() != BfImportCallKind_None) initVal = mBfIRBuilder->CreateConstNull(ptrType); } - + auto globalVar = mBfIRBuilder->CreateGlobalVariable(ptrType, false, BfIRLinkageType_External, initVal, name); if ((define) && (mBfIRBuilder->DbgHasInfo())) @@ -17413,7 +17394,7 @@ void BfModule::CreateDllImportMethod() bool allowTailCall = true; mBfIRBuilder->ClearDebugLocation(); - + bool isHotCompile = mCompiler->IsHotCompile(); // If we are hot swapping, we need to have this stub because we may need to call the LoadSharedLibraries on demand @@ -17455,7 +17436,7 @@ void BfModule::CreateDllImportMethod() if (HasCompiledOutput()) { BfDllImportEntry dllImportEntry; - dllImportEntry.mFuncVar = globalVar; + dllImportEntry.mFuncVar = globalVar; dllImportEntry.mMethodInstance = mCurMethodInstance; mDllImportEntries.push_back(dllImportEntry); } @@ -17476,7 +17457,7 @@ BfIRCallingConv BfModule::GetIRCallingConvention(BfMethodInstance* methodInstanc return BfIRCallingConv_StdCall; if (methodInstance->mCallingConvention == BfCallingConvention_Fastcall) return BfIRCallingConv_FastCall; - if (!methodDef->mIsStatic) + if (!methodDef->mIsStatic) { if (owner->mIsCRepr) return BfIRCallingConv_ThisCall; @@ -17490,20 +17471,20 @@ BfIRCallingConv BfModule::GetIRCallingConvention(BfMethodInstance* methodInstanc } void BfModule::SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func, bool isInlined) -{ +{ BfMethodDef* methodDef = NULL; if (methodInstance != NULL) methodDef = methodInstance->mMethodDef; if (!func) return; - + if (mCompiler->mOptions.mNoFramePointerElim) - mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_NoFramePointerElim); + mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_NoFramePointerElim); mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_NoUnwind); - if (mSystem->mPtrSize == 8) // We need unwind info for debugging + if (mSystem->mPtrSize == 8) // We need unwind info for debugging mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_UWTable); - + if (methodInstance == NULL) return; @@ -17519,17 +17500,17 @@ void BfModule::SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func auto callingConv = GetIRCallingConvention(methodInstance); if (callingConv != BfIRCallingConv_CDecl) mBfIRBuilder->SetFuncCallingConv(func, callingConv); - + if (isInlined) { - mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_AlwaysInline); + mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_AlwaysInline); } int argIdx = 0; int paramIdx = 0; - if ((methodInstance->HasThis()) && (!methodDef->mHasExplicitThis)) - paramIdx = -1; + if ((methodInstance->HasThis()) && (!methodDef->mHasExplicitThis)) + paramIdx = -1; int argCount = methodInstance->GetIRFunctionParamCount(this); @@ -17551,7 +17532,7 @@ void BfModule::SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func BfType* resolvedTypeRef2 = NULL; String paramName; bool isSplattable = false; - bool tryLowering = !mIsComptimeModule; + bool tryLowering = !mIsComptimeModule; if (isThis) { paramName = "this"; @@ -17584,7 +17565,7 @@ void BfModule::SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func else if (resolvedTypeRef->GetSplatCount() + argIdx <= mCompiler->mOptions.mMaxSplatRegs) isSplattable = true; } - } + } } if (tryLowering) @@ -17592,7 +17573,7 @@ void BfModule::SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func BfTypeCode loweredTypeCode = BfTypeCode_None; BfTypeCode loweredTypeCode2 = BfTypeCode_None; if (resolvedTypeRef->GetLoweredType(BfTypeUsage_Parameter, &loweredTypeCode, &loweredTypeCode2)) - { + { mBfIRBuilder->Func_SetParamName(func, argIdx + 1, paramName + "__1"); argIdx++; @@ -17604,7 +17585,7 @@ void BfModule::SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func paramIdx++; continue; - } + } } auto _SetupParam = [&](const StringImpl& paramName, BfType* resolvedTypeRef) @@ -17630,7 +17611,7 @@ void BfModule::SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func addDeref = resolvedTypeRef->mSize; } else if (methodInstance->WantsStructsAttribByVal(resolvedTypeRef)) - { + { mBfIRBuilder->PopulateType(resolvedTypeRef, BfIRPopulateType_Full); BF_ASSERT(resolvedTypeRef->mAlign > 0); mBfIRBuilder->Func_AddAttribute(func, argIdx + 1, BfIRAttribute_ByVal, mSystem->mPtrSize); @@ -17650,15 +17631,15 @@ void BfModule::SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func }; if (isSplattable) - { + { std::function checkTypeLambda = [&](BfType* checkType, const StringImpl& curName) - { + { if (checkType->IsStruct()) { auto checkTypeInstance = checkType->ToTypeInstance(); if (checkTypeInstance->mBaseType != NULL) checkTypeLambda(checkTypeInstance->mBaseType, curName); - + if (checkTypeInstance->mIsUnion) { BfType* unionInnerType = checkTypeInstance->GetUnionInnerType(); @@ -17697,7 +17678,7 @@ void BfModule::SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func checkTypeLambda(methodRefType->GetCaptureType(dataIdx), curName + "_" + methodRefMethodInst->GetParamName(methodRefParamIdx)); } else - { + { _SetupParam(curName + "_" + methodRefMethodInst->GetParamName(methodRefParamIdx), methodRefType->GetCaptureType(dataIdx)); } } @@ -17716,7 +17697,7 @@ void BfModule::SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func _SetupParam(paramName, resolvedTypeRef); if (resolvedTypeRef2 != NULL) _SetupParam(paramName, resolvedTypeRef2); - + paramIdx++; } } @@ -17781,7 +17762,7 @@ void BfModule::EmitCtorBody(bool& skipBody) // Prologue mBfIRBuilder->ClearDebugLocation(); - bool hadThisInitializer = false; + bool hadThisInitializer = false; if ((ctorDeclaration != NULL) && (ctorInvocation != NULL)) { auto targetToken = BfNodeDynCast(ctorInvocation->mTarget); @@ -17829,16 +17810,16 @@ void BfModule::EmitCtorBody(bool& skipBody) baseCtorNode = mContext->mBfObjectType->mTypeDef->mTypeDeclaration; bool calledCtorNoBody = false; - + if ((mCurTypeInstance->IsTypedPrimitive()) && (!mCurTypeInstance->IsValuelessType())) { // Zero out typed primitives in ctor mBfIRBuilder->CreateAlignedStore(GetDefaultValue(mCurTypeInstance->GetUnderlyingType()), mBfIRBuilder->GetArgument(0), mCurTypeInstance->mAlign); - } + } if ((!mCurTypeInstance->IsBoxed()) && (methodDef->mMethodType == BfMethodType_Ctor) && (!hadThisInitializer)) { - // Call the root type's default ctor (with no body) to initialize its fields and call the chained ctors + // Call the root type's default ctor (with no body) to initialize its fields and call the chained ctors if (mCurTypeInstance->mTypeDef->mHasCtorNoBody) { BfMethodDef* defaultCtor = NULL; @@ -17855,7 +17836,7 @@ void BfModule::EmitCtorBody(bool& skipBody) { UpdateSrcPos(mCurTypeInstance->mTypeDef->GetRefNode()); SetIllegalSrcPos(); - + auto moduleMethodInstance = GetMethodInstance(mCurTypeInstance, defaultCtor, BfTypeVector()); BfExprEvaluator exprEvaluator(this); @@ -17884,9 +17865,9 @@ void BfModule::EmitCtorBody(bool& skipBody) { // If we had a 'this' initializer, that other ctor will have initialized our fields - //auto - - if ((!mCompiler->mIsResolveOnly) || + //auto + + if ((!mCompiler->mIsResolveOnly) || (mCompiler->mResolvePassData->mAutoComplete == NULL) || (mCompiler->mResolvePassData->mAutoComplete->mResolveType == BfResolveType_ShowFileSymbolReferences)) { @@ -17897,7 +17878,7 @@ void BfModule::EmitCtorBody(bool& skipBody) bool hadInlineInitBlock = false; BfScopeData scopeData; scopeData.mInInitBlock = true; - + auto _CheckInitBlock = [&](BfAstNode* node) { if (!hadInlineInitBlock) @@ -17926,7 +17907,7 @@ void BfModule::EmitCtorBody(bool& skipBody) mCurMethodState->mCurScope->mDIInlinedAt = mBfIRBuilder->DbgGetCurrentLocation(); BF_ASSERT(mCurMethodState->mCurScope->mDIInlinedAt); // mCurMethodState->mCurScope->mDIInlinedAt may still be null ifwe don't have an explicit ctor - + String linkageName; if ((mIsComptimeModule) && (mCompiler->mCeMachine->mCurBuilder != NULL)) linkageName = StrFormat("%d", mCompiler->mCeMachine->mCurBuilder->DbgCreateMethodRef(mCurMethodInstance, "$initFields")); @@ -17969,7 +17950,7 @@ void BfModule::EmitCtorBody(bool& skipBody) // For extensions, only handle these fields in the appropriate extension if ((fieldDef->mDeclaringType->mTypeDeclaration != methodDef->mDeclaringType->mTypeDeclaration)) continue; - + if ((!fieldDef->mIsConst) && (!fieldDef->mIsStatic)) { auto fieldInst = &mCurTypeInstance->mFieldInstances[fieldDef->mIdx]; @@ -17982,7 +17963,7 @@ void BfModule::EmitCtorBody(bool& skipBody) if (fieldInst->IsAppendedObject()) { UpdateSrcPos(fieldDef->GetNameNode()); - AppendedObjectInit(fieldInst); + AppendedObjectInit(fieldInst); continue; } @@ -17993,7 +17974,7 @@ void BfModule::EmitCtorBody(bool& skipBody) // if (fieldDef->mProtection != BfProtection_Hidden) // continue; // if (mCurTypeInstance->IsObject()) // Already zeroed out -// continue; +// continue; } if (fieldInst->mResolvedType == NULL) @@ -18016,10 +17997,10 @@ void BfModule::EmitCtorBody(bool& skipBody) { // Failed } - auto assignValue = GetFieldInitializerValue(fieldInst); + auto assignValue = GetFieldInitializerValue(fieldInst); if (mCurTypeInstance->IsUnion()) - { + { auto fieldPtrType = CreatePointerType(fieldInst->mResolvedType); fieldAddr = mBfIRBuilder->CreateBitCast(fieldAddr, mBfIRBuilder->MapType(fieldPtrType)); } @@ -18030,7 +18011,7 @@ void BfModule::EmitCtorBody(bool& skipBody) } EmitInitBlocks(_CheckInitBlock); - + if (hadInlineInitBlock) { RestoreScopeState(); @@ -18049,8 +18030,8 @@ void BfModule::EmitCtorBody(bool& skipBody) mCurMethodState->AddScope(&scopeData); NewScopeState(); - // The reason we can't just do the 'normal' path for this is that the BfTypeInstance here is NOT the - // autocomplete type instance, so FieldInstance initializer values contain expressions from the full + // The reason we can't just do the 'normal' path for this is that the BfTypeInstance here is NOT the + // autocomplete type instance, so FieldInstance initializer values contain expressions from the full // resolve pass, NOT the autocomplete expression for (auto tempTypeDef : mCompiler->mResolvePassData->mAutoCompleteTempTypes) { @@ -18058,7 +18039,7 @@ void BfModule::EmitCtorBody(bool& skipBody) { for (auto fieldDef : tempTypeDef->mFields) { - auto initializer = fieldDef->GetInitializer(); + auto initializer = fieldDef->GetInitializer(); if ((!fieldDef->mIsStatic) && (initializer != NULL) && (mCompiler->mResolvePassData->mIsClassifying)) { @@ -18095,10 +18076,10 @@ void BfModule::EmitCtorBody(bool& skipBody) { if (initMethodDef->mMethodType != BfMethodType_Init) continue; - initBodies.Insert(0, initMethodDef->mBody); + initBodies.Insert(0, initMethodDef->mBody); } - for (auto body : initBodies) - VisitEmbeddedStatement(body); + for (auto body : initBodies) + VisitEmbeddedStatement(body); } } @@ -18114,7 +18095,7 @@ void BfModule::EmitCtorBody(bool& skipBody) } RestoreScopeState(); - } + } } if (!methodInstance->mIsAutocompleteMethod) @@ -18136,8 +18117,8 @@ void BfModule::EmitCtorBody(bool& skipBody) BF_ASSERT(localVar->mName == paramDef->mName); auto localVal = exprEvaluator.LoadLocal(localVar); localVal = LoadOrAggregateValue(localVal); - - if (!localVal.mType->IsVar()) + + if (!localVal.mType->IsVar()) { auto thisVal = GetThis(); auto fieldPtr = mBfIRBuilder->CreateInBoundsGEP(thisVal.mValue, 0, fieldInstance.mDataIdx); @@ -18149,7 +18130,7 @@ void BfModule::EmitCtorBody(bool& skipBody) } // Call base ctor (if applicable) - BfTypeInstance* targetType = NULL; + BfTypeInstance* targetType = NULL; BfAstNode* targetRefNode = NULL; if (ctorDeclaration != NULL) targetRefNode = ctorDeclaration->mInitializer; @@ -18158,7 +18139,7 @@ void BfModule::EmitCtorBody(bool& skipBody) if (baseCtorNode != NULL) { - UpdateSrcPos(baseCtorNode); + UpdateSrcPos(baseCtorNode); if (methodDef->mBody == NULL) SetIllegalSrcPos(); } @@ -18179,7 +18160,7 @@ void BfModule::EmitCtorBody(bool& skipBody) bool hadCtorWithAllDefaults = false; bool isHiddenGenerated = (methodDeclaration == NULL) && (methodDef->mProtection == BfProtection_Hidden); - + for (int pass = 0; pass < 2; pass++) { baseType->mTypeDef->PopulateMemberSets(); @@ -18188,7 +18169,7 @@ void BfModule::EmitCtorBody(bool& skipBody) baseType->mTypeDef->mMethodSet.TryGetWith(String("__BfCtor"), &entry); if (entry != NULL) checkMethodDef = (BfMethodDef*)entry->mMemberDef; - + while (checkMethodDef != NULL) { bool allowMethod = checkMethodDef->mProtection > BfProtection_Private; @@ -18199,11 +18180,11 @@ void BfModule::EmitCtorBody(bool& skipBody) if ((checkMethodDef->mMethodDeclaration == NULL) && (pass == 1) && (!hadCtorWithAllDefaults)) allowMethod = true; } - + if ((checkMethodDef->mMethodType == BfMethodType_Ctor) && (!checkMethodDef->mIsStatic) && (allowMethod)) { if (checkMethodDef->mParams.size() == 0) - { + { if (matchedMethod != NULL) { // Has multiple matched methods - can happen from extensions @@ -18239,7 +18220,7 @@ void BfModule::EmitCtorBody(bool& skipBody) auto callInst = mBfIRBuilder->CreateCall(ctorBodyMethodInstance.mFunc, args); auto callingConv = GetIRCallingConvention(ctorBodyMethodInstance.mMethodInstance); if (callingConv != BfIRCallingConv_CDecl) - mBfIRBuilder->SetCallCallingConv(callInst, callingConv); + mBfIRBuilder->SetCallCallingConv(callInst, callingConv); if (mIsComptimeModule) mCompiler->mCeMachine->QueueMethod(ctorBodyMethodInstance); } @@ -18253,7 +18234,7 @@ void BfModule::EmitCtorBody(bool& skipBody) targetRefNode = typeDef->mTypeDeclaration->mNameNode; } } - } + } if (methodDef->mHasAppend) { @@ -18275,7 +18256,7 @@ void BfModule::EmitCtorBody(bool& skipBody) } targetType = NULL; - } + } } if (targetType != NULL) @@ -18299,7 +18280,7 @@ void BfModule::EmitCtorBody(bool& skipBody) BfExprEvaluator exprEvaluator(this); BfResolvedArgs argValues; if ((ctorDeclaration != NULL) && (ctorInvocation != NULL)) - { + { argValues.Init(&ctorInvocation->mArguments); if (gDebugStuff) { @@ -18310,7 +18291,7 @@ void BfModule::EmitCtorBody(bool& skipBody) BfTypedValue appendIdxVal; if (methodDef->mHasAppend) - { + { auto localVar = mCurMethodState->GetRootMethodState()->mLocals[1]; BF_ASSERT(localVar->mName == "appendIdx"); auto intRefType = localVar->mResolvedType; @@ -18326,7 +18307,7 @@ void BfModule::EmitCtorBody(bool& skipBody) if (autoComplete->mMethodMatchInfo != NULL) autoComplete->mIsCapturingMethodMatchInfo = true; else - autoComplete->mIsCapturingMethodMatchInfo = false; + autoComplete->mIsCapturingMethodMatchInfo = false; } else autoComplete->mIsCapturingMethodMatchInfo = false; @@ -18335,7 +18316,7 @@ void BfModule::EmitCtorBody(bool& skipBody) } void BfModule::EmitEnumToStringBody() -{ +{ auto stringType = ResolveTypeDef(mCompiler->mStringTypeDef); auto strVal = CreateAlloca(stringType); @@ -18343,7 +18324,7 @@ void BfModule::EmitEnumToStringBody() BfExprEvaluator exprEvaluator(this); auto stringDestAddr = exprEvaluator.LoadLocal(mCurMethodState->mLocals[1]); - + BfIRBlock appendBlock = mBfIRBuilder->CreateBlock("append"); BfIRBlock noMatchBlock = mBfIRBuilder->CreateBlock("noMatch"); BfIRBlock endBlock = mBfIRBuilder->CreateBlock("end"); @@ -18354,7 +18335,7 @@ void BfModule::EmitEnumToStringBody() BfIRValue enumVal; if (mCurTypeInstance->IsPayloadEnum()) { - discriminatorType = mCurTypeInstance->GetDiscriminatorType(); + discriminatorType = mCurTypeInstance->GetDiscriminatorType(); auto enumTypedValue = ExtractValue(GetThis(), NULL, 2); enumTypedValue = LoadValue(enumTypedValue); enumVal = enumTypedValue.mValue; @@ -18390,20 +18371,20 @@ void BfModule::EmitEnumToStringBody() args.Add(stringDestVal.mValue); args.Add(caseStr); exprEvaluator.CreateCall(NULL, appendModuleMethodInstance.mMethodInstance, appendModuleMethodInstance.mFunc, false, args); - + auto payloadType = fieldInstance.mResolvedType->ToTypeInstance(); BF_ASSERT(payloadType->IsTuple()); - - if (payloadType->mFieldInstances.size() != 0) + + if (payloadType->mFieldInstances.size() != 0) { auto payload = rawPayload; if (payload.mType != payloadType) - { + { payload = Cast(NULL, payload, payloadType, BfCastFlags_Force); } auto toStringMethod = GetMethodByName(payloadType->ToTypeInstance(), "ToString"); - + SizedArray irArgs; exprEvaluator.PushThis(NULL, payload, toStringMethod.mMethodInstance, irArgs); stringDestVal = LoadValue(stringDestAddr); @@ -18434,18 +18415,18 @@ void BfModule::EmitEnumToStringBody() BfIRBlock caseBlock = mBfIRBuilder->CreateBlock("case"); mBfIRBuilder->AddBlock(caseBlock); mBfIRBuilder->SetInsertPoint(caseBlock); - + BfIRValue constVal = ConstantToCurrent(constant, mCurTypeInstance->mConstHolder, mCurTypeInstance); mBfIRBuilder->AddSwitchCase(switchVal, constVal, caseBlock); - auto caseStr = GetStringObjectValue(fieldInstance.GetFieldDef()->mName); + auto caseStr = GetStringObjectValue(fieldInstance.GetFieldDef()->mName); mBfIRBuilder->CreateStore(caseStr, strVal); - mBfIRBuilder->CreateBr(appendBlock); + mBfIRBuilder->CreateBr(appendBlock); } mBfIRBuilder->AddBlock(appendBlock); mBfIRBuilder->SetInsertPoint(appendBlock); - + SizedArray args; auto stringDestVal = LoadValue(stringDestAddr); args.Add(stringDestVal.mValue); @@ -18472,7 +18453,7 @@ void BfModule::EmitTupleToStringBody() { auto stringType = ResolveTypeDef(mCompiler->mStringTypeDef); - BfExprEvaluator exprEvaluator(this); + BfExprEvaluator exprEvaluator(this); auto stringDestRef = exprEvaluator.LoadLocal(mCurMethodState->mLocals[1]); @@ -18496,7 +18477,7 @@ void BfModule::EmitTupleToStringBody() int fieldIdx = 0; auto thisValue = GetThis(); - + auto toStringModuleMethodInstance = GetMethodByName(mContext->mBfObjectType, "ToString", 1); auto toStringSafeModuleMethodInstance = GetMethodByName(mContext->mBfObjectType, "ToString", 2); BfIRValue commaStr; @@ -18513,7 +18494,7 @@ void BfModule::EmitTupleToStringBody() if (fieldIdx > 0) { if (!commaStr) - commaStr = GetStringObjectValue(", "); + commaStr = GetStringObjectValue(", "); SizedArray args; auto stringDestVal = LoadValue(stringDestRef); args.Add(stringDestVal.mValue); @@ -18522,8 +18503,8 @@ void BfModule::EmitTupleToStringBody() } fieldIdx++; - if (fieldInstance.mResolvedType->IsValuelessType()) - continue; + if (fieldInstance.mResolvedType->IsValuelessType()) + continue; BfTypedValue fieldValue = ExtractValue(thisValue, &fieldInstance, fieldInstance.mDataIdx); @@ -18536,7 +18517,7 @@ void BfModule::EmitTupleToStringBody() if ((typeInstance != NULL) && (TypeIsSubTypeOf(typeInstance, iPrintableType, false))) { - BfExprEvaluator exprEvaluator(this); + BfExprEvaluator exprEvaluator(this); SizedArray resolvedArgs; BfMethodMatcher methodMatcher(NULL, this, printModuleMethodInstance.mMethodInstance, resolvedArgs, BfMethodGenericArguments()); methodMatcher.mBestMethodDef = printModuleMethodInstance.mMethodInstance->mMethodDef; @@ -18558,21 +18539,21 @@ void BfModule::EmitTupleToStringBody() if (fieldValue.mType->IsObjectOrInterface()) { fieldValue = LoadValue(fieldValue); - BF_ASSERT(!fieldValue.IsAddr()); + BF_ASSERT(!fieldValue.IsAddr()); SizedArray args; args.Add(mBfIRBuilder->CreateBitCast(fieldValue.mValue, mBfIRBuilder->MapType(mContext->mBfObjectType))); auto stringDestVal = exprEvaluator.LoadLocal(mCurMethodState->mLocals[1]); stringDestVal = LoadValue(stringDestVal); - args.Add(stringDestVal.mValue); + args.Add(stringDestVal.mValue); exprEvaluator.CreateCall(NULL, toStringSafeModuleMethodInstance.mMethodInstance, toStringSafeModuleMethodInstance.mFunc, false, args); continue; } - BfExprEvaluator exprEvaluator(this); - SizedArray resolvedArgs; + BfExprEvaluator exprEvaluator(this); + SizedArray resolvedArgs; BfMethodMatcher methodMatcher(NULL, this, toStringModuleMethodInstance.mMethodInstance, resolvedArgs, BfMethodGenericArguments()); methodMatcher.mBestMethodDef = toStringModuleMethodInstance.mMethodInstance->mMethodDef; - methodMatcher.mBestMethodTypeInstance = mContext->mBfObjectType; + methodMatcher.mBestMethodTypeInstance = mContext->mBfObjectType; methodMatcher.TryDevirtualizeCall(fieldValue); if (methodMatcher.mBestMethodTypeInstance == mContext->mBfObjectType) @@ -18593,13 +18574,13 @@ void BfModule::EmitTupleToStringBody() } BfTypedValue callVal = Cast(NULL, fieldValue, methodMatcher.mBestMethodTypeInstance); - + BfResolvedArg resolvedArg; auto stringDestVal = LoadValue(stringDestRef); resolvedArg.mTypedValue = stringDestVal; resolvedArg.mResolvedType = stringDestVal.mType; resolvedArgs.Add(resolvedArg); - + exprEvaluator.CreateCall(&methodMatcher, callVal); } _AppendChar(')'); @@ -18611,18 +18592,18 @@ void BfModule::EmitIteratorBlock(bool& skipBody) auto methodDef = methodInstance->mMethodDef; auto methodDeclaration = methodDef->GetMethodDeclaration(); auto typeDef = mCurTypeInstance->mTypeDef; - + BfType* innerRetType = NULL; BfTypeInstance* usingInterface = NULL; - auto retTypeInst = mCurMethodInstance->mReturnType->ToGenericTypeInstance(); + auto retTypeInst = mCurMethodInstance->mReturnType->ToGenericTypeInstance(); if (retTypeInst != NULL) { - if ((retTypeInst->IsInstanceOf(mCompiler->mGenericIEnumerableTypeDef)) || + if ((retTypeInst->IsInstanceOf(mCompiler->mGenericIEnumerableTypeDef)) || (retTypeInst->IsInstanceOf(mCompiler->mGenericIEnumeratorTypeDef))) - { + { innerRetType = retTypeInst->mGenericTypeInfo->mTypeGenericArguments[0]; - } + } } if (innerRetType == NULL) @@ -18633,22 +18614,22 @@ void BfModule::EmitIteratorBlock(bool& skipBody) auto blockBody = BfNodeDynCast(methodDeclaration->mBody); if (blockBody == NULL) - return; + return; } void BfModule::EmitGCMarkAppended(BfTypedValue markVal) -{ +{ auto gcType = ResolveTypeDef(mCompiler->mGCTypeDef, BfPopulateType_DataAndMethods); if (gcType == NULL) return; BfModuleMethodInstance markFromGCThreadMethodInstance = GetMethodByName(gcType->ToTypeInstance(), "MarkAppendedObject", 1); if (!markFromGCThreadMethodInstance) return; - + SizedArray args; args.push_back(mBfIRBuilder->CreateBitCast(markVal.mValue, mBfIRBuilder->MapType(mContext->mBfObjectType))); BfExprEvaluator exprEvaluator(this); - exprEvaluator.CreateCall(NULL, markFromGCThreadMethodInstance.mMethodInstance, markFromGCThreadMethodInstance.mFunc, false, args); + exprEvaluator.CreateCall(NULL, markFromGCThreadMethodInstance.mMethodInstance, markFromGCThreadMethodInstance.mFunc, false, args); } void BfModule::EmitGCMarkValue(BfTypedValue markVal, BfModuleMethodInstance markFromGCThreadMethodInstance) @@ -18670,13 +18651,13 @@ void BfModule::EmitGCMarkValue(BfTypedValue markVal, BfModuleMethodInstance mark SizedArray args; args.push_back(val); exprEvaluator.CreateCall(NULL, markFromGCThreadMethodInstance.mMethodInstance, markFromGCThreadMethodInstance.mFunc, false, args); - } + } else if (fieldType->IsSizedArray()) { BfSizedArrayType* sizedArrayType = (BfSizedArrayType*)fieldType; if (sizedArrayType->mElementType->WantsGCMarking()) { - BfTypedValue arrayValue = markVal; + BfTypedValue arrayValue = markVal; auto intPtrType = GetPrimitiveType(BfTypeCode_IntPtr); auto itr = CreateAlloca(intPtrType); mBfIRBuilder->CreateStore(GetDefaultValue(intPtrType), itr); @@ -18704,16 +18685,16 @@ void BfModule::EmitGCMarkValue(BfTypedValue markVal, BfModuleMethodInstance mark mBfIRBuilder->CreateStore(incValue, itr); mBfIRBuilder->CreateBr(loopBB); - mBfIRBuilder->SetInsertPoint(doneBB); + mBfIRBuilder->SetInsertPoint(doneBB); } } else if ((fieldType->IsComposite()) && (!fieldType->IsTypedPrimitive()) && (fieldTypeInst != NULL)) - { + { auto markMemberMethodInstance = GetMethodByName(fieldTypeInst, BF_METHODNAME_MARKMEMBERS, 0, true); if (markMemberMethodInstance) { SizedArray args; - + auto methodOwner = markMemberMethodInstance.mMethodInstance->GetOwner(); if (markVal.mType != methodOwner) markVal = Cast(NULL, markVal, methodOwner); @@ -18725,11 +18706,11 @@ void BfModule::EmitGCMarkValue(BfTypedValue markVal, BfModuleMethodInstance mark } void BfModule::CallChainedMethods(BfMethodInstance* methodInstance, bool reverse) -{ +{ Array methodInstances; for (int methodIdx = 0; methodIdx < (int)mCurTypeInstance->mMethodInstanceGroups.size(); methodIdx++) - { + { auto& methodInstGroup = mCurTypeInstance->mMethodInstanceGroups[methodIdx]; auto chainedMethodInst = methodInstGroup.mDefault; if ((chainedMethodInst != NULL) && (chainedMethodInst->mChainType == BfMethodChainType_ChainMember)) @@ -18737,11 +18718,11 @@ void BfModule::CallChainedMethods(BfMethodInstance* methodInstance, bool reverse if ((chainedMethodInst->mMethodDef->mIsStatic == methodInstance->mMethodDef->mIsStatic) && (CompareMethodSignatures(methodInstance, chainedMethodInst))) { - methodInstances.push_back(chainedMethodInst); + methodInstances.push_back(chainedMethodInst); } } } - + std::stable_sort(methodInstances.begin(), methodInstances.end(), [&](BfMethodInstance* lhs, BfMethodInstance* rhs) { @@ -18773,7 +18754,7 @@ void BfModule::CallChainedMethods(BfMethodInstance* methodInstance, bool reverse } void BfModule::AddHotDataReferences(BfHotDataReferenceBuilder* builder) -{ +{ BF_ASSERT(mCurMethodInstance->mIsReified); if (mCurTypeInstance->mHotTypeData == NULL) @@ -18782,7 +18763,7 @@ void BfModule::AddHotDataReferences(BfHotDataReferenceBuilder* builder) BfLogSysM("Created HotTypeData %p created for type %p in AddHotDataReferences\n", mCurTypeInstance->mHotTypeData, mCurTypeInstance); } - auto hotMethod = mCurMethodInstance->mHotMethod; + auto hotMethod = mCurMethodInstance->mHotMethod; for (auto depData : hotMethod->mReferences) { // Only virtual decls are allowed to already be there @@ -18790,7 +18771,7 @@ void BfModule::AddHotDataReferences(BfHotDataReferenceBuilder* builder) } BF_ASSERT(hotMethod->mSrcTypeVersion != NULL); - + int prevSize = (int)hotMethod->mReferences.size(); int refCount = (int)(prevSize + builder->mUsedData.size() + builder->mCalledMethods.size() + builder->mDevirtualizedCalledMethods.size()); if (!mCurMethodInstance->mMethodDef->mIsStatic) @@ -18798,16 +18779,16 @@ void BfModule::AddHotDataReferences(BfHotDataReferenceBuilder* builder) hotMethod->mReferences.Reserve(refCount); if (!mCurMethodInstance->mMethodDef->mIsStatic) - { + { auto hotThis = mCompiler->mHotData->GetThisType(mCurMethodInstance->GetOwner()->mHotTypeData->GetLatestVersion()); hotThis->mRefCount++; hotMethod->mReferences.Insert(0, hotThis); prevSize++; } for (auto val : builder->mAllocatedData) - { + { auto hotAllocation = mCompiler->mHotData->GetAllocation(val); - hotMethod->mReferences.Add(hotAllocation); + hotMethod->mReferences.Add(hotAllocation); } for (auto val : builder->mUsedData) hotMethod->mReferences.Add(val); @@ -18834,7 +18815,7 @@ void BfModule::AddHotDataReferences(BfHotDataReferenceBuilder* builder) auto depData = hotMethod->mReferences[refIdx]; BF_ASSERT(depData != NULL); depData->mRefCount++; - } + } } void BfModule::ProcessMethod_SetupParams(BfMethodInstance* methodInstance, BfType* thisType, bool wantsDIData, SizedArrayImpl* diParams) @@ -18845,9 +18826,9 @@ void BfModule::ProcessMethod_SetupParams(BfMethodInstance* methodInstance, BfTyp bool isThisStruct = false; if (thisType != NULL) isThisStruct = thisType->IsStruct() && !thisType->IsTypedPrimitive(); - + int argIdx = 0; - + if ((!mIsComptimeModule) && (argIdx == methodInstance->GetStructRetIdx())) argIdx++; @@ -18866,7 +18847,7 @@ void BfModule::ProcessMethod_SetupParams(BfMethodInstance* methodInstance, BfTyp paramVar->mValue = mBfIRBuilder->GetArgument(argIdx); else paramVar->mValue = mBfIRBuilder->GetFakeVal(); - + if ((!mIsComptimeModule) && (thisType->IsSplattable()) && (methodInstance->AllowsSplatting(-1))) { if (!thisType->IsTypedPrimitive()) @@ -18904,7 +18885,7 @@ void BfModule::ProcessMethod_SetupParams(BfMethodInstance* methodInstance, BfTyp diType = mBfIRBuilder->DbgCreateArtificialType(diType); else if (!paramVar->mIsSplat) diType = mBfIRBuilder->DbgCreatePointerType(diType); - + diParams->push_back(diType); } @@ -18913,12 +18894,12 @@ void BfModule::ProcessMethod_SetupParams(BfMethodInstance* methodInstance, BfTyp BfTypeUtils::SplatIterate([&](BfType* checkType) { argIdx++; }, paramVar->mResolvedType); } else - { + { argIdx++; if (loweredTypeCode2 != BfTypeCode_None) argIdx++; } - } + } } if ((!mIsComptimeModule) && (argIdx == methodInstance->GetStructRetIdx())) @@ -18930,7 +18911,7 @@ void BfModule::ProcessMethod_SetupParams(BfMethodInstance* methodInstance, BfTyp int compositeVariableIdx = -1; int paramIdx = 0; for (paramIdx = 0; paramIdx < methodInstance->GetParamCount(); paramIdx++) - { + { // We already issues a type error for this param if we had one in declaration processing SetAndRestoreValue prevIgnoreErrors(mIgnoreErrors, true); BfLocalVariable* paramVar = rootMethodState->mBumpAlloc.Alloc(); @@ -18940,7 +18921,7 @@ void BfModule::ProcessMethod_SetupParams(BfMethodInstance* methodInstance, BfTyp BfTypeCode loweredTypeCode2 = BfTypeCode_None; bool isParamSkipped = methodInstance->IsParamSkipped(paramIdx); - + auto resolvedType = methodInstance->GetParamType(paramIdx); if (resolvedType == NULL) { @@ -19135,14 +19116,14 @@ void BfModule::ProcessMethod_SetupParams(BfMethodInstance* methodInstance, BfTyp // Had error or 'var' } else if (paramsType->IsGenericParam()) - { + { auto genericParamInstance = GetGenericParamInstance((BfGenericParamType*)paramsType); if (genericParamInstance->mTypeConstraint != NULL) { auto typeInstConstraint = genericParamInstance->mTypeConstraint->ToTypeInstance(); - if ((genericParamInstance->mTypeConstraint->IsDelegate()) || (genericParamInstance->mTypeConstraint->IsFunction()) || - ((typeInstConstraint != NULL) && + if ((genericParamInstance->mTypeConstraint->IsDelegate()) || (genericParamInstance->mTypeConstraint->IsFunction()) || + ((typeInstConstraint != NULL) && ((typeInstConstraint->IsInstanceOf(mCompiler->mDelegateTypeDef)) || (typeInstConstraint->IsInstanceOf(mCompiler->mFunctionTypeDef))))) { BfLocalVariable* localVar = new BfLocalVariable(); @@ -19194,12 +19175,12 @@ void BfModule::ProcessMethod_ProcessDeferredLocals(int startIdx) mCurMethodState->mLocals.Clear(); mCurMethodState->mLocalVarSet.Clear(); }; - + while (true) { bool didWork = false; // Don't process local methods if we had a build error - this isn't just an optimization, it keeps us from showing the same error twice since - // we show errors in the capture phase. If we somehow pass the capture phase without error then this method WILL show any errors here, + // we show errors in the capture phase. If we somehow pass the capture phase without error then this method WILL show any errors here, // however (compiler bug), so this is the safest way if (!mCurMethodState->mDeferredLocalMethods.IsEmpty()) { @@ -19316,7 +19297,7 @@ void BfModule::ProcessMethod_ProcessDeferredLocals(int startIdx) } mContext->CheckLockYield(); - mCurMethodState->mDeferredLambdaInstances.Clear(); + mCurMethodState->mDeferredLambdaInstances.Clear(); } if (!didWork) @@ -19328,12 +19309,12 @@ void BfModule::EmitGCMarkValue(BfTypedValue& thisValue, BfType* checkType, int m { if (checkType->IsComposite()) PopulateType(checkType, BfPopulateType_Data); - + if (!checkType->WantsGCMarking()) return; auto typeInstance = checkType->ToTypeInstance(); - bool callMarkMethod = false; + bool callMarkMethod = false; // Call the actual marking method if (memberDepth == 0) @@ -19352,7 +19333,7 @@ void BfModule::EmitGCMarkValue(BfTypedValue& thisValue, BfType* checkType, int m { BfSizedArrayType* sizedArrayType = (BfSizedArrayType*)checkType; if (sizedArrayType->mElementType->WantsGCMarking()) - { + { BfTypedValue arrayValue = thisValue; if (thisValue.mType != checkType) { @@ -19390,18 +19371,18 @@ void BfModule::EmitGCMarkValue(BfTypedValue& thisValue, BfType* checkType, int m mBfIRBuilder->CreateCondBr(cmpRes, doneBB, bodyBB); mBfIRBuilder->SetInsertPoint(bodyBB); - + auto ptrType = CreatePointerType(sizedArrayType->mElementType); auto ptrValue = mBfIRBuilder->CreateBitCast(arrayValue.mValue, mBfIRBuilder->MapType(ptrType)); auto gepResult = mBfIRBuilder->CreateInBoundsGEP(ptrValue, loadedItr); auto value = BfTypedValue(gepResult, sizedArrayType->mElementType, BfTypedValueKind_Addr); EmitGCMarkValue(value, markFromGCThreadMethodInstance); - + auto incValue = mBfIRBuilder->CreateAdd(loadedItr, mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, 1)); mBfIRBuilder->CreateStore(incValue, itr); mBfIRBuilder->CreateBr(loopBB); - + mBfIRBuilder->SetInsertPoint(doneBB); } else @@ -19412,13 +19393,13 @@ void BfModule::EmitGCMarkValue(BfTypedValue& thisValue, BfType* checkType, int m auto ptrValue = mBfIRBuilder->CreateBitCast(arrayValue.mValue, mBfIRBuilder->MapType(ptrType)); auto gepResult = mBfIRBuilder->CreateInBoundsGEP(ptrValue, mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, dataIdx)); auto value = BfTypedValue(gepResult, sizedArrayType->mElementType, BfTypedValueKind_Addr); - - HashSet objectOffsets; + + HashSet objectOffsets; EmitGCMarkValue(value, markFromGCThreadMethodInstance); } } } - } + } else if (typeInstance != NULL) { typeInstance->mTypeDef->PopulateMemberSets(); @@ -19467,7 +19448,7 @@ void BfModule::EmitGCMarkValue(BfTypedValue& thisValue, BfType* checkType, int m return; } - auto methodDef = mCurMethodInstance->mMethodDef; + auto methodDef = mCurMethodInstance->mMethodDef; if (checkType->IsPayloadEnum()) { @@ -19475,14 +19456,14 @@ void BfModule::EmitGCMarkValue(BfTypedValue& thisValue, BfType* checkType, int m { if (!fieldInst.mIsEnumPayloadCase) continue; - auto fieldDef = fieldInst.GetFieldDef(); + auto fieldDef = fieldInst.GetFieldDef(); EmitGCMarkValue(thisValue, fieldInst.mResolvedType, memberDepth + 1, curOffset, objectOffsets, markFromGCThreadMethodInstance); } return; } if (typeInstance == NULL) - return; + return; for (auto& fieldInst : typeInstance->mFieldInstances) { @@ -19490,7 +19471,7 @@ void BfModule::EmitGCMarkValue(BfTypedValue& thisValue, BfType* checkType, int m if (fieldDef == NULL) continue; if (fieldDef->mIsStatic) - continue; + continue; if (typeInstance == mCurTypeInstance) { // Note: we don't do method chaining when we are marking members of members. Theoretically this means @@ -19498,10 +19479,10 @@ void BfModule::EmitGCMarkValue(BfTypedValue& thisValue, BfType* checkType, int m if ((fieldDef->mDeclaringType->mTypeDeclaration != methodDef->mDeclaringType->mTypeDeclaration)) continue; } - + EmitGCMarkValue(thisValue, fieldInst.mResolvedType, memberDepth + 1, curOffset + fieldInst.mDataOffset, objectOffsets, markFromGCThreadMethodInstance, fieldInst.IsAppendedObject()); } - + if ((typeInstance->mBaseType != NULL) && (typeInstance->mBaseType != mContext->mBfObjectType)) { EmitGCMarkValue(thisValue, typeInstance->mBaseType, memberDepth, curOffset, objectOffsets, markFromGCThreadMethodInstance); @@ -19585,7 +19566,7 @@ void BfModule::EmitGCMarkMembers() auto thisValue = GetThis(); auto baseValue = Cast(NULL, thisValue, methodBaseType, BfCastFlags_Explicit); - SizedArray args; + SizedArray args; if ((!mIsComptimeModule) && (moduleMethodInst.mMethodInstance->GetParamIsSplat(-1))) { BfExprEvaluator exprEvaluator(this); @@ -19628,7 +19609,7 @@ void BfModule::EmitGCMarkMembers() if (!fieldInst.mFieldIncluded) continue; - auto fieldType = fieldInst.mResolvedType; + auto fieldType = fieldInst.mResolvedType; auto fieldDef = fieldInst.GetFieldDef(); BfTypedValue markVal; @@ -19692,19 +19673,19 @@ void BfModule::EmitGCFindTLSMembers() BF_ASSERT(reportTLSMark); for (auto& fieldInst : mCurTypeInstance->mFieldInstances) - { + { auto fieldDef = fieldInst.GetFieldDef(); if (fieldDef == NULL) continue; if (!fieldInst.mIsThreadLocal) continue; - + // For extensions, only handle these fields in the appropriate extension if ((fieldDef->mDeclaringType->mTypeDeclaration != methodDef->mDeclaringType->mTypeDeclaration)) continue; if (!fieldInst.mFieldIncluded) continue; - + if (fieldDef->mIsConst) continue; @@ -19715,18 +19696,18 @@ void BfModule::EmitGCFindTLSMembers() if (fieldType->IsValuelessType()) continue; - + BfTypedValue markVal = ReferenceStaticField(&fieldInst); if (markVal) { BfIRValue fieldRefPtr = mBfIRBuilder->CreateBitCast(markVal.mValue, mBfIRBuilder->MapType(GetPrimitiveType(BfTypeCode_NullPtr))); BfIRValue markFuncPtr = GetMarkFuncPtr(fieldType); - + SizedArray llvmArgs; llvmArgs.push_back(fieldRefPtr); - llvmArgs.push_back(markFuncPtr); - mBfIRBuilder->CreateCall(reportTLSMark.mFunc, llvmArgs); - } + llvmArgs.push_back(markFuncPtr); + mBfIRBuilder->CreateCall(reportTLSMark.mFunc, llvmArgs); + } } if (mCurMethodInstance->mChainType == BfMethodChainType_ChainHead) @@ -19747,7 +19728,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, if (!methodInstance->mIsReified) BF_ASSERT(!mIsReified); - + BF_ASSERT((!methodInstance->GetOwner()->IsUnspecializedTypeVariation()) || (mIsComptimeModule)); if (methodInstance->mMethodInfoEx != NULL) @@ -19763,14 +19744,14 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, } SetAndRestoreValue prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, (mWantsIRIgnoreWrites || methodInstance->mIsUnspecialized) && (!forceIRWrites)); - + if ((HasCompiledOutput()) && (!mBfIRBuilder->mIgnoreWrites)) { BF_ASSERT(!methodInstance->mIRFunction.IsFake() || (methodInstance->GetImportCallKind() != BfImportCallKind_None)); } SetAndRestoreValue prevIsClassifying; - if (((methodInstance->mMethodDef->mMethodType == BfMethodType_CtorCalcAppend) || (methodInstance->mIsForeignMethodDef) || (methodInstance->IsSpecializedGenericMethod())) && + if (((methodInstance->mMethodDef->mMethodType == BfMethodType_CtorCalcAppend) || (methodInstance->mIsForeignMethodDef) || (methodInstance->IsSpecializedGenericMethod())) && (mCompiler->mResolvePassData != NULL)) { // Don't classify on the CtorCalcAppend, just on the actual Ctor @@ -19798,7 +19779,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, } BfMethodInstance* defaultMethodInstance = methodInstance->mMethodInstanceGroup->mDefault; - + if (!mIsComptimeModule) { BF_ASSERT(methodInstance->mMethodInstanceGroup->mOnDemandKind != BfMethodOnDemandKind_NotSet); @@ -19826,8 +19807,8 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, // We set mHasBeenProcessed to true immediately -- this helps avoid stack overflow during recursion for things like // self-referencing append allocations in ctor@calcAppend - methodInstance->mHasBeenProcessed = true; - mIncompleteMethodCount--; + methodInstance->mHasBeenProcessed = true; + mIncompleteMethodCount--; BF_ASSERT((mIsSpecialModule) || (mIncompleteMethodCount >= 0)); auto typeDef = methodInstance->mMethodInstanceGroup->mOwner->mTypeDef; @@ -19835,7 +19816,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, auto methodDeclaration = methodDef->GetMethodDeclaration(); if ((methodDef->mHasComptime) && (!mIsComptimeModule)) - mBfIRBuilder->mIgnoreWrites = true; + mBfIRBuilder->mIgnoreWrites = true; if ((methodInstance->mIsReified) && (methodInstance->mVirtualTableIdx != -1)) { @@ -19848,9 +19829,9 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, if ((methodDef->mIsLocalMethod) && (mCurMethodState != NULL)) // See DoMethodDeclaration for an explaination of dependentGenericStartIdx dependentGenericStartIdx = (int)mCurMethodState->GetRootMethodState()->mMethodInstance->GetNumGenericArguments(); - SetAndRestoreValue prevMethodInstance(mCurMethodInstance, methodInstance); + SetAndRestoreValue prevMethodInstance(mCurMethodInstance, methodInstance); SetAndRestoreValue prevTypeInstance(mCurTypeInstance, methodInstance->mMethodInstanceGroup->mOwner); - SetAndRestoreValue prevFilePos(mCurFilePosition); + SetAndRestoreValue prevFilePos(mCurFilePosition); SetAndRestoreValue prevHadBuildError(mHadBuildError, false); SetAndRestoreValue prevHadWarning(mHadBuildWarning, false); SetAndRestoreValue prevIgnoreErrors(mIgnoreErrors); @@ -19891,10 +19872,10 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, } } if ((mCompiler->mResolvePassData != NULL) && (methodDeclaration != NULL) && (nameNode != NULL) && - (mCompiler->mResolvePassData->mGetSymbolReferenceKind == BfGetSymbolReferenceKind_Method) && + (mCompiler->mResolvePassData->mGetSymbolReferenceKind == BfGetSymbolReferenceKind_Method) && (methodDef->mIdx >= 0) && (!methodInstance->mIsForeignMethodDef)) { - if (methodInstance->GetExplicitInterface() == NULL) + if (methodInstance->GetExplicitInterface() == NULL) mCompiler->mResolvePassData->HandleMethodReference(nameNode, typeDef, methodDef); else { @@ -19924,12 +19905,12 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, auto ifaceMethodDef = ifaceInst->mTypeDef->mMethods[checkMethod->mIdx]; mCompiler->mResolvePassData->HandleMethodReference(nameNode, ifaceInst->mTypeDef, ifaceMethodDef); } - } + } } } if (methodDef->mIsOverride) - { + { for (int virtIdx = 0; virtIdx < (int)mCurTypeInstance->mVirtualMethodTable.size(); virtIdx++) { auto& ventry = mCurTypeInstance->mVirtualMethodTable[virtIdx]; @@ -19971,11 +19952,11 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, { if (customAttr->mCtorArgs.size() == 1) { - auto fileNameArg = customAttr->mCtorArgs[0]; + auto fileNameArg = customAttr->mCtorArgs[0]; auto constant = mCurTypeInstance->mConstHolder->GetConstant(fileNameArg); if (constant != NULL) { - if (!constant->IsNull()) + if (!constant->IsNull()) importStrNum = constant->mInt32; } else @@ -19985,7 +19966,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, if (importStrNum != -1) { if (!mStringPoolRefs.Contains(importStrNum)) - mStringPoolRefs.Add(importStrNum); + mStringPoolRefs.Add(importStrNum); } } } @@ -19994,7 +19975,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, if (methodInstance->GetImportCallKind() != BfImportCallKind_None) { if (mBfIRBuilder->mIgnoreWrites) - return; + return; BfLogSysM("DllImportGlobalVar processing %p\n", methodInstance); @@ -20005,41 +19986,41 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, BF_ASSERT(dllImportGlobalVar || methodInstance->mHasFailed); mFuncReferences[mCurMethodInstance] = dllImportGlobalVar; } - + if (HasCompiledOutput()) { BfDllImportEntry dllImportEntry; - dllImportEntry.mFuncVar = methodInstance->mIRFunction; + dllImportEntry.mFuncVar = methodInstance->mIRFunction; dllImportEntry.mMethodInstance = mCurMethodInstance; mDllImportEntries.push_back(dllImportEntry); } - return; + return; } StringT<512> mangledName; BfMangler::Mangle(mangledName, mCompiler->GetMangleKind(), mCurMethodInstance); if (!methodInstance->mIRFunction) - { + { bool isIntrinsic = false; - SetupIRFunction(methodInstance, mangledName, false, &isIntrinsic); + SetupIRFunction(methodInstance, mangledName, false, &isIntrinsic); } if (methodInstance->mIsIntrinsic) return; if (mCurTypeInstance->IsFunction()) return; - + auto prevActiveFunction = mBfIRBuilder->GetActiveFunction(); - mBfIRBuilder->SetActiveFunction(mCurMethodInstance->mIRFunction); + mBfIRBuilder->SetActiveFunction(mCurMethodInstance->mIRFunction); if (methodDef->mBody != NULL) UpdateSrcPos(methodDef->mBody, BfSrcPosFlag_NoSetDebugLoc); - else if (methodDeclaration != NULL) + else if (methodDeclaration != NULL) UpdateSrcPos(methodDeclaration, BfSrcPosFlag_NoSetDebugLoc); else if ((methodDef->mDeclaringType != NULL) && (methodDef->mDeclaringType->GetRefNode() != NULL)) UpdateSrcPos(methodDef->mDeclaringType->GetRefNode(), BfSrcPosFlag_NoSetDebugLoc); else if (mCurTypeInstance->mTypeDef->mTypeDeclaration != NULL) - UpdateSrcPos(mCurTypeInstance->mTypeDef->mTypeDeclaration, BfSrcPosFlag_NoSetDebugLoc); - + UpdateSrcPos(mCurTypeInstance->mTypeDef->mTypeDeclaration, BfSrcPosFlag_NoSetDebugLoc); + if ((mCurMethodState == NULL) && (!IsInSpecializedSection())) // Only do initial classify for the 'outer' method state, not any local methods or lambdas { if ((mCompiler->mIsResolveOnly) && (!mIsComptimeModule) && (methodDef->mBody != NULL) && (!mCurTypeInstance->IsBoxed())) @@ -20047,7 +20028,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, if (auto sourceClassifier = mCompiler->mResolvePassData->GetSourceClassifier(methodDef->mBody)) sourceClassifier->VisitChildNoRef(methodDef->mBody); } - } + } BfHotDataReferenceBuilder hotDataReferenceBuilder; BfMethodState methodState; @@ -20055,7 +20036,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, methodState.mClosureState = mCurMethodState->mClosureState; if ((mCompiler->mOptions.mAllowHotSwapping) && (methodInstance->mIsReified) && (!methodInstance->mIsUnspecialized) && (!isInlineDup)) - { + { //BF_ASSERT(methodInstance->mHotMethod != NULL); if (methodInstance->mHotMethod == NULL) CheckHotMethod(methodInstance, mangledName); @@ -20065,32 +20046,32 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, methodState.mPrevMethodState = mCurMethodState; methodState.mMethodInstance = methodInstance; SetAndRestoreValue prevMethodState(mCurMethodState, &methodState); - + if (methodInstance->GetCustomAttributes() != NULL) { int typeOptionsIdx = GenerateTypeOptions(methodInstance->GetCustomAttributes(), mCurTypeInstance, false); if (typeOptionsIdx != -1) methodState.mMethodTypeOptions = mSystem->GetTypeOptions(typeOptionsIdx); } - + BfTypeState typeState(mCurTypeInstance); SetAndRestoreValue prevTypeState(mContext->mCurTypeState, &typeState); bool isGenericVariation = (methodInstance->mIsUnspecializedVariation) || (mCurTypeInstance->IsUnspecializedTypeVariation()); - BfMethodInstance* unspecializedMethodInstance = NULL; - if ((prevMethodState.mPrevVal != NULL) && + BfMethodInstance* unspecializedMethodInstance = NULL; + if ((prevMethodState.mPrevVal != NULL) && ((methodState.mClosureState == NULL) || (methodState.mClosureState->mActiveDeferredLocalMethod == NULL))) { // This is 'inner' (probably a closure) - use binding from outer function - methodState.mGenericTypeBindings = prevMethodState.mPrevVal->mGenericTypeBindings; + methodState.mGenericTypeBindings = prevMethodState.mPrevVal->mGenericTypeBindings; } - else if ((methodInstance->mIsUnspecialized) || + else if ((methodInstance->mIsUnspecialized) || ((mCurTypeInstance->IsUnspecializedType()) && (!isGenericVariation))) - { + { methodState.mGenericTypeBindings = &methodInstance->GetMethodInfoEx()->mGenericTypeBindings; } - else if ((((methodInstance->mMethodInfoEx != NULL) && ((int)methodInstance->mMethodInfoEx->mMethodGenericArguments.size() > dependentGenericStartIdx)) || + else if ((((methodInstance->mMethodInfoEx != NULL) && ((int)methodInstance->mMethodInfoEx->mMethodGenericArguments.size() > dependentGenericStartIdx)) || ((mCurTypeInstance->IsGenericTypeInstance()) && (!isGenericVariation || mIsComptimeModule) && (!methodInstance->mMethodDef->mIsLocalMethod) && (!methodInstance->mMethodDef->mDeclaringType->IsEmitted())))) { unspecializedMethodInstance = GetUnspecializedMethodInstance(methodInstance, !methodInstance->mMethodDef->mIsLocalMethod); @@ -20105,12 +20086,12 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, BF_ASSERT(unspecializedMethodInstance != methodInstance); if (!unspecializedMethodInstance->mHasBeenProcessed) { - // Make sure the unspecialized method is processed so we can take its bindings + // Make sure the unspecialized method is processed so we can take its bindings // Clear mCurMethodState so we don't think we're in a local method SetAndRestoreValue prevMethodState_Unspec(mCurMethodState, prevMethodState.mPrevVal); if (unspecializedMethodInstance->mMethodProcessRequest == NULL) unspecializedMethodInstance->mDeclModule->mIncompleteMethodCount++; - mContext->ProcessMethod(unspecializedMethodInstance); + mContext->ProcessMethod(unspecializedMethodInstance); } methodState.mGenericTypeBindings = &unspecializedMethodInstance->GetMethodInfoEx()->mGenericTypeBindings; } @@ -20130,8 +20111,8 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, if (operatorDef->mOperatorDeclaration->mBinOp != BfBinaryOp_None) { if (methodDef->mParams.size() != 2) - { - Fail("Binary operators must declare two parameters", paramErrorRefNode); + { + Fail("Binary operators must declare two parameters", paramErrorRefNode); } else { @@ -20205,7 +20186,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, { Fail("Assignment operators must declare one parameter", paramErrorRefNode); } - + if (!mCurMethodInstance->mReturnType->IsVoid()) { Fail("The return type for assignment operator must be 'void'", operatorDef->mOperatorDeclaration->mReturnType); @@ -20233,12 +20214,12 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, auto checkParam0 = mCurMethodInstance->GetParamType(0); if ((checkParam0->IsRef()) && (!checkParam0->IsOut())) checkParam0 = checkParam0->GetUnderlyingType(); - + if ((checkParam0 != mCurTypeInstance) && (!checkParam0->IsSelf()) && (mCurMethodInstance->mReturnType != mCurTypeInstance) && (!mCurMethodInstance->mReturnType->IsSelf())) Fail("User-defined conversion must convert to or from the enclosing type", paramErrorRefNode); if (checkParam0 == mCurMethodInstance->mReturnType) - Fail("User-defined operator cannot take an object of the enclosing type and convert to an object of the enclosing type", operatorDef->mOperatorDeclaration->mReturnType); + Fail("User-defined operator cannot take an object of the enclosing type and convert to an object of the enclosing type", operatorDef->mOperatorDeclaration->mReturnType); // On type lookup error we default to 'object', so don't do the 'base class' error if that may have // happened here @@ -20273,20 +20254,20 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, diParams.push_back(mBfIRBuilder->DbgGetType(methodInstance->mReturnType)); bool isThisStruct = mCurTypeInstance->IsStruct() && !mCurTypeInstance->IsTypedPrimitive(); - BfType* thisType = NULL; + BfType* thisType = NULL; if (!methodDef->mIsStatic) { if ((methodState.mClosureState != NULL) && (methodState.mClosureState->mClosureType != NULL)) thisType = methodState.mClosureState->mClosureType; else - thisType = mCurTypeInstance; + thisType = mCurTypeInstance; } - + PopulateType(methodInstance->mReturnType, BfPopulateType_Data); - + ProcessMethod_SetupParams(methodInstance, thisType, wantsDIData, &diParams); - - ////////////////////////////////////////////////////////////////////////// + + ////////////////////////////////////////////////////////////////////////// // { @@ -20297,24 +20278,24 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, else if ((methodDef->mDeclaringType != NULL) && (methodDef->mDeclaringType->GetRefNode() != NULL)) UpdateSrcPos(methodDef->mDeclaringType->GetRefNode(), BfSrcPosFlag_NoSetDebugLoc); else if (mCurTypeInstance->mTypeDef->mTypeDeclaration != NULL) - UpdateSrcPos(mCurTypeInstance->mTypeDef->mTypeDeclaration, BfSrcPosFlag_NoSetDebugLoc); + UpdateSrcPos(mCurTypeInstance->mTypeDef->mTypeDeclaration, BfSrcPosFlag_NoSetDebugLoc); } BfIRMDNode diFunction; - + if (wantsDIData) { - BP_ZONE("BfModule::DoMethodDeclaration.DISetup"); + BP_ZONE("BfModule::DoMethodDeclaration.DISetup"); BfIRMDNode diFuncType = mBfIRBuilder->DbgCreateSubroutineType(diParams); int defLine = mCurFilePosition.mCurLine; if (mDICompileUnit) - { - int flags = 0; + { + int flags = 0; BfIRMDNode funcScope = mBfIRBuilder->DbgGetTypeInst(mCurTypeInstance); - + if (methodDef->mProtection == BfProtection_Public) flags = llvm::DINode::FlagPublic; else if (methodDef->mProtection == BfProtection_Protected) @@ -20331,7 +20312,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, flags |= llvm::DINode::FlagStaticMember; else { - if ((mCurTypeInstance->IsValuelessType()) || + if ((mCurTypeInstance->IsValuelessType()) || ((!mIsComptimeModule) && (mCurTypeInstance->IsSplattable()))) flags |= llvm::DINode::FlagStaticMember; } @@ -20340,9 +20321,9 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, { flags |= llvm::DINode::FlagArtificial; } - + auto llvmFunction = methodInstance->mIRFunction; - SizedArray genericArgs; + SizedArray genericArgs; SizedArray genericConstValueArgs; String methodName; @@ -20359,7 +20340,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, } methodName += methodDef->mName; - + if (methodInstance->GetNumGenericArguments() != 0) { for (auto genericArg : methodInstance->mMethodInfoEx->mMethodGenericArguments) @@ -20371,12 +20352,12 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, genericConstValueArgs.push_back(BfIRValue()); genericConstValueArgs.push_back(mBfIRBuilder->CreateConst(BfTypeCode_UInt64, constExprValueType->mValue.mUInt64)); - genericArgs.push_back(mBfIRBuilder->DbgGetType(GetPrimitiveType(BfTypeCode_Int64))); + genericArgs.push_back(mBfIRBuilder->DbgGetType(GetPrimitiveType(BfTypeCode_Int64))); } else genericArgs.push_back(mBfIRBuilder->DbgGetType(genericArg)); } - + methodName += "<"; for (int i = 0; i < (int)methodInstance->mMethodInfoEx->mMethodGenericArguments.size(); i++) { @@ -20386,7 +20367,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, methodName += TypeToString(type); } methodName += ">"; - } + } if ((methodName.empty()) && (methodDeclaration != NULL)) { @@ -20410,39 +20391,38 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, methodState.mDIFile = mCurFilePosition.mFileInstance->mDIFile; // diFunction = mBfIRBuilder->DbgCreateMethod(funcScope, methodName, mangledName, methodState.mDIFile, -// defLine + 1, diFuncType, false, true, +// defLine + 1, diFuncType, false, true, // (methodInstance->mVirtualTableIdx != -1) ? llvm::dwarf::DW_VIRTUALITY_virtual : llvm::dwarf::DW_VIRTUALITY_none, // (methodInstance->mVirtualTableIdx != -1) ? methodInstance->DbgGetVirtualMethodNum() : 0, // nullptr, flags, IsOptimized(), llvmFunction, genericArgs, genericConstValueArgs); - + diFunction = mBfIRBuilder->DbgCreateMethod(funcScope, methodName, mangledName, methodState.mDIFile, - defLine + 1, diFuncType, false, true, + defLine + 1, diFuncType, false, true, llvm::dwarf::DW_VIRTUALITY_none, 0, BfIRMDNode(), flags, IsOptimized(), llvmFunction, genericArgs, genericConstValueArgs); - } else { methodState.mDIFile = mCurFilePosition.mFileInstance->mDIFile; } } - + ////////////////////////////////////////////////////////////////////////// // Head and Init get rolled into Entry afterwards. - + methodState.mIRFunction = methodInstance->mIRFunction; - methodState.mIRHeadBlock = mBfIRBuilder->CreateBlock("head", true); + methodState.mIRHeadBlock = mBfIRBuilder->CreateBlock("head", true); methodState.mIRInitBlock = mBfIRBuilder->CreateBlock("init", true); - + methodState.mIREntryBlock = mBfIRBuilder->CreateBlock("entry", true); methodState.mCurScope->mDIScope = diFunction; - auto llvmEntryBlock = methodState.mIREntryBlock; + auto llvmEntryBlock = methodState.mIREntryBlock; mBfIRBuilder->SetInsertPoint(llvmEntryBlock); - + if (methodDef->mName == "__MALFORMED") { auto newBlock = mBfIRBuilder->CreateBlock("malformed", true); @@ -20465,15 +20445,15 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, // Clear out DebugLoc - to mark the ".addr" code as part of prologue mBfIRBuilder->ClearDebugLocation(); - + bool isTypedPrimitiveFunc = mCurTypeInstance->IsTypedPrimitive() && (methodDef->mMethodType != BfMethodType_Ctor); int irParamCount = methodInstance->GetIRFunctionParamCount(this); if (methodInstance->GetImportKind() != BfImportKind_Import_Dynamic) { int localIdx = 0; - int argIdx = 0; - + int argIdx = 0; + Array splatAddrValues; for ( ; argIdx < irParamCount; localIdx++) @@ -20505,12 +20485,12 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, { paramVar->mIsReadOnly = true; } - - bool wantsAddr = (wantsDIVariables) || (!paramVar->mIsReadOnly) || + + bool wantsAddr = (wantsDIVariables) || (!paramVar->mIsReadOnly) || ((!mIsComptimeModule) && (paramVar->mResolvedType->GetLoweredType(BfTypeUsage_Parameter))); if (paramVar->mResolvedType->IsMethodRef()) - wantsAddr = false; + wantsAddr = false; // if ((methodDef->mHasAppend) && (argIdx == 1)) // { @@ -20519,7 +20499,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, // } if (paramVar->mIsSplat) - { + { auto prevInsert = mBfIRBuilder->GetInsertBlock(); mBfIRBuilder->SetInsertPoint(mCurMethodState->mIRHeadBlock); BfTypeUtils::SplatIterate([&](BfType* checkType) @@ -20540,7 +20520,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, mBfIRBuilder->SetInsertPoint(prevInsert); } else if (isThis) - { + { if (wantsAddr) { auto prevInsert = mBfIRBuilder->GetInsertBlock(); @@ -20557,7 +20537,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, wantPtr = true; if (wantPtr) - { + { thisAddrType = mBfIRBuilder->MapTypeInstPtr(thisType->ToTypeInstance()); } @@ -20586,7 +20566,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, alignSize = paramVar->mResolvedType->mAlign; } else - { + { paramVar->mHasLocalStructBacking = true; auto typeInst = paramVar->mResolvedType->ToTypeInstance(); if (typeInst != NULL) @@ -20604,16 +20584,16 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, mBfIRBuilder->SetName(allocaInst, paramVar->mName + ".addr"); mBfIRBuilder->SetAllocaAlignment(allocaInst, alignSize); paramVar->mAddr = allocaInst; - mBfIRBuilder->SetInsertPoint(prevInsert); + mBfIRBuilder->SetInsertPoint(prevInsert); if (WantsLifetimes()) mCurMethodState->mCurScope->mDeferredLifetimeEnds.push_back(allocaInst); } } else if (wantsAddr) - { + { auto allocaInst = CreateAlloca(paramVar->mResolvedType); mBfIRBuilder->SetName(allocaInst, paramVar->mName + ".addr"); - paramVar->mAddr = allocaInst; + paramVar->mAddr = allocaInst; } if (paramVar->mIsSplat) @@ -20634,18 +20614,18 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, argIdx++; } } - - if (methodDef->mBody != NULL) - UpdateSrcPos(methodDef->mBody); + + if (methodDef->mBody != NULL) + UpdateSrcPos(methodDef->mBody); else if ((methodDef->mDeclaringType != NULL) && (methodDef->mDeclaringType->GetRefNode() != NULL)) UpdateSrcPos(methodDef->mDeclaringType->GetRefNode()); else if (mCurTypeInstance->mTypeDef->mTypeDeclaration != NULL) UpdateSrcPos(mCurTypeInstance->mTypeDef->mTypeDeclaration); - + localIdx = 0; argIdx = 0; - - int splatAddrIdx = 0; + + int splatAddrIdx = 0; while (localIdx < (int)methodState.mLocals.size()) { if ((!mIsComptimeModule) && (argIdx == methodInstance->GetStructRetIdx())) @@ -20659,7 +20639,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, if (!paramVar->IsParam()) continue; if (paramVar->mCompositeCount != -1) - continue; + continue; bool isThis = ((curLocalIdx == 0) && (!mCurMethodInstance->mMethodDef->mIsStatic)); if ((isThis) && (thisType->IsValuelessType())) @@ -20678,7 +20658,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, { if ((mCurMethodState->mClosureState != NULL) && (mCurMethodState->mClosureState->mClosureType != NULL)) paramName = "__closure"; - + if ((paramVar->mResolvedType->IsValueType()) && (!paramVar->mIsSplat) && (!paramVar->mIsLowered)) { diType = mBfIRBuilder->DbgGetType(paramVar->mResolvedType); @@ -20703,7 +20683,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, diType = mBfIRBuilder->DbgCreateConstType(diType); } } - + if (!paramVar->mIsSplat) { if ((paramVar->mParamIdx >= 0) && (paramVar->mParamIdx < methodInstance->mDefaultValues.mSize)) @@ -20746,19 +20726,19 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, paramVar->mDbgVarInst = diVariable; } else if ((paramVar->mIsSplat) && (paramVar->mResolvedType->GetSplatCount() == 0)) - { + { // if ((mBfIRBuilder->HasDebugLocation()) && (wantsDIVariables)) // { -// // Only add this placeholder if we don't have any values +// // Only add this placeholder if we don't have any values // auto diVariable = mBfIRBuilder->DbgCreateAutoVariable(mCurMethodState->mCurScope->mDIScope, // paramName, mCurFilePosition.mFileInstance->mDIFile, mCurFilePosition.mCurLine, diType); // mBfIRBuilder->DbgInsertValueIntrinsic(GetConstValue(0), diVariable); // } } } - + bool isTypedPrimCtor = mCurTypeInstance->IsTypedPrimitive() && (methodDef->mMethodType == BfMethodType_Ctor); - + if ((!paramVar->mParamFailed) && (paramVar->mAddr)) { // Write our argument value into the .addr @@ -20766,13 +20746,13 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, if (paramVar->mIsSplat) { mBfIRBuilder->PopulateType(paramVar->mResolvedType); - // + // } else { bool handled = false; if (paramVar->mIsLowered) - { + { BfTypeCode loweredTypeCode = BfTypeCode_None; BfTypeCode loweredTypeCode2 = BfTypeCode_None; if (paramVar->mResolvedType->GetLoweredType(BfTypeUsage_Parameter, &loweredTypeCode, &loweredTypeCode2)) @@ -20785,11 +20765,11 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, { isTempTarget = true; targetAddr = CreateAlloca(GetPrimitiveType(BfTypeCode_Int8), true, NULL, GetConstValue(loweredSize)); - mBfIRBuilder->SetAllocaAlignment(targetAddr, - BF_MAX(paramVar->mResolvedType->mAlign, + mBfIRBuilder->SetAllocaAlignment(targetAddr, + BF_MAX(paramVar->mResolvedType->mAlign, BF_MAX(mBfIRBuilder->GetSize(loweredTypeCode), mBfIRBuilder->GetSize(loweredTypeCode2)))); } - + // We have a lowered type coming in, so we have to cast the .addr before storing auto primType = mBfIRBuilder->GetPrimitiveType(loweredTypeCode); auto primPtrType = mBfIRBuilder->GetPointerTo(primType); @@ -20806,7 +20786,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, else primPtrVal2 = mBfIRBuilder->CreateBitCast(mBfIRBuilder->CreateInBoundsGEP(primPtrVal, 1), primPtrType2); mBfIRBuilder->CreateStore(mBfIRBuilder->GetArgument(argIdx + 1), primPtrVal2); - } + } if (isTempTarget) { @@ -20829,14 +20809,14 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, mBfIRBuilder->CreateAlignedStore(paramVar->mValue, paramVar->mAddr, paramVar->mResolvedType->mAlign); } } - + if (methodDef->mBody != NULL) UpdateSrcPos(methodDef->mBody); else if (methodDef->mDeclaringType->mTypeDeclaration != NULL) UpdateSrcPos(methodDef->mDeclaringType->mTypeDeclaration); else if (methodDeclaration == NULL) UseDefaultSrcPos(); - + // Write our argument value into the .addr if (paramVar->mIsSplat) { @@ -20868,9 +20848,9 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, curArgIdx++; splatComponentIdx++; }; - + std::function _FinishSplatsIterate = [&](BfType* checkType, const StringImpl& name) - { + { if (checkType->IsStruct()) { auto checkTypeInstance = checkType->ToTypeInstance(); @@ -20883,13 +20863,13 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, { auto unionInnerType = checkTypeInstance->GetUnionInnerType(); if (!unionInnerType->IsValuelessType()) - { + { _FinishSplatsIterate(unionInnerType, name + "$u"); } if (checkTypeInstance->IsEnum()) { - auto dscrType = checkTypeInstance->GetDiscriminatorType(); + auto dscrType = checkTypeInstance->GetDiscriminatorType(); _FinishSplatsIterate(dscrType, name + "$d"); } } @@ -20913,7 +20893,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, // int implicitParamCount = methodInstance->GetImplicitParamCount(); // for (int implicitParamIdx = methodInstance->HasThis() ? -1 : 0; implicitParamIdx < implicitParamCount; implicitParamIdx++) // { -// auto paramType = methodInstance->GetParamType(implicitParamIdx); +// auto paramType = methodInstance->GetParamType(implicitParamIdx); // if (!paramType->IsValuelessType()) // _FinishSplats(paramType, name + "$m$" + methodInstance->GetParamName(implicitParamIdx)); // } @@ -20928,17 +20908,17 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, _FinishSplatsIterate(methodRefType->GetCaptureType(dataIdx), name + "$m$" + paramName); } else - { + { _FinishSplats(methodRefType->GetCaptureType(dataIdx), name + "$m$" + paramName); } } } else if (!checkType->IsValuelessType()) { - _FinishSplats(checkType, name); + _FinishSplats(checkType, name); } }; - + mBfIRBuilder->PopulateType(paramVar->mResolvedType); if (!paramVar->mConstValue) _FinishSplatsIterate(paramVar->mResolvedType, "$" + paramVar->mName); @@ -20948,12 +20928,11 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, if (diVariable) { if ((mBfIRBuilder->HasDebugLocation()) && (wantsDIVariables)) - { + { if (!paramVar->mAddr) { if ((!paramVar->mValue) || (paramVar->mValue.IsFake())) { - if ((!paramVar->mIsThis) && (mCompiler->mOptions.mToolsetType != BfToolsetType_GNU)) // DWARF chokes on this: { // We don't need to set the location for this @@ -20971,17 +20950,17 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, } if ((isThis) && (!paramVar->mIsSplat) && (paramVar->mAddr)) - { + { // We don't allow actually assignment to "this", so we just do a single load // Keep in mind we don't use the ACTUAL mValue value because that's a register, but // we need to store it in the stack frame for debugging purposes auto loadedThis = mBfIRBuilder->CreateAlignedLoad(paramVar->mAddr/*, "this"*/, paramVar->mResolvedType->mAlign); - mBfIRBuilder->ClearDebugLocation(loadedThis); + mBfIRBuilder->ClearDebugLocation(loadedThis); paramVar->mValue = loadedThis; } - + if ((wantsDIData) && (declareCall)) - mBfIRBuilder->UpdateDebugLocation(declareCall); + mBfIRBuilder->UpdateDebugLocation(declareCall); if (paramVar->mIsSplat) { @@ -21006,7 +20985,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, BF_ASSERT(splatAddrIdx == (int)splatAddrValues.size()); } } - + for (int varIdx = 0; varIdx < (int)mCurMethodState->mLocals.size(); varIdx++) { auto paramVar = mCurMethodState->mLocals[varIdx]; @@ -21023,10 +21002,10 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, // } if (paramVar->mResolvedType->IsValuelessType()) - { + { if ((mBfIRBuilder->HasDebugLocation()) && (wantsDIVariables) && (mCompiler->mOptions.mToolsetType != BfToolsetType_GNU)) // DWARF chokes on this: { - // Only add this placeholder if we don't have any values + // Only add this placeholder if we don't have any values auto diType = mBfIRBuilder->DbgGetType(paramVar->mResolvedType); auto diVariable = mBfIRBuilder->DbgCreateAutoVariable(mCurMethodState->mCurScope->mDIScope, paramVar->mName, mCurFilePosition.mFileInstance->mDIFile, mCurFilePosition.mCurLine, diType); @@ -21059,7 +21038,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, if ((methodDef != NULL) && (propertyDeclaration != NULL) && (propertyDeclaration->mExternSpecifier != NULL)) hasExternSpecifier = true; - // Allocate, clear, set classVData + // Allocate, clear, set classVData if ((methodDef->mMethodType == BfMethodType_Ctor) && (methodDef->mIsStatic)) { @@ -21069,7 +21048,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, { skipBody = true; skipEndChecks = true; - + if (HasExecutedOutput()) { // Clear out DebugLoc - to mark the ".addr" code as part of prologue @@ -21100,7 +21079,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, mBfIRBuilder->CreateRetVoid(); } else - { + { auto innerMethodDef = innerMethodInstance.mMethodInstance->mMethodDef; BF_ASSERT(innerMethodDef == methodDef); @@ -21112,7 +21091,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, BfIRValue thisValue = mBfIRBuilder->CreateInBoundsGEP(mCurMethodState->mLocals[0]->mValue, 0, 1); BfTypedValue innerVal(thisValue, innerType, true); if (boxedType->IsBoxedStructPtr()) - { + { innerVal = LoadValue(innerVal); innerVal = BfTypedValue(innerVal.mValue, innerType, true); } @@ -21149,12 +21128,12 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, } } } - + mCurMethodState->SetHadReturn(true); mCurMethodState->mLeftBlockUncond = true; } else if (methodDef->mMethodType == BfMethodType_CtorClear) - { + { SetIllegalSrcPos(); mBfIRBuilder->ClearDebugLocation(); PopulateType(mCurTypeInstance, BfPopulateType_Data); @@ -21179,7 +21158,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, int curSize = mCurTypeInstance->mInstSize; if (curSize > prevSize) - { + { auto int8PtrVal = mBfIRBuilder->CreateBitCast(thisVal.mValue, mBfIRBuilder->MapType(int8PtrType)); int8PtrVal = mBfIRBuilder->CreateInBoundsGEP(int8PtrVal, GetConstValue(prevSize)); mBfIRBuilder->CreateMemSet(int8PtrVal, GetConstValue8(0), GetConstValue(curSize - prevSize), GetConstValue(mCurTypeInstance->mInstAlign)); @@ -21227,7 +21206,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, EmitDtorBody(); skipBody = true; } - + if ((!mCurTypeInstance->IsBoxed()) && (methodDeclaration != NULL) && (methodDeclaration->mHadYield) && (methodDef->mBody != NULL)) { EmitIteratorBlock(skipBody); @@ -21245,11 +21224,11 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, mCurMethodState->mIgnoreObjectAccessCheck = true; if (customAttributes->Contains(mCompiler->mDisableChecksAttributeTypeDef)) mCurMethodState->mDisableChecks = true; - } - + } + if ((methodDef->mMethodType == BfMethodType_CtorNoBody) && (!methodDef->mIsStatic) && ((methodInstance->mChainType == BfMethodChainType_ChainHead) || (methodInstance->mChainType == BfMethodChainType_None))) - { + { // We chain even non-default ctors to the default ctors auto defaultCtor = methodInstance; if (defaultCtor->mChainType == BfMethodChainType_ChainHead) @@ -21266,17 +21245,17 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, if (methodDeclaration != NULL) { if (auto operatorDeclaration = BfNodeDynCast(methodDeclaration)) - { + { if (operatorDeclaration->mIsConvOperator) wantsRemoveBody = true; } } - bool isDllImport = false; + bool isDllImport = false; if ((importKind == BfImportKind_Import_Static) || (importKind == BfImportKind_Import_Dynamic)) { if (importStrNum != -1) - { + { if (importKind == BfImportKind_Import_Static) { if (!mImportFileNames.Contains(importStrNum)) @@ -21284,7 +21263,6 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, mImportFileNames.Add(importStrNum); } } - } } else if (methodInstance->GetImportKind() == BfImportKind_Import_Dynamic) @@ -21328,7 +21306,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, } else { - // Unfortunate DebugLoc shenanigans- + // Unfortunate DebugLoc shenanigans- // Our params get removed if we don't have any DebugLocs, but we don't want to actually be able to step into this method, // so we only set the loc on the CreateRet which gets inlined out mBfIRBuilder->SaveDebugLocation(); @@ -21353,21 +21331,21 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, mCurMethodState->SetHadReturn(true); mCurMethodState->mLeftBlockUncond = true; - } - else if (((methodDef->mName == BF_METHODNAME_ENUM_GETUNDERLYINGREF) || (methodDef->mName == BF_METHODNAME_ENUM_GETUNDERLYING)) && + } + else if (((methodDef->mName == BF_METHODNAME_ENUM_GETUNDERLYINGREF) || (methodDef->mName == BF_METHODNAME_ENUM_GETUNDERLYING)) && (mCurTypeInstance->IsEnum()) && (!mCurTypeInstance->IsBoxed())) { - BfIRValue ret; - // Unfortunate DebugLoc shenanigans- + BfIRValue ret; + // Unfortunate DebugLoc shenanigans- // Our params get removed if we don't have any DebugLocs, but we don't want to actually be able to step into this method, // so we only set the loc on the CreateRet which gets inlined out mBfIRBuilder->SaveDebugLocation(); mBfIRBuilder->ClearDebugLocation(); - BfIRValue fromBool; + BfIRValue fromBool; mBfIRBuilder->RestoreDebugLocation(); ret = mBfIRBuilder->CreateRet(GetThis().mValue); //ExtendLocalLifetimes(0); - EmitLifetimeEnds(&mCurMethodState->mHeadScope); + EmitLifetimeEnds(&mCurMethodState->mHeadScope); mCurMethodState->SetHadReturn(true); mCurMethodState->mLeftBlockUncond = true; @@ -21423,7 +21401,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, skipEndChecks = true; } else - { + { auto propertyDeclaration = methodDef->GetPropertyDeclaration(); if ((propertyDeclaration != NULL) && (!typeDef->HasAutoProperty(propertyDeclaration))) { @@ -21538,7 +21516,6 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, } else if (!mCurTypeInstance->IsObject()) { - } } else if (methodDef->mName == BF_METHODNAME_FIND_TLS_MEMBERS) @@ -21554,7 +21531,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, else if (!skipBody) { bool isEmptyBodied = BfNodeDynCast(methodDef->mBody) != NULL; - + bool wantsRetVal = true; if ((mIsComptimeModule) && (methodDef->mMethodType != BfMethodType_CtorCalcAppend)) wantsRetVal = false; @@ -21562,13 +21539,13 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, wantsRetVal = false; if ((!mCurMethodInstance->mReturnType->IsValuelessType()) && (!isEmptyBodied)) - { + { mBfIRBuilder->PopulateType(mCurMethodInstance->mReturnType); - + if ((!mIsComptimeModule) && (mCurMethodInstance->GetStructRetIdx() != -1)) { auto ptrType = CreatePointerType(mCurMethodInstance->mReturnType); - auto allocaInst = AllocLocalVariable(ptrType, "__return.addr", false); + auto allocaInst = AllocLocalVariable(ptrType, "__return.addr", false); auto storeInst = mBfIRBuilder->CreateAlignedStore(mBfIRBuilder->GetArgument(mCurMethodInstance->GetStructRetIdx()), allocaInst, mCurMethodInstance->mReturnType->mAlign); mBfIRBuilder->ClearDebugLocation(storeInst); mCurMethodState->mRetValAddr = allocaInst; @@ -21577,7 +21554,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, { auto allocaInst = AllocLocalVariable(mCurMethodInstance->mReturnType, "__return", false); mCurMethodState->mRetVal = BfTypedValue(allocaInst, mCurMethodInstance->mReturnType, true); - } + } } if (methodDef->mMethodType == BfMethodType_CtorCalcAppend) @@ -21610,7 +21587,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, isExpressionBody = true; } else if (auto propertyDeclaration = methodDef->GetPropertyDeclaration()) - { + { auto propertyMethodDeclaration = methodDef->GetPropertyMethodDeclaration(); if ((propertyMethodDeclaration != NULL) && (propertyMethodDeclaration->mFatArrowToken != NULL)) isExpressionBody = true; @@ -21656,7 +21633,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, VisitCodeBlock(bodyBlock); } else if (auto expressionBody = BfNodeDynCast(methodDef->mBody)) - { + { // if ((methodDef->mMethodType != BfMethodType_Normal) && (propertyDeclaration == NULL)) // { // BF_ASSERT(methodDeclaration->mFatArrowToken != NULL); @@ -21669,7 +21646,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, // { // Warn(0, "Using a 'void' return with an expression-bodied method isn't needed. Consider removing '=>' token", methodDeclaration->mFatArrowToken); // } - + BfEvalExprFlags exprEvalFlags = (BfEvalExprFlags)(BfEvalExprFlags_AllowRefExpr | BfEvalExprFlags_IsExpressionBody); if (expectingType->IsVoid()) { @@ -21686,7 +21663,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, if ((unspecializedMethodInstance != NULL) && (unspecializedMethodInstance->mReturnType->IsGenericParam())) wasReturnGenericParam = true; } - + // If we the void return was from a generic specialization, allow us to return a void result, // otherwise treat expression as though it must be a statement bool isStatement = expressionBody->VerifyIsStatement(mCompiler->mPassInstance, wasReturnGenericParam); @@ -21707,7 +21684,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, EmitReturn(retVal); } } - } + } } BF_ASSERT(mCurMethodState->mCurScope == &mCurMethodState->mHeadScope); @@ -21728,7 +21705,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, UseDefaultSrcPos(); if (methodDef->mMethodType == BfMethodType_CtorCalcAppend) - { + { if (mCurMethodState->mRetVal) { mCurMethodState->SetHadReturn(true); @@ -21741,12 +21718,12 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, if (!mCurMethodState->mHadReturn) { - // Clear off the stackallocs that have occurred after a scopeData break + // Clear off the stackallocs that have occurred after a scopeData break EmitDeferredScopeCalls(false, &mCurMethodState->mHeadScope, mCurMethodState->mIRExitBlock); } - + if (mCurMethodState->mIRExitBlock) - { + { for (auto preExitBlock : mCurMethodState->mHeadScope.mAtEndBlocks) mBfIRBuilder->MoveBlockToEnd(preExitBlock); @@ -21770,16 +21747,16 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, if (mCurMethodState->mIRExitBlock) { - if ((mCurMethodState->mRetVal) && + if ((mCurMethodState->mRetVal) && ((mIsComptimeModule) || (mCurMethodInstance->GetStructRetIdx() == -1))) - { + { auto loadedVal = mBfIRBuilder->CreateAlignedLoad(mCurMethodState->mRetVal.mValue, mCurMethodState->mRetVal.mType->mAlign); - - CreateReturn(loadedVal); - + + CreateReturn(loadedVal); + EmitLifetimeEnds(&mCurMethodState->mHeadScope); - - if (mCurMethodState->mDIRetVal) + + if (mCurMethodState->mDIRetVal) mBfIRBuilder->DbgLifetimeEnd(mCurMethodState->mDIRetVal); } else @@ -21790,7 +21767,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, if ((bodyBlock != NULL) && (bodyBlock->mCloseBrace != NULL)) UpdateSrcPos(bodyBlock->mCloseBrace); EmitEnsureInstructionAt(); - + if ((irParamCount == 0) && (!IsTargetingBeefBackend()) && (mCompiler->mOptions.mAllowHotSwapping)) { // This may be a case where we only emit 4 bytes, whereas we need 5 for a hot replace jump @@ -21799,13 +21776,12 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, } mBfIRBuilder->CreateRetVoid(); EmitLifetimeEnds(&mCurMethodState->mHeadScope); - + if (mCurMethodState->mDIRetVal) mBfIRBuilder->DbgLifetimeEnd(mCurMethodState->mDIRetVal); } } - - + if ((mCurMethodInstance->mReturnType == NULL) || (mCurMethodInstance->mReturnType->IsValuelessType())) { if ((!mCurMethodState->mHadReturn) && (!mCurMethodState->mIRExitBlock)) @@ -21818,14 +21794,14 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, mBfIRBuilder->CreateRetVoid(); } - } + } else - { + { if (!mCurMethodState->mHadReturn) { - auto refNode = mCurMethodInstance->mMethodDef->GetRefNode(); + auto refNode = mCurMethodInstance->mMethodDef->GetRefNode(); if (bodyBlock != NULL) - { + { if (bodyBlock->mCloseBrace != NULL) { BfAstNode* target = bodyBlock->mCloseBrace; @@ -21842,7 +21818,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, // It's possible to not have a closing brace if the method ends in an EOF AssertErrorState(); } - } + } } } @@ -21850,13 +21826,13 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, mBfIRBuilder->MergeBlockDown(mCurMethodState->mIRInitBlock, mCurMethodState->mIREntryBlock); mBfIRBuilder->MergeBlockDown(mCurMethodState->mIRHeadBlock, mCurMethodState->mIREntryBlock); - if (((mCurMethodInstance->mIsUnspecialized) /*|| (typeDef->mIsFunction)*/ || (mCurTypeInstance->IsUnspecializedType())) && + if (((mCurMethodInstance->mIsUnspecialized) /*|| (typeDef->mIsFunction)*/ || (mCurTypeInstance->IsUnspecializedType())) && (!mIsComptimeModule)) { // Don't keep instructions for unspecialized types - mBfIRBuilder->Func_DeleteBody(mCurMethodInstance->mIRFunction); - } - + mBfIRBuilder->Func_DeleteBody(mCurMethodInstance->mIRFunction); + } + // Avoid linking any internal funcs that were just supposed to be comptime-accessible /*if ((methodDef->mHasComptime) && (!mIsComptimeModule)) wantsRemoveBody = true;*/ @@ -21878,7 +21854,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, mBfIRBuilder->Func_DeleteBody(mCurMethodInstance->mIRFunction); } else if (wantsRemoveBody) - mBfIRBuilder->Func_DeleteBody(mCurMethodInstance->mIRFunction); + mBfIRBuilder->Func_DeleteBody(mCurMethodInstance->mIRFunction); // We don't want to hold on to pointers to LLVMFunctions of unspecialized types. // This allows us to delete the mScratchModule LLVM module without rebuilding all @@ -21889,7 +21865,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, BfLogSysM("ProcessMethod Clearing IRFunction: %p\n", methodInstance); methodInstance->mIRFunction = BfIRFunction(); } - + CheckAddFailType(); if (mHadBuildError) @@ -21903,8 +21879,8 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, mBfIRBuilder->SetActiveFunction(prevActiveFunction); if (methodState.mHotDataReferenceBuilder != NULL) - { - AddHotDataReferences(&hotDataReferenceBuilder); + { + AddHotDataReferences(&hotDataReferenceBuilder); } else { @@ -21918,15 +21894,15 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, { // If there's a prev method then pull its data into the main HotMethod. // This, in effect, removes the 'hotMethod' data and rebases 'prevMethod' - // over to the main HotMethod definition to keep the HotMethod address - // invariant + // over to the main HotMethod definition to keep the HotMethod address + // invariant for (auto ref : hotMethod->mReferences) ref->Deref(); - hotMethod->mReferences.Clear(); + hotMethod->mReferences.Clear(); BF_ASSERT(prevMethod->mRefCount == 1); hotMethod->mReferences = prevMethod->mReferences; - + if (hotMethod->mSrcTypeVersion != NULL) hotMethod->mSrcTypeVersion->Deref(); hotMethod->mSrcTypeVersion = prevMethod->mSrcTypeVersion; @@ -21937,7 +21913,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, prevMethod->mPrevVersion = NULL; prevMethod->Deref(); } - + hotMethod->Deref(); methodInstance->mHotMethod = NULL; } @@ -21945,9 +21921,9 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup, } String BfModule::GetLocalMethodName(const StringImpl& baseName, BfAstNode* anchorNode, BfMethodState* declMethodState, BfMixinState* declMixinState) -{ +{ String name; - + bool found = false; auto checkMethodState = mCurMethodState; while (checkMethodState != NULL) @@ -21961,15 +21937,15 @@ String BfModule::GetLocalMethodName(const StringImpl& baseName, BfAstNode* ancho break; } checkMethodState = checkMethodState->mPrevMethodState; - } + } if (!found) - name += mCurMethodInstance->mMethodDef->mName; + name += mCurMethodInstance->mMethodDef->mName; int prevSepPos = (int)name.LastIndexOf('$'); if (prevSepPos != -1) - { - name.RemoveToEnd(prevSepPos); + { + name.RemoveToEnd(prevSepPos); } name += "@"; @@ -22032,7 +22008,7 @@ BfMethodDef* BfModule::GetLocalMethodDef(BfLocalMethod* localMethod) auto _AllocDirectTypeRef = [&](BfType* type) { BfDirectTypeReference* directTypeRef = localMethod->mDirectTypeRefs.Alloc(); - directTypeRef->Init(type); + directTypeRef->Init(type); return directTypeRef; }; @@ -22040,7 +22016,7 @@ BfMethodDef* BfModule::GetLocalMethodDef(BfLocalMethod* localMethod) if (methodDeclaration != NULL) { body = methodDeclaration->mBody; - anchorNode = methodDeclaration->mOpenParen; + anchorNode = methodDeclaration->mOpenParen; } else { @@ -22069,15 +22045,15 @@ BfMethodDef* BfModule::GetLocalMethodDef(BfLocalMethod* localMethod) methodDef = defBuilder.CreateMethodDef(methodDeclaration, outerMethodDef); } else - { + { auto invokeMethod = localMethod->mLambdaInvokeMethodInstance; - + methodDef = new BfMethodDef(); methodDef->mName = localMethod->mMethodName; methodDef->mDeclaringType = mCurMethodInstance->mMethodDef->mDeclaringType; methodDef->mReturnTypeRef = _AllocDirectTypeRef(invokeMethod->mReturnType); methodDef->mBody = body; - + for (int paramIdx = 0; paramIdx < invokeMethod->GetParamCount(); paramIdx++) { auto paramType = invokeMethod->GetParamType(paramIdx); @@ -22086,7 +22062,7 @@ BfMethodDef* BfModule::GetLocalMethodDef(BfLocalMethod* localMethod) paramName = localMethod->mLambdaBindExpr->mParams[paramIdx]->ToString(); else paramName = invokeMethod->GetParamName(paramIdx); - + auto paramDef = new BfParameterDef(); paramDef->mTypeRef = _AllocDirectTypeRef(paramType); paramDef->mName = paramName; @@ -22110,7 +22086,7 @@ BfMethodDef* BfModule::GetLocalMethodDef(BfLocalMethod* localMethod) methodDef->mName = localMethod->mExpectedFullName; // methodDef->mName = GetLocalMethodName(methodDef->mName, anchorNode, declMethodState, declMixinState); - // + // // if (!localMethod->mExpectedFullName.IsEmpty()) // BF_ASSERT(methodDef->mName == localMethod->mExpectedFullName); @@ -22118,7 +22094,7 @@ BfMethodDef* BfModule::GetLocalMethodDef(BfLocalMethod* localMethod) methodDef->mIsLocalMethod = true; methodDef->mIsVirtual = false; localMethod->mMethodDef = methodDef; - + auto methodInstanceGroup = new BfMethodInstanceGroup(); localMethod->mMethodInstanceGroup = methodInstanceGroup; methodInstanceGroup->mMethodIdx = -1; @@ -22153,45 +22129,45 @@ BfModuleMethodInstance BfModule::GetLocalMethodInstance(BfLocalMethod* localMeth BP_ZONE_F("GetLocalMethodInstance %s", localMethod->mMethodName.c_str()); BfLogSysM("GetLocalMethodInstance %p\n", localMethod); - + auto rootMethodState = mCurMethodState->GetRootMethodState(); auto declMethodState = localMethod->mDeclMethodState; auto declMixinState = localMethod->mDeclMixinState; auto callerMethodState = mCurMethodState; - + auto typeInst = mCurTypeInstance; if (mCurMethodState->mMixinState != NULL) { typeInst = mCurMethodState->mMixinState->mMixinMethodInstance->GetOwner(); } - + auto methodDef = GetLocalMethodDef(localMethod); BfAstNode* body = NULL; - + auto methodDeclaration = localMethod->mMethodDeclaration; if (methodDeclaration != NULL) { - body = methodDeclaration->mBody; + body = methodDeclaration->mBody; } else { - body = localMethod->mLambdaBindExpr->mBody; + body = localMethod->mLambdaBindExpr->mBody; } - + bool hadConcreteInterfaceGenericArgument = false; BfTypeVector sanitizedMethodGenericArguments; - + // Ignore the outermost method's generic method arguments for the purpose of determining if we are the 'default' (ie: unspecialized) // version of this method for this pass through the outermost method int dependentGenericStartIdx = 0; if ((rootMethodState->mMethodInstance != NULL) && (rootMethodState->mMethodInstance->mMethodInfoEx != NULL)) dependentGenericStartIdx = (int)rootMethodState->mMethodInstance->mMethodInfoEx->mMethodGenericArguments.size(); - + BfMethodInstance* outerMethodInstance = mCurMethodInstance; - + if (methodGenericArguments.size() == 0) { if ((rootMethodState->mMethodInstance != NULL) && (rootMethodState->mMethodInstance->mMethodInfoEx != NULL)) @@ -22221,7 +22197,7 @@ BfModuleMethodInstance BfModule::GetLocalMethodInstance(BfLocalMethod* localMeth sanitizedMethodGenericArguments.push_back(genericArgType); } } - + bool wantPrematureMethodInstance = false; if (!force) { @@ -22229,12 +22205,12 @@ BfModuleMethodInstance BfModule::GetLocalMethodInstance(BfLocalMethod* localMeth } auto methodInstGroup = localMethod->mMethodInstanceGroup; - + bool isDefaultPass = true; BfTypeVector lookupMethodGenericArguments; for (int genericArgIdx = dependentGenericStartIdx; genericArgIdx < (int)methodGenericArguments.size(); genericArgIdx++) { - auto genericArgType = methodGenericArguments[genericArgIdx]; + auto genericArgType = methodGenericArguments[genericArgIdx]; BF_ASSERT(!genericArgType->IsRef()); lookupMethodGenericArguments.Add(genericArgType); @@ -22327,12 +22303,12 @@ BfModuleMethodInstance BfModule::GetLocalMethodInstance(BfLocalMethod* localMeth methodInfoEx->mMethodGenericArguments.push_back(genericParamType); } SetupMethodIdHash(methodInstance); - } + } auto _SetupMethodInstance = [&]() { BF_ASSERT(methodInstance->GetNumGenericParams() == 0); - + // Generic constraints for (int genericParamIdx = 0; genericParamIdx < (int)methodDef->mGenericParams.size(); genericParamIdx++) { @@ -22344,14 +22320,14 @@ BfModuleMethodInstance BfModule::GetLocalMethodInstance(BfLocalMethod* localMeth ////////////////////////////////////////////////////////////////////////// auto _VisitLambdaBody = [&]() - { + { if (localMethod->mDeclOnly) return; if (mCompiler->mCanceling) return; if (auto blockBody = BfNodeDynCast(body)) - { + { VisitCodeBlock(blockBody); } else if (auto bodyExpr = BfNodeDynCast(body)) @@ -22375,14 +22351,14 @@ BfModuleMethodInstance BfModule::GetLocalMethodInstance(BfLocalMethod* localMeth BfTypeInstance* outerClosure = NULL; if ((declMethodState->mClosureState != NULL) && (!declMethodState->mClosureState->mCapturing)) outerClosure = declMethodState->mClosureState->mClosureType; - - BfMethodState methodState; + + BfMethodState methodState; methodState.mPrevMethodState = declMethodState;//mCurMethodState; - BfIRFunctionType funcType; + BfIRFunctionType funcType; auto voidType = GetPrimitiveType(BfTypeCode_None); SizedArray paramTypes; - funcType = mBfIRBuilder->CreateFunctionType(mBfIRBuilder->MapType(voidType), paramTypes, methodInstance->IsVarArgs()); + funcType = mBfIRBuilder->CreateFunctionType(mBfIRBuilder->MapType(voidType), paramTypes, methodInstance->IsVarArgs()); mBfIRBuilder->SaveDebugLocation(); auto prevInsertBlock = mBfIRBuilder->GetInsertBlock(); @@ -22394,23 +22370,23 @@ BfModuleMethodInstance BfModule::GetLocalMethodInstance(BfLocalMethod* localMeth //TODO: Why did we do this? It can cause us to pull in local variables that don't belong to us... /*if (declMethodState->mDeferredLocalAssignData != NULL) deferredLocalAssignData.ExtendFrom(declMethodState->mDeferredLocalAssignData);*/ - SetAndRestoreValue prevMethodState(mCurMethodState, &methodState); + SetAndRestoreValue prevMethodState(mCurMethodState, &methodState); - methodState.mIRHeadBlock = mBfIRBuilder->CreateBlock("head", true); - methodState.mIRInitBlock = mBfIRBuilder->CreateBlock("init", true); - methodState.mIREntryBlock = mBfIRBuilder->CreateBlock("entry", true); + methodState.mIRHeadBlock = mBfIRBuilder->CreateBlock("head", true); + methodState.mIRInitBlock = mBfIRBuilder->CreateBlock("init", true); + methodState.mIREntryBlock = mBfIRBuilder->CreateBlock("entry", true); methodState.mCurScope->mDIScope = localMethod->mDeclDIScope; //declMethodState->mCurScope->mDIScope ; //methodState.mCurLocalVarId = declMethodState->mCurLocalVarId; methodState.mIRFunction = declMethodState->mIRFunction; methodState.mDeferredLocalAssignData = &deferredLocalAssignData; - + if (auto blockBody = BfNodeDynCast(body)) { methodState.mCurScope->mAstBlock = blockBody; methodState.mCurScope->mCloseNode = blockBody->mCloseBrace; } - mBfIRBuilder->SetInsertPoint(methodState.mIREntryBlock); + mBfIRBuilder->SetInsertPoint(methodState.mIREntryBlock); BfClosureState closureState; if (methodDef->mMethodType == BfMethodType_Mixin) @@ -22423,17 +22399,17 @@ BfModuleMethodInstance BfModule::GetLocalMethodInstance(BfLocalMethod* localMeth closureState.mReturnType = declMethodState->mMethodInstance->mReturnType; } } - + if (closureState.mReturnType == NULL) closureState.mReturnType = _SafeResolveTypeRef(methodDef->mReturnTypeRef); - closureState.mCapturing = true; + closureState.mCapturing = true; closureState.mLocalMethod = localMethod; closureState.mClosureInstanceInfo = methodInstance->mMethodInfoEx->mClosureInstanceInfo; closureState.mDeclaringMethodIsMutating = mCurMethodInstance->mMethodDef->mIsMutating; methodState.mClosureState = &closureState; closureState.mClosureType = outerClosure; - - int outerLocalsCount = (int)methodState.mLocals.size(); + + int outerLocalsCount = (int)methodState.mLocals.size(); if (!hadExistingMethodInstance) { @@ -22467,7 +22443,7 @@ BfModuleMethodInstance BfModule::GetLocalMethodInstance(BfLocalMethod* localMeth BF_ASSERT(methodInstance->mMethodInfoEx->mClosureInstanceInfo->mCaptureClosureState == NULL); - closureState.mCaptureStartAccessId = mCurMethodState->GetRootMethodState()->mCurAccessId; + closureState.mCaptureStartAccessId = mCurMethodState->GetRootMethodState()->mCurAccessId; methodInstance->mMethodInfoEx->mClosureInstanceInfo->mCaptureClosureState = &closureState; closureState.mClosureMethodDef = methodDef; @@ -22479,7 +22455,7 @@ BfModuleMethodInstance BfModule::GetLocalMethodInstance(BfLocalMethod* localMeth bool allowCapture = (methodDeclaration == NULL) || (methodDeclaration->mStaticSpecifier == NULL); if (wantsVisitBody) - { + { BP_ZONE("VisitLambdaBody"); // For generic methods, we capture for each specialization, so make sure mIsStatic is set to 'true' for @@ -22490,16 +22466,16 @@ BfModuleMethodInstance BfModule::GetLocalMethodInstance(BfLocalMethod* localMeth // Only generate errors once. Also there are some errors that will occur during this scanning phase // that will not occur during the actual lambda method generation, for example: returning a value // when our current method is a 'void' method. This shouldn't affect capture scanning since all - // our AST nodes will still be visited + // our AST nodes will still be visited SetAndRestoreValue ignoreError(mIgnoreErrors, true); - */ + */ SetAndRestoreValue prevMethodInstance(mCurMethodInstance, methodInstance); - + //SetAndRestoreValue wantsIgnoreWrites(mWantsISIgnoreWrites, true); mBfIRBuilder->SaveDebugLocation(); closureState.mCaptureVisitingBody = true; - - BF_ASSERT(methodInstance->mMethodInfoEx != NULL); + + BF_ASSERT(methodInstance->mMethodInfoEx != NULL); methodState.mGenericTypeBindings = &methodInstance->mMethodInfoEx->mGenericTypeBindings; methodState.mMethodInstance = methodInstance; @@ -22518,7 +22494,7 @@ BfModuleMethodInstance BfModule::GetLocalMethodInstance(BfLocalMethod* localMeth // Keep outs for being marked as assigned auto rootMethodState = mCurMethodState->GetRootMethodState(); - BfDeferredLocalAssignData deferredLocalAssignData(rootMethodState->mCurScope); + BfDeferredLocalAssignData deferredLocalAssignData(rootMethodState->mCurScope); deferredLocalAssignData.mVarIdBarrier = rootMethodState->mCurLocalVarId; SetAndRestoreValue prevDLA(rootMethodState->mDeferredLocalAssignData, &deferredLocalAssignData); if (!mIgnoreErrors) @@ -22543,23 +22519,23 @@ BfModuleMethodInstance BfModule::GetLocalMethodInstance(BfLocalMethod* localMeth // can be used by these methods (which will be necessary if any of these methods call us directly or indirectly) closureState.mClosureMethodDef = NULL; for (auto methodInstance : closureState.mLocalMethodRefs) - { + { GetLocalMethodInstance(methodInstance->mMethodInfoEx->mClosureInstanceInfo->mLocalMethod, BfTypeVector(), methodInstance); } methodInstance->mMethodInfoEx->mClosureInstanceInfo->mCaptureClosureState = NULL; prevIgnoreWrites.Restore(); - + std::multiset capturedEntries; - - // + + // { auto varMethodState = declMethodState; while (varMethodState != NULL) { if ((varMethodState->mMixinState != NULL) && (varMethodState->mMixinState->mLastTargetAccessId >= closureState.mCaptureStartAccessId)) - { + { BF_ASSERT(methodInstance->GetOwner() == varMethodState->mMixinState->mTarget.mType); methodDef->mIsStatic = false; if (rootMethodState->mMethodInstance->mMethodDef->mIsMutating) @@ -22645,23 +22621,23 @@ BfModuleMethodInstance BfModule::GetLocalMethodInstance(BfLocalMethod* localMeth } varMethodState = varMethodState->mPrevMethodState; - if ((varMethodState == NULL) || - (varMethodState->mMixinState != NULL) || + if ((varMethodState == NULL) || + (varMethodState->mMixinState != NULL) || ((varMethodState->mClosureState != NULL) && (!varMethodState->mClosureState->mCapturing))) break; } } - + for (auto& copyField : closureState.mReferencedOuterClosureMembers) - { + { auto fieldDef = copyField->GetFieldDef(); BfClosureCapturedEntry capturedEntry; - capturedEntry.mName = copyField->GetFieldDef()->mName; + capturedEntry.mName = copyField->GetFieldDef()->mName; capturedEntry.mType = copyField->mResolvedType; if (capturedEntry.mType->IsRef()) { // Keep by ref - } + } else if (!fieldDef->mIsReadOnly) { capturedEntry.mType = CreateRefType(capturedEntry.mType); @@ -22673,15 +22649,15 @@ BfModuleMethodInstance BfModule::GetLocalMethodInstance(BfLocalMethod* localMeth int captureIdx = 0; for (auto& capturedEntry : capturedEntries) { - methodInstance->mMethodInfoEx->mClosureInstanceInfo->mCaptureEntries.Add(capturedEntry); - } + methodInstance->mMethodInfoEx->mClosureInstanceInfo->mCaptureEntries.Add(capturedEntry); + } /*if (isDefaultPass) - { + { // Insert captured members a params at the start. If we added at the end then it would screw up varargs methods int captureIdx = 0; for (auto& capturedEntry : capturedEntries) - { + { methodInstance->mClosureInstanceInfo->mCaptureNodes.Add(BfNodeDynCast(capturedEntry.mNameNode)); BfParameterDef* paramDef = new BfParameterDef(); @@ -22719,7 +22695,7 @@ BfModuleMethodInstance BfModule::GetLocalMethodInstance(BfLocalMethod* localMeth methodInstance->mDisallowCalling = false; BfLogSysM("LocalMethod %p UndoingDeclaration %p\n", localMethod, methodInstance); - } + } auto declareModule = this; SetAndRestoreValue prevMethodInstance(declareModule->mCurMethodInstance, methodInstance); @@ -22728,15 +22704,15 @@ BfModuleMethodInstance BfModule::GetLocalMethodInstance(BfLocalMethod* localMeth methodInstance->mDeclModule = declareModule; _SetupMethodInstance(); BfLogSysM("LocalMethod %p DoMethodDeclaration %p\n", localMethod, methodInstance); - declareModule->DoMethodDeclaration(localMethod->mMethodDef->GetMethodDeclaration(), false, false); - + declareModule->DoMethodDeclaration(localMethod->mMethodDef->GetMethodDeclaration(), false, false); + closureState.mReturnType = methodInstance->mReturnType; mCompiler->mStats.mMethodsQueued++; mCompiler->UpdateCompletion(); declareModule->mIncompleteMethodCount++; - mCompiler->mStats.mMethodsProcessed++; + mCompiler->mStats.mMethodsProcessed++; if (!methodInstance->mIsReified) - mCompiler->mStats.mUnreifiedMethodsProcessed++; + mCompiler->mStats.mUnreifiedMethodsProcessed++; auto deferMethodState = rootMethodState; @@ -22808,9 +22784,9 @@ BfModuleMethodInstance BfModule::GetLocalMethodInstance(BfLocalMethod* localMeth } } } - + checkMethodState = checkMethodState->mPrevMethodState; - } + } } return BfModuleMethodInstance(methodInstance); @@ -22833,7 +22809,7 @@ int BfModule::GetLocalInferrableGenericArgCount(BfMethodDef* methodDef) BfLocalMethod* callerLocalMethod = mCurMethodInstance->mMethodInfoEx->mClosureInstanceInfo->mLocalMethod; if (callerLocalMethod == NULL) - return rootMethodGenericParamCount; + return rootMethodGenericParamCount; BfLocalMethod* calledLocalMethod = NULL; rootMethodState->mLocalMethodCache.TryGetValue(methodDef->mName, &calledLocalMethod); @@ -22843,18 +22819,18 @@ int BfModule::GetLocalInferrableGenericArgCount(BfMethodDef* methodDef) if (calledLocalMethod->mOuterLocalMethod == callerLocalMethod) return (int)callerLocalMethod->mMethodDef->mGenericParams.size(); callerLocalMethod = calledLocalMethod->mOuterLocalMethod; - } + } return rootMethodGenericParamCount; } void BfModule::GetMethodCustomAttributes(BfMethodInstance* methodInstance) { auto methodDef = methodInstance->mMethodDef; - - auto customAttributes = methodInstance->GetCustomAttributes(); + + auto customAttributes = methodInstance->GetCustomAttributes(); if (customAttributes != NULL) return; - + auto methodDeclaration = methodDef->GetMethodDeclaration(); auto propertyMethodDeclaration = methodDef->GetPropertyMethodDeclaration(); auto typeInstance = methodInstance->GetOwner(); @@ -22892,10 +22868,10 @@ void BfModule::GetMethodCustomAttributes(BfMethodInstance* methodInstance) methodInstance->mMethodInfoEx->mMethodCustomAttributes->mCustomAttributes = methodInstance->mMethodInstanceGroup->mDefaultCustomAttributes; methodInstance->mMethodInstanceGroup->mDefaultCustomAttributes = NULL; } - else - methodInstance->mMethodInfoEx->mMethodCustomAttributes->mCustomAttributes = GetCustomAttributes(attributeDirective, attrTarget); + else + methodInstance->mMethodInfoEx->mMethodCustomAttributes->mCustomAttributes = GetCustomAttributes(attributeDirective, attrTarget); } - + if ((propertyMethodDeclaration != NULL) && (propertyMethodDeclaration->mPropertyDeclaration->mAttributes != NULL) && ((attrTarget & BfAttributeTargets_Property) == 0)) { if (methodInstance->GetMethodInfoEx()->mMethodCustomAttributes != NULL) @@ -22908,7 +22884,7 @@ void BfModule::GetMethodCustomAttributes(BfMethodInstance* methodInstance) methodInstance->mMethodInfoEx->mMethodCustomAttributes->mCustomAttributes = GetCustomAttributes(propertyMethodDeclaration->mPropertyDeclaration->mAttributes, BfAttributeTargets_Property); } } - + customAttributes = methodInstance->GetCustomAttributes(); if (customAttributes == NULL) { @@ -22955,7 +22931,7 @@ void BfModule::GetMethodCustomAttributes(BfMethodInstance* methodInstance) } } } - + auto delegateInfo = typeInstance->GetDelegateInfo(); if ((delegateInfo != NULL) && (methodInstance->mMethodDef->mMethodType == BfMethodType_Normal) && (methodInstance->mMethodDef->mName == "Invoke")) methodInstance->mCallingConvention = delegateInfo->mCallingConvention; @@ -23042,7 +23018,7 @@ void BfModule::SetupIRFunction(BfMethodInstance* methodInstance, StringImpl& man if (takeover) mCurMethodInstance->mIRFunction = prevFunc; - + if (!mCurMethodInstance->mIRFunction) { BfLogSysM("Function collision from inner override erased prevFunc %p: %d\n", methodInstance, prevFunc.mId); @@ -23059,7 +23035,7 @@ void BfModule::SetupIRFunction(BfMethodInstance* methodInstance, StringImpl& man { // We can have a collision of names when we have generic methods that differ only in // their constraints, but they should only collide in their unspecialized form - // since only one will be chosen for a given concrete type + // since only one will be chosen for a given concrete type if (!mIsComptimeModule) mCurMethodInstance->mMangleWithIdx = true; mangledName.Clear(); @@ -23123,14 +23099,14 @@ void BfModule::SetupIRFunction(BfMethodInstance* methodInstance, StringImpl& man if (!methodInstance->mIRFunction) { BfIRFunction func; - bool wantsLLVMFunc = ((!typeInstance->IsUnspecializedType() || (mIsComptimeModule)) && + bool wantsLLVMFunc = ((!typeInstance->IsUnspecializedType() || (mIsComptimeModule)) && (!methodDef->IsEmptyPartial())) && (funcType); /*if (mCurTypeInstance->mTypeDef->mName->ToString() == "ClassA") { if (!mIsReified) wantsLLVMFunc = false; - }*/ + }*/ if (wantsLLVMFunc) { @@ -23167,55 +23143,55 @@ void BfModule::CheckHotMethod(BfMethodInstance* methodInstance, const StringImpl { if (methodInstance->mHotMethod != NULL) return; - + if ((mCompiler->mOptions.mAllowHotSwapping) && (!methodInstance->mIsUnspecialized)) { auto srcTypeInst = methodInstance->GetOwner(); if (srcTypeInst->mHotTypeData == NULL) return; - + StringT<128> mangledName = inMangledName; if (mangledName.IsEmpty()) BfMangler::Mangle(mangledName, mCompiler->GetMangleKind(), methodInstance); - + // We always keep the current primary method at the same address BfHotMethod* hotMethod; BfHotMethod** hotMethodPtr; if (mCompiler->mHotData->mMethodMap.TryAdd(mangledName, NULL, &hotMethodPtr)) - { + { hotMethod = new BfHotMethod(); *hotMethodPtr = hotMethod; - hotMethod->mRefCount = 1; + hotMethod->mRefCount = 1; hotMethod->mFlags = (BfHotDepDataFlags)(hotMethod->mFlags | BfHotDepDataFlag_IsBound); #ifdef BF_DBG_HOTMETHOD_IDX static int sMethodIdx = 0; hotMethod->mMethodIdx = sMethodIdx++; #endif - + BfLogSysM("HotMethodData %p created for method %p %s - %s\n", hotMethod, methodInstance, MethodToString(methodInstance).c_str(), mangledName.c_str()); } else - { + { hotMethod = *hotMethodPtr; if ((hotMethod->mFlags & BfHotDepDataFlag_IsBound) != 0) { // This is a duplicate mangled name - we link to this new entry via a 'BfHotDupMethod' auto prevHotMethod = *hotMethodPtr; - - hotMethod = new BfHotMethod(); + + hotMethod = new BfHotMethod(); hotMethod->mFlags = (BfHotDepDataFlags)(hotMethod->mFlags | BfHotDepDataFlag_IsBound); - + BfHotDupMethod* hotDupMethod = new BfHotDupMethod(hotMethod); hotDupMethod->mRefCount++; prevHotMethod->mReferences.Add(hotDupMethod); - prevHotMethod->mFlags = (BfHotDepDataFlags)(hotMethod->mFlags | BfHotDepDataFlag_HasDup); + prevHotMethod->mFlags = (BfHotDepDataFlags)(hotMethod->mFlags | BfHotDepDataFlag_HasDup); BfLogSysM("HotMethodData %p (duplicate of %p) created for method %p %s - %s\n", hotMethod, prevHotMethod, methodInstance, MethodToString(methodInstance).c_str(), mangledName.c_str()); } else if (mCompiler->IsHotCompile()) { - // Link the previous version into the mPrevVersion + // Link the previous version into the mPrevVersion BfHotMethod* prevMethod = new BfHotMethod(); prevMethod->mRefCount = 1; prevMethod->mPrevVersion = hotMethod->mPrevVersion; @@ -23232,20 +23208,20 @@ void BfModule::CheckHotMethod(BfMethodInstance* methodInstance, const StringImpl BfLogSysM("HotMethodData %p created for prevmethod of %p for method %p %s\n", prevMethod, hotMethod, methodInstance, MethodToString(methodInstance).c_str()); } else - { + { BfLogSysM("HotMethodData %p used for method %p %s - %s\n", hotMethod, methodInstance, MethodToString(methodInstance).c_str(), mangledName.c_str()); hotMethod->Clear(true); hotMethod->mFlags = (BfHotDepDataFlags)(hotMethod->mFlags | BfHotDepDataFlag_IsBound); } - } + } if (methodInstance->mIsClosure) { hotMethod->mFlags = (BfHotDepDataFlags)(hotMethod->mFlags | BfHotDepDataFlag_RetainMethodWithoutBinding); } - + hotMethod->mSrcTypeVersion = srcTypeInst->mHotTypeData->GetLatestVersion(); - hotMethod->mSrcTypeVersion->mRefCount++; + hotMethod->mSrcTypeVersion->mRefCount++; hotMethod->mRefCount++; #ifdef BF_DBG_HOTMETHOD_NAME hotMethod->mMangledName = mangledName; @@ -23253,7 +23229,7 @@ void BfModule::CheckHotMethod(BfMethodInstance* methodInstance, const StringImpl if ((methodInstance->mMethodInstanceGroup->IsImplemented()) && (!IsHotCompile())) hotMethod->mFlags = (BfHotDepDataFlags)(hotMethod->mFlags | BfHotDepDataFlag_IsOriginalBuild); - methodInstance->mHotMethod = hotMethod; + methodInstance->mHotMethod = hotMethod; } } @@ -23329,7 +23305,7 @@ void BfModule::StartMethodDeclaration(BfMethodInstance* methodInstance, BfMethod methodInstance->mIsUnspecializedVariation = true; methodInstance->mIsUnspecialized = true; } - + if (methodInstance->mIsUnspecializedVariation) BF_ASSERT(methodInstance->mIsUnspecialized); @@ -23347,46 +23323,46 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool { BF_ASSERT((mCompiler->mCeMachine == NULL) || (!mCompiler->mCeMachine->mDbgPaused)); - BP_ZONE("BfModule::DoMethodDeclaration"); + BP_ZONE("BfModule::DoMethodDeclaration"); // We could trigger a DoMethodDeclaration from a const resolver or other location, so we reset it here // to effectively make mIgnoreWrites method-scoped SetAndRestoreValue prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, mWantsIRIgnoreWrites || mCurMethodInstance->mIsUnspecialized || mCurTypeInstance->mResolvingVarField); - SetAndRestoreValue prevIsCapturingMethodMatchInfo; + SetAndRestoreValue prevIsCapturingMethodMatchInfo; SetAndRestoreValue prevAllowLockYield(mContext->mAllowLockYield, false); BfTypeState typeState(mCurTypeInstance); SetAndRestoreValue prevTypeState(mContext->mCurTypeState, &typeState); - - if (mCompiler->IsAutocomplete()) + + if (mCompiler->IsAutocomplete()) prevIsCapturingMethodMatchInfo.Init(mCompiler->mResolvePassData->mAutoComplete->mIsCapturingMethodMatchInfo, false); - + if (mCurMethodInstance->mMethodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_NoDecl_AwaitingReference) mCurMethodInstance->mMethodInstanceGroup->mOnDemandKind = BfMethodOnDemandKind_Decl_AwaitingReference; BfMethodState methodState; SetAndRestoreValue prevMethodState(mCurMethodState, &methodState); methodState.mTempKind = BfMethodState::TempKind_Static; - + defer({ mCurMethodInstance->mHasBeenDeclared = true; }); // If we are doing this then we may end up creating methods when var types are unknown still, failing on splat/zero-sized info BF_ASSERT((!mCurTypeInstance->mResolvingVarField) || (mBfIRBuilder->mIgnoreWrites)); bool ignoreWrites = mBfIRBuilder->mIgnoreWrites; - + // if ((!isTemporaryFunc) && (mCurTypeInstance->mDefineState < BfTypeDefineState_Defined)) // { // BF_ASSERT(mContext->mResolvingVarField); // isTemporaryFunc = true; // } - + if ((mAwaitingInitFinish) && (!mBfIRBuilder->mIgnoreWrites)) FinishInit(); auto typeInstance = mCurTypeInstance; - auto typeDef = typeInstance->mTypeDef; - auto methodDef = mCurMethodInstance->mMethodDef; - + auto typeDef = typeInstance->mTypeDef; + auto methodDef = mCurMethodInstance->mMethodDef; + BF_ASSERT(methodDef->mName != "__ASSERTNAME"); if (methodDef->mName == "__FATALERRORNAME") BFMODULE_FATAL(this, "__FATALERRORNAME"); @@ -23394,16 +23370,16 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool StackOverflow(); if (typeInstance->IsClosure()) - { + { if (methodDef->mName == "Invoke") return; } - auto methodInstance = mCurMethodInstance; + auto methodInstance = mCurMethodInstance; if ((methodInstance->IsSpecializedByAutoCompleteMethod()) || (mCurTypeInstance->IsFunction())) addToWorkList = false; - + if (!methodInstance->mHasStartedDeclaration) StartMethodDeclaration(methodInstance, prevMethodState.mPrevVal); @@ -23439,8 +23415,8 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool else genericParam->mExternType = GetPrimitiveType(BfTypeCode_Var); } - - ResolveGenericParamConstraints(genericParam, methodInstance->mIsUnspecialized, &deferredResolveTypes); + + ResolveGenericParamConstraints(genericParam, methodInstance->mIsUnspecialized, &deferredResolveTypes); if (genericParamIdx < (int)methodDef->mGenericParams.size()) { @@ -23534,16 +23510,16 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool continue; if (!CompareMethodSignatures(defaultMethod, methodInstance)) continue; - + autoComplete->SetDefinitionLocation(defaultMethod->mMethodDef->GetRefNode(), true); autoComplete->mDefType = typeInstance->mTypeDef; - autoComplete->mDefMethod = defaultMethod->mMethodDef; + autoComplete->mDefMethod = defaultMethod->mMethodDef; } } } } } - + bool reportErrors = true; if ((mCompiler->mResolvePassData != NULL) && (mCompiler->mResolvePassData->mAutoComplete != NULL)) reportErrors = true; @@ -23562,7 +23538,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool { BfAstNode* refNode = methodDeclaration; if (refNode == NULL) - { + { // Whatever caused this ctor to be generated should have caused another failure // But that failure might not be generated until the ctor is generated } @@ -23594,10 +23570,10 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool if ((((methodInstance->mComptimeFlags & BfComptimeFlag_ConstEval) != 0) || (methodInstance->mIsAutocompleteMethod)) && (methodDef->mReturnTypeRef->IsA())) - resolvedReturnType = GetPrimitiveType(BfTypeCode_Var); + resolvedReturnType = GetPrimitiveType(BfTypeCode_Var); else - resolvedReturnType = ResolveTypeRef(methodDef->mReturnTypeRef, BfPopulateType_Declaration, flags); - + resolvedReturnType = ResolveTypeRef(methodDef->mReturnTypeRef, BfPopulateType_Declaration, flags); + if (resolvedReturnType == NULL) resolvedReturnType = GetPrimitiveType(BfTypeCode_Var); @@ -23612,16 +23588,16 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool { resolvedReturnType = ResolveTypeDef(mSystem->mTypeVoid); } - - BF_ASSERT(resolvedReturnType != NULL); - mCurMethodInstance->mReturnType = resolvedReturnType; - - //TODO: We used to NOT add the return value dependency for specialized methods, but when we have types that are + + BF_ASSERT(resolvedReturnType != NULL); + mCurMethodInstance->mReturnType = resolvedReturnType; + + //TODO: We used to NOT add the return value dependency for specialized methods, but when we have types that are // specialized based on the method's generic param then they can get deleted if no one else has referred to them (yet) //if (!methodInstance->IsSpecializedGenericMethod()) - + AddDependency(resolvedReturnType, typeInstance, BfDependencyMap::DependencyFlag_ParamOrReturnValue); - + if (methodDef->mExplicitInterface != NULL) { auto autoComplete = mCompiler->GetAutoComplete(); @@ -23633,7 +23609,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool if (explicitType != NULL) explicitInterface = explicitType->ToTypeInstance(); if (explicitInterface != NULL) - { + { mCurMethodInstance->GetMethodInfoEx()->mExplicitInterface = explicitInterface->ToTypeInstance(); if (autoComplete != NULL) { @@ -23644,7 +23620,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool dotToken = methodDeclaration->mExplicitInterfaceDotToken; nameNode = methodDeclaration->mNameNode; } - + autoComplete->CheckExplicitInterface(explicitInterface, dotToken, nameNode); } } @@ -23654,7 +23630,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool for (auto ifaceInst : typeInstance->mInterfaces) interfaceFound |= ifaceInst.mInterfaceType == mCurMethodInstance->mMethodInfoEx->mExplicitInterface; if ((!interfaceFound) && (!typeInstance->mTypeFailed)) - { + { if (methodDef->mMethodDeclaration != NULL) Fail("Containing class has not declared to implement this interface", methodDef->mMethodDeclaration); else @@ -23662,13 +23638,13 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool // For property decls, we should have already given the error during type population if (mCompiler->mRevision == 1) AssertErrorState(); - } + } } } } bool isThisStruct = mCurTypeInstance->IsStruct(); - BfType* thisType = NULL; + BfType* thisType = NULL; if ((!methodDef->mIsStatic) && (!mCurTypeInstance->IsValuelessType())) { @@ -23677,31 +23653,30 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool thisType = mCurTypeInstance; if (thisType == NULL) return; - + if ((thisType->IsSplattable()) && (!methodDef->HasNoThisSplat())) { - BfTypeUtils::SplatIterate([&](BfType* checkType) - { - PopulateType(checkType, BfPopulateType_Data); + BfTypeUtils::SplatIterate([&](BfType* checkType) + { + PopulateType(checkType, BfPopulateType_Data); }, thisType); - } + } } else { thisType = mCurTypeInstance; - PopulateType(thisType, BfPopulateType_Declaration); - } + PopulateType(thisType, BfPopulateType_Declaration); + } } - + int implicitParamCount = 0; if ((mCurMethodInstance->mMethodInfoEx != NULL) && (mCurMethodInstance->mMethodInfoEx->mClosureInstanceInfo != NULL)) implicitParamCount = (int)methodInstance->mMethodInfoEx->mClosureInstanceInfo->mCaptureEntries.size(); methodInstance->mMethodDef->mParams.Reserve((int)methodDef->mParams.size()); - bool hadDelegateParams = false; - bool hadParams = false; + bool hadParams = false; for (int paramIdx = 0; paramIdx < (int)methodDef->mParams.size() + implicitParamCount; paramIdx++) { BfClosureCapturedEntry* closureCaptureEntry = NULL; @@ -23752,15 +23727,15 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool } else if ((paramDef->mTypeRef != NULL) && (paramDef->mTypeRef->IsA())) { - if (methodDef->mMethodType != BfMethodType_Mixin) + if (methodDef->mMethodType != BfMethodType_Mixin) { Fail("Cannot declare var parameters", paramDef->mTypeRef); resolvedParamType = mContext->mBfObjectType; } else resolvedParamType = GetPrimitiveType(BfTypeCode_Var); - } - + } + BfType* unresolvedParamType = resolvedParamType; bool wasGenericParam = false; if (resolvedParamType == NULL) @@ -23783,12 +23758,12 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool BF_ASSERT(boxedType->mElementType->ToTypeInstance()->mModule->mHadBuildError || mContext->mFailTypes.Contains(boxedType->mElementType->ToTypeInstance())); } } - + BF_ASSERT(!resolvedParamType->IsDeleting()); if (!methodInstance->IsSpecializedGenericMethod()) AddDependency(resolvedParamType, typeInstance, BfDependencyMap::DependencyFlag_ParamOrReturnValue); - PopulateType(resolvedParamType, BfPopulateType_Declaration); + PopulateType(resolvedParamType, BfPopulateType_Declaration); AddDependency(resolvedParamType, mCurTypeInstance, BfDependencyMap::DependencyFlag_LocalUsage); @@ -23802,7 +23777,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool refNode = paramDef->mParamDeclaration->mModToken; Fail("Cannot specify a default value for a 'params' parameter", refNode); } - + BfTypedValue defaultValue; if (resolvedParamType->IsConstExprValue()) { @@ -23871,7 +23846,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool } if ((paramDef != NULL) && (paramDef->mParamKind == BfParamKind_Params)) - { + { bool addParams = true; bool isValid = false; @@ -23884,7 +23859,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool } else if (resolvedParamType->IsArray()) { - // Array is the 'normal' params type + // Array is the 'normal' params type isValid = true; } else if (resolvedParamType->IsSizedArray()) @@ -23912,11 +23887,11 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool auto paramType = invokeMethodInstance->GetParamType(delegateParamIdx); if (!methodInstance->IsSpecializedGenericMethod()) - AddDependency(paramType, mCurTypeInstance, BfDependencyMap::DependencyFlag_ParamOrReturnValue); + AddDependency(paramType, mCurTypeInstance, BfDependencyMap::DependencyFlag_ParamOrReturnValue); } isValid = true; addParams = false; - } + } else if (resolvedParamType->IsGenericParam()) { auto genericParamInstance = GetGenericParamInstance((BfGenericParamType*)resolvedParamType); @@ -23925,16 +23900,16 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool auto typeInstConstraint = genericParamInstance->mTypeConstraint->ToTypeInstance(); if ((genericParamInstance->mTypeConstraint->IsArray()) || (genericParamInstance->mTypeConstraint->IsSizedArray())) { - BfMethodParam methodParam; + BfMethodParam methodParam; methodParam.mResolvedType = resolvedParamType; - methodParam.mParamDefIdx = paramDefIdx; + methodParam.mParamDefIdx = paramDefIdx; mCurMethodInstance->mParams.Add(methodParam); isValid = true; } else if ((genericParamInstance->mTypeConstraint->IsDelegate()) || (genericParamInstance->mTypeConstraint->IsFunction()) || ((genericParamInstance != NULL) && (typeInstConstraint != NULL) && ((typeInstConstraint->IsInstanceOf(mCompiler->mDelegateTypeDef)) || (typeInstConstraint->IsInstanceOf(mCompiler->mFunctionTypeDef))))) - { + { mCurMethodInstance->mHadGenericDelegateParams = true; isValid = true; addParams = false; @@ -23952,7 +23927,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool addParams = false; } } - + if (!isValid) { Fail("Parameters with 'params' specifiers can only be used for array, span, delegate, or function types", paramDef->mParamDeclaration->mModToken); @@ -23962,22 +23937,22 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool if ((addParams) && (resolvedParamType != NULL)) { - BfMethodParam methodParam; + BfMethodParam methodParam; methodParam.mResolvedType = resolvedParamType; - methodParam.mParamDefIdx = paramDefIdx; + methodParam.mParamDefIdx = paramDefIdx; mCurMethodInstance->mParams.push_back(methodParam); } if (paramDefIdx < (int)methodDef->mParams.size() - 1) - { + { Fail("Only the last parameter can specify 'params'", paramDef->mParamDeclaration->mModToken); } } else { - BfMethodParam methodParam; + BfMethodParam methodParam; methodParam.mResolvedType = resolvedParamType; - methodParam.mParamDefIdx = paramDefIdx; + methodParam.mParamDefIdx = paramDefIdx; mCurMethodInstance->mParams.Add(methodParam); } } @@ -23990,7 +23965,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool { usedNames.Add(methodParam->mName); } - + for (auto& methodParam : mCurMethodInstance->mParams) { if ((methodParam.mParamDefIdx != -1) && (methodParam.mDelegateParamIdx == 0)) @@ -24004,7 +23979,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool for (auto& methodParam : mCurMethodInstance->mParams) { if (methodParam.mDelegateParamIdx != -1) - { + { if (usedParamDefIdx[methodParam.mParamDefIdx] > 1) methodParam.mDelegateParamNameCombine = true; BfMethodInstance* invokeMethodInstance = methodParam.GetDelegateParamInvoke(); @@ -24016,10 +23991,10 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool } int argIdx = 0; - PopulateType(methodInstance->mReturnType, BfPopulateType_Data); + PopulateType(methodInstance->mReturnType, BfPopulateType_Data); if ((!methodDef->mIsStatic) && (!methodDef->mHasExplicitThis)) { - int thisIdx = methodDef->mHasExplicitThis ? 0 : -1; + int thisIdx = methodDef->mHasExplicitThis ? 0 : -1; auto thisType = methodInstance->GetOwner(); if (methodInstance->GetParamIsSplat(thisIdx)) argIdx += methodInstance->GetParamType(thisIdx)->GetSplatCount(); @@ -24062,7 +24037,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool bool isSplat = false; auto checkTypeInstance = checkType->ToTypeInstance(); if ((checkTypeInstance != NULL) && (checkTypeInstance->mIsCRepr)) - isSplat = true; + isSplat = true; int splatCount = checkType->GetSplatCount(); if (checkArgIdx + splatCount <= mCompiler->mOptions.mMaxSplatRegs) isSplat = true; @@ -24076,7 +24051,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool else if (!checkType->IsValuelessType()) { BfTypeCode loweredTypeCode = BfTypeCode_None; - BfTypeCode loweredTypeCode2 = BfTypeCode_None; + BfTypeCode loweredTypeCode2 = BfTypeCode_None; if (!mIsComptimeModule) checkType->GetLoweredType(BfTypeUsage_Parameter, &loweredTypeCode, &loweredTypeCode2); argIdx++; @@ -24084,8 +24059,8 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool argIdx++; continue; } - } - + } + argIdx++; } @@ -24103,7 +24078,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool { if (auto autoCtorDecl = BfNodeDynCast(methodDeclaration)) { - // + // } else AssertParseErrorState(); @@ -24121,7 +24096,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool if (((methodInstance->mReturnType == typeInstance) && (methodInstance->GetParamType(0) == typeInstance->GetUnderlyingType())) || ((methodInstance->mReturnType == typeInstance->GetUnderlyingType()) && (methodInstance->GetParamType(0) == typeInstance))) { - isError = false; + isError = false; } } } @@ -24149,10 +24124,10 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool BF_ASSERT((actualParamCount == defaultMethodInstance->mParams.size() - defaultImplicitParamCount) || (defaultMethodInstance->mHadGenericDelegateParams)); mCurMethodInstance->mHadGenericDelegateParams = defaultMethodInstance->mHadGenericDelegateParams; - + int paramIdx = 0; int defaultParamIdx = 0; - + while (true) { bool isDone = paramIdx + implicitParamCount >= (int)methodInstance->mParams.size(); @@ -24162,8 +24137,8 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool { paramIdx++; continue; - } - + } + if ((!isDefaultDone) && (defaultMethodInstance->mParams[defaultParamIdx + defaultImplicitParamCount].mDelegateParamIdx >= 0)) { defaultParamIdx++; @@ -24172,22 +24147,22 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool if ((isDone) || (isDefaultDone)) { - // If we have generic delegate params, it's possible we will fail constraints later if we specialize with an invalid type, but we can't allow that + // If we have generic delegate params, it's possible we will fail constraints later if we specialize with an invalid type, but we can't allow that // to cause us to throw an assertion in the declaration here if ((!defaultMethodInstance->mHadGenericDelegateParams) && (!methodInstance->mHasFailed) && (!defaultMethodInstance->mHasFailed)) BF_ASSERT((isDone) && (isDefaultDone)); break; - } + } BfType* paramType = defaultMethodInstance->mParams[defaultParamIdx + defaultImplicitParamCount].mResolvedType; if (paramType->IsRef()) paramType = paramType->GetUnderlyingType(); - methodInstance->mParams[paramIdx + implicitParamCount].mWasGenericParam = paramType->IsGenericParam(); + methodInstance->mParams[paramIdx + implicitParamCount].mWasGenericParam = paramType->IsGenericParam(); paramIdx++; defaultParamIdx++; - } + } } StringT<4096> mangledName; @@ -24197,7 +24172,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool { auto paramType = methodInstance->GetParamType(paramIdx); if (paramType->IsComposite()) - PopulateType(paramType, BfPopulateType_Data); + PopulateType(paramType, BfPopulateType_Data); if (!methodInstance->IsParamSkipped(paramIdx)) { @@ -24210,7 +24185,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool PopulateType(paramType, BfPopulateType_Declaration); } } - } + } // Only process method in default unspecialized mode, not in variations if (methodInstance->mIsUnspecializedVariation) @@ -24239,7 +24214,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool auto func = methodInstance->mIRFunction; // if (methodInstance->mIsReified) -// CheckHotMethod(methodInstance, mangledName); +// CheckHotMethod(methodInstance, mangledName); for (auto& param : methodInstance->mParams) { @@ -24247,10 +24222,10 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool } BfLogSysM("DoMethodDeclaration %s Module: %p Type: %p MethodInst: %p Reified: %d Unspecialized: %d IRFunction: %d MethodId:%llx\n", mangledName.c_str(), this, mCurTypeInstance, methodInstance, methodInstance->mIsReified, mCurTypeInstance->IsUnspecializedType(), methodInstance->mIRFunction.mId, methodInstance->mIdHash); - - SizedArray diParams; - diParams.push_back(mBfIRBuilder->DbgGetType(resolvedReturnType)); - + + SizedArray diParams; + diParams.push_back(mBfIRBuilder->DbgGetType(resolvedReturnType)); + if ((!methodDef->mIsStatic) && (typeDef->mIsStatic) && (methodDef->mMethodDeclaration != NULL)) { //CS0708 @@ -24291,7 +24266,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool else if (methodDef->mMethodType == BfMethodType_Dtor) Warn(0, "Unnecessary 'mut' specifier, destructors are implicitly mutating", mutSpecifier); } - + if (isTemporaryFunc) { // This handles temporary methods for autocomplete types @@ -24301,13 +24276,13 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool return; // Bail out early for autocomplete pass } - //TODO: We used to have this (this != mContext->mExternalFuncModule) check, but it caused us to keep around + //TODO: We used to have this (this != mContext->mExternalFuncModule) check, but it caused us to keep around // an invalid mFuncRefernce (which came from GetMethodInstanceAtIdx) which later got remapped by the // autocompleter. Why did we have this check anyway? /*if ((typeInstance->mContext != mContext) && (!methodDef->IsEmptyPartial())) { AddMethodReference(methodInstance); - mFuncReferences[methodInstance] = func; + mFuncReferences[methodInstance] = func; BfLogSysM("Adding func reference (DoMethodDeclaration). Module:%p MethodInst:%p LLVMFunc:%p\n", this, methodInstance, func); }*/ @@ -24321,14 +24296,14 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool mFuncReferences[methodInstance] = func; } } - + if (methodInstance->mMethodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_NotSet) { methodInstance->mMethodInstanceGroup->mOnDemandKind = BfMethodOnDemandKind_Decl_AwaitingDecl; auto owningModule = methodInstance->GetOwner()->mModule; if (!owningModule->mIsScratchModule) owningModule->mOnDemandMethodCount++; - VerifyOnDemandMethods(); + VerifyOnDemandMethods(); } bool wasAwaitingDecl = methodInstance->mMethodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_Decl_AwaitingDecl; @@ -24338,11 +24313,11 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool if (addToWorkList) { if ((!methodDef->mIsAbstract) && (!methodInstance->mIgnoreBody)) - { + { AddMethodToWorkList(methodInstance); } else - { + { BfLogSysM("DoMethodDeclaration ignoring method body %d %d %d\n", hasExternSpecifier, methodDef->mIsAbstract, methodInstance->mIgnoreBody); methodInstance->mIgnoreBody = true; @@ -24352,13 +24327,13 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool methodInstance->mIRFunction = BfIRFunction(); } } - } + } else { //BF_ASSERT(methodInstance->mMethodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_Decl_AwaitingReference); } - - if ((!methodInstance->IsSpecializedGenericMethodOrType()) && (!mCurTypeInstance->IsBoxed()) && + + if ((!methodInstance->IsSpecializedGenericMethodOrType()) && (!mCurTypeInstance->IsBoxed()) && (!methodDef->mIsLocalMethod) && (!CheckDefineMemberProtection(methodDef->mProtection, methodInstance->mReturnType)) && (!methodDef->mReturnTypeRef->IsTemporary())) @@ -24377,9 +24352,9 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool Fail(StrFormat("Inconsistent accessibility: return type '%s' is less accessible than method '%s'", TypeToString(methodInstance->mReturnType).c_str(), MethodToString(methodInstance).c_str()), methodDef->mReturnTypeRef, true); - } + } } - + if (typeInstance->IsInterface()) { if (methodDef->mMethodType == BfMethodType_Ctor) @@ -24390,7 +24365,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool { if (methodDef->mProtection != BfProtection_Public) //TODO: MAKE AN ERROR Warn(0, "Protection specifiers can only be used with interface methods containing a default implementation body", methodDeclaration->mProtectionSpecifier); - if ((methodDeclaration->mVirtualSpecifier != NULL) && + if ((methodDeclaration->mVirtualSpecifier != NULL) && (methodDeclaration->mVirtualSpecifier->mToken != BfToken_Abstract) && (methodDeclaration->mVirtualSpecifier->mToken != BfToken_Concrete)) //TODO: MAKE AN ERROR Warn(0, "Virtual specifiers can only be used with interface methods containing a default implementation body", methodDeclaration->mVirtualSpecifier); @@ -24418,7 +24393,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool BfMemberSetEntry* entry = NULL; if (typeDef->mMethodSet.TryGet(BfMemberSetEntry(methodDef), &entry)) nextMethod = (BfMethodDef*)entry->mMemberDef; - + while (nextMethod != NULL) { auto checkMethod = nextMethod; @@ -24427,7 +24402,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool if (checkMethod == methodDef) continue; - auto checkMethodInstance = typeInstance->mMethodInstanceGroups[checkMethod->mIdx].mDefault; + auto checkMethodInstance = typeInstance->mMethodInstanceGroups[checkMethod->mIdx].mDefault; if (checkMethodInstance == NULL) { if ((methodDef->mDeclaringType->IsExtension()) && (!checkMethod->mDeclaringType->IsExtension())) @@ -24548,15 +24523,15 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool } } - // Virtual methods give their error while slotting - if ((!typeInstance->IsBoxed()) && (!methodDef->mIsVirtual) && (methodDef->mProtection != BfProtection_Private) && + // Virtual methods give their error while slotting + if ((!typeInstance->IsBoxed()) && (!methodDef->mIsVirtual) && (methodDef->mProtection != BfProtection_Private) && (!methodDef->mIsLocalMethod) && - (!methodInstance->mIsForeignMethodDef) && (typeInstance->mBaseType != NULL) && + (!methodInstance->mIsForeignMethodDef) && (typeInstance->mBaseType != NULL) && (methodDef->mMethodType == BfMethodType_Normal) && (methodDef->mMethodDeclaration != NULL)) - { + { auto baseType = typeInstance->mBaseType; while (baseType != NULL) - { + { auto baseTypeDef = baseType->mTypeDef; baseTypeDef->PopulateMemberSets(); BfMethodDef* checkMethod = NULL; @@ -24565,13 +24540,13 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool checkMethod = (BfMethodDef*)entry->mMemberDef; while (checkMethod != NULL) - { + { if (checkMethod->mMethodDeclaration == NULL) { checkMethod = checkMethod->mNextWithSameName; continue; } - + if (baseType->mMethodInstanceGroups.size() == 0) { BF_ASSERT(baseType->IsIncomplete() && mCompiler->IsAutocomplete()); @@ -24591,7 +24566,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool auto checkMethodInstance = GetRawMethodInstanceAtIdx(baseType, checkMethod->mIdx); if (checkMethodInstance != NULL) - { + { if ((checkMethodInstance->GetExplicitInterface() == methodInstance->GetExplicitInterface()) && (checkMethod->mProtection != BfProtection_Private) && (CompareMethodSignatures(checkMethodInstance, mCurMethodInstance))) @@ -24624,7 +24599,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool auto propertyDeclaration = methodDef->GetPropertyDeclaration(); auto tokenNode = (propertyDeclaration != NULL) ? propertyDeclaration->mNewSpecifier : methodDeclaration->mNewSpecifier; - Fail("Method does not hide an inherited member. The 'new' keyword is not required", tokenNode, true); + Fail("Method does not hide an inherited member. The 'new' keyword is not required", tokenNode, true); } } } @@ -24650,7 +24625,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool } mCompiler->mStats.mMethodDeclarations++; - mCompiler->UpdateCompletion(); + mCompiler->UpdateCompletion(); } void BfModule::UniqueSlotVirtualMethod(BfMethodInstance* methodInstance) @@ -24660,14 +24635,14 @@ void BfModule::UniqueSlotVirtualMethod(BfMethodInstance* methodInstance) auto typeInstance = mCurTypeInstance; auto methodDef = methodInstance->mMethodDef; - int virtualMethodMatchIdx = -1; + int virtualMethodMatchIdx = -1; if (typeInstance->mHotTypeData != NULL) - { + { if (typeInstance->mHotTypeData->mVTableOrigLength != -1) { BF_ASSERT(mCompiler->IsHotCompile()); - // In the 'normal' case we'd assert that mIsOverride is false, but if we can't find the declaring method then we + // In the 'normal' case we'd assert that mIsOverride is false, but if we can't find the declaring method then we // may slot this override anyway (?) int vTableStart = 0; @@ -24701,15 +24676,15 @@ void BfModule::UniqueSlotVirtualMethod(BfMethodInstance* methodInstance) } if (virtualMethodMatchIdx == -1) - { + { methodInstance->mVirtualTableIdx = typeInstance->mVirtualMethodTableSize++; BfVirtualMethodEntry entry = { methodInstance, methodInstance }; - typeInstance->mVirtualMethodTable.push_back(entry); + typeInstance->mVirtualMethodTable.push_back(entry); } } void BfModule::CompareDeclTypes(BfTypeInstance* typeInst, BfTypeDef* newDeclType, BfTypeDef* prevDeclType, bool& isBetter, bool& isWorse) -{ +{ if ((!prevDeclType->IsExtension()) && (newDeclType->IsExtension())) { // When we provide an extension override in the same project a root type override @@ -24719,7 +24694,7 @@ void BfModule::CompareDeclTypes(BfTypeInstance* typeInst, BfTypeDef* newDeclType else { isBetter = newDeclType->mProject->ContainsReference(prevDeclType->mProject); - isWorse = prevDeclType->mProject->ContainsReference(newDeclType->mProject); + isWorse = prevDeclType->mProject->ContainsReference(newDeclType->mProject); } if ((isBetter == isWorse) && (typeInst != NULL) && (newDeclType->IsExtension()) && (prevDeclType->IsExtension())) @@ -24751,11 +24726,11 @@ void BfModule::CompareDeclTypes(BfTypeInstance* typeInst, BfTypeDef* newDeclType bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityContext* ambiguityContext) { - BP_ZONE("BfModule::SlotVirtualMethod"); + BP_ZONE("BfModule::SlotVirtualMethod"); if (mCurTypeInstance->IsUnspecializedTypeVariation()) return false; - + auto _AddVirtualDecl = [&](BfMethodInstance* declMethodInstance) { if (!mCompiler->mOptions.mAllowHotSwapping) @@ -24763,8 +24738,8 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo if ((!methodInstance->mIsReified) || (!declMethodInstance->mIsReified)) return; - if (methodInstance->mHotMethod == NULL) - CheckHotMethod(methodInstance, ""); + if (methodInstance->mHotMethod == NULL) + CheckHotMethod(methodInstance, ""); if (methodInstance->mHotMethod == NULL) return; @@ -24774,12 +24749,12 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo CheckHotMethod(declMethodInstance, ""); auto virtualDecl = mCompiler->mHotData->GetVirtualDeclaration(declMethodInstance->mHotMethod); virtualDecl->mRefCount++; - methodInstance->mHotMethod->mReferences.Add(virtualDecl); + methodInstance->mHotMethod->mReferences.Add(virtualDecl); }; auto typeInstance = mCurTypeInstance; auto typeDef = typeInstance->mTypeDef; - auto methodDef = methodInstance->mMethodDef; + auto methodDef = methodInstance->mMethodDef; auto methodDeclaration = methodDef->GetMethodDeclaration(); auto propertyDeclaration = methodDef->GetPropertyDeclaration(); auto propertyMethodDeclaration = methodDef->GetPropertyMethodDeclaration(); @@ -24790,7 +24765,7 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo BfAstNode* declaringNode = methodDeclaration; if (propertyMethodDeclaration != NULL) declaringNode = propertyMethodDeclaration->mNameNode; - + BfMethodInstance* methodOverriden = NULL; bool usedMethod = false; @@ -24815,13 +24790,13 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo checkBase = checkBase->mBaseType; if (typeInstance->IsValueType()) - { + { if (typeInstance->mBaseType == NULL) return false; // It's actually ValueType // We allow structs to override object methods for when they get boxed, so just ignore 'override' keyword until it gets boxed if (!methodDef->mIsOverride) - { + { Fail("Structs cannot have virtual methods", virtualToken, true); return false; } @@ -24834,7 +24809,7 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo } int virtualMethodMatchIdx = -1; - bool hadHidingError = false; + bool hadHidingError = false; BfMethodInstance* bestOverrideMethodInstance = NULL; BfMethodInstance* ambiguousOverrideMethodInstance = NULL; @@ -24956,10 +24931,10 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo } //TODO: - if ((checkBase != NULL) + if ((checkBase != NULL) && (false) ) - { + { auto& baseVirtualMethodTable = checkBase->mVirtualMethodTable; for (int checkMethodIdx = (int) baseVirtualMethodTable.size() - 1; checkMethodIdx >= 0; checkMethodIdx--) { @@ -24976,9 +24951,9 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo AssertErrorState(); continue; } - + if ((baseMethodInstance != NULL) && (CompareMethodSignatures(baseMethodInstance, methodInstance))) - { + { if (methodDef->mIsOverride) { BfMethodInstance* checkMethodInstance; @@ -24986,9 +24961,9 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo checkMethodInstance = checkBase->mVirtualMethodTable[checkMethodIdx].mDeclaringMethod; else checkMethodInstance = typeInstance->mVirtualMethodTable[checkMethodIdx].mDeclaringMethod; - + auto newDeclType = checkMethodInstance->mMethodDef->mDeclaringType; - + if (!typeInstance->IsTypeMemberAccessible(newDeclType, methodDef->mDeclaringType->mProject)) continue; @@ -25006,7 +24981,7 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo { if (isWorse) continue; - ambiguousOverrideMethodInstance = NULL; + ambiguousOverrideMethodInstance = NULL; } } @@ -25076,7 +25051,7 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo if ((baseVirtualMethodInstance != methodInstance) && (methodDef->mIsOverride)) { if (baseVirtualMethodInstance->mReturnType != methodInstance->mReturnType) - { + { BfTypeReference* returnTypeRef; if (auto propertyDeclaration = methodDef->GetPropertyDeclaration()) { @@ -25176,13 +25151,13 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo setMethodInstance->mVirtualTableIdx = virtualMethodMatchIdx; auto& implMethodRef = typeInstance->mVirtualMethodTable[virtualMethodMatchIdx].mImplementingMethod; - if ((!mCompiler->mIsResolveOnly) && (implMethodRef.mMethodNum >= 0) && + if ((!mCompiler->mIsResolveOnly) && (implMethodRef.mMethodNum >= 0) && (implMethodRef.mTypeInstance == typeInstance) && (methodInstance->GetOwner() == typeInstance)) { auto prevImplMethodInstance = (BfMethodInstance*)implMethodRef; if (prevImplMethodInstance->mMethodDef->mDeclaringType->mProject != methodInstance->mMethodDef->mDeclaringType->mProject) { - // We may need to have to previous method reified when we must re-slot in another project during vdata creation + // We may need to have to previous method reified when we must re-slot in another project during vdata creation BfReifyMethodDependency dep; dep.mDepMethod = typeInstance->mVirtualMethodTable[virtualMethodMatchIdx].mDeclaringMethod; dep.mMethodIdx = implMethodRef.mMethodNum; @@ -25201,29 +25176,29 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo } } } - + typeInstance->mVirtualMethodTable[virtualMethodMatchIdx].mImplementingMethod = setMethodInstance; } } - + if (methodOverriden != NULL) { - CheckOverridenMethod(methodInstance, methodOverriden); + CheckOverridenMethod(methodInstance, methodOverriden); } - } + } } if ((virtualMethodMatchIdx == -1) && ((ambiguityContext == NULL) || (!ambiguityContext->mIsReslotting))) { if (methodDef->mIsOverride) - { + { BfTokenNode* overrideToken = NULL; if (auto propertyMethodDeclaration = methodDef->GetPropertyMethodDeclaration()) overrideToken = propertyMethodDeclaration->mPropertyDeclaration->mVirtualSpecifier; else if (auto methodDeclaration = methodDef->GetMethodDeclaration()) overrideToken = methodDeclaration->mVirtualSpecifier; if (overrideToken != NULL) - { + { if ((propertyDeclaration != NULL) && (propertyDeclaration->mNameNode != NULL) && ((methodDef->mMethodType == BfMethodType_PropertyGetter) || (methodDef->mMethodType == BfMethodType_PropertySetter))) Fail(StrFormat("No suitable method found to override for '%s.%s'", @@ -25231,7 +25206,7 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo else Fail("No suitable method found to override", overrideToken, true); } - + return usedMethod; } @@ -25240,9 +25215,9 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo else usedMethod = true; - if (typeInstance->IsValueType()) + if (typeInstance->IsValueType()) return usedMethod; - } + } bool foundInterface = false; bool hadAnyMatch = false; @@ -25253,7 +25228,7 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo auto ifaceInst = ifaceTypeInst.mInterfaceType; if (ifaceInst->IsIncomplete()) PopulateType(ifaceInst, BfPopulateType_DataAndMethods); - int startIdx = ifaceTypeInst.mStartInterfaceTableIdx; + int startIdx = ifaceTypeInst.mStartInterfaceTableIdx; int iMethodCount = (int)ifaceInst->mMethodInstanceGroups.size(); // See "bidirectional" rules mentioned in DoTypeInstanceMethodProcessing @@ -25266,7 +25241,7 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo bool hadMatch = false; BfMethodInstance* hadNameMatch = NULL; BfType* expectedReturnType = NULL; - + bool showedError = false; // We go through our VTable looking for NULL entries within the interface sections @@ -25288,7 +25263,7 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo BfTypeInterfaceMethodEntry* interfaceMethodEntry = &typeInstance->mInterfaceMethodTable[iTableIdx]; auto iMethodPtr = &interfaceMethodEntry->mMethodRef; bool storeIFaceMethod = false; - + if ((mCompiler->mPassInstance->HasFailed()) && (iMethodIdx >= (int)ifaceInst->mMethodInstanceGroups.size())) { checkMethodDef = checkMethodDef->mNextWithSameName; @@ -25307,7 +25282,7 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo if (iMethodInst->mMethodDef->mName == methodInstance->mMethodDef->mName) hadNameMatch = iMethodInst; - bool doesMethodSignatureMatch = CompareMethodSignatures(iMethodInst, methodInstance); + bool doesMethodSignatureMatch = CompareMethodSignatures(iMethodInst, methodInstance); if ((!doesMethodSignatureMatch) && (interfaceMethodEntry->mMethodRef.IsNull())) { doesMethodSignatureMatch = IsCompatibleInterfaceMethod(iMethodInst, methodInstance); @@ -25327,20 +25302,20 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo } } } - + if (doesMethodSignatureMatch) - { + { usedMethod = true; hadMatch = true; hadAnyMatch = true; storeIFaceMethod = true; - + if ((iMethodPtr->mKind != BfMethodRefKind_AmbiguousRef) && (iMethodPtr->mTypeInstance != NULL)) - { + { auto prevMethod = (BfMethodInstance*)*iMethodPtr; if ((mCompiler->mIsResolveOnly) && (prevMethod == methodInstance) && (!mIsComptimeModule)) { - // When autocompletion regenerates a single method body but not the whole type then + // When autocompletion regenerates a single method body but not the whole type then // we will see ourselves in the vtable already return usedMethod; } @@ -25367,21 +25342,21 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo ambiguityContext->Remove(~iTableIdx); storeIFaceMethod = isBetter; } - } + } } - + if (storeIFaceMethod) { if (methodInstance->GetNumGenericParams() != 0) _AddVirtualDecl(iMethodInst); *iMethodPtr = methodInstance; } - + checkMethodDef = checkMethodDef->mNextWithSameName; - } + } if ((methodInstance->mMethodInfoEx != NULL) && (methodInstance->mMethodInfoEx->mExplicitInterface == ifaceInst) && (!hadMatch) && (!showedError)) - { + { if (expectedReturnType != NULL) Fail(StrFormat("Wrong return type, expected '%s'", TypeToString(expectedReturnType).c_str()), declaringNode, true); else if (hadNameMatch != NULL) @@ -25402,7 +25377,7 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo name = "this[]"; else if (propertyDecl->mNameNode != NULL) propertyDecl->mNameNode->ToString(name); - + Fail(StrFormat("Property '%s' %s accessor not defined in interface '%s'", name.c_str(), (methodDef->mMethodType == BfMethodType_PropertyGetter) ? "get" : "set", TypeToString(ifaceInst).c_str()), methodDef->GetRefNode(), true); } @@ -25454,13 +25429,13 @@ void BfModule::CheckOverridenMethod(BfMethodInstance* methodInstance, BfMethodIn } bool BfModule::SlotInterfaceMethod(BfMethodInstance* methodInstance) -{ +{ auto typeInstance = mCurTypeInstance; auto methodDef = methodInstance->mMethodDef; if (methodDef->mMethodType == BfMethodType_Ctor) return true; - + bool foundOverride = false; if ((methodDef->mBody == NULL) && (methodDef->mProtection == BfProtection_Private)) @@ -25479,8 +25454,8 @@ bool BfModule::SlotInterfaceMethod(BfMethodInstance* methodInstance) Fail("Explicit interfaces can only be specified for overrides in interface declarations", methodDef->GetMethodDeclaration()->mExplicitInterface); } - BfAstNode* declaringNode = methodDef->GetRefNode(); - + BfAstNode* declaringNode = methodDef->GetRefNode(); + for (auto& ifaceTypeInst : typeInstance->mInterfaces) { auto ifaceInst = ifaceTypeInst.mInterfaceType; @@ -25524,7 +25499,7 @@ bool BfModule::SlotInterfaceMethod(BfMethodInstance* methodInstance) Warn(BfWarning_CS0114_MethodHidesInherited, StrFormat("Method hides inherited member from '%s'. Use the 'new' keyword if hiding was intentional.", TypeToString(ifaceInst).c_str()), declaringNode); } } - } + } } if ((methodDef->mIsOverride) && (!foundOverride)) @@ -25547,14 +25522,13 @@ bool BfModule::SlotInterfaceMethod(BfMethodInstance* methodInstance) continue; if (ifaceMethod->mMethodDef->mDeclaringType == methodInstance->mMethodDef->mDeclaringType) continue; - + if (CompareMethodSignatures(ifaceMethod, methodInstance)) { - foundOverride = true; + foundOverride = true; } } - // for (int methodIdx = 0; methodIdx < typeInstance->mMethodInstanceGroups.size(); methodIdx++) // { // auto ifaceMethod = typeInstance->mMethodInstanceGroups[methodIdx].mDefault; @@ -25562,10 +25536,10 @@ bool BfModule::SlotInterfaceMethod(BfMethodInstance* methodInstance) // continue; // if (ifaceMethod->mMethodDef->mDeclaringType == methodInstance->mMethodDef->mDeclaringType) // continue; -// +// // if (CompareMethodSignatures(ifaceMethod, methodInstance)) // { -// foundOverride = true; +// foundOverride = true; // } // } } @@ -25616,11 +25590,11 @@ void BfModule::SetMethodDependency(BfMethodInstance* methodInstance) wantMinDepth = mCurTypeInstance->mDependencyMap.mMinDependDepth + 1; if ((mCurMethodInstance != NULL) && (mCurMethodInstance->mMethodInfoEx != NULL) && (mCurMethodInstance->mMethodInfoEx->mMinDependDepth != -1)) - { + { int wantTypeMinDepth = mCurMethodInstance->mMethodInfoEx->mMinDependDepth + 1; if ((wantMinDepth == -1) || (wantTypeMinDepth < wantMinDepth)) wantMinDepth = wantTypeMinDepth; - } + } if ((methodInstance->mMethodInfoEx->mMinDependDepth == -1) || (wantMinDepth < methodInstance->mMethodInfoEx->mMinDependDepth)) methodInstance->mMethodInfoEx->mMinDependDepth = wantMinDepth; @@ -25639,7 +25613,7 @@ void BfModule::DbgFinish() String markerName; BfIRValue linkMarker; - + if (mBfIRBuilder->DbgHasInfo()) { bool needForceLinking = false; @@ -25648,7 +25622,7 @@ void BfModule::DbgFinish() bool hasConfirmedReference = false; for (auto& methodInstGroup : ownedType->mMethodInstanceGroups) { - if ((methodInstGroup.IsImplemented()) && (methodInstGroup.mDefault != NULL) && + if ((methodInstGroup.IsImplemented()) && (methodInstGroup.mDefault != NULL) && (!methodInstGroup.mDefault->mMethodDef->mIsStatic) && (methodInstGroup.mDefault->mIsReified) && (!methodInstGroup.mDefault->mAlwaysInline) && ((methodInstGroup.mOnDemandKind == BfMethodOnDemandKind_AlwaysInclude) || (methodInstGroup.mOnDemandKind == BfMethodOnDemandKind_Referenced)) && (methodInstGroup.mHasEmittedReference)) @@ -25664,7 +25638,7 @@ void BfModule::DbgFinish() { BfMethodState methodState; SetAndRestoreValue prevMethodState(mCurMethodState, &methodState); - methodState.mTempKind = BfMethodState::TempKind_Static; + methodState.mTempKind = BfMethodState::TempKind_Static; mHasForceLinkMarker = true; @@ -25680,7 +25654,7 @@ void BfModule::DbgFinish() auto firstType = mOwnedTypeInstances[0]; UpdateSrcPos(mContext->mBfObjectType->mTypeDef->GetRefNode()); - SizedArray diParamTypes; + SizedArray diParamTypes; diParamTypes.Add(mBfIRBuilder->DbgGetType(GetPrimitiveType(BfTypeCode_None))); BfIRMDNode diFuncType = mBfIRBuilder->DbgCreateSubroutineType(diParamTypes); auto diScope = mBfIRBuilder->DbgCreateFunction(mDICompileUnit, "FORCELINKMOD", linkName, mCurFilePosition.mFileInstance->mDIFile, @@ -25693,7 +25667,7 @@ void BfModule::DbgFinish() BfExprEvaluator exprEvaluator(this); for (auto& ownedType : mOwnedTypeInstances) - { + { auto alloca = mBfIRBuilder->CreateAlloca(mBfIRBuilder->MapType(GetPrimitiveType(BfTypeCode_Int8))); auto diVariable = mBfIRBuilder->DbgCreateAutoVariable(diScope, "variable", mCurFilePosition.mFileInstance->mDIFile, mCurFilePosition.mCurLine, mBfIRBuilder->DbgGetType(ownedType)); mBfIRBuilder->DbgInsertDeclare(alloca, diVariable); @@ -25701,12 +25675,12 @@ void BfModule::DbgFinish() mBfIRBuilder->CreateRetVoid(); mBfIRBuilder->SetActiveFunction(BfIRFunction()); - } + } } } bool BfModule::Finish() -{ +{ BP_ZONE("BfModule::Finish"); BfLogSysM("BfModule finish: %p\n", this); @@ -25716,7 +25690,7 @@ bool BfModule::Finish() // the module was still queued in mFinishedModuleWorkList ClearModule(); return true; - } + } if (mUsedSlotCount != -1) { @@ -25730,8 +25704,8 @@ bool BfModule::Finish() BF_ASSERT(mAddedToCount); mAddedToCount = false; mAwaitingFinish = false; - - mCompiler->mStats.mModulesFinished++; + + mCompiler->mStats.mModulesFinished++; if (HasCompiledOutput()) { @@ -25749,8 +25723,8 @@ bool BfModule::Finish() } if (mBfIRBuilder->DbgHasInfo()) - { - mBfIRBuilder->DbgFinalize(); + { + mBfIRBuilder->DbgFinalize(); } String objOutputPath; @@ -25762,7 +25736,7 @@ bool BfModule::Finish() bool writeModule = mBfIRBuilder->HasExports(); String outputPath; - + BfCodeGenOptions codeGenOptions = mProject->mCodeGenOptions; auto& compilerOpts = mCompiler->mOptions; @@ -25780,7 +25754,7 @@ bool BfModule::Finish() mCompiler->mStats.mConstBytes += mBfIRBuilder->mTempAlloc.GetAllocSize(); bool allowWriteToLib = true; - if ((allowWriteToLib) && (codeGenOptions.mOptLevel == BfOptLevel_OgPlus) && + if ((allowWriteToLib) && (codeGenOptions.mOptLevel == BfOptLevel_OgPlus) && (!mCompiler->IsHotCompile()) && (mModuleName != "vdata")) { codeGenOptions.mWriteToLib = true; @@ -25792,12 +25766,12 @@ bool BfModule::Finish() } for (int fileIdx = 0; fileIdx <= mExtensionCount; fileIdx++) - { + { outputPath = mModuleName; outputPath = mCompiler->mOutputDirectory + "/" + mProject->mName + "/" + outputPath; BfModuleFileName moduleFileName; - + if (mParentModule != NULL) { for (auto&& checkPair : mParentModule->mSpecializedMethodModules) @@ -25805,7 +25779,7 @@ bool BfModule::Finish() if (checkPair.mValue == this) moduleFileName.mProjects = checkPair.mKey; } - } + } moduleFileName.mProjects.Add(mProject); if (fileIdx > 0) @@ -25815,11 +25789,11 @@ bool BfModule::Finish() if (mCompiler->mOptions.mGenerateObj) { objOutputPath = outputPath + BF_OBJ_EXT; - moduleFileName.mFileName = objOutputPath; + moduleFileName.mFileName = objOutputPath; } else if (mCompiler->mOptions.mWriteIR) { - moduleFileName.mFileName = irOutputPath; + moduleFileName.mFileName = irOutputPath; } else if ((!mCompiler->mOptions.mGenerateObj) && (!mCompiler->mOptions.mGenerateBitcode) && (!mCompiler->mOptions.mWriteIR)) { @@ -25831,35 +25805,34 @@ bool BfModule::Finish() if (!mOutFileNames.Contains(moduleFileName)) mOutFileNames.Add(moduleFileName); } - + if (mCompiler->IsHotCompile()) { codeGenOptions.mIsHotCompile = true; if (mParentModule != NULL) mParentModule->mHadHotObjectWrites = true; - mHadHotObjectWrites = true; + mHadHotObjectWrites = true; } - //TODO: Testing VDATA /*if (mModuleName == "vdata") { codeGenOptions.mOptLevel = 4; }*/ - - codeGenOptions.GenerateHash(); - BP_ZONE("BfModule::Finish.WriteObjectFile"); - + + codeGenOptions.GenerateHash(); + BP_ZONE("BfModule::Finish.WriteObjectFile"); + if ((writeModule) && (!mBfIRBuilder->mIgnoreWrites)) - mCompiler->mCodeGen.WriteObjectFile(this, outputPath, codeGenOptions); - mLastModuleWrittenRevision = mCompiler->mRevision; - } + mCompiler->mCodeGen.WriteObjectFile(this, outputPath, codeGenOptions); + mLastModuleWrittenRevision = mCompiler->mRevision; + } else { for (auto type : mOwnedTypeInstances) { BF_ASSERT((!type->IsIncomplete()) || (type->IsSpecializedByAutoCompleteMethod())); - } + } } for (auto& specModulePair : mSpecializedMethodModules) @@ -25890,21 +25863,21 @@ void BfModule::ReportMemory(MemReporter* memReporter) memReporter->BeginSection("IRBuilder_BFIR"); memReporter->Add("Used", (int)(mBfIRBuilder->mStream.GetSize())); - memReporter->Add("Unused", (int)(mBfIRBuilder->mStream.mPools.size() * ChunkedDataBuffer::ALLOC_SIZE) - mBfIRBuilder->mStream.GetSize()); + memReporter->Add("Unused", (int)(mBfIRBuilder->mStream.mPools.size() * ChunkedDataBuffer::ALLOC_SIZE) - mBfIRBuilder->mStream.GetSize()); memReporter->EndSection(); memReporter->Add(sizeof(BfIRBuilder)); } - + memReporter->BeginSection("FileInstanceMap"); - memReporter->AddMap(mFileInstanceMap); + memReporter->AddMap(mFileInstanceMap); memReporter->AddMap(mNamedFileInstanceMap); memReporter->Add((int)mNamedFileInstanceMap.size() * sizeof(BfFileInstance)); - memReporter->EndSection(); + memReporter->EndSection(); memReporter->AddVec(mOwnedTypeInstances, false); memReporter->AddVec(mSpecializedMethodModules, false); - memReporter->AddVec(mOutFileNames, false); + memReporter->AddVec(mOutFileNames, false); memReporter->AddMap("FuncReferences", mFuncReferences, false); memReporter->AddMap(mInterfaceSlotRefs, false); memReporter->AddMap(mStaticFieldRefs, false); @@ -25920,7 +25893,7 @@ void BfModule::ReportMemory(MemReporter* memReporter) // ClearModuleData is called immediately after the module is compiled, so don't clear out any data that needs to // be transient through the next compile void BfModule::ClearModuleData(bool clearTransientData) -{ +{ BfLogSysM("ClearModuleData %p\n", this); if (mAddedToCount) @@ -25929,9 +25902,9 @@ void BfModule::ClearModuleData(bool clearTransientData) mAddedToCount = false; } - mDICompileUnit = BfIRMDNode(); + mDICompileUnit = BfIRMDNode(); if (clearTransientData) - mIncompleteMethodCount = 0; + mIncompleteMethodCount = 0; mHasGenericMethods = false; // We don't want to clear these because we want it to persist through module extensions- @@ -25950,29 +25923,29 @@ void BfModule::ClearModuleData(bool clearTransientData) for (auto prevIRBuilder : mPrevIRBuilders) delete prevIRBuilder; - mPrevIRBuilders.Clear(); + mPrevIRBuilders.Clear(); for (auto& specPair : mSpecializedMethodModules) { auto specModule = specPair.mValue; specModule->ClearModuleData(); } - + for (int i = 0; i < BfBuiltInFuncType_Count; i++) mBuiltInFuncs[i] = BfIRFunction(); if (mNextAltModule != NULL) mNextAltModule->ClearModuleData(); - - BfLogSysM("ClearModuleData. Deleting IRBuilder: %p\n", mBfIRBuilder); + + BfLogSysM("ClearModuleData. Deleting IRBuilder: %p\n", mBfIRBuilder); mIsModuleMutable = false; delete mBfIRBuilder; - mBfIRBuilder = NULL; + mBfIRBuilder = NULL; mWantsIRIgnoreWrites = false; } void BfModule::DisownMethods() -{ +{ for (int i = 0; i < BfBuiltInFuncType_Count; i++) mBuiltInFuncs[i] = BfIRFunction(); @@ -25991,7 +25964,7 @@ void BfModule::DisownMethods() BF_ASSERT(methodGroup.mDefault->mDeclModule != NULL); if (methodGroup.mDefault->mDeclModule == this) { - methodGroup.mDefault->mIRFunction = BfIRFunction(); + methodGroup.mDefault->mIRFunction = BfIRFunction(); } } } @@ -26021,8 +25994,7 @@ void BfModule::ClearModule() { auto specModule = specPair.mValue; specModule->ClearModule(); - } + } if (mNextAltModule != NULL) mNextAltModule->ClearModule(); -} - +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfModule.h b/IDEHelper/Compiler/BfModule.h index c86959ff..c3a6c099 100644 --- a/IDEHelper/Compiler/BfModule.h +++ b/IDEHelper/Compiler/BfModule.h @@ -51,7 +51,7 @@ enum BfPopulateType BfPopulateType_Data, BfPopulateType_DataAndMethods, BfPopulateType_Full = BfPopulateType_DataAndMethods, - + BfPopulateType_Full_Force }; @@ -59,8 +59,8 @@ enum BfEvalExprFlags : int64 { BfEvalExprFlags_None = 0, BfEvalExprFlags_ExplicitCast = 1, - BfEvalExprFlags_NoCast = 2, - BfEvalExprFlags_NoValueAddr = 4, + BfEvalExprFlags_NoCast = 2, + BfEvalExprFlags_NoValueAddr = 4, BfEvalExprFlags_PropogateNullConditional = 8, BfEvalExprFlags_IgnoreNullConditional = 0x10, BfEvalExprFlags_AllowSplat = 0x20, @@ -155,32 +155,32 @@ enum BfLocalVarAssignKind : int8 { BfLocalVarAssignKind_None = 0, BfLocalVarAssignKind_Conditional = 1, - BfLocalVarAssignKind_Unconditional = 2 + BfLocalVarAssignKind_Unconditional = 2 }; class BfLocalVariable { public: - int64 mUnassignedFieldFlags; + int64 mUnassignedFieldFlags; BfType* mResolvedType; BfIdentifierNode* mNameNode; String mName; BfIRValue mAddr; BfIRValue mConstValue; BfIRValue mValue; - BfIRMDNode mDbgVarInst; - BfIRValue mDbgDeclareInst; + BfIRMDNode mDbgVarInst; + BfIRValue mDbgDeclareInst; BfIRBlock mDeclBlock; int mLocalVarIdx; // Index in mLocals int mLocalVarId; // Unique Id for identification (does not get reused, unlike mLocalVarIdx) - int mCompositeCount; + int mCompositeCount; int mWrittenToId; int mReadFromId; int mParamIdx; uint8 mNamePrefixCount; bool mIsThis; bool mHasLocalStructBacking; - bool mIsStruct; + bool mIsStruct; bool mIsImplicitParam; bool mParamFailed; BfLocalVarAssignKind mAssignedKind; @@ -191,7 +191,7 @@ public: bool mIsLowered; bool mAllowAddr; bool mIsShadow; - bool mUsedImplicitly; // Passed implicitly to a local method, capture by ref if we can + bool mUsedImplicitly; // Passed implicitly to a local method, capture by ref if we can bool mNotCaptured; bool mIsConst; bool mIsBumpAlloc; @@ -230,11 +230,11 @@ public: mShadowedLocal = NULL; } - bool IsParam() + bool IsParam() { return mParamIdx != -2; } - void Init(); + void Init(); }; class BfMethodState; @@ -245,19 +245,19 @@ class BfLocalMethod { public: BfSystem* mSystem; - BfModule* mModule; + BfModule* mModule; BfSource* mSource; BfMethodDeclaration* mMethodDeclaration; String mExpectedFullName; - String mMethodName; - BfMethodDef* mMethodDef; + String mMethodName; + BfMethodDef* mMethodDef; BfLocalMethod* mOuterLocalMethod; - BfMethodInstanceGroup* mMethodInstanceGroup; - BfMethodInstance* mLambdaInvokeMethodInstance; - BfLambdaBindExpression* mLambdaBindExpr; + BfMethodInstanceGroup* mMethodInstanceGroup; + BfMethodInstance* mLambdaInvokeMethodInstance; + BfLambdaBindExpression* mLambdaBindExpr; BfMethodState* mDeclMethodState; BfIRMDNode mDeclDIScope; - BfMixinState* mDeclMixinState; + BfMixinState* mDeclMixinState; OwnedVector mDirectTypeRefs; bool mDeclOnly; bool mDidBodyErrorPass; @@ -274,9 +274,9 @@ public: mOuterLocalMethod = NULL; mMethodInstanceGroup = NULL; mLambdaInvokeMethodInstance = NULL; - mLambdaBindExpr = NULL; + mLambdaBindExpr = NULL; mDeclMethodState = NULL; - mDeclMixinState = NULL; + mDeclMixinState = NULL; mDeclOnly = false; mDidBodyErrorPass = false; mNextWithSameName = NULL; @@ -303,7 +303,7 @@ public: BfIRValue mDeferredAlloca; SizedArray mOrigScopeArgs; SizedArray mScopeArgs; - Array mCaptures; + Array mCaptures; BfBlock* mDeferredBlock; BfAstNode* mEmitRefNode; int64 mBlockId; @@ -313,9 +313,9 @@ public: bool mCastThis; bool mArgsNeedLoad; bool mIgnored; - + SLIList mDynList; - BfIRValue mDynCallTail; + BfIRValue mDynCallTail; public: BfDeferredCallEntry() @@ -380,7 +380,7 @@ public: bool mIsUnconditional; bool mIsIfCondition; bool mIfMayBeSkipped; - bool mLeftBlock; + bool mLeftBlock; bool mLeftBlockUncond; public: @@ -399,7 +399,7 @@ public: mLeftBlock = false; mLeftBlockUncond = false; } - + bool Contains(const BfAssignedLocal& val) { for (int i = 0; i < (int)mAssignedLocals.mSize; i++) @@ -430,13 +430,13 @@ enum BfScopeKind class BfScopeData { public: - BfScopeData* mPrevScope; + BfScopeData* mPrevScope; BfScopeKind mScopeKind; BfIRMDNode mDIScope; - BfIRMDNode mDIInlinedAt; + BfIRMDNode mDIInlinedAt; String mLabel; BfIdentifierNode* mLabelNode; - int mLocalVarStart; + int mLocalVarStart; int mScopeDepth; int mMixinDepth; int mScopeLocalId; @@ -446,8 +446,8 @@ public: bool mOuterIsConditional; bool mInnerIsConditional; bool mHadOuterDynStack; - bool mAllowTargeting; - bool mHadScopeValueRetain; + bool mAllowTargeting; + bool mHadScopeValueRetain; bool mIsDeferredBlock; bool mAllowVariableDeclarations; bool mInInitBlock; @@ -461,16 +461,16 @@ public: SLIList mDeferredCallEntries; BfIRValue mBlock; BfIRValue mValueScopeStart; - BfIRValue mSavedStack; + BfIRValue mSavedStack; Array mSavedStackUses; Array mDeferredHandlers; // These get cleared when us our a parent gets new entries added into mDeferredCallEntries Array mAtEndBlocks; // Move these to the end after we close scope Array mDeferredLifetimeEnds; BfDeferredLocalAssignData* mExitLocalAssignData; BfIRMDNode mAltDIFile; - BfIRMDNode mAltDIScope; + BfIRMDNode mAltDIScope; -public: +public: BfScopeData() { mScopeKind = BfScopeKind_Normal; @@ -486,11 +486,11 @@ public: mIsConditional = false; mOuterIsConditional = false; mInnerIsConditional = false; - mHadOuterDynStack = false; + mHadOuterDynStack = false; mHadScopeValueRetain = false; mIsDeferredBlock = false; mSupressNextUnreachable = false; - mAllowTargeting = true; + mAllowTargeting = true; mAllowVariableDeclarations = true; mInInitBlock = false; mInConstIgnore = false; @@ -499,7 +499,7 @@ public: mScopeDepth = 0; mScopeLocalId = -1; mExitLocalAssignData = NULL; - } + } ~BfScopeData() { @@ -535,7 +535,7 @@ public: } return false; } - + bool IsDyn(BfScopeData* scopeData) { auto checkScope = this; @@ -563,7 +563,7 @@ public: return false; auto checkScope = this; while (checkScope != scopeData) - { + { checkScope = checkScope->mPrevScope; if (!checkScope->mDIInlinedAt) return true; @@ -580,7 +580,7 @@ public: if (checkScope == scopeData) break; checkScope = checkScope->mPrevScope; - } + } } int GetDepth() @@ -676,7 +676,7 @@ class BfBreakData { public: BfBreakData* mPrevBreakData; - BfScopeData* mScope; + BfScopeData* mScope; BfIRBlock mIRContinueBlock; BfIRBlock mIRBreakBlock; BfIRBlock mIRFallthroughBlock; @@ -734,7 +734,7 @@ public: BfTypeInstance* mClosureType; BfDeferredLocalMethod* mActiveDeferredLocalMethod; Array mConstLocals; // Locals not inserted into the captured 'this' - HashSet mReferencedOuterClosureMembers; + HashSet mReferencedOuterClosureMembers; HashSet mLocalMethodRefSet; Array mLocalMethodRefs; Array mDeferredProcessLocalMethods; @@ -752,10 +752,10 @@ public: mDeclaringMethodIsMutating = false; mCapturedDelegateSelf = false; mReturnTypeInferState = BfReturnTypeInferState_None; - mActiveDeferredLocalMethod = NULL; + mActiveDeferredLocalMethod = NULL; mReturnType = NULL; mDelegateType = NULL; - mClosureType = NULL; + mClosureType = NULL; } }; @@ -782,7 +782,7 @@ public: }; class BfAttributeState -{ +{ public: enum Flags { @@ -791,19 +791,19 @@ public: Flag_HadError = 2 }; -public: +public: Flags mFlags; BfAstNode* mSrc; BfAttributeTargets mTarget; - BfCustomAttributes* mCustomAttributes; - bool mUsed; + BfCustomAttributes* mCustomAttributes; + bool mUsed; BfAttributeState() { mSrc = NULL; mFlags = Flag_None; mTarget = BfAttributeTargets_None; - mCustomAttributes = NULL; + mCustomAttributes = NULL; mUsed = false; } @@ -811,12 +811,12 @@ public: { if (mCustomAttributes != NULL) delete mCustomAttributes; - } + } }; class BfMixinState { -public: +public: BfMixinState* mPrevMixinState; BfAstNode* mSource; BfScopeData* mCallerScope; @@ -887,8 +887,8 @@ public: public: BfErrorKind mErrorKind; BfAstNode* mRefNode; - BfTypeDef* mAmbiguousTypeDef; - + BfTypeDef* mAmbiguousTypeDef; + public: BfTypeLookupError() { @@ -964,7 +964,7 @@ struct BfLocalVarEntry class BfLambdaCaptureInfo { public: - String mName; + String mName; }; class BfLambdaInstance @@ -1005,8 +1005,8 @@ public: { auto methodDef = mMethodInstance->mMethodDef; delete mMethodInstance; - delete methodDef; - + delete methodDef; + if (mDtorMethodInstance != NULL) { auto methodDef = mDtorMethodInstance->mMethodDef; @@ -1036,48 +1036,48 @@ public: public: BumpAllocator mBumpAlloc; BfMethodState* mPrevMethodState; // Only non-null for things like local methods - BfConstResolveState* mConstResolveState; - BfMethodInstance* mMethodInstance; + BfConstResolveState* mConstResolveState; + BfMethodInstance* mMethodInstance; BfHotDataReferenceBuilder* mHotDataReferenceBuilder; - BfIRFunction mIRFunction; + BfIRFunction mIRFunction; BfIRBlock mIRHeadBlock; BfIRBlock mIRInitBlock; BfIRBlock mIREntryBlock; Array > mLocals; HashSet > mLocalVarSet; - Array mLocalMethods; + Array mLocalMethods; Dictionary mLocalMethodMap; - Dictionary mLocalMethodCache; // So any lambda 'capturing' and 'processing' stages use the same local method + Dictionary mLocalMethodCache; // So any lambda 'capturing' and 'processing' stages use the same local method Array mDeferredLocalMethods; OwnedVector mMixinStates; Dictionary mLambdaCache; Array mDeferredLambdaInstances; - Array mSplatDecompAddrs; + Array mSplatDecompAddrs; BfDeferredLocalAssignData* mDeferredLocalAssignData; BfProjectSet mVisibleProjectSet; int mDeferredLoopListCount; - int mDeferredLoopListEntryCount; + int mDeferredLoopListEntryCount; HashSet mSkipObjectAccessChecks; // Indexed by BfIRValue value id - + Dictionary* mGenericTypeBindings; - + BfIRMDNode mDIFile; bool mInHeadScope; // Is in starting scope of code on entry, controls mStackAllocUncondCount BfTypedValue mRetVal; - BfIRValue mRetValAddr; + BfIRValue mRetValAddr; int mCurAppendAlign; BfIRValue mDynStackRevIdx; // Increments when we restore the stack, which can invalidate dynSize for dynamic looped allocs BfIRBlock mIRExitBlock; BfBreakData* mBreakData; - int mBlockNestLevel; // 0 = top level - bool mIgnoreObjectAccessCheck; + int mBlockNestLevel; // 0 = top level + bool mIgnoreObjectAccessCheck; bool mDisableChecks; BfMixinState* mMixinState; BfClosureState* mClosureState; BfDeferredCallEmitState* mDeferredCallEmitState; BfIteratorClassState* mIteratorClassState; BfPendingNullConditional* mPendingNullConditional; - BfTypeOptions* mMethodTypeOptions; // for [Options] attribute + BfTypeOptions* mMethodTypeOptions; // for [Options] attribute BfIRMDNode mDIRetVal; BfScopeData mHeadScope; @@ -1092,14 +1092,14 @@ public: bool mMayNeedThisAccessCheck; bool mLeftBlockUncond; // Definitely left block. mHadReturn also sets mLeftBlock bool mLeftBlockCond; // May have left block. - bool mInPostReturn; // Unreachable code + bool mInPostReturn; // Unreachable code bool mCrossingMixin; // ie: emitting dtors in response to a return in a mixin bool mNoBind; - bool mInConditionalBlock; // IE: RHS of ((A) && (B)), indicates an allocation in 'B' won't be dominated by a dtor, for example + bool mInConditionalBlock; // IE: RHS of ((A) && (B)), indicates an allocation in 'B' won't be dominated by a dtor, for example bool mAllowUinitReads; bool mDisableReturns; - bool mCancelledDeferredCall; - bool mNoObjectAccessChecks; + bool mCancelledDeferredCall; + bool mNoObjectAccessChecks; int mCurLocalVarId; // Can also refer to a label int mCurAccessId; // For checking to see if a block reads from or writes to a local @@ -1107,51 +1107,51 @@ public: BfMethodState() { mLocals.mAlloc = &mBumpAlloc; - mLocalVarSet.mAlloc = &mBumpAlloc; - - mMethodInstance = NULL; + mLocalVarSet.mAlloc = &mBumpAlloc; + + mMethodInstance = NULL; mPrevMethodState = NULL; mConstResolveState = NULL; - mHotDataReferenceBuilder = NULL; + mHotDataReferenceBuilder = NULL; mHeadScope.mIsScopeHead = true; mCurScope = &mHeadScope; mTailScope = &mHeadScope; mEmitRefNode = NULL; mOverrideScope = NULL; mHadReturn = false; - mLeftBlockUncond = false; + mLeftBlockUncond = false; mLeftBlockCond = false; mHadContinue = false; mMayNeedThisAccessCheck = false; - mTempKind = TempKind_None; + mTempKind = TempKind_None; mInHeadScope = true; mBreakData = NULL; mBlockNestLevel = 0; - mInPostReturn = false; + mInPostReturn = false; mCrossingMixin = false; - mNoBind = false; + mNoBind = false; mIgnoreObjectAccessCheck = false; mDisableChecks = false; mInConditionalBlock = false; mAllowUinitReads = false; mDisableReturns = false; mCancelledDeferredCall = false; - mNoObjectAccessChecks = false; - mInDeferredBlock = false; + mNoObjectAccessChecks = false; + mInDeferredBlock = false; mDeferredLocalAssignData = NULL; mCurLocalVarId = 0; mCurAccessId = 1; mCurAppendAlign = 0; mDeferredLoopListCount = 0; - mDeferredLoopListEntryCount = 0; - mClosureState = NULL; + mDeferredLoopListEntryCount = 0; + mClosureState = NULL; mDeferredCallEmitState = NULL; - mIteratorClassState = NULL; - + mIteratorClassState = NULL; + mGenericTypeBindings = NULL; mMixinState = NULL; mPendingNullConditional = NULL; - mMethodTypeOptions = NULL; + mMethodTypeOptions = NULL; } ~BfMethodState(); @@ -1163,11 +1163,11 @@ public: mInHeadScope = false; newScopeData->mDIScope = mCurScope->mDIScope; newScopeData->mDIInlinedAt = mCurScope->mDIInlinedAt; - newScopeData->mLocalVarStart = mCurScope->mLocalVarStart; + newScopeData->mLocalVarStart = mCurScope->mLocalVarStart; newScopeData->mExprEvaluator = mCurScope->mExprEvaluator; newScopeData->mAltDIFile = mCurScope->mAltDIFile; - newScopeData->mPrevScope = mCurScope; - newScopeData->mMixinDepth = mCurScope->mMixinDepth; + newScopeData->mPrevScope = mCurScope; + newScopeData->mMixinDepth = mCurScope->mMixinDepth; newScopeData->mScopeDepth = mCurScope->mScopeDepth + 1; newScopeData->mInConstIgnore = mCurScope->mInConstIgnore; mCurScope = newScopeData; @@ -1193,7 +1193,7 @@ public: { //TODO: Why did this require mLocalMethod to not be null? That means lambda captures we're not crossed over auto checkMethodState = this; - while ((checkMethodState->mPrevMethodState != NULL) && (checkMethodState->mClosureState != NULL) && + while ((checkMethodState->mPrevMethodState != NULL) && (checkMethodState->mClosureState != NULL) && (checkMethodState->mClosureState->mCapturing) /*&& (checkMethodState->mClosureState->mLocalMethod != NULL)*/) checkMethodState = checkMethodState->mPrevMethodState; return checkMethodState; @@ -1270,7 +1270,7 @@ public: } void LocalDefined(BfLocalVariable* localVar, int fieldIdx = -1, BfLocalVarAssignKind assignKind = BfLocalVarAssignKind_None, bool isFromDeferredAssignData = false); - void ApplyDeferredLocalAssignData(const BfDeferredLocalAssignData& deferredLocalAssignData); + void ApplyDeferredLocalAssignData(const BfDeferredLocalAssignData& deferredLocalAssignData); void Reset(); int GetLocalStartIdx() @@ -1298,19 +1298,19 @@ enum BfBuiltInFuncType { BfBuiltInFuncType_PrintF, BfBuiltInFuncType_Malloc, - BfBuiltInFuncType_Free, + BfBuiltInFuncType_Free, BfBuiltInFuncType_LoadSharedLibraries, BfBuiltInFuncType_Count }; -// These are the options that can be applied to individual methods that cause AltModules -// to be build, since they are exclusive to an LLVMModule; LLVM optimization-related +// These are the options that can be applied to individual methods that cause AltModules +// to be build, since they are exclusive to an LLVMModule; LLVM optimization-related // options always apply to entire LLVM modules struct BfModuleOptions { public: - BfSIMDSetting mSIMDSetting; + BfSIMDSetting mSIMDSetting; int mEmitDebugInfo; BfOptLevel mOptLevel; @@ -1375,7 +1375,7 @@ public: class BfAmbiguityContext { -public: +public: class Entry { public: @@ -1389,7 +1389,7 @@ public: BfTypeInstance* mTypeInstance; bool mIsProjectSpecific; bool mIsReslotting; - Dictionary mEntries; + Dictionary mEntries; public: BfAmbiguityContext() @@ -1482,7 +1482,7 @@ public: struct BfCEParseContext { int mFailIdx; - int mWarnIdx; + int mWarnIdx; }; class BfModule : public BfStructuralVisitor @@ -1504,12 +1504,12 @@ public: String mModuleName; #endif Array mOutFileNames; - // SpecializedModules contain method specializations with types that come from other projects - Dictionary, BfModule*> mSpecializedMethodModules; + // SpecializedModules contain method specializations with types that come from other projects + Dictionary, BfModule*> mSpecializedMethodModules; BfModule* mParentModule; - BfModule* mNextAltModule; // Linked - BfModuleOptions* mModuleOptions; // Only in altModules - + BfModule* mNextAltModule; // Linked + BfModuleOptions* mModuleOptions; // Only in altModules + BfSystem* mSystem; BfCompiler* mCompiler; BfContext* mContext; @@ -1519,36 +1519,36 @@ public: BfTypeInstance* mCurTypeInstance; Dictionary mFileInstanceMap; Dictionary mNamedFileInstanceMap; - Array mOwnedTypeInstances; - + Array mOwnedTypeInstances; + Dictionary mStringObjectPool; Dictionary mStringCharPtrPool; - Array mStringPoolRefs; + Array mStringPoolRefs; HashSet mUnreifiedStringPoolRefs; - - Array mPrevIRBuilders; // Before extensions - BfIRBuilder* mBfIRBuilder; - - BfMethodState* mCurMethodState; - BfAttributeState* mAttributeState; + + Array mPrevIRBuilders; // Before extensions + BfIRBuilder* mBfIRBuilder; + + BfMethodState* mCurMethodState; + BfAttributeState* mAttributeState; BfFilePosition mCurFilePosition; BfMethodInstance* mCurMethodInstance; BfParentNodeEntry* mParentNodeEntry; - BfIRFunction mBuiltInFuncs[BfBuiltInFuncType_Count]; + BfIRFunction mBuiltInFuncs[BfBuiltInFuncType_Count]; Array mDllImportEntries; Array mImportFileNames; - Dictionary mFuncReferences; + Dictionary mFuncReferences; Dictionary mStaticFieldRefs; - Dictionary mInterfaceSlotRefs; + Dictionary mInterfaceSlotRefs; Dictionary mClassVDataRefs; Dictionary mClassVDataExtRefs; Dictionary mTypeDataRefs; Dictionary mDbgRawAllocDataRefs; Dictionary mDeferredMethodCallData; HashSet mDeferredMethodIds; - HashSet mModuleRefs; + HashSet mModuleRefs; BfIRMDNode mDICompileUnit; int mRevision; @@ -1571,14 +1571,14 @@ public: bool mIsComptimeModule; bool mIsScratchModule; bool mIsSpecializedMethodModuleRoot; - bool mIsModuleMutable; // Set to false after writing module to disk, can be set back to true after doing extension module + bool mIsModuleMutable; // Set to false after writing module to disk, can be set back to true after doing extension module bool mWroteToLib; bool mHadBuildError; - bool mHadBuildWarning; - bool mIgnoreErrors; + bool mHadBuildWarning; + bool mIgnoreErrors; bool mHadIgnoredError; - bool mIgnoreWarnings; - bool mSetIllegalSrcPosition; + bool mIgnoreWarnings; + bool mSetIllegalSrcPosition; bool mReportErrors; // Still puts system in error state when set to false bool mIsInsideAutoComplete; bool mIsHotModule; @@ -1590,14 +1590,14 @@ public: bool mNoResolveGenericParams; bool mHadHotObjectWrites; -public: +public: void FatalError(const StringImpl& error, const char* file = NULL, int line = -1); - void NotImpl(BfAstNode* astNode); + void NotImpl(BfAstNode* astNode); void AddMethodReference(const BfMethodRef& methodRef, BfGetMethodInstanceFlags flags = BfGetMethodInstanceFlag_None); bool CheckProtection(BfProtection protection, BfTypeDef* checkType, bool allowProtected, bool allowPrivate); void GetAccessAllowed(BfTypeInstance* checkType, bool& allowProtected, bool& allowPrivate); bool CheckProtection(BfProtectionCheckFlags& flags, BfTypeInstance* memberOwner, BfProject* memberProject, BfProtection memberProtection, BfTypeInstance* lookupStartType); - void SetElementType(BfAstNode* astNode, BfSourceElementType elementType); + void SetElementType(BfAstNode* astNode, BfSourceElementType elementType); bool PreFail(); void SetFail(); void VerifyOnDemandMethods(); @@ -1606,27 +1606,27 @@ public: CeDbgState* GetCeDbgState(); BfError* Fail(const StringImpl& error, BfAstNode* refNode = NULL, bool isPersistent = false, bool deferError = false); BfError* FailInternal(const StringImpl& error, BfAstNode* refNode = NULL); - BfError* FailAfter(const StringImpl& error, BfAstNode* refNode); + BfError* FailAfter(const StringImpl& error, BfAstNode* refNode); BfError* Warn(int warningNum, const StringImpl& warning, BfAstNode* refNode = NULL, bool isPersistent = false, bool showInSpecialized = false); void CheckErrorAttributes(BfTypeInstance* typeInstance, BfMethodInstance* methodInstance, BfCustomAttributes* customAttributes, BfAstNode* targetSrc); void CheckRangeError(BfType* type, BfAstNode* refNode); bool CheckCircularDataError(bool failTypes = true); BfFileInstance* GetFileFromNode(BfAstNode* astNode); - //void UpdateSrcPos(BfAstNode* astNode, bool setDebugLoc = true, int debugLocOffset = 0, bool force = false); + //void UpdateSrcPos(BfAstNode* astNode, bool setDebugLoc = true, int debugLocOffset = 0, bool force = false); void UpdateSrcPos(BfAstNode* astNode, BfSrcPosFlags flags = BfSrcPosFlag_None, int debugLocOffset = 0); - void UseDefaultSrcPos(BfSrcPosFlags flags = BfSrcPosFlag_None, int debugLocOffset = 0); + void UseDefaultSrcPos(BfSrcPosFlags flags = BfSrcPosFlag_None, int debugLocOffset = 0); void UpdateExprSrcPos(BfAstNode* astNode, BfSrcPosFlags flags = BfSrcPosFlag_None); void SetIllegalSrcPos(BfSrcPosFlags flags = BfSrcPosFlag_None); void SetIllegalExprSrcPos(BfSrcPosFlags flags = BfSrcPosFlag_None); - void GetConstClassValueParam(BfIRValue classVData, SizedArrayImpl& typeValueParams); + void GetConstClassValueParam(BfIRValue classVData, SizedArrayImpl& typeValueParams); BfIRValue GetConstValue(int64 val); BfIRValue GetConstValue(int64 val, BfType* type); BfIRValue GetConstValue8(int val); BfIRValue GetConstValue32(int32 val); - BfIRValue GetConstValue64(int64 val); - BfIRValue GetDefaultValue(BfType* type); + BfIRValue GetConstValue64(int64 val); + BfIRValue GetDefaultValue(BfType* type); BfTypedValue GetFakeTypedValue(BfType* type); - BfTypedValue GetDefaultTypedValue(BfType* type, bool allowRef = false, BfDefaultValueKind defaultValueKind = BfDefaultValueKind_Const); + BfTypedValue GetDefaultTypedValue(BfType* type, bool allowRef = false, BfDefaultValueKind defaultValueKind = BfDefaultValueKind_Const); void FixConstValueParams(BfTypeInstance* typeInst, SizedArrayImpl& valueParams, bool fillInPadding = false); BfIRValue CreateStringObjectValue(const StringImpl& str, int stringId, bool define); BfIRValue CreateStringCharPtr(const StringImpl& str, int stringId, bool define); @@ -1637,10 +1637,10 @@ public: BfIRValue GetStringCharPtr(const StringImpl& str, bool force = false); BfIRValue GetStringObjectValue(int idx, bool define, bool force); BfIRValue GetStringObjectValue(const StringImpl& str, bool define = false, bool force = false); - BfIRValue CreateGlobalConstValue(const StringImpl& name, BfIRValue constant, BfIRType type, bool external); + BfIRValue CreateGlobalConstValue(const StringImpl& name, BfIRValue constant, BfIRType type, bool external); void VariantToString(StringImpl& str, const BfVariant& variant); StringT<128> TypeToString(BfType* resolvedType, Array* genericMethodParamNameOverrides = NULL); - StringT<128> TypeToString(BfType* resolvedType, BfTypeNameFlags typeNameFlags, Array* genericMethodParamNameOverrides = NULL); + StringT<128> TypeToString(BfType* resolvedType, BfTypeNameFlags typeNameFlags, Array* genericMethodParamNameOverrides = NULL); void DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameFlags typeNameFlags = BfTypeNameFlags_None, Array* genericMethodParamNameOverrides = NULL); StringT<128> MethodToString(BfMethodInstance* methodInst, BfMethodNameFlags methodNameFlags = BfMethodNameFlag_ResolveGenericParamNames, BfTypeVector* typeGenericArgs = NULL, BfTypeVector* methodGenericArgs = NULL); void pt(BfType* type); @@ -1649,7 +1649,7 @@ public: void CurrentAddToConstHolder(BfIRValue& irVal); void ClearConstData(); bool HasUnactializedConstant(BfConstant* constant, BfIRConstHolder* constHolder); - BfTypedValue GetTypedValueFromConstant(BfConstant* constant, BfIRConstHolder* constHolder, BfType* wantType); + BfTypedValue GetTypedValueFromConstant(BfConstant* constant, BfIRConstHolder* constHolder, BfType* wantType); BfIRValue ConstantToCurrent(BfConstant* constant, BfIRConstHolder* constHolder, BfType* wantType, bool allowUnactualized = false); void ValidateCustomAttributes(BfCustomAttributes* customAttributes, BfAttributeTargets attrTarget); void GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttributeDirective* attributesDirective, BfAttributeTargets attrType, BfGetCustomAttributesFlags flags = BfGetCustomAttributesFlags_None, BfCaptureInfo* captureInfo = NULL); @@ -1657,39 +1657,39 @@ public: BfCustomAttributes* GetCustomAttributes(BfTypeDef* typeDef); void FinishAttributeState(BfAttributeState* attributeState); void ProcessTypeInstCustomAttributes(int& packing, bool& isUnion, bool& isCRepr, bool& isOrdered, int& alignOverride, BfType*& underlyingArrayType, int& underlyingArraySize); - void ProcessCustomAttributeData(); + void ProcessCustomAttributeData(); bool TryGetConstString(BfIRConstHolder* constHolder, BfIRValue irValue, StringImpl& str); BfVariant TypedValueToVariant(BfAstNode* refNode, const BfTypedValue& value, bool allowUndef = false); - BfTypedValue FlushNullConditional(BfTypedValue result, bool ignoreNullable = false); - void NewScopeState(bool createLexicalBlock = true, bool flushValueScope = true); // returns prev scope data + BfTypedValue FlushNullConditional(BfTypedValue result, bool ignoreNullable = false); + void NewScopeState(bool createLexicalBlock = true, bool flushValueScope = true); // returns prev scope data BfIRValue CreateAlloca(BfType* type, bool addLifetime = true, const char* name = NULL, BfIRValue arraySize = BfIRValue()); BfIRValue CreateAllocaInst(BfTypeInstance* typeInst, bool addLifetime = true, const char* name = NULL); BfDeferredCallEntry* AddStackAlloc(BfTypedValue val, BfIRValue arraySize, BfAstNode* refNode, BfScopeData* scope, bool condAlloca = false, bool mayEscape = false, BfIRBlock valBlock = BfIRBlock()); void RestoreScoreState_LocalVariables(); - void RestoreScopeState(); + void RestoreScopeState(); void MarkDynStack(BfScopeData* scope); void SaveStackState(BfScopeData* scope); BfIRValue ValueScopeStart(); void ValueScopeEnd(BfIRValue valueScopeStart); BfProjectSet* GetVisibleProjectSet(); - void AddBasicBlock(BfIRBlock bb, bool activate = true); + void AddBasicBlock(BfIRBlock bb, bool activate = true); void VisitEmbeddedStatement(BfAstNode* stmt, BfExprEvaluator* exprEvaluator = NULL, BfEmbeddedStatementFlags flags = BfEmbeddedStatementFlags_None); void VisitCodeBlock(BfBlock* block); void VisitCodeBlock(BfBlock* block, BfIRBlock continueBlock, BfIRBlock breakBlock, BfIRBlock fallthroughBlock, bool defaultBreak, bool* hadReturn = NULL, BfLabelNode* labelNode = NULL, bool closeScope = false, BfEmbeddedStatementFlags flags = BfEmbeddedStatementFlags_None); void DoForLess(BfForEachStatement* forEachStmt); // Util - void CreateReturn(BfIRValue val); + void CreateReturn(BfIRValue val); void EmitReturn(const BfTypedValue& val); void EmitDefaultReturn(); void EmitDeferredCall(BfModuleMethodInstance moduleMethodInstance, SizedArrayImpl& llvmArgs, BfDeferredBlockFlags flags = BfDeferredBlockFlag_None); bool AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfScopeData* scope); BfDeferredCallEntry* AddDeferredBlock(BfBlock* block, BfScopeData* scope, Array* captures = NULL); - BfDeferredCallEntry* AddDeferredCall(const BfModuleMethodInstance& moduleMethodInstance, SizedArrayImpl& llvmArgs, BfScopeData* scope, BfAstNode* srcNode = NULL, bool bypassVirtual = false, bool doNullCheck = false); + BfDeferredCallEntry* AddDeferredCall(const BfModuleMethodInstance& moduleMethodInstance, SizedArrayImpl& llvmArgs, BfScopeData* scope, BfAstNode* srcNode = NULL, bool bypassVirtual = false, bool doNullCheck = false); void EmitDeferredCall(BfDeferredCallEntry& deferredCallEntry, bool moveBlocks); - void EmitDeferredCallProcessor(SLIList& callEntries, BfIRValue callTail); + void EmitDeferredCallProcessor(SLIList& callEntries, BfIRValue callTail); bool CanCast(BfTypedValue typedVal, BfType* toType, BfCastFlags castFlags = BfCastFlags_None); bool AreSplatsCompatible(BfType* fromType, BfType* toType, bool* outNeedsMemberCasting); BfType* GetClosestNumericCastType(const BfTypedValue& typedVal, BfType* wantType); @@ -1706,34 +1706,34 @@ public: void CleanupFileInstances(); void AssertErrorState(); void AssertParseErrorState(); - void InitTypeInst(BfTypedValue typedValue, BfScopeData* scope, bool zeroMemory, BfIRValue dataSize); + void InitTypeInst(BfTypedValue typedValue, BfScopeData* scope, bool zeroMemory, BfIRValue dataSize); bool IsAllocatorAligned(); BfIRValue AllocBytes(BfAstNode* refNode, const BfAllocTarget& allocTarget, BfType* type, BfIRValue sizeValue, BfIRValue alignValue, BfAllocFlags allocFlags/*bool zeroMemory, bool defaultToMalloc*/); BfIRValue GetMarkFuncPtr(BfType* type); BfIRValue GetDbgRawAllocData(BfType* type); BfIRValue AllocFromType(BfType* type, const BfAllocTarget& allocTarget, BfIRValue appendSizeValue = BfIRValue(), BfIRValue arraySize = BfIRValue(), int arrayDim = 0, /*bool isRawArrayAlloc = false, bool zeroMemory = true*/BfAllocFlags allocFlags = BfAllocFlags_ZeroMemory, int alignOverride = -1); void ValidateAllocation(BfType* type, BfAstNode* refNode); - bool IsOptimized(); + bool IsOptimized(); void EmitAppendAlign(int align, int sizeMultiple = 0); - BfIRValue AppendAllocFromType(BfType* type, BfIRValue appendSizeValue = BfIRValue(), int appendAllocAlign = 0, BfIRValue arraySize = BfIRValue(), int arrayDim = 0, bool isRawArrayAlloc = false, bool zeroMemory = true); + BfIRValue AppendAllocFromType(BfType* type, BfIRValue appendSizeValue = BfIRValue(), int appendAllocAlign = 0, BfIRValue arraySize = BfIRValue(), int arrayDim = 0, bool isRawArrayAlloc = false, bool zeroMemory = true); bool IsTargetingBeefBackend(); bool WantsLifetimes(); bool HasCompiledOutput(); bool HasExecutedOutput(); void SkipObjectAccessCheck(BfTypedValue typedVal); - void EmitObjectAccessCheck(BfTypedValue typedVal); + void EmitObjectAccessCheck(BfTypedValue typedVal); void EmitEnsureInstructionAt(); void EmitDynamicCastCheck(const BfTypedValue& targetValue, BfType* targetType, BfIRBlock trueBlock, BfIRBlock falseBlock, bool nullSucceeds = false); void EmitDynamicCastCheck(BfTypedValue typedVal, BfType* type, bool allowNull); - void CheckStaticAccess(BfTypeInstance* typeInstance); + void CheckStaticAccess(BfTypeInstance* typeInstance); BfTypedValue RemoveRef(BfTypedValue typedValue); BfTypedValue SanitizeAddr(BfTypedValue typedValue); BfTypedValue ToRef(BfTypedValue typedValue, BfRefType* refType = NULL); BfTypedValue LoadOrAggregateValue(BfTypedValue typedValue); - BfTypedValue LoadValue(BfTypedValue typedValue, BfAstNode* refNode = NULL, bool isVolatile = false); + BfTypedValue LoadValue(BfTypedValue typedValue, BfAstNode* refNode = NULL, bool isVolatile = false); BfTypedValue PrepareConst(BfTypedValue& typedValue); void AggregateSplatIntoAddr(BfTypedValue typedValue, BfIRValue addrVal); - BfTypedValue AggregateSplat(BfTypedValue typedValue, BfIRValue* valueArrPtr = NULL); + BfTypedValue AggregateSplat(BfTypedValue typedValue, BfIRValue* valueArrPtr = NULL); BfTypedValue MakeAddressable(BfTypedValue typedValue, bool forceMutable = false, bool forceAddressable = false); BfTypedValue RemoveReadOnly(BfTypedValue typedValue); BfTypedValue CopyValue(const BfTypedValue& typedValue); @@ -1763,13 +1763,13 @@ public: virtual void Visit(BfIdentifierNode* identifierNode) override; virtual void Visit(BfTypeReference* typeRef) override; virtual void Visit(BfEmptyStatement* astNode) override; - virtual void Visit(BfExpression* expressionStmt) override; + virtual void Visit(BfExpression* expressionStmt) override; virtual void Visit(BfExpressionStatement* expressionStmt) override; virtual void Visit(BfVariableDeclaration* varDecl) override; virtual void Visit(BfLocalMethodDeclaration* methodDecl) override; virtual void Visit(BfAttributedStatement* attribStmt) override; virtual void Visit(BfThrowStatement* throwStmt) override; - virtual void Visit(BfDeleteStatement* deleteStmt) override; + virtual void Visit(BfDeleteStatement* deleteStmt) override; virtual void Visit(BfSwitchStatement* switchStmt) override; virtual void Visit(BfTryStatement* tryStmt) override; virtual void Visit(BfCatchStatement* catchStmt) override; @@ -1777,7 +1777,7 @@ public: virtual void Visit(BfCheckedStatement* checkedStmt) override; virtual void Visit(BfUncheckedStatement* uncheckedStmt) override; void DoIfStatement(BfIfStatement* ifStmt, bool includeTrueStmt, bool includeFalseStmt); - virtual void Visit(BfIfStatement* ifStmt) override; + virtual void Visit(BfIfStatement* ifStmt) override; virtual void Visit(BfReturnStatement* returnStmt) override; virtual void Visit(BfYieldStatement* yieldStmt) override; virtual void Visit(BfBreakStatement* breakStmt) override; @@ -1796,7 +1796,7 @@ public: virtual void Visit(BfRootNode* rootNode) override; virtual void Visit(BfInlineAsmStatement* asmStmt) override; - // Type helpers + // Type helpers BfGenericExtensionEntry* BuildGenericExtensionInfo(BfTypeInstance* genericTypeInst, BfTypeDef* partialTypeDef); bool InitGenericParams(BfType* resolvedTypeRef); bool FinishGenericParams(BfType* resolvedTypeRef); @@ -1810,12 +1810,12 @@ public: void InitType(BfType* resolvedTypeRef, BfPopulateType populateType); BfProtection FixProtection(BfProtection protection, BfProject* defProject); bool CheckAccessMemberProtection(BfProtection protection, BfTypeInstance* memberType); - bool CheckDefineMemberProtection(BfProtection protection, BfType* memberType); - void CheckMemberNames(BfTypeInstance* typeInst); + bool CheckDefineMemberProtection(BfProtection protection, BfType* memberType); + void CheckMemberNames(BfTypeInstance* typeInst); void AddDependency(BfType* usedType, BfType* userType, BfDependencyMap::DependencyFlags flags, BfDepContext* depContext = NULL); void AddDependency(BfGenericParamInstance* genericParam, BfTypeInstance* usingType); void AddCallDependency(BfMethodInstance* methodInstance, bool devirtualized = false); - void AddFieldDependency(BfTypeInstance* typeInstance, BfFieldInstance* fieldInstance, BfType* fieldType); + void AddFieldDependency(BfTypeInstance* typeInstance, BfFieldInstance* fieldInstance, BfType* fieldType); void TypeFailed(BfTypeInstance* typeInstance); bool IsAttribute(BfTypeInstance* typeInst); void PopulateGlobalContainersList(const BfGlobalLookup& globalLookup); @@ -1844,9 +1844,9 @@ public: void PopulateUsingFieldData(BfTypeInstance* typeInstance); void DoPopulateType_TypeAlias(BfTypeAliasType* typeAlias); void DoPopulateType_InitSearches(BfTypeInstance* typeInstance); - void DoPopulateType_SetGenericDependencies(BfTypeInstance* genericTypeInstance); + void DoPopulateType_SetGenericDependencies(BfTypeInstance* genericTypeInstance); void DoPopulateType_FinishEnum(BfTypeInstance* typeInstance, bool underlyingTypeDeferred, HashContext* dataMemberHashCtx, BfType* unionInnerType); - void DoPopulateType_CeCheckEnum(BfTypeInstance* typeInstance, bool underlyingTypeDeferred); + void DoPopulateType_CeCheckEnum(BfTypeInstance* typeInstance, bool underlyingTypeDeferred); void DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateType = BfPopulateType_Data); static BfModule* GetModuleFor(BfType* type); void DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance); @@ -1858,7 +1858,7 @@ public: void AppendedObjectInit(BfFieldInstance* fieldInstance); void MarkFieldInitialized(BfFieldInstance* fieldInstance); bool IsThreadLocal(BfFieldInstance* fieldInstance); - BfType* ResolveVarFieldType(BfTypeInstance* typeInst, BfFieldInstance* fieldInstance, BfFieldDef* field); + BfType* ResolveVarFieldType(BfTypeInstance* typeInst, BfFieldInstance* fieldInstance, BfFieldDef* field); void FindSubTypes(BfTypeInstance* classType, SizedArrayImpl* outVals, SizedArrayImpl* exChecks, bool isInterfacePass); BfType* CheckUnspecializedGenericType(BfTypeInstance* genericTypeInst, BfPopulateType populateType); BfTypeInstance* GetUnspecializedTypeInstance(BfTypeInstance* typeInst); @@ -1877,7 +1877,7 @@ public: BfConcreteInterfaceType* CreateConcreteInterfaceType(BfTypeInstance* interfaceType); BfTypeInstance* GetWrappedStructType(BfType* type, bool allowSpecialized = true); BfTypeInstance* GetPrimitiveStructType(BfTypeCode typeCode); - BfPrimitiveType* GetPrimitiveType(BfTypeCode typeCode); + BfPrimitiveType* GetPrimitiveType(BfTypeCode typeCode); BfIRType GetIRLoweredType(BfTypeCode loweredTypeCode, BfTypeCode loweredTypeCode2); BfMethodRefType* CreateMethodRefType(BfMethodInstance* methodInstance, bool mustAlreadyExist = false); BfType* FixIntUnknown(BfType* type); @@ -1893,7 +1893,7 @@ public: BfIRValue AllocLocalVariable(BfType* type, const StringImpl& name, bool doLifetimeEnd = true); void DoAddLocalVariable(BfLocalVariable* localVar); void DoLocalVariableDebugInfo(BfLocalVariable* localVar, bool doAliasValue = false, BfIRValue declareBefore = BfIRValue(), BfIRInitType initType = BfIRInitType_NotSet); - BfLocalVariable* AddLocalVariableDef(BfLocalVariable* localVarDef, bool addDebugInfo = false, bool doAliasValue = false, BfIRValue declareBefore = BfIRValue(), BfIRInitType initType = BfIRInitType_NotSet); + BfLocalVariable* AddLocalVariableDef(BfLocalVariable* localVarDef, bool addDebugInfo = false, bool doAliasValue = false, BfIRValue declareBefore = BfIRValue(), BfIRInitType initType = BfIRInitType_NotSet); bool TryLocalVariableInit(BfLocalVariable* localVar); void LocalVariableDone(BfLocalVariable* localVar, bool isMethodExit); void CreateRetValLocal(); @@ -1902,7 +1902,7 @@ public: void CheckTupleVariableDeclaration(BfTupleExpression* tupleExpr, BfType* initType); void HandleTupleVariableDeclaration(BfVariableDeclaration* varDecl, BfTupleExpression* tupleExpr, BfTypedValue initTupleValue, bool isReadOnly, bool isConst, bool forceAddr, BfIRBlock* declBlock = NULL); void HandleTupleVariableDeclaration(BfVariableDeclaration* varDecl); - void HandleCaseEnumMatch_Tuple(BfTypedValue tupleVal, const BfSizedArray& arguments, BfAstNode* tooFewRef, BfIRValue phiVal, BfIRBlock& matchedBlockStart, + void HandleCaseEnumMatch_Tuple(BfTypedValue tupleVal, const BfSizedArray& arguments, BfAstNode* tooFewRef, BfIRValue phiVal, BfIRBlock& matchedBlockStart, BfIRBlock& matchedBlockEnd, BfIRBlock& falseBlockStart, BfIRBlock& falseBlockEnd, bool& hadConditional, bool clearOutOnMismatch, bool prevHadFallthrough); BfTypedValue TryCaseTupleMatch(BfTypedValue tupleVal, BfTupleExpression* tupleExpr, BfIRBlock* eqBlock, BfIRBlock* notEqBlock, BfIRBlock* matchBlock, bool& hadConditional, bool clearOutOnMismatch, bool prevHadFallthrough); BfTypedValue TryCaseEnumMatch(BfTypedValue enumVal, BfTypedValue tagVal, BfExpression* expr, BfIRBlock* eqBlock, BfIRBlock* notEqBlock, BfIRBlock* matchBlock, int& uncondTagId, bool& hadConditional, bool clearOutOnMismatch, bool prevHadFallthrough); @@ -1911,14 +1911,14 @@ public: BfLocalVariable* HandleVariableDeclaration(BfVariableDeclaration* varDecl, BfExprEvaluator* exprEvaluator = NULL); BfLocalVariable* HandleVariableDeclaration(BfType* type, BfAstNode* nameNode, BfTypedValue val, bool updateSrcLoc = true, bool forceAddr = false); BfLocalVariable* HandleVariableDeclaration(BfVariableDeclaration* varDecl, BfTypedValue val, bool updateSrcLoc = true, bool forceAddr = false); - void CheckVariableDef(BfLocalVariable* variableDef); + void CheckVariableDef(BfLocalVariable* variableDef); BfScopeData* FindScope(BfAstNode* scopeName, BfMixinState* curMixinState, bool allowAcrossDeferredBlock); BfScopeData* FindScope(BfAstNode* scopeName, bool allowAcrossDeferredBlock); BfBreakData* FindBreakData(BfAstNode* scopeName); void EmitLifetimeEnds(BfScopeData* scopeData); void ClearLifetimeEnds(); - bool HasDeferredScopeCalls(BfScopeData* scope); - void EmitDeferredScopeCalls(bool useSrcPositions, BfScopeData* scope, BfIRBlock doneBlock = BfIRBlock()); + bool HasDeferredScopeCalls(BfScopeData* scope); + void EmitDeferredScopeCalls(bool useSrcPositions, BfScopeData* scope, BfIRBlock doneBlock = BfIRBlock()); void MarkScopeLeft(BfScopeData* scopeData, bool isNoReturn = false); BfGenericParamType* GetGenericParamType(BfGenericParamKind paramKind, int paramIdx); BfType* ResolveGenericType(BfType* unspecializedType, BfTypeVector* typeGenericArguments, BfTypeVector* methodGenericArguments, BfType* selfType, bool allowFail = false); @@ -1935,8 +1935,8 @@ public: bool ResolveTypeResult_Validate(BfAstNode* typeRef, BfType* resolvedTypeRef); BfType* ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTypeRef, BfPopulateType populateType, BfResolveTypeRefFlags resolveFlags); void ShowAmbiguousTypeError(BfAstNode* refNode, BfTypeDef* typeDef, BfTypeDef* otherTypeDef); - void ShowGenericArgCountError(BfAstNode* typeRef, int wantedGenericParams); - BfTypeDef* GetActiveTypeDef(BfTypeInstance* typeInstanceOverride = NULL, bool useMixinDecl = false); // useMixinDecl is useful for type lookup, but we don't want the decl project to limit what methods the user can call + void ShowGenericArgCountError(BfAstNode* typeRef, int wantedGenericParams); + BfTypeDef* GetActiveTypeDef(BfTypeInstance* typeInstanceOverride = NULL, bool useMixinDecl = false); // useMixinDecl is useful for type lookup, but we don't want the decl project to limit what methods the user can call BfTypeDef* FindTypeDefRaw(const BfAtomComposite& findName, int numGenericArgs, BfTypeInstance* typeInstance, BfTypeDef* useTypeDef, BfTypeLookupError* error, BfTypeLookupResultCtx* lookupResultCtx = NULL, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0); BfTypeDef* FindTypeDef(const BfAtomComposite& findName, int numGenericArgs = 0, BfTypeInstance* typeInstanceOverride = NULL, BfTypeLookupError* error = NULL, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0); BfTypeDef* FindTypeDef(const StringImpl& typeName, int numGenericArgs = 0, BfTypeInstance* typeInstanceOverride = NULL, BfTypeLookupError* error = NULL, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0); @@ -1945,7 +1945,7 @@ public: void CheckTypeRefFixit(BfAstNode* typeRef, const char* appendName = NULL); void CheckIdentifierFixit(BfAstNode* node); void TypeRefNotFound(BfTypeReference* typeRef, const char* appendName = NULL); - bool ValidateTypeWildcard(BfAstNode* typeRef, bool isAttributeRef); + bool ValidateTypeWildcard(BfAstNode* typeRef, bool isAttributeRef); void GetDelegateTypeRefAttributes(BfDelegateTypeRef* delegateTypeRef, BfCallingConvention& callingConvention); BfType* ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType populateType = BfPopulateType_Data, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0, int numGenericArgs = 0); BfType* ResolveTypeRefAllowUnboundGenerics(BfTypeReference* typeRef, BfPopulateType populateType = BfPopulateType_Data, bool resolveGenericParam = true); @@ -1956,20 +1956,20 @@ public: BfType* ResolveInnerType(BfType* outerType, BfAstNode* typeRef, BfPopulateType populateType = BfPopulateType_Data, bool ignoreErrors = false, int numGenericArgs = 0, BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_None); BfTypeDef* GetCombinedPartialTypeDef(BfTypeDef* type); BfTypeInstance* GetOuterType(BfType* type); - bool IsInnerType(BfType* checkInnerType, BfType* checkOuterType); + bool IsInnerType(BfType* checkInnerType, BfType* checkOuterType); bool IsInnerType(BfTypeDef* checkInnerType, BfTypeDef* checkOuterType); bool TypeHasParentOrEquals(BfTypeDef* checkChildTypeDef, BfTypeDef* checkParentTypeDef); - BfTypeDef* FindCommonOuterType(BfTypeDef* type, BfTypeDef* type2); + BfTypeDef* FindCommonOuterType(BfTypeDef* type, BfTypeDef* type2); bool TypeIsSubTypeOf(BfTypeInstance* srcType, BfTypeInstance* wantType, bool checkAccessibility = true); bool TypeIsSubTypeOf(BfTypeInstance* srcType, BfTypeDef* wantType); int GetTypeDistance(BfType* fromType, BfType* toType); - bool IsTypeMoreSpecific(BfType* leftType, BfType* rightType); + bool IsTypeMoreSpecific(BfType* leftType, BfType* rightType); bool GetBasePropertyDef(BfPropertyDef*& propDef, BfTypeInstance*& typeInst); - + // Method helpers - void CheckInterfaceMethod(BfMethodInstance* methodInstance); + void CheckInterfaceMethod(BfMethodInstance* methodInstance); void CreateDelegateInvokeMethod(); - BfType* GetDelegateReturnType(BfType* delegateType); + BfType* GetDelegateReturnType(BfType* delegateType); BfMethodInstance* GetDelegateInvokeMethod(BfTypeInstance* typeInstance); String GetLocalMethodName(const StringImpl& baseName, BfAstNode* anchorNode, BfMethodState* declMethodState, BfMixinState* declMixinState); BfMethodDef* GetLocalMethodDef(BfLocalMethod* localMethod); @@ -1985,17 +1985,17 @@ public: void CalcAppendAlign(BfMethodInstance* methodInst); BfTypedValue TryConstCalcAppend(BfMethodInstance* methodInst, SizedArrayImpl& args, bool force = false); BfTypedValue CallBaseCtorCalc(bool constOnly); - void EmitCtorCalcAppend(); - void CreateStaticCtor(); + void EmitCtorCalcAppend(); + void CreateStaticCtor(); BfIRValue CreateDllImportGlobalVar(BfMethodInstance* methodInstance, bool define = false); - void CreateDllImportMethod(); + void CreateDllImportMethod(); BfIRCallingConv GetIRCallingConvention(BfMethodInstance* methodInstance); void SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func, bool isInlined); void EmitInitBlocks(const std::function& initBlockCallback); void EmitCtorBody(bool& skipBody); void EmitDtorBody(); void EmitEnumToStringBody(); - void EmitTupleToStringBody(); + void EmitTupleToStringBody(); void EmitGCMarkAppended(BfTypedValue markVal); void EmitGCMarkValue(BfTypedValue& thisValue, BfType* checkType, int memberDepth, int curOffset, HashSet& objectOffsets, BfModuleMethodInstance markFromGCThreadMethodInstance, bool isAppendObject = false); void EmitGCMarkValue(BfTypedValue markVal, BfModuleMethodInstance markFromGCThreadMethodInstance); @@ -2014,7 +2014,7 @@ public: void CreateValueTypeEqualsMethod(bool strictEquals); BfIRFunction GetIntrinsic(BfMethodInstance* methodInstance, bool reportFailure = false); BfIRFunction GetBuiltInFunc(BfBuiltInFuncType funcType); - BfIRValue CreateFunctionFrom(BfMethodInstance* methodInstance, bool tryExisting, bool isInlined); + BfIRValue CreateFunctionFrom(BfMethodInstance* methodInstance, bool tryExisting, bool isInlined); void EvaluateWithNewConditionalScope(BfExprEvaluator& exprEvaluator, BfExpression* expr, BfEvalExprFlags flags); BfTypedValue CreateValueFromExpression(BfExprEvaluator& exprEvaluator, BfExpression* expr, BfType* wantTypeRef = NULL, BfEvalExprFlags flags = BfEvalExprFlags_None, BfType** outOrigType = NULL); BfTypedValue CreateValueFromExpression(BfExpression* expr, BfType* wantTypeRef = NULL, BfEvalExprFlags flags = BfEvalExprFlags_None, BfType** outOrigType = NULL); @@ -2022,9 +2022,9 @@ public: BfMethodInstance* GetRawMethodInstanceAtIdx(BfTypeInstance* typeInstance, int methodIdx, const char* assertName = NULL); BfMethodInstance* GetRawMethodInstance(BfTypeInstance* typeInstance, BfMethodDef* methodDef); BfMethodInstance* GetRawMethodByName(BfTypeInstance* typeInstance, const StringImpl& methodName, int paramCount = -1, bool checkBase = false, bool allowMixin = false); - BfMethodInstance* GetUnspecializedMethodInstance(BfMethodInstance* methodInstance, bool useUnspecializedType = true); // Unspecialized owner type and unspecialized method type - int GetGenericParamAndReturnCount(BfMethodInstance* methodInstance); - BfModule* GetSpecializedMethodModule(const SizedArrayImpl& projectList); + BfMethodInstance* GetUnspecializedMethodInstance(BfMethodInstance* methodInstance, bool useUnspecializedType = true); // Unspecialized owner type and unspecialized method type + int GetGenericParamAndReturnCount(BfMethodInstance* methodInstance); + BfModule* GetSpecializedMethodModule(const SizedArrayImpl& projectList); BfModuleMethodInstance GetMethodInstanceAtIdx(BfTypeInstance* typeInstance, int methodIdx, const char* assertName = NULL, BfGetMethodInstanceFlags flags = BfGetMethodInstanceFlag_None); BfModuleMethodInstance GetMethodByName(BfTypeInstance* typeInstance, const StringImpl& methodName, int paramCount = -1, bool checkBase = false); BfModuleMethodInstance GetMethodByName(BfTypeInstance* typeInstance, const StringImpl& methodName, const Array& paramTypes, bool checkBase = false); @@ -2036,15 +2036,15 @@ public: bool CompareMethodSignatures(BfMethodInstance* methodA, BfMethodInstance* methodB); // Doesn't compare return types nor static bool StrictCompareMethodSignatures(BfMethodInstance* methodA, BfMethodInstance* methodB); // Compares return types and static bool IsCompatibleInterfaceMethod(BfMethodInstance* methodA, BfMethodInstance* methodB); - void UniqueSlotVirtualMethod(BfMethodInstance* methodInstance); + void UniqueSlotVirtualMethod(BfMethodInstance* methodInstance); void CompareDeclTypes(BfTypeInstance* typeInst, BfTypeDef* newDeclType, BfTypeDef* prevDeclType, bool& isBetter, bool& isWorse); - bool SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityContext* ambiguityContext = NULL); + bool SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityContext* ambiguityContext = NULL); void CheckOverridenMethod(BfMethodInstance* methodInstance, BfMethodInstance* methodOverriden); - bool SlotInterfaceMethod(BfMethodInstance* methodInstance); + bool SlotInterfaceMethod(BfMethodInstance* methodInstance); void SetMethodDependency(BfMethodInstance* methodInstance); BfModuleMethodInstance ReferenceExternalMethodInstance(BfMethodInstance* methodInstance, BfGetMethodInstanceFlags flags = BfGetMethodInstanceFlag_None); BfModule* GetOrCreateMethodModule(BfMethodInstance* methodInstance); - BfModuleMethodInstance GetMethodInstance(BfTypeInstance* typeInst, BfMethodDef* methodDef, const BfTypeVector& methodGenericArguments, BfGetMethodInstanceFlags flags = BfGetMethodInstanceFlag_None, BfTypeInstance* foreignType = NULL); + BfModuleMethodInstance GetMethodInstance(BfTypeInstance* typeInst, BfMethodDef* methodDef, const BfTypeVector& methodGenericArguments, BfGetMethodInstanceFlags flags = BfGetMethodInstanceFlag_None, BfTypeInstance* foreignType = NULL); BfModuleMethodInstance GetMethodInstance(BfMethodInstance* methodInstance, BfGetMethodInstanceFlags flags = BfGetMethodInstanceFlag_None); BfMethodInstance* GetOuterMethodInstance(BfMethodInstance* methodInstance); // Only useful for local methods void SetupMethodIdHash(BfMethodInstance* methodInstance); @@ -2064,7 +2064,7 @@ public: BfModule(BfContext* context, const StringImpl& moduleName); virtual ~BfModule(); - void Init(bool isFullRebuild = true); + void Init(bool isFullRebuild = true); bool WantsFinishModule(); bool IsHotCompile(); void FinishInit(); @@ -2080,7 +2080,7 @@ public: BfIRValue CreateForceLinkMarker(BfModule* module, String* outName); void ClearModuleData(bool clearTransientData = true); void DisownMethods(); - void ClearModule(); + void ClearModule(); void StartExtension(); // For new method specializations bool Finish(); void RemoveModuleData(); @@ -2106,7 +2106,6 @@ public: } }; - class BfVDataModule : public BfModule { public: @@ -2149,5 +2148,5 @@ namespace std { return std::hash()(val.mLocalVar->mName); } - }; + }; } diff --git a/IDEHelper/Compiler/BfModuleTypeUtils.cpp b/IDEHelper/Compiler/BfModuleTypeUtils.cpp index d7805f99..d5849489 100644 --- a/IDEHelper/Compiler/BfModuleTypeUtils.cpp +++ b/IDEHelper/Compiler/BfModuleTypeUtils.cpp @@ -89,7 +89,7 @@ BfGenericExtensionEntry* BfModule::BuildGenericExtensionInfo(BfTypeInstance* gen if (autoComplete != NULL) autoComplete->CheckTypeRef(genericConstraint.mTypeRef, false); - if (genericParamInstance->mExternType == NULL) + if (genericParamInstance->mExternType == NULL) genericParamInstance->mExternType = GetPrimitiveType(BfTypeCode_Var); ResolveGenericParamConstraints(genericParamInstance, genericTypeInst->IsUnspecializedType()); @@ -109,7 +109,7 @@ BfGenericExtensionEntry* BfModule::BuildGenericExtensionInfo(BfTypeInstance* gen } for (auto genericParam : genericExEntry->mGenericParams) - AddDependency(genericParam, mCurTypeInstance); + AddDependency(genericParam, mCurTypeInstance); ValidateGenericParams(BfGenericParamKind_Type, Span((BfGenericParamInstance**)genericExEntry->mGenericParams.mVals, @@ -124,7 +124,7 @@ bool BfModule::InitGenericParams(BfType* resolvedTypeRef) typeState.mPrevState = mContext->mCurTypeState; typeState.mResolveKind = BfTypeState::ResolveKind_BuildingGenericParams; typeState.mType = resolvedTypeRef; - SetAndRestoreValue prevTypeState(mContext->mCurTypeState, &typeState); + SetAndRestoreValue prevTypeState(mContext->mCurTypeState, &typeState); BF_ASSERT(mCurMethodInstance == NULL); @@ -146,14 +146,14 @@ bool BfModule::InitGenericParams(BfType* resolvedTypeRef) auto genericParamInstance = new BfGenericTypeParamInstance(typeDef, paramIdx); genericParamInstance->mExternType = GetGenericParamType(BfGenericParamKind_Type, paramIdx); genericTypeInst->mGenericTypeInfo->mGenericParams.push_back(genericParamInstance); - } + } for (int externConstraintIdx = 0; externConstraintIdx < (int)typeDef->mExternalConstraints.size(); externConstraintIdx++) { auto genericParamInstance = new BfGenericTypeParamInstance(typeDef, externConstraintIdx + (int)typeDef->mGenericParamDefs.size()); genericTypeInst->mGenericTypeInfo->mGenericParams.push_back(genericParamInstance); } - + return true; } @@ -248,7 +248,7 @@ bool BfModule::FinishGenericParams(BfType* resolvedTypeRef) genericExtensionInfo->mConstraintsPassedSet.Resize(typeDef->mPartials.mSize); extensionCount++; - + if (!genericTypeInst->IsUnspecializedType()) { SetAndRestoreValue prevIgnoreErrors(mIgnoreErrors, true); @@ -281,7 +281,7 @@ bool BfModule::FinishGenericParams(BfType* resolvedTypeRef) genericExtensionInfo->mConstraintsPassedSet.Set(partialTypeDef->mPartialIdx); BfLogSysM("BfModule::FinishGenericParams %p partialTypeDef:%p passed:%d\n", resolvedTypeRef, partialTypeDef, genericExEntry->mConstraintsPassed); - } + } } auto genericExtensionInfo = genericTypeInst->mGenericTypeInfo->mGenericExtensionInfo; @@ -331,19 +331,19 @@ bool BfModule::FinishGenericParams(BfType* resolvedTypeRef) for (auto typeRef : deferredResolveTypes) auto constraintType = ResolveTypeRef(typeRef, BfPopulateType_Declaration, BfResolveTypeRefFlag_None); - - ValidateGenericParams(BfGenericParamKind_Type, - Span((BfGenericParamInstance**)genericTypeInst->mGenericTypeInfo->mGenericParams.mVals, + + ValidateGenericParams(BfGenericParamKind_Type, + Span((BfGenericParamInstance**)genericTypeInst->mGenericTypeInfo->mGenericParams.mVals, genericTypeInst->mGenericTypeInfo->mGenericParams.mSize)); - for (auto genericParam : genericTypeInst->mGenericTypeInfo->mGenericParams) - AddDependency(genericParam, mCurTypeInstance); + for (auto genericParam : genericTypeInst->mGenericTypeInfo->mGenericParams) + AddDependency(genericParam, mCurTypeInstance); return true; } void BfModule::ValidateGenericParams(BfGenericParamKind genericParamKind, Span genericParams) -{ +{ std::function&)> _CheckType = [&](BfType* type, Array& foundParams) { if (type == NULL) @@ -353,11 +353,11 @@ void BfModule::ValidateGenericParams(BfGenericParamKind genericParamKind, SpanmGenericParamKind != genericParamKind) return; - + auto genericParam = genericParams[genericParamType->mGenericParamIdx]; if (genericParam->mTypeConstraint == NULL) return; - + if (foundParams.Contains(genericParamType)) { String error = "Circular constraint dependency between "; @@ -385,7 +385,7 @@ void BfModule::ValidateGenericParams(BfGenericParamKind genericParamKind, SpanmTypeConstraint != NULL) { Array foundParams; @@ -433,8 +433,8 @@ bool BfModule::ValidateGenericConstraints(BfAstNode* typeRef, BfTypeInstance* ge if (genericArg != NULL) genericTypeInst->mGenericTypeInfo->mMaxGenericDepth = BF_MAX(genericTypeInst->mGenericTypeInfo->mMaxGenericDepth, genericArg->mGenericTypeInfo->mMaxGenericDepth + 1); } - - auto typeDef = genericTypeInst->mTypeDef; + + auto typeDef = genericTypeInst->mTypeDef; int startGenericParamIdx = 0; if (typeDef->mOuterType != NULL) @@ -442,14 +442,14 @@ bool BfModule::ValidateGenericConstraints(BfAstNode* typeRef, BfTypeInstance* ge startGenericParamIdx = typeDef->mOuterType->mGenericParamDefs.mSize + typeDef->mOuterType->mExternalConstraints.mSize; auto outerType = GetOuterType(genericTypeInst); PopulateType(outerType, BfPopulateType_Declaration); - if ((outerType->mGenericTypeInfo != NULL) && (outerType->mGenericTypeInfo->mHadValidateErrors)) + if ((outerType->mGenericTypeInfo != NULL) && (outerType->mGenericTypeInfo->mHadValidateErrors)) genericTypeInst->mGenericTypeInfo->mHadValidateErrors = true; } for (int paramIdx = startGenericParamIdx; paramIdx < (int)genericTypeInst->mGenericTypeInfo->mGenericParams.size(); paramIdx++) { auto genericParamInstance = genericTypeInst->mGenericTypeInfo->mGenericParams[paramIdx]; - + BfType* genericArg; if (paramIdx < (int)genericTypeInst->mGenericTypeInfo->mTypeGenericArguments.size()) { @@ -466,8 +466,8 @@ bool BfModule::ValidateGenericConstraints(BfAstNode* typeRef, BfTypeInstance* ge if (!genericTypeInst->IsUnspecializedTypeVariation()) genericTypeInst->mGenericTypeInfo->mHadValidateErrors = true; return false; - } - } + } + } return true; } @@ -534,13 +534,13 @@ bool BfModule::AreConstraintsSubset(BfGenericParamInstance* checkInner, BfGeneri if (checkInner->mTypeConstraint != NULL) { if (checkOuter->mTypeConstraint == NULL) - return false; + return false; if (!TypeIsSubTypeOf(checkOuter->mTypeConstraint->ToTypeInstance(), checkInner->mTypeConstraint->ToTypeInstance())) - return false; + return false; } - + for (auto innerIFace : checkInner->mInterfaceConstraints) - { + { if (checkOuter->mInterfaceConstraints.IsEmpty()) return false; @@ -555,10 +555,10 @@ bool BfModule::AreConstraintsSubset(BfGenericParamInstance* checkInner, BfGeneri for (auto& ifaceEntry : ifaceType->mInterfaces) _AddInterface(ifaceEntry.mInterfaceType); }; - + checkOuter->mInterfaceConstraintSet = new HashSet(); - for (auto outerIFace : checkOuter->mInterfaceConstraints) - _AddInterface(outerIFace); + for (auto outerIFace : checkOuter->mInterfaceConstraints) + _AddInterface(outerIFace); } if (!checkOuter->mInterfaceConstraintSet->Contains(innerIFace)) @@ -643,7 +643,7 @@ void BfModule::CheckInjectNewRevision(BfTypeInstance* typeInstance) { if ((typeInstance != NULL) && (typeInstance->mTypeDef != NULL)) { - auto typeDef = typeInstance->mTypeDef; + auto typeDef = typeInstance->mTypeDef; if (typeDef->mEmitParent != NULL) typeDef = typeDef->mEmitParent; if (typeDef->mNextRevision != NULL) @@ -679,7 +679,7 @@ void BfModule::CheckInjectNewRevision(BfTypeInstance* typeInstance) void BfModule::InitType(BfType* resolvedTypeRef, BfPopulateType populateType) { BP_ZONE("BfModule::InitType"); - + if (auto depType = resolvedTypeRef->ToDependedType()) { if ((mCurMethodInstance != NULL) && (mCurMethodInstance->mMethodInfoEx != NULL)) @@ -718,7 +718,7 @@ void BfModule::InitType(BfType* resolvedTypeRef, BfPopulateType populateType) typeInst->mIsReified = mIsReified; //BF_ASSERT(typeInst->mTypeDef->mTypeCode != BfTypeCode_Extension); - + typeInst->mRevision = mCompiler->mRevision; if (typeInst->mTypeDef != NULL) BF_ASSERT(typeInst->mTypeDef->mDefState != BfTypeDef::DefState_Deleted); @@ -727,7 +727,7 @@ void BfModule::InitType(BfType* resolvedTypeRef, BfPopulateType populateType) { auto tupleType = (BfTypeInstance*)resolvedTypeRef; for (int fieldIdx = 0; fieldIdx < (int)tupleType->mFieldInstances.size(); fieldIdx++) - { + { auto fieldInstance = (BfFieldInstance*)&tupleType->mFieldInstances[fieldIdx]; // We need to make sure dependencies get set immediately since we already resolved the types AddFieldDependency(typeInst, fieldInstance, fieldInstance->mResolvedType); @@ -740,7 +740,7 @@ void BfModule::InitType(BfType* resolvedTypeRef, BfPopulateType populateType) auto genericTypeInst = (BfTypeInstance*)resolvedTypeRef; for (auto typeGenericArg : genericTypeInst->mGenericTypeInfo->mTypeGenericArguments) { - BF_ASSERT((typeGenericArg->mRebuildFlags & BfTypeRebuildFlag_Deleted) == 0); + BF_ASSERT((typeGenericArg->mRebuildFlags & BfTypeRebuildFlag_Deleted) == 0); if (mIsReified) { // Try to reify any generic args @@ -786,7 +786,7 @@ void BfModule::InitType(BfType* resolvedTypeRef, BfPopulateType populateType) resolvedTypeRef->mContext = mContext; if (resolvedTypeRef->IsGenericTypeInstance()) { - auto genericTypeInstance = (BfTypeInstance*)resolvedTypeRef; + auto genericTypeInstance = (BfTypeInstance*)resolvedTypeRef; #ifdef _DEBUG for (auto genericArg : genericTypeInstance->mGenericTypeInfo->mTypeGenericArguments) @@ -810,11 +810,11 @@ void BfModule::InitType(BfType* resolvedTypeRef, BfPopulateType populateType) { BfTypeProcessRequest* typeProcessRequest = mContext->mPopulateTypeWorkList.Alloc(); typeProcessRequest->mType = resolvedTypeRef; - BF_ASSERT(resolvedTypeRef->mContext == mContext); + BF_ASSERT(resolvedTypeRef->mContext == mContext); mCompiler->mStats.mTypesQueued++; mCompiler->UpdateCompletion(); } - PopulateType(resolvedTypeRef, populateType); + PopulateType(resolvedTypeRef, populateType); } void BfModule::AddFieldDependency(BfTypeInstance* typeInstance, BfFieldInstance* fieldInstance, BfType* fieldType) @@ -864,12 +864,12 @@ void BfModule::CheckMemberNames(BfTypeInstance* typeInst) BfTypeInstance* mTypeInst; BfAstNode* mNameNode; BfProtection mProtection; - BfTypeDef* mDeclaringType; + BfTypeDef* mDeclaringType; bool mIsOverride; }; SizedArray memberList; - + // Check base types first and then current type auto checkType = typeInst; while (checkType != NULL) @@ -942,10 +942,10 @@ void BfModule::CheckMemberNames(BfTypeInstance* typeInst) if (memberMap.TryGetValue(memberRef.mName, &prevMemberRef)) { //auto& prevMemberRef = itr->second; - + MemberRef* firstMemberRef = &memberRef; MemberRef* secondMemberRef = prevMemberRef; - bool showPrevious = false; + bool showPrevious = false; BfError* error = NULL; if (prevMemberRef->mTypeInst != typeInst) @@ -987,7 +987,7 @@ void BfModule::CheckMemberNames(BfTypeInstance* typeInst) { std::swap(firstMemberRef, secondMemberRef); } - + if (typeInst->mTypeDef->mIsCombinedPartial) { if ((firstMemberRef->mKindName == "property") && (secondMemberRef->mKindName == "property")) @@ -1021,7 +1021,7 @@ void BfModule::TypeFailed(BfTypeInstance* typeInstance) typeInstance->mTypeFailed = true; // Punt on field types - just substitute 'var' where we have NULLs for (auto& fieldInstance : typeInstance->mFieldInstances) - { + { if ((fieldInstance.mResolvedType == NULL) || (fieldInstance.mResolvedType->IsNull())) { if (fieldInstance.mDataIdx >= 0) @@ -1039,7 +1039,7 @@ void BfModule::TypeFailed(BfTypeInstance* typeInstance) } bool BfModule::CheckCircularDataError(bool failTypes) -{ +{ // Find two loops of mCurTypeInstance. Just finding one loop can give some false errors. BfTypeState* circularTypeStateEnd = NULL; @@ -1151,7 +1151,7 @@ void BfModule::PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType return; if ((resolvedTypeRef->mRebuildFlags & BfTypeRebuildFlag_PendingGenericArgDep) != 0) - { + { BfLogSysM("PopulateType handling BfTypeRebuildFlag_PendingGenericArgDep for type %p\n", resolvedTypeRef); // Reinit dependencies resolvedTypeRef->mRebuildFlags = (BfTypeRebuildFlags)(resolvedTypeRef->mRebuildFlags & ~BfTypeRebuildFlag_PendingGenericArgDep); @@ -1172,14 +1172,14 @@ void BfModule::PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType BfLogSysM("Reifying type %p in scratch module in PopulateType\n", resolvedTypeRef); // It's important for unspecialized types to be in the correct module -- - // when we process their methods, new types will be determined as + // when we process their methods, new types will be determined as // resolve-only or reified based on the module the unresolved type is in BF_ASSERT(typeInst->mModule == mContext->mUnreifiedModule); typeInst->mIsReified = true; typeInst->mModule = mContext->mScratchModule; - // Why did we need to do this at all? Why is just marking the type as reified not enough? - // This causes issues where we may delete a method instance that is currently being used as the generic bindings for + // Why did we need to do this at all? Why is just marking the type as reified not enough? + // This causes issues where we may delete a method instance that is currently being used as the generic bindings for // a method of a specialized generic type // if (typeInst->IsOnDemand()) // { @@ -1199,7 +1199,7 @@ void BfModule::PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType } } else - { + { if ((typeModule != NULL) && (!typeModule->mIsReified) && (!typeModule->mReifyQueued)) { bool canFastReify = false; @@ -1216,7 +1216,7 @@ void BfModule::PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType BfLogSysM("Setting reified type %p in module %p in PopulateType on module awaiting finish\n", resolvedTypeRef, typeModule); typeModule->mIsReified = true; typeModule->CalcGeneratesCode(); - typeModule->mWantsIRIgnoreWrites = false; + typeModule->mWantsIRIgnoreWrites = false; for (auto ownedTypes : typeModule->mOwnedTypeInstances) { ownedTypes->mIsReified = true; @@ -1241,7 +1241,7 @@ void BfModule::PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType typeModule->SetupIRBuilder(false); } else - typeModule->PrepareForIRWriting(resolvedTypeRef->ToTypeInstance()); + typeModule->PrepareForIRWriting(resolvedTypeRef->ToTypeInstance()); } else { @@ -1260,7 +1260,7 @@ void BfModule::PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType } } } - else + else { // If we're a type like "A*", make sure we reify "A" if necessary auto checkUnderlying = resolvedTypeRef->GetUnderlyingType(); @@ -1283,9 +1283,9 @@ void BfModule::PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType if (populateType <= BfPopulateType_TypeDef) return; - + auto typeInstance = resolvedTypeRef->ToTypeInstance(); - CheckInjectNewRevision(typeInstance); + CheckInjectNewRevision(typeInstance); SetAndRestoreValue prevTypeInstance(mCurTypeInstance, typeInstance); SetAndRestoreValue prevMethodInstance(mCurMethodInstance, NULL); @@ -1352,7 +1352,7 @@ void BfModule::PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType return; } - if (resolvedTypeRef->IsTypeAlias()) + if (resolvedTypeRef->IsTypeAlias()) { // Always populate these all the way if (populateType != BfPopulateType_IdentityNoRemapAlias) @@ -1360,7 +1360,7 @@ void BfModule::PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType } if (resolvedTypeRef->IsSizedArray()) - { + { resolvedTypeRef->mRevision = mRevision; bool typeFailed = false; @@ -1385,7 +1385,7 @@ void BfModule::PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType PopulateType(arrayType->mElementType, BfPopulateType_Identity); } resolvedTypeRef->mDefineState = arrayType->mElementType->mDefineState; - AddDependency(elementType, resolvedTypeRef, BfDependencyMap::DependencyFlag_ValueTypeMemberData); + AddDependency(elementType, resolvedTypeRef, BfDependencyMap::DependencyFlag_ValueTypeMemberData); } else { @@ -1428,8 +1428,8 @@ void BfModule::PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType bool isValueless = arrayType->IsValuelessType(); return; - } - + } + if (isNew) { BfTypeDef* typeDef = NULL; @@ -1466,7 +1466,7 @@ void BfModule::PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType if (resolvedTypeRef->IsModifiedTypeType()) { BfModifiedTypeType* retTypeType = (BfModifiedTypeType*)resolvedTypeRef; - BF_ASSERT(retTypeType->mElementType->IsGenericParam()); + BF_ASSERT(retTypeType->mElementType->IsGenericParam()); resolvedTypeRef->mSize = mContext->mBfObjectType->mSize; resolvedTypeRef->mAlign = mContext->mBfObjectType->mAlign; resolvedTypeRef->mDefineState = BfTypeDefineState_Defined; @@ -1490,7 +1490,7 @@ void BfModule::PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType resolvedTypeRef->mDefineState = BfTypeDefineState_Defined; return; } - + // The autocomplete pass doesn't need to do the method processing, allow type to be (partially) incomplete if ((mCompiler->mResolvePassData != NULL) && (mCompiler->mResolvePassData->mAutoComplete != NULL) && (typeInstance != NULL) && (typeInstance->mNeedsMethodProcessing) && (!typeInstance->IsDelegate())) @@ -1520,7 +1520,7 @@ void BfModule::PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType case BfTypeCode_Let: { primitiveType->mSize = mSystem->mPtrSize; - primitiveType->mAlign = mSystem->mPtrSize; + primitiveType->mAlign = mSystem->mPtrSize; resolvedTypeRef->mDefineState = BfTypeDefineState_Defined; } return; @@ -1575,7 +1575,7 @@ void BfModule::PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType PRIMITIVE_TYPE("uintptr", Int64, 8, DW_ATE_unsigned); } return; - case BfTypeCode_IntUnknown: + case BfTypeCode_IntUnknown: case BfTypeCode_UIntUnknown: return; case BfTypeCode_Char8: @@ -1596,24 +1596,24 @@ void BfModule::PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType case BfTypeCode_Object: case BfTypeCode_Struct: case BfTypeCode_Interface: - case BfTypeCode_Enum: + case BfTypeCode_Enum: case BfTypeCode_TypeAlias: // Implemented below break; case BfTypeCode_Extension: - // This can only happen if we didn't actually find the type the extension referred to + // This can only happen if we didn't actually find the type the extension referred to break; default: //NotImpl(resolvedTypeRef->mTypeRef); BFMODULE_FATAL(this, "Invalid type"); return; } - ////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// BF_ASSERT(typeInstance != NULL); if (!typeInstance->IsArray()) - { + { BF_ASSERT(typeInstance->mTypeDef != mContext->mCompiler->mArray1TypeDef); } @@ -1641,7 +1641,7 @@ void BfModule::PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType return; } - typeInstance->mModule->DoPopulateType(typeInstance, populateType); + typeInstance->mModule->DoPopulateType(typeInstance, populateType); } BfTypeOptions* BfModule::GetTypeOptions(BfTypeDef* typeDef) @@ -1652,7 +1652,7 @@ BfTypeOptions* BfModule::GetTypeOptions(BfTypeDef* typeDef) } Array matchedIndices; - + if (!mCompiler->mAttributeTypeOptionMap.IsEmpty()) { auto customAttributes = typeDef->mTypeDeclaration->mAttributes; @@ -1686,7 +1686,7 @@ BfTypeOptions* BfModule::GetTypeOptions(BfTypeDef* typeDef) } int typeOptionsCount = (int)mContext->mSystem->mTypeOptions.size(); - + auto _CheckTypeName = [&](const StringImpl& typeName) { for (int optionIdx = 0; optionIdx < (int)mContext->mSystem->mTypeOptions.size(); optionIdx++) @@ -1796,7 +1796,7 @@ BfTypeOptions* BfModule::GetTypeOptions(BfTypeDef* typeDef) // if (typeInstance->IsTypedPrimitive()) // { // auto underlyingType = typeInstance->GetUnderlyingType(); -// if (underlyingType != NULL) +// if (underlyingType != NULL) // { // String typeName = TypeToString(underlyingType); // _CheckTypeName(typeName); @@ -1806,7 +1806,7 @@ BfTypeOptions* BfModule::GetTypeOptions(BfTypeDef* typeDef) // // Can this only happen for functions that are being extended? // } // } -// +// // if ((!typeInstance->IsBoxed()) && (typeInstance->mTypeDef == mCompiler->mPointerTTypeDef)) // { // BF_ASSERT(typeInstance->IsGenericTypeInstance()); @@ -1817,7 +1817,7 @@ BfTypeOptions* BfModule::GetTypeOptions(BfTypeDef* typeDef) // } String typeName = BfTypeUtils::TypeToString(typeDef); - _CheckTypeName(typeName); + _CheckTypeName(typeName); int matchedIdx = -1; if (matchedIndices.size() == 1) @@ -1846,8 +1846,8 @@ BfTypeOptions* BfModule::GetTypeOptions(BfTypeDef* typeDef) mergedTypeOptions.mOptimizationLevel = first.mOptimizationLevel; mergedTypeOptions.mEmitDebugInfo = first.mEmitDebugInfo; mergedTypeOptions.mAndFlags = first.mAndFlags; - mergedTypeOptions.mOrFlags = first.mOrFlags; - mergedTypeOptions.mAllocStackTraceDepth = first.mAllocStackTraceDepth; + mergedTypeOptions.mOrFlags = first.mOrFlags; + mergedTypeOptions.mAllocStackTraceDepth = first.mAllocStackTraceDepth; mergedTypeOptions.mReflectMethodFilters = first.mReflectMethodFilters; mergedTypeOptions.mReflectMethodAttributeFilters = first.mReflectMethodAttributeFilters; @@ -1861,13 +1861,13 @@ BfTypeOptions* BfModule::GetTypeOptions(BfTypeDef* typeDef) mergedTypeOptions.mOptimizationLevel = typeOptions.mOptimizationLevel; if (typeOptions.mEmitDebugInfo != -1) mergedTypeOptions.mEmitDebugInfo = typeOptions.mEmitDebugInfo; - + mergedTypeOptions.mOrFlags = (BfOptionFlags)(mergedTypeOptions.mOrFlags | typeOptions.mOrFlags); mergedTypeOptions.mAndFlags = (BfOptionFlags)(mergedTypeOptions.mAndFlags | typeOptions.mOrFlags); mergedTypeOptions.mAndFlags = (BfOptionFlags)(mergedTypeOptions.mAndFlags & typeOptions.mAndFlags); - mergedTypeOptions.mOrFlags = (BfOptionFlags)(mergedTypeOptions.mOrFlags & typeOptions.mAndFlags); - + mergedTypeOptions.mOrFlags = (BfOptionFlags)(mergedTypeOptions.mOrFlags & typeOptions.mAndFlags); + if (mergedTypeOptions.HasReflectMethodFilters()) { // If merging filter has non-default method flags but no filter then we need to append it as a filtered modification @@ -1879,7 +1879,7 @@ BfTypeOptions* BfModule::GetTypeOptions(BfTypeDef* typeDef) } mergedTypeOptions.mAndFlags = (BfOptionFlags)(mergedTypeOptions.mAndFlags | BfOptionFlags_Reflect_MethodMask); - mergedTypeOptions.mOrFlags = (BfOptionFlags)(mergedTypeOptions.mOrFlags & ~BfOptionFlags_Reflect_MethodMask); + mergedTypeOptions.mOrFlags = (BfOptionFlags)(mergedTypeOptions.mOrFlags & ~BfOptionFlags_Reflect_MethodMask); } if (typeOptions.mAllocStackTraceDepth != -1) @@ -1887,7 +1887,7 @@ BfTypeOptions* BfModule::GetTypeOptions(BfTypeDef* typeDef) for (auto filter : typeOptions.mReflectMethodFilters) mergedTypeOptions.mReflectMethodFilters.Add(filter); for (auto filter : typeOptions.mReflectMethodAttributeFilters) - mergedTypeOptions.mReflectMethodAttributeFilters.Add(filter); + mergedTypeOptions.mReflectMethodAttributeFilters.Add(filter); } matchedIdx = typeOptionsCount + (int)mContext->mSystem->mMergedTypeOptions.size(); mContext->mSystem->mMergedTypeOptions.push_back(mergedTypeOptions); @@ -1923,7 +1923,7 @@ bool BfModule::ApplyTypeOptionMethodFilters(bool includeMethod, BfMethodDef* met if ((filter.mAndFlags | findFlag) != 0) includeMethod = true; } - } + } } return includeMethod; @@ -1971,9 +1971,9 @@ int BfModule::GenerateTypeOptions(BfCustomAttributes* customAttributes, BfTypeIn int typeOptionsCount = (int)mContext->mSystem->mTypeOptions.size(); if (checkTypeName) - { + { auto _CheckType = [&](BfType* type) - { + { StringImpl typeName = TypeToString(type); for (int optionIdx = 0; optionIdx < (int)mContext->mSystem->mTypeOptions.size(); optionIdx++) @@ -2014,7 +2014,7 @@ int BfModule::GenerateTypeOptions(BfCustomAttributes* customAttributes, BfTypeIn } if (matched) break; - } + } } else if (BfCheckWildcard(filter, typeName)) { @@ -2032,7 +2032,7 @@ int BfModule::GenerateTypeOptions(BfCustomAttributes* customAttributes, BfTypeIn { auto underlyingType = typeInstance->GetUnderlyingType(); if (underlyingType != NULL) - { + { _CheckType(underlyingType); } else @@ -2045,10 +2045,10 @@ int BfModule::GenerateTypeOptions(BfCustomAttributes* customAttributes, BfTypeIn { BF_ASSERT(typeInstance->IsGenericTypeInstance()); auto innerType = typeInstance->mGenericTypeInfo->mTypeGenericArguments[0]; - auto ptrType = CreatePointerType(innerType); + auto ptrType = CreatePointerType(innerType); _CheckType(ptrType); } - + _CheckType(typeInstance); } @@ -2124,23 +2124,23 @@ void BfModule::SetTypeOptions(BfTypeInstance* typeInstance) BfCEParseContext BfModule::CEEmitParse(BfTypeInstance* typeInstance, BfTypeDef* declaringType, const StringImpl& src, BfAstNode* refNode, BfCeTypeEmitSourceKind emitSourceKind) { if (mCompiler->mResolvePassData != NULL) - mCompiler->mResolvePassData->mHadEmits = true; - + mCompiler->mResolvePassData->mHadEmits = true; + BfCEParseContext ceParseContext; ceParseContext.mFailIdx = mCompiler->mPassInstance->mFailedIdx; ceParseContext.mWarnIdx = mCompiler->mPassInstance->mWarnIdx; bool createdParser = false; int startSrcIdx = 0; - + BfParser* emitParser = NULL; - int64 emitSourceMapKey = ((int64)declaringType->mPartialIdx << 32) | refNode->mSrcStart; + int64 emitSourceMapKey = ((int64)declaringType->mPartialIdx << 32) | refNode->mSrcStart; if (typeInstance->mCeTypeInfo == NULL) typeInstance->mCeTypeInfo = new BfCeTypeInfo(); auto ceTypeInfo = typeInstance->mCeTypeInfo; if (ceTypeInfo->mNext != NULL) - ceTypeInfo = ceTypeInfo->mNext; + ceTypeInfo = ceTypeInfo->mNext; BfCeTypeEmitSource* ceEmitSource = NULL; if ((mCurMethodState != NULL) && (mCurMethodState->mClosureState != NULL) && (mCurMethodState->mClosureState->mCapturing)) { @@ -2175,35 +2175,35 @@ BfCEParseContext BfModule::CEEmitParse(BfTypeInstance* typeInstance, BfTypeDef* } ceEmitSource->mKind = emitSourceKind; } - + BfLogSysM("CEEmitParse type %p ceTypeInfo %p\n", typeInstance, ceTypeInfo); int emitSrcStart = 0; BfEmitEmbedEntry* emitEmbedEntry = NULL; - + if (typeInstance->mTypeDef->mEmitParent == NULL) { BF_ASSERT(typeInstance->mTypeDef->mNextRevision == NULL); - + BfTypeDef* emitTypeDef = new BfTypeDef(); emitTypeDef->mEmitParent = typeInstance->mTypeDef; mSystem->CopyTypeDef(emitTypeDef, typeInstance->mTypeDef); emitTypeDef->mDefState = BfTypeDef::DefState_Emitted; - typeInstance->mTypeDef = emitTypeDef; - - createdParser = true; + typeInstance->mTypeDef = emitTypeDef; + + createdParser = true; emitParser = new BfParser(mSystem, typeInstance->mTypeDef->mProject); emitParser->mIsEmitted = true; - + BfLogSys(mSystem, "Emit typeDef for type %p created %p parser %p typeDecl %p\n", typeInstance, emitTypeDef, emitParser, emitTypeDef->mTypeDeclaration); String typeName = TypeToString(typeInstance, BfTypeNameFlag_AddProjectName); - + if ((mCompiler->mResolvePassData != NULL) && (!mCompiler->mResolvePassData->mEmitEmbedEntries.IsEmpty())) mCompiler->mResolvePassData->mEmitEmbedEntries.TryGetValue(typeName, &emitEmbedEntry); - + emitParser->mFileName = "$Emit$"; emitParser->mFileName += typeName; @@ -2215,7 +2215,7 @@ BfCEParseContext BfModule::CEEmitParse(BfTypeInstance* typeInstance, BfTypeDef* { emitEmbedEntry->mRevision = typeInstance->mRevision; emitEmbedEntry->mParser = emitParser; - emitEmbedEntry->mParser->mSourceClassifier = new BfSourceClassifier(emitEmbedEntry->mParser, NULL); + emitEmbedEntry->mParser->mSourceClassifier = new BfSourceClassifier(emitEmbedEntry->mParser, NULL); mCompiler->mPassInstance->mFilterErrorsTo.Add(emitEmbedEntry->mParser->mParserData); if (emitEmbedEntry->mCursorIdx != -1) @@ -2230,7 +2230,7 @@ BfCEParseContext BfModule::CEEmitParse(BfTypeInstance* typeInstance, BfTypeDef* { if (methodInstance == NULL) return; - methodInstance->mMethodDef = emitTypeDef->mMethods[methodInstance->mMethodDef->mIdx]; + methodInstance->mMethodDef = emitTypeDef->mMethods[methodInstance->mMethodDef->mIdx]; }; for (auto& methodInstanceGroup : typeInstance->mMethodInstanceGroups) @@ -2248,7 +2248,7 @@ BfCEParseContext BfModule::CEEmitParse(BfTypeInstance* typeInstance, BfTypeDef* emitParser = typeInstance->mTypeDef->mSource->ToParser(); if ((mCompiler->mResolvePassData != NULL) && (!mCompiler->mResolvePassData->mEmitEmbedEntries.IsEmpty())) - { + { int dollarPos = (int)emitParser->mFileName.LastIndexOf('$'); if (dollarPos != -1) mCompiler->mResolvePassData->mEmitEmbedEntries.TryGetValue(emitParser->mFileName.Substring(dollarPos + 1), &emitEmbedEntry); @@ -2276,7 +2276,7 @@ BfCEParseContext BfModule::CEEmitParse(BfTypeInstance* typeInstance, BfTypeDef* { // Add the warning changes occur before the start of the buffer. // We use this conservatively now - any temporary disabling will permanently disable - for (auto& warning : parserData->mWarningEnabledChanges) + for (auto& warning : parserData->mWarningEnabledChanges) { if (!warning.mValue.mEnable) emitParser->mParserData->mWarningEnabledChanges[-warning.mValue.mWarningNumber] = warning.mValue; @@ -2308,7 +2308,7 @@ BfCEParseContext BfModule::CEEmitParse(BfTypeInstance* typeInstance, BfTypeDef* charDataPtr[i].mDisplayFlags = 0; } - emitEmbedEntry->mParser->mSourceClassifier->mCharData = emitEmbedEntry->mCharData.mVals; + emitEmbedEntry->mParser->mSourceClassifier->mCharData = emitEmbedEntry->mCharData.mVals; } if (createdParser) @@ -2340,21 +2340,21 @@ void BfModule::UpdateCEEmit(CeEmitContext* ceEmitContext, BfTypeInstance* typeIn if (ceEmitContext->mEmitData.IsEmpty()) return; - + String src; - + // if (typeInstance->mTypeDef->mEmitParent != NULL) // src += "\n\n"; // src += "// Code emission in "; // src += ctxString; // src += "\n\n"; - src += ceEmitContext->mEmitData; + src += ceEmitContext->mEmitData; ceEmitContext->mEmitData.Clear(); - BfCEParseContext ceParseContext = CEEmitParse(typeInstance, declaringType, src, refNode, emitSourceKind); + BfCEParseContext ceParseContext = CEEmitParse(typeInstance, declaringType, src, refNode, emitSourceKind); auto emitParser = typeInstance->mTypeDef->mSource->ToParser(); - + auto typeDeclaration = emitParser->mAlloc->Alloc(); BfReducer bfReducer; @@ -2395,9 +2395,9 @@ void BfModule::UpdateCEEmit(CeEmitContext* ceEmitContext, BfTypeInstance* typeIn void BfModule::HandleCEAttributes(CeEmitContext* ceEmitContext, BfTypeInstance* typeInstance, BfFieldInstance* fieldInstance, BfCustomAttributes* customAttributes, Dictionary& prevAttrInstances, bool underlyingTypeDeferred) { for (auto& customAttribute : customAttributes->mAttributes) - { + { auto attrType = customAttribute.mType; - + BfMethodInstance* methodInstance = NULL; bool isFieldApply = false; BfIRValue irValue; @@ -2413,7 +2413,7 @@ void BfModule::HandleCEAttributes(CeEmitContext* ceEmitContext, BfTypeInstance* { isFieldApply = false; isFieldApply = (ceEmitContext != NULL) && (fieldInstance != NULL) && (ifaceEntry.mInterfaceType->IsInstanceOf(mCompiler->mIOnFieldInitTypeDef)); - + if ((isFieldApply) || ((ceEmitContext != NULL) && (ifaceEntry.mInterfaceType->IsInstanceOf(mCompiler->mIComptimeTypeApply))) || ((ceEmitContext != NULL) && (ifaceEntry.mInterfaceType->IsInstanceOf(mCompiler->mIOnTypeInitTypeDef))) || @@ -2421,7 +2421,7 @@ void BfModule::HandleCEAttributes(CeEmitContext* ceEmitContext, BfTypeInstance* { // Passes } - else + else continue; prevAttrInstances.TryGetValue(checkAttrType, &irValue); @@ -2440,7 +2440,7 @@ void BfModule::HandleCEAttributes(CeEmitContext* ceEmitContext, BfTypeInstance* SetAndRestoreValue prevEmitContext(mCompiler->mCeMachine->mCurEmitContext, ceEmitContext); auto ceContext = mCompiler->mCeMachine->AllocContext(); - + BfIRValue attrVal =ceContext->CreateAttribute(customAttribute.mRef, this, typeInstance->mConstHolder, &customAttribute); for (int baseIdx = 0; baseIdx < checkDepth; baseIdx++) attrVal = mBfIRBuilder->CreateExtractValue(attrVal, 0); @@ -2455,7 +2455,7 @@ void BfModule::HandleCEAttributes(CeEmitContext* ceEmitContext, BfTypeInstance* { SetAndRestoreValue prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, true); SizedArray fieldData = - { + { mBfIRBuilder->CreateConstAggZero(mBfIRBuilder->MapType(fieldInfoType->ToTypeInstance()->mBaseType, BfIRPopulateType_Identity)), mBfIRBuilder->CreateTypeOf(mCurTypeInstance), // mTypeInstance CreateFieldData(fieldInstance, -1) @@ -2482,7 +2482,7 @@ void BfModule::HandleCEAttributes(CeEmitContext* ceEmitContext, BfTypeInstance* continue; } - DoPopulateType_CeCheckEnum(typeInstance, underlyingTypeDeferred); + DoPopulateType_CeCheckEnum(typeInstance, underlyingTypeDeferred); if (fieldInstance != NULL) mCompiler->mCeMachine->mFieldInstanceSet.Add(fieldInstance); BfTypedValue result; @@ -2517,7 +2517,7 @@ void BfModule::HandleCEAttributes(CeEmitContext* ceEmitContext, BfTypeInstance* continue; if (typeInstance->mDefineState == BfTypeDefineState_DefinedAndMethodsSlotted) - return; + return; if (typeInstance->mDefineState != BfTypeDefineState_CETypeInit) { @@ -2572,7 +2572,7 @@ void BfModule::HandleCEAttributes(CeEmitContext* ceEmitContext, BfTypeInstance* } } - mCompiler->mCeMachine->ReleaseContext(ceContext); + mCompiler->mCeMachine->ReleaseContext(ceContext); } } @@ -2585,27 +2585,27 @@ void BfModule::CEMixin(BfAstNode* refNode, const StringImpl& code) { Fail("Invalid code mixin", refNode); return; - } + } auto activeTypeDef = mCurMethodInstance->mMethodDef->mDeclaringType; //auto emitParser = activeTypeDef->mEmitParser; - + String src; // if (mCurTypeInstance->mTypeDef->mEmitParent != NULL) // src += "\n\n"; -// src += "// Code emission in "; -// src += MethodToString(mCurMethodInstance); +// src += "// Code emission in "; +// src += MethodToString(mCurMethodInstance); // src += "\n"; src += code; - BfReducer bfReducer; + BfReducer bfReducer; bfReducer.mPassInstance = mCompiler->mPassInstance; bfReducer.mSystem = mSystem; bfReducer.mCurTypeDecl = activeTypeDef->mTypeDeclaration; bfReducer.mCurMethodDecl = BfNodeDynCast(mCurMethodInstance->mMethodDef->mMethodDeclaration); - + SetAndRestoreValue prevCustomAttribute(mCurMethodState->mEmitRefNode, refNode); - + EmitEnsureInstructionAt(); BfCEParseContext ceParseContext = CEEmitParse(mCurTypeInstance, activeTypeDef, src, refNode, BfCeTypeEmitSourceKind_Method); @@ -2629,9 +2629,9 @@ void BfModule::CEMixin(BfAstNode* refNode, const StringImpl& code) } void BfModule::ExecuteCEOnCompile(CeEmitContext* ceEmitContext, BfTypeInstance* typeInstance, BfCEOnCompileKind onCompileKind, bool underlyingTypeDeferred) -{ +{ Dictionary prevAttrInstances; - + if (typeInstance->mCustomAttributes != NULL) HandleCEAttributes(ceEmitContext, typeInstance, NULL, typeInstance->mCustomAttributes, prevAttrInstances, underlyingTypeDeferred); @@ -2674,7 +2674,7 @@ void BfModule::ExecuteCEOnCompile(CeEmitContext* ceEmitContext, BfTypeInstance* if (!typeInstance->IsTypeMemberIncluded(methodDef->mDeclaringType, mCurTypeInstance->mTypeDef, this)) continue; } - + if (methodDef->mIdx >= typeInstance->mMethodInstanceGroups.mSize) continue; @@ -2689,7 +2689,7 @@ void BfModule::ExecuteCEOnCompile(CeEmitContext* ceEmitContext, BfTypeInstance* } HandleCEAttributes(ceEmitContext, typeInstance, NULL, methodInstanceGroup.mDefaultCustomAttributes, prevAttrInstances, underlyingTypeDeferred); } - } + } int methodCount = (int)typeInstance->mTypeDef->mMethods.size(); for (int methodIdx = 0; methodIdx < methodCount; methodIdx++) @@ -2706,7 +2706,7 @@ void BfModule::ExecuteCEOnCompile(CeEmitContext* ceEmitContext, BfTypeInstance* typeState.mForceActiveTypeDef = methodDef->mDeclaringType; SetAndRestoreValue prevTypeState(mContext->mCurTypeState, &typeState); - bool wantsAttributes = false; + bool wantsAttributes = false; BfAttributeDirective* checkAttributes = methodDeclaration->mAttributes; while (checkAttributes != NULL) { @@ -2723,13 +2723,13 @@ void BfModule::ExecuteCEOnCompile(CeEmitContext* ceEmitContext, BfTypeInstance* checkAttributes = checkAttributes->mNextAttribute; } - + if (!wantsAttributes) continue; auto customAttributes = GetCustomAttributes(methodDeclaration->mAttributes, BfAttributeTargets_Method); defer({ delete customAttributes; }); - + auto onCompileAttribute = customAttributes->Get(mCompiler->mOnCompileAttributeTypeDef); if (onCompileAttribute == NULL) continue; @@ -2756,7 +2756,7 @@ void BfModule::ExecuteCEOnCompile(CeEmitContext* ceEmitContext, BfTypeInstance* continue; } - SetAndRestoreValue prevEmitContext(mCompiler->mCeMachine->mCurEmitContext); + SetAndRestoreValue prevEmitContext(mCompiler->mCeMachine->mCurEmitContext); if (onCompileKind == BfCEOnCompileKind_TypeInit) { mCompiler->mCeMachine->mCurEmitContext = ceEmitContext; @@ -2765,10 +2765,10 @@ void BfModule::ExecuteCEOnCompile(CeEmitContext* ceEmitContext, BfTypeInstance* DoPopulateType_CeCheckEnum(typeInstance, underlyingTypeDeferred); auto methodInstance = GetRawMethodInstanceAtIdx(typeInstance, methodDef->mIdx); auto result = mCompiler->mCeMachine->Call(methodDef->GetRefNode(), this, methodInstance, {}, (CeEvalFlags)(CeEvalFlags_PersistantError | CeEvalFlags_DeferIfNotOnlyError), NULL); - + if ((onCompileKind == BfCEOnCompileKind_TypeDone) && (typeInstance->mDefineState > BfTypeDefineState_CETypeInit)) { - // Type done, okay + // Type done, okay } else if (typeInstance->mDefineState != BfTypeDefineState_CETypeInit) { @@ -2776,7 +2776,7 @@ void BfModule::ExecuteCEOnCompile(CeEmitContext* ceEmitContext, BfTypeInstance* AssertErrorState(); } else - { + { if ((!result) && (mCompiler->mFastFinish)) { if ((typeInstance->mCeTypeInfo != NULL) && (typeInstance->mCeTypeInfo->mNext == NULL)) @@ -2805,7 +2805,7 @@ void BfModule::ExecuteCEOnCompile(CeEmitContext* ceEmitContext, BfTypeInstance* } else if ((ceEmitContext->mFailed) && (typeInstance->mCeTypeInfo != NULL)) typeInstance->mCeTypeInfo->mFailed = true; - + if (!ceEmitContext->mEmitData.IsEmpty()) { String ctxStr = "OnCompile execution of "; @@ -2819,7 +2819,7 @@ void BfModule::ExecuteCEOnCompile(CeEmitContext* ceEmitContext, BfTypeInstance* if (mCompiler->mCanceling) { DeferRebuildType(typeInstance); - } + } } // if ((!typeInstance->IsInstanceOf(mCompiler->mValueTypeTypeDef)) && @@ -2864,13 +2864,13 @@ void BfModule::DoCEEmit(BfMethodInstance* methodInstance) CeEmitContext ceEmitContext; ceEmitContext.mMethodInstance = methodInstance; - + Dictionary prevAttrInstances; for (auto& customAttribute : customAttributes->mAttributes) { auto attrType = customAttribute.mType; - + BfMethodInstance* applyMethodInstance = NULL; BfIRValue irValue; int checkDepth = 0; @@ -2901,7 +2901,7 @@ void BfModule::DoCEEmit(BfMethodInstance* methodInstance) } if (applyMethodInstance == NULL) - continue; + continue; SetAndRestoreValue prevEmitContext(mCompiler->mCeMachine->mCurEmitContext, &ceEmitContext); auto ceContext = mCompiler->mCeMachine->AllocContext(); @@ -2913,14 +2913,13 @@ void BfModule::DoCEEmit(BfMethodInstance* methodInstance) SizedArray args; if (!attrType->IsValuelessType()) args.Add(attrVal); - + auto methodInfoType = ResolveTypeDef(mCompiler->mReflectMethodInfoTypeDef); SizedArray methodData = { mBfIRBuilder->CreateConstAggZero(mBfIRBuilder->MapType(methodInfoType->ToTypeInstance()->mBaseType, BfIRPopulateType_Identity)), mBfIRBuilder->CreateTypeOf(mCurTypeInstance), // mTypeInstance GetConstValue((int64)methodInstance, GetPrimitiveType(BfTypeCode_Int64)), // mNativeMethodInstance - }; FixConstValueParams(methodInfoType->ToTypeInstance(), methodData, true); auto fieldDataAgg = mBfIRBuilder->CreateConstAgg(mBfIRBuilder->MapType(methodInfoType, BfIRPopulateType_Identity), methodData); @@ -2941,8 +2940,8 @@ void BfModule::DoCEEmit(BfMethodInstance* methodInstance) } mCompiler->mCeMachine->mMethodInstanceSet.Add(methodInstance); - auto activeTypeDef = typeInstance->mTypeDef; - + auto activeTypeDef = typeInstance->mTypeDef; + BfTypedValue result; /// { @@ -2952,7 +2951,7 @@ void BfModule::DoCEEmit(BfMethodInstance* methodInstance) callSource.mRefNode = customAttribute.mRef; callSource.mKind = CeCallSource::Kind_MethodInit; result = ceContext->Call(callSource, this, applyMethodInstance, args, CeEvalFlags_ForceReturnThis, NULL); - } + } if (result.mType == methodInstance->GetOwner()) prevAttrInstances[methodInstance->GetOwner()] = result.mValue; @@ -2963,7 +2962,7 @@ void BfModule::DoCEEmit(BfMethodInstance* methodInstance) if ((!ceEmitContext.mEmitData.IsEmpty()) || (!ceEmitContext.mExitEmitData.IsEmpty())) { - String src; + String src; // src += "// Code emission in comptime ApplyToMethod of "; // src += TypeToString(attrType); // src += " to "; @@ -2971,7 +2970,7 @@ void BfModule::DoCEEmit(BfMethodInstance* methodInstance) // src += " "; // src += customAttribute.mRef->LocationToString(); // src += "\n"; - + //auto emitTypeDef = typeInstance->mCeTypeInfo->mNext->mTypeDef; //auto emitParser = emitTypeDef->mSource->ToParser(); @@ -2979,12 +2978,12 @@ void BfModule::DoCEEmit(BfMethodInstance* methodInstance) BfReducer bfReducer; //bfReducer.mSource = emitParser; - bfReducer.mPassInstance = mCompiler->mPassInstance; + bfReducer.mPassInstance = mCompiler->mPassInstance; bfReducer.mSystem = mSystem; bfReducer.mCurTypeDecl = activeTypeDef->mTypeDeclaration; bfReducer.mCurMethodDecl = BfNodeDynCast(methodInstance->mMethodDef->mMethodDeclaration); - BfAstNode* bodyNode = NULL; + BfAstNode* bodyNode = NULL; if (auto methodDecl = BfNodeDynCast(methodInstance->mMethodDef->mMethodDeclaration)) bodyNode = methodDecl->mBody; @@ -2999,7 +2998,7 @@ void BfModule::DoCEEmit(BfMethodInstance* methodInstance) if (!ceEmitContext.mEmitData.IsEmpty()) { - SetAndRestoreValue prevCustomAttribute(mCurMethodState->mEmitRefNode, customAttribute.mRef); + SetAndRestoreValue prevCustomAttribute(mCurMethodState->mEmitRefNode, customAttribute.mRef); String entrySrc = src; // if (mCurTypeInstance->mTypeDef->mEmitParent != NULL) // entrySrc += "\n\n"; @@ -3055,7 +3054,7 @@ void BfModule::DoCEEmit(BfMethodInstance* methodInstance) } } - mCompiler->mCeMachine->ReleaseContext(ceContext); + mCompiler->mCeMachine->ReleaseContext(ceContext); } } @@ -3063,7 +3062,7 @@ void BfModule::PopulateUsingFieldData(BfTypeInstance* typeInstance) { if (typeInstance->mTypeInfoEx == NULL) typeInstance->mTypeInfoEx = new BfTypeInfoEx(); - + BfUsingFieldData* usingFieldData; if (typeInstance->mTypeInfoEx->mUsingFieldData != NULL) { @@ -3089,7 +3088,7 @@ void BfModule::PopulateUsingFieldData(BfTypeInstance* typeInstance) usingFieldData = new BfUsingFieldData(); typeInstance->mTypeInfoEx->mUsingFieldData = usingFieldData; } - + HashSet checkedTypeSet; Array memberRefs; std::function _CheckType = [&](BfTypeInstance* usingType, bool staticOnly) @@ -3118,7 +3117,7 @@ void BfModule::PopulateUsingFieldData(BfTypeInstance* typeInstance) usingFieldData->mEntries.TryAdd(fieldDef->mName, NULL, &entry); SizedArray lookup; for (auto entry : memberRefs) - lookup.Add(entry); + lookup.Add(entry); entry->mLookups.Add(lookup); } @@ -3141,7 +3140,7 @@ void BfModule::PopulateUsingFieldData(BfTypeInstance* typeInstance) checkTypeState = checkTypeState->mPrevState; } - if (!isPopulatingType) + if (!isPopulatingType) { // We need to populate this type now PopulateType(usingType, BfPopulateType_Data_Soft); @@ -3172,9 +3171,9 @@ void BfModule::PopulateUsingFieldData(BfTypeInstance* typeInstance) { BfUsingFieldData::Entry* entry = NULL; usingFieldData->mEntries.TryAdd(propDef->mName, NULL, &entry); - SizedArray lookup; + SizedArray lookup; for (auto entry : memberRefs) - lookup.Add(entry); + lookup.Add(entry); entry->mLookups.Add(lookup); } @@ -3194,12 +3193,12 @@ void BfModule::PopulateUsingFieldData(BfTypeInstance* typeInstance) if (methodInstance == NULL) continue; if (methodDef->mMethodType == BfMethodType_PropertyGetter) - { + { propType = methodInstance->mReturnType; break; } if (methodDef->mMethodType == BfMethodType_PropertySetter) - { + { if (methodInstance->GetParamCount() > 0) { propType = methodInstance->GetParamType(0); @@ -3222,7 +3221,7 @@ void BfModule::PopulateUsingFieldData(BfTypeInstance* typeInstance) // No auto methods if (methodDef->mMethodDeclaration == NULL) - continue; + continue; memberRefs.Add(BfUsingFieldData::MemberRef(usingType, methodDef)); defer( @@ -3234,14 +3233,14 @@ void BfModule::PopulateUsingFieldData(BfTypeInstance* typeInstance) { BfUsingFieldData::Entry* entry = NULL; usingFieldData->mMethods.TryAdd(methodDef->mName, NULL, &entry); - SizedArray lookup; + SizedArray lookup; for (auto entry : memberRefs) - lookup.Add(entry); + lookup.Add(entry); entry->mLookups.Add(lookup); } } }; - + _CheckType(typeInstance, false); } @@ -3291,7 +3290,7 @@ void BfModule::DoPopulateType_TypeAlias(BfTypeAliasType* typeAlias) SetAndRestoreValue prevTypeInstance(mCurTypeInstance, typeAlias); SetAndRestoreValue prevMethodInstance(mCurMethodInstance, NULL); SetAndRestoreValue prevMethodState(mCurMethodState, NULL); - + BF_ASSERT(mCurMethodInstance == NULL); auto typeDef = typeAlias->mTypeDef; auto typeAliasDecl = (BfTypeAliasDeclaration*)typeDef->mTypeDeclaration; @@ -3299,10 +3298,10 @@ void BfModule::DoPopulateType_TypeAlias(BfTypeAliasType* typeAlias) if (typeAlias->mBaseType == NULL) typeAlias->mBaseType = ResolveTypeDef(mCompiler->mValueTypeTypeDef)->ToTypeInstance(); - + if ((typeAlias->mGenericTypeInfo != NULL) && (!typeAlias->mGenericTypeInfo->mFinishedGenericParams)) FinishGenericParams(typeAlias); - + BfTypeState typeState(mCurTypeInstance, mContext->mCurTypeState); typeState.mPopulateType = BfPopulateType_Data; typeState.mCurBaseTypeRef = typeAliasDecl->mAliasToType; @@ -3319,7 +3318,7 @@ void BfModule::DoPopulateType_TypeAlias(BfTypeAliasType* typeAlias) if (!CheckCircularDataError()) { if (typeAliasDecl->mAliasToType != NULL) - aliasToType = ResolveTypeRef(typeAliasDecl->mAliasToType, BfPopulateType_IdentityNoRemapAlias, + aliasToType = ResolveTypeRef(typeAliasDecl->mAliasToType, BfPopulateType_IdentityNoRemapAlias, (BfResolveTypeRefFlags)(BfResolveTypeRefFlag_AllowGenericParamConstValue | BfResolveTypeRefFlag_AllowImplicitConstExpr)); } @@ -3335,14 +3334,14 @@ void BfModule::DoPopulateType_TypeAlias(BfTypeAliasType* typeAlias) } if (aliasToType != NULL) - { + { AddDependency(aliasToType, typeAlias, BfDependencyMap::DependencyFlag_DerivedFrom); } else mContext->mFailTypes.Add(typeAlias); if (typeAlias->mTypeFailed) - aliasToType = NULL; + aliasToType = NULL; if ((typeAlias->mAliasToType != NULL) && (typeAlias->mAliasToType != aliasToType) && (!typeAlias->mDependencyMap.IsEmpty())) mContext->QueueMidCompileRebuildDependentTypes(typeAlias, "type alias remapped"); @@ -3362,7 +3361,7 @@ void BfModule::DoPopulateType_TypeAlias(BfTypeAliasType* typeAlias) typeAlias->mCustomAttributes = GetCustomAttributes(typeDef->mTypeDeclaration->mAttributes, BfAttributeTargets_Alias); if (typeAlias->mGenericTypeInfo != NULL) - { + { DoPopulateType_SetGenericDependencies(typeAlias); } } @@ -3370,7 +3369,7 @@ void BfModule::DoPopulateType_TypeAlias(BfTypeAliasType* typeAlias) void BfModule::DoPopulateType_InitSearches(BfTypeInstance* typeInstance) { auto typeDef = typeInstance->mTypeDef; - + auto _AddStaticSearch = [&](BfTypeDef* typeDef) { if (!typeDef->mStaticSearch.IsEmpty()) @@ -3638,9 +3637,9 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy if ((populateType <= BfPopulateType_Data) && (resolvedTypeRef->mDefineState >= BfTypeDefineState_Defined)) return; - + auto typeInstance = resolvedTypeRef->ToTypeInstance(); - auto typeDef = typeInstance->mTypeDef; + auto typeDef = typeInstance->mTypeDef; BF_ASSERT((typeInstance->mTypeDef->mNextRevision == NULL) || (mCompiler->IsAutocomplete())); @@ -3654,7 +3653,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy if (!typeInstance->mTypeIncomplete) return; } - typeInstance->mBaseTypeMayBeIncomplete = false; + typeInstance->mBaseTypeMayBeIncomplete = false; BF_ASSERT(mIsModuleMutable); @@ -3669,7 +3668,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy if (typeInstance->mResolvingConstField) return; - + // Partial population break out point if ((populateType >= BfPopulateType_Identity) && (populateType <= BfPopulateType_IdentityNoRemapAlias)) return; @@ -3695,7 +3694,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy BfLogSysM("DoPopulateType %p bailing due to IsCePaused\n", resolvedTypeRef); return; } - + auto _CheckTypeDone = [&]() { if (typeInstance->mNeedsMethodProcessing) @@ -3717,7 +3716,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy { resolvedTypeRef->mSize = typeInstance->mAlign = mSystem->mPtrSize; } - + BF_ASSERT((typeInstance->mMethodInstanceGroups.size() == 0) || (typeInstance->mMethodInstanceGroups.size() == typeDef->mMethods.size()) || (typeInstance->mCeTypeInfo != NULL) || (typeInstance->IsBoxed())); typeInstance->mMethodInstanceGroups.Resize(typeDef->mMethods.size()); for (int i = 0; i < (int)typeInstance->mMethodInstanceGroups.size(); i++) @@ -3726,24 +3725,24 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy typeInstance->mMethodInstanceGroups[i].mMethodIdx = i; } - AutoDisallowYield disableYield(mSystem); + AutoDisallowYield disableYield(mSystem); SetAndRestoreValue prevTypeInstance(mCurTypeInstance, typeInstance); SetAndRestoreValue prevMethodInstance(mCurMethodInstance, NULL); SetAndRestoreValue prevMethodState(mCurMethodState, NULL); - // WHY were we clearing these values? + // WHY were we clearing these values? //SetAndRestoreValue prevHadError(mHadBuildError, false); //SetAndRestoreValue prevHadWarning(mHadBuildWarning, false); BfTypeState typeState(mCurTypeInstance, mContext->mCurTypeState); typeState.mPopulateType = populateType; SetAndRestoreValue prevTypeState(mContext->mCurTypeState, &typeState); - + if (typeInstance->IsGenericTypeInstance()) { auto genericTypeInst = (BfTypeInstance*)typeInstance; if (!genericTypeInst->mGenericTypeInfo->mInitializedGenericParams) - InitGenericParams(resolvedTypeRef); + InitGenericParams(resolvedTypeRef); } if (resolvedTypeRef->IsTypeAlias()) @@ -3771,7 +3770,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy // If we're not the defining context then we don't report errors for this type, but errors will still put the system // into an errored state SetAndRestoreValue prevReportErrors(mReportErrors, reportErrors); - + if (typeInstance->mIsFinishingType) { if (typeInstance->mTypeFailed) @@ -3800,7 +3799,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy BP_ZONE("DoPopulateType:CheckStack"); StackHelper stackHelper; if (!stackHelper.CanStackExpand(128 * 1024)) - { + { if (!stackHelper.Execute([&]() { DoPopulateType(resolvedTypeRef, populateType); @@ -3813,9 +3812,9 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy } bool underlyingTypeDeferred = false; - BfType* underlyingType = NULL; + BfType* underlyingType = NULL; if (typeInstance->mBaseType != NULL) - { + { if (typeInstance->IsTypedPrimitive()) underlyingType = typeInstance->GetUnderlyingType(); if ((typeInstance->mRebuildFlags & BfTypeRebuildFlag_UnderlyingTypeDeferred) != 0) @@ -3834,7 +3833,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy } if (!hasPayloads) - { + { bool hadType = false; BfAstNode* deferredErrorNode = NULL; @@ -3844,7 +3843,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy { SetAndRestoreValue prevTypeRef(mContext->mCurTypeState->mCurBaseTypeRef, baseTypeRef); SetAndRestoreValue prevDefineState(typeInstance->mDefineState, BfTypeDefineState_ResolvingBaseType); - SetAndRestoreValue prevIgnoreError(mIgnoreErrors, true); + SetAndRestoreValue prevIgnoreError(mIgnoreErrors, true); SetAndRestoreValue prevSkipTypeProtectionChecks(typeInstance->mSkipTypeProtectionChecks, true); auto baseType = ResolveTypeRef(baseTypeRef, BfPopulateType_Declaration); @@ -3894,7 +3893,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy (!typeInstance->mTypeFailed)) { for (auto baseTypeRef : typeDef->mBaseTypes) - { + { auto declTypeDef = typeDef; if (typeDef->mIsCombinedPartial) declTypeDef = typeDef->mPartials.front(); @@ -3952,7 +3951,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy // so we need to take care not to truncate their fieldInstance vector here (thus the 'wantFieldCount' check above) typeInstance->mFieldInstances.Resize(wantFieldCount); } - + if (underlyingType != NULL) { auto fieldInstance = &typeInstance->mFieldInstances.back(); @@ -3965,19 +3964,19 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy typeInstance->mAlign = underlyingType->mAlign; typeInstance->mInstSize = underlyingType->mSize; typeInstance->mInstAlign = underlyingType->mAlign; - typeInstance->mHasPackingHoles = underlyingType->HasPackingHoles(); + typeInstance->mHasPackingHoles = underlyingType->HasPackingHoles(); } // Partial population break out point - if (typeInstance->mDefineState < BfTypeDefineState_Declared) + if (typeInstance->mDefineState < BfTypeDefineState_Declared) typeInstance->mDefineState = BfTypeDefineState_Declared; - + if (populateType == BfPopulateType_Declaration) { return; } - + if ((!mCompiler->mIsResolveOnly) && (!typeInstance->HasBeenInstantiated())) { for (auto& dep : typeInstance->mDependencyMap) @@ -4007,7 +4006,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy Fail("Global blocks cannot contain type declarations", typeDef->mTypeDeclaration->mTypeNode); } - /// Create DI data + /// Create DI data SizedArray llvmFieldTypes; int curFieldDataIdx = 0; @@ -4089,7 +4088,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy baseType = ResolveTypeDef(mCompiler->mFunctionTypeDef)->ToTypeInstance(); } else - { + { for (auto checkTypeRef : typeDef->mBaseTypes) { if ((typeInstance->mDefineState == BfTypeDefineState_ResolvingBaseType) && (typeInstance->mTypeFailed)) @@ -4100,7 +4099,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy declTypeDef = typeDef->mPartials.front(); SetAndRestoreValue prevTypeDef(mContext->mCurTypeState->mCurTypeDef, declTypeDef); SetAndRestoreValue prevTypeRef(mContext->mCurTypeState->mCurBaseTypeRef, checkTypeRef); - SetAndRestoreValue prevDefineState(typeInstance->mDefineState, BfTypeDefineState_ResolvingBaseType); + SetAndRestoreValue prevDefineState(typeInstance->mDefineState, BfTypeDefineState_ResolvingBaseType); bool populateBase = !typeInstance->mTypeFailed; BfType* checkType = checkType = ResolveTypeRef(checkTypeRef, BfPopulateType_Declaration); @@ -4118,7 +4117,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy } if (checkType != NULL) - { + { if (auto genericTypeInst = checkType->ToGenericTypeInstance()) { // Specialized type variations don't need to validate their constraints @@ -4201,14 +4200,13 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy Fail(StrFormat("Type '%s' cannot be declare inner type '%s' as a base type", TypeToString(typeInstance).c_str(), TypeToString(checkTypeInst).c_str()), checkTypeRef, true); - checkTypeInst = NULL; + checkTypeInst = NULL; break; } checkOuter = GetOuterType(checkOuter); } } - if (checkTypeInst != NULL) { baseType = checkTypeInst; @@ -4227,10 +4225,10 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy AssertErrorState(); // Why did we go around setting mTypeFailed on all these things? //typeInstance->mTypeFailed = true; - } + } } - wantPopulateInterfaces = true; + wantPopulateInterfaces = true; } if ((typeInstance->mCeTypeInfo != NULL) && (!typeInstance->mCeTypeInfo->mPendingInterfaces.IsEmpty())) @@ -4251,7 +4249,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy ifaceDecl.mDeclaringType = typeDef->GetDefinition(); interfaces.Add(ifaceDecl); } - } + } } if (_CheckTypeDone()) @@ -4274,9 +4272,9 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy } AddDependency(boxedType->mElementType, typeInstance, BfDependencyMap::DependencyFlag_ValueTypeMemberData); - + baseType = mContext->mBfObjectType; - } + } BfTypeInstance* baseTypeInst = NULL; @@ -4289,11 +4287,11 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy { BF_ASSERT(typeInstance->mBaseType == baseTypeInst); } - + if (auto genericTypeInst = typeInstance->ToGenericTypeInstance()) { if ((genericTypeInst->IsSpecializedType()) && (!genericTypeInst->mGenericTypeInfo->mValidatedGenericConstraints) && (!typeInstance->IsBoxed())) - { + { deferredTypeValidateList.Add({ NULL, genericTypeInst, true }); } } @@ -4466,7 +4464,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy typeInterfaceInst.mStartInterfaceTableIdx = -1; typeInterfaceInst.mStartVirtualIdx = -1; typeInterfaceInst.mIsRedeclared = false; - typeInstance->mInterfaces.push_back(typeInterfaceInst); + typeInstance->mInterfaces.push_back(typeInterfaceInst); AddDependency(checkInterface, typeInstance, BfDependencyMap::DependencyFlag_ImplementsInterface); @@ -4491,9 +4489,9 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy } if ((mCompiler->mOptions.mAllowHotSwapping) && - (typeInstance->mDefineState < BfTypeDefineState_HasInterfaces_Direct) && + (typeInstance->mDefineState < BfTypeDefineState_HasInterfaces_Direct) && (typeInstance->mDefineState != BfTypeDefineState_ResolvingBaseType)) - { + { if (typeInstance->mHotTypeData == NULL) { typeInstance->mHotTypeData = new BfHotTypeData(); @@ -4525,13 +4523,13 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy hotTypeVersion->mRefCount++; typeInstance->mHotTypeData->mTypeVersions.Add(hotTypeVersion); - BfLogSysM("BfHotTypeVersion %p created for type %p\n", hotTypeVersion, typeInstance); + BfLogSysM("BfHotTypeVersion %p created for type %p\n", hotTypeVersion, typeInstance); } BF_ASSERT(!typeInstance->mNeedsMethodProcessing); if (typeInstance->mDefineState < BfTypeDefineState_HasInterfaces_Direct) - typeInstance->mDefineState = BfTypeDefineState_HasInterfaces_Direct; - + typeInstance->mDefineState = BfTypeDefineState_HasInterfaces_Direct; + for (auto& validateEntry : deferredTypeValidateList) { SetAndRestoreValue prevAttributeTypeRef(typeState.mCurAttributeTypeRef, validateEntry.mTypeRef); @@ -4561,7 +4559,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy if (!typeInstance->mTypeFailed) { BfTypeState typeState; - typeState.mPrevState = mContext->mCurTypeState; + typeState.mPrevState = mContext->mCurTypeState; typeState.mResolveKind = BfTypeState::ResolveKind_Attributes; typeState.mType = typeInstance; SetAndRestoreValue prevTypeState(mContext->mCurTypeState, &typeState); @@ -4576,7 +4574,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy { if (partialTypeDef->mTypeDeclaration->mAttributes == NULL) continue; - + typeState.mCurTypeDef = partialTypeDef; GetCustomAttributes(customAttributes, partialTypeDef->mTypeDeclaration->mAttributes, attrTarget); } @@ -4596,21 +4594,21 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy delete customAttributes; } } - } + } } if (typeInstance->mTypeOptionsIdx == -2) { - SetTypeOptions(typeInstance); + SetTypeOptions(typeInstance); } if (populateType <= BfPopulateType_AllowStaticMethods) - return; + return; prevSkipTypeProtectionChecks.Restore(); typeInstance->mInstSize = std::max(0, typeInstance->mInstSize); - typeInstance->mInstAlign = std::max(0, typeInstance->mInstAlign); - + typeInstance->mInstAlign = std::max(0, typeInstance->mInstAlign); + ProcessCustomAttributeData(); int packing = 0; bool isUnion = false; @@ -4623,7 +4621,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy if (underlyingArraySize > 0) { typeInstance->mHasUnderlyingArray = true; - curFieldDataIdx = 0; + curFieldDataIdx = 0; } if (packing > 0) // Packed infers ordered isOrdered = true; @@ -4632,12 +4630,12 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy typeInstance->mIsUnion = true; typeInstance->mPacking = (uint8)packing; typeInstance->mIsCRepr = isCRepr; - + if (typeInstance->mTypeOptionsIdx >= 0) { auto typeOptions = mSystem->GetTypeOptions(typeInstance->mTypeOptionsIdx); if (typeOptions != NULL) - { + { typeInstance->mHasBeenInstantiated = typeOptions->Apply(typeInstance->HasBeenInstantiated(), BfOptionFlags_ReflectAssumeInstantiated); bool alwaysInclude = typeInstance->mAlwaysIncludeFlags != 0; @@ -4663,7 +4661,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy if (boxedType->IsBoxedStructPtr()) innerType = CreatePointerType(innerType); if (innerType->IsIncomplete()) - PopulateType(innerType, BfPopulateType_Data); + PopulateType(innerType, BfPopulateType_Data); auto innerTypeInst = innerType->ToTypeInstance(); if (innerTypeInst != NULL) @@ -4728,13 +4726,13 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy curFieldDataIdx++; } } - + struct DeferredResolveEntry { BfFieldDef* mFieldDef; int mTypeArrayIdx; }; - + BfSizedVector deferredVarResolves; for (auto field : typeDef->mFields) @@ -4771,9 +4769,9 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy SetAndRestoreValue prevTypeRef(mContext->mCurTypeState->mCurFieldDef, field); SetAndRestoreValue prevResolveKind(mContext->mCurTypeState->mResolveKind, BfTypeState::ResolveKind_FieldType); - + BfType* resolvedFieldType = NULL; - + auto initializer = field->GetInitializer(); if ((field->mIsAppend) && (!resolvedTypeRef->IsObject())) @@ -4781,7 +4779,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy if ((field->mIsAppend) && (isUnion)) Fail("Appended objects cannot be declared in unions", field->GetFieldDeclaration()->mExternSpecifier, true); - + if (field->IsEnumCaseEntry()) { if (typeInstance->IsEnum()) @@ -4824,7 +4822,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy // For 'let', make read-only } else - { + { BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_NoResolveGenericParam; if (initializer != NULL) resolveFlags = (BfResolveTypeRefFlags)(resolveFlags | BfResolveTypeRefFlag_AllowInferredSizedArray); @@ -4851,7 +4849,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy deferredVarResolves.push_back(resolveEntry); fieldInstance->mIsInferredType = true; - } + } else { AssertErrorState(); @@ -4870,12 +4868,12 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy if (field->mIsConst) { - // Resolve in ResolveConstField after we finish populating entire FieldInstance list + // Resolve in ResolveConstField after we finish populating entire FieldInstance list } else if (field->mIsStatic) { // Don't allocate this until after we're finished populating entire FieldInstance list, - // because we may have re-entry and create multiple instances of this static field + // because we may have re-entry and create multiple instances of this static field } } } @@ -4928,7 +4926,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy else { SetAndRestoreValue prevTypeRef(mContext->mCurTypeState->mCurFieldDef, fieldDef); - + fieldInstance->mCustomAttributes = GetCustomAttributes(fieldDef->GetFieldDeclaration()->mAttributes, fieldDef->mIsStatic ? BfAttributeTargets_StaticField : BfAttributeTargets_Field); for (auto customAttr : fieldInstance->mCustomAttributes->mAttributes) { @@ -4992,13 +4990,13 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy if (hadSoftFail) return; - + bool tryCE = true; if (typeInstance->mDefineState == BfTypeDefineState_CETypeInit) { if (populateType <= BfPopulateType_AllowStaticMethods) return; - + int foundTypeCount = 0; auto typeState = mContext->mCurTypeState; while (typeState != NULL) @@ -5029,17 +5027,17 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy tryCE = false; } } - + if ((typeInstance->mDefineState < BfTypeDefineState_CEPostTypeInit) && (tryCE)) { BF_ASSERT(!typeInstance->mTypeDef->IsEmitted()); - if (typeInstance->mCeTypeInfo != NULL) + if (typeInstance->mCeTypeInfo != NULL) typeInstance->mCeTypeInfo->mPendingInterfaces.Clear(); typeInstance->mDefineState = BfTypeDefineState_CETypeInit; bool hadNewMembers = false; - DoCEEmit(typeInstance, hadNewMembers, underlyingTypeDeferred); + DoCEEmit(typeInstance, hadNewMembers, underlyingTypeDeferred); if (typeInstance->mDefineState < BfTypeDefineState_CEPostTypeInit) typeInstance->mDefineState = BfTypeDefineState_CEPostTypeInit; @@ -5101,7 +5099,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy typeInstance->mCeTypeInfo->mTypeIFaceMap.Clear(); typeInstance->mCeTypeInfo->mHash = Val128(); } - + if (((typeInstance->mCeTypeInfo->mFailed) || (typeInstance->mTypeDef->HasParsingFailed())) && (prevHadEmissions)) { @@ -5113,7 +5111,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy if ((typeInstance->mCeTypeInfo != NULL) && (!typeInstance->mCeTypeInfo->mPendingInterfaces.IsEmpty())) hadNewMembers = true; - + if ((typeInstance->mTypeDef->IsEmitted()) && (typeInstance->mCeTypeInfo == NULL)) { BF_ASSERT(mCompiler->mCanceling); @@ -5146,7 +5144,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy if (_CheckTypeDone()) return; - + BF_ASSERT(mContext->mCurTypeState == &typeState); //BF_ASSERT(!typeInstance->mIsFinishingType); @@ -5156,7 +5154,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy BfSizedVector diFieldTypes; HashContext dataMemberHashCtx; - + if (!resolvedTypeRef->IsBoxed()) { for (auto propDef : typeDef->mProperties) @@ -5209,7 +5207,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy } } - bool isGlobalContainer = typeDef->IsGlobalsContainer(); + bool isGlobalContainer = typeDef->IsGlobalsContainer(); if (typeInstance->mBaseType != NULL) { @@ -5228,7 +5226,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy int maxDataPos = dataPos; BfSizedVector dataFieldVec; - + bool allowInstanceFields = (underlyingType == NULL); if (typeInstance->IsTypedPrimitive()) allowInstanceFields = false; @@ -5259,18 +5257,18 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy AddDependency(resolvedFieldType, typeInstance, BfDependencyMap::DependencyFlag_StaticValue); } - auto fieldDef = fieldInstance->GetFieldDef(); + auto fieldDef = fieldInstance->GetFieldDef(); if (fieldInstance->mResolvedType != NULL) { - auto resolvedFieldType = fieldInstance->GetResolvedType(); + auto resolvedFieldType = fieldInstance->GetResolvedType(); if ((!typeInstance->IsBoxed()) && (fieldDef != NULL)) { if ((fieldDef->mUsingProtection != BfProtection_Hidden) && (!resolvedFieldType->IsGenericParam()) && (!resolvedFieldType->IsObject()) && (!resolvedFieldType->IsStruct())) Warn(0, StrFormat("Field type '%s' is not applicable for 'using'", TypeToString(resolvedFieldType).c_str()), fieldDef->GetFieldDeclaration()->mConstSpecifier); if (fieldInstance->mIsEnumPayloadCase) - { + { PopulateType(resolvedFieldType, BfPopulateType_Data); if (resolvedFieldType->WantsGCMarking()) typeInstance->mWantsGCMarking = true; @@ -5330,7 +5328,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy if (!mCompiler->mIsResolveOnly) { - dataMemberHashCtx.MixinStr(fieldDef->mName); + dataMemberHashCtx.MixinStr(fieldDef->mName); dataMemberHashCtx.Mixin(resolvedFieldType->mTypeId); } @@ -5343,7 +5341,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy SetAndRestoreValue prevResolveKind(mContext->mCurTypeState->mResolveKind, BfTypeState::ResolveKind_FieldType); PopulateType(resolvedFieldType, BfPopulateType_Data); - + auto fieldTypeInst = resolvedFieldType->ToTypeInstance(); dataSize = BF_MAX(fieldTypeInst->mInstSize, 0); alignSize = BF_MAX(fieldTypeInst->mInstAlign, 1); @@ -5364,7 +5362,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy BfMethodState methodState; SetAndRestoreValue prevMethodState(mCurMethodState, &methodState); methodState.mTempKind = BfMethodState::TempKind_NonStatic; - + BfTypedValue appendIndexValue; BfExprEvaluator exprEvaluator(this); @@ -5381,7 +5379,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy bindResult.mSkipThis = true; bindResult.mWantsArgs = true; SetAndRestoreValue prevBindResult(exprEvaluator.mFunctionBindResult, &bindResult); - + BfTypedValue emptyThis(mBfIRBuilder->GetFakeVal(), resolvedTypeRef, resolvedTypeRef->IsStruct()); exprEvaluator.mBfEvalExprFlags = BfEvalExprFlags_Comptime; @@ -5411,7 +5409,6 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy { Fail(StrFormat("Append constructor '%s' does not result in a constant size", MethodToString(bindResult.mMethodInstance).c_str()), nameRefNode); } - } } else if (fieldDef->mIsAppend) @@ -5428,17 +5425,17 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy { if (!resolvedFieldType->IsValuelessType()) { - dataFieldVec.push_back(fieldInstance); + dataFieldVec.push_back(fieldInstance); } } else { - BF_ASSERT(resolvedFieldType->mSize >= 0); + BF_ASSERT(resolvedFieldType->mSize >= 0); if (alignSize > 1) dataPos = (dataPos + (alignSize - 1)) & ~(alignSize - 1); fieldInstance->mDataOffset = dataPos; - + typeInstance->mInstAlign = std::max(typeInstance->mInstAlign, alignSize); dataPos += dataSize; @@ -5447,7 +5444,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy maxDataPos = dataPos; } dataPos = startDataPos; - } + } auto fieldTypeInst = resolvedFieldType->ToTypeInstance(); if (fieldTypeInst != NULL) @@ -5496,9 +5493,9 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy else { BF_ASSERT(typeInstance->mIsUnion); - } + } } - + if ((!fieldDef->mIsStatic) && (!resolvedFieldType->IsValuelessType())) { if (isUnion) @@ -5546,7 +5543,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy alignBuckets.pop_back(); } - int alignBits = GetNumLowZeroBits(curSize) + 1; + int alignBits = GetNumLowZeroBits(curSize) + 1; alignBits = BF_MIN(alignBits, (int)alignBuckets.size() - 1); bool foundEntry = false; @@ -5559,7 +5556,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy } bool isHighestBucket = alignBits == alignBuckets.size() - 1; - + auto fieldInst = alignBuckets[alignBits][0]; alignBuckets[alignBits].RemoveAt(0); dataFieldVec.push_back(fieldInst); @@ -5573,14 +5570,14 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy break; } } - + if (!foundEntry) { // If no entries will fit, then force an entry of the smallest alignment for (int alignBits = 0; alignBits < alignBuckets.size(); alignBits++) { if (!alignBuckets[alignBits].IsEmpty()) - { + { auto fieldInst = alignBuckets[alignBits][0]; alignBuckets[alignBits].RemoveAt(0); dataFieldVec.push_back(fieldInst); @@ -5595,20 +5592,20 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy bool needsExplicitAlignment = true; - for (int fieldIdx = 0; fieldIdx < (int)dataFieldVec.size(); fieldIdx++) + for (int fieldIdx = 0; fieldIdx < (int)dataFieldVec.size(); fieldIdx++) { auto fieldInstance = dataFieldVec[fieldIdx]; auto resolvedFieldType = fieldInstance->GetResolvedType(); BF_ASSERT(resolvedFieldType->mSize >= 0); - - if (fieldInstance->mDataSize == 0) - fieldInstance->mDataSize = resolvedFieldType->mSize; + + if (fieldInstance->mDataSize == 0) + fieldInstance->mDataSize = resolvedFieldType->mSize; int dataSize = fieldInstance->mDataSize; int alignSize = fieldInstance->GetAlign(packing); - int nextDataPos = dataPos; + int nextDataPos = dataPos; nextDataPos = (dataPos + (alignSize - 1)) & ~(alignSize - 1); int padding = nextDataPos - dataPos; if ((alignSize > 1) && (needsExplicitAlignment) && (padding > 0)) @@ -5618,9 +5615,9 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy dataPos = nextDataPos; fieldInstance->mDataOffset = dataPos; fieldInstance->mDataIdx = curFieldDataIdx++; - + typeInstance->mInstAlign = std::max(typeInstance->mInstAlign, alignSize); - dataPos += dataSize; + dataPos += dataSize; } if (unionInnerType != NULL) @@ -5629,7 +5626,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy typeInstance->mInstAlign = BF_MAX(unionInnerType->mAlign, typeInstance->mInstAlign); } - // Old dataMemberHash location + // Old dataMemberHash location CheckMemberNames(typeInstance); @@ -5650,7 +5647,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy { typeInstance->mInstSize = dataPos; typeInstance->mIsCRepr = false; - } + } if ((mCompiler->mResolvePassData != NULL) && (mCompiler->mResolvePassData->mAutoComplete != NULL)) { @@ -5659,7 +5656,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy mCompiler->mResolvePassData->mAutoComplete->CheckProperty(BfNodeDynCast(propDef->mFieldDeclaration)); } } - + if (typeInstance->IsObjectOrInterface()) typeInstance->mWantsGCMarking = true; if ((mCompiler->mOptions.mEnableRealtimeLeakCheck) && (!typeInstance->mWantsGCMarking)) @@ -5674,15 +5671,15 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy typeInstance->mWantsGCMarking = true; } } - + if (typeInstance->IsValueType()) { typeInstance->mSize = typeInstance->mInstSize; typeInstance->mAlign = typeInstance->mInstAlign; - } - + } + if ((mCompiler->mOptions.mAllowHotSwapping) && (typeInstance->mDefineState < BfTypeDefineState_Defined)) - { + { if (typeInstance->mHotTypeData == NULL) { BF_ASSERT(typeInstance->mTypeFailed); @@ -5738,7 +5735,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy mHadBuildError = true; CheckAddFailType(); - + BF_ASSERT_REL(typeInstance->mDefineState != BfTypeDefineState_DefinedAndMethodsSlotting); BF_ASSERT_REL(typeInstance->mDefineState != BfTypeDefineState_DefinedAndMethodsSlotted); @@ -5762,7 +5759,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy if ((typeInstance->mBaseType == NULL) || (typeInstance->mBaseType->IsSplattable())) { int dataCount = 0; - + std::function splatIterate; splatIterate = [&](BfType* checkType) { @@ -5771,7 +5768,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy if (checkType->IsMethodRef()) { - // For simplicity, any methodRef inside a struct makes the struct non-splattable. This reduces cases of needing to + // For simplicity, any methodRef inside a struct makes the struct non-splattable. This reduces cases of needing to // handle embedded methodRefs hadNonSplattable = true; } @@ -5780,7 +5777,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy hadNonSplattable = true; } else if (checkType->IsStruct()) - { + { auto checkTypeInstance = checkType->ToTypeInstance(); if (checkTypeInstance->mBaseType != NULL) splatIterate(checkTypeInstance->mBaseType); @@ -5811,7 +5808,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy { if (checkType->IsSizedArray()) hadNonSplattable = true; - + dataCount += checkType->GetSplatCount(); } }; @@ -5834,7 +5831,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy typeInstance->mIsSplattable = true; if (typeInstance->mTypeDef->mIsOpaque) typeInstance->mIsSplattable = false; - + BF_ASSERT(mContext->mCurTypeState == &typeState); // This is only required for autocomplete and finding type references @@ -5899,7 +5896,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy } } } - + if ((typeInstance->IsEnum()) && (!typeInstance->IsPayloadEnum())) { BfLogSysM("Setting underlying type %p %d\n", typeInstance, underlyingTypeDeferred); @@ -5919,7 +5916,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy if (typeInstance->mHotTypeData != NULL) { - auto newHotTypeVersion = typeInstance->mHotTypeData->GetLatestVersion(); + auto newHotTypeVersion = typeInstance->mHotTypeData->GetLatestVersion(); newHotTypeVersion->mDataHash = dataMemberHash; if (mCompiler->mHotState != NULL) @@ -5934,7 +5931,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy if (!typeInstance->mHotTypeData->mPendingDataChange) { mCompiler->mHotState->mPendingDataChanges.Add(typeInstance->mTypeId); - typeInstance->mHotTypeData->mPendingDataChange = true; + typeInstance->mHotTypeData->mPendingDataChange = true; } else { @@ -6008,7 +6005,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy } void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) -{ +{ if (typeInstance->IsDeleting()) { BF_ASSERT(typeInstance->IsOnDemand()); @@ -6017,7 +6014,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) if (typeInstance->IsSpecializedByAutoCompleteMethod()) return; - + if (typeInstance->mDefineState == BfTypeDefineState_DefinedAndMethodsSlotting) { BfLogSysM("DoTypeInstanceMethodProcessing %p re-entrancy exit\n", typeInstance); @@ -6053,7 +6050,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) AutoDisallowYield disableYield(mSystem); SetAndRestoreValue prevTypeInstance(mCurTypeInstance, typeInstance); - SetAndRestoreValue prevMethodInstance(mCurMethodInstance, NULL); + SetAndRestoreValue prevMethodInstance(mCurMethodInstance, NULL); BfLogSysM("DoTypeInstanceMethodProcessing: %p %s Revision:%d DefineState:%d\n", typeInstance, TypeToString(typeInstance).c_str(), typeInstance->mRevision, typeInstance->mDefineState); @@ -6097,21 +6094,20 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) //BF_ASSERT((methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_NotSet) || (methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_AlwaysInclude)); } - if (typeInstance == mContext->mBfObjectType) { BF_ASSERT(typeInstance->mInterfaceMethodTable.size() == 0); } int newIntefaceStartIdx = 0; - auto implBaseType = typeInstance->GetImplBaseType(); + auto implBaseType = typeInstance->GetImplBaseType(); if (implBaseType != NULL) { auto baseTypeInst = implBaseType->ToTypeInstance(); if (implBaseType->IsIncomplete()) PopulateType(implBaseType, BfPopulateType_Full_Force); - typeInstance->mInterfaceMethodTable = baseTypeInst->mInterfaceMethodTable; + typeInstance->mInterfaceMethodTable = baseTypeInst->mInterfaceMethodTable; typeInstance->mVirtualMethodTable = implBaseType->mVirtualMethodTable; typeInstance->mVirtualMethodTableSize = implBaseType->mVirtualMethodTableSize; if ((!mCompiler->IsHotCompile()) && (!mCompiler->mPassInstance->HasFailed()) && ((mCompiler->mResolvePassData == NULL) || (mCompiler->mResolvePassData->mAutoComplete == NULL))) @@ -6122,18 +6118,18 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) { BF_ASSERT(typeInstance->mVirtualMethodTableSize >= (int)typeInstance->mVirtualMethodTable.size()); } - } + } - // Add new interfaces + // Add new interfaces for (int iFaceIdx = 0; iFaceIdx < (int)typeInstance->mInterfaces.size(); iFaceIdx++) { - BfTypeInterfaceEntry& typeInterfaceInst = typeInstance->mInterfaces[iFaceIdx]; + BfTypeInterfaceEntry& typeInterfaceInst = typeInstance->mInterfaces[iFaceIdx]; auto checkInterface = typeInterfaceInst.mInterfaceType; - if (checkInterface->IsIncomplete()) + if (checkInterface->IsIncomplete()) PopulateType(checkInterface, BfPopulateType_Full_Force); - - typeInterfaceInst.mStartInterfaceTableIdx = (int)typeInstance->mInterfaceMethodTable.size(); + + typeInterfaceInst.mStartInterfaceTableIdx = (int)typeInstance->mInterfaceMethodTable.size(); // We don't add to the vtable for interface declarations, we just reference the listed interfaces if (!typeInstance->IsInterface()) @@ -6142,17 +6138,17 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) BF_ASSERT(interfaceTypeDef->mMethods.size() == checkInterface->mMethodInstanceGroups.size()); // Reserve empty entries - for (int methodIdx = 0; methodIdx < (int)interfaceTypeDef->mMethods.size(); methodIdx++) + for (int methodIdx = 0; methodIdx < (int)interfaceTypeDef->mMethods.size(); methodIdx++) typeInstance->mInterfaceMethodTable.push_back(BfTypeInterfaceMethodEntry()); - } + } } auto checkTypeInstance = typeInstance; while (checkTypeInstance != NULL) { // These may have been already added - for (auto&& interfaceEntry : checkTypeInstance->mInterfaces) - AddDependency(interfaceEntry.mInterfaceType, typeInstance, BfDependencyMap::DependencyFlag_ImplementsInterface); + for (auto&& interfaceEntry : checkTypeInstance->mInterfaces) + AddDependency(interfaceEntry.mInterfaceType, typeInstance, BfDependencyMap::DependencyFlag_ImplementsInterface); checkTypeInstance = checkTypeInstance->GetImplBaseType(); } @@ -6162,7 +6158,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) { BF_ASSERT(typeInstance->mInterfaceMethodTable.size() == 1); } - + // Slot interfaces method blocks in vtable { int ifaceVirtIdx = 0; @@ -6213,16 +6209,16 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) if ((mCompiler->mOptions.mHasVDataExtender) && (!typeInstance->IsInterface())) { // This is the vExt entry for this type instance - BfVirtualMethodEntry entry; + BfVirtualMethodEntry entry; entry.mDeclaringMethod.mMethodNum = -1; entry.mDeclaringMethod.mTypeInstance = typeInstance; typeInstance->mVirtualMethodTable.push_back(entry); - typeInstance->mVirtualMethodTableSize++; + typeInstance->mVirtualMethodTableSize++; } // Fill out to correct size if (typeInstance->mHotTypeData != NULL) - { + { //auto hotLatestVersionHead = typeInstance->mHotTypeData->GetLatestVersionHead(); int wantVTableSize = typeInstance->GetImplBaseVTableSize() + (int)typeInstance->mHotTypeData->mVTableEntries.size(); while ((int)typeInstance->mVirtualMethodTable.size() < wantVTableSize) @@ -6231,12 +6227,12 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) typeInstance->mVirtualMethodTableSize++; } } - + BfAmbiguityContext ambiguityContext; ambiguityContext.mTypeInstance = typeInstance; ambiguityContext.mModule = this; ambiguityContext.mIsProjectSpecific = false; - + bool wantsOnDemandMethods = false; //TODO: Testing having interface methods be "on demand"... //if (!typeInstance->IsInterface()) @@ -6251,7 +6247,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) //if (typeDef->mName->ToString() != "AttributeUsageAttribute") auto attributeDef = mCompiler->mAttributeTypeDef; - auto attributeType = mContext->mUnreifiedModule->ResolveTypeDef(attributeDef, BfPopulateType_Identity)->ToTypeInstance(); + auto attributeType = mContext->mUnreifiedModule->ResolveTypeDef(attributeDef, BfPopulateType_Identity)->ToTypeInstance(); if (!TypeIsSubTypeOf(mCurTypeInstance, attributeType, false)) { wantsOnDemandMethods = true; @@ -6271,13 +6267,13 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) auto parser = typeDef->mTypeDeclaration->GetParser(); if (parser != NULL) if (mCompiler->mResolvePassData->GetSourceClassifier(parser) != NULL) - isCurrentEntry = true; + isCurrentEntry = true; }; _CheckEntry(typeInstance->mTypeDef); for (auto& partial : typeInstance->mTypeDef->mPartials) _CheckEntry(partial); - + if (isCurrentEntry) { String typeName = TypeToString(typeInstance, BfTypeNameFlag_AddProjectName); @@ -6304,7 +6300,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) BfTypeInterfaceEntry& typeInterfaceInst = typeInstance->mInterfaces[iFaceIdx]; for (auto checkMethodDef : typeInterfaceInst.mInterfaceType->mTypeDef->mMethods) { - ifaceMethodNameSet.Add(checkMethodDef->mName); + ifaceMethodNameSet.Add(checkMethodDef->mName); } } } @@ -6316,7 +6312,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) isFailedType = true; } - bool typeOptionsIncludeAll = false; + bool typeOptionsIncludeAll = false; bool typeOptionsIncludeFiltered = false; if (typeOptions != NULL) { @@ -6326,8 +6322,8 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) // Generate all methods. Pass 1 for (auto methodDef : typeDef->mMethods) - { - auto methodInstanceGroup = &typeInstance->mMethodInstanceGroups[methodDef->mIdx]; + { + auto methodInstanceGroup = &typeInstance->mMethodInstanceGroups[methodDef->mIdx]; if (typeOptions != NULL) { @@ -6335,7 +6331,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) if (methodDef->mMethodType == BfMethodType_Ctor) optionFlags = BfOptionFlags_ReflectConstructors; else if (methodDef->mIsStatic) - optionFlags = BfOptionFlags_ReflectStaticMethods; + optionFlags = BfOptionFlags_ReflectStaticMethods; methodInstanceGroup->mExplicitlyReflected = typeOptions->Apply(false, optionFlags); methodInstanceGroup->mExplicitlyReflected = ApplyTypeOptionMethodFilters(methodInstanceGroup->mExplicitlyReflected, methodDef, typeOptions); } @@ -6345,17 +6341,17 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) if (methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_AlwaysInclude) continue; if (methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_InWorkList) - continue; + continue; if (methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_Referenced) continue; - + if (isFailedType) { // We don't want method decls from failed generic types to clog up our type system continue; } - - BF_ASSERT((methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_NotSet) || + + BF_ASSERT((methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_NotSet) || (methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_Decl_AwaitingDecl) || (methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_Decl_AwaitingReference)); @@ -6364,7 +6360,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) if (methodDef->mIsStatic) continue; bool boxedRequired = false; - if (((methodDef->mMethodType == BfMethodType_Ctor) && (methodDef->mParams.size() == 0)) || + if (((methodDef->mMethodType == BfMethodType_Ctor) && (methodDef->mParams.size() == 0)) || (methodDef->mMethodType == BfMethodType_Dtor) || ((methodDef->mName == BF_METHODNAME_MARKMEMBERS) || (methodDef->mName == BF_METHODNAME_MARKMEMBERS_STATIC) || (methodDef->mName == BF_METHODNAME_INVOKE) || (methodDef->mName == BF_METHODNAME_DYNAMICCAST)) || (methodDef->mGenericParams.size() != 0)) @@ -6381,11 +6377,11 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) } if (methodDef->mMethodType == BfMethodType_Ignore) - continue; + continue; if ((methodDef->mName == BF_METHODNAME_DYNAMICCAST) && (typeInstance->IsValueType())) continue; // This is just a placeholder for boxed types - + bool doAlwaysInclude = false; if (wantsOnDemandMethods) @@ -6440,7 +6436,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) attributes = attributes->mNextAttribute; } if ((mProject != NULL) && (mProject->mAlwaysIncludeAll) && (methodDef->mBody != NULL)) - { + { implRequired = true; declRequired = true; } @@ -6451,7 +6447,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) if (((typeInstance->mAlwaysIncludeFlags & BfAlwaysIncludeFlag_AssumeInstantiated) != 0) && (methodDef->IsDefaultCtor())) implRequired = true; - + if ((typeOptionsIncludeAll || typeOptionsIncludeFiltered) && (ApplyTypeOptionMethodFilters(typeOptionsIncludeAll, methodDef, typeOptions))) implRequired = true; @@ -6469,7 +6465,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) // Any interface with the same name causes us to not be on-demand if (ifaceMethodNameSet.Contains(methodDef->mName)) declRequired = true; - } + } // Is this strictly necessary? It will reduce our compilation speed in order to ensure methods are available for debug info if (allDeclsRequired) @@ -6490,7 +6486,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) } if (!implRequired) - { + { if (methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_NotSet) { if (!mIsScratchModule) @@ -6513,9 +6509,9 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) } else { - doAlwaysInclude = true; + doAlwaysInclude = true; } - } + } else doAlwaysInclude = true; @@ -6523,7 +6519,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) { bool wasDeclared = (methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_Decl_AwaitingDecl) || (methodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_Decl_AwaitingReference); - + methodInstanceGroup->mOnDemandKind = BfMethodOnDemandKind_AlwaysInclude; if (wasDeclared) @@ -6540,10 +6536,10 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) BfLogSysM("Starting DoTypeInstanceMethodProcessing %p GetMethodInstance pass. OnDemandMethods: %d\n", typeInstance, mOnDemandMethodCount); // Def passes. First non-overrides then overrides (for in-place overrides in methods) - for (int pass = 0; pass < 2; pass++) + for (int pass = 0; pass < 2; pass++) { for (auto methodDef : typeDef->mMethods) - { + { if ((pass == 1) != (methodDef->mIsOverride)) continue; @@ -6666,7 +6662,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) } // This is important for reducing latency of autocomplete popup, but it's important we don't allow the autocomplete - // thread to cause any reentry issues by re-populating a type at an "inopportune time". We do allow certain + // thread to cause any reentry issues by re-populating a type at an "inopportune time". We do allow certain // reentries in PopulateType, but not when we're resolving fields (for example) if ((mContext->mFieldResolveReentrys.size() == 0) && (!mContext->mResolvingVarField)) { @@ -6677,7 +6673,6 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) } } - BF_ASSERT(typeInstance->mVirtualMethodTable.size() == typeInstance->mVirtualMethodTableSize); if ((isBoxed) && (!typeInstance->IsUnspecializedTypeVariation())) @@ -6731,7 +6726,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) auto methodFlags = matchedMethod->mIsForeignMethodDef ? BfGetMethodInstanceFlag_ForeignMethodDef : BfGetMethodInstanceFlag_None; methodFlags = (BfGetMethodInstanceFlags)(methodFlags | BfGetMethodInstanceFlag_MethodInstanceOnly); - + auto moduleMethodInstance = GetMethodInstance(typeInstance, matchedMethodDef, BfTypeVector(), methodFlags, matchedMethod->GetForeignType()); @@ -6748,7 +6743,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) if (typeInstance->mHotTypeData != NULL) { auto latestVersion = typeInstance->mHotTypeData->GetLatestVersion(); - auto latestVersionHead = typeInstance->mHotTypeData->GetLatestVersionHead(); + auto latestVersionHead = typeInstance->mHotTypeData->GetLatestVersionHead(); if (typeInstance->mHotTypeData->mVTableOrigLength != -1) { bool hasSlotError = false; @@ -6785,7 +6780,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) { latestVersion->mInterfaceMapping = ifaceMapping; } - hasSlotError = true; + hasSlotError = true; } else if (hasSlotError) { @@ -6804,10 +6799,10 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) mCompiler->mHotState->mPendingFailedSlottings.Remove(typeInstance->mTypeId); } } - + if ((typeInstance->IsInterface()) && (!typeInstance->IsUnspecializedType()) && (typeInstance->mIsReified) && (typeInstance->mSlotNum == -1) && (mCompiler->IsHotCompile())) { - mCompiler->mHotState->mHasNewInterfaceTypes = true; + mCompiler->mHotState->mHasNewInterfaceTypes = true; } if ((!typeInstance->IsInterface()) && (!typeInstance->IsUnspecializedTypeVariation()) && (!isBoxed) && (!isFailedType)) @@ -6886,7 +6881,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) if ((methodInstance->mMethodDef->mProtection != BfProtection_Private) && (!methodInstance->mMethodDef->mIsOverride) && (missingIFaceMethodNames.find(methodInstance->mMethodDef->mName) != missingIFaceMethodNames.end())) - { + { SlotVirtualMethod(methodInstance, &ambiguityContext); } } @@ -6896,7 +6891,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) } for (auto& ifaceTypeInst : typeInstance->mInterfaces) - { + { auto ifaceInst = ifaceTypeInst.mInterfaceType; int startIdx = ifaceTypeInst.mStartInterfaceTableIdx; int iMethodCount = (int)ifaceInst->mMethodInstanceGroups.size(); @@ -6924,7 +6919,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) continue; // Don't consider overrides here // If we have "ProjA depends on LibBase", "ProjB depends on LibBase", then a type ClassC in LibBase implementing IFaceD, - // where IFaceD gets extended with MethodE in ProjA, an implementing MethodE is still required to exist on ClassC -- + // where IFaceD gets extended with MethodE in ProjA, an implementing MethodE is still required to exist on ClassC -- // the visibility is bidirectional. A type ClassF implementing IFaceD inside ProjB will not be required to implement // MethodE, however if ((!ifaceInst->IsTypeMemberAccessible(ifaceMethodInst->mMethodDef->mDeclaringType, ifaceTypeInst.mDeclaringType)) && @@ -6944,7 +6939,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) if ((matchedMethod->GetExplicitInterface() == NULL) && (matchedMethod->mMethodDef->mProtection != BfProtection_Public)) { hadMatch = false; - hadPubFailure = true; + hadPubFailure = true; } if (matchedMethod->mMethodDef->mIsStatic != ifaceMethodInst->mMethodDef->mIsStatic) @@ -6952,7 +6947,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) hadMatch = false; hadStaticFailure = true; } - + if (ifaceMethodInst->mVirtualTableIdx != -1) { if (matchedMethod->mReturnType != iReturnType) @@ -6964,18 +6959,18 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) if (!CanCast(GetFakeTypedValue(matchedMethod->mReturnType), iReturnType)) hadMatch = false; } - - // If we have mExplicitInterface set then we already gave a mut error (if needed) + + // If we have mExplicitInterface set then we already gave a mut error (if needed) if ((typeInstance->IsValueType()) && (matchedMethod->GetExplicitInterface() == NULL) && (matchedMethod->mMethodDef->mIsMutating) && (!ifaceMethodInst->mMethodDef->mIsMutating)) { hadMutFailure = true; hadMatch = false; - } + } } if (!hadMatch) - { + { if (!typeInstance->IsUnspecializedTypeVariation()) { auto bestMethodInst = ifaceMethodInst; @@ -6985,7 +6980,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) { bool searchFailed = false; for (auto& checkIFaceTypeInst : typeInstance->mInterfaces) - { + { auto checkIFaceInst = checkIFaceTypeInst.mInterfaceType; int checkStartIdx = checkIFaceTypeInst.mStartInterfaceTableIdx; int checkIMethodCount = (int)checkIFaceInst->mMethodInstanceGroups.size(); @@ -6994,7 +6989,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) auto checkIFaceMethodInst = checkIFaceInst->mMethodInstanceGroups[checkIMethodIdx].mDefault; if ((checkIFaceMethodInst != NULL) && (checkIFaceMethodInst->mMethodDef->mIsOverride)) { - bool cmpResult = CompareMethodSignatures(checkIFaceMethodInst, ifaceMethodInst); + bool cmpResult = CompareMethodSignatures(checkIFaceMethodInst, ifaceMethodInst); if (cmpResult) { bool isBetter = TypeIsSubTypeOf(checkIFaceInst, bestInterface); @@ -7021,7 +7016,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) mCompiler->mPassInstance->MoreInfo(StrFormat("'%s' is a candidate", MethodToString(checkIFaceMethodInst).c_str()), checkIFaceMethodInst->mMethodDef->GetRefNode()); } - //candidate implementations include '%s' and '%s'", + //candidate implementations include '%s' and '%s'", //TypeToString(checkIFaceInst).c_str(), TypeToString(bestInterface).c_str()), ); } } @@ -7055,13 +7050,13 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) *matchedMethodRef = methodInst.mMethodInstance; BfMethodInstance* newMethodInstance = methodInst.mMethodInstance; - BF_ASSERT(newMethodInstance->mIsForeignMethodDef); + BF_ASSERT(newMethodInstance->mIsForeignMethodDef); if (newMethodInstance->mMethodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_Decl_AwaitingReference) { if (!mIsScratchModule) mOnDemandMethodCount++; - } - + } + continue; } } @@ -7084,19 +7079,19 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) // It's possible const eval was supposed to generate this method. We're rebuilding the type anyway. } else - { + { String methodString; /// { BfTypeState typeState; - typeState.mPrevState = mContext->mCurTypeState; + typeState.mPrevState = mContext->mCurTypeState; typeState.mForceActiveTypeDef = declTypeDef; SetAndRestoreValue prevTypeState(mContext->mCurTypeState, &typeState); - + SetAndRestoreValue prevMethodInstance(mCurMethodInstance, ifaceMethodInst); methodString = MethodToString(ifaceMethodInst); } - + BfTypeDeclaration* typeDecl = declTypeDef->mTypeDeclaration; BfError* error = Fail(StrFormat("'%s' does not implement interface member '%s'", TypeToString(typeInstance).c_str(), methodString.c_str()), typeDecl->mNameNode, true); if ((matchedMethod != NULL) && (error != NULL)) @@ -7124,7 +7119,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) { mCompiler->mPassInstance->MoreInfo(StrFormat("'%s' cannot match because it does not have a concrete return type that implements '%s'", methodString.c_str(), TypeToString(ifaceMethodInst->mReturnType).c_str()), matchedMethod->mMethodDef->mReturnTypeRef); - } + } else if (hadMutFailure) { mCompiler->mPassInstance->MoreInfo(StrFormat("'%s' cannot match because it's market as 'mut' but interface method does not allow it", @@ -7138,14 +7133,14 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) if ((ifaceMethodInst->mVirtualTableIdx != -1) && (ifaceMethodInst->mReturnType->IsInterface())) mCompiler->mPassInstance->MoreInfo("Declare the interface method as 'concrete' to allow matching concrete return values", ifaceMethodInst->mMethodDef->GetMethodDeclaration()->mVirtualSpecifier); } - } + } } } // Clear out the entry *matchedMethodRef = BfMethodRef(); } - } + } } } @@ -7155,7 +7150,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) CheckAddFailType(); typeInstance->mDefineState = BfTypeDefineState_DefinedAndMethodsSlotted; - mCompiler->mStats.mTypesPopulated++; + mCompiler->mStats.mTypesPopulated++; mCompiler->UpdateCompletion(); BF_ASSERT_REL(!typeInstance->mNeedsMethodProcessing); @@ -7164,10 +7159,10 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance) } void BfModule::RebuildMethods(BfTypeInstance* typeInstance) -{ +{ if (typeInstance->IsIncomplete()) return; - + BfLogSysM("RebuildMethods setting mNeedsMethodProcessing=true on %p\n", typeInstance); BF_ASSERT_REL(typeInstance->mDefineState != BfTypeDefineState_DefinedAndMethodsSlotting); @@ -7180,13 +7175,13 @@ void BfModule::RebuildMethods(BfTypeInstance* typeInstance) delete methodInstanceGroup.mDefault; methodInstanceGroup.mDefault = NULL; delete methodInstanceGroup.mMethodSpecializationMap; - methodInstanceGroup.mMethodSpecializationMap = NULL; + methodInstanceGroup.mMethodSpecializationMap = NULL; methodInstanceGroup.mOnDemandKind = BfMethodOnDemandKind_NotSet; } BfTypeProcessRequest* typeProcessRequest = mContext->mPopulateTypeWorkList.Alloc(); typeProcessRequest->mType = typeInstance; - BF_ASSERT(typeInstance->mContext == mContext); + BF_ASSERT(typeInstance->mContext == mContext); mCompiler->mStats.mTypesQueued++; mCompiler->UpdateCompletion(); } @@ -7205,7 +7200,7 @@ void BfModule::AddMethodToWorkList(BfMethodInstance* methodInstance) if (methodInstance->IsSpecializedByAutoCompleteMethod()) return; - + BF_ASSERT(mCompiler->mCompileState != BfCompiler::CompileState_VData); if ((methodInstance->mIsReified) && (!methodInstance->mIsUnspecialized)) { @@ -7250,7 +7245,7 @@ void BfModule::AddMethodToWorkList(BfMethodInstance* methodInstance) { auto module = GetOrCreateMethodModule(methodInstance); methodInstance->mDeclModule = module; - + BfIRValue func = CreateFunctionFrom(methodInstance, false, methodInstance->mAlwaysInline); methodInstance->mIRFunction = func; @@ -7262,20 +7257,20 @@ void BfModule::AddMethodToWorkList(BfMethodInstance* methodInstance) if ((!methodInstance->mIRFunction) && (methodInstance->mIsReified) && (!methodInstance->mIsUnspecialized) && (methodInstance->GetImportCallKind() == BfImportCallKind_None)) - { + { if (!mIsModuleMutable) PrepareForIRWriting(methodInstance->GetOwner()); - + SetAndRestoreValue prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, mWantsIRIgnoreWrites); - BfIRValue func = CreateFunctionFrom(methodInstance, false, methodInstance->mAlwaysInline); + BfIRValue func = CreateFunctionFrom(methodInstance, false, methodInstance->mAlwaysInline); if (func) { methodInstance->mIRFunction = func; mFuncReferences[methodInstance] = func; } } - + BF_ASSERT(methodInstance->mDeclModule == this); if (defaultMethod == methodInstance) @@ -7286,13 +7281,13 @@ void BfModule::AddMethodToWorkList(BfMethodInstance* methodInstance) BF_ASSERT(methodInstance->mMethodInstanceGroup->mOnDemandKind != BfMethodOnDemandKind_Referenced); if (!mIsScratchModule) - { + { auto onDemandModule = owningModule; if (owningModule->mParentModule != NULL) onDemandModule = owningModule->mParentModule; owningModule->VerifyOnDemandMethods(); - + if (methodInstance->mMethodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_NotSet) owningModule->mOnDemandMethodCount++; BF_ASSERT(onDemandModule->mOnDemandMethodCount > 0); @@ -7313,7 +7308,6 @@ void BfModule::AddMethodToWorkList(BfMethodInstance* methodInstance) specMethodInstance->mDeclModule->AddMethodToWorkList(specMethodInstance); } } - } } else @@ -7324,7 +7318,7 @@ void BfModule::AddMethodToWorkList(BfMethodInstance* methodInstance) BF_ASSERT(methodInstance->mDeclModule != NULL); auto typeInstance = methodInstance->GetOwner(); - + BfMethodProcessRequest* methodProcessRequest = mContext->mMethodWorkList.Alloc(); if (mCompiler->mCompileState == BfCompiler::CompileState_Unreified) { @@ -7336,7 +7330,7 @@ void BfModule::AddMethodToWorkList(BfMethodInstance* methodInstance) } //BF_ASSERT(!methodInstance->mIsReified); methodProcessRequest->mType = typeInstance; - methodProcessRequest->mMethodInstance = methodInstance; + methodProcessRequest->mMethodInstance = methodInstance; methodProcessRequest->mRevision = typeInstance->mRevision; methodProcessRequest->mFromModuleRebuildIdx = mRebuildIdx; methodProcessRequest->mFromModule = this; @@ -7367,7 +7361,7 @@ void BfModule::AddMethodToWorkList(BfMethodInstance* methodInstance) mIncompleteMethodCount++; if (methodInstance->GetNumGenericArguments() != 0) mHasGenericMethods = true; - + methodInstance->mMethodProcessRequest = methodProcessRequest; } @@ -7461,13 +7455,13 @@ BfConstExprValueType* BfModule::CreateConstExprValueType(const BfTypedValue& typ } } - if (variant.mTypeCode == BfTypeCode_None) + if (variant.mTypeCode == BfTypeCode_None) return NULL; auto constExprValueType = mContext->mConstExprValueTypePool.Get(); constExprValueType->mContext = mContext; constExprValueType->mType = typedValue.mType; - constExprValueType->mValue = variant; + constExprValueType->mValue = variant; auto resolvedConstExprValueType = (BfConstExprValueType*)ResolveType(constExprValueType, populateType, resolveFlags); if (resolvedConstExprValueType != constExprValueType) @@ -7480,7 +7474,7 @@ BfConstExprValueType* BfModule::CreateConstExprValueType(const BfTypedValue& typ } BfConstExprValueType* BfModule::CreateConstExprValueType(const BfVariant& variant, BfType* type, bool allowCreate) -{ +{ BfPopulateType populateType = allowCreate ? BfPopulateType_Data : BfPopulateType_Identity; BfResolveTypeRefFlags resolveFlags = allowCreate ? BfResolveTypeRefFlag_None : BfResolveTypeRefFlag_NoCreate; @@ -7536,7 +7530,7 @@ BfTypeInstance* BfModule::GetWrappedStructType(BfType* type, bool allowSpecializ { BfUnknownSizedArrayType* sizedArrayType = (BfUnknownSizedArrayType*)type; BfTypeVector typeVector; - typeVector.Add(sizedArrayType->mElementType); + typeVector.Add(sizedArrayType->mElementType); typeVector.Add(sizedArrayType->mElementCountSource); return ResolveTypeDef(mCompiler->mSizedArrayTypeDef, typeVector, BfPopulateType_Data)->ToTypeInstance(); } @@ -7557,7 +7551,7 @@ BfTypeInstance* BfModule::GetWrappedStructType(BfType* type, bool allowSpecializ } BfPrimitiveType* BfModule::GetPrimitiveType(BfTypeCode typeCode) -{ +{ BfPrimitiveType* primType = mContext->mPrimitiveTypes[typeCode]; if (primType == NULL) { @@ -7638,12 +7632,12 @@ BfPrimitiveType* BfModule::GetPrimitiveType(BfTypeCode typeCode) case BfTypeCode_StringId: BFMODULE_FATAL(this, "Invalid use of StringId"); break; - default: + default: BF_DBG_FATAL("Invalid type"); break; } mContext->mPrimitiveTypes[typeCode] = primType; - } + } return primType; } @@ -7651,28 +7645,28 @@ BfIRType BfModule::GetIRLoweredType(BfTypeCode loweredTypeCode, BfTypeCode lower { BF_ASSERT(!mIsComptimeModule); - BF_ASSERT(loweredTypeCode != BfTypeCode_None); - if (loweredTypeCode2 == BfTypeCode_None) - return mBfIRBuilder->GetPrimitiveType(loweredTypeCode); - + BF_ASSERT(loweredTypeCode != BfTypeCode_None); + if (loweredTypeCode2 == BfTypeCode_None) + return mBfIRBuilder->GetPrimitiveType(loweredTypeCode); + SizedArray types; types.push_back(mBfIRBuilder->GetPrimitiveType(loweredTypeCode)); types.push_back(mBfIRBuilder->GetPrimitiveType(loweredTypeCode2)); - return mBfIRBuilder->CreateStructType(types); + return mBfIRBuilder->CreateStructType(types); } BfMethodRefType* BfModule::CreateMethodRefType(BfMethodInstance* methodInstance, bool mustAlreadyExist) { - // Make sure we don't have a partially-formed local method or lambda coming in, because those may be replaced + // Make sure we don't have a partially-formed local method or lambda coming in, because those may be replaced // after the capture phase BF_ASSERT(!methodInstance->mDisallowCalling); auto methodRefType = new BfMethodRefType(); methodRefType->mContext = mContext; //methodRefType->mCaptureType = NULL; - methodRefType->mMethodRef = methodInstance; + methodRefType->mMethodRef = methodInstance; methodRefType->mOwner = methodInstance->GetOwner(); - methodRefType->mOwnerRevision = methodRefType->mOwner->mRevision; + methodRefType->mOwnerRevision = methodRefType->mOwner->mRevision; //methodRefType->mMangledName = BfMangler::Mangle(mCompiler->GetMangleKind(), methodInstance); methodRefType->mIsAutoCompleteMethod = methodInstance->mIsAutocompleteMethod; methodRefType->mIsUnspecialized = methodInstance->mIsUnspecialized; @@ -7684,7 +7678,7 @@ BfMethodRefType* BfModule::CreateMethodRefType(BfMethodInstance* methodInstance, BfResolvedTypeSet::EntryRef typeEntry; auto inserted = mContext->mResolvedTypes.Insert(methodRefType, &lookupCtx, &typeEntry); if (typeEntry->mValue == NULL) - { + { BF_ASSERT(!mustAlreadyExist); BF_ASSERT(!methodInstance->mHasMethodRefType); @@ -7697,7 +7691,7 @@ BfMethodRefType* BfModule::CreateMethodRefType(BfMethodInstance* methodInstance, BfLogSysM("Create MethodRefType %p MethodInstance: %p\n", methodRefType, methodInstance); methodRefType->mRevision = 0; AddDependency(methodInstance->GetOwner(), methodRefType, BfDependencyMap::DependencyFlag_Calls); - + BfTypeVector tupleTypes; Array tupleNames; @@ -7706,11 +7700,11 @@ BfMethodRefType* BfModule::CreateMethodRefType(BfMethodInstance* methodInstance, methodRefType->mAlign = 1; int dataIdx = 0; - - // CRepr, just because we're lazy (for now) + + // CRepr, just because we're lazy (for now) int implicitParamCount = methodInstance->GetImplicitParamCount(); for (int implicitParamIdx = methodInstance->HasThis() ? -1 : 0; implicitParamIdx < implicitParamCount; implicitParamIdx++) - { + { auto paramType = methodInstance->GetParamType(implicitParamIdx); if (!paramType->IsValuelessType()) { @@ -7723,7 +7717,7 @@ BfMethodRefType* BfModule::CreateMethodRefType(BfMethodInstance* methodInstance, methodRefType->mAlign = std::max(methodRefType->mAlign, paramType->mAlign); dataIdx++; - } + } else { methodRefType->mParamToDataIdx.Add(-1); @@ -7736,10 +7730,10 @@ BfMethodRefType* BfModule::CreateMethodRefType(BfMethodInstance* methodInstance, // { // methodRefType->mCaptureType = CreateTupleType(tupleTypes, tupleNames); // AddDependency(methodRefType->mCaptureType, methodRefType, BfDependencyMap::DependencyFlag_ReadFields); -// +// // methodRefType->mSize = methodRefType->mCaptureType->mSize; // methodRefType->mAlign = methodRefType->mCaptureType->mAlign; -// } +// } // else // { // methodRefType->mSize = 0; @@ -7841,8 +7835,8 @@ void BfModule::FixIntUnknown(BfTypedValue& typedVal, BfType* matchType) } void BfModule::FixIntUnknown(BfTypedValue& lhs, BfTypedValue& rhs) -{ - if ((lhs.mType != NULL) && (lhs.mType->IsIntUnknown()) && (rhs.mType != NULL) && +{ + if ((lhs.mType != NULL) && (lhs.mType->IsIntUnknown()) && (rhs.mType != NULL) && (rhs.mType->IsInteger()) && (!rhs.mType->IsIntUnknown())) { if (CanCast(lhs, rhs.mType)) @@ -7854,7 +7848,7 @@ void BfModule::FixIntUnknown(BfTypedValue& lhs, BfTypedValue& rhs) } } - if ((rhs.mType != NULL) && (rhs.mType->IsIntUnknown()) && (lhs.mType != NULL) && + if ((rhs.mType != NULL) && (rhs.mType->IsIntUnknown()) && (lhs.mType != NULL) && (lhs.mType->IsInteger()) && (!lhs.mType->IsIntUnknown())) { if (CanCast(rhs, lhs.mType)) @@ -7873,12 +7867,12 @@ void BfModule::FixIntUnknown(BfTypedValue& lhs, BfTypedValue& rhs) void BfModule::FixValueActualization(BfTypedValue& typedVal, bool force) { if (!typedVal.mValue.IsConst()) - return; + return; if ((mBfIRBuilder->mIgnoreWrites) && (!force)) return; auto constant = mBfIRBuilder->GetConstant(typedVal.mValue); if (!HasUnactializedConstant(constant, mBfIRBuilder)) - return; + return; typedVal.mValue = ConstantToCurrent(constant, mBfIRBuilder, typedVal.mType, false); } @@ -7940,7 +7934,7 @@ BfBoxedType* BfModule::CreateBoxedType(BfType* resolvedTypeRef, bool allowCreate { auto primType = (BfPrimitiveType*)resolvedTypeRef; resolvedTypeRef = GetPrimitiveStructType(primType->mTypeDef->mTypeCode); - if (resolvedTypeRef == NULL) + if (resolvedTypeRef == NULL) return NULL; } else if (resolvedTypeRef->IsPointer()) @@ -7982,7 +7976,7 @@ BfBoxedType* BfModule::CreateBoxedType(BfType* resolvedTypeRef, bool allowCreate resolvedTypeRef = ResolveTypeDef(mCompiler->mSizedArrayTypeDef, typeVector, populateType, resolveFlags); if (resolvedTypeRef == NULL) return NULL; - } + } BfTypeInstance* typeInst = resolvedTypeRef->ToTypeInstance(); if ((typeInst == NULL) && (!resolvedTypeRef->IsGenericParam())) @@ -8010,7 +8004,7 @@ BfTypeInstance* BfModule::CreateTupleType(const BfTypeVector& fieldTypes, const auto baseType = (BfTypeInstance*)ResolveTypeDef(mContext->mCompiler->mValueTypeTypeDef); BfTupleType* tupleType = NULL; - + auto actualTupleType = mContext->mTupleTypePool.Get(); actualTupleType->Init(baseType->mTypeDef->mProject, baseType); @@ -8036,13 +8030,13 @@ BfTypeInstance* BfModule::CreateTupleType(const BfTypeVector& fieldTypes, const { BfFieldInstance* fieldInstance = (BfFieldInstance*)&tupleType->mFieldInstances[fieldIdx]; fieldInstance->mFieldIdx = fieldIdx; - BfType* fieldType = fieldTypes[fieldIdx]; + BfType* fieldType = fieldTypes[fieldIdx]; if ((fieldType->IsVar()) && (!allowVar)) fieldType = mContext->mBfObjectType; fieldInstance->SetResolvedType(fieldType); - fieldInstance->mOwner = tupleType; + fieldInstance->mOwner = tupleType; } - + tupleType->mIsUnspecializedType = false; tupleType->mIsUnspecializedTypeVariation = false; if (isUnspecialzied) @@ -8058,7 +8052,7 @@ BfTypeInstance* BfModule::CreateTupleType(const BfTypeVector& fieldTypes, const tupleType->Dispose(); mContext->mTupleTypePool.GiveBack((BfTupleType*)tupleType); } - + return (BfTupleType*)resolvedTupleType; } @@ -8070,7 +8064,7 @@ BfTypeInstance* BfModule::SantizeTupleType(BfTypeInstance* tupleType) BfFieldInstance* fieldInstance = (BfFieldInstance*)&tupleType->mFieldInstances[fieldIdx]; if ((fieldInstance->mResolvedType->IsVar()) || (fieldInstance->mResolvedType->IsLet())) { - needsSanitize = true; + needsSanitize = true; break; } } @@ -8088,7 +8082,7 @@ BfTypeInstance* BfModule::SantizeTupleType(BfTypeInstance* tupleType) if ((fieldInstance->mResolvedType->IsVar()) || (fieldInstance->mResolvedType->IsLet())) fieldTypes.Add(mContext->mBfObjectType); else - fieldTypes.Add(fieldInstance->mResolvedType); + fieldTypes.Add(fieldInstance->mResolvedType); if (!fieldDef->IsUnnamedTupleField()) { for (int i = 0; i < fieldIdx; i++) @@ -8117,7 +8111,7 @@ BfModifiedTypeType* BfModule::CreateModifiedTypeType(BfType* resolvedTypeRef, Bf retTypeType->mContext = mContext; retTypeType->mModifiedKind = modifiedKind; retTypeType->mElementType = resolvedTypeRef; - auto resolvedRetTypeType = ResolveType(retTypeType); + auto resolvedRetTypeType = ResolveType(retTypeType); if (resolvedRetTypeType != retTypeType) mContext->mModifiedTypeTypePool.GiveBack(retTypeType); return (BfModifiedTypeType*)resolvedRetTypeType; @@ -8149,7 +8143,7 @@ BfType* BfModule::ResolveTypeDef(BfTypeDef* typeDef, BfPopulateType populateType if (typeDef->mTypeDeclaration == NULL) { BF_ASSERT(!typeDef->mIsDelegate && !typeDef->mIsFunction); - } + } //BF_ASSERT(typeDef->mTypeCode != BfTypeCode_Extension); BF_ASSERT(!typeDef->mIsPartial || typeDef->mIsCombinedPartial); @@ -8160,7 +8154,7 @@ BfType* BfModule::ResolveTypeDef(BfTypeDef* typeDef, BfPopulateType populateType if (typeDef->mGenericParamDefs.size() != 0) return ResolveTypeDef(typeDef, BfTypeVector(), populateType, resolveFlags); - auto typeDefTypeRef = mContext->mTypeDefTypeRefPool.Get(); + auto typeDefTypeRef = mContext->mTypeDefTypeRefPool.Get(); typeDefTypeRef->mTypeDef = typeDef; auto resolvedtypeDefType = ResolveTypeRef(typeDefTypeRef, populateType); if (resolvedtypeDefType == NULL) @@ -8188,7 +8182,7 @@ BfTypeInstance* BfModule::GetBaseType(BfTypeInstance* typeInst) } } - if ((typeInst->mBaseType == NULL) && (typeInst != mContext->mBfObjectType)) + if ((typeInst->mBaseType == NULL) && (typeInst != mContext->mBfObjectType)) PopulateType(typeInst, BfPopulateType_BaseType); return typeInst->mBaseType; } @@ -8203,7 +8197,7 @@ void BfModule::HandleTypeGenericParamRef(BfAstNode* refNode, BfTypeDef* typeDef, if ((autoComplete->mDefMethod == NULL) && (autoComplete->mDefField == NULL) && (autoComplete->mDefProp == NULL)) { - autoComplete->mDefType = typeDef; + autoComplete->mDefType = typeDef; autoComplete->mDefTypeGenericParamIdx = typeGenericParamIdx; autoComplete->SetDefinitionLocation(refNode); } @@ -8277,7 +8271,7 @@ BfType* BfModule::ResolveInnerType(BfType* outerType, BfAstNode* typeRef, BfPopu findName = directStrTypeRef->mTypeName; if (!findName.Contains('.')) - { + { if (outerType->IsTypeInstance()) { auto outerTypeInstance = outerType->ToTypeInstance(); @@ -8294,10 +8288,10 @@ BfType* BfModule::ResolveInnerType(BfType* outerType, BfAstNode* typeRef, BfPopu while (checkOuterType != NULL) { for (auto checkType : checkOuterType->mTypeDef->mNestedTypes) - { + { auto latestCheckType = checkType->GetLatest(); - if ((!isFailurePass) && ((resolveFlags & BfResolveTypeRefFlag_IgnoreProtection) == 0) && + if ((!isFailurePass) && ((resolveFlags & BfResolveTypeRefFlag_IgnoreProtection) == 0) && (!CheckProtection(latestCheckType->mProtection, latestCheckType, allowProtected, allowPrivate))) continue; @@ -8373,14 +8367,14 @@ BfType* BfModule::ResolveInnerType(BfType* outerType, BfAstNode* typeRef, BfPopu } if (genericArgs.size() != nestedTypeDef->mGenericParamDefs.size()) - { + { if (populateType == BfPopulateType_TypeDef) { // Probably from inside ResolveGenericInstanceDef, just return unresolved typedef genericArgs.clear(); } else - { + { ShowGenericArgCountError(typeRef, (int)nestedTypeDef->mGenericParamDefs.size() - (int)nestedTypeDef->mOuterType->mGenericParamDefs.size()); return NULL; } @@ -8466,7 +8460,7 @@ bool BfModule::IsInnerType(BfTypeDef* checkInnerType, BfTypeDef* checkOuterType) if (checkInnerType->mNestDepth <= checkOuterType->mNestDepth) return false; while (true) - { + { BfTypeDef* outerType = checkInnerType->mOuterType; if (outerType == NULL) return false; @@ -8475,7 +8469,7 @@ bool BfModule::IsInnerType(BfTypeDef* checkInnerType, BfTypeDef* checkOuterType) if (outerType->GetDefinition() == checkOuterType->GetDefinition()) return true; checkInnerType = checkInnerType->mOuterType; - } + } } BfType* BfModule::ResolveTypeDef(BfTypeDef* typeDef, const BfTypeVector& genericArgs, BfPopulateType populateType, BfResolveTypeRefFlags resolveFlags) @@ -8527,14 +8521,14 @@ BfType* BfModule::ResolveTypeDef(BfTypeDef* typeDef, const BfTypeVector& generic } BF_ASSERT((resolvedType == NULL) || resolvedType->IsTypeInstance() || resolvedType->IsPrimitiveType()); return resolvedType; - } + } BfTypeInstance* genericInstType; if (typeDef->mTypeCode == BfTypeCode_TypeAlias) genericInstType = mContext->mAliasTypePool.Get(); else genericInstType = mContext->mGenericTypeInstancePool.Get(); - delete genericInstType->mGenericTypeInfo; + delete genericInstType->mGenericTypeInfo; genericInstType->mGenericTypeInfo = new BfGenericTypeInfo(); BF_ASSERT(genericInstType->mGenericTypeInfo->mGenericParams.size() == 0); @@ -8566,9 +8560,9 @@ BfType* BfModule::ResolveTypeDef(BfTypeDef* typeDef, const BfTypeVector& generic BfType* resolvedType = NULL; bool failed = false; - resolvedType = ResolveType(genericInstType, populateType, resolveFlags); + resolvedType = ResolveType(genericInstType, populateType, resolveFlags); if (resolvedType != genericInstType) - { + { BF_ASSERT(genericInstType->mGenericTypeInfo->mGenericParams.size() == 0); BF_ASSERT((genericInstType->mRebuildFlags & BfTypeRebuildFlag_AddedToWorkList) == 0); genericInstType->mRebuildFlags = (BfTypeRebuildFlags)(genericInstType->mRebuildFlags | BfTypeRebuildFlag_InTempPool); @@ -8610,16 +8604,16 @@ BfTypeDef* BfModule::ResolveGenericInstanceDef(BfGenericInstanceTypeRef* generic auto namedTypeRef = BfNodeDynCast(typeRef); auto directStrTypeDef = BfNodeDynCastExact(typeRef); if ((namedTypeRef != NULL) || (directStrTypeDef != NULL)) - { + { BfTypeLookupError error; error.mRefNode = typeRef; - BfTypeDef* typeDef = FindTypeDef(typeRef, NULL, &error, numGenericParams, resolveFlags); + BfTypeDef* typeDef = FindTypeDef(typeRef, NULL, &error, numGenericParams, resolveFlags); if (typeDef != NULL) { BfAutoComplete* autoComplete = NULL; if (mCompiler->IsAutocomplete()) autoComplete = mCompiler->mResolvePassData->mAutoComplete; - + if ((autoComplete != NULL) && (autoComplete->mIsGetDefinition) && (autoComplete->IsAutocompleteNode(typeRef))) { if ((autoComplete->mDefMethod == NULL) && (autoComplete->mDefField == NULL) && @@ -8671,7 +8665,7 @@ BfTypeDef* BfModule::ResolveGenericInstanceDef(BfGenericInstanceTypeRef* generic if ((wasGenericParam) && ((resolveFlags & BfResolveTypeRefFlag_IgnoreLookupError) == 0)) Fail("Cannot use generic param as generic instance type", typeRef); } - + if (typeDef == NULL) { if ((resolveFlags & BfResolveTypeRefFlag_IgnoreLookupError) == 0) @@ -8681,7 +8675,7 @@ BfTypeDef* BfModule::ResolveGenericInstanceDef(BfGenericInstanceTypeRef* generic } if (auto qualifiedTypeRef = BfNodeDynCast(typeRef)) - { + { BfAutoParentNodeEntry autoParentNodeEntry(this, genericTypeRef); auto type = ResolveTypeRef(qualifiedTypeRef, BfPopulateType_TypeDef, resolveFlags, numGenericParams); if (type == NULL) @@ -8722,7 +8716,7 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty return resolvedType; } BF_ASSERT(allowFail); - } + } return unspecializedType; } @@ -8732,14 +8726,14 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty if (!unspecializedType->IsUnspecializedType()) { return unspecializedType; - } + } if (unspecializedType->IsUnknownSizedArrayType()) { auto* arrayType = (BfUnknownSizedArrayType*)unspecializedType; auto elementType = ResolveGenericType(arrayType->mElementType, typeGenericArguments, methodGenericArguments, selfType, allowFail); if (elementType == NULL) - return NULL; + return NULL; if (elementType->IsVar()) return elementType; auto sizeType = ResolveGenericType(arrayType->mElementCountSource, typeGenericArguments, methodGenericArguments, selfType, allowFail); @@ -8796,7 +8790,7 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty return NULL; auto elementTypeInstance = elementType->ToTypeInstance(); if (elementTypeInstance == NULL) - return unspecializedType; + return unspecializedType; return CreateConcreteInterfaceType(elementTypeInstance); } @@ -8819,7 +8813,7 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty auto unspecializedTupleType = (BfTypeInstance*)unspecializedType; auto unspecializedGenericTupleType = unspecializedTupleType->ToGenericTypeInstance(); - Array fieldNames; + Array fieldNames; BfTypeVector fieldTypes; bool hadChange = false; @@ -8848,7 +8842,7 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty if (!hadChange) return unspecializedType; - + if (unspecializedGenericTupleType == NULL) wantGeneric = false; @@ -8918,8 +8912,8 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty for (int fieldIdx = 0; fieldIdx < (int)fieldTypes.size(); fieldIdx++) { - String fieldName = fieldNames[fieldIdx]; - BfFieldDef* fieldDef = actualTupleType->AddField(fieldName); + String fieldName = fieldNames[fieldIdx]; + BfFieldDef* fieldDef = actualTupleType->AddField(fieldName); } tupleType = actualTupleType; @@ -8940,11 +8934,11 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty BfType* resolvedType = NULL; if (!failed) resolvedType = ResolveType(tupleType, BfPopulateType_Identity); - + if (resolvedType != tupleType) { delete tupleType->mGenericTypeInfo; - tupleType->mGenericTypeInfo = NULL; + tupleType->mGenericTypeInfo = NULL; tupleType->Dispose(); mContext->mTupleTypePool.GiveBack((BfTupleType*)tupleType); } @@ -8957,7 +8951,7 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty BfTypeInstance* unspecializedDelegateType = (BfTypeInstance*)unspecializedType; BfTypeInstance* unspecializedGenericDelegateType = unspecializedType->ToGenericTypeInstance(); BfDelegateInfo* unspecializedDelegateInfo = unspecializedType->GetDelegateInfo(); - + bool wantGeneric = false; bool isUnspecialized = false; auto _CheckType = [&](BfType* type) @@ -8972,7 +8966,7 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty bool hasTypeGenerics = false; auto returnType = ResolveGenericType(unspecializedDelegateInfo->mReturnType, typeGenericArguments, methodGenericArguments, selfType, allowFail); - + if (returnType == NULL) return NULL; if (returnType->IsVar()) @@ -8989,7 +8983,7 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty return NULL; if (paramType->IsVar()) return paramType; - paramTypes.Add(paramType); + paramTypes.Add(paramType); _CheckType(paramType); } @@ -8999,9 +8993,9 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty //TODO: wantGeneric = false; - BfTypeInstance* delegateType = NULL; - auto baseDelegateType = ResolveTypeDef(mCompiler->mDelegateTypeDef)->ToTypeInstance(); - + BfTypeInstance* delegateType = NULL; + auto baseDelegateType = ResolveTypeDef(mCompiler->mDelegateTypeDef)->ToTypeInstance(); + if (wantGeneric) { Array genericArgs; @@ -9012,10 +9006,10 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty { resolvedArg = ResolveGenericType(resolvedArg, typeGenericArguments, methodGenericArguments, selfType, allowFail); if (resolvedArg == NULL) - return NULL; + return NULL; if (resolvedArg->IsVar()) return resolvedArg; - } + } genericArgs.push_back(resolvedArg); } @@ -9049,14 +9043,14 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty auto dlgType = mContext->mDelegateTypePool.Get(); dlgType->mIsUnspecializedType = isUnspecialized; dlgType->mIsUnspecializedTypeVariation = isUnspecialized; - delegateType = dlgType; + delegateType = dlgType; } delete delegateType->mTypeDef; delegateType->mTypeDef = NULL; BfDelegateInfo* delegateInfo = delegateType->GetDelegateInfo(); delegateInfo->mParams.Clear(); - + BfTypeDef* typeDef = new BfTypeDef(); typeDef->mProject = baseDelegateType->mTypeDef->mProject; @@ -9065,7 +9059,7 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty typeDef->mTypeCode = unspecializedDelegateType->mTypeDef->mTypeCode; typeDef->mIsDelegate = unspecializedDelegateType->mTypeDef->mIsDelegate; typeDef->mIsFunction = unspecializedDelegateType->mTypeDef->mIsFunction; - + BfMethodDef* unspecializedInvokeMethodDef = unspecializedDelegateType->mTypeDef->GetMethodByName("Invoke"); BfMethodDef* methodDef = new BfMethodDef(); @@ -9075,7 +9069,7 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty methodDef->mIdx = 0; methodDef->mIsStatic = !typeDef->mIsDelegate && !unspecializedDelegateInfo->mHasExplicitThis; methodDef->mHasExplicitThis = unspecializedDelegateInfo->mHasExplicitThis; - + auto directTypeRef = BfAstNode::ZeroedAlloc(); delegateInfo->mDirectAllocNodes.push_back(directTypeRef); if (typeDef->mIsDelegate) @@ -9088,20 +9082,20 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty delegateInfo->mDirectAllocNodes.push_back(directTypeRef); directTypeRef->Init(returnType); methodDef->mReturnTypeRef = directTypeRef; - delegateInfo->mReturnType = returnType; + delegateInfo->mReturnType = returnType; delegateInfo->mHasExplicitThis = unspecializedDelegateInfo->mHasExplicitThis; delegateInfo->mHasVarArgs = unspecializedDelegateInfo->mHasVarArgs; int paramIdx = 0; - for (int paramIdx = 0; paramIdx < (int)paramTypes.size(); paramIdx++) - { + for (int paramIdx = 0; paramIdx < (int)paramTypes.size(); paramIdx++) + { auto paramType = paramTypes[paramIdx]; - + BfParameterDef* unspecializedParamDef = unspecializedInvokeMethodDef->mParams[paramIdx]; - + if (!paramType->IsReified()) delegateType->mIsReified = false; - + auto directTypeRef = BfAstNode::ZeroedAlloc(); delegateInfo->mDirectAllocNodes.push_back(directTypeRef); directTypeRef->Init(paramType); @@ -9123,9 +9117,8 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty methodDef->mIsMutating = unspecializedInvokeMethodDef->mIsMutating; } + // - // - if (typeDef->mIsDelegate) { BfDefBuilder::AddMethod(typeDef, BfMethodType_Ctor, BfProtection_Public, false, ""); @@ -9134,7 +9127,7 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty delegateType->mContext = mContext; delegateType->mTypeDef = typeDef; - + BfType* resolvedType = NULL; if (!failed) resolvedType = ResolveType(delegateType, BfPopulateType_Identity); @@ -9142,12 +9135,12 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty { AddDependency(directTypeRef->mType, delegateType, BfDependencyMap::DependencyFlag_ParamOrReturnValue); for (auto paramType : paramTypes) - AddDependency(paramType, delegateType, BfDependencyMap::DependencyFlag_ParamOrReturnValue); + AddDependency(paramType, delegateType, BfDependencyMap::DependencyFlag_ParamOrReturnValue); } else - { + { delegateType->Dispose(); - mContext->mDelegateTypePool.GiveBack((BfDelegateType*)delegateType); + mContext->mDelegateTypePool.GiveBack((BfDelegateType*)delegateType); } BF_ASSERT((resolvedType == NULL) || resolvedType->IsTypeInstance() || resolvedType->IsPrimitiveType()); return resolvedType; @@ -9178,7 +9171,7 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty if (resolvedType != NULL) specializedType = resolvedType->ToGenericTypeInstance(); if (specializedType != NULL) - { + { if (specializedType->mGenericTypeInfo->mHadValidateErrors) return NULL; } @@ -9192,17 +9185,17 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty BfType* BfModule::ResolveSelfType(BfType* type, BfType* selfType) { if (!type->IsUnspecializedTypeVariation()) - return type; + return type; return ResolveGenericType(type, NULL, NULL, selfType); } BfType* BfModule::ResolveType(BfType* lookupType, BfPopulateType populateType, BfResolveTypeRefFlags resolveFlags) { BfResolvedTypeSet::LookupContext lookupCtx; - lookupCtx.mModule = this; + lookupCtx.mModule = this; lookupCtx.mResolveFlags = resolveFlags; BfResolvedTypeSet::EntryRef resolvedEntry; - bool inserted = mContext->mResolvedTypes.Insert(lookupType, &lookupCtx, &resolvedEntry); + bool inserted = mContext->mResolvedTypes.Insert(lookupType, &lookupCtx, &resolvedEntry); if (!resolvedEntry) return NULL; @@ -9213,22 +9206,21 @@ BfType* BfModule::ResolveType(BfType* lookupType, BfPopulateType populateType, B PopulateType(resolvedTypeRef, populateType); return resolvedTypeRef; } - + if (lookupType->IsGenericTypeInstance()) CheckUnspecializedGenericType((BfTypeInstance*)lookupType, populateType); if (lookupType->IsTuple()) - { + { auto tupleType = (BfTupleType*)lookupType; - tupleType->Finish(); + tupleType->Finish(); } resolvedEntry->mValue = lookupType; - InitType(lookupType, populateType); + InitType(lookupType, populateType); return lookupType; } - bool BfModule::IsUnboundGeneric(BfType* type) { if (type->IsVar()) @@ -9278,7 +9270,7 @@ BfGenericParamInstance* BfModule::GetGenericTypeParamInstance(int genericParamId BfGenericExtensionEntry* genericExEntry; if (genericTypeInst->mGenericTypeInfo->mGenericExtensionInfo->mExtensionMap.TryGetValue(lookupTypeDef, &genericExEntry)) - { + { return genericExEntry->mGenericParams[genericParamIdx]; } else @@ -9309,7 +9301,7 @@ void BfModule::GetActiveTypeGenericParamInstances(SizedArray prevTypeInst(mCurTypeInstance, NULL); PopulateType(genericTypeInst, BfPopulateType_Declaration); } - + if (genericTypeInst->mGenericTypeInfo->mGenericExtensionInfo != NULL) { auto activeTypeDef = GetActiveTypeDef(NULL, true); @@ -9348,7 +9340,7 @@ void BfModule::GetActiveTypeGenericParamInstances(SizedArraymGenericParamFlags; outTypeConstraint = genericParam->mTypeConstraint; @@ -9399,7 +9391,7 @@ bool BfModule::ResolveTypeResult_Validate(BfAstNode* typeRef, BfType* resolvedTy return true; BfTypeInstance* genericTypeInstance = resolvedTypeRef->ToGenericTypeInstance(); - + if ((genericTypeInstance != NULL) && (genericTypeInstance != mCurTypeInstance)) { bool doValidate = (genericTypeInstance->mGenericTypeInfo->mHadValidateErrors) || @@ -9435,13 +9427,13 @@ bool BfModule::ResolveTypeResult_Validate(BfAstNode* typeRef, BfType* resolvedTy { if (genericTypeInstance != NULL) { - auto genericTypeInfo = genericTypeInstance->GetGenericTypeInfo(); + auto genericTypeInfo = genericTypeInstance->GetGenericTypeInfo(); for (int argIdx = 0; argIdx < (int)genericInstanceTypeRef->mGenericArguments.size(); argIdx++) { ResolveTypeResult_Validate(genericInstanceTypeRef->mGenericArguments[argIdx], genericTypeInfo->mTypeGenericArguments[argIdx]); } } - } + } else if (auto elementedTypeRef = BfNodeDynCast(typeRef)) { return ResolveTypeResult_Validate(elementedTypeRef, resolvedTypeRef->GetUnderlyingType()); @@ -9454,7 +9446,7 @@ BfType* BfModule::SafeResolveAliasType(BfTypeAliasType* aliasType) { int aliasDepth = 0; HashSet seenAliases; - + BfType* type = aliasType; while (type->IsTypeAlias()) { @@ -9467,7 +9459,7 @@ BfType* BfModule::SafeResolveAliasType(BfTypeAliasType* aliasType) type = type->GetUnderlyingType(); if (type == NULL) - return NULL; + return NULL; } return type; } @@ -9522,7 +9514,7 @@ BfType* BfModule::ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTy if (resolvedTypeRef != NULL) resolvedTypeInstance = resolvedTypeRef->ToTypeInstance(); - bool isNamespace = false; + bool isNamespace = false; auto checkTypeRef = typeRef; if (auto genericTypeRef = BfNodeDynCast(checkTypeRef)) checkTypeRef = genericTypeRef->mElementType; @@ -9542,7 +9534,7 @@ BfType* BfModule::ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTy //mCompiler->mResolvePassData->mSourceClassifier->VisitChildNoRef(typeRef); } } - + BfSourceElementType elemType = BfSourceElementType_Type; { auto type = resolvedTypeRef; @@ -9590,7 +9582,7 @@ BfType* BfModule::ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTy autoComplete->CheckNamespace(qualifiedTypeRef->mLeft, resolvedTypeInstance->mTypeDef->mNamespace); } mCompiler->mResolvePassData->HandleNamespaceReference(qualifiedTypeRef->mLeft, resolvedTypeInstance->mTypeDef->mNamespace); - + isNamespace = true; } checkTypeRef = qualifiedTypeRef->mLeft; @@ -9602,7 +9594,7 @@ BfType* BfModule::ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTy bool setType = false; if ((sourceClassifier != NULL) && (checkTypeRef == headTypeRef) && (elemType != BfSourceElementType_Type)) - { + { if (auto qualifiedNameNode = BfNodeDynCast(checkNameNode)) { sourceClassifier->SetElementType(qualifiedNameNode->mRight, elemType); @@ -9654,8 +9646,8 @@ BfType* BfModule::ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTy elementTypeRef = namedTypeRef->mNameNode; if (elementTypeRef != NULL) - { - BfType* elementType = resolvedTypeRef; + { + BfType* elementType = resolvedTypeRef; if (BfTypeInstance* elementTypeInst = elementType->ToTypeInstance()) { mCompiler->mResolvePassData->HandleTypeReference(elementTypeRef, elementTypeInst->mTypeDef); @@ -9694,7 +9686,7 @@ BfType* BfModule::ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTy if ((baseNode != NULL) && (autoComplete->IsAutocompleteNode(baseNode))) { - // We didn't have this mDefType check before - why? We always want to catch the FIRST definition, + // We didn't have this mDefType check before - why? We always want to catch the FIRST definition, // so 'Type?' will catch on 'Type' and not 'Type?' if ((autoComplete->mDefType == NULL) && (autoComplete->mDefMethod == NULL) && (autoComplete->mDefField == NULL) && @@ -9706,18 +9698,18 @@ BfType* BfModule::ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTy if ((autoComplete->mResolveType == BfResolveType_GetResultString) && (resolvedTypeRef != NULL)) { - autoComplete->SetResultStringType(resolvedTypeRef); + autoComplete->SetResultStringType(resolvedTypeRef); } } } } - } + } } } } if (resolvedTypeRef == NULL) - return NULL; + return NULL; if (mCurTypeInstance == NULL) { @@ -9730,30 +9722,30 @@ BfType* BfModule::ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTy BfTypeInstance* payloadTupleType = (BfTypeInstance*)resolvedTypeRef; for (auto& payloadFieldInst : payloadTupleType->mFieldInstances) { - auto payloadFieldType = payloadFieldInst.mResolvedType; + auto payloadFieldType = payloadFieldInst.mResolvedType; AddDependency(payloadFieldType, mCurTypeInstance, BfDependencyMap::DependencyFlag_TypeReference); } } else if (resolvedTypeRef->IsDelegateFromTypeRef() || resolvedTypeRef->IsFunctionFromTypeRef()) - { + { auto delegateInfo = resolvedTypeRef->GetDelegateInfo(); // if (delegateInfo->mFunctionThisType != NULL) // AddDependency(delegateInfo->mFunctionThisType, mCurTypeInstance, BfDependencyMap::DependencyFlag_TypeReference); AddDependency(delegateInfo->mReturnType, mCurTypeInstance, BfDependencyMap::DependencyFlag_TypeReference); for (auto& param : delegateInfo->mParams) - AddDependency(param, mCurTypeInstance, BfDependencyMap::DependencyFlag_TypeReference); + AddDependency(param, mCurTypeInstance, BfDependencyMap::DependencyFlag_TypeReference); } BfTypeInstance* typeInstance = resolvedTypeRef->ToTypeInstance(); - BfTypeInstance* genericTypeInstance = resolvedTypeRef->ToGenericTypeInstance(); - + BfTypeInstance* genericTypeInstance = resolvedTypeRef->ToGenericTypeInstance(); + auto populateModule = this; if ((resolveFlags & BfResolveTypeRefFlag_NoReify) != 0) populateModule = mContext->mUnreifiedModule; - + populateModule->PopulateType(resolvedTypeRef, populateType); - - if ((typeInstance != NULL) && (typeInstance->mTypeDef != NULL) && (typeInstance->mTypeDef->mProtection == BfProtection_Internal) && + + if ((typeInstance != NULL) && (typeInstance->mTypeDef != NULL) && (typeInstance->mTypeDef->mProtection == BfProtection_Internal) && (typeInstance != mCurTypeInstance) && (typeInstance->mTypeDef->mOuterType == NULL) && (!typeRef->IsTemporary())) { if (!CheckProtection(typeInstance->mTypeDef->mProtection, typeInstance->mTypeDef, false, false)) @@ -9761,7 +9753,7 @@ BfType* BfModule::ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTy } // If the inner type is definted in an extension then we need to make sure the constraints are good - if ((typeInstance != NULL) && (typeInstance->mTypeDef != NULL) && (typeInstance->mTypeDef->mOuterType != NULL) && + if ((typeInstance != NULL) && (typeInstance->mTypeDef != NULL) && (typeInstance->mTypeDef->mOuterType != NULL) && (typeInstance->mTypeDef->mOuterType->mTypeCode == BfTypeCode_Extension)) { auto outerType = GetOuterType(typeInstance); @@ -9779,7 +9771,7 @@ BfType* BfModule::ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTy if (!ResolveTypeResult_Validate(typeRef, resolvedTypeRef)) return NULL; } - + if ((populateType != BfPopulateType_TypeDef) && (populateType != BfPopulateType_IdentityNoRemapAlias)) { int aliasDepth = 0; @@ -9803,12 +9795,12 @@ BfType* BfModule::ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTy if (resolvedTypeRef->mDefineState == BfTypeDefineState_Undefined) PopulateType(resolvedTypeRef); if ((typeInstance->mCustomAttributes != NULL) && (!typeRef->IsTemporary())) - CheckErrorAttributes(typeInstance, NULL, typeInstance->mCustomAttributes, typeRef); - resolvedTypeRef = resolvedTypeRef->GetUnderlyingType(); + CheckErrorAttributes(typeInstance, NULL, typeInstance->mCustomAttributes, typeRef); + resolvedTypeRef = resolvedTypeRef->GetUnderlyingType(); if (resolvedTypeRef != NULL) typeInstance = resolvedTypeRef->ToTypeInstance(); else - typeInstance = NULL; + typeInstance = NULL; } } @@ -9899,12 +9891,12 @@ void BfModule::ShowGenericArgCountError(BfAstNode* typeRef, int wantedGenericPar } } else - genericArgDiffCount = -wantedGenericParams; - + genericArgDiffCount = -wantedGenericParams; + if (wantedGenericParams == 1) Fail("Too few generic parameters, expected one more", lastNode); else - Fail(StrFormat("Too few generic parameters, expected %d more", -genericArgDiffCount), lastNode); + Fail(StrFormat("Too few generic parameters, expected %d more", -genericArgDiffCount), lastNode); } BfTypeDef* BfModule::GetActiveTypeDef(BfTypeInstance* typeInstanceOverride, bool useMixinDecl) @@ -9919,7 +9911,6 @@ BfTypeDef* BfModule::GetActiveTypeDef(BfTypeInstance* typeInstanceOverride, bool useTypeDef = mCurMethodState->mMixinState->mMixinMethodInstance->mMethodDef->mDeclaringType->GetDefinition(); else if ((mCurMethodInstance != NULL) && (mCurMethodInstance->mMethodDef->mDeclaringType != NULL)) { - auto declTypeDef = mCurMethodInstance->mMethodDef->mDeclaringType; useTypeDef = declTypeDef->GetDefinition(); if ((declTypeDef->IsEmitted()) && (useTypeDef->mIsCombinedPartial)) @@ -9946,7 +9937,7 @@ BfTypeDef* BfModule::FindTypeDefRaw(const BfAtomComposite& findName, int numGene return mSystem->FindTypeDef(findName, 0, useTypeDef->mProject); } - BfTypeInstance* skipCheckBaseType = NULL; + BfTypeInstance* skipCheckBaseType = NULL; if (mContext->mCurTypeState != NULL) { if (mContext->mCurTypeState->mCurBaseTypeRef != NULL) @@ -9963,7 +9954,7 @@ BfTypeDef* BfModule::FindTypeDefRaw(const BfAtomComposite& findName, int numGene BfTypeDef* protErrorTypeDef = NULL; BfTypeInstance* protErrorOuterType = NULL; - + BfTypeDef* foundInnerType = NULL; if ((lookupResultCtx != NULL) && (lookupResultCtx->mIsVerify)) @@ -10032,12 +10023,12 @@ BfTypeDef* BfModule::FindTypeDefRaw(const BfAtomComposite& findName, int numGene { if (mSystem->mTypeDefs.TryGet(findName, NULL)) mSystem->FindTypeDef(findName, numGenericArgs, useTypeDef->mProject, BfAtomComposite(), allowPrivate, &lookupCtx); - + for (auto& checkNamespace : useTypeDef->mNamespaceSearch) - { - BfAtom* atom = findName.mParts[0]; + { + BfAtom* atom = findName.mParts[0]; BfAtom* prevAtom = checkNamespace.mParts[checkNamespace.mSize - 1]; - if (atom->mPrevNamesMap.ContainsKey(prevAtom)) + if (atom->mPrevNamesMap.ContainsKey(prevAtom)) mSystem->FindTypeDef(findName, numGenericArgs, useTypeDef->mProject, checkNamespace, allowPrivate, &lookupCtx); } } @@ -10053,27 +10044,27 @@ BfTypeDef* BfModule::FindTypeDefRaw(const BfAtomComposite& findName, int numGene { if (lookupCtx.HasValidMatch()) break; - + if (lookupCtx.mBestTypeDef->mProtection < BfProtection_Public) { protErrorTypeDef = lookupCtx.mBestTypeDef; protErrorOuterType = staticTypeInstance; - } + } } } } } - + if ((!lookupCtx.HasValidMatch()) && (typeInstance == NULL)) { if (useTypeDef->mOuterType != NULL) return FindTypeDefRaw(findName, numGenericArgs, typeInstance, useTypeDef->mOuterType, error); } - + if ((error != NULL) && (lookupCtx.mAmbiguousTypeDef != NULL)) { - if (error->mErrorKind == BfTypeLookupError::BfErrorKind_None) - error->mErrorKind = BfTypeLookupError::BfErrorKind_Ambiguous; + if (error->mErrorKind == BfTypeLookupError::BfErrorKind_None) + error->mErrorKind = BfTypeLookupError::BfErrorKind_Ambiguous; error->mAmbiguousTypeDef = lookupCtx.mAmbiguousTypeDef; if (error->mRefNode != NULL) @@ -10106,7 +10097,7 @@ BfTypeDef* BfModule::FindTypeDef(const BfAtomComposite& findName, int numGeneric useTypeDef = useTypeDef->GetDefinition(); if ((typeInstance == NULL) && (useTypeDef == NULL)) - { + { BfProject* project = NULL; if ((mContext->mCurTypeState != NULL) && (mContext->mCurTypeState->mActiveProject != NULL)) project = mContext->mCurTypeState->mActiveProject; @@ -10125,7 +10116,7 @@ BfTypeDef* BfModule::FindTypeDef(const BfAtomComposite& findName, int numGeneric if (!checkNamespace.IsEmpty()) checkNamespace += "."; namespaceNode->mNameNode->ToString(checkNamespace); - } + } } if (!checkNamespace.IsEmpty()) @@ -10137,8 +10128,8 @@ BfTypeDef* BfModule::FindTypeDef(const BfAtomComposite& findName, int numGeneric } BfFindTypeDefFlags findDefFlags = BfFindTypeDefFlag_None; - if ((resolveFlags & BfResolveTypeRefFlag_AllowGlobalContainer) != 0) - findDefFlags = (BfFindTypeDefFlags)(findDefFlags | BfFindTypeDefFlag_AllowGlobal); + if ((resolveFlags & BfResolveTypeRefFlag_AllowGlobalContainer) != 0) + findDefFlags = (BfFindTypeDefFlags)(findDefFlags | BfFindTypeDefFlag_AllowGlobal); BfTypeDef* ambiguousTypeDef = NULL; BfTypeDef *result = mSystem->FindTypeDef(findName, numGenericArgs, project, namespaceSearch, &ambiguousTypeDef, findDefFlags); @@ -10151,7 +10142,7 @@ BfTypeDef* BfModule::FindTypeDef(const BfAtomComposite& findName, int numGeneric } return result; - } + } if ((mCompiler->mResolvePassData != NULL) && (typeInstance != NULL)) { @@ -10174,7 +10165,7 @@ BfTypeDef* BfModule::FindTypeDef(const BfAtomComposite& findName, int numGeneric if (useTypeDef->mIsPartial) isValid = typeInstance->mTypeDef->GetDefinition()->ContainsPartial(useTypeDef); else - isValid = typeInstance->mTypeDef->GetDefinition() == useTypeDef; + isValid = typeInstance->mTypeDef->GetDefinition() == useTypeDef; if ((!isValid) && (mCurMethodInstance != NULL) && (mCurMethodInstance->mIsForeignMethodDef)) { @@ -10183,7 +10174,7 @@ BfTypeDef* BfModule::FindTypeDef(const BfAtomComposite& findName, int numGeneric } BF_ASSERT(isValid); - + typeLookupEntryPtr->mAtomUpdateIdx = typeLookupEntry.mName.GetAtomUpdateIdx(); // FindTypeDefRaw may re-enter when finding base types, so we need to expect that resultPtr can change @@ -10205,7 +10196,7 @@ BfTypeDef* BfModule::FindTypeDef(const BfAtomComposite& findName, int numGeneric } resultPtr->mTypeDef = typeDef; - resultPtr->mForceLookup = errorPtr->mErrorKind != BfTypeLookupError::BfErrorKind_None; + resultPtr->mForceLookup = errorPtr->mErrorKind != BfTypeLookupError::BfErrorKind_None; return typeDef; } @@ -10215,7 +10206,7 @@ BfTypeDef* BfModule::FindTypeDef(const BfAtomComposite& findName, int numGeneric return FindTypeDefRaw(findName, numGenericArgs, typeInstance, useTypeDef, error, NULL, resolveFlags); else return resultPtr->mTypeDef; - } + } } BfTypeDef* BfModule::FindTypeDef(const StringImpl& typeName, int numGenericArgs, BfTypeInstance* typeInstanceOverride, BfTypeLookupError* error, BfResolveTypeRefFlags resolveFlags) @@ -10228,7 +10219,7 @@ BfTypeDef* BfModule::FindTypeDef(const StringImpl& typeName, int numGenericArgs, auto result = FindTypeDef(findName, numGenericArgs, typeInstanceOverride, error, resolveFlags); // Don't allow just finding extensions here. This can happen in some 'using static' cases but generally shouldn't happen if ((result != NULL) && (result->mTypeCode == BfTypeCode_Extension)) - return NULL; + return NULL; return result; } @@ -10249,7 +10240,7 @@ BfTypeDef* BfModule::FindTypeDef(BfTypeReference* typeRef, BfTypeInstance* typeI BF_ASSERT(typeRef->IsA() || typeRef->IsA() || typeRef->IsA()); auto namedTypeRef = BfNodeDynCast(typeRef); - StringView findNameStr; + StringView findNameStr; if (namedTypeRef != NULL) findNameStr = namedTypeRef->mNameNode->ToStringView(); else @@ -10273,7 +10264,7 @@ BfTypeDef* BfModule::FindTypeDef(BfTypeReference* typeRef, BfTypeInstance* typeI findNameStr = "System.String"; Fail("'string' alias not supported, use 'String'", typeRef); } - } + } BfSizedAtomComposite findName; if ((resolveFlags & BfResolveTypeRefFlag_Attribute) != 0) @@ -10281,21 +10272,20 @@ BfTypeDef* BfModule::FindTypeDef(BfTypeReference* typeRef, BfTypeInstance* typeI String attributeName; attributeName += findNameStr; attributeName += "Attribute"; - if (!mSystem->ParseAtomComposite(attributeName, findName)) - return NULL; + if (!mSystem->ParseAtomComposite(attributeName, findName)) + return NULL; } else { - if (!mSystem->ParseAtomComposite(findNameStr, findName)) - return NULL; + if (!mSystem->ParseAtomComposite(findNameStr, findName)) + return NULL; } - - + #ifdef BF_AST_HAS_PARENT_MEMBER if (auto parentGenericTypeRef = BfNodeDynCast(typeRef->mParent)) { if (parentGenericTypeRef->mElementType == typeRef) - BF_ASSERT(numGenericParams == parentGenericTypeRef->GetGenericArgCount()); + BF_ASSERT(numGenericParams == parentGenericTypeRef->GetGenericArgCount()); } #endif @@ -10313,10 +10303,10 @@ void BfModule::CheckTypeRefFixit(BfAstNode* typeRef, const char* appendName) String typeName = typeRef->ToString(); if (appendName != NULL) typeName += appendName; - + std::set fixitNamespaces; - //TODO: Do proper value for numGenericArgs + //TODO: Do proper value for numGenericArgs mSystem->FindFixitNamespaces(typeName, -1, mCompiler->mResolvePassData->mParsers[0]->mProject, fixitNamespaces); int insertLoc = 0; @@ -10362,7 +10352,7 @@ void BfModule::TypeRefNotFound(BfTypeReference* typeRef, const char* appendName) { //BfTypeInstance* typeInstance = (typeInstanceOverride != NULL) ? typeInstanceOverride : mCurTypeInstance; // We don't need a typeInstanceOverride because that is used to lookup references - // from mixins, but it's the type using the mixin (mCurTypeInstance) that needs + // from mixins, but it's the type using the mixin (mCurTypeInstance) that needs // rebuilding if the lookup fails BfTypeInstance* typeInstance = mCurTypeInstance; BfTypeLookupEntry typeLookupEntry; @@ -10383,20 +10373,20 @@ bool BfModule::ValidateTypeWildcard(BfAstNode* typeRef, bool isAttributeRef) if (auto wildcardTypeRef = BfNodeDynCast(typeRef)) return true; - + StringT<128> nameStr; typeRef->ToString(nameStr); if (isAttributeRef) nameStr.Append("Attribute"); auto typeDef = mSystem->FindTypeDef(nameStr, (BfProject*)NULL); if ((typeDef != NULL) && (typeDef->mGenericParamDefs.IsEmpty())) - return true; + return true; if (auto qualifiedTypeRef = BfNodeDynCast(typeRef)) { if (qualifiedTypeRef->mLeft == NULL) return false; - + if (auto wildcardTypeRef = BfNodeDynCast(qualifiedTypeRef->mRight)) { StringT<128> leftNameStr; @@ -10413,7 +10403,7 @@ bool BfModule::ValidateTypeWildcard(BfAstNode* typeRef, bool isAttributeRef) return ValidateTypeWildcard(qualifiedTypeRef->mLeft, false); } - } + } if (!BfNodeIsA(typeRef)) { @@ -10442,10 +10432,10 @@ bool BfModule::ValidateTypeWildcard(BfAstNode* typeRef, bool isAttributeRef) if (auto genericTypeRef = BfNodeDynCast(typeRef)) { _ToString(genericTypeRef->mElementType, false); - genericCount += genericTypeRef->mCommas.mSize + 1; + genericCount += genericTypeRef->mCommas.mSize + 1; for (auto genericArg : genericTypeRef->mGenericArguments) if (!ValidateTypeWildcard(genericArg, false)) - return false; + return false; } else { @@ -10473,7 +10463,7 @@ bool BfModule::ValidateTypeWildcard(BfAstNode* typeRef, bool isAttributeRef) BfAtomCompositeT<16> compositeEx; if (!mSystem->ParseAtomComposite(nameEx, compositeEx)) return false; - + auto itr = mSystem->mTypeDefs.TryGet(composite); while (itr != mSystem->mTypeDefs.end()) { @@ -10503,7 +10493,7 @@ BfTypedValue BfModule::TryLookupGenericConstVaue(BfIdentifierNode* identifierNod if (contextTypeInstance != NULL) { curTypeDef = contextTypeInstance->mTypeDef; - + StringT<128> findName; identifierNode->ToString(findName); @@ -10517,7 +10507,7 @@ BfTypedValue BfModule::TryLookupGenericConstVaue(BfIdentifierNode* identifierNod genericCheckTypeInstance = GetUnspecializedTypeInstance(genericCheckTypeInstance); doUndefVal = true; } - + BfGenericParamDef* genericParamDef = NULL; BfGenericParamDef* origGenericParamDef = NULL; BfType* genericParamResult = NULL; @@ -10528,18 +10518,18 @@ BfTypedValue BfModule::TryLookupGenericConstVaue(BfIdentifierNode* identifierNod auto genericTypeInst = (BfTypeInstance*)genericCheckTypeInstance; auto* genericParams = &curTypeDef->mGenericParamDefs; auto* origGenericParams = &curTypeDef->mGenericParamDefs; - + if (genericTypeInst->mGenericTypeInfo->mGenericExtensionInfo != NULL) { auto activeTypeDef = GetActiveTypeDef(NULL, true); genericParams = &activeTypeDef->mGenericParamDefs; - } - + } + for (int genericParamIdx = (int)genericParams->size() - 1; genericParamIdx >= 0; genericParamIdx--) { auto checkGenericParamDef = (*genericParams)[genericParamIdx]; String genericName = checkGenericParamDef->mName; - + if (genericName == findName) { genericParamDef = checkGenericParamDef; @@ -10591,7 +10581,7 @@ BfTypedValue BfModule::TryLookupGenericConstVaue(BfIdentifierNode* identifierNod } if (genericParamResult != NULL) - { + { auto typeRefSource = identifierNode->GetSourceData(); if ((mCompiler->mResolvePassData != NULL) && (mCompiler->mResolvePassData->mIsClassifying) && (typeRefSource != NULL)) { @@ -10609,7 +10599,7 @@ BfTypedValue BfModule::TryLookupGenericConstVaue(BfIdentifierNode* identifierNod BfExprEvaluator exprEvaluator(this); exprEvaluator.mExpectingType = constType; - exprEvaluator.GetLiteral(identifierNode, constExprValueType->mValue); + exprEvaluator.GetLiteral(identifierNode, constExprValueType->mValue); if (exprEvaluator.mResult) { @@ -10617,7 +10607,7 @@ BfTypedValue BfModule::TryLookupGenericConstVaue(BfIdentifierNode* identifierNod if (castedVal) return BfTypedValue(castedVal, constType); } - + return exprEvaluator.mResult; } else if (genericParamResult->IsGenericParam()) @@ -10662,7 +10652,7 @@ void BfModule::GetDelegateTypeRefAttributes(BfDelegateTypeRef* delegateTypeRef, } } delete customAttributes; - } + } } BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType populateType, BfResolveTypeRefFlags resolveFlags, int numGenericArgs) @@ -10699,7 +10689,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula } if (auto dotType = BfNodeDynCastExact(typeRef)) - { + { Fail(StrFormat("Invalid use of '%s'", BfTokenToString(dotType->mDotToken->mToken)), typeRef); return NULL; } @@ -10775,13 +10765,13 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula { Fail("'Self' type is not usable here", typeRef); } - return ResolveTypeResult(typeRef, selfType, populateType, resolveFlags); + return ResolveTypeResult(typeRef, selfType, populateType, resolveFlags); } else if (findName == "SelfBase") { BfType* selfType = mCurTypeInstance; if (selfType->IsTypeAlias()) - selfType = GetOuterType(selfType); + selfType = GetOuterType(selfType); if (selfType != NULL) { resolveFlags = (BfResolveTypeRefFlags)(resolveFlags | BfResolveTypeRefFlag_FromIndirectSource); @@ -10810,7 +10800,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula if (baseType == NULL) { Fail("'SelfBase' type is not usable here", typeRef); - } + } return ResolveTypeResult(typeRef, baseType, populateType, resolveFlags); } else if (findName == "SelfOuter") @@ -10902,7 +10892,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula } } } - + if ((genericCheckTypeInstance != NULL) && (genericCheckTypeInstance->IsGenericTypeInstance()) && (genericParamResult == NULL)) { auto genericTypeInst = (BfTypeInstance*)genericCheckTypeInstance; @@ -10933,7 +10923,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula { SetAndRestoreValue prevSymbolRefKind; if (mCompiler->mResolvePassData != NULL) // Don't add these typeRefs, they are indirect - prevSymbolRefKind.Init(mCompiler->mResolvePassData->mGetSymbolReferenceKind, BfGetSymbolReferenceKind_None); + prevSymbolRefKind.Init(mCompiler->mResolvePassData->mGetSymbolReferenceKind, BfGetSymbolReferenceKind_None); genericParamResult = genericTypeInst->mGenericTypeInfo->mTypeGenericArguments[genericParamIdx]; if ((genericParamResult != NULL) && (genericParamResult->IsConstExprValue()) && @@ -10942,7 +10932,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula } } } - } + } if (genericParamResult != NULL) { @@ -10964,8 +10954,8 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula } BfTypeDef* typeDef = NULL; - - if (typeRef->IsNamedTypeReference()) + + if (typeRef->IsNamedTypeReference()) { BfTypeLookupError error; error.mRefNode = typeRef; @@ -10979,7 +10969,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula auto leftType = ResolveTypeRef(qualifiedNameNode->mLeft, NULL, BfPopulateType_Identity, (BfResolveTypeRefFlags)(resolveFlags | BfResolveTypeRefFlag_NoResolveGenericParam | BfResolveTypeRefFlag_AllowRef)); if ((leftType != NULL) && (qualifiedNameNode->mRight != NULL)) { - // Try searching within inner type + // Try searching within inner type auto resolvedType = ResolveInnerType(leftType, qualifiedNameNode->mRight, populateType, true); if (resolvedType != NULL) { @@ -10990,7 +10980,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula } } } - + if ((typeDef == NULL) && (mCurTypeInstance != NULL)) { // Try searching within inner type @@ -11012,7 +11002,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula checkOuterType = GetOuterType(checkOuterType); } } - + if (typeDef == NULL) { auto staticSearch = GetStaticSearch(); @@ -11059,7 +11049,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula } return NULL; - } + } } else if (auto typeDefTypeRef = BfNodeDynCastExact(typeRef)) { @@ -11092,7 +11082,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula StringT<128> findName; auto genericTypeRef = BfNodeDynCast(qualifiedTypeRef->mRight); - auto activeTypeDef = GetActiveTypeDef(); + auto activeTypeDef = GetActiveTypeDef(); BfProject* bfProject = NULL; if (activeTypeDef != NULL) bfProject = activeTypeDef->mProject; @@ -11186,7 +11176,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula if (leftType == NULL) { BfAutoParentNodeEntry autoParentNodeEntry(this, qualifiedTypeRef); - + auto leftPopulateType = BfPopulateType_Identity; if ((resolveFlags & BfResolveTypeRefFlag_AllowUnboundGeneric) == 0) { @@ -11197,7 +11187,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula leftType = ResolveTypeRef(qualifiedTypeRef->mLeft, leftPopulateType, (BfResolveTypeRefFlags)((resolveFlags | BfResolveTypeRefFlag_IgnoreLookupError) & ~BfResolveTypeRefFlag_Attribute)); // We throw an error below if we can't find the type } - + if (leftType == NULL) { mIgnoreErrors = prevIgnoreErrors.mPrevVal; @@ -11248,7 +11238,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula } if (auto retTypeTypeRef = BfNodeDynCastExact(typeRef)) - { + { if (retTypeTypeRef->mRetTypeToken->mToken == BfToken_RetType) { bool allowThrough = false; @@ -11274,7 +11264,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula { if ((mCurTypeInstance != NULL) && (mCurTypeInstance->IsUnspecializedTypeVariation())) { - // We could have case where we have "rettype(@T0)" and @T0 gets a type variation of @M0, but we can't do a + // We could have case where we have "rettype(@T0)" and @T0 gets a type variation of @M0, but we can't do a // GetGenericParamInstance on that allowThrough = true; } @@ -11332,12 +11322,12 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula else if (((genericParam->mTypeConstraint != NULL) && (!genericParam->mTypeConstraint->IsValueType())) || ((genericParam->mGenericParamFlags & (BfGenericParamFlag_Class)) != 0)) { - // Leave as 'T' + // Leave as 'T' } else resolvedType = CreateModifiedTypeType(resolvedType, BfToken_AllocType); } - else if (resolvedType->IsValueType()) + else if (resolvedType->IsValueType()) resolvedType = CreatePointerType(resolvedType); } } @@ -11361,7 +11351,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula resolvedType = ResolveTypeDef(mCompiler->mNullableTypeDef, typeVec, BfPopulateType_Declaration); } else if (resolvedType != NULL) - { + { if (resolvedType->IsValueType()) { if (InDefinitionSection()) @@ -11405,7 +11395,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula else Warn(0, "Use 'mut' for generic arguments which may or may not be reference types. Consider using 'ref' here, instead.", refTypeRef->mRefToken); } - } + } if (!needsRefWrap) { @@ -11415,7 +11405,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula } } - static int sCallIdx = 0; + static int sCallIdx = 0; int callIdx = sCallIdx++; if (callIdx == 0x00006CA4) { @@ -11433,9 +11423,9 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula lookupCtx.mModule = this; BfResolvedTypeSet::EntryRef resolvedEntry; if (auto delegateTypeRef = BfNodeDynCastExact(typeRef)) - GetDelegateTypeRefAttributes(delegateTypeRef, lookupCtx.mCallingConvention); + GetDelegateTypeRefAttributes(delegateTypeRef, lookupCtx.mCallingConvention); - auto inserted = mContext->mResolvedTypes.Insert(typeRef, &lookupCtx, &resolvedEntry); + auto inserted = mContext->mResolvedTypes.Insert(typeRef, &lookupCtx, &resolvedEntry); if (!resolvedEntry) { @@ -11454,7 +11444,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula if ((lookupCtx.mIsUnboundGeneric) && (lookupCtx.mRootTypeDef != NULL)) { mContext->mResolvedTypes.RemoveEntry(resolvedEntry); - return ResolveTypeResult(typeRef, ResolveTypeDef(lookupCtx.mRootTypeDef), populateType, resolveFlags); + return ResolveTypeResult(typeRef, ResolveTypeDef(lookupCtx.mRootTypeDef), populateType, resolveFlags); } if ((resolveFlags & BfResolveTypeRefFlag_NoCreate) != 0) @@ -11487,7 +11477,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula if ((outerTypeInstance != NULL) && (typeDef->mGenericParamDefs.size() != 0)) { // Try to inherit generic params from current parent - + BfTypeDef* outerType = mSystem->GetCombinedPartial(typeDef->mOuterType); BF_ASSERT(!outerType->mIsPartial); if (TypeHasParentOrEquals(outerTypeInstance->mTypeDef, outerType)) @@ -11579,7 +11569,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula #endif populateModule->InitType(typeInst, populateType); - + if (BfResolvedTypeSet::Hash(typeInst, &lookupCtx) != resolvedEntry->mHashCode) { int refHash = BfResolvedTypeSet::Hash(typeRef, &lookupCtx); @@ -11588,9 +11578,9 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula } { BF_ASSERT(BfResolvedTypeSet::Hash(typeInst, &lookupCtx) == resolvedEntry->mHashCode); - } + } return ResolveTypeResult(typeRef, typeInst, populateType, resolveFlags); - } + } else if (auto arrayTypeRef = BfNodeDynCast(typeRef)) { if (arrayTypeRef->mDimensions > 4) @@ -11607,7 +11597,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula mContext->mResolvedTypes.RemoveEntry(resolvedEntry); return ResolveTypeResult(typeRef, NULL, populateType, resolveFlags); } - + if ((arrayTypeRef->mDimensions == 1) && (arrayTypeRef->mParams.size() == 1)) { intptr elementCount = -1; @@ -11619,7 +11609,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula BfTypedValue typedVal; lookupCtx.mResolvedValueMap.TryGetValue(sizeExpr, &typedVal); if (typedVal.mKind == BfTypedValueKind_GenericConstValue) - { + { BfUnknownSizedArrayType* arrayType = new BfUnknownSizedArrayType(); arrayType->mContext = mContext; arrayType->mElementType = elementType; @@ -11682,7 +11672,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula } else if (auto genericTypeInstRef = BfNodeDynCast(typeRef)) { - BfTypeReference* outerTypeRef = NULL; + BfTypeReference* outerTypeRef = NULL; Array genericArguments; @@ -11699,7 +11689,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula } if (auto genericTypeRef = BfNodeDynCast(checkTypeRef)) - { + { for (auto genericArg : genericTypeRef->mGenericArguments) genericArguments.push_back(genericArg); checkTypeRef = genericTypeRef->mElementType; @@ -11719,7 +11709,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula } break; } - + BfTypeVector genericArgs; BfType* type = NULL; @@ -11730,13 +11720,13 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula mContext->mResolvedTypes.RemoveEntry(resolvedEntry); return ResolveTypeResult(typeRef, NULL, populateType, resolveFlags); } - + BfTypeInstance* outerTypeInstance = NULL; BfTypeDef* commonOuterType = NULL; int startDefGenericParamIdx = 0; if (outerTypeRef != NULL) - { + { BfType* outerType = lookupCtx.GetCachedResolvedType(outerTypeRef); if (outerType != NULL) { @@ -11745,9 +11735,9 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula } } else - { + { outerTypeInstance = mCurTypeInstance; - auto outerType = typeDef->mOuterType; + auto outerType = typeDef->mOuterType; commonOuterType = BfResolvedTypeSet::FindRootCommonOuterType(outerType, &lookupCtx, outerTypeInstance); } @@ -11759,24 +11749,24 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula parentTypeInstance = (BfTypeInstance*)GetOuterType(parentTypeInstance)->ToTypeInstance(); for (int i = 0; i < startDefGenericParamIdx; i++) genericArgs.push_back(parentTypeInstance->mGenericTypeInfo->mTypeGenericArguments[i]); - } + } for (auto genericArgRef : genericArguments) { - BfType* genericArg = NULL; + BfType* genericArg = NULL; lookupCtx.mResolvedTypeMap.TryGetValue(genericArgRef, &genericArg); if (genericArg == NULL) genericArg = ResolveTypeRef(genericArgRef, NULL, BfPopulateType_Identity, (BfResolveTypeRefFlags)(BfResolveTypeRefFlag_AllowGenericTypeParamConstValue | BfResolveTypeRefFlag_AllowGenericMethodParamConstValue)); if ((genericArg == NULL) || (genericArg->IsVar())) - { + { mContext->mResolvedTypes.RemoveEntry(resolvedEntry); return ResolveTypeResult(typeRef, ((genericArg != NULL) && (genericArg->IsVar())) ? genericArg : NULL, populateType, resolveFlags); } genericArgs.Add(genericArg); - } + } BfTypeInstance* genericTypeInst; - if ((type != NULL) && + if ((type != NULL) && ((type->IsDelegateFromTypeRef()) || (type->IsFunctionFromTypeRef()))) { mContext->mResolvedTypes.RemoveEntry(resolvedEntry); @@ -11813,7 +11803,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula mContext->mResolvedTypes.RemoveEntry(resolvedEntry); return ResolveTypeResult(typeRef, NULL, populateType, resolveFlags); } - + genericTypeInst->mTypeDef = typeDef; if (commonOuterType != NULL) @@ -11843,7 +11833,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula int innerWantedGenericParams = genericParamCount; if (typeDef->mOuterType != NULL) innerWantedGenericParams -= (int)typeDef->mOuterType->mGenericParamDefs.size(); - ShowGenericArgCountError(genericTypeInstRef, innerWantedGenericParams); + ShowGenericArgCountError(genericTypeInstRef, innerWantedGenericParams); delete genericTypeInst; mContext->mResolvedTypes.RemoveEntry(resolvedEntry); return ResolveTypeResult(typeRef, NULL, populateType, resolveFlags); @@ -11853,8 +11843,8 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula for (auto genericArgRef : genericArguments) { auto genericArg = genericArgs[genericParamIdx + startDefGenericParamIdx]; - - genericTypeInst->mGenericTypeInfo->mMaxGenericDepth = BF_MAX(genericTypeInst->mGenericTypeInfo->mMaxGenericDepth, genericArg->GetGenericDepth() + 1); + + genericTypeInst->mGenericTypeInfo->mMaxGenericDepth = BF_MAX(genericTypeInst->mGenericTypeInfo->mMaxGenericDepth, genericArg->GetGenericDepth() + 1); genericTypeInst->mGenericTypeInfo->mTypeGenericArguments.push_back(genericArg); genericParamIdx++; @@ -11868,8 +11858,8 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula return ResolveTypeResult(typeRef, NULL, populateType, resolveFlags); } - resolvedEntry->mValue = genericTypeInst; - + resolvedEntry->mValue = genericTypeInst; + CheckUnspecializedGenericType(genericTypeInst, populateType); populateModule->InitType(genericTypeInst, populateType); @@ -11889,7 +11879,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula BfLogSysM("Generic type %p typeHash: %8X\n", genericTypeInst, resolvedEntry->mHashCode); #endif - BF_ASSERT(BfResolvedTypeSet::Hash(genericTypeInst, &lookupCtx) == resolvedEntry->mHashCode); + BF_ASSERT(BfResolvedTypeSet::Hash(genericTypeInst, &lookupCtx) == resolvedEntry->mHashCode); return ResolveTypeResult(typeRef, genericTypeInst, populateType, resolveFlags); } else if (auto tupleTypeRef = BfNodeDynCast(typeRef)) @@ -11952,7 +11942,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula BfFieldDef* fieldDef = actualTupleType->AddField(names[fieldIdx]); fieldDef->mProtection = (names[fieldIdx][0] == '_') ? BfProtection_Private : BfProtection_Public; } - actualTupleType->Finish(); + actualTupleType->Finish(); auto parentTypeInstance = (BfTypeInstance*)mCurTypeInstance; for (int i = 0; i < parentTypeInstance->mGenericTypeInfo->mGenericParams.size(); i++) { @@ -11966,7 +11956,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula actualTupleType->mGenericTypeInfo->mIsUnspecialized |= typeGenericArg->IsGenericParam() || typeGenericArg->IsUnspecializedType(); } - CheckUnspecializedGenericType(actualTupleType, populateType); + CheckUnspecializedGenericType(actualTupleType, populateType); if (isUnspecialized) { actualTupleType->mGenericTypeInfo->mIsUnspecialized = true; @@ -11989,7 +11979,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula tupleType = actualTupleType; actualTupleType->mIsUnspecializedType = isUnspecialized; actualTupleType->mIsUnspecializedTypeVariation = isUnspecialized; - } + } tupleType->mFieldInstances.Resize(types.size()); for (int fieldIdx = 0; fieldIdx < (int)types.size(); fieldIdx++) @@ -12001,7 +11991,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula fieldInstance->mOwner = tupleType; tupleType->mGenericDepth = BF_MAX(tupleType->mGenericDepth, fieldInstance->mResolvedType->GetGenericDepth() + 1); } - + resolvedEntry->mValue = tupleType; BF_ASSERT(BfResolvedTypeSet::Hash(tupleType, &lookupCtx) == resolvedEntry->mHashCode); populateModule->InitType(tupleType, populateType); @@ -12047,7 +12037,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula else if (auto pointerTypeRef = BfNodeDynCast(typeRef)) { BfPointerType* pointerType = new BfPointerType(); - auto elementType = ResolveTypeRef(pointerTypeRef->mElementType, BfPopulateType_Identity, BfResolveTypeRefFlag_AllowGenericParamConstValue); + auto elementType = ResolveTypeRef(pointerTypeRef->mElementType, BfPopulateType_Identity, BfResolveTypeRefFlag_AllowGenericParamConstValue); if ((elementType == NULL) || (elementType->IsVar())) { delete pointerType; @@ -12088,7 +12078,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula refType->mElementType = elementType; resolvedEntry->mValue = refType; - + #ifdef _DEBUG if (BfResolvedTypeSet::Hash(refType, &lookupCtx) != resolvedEntry->mHashCode) { @@ -12109,8 +12099,8 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula { if (type->IsTypeGenericParam()) wantGeneric = true; - if (type->IsUnspecializedType()) - isUnspecialized = true; + if (type->IsUnspecializedType()) + isUnspecialized = true; }; bool failed = false; @@ -12124,7 +12114,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula _CheckType(returnType); BfType* functionThisType = NULL; - bool hasMutSpecifier = false; + bool hasMutSpecifier = false; bool isFirst = true; bool isDelegate = delegateTypeRef->mTypeToken->GetToken() == BfToken_Delegate; bool hasVarArgs = false; @@ -12132,7 +12122,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula Array paramTypes; for (int paramIdx = 0; paramIdx < delegateTypeRef->mParams.size(); paramIdx++) { - auto param = delegateTypeRef->mParams[paramIdx]; + auto param = delegateTypeRef->mParams[paramIdx]; BfResolveTypeRefFlags resolveTypeFlags = BfResolveTypeRefFlag_AllowRef; if ((param->mNameNode != NULL) && (param->mNameNode->Equals("this"))) resolveTypeFlags = (BfResolveTypeRefFlags)(resolveTypeFlags | BfResolveTypeRefFlag_NoWarnOnMut); @@ -12171,7 +12161,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula } } hasMutSpecifier = true; - functionThisType = refType->mElementType; + functionThisType = refType->mElementType; } paramTypes.Add(functionThisType); _CheckType(functionThisType); @@ -12205,21 +12195,21 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula genericTypeInst->mGenericTypeInfo = new BfGenericTypeInfo(); genericTypeInst->mGenericTypeInfo->mFinishedGenericParams = true; delegateType = genericTypeInst; - delegateInfo = delegateType->GetDelegateInfo(); + delegateInfo = delegateType->GetDelegateInfo(); auto parentTypeInstance = (BfTypeInstance*)mCurTypeInstance; for (int i = 0; i < parentTypeInstance->mGenericTypeInfo->mGenericParams.size(); i++) { - genericTypeInst->mGenericTypeInfo->mGenericParams.push_back(parentTypeInstance->mGenericTypeInfo->mGenericParams[i]->AddRef()); + genericTypeInst->mGenericTypeInfo->mGenericParams.push_back(parentTypeInstance->mGenericTypeInfo->mGenericParams[i]->AddRef()); } for (int i = 0; i < parentTypeInstance->mGenericTypeInfo->mTypeGenericArguments.size(); i++) - { + { genericTypeInst->mGenericTypeInfo->mTypeGenericArguments.push_back(parentTypeInstance->mGenericTypeInfo->mTypeGenericArguments[i]); auto typeGenericArg = genericTypeInst->mGenericTypeInfo->mTypeGenericArguments[i]; genericTypeInst->mGenericTypeInfo->mIsUnspecialized |= typeGenericArg->IsGenericParam() || typeGenericArg->IsUnspecializedType(); } CheckUnspecializedGenericType(genericTypeInst, populateType); - + // We don't ever need to do an actual pass over generic delegate methods, so it's safe to set the 'unspecialized variation' flag if (isUnspecialized) { @@ -12240,7 +12230,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula } delegateInfo->mCallingConvention = lookupCtx.mCallingConvention; - + Val128 hashContext; BfTypeDef* typeDef = new BfTypeDef(); @@ -12258,14 +12248,14 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula typeDef->mIsFunction = true; typeDef->mTypeCode = BfTypeCode_Struct; } - + BfMethodDef* methodDef = new BfMethodDef(); methodDef->mDeclaringType = typeDef; methodDef->mName = "Invoke"; methodDef->mProtection = BfProtection_Public; methodDef->mIdx = 0; - methodDef->mIsStatic = !typeDef->mIsDelegate && (functionThisType == NULL); - methodDef->mHasExplicitThis = functionThisType != NULL; + methodDef->mIsStatic = !typeDef->mIsDelegate && (functionThisType == NULL); + methodDef->mHasExplicitThis = functionThisType != NULL; if ((functionThisType != NULL) && (hasMutSpecifier)) { @@ -12274,7 +12264,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula } auto directTypeRef = BfAstNode::ZeroedAlloc(); - delegateInfo->mDirectAllocNodes.push_back(directTypeRef); + delegateInfo->mDirectAllocNodes.push_back(directTypeRef); if (typeDef->mIsDelegate) directTypeRef->Init(delegateType); else if (mCompiler->mFunctionTypeDef == NULL) @@ -12282,7 +12272,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula else directTypeRef->Init(ResolveTypeDef(mCompiler->mFunctionTypeDef)); if (!failed) - typeDef->mBaseTypes.push_back(directTypeRef); + typeDef->mBaseTypes.push_back(directTypeRef); directTypeRef = BfAstNode::ZeroedAlloc(); delegateInfo->mDirectAllocNodes.push_back(directTypeRef); @@ -12291,11 +12281,11 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula delegateInfo->mReturnType = returnType; delegateInfo->mHasExplicitThis = functionThisType != NULL; delegateInfo->mHasVarArgs = hasVarArgs; - + delegateType->mGenericDepth = BF_MAX(delegateType->mGenericDepth, returnType->GetGenericDepth() + 1); auto hashVal = mContext->mResolvedTypes.Hash(typeRef, &lookupCtx); - + //int paramSrcOfs = (functionThisType != NULL) ? 1 : 0; int paramSrcOfs = 0; for (int paramIdx = 0; paramIdx < (int)paramTypes.size(); paramIdx++) @@ -12310,7 +12300,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula paramName = param->mNameNode->ToString(); if (!paramType->IsReified()) - delegateType->mIsReified = false; + delegateType->mIsReified = false; auto directTypeRef = BfAstNode::ZeroedAlloc(); delegateInfo->mDirectAllocNodes.push_back(directTypeRef); @@ -12333,7 +12323,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula Fail("Params parameter must be the last parameter", param); } } - + if (auto dotTypeRef = BfNodeDynCast(paramDef->mTypeRef)) { if (dotTypeRef->mDotToken->mToken == BfToken_DotDotDot) @@ -12347,8 +12337,8 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula } } } - - delegateInfo->mParams.Add(paramType); + + delegateInfo->mParams.Add(paramType); delegateType->mGenericDepth = BF_MAX(delegateType->mGenericDepth, paramType->GetGenericDepth() + 1); } @@ -12356,7 +12346,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula if (delegateInfo->mHasVarArgs) { BfParameterDef* paramDef = new BfParameterDef(); - paramDef->mParamKind = BfParamKind_VarArgs; + paramDef->mParamKind = BfParamKind_VarArgs; methodDef->mParams.push_back(paramDef); } @@ -12369,8 +12359,8 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula return ResolveTypeResult(typeRef, NULL, populateType, resolveFlags); } - // - + // + if (typeDef->mIsDelegate) { BfDefBuilder::AddMethod(typeDef, BfMethodType_Ctor, BfProtection_Public, false, ""); @@ -12380,7 +12370,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula delegateType->mContext = mContext; delegateType->mTypeDef = typeDef; populateModule->InitType(delegateType, populateType); - resolvedEntry->mValue = delegateType; + resolvedEntry->mValue = delegateType; AddDependency(directTypeRef->mType, delegateType, BfDependencyMap::DependencyFlag_ParamOrReturnValue); // if (delegateInfo->mFunctionThisType != NULL) @@ -12392,7 +12382,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula if (BfResolvedTypeSet::Hash(delegateType, &lookupCtx) != resolvedEntry->mHashCode) { int refHash = BfResolvedTypeSet::Hash(typeRef, &lookupCtx); - int typeHash = BfResolvedTypeSet::Hash(delegateType, &lookupCtx); + int typeHash = BfResolvedTypeSet::Hash(delegateType, &lookupCtx); BF_ASSERT(refHash == typeHash); } BF_ASSERT(BfResolvedTypeSet::Equals(delegateType, typeRef, &lookupCtx)); @@ -12435,10 +12425,10 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula return ResolveTypeRef(constTypeRef->mElementType, populateType, (BfResolveTypeRefFlags)(resolveFlags & BfResolveTypeRefFlag_NoResolveGenericParam)); } else if (auto constExprTypeRef = BfNodeDynCastExact(typeRef)) - { + { if ((mCurTypeInstance != NULL) && (mCurTypeInstance->mDependencyMap.mMinDependDepth > 32)) { - Fail("Generic type dependency depth exceeded", typeRef); + Fail("Generic type dependency depth exceeded", typeRef); mContext->mResolvedTypes.RemoveEntry(resolvedEntry); return ResolveTypeResult(typeRef, NULL, populateType, resolveFlags); } @@ -12446,11 +12436,11 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula BfVariant result; BfType* resultType = NULL; if (constExprTypeRef->mConstExpr != NULL) - { + { result = mContext->mResolvedTypes.EvaluateToVariant(&lookupCtx, constExprTypeRef->mConstExpr, resultType); - BF_ASSERT(resultType != NULL); + BF_ASSERT(resultType != NULL); } - + auto constExprType = new BfConstExprValueType(); constExprType->mContext = mContext; @@ -12465,13 +12455,13 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula if (BfResolvedTypeSet::Hash(constExprType, &lookupCtx) != resolvedEntry->mHashCode) { int refHash = BfResolvedTypeSet::Hash(typeRef, &lookupCtx); - int typeHash = BfResolvedTypeSet::Hash(constExprType, &lookupCtx); + int typeHash = BfResolvedTypeSet::Hash(constExprType, &lookupCtx); BF_ASSERT(refHash == typeHash); } BF_ASSERT(BfResolvedTypeSet::Equals(constExprType, typeRef, &lookupCtx)); #endif - - populateModule->InitType(constExprType, populateType); + + populateModule->InitType(constExprType, populateType); return constExprType; } @@ -12494,7 +12484,7 @@ BfType* BfModule::ResolveTypeRefAllowUnboundGenerics(BfTypeReference* typeRef, B auto genericTypeDef = ResolveGenericInstanceDef(genericTypeRef); if (genericTypeDef == NULL) return NULL; - + BfTypeVector typeVector; for (int i = 0; i < (int)genericTypeDef->mGenericParamDefs.size(); i++) typeVector.push_back(GetGenericParamType(BfGenericParamKind_Type, i)); @@ -12659,7 +12649,7 @@ BfType* BfModule::ResolveTypeRef(BfAstNode* astNode, const BfSizedArraymResolvedTypes.EvaluateToVariant(&lookupCtx, expr, resultType); if (resultType != NULL) @@ -12669,7 +12659,7 @@ BfType* BfModule::ResolveTypeRef(BfAstNode* astNode, const BfSizedArray prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, true); - return CastToValue(NULL, typedVal, toType, (BfCastFlags)(castFlags | BfCastFlags_SilentFail | BfCastFlags_IsCastCheck)); + return CastToValue(NULL, typedVal, toType, (BfCastFlags)(castFlags | BfCastFlags_SilentFail | BfCastFlags_IsCastCheck)); } bool BfModule::AreSplatsCompatible(BfType* fromType, BfType* toType, bool* outNeedsMemberCasting) @@ -12690,7 +12680,7 @@ bool BfModule::AreSplatsCompatible(BfType* fromType, BfType* toType, bool* outNe return false; auto _GetTypes = [&](BfType* type, Array& types) - { + { BfTypeUtils::SplatIterate([&](BfType* memberType) { types.Add(memberType); }, type); }; @@ -12709,14 +12699,14 @@ bool BfModule::AreSplatsCompatible(BfType* fromType, BfType* toType, bool* outNe if (fromMemberType != toMemberType) { - if ((outNeedsMemberCasting != NULL) && + if ((outNeedsMemberCasting != NULL) && (fromMemberType->IsIntPtrable()) && (toMemberType->IsIntPtrable())) *outNeedsMemberCasting = true; else return false; } } - + return true; } @@ -12750,7 +12740,7 @@ BfType* BfModule::GetClosestNumericCastType(const BfTypedValue& typedVal, BfType if ((toType != NULL) && (!CanCast(GetFakeTypedValue(returnType), toType))) canCastTo = false; - + if (canCastTo) { if (bestReturnType == NULL) @@ -12788,10 +12778,10 @@ BfType* BfModule::GetClosestNumericCastType(const BfTypedValue& typedVal, BfType } BfIRValue BfModule::CastToFunction(BfAstNode* srcNode, const BfTypedValue& targetValue, BfMethodInstance* methodInstance, BfType* toType, BfCastFlags castFlags, BfIRValue irFunc) -{ +{ auto invokeMethodInstance = GetDelegateInvokeMethod(toType->ToTypeInstance()); - bool methodsThisMatch = true; + bool methodsThisMatch = true; if (invokeMethodInstance->mMethodDef->mIsStatic != methodInstance->mMethodDef->mIsStatic) methodsThisMatch = false; else @@ -12851,7 +12841,7 @@ BfIRValue BfModule::CastToFunction(BfAstNode* srcNode, const BfTypedValue& targe } else if (invokeMethodInstance->IsExactMatch(methodInstance, false, false)) { - bool handled = false; + bool handled = false; if (methodInstance->HasThis()) { auto thisType = methodInstance->GetThisType(); @@ -12876,7 +12866,7 @@ BfIRValue BfModule::CastToFunction(BfAstNode* srcNode, const BfTypedValue& targe if (TypeIsSubTypeOf(thisType->ToTypeInstance(), invokeThisType->ToTypeInstance())) { if (invokeThisWasPtr != thisWasPtr) - { + { if (invokeThisWasPtr) Fail(StrFormat("Non-static method '%s' cannot match '%s', consider removing 'mut' from 'mut %s this' in the function parameters", MethodToString(methodInstance).c_str(), TypeToString(toType).c_str(), TypeToString(thisType).c_str()), srcNode); else @@ -12884,16 +12874,16 @@ BfIRValue BfModule::CastToFunction(BfAstNode* srcNode, const BfTypedValue& targe handled = true; } } - } + } } - + if ((!methodInstance->mMethodDef->mIsStatic) && (!invokeMethodInstance->HasExplicitThis())) { handled = true; auto thisType = methodInstance->GetParamType(-1); Fail(StrFormat("Non-static method '%s' cannot match '%s', consider adding '%s this' to the function parameters", MethodToString(methodInstance).c_str(), TypeToString(toType).c_str(), TypeToString(thisType).c_str()), srcNode); } - + if (!handled) { if (invokeMethodInstance->mMethodDef->mIsStatic) @@ -12940,7 +12930,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp { bool checkUnderlying = false; bool isRef = false; - + if (((typedVal.mType->IsRef()) && (toType->IsRef()))) { isRef = true; @@ -12959,16 +12949,16 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp { auto fromInner = typedVal.mType->GetUnderlyingType(); auto toInner = toType->GetUnderlyingType(); - + if (fromInner == toInner) - { + { return typedVal.mValue; } if ((fromInner->IsTuple()) && (toInner->IsTuple())) { auto fromTuple = (BfTupleType*)fromInner; - auto toTuple = (BfTupleType*)toInner; + auto toTuple = (BfTupleType*)toInner; if (fromTuple->mFieldInstances.size() == toTuple->mFieldInstances.size()) { bool matches = true; @@ -12984,7 +12974,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp { // This is either a ref or a ptr so we don't need to set the "IsAddr" flag typedVal = MakeAddressable(typedVal); - return mBfIRBuilder->CreateBitCast(typedVal.mValue, mBfIRBuilder->MapType(toType)); + return mBfIRBuilder->CreateBitCast(typedVal.mValue, mBfIRBuilder->MapType(toType)); } } } @@ -13024,7 +13014,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp } if (explicitCast) - { + { // void* -> Func if ((typedVal.mType->IsVoidPtr()) && (toType->IsFunction())) { @@ -13038,7 +13028,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp // void* -> intptr if ((typedVal.mType->IsPointer()) && (toType->IsIntPtr())) - { + { if ((!typedVal.mType->GetUnderlyingType()->IsVoid()) && ((castFlags & BfCastFlags_FromCompiler) == 0)) { if (!ignoreErrors) @@ -13046,14 +13036,14 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp else if (!silentFail) SetFail(); } - + auto toPrimitive = (BfPrimitiveType*)toType; return mBfIRBuilder->CreatePtrToInt(typedVal.mValue, toPrimitive->mTypeDef->mTypeCode); } // intptr -> void* if ((typedVal.mType->IsIntPtr()) && (toType->IsPointer())) - { + { if ((!toType->GetUnderlyingType()->IsVoid()) && ((castFlags & BfCastFlags_FromCompiler) == 0)) { if (!ignoreErrors) @@ -13066,7 +13056,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp } } - // * <-> Var + // * <-> Var if ((typedVal.mType->IsVar()) || (toType->IsVar())) { return mBfIRBuilder->CreateUndefValue(mBfIRBuilder->MapType(toType)); @@ -13109,7 +13099,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp if ((constraintTypeInst != NULL) && (constraintTypeInst->IsDelegateOrFunction())) { - // Could be a methodref - can't cast to anything else + // Could be a methodref - can't cast to anything else } else { @@ -13166,7 +13156,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp BfIRValue retVal; - // For these casts, it's just important we get *A* value to work with here, + // For these casts, it's just important we get *A* value to work with here, // as this is just use for unspecialized parsing. We don't use the generated code { auto genericParamInst = GetGenericParamInstance((BfGenericParamType*)typedVal.mType); @@ -13193,7 +13183,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp } } - // * -> Generic param + // * -> Generic param if (toType->IsGenericParam()) { if (explicitCast) @@ -13208,7 +13198,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp auto genericParamInst = GetGenericParamInstance((BfGenericParamType*)toType); if (genericParamInst->mGenericParamFlags & BfGenericParamFlag_Var) return GetDefaultValue(toType); - + if (typedVal.mType->IsNull()) { bool allowCast = (genericParamInst->mGenericParamFlags & (BfGenericParamFlag_Class | BfGenericParamFlag_StructPtr | BfGenericParamFlag_Interface)) != 0; @@ -13219,7 +13209,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp } if (genericParamInst->mTypeConstraint != NULL) - { + { if (genericParamInst->mTypeConstraint->IsInstanceOf(mCompiler->mEnumTypeDef)) { // int->Enum @@ -13234,7 +13224,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp if (castedVal) return castedVal; } - + if (explicitCast) { if (((genericParamInst->mGenericParamFlags & BfGenericParamFlag_StructPtr) != 0) || @@ -13249,7 +13239,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp if ((typedVal.mType->IsIntegral()) && ((genericParamInst->mGenericParamFlags & BfGenericParamFlag_Enum) != 0)) { - bool allowCast = explicitCast; + bool allowCast = explicitCast; if ((!allowCast) && (typedVal.mType->IsIntegral())) { // Allow implicit cast of zero @@ -13284,11 +13274,11 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp return BfIRValue::sValueless; if (ignoreWrites) return mBfIRBuilder->GetFakeVal(); - + if (resultFlags != NULL) *resultFlags = (BfCastResultFlags)(BfCastResultFlags_IsAddr); typedVal = MakeAddressable(typedVal); - return mBfIRBuilder->CreateBitCast(typedVal.mValue, mBfIRBuilder->MapTypeInstPtr(toTypeInstance)); + return mBfIRBuilder->CreateBitCast(typedVal.mValue, mBfIRBuilder->MapTypeInstPtr(toTypeInstance)); } } @@ -13394,7 +13384,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp // Boxing? bool mayBeBox = false; - if (((typedVal.mType->IsValueType()) || (typedVal.mType->IsPointer()) || (typedVal.mType->IsValuelessType())) && + if (((typedVal.mType->IsValueType()) || (typedVal.mType->IsPointer()) || (typedVal.mType->IsValuelessType())) && ((toType->IsInterface()) || (toType == mContext->mBfObjectType))) { // Make sure there's no conversion operator before we box @@ -13403,14 +13393,14 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp } //TODO: the IsGenericParam is not valid - why did we have that? The generic param could be a struct for example... - if ((explicitCast) && ((typedVal.mType->IsInterface()) || (typedVal.mType == mContext->mBfObjectType) /*|| (typedVal.mType->IsGenericParam())*/) && + if ((explicitCast) && ((typedVal.mType->IsInterface()) || (typedVal.mType == mContext->mBfObjectType) /*|| (typedVal.mType->IsGenericParam())*/) && ((toType->IsValueType()) || (toType->IsPointer()))) { if (toType->IsValuelessType()) - return BfIRValue::sValueless; + return BfIRValue::sValueless; - if (ignoreWrites) - return mBfIRBuilder->GetFakeVal(); + if (ignoreWrites) + return mBfIRBuilder->GetFakeVal(); // Unbox! if ((castFlags & BfCastFlags_Unchecked) == 0) @@ -13471,7 +13461,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp *resultFlags = (BfCastResultFlags)(BfCastResultFlags_IsAddr | BfCastResultFlags_IsTemp); return allocaInst; } - + auto boxedType = CreateBoxedType(toType); mBfIRBuilder->PopulateType(boxedType); AddDependency(boxedType, mCurTypeInstance, BfDependencyMap::DependencyFlag_ReadFields); @@ -13482,14 +13472,14 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp valPtr = mBfIRBuilder->CreateBitCast(valPtr, mBfIRBuilder->GetPointerTo(mBfIRBuilder->MapType(toType))); } if ((toType->IsComposite()) && (resultFlags != NULL)) - { + { *resultFlags = BfCastResultFlags_IsAddr; return valPtr; } else return mBfIRBuilder->CreateLoad(valPtr, false); } - + // Null -> Nullable if ((typedVal.mType->IsNull()) && (toType->IsNullable())) { @@ -13498,15 +13488,15 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp if ((castFlags & BfCastFlags_PreferAddr) != 0) { - auto boolType = GetPrimitiveType(BfTypeCode_Boolean); - auto toTypeInst = toType->ToTypeInstance(); + auto boolType = GetPrimitiveType(BfTypeCode_Boolean); + auto toTypeInst = toType->ToTypeInstance(); int hasValueIdx = toTypeInst->mFieldInstances[1].mDataIdx; - + auto allocaInst = CreateAlloca(toType); auto hasValueAddr = mBfIRBuilder->CreateInBoundsGEP(allocaInst, 0, hasValueIdx); // has_value - mBfIRBuilder->CreateStore(GetConstValue(0, boolType), hasValueAddr); - - auto typedValue = BfTypedValue(allocaInst, toType, true); + mBfIRBuilder->CreateStore(GetConstValue(0, boolType), hasValueAddr); + + auto typedValue = BfTypedValue(allocaInst, toType, true); if (resultFlags != NULL) *resultFlags = (BfCastResultFlags)(BfCastResultFlags_IsAddr | BfCastResultFlags_IsTemp); return allocaInst; @@ -13530,7 +13520,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp return BfIRValue(); return mBfIRBuilder->GetFakeVal(); } - + BfIRValue srcPtr = typedVal.mValue; if (!typedVal.IsAddr()) { @@ -13542,7 +13532,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp auto srcAddr = mBfIRBuilder->CreateInBoundsGEP(srcPtr, 0, 1); // mValue auto srcVal = mBfIRBuilder->CreateLoad(srcAddr); - auto toVal = CastToValue(srcNode, BfTypedValue(srcVal, fromNullableType->mGenericTypeInfo->mTypeGenericArguments[0]), + auto toVal = CastToValue(srcNode, BfTypedValue(srcVal, fromNullableType->mGenericTypeInfo->mTypeGenericArguments[0]), toNullableType->mGenericTypeInfo->mTypeGenericArguments[0], ignoreErrors ? BfCastFlags_SilentFail : BfCastFlags_None); if (!toVal) return BfIRValue(); @@ -13573,7 +13563,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp if (fromTupleType->mFieldInstances.size() == toTupleType->mFieldInstances.size()) { - typedVal = LoadValue(typedVal); + typedVal = LoadValue(typedVal); BfIRValue curTupleValue = mBfIRBuilder->CreateUndefValue(mBfIRBuilder->MapType(toTupleType)); for (int valueIdx = 0; valueIdx < (int)fromTupleType->mFieldInstances.size(); valueIdx++) @@ -13627,7 +13617,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp if (constant != NULL) { BfConstExprValueType* toConstExprValueType = (BfConstExprValueType*)toType; - + auto variantVal = TypedValueToVariant(srcNode, typedVal, true); if ((mBfIRBuilder->IsIntable(variantVal.mTypeCode)) && (mBfIRBuilder->IsIntable(toConstExprValueType->mValue.mTypeCode))) { @@ -13642,7 +13632,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp if (toConstExprValueType->mValue.mTypeCode == BfTypeCode_StringId) { - int stringIdx = GetStringPoolIdx(typedVal.mValue, mBfIRBuilder); + int stringIdx = GetStringPoolIdx(typedVal.mValue, mBfIRBuilder); if ((stringIdx != -1) && (stringIdx == toConstExprValueType->mValue.mInt32)) return typedVal.mValue; } @@ -13727,7 +13717,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp BF_ASSERT(mBfIRBuilder->mIgnoreWrites); auto undefConst = (BfConstantUndef*)constant; - + BfType* bfType = NULL; if (undefConst->mType.mKind == BfIRTypeData::TypeKind_TypeCode) { @@ -13858,7 +13848,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp case BfTypeCode_UInt32: case BfTypeCode_Int64: // It may seem that we want this to require an explicit cast, - // but consider the case of + // but consider the case of // int val = Math.Max(intA, intB) // Math.Max has an int32 and int64 override, so we want the correct one to be chosen and // to be able to have the int64 return value implicitly used in a 64-bit build @@ -13971,7 +13961,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp PopulateType(svTypeInst); PopulateType(svTypeInst->mBaseType); mBfIRBuilder->PopulateType(svTypeInst); - + SizedArray spanFieldVals; spanFieldVals.Add(mBfIRBuilder->CreateConstAggZero(mBfIRBuilder->MapType(svTypeInst->mBaseType->mBaseType))); @@ -13990,8 +13980,8 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp SizedArray svFieldVals; svFieldVals.Add(mBfIRBuilder->CreateConstAgg(mBfIRBuilder->MapType(svTypeInst->mBaseType), spanFieldVals)); return mBfIRBuilder->CreateConstAgg(mBfIRBuilder->MapType(svTypeInst), svFieldVals); - } - } + } + } } } @@ -14022,9 +14012,9 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp methodMatcher.mAllowImplicitRef = true; methodMatcher.mAllowImplicitWrap = true; BfBaseClassWalker baseClassWalker(walkFromType, walkToType, this); - - bool isConstraintCheck = ((castFlags & BfCastFlags_IsConstraintCheck) != 0); - + + bool isConstraintCheck = ((castFlags & BfCastFlags_IsConstraintCheck) != 0); + BfType* bestSelfType = NULL; while (true) { @@ -14078,7 +14068,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp } } } - + if (methodMatcher.mBestMethodDef != NULL) { if (mayBeBox) @@ -14159,7 +14149,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp } } } - } + } else { BfTypedValue result; @@ -14199,7 +14189,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp // Check typedPrimitive->underlying cast if ((explicitCast) && (typedVal.mType->IsTypedPrimitive())) - { + { auto underlyingType = typedVal.mType->GetUnderlyingType(); if ((returnType == underlyingType) && (explicitCast)) { @@ -14300,7 +14290,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp // We've already verified that we can cast from the return type to toType in MethodMatcher.CheckMethod return mBfIRBuilder->GetFakeVal(); } - + result = exprEvaluator.CreateCall(&methodMatcher, BfTypedValue()); if (result.mType != toType) return CastToValue(srcNode, result, toType, (BfCastFlags)(castFlags | BfCastFlags_Explicit | BfCastFlags_NoConversionOperator), resultFlags); @@ -14322,7 +14312,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp } } } - + // Default typed primitive 'underlying casts' happen after checking cast operators if (explicitCast) { @@ -14379,7 +14369,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp } } if (allowCast) - { + { return CastToValue(srcNode, typedVal, toType->GetUnderlyingType(), castFlags); } } @@ -14389,7 +14379,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp BfBoxedType* boxedType = (BfBoxedType*)typedVal.mType; if (boxedType->mElementType->IsGenericParam()) { - // If we have a boxed generic param, the actual available interfaces constraints won't be + // If we have a boxed generic param, the actual available interfaces constraints won't be // handled, so we need to pass through again as the root generic param BfTypedValue unboxedValue = typedVal; unboxedValue.mType = boxedType->mElementType; @@ -14430,7 +14420,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp if ((castFlags & BfCastFlags_FromComptimeReturn) != 0) errStrF = "Comptime return unable to cast '%s' to '%s'"; - String errStr = StrFormat(errStrF, TypeToString(typedVal.mType).c_str(), TypeToString(toType).c_str()); + String errStr = StrFormat(errStrF, TypeToString(typedVal.mType).c_str(), TypeToString(toType).c_str()); auto error = Fail(errStr, srcNode); if ((error != NULL) && (srcNode != NULL)) @@ -14477,7 +14467,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp BfTypedValue BfModule::Cast(BfAstNode* srcNode, const BfTypedValue& typedVal, BfType* toType, BfCastFlags castFlags) { - bool explicitCast = (castFlags & BfCastFlags_Explicit) != 0; + bool explicitCast = (castFlags & BfCastFlags_Explicit) != 0; if (typedVal.mType == toType) return typedVal; @@ -14504,8 +14494,8 @@ BfTypedValue BfModule::Cast(BfAstNode* srcNode, const BfTypedValue& typedVal, Bf { return BfTypedValue(typedVal.mValue, toType, needsMemberCasting ? BfTypedValueKind_SplatHead_NeedsCasting : BfTypedValueKind_SplatHead); } - } - + } + if (typedVal.mType->IsValueType()) { auto addrTypedValue = MakeAddressable(typedVal); @@ -14588,18 +14578,18 @@ BfTypedValue BfModule::Cast(BfAstNode* srcNode, const BfTypedValue& typedVal, Bf return BfTypedValue(mBfIRBuilder->CreateBitCast(typedVal.mValue, mBfIRBuilder->MapTypeInstPtr(tupleType)), tupleType, BfTypedValueKind_ReadOnlyAddr); } else if (typedVal.IsSplat()) - { + { BfTypedValue retTypedValue = typedVal; retTypedValue.mType = tupleType; return retTypedValue; } - + BfIRValue curTupleValue = CreateAlloca(tupleType); auto loadedVal = LoadValue(typedVal); mBfIRBuilder->CreateStore(loadedVal.mValue, mBfIRBuilder->CreateBitCast(curTupleValue, mBfIRBuilder->MapTypeInstPtr(fromTupleType))); return BfTypedValue(curTupleValue, tupleType, BfTypedValueKind_TempAddr); - } - + } + BfIRValue curTupleValue = CreateAlloca(tupleType); for (int fieldIdx = 0; fieldIdx < (int)fromTupleType->mFieldInstances.size(); fieldIdx++) { @@ -14623,7 +14613,7 @@ BfTypedValue BfModule::Cast(BfAstNode* srcNode, const BfTypedValue& typedVal, Bf isCompatible = false; } } - + return BfTypedValue(curTupleValue, tupleType, BfTypedValueKind_TempAddr); } } @@ -14643,18 +14633,18 @@ BfTypedValue BfModule::Cast(BfAstNode* srcNode, const BfTypedValue& typedVal, Bf { auto fromTypeInst = typedVal.mType->ToTypeInstance(); auto toTypeInst = toType->ToTypeInstance(); - + auto fromMethodInst = GetRawMethodByName(fromTypeInst, "Invoke", -1, true); auto toMethodInst = GetRawMethodByName(toTypeInst, "Invoke", -1, true); - + auto toDelegateInfo = toTypeInst->GetDelegateInfo(); if ((fromMethodInst != NULL) && (toMethodInst != NULL) && (fromMethodInst->mCallingConvention == toMethodInst->mCallingConvention) && (fromMethodInst->mMethodDef->mIsMutating == toMethodInst->mMethodDef->mIsMutating) && - (fromMethodInst->mReturnType == toMethodInst->mReturnType) && + (fromMethodInst->mReturnType == toMethodInst->mReturnType) && (fromMethodInst->GetParamCount() == toMethodInst->GetParamCount())) - { + { bool matched = true; StringT<64> fromParamName; @@ -14696,10 +14686,10 @@ BfTypedValue BfModule::Cast(BfAstNode* srcNode, const BfTypedValue& typedVal, Bf if (matched) { - BfTypedValue loadedVal = LoadValue(typedVal); + BfTypedValue loadedVal = LoadValue(typedVal); return BfTypedValue(mBfIRBuilder->CreateBitCast(loadedVal.mValue, mBfIRBuilder->MapType(toType)), toType); } - } + } } // Struct truncate @@ -14793,14 +14783,14 @@ BfTypedValue BfModule::GetIntCoercible(const BfTypedValue& typedValue) return BfTypedValue(); if (typedValue.mValue.IsConst()) - { + { auto constant = mBfIRBuilder->GetConstant(typedValue.mValue); if (constant->mConstType == BfConstType_Agg) { uint64 intVal = 0; auto constantArray = (BfConstantAgg*)constant; - int memberIdx = 0; + int memberIdx = 0; for (int memberIdx = 0; memberIdx < (int)constantArray->mValues.size(); memberIdx++) { auto memberConstant = mBfIRBuilder->GetConstant(constantArray->mValues[memberIdx]); @@ -14847,7 +14837,7 @@ bool BfModule::TypeHasParentOrEquals(BfTypeDef* checkChildTypeDef, BfTypeDef* ch if (partial == checkType) return true; } - + return false; } @@ -14904,8 +14894,8 @@ bool BfModule::TypeIsSubTypeOf(BfTypeInstance* srcType, BfTypeInstance* wantType } // Type is incomplete. We don't do the IsIncomplete check here because of re-entry - // While handling 'var' resolution, we don't want to force a PopulateType reentry - // but we do have enough information for TypeIsSubTypeOf + // While handling 'var' resolution, we don't want to force a PopulateType reentry + // but we do have enough information for TypeIsSubTypeOf PopulateType(srcType, BfPopulateType_Interfaces_Direct); } @@ -14915,15 +14905,15 @@ bool BfModule::TypeIsSubTypeOf(BfTypeInstance* srcType, BfTypeInstance* wantType PopulateType(srcType, BfPopulateType_Interfaces_All); BfTypeDef* checkActiveTypeDef = NULL; - bool checkAccessibility = true; + bool checkAccessibility = true; if (IsInSpecializedSection()) { - // When we have a specialized section, the generic params may not be considered "included" + // When we have a specialized section, the generic params may not be considered "included" // in the module that contains the generic type definition. We rely on any casting errors // to be thrown on the unspecialized type pass. We have a similar issue with injecting mixins. - checkAccessibility = false; - } - + checkAccessibility = false; + } + auto checkType = srcType; while (checkType != NULL) { @@ -14938,7 +14928,7 @@ bool BfModule::TypeIsSubTypeOf(BfTypeInstance* srcType, BfTypeInstance* wantType // We need to be lenient when validating generic constraints // Otherwise "T where T : IB" declared in a lib won't be able to match a type B in a using project 'C', - // because this check will see the lib using 'C', which it won't consider visible + // because this check will see the lib using 'C', which it won't consider visible if ((checkActiveTypeDef != NULL) && ((mCurMethodInstance != NULL) && (mContext->mCurTypeState != NULL) && (mContext->mCurTypeState->mResolveKind != BfTypeState::ResolveKind_BuildingGenericParams))) { @@ -15002,7 +14992,7 @@ bool BfModule::TypeIsSubTypeOf(BfTypeInstance* srcType, BfTypeDef* wantType) } // Type is incomplete. We don't do the IsIncomplete check here because of re-entry - // While handling 'var' resolution, we don't want to force a PopulateType reentry + // While handling 'var' resolution, we don't want to force a PopulateType reentry // but we do have enough information for TypeIsSubTypeOf PopulateType(srcType, BfPopulateType_Interfaces_Direct); } @@ -15062,7 +15052,7 @@ int BfModule::GetTypeDistance(BfType* fromType, BfType* toType) auto toPrimType = (BfPrimitiveType*)toType; if ((fromPrimType->IsIntegral()) && (toPrimType->IsIntegral())) - { + { int fromBitSize = fromPrimType->mSize * 8; if (fromPrimType->IsSigned()) fromBitSize--; @@ -15150,23 +15140,23 @@ StringT<128> BfModule::TypeToString(BfType* resolvedType, Array* generic BfTypeNameFlags flags = BfTypeNameFlags_None; if ((mCurTypeInstance == NULL) || (!mCurTypeInstance->IsUnspecializedTypeVariation())) flags = BfTypeNameFlag_ResolveGenericParamNames; - + StringT<128> str; DoTypeToString(str, resolvedType, flags, genericMethodParamNameOverrides); return str; } StringT<128> BfModule::TypeToString(BfType* resolvedType, BfTypeNameFlags typeNameFlags, Array* genericMethodParamNameOverrides) -{ +{ StringT<128> str; - DoTypeToString(str, resolvedType, typeNameFlags, genericMethodParamNameOverrides); + DoTypeToString(str, resolvedType, typeNameFlags, genericMethodParamNameOverrides); return str; } void BfModule::VariantToString(StringImpl& str, const BfVariant& variant) { switch (variant.mTypeCode) - { + { case BfTypeCode_Boolean: if (variant.mUInt64 == 0) str += "false"; @@ -15185,7 +15175,7 @@ void BfModule::VariantToString(StringImpl& str, const BfVariant& variant) case BfTypeCode_Char8: case BfTypeCode_Char16: case BfTypeCode_Char32: - if ((variant.mUInt32 >= 32) && (variant.mUInt32 <= 0x7E)) + if ((variant.mUInt32 >= 32) && (variant.mUInt32 <= 0x7E)) str += StrFormat("'%c'", (char)variant.mUInt32); else if (variant.mUInt32 <= 0xFF) str += StrFormat("'\\x%2X'", variant.mUInt32); @@ -15285,7 +15275,7 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF DoTypeToString(str, arrayType->mGenericTypeInfo->mTypeGenericArguments[0], typeNameFlags, genericMethodNameOverrides); str += "["; for (int i = 1; i < arrayType->mDimensions; i++) - str += ","; + str += ","; str += "]"; return; } @@ -15321,7 +15311,7 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF } str += ")"; return; - } + } else if (resolvedType->IsDelegateFromTypeRef() || resolvedType->IsFunctionFromTypeRef()) { SetAndRestoreValue prevTypeInstance(mCurTypeInstance); @@ -15337,7 +15327,7 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF } auto methodDef = delegateType->mTypeDef->mMethods[0]; - + switch (methodDef->mCallingConvention) { case BfCallingConvention_Stdcall: @@ -15376,14 +15366,14 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF DoTypeToString(str, delegateInfo->mReturnType, typeNameFlags, genericMethodNameOverrides); str += "("; - bool isFirstParam = true;// + bool isFirstParam = true;// for (int paramIdx = 0; paramIdx < methodDef->mParams.size(); paramIdx++) { if (!isFirstParam) str += ", "; auto paramDef = methodDef->mParams[paramIdx]; BfTypeNameFlags innerFlags = (BfTypeNameFlags)(typeNameFlags & ~(BfTypeNameFlag_OmitNamespace | BfTypeNameFlag_OmitOuterType | BfTypeNameFlag_ExtendedInfo)); - + if (paramDef->mParamKind == BfParamKind_VarArgs) { str += "..."; @@ -15432,7 +15422,7 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF else if (resolvedType->IsTypeInstance()) { BfTypeInstance* typeInstance = (BfTypeInstance*)resolvedType; - + if ((typeNameFlags & BfTypeNameFlag_ExtendedInfo) != 0) { if (typeInstance->mTypeDef->mIsDelegate) @@ -15460,7 +15450,7 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF } if ((!typeInstance->mTypeDef->mNamespace.IsEmpty()) && (!omitNamespace)) - { + { if (!typeInstance->mTypeDef->mNamespace.IsEmpty()) { typeInstance->mTypeDef->mNamespace.ToString(str); @@ -15468,16 +15458,16 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF str += '.'; } } - - SizedArray typeDefStack; - + + SizedArray typeDefStack; + BfTypeDef* endTypeDef = NULL; if (((typeNameFlags & BfTypeNameFlag_ReduceName) != 0) && (mCurTypeInstance != NULL)) { - auto checkTypeInst = typeInstance; - + auto checkTypeInst = typeInstance; + auto outerTypeInst = GetOuterType(checkTypeInst); - if (outerTypeInst != NULL) + if (outerTypeInst != NULL) { checkTypeInst = outerTypeInst; auto checkTypeDef = checkTypeInst->mTypeDef; @@ -15661,7 +15651,7 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF if ((mCurMethodInstance != NULL) && (mCurMethodInstance->mIsUnspecializedVariation)) doResolveGenericParams = false; } - + if (!doResolveGenericParams) { if (genericParam->mGenericParamKind == BfGenericParamKind_Method) @@ -15674,7 +15664,7 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF str += (*genericMethodNameOverrides)[genericParam->mGenericParamIdx]; return; } - } + } str += StrFormat("@M%d", genericParam->mGenericParamIdx); return; } @@ -15702,7 +15692,7 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF return; } } - + if (genericParam->mGenericParamKind == BfGenericParamKind_Type) { auto curTypeInstance = mCurTypeInstance; @@ -15759,7 +15749,7 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF } else if (resolvedType->IsModifiedTypeType()) { - auto retTypeType = (BfModifiedTypeType*)resolvedType; + auto retTypeType = (BfModifiedTypeType*)resolvedType; str += BfTokenToString(retTypeType->mModifiedKind); str += "("; DoTypeToString(str, retTypeType->mElementType, typeNameFlags, genericMethodNameOverrides); @@ -15796,11 +15786,11 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF checkType = arrayType->mElementType; continue; } - + DoTypeToString(str, checkType, typeNameFlags, genericMethodNameOverrides); break; } - + for (int i = 0; i < (int)sizes.mSize; i++) { if (sizes[i] == -1) @@ -15822,11 +15812,10 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF } VariantToString(str, constExprValueType->mValue); - + return; } BFMODULE_FATAL(this, "Not implemented"); str += "???"; return; -} - +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfNamespaceVisitor.cpp b/IDEHelper/Compiler/BfNamespaceVisitor.cpp index 78caf433..d37760e0 100644 --- a/IDEHelper/Compiler/BfNamespaceVisitor.cpp +++ b/IDEHelper/Compiler/BfNamespaceVisitor.cpp @@ -6,14 +6,13 @@ USING_NS_BF; ////////////////////////////////////////////////////////////////////////// - void BfNamespaceVisitor::Visit(BfUsingDirective* usingDirective) { if (usingDirective->mNamespace == NULL) - { + { return; } - + String usingString = usingDirective->mNamespace->ToString(); BfAtomCompositeT<16> usingComposite; mSystem->ParseAtomComposite(usingString, usingComposite); @@ -24,11 +23,11 @@ void BfNamespaceVisitor::Visit(BfUsingDirective* usingDirective) } void BfNamespaceVisitor::Visit(BfUsingModDirective* usingDirective) -{ +{ BfAstNode* useNode = usingDirective->mTypeRef; BfAstNode* checkNode = usingDirective->mTypeRef; while (true) - { + { if (auto qualifiedTypeRef = BfNodeDynCast(checkNode)) checkNode = qualifiedTypeRef->mLeft; else if (auto elementedTypeRef = BfNodeDynCast(checkNode)) @@ -42,9 +41,9 @@ void BfNamespaceVisitor::Visit(BfUsingModDirective* usingDirective) if (useNode == NULL) return; - + String usingString = useNode->ToString(); - + BfAtomCompositeT<16> usingComposite; if (mSystem->ParseAtomComposite(usingString, usingComposite)) mResolvePassData->HandleNamespaceReference(useNode, usingComposite); @@ -53,7 +52,7 @@ void BfNamespaceVisitor::Visit(BfUsingModDirective* usingDirective) void BfNamespaceVisitor::Visit(BfNamespaceDeclaration* namespaceDeclaration) { BfAtomCompositeT<16> prevNamespace = mNamespace; - + if (namespaceDeclaration->mNameNode == NULL) return; @@ -64,7 +63,7 @@ void BfNamespaceVisitor::Visit(BfNamespaceDeclaration* namespaceDeclaration) if (dotIdx == -1) { BfAtom* namespaceAtom = mSystem->FindAtom(namespaceLeft); - mNamespace.Set(mNamespace.mParts, mNamespace.mSize, &namespaceAtom, 1); + mNamespace.Set(mNamespace.mParts, mNamespace.mSize, &namespaceAtom, 1); break; } @@ -76,7 +75,7 @@ void BfNamespaceVisitor::Visit(BfNamespaceDeclaration* namespaceDeclaration) if (mResolvePassData->mAutoComplete != NULL) mResolvePassData->mAutoComplete->CheckNamespace(namespaceDeclaration->mNameNode, mNamespace); mResolvePassData->HandleNamespaceReference(namespaceDeclaration->mNameNode, mNamespace); - VisitChild(namespaceDeclaration->mBody); + VisitChild(namespaceDeclaration->mBody); mNamespace = prevNamespace; } @@ -88,4 +87,4 @@ void BfNamespaceVisitor::Visit(BfBlock* block) void BfNamespaceVisitor::Visit(BfRootNode* rootNode) { VisitMembers(rootNode); -} +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfNamespaceVisitor.h b/IDEHelper/Compiler/BfNamespaceVisitor.h index 89edd11a..e072951a 100644 --- a/IDEHelper/Compiler/BfNamespaceVisitor.h +++ b/IDEHelper/Compiler/BfNamespaceVisitor.h @@ -9,7 +9,7 @@ class BfResolvePassData; class BfNamespaceVisitor : public BfStructuralVisitor { -public: +public: BfSystem* mSystem; BfResolvePassData* mResolvePassData; BfAtomComposite mNamespace; @@ -20,7 +20,7 @@ public: mSystem = NULL; mResolvePassData = NULL; } - + virtual void Visit(BfUsingDirective* usingDirective) override; virtual void Visit(BfUsingModDirective* usingDirective) override; virtual void Visit(BfNamespaceDeclaration* namespaceDeclaration) override; diff --git a/IDEHelper/Compiler/BfParser.cpp b/IDEHelper/Compiler/BfParser.cpp index 659aa9de..77d28807 100644 --- a/IDEHelper/Compiler/BfParser.cpp +++ b/IDEHelper/Compiler/BfParser.cpp @@ -1,6 +1,5 @@ #pragma warning(disable:4996) - #include "BfParser.h" #include "BfReducer.h" #include "BfPrinter.h" @@ -158,7 +157,7 @@ void BfParserCache::ReportMemory(MemReporter* memReporter) int allocPages = 0; int usedPages = 0; mAstAllocManager.GetStats(allocPages, usedPages); - + OutputDebugStrF("Parsers: %d Chars: %d UsedAlloc: %dk BytesPerChar: %d SysAllocPages: %d SysUsedPages: %d (%dk) LargeAllocs: %dk\n", (int)mEntries.size(), srcLen, allocBytesUsed / 1024, allocBytesUsed / BF_MAX(1, srcLen), allocPages, usedPages, (usedPages * BfAstAllocManager::PAGE_SIZE) / 1024, largeAllocs / 1024); @@ -182,7 +181,6 @@ static int DecodeInt(uint8* buf, int& idx) curByte = buf[idx++]; value |= ((curByte & 0x7f) << shift); shift += 7; - } while (curByte >= 128); // Sign extend negative numbers. if (((curByte & 0x40) != 0) && (shift < 64)) @@ -192,14 +190,14 @@ static int DecodeInt(uint8* buf, int& idx) static int gCurDataId = 0; BfParserData::BfParserData() -{ +{ mDataId = (int)BfpSystem_InterlockedExchangeAdd32((uint32*)&gCurDataId, 1) + 1; mHash = 0; mRefCount = -1; mJumpTable = NULL; mJumpTableSize = 0; - mFailed = false; + mFailed = false; mCharIdData = NULL; mUniqueParser = NULL; mDidReduce = false; @@ -239,7 +237,7 @@ int BfParserData::GetCharIdAtIndex(int findIndex) } void BfParserData::GetLineCharAtIdx(int idx, int& line, int& lineChar) -{ +{ if (mJumpTableSize <= 0) { line = 0; @@ -348,7 +346,7 @@ BfParser::BfParser(BfSystem* bfSystem, BfProject* bfProject) : BfSource(bfSystem { BfLogSys(bfSystem, "BfParser::BfParser %08X\n", this); - gParserCount++; + gParserCount++; mTextVersion = -1; mEmbedKind = BfSourceEmbedKind_None; @@ -374,15 +372,15 @@ BfParser::BfParser(BfSystem* bfSystem, BfProject* bfProject) : BfSource(bfSystem mLineStart = 0; //mCurToken = (BfSyntaxToken)0; mToken = BfToken_None; - mSyntaxToken = BfSyntaxToken_None; + mSyntaxToken = BfSyntaxToken_None; mTokenStart = 0; mTokenEnd = 0; - mLineNum = 0; + mLineNum = 0; mCompatMode = false; mQuickCompatMode = false; mLiteral.mWarnType = 0; - mDataId = -1; + mDataId = -1; mTriviaStart = 0; mParsingFailed = false; @@ -397,7 +395,6 @@ BfParser::BfParser(BfSystem* bfSystem, BfProject* bfProject) : BfSource(bfSystem } } - //static std::set gFoundNodes; BfParser::~BfParser() @@ -406,7 +403,6 @@ BfParser::~BfParser() if (mParserData == NULL) { - } else if (mParserData->mRefCount == -1) { @@ -419,12 +415,12 @@ BfParser::~BfParser() // Just never got added to the cache delete mParserData; } - else + else { - mParserData->Deref(); + mParserData->Deref(); } - mSourceData = NULL; + mSourceData = NULL; BfLogSys(mSystem, "BfParser::~BfParser %p\n", this); } @@ -470,9 +466,9 @@ void BfParser::TokenFail(const StringImpl& error, int offset) void BfParser::Init(uint64 cacheHash) { BF_ASSERT(mParserData == NULL); - + mParserData = new BfParserData(); - mSourceData = mParserData; + mSourceData = mParserData; mParserData->mFileName = mFileName; if (mDataId != -1) mParserData->mDataId = mDataId; @@ -481,7 +477,7 @@ void BfParser::Init(uint64 cacheHash) mParserData->mAstAllocManager = &gBfParserCache->mAstAllocManager; mParserData->mSrc = mSrc; mParserData->mSrcLength = mSrcLength; - + if (cacheHash != 0) { BfLogSysM("Creating cached parserData %p for %p %s\n", mParserData, this, mFileName.c_str()); @@ -503,9 +499,9 @@ void BfParser::Init(uint64 cacheHash) mParserData->mJumpTable = mJumpTable; mParserData->mJumpTableSize = mJumpTableSize; - + mAlloc = &mParserData->mAlloc; - mAlloc->mSourceData = mSourceData; + mAlloc->mSourceData = mSourceData; } void BfParser::NewLine() @@ -529,7 +525,7 @@ void BfParser::SetSource(const char* data, int length) const int EXTRA_BUFFER_SIZE = 80; // Extra chars for a bit of AllocChars room //TODO: Check cache - // Don't cache if we have a Cursorid set, + // Don't cache if we have a Cursorid set, // if mDataId != -1 // if BfParerFlag != 0 @@ -570,7 +566,7 @@ void BfParser::SetSource(const char* data, int length) BfParserCache::DataEntry* dataEntryP; if (gBfParserCache->mEntries.TryGetWith(lookupEntry, &dataEntryP)) - { + { mUsingCache = true; mParserData = dataEntryP->mParserData; @@ -595,7 +591,7 @@ void BfParser::SetSource(const char* data, int length) mSrcLength = length; mOrigSrcLength = length; - mSrcAllocSize = mSrcLength /*+ EXTRA_BUFFER_SIZE*/; + mSrcAllocSize = mSrcLength /*+ EXTRA_BUFFER_SIZE*/; char* ownedSrc = new char[mSrcAllocSize + 1]; if (data != NULL) memcpy(ownedSrc, data, length); @@ -753,7 +749,7 @@ BfBlock* BfParser::ParseInlineBlock(int spaceIdx, int endIdx) break; if ((childNode->IsA())) { - mSidechannelRootNode->Add(childNode); + mSidechannelRootNode->Add(childNode); mPendingSideNodes.push_back(childNode); continue; } @@ -798,7 +794,7 @@ void BfParser::HandlePragma(const StringImpl& pragma, BfBlock* block) if (paramNode->ToStringView() == "warning") { ++itr; - //auto iterNode = paramNode->mNext; + //auto iterNode = paramNode->mNext; //BfAstNode* iterNode = parentNode->mChildArr.GetAs(++curIdx); BfAstNode* iterNode = itr.Get(); @@ -863,11 +859,11 @@ void BfParser::HandlePragma(const StringImpl& pragma, BfBlock* block) } else if (paramNode->ToStringView() == "format") { - ++itr; + ++itr; BfAstNode* iterNode = itr.Get(); if (iterNode) { - if ((iterNode->ToStringView() != "disable") && + if ((iterNode->ToStringView() != "disable") && (iterNode->ToStringView() != "restore")) { mPassInstance->FailAfterAt("Expected \"disable\" or \"restore\" after \"format\"", mSourceData, paramNode->GetSrcEnd() - 1); @@ -881,13 +877,13 @@ void BfParser::HandlePragma(const StringImpl& pragma, BfBlock* block) } void BfParser::HandleDefine(const StringImpl& name, BfAstNode* paramNode) -{ +{ mPreprocessorDefines[name] = BfDefineState_ManualSet; } void BfParser::HandleUndefine(const StringImpl& name) { - mPreprocessorDefines[name] = BfDefineState_ManualUnset; + mPreprocessorDefines[name] = BfDefineState_ManualUnset; } MaybeBool BfParser::HandleIfDef(const StringImpl& name) @@ -925,16 +921,14 @@ MaybeBool BfParser::HandleProcessorCondition(BfBlock* paramNode) void BfParser::HandleInclude(BfAstNode* paramNode) { - } void BfParser::HandleIncludeNext(BfAstNode* paramNode) { - } bool BfParser::HandlePreprocessor() -{ +{ int triviaStart = mTriviaStart; int checkIdx = 0; @@ -958,7 +952,7 @@ bool BfParser::HandlePreprocessor() String pragmaParam; switch (mSrc[mSrcIdx - 1]) - { + { case '<': if (mPreprocessorIgnoreDepth > 0) return false; @@ -967,15 +961,15 @@ bool BfParser::HandlePreprocessor() case '=': if (mPreprocessorIgnoreDepth > 0) return false; - pragma = "==="; - break; + pragma = "==="; + break; case '>': if (mPreprocessorIgnoreDepth > 1) - return false; + return false; pragma = ">>>"; break; } - + bool atEnd = false; int startIdx = mSrcIdx - 1; @@ -1003,7 +997,7 @@ bool BfParser::HandlePreprocessor() } if (!hadSlash) - break; + break; } if (c == '\0') @@ -1045,7 +1039,7 @@ bool BfParser::HandlePreprocessor() BfBlock* paramNode = NULL; if (pragma.IsEmpty()) - { + { if (spaceIdx != -1) { pragma = String(mSrc + charIdx, mSrc + spaceIdx); @@ -1234,7 +1228,7 @@ bool BfParser::HandlePreprocessor() mPreprocessorNodeStack.pop_back(); } else if (pragma == "define") - { + { if ((paramNode != NULL) && (!paramNode->mChildArr.IsEmpty())) HandleDefine(paramNode->mChildArr[0]->ToString(), paramNode); wantedParam = true; @@ -1247,7 +1241,7 @@ bool BfParser::HandlePreprocessor() } else if (pragma == "error") { - wantsSingleParam = false; + wantsSingleParam = false; mPassInstance->FailAt(pragmaParam, mSourceData, startIdx, mSrcIdx - startIdx); wantedParam = true; } @@ -1370,7 +1364,6 @@ struct StrHashT<4> { const static int HASH = (StrHashT<3>::HASH) ^ Str[4]; }; - }; // This is little endian only @@ -1512,7 +1505,7 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro if (mSrc[mSrcIdx + 1] == '=') { if (mSrc[mSrcIdx + 2] == '=') - { + { if (HandlePreprocessor()) { // Conflict split @@ -1782,7 +1775,7 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro } break; case '$': - + c = mSrc[mSrcIdx]; if ((c == '\"') || (c == '@') || (c == '$')) { @@ -1795,7 +1788,7 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro case '\'': { SizedArray interpolateExpressions; - + String lineHeader; String strLiteral; char startChar = c; @@ -2139,9 +2132,9 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro mPassInstance->FailAfterAt("Expected '}'", mSourceData, newBlock->GetSrcEnd() - 1); } mInAsmBlock = false; - interpolateExpressions.Add(newBlock); + interpolateExpressions.Add(newBlock); } - + if (interpolateSetting == 1) { for (int i = 0; i < braceCount - 1; i++) @@ -2169,7 +2162,7 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro braceCount++; mSrcIdx++; } - + bool isClosingBrace = false; if (!interpolateExpressions.IsEmpty()) @@ -2186,14 +2179,14 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro isClosingBrace = true; } else if (block->mCloseBrace->mSrcStart == mSrcIdx - braceCount) - { + { block->mCloseBrace->mSrcEnd = mSrcIdx - braceCount + interpolateSetting; isClosingBrace = true; } } if (interpolateSetting == 1) - { + { for (int i = 0; i < braceCount - 1; i++) strLiteral += '}'; } @@ -2222,7 +2215,7 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro { mTokenStart = stringStart; stringStart = -1; - } + } mTriviaStart = triviaStart; mTokenEnd = mSrcIdx; @@ -2246,7 +2239,7 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro { bool isGraphemeCluster = false; - // There's no explicit unicode limit to how many diacriticals a grapheme cluster can contain, + // There's no explicit unicode limit to how many diacriticals a grapheme cluster can contain, // but we apply a limit for sanity for the purpose of this error if (strLiteral.length() < 64) { @@ -2266,7 +2259,7 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro { mLiteral.mInt64 = (uint8)strLiteral[0]; } - + if (mLiteral.mInt64 >= 0x8000) // Use 0x8000 to remain UTF16-compatible mLiteral.mTypeCode = BfTypeCode_Char32; else if (mLiteral.mInt64 >= 0x80) // Use 0x80 to remain UTF8-compatible @@ -2289,7 +2282,7 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro interpolateExpr->mTriviaStart = mTriviaStart; interpolateExpr->mSrcStart = mTokenStart; interpolateExpr->mSrcEnd = mSrcIdx; - BfSizedArrayInitIndirect(interpolateExpr->mExpressions, interpolateExpressions, mAlloc); + BfSizedArrayInitIndirect(interpolateExpr->mExpressions, interpolateExpressions, mAlloc); mGeneratedNode = interpolateExpr; mSyntaxToken = BfSyntaxToken_GeneratedNode; mToken = BfToken_None; @@ -2321,10 +2314,10 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro if (!mPendingSideNodes.IsEmpty()) { if (auto prevComment = BfNodeDynCast(mPendingSideNodes.back())) - { + { // This is required for folding '///' style multi-line documentation into a single node if (prevComment->GetTriviaStart() == mTriviaStart) - { + { auto prevCommentKind = GetCommentKind(prevComment->mSrcStart); if ((!BfIsCommentBlock(commentKind)) && (commentKind == prevCommentKind)) @@ -2339,7 +2332,7 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro if ((!handled) && (!disablePreprocessor)) { auto bfCommentNode = mAlloc->Alloc(); - bfCommentNode->Init(this); + bfCommentNode->Init(this); bfCommentNode->mCommentKind = commentKind; mSidechannelRootNode->Add(bfCommentNode); mPendingSideNodes.push_back(bfCommentNode); @@ -2547,7 +2540,7 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro return; default: if (((c >= '0') && (c <= '9')) || (c == '-')) - { + { bool prevIsDot = prevToken == BfToken_Dot; if (c == '-') @@ -2577,7 +2570,7 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro mTokenEnd = mSrcIdx; return; } - + bool hadOverflow = false; uint64 val = 0; int numberBase = 10; @@ -2674,14 +2667,14 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro { // Skip float parsing if we have a double-dot `1..` case hasDot = false; - } + } // The 'prevIsDot' helps tuple lookups like "tuple.0.0", interpreting those as two integers rather than a float if (((hasDot) && (!prevIsDot)) || (hasExp)) { // Switch to floating point mode //double dVal = val; - //double dValScale = 0.1; + //double dValScale = 0.1; //if (hasExp) //dVal *= pow(10, expVal); while (true) @@ -2796,7 +2789,7 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro if (endNumber) { mTokenEnd = mSrcIdx - 1; - mSrcIdx--; + mSrcIdx--; if ((numberBase == 0x10) && ((hexDigits >= 16) || ((hadSeps) && (hexDigits > 8)) || ((hadLeadingHexSep) && (hexDigits == 8)))) @@ -2815,7 +2808,7 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro mLiteral.mTypeCode = BfTypeCode_IntUnknown; if ((numberBase == 0x10) && (hexDigits == 7)) - mLiteral.mWarnType = BfWarning_BF4201_Only7Hex; + mLiteral.mWarnType = BfWarning_BF4201_Only7Hex; if ((numberBase == 0x10) && (hexDigits == 9)) mLiteral.mWarnType = BfWarning_BF4202_TooManyHexForInt; @@ -2830,9 +2823,9 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro mLiteral.mTypeCode = BfTypeCode_UInt64; } else if (val > 0xFFFFFFFFLL) - { + { mLiteral.mTypeCode = BfTypeCode_Int64; - } + } } mSyntaxToken = BfSyntaxToken_Literal; @@ -2859,9 +2852,9 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro val *= numberBase; val += c - 'a' + 0xa; } - + else if ((c == 'u') || (c == 'U')) - { + { if ((mSrc[mSrcIdx] == 'l') || (mSrc[mSrcIdx] == 'L')) { if (mSrc[mSrcIdx] == 'l') @@ -2888,7 +2881,7 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro else if ((c == 'l') || (c == 'L')) { if (c == 'l') - TokenFail("Uppercase 'L' required for int64"); + TokenFail("Uppercase 'L' required for int64"); if ((mSrc[mSrcIdx] == 'u') || (mSrc[mSrcIdx] == 'U')) { mSrcIdx++; @@ -2901,12 +2894,12 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro mPassInstance->FailAt("Value doesn't fit into uint64", mSourceData, mTokenStart, mSrcIdx - mTokenStart); mSyntaxToken = BfSyntaxToken_Literal; return; - } + } mTokenEnd = mSrcIdx; mLiteral.mTypeCode = BfTypeCode_Int64; mLiteral.mInt64 = (int64)val; if (val == 0x8000000000000000) - mLiteral.mTypeCode = BfTypeCode_UInt64; + mLiteral.mTypeCode = BfTypeCode_UInt64; else if (val >= 0x8000000000000000) hadOverflow = true; if (numberBase == 0x10) @@ -2938,14 +2931,14 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro else { mTokenEnd = mSrcIdx - 1; - mSrcIdx--; + mSrcIdx--; mLiteral.mUInt64 = val; mLiteral.mTypeCode = BfTypeCode_IntUnknown; mSyntaxToken = BfSyntaxToken_Literal; TokenFail("Unexpected character while parsing number", 0); return; } - + if ((uint64)prevVal > (uint64)val) hadOverflow = true; } @@ -3188,7 +3181,7 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro if (SrcPtrHasToken("new")) mToken = BfToken_New; break; - case TOKEN_HASH('n', 'u', 'l', 'l'): + case TOKEN_HASH('n', 'u', 'l', 'l'): if (SrcPtrHasToken("null")) mToken = BfToken_Null; else if (SrcPtrHasToken("nullable")) @@ -3213,7 +3206,7 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro case TOKEN_HASH('p', 'a', 'r', 'a'): if ((!mCompatMode) && (SrcPtrHasToken("params"))) mToken = BfToken_Params; - break; + break; case TOKEN_HASH('p', 'r', 'i', 'v'): if (SrcPtrHasToken("private")) mToken = BfToken_Private; @@ -3460,7 +3453,7 @@ void BfParser::NextToken(int endIdx, bool outerIsInterpolate, bool disablePrepro { if (interpolateSetting == 0) stringStart = mTokenStart; - interpolateSetting++; + interpolateSetting++; } } } @@ -3476,7 +3469,7 @@ void BfParser::ParseBlock(BfBlock* astNode, int depth, bool isInterpolate) bool isAsmBlock = false; bool isTernary = false; - SizedArray childArr; + SizedArray childArr; int parenDepth = 0; @@ -3491,7 +3484,7 @@ void BfParser::ParseBlock(BfBlock* astNode, int depth, bool isInterpolate) } NextToken(-1, isInterpolate && (parenDepth == 0)); - + if (mPreprocessorIgnoredSectionNode != NULL) { if (mSyntaxToken != BfSyntaxToken_EOF) @@ -3508,7 +3501,7 @@ void BfParser::ParseBlock(BfBlock* astNode, int depth, bool isInterpolate) gParseMemberIdx++; int memberIdx = gParseMemberIdx; - + auto childNode = CreateNode(); if (childNode == NULL) break; @@ -3556,12 +3549,12 @@ void BfParser::ParseBlock(BfBlock* astNode, int depth, bool isInterpolate) } mInAsmBlock = false; astNode->Add(newBlock); - childArr.push_back(newBlock); - } + childArr.push_back(newBlock); + } else if (mToken == BfToken_RBrace) { if (depth == 0) - Fail("Unexpected ending brace"); + Fail("Unexpected ending brace"); break; } else @@ -3578,7 +3571,7 @@ void BfParser::ParseBlock(BfBlock* astNode, int depth, bool isInterpolate) bool endNow = false; if (mToken == BfToken_Colon) - { + { endNow = true; if (!childArr.IsEmpty()) { @@ -3599,7 +3592,7 @@ void BfParser::ParseBlock(BfBlock* astNode, int depth, bool isInterpolate) if (mToken == BfToken_Comma) endNow = true; - + if (endNow) { mSrcIdx = mTokenStart; @@ -3607,7 +3600,7 @@ void BfParser::ParseBlock(BfBlock* astNode, int depth, bool isInterpolate) } } - astNode->Add(childNode); + astNode->Add(childNode); childArr.Add(childNode); if ((mSyntaxToken == BfSyntaxToken_Token) && (mToken == BfToken_RBrace)) @@ -3667,7 +3660,7 @@ void BfParser::Parse(BfPassInstance* passInstance) mSyntaxToken = BfSyntaxToken_None; mPassInstance = passInstance; - int startIdx = mSrcIdx; + int startIdx = mSrcIdx; if (mUsingCache) { @@ -3708,7 +3701,7 @@ void BfParser::Parse(BfPassInstance* passInstance) if ((mPassInstance->HasMessages()) || (mParsingFailed)) { - mParserData->mFailed = true; // Don't reuse cache if there were errors or warnings + mParserData->mFailed = true; // Don't reuse cache if there were errors or warnings } mPassInstance = NULL; @@ -3739,18 +3732,18 @@ void BfParser::Close() } else { - // It's possible two of the same entries were being parsed at the same time on different threads. + // It's possible two of the same entries were being parsed at the same time on different threads. // Just let the loser be deleted in the dtor BfLogSys(mSystem, "Duplicate parser %p not added to cache\n", this); } - } + } } void BfParser::HadSrcRealloc() { int jumpTableSize = ((mSrcAllocSize + 1) + PARSER_JUMPTABLE_DIVIDE - 1) / PARSER_JUMPTABLE_DIVIDE; if (jumpTableSize > mJumpTableSize) - { + { auto jumpTable = new BfLineStartEntry[jumpTableSize]; memset(jumpTable, 0, jumpTableSize * sizeof(BfLineStartEntry)); memcpy(jumpTable, mJumpTable, mJumpTableSize * sizeof(BfLineStartEntry)); @@ -3763,7 +3756,6 @@ void BfParser::HadSrcRealloc() mParserData->mJumpTable = mJumpTable; mParserData->mJumpTableSize = mJumpTableSize; } - } void BfParser::GenerateAutoCompleteFrom(int srcPosition) @@ -3782,7 +3774,7 @@ void BfParser::ReportMemory(MemReporter* memReporter) // if (!mUsingCache) // memReporter->AddBumpAlloc("AstAlloc", *mAlloc); -// +// // memReporter->Add("JumpTable", mJumpTableSize * sizeof(BfLineStartEntry)); memReporter->Add(sizeof(BfParser)); @@ -3917,7 +3909,7 @@ BF_EXPORT void BF_CALLTYPE BfParser_SetNextRevision(BfParser* bfParser, BfParser BF_EXPORT void BF_CALLTYPE BfParser_SetCursorIdx(BfParser* bfParser, int cursorIdx) { - bfParser->SetCursorIdx(cursorIdx); + bfParser->SetCursorIdx(cursorIdx); } BF_EXPORT void BF_CALLTYPE BfParser_SetIsClassifying(BfParser* bfParser) @@ -3961,7 +3953,7 @@ BF_EXPORT bool BF_CALLTYPE BfParser_Reduce(BfParser* bfParser, BfPassInstance* b BP_ZONE("BfParser_Reduce"); if (bfParser->mUsingCache) return true; // Already reduced - + bfParser->FinishSideNodes(); int startFailIdx = bfPassInstance->mFailedIdx; int startWarningCount = bfPassInstance->mWarningCount; @@ -4013,7 +4005,7 @@ BF_EXPORT const char* BF_CALLTYPE BfParser_DocPrep(BfParser* bfParser) bfPrinter.mCharMapping = &gCharMapping; bfPrinter.mDocPrep = true; bfPrinter.Visit(bfParser->mRootNode); - outString = bfPrinter.mOutString; + outString = bfPrinter.mOutString; return outString.c_str(); } @@ -4094,7 +4086,7 @@ BF_EXPORT BfResolvePassData* BF_CALLTYPE BfParser_CreateResolvePassData(BfParser } BF_EXPORT bool BF_CALLTYPE BfParser_BuildDefs(BfParser* bfParser, BfPassInstance* bfPassInstance, BfResolvePassData* resolvePassData, bool fullRefresh) -{ +{ if (bfParser->mCursorIdx != -1) resolvePassData->mHasCursorIdx = true; @@ -4108,7 +4100,6 @@ BF_EXPORT bool BF_CALLTYPE BfParser_BuildDefs(BfParser* bfParser, BfPassInstance BF_EXPORT void BF_CALLTYPE BfParser_RemoveDefs(BfParser* bfParser) { - } BF_EXPORT void BF_CALLTYPE BfParser_ClassifySource(BfParser* bfParser, BfSourceClassifier::CharData* charData, bool preserveFlags) @@ -4117,18 +4108,18 @@ BF_EXPORT void BF_CALLTYPE BfParser_ClassifySource(BfParser* bfParser, BfSourceC bfParser->Close(); BfSourceClassifier bfSourceClassifier(bfParser, charData); - bfSourceClassifier.mPreserveFlags = preserveFlags; + bfSourceClassifier.mPreserveFlags = preserveFlags; bfSourceClassifier.Visit(bfParser->mRootNode); bfSourceClassifier.mIsSideChannel = false; //? false or true? bfSourceClassifier.Visit(bfParser->mErrorRootNode); bfSourceClassifier.mIsSideChannel = true; - bfSourceClassifier.Visit(bfParser->mSidechannelRootNode); + bfSourceClassifier.Visit(bfParser->mSidechannelRootNode); } BF_EXPORT void BF_CALLTYPE BfParser_CreateClassifier(BfParser* bfParser, BfPassInstance* bfPassInstance, BfResolvePassData* resolvePassData, BfSourceClassifier::CharData* charData) { resolvePassData->mIsClassifying = true; - bfParser->mSourceClassifier = new BfSourceClassifier(bfParser, charData); + bfParser->mSourceClassifier = new BfSourceClassifier(bfParser, charData); bfParser->mSourceClassifier->mClassifierPassId = bfPassInstance->mClassifierPassId; if ((resolvePassData->mParsers.IsEmpty()) || (bfParser != resolvePassData->mParsers[0])) @@ -4140,7 +4131,7 @@ BF_EXPORT void BF_CALLTYPE BfParser_CreateClassifier(BfParser* bfParser, BfPassI bfParser->mSourceClassifier->mSkipMethodInternals = true; bfParser->mSourceClassifier->mSkipTypeDeclarations = true; if (charData != NULL) - { + { if ((doClassifyPass) && (bfParser->mRootNode != NULL)) bfParser->mSourceClassifier->Visit(bfParser->mRootNode); } @@ -4179,4 +4170,4 @@ BF_EXPORT void BF_CALLTYPE BfParser_GenerateAutoCompletionFrom(BfParser* bfParse BF_EXPORT void BF_CALLTYPE BfParser_SetCompleteParse(BfParser* bfParser) { bfParser->mCompleteParse = true; -} +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfParser.h b/IDEHelper/Compiler/BfParser.h index b146dfc7..d68f825e 100644 --- a/IDEHelper/Compiler/BfParser.h +++ b/IDEHelper/Compiler/BfParser.h @@ -20,15 +20,15 @@ enum BfSyntaxToken { BfSyntaxToken_None, BfSyntaxToken_Token, - BfSyntaxToken_Identifier, + BfSyntaxToken_Identifier, BfSyntaxToken_CharQuote, - BfSyntaxToken_StringQuote, + BfSyntaxToken_StringQuote, BfSyntaxToken_ForwardSlash, - BfSyntaxToken_Literal, + BfSyntaxToken_Literal, BfSyntaxToken_CommentLine, BfSyntaxToken_CommentBlock, - BfSyntaxToken_GeneratedNode, - BfSyntaxToken_FAILED, + BfSyntaxToken_GeneratedNode, + BfSyntaxToken_FAILED, BfSyntaxToken_HIT_END_IDX, BfSyntaxToken_EOF }; @@ -59,12 +59,12 @@ enum MaybeBool { MaybeBool_None = -1, MaybeBool_False = 0, - MaybeBool_True = 1, + MaybeBool_True = 1, }; class BfParserData : public BfSourceData { -public: +public: uint64 mHash; int mDataId; int mRefCount; // -1 = not cached @@ -82,7 +82,7 @@ public: Dictionary mWarningEnabledChanges; std::set mUnwarns; bool mFailed; // Don't cache if there's a warning or an error - bool mDidReduce; + bool mDidReduce; public: BfParserData(); @@ -95,11 +95,11 @@ public: } virtual BfParser* ToParser() override; - int GetCharIdAtIndex(int findIndex); + int GetCharIdAtIndex(int findIndex); void GetLineCharAtIdx(int idx, int& line, int& lineChar); bool IsUnwarnedAt(BfAstNode* node); bool IsWarningEnabledAtSrcIndex(int warningNumber, int srcIdx); - void ReportMemory(MemReporter* memReporter); + void ReportMemory(MemReporter* memReporter); }; class BfParserCache @@ -115,7 +115,7 @@ public: }; struct DataEntry - { + { BfParserData* mParserData; bool operator==(const LookupEntry& lookup) const; @@ -123,7 +123,7 @@ public: { return lookup.mParserData == mParserData; } - }; + }; public: CritSect mCritSect; @@ -131,7 +131,7 @@ public: BfAstAllocManager mAstAllocManager; HashSet mEntries; -public: +public: BfParserCache(); ~BfParserCache(); void ReportMemory(MemReporter* memReporter); @@ -153,30 +153,30 @@ enum BfSourceEmbedKind : int8 class BfParser : public BfSource { -public: +public: BfParserData* mParserData; bool mUsingCache; BfPassInstance* mPassInstance; BfSourceClassifier* mSourceClassifier; - String mFileName; + String mFileName; int mTextVersion; BfSourceEmbedKind mEmbedKind; - bool mAwaitingDelete; - + bool mAwaitingDelete; + bool mCompatMode; // Does C++ compatible parsing - bool mQuickCompatMode; + bool mQuickCompatMode; bool mScanOnly; bool mCompleteParse; bool mIsEmitted; BfLineStartEntry* mJumpTable; int mJumpTableSize; - int mOrigSrcLength; + int mOrigSrcLength; int mDataId; int mSrcIdx; int mLineStart; - int mLineNum; + int mLineNum; bool mInAsmBlock; BfParserFlag mParserFlags; @@ -186,43 +186,43 @@ public: BfSyntaxToken mSyntaxToken; int mTriviaStart; // mTriviaStart < mTokenStart when there's leading whitespace int mTokenStart; - int mTokenEnd; + int mTokenEnd; BfAstNode* mGeneratedNode; - BfVariant mLiteral; + BfVariant mLiteral; BfToken mToken; BfPreprocesorIgnoredSectionNode* mPreprocessorIgnoredSectionNode; int mPreprocessorIgnoreDepth; Array< std::pair > mPreprocessorNodeStack; Dictionary mPreprocessorDefines; - - std::set mPreprocessorIgnoredSectionStarts; + + std::set mPreprocessorIgnoredSectionStarts; public: virtual void HandleInclude(BfAstNode* paramNode); virtual void HandleIncludeNext(BfAstNode* paramNode); virtual void HandlePragma(const StringImpl& pragma, BfBlock* block); virtual void HandleDefine(const StringImpl& name, BfAstNode* paramNode); - virtual void HandleUndefine(const StringImpl& name); + virtual void HandleUndefine(const StringImpl& name); virtual MaybeBool HandleIfDef(const StringImpl& name); virtual MaybeBool HandleProcessorCondition(BfBlock* paramNode); -public: +public: void Init(uint64 cacheHash = 0); - void NewLine(); + void NewLine(); BfExpression* CreateInlineExpressionFromNode(BfBlock* block); bool EvaluatePreprocessor(BfExpression* expr); BfBlock* ParseInlineBlock(int spaceIdx, int endIdx); - bool HandlePreprocessor(); + bool HandlePreprocessor(); bool IsUnwarnedAt(BfAstNode* node); bool SrcPtrHasToken(const char* name); uint32 GetTokenHash(); void ParseBlock(BfBlock* astNode, int depth, bool isInterpolate = false); - double ParseLiteralDouble(); + double ParseLiteralDouble(); void AddErrorNode(int startIdx, int endIdx); - BfCommentKind GetCommentKind(int startIdx); + BfCommentKind GetCommentKind(int startIdx); -public: +public: BfParser(BfSystem* bfSystem, BfProject* bfProject = NULL); ~BfParser(); @@ -232,23 +232,23 @@ public: void GetLineCharAtIdx(int idx, int& line, int& lineChar); void Fail(const StringImpl& error, int offset = -1); - void TokenFail(const StringImpl& error, int offset = -1); - - void SetSource(const char* data, int length); + void TokenFail(const StringImpl& error, int offset = -1); + + void SetSource(const char* data, int length); void MoveSource(const char* data, int length); // Takes ownership of data ptr void RefSource(const char* data, int length); void MakeNegative(uint64& val, bool& hadOverflow); void NextToken(int endIdx = -1, bool outerIsInterpolate = false, bool disablePreprocessor = false); - BfAstNode* CreateNode(); - - void Parse(BfPassInstance* passInstance); + BfAstNode* CreateNode(); + + void Parse(BfPassInstance* passInstance); int GetCharIdAtIndex(int findIndex); virtual void Close() override; virtual void HadSrcRealloc() override; - void GenerateAutoCompleteFrom(int srcPosition); - - void ReportMemory(MemReporter* memReporter); + void GenerateAutoCompleteFrom(int srcPosition); + + void ReportMemory(MemReporter* memReporter); void GetSrcPosition(int idx, int& lineNum, int& column); }; diff --git a/IDEHelper/Compiler/BfPrinter.cpp b/IDEHelper/Compiler/BfPrinter.cpp index 105cde42..8eb3590b 100644 --- a/IDEHelper/Compiler/BfPrinter.cpp +++ b/IDEHelper/Compiler/BfPrinter.cpp @@ -17,8 +17,8 @@ BfPrinter::BfPrinter(BfRootNode *rootNode, BfRootNode *sidechannelRootNode, BfRo mSidechannelNextNode = mSidechannelItr.Get(); if (errorRootNode != NULL) - mErrorItr = errorRootNode->begin(); - mErrorNextNode = mErrorItr.Get(); + mErrorItr = errorRootNode->begin(); + mErrorNextNode = mErrorItr.Get(); mTriviaIdx = 0; mCurSrcIdx = 0; @@ -26,11 +26,11 @@ BfPrinter::BfPrinter(BfRootNode *rootNode, BfRootNode *sidechannelRootNode, BfRo mCurBlockState = NULL; mQueuedSpaceCount = 0; mLastSpaceOffset = 0; - mReformatting = false; + mReformatting = false; mDocPrep = false; mIgnoreTrivia = false; - mForceUseTrivia = false; - mIsFirstStatementInBlock = false; + mForceUseTrivia = false; + mIsFirstStatementInBlock = false; mFormatStart = -1; mFormatEnd = -1; mInSideChannel = false; @@ -52,7 +52,7 @@ BfPrinter::BfPrinter(BfRootNode *rootNode, BfRootNode *sidechannelRootNode, BfRo } void BfPrinter::Write(const StringView& str) -{ +{ if (str == '\n') mCurCol = 0; else if (mMaxCol > 0) @@ -66,8 +66,8 @@ void BfPrinter::Write(const StringView& str) mCurCol = ((mCurCol / mTabSize) + 1) * mTabSize; else mCurCol++; - } - } + } + } mOutString.Append(str); if (mCharMapping != NULL) @@ -75,8 +75,8 @@ void BfPrinter::Write(const StringView& str) for (int i = 0; i < (int)str.length(); i++) { int prevSrcIdx = -1; - if (mCharMapping->size() > 0) - prevSrcIdx = mCharMapping->back(); + if (mCharMapping->size() > 0) + prevSrcIdx = mCharMapping->back(); if (prevSrcIdx != -1) { bool matched = false; @@ -99,7 +99,7 @@ void BfPrinter::Write(const StringView& str) if (matched) { - // It matches the source character, extend... + // It matches the source character, extend... mCharMapping->push_back(curSrcIdx); } else @@ -113,11 +113,11 @@ void BfPrinter::Write(const StringView& str) mCharMapping->push_back(-1); } } - } + } } void BfPrinter::FlushIndent() -{ +{ while ((mQueuedSpaceCount >= mTabSize) && (!mWantsTabsAsSpaces)) { Write("\t"); @@ -126,19 +126,19 @@ void BfPrinter::FlushIndent() while (mQueuedSpaceCount > 0) { - Write(" "); + Write(" "); mQueuedSpaceCount--; } } void BfPrinter::Write(BfAstNode* node, int start, int len) { - FlushIndent(); + FlushIndent(); if (mMaxCol > 0) { int startCol = mCurCol; - + auto parserData = node->GetParserData(); for (int i = 0; i < len; i++) @@ -148,7 +148,7 @@ void BfPrinter::Write(BfAstNode* node, int start, int len) mCurCol = ((mCurCol / mTabSize) + 1) * mTabSize; else mCurCol++; - } + } } mOutString.Append(node->GetSourceData()->mSrc + start, len); @@ -157,7 +157,7 @@ void BfPrinter::Write(BfAstNode* node, int start, int len) if (start < mParser->mSrcLength) { for (int i = 0; i < len; i++) - { + { mCharMapping->push_back(start + i); } } @@ -171,11 +171,11 @@ void BfPrinter::Write(BfAstNode* node, int start, int len) void BfPrinter::WriteSourceString(BfAstNode* node) { - Write(node, node->GetSrcStart(), node->GetSrcLength()); + Write(node, node->GetSrcStart(), node->GetSrcLength()); } void BfPrinter::QueueVisitChild(BfAstNode* astNode) -{ +{ if (astNode != NULL) { mNextStateModify.mQueuedNode = astNode; @@ -188,7 +188,7 @@ void BfPrinter::QueueVisitErrorNodes(BfRootNode* astNode) { for (auto& childNodeRef : *astNode) { - BfAstNode* childNode = childNodeRef; + BfAstNode* childNode = childNodeRef; if (childNode->IsA()) QueueVisitChild(childNode); } @@ -203,16 +203,16 @@ void BfPrinter::FlushVisitChild() { if (mChildNodeQueue.size() == 0) return; - + auto nodeQueue = mChildNodeQueue; - mChildNodeQueue.Clear(); - - std::stable_sort(nodeQueue.begin(), nodeQueue.end(), CompareNodeStart); + mChildNodeQueue.Clear(); + + std::stable_sort(nodeQueue.begin(), nodeQueue.end(), CompareNodeStart); for (auto& node : nodeQueue) { mNextStateModify = node; - + VisitChild(node.mQueuedNode); if (mVirtualNewLineIdx == mNextStateModify.mWantNewLineIdx) mVirtualNewLineIdx = node.mWantNewLineIdx; @@ -230,29 +230,29 @@ void BfPrinter::VisitChildWithPrecedingSpace(BfAstNode* bfAstNode) void BfPrinter::VisitChildWithProceedingSpace(BfAstNode* bfAstNode) { if (bfAstNode == NULL) - return; + return; VisitChild(bfAstNode); ExpectSpace(); } void BfPrinter::ExpectSpace() { - mNextStateModify.mExpectingSpace = true; + mNextStateModify.mExpectingSpace = true; } void BfPrinter::ExpectNewLine() { - mNextStateModify.mWantNewLineIdx++; + mNextStateModify.mWantNewLineIdx++; } void BfPrinter::ExpectIndent() -{ +{ mNextStateModify.mWantVirtualIndent++; ExpectNewLine(); } void BfPrinter::ExpectUnindent() -{ +{ mNextStateModify.mWantVirtualIndent--; ExpectNewLine(); } @@ -261,13 +261,13 @@ void BfPrinter::VisitChildNextLine(BfAstNode* node) { if (node == NULL) return; - + if (node->IsA()) { VisitChild(node); } else - { + { ExpectNewLine(); ExpectIndent(); VisitChild(node); @@ -290,7 +290,7 @@ int BfPrinter::CalcOrigLineSpacing(BfAstNode* bfAstNode, int* lineStartIdx) else if (c == ' ') origLineSpacing += 1; else - return -1; + return -1; } if (lineStartIdx != NULL) *lineStartIdx = checkIdx + 1; @@ -305,16 +305,16 @@ void BfPrinter::WriteIgnoredNode(BfAstNode* node) { int startIdx = BF_MAX(node->mTriviaStart, mTriviaIdx); Write(node, startIdx, node->mSrcEnd - startIdx); - mTriviaIdx = node->mSrcEnd; + mTriviaIdx = node->mSrcEnd; return; } bool startsWithSpace = false; - + bool wasExpectingNewLine = mExpectingNewLine; mTriviaIdx = std::max(mTriviaIdx, node->GetTriviaStart()); - int endIdx = mTriviaIdx; + int endIdx = mTriviaIdx; int crCount = 0; auto astNodeSrc = node->GetSourceData(); int srcEnd = node->GetSrcEnd(); @@ -331,9 +331,9 @@ void BfPrinter::WriteIgnoredNode(BfAstNode* node) } bool wantsPrefixSpace = (!mOutString.IsEmpty()) && (!isspace((uint8)mOutString[mOutString.mLength - 1])); - + bool expectingNewLine = mNextStateModify.mWantNewLineIdx != mVirtualNewLineIdx; - + int startIdx = mTriviaIdx; if ((expectingNewLine) && (mReformatting)) { @@ -351,9 +351,9 @@ void BfPrinter::WriteIgnoredNode(BfAstNode* node) startIdx = node->GetSrcStart(); // Leave left-aligned preprocessor nodes if ((node->GetSourceData()->mSrc[node->GetSrcStart()] != '#') || (origLineSpacing > 0)) - mQueuedSpaceCount = origLineSpacing + mLastSpaceOffset; + mQueuedSpaceCount = origLineSpacing + mLastSpaceOffset; } - } + } auto commentNode = BfNodeDynCast(node); bool isBlockComment = false; @@ -395,7 +395,7 @@ void BfPrinter::WriteIgnoredNode(BfAstNode* node) startIdx = node->mSrcStart; if (doWrap) - { + { bool wantWrap = false; int spacedWordCount = 0; @@ -442,8 +442,8 @@ void BfPrinter::WriteIgnoredNode(BfAstNode* node) int lineEmittedChars = 0; // This handles tab adjustment within multiline comments - FlushIndent(); - bool isNewLine = false; + FlushIndent(); + bool isNewLine = false; for (int srcIdx = startIdx; srcIdx < endIdx; srcIdx++) { #ifdef A @@ -451,7 +451,7 @@ void BfPrinter::WriteIgnoredNode(BfAstNode* node) #endif bool emitChar = true; - + char c = astNodeSrc->mSrc[srcIdx]; if ((wantsPrefixSpace) && (isspace((uint8)c))) @@ -471,7 +471,7 @@ void BfPrinter::WriteIgnoredNode(BfAstNode* node) int startIdx = srcIdx; for (int checkIdx = srcIdx + 1; checkIdx < endIdx + 1; checkIdx++) { - char checkC = astNodeSrc->mSrc[checkIdx]; + char checkC = astNodeSrc->mSrc[checkIdx]; if (isBlockComment) { @@ -518,7 +518,7 @@ void BfPrinter::WriteIgnoredNode(BfAstNode* node) if ((checkC != ' ') && (checkC != '\t')) break; - } + } } if (merging) @@ -539,7 +539,7 @@ void BfPrinter::WriteIgnoredNode(BfAstNode* node) mCurCol = 0; prevHadWrap = false; } - else if (isNewLine) + else if (isNewLine) { if (c == ' ') { @@ -552,31 +552,31 @@ void BfPrinter::WriteIgnoredNode(BfAstNode* node) emitChar = false; } else - { + { // Leave left-aligned preprocessor nodes that are commented out if ((c != '#') || (mQueuedSpaceCount > 0)) mQueuedSpaceCount = std::max(0, mQueuedSpaceCount + mLastSpaceOffset); else mQueuedSpaceCount = mCurIndentLevel * mTabSize; // Do default indent - isNewLine = false; + isNewLine = false; } } if (emitChar) - { + { int startIdx = srcIdx; if (c != '\n') { while (srcIdx < endIdx) - { + { char c = astNodeSrc->mSrc[srcIdx + 1]; if (isspace((uint8)c)) break; srcIdx++; } } - + if (doWrap) { int len = 0; @@ -586,7 +586,7 @@ void BfPrinter::WriteIgnoredNode(BfAstNode* node) if (isutf(c)) len++; } - + if ((mCurCol + len > mMaxCol) && (lineEmittedChars >= 8)) { Write("\n"); @@ -595,10 +595,10 @@ void BfPrinter::WriteIgnoredNode(BfAstNode* node) if (isStarredBlockComment) Write(" * "); - else if (!isBlockComment) + else if (!isBlockComment) Write("// "); - prevHadWrap = true; - + prevHadWrap = true; + while (startIdx < endIdx) { char c = astNodeSrc->mSrc[startIdx]; @@ -611,7 +611,7 @@ void BfPrinter::WriteIgnoredNode(BfAstNode* node) } if (wantsPrefixSpace) - { + { mQueuedSpaceCount++; wantsPrefixSpace = false; } @@ -645,7 +645,7 @@ void BfPrinter::WriteIgnoredNode(BfAstNode* node) FlushIndent(); - mTriviaIdx = endIdx; + mTriviaIdx = endIdx; mIsFirstStatementInBlock = false; mExpectingNewLine = wasExpectingNewLine; } @@ -658,7 +658,7 @@ void BfPrinter::CheckRawNode(BfAstNode* node) (!BfNodeIsExact(node)) && (!BfNodeIsExact(node))) return; - + //mForceUseTrivia = true; // Usually 'raw' nodes get merged into larger nodes like expressions/statements, but if they don't then this tries to help formatting @@ -669,7 +669,7 @@ void BfPrinter::CheckRawNode(BfAstNode* node) bool inLineStart = false; int spaceCount = 0; - auto parserData = node->GetParserData(); + auto parserData = node->GetParserData(); for (int i = node->mTriviaStart; i < node->mSrcStart; i++) { char c = parserData->mSrc[i]; @@ -753,7 +753,7 @@ void BfPrinter::Update(BfAstNode* bfAstNode) } void BfPrinter::Visit(BfAstNode* bfAstNode) -{ +{ SetAndRestoreValue prevForceTrivia(mForceUseTrivia); bool newExpectingNewLine = mNextStateModify.mWantNewLineIdx != mVirtualNewLineIdx; @@ -763,7 +763,7 @@ void BfPrinter::Visit(BfAstNode* bfAstNode) int indentOffset = 0; if (bfAstNode->GetTriviaStart() != -1) - { + { if (newExpectingNewLine) { indentOffset = mNextStateModify.mWantVirtualIndent - mVirtualIndentLevel; @@ -774,7 +774,7 @@ void BfPrinter::Visit(BfAstNode* bfAstNode) while (true) { - int sidechannelDist = -1; + int sidechannelDist = -1; if (mSidechannelNextNode != NULL) sidechannelDist = bfAstNode->GetSrcStart() - mSidechannelNextNode->GetSrcStart(); @@ -795,30 +795,30 @@ void BfPrinter::Visit(BfAstNode* bfAstNode) { auto curErrorNode = mErrorNextNode; ++mErrorItr; - mErrorNextNode = mErrorItr.Get(); + mErrorNextNode = mErrorItr.Get(); mForceUseTrivia = true; - VisitChild(curErrorNode); + VisitChild(curErrorNode); } else break; } - - Update(bfAstNode); - + + Update(bfAstNode); + // When triviaStart == -1, that indicates it's a combined node where the text we want to process is on the inside - if (bfAstNode->GetTriviaStart() != -1) - { + if (bfAstNode->GetTriviaStart() != -1) + { mTriviaIdx = std::max(mTriviaIdx, bfAstNode->GetTriviaStart()); bool usedTrivia = false; - + if ((!mIgnoreTrivia) && (mTriviaIdx < bfAstNode->GetSrcStart())) { if ((!mReformatting) || (mForceUseTrivia)) { Write(bfAstNode, mTriviaIdx, bfAstNode->GetSrcStart() - mTriviaIdx); usedTrivia = true; - } - } + } + } if ((mReformatting) && (!mInSideChannel)) { @@ -838,10 +838,10 @@ void BfPrinter::Visit(BfAstNode* bfAstNode) for (int i = mTriviaIdx; i < triviaEnd; i++) { if (mIgnoreTrivia) - break; + break; char c = astNodeSrc->mSrc[i]; - + if (c == ' ') { if (spaceTriviaStart == -1) @@ -856,9 +856,9 @@ void BfPrinter::Visit(BfAstNode* bfAstNode) } if (((c == '\n') || (i == bfAstNode->GetSrcStart() - 1)) && (hadPrevLineSpacing) && (prevSpaceCount > 0)) - { + { mQueuedSpaceCount += std::max(0, spaceCount - prevSpaceCount) - std::max(0, indentOffset * mTabSize); - + prevSpaceCount = -1; hadPrevLineSpacing = false; } @@ -868,7 +868,7 @@ void BfPrinter::Visit(BfAstNode* bfAstNode) canUseTrivia = false; hadNewline = true; int backIdx = i - 1; - prevSpaceCount = 0; + prevSpaceCount = 0; while (backIdx >= 0) { char c = astNodeSrc->mSrc[backIdx]; @@ -876,7 +876,7 @@ void BfPrinter::Visit(BfAstNode* bfAstNode) prevSpaceCount++; else if (c == '\t') prevSpaceCount += mTabSize; - + if ((c == '\n') || (backIdx == 0)) { // Found previous line @@ -904,8 +904,7 @@ void BfPrinter::Visit(BfAstNode* bfAstNode) { spaceCount = 0; spaceTriviaStart = -1; - } - + } } if ((canUseTrivia) && (spaceCount > 1) && (spaceTriviaStart != -1)) @@ -946,14 +945,14 @@ void BfPrinter::Visit(BfAstNode* bfAstNode) } } else if ((mNextStateModify.mExpectingSpace) || (newExpectingNewLine)) - { + { FlushIndent(); char startChar = bfAstNode->GetSourceData()->mSrc[bfAstNode->GetSrcStart()]; bool isEnding = (startChar == ';') || (startChar == ')'); if ((!isEnding) && (mOutString.length() > 0) && (!isspace((uint8)mOutString[mOutString.length() - 1]))) Write(" "); - } - } + } + } if (!mInSideChannel) { @@ -968,7 +967,7 @@ void BfPrinter::Visit(BfAstNode* bfAstNode) mVirtualNewLineIdx = mNextStateModify.mWantNewLineIdx; } - mForceUseTrivia = false; + mForceUseTrivia = false; if (bfAstNode->GetSrcStart() >= mTriviaIdx) mTriviaIdx = bfAstNode->GetSrcStart(); @@ -978,7 +977,7 @@ void BfPrinter::Visit(BfAstNode* bfAstNode) } bool BfPrinter::CheckReplace(BfAstNode* astNode) -{ +{ return false; } @@ -1018,10 +1017,9 @@ void BfPrinter::Visit(BfNewNode* newNode) } } - void BfPrinter::Visit(BfExpression* expr) { - Visit(expr->ToBase()); + Visit(expr->ToBase()); } void BfPrinter::Visit(BfExpressionStatement* exprStmt) @@ -1044,7 +1042,7 @@ void BfPrinter::Visit(BfNamedExpression* namedExpr) } void BfPrinter::Visit(BfAttributedExpression* attribExpr) -{ +{ Visit(attribExpr->ToBase()); if (auto indexerExpr = BfNodeDynCast(attribExpr->mExpression)) @@ -1062,20 +1060,20 @@ void BfPrinter::Visit(BfAttributedExpression* attribExpr) VisitChild(indexerExpr->mArguments[i]); } - VisitChild(indexerExpr->mCloseBracket); + VisitChild(indexerExpr->mCloseBracket); } else { VisitChild(attribExpr->mAttributes); VisitChild(attribExpr->mExpression); - } + } } void BfPrinter::Visit(BfStatement* stmt) -{ +{ // Trailing semicolon must come after, so every derived type is responsible for printing it -#ifdef BF_AST_HAS_PARENT_MEMBER +#ifdef BF_AST_HAS_PARENT_MEMBER // if (stmt->mParent != NULL) // { // if (auto block = BfNodeDynCast(stmt->mParent)) @@ -1088,7 +1086,7 @@ void BfPrinter::Visit(BfStatement* stmt) // } // } #endif - + if (stmt == mCurBlockMember) ExpectNewLine(); @@ -1108,7 +1106,7 @@ void BfPrinter::Visit(BfLabelableStatement* labelableStmt) } void BfPrinter::Visit(BfCommentNode* commentNode) -{ +{ WriteIgnoredNode(commentNode); if (commentNode->mCommentKind == BfCommentKind_Line) ExpectNewLine(); @@ -1124,7 +1122,7 @@ void BfPrinter::Visit(BfPreprocessorNode* preprocessorNode) { WriteIgnoredNode(preprocessorNode); - if ((preprocessorNode->mCommand->ToStringView() == "pragma") && + if ((preprocessorNode->mCommand->ToStringView() == "pragma") && (preprocessorNode->mArgument != NULL) && (preprocessorNode->mArgument->mChildArr.mSize == 2) && (preprocessorNode->mArgument->mChildArr[0] != NULL) && @@ -1137,13 +1135,13 @@ void BfPrinter::Visit(BfPreprocessorNode* preprocessorNode) mFormatDisableCount = BF_MAX(0, mFormatDisableCount - 1); } - ExpectNewLine(); + ExpectNewLine(); } void BfPrinter::Visit(BfAttributeDirective* attributeDirective) { Visit(attributeDirective->ToBase()); - + if (attributeDirective->mAttrOpenToken != NULL) { if (attributeDirective->mAttrOpenToken->mToken == BfToken_Comma) @@ -1157,7 +1155,7 @@ void BfPrinter::Visit(BfAttributeDirective* attributeDirective) VisitChild(attributeDirective->mAttrOpenToken); } } - + if (attributeDirective->mAttributeTargetSpecifier != NULL) { if (auto attributeTargetSpecifier = BfNodeDynCast(attributeDirective->mAttributeTargetSpecifier)) @@ -1171,7 +1169,7 @@ void BfPrinter::Visit(BfAttributeDirective* attributeDirective) VisitChild(attributeDirective->mAttributeTargetSpecifier); } } - + VisitChild(attributeDirective->mAttributeTypeRef); VisitChild(attributeDirective->mCtorOpenParen); for (int i = 0; i < (int)attributeDirective->mArguments.size(); i++) @@ -1181,7 +1179,7 @@ void BfPrinter::Visit(BfAttributeDirective* attributeDirective) VisitChildNoRef(attributeDirective->mCommas.GetSafe(i - 1)); ExpectSpace(); } - VisitChild(attributeDirective->mArguments[i]); + VisitChild(attributeDirective->mArguments[i]); } VisitChild(attributeDirective->mCtorCloseParen); VisitChild(attributeDirective->mAttrCloseToken); @@ -1244,7 +1242,7 @@ void BfPrinter::Visit(BfGenericConstraintsDeclaration* genericConstraints) VisitChildNoRef(genericConstraint->mCommas.GetSafe(i - 1)); ExpectSpace(); } - VisitChild(genericConstraint->mConstraintTypes[i]); + VisitChild(genericConstraint->mConstraintTypes[i]); } } } @@ -1261,7 +1259,7 @@ void BfPrinter::Visit(BfGenericArgumentsNode* genericArgumentsNode) VisitChildNoRef(genericArgumentsNode->mCommas.GetSafe(i - 1)); ExpectSpace(); } - VisitChild(genericArgumentsNode->mGenericArgs[i]); + VisitChild(genericArgumentsNode->mGenericArgs[i]); } for (int i = (int)genericArgumentsNode->mGenericArgs.size() - 1; i < (int)genericArgumentsNode->mCommas.size(); i++) VisitChildNoRef(genericArgumentsNode->mCommas.GetSafe(i)); @@ -1286,7 +1284,7 @@ void BfPrinter::Visit(BfTokenNode* tokenNode) } if (tokenNode->GetSrcEnd() == 0) - { + { String tokenStr = BfTokenToString(tokenNode->GetToken()); Write(tokenStr); } @@ -1294,7 +1292,7 @@ void BfPrinter::Visit(BfTokenNode* tokenNode) { BF_ASSERT(tokenNode->GetSrcEnd() > tokenNode->GetSrcStart()); WriteSourceString(tokenNode); - } + } } void BfPrinter::Visit(BfTokenPairNode* tokenPairNode) @@ -1334,7 +1332,6 @@ void BfPrinter::Visit(BfLiteralExpression* literalExpr) break; } } - if (isMultiLine) { @@ -1351,7 +1348,7 @@ void BfPrinter::Visit(BfLiteralExpression* literalExpr) } checkIdx--; } - + int queuedSpaceCount = mQueuedSpaceCount; FlushIndent(); @@ -1379,14 +1376,14 @@ void BfPrinter::Visit(BfLiteralExpression* literalExpr) FlushIndent(); i--; - } + } } - + return; } } - WriteSourceString(literalExpr); + WriteSourceString(literalExpr); } void BfPrinter::Visit(BfStringInterpolationExpression* stringInterpolationExpression) @@ -1399,7 +1396,7 @@ void BfPrinter::Visit(BfStringInterpolationExpression* stringInterpolationExpres void BfPrinter::Visit(BfIdentifierNode* identifierNode) { - Visit(identifierNode->ToBase()); + Visit(identifierNode->ToBase()); if (!CheckReplace(identifierNode)) WriteSourceString(identifierNode); @@ -1449,7 +1446,7 @@ void BfPrinter::Visit(BfInitializerExpression* initExpr) VisitChild(initExpr->mTarget); BlockState blockState; - DoBlockOpen(initExpr->mTarget, initExpr->mOpenBrace, initExpr->mCloseBrace, false, blockState); + DoBlockOpen(initExpr->mTarget, initExpr->mOpenBrace, initExpr->mCloseBrace, false, blockState); for (int i = 0; i < (int)initExpr->mValues.size(); i++) { if (i > 0) @@ -1460,13 +1457,13 @@ void BfPrinter::Visit(BfInitializerExpression* initExpr) else ExpectNewLine(); } - + VisitChild(initExpr->mValues[i]); } DoBlockClose(initExpr->mTarget, initExpr->mOpenBrace, initExpr->mCloseBrace, false, blockState); // Visit(initExpr->ToBase()); -// +// // VisitChild(initExpr->mTarget); // ExpectSpace(); // VisitChild(initExpr->mOpenBrace); @@ -1569,11 +1566,11 @@ void BfPrinter::Visit(BfRefTypeRef* typeRef) void BfPrinter::Visit(BfArrayTypeRef* arrayTypeRef) { Visit((BfAstNode*)arrayTypeRef); - + std::function _VisitElements = [&](BfTypeReference* elementRef) { auto arrType = BfNodeDynCast(elementRef); - + if (arrType != NULL) { _VisitElements(arrType->mElementType); @@ -1594,7 +1591,6 @@ void BfPrinter::Visit(BfArrayTypeRef* arrayTypeRef) { if (auto tokenNode = BfNodeDynCast(param)) { - } else { @@ -1612,7 +1608,6 @@ void BfPrinter::Visit(BfArrayTypeRef* arrayTypeRef) _VisitElements(arrayTypeRef); _VisitBrackets(arrayTypeRef); - } void BfPrinter::Visit(BfGenericInstanceTypeRef* genericInstTypeRef) @@ -1645,9 +1640,9 @@ void BfPrinter::Visit(BfTupleTypeRef* typeRef) { Visit((BfAstNode*) typeRef); - VisitChild(typeRef->mOpenParen); + VisitChild(typeRef->mOpenParen); for (int i = 0; i < (int)typeRef->mFieldTypes.size(); i++) - { + { if (i > 0) { VisitChildNoRef(typeRef->mCommas.GetSafe(i - 1)); @@ -1659,7 +1654,7 @@ void BfPrinter::Visit(BfTupleTypeRef* typeRef) { ExpectSpace(); auto fieldNameNode = typeRef->mFieldNames[i]; - if (fieldNameNode != NULL) + if (fieldNameNode != NULL) VisitChild(fieldNameNode); } } @@ -1674,7 +1669,7 @@ void BfPrinter::Visit(BfDelegateTypeRef* typeRef) ExpectSpace(); VisitChild(typeRef->mAttributes); ExpectSpace(); - VisitChild(typeRef->mReturnType); + VisitChild(typeRef->mReturnType); VisitChild(typeRef->mOpenParen); for (int i = 0; i < (int)typeRef->mParams.size(); i++) @@ -1684,8 +1679,8 @@ void BfPrinter::Visit(BfDelegateTypeRef* typeRef) VisitChildNoRef(typeRef->mCommas.GetSafe(i - 1)); ExpectSpace(); } - VisitChild(typeRef->mParams[i]); - } + VisitChild(typeRef->mParams[i]); + } VisitChild(typeRef->mCloseParen); } @@ -1719,16 +1714,16 @@ void BfPrinter::Visit(BfVariableDeclaration* varDecl) } else VisitChild(varDecl->mTypeRef); - + VisitChildWithPrecedingSpace(varDecl->mNameNode); VisitChildWithPrecedingSpace(varDecl->mEqualsNode); - + if (varDecl->mInitializer != NULL) { if (varDecl->mNameNode != NULL) ExpectSpace(); VisitChild(varDecl->mInitializer); - } + } } void BfPrinter::Visit(BfParameterDeclaration* paramDecl) @@ -1749,7 +1744,7 @@ void BfPrinter::Visit(BfTypeOfExpression* typeOfExpr) VisitChild(typeOfExpr->mToken); VisitChild(typeOfExpr->mOpenParen); VisitChild(typeOfExpr->mTypeRef); - VisitChild(typeOfExpr->mCloseParen); + VisitChild(typeOfExpr->mCloseParen); } void BfPrinter::Visit(BfSizeOfExpression* sizeOfExpr) @@ -1766,7 +1761,7 @@ void BfPrinter::Visit(BfOffsetOfExpression* offsetOfExpr) { VisitChild(offsetOfExpr->mToken); VisitChild(offsetOfExpr->mOpenParen); - VisitChild(offsetOfExpr->mTypeRef); + VisitChild(offsetOfExpr->mTypeRef); VisitChild(offsetOfExpr->mCommaToken); ExpectSpace(); VisitChild(offsetOfExpr->mMemberName); @@ -1816,7 +1811,7 @@ void BfPrinter::Visit(BfDynamicCastExpression* dynCastExpr) } void BfPrinter::Visit(BfCastExpression* castExpr) -{ +{ Visit((BfAstNode*)castExpr); VisitChild(castExpr->mOpenParen); @@ -1824,7 +1819,7 @@ void BfPrinter::Visit(BfCastExpression* castExpr) VisitChild(castExpr->mCloseParen); bool surroundWithParen = false; - + if (surroundWithParen) Write("("); VisitChild(castExpr->mExpression); @@ -1861,19 +1856,19 @@ void BfPrinter::Visit(BfLambdaBindExpression* lambdaBindExpr) VisitChildNoRef(lambdaBindExpr->mCommas.GetSafe(i - 1)); ExpectSpace(); } - VisitChild(lambdaBindExpr->mParams[i]); + VisitChild(lambdaBindExpr->mParams[i]); } VisitChild(lambdaBindExpr->mCloseParen); ExpectSpace(); - VisitChild(lambdaBindExpr->mFatArrowToken); + VisitChild(lambdaBindExpr->mFatArrowToken); if (lambdaBindExpr->mBody != NULL) { if (lambdaBindExpr->mBody->IsA()) { ExpectNewLine(); ExpectIndent(); - VisitChild(lambdaBindExpr->mBody); - ExpectUnindent(); + VisitChild(lambdaBindExpr->mBody); + ExpectUnindent(); } else { @@ -1894,8 +1889,8 @@ void BfPrinter::Visit(BfObjectCreateExpression* newExpr) VisitChild(newExpr->mNewNode); ExpectSpace(); - - VisitChild(newExpr->mTypeRef); + + VisitChild(newExpr->mTypeRef); if (newExpr->mStarToken != NULL) { @@ -1920,9 +1915,9 @@ void BfPrinter::Visit(BfObjectCreateExpression* newExpr) VisitChildNoRef(newExpr->mCommas.GetSafe(i - 1)); ExpectSpace(); } - VisitChild(newExpr->mArguments[i]); + VisitChild(newExpr->mArguments[i]); } - _WriteToken(newExpr->mCloseToken, BfToken_RParen); + _WriteToken(newExpr->mCloseToken, BfToken_RParen); } void BfPrinter::Visit(BfBoxExpression* boxExpr) @@ -1933,7 +1928,7 @@ void BfPrinter::Visit(BfBoxExpression* boxExpr) ExpectSpace(); VisitChild(boxExpr->mBoxToken); ExpectSpace(); - VisitChild(boxExpr->mExpression); + VisitChild(boxExpr->mExpression); } void BfPrinter::Visit(BfThrowStatement* throwStmt) @@ -1956,7 +1951,6 @@ void BfPrinter::Visit(BfDeleteStatement* deleteStmt) VisitChild(deleteStmt->mAllocExpr); ExpectSpace(); VisitChild(deleteStmt->mExpression); - VisitChild(deleteStmt->mTrailingSemicolon); } @@ -1991,8 +1985,8 @@ void BfPrinter::Visit(BfDeferStatement* deferStmt) if (deferStmt->mBind != NULL) { auto bind = deferStmt->mBind; - - VisitChild(bind->mOpenBracket); + + VisitChild(bind->mOpenBracket); for (int i = 0; i < bind->mParams.size(); i++) { if (i > 0) @@ -2007,10 +2001,10 @@ void BfPrinter::Visit(BfDeferStatement* deferStmt) VisitChild(deferStmt->mOpenParen); VisitChild(deferStmt->mScopeToken); - VisitChild(deferStmt->mCloseParen); + VisitChild(deferStmt->mCloseParen); ExpectSpace(); VisitChild(deferStmt->mTargetNode); - + VisitChild(deferStmt->mTrailingSemicolon); } @@ -2040,13 +2034,13 @@ void BfPrinter::Visit(BfCaseExpression* caseExpr) } else { - VisitChild(caseExpr->mValueExpression); + VisitChild(caseExpr->mValueExpression); ExpectSpace(); - VisitChild(caseExpr->mCaseToken); + VisitChild(caseExpr->mCaseToken); BF_ASSERT(caseExpr->mEqualsNode == NULL); ExpectSpace(); VisitChild(caseExpr->mCaseExpression); - } + } } void BfPrinter::Visit(BfSwitchCase* switchCase) @@ -2054,7 +2048,7 @@ void BfPrinter::Visit(BfSwitchCase* switchCase) if (mIndentCaseLabels) ExpectIndent(); - VisitChild(switchCase->mCaseToken); + VisitChild(switchCase->mCaseToken); for (int caseIdx = 0; caseIdx < (int) switchCase->mCaseExpressions.size(); caseIdx++) { if ((caseIdx == 0) || (caseIdx > (int)switchCase->mCaseCommas.size())) @@ -2099,30 +2093,29 @@ void BfPrinter::Visit(BfSwitchStatement* switchStmt) ExpectNewLine(); VisitChild(switchStmt->mOpenBrace); - ExpectNewLine(); - + ExpectNewLine(); + for (auto switchCase : switchStmt->mSwitchCases) Visit(switchCase); if (switchStmt->mDefaultCase != NULL) Visit(switchStmt->mDefaultCase); - + ExpectNewLine(); VisitChild(switchStmt->mCloseBrace); VisitChild(switchStmt->mTrailingSemicolon); } - void BfPrinter::Visit(BfTryStatement* tryStmt) { Visit(tryStmt->ToBase()); - + VisitChild(tryStmt->mTryToken); VisitChild(tryStmt->mStatement); } void BfPrinter::Visit(BfCatchStatement* catchStmt) -{ +{ Visit(catchStmt->ToBase()); WriteSourceString(catchStmt); @@ -2160,12 +2153,12 @@ void BfPrinter::Visit(BfIfStatement* ifStmt) VisitChild(ifStmt->mIfToken); ExpectSpace(); - VisitChild(ifStmt->mOpenParen); + VisitChild(ifStmt->mOpenParen); VisitChild(ifStmt->mCondition); VisitChild(ifStmt->mCloseParen); - ExpectSpace(); - VisitChildNextLine(ifStmt->mTrueStatement); - VisitChild(ifStmt->mElseToken); + ExpectSpace(); + VisitChildNextLine(ifStmt->mTrueStatement); + VisitChild(ifStmt->mElseToken); if (ifStmt->mFalseStatement != NULL) { ExpectSpace(); @@ -2179,9 +2172,9 @@ void BfPrinter::Visit(BfIfStatement* ifStmt) } void BfPrinter::Visit(BfReturnStatement* returnStmt) -{ +{ Visit(returnStmt->ToBase()); - + VisitChild(returnStmt->mReturnToken); if (returnStmt->mExpression != NULL) { @@ -2192,7 +2185,7 @@ void BfPrinter::Visit(BfReturnStatement* returnStmt) } void BfPrinter::Visit(BfUsingStatement* doStmt) -{ +{ Visit(doStmt->ToBase()); VisitChild(doStmt->mUsingToken); @@ -2210,20 +2203,20 @@ void BfPrinter::Visit(BfDoStatement* doStmt) Visit(doStmt->ToBase()); VisitChild(doStmt->mDoToken); - VisitChildNextLine(doStmt->mEmbeddedStatement); + VisitChildNextLine(doStmt->mEmbeddedStatement); } void BfPrinter::Visit(BfRepeatStatement* repeatStmt) { Visit(repeatStmt->ToBase()); - VisitChild(repeatStmt->mRepeatToken); + VisitChild(repeatStmt->mRepeatToken); VisitChildNextLine(repeatStmt->mEmbeddedStatement); VisitChild(repeatStmt->mWhileToken); ExpectSpace(); VisitChild(repeatStmt->mOpenParen); VisitChild(repeatStmt->mCondition); - VisitChild(repeatStmt->mCloseParen); + VisitChild(repeatStmt->mCloseParen); VisitChild(repeatStmt->mTrailingSemicolon); } @@ -2232,7 +2225,7 @@ void BfPrinter::Visit(BfWhileStatement* whileStmt) { Visit(whileStmt->ToBase()); - VisitChild(whileStmt->mWhileToken); + VisitChild(whileStmt->mWhileToken); ExpectSpace(); VisitChild(whileStmt->mOpenParen); VisitChild(whileStmt->mCondition); @@ -2252,7 +2245,7 @@ void BfPrinter::Visit(BfBreakStatement* breakStmt) ExpectSpace(); VisitChild(breakStmt->mLabel); } - VisitChild(breakStmt->mTrailingSemicolon); + VisitChild(breakStmt->mTrailingSemicolon); } void BfPrinter::Visit(BfContinueStatement* continueStmt) @@ -2307,11 +2300,11 @@ void BfPrinter::Visit(BfForStatement* forStmt) void BfPrinter::Visit(BfForEachStatement* forEachStmt) { - Visit(forEachStmt->ToBase()); + Visit(forEachStmt->ToBase()); VisitChild(forEachStmt->mForToken); ExpectSpace(); - VisitChild(forEachStmt->mOpenParen); + VisitChild(forEachStmt->mOpenParen); if (forEachStmt->mReadOnlyToken != NULL) { VisitChild(forEachStmt->mReadOnlyToken); @@ -2323,7 +2316,7 @@ void BfPrinter::Visit(BfForEachStatement* forEachStmt) ExpectSpace(); VisitChild(forEachStmt->mInToken); ExpectSpace(); - VisitChild(forEachStmt->mCollectionExpression); + VisitChild(forEachStmt->mCollectionExpression); VisitChild(forEachStmt->mCloseParen); ExpectNewLine(); VisitChildNextLine(forEachStmt->mEmbeddedStatement); @@ -2361,8 +2354,8 @@ void BfPrinter::Visit(BfParenthesizedExpression* parenExpr) { Visit(parenExpr->ToBase()); - VisitChild(parenExpr->mOpenParen); - VisitChild(parenExpr->mExpression); + VisitChild(parenExpr->mOpenParen); + VisitChild(parenExpr->mExpression); VisitChild(parenExpr->mCloseParen); } @@ -2389,7 +2382,7 @@ void BfPrinter::Visit(BfTupleExpression* tupleExpr) ExpectSpace(); } } - + VisitChild(tupleExpr->mValues[i]); } @@ -2418,7 +2411,7 @@ void BfPrinter::Visit(BfIndexerExpression* indexerExpr) VisitChildNoRef(indexerExpr->mCommas.GetSafe(i - 1)); ExpectSpace(); } - VisitChild(indexerExpr->mArguments[i]); + VisitChild(indexerExpr->mArguments[i]); } VisitChild(indexerExpr->mCloseBracket); @@ -2460,11 +2453,11 @@ void BfPrinter::Visit(BfConstructorDeclaration* ctorDeclaration) ExpectNewLine(); } - QueueVisitChild(ctorDeclaration->mProtectionSpecifier); + QueueVisitChild(ctorDeclaration->mProtectionSpecifier); ExpectSpace(); QueueVisitChild(ctorDeclaration->mNewSpecifier); ExpectSpace(); - QueueVisitChild(ctorDeclaration->mStaticSpecifier); + QueueVisitChild(ctorDeclaration->mStaticSpecifier); ExpectSpace(); if (mDocPrep) @@ -2476,7 +2469,7 @@ void BfPrinter::Visit(BfConstructorDeclaration* ctorDeclaration) else { QueueVisitChild(ctorDeclaration->mThisToken); - } + } QueueVisitChild(ctorDeclaration->mOpenParen); for (int i = 0; i < (int) ctorDeclaration->mParams.size(); i++) @@ -2496,7 +2489,7 @@ void BfPrinter::Visit(BfConstructorDeclaration* ctorDeclaration) QueueVisitChild(ctorDeclaration->mFatArrowToken); QueueVisitChild(ctorDeclaration->mBody); - + FlushVisitChild(); } @@ -2507,7 +2500,7 @@ void BfPrinter::Visit(BfDestructorDeclaration* dtorDeclaration) QueueVisitChild(dtorDeclaration->mAttributes); ExpectNewLine(); ExpectSpace(); - QueueVisitChild(dtorDeclaration->mProtectionSpecifier); + QueueVisitChild(dtorDeclaration->mProtectionSpecifier); ExpectSpace(); QueueVisitChild(dtorDeclaration->mNewSpecifier); ExpectSpace(); @@ -2517,14 +2510,14 @@ void BfPrinter::Visit(BfDestructorDeclaration* dtorDeclaration) if (mDocPrep) { - FlushVisitChild(); + FlushVisitChild(); VisitChild(mCurTypeDecl->mNameNode); } else { QueueVisitChild(dtorDeclaration->mThisToken); } - + QueueVisitChild(dtorDeclaration->mOpenParen); for (int i = 0; i < (int) dtorDeclaration->mParams.size(); i++) { @@ -2535,7 +2528,7 @@ void BfPrinter::Visit(BfDestructorDeclaration* dtorDeclaration) } QueueVisitChild(dtorDeclaration->mParams[i]); } - QueueVisitChild(dtorDeclaration->mCloseParen); + QueueVisitChild(dtorDeclaration->mCloseParen); QueueVisitChild(dtorDeclaration->mFatArrowToken); QueueVisitChild(dtorDeclaration->mBody); @@ -2543,41 +2536,40 @@ void BfPrinter::Visit(BfDestructorDeclaration* dtorDeclaration) FlushVisitChild(); } - void BfPrinter::QueueMethodDeclaration(BfMethodDeclaration* methodDeclaration) -{ +{ if (methodDeclaration->mAttributes != NULL) { QueueVisitChild(methodDeclaration->mAttributes); ExpectNewLine(); } - + if (methodDeclaration->mExternSpecifier != NULL) - { + { ExpectSpace(); - QueueVisitChild(methodDeclaration->mExternSpecifier); + QueueVisitChild(methodDeclaration->mExternSpecifier); } if (methodDeclaration->mProtectionSpecifier != NULL) - { + { ExpectSpace(); - QueueVisitChild(methodDeclaration->mProtectionSpecifier); + QueueVisitChild(methodDeclaration->mProtectionSpecifier); } - + if (methodDeclaration->mNewSpecifier != NULL) - { + { ExpectSpace(); - QueueVisitChild(methodDeclaration->mNewSpecifier); + QueueVisitChild(methodDeclaration->mNewSpecifier); } - + if (methodDeclaration->mVirtualSpecifier != NULL) - { + { ExpectSpace(); - QueueVisitChild(methodDeclaration->mVirtualSpecifier); + QueueVisitChild(methodDeclaration->mVirtualSpecifier); } - + if (methodDeclaration->mStaticSpecifier != NULL) - { + { ExpectSpace(); QueueVisitChild(methodDeclaration->mStaticSpecifier); } @@ -2589,23 +2581,23 @@ void BfPrinter::QueueMethodDeclaration(BfMethodDeclaration* methodDeclaration) } if (methodDeclaration->mMixinSpecifier != NULL) - { + { ExpectSpace(); - QueueVisitChild(methodDeclaration->mMixinSpecifier); + QueueVisitChild(methodDeclaration->mMixinSpecifier); } if (methodDeclaration->mPartialSpecifier != NULL) - { + { ExpectSpace(); - QueueVisitChild(methodDeclaration->mPartialSpecifier); + QueueVisitChild(methodDeclaration->mPartialSpecifier); } - + if ((methodDeclaration->mNameNode != NULL) || (methodDeclaration->mExplicitInterface != NULL)) ExpectSpace(); - QueueVisitChild(methodDeclaration->mExplicitInterface); + QueueVisitChild(methodDeclaration->mExplicitInterface); QueueVisitChild(methodDeclaration->mExplicitInterfaceDotToken); QueueVisitChild(methodDeclaration->mNameNode); - + if (auto operatorDecl = BfNodeDynCast(methodDeclaration)) { if ((operatorDecl->mOpTypeToken != NULL) && (operatorDecl->mOpTypeToken->mToken == BfToken_LChevron)) @@ -2614,7 +2606,7 @@ void BfPrinter::QueueMethodDeclaration(BfMethodDeclaration* methodDeclaration) QueueVisitChild(methodDeclaration->mGenericParams); if (auto operatorDecl = BfNodeDynCast(methodDeclaration)) - { + { ExpectSpace(); QueueVisitChild(operatorDecl->mExplicitToken); ExpectSpace(); @@ -2622,14 +2614,14 @@ void BfPrinter::QueueMethodDeclaration(BfMethodDeclaration* methodDeclaration) ExpectSpace(); QueueVisitChild(operatorDecl->mOpTypeToken); ExpectSpace(); - QueueVisitChild(methodDeclaration->mReturnType); + QueueVisitChild(methodDeclaration->mReturnType); } else if (methodDeclaration->mReturnType != NULL) - { + { ExpectSpace(); - QueueVisitChild(methodDeclaration->mReturnType); + QueueVisitChild(methodDeclaration->mReturnType); } - + QueueVisitChild(methodDeclaration->mOpenParen); if (methodDeclaration->mThisToken != NULL) { @@ -2642,7 +2634,7 @@ void BfPrinter::QueueMethodDeclaration(BfMethodDeclaration* methodDeclaration) { QueueVisitChild(methodDeclaration->mCommas.GetSafe(i - 1)); ExpectSpace(); - } + } QueueVisitChild(methodDeclaration->mParams[i]); } QueueVisitChild(methodDeclaration->mCloseParen); @@ -2655,15 +2647,15 @@ void BfPrinter::QueueMethodDeclaration(BfMethodDeclaration* methodDeclaration) ExpectSpace(); QueueVisitChild(methodDeclaration->mFatArrowToken); ExpectSpace(); - } + } QueueVisitChild(methodDeclaration->mBody); - QueueVisitChild(methodDeclaration->mEndSemicolon); + QueueVisitChild(methodDeclaration->mEndSemicolon); } void BfPrinter::Visit(BfMethodDeclaration* methodDeclaration) { //Visit(methodDeclaration->ToBase()); - + ExpectNewLine(); QueueMethodDeclaration(methodDeclaration); //?? QueueVisitErrorNodes(methodDeclaration); @@ -2678,12 +2670,12 @@ void BfPrinter::Visit(BfOperatorDeclaration* opreratorDeclaration) } void BfPrinter::Visit(BfPropertyMethodDeclaration* propertyMethodDeclaration) -{ +{ ExpectNewLine(); QueueVisitChild(propertyMethodDeclaration->mAttributes); ExpectNewLine(); QueueVisitChild(propertyMethodDeclaration->mProtectionSpecifier); - ExpectSpace(); + ExpectSpace(); QueueVisitChild(propertyMethodDeclaration->mNameNode); ExpectSpace(); QueueVisitChild(propertyMethodDeclaration->mSetRefSpecifier); @@ -2692,8 +2684,8 @@ void BfPrinter::Visit(BfPropertyMethodDeclaration* propertyMethodDeclaration) ExpectSpace(); QueueVisitChild(propertyMethodDeclaration->mFatArrowToken); ExpectSpace(); - if (auto block = BfNodeDynCast(propertyMethodDeclaration->mBody)) - ExpectNewLine(); + if (auto block = BfNodeDynCast(propertyMethodDeclaration->mBody)) + ExpectNewLine(); QueueVisitChild(propertyMethodDeclaration->mBody); QueueVisitChild(propertyMethodDeclaration->mEndSemicolon); } @@ -2711,7 +2703,7 @@ void BfPrinter::Visit(BfPropertyDeclaration* propertyDeclaration) ExpectNewLine(); QueueVisitChild(propertyDeclaration->mAttributes); - ExpectNewLine(); + ExpectNewLine(); ExpectSpace(); QueueVisitChild(propertyDeclaration->mProtectionSpecifier); ExpectSpace(); @@ -2735,7 +2727,7 @@ void BfPrinter::Visit(BfPropertyDeclaration* propertyDeclaration) QueueVisitChild(propertyDeclaration->mExplicitInterfaceDotToken); QueueVisitChild(propertyDeclaration->mNameNode); ExpectSpace(); - + if (indexerDeclaration != NULL) { QueueVisitChild(indexerDeclaration->mThisToken); @@ -2799,10 +2791,10 @@ void BfPrinter::Visit(BfFieldDeclaration* fieldDeclaration) bool isEnumDecl = false; if (auto enumEntry = BfNodeDynCast(fieldDeclaration)) - { + { isEnumDecl = true; } - + if (fieldDeclaration->mPrecedingComma != NULL) { mVirtualNewLineIdx = mNextStateModify.mWantNewLineIdx; @@ -2865,7 +2857,7 @@ void BfPrinter::Visit(BfEnumCaseDeclaration* enumCaseDeclaration) { ExpectNewLine(); - Visit(enumCaseDeclaration->ToBase()); + Visit(enumCaseDeclaration->ToBase()); if (mDocPrep) { @@ -2883,7 +2875,7 @@ void BfPrinter::Visit(BfEnumCaseDeclaration* enumCaseDeclaration) } VisitChild(enumCaseDeclaration->mCaseToken); - ExpectSpace(); + ExpectSpace(); for (int i = 0; i < (int)enumCaseDeclaration->mEntries.size(); i++) { @@ -2908,8 +2900,8 @@ void BfPrinter::Visit(BfTypeAliasDeclaration* typeDeclaration) } void BfPrinter::Visit(BfFieldDtorDeclaration* fieldDtorDeclaration) -{ - ExpectSpace(); +{ + ExpectSpace(); if (fieldDtorDeclaration->mBody != NULL) { if (fieldDtorDeclaration->mBody->IsA()) @@ -2949,16 +2941,16 @@ void BfPrinter::Visit(BfTypeDeclaration* typeDeclaration) break; } } - - ExpectNewLine(); + + ExpectNewLine(); QueueVisitChild(typeDeclaration->mAttributes); if (!isOneLine) - ExpectNewLine(); + ExpectNewLine(); ExpectSpace(); QueueVisitChild(typeDeclaration->mAbstractSpecifier); ExpectSpace(); QueueVisitChild(typeDeclaration->mSealedSpecifier); - ExpectSpace(); + ExpectSpace(); QueueVisitChild(typeDeclaration->mProtectionSpecifier); ExpectSpace(); QueueVisitChild(typeDeclaration->mStaticSpecifier); @@ -2970,16 +2962,15 @@ void BfPrinter::Visit(BfTypeDeclaration* typeDeclaration) if ((mDocPrep) && (typeDeclaration->mTypeNode != NULL) && (typeDeclaration->mTypeNode->mToken == BfToken_Enum)) { if (auto defineBlock = BfNodeDynCast(typeDeclaration->mDefineNode)) - { + { if (auto enumEntryDecl = BfNodeDynCast(defineBlock->GetFirst())) { - } else { isEnumDoc = true; } - } + } } if (isEnumDoc) @@ -3010,14 +3001,14 @@ void BfPrinter::Visit(BfTypeDeclaration* typeDeclaration) QueueVisitChild(typeDeclaration->mBaseClassCommas.GetSafe(i - 1)); } } - ExpectSpace(); + ExpectSpace(); } QueueVisitChild(typeDeclaration->mGenericConstraintsDeclaration); if (queueChildren) { if (auto defineBlock = BfNodeDynCast(typeDeclaration->mDefineNode)) - { + { for (auto member : defineBlock->mChildArr) { SetAndRestoreValue prevBlockMember(mCurBlockMember, member); @@ -3037,7 +3028,7 @@ void BfPrinter::Visit(BfTypeDeclaration* typeDeclaration) } } else - { + { FlushVisitChild(); if (auto defineBlock = BfNodeDynCast(typeDeclaration->mDefineNode)) { @@ -3063,14 +3054,14 @@ void BfPrinter::Visit(BfTypeDeclaration* typeDeclaration) VisitChild(member); } ExpectUnindent(); - VisitChild(defineBlock->mCloseBrace); - } + VisitChild(defineBlock->mCloseBrace); + } else { FlushVisitChild(); VisitChild(typeDeclaration->mDefineNode); } - } + } ExpectNewLine(); } @@ -3078,13 +3069,13 @@ void BfPrinter::Visit(BfTypeDeclaration* typeDeclaration) void BfPrinter::Visit(BfUsingDirective* usingDirective) { //Visit(usingDirective->ToBase()); - - ExpectNewLine(); - VisitChild(usingDirective->mUsingToken); - ExpectSpace(); - VisitChild(usingDirective->mNamespace); - VisitChild(usingDirective->mTrailingSemicolon); + ExpectNewLine(); + VisitChild(usingDirective->mUsingToken); + ExpectSpace(); + VisitChild(usingDirective->mNamespace); + + VisitChild(usingDirective->mTrailingSemicolon); ExpectNewLine(); } @@ -3110,12 +3101,12 @@ void BfPrinter::Visit(BfNamespaceDeclaration* namespaceDeclaration) ExpectNewLine(); VisitChild(namespaceDeclaration->mNamespaceNode); ExpectSpace(); - VisitChild(namespaceDeclaration->mNameNode); + VisitChild(namespaceDeclaration->mNameNode); VisitChild(namespaceDeclaration->mBody); } void BfPrinter::DoBlockOpen(BfAstNode* prevNode, BfTokenNode* blockOpen, BfTokenNode* blockClose, bool queue, BlockState& blockState) -{ +{ blockState.mLastSpaceOffset = mLastSpaceOffset; blockState.mIndentStart = mNextStateModify.mWantVirtualIndent; @@ -3160,7 +3151,7 @@ void BfPrinter::DoBlockClose(BfAstNode* prevNode, BfTokenNode* blockOpen, BfToke { if (!blockState.mDoInlineBlock) { - ExpectUnindent(); + ExpectUnindent(); mNextStateModify.mDoingBlockClose = true; } else @@ -3169,7 +3160,7 @@ void BfPrinter::DoBlockClose(BfAstNode* prevNode, BfTokenNode* blockOpen, BfToke QueueVisitChild(blockClose); else VisitChild(blockClose); - + if (!blockState.mDoInlineBlock) { mNextStateModify.mWantVirtualIndent = blockState.mIndentStart; @@ -3178,7 +3169,7 @@ void BfPrinter::DoBlockClose(BfAstNode* prevNode, BfTokenNode* blockOpen, BfToke } void BfPrinter::Visit(BfBlock* block) -{ +{ BlockState blockState; SetAndRestoreValue prevBlockState(mCurBlockState, &blockState); @@ -3186,7 +3177,7 @@ void BfPrinter::Visit(BfBlock* block) for (auto& childNodeRef : *block) { BfAstNode* child = childNodeRef; - SetAndRestoreValue prevForceTrivia(mForceUseTrivia); + SetAndRestoreValue prevForceTrivia(mForceUseTrivia); SetAndRestoreValue prevVirtualIndent(mNextStateModify.mWantVirtualIndent); SetAndRestoreValue prevBlockMember(mCurBlockMember, child); CheckRawNode(child); @@ -3198,7 +3189,7 @@ void BfPrinter::Visit(BfBlock* block) } void BfPrinter::Visit(BfRootNode* rootNode) -{ +{ for (auto child : rootNode->mChildArr) { SetAndRestoreValue prevBlockMember(mCurBlockMember, child); @@ -3208,7 +3199,7 @@ void BfPrinter::Visit(BfRootNode* rootNode) // Flush whitespace at the end of the document BfParserData* bfParser = rootNode->GetSourceData()->ToParserData(); if (bfParser != NULL) - { + { BfAstNode* endNode = mSource->mAlloc.Alloc(); endNode->Init(rootNode->GetSrcEnd(), bfParser->mSrcLength, bfParser->mSrcLength); Visit(endNode); @@ -3222,5 +3213,4 @@ void BfPrinter::Visit(BfRootNode* rootNode) void BfPrinter::Visit(BfInlineAsmStatement* asmStmt) { - -} +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfPrinter.h b/IDEHelper/Compiler/BfPrinter.h index d461514b..766ceb60 100644 --- a/IDEHelper/Compiler/BfPrinter.h +++ b/IDEHelper/Compiler/BfPrinter.h @@ -5,7 +5,6 @@ NS_BF_BEGIN - class BfPrinter : public BfElementVisitor { public: @@ -26,10 +25,10 @@ public: struct StateModify { public: - bool mExpectingSpace; + bool mExpectingSpace; int mWantNewLineIdx; bool mDoingBlockOpen; - bool mDoingBlockClose; + bool mDoingBlockClose; int mWantVirtualIndent; BfAstNode* mQueuedNode; @@ -43,18 +42,18 @@ public: void Clear() { - mExpectingSpace = false; + mExpectingSpace = false; mDoingBlockOpen = false; mDoingBlockClose = false; mQueuedNode = NULL; } }; - + BfSourceData* mSource; BfParserData* mParser; BfBlock::Iterator mSidechannelItr; - BfAstNode* mSidechannelNextNode; + BfAstNode* mSidechannelNextNode; BfBlock::Iterator mErrorItr; BfAstNode* mErrorNextNode; @@ -65,18 +64,18 @@ public: int mCurSrcIdx; Array mChildNodeQueue; int mFormatStart; - int mFormatEnd; + int mFormatEnd; int mFormatDisableCount; StateModify mNextStateModify; - + String mOutString; - bool mReformatting; + bool mReformatting; bool mIgnoreTrivia; bool mDocPrep; BlockState* mCurBlockState; int mCurIndentLevel; int mQueuedSpaceCount; - int mLastSpaceOffset; // Indent difference from original to new + int mLastSpaceOffset; // Indent difference from original to new bool mExpectingNewLine; int mCurCol; int mMaxCol; @@ -86,19 +85,19 @@ public: bool mIsFirstStatementInBlock; bool mForceUseTrivia; - bool mInSideChannel; + bool mInSideChannel; int mStateModifyVirtualIndentLevel; int mVirtualIndentLevel; int mVirtualNewLineIdx; - + Array* mCharMapping; int mHighestCharId; -public: +public: BfPrinter(BfRootNode* rootNode, BfRootNode* sidechannelRootNode, BfRootNode* errorRootNode); - -public: + +public: void Update(BfAstNode* bfAstNode); bool CheckReplace(BfAstNode* astNode); void FlushIndent(); @@ -106,7 +105,7 @@ public: void Write(BfAstNode* node, int start, int len); void WriteSourceString(BfAstNode* node); void QueueVisitChild(BfAstNode* astNode); - void QueueVisitErrorNodes(BfRootNode* astNode); + void QueueVisitErrorNodes(BfRootNode* astNode); void FlushVisitChild(); void VisitChildWithPrecedingSpace(BfAstNode* bfAstNode); void VisitChildWithProceedingSpace(BfAstNode* bfAstNode); @@ -117,9 +116,9 @@ public: void VisitChildNextLine(BfAstNode* node); void DoBlockOpen(BfAstNode* prevNode, BfTokenNode* blockOpen, BfTokenNode* blockClose, bool queue, BlockState& blockState); void DoBlockClose(BfAstNode* prevNode, BfTokenNode* blockOpen, BfTokenNode* blockClose, bool queue, BlockState& blockState); - void QueueMethodDeclaration(BfMethodDeclaration* methodDeclaration); + void QueueMethodDeclaration(BfMethodDeclaration* methodDeclaration); int CalcOrigLineSpacing(BfAstNode* bfAstNode, int* lineStartIdx); - void WriteIgnoredNode(BfAstNode* node); + void WriteIgnoredNode(BfAstNode* node); void CheckRawNode(BfAstNode* node); virtual void Visit(BfAstNode* bfAstNode) override; @@ -130,20 +129,20 @@ public: virtual void Visit(BfExpressionStatement* exprStmt) override; virtual void Visit(BfNamedExpression* namedExpr) override; virtual void Visit(BfAttributedExpression* attribExpr) override; - virtual void Visit(BfStatement* stmt) override; + virtual void Visit(BfStatement* stmt) override; virtual void Visit(BfLabelableStatement* labelableStmt) override; virtual void Visit(BfCommentNode* commentNode) override; virtual void Visit(BfPreprocesorIgnoredSectionNode* preprocesorIgnoredSection) override; virtual void Visit(BfPreprocessorNode* preprocessorNode) override; - virtual void Visit(BfAttributeDirective* attributeDirective) override; + virtual void Visit(BfAttributeDirective* attributeDirective) override; virtual void Visit(BfGenericParamsDeclaration* genericParams) override; virtual void Visit(BfGenericOperatorConstraint* genericConstraints) override; virtual void Visit(BfGenericConstraintsDeclaration* genericConstraints) override; virtual void Visit(BfGenericArgumentsNode* genericArgumentsNode) override; - virtual void Visit(BfEmptyStatement* emptyStmt) override; + virtual void Visit(BfEmptyStatement* emptyStmt) override; virtual void Visit(BfTokenNode* tokenNode) override; virtual void Visit(BfTokenPairNode* tokenPairNode) override; virtual void Visit(BfUsingSpecifierNode* usingSpecifier) override; @@ -156,7 +155,7 @@ public: virtual void Visit(BfMixinExpression* mixinExpr) override; virtual void Visit(BfSizedArrayCreateExpression* createExpr) override; virtual void Visit(BfInitializerExpression* initExpr) override; - virtual void Visit(BfCollectionInitializerExpression* initExpr) override; + virtual void Visit(BfCollectionInitializerExpression* initExpr) override; virtual void Visit(BfTypeReference* typeRef) override; virtual void Visit(BfNamedTypeReference* typeRef) override; virtual void Visit(BfQualifiedTypeReference* qualifiedType) override; @@ -172,7 +171,7 @@ public: virtual void Visit(BfPointerTypeRef* typeRef) override; virtual void Visit(BfNullableTypeRef* typeRef) override; virtual void Visit(BfVariableDeclaration* varDecl) override; - virtual void Visit(BfParameterDeclaration* paramDecl) override; + virtual void Visit(BfParameterDeclaration* paramDecl) override; virtual void Visit(BfTypeOfExpression* typeOfExpr) override; virtual void Visit(BfSizeOfExpression* sizeOfExpr) override; virtual void Visit(BfOffsetOfExpression* offsetOfExpr) override; @@ -181,11 +180,11 @@ public: virtual void Visit(BfCheckTypeExpression* checkTypeExpr) override; virtual void Visit(BfDynamicCastExpression* dynCastExpr) override; virtual void Visit(BfCastExpression* castExpr) override; - virtual void Visit(BfDelegateBindExpression* invocationExpr) override; + virtual void Visit(BfDelegateBindExpression* invocationExpr) override; virtual void Visit(BfLambdaBindExpression* lambdaBindExpr) override; virtual void Visit(BfObjectCreateExpression* invocationExpr) override; virtual void Visit(BfBoxExpression* boxExpr) override; - virtual void Visit(BfInvocationExpression* invocationExpr) override; + virtual void Visit(BfInvocationExpression* invocationExpr) override; virtual void Visit(BfSwitchCase* switchCase) override; virtual void Visit(BfWhenExpression* whenExpr) override; virtual void Visit(BfSwitchStatement* switchStmt) override; diff --git a/IDEHelper/Compiler/BfReducer.cpp b/IDEHelper/Compiler/BfReducer.cpp index 23a0ce3b..dc24a012 100644 --- a/IDEHelper/Compiler/BfReducer.cpp +++ b/IDEHelper/Compiler/BfReducer.cpp @@ -149,7 +149,7 @@ void BfReducer::ReplaceNode(BfAstNode* prevNode, BfAstNode* newNode) if (!newNode->IsInitialized()) { -#ifdef BF_AST_COMPACT +#ifdef BF_AST_COMPACT if (prevNode->mIsCompact) { newNode->mIsCompact = prevNode->mIsCompact; @@ -224,9 +224,8 @@ void BfReducer::AddErrorNode(BfAstNode* astNode, bool removeNode) astNode->RemoveSelf(); } - bool BfReducer::IsTypeReference(BfAstNode* checkNode, BfToken successToken, int endNode, int* retryNode, int* outEndNode, bool* couldBeExpr, bool* isGenericType, bool* isTuple) -{ +{ AssertCurrentNode(checkNode); if (couldBeExpr != NULL) @@ -418,7 +417,7 @@ bool BfReducer::IsTypeReference(BfAstNode* checkNode, BfToken successToken, int bool hadTupleComma = false; bool hadIdentifier = false; bool foundSuccessToken = false; - bool hadUnexpectedIdentifier = false; + bool hadUnexpectedIdentifier = false; BfTokenNode* lastToken = NULL; SizedArray tokenStack; @@ -459,7 +458,7 @@ bool BfReducer::IsTypeReference(BfAstNode* checkNode, BfToken successToken, int if ((doEnding) && (tokenStack.size() == 1)) doEnding = checkToken == tokenStack.back(); if (doEnding) - { + { bool success = false; if ((lastToken != NULL) && ((lastToken->GetToken() == BfToken_RChevron) || (lastToken->GetToken() == BfToken_RDblChevron))) @@ -469,7 +468,7 @@ bool BfReducer::IsTypeReference(BfAstNode* checkNode, BfToken successToken, int } if (successToken == BfToken_RParen) - { + { success = (chevronDepth == 0) && (bracketDepth == 0) && (parenDepth == 1); if (success) @@ -477,7 +476,7 @@ bool BfReducer::IsTypeReference(BfAstNode* checkNode, BfToken successToken, int // Check identifierExpected - this catches (.) casts if ((identifierExpected) && (couldBeExpr != NULL)) *couldBeExpr = false; - } + } } else if ((successToken == BfToken_Comma) || (successToken == BfToken_LBracket)) @@ -575,7 +574,6 @@ bool BfReducer::IsTypeReference(BfAstNode* checkNode, BfToken successToken, int return false; } } - } else if ((checkToken == BfToken_Const) && (chevronDepth > 0)) { @@ -631,9 +629,9 @@ bool BfReducer::IsTypeReference(BfAstNode* checkNode, BfToken successToken, int if (tokenStack.IsEmpty()) break; - + for (int i = 0; i < ((checkToken == BfToken_RDblChevron) ? 2 : 1); i++) - { + { if (tokenStack.back() != BfToken_RChevron) { if (outEndNode != NULL) @@ -900,7 +898,7 @@ bool BfReducer::IsTypeReference(BfAstNode* checkNode, BfToken successToken, int else if ((checkToken == BfToken_DotDotDot) && (chevronDepth > 0)) { isDone = true; - + auto nextNode = mVisitorPos.Get(checkIdx + 1); if (auto nextToken = BfNodeDynCast(nextNode)) { @@ -910,7 +908,6 @@ bool BfReducer::IsTypeReference(BfAstNode* checkNode, BfToken successToken, int } else if (checkToken != BfToken_LBracket) isDone = true; - if (isDone) { @@ -961,7 +958,7 @@ bool BfReducer::IsTypeReference(BfAstNode* checkNode, BfToken successToken, int { // Allow identifierExpected = false; - } + } else { bool mayBeExprPart = false; @@ -1000,7 +997,7 @@ bool BfReducer::IsTypeReference(BfAstNode* checkNode, BfToken successToken, int int retryNode = -1; if (IsTypeReference(checkNode, successToken, endNode, &retryNode, outEndNode, couldBeExpr, isGenericType, isTuple)) return true; - + if ((retryNode != -1) && (successToken == BfToken_None)) { int newEndNode = -1; @@ -1063,7 +1060,6 @@ bool BfReducer::IsLocalMethod(BfAstNode* nameNode) } else { - } checkIdx++; @@ -1585,7 +1581,7 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat //if (!couldBeExpr) { auto endingTokenNode = BfNodeDynCast(mVisitorPos.Get(outEndNode - 1)); - // If the type ends with a * or a ? then it could be an expression + // If the type ends with a * or a ? then it could be an expression if (endingTokenNode == NULL) { isLocalVariable = true; @@ -1823,7 +1819,6 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat bool isLambdaBind = false; bool isBoxing = false; - auto nextNode = mVisitorPos.GetNext(); if (auto nextTokenNode = BfNodeDynCast(nextNode)) { @@ -1845,7 +1840,7 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat mVisitorPos.mReadPos--; } } - + if (auto interpExpr = BfNodeDynCastExact(nextNode)) { mVisitorPos.MoveNext(); @@ -1854,8 +1849,8 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat interpExpr->mAllocNode = allocNode; interpExpr->mTriviaStart = allocNode->mTriviaStart; - interpExpr->mSrcStart = allocNode->mSrcStart; - + interpExpr->mSrcStart = allocNode->mSrcStart; + exprLeft = interpExpr; } else if (isBoxing) @@ -2000,7 +1995,7 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat auto expr = CreateExpressionAfter(isConstExpr); MEMBER_SET_CHECKED(isConstExpr, mExpression, expr); tokenNode = ExpectTokenAfter(isConstExpr, BfToken_RParen); - MEMBER_SET_CHECKED(isConstExpr, mCloseParen, tokenNode); + MEMBER_SET_CHECKED(isConstExpr, mCloseParen, tokenNode); exprLeft = isConstExpr; } else if (token == BfToken_Question) @@ -2171,9 +2166,9 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat couldBeExpr = false; isTuple = false; if ((createExprFlags & CreateExprFlags_NoCast) == 0) - isCastExpr = IsTypeReference(node, BfToken_RParen, -1, &endNodeIdx, &couldBeExpr, NULL, &isTuple); + isCastExpr = IsTypeReference(node, BfToken_RParen, -1, &endNodeIdx, &couldBeExpr, NULL, &isTuple); if (endNodeIdx != -1) - endNode = mVisitorPos.Get(endNodeIdx); + endNode = mVisitorPos.Get(endNodeIdx); if (isCastExpr) { bool isValidTupleCast = false; @@ -2242,9 +2237,8 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat } } - if (isCastExpr) - { + { BfCastExpression* bfCastExpr = NULL; if (isTuple) { @@ -2284,7 +2278,7 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat unaryOpExpr = bfCastExpr; } } - + if (!isCastExpr) { if (auto nextToken = BfNodeDynCast(mVisitorPos.GetNext())) @@ -2354,7 +2348,7 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat } else if (tokenNode->GetToken() == BfToken_NameOf) { - BfNameOfExpression* nameOfExpr = mAlloc->Alloc(); + BfNameOfExpression* nameOfExpr = mAlloc->Alloc(); ReplaceNode(tokenNode, nameOfExpr); nameOfExpr->mToken = tokenNode; tokenNode = ExpectTokenAfter(nameOfExpr, BfToken_LParen); @@ -2364,7 +2358,7 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat int outEndNode = -1; bool isTypeRef = IsTypeReference(mVisitorPos.GetCurrent(), BfToken_RParen, -1, &outEndNode); mVisitorPos.mReadPos--; - + if ((isTypeRef) && (outEndNode > 0)) { if (auto tokenNode = BfNodeDynCast(mVisitorPos.Get(outEndNode - 1))) @@ -2375,17 +2369,17 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat auto typeRef = CreateTypeRefAfter(nameOfExpr); MEMBER_SET_CHECKED(nameOfExpr, mTarget, typeRef); } - } + } } - + if (nameOfExpr->mTarget == NULL) { auto expr = CreateExpressionAfter(nameOfExpr); MEMBER_SET_CHECKED(nameOfExpr, mTarget, expr); - } + } tokenNode = ExpectTokenAfter(nameOfExpr, BfToken_RParen); MEMBER_SET_CHECKED(nameOfExpr, mCloseParen, tokenNode); - exprLeft = nameOfExpr; + exprLeft = nameOfExpr; } if (exprLeft == NULL) @@ -2393,7 +2387,7 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat BfUnaryOp unaryOp = BfTokenToUnaryOp(tokenNode->GetToken()); if (unaryOp != BfUnaryOp_None) - { + { unaryOpExpr = mAlloc->Alloc(); unaryOpExpr->mOp = unaryOp; unaryOpExpr->mOpToken = tokenNode; @@ -2404,7 +2398,7 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat innerFlags = (CreateExprFlags)(innerFlags | (createExprFlags & CreateExprFlags_AllowVariableDecl)); if (unaryOp == BfUnaryOp_PartialRangeThrough) // This allows for just a naked '...' - innerFlags = (CreateExprFlags)(innerFlags | CreateExprFlags_AllowEmpty); + innerFlags = (CreateExprFlags)(innerFlags | CreateExprFlags_AllowEmpty); // Don't attempt binary or unary operations- they will always be lower precedence unaryOpExpr->mExpression = CreateExpressionAfter(unaryOpExpr, innerFlags); @@ -2432,7 +2426,7 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat if (auto assignmentExpr = BfNodeDynCast(unaryOpExpr->mExpression)) { - // Apply unary operator (likely a dereference) to LHS + // Apply unary operator (likely a dereference) to LHS assignmentExpr->RemoveSelf(); ReplaceNode(unaryOpExpr, assignmentExpr); if (assignmentExpr->mLeft != NULL) @@ -2495,23 +2489,23 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat { BfToken token = tokenNode->GetToken(); - if (((createExprFlags & CreateExprFlags_BreakOnRChevron) != 0) && + if (((createExprFlags & CreateExprFlags_BreakOnRChevron) != 0) && ((token == BfToken_RChevron) || (token == BfToken_RDblChevron))) return exprLeft; - + BfUnaryOp postUnaryOp = BfUnaryOp_None; if (token == BfToken_DblPlus) postUnaryOp = BfUnaryOp_PostIncrement; if (token == BfToken_DblMinus) - postUnaryOp = BfUnaryOp_PostDecrement; + postUnaryOp = BfUnaryOp_PostDecrement; if (token == BfToken_DotDotDot) - { + { //TODO: Detect if this is a BfUnaryOp_PartialRangeFrom } if (postUnaryOp != BfUnaryOp_None) - { + { auto unaryOpExpr = mAlloc->Alloc(); ReplaceNode(exprLeft, unaryOpExpr); unaryOpExpr->mOp = postUnaryOp; @@ -2523,7 +2517,7 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat } if (token == BfToken_As) - { + { auto dynCastExpr = mAlloc->Alloc(); ReplaceNode(exprLeft, dynCastExpr); dynCastExpr->mTarget = exprLeft; @@ -2537,7 +2531,7 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat } if (token == BfToken_Is) - { + { auto checkTypeExpr = mAlloc->Alloc(); ReplaceNode(exprLeft, checkTypeExpr); checkTypeExpr->mTarget = exprLeft; @@ -2788,7 +2782,7 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat continue; } - // Could be a struct generic initializer, or a generic method invocation + // Could be a struct generic initializer, or a generic method invocation if (auto outToken = BfNodeDynCast(outNode)) { int endNodeIdx = -1; @@ -2857,7 +2851,7 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat binOpExpression->mLeft = exprLeft; binOpExpression->mOp = binOp; MEMBER_SET(binOpExpression, mOpToken, tokenNode); - + if (exprRight == NULL) return binOpExpression; MEMBER_SET(binOpExpression, mRight, exprRight); @@ -3239,7 +3233,7 @@ BfStatement* BfReducer::CreateForStatement(BfAstNode* node) { // Try to convert 'int i = 0, j = 0` into two variable declarations instead of a var decl and an assignment if (auto prevExprStmt = BfNodeDynCast(initializers.back())) - { + { if (auto prevVarDecl = BfNodeDynCast(prevExprStmt->mExpression)) { if (auto exprStmt = BfNodeDynCast(stmt)) @@ -3574,7 +3568,7 @@ BfSwitchStatement* BfReducer::CreateSwitchStatement(BfTokenNode* tokenNode) token = tokenNode->GetToken(); if ((tokenNode == NULL) || ((token != BfToken_Case) && (token != BfToken_When) && (token != BfToken_Default))) - { + { Fail("Expected 'case'", child); AddErrorNode(child); isDone = !mVisitorPos.MoveNext(); @@ -3623,7 +3617,7 @@ BfSwitchStatement* BfReducer::CreateSwitchStatement(BfTokenNode* tokenNode) whenExpr->mWhenToken = whenToken; ReplaceNode(whenToken, whenExpr); //mVisitorPos.MoveNext(); - //auto exprAfter = wasWhenSet ? (BfAstNode*)switchCase : (BfAstNode*)whenExpr; + //auto exprAfter = wasWhenSet ? (BfAstNode*)switchCase : (BfAstNode*)whenExpr; if (expr == NULL) { auto innerExpr = CreateExpressionAfter(whenToken); @@ -3727,7 +3721,7 @@ BfSwitchStatement* BfReducer::CreateSwitchStatement(BfTokenNode* tokenNode) { int token = tokenNode->GetToken(); if ((token == BfToken_Case) || (token == BfToken_Default) || (token == BfToken_When)) - break; // Done! No fallthrough + break; // Done! No fallthrough } nextNode = mVisitorPos.GetNext(); @@ -3736,7 +3730,7 @@ BfSwitchStatement* BfReducer::CreateSwitchStatement(BfTokenNode* tokenNode) hadEmptyCaseStatement = false; mVisitorPos.MoveNext(); - // We need to use CreateStmtFlags_NoCaseExpr because otherwise during typing a new statement at the end of one case, it + // We need to use CreateStmtFlags_NoCaseExpr because otherwise during typing a new statement at the end of one case, it // could interpret the 'case' token for the next case as being part of a case expression in the first case auto stmt = CreateStatement(nextNode, (CreateStmtFlags)(CreateStmtFlags_FindTrailingSemicolon | CreateStmtFlags_NoCaseExpr | CreateStmtFlags_AllowLocalFunction)); if (stmt == NULL) @@ -4113,7 +4107,7 @@ BfAstNode* BfReducer::DoCreateStatement(BfAstNode* node, CreateStmtFlags createS { auto flags = (CreateStmtFlags)(CreateStmtFlags_FindTrailingSemicolon | CreateStmtFlags_ForceVariableDecl); if (token == BfToken_Static) - flags = (CreateStmtFlags)(flags | CreateStmtFlags_AllowLocalFunction); + flags = (CreateStmtFlags)(flags | CreateStmtFlags_AllowLocalFunction); auto stmt = CreateStatementAfter(tokenNode, flags); if (auto exprStmt = BfNodeDynCast(stmt)) { @@ -4512,7 +4506,7 @@ bool BfReducer::IsTerminatingExpression(BfAstNode* node) chevronDepth++; break; case BfToken_RChevron: - // If we find a < and > that are not separated by parens, that's a generic, which must be a + // If we find a < and > that are not separated by parens, that's a generic, which must be a // variable decl if it's not in parens if ((parenDepth == 0) && (chevronDepth > 0)) return false; @@ -5003,7 +4997,7 @@ BfTypeReference* BfReducer::DoCreateTypeRef(BfAstNode* firstNode, CreateTypeRefF } MEMBER_SET_CHECKED(delegateTypeRef, mCloseParen, closeNode); mVisitorPos.MoveNext(); - + isHandled = true; firstNode = delegateTypeRef; @@ -5026,7 +5020,7 @@ BfTypeReference* BfReducer::DoCreateTypeRef(BfAstNode* firstNode, CreateTypeRefF firstNode = declTypeRef; if ((createTypeRefFlags & CreateTypeRefFlags_EarlyExit) != 0) - return declTypeRef; + return declTypeRef; } else if (token == BfToken_LParen) { @@ -5095,7 +5089,7 @@ BfTypeReference* BfReducer::DoCreateTypeRef(BfAstNode* firstNode, CreateTypeRefF { Fail("Expected type", firstNode); return NULL; - } + } } } @@ -5518,7 +5512,7 @@ BfIdentifierNode* BfReducer::CompactQualifiedName(BfAstNode* leftNode) auto rightIdentifier = BfNodeDynCast(nextNextToken); if (rightIdentifier == NULL) { - if (auto rightToken = BfNodeDynCast(nextNextToken)) + if (auto rightToken = BfNodeDynCast(nextNextToken)) { if (BfTokenIsKeyword(rightToken->mToken)) { @@ -5526,16 +5520,16 @@ BfIdentifierNode* BfReducer::CompactQualifiedName(BfAstNode* leftNode) ReplaceNode(rightToken, rightIdentifier); } } - + if (rightIdentifier == NULL) return leftIdentifier; } // If the previous dotted span failed (IE: had chevrons) then don't insert qualified names in the middle of it auto prevNodeToken = BfNodeDynCast(prevNode); - if ((prevNodeToken != NULL) && - ((prevNodeToken->GetToken() == BfToken_Dot) || - (prevNodeToken->GetToken() == BfToken_QuestionDot) || + if ((prevNodeToken != NULL) && + ((prevNodeToken->GetToken() == BfToken_Dot) || + (prevNodeToken->GetToken() == BfToken_QuestionDot) || (prevNodeToken->GetToken() == BfToken_Arrow))) return leftIdentifier; @@ -5566,7 +5560,7 @@ void BfReducer::TryIdentifierConvert(int readPos) ReplaceNode(tokenNode, identifierNode); mVisitorPos.Set(readPos, identifierNode); } - } + } } void BfReducer::CreateQualifiedNames(BfAstNode* node) @@ -5691,7 +5685,7 @@ Do_RBracket: mVisitorPos.MoveNext(); } - // Has another one- chain it + // Has another one- chain it auto nextAttribute = CreateAttributeDirective(tokenNode); if (nextAttribute != NULL) { @@ -5706,14 +5700,14 @@ BfStatement* BfReducer::CreateAttributedStatement(BfTokenNode* tokenNode, Create auto attrib = CreateAttributeDirective(tokenNode); if (attrib == NULL) return NULL; - + BfAstNode* stmt = CreateStatementAfter(attrib, createStmtFlags); if (stmt != NULL) - { + { if (auto localMethodDecl = BfNodeDynCastExact(stmt)) { BF_ASSERT(localMethodDecl->mMethodDeclaration->mAttributes == NULL); - localMethodDecl->mSrcStart = attrib->mSrcStart; + localMethodDecl->mSrcStart = attrib->mSrcStart; MEMBER_SET(localMethodDecl->mMethodDeclaration, mAttributes, attrib); return localMethodDecl; } @@ -5755,7 +5749,7 @@ BfExpression* BfReducer::CreateAttributedExpression(BfTokenNode* tokenNode, bool return NULL; if (!onlyAllowIdentifier) - { + { BfExpression* expr = CreateExpressionAfter(attrib, CreateExprFlags_EarlyExit); if (expr != NULL) { @@ -5780,7 +5774,7 @@ BfExpression* BfReducer::CreateAttributedExpression(BfTokenNode* tokenNode, bool MEMBER_SET(attribExpr, mExpression, expr); return attribExpr; } - } + } Fail("Prefixed attributes can only be used on allocations, invocations, blocks, or variable declarations", attrib); @@ -6156,7 +6150,7 @@ BfAstNode* BfReducer::ReadTypeMember(BfTokenNode* tokenNode, bool declStarted, i ReplaceNode(tokenNode, ctorDecl); MEMBER_SET(ctorDecl, mThisToken, tokenNode); if (auto block = BfNodeDynCast(mVisitorPos.GetNext())) - { + { mVisitorPos.MoveNext(); MEMBER_SET(ctorDecl, mBody, block); @@ -6443,7 +6437,7 @@ BfAstNode* BfReducer::ReadTypeMember(BfTokenNode* tokenNode, bool declStarted, i } } - SetProtection(memberDecl, memberDecl->mProtectionSpecifier, tokenNode); + SetProtection(memberDecl, memberDecl->mProtectionSpecifier, tokenNode); return memberDecl; } @@ -6549,7 +6543,7 @@ BfAstNode* BfReducer::ReadTypeMember(BfTokenNode* tokenNode, bool declStarted, i { if (token == BfToken_Override) { - // Must be typing an 'override' over a field declaration + // Must be typing an 'override' over a field declaration auto propDecl = mAlloc->Alloc(); propDecl->mVirtualSpecifier = tokenNode; typeMember = memberDecl = propDecl; @@ -6584,7 +6578,7 @@ BfAstNode* BfReducer::ReadTypeMember(BfTokenNode* tokenNode, bool declStarted, i auto usingSpecifier = mAlloc->Alloc(); ReplaceNode(tokenNode, usingSpecifier); - MEMBER_SET(usingSpecifier, mUsingToken, tokenNode); + MEMBER_SET(usingSpecifier, mUsingToken, tokenNode); MEMBER_SET(fieldDecl, mConstSpecifier, usingSpecifier); handled = true; } @@ -6759,10 +6753,10 @@ void BfReducer::ReadPropertyBlock(BfPropertyDeclaration* propertyDeclaration, Bf BfAstNode* bodyAfterNode = accessorIdentifier; BfAstNode* body = NULL; - + auto tokenNode = BfNodeDynCast(child); if ((tokenNode != NULL) && (tokenNode->GetToken() == BfToken_Ref) && (accessorName == "set")) - { + { refSpecifier = tokenNode; bodyAfterNode = tokenNode; @@ -6782,8 +6776,8 @@ void BfReducer::ReadPropertyBlock(BfPropertyDeclaration* propertyDeclaration, Bf mVisitorPos.MoveNext(); child = mVisitorPos.GetNext(); - } - + } + bool handled = false; BfTokenNode* fatArrowToken = NULL; BfAstNode* endSemicolon = NULL; @@ -6796,7 +6790,7 @@ void BfReducer::ReadPropertyBlock(BfPropertyDeclaration* propertyDeclaration, Bf mVisitorPos.MoveNext(); } else if (tokenNode->mToken == BfToken_FatArrow) - { + { handled = true; fatArrowToken = tokenNode; mVisitorPos.MoveNext(); @@ -6806,9 +6800,9 @@ void BfReducer::ReadPropertyBlock(BfPropertyDeclaration* propertyDeclaration, Bf { body = expr; endSemicolon = ExpectTokenAfter(expr, BfToken_Semicolon); - } + } } - } + } if (!handled) { @@ -6822,7 +6816,7 @@ void BfReducer::ReadPropertyBlock(BfPropertyDeclaration* propertyDeclaration, Bf { body = accessorBlock; mVisitorPos.MoveNext(); - } + } if (body == NULL) { if (child != NULL) @@ -6831,7 +6825,7 @@ void BfReducer::ReadPropertyBlock(BfPropertyDeclaration* propertyDeclaration, Bf AddErrorNode(child); mVisitorPos.MoveNext(); } - } + } } } @@ -6859,7 +6853,7 @@ void BfReducer::ReadPropertyBlock(BfPropertyDeclaration* propertyDeclaration, Bf auto method = mAlloc->Alloc(); method->mPropertyDeclaration = propertyDeclaration; - + if (fatArrowToken != NULL) MEMBER_SET(method, mFatArrowToken, fatArrowToken); if (endSemicolon != NULL) @@ -6897,12 +6891,12 @@ BfAstNode* BfReducer::ReadTypeMember(BfAstNode* node, bool declStarted, int dept BfTokenNode* refToken = NULL; if (auto tokenNode = BfNodeDynCast(node)) - { + { BfToken token = tokenNode->GetToken(); bool isTypeRef = false; if ((token == BfToken_Delegate) || (token == BfToken_Function)) { - // We need to differentiate between a delegate type reference and a delegate type declaration + // We need to differentiate between a delegate type reference and a delegate type declaration int endNodeIdx = -1; if (IsTypeReference(node, BfToken_LParen, -1, &endNodeIdx)) { @@ -6939,7 +6933,7 @@ BfAstNode* BfReducer::ReadTypeMember(BfAstNode* node, bool declStarted, int dept } else { - SetAndRestoreValue prevTypeMemberNodeStart(mTypeMemberNodeStart, tokenNode, !declStarted); + SetAndRestoreValue prevTypeMemberNodeStart(mTypeMemberNodeStart, tokenNode, !declStarted); return ReadTypeMember(tokenNode, declStarted, depth, deferredHeadNode); } } @@ -6992,7 +6986,6 @@ BfAstNode* BfReducer::ReadTypeMember(BfAstNode* node, bool declStarted, int dept node = typeRef; - auto nextNode = mVisitorPos.GetNext(); if (auto tokenNode = BfNodeDynCast(nextNode)) { @@ -7146,7 +7139,7 @@ BfAstNode* BfReducer::ReadTypeMember(BfAstNode* node, bool declStarted, int dept } ParseMethod(operatorDecl, ¶ms, &commas); - + if (params.size() == 1) { if (operatorDecl->mBinOp == BfBinaryOp_Add) @@ -7158,7 +7151,7 @@ BfAstNode* BfReducer::ReadTypeMember(BfAstNode* node, bool declStarted, int dept { operatorDecl->mBinOp = BfBinaryOp_None; operatorDecl->mUnaryOp = BfUnaryOp_Negate; - } + } } return operatorDecl; @@ -7235,7 +7228,7 @@ BfAstNode* BfReducer::ReadTypeMember(BfAstNode* node, bool declStarted, int dept // If we don't have a token afterwards then still treat it as a property for autocomplete purposes if ((typeRef != NULL) && ((block != NULL) || (tokenNode == NULL) || (isExprBodyProp))) - { + { if (propertyDeclaration == NULL) { if ((block == NULL) && (!isExprBodyProp)) @@ -7255,7 +7248,7 @@ BfAstNode* BfReducer::ReadTypeMember(BfAstNode* node, bool declStarted, int dept //mVisitorPos.mReadPos--; // WHY did we want to not set this? - // If we don't, then typing a new method name will end up treating the name node as a typeRef + // If we don't, then typing a new method name will end up treating the name node as a typeRef // which can autocomplete incorrectly MEMBER_SET(propDecl, mNameNode, nameIdentifier); @@ -7320,7 +7313,7 @@ BfAstNode* BfReducer::ReadTypeMember(BfAstNode* node, bool declStarted, int dept if (tokenNode->mToken == BfToken_Mut) { MEMBER_SET(propertyBodyExpr, mMutSpecifier, tokenNode); - tokenNode = ExpectTokenAfter(tokenNode, BfToken_FatArrow); + tokenNode = ExpectTokenAfter(tokenNode, BfToken_FatArrow); } if (tokenNode != NULL) @@ -7383,7 +7376,7 @@ BfAstNode* BfReducer::ReadTypeMember(BfAstNode* node, bool declStarted, int dept { if (token == BfToken_LChevron) { - bool isTypeRef = IsTypeReference(nameIdentifier, BfToken_LParen); + bool isTypeRef = IsTypeReference(nameIdentifier, BfToken_LParen); if (!isTypeRef) { bool onNewLine = false; @@ -7395,7 +7388,7 @@ BfAstNode* BfReducer::ReadTypeMember(BfAstNode* node, bool declStarted, int dept if (onNewLine) { - // Actually it looks like a partially formed type declaration followed by a method + // Actually it looks like a partially formed type declaration followed by a method // which returns a generic type FailAfter("Name expected", typeRef); @@ -7543,7 +7536,7 @@ BfInitializerExpression* BfReducer::TryCreateInitializerExpression(BfAstNode* ta SetAndRestoreValue prevVisitorPos(mVisitorPos, BfVisitorPos(block)); bool isDone = !mVisitorPos.MoveNext(); - + BfDeferredAstNodeSizedArray values(initializerExpr, initializerExpr->mValues, mAlloc); BfDeferredAstNodeSizedArray commas(initializerExpr, initializerExpr->mCommas, mAlloc); @@ -7575,12 +7568,12 @@ BfInitializerExpression* BfReducer::TryCreateInitializerExpression(BfAstNode* ta } } } - } + } mVisitorPos.Trim(); - + if (block->mCloseBrace != NULL) - MEMBER_SET(initializerExpr, mCloseBrace, block->mCloseBrace); + MEMBER_SET(initializerExpr, mCloseBrace, block->mCloseBrace); return initializerExpr; } @@ -7843,7 +7836,7 @@ bool BfReducer::SetProtection(BfAstNode* parentNode, BfAstNode*& protectionNodeR ((prevToken->mToken == BfToken_Internal) && (tokenNode->mToken == BfToken_Protected))) { auto tokenPair = mAlloc->Alloc(); - + if (prevToken->mSrcStart < tokenNode->mSrcStart) { ReplaceNode(prevToken, tokenPair); @@ -7863,7 +7856,7 @@ bool BfReducer::SetProtection(BfAstNode* parentNode, BfAstNode*& protectionNodeR return true; } } - + Fail("Protection already specified", protectionNodeRef); } protectionNodeRef = tokenNode; @@ -8017,7 +8010,6 @@ BfAstNode* BfReducer::CreateAllocNode(BfTokenNode* allocToken) MEMBER_SET(newNode, mAllocNode, identifier); mVisitorPos.MoveNext(); } - } } @@ -8112,7 +8104,7 @@ BfObjectCreateExpression* BfReducer::CreateObjectCreateExpression(BfAstNode* all MEMBER_SET(objectCreateExpr, mCloseToken, block->mCloseBrace); objectCreateExpr->mSrcEnd = block->mSrcEnd; return objectCreateExpr; - } + } if (isArray) { @@ -8127,13 +8119,13 @@ BfObjectCreateExpression* BfReducer::CreateObjectCreateExpression(BfAstNode* all } else { - // Note- if there WERE an LBracket here then we'd have an 'isArray' case. We pass this in here for + // Note- if there WERE an LBracket here then we'd have an 'isArray' case. We pass this in here for // error display purposes tokenNode = ExpectTokenAfter(objectCreateExpr, BfToken_LParen, BfToken_LBracket); if (tokenNode == NULL) return objectCreateExpr; } - + MEMBER_SET(objectCreateExpr, mOpenToken, tokenNode); BfToken endToken = (BfToken)(tokenNode->GetToken() + 1); @@ -8141,7 +8133,7 @@ BfObjectCreateExpression* BfReducer::CreateObjectCreateExpression(BfAstNode* all if (tokenNode == NULL) return objectCreateExpr; MEMBER_SET(objectCreateExpr, mCloseToken, tokenNode); - + return objectCreateExpr; } @@ -8175,7 +8167,7 @@ BfExpression* BfReducer::CreateIndexerExpression(BfExpression* target) if (attributeDirective != NULL) { BfAttributedExpression* attribExpr = mAlloc->Alloc(); - ReplaceNode(indexerExpr, attribExpr); + ReplaceNode(indexerExpr, attribExpr); attribExpr->mExpression = indexerExpr; MEMBER_SET(attribExpr, mAttributes, attributeDirective); return attribExpr; @@ -8340,16 +8332,16 @@ BfAstNode* BfReducer::HandleTopLevel(BfBlock* node) bool hadPrevFail = false; bool isDone = !mVisitorPos.MoveNext(); - + auto parser = mSource->ToParser(); if ((parser != NULL) && (parser->mEmbedKind == BfSourceEmbedKind_Type)) - { + { while (!isDone) { auto node = mVisitorPos.GetCurrent(); if (node == prevNode) - { + { // If we're stuck on an error and can't process any more nodes break; } @@ -8418,7 +8410,7 @@ BfAstNode* BfReducer::HandleTopLevel(BfBlock* node) isDone = !mVisitorPos.MoveNext(); if (newNode != NULL) - mVisitorPos.Write(newNode); + mVisitorPos.Write(newNode); } mVisitorPos.Trim(); return node; @@ -8503,7 +8495,7 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi break; } } - } + } else if ((bracketDepth > 0) || (parenDepth > 0)) { // Allow @@ -8627,7 +8619,7 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi bodyNode = ExpectTokenAfter(namespaceDeclaration, BfToken_Semicolon); else bodyNode = blockNode = ExpectBlockAfter(namespaceDeclaration); - + if (bodyNode == NULL) return namespaceDeclaration; MoveNode(bodyNode, namespaceDeclaration); @@ -8653,7 +8645,7 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi FailAfter("Expected type declaration", tokenNode); return NULL; } - + mVisitorPos.MoveNext(); auto topLevelObject = CreateTopLevelObject(nextToken, attributes); if (topLevelObject == NULL) @@ -8674,7 +8666,7 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi break; case BfToken_Sealed: - case BfToken_Abstract: + case BfToken_Abstract: case BfToken_Public: case BfToken_Private: case BfToken_Protected: @@ -8707,7 +8699,7 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi return NULL; } mVisitorPos.MoveNext(); - + auto topLevelObject = CreateTopLevelObject(nextToken, attributes); if (topLevelObject == NULL) { @@ -8731,7 +8723,7 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi (token == BfToken_Private) || (token == BfToken_Internal)) { - SetProtection(typeDeclaration, typeDeclaration->mProtectionSpecifier, tokenNode); + SetProtection(typeDeclaration, typeDeclaration->mProtectionSpecifier, tokenNode); } if (token == BfToken_Static) @@ -8822,8 +8814,6 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi //MEMBER_SET(methodDecl, mReturnType, retType); - - return typeDeclaration; } break; @@ -8961,15 +8951,15 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi { if (tokenNode->mToken == BfToken_This) { - mVisitorPos.MoveNext(); + mVisitorPos.MoveNext(); auto ctorDecl = mAlloc->Alloc(); BfDeferredAstSizedArray params(ctorDecl->mParams, mAlloc); BfDeferredAstSizedArray commas(ctorDecl->mCommas, mAlloc); ctorDecl->mReturnType = NULL; ReplaceNode(tokenNode, ctorDecl); - MEMBER_SET(ctorDecl, mThisToken, tokenNode); + MEMBER_SET(ctorDecl, mThisToken, tokenNode); ParseMethod(ctorDecl, ¶ms, &commas); - + if (typeDeclaration->mAutoCtor == NULL) { MEMBER_SET(typeDeclaration, mAutoCtor, ctorDecl); @@ -9098,7 +9088,7 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi if (child == NULL) break; auto fieldDecl = mAlloc->Alloc(); - + if (auto tokenNode = BfNodeDynCast(child)) { if (tokenNode->mToken == BfToken_LBracket) @@ -9114,7 +9104,7 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi break; } } - } + } mVisitorPos.MoveNext(); mVisitorPos.Write(fieldDecl); @@ -9351,7 +9341,7 @@ BfCommentNode * BfReducer::FindDocumentation(BfAstNode* defNodeHead, BfAstNode* return NULL; } - if ((checkComment->mCommentKind != BfCommentKind_Documentation_Line_Pre) && + if ((checkComment->mCommentKind != BfCommentKind_Documentation_Line_Pre) && (checkComment->mCommentKind != BfCommentKind_Documentation_Block_Pre)) { // Skip this, not used @@ -9422,7 +9412,7 @@ BfTokenNode* BfReducer::ParseMethodParams(BfAstNode* node, SizedArrayImplGetToken(); if ((token == BfToken_Var) || (token == BfToken_LParen) || (token == BfToken_Delegate) || (token == BfToken_Function) || - (token == BfToken_Comptype) || (token == BfToken_Decltype) || + (token == BfToken_Comptype) || (token == BfToken_Decltype) || (token == BfToken_AllocType) || (token == BfToken_RetType) || (token == BfToken_DotDotDot)) { @@ -9690,7 +9680,7 @@ BfTokenNode* BfReducer::ParseMethodParams(BfAstNode* node, SizedArrayImplmTypeNode != NULL) && (mCurTypeDecl->mTypeNode->GetToken() == BfToken_Function)) isFunction = true; else if ((mCurTypeDecl->mTypeNode != NULL) && (mCurTypeDecl->mTypeNode->GetToken() == BfToken_Delegate)) @@ -9728,13 +9718,13 @@ BfTokenNode* BfReducer::ParseMethodParams(BfAstNode* node, SizedArrayImplmNameNode = nameIdentifierNode; MoveNode(nameIdentifierNode, paramDecl); - nameAfterNode = nameIdentifierNode; - } + nameAfterNode = nameIdentifierNode; + } } node->mSrcEnd = paramDecl->mSrcEnd; @@ -9803,7 +9793,7 @@ bool BfReducer::ParseMethod(BfMethodDeclaration* methodDeclaration, SizedArrayIm methodDeclaration->mCloseParen = ParseMethodParams(methodDeclaration, params, commas, BfToken_RParen, true); - // RParen + // RParen if (methodDeclaration->mCloseParen == NULL) { auto nextNode = mVisitorPos.GetNext(); @@ -9908,7 +9898,7 @@ bool BfReducer::ParseMethod(BfMethodDeclaration* methodDeclaration, SizedArrayIm if (ctorDecl->mInitializer != NULL) { MEMBER_SET(attribExpr, mExpression, ctorDecl->mInitializer); - } + } MEMBER_SET(ctorDecl, mInitializer, attribExpr); } } @@ -10121,44 +10111,44 @@ BfGenericConstraintsDeclaration* BfReducer::CreateGenericConstraintsDeclaration( // ReplaceNode(tokenNode, genericConstraint); // genericConstraint->mWhereToken = tokenNode; // constraintsDeclaration->mHasExpressions = true; -// +// // genericConstraintsArr.push_back(genericConstraint); -// +// // auto expr = CreateExpressionAfter(genericConstraint, CreateExprFlags_EarlyExit); // if (expr == NULL) // break; -// -// MEMBER_SET(genericConstraint, mExpression, expr); -// +// +// MEMBER_SET(genericConstraint, mExpression, expr); +// // BfTokenNode* nextWhereToken = NULL; // if (auto checkToken = BfNodeDynCast(mVisitorPos.GetNext())) // { // if (checkToken->mToken != BfToken_Where) // nextWhereToken = checkToken; // } -// +// // auto nextNode = mVisitorPos.GetNext(); -// if (BfNodeDynCast(nextNode)) -// break; -// +// if (BfNodeDynCast(nextNode)) +// break; +// // bool handled = false; // if (auto tokenNode = BfNodeDynCast(nextNode)) // { -// if (tokenNode->mToken == BfToken_FatArrow) -// break; +// if (tokenNode->mToken == BfToken_FatArrow) +// break; // } -// +// // tokenNode = ExpectTokenAfter(genericConstraint, BfToken_LBrace, BfToken_Where, BfToken_Semicolon); -// if (tokenNode == NULL) +// if (tokenNode == NULL) // break; -// +// // BfToken token = tokenNode->GetToken(); -// if (token != BfToken_Where) -// { +// if (token != BfToken_Where) +// { // mVisitorPos.mReadPos--; // break; // } -// +// // continue; // } // } @@ -10170,7 +10160,7 @@ BfGenericConstraintsDeclaration* BfReducer::CreateGenericConstraintsDeclaration( ReplaceNode(tokenNode, genericConstraint); genericConstraint->mWhereToken = tokenNode; - genericConstraintsArr.push_back(genericConstraint); + genericConstraintsArr.push_back(genericConstraint); auto genericParamName = CreateTypeRefAfter(genericConstraint); if (genericParamName != NULL) @@ -10206,7 +10196,7 @@ BfGenericConstraintsDeclaration* BfReducer::CreateGenericConstraintsDeclaration( { isDone = true; break; - } + } } tokenNode = ExpectTokenAfter(genericConstraint, BfToken_Comma, BfToken_LBrace, BfToken_Where, BfToken_Semicolon); @@ -10960,4 +10950,4 @@ BfInlineAsmStatement* BfReducer::CreateInlineAsmStatement(BfAstNode* asmNode) } return asmStatement; -} +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfReducer.h b/IDEHelper/Compiler/BfReducer.h index 01b2ed9d..5b2ec940 100644 --- a/IDEHelper/Compiler/BfReducer.h +++ b/IDEHelper/Compiler/BfReducer.h @@ -36,8 +36,8 @@ public: CreateStmtFlags_NoCaseExpr = 1, CreateStmtFlags_FindTrailingSemicolon = 2, CreateStmtFlags_AllowUnterminatedExpression = 4, - CreateStmtFlags_AllowLocalFunction = 8, - CreateStmtFlags_ForceVariableDecl = 0x10, + CreateStmtFlags_AllowLocalFunction = 8, + CreateStmtFlags_ForceVariableDecl = 0x10, CreateStmtFlags_To_CreateExprFlags_Mask = 1 }; @@ -127,7 +127,7 @@ public: } }; -public: +public: BfAstAllocator* mAlloc; BfSystem* mSystem; BfSource* mSource; @@ -141,12 +141,12 @@ public: BfMethodDeclaration* mCurMethodDecl; BfAstNode* mLastBlockNode; bool mStmtHasError; - bool mPrevStmtHadError; + bool mPrevStmtHadError; bool mCompatMode; // Does C++ compatible parsing bool mAllowTypeWildcard; bool mIsFieldInitializer; bool mInParenExpr; - bool mSkipCurrentNodeAssert; + bool mSkipCurrentNodeAssert; BfVisitorPos mVisitorPos; int mDocumentCheckIdx; SizedArray mCurNamespaceStack; @@ -154,15 +154,15 @@ public: int mAssertCurrentNodeIdx; -public: +public: BfAstNode* Fail(const StringImpl& errorMsg, BfAstNode* refNode); BfAstNode* FailAfter(const StringImpl& errorMsg, BfAstNode* refNode); void AddErrorNode(BfAstNode* astNode, bool removeNode = true); - -public: + +public: bool StringEquals(BfAstNode* node, BfAstNode* node2); bool IsSemicolon(BfAstNode* node); - BfTokenNode* ExpectTokenAfter(BfAstNode* node, BfToken token); + BfTokenNode* ExpectTokenAfter(BfAstNode* node, BfToken token); BfTokenNode* ExpectTokenAfter(BfAstNode* node, BfToken tokenA, BfToken tokenB); BfTokenNode* ExpectTokenAfter(BfAstNode* node, BfToken tokenA, BfToken tokenB, BfToken tokenC); BfTokenNode* ExpectTokenAfter(BfAstNode* node, BfToken tokenA, BfToken tokenB, BfToken tokenC, BfToken tokenD); @@ -176,8 +176,8 @@ public: bool IsNodeRelevant(BfAstNode* astNode); bool IsNodeRelevant(BfAstNode* startNode, BfAstNode* endNode); void MoveNode(BfAstNode* srcNode, BfAstNode* newOwner); - void ReplaceNode(BfAstNode* prevNode, BfAstNode* newNode); - + void ReplaceNode(BfAstNode* prevNode, BfAstNode* newNode); + bool SetProtection(BfAstNode* parentNode, BfAstNode*& protectionNodeRef, BfTokenNode* tokenNode); BfAstNode* CreateAllocNode(BfTokenNode* newNode); BfAstNode* ReplaceTokenStarter(BfAstNode* astNode, int idx = -1, bool allowIn = false); @@ -195,12 +195,12 @@ public: void CreateQualifiedNames(BfAstNode* node); BfFieldDtorDeclaration* CreateFieldDtorDeclaration(BfAstNode* srcNode); BfFieldDeclaration* CreateFieldDeclaration(BfTokenNode* tokenNode, BfTypeReference* typeRef, BfIdentifierNode* nameIdentifier, BfFieldDeclaration* prevFieldDeclaration); - BfAttributeDirective* CreateAttributeDirective(BfTokenNode* startToken); + BfAttributeDirective* CreateAttributeDirective(BfTokenNode* startToken); BfStatement* CreateAttributedStatement(BfTokenNode* tokenNode, CreateStmtFlags createStmtFlags = CreateStmtFlags_None); BfExpression* CreateAttributedExpression(BfTokenNode* tokenNode, bool onlyAllowIdentifier); BfDelegateBindExpression* CreateDelegateBindExpression(BfAstNode* allocNode); BfLambdaBindExpression* CreateLambdaBindExpression(BfAstNode* allocNode, BfTokenNode* parenToken = NULL); - BfCollectionInitializerExpression* CreateCollectionInitializerExpression(BfBlock* block); + BfCollectionInitializerExpression* CreateCollectionInitializerExpression(BfBlock* block); BfCollectionInitializerExpression* CreateCollectionInitializerExpression(BfTokenNode* openToken); BfObjectCreateExpression* CreateObjectCreateExpression(BfAstNode* allocNode); BfScopedInvocationTarget* CreateScopedInvocationTarget(BfAstNode*& targetRef, BfTokenNode* colonToken); @@ -225,7 +225,7 @@ public: BfTypeReference* DoCreateTypeRef(BfAstNode* identifierNode, CreateTypeRefFlags createTypeRefFlags = CreateTypeRefFlags_None, int endNode = -1); BfTypeReference* CreateTypeRef(BfAstNode* identifierNode, CreateTypeRefFlags createTypeRefFlags = CreateTypeRefFlags_None); BfTypeReference* CreateTypeRefAfter(BfAstNode* astNode, CreateTypeRefFlags createTypeRefFlags = CreateTypeRefFlags_None); - BfTypeReference* CreateRefTypeRef(BfTypeReference* elementType, BfTokenNode* refToken); + BfTypeReference* CreateRefTypeRef(BfTypeReference* elementType, BfTokenNode* refToken); bool ParseMethod(BfMethodDeclaration* methodDeclaration, SizedArrayImpl* params, SizedArrayImpl* commas, bool alwaysIncludeBlock = false); BfGenericArgumentsNode* CreateGenericArguments(BfTokenNode* tokenNode, bool allowPartial = false); BfGenericParamsDeclaration* CreateGenericParamsDeclaration(BfTokenNode* tokenNode); diff --git a/IDEHelper/Compiler/BfResolvePass.cpp b/IDEHelper/Compiler/BfResolvePass.cpp index 5474cd2d..725a4cb3 100644 --- a/IDEHelper/Compiler/BfResolvePass.cpp +++ b/IDEHelper/Compiler/BfResolvePass.cpp @@ -1,14 +1,14 @@ -#include "BfResolvePass.h" +#include "BfResolvePass.h" #include "BfParser.h" #include "BfModule.h" USING_NS_BF; BfResolvePassData::BfResolvePassData() -{ +{ mGetSymbolReferenceKind = BfGetSymbolReferenceKind_None; - mSymbolReferenceTypeDef = NULL; + mSymbolReferenceTypeDef = NULL; mSymbolReferenceLocalIdx = -1; mSymbolReferenceFieldIdx = -1; @@ -31,7 +31,7 @@ BfResolvePassData::~BfResolvePassData() auto parser = emitEntryKV.mValue.mParser; if (parser != NULL) { - delete parser->mSourceClassifier; + delete parser->mSourceClassifier; parser->mSourceClassifier = NULL; parser->mParserFlags = ParserFlag_None; parser->mCursorCheckIdx = -1; @@ -56,7 +56,7 @@ void BfResolvePassData::RecordReplaceNode(BfAstNode* node) auto parser = node->GetSourceData()->ToParserData(); if (node->GetSrcStart() >= parser->mSrcLength) return; - + while (true) { if (auto qualifiedName = BfNodeDynCast(node)) @@ -65,35 +65,35 @@ void BfResolvePassData::RecordReplaceNode(BfAstNode* node) } else break; - } + } RecordReplaceNode(parser, node->GetSrcStart(), node->GetSrcLength()); } void BfResolvePassData::HandleMethodReference(BfAstNode* node, BfTypeDef* typeDef, BfMethodDef* methodDef) { - if ((mGetSymbolReferenceKind == BfGetSymbolReferenceKind_Method) && (mSymbolReferenceTypeDef == typeDef->GetDefinition()) && + if ((mGetSymbolReferenceKind == BfGetSymbolReferenceKind_Method) && (mSymbolReferenceTypeDef == typeDef->GetDefinition()) && (mSymbolReferenceMethodIdx == methodDef->mIdx)) RecordReplaceNode(node); } void BfResolvePassData::HandleFieldReference(BfAstNode* node, BfTypeDef* typeDef, BfFieldDef* fieldDef) { - if ((mGetSymbolReferenceKind == BfGetSymbolReferenceKind_Field) && (mSymbolReferenceTypeDef == typeDef->GetDefinition()) && + if ((mGetSymbolReferenceKind == BfGetSymbolReferenceKind_Field) && (mSymbolReferenceTypeDef == typeDef->GetDefinition()) && (mSymbolReferenceFieldIdx == fieldDef->mIdx)) RecordReplaceNode(node); } void BfResolvePassData::HandlePropertyReference(BfAstNode* node, BfTypeDef* typeDef, BfPropertyDef* propDef) { - if ((mGetSymbolReferenceKind == BfGetSymbolReferenceKind_Property) && (mSymbolReferenceTypeDef == typeDef->GetDefinition()) && + if ((mGetSymbolReferenceKind == BfGetSymbolReferenceKind_Property) && (mSymbolReferenceTypeDef == typeDef->GetDefinition()) && (mSymbolReferencePropertyIdx == propDef->mIdx)) RecordReplaceNode(node); } void BfResolvePassData::HandleLocalReference(BfIdentifierNode* identifier, BfTypeDef* typeDef, BfMethodDef* methodDef, int localVarIdx) { - if ((mGetSymbolReferenceKind == BfGetSymbolReferenceKind_Local) && (mSymbolReferenceTypeDef == typeDef->GetDefinition()) && + if ((mGetSymbolReferenceKind == BfGetSymbolReferenceKind_Local) && (mSymbolReferenceTypeDef == typeDef->GetDefinition()) && (mSymbolReferenceMethodIdx == methodDef->mIdx) && (localVarIdx == mSymbolReferenceLocalIdx)) RecordReplaceNode(identifier); } @@ -106,14 +106,14 @@ void BfResolvePassData::HandleTypeGenericParam(BfAstNode* node, BfTypeDef* typeD void BfResolvePassData::HandleMethodGenericParam(BfAstNode* node, BfTypeDef* typeDef, BfMethodDef* methodDef, int genericParamIdx) { - if ((mGetSymbolReferenceKind == BfGetSymbolReferenceKind_MethodGenericParam) && (mSymbolReferenceTypeDef == typeDef->GetDefinition()) && + if ((mGetSymbolReferenceKind == BfGetSymbolReferenceKind_MethodGenericParam) && (mSymbolReferenceTypeDef == typeDef->GetDefinition()) && (mSymbolReferenceMethodIdx == methodDef->mIdx) && (genericParamIdx == mSymbolMethodGenericParamIdx)) RecordReplaceNode(node); } void BfResolvePassData::HandleLocalReference(BfIdentifierNode* identifier, BfIdentifierNode* origNameNode, BfTypeDef* typeDef, BfMethodDef* methodDef, int localVarIdx) { - if ((mGetSymbolReferenceKind == BfGetSymbolReferenceKind_Local) && (mSymbolReferenceTypeDef == typeDef->GetDefinition()) && + if ((mGetSymbolReferenceKind == BfGetSymbolReferenceKind_Local) && (mSymbolReferenceTypeDef == typeDef->GetDefinition()) && (mSymbolReferenceMethodIdx == methodDef->mIdx) && (localVarIdx == mSymbolReferenceLocalIdx)) { if (origNameNode == NULL) @@ -122,7 +122,7 @@ void BfResolvePassData::HandleLocalReference(BfIdentifierNode* identifier, BfIde int origLen = origNameNode->GetSrcLength(); int refLen = identifier->GetSrcLength(); - // The lengths can be different if we have one or more @'s prepended + // The lengths can be different if we have one or more @'s prepended RecordReplaceNode(identifier->GetSourceData()->ToParserData(), identifier->GetSrcStart() + (refLen - origLen), origLen); } } @@ -215,4 +215,4 @@ BfSourceClassifier* BfResolvePassData::GetSourceClassifier(BfParser* parser) if (parser == NULL) return NULL; return parser->mSourceClassifier; -} +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfResolvePass.h b/IDEHelper/Compiler/BfResolvePass.h index be12ddd1..da95812e 100644 --- a/IDEHelper/Compiler/BfResolvePass.h +++ b/IDEHelper/Compiler/BfResolvePass.h @@ -14,7 +14,7 @@ enum BfResolveType BfResolveType_Autocomplete, BfResolveType_Autocomplete_HighPri, BfResolveType_GoToDefinition, - BfResolveType_GetSymbolInfo, + BfResolveType_GetSymbolInfo, BfResolveType_RenameSymbol, BfResolveType_ShowFileSymbolReferences, BfResolveType_GetNavigationData, @@ -68,14 +68,14 @@ public: BfAutoComplete* mAutoComplete; Array mAutoCompleteTempTypes; // Contains multiple values when we have nested types Dictionary mStaticSearchMap; - Dictionary mInternalAccessMap; + Dictionary mInternalAccessMap; Array mExteriorAutocompleteCheckNodes; - BfGetSymbolReferenceKind mGetSymbolReferenceKind; + BfGetSymbolReferenceKind mGetSymbolReferenceKind; String mQueuedReplaceTypeDef; BfTypeDef* mSymbolReferenceTypeDef; String mQueuedSymbolReferenceNamespace; - BfAtomComposite mSymbolReferenceNamespace; + BfAtomComposite mSymbolReferenceNamespace; int mSymbolReferenceLocalIdx; int mSymbolReferenceFieldIdx; int mSymbolReferenceMethodIdx; @@ -85,7 +85,7 @@ public: bool mIsClassifying; bool mHasCursorIdx; bool mHadEmits; - + typedef Dictionary FoundSymbolReferencesParserDataMap; FoundSymbolReferencesParserDataMap mFoundSymbolReferencesParserData; //std::vector mSymbolReferenceIdentifiers; @@ -94,7 +94,7 @@ public: public: void RecordReplaceNode(BfParserData* parser, int srcStart, int srcLen); - void RecordReplaceNode(BfAstNode* node); + void RecordReplaceNode(BfAstNode* node); BfAstNode* FindBaseNode(BfAstNode* node); public: @@ -108,7 +108,7 @@ public: void HandleMethodReference(BfAstNode* node, BfTypeDef* typeDef, BfMethodDef* methodDef); void HandleFieldReference(BfAstNode* node, BfTypeDef* typeDef, BfFieldDef* fieldDef); void HandlePropertyReference(BfAstNode* node, BfTypeDef* typeDef, BfPropertyDef* propDef); - void HandleTypeReference(BfAstNode* node, BfTypeDef* typeDef); + void HandleTypeReference(BfAstNode* node, BfTypeDef* typeDef); void HandleNamespaceReference(BfAstNode* node, const BfAtomComposite& namespaceName); BfSourceClassifier* GetSourceClassifier(BfAstNode* astNode); diff --git a/IDEHelper/Compiler/BfResolvedTypeUtils.cpp b/IDEHelper/Compiler/BfResolvedTypeUtils.cpp index 5c088f1f..61bbdbf8 100644 --- a/IDEHelper/Compiler/BfResolvedTypeUtils.cpp +++ b/IDEHelper/Compiler/BfResolvedTypeUtils.cpp @@ -42,7 +42,7 @@ void BfTypedValue::DbgCheckType() const BF_ASSERT(strncmp(stringRef.data(), "DEAD", 4) != 0); } }*/ - + #ifdef _DEBUG /*if (mValue != NULL) { @@ -58,8 +58,8 @@ bool BfTypedValue::IsValuelessType() const } bool BfTypedValue::CanModify() const -{ - return (((IsAddr()) || (mType->IsValuelessType())) && (!IsReadOnly())); +{ + return (((IsAddr()) || (mType->IsValuelessType())) && (!IsReadOnly())); } ////////////////////////////////////////////////////////////////////////// @@ -144,9 +144,9 @@ String BfUsingFieldData::MemberRef::GetName(BfModule* curModule) const { auto methodInstance = curModule->GetRawMethodInstance(mTypeInstance, mTypeInstance->mTypeDef->mMethods[mIdx]); return curModule->MethodToString(methodInstance, BfMethodNameFlag_OmitTypeName); - } + } case Kind_Local: - return curModule->mCurMethodState->mLocals[mIdx]->mName; + return curModule->mCurMethodState->mLocals[mIdx]->mName; } return ""; } @@ -176,7 +176,7 @@ bool BfUsingFieldData::MemberRef::IsStatic() const case Kind_Property: return mTypeInstance->mTypeDef->mProperties[mIdx]->mIsStatic; case Kind_Method: - return mTypeInstance->mTypeDef->mMethods[mIdx]->mIsStatic; + return mTypeInstance->mTypeDef->mMethods[mIdx]->mIsStatic; } return false; } @@ -200,10 +200,10 @@ bool BfGenericParamInstance::IsEnum() ////////////////////////////////////////////////////////////////////////// bool BfDependencyMap::AddUsedBy(BfType* dependentType, BfDependencyMap::DependencyFlags flags) -{ +{ BF_ASSERT(dependentType != NULL); BF_ASSERT(dependentType->mRevision != -1); - + //auto itr = mTypeSet.insert(BfDependencyMap::TypeMap::value_type(dependentType, DependencyEntry(dependentType->mRevision, flags))); //if (!itr.second) @@ -219,7 +219,7 @@ bool BfDependencyMap::AddUsedBy(BfType* dependentType, BfDependencyMap::Dependen mMinDependDepth = tryDepth; } } - + dependencyEntry->mRevision = dependentType->mRevision; dependencyEntry->mFlags = flags; return true; @@ -227,13 +227,13 @@ bool BfDependencyMap::AddUsedBy(BfType* dependentType, BfDependencyMap::Dependen else { if (dependencyEntry->mRevision != dependentType->mRevision) - { + { dependencyEntry->mRevision = dependentType->mRevision; dependencyEntry->mFlags = flags; return true; } else - { + { if ((dependencyEntry->mFlags & flags) == flags) return false; dependencyEntry->mFlags = (DependencyFlags)(dependencyEntry->mFlags | flags); @@ -274,27 +274,26 @@ BfFieldDef* BfFieldInstance::GetFieldDef() ////////////////////////////////////////////////////////////////////////// BfType::BfType() -{ - mTypeId = -1; +{ + mTypeId = -1; mContext = NULL; mRevision = -1; - + //mLastUsedRevision = -1; - mDefineState = BfTypeDefineState_Undefined; - //mDICallbackVH = NULL; - //mInnerDICallbackVH = NULL; - mRebuildFlags = BfTypeRebuildFlag_None; - mAlign = -1; - mSize = -1; //mDICallbackVH = NULL; //mInnerDICallbackVH = NULL; - mDirty = true; + mRebuildFlags = BfTypeRebuildFlag_None; + mAlign = -1; + mSize = -1; + //mDICallbackVH = NULL; + //mInnerDICallbackVH = NULL; + mDirty = true; } BfModule* BfType::GetModule() -{ +{ if (mContext->mCompiler->mOptions.mCompileOnDemandKind == BfCompileOnDemandKind_AlwaysInclude) return mContext->mScratchModule; else @@ -348,7 +347,7 @@ BfMethodInstance* BfNonGenericMethodRef::operator->() const } BfNonGenericMethodRef& BfNonGenericMethodRef::operator=(BfMethodInstance* methodInstance) -{ +{ if (methodInstance == NULL) { mTypeInstance = NULL; @@ -358,7 +357,7 @@ BfNonGenericMethodRef& BfNonGenericMethodRef::operator=(BfMethodInstance* method { mTypeInstance = methodInstance->mMethodInstanceGroup->mOwner; mMethodNum = methodInstance->mMethodInstanceGroup->mMethodIdx; - BF_ASSERT((methodInstance->GetNumGenericArguments() == 0) || + BF_ASSERT((methodInstance->GetNumGenericArguments() == 0) || ((methodInstance->mIsUnspecialized) && (!methodInstance->mIsUnspecializedVariation))); mSignatureHash = (int)mTypeInstance->mTypeDef->mSignatureHash; } @@ -415,7 +414,7 @@ BfMethodRef::operator BfMethodInstance* () const isSpecialied = true; break; } - + auto genericParam = (BfGenericParamType*)genericArg; if ((genericParam->mGenericParamKind != BfGenericParamKind_Method) || (genericParam->mGenericParamIdx != paramIdx)) { @@ -427,7 +426,7 @@ BfMethodRef::operator BfMethodInstance* () const } if (isSpecialied) - { + { BfMethodInstance** methodInstancePtr = NULL; if (methodSpecializationGroup.mMethodSpecializationMap->TryGetValue(mMethodGenericArguments, &methodInstancePtr)) return *methodInstancePtr; @@ -452,7 +451,7 @@ BfMethodRef& BfMethodRef::operator=(BfMethodInstance* methodInstance) mMethodRefFlags = BfMethodRefFlag_None; } else - { + { mTypeInstance = methodInstance->mMethodInstanceGroup->mOwner; mMethodNum = methodInstance->mMethodInstanceGroup->mMethodIdx; if (methodInstance->mMethodInfoEx != NULL) @@ -531,11 +530,10 @@ BfPropertyRef::BfPropertyRef(BfTypeInstance* typeInst, BfPropertyDef* propDef) } BfPropertyRef::operator BfPropertyDef*() const -{ +{ return mTypeInstance->mTypeDef->mProperties[mPropIdx]; } - ////////////////////////////////////////////////////////////////////////// /*BfMethodInstance* BfTypeInstance::GetVTableMethodInstance(int vtableIdx) @@ -547,7 +545,7 @@ BfPropertyRef::operator BfPropertyDef*() const static int gDelIdx = 0; BfType::~BfType() -{ +{ if (mContext != NULL) BfLogSys(mContext->mSystem, "~BfType %p\n", this); @@ -566,16 +564,16 @@ BfFieldInstance::~BfFieldInstance() BfType* BfFieldInstance::GetResolvedType() { - return mResolvedType; + return mResolvedType; } void BfFieldInstance::SetResolvedType(BfType* type) -{ +{ mResolvedType = type; } void BfFieldInstance::GetDataRange(int& dataIdx, int& dataCount) -{ +{ int minMergedDataIdx = mMergedDataIdx; int maxMergedDataIdx = minMergedDataIdx + 1; if (mResolvedType->IsStruct()) @@ -625,7 +623,7 @@ int BfFieldInstance::GetAlign(int packing) { auto module = mOwner->mModule; for (auto& attrib : mCustomAttributes->mAttributes) - { + { if (attrib.mType->IsInstanceOf(module->mCompiler->mAlignAttributeTypeDef)) { align = 16; // System conservative default @@ -643,7 +641,7 @@ int BfFieldInstance::GetAlign(int packing) module->Fail("Alignment must be a power of 2", attrib.GetRefNode()); } } - } + } } } return align; @@ -710,13 +708,13 @@ BfMethodInstance* BfMethodParam::GetDelegateParamInvoke() BfMethodInfoEx::~BfMethodInfoEx() { for (auto genericParam : mGenericParams) - genericParam->Release(); + genericParam->Release(); delete mMethodCustomAttributes; delete mClosureInstanceInfo; } BfMethodInstance::~BfMethodInstance() -{ +{ Dispose(true); if (mHasMethodRefType) @@ -729,7 +727,7 @@ BfMethodInstance::~BfMethodInstance() } } - delete mMethodInfoEx; + delete mMethodInfoEx; } void BfMethodInstance::Dispose(bool isDeleting) @@ -737,7 +735,7 @@ void BfMethodInstance::Dispose(bool isDeleting) if (mIsDisposed) return; mIsDisposed = true; - + if (mMethodInstanceGroup != NULL) { BfLogSys(GetOwner()->mModule->mSystem, "BfMethodInstance::~BfMethodInstance %p Local:%d InCEMachine:%d Deleting:%d\n", this, mMethodDef->mIsLocalMethod, mInCEMachine, isDeleting); @@ -752,7 +750,7 @@ void BfMethodInstance::Dispose(bool isDeleting) auto module = GetOwner()->mModule; if (module->mCompiler->mCeMachine != NULL) module->mCompiler->mCeMachine->RemoveMethod(this); - } + } if (mMethodProcessRequest != NULL) { @@ -777,7 +775,7 @@ void BfMethodInstance::CopyFrom(BfMethodInstance* methodInstance) for (auto genericParam : mMethodInfoEx->mGenericParams) genericParam->AddRef(); mMethodInfoEx->mMethodCustomAttributes = NULL; - + if (mMethodInfoEx->mClosureInstanceInfo != NULL) { mMethodInfoEx->mClosureInstanceInfo = new BfClosureInstanceInfo(); @@ -800,7 +798,7 @@ BfImportKind BfMethodInstance::GetImportKind() auto customAttributes = GetCustomAttributes(); if (customAttributes == NULL) return BfImportKind_None; - + BfCustomAttribute* customAttribute = customAttributes->Get(module->mCompiler->mImportAttributeTypeDef); if (customAttribute == NULL) return BfImportKind_Import_Static; @@ -849,10 +847,10 @@ void BfMethodInstance::UndoDeclaration(bool keepIRFunction) if (mMethodInfoEx != NULL) { for (auto genericParam : mMethodInfoEx->mGenericParams) - genericParam->Release(); + genericParam->Release(); mMethodInfoEx->mGenericParams.Clear(); delete mMethodInfoEx->mMethodCustomAttributes; - mMethodInfoEx->mMethodCustomAttributes = NULL; + mMethodInfoEx->mMethodCustomAttributes = NULL; mMethodInfoEx->mGenericTypeBindings.Clear(); } @@ -860,7 +858,7 @@ void BfMethodInstance::UndoDeclaration(bool keepIRFunction) if (!keepIRFunction) mIRFunction = BfIRValue(); mParams.Clear(); - + mDefaultValues.Clear(); if (mMethodProcessRequest != NULL) { @@ -873,7 +871,7 @@ void BfMethodInstance::UndoDeclaration(bool keepIRFunction) mIsUnspecialized = false; mIsUnspecializedVariation = false; mDisallowCalling = false; - mIsIntrinsic = false; + mIsIntrinsic = false; mHasFailed = false; mFailedConstraints = false; } @@ -943,7 +941,7 @@ bool BfMethodInstance::HasParamsArray() } int BfMethodInstance::GetStructRetIdx(bool forceStatic) -{ +{ if ((mReturnType->IsComposite()) && (!mReturnType->IsValuelessType()) && (!GetLoweredReturnType(NULL, NULL, forceStatic)) && (!mIsIntrinsic)) { auto returnTypeInst = mReturnType->ToTypeInstance(); @@ -962,7 +960,7 @@ int BfMethodInstance::GetStructRetIdx(bool forceStatic) return 1; if ((mMethodDef->mIsMutating) || (!thisType->IsSplattable()) || ((!AllowsSplatting(-1)) && (!thisType->GetLoweredType(BfTypeUsage_Parameter)))) return 1; - return 0; + return 0; } return -1; @@ -981,7 +979,7 @@ bool BfMethodInstance::HasSelf() bool BfMethodInstance::GetLoweredReturnType(BfTypeCode* loweredTypeCode, BfTypeCode* loweredTypeCode2, bool forceStatic) { // Win32 handler - if (((mMethodDef->mIsStatic) || (forceStatic)) && + if (((mMethodDef->mIsStatic) || (forceStatic)) && (mReturnType->IsComposite()) && ((mReturnType->mSize == 4) || (mReturnType->mSize == 8))) { @@ -1003,7 +1001,7 @@ bool BfMethodInstance::GetLoweredReturnType(BfTypeCode* loweredTypeCode, BfTypeC } } - return mReturnType->GetLoweredType((mMethodDef->mIsStatic || forceStatic) ? BfTypeUsage_Return_Static : BfTypeUsage_Return_NonStatic, loweredTypeCode, loweredTypeCode2); + return mReturnType->GetLoweredType((mMethodDef->mIsStatic || forceStatic) ? BfTypeUsage_Return_Static : BfTypeUsage_Return_NonStatic, loweredTypeCode, loweredTypeCode2); } bool BfMethodInstance::WantsStructsAttribByVal(BfType* paramType) @@ -1019,8 +1017,8 @@ bool BfMethodInstance::WantsStructsAttribByVal(BfType* paramType) } bool BfMethodInstance::IsSkipCall(bool bypassVirtual) -{ - if ((mMethodDef->mIsSkipCall) && +{ + if ((mMethodDef->mIsSkipCall) && ((!mMethodDef->mIsVirtual) || (bypassVirtual))) return true; return false; @@ -1041,7 +1039,7 @@ bool BfMethodInstance::AlwaysInline() BfImportCallKind BfMethodInstance::GetImportCallKind() { if (GetImportKind() != BfImportKind_Import_Dynamic) - return BfImportCallKind_None; + return BfImportCallKind_None; if ((mHotMethod != NULL) && ((mHotMethod->mFlags & BfHotDepDataFlag_IsOriginalBuild) == 0)) return BfImportCallKind_GlobalVar_Hot; return BfImportCallKind_GlobalVar; @@ -1080,7 +1078,7 @@ bool BfMethodInstance::AllowsSplatting(int paramIdx) bool BfMethodInstance::HasThis() { if (mMethodDef->mIsStatic) - return false; + return false; if ((mMethodInfoEx != NULL) && (mMethodInfoEx->mClosureInstanceInfo != NULL) && (mMethodInfoEx->mClosureInstanceInfo->mThisOverride != NULL)) return !mMethodInfoEx->mClosureInstanceInfo->mThisOverride->IsValuelessType(); return (!mMethodInstanceGroup->mOwner->IsValuelessType()); @@ -1118,7 +1116,7 @@ bool BfMethodInstance::HasExplicitThis() { if (mMethodDef->mIsStatic) return false; - return mMethodInstanceGroup->mOwner->IsFunction(); + return mMethodInstanceGroup->mOwner->IsFunction(); } int BfMethodInstance::GetParamCount() @@ -1167,7 +1165,7 @@ void BfMethodInstance::GetParamName(int paramIdx, StringImpl& name, int& namePre } String BfMethodInstance::GetParamName(int paramIdx) -{ +{ StringT<256> paramName; int namePrefixCount = 0; GetParamName(paramIdx, paramName, namePrefixCount); @@ -1182,7 +1180,7 @@ String BfMethodInstance::GetParamName(int paramIdx, int& namePrefixCount) } BfType* BfMethodInstance::GetParamType(int paramIdx, bool returnUnderlyingParamsType) -{ +{ if (paramIdx == -1) { if ((mMethodInfoEx != NULL) && (mMethodInfoEx->mClosureInstanceInfo != NULL) && (mMethodInfoEx->mClosureInstanceInfo->mThisOverride != NULL)) @@ -1199,9 +1197,9 @@ BfType* BfMethodInstance::GetParamType(int paramIdx, bool returnUnderlyingParams return thisType; } - BfMethodParam* methodParam = &mParams[paramIdx]; + BfMethodParam* methodParam = &mParams[paramIdx]; if (methodParam->mDelegateParamIdx != -1) - { + { BfMethodInstance* invokeMethodInstance = methodParam->GetDelegateParamInvoke(); return invokeMethodInstance->GetParamType(methodParam->mDelegateParamIdx, true); } @@ -1230,7 +1228,7 @@ bool BfMethodInstance::GetParamIsSplat(int paramIdx) if ((owner->IsValueType()) && (mMethodDef->mIsMutating || !AllowsSplatting(paramIdx))) return false; return owner->mIsSplattable; - } + } BfMethodParam* methodParam = &mParams[paramIdx]; if (methodParam->mDelegateParamIdx != -1) @@ -1271,7 +1269,7 @@ bool BfMethodInstance::IsParamSkipped(int paramIdx) GetModule()->PopulateType(paramType, BfPopulateType_Data); if ((paramType->IsValuelessType()) && (!paramType->IsMethodRef())) return true; - return false; + return false; } bool BfMethodInstance::IsImplicitCapture(int paramIdx) @@ -1280,7 +1278,7 @@ bool BfMethodInstance::IsImplicitCapture(int paramIdx) return false; BfMethodParam* methodParam = &mParams[paramIdx]; if (methodParam->mParamDefIdx == -1) - return true; + return true; return false; } @@ -1372,7 +1370,7 @@ void BfMethodInstance::GetIRFunctionInfo(BfModule* module, BfIRType& returnType, module->PopulateType(mReturnType); BfTypeCode loweredReturnTypeCode = BfTypeCode_None; - BfTypeCode loweredReturnTypeCode2 = BfTypeCode_None; + BfTypeCode loweredReturnTypeCode2 = BfTypeCode_None; if ((!module->mIsComptimeModule) && (GetLoweredReturnType(&loweredReturnTypeCode, &loweredReturnTypeCode2, forceStatic)) && (loweredReturnTypeCode != BfTypeCode_None)) { auto irReturnType = module->GetIRLoweredType(loweredReturnTypeCode, loweredReturnTypeCode2); @@ -1401,7 +1399,7 @@ void BfMethodInstance::GetIRFunctionInfo(BfModule* module, BfIRType& returnType, else { returnType = module->mBfIRBuilder->MapType(mReturnType); - } + } for (int paramIdx = -1; paramIdx < GetParamCount(); paramIdx++) { @@ -1419,7 +1417,7 @@ void BfMethodInstance::GetIRFunctionInfo(BfModule* module, BfIRType& returnType, if (HasExplicitThis()) checkType = GetParamType(0); else - checkType = GetOwner(); + checkType = GetOwner(); } } else @@ -1435,7 +1433,7 @@ void BfMethodInstance::GetIRFunctionInfo(BfModule* module, BfIRType& returnType, NOP; }*/ - bool checkLowered = false; + bool checkLowered = false; bool doSplat = false; if (paramIdx == -1) { @@ -1451,7 +1449,7 @@ void BfMethodInstance::GetIRFunctionInfo(BfModule* module, BfIRType& returnType, checkLowered = true; } else - { + { if ((checkType->IsComposite()) && (checkType->IsIncomplete())) module->PopulateType(checkType, BfPopulateType_Data); @@ -1482,17 +1480,17 @@ void BfMethodInstance::GetIRFunctionInfo(BfModule* module, BfIRType& returnType, if (loweredTypeCode2 != BfTypeCode_None) paramTypes.push_back(module->mBfIRBuilder->GetPrimitiveType(loweredTypeCode2)); continue; - } + } } if (checkType->CanBeValuelessType()) module->PopulateType(checkType, BfPopulateType_Data); if ((checkType->IsValuelessType()) && (!checkType->IsMethodRef())) continue; - + if ((doSplat) && (!checkType->IsMethodRef())) - { - int splatCount = checkType->GetSplatCount(); + { + int splatCount = checkType->GetSplatCount(); if ((int)paramTypes.size() + splatCount > module->mCompiler->mOptions.mMaxSplatRegs) { auto checkTypeInst = checkType->ToTypeInstance(); @@ -1506,7 +1504,7 @@ void BfMethodInstance::GetIRFunctionInfo(BfModule* module, BfIRType& returnType, } auto _AddType = [&](BfType* type) - { + { if ((type->IsComposite()) || ((!doSplat) && (paramIdx == -1) && (type->IsTypedPrimitive()))) { auto typeInst = type->ToTypeInstance(); @@ -1529,14 +1527,14 @@ void BfMethodInstance::GetIRFunctionInfo(BfModule* module, BfIRType& returnType, }, checkType); } else - _AddType(checkType); + _AddType(checkType); if (checkType2 != NULL) _AddType(checkType2); } if ((!module->mIsComptimeModule) && (GetStructRetIdx(forceStatic) == 1)) - { + { BF_SWAP(paramTypes[0], paramTypes[1]); } } @@ -1554,13 +1552,12 @@ bool BfMethodInstance::IsExactMatch(BfMethodInstance* other, bool ignoreImplicit { if (mReturnType != other->mReturnType) return false; - + int implicitParamCountA = ignoreImplicitParams ? GetImplicitParamCount() : 0; int implicitParamCountB = ignoreImplicitParams ? other->GetImplicitParamCount() : 0; if (HasExplicitThis()) { - } // if (other->HasExplicitThis()) @@ -1574,21 +1571,21 @@ bool BfMethodInstance::IsExactMatch(BfMethodInstance* other, bool ignoreImplicit if (checkThis) { if (other->mMethodDef->mIsStatic != mMethodDef->mIsStatic) - return false; + return false; // { // // If we are static and we have to match a non-static method, allow us to do so if we have an explicitly defined 'this' param that matches -// +// // if (other->mMethodDef->mIsStatic) // return false; -// +// // if ((GetParamCount() > 0) && (GetParamName(0) == "this")) // { // auto thisType = GetParamType(0); // auto otherThisType = other->GetParamType(-1); // if (thisType != otherThisType) // return false; -// +// // implicitParamCountA++; // } // else @@ -1663,11 +1660,11 @@ void BfMethodInstance::ReportMemory(MemReporter* memReporter) memReporter->EndSection(); } - - memReporter->AddVec("Params", mParams, false); + + memReporter->AddVec("Params", mParams, false); if (!mDefaultValues.IsEmpty()) memReporter->AddVec("DefaultValues", mDefaultValues, false); - + memReporter->EndSection(); } @@ -1690,11 +1687,11 @@ BfModuleMethodInstance::BfModuleMethodInstance(BfMethodInstance* methodInstance) mFunc = BfIRValue(); // if (methodInstance->GetImportCallKind() == BfImportCallKind_Thunk) // { -// auto declModule = methodInstance->mDeclModule; +// auto declModule = methodInstance->mDeclModule; // BfIRValue* irFuncPtr = NULL; // if (declModule->mFuncReferences.TryGetValue(methodInstance, &irFuncPtr)) // mFunc = *irFuncPtr; -// } +// } } ////////////////////////////////////////////////////////////////////////// @@ -1724,7 +1721,7 @@ BfMethodInstanceGroup::BfMethodInstanceGroup(BfMethodInstanceGroup&& prev) noexc for (auto& pair : *mMethodSpecializationMap) pair.mValue->mMethodInstanceGroup = this; } - + prev.mDefaultCustomAttributes = NULL; prev.mRefCount = 0; prev.mDefault = NULL; @@ -1803,12 +1800,12 @@ int BfTypeInstance::GetSplatCount() } bool BfTypeInstance::IsString() -{ +{ return IsInstanceOf(mContext->mCompiler->mStringTypeDef); } int BfTypeInstance::GetOrigVTableSize() -{ +{ if (!mModule->mCompiler->mOptions.mHasVDataExtender) { BF_ASSERT(mHotTypeData == NULL); @@ -1823,7 +1820,7 @@ int BfTypeInstance::GetOrigVTableSize() } if (mBaseType != NULL) return mBaseType->GetOrigVTableSize() + (mVirtualMethodTableSize - mBaseType->mVirtualMethodTableSize); - return mVirtualMethodTableSize; + return mVirtualMethodTableSize; } int BfTypeInstance::GetSelfVTableSize() @@ -1837,7 +1834,7 @@ int BfTypeInstance::GetSelfVTableSize() } int BfTypeInstance::GetOrigSelfVTableSize() -{ +{ if (mBaseType != NULL) return GetOrigVTableSize() - GetOrigImplBaseVTableSize(); return GetOrigVTableSize(); @@ -1880,14 +1877,14 @@ BfType* BfTypeInstance::GetUnionInnerType(bool* wantSplat) *wantSplat = false; if (!mIsUnion) - return NULL; + return NULL; BfTypeState typeState(this, mContext->mCurTypeState); typeState.mPopulateType = BfPopulateType_Data; SetAndRestoreValue prevTypeState(mContext->mCurTypeState, &typeState); int unionSize = 0; - BfType* unionInnerType = NULL; + BfType* unionInnerType = NULL; bool makeRaw = false; for (int fieldIdx = 0; fieldIdx < (int)mFieldInstances.size(); fieldIdx++) { @@ -1906,8 +1903,8 @@ BfType* BfTypeInstance::GetUnionInnerType(bool* wantSplat) } if (fieldInstance->mDataIdx >= 0) - { - checkInnerType = fieldInstance->mResolvedType; + { + checkInnerType = fieldInstance->mResolvedType; } if (checkInnerType != NULL) @@ -1916,10 +1913,10 @@ BfType* BfTypeInstance::GetUnionInnerType(bool* wantSplat) mModule->PopulateType(checkInnerType, checkInnerType->IsValueType() ? BfPopulateType_Data : BfPopulateType_Declaration); if (checkInnerType->mSize > unionSize) - unionSize = checkInnerType->mSize; + unionSize = checkInnerType->mSize; if ((!checkInnerType->IsValuelessType()) && (checkInnerType != unionInnerType)) - { + { if (unionInnerType == NULL) { unionInnerType = checkInnerType; @@ -1947,10 +1944,10 @@ BfType* BfTypeInstance::GetUnionInnerType(bool* wantSplat) unionInnerType = NULL; makeRaw = true; } - } + } } } - } + } } BF_ASSERT(unionInnerType != this); @@ -1962,7 +1959,7 @@ BfType* BfTypeInstance::GetUnionInnerType(bool* wantSplat) *wantSplat = true; } else - { + { switch (unionSize) { case 0: return mModule->CreateSizedArrayType(mModule->GetPrimitiveType(BfTypeCode_Int8), 0); @@ -2014,7 +2011,7 @@ void BfTypeInstance::GetUnderlyingArray(BfType*& type, int& size, bool& isVector if (attributes->mCtorArgs.size() != 3) return; - auto typeConstant = mConstHolder->GetConstant(attributes->mCtorArgs[0]); + auto typeConstant = mConstHolder->GetConstant(attributes->mCtorArgs[0]); auto sizeConstant = mConstHolder->GetConstant(attributes->mCtorArgs[1]); auto isVectorConstant = mConstHolder->GetConstant(attributes->mCtorArgs[2]); if ((typeConstant == NULL) || (sizeConstant == NULL) || (isVectorConstant == NULL)) @@ -2041,7 +2038,7 @@ bool BfTypeInstance::GetLoweredType(BfTypeUsage typeUsage, BfTypeCode* outTypeCo // Odd Windows rule: composite returns for non-static methods are always sret if (typeUsage == BfTypeUsage_Return_NonStatic) return false; - } + } else { // Non-Win64 systems allow lowered splitting of composites over multiple params @@ -2066,7 +2063,7 @@ bool BfTypeInstance::GetLoweredType(BfTypeUsage typeUsage, BfTypeCode* outTypeCo { if ((mInstSize >= 4) && (mInstSize <= maxInstSize)) { - BfTypeCode types[8] = { BfTypeCode_None }; + BfTypeCode types[8] = { BfTypeCode_None }; std::function _CheckType = [&](BfType* type, int offset) { @@ -2085,13 +2082,13 @@ bool BfTypeInstance::GetLoweredType(BfTypeUsage typeUsage, BfTypeCode* outTypeCo } else { - types[offset / 4] = BfTypeCode_Object; + types[offset / 4] = BfTypeCode_Object; } } else if (type->IsPrimitiveType()) { auto primType = (BfPrimitiveType*)type; - types[offset / 4] = primType->mTypeDef->mTypeCode; + types[offset / 4] = primType->mTypeDef->mTypeCode; } else if (type->IsSizedArray()) { @@ -2291,19 +2288,19 @@ bool BfTypeInstance::GetLoweredType(BfTypeUsage typeUsage, BfTypeCode* outTypeCo BfTypeCode typeCode = BfTypeCode_None; BfTypeCode pow2TypeCode = BfTypeCode_None; - + switch (mInstSize) { - case 1: + case 1: pow2TypeCode = BfTypeCode_Int8; break; - case 2: + case 2: pow2TypeCode = BfTypeCode_Int16; break; case 3: typeCode = BfTypeCode_Int24; break; - case 4: + case 4: pow2TypeCode = BfTypeCode_Int32; break; case 5: @@ -2315,7 +2312,7 @@ bool BfTypeInstance::GetLoweredType(BfTypeUsage typeUsage, BfTypeCode* outTypeCo case 7: typeCode = BfTypeCode_Int56; break; - case 8: + case 8: if (mModule->mSystem->mPtrSize == 8) { pow2TypeCode = BfTypeCode_Int64; @@ -2326,7 +2323,7 @@ bool BfTypeInstance::GetLoweredType(BfTypeUsage typeUsage, BfTypeCode* outTypeCo pow2TypeCode = BfTypeCode_Int64; break; } - break; + break; } if (pow2TypeCode != BfTypeCode_None) @@ -2335,7 +2332,7 @@ bool BfTypeInstance::GetLoweredType(BfTypeUsage typeUsage, BfTypeCode* outTypeCo *outTypeCode = pow2TypeCode; return true; } - + if ((mModule->mCompiler->mOptions.mPlatformType != BfPlatformType_Windows) && (mModule->mSystem->mPtrSize == 8)) { if (typeCode != BfTypeCode_None) @@ -2405,7 +2402,7 @@ bool BfTypeInstance::GetResultInfo(BfType*& valueType, int& okTagId) { valueType = tupleType->mFieldInstances[0].mResolvedType; okTagId = -fieldInstance.mDataIdx - 1; - return true; + return true; } } break; @@ -2420,7 +2417,7 @@ void BfTypeInstance::ReportMemory(MemReporter* memReporter) memReporter->Add(sizeof(BfTypeInstance)); - int depSize = 0; + int depSize = 0; depSize += sizeof((int)mDependencyMap.mTypeSet.mAllocSize * sizeof(BfDependencyMap::TypeMap::EntryPair)); memReporter->Add("DepMap", depSize); memReporter->AddVec(mInterfaces, false); @@ -2428,12 +2425,12 @@ void BfTypeInstance::ReportMemory(MemReporter* memReporter) if (mCustomAttributes != NULL) mCustomAttributes->ReportMemory(memReporter); - + int methodCount = 0; memReporter->BeginSection("MethodData"); for (auto& methodInstGroup : mMethodInstanceGroups) { - memReporter->Add(sizeof(BfMethodInstanceGroup)); + memReporter->Add(sizeof(BfMethodInstanceGroup)); if (methodInstGroup.mDefault != NULL) { methodInstGroup.mDefault->ReportMemory(memReporter); @@ -2446,7 +2443,7 @@ void BfTypeInstance::ReportMemory(MemReporter* memReporter) { methodCount++; kv.mValue->ReportMemory(memReporter); - } + } } } memReporter->EndSection(); @@ -2457,17 +2454,17 @@ void BfTypeInstance::ReportMemory(MemReporter* memReporter) memReporter->AddMap("SpecializedMethodReferences", mSpecializedMethodReferences, false); memReporter->AddMap("LookupResults", mLookupResults, false); if (mConstHolder != NULL) - memReporter->Add("ConstHolder", mConstHolder->mTempAlloc.GetTotalAllocSize()); + memReporter->Add("ConstHolder", mConstHolder->mTempAlloc.GetTotalAllocSize()); if (mHotTypeData != NULL) { AutoMemReporter autoMemReporter(memReporter, "HotTypeData"); - memReporter->Add(sizeof(BfHotTypeData)); + memReporter->Add(sizeof(BfHotTypeData)); memReporter->AddVec(mHotTypeData->mTypeVersions, false); for (auto typeVersion : mHotTypeData->mTypeVersions) { memReporter->AddVec(typeVersion->mMembers, false); - memReporter->AddVec(typeVersion->mInterfaceMapping, false); + memReporter->AddVec(typeVersion->mInterfaceMapping, false); } memReporter->AddVec(mHotTypeData->mVTableEntries, false); for (auto& entry : mHotTypeData->mVTableEntries) @@ -2478,12 +2475,12 @@ void BfTypeInstance::ReportMemory(MemReporter* memReporter) } bool BfTypeInstance::IsTypeMemberAccessible(BfTypeDef* declaringTypeDef, BfTypeDef* activeTypeDef) -{ +{ if (activeTypeDef == NULL) return false; if (declaringTypeDef == activeTypeDef) return true; - return activeTypeDef->mProject->ContainsReference(declaringTypeDef->mProject); + return activeTypeDef->mProject->ContainsReference(declaringTypeDef->mProject); } bool BfTypeInstance::IsTypeMemberAccessible(BfTypeDef* declaringTypeDef, BfProject* curProject) @@ -2503,10 +2500,10 @@ bool BfTypeInstance::IsTypeMemberAccessible(BfTypeDef* declaringTypeDef, BfProje bool BfTypeInstance::WantsGCMarking() { BF_ASSERT(mTypeDef->mTypeCode != BfTypeCode_Extension); - if (IsObjectOrInterface()) - return true; + if (IsObjectOrInterface()) + return true; if ((IsEnum()) && (!IsPayloadEnum())) - return false; + return false; BF_ASSERT((mDefineState >= BfTypeDefineState_Defined) || (mTypeFailed)); return mWantsGCMarking; } @@ -2542,7 +2539,7 @@ BfGenericTypeInfo::GenericParamsVector* BfTypeInstance::GetGenericParamsVector(B BfGenericExtensionEntry* genericExEntry = NULL; if (mGenericTypeInfo->mGenericExtensionInfo->mExtensionMap.TryGetValue(declaringTypeDef, &genericExEntry)) return &genericExEntry->mGenericParams; - + return &mGenericTypeInfo->mGenericParams; } @@ -2561,7 +2558,7 @@ bool BfTypeInstance::IsAlwaysInclude() bool alwaysInclude = mTypeDef->mIsAlwaysInclude || mTypeDef->mProject->mAlwaysIncludeAll; if (mTypeOptionsIdx > 0) { - auto typeOptions = mModule->mSystem->GetTypeOptions(mTypeOptionsIdx); + auto typeOptions = mModule->mSystem->GetTypeOptions(mTypeOptionsIdx); typeOptions->Apply(alwaysInclude, BfOptionFlags_ReflectAlwaysIncludeType); } if ((mAlwaysIncludeFlags & BfAlwaysIncludeFlag_Type) != 0) @@ -2588,7 +2585,7 @@ bool BfTypeInstance::IsSpecializedByAutoCompleteMethod() } bool BfTypeInstance::IsNullable() -{ +{ return IsInstanceOf(mContext->mCompiler->mNullableTypeDef); } @@ -2605,7 +2602,7 @@ bool BfTypeInstance::HasVarConstraints() } bool BfTypeInstance::IsTypeMemberIncluded(BfTypeDef* typeDef, BfTypeDef* activeTypeDef, BfModule* module) -{ +{ if (mGenericTypeInfo == NULL) return true; if (mGenericTypeInfo->mGenericExtensionInfo == NULL) @@ -2616,7 +2613,7 @@ bool BfTypeInstance::IsTypeMemberIncluded(BfTypeDef* typeDef, BfTypeDef* activeT // The combined type declaration is the root type declaration, it's implicitly included if (typeDef->mTypeDeclaration == mTypeDef->mTypeDeclaration) return true; - + BfGenericExtensionEntry* genericExEntry = NULL; if (!mGenericTypeInfo->mGenericExtensionInfo->mExtensionMap.TryGetValue(typeDef, &genericExEntry)) return true; @@ -2648,12 +2645,12 @@ bool BfTypeInstance::IsTypeMemberIncluded(BfTypeDef* typeDef, BfTypeDef* activeT return true; } - + return genericExEntry->mConstraintsPassed; } void BfGenericTypeInfo::ReportMemory(MemReporter* memReporter) -{ +{ memReporter->Add(sizeof(BfGenericTypeInfo)); memReporter->AddVec(mTypeGenericArguments, false); memReporter->AddVec(mGenericParams, false); @@ -2698,12 +2695,12 @@ bool BfTypeInstance::IsValuelessType() return false; } if (mTypeDef->mIsOpaque) - return false; - + return false; + BF_ASSERT(mDefineState >= BfTypeDefineState_Defined); BF_ASSERT(mInstSize >= 0); if (mInstSize == 0) - { + { return true; } @@ -2748,7 +2745,7 @@ void BfTypeInstance::CalcHotVirtualData(Array* ifaceMapping) if (slotNum >= (int)ifaceMapping->size()) ifaceMapping->Resize(slotNum + 1); (*ifaceMapping)[slotNum] = iface.mInterfaceType->mTypeId; - } + } } if (mBaseType != NULL) mBaseType->CalcHotVirtualData(ifaceMapping); @@ -2759,7 +2756,7 @@ void BfTypeInstance::CalcHotVirtualData(Array* ifaceMapping) BfClosureType::BfClosureType(BfTypeInstance* srcDelegate, Val128 closureHash) : mSource(srcDelegate->mTypeDef->mSystem) -{ +{ BF_ASSERT(srcDelegate->IsDelegate()); mSrcDelegate = srcDelegate; mTypeDef = mSrcDelegate->mTypeDef; @@ -2789,21 +2786,21 @@ void BfClosureType::Init(BfProject* bfProject) mTypeDef = new BfTypeDef(); mTypeDef->mSystem = system; - mTypeDef->mSource = &mSource; + mTypeDef->mSource = &mSource; mTypeDef->mSource->mRefCount++; mTypeDef->mProject = bfProject; - mTypeDef->mTypeCode = srcTypeDef->mTypeCode; - mTypeDef->mName = system->GetAtom(srcTypeDef->mName->mString + mNameAdd); + mTypeDef->mTypeCode = srcTypeDef->mTypeCode; + mTypeDef->mName = system->GetAtom(srcTypeDef->mName->mString + mNameAdd); // Purposely leave out 'mOuterType' - this fails if the outer type is generic //mTypeDef->mOuterType = srcTypeDef->mOuterType; mTypeDef->mNamespace = srcTypeDef->mNamespace; system->AddNamespaceUsage(mTypeDef->mNamespace, mTypeDef->mProject); mTypeDef->mHash = srcTypeDef->mHash; - mTypeDef->mSignatureHash = srcTypeDef->mSignatureHash; + mTypeDef->mSignatureHash = srcTypeDef->mSignatureHash; // mTypeDef->mFullName = srcTypeDef->mFullName; // if (!mTypeDef->mFullName.mParts.IsEmpty()) // mTypeDef->mFullName.mParts.pop_back(); -// mTypeDef->mFullName.mParts.push_back(mTypeDef->mName); +// mTypeDef->mFullName.mParts.push_back(mTypeDef->mName); if (srcTypeDef->mFullName.mSize > 0) mTypeDef->mFullName.Set(srcTypeDef->mFullName.mParts, srcTypeDef->mFullName.mSize - 1, &mTypeDef->mName, 1); else @@ -2812,7 +2809,7 @@ void BfClosureType::Init(BfProject* bfProject) mTypeDef->mTypeCode = BfTypeCode_Object; mTypeDef->mIsDelegate = true; - mTypeDef->mIsClosure = true; + mTypeDef->mIsClosure = true; mTypeDef->mDefState = BfTypeDef::DefState_Defined; auto baseDirectTypeRef = BfAstNode::ZeroedAlloc(); @@ -2853,7 +2850,7 @@ void BfClosureType::Finish() ////////////////////////////////////////////////////////////////////////// BfDelegateType::~BfDelegateType() -{ +{ mMethodInstanceGroups.Clear(); delete mTypeDef; mTypeDef = NULL; @@ -2872,7 +2869,7 @@ BfTupleType::BfTupleType() { mCreatedTypeDef = false; mSource = NULL; - mTypeDef = NULL; + mTypeDef = NULL; mIsUnspecializedType = false; mIsUnspecializedTypeVariation = false; mGenericDepth = 0; @@ -2890,7 +2887,7 @@ BfTupleType::~BfTupleType() } void BfTupleType::Init(BfProject* bfProject, BfTypeInstance* valueTypeInstance) -{ +{ auto srcTypeDef = valueTypeInstance->mTypeDef; auto system = valueTypeInstance->mModule->mSystem; @@ -2899,17 +2896,17 @@ void BfTupleType::Init(BfProject* bfProject, BfTypeInstance* valueTypeInstance) for (auto field : mTypeDef->mFields) delete field; mTypeDef->mFields.Clear(); - mTypeDef->mSystem = system; + mTypeDef->mSystem = system; mTypeDef->mProject = bfProject; mTypeDef->mTypeCode = srcTypeDef->mTypeCode; mTypeDef->mName = system->mEmptyAtom; mTypeDef->mSystem = system; - + mTypeDef->mHash = srcTypeDef->mHash; - mTypeDef->mSignatureHash = srcTypeDef->mSignatureHash; + mTypeDef->mSignatureHash = srcTypeDef->mSignatureHash; mTypeDef->mTypeCode = BfTypeCode_Struct; - - mCreatedTypeDef = true; + + mCreatedTypeDef = true; } void BfTupleType::Dispose() @@ -2931,7 +2928,7 @@ BfFieldDef* BfTupleType::AddField(const StringImpl& name) void BfTupleType::Finish() { BF_ASSERT(!mTypeFailed); - + auto bfSystem = mTypeDef->mSystem; mSource = new BfSource(bfSystem); mTypeDef->mSource = mSource; @@ -2952,13 +2949,13 @@ BfBoxedType::~BfBoxedType() } BfType* BfBoxedType::GetModifiedElementType() -{ +{ if ((mBoxedFlags & BoxedFlags_StructPtr) != 0) { auto module = mModule; if (module == NULL) - module = mContext->mUnreifiedModule; - return module->CreatePointerType(mElementType); + module = mContext->mUnreifiedModule; + return module->CreatePointerType(mElementType); } return mElementType; } @@ -3008,7 +3005,7 @@ int BfMethodRefType::GetParamIdxFromDataIdx(int dataIdx) } bool BfMethodRefType::WantsDataPassedAsSplat(int dataIdx) -{ +{ if (dataIdx != -1) return false; return mMethodRef->GetParamIsSplat(mDataToParamIdx[dataIdx]); @@ -3017,7 +3014,7 @@ bool BfMethodRefType::WantsDataPassedAsSplat(int dataIdx) ////////////////////////////////////////////////////////////////////////// size_t BfTypeVectorHash::operator()(const BfTypeVector& typeVec) const -{ +{ size_t hash = typeVec.size(); BfResolvedTypeSet::LookupContext ctx; for (auto type : typeVec) @@ -3072,7 +3069,6 @@ BfCustomAttribute* BfCustomAttributes::Get(int idx) BfResolvedTypeSet::~BfResolvedTypeSet() { - } #define HASH_MIX(origHashVal, newHashVal) ((((origHashVal) << 5) - (origHashVal)) ^ (newHashVal)) @@ -3094,14 +3090,14 @@ BfResolvedTypeSet::~BfResolvedTypeSet() BfVariant BfResolvedTypeSet::EvaluateToVariant(LookupContext* ctx, BfExpression* expr, BfType*& outType) { - outType = NULL; + outType = NULL; BfConstResolver constResolver(ctx->mModule); - BfVariant variant; + BfVariant variant; constResolver.mBfEvalExprFlags = BfEvalExprFlags_NoCast; constResolver.mBfEvalExprFlags = (BfEvalExprFlags)(constResolver.mBfEvalExprFlags | BfEvalExprFlags_AllowGenericConstValue); constResolver.mExpectingType = ctx->mModule->GetPrimitiveType(BfTypeCode_Int64); - auto result = constResolver.Resolve(expr); + auto result = constResolver.Resolve(expr); if (result) { // Limit the types of constants to prevent duplicate values with different types - we don't want to hash a typeref with an int32 @@ -3115,9 +3111,9 @@ BfVariant BfResolvedTypeSet::EvaluateToVariant(LookupContext* ctx, BfExpression* outType = result.mType; if (result.mKind == BfTypedValueKind_GenericConstValue) - { + { return variant; - } + } else { variant = ctx->mModule->TypedValueToVariant(expr, result, true); @@ -3141,8 +3137,8 @@ int BfResolvedTypeSet::DoHash(BfType* type, LookupContext* ctx, bool allowRef, i // } // return Hash(underlyingType, ctx, allowRef); // } -// else - +// else + if (type->IsBoxed()) { BfBoxedType* boxedType = (BfBoxedType*)type; @@ -3154,14 +3150,14 @@ int BfResolvedTypeSet::DoHash(BfType* type, LookupContext* ctx, bool allowRef, i BfArrayType* arrayType = (BfArrayType*)type; int elemHash = Hash(arrayType->mGenericTypeInfo->mTypeGenericArguments[0], ctx, BfHashFlag_None, hashSeed) ^ (arrayType->mDimensions << 8); return (elemHash << 5) - elemHash; - } + } else if (type->IsDelegateFromTypeRef() || type->IsFunctionFromTypeRef()) - { + { auto typeInst = (BfTypeInstance*)type; int hashVal = HASH_DELEGATE; - + auto delegateInfo = type->GetDelegateInfo(); - + hashVal = HASH_MIX(hashVal, Hash(delegateInfo->mReturnType, ctx, BfHashFlag_None, hashSeed + 1)); auto methodDef = typeInst->mTypeDef->mMethods[0]; @@ -3174,19 +3170,19 @@ int BfResolvedTypeSet::DoHash(BfType* type, LookupContext* ctx, bool allowRef, i BF_ASSERT(infoParamCount == methodDef->mParams.size()); for (int paramIdx = 0; paramIdx < delegateInfo->mParams.size(); paramIdx++) - { + { // Parse attributes? hashVal = HASH_MIX(hashVal, Hash(delegateInfo->mParams[paramIdx], ctx, BfHashFlag_None, hashSeed + 1)); String paramName = methodDef->mParams[paramIdx]->mName; int nameHash = (int)Hash64(paramName.c_str(), (int)paramName.length()); hashVal = HASH_MIX(hashVal, nameHash); } - + if (delegateInfo->mHasVarArgs) hashVal = HASH_MIX(hashVal, HASH_DOTDOTDOT); return hashVal; - } + } else if (type->IsTypeInstance()) { BfTypeInstance* typeInst = (BfTypeInstance*)type; @@ -3200,7 +3196,7 @@ int BfResolvedTypeSet::DoHash(BfType* type, LookupContext* ctx, bool allowRef, i if (closureType->mIsUnique) return false; hashVal = ((hashVal ^ (int)closureType->mClosureHash.mLow) << 5) - hashVal; - } + } else if (type->IsTuple()) { hashVal = HASH_VAL_TUPLE; @@ -3209,8 +3205,8 @@ int BfResolvedTypeSet::DoHash(BfType* type, LookupContext* ctx, bool allowRef, i for (int fieldIdx = 0; fieldIdx < (int)tupleType->mFieldInstances.size(); fieldIdx++) { BfFieldInstance* fieldInstance = &tupleType->mFieldInstances[fieldIdx]; - - auto fieldType = fieldInstance->mResolvedType; + + auto fieldType = fieldInstance->mResolvedType; hashVal = HASH_MIX(hashVal, Hash(fieldType, ctx, BfHashFlag_None, hashSeed + 1)); BfFieldDef* fieldDef = NULL; @@ -3224,7 +3220,7 @@ int BfResolvedTypeSet::DoHash(BfType* type, LookupContext* ctx, bool allowRef, i nameHash = (int)Hash64(nameStr, strlen(nameStr)); } else - { + { nameHash = (int)Hash64(fieldDef->mName.c_str(), (int)fieldDef->mName.length()); } hashVal = HASH_MIX(hashVal, nameHash); @@ -3233,7 +3229,7 @@ int BfResolvedTypeSet::DoHash(BfType* type, LookupContext* ctx, bool allowRef, i else if (type->IsGenericTypeInstance()) { BfTypeInstance* genericType = (BfTypeInstance*)type; - for (auto genericArg : genericType->mGenericTypeInfo->mTypeGenericArguments) + for (auto genericArg : genericType->mGenericTypeInfo->mTypeGenericArguments) hashVal = HASH_MIX(hashVal, Hash(genericArg, ctx, BfHashFlag_None, hashSeed + 1)); } return hashVal; @@ -3242,7 +3238,7 @@ int BfResolvedTypeSet::DoHash(BfType* type, LookupContext* ctx, bool allowRef, i { BfPrimitiveType* primType = (BfPrimitiveType*)type; return primType->mTypeDef->mHash; - } + } else if (type->IsPointer()) { BfPointerType* pointerType = (BfPointerType*) type; @@ -3259,7 +3255,7 @@ int BfResolvedTypeSet::DoHash(BfType* type, LookupContext* ctx, bool allowRef, i auto refType = (BfRefType*)type; int elemHash = Hash(refType->mElementType, ctx, BfHashFlag_None, hashSeed) ^ (HASH_VAL_REF + (int)refType->mRefKind); return (elemHash << 5) - elemHash; - } + } else if (type->IsModifiedTypeType()) { auto modifiedTypeType = (BfModifiedTypeType*)type; @@ -3287,15 +3283,15 @@ int BfResolvedTypeSet::DoHash(BfType* type, LookupContext* ctx, bool allowRef, i hashVal = ((hashVal ^ (int)sizedArray->mElementCount) << 5) - hashVal; return hashVal; - } + } else if (type->IsMethodRef()) - { + { auto methodRefType = (BfMethodRefType*)type; if (methodRefType->IsNull()) return 0; return (int)((int)(intptr)(methodRefType->mMethodRef) << 5) ^ (int)(intptr)(methodRefType->mOwner) ^ methodRefType->mOwnerRevision; - } + } else if (type->IsConstExprValue()) { BfConstExprValueType* constExprValueType = (BfConstExprValueType*)type; @@ -3327,8 +3323,8 @@ void BfResolvedTypeSet::HashGenericArguments(BfTypeReference* typeRef, LookupCon bool allowUnboundGeneric = ((ctx->mResolveFlags & BfResolveTypeRefFlag_AllowUnboundGeneric) != 0) && (hashSeed == 0); BfAstNode* genericArgTypeRef = NULL; - if (genericIdx < genericTypeRef->mGenericArguments.mSize) - genericArgTypeRef = genericTypeRef->mGenericArguments[genericIdx]; + if (genericIdx < genericTypeRef->mGenericArguments.mSize) + genericArgTypeRef = genericTypeRef->mGenericArguments[genericIdx]; if (allowUnboundGeneric) { @@ -3350,7 +3346,7 @@ void BfResolvedTypeSet::HashGenericArguments(BfTypeReference* typeRef, LookupCon { ctx->mIsUnboundGeneric = true; argHashVal = (((int)BfGenericParamKind_Type + 0xB00) << 8) ^ (genericIdx + 1); - argHashVal = HASH_MIX(argHashVal, hashSeed + 1); + argHashVal = HASH_MIX(argHashVal, hashSeed + 1); } else { @@ -3359,7 +3355,7 @@ void BfResolvedTypeSet::HashGenericArguments(BfTypeReference* typeRef, LookupCon return; } } - + hashVal = HASH_MIX(hashVal, argHashVal); } } @@ -3385,7 +3381,7 @@ BfResolveTypeRefFlags BfResolvedTypeSet::GetResolveFlags(BfAstNode* typeRef, Loo } int BfResolvedTypeSet::DirectHash(BfTypeReference* typeRef, LookupContext* ctx, BfHashFlags flags, int hashSeed) -{ +{ auto resolvedType = ctx->mModule->ResolveTypeRef(typeRef, BfPopulateType_Identity, GetResolveFlags(typeRef, ctx, flags)); if (resolvedType == NULL) { @@ -3426,11 +3422,11 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa { if ((typeRef == ctx->mRootTypeRef) && (ctx->mRootTypeDef != NULL) && ((typeRef->IsNamedTypeReference()) || (BfNodeIsA(typeRef)))) - { + { BfTypeDef* typeDef = ctx->mRootTypeDef; - + int hashVal = typeDef->mHash; - + if (typeDef->mGenericParamDefs.size() != 0) { auto checkTypeInstance = ctx->mModule->mCurTypeInstance; @@ -3438,7 +3434,7 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa checkTypeInstance = checkTypeInstance->GetUnderlyingType()->ToTypeInstance(); auto outerType = ctx->mModule->mSystem->GetOuterTypeNonPartial(typeDef); - + BfTypeDef* commonOuterType; if (typeRef == ctx->mRootTypeRef) commonOuterType = FindRootCommonOuterType(outerType, ctx, checkTypeInstance); @@ -3469,12 +3465,12 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa ctx->mFailed = true; return 0; } - + BF_ASSERT(checkTypeInstance->IsGenericTypeInstance()); auto curGenericTypeInst = (BfTypeInstance*)checkTypeInstance; int numParentGenericParams = (int)commonOuterType->mGenericParamDefs.size(); for (int i = 0; i < numParentGenericParams; i++) - { + { hashVal = HASH_MIX(hashVal, Hash(curGenericTypeInst->mGenericTypeInfo->mTypeGenericArguments[i], ctx, BfHashFlag_None, hashSeed + 1)); } } @@ -3511,14 +3507,14 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa } else if (elementTypeDef->mTypeCode == BfTypeCode_TypeAlias) { - isInnerTypeAlias = true; + isInnerTypeAlias = true; } - + BfTypeVector typeAliasGenericArgs; bool fullyQualified = false; int hashVal = elementTypeDef->mHash; - + BfTypeInstance* outerType = NULL; int checkIdx = 0; @@ -3531,7 +3527,7 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa fullyQualified = true; if ((elementTypeDef->mOuterType != NULL) && (!elementTypeDef->mOuterType->mGenericParamDefs.IsEmpty())) { - auto resolvedType = ctx->mModule->ResolveTypeRef(checkTypeRef, BfPopulateType_Identity, + auto resolvedType = ctx->mModule->ResolveTypeRef(checkTypeRef, BfPopulateType_Identity, (BfResolveTypeRefFlags)(GetResolveFlags(checkTypeRef, ctx, flags) | BfResolveTypeRefFlag_IgnoreLookupError)); if (resolvedType == NULL) { @@ -3554,12 +3550,12 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa { checkTypeRef = qualifiedTypeRef->mLeft; continue; - } + } break; } - + if (fullyQualified) - { + { if (outerType != NULL) { for (auto genericArg : outerType->mGenericTypeInfo->mTypeGenericArguments) @@ -3599,7 +3595,7 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa } if (isInnerTypeAlias) - { + { for (auto genericArgTypeRef : genericInstTypeRef->mGenericArguments) { auto argType = ctx->mModule->ResolveTypeRef(genericArgTypeRef, NULL, BfPopulateType_Identity, GetResolveFlags(genericArgTypeRef, ctx, flags)); @@ -3637,10 +3633,10 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa for (int fieldIdx = 0; fieldIdx < (int)tupleTypeRef->mFieldTypes.size(); fieldIdx++) { - BfTypeReference* fieldType = tupleTypeRef->mFieldTypes[fieldIdx]; + BfTypeReference* fieldType = tupleTypeRef->mFieldTypes[fieldIdx]; hashVal = HASH_MIX(hashVal, Hash(fieldType, ctx, BfHashFlag_None, hashSeed + 1)); - int nameHash = 0; + int nameHash = 0; BfIdentifierNode* fieldName = NULL; if (fieldIdx < (int)tupleTypeRef->mFieldNames.size()) fieldName = tupleTypeRef->mFieldNames[fieldIdx]; @@ -3692,7 +3688,7 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa constResolver.mBfEvalExprFlags = (BfEvalExprFlags)(constResolver.mBfEvalExprFlags | BfEvalExprFlags_AllowGenericConstValue); constResolver.mExpectingType = intType; BfTypedValue typedVal = constResolver.Resolve(sizeExpr, NULL, BfConstResolveFlag_ArrayInitSize); - + if (typedVal.mKind == BfTypedValueKind_GenericConstValue) { ctx->mResolvedValueMap[sizeExpr] = typedVal; @@ -3708,7 +3704,7 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa typedVal = ctx->mModule->Cast(sizeExpr, typedVal, intType); } ctx->mResolvedValueMap[sizeExpr] = typedVal; - + if (typedVal) { auto constant = ctx->mModule->mBfIRBuilder->GetConstant(typedVal.mValue); @@ -3741,8 +3737,8 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa } } } - } - + } + hashVal = ((hashVal ^ (int)elementCount) << 5) - hashVal; return hashVal; } @@ -3769,7 +3765,7 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa } } else if (auto pointerType = BfNodeDynCastExact(typeRef)) - { + { int elemHash = Hash(pointerType->mElementType, ctx, BfHashFlag_None, hashSeed) ^ HASH_VAL_PTR; return (elemHash << 5) - elemHash; } @@ -3778,10 +3774,10 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa if (ctx->mRootTypeRef == typeRef) ctx->mRootTypeDef = ctx->mModule->mCompiler->mNullableTypeDef; - int hashVal = ctx->mModule->mCompiler->mNullableTypeDef->mHash; + int hashVal = ctx->mModule->mCompiler->mNullableTypeDef->mHash; hashVal = HASH_MIX(hashVal, Hash(nullableType->mElementType, ctx, BfHashFlag_None, hashSeed + 1)); return hashVal; - } + } else if (auto refType = BfNodeDynCastExact(typeRef)) { if ((flags & BfHashFlag_AllowRef) != 0) @@ -3800,10 +3796,10 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa return (elemHash << 5) - elemHash; } else - { + { ctx->mModule->ResolveTypeRef(typeRef, BfPopulateType_Identity, GetResolveFlags(typeRef, ctx, flags)); // To throw an error... ctx->mFailed = true; - return 0; + return 0; //return Hash(refType->mElementType, ctx); } } @@ -3849,7 +3845,7 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa // Don't allow 'var' ctx->mModule->Fail("Invalid use of 'var'", typeRef); ctx->mFailed = true; - return 0; + return 0; } else if (auto letType = BfNodeDynCastExact(typeRef)) { @@ -3859,7 +3855,7 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa return 0; } else if (auto retTypeTypeRef = BfNodeDynCastExact(typeRef)) - { + { // Don't cause infinite loop, but if we have an inner 'rettype' then try to directly resolve that -- // Only use the HAS_RETTYPE for root-level rettype insertions if (ctx->mRootTypeRef != retTypeTypeRef) @@ -3886,7 +3882,7 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa { // We purposely don't mix in a HASH_CONSTTYPE because there's no such thing as a const type in Beef, so we just strip it return Hash(constTypeRef->mElementType, ctx, flags, hashSeed); - } + } else if (auto delegateTypeRef = BfNodeDynCastExact(typeRef)) { int hashVal = HASH_DELEGATE; @@ -3894,10 +3890,10 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa hashVal = HASH_MIX(hashVal, Hash(delegateTypeRef->mReturnType, ctx, BfHashFlag_AllowRef, hashSeed + 1)); else ctx->mFailed = true; - + bool isFirstParam = true; - for (int paramIdx = 0; paramIdx < delegateTypeRef->mParams.size(); paramIdx++) + for (int paramIdx = 0; paramIdx < delegateTypeRef->mParams.size(); paramIdx++) { auto param = delegateTypeRef->mParams[paramIdx]; // Parse attributes? @@ -3917,13 +3913,13 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa if (auto dotTypeRef = BfNodeDynCastExact(fieldType)) { if (dotTypeRef->mDotToken->mToken == BfToken_DotDotDot) - { + { hashVal = HASH_MIX(hashVal, HASH_DOTDOTDOT); continue; } } } - + if (fieldType != NULL) hashVal = HASH_MIX(hashVal, Hash(fieldType, ctx, (BfHashFlags)(BfHashFlag_AllowRef), hashSeed + 1)); hashVal = HASH_MIX(hashVal, HashNode(param->mNameNode)); @@ -3931,7 +3927,7 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa } return hashVal; - } + } else if (auto exprModTypeRef = BfNodeDynCastExact(typeRef)) { auto cachedResolvedType = ctx->GetCachedResolvedType(typeRef); @@ -3944,9 +3940,9 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa { BfMethodState methodState; SetAndRestoreValue prevMethodState(ctx->mModule->mCurMethodState, &methodState, false); - if (ctx->mModule->mCurMethodState == NULL) + if (ctx->mModule->mCurMethodState == NULL) prevMethodState.Set(); - methodState.mTempKind = BfMethodState::TempKind_NonStatic; + methodState.mTempKind = BfMethodState::TempKind_NonStatic; SetAndRestoreValue ignoreWrites(ctx->mModule->mBfIRBuilder->mIgnoreWrites, true); SetAndRestoreValue allowUninitReads(ctx->mModule->mCurMethodState->mAllowUinitReads, true); @@ -3962,7 +3958,7 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa auto typeType = ctx->mModule->ResolveTypeDef(ctx->mModule->mCompiler->mTypeTypeDef); exprFlags = (BfEvalExprFlags)(exprFlags | BfEvalExprFlags_Comptime | BfEvalExprFlags_NoCast); result = ctx->mModule->CreateValueFromExpression(exprModTypeRef->mTarget, typeType, exprFlags); - if ((result.mType != NULL) && (!result.mType->IsInteger()) && (result.mType != typeType) && + if ((result.mType != NULL) && (!result.mType->IsInteger()) && (result.mType != typeType) && (!result.mType->IsInstanceOf(ctx->mModule->mCompiler->mReflectTypeIdTypeDef))) result = ctx->mModule->Cast(exprModTypeRef->mTarget, result, typeType); } @@ -3971,9 +3967,9 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa result = ctx->mModule->CreateValueFromExpression(exprModTypeRef->mTarget, NULL, BfEvalExprFlags_DeclType); } } - + if ((result) && (exprModTypeRef->mToken->mToken == BfToken_Comptype)) - { + { auto constant = ctx->mModule->mBfIRBuilder->GetConstant(result.mValue); if (constant != NULL) { @@ -3983,7 +3979,7 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa cachedResolvedType = typeOf->mType; } else if (constant->mConstType == BfConstType_Undef) - { + { ctx->mHadVar = true; cachedResolvedType = ctx->mModule->GetPrimitiveType(BfTypeCode_Var); } @@ -4006,7 +4002,7 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa } } } - + if (cachedResolvedType == NULL) ctx->mModule->Fail("Constant System.Type value required", exprModTypeRef->mTarget); } @@ -4025,7 +4021,7 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa { ctx->mFailed = true; return 0; - } + } int hashVal = Hash(cachedResolvedType, ctx, flags, hashSeed); hashSeed = 0; @@ -4040,11 +4036,11 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa return 0; } - BfVariant result; + BfVariant result; BfType* resultType = NULL; if (constExprTypeRef->mConstExpr != NULL) { - result = EvaluateToVariant(ctx, constExprTypeRef->mConstExpr, resultType); + result = EvaluateToVariant(ctx, constExprTypeRef->mConstExpr, resultType); if ((resultType != NULL) && (resultType->IsGenericParam())) { int hashVal = Hash(resultType, ctx, BfHashFlag_None, hashSeed); @@ -4059,12 +4055,12 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa return 0; } - auto hashVal = ((int)result.mTypeCode << 17) ^ (result.mInt32 << 3) ^ HASH_CONSTTYPE; - hashVal = ((hashVal ^ (Hash(resultType, ctx, BfHashFlag_AllowRef, hashSeed))) << 5) - hashVal; + auto hashVal = ((int)result.mTypeCode << 17) ^ (result.mInt32 << 3) ^ HASH_CONSTTYPE; + hashVal = ((hashVal ^ (Hash(resultType, ctx, BfHashFlag_AllowRef, hashSeed))) << 5) - hashVal; return hashVal; } - else if (auto dotTypeRef = BfNodeDynCastExact(typeRef)) - { + else if (auto dotTypeRef = BfNodeDynCastExact(typeRef)) + { ctx->mModule->ResolveTypeRef(dotTypeRef, BfPopulateType_Identity, GetResolveFlags(dotTypeRef, ctx, flags)); ctx->mFailed = true; return 0; @@ -4102,7 +4098,7 @@ int BfResolvedTypeSet::Hash(BfAstNode* typeRefNode, LookupContext* ctx, BfHashFl } ctx->mResolvedTypeMap[typeRefNode] = result; - return Hash(result, ctx, false, hashSeed); + return Hash(result, ctx, false, hashSeed); } bool BfResolvedTypeSet::Equals(BfType* lhs, BfType* rhs, LookupContext* ctx) @@ -4126,13 +4122,13 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfType* rhs, LookupContext* ctx) if (lhsArrayType->mDimensions != rhsArrayType->mDimensions) return false; return lhsArrayType->mGenericTypeInfo->mTypeGenericArguments[0] == rhsArrayType->mGenericTypeInfo->mTypeGenericArguments[0]; - } + } else if (lhs->IsTypeInstance()) { if ((!rhs->IsTypeInstance()) || (rhs->IsBoxed())) return false; BfTypeInstance* lhsInst = (BfTypeInstance*)lhs; - BfTypeInstance* rhsInst = (BfTypeInstance*)rhs; + BfTypeInstance* rhsInst = (BfTypeInstance*)rhs; if (lhs->IsClosure()) { @@ -4146,13 +4142,13 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfType* rhs, LookupContext* ctx) return false; return lhsClosure->mClosureHash == rhsClosure->mClosureHash; } - + if (lhs->IsDelegateFromTypeRef() || lhs->IsFunctionFromTypeRef()) { if (!rhs->IsDelegateFromTypeRef() && !rhs->IsFunctionFromTypeRef()) return false; if (lhs->IsDelegate() != rhs->IsDelegate()) - return false; + return false; BfDelegateInfo* lhsDelegateInfo = lhs->GetDelegateInfo(); BfDelegateInfo* rhsDelegateInfo = rhs->GetDelegateInfo(); if (lhsInst->mTypeDef->mIsDelegate != rhsInst->mTypeDef->mIsDelegate) @@ -4180,7 +4176,7 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfType* rhs, LookupContext* ctx) } return true; } - + if (lhs->IsTuple()) { if (!rhs->IsTuple()) @@ -4203,14 +4199,14 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfType* rhs, LookupContext* ctx) { char c = lhsFieldDef->mName[0]; if ((c < '0') || (c > '9')) - return false; + return false; } else { auto rhsFieldDef = rhsFieldInstance->GetFieldDef(); if (lhsFieldDef->mName != rhsFieldDef->mName) return false; - } + } } return true; } @@ -4249,7 +4245,7 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfType* rhs, LookupContext* ctx) BfPointerType* lhsPtrType = (BfPointerType*)lhs; BfPointerType* rhsPtrType = (BfPointerType*)rhs; return lhsPtrType->mElementType == rhsPtrType->mElementType; - } + } else if (lhs->IsGenericParam()) { if (!rhs->IsGenericParam()) @@ -4258,7 +4254,7 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfType* rhs, LookupContext* ctx) BfGenericParamType* rhsGenericParamType = (BfGenericParamType*)rhs; return (lhsGenericParamType->mGenericParamKind == rhsGenericParamType->mGenericParamKind) && (lhsGenericParamType->mGenericParamIdx == rhsGenericParamType->mGenericParamIdx); - } + } else if (lhs->IsRef()) { if (!rhs->IsRef()) @@ -4273,7 +4269,7 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfType* rhs, LookupContext* ctx) return false; BfModifiedTypeType* lhsRetTypeType = (BfModifiedTypeType*)lhs; BfModifiedTypeType* rhsRetTypeType = (BfModifiedTypeType*)rhs; - return (lhsRetTypeType->mModifiedKind == rhsRetTypeType->mModifiedKind) && + return (lhsRetTypeType->mModifiedKind == rhsRetTypeType->mModifiedKind) && (lhsRetTypeType->mElementType == rhsRetTypeType->mElementType); } else if (lhs->IsConcreteInterfaceType()) @@ -4302,7 +4298,7 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfType* rhs, LookupContext* ctx) return (lhsMethodRefType->mMethodRef == rhsMethodRefType->mMethodRef) && (lhsMethodRefType->mOwner == rhsMethodRefType->mOwner) && (lhsMethodRefType->mOwnerRevision == rhsMethodRefType->mOwnerRevision); - } + } else if ((lhs->IsConstExprValue()) || (rhs->IsConstExprValue())) { if (!lhs->IsConstExprValue() || !rhs->IsConstExprValue()) @@ -4311,10 +4307,10 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfType* rhs, LookupContext* ctx) BfConstExprValueType* lhsConstExprValueType = (BfConstExprValueType*)lhs; BfConstExprValueType* rhsConstExprValueType = (BfConstExprValueType*)rhs; - return (lhsConstExprValueType->mType == rhsConstExprValueType->mType) && + return (lhsConstExprValueType->mType == rhsConstExprValueType->mType) && (lhsConstExprValueType->mValue.mInt64 == rhsConstExprValueType->mValue.mInt64); } - else + else { BF_FATAL("Not handled"); } @@ -4381,7 +4377,7 @@ bool BfResolvedTypeSet::GenericTypeEquals(BfTypeInstance* lhsGenericType, BfType { if (!Equals(lhsArgType, genericArgTypeRef, ctx)) return false; - } + } } } @@ -4392,7 +4388,7 @@ bool BfResolvedTypeSet::GenericTypeEquals(BfTypeInstance* lhsGenericType, BfType { int genericParamOffset = 0; bool isFullyQualified = false; - BfTypeInstance* outerType = NULL; + BfTypeInstance* outerType = NULL; if (auto genericInstTypeRef = BfNodeDynCast(rhs)) { @@ -4417,7 +4413,7 @@ bool BfResolvedTypeSet::GenericTypeEquals(BfTypeInstance* lhsGenericType, BfType lhsCheckType = ctx->mModule->GetOuterType(lhsCheckType); } if (lhsCheckType != outerType) - return false; + return false; if (outerType->mGenericTypeInfo != NULL) genericParamOffset = (int)outerType->mGenericTypeInfo->mTypeGenericArguments.mSize; @@ -4449,7 +4445,7 @@ bool BfResolvedTypeSet::GenericTypeEquals(BfTypeInstance* lhsGenericType, BfType rootOuterTypeInstance = ctx->mModule->mCurTypeInstance; if ((rhsTypeDef == ctx->mRootTypeDef) && (ctx->mRootOuterTypeInstance != NULL)) rootOuterTypeInstance = ctx->mRootOuterTypeInstance; - + if (rhsGenericTypeInstRef == NULL) { if (auto rhsNullableTypeRef = BfNodeDynCastExact(rhs)) @@ -4566,7 +4562,7 @@ BfTypeDef* BfResolvedTypeSet::LookupContext::ResolveToTypeDef(BfTypeReference* t return typeDefTypeRef->mTypeDef; } - auto type = mModule->ResolveTypeRef(typeReference, BfPopulateType_Identity, BfResolveTypeRefFlag_AllowGenericParamConstValue); + auto type = mModule->ResolveTypeRef(typeReference, BfPopulateType_Identity, BfResolveTypeRefFlag_AllowGenericParamConstValue); if (type == NULL) return NULL; if (outType != NULL) @@ -4580,7 +4576,7 @@ BfTypeDef* BfResolvedTypeSet::LookupContext::ResolveToTypeDef(BfTypeReference* t } bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, BfTypeDef* rhsTypeDef, LookupContext* ctx) -{ +{ auto rhsType = ctx->mModule->ResolveTypeDef(rhsTypeDef, BfPopulateType_Identity); if (rhsType == NULL) { @@ -4594,7 +4590,7 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, BfTypeDef* rhs bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext* ctx) { //BP_ZONE("BfResolvedTypeSet::Equals"); - + if (ctx->mRootTypeRef != rhs) { if (auto retTypeRef = BfNodeDynCastExact(rhs)) @@ -4616,17 +4612,17 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext* ctx->mFailed = true; return false; } - return lhs == rhsResolvedType; + return lhs == rhsResolvedType; } } - + if (auto declTypeRef = BfNodeDynCastExact(rhs)) { auto cachedResolveType = ctx->GetCachedResolvedType(rhs); BF_ASSERT(cachedResolveType != NULL); return lhs == cachedResolveType; } - + // Strip off 'const' - it's just an error when applied to a typeRef in Beef auto constTypeRef = BfNodeDynCastExact(rhs); if (constTypeRef != NULL) @@ -4661,15 +4657,15 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext* auto rhsDelegateType = BfNodeDynCastExact(rhs); if (rhsDelegateType == NULL) return false; - + bool wantGeneric = false; - - BfDelegateInfo* lhsDelegateInfo = lhs->GetDelegateInfo(); - + + BfDelegateInfo* lhsDelegateInfo = lhs->GetDelegateInfo(); + auto lhsTypeInstance = lhs->ToTypeInstance(); BfMethodDef* invokeMethodDef = lhsTypeInstance->mTypeDef->mMethods[0]; BF_ASSERT(invokeMethodDef->mName == "Invoke"); - + bool rhsIsDelegate = rhsDelegateType->mTypeToken->GetToken() == BfToken_Delegate; if ((lhs->IsDelegate()) != rhsIsDelegate) @@ -4680,14 +4676,14 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext* if (type->IsTypeGenericParam()) wantGeneric = true; }; - + BfCallingConvention rhsCallingConvention = BfCallingConvention_Unspecified; if (ctx->mRootTypeRef == rhsDelegateType) rhsCallingConvention = ctx->mCallingConvention; else ctx->mModule->GetDelegateTypeRefAttributes(rhsDelegateType, rhsCallingConvention); if (lhsDelegateInfo->mCallingConvention != rhsCallingConvention) - return false; + return false; if (!Equals(lhsDelegateInfo->mReturnType, rhsDelegateType->mReturnType, ctx)) return false; _CheckType(lhsDelegateInfo->mReturnType); @@ -4704,21 +4700,21 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext* return false; bool handled = false; - auto lhsThisType = lhsDelegateInfo->mParams[0]; + auto lhsThisType = lhsDelegateInfo->mParams[0]; auto rhsThisType = ctx->mModule->ResolveTypeRef(param0->mTypeRef, BfPopulateType_Identity, (BfResolveTypeRefFlags)(BfResolveTypeRefFlag_NoWarnOnMut | BfResolveTypeRefFlag_AllowRef)); bool wantsMutating = false; if (rhsThisType->IsRef()) - { + { if (lhsThisType != rhsThisType->GetUnderlyingType()) return false; - wantsMutating = (lhsThisType->IsValueType()) || (lhsThisType->IsGenericParam()); + wantsMutating = (lhsThisType->IsValueType()) || (lhsThisType->IsGenericParam()); } else { if (lhsThisType != rhsThisType) - return false; + return false; } if (invokeMethodDef->mIsMutating != wantsMutating) return false; @@ -4735,7 +4731,7 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext* return false; for (int paramIdx = paramRefOfs; paramIdx < lhsDelegateInfo->mParams.size(); paramIdx++) { - auto paramTypeRef = rhsDelegateType->mParams[paramIdx]->mTypeRef; + auto paramTypeRef = rhsDelegateType->mParams[paramIdx]->mTypeRef; if (!Equals(lhsDelegateInfo->mParams[paramIdx], paramTypeRef, ctx)) return false; _CheckType(lhsDelegateInfo->mParams[paramIdx]); @@ -4758,9 +4754,9 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext* return true; } else if (lhs->IsTypeInstance()) - { - BfTypeInstance* lhsInst = (BfTypeInstance*) lhs; - + { + BfTypeInstance* lhsInst = (BfTypeInstance*) lhs; + if (lhs->IsTuple()) { if (!rhs->IsA()) @@ -4813,12 +4809,12 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext* BfTypeInstance* lhsGenericType = (BfTypeInstance*) lhs; return GenericTypeEquals(lhsGenericType, &lhsGenericType->mGenericTypeInfo->mTypeGenericArguments, rhs, rhsTypeDef, ctx); - } + } else { if (rhs->IsA()) return false; - + if (!rhs->IsTypeDefTypeReference()) { if (rhs->IsA()) @@ -4834,7 +4830,7 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext* return true; } } - + return false; } auto rhsTypeDef = ctx->ResolveToTypeDef(rhs); @@ -4842,7 +4838,7 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext* return false; return lhsInst->IsInstanceOf(rhsTypeDef); - } + } } else if (lhs->IsPrimitiveType()) { @@ -4867,20 +4863,20 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext* return true; } - BfPrimitiveType* lhsPrimType = (BfPrimitiveType*)lhs; - auto rhsTypeDef = ctx->ResolveToTypeDef(rhs); -// if (rhsTypeDef->mTypeCode == BfTypeCode_TypeAlias) -// return Equals(lhs, rhs, rhsTypeDef, ctx); + BfPrimitiveType* lhsPrimType = (BfPrimitiveType*)lhs; + auto rhsTypeDef = ctx->ResolveToTypeDef(rhs); +// if (rhsTypeDef->mTypeCode == BfTypeCode_TypeAlias) +// return Equals(lhs, rhs, rhsTypeDef, ctx); return lhsPrimType->mTypeDef == rhsTypeDef; } else if (lhs->IsPointer()) { auto rhsPointerTypeRef = BfNodeDynCastExact(rhs); if (rhsPointerTypeRef == NULL) - return false; - BfPointerType* lhsPtrType = (BfPointerType*)lhs; + return false; + BfPointerType* lhsPtrType = (BfPointerType*)lhs; return Equals(lhsPtrType->mElementType, rhsPointerTypeRef->mElementType, ctx); - } + } else if (lhs->IsGenericParam()) { auto lhsGenericParamType = (BfGenericParamType*)lhs; @@ -4894,7 +4890,7 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext* return false; BfType* resultType = NULL; - result = EvaluateToVariant(ctx, constExprTypeRef->mConstExpr, resultType); + result = EvaluateToVariant(ctx, constExprTypeRef->mConstExpr, resultType); return resultType == lhs; } @@ -4967,12 +4963,12 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext* } if (typedVal) typedVal = ctx->mModule->Cast(sizeExpr, typedVal, intType); - + if (typedVal) - { + { if (lhs->IsUnknownSizedArrayType()) - return false; - + return false; + auto constant = ctx->mModule->mBfIRBuilder->GetConstant(typedVal.mValue); if ((constant->mConstType == BfConstType_Undef) || (!BfIRBuilder::IsInt(constant->mTypeCode))) { @@ -4981,15 +4977,15 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext* else { elementCount = (intptr)constant->mInt64; - BF_ASSERT(elementCount >= 0); // Should have been caught in hash + BF_ASSERT(elementCount >= 0); // Should have been caught in hash } } } - + return lhsArrayType->mElementCount == elementCount; } else if (lhs->IsMethodRef()) - { + { // Always make these unique. The MethodInstance value will change on rebuild anyway return false; } @@ -5019,7 +5015,7 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext* else { BF_FATAL("Not handled"); - } + } return false; } @@ -5052,9 +5048,9 @@ void BfResolvedTypeSet::RemoveEntry(BfResolvedTypeSet::EntryRef entry) // { // entry->mPrev->mNext = entry->mNext; // if (entry->mNext != NULL) -// entry->mNext->mPrev = entry->mPrev; -// } -// +// entry->mNext->mPrev = entry->mPrev; +// } +// // mSize--; bool found = false; @@ -5067,12 +5063,12 @@ void BfResolvedTypeSet::RemoveEntry(BfResolvedTypeSet::EntryRef entry) if (checkEntryIdx == entry.mIndex) { *srcCheckEntryPtr = checkEntry->mNext; - found = true; + found = true; } srcCheckEntryPtr = &checkEntry->mNext; checkEntryIdx = checkEntry->mNext; } - + BF_ASSERT(found); BF_ASSERT(entry->mValue == NULL); FreeIdx(entry.mIndex); @@ -5082,33 +5078,33 @@ void BfResolvedTypeSet::RemoveEntry(BfResolvedTypeSet::EntryRef entry) // { // return ++Iterator(this); // } -// +// // BfResolvedTypeSet::Iterator BfResolvedTypeSet::end() // { // Iterator itr(this); // itr.mCurBucket = HashSize; // return itr; // } -// +// // BfResolvedTypeSet::Iterator BfResolvedTypeSet::erase(BfResolvedTypeSet::Iterator& itr) // { // auto next = itr; // ++next; -// +// // auto cur = itr.mCurEntry; -// +// // auto& hashHead = itr.mTypeSet->mHashHeads[itr.mCurBucket]; -// +// // if (hashHead == cur) // hashHead = cur->mNext; -// if (cur->mPrev != NULL) -// cur->mPrev->mNext = cur->mNext; +// if (cur->mPrev != NULL) +// cur->mPrev->mNext = cur->mNext; // if (cur->mNext != NULL) -// cur->mNext->mPrev = cur->mPrev; +// cur->mNext->mPrev = cur->mPrev; // delete cur; -// +// // //BfLogSys("Deleting node %@ from bucket %d\n", cur, itr.mCurBucket); -// +// // mSize--; // return next; // } @@ -5124,8 +5120,8 @@ BfHotTypeVersion::~BfHotTypeVersion() BfHotTypeData::~BfHotTypeData() { for (auto version : mTypeVersions) - { - version->Deref(); + { + version->Deref(); } } @@ -5136,7 +5132,7 @@ BfHotTypeVersion* BfHotTypeData::GetTypeVersion(int hotCommitedIdx) BfHotTypeVersion* hotTypeVersion = mTypeVersions[checkIdx]; if (hotTypeVersion->mDeclHotCompileIdx <= hotCommitedIdx) return hotTypeVersion; - } + } return NULL; } @@ -5147,7 +5143,7 @@ BfHotTypeVersion* BfHotTypeData::GetLatestVersion() BfHotTypeVersion* BfHotTypeData::GetLatestVersionHead() { - auto lastestVersion = mTypeVersions.back(); + auto lastestVersion = mTypeVersions.back(); for (int versionIdx = (int)mTypeVersions.size() - 1; versionIdx >= 0; versionIdx--) { auto checkVersion = mTypeVersions[versionIdx]; @@ -5175,9 +5171,9 @@ void BfHotTypeData::ClearVersionsAfter(int hotIdx) } void BfHotDepData::Deref() -{ +{ mRefCount--; - BF_ASSERT(mRefCount >= 0); + BF_ASSERT(mRefCount >= 0); if (mRefCount == 0) { @@ -5209,7 +5205,7 @@ void BfHotDepData::Deref() break; case BfHotDepDataKind_VirtualDecl: delete (BfHotVirtualDeclaration*)this; - break; + break; default: BF_FATAL("Not handled"); } @@ -5217,7 +5213,7 @@ void BfHotDepData::Deref() } void BfHotMethod::Clear(bool keepDupMethods) -{ +{ if (mPrevVersion != NULL) { mPrevVersion->Deref(); @@ -5226,10 +5222,10 @@ void BfHotMethod::Clear(bool keepDupMethods) if (mSrcTypeVersion != NULL) { - mSrcTypeVersion->Deref(); + mSrcTypeVersion->Deref(); mSrcTypeVersion = NULL; - } - + } + if ((keepDupMethods) && ((mFlags & BfHotDepDataFlag_HasDup) != 0)) { int writeIdx = 0; @@ -5255,7 +5251,6 @@ void BfHotMethod::Clear(bool keepDupMethods) } mReferences.Clear(); } - } BfHotMethod::~BfHotMethod() @@ -5280,7 +5275,7 @@ String BfTypeUtils::HashEncode64(uint64 val) uint64 flippedNum = (uint64)-(int64)val; // Only flip if the encoded result would actually be shorter if (flippedNum <= 0x00FFFFFFFFFFFFFFLL) - { + { val = flippedNum; outStr.Append('_'); } @@ -5290,7 +5285,7 @@ String BfTypeUtils::HashEncode64(uint64 val) { int charIdx = val % 0x3F; val /= 0x3F; - outStr.Append(cHash64bToChar[charIdx]); + outStr.Append(cHash64bToChar[charIdx]); } return outStr; @@ -5316,7 +5311,7 @@ String BfTypeUtils::TypeToString(BfAstNode* typeRefNode) return ""; if (auto typeDefTypeRef = BfNodeDynCast(typeRef)) - { + { if (!typeDefTypeRef->mTypeDef->mNamespace.IsEmpty()) return typeDefTypeRef->mTypeDef->mNamespace.ToString() + "." + typeDefTypeRef->mTypeDef->mName->mString; else @@ -5324,12 +5319,12 @@ String BfTypeUtils::TypeToString(BfAstNode* typeRefNode) } if (typeRef->IsNamedTypeReference()) - { + { return typeRef->ToString(); } if (auto ptrType = BfNodeDynCast(typeRef)) - return TypeToString(ptrType->mElementType) + "*"; + return TypeToString(ptrType->mElementType) + "*"; if (auto ptrType = BfNodeDynCast(typeRef)) { String name = TypeToString(ptrType->mElementType) + "["; @@ -5379,7 +5374,7 @@ String BfTypeUtils::TypeToString(BfAstNode* typeRefNode) { if (i > 0) name += ", "; - name += TypeToString(tupleTypeRef->mFieldTypes[i]); + name += TypeToString(tupleTypeRef->mFieldTypes[i]); if ((i < tupleTypeRef->mFieldNames.size()) && (tupleTypeRef->mFieldNames[i] != NULL)) { name += " "; @@ -5405,9 +5400,9 @@ String BfTypeUtils::TypeToString(BfAstNode* typeRefNode) bool BfTypeUtils::TypeEquals(BfType* typeA, BfType* typeB, BfTypeInstance* selfType) { if (typeA->IsUnspecializedTypeVariation()) - typeA = selfType->mModule->ResolveSelfType(typeA, selfType); + typeA = selfType->mModule->ResolveSelfType(typeA, selfType); if (typeB->IsUnspecializedTypeVariation()) - typeB = selfType->mModule->ResolveSelfType(typeB, selfType); + typeB = selfType->mModule->ResolveSelfType(typeB, selfType); return typeA == typeB; } @@ -5419,7 +5414,7 @@ String BfTypeUtils::TypeToString(BfTypeDef* typeDef, BfTypeNameFlags typeNameFla } bool BfTypeUtils::TypeToString(StringImpl& str, BfTypeDef* typeDef, BfTypeNameFlags typeNameFlags) -{ +{ auto checkTypeDef = typeDef; char needsSep = 0; @@ -5427,7 +5422,7 @@ bool BfTypeUtils::TypeToString(StringImpl& str, BfTypeDef* typeDef, BfTypeNameFl { if (TypeToString(str, checkTypeDef->mOuterType, typeNameFlags)) { - if ((typeNameFlags & BfTypeNameFlag_InternalName) != 0) + if ((typeNameFlags & BfTypeNameFlag_InternalName) != 0) needsSep = '+'; else needsSep = '.'; @@ -5439,15 +5434,15 @@ bool BfTypeUtils::TypeToString(StringImpl& str, BfTypeDef* typeDef, BfTypeNameFl { typeDef->mNamespace.ToString(str); needsSep = '.'; - } + } } if (needsSep != 0) str += needsSep; - + if (((typeNameFlags & BfTypeNameFlag_HideGlobalName) != 0) && (typeDef->IsGlobalsContainer())) return false; - + typeDef->mName->ToString(str); if (typeDef->mGenericParamDefs.size() != 0) @@ -5455,7 +5450,7 @@ bool BfTypeUtils::TypeToString(StringImpl& str, BfTypeDef* typeDef, BfTypeNameFl int prevGenericParamCount = 0; if (checkTypeDef->mOuterType != NULL) prevGenericParamCount = (int)typeDef->mOuterType->mGenericParamDefs.size(); - + if (prevGenericParamCount != (int)checkTypeDef->mGenericParamDefs.size()) { str += "<"; @@ -5491,4 +5486,4 @@ BfConstExprValueType::~BfConstExprValueType() { // mContext->mTypeConstExprCount--; // BF_ASSERT(mContext->mTypeConstExprCount == 0); -} +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfResolvedTypeUtils.h b/IDEHelper/Compiler/BfResolvedTypeUtils.h index a80015e4..98c054c0 100644 --- a/IDEHelper/Compiler/BfResolvedTypeUtils.h +++ b/IDEHelper/Compiler/BfResolvedTypeUtils.h @@ -28,7 +28,7 @@ enum BfResolveTypeRefFlags BfResolveTypeRefFlag_AllowGenericMethodParamConstValue = 0x20, BfResolveTypeRefFlag_AllowGenericParamConstValue = 0x10 | 0x20, BfResolveTypeRefFlag_AutoComplete = 0x40, - BfResolveTypeRefFlag_FromIndirectSource = 0x80, // Such as a type alias or a generic parameter + BfResolveTypeRefFlag_FromIndirectSource = 0x80, // Such as a type alias or a generic parameter BfResolveTypeRefFlag_Attribute = 0x100, BfResolveTypeRefFlag_NoReify = 0x200, BfResolveTypeRefFlag_NoCreate = 0x400, @@ -53,9 +53,9 @@ enum BfTypeNameFlags : uint16 BfTypeNameFlag_OmitOuterType = 8, BfTypeNameFlag_ReduceName = 0x10, BfTypeNameFlag_UseArrayImplType = 0x20, - BfTypeNameFlag_DisambiguateDups = 0x40, // Add a disambiguation if mDupDetectedRevision is set + BfTypeNameFlag_DisambiguateDups = 0x40, // Add a disambiguation if mDupDetectedRevision is set BfTypeNameFlag_AddGlobalContainerName = 0x80, - BfTypeNameFlag_InternalName = 0x100, // Use special delimiters to remove ambiguities (ie: '+' for inner types) + BfTypeNameFlag_InternalName = 0x100, // Use special delimiters to remove ambiguities (ie: '+' for inner types) BfTypeNameFlag_HideGlobalName = 0x200, BfTypeNameFlag_ExtendedInfo = 0x400, BfTypeNameFlag_ShortConst = 0x800, @@ -124,7 +124,7 @@ public: DependencyFlag_Allocates = 0x800000, DependencyFlag_NameReference = 0x1000000, DependencyFlag_VirtualCall = 0x2000000, - DependencyFlag_WeakReference = 0x4000000, // Keeps alive but won't rebuild + DependencyFlag_WeakReference = 0x4000000, // Keeps alive but won't rebuild DependencyFlag_ValueTypeSizeDep = 0x8000000, // IE: int32[DepType.cVal] DependencyFlag_DependentUsageMask = ~(DependencyFlag_UnspecializedType | DependencyFlag_MethodGenericArg | DependencyFlag_GenericArgRef) @@ -132,18 +132,18 @@ public: struct DependencyEntry { - int mRevision; + int mRevision; DependencyFlags mFlags; DependencyEntry(int revision, DependencyFlags flags) { - mRevision = revision; - mFlags = flags; + mRevision = revision; + mFlags = flags; } }; public: - typedef Dictionary TypeMap; + typedef Dictionary TypeMap; DependencyFlags mFlagsUnion; TypeMap mTypeSet; int mMinDependDepth; @@ -155,11 +155,11 @@ public: mFlagsUnion = DependencyFlag_None; } - bool AddUsedBy(BfType* dependentType, DependencyFlags flags); + bool AddUsedBy(BfType* dependentType, DependencyFlags flags); bool IsEmpty(); TypeMap::iterator begin(); TypeMap::iterator end(); - TypeMap::iterator erase(TypeMap::iterator& itr); + TypeMap::iterator erase(TypeMap::iterator& itr); }; class BfDepContext @@ -180,7 +180,7 @@ enum BfHotDepDataKind : int8 BfHotDepDataKind_Unknown, BfHotDepDataKind_TypeVersion, BfHotDepDataKind_ThisType, - BfHotDepDataKind_Allocation, + BfHotDepDataKind_Allocation, BfHotDepDataKind_Method, BfHotDepDataKind_DupMethod, BfHotDepDataKind_DevirtualizedMethod, @@ -218,7 +218,7 @@ public: #ifdef _DEBUG virtual ~BfHotDepData() - { + { BF_ASSERT(mRefCount == 0); } #endif @@ -227,12 +227,12 @@ public: struct BfHotTypeDataEntry { public: - String mFuncName; // Name of original virtual function, not overrides + String mFuncName; // Name of original virtual function, not overrides }; class BfHotTypeVersion : public BfHotDepData { -public: +public: Val128 mDataHash; // Determines when the user's declaration changed - changes do not cascade into including types BfHotTypeVersion* mBaseType; Array mMembers; // Struct members directly included (not via pointers) @@ -240,13 +240,13 @@ public: int mCommittedHotCompileIdx; int mTypeId; - Array mInterfaceMapping; + Array mInterfaceMapping; bool mPopulatedInterfaceMapping; BfHotTypeVersion() { mBaseType = NULL; - mDataKind = BfHotDepDataKind_TypeVersion; + mDataKind = BfHotDepDataKind_TypeVersion; mPopulatedInterfaceMapping = 0; } @@ -267,7 +267,7 @@ public: ~BfHotThisType() { - mTypeVersion->Deref(); + mTypeVersion->Deref(); } }; @@ -285,7 +285,7 @@ public: ~BfHotAllocation() { - mTypeVersion->Deref(); + mTypeVersion->Deref(); } }; @@ -294,24 +294,24 @@ public: class BfHotMethod : public BfHotDepData { -public: +public: #ifdef BF_DBG_HOTMETHOD_NAME String mMangledName; #endif #ifdef BF_DBG_HOTMETHOD_IDX int mMethodIdx; -#endif - BfHotTypeVersion* mSrcTypeVersion; +#endif + BfHotTypeVersion* mSrcTypeVersion; Array mReferences; - BfHotMethod* mPrevVersion; + BfHotMethod* mPrevVersion; BfHotMethod() { #ifdef BF_DBG_HOTMETHOD_IDX mMethodIdx = -1; -#endif +#endif mDataKind = BfHotDepDataKind_Method; - mSrcTypeVersion = NULL; + mSrcTypeVersion = NULL; mPrevVersion = NULL; } void Clear(bool keepDupMethods = false); @@ -337,7 +337,6 @@ public: } }; - class BfHotDevirtualizedMethod : public BfHotDepData { public: @@ -352,7 +351,7 @@ public: ~BfHotDevirtualizedMethod() { - mMethod->Deref(); + mMethod->Deref(); } }; @@ -370,7 +369,7 @@ public: ~BfHotFunctionReference() { - mMethod->Deref(); + mMethod->Deref(); } }; @@ -388,7 +387,7 @@ public: ~BfHotInnerMethod() { - mMethod->Deref(); + mMethod->Deref(); } }; @@ -406,15 +405,15 @@ public: ~BfHotVirtualDeclaration() { - mMethod->Deref(); + mMethod->Deref(); } }; class BfHotDataReferenceBuilder { -public: - HashSet mAllocatedData; // Any usage that depends on size or layout - HashSet mUsedData; // Any usage that depends on size or layout +public: + HashSet mAllocatedData; // Any usage that depends on size or layout + HashSet mUsedData; // Any usage that depends on size or layout HashSet mCalledMethods; HashSet mDevirtualizedCalledMethods; HashSet mFunctionPtrs; @@ -431,7 +430,7 @@ enum BfTypeRebuildFlags BfTypeRebuildFlag_StaticChange = 1, BfTypeRebuildFlag_NonStaticChange = 2, BfTypeRebuildFlag_MethodInlineInternalsChange = 4, - BfTypeRebuildFlag_MethodSignatureChange = 8, + BfTypeRebuildFlag_MethodSignatureChange = 8, BfTypeRebuildFlag_ConstEvalChange = 0x10, BfTypeRebuildFlag_ConstEvalFieldChange = 0x20, BfTypeRebuildFlag_DeleteQueued = 0x40, @@ -458,7 +457,7 @@ enum BfTypeDefineState : uint8 BfTypeDefineState_Undefined, BfTypeDefineState_Declaring, BfTypeDefineState_Declared, - BfTypeDefineState_ResolvingBaseType, + BfTypeDefineState_ResolvingBaseType, BfTypeDefineState_HasInterfaces_Direct, BfTypeDefineState_CETypeInit, BfTypeDefineState_CEPostTypeInit, @@ -473,7 +472,7 @@ class BfDelegateInfo { public: Array mDirectAllocNodes; - BfType* mReturnType; + BfType* mReturnType; Array mParams; bool mHasExplicitThis; bool mHasVarArgs; @@ -499,7 +498,7 @@ enum BfTypeUsage { BfTypeUsage_Unspecified, BfTypeUsage_Return_Static, - BfTypeUsage_Return_NonStatic, + BfTypeUsage_Return_NonStatic, BfTypeUsage_Parameter, }; @@ -507,28 +506,28 @@ class BfType { public: BfTypeRebuildFlags mRebuildFlags; - + BfContext* mContext; int mTypeId; int mRevision; - - // For Objects, align and size is ref-sized (object*). + + // For Objects, align and size is ref-sized (object*). // Use mInstSize/mInstAlign for actual data size/align - int mSize; - int16 mAlign; + int mSize; + int16 mAlign; bool mDirty; BfTypeDefineState mDefineState; public: - BfType(); + BfType(); virtual ~BfType(); - + BfTypeInstance* FindUnderlyingTypeInstance(); virtual BfModule* GetModule(); - - int GetStride() { return BF_ALIGN(mSize, mAlign); } - bool IsSizeAligned() { return (mSize == 0) || (mSize % mAlign == 0); } + + int GetStride() { return BF_ALIGN(mSize, mAlign); } + bool IsSizeAligned() { return (mSize == 0) || (mSize % mAlign == 0); } virtual bool IsInstanceOf(BfTypeDef* typeDef) { return false; } virtual bool HasBeenReferenced() { return mDefineState != BfTypeDefineState_Undefined; } @@ -538,11 +537,11 @@ public: virtual bool IsIncomplete() { return mDefineState < BfTypeDefineState_Defined; } virtual bool IsDeleting() { return ((mRebuildFlags & (BfTypeRebuildFlag_Deleted | BfTypeRebuildFlag_DeleteQueued)) != 0); } virtual bool IsDeclared() { return mDefineState >= BfTypeDefineState_Declared; } - + virtual BfDependedType* ToDependedType() { return NULL; } virtual BfTypeInstance* ToTypeInstance() { return NULL; } virtual BfTypeInstance* ToGenericTypeInstance() { return NULL; } - virtual BfPrimitiveType* ToPrimitiveType() { return NULL; } + virtual BfPrimitiveType* ToPrimitiveType() { return NULL; } virtual bool IsDependendType() { return false; } virtual int GetGenericDepth() { return 0; } virtual bool IsTypeInstance() { return false; } @@ -560,10 +559,10 @@ public: virtual bool IsValuelessType() { BF_ASSERT(mSize != -1); BF_ASSERT(mDefineState >= BfTypeDefineState_Defined); return mSize == 0; } virtual bool IsSelf() { return false; } virtual bool IsDot() { return false; } - virtual bool IsVar() { return false; } + virtual bool IsVar() { return false; } virtual bool IsLet() { return false; } virtual bool IsNull(){ return false; } - virtual bool IsNullable() { return false; } + virtual bool IsNullable() { return false; } virtual bool IsBoxed() { return false; } virtual bool IsInterface() { return false; } virtual bool IsEnum() { return false; } @@ -573,7 +572,7 @@ public: virtual bool IsStruct() { return false; } virtual bool IsStructPtr() { return false; } virtual bool IsUnion() { return false; } - virtual bool IsStructOrStructPtr() { return false; } + virtual bool IsStructOrStructPtr() { return false; } virtual bool IsObject() { return false; } virtual bool IsObjectOrStruct() { return false; } virtual bool IsObjectOrInterface() { return false; } @@ -581,18 +580,18 @@ public: virtual bool IsSizedArray() { return false; } virtual bool IsUndefSizedArray() { return false; } virtual bool IsUnknownSizedArrayType() { return false; } - virtual bool IsArray() { return false; } + virtual bool IsArray() { return false; } virtual bool IsDelegate() { return false; } virtual bool IsFunction() { return false; } virtual bool IsDelegateOrFunction() { return false; } virtual bool IsDelegateFromTypeRef() { return false; } virtual bool IsFunctionFromTypeRef() { return false; } virtual BfDelegateInfo* GetDelegateInfo() { return NULL; } - virtual bool IsValueType() { return false; } + virtual bool IsValueType() { return false; } virtual bool IsOpaque() { return false; } - virtual bool IsValueTypeOrValueTypePtr() { return false; } + virtual bool IsValueTypeOrValueTypePtr() { return false; } virtual bool IsWrappableType() { return false; } - virtual bool IsPrimitiveType() { return false; } + virtual bool IsPrimitiveType() { return false; } virtual BfTypeCode GetTypeCode() { return BfTypeCode_None; } virtual bool IsBoolean() { return false; } virtual bool IsInteger() { return false; } @@ -603,22 +602,22 @@ public: virtual bool IsSignedInt() { return false; } virtual bool IsIntUnknown() { return false; } virtual bool IsChar() { return false; } - virtual bool IsFloat() { return false; } + virtual bool IsFloat() { return false; } virtual bool IsPointer() { return false; } virtual bool IsAllocType() { return false; } - virtual bool IsIntPtrable() { return false; } - virtual bool IsRef() { return false; } + virtual bool IsIntPtrable() { return false; } + virtual bool IsRef() { return false; } virtual bool IsMut() { return false; } virtual bool IsIn() { return false; } virtual bool IsOut() { return false; } virtual bool IsGenericParam() { return false; } virtual bool IsTypeGenericParam() { return false; } virtual bool IsMethodGenericParam() { return false; } - virtual bool IsClosure() { return false; } + virtual bool IsClosure() { return false; } virtual bool IsMethodRef() { return false; } virtual bool IsTuple() { return false; } virtual bool IsOnDemand() { return false; } - virtual bool IsTemporary() { return false; } + virtual bool IsTemporary() { return false; } virtual bool IsModifiedTypeType() { return false; } virtual bool IsConcreteInterfaceType() { return false; } virtual bool IsTypeAlias() { return false; } @@ -627,7 +626,7 @@ public: virtual bool IsDependentOnUnderlyingType() { return false; } virtual bool WantsGCMarking() { return false; } virtual bool GetLoweredType(BfTypeUsage typeUsage, BfTypeCode* outTypeCode = NULL, BfTypeCode* outTypeCode2 = NULL) { return false; } - virtual BfType* GetUnderlyingType() { return NULL; } + virtual BfType* GetUnderlyingType() { return NULL; } virtual bool HasWrappedRepresentation() { return IsWrappableType(); } virtual bool IsTypeMemberIncluded(BfTypeDef* declaringTypeDef, BfTypeDef* activeTypeDef = NULL, BfModule* module = NULL) { return true; } // May be 'false' only for generic extensions with constraints virtual bool IsTypeMemberAccessible(BfTypeDef* declaringTypeDef, BfTypeDef* activeTypeDef) { return true; } @@ -648,7 +647,7 @@ public: mGenericDepth = 0; } - virtual int GetGenericDepth() override { return mGenericDepth; } + virtual int GetGenericDepth() override { return mGenericDepth; } }; // This is explicitly used for generics @@ -659,7 +658,7 @@ class BfPrimitiveType : public BfType { public: BfTypeDef* mTypeDef; - + public: virtual bool IsPrimitiveType() override { return true; } virtual BfTypeCode GetTypeCode() override { return mTypeDef->mTypeCode; } @@ -672,31 +671,31 @@ public: virtual bool IsBoolean() override { return mTypeDef->mTypeCode == BfTypeCode_Boolean; } virtual bool IsIntegral() override { return (mTypeDef->mTypeCode >= BfTypeCode_Int8) && (mTypeDef->mTypeCode <= BfTypeCode_Char32); } virtual bool IsIntegralOrBool() override { return (mTypeDef->mTypeCode >= BfTypeCode_Boolean) && (mTypeDef->mTypeCode <= BfTypeCode_Char32); } - virtual bool IsInteger() override { return (mTypeDef->mTypeCode >= BfTypeCode_Int8) && (mTypeDef->mTypeCode <= BfTypeCode_UIntUnknown); } + virtual bool IsInteger() override { return (mTypeDef->mTypeCode >= BfTypeCode_Int8) && (mTypeDef->mTypeCode <= BfTypeCode_UIntUnknown); } virtual bool IsIntPtr() override { return (mTypeDef->mTypeCode == BfTypeCode_IntPtr) || (mTypeDef->mTypeCode == BfTypeCode_UIntPtr); } - virtual bool IsIntPtrable() override - { + virtual bool IsIntPtrable() override + { return (mTypeDef->mTypeCode == BfTypeCode_IntPtr) || (mTypeDef->mTypeCode == BfTypeCode_UIntPtr) || ((mTypeDef->mSystem->mPtrSize == 8) && ((mTypeDef->mTypeCode == BfTypeCode_Int64) || (mTypeDef->mTypeCode == BfTypeCode_UInt64))) || ((mTypeDef->mSystem->mPtrSize == 4) && ((mTypeDef->mTypeCode == BfTypeCode_Int32) || (mTypeDef->mTypeCode == BfTypeCode_UInt32))); } - virtual bool IsSigned() override { return (mTypeDef->mTypeCode == BfTypeCode_Int8) || (mTypeDef->mTypeCode == BfTypeCode_Int16) || - (mTypeDef->mTypeCode == BfTypeCode_Int32) || (mTypeDef->mTypeCode == BfTypeCode_Int64) || (mTypeDef->mTypeCode == BfTypeCode_IntPtr) || + virtual bool IsSigned() override { return (mTypeDef->mTypeCode == BfTypeCode_Int8) || (mTypeDef->mTypeCode == BfTypeCode_Int16) || + (mTypeDef->mTypeCode == BfTypeCode_Int32) || (mTypeDef->mTypeCode == BfTypeCode_Int64) || (mTypeDef->mTypeCode == BfTypeCode_IntPtr) || (mTypeDef->mTypeCode == BfTypeCode_IntUnknown) || (mTypeDef->mTypeCode == BfTypeCode_Float) || (mTypeDef->mTypeCode == BfTypeCode_Double); } - virtual bool IsSignedInt() override { return (mTypeDef->mTypeCode == BfTypeCode_Int8) || (mTypeDef->mTypeCode == BfTypeCode_Int16) || + virtual bool IsSignedInt() override { return (mTypeDef->mTypeCode == BfTypeCode_Int8) || (mTypeDef->mTypeCode == BfTypeCode_Int16) || (mTypeDef->mTypeCode == BfTypeCode_Int32) || (mTypeDef->mTypeCode == BfTypeCode_Int64) || (mTypeDef->mTypeCode == BfTypeCode_IntPtr) || (mTypeDef->mTypeCode == BfTypeCode_IntUnknown); } virtual bool IsIntUnknown() override { return (mTypeDef->mTypeCode == BfTypeCode_IntUnknown) || (mTypeDef->mTypeCode == BfTypeCode_UIntUnknown); } virtual bool IsChar() override { return (mTypeDef->mTypeCode == BfTypeCode_Char8) || (mTypeDef->mTypeCode == BfTypeCode_Char16) || (mTypeDef->mTypeCode == BfTypeCode_Char32); } virtual bool IsFloat() override { return (mTypeDef->mTypeCode == BfTypeCode_Float) || (mTypeDef->mTypeCode == BfTypeCode_Double); } virtual bool IsNull() override { return mTypeDef->mTypeCode == BfTypeCode_NullPtr; } - virtual bool IsVoid() override { return mTypeDef->mTypeCode == BfTypeCode_None; } + virtual bool IsVoid() override { return mTypeDef->mTypeCode == BfTypeCode_None; } virtual bool CanBeValuelessType() override { return mTypeDef->mTypeCode == BfTypeCode_None; } virtual bool IsValuelessType() override { return mTypeDef->mTypeCode == BfTypeCode_None; } virtual bool IsSelf() override { return mTypeDef->mTypeCode == BfTypeCode_Self; } virtual bool IsDot() override { return mTypeDef->mTypeCode == BfTypeCode_Dot; } - virtual bool IsVar() override { return mTypeDef->mTypeCode == BfTypeCode_Var; } + virtual bool IsVar() override { return mTypeDef->mTypeCode == BfTypeCode_Var; } virtual bool IsLet() override { return mTypeDef->mTypeCode == BfTypeCode_Let; } virtual bool IsUnspecializedType() override { return mTypeDef->mTypeCode == BfTypeCode_Self; } virtual bool IsUnspecializedTypeVariation() override { return mTypeDef->mTypeCode == BfTypeCode_Self; } @@ -720,7 +719,7 @@ public: public: BfDeferredMethodCallData() - { + { mAlign = 0; mSize = 0; mMethodId = 0; @@ -748,7 +747,7 @@ public: class BfMethodParam { -public: +public: BfType* mResolvedType; int16 mParamDefIdx; int16 mDelegateParamIdx; @@ -759,7 +758,7 @@ public: public: BfMethodParam() - { + { mResolvedType = NULL; mParamDefIdx = -1; mDelegateParamIdx = -1; @@ -767,7 +766,7 @@ public: mWasGenericParam = false; mIsSplat = false; mReferencedInConstPass = false; - } + } BfMethodInstance* GetDelegateParamInvoke(); }; @@ -835,7 +834,7 @@ public: { mThisOverride = NULL; mLocalMethod = NULL; - mCaptureClosureState = NULL; + mCaptureClosureState = NULL; } }; @@ -850,7 +849,7 @@ public: BfTypeVector mMethodGenericArguments; Dictionary mGenericTypeBindings; BfMethodCustomAttributes* mMethodCustomAttributes; - int mMinDependDepth; + int mMinDependDepth; BfMethodInfoEx() { @@ -858,10 +857,10 @@ public: mForeignType = NULL; mClosureInstanceInfo = NULL; mMethodCustomAttributes = NULL; - mMinDependDepth = -1; + mMinDependDepth = -1; } - - ~BfMethodInfoEx(); + + ~BfMethodInfoEx(); }; enum BfImportCallKind @@ -873,7 +872,7 @@ enum BfImportCallKind class BfMethodInstance { -public: +public: int mVirtualTableIdx; BfIRFunction mIRFunction; // Only valid for owning module int16 mAppendAllocAlign; @@ -893,12 +892,12 @@ public: bool mIsAutocompleteMethod:1; bool mRequestedByAutocomplete : 1; bool mIsClosure:1; - bool mMayBeConst:1; // Only used for calcAppend currently + bool mMayBeConst:1; // Only used for calcAppend currently bool mIsForeignMethodDef:1; bool mAlwaysInline:1; bool mIsIntrinsic:1; bool mHasMethodRefType:1; - bool mDisallowCalling:1; + bool mDisallowCalling:1; bool mIsInnerOverride:1; bool mInCEMachine:1; bool mCeCancelled:1; @@ -909,19 +908,19 @@ public: BfMethodInstanceGroup* mMethodInstanceGroup; BfMethodDef* mMethodDef; BfType* mReturnType; - Array mParams; + Array mParams; Array mDefaultValues; BfModule* mDeclModule; - BfMethodProcessRequest* mMethodProcessRequest; - BfMethodInfoEx* mMethodInfoEx; - int64 mIdHash; // Collisions are (essentially) benign + BfMethodProcessRequest* mMethodProcessRequest; + BfMethodInfoEx* mMethodInfoEx; + int64 mIdHash; // Collisions are (essentially) benign BfHotMethod* mHotMethod; public: BfMethodInstance() - { - mVirtualTableIdx = -1; - mIsUnspecialized = false; + { + mVirtualTableIdx = -1; + mIsUnspecialized = false; mIsUnspecializedVariation = false; mIsReified = true; mHasStartedDeclaration = false; @@ -936,7 +935,7 @@ public: mIsAutocompleteMethod = false; mRequestedByAutocomplete = false; mIsClosure = false; - mMayBeConst = true; + mMayBeConst = true; mIsForeignMethodDef = false; mAlwaysInline = false; mIsIntrinsic = false; @@ -950,14 +949,14 @@ public: mComptimeFlags = BfComptimeFlag_None; mCallingConvention = BfCallingConvention_Unspecified; mMethodInstanceGroup = NULL; - mMethodDef = NULL; - mReturnType = NULL; + mMethodDef = NULL; + mReturnType = NULL; mIdHash = 0; - mAppendAllocAlign = -1; + mAppendAllocAlign = -1; mEndingAppendAllocAlign = -1; - mDeclModule = NULL; + mDeclModule = NULL; mMethodProcessRequest = NULL; - mMethodInfoEx = NULL; + mMethodInfoEx = NULL; mHotMethod = NULL; } @@ -974,14 +973,14 @@ public: BfImportKind GetImportKind(); BfMethodFlags GetMethodFlags(); void UndoDeclaration(bool keepIRFunction = false); - BfTypeInstance* GetOwner(); + BfTypeInstance* GetOwner(); BfModule* GetModule(); bool IsSpecializedGenericMethod(); bool IsSpecializedGenericMethodOrType(); bool IsSpecializedByAutoCompleteMethod(); bool IsOrInUnspecializedVariation(); bool HasExternConstraints(); - bool HasThis(); + bool HasThis(); bool IsVirtual(); BfType* GetThisType(); int GetThisIdx(); @@ -989,17 +988,17 @@ public: bool HasParamsArray(); int GetStructRetIdx(bool forceStatic = false); bool HasSelf(); - bool GetLoweredReturnType(BfTypeCode* loweredTypeCode = NULL, BfTypeCode* loweredTypeCode2 = NULL, bool forceStatic = false); + bool GetLoweredReturnType(BfTypeCode* loweredTypeCode = NULL, BfTypeCode* loweredTypeCode2 = NULL, bool forceStatic = false); bool WantsStructsAttribByVal(BfType* paramType); bool IsAutocompleteMethod() { /*return mIdHash == -1;*/ return mIsAutocompleteMethod; } - bool IsSkipCall(bool bypassVirtual = false); + bool IsSkipCall(bool bypassVirtual = false); bool IsVarArgs(); bool AlwaysInline(); - BfImportCallKind GetImportCallKind(); + BfImportCallKind GetImportCallKind(); bool IsTestMethod(); bool AllowsSplatting(int paramIdx); int GetParamCount(); - int GetImplicitParamCount(); + int GetImplicitParamCount(); void GetParamName(int paramIdx, StringImpl& name, int& namePrefixCount); String GetParamName(int paramIdx); String GetParamName(int paramIdx, int& namePrefixCount); @@ -1017,8 +1016,8 @@ public: void GetIRFunctionInfo(BfModule* module, BfIRType& returnType, SizedArrayImpl& paramTypes, bool forceStatic = false); int GetIRFunctionParamCount(BfModule* module); - bool IsExactMatch(BfMethodInstance* other, bool ignoreImplicitParams = false, bool checkThis = false); - bool IsReifiedAndImplemented(); + bool IsExactMatch(BfMethodInstance* other, bool ignoreImplicitParams = false, bool checkThis = false); + bool IsReifiedAndImplemented(); BfMethodInfoEx* GetMethodInfoEx(); BfCustomAttributes* GetCustomAttributes() @@ -1088,14 +1087,14 @@ public: public: BfModuleMethodInstance() { - mMethodInstance = NULL; + mMethodInstance = NULL; } - BfModuleMethodInstance(BfMethodInstance* methodInstance); + BfModuleMethodInstance(BfMethodInstance* methodInstance); BfModuleMethodInstance(BfMethodInstance* methodInstance, BfIRValue func) : mFunc(func) { - mMethodInstance = methodInstance; + mMethodInstance = methodInstance; } operator bool() const @@ -1115,7 +1114,7 @@ class BfGenericParamType : public BfType public: BfGenericParamKind mGenericParamKind; int mGenericParamIdx; - + public: bool IsGenericParam() override { return true; } bool IsTypeGenericParam() override { return mGenericParamKind == BfGenericParamKind_Type; } @@ -1138,7 +1137,7 @@ public: virtual bool IsUnspecializedType() override { return mElementType->IsUnspecializedType(); } virtual bool IsUnspecializedTypeVariation() override { return mElementType->IsUnspecializedType(); } virtual bool IsReified() override { return mElementType->IsReified(); } - virtual bool IsDependentOnUnderlyingType() override { return true; } + virtual bool IsDependentOnUnderlyingType() override { return true; } virtual bool IsAllocType() override { return mModifiedKind == BfToken_AllocType; } virtual BfType* GetUnderlyingType() override { return mElementType; } }; @@ -1173,9 +1172,9 @@ public: } }; -class BfGenericParamInstance +class BfGenericParamInstance { -public: +public: BfGenericParamFlags mGenericParamFlags; BfType* mExternType; Array mInterfaceConstraints; @@ -1198,7 +1197,7 @@ public: { if (--mRefCount == 0) delete this; - } + } virtual ~BfGenericParamInstance() { @@ -1207,7 +1206,7 @@ public: virtual BfConstraintDef* GetConstraintDef() = 0; virtual BfGenericParamDef* GetGenericParamDef() = 0; virtual BfExternalConstraintDef* GetExternConstraintDef() = 0; - virtual String GetName() = 0; + virtual String GetName() = 0; virtual BfAstNode* GetRefNode() = 0; bool IsEnum(); }; @@ -1329,7 +1328,7 @@ public: #define BF_VALCOMP(val) if (val != 0) return val struct BfTypeVectorHash -{ +{ size_t operator()(const BfTypeVector& val) const; }; @@ -1342,10 +1341,10 @@ struct BfTypeVectorEquals class BfMethodInstanceGroup { public: - BfTypeInstance* mOwner; - BfMethodInstance* mDefault; + BfTypeInstance* mOwner; + BfMethodInstance* mDefault; typedef Dictionary MapType; - MapType* mMethodSpecializationMap; + MapType* mMethodSpecializationMap; BfCustomAttributes* mDefaultCustomAttributes; int mMethodIdx; int mRefCount; // External references from BfMethodRefType @@ -1366,13 +1365,13 @@ public: mExplicitlyReflected = false; mHasEmittedReference = false; } - + BfMethodInstanceGroup(BfMethodInstanceGroup&& prev) noexcept; - ~BfMethodInstanceGroup(); + ~BfMethodInstanceGroup(); bool IsImplemented() { - return (mOnDemandKind == BfMethodOnDemandKind_AlwaysInclude) || + return (mOnDemandKind == BfMethodOnDemandKind_AlwaysInclude) || (mOnDemandKind == BfMethodOnDemandKind_Referenced) || (mOnDemandKind == BfMethodOnDemandKind_InWorkList); } @@ -1381,8 +1380,8 @@ public: class BfFieldInstance { public: - BfTypeInstance* mOwner; - BfType* mResolvedType; + BfTypeInstance* mOwner; + BfType* mResolvedType; BfCustomAttributes* mCustomAttributes; int mConstIdx; int mFieldIdx; @@ -1398,16 +1397,16 @@ public: int mLastRevisionReferenced; public: - BfFieldDef* GetFieldDef(); + BfFieldDef* GetFieldDef(); BfFieldInstance(BfFieldInstance&& copyFrom) { mCustomAttributes = copyFrom.mCustomAttributes; copyFrom.mCustomAttributes = NULL; - mOwner = copyFrom.mOwner; + mOwner = copyFrom.mOwner; mResolvedType = copyFrom.mResolvedType; - + mCustomAttributes = copyFrom.mCustomAttributes; mConstIdx = copyFrom.mConstIdx; mFieldIdx = copyFrom.mFieldIdx; @@ -1415,12 +1414,12 @@ public: mMergedDataIdx = copyFrom.mMergedDataIdx; mDataOffset = copyFrom.mDataOffset; mDataSize = copyFrom.mDataSize; - mFieldIncluded = copyFrom.mFieldIncluded; + mFieldIncluded = copyFrom.mFieldIncluded; mIsEnumPayloadCase = copyFrom.mIsEnumPayloadCase; mIsThreadLocal = copyFrom.mIsThreadLocal; - mIsInferredType = copyFrom.mIsInferredType; + mIsInferredType = copyFrom.mIsInferredType; mHadConstEval = copyFrom.mHadConstEval; - mLastRevisionReferenced = copyFrom.mLastRevisionReferenced; + mLastRevisionReferenced = copyFrom.mLastRevisionReferenced; } BfFieldInstance(const BfFieldInstance& copyFrom) @@ -1448,10 +1447,10 @@ public: BfFieldInstance() { mFieldIdx = -1; - mOwner = NULL; + mOwner = NULL; mResolvedType = NULL; mIsEnumPayloadCase = false; - mCustomAttributes = NULL; + mCustomAttributes = NULL; mConstIdx = -1; mDataIdx = -1; mMergedDataIdx = -1; @@ -1462,7 +1461,7 @@ public: mIsInferredType = false; mHadConstEval = false; mLastRevisionReferenced = -1; - } + } ~BfFieldInstance(); @@ -1487,7 +1486,7 @@ public: { int mMethodNum; BfMethodRefKind mKind; - }; + }; int mSignatureHash; BfNonGenericMethodRef() @@ -1505,7 +1504,7 @@ public: BfNonGenericMethodRef& operator=(BfMethodInstance* methodInstance); bool operator==(const BfNonGenericMethodRef& methodRef) const; bool operator==(BfMethodInstance* methodInstance) const; - + struct Hash { size_t operator()(const BfNonGenericMethodRef& val) const; @@ -1528,13 +1527,13 @@ enum BfMethodRefFlags : uint8 class BfMethodRef { -public: +public: BfTypeInstance* mTypeInstance; union { int mMethodNum; BfMethodRefKind mKind; - }; + }; Array mMethodGenericArguments; int mSignatureHash; BfMethodRefFlags mMethodRefFlags; @@ -1547,7 +1546,7 @@ public: mMethodRefFlags = BfMethodRefFlag_None; } - BfMethodRef(BfMethodInstance* methodInstance); + BfMethodRef(BfMethodInstance* methodInstance); operator BfMethodInstance*() const; bool IsNull() { return mTypeInstance == NULL; }; @@ -1555,9 +1554,9 @@ public: BfMethodRef& operator=(BfMethodInstance* methodInstance); bool operator==(const BfMethodRef& methodRef) const; bool operator==(BfMethodInstance* methodInstance) const; - + struct Hash - { + { size_t operator()(const BfMethodRef& val) const; }; @@ -1610,18 +1609,18 @@ public: } BfPropertyRef(BfTypeInstance* typeInst, BfPropertyDef* propDef); - + operator BfPropertyDef*() const; }; class BfTypeInterfaceEntry { -public: +public: BfTypeDef* mDeclaringType; BfTypeInstance* mInterfaceType; int mStartInterfaceTableIdx; int mStartVirtualIdx; // Relative to start of virtual interface methods - bool mIsRedeclared; + bool mIsRedeclared; }; class BfTypeInterfaceMethodEntry @@ -1656,7 +1655,7 @@ enum BfAttributeTargets : int32 BfAttributeTargets_Parameter = 0x0800, BfAttributeTargets_Delegate = 0x1000, BfAttributeTargets_Function = 0x2000, - BfAttributeTargets_ReturnValue = 0x4000, + BfAttributeTargets_ReturnValue = 0x4000, BfAttributeTargets_GenericParameter = 0x8000, BfAttributeTargets_Invocation = 0x10000, BfAttributeTargets_MemberAccess = 0x20000, @@ -1695,25 +1694,25 @@ public: class BfHotTypeData { -public: +public: Array mTypeVersions; - Array mVTableEntries; // Doesn't fill in until we rebuild or delete type + Array mVTableEntries; // Doesn't fill in until we rebuild or delete type int mVTableOrigLength; int mOrigInterfaceMethodsLength; bool mPendingDataChange; bool mHadDataChange; // True if we have EVER had a hot data change - + public: BfHotTypeData() { mVTableOrigLength = -1; - mOrigInterfaceMethodsLength = -1; + mOrigInterfaceMethodsLength = -1; mPendingDataChange = false; mHadDataChange = false; } ~BfHotTypeData(); - + BfHotTypeVersion* GetTypeVersion(int hotCommitedIdx); BfHotTypeVersion* GetLatestVersion(); BfHotTypeVersion* GetLatestVersionHead(); // The oldest version that has the same data @@ -1724,7 +1723,7 @@ struct BfTypeLookupEntry { BfAtomComposite mName; int mNumGenericParams; - uint32 mAtomUpdateIdx; + uint32 mAtomUpdateIdx; BfTypeDef* mUseTypeDef; bool operator==(const BfTypeLookupEntry& rhs) const @@ -1801,10 +1800,10 @@ struct BfVirtualMethodEntry struct BfSpecializedMethodRefInfo { bool mHasReifiedRef; - + BfSpecializedMethodRefInfo() { - mHasReifiedRef = false; + mHasReifiedRef = false; } }; @@ -1877,11 +1876,11 @@ public: }; struct Entry - { + { SizedArray, 1> mLookups; }; -public: +public: Dictionary mEntries; Dictionary mMethods; HashSet mAwaitingPopulateSet; @@ -1909,7 +1908,6 @@ public: } }; - class BfGenericExtensionEntry { public: @@ -1938,7 +1936,7 @@ public: void Clear() { - mExtensionMap.Clear(); + mExtensionMap.Clear(); } }; @@ -1957,7 +1955,7 @@ public: bool mValidatedGenericConstraints; bool mHadValidateErrors; bool mInitializedGenericParams; - bool mFinishedGenericParams; + bool mFinishedGenericParams; Array mProjectsReferenced; // Generic methods that only refer to these projects don't need a specialized extension int32 mMaxGenericDepth; @@ -1975,7 +1973,7 @@ public: } ~BfGenericTypeInfo(); - + void ReportMemory(MemReporter* memReporter); }; @@ -2004,41 +2002,41 @@ public: BfTypeInfoEx* mTypeInfoEx; BfGenericTypeInfo* mGenericTypeInfo; BfCeTypeInfo* mCeTypeInfo; - Array mInterfaces; - Array mInterfaceMethodTable; + Array mInterfaces; + Array mInterfaceMethodTable; Array mMethodInstanceGroups; Array mOperatorInfo; Array mVirtualMethodTable; Array mReifyMethodDependencies; - BfHotTypeData* mHotTypeData; - int mVirtualMethodTableSize; // With hot reloading, mVirtualMethodTableSize can be larger than mInterfaceMethodTable (live vtable versioning) + BfHotTypeData* mHotTypeData; + int mVirtualMethodTableSize; // With hot reloading, mVirtualMethodTableSize can be larger than mInterfaceMethodTable (live vtable versioning) Array mFieldInstances; - Array mInternalMethods; + Array mInternalMethods; Dictionary mStaticSearchMap; Dictionary mInternalAccessMap; Array mOwnedLocalMethods; // Local methods in CEMachine bool mHasStaticInitMethod; bool mHasStaticDtorMethod; - bool mHasStaticMarkMethod; + bool mHasStaticMarkMethod; bool mHasTLSFindMethod; - BfIRConstHolder* mConstHolder; + BfIRConstHolder* mConstHolder; Dictionary mSpecializedMethodReferences; // Includes both specialized methods and OnDemand methods - // We store lookup results so we can rebuild this type if a name resolves differently due to a new type being created (ie: a type name found first in + // We store lookup results so we can rebuild this type if a name resolves differently due to a new type being created (ie: a type name found first in Dictionary mLookupResults; - + int mTypeOptionsIdx; - int mMergedFieldDataCount; + int mMergedFieldDataCount; int mInstAlign; - int mInstSize; + int mInstSize; int16 mInheritDepth; int16 mSlotNum; BfAlwaysIncludeFlags mAlwaysIncludeFlags; bool mHasBeenInstantiated; bool mIsReified; bool mIsTypedPrimitive; - bool mIsCRepr; - bool mIsUnion; + bool mIsCRepr; + bool mIsUnion; uint8 mPacking; bool mIsSplattable; bool mHasUnderlyingArray; @@ -2049,16 +2047,16 @@ public: bool mResolvingConstField; bool mSkipTypeProtectionChecks; bool mNeedsMethodProcessing; - bool mBaseTypeMayBeIncomplete; + bool mBaseTypeMayBeIncomplete; bool mHasParameterizedBase; // Generic, array, etc - bool mIsFinishingType; - bool mHasPackingHoles; + bool mIsFinishingType; + bool mHasPackingHoles; bool mWantsGCMarking; - bool mHasDeclError; + bool mHasDeclError; public: BfTypeInstance() - { + { mModule = NULL; mSignatureRevision = -1; mLastNonGenericUsedRevision = -1; @@ -2079,19 +2077,19 @@ public: mCeTypeInfo = NULL; //mClassVData = NULL; mVirtualMethodTableSize = 0; - mHotTypeData = NULL; + mHotTypeData = NULL; mHasStaticInitMethod = false; mHasStaticMarkMethod = false; - mHasStaticDtorMethod = false; + mHasStaticDtorMethod = false; mHasTLSFindMethod = false; mSlotNum = -1; mTypeOptionsIdx = -2; // -2 = not checked, -1 = none mInstSize = -1; mInstAlign = -1; - mInheritDepth = 0; + mInheritDepth = 0; mIsTypedPrimitive = false; mTypeIncomplete = true; - mIsCRepr = false; + mIsCRepr = false; mIsUnion = false; mTypeFailed = false; mTypeWarned = false; @@ -2101,20 +2099,20 @@ public: mBaseTypeMayBeIncomplete = false; mIsFinishingType = false; mResolvingConstField = false; - mHasPackingHoles = false; + mHasPackingHoles = false; mAlwaysIncludeFlags = BfAlwaysIncludeFlag_None; - mHasBeenInstantiated = false; + mHasBeenInstantiated = false; mWantsGCMarking = false; mHasParameterizedBase = false; mHasDeclError = false; mMergedFieldDataCount = 0; mConstHolder = NULL; } - - ~BfTypeInstance(); - + + ~BfTypeInstance(); + virtual void Dispose(); - void ReleaseData(); + void ReleaseData(); virtual bool IsInstanceOf(BfTypeDef* typeDef) override { if (typeDef == NULL) return false; return typeDef->GetDefinition() == mTypeDef->GetDefinition(); } virtual BfModule* GetModule() override { return mModule; } @@ -2122,11 +2120,11 @@ public: virtual bool IsDependentOnUnderlyingType() override { return true; } virtual BfPrimitiveType* ToPrimitiveType() override { return IsBoxed() ? GetUnderlyingType()->ToPrimitiveType() : NULL; } virtual bool HasWrappedRepresentation() override { return IsTypedPrimitive(); } - - int GetEndingInstanceAlignment() { if (mInstSize % mInstAlign == 0) return mInstAlign; return mInstSize % mInstAlign; } - virtual bool HasTypeFailed() override { return mTypeFailed; } - virtual bool IsReified() override { return mIsReified; } - virtual bool IsDataIncomplete() override { return ((mTypeIncomplete) || (mBaseTypeMayBeIncomplete)) && (!mNeedsMethodProcessing); } + + int GetEndingInstanceAlignment() { if (mInstSize % mInstAlign == 0) return mInstAlign; return mInstSize % mInstAlign; } + virtual bool HasTypeFailed() override { return mTypeFailed; } + virtual bool IsReified() override { return mIsReified; } + virtual bool IsDataIncomplete() override { return ((mTypeIncomplete) || (mBaseTypeMayBeIncomplete)) && (!mNeedsMethodProcessing); } virtual bool IsFinishingType() override { return mIsFinishingType; } virtual bool IsIncomplete() override { return (mTypeIncomplete) || (mBaseTypeMayBeIncomplete); } virtual bool IsSplattable() override { BF_ASSERT((mInstSize >= 0) || (!IsComposite())); return mIsSplattable; } @@ -2136,7 +2134,7 @@ public: virtual bool IsInterface() override { return mTypeDef->mTypeCode == BfTypeCode_Interface; } virtual bool IsValueType() override { return (mTypeDef->mTypeCode == BfTypeCode_Struct) || (mTypeDef->mTypeCode == BfTypeCode_Enum); } virtual bool IsOpaque() override { return mTypeDef->mIsOpaque; } - virtual bool IsStruct() override { return ((mTypeDef->mTypeCode == BfTypeCode_Struct) || (mTypeDef->mTypeCode == BfTypeCode_Enum)) && (!mIsTypedPrimitive); } + virtual bool IsStruct() override { return ((mTypeDef->mTypeCode == BfTypeCode_Struct) || (mTypeDef->mTypeCode == BfTypeCode_Enum)) && (!mIsTypedPrimitive); } virtual bool IsUnion() override { return mIsUnion; } virtual bool IsDelegate() override { return mTypeDef->mIsDelegate; } virtual bool IsFunction() override { return mTypeDef->mIsFunction; } @@ -2148,23 +2146,23 @@ public: virtual bool IsTypedPrimitive() override { return mIsTypedPrimitive; } virtual bool IsStructOrStructPtr() override { return mTypeDef->mTypeCode == BfTypeCode_Struct; } virtual bool IsValueTypeOrValueTypePtr() override { return (mTypeDef->mTypeCode == BfTypeCode_Struct) || (mTypeDef->mTypeCode == BfTypeCode_Enum); } - virtual bool IsObject() override { return mTypeDef->mTypeCode == BfTypeCode_Object; } + virtual bool IsObject() override { return mTypeDef->mTypeCode == BfTypeCode_Object; } virtual bool IsObjectOrStruct() override { return (mTypeDef->mTypeCode == BfTypeCode_Object) || (mTypeDef->mTypeCode == BfTypeCode_Struct); } virtual bool IsObjectOrInterface() override { return (mTypeDef->mTypeCode == BfTypeCode_Object) || (mTypeDef->mTypeCode == BfTypeCode_Interface); } virtual BfType* GetUnderlyingType() override; - //virtual bool IsValuelessType() override { return (mIsTypedPrimitive) && (mInstSize == 0); } + //virtual bool IsValuelessType() override { return (mIsTypedPrimitive) && (mInstSize == 0); } virtual bool CanBeValuelessType() override { return (mTypeDef->mTypeCode == BfTypeCode_Struct) || (mTypeDef->mTypeCode == BfTypeCode_Enum); } virtual bool IsValuelessType() override; virtual bool HasPackingHoles() override { return mHasPackingHoles; } virtual bool IsTypeMemberAccessible(BfTypeDef* declaringTypeDef, BfTypeDef* activeTypeDef) override; - virtual bool IsTypeMemberAccessible(BfTypeDef* declaringTypeDef, BfProject* curProject) override; + virtual bool IsTypeMemberAccessible(BfTypeDef* declaringTypeDef, BfProject* curProject) override; virtual bool IsTypeMemberAccessible(BfTypeDef* declaringTypeDef, BfProjectSet* visibleProjectSet) override; virtual bool WantsGCMarking() override; virtual bool GetLoweredType(BfTypeUsage typeUsage, BfTypeCode* outTypeCode = NULL, BfTypeCode* outTypeCode2 = NULL) override; BfGenericTypeInfo* GetGenericTypeInfo() { return mGenericTypeInfo; } - virtual int GetGenericDepth() { return (mGenericTypeInfo != NULL) ? mGenericTypeInfo->mMaxGenericDepth : 0; } - + virtual int GetGenericDepth() { return (mGenericTypeInfo != NULL) ? mGenericTypeInfo->mMaxGenericDepth : 0; } + virtual BfTypeInstance* ToGenericTypeInstance() override { return (mGenericTypeInfo != NULL) ? this : NULL; } virtual bool IsGenericTypeInstance() override { return mGenericTypeInfo != NULL; } virtual bool IsSpecializedType() override { return (mGenericTypeInfo != NULL) && (!mGenericTypeInfo->mIsUnspecialized); } @@ -2172,7 +2170,7 @@ public: virtual bool IsUnspecializedType() override { return (mGenericTypeInfo != NULL) && (mGenericTypeInfo->mIsUnspecialized); } virtual bool IsUnspecializedTypeVariation() override { return (mGenericTypeInfo != NULL) && (mGenericTypeInfo->mIsUnspecializedVariation); } virtual bool IsNullable() override; - virtual bool HasVarConstraints(); + virtual bool HasVarConstraints(); virtual bool IsTypeMemberIncluded(BfTypeDef* declaringTypeDef, BfTypeDef* activeTypeDef = NULL, BfModule* module = NULL) override; virtual BfTypeInstance* GetImplBaseType() { return mBaseType; } @@ -2182,22 +2180,22 @@ public: void CalcHotVirtualData(/*Val128& vtHash, */Array* ifaceMapping); int GetOrigVTableSize(); int GetSelfVTableSize(); - int GetOrigSelfVTableSize(); + int GetOrigSelfVTableSize(); int GetImplBaseVTableSize(); int GetOrigImplBaseVTableSize(); int GetIFaceVMethodSize(); BfType* GetUnionInnerType(bool* wantSplat = NULL); - BfPrimitiveType* GetDiscriminatorType(int* outDataIdx = NULL); + BfPrimitiveType* GetDiscriminatorType(int* outDataIdx = NULL); void GetUnderlyingArray(BfType*& type, int& size, bool& isVector); bool HasEquivalentLayout(BfTypeInstance* compareTo); BfIRConstHolder* GetOrCreateConstHolder(); - BfIRValue CreateConst(BfConstant* fromConst, BfIRConstHolder* fromHolder); + BfIRValue CreateConst(BfConstant* fromConst, BfIRConstHolder* fromHolder); int GetInstStride() { return BF_ALIGN(mInstSize, mInstAlign); } - bool HasOverrideMethods(); + bool HasOverrideMethods(); bool GetResultInfo(BfType*& valueType, int& okTagId); BfGenericTypeInfo::GenericParamsVector* GetGenericParamsVector(BfTypeDef* declaringTypeDef); void GenerateProjectsReferenced(); - bool IsAlwaysInclude(); + bool IsAlwaysInclude(); bool HasBeenInstantiated() { return mHasBeenInstantiated || ((mAlwaysIncludeFlags & BfAlwaysIncludeFlag_AssumeInstantiated) != 0); } bool IncludeAllMethods() { return ((mAlwaysIncludeFlags & BfAlwaysIncludeFlag_IncludeAllMethods) != 0); } bool DefineStateAllowsStaticMethods() { return mDefineState >= BfTypeDefineState_HasInterfaces_Direct; } @@ -2270,11 +2268,11 @@ public: virtual bool IsObjectOrInterface() override { return true; } virtual bool IsDependentOnUnderlyingType() override { return true; } virtual BfType* GetUnderlyingType() override { return mElementType; } - + virtual BfTypeInstance* ToGenericTypeInstance() override { return mElementType->ToGenericTypeInstance(); } virtual bool IsSpecializedType() override { return !mElementType->IsUnspecializedType(); } virtual bool IsUnspecializedType() override { return mElementType->IsUnspecializedType(); } - virtual bool IsUnspecializedTypeVariation() override { return mElementType->IsUnspecializedTypeVariation(); } + virtual bool IsUnspecializedTypeVariation() override { return mElementType->IsUnspecializedTypeVariation(); } virtual BfTypeInstance* GetImplBaseType() override { return (mBoxedBaseType != NULL) ? mBoxedBaseType : mBaseType; } @@ -2294,10 +2292,10 @@ public: public: BfTypeAliasType() { - mAliasToType = NULL; + mAliasToType = NULL; } - virtual bool IsTypeAlias() override { return true; } + virtual bool IsTypeAlias() override { return true; } virtual BfType* GetUnderlyingType() override { return mAliasToType; } virtual bool WantsGCMarking() override { return mAliasToType->WantsGCMarking(); } }; @@ -2306,17 +2304,17 @@ enum BfCaptureType { BfCaptureType_None, BfCaptureType_Copy, - BfCaptureType_Reference, + BfCaptureType_Reference, }; class BfClosureType : public BfTypeInstance { public: Val128 mClosureHash; // Includes base type and capture info - BfTypeInstance* mSrcDelegate; + BfTypeInstance* mSrcDelegate; bool mCreatedTypeDef; String mNameAdd; - BfSource mSource; + BfSource mSource; Array mDirectAllocNodes; bool mIsUnique; @@ -2329,13 +2327,13 @@ public: BfMethodDef* AddDtor(); void Finish(); - virtual bool IsClosure() override { return true; } - virtual bool IsOnDemand() override { return true; } + virtual bool IsClosure() override { return true; } + virtual bool IsOnDemand() override { return true; } }; class BfDelegateType : public BfTypeInstance { -public: +public: BfDelegateInfo mDelegateInfo; bool mIsUnspecializedType; bool mIsUnspecializedTypeVariation; @@ -2349,10 +2347,10 @@ public: mGenericDepth = 0; } ~BfDelegateType(); - + virtual void Dispose() override; virtual bool IsOnDemand() override { return true; } - + virtual bool IsDelegate() override { return mTypeDef->mIsDelegate; } virtual bool IsDelegateFromTypeRef() override { return mTypeDef->mIsDelegate; } @@ -2372,12 +2370,12 @@ class BfTupleType : public BfTypeInstance { public: bool mCreatedTypeDef; - String mNameAdd; + String mNameAdd; BfSource* mSource; bool mIsUnspecializedType; bool mIsUnspecializedTypeVariation; int mGenericDepth; - + public: BfTupleType(); ~BfTupleType(); @@ -2388,7 +2386,7 @@ public: void Finish(); virtual bool IsOnDemand() override { return true; } - virtual bool IsTuple() override { return true; } + virtual bool IsTuple() override { return true; } virtual bool IsUnspecializedType() override { return mIsUnspecializedType; } virtual bool IsUnspecializedTypeVariation() override { return mIsUnspecializedTypeVariation; } @@ -2436,7 +2434,7 @@ public: String mMangledMethodName; BfTypeInstance* mOwner; int mOwnerRevision; - bool mIsAutoCompleteMethod; + bool mIsAutoCompleteMethod; Array mParamToDataIdx; Array mDataToParamIdx; bool mIsUnspecialized; @@ -2444,17 +2442,17 @@ public: public: BfMethodRefType() - { + { mMethodRef = NULL; mOwner = NULL; mOwnerRevision = -1; - mIsAutoCompleteMethod = false; + mIsAutoCompleteMethod = false; mIsUnspecialized = false; mIsUnspecializedVariation = false; } - ~BfMethodRefType(); - + ~BfMethodRefType(); + //virtual bool IsValuelessType() override { return mSize != 0; } virtual bool IsValueType() override { return true; } virtual bool IsComposite() override { return true; } @@ -2468,15 +2466,14 @@ public: virtual bool IsUnspecializedTypeVariation() override { return mIsUnspecializedVariation; } int GetCaptureDataCount(); - BfType* GetCaptureType(int captureDataIdx); + BfType* GetCaptureType(int captureDataIdx); int GetDataIdxFromParamIdx(int paramIdx); int GetParamIdxFromDataIdx(int dataIdx); bool WantsDataPassedAsSplat(int dataIdx); - + //virtual BfType* GetUnderlyingType() override { return mOwner; } }; - class BfRefType : public BfType { public: @@ -2502,7 +2499,7 @@ public: virtual bool IsIncomplete() override { CheckElement(); return mDefineState < BfTypeDefineState_Defined; } virtual bool IsReified() override { return mElementType->IsReified(); } - virtual bool IsRef() override { return true; } + virtual bool IsRef() override { return true; } virtual bool IsMut() override { return mRefKind == RefKind_Mut; } virtual bool IsIn() override { return mRefKind == RefKind_In; } virtual bool IsOut() override { return mRefKind == RefKind_Out; } @@ -2511,7 +2508,7 @@ public: virtual bool IsUnspecializedType() override { return mElementType->IsUnspecializedType(); } virtual bool IsUnspecializedTypeVariation() override { return mElementType->IsUnspecializedTypeVariation(); } virtual bool CanBeValuelessType() override { return mElementType->CanBeValuelessType(); } - virtual bool IsValuelessType() override { return mElementType->IsValuelessType(); } + virtual bool IsValuelessType() override { return mElementType->IsValuelessType(); } }; class BfArrayType : public BfTypeInstance @@ -2547,11 +2544,11 @@ public: mElementCount = 0; mGenericDepth = 0; mWantsGCMarking = false; - } + } virtual bool IsSizedArray() override { return true; } virtual bool IsUndefSizedArray() override { return mElementCount == -1; } - + virtual bool IsWrappableType() override { return true; } virtual bool IsValueType() override { return true; } // Is a type of struct virtual bool IsValueTypeOrValueTypePtr() override { return true; } @@ -2575,7 +2572,7 @@ public: // This is used when a sized array is sized by a const generic argument class BfUnknownSizedArrayType : public BfSizedArrayType { -public: +public: BfType* mElementCountSource; public: @@ -2593,7 +2590,7 @@ public: virtual BfType* GetUnderlyingType() override { return mElementType; } virtual bool IsUnspecializedType() override { return mElementType->IsUnspecializedType() || mElementCountSource->IsUnspecializedType(); } virtual bool IsUnspecializedTypeVariation() override { return mElementType->IsUnspecializedTypeVariation() || mElementCountSource->IsUnspecializedTypeVariation(); } - virtual bool CanBeValuelessType() override { return true; } + virtual bool CanBeValuelessType() override { return true; } // Leave the default "zero sized" definition //virtual bool IsValuelessType() override { return mElementType->IsValuelessType(); } }; @@ -2604,7 +2601,7 @@ public: BfType* mType; BfVariant mValue; -public: +public: ~BfConstExprValueType(); virtual bool IsConstExprValue() override { return true; } @@ -2616,20 +2613,20 @@ public: /*class BfCustomAttributeArgument { -public: +public: llvm::Constant* mConstParam; };*/ class BfCustomAttributeSetProperty { -public: +public: BfPropertyRef mPropertyRef; BfTypedValue mParam; }; class BfCustomAttributeSetField { -public: +public: BfFieldRef mFieldRef; BfTypedValue mParam; }; @@ -2657,7 +2654,7 @@ public: class BfCustomAttributes { public: - Array mAttributes; + Array mAttributes; bool Contains(BfTypeDef* typeDef); BfCustomAttribute* Get(BfTypeDef* typeDef); BfCustomAttribute* Get(BfType* type); @@ -2668,7 +2665,6 @@ public: class BfResolvedTypeSetFuncs : public MultiHashSetFuncs { - }; class BfResolvedTypeSet : public MultiHashSet @@ -2681,7 +2677,7 @@ public: BfHashFlag_AllowGenericParamConstValue = 2, BfHashFlag_AllowDotDotDot = 4, }; - + struct BfExprResult { BfVariant mValue; @@ -2689,16 +2685,16 @@ public: }; class LookupContext - { + { public: BfModule* mModule; BfTypeReference* mRootTypeRef; - BfTypeDef* mRootTypeDef; + BfTypeDef* mRootTypeDef; BfTypeInstance* mRootOuterTypeInstance; BfType* mRootResolvedType; Dictionary mResolvedTypeMap; Dictionary mResolvedValueMap; - BfResolveTypeRefFlags mResolveFlags; + BfResolveTypeRefFlags mResolveFlags; BfCallingConvention mCallingConvention; bool mHadVar; bool mFailed; @@ -2723,7 +2719,7 @@ public: void SetCachedResolvedType(BfTypeReference* typeReference, BfType* type); BfType* ResolveTypeRef(BfTypeReference* typeReference); - BfTypeDef* ResolveToTypeDef(BfTypeReference* typeReference, BfType** outType = NULL); + BfTypeDef* ResolveToTypeDef(BfTypeReference* typeReference, BfType** outType = NULL); }; public: @@ -2739,7 +2735,7 @@ public: static int DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHashFlags flags, int& hashSeed); static int Hash(BfTypeReference* typeRef, LookupContext* ctx, BfHashFlags flags = BfHashFlag_None, int hashSeed = 0); static int Hash(BfAstNode* typeRefNode, LookupContext* ctx, BfHashFlags flags = BfHashFlag_None, int hashSeed = 0); - + static bool Equals(BfType* lhs, BfType* rhs, LookupContext* ctx); static bool Equals(BfType* lhs, BfTypeReference* rhs, LookupContext* ctx); static bool Equals(BfType* lhs, BfAstNode* rhs, LookupContext* ctx); @@ -2749,16 +2745,16 @@ public: BfResolvedTypeSet() { Rehash(9973); - } + } ~BfResolvedTypeSet(); - + template bool Insert(T* findType, LookupContext* ctx, BfResolvedTypeSet::EntryRef* entryPtr) { CheckRehash(); - int tryCount = 0; + int tryCount = 0; ctx->mFailed = false; BfHashFlags hashFlags = BfHashFlag_AllowRef; @@ -2770,7 +2766,7 @@ public: int hashVal = Hash(findType, ctx, hashFlags); if ((ctx->mFailed) || (ctx->mHadVar)) - { + { return false; } int bucket = (hashVal & 0x7FFFFFFF) % mHashSize; @@ -2796,14 +2792,14 @@ public: } BF_ASSERT(tryCount < 10); } - + if ((ctx->mResolveFlags & BfResolveTypeRefFlag_NoCreate) != 0) return false; - *entryPtr = AddRaw(hashVal); + *entryPtr = AddRaw(hashVal); return true; } - + // Iterator begin(); // Iterator end(); // Iterator erase(Iterator& itr); @@ -2890,7 +2886,7 @@ public: else if (checkType->IsSizedArray()) GetProjectList(((BfSizedArrayType*)checkType)->mElementType, projectList, immutableLength); else if (checkType->IsMethodRef()) - GetProjectList(((BfMethodRefType*)checkType)->mOwner, projectList, immutableLength); + GetProjectList(((BfMethodRefType*)checkType)->mOwner, projectList, immutableLength); } static BfPrimitiveType* GetPrimitiveType(BfModule* module, BfTypeCode typeCode); @@ -2905,10 +2901,10 @@ public: PopulateType(checkTypeInstance->mModule, checkTypeInstance); if (checkType->IsStruct()) - { + { if (checkTypeInstance->mBaseType != NULL) - SplatIterate(dataLambda, checkTypeInstance->mBaseType); - + SplatIterate(dataLambda, checkTypeInstance->mBaseType); + if (checkTypeInstance->mIsUnion) { BfType* unionInnerType = checkTypeInstance->GetUnionInnerType(); diff --git a/IDEHelper/Compiler/BfSource.cpp b/IDEHelper/Compiler/BfSource.cpp index 0458081b..ce731961 100644 --- a/IDEHelper/Compiler/BfSource.cpp +++ b/IDEHelper/Compiler/BfSource.cpp @@ -16,7 +16,7 @@ BfSource::BfSource(BfSystem* bfSystem) if (bfSystem != NULL) mAstAllocManager = &gBfParserCache->mAstAllocManager; mSrc = NULL; - + mSrcLength = 0; mSrcAllocSize = -1; @@ -36,7 +36,7 @@ BfSource::BfSource(BfSystem* bfSystem) BfSource::~BfSource() { - int sourceCount = gSourceCount--; + int sourceCount = gSourceCount--; delete mSourceData; @@ -65,7 +65,7 @@ BfErrorNode* BfSource::CreateErrorNode(BfAstNode* astNode) } void BfSource::AddErrorNode(BfAstNode* astNode) -{ +{ mPendingErrorNodes.push_back(CreateErrorNode(astNode)); } @@ -85,10 +85,10 @@ int BfSource::AllocChars(int charCount) mSrcAllocSize = newAllocSize; BF_ASSERT(mSourceData->ToParser() != NULL); - mSourceData->mSrc = mSrc; + mSourceData->mSrc = mSrc; HadSrcRealloc(); - } + } int retVal = mSrcLength; mSrcLength += charCount; @@ -130,7 +130,7 @@ void BfSource::FinishSideNodes() } void BfSource::Close() -{ +{ // if (mAlloc->mSource == NULL) // { // BF_ASSERT(mErrorRootNode == NULL); @@ -149,4 +149,4 @@ void BfSource::Close() } mIsClosed = true; -} +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfSource.h b/IDEHelper/Compiler/BfSource.h index 10848d15..9f1d221b 100644 --- a/IDEHelper/Compiler/BfSource.h +++ b/IDEHelper/Compiler/BfSource.h @@ -21,7 +21,7 @@ public: ExternalNodesState_Failed }; -public: +public: const char* mSrc; int mSrcLength; BfAstAllocManager* mAstAllocManager; @@ -30,7 +30,7 @@ public: BfRootNode* mSidechannelRootNode; // Holds comments and preprocessor nodes BfRootNode* mRootNode; BfRootNode* mErrorRootNode; - + BfSizedArray mExteriorNodes; int mExteriorNodesCheckIdx; // 0 = unchecked, -1 = failed, >0 means success and equals the BfSystem.mTypesIdx @@ -76,7 +76,7 @@ public: BfAstAllocator* mAlloc; const char* mSrc; int mSrcLength; - int mSrcAllocSize; + int mSrcAllocSize; bool mParsingFailed; bool mIsClosed; uint8* mAstScratch; @@ -86,28 +86,28 @@ public: BfRootNode* mSidechannelRootNode; // Holds comments and preprocessor nodes BfRootNode* mRootNode; BfRootNode* mErrorRootNode; - + BfParser* mNextRevision; BfParser* mPrevRevision; SizedArray mPendingSideNodes; SizedArray mPendingErrorNodes; -public: +public: bool WantsStats(); public: BfSource(BfSystem* bfSystem); virtual ~BfSource(); - virtual BfParser* ToParser() { return NULL; } + virtual BfParser* ToParser() { return NULL; } virtual void HadSrcRealloc() {} - + BfErrorNode* CreateErrorNode(BfAstNode* astNode); - void AddErrorNode(BfAstNode* astNode); - int AllocChars(int charCount); + void AddErrorNode(BfAstNode* astNode); + int AllocChars(int charCount); void FinishSideNodes(); - virtual void Close(); // Writing done, return unused pages but retain used pages + virtual void Close(); // Writing done, return unused pages but retain used pages }; NS_BF_END; \ No newline at end of file diff --git a/IDEHelper/Compiler/BfSourceClassifier.cpp b/IDEHelper/Compiler/BfSourceClassifier.cpp index c69033db..388460ec 100644 --- a/IDEHelper/Compiler/BfSourceClassifier.cpp +++ b/IDEHelper/Compiler/BfSourceClassifier.cpp @@ -8,7 +8,7 @@ BfSourceClassifier::BfSourceClassifier(BfParser* bfParser, CharData* charData) { mParser = bfParser; mCharData = charData; - mSkipMethodInternals = false; + mSkipMethodInternals = false; mSkipTypeDeclarations = false; mSkipAttributes = false; mIsSideChannel = false; @@ -23,7 +23,7 @@ BfSourceClassifier::BfSourceClassifier(BfParser* bfParser, CharData* charData) void BfSourceClassifier::ModifyFlags(BfAstNode* node, uint8 andFlags, uint8 orFlags) { if (node != NULL) - { + { ModifyFlags(node->GetSrcStart(), node->GetSrcEnd(), andFlags, orFlags); } } @@ -35,8 +35,8 @@ void BfSourceClassifier::ModifyFlags(int startPos, int endPos, uint8 andFlags, u endPos = std::min(endPos, mParser->mOrigSrcLength); for (int i = startPos; i < endPos; i++) - { - mCharData[i].mDisplayPassId = mClassifierPassId; + { + mCharData[i].mDisplayPassId = mClassifierPassId; mCharData[i].mDisplayFlags = (mCharData[i].mDisplayFlags & andFlags) | orFlags; } } @@ -62,13 +62,13 @@ void BfSourceClassifier::SetElementType(BfAstNode * node, BfTypeCode typeCode) } void BfSourceClassifier::SetHighestElementType(int startPos, int endPos, BfSourceElementType elementType) -{ +{ if (!mEnabled) return; endPos = BF_MIN(endPos, mParser->mOrigSrcLength); for (int i = startPos; i < endPos; i++) - { + { auto& charData = mCharData[i]; charData.mDisplayPassId = mClassifierPassId; charData.mDisplayTypeId = BF_MAX(charData.mDisplayTypeId, (uint8)elementType); @@ -100,15 +100,15 @@ void BfSourceClassifier::VisitMembers(BfBlock* node) { mPrevNode = NULL; for (auto& childNodeRef : *node) - { + { BfAstNode* child = childNodeRef; child->Accept(this); - mPrevNode = child; + mPrevNode = child; } } bool BfSourceClassifier::IsInterestedInMember(BfAstNode* node, bool forceSkip) -{ +{ if ((mSkipMethodInternals || forceSkip) && (mParser->mCursorIdx != -1) && (!node->Contains(mParser->mCursorIdx, 1, 0))) return false; @@ -121,16 +121,16 @@ void BfSourceClassifier::HandleLeafNode(BfAstNode* node) return; int nodeStart = node->GetSrcStart(); - int srcStart = nodeStart; + int srcStart = nodeStart; int triviaStart = node->GetTriviaStart(); if (triviaStart != -1) { srcStart = triviaStart; - + if ((mIsSideChannel) && (mPrevNode != NULL)) srcStart = std::max(mPrevNode->GetSrcEnd(), srcStart); } - + if (nodeStart != srcStart) SetElementType(srcStart, nodeStart, BfSourceElementType_Normal); //SetElementType(srcStart, node->GetSrcEnd(), BfSourceElementType_Normal); @@ -140,7 +140,6 @@ void BfSourceClassifier::HandleLeafNode(BfAstNode* node) void BfSourceClassifier::Visit(BfAstNode* node) { - } void BfSourceClassifier::Visit(BfErrorNode* errorNode) @@ -153,7 +152,7 @@ void BfSourceClassifier::Visit(BfFieldDeclaration* fieldDecl) { if (!IsInterestedInMember(fieldDecl)) return; - + BfElementVisitor::Visit(fieldDecl); VisitChild(fieldDecl->mConstSpecifier); @@ -188,12 +187,12 @@ void BfSourceClassifier::Visit(BfPreprocessorNode* preprocessorNode) if (!mPreserveFlags) ModifyFlags(preprocessorNode, ~BfSourceElementFlag_CompilerFlags_Mask, 0); SetElementType(preprocessorNode, BfSourceElementType_Normal); - - Visit(preprocessorNode->ToBase()); + + Visit(preprocessorNode->ToBase()); } void BfSourceClassifier::Visit(BfCommentNode* commentNode) -{ +{ HandleLeafNode(commentNode); Visit(commentNode->ToBase()); @@ -236,7 +235,7 @@ void BfSourceClassifier::Visit(BfAttributeDirective* attributeDirective) } } - BfElementVisitor::Visit(attributeDirective); + BfElementVisitor::Visit(attributeDirective); VisitChild(attributeDirective->mAttrCloseToken); @@ -262,7 +261,7 @@ void BfSourceClassifier::Visit(BfAttributeDirective* attributeDirective) for (auto& arg : attributeDirective->mArguments) VisitChild(arg); for (auto& comma : attributeDirective->mCommas) - VisitChild(comma); + VisitChild(comma); VisitChild(attributeDirective->mNextAttribute); } @@ -280,7 +279,7 @@ void BfSourceClassifier::Visit(BfIdentifierNode* identifier) } void BfSourceClassifier::Visit(BfQualifiedNameNode* qualifiedName) -{ +{ Visit((BfAstNode*)qualifiedName); VisitChild(qualifiedName->mLeft); @@ -406,11 +405,11 @@ void BfSourceClassifier::Visit(BfLiteralExpression* literalExpr) void BfSourceClassifier::Visit(BfStringInterpolationExpression* stringInterpolationExpression) { HandleLeafNode(stringInterpolationExpression); - + Visit(stringInterpolationExpression->ToBase()); SetElementType(stringInterpolationExpression, BfSourceElementType_Literal); - VisitChild(stringInterpolationExpression->mAllocNode); + VisitChild(stringInterpolationExpression->mAllocNode); for (auto& expr : stringInterpolationExpression->mExpressions) { SetElementType(expr, BfSourceElementType_Normal); @@ -423,7 +422,7 @@ void BfSourceClassifier::Visit(BfTokenNode* tokenNode) HandleLeafNode(tokenNode); Visit(tokenNode->ToBase()); - + if (BfTokenIsKeyword(tokenNode->GetToken())) SetElementType(tokenNode, BfSourceElementType_Keyword); else @@ -436,15 +435,15 @@ void BfSourceClassifier::Visit(BfInvocationExpression* invocationExpr) Visit(invocationExpr->ToBase()); //BP_ZONE("BfSourceClassifier BfInvocationExpression"); - + BfAstNode* target = invocationExpr->mTarget; if (target == NULL) return; - + VisitChild(invocationExpr->mOpenParen); VisitChild(invocationExpr->mCloseParen); VisitChild(invocationExpr->mGenericArgs); - + if (auto scopedTarget = BfNodeDynCast(target)) { VisitChild(target); @@ -458,27 +457,27 @@ void BfSourceClassifier::Visit(BfInvocationExpression* invocationExpr) VisitChild(qualifiedName->mLeft); VisitChild(qualifiedName->mDot); VisitChild(qualifiedName->mRight); - identifier = qualifiedName->mRight; + identifier = qualifiedName->mRight; } else if ((identifier = BfNodeDynCast(target))) { VisitChild(target); // Leave as BfAttributedIdentifierNode if that's the case - identifier = target; + identifier = target; } else if (auto qualifiedName = BfNodeDynCast(target)) { VisitChild(qualifiedName->mLeft); VisitChild(qualifiedName->mDot); VisitChild(qualifiedName->mRight); - identifier = qualifiedName->mRight; + identifier = qualifiedName->mRight; } else if (auto memberRefExpr = BfNodeDynCast(target)) { VisitChild(memberRefExpr->mTarget); VisitChild(memberRefExpr->mDotToken); VisitChild(memberRefExpr->mMemberName); - identifier = memberRefExpr->mMemberName; + identifier = memberRefExpr->mMemberName; } else { @@ -490,9 +489,9 @@ void BfSourceClassifier::Visit(BfInvocationExpression* invocationExpr) if (auto attrIdentifier = BfNodeDynCast(identifier)) { VisitChild(attrIdentifier->mAttributes); - identifier = attrIdentifier->mIdentifier; + identifier = attrIdentifier->mIdentifier; } - + if (identifier != NULL) SetElementType(identifier, BfSourceElementType_Method); } @@ -551,7 +550,7 @@ void BfSourceClassifier::Visit(BfDestructorDeclaration* dtorDeclaration) } void BfSourceClassifier::Visit(BfMethodDeclaration* methodDeclaration) -{ +{ if (!IsInterestedInMember(methodDeclaration)) return; @@ -559,8 +558,8 @@ void BfSourceClassifier::Visit(BfMethodDeclaration* methodDeclaration) SetAndRestoreValue prevMember(mCurMember, methodDeclaration); - BfElementVisitor::Visit(methodDeclaration); - + BfElementVisitor::Visit(methodDeclaration); + SetElementType(methodDeclaration->mNameNode, BfSourceElementType_Method); if (methodDeclaration->mGenericParams != NULL) @@ -582,7 +581,7 @@ void BfSourceClassifier::Visit(BfMethodDeclaration* methodDeclaration) if (typeRef != NULL) { if (auto namedTypeRef = BfNodeDynCast(typeRef)) - SetElementType(typeRef, BfSourceElementType_GenericParam); + SetElementType(typeRef, BfSourceElementType_GenericParam); else VisitChild(typeRef); } @@ -651,7 +650,7 @@ void BfSourceClassifier::Handle(BfTypeDeclaration* typeDeclaration) llvm::SmallVector mBaseClasses; llvm::SmallVector mBaseClassCommas; - + if (typeDeclaration->mGenericParams != NULL) { for (auto& genericParam : typeDeclaration->mGenericParams->mGenericParams) @@ -712,7 +711,7 @@ void BfSourceClassifier::Visit(BfTypeAliasDeclaration* typeDeclaration) if (typeDeclaration->mIgnoreDeclaration) return; - BfElementVisitor::Visit(typeDeclaration); + BfElementVisitor::Visit(typeDeclaration); } void BfSourceClassifier::Visit(BfUsingDirective* usingDirective) @@ -735,7 +734,7 @@ void BfSourceClassifier::Visit(BfUsingDirective* usingDirective) void BfSourceClassifier::Visit(BfUsingModDirective* usingDirective) { - BfElementVisitor::Visit(usingDirective); + BfElementVisitor::Visit(usingDirective); } void BfSourceClassifier::Visit(BfNamespaceDeclaration* namespaceDeclaration) @@ -760,7 +759,7 @@ bool BfSourceClassifier::WantsSkipParentMethod(BfAstNode* node) { if (!mSkipMethodInternals) return false; - + #ifdef BF_AST_HAS_PARENT_MEMBER if (node->mParent->IsA()) { @@ -798,7 +797,7 @@ void BfSourceClassifier::Visit(BfGenericConstraintsDeclaration* genericConstrain } void BfSourceClassifier::Visit(BfBlock* block) -{ +{ if (WantsSkipParentMethod(block)) return; if (block->mOpenBrace != NULL) @@ -813,7 +812,7 @@ void BfSourceClassifier::Visit(BfRootNode* rootNode) // Clear off the flags at the end ModifyFlags(mParser->mRootNode->GetSrcEnd(), mParser->mOrigSrcLength, 0, 0); - VisitMembers(rootNode); + VisitMembers(rootNode); } void BfSourceClassifier::Visit(BfInlineAsmStatement* asmStmt) @@ -822,7 +821,7 @@ void BfSourceClassifier::Visit(BfInlineAsmStatement* asmStmt) Visit(asmStmt->mOpenBrace); if (asmStmt->mCloseBrace != NULL) Visit(asmStmt->mCloseBrace); - + //VisitMembers(asmStmt); } diff --git a/IDEHelper/Compiler/BfSourceClassifier.h b/IDEHelper/Compiler/BfSourceClassifier.h index 3a956ffd..169ad52e 100644 --- a/IDEHelper/Compiler/BfSourceClassifier.h +++ b/IDEHelper/Compiler/BfSourceClassifier.h @@ -12,7 +12,7 @@ enum BfSourceElementType BfSourceElementType_Normal, BfSourceElementType_Keyword, BfSourceElementType_Literal, - BfSourceElementType_Identifier, + BfSourceElementType_Identifier, BfSourceElementType_Comment, BfSourceElementType_Method, BfSourceElementType_Type, @@ -48,7 +48,7 @@ class BfSourceClassifier : public BfElementVisitor public: struct CharData { - char mChar; + char mChar; uint8 mDisplayPassId; uint8 mDisplayTypeId; uint8 mDisplayFlags; @@ -58,8 +58,8 @@ public: }; public: - BfParser* mParser; - CharData* mCharData; + BfParser* mParser; + CharData* mCharData; bool mEnabled; bool mSkipMethodInternals; bool mSkipTypeDeclarations; @@ -96,7 +96,7 @@ public: virtual void Visit(BfGenericConstraintsDeclaration* genericConstraints) override; virtual void Visit(BfAstNode* node) override; - virtual void Visit(BfErrorNode* errorNode) override; + virtual void Visit(BfErrorNode* errorNode) override; virtual void Visit(BfFieldDeclaration* fieldDecl) override; virtual void Visit(BfFieldDtorDeclaration* fieldDtorDecl) override; virtual void Visit(BfPreprocesorIgnoredSectionNode* preprocesorIgnoredSection) override; @@ -104,10 +104,10 @@ public: virtual void Visit(BfCommentNode* commentNode) override; virtual void Visit(BfAttributeDirective* attributeDirective) override; virtual void Visit(BfIdentifierNode* identifier) override; - virtual void Visit(BfQualifiedNameNode* identifier) override; + virtual void Visit(BfQualifiedNameNode* identifier) override; virtual void Visit(BfThisExpression* thisExpr) override; virtual void Visit(BfBaseExpression* baseExpr) override; - virtual void Visit(BfMemberReferenceExpression* memberRefExpr) override; + virtual void Visit(BfMemberReferenceExpression* memberRefExpr) override; virtual void Visit(BfQualifiedTypeReference* qualifiedType) override; virtual void Visit(BfRefTypeRef* typeRef) override; virtual void Visit(BfArrayTypeRef* arrayType) override; @@ -118,11 +118,11 @@ public: virtual void Visit(BfLiteralExpression* literalExpr) override; virtual void Visit(BfStringInterpolationExpression* stringInterpolationExpression) override; virtual void Visit(BfTokenNode* tokenNode) override; - virtual void Visit(BfInvocationExpression* invocationExpr) override; + virtual void Visit(BfInvocationExpression* invocationExpr) override; virtual void Visit(BfIndexerExpression* indexerExpr) override; - virtual void Visit(BfConstructorDeclaration* ctorDeclaration) override; - virtual void Visit(BfDestructorDeclaration* dtorDeclaration) override; - virtual void Visit(BfMethodDeclaration* methodDeclaration) override; + virtual void Visit(BfConstructorDeclaration* ctorDeclaration) override; + virtual void Visit(BfDestructorDeclaration* dtorDeclaration) override; + virtual void Visit(BfMethodDeclaration* methodDeclaration) override; virtual void Visit(BfPropertyMethodDeclaration* propertyMethodDeclaration) override; virtual void Visit(BfPropertyDeclaration* propertyDeclaration) override; virtual void Visit(BfTypeDeclaration* typeDeclaration) override; diff --git a/IDEHelper/Compiler/BfSourcePositionFinder.cpp b/IDEHelper/Compiler/BfSourcePositionFinder.cpp index 56bc5f33..c67112aa 100644 --- a/IDEHelper/Compiler/BfSourcePositionFinder.cpp +++ b/IDEHelper/Compiler/BfSourcePositionFinder.cpp @@ -13,5 +13,5 @@ BfSourcePositionFinder::BfSourcePositionFinder(BfParser* bfParser, int findPosit void BfSourcePositionFinder::Visit(BfAstNode* node) { if ((mFindPosition >= node->GetSrcStart()) && (mFindPosition <= node->GetSrcEnd())) - mClosestElement = node; -} + mClosestElement = node; +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfSourcePositionFinder.h b/IDEHelper/Compiler/BfSourcePositionFinder.h index eeceae97..7c5c9adc 100644 --- a/IDEHelper/Compiler/BfSourcePositionFinder.h +++ b/IDEHelper/Compiler/BfSourcePositionFinder.h @@ -16,7 +16,7 @@ public: BfSourcePositionFinder(BfParser* bfParser, int findPosition); using BfStructuralVisitor::Visit; - virtual void Visit(BfAstNode* node) override; + virtual void Visit(BfAstNode* node) override; }; NS_BF_END \ No newline at end of file diff --git a/IDEHelper/Compiler/BfStmtEvaluator.cpp b/IDEHelper/Compiler/BfStmtEvaluator.cpp index bc953b30..1d5b6b87 100644 --- a/IDEHelper/Compiler/BfStmtEvaluator.cpp +++ b/IDEHelper/Compiler/BfStmtEvaluator.cpp @@ -41,8 +41,8 @@ USING_NS_BF; bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfScopeData* scopeData) -{ - if ((((mCompiler->mIsResolveOnly) && (!mIsComptimeModule)) || +{ + if ((((mCompiler->mIsResolveOnly) && (!mIsComptimeModule)) || (mBfIRBuilder->mIgnoreWrites)) && (deferredCallEntry->mDeferredBlock == NULL)) { // For resolve entries, we only keep deferred blocks because we need to process them later so we can @@ -56,10 +56,10 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc deferredCallEntry->mIgnored = true; scopeData->mDeferredCallEntries.PushBack(deferredCallEntry); return true; - } + } // We don't need to do a "clear handlers" if we're just adding another dyn to an existing dyn list - bool isDyn = mCurMethodState->mCurScope->IsDyn(scopeData); + bool isDyn = mCurMethodState->mCurScope->IsDyn(scopeData); if (mCurMethodState->mPendingNullConditional != NULL) isDyn = true; @@ -78,7 +78,7 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc SizedArray origParamTypes; BfIRType origReturnType; deferredCallEntry->mModuleMethodInstance.mMethodInstance->GetIRFunctionInfo(this, origReturnType, origParamTypes); - + int sretIdx = deferredCallEntry->mModuleMethodInstance.mMethodInstance->GetStructRetIdx(); BF_ASSERT(origParamTypes.size() == deferredCallEntry->mScopeArgs.size() + ((sretIdx != -1) ? 1 : 0)); @@ -90,7 +90,7 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc paramIdx++; auto scopeArg = deferredCallEntry->mScopeArgs[argIdx]; - if ((scopeArg.IsConst()) || (scopeArg.IsFake())) + if ((scopeArg.IsConst()) || (scopeArg.IsFake())) continue; auto prevInsertBlock = mBfIRBuilder->GetInsertBlock(); @@ -130,9 +130,9 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc AddDependency(deferredCallEntryType, mCurTypeInstance, BfDependencyMap::DependencyFlag_Allocates); mBfIRBuilder->PopulateType(deferredCallEntryType); auto deferredCallEntryTypePtr = CreatePointerType(deferredCallEntryType); - + UpdateSrcPos(mCurMethodInstance->mMethodDef->GetRefNode(), BfSrcPosFlag_NoSetDebugLoc); - + if (listEntry == NULL) { listEntry = new BfDeferredCallEntry(); @@ -183,10 +183,10 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc } mCurMethodState->mCurScope->ClearHandlers(scopeData); - scopeData->mDeferredCallEntries.PushFront(listEntry); + scopeData->mDeferredCallEntries.PushFront(listEntry); } - BfIRValue deferredAlloca; + BfIRValue deferredAlloca; SizedArray types; SizedArray memberNames; int instAlign = 1; @@ -200,19 +200,19 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc { HashContext hashCtx; hashCtx.Mixin(deferredCallEntry->mDeferredBlock->GetSrcStart()); - + auto parserData = deferredCallEntry->mDeferredBlock->GetParserData(); - if (parserData != NULL) + if (parserData != NULL) hashCtx.MixinStr(parserData->mFileName); - + int64 blockId = BfDeferredMethodCallData::GenerateMethodId(this, hashCtx.Finish64()); deferredCallEntry->mBlockId = blockId; auto deferType = deferredCallEntryType; - BfIRType deferIRType; + BfIRType deferIRType; auto int64Type = GetPrimitiveType(BfTypeCode_Int64); - + types.push_back(int64Type); memberNames.push_back("__methodId"); @@ -228,9 +228,9 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc SizedArray llvmTypes; SizedArray diFieldTypes; - + typeName = StrFormat("_BF_DeferredData_%s", BfTypeUtils::HashEncode64(blockId).c_str()); - + auto valueType = ResolveTypeDef(mCompiler->mValueTypeTypeDef); llvmTypes.push_back(mBfIRBuilder->MapType(valueType)); @@ -252,18 +252,18 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc memberPositions.push_back(dataPos); dataPos += type->mSize; - } + } } instSize = dataPos; deferIRType = mBfIRBuilder->CreateStructType(typeName); mBfIRBuilder->StructSetBody(deferIRType, llvmTypes, instSize, instAlign, false); - + auto prevInsertPoint = mBfIRBuilder->GetInsertBlock(); if (!isLooped) mBfIRBuilder->SetInsertPoint(mCurMethodState->mIRHeadBlock); deferredAlloca = mBfIRBuilder->CreateAlloca(deferIRType); - mBfIRBuilder->SetAllocaAlignment(deferredAlloca, instAlign); + mBfIRBuilder->SetAllocaAlignment(deferredAlloca, instAlign); mBfIRBuilder->SetAllocaNoChkStkHint(deferredAlloca); if (!isLooped) mBfIRBuilder->SetInsertPoint(prevInsertPoint); @@ -315,11 +315,11 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc deferredMethodCallData = new BfDeferredMethodCallData(); mDeferredMethodCallData[methodInstance] = deferredMethodCallData; deferredMethodCallData->mMethodId = BfDeferredMethodCallData::GenerateMethodId(this, methodInstance->mIdHash); - + auto int64Type = GetPrimitiveType(BfTypeCode_Int64); auto methodDef = moduleMethodInstance.mMethodInstance->mMethodDef; auto thisType = moduleMethodInstance.mMethodInstance->mMethodInstanceGroup->mOwner; - + types.push_back(int64Type); memberNames.push_back("__methodId"); @@ -340,9 +340,9 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc memberNames.push_back(methodInstance->GetParamName(paramIdx)); } - SizedArray llvmTypes; + SizedArray llvmTypes; - //String typeName; + //String typeName; typeName += StrFormat("_BF_DeferredData_%s", BfTypeUtils::HashEncode64(deferredMethodCallData->mMethodId).c_str()); BfLogSysM("Building type: %s from methodInstance:%p\n", typeName.c_str(), methodInstance); @@ -386,10 +386,10 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc mBfIRBuilder->SetInsertPoint(mCurMethodState->mIRHeadBlock); deferredAlloca = mBfIRBuilder->CreateAlloca(BfIRType(deferredMethodCallData->mDeferType)); mBfIRBuilder->ClearDebugLocation(deferredAlloca); - mBfIRBuilder->SetAllocaAlignment(deferredAlloca, deferredMethodCallData->mAlign); + mBfIRBuilder->SetAllocaAlignment(deferredAlloca, deferredMethodCallData->mAlign); mBfIRBuilder->SetAllocaNoChkStkHint(deferredAlloca); if (!isLooped) - mBfIRBuilder->SetInsertPoint(prevInsertPoint); + mBfIRBuilder->SetInsertPoint(prevInsertPoint); auto gepInstance = mBfIRBuilder->CreateInBoundsGEP(deferredAlloca, 0, 1); auto prevVal = mBfIRBuilder->CreateLoad(listEntry->mDynCallTail); @@ -446,20 +446,20 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc } else { - auto val = mBfIRBuilder->CreateLoad(llvmArgs[argIdx]); + auto val = mBfIRBuilder->CreateLoad(llvmArgs[argIdx]); mBfIRBuilder->CreateStore(val, gepInstance); argIdx++; } } else - { + { mBfIRBuilder->CreateStore(llvmArgs[argIdx], gepInstance); argIdx++; } } mBfIRBuilder->CreateStore(mBfIRBuilder->CreateBitCast(deferredAlloca, mBfIRBuilder->MapType(deferredCallEntryTypePtr)), listEntry->mDynCallTail); - + deferredCallEntry->mDeferredAlloca = deferredAlloca; listEntry->mDynList.PushFront(deferredCallEntry); } @@ -511,18 +511,18 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc diFieldTypes.push_back(memberType); } } - + int diFlags = 0; mBfIRBuilder->DbgMakePermanent(diForwardDecl, BfIRMDNode(), diFieldTypes); deferDIType = mBfIRBuilder->DbgCreatePointerType(diForwardDecl); if (deferredMethodCallData != NULL) - deferredMethodCallData->mDeferDIType = deferDIType; + deferredMethodCallData->mDeferDIType = deferDIType; } - + // We don't actually want to see this, and it doesn't emit properly in LLVM CodeView anyway - it only accepts static allocs, // not dynamic allocas - String varName = StrFormat("$__deferredCall_%d", mCurMethodState->mDeferredLoopListEntryCount); - mCurMethodState->mDeferredLoopListEntryCount++; + String varName = StrFormat("$__deferredCall_%d", mCurMethodState->mDeferredLoopListEntryCount); + mCurMethodState->mDeferredLoopListEntryCount++; auto diVariable = mBfIRBuilder->DbgCreateAutoVariable(mCurMethodState->mCurScope->mDIScope, varName, mCurFilePosition.mFileInstance->mDIFile, mCurFilePosition.mCurLine, deferDIType); mBfIRBuilder->DbgInsertDeclare(deferredAlloca, diVariable); @@ -549,7 +549,7 @@ BfDeferredCallEntry* BfModule::AddDeferredCall(const BfModuleMethodInstance& mod for (auto arg : llvmArgs) { - deferredCallEntry->mScopeArgs.push_back(arg); + deferredCallEntry->mScopeArgs.push_back(arg); } deferredCallEntry->mSrcNode = srcNode; deferredCallEntry->mBypassVirtual = bypassVirtual; @@ -560,11 +560,11 @@ BfDeferredCallEntry* BfModule::AddDeferredCall(const BfModuleMethodInstance& mod } void BfModule::EmitDeferredCall(BfModuleMethodInstance moduleMethodInstance, SizedArrayImpl& llvmArgs, BfDeferredBlockFlags flags) -{ +{ if (moduleMethodInstance.mMethodInstance->GetOwner()->IsInstanceOf(mCompiler->mInternalTypeDef)) { if (moduleMethodInstance.mMethodInstance->mMethodDef->mName.StartsWith("SetDeleted")) - { + { intptr typeSize = 0; intptr typeAlign = 1; intptr clearSize = 0; @@ -576,7 +576,7 @@ void BfModule::EmitDeferredCall(BfModuleMethodInstance moduleMethodInstance, Siz if ((moduleMethodInstance.mMethodInstance->mMethodDef->mName == "SetDeleted") || (moduleMethodInstance.mMethodInstance->mMethodDef->mName == "SetDeletedArray")) - { + { auto constant = mBfIRBuilder->GetConstant(llvmArgs[1]); if (constant != NULL) typeSize = constant->mInt64; @@ -584,7 +584,7 @@ void BfModule::EmitDeferredCall(BfModuleMethodInstance moduleMethodInstance, Siz if (constant != NULL) typeAlign = constant->mInt64; if (llvmArgs.size() >= 4) - arraySize = llvmArgs[3]; + arraySize = llvmArgs[3]; intptr allocSize = typeSize; if (arraySize) @@ -610,7 +610,7 @@ void BfModule::EmitDeferredCall(BfModuleMethodInstance moduleMethodInstance, Siz clearSize = typeSize; arraySize = llvmArgs[1]; isDynSize = true; - } + } else if (moduleMethodInstance.mMethodInstance->mMethodDef->mName == "SetDeleted1") { clearSize = 1; @@ -665,7 +665,7 @@ void BfModule::EmitDeferredCall(BfModuleMethodInstance moduleMethodInstance, Siz mBfIRBuilder->SetInsertPoint(ddDoneBlock); if ((flags & BfDeferredBlockFlag_MoveNewBlocksToEnd) != 0) - { + { mCurMethodState->mCurScope->mAtEndBlocks.push_back(ddSize1Block); mCurMethodState->mCurScope->mAtEndBlocks.push_back(ddDoneBlock); } @@ -736,7 +736,7 @@ void BfModule::EmitDeferredCall(BfModuleMethodInstance moduleMethodInstance, Siz BF_ASSERT(llvmArgs.size() == 3); auto sizeConstant = mBfIRBuilder->GetConstant(llvmArgs[1]); int clearSize = BF_MIN(sizeConstant->mInt32, 32); - + auto alignConstant = mBfIRBuilder->GetConstant(llvmArgs[2]); int clearAlign = alignConstant->mInt32; @@ -752,7 +752,7 @@ void BfModule::EmitDeferredCall(BfModuleMethodInstance moduleMethodInstance, Siz if ((isDtor) && (methodInstance->GetParamCount() != 0)) { // Dtor declared with params - AssertErrorState(); + AssertErrorState(); return; } @@ -778,7 +778,7 @@ void BfModule::EmitDeferredCall(BfModuleMethodInstance moduleMethodInstance, Siz (!skipAccessCheck)) { EmitObjectAccessCheck(BfTypedValue(llvmArgs[0], methodOwner)); - } + } BfExprEvaluator expressionEvaluator(this); expressionEvaluator.CreateCall(NULL, moduleMethodInstance.mMethodInstance, moduleMethodInstance.mFunc, ((flags & BfDeferredBlockFlag_BypassVirtual) != 0), llvmArgs); @@ -798,11 +798,11 @@ void BfModule::EmitDeferredCall(BfModuleMethodInstance moduleMethodInstance, Siz mCurMethodState->mCurScope->mAtEndBlocks.push_back(nullLabel); } } - } + } } void BfModule::EmitDeferredCall(BfDeferredCallEntry& deferredCallEntry, bool moveBlocks) -{ +{ if ((mCompiler->mIsResolveOnly) && (!mIsComptimeModule) && (deferredCallEntry.mHandlerCount > 0)) { // We only want to process deferred blocks once, otherwise it could significantly slow down autocompletion @@ -821,7 +821,7 @@ void BfModule::EmitDeferredCall(BfDeferredCallEntry& deferredCallEntry, bool mov { // Only show warnings on the first pass // For errors, show on the first pass OR as long as we haven't gotten any errors within this method. I'm not sure if there's a case - // where the first emission succeeds but a subsequent one would fail, but we leave this logic to handle that possibility + // where the first emission succeeds but a subsequent one would fail, but we leave this logic to handle that possibility SetAndRestoreValue prevIgnoreErrors(mIgnoreErrors, (deferredCallEntry.mHandlerCount > 1) && (mCurMethodInstance->mHasFailed)); SetAndRestoreValue prevIgnoreWarnings(mIgnoreWarnings, (deferredCallEntry.mHandlerCount > 1)); @@ -841,17 +841,17 @@ void BfModule::EmitDeferredCall(BfDeferredCallEntry& deferredCallEntry, bool mov { auto addr = CreateAlloca(localVar->mResolvedType); mBfIRBuilder->CreateAlignedStore(localVar->mValue, addr, localVar->mResolvedType->mAlign); - localVar->mAddr = addr; - } + localVar->mAddr = addr; + } AddLocalVariableDef(localVar, true); } - + SetAndRestoreValue prevCustomAttribute(mCurMethodState->mEmitRefNode, deferredCallEntry.mEmitRefNode); - VisitEmbeddedStatement(deferredCallEntry.mDeferredBlock, NULL, BfEmbeddedStatementFlags_IsDeferredBlock); + VisitEmbeddedStatement(deferredCallEntry.mDeferredBlock, NULL, BfEmbeddedStatementFlags_IsDeferredBlock); RestoreScopeState(); return; } - + auto args = deferredCallEntry.mScopeArgs; if (deferredCallEntry.mArgsNeedLoad) { @@ -878,7 +878,7 @@ void BfModule::EmitDeferredCall(BfDeferredCallEntry& deferredCallEntry, bool mov } void BfModule::EmitDeferredCallProcessor(SLIList& callEntries, BfIRValue callTail) -{ +{ int64 collisionId = 0; struct _CallInfo @@ -889,7 +889,7 @@ void BfModule::EmitDeferredCallProcessor(SLIList& callEntr //typedef std::map MapType; //MapType methodInstanceMap; - Dictionary methodInstanceMap; + Dictionary methodInstanceMap; int blockCount = 0; HashSet nullCheckMethodSet; @@ -897,7 +897,7 @@ void BfModule::EmitDeferredCallProcessor(SLIList& callEntr BfDeferredCallEntry* deferredCallEntry = callEntries.mHead; while (deferredCallEntry != NULL) { - BfModuleMethodInstance moduleMethodInstance = deferredCallEntry->mModuleMethodInstance; + BfModuleMethodInstance moduleMethodInstance = deferredCallEntry->mModuleMethodInstance; int64 methodId = 0; if (moduleMethodInstance.mMethodInstance != NULL) { @@ -916,7 +916,7 @@ void BfModule::EmitDeferredCallProcessor(SLIList& callEntr // Only bypass virtual if ALL these calls are devirtualized callInfo->mBypassVirtual &= deferredCallEntry->mBypassVirtual; } - } + } else blockCount++; if (deferredCallEntry->mDoNullCheck) @@ -933,12 +933,12 @@ void BfModule::EmitDeferredCallProcessor(SLIList& callEntr BfIRBlock condBB = mBfIRBuilder->CreateBlock("deferCall.cond", true); if (moveBlocks) mCurMethodState->mCurScope->mAtEndBlocks.push_back(condBB); - mBfIRBuilder->CreateBr(condBB); + mBfIRBuilder->CreateBr(condBB); auto deferredCallEntryType = ResolveTypeDef(mCompiler->mDeferredCallTypeDef); auto deferredCallEntryTypePtr = CreatePointerType(deferredCallEntryType); - BfIRBlock bodyBB = mBfIRBuilder->CreateBlock("deferCall.body"); + BfIRBlock bodyBB = mBfIRBuilder->CreateBlock("deferCall.body"); if (moveBlocks) mCurMethodState->mCurScope->mAtEndBlocks.push_back(bodyBB); BfIRBlock endBB = mBfIRBuilder->CreateBlock("deferCall.end"); @@ -950,21 +950,21 @@ void BfModule::EmitDeferredCallProcessor(SLIList& callEntr BfIRValue deferredCallTail; mBfIRBuilder->SetInsertPoint(condBB); - deferredCallTail = mBfIRBuilder->CreateLoad(callTail); + deferredCallTail = mBfIRBuilder->CreateLoad(callTail); auto isNotNull = mBfIRBuilder->CreateIsNotNull(deferredCallTail); ValueScopeEnd(valueScopeStart); - mBfIRBuilder->CreateCondBr(isNotNull, bodyBB, exitBB); + mBfIRBuilder->CreateCondBr(isNotNull, bodyBB, exitBB); mBfIRBuilder->AddBlock(bodyBB); mBfIRBuilder->SetInsertPoint(bodyBB); - - BfIRValue switchInst; + + BfIRValue switchInst; bool wantsSwitch = ((int)methodInstanceMap.size() + blockCount) > 1; if (blockCount > 0) { // A block may embed a switch so we need a switch whenever we have blocks wantsSwitch = true; - } + } if (mCurMethodState->mCancelledDeferredCall) wantsSwitch = true; if (wantsSwitch) @@ -972,7 +972,7 @@ void BfModule::EmitDeferredCallProcessor(SLIList& callEntr if (IsTargetingBeefBackend()) deferredCallTail = mBfIRBuilder->CreateLoad(callTail); auto idPtr = mBfIRBuilder->CreateInBoundsGEP(deferredCallTail, 0, 1); // mMethodId - auto id = mBfIRBuilder->CreateLoad(idPtr); + auto id = mBfIRBuilder->CreateLoad(idPtr); switchInst = mBfIRBuilder->CreateSwitch(id, exitBB, (int)methodInstanceMap.size()); ValueScopeEnd(valueScopeStart); } @@ -984,7 +984,7 @@ void BfModule::EmitDeferredCallProcessor(SLIList& callEntr deferredCallEntry = callEntries.mHead; while (deferredCallEntry != NULL) - { + { auto block = deferredCallEntry->mDeferredBlock; if (block == NULL) { @@ -1058,7 +1058,7 @@ void BfModule::EmitDeferredCallProcessor(SLIList& callEntr BfModuleMethodInstance moduleMethodInstance = deferredCallEntry->mModuleMethodInstance; if (moduleMethodInstance.mMethodInstance != NULL) { - auto deferredMethodCallData = mDeferredMethodCallData[moduleMethodInstance.mMethodInstance]; + auto deferredMethodCallData = mDeferredMethodCallData[moduleMethodInstance.mMethodInstance]; //methodInstanceMap.insert(MapType::value_type(deferredMethodCallData->mMethodId, moduleMethodInstance)); _CallInfo* callInfo = NULL; if (methodInstanceMap.TryAdd(deferredMethodCallData->mMethodId, NULL, &callInfo)) @@ -1092,31 +1092,31 @@ void BfModule::EmitDeferredCallProcessor(SLIList& callEntr if (moveBlocks) mCurMethodState->mCurScope->mAtEndBlocks.push_back(caseBB); mBfIRBuilder->AddSwitchCase(switchInst, GetConstValue64(methodId), caseBB); - mBfIRBuilder->SetInsertPoint(caseBB); + mBfIRBuilder->SetInsertPoint(caseBB); } - + if (IsTargetingBeefBackend()) - deferredCallTail = mBfIRBuilder->CreateLoad(callTail); + deferredCallTail = mBfIRBuilder->CreateLoad(callTail); auto nextPtr = mBfIRBuilder->CreateInBoundsGEP(deferredCallTail, 0, 2); // mNext auto next = mBfIRBuilder->CreateLoad(nextPtr); mBfIRBuilder->CreateStore(next, callTail); - deferredCallInst = mBfIRBuilder->CreateBitCast(deferredCallTail, deferredMethodCallData->mDeferTypePtr); + deferredCallInst = mBfIRBuilder->CreateBitCast(deferredCallTail, deferredMethodCallData->mDeferTypePtr); int paramIdx = 0; if (!methodDef->mIsStatic) paramIdx = -1; - SizedArray llvmArgs; + SizedArray llvmArgs; for (int argIdx = 0; paramIdx < methodInstance->GetParamCount(); argIdx++, paramIdx++) { auto argPtr = mBfIRBuilder->CreateInBoundsGEP(deferredCallInst, 0, argIdx + 2); bool isStruct = false; bool doSplat = methodInstance->GetParamIsSplat(paramIdx);; - BfTypedValue typedVal; + BfTypedValue typedVal; if (paramIdx == -1) { - typedVal = BfTypedValue(argPtr, methodOwner, true); + typedVal = BfTypedValue(argPtr, methodOwner, true); } else { @@ -1142,11 +1142,11 @@ void BfModule::EmitDeferredCallProcessor(SLIList& callEntr if (paramIdx >= methodInstance->GetParamCount()) break; auto paramType = methodInstance->GetParamType(paramIdx); - isStruct = paramType->IsStruct(); + isStruct = paramType->IsStruct(); } if (isStruct) - { + { llvmArgs.push_back(argPtr); } else @@ -1167,7 +1167,7 @@ void BfModule::EmitDeferredCallProcessor(SLIList& callEntr ValueScopeEnd(valueScopeStart); mBfIRBuilder->CreateBr(condBB); } - + if (endBB) { mBfIRBuilder->AddBlock(endBB); @@ -1197,7 +1197,7 @@ void BfModule::TryInitVar(BfAstNode* checkNode, BfLocalVariable* localVar, BfTyp bool isDynamicCast = false; if (varType->IsGenericParam()) - { + { int pass = 0; while (varType->IsGenericParam()) { @@ -1227,10 +1227,10 @@ void BfModule::TryInitVar(BfAstNode* checkNode, BfLocalVariable* localVar, BfTyp if (!IsInSpecializedSection()) { if (initValue.mType != varType) - Warn(BfWarning_CS0472_ValueTypeNullCompare, StrFormat("Variable declaration is always 'true' because static cast cannot fail and a value of type '%s' can never be null", - TypeToString(varType).c_str()), checkNode); + Warn(BfWarning_CS0472_ValueTypeNullCompare, StrFormat("Variable declaration is always 'true' because static cast cannot fail and a value of type '%s' can never be null", + TypeToString(varType).c_str()), checkNode); else - Warn(BfWarning_CS0472_ValueTypeNullCompare, StrFormat("Variable declaration is always 'true' because a value of type '%s' can never be null", + Warn(BfWarning_CS0472_ValueTypeNullCompare, StrFormat("Variable declaration is always 'true' because a value of type '%s' can never be null", TypeToString(varType).c_str()), checkNode); } } @@ -1256,7 +1256,7 @@ void BfModule::TryInitVar(BfAstNode* checkNode, BfLocalVariable* localVar, BfTyp // } if (!isDynamicCast) - { + { //initValue = Cast(checkNode, initValue, varType, (BfCastFlags)(BfCastFlags_Explicit | BfCastFlags_SilentFail)); initValue = Cast(checkNode, initValue, varType); @@ -1264,7 +1264,7 @@ void BfModule::TryInitVar(BfAstNode* checkNode, BfLocalVariable* localVar, BfTyp { checkResult = BfTypedValue(GetConstValue(0, boolType), boolType); } - else + else { if (localVar->mAddr) { @@ -1333,14 +1333,14 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD } BfAutoComplete* bfAutocomplete = NULL; - + // Just a check mBfIRBuilder->GetInsertBlock(); if (mCompiler->mResolvePassData != NULL) - bfAutocomplete = mCompiler->mResolvePassData->mAutoComplete; - if (bfAutocomplete != NULL) - bfAutocomplete->CheckTypeRef(varDecl->mTypeRef, true, true); + bfAutocomplete = mCompiler->mResolvePassData->mAutoComplete; + if (bfAutocomplete != NULL) + bfAutocomplete->CheckTypeRef(varDecl->mTypeRef, true, true); bool isConst = (varDecl->mModSpecifier != NULL) && (varDecl->mModSpecifier->GetToken() == BfToken_Const); bool isReadOnly = (varDecl->mModSpecifier != NULL) && (varDecl->mModSpecifier->GetToken() == BfToken_ReadOnly); @@ -1412,7 +1412,7 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD auto phiVal = mBfIRBuilder->CreatePhi(mBfIRBuilder->MapType(boolType), 2); mBfIRBuilder->AddPhiIncoming(phiVal, mBfIRBuilder->CreateConst(BfTypeCode_Boolean, 0), insertBlock); mBfIRBuilder->AddPhiIncoming(phiVal, mBfIRBuilder->CreateConst(BfTypeCode_Boolean, 1), doAssignBlock); - exprEvaluator->mResult = BfTypedValue(phiVal, boolType); + exprEvaluator->mResult = BfTypedValue(phiVal, boolType); }; bool handled = false; @@ -1430,7 +1430,7 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD BfIRValue dscVal = ExtractValue(initValue, dscDataIdx); auto eqVal = mBfIRBuilder->CreateCmpEQ(dscVal, GetConstValue(tagId, dscType)); exprEvaluator->mResult = BfTypedValue(eqVal, boolType); - + PopulateType(outType); if (!outType->IsValuelessType()) { @@ -1447,7 +1447,7 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD } handled = true; - } + } } if (handled) @@ -1488,7 +1488,7 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD handledVarInit = true; handledVarStore = true; } - }; + }; if ((varDecl->mTypeRef->IsA()) || (isLet)) { @@ -1501,7 +1501,7 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD if (mCurMethodState->mLocalVarSet.TryGet(BfLocalVarEntry(localDef), &shadowEntry)) { auto prevLocal = shadowEntry->mLocalVar; - if (prevLocal->mLocalVarIdx >= mCurMethodState->GetLocalStartIdx()) + if (prevLocal->mLocalVarIdx >= mCurMethodState->GetLocalStartIdx()) { BfExprEvaluator exprEvaluator(this); initValue = exprEvaluator.LoadLocal(prevLocal); @@ -1554,27 +1554,27 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD { auto typeInst = initValue.mType->ToTypeInstance(); if (typeInst != NULL) - { + { PopulateType(typeInst); BfType* outType = NULL; - int tagId = -1; + int tagId = -1; if (typeInst->GetResultInfo(outType, tagId)) { handledExprBoolResult = true; unresolvedType = outType; resolvedType = outType; isReadOnly = isLet; - localDef->mIsReadOnly = isLet; - _DoConditionalInit(outType); + localDef->mIsReadOnly = isLet; + _DoConditionalInit(outType); } } } - } + } } } - if (!initValue) + if (!initValue) { - initValue = GetDefaultTypedValue(GetPrimitiveType(BfTypeCode_Var)); + initValue = GetDefaultTypedValue(GetPrimitiveType(BfTypeCode_Var)); } if (initValue.mType->IsNull()) { @@ -1588,12 +1588,12 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD if ((initValue.IsTempAddr()) && (!localDef->mAddr) && (initValue.mType == resolvedType)) { // Take over value - localDef->mAddr = initValue.mValue; - handledVarInit = true; + localDef->mAddr = initValue.mValue; + handledVarInit = true; if (isLet) { - localDef->mValue = mBfIRBuilder->CreateLoad(localDef->mAddr); + localDef->mValue = mBfIRBuilder->CreateLoad(localDef->mAddr); } } @@ -1612,9 +1612,9 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD unresolvedType = ResolveTypeRef(varDecl->mTypeRef, BfPopulateType_Data, flags); if (unresolvedType == NULL) - unresolvedType = GetPrimitiveType(BfTypeCode_Var); - resolvedType = unresolvedType; - } + unresolvedType = GetPrimitiveType(BfTypeCode_Var); + resolvedType = unresolvedType; + } auto _CheckConst = [&] { @@ -1636,10 +1636,10 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD } } }; - + localDef->mResolvedType = resolvedType; - localDef->mIsReadOnly = isReadOnly; - + localDef->mIsReadOnly = isReadOnly; + if (!initHandled) { if (isLet) @@ -1656,11 +1656,11 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD } _CheckConst(); - + bool localNeedsAddr = false; bool allowValueAccess = true; if (mHasFullDebugInfo) - { + { //if (!IsTargetingBeefBackend()) if (!isConst) @@ -1669,7 +1669,7 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD /*if (mCurMethodInstance->mMethodDef->mName != "Boop2") dbgNeedsAddr = true;*/ } - + // This is required because of lifetime and LLVM domination rules for certain instances of variable declarations in binary conditionals. // IE: if ((something) && (let a = somethingElse)) if ((exprEvaluator != NULL) && (!isConst)) @@ -1677,14 +1677,14 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD localNeedsAddr = true; allowValueAccess = false; } - + if ((varDecl->mEqualsNode != NULL) && (mCompiler->mResolvePassData != NULL) && (mCompiler->mResolvePassData->mAutoComplete != NULL) && (!initHandled)) { mCompiler->mResolvePassData->mAutoComplete->CheckEmptyStart(varDecl->mEqualsNode, resolvedType); } BfIRInitType initType = BfIRInitType_NotSet; - + if (varDecl->mInitializer != NULL) { initType = BfIRInitType_NotNeeded_AliveOnDecl; @@ -1695,11 +1695,11 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD { BfConstResolver constResolver(this); initValue = constResolver.Resolve(varDecl->mInitializer, resolvedType, BfConstResolveFlag_ActualizeValues); - if (!initValue) + if (!initValue) initValue = GetDefaultTypedValue(resolvedType); } - else if (varDecl->mInitializer->IsA()) - { + else if (varDecl->mInitializer->IsA()) + { // Fake 'is assigned' } else @@ -1720,7 +1720,7 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD if ((!handledVarInit) && (initValue)) initValue = Cast(varDecl->mInitializer, initValue, resolvedType, BfCastFlags_PreferAddr); } - + if ((initValue) && (resolvedType->IsUndefSizedArray())) { resolvedType = initValue.mType; @@ -1733,8 +1733,8 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD { // Handled later } - else if (varDecl->mInitializer->IsA()) - { + else if (varDecl->mInitializer->IsA()) + { // Fake 'is assigned' initType = BfIRInitType_Uninitialized; } @@ -1787,8 +1787,8 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD { localDef->mAddr = initValue.mValue; if (localDef->mIsReadOnly) - localDef->mValue = mBfIRBuilder->CreateLoad(localDef->mAddr); - } + localDef->mValue = mBfIRBuilder->CreateLoad(localDef->mAddr); + } if (WantsLifetimes()) mCurMethodState->mCurScope->mDeferredLifetimeEnds.push_back(localDef->mAddr); } @@ -1832,7 +1832,7 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD bool wantsStore = false; if ((initValue) && (!handledVarStore) && (!isConst) && (!initHandled)) - { + { initValue = LoadValue(initValue); if (initValue.IsSplat()) { @@ -1884,16 +1884,16 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD else if ((resolvedType->IsPointer()) || (resolvedType->IsObjectOrInterface())) { exprEvaluator->mResult = BfTypedValue(mBfIRBuilder->CreateIsNotNull(initValue.mValue), boolType); - } + } else if (resolvedType->IsVar()) { exprEvaluator->mResult = GetDefaultTypedValue(GetPrimitiveType(BfTypeCode_Boolean), false, BfDefaultValueKind_Undef); } else - { + { // Always true if ((!IsInSpecializedSection()) && (!resolvedType->IsGenericParam())) - Warn(BfWarning_CS0472_ValueTypeNullCompare, StrFormat("Variable declaration is always 'true' since a value of type '%s' can never be null", + Warn(BfWarning_CS0472_ValueTypeNullCompare, StrFormat("Variable declaration is always 'true' since a value of type '%s' can never be null", TypeToString(initValue.mType).c_str()), varDecl); exprEvaluator->mResult = BfTypedValue(mBfIRBuilder->CreateConst(BfTypeCode_Boolean, 1), boolType); } @@ -1923,11 +1923,11 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD ValidateAllocation(localDef->mResolvedType, varDecl->mTypeRef); if ((exprEvaluator == NULL) && (varDecl->GetSourceData() != NULL)) - UpdateSrcPos(varDecl); + UpdateSrcPos(varDecl); localDef->Init(); if (localDef->mConstValue) - initType = BfIRInitType_NotNeeded; + initType = BfIRInitType_NotNeeded; BfLocalVariable* localVar = AddLocalVariableDef(localDef, true, false, BfIRValue(), initType); if (wantsStore) @@ -1973,7 +1973,7 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfType* type, BfAstNode* na if (nameNode->GetSourceData() != NULL) UpdateSrcPos(nameNode); localDef->Init(); - return AddLocalVariableDef(localDef, true); + return AddLocalVariableDef(localDef, true); } BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varDecl, BfTypedValue val, bool updateSrcLoc, bool forceAddr) @@ -1983,7 +1983,7 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD if (varDecl->mInitializer != NULL) CreateValueFromExpression(varDecl->mInitializer); - auto isLet = varDecl->mTypeRef->IsA(); + auto isLet = varDecl->mTypeRef->IsA(); auto isVar = varDecl->mTypeRef->IsA(); bool isRef = false; @@ -2008,11 +2008,11 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD // type = ResolveTypeRef(varDecl->mTypeRef); // if (type == NULL) // type = mContext->mBfObjectType; -// } +// } BfType* type = NULL; if ((isLet) || (isVar)) - { + { type = val.mType; } else @@ -2020,14 +2020,13 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD type = ResolveTypeRef(varDecl->mTypeRef); } if (type == NULL) - { + { type = GetPrimitiveType(BfTypeCode_Var); val = GetDefaultTypedValue(type); } if ((type->IsVar()) || (type->IsLet())) { - } if (isRef) @@ -2040,16 +2039,16 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD varDecl->mNameNode->ToString(localDef->mName); localDef->mNameNode = BfNodeDynCast(varDecl->mNameNode); localDef->mResolvedType = type; - localDef->mAssignedKind = BfLocalVarAssignKind_Unconditional; + localDef->mAssignedKind = BfLocalVarAssignKind_Unconditional; localDef->mValue = val.mValue; if (isLet) { - localDef->mIsReadOnly = true; + localDef->mIsReadOnly = true; } if ((!localDef->mIsReadOnly) || (mHasFullDebugInfo) || (forceAddr)) { - localDef->mAddr = AllocLocalVariable(localDef->mResolvedType, localDef->mName); + localDef->mAddr = AllocLocalVariable(localDef->mResolvedType, localDef->mName); if ((val.mValue) && (!localDef->mResolvedType->IsValuelessType()) && (!localDef->mResolvedType->IsVar())) { if (localDef->mResolvedType->IsRef()) @@ -2071,7 +2070,7 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD if ((updateSrcLoc) && (varDecl->GetSourceData() != NULL)) UpdateSrcPos(varDecl); localDef->Init(); - return AddLocalVariableDef(localDef, true); + return AddLocalVariableDef(localDef, true); } void BfModule::CheckTupleVariableDeclaration(BfTupleExpression* tupleExpr, BfType* initType) @@ -2114,9 +2113,9 @@ void BfModule::HandleTupleVariableDeclaration(BfVariableDeclaration* varDecl, Bf initTupleType = (BfTypeInstance*)initTupleValue.mType; CheckTupleVariableDeclaration(tupleExpr, initTupleValue.mType); - + for (int varIdx = 0; varIdx < (int)tupleExpr->mValues.size(); varIdx++) - { + { BfType* resolvedType = NULL; BfTypedValue initValue; if ((initTupleType != NULL) && (varIdx < (int)initTupleType->mFieldInstances.size())) @@ -2164,7 +2163,7 @@ void BfModule::HandleTupleVariableDeclaration(BfVariableDeclaration* varDecl, Bf if (!varNameNode->IsExact()) { if (BfTupleExpression* innerTupleExpr = BfNodeDynCast(varNameNode)) - { + { HandleTupleVariableDeclaration(varDecl, innerTupleExpr, initValue, isReadOnly, isConst, false, declBlock); } else if (!varNameNode->IsExact()) @@ -2176,22 +2175,22 @@ void BfModule::HandleTupleVariableDeclaration(BfVariableDeclaration* varDecl, Bf BfLocalVariable* localDef = new BfLocalVariable(); varNameNode->ToString(localDef->mName); - localDef->mNameNode = BfNodeDynCast(varNameNode); + localDef->mNameNode = BfNodeDynCast(varNameNode); localDef->mResolvedType = resolvedType; localDef->mReadFromId = 0; // Don't give usage errors for binds if (isReadOnly) { localDef->mIsReadOnly = true; if ((initValue) && (initValue.mValue.IsConst())) - { + { isConst = true; } } CheckVariableDef(localDef); if ((!isConst) && ((forceAddr) || (!localDef->mIsReadOnly) || (mHasFullDebugInfo))) - { - localDef->mAddr = AllocLocalVariable(resolvedType, localDef->mName); + { + localDef->mAddr = AllocLocalVariable(resolvedType, localDef->mName); } if ((varDecl != NULL) && (varDecl->mEqualsNode != NULL) && (mCompiler->mResolvePassData != NULL) && (mCompiler->mResolvePassData->mAutoComplete != NULL) && (!initHandled)) @@ -2204,13 +2203,13 @@ void BfModule::HandleTupleVariableDeclaration(BfVariableDeclaration* varDecl, Bf if ((!isConst) && (!initHandled)) { if (initValue) - { + { if (!forceAddr) localDef->mValue = initValue.mValue; if (localDef->mAddr) { mBfIRBuilder->CreateStore(initValue.mValue, localDef->mAddr); - } + } } else if ((varDecl == NULL) || (varDecl->mInitializer->IsA())) { @@ -2222,7 +2221,7 @@ void BfModule::HandleTupleVariableDeclaration(BfVariableDeclaration* varDecl, Bf } } - localDef->mAssignedKind = BfLocalVarAssignKind_Unconditional; + localDef->mAssignedKind = BfLocalVarAssignKind_Unconditional; } else if ((varDecl != NULL) && (varDecl->mInitializer == NULL)) { @@ -2268,15 +2267,15 @@ void BfModule::HandleTupleVariableDeclaration(BfVariableDeclaration* varDecl) BfTypedValue initTupleValue; bool hadVarType = false; bool isLet = varDecl->mTypeRef->IsA(); - bool isVar = varDecl->mTypeRef->IsA(); + bool isVar = varDecl->mTypeRef->IsA(); bool wasVarOrLet = isVar || isLet; - + if ((!isLet) && (!isVar)) { ResolveTypeRef(varDecl->mTypeRef); Fail("'var' or 'let' expected", varDecl->mTypeRef); isVar = true; - } + } if ((isVar) || (isLet)) { @@ -2300,10 +2299,10 @@ void BfModule::HandleTupleVariableDeclaration(BfVariableDeclaration* varDecl) } initTupleValue = LoadValue(initTupleValue); - + if ((bfAutocomplete != NULL) && (wasVarOrLet)) bfAutocomplete->CheckVarResolution(varDecl->mTypeRef, initTupleValue.mType); - } + } bool isCompatible = false; if (initTupleValue) @@ -2334,7 +2333,7 @@ void BfModule::HandleCaseEnumMatch_Tuple(BfTypedValue tupleVal, const BfSizedArr auto tupleFieldInstance = &tupleType->mFieldInstances[tupleFieldIdx]; if (tupleFieldIdx >= arguments.size()) - { + { BfError* error = Fail(StrFormat("Not enough parameters specified, expected %d more.", tupleType->mFieldInstances.size() - (int)arguments.size()), tooFewRef); break; } @@ -2364,7 +2363,7 @@ void BfModule::HandleCaseEnumMatch_Tuple(BfTypedValue tupleVal, const BfSizedArr if (wantType == NULL) wantType = mContext->mBfObjectType; if (wantType != NULL) - tupleElement = Cast(varDecl->mTypeRef, tupleElement, wantType); + tupleElement = Cast(varDecl->mTypeRef, tupleElement, wantType); if (!tupleElement) tupleElement = GetDefaultTypedValue(wantType); } @@ -2392,7 +2391,7 @@ void BfModule::HandleCaseEnumMatch_Tuple(BfTypedValue tupleVal, const BfSizedArr { resolvedType = CreatePointerType(resolvedType); - PopulateType(tupleElement.mType); + PopulateType(tupleElement.mType); tupleElement = LoadValue(tupleElement); tupleElement = Cast(binOpExpr->mLeft, tupleElement, resolvedType); @@ -2412,7 +2411,7 @@ void BfModule::HandleCaseEnumMatch_Tuple(BfTypedValue tupleVal, const BfSizedArr } if (tupleFieldInstance->mDataIdx >= 0) - { + { if (auto tupleExpr = BfNodeDynCast(expr)) { if (tupleElement.mType->IsTuple()) @@ -2421,7 +2420,7 @@ void BfModule::HandleCaseEnumMatch_Tuple(BfTypedValue tupleVal, const BfSizedArr if (tupleExpr->mValues.size() > 0) tooFewRef = tupleExpr->mValues[tupleExpr->mValues.size() - 1]; if (tooFewRef == NULL) - tooFewRef = tupleExpr->mOpenParen; + tooFewRef = tupleExpr->mOpenParen; HandleCaseEnumMatch_Tuple(tupleElement, tupleExpr->mValues, tooFewRef, phiVal, matchedBlockStart, matchedBlockEnd, falseBlockStart, falseBlockEnd, hadConditional, clearOutOnMismatch, prevHadFallthrough); continue; } @@ -2457,7 +2456,7 @@ void BfModule::HandleCaseEnumMatch_Tuple(BfTypedValue tupleVal, const BfSizedArr } else enumTagVal = BfTypedValue(mBfIRBuilder->CreateExtractValue(tupleElement.mValue, 2), intType, false); - + int uncondTagId = -1; bool hadConditional = false; exprResult = TryCaseEnumMatch(tupleElementAddr, enumTagVal, expr, NULL, NULL, NULL, uncondTagId, hadConditional, clearOutOnMismatch, prevHadFallthrough); @@ -2495,7 +2494,7 @@ void BfModule::HandleCaseEnumMatch_Tuple(BfTypedValue tupleVal, const BfSizedArr continue; if (argValue.mType->IsRef()) - { + { auto refType = (BfRefType*)argValue.mType; if (refType->mRefKind != BfRefType::RefKind_Out) { @@ -2524,23 +2523,23 @@ void BfModule::HandleCaseEnumMatch_Tuple(BfTypedValue tupleVal, const BfSizedArr argValue = LoadValue(argValue); argValue = Cast(expr, argValue, tupleFieldInstance->GetResolvedType()); if (!argValue) - continue; - + continue; + exprEvaluator.PerformBinaryOperation(expr, expr, BfBinaryOp_Equality, expr, BfBinOpFlag_NoClassify, tupleElement, argValue); exprResult = exprEvaluator.mResult; } - + if (exprResult) { hadConditional = true; if (phiVal) { - auto insertBlock = mBfIRBuilder->GetInsertBlock(); + auto insertBlock = mBfIRBuilder->GetInsertBlock(); mBfIRBuilder->AddPhiIncoming(phiVal, mBfIRBuilder->CreateConst(BfTypeCode_Boolean, 0), insertBlock); } - + matchedBlockStart = matchedBlockEnd = mBfIRBuilder->CreateBlock("match", false); - + mBfIRBuilder->CreateCondBr(exprResult.mValue, matchedBlockStart, falseBlockStart); mBfIRBuilder->AddBlock(matchedBlockStart); mBfIRBuilder->SetInsertPoint(matchedBlockStart); @@ -2568,7 +2567,7 @@ void BfModule::HandleCaseEnumMatch_Tuple(BfTypedValue tupleVal, const BfSizedArr auto curInsertPoint = mBfIRBuilder->GetInsertBlock(); mBfIRBuilder->SetInsertPoint(falseBlockEnd); for (auto& deferredAssign : deferredAssigns) - { + { auto tupleFieldInstance = &tupleType->mFieldInstances[deferredAssign.mFieldIdx]; // We have to re-process the expr because we haven't done it in this branch, and then clear the result out SetAndRestoreValue prevIgnoreErrors(mIgnoreErrors, mHadBuildError); // Don't fail twice @@ -2595,7 +2594,7 @@ void BfModule::HandleCaseEnumMatch_Tuple(BfTypedValue tupleVal, const BfSizedArr CreateValueFromExpression(expr); } - BfAstNode* errorRef = arguments[(int)tupleType->mFieldInstances.size()]; + BfAstNode* errorRef = arguments[(int)tupleType->mFieldInstances.size()]; BfError* error = Fail(StrFormat("Too many arguments, expected %d fewer.", arguments.size() - tupleType->mFieldInstances.size()), errorRef); } } @@ -2630,7 +2629,7 @@ BfTypedValue BfModule::TryCaseTupleMatch(BfTypedValue tupleVal, BfTupleExpressio auto methodMatchInfo = autoComplete->mMethodMatchInfo; // auto methodDef = tupleType->mTypeDef->mMethods[0]; -// +// // BfAutoComplete::MethodMatchEntry methodMatchEntry; // methodMatchEntry.mMethodDef = methodDef; // methodMatchEntry.mTypeInstance = tupleType; @@ -2723,12 +2722,12 @@ BfTypedValue BfModule::TryCaseTupleMatch(BfTypedValue tupleVal, BfTupleExpressio BfIRValue phiVal; if (eqBlock == NULL) phiVal = mBfIRBuilder->CreatePhi(mBfIRBuilder->MapType(boolType), 2); - + mBfIRBuilder->SetInsertPoint(matchedBlockStart); BfIRBlock matchedBlockEnd = matchedBlockStart; - HandleCaseEnumMatch_Tuple(tupleVal, tupleExpr->mValues, tooFewRef, falseBlockStart ? BfIRValue() : phiVal, matchedBlockStart, matchedBlockEnd, + HandleCaseEnumMatch_Tuple(tupleVal, tupleExpr->mValues, tooFewRef, falseBlockStart ? BfIRValue() : phiVal, matchedBlockStart, matchedBlockEnd, falseBlockStart ? falseBlockStart : doneBlockStart, falseBlockEnd ? falseBlockEnd : doneBlockEnd, hadConditional, clearOutOnMismatch, prevHadFallthrough); - + if (phiVal) { auto falseVal = mBfIRBuilder->CreateConst(BfTypeCode_Boolean, 0); @@ -2777,7 +2776,7 @@ BfTypedValue BfModule::TryCaseEnumMatch(BfTypedValue enumVal, BfTypedValue tagVa { targetType = enumVal.mType; } - else if (auto typeRef = BfNodeDynCast(memberRefExpr->mTarget)) + else if (auto typeRef = BfNodeDynCast(memberRefExpr->mTarget)) { SetAndRestoreValue prevIgnoreErrors(mIgnoreErrors, true); targetType = ResolveTypeRef(typeRef); @@ -2829,7 +2828,7 @@ BfTypedValue BfModule::TryCaseEnumMatch(BfTypedValue enumVal, BfTypedValue tagVa TypeToString(enumVal.mType).c_str(), TypeToString(enumType).c_str())); enumVal = GetDefaultTypedValue(enumType); tagVal = GetDefaultTypedValue(tagType); - } + } for (int fieldIdx = 0; fieldIdx < (int)enumType->mFieldInstances.size(); fieldIdx++) { @@ -2849,7 +2848,7 @@ BfTypedValue BfModule::TryCaseEnumMatch(BfTypedValue enumVal, BfTypedValue tagVa if (resolvePassData->mGetSymbolReferenceKind == BfGetSymbolReferenceKind_Field) resolvePassData->HandleFieldReference(nameNode, enumType->mTypeDef, fieldDef); String filter; - auto autoComplete = resolvePassData->mAutoComplete; + auto autoComplete = resolvePassData->mAutoComplete; if ((autoComplete != NULL) && (autoComplete->InitAutocomplete(dotNode, nameNode, filter))) autoComplete->AddEnumTypeMembers(enumType, enumCaseName, false, enumType == mCurTypeInstance); } @@ -2870,10 +2869,10 @@ BfTypedValue BfModule::TryCaseEnumMatch(BfTypedValue enumVal, BfTypedValue tagVa BfIRBlock falseBlockEnd; BfIRBlock doneBlockStart; BfIRBlock doneBlockEnd; - if (notEqBlock != NULL) + if (notEqBlock != NULL) doneBlockStart = doneBlockEnd = *notEqBlock; - else - doneBlockStart = doneBlockEnd = mBfIRBuilder->CreateBlock("caseDone", false); + else + doneBlockStart = doneBlockEnd = mBfIRBuilder->CreateBlock("caseDone", false); if (clearOutOnMismatch) { @@ -2886,32 +2885,32 @@ BfTypedValue BfModule::TryCaseEnumMatch(BfTypedValue enumVal, BfTypedValue tagVa if (matchBlock != NULL) *matchBlock = matchedBlockStart; mBfIRBuilder->CreateCondBr(eqResult, matchedBlockStart, falseBlockStart ? falseBlockStart : doneBlockStart); - + mBfIRBuilder->AddBlock(matchedBlockStart); - + mBfIRBuilder->SetInsertPoint(doneBlockEnd); BfIRValue phiVal; if (eqBlock == NULL) phiVal = mBfIRBuilder->CreatePhi(mBfIRBuilder->MapType(boolType), 1 + (int)tupleType->mFieldInstances.size()); - + mBfIRBuilder->SetInsertPoint(matchedBlockEnd); - + BfTypedValue tupleVal; if (!enumVal.IsAddr()) { auto unionInnerType = enumType->GetUnionInnerType(); if (unionInnerType == tupleType) - { - tupleVal = ExtractValue(enumVal, NULL, 1); + { + tupleVal = ExtractValue(enumVal, NULL, 1); } } if (!tupleVal) - { + { if (!tupleType->IsValuelessType()) { tupleVal = ExtractValue(enumVal, NULL, 1); - tupleVal = Cast(NULL, tupleVal, tupleType, BfCastFlags_Force); + tupleVal = Cast(NULL, tupleVal, tupleType, BfCastFlags_Force); } else tupleVal = GetDefaultTypedValue(tupleType); @@ -2923,7 +2922,7 @@ BfTypedValue BfModule::TryCaseEnumMatch(BfTypedValue enumVal, BfTypedValue tagVa if ((tooFewRef == NULL) && (!invocationExpr->mCommas.IsEmpty())) tooFewRef = invocationExpr->mCommas[invocationExpr->mCommas.size() - 1]; else if (tooFewRef == NULL) - tooFewRef = invocationExpr->mOpenParen; + tooFewRef = invocationExpr->mOpenParen; /// @@ -2936,7 +2935,7 @@ BfTypedValue BfModule::TryCaseEnumMatch(BfTypedValue enumVal, BfTypedValue tagVa autoComplete->CheckInvocation(invocationExpr, invocationExpr->mOpenParen, invocationExpr->mCloseParen, invocationExpr->mCommas); if (autoComplete->mIsCapturingMethodMatchInfo) - { + { autoComplete->mMethodMatchInfo->mInstanceList.Clear(); auto methodMatchInfo = autoComplete->mMethodMatchInfo; @@ -2979,7 +2978,7 @@ BfTypedValue BfModule::TryCaseEnumMatch(BfTypedValue enumVal, BfTypedValue tagVa if (fieldDef->IsUnnamedTupleField()) insertStr = "p"; insertStr += fieldDef->mName; - + insertStr.Insert(0, "let "); autoComplete->mEntriesSet.Clear(); autoComplete->AddEntry(AutoCompleteEntry("paramName", insertStr)); @@ -2999,7 +2998,7 @@ BfTypedValue BfModule::TryCaseEnumMatch(BfTypedValue enumVal, BfTypedValue tagVa /// - HandleCaseEnumMatch_Tuple(tupleVal, invocationExpr->mArguments, tooFewRef, falseBlockStart ? BfIRValue() : phiVal, matchedBlockStart, matchedBlockEnd, + HandleCaseEnumMatch_Tuple(tupleVal, invocationExpr->mArguments, tooFewRef, falseBlockStart ? BfIRValue() : phiVal, matchedBlockStart, matchedBlockEnd, falseBlockStart ? falseBlockStart : doneBlockStart, falseBlockEnd ? falseBlockEnd : doneBlockEnd, hadConditional, clearOutOnMismatch, prevHadFallthrough); @@ -3022,7 +3021,7 @@ BfTypedValue BfModule::TryCaseEnumMatch(BfTypedValue enumVal, BfTypedValue tagVa mBfIRBuilder->CreateBr(doneBlockStart); if (falseBlockEnd) - { + { mBfIRBuilder->SetInsertPoint(falseBlockEnd); mBfIRBuilder->CreateBr(doneBlockStart); //mBfIRBuilder->AddPhiIncoming(phiVal, mBfIRBuilder->CreateConst(BfTypeCode_Boolean, 0), falseBlock); @@ -3043,7 +3042,7 @@ BfTypedValue BfModule::TryCaseEnumMatch(BfTypedValue enumVal, BfTypedValue tagVa BfTypedValue BfModule::HandleCaseBind(BfTypedValue enumVal, const BfTypedValue& tagVal, BfEnumCaseBindExpression* bindExpr, BfIRBlock* eqBlock, BfIRBlock* notEqBlock, BfIRBlock* matchBlock, int* outEnumIdx) { - BfTypeInstance* tupleType = NULL; + BfTypeInstance* tupleType = NULL; auto activeTypeDef = GetActiveTypeDef(); @@ -3073,9 +3072,8 @@ BfTypedValue BfModule::HandleCaseBind(BfTypedValue enumVal, const BfTypedValue& } else if (auto typeRef = BfNodeDynCast(memberExpr->mTarget)) { - type = ResolveTypeRef(typeRef); + type = ResolveTypeRef(typeRef); } - } targetNode = memberExpr->mTarget; @@ -3096,7 +3094,7 @@ BfTypedValue BfModule::HandleCaseBind(BfTypedValue enumVal, const BfTypedValue& } if (!findName.empty()) - { + { if (type != NULL) { if (type != enumVal.mType) @@ -3112,7 +3110,7 @@ BfTypedValue BfModule::HandleCaseBind(BfTypedValue enumVal, const BfTypedValue& { auto fieldDef = fieldInstance.GetFieldDef(); if ((fieldDef != NULL) && (fieldDef->IsEnumCaseEntry()) && (fieldDef->mName == findName)) - { + { if ((!enumType->IsTypeMemberIncluded(fieldDef->mDeclaringType, activeTypeDef, this)) || (!enumType->IsTypeMemberAccessible(fieldDef->mDeclaringType, activeTypeDef))) continue; @@ -3123,7 +3121,7 @@ BfTypedValue BfModule::HandleCaseBind(BfTypedValue enumVal, const BfTypedValue& if (resolvePassData->mGetSymbolReferenceKind == BfGetSymbolReferenceKind_Field) resolvePassData->HandleFieldReference(nameNode, enumType->mTypeDef, fieldDef); String filter; - auto autoComplete = resolvePassData->mAutoComplete; + auto autoComplete = resolvePassData->mAutoComplete; if ((autoComplete != NULL) && (autoComplete->InitAutocomplete(dotNode, nameNode, filter))) autoComplete->AddEnumTypeMembers(enumType, findName, false, enumType == mCurTypeInstance); } @@ -3145,8 +3143,8 @@ BfTypedValue BfModule::HandleCaseBind(BfTypedValue enumVal, const BfTypedValue& { Fail(StrFormat("Type '%s' is not an enum type", TypeToString(type).c_str()), targetNode); } - } - } + } + } BF_ASSERT(tagVal.mType->IsPrimitiveType()); eqResult = mBfIRBuilder->CreateCmpEQ(tagVal.mValue, mBfIRBuilder->CreateConst(((BfPrimitiveType*)tagVal.mType)->mTypeDef->mTypeCode, enumIdx)); @@ -3168,7 +3166,7 @@ BfTypedValue BfModule::HandleCaseBind(BfTypedValue enumVal, const BfTypedValue& auto mainBlock = mBfIRBuilder->GetInsertBlock(); - BfIRBlock trueBlock = mBfIRBuilder->CreateBlock("eqBlock", false); + BfIRBlock trueBlock = mBfIRBuilder->CreateBlock("eqBlock", false); if (matchBlock != NULL) *matchBlock = trueBlock; mBfIRBuilder->AddBlock(trueBlock); @@ -3197,7 +3195,7 @@ BfTypedValue BfModule::HandleCaseBind(BfTypedValue enumVal, const BfTypedValue& { tupleVal = MakeAddressable(tupleVal); tupleVal = BfTypedValue(mBfIRBuilder->CreateBitCast(tupleVal.mValue, mBfIRBuilder->MapTypeInstPtr(tupleType)), tupleType, true); - } + } } HandleTupleVariableDeclaration(NULL, bindExpr->mBindNames, tupleVal, isLet, false, true /*, &mainBlock*/); @@ -3214,12 +3212,12 @@ BfTypedValue BfModule::HandleCaseBind(BfTypedValue enumVal, const BfTypedValue& mBfIRBuilder->CreateBr(falseBlock); // Don't create the condBr until now, so HandleTupleVariableDeclaration can create the variable declarations in mainBlock-- - // we need them there since the code that uses the new variables is created outside the eqBlock + // we need them there since the code that uses the new variables is created outside the eqBlock mBfIRBuilder->SetInsertPoint(mainBlock); mBfIRBuilder->CreateCondBr(eqResult, trueBlock, falseBlock); mBfIRBuilder->AddBlock(falseBlock); - mBfIRBuilder->SetInsertPoint(falseBlock); + mBfIRBuilder->SetInsertPoint(falseBlock); return BfTypedValue(eqResult, boolType); } @@ -3277,11 +3275,11 @@ void BfModule::VisitEmbeddedStatement(BfAstNode* stmt, BfExprEvaluator* exprEval } else if (mCurMethodState != NULL) { - bool isIgnore = mBfIRBuilder->mIgnoreWrites; - + bool isIgnore = mBfIRBuilder->mIgnoreWrites; + mCurMethodState->mInHeadScope = false; - BfScopeData scopeData; + BfScopeData scopeData; if (IsTargetingBeefBackend()) scopeData.mValueScopeStart = mBfIRBuilder->CreateValueScopeStart(); @@ -3290,13 +3288,13 @@ void BfModule::VisitEmbeddedStatement(BfAstNode* stmt, BfExprEvaluator* exprEval { mCurMethodState->mCurScope->mAstBlock = block; mCurMethodState->mCurScope->mCloseNode = closeBrace; - } + } if (labelNode != NULL) scopeData.mLabelNode = labelNode->mLabel; NewScopeState(block != NULL); mCurMethodState->mCurScope->mOuterIsConditional = (flags & BfEmbeddedStatementFlags_IsConditional) != 0; mCurMethodState->mCurScope->mIsDeferredBlock = (flags & BfEmbeddedStatementFlags_IsDeferredBlock) != 0; - mCurMethodState->mCurScope->mExprEvaluator = exprEvaluator; + mCurMethodState->mCurScope->mExprEvaluator = exprEvaluator; // { @@ -3357,7 +3355,7 @@ void BfModule::VisitCodeBlock(BfBlock* block, BfIRBlock continueBlock, BfIRBlock SetAndRestoreValue prevBreakData(mCurMethodState->mBreakData, &breakData); VisitEmbeddedStatement(block, NULL, flags); - if (closeScope) + if (closeScope) RestoreScopeState(); if ((!mCurMethodState->mLeftBlockUncond) && (defaultBreak)) @@ -3380,15 +3378,15 @@ void BfModule::VisitCodeBlock(BfBlock* block) BfIRBlock prevInsertBlock; bool hadReturn = false; - + int startLocalMethod = 0; // was -1 auto rootMethodState = mCurMethodState->GetRootMethodState(); - BfIRBlock startInsertBlock = mBfIRBuilder->GetInsertBlock(); + BfIRBlock startInsertBlock = mBfIRBuilder->GetInsertBlock(); bool allowLocalMethods = mCurMethodInstance != NULL; //int startDeferredLocalIdx = (int)rootMethodState->mDeferredLocalMethods.size(); - + int curLocalMethodIdx = -1; // Scan for any local method declarations @@ -3404,7 +3402,7 @@ void BfModule::VisitCodeBlock(BfBlock* block) { BfLocalMethod* localMethod; auto rootMethodState = mCurMethodState->GetRootMethodState(); - + String methodName; if (localMethodDecl->mMethodDeclaration->mNameNode != NULL) { @@ -3433,7 +3431,7 @@ void BfModule::VisitCodeBlock(BfBlock* block) auto autoComplete = mCompiler->mResolvePassData->mAutoComplete; if (!autoComplete->IsAutocompleteNode(localMethod->mMethodDeclaration)) localMethod->mDeclOnly = true; - } + } if (localMethod->mMethodDeclaration->mNameNode != NULL) localMethod->mMethodName = localMethod->mMethodDeclaration->mNameNode->ToString(); @@ -3449,11 +3447,11 @@ void BfModule::VisitCodeBlock(BfBlock* block) localMethod->mDeclMixinState->mHasDeferredUsage = true; mCurMethodState->mLocalMethods.push_back(localMethod); - String* namePtr; - if (!mCurMethodState->mLocalMethodMap.TryAdd(localMethod->mMethodName, &namePtr, &localMethodPtr)) - { + String* namePtr; + if (!mCurMethodState->mLocalMethodMap.TryAdd(localMethod->mMethodName, &namePtr, &localMethodPtr)) + { BF_ASSERT(localMethod != *localMethodPtr); - localMethod->mNextWithSameName = *localMethodPtr; + localMethod->mNextWithSameName = *localMethodPtr; } *localMethodPtr = localMethod; } @@ -3463,7 +3461,7 @@ void BfModule::VisitCodeBlock(BfBlock* block) } bool wantsAllLocalMethods = true; - auto autoComplete = mCompiler->GetAutoComplete(); + auto autoComplete = mCompiler->GetAutoComplete(); if (autoComplete != NULL) { // If we only need reasoning "at the cursor" then we don't need all local methods @@ -3496,7 +3494,7 @@ void BfModule::VisitCodeBlock(BfBlock* block) BfAstNode* child = *itr; if (auto localMethodDecl = BfNodeDynCastExact(child)) - { + { /*if ((mCurMethodInstance != NULL) && (mCurMethodInstance->mMethodDef->mMethodType == BfMethodType_Mixin)) Fail("Mixins cannot contain local methods", child);*/ @@ -3525,12 +3523,11 @@ void BfModule::VisitCodeBlock(BfBlock* block) continue; } - if ((mCurMethodState != NULL) && (mCurMethodState->mLeftBlockUncond)) // mLeftBlock is cleared after conditional block is completed { if (mCurMethodState->mHadReturn) hadReturn = true; - + if ((!hadUnreachableCode) && (!mCurMethodState->mInPostReturn)) { if ((mCurMethodState->mCurScope == NULL) || (!mCurMethodState->mCurScope->mSupressNextUnreachable)) @@ -3539,9 +3536,9 @@ void BfModule::VisitCodeBlock(BfBlock* block) hadUnreachableCode = true; prevInsertBlock = mBfIRBuilder->GetInsertBlock(); - mCurMethodState->mInPostReturn = true; + mCurMethodState->mInPostReturn = true; mBfIRBuilder->mIgnoreWrites = true; - } + } } if ((mCurMethodState != NULL) && (mCurMethodState->mCurScope != NULL)) mCurMethodState->mCurScope->mSupressNextUnreachable = false; @@ -3549,7 +3546,7 @@ void BfModule::VisitCodeBlock(BfBlock* block) if (itr.IsLast()) { if (auto expr = BfNodeDynCast(child)) - { + { if (expr->IsExpression()) { if (mCurMethodState != NULL) @@ -3572,19 +3569,19 @@ void BfModule::VisitCodeBlock(BfBlock* block) if ((exprEvaluator->mResult) && (!exprEvaluator->mResult.mType->IsValuelessType()) && (!exprEvaluator->mResult.mValue.IsConst()) && (!exprEvaluator->mResult.IsAddr()) && (!exprEvaluator->mResult.mValue.IsFake())) - { - if ((mCurMethodState->mCurScope != NULL) && (mCurMethodState->mCurScope->mPrevScope != NULL)) + { + if ((mCurMethodState->mCurScope != NULL) && (mCurMethodState->mCurScope->mPrevScope != NULL)) { // We need to make sure we don't retain any values through the scope's ValueScopeHardEnd - and extend alloca through previous scope bool wasReadOnly = exprEvaluator->mResult.IsReadOnly(); - FixIntUnknown(exprEvaluator->mResult, exprEvaluator->mExpectingType); - auto prevInsertBlock = mBfIRBuilder->GetInsertBlock(); + FixIntUnknown(exprEvaluator->mResult, exprEvaluator->mExpectingType); + auto prevInsertBlock = mBfIRBuilder->GetInsertBlock(); auto tempVar = CreateAlloca(exprEvaluator->mResult.mType, false, "blockExpr"); mBfIRBuilder->SetInsertPointAtStart(startInsertBlock); auto lifetimeStart = mBfIRBuilder->CreateLifetimeStart(tempVar); mBfIRBuilder->ClearDebugLocation(lifetimeStart); - + if (!mBfIRBuilder->mIgnoreWrites) mCurMethodState->mCurScope->mPrevScope->mDeferredLifetimeEnds.push_back(tempVar); mBfIRBuilder->SetInsertPoint(prevInsertBlock); @@ -3595,7 +3592,7 @@ void BfModule::VisitCodeBlock(BfBlock* block) exprEvaluator->mResult = BfTypedValue(tempVar, exprEvaluator->mResult.mType, exprEvaluator->mResult.IsThis() ? (wasReadOnly ? BfTypedValueKind_ReadOnlyThisAddr : BfTypedValueKind_ThisAddr) : - (wasReadOnly ? BfTypedValueKind_ReadOnlyAddr : BfTypedValueKind_Addr)); + (wasReadOnly ? BfTypedValueKind_ReadOnlyAddr : BfTypedValueKind_Addr)); } } @@ -3625,10 +3622,10 @@ void BfModule::VisitCodeBlock(BfBlock* block) } } } - } + } } - - UpdateSrcPos(child); + + UpdateSrcPos(child); BfAutoParentNodeEntry autoParentNode(this, child); if ((mAttributeState != NULL) && @@ -3638,14 +3635,14 @@ void BfModule::VisitCodeBlock(BfBlock* block) } else child->Accept(this); - + mContext->CheckLockYield(); ++itr; } if (mCurMethodState != NULL) - { + { // Any local method that hasn't been called needs to be processed now for (int localMethodIdx = startLocalMethod; localMethodIdx < (int)mCurMethodState->mLocalMethods.size(); localMethodIdx++) { @@ -3659,9 +3656,9 @@ void BfModule::VisitCodeBlock(BfBlock* block) } while ((int)mCurMethodState->mLocalMethods.size() > startLocalMethod) - { + { auto localMethod = mCurMethodState->mLocalMethods.back(); - + #if _DEBUG BfLocalMethod** localMethodPtr = NULL; mCurMethodState->mLocalMethodMap.TryGetValue(localMethod->mMethodName, &localMethodPtr); @@ -3674,8 +3671,8 @@ void BfModule::VisitCodeBlock(BfBlock* block) mCurMethodState->mLocalMethodMap[localMethod->mMethodName] = localMethod->mNextWithSameName; localMethod->mNextWithSameName = NULL; } - - mCurMethodState->mLocalMethods.pop_back(); + + mCurMethodState->mLocalMethods.pop_back(); } if (hadUnreachableCode) @@ -3684,11 +3681,11 @@ void BfModule::VisitCodeBlock(BfBlock* block) mCurMethodState->SetHadReturn(true); mCurMethodState->mLeftBlockUncond = true; mCurMethodState->mInPostReturn = false; - + if (prevInsertBlock) mBfIRBuilder->SetInsertPoint(prevInsertBlock); } - } + } } void BfModule::Visit(BfAstNode* astNode) @@ -3698,7 +3695,7 @@ void BfModule::Visit(BfAstNode* astNode) void BfModule::Visit(BfIdentifierNode* identifierNode) { - Visit((BfExpression*)identifierNode); + Visit((BfExpression*)identifierNode); } void BfModule::Visit(BfTypeReference* typeRef) @@ -3710,7 +3707,6 @@ void BfModule::Visit(BfTypeReference* typeRef) void BfModule::Visit(BfEmptyStatement* astNode) { - } void BfModule::Visit(BfTryStatement* tryStmt) @@ -3737,7 +3733,7 @@ void BfModule::Visit(BfCheckedStatement* checkedStmt) } void BfModule::Visit(BfUncheckedStatement* uncheckedStmt) -{ +{ VisitChild(uncheckedStmt->mStatement); } @@ -3751,7 +3747,7 @@ void BfModule::DoIfStatement(BfIfStatement* ifStmt, bool includeTrueStmt, bool i { AssertErrorState(); return; - } + } //TODO: Only conditionally create the scopeData here if we create a variable inside the condition statement @@ -3762,30 +3758,30 @@ void BfModule::DoIfStatement(BfIfStatement* ifStmt, bool includeTrueStmt, bool i newScope.mScopeKind = BfScopeKind_StatementTarget; if (ifStmt->mLabelNode != NULL) newScope.mLabelNode = ifStmt->mLabelNode->mLabel; - mCurMethodState->AddScope(&newScope); + mCurMethodState->AddScope(&newScope); NewScopeState(); - BfBreakData breakData; + BfBreakData breakData; breakData.mScope = &newScope; - breakData.mPrevBreakData = mCurMethodState->mBreakData; - SetAndRestoreValue prevBreakData(mCurMethodState->mBreakData, &breakData); + breakData.mPrevBreakData = mCurMethodState->mBreakData; + SetAndRestoreValue prevBreakData(mCurMethodState->mBreakData, &breakData); - auto boolType = GetPrimitiveType(BfTypeCode_Boolean); + auto boolType = GetPrimitiveType(BfTypeCode_Boolean); - BfDeferredLocalAssignData deferredLocalAssignData(mCurMethodState->mCurScope); + BfDeferredLocalAssignData deferredLocalAssignData(mCurMethodState->mCurScope); deferredLocalAssignData.mIsIfCondition = true; deferredLocalAssignData.ExtendFrom(mCurMethodState->mDeferredLocalAssignData, true); deferredLocalAssignData.mVarIdBarrier = mCurMethodState->GetRootMethodState()->mCurLocalVarId; SetAndRestoreValue prevDLA(mCurMethodState->mDeferredLocalAssignData, &deferredLocalAssignData); BfAutoParentNodeEntry autoParentNodeEntry(this, ifStmt); - BfTypedValue condValue = CreateValueFromExpression(ifStmt->mCondition, boolType); + BfTypedValue condValue = CreateValueFromExpression(ifStmt->mCondition, boolType); newScope.mScopeKind = BfScopeKind_Normal; deferredLocalAssignData.mIsIfCondition = false; - // The "extend chain" is only valid for the conditional -- since that expression may contain unconditionally executed and + // The "extend chain" is only valid for the conditional -- since that expression may contain unconditionally executed and // conditionally executed code (in the case of "(GetVal(out a) && GetVal(out b))" for example mCurMethodState->mDeferredLocalAssignData->BreakExtendChain(); @@ -3794,7 +3790,7 @@ void BfModule::DoIfStatement(BfIfStatement* ifStmt, bool includeTrueStmt, bool i AssertErrorState(); condValue = BfTypedValue(GetDefaultValue(boolType), boolType); } - + BfIRBlock trueBB; BfIRBlock falseBB; bool isConstBranch = false; @@ -3810,7 +3806,7 @@ void BfModule::DoIfStatement(BfIfStatement* ifStmt, bool includeTrueStmt, bool i } if (!isConstBranch) - { + { trueBB = mBfIRBuilder->CreateBlock("if.then", true); falseBB = (ifStmt->mFalseStatement == NULL) ? BfIRBlock() : mBfIRBuilder->CreateBlock("if.else"); } @@ -3824,7 +3820,7 @@ void BfModule::DoIfStatement(BfIfStatement* ifStmt, bool includeTrueStmt, bool i mBfIRBuilder->CreateCondBr(condValue.mValue, trueBB, (falseBB) ? falseBB : contBB); } - // TRUE statement + // TRUE statement bool ignoredLastBlock = true; if (includeTrueStmt) @@ -3843,12 +3839,12 @@ void BfModule::DoIfStatement(BfIfStatement* ifStmt, bool includeTrueStmt, bool i ignoredLastBlock = false; VisitEmbeddedStatement(ifStmt->mTrueStatement); } - prevDLA.Restore(); + prevDLA.Restore(); if (mCurMethodState->mDeferredLocalAssignData != NULL) mCurMethodState->mDeferredLocalAssignData->mHadBreak |= deferredLocalAssignData.mHadBreak; - bool trueHadReturn = mCurMethodState->mHadReturn; + bool trueHadReturn = mCurMethodState->mHadReturn; // We restore the scopeData before the False block because we don't want variables created in the if condition to // be visible in the false section @@ -3866,7 +3862,7 @@ void BfModule::DoIfStatement(BfIfStatement* ifStmt, bool includeTrueStmt, bool i mCurMethodState->mLeftBlockUncond = false; mCurMethodState->SetHadReturn(false); - + bool falseHadReturn = false; if (ifStmt->mFalseStatement != NULL) { @@ -3877,9 +3873,9 @@ void BfModule::DoIfStatement(BfIfStatement* ifStmt, bool includeTrueStmt, bool i mBfIRBuilder->AddBlock(falseBB); mBfIRBuilder->SetInsertPoint(falseBB); } - + ignoredLastBlock = true; - // + // { SetAndRestoreValue prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites); SetAndRestoreValue prevInConstIgnore(mCurMethodState->mCurScope->mInConstIgnore); @@ -3892,15 +3888,14 @@ void BfModule::DoIfStatement(BfIfStatement* ifStmt, bool includeTrueStmt, bool i else ignoredLastBlock = false; falseDeferredLocalAssignData.ExtendFrom(mCurMethodState->mDeferredLocalAssignData); - SetAndRestoreValue prevDLA(mCurMethodState->mDeferredLocalAssignData, &falseDeferredLocalAssignData); + SetAndRestoreValue prevDLA(mCurMethodState->mDeferredLocalAssignData, &falseDeferredLocalAssignData); if (includeFalseStmt) VisitEmbeddedStatement(ifStmt->mFalseStatement, NULL, BfEmbeddedStatementFlags_IsConditional); } if ((!mCurMethodState->mLeftBlockUncond) && (!ignoredLastBlock)) - { - + { if (IsTargetingBeefBackend()) - { + { // If we don't do this, then with: // if (a) { } else if (b) { } // Then we hit the closing second brace even if 'b' is false @@ -3934,15 +3929,15 @@ void BfModule::DoIfStatement(BfIfStatement* ifStmt, bool includeTrueStmt, bool i mBfIRBuilder->AddBlock(contBB); mBfIRBuilder->SetInsertPoint(contBB); - + if (isConstBranch) mCurMethodState->SetHadReturn(constResult ? trueHadReturn : falseHadReturn); else - mCurMethodState->SetHadReturn(trueHadReturn && falseHadReturn); + mCurMethodState->SetHadReturn(trueHadReturn && falseHadReturn); mCurMethodState->mLeftBlockUncond = mCurMethodState->mHadReturn; if (mCurMethodState->mHadReturn) - { + { mBfIRBuilder->EraseFromParent(contBB); } else @@ -3967,15 +3962,15 @@ void BfModule::Visit(BfVariableDeclaration* varDecl) BfTupleExpression* tupleVariableDeclaration = BfNodeDynCast(varDecl->mNameNode); if (tupleVariableDeclaration != NULL) { - HandleTupleVariableDeclaration(varDecl); + HandleTupleVariableDeclaration(varDecl); } else - HandleVariableDeclaration(varDecl); + HandleVariableDeclaration(varDecl); } void BfModule::Visit(BfLocalMethodDeclaration* methodDecl) { - Fail("Local method declarations must be wrapped in a block statement", methodDecl->mMethodDeclaration->mNameNode); + Fail("Local method declarations must be wrapped in a block statement", methodDecl->mMethodDeclaration->mNameNode); } void BfModule::Visit(BfAttributedStatement* attribStmt) @@ -4019,13 +4014,13 @@ void BfModule::Visit(BfAttributedStatement* attribStmt) VisitChild(attribStmt->mStatement); } - FinishAttributeState(&attributeState); + FinishAttributeState(&attributeState); } void BfModule::Visit(BfExpression* expression) -{ - UpdateSrcPos(expression); - BfExprEvaluator exprEvaluator(this); +{ + UpdateSrcPos(expression); + BfExprEvaluator exprEvaluator(this); exprEvaluator.mUsedAsStatement = true; exprEvaluator.Evaluate(expression); } @@ -4036,7 +4031,7 @@ void BfModule::Visit(BfExpressionStatement* expressionStmt) } void BfModule::Visit(BfThrowStatement* throwStmt) -{ +{ if (throwStmt->mExpression == NULL) { AssertErrorState(); @@ -4050,11 +4045,11 @@ void BfModule::Visit(BfThrowStatement* throwStmt) if (mCurMethodInstance->mReturnType->IsVoid()) EmitReturn(BfTypedValue()); else - EmitReturn(GetDefaultTypedValue(mCurMethodInstance->mReturnType)); + EmitReturn(GetDefaultTypedValue(mCurMethodInstance->mReturnType)); } void BfModule::Visit(BfDeleteStatement* deleteStmt) -{ +{ UpdateSrcPos(deleteStmt); auto autoComplete = mCompiler->GetAutoComplete(); @@ -4091,12 +4086,12 @@ void BfModule::Visit(BfDeleteStatement* deleteStmt) if (val.mType->IsAllocType()) val.mType = val.mType->GetUnderlyingType(); - + BfGenericParamType* genericType = NULL; if (val.mType->IsGenericParam()) genericType = (BfGenericParamType*)val.mType; if ((val.mType->IsPointer()) && (val.mType->GetUnderlyingType()->IsGenericParam())) - genericType = (BfGenericParamType*)val.mType->GetUnderlyingType(); + genericType = (BfGenericParamType*)val.mType->GetUnderlyingType(); auto checkType = val.mType; if (genericType != NULL) @@ -4110,7 +4105,7 @@ void BfModule::Visit(BfDeleteStatement* deleteStmt) bool canAlwaysDelete = checkType->IsDelegate() || checkType->IsFunction() || checkType->IsArray(); if (auto checkTypeInst = checkType->ToTypeInstance()) { - if ((checkTypeInst->IsInstanceOf(mCompiler->mDelegateTypeDef)) || + if ((checkTypeInst->IsInstanceOf(mCompiler->mDelegateTypeDef)) || (checkTypeInst->IsInstanceOf(mCompiler->mFunctionTypeDef))) canAlwaysDelete = true; } @@ -4129,7 +4124,7 @@ void BfModule::Visit(BfDeleteStatement* deleteStmt) return; } } - + if (checkType->IsVar()) { // Mixin or unconstrained generic @@ -4150,7 +4145,6 @@ void BfModule::Visit(BfDeleteStatement* deleteStmt) bool mayBeSentinel = false; - if (checkType->IsPointer()) { auto innerType = checkType->GetUnderlyingType(); @@ -4167,8 +4161,8 @@ void BfModule::Visit(BfDeleteStatement* deleteStmt) } else { - isNotNull = mBfIRBuilder->CreateIsNotNull(val.mValue); - } + isNotNull = mBfIRBuilder->CreateIsNotNull(val.mValue); + } mBfIRBuilder->CreateCondBr(isNotNull, bodyBB, endBB); mBfIRBuilder->AddBlock(bodyBB); @@ -4176,16 +4170,16 @@ void BfModule::Visit(BfDeleteStatement* deleteStmt) if (val.mType->IsObjectOrInterface()) { - EmitObjectAccessCheck(val); - } - + EmitObjectAccessCheck(val); + } + SizedArray llvmArgs; auto bitAddr = mBfIRBuilder->CreateBitCast(val.mValue, mBfIRBuilder->GetPrimitiveType(BfTypeCode_NullPtr)); llvmArgs.push_back(bitAddr); if (val.mType->IsObjectOrInterface()) { auto objectType = mContext->mBfObjectType; - BfTypeInstance* checkTypeInst = val.mType->ToTypeInstance(); + BfTypeInstance* checkTypeInst = val.mType->ToTypeInstance(); bool allowPrivate = checkTypeInst == mCurTypeInstance; bool allowProtected = allowPrivate || TypeIsSubTypeOf(mCurTypeInstance, checkTypeInst); @@ -4196,15 +4190,15 @@ void BfModule::Visit(BfDeleteStatement* deleteStmt) { if (!CheckProtection(dtorMethodDef->mProtection, checkTypeInst->mTypeDef, allowProtected, allowPrivate)) { - auto error = Fail(StrFormat("'%s.~this()' is inaccessible due to its protection level", TypeToString(checkTypeInst).c_str()), deleteStmt->mExpression); // CS0122 + auto error = Fail(StrFormat("'%s.~this()' is inaccessible due to its protection level", TypeToString(checkTypeInst).c_str()), deleteStmt->mExpression); // CS0122 } } checkTypeInst = checkTypeInst->mBaseType; allowPrivate = false; - } + } if ((mCompiler->mOptions.mObjectHasDebugFlags) && (!mIsComptimeModule)) - { + { auto preDelete = GetInternalMethod((deleteStmt->mTargetTypeToken != NULL) ? "Dbg_ObjectPreCustomDelete" : "Dbg_ObjectPreDelete"); SizedArray llvmArgs; llvmArgs.push_back(mBfIRBuilder->CreateBitCast(val.mValue, mBfIRBuilder->MapType(objectType))); @@ -4213,7 +4207,7 @@ void BfModule::Visit(BfDeleteStatement* deleteStmt) // call dtor BfExprEvaluator expressionEvaluator(this); - PopulateType(val.mType); + PopulateType(val.mType); PopulateType(objectType, BfPopulateType_DataAndMethods); if (objectType->mVirtualMethodTable.size() == 0) @@ -4233,7 +4227,7 @@ void BfModule::Visit(BfDeleteStatement* deleteStmt) if ((deleteStmt->mTargetTypeToken != NULL) && (!isAppendDelete)) { if (deleteStmt->mAllocExpr != NULL) - { + { if (customAllocator) { auto customAllocTypeInst = customAllocator.mType->ToTypeInstance(); @@ -4261,7 +4255,7 @@ void BfModule::Visit(BfDeleteStatement* deleteStmt) else { if ((mCompiler->mOptions.mEnableRealtimeLeakCheck) && (!mIsComptimeModule)) - { + { SizedArray llvmArgs; llvmArgs.push_back(mBfIRBuilder->CreateBitCast(val.mValue, mBfIRBuilder->MapType(objectType))); auto moduleMethodInstance = GetInternalMethod("Dbg_MarkObjectDeleted"); @@ -4281,7 +4275,7 @@ void BfModule::Visit(BfDeleteStatement* deleteStmt) } else { - auto func = GetBuiltInFunc(BfBuiltInFuncType_Free); + auto func = GetBuiltInFunc(BfBuiltInFuncType_Free); if (!func) { BF_ASSERT(mCompiler->mIsResolveOnly); @@ -4301,7 +4295,7 @@ void BfModule::Visit(BfDeleteStatement* deleteStmt) auto voidPtrType = GetPrimitiveType(BfTypeCode_NullPtr); auto ptrValue = BfTypedValue(mBfIRBuilder->CreateBitCast(val.mValue, mBfIRBuilder->MapType(voidPtrType)), voidPtrType); BfTypedValueExpression typedValueExpr; - typedValueExpr.Init(ptrValue); + typedValueExpr.Init(ptrValue); BfExprEvaluator exprEvaluator(this); SizedArray argExprs; argExprs.push_back(&typedValueExpr); @@ -4311,7 +4305,7 @@ void BfModule::Visit(BfDeleteStatement* deleteStmt) exprEvaluator.mNoBind = true; exprEvaluator.MatchMethod(deleteStmt->mAllocExpr, NULL, customAllocator, false, false, "Free", argValues, BfMethodGenericArguments()); } - + mBfIRBuilder->CreateBr(endBB); mBfIRBuilder->AddBlock(endBB); @@ -4324,7 +4318,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) outerScope.mInnerIsConditional = false; outerScope.mCloseNode = switchStmt; if (switchStmt->mCloseBrace != NULL) - outerScope.mCloseNode = switchStmt->mCloseBrace; + outerScope.mCloseNode = switchStmt->mCloseBrace; mCurMethodState->AddScope(&outerScope); NewScopeState(); @@ -4334,11 +4328,11 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) if (switchStmt->mSwitchValue == NULL) { AssertErrorState(); - UpdateSrcPos(switchStmt->mSwitchToken); + UpdateSrcPos(switchStmt->mSwitchToken); } else { - UpdateExprSrcPos(switchStmt->mSwitchValue); + UpdateExprSrcPos(switchStmt->mSwitchValue); BfEvalExprFlags flags = BfEvalExprFlags_None; flags = BfEvalExprFlags_AllowSplat; @@ -4371,12 +4365,12 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) if (switchStmt->mLabelNode != NULL) newScope.mLabelNode = switchStmt->mLabelNode->mLabel; mCurMethodState->AddScope(&newScope); - NewScopeState(); - + NewScopeState(); + BfTypedValue switchValueAddr = switchValue; - + BfLocalVariable* localDef = new BfLocalVariable(); - localDef->mName = "_"; + localDef->mName = "_"; localDef->mResolvedType = switchValueAddr.mType; localDef->mIsReadOnly = true; localDef->mAssignedKind = BfLocalVarAssignKind_Unconditional; @@ -4445,7 +4439,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) else if ((switchValue.mType->IsComposite()) && (switchValue.IsAddr())) { auto refType = CreateRefType(switchValue.mType); - auto allocaVal = CreateAlloca(refType); + auto allocaVal = CreateAlloca(refType); mBfIRBuilder->CreateStore(switchValue.mValue, allocaVal); auto diType = mBfIRBuilder->DbgGetType(refType); @@ -4459,7 +4453,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) if (switchValueAddr.IsSplat()) { auto addr = CreateAlloca(switchValue.mType); - if (switchValue.IsSplat()) + if (switchValue.IsSplat()) AggregateSplatIntoAddr(switchValue, addr); else mBfIRBuilder->CreateStore(switchValue.mValue, addr); @@ -4467,8 +4461,8 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) localDef->mValue = BfIRValue(); localDef->mIsSplat = false; } - } - } + } + } if (!localDef->mResolvedType->IsVar()) AddLocalVariableDef(localDef, addDebugInfo, true); @@ -4480,7 +4474,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) SizedArray blocks; SizedArray whenExprs; SizedArray whenFailBlocks; - BfIRBlock defaultBlock; + BfIRBlock defaultBlock; auto endBlock = mBfIRBuilder->CreateBlock("switch.end"); for (BfSwitchCase* switchCase : switchStmt->mSwitchCases) @@ -4492,9 +4486,9 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) defaultBlock = mBfIRBuilder->CreateBlock("default"); bool hasDefaultCase = switchStmt->mDefaultCase != NULL; - if (hasDefaultCase) - blocks.push_back(defaultBlock); - + if (hasDefaultCase) + blocks.push_back(defaultBlock); + SizedArray deferredLocalAssignDataVec; deferredLocalAssignDataVec.resize(blocks.size()); @@ -4510,8 +4504,8 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) auto switchBlock = mBfIRBuilder->GetInsertBlock(); BfIRBlock noSwitchBlock = mBfIRBuilder->CreateBlock("noSwitch", true); - BfPrimitiveType* intCoercibleType = GetIntCoercibleType(switchValue.mType); - + BfPrimitiveType* intCoercibleType = GetIntCoercibleType(switchValue.mType); + bool isConstSwitch = false; if ((switchValue.mValue.IsConst()) || (switchValue.mType->IsValuelessType())) { @@ -4534,7 +4528,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) switchStatement = mBfIRBuilder->CreateSwitch(enumTagVal.mValue, noSwitchBlock, numExpressions); } else if ((!isConstSwitch) && (!switchValue.mType->IsVar())) - switchStatement = mBfIRBuilder->CreateSwitch(switchValue.mValue, noSwitchBlock, numExpressions); + switchStatement = mBfIRBuilder->CreateSwitch(switchValue.mValue, noSwitchBlock, numExpressions); } auto valueScopeStartInner = ValueScopeStart(); @@ -4554,7 +4548,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) { auto fieldDef = fieldInstance.GetFieldDef(); if (fieldDef->IsEnumCaseEntry()) - { + { int enumIdx = -fieldInstance.mDataIdx - 1; if (enumIdx == id) { @@ -4580,7 +4574,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) }; bool hadConstMatch = false; - + auto startingLocalVarId = mCurMethodState->GetRootMethodState()->mCurLocalVarId; bool prevHadFallthrough = false; @@ -4601,7 +4595,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) if ((mCompiler->mResolvePassData != NULL) && (mCompiler->mResolvePassData->mAutoComplete != NULL)) { - // This does the enum autocomplete popup + // This does the enum autocomplete popup BfAstNode* checkNode = NULL; int caseExprIdx = (int)switchCase->mCaseExpressions.size(); if (caseExprIdx == 0) @@ -4615,7 +4609,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) bool mayHaveMatch = false; BfWhenExpression* whenExpr = NULL; - + for (BfExpression* caseExpr : switchCase->mCaseExpressions) { if (auto checkWhenExpr = BfNodeDynCast(caseExpr)) @@ -4636,14 +4630,14 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) continue; if ((!openedScope) && (wantsOpenedScope)) - { + { openedScope = true; caseScopeData.mOuterIsConditional = true; caseScopeData.mIsSharedTempBlock = true; mCurMethodState->AddScope(&caseScopeData); NewScopeState(); - UpdateSrcPos(caseExpr); + UpdateSrcPos(caseExpr); SetIllegalSrcPos(); } @@ -4657,7 +4651,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) { auto dscrType = switchValue.mType->ToTypeInstance()->GetDiscriminatorType(); if (!enumTagVal) - { + { enumTagVal = ExtractValue(switchValue, NULL, 2); enumTagVal = LoadValue(enumTagVal); } @@ -4665,17 +4659,17 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) notEqBB = mBfIRBuilder->CreateBlock(StrFormat("switch.notEq.%d", blockIdx), false); int tagId = -1; BfIRBlock matchBlock; - BfTypedValue eqTypedResult; + BfTypedValue eqTypedResult; if (auto bindExpr = BfNodeDynCast(caseExpr)) { - eqTypedResult = HandleCaseBind(switchValueAddr, enumTagVal, bindExpr, &caseBlock, ¬EqBB, &matchBlock, &tagId); + eqTypedResult = HandleCaseBind(switchValueAddr, enumTagVal, bindExpr, &caseBlock, ¬EqBB, &matchBlock, &tagId); } else { eqTypedResult = TryCaseEnumMatch(switchValueAddr, enumTagVal, caseExpr, &caseBlock, ¬EqBB, &matchBlock, tagId, hadConditional, false, prevHadFallthrough); if (hadConditional) hadCondCase = true; - } + } if (tagId != -1) { @@ -4683,12 +4677,12 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) caseValue = BfTypedValue(GetConstValue(tagId, GetPrimitiveType(dscrType->mTypeDef->mTypeCode)), dscrType); } else - hadCondCase = true; + hadCondCase = true; if (eqTypedResult) { handled = true; - eqResult = eqTypedResult.mValue; + eqResult = eqTypedResult.mValue; } } else if (auto tupleExpr = BfNodeDynCast(caseExpr)) @@ -4717,14 +4711,14 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) BfTypedValue caseIntVal = caseValue; if ((isIntegralSwitch) || (isPayloadEnum)) { - if ((intCoercibleType != NULL) && - (caseValue.mType == switchValue.mType) && + if ((intCoercibleType != NULL) && + (caseValue.mType == switchValue.mType) && (caseValue.mValue.IsConst())) { caseIntVal = GetIntCoercible(caseValue); constantInt = mBfIRBuilder->GetConstant(caseIntVal.mValue); } - else + else { // For a non-const case, allow for conversion operators, otherwise cast now if ((isIntegralSwitch) && (caseValue.mValue.IsConst())) @@ -4758,7 +4752,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) { _CaseState* caseState = NULL; handledCases.TryAdd(constantInt->mInt64, NULL, &caseState); - + if (caseState->mUncondBlock) { _ShowCaseError(constantInt->mInt64, caseExpr); @@ -4775,7 +4769,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) else if (!handled) { hadCondCase = true; - + if (!eqResult) { BfExprEvaluator exprEvaluator(this); @@ -4784,14 +4778,14 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) if ((caseValue.mType->IsPayloadEnum()) && (caseValue.mValue.IsConst()) && (switchValue.mType == caseValue.mType)) { if (!enumTagVal) - { + { enumTagVal = ExtractValue(switchValue, NULL, 2); enumTagVal = LoadValue(enumTagVal); } eqResult = mBfIRBuilder->CreateCmpEQ(enumTagVal.mValue, caseValue.mValue); } else - { + { exprEvaluator.PerformBinaryOperation(switchStmt->mSwitchValue, caseExpr, BfBinaryOp_Equality, refNode, (BfBinOpFlags)(BfBinOpFlag_ForceLeftType), switchValue, caseValue); if (switchStmt->mSwitchValue != NULL) @@ -4814,17 +4808,17 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) if (constant->mTypeCode == BfTypeCode_Boolean) { isConstResult = true; - constResult = constant->mBool; + constResult = constant->mBool; } } if (isConstResult) - { + { if (constResult) { mBfIRBuilder->CreateBr(caseBlock); mayHaveMatch = true; - + if (whenExpr == NULL) { hadConstMatch = true; @@ -4832,7 +4826,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) else { notEqBB = mBfIRBuilder->CreateBlock(StrFormat("switch.notEq.%d", blockIdx)); - + mBfIRBuilder->AddBlock(notEqBB); mBfIRBuilder->SetInsertPoint(notEqBB); } @@ -4848,7 +4842,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) mBfIRBuilder->AddBlock(notEqBB); mBfIRBuilder->SetInsertPoint(notEqBB); } - } + } if (notEqBB) lastNotEqBlock = notEqBB; @@ -4864,7 +4858,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) auto notEqBB = mBfIRBuilder->CreateBlock(StrFormat("switch.notEq_when.%d", blockIdx)); - mBfIRBuilder->CreateBr(caseBlock); + mBfIRBuilder->CreateBr(caseBlock); mBfIRBuilder->AddBlock(notEqBB); mBfIRBuilder->SetInsertPoint(notEqBB); @@ -4875,14 +4869,14 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) mBfIRBuilder->SetSwitchDefaultDest(switchStatement, lastDefaultBlock); auto prevInsertBlock = mBfIRBuilder->GetInsertBlock(); - + bool isConstIgnore = !mayHaveMatch && !prevHadFallthrough; SetAndRestoreValue prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, true, isConstIgnore); SetAndRestoreValue prevInConstIgnore(mCurMethodState->mCurScope->mInConstIgnore, true, isConstIgnore); - + mBfIRBuilder->AddBlock(caseBlock); mBfIRBuilder->SetInsertPoint(caseBlock); - + if (whenExpr != NULL) { UpdateSrcPos(whenExpr); @@ -4894,7 +4888,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) { AssertErrorState(); whenValue = GetDefaultTypedValue(boolType); - } + } bool constResult = false; if (mBfIRBuilder->TryGetBool(whenValue.mValue, constResult)) @@ -4921,14 +4915,14 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) bool hadReturn = false; if ((switchCase->mCodeBlock != NULL) && (!switchCase->mCodeBlock->mChildArr.IsEmpty())) { - UpdateSrcPos(switchCase->mCodeBlock); + UpdateSrcPos(switchCase->mCodeBlock); VisitCodeBlock(switchCase->mCodeBlock, BfIRBlock(), endBlock, fallthroughBlock, true, &hadReturn, switchStmt->mLabelNode, openedScope /*, BfEmbeddedStatementFlags_RescopeDLA*/); openedScope = false; deferredLocalAssignDataVec[blockIdx].mHadReturn = hadReturn; caseCount++; - if ((!hadReturn) && + if ((!hadReturn) && ((!mCurMethodState->mDeferredLocalAssignData->mHadFallthrough) || (mCurMethodState->mDeferredLocalAssignData->mHadBreak))) allHadReturns = false; @@ -4939,8 +4933,8 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) else { if (switchStmt->mCloseBrace != NULL) - { - UpdateSrcPos(switchStmt->mCloseBrace); + { + UpdateSrcPos(switchStmt->mCloseBrace); } EmitEnsureInstructionAt(); } @@ -4961,8 +4955,8 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) prevIgnoreWrites.Restore(); mBfIRBuilder->SetInsertPoint(prevInsertBlock); - - prevHadFallthrough = mCurMethodState->mDeferredLocalAssignData->mHadFallthrough; + + prevHadFallthrough = mCurMethodState->mDeferredLocalAssignData->mHadFallthrough; blockIdx++; } @@ -4970,7 +4964,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) // Check for comprehensiveness bool isComprehensive = true; if ((switchValue) && (switchStmt->mDefaultCase == NULL)) - { + { if (switchValue.mType->IsEnum()) { if (hadConstMatch) @@ -5036,9 +5030,9 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) mBfIRBuilder->SetInsertPoint(switchBlock); if (!hadConstIntVals) - { + { if (switchStatement) - mBfIRBuilder->EraseInstFromParent(switchStatement); + mBfIRBuilder->EraseInstFromParent(switchStatement); mBfIRBuilder->CreateBr(noSwitchBlock); } @@ -5075,7 +5069,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) allHadReturns = false; RestoreScopeState(); - } + } } else { @@ -5088,14 +5082,14 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) if (IsTargetingBeefBackend()) mBfIRBuilder->CreateBr(endBlock); } - else + else mBfIRBuilder->CreateBr(endBlock); } if (isComprehensive) { // Merge and apply deferred local assign data - // We only do this if there's a default case, otherwise we assume we may have missed a case + // We only do this if there's a default case, otherwise we assume we may have missed a case // that by definition had no local assigns BfDeferredLocalAssignData* mergedDeferredLocalAssignData = NULL; for (blockIdx = 0; blockIdx < (int)blocks.size(); blockIdx++) @@ -5121,7 +5115,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) mCurMethodState->mLeftBlockUncond = true; if ((!hasDefaultCase) && (!isComprehensive)) - mBfIRBuilder->DeleteBlock(endBlock); + mBfIRBuilder->DeleteBlock(endBlock); else { if (switchStmt->mCloseBrace != NULL) @@ -5130,7 +5124,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) mBfIRBuilder->SetInsertPoint(endBlock); mBfIRBuilder->CreateUnreachable(); } - } + } else { if (switchStmt->mCloseBrace != NULL) @@ -5139,29 +5133,29 @@ void BfModule::Visit(BfSwitchStatement* switchStmt) mBfIRBuilder->AddBlock(endBlock); mBfIRBuilder->SetInsertPoint(endBlock); } - + BfIRValue lifetimeExtendVal; if (tryExtendValue) { if (localDef->mAddr) lifetimeExtendVal = localDef->mAddr; else - lifetimeExtendVal = localDef->mValue; + lifetimeExtendVal = localDef->mValue; } - + RestoreScopeState(); // newScope RestoreScopeState(); // outerScope if (lifetimeExtendVal) mBfIRBuilder->CreateLifetimeExtend(lifetimeExtendVal); - + ValueScopeEnd(valueScopeStartOuter); } static int gRetIdx = 0; void BfModule::Visit(BfReturnStatement* returnStmt) -{ +{ if ((mCurMethodInstance == NULL) || (mCurMethodState->mDisableReturns)) { Fail("Unexpected return", returnStmt); @@ -5172,7 +5166,7 @@ void BfModule::Visit(BfReturnStatement* returnStmt) } return; } - + UpdateSrcPos(returnStmt); EmitEnsureInstructionAt(); @@ -5204,7 +5198,7 @@ void BfModule::Visit(BfReturnStatement* returnStmt) { Fail("Initialization blocks cannot contain 'return' statements", returnStmt); } - checkScope = checkScope->mPrevScope; + checkScope = checkScope->mPrevScope; } auto checkLocalAssignData = mCurMethodState->mDeferredLocalAssignData; @@ -5219,17 +5213,17 @@ void BfModule::Visit(BfReturnStatement* returnStmt) { if (returnStmt->mExpression != NULL) { - BfExprEvaluator exprEvaluator(this); + BfExprEvaluator exprEvaluator(this); CreateValueFromExpression(exprEvaluator, returnStmt->mExpression, GetPrimitiveType(BfTypeCode_Var), BfEvalExprFlags_None); } MarkScopeLeft(&mCurMethodState->mHeadScope); return; - } + } if (returnStmt->mExpression == NULL) { MarkScopeLeft(&mCurMethodState->mHeadScope); - + if ((retType != NULL) && (retType->IsVoid())) { EmitReturn(BfTypedValue()); @@ -5237,11 +5231,11 @@ void BfModule::Visit(BfReturnStatement* returnStmt) } Fail("Expected return value", returnStmt); - if (retType != NULL) + if (retType != NULL) EmitReturn(GetDefaultTypedValue(retType)); else EmitReturn(BfTypedValue()); - return; + return; } BfType* expectingReturnType = retType; @@ -5249,15 +5243,15 @@ void BfModule::Visit(BfReturnStatement* returnStmt) BfExprEvaluator exprEvaluator(this); bool alreadyWritten = false; if ((!mIsComptimeModule) && (mCurMethodInstance->GetStructRetIdx() != -1)) - exprEvaluator.mReceivingValue = &mCurMethodState->mRetVal; + exprEvaluator.mReceivingValue = &mCurMethodState->mRetVal; if (mCurMethodInstance->mMethodDef->mIsReadOnly) exprEvaluator.mAllowReadOnlyReference = true; if (inferReturnType) expectingReturnType = NULL; - auto retValue = CreateValueFromExpression(exprEvaluator, returnStmt->mExpression, expectingReturnType, BfEvalExprFlags_AllowRefExpr, &origType); - + auto retValue = CreateValueFromExpression(exprEvaluator, returnStmt->mExpression, expectingReturnType, BfEvalExprFlags_AllowRefExpr, &origType); + if ((retValue) && (inferReturnType)) { if (mCurMethodState->mClosureState->mReturnType == NULL) @@ -5287,7 +5281,7 @@ void BfModule::Visit(BfReturnStatement* returnStmt) if ((!mIsComptimeModule) && (mCurMethodInstance->GetStructRetIdx() != -1)) alreadyWritten = exprEvaluator.mReceivingValue == NULL; MarkScopeLeft(&mCurMethodState->mHeadScope); - + if (!retValue) { AssertErrorState(); @@ -5299,7 +5293,7 @@ void BfModule::Visit(BfReturnStatement* returnStmt) { EmitReturn(BfTypedValue()); return; - } + } } if (retValue.mType->IsVar()) @@ -5307,7 +5301,7 @@ void BfModule::Visit(BfReturnStatement* returnStmt) EmitReturn(BfTypedValue()); } else if (retValue.mType->IsVoid()) - { + { if (retType->IsVoid()) { Warn(0, "Returning void value", returnStmt->mReturnToken); @@ -5337,20 +5331,20 @@ void BfModule::Visit(BfReturnStatement* returnStmt) } void BfModule::Visit(BfYieldStatement* yieldStmt) -{ +{ Fail("Yield not supported", yieldStmt); } void BfModule::Visit(BfBreakStatement* breakStmt) { bool inMixinDecl = (mCurMethodInstance != NULL) && (mCurMethodInstance->IsMixin()); - + UpdateSrcPos(breakStmt); mBfIRBuilder->CreateEnsureInstructionAt(); BfBreakData* breakData = mCurMethodState->mBreakData; if (breakStmt->mLabel != NULL) - { + { breakData = FindBreakData(breakStmt->mLabel); } else @@ -5360,7 +5354,7 @@ void BfModule::Visit(BfBreakStatement* breakStmt) if (breakData->mIRBreakBlock) break; breakData = breakData->mPrevBreakData; - } + } } if ((mCompiler->mResolvePassData != NULL) && (mCompiler->mResolvePassData->mAutoComplete != NULL)) @@ -5373,7 +5367,7 @@ void BfModule::Visit(BfBreakStatement* breakStmt) } if ((breakData == NULL) || (!breakData->mIRBreakBlock)) - { + { if (inMixinDecl) { // Our mixin may just require that we're injected into a breakable scope @@ -5381,7 +5375,7 @@ void BfModule::Visit(BfBreakStatement* breakStmt) else Fail("'break' not applicable in this block", breakStmt); return; - } + } if (mCurMethodState->mInDeferredBlock) { @@ -5391,33 +5385,33 @@ void BfModule::Visit(BfBreakStatement* breakStmt) if (checkScope == breakData->mScope) break; if (checkScope->mIsDeferredBlock) - { + { Fail("The break target crosses a deferred block boundary", breakStmt); return; } checkScope = checkScope->mPrevScope; } } - + if (HasDeferredScopeCalls(breakData->mScope)) - { + { EmitDeferredScopeCalls(true, breakData->mScope, breakData->mIRBreakBlock); } else - { - mBfIRBuilder->CreateBr(breakData->mIRBreakBlock); + { + mBfIRBuilder->CreateBr(breakData->mIRBreakBlock); } - mCurMethodState->mLeftBlockUncond = true; + mCurMethodState->mLeftBlockUncond = true; bool isCond = false; int uncondScopeDepth = 0; if (mCurMethodState->mCurScope != NULL) uncondScopeDepth = mCurMethodState->mCurScope->mScopeDepth + 1; - BfIRValue earliestValueScopeStart; + BfIRValue earliestValueScopeStart; auto checkScope = mCurMethodState->mCurScope; while (checkScope != NULL) - { + { if (!isCond) uncondScopeDepth = checkScope->mScopeDepth; if ((checkScope->mOuterIsConditional) && (!checkScope->mIsSharedTempBlock)) @@ -5427,7 +5421,7 @@ void BfModule::Visit(BfBreakStatement* breakStmt) earliestValueScopeStart = checkScope->mValueScopeStart; if (checkScope == breakData->mScope) break; - + checkScope = checkScope->mPrevScope; } @@ -5445,7 +5439,7 @@ void BfModule::Visit(BfBreakStatement* breakStmt) } MarkScopeLeft(breakData->mScope); - ValueScopeEnd(earliestValueScopeStart); + ValueScopeEnd(earliestValueScopeStart); auto checkBreakData = mCurMethodState->mBreakData; while (true) @@ -5454,13 +5448,13 @@ void BfModule::Visit(BfBreakStatement* breakStmt) if (checkBreakData == breakData) break; checkBreakData = checkBreakData->mPrevBreakData; - } + } } void BfModule::Visit(BfContinueStatement* continueStmt) { bool inMixinDecl = (mCurMethodInstance != NULL) && (mCurMethodInstance->IsMixin()); - + UpdateSrcPos(continueStmt); mBfIRBuilder->CreateEnsureInstructionAt(); @@ -5483,7 +5477,7 @@ void BfModule::Visit(BfContinueStatement* continueStmt) break; breakData = breakData->mPrevBreakData; } - } + } if ((mCompiler->mResolvePassData != NULL) && (mCompiler->mResolvePassData->mAutoComplete != NULL)) { @@ -5538,7 +5532,7 @@ void BfModule::Visit(BfContinueStatement* continueStmt) } if ((nextScope != NULL) && (HasDeferredScopeCalls(nextScope))) - { + { EmitDeferredScopeCalls(true, nextScope, breakData->mIRContinueBlock); } else @@ -5592,12 +5586,12 @@ void BfModule::Visit(BfFallthroughStatement* fallthroughStmt) } void BfModule::Visit(BfUsingStatement* usingStmt) -{ +{ UpdateSrcPos(usingStmt); mCurMethodState->mInHeadScope = false; BfScopeData newScope; - mCurMethodState->AddScope(&newScope); + mCurMethodState->AddScope(&newScope); NewScopeState(); if (usingStmt->mVariableDeclaration != NULL) UpdateSrcPos(usingStmt->mVariableDeclaration); @@ -5624,21 +5618,21 @@ void BfModule::Visit(BfUsingStatement* usingStmt) AssertErrorState(); failed = true; } - else + else { - embeddedValue = exprEvaluator.LoadLocal(localVar); + embeddedValue = exprEvaluator.LoadLocal(localVar); } //exprEvaluator.CheckModifyResult(embeddedValue, usingStmt->mVariableDeclaration->mNameNode,); } - else - { + else + { embeddedValue = CreateValueFromExpression(usingStmt->mVariableDeclaration->mInitializer); if (!embeddedValue) failed = true; } if (!failed) - { + { auto iDisposableType = ResolveTypeDef(mCompiler->mIDisposableTypeDef)->ToTypeInstance(); auto dispMethod = GetMethodByName(iDisposableType, "Dispose"); @@ -5659,7 +5653,7 @@ void BfModule::Visit(BfUsingStatement* usingStmt) mayBeNull = false; } - exprEvaluator.mFunctionBindResult = &functionBindResult; + exprEvaluator.mFunctionBindResult = &functionBindResult; SizedArray resolvedArgs; BfMethodMatcher methodMatcher(usingStmt->mVariableDeclaration, this, dispMethod.mMethodInstance, resolvedArgs, BfMethodGenericArguments()); methodMatcher.CheckType(iDisposableType, embeddedValue, false); @@ -5686,40 +5680,40 @@ void BfModule::Visit(BfUsingStatement* usingStmt) } void BfModule::Visit(BfDoStatement* doStmt) -{ +{ UpdateSrcPos(doStmt); - auto bodyBB = mBfIRBuilder->CreateBlock("do.body", true); + auto bodyBB = mBfIRBuilder->CreateBlock("do.body", true); auto endBB = mBfIRBuilder->CreateBlock("do.end"); - BfScopeData scopeData; + BfScopeData scopeData; if (doStmt->mLabelNode != NULL) scopeData.mLabelNode = doStmt->mLabelNode->mLabel; mCurMethodState->AddScope(&scopeData); NewScopeState(); - BfBreakData breakData; + BfBreakData breakData; breakData.mIRBreakBlock = endBB; breakData.mScope = &scopeData; - breakData.mPrevBreakData = mCurMethodState->mBreakData; + breakData.mPrevBreakData = mCurMethodState->mBreakData; SetAndRestoreValue prevBreakData(mCurMethodState->mBreakData, &breakData); BfDeferredLocalAssignData deferredLocalAssignData(mCurMethodState->mCurScope); deferredLocalAssignData.ExtendFrom(mCurMethodState->mDeferredLocalAssignData, false); deferredLocalAssignData.mVarIdBarrier = mCurMethodState->GetRootMethodState()->mCurLocalVarId; - SetAndRestoreValue prevDLA(mCurMethodState->mDeferredLocalAssignData, &deferredLocalAssignData); + SetAndRestoreValue prevDLA(mCurMethodState->mDeferredLocalAssignData, &deferredLocalAssignData); // We may have a call in the loop body mCurMethodState->mMayNeedThisAccessCheck = true; mBfIRBuilder->CreateBr(bodyBB); - mBfIRBuilder->SetInsertPoint(bodyBB); - VisitEmbeddedStatement(doStmt->mEmbeddedStatement); - + mBfIRBuilder->SetInsertPoint(bodyBB); + VisitEmbeddedStatement(doStmt->mEmbeddedStatement); + prevDLA.Restore(); mCurMethodState->ApplyDeferredLocalAssignData(deferredLocalAssignData); - RestoreScopeState(); + RestoreScopeState(); if (!mCurMethodState->mLeftBlockUncond) mBfIRBuilder->CreateBr(endBB); @@ -5727,7 +5721,7 @@ void BfModule::Visit(BfDoStatement* doStmt) mCurMethodState->mLeftBlockUncond = false; mBfIRBuilder->AddBlock(endBB); - mBfIRBuilder->SetInsertPoint(endBB); + mBfIRBuilder->SetInsertPoint(endBB); } void BfModule::Visit(BfRepeatStatement* repeatStmt) @@ -5747,7 +5741,7 @@ void BfModule::Visit(BfRepeatStatement* repeatStmt) auto endBB = mBfIRBuilder->CreateBlock("repeat.end"); BfScopeData scopeData; - // We set mIsLoop later + // We set mIsLoop later if (repeatStmt->mLabelNode != NULL) scopeData.mLabelNode = repeatStmt->mLabelNode->mLabel; mCurMethodState->AddScope(&scopeData); @@ -5757,15 +5751,15 @@ void BfModule::Visit(BfRepeatStatement* repeatStmt) breakData.mIRContinueBlock = condBB; breakData.mIRBreakBlock = endBB; breakData.mScope = &scopeData; - breakData.mPrevBreakData = mCurMethodState->mBreakData; + breakData.mPrevBreakData = mCurMethodState->mBreakData; SetAndRestoreValue prevBreakData(mCurMethodState->mBreakData, &breakData); // We may have a call in the loop body mCurMethodState->mMayNeedThisAccessCheck = true; mBfIRBuilder->CreateBr(bodyBB); - mBfIRBuilder->SetInsertPoint(bodyBB); - scopeData.mIsLoop = true; + mBfIRBuilder->SetInsertPoint(bodyBB); + scopeData.mIsLoop = true; BfDeferredLocalAssignData deferredLocalAssignData(mCurMethodState->mCurScope); deferredLocalAssignData.ExtendFrom(mCurMethodState->mDeferredLocalAssignData, false); @@ -5776,20 +5770,20 @@ void BfModule::Visit(BfRepeatStatement* repeatStmt) if (!mCurMethodState->mLeftBlockUncond) mBfIRBuilder->CreateBr(condBB); - mCurMethodState->SetHadReturn(false); + mCurMethodState->SetHadReturn(false); mCurMethodState->mLeftBlockUncond = false; mCurMethodState->mLeftBlockCond = false; - mBfIRBuilder->AddBlock(condBB); + mBfIRBuilder->AddBlock(condBB); mBfIRBuilder->SetInsertPoint(condBB); bool isInfiniteLoop = false; - if (repeatStmt->mCondition != NULL) - { + if (repeatStmt->mCondition != NULL) + { UpdateSrcPos(repeatStmt->mCondition); auto checkVal = CreateValueFromExpression(repeatStmt->mCondition, GetPrimitiveType(BfTypeCode_Boolean)); - if (checkVal) + if (checkVal) { if ((!breakData.mHadBreak) && (checkVal.mValue.IsConst())) { @@ -5802,9 +5796,8 @@ void BfModule::Visit(BfRepeatStatement* repeatStmt) mBfIRBuilder->AddBlock(endBB); mBfIRBuilder->SetInsertPoint(endBB); } - } - + RestoreScopeState(); prevDLA.Restore(); @@ -5821,8 +5814,8 @@ void BfModule::Visit(BfWhileStatement* whileStmt) bool prevHadReturn = mCurMethodState->mHadReturn; auto condBB = mBfIRBuilder->CreateBlock("while.cond"); - auto bodyBB = mBfIRBuilder->CreateBlock("while.body"); - auto endBB = mBfIRBuilder->CreateBlock("while.end"); + auto bodyBB = mBfIRBuilder->CreateBlock("while.body"); + auto endBB = mBfIRBuilder->CreateBlock("while.end"); mCurMethodState->mInHeadScope = false; BfScopeData scopeData; @@ -5831,14 +5824,14 @@ void BfModule::Visit(BfWhileStatement* whileStmt) if (whileStmt->mLabelNode != NULL) scopeData.mLabelNode = whileStmt->mLabelNode->mLabel; scopeData.mValueScopeStart = ValueScopeStart(); - mCurMethodState->AddScope(&scopeData); + mCurMethodState->AddScope(&scopeData); NewScopeState(); BfBreakData breakData; breakData.mIRContinueBlock = condBB; breakData.mIRBreakBlock = endBB; breakData.mScope = &scopeData; - breakData.mPrevBreakData = mCurMethodState->mBreakData; + breakData.mPrevBreakData = mCurMethodState->mBreakData; breakData.mInnerValueScopeStart = scopeData.mValueScopeStart; SetAndRestoreValue prevBreakData(mCurMethodState->mBreakData, &breakData); @@ -5882,7 +5875,7 @@ void BfModule::Visit(BfWhileStatement* whileStmt) mBfIRBuilder->CreateBr(bodyBB); else if (isFalseLoop) mBfIRBuilder->CreateBr(endBB); - else + else mBfIRBuilder->CreateCondBr(checkVal.mValue, bodyBB, endBB); // Apply deferred local assign to mEmbeddedStatement and itrStmt @@ -5893,7 +5886,7 @@ void BfModule::Visit(BfWhileStatement* whileStmt) deferredLocalAssignData.mIsUnconditional = isInfiniteLoop; mBfIRBuilder->AddBlock(bodyBB); - mBfIRBuilder->SetInsertPoint(bodyBB); + mBfIRBuilder->SetInsertPoint(bodyBB); if (whileStmt->mEmbeddedStatement != NULL) { if (isFalseLoop) @@ -5903,7 +5896,7 @@ void BfModule::Visit(BfWhileStatement* whileStmt) VisitEmbeddedStatement(whileStmt->mEmbeddedStatement); } else - VisitEmbeddedStatement(whileStmt->mEmbeddedStatement); + VisitEmbeddedStatement(whileStmt->mEmbeddedStatement); } else { @@ -5913,24 +5906,24 @@ void BfModule::Visit(BfWhileStatement* whileStmt) { isInfiniteLoop = false; } - + if ((!mCurMethodState->mLeftBlockUncond) && (!isFalseLoop)) { mBfIRBuilder->CreateBr(condBB); - } + } if (!isInfiniteLoop) mCurMethodState->mHadReturn = prevHadReturn; - mCurMethodState->mLeftBlockUncond = false; - mCurMethodState->mLeftBlockCond = false; + mCurMethodState->mLeftBlockUncond = false; + mCurMethodState->mLeftBlockCond = false; mBfIRBuilder->AddBlock(endBB); mBfIRBuilder->SetInsertPoint(endBB); if (isFalseLoop) { - mBfIRBuilder->EraseFromParent(bodyBB); + mBfIRBuilder->EraseFromParent(bodyBB); } RestoreScopeState(); @@ -5975,22 +5968,22 @@ void BfModule::Visit(BfForStatement* forStmt) auto incBB = mBfIRBuilder->CreateBlock("for.inc"); auto endBB = mBfIRBuilder->CreateBlock("for.end"); - BfBreakData breakData; + BfBreakData breakData; breakData.mIRContinueBlock = incBB; breakData.mIRBreakBlock = endBB; breakData.mScope = &scopeData; - breakData.mPrevBreakData = mCurMethodState->mBreakData; - SetAndRestoreValue prevBreakData(mCurMethodState->mBreakData, &breakData); + breakData.mPrevBreakData = mCurMethodState->mBreakData; + SetAndRestoreValue prevBreakData(mCurMethodState->mBreakData, &breakData); mBfIRBuilder->CreateBr(condBB); - bool isInfiniteLoop = false; + bool isInfiniteLoop = false; mBfIRBuilder->SetInsertPoint(condBB); if (forStmt->mCondition != NULL) { auto conditionValue = CreateValueFromExpression(forStmt->mCondition, boolType); if (!conditionValue) - conditionValue = GetDefaultTypedValue(boolType); + conditionValue = GetDefaultTypedValue(boolType); auto constant = mBfIRBuilder->GetConstant(conditionValue.mValue); if ((constant != NULL) && (constant->mTypeCode == BfTypeCode_Boolean)) isInfiniteLoop = constant->mBool; @@ -6012,8 +6005,8 @@ void BfModule::Visit(BfForStatement* forStmt) mBfIRBuilder->AddBlock(bodyBB); mBfIRBuilder->SetInsertPoint(bodyBB); if (forStmt->mEmbeddedStatement != NULL) - { - VisitEmbeddedStatement(forStmt->mEmbeddedStatement); + { + VisitEmbeddedStatement(forStmt->mEmbeddedStatement); } if (!mCurMethodState->mLeftBlockUncond) mBfIRBuilder->CreateBr(incBB); @@ -6030,7 +6023,7 @@ void BfModule::Visit(BfForStatement* forStmt) mBfIRBuilder->CreateBr(condBB); mBfIRBuilder->AddBlock(endBB); - mBfIRBuilder->SetInsertPoint(endBB); + mBfIRBuilder->SetInsertPoint(endBB); // The 'return' may have been inside the block, which may not have been entered if preconditions were not met mCurMethodState->SetHadReturn(false); @@ -6055,19 +6048,19 @@ void BfModule::DoForLess(BfForEachStatement* forEachStmt) mBfIRBuilder->SetInsertPoint(condBB); BfScopeData scopeData; - // We set mIsLoop later + // We set mIsLoop later if (forEachStmt->mLabelNode != NULL) scopeData.mLabelNode = forEachStmt->mLabelNode->mLabel; - mCurMethodState->AddScope(&scopeData); + mCurMethodState->AddScope(&scopeData); NewScopeState(); - + auto autoComplete = mCompiler->GetAutoComplete(); auto isLet = BfNodeDynCast(forEachStmt->mVariableTypeRef) != 0; auto isVar = BfNodeDynCast(forEachStmt->mVariableTypeRef) != 0; - - BfTypedValue target; - BfType* varType = NULL; + + BfTypedValue target; + BfType* varType = NULL; bool didInference = false; if (isLet || isVar) { @@ -6080,19 +6073,18 @@ void BfModule::DoForLess(BfForEachStatement* forEachStmt) } if (autoComplete != NULL) - autoComplete->CheckVarResolution(forEachStmt->mVariableTypeRef, varType); + autoComplete->CheckVarResolution(forEachStmt->mVariableTypeRef, varType); didInference = true; } else { - varType = ResolveTypeRef(forEachStmt->mVariableTypeRef, BfPopulateType_Data, BfResolveTypeRefFlag_AllowRef); + varType = ResolveTypeRef(forEachStmt->mVariableTypeRef, BfPopulateType_Data, BfResolveTypeRefFlag_AllowRef); if (forEachStmt->mCollectionExpression != NULL) target = CreateValueFromExpression(forEachStmt->mCollectionExpression, varType); } if (varType == NULL) varType = GetPrimitiveType(BfTypeCode_IntPtr); - BfDeferredLocalAssignData deferredLocalAssignData(mCurMethodState->mCurScope); deferredLocalAssignData.mIsIfCondition = true; deferredLocalAssignData.ExtendFrom(mCurMethodState->mDeferredLocalAssignData, true); @@ -6101,7 +6093,7 @@ void BfModule::DoForLess(BfForEachStatement* forEachStmt) deferredLocalAssignData.mIsIfCondition = false; - // The "extend chain" is only valid for the conditional -- since that expression may contain unconditionally executed and + // The "extend chain" is only valid for the conditional -- since that expression may contain unconditionally executed and // conditionally executed code (in the case of "(GetVal(out a) && GetVal(out b))" for example mCurMethodState->mDeferredLocalAssignData->BreakExtendChain(); @@ -6115,19 +6107,19 @@ void BfModule::DoForLess(BfForEachStatement* forEachStmt) if (didInference) target = GetDefaultTypedValue(varType); } - PopulateType(varType, BfPopulateType_Data); + PopulateType(varType, BfPopulateType_Data); auto condEndBB = mBfIRBuilder->GetInsertBlock(); mBfIRBuilder->SetInsertPoint(startBB); - - BfLocalVariable* localDef = new BfLocalVariable(); + + BfLocalVariable* localDef = new BfLocalVariable(); localDef->mNameNode = BfNodeDynCast(forEachStmt->mVariableName); localDef->mName = localDef->mNameNode->ToString(); localDef->mResolvedType = varType; BfIRValue varInst; if (!varType->IsValuelessType()) { - varInst = CreateAlloca(varType); + varInst = CreateAlloca(varType); } localDef->mAddr = varInst; localDef->mAssignedKind = BfLocalVarAssignKind_Unconditional; @@ -6141,7 +6133,7 @@ void BfModule::DoForLess(BfForEachStatement* forEachStmt) localDef->Init(); UpdateExprSrcPos(forEachStmt->mVariableName); AddLocalVariableDef(localDef, true); - + auto bodyBB = mBfIRBuilder->CreateBlock("forless.body"); auto incBB = mBfIRBuilder->CreateBlock("forless.inc"); auto endBB = mBfIRBuilder->CreateBlock("forless.end"); @@ -6150,7 +6142,7 @@ void BfModule::DoForLess(BfForEachStatement* forEachStmt) breakData.mIRContinueBlock = incBB; breakData.mIRBreakBlock = endBB; breakData.mScope = &scopeData; - breakData.mPrevBreakData = mCurMethodState->mBreakData; + breakData.mPrevBreakData = mCurMethodState->mBreakData; SetAndRestoreValue prevBreakData(mCurMethodState->mBreakData, &breakData); @@ -6163,7 +6155,6 @@ void BfModule::DoForLess(BfForEachStatement* forEachStmt) // We may have a call in the loop body mCurMethodState->mMayNeedThisAccessCheck = true; - // Cond auto valueScopeStart = ValueScopeStart(); auto localVal = mBfIRBuilder->CreateAlignedLoad(localDef->mAddr, localDef->mResolvedType->mAlign); @@ -6176,7 +6167,7 @@ void BfModule::DoForLess(BfForEachStatement* forEachStmt) conditionValue = mBfIRBuilder->CreateCmpLTE(localVal, target.mValue, varType->IsSigned()); else conditionValue = mBfIRBuilder->CreateCmpLT(localVal, target.mValue, varType->IsSigned()); - mBfIRBuilder->CreateCondBr(conditionValue, bodyBB, endBB); + mBfIRBuilder->CreateCondBr(conditionValue, bodyBB, endBB); ValueScopeEnd(valueScopeStart); mBfIRBuilder->AddBlock(bodyBB); @@ -6185,8 +6176,8 @@ void BfModule::DoForLess(BfForEachStatement* forEachStmt) // Body scopeData.mIsLoop = true; if (forEachStmt->mEmbeddedStatement != NULL) - { - VisitEmbeddedStatement(forEachStmt->mEmbeddedStatement); + { + VisitEmbeddedStatement(forEachStmt->mEmbeddedStatement); } // Inc @@ -6208,16 +6199,16 @@ void BfModule::DoForLess(BfForEachStatement* forEachStmt) mBfIRBuilder->CreateAlignedStore(result, localDef->mAddr, localDef->mResolvedType->mAlign); ValueScopeEnd(valueScopeStart); - mBfIRBuilder->CreateBr(condBB); + mBfIRBuilder->CreateBr(condBB); mBfIRBuilder->AddBlock(endBB); - mBfIRBuilder->SetInsertPoint(endBB); + mBfIRBuilder->SetInsertPoint(endBB); // The 'return' may have been inside the block, which may not have been entered if preconditions were not met mCurMethodState->SetHadReturn(false); mCurMethodState->mLeftBlockUncond = false; mCurMethodState->mLeftBlockCond = false; - + bool definitelyExecuted = false; if (target.mValue.IsConst()) { @@ -6234,8 +6225,8 @@ void BfModule::DoForLess(BfForEachStatement* forEachStmt) } void BfModule::Visit(BfForEachStatement* forEachStmt) -{ - if ((forEachStmt->mInToken != NULL) && +{ + if ((forEachStmt->mInToken != NULL) && ((forEachStmt->mInToken->GetToken() == BfToken_LChevron) || (forEachStmt->mInToken->GetToken() == BfToken_LessEquals))) { DoForLess(forEachStmt); @@ -6243,10 +6234,10 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) } auto autoComplete = mCompiler->GetAutoComplete(); - UpdateSrcPos(forEachStmt); + UpdateSrcPos(forEachStmt); BfScopeData scopeData; - // We set mIsLoop after the non-looped initializations + // We set mIsLoop after the non-looped initializations scopeData.mValueScopeStart = ValueScopeStart(); mCurMethodState->AddScope(&scopeData); NewScopeState(); @@ -6274,7 +6265,7 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) bool isLet = (forEachStmt->mVariableTypeRef != NULL) && (forEachStmt->mVariableTypeRef->IsA()); BfType* varType = NULL; - bool inferVarType = false; + bool inferVarType = false; if ((forEachStmt->mVariableTypeRef == NULL) || (forEachStmt->mVariableTypeRef->IsA()) || (isLet)) { if (target.mType->IsSizedArray()) @@ -6298,7 +6289,7 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) autoComplete->CheckTypeRef(forEachStmt->mVariableTypeRef, false); varType = ResolveTypeRef(forEachStmt->mVariableTypeRef, BfPopulateType_Data, BfResolveTypeRefFlag_AllowRef); } - + if (varType == NULL) varType = GetPrimitiveType(BfTypeCode_Var); bool isArray = target.mType->IsArray(); @@ -6309,7 +6300,7 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) BfType* itrType; BfTypedValue itr; BfTypeInstance* itrInterface = NULL; - BfTypeInstance* refItrInterface = NULL; + BfTypeInstance* refItrInterface = NULL; if (isVarEnumerator) varType = GetPrimitiveType(BfTypeCode_Var); @@ -6335,14 +6326,14 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) if (genericParamInst->mTypeConstraint->IsGenericTypeInstance()) { - auto genericConstraintType = (BfTypeInstance*)genericParamInst->mTypeConstraint; + auto genericConstraintType = (BfTypeInstance*)genericParamInst->mTypeConstraint; if (genericConstraintType->IsInstanceOf(mCompiler->mSizedArrayTypeDef)) { varType = genericConstraintType->mGenericTypeInfo->mTypeGenericArguments[0]; isVarEnumerator = true; - } - } - } + } + } + } } if (target.mType->IsConcreteInterfaceType()) @@ -6351,26 +6342,26 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) if (isArray || isSizedArray) { itrType = GetPrimitiveType(BfTypeCode_IntPtr); - BfIRValue itrInst = CreateAlloca(itrType); + BfIRValue itrInst = CreateAlloca(itrType); itr = BfTypedValue(itrInst, itrType, true); } else if (isVarEnumerator) { - // Generic method or mixin decl - } + // Generic method or mixin decl + } else if ((!target.mType->IsTypeInstance()) && (genericParamInst == NULL)) - { + { Fail(StrFormat("Type '%s' cannot be used in enumeration", TypeToString(target.mType).c_str()), forEachStmt->mCollectionExpression); } else if (forEachStmt->mCollectionExpression != NULL) { - auto targetTypeInstance = target.mType->ToTypeInstance(); - + auto targetTypeInstance = target.mType->ToTypeInstance(); + itr = target; bool hadGetEnumeratorType = false; if (genericParamInst != NULL) - { + { for (auto ifaceConstraint : genericParamInst->mInterfaceConstraints) { if (ifaceConstraint->IsInstanceOf(mCompiler->mGenericIEnumerableTypeDef)) @@ -6380,7 +6371,7 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) targetTypeInstance = NULL; break; } - targetTypeInstance = ifaceConstraint->ToTypeInstance(); + targetTypeInstance = ifaceConstraint->ToTypeInstance(); } } } @@ -6398,7 +6389,7 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) { hadGetEnumeratorType = true; Fail(StrFormat("Type '%s' does not contain a non-static 'GetEnumerator' method", TypeToString(targetTypeInstance).c_str()), forEachStmt->mCollectionExpression); - } + } else { if (getEnumeratorMethod.mMethodInstance->mMethodDef->mIsConcrete) @@ -6450,7 +6441,6 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) if (varType->IsPointer()) varType = CreateRefType(varType->GetUnderlyingType()); } - } } }; @@ -6463,7 +6453,7 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) for (auto& interfaceRef : enumeratorTypeInst->mInterfaces) { BfTypeInstance* interface = interfaceRef.mInterfaceType; - _CheckInterface(interface); + _CheckInterface(interface); } if (enumeratorTypeInst->IsInstanceOf(isRefExpression ? mCompiler->mGenericIRefEnumeratorTypeDef : mCompiler->mGenericIEnumeratorTypeDef)) @@ -6520,11 +6510,11 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) itr = MakeAddressable(itr); itr = RemoveReadOnly(itr); } - } + } } else - { - AssertErrorState(); + { + AssertErrorState(); } PopulateType(varType, BfPopulateType_Data); @@ -6549,28 +6539,27 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) struct _TupleBind { BfIdentifierNode* mNameNode; - String mName; + String mName; BfType* mType; BfLocalVariable* mVariable; }; Array<_TupleBind> tupleBinds; - if (forEachStmt->mVariableName != NULL) { if (auto tupleExpr = BfNodeDynCast(forEachStmt->mVariableName)) { CheckTupleVariableDeclaration(tupleExpr, varType); - + if (varType->IsTuple()) { auto tupleType = (BfTypeInstance*)varType; for (int idx = 0; idx < BF_MIN((int)tupleExpr->mValues.size(), (int)tupleType->mFieldInstances.size()); idx++) - { - auto nameNode = tupleExpr->mValues[idx]; - + { + auto nameNode = tupleExpr->mValues[idx]; + _TupleBind tupleBind; tupleBind.mNameNode = BfNodeDynCast(nameNode); if ((tupleBind.mNameNode == NULL) && (nameNode != NULL)) @@ -6580,7 +6569,7 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) tupleBind.mName = nameNode->ToString(); tupleBind.mType = tupleType->mFieldInstances[idx].mResolvedType; tupleBind.mVariable = NULL; - + tupleBinds.Add(tupleBind); if (idx == 0) variableName = tupleBind.mName; @@ -6594,10 +6583,10 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) variableName = nameNode->ToString(); } } - + if (variableName.IsEmpty()) variableName = "_"; - + BfModuleMethodInstance getNextMethodInst; BfType* nextEmbeddedType = NULL; @@ -6629,43 +6618,43 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) // Iterator local def if (itr) - { + { BfLocalVariable* localDef = new BfLocalVariable(); itrLocalDef = localDef; - localDef->mNameNode = nameNode; - localDef->mName = variableName; + localDef->mNameNode = nameNode; + localDef->mName = variableName; localDef->mResolvedType = itr.mType; localDef->mAddr = itr.mValue; localDef->mAssignedKind = BfLocalVarAssignKind_Unconditional; - localDef->mReadFromId = 0; + localDef->mReadFromId = 0; localDef->Init(); UpdateSrcPos(forEachStmt); CheckVariableDef(localDef); - AddLocalVariableDef(localDef, true); + AddLocalVariableDef(localDef, true); } BfIRValue varInst; BfTypedValue varTypedVal; bool needsValCopy = true; - + // Local variable { if (!tupleBinds.IsEmpty()) - { + { BF_ASSERT(varType->IsTuple()); auto tupleType = (BfTypeInstance*)varType; - // Tuple binds + // Tuple binds needsValCopy = false; if (!nextResult) { varInst = CreateAlloca(varType); varTypedVal = BfTypedValue(varInst, varType, true); - } + } // Local - for (int idx = 0; idx < (int)tupleBinds.size(); idx++) - { + for (int idx = 0; idx < (int)tupleBinds.size(); idx++) + { auto& tupleBind = tupleBinds[idx]; BfLocalVariable* localDef = new BfLocalVariable(); localDef->mNameNode = tupleBind.mNameNode; @@ -6679,7 +6668,7 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) if ((isLet) || (forEachStmt->mReadOnlyToken != NULL)) localDef->mIsReadOnly = true; localDef->Init(); - + auto fieldInstance = &tupleType->mFieldInstances[idx]; if (fieldInstance->mDataIdx >= 0) { @@ -6691,8 +6680,8 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) tuplePtr = mBfIRBuilder->CreateBitCast(varInst, mBfIRBuilder->MapType(tuplePtrType)); auto valAddr = mBfIRBuilder->CreateInBoundsGEP(tuplePtr, 0, fieldInstance->mDataIdx); mBfIRBuilder->CreateAlignedStore(valAddr, localDef->mAddr, localDef->mResolvedType->mAlign); - } - + } + UpdateSrcPos(forEachStmt); if ((itrLocalDef != NULL) && (idx == 0)) { @@ -6705,11 +6694,11 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) } AddLocalVariableDef(localDef, true, false, BfIRValue(), BfIRInitType_NotNeeded_AliveOnDecl); - } + } } else { - // Normal case + // Normal case if ((nextResult) && (varType->IsComposite())) { needsValCopy = false; @@ -6750,11 +6739,11 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) varTypedVal = BfTypedValue(varInst, varType, true); } - } - + } + // Iterator if (itr) - { + { if ((!isArray) && (!isSizedArray)) { BfFunctionBindResult functionBindResult; @@ -6762,7 +6751,7 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) exprEvaluator.mFunctionBindResult = &functionBindResult; // Allow for "Dispose" not to exist - SetAndRestoreValue prevIgnoreErrors(mIgnoreErrors, true); + SetAndRestoreValue prevIgnoreErrors(mIgnoreErrors, true); BfResolvedArgs resolvedArgs; exprEvaluator.mBfEvalExprFlags = (BfEvalExprFlags)(exprEvaluator.mBfEvalExprFlags | BfEvalExprFlags_NoAutoComplete); exprEvaluator.MatchMethod(forEachStmt->mCollectionExpression, NULL, itr, false, false, "Dispose", resolvedArgs, BfMethodGenericArguments()); @@ -6773,7 +6762,7 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) AddDeferredCall(moduleMethodInstance, functionBindResult.mIRArgs, mCurMethodState->mCurScope); } } - } + } BfScopeData innerScopeData; if (forEachStmt->mLabelNode != NULL) @@ -6786,8 +6775,8 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) if ((autoComplete != NULL) && (forEachStmt->mVariableTypeRef != NULL)) autoComplete->CheckVarResolution(forEachStmt->mVariableTypeRef, varType); - if (isArray || isSizedArray) - mBfIRBuilder->CreateAlignedStore(GetConstValue(0), itr.mValue, itr.mType->mAlign); + if (isArray || isSizedArray) + mBfIRBuilder->CreateAlignedStore(GetConstValue(0), itr.mValue, itr.mType->mAlign); auto valueScopeStartInner = ValueScopeStart(); @@ -6804,7 +6793,7 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) breakData.mIRBreakBlock = endBB; breakData.mScope = &innerScopeData; breakData.mInnerValueScopeStart = valueScopeStartInner; - breakData.mPrevBreakData = mCurMethodState->mBreakData; + breakData.mPrevBreakData = mCurMethodState->mBreakData; SetAndRestoreValue prevBreakData(mCurMethodState->mBreakData, &breakData); mBfIRBuilder->CreateBr(condBB); @@ -6816,16 +6805,16 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) { auto itrVal = mBfIRBuilder->CreateLoad(itr.mValue); auto arrayType = (BfSizedArrayType*)target.mType; - PopulateType(arrayType, BfPopulateType_DataAndMethods); + PopulateType(arrayType, BfPopulateType_DataAndMethods); BfIRValue lengthVal = GetConstValue(arrayType->mElementCount); - conditionValue = mBfIRBuilder->CreateCmpLT(itrVal, lengthVal, true); + conditionValue = mBfIRBuilder->CreateCmpLT(itrVal, lengthVal, true); mBfIRBuilder->CreateCondBr(conditionValue, bodyBB, endBB); ValueScopeEnd(valueScopeStartInner); } else if (isArray) // if (i < array.mLength) - { + { auto itrVal = mBfIRBuilder->CreateAlignedLoad(itr.mValue, itr.mType->mAlign); - auto arrayType = (BfArrayType*)target.mType; + auto arrayType = (BfArrayType*)target.mType; PopulateType(arrayType); auto arrayBaseValue = mBfIRBuilder->CreateBitCast(target.mValue, mBfIRBuilder->MapType(arrayType->mBaseType, BfIRPopulateType_Full)); int getLengthBitCount = arrayType->GetLengthBitCount(); @@ -6849,7 +6838,7 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) } } lengthVal = mBfIRBuilder->CreateNumericCast(lengthVal, true, BfTypeCode_IntPtr); - conditionValue = mBfIRBuilder->CreateCmpLT(itrVal, lengthVal, true); + conditionValue = mBfIRBuilder->CreateCmpLT(itrVal, lengthVal, true); mBfIRBuilder->CreateCondBr(conditionValue, bodyBB, endBB); ValueScopeEnd(valueScopeStartInner); } @@ -6863,18 +6852,18 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) mBfIRBuilder->CreateBr(endBB); } else - { - BfExprEvaluator exprEvaluator(this); + { + BfExprEvaluator exprEvaluator(this); auto itrTypeInstance = itr.mType->ToTypeInstance(); - SizedArray resolvedArgs; + SizedArray resolvedArgs; BfMethodMatcher methodMatcher(forEachStmt->mCollectionExpression, this, getNextMethodInst.mMethodInstance, resolvedArgs, BfMethodGenericArguments()); if (isRefExpression) methodMatcher.CheckType(refItrInterface, itr, false); else methodMatcher.CheckType(itrInterface, itr, false); methodMatcher.TryDevirtualizeCall(itr); - exprEvaluator.mReceivingValue = &nextResult; - auto retVal = exprEvaluator.CreateCall(&methodMatcher, itr); + exprEvaluator.mReceivingValue = &nextResult; + auto retVal = exprEvaluator.CreateCall(&methodMatcher, itr); if (exprEvaluator.mReceivingValue != NULL) { if (mIsComptimeModule) @@ -6893,11 +6882,11 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) conditionValue = mBfIRBuilder->CreateCmpEQ(i8Result.mValue, GetConstValue8(0)); } else - conditionValue = GetDefaultValue(GetPrimitiveType(BfTypeCode_Boolean)); + conditionValue = GetDefaultValue(GetPrimitiveType(BfTypeCode_Boolean)); mBfIRBuilder->CreateCondBr(conditionValue, bodyBB, endBB); ValueScopeEnd(valueScopeStartInner); } - } + } mBfIRBuilder->AddBlock(bodyBB); mBfIRBuilder->SetInsertPoint(bodyBB); @@ -6906,12 +6895,12 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) // Nothing to do... } else if (isSizedArray) // val = array[i] - { + { auto itrVal = mBfIRBuilder->CreateLoad(itr.mValue); auto arrayType = (BfSizedArrayType*)target.mType; BfType* ptrType = CreatePointerType(arrayType->mElementType); BfTypedValue arrayItem; - + if (arrayType->mElementType->IsValuelessType()) { arrayItem = GetDefaultTypedValue(arrayType->mElementType); @@ -6940,13 +6929,13 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) SizedArray indices; indices.push_back(&typedValueExpr); BfSizedArray sizedArgExprs(indices); - BfResolvedArgs argValues(&sizedArgExprs); + BfResolvedArgs argValues(&sizedArgExprs); exprEvaluator.ResolveArgValues(argValues); bool boundsCheck = mCompiler->mOptions.mRuntimeChecks; auto typeOptions = GetTypeOptions(); if (typeOptions != NULL) boundsCheck = typeOptions->Apply(boundsCheck, BfOptionFlags_RuntimeChecks); - + BfMethodMatcher methodMatcher(forEachStmt->mVariableName, this, "get__", argValues.mResolvedArgs, BfMethodGenericArguments()); methodMatcher.mMethodType = BfMethodType_PropertyGetter; methodMatcher.CheckType(target.mType->ToTypeInstance(), target, false); @@ -6981,12 +6970,12 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) } else if (mCompiler->IsAutocomplete()) { - // If we don't do this shortcut, we can end up creating temporary "boxed" objects + // If we don't do this shortcut, we can end up creating temporary "boxed" objects } else { if (needsValCopy) - { + { auto nextVal = BfTypedValue(mBfIRBuilder->CreateBitCast(nextResult.mValue, mBfIRBuilder->MapType(CreatePointerType(nextEmbeddedType))), nextEmbeddedType, true); if (isRefExpression) { @@ -7002,8 +6991,8 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) } if (forEachStmt->mEmbeddedStatement != NULL) - { - VisitEmbeddedStatement(forEachStmt->mEmbeddedStatement); + { + VisitEmbeddedStatement(forEachStmt->mEmbeddedStatement); } if (!mCurMethodState->mLeftBlockUncond) @@ -7014,7 +7003,7 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) mBfIRBuilder->AddBlock(incBB); mBfIRBuilder->SetInsertPoint(incBB); - + if (isArray || isSizedArray) { auto val = mBfIRBuilder->CreateLoad(itr.mValue); @@ -7023,10 +7012,10 @@ void BfModule::Visit(BfForEachStatement* forEachStmt) } else { - // Nothing to do + // Nothing to do } - - mBfIRBuilder->CreateBr(condBB); + + mBfIRBuilder->CreateBr(condBB); mBfIRBuilder->AddBlock(endBB); mBfIRBuilder->SetInsertPoint(endBB); @@ -7057,9 +7046,9 @@ void BfModule::Visit(BfDeferStatement* deferStmt) // We only want the breakpoint to hit on execution of the defer, not on insertion of it //SetAndRestoreValue prevSetIllegalSrcPos(mSetIllegalSrcPosition, true); - UpdateSrcPos(deferStmt); + UpdateSrcPos(deferStmt); EmitEnsureInstructionAt(); - + BfScopeData* scope = NULL; if (deferStmt->mScopeToken != NULL) @@ -7075,7 +7064,7 @@ void BfModule::Visit(BfDeferStatement* deferStmt) scope = mCurMethodState->mCurScope; if ((mCompiler->mResolvePassData != NULL) && (mCompiler->mResolvePassData->mAutoComplete != NULL)) - { + { auto targetIdentifier = BfNodeDynCast(deferStmt->mScopeName); if ((deferStmt->mScopeName == NULL) || (targetIdentifier != NULL)) mCompiler->mResolvePassData->mAutoComplete->CheckLabel(targetIdentifier, deferStmt->mColonToken, scope); @@ -7084,14 +7073,14 @@ void BfModule::Visit(BfDeferStatement* deferStmt) if ((scope == mCurMethodState->mCurScope) && (scope->mCloseNode == NULL)) { auto parser = deferStmt->GetParser(); - if ((parser == NULL) || (!parser->mIsEmitted)) + if ((parser == NULL) || (!parser->mIsEmitted)) Warn(0, "This defer will immediately execute. Consider specifying a wider scope target such as 'defer::'", deferStmt->mDeferToken); } if (auto block = BfNodeDynCast(deferStmt->mTargetNode)) - { + { if (deferStmt->mBind != NULL) - { + { Array captures; for (auto identifier : deferStmt->mBind->mParams) { @@ -7102,18 +7091,18 @@ void BfModule::Visit(BfDeferStatement* deferStmt) { captures.push_back(deferredCapture); } - } + } AddDeferredBlock(block, scope, &captures); } else AddDeferredBlock(block, scope); } else if (auto exprStmt = BfNodeDynCast(deferStmt->mTargetNode)) - { + { BfExprEvaluator expressionEvaluator(this); expressionEvaluator.mDeferCallRef = exprStmt->mExpression; expressionEvaluator.mDeferScopeAlloc = scope; - expressionEvaluator.VisitChild(exprStmt->mExpression); + expressionEvaluator.VisitChild(exprStmt->mExpression); if (mCurMethodState->mPendingNullConditional != NULL) FlushNullConditional(expressionEvaluator.mResult, true); } @@ -7138,9 +7127,9 @@ void BfModule::Visit(BfDeferStatement* deferStmt) { isGenericParam = true; auto genericParamInst = GetGenericParamInstance((BfGenericParamType*)val.mType); - if (genericParamInst->mGenericParamFlags & BfGenericParamFlag_Delete) - return; - if (genericParamInst->mTypeConstraint != NULL) + if (genericParamInst->mGenericParamFlags & BfGenericParamFlag_Delete) + return; + if (genericParamInst->mTypeConstraint != NULL) checkType = genericParamInst->mTypeConstraint; } @@ -7180,7 +7169,7 @@ void BfModule::Visit(BfDeferStatement* deferStmt) } else if (customAllocator) { - BfFunctionBindResult functionBindResult; + BfFunctionBindResult functionBindResult; functionBindResult.mWantsArgs = true; auto customAllocTypeInst = customAllocator.mType->ToTypeInstance(); if ((checkType->IsObjectOrInterface()) && (customAllocTypeInst != NULL) && (customAllocTypeInst->mTypeDef->GetMethodByName("FreeObject") != NULL)) @@ -7203,7 +7192,7 @@ void BfModule::Visit(BfDeferStatement* deferStmt) auto voidPtrType = GetPrimitiveType(BfTypeCode_NullPtr); auto ptrValue = BfTypedValue(mBfIRBuilder->CreateBitCast(val.mValue, mBfIRBuilder->MapType(voidPtrType)), voidPtrType); BfTypedValueExpression typedValueExpr; - typedValueExpr.Init(ptrValue); + typedValueExpr.Init(ptrValue); BfExprEvaluator exprEvaluator(this); SizedArray argExprs; argExprs.push_back(&typedValueExpr); @@ -7216,13 +7205,13 @@ void BfModule::Visit(BfDeferStatement* deferStmt) } if (functionBindResult.mMethodInstance != NULL) - { + { AddDeferredCall(BfModuleMethodInstance(functionBindResult.mMethodInstance, functionBindResult.mFunc), functionBindResult.mIRArgs, scope, deleteStmt, true); } - } + } if (checkType->IsObjectOrInterface()) - { + { auto objectType = mContext->mBfObjectType; PopulateType(objectType); BfMethodInstance* methodInstance = objectType->mVirtualMethodTable[mCompiler->GetVTableMethodOffset() + 0].mImplementingMethod; @@ -7244,7 +7233,7 @@ void BfModule::Visit(BfDeferStatement* deferStmt) llvmArgs.push_back(mBfIRBuilder->CreateBitCast(val.mValue, mBfIRBuilder->GetPrimitiveType(BfTypeCode_NullPtr))); AddDeferredCall(moduleMethodInstance, llvmArgs, scope, deleteStmt, false, true); } - } + } auto moduleMethodInstance = GetMethodInstance(objectType, methodInstance->mMethodDef, BfTypeVector()); AddDeferredCall(moduleMethodInstance, llvmArgs, scope, deleteStmt, false, true); @@ -7253,10 +7242,10 @@ void BfModule::Visit(BfDeferStatement* deferStmt) { auto moduleMethodInstance = GetMethodByName(internalType->ToTypeInstance(), (deleteStmt->mTargetTypeToken != NULL) ? "Dbg_ObjectPreCustomDelete" : "Dbg_ObjectPreDelete"); AddDeferredCall(moduleMethodInstance, llvmArgs, scope, deleteStmt, false, true); - } - } + } + } else - { + { if ((!customAllocator) && (!isAppendDelete)) { val = LoadValue(val); @@ -7268,8 +7257,8 @@ void BfModule::Visit(BfDeferStatement* deferStmt) SizedArray llvmArgs; llvmArgs.push_back(mBfIRBuilder->CreateBitCast(val.mValue, mBfIRBuilder->GetPrimitiveType(BfTypeCode_NullPtr))); AddDeferredCall(moduleMethodInstance, llvmArgs, scope, deleteStmt, false, true); - } - } + } + } } else { @@ -7294,7 +7283,7 @@ void BfModule::Visit(BfLabeledBlock* labeledBlock) } void BfModule::Visit(BfRootNode* rootNode) -{ +{ VisitMembers(rootNode); } @@ -7433,7 +7422,7 @@ void BfModule::Visit(BfInlineAsmStatement* asmStmt) { if (hasOpCode) // check against label-only lines (which still get written out, but don't do any other processing) { - int argCount = (int)asmInst.mArgs.size(); + int argCount = (int)asmInst.mArgs.size(); for (int iArg=0; iArgmInstructions.empty()) debugLocOffset = asmStmt->mInstructions.front()->GetSrcStart() - asmStmt->GetSrcStart(); UpdateSrcPos(asmStmt, true, debugLocOffset); @@ -7826,7 +7815,7 @@ void BfModule::Visit(BfInlineAsmStatement* asmStmt) //BasicBlock* block = mBfIRBuilder->GetInsertBlock(); //auto declareVar = mDIBuilder->insertDeclare(varValue, diVariable, mBfIRBuilder->GetInsertBlock()); - auto declareVar = mDIBuilder->insertDeclare(allocaInst, diVariable, mDIBuilder->createExpression(), + auto declareVar = mDIBuilder->insertDeclare(allocaInst, diVariable, mDIBuilder->createExpression(), mIRBuilder->getCurrentDebugLocation(), mBfIRBuilder->GetInsertBlock()); //auto declareVar = mDIBuilder->insertDbgValueIntrinsic(varValue, 0, diVariable, mBfIRBuilder->GetInsertBlock()); declareVar->setDebugLoc(mIRBuilder->getCurrentDebugLocation()); @@ -7891,4 +7880,4 @@ void BfModule::Visit(BfInlineAsmStatement* asmStmt) RestoreScopeState(&prevScope); #endif -} +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfSystem.cpp b/IDEHelper/Compiler/BfSystem.cpp index 01485521..28be7946 100644 --- a/IDEHelper/Compiler/BfSystem.cpp +++ b/IDEHelper/Compiler/BfSystem.cpp @@ -23,7 +23,7 @@ using namespace llvm; #pragma warning(disable:4996) void Beefy::DoBfLog(int fileIdx, const char* fmt ...) -{ +{ static int entryNum = 0; static bool onNewLine[10]; entryNum++; @@ -47,7 +47,7 @@ void Beefy::DoBfLog(int fileIdx, const char* fmt ...) char exeName[512]; int len = 512; BfpSystem_GetExecutablePath(exeName, &len, NULL); - + String dbgName = exeName; int dotPos = (int)dbgName.IndexOf('.'); if (dotPos != -1) @@ -58,21 +58,21 @@ void Beefy::DoBfLog(int fileIdx, const char* fmt ...) dbgName += 'B'; dbgName += ".txt"; - + fp[fileIdx] = BfpFile_Create(dbgName.c_str(), BfpFileCreateKind_CreateAlways, (BfpFileCreateFlags)(BfpFileCreateFlag_Write | BfpFileCreateFlag_NoBuffering | BfpFileCreateFlag_ShareRead), BfpFileAttribute_Normal, NULL); onNewLine[fileIdx] = true; logCount[fileIdx]++; } if (fp[fileIdx] == NULL) - return; - - char lineStr[4096]; + return; + + char lineStr[4096]; int strOfs; int maxChars; - + if (onNewLine[fileIdx]) { - strOfs = sprintf(lineStr, "%d", entryNum) + 1; + strOfs = sprintf(lineStr, "%d", entryNum) + 1; lineStr[strOfs - 1] = ' '; maxChars = 4095 - strOfs; } @@ -87,7 +87,7 @@ void Beefy::DoBfLog(int fileIdx, const char* fmt ...) int numChars = BF_stbsp_vsnprintf(lineStr + strOfs, maxChars, fmt, argList); if (numChars <= maxChars) - { + { if (strOfs + numChars > 0) { logSize[fileIdx] += strOfs + numChars; @@ -97,27 +97,27 @@ void Beefy::DoBfLog(int fileIdx, const char* fmt ...) onNewLine[fileIdx] = true; else onNewLine[fileIdx] = false; - } + } else onNewLine[fileIdx] = false; return; } - + String aResult = vformat(fmt, argList); va_end(argList); - + if (onNewLine[fileIdx]) { - aResult = StrFormat("%d ", entryNum) + aResult; + aResult = StrFormat("%d ", entryNum) + aResult; } if (aResult.EndsWith('\n')) onNewLine[fileIdx] = true; else onNewLine[fileIdx] = false; - + logSize[fileIdx] += aResult.length(); - BfpFile_Write(fp[fileIdx], aResult.c_str(), aResult.length(), -1, NULL); + BfpFile_Write(fp[fileIdx], aResult.c_str(), aResult.length(), -1, NULL); } BfAtom::~BfAtom() @@ -139,13 +139,13 @@ void BfAtom::Ref() // if (mTypeData->mTypesHash.IsZero()) // { // for (auto typeDef : mTypeData->mTypeDefs) -// { +// { // if (typeDef->mNextRevision != NULL) // { // HASH128_MIXIN(mTypeData->mTypesHash, typeDef->mNextRevision->mHash); // continue; // } -// +// // // Use the typeDef's 'mHash' here - we don't want our hash to change when // // the internals of a typeDef changes, we just want it to change when // // we add or remove typeDefs of this given name @@ -165,7 +165,7 @@ BfAtomComposite::BfAtomComposite() BfAtomComposite::BfAtomComposite(BfAtom* atom) { - Set(&atom, 1, NULL, 0); + Set(&atom, 1, NULL, 0); } BfAtomComposite::BfAtomComposite(const BfAtomComposite& rhs) @@ -193,7 +193,7 @@ BfAtomComposite::BfAtomComposite(BfAtomComposite&& rhs) rhs.mOwns = false; return; } - + mParts = NULL; mSize = 0; mAllocSize = 0; @@ -218,7 +218,7 @@ BfAtomComposite::BfAtomComposite(const BfAtomComposite& left, BfAtom* right) mAllocSize = 0; mOwns = false; Set(left.mParts, left.mSize, &right, 1); -} +} void BfAtomComposite::Set(const BfAtomComposite& left, const BfAtomComposite& right) { @@ -226,13 +226,13 @@ void BfAtomComposite::Set(const BfAtomComposite& left, const BfAtomComposite& ri } void BfAtomComposite::Set(BfAtom** atomsA, int countA, BfAtom** atomsB, int countB) -{ +{ BfAtom** freeParts = NULL; if (countA + countB > mAllocSize) { if (mOwns) // Defer freeing incase we are referring to ourselves - freeParts = mParts; + freeParts = mParts; mAllocSize = countA + countB; mParts = (BfAtom**)malloc(sizeof(BfAtom*) * mAllocSize); mOwns = true; @@ -255,7 +255,7 @@ BfAtomComposite::~BfAtomComposite() } BfAtomComposite& BfAtomComposite::operator=(const BfAtomComposite& rhs) -{ +{ Set(rhs.mParts, rhs.mSize, NULL, 0); return *this; } @@ -279,7 +279,7 @@ bool BfAtomComposite::IsValid() const { for (int i = 0; i < mSize; i++) if (mParts[i] == NULL) - return false; + return false; return true; } @@ -310,13 +310,13 @@ String BfAtomComposite::ToString() const } void BfAtomComposite::ToString(StringImpl& str) const -{ +{ for (int i = 0; i < mSize; i++) { if (i > 0) str += "."; str += mParts[i]->mString; - } + } } bool BfAtomComposite::StartsWith(const BfAtomComposite& other) const @@ -334,7 +334,7 @@ bool BfAtomComposite::EndsWith(const BfAtomComposite& other) const int ofs = mSize - other.mSize; if (ofs < 0) return false; - + for (int i = 0; i < other.mSize; i++) if (mParts[i + ofs] != other.mParts[i]) return false; @@ -362,7 +362,7 @@ void BfAtomComposite::Reference(const BfAtomComposite & other) // Val128 BfAtomComposite::GetTypesHash() // { // Val128 hash; -// for (int i = 0; i < mSize; i++) +// for (int i = 0; i < mSize; i++) // { // auto atom = mParts[i]; // if (atom->mRefCount == 0) @@ -435,7 +435,7 @@ bool BfPropertyDef::IsVirtual() } bool BfPropertyDef::HasExplicitInterface() -{ +{ for (auto methodDef : mMethods) { if (methodDef->mExplicitInterface != NULL) @@ -470,21 +470,21 @@ BfAstNode* BfMethodDef::GetRefNode() if (operatorDef->mOperatorDeclaration->mOpTypeToken != NULL) return operatorDef->mOperatorDeclaration->mOpTypeToken; return operatorDef->mOperatorDeclaration->mOperatorToken; - } + } if (auto methodDeclaration = GetMethodDeclaration()) { if (auto ctorDecl = BfNodeDynCast(methodDeclaration)) - return ctorDecl->mThisToken; + return ctorDecl->mThisToken; if (methodDeclaration->mNameNode != NULL) - return methodDeclaration->mNameNode; + return methodDeclaration->mNameNode; return methodDeclaration; } if (auto methodDeclaration = GetPropertyMethodDeclaration()) - { + { return methodDeclaration->mNameNode; } - if (mDeclaringType != NULL) - return mDeclaringType->GetRefNode(); + if (mDeclaringType != NULL) + return mDeclaringType->GetRefNode(); return NULL; } @@ -505,7 +505,7 @@ bool BfMethodDef::HasBody() { auto body = methodDeclaration->mBody; return (body != NULL) && (!BfNodeIsA(body)); - } + } return false; } @@ -586,8 +586,8 @@ bool BfMethodDef::IsCtorOrInit() } String BfMethodDef::ToString() -{ - String methodText; +{ + String methodText; if (mName.empty()) { if (auto operatorDecl = BfNodeDynCast(mMethodDeclaration)) @@ -607,7 +607,7 @@ String BfMethodDef::ToString() else if (mMethodType == BfMethodType_Dtor) methodText += "~this"; else - methodText += mName; + methodText += mName; if (mMethodType == BfMethodType_Mixin) methodText += "!"; @@ -676,13 +676,13 @@ void BfMethodDef::BuildParamNameMap() void BfTypeDef::Reset() { FreeMembers(); - Init(); + Init(); } void BfTypeDef::FreeMembers() -{ +{ if ((!mIsCombinedPartial) && (mEmitParent == NULL)) - mSystem->RemoveNamespaceUsage(mNamespace, mProject); + mSystem->RemoveNamespaceUsage(mNamespace, mProject); if (mName != NULL) { @@ -707,17 +707,17 @@ void BfTypeDef::FreeMembers() { BF_ASSERT(mNameEx->mPendingDerefCount > 0); if (mNameEx->mPendingDerefCount > 0) - mNameEx->mPendingDerefCount--; + mNameEx->mPendingDerefCount--; } mSystem->ReleaseAtom(mNameEx); mNameEx = NULL; } - + for (auto genericParam : mGenericParamDefs) { // auto genericParamCopy = *genericParam; // BF_ASSERT(genericParam->mOwner != NULL); -// +// // if (genericParam->mOwner == this) delete genericParam; } @@ -728,18 +728,18 @@ void BfTypeDef::FreeMembers() mFields.Clear(); for (auto prop : mProperties) delete prop; - mProperties.Clear(); + mProperties.Clear(); for (auto method : mMethods) delete method; - mMethods.Clear(); + mMethods.Clear(); mNestedTypes.Clear(); // mOperators are also in mMethods so we don't need to delete those specifically mOperators.Clear(); for (auto& searchName : mNamespaceSearch) - mSystem->ReleaseAtomComposite(searchName); + mSystem->ReleaseAtomComposite(searchName); mNamespaceSearch.Clear(); - + mStaticSearch.Clear(); mInternalAccessSet.Clear(); @@ -799,7 +799,7 @@ void BfTypeDef::ClearMemberSets() for (auto entry : mFieldSet) ((BfFieldDef*)entry.mMemberDef)->mNextWithSameName = NULL; - mFieldSet.Clear(); + mFieldSet.Clear(); for (auto entry : mPropertySet) ((BfPropertyDef*)entry.mMemberDef)->mNextWithSameName = NULL; @@ -860,14 +860,14 @@ int BfTypeDef::GetSelfGenericParamCount() BfMethodDef* BfTypeDef::GetMethodByName(const StringImpl& name, int paramCount) { PopulateMemberSets(); - BfMemberSetEntry* entry = NULL; + BfMemberSetEntry* entry = NULL; if (!mMethodSet.TryGetWith(name, &entry)) return NULL; BfMethodDef* bestMethodDef = NULL; auto methodDef = (BfMethodDef*)entry->mMemberDef; while (methodDef != NULL) - { + { if (((paramCount == -1) || (paramCount == (int)methodDef->mParams.size()))) { if ((bestMethodDef == NULL) || @@ -892,7 +892,7 @@ BfFieldDef* BfTypeDef::GetFieldByName(const StringImpl& name) } String BfTypeDef::ToString() -{ +{ String typeName(mName->ToString()); auto checkOuterTypeDef = mOuterType; while (checkOuterTypeDef != NULL) @@ -926,7 +926,7 @@ bool BfTypeDef::HasAutoProperty(BfPropertyDeclaration* propertyDeclaration) return false; if (propertyDeclaration->mExternSpecifier != NULL) return false; - + for (auto methodDeclaration : propertyDeclaration->mMethods) { if (methodDeclaration->mBody == NULL) @@ -936,7 +936,7 @@ bool BfTypeDef::HasAutoProperty(BfPropertyDeclaration* propertyDeclaration) } String BfTypeDef::GetAutoPropertyName(BfPropertyDeclaration* propertyDeclaration) -{ +{ String name = "prop__"; if (propertyDeclaration->IsA()) name += "indexer__"; @@ -1001,9 +1001,9 @@ bool BfTypeDef::NameEquals(BfTypeDef* otherTypeDef) } bool BfTypeDef::HasSource(BfSource* source) -{ +{ if (mNextRevision != NULL) - return mNextRevision->HasSource(source); + return mNextRevision->HasSource(source); if (mSource == source) return true; if ((mSource != NULL) && (mSource->mNextRevision != NULL) && (mSource->mNextRevision == source)) @@ -1028,8 +1028,8 @@ bool BfTypeDef::HasParsingFailed() { auto parser = mTypeDeclaration->GetParser(); if ((parser != NULL) && (parser->mParsingFailed)) - return true; - + return true; + for (auto partial : mPartials) { parser = partial->mTypeDeclaration->GetParser(); @@ -1043,11 +1043,11 @@ bool BfTypeDef::HasParsingFailed() ////////////////////////////////////////////////////////////////////////// BfProject::BfProject() -{ +{ mDisabled = false; mSingleModule = false; mTargetType = BfTargetType_BeefConsoleApplication; - mBuildConfigChanged = false; + mBuildConfigChanged = false; mSingleModule = false; mAlwaysIncludeAll = false; mDeleteStage = BfProject::DeleteStage_None; @@ -1111,8 +1111,8 @@ size_t BfErrorEntry::GetHashCode() const HashContext hashCtx; hashCtx.Mixin(mError->mSrcStart); hashCtx.Mixin(mError->mSrcEnd); - hashCtx.Mixin(mError->mSource); - hashCtx.Mixin(mError->mIsWarning); + hashCtx.Mixin(mError->mSource); + hashCtx.Mixin(mError->mIsWarning); hashCtx.Mixin(mError->mIsDeferred); return (size_t)hashCtx.Finish64(); } @@ -1225,8 +1225,8 @@ bool BfPassInstance::WantsRangeDisplayed(BfSourceData* bfSource, int srcIdx, int auto bfParser = (bfSource == NULL) ? NULL : bfSource->ToParser(); if (bfParser == NULL) return true; - if (bfParser->mCursorIdx == -1) - return !mTrimMessagesToCursor; + if (bfParser->mCursorIdx == -1) + return !mTrimMessagesToCursor; if ((bfParser->mCursorIdx >= srcIdx) && (bfParser->mCursorIdx < srcIdx + srcLen)) return true; return false; @@ -1275,7 +1275,7 @@ static void VisibleAdvance(const char* str, int strLength, int& idx) idx++; break; } - + int cLen = 0; uint32 c32 = u8_toucs(str + idx, strLength - idx, &cLen); idx += cLen; @@ -1331,14 +1331,14 @@ void BfPassInstance::MessageAt(const StringImpl& msgPrefix, const StringImpl& er lineNum++; } } - + int lineChar = origSrcIdx - lineStart; bool endsWithPunctuation = false; int lastChar = error[(int)error.length() - 1]; String formatStr; if ((lastChar == '.') || (lastChar == '?') || (lastChar == '!')) - formatStr = "%s %s Line %d:%d in %s"; + formatStr = "%s %s Line %d:%d in %s"; else formatStr = "%s %s at line %d:%d in %s"; @@ -1358,19 +1358,19 @@ void BfPassInstance::MessageAt(const StringImpl& msgPrefix, const StringImpl& er else if (spaceCount == 1) lineStr.Append(""); spaceCount = 0; - + if (tabCount > 1) lineStr += StrFormat("<%d TABS>", tabCount); else if (tabCount == 1) lineStr.Append(""); - tabCount = 0; + tabCount = 0; }; for (int i = 0; i < 255; i++) { char c = bfParser->mSrc[lineStart + i]; if ((c == '\0') || (c == '\n') || (c == '\r')) - { + { break; } else if (c == '\t') @@ -1380,7 +1380,7 @@ void BfPassInstance::MessageAt(const StringImpl& msgPrefix, const StringImpl& er if (spaceCount > 0) _FlushSpacing(); tabCount++; - //lineStr.Append("\xe2\x86\x92"); // Arrow \u2192 + //lineStr.Append("\xe2\x86\x92"); // Arrow \u2192 } else lineStr.Append(' '); @@ -1403,7 +1403,7 @@ void BfPassInstance::MessageAt(const StringImpl& msgPrefix, const StringImpl& er showSpaces = false; lineStr.Append(c); } - } + } _FlushSpacing(); OutputLine(lineStr); @@ -1422,7 +1422,7 @@ void BfPassInstance::MessageAt(const StringImpl& msgPrefix, const StringImpl& er lineStr[i] = c; } OutputLine(lineStr);*/ - + // Don't show '^^^^^^^^^' under the entire line bool isFullUnderline = true; for (int i = lineStart; i < srcIdx; i++) @@ -1431,7 +1431,7 @@ void BfPassInstance::MessageAt(const StringImpl& msgPrefix, const StringImpl& er if (!::isspace((uint8)c)) isFullUnderline = false; } - + if (isFullUnderline) { isFullUnderline = false; @@ -1461,7 +1461,7 @@ void BfPassInstance::MessageAt(const StringImpl& msgPrefix, const StringImpl& er break; } OutputLine(pointerStr); - } + } } BfError* BfPassInstance::FailAt(const StringImpl& error, BfSourceData* bfSource, int srcIdx, int srcLen, BfFailFlags flags) @@ -1472,10 +1472,10 @@ BfError* BfPassInstance::FailAt(const StringImpl& error, BfSourceData* bfSource, mFailedIdx++; if ((int) mErrors.size() >= sMaxErrors) return NULL; - + if (!WantsRangeRecorded(bfSource, srcIdx, srcLen, false)) return NULL; - + TrimSourceRange(bfSource, srcIdx, srcLen); BfError* errorVal = new BfError(); @@ -1485,7 +1485,7 @@ BfError* BfPassInstance::FailAt(const StringImpl& error, BfSourceData* bfSource, errorVal->mError = error; errorVal->mSrcStart = srcIdx; errorVal->mSrcEnd = srcIdx + srcLen; - //int checkEnd = srcIdx + srcLen; + //int checkEnd = srcIdx + srcLen; for (int i = srcIdx; i < srcIdx + srcLen; i++) { char c = bfSource->mSrc[i]; @@ -1510,7 +1510,6 @@ BfError* BfPassInstance::FailAt(const StringImpl& error, BfSourceData* bfSource, return errorVal; } - void BfPassInstance::FixSrcStartAndEnd(BfSourceData* bfSource, int& startIdx, int& endIdx) { auto bfParser = bfSource->ToParserData(); @@ -1548,9 +1547,9 @@ BfError* BfPassInstance::FailAfterAt(const StringImpl& error, BfSourceData* bfSo FixSrcStartAndEnd(bfSource, errorVal->mSrcStart, errorVal->mSrcEnd); mErrorSet.Add(BfErrorEntry(errorVal)); mErrors.push_back(errorVal); - + mLastWasDisplayed = WantsRangeDisplayed(bfParser, srcIdx - 1, 2, false); - if (mLastWasDisplayed) + if (mLastWasDisplayed) { String errorStart = "ERROR"; /*if ((int)mErrors.size() > 1) @@ -1568,7 +1567,7 @@ BfError* BfPassInstance::Fail(const StringImpl& error) BfError* errorVal = new BfError(); errorVal->mIsWarning = false; - errorVal->mSource = NULL; + errorVal->mSource = NULL; errorVal->mIsAfter = false; errorVal->mError = error; errorVal->mSrcStart = 0; @@ -1598,7 +1597,7 @@ BfError* BfPassInstance::Fail(const StringImpl& errorStr, BfAstNode* refNode) else if (refNode->IsA()) error = FailAt(errorStr, refNode->GetSourceData(), refNode->GetSrcStart(), 1); else - error = FailAt(errorStr, refNode->GetSourceData(), refNode->GetSrcStart(), refNode->GetSrcLength()); + error = FailAt(errorStr, refNode->GetSourceData(), refNode->GetSrcStart(), refNode->GetSrcLength()); return error; } @@ -1636,12 +1635,12 @@ BfError* BfPassInstance::DeferFail(const StringImpl& error, BfAstNode* refNode) if (refNode == NULL) { - return Fail(error); + return Fail(error); } if (!WantsRangeRecorded(refNode->GetSourceData(), refNode->GetSrcStart(), refNode->GetSrcLength(), false, true)) return NULL; - + ++mDeferredErrorCount; BfError* errorVal = new BfError(); errorVal->mIsWarning = false; @@ -1672,7 +1671,7 @@ BfError* BfPassInstance::WarnAt(int warningNumber, const StringImpl& warning, Bf mLastWasAdded = false; if ((int) mErrors.size() >= sMaxErrors) return NULL; - + auto bfParser = bfSource->ToParserData(); if ((bfParser != NULL) && (warningNumber > 0) && (!bfParser->IsWarningEnabledAtSrcIndex(warningNumber, srcIdx))) return NULL; @@ -1735,7 +1734,7 @@ BfError* BfPassInstance::Warn(int warningNumber, const StringImpl& warning, BfAs mLastWasAdded = false; mLastWasDisplayed = (int)mErrors.size() <= sMaxErrors; if (!mLastWasDisplayed) - return NULL; + return NULL; auto parser = refNode->GetSourceData()->ToParserData(); if (parser != NULL) @@ -1745,7 +1744,7 @@ BfError* BfPassInstance::Warn(int warningNumber, const StringImpl& warning, BfAs mLastWasDisplayed = false; return NULL; } - } + } if (refNode != NULL) return WarnAt(warningNumber, warning, refNode->GetSourceData(), refNode->GetSrcStart(), refNode->GetSrcLength(), isDeferred); @@ -1811,7 +1810,7 @@ BfError* BfPassInstance::WarnAfterAt(int warningNumber, const StringImpl& error, } BfMoreInfo* BfPassInstance::MoreInfoAt(const StringImpl& info, BfSourceData* bfSource, int srcIdx, int srcLen, BfFailFlags flags) -{ +{ if (!mLastWasDisplayed) { if (mLastWasAdded) @@ -1836,7 +1835,7 @@ BfMoreInfo* BfPassInstance::MoreInfoAt(const StringImpl& info, BfSourceData* bfS } BfMoreInfo* BfPassInstance::MoreInfo(const StringImpl& info, bool forceQueue) -{ +{ if ((!mLastWasDisplayed) || (forceQueue)) { if (mLastWasAdded) @@ -1854,7 +1853,7 @@ BfMoreInfo* BfPassInstance::MoreInfo(const StringImpl& info, bool forceQueue) return NULL; } - + String outText; outText += " > "; outText += info; @@ -1863,7 +1862,7 @@ BfMoreInfo* BfPassInstance::MoreInfo(const StringImpl& info, bool forceQueue) } BfMoreInfo* BfPassInstance::MoreInfo(const StringImpl& info, BfAstNode* refNode) -{ +{ if (refNode == NULL) return MoreInfo(info); else @@ -1876,11 +1875,11 @@ BfMoreInfo* BfPassInstance::MoreInfoAfter(const StringImpl& info, BfAstNode* ref } void BfPassInstance::TryFlushDeferredError() -{ +{ // This can happen in the case of an internal compiler error, where we believe we've satisfied // generic constraints but we generate an error on the specialization but not the unspecialized version bool hasDisplayedError = false; - bool hasDisplayedWarning = false; + bool hasDisplayedWarning = false; for (int pass = 0; pass < 2; pass++) { for (auto& error : mErrors) @@ -1891,7 +1890,7 @@ void BfPassInstance::TryFlushDeferredError() hasDisplayedWarning = true; else if ((pass == 1) && (!hasDisplayedWarning)) { - String errorText = "WARNING "; + String errorText = "WARNING "; if (error->mWarningNumber > 0) errorText += StrFormat(": BF%04d", error->mWarningNumber); errorText += ": "; @@ -1911,21 +1910,21 @@ void BfPassInstance::TryFlushDeferredError() else { if (!error->mIsDeferred) - hasDisplayedError = true; + hasDisplayedError = true; else if ((pass == 1) && (!hasDisplayedError)) { - MessageAt(":error", "ERROR: " + error->mError, error->mSource, error->mSrcStart, error->mSrcEnd - error->mSrcStart); + MessageAt(":error", "ERROR: " + error->mError, error->mSource, error->mSrcStart, error->mSrcEnd - error->mSrcStart); for (auto moreInfo : error->mMoreInfo) { - if (moreInfo->mSource != NULL) + if (moreInfo->mSource != NULL) MessageAt(":error", " > " + moreInfo->mInfo, moreInfo->mSource, moreInfo->mSrcStart, moreInfo->mSrcEnd - moreInfo->mSrcStart); else OutputLine(":error " + moreInfo->mInfo); } } } - } + } } } @@ -1954,25 +1953,25 @@ BfSystem::BfSystem() if (gPerfManager == NULL) gPerfManager = new PerfManager(); //gPerfManager->StartRecording(); - + mAtomUpdateIdx = 0; mAtomCreateIdx = 0; mTypeMapVersion = 1; CreateBasicTypes(); - mPtrSize = 4; + mPtrSize = 4; mCurSystemLockPri = -1; mYieldDisallowCount = 0; mPendingSystemLockPri = -1; mCurSystemLockThreadId = 0; mYieldTickCount = 0; mHighestYieldTime = 0; - mNeedsTypesHandledByCompiler = false; + mNeedsTypesHandledByCompiler = false; mWorkspaceConfigChanged = false; mIsResolveOnly = false; mEmptyAtom = GetAtom(""); mBfAtom = GetAtom("bf"); mGlobalsAtom = GetAtom("@"); - mTypeDot = NULL; + mTypeDot = NULL; if (gBfParserCache == NULL) gBfParserCache = new BfParserCache(); @@ -2000,24 +1999,24 @@ BfSystem::BfSystem() mDirectRefIntTypeRef->mElementType = mDirectIntTypeRef; mDirectRefIntTypeRef->mRefToken = NULL; mDirectInt32TypeRef = mDirectTypeRefs.Alloc(); - mDirectInt32TypeRef->Init("int32"); + mDirectInt32TypeRef->Init("int32"); } BfSystem::~BfSystem() -{ +{ BP_ZONE("BfSystem::~BfSystem"); BfLogSys(this, "Deleting BfSystem...\n"); BfReportMemory(); //gPerfManager->StopRecording(); - //gPerfManager->DbgPrint(); + //gPerfManager->DbgPrint(); for (auto& typeItr : mSystemTypeDefs) delete typeItr.mValue; - for (auto typeDef : mTypeDefs) - delete typeDef; + for (auto typeDef : mTypeDefs) + delete typeDef; mTypeDefs.Clear(); for (auto typeDef : mTypeDefDeleteQueue) @@ -2026,7 +2025,7 @@ BfSystem::~BfSystem() { BP_ZONE("Deleting parsers"); for (auto parser : mParsers) - { + { delete parser; } } @@ -2035,11 +2034,11 @@ BfSystem::~BfSystem() delete project; for (auto project : mProjectDeleteQueue) - delete project; - + delete project; + ReleaseAtom(mGlobalsAtom); ReleaseAtom(mBfAtom); - ReleaseAtom(mEmptyAtom); + ReleaseAtom(mEmptyAtom); ProcessAtomGraveyard(); BF_ASSERT(mAtomMap.size() == 0); @@ -2066,7 +2065,7 @@ BfSystem::~BfSystem() mSystemTypeDefs[name] = typeDef; BfAtom* BfSystem::GetAtom(const StringImpl& string) -{ +{ StringView* stringPtr = NULL; BfAtom* atom = NULL; BfAtom** atomPtr = NULL; @@ -2087,7 +2086,7 @@ BfAtom* BfSystem::GetAtom(const StringImpl& string) atom->mString = *stringPtr; atom->mRefCount = 1; atom->mPendingDerefCount = 0; - + atom->mHash = 0; for (char c : string) atom->mHash = ((atom->mHash ^ c) << 5) - atom->mHash; @@ -2098,17 +2097,17 @@ BfAtom* BfSystem::GetAtom(const StringImpl& string) } else atom = *atomPtr; - + atom->Ref(); return atom; } BfAtom* BfSystem::FindAtom(const StringImpl& string) -{ +{ BfAtom** atomPtr = NULL; if (mAtomMap.TryGetValueWith(string, &atomPtr)) - return *atomPtr; - return NULL; + return *atomPtr; + return NULL; } BfAtom* BfSystem::FindAtom(const StringView& string) @@ -2120,13 +2119,13 @@ BfAtom* BfSystem::FindAtom(const StringView& string) } void BfSystem::ReleaseAtom(BfAtom* atom) -{ +{ if (--atom->mRefCount == 0) - { - mAtomGraveyard.push_back(atom); + { + mAtomGraveyard.push_back(atom); return; } - + BF_ASSERT(atom->mRefCount > 0); // Sanity check BF_ASSERT(atom->mRefCount < 1000000); @@ -2167,7 +2166,7 @@ bool BfSystem::ParseAtomComposite(const StringView& name, BfAtomComposite& compo BF_ASSERT(composite.mSize == 0); int lastDot = -1; for (int i = 0; i <= (int)name.mLength; i++) - { + { if ((i == (int)name.mLength) || (name[i] == '.')) { BfAtom* atom; @@ -2178,7 +2177,7 @@ bool BfSystem::ParseAtomComposite(const StringView& name, BfAtomComposite& compo if (atom == NULL) isValid = false; parts.push_back(atom); - lastDot = i; + lastDot = i; } } if (!parts.IsEmpty()) @@ -2210,7 +2209,7 @@ void BfSystem::SanityCheckAtomComposite(const BfAtomComposite& atomComposite) { for (int i = 0; i < atomComposite.mSize; i++) { - auto part = atomComposite.mParts[i]; + auto part = atomComposite.mParts[i]; BF_ASSERT(part != NULL); BF_ASSERT(part->mRefCount > 0); BF_ASSERT(part->mRefCount < 1000000); @@ -2218,7 +2217,7 @@ void BfSystem::SanityCheckAtomComposite(const BfAtomComposite& atomComposite) } void BfSystem::TrackName(BfTypeDef* typeDef) -{ +{ if (!typeDef->IsEmitted()) { for (int i = 0; i < (int)typeDef->mFullName.mSize - 1; i++) @@ -2242,7 +2241,7 @@ void BfSystem::UntrackName(BfTypeDef* typeDef) { BfAtom* nameAtom = typeDef->mName; if (nameAtom != mEmptyAtom) - { + { nameAtom->mAtomUpdateIdx = ++mAtomUpdateIdx; } @@ -2274,9 +2273,9 @@ void BfSystem::CreateBasicTypes() { BfTypeDef* typeDef; - SYSTEM_TYPE(mTypeVoid, "void", BfTypeCode_None); + SYSTEM_TYPE(mTypeVoid, "void", BfTypeCode_None); SYSTEM_TYPE(mTypeNullPtr, "null", BfTypeCode_NullPtr); - SYSTEM_TYPE(mTypeSelf, "Self", BfTypeCode_Self); + SYSTEM_TYPE(mTypeSelf, "Self", BfTypeCode_Self); SYSTEM_TYPE(mTypeVar, "var", BfTypeCode_Var); SYSTEM_TYPE(mTypeLet, "let", BfTypeCode_Let); SYSTEM_TYPE(mTypeBool, "bool", BfTypeCode_Boolean); @@ -2296,15 +2295,15 @@ void BfSystem::CreateBasicTypes() SYSTEM_TYPE(mTypeChar16, "char16", BfTypeCode_Char16); SYSTEM_TYPE(mTypeChar32, "char32", BfTypeCode_Char32); SYSTEM_TYPE(mTypeSingle, "float", BfTypeCode_Float); - SYSTEM_TYPE(mTypeDouble, "double", BfTypeCode_Double); + SYSTEM_TYPE(mTypeDouble, "double", BfTypeCode_Double); } bool BfSystem::DoesLiteralFit(BfTypeCode typeCode, int64 value) { - if (typeCode == BfTypeCode_IntPtr) + if (typeCode == BfTypeCode_IntPtr) typeCode = (mPtrSize == 4) ? BfTypeCode_Int32 : BfTypeCode_Int64; - if (typeCode == BfTypeCode_UIntPtr) - typeCode = (mPtrSize == 4) ? BfTypeCode_UInt32 : BfTypeCode_UInt64; + if (typeCode == BfTypeCode_UIntPtr) + typeCode = (mPtrSize == 4) ? BfTypeCode_UInt32 : BfTypeCode_UInt64; switch (typeCode) { @@ -2321,7 +2320,7 @@ bool BfSystem::DoesLiteralFit(BfTypeCode typeCode, int64 value) case BfTypeCode_UInt8: case BfTypeCode_Char8: - return (value >= 0) && (value < 0x100); + return (value >= 0) && (value < 0x100); case BfTypeCode_UInt16: case BfTypeCode_Char16: return (value >= 0) && (value < 0x10000); @@ -2337,7 +2336,7 @@ bool BfSystem::DoesLiteralFit(BfTypeCode typeCode, int64 value) } bool BfSystem::DoesLiteralFit(BfTypeCode typeCode, uint64 value) -{ +{ if (typeCode == BfTypeCode_IntPtr) typeCode = (mPtrSize == 4) ? BfTypeCode_Int32 : BfTypeCode_Int64; if (typeCode == BfTypeCode_UIntPtr) @@ -2393,7 +2392,7 @@ bool BfSystem::DoesLiteralFit(BfTypeCode typeCode, const BfVariant& variant) BfParser* BfSystem::CreateParser(BfProject* bfProject) { AutoCrit crit(mDataLock); - auto parser = new BfParser(this, bfProject); + auto parser = new BfParser(this, bfProject); mParsers.push_back(parser); BfLogSys(this, "CreateParser: %p\n", parser); @@ -2403,7 +2402,7 @@ BfParser* BfSystem::CreateParser(BfProject* bfProject) BfCompiler* BfSystem::CreateCompiler(bool isResolveOnly) { - auto compiler = new BfCompiler(this, isResolveOnly); + auto compiler = new BfCompiler(this, isResolveOnly); mCompilers.push_back(compiler); if (mIsResolveOnly) BF_ASSERT(isResolveOnly); @@ -2424,28 +2423,27 @@ BfProject* BfSystem::GetProject(const StringImpl& projName) BfTypeReference* BfSystem::GetTypeRefElement(BfTypeReference* typeRef) { if (auto elementedType = BfNodeDynCast(typeRef)) - return GetTypeRefElement(elementedType->mElementType); + return GetTypeRefElement(elementedType->mElementType); return (BfTypeReference*)typeRef; } - void BfSystem::AddNamespaceUsage(const BfAtomComposite& namespaceStr, BfProject* bfProject) { if (namespaceStr.IsEmpty()) return; - + if (namespaceStr.GetPartsCount() > 1) { - BfAtomComposite subComposite; + BfAtomComposite subComposite; subComposite.Set(namespaceStr.mParts, namespaceStr.mSize - 1, NULL, 0); AddNamespaceUsage(subComposite, bfProject); } int* valuePtr = NULL; if (bfProject->mNamespaces.TryAdd(namespaceStr, NULL, &valuePtr)) - { + { BfLogSys(this, "BfSystem::AddNamespaceUsage created %s in project: %p\n", namespaceStr.ToString().c_str(), bfProject); - *valuePtr = 1; + *valuePtr = 1; mTypeMapVersion++; } else @@ -2456,7 +2454,7 @@ void BfSystem::RemoveNamespaceUsage(const BfAtomComposite& namespaceStr, BfProje { if (namespaceStr.IsEmpty()) return; - + if (namespaceStr.GetPartsCount() > 1) { BfAtomComposite subComposite; @@ -2465,7 +2463,7 @@ void BfSystem::RemoveNamespaceUsage(const BfAtomComposite& namespaceStr, BfProje } int* valuePtr = NULL; - bfProject->mNamespaces.TryGetValue(namespaceStr, &valuePtr); + bfProject->mNamespaces.TryGetValue(namespaceStr, &valuePtr); BF_ASSERT(valuePtr != NULL); (*valuePtr)--; if (*valuePtr == 0) @@ -2497,7 +2495,7 @@ bool BfSystem::ContainsNamespace(const BfAtomComposite& namespaceStr, BfProject* } BfTypeDef* BfSystem::FilterDeletedTypeDef(BfTypeDef* typeDef) -{ +{ if ((typeDef != NULL) && (typeDef->mDefState == BfTypeDef::DefState_Deleted)) return NULL; return typeDef; @@ -2513,42 +2511,42 @@ bool BfSystem::CheckTypeDefReference(BfTypeDef* typeDef, BfProject* project) } BfTypeDef* BfSystem::FindTypeDef(const BfAtomComposite& findName, int numGenericArgs, BfProject* project, const Array& namespaceSearch, BfTypeDef** ambiguousTypeDef, BfFindTypeDefFlags flags) -{ +{ if (findName.GetPartsCount() == 1) - { + { BfTypeDef** typeDefPtr = NULL; if (mSystemTypeDefs.TryGetValueWith(findName.mParts[0]->mString, &typeDefPtr)) return FilterDeletedTypeDef(*typeDefPtr); } // This searched globals, but we were already doing that down below at the LAST step. Right? - BfTypeDef* foundTypeDef = NULL; + BfTypeDef* foundTypeDef = NULL; BfAtomCompositeT<16> qualifiedFindName; bool allowGlobal = (flags & BfFindTypeDefFlag_AllowGlobal) != 0; int foundPri = (int)0x80000000; for (int namespaceIdx = 0; namespaceIdx <= (int) namespaceSearch.size(); namespaceIdx++) - { + { int curNamespacePri = 0; if (namespaceIdx < (int)namespaceSearch.size()) - { + { auto& namespaceDeclaration = namespaceSearch[namespaceIdx]; qualifiedFindName.Set(namespaceDeclaration, findName); } else - { + { qualifiedFindName = findName; } - + int partialStartEntryIdx = -1; - auto itr = mTypeDefs.TryGet(qualifiedFindName); + auto itr = mTypeDefs.TryGet(qualifiedFindName); while (itr) { BfTypeDef* typeDef = *itr; - if ((typeDef->mIsPartial) || + if ((typeDef->mIsPartial) || ((typeDef->IsGlobalsContainer()) && ((flags & BfFindTypeDefFlag_AllowGlobal) == 0))) { bool handled = false; @@ -2577,7 +2575,7 @@ BfTypeDef* BfSystem::FindTypeDef(const BfAtomComposite& findName, int numGeneric continue; } } - + if ((partialStartEntryIdx != -1) && (!allowGlobal)) { mTypeDefs.SetPartialSkipCache(partialStartEntryIdx, itr.mCurEntry); @@ -2586,7 +2584,7 @@ BfTypeDef* BfSystem::FindTypeDef(const BfAtomComposite& findName, int numGeneric if ((typeDef->mFullName == qualifiedFindName) && (CheckTypeDefReference(typeDef, project))) { - int curPri = curNamespacePri; + int curPri = curNamespacePri; if (typeDef->mGenericParamDefs.size() != numGenericArgs) { // Still allow SOME match even if we put in the wrong number of generic args @@ -2603,7 +2601,7 @@ BfTypeDef* BfSystem::FindTypeDef(const BfAtomComposite& findName, int numGeneric else if (curPri == foundPri) { if ((ambiguousTypeDef != NULL) && (!typeDef->mIsPartial)) - *ambiguousTypeDef = typeDef; + *ambiguousTypeDef = typeDef; } } itr.MoveToNextHashMatch(); @@ -2611,18 +2609,18 @@ BfTypeDef* BfSystem::FindTypeDef(const BfAtomComposite& findName, int numGeneric if ((partialStartEntryIdx != -1) && (!allowGlobal)) mTypeDefs.SetPartialSkipCache(partialStartEntryIdx, -1); - } + } // Didn't match the correct number of generic params, but let the compiler complain return FilterDeletedTypeDef(foundTypeDef); } bool BfSystem::FindTypeDef(const BfAtomComposite& findName, int numGenericArgs, BfProject* project, const BfAtomComposite& checkNamespace, bool allowPrivate, BfTypeDefLookupContext* ctx) -{ +{ BfAtomComposite const* qualifiedFindNamePtr; BfAtomComposite qualifiedFindName; - BfAtom* tempData[16]; - + BfAtom* tempData[16]; + if (checkNamespace.IsEmpty()) { if ((findName.mSize == 1) && (findName.mParts[0]->mIsSystemType)) @@ -2636,31 +2634,31 @@ bool BfSystem::FindTypeDef(const BfAtomComposite& findName, int numGenericArgs, return true; } qualifiedFindNamePtr = &findName; - } + } else { qualifiedFindName.mAllocSize = 16; qualifiedFindName.mParts = tempData; qualifiedFindName.Set(checkNamespace, findName); qualifiedFindNamePtr = &qualifiedFindName; - } + } BfProtection minProtection = allowPrivate ? BfProtection_Private : BfProtection_Protected; bool hadMatch = false; - auto itr = mTypeDefs.TryGet(*qualifiedFindNamePtr); + auto itr = mTypeDefs.TryGet(*qualifiedFindNamePtr); while (itr) { BfTypeDef* typeDef = *itr; - if ((typeDef->mIsPartial) || + if ((typeDef->mIsPartial) || (typeDef->mDefState == BfTypeDef::DefState_Deleted)) { itr.MoveToNextHashMatch(); continue; } - + if ((typeDef->mFullName == *qualifiedFindNamePtr) && (CheckTypeDefReference(typeDef, project))) { int curPri = 0; @@ -2681,31 +2679,31 @@ bool BfSystem::FindTypeDef(const BfAtomComposite& findName, int numGenericArgs, if ((curPri > ctx->mBestPri) || (ctx->mBestTypeDef == NULL)) { - ctx->mBestTypeDef = typeDef; + ctx->mBestTypeDef = typeDef; ctx->mAmbiguousTypeDef = NULL; ctx->mBestPri = curPri; hadMatch = true; } else if (curPri == ctx->mBestPri) - { + { ctx->mAmbiguousTypeDef = typeDef; } } itr.MoveToNextHashMatch(); } - if (qualifiedFindName.mParts == tempData) - qualifiedFindName.mParts = NULL; + if (qualifiedFindName.mParts == tempData) + qualifiedFindName.mParts = NULL; return hadMatch; } BfTypeDef* BfSystem::FindTypeDef(const StringImpl& typeName, int numGenericArgs, BfProject* project, const Array& namespaceSearch, BfTypeDef** ambiguousTypeDef, BfFindTypeDefFlags flags) { - BfAtomCompositeT<16> qualifiedFindName; + BfAtomCompositeT<16> qualifiedFindName; BfTypeDef* result = NULL; if (ParseAtomComposite(typeName, qualifiedFindName)) - result = FindTypeDef(qualifiedFindName, numGenericArgs, project, namespaceSearch, ambiguousTypeDef, flags); + result = FindTypeDef(qualifiedFindName, numGenericArgs, project, namespaceSearch, ambiguousTypeDef, flags); return result; } @@ -2736,8 +2734,8 @@ BfTypeDef * BfSystem::FindTypeDef(const StringImpl& typeName, BfProject* project } } - if (firstChevIdx != -1) - findName = typeName.Substring(0, firstChevIdx); + if (firstChevIdx != -1) + findName = typeName.Substring(0, firstChevIdx); else findName = typeName; @@ -2756,12 +2754,12 @@ BfTypeDef* BfSystem::FindTypeDefEx(const StringImpl& fullTypeName) int numGenericArgs = 0; String typeName = fullTypeName.Substring(colonPos + 1); - int tildePos = (int)typeName.LastIndexOf('`'); + int tildePos = (int)typeName.LastIndexOf('`'); if (tildePos != -1) { BF_ASSERT(tildePos > (int)typeName.LastIndexOf('.')); numGenericArgs = atoi(typeName.c_str() + tildePos + 1); - typeName.RemoveToEnd(tildePos); + typeName.RemoveToEnd(tildePos); } BfAtomComposite qualifiedFindName; @@ -2771,15 +2769,15 @@ BfTypeDef* BfSystem::FindTypeDefEx(const StringImpl& fullTypeName) BfTypeDef* result = NULL; if (ParseAtomComposite(typeName, qualifiedFindName)) - { + { auto itr = mTypeDefs.TryGet(qualifiedFindName); while (itr) { - BfTypeDef* typeDef = *itr; - if ((typeDef->mFullName == qualifiedFindName) && (CheckTypeDefReference(typeDef, project)) && + BfTypeDef* typeDef = *itr; + if ((typeDef->mFullName == qualifiedFindName) && (CheckTypeDefReference(typeDef, project)) && (!typeDef->mIsPartial)) - { - if (typeDef->mGenericParamDefs.size() == numGenericArgs) + { + if (typeDef->mGenericParamDefs.size() == numGenericArgs) return typeDef; } itr.MoveToNextHashMatch(); @@ -2800,7 +2798,7 @@ void BfSystem::FindFixitNamespaces(const StringImpl& typeName, int numGenericArg // name and then adds its namespace to the fixitNamespaces for (auto typeDef : mTypeDefs) - { + { if ((typeDef->mName == findName.mParts[0]) && (CheckTypeDefReference(typeDef, project)) && ((numGenericArgs == -1) || (typeDef->mGenericParamDefs.size() == numGenericArgs))) @@ -2817,18 +2815,18 @@ void BfSystem::FindFixitNamespaces(const StringImpl& typeName, int numGenericArg outerName = typeDef->mNamespace.ToString(); fixitNamespaces.insert(outerName); } - } + } } void BfSystem::RemoveTypeDef(BfTypeDef* typeDef) -{ - BF_ASSERT(typeDef->mDefState == BfTypeDef::DefState_Deleted); +{ + BF_ASSERT(typeDef->mDefState == BfTypeDef::DefState_Deleted); // mTypeDef is already locked by the system lock - mTypeDefs.Remove(typeDef); + mTypeDefs.Remove(typeDef); AutoCrit autoCrit(mDataLock); - + if (typeDef->mOuterType != NULL) - { + { // We are in the outer type's mNestedTypes list BfLogSys(this, "Setting mForceUseNextRevision on outer type %p from %p\n", typeDef->mOuterType, typeDef); typeDef->mOuterType->mForceUseNextRevision = true; @@ -2847,8 +2845,8 @@ void BfSystem::RemoveTypeDef(BfTypeDef* typeDef) typeDef->mNameEx->mPendingDerefCount++; } typeDef->mInDeleteQueue = true; - - mTypeDefDeleteQueue.push_back(typeDef); + + mTypeDefDeleteQueue.push_back(typeDef); mTypeMapVersion++; } @@ -2859,7 +2857,7 @@ void BfSystem::InjectNewRevision(BfTypeDef* typeDef) bool setDeclaringType = !typeDef->mIsCombinedPartial; auto nextTypeDef = typeDef->mNextRevision; - + for (auto prevProperty : typeDef->mProperties) delete prevProperty; typeDef->mProperties = nextTypeDef->mProperties; @@ -2867,12 +2865,12 @@ void BfSystem::InjectNewRevision(BfTypeDef* typeDef) for (auto prop : typeDef->mProperties) prop->mDeclaringType = typeDef; nextTypeDef->mProperties.Clear(); - + if ((typeDef->mDefState != BfTypeDef::DefState_Signature_Changed) && (typeDef->mDefState != BfTypeDef::DefState_New)) { BF_ASSERT(typeDef->mMethods.size() == nextTypeDef->mMethods.size()); - + for (auto prop : typeDef->mProperties) { for (int methodIdx = 0; methodIdx < (int)prop->mMethods.size(); methodIdx++) @@ -2882,7 +2880,7 @@ void BfSystem::InjectNewRevision(BfTypeDef* typeDef) for (int opIdx = 0; opIdx < (int)typeDef->mOperators.size(); opIdx++) { typeDef->mOperators[opIdx] = (BfOperatorDef*)typeDef->mMethods[typeDef->mOperators[opIdx]->mIdx]; - } + } // Remap methods in-place to previous revision's method list for (int methodIdx = 0; methodIdx < (int)typeDef->mMethods.size(); methodIdx++) @@ -2906,7 +2904,7 @@ void BfSystem::InjectNewRevision(BfTypeDef* typeDef) } else { - *methodDef = *nextMethodDef; + *methodDef = *nextMethodDef; if (setDeclaringType) methodDef->mDeclaringType = typeDef; } @@ -2918,7 +2916,7 @@ void BfSystem::InjectNewRevision(BfTypeDef* typeDef) } } else - { + { typeDef->mOperators = nextTypeDef->mOperators; nextTypeDef->mOperators.Clear(); @@ -2930,23 +2928,23 @@ void BfSystem::InjectNewRevision(BfTypeDef* typeDef) if (setDeclaringType) for (auto method : typeDef->mMethods) method->mDeclaringType = typeDef; - nextTypeDef->mMethods.Clear(); + nextTypeDef->mMethods.Clear(); } for (auto fieldDef : typeDef->mFields) fieldDef->mNextWithSameName = NULL; for (auto propDef : typeDef->mProperties) propDef->mNextWithSameName = NULL; - for (auto methodDef : typeDef->mMethods) - methodDef->mNextWithSameName = NULL; + for (auto methodDef : typeDef->mMethods) + methodDef->mNextWithSameName = NULL; if (typeDef->mSource != NULL) - typeDef->mSource->mRefCount--; + typeDef->mSource->mRefCount--; typeDef->mSource = nextTypeDef->mSource; typeDef->mSource->mRefCount++; typeDef->mPartialIdx = nextTypeDef->mPartialIdx; - typeDef->mTypeDeclaration = nextTypeDef->mTypeDeclaration; + typeDef->mTypeDeclaration = nextTypeDef->mTypeDeclaration; typeDef->mHash = nextTypeDef->mHash; typeDef->mSignatureHash = nextTypeDef->mSignatureHash; typeDef->mFullHash = nextTypeDef->mFullHash; @@ -2964,22 +2962,22 @@ void BfSystem::InjectNewRevision(BfTypeDef* typeDef) BF_ASSERT(typeDef->mFullNameEx == nextTypeDef->mFullNameEx); - typeDef->mProtection = nextTypeDef->mProtection; + typeDef->mProtection = nextTypeDef->mProtection; BF_ASSERT(typeDef->mTypeCode == nextTypeDef->mTypeCode); typeDef->mTypeCode = nextTypeDef->mTypeCode; typeDef->mShow = nextTypeDef->mShow; typeDef->mIsAlwaysInclude = nextTypeDef->mIsAlwaysInclude; - typeDef->mIsNoDiscard = nextTypeDef->mIsNoDiscard; + typeDef->mIsNoDiscard = nextTypeDef->mIsNoDiscard; typeDef->mIsPartial = nextTypeDef->mIsPartial; typeDef->mIsExplicitPartial = nextTypeDef->mIsExplicitPartial; - //mPartialUsed + //mPartialUsed typeDef->mIsCombinedPartial = nextTypeDef->mIsCombinedPartial; typeDef->mIsDelegate = nextTypeDef->mIsDelegate; typeDef->mIsFunction = nextTypeDef->mIsFunction; typeDef->mIsClosure = nextTypeDef->mIsClosure; - typeDef->mIsAbstract = nextTypeDef->mIsAbstract; + typeDef->mIsAbstract = nextTypeDef->mIsAbstract; typeDef->mIsStatic = nextTypeDef->mIsStatic; typeDef->mHasAppendCtor = nextTypeDef->mHasAppendCtor; typeDef->mHasCEOnCompile = nextTypeDef->mHasCEOnCompile; @@ -2988,20 +2986,20 @@ void BfSystem::InjectNewRevision(BfTypeDef* typeDef) typeDef->mHasExtensionMethods = nextTypeDef->mHasExtensionMethods; typeDef->mHasUsingFields = nextTypeDef->mHasUsingFields; typeDef->mIsOpaque = nextTypeDef->mIsOpaque; - - typeDef->mDupDetectedRevision = nextTypeDef->mDupDetectedRevision; - + + typeDef->mDupDetectedRevision = nextTypeDef->mDupDetectedRevision; + for (auto prevDirectNodes : typeDef->mDirectAllocNodes) delete prevDirectNodes; typeDef->mDirectAllocNodes = nextTypeDef->mDirectAllocNodes; nextTypeDef->mDirectAllocNodes.Clear(); for (auto name : typeDef->mNamespaceSearch) - ReleaseAtomComposite(name); + ReleaseAtomComposite(name); typeDef->mNamespaceSearch = nextTypeDef->mNamespaceSearch; for (auto name : typeDef->mNamespaceSearch) RefAtomComposite(name); - + typeDef->mStaticSearch = nextTypeDef->mStaticSearch; typeDef->mInternalAccessSet = nextTypeDef->mInternalAccessSet; @@ -3013,19 +3011,19 @@ void BfSystem::InjectNewRevision(BfTypeDef* typeDef) if (setDeclaringType) for (auto field : typeDef->mFields) field->mDeclaringType = typeDef; - nextTypeDef->mFields.Clear(); - + nextTypeDef->mFields.Clear(); + for (auto genericParam : typeDef->mGenericParamDefs) delete genericParam; typeDef->mGenericParamDefs.Clear(); - + typeDef->mGenericParamDefs = nextTypeDef->mGenericParamDefs; typeDef->mExternalConstraints = nextTypeDef->mExternalConstraints; - nextTypeDef->mGenericParamDefs.Clear(); + nextTypeDef->mGenericParamDefs.Clear(); + + typeDef->mBaseTypes = nextTypeDef->mBaseTypes; + typeDef->mNestedTypes = nextTypeDef->mNestedTypes; - typeDef->mBaseTypes = nextTypeDef->mBaseTypes; - typeDef->mNestedTypes = nextTypeDef->mNestedTypes; - // If we are a partial then the mOuterType gets set to the combined partial so don't do that here if (!typeDef->mIsCombinedPartial) { @@ -3035,7 +3033,7 @@ void BfSystem::InjectNewRevision(BfTypeDef* typeDef) nestedType->mOuterType = typeDef; } } - typeDef->mPartials = nextTypeDef->mPartials; + typeDef->mPartials = nextTypeDef->mPartials; typeDef->mMethodSet.Clear(); typeDef->mFieldSet.Clear(); typeDef->mPropertySet.Clear(); @@ -3043,7 +3041,7 @@ void BfSystem::InjectNewRevision(BfTypeDef* typeDef) delete nextTypeDef; typeDef->mNextRevision = NULL; - typeDef->mDefState = BfTypeDef::DefState_Defined; + typeDef->mDefState = BfTypeDef::DefState_Defined; typeDef->mForceUseNextRevision = false; VerifyTypeDef(typeDef); @@ -3063,9 +3061,9 @@ void BfSystem::AddToCompositePartial(BfPassInstance* passInstance, BfTypeDef* co { typeDef = new BfTypeDef(); compositeTypeDef->mNextRevision = typeDef; - + typeDef->mIsCombinedPartial = true; - + typeDef->mTypeDeclaration = partialTypeDef->mTypeDeclaration; typeDef->mSource = partialTypeDef->mSource; typeDef->mSource->mRefCount++; @@ -3077,19 +3075,19 @@ void BfSystem::AddToCompositePartial(BfPassInstance* passInstance, BfTypeDef* co typeDef->mIsDelegate = partialTypeDef->mIsDelegate; typeDef->mNestDepth = partialTypeDef->mNestDepth; typeDef->mOuterType = partialTypeDef->mOuterType; - typeDef->mNamespace = partialTypeDef->mNamespace; + typeDef->mNamespace = partialTypeDef->mNamespace; typeDef->mName = partialTypeDef->mName; typeDef->mName->Ref(); - TrackName(typeDef); + TrackName(typeDef); typeDef->mNameEx = partialTypeDef->mNameEx; typeDef->mNameEx->Ref(); typeDef->mFullName = partialTypeDef->mFullName; typeDef->mFullNameEx = partialTypeDef->mFullNameEx; - typeDef->mProtection = partialTypeDef->mProtection; + typeDef->mProtection = partialTypeDef->mProtection; typeDef->mIsDelegate = partialTypeDef->mIsDelegate; - typeDef->mIsAbstract = partialTypeDef->mIsAbstract; + typeDef->mIsAbstract = partialTypeDef->mIsAbstract; typeDef->mIsStatic = partialTypeDef->mIsStatic; - typeDef->mHasAppendCtor = partialTypeDef->mHasAppendCtor; + typeDef->mHasAppendCtor = partialTypeDef->mHasAppendCtor; typeDef->mHasCtorNoBody = partialTypeDef->mHasCtorNoBody; typeDef->mHasExtensionMethods = partialTypeDef->mHasExtensionMethods; typeDef->mHasUsingFields = partialTypeDef->mHasUsingFields; @@ -3104,8 +3102,8 @@ void BfSystem::AddToCompositePartial(BfPassInstance* passInstance, BfTypeDef* co typeDef->mGenericParamDefs.push_back(newGeneric); } typeDef->mExternalConstraints = partialTypeDef->mExternalConstraints; - - typeDef->mBaseTypes = partialTypeDef->mBaseTypes; + + typeDef->mBaseTypes = partialTypeDef->mBaseTypes; isFirst = true; @@ -3119,31 +3117,31 @@ void BfSystem::AddToCompositePartial(BfPassInstance* passInstance, BfTypeDef* co if (partialTypeDef->mTypeCode != BfTypeCode_Extension) { typeDef->mTypeCode = partialTypeDef->mTypeCode; - typeDef->mTypeDeclaration = partialTypeDef->mTypeDeclaration; - } + typeDef->mTypeDeclaration = partialTypeDef->mTypeDeclaration; + } // for (auto& externConstraint : partialTypeDef->mExternalConstraints) // typeDef->mExternalConstraints.Add(externConstraint); - } + } // Merge attributes together - typeDef->mIsAbstract |= partialTypeDef->mIsAbstract; + typeDef->mIsAbstract |= partialTypeDef->mIsAbstract; typeDef->mIsStatic |= partialTypeDef->mIsStatic; - typeDef->mHasAppendCtor |= partialTypeDef->mHasAppendCtor; + typeDef->mHasAppendCtor |= partialTypeDef->mHasAppendCtor; typeDef->mHasCEOnCompile |= partialTypeDef->mHasCEOnCompile; typeDef->mHasExtensionMethods |= partialTypeDef->mHasExtensionMethods; typeDef->mHasUsingFields |= partialTypeDef->mHasUsingFields; - typeDef->mHasOverrideMethods |= partialTypeDef->mHasOverrideMethods; + typeDef->mHasOverrideMethods |= partialTypeDef->mHasOverrideMethods; for (auto innerType : partialTypeDef->mNestedTypes) { typeDef->mNestedTypes.push_back(innerType); } - + //TODO: We had the CLEAR here, but it caused an issue because when we have to rebuild the composite then // we don't actually have the nested types from the original typeDef if they original typedef wasn't rebuilt //partialTypeDef->mNestedTypes.Clear(); // Only reference from main typedef - + for (auto field : partialTypeDef->mFields) { BfFieldDef* newField = new BfFieldDef(); @@ -3151,16 +3149,16 @@ void BfSystem::AddToCompositePartial(BfPassInstance* passInstance, BfTypeDef* co newField->mIdx = (int)typeDef->mFields.size(); typeDef->mFields.push_back(newField); } - typeDef->mFieldSet.Clear(); - + typeDef->mFieldSet.Clear(); + bool hadNoDeclMethod = false; int startMethodIdx = (int)typeDef->mMethods.size(); for (auto method : partialTypeDef->mMethods) { bool ignoreNewMethod = false; - + if (typeDef->mTypeCode == BfTypeCode_Interface) - { + { if (method->mMethodDeclaration == NULL) continue; @@ -3168,8 +3166,8 @@ void BfSystem::AddToCompositePartial(BfPassInstance* passInstance, BfTypeDef* co { if (methodDeclaration->mProtectionSpecifier == NULL) method->mProtection = BfProtection_Public; - } - } + } + } BfMethodDef* newMethod = NULL; if (method->mMethodType == BfMethodType_Operator) @@ -3186,7 +3184,7 @@ void BfSystem::AddToCompositePartial(BfPassInstance* passInstance, BfTypeDef* co } method->mParamNameMap = NULL; newMethod->mIdx = (int)typeDef->mMethods.size(); - for (int paramIdx = 0; paramIdx < (int)newMethod->mParams.size(); paramIdx++) + for (int paramIdx = 0; paramIdx < (int)newMethod->mParams.size(); paramIdx++) { BfParameterDef* param = newMethod->mParams[paramIdx]; BfParameterDef* newParam = new BfParameterDef(); @@ -3202,7 +3200,7 @@ void BfSystem::AddToCompositePartial(BfPassInstance* passInstance, BfTypeDef* co } if (ignoreNewMethod) newMethod->mMethodType = BfMethodType_Ignore; - typeDef->mMethods.push_back(newMethod); + typeDef->mMethods.push_back(newMethod); } typeDef->mMethodSet.Clear(); @@ -3216,7 +3214,7 @@ void BfSystem::AddToCompositePartial(BfPassInstance* passInstance, BfTypeDef* co typeDef->mProperties.push_back(newProp); } typeDef->mPropertySet.Clear(); - + BF_ASSERT(partialTypeDef->mPartials.empty()); partialTypeDef->mPartialIdx = (int)typeDef->mPartials.size(); typeDef->mPartials.push_back(partialTypeDef); @@ -3248,17 +3246,17 @@ void BfSystem::FinishCompositePartial(BfTypeDef* compositeTypeDef) _HasMethods allHasMethods[2][2] = { 0 }; auto primaryDef = nextRevision->mPartials[0]; - + //Dictionary projectCount; bool hasCtorNoBody = false; - + bool primaryHasFieldInitializers = false; bool anyHasInitializers = false; // For methods that require chaining, make sure the primary def has a definition for (auto partialTypeDef : nextRevision->mPartials) - { + { bool isExtension = partialTypeDef->mTypeDeclaration != nextRevision->mTypeDeclaration; if (!isExtension) primaryDef = partialTypeDef; @@ -3291,10 +3289,10 @@ void BfSystem::FinishCompositePartial(BfTypeDef* compositeTypeDef) for (auto fieldDef : partialTypeDef->mFields) { - if (!fieldDef->mIsStatic) + if (!fieldDef->mIsStatic) { if (auto fieldDeclaration = BfNodeDynCast(fieldDef->mFieldDeclaration)) - if (fieldDeclaration->mInitializer != NULL) + if (fieldDeclaration->mInitializer != NULL) hasInitializers = true; if (auto paramDeclaration = BfNodeDynCast(fieldDef->mFieldDeclaration)) if (paramDeclaration->mInitializer != NULL) @@ -3306,9 +3304,9 @@ void BfSystem::FinishCompositePartial(BfTypeDef* compositeTypeDef) if (hasInitializers) { - anyHasInitializers = true; + anyHasInitializers = true; if (!isExtension) - primaryHasFieldInitializers = true; + primaryHasFieldInitializers = true; nextRevision->mHasCtorNoBody = true; auto methodDef = BfDefBuilder::AddMethod(nextRevision, BfMethodType_CtorNoBody, BfProtection_Protected, false, ""); methodDef->mDeclaringType = partialTypeDef; @@ -3326,11 +3324,11 @@ void BfSystem::FinishCompositePartial(BfTypeDef* compositeTypeDef) if ((allHasMethods[0][0].mCtor == 0) && (allHasMethods[1][0].mCtor > 1)) { - auto methodDef = BfDefBuilder::AddMethod(nextRevision, BfMethodType_Ctor, (allHasMethods[1][0].mCtorPublic > 0) ? BfProtection_Public : BfProtection_Protected, false, ""); + auto methodDef = BfDefBuilder::AddMethod(nextRevision, BfMethodType_Ctor, (allHasMethods[1][0].mCtorPublic > 0) ? BfProtection_Public : BfProtection_Protected, false, ""); methodDef->mDeclaringType = primaryDef; methodDef->mIsMutating = true; } - + // if (!hasCtorNoBody) // { // auto methodDef = BfDefBuilder::AddMethod(nextRevision, BfMethodType_CtorNoBody, BfProtection_Protected, false, ""); @@ -3395,7 +3393,7 @@ void BfSystem::CopyTypeDef(BfTypeDef* typeDef, BfTypeDef* fromTypeDef) BfLogSys(this, "CopyTypeDef %p from %p Hash: %d\n", typeDef, fromTypeDef, fromTypeDef->mHash); for (auto fromMethodDef : fromTypeDef->mMethods) - { + { BfMethodDef* methodDef; if (fromMethodDef->mIsOperator) { @@ -3418,7 +3416,7 @@ void BfSystem::CopyTypeDef(BfTypeDef* typeDef, BfTypeDef* fromTypeDef) { auto fromParamDef = fromMethodDef->mParams[paramIdx]; BfParameterDef* paramDef = new BfParameterDef(); - *paramDef = *fromParamDef; + *paramDef = *fromParamDef; methodDef->mParams[paramIdx] = paramDef; } @@ -3443,13 +3441,13 @@ void BfSystem::CopyTypeDef(BfTypeDef* typeDef, BfTypeDef* fromTypeDef) } for (auto fromPropDef : fromTypeDef->mProperties) - { - BfPropertyDef* propDef = new BfPropertyDef(); + { + BfPropertyDef* propDef = new BfPropertyDef(); *propDef = *fromPropDef; if (propDef->mDeclaringType == fromTypeDef) propDef->mDeclaringType = typeDef; - for (auto& methodDef : propDef->mMethods) - methodDef = typeDef->mMethods[methodDef->mIdx]; + for (auto& methodDef : propDef->mMethods) + methodDef = typeDef->mMethods[methodDef->mIdx]; propDef->mNextWithSameName = NULL; typeDef->mProperties.Add(propDef); } @@ -3463,7 +3461,7 @@ void BfSystem::CopyTypeDef(BfTypeDef* typeDef, BfTypeDef* fromTypeDef) fieldDef->mNextWithSameName = NULL; typeDef->mFields.Add(fieldDef); } - + typeDef->mSystem = fromTypeDef->mSystem; typeDef->mProject = fromTypeDef->mProject; typeDef->mPartialIdx = fromTypeDef->mPartialIdx; @@ -3475,8 +3473,8 @@ void BfSystem::CopyTypeDef(BfTypeDef* typeDef, BfTypeDef* fromTypeDef) typeDef->mNestDepth = fromTypeDef->mNestDepth; typeDef->mOuterType = fromTypeDef->mOuterType; - //typeDef->mOuterType = fromTypeDef->mOuterType; - typeDef->mNamespace = fromTypeDef->mNamespace; + //typeDef->mOuterType = fromTypeDef->mOuterType; + typeDef->mNamespace = fromTypeDef->mNamespace; typeDef->mName = fromTypeDef->mName; if (typeDef->mName != mEmptyAtom) @@ -3485,7 +3483,7 @@ void BfSystem::CopyTypeDef(BfTypeDef* typeDef, BfTypeDef* fromTypeDef) //typeDef->mName = fromTypeDef->mName; typeDef->mNameEx = fromTypeDef->mNameEx; if (typeDef->mNameEx != NULL) - typeDef->mNameEx->mRefCount++; + typeDef->mNameEx->mRefCount++; //typeDef->mNameEx = fromTypeDef->mNameEx; typeDef->mFullName = fromTypeDef->mFullName; @@ -3500,7 +3498,7 @@ void BfSystem::CopyTypeDef(BfTypeDef* typeDef, BfTypeDef* fromTypeDef) typeDef->mIsNoDiscard = fromTypeDef->mIsNoDiscard; typeDef->mIsPartial = fromTypeDef->mIsPartial; typeDef->mIsExplicitPartial = fromTypeDef->mIsExplicitPartial; - //mPartialUsed + //mPartialUsed typeDef->mIsCombinedPartial = fromTypeDef->mIsCombinedPartial; typeDef->mIsDelegate = fromTypeDef->mIsDelegate; typeDef->mIsFunction = fromTypeDef->mIsFunction; @@ -3516,31 +3514,31 @@ void BfSystem::CopyTypeDef(BfTypeDef* typeDef, BfTypeDef* fromTypeDef) typeDef->mIsOpaque = fromTypeDef->mIsOpaque; typeDef->mDupDetectedRevision = fromTypeDef->mDupDetectedRevision; - + typeDef->mDirectAllocNodes = fromTypeDef->mDirectAllocNodes; fromTypeDef->mDirectAllocNodes.Clear(); - + typeDef->mNamespaceSearch = fromTypeDef->mNamespaceSearch; for (auto name : typeDef->mNamespaceSearch) RefAtomComposite(name); typeDef->mStaticSearch = fromTypeDef->mStaticSearch; typeDef->mInternalAccessSet = fromTypeDef->mInternalAccessSet; - + for (auto fromGenericParamDef : fromTypeDef->mGenericParamDefs) { BfGenericParamDef* genericParamDef = new BfGenericParamDef(); *genericParamDef = *fromGenericParamDef; typeDef->mGenericParamDefs.Add(genericParamDef); - } + } - typeDef->mExternalConstraints = fromTypeDef->mExternalConstraints; + typeDef->mExternalConstraints = fromTypeDef->mExternalConstraints; typeDef->mBaseTypes = fromTypeDef->mBaseTypes; typeDef->mNestedTypes = fromTypeDef->mNestedTypes; - + typeDef->mPartials = fromTypeDef->mPartials; - + VerifyTypeDef(typeDef); } @@ -3559,7 +3557,7 @@ void BfSystem::UpdateEmittedTypeDef(BfTypeDef* typeDef) typeDef->mOuterType = fromTypeDef->mOuterType; for (int methodIdx = 0; methodIdx < (int)typeDef->mMethods.size(); methodIdx++) - { + { auto methodDef = typeDef->mMethods[methodIdx]; if (methodIdx >= fromTypeDef->mMethods.mSize) { @@ -3601,7 +3599,7 @@ void BfSystem::UpdateEmittedTypeDef(BfTypeDef* typeDef) BfGenericParamDef* genericParam = new BfGenericParamDef(); *genericParam = *fromGenericParam; methodDef->mGenericParams[genericParamIdx] = genericParam; - } + } } typeDef->mOperators.Clear(); @@ -3639,7 +3637,7 @@ void BfSystem::UpdateEmittedTypeDef(BfTypeDef* typeDef) BF_ASSERT(propertyDef->mDeclaringType != typeDef); auto fromPropertyDef = fromTypeDef->mProperties[propertyIdx]; propertyDef->mDeclaringType = fromPropertyDef->mDeclaringType; - } + } typeDef->mGenericParamDefs.Clear(); for (auto fromGenericParamDef : fromTypeDef->mGenericParamDefs) @@ -3681,7 +3679,7 @@ BfTypeDef* BfSystem::GetOuterTypeNonPartial(BfTypeDef* typeDef) if ((checkType == NULL) || (!checkType->mIsPartial)) return checkType; - return GetCombinedPartial(checkType); + return GetCombinedPartial(checkType); } int BfSystem::GetGenericParamIdx(const Array& genericParams, const StringImpl& name) @@ -3711,7 +3709,7 @@ void BfSystem::SummarizeYieldSection() } void BfSystem::CheckLockYield() -{ +{ if (mYieldDisallowCount != 0) return; @@ -3725,7 +3723,7 @@ void BfSystem::CheckLockYield() int mySystemLockPri = mCurSystemLockPri; BF_ASSERT(mSystemLock.mLockCount == 1); mSystemLock.Unlock(); - // Wait for the other thread to actually acquire the lock. This only spins between the time + // Wait for the other thread to actually acquire the lock. This only spins between the time // we get a NotifyWillRequestLock and when that thread actually does the Lock while (mPendingSystemLockPri != -1) { @@ -3742,7 +3740,7 @@ void BfSystem::NotifyWillRequestLock(int priority) } void BfSystem::Lock(int priority) -{ +{ #ifdef _DEBUG if (priority > 0) { @@ -3772,7 +3770,7 @@ void BfSystem::Unlock() void BfSystem::AssertWeHaveLock() { -#ifdef BF_PLATFORM_WINDOWS +#ifdef BF_PLATFORM_WINDOWS BF_ASSERT_REL(((CRITICAL_SECTION*)mSystemLock.mCritSect)->OwningThread == (HANDLE)(uintptr)::GetCurrentThreadId()); #endif } @@ -3805,24 +3803,24 @@ void BfSystem::RemoveOldParsers() { mDataLock.Lock(); - // We can't be allowed to delete old parsers if the new typedefs haven't been + // We can't be allowed to delete old parsers if the new typedefs haven't been // injected yet by the compiler if (mNeedsTypesHandledByCompiler) { mDataLock.Unlock(); return; } - + RemoveDeletedParsers(); - + for (int i = 0; i < (int)mParsers.size(); i++) { auto bfParser = mParsers[i]; - + bool wantsDelete = false; - + if (bfParser->mRefCount == 0) - { + { if ((bfParser->mNextRevision != NULL) || (bfParser->mAwaitingDelete)) { if (bfParser->mNextRevision != NULL) @@ -3837,19 +3835,19 @@ void BfSystem::RemoveOldParsers() mDataLock.Unlock(); delete bfParser; - mDataLock.Lock(); + mDataLock.Lock(); } - } + } } mDataLock.Unlock(); } void BfSystem::RemoveOldData() -{ +{ { AutoCrit autoCrit(mDataLock); - for (int i = 0; i < (int)mTypeDefDeleteQueue.size(); i++) + for (int i = 0; i < (int)mTypeDefDeleteQueue.size(); i++) { auto typeDef = mTypeDefDeleteQueue[i]; mTypeDefDeleteQueue[i] = NULL; @@ -3857,7 +3855,7 @@ void BfSystem::RemoveOldData() delete typeDef; } mTypeDefDeleteQueue.Clear(); - + if (!mProjectDeleteQueue.IsEmpty()) { for (auto project : mProjectDeleteQueue) @@ -3881,7 +3879,7 @@ void BfSystem::RemoveOldData() projectIdx--; } } - } + } } RemoveOldParsers(); @@ -3932,7 +3930,7 @@ BfTypeOptions* BfSystem::GetTypeOptions(int optionsIdx) if (optionsIdx < 0) return NULL; if (optionsIdx < mTypeOptions.size()) - return &mTypeOptions[optionsIdx]; + return &mTypeOptions[optionsIdx]; return &mMergedTypeOptions[optionsIdx - mTypeOptions.size()]; } @@ -3974,12 +3972,12 @@ BF_EXPORT void BF_CALLTYPE BfSystem_Delete(BfSystem* bfSystem) } BF_EXPORT void BF_CALLTYPE BfSystem_CheckLock(BfSystem* bfSystem) -{ +{ BF_ASSERT(bfSystem->mSystemLock.mLockCount == 0); } BF_EXPORT void BF_CALLTYPE BfResolvePassData_Delete(BfResolvePassData* resolvePassData) -{ +{ delete resolvePassData->mAutoComplete; for (auto tempType : resolvePassData->mAutoCompleteTempTypes) delete tempType; @@ -4005,7 +4003,7 @@ BF_EXPORT void BF_CALLTYPE BfResolvePassData_SetMethodGenericParamIdx(BfResolveP } BF_EXPORT void BF_CALLTYPE BfResolvePassData_SetSymbolReferenceTypeDef(BfResolvePassData* resolvePassData, const char* replaceTypeDef) -{ +{ resolvePassData->mQueuedReplaceTypeDef = replaceTypeDef; resolvePassData->mGetSymbolReferenceKind = BfGetSymbolReferenceKind_Type; } @@ -4060,7 +4058,7 @@ BF_EXPORT void* BfResolvePassData_GetEmitEmbedData(BfResolvePassData* resolvePas *charCount = emitEmbedEntry->mParser->mSrcLength; auto emitParser = emitEmbedEntry->mParser; - emitParser->mSourceClassifier->FlushDeferredNodes(); + emitParser->mSourceClassifier->FlushDeferredNodes(); return emitEmbedEntry->mParser->mSourceClassifier->mCharData; } @@ -4071,7 +4069,7 @@ BF_EXPORT bool BfResolvePassData_GetHadEmits(BfResolvePassData* resolvePassData) } BF_EXPORT BfParser* BF_CALLTYPE BfSystem_CreateParser(BfSystem* bfSystem, BfProject* bfProject) -{ +{ return bfSystem->CreateParser(bfProject); } @@ -4089,7 +4087,7 @@ BF_EXPORT void BF_CALLTYPE BfSystem_DeleteParser(BfSystem* bfSystem, BfParser* b typeDef->mDefState = BfTypeDef::DefState_Deleted; } } - //bfSystem->mParserDeleteQueue.push_back(bfParser); + //bfSystem->mParserDeleteQueue.push_back(bfParser); } BF_EXPORT BfCompiler* BF_CALLTYPE BfSystem_CreateCompiler(BfSystem* bfSystem, bool isResolveOnly) @@ -4136,7 +4134,7 @@ BF_EXPORT const char* BF_CALLTYPE BfPassInstance_GetErrorData(BfPassInstance* bf } if (outLine != NULL) - { + { auto parserData = bfError->mSource->ToParserData(); if (parserData != NULL) { @@ -4168,7 +4166,7 @@ BF_EXPORT const char* BfPassInstance_Error_GetMoreInfoData(BfPassInstance* bfPas if (bfPassInstance->mSourceFileNameMap.TryGetValue(moreInfo->mSource, &srcFileName)) { fileName = (char*)srcFileName->c_str(); - } + } } if (moreInfo->mLocation != NULL) @@ -4247,27 +4245,26 @@ BF_EXPORT void BF_CALLTYPE BfSystem_Update(BfSystem* bfSystem) BF_EXPORT void BF_CALLTYPE BfSystem_ReportMemory(BfSystem* bfSystem) { AutoCrit crit(bfSystem->mDataLock); - + MemReporter memReporter; - - + for (auto compiler : bfSystem->mCompilers) { AutoMemReporter autoMemReporter(&memReporter, "Compiler"); compiler->ReportMemory(&memReporter); - } - + } + for (auto typeDef : bfSystem->mTypeDefs) { AutoMemReporter autoMemReporter(&memReporter, "TypeDef"); typeDef->ReportMemory(&memReporter); - } + } for (auto parser : bfSystem->mParsers) { AutoMemReporter autoMemReporter(&memReporter, "Parsers"); parser->ReportMemory(&memReporter); - } + } memReporter.Report(); } @@ -4278,7 +4275,7 @@ BF_EXPORT void BF_CALLTYPE BfSystem_StartTiming() } BF_EXPORT void BF_CALLTYPE BfSystem_PerfZoneStart(const char* name) -{ +{ gPerfManager->ZoneStart(name); } @@ -4297,7 +4294,6 @@ BF_EXPORT void BF_CALLTYPE BfSystem_DbgPrintTimings() gPerfManager->DbgPrint(); } - BF_EXPORT const char* BF_CALLTYPE BfSystem_GetNamespaceSearch(BfSystem* bfSystem, const char* typeName, BfProject* project) { auto typeDef = bfSystem->FindTypeDef(typeName, project); @@ -4324,7 +4320,7 @@ BF_EXPORT BfProject* BF_CALLTYPE BfSystem_CreateProject(BfSystem* bfSystem, cons bfProject->mDirectory = projectDir; bfProject->mSystem = bfSystem; bfProject->mIdx = (int)bfSystem->mProjects.size(); - bfSystem->mProjects.push_back(bfProject); + bfSystem->mProjects.push_back(bfProject); String safeProjectName = projectName; for (auto& c : safeProjectName) @@ -4346,7 +4342,7 @@ BF_EXPORT BfProject* BF_CALLTYPE BfSystem_CreateProject(BfSystem* bfSystem, cons break; tryName = safeProjectName + StrFormat("_%d", i); } - bfProject->mSafeName = tryName; + bfProject->mSafeName = tryName; BfLogSys(bfSystem, "Creating project %p\n", bfProject); return bfProject; @@ -4401,11 +4397,11 @@ BF_EXPORT void BF_CALLTYPE BfSystem_AddTypeOptions(BfSystem* bfSystem, char* fil if ((typeOptions.mTypeFilters.IsEmpty()) && (typeOptions.mAttributeFilters.IsEmpty())) return; typeOptions.mSIMDSetting = simdSetting; - typeOptions.mOptimizationLevel = optimizationLevel; + typeOptions.mOptimizationLevel = optimizationLevel; typeOptions.mEmitDebugInfo = emitDebugInfo; typeOptions.mAndFlags = (BfOptionFlags)andFlags; typeOptions.mOrFlags = (BfOptionFlags)orFlags; - typeOptions.mAllocStackTraceDepth = allocStackTraceDepth; + typeOptions.mAllocStackTraceDepth = allocStackTraceDepth; Array methodReflectFilters; Array methodReflectAttributeFilters; @@ -4414,16 +4410,16 @@ BF_EXPORT void BF_CALLTYPE BfSystem_AddTypeOptions(BfSystem* bfSystem, char* fil // When we have method filters we want to apply those to the methods for when we merge options if ((!methodReflectFilters.IsEmpty()) || (!methodReflectAttributeFilters.IsEmpty())) { - for (auto& filter : methodReflectFilters) + for (auto& filter : methodReflectFilters) typeOptions.mReflectMethodFilters.Add({ filter, (BfOptionFlags)andFlags, (BfOptionFlags)orFlags }); for (auto& filter : methodReflectAttributeFilters) typeOptions.mReflectMethodAttributeFilters.Add({ filter, (BfOptionFlags)andFlags, (BfOptionFlags)orFlags }); - + typeOptions.mAndFlags = (BfOptionFlags)(typeOptions.mAndFlags | BfOptionFlags_Reflect_MethodMask); typeOptions.mOrFlags = (BfOptionFlags)(typeOptions.mOrFlags & ~BfOptionFlags_Reflect_MethodMask); } - bfSystem->mTypeOptions.push_back(typeOptions); + bfSystem->mTypeOptions.push_back(typeOptions); } BF_EXPORT void BF_CALLTYPE BfProject_Delete(BfProject* bfProject) @@ -4432,11 +4428,11 @@ BF_EXPORT void BF_CALLTYPE BfProject_Delete(BfProject* bfProject) AutoCrit autoCrit(bfSystem->mSystemLock); bfProject->mDeleteStage = BfProject::DeleteStage_Queued; - bfSystem->mProjectDeleteQueue.push_back(bfProject); + bfSystem->mProjectDeleteQueue.push_back(bfProject); bfSystem->mUsedSafeProjectNames.Remove(bfProject->mSafeName); - BF_ASSERT(bfSystem->mProjects[bfProject->mIdx] == bfProject); - bool wasRemoved = bfSystem->mProjects.Remove(bfProject); + BF_ASSERT(bfSystem->mProjects[bfProject->mIdx] == bfProject); + bool wasRemoved = bfSystem->mProjects.Remove(bfProject); BF_ASSERT(wasRemoved); for (int i = bfProject->mIdx; i < (int)bfSystem->mProjects.size(); i++) @@ -4444,7 +4440,7 @@ BF_EXPORT void BF_CALLTYPE BfProject_Delete(BfProject* bfProject) bfProject->mIdx = -1; -/*#ifdef _DEBUG +/*#ifdef _DEBUG { AutoCrit autoCrit(bfSystem->mSystemLock); for (auto typeDefKV : bfSystem->mTypeDefs) @@ -4469,7 +4465,7 @@ BF_EXPORT void BF_CALLTYPE BfProject_AddDependency(BfProject* bfProject, BfProje } BF_EXPORT void BF_CALLTYPE BfProject_SetDisabled(BfProject* bfProject, bool disabled) -{ +{ bfProject->mDisabled = disabled; } @@ -4477,8 +4473,8 @@ BF_EXPORT void BF_CALLTYPE BfProject_SetOptions(BfProject* bfProject, int target int optLevel, int ltoType, int relocType, int picLevel, BfProjectFlags flags) { bfProject->mTargetType = (BfTargetType)targetType; - bfProject->mStartupObject = startupObject; - + bfProject->mStartupObject = startupObject; + BfCodeGenOptions codeGenOptions; codeGenOptions.mOptLevel = (BfOptLevel)optLevel; codeGenOptions.mLTOType = (BfLTOType)ltoType; @@ -4487,7 +4483,7 @@ BF_EXPORT void BF_CALLTYPE BfProject_SetOptions(BfProject* bfProject, int target codeGenOptions.mMergeFunctions = (flags & BfProjectFlags_MergeFunctions) != 0; codeGenOptions.mLoadCombine = (flags & BfProjectFlags_CombineLoads) != 0; codeGenOptions.mLoopVectorize = (flags & BfProjectFlags_VectorizeLoops) != 0; - codeGenOptions.mSLPVectorize = (flags & BfProjectFlags_VectorizeSLP) != 0; + codeGenOptions.mSLPVectorize = (flags & BfProjectFlags_VectorizeSLP) != 0; if ((flags & BfProjectFlags_AsmOutput) != 0) { static bool setLLVMAsmKind = false; @@ -4499,15 +4495,15 @@ BF_EXPORT void BF_CALLTYPE BfProject_SetOptions(BfProject* bfProject, int target if (!setLLVMAsmKind) { setLLVMAsmKind = true; - BfIRCodeGen::SetAsmKind(codeGenOptions.mAsmKind); + BfIRCodeGen::SetAsmKind(codeGenOptions.mAsmKind); } - } + } bfProject->mCodeGenOptions = codeGenOptions; bfProject->mSingleModule = (flags & BfProjectFlags_SingleModule) != 0; bfProject->mAlwaysIncludeAll = (flags & BfProjectFlags_AlwaysIncludeAll) != 0; bfProject->mPreprocessorMacros.Clear(); - + int startIdx = 0; int idx = 0; while (true) @@ -4546,7 +4542,7 @@ public: std::map mReplaceMap; public: - + String GetTypeName(const StringImpl& typeName) { if (typeName == "long") @@ -4587,8 +4583,8 @@ public: void Visit(BfTypeReference* typeRef) { - String typeName = typeRef->ToString(); - String wantTypeName = GetTypeName(typeName); + String typeName = typeRef->ToString(); + String wantTypeName = GetTypeName(typeName); if (typeName != wantTypeName) { ReplaceRecord replaceRecord = { typeRef, wantTypeName }; @@ -4632,7 +4628,7 @@ public: { SetAndRestoreValue prevInMethod(mInMethod, true); BfElementVisitor::Visit(methodDecl); - } + } void FixStr(String& source) { @@ -4658,10 +4654,10 @@ public: String origFileName = parser->mFileName; origFileName.Insert(3, "Orig_"); - + String source; source.Insert(0, parser->mSrc, parser->mSrcLength); - + String origSource = source; FixStr(origSource); RecursiveCreateDirectory(GetFileDir(origFileName)); @@ -4669,7 +4665,7 @@ public: fwrite(origSource.c_str(), 1, (int)origSource.length(), fp); fclose(fp); - VisitMembers(parser->mRootNode); + VisitMembers(parser->mRootNode); int ofs = 0; for (auto& pair : mReplaceMap) @@ -4701,6 +4697,4 @@ BF_EXPORT void BF_CALLTYPE BfSystem_Log(BfSystem* bfSystem, char* str) { BfLogSys(bfSystem, str); BfLogSys(bfSystem, "\n"); -} - - +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfSystem.h b/IDEHelper/Compiler/BfSystem.h index 6ef9c9fd..d8706366 100644 --- a/IDEHelper/Compiler/BfSystem.h +++ b/IDEHelper/Compiler/BfSystem.h @@ -56,7 +56,7 @@ public: uint32 mAtomUpdateIdx; bool mIsSystemType; Dictionary mPrevNamesMap; - + public: ~BfAtom(); const StringView& ToString() @@ -68,7 +68,7 @@ public: str += mString; } - void Ref(); + void Ref(); }; class BfAtomComposite @@ -80,15 +80,15 @@ public: bool mOwns; public: - BfAtomComposite(); + BfAtomComposite(); BfAtomComposite(BfAtomComposite&& rhs); BfAtomComposite(const BfAtomComposite& rhs); - BfAtomComposite(BfAtom* atom); + BfAtomComposite(BfAtom* atom); BfAtomComposite(const BfAtomComposite& left, const BfAtomComposite& right); BfAtomComposite(const BfAtomComposite& left, BfAtom* right); ~BfAtomComposite(); - - void Set(const BfAtomComposite& left, const BfAtomComposite& right); + + void Set(const BfAtomComposite& left, const BfAtomComposite& right); void Set(BfAtom** atomsA, int countA, BfAtom** atomsB, int countB); BfAtomComposite& operator=(const BfAtomComposite& rhs); bool operator==(const BfAtomComposite& other) const; @@ -102,7 +102,7 @@ public: bool EndsWith(const BfAtomComposite& other) const; BfAtomComposite GetSub(int start, int len) const; void Reference(const BfAtomComposite& other); - + uint32 GetAtomUpdateIdx(); }; @@ -138,17 +138,17 @@ class BfSizedAtomComposite : public BfAtomComposite public: BfAtom* mInitialAlloc[8]; - BfSizedAtomComposite(); - ~BfSizedAtomComposite(); + BfSizedAtomComposite(); + ~BfSizedAtomComposite(); }; struct BfAtomCompositeHash { size_t operator()(const BfAtomComposite& composite) const { - int curHash = 0; - for (int i = 0; i < (int)composite.mSize; i++) - curHash = ((curHash ^ (int)(intptr)composite.mParts[i]->mHash) << 5) - curHash; + int curHash = 0; + for (int i = 0; i < (int)composite.mSize; i++) + curHash = ((curHash ^ (int)(intptr)composite.mParts[i]->mHash) << 5) - curHash; return curHash; } }; @@ -179,7 +179,7 @@ enum BfCompilerOptionFlags BfCompilerOptionFlag_EmitLineInfo = 2, BfCompilerOptionFlag_WriteIR = 4, BfCompilerOptionFlag_GenerateOBJ = 8, - BfCompilerOptionFlag_GenerateBitcode = 0x10, + BfCompilerOptionFlag_GenerateBitcode = 0x10, BfCompilerOptionFlag_ClearLocalVars = 0x20, BfCompilerOptionFlag_RuntimeChecks = 0x40, BfCompilerOptionFlag_EmitDynamicCastCheck = 0x80, @@ -190,7 +190,7 @@ enum BfCompilerOptionFlags BfCompilerOptionFlag_EnableSideStack = 0x1000, BfCompilerOptionFlag_EnableHotSwapping = 0x2000, BfCompilerOptionFlag_IncrementalBuild = 0x4000, - BfCompilerOptionFlag_DebugAlloc = 0x8000, + BfCompilerOptionFlag_DebugAlloc = 0x8000, BfCompilerOptionFlag_OmitDebugHelpers = 0x10000, BfCompilerOptionFlag_NoFramePointerElim = 0x20000, BfCompilerOptionFlag_ArithmeticChecks = 0x40000, @@ -234,7 +234,7 @@ enum BfMethodFlags BfMethodFlags_FastCall = 0x2000, BfMethodFlags_ThisCall = 0x3000, BfMethodFlags_Mutating = 0x4000, - BfMethodFlags_Constructor = 0x8000 + BfMethodFlags_Constructor = 0x8000 }; enum BfObjectFlags : uint8 @@ -344,7 +344,7 @@ enum BfLTOType }; enum BfCFLAAType -{ +{ BfCFLAAType_None, BfCFLAAType_Steensgaard, BfCFLAAType_Andersen, @@ -354,11 +354,11 @@ enum BfCFLAAType enum BfRelocType { BfRelocType_NotSet, - BfRelocType_Static, - BfRelocType_PIC, + BfRelocType_Static, + BfRelocType_PIC, BfRelocType_DynamicNoPIC, BfRelocType_ROPI, - BfRelocType_RWPI, + BfRelocType_RWPI, BfRelocType_ROPI_RWPI }; @@ -366,32 +366,32 @@ enum BfPICLevel { BfPICLevel_NotSet, BfPICLevel_Not, - BfPICLevel_Small, + BfPICLevel_Small, BfPICLevel_Big }; struct BfCodeGenOptions -{ +{ bool mIsHotCompile; bool mWriteObj; bool mWriteBitcode; BfAsmKind mAsmKind; bool mWriteToLib; - bool mWriteLLVMIR; + bool mWriteLLVMIR; int16 mVirtualMethodOfs; int16 mDynSlotOfs; BfRelocType mRelocType; BfPICLevel mPICLevel; - BfSIMDSetting mSIMDSetting; + BfSIMDSetting mSIMDSetting; BfOptLevel mOptLevel; BfLTOType mLTOType; int mSizeLevel; BfCFLAAType mUseCFLAA; bool mUseNewSROA; - + bool mDisableTailCalls; bool mDisableUnitAtATime; bool mDisableUnrollLoops; @@ -410,7 +410,7 @@ struct BfCodeGenOptions bool mUseGVNAfterVectorization; bool mEnableLoopInterchange; bool mEnableLoopLoadElim; - bool mExtraVectorizerPasses; + bool mExtraVectorizerPasses; bool mEnableEarlyCSEMemSSA; bool mEnableGVNHoist; bool mEnableGVNSink; @@ -427,8 +427,8 @@ struct BfCodeGenOptions Val128 mHash; BfCodeGenOptions() - { - mIsHotCompile = false; + { + mIsHotCompile = false; mWriteObj = true; mWriteBitcode = false; mAsmKind = BfAsmKind_None; @@ -436,7 +436,7 @@ struct BfCodeGenOptions mWriteLLVMIR = false; mVirtualMethodOfs = 0; mDynSlotOfs = 0; - + mRelocType = BfRelocType_NotSet; mPICLevel = BfPICLevel_NotSet; mSIMDSetting = BfSIMDSetting_None; @@ -445,7 +445,7 @@ struct BfCodeGenOptions mSizeLevel = 0; mUseCFLAA = BfCFLAAType_None; mUseNewSROA = false; - + mDisableTailCalls = false; mDisableUnitAtATime = false; mDisableUnrollLoops = false; @@ -480,7 +480,7 @@ struct BfCodeGenOptions } void GenerateHash() - { + { HashContext hashCtx; hashCtx.Mixin(mWriteObj); @@ -524,7 +524,6 @@ struct BfCodeGenOptions } }; - enum BfParamKind : uint8 { BfParamKind_Normal, @@ -547,7 +546,7 @@ class BfParameterDef { public: String mName; - BfTypeReference* mTypeRef; + BfTypeReference* mTypeRef; BfParameterDeclaration* mParamDeclaration; int mMethodGenericParamIdx; BfParamKind mParamKind; @@ -559,7 +558,7 @@ public: mTypeRef = NULL; mMethodGenericParamIdx = -1; mParamKind = BfParamKind_Normal; - mParamDeclaration = NULL; + mParamDeclaration = NULL; mNamePrefixCount = 0; } void SetName(BfAstNode* nameNode); @@ -579,7 +578,7 @@ public: bool mIsStatic; BfShow mShow; bool mIsReadOnly; - bool mHasMultiDefs; + bool mHasMultiDefs; public: BfMemberDef() @@ -603,25 +602,25 @@ public: class BfFieldDef : public BfMemberDef { public: - int mIdx; - bool mIsConst; // Note: Consts are also all considered Static + int mIdx; + bool mIsConst; // Note: Consts are also all considered Static BfTypeReference* mTypeRef; BfProtection mUsingProtection; bool mIsInline; bool mIsVolatile; - bool mIsExtern; + bool mIsExtern; bool mIsAppend; - bool mIsProperty; + bool mIsProperty; BfAstNode* mFieldDeclaration; // 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; public: BfFieldDef() { mIdx = 0; - mIsConst = false; + mIsConst = false; mTypeRef = NULL; mUsingProtection = BfProtection_Hidden; mIsInline = false; @@ -686,7 +685,7 @@ public: return paramDecl->mInitializer; return NULL; } - + BfAstNode* GetNameNode() { if (auto fieldDecl = GetFieldDeclaration()) @@ -699,18 +698,18 @@ public: class BfPropertyDef : public BfFieldDef { -public: - Array mMethods; +public: + Array mMethods; BfPropertyDef* mNextWithSameName; public: BfPropertyDef() - { + { mNextWithSameName = NULL; - } + } bool IsVirtual(); - bool HasExplicitInterface(); + bool HasExplicitInterface(); bool IsExpressionBodied(); BfAstNode* GetRefNode(); }; @@ -722,7 +721,7 @@ enum BfGenericParamFlags : uint16 BfGenericParamFlag_Struct = 2, BfGenericParamFlag_StructPtr = 4, BfGenericParamFlag_Enum = 8, - BfGenericParamFlag_Interface = 0x10, + BfGenericParamFlag_Interface = 0x10, BfGenericParamFlag_Concrete = 0x20, BfGenericParamFlag_New = 0x40, BfGenericParamFlag_Delete = 0x80, @@ -768,10 +767,10 @@ public: class BfGenericParamDef : public BfConstraintDef { -public: - String mName; +public: + String mName; Array mNameNodes; // 0 is always the def name - + bool operator==(const BfGenericParamDef& other) const { if (mName != other.mName) @@ -788,7 +787,7 @@ public: class BfExternalConstraintDef : public BfConstraintDef { public: - BfTypeReference* mTypeRef; + BfTypeReference* mTypeRef; }; // CTOR is split into two for Objects - Ctor clears and sets up VData, Ctor_Body executes ctor body code @@ -814,7 +813,7 @@ enum BfCallingConvention : uint8 BfCallingConvention_Unspecified, BfCallingConvention_Cdecl, BfCallingConvention_Stdcall, - BfCallingConvention_Fastcall, + BfCallingConvention_Fastcall, }; #define BF_METHODNAME_MARKMEMBERS "GCMarkMembers" @@ -866,9 +865,9 @@ enum BfComptimeFlags : int8 class BfMethodDef : public BfMemberDef { -public: - BfAstNode* mMethodDeclaration; - BfAstNode* mBody; +public: + BfAstNode* mMethodDeclaration; + BfAstNode* mBody; BfTypeReference* mExplicitInterface; BfTypeReference* mReturnTypeRef; @@ -893,7 +892,7 @@ public: bool mWantsBody; bool mCLink; bool mHasAppend; - bool mAlwaysInline; + bool mAlwaysInline; bool mIsNoReturn; bool mIsMutating; bool mIsNoSplat; @@ -901,14 +900,14 @@ public: bool mIsSkipCall; bool mHasComptime; bool mIsOperator; - bool mIsExtern; + bool mIsExtern; bool mIsNoDiscard; bool mHasExplicitThis; bool mAddedAfterEmit; BfCommutableKind mCommutableKind; BfCheckedKind mCheckedKind; - BfImportKind mImportKind; - BfCallingConvention mCallingConvention; + BfImportKind mImportKind; + BfCallingConvention mCallingConvention; public: BfMethodDef() @@ -923,7 +922,7 @@ public: mIsStatic = false; mIsNew = false; mIsPartial = false; - mCLink = false; + mCLink = false; mIsNoReturn = false; mIsMutating = false; mIsNoSplat = false; @@ -958,16 +957,16 @@ public: bool HasNoThisSplat() { return mIsMutating || mIsNoSplat; } void Reset(); void FreeMembers(); - BfMethodDeclaration* GetMethodDeclaration(); + BfMethodDeclaration* GetMethodDeclaration(); BfPropertyMethodDeclaration* GetPropertyMethodDeclaration(); BfPropertyDeclaration* GetPropertyDeclaration(); BfAstNode* GetRefNode(); - BfTokenNode* GetMutNode(); + BfTokenNode* GetMutNode(); bool HasBody(); - bool IsEmptyPartial(); + bool IsEmptyPartial(); bool IsDefaultCtor(); bool IsCtorOrInit(); - String ToString(); + String ToString(); int GetExplicitParamCount(); void BuildParamNameMap(); }; @@ -975,7 +974,7 @@ public: class BfOperatorDef : public BfMethodDef { public: - BfOperatorDeclaration* mOperatorDeclaration; + BfOperatorDeclaration* mOperatorDeclaration; public: BfOperatorDef() @@ -996,7 +995,7 @@ public: struct BfTypeDefLookupContext { public: - int mBestPri; + int mBestPri; BfTypeDef* mBestTypeDef; BfTypeDef* mAmbiguousTypeDef; @@ -1005,8 +1004,8 @@ public: { mBestPri = (int)0x80000000; mBestTypeDef = NULL; - mAmbiguousTypeDef = NULL; - } + mAmbiguousTypeDef = NULL; + } bool HasValidMatch() { @@ -1036,12 +1035,12 @@ struct BfMemberSetEntry class BfTypeDefMemberSet : public HashSet { -public: +public: int mSourceSize; public: BfTypeDefMemberSet() - { + { mSourceSize = 0; } @@ -1052,7 +1051,7 @@ public: } }; -// 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 { public: @@ -1073,16 +1072,16 @@ public: public: BfTypeDef* mNextRevision; - + BfSystem* mSystem; BfProject* mProject; BfTypeDeclaration* mTypeDeclaration; - BfSource* mSource; - DefState mDefState; + BfSource* mSource; + DefState mDefState; Val128 mSignatureHash; // Data, methods, etc - Val128 mFullHash; + Val128 mFullHash; Val128 mInlineHash; - + BfTypeDef* mEmitParent; BfTypeDef* mOuterType; BfAtomComposite mNamespace; @@ -1101,13 +1100,13 @@ public: BfTypeDefMemberSet mFieldSet; BfTypeDefMemberSet mPropertySet; Array mOperators; - Array mGenericParamDefs; + Array mGenericParamDefs; Array mExternalConstraints; - Array mBaseTypes; - Array mNestedTypes; + Array mBaseTypes; + Array mNestedTypes; Array mDirectAllocNodes; - Array mPartials; // Only valid for mIsCombinedPartial - + Array mPartials; // Only valid for mIsCombinedPartial + int mHash; int mPartialIdx; int mNestDepth; @@ -1123,29 +1122,29 @@ public: bool mIsDelegate; bool mIsFunction; bool mIsClosure; - bool mIsAbstract; - bool mIsStatic; + bool mIsAbstract; + bool mIsStatic; bool mHasCEOnCompile; bool mHasAppendCtor; bool mHasCtorNoBody; bool mHasExtensionMethods; - bool mHasOverrideMethods; + bool mHasOverrideMethods; bool mHasUsingFields; bool mIsOpaque; bool mIsNextRevision; - bool mInDeleteQueue; + bool mInDeleteQueue; bool mForceUseNextRevision; public: BfTypeDef() - { + { Init(); } ~BfTypeDef(); void Init() - { + { mName = NULL; mNameEx = NULL; mSystem = NULL; @@ -1158,11 +1157,11 @@ public: mIsPartial = false; mIsCombinedPartial = false; mTypeDeclaration = NULL; - mSource = NULL; + mSource = NULL; mDefState = DefState_New; - mHash = 0; + mHash = 0; mPartialIdx = -1; - mIsAbstract = false; + mIsAbstract = false; mIsDelegate = false; mIsFunction = false; mIsClosure = false; @@ -1176,29 +1175,29 @@ public: mIsOpaque = false; mPartialUsed = false; mIsNextRevision = false; - mInDeleteQueue = false; + mInDeleteQueue = false; mForceUseNextRevision = false; mDupDetectedRevision = -1; mNestDepth = 0; mEmitParent = NULL; mOuterType = NULL; - mTypeDeclaration = NULL; + mTypeDeclaration = NULL; mNextRevision = NULL; - mProtection = BfProtection_Public; + mProtection = BfProtection_Public; } BfSource* GetLastSource(); - bool IsGlobalsContainer(); + bool IsGlobalsContainer(); void Reset(); void FreeMembers(); void PopulateMemberSets(); void ClearMemberSets(); - void RemoveGenericParamDef(BfGenericParamDef* genericParamDef); + void RemoveGenericParamDef(BfGenericParamDef* genericParamDef); int GetSelfGenericParamCount(); String ToString(); BfMethodDef* GetMethodByName(const StringImpl& name, int paramCount = -1); BfFieldDef* GetFieldByName(const StringImpl& name); - bool HasAutoProperty(BfPropertyDeclaration* propertyDeclaration); + bool HasAutoProperty(BfPropertyDeclaration* propertyDeclaration); bool ContainsPartial(BfTypeDef* partialTypeDef); bool HasParsingFailed(); String GetAutoPropertyName(BfPropertyDeclaration* propertyDeclaration); @@ -1274,7 +1273,7 @@ public: SkipEntry() { mIndex = -1; - mRevision = -1; + mRevision = -1; } SkipEntry(int index, int revision) @@ -1337,12 +1336,12 @@ public: enum BfTargetType { BfTargetType_BeefConsoleApplication, - BfTargetType_BeefWindowsApplication, - BfTargetType_BeefLib, + BfTargetType_BeefWindowsApplication, + BfTargetType_BeefLib, BfTargetType_CustomBuild, BfTargetType_BeefTest, BfTargetType_C_ConsoleApplication, - BfTargetType_C_WindowsApplication, + BfTargetType_C_WindowsApplication, BfTargetType_BeefApplication_StaticLib, BfTargetType_BeefApplication_DynamicLib, BfTargetType_BeefLib_StaticLib, @@ -1372,14 +1371,14 @@ public: DeleteStage_AwaitingRefs, }; -public: +public: BfSystem* mSystem; String mName; String mSafeName; String mDirectory; Array mDependencies; BfTargetType mTargetType; - BfCodeGenOptions mCodeGenOptions; + BfCodeGenOptions mCodeGenOptions; bool mDisabled; bool mSingleModule; bool mAlwaysIncludeAll; @@ -1387,11 +1386,11 @@ public: int mIdx; String mStartupObject; - Array mPreprocessorMacros; + Array mPreprocessorMacros; Dictionary mNamespaces; - + HashSet mUsedModules; - HashSet mReferencedTypeData; + HashSet mReferencedTypeData; Val128 mBuildConfigHash; Val128 mVDataConfigHash; @@ -1403,7 +1402,7 @@ public: ~BfProject(); bool ContainsReference(BfProject* refProject); - bool ReferencesOrReferencedBy(BfProject* refProject); + bool ReferencesOrReferencedBy(BfProject* refProject); bool IsTestProject(); }; @@ -1415,7 +1414,7 @@ enum BfWarning BfWarning_CS0162_UnreachableCode = 162, BfWarning_CS0168_VariableDeclaredButNeverUsed = 168, BfWarning_CS0472_ValueTypeNullCompare = 472, - BfWarning_CS1030_PragmaWarning = 1030, + BfWarning_CS1030_PragmaWarning = 1030, BfWarning_BF4201_Only7Hex = 4201, BfWarning_BF4202_TooManyHexForInt = 4202, BfWarning_BF4203_UnnecessaryDynamicCast = 4203, @@ -1438,9 +1437,9 @@ class BfErrorBase public: bool mIsWarning; bool mIsDeferred; - BfSourceData* mSource; + BfSourceData* mSource; int mSrcStart; - int mSrcEnd; + int mSrcEnd; BfErrorLocation* mLocation; public: @@ -1448,7 +1447,7 @@ public: { mIsWarning = false; mIsDeferred = false; - mSource = NULL; + mSource = NULL; mSrcStart = -1; mSrcEnd = -1; mLocation = NULL; @@ -1466,11 +1465,11 @@ public: class BfError : public BfErrorBase { -public: - bool mIsAfter; +public: + bool mIsAfter; bool mIsPersistent; BfWhileSpecializingFlags mIsWhileSpecializing; - bool mIgnore; + bool mIgnore; BfProject* mProject; String mError; int mWarningNumber; @@ -1479,10 +1478,10 @@ public: public: BfError() { - mIsAfter = false; + mIsAfter = false; mIsPersistent = false; mIsWhileSpecializing = BfWhileSpecializingFlag_None; - mIgnore = false; + mIgnore = false; mProject = NULL; mWarningNumber = 0; } @@ -1540,16 +1539,16 @@ public: BfSystem* mSystem; BfCompiler* mCompiler; bool mTrimMessagesToCursor; - int mFailedIdx; + int mFailedIdx; int mWarnIdx; - + Dictionary mSourceFileNameMap; HashSet mErrorSet; Array mErrors; int mIgnoreCount; - int mWarningCount; + int mWarningCount; int mDeferredErrorCount; - Deque mOutStream; + Deque mOutStream; bool mLastWasDisplayed; bool mLastWasAdded; uint8 mClassifierPassId; @@ -1567,9 +1566,9 @@ public: mLastWasDisplayed = false; mLastWasAdded = false; mClassifierPassId = 0; - mWarningCount = 0; + mWarningCount = 0; mDeferredErrorCount = 0; - mIgnoreCount = 0; + mIgnoreCount = 0; mHadSignatureChanges = false; } @@ -1594,7 +1593,7 @@ public: BfError* Warn(int warningNumber, const StringImpl& warning, BfAstNode* refNode, bool isDeferred = false); BfError* DeferWarn(int warningNumber, const StringImpl& warning, BfAstNode* refNode); BfError* WarnAfter(int warningNumber, const StringImpl& warning, BfAstNode* refNode); - BfError* WarnAfterAt(int warningNumber, const StringImpl& error, BfSourceData* bfSource, int srcIdx); + BfError* WarnAfterAt(int warningNumber, const StringImpl& error, BfSourceData* bfSource, int srcIdx); BfMoreInfo* MoreInfoAt(const StringImpl& info, BfSourceData* bfSource, int srcIdx, int srcLen, BfFailFlags flags = BfFailFlag_None); BfMoreInfo* MoreInfo(const StringImpl& info, bool forceQueue = false); @@ -1608,7 +1607,7 @@ public: BfError* FailAfter(const StringImpl& error, BfAstNode* refNode); BfError* DeferFail(const StringImpl& error, BfAstNode* refNode); void SilentFail(); - + void TryFlushDeferredError(); void WriteErrorSummary(); }; @@ -1635,7 +1634,6 @@ enum BfOptionFlags BfOptionFlags_Reflect_MethodMask = BfOptionFlags_ReflectStaticMethods | BfOptionFlags_ReflectNonStaticMethods | BfOptionFlags_ReflectConstructors, BfOptionFlags_Mask = 0x3FFF - }; enum BfFieldFlags @@ -1661,7 +1659,7 @@ enum BfReflectKind BfReflectKind_DefaultConstructor = 8, BfReflectKind_Constructors = 0x10, BfReflectKind_StaticMethods = 0x20, - BfReflectKind_Methods = 0x40, + BfReflectKind_Methods = 0x40, BfReflectKind_DynamicBoxing = 0x80, BfReflectKind_User = 0x100, BfReflectKind_All = 0x1FF, @@ -1682,15 +1680,15 @@ public: public: Array mTypeFilters; Array mAttributeFilters; - Array mMatchedIndices; + Array mMatchedIndices; int mSIMDSetting; int mOptimizationLevel; - int mEmitDebugInfo; + int mEmitDebugInfo; BfOptionFlags mAndFlags; BfOptionFlags mOrFlags; Array mReflectMethodFilters; Array mReflectMethodAttributeFilters; - int mAllocStackTraceDepth; + int mAllocStackTraceDepth; public: static int Apply(int val, int applyVal) @@ -1698,7 +1696,7 @@ public: if (applyVal != -1) return applyVal; return val; - } + } bool Apply(bool val, BfOptionFlags flags) { @@ -1722,10 +1720,10 @@ enum BfFindTypeDefFlags class BfSystem { -public: - int mPtrSize; +public: + int mPtrSize; bool mIsResolveOnly; - + CritSect mDataLock; // short-lived, hold only while active modifying data // The following are protected by mDataLock: HashSet mUsedSafeProjectNames; @@ -1753,11 +1751,11 @@ public: uint32 mYieldTickCount; int mHighestYieldTime; // The following are protected by mSystemLock - can only be accessed by the compiling thread - Dictionary mSystemTypeDefs; - BfTypeDefMap mTypeDefs; + Dictionary mSystemTypeDefs; + BfTypeDefMap mTypeDefs; bool mNeedsTypesHandledByCompiler; - BumpAllocator mAlloc; - int mAtomCreateIdx; + BumpAllocator mAlloc; + int mAtomCreateIdx; Dictionary mAtomMap; Array mAtomGraveyard; uint32 mAtomUpdateIdx; @@ -1792,7 +1790,7 @@ public: BfTypeDef* mTypeChar16; BfTypeDef* mTypeChar32; BfTypeDef* mTypeSingle; - BfTypeDef* mTypeDouble; + BfTypeDef* mTypeDouble; BfDirectStrTypeReference* mDirectVoidTypeRef; BfDirectStrTypeReference* mDirectBoolTypeRef; @@ -1808,58 +1806,57 @@ public: public: BfSystem(); ~BfSystem(); - + BfAtom* GetAtom(const StringImpl& string); BfAtom* FindAtom(const StringImpl& string); // Doesn't create a ref BfAtom* FindAtom(const StringView& string); // Doesn't create a ref - void ReleaseAtom(BfAtom* atom); + void ReleaseAtom(BfAtom* atom); void ProcessAtomGraveyard(); void RefAtomComposite(const BfAtomComposite& atomComposite); - void ReleaseAtomComposite(const BfAtomComposite& atomComposite); + void ReleaseAtomComposite(const BfAtomComposite& atomComposite); void SanityCheckAtomComposite(const BfAtomComposite& atomComposite); void TrackName(BfTypeDef* typeDef); - void UntrackName(BfTypeDef* typeDef); + void UntrackName(BfTypeDef* typeDef); bool ParseAtomComposite(const StringView& name, BfAtomComposite& composite, bool addRefs = false); - void CreateBasicTypes(); + void CreateBasicTypes(); bool DoesLiteralFit(BfTypeCode typeCode, int64 value); bool DoesLiteralFit(BfTypeCode typeCode, uint64 value); bool DoesLiteralFit(BfTypeCode typeCode, const BfVariant& variant); - BfParser* CreateParser(BfProject* bfProject); - BfCompiler* CreateCompiler(bool isResolveOnly); + BfParser* CreateParser(BfProject* bfProject); + BfCompiler* CreateCompiler(bool isResolveOnly); BfProject* GetProject(const StringImpl& projName); - BfTypeReference* GetTypeRefElement(BfTypeReference* typeRef); + BfTypeReference* GetTypeRefElement(BfTypeReference* typeRef); BfTypeDef* FilterDeletedTypeDef(BfTypeDef* typeDef); - bool CheckTypeDefReference(BfTypeDef* typeDef, BfProject* project); + bool CheckTypeDefReference(BfTypeDef* typeDef, BfProject* project); BfTypeDef* FindTypeDef(const BfAtomComposite& findName, int numGenericArgs = 0, BfProject* project = NULL, const Array& namespaceSearch = Array(), BfTypeDef** ambiguousTypeDef = NULL, BfFindTypeDefFlags flags = BfFindTypeDefFlag_None); bool FindTypeDef(const BfAtomComposite& findName, int numGenericArgs, BfProject* project, const BfAtomComposite& checkNamespace, bool allowPrivate, BfTypeDefLookupContext* ctx); BfTypeDef* FindTypeDef(const StringImpl& typeName, int numGenericArgs = 0, BfProject* project = NULL, const Array& namespaceSearch = Array(), BfTypeDef** ambiguousTypeDef = NULL, BfFindTypeDefFlags flags = BfFindTypeDefFlag_None); BfTypeDef* FindTypeDef(const StringImpl& typeName, BfProject* project); BfTypeDef* FindTypeDefEx(const StringImpl& typeName); void ClearTypeDefCache(); - void FindFixitNamespaces(const StringImpl& typeName, int numGenericArgs, BfProject* project, std::set& fixitNamespaces); + void FindFixitNamespaces(const StringImpl& typeName, int numGenericArgs, BfProject* project, std::set& fixitNamespaces); void RemoveTypeDef(BfTypeDef* typeDef); //BfTypeDefMap::Iterator RemoveTypeDef(BfTypeDefMap::Iterator typeDefItr); void AddNamespaceUsage(const BfAtomComposite& namespaceStr, BfProject* bfProject); void RemoveNamespaceUsage(const BfAtomComposite& namespaceStr, BfProject* bfProject); - bool ContainsNamespace(const BfAtomComposite& namespaceStr, BfProject* bfProject); + bool ContainsNamespace(const BfAtomComposite& namespaceStr, BfProject* bfProject); void InjectNewRevision(BfTypeDef* typeDef); void AddToCompositePartial(BfPassInstance* passInstance, BfTypeDef* compositeTypeDef, BfTypeDef* partialTypeDef); - void FinishCompositePartial(BfTypeDef* compositeTypeDef); + void FinishCompositePartial(BfTypeDef* compositeTypeDef); void CopyTypeDef(BfTypeDef* typeDef, BfTypeDef* nextTypeDef); void UpdateEmittedTypeDef(BfTypeDef* typeDef); BfTypeDef* GetCombinedPartial(BfTypeDef* typeDef); BfTypeDef* GetOuterTypeNonPartial(BfTypeDef* typeDef); - int GetGenericParamIdx(const Array& genericParams, const StringImpl& name); int GetGenericParamIdx(const Array& genericParams, BfTypeReference* typeRef); - void StartYieldSection(); + void StartYieldSection(); void CheckLockYield(); // Yields to a higher priority request void SummarizeYieldSection(); @@ -1888,7 +1885,7 @@ public: public: AutoDisallowYield(BfSystem* system) - { + { mSystem = system; mSystem->mYieldDisallowCount++; mHeld = true; @@ -1921,7 +1918,6 @@ public: } }; - #ifdef _DEBUG #ifdef BF_PLATFORM_WINDOWS @@ -1959,7 +1955,6 @@ public: #define BfLogX(logIdx, fmt, ...) {} // Nothing #endif - #ifdef BF_WANTS_LOG_SYS #define BfLogSys(sys, fmt, ...) DoBfLog((sys)->mIsResolveOnly ? 1 : 2, fmt, ##__VA_ARGS__) #define BfLogSysM(fmt, ...) DoBfLog(mSystem->mIsResolveOnly ? 1 : 2, fmt, ##__VA_ARGS__) @@ -2035,7 +2030,6 @@ namespace std }; } - namespace std { template<> diff --git a/IDEHelper/Compiler/BfTargetTriple.cpp b/IDEHelper/Compiler/BfTargetTriple.cpp index 37fb863d..d1bb152c 100644 --- a/IDEHelper/Compiler/BfTargetTriple.cpp +++ b/IDEHelper/Compiler/BfTargetTriple.cpp @@ -39,4 +39,4 @@ BfMachineType BfTargetTriple::GetMachineType() if (!mParsed) Parse(); return mMachineType; -} +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfType.h b/IDEHelper/Compiler/BfType.h index bfafa7c8..2f2c44b7 100644 --- a/IDEHelper/Compiler/BfType.h +++ b/IDEHelper/Compiler/BfType.h @@ -3,5 +3,4 @@ NS_BF_BEGIN - NS_BF_END \ No newline at end of file diff --git a/IDEHelper/Compiler/BfUtil.cpp b/IDEHelper/Compiler/BfUtil.cpp index dee396a3..cb015a79 100644 --- a/IDEHelper/Compiler/BfUtil.cpp +++ b/IDEHelper/Compiler/BfUtil.cpp @@ -60,7 +60,7 @@ String Beefy::EncodeFileName(const StringImpl& fromStr) path.Insert(0, fromStr.mPtr, 80); else path += fromStr; - + path.Replace("$", "\\"); for (auto& c : path) { @@ -178,7 +178,7 @@ bool Beefy::BfCheckWildcard(const StringImpl& wildcard, const StringImpl& checkS break; } - prevFilterC = filterC; + prevFilterC = filterC; } return matched; diff --git a/IDEHelper/Compiler/BfUtil.h b/IDEHelper/Compiler/BfUtil.h index 07c60fdf..39456e08 100644 --- a/IDEHelper/Compiler/BfUtil.h +++ b/IDEHelper/Compiler/BfUtil.h @@ -41,7 +41,7 @@ public: public: SetAndRestoreValue() { - mVarPtr = NULL; + mVarPtr = NULL; } SetAndRestoreValue(T& varRef) @@ -54,14 +54,14 @@ public: SetAndRestoreValue(T& varRef, T newVal) { mPrevVal = varRef; - mVarPtr = &varRef; + mVarPtr = &varRef; varRef = newVal; mNewVal = newVal; } SetAndRestoreValue(T& varRef, T newVal, bool doSet) { - mPrevVal = varRef; + mPrevVal = varRef; mVarPtr = &varRef; if (doSet) varRef = newVal; @@ -183,14 +183,14 @@ public: mVals.pop_back(); return val; } - + if (mZeroAlloc) { void* addr = malloc(sizeof(T)); memset(addr, 0, sizeof(T)); val = new(addr) T(); } - else + else val = new T(); if (mOwnsAll) mVals.push_back(val); @@ -226,15 +226,15 @@ inline void EncodeSLEB128(uint8*& buf, int value) bool hasMore; do { - uint8 curByte = (uint8)(value & 0x7f); + uint8 curByte = (uint8)(value & 0x7f); value >>= 7; hasMore = !((((value == 0) && ((curByte & 0x40) == 0)) || ((value == -1) && ((curByte & 0x40) != 0)))); if (hasMore) curByte |= 0x80; - *(buf++) = curByte; + *(buf++) = curByte; } - while (hasMore); + while (hasMore); } inline void EncodeSLEB128(uint8*& buf, int64_t value) @@ -242,15 +242,15 @@ inline void EncodeSLEB128(uint8*& buf, int64_t value) bool hasMore; do { - uint8 curByte = (uint8)(value & 0x7f); + uint8 curByte = (uint8)(value & 0x7f); value >>= 7; hasMore = !((((value == 0) && ((curByte & 0x40) == 0)) || ((value == -1) && ((curByte & 0x40) != 0)))); if (hasMore) curByte |= 0x80; - *(buf++) = curByte; + *(buf++) = curByte; } - while (hasMore); + while (hasMore); } #pragma warning(push) @@ -258,7 +258,7 @@ inline void EncodeSLEB128(uint8*& buf, int64_t value) /// Utility function to decode a SLEB128 value. inline int64_t DecodeSLEB128(const uint8*& p) -{ +{ int value = 0; int shift = 0; int curByte; @@ -267,7 +267,6 @@ inline int64_t DecodeSLEB128(const uint8*& p) curByte = (uint8_t)*p++; value |= ((curByte & 0x7f) << shift); shift += 7; - } while (curByte >= 128); // Sign extend negative numbers. if (((curByte & 0x40) != 0) && (shift < 64)) diff --git a/IDEHelper/Compiler/BfVarDeclChecker.cpp b/IDEHelper/Compiler/BfVarDeclChecker.cpp index 5c0702f3..a0884d0d 100644 --- a/IDEHelper/Compiler/BfVarDeclChecker.cpp +++ b/IDEHelper/Compiler/BfVarDeclChecker.cpp @@ -10,4 +10,4 @@ BfVarDeclChecker::BfVarDeclChecker() void BfVarDeclChecker::Visit(BfVariableDeclaration * binOpExpr) { mHasVarDecl = true; -} +} \ No newline at end of file diff --git a/IDEHelper/Compiler/BfVarDeclChecker.h b/IDEHelper/Compiler/BfVarDeclChecker.h index 4b9632e8..80af731b 100644 --- a/IDEHelper/Compiler/BfVarDeclChecker.h +++ b/IDEHelper/Compiler/BfVarDeclChecker.h @@ -17,5 +17,4 @@ public: virtual void Visit(BfVariableDeclaration* binOpExpr) override; }; - NS_BF_END \ No newline at end of file diff --git a/IDEHelper/Compiler/CeDebugger.cpp b/IDEHelper/Compiler/CeDebugger.cpp index 20070722..dd402f46 100644 --- a/IDEHelper/Compiler/CeDebugger.cpp +++ b/IDEHelper/Compiler/CeDebugger.cpp @@ -60,7 +60,6 @@ CePendingExpr::~CePendingExpr() ////////////////////////////////////////////////////////////////////////// - CeEvaluationContext::CeEvaluationContext(CeDebugger* winDebugger, const StringImpl& expr, CeFormatInfo* formatInfo, BfTypedValue contextValue) { Init(winDebugger, expr, formatInfo, contextValue); @@ -69,16 +68,16 @@ CeEvaluationContext::CeEvaluationContext(CeDebugger* winDebugger, const StringIm void CeEvaluationContext::Init(CeDebugger* ceDebugger, const StringImpl& expr, CeFormatInfo* formatInfo, BfTypedValue contextValue) { mDebugger = ceDebugger; - + mCallStackIdx = 0; mParser = NULL; mReducer = NULL; mPassInstance = NULL; mExprEvaluator = NULL; mExprNode = NULL; - + if (expr.empty()) - return; + return; int atPos = (int)expr.IndexOf('@'); if ((atPos != -1) && (atPos < expr.mLength - 2) && (expr[atPos + 1] == '0') && (expr[atPos + 2] == 'x')) @@ -135,7 +134,7 @@ void CeEvaluationContext::Init(CeDebugger* ceDebugger, const StringImpl& expr, C } } - mParser = new BfParser(ceDebugger->mCompiler->mSystem); + mParser = new BfParser(ceDebugger->mCompiler->mSystem); mPassInstance = new BfPassInstance(ceDebugger->mCompiler->mSystem); auto terminatedExpr = expr + ";"; mParser->SetSource(terminatedExpr.c_str(), (int)terminatedExpr.length()); @@ -197,7 +196,7 @@ BfTypedValue CeEvaluationContext::EvaluateInContext(BfTypedValue contextTypedVal auto ceFrame = mDebugger->GetFrame(mCallStackIdx); auto module = mDebugger->mCeMachine->mCeModule; - + SetAndRestoreValue prevTypeInstance(module->mCurTypeInstance, ceFrame->mFunction->mMethodInstance->GetOwner()); SetAndRestoreValue prevMethodInstance(module->mCurMethodInstance, ceFrame->mFunction->mMethodInstance); SetAndRestoreValue prevPassInstance(mDebugger->mCompiler->mPassInstance, mPassInstance); @@ -260,7 +259,7 @@ CeDebugger::CeDebugger(DebugManager* debugManager, BfCompiler* bfCompiler) mDebugPendingExpr = NULL; mCurDbgState = NULL; mBreakpointVersion = 0; - mBreakpointCacheDirty = false; + mBreakpointCacheDirty = false; mBreakpointFramesDirty = false; mCurDisasmFuncId = 0; mActiveBreakpoint = NULL; @@ -285,7 +284,7 @@ String CeDebugger::TypeToString(BfType* type, CeTypeModKind typeModKind) if (typeModKind == CeTypeModKind_ReadOnly) str += "readonly "; else if (typeModKind == CeTypeModKind_Const) - str += "const "; + str += "const "; str += mCeMachine->mCeModule->TypeToString(type); return str; } @@ -363,10 +362,10 @@ String CeDebugger::GetDbgAllocInfo() void CeDebugger::Update() { AutoCrit autoCrit(mCeMachine->mCritSect); - + if ((mRunState == RunState_Terminated) || (mRunState == RunState_Terminating)) return; - + if (mDebugPendingExpr != NULL) { if (mDebugPendingExpr->mDone) @@ -374,10 +373,10 @@ void CeDebugger::Update() else mRunState = RunState_DebugEval; } - else if (mCeMachine->mDbgPaused) - mRunState = RunState_Paused; - else - mRunState = RunState_Running; + else if (mCeMachine->mDbgPaused) + mRunState = RunState_Paused; + else + mRunState = RunState_Running; } void CeDebugger::UpdateBreakpointFrames() @@ -392,7 +391,7 @@ void CeDebugger::UpdateBreakpointFrames() } void CeDebugger::ContinueDebugEvent() -{ +{ AutoCrit autoCrit(mCeMachine->mCritSect); mRunState = RunState_Running; @@ -435,9 +434,9 @@ bool CeDebugger::CheckConditionalBreakpoint(CeBreakpoint* breakpoint) { StringT<256> expr; StringT<256> subjectExpr; - _SplitExpr(conditional->mExpr, expr, subjectExpr); + _SplitExpr(conditional->mExpr, expr, subjectExpr); - conditional->mDbgEvaluationContext = new CeEvaluationContext(this, expr); + conditional->mDbgEvaluationContext = new CeEvaluationContext(this, expr); conditional->mDbgEvaluationContext->mCallStackIdx = -1; } @@ -451,7 +450,6 @@ bool CeDebugger::CheckConditionalBreakpoint(CeBreakpoint* breakpoint) { if (!error->mIsWarning) errorStr = error->mError; - } String condError = StrFormat("error Conditional breakpoint expression '%s' failed: %s", conditional->mExpr.c_str(), errorStr.c_str()); mDebugManager->mOutMessages.push_back(condError); @@ -487,7 +485,7 @@ bool CeDebugger::CheckConditionalBreakpoint(CeBreakpoint* breakpoint) return false; break; } - + if (!breakpoint->mLogging.IsEmpty()) { auto ceContext = mCeMachine->mCurContext; @@ -501,14 +499,14 @@ bool CeDebugger::CheckConditionalBreakpoint(CeBreakpoint* breakpoint) CeFormatInfo formatInfo; formatInfo.mCallStackIdx = -1; - + auto prevRunState = mRunState; mRunState = RunState_Paused; // We need to be paused to avoid certain errors in the eval String displayString; String expr; _SplitExpr(breakpoint->mLogging, expr, formatInfo.mSubjectExpr); - + ProcessEvalString(BfTypedValue(), expr, displayString, formatInfo, NULL, false); mRunState = prevRunState; @@ -520,7 +518,7 @@ bool CeDebugger::CheckConditionalBreakpoint(CeBreakpoint* breakpoint) if (!breakpoint->mBreakAfterLogging) return false; } - + return true; } @@ -533,7 +531,7 @@ Breakpoint* CeDebugger::CreateBreakpoint(const StringImpl& fileName, int lineNum breakpoint->mRequestedLineNum = lineNum; breakpoint->mLineNum = lineNum; breakpoint->mColumn = wantColumn; - breakpoint->mInstrOffset = instrOffset; + breakpoint->mInstrOffset = instrOffset; mBreakpoints.Add(breakpoint); mBreakpointVersion++; @@ -572,7 +570,6 @@ void CeDebugger::CheckBreakpoint(Breakpoint* breakpoint) void CeDebugger::HotBindBreakpoint(Breakpoint* breakpoint, int lineNum, int hotIdx) { - } int64 CeDebugger::ValueToInt(addr_ce addr, BfType* type) @@ -602,7 +599,7 @@ int64 CeDebugger::ValueToInt(addr_ce addr, BfType* type) } int64 CeDebugger::ValueToInt(const BfTypedValue& typedVal) -{ +{ auto ceModule = mCeMachine->mCeModule; auto constant = ceModule->mBfIRBuilder->GetConstant(typedVal.mValue); @@ -610,13 +607,13 @@ int64 CeDebugger::ValueToInt(const BfTypedValue& typedVal) return 0; if (typedVal.IsAddr()) - { + { BfType* type = typedVal.mType; if (type->IsTypedPrimitive()) type = type->GetUnderlyingType(); if ((type->IsInteger()) || (type->IsBoolean())) - { + { auto ceTypedVal = GetAddr(constant); if (ceTypedVal) return ValueToInt((addr_ce)ceTypedVal.mAddr, type); @@ -630,9 +627,9 @@ int64 CeDebugger::ValueToInt(const BfTypedValue& typedVal) auto fromConstGEP = (BfConstantExtractValue*)constant; auto fromTarget = ceModule->mBfIRBuilder->GetConstantById(fromConstGEP->mTarget); if (fromTarget->mConstType == BfConstType_AggCE) - { + { auto aggCE = (BfConstantAggCE*)fromTarget; - + auto dbgTypeInfo = GetDbgTypeInfo(aggCE->mType); if (dbgTypeInfo == NULL) return 0; @@ -678,7 +675,7 @@ void CeDebugger::MoveMemoryBreakpoint(Breakpoint* breakpoint, intptr addr, int b } void CeDebugger::DisableBreakpoint(Breakpoint* breakpoint) -{ +{ } void CeDebugger::SetBreakpointCondition(Breakpoint* breakpoint, const StringImpl& conditionExpr) @@ -727,7 +724,6 @@ void CeDebugger::BreakAll() { mCeMachine->mSpecialCheck = true; mCeMachine->mDbgWantBreak = true; - } bool CeDebugger::TryRunContinue() @@ -752,7 +748,7 @@ bool CeDebugger::SetupStep(int frameIdx) return false; } - auto ceMachine = mCeMachine; + auto ceMachine = mCeMachine; auto ceContext = mCeMachine->mCurContext; if (entryIdx < ceFrame->mFunction->mEmitTable.mSize - 1) @@ -768,7 +764,7 @@ bool CeDebugger::SetupStep(int frameIdx) } } else - ceMachine->mStepState.mNextInstIdx = ceFrame->mFunction->mCode.mSize; + ceMachine->mStepState.mNextInstIdx = ceFrame->mFunction->mCode.mSize; ceMachine->mStepState.mStartDepth = ceContext->mCallStack.mSize - frameIdx; ceMachine->mSpecialCheck = true; @@ -808,7 +804,7 @@ void CeDebugger::SetNextStatement(bool inAssembly, const StringImpl& fileName, i return; if (inAssembly) - { + { int32 instIdx = (int32)lineNumOrAsmAddr; if (instIdx < ceFrame->mFunction->mCode.mSize) { @@ -838,7 +834,7 @@ void CeDebugger::SetNextStatement(bool inAssembly, const StringImpl& fileName, i } CeFrame* CeDebugger::GetFrame(int callStackIdx) -{ +{ auto ceContext = mCeMachine->mCurContext; if (ceContext == NULL) return NULL; @@ -938,7 +934,7 @@ String CeDebugger::DoEvaluate(CePendingExpr* pendingExpr, bool inCompilerThread) autoComplete.mModule = module; autoComplete.mCompiler = module->mCompiler; autoComplete.mSystem = module->mSystem; - + BfResolvePassData resolvePass; resolvePass.mParsers.Add(pendingExpr->mParser); resolvePass.mAutoComplete = &autoComplete; @@ -965,14 +961,14 @@ String CeDebugger::DoEvaluate(CePendingExpr* pendingExpr, bool inCompilerThread) { BfExprEvaluator exprEvaluator(mCeMachine->mCeModule); exprEvaluator.mBfEvalExprFlags = (BfEvalExprFlags)(exprEvaluator.mBfEvalExprFlags | BfEvalExprFlags_Comptime); - exprEvaluator.VisitChildNoRef(pendingExpr->mExprNode); - exprResult = exprEvaluator.GetResult(); + exprEvaluator.VisitChildNoRef(pendingExpr->mExprNode); + exprResult = exprEvaluator.GetResult(); origExprResult = exprResult; if ((exprResult) && (!exprResult.mType->IsComposite())) exprResult = module->LoadValue(exprResult); module->FixIntUnknown(exprResult); } - + if (dbgState.mBlockedSideEffects) { if ((mCeMachine->mDbgPaused) && ((pendingExpr->mExpressionFlags & DwEvalExpressionFlag_AllowCalls) != 0)) @@ -983,7 +979,7 @@ String CeDebugger::DoEvaluate(CePendingExpr* pendingExpr, bool inCompilerThread) return "!sideeffects"; } - + if (!exprResult) { auto resultType = mCeMachine->mCeModule->ResolveTypeRef(pendingExpr->mExprNode, {}, BfPopulateType_Data, BfResolveTypeRefFlag_IgnoreLookupError); @@ -1077,7 +1073,7 @@ String CeDebugger::DoEvaluate(CePendingExpr* pendingExpr, bool inCompilerThread) // val += "\n:canEdit"; // } - if ((origExprResult.mType != NULL) && (!origExprResult.mType->IsComposite()) && (!origExprResult.mType->IsRef()) && + if ((origExprResult.mType != NULL) && (!origExprResult.mType->IsComposite()) && (!origExprResult.mType->IsRef()) && (origExprResult.IsAddr()) && (!origExprResult.IsReadOnly())) { val += "\n:canEdit"; @@ -1085,7 +1081,7 @@ String CeDebugger::DoEvaluate(CePendingExpr* pendingExpr, bool inCompilerThread) if (pendingExpr->mCursorPos != -1) val += GetAutocompleteOutput(autoComplete); - + return val; } @@ -1103,7 +1099,7 @@ String CeDebugger::Evaluate(const StringImpl& expr, CeFormatInfo formatInfo, int auto ceContext = mCeMachine->mCurContext; bool valIsAddr = false; - BfParser* parser = new BfParser(mCompiler->mSystem); + BfParser* parser = new BfParser(mCompiler->mSystem); BfPassInstance* bfPassInstance = new BfPassInstance(mCompiler->mSystem); @@ -1140,14 +1136,14 @@ String CeDebugger::Evaluate(const StringImpl& expr, CeFormatInfo formatInfo, int } parser->SetSource(terminatedExpr.c_str(), (int)terminatedExpr.length()); - parser->Parse(bfPassInstance); + parser->Parse(bfPassInstance); BfReducer bfReducer; bfReducer.mAlloc = parser->mAlloc; bfReducer.mSystem = mCompiler->mSystem; bfReducer.mPassInstance = bfPassInstance; bfReducer.mVisitorPos = BfReducer::BfVisitorPos(parser->mRootNode); - bfReducer.mVisitorPos.MoveNext(); + bfReducer.mVisitorPos.MoveNext(); bfReducer.mSource = parser; BfAstNode* exprNode = NULL; if (parseAsType) @@ -1157,8 +1153,8 @@ String CeDebugger::Evaluate(const StringImpl& expr, CeFormatInfo formatInfo, int parser->Close(); formatInfo.mCallStackIdx = callStackIdx; - - CePendingExpr* pendingExpr = new CePendingExpr(); + + CePendingExpr* pendingExpr = new CePendingExpr(); pendingExpr->mPassInstance = bfPassInstance; pendingExpr->mParser = parser; pendingExpr->mCallStackIdx = callStackIdx; @@ -1231,7 +1227,7 @@ String CeDebugger::Evaluate(const StringImpl& expr, CeFormatInfo formatInfo, int pendingExpr->mExplitType = explicitType; pendingExpr->mFormatInfo = formatInfo; - + String result = DoEvaluate(pendingExpr, false); if (result == "!pending") { @@ -1252,7 +1248,7 @@ String CeDebugger::Evaluate(const StringImpl& expr, CeFormatInfo formatInfo, int void CeDebugger::ClearBreakpointCache() { - if (!mCeMachine->mDbgPaused) + if (!mCeMachine->mDbgPaused) mCeMachine->mSpecialCheck = true; mBreakpointFramesDirty = true; mBreakpointCacheDirty = true; @@ -1267,7 +1263,7 @@ void CeDebugger::UpdateBreakpointAddrs() { breakpoint->mCurBindAddr = 1; } - + CeFunction* ceFunction = NULL; if (!mCeMachine->mFunctionIdMap.TryGetValue(mCurDisasmFuncId, &ceFunction)) return; @@ -1285,7 +1281,7 @@ void CeDebugger::UpdateBreakpointCache() mBreakpointCacheDirty = false; if (!mFileInfo.IsEmpty()) - return; + return; for (int i = 0; i < (int)mBreakpoints.mSize; i++) { auto breakpoint = mBreakpoints[i]; @@ -1324,7 +1320,7 @@ void CeDebugger::UpdateBreakpoints(CeFunction* ceFunction) UpdateBreakpointCache(); - ceFunction->UnbindBreakpoints(); + ceFunction->UnbindBreakpoints(); String path; int scope = -1; @@ -1365,7 +1361,7 @@ void CeDebugger::UpdateBreakpoints(CeFunction* ceFunction) int bestRequestedBindLine = 0; while ((idx >= 0) && (idx < ceFileInfo->mOrderedBreakpoints.mSize)) - { + { auto breakpoint = ceFileInfo->mOrderedBreakpoints[idx]; if (usedBreakpointSet.IsSet(breakpoint->mIdx)) { @@ -1384,10 +1380,10 @@ void CeDebugger::UpdateBreakpoints(CeFunction* ceFunction) int lineDiff = emitEntry.mLine - breakpoint->mLineNum; if ((lineDiff < 0) || (lineDiff > 4)) break; - + if ((breakpoint->mHasBound) && (lineDiff != 0)) break; - + bestRequestedBindLine = breakpoint->mRequestedLineNum; } @@ -1437,11 +1433,11 @@ CeDbgTypeInfo* CeDebugger::GetDbgTypeInfo(int typeId) mDbgTypeInfoMap.Remove(typeId); return NULL; } - dbgTypeInfo->mType = type; + dbgTypeInfo->mType = type; auto typeInst = type->ToTypeInstance(); if (typeInst != NULL) - { + { for (int fieldIdx = 0; fieldIdx < typeInst->mFieldInstances.mSize; fieldIdx++) { auto& fieldInst = typeInst->mFieldInstances[fieldIdx]; @@ -1466,7 +1462,6 @@ CeDbgTypeInfo* CeDebugger::GetDbgTypeInfo(int typeId) } } } - } return dbgTypeInfo; } @@ -1514,7 +1509,6 @@ static String IntTypeToString(T val, const StringImpl& name, DwDisplayInfo* disp binary = "'" + binary; binary = ((val & ((T)1 << i)) ? "1" : "0") + binary; - } return StrFormat("0b'%s\n%s", binary.c_str(), name.c_str()); } @@ -1597,7 +1591,7 @@ String CeDebugger::GetMemberList(BfType* type, addr_ce addr, addr_ce addrInst, b auto typeInst = type->ToTypeInstance(); if (typeInst == NULL) return ""; - + auto module = typeInst->mModule; String retVal; @@ -1608,7 +1602,7 @@ String CeDebugger::GetMemberList(BfType* type, addr_ce addr, addr_ce addrInst, b retVal += StrFormat("[base]\tthis,this=%d@0x%X, nd, na, nv", typeInst->mBaseType->mTypeId, addr); fieldCount++; } - + auto ceContext = mCompiler->mCeMachine->mCurContext; bool didStaticCtor = ceContext->mStaticCtorExecSet.Contains(type->mTypeId); @@ -1618,7 +1612,7 @@ String CeDebugger::GetMemberList(BfType* type, addr_ce addr, addr_ce addrInst, b auto fieldDef = fieldInst.GetFieldDef(); if (fieldDef == NULL) continue; - + if (fieldDef->mIsStatic != isStatic) { if (fieldDef->mIsStatic) @@ -1640,7 +1634,7 @@ String CeDebugger::GetMemberList(BfType* type, addr_ce addr, addr_ce addrInst, b else { retVal += "\t"; - retVal += fieldDef->mName; + retVal += fieldDef->mName; retVal += StrFormat(",this=%d@0x%X", typeInst->mTypeId, addrInst); } @@ -1651,7 +1645,7 @@ String CeDebugger::GetMemberList(BfType* type, addr_ce addr, addr_ce addrInst, b { if (fieldCount > 0) retVal += "\n"; - + retVal += StrFormat("Static values\tcomptype(%d)", typeInst->mTypeId); } @@ -1926,8 +1920,8 @@ String CeDebugger::MaybeQuoteFormatInfoParam(const StringImpl& str) } BfTypedValue CeDebugger::EvaluateInContext(const BfTypedValue& contextTypedValue, const StringImpl& subExpr, CeFormatInfo* formatInfo, String* outReferenceId, String* outErrors) -{ - CeEvaluationContext dbgEvaluationContext(this, subExpr, formatInfo, contextTypedValue); +{ + CeEvaluationContext dbgEvaluationContext(this, subExpr, formatInfo, contextTypedValue); // if (formatInfo != NULL) // { // dbgEvaluationContext.mDbgExprEvaluator->mSubjectExpr = formatInfo->mSubjectExpr; @@ -2025,11 +2019,11 @@ String CeDebugger::GetArrayItems(DebugVisualizerEntry* debugVis, BfType* valueTy BfTypedValue condVal = conditionEvaluationContext.EvaluateInContext(curNode); if (!condVal) break; - + auto ceTypedVal = GetAddr(curNode); if (!ceTypedVal) break; - + if (ValueToInt(condVal) != 0) { auto val = curNode; @@ -2066,11 +2060,11 @@ String CeDebugger::GetLinkedListItems(DebugVisualizerEntry* debugVis, addr_ce en CeEvaluationContext nextEvaluationContext(this, debugVis->mNextPointer); CeEvaluationContext valueEvaluationContext(this, debugVis->mValuePointer); auto ceModule = mCeMachine->mCeModule; - + String addrs; bool checkLeft = true; - + int mapIdx; for (mapIdx = 0; mapIdx < count; mapIdx++) { @@ -2104,7 +2098,7 @@ String CeDebugger::GetLinkedListItems(DebugVisualizerEntry* debugVis, addr_ce en curNode = nextEvaluationContext.EvaluateInContext(curNode); } count = mapIdx; - + if (outContinuationData != NULL) { CeTypedValue ceNodeVal = GetAddr(curNode); @@ -2116,7 +2110,7 @@ String CeDebugger::GetLinkedListItems(DebugVisualizerEntry* debugVis, addr_ce en } String CeDebugger::GetDictionaryItems(DebugVisualizerEntry* debugVis, BfTypedValue dictValue, int bucketIdx, int nodeIdx, int& count, String* outContinuationData) -{ +{ CeEvaluationContext nextEvaluationContext(this, debugVis->mNextPointer); auto ceModule = mCeMachine->mCeModule; @@ -2127,7 +2121,7 @@ String CeDebugger::GetDictionaryItems(DebugVisualizerEntry* debugVis, BfTypedVal count = -1; return ""; } - + auto ceDictTypedVal = GetAddr(dictValue); if (!ceDictTypedVal) return ""; @@ -2157,10 +2151,10 @@ String CeDebugger::GetDictionaryItems(DebugVisualizerEntry* debugVis, BfTypedVal while (encodeCount < count) { if (nodeIdx != -1) - { + { addr_ce entryAddr = (addr_ce)ceElemTypedVal.mAddr + (nodeIdx * entrySize); - BfTypedValue entryValue = BfTypedValue(ceModule->mBfIRBuilder->CreateConstAggCE(ceModule->mBfIRBuilder->MapType(entryType), entryAddr), entryType); + BfTypedValue entryValue = BfTypedValue(ceModule->mBfIRBuilder->CreateConstAggCE(ceModule->mBfIRBuilder->MapType(entryType), entryAddr), entryType); addrs += EncodeDataPtr(entryAddr, false); BfTypedValue nextValue = nextEvaluationContext.EvaluateInContext(entryValue); @@ -2183,7 +2177,7 @@ String CeDebugger::GetDictionaryItems(DebugVisualizerEntry* debugVis, BfTypedVal } count = encodeCount; - + if (outContinuationData != NULL) { *outContinuationData += EncodeDataPtr(debugVis, false) + EncodeDataPtr(dictValue.mType, false) + EncodeDataPtr((addr_ce)ceDictTypedVal.mAddr, false) + @@ -2205,25 +2199,25 @@ String CeDebugger::GetTreeItems(DebugVisualizerEntry* debugVis, Array& //TODO: // bool checkLeft = true; -// +// // if ((curNode.mPtr & 2) != 0) // Flag from continuation // { // checkLeft = false; // curNode.mPtr &= (addr_ce)~2; // } -// +// // HashSet seenAddrs; -// +// // for (int mapIdx = 0; mapIdx < count; mapIdx++) // { // BfTypedValue readNode; // while (true) // { // bool checkNode = (curNode.mPtr & 1) == 0; -// +// // readNode = curNode; // readNode.mPtr &= (addr_ce)~1; -// +// // if (checkLeft) // { // BfTypedValue leftValue = leftEvaluationContext.EvaluateInContext(readNode); @@ -2239,7 +2233,7 @@ String CeDebugger::GetTreeItems(DebugVisualizerEntry* debugVis, Array& // checkLeft = false; // break; // Handle node // } -// +// // parentList.push_back(curNode.mPtr); // curNode = leftValue; // } @@ -2269,34 +2263,34 @@ String CeDebugger::GetTreeItems(DebugVisualizerEntry* debugVis, Array& // // Failed // break; // } -// +// // curNode.mPtr = parentList.back(); // parentList.pop_back(); // continue; // Don't check against seenAddrs // } // } -// +// // if (!seenAddrs.Add(curNode.mPtr)) // { // // Failed! // return ""; // } // } -// -// +// +// // BfTypedValue val = valueEvaluationContext.EvaluateInContext(readNode); // if (valueType == NULL) // valueType = val.mType; -// +// // String addr = EncodeDataPtr(val.mPtr, false); // addrs += addr; -// +// // curNode.mPtr |= 1; // Node handled // } -// +// // if (!checkLeft) // curNode.mPtr |= 2; -// +// // if (outContinuationData != NULL) // { // *outContinuationData += EncodeDataPtr(debugVis, false) + EncodeDataPtr(valueType, false) + EncodeDataPtr(curNode.mType, false) + EncodeDataPtr(curNode.mPtr, false); @@ -2308,7 +2302,7 @@ String CeDebugger::GetTreeItems(DebugVisualizerEntry* debugVis, Array& } String CeDebugger::GetCollectionContinuation(const StringImpl& continuationData, int callStackIdx, int count) -{ +{ if (!mCeMachine->mDbgPaused) return ""; @@ -2323,26 +2317,26 @@ String CeDebugger::GetCollectionContinuation(const StringImpl& continuationData, // BfTypedValue curNode; // curNode.mType = (DbgType*)DecodeLocalDataPtr(dataPtr); // curNode.mPtr = DecodeTargetDataPtr(dataPtr); -// +// // Array parentList; // String newContinuationData; // while (*dataPtr != 0) // parentList.push_back(DecodeTargetDataPtr(dataPtr)); -// +// // String retVal = GetTreeItems(dbgCompileUnit, debugVis, parentList, valueType, curNode, count, &newContinuationData); // retVal += "\n" + newContinuationData; // return retVal; } else if (debugVis->mCollectionType == DebugVisualizerEntry::CollectionType_LinkedList) - { + { addr_ce endNodePtr = DecodeTargetDataPtr(dataPtr); BfType* valueType = (BfType*)DecodeLocalDataPtr(dataPtr); BfType* nodeType = (BfType*)DecodeLocalDataPtr(dataPtr); - + BfTypedValue curNode = BfTypedValue( ceModule->mBfIRBuilder->CreateIntToPtr(DecodeTargetDataPtr(dataPtr), ceModule->mBfIRBuilder->MapType(nodeType)), nodeType); - + String newContinuationData; if (count < 0) @@ -2354,9 +2348,9 @@ String CeDebugger::GetCollectionContinuation(const StringImpl& continuationData, } else if (debugVis->mCollectionType == DebugVisualizerEntry::CollectionType_Array) { - BfType* valueType = (BfType*)DecodeLocalDataPtr(dataPtr); - - auto nodeType = (BfType*)DecodeLocalDataPtr(dataPtr); + BfType* valueType = (BfType*)DecodeLocalDataPtr(dataPtr); + + auto nodeType = (BfType*)DecodeLocalDataPtr(dataPtr); BfTypedValue curNode = BfTypedValue( ceModule->mBfIRBuilder->CreateIntToPtr(DecodeTargetDataPtr(dataPtr), ceModule->mBfIRBuilder->MapType(nodeType)), nodeType); @@ -2371,7 +2365,7 @@ String CeDebugger::GetCollectionContinuation(const StringImpl& continuationData, return retVal; } else if (debugVis->mCollectionType == DebugVisualizerEntry::CollectionType_Dictionary) - { + { auto dictValueType = (BfType*)DecodeLocalDataPtr(dataPtr); BfTypedValue dictValue = BfTypedValue( ceModule->mBfIRBuilder->CreateIntToPtr(DecodeTargetDataPtr(dataPtr), ceModule->mBfIRBuilder->MapType(dictValueType)), @@ -2399,9 +2393,9 @@ CeTypedValue CeDebugger::GetAddr(BfConstant* constant, BfType* type) auto globalVar = (BfGlobalVar*)constant; String varName(globalVar->mName); - + if (varName.StartsWith("__bfStrObj")) - { + { int stringId = atoi(varName.c_str() + 10); auto addr = ceContext->GetString(stringId); return CeTypedValue(addr, globalVar->mType); @@ -2431,17 +2425,17 @@ CeTypedValue CeDebugger::GetAddr(BfConstant* constant, BfType* type) return CeTypedValue(fieldInfo->mAddr, globalVar->mType); } else if (constant->mTypeCode == BfTypeCode_StringId) - { + { auto stringType = module->ResolveTypeDef(module->mCompiler->mStringTypeDef)->ToTypeInstance(); if ((type != NULL) && (type->IsPointer())) { BfType* charType = module->GetPrimitiveType(BfTypeCode_Char8); - BfType* charPtrType = module->CreatePointerType(charType); + BfType* charPtrType = module->CreatePointerType(charType); auto addr = ceContext->GetString(constant->mInt32) + stringType->mInstSize; return CeTypedValue(addr, module->mBfIRBuilder->MapType(charPtrType)); } else - { + { auto addr = ceContext->GetString(constant->mInt32); return CeTypedValue(addr, module->mBfIRBuilder->MapType(stringType)); } @@ -2476,15 +2470,15 @@ CeTypedValue CeDebugger::GetAddr(BfConstant* constant, BfType* type) if (!typedVal) return CeTypedValue(); - auto dbgTypeInfo = GetDbgTypeInfo(typedVal.mType); + auto dbgTypeInfo = GetDbgTypeInfo(typedVal.mType); if (dbgTypeInfo == NULL) return CeTypedValue(); auto addr = typedVal.mAddr; if (gepConst->mIdx0 != 0) - addr += gepConst->mIdx0 * dbgTypeInfo->mType->GetUnderlyingType()->GetStride(); - + addr += gepConst->mIdx0 * dbgTypeInfo->mType->GetUnderlyingType()->GetStride(); + return CeTypedValue(addr, module->mBfIRBuilder->MapType(dbgTypeInfo->mType)); } else if (constant->mConstType == BfConstType_GEP32_2) @@ -2498,7 +2492,7 @@ CeTypedValue CeDebugger::GetAddr(BfConstant* constant, BfType* type) auto dbgTypeInfo = GetDbgTypeInfo(typedVal.mType); - if ((dbgTypeInfo != NULL) && + if ((dbgTypeInfo != NULL) && ((dbgTypeInfo->mType->IsPointer()) || ((dbgTypeInfo->mType->IsRef())))) dbgTypeInfo = GetDbgTypeInfo(dbgTypeInfo->mType->GetUnderlyingType()->mTypeId); @@ -2522,7 +2516,7 @@ CeTypedValue CeDebugger::GetAddr(BfConstant* constant, BfType* type) ptrType = module->CreatePointerType(ptrType); } } - + if (ptrType == NULL) { if (gepConst->mIdx1 > dbgTypeInfo->mFieldOffsets.mSize) @@ -2572,7 +2566,7 @@ String CeDebugger::ReadString(BfTypeCode charType, intptr addr, intptr maxLength maxLength = BF_MIN(formatInfo.mMaxCount, maxLength); if (maxLength == -1) - maxLength = 8 * 1024 * 1024; // Is 8MB crazy? + maxLength = 8 * 1024 * 1024; // Is 8MB crazy? if (!formatInfo.mRawString) maxLength = BF_MIN(maxLength, maxShowSize); @@ -2840,15 +2834,15 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const { return "!Invalid expression"; } - + bool didAlloc = false; - addr_ce addr = 0; + addr_ce addr = 0; defer( { if (didAlloc) mCurDbgState->mCeContext->CeFree(addr); - } + } ); if (constant->mConstType == BfConstType_AggCE) @@ -2880,19 +2874,19 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const if (!mCurDbgState->mCeContext->WriteConstant(mCeMachine->mCeModule, addr, constant, typedValue.mType)) { return StrFormat("!Failed to encode value"); - } + } } DwDisplayInfo* displayInfo = GetDisplayInfo(formatInfo.mReferenceId); char str[32]; - String result; + String result; auto memStart = mCurDbgState->mCeContext->mMemory.mVals; int checkMemSize = typedValue.mType->mSize; if (typedValue.mType->IsPointer()) checkMemSize = typedValue.mType->GetUnderlyingType()->mSize; - + uint8* data = ceContext->GetMemoryPtr(addr, checkMemSize); if ((addr != 0) && (data == NULL)) { @@ -2902,9 +2896,9 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const return "!Invalid address"; } - addr_ce dataAddr = addr; + addr_ce dataAddr = addr; if ((typedValue.IsAddr()) && (typedValue.mType->IsObjectOrInterface())) - dataAddr = *(addr_ce*)data; + dataAddr = *(addr_ce*)data; if (formatInfo.mRawString) { @@ -2937,7 +2931,7 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const displayStrFormatInfo.mArrayLength = -1; // Why did we have this "na" on here? It made "void*[3]" type things show up as "{,,}" - //String evalStr = "((" + innerType->ToStringRaw(language) + "*)" + EncodeDataPtr(ptrVal, true) + StrFormat(")[%d], na", idx); + //String evalStr = "((" + innerType->ToStringRaw(language) + "*)" + EncodeDataPtr(ptrVal, true) + StrFormat(")[%d], na", idx); String evalStr = StrFormat("((comptype(%d))(void*)", ptrType->mTypeId) + EncodeDataPtr(ptrVal, true) + StrFormat(")[%lld]", idx); BfTypedValue evalResult = EvaluateInContext(typedValue, evalStr, &displayStrFormatInfo); @@ -2978,7 +2972,7 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const _ShowArraySummary(retVal, ptrVal, formatInfo.mArrayLength, elementType); - String idxStr = "[{0}]"; + String idxStr = "[{0}]"; retVal += "\n" + TypeToString(typedValue); @@ -3068,7 +3062,7 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const { // addr = *(addr_ce*)data; // dataAddr = addr; -// +// // data = ceContext->GetMemoryPtr(addr, checkMemSize); // if ((addr != 0) && (data == NULL)) // return "!Invalid address"; @@ -3132,7 +3126,6 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const retVal += ", refid=" + MaybeQuoteFormatInfoParam(formatInfo.mReferenceId); retVal += StrFormat(", this=%d@0x%X", innerType->mTypeId, ptrVal); - } retVal += "\n:canEdit\n:editVal\t" + EncodeDataPtr((uint32)addr, true); @@ -3144,7 +3137,7 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const if (typedValue.mType->IsPrimitiveType()) { auto primType = (BfPrimitiveType*)typedValue.mType; - + BfTypeCode typeCode = primType->mTypeDef->mTypeCode; if (typeCode == BfTypeCode_IntPtr) typeCode = (primType->mSize == 8) ? BfTypeCode_Int64 : BfTypeCode_Int32; @@ -3165,7 +3158,7 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const else return StrFormat("true (%d)\n%s", val, TypeToString(origTypedValue.mType, typeModKind).c_str()); } - break; + break; case BfTypeCode_Char8: { auto val = *(uint8*)(data); @@ -3183,7 +3176,7 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const result = "'\\0'\n"; return result + TypeToString(origTypedValue.mType, typeModKind); } - break; + break; case BfTypeCode_Char16: { auto val = *(uint16*)(data); @@ -3200,7 +3193,7 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const result = "'\\0'\n"; return result + TypeToString(origTypedValue.mType, typeModKind); } - break; + break; case BfTypeCode_Char32: { auto val = *(uint32*)(data); @@ -3248,7 +3241,7 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const else //if (floatDisplayType == DwFloatDisplayType_HexLower) sprintf(str, "0x%04x", *(uint32*)data); return StrFormat("%s\n%s", str, TypeToString(origTypedValue.mType, typeModKind).c_str()); - } + } case BfTypeCode_Double: { DwFloatDisplayType floatDisplayType = displayInfo->mFloatDisplayType; @@ -3266,7 +3259,7 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const } } } - + if (typedValue.mType->IsSizedArray()) { auto arrayType = (BfSizedArrayType*)typedValue.mType; @@ -3274,10 +3267,10 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const String retVal; addr_ce ptrVal = addr; - + intptr arraySize = arrayType->mElementCount; intptr innerSize = innerType->GetStride(); - + String idxStr = "[{0}]"; if (innerType->IsChar()) @@ -3301,7 +3294,7 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const String referenceId = TypeToString(typedValue.mType); String evalStr; - // Why did we have the "na"? Do we not want to show addresses for all members? + // Why did we have the "na"? Do we not want to show addresses for all members? auto ptrType = module->CreatePointerType(innerType); @@ -3312,14 +3305,14 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const "\t" + idxStr + "\t" + evalStr; return retVal; } - + if (typedValue.mType->IsEnum()) { if (formatInfo.mRawString) return ""; String retVal; - if (typedValue.mType->IsTypedPrimitive()) + if (typedValue.mType->IsTypedPrimitive()) { int64 bitsLeft = ValueToInt(typedValue); int valueCount = 0; @@ -3400,25 +3393,25 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const auto fieldDef = fieldInstance.GetFieldDef(); if (!fieldInstance.mIsEnumPayloadCase) continue; - + int tagId = -fieldInstance.mDataIdx - 1; if (dscrVal == tagId) { auto evalResult = BfTypedValue(module->mBfIRBuilder->CreateConstAggCE( module->mBfIRBuilder->MapType(fieldInstance.mResolvedType), (addr_ce)dataAddr), fieldInstance.mResolvedType, true); - + String innerResult = TypedValueToString(evalResult, "", formatInfo, NULL); int crPos = (int)innerResult.IndexOf('\n'); if (crPos != -1) innerResult.RemoveToEnd(crPos); retVal += "."; - retVal += fieldDef->mName; - retVal += innerResult; + retVal += fieldDef->mName; + retVal += innerResult; retVal += "\n" + TypeToString(origTypedValue.mType, typeModKind); retVal += "\n:canEdit"; - + retVal += "\n" + GetMemberList(fieldInstance.mResolvedType, addr, dataAddr, false); return retVal; } @@ -3461,14 +3454,14 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const if ((((origTypedValue.mType->IsObjectOrInterface()) || (origTypedValue.mType->IsPointer())) && (!formatInfo.mHidePointers) || (dataAddr == 0))) - { + { retVal = EncodeDataPtr((uint32)dataAddr, true); retVal += " "; if (!ceContext->CheckMemory(dataAddr, displayType->mInstSize)) isMemoryValid = false; } - + bool isBadSrc = false; bool isNull = dataAddr == 0; bool hadCustomDisplayString = false; @@ -3477,7 +3470,7 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const bool useActualRawType = false; bool isTuple = typedValue.mType->IsTuple(); - + String ptrDataStr; if (!formatInfo.mIgnoreDerivedClassInfo) @@ -3496,11 +3489,11 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const } } } - + BfTypedValue summaryTypedValue = typedValue; if ((actualType != NULL) && (actualType != displayType)) - { + { summaryTypedValue = BfTypedValue(module->mBfIRBuilder->CreateIntToPtr(addr, module->mBfIRBuilder->MapType(actualType)), actualType); } @@ -3508,7 +3501,7 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const Array dbgVisWildcardCaptures; if ((!formatInfo.mNoVisualizers) && (!isNull) && (!isBadSrc)) - { + { debugVis = FindVisualizerForType(summaryTypedValue.mType, &dbgVisWildcardCaptures); } @@ -3570,8 +3563,8 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const } else if ((!isNull) && (!formatInfo.mNoVisualizers) && (!hadCustomDisplayString)) { - // Create our own custom display - + // Create our own custom display + String firstRet; String bigRet = isTuple ? "(" : "{ "; @@ -3579,15 +3572,15 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const BfType* summaryType = summaryTypedValue.mType; bool summaryDone = false; bool truncatedMemberList = false; - + String summaryDataStr = ptrDataStr; String splatStr; if (dataAddr == -1) splatStr = expr; while ((summaryType != NULL) && (isMemoryValid)) - { - if ((summaryType->IsTypedPrimitive()) + { + if ((summaryType->IsTypedPrimitive()) //&& ((summaryType->mBaseTypes.IsEmpty()) || (!summaryType->mBaseTypes.front()->mBaseType->IsTypedPrimitive()))) ) { @@ -3746,7 +3739,7 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const bigRet += result; //formatInfo.mEmbeddedDisplayCount = displayStrFormatInfo.mEmbeddedDisplayCount; memberIdx++; - } + } } } @@ -3754,12 +3747,12 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const break; // Find first base class with members - BfType* nextSummaryType = summaryTypeInst->mBaseType; + BfType* nextSummaryType = summaryTypeInst->mBaseType; summaryType = nextSummaryType; if ((summaryType == NULL) || (summaryType == module->mContext->mBfObjectType)) break; - + // If we don't have many members then find a base class with some members to show if ((memberIdx != 0) && (displayString.length() >= 255)) { @@ -3776,7 +3769,7 @@ String CeDebugger::TypedValueToString(const BfTypedValue& origTypedValue, const if ((memberIdx == 1) && (!truncatedMemberList) && (firstRet.IndexOf('{') == -1) && (!isTuple)) displayString += "{ " + firstRet + " }"; else - displayString += bigRet; + displayString += bigRet; } retVal += displayString; @@ -3824,10 +3817,10 @@ void CeDebugger::HandleCustomExpandedItems(String& retVal, DebugVisualizerEntry* { auto debugVisualizers = mDebugManager->mDebugVisualizers; auto ceModule = mCeMachine->mCeModule; - + if (formatInfo.mExpandItemDepth > 10) // Avoid crashing on circular ExpandItems return; - + bool isReadOnly = false; // if (useTypedValue.mIsReadOnly) // isReadOnly = true; @@ -3980,7 +3973,7 @@ void CeDebugger::HandleCustomExpandedItems(String& retVal, DebugVisualizerEntry* int dimSize1 = lowerDimSizes[0]; int dimSize2 = lowerDimSizes[1]; int dimSize3 = lowerDimSizes[2]; - + BfTypedValue headPointer = EvaluateInContext(typedValue, debugVisualizers->DoStringReplace(debugVis->mValuePointer, dbgVisWildcardCaptures), &formatInfo); if ((headPointer.mType != NULL) && (headPointer.mType->IsPointer())) { @@ -4025,7 +4018,7 @@ void CeDebugger::HandleCustomExpandedItems(String& retVal, DebugVisualizerEntry* BfType* valueType = NULL; if (!debugVis->mValueType.empty()) { - valueType = FindType(debugVisualizers->DoStringReplace(debugVis->mValueType, dbgVisWildcardCaptures)); + valueType = FindType(debugVisualizers->DoStringReplace(debugVis->mValueType, dbgVisWildcardCaptures)); } BfTypedValue headPointer = EvaluateInContext(typedValue, debugVisualizers->DoStringReplace(debugVis->mHeadPointer, dbgVisWildcardCaptures), &formatInfo); @@ -4106,12 +4099,12 @@ void CeDebugger::HandleCustomExpandedItems(String& retVal, DebugVisualizerEntry* BfType* valueType = NULL; if (!debugVis->mValueType.empty()) { - valueType = FindType(debugVisualizers->DoStringReplace(debugVis->mValueType, dbgVisWildcardCaptures)); + valueType = FindType(debugVisualizers->DoStringReplace(debugVis->mValueType, dbgVisWildcardCaptures)); } BfTypedValue sizeValue = EvaluateInContext(typedValue, debugVisualizers->DoStringReplace(debugVis->mSize, dbgVisWildcardCaptures), &formatInfo); BfTypedValue headPointer = EvaluateInContext(typedValue, debugVisualizers->DoStringReplace(debugVis->mHeadPointer, dbgVisWildcardCaptures), &formatInfo); - + if ((sizeValue) && (headPointer) && (sizeValue.mType->IsInteger()) && (ValueToInt(sizeValue) > 0)) { BfTypedValue curNode = headPointer; @@ -4156,7 +4149,7 @@ void CeDebugger::HandleCustomExpandedItems(String& retVal, DebugVisualizerEntry* if (isReadOnly) evalStr += ", ne"; retVal += "\n:repeat" + StrFormat("\t%d\t%d\t%d", 0, size, 10000) + - "\t[{0}]\t" + evalStr + "\t" + EncodeDataPtr(firstAddr, false); + "\t[{0}]\t" + evalStr + "\t" + EncodeDataPtr(firstAddr, false); if (hasSecondAddr) retVal += "\t" + EncodeDataPtr(secondAddr, false); @@ -4173,7 +4166,7 @@ void CeDebugger::HandleCustomExpandedItems(String& retVal, DebugVisualizerEntry* { BfTypedValue sizeValue = EvaluateInContext(typedValue, debugVisualizers->DoStringReplace(debugVis->mSize, dbgVisWildcardCaptures), &formatInfo); BfTypedValue entriesPtrValue = EvaluateInContext(typedValue, debugVisualizers->DoStringReplace(debugVis->mEntries, dbgVisWildcardCaptures), &formatInfo); - + if ((sizeValue) && (entriesPtrValue) && (sizeValue.mType->IsInteger()) && (ValueToInt(sizeValue) > 0)) { String continuationData; @@ -4210,7 +4203,7 @@ void CeDebugger::HandleCustomExpandedItems(String& retVal, DebugVisualizerEntry* } if (formatInfo.mExpandItemDepth == 0) - { + { retVal += "\n[Raw View]\tthis,this=" + ptrUseDataStr + ", nv"; } } @@ -4230,7 +4223,7 @@ String CeDebugger::EvaluateContinue() if (!mDebugPendingExpr->mDone) return "!pending"; - + String result = mDebugPendingExpr->mResult; delete mDebugPendingExpr; mDebugPendingExpr = NULL; @@ -4265,15 +4258,15 @@ String CeDebugger::GetAutoLocals(int callStackIdx, bool showRegs) String result; - auto ceFrame = GetFrame(callStackIdx); + auto ceFrame = GetFrame(callStackIdx); if (ceFrame == NULL) return result; - + int scopeIdx = -1; auto ceEntry = ceFrame->mFunction->FindEmitEntry(ceFrame->GetInstIdx()); if (ceEntry != NULL) scopeIdx = ceEntry->mScope; - + int instIdx = ceFrame->GetInstIdx(); if (ceFrame->mFunction->mDbgInfo != NULL) { @@ -4320,9 +4313,9 @@ String CeDebugger::GetAutoLocals(int callStackIdx, bool showRegs) else { dbgInfo[i].mIncluded = false; - } + } } - + for (int i = 0; i < ceFunction->mDbgInfo->mVariables.mSize; i++) { auto& dbgVar = ceFunction->mDbgInfo->mVariables[i]; @@ -4334,7 +4327,7 @@ String CeDebugger::GetAutoLocals(int callStackIdx, bool showRegs) result += "\n"; } } - } + } return result; } @@ -4357,10 +4350,10 @@ DebugVisualizerEntry* CeDebugger::FindVisualizerForType(BfType* dbgType, ArraymDebugVisualizers->FindEntryForType(ceModule->TypeToString(dbgType), DbgFlavor_Unknown, wildcardCaptures); if (entry == NULL) - { + { auto typeInst = dbgType->ToTypeInstance(); if ((typeInst != NULL) && (typeInst->mBaseType != NULL)) - entry = FindVisualizerForType(typeInst->mBaseType, wildcardCaptures); + entry = FindVisualizerForType(typeInst->mBaseType, wildcardCaptures); } return entry; @@ -4402,7 +4395,7 @@ void CeDebugger::ClearCallStack() void CeDebugger::UpdateCallStack(bool slowEarlyOut) { AutoCrit autoCrit(mCeMachine->mCritSect); - + if (!mDbgCallStack.IsEmpty()) return; @@ -4410,7 +4403,7 @@ void CeDebugger::UpdateCallStack(bool slowEarlyOut) for (int frameIdx = ceContext->mCallStack.mSize - 1; frameIdx >= 0; frameIdx--) { auto ceFrame = &ceContext->mCallStack[frameIdx]; - + auto instIdx = ceFrame->GetInstIdx(); auto emitEntry = ceFrame->mFunction->FindEmitEntry(instIdx); if (emitEntry == NULL) @@ -4419,7 +4412,7 @@ void CeDebugger::UpdateCallStack(bool slowEarlyOut) int scopeIdx = emitEntry->mScope; int prevInlineIdx = -1; while (scopeIdx != -1) - { + { CeDbgStackInfo ceDbgStackInfo; ceDbgStackInfo.mFrameIdx = frameIdx; ceDbgStackInfo.mScopeIdx = scopeIdx; @@ -4449,7 +4442,7 @@ int CeDebugger::GetCallStackCount() if (!mCeMachine->mDbgPaused) return 0; - UpdateCallStack(); + UpdateCallStack(); return mDbgCallStack.mSize; } @@ -4524,7 +4517,7 @@ void CeDebugger::GetStackAllocInfo(intptr addr, int* outThreadId, int* outStackI if (outStackIdx != NULL) *outStackIdx = (int)ceContext->mCallStack.mSize - i - 1; } - } + } } String CeDebugger::GetStackFrameInfo(int stackFrameIdx, intptr* addr, String* outFile, int32* outHotIdx, int32* outDefLineStart, int32* outDefLineEnd, int32* outLine, int32* outColumn, int32* outLanguage, int32* outStackSize, int8* outFlags) @@ -4545,8 +4538,8 @@ String CeDebugger::GetStackFrameInfo(int stackFrameIdx, intptr* addr, String* ou FrameFlags_HadError = 0x10 }; - auto ceContext = mCeMachine->mCurContext; - + auto ceContext = mCeMachine->mCurContext; + *addr = 0; *outFile = ""; *outHotIdx = 0; @@ -4562,11 +4555,11 @@ String CeDebugger::GetStackFrameInfo(int stackFrameIdx, intptr* addr, String* ou return ""; auto& dbgCallstackInfo = mDbgCallStack[stackFrameIdx]; - + if (dbgCallstackInfo.mFrameIdx == -1) { if (ceContext->mCurCallSource != NULL) - { + { int line = -1; int lineChar = -1; auto parserData = ceContext->mCurCallSource->mRefNode->GetParserData(); @@ -4576,7 +4569,7 @@ String CeDebugger::GetStackFrameInfo(int stackFrameIdx, intptr* addr, String* ou *outLine = line; *outColumn = lineChar; *outFile = parserData->mFileName; - } + } } // Entry marker @@ -4607,14 +4600,14 @@ String CeDebugger::GetStackFrameInfo(int stackFrameIdx, intptr* addr, String* ou if (ceFunction->mFailed) *outFlags |= FrameFlags_HadError; - + int instIdx = (int)(ceFrame->mInstPtr - &ceFunction->mCode[0] - 2); BF_ASSERT(ceFunction->mId != -1); *addr = ((intptr)ceFunction->mId << 32) | instIdx; CeEmitEntry* emitEntry = ceFunction->FindEmitEntry(instIdx); - + *outStackSize = ceContext->mStackSize - ceFrame->mStackAddr; if (stackFrameIdx < mDbgCallStack.mSize - 1) { @@ -4625,12 +4618,11 @@ String CeDebugger::GetStackFrameInfo(int stackFrameIdx, intptr* addr, String* ou *outStackSize = prevFrame->mStackAddr - ceFrame->mStackAddr; } } - CeDbgScope* ceScope = NULL; if (dbgCallstackInfo.mScopeIdx != -1) ceScope = &ceFunction->mDbgScopes[dbgCallstackInfo.mScopeIdx]; - + if (emitEntry != NULL) { if (emitEntry->mScope != -1) @@ -4658,18 +4650,18 @@ String CeDebugger::GetStackFrameInfo(int stackFrameIdx, intptr* addr, String* ou auto callTableEntry = &ceFunction->mCallTable[ceScope->mMethodVal]; return ceContext->mCurModule->MethodToString(callTableEntry->mFunctionInfo->mMethodInstance); } - } + } return ceContext->mCurModule->MethodToString(ceFrame->mFunction->mMethodInstance); } BfType* CeDebugger::FindType(const StringImpl& name) -{ +{ if (name == "System.Object") return mCeMachine->mCeModule->mContext->mBfObjectType; BfParser parser(mCompiler->mSystem); - BfPassInstance passInstance(mCompiler->mSystem); + BfPassInstance passInstance(mCompiler->mSystem); parser.SetSource(name.c_str(), (int)name.length()); parser.Parse(&passInstance); @@ -4682,7 +4674,7 @@ BfType* CeDebugger::FindType(const StringImpl& name) reducer.mSource = &parser; auto typeRef = reducer.CreateTypeRef(parser.mRootNode->GetFirst()); parser.Close(); - + auto ceModule = mCeMachine->mCeModule; SetAndRestoreValue prevIgnoreErrors(ceModule->mIgnoreErrors, true); SetAndRestoreValue prevIgnoreWarning(ceModule->mIgnoreWarnings, true); @@ -4700,7 +4692,7 @@ String CeDebugger::Callstack_GetStackFrameOldFileInfo(int stackFrameIdx) int CeDebugger::GetJmpState(int stackFrameIdx) { AutoCrit autoCrit(mDebugManager->mCritSect); - + if (!mCeMachine->mDbgPaused) return -1; @@ -4775,7 +4767,7 @@ String CeDebugger::DisassembleAt(intptr address) mCurDisasmFuncId = (int)(address >> 32); UpdateBreakpointAddrs(); - + CeFunction* ceFunction = NULL; if (!mCeMachine->mFunctionIdMap.TryGetValue(mCurDisasmFuncId, &ceFunction)) return ""; @@ -4787,13 +4779,13 @@ String CeDebugger::DisassembleAt(intptr address) dumpCtx.mEnd = dumpCtx.mPtr + ceFunction->mCode.mSize; uint8* start = dumpCtx.mStart; - + dumpCtx.mStr += StrFormat("T Frame Size: %d\n", ceFunction->mFrameSize); dumpCtx.mStr += StrFormat("A %llX\n", (intptr)mCurDisasmFuncId << 32); int curEmitIdx = 0; CeEmitEntry* prevEmitEntry = NULL; - CeEmitEntry* curEmitEntry = NULL; + CeEmitEntry* curEmitEntry = NULL; String prevSourcePath; @@ -4833,11 +4825,11 @@ String CeDebugger::DisassembleAt(intptr address) } prevEmitEntry = curEmitEntry; - } + } } - + dumpCtx.mStr += StrFormat("D %04X: ", ofs); - dumpCtx.Next(); + dumpCtx.Next(); dumpCtx.mStr += "\n"; if (dumpCtx.mJmp != -1) @@ -4845,7 +4837,7 @@ String CeDebugger::DisassembleAt(intptr address) dumpCtx.mStr += StrFormat("J %X\n", dumpCtx.mJmp); dumpCtx.mJmp = -1; } - } + } return dumpCtx.mStr; } @@ -4931,4 +4923,4 @@ bool CeDebugger::IsOnDemandDebugger() bool CeDebugger::GetEmitSource(const StringImpl& filePath, String& outText) { return false; -} +} \ No newline at end of file diff --git a/IDEHelper/Compiler/CeDebugger.h b/IDEHelper/Compiler/CeDebugger.h index 375ee140..f37743e1 100644 --- a/IDEHelper/Compiler/CeDebugger.h +++ b/IDEHelper/Compiler/CeDebugger.h @@ -29,7 +29,7 @@ public: class CeBreakpoint : public Breakpoint { -public: +public: uintptr mCurBindAddr; bool mHasBound; int mIdx; @@ -37,7 +37,7 @@ public: public: CeBreakpoint() - { + { mCurBindAddr = 1; mHasBound = false; mIdx = -1; @@ -62,7 +62,7 @@ struct CeFormatInfo intptr mArrayLength; intptr mOverrideCount; intptr mMaxCount; - DwDisplayType mDisplayType; + DwDisplayType mDisplayType; int mTotalSummaryLength; String mReferenceId; String mSubjectExpr; @@ -86,7 +86,7 @@ struct CeFormatInfo mMaxCount = -1; mTotalSummaryLength = 0; mDisplayType = DwDisplayType_NotSpecified; - mExpandItemDepth = 0; + mExpandItemDepth = 0; } }; @@ -99,7 +99,7 @@ public: BfPassInstance* mPassInstance; BfExprEvaluator* mExprEvaluator; BfExpression* mExprNode; - BfTypedValue mResultOverride; + BfTypedValue mResultOverride; String mExprString; BfTypedValue mExplicitThis; @@ -110,7 +110,7 @@ public: void Init(CeDebugger* winDebugger, const StringImpl& expr, CeFormatInfo* formatInfo = NULL, BfTypedValue contextValue = BfTypedValue()); bool HasExpression(); ~CeEvaluationContext(); - BfTypedValue EvaluateInContext(BfTypedValue contextTypedValue, CeDbgState* dbgState = NULL); + BfTypedValue EvaluateInContext(BfTypedValue contextTypedValue, CeDbgState* dbgState = NULL); String GetErrorStr(); bool HadError(); }; @@ -153,9 +153,9 @@ public: BfAstNode* mExprNode; String mReferenceId; int mCallStackIdx; - String mResult; + String mResult; int mIdleTicks; - String mException; + String mException; bool mDone; CePendingExpr(); @@ -197,7 +197,7 @@ public: { public: int mFieldIdx; - int64 mVal; + int64 mVal; }; public: @@ -243,16 +243,16 @@ public: CeMachine* mCeMachine; DebugManager* mDebugManager; CePendingExpr* mDebugPendingExpr; - CeDbgState* mCurDbgState; + CeDbgState* mCurDbgState; Array mBreakpoints; - Dictionary mFileInfo; + Dictionary mFileInfo; Dictionary mDbgTypeInfoMap; Array mDbgCallStack; CeEvaluationContext* mCurEvaluationContext; CeBreakpoint* mActiveBreakpoint; int mBreakpointVersion; - bool mBreakpointCacheDirty; + bool mBreakpointCacheDirty; bool mBreakpointFramesDirty; int mCurDisasmFuncId; int mPendingActiveFrameOffset; @@ -270,7 +270,7 @@ public: bool CheckConditionalBreakpoint(CeBreakpoint* breakpoint); bool SetupStep(int frameIdx = 0); - CeFrame* GetFrame(int callStackIdx); + CeFrame* GetFrame(int callStackIdx); String DoEvaluate(CePendingExpr* pendingExpr, bool inCompilerThread); String Evaluate(const StringImpl& expr, CeFormatInfo formatInfo, int callStackIdx, int cursorPos, int language, DwEvalExpressionFlags expressionFlags); DwDisplayInfo* GetDisplayInfo(const StringImpl& referenceId); @@ -296,7 +296,7 @@ public: void UpdateBreakpointCache(); void UpdateBreakpointFrames(); void UpdateBreakpointAddrs(); - void UpdateBreakpoints(CeFunction* ceFunction); + void UpdateBreakpoints(CeFunction* ceFunction); void Continue(); CeDbgTypeInfo* GetDbgTypeInfo(int typeId); CeDbgTypeInfo* GetDbgTypeInfo(BfIRType irType); @@ -346,7 +346,7 @@ public: virtual void StepIntoSpecific(intptr addr) override; virtual void StepOver(bool inAssembly) override; virtual void StepOut(bool inAssembly) override; - virtual void SetNextStatement(bool inAssembly, const StringImpl& fileName, int64 lineNumOrAsmAddr, int wantColumn) override; + virtual void SetNextStatement(bool inAssembly, const StringImpl& fileName, int64 lineNumOrAsmAddr, int wantColumn) override; //virtual DbgTypedValue GetRegister(const StringImpl& regName, CPURegisters* registers, Array* regForms = NULL) override; virtual String Evaluate(const StringImpl& expr, int callStackIdx, int cursorPos, int language, DwEvalExpressionFlags expressionFlags) override; virtual String EvaluateContinue() override; diff --git a/IDEHelper/Compiler/CeMachine.cpp b/IDEHelper/Compiler/CeMachine.cpp index c6a05806..964272bf 100644 --- a/IDEHelper/Compiler/CeMachine.cpp +++ b/IDEHelper/Compiler/CeMachine.cpp @@ -103,7 +103,7 @@ static CeOpInfo gOpInfo[] = {"Jmp", CEOI_None, CEOI_JMPREL}, {"JmpIf", CEOI_None, CEOI_JMPREL, CEOI_FrameRef8}, {"JmpIfNot", CEOI_None, CEOI_JMPREL, CEOI_FrameRef8}, - {"Error", CEOI_None, CEOI_IMM32}, + {"Error", CEOI_None, CEOI_IMM32}, {"DynamicCastCheck", CEOI_FrameRef, CEOI_FrameRef, CEOI_IMM32}, {"GetReflectType", CEOI_FrameRef, CEOI_IMM32}, {"GetString", CEOI_FrameRef, CEOI_IMM32}, @@ -118,8 +118,8 @@ static CeOpInfo gOpInfo[] = {"FrameAddrOfs_32", CEOI_FrameRef, CEOI_FrameRef, CEOI_IMM32}, {"ConstData", CEOI_FrameRef, CEOI_IMM32}, {"ConstDataRef", CEOI_FrameRef, CEOI_IMM32}, - {"Zero", CEOI_None, CEOI_FrameRef, CEOI_IMM32}, - + {"Zero", CEOI_None, CEOI_FrameRef, CEOI_IMM32}, + {"Const_8", CEOI_FrameRef8, CEOI_IMM8}, {"Const_16", CEOI_FrameRef16, CEOI_IMM16}, {"Const_32", CEOI_FrameRef32, CEOI_IMM32}, @@ -190,14 +190,14 @@ static CeOpInfo gOpInfo[] = {"CeOp_Conv_F64_U32", CEOI_FrameRef32, CEOI_FrameRefF64}, {"CeOp_Conv_F64_U64", CEOI_FrameRef64, CEOI_FrameRefF64}, {"CeOp_Conv_F64_F32", CEOI_FrameRefF32, CEOI_FrameRefF64}, - + CEOPINFO_SIZED_NUMERIC_PLUSF_2("Abs", CEOI_FrameRef, CEOI_FrameRef), {"AddConst_I8", CEOI_FrameRef8, CEOI_FrameRef8, CEOI_IMM8}, {"AddConst_I16", CEOI_FrameRef16, CEOI_FrameRef16, CEOI_IMM16}, {"AddConst_I32", CEOI_FrameRef32, CEOI_FrameRef32, CEOI_IMM32}, {"AddConst_I64", CEOI_FrameRef64, CEOI_FrameRef64, CEOI_IMM64}, {"AddConst_F32", CEOI_FrameRefF32, CEOI_FrameRefF32, CEOI_IMMF32}, - {"AddConst_F64", CEOI_FrameRefF64, CEOI_FrameRefF64, CEOI_IMMF64}, + {"AddConst_F64", CEOI_FrameRefF64, CEOI_FrameRefF64, CEOI_IMMF64}, CEOPINFO_SIZED_NUMERIC_PLUSF_3("Add", CEOI_FrameRef, CEOI_FrameRef, CEOI_FrameRef), CEOPINFO_SIZED_NUMERIC_PLUSF_3("Sub", CEOI_FrameRef, CEOI_FrameRef, CEOI_FrameRef), CEOPINFO_SIZED_NUMERIC_PLUSF_3("Mul", CEOI_FrameRef, CEOI_FrameRef, CEOI_FrameRef), @@ -211,7 +211,7 @@ static CeOpInfo gOpInfo[] = CEOPINFO_SIZED_NUMERIC_3("Shl", CEOI_FrameRef, CEOI_FrameRef, CEOI_FrameRef), CEOPINFO_SIZED_NUMERIC_3("Shr", CEOI_FrameRef, CEOI_FrameRef, CEOI_FrameRef), CEOPINFO_SIZED_UNUMERIC_3("Shr", CEOI_FrameRef, CEOI_FrameRef, CEOI_FrameRef), - + CEOPINFO_SIZED_FLOAT_2("Acos", CEOI_FrameRef, CEOI_FrameRef), CEOPINFO_SIZED_FLOAT_2("Asin", CEOI_FrameRef, CEOI_FrameRef), CEOPINFO_SIZED_FLOAT_2("Atan", CEOI_FrameRef, CEOI_FrameRef), @@ -240,7 +240,7 @@ static CeOpInfo gOpInfo[] = CEOPINFO_SIZED_NUMERIC_PLUSF_3("Cmp_SGT", CEOI_FrameRef, CEOI_FrameRef, CEOI_FrameRef), CEOPINFO_SIZED_NUMERIC_3("Cmp_UGT", CEOI_FrameRef, CEOI_FrameRef, CEOI_FrameRef), CEOPINFO_SIZED_NUMERIC_PLUSF_3("Cmp_SGE", CEOI_FrameRef, CEOI_FrameRef, CEOI_FrameRef), - CEOPINFO_SIZED_NUMERIC_3("Cmp_UGE", CEOI_FrameRef, CEOI_FrameRef, CEOI_FrameRef), + CEOPINFO_SIZED_NUMERIC_3("Cmp_UGE", CEOI_FrameRef, CEOI_FrameRef, CEOI_FrameRef), CEOPINFO_SIZED_NUMERIC_PLUSF_2("Neg", CEOI_FrameRef, CEOI_FrameRef), {"Not_I1", CEOI_FrameRef8, CEOI_FrameRef8}, CEOPINFO_SIZED_NUMERIC_2("Not", CEOI_FrameRef, CEOI_FrameRef), @@ -404,7 +404,7 @@ CeEmitEntry* CeFunction::FindEmitEntry(int instIdx, int* entryIdx) if (!mCode.IsEmpty()) { int lo = 0; - int hi = mEmitTable.size() - 1; + int hi = mEmitTable.size() - 1; while (lo <= hi) { i = (lo + hi) / 2; @@ -439,7 +439,6 @@ int CeFunction::SafeGetId() } __except (EXCEPTION_EXECUTE_HANDLER) { - } return 0; #else @@ -549,7 +548,7 @@ void CeDumpContext::DumpOperandInfo(CeOperandInfoKind operandInfoKind) mStr += '['; int32 size = CE_GET(int32); for (int i = 0; i < size; i++) - { + { if (i != 0) mStr += ", "; uint8 val = CE_GET(uint8); @@ -557,7 +556,7 @@ void CeDumpContext::DumpOperandInfo(CeOperandInfoKind operandInfoKind) sprintf(str, "%X", val); mStr += str; } - mStr += ']'; + mStr += ']'; } break; case CEOI_JMPREL: @@ -587,8 +586,8 @@ void CeDumpContext::Next() } } - CeOpInfo& opInfo = gOpInfo[op]; - + CeOpInfo& opInfo = gOpInfo[op]; + auto argPtr = mPtr; if (mCeFunction->mDbgInfo != NULL) @@ -647,17 +646,17 @@ void CeDumpContext::Next() auto methodInstance = callEntry.mFunctionInfo->mMethodInstance; auto ceModule = mCeFunction->mCeMachine->mCeModule; if (!callEntry.mFunctionInfo->mMethodRef.IsNull()) - { + { auto methodRef = callEntry.mFunctionInfo->mMethodRef; auto methodDef = methodRef.mTypeInstance->mTypeDef->mMethods[methodRef.mMethodNum]; methodInstance = ceModule->GetMethodInstance(methodRef.mTypeInstance, methodDef, - methodRef.mMethodGenericArguments).mMethodInstance; + methodRef.mMethodGenericArguments).mMethodInstance; } if (methodInstance != NULL) mStr += StrFormat(" ; %s", ceModule->MethodToString(methodInstance).c_str()); mPtr = endPtr; - } + } } void CeDumpContext::Dump() @@ -669,11 +668,11 @@ void CeDumpContext::Dump() uint8* start = mPtr; int curEmitIdx = 0; CeEmitEntry* curEmitEntry = NULL; - + while (mPtr < mEnd) { int ofs = mPtr - start; - + while ((curEmitIdx < mCeFunction->mEmitTable.mSize - 1) && (ofs >= mCeFunction->mEmitTable[curEmitIdx + 1].mCodePos)) curEmitIdx++; if (curEmitIdx < mCeFunction->mEmitTable.mSize) @@ -683,12 +682,12 @@ void CeDumpContext::Dump() Next(); if ((curEmitEntry != NULL) && (curEmitEntry->mScope != -1)) - { + { mStr += StrFormat(" @%d[%s:%d]", curEmitIdx, GetFileName(mCeFunction->mDbgScopes[curEmitEntry->mScope].mFilePath).c_str(), curEmitEntry->mLine + 1, curEmitEntry->mColumn + 1); } - mStr += "\n"; + mStr += "\n"; } } @@ -723,8 +722,8 @@ void CeBuilder::Emit(CeOp val) void CeBuilder::EmitSizedOp(CeOp val, int size) { CeSizeClass sizeClass = GetSizeClass(size); - Emit((CeOp)(val + sizeClass)); - if (sizeClass == CeSizeClass_X) + Emit((CeOp)(val + sizeClass)); + if (sizeClass == CeSizeClass_X) Emit((int32)size); } @@ -773,19 +772,19 @@ void CeBuilder::EmitBinarySwitchSection(BeSwitchInst* switchInst, int startIdx, if (endIdx - startIdx >= 18) { // int gteLabel = mCurLabelIdx++; -// +// // auto mcDefaultBlock = GetOperand(switchInst->mDefaultBlock); -// +// // int midIdx = startIdx + (endIdx - startIdx) / 2; // auto& switchCase = switchInst->mCases[midIdx]; // auto switchBlock = GetOperand(switchCase.mBlock); // auto mcValue = GetOperand(switchInst->mValue); // auto valueType = GetType(mcValue); -// +// // AllocInst(BeMCInstKind_Cmp, mcValue, GetOperand(switchCase.mValue)); // AllocInst(BeMCInstKind_CondBr, BeMCOperand::FromLabel(gteLabel), BeMCOperand::FromCmpKind(BeCmpKind_SGE)); // switchBlock.mBlock->AddPred(mActiveBlock); -// +// // CreateBinarySwitchSection(switchInst, startIdx, midIdx); // AllocInst(BeMCInstKind_Br, mcDefaultBlock); // CreateLabel(-1, gteLabel); @@ -818,7 +817,7 @@ void CeBuilder::EmitFrameOffset(const CeOperand& val) void CeBuilder::FlushPhi(CeBlock* ceBlock, int targetBlockIdx) { - for (int i = 0; i < (int)ceBlock->mPhiOutgoing.size(); i++) + for (int i = 0; i < (int)ceBlock->mPhiOutgoing.size(); i++) { auto& phiOutgoing = ceBlock->mPhiOutgoing[i]; if (phiOutgoing.mPhiBlockIdx == targetBlockIdx) @@ -839,7 +838,7 @@ void CeBuilder::EmitBinaryOp(CeOp iOp, CeOp fOp, const CeOperand& lhs, const CeO { CeOp op = iOp; if (lhs.mType->IsIntable()) - { + { if (lhs.mType->mSize == 1) op = iOp; else if (lhs.mType->mSize == 2) @@ -855,7 +854,7 @@ void CeBuilder::EmitBinaryOp(CeOp iOp, CeOp fOp, const CeOperand& lhs, const CeO { BF_ASSERT(fOp != CeOp_InvalidOp); if (lhs.mType->mSize == 4) - op = fOp; + op = fOp; else if (lhs.mType->mSize == 8) op = (CeOp)(fOp + 1); else @@ -864,7 +863,7 @@ void CeBuilder::EmitBinaryOp(CeOp iOp, CeOp fOp, const CeOperand& lhs, const CeO else Fail("Invalid binary operand"); Emit(op); - + if (!result) result = FrameAlloc(lhs.mType); EmitFrameOffset(result); @@ -903,7 +902,7 @@ void CeBuilder::EmitUnaryOp(CeOp iOp, CeOp fOp, const CeOperand& val, CeOperand& result = FrameAlloc(val.mType); EmitFrameOffset(result); - EmitFrameOffset(val); + EmitFrameOffset(val); } void CeBuilder::EmitSizedOp(CeOp baseOp, const CeOperand& operand, CeOperand* outResult, bool allowNonStdSize) @@ -924,7 +923,7 @@ void CeBuilder::EmitSizedOp(CeOp baseOp, const CeOperand& operand, CeOperand* ou isStdSize = false; op = (CeOp)(baseOp + 4); } - + Emit(op); if (!isStdSize) @@ -938,9 +937,9 @@ void CeBuilder::EmitSizedOp(CeOp baseOp, const CeOperand& operand, CeOperand* ou { *outResult = FrameAlloc(operand.mType); EmitFrameOffset(*outResult); - } + } - EmitFrameOffset(operand); + EmitFrameOffset(operand); } CeOperand CeBuilder::FrameAlloc(BeType* type) @@ -950,7 +949,7 @@ CeOperand CeBuilder::FrameAlloc(BeType* type) CeOperand result; result.mKind = CeOperandKind_FrameOfs; result.mFrameOfs = -mFrameSize; - result.mType = type; + result.mType = type; return result; } @@ -1045,7 +1044,7 @@ CeOperand CeBuilder::GetOperand(BeValue* value, bool allowAlloca, bool allowImme { if (value == NULL) return CeOperand(); - + BeType* errorType = mIntPtrType; CeErrorKind errorKind = CeErrorKind_None; @@ -1092,7 +1091,7 @@ CeOperand CeBuilder::GetOperand(BeValue* value, bool allowAlloca, bool allowImme Emit(CeOp_GetString); EmitFrameOffset(result); Emit((int32)*stringTableIdxPtr); - + BfTypeInstance* stringTypeInst = (BfTypeInstance*)mCeMachine->mCeModule->ResolveTypeDef( mCeMachine->mCeModule->mCompiler->mStringTypeDef, BfPopulateType_Data); @@ -1106,13 +1105,13 @@ CeOperand CeBuilder::GetOperand(BeValue* value, bool allowAlloca, bool allowImme BfFieldInstance** fieldInstancePtr = NULL; if (mStaticFieldInstanceMap.TryGetValue(globalVar->mName, &fieldInstancePtr)) - { + { int* staticFieldTableIdxPtr = NULL; if (mStaticFieldMap.TryAdd(globalVar, NULL, &staticFieldTableIdxPtr)) { CeStaticFieldEntry staticFieldEntry; staticFieldEntry.mTypeId = (*fieldInstancePtr)->mOwner->mTypeId; - staticFieldEntry.mName = globalVar->mName; + staticFieldEntry.mName = globalVar->mName; staticFieldEntry.mSize = globalVar->mType->mSize; *staticFieldTableIdxPtr = (int)mCeFunction->mStaticFieldTable.size(); mCeFunction->mStaticFieldTable.Add(staticFieldEntry); @@ -1151,7 +1150,7 @@ CeOperand CeBuilder::GetOperand(BeValue* value, bool allowAlloca, bool allowImme case BeCastConstant::TypeId: { auto constant = (BeCastConstant*)value; - + CeOperand mcOperand; auto result = GetOperand(constant->mTarget); result.mType = constant->mType; @@ -1183,7 +1182,7 @@ CeOperand CeBuilder::GetOperand(BeValue* value, bool allowAlloca, bool allowImme return result; } - case BeTypeCode_Boolean: + case BeTypeCode_Boolean: case BeTypeCode_Double: dataPtr = &constant->mUInt64; dataSize = constant->mType->mSize; @@ -1209,20 +1208,20 @@ CeOperand CeBuilder::GetOperand(BeValue* value, bool allowAlloca, bool allowImme result.mType = constant->mType; return result; } - + // if (relTo.mKind == CeOperandKind_Immediate_Null) // { // mcOperand.mKind = CeOperandKind_Immediate_Null; // mcOperand.mType = constant->mType; // return mcOperand; // } -// +// // mcOperand = AllocVirtualReg(constant->mType); // auto vregInfo = GetVRegInfo(mcOperand); // vregInfo->mDefOnFirstUse = true; // vregInfo->mRelTo = relTo; // vregInfo->mIsExpr = true; -// +// //return mcOperand; } } @@ -1253,10 +1252,10 @@ CeOperand CeBuilder::GetOperand(BeValue* value, bool allowAlloca, bool allowImme CeSizeClass sizeClass = GetSizeClass(dataSize); Emit((CeOp)(CeOp_Const_8 + sizeClass)); EmitFrameOffset(result); - if (sizeClass == CeSizeClass_X) + if (sizeClass == CeSizeClass_X) Emit((int32)dataSize); if (dataPtr != 0) - Emit(dataPtr, dataSize); + Emit(dataPtr, dataSize); else { for (int i = 0; i < dataSize; i++) @@ -1264,7 +1263,7 @@ CeOperand CeBuilder::GetOperand(BeValue* value, bool allowAlloca, bool allowImme } return result; - } + } } break; case BeStructConstant::TypeId: @@ -1272,7 +1271,7 @@ CeOperand CeBuilder::GetOperand(BeValue* value, bool allowAlloca, bool allowImme int* constDataPtr = NULL; auto structConstant = (BeStructConstant*)value; if (mConstDataMap.TryAdd(structConstant, NULL, &constDataPtr)) - { + { CeConstStructData constStructData; constStructData.mQueueFixups = true; errorKind = mCeMachine->WriteConstant(constStructData, structConstant, NULL); @@ -1307,27 +1306,27 @@ CeOperand CeBuilder::GetOperand(BeValue* value, bool allowAlloca, bool allowImme } } else - { + { errorKind = CeErrorKind_GlobalVariable; } } - break; + break; case BeGEP1Constant::TypeId: { auto gepConstant = (BeGEP1Constant*)value; - + auto mcVal = GetOperand(gepConstant->mTarget); - + BePointerType* ptrType = (BePointerType*)mcVal.mType; BF_ASSERT(ptrType->mTypeCode == BeTypeCode_Pointer); - + auto result = mcVal; - - // We assume we never do both an idx0 and idx1 at once. Fix if we change that. + + // We assume we never do both an idx0 and idx1 at once. Fix if we change that. int64 byteOffset = 0; BeType* elementType = NULL; byteOffset += gepConstant->mIdx0 * ptrType->mElementType->mSize; - + result = FrameAlloc(ptrType); EmitSizedOp(CeOp_AddConst_I8, mPtrSize); EmitFrameOffset(result); @@ -1340,19 +1339,19 @@ CeOperand CeBuilder::GetOperand(BeValue* value, bool allowAlloca, bool allowImme case BeGEP2Constant::TypeId: { auto gepConstant = (BeGEP2Constant*)value; - + auto mcVal = GetOperand(gepConstant->mTarget); - + BePointerType* ptrType = (BePointerType*)mcVal.mType; BF_ASSERT(ptrType->mTypeCode == BeTypeCode_Pointer); - + auto result = mcVal; - - // We assume we never do both an idx0 and idx1 at once. Fix if we change that. + + // We assume we never do both an idx0 and idx1 at once. Fix if we change that. int64 byteOffset = 0; BeType* elementType = NULL; byteOffset += gepConstant->mIdx0 * ptrType->mElementType->mSize; - + if (ptrType->mElementType->mTypeCode == BeTypeCode_Struct) { BeStructType* structType = (BeStructType*)ptrType->mElementType; @@ -1367,7 +1366,7 @@ CeOperand CeBuilder::GetOperand(BeValue* value, bool allowAlloca, bool allowImme elementType = arrayType->mElementType; byteOffset = gepConstant->mIdx1 * elementType->GetStride(); } - + auto elementPtrType = mCeMachine->GetBeContext()->GetPointerTo(elementType); result = FrameAlloc(elementPtrType); EmitSizedOp(CeOp_AddConst_I8, mPtrSize); @@ -1383,16 +1382,16 @@ CeOperand CeBuilder::GetOperand(BeValue* value, bool allowAlloca, bool allowImme // Note: this only handles zero-aggregates auto extractConstant = (BeExtractValueConstant*)value; auto elementType = extractConstant->GetType(); - - auto mcVal = GetOperand(extractConstant->mTarget); - + + auto mcVal = GetOperand(extractConstant->mTarget); + BeConstant beConstant; beConstant.mType = elementType; beConstant.mUInt64 = 0; return GetOperand(&beConstant); } break; - case BeFunction::TypeId: + case BeFunction::TypeId: { auto beFunction = (BeFunction*)value; CeOperand operand; @@ -1428,7 +1427,7 @@ CeOperand CeBuilder::GetOperand(BeValue* value, bool allowAlloca, bool allowImme CeOperand* operandPtr = NULL; mValueToOperand.TryGetValue(value, &operandPtr); - + if (errorKind != CeErrorKind_None) { Emit(CeOp_Error); @@ -1454,7 +1453,7 @@ CeOperand CeBuilder::GetOperand(BeValue* value, bool allowAlloca, bool allowImme if ((operand.mKind == CeOperandKind_AllocaAddr) && (!allowAlloca)) { auto irCodeGen = mCeMachine->mCeModule->mBfIRBuilder->mBeIRCodeGen; - + auto ptrType = mCeMachine->GetBeContext()->GetPointerTo(operand.mType); auto result = FrameAlloc(ptrType); Emit((mPtrSize == 4) ? CeOp_FrameAddr_32 : CeOp_FrameAddr_64); @@ -1490,7 +1489,7 @@ int CeBuilder::DbgCreateMethodRef(BfMethodInstance* methodInstance, const String dbgMethodRef.mMethodRef = methodInstance; int* valuePtr = NULL; if (mDbgMethodRefMap.TryAdd(dbgMethodRef, NULL, &valuePtr)) - { + { *valuePtr = mCeFunction->mDbgMethodRefTable.mSize; mCeFunction->mDbgMethodRefTable.Add(dbgMethodRef); } @@ -1503,11 +1502,11 @@ void CeBuilder::HandleParams() // int regIdxOfs = 0; // int paramOfs = 0; auto retType = mBeFunction->GetFuncType()->mReturnType; - + int frameOffset = 0; if (mCeFunction->mMaxReturnSize > 0) - { + { mReturnVal.mKind = CeOperandKind_AllocaAddr; mReturnVal.mFrameOfs = frameOffset; frameOffset += mCeFunction->mMaxReturnSize; @@ -1522,7 +1521,7 @@ void CeBuilder::HandleParams() auto& typeParam = funcType->mParams[paramIdx + paramOfs]; auto& param = mBeFunction->mParams[paramIdx + paramOfs]; auto beArg = beModule->GetArgument(paramIdx + paramOfs); - auto paramType = typeParam.mType; + auto paramType = typeParam.mType; CeOperand ceOperand; ceOperand.mKind = CeOperandKind_FrameOfs; @@ -1552,8 +1551,8 @@ void CeBuilder::ProcessMethod(BfMethodInstance* methodInstance, BfMethodInstance dupMethodInstance->mIsReified = true; dupMethodInstance->mInCEMachine = false; // Only have the original one - - // We can't use methodInstance->mMethodInstanceGroup because we may add foreign method instances which + + // We can't use methodInstance->mMethodInstanceGroup because we may add foreign method instances which // would reallocate the methodInstanceGroup BfMethodInstanceGroup methodInstanceGroup; methodInstanceGroup.mOwner = methodInstance->mMethodInstanceGroup->mOwner; @@ -1568,7 +1567,7 @@ void CeBuilder::ProcessMethod(BfMethodInstance* methodInstance, BfMethodInstance mCeMachine->mCeModule->ProcessMethod(dupMethodInstance, true, forceIRWrites); irCodeGen->SetState(beState); irBuilder->SetState(irState); - + if (mCeMachine->mCeModule->mCompiler->mResolvePassData != NULL) mCeMachine->mCeModule->mCompiler->mResolvePassData->mAutoComplete = prevAutoComplete; @@ -1589,14 +1588,14 @@ void CeBuilder::Build() mCeFunction->mFailed = true; auto methodInstance = mCeFunction->mMethodInstance; - + if (methodInstance != NULL) { BfMethodInstance dupMethodInstance; dupMethodInstance.CopyFrom(methodInstance); auto methodDef = methodInstance->mMethodDef; - bool isGenericVariation = (methodInstance->mIsUnspecializedVariation) || (methodInstance->GetOwner()->IsUnspecializedTypeVariation()); + bool isGenericVariation = (methodInstance->mIsUnspecializedVariation) || (methodInstance->GetOwner()->IsUnspecializedTypeVariation()); int dependentGenericStartIdx = 0; if ((((methodInstance->mMethodInfoEx != NULL) && ((int)methodInstance->mMethodInfoEx->mMethodGenericArguments.size() > dependentGenericStartIdx)) || ((methodInstance->GetOwner()->IsGenericTypeInstance()) && (!isGenericVariation) && (!methodInstance->mMethodDef->mIsLocalMethod) && (!methodInstance->mIsUnspecialized)))) @@ -1611,12 +1610,12 @@ void CeBuilder::Build() dupMethodInstance.GetMethodInfoEx()->mGenericTypeBindings = dupUnspecMethodInstance.mMethodInfoEx->mGenericTypeBindings; } } - + // Clear this so we can properly get QueueStaticField calls - mCeMachine->mCeModule->mStaticFieldRefs.Clear(); + mCeMachine->mCeModule->mStaticFieldRefs.Clear(); int startFunctionCount = (int)beModule->mFunctions.size(); - ProcessMethod(methodInstance, &dupMethodInstance, true); + ProcessMethod(methodInstance, &dupMethodInstance, true); if (mCeFunction->mInitializeState == CeFunction::InitializeState_Initialized) return; @@ -1624,7 +1623,7 @@ void CeBuilder::Build() { mCeFunction->mFailed = true; return; - } + } mBeFunction = (BeFunction*)irCodeGen->GetBeValue(dupMethodInstance.mIRFunction.mId); mIntPtrType = irCodeGen->mBeContext->GetPrimitiveType((mPtrSize == 4) ? BeTypeCode_Int32 : BeTypeCode_Int64); @@ -1637,7 +1636,7 @@ void CeBuilder::Build() if (beFunction->mBlocks.IsEmpty()) continue; - CeFunction* innerFunction = new CeFunction(); + CeFunction* innerFunction = new CeFunction(); innerFunction->mCeMachine = mCeMachine; innerFunction->mIsVarReturn = beFunction->mIsVarReturn; innerFunction->mCeInnerFunctionInfo = new CeInnerFunctionInfo(); @@ -1676,10 +1675,10 @@ void CeBuilder::Build() mCeFunction->mCeInnerFunctionInfo->mBeFunction = NULL; } - SetAndRestoreValue prevBeFunction(beModule->mActiveFunction, mBeFunction); - + SetAndRestoreValue prevBeFunction(beModule->mActiveFunction, mBeFunction); + // Create blocks - for (int blockIdx = 0; blockIdx < (int)mBeFunction->mBlocks.size(); blockIdx++) + for (int blockIdx = 0; blockIdx < (int)mBeFunction->mBlocks.size(); blockIdx++) { auto beBlock = mBeFunction->mBlocks[blockIdx]; @@ -1697,17 +1696,17 @@ void CeBuilder::Build() { auto beBlock = mBeFunction->mBlocks[blockIdx]; auto& ceBlock = mBlocks[blockIdx]; - + for (int instIdx = 0; instIdx < (int)beBlock->mInstructions.size(); instIdx++) { auto inst = beBlock->mInstructions[instIdx]; - + int instType = inst->GetTypeId(); switch (instType) { case BePhiInst::TypeId: - { + { auto castedInst = (BePhiInst*)inst; auto resultType = castedInst->GetType(); @@ -1723,7 +1722,7 @@ void CeBuilder::Build() CePhiOutgoing phiOutgoing; phiOutgoing.mPhiValue = phiIncoming->mValue; phiOutgoing.mPhiInst = castedInst; - phiOutgoing.mPhiBlockIdx = blockIdx; + phiOutgoing.mPhiBlockIdx = blockIdx; incomingBlock.mPhiOutgoing.Add(phiOutgoing); } } @@ -1734,7 +1733,7 @@ void CeBuilder::Build() auto castedInst = (BeRetInst*)inst; if (castedInst->mRetValue != NULL) { - auto retType = castedInst->mRetValue->GetType(); + auto retType = castedInst->mRetValue->GetType(); mCeFunction->mMaxReturnSize = BF_MAX(retType->mSize, mCeFunction->mMaxReturnSize); } } @@ -1752,11 +1751,11 @@ void CeBuilder::Build() { auto beBlock = mBeFunction->mBlocks[blockIdx]; auto ceBlock = &mBlocks[blockIdx]; - + ceBlock->mEmitOfs = GetCodePos(); if (blockIdx == 0) - HandleParams(); + HandleParams(); for (int instIdx = 0; instIdx < (int)beBlock->mInstructions.size(); instIdx++) { @@ -1765,8 +1764,8 @@ void CeBuilder::Build() int startCodePos = GetCodePos(); - mCurDbgLoc = inst->mDbgLoc; - + mCurDbgLoc = inst->mDbgLoc; + if ((prevEmitDbgPos != mCurDbgLoc) && (mCurDbgLoc != NULL)) { auto _GetScope = [&](BeMDNode* mdNode, int inlinedAt) @@ -1775,12 +1774,12 @@ void CeBuilder::Build() BeDbgFunction* dbgFunc = NULL; String nameAdd; - while (auto dbgLexicalBlock = BeValueDynCast(mdNode)) + while (auto dbgLexicalBlock = BeValueDynCast(mdNode)) mdNode = dbgLexicalBlock->mScope; - + if (dbgFunc = BeValueDynCast(mdNode)) { - dbgFile = dbgFunc->mFile; + dbgFile = dbgFunc->mFile; } else if (auto dbgLoc = BeValueDynCast(mdNode)) dbgFile = dbgLoc->GetDbgFile(); @@ -1803,14 +1802,14 @@ void CeBuilder::Build() if (dbgFunc != NULL) { if (dbgFunc->mValue == NULL) - { + { if (!dbgFunc->mLinkageName.IsEmpty()) { int methodRefIdx = atoi(dbgFunc->mLinkageName.c_str()); dbgScope.mMethodVal = methodRefIdx | CeDbgScope::MethodValFlag_MethodRef; } else - { + { CeDbgMethodRef dbgMethodRef; dbgMethodRef.mNameMod = dbgFunc->mName; @@ -1821,7 +1820,7 @@ void CeBuilder::Build() mCeFunction->mDbgMethodRefTable.Add(dbgMethodRef); } dbgScope.mMethodVal = *valuePtr | CeDbgScope::MethodValFlag_MethodRef; - } + } } else if (dbgFunc->mValue != mBeFunction) dbgScope.mMethodVal = GetCallTableIdx(dbgFunc->mValue, NULL); @@ -1842,10 +1841,10 @@ void CeBuilder::Build() int* valuePtr = NULL; if (mDbgInlineMap.TryAdd(dbgLoc, NULL, &valuePtr)) { - CeDbgInlineEntry inlineEntry; + CeDbgInlineEntry inlineEntry; inlineEntry.mLine = dbgLoc->mLine; inlineEntry.mColumn = dbgLoc->mColumn; - + auto inlinedAt = _GetInlinedScope(dbgLoc->mDbgInlinedAt); inlineEntry.mScope = _GetScope(dbgLoc->mDbgScope, inlinedAt); @@ -1856,7 +1855,7 @@ void CeBuilder::Build() }; int inlinedAt = _GetInlinedScope(mCurDbgLoc->mDbgInlinedAt); - scopeIdx = _GetScope(mCurDbgLoc->mDbgScope, inlinedAt); + scopeIdx = _GetScope(mCurDbgLoc->mDbgScope, inlinedAt); } int instType = inst->GetTypeId(); @@ -1874,7 +1873,7 @@ void CeBuilder::Build() switch (instType) { - case BeNopInst::TypeId: + case BeNopInst::TypeId: case BeLifetimeSoftEndInst::TypeId: case BeLifetimeStartInst::TypeId: case BeLifetimeExtendInst::TypeId: @@ -1904,7 +1903,7 @@ void CeBuilder::Build() bool isAligned16 = false; int align = castedInst->mAlign; BeType* allocType = castedInst->mType; - bool preservedVolatiles = false; + bool preservedVolatiles = false; if (castedInst->mArraySize != NULL) { @@ -1914,7 +1913,7 @@ void CeBuilder::Build() ceSize.mImmediate = ceSize.mImmediate * mcArraySize.mImmediate; } else - { + { inHeadAlloca = false; if (ceSize.mImmediate == 1) { @@ -1953,12 +1952,12 @@ void CeBuilder::Build() Emit(CeOp_AdjustSPNeg); EmitFrameOffset(ceSize); } - + auto ptrType = beModule->mContext->GetPointerTo(allocType); result = FrameAlloc(ptrType); Emit(CeOp_GetSP); - EmitFrameOffset(result); + EmitFrameOffset(result); } } break; @@ -1975,11 +1974,11 @@ void CeBuilder::Build() result.mKind = CeOperandKind_FrameOfs; } else - { + { ceTarget.mKind = CeOperandKind_FrameOfs; result = FrameAlloc(ceTarget.mType); EmitSizedOp(CeOp_Move_8, ceTarget, NULL, true); - Emit((int32)result.mFrameOfs); + Emit((int32)result.mFrameOfs); } } else @@ -1987,9 +1986,9 @@ void CeBuilder::Build() BF_ASSERT(ceTarget.mType->IsPointer()); auto pointerType = (BePointerType*)ceTarget.mType; auto elemType = pointerType->mElementType; - + CeOperand refOperand = ceTarget; - refOperand.mType = elemType; + refOperand.mType = elemType; EmitSizedOp(CeOp_Load_8, refOperand, &result, true); } } @@ -2070,7 +2069,7 @@ void CeBuilder::Build() else { // Non-zero constant. Weird case, just do an actual MOV - result = FrameAlloc(toType); + result = FrameAlloc(toType); EmitSizedOp(CeOp_Const_8, result, NULL, true); int64 val = mcValue.mImmediate; Emit(&val, toType->mSize); @@ -2104,17 +2103,17 @@ void CeBuilder::Build() // For truncating values, no actual instructions are needed // Note that a copy is not needed because of SSA rules result = ceValue; - result.mType = toType; + result.mType = toType; } else - { + { result = FrameAlloc(toType); CeOp op = CeOp_InvalidOp; - + BeTypeCode fromTypeCode = fromType->mTypeCode; BeTypeCode toTypeCode = toType->mTypeCode; - + if ((castedInst->mValSigned) && (castedInst->mToSigned)) { switch (fromTypeCode) @@ -2172,7 +2171,7 @@ void CeBuilder::Build() break; case BeTypeCode_Int64: switch (toTypeCode) - { + { case BeTypeCode_Float: op = CeOp_Conv_I64_F32; break; @@ -2325,18 +2324,18 @@ void CeBuilder::Build() break; } } - + if (op == CeOp_InvalidOp) { Fail("Invalid conversion op"); } else { - Emit(op); + Emit(op); EmitFrameOffset(result); EmitFrameOffset(ceValue); - } - } + } + } } } break; @@ -2352,7 +2351,7 @@ void CeBuilder::Build() Emit((int32)mcPtr.mFrameOfs); } else - { + { EmitSizedOp(CeOp_Store_8, mcVal, NULL, true); EmitFrameOffset(mcPtr); } @@ -2360,7 +2359,7 @@ void CeBuilder::Build() break; case BeRetInst::TypeId: case BeSetRetInst::TypeId: - { + { auto castedInst = (BeRetInst*)inst; if (castedInst->mRetValue != NULL) { @@ -2382,7 +2381,7 @@ void CeBuilder::Build() Emit((int32)setRetInst->mReturnTypeId); } } - break; + break; case BeCmpInst::TypeId: { auto castedInst = (BeCmpInst*)inst; @@ -2402,7 +2401,7 @@ void CeBuilder::Build() iOp = CeOp_Cmp_NE_I8; fOp = CeOp_Cmp_NE_F32; break; - + case BeCmpKind_SLT: iOp = CeOp_Cmp_SLT_I8; fOp = CeOp_Cmp_SLT_F32; @@ -2445,15 +2444,15 @@ void CeBuilder::Build() EmitBinaryOp(iOp, fOp, ceLHS, ceRHS, result); // auto mcInst = AllocInst(BeMCInstKind_Cmp, mcLHS, mcRHS); -// +// // auto cmpResultIdx = (int)mCmpResults.size(); // BeCmpResult cmpResult; // cmpResult.mCmpKind = castedInst->mCmpKind; // mCmpResults.push_back(cmpResult); -// +// // result.mKind = BeMCOperandKind_CmpResult; // result.mCmpResultIdx = cmpResultIdx; -// +// // mcInst->mResult = result; } break; @@ -2482,7 +2481,7 @@ void CeBuilder::Build() auto arrayType = (BeSizedArrayType*)ptrType->mElementType; auto elementPtrType = beModule->mContext->GetPointerTo(arrayType->mElementType); - + if (ceIdx1.IsImmediate()) { if (ceIdx1.mImmediate == 0) @@ -2553,7 +2552,7 @@ void CeBuilder::Build() EmitFrameOffset(ofsValue); } else - { + { auto mcElementSize = FrameAlloc(mIntPtrType); Emit(CeOp_Const_64); EmitFrameOffset(mcElementSize); @@ -2564,16 +2563,16 @@ void CeBuilder::Build() EmitFrameOffset(ofsValue); EmitFrameOffset(ceIdx1); EmitFrameOffset(mcElementSize); - + Emit(CeOp_Add_I64); EmitFrameOffset(result); EmitFrameOffset(ceVal); EmitFrameOffset(ofsValue); - } + } } } else - Fail("Invalid GEP"); + Fail("Invalid GEP"); } else { @@ -2603,7 +2602,7 @@ void CeBuilder::Build() { Fail("Invalid gep target"); } - + auto elementPtrType = beModule->mContext->GetPointerTo(elementType); if (byteOffset != 0) @@ -2623,7 +2622,7 @@ void CeBuilder::Build() } } else - { + { CeOperand mcRelOffset; int relScale = 1; if (ceIdx0.IsImmediate()) @@ -2638,7 +2637,7 @@ void CeBuilder::Build() Emit((int32)byteOffset); if (mPtrSize == 8) Emit((int32)0); - } + } } else { @@ -2679,17 +2678,17 @@ void CeBuilder::Build() EmitFrameOffset(ceVal); EmitFrameOffset(ofsValue); } - } + } } } break; case BeExtractValueInst::TypeId: { auto castedInst = (BeExtractValueInst*)inst; - + BeConstant* constant = BeValueDynCast(castedInst->mAggVal); CeOperand mcAgg; - + if (constant != NULL) { result.mImmediate = 0; @@ -2773,7 +2772,7 @@ void CeBuilder::Build() byteOffset = structMember.mByteOffset; memberType = structMember.mType; } - + if (byteOffset != 0) { auto ptrVal = FrameAlloc(beModule->mContext->GetPrimitiveType(BeTypeCode_Int32)); @@ -2798,7 +2797,7 @@ void CeBuilder::Build() { auto castedInst = (BeBrInst*)inst; auto targetBlock = GetOperand(castedInst->mTargetBlock); - + BF_ASSERT(targetBlock.mKind == CeOperandKind_Block); FlushPhi(ceBlock, targetBlock.mBlockIdx); @@ -2809,7 +2808,7 @@ void CeBuilder::Build() break; } - EmitJump(CeOp_Jmp, targetBlock); + EmitJump(CeOp_Jmp, targetBlock); } break; case BeCondBrInst::TypeId: @@ -2818,15 +2817,15 @@ void CeBuilder::Build() auto testVal = GetOperand(castedInst->mCond, true); auto trueBlock = GetOperand(castedInst->mTrueBlock); auto falseBlock = GetOperand(castedInst->mFalseBlock); - + FlushPhi(ceBlock, trueBlock.mBlockIdx); - - EmitJump(CeOp_JmpIf, trueBlock); + + EmitJump(CeOp_JmpIf, trueBlock); EmitFrameOffset(testVal); FlushPhi(ceBlock, falseBlock.mBlockIdx); - EmitJump(CeOp_Jmp, falseBlock); + EmitJump(CeOp_Jmp, falseBlock); } break; case BePhiInst::TypeId: @@ -2862,21 +2861,21 @@ void CeBuilder::Build() int numVals = castedInst->mCases.size(); if (numVals > 0) - { + { EmitBinarySwitchSection(castedInst, 0, castedInst->mCases.size()); } auto mcDefaultBlock = GetOperand(castedInst->mDefaultBlock); - EmitJump(CeOp_Jmp, mcDefaultBlock); + EmitJump(CeOp_Jmp, mcDefaultBlock); } break; case BeCallInst::TypeId: { - auto castedInst = (BeCallInst*)inst; + auto castedInst = (BeCallInst*)inst; BeType* returnType = NULL; bool isVarArg = false; bool useAltArgs = false; - + CeOperand ceFunc; BeFunctionType* beFuncType = NULL; CeOperand virtTarget; @@ -2887,8 +2886,8 @@ void CeBuilder::Build() { switch (intrin->mKind) { - case BfIRIntrinsic_Abs: - EmitUnaryOp(CeOp_Abs_I8, CeOp_Abs_F32, GetOperand(castedInst->mArgs[0].mValue), result); + case BfIRIntrinsic_Abs: + EmitUnaryOp(CeOp_Abs_I8, CeOp_Abs_F32, GetOperand(castedInst->mArgs[0].mValue), result); break; case BfIRIntrinsic_Cast: { @@ -2925,7 +2924,7 @@ void CeBuilder::Build() // Nothing to do break; case BfIRIntrinsic_AtomicAdd: - EmitBinaryOp(CeOp_Add_I8, CeOp_Add_F32, GetOperand(castedInst->mArgs[0].mValue), GetOperand(castedInst->mArgs[1].mValue), result); + EmitBinaryOp(CeOp_Add_I8, CeOp_Add_F32, GetOperand(castedInst->mArgs[0].mValue), GetOperand(castedInst->mArgs[1].mValue), result); break; case BfIRIntrinsic_AtomicOr: EmitBinaryOp(CeOp_Or_I8, CeOp_InvalidOp, GetOperand(castedInst->mArgs[0].mValue), GetOperand(castedInst->mArgs[1].mValue), result); @@ -3019,7 +3018,7 @@ void CeBuilder::Build() EmitFrameOffset(arg0); EmitFrameOffset(arg1); } - + break; } } @@ -3048,7 +3047,7 @@ void CeBuilder::Build() { virtTarget = GetOperand(beGetVirtualFunc->mValue); virtualTableIdx = beGetVirtualFunc->mVirtualTableIdx; - + auto resultType = beGetVirtualFunc->GetType(); BF_ASSERT(resultType->IsPointer()); beFuncType = (BeFunctionType*)((BePointerType*)resultType)->mElementType; @@ -3065,17 +3064,17 @@ void CeBuilder::Build() } else { - ceFunc = GetOperand(castedInst->mFunc, false, true); + ceFunc = GetOperand(castedInst->mFunc, false, true); auto funcType = castedInst->mFunc->GetType(); if (funcType->IsPointer()) { auto ptrType = (BePointerType*)funcType; if (ptrType->mElementType->mTypeCode == BeTypeCode_Function) { - beFuncType = (BeFunctionType*)ptrType->mElementType; + beFuncType = (BeFunctionType*)ptrType->mElementType; } - } - } + } + } if ((ceFunc) || (virtualTableIdx != -1)) { @@ -3098,7 +3097,7 @@ void CeBuilder::Build() if (beFuncType->mReturnType->mSize > 0) { Emit(CeOp_AdjustSPConst); - Emit((int32)-beFuncType->mReturnType->mSize); + Emit((int32)-beFuncType->mReturnType->mSize); } if (!ceFunc) @@ -3119,14 +3118,14 @@ void CeBuilder::Build() EmitFrameOffset(thisOperand); Emit((int32)virtualTableIdx); } - + if (ceFunc.mKind == CeOperandKind_CallTableIdx) { CeOperand result = FrameAlloc(mCeMachine->GetBeContext()->GetPrimitiveType((sizeof(BfMethodInstance*) == 8) ? BeTypeCode_Int64 : BeTypeCode_Int32)); Emit(CeOp_GetMethod); EmitFrameOffset(result); Emit((int32)ceFunc.mCallTableIdx); - + ceFunc = result; } @@ -3151,11 +3150,11 @@ void CeBuilder::Build() { auto castedInst = (BeMemSetInst*)inst; auto ceAddr = GetOperand(castedInst->mAddr); - + if (auto constVal = BeValueDynCast(castedInst->mVal)) { if (auto constSize = BeValueDynCast(castedInst->mSize)) - { + { if (constVal->mUInt8 == 0) { Emit(CeOp_MemSet_Const); @@ -3163,7 +3162,7 @@ void CeBuilder::Build() Emit((uint8)0); Emit((int32)constSize->mUInt32); break; - } + } } } @@ -3173,16 +3172,16 @@ void CeBuilder::Build() Emit(CeOp_MemSet); EmitFrameOffset(ceAddr); EmitFrameOffset(ceVal); - EmitFrameOffset(ceSize); + EmitFrameOffset(ceSize); } break; - case BeFenceInst::TypeId: + case BeFenceInst::TypeId: break; case BeStackSaveInst::TypeId: { result = FrameAlloc(mIntPtrType); Emit(CeOp_GetSP); - EmitFrameOffset(result); + EmitFrameOffset(result); } break; case BeStackRestoreInst::TypeId: @@ -3216,7 +3215,7 @@ void CeBuilder::Build() result = FrameAlloc(ptrType); Emit(CeOp_GetReflectType); - EmitFrameOffset(result); + EmitFrameOffset(result); Emit((int32)castedInst->mTypeId); } break; @@ -3233,11 +3232,11 @@ void CeBuilder::Build() EmitFrameOffset(mcValue); Emit((int32)castedInst->mTypeId); } - break; + break; case BeDbgDeclareInst::TypeId: { auto castedInst = (BeDbgDeclareInst*)inst; - auto mcValue = GetOperand(castedInst->mValue, true); + auto mcValue = GetOperand(castedInst->mValue, true); if (mCeFunction->mDbgInfo != NULL) { @@ -3254,7 +3253,7 @@ void CeBuilder::Build() { mDbgVariableMap[castedInst->mValue] = mCeFunction->mDbgInfo->mVariables.mSize; - CeDbgVariable dbgVariable; + CeDbgVariable dbgVariable; dbgVariable.mName = castedInst->mDbgVar->mName; dbgVariable.mValue = mcValue; dbgVariable.mType = mCeMachine->mCeModule->mContext->mTypes[dbgTypeId->mTypeId]; @@ -3295,7 +3294,7 @@ void CeBuilder::Build() mValueToOperand[inst] = result; if ((startCodePos != GetCodePos()) && (prevEmitDbgPos != mCurDbgLoc)) - { + { CeEmitEntry emitEntry; emitEntry.mCodePos = startCodePos; emitEntry.mScope = scopeIdx; @@ -3316,7 +3315,7 @@ void CeBuilder::Build() emitEntry.mLine = -1; emitEntry.mColumn = -1; } - mCeFunction->mEmitTable.Add(emitEntry); + mCeFunction->mEmitTable.Add(emitEntry); prevEmitDbgPos = mCurDbgLoc; } @@ -3341,11 +3340,11 @@ void CeBuilder::Build() Fail("No method definition available"); return; } - - if (mCeFunction->mGenError.IsEmpty()) - mCeFunction->mFailed = false; - mCeFunction->mFrameSize = mFrameSize; + if (mCeFunction->mGenError.IsEmpty()) + mCeFunction->mFailed = false; + + mCeFunction->mFrameSize = mFrameSize; } ////////////////////////////////////////////////////////////////////////// @@ -3359,7 +3358,7 @@ CeContext::CeContext() mExecuteId = -1; mStackSize = -1; - mCurCallSource = NULL; + mCurCallSource = NULL; mHeap = new ContiguousHeap(); mCurFrame = NULL; mCurModule = NULL; @@ -3368,7 +3367,7 @@ CeContext::CeContext() mCallerTypeInstance = NULL; mCallerActiveTypeDef = NULL; mCurExpectingType = NULL; - mCurEmitContext = NULL; + mCurEmitContext = NULL; } CeContext::~CeContext() @@ -3403,16 +3402,16 @@ BfError* CeContext::Fail(const CeFrame& curFrame, const StringImpl& str) ((mCurEvalFlags & CeEvalFlags_DeferIfNotOnlyError) != 0) && !mCurModule->mHadBuildError); if (bfError == NULL) return NULL; - + auto passInstance = mCeMachine->mCompiler->mPassInstance; - + for (int stackIdx = mCallStack.size(); stackIdx >= 0; stackIdx--) { bool isHeadEntry = stackIdx == mCallStack.size(); auto* ceFrame = (isHeadEntry) ? &curFrame : &mCallStack[stackIdx]; - auto ceFunction = ceFrame->mFunction; - + auto ceFunction = ceFrame->mFunction; + CeEmitEntry* emitEntry = ceFunction->FindEmitEntry(ceFrame->mInstPtr - ceFunction->mCode.mVals - 1); StringT<256> err; if (isHeadEntry) @@ -3420,23 +3419,23 @@ BfError* CeContext::Fail(const CeFrame& curFrame, const StringImpl& str) err = str; err += " "; } - + auto contextMethodInstance = mCallerMethodInstance; auto contextTypeInstance = mCallerTypeInstance; if (stackIdx > 1) { auto func = mCallStack[stackIdx - 1].mFunction; - contextMethodInstance = func->mCeFunctionInfo->mMethodInstance; + contextMethodInstance = func->mCeFunctionInfo->mMethodInstance; contextTypeInstance = contextMethodInstance->GetOwner(); } auto _AddCeMethodInstance = [&](BfMethodInstance* methodInstance) { SetAndRestoreValue prevTypeInstance(mCeMachine->mCeModule->mCurTypeInstance, contextTypeInstance); - SetAndRestoreValue prevMethodInstance(mCeMachine->mCeModule->mCurMethodInstance, contextMethodInstance); - err += mCeMachine->mCeModule->MethodToString(methodInstance, BfMethodNameFlag_OmitParams); + SetAndRestoreValue prevMethodInstance(mCeMachine->mCeModule->mCurMethodInstance, contextMethodInstance); + err += mCeMachine->mCeModule->MethodToString(methodInstance, BfMethodNameFlag_OmitParams); }; - + auto _AddError = [&](const StringImpl& filePath, int line, int column) { err += StrFormat(" at line% d:%d in %s", line + 1, column + 1, filePath.c_str()); @@ -3462,14 +3461,14 @@ BfError* CeContext::Fail(const CeFrame& curFrame, const StringImpl& str) int line = emitEntry->mLine; int column = emitEntry->mColumn; - String fileName; + String fileName; if (prevInlineIdx != -1) { auto dbgInlineInfo = &ceFunction->mDbgInlineTable[prevInlineIdx]; line = dbgInlineInfo->mLine; column = dbgInlineInfo->mColumn; - } + } CeDbgScope* ceScope = &ceFunction->mDbgScopes[scopeIdx]; if (ceScope->mMethodVal == -1) @@ -3494,7 +3493,7 @@ BfError* CeContext::Fail(const CeFrame& curFrame, const StringImpl& str) } _AddError(ceFunction->mDbgScopes[emitEntry->mScope].mFilePath, line, column); - + if (ceScope->mInlinedAt == -1) break; auto inlineInfo = &ceFrame->mFunction->mDbgInlineTable[ceScope->mInlinedAt]; @@ -3510,12 +3509,12 @@ BfError* CeContext::Fail(const CeFrame& curFrame, const StringImpl& str) if (ceFunction->mMethodInstance != NULL) _AddCeMethodInstance(ceFunction->mMethodInstance); - else + else _AddCeMethodInstance(ceFunction->mCeInnerFunctionInfo->mOwner->mMethodInstance); if ((emitEntry != NULL) && (emitEntry->mScope != -1)) { - _AddError(ceFunction->mDbgScopes[emitEntry->mScope].mFilePath, emitEntry->mLine, emitEntry->mColumn); + _AddError(ceFunction->mDbgScopes[emitEntry->mScope].mFilePath, emitEntry->mLine, emitEntry->mColumn); } else { @@ -3544,7 +3543,7 @@ void CeContext::CalcWorkingDir() void CeContext::FixRelativePath(StringImpl& path) { - CalcWorkingDir(); + CalcWorkingDir(); if (!mWorkingDir.IsEmpty()) path = GetAbsPath(path, mWorkingDir); } @@ -3586,7 +3585,7 @@ void CeContext::AddFileRebuild(const StringImpl& path) uint8* CeContext::CeMalloc(int size) { #ifdef CE_ENABLE_HEAP - auto heapRef = mHeap->Alloc(size); + auto heapRef = mHeap->Alloc(size); auto ceAddr = mStackSize + heapRef; int sizeDelta = (ceAddr + size) - mMemory.mSize; if (sizeDelta > 0) @@ -3613,7 +3612,7 @@ addr_ce CeContext::CeAllocArray(BfArrayType* arrayType, int count, addr_ce& elem BfType* elemType = arrayType->GetUnderlyingType(); auto countOffset = arrayType->mBaseType->mFieldInstances[0].mDataOffset; - auto elemOffset = arrayType->mFieldInstances[0].mDataOffset; + auto elemOffset = arrayType->mFieldInstances[0].mDataOffset; int allocSize = elemOffset + elemType->GetStride() * count; @@ -3654,7 +3653,7 @@ addr_ce CeContext::GetReflectType(int typeId) return *addrPtr; auto ceModule = mCeMachine->mCeModule; - SetAndRestoreValue ignoreWrites(ceModule->mBfIRBuilder->mIgnoreWrites, false); + SetAndRestoreValue ignoreWrites(ceModule->mBfIRBuilder->mIgnoreWrites, false); if (ceModule->mContext->mBfTypeType == NULL) ceModule->mContext->ReflectInit(); @@ -3669,8 +3668,8 @@ addr_ce CeContext::GetReflectType(int typeId) ceModule->PopulateType(bfType, BfPopulateType_DataAndMethods); Dictionary usedStringMap; - auto irData = ceModule->CreateTypeData(bfType, usedStringMap, true, true, true, false); - + auto irData = ceModule->CreateTypeData(bfType, usedStringMap, true, true, true, false); + BeValue* beValue = NULL; if (auto constant = mCeMachine->mCeModule->mBfIRBuilder->GetConstant(irData)) { @@ -3689,7 +3688,7 @@ addr_ce CeContext::GetReflectType(int typeId) if (auto constant = BeValueDynCast(beValue)) *addrPtr = GetConstantData(constant); - // We need to 'get' again because we might have resized + // We need to 'get' again because we might have resized return *addrPtr; } @@ -3790,11 +3789,11 @@ addr_ce CeContext::GetReflectSpecializedType(addr_ce unspecializedTypeAddr, addr } addr_ce CeContext::GetString(int stringId) -{ +{ addr_ce* ceAddrPtr = NULL; if (!mStringMap.TryAdd(stringId, NULL, &ceAddrPtr)) return *ceAddrPtr; - + BfTypeInstance* stringTypeInst = (BfTypeInstance*)mCeMachine->mCeModule->ResolveTypeDef(mCeMachine->mCompiler->mStringTypeDef, BfPopulateType_Data); String str; @@ -3806,9 +3805,9 @@ addr_ce CeContext::GetString(int stringId) } int allocSize = stringTypeInst->mInstSize + (int)str.length() + 1; - int charsOffset = stringTypeInst->mInstSize; - - uint8* mem = CeMalloc(allocSize); + int charsOffset = stringTypeInst->mInstSize; + + uint8* mem = CeMalloc(allocSize); memset(mem, 0, allocSize); @@ -3856,7 +3855,7 @@ void CeContext::PrepareConstStructEntry(CeConstStructData& constEntry) if (constEntry.mHash.IsZero()) { constEntry.mHash = Hash128(constEntry.mData.mVals, constEntry.mData.mSize); - if (!constEntry.mFixups.IsEmpty()) + if (!constEntry.mFixups.IsEmpty()) constEntry.mHash = Hash128(&constEntry.mFixups[0], constEntry.mFixups.mSize * sizeof(CeConstStructFixup), constEntry.mHash); } @@ -3880,14 +3879,14 @@ void CeContext::PrepareConstStructEntry(CeConstStructData& constEntry) *(addr_ce*)(constEntry.mFixedData.mVals + fixup.mOffset) = addrPtr + stringTypeInst->mInstSize; } } - } + } constEntry.mBindExecuteId = mExecuteId; } bool CeContext::CheckMemory(addr_ce addr, int32 size) { - if ((addr < 0x10000) || (addr + size > mMemory.mSize)) + if ((addr < 0x10000) || (addr + size > mMemory.mSize)) return false; return true; } @@ -3944,7 +3943,7 @@ bool CeContext::GetStringFromAddr(addr_ce strInstAddr, StringImpl& str) } int32 ptrVal = *(int32*)(strInst + ptrOffset); - + if (charPtr != NULL) str.Insert(str.length(), charPtr, lenVal); return true; @@ -3977,9 +3976,9 @@ bool CeContext::GetCustomAttribute(BfModule* module, BfIRConstHolder* constHolde auto customAttr = customAttributes->Get(attributeIdx); if (customAttr == NULL) return false; - + auto ceContext = mCeMachine->AllocContext(); - BfIRValue foreignValue = ceContext->CreateAttribute(mCurCallSource->mRefNode, module, constHolder, customAttr); + BfIRValue foreignValue = ceContext->CreateAttribute(mCurCallSource->mRefNode, module, constHolder, customAttr); auto foreignConstant = module->mBfIRBuilder->GetConstant(foreignValue); if (foreignConstant->mConstType == BfConstType_AggCE) { @@ -3990,7 +3989,7 @@ bool CeContext::GetCustomAttribute(BfModule* module, BfIRConstHolder* constHolde auto attrConstant = module->mBfIRBuilder->GetConstant(value); if ((attrConstant == NULL) || (!WriteConstant(module, resultAddr, attrConstant, customAttr->mType))) Fail("Failed to decode attribute"); - } + } mCeMachine->ReleaseContext(ceContext); @@ -4005,7 +4004,7 @@ BfType* CeContext::GetCustomAttributeType(BfCustomAttributes* customAttributes, auto customAttr = customAttributes->Get(attributeIdx); if (customAttr == NULL) return NULL; - + return customAttr->mType; } @@ -4088,7 +4087,7 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta auto elemType = type->GetUnderlyingType(); addr_ce elemsAddr = 0; - addr_ce arrayAddr = CeAllocArray((BfArrayType*)type, aggConstant->mValues.size(), elemsAddr); + addr_ce arrayAddr = CeAllocArray((BfArrayType*)type, aggConstant->mValues.size(), elemsAddr); for (int i = 0; i < (int)aggConstant->mValues.size(); i++) { @@ -4098,14 +4097,14 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta if (!WriteConstant(module, elemsAddr + i * elemType->GetStride(), fieldConstant, elemType)) return false; } - + if (ptrSize == 4) CE_GETC(int32) = arrayAddr; else CE_GETC(int64) = arrayAddr; return true; - } + } else if ((type->IsInstanceOf(module->mCompiler->mSpanTypeDef)) && (isParams)) { auto elemType = type->GetUnderlyingType(); @@ -4134,7 +4133,7 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta } } else - { + { BF_ASSERT(type->IsStruct()); module->PopulateType(type); @@ -4168,7 +4167,7 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta auto fieldDef = fieldInstance.GetFieldDef(); if (!fieldInstance.mIsEnumPayloadCase) continue; - int tagIdx = -fieldInstance.mDataIdx - 1; + int tagIdx = -fieldInstance.mDataIdx - 1; if (fieldConstant->mInt32 == tagIdx) payloadType = fieldInstance.mResolvedType; } @@ -4190,7 +4189,7 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta return false; innerType = payloadType; } - + auto fieldConstant = module->mBfIRBuilder->GetConstant(dataVal); if (fieldConstant == NULL) return false; @@ -4225,7 +4224,7 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta } if (constant->mConstType == BfConstType_ArrayZero8) - { + { memset(mMemory.mVals + addr, 0, constant->mInt32); return true; } @@ -4241,7 +4240,7 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta auto constAggData = (BfConstantAggCE*)constant; if (type->IsPointer()) - { + { if (ptrSize == 4) CE_GETC(int32) = constAggData->mCEAddr; else @@ -4249,7 +4248,7 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta } else { - BF_ASSERT(type->IsComposite()); + BF_ASSERT(type->IsComposite()); memcpy(mMemory.mVals + addr, mMemory.mVals + constAggData->mCEAddr, type->mSize); } return true; @@ -4264,7 +4263,7 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta if (constant->mConstType == BfConstType_Box) { - auto constBox = (BfConstantBox*)constant; + auto constBox = (BfConstantBox*)constant; auto boxedType = GetBfType(constBox->mToType); if (boxedType == NULL) return false; @@ -4277,7 +4276,7 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta auto& fieldInstance = boxedTypeInst->mFieldInstances.back(); auto boxedMem = CeMalloc(boxedTypeInst->mInstSize); - memset(boxedMem, 0, ptrSize*2); + memset(boxedMem, 0, ptrSize*2); *(int32*)boxedMem = boxedTypeInst->mTypeId; auto constTarget = module->mBfIRBuilder->GetConstantById(constBox->mTarget); @@ -4313,7 +4312,7 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta memset(mMemory.mVals + addr, 0, type->mSize); return true; } - + if (constant->mConstType == BfConstType_GEP32_2) { auto gepConst = (BfConstantGEP32_2*)constant; @@ -4342,7 +4341,7 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta if (strncmp(globalVar->mName, "__bfStrObj", 10) == 0) { int stringId = atoi(globalVar->mName + 10); - addr_ce strAddr = GetString(stringId); + addr_ce strAddr = GetString(stringId); if (ptrSize == 4) CE_GETC(int32) = strAddr; else @@ -4352,7 +4351,7 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta } if (constant->mTypeCode == BfTypeCode_StringId) - { + { addr_ce strAddr = GetString(constant->mInt32); if (type->IsPointer()) @@ -4382,7 +4381,7 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta if (constant->mConstType == BfConstType_ExtractValue) { Array extractStack; - auto checkConstant = constant; + auto checkConstant = constant; while (true) { if (checkConstant == NULL) @@ -4399,13 +4398,12 @@ bool CeContext::WriteConstant(BfModule* module, addr_ce addr, BfConstant* consta if (checkConstant->mConstType == BfConstType_AggCE) return WriteConstant(module, addr, checkConstant, type, isParams); - } - } + } + } return false; } - #define CE_CREATECONST_CHECKPTR(PTR, SIZE) \ if ((((uint8*)(PTR) - memStart) - 0x10000) + (SIZE) > (memSize - 0x10000)) \ { \ @@ -4472,7 +4470,7 @@ BfIRValue CeContext::CreateConstant(BfModule* module, uint8* ptr, BfType* bfType return BfIRValue(); } - + if (bfType->IsTypedPrimitive()) return CreateConstant(module, ptr, bfType->GetUnderlyingType(), outType); @@ -4482,7 +4480,7 @@ BfIRValue CeContext::CreateConstant(BfModule* module, uint8* ptr, BfType* bfType if (bfType->IsTypeInstance()) { auto typeInst = bfType->ToTypeInstance(); - + uint8* instData = ptr; // if ((typeInst->IsObject()) && (!isBaseType)) // { @@ -4626,15 +4624,15 @@ BfIRValue CeContext::CreateConstant(BfModule* module, uint8* ptr, BfType* bfType Fail(StrFormat("Reference type '%s' return value not allowed", module->TypeToString(typeInst).c_str())); return BfIRValue(); } - + if (typeInst->mBaseType != NULL) { auto result = CreateConstant(module, instData, typeInst->mBaseType); if (!result) return BfIRValue(); fieldVals.Add(result); - } - + } + if (typeInst->IsUnion()) { auto innerType = typeInst->GetUnionInnerType(); @@ -4681,7 +4679,7 @@ BfIRValue CeContext::CreateConstant(BfModule* module, uint8* ptr, BfType* bfType } } } - + for (auto& fieldVal : fieldVals) { if (!fieldVal) @@ -4708,7 +4706,7 @@ BfIRValue CeContext::CreateConstant(BfModule* module, uint8* ptr, BfType* bfType if (!elemValue) return BfIRValue(); values.Add(elemValue); - } + } return irBuilder->CreateConstAgg(irBuilder->MapType(sizedArrayType, BfIRPopulateType_Full), values); } @@ -4722,7 +4720,7 @@ BfIRValue CeContext::CreateAttribute(BfAstNode* targetSrc, BfModule* module, BfI module->mContext->mUnreifiedModule->PopulateType(customAttribute->mType); if (ceAttrAddr == 0) - ceAttrAddr = CeMalloc(customAttribute->mType->mSize) - mMemory.mVals; + ceAttrAddr = CeMalloc(customAttribute->mType->mSize) - mMemory.mVals; BfIRValue ceAttrVal = module->mBfIRBuilder->CreateConstAggCE(module->mBfIRBuilder->MapType(customAttribute->mType, BfIRPopulateType_Identity), ceAttrAddr); BfTypedValue ceAttrTypedValue(ceAttrVal, customAttribute->mType); @@ -4766,10 +4764,10 @@ BfIRValue CeContext::CreateAttribute(BfAstNode* targetSrc, BfModule* module, BfI module->Fail("Attribute prop failed", targetSrc); return ceAttrVal; } - + SizedArray setArgs; if (!customAttribute->mType->IsValuelessType()) - setArgs.Add(ceAttrVal); + setArgs.Add(ceAttrVal); if (!setProperty.mParam.mType->IsValuelessType()) { auto constant = constHolder->GetConstant(setProperty.mParam.mValue); @@ -4777,7 +4775,7 @@ BfIRValue CeContext::CreateAttribute(BfAstNode* targetSrc, BfModule* module, BfI { module->AssertErrorState(); return ceAttrVal; - } + } setArgs.Add(module->ConstantToCurrent(constant, constHolder, setProperty.mParam.mType, true)); } @@ -4790,7 +4788,7 @@ BfIRValue CeContext::CreateAttribute(BfAstNode* targetSrc, BfModule* module, BfI { BfFieldInstance* fieldInstance = setField.mFieldRef; if (fieldInstance->mDataOffset < 0) - continue; + continue; auto constant = constHolder->GetConstant(setField.mParam.mValue); WriteConstant(module, ceAttrAddr + fieldInstance->mDataOffset, constant, fieldInstance->mResolvedType); } @@ -4798,7 +4796,6 @@ BfIRValue CeContext::CreateAttribute(BfAstNode* targetSrc, BfModule* module, BfI return ceAttrVal; } - BfTypedValue CeContext::Call(CeCallSource callSource, BfModule* module, BfMethodInstance* methodInstance, const BfSizedArray& args, CeEvalFlags flags, BfType* expectingType) { // DISABLED @@ -4815,19 +4812,19 @@ BfTypedValue CeContext::Call(CeCallSource callSource, BfModule* module, BfMethod SetAndRestoreValue prevCallerMethodInstance(mCallerMethodInstance, module->mCurMethodInstance); SetAndRestoreValue prevCallerTypeInstance(mCallerTypeInstance, module->mCurTypeInstance); SetAndRestoreValue prevCallerActiveTypeDef(mCallerActiveTypeDef, module->GetActiveTypeDef()); - SetAndRestoreValue prevExpectingType(mCurExpectingType, expectingType); - + SetAndRestoreValue prevExpectingType(mCurExpectingType, expectingType); + SetAndRestoreValue prevCtxResolvingVar(module->mContext->mResolvingVarField, false); SetAndRestoreValue moduleCurMethodInstance(module->mCurMethodInstance, methodInstance); - SetAndRestoreValue moduleCurTypeInstance(module->mCurTypeInstance, methodInstance->GetOwner()); + SetAndRestoreValue moduleCurTypeInstance(module->mCurTypeInstance, methodInstance->GetOwner()); - SetAndRestoreValue prevCurExecuteId(mCurModule->mCompiler->mCurCEExecuteId, mCeMachine->mExecuteId); + SetAndRestoreValue prevCurExecuteId(mCurModule->mCompiler->mCurCEExecuteId, mCeMachine->mExecuteId); // Reentrancy may occur as methods need defining //SetAndRestoreValue prevMethodStateInConstEval(module->mCurMethodState, NULL); if (mCeMachine->mAppendAllocInfo != NULL) - { + { if (mCeMachine->mAppendAllocInfo->mAppendSizeValue) { bool isConst = mCeMachine->mAppendAllocInfo->mAppendSizeValue.IsConst(); @@ -4850,7 +4847,7 @@ BfTypedValue CeContext::Call(CeCallSource callSource, BfModule* module, BfMethod int appendAllocIdx = -1; bool hasAggData = false; if (!methodInstance->mMethodDef->mIsStatic) - { + { if (!methodInstance->GetOwner()->IsValuelessType()) { thisArgIdx = 0; @@ -4864,7 +4861,7 @@ BfTypedValue CeContext::Call(CeCallSource callSource, BfModule* module, BfMethod } if (checkConstant->mConstType == BfConstType_ExtractValue) - { + { auto gepConst = (BfConstantExtractValue*)checkConstant; BfIRValue targetConst(BfIRValueFlags_Const, gepConst->mTarget); checkConstant = module->mBfIRBuilder->GetConstant(targetConst); @@ -4876,7 +4873,7 @@ BfTypedValue CeContext::Call(CeCallSource callSource, BfModule* module, BfMethod } if ((methodInstance->GetParamCount() >= 1) && (methodInstance->GetParamKind(0) == BfParamKind_AppendIdx)) - appendAllocIdx = 1; + appendAllocIdx = 1; } int paramCompositeSize = 0; @@ -4893,9 +4890,9 @@ BfTypedValue CeContext::Call(CeCallSource callSource, BfModule* module, BfMethod if ((!paramType->IsValuelessType()) && (!paramType->IsVar())) break; } - - BfType* compositeType = paramType->IsComposite() ? paramType : NULL; - + + BfType* compositeType = paramType->IsComposite() ? paramType : NULL; + auto arg = args[argIdx]; bool isConst = arg.IsConst(); if (isConst) @@ -4948,7 +4945,7 @@ BfTypedValue CeContext::Call(CeCallSource callSource, BfModule* module, BfMethod if (ceFunction->mInitializeState == CeFunction::InitializeState_Initializing_ReEntry) { - String error = "Comptime method preparation recursion"; + String error = "Comptime method preparation recursion"; auto curContext = this; while (curContext != NULL) { @@ -4964,9 +4961,9 @@ BfTypedValue CeContext::Call(CeCallSource callSource, BfModule* module, BfMethod } if (ceFunction->mInitializeState < CeFunction::InitializeState_Initialized) - mCeMachine->PrepareFunction(ceFunction, NULL); + mCeMachine->PrepareFunction(ceFunction, NULL); - Array prevCallStack; + Array prevCallStack; auto stackPtr = &mMemory[0] + mStackSize; auto* memStart = &mMemory[0]; @@ -4974,7 +4971,7 @@ BfTypedValue CeContext::Call(CeCallSource callSource, BfModule* module, BfMethod if (!mCallStack.IsEmpty()) { BF_ASSERT((flags & CeEvalFlags_DbgCall) != 0); - prevCallStack = mCallStack; + prevCallStack = mCallStack; stackPtr = &mMemory[0] + mCallStack.back().mStackAddr; mCallStack.Clear(); } @@ -5009,7 +5006,7 @@ BfTypedValue CeContext::Call(CeCallSource callSource, BfModule* module, BfMethod Fail("Return value too large (>2GB)"); return BfTypedValue(); } - + if (memSize > mMemory.mSize) mMemory.Resize(memSize); stackPtr = &mMemory[0] + mStackSize; @@ -5089,12 +5086,12 @@ BfTypedValue CeContext::Call(CeCallSource callSource, BfModule* module, BfMethod } auto constant = module->mBfIRBuilder->GetConstant(arg); - BfType* compositeType = paramType->IsComposite() ? paramType : NULL; + BfType* compositeType = paramType->IsComposite() ? paramType : NULL; if (((constant->mConstType == BfConstType_AggZero) || (constant->mConstType == BfConstType_Agg)) && ((paramType->IsPointer()) || (paramType->IsRef()))) compositeType = paramType->GetUnderlyingType(); if (compositeType != NULL) - { + { useCompositeAddr -= compositeType->mSize; if (!WriteConstant(module, useCompositeAddr, constant, compositeType, isParams)) { @@ -5108,9 +5105,9 @@ BfTypedValue CeContext::Call(CeCallSource callSource, BfModule* module, BfMethod if (argIdx == thisArgIdx) thisAddr = addr64; memcpy(stackPtr, &addr64, ceModule->mSystem->mPtrSize); - } + } else - { + { stackPtr -= paramType->mSize; auto useCompositeAddr = stackPtr - memStart; if (!WriteConstant(module, useCompositeAddr, constant, paramType, isParams)) @@ -5227,7 +5224,7 @@ BfTypedValue CeContext::Call(CeCallSource callSource, BfModule* module, BfMethod else if ((returnType->IsComposite()) || (returnType->IsValuelessType())) { returnValue = BfTypedValue(module->mBfIRBuilder->CreateConstAggZero(module->mBfIRBuilder->MapType(returnType, BfIRPopulateType_Identity)), returnType); - } + } } mCallStack.Clear(); @@ -5546,7 +5543,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* stackPtr += memOffset; framePtr += memOffset; }; - + auto _DbgPause = [&]() { int itr = 0; @@ -5565,41 +5562,40 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* /// { AutoCrit autoCrit(mCeMachine->mCritSect); - + if ((mCeMachine->mDebugger->mDebugPendingExpr != NULL) && (itr == 0)) { // Abandon evaluating expression - prevPendingExpr = mCeMachine->mDebugger->mDebugPendingExpr; + prevPendingExpr = mCeMachine->mDebugger->mDebugPendingExpr; mCeMachine->mDebugger->mDebugPendingExpr = NULL; } if (itr == 0) mCallStack.Add(_GetCurFrame()); - mCeMachine->mDbgPaused = true; + mCeMachine->mDbgPaused = true; } - - + mCeMachine->mDebugEvent.WaitFor(); - + CePendingExpr* pendingExpr = NULL; /// { AutoCrit autoCrit(mCeMachine->mCritSect); mCeMachine->mDbgPaused = false; - + if (mCeMachine->mStepState.mKind != CeStepState::Kind_Evaluate) { mCallStack.pop_back(); _FixVariables(); break; } - + mCeMachine->mStepState.mKind = CeStepState::Kind_None; String result; - if (mCeMachine->mDebugger->mDebugPendingExpr != NULL) - pendingExpr = mCeMachine->mDebugger->mDebugPendingExpr; - } + if (mCeMachine->mDebugger->mDebugPendingExpr != NULL) + pendingExpr = mCeMachine->mDebugger->mDebugPendingExpr; + } if (pendingExpr == NULL) continue;; @@ -5680,7 +5676,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* else size = *(int64*)((uint8*)stackPtr + 8); CE_CHECKALLOC(size); - uint8* ptr = CeMalloc(size); + uint8* ptr = CeMalloc(size); CeSetAddrVal(stackPtr + 0, ptr - memStart, ptrSize); } else if (checkFunction->mFunctionKind == CeFunctionKind_Free) @@ -5692,7 +5688,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* } else if (checkFunction->mFunctionKind == CeFunctionKind_FatalError) { - int32 strInstAddr = *(int32*)((uint8*)stackPtr + 0); + int32 strInstAddr = *(int32*)((uint8*)stackPtr + 0); int32 stackOffset = *(int32*)(stackPtr + ceModule->mSystem->mPtrSize); if (mCeMachine->mDebugger != NULL) @@ -5751,7 +5747,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* int32 typeId = *(int32*)((uint8*)stackPtr + ceModule->mSystem->mPtrSize); auto reflectType = GetReflectType(typeId); _FixVariables(); - CeSetAddrVal(stackPtr + 0, reflectType, ptrSize); + CeSetAddrVal(stackPtr + 0, reflectType, ptrSize); } else if (checkFunction->mFunctionKind == CeFunctionKind_GetReflectTypeByName) { @@ -5776,9 +5772,9 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* CeSetAddrVal(stackPtr + 0, reflectType, ptrSize); } else if (checkFunction->mFunctionKind == CeFunctionKind_Type_ToString) - { + { int32 typeId = *(int32*)((uint8*)stackPtr + ptrSize); - + BfType* type = GetBfType(typeId); bool success = false; if (type == NULL) @@ -5786,7 +5782,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* _Fail("Invalid type"); return false; } - + SetAndRestoreValue prevMethodInstance(mCeMachine->mCeModule->mCurMethodInstance, mCallerMethodInstance); SetAndRestoreValue prevTypeInstance(mCeMachine->mCeModule->mCurTypeInstance, mCallerTypeInstance); CeSetAddrVal(stackPtr + 0, GetString(mCeMachine->mCeModule->TypeToString(type)), ptrSize); @@ -5844,17 +5840,17 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* } else if (checkFunction->mFunctionKind == CeFunctionKind_Method_GetCustomAttribute) { - int64 methodHandle = *(int64*)((uint8*)stackPtr + 1); + int64 methodHandle = *(int64*)((uint8*)stackPtr + 1); int32 attributeIdx = *(int32*)((uint8*)stackPtr + 1 + 8); - addr_ce resultPtr = *(addr_ce*)((uint8*)stackPtr + 1 + 8 + 4); + addr_ce resultPtr = *(addr_ce*)((uint8*)stackPtr + 1 + 8 + 4); auto methodInstance = mCeMachine->GetMethodInstance(methodHandle); if (methodInstance == NULL) { _Fail("Invalid method instance"); return false; - } - bool success = GetCustomAttribute(mCurModule, methodInstance->GetOwner()->mConstHolder, methodInstance->GetCustomAttributes(), attributeIdx, resultPtr); + } + bool success = GetCustomAttribute(mCurModule, methodInstance->GetOwner()->mConstHolder, methodInstance->GetCustomAttributes(), attributeIdx, resultPtr); _FixVariables(); *(addr_ce*)(stackPtr + 0) = success; } @@ -5914,15 +5910,15 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* } else if (checkFunction->mFunctionKind == CeFunctionKind_Method_GetCustomAttributeType) { - int64 methodHandle = *(int64*)((uint8*)stackPtr + ptrSize); - int32 attributeIdx = *(int32*)((uint8*)stackPtr + ptrSize + 8); + int64 methodHandle = *(int64*)((uint8*)stackPtr + ptrSize); + int32 attributeIdx = *(int32*)((uint8*)stackPtr + ptrSize + 8); auto methodInstance = mCeMachine->GetMethodInstance(methodHandle); if (methodInstance == NULL) { _Fail("Invalid method instance"); return false; - } + } auto attrType = GetCustomAttributeType(methodInstance->GetCustomAttributes(), attributeIdx); if (attrType != NULL) CeSetAddrVal(stackPtr + 0, GetReflectType(attrType->mTypeId), ptrSize); @@ -5933,8 +5929,8 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* else if (checkFunction->mFunctionKind == CeFunctionKind_GetMethodCount) { int32 typeId = *(int32*)((uint8*)stackPtr + 4); - - CeTypeInfo* typeInfo = mCeMachine->GetTypeInfo(GetBfType(typeId)); + + CeTypeInfo* typeInfo = mCeMachine->GetTypeInfo(GetBfType(typeId)); if (typeInfo == NULL) { _Fail("Invalid type"); @@ -5947,8 +5943,8 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* { int32 typeId = *(int32*)((uint8*)stackPtr + 8); int32 methodIdx = *(int32*)((uint8*)stackPtr + 8+4); - - CeTypeInfo* typeInfo = mCeMachine->GetTypeInfo(GetBfType(typeId)); + + CeTypeInfo* typeInfo = mCeMachine->GetTypeInfo(GetBfType(typeId)); if (typeInfo == NULL) { _Fail("Invalid type"); @@ -5962,35 +5958,35 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* *(int64*)(stackPtr + 0) = (int64)(intptr)typeInfo->mMethodInstances[methodIdx]; } else if (checkFunction->mFunctionKind == CeFunctionKind_Method_ToString) - { + { int64 methodHandle = *(int64*)((uint8*)stackPtr + ptrSize); - + auto methodInstance = mCeMachine->GetMethodInstance(methodHandle); if (methodInstance == NULL) { _Fail("Invalid method instance"); return false; } - + CeSetAddrVal(stackPtr + 0, GetString(mCeMachine->mCeModule->MethodToString(methodInstance)), ptrSize); _FixVariables(); } else if (checkFunction->mFunctionKind == CeFunctionKind_Method_GetName) - { + { int64 methodHandle = *(int64*)((uint8*)stackPtr + ptrSize); - + auto methodInstance = mCeMachine->GetMethodInstance(methodHandle); if (methodInstance == NULL) { _Fail("Invalid method instance"); return false; } - + CeSetAddrVal(stackPtr + 0, GetString(methodInstance->mMethodDef->mName), ptrSize); _FixVariables(); } - else if (checkFunction->mFunctionKind == CeFunctionKind_Method_GetInfo) - { + else if (checkFunction->mFunctionKind == CeFunctionKind_Method_GetInfo) + { // int32 mReturnType // int32 mParamCount // int32 mGenericArgCount @@ -5998,14 +5994,14 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* // int32 mMethodIdx int64 methodHandle = *(int64*)((uint8*)stackPtr + 4+4+4+2+4); - + auto methodInstance = mCeMachine->GetMethodInstance(methodHandle); if (methodInstance == NULL) { _Fail("Invalid method instance"); return false; } - + int genericArgCount = 0; if (methodInstance->mMethodInfoEx != NULL) genericArgCount = methodInstance->mMethodInfoEx->mMethodGenericArguments.mSize; @@ -6017,14 +6013,14 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* *(int32*)(stackPtr + 4+4+4+2) = methodInstance->mMethodDef->mIdx; } else if (checkFunction->mFunctionKind == CeFunctionKind_Method_GetParamInfo) - { - // int32 mParamType + { + // int32 mParamType // int16 mFlags // str mName int64 methodHandle = *(int64*)((uint8*)stackPtr + 4+2+ptrSize); int32 paramIdx = *(int32*)((uint8*)stackPtr + 4+2+ptrSize+8); - + auto methodInstance = mCeMachine->GetMethodInstance(methodHandle); if (methodInstance == NULL) { @@ -6037,7 +6033,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* _Fail("paramIdx is out of range"); return false; } - + enum ParamFlags { ParamFlag_None = 0, @@ -6059,13 +6055,13 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* _FixVariables(); *(int32*)(stackPtr + 0) = methodInstance->GetParamType(paramIdx)->mTypeId; *(int16*)(stackPtr + 4) = (int16)paramFlags; - CeSetAddrVal(stackPtr + 4+2, stringAddr, ptrSize); + CeSetAddrVal(stackPtr + 4+2, stringAddr, ptrSize); } else if (checkFunction->mFunctionKind == CeFunctionKind_Method_GetGenericArg) { int64 methodHandle = *(int64*)((uint8*)stackPtr + ptrSize); int32 genericArgIdx = *(int32*)((uint8*)stackPtr + ptrSize + 8); - + auto methodInstance = mCeMachine->GetMethodInstance(methodHandle); if (methodInstance == NULL) { @@ -6078,7 +6074,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* _Fail("genericArgIdx is out of range"); return false; } - + auto reflectType = GetReflectType(methodInstance->mMethodInfoEx->mMethodGenericArguments[genericArgIdx]->mTypeId); _FixVariables(); CeSetAddrVal(stackPtr + 0, reflectType, ptrSize); @@ -6109,7 +6105,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* else if (checkFunction->mFunctionKind == CeFunctionKind_EmitAddInterface) { int32 typeId = *(int32*)((uint8*)stackPtr); - int32 ifaceTypeId = *(int32*)((uint8*)stackPtr + sizeof(int32)); + int32 ifaceTypeId = *(int32*)((uint8*)stackPtr + sizeof(int32)); if ((mCurEmitContext == NULL) || (mCurEmitContext->mType->mTypeId != typeId)) { _Fail("Code cannot be emitted for this type in this context"); @@ -6150,12 +6146,12 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* return false; } } - else if (checkFunction->mFunctionKind == CeFunctionKind_EmitMixin) + else if (checkFunction->mFunctionKind == CeFunctionKind_EmitMixin) { SetAndRestoreValue prevMethodInstance(mCurModule->mCurMethodInstance, mCallerMethodInstance); SetAndRestoreValue prevTypeInstance(mCurModule->mCurTypeInstance, mCallerTypeInstance); -// int32 strInstAddr = *(int32*)((uint8*)stackPtr + 0); +// int32 strInstAddr = *(int32*)((uint8*)stackPtr + 0); // String emitStr; // if (!GetStringFromAddr(strInstAddr, emitStr)) // { @@ -6194,38 +6190,38 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* else if (checkFunction->mFunctionKind == CeFunctionKind_BfpSystem_GetTimeStamp) { int64& result = *(int64*)((uint8*)stackPtr + 0); - result = BfpSystem_GetTimeStamp(); + result = BfpSystem_GetTimeStamp(); } else if (checkFunction->mFunctionKind == CeFunctionKind_Char32_ToLower) { int32& result = *(int32*)((uint8*)stackPtr + 0); int32 val = *(int32*)((uint8*)stackPtr + 4); - result = utf8proc_tolower(val); + result = utf8proc_tolower(val); } else if (checkFunction->mFunctionKind == CeFunctionKind_Char32_ToUpper) { int32& result = *(int32*)((uint8*)stackPtr + 0); int32 val = *(int32*)((uint8*)stackPtr + 4); - result = utf8proc_toupper(val); + result = utf8proc_toupper(val); } else if (checkFunction->mFunctionKind == CeFunctionKind_Char32_IsLower) { int32& result = *(int32*)((uint8*)stackPtr + 0); int32 val = *(int32*)((uint8*)stackPtr + 1); - result = utf8proc_category(val) == UTF8PROC_CATEGORY_LL; + result = utf8proc_category(val) == UTF8PROC_CATEGORY_LL; } else if (checkFunction->mFunctionKind == CeFunctionKind_Char32_IsUpper) { int32& result = *(int32*)((uint8*)stackPtr + 0); int32 val = *(int32*)((uint8*)stackPtr + 1); - result = utf8proc_category(val) == UTF8PROC_CATEGORY_LU; + result = utf8proc_category(val) == UTF8PROC_CATEGORY_LU; } else if (checkFunction->mFunctionKind == CeFunctionKind_Char32_IsWhiteSpace_EX) { int32& result = *(int32*)((uint8*)stackPtr + 0); int32 val = *(int32*)((uint8*)stackPtr + 1); auto cat = utf8proc_category(val); - result = (cat == UTF8PROC_CATEGORY_ZS) || (cat == UTF8PROC_CATEGORY_ZL) || (cat == UTF8PROC_CATEGORY_ZP); + result = (cat == UTF8PROC_CATEGORY_ZS) || (cat == UTF8PROC_CATEGORY_ZL) || (cat == UTF8PROC_CATEGORY_ZP); } else if (checkFunction->mFunctionKind == CeFunctionKind_Char32_IsLetterOrDigit) { @@ -6246,7 +6242,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* break; default: result = false; - } + } } else if (checkFunction->mFunctionKind == CeFunctionKind_Char32_IsLetter) { @@ -6264,7 +6260,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* break; default: result = false; - } + } } else if (checkFunction->mFunctionKind == CeFunctionKind_Char32_IsNumber) { @@ -6280,15 +6276,15 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* break; default: result = false; - } + } } else if (checkFunction->mFunctionKind == CeFunctionKind_Double_Strtod) { double& result = *(double*)((uint8*)stackPtr + 0); addr_ce strAddr = *(addr_ce*)((uint8*)stackPtr + 8); addr_ce endAddr = *(addr_ce*)((uint8*)stackPtr + 8 + ptrSize); - - addr_ce checkAddr = strAddr; + + addr_ce checkAddr = strAddr; while (true) { if ((uintptr)checkAddr >= (uintptr)memSize) @@ -6351,7 +6347,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* } else if (checkFunction->mFunctionKind == CeFunctionKind_BfpDirectory_Create) { - addr_ce nameAddr = *(addr_ce*)((uint8*)stackPtr + 0); + addr_ce nameAddr = *(addr_ce*)((uint8*)stackPtr + 0); addr_ce outResultAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize); if (outResultAddr != 0) CE_CHECKADDR(outResultAddr, 4); @@ -6379,7 +6375,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* } else if (checkFunction->mFunctionKind == CeFunctionKind_BfpDirectory_Delete) { - addr_ce nameAddr = *(addr_ce*)((uint8*)stackPtr + 0); + addr_ce nameAddr = *(addr_ce*)((uint8*)stackPtr + 0); addr_ce outResultAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize); if (outResultAddr != 0) CE_CHECKADDR(outResultAddr, 4); @@ -6394,7 +6390,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* addr_ce nameAddr = *(addr_ce*)((uint8*)stackPtr + 0); addr_ce sizeAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize); addr_ce outResultAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize + ptrSize); - + CE_CHECKADDR(sizeAddr, 4); int& nameSize = *(int*)(memStart + sizeAddr); CE_CHECKADDR(nameAddr, nameSize); @@ -6407,7 +6403,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* } else if (checkFunction->mFunctionKind == CeFunctionKind_BfpDirectory_SetCurrent) { - addr_ce nameAddr = *(addr_ce*)((uint8*)stackPtr + 0); + addr_ce nameAddr = *(addr_ce*)((uint8*)stackPtr + 0); addr_ce outResultAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize); if (outResultAddr != 0) CE_CHECKADDR(outResultAddr, 4); @@ -6444,7 +6440,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* addr_ce nameAddr = *(addr_ce*)((uint8*)stackPtr + 4); addr_ce sizeAddr = *(addr_ce*)((uint8*)stackPtr + 4 + ptrSize); addr_ce outResultAddr = *(addr_ce*)((uint8*)stackPtr + 4 + ptrSize + ptrSize); - + CE_CHECKADDR(sizeAddr, 4); int& nameSize = *(int*)(memStart + sizeAddr); CE_CHECKADDR(nameAddr, nameSize); @@ -6456,9 +6452,9 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* } else if (checkFunction->mFunctionKind == CeFunctionKind_BfpFile_Close) { - addr_ce fileId = *(addr_ce*)((uint8*)stackPtr + 0); + addr_ce fileId = *(addr_ce*)((uint8*)stackPtr + 0); addr_ce outResultAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize); - + CE_CHECKADDR(outResultAddr, 4); CeInternalData* internalData = NULL; @@ -6476,7 +6472,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* String path; CE_CHECKADDR_STR(path, nameAddr); - CE_CHECKADDR(outResultAddr, 4); + CE_CHECKADDR(outResultAddr, 4); FixRelativePath(path); auto bfpFile = BfpFile_Create(path.c_str(), (BfpFileCreateKind)createKind, (BfpFileCreateFlags)createFlags, (BfpFileAttributes)createFileAttrs, (BfpFileResult*)(memStart + outResultAddr)); if (bfpFile != NULL) @@ -6531,7 +6527,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* while (true) { if (*cancelingPtr) - break; + break; int useTimeout = timeoutLeft; if (useTimeout < 0) @@ -6579,7 +6575,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* asyncOperation->AddRef(); asyncThread = BfpThread_Create(CeAsyncOperation::RunProc, asyncOperation); - } + } if (asyncOperation != NULL) asyncOperation->Release(); @@ -6611,9 +6607,9 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* } else if (checkFunction->mFunctionKind == CeFunctionKind_BfpFile_Truncate) { - addr_ce fileId = *(addr_ce*)((uint8*)stackPtr + 0); + addr_ce fileId = *(addr_ce*)((uint8*)stackPtr + 0); addr_ce outResultAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize); - + CE_CHECKADDR(outResultAddr, 4); CeInternalData* internalData = NULL; @@ -6661,7 +6657,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* result = BfpFile_GetAttributes(path.c_str(), (outResultAddr == 0) ? NULL : (BfpFileResult*)(memStart + outResultAddr)); } else if (checkFunction->mFunctionKind == CeFunctionKind_BfpFile_SetAttributes) - { + { addr_ce nameAddr = *(addr_ce*)((uint8*)stackPtr + 0); BfpFileAttributes attribs = *(BfpFileAttributes*)((uint8*)stackPtr + ptrSize); addr_ce outResultAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize + ptrSize); @@ -6677,7 +6673,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* { addr_ce srcAddr = *(addr_ce*)((uint8*)stackPtr + 0); addr_ce destAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize); - BfpFileCopyKind fileCopyKind = *(BfpFileCopyKind*)((uint8*)stackPtr + ptrSize + ptrSize); + BfpFileCopyKind fileCopyKind = *(BfpFileCopyKind*)((uint8*)stackPtr + ptrSize + ptrSize); addr_ce outResultAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize + ptrSize + 4); if (outResultAddr != 0) CE_CHECKADDR(outResultAddr, 4); @@ -6708,7 +6704,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* } else if (checkFunction->mFunctionKind == CeFunctionKind_BfpFile_Delete) { - addr_ce nameAddr = *(addr_ce*)((uint8*)stackPtr + 0); + addr_ce nameAddr = *(addr_ce*)((uint8*)stackPtr + 0); addr_ce outResultAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize); if (outResultAddr != 0) CE_CHECKADDR(outResultAddr, 4); @@ -6725,16 +6721,16 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* String path; CE_CHECKADDR_STR(path, nameAddr); - FixRelativePath(path); + FixRelativePath(path); AddFileRebuild(path); result = BfpFile_Exists(path.c_str()); } else if (checkFunction->mFunctionKind == CeFunctionKind_BfpFile_GetTempPath) - { + { addr_ce nameAddr = *(addr_ce*)((uint8*)stackPtr + 0); addr_ce sizeAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize); addr_ce outResultAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize + ptrSize); - + CE_CHECKADDR(sizeAddr, 4); int& nameSize = *(int*)(memStart + sizeAddr); CE_CHECKADDR(nameAddr, nameSize); @@ -6749,7 +6745,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* addr_ce nameAddr = *(addr_ce*)((uint8*)stackPtr + 0); addr_ce sizeAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize); addr_ce outResultAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize + ptrSize); - + CE_CHECKADDR(sizeAddr, 4); int& nameSize = *(int*)(memStart + sizeAddr); CE_CHECKADDR(nameAddr, nameSize); @@ -6765,7 +6761,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* addr_ce nameAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize); addr_ce sizeAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize + ptrSize); addr_ce outResultAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize + ptrSize + ptrSize); - + String srcPath; CE_CHECKADDR_STR(srcPath, srcAddr); @@ -6775,7 +6771,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* char* namePtr = (char*)(memStart + nameAddr); if (outResultAddr != 0) CE_CHECKADDR(outResultAddr, 4); - + FixRelativePath(srcPath); BfpFile_GetFullPath(srcPath.c_str(), namePtr, &nameSize, (outResultAddr == 0) ? NULL : (BfpFileResult*)(memStart + outResultAddr)); } @@ -6785,7 +6781,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* addr_ce nameAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize); addr_ce sizeAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize + ptrSize); addr_ce outResultAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize + ptrSize + ptrSize); - + String srcPath; CE_CHECKADDR_STR(srcPath, srcAddr); @@ -6822,18 +6818,18 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* CE_CHECKADDR_STR(env, envAddr); if (outResultAddr != 0) CE_CHECKADDR(outResultAddr, 4); - + if ((targetPath.Contains('/')) || (targetPath.Contains('\\'))) { - FixRelativePath(targetPath); + FixRelativePath(targetPath); } - auto bfpSpawn = BfpSpawn_Create(targetPath.c_str(), + auto bfpSpawn = BfpSpawn_Create(targetPath.c_str(), (argsAddr == 0) ? NULL : args.c_str(), (workingDirAddr == 0) ? NULL : workingDir.c_str(), (envAddr == 0) ? NULL : env.c_str(), (BfpSpawnFlags)flags, (outResultAddr == 0) ? NULL : (BfpSpawnResult*)(memStart + outResultAddr)); if (bfpSpawn != NULL) - { + { CeInternalData* internalData = new CeInternalData(); internalData->mKind = CeInternalData::Kind_Spawn; internalData->mSpawn = bfpSpawn; @@ -6862,12 +6858,12 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* BfpFile* outStdErr = NULL; CeInternalData* internalData = NULL; - CE_GET_INTERNAL(internalData, (int)spawnId, CeInternalData::Kind_Spawn); + CE_GET_INTERNAL(internalData, (int)spawnId, CeInternalData::Kind_Spawn); BfpSpawn_GetStdHandles(internalData->mSpawn, (outStdInAddr != 0) ? &outStdIn : NULL, (outStdOutAddr != 0) ? &outStdOut : NULL, (outStdErrAddr != 0) ? &outStdErr : NULL); - + auto _SetHandle = [&](addr_ce addr, BfpFile* file) { if (addr == 0) @@ -6881,7 +6877,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* CeSetAddrVal(memStart + addr, mCurHandleId, ptrSize); } }; - + if (outStdInAddr != 0) _SetHandle(outStdInAddr, outStdIn); if (outStdOutAddr != 0) @@ -6923,7 +6919,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* CeInternalData* internalData = NULL; CE_GET_INTERNAL(internalData, (int)spawnId, CeInternalData::Kind_Spawn); - + int outExitCode = 0; int timeLeft = waitMS; do @@ -6940,12 +6936,12 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* waitTime = BF_MIN(timeLeft, 20); timeLeft -= waitTime; } - + result = BfpSpawn_WaitFor(internalData->mSpawn, waitTime, &outExitCode, (outResultAddr == 0) ? NULL : (BfpSpawnResult*)(memStart + outResultAddr)); if (result) break; if (waitTime == 0) - break; + break; } while (true); *(int*)(memStart + outExitCodeAddr) = outExitCode; } @@ -6953,7 +6949,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* { void* resultPtr = ((uint8*)stackPtr + 0); addr_ce nameAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize); - int flags = *(int*)((uint8*)stackPtr + ptrSize + ptrSize); + int flags = *(int*)((uint8*)stackPtr + ptrSize + ptrSize); addr_ce outResultAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize + ptrSize + 4); String path; @@ -6972,7 +6968,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* CeRebuildKey rebuildKey; rebuildKey.mKind = CeRebuildKey::Kind_Directory; rebuildKey.mString = dir; - CeRebuildValue rebuildValue; + CeRebuildValue rebuildValue; if (AddRebuild(rebuildKey, rebuildValue)) mCurModule->mCompiler->mRebuildFileSet.Add(dir); @@ -6999,7 +6995,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* addr_ce nameAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize); addr_ce sizeAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize + ptrSize); addr_ce outResultAddr = *(addr_ce*)((uint8*)stackPtr + ptrSize + ptrSize + ptrSize); - + CeInternalData* internalData = NULL; CE_GET_INTERNAL(internalData, (int)spawnId, CeInternalData::Kind_FindFileData); CE_CHECKADDR(sizeAddr, 4); @@ -7068,7 +7064,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* return true; } - if (!checkFunction->mFailed) + if (!checkFunction->mFailed) return true; if ((mCeMachine->mDebugger != NULL) && (!mCallStack.IsEmpty())) @@ -7100,7 +7096,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* CeOp op = CE_GETINST(CeOp); if (*specialCheckPtr) - { + { SpecialCheck: if (*fastFinishPtr) { @@ -7115,10 +7111,10 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* _Fail("Comptime evaluation canceled"); } return false; - } + } bool wantsStop = false; - + if (mCeMachine->mStepState.mKind != CeStepState::Kind_None) { int curDepth = mCallStack.mSize + 1; @@ -7163,7 +7159,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* op = CE_GETINST(CeOp); wantsStop = true; break; - } + } } else if (mCeMachine->mDbgWantBreak) { @@ -7174,13 +7170,13 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* AutoCrit autoCrit(mCeMachine->mCritSect); mCallStack.Add(_GetCurFrame()); mCeMachine->mDebugger->UpdateBreakpointFrames(); - mCallStack.pop_back(); + mCallStack.pop_back(); } else *specialCheckPtr = false; if (wantsStop) - { + { mCeMachine->mDbgWantBreak = false; mCeMachine->mStepState.mKind = CeStepState::Kind_None; _DbgPause(); @@ -7189,9 +7185,9 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* // We may have changed breakpoints so we need to re-read instPtr -= sizeof(CeOp); op = CE_GETINST(CeOp); - } + } } - + OpSwitch: switch (op) { @@ -7213,9 +7209,9 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* mCallStack.Add(_GetCurFrame()); if (mCeMachine->mDebugger->CheckConditionalBreakpoint(breakpointEntry->mBreakpoint)) - doBreak = true; + doBreak = true; mCallStack.pop_back(); - + op = breakpointEntry->mPrevOpCode; // Keep us from an infinite loop if we set a breakpoint on a manual Break skipInst = op == CeOp_DbgBreak; @@ -7227,7 +7223,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* _FixVariables(); if (skipInst) break; - goto OpSwitch; + goto OpSwitch; } mCeMachine->mDebugger->mActiveBreakpoint = breakpointEntry->mBreakpoint; @@ -7337,8 +7333,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* CeSetAddrVal(&result, valueAddr, ptrSize); else CeSetAddrVal(&result, 0, ptrSize); - - } + } } break; case CeOp_GetReflectType: @@ -7347,7 +7342,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* int32 typeId = CE_GETINST(int32); auto reflectType = GetReflectType(typeId); _FixVariables(); - CeSetAddrVal(framePtr + frameOfs, reflectType, ptrSize); + CeSetAddrVal(framePtr + frameOfs, reflectType, ptrSize); } break; case CeOp_GetString: @@ -7361,7 +7356,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* _FixVariables(); ceStringEntry.mBindExecuteId = mExecuteId; } - CeSetAddrVal(framePtr + frameOfs, ceStringEntry.mStringAddr, ptrSize); + CeSetAddrVal(framePtr + frameOfs, ceStringEntry.mStringAddr, ptrSize); } break; case CeOp_Malloc: @@ -7531,7 +7526,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* CE_LOAD(uint32); break; case CeOp_Load_64: - CE_LOAD(uint64); + CE_LOAD(uint64); break; case CeOp_Load_X: { @@ -7630,7 +7625,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* case CeOp_AdjustSPConst: { int32 adjust = CE_GETINST(int32); - stackPtr += adjust; + stackPtr += adjust; } break; case CeOp_GetSP: @@ -8382,7 +8377,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* case CeOp_Shr_U64: CEOP_BIN2(>> , uint64, uint8); break; - + case CeOp_Acos_F32: CEOP_UNARY_FUNC(acosf, float); break; @@ -8491,7 +8486,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* case CeOp_Tanh_F64: CEOP_UNARY_FUNC(tanh, double); break; - + case CeOp_Cmp_NE_I8: CEOP_CMP(!= , int8); break; @@ -8709,7 +8704,7 @@ CeMachine::CeMachine(BfCompiler* compiler) mCurBuilder = NULL; mPreparingFunction = NULL; - mCurEmitContext = NULL; + mCurEmitContext = NULL; mAppendAllocInfo = NULL; mTempParser = NULL; @@ -8724,7 +8719,6 @@ CeMachine::CeMachine(BfCompiler* compiler) BfLogSys(mCompiler->mSystem, "CeMachine::CeMachine %p\n", this); } - CeMachine::~CeMachine() { BF_ASSERT(mDebugger == NULL); @@ -8811,7 +8805,7 @@ void CeMachine::CompileStarted() mRevisionExecuteTime = 0; mSpecialCheck = false; mRevision++; - mMethodBindRevision++; + mMethodBindRevision++; mDbgWantBreak = false; if (mCeModule != NULL) { @@ -8840,7 +8834,7 @@ int CeMachine::GetInstSize(CeFunction* ceFunction, int instIdx) { switch (kind) { - case CEOI_FrameRef: + case CEOI_FrameRef: case CEOI_FrameRef8: case CEOI_FrameRef16: case CEOI_FrameRef32: @@ -8863,7 +8857,7 @@ int CeMachine::GetInstSize(CeFunction* ceFunction, int instIdx) break; case CEOI_IMM_VAR: { - int32 size = CE_SIZE_GET(int32); + int32 size = CE_SIZE_GET(int32); ptr += size; } break; @@ -8878,10 +8872,10 @@ int CeMachine::GetInstSize(CeFunction* ceFunction, int instIdx) auto op = CE_SIZE_GET(CeOp); if (op == CeOp_DbgBreak) - { + { CeBreakpointBind* breakpointEntry = NULL; if (ceFunction->mBreakpoints.TryGetValue(instIdx, &breakpointEntry)) - op = breakpointEntry->mPrevOpCode; + op = breakpointEntry->mPrevOpCode; } CeOpInfo& opInfo = gOpInfo[op]; @@ -8892,7 +8886,7 @@ int CeMachine::GetInstSize(CeFunction* ceFunction, int instIdx) _HandleOperand(opInfo.mOperandA); _HandleOperand(opInfo.mOperandB); _HandleOperand(opInfo.mOperandC); - + return (int)(ptr - startPtr); } @@ -8915,7 +8909,7 @@ void CeMachine::DerefMethodInfo(CeFunctionInfo* ceFunctionInfo) void CeMachine::RemoveFunc(CeFunction* ceFunction) { mFunctionIdMap.Remove(ceFunction->mId); - ceFunction->mId = -1; + ceFunction->mId = -1; } void CeMachine::RemoveMethod(BfMethodInstance* methodInstance) @@ -9009,7 +9003,7 @@ CeErrorKind CeMachine::WriteConstant(CeConstStructData& data, BeConstant* constV // if (mCeMachine->mStaticFieldMap.TryGetValue(globalVar->mName, &staticFieldInfoPtr)) // { // CeStaticFieldInfo* staticFieldInfo = staticFieldInfoPtr; -// +// // int* staticFieldTableIdxPtr = NULL; // if (mStaticFieldMap.TryAdd(globalVar, NULL, &staticFieldTableIdxPtr)) // { @@ -9020,22 +9014,21 @@ CeErrorKind CeMachine::WriteConstant(CeConstStructData& data, BeConstant* constV // *staticFieldTableIdxPtr = (int)mCeFunction->mStaticFieldTable.size(); // mCeFunction->mStaticFieldTable.Add(staticFieldEntry); // } -// +// // auto result = FrameAlloc(mCeMachine->GetBeContext()->GetPointerTo(globalVar->mType)); -// +// // Emit(CeOp_GetStaticField); // EmitFrameOffset(result); // Emit((int32)*staticFieldTableIdxPtr); -// +// // return result; // } // return CeErrorKind_GlobalVariable; } - BF_ASSERT(!data.mQueueFixups); CeConstStructData gvData; - + auto result = WriteConstant(gvData, globalVar->mInitializer, ceContext); if (result != CeErrorKind_None) return result; @@ -9062,10 +9055,10 @@ CeErrorKind CeMachine::WriteConstant(CeConstStructData& data, BeConstant* constV for (int memberIdx = 0; memberIdx < (int)constStruct->mMemberValues.size(); memberIdx++) { auto& member = structType->mMembers[memberIdx]; - // Do any per-member alignment + // Do any per-member alignment int wantZeroes = member.mByteOffset - (data.mData.mSize - startOfs); - if (wantZeroes > 0) - data.mData.Insert(data.mData.size(), (uint8)0, wantZeroes); + if (wantZeroes > 0) + data.mData.Insert(data.mData.size(), (uint8)0, wantZeroes); auto result = WriteConstant(data, constStruct->mMemberValues[memberIdx], ceContext); if (result != CeErrorKind_None) @@ -9117,7 +9110,7 @@ CeErrorKind CeMachine::WriteConstant(CeConstStructData& data, BeConstant* constV { BF_FATAL("Invalid GEP"); } - + addr_ce addr = -1; if (globalVar->mName.StartsWith("__bfStrData")) @@ -9152,7 +9145,7 @@ CeErrorKind CeMachine::WriteConstant(CeConstStructData& data, BeConstant* constV return CeErrorKind_GlobalVariable; // auto sym = GetSymbol(globalVar); - // + // // BeMCRelocation reloc; // reloc.mKind = BeMCRelocationKind_ADDR64; // reloc.mOffset = sect.mData.GetPos(); @@ -9165,7 +9158,7 @@ CeErrorKind CeMachine::WriteConstant(CeConstStructData& data, BeConstant* constV BF_FATAL("Invalid GEPConstant"); } } - + /*else if ((beType->IsPointer()) && (constVal->mTarget != NULL)) { auto result = WriteConstant(arr, constVal->mTarget); @@ -9194,13 +9187,13 @@ CeErrorKind CeMachine::WriteConstant(CeConstStructData& data, BeConstant* constV if (constVal->mType->mSize > 0) { auto ptr = data.mData.GrowUninitialized(constVal->mType->mSize); - memset(ptr, 0, constVal->mType->mSize); - } + memset(ptr, 0, constVal->mType->mSize); + } } else { auto ptr = data.mData.GrowUninitialized(beType->mSize); - memcpy(ptr, &constVal->mInt64, beType->mSize); + memcpy(ptr, &constVal->mInt64, beType->mSize); } } else @@ -9371,8 +9364,8 @@ void CeMachine::CheckFunctionKind(CeFunction* ceFunction) else if (methodDef->mName == "BfpDirectory_Exists") ceFunction->mFunctionKind = CeFunctionKind_BfpDirectory_Exists; else if (methodDef->mName == "BfpDirectory_GetSysDirectory") - ceFunction->mFunctionKind = CeFunctionKind_BfpDirectory_GetSysDirectory; - + ceFunction->mFunctionKind = CeFunctionKind_BfpDirectory_GetSysDirectory; + else if (methodDef->mName == "BfpFile_Close") ceFunction->mFunctionKind = CeFunctionKind_BfpFile_Close; else if (methodDef->mName == "BfpFile_Create") @@ -9443,7 +9436,7 @@ void CeMachine::CheckFunctionKind(CeFunction* ceFunction) ceFunction->mFunctionKind = CeFunctionKind_BfpFindFileData_GetFileSize; else if (methodDef->mName == "BfpFindFileData_Release") ceFunction->mFunctionKind = CeFunctionKind_BfpFindFileData_Release; - + else if (methodDef->mName == "BfpSystem_GetTimeStamp") ceFunction->mFunctionKind = CeFunctionKind_BfpSystem_GetTimeStamp; } @@ -9524,7 +9517,7 @@ void CeMachine::CheckFunctionKind(CeFunction* ceFunction) ceFunction->mFunctionKind = CeFunctionKind_Math_Tan; else if (methodDef->mName == "Tanh") ceFunction->mFunctionKind = CeFunctionKind_Math_Tanh; - } + } ceFunction->mInitializeState = CeFunction::InitializeState_Initialized; return; @@ -9535,7 +9528,7 @@ void CeMachine::CheckFunctionKind(CeFunction* ceFunction) void CeMachine::PrepareFunction(CeFunction* ceFunction, CeBuilder* parentBuilder) { AutoTimer autoTimer(mRevisionExecuteTime); - SetAndRestoreValue prevCEFunction(mPreparingFunction, ceFunction); + SetAndRestoreValue prevCEFunction(mPreparingFunction, ceFunction); BF_ASSERT(ceFunction->mInitializeState <= CeFunction::InitializeState_Initialized); @@ -9557,13 +9550,13 @@ void CeMachine::PrepareFunction(CeFunction* ceFunction, CeBuilder* parentBuilder ceFunction->mInitializeState = CeFunction::InitializeState_Initializing_ReEntry; else ceFunction->mInitializeState = CeFunction::InitializeState_Initializing; - + CeBuilder ceBuilder; SetAndRestoreValue prevBuilder(mCurBuilder, &ceBuilder); ceBuilder.mParentBuilder = parentBuilder; ceBuilder.mPtrSize = mCeModule->mCompiler->mSystem->mPtrSize; ceBuilder.mCeMachine = this; - ceBuilder.mCeFunction = ceFunction; + ceBuilder.mCeFunction = ceFunction; ceBuilder.Build(); ceFunction->mInitializeState = CeFunction::InitializeState_Initialized; @@ -9582,7 +9575,7 @@ void CeMachine::PrepareFunction(CeFunction* ceFunction, CeBuilder* parentBuilder } void CeMachine::MapFunctionId(CeFunction* ceFunction) -{ +{ if ((mCeModule->mSystem->mPtrSize == 8) && (mDebugger == NULL)) return; ceFunction->mId = ++mCurFunctionId; @@ -9590,7 +9583,7 @@ void CeMachine::MapFunctionId(CeFunction* ceFunction) } CeFunction* CeMachine::GetFunction(BfMethodInstance* methodInstance, BfIRValue func, bool& added) -{ +{ if (func) { if ((func.IsConst()) || (func.IsFake())) @@ -9600,10 +9593,10 @@ CeFunction* CeMachine::GetFunction(BfMethodInstance* methodInstance, BfIRValue f CeFunctionInfo** functionInfoPtr = NULL; CeFunctionInfo* ceFunctionInfo = NULL; CeFunction* ceFunction = NULL; - if (!mFunctions.TryAdd(methodInstance, NULL, &functionInfoPtr)) - { - ceFunctionInfo = *functionInfoPtr; - BF_ASSERT(ceFunctionInfo->mCeFunction != NULL); + if (!mFunctions.TryAdd(methodInstance, NULL, &functionInfoPtr)) + { + ceFunctionInfo = *functionInfoPtr; + BF_ASSERT(ceFunctionInfo->mCeFunction != NULL); return ceFunctionInfo->mCeFunction; } @@ -9611,10 +9604,10 @@ CeFunction* CeMachine::GetFunction(BfMethodInstance* methodInstance, BfIRValue f methodInstance->mInCEMachine = true; BfLogSys(mCeModule->mSystem, "CeMachine::GetFunction %p\n", methodInstance); - + if (!func) { - ceFunctionInfo = new CeFunctionInfo(); + ceFunctionInfo = new CeFunctionInfo(); } else { @@ -9652,10 +9645,10 @@ CeFunction* CeMachine::GetFunction(BfMethodInstance* methodInstance, BfIRValue f { added = true; auto module = methodInstance->GetOwner()->mModule; - + BF_ASSERT(ceFunctionInfo->mCeFunction == NULL); - ceFunction = new CeFunction(); + ceFunction = new CeFunction(); ceFunction->mCeMachine = this; ceFunction->mIsVarReturn = methodInstance->mReturnType->IsVar(); ceFunction->mCeFunctionInfo = ceFunctionInfo; @@ -9663,10 +9656,9 @@ CeFunction* CeMachine::GetFunction(BfMethodInstance* methodInstance, BfIRValue f if (mDebugger != NULL) ceFunction->mDbgInfo = new CeDbgFunctionInfo(); ceFunctionInfo->mMethodInstance = methodInstance; - ceFunctionInfo->mCeFunction = ceFunction; + ceFunctionInfo->mCeFunction = ceFunction; MapFunctionId(ceFunction); } - return ceFunction; } @@ -9698,7 +9690,7 @@ CeTypeInfo* CeMachine::GetTypeInfo(BfType* type) return ceTypeInfo; ceTypeInfo->mMethodInstances.Clear(); } - + mCeModule->PopulateType(typeInstance, BfPopulateType_DataAndMethods); ceTypeInfo->mRevision = typeInstance->mRevision; for (auto& methodGroup : typeInstance->mMethodInstanceGroups) @@ -9706,7 +9698,7 @@ CeTypeInfo* CeMachine::GetTypeInfo(BfType* type) if (methodGroup.mOnDemandKind == BfMethodOnDemandKind_NoDecl_AwaitingReference) { auto methodDef = typeInstance->mTypeDef->mMethods[methodGroup.mMethodIdx]; - auto flags = ((methodDef->mGenericParams.size() != 0) || (typeInstance->IsUnspecializedType())) ? BfGetMethodInstanceFlag_UnspecializedPass : BfGetMethodInstanceFlag_None; + auto flags = ((methodDef->mGenericParams.size() != 0) || (typeInstance->IsUnspecializedType())) ? BfGetMethodInstanceFlag_UnspecializedPass : BfGetMethodInstanceFlag_None; flags = (BfGetMethodInstanceFlags)(flags | BfGetMethodInstanceFlag_MethodInstanceOnly); mCeModule->GetMethodInstance(typeInstance, methodDef, BfTypeVector(), flags); } @@ -9724,7 +9716,7 @@ CeTypeInfo* CeMachine::GetTypeInfo(BfType* type) ceTypeInfo->mMethodInstances.Add(kv.mValue); } } - } + } return ceTypeInfo; } @@ -9762,7 +9754,7 @@ void CeMachine::QueueMethod(BfModuleMethodInstance moduleMethodInstance) } void CeMachine::QueueStaticField(BfFieldInstance* fieldInstance, const StringImpl& mangledFieldName) -{ +{ if (mCurBuilder != NULL) mCurBuilder->mStaticFieldInstanceMap[mangledFieldName] = fieldInstance; } @@ -9798,9 +9790,9 @@ CeContext* CeMachine::AllocContext() memset(ceContext->mMemory.mVals, 0, BF_CE_INITIAL_MEMORY); } - ceContext->mCurEmitContext = mCurEmitContext; - mCurEmitContext = NULL; - mExecuteId++; + ceContext->mCurEmitContext = mCurEmitContext; + mCurEmitContext = NULL; + mExecuteId++; ceContext->mStackSize = BF_CE_DEFAULT_STACK_SIZE; ceContext->mMemory.ResizeRaw(ceContext->mStackSize); ceContext->mExecuteId = mExecuteId; @@ -9815,26 +9807,24 @@ void CeMachine::ReleaseContext(CeContext* ceContext) ceContext->mConstDataMap.Clear(); ceContext->mMemory.Clear(); if (ceContext->mMemory.mAllocSize > BF_CE_MAX_CARRYOVER_MEMORY) - ceContext->mMemory.Dispose(); + ceContext->mMemory.Dispose(); ceContext->mStaticCtorExecSet.Clear(); ceContext->mStaticFieldMap.Clear(); ceContext->mHeap->Clear(BF_CE_MAX_CARRYOVER_HEAP); - ceContext->mReflectTypeIdOffset = -1; - mCurEmitContext = ceContext->mCurEmitContext; - ceContext->mCurEmitContext = NULL; + ceContext->mReflectTypeIdOffset = -1; + mCurEmitContext = ceContext->mCurEmitContext; + ceContext->mCurEmitContext = NULL; mContextList.Add(ceContext); for (auto kv : ceContext->mInternalDataMap) - kv.mValue->Release(); + kv.mValue->Release(); ceContext->mInternalDataMap.Clear(); ceContext->mWorkingDir.Clear(); } BfTypedValue CeMachine::Call(CeCallSource callSource, BfModule* module, BfMethodInstance* methodInstance, const BfSizedArray& args, CeEvalFlags flags, BfType* expectingType) -{ +{ auto ceContext = AllocContext(); auto result = ceContext->Call(callSource, module, methodInstance, args, flags, expectingType); - ReleaseContext(ceContext); + ReleaseContext(ceContext); return result; -} - - +} \ No newline at end of file diff --git a/IDEHelper/Compiler/CeMachine.h b/IDEHelper/Compiler/CeMachine.h index 297c90ed..d8d8baca 100644 --- a/IDEHelper/Compiler/CeMachine.h +++ b/IDEHelper/Compiler/CeMachine.h @@ -80,17 +80,17 @@ enum CeOp : int16 CeOp_JmpIf, CeOp_JmpIfNot, - CeOp_Error, + CeOp_Error, CeOp_DynamicCastCheck, CeOp_GetReflectType, CeOp_GetString, CeOp_Malloc, CeOp_Free, - + CeOp_MemSet, CeOp_MemSet_Const, CeOp_MemCpy, - + CeOp_FrameAddr_32, CeOp_FrameAddr_64, CeOp_FrameAddrOfs_32, @@ -116,7 +116,7 @@ enum CeOp : int16 CeOp_GetMethod_Virt, CeOp_GetMethod_IFace, CeOp_Call, - + CeOp_Conv_I8_I16, CeOp_Conv_I8_I32, CeOp_Conv_I8_I64, @@ -128,7 +128,7 @@ enum CeOp : int16 CeOp_Conv_I16_F64, CeOp_Conv_I32_I64, CeOp_Conv_I32_F32, - CeOp_Conv_I32_F64, + CeOp_Conv_I32_F64, CeOp_Conv_I64_F32, CeOp_Conv_I64_F64, CeOp_Conv_U8_U16, @@ -168,7 +168,7 @@ enum CeOp : int16 CEOP_SIZED_NUMERIC_PLUSF(AddConst), CEOP_SIZED_NUMERIC_PLUSF(Add), CEOP_SIZED_NUMERIC_PLUSF(Sub), - CEOP_SIZED_NUMERIC_PLUSF(Mul), + CEOP_SIZED_NUMERIC_PLUSF(Mul), CEOP_SIZED_NUMERIC_PLUSF(Div), CEOP_SIZED_UNUMERIC(Div), CEOP_SIZED_NUMERIC_PLUSF(Mod), @@ -179,7 +179,7 @@ enum CeOp : int16 CEOP_SIZED_NUMERIC(Shl), CEOP_SIZED_NUMERIC(Shr), CEOP_SIZED_UNUMERIC(Shr), - + CEOP_SIZED_FLOAT(Acos), CEOP_SIZED_FLOAT(Asin), CEOP_SIZED_FLOAT(Atan), @@ -190,7 +190,7 @@ enum CeOp : int16 CEOP_SIZED_FLOAT(Exp), CEOP_SIZED_FLOAT(Floor), CEOP_SIZED_FLOAT(Log), - CEOP_SIZED_FLOAT(Log10), + CEOP_SIZED_FLOAT(Log10), CEOP_SIZED_FLOAT(Pow), CEOP_SIZED_FLOAT(Round), CEOP_SIZED_FLOAT(Sin), @@ -198,7 +198,7 @@ enum CeOp : int16 CEOP_SIZED_FLOAT(Sqrt), CEOP_SIZED_FLOAT(Tan), CEOP_SIZED_FLOAT(Tanh), - + CEOP_SIZED_NUMERIC_PLUSF(Cmp_EQ), CEOP_SIZED_NUMERIC_PLUSF(Cmp_NE), CEOP_SIZED_NUMERIC_PLUSF(Cmp_SLT), @@ -307,7 +307,7 @@ public: }; struct CeDbgInlineEntry -{ +{ int mScope; int mLine; int mColumn; @@ -329,7 +329,7 @@ public: mCeFunction = NULL; mRefCount = 0; } - + ~CeFunctionInfo(); BfTypeInstance* GetOwner() @@ -447,14 +447,14 @@ enum CeFunctionKind CeFunctionKind_Method_GetInfo, CeFunctionKind_Method_GetParamInfo, CeFunctionKind_Method_GetGenericArg, - + CeFunctionKind_SetReturnType, CeFunctionKind_EmitTypeBody, CeFunctionKind_EmitAddInterface, CeFunctionKind_EmitMethodEntry, CeFunctionKind_EmitMethodExit, CeFunctionKind_EmitMixin, - + CeFunctionKind_BfpDirectory_Create, CeFunctionKind_BfpDirectory_Rename, CeFunctionKind_BfpDirectory_Delete, @@ -483,7 +483,7 @@ enum CeFunctionKind CeFunctionKind_BfpFile_GetTempFileName, CeFunctionKind_BfpFile_GetFullPath, CeFunctionKind_BfpFile_GetActualPath, - + CeFunctionKind_BfpFindFileData_FindFirstFile, CeFunctionKind_BfpFindFileData_FindNextFile, CeFunctionKind_BfpFindFileData_GetFileName, @@ -521,7 +521,7 @@ enum CeFunctionKind CeFunctionKind_Math_Asin, CeFunctionKind_Math_Atan, CeFunctionKind_Math_Atan2, - CeFunctionKind_Math_Ceiling, + CeFunctionKind_Math_Ceiling, CeFunctionKind_Math_Cos, CeFunctionKind_Math_Cosh, CeFunctionKind_Math_Exp, @@ -535,7 +535,7 @@ enum CeFunctionKind CeFunctionKind_Math_Sinh, CeFunctionKind_Math_Sqrt, CeFunctionKind_Math_Tan, - CeFunctionKind_Math_Tanh, + CeFunctionKind_Math_Tanh, }; class CeConstStructFixup @@ -596,14 +596,14 @@ public: { mTypeId = -1; mSize = 0; - mAddr = 0; - mBindExecuteId = -1; + mAddr = 0; + mBindExecuteId = -1; } }; class CeDbgVariable { -public: +public: String mName; CeOperand mValue; BfType* mType; @@ -641,17 +641,17 @@ public: CeMachine* mCeMachine; CeFunctionInfo* mCeFunctionInfo; CeInnerFunctionInfo* mCeInnerFunctionInfo; - BfMethodInstance* mMethodInstance; - CeFunctionKind mFunctionKind; + BfMethodInstance* mMethodInstance; + CeFunctionKind mFunctionKind; InitializeState mInitializeState; bool mFailed; bool mIsVarReturn; - Array mCode; + Array mCode; Array mDbgScopes; Array mDbgInlineTable; Array mDbgMethodRefTable; - Array mEmitTable; - Array mCallTable; + Array mEmitTable; + Array mCallTable; Array mStringTable; Array mConstStructTable; Array mStaticFieldTable; @@ -659,7 +659,7 @@ public: Array mInnerFunctions; Dictionary mBreakpoints; String mGenError; - int mFrameSize; + int mFrameSize; int mMaxReturnSize; int mId; int mBreakpointVersion; @@ -671,7 +671,7 @@ public: mCeMachine = NULL; mCeFunctionInfo = NULL; mCeInnerFunctionInfo = NULL; - mFunctionKind = CeFunctionKind_NotSet; + mFunctionKind = CeFunctionKind_NotSet; mInitializeState = InitializeState_None; mMethodInstance = NULL; mFailed = false; @@ -681,7 +681,7 @@ public: mBreakpointVersion = 0; mId = -1; mDbgInfo = NULL; - } + } ~CeFunction(); void Print(); @@ -747,7 +747,7 @@ enum CeSizeClass class CeDumpContext { -public: +public: Dictionary mVarMap; CeFunction* mCeFunction; String mStr; @@ -765,13 +765,13 @@ public: void DumpOperandInfo(CeOperandInfoKind operandInfoKind); void Next(); - void Dump(); + void Dump(); }; struct CePhiOutgoing { BeValue* mPhiValue; - BePhiInst* mPhiInst; + BePhiInst* mPhiInst; int mPhiBlockIdx; }; @@ -784,7 +784,7 @@ public: public: CeBlock() { - mEmitOfs = -1; + mEmitOfs = -1; } }; @@ -811,7 +811,7 @@ struct CeDbgInlineLookup mDbgFile = NULL; mInlineAtIdx = -1; } - + bool operator==(const CeDbgInlineLookup& second) const { return (mDbgFile == second.mDbgFile) && (mDbgFile == second.mDbgFile); @@ -820,18 +820,18 @@ struct CeDbgInlineLookup class CeBuilder { -public: +public: CeBuilder* mParentBuilder; - CeMachine* mCeMachine; + CeMachine* mCeMachine; CeFunction* mCeFunction; - BeFunction* mBeFunction; + BeFunction* mBeFunction; CeOperand mReturnVal; BeType* mIntPtrType; - int mPtrSize; + int mPtrSize; String mError; BeDbgLoc* mCurDbgLoc; - Array mBlocks; + Array mBlocks; Array mJumpTable; Dictionary mValueToOperand; int mFrameSize; @@ -845,7 +845,7 @@ public: Dictionary mStaticFieldMap; Dictionary mStaticFieldInstanceMap; Dictionary mDbgVariableMap; - + public: CeBuilder() { @@ -857,7 +857,7 @@ public: mCurDbgLoc = NULL; mFrameSize = 0; } - + void Fail(const StringImpl& error); CeOperand FrameAlloc(BeType* type); @@ -871,7 +871,7 @@ public: int GetCodePos(); void HandleParams(); - + void Emit(uint8 val); void Emit(CeOp val); void EmitSizedOp(CeOp val, int size); @@ -881,7 +881,7 @@ public: void Emit(void* ptr, int size); void EmitZeroes(int size); void EmitJump(CeOp op, const CeOperand& block); - void EmitBinarySwitchSection(BeSwitchInst* switchInst, int startIdx, int endIdx); + void EmitBinarySwitchSection(BeSwitchInst* switchInst, int startIdx, int endIdx); void EmitFrameOffset(const CeOperand& val); void FlushPhi(CeBlock* ceBlock, int targetBlockIdx); @@ -920,7 +920,7 @@ public: class CeStaticFieldInfo { -public: +public: addr_ce mAddr; public: @@ -970,16 +970,16 @@ public: class CeEmitContext { public: - BfType* mType; + BfType* mType; BfMethodInstance* mMethodInstance; - Array mInterfaces; + Array mInterfaces; String mEmitData; String mExitEmitData; bool mFailed; CeEmitContext() { - mType = NULL; + mType = NULL; mMethodInstance = NULL; mFailed = false; } @@ -1088,15 +1088,15 @@ public: int mExecuteId; CeEvalFlags mCurEvalFlags; - // These are only valid for the current execution + // These are only valid for the current execution ContiguousHeap* mHeap; Array mCallStack; Array mMemory; int mStackSize; Dictionary mStringMap; Dictionary mReflectMap; - Dictionary mConstDataMap; - HashSet mStaticCtorExecSet; + Dictionary mConstDataMap; + HashSet mStaticCtorExecSet; Dictionary mStaticFieldMap; Dictionary mInternalDataMap; int mCurHandleId; @@ -1109,16 +1109,16 @@ public: CeCallSource* mCurCallSource; BfModule* mCurModule; CeFrame* mCurFrame; - CeEmitContext* mCurEmitContext; + CeEmitContext* mCurEmitContext; String mWorkingDir; public: CeContext(); ~CeContext(); - + BfError* Fail(const StringImpl& error); BfError* Fail(const CeFrame& curFrame, const StringImpl& error); - + void CalcWorkingDir(); void FixRelativePath(StringImpl& path); bool AddRebuild(const CeRebuildKey& key, const CeRebuildValue& value); @@ -1143,8 +1143,8 @@ public: bool GetCustomAttribute(BfModule* module, BfIRConstHolder* constHolder, BfCustomAttributes* customAttributes, int attributeIdx, addr_ce resultAddr); BfType* GetCustomAttributeType(BfCustomAttributes* customAttributes, int attributeIdx); - bool WriteConstant(BfModule* module, addr_ce addr, BfConstant* constant, BfType* type, bool isParams = false); - BfIRValue CreateConstant(BfModule* module, uint8* ptr, BfType* type, BfType** outType = NULL); + bool WriteConstant(BfModule* module, addr_ce addr, BfConstant* constant, BfType* type, bool isParams = false); + BfIRValue CreateConstant(BfModule* module, uint8* ptr, BfType* type, BfType** outType = NULL); BfIRValue CreateAttribute(BfAstNode* targetSrc, BfModule* module, BfIRConstHolder* constHolder, BfCustomAttribute* customAttribute, addr_ce ceAttrAddr = 0); bool Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* startFramePtr, BfType*& returnType, BfType*& castReturnType); @@ -1173,14 +1173,14 @@ public: Kind_Evaluate }; - Kind mKind; + Kind mKind; int mNextInstIdx; int mStartDepth; public: CeStepState() { - mKind = Kind_None; + mKind = Kind_None; mNextInstIdx = -1; mStartDepth = 0; } @@ -1194,24 +1194,24 @@ public: Dictionary mFunctionIdMap; // Only used for 32-bit and debugging Dictionary mTypeInfoMap; HashSet mMethodInstanceSet; - HashSet mFieldInstanceSet; - + HashSet mFieldInstanceSet; + Array mContextList; BfCompiler* mCompiler; BfModule* mCeModule; int mRevision; int mMethodBindRevision; - int mRevisionExecuteTime; - int mCurFunctionId; + int mRevisionExecuteTime; + int mCurFunctionId; int mExecuteId; - CeAppendAllocInfo* mAppendAllocInfo; - + CeAppendAllocInfo* mAppendAllocInfo; + CeContext* mCurContext; CeEmitContext* mCurEmitContext; CeCallSource* mCurCallSource; CeBuilder* mCurBuilder; - CeFunction* mPreparingFunction; + CeFunction* mPreparingFunction; BfParser* mTempParser; BfReducer* mTempReducer; @@ -1221,27 +1221,27 @@ public: SyncEvent mDebugEvent; CeStepState mStepState; CeDebugger* mDebugger; - bool mDbgPaused; + bool mDbgPaused; bool mSpecialCheck; bool mDbgWantBreak; public: CeMachine(BfCompiler* compiler); - ~CeMachine(); + ~CeMachine(); - void Init(); + void Init(); BeContext* GetBeContext(); BeModule* GetBeModule(); int GetInstSize(CeFunction* ceFunction, int instIdx); void DerefMethodInfo(CeFunctionInfo* ceFunctionInfo); void RemoveFunc(CeFunction* ceFunction); - void RemoveMethod(BfMethodInstance* methodInstance); - void CreateFunction(BfMethodInstance* methodInstance, CeFunction* ceFunction); - CeErrorKind WriteConstant(CeConstStructData& data, BeConstant* constVal, CeContext* ceContext); + void RemoveMethod(BfMethodInstance* methodInstance); + void CreateFunction(BfMethodInstance* methodInstance, CeFunction* ceFunction); + CeErrorKind WriteConstant(CeConstStructData& data, BeConstant* constVal, CeContext* ceContext); void CheckFunctionKind(CeFunction* ceFunction); - void PrepareFunction(CeFunction* methodInstance, CeBuilder* parentBuilder); + void PrepareFunction(CeFunction* methodInstance, CeBuilder* parentBuilder); void MapFunctionId(CeFunction* ceFunction); void CheckFunctions(); @@ -1249,14 +1249,14 @@ public: CeFunction* GetPreparedFunction(BfMethodInstance* methodInstance); CeTypeInfo* GetTypeInfo(BfType* type); BfMethodInstance* GetMethodInstance(int64 methodHandle); - BfFieldInstance* GetFieldInstance(int64 fieldHandle); + BfFieldInstance* GetFieldInstance(int64 fieldHandle); public: void CompileStarted(); void CompileDone(); CeFunction* QueueMethod(BfMethodInstance* methodInstance, BfIRValue func); void QueueMethod(BfModuleMethodInstance moduleMethodInstance); - void QueueStaticField(BfFieldInstance* fieldInstance, const StringImpl& mangledFieldName); + void QueueStaticField(BfFieldInstance* fieldInstance, const StringImpl& mangledFieldName); void SetAppendAllocInfo(BfModule* module, BfIRValue allocValue, BfIRValue appendSizeValue); void ClearAppendAllocInfo(); @@ -1277,7 +1277,7 @@ namespace std { return BeefHash()(key.mString) ^ (size_t)key.mKind; } - }; + }; template <> struct hash diff --git a/IDEHelper/Compiler/MemReporter.cpp b/IDEHelper/Compiler/MemReporter.cpp index afae1de3..965d5fe8 100644 --- a/IDEHelper/Compiler/MemReporter.cpp +++ b/IDEHelper/Compiler/MemReporter.cpp @@ -16,7 +16,7 @@ MemReporter::~MemReporter() int MemReporter::GetChildSizes(Entry* entry) { int childSizes = 0; - for (auto& childPair : entry->mChildren) + for (auto& childPair : entry->mChildren) { auto child = childPair.mValue; childSizes += child->mSize + GetChildSizes(child); @@ -29,10 +29,10 @@ void MemReporter::Report(int depth, Entry* entry) String str; for (int i = 0; i < depth; i++) str += " "; - + str += entry->mName; while (str.length() < 64) - str += ' '; + str += ' '; if (entry->mChildSize == -1) entry->mChildSize = GetChildSizes(entry); @@ -45,7 +45,7 @@ void MemReporter::Report(int depth, Entry* entry) Array entries; for (auto& kv : entry->mChildren) - { + { auto* entry = kv.mValue; entry->mChildSize = GetChildSizes(entry); entries.Add(kv.mValue); @@ -63,7 +63,7 @@ void MemReporter::BeginSection(const StringView& name) { Entry** entryPtr; if (!mCurEntry->mChildren.TryAdd(StringImpl::MakeRef(name), NULL, &entryPtr)) - { + { mCurEntry = *entryPtr; mCurEntry->mCount++; return; @@ -95,6 +95,6 @@ void MemReporter::EndSection() } void MemReporter::Report() -{ +{ Report(0, &mRoot); -} +} \ No newline at end of file diff --git a/IDEHelper/Compiler/MemReporter.h b/IDEHelper/Compiler/MemReporter.h index ea0ff7ff..1ad8ef12 100644 --- a/IDEHelper/Compiler/MemReporter.h +++ b/IDEHelper/Compiler/MemReporter.h @@ -36,24 +36,24 @@ public: Entry* mCurEntry; bool mShowInKB; -public: +public: int GetChildSizes(Entry* entry); void Report(int depth, Entry* entry); -public: +public: MemReporter(); ~MemReporter(); void BeginSection(const StringView& name); void Add(int size); void Add(const StringView& name, int size); - + template void AddVec(const T& vec, bool addContainerSize = true) { Add((addContainerSize ? sizeof(T) : 0) + (int)vec.mAllocSize * sizeof(typename T::value_type)); } - + template void AddVec(const StringView& name, const T& vec, bool addContainerSize = true) { @@ -61,21 +61,21 @@ public: Add((addContainerSize ? sizeof(T) : 0) + (int)vec.mAllocSize * sizeof(typename T::value_type)); EndSection(); } - + template void AddVecPtr(const std::vector& vec, bool addContainerSize = true) { Add((addContainerSize ? sizeof(T) : 0) + - (int)vec.capacity() * sizeof(T) + + (int)vec.capacity() * sizeof(T) + (int)vec.size() * sizeof(typename std::remove_pointer::type)); //-V220 } - + template void AddVecPtr(const Array& vec, bool addContainerSize = true) { Add((addContainerSize ? sizeof(T) : 0) + (int)vec.mAllocSize * sizeof(T) + - (int)vec.size() * sizeof(typename std::remove_pointer::type)); //-V220 + (int)vec.size() * sizeof(typename std::remove_pointer::type)); //-V220 } template @@ -83,12 +83,12 @@ public: { Add(name, (addContainerSize ? sizeof(T) : 0) + (int)vec.mAllocSize * sizeof(T) + - (int)vec.size() * sizeof(typename std::remove_pointer::type)); //-V220 + (int)vec.size() * sizeof(typename std::remove_pointer::type)); //-V220 } template void AddMap(const StringView& name, const T& map, bool addContainerSize = true) - { + { Add(name, (addContainerSize ? sizeof(T) : 0) + map.mAllocSize * (sizeof(typename T::EntryPair) + sizeof(typename T::int_cosize))); } @@ -109,7 +109,7 @@ public: { Add((addContainerSize ? sizeof(T) : 0) + map.mAllocSize * (sizeof(typename T::Entry) + sizeof(typename T::int_cosize))); } - + void AddStr(const StringImpl& str, bool addContainerSize = true) { Add((addContainerSize ? sizeof(StringImpl) : 0) + (int)str.GetAllocSize()); @@ -123,12 +123,11 @@ public: void EndSection(); void Report(); - template void AddBumpAlloc(const StringView& name, const T& alloc) - { + { BeginSection(name); - + int usedSize = alloc.CalcUsedSize(); #ifdef BUMPALLOC_TRACKALLOCS @@ -162,9 +161,9 @@ public: Add("Unaccounted", usedSizeLeft); #else Add("Used", usedSize); -#endif +#endif Add("Waste", alloc.GetAllocSize() - usedSize); - Add("Unused", alloc.GetTotalAllocSize() - alloc.GetAllocSize()); + Add("Unused", alloc.GetTotalAllocSize() - alloc.GetAllocSize()); EndSection(); } @@ -173,7 +172,7 @@ public: class AutoMemReporter { public: - MemReporter* mMemReporter; + MemReporter* mMemReporter; public: AutoMemReporter(MemReporter* memReporter, const StringImpl& name) diff --git a/IDEHelper/DbgMiniDump.cpp b/IDEHelper/DbgMiniDump.cpp index 8a0a9d31..49c5b24b 100644 --- a/IDEHelper/DbgMiniDump.cpp +++ b/IDEHelper/DbgMiniDump.cpp @@ -3,7 +3,7 @@ USING_NS_BF; -enum DbgMiniDumpFlags +enum DbgMiniDumpFlags { DbgMiniDumpFlag_MiniDumpNormal = 0x00000000, DbgMiniDumpFlag_MiniDumpWithDataSegs = 0x00000001, @@ -41,18 +41,18 @@ bool DbgMiniDump::StartLoad(const StringImpl& path) uint32 mVersion; uint32 mNumberOfStreams; uint32 mStreamDirectoryRVA; - uint32 mCheckSum; - uint32 TimeDateStamp; + uint32 mCheckSum; + uint32 TimeDateStamp; uint64 Flags; }; - _Header& header = *(_Header*)((uint8*)mMF.mData); + _Header& header = *(_Header*)((uint8*)mMF.mData); if (header.mSignature != 'PMDM') return false; - + mDirectory.mVals = (StreamDirectoryEntry*)((uint8*)mMF.mData + header.mStreamDirectoryRVA); mDirectory.mSize = header.mNumberOfStreams; - + return true; } @@ -72,4 +72,4 @@ int DbgMiniDump::GetTargetBitCount() } return 0; -} +} \ No newline at end of file diff --git a/IDEHelper/DbgMiniDump.h b/IDEHelper/DbgMiniDump.h index 3534e0ec..070272f2 100644 --- a/IDEHelper/DbgMiniDump.h +++ b/IDEHelper/DbgMiniDump.h @@ -46,7 +46,7 @@ public: bool StartLoad(const StringImpl& path); int GetTargetBitCount(); - template + template T& GetStreamData(const StreamDirectoryEntry& entry) { return *(T*)((uint8*)mMF.mData + entry.mDataRVA); diff --git a/IDEHelper/DebugManager.cpp b/IDEHelper/DebugManager.cpp index 58c706df..09cf16a1 100644 --- a/IDEHelper/DebugManager.cpp +++ b/IDEHelper/DebugManager.cpp @@ -80,7 +80,7 @@ DebugManager::DebugManager() mStepOverExternalFiles = false; mDebugger32 = NULL; - mDebugger64 = NULL; + mDebugger64 = NULL; mNetManager = new NetManager(); mNetManager->mDebugManager = this; @@ -106,12 +106,11 @@ DebugManager::~DebugManager() delete mNetManager; delete mDebugger64; - delete mDebugger32; + delete mDebugger32; /*for (auto stepFilter : mStepFilters) { - }*/ - delete mDebugVisualizers; + delete mDebugVisualizers; } void DebugManager::OutputMessage(const StringImpl& msg) @@ -144,7 +143,6 @@ void DebugManager::SetSourceServerCacheDir() #endif } - //#define CAPTURE_ALLOC_BACKTRACE //#define CAPTURE_ALLOC_SOURCES @@ -153,7 +151,7 @@ const int sNumAllocAddrs = 0x300000; const int sCaptureDepth = 14; const int sCaptureOffset = 4; static intptr gAllocAddrs[sNumAllocAddrs][sCaptureDepth]; -#endif +#endif #ifdef CAPTURE_ALLOC_SOURCES #include @@ -191,7 +189,7 @@ static void ReallocEntry(long oldRequest, long newRequest, int newSize) entry->mAllocSize = newSize; gBfCaptureSourceAllocMap[newRequest] = *entry; gBfCaptureSourceAllocMap.erase(itr); - } + } } static void RemoveAllocEntry(long lRequest) @@ -203,13 +201,11 @@ static void RemoveAllocEntry(long lRequest) entry->mLoc->mTotalSize -= entry->mAllocSize; gBfCaptureSourceAllocMap.erase(itr); - } + } } - //const LOC_HASHES - #endif static int gBfNumAllocs = 0; @@ -246,7 +242,7 @@ static int BfAllocHook(int nAllocType, void *pvData, if (hProcess == NULL) { hProcess = GetCurrentProcess(); - BOOL worked = SymInitialize(hProcess, NULL, TRUE); + BOOL worked = SymInitialize(hProcess, NULL, TRUE); } if (nAllocType == _HOOK_ALLOC) @@ -317,7 +313,6 @@ static int BfAllocHook(int nAllocType, void *pvData, if ((captureAllocLoc->mIsEndpoint) && (foundSym)) { - } gHashCaptureAllocSize[hashVal] = captureAllocLoc; @@ -330,7 +325,6 @@ static int BfAllocHook(int nAllocType, void *pvData, continue; } - captureAllocLoc->mTotalSize += (int)nSize; CaptureAllocEntry entry; @@ -433,19 +427,18 @@ static int BfAllocHook(int nAllocType, void *pvData, #endif //BF_PLATFORM_WINDOWS - void BfReportMemory() { BfLogDbg("Used: %.2fM NumAllocs: %d Allocs: %.2fM\n", (gBfAllocCount - gBfFreeCount) / (1024.0 * 1024.0), gBfNumAllocs, gBfAllocCount / (1024.0 * 1024.0)); } void BfFullReportMemory() -{ +{ /*OutputDebugStrF("Testing OOB\n"); char* str = new char[12]; delete str; char c = str[1];*/ - + if (gBfParserCache != NULL) { MemReporter memReporter; @@ -457,7 +450,7 @@ void BfFullReportMemory() OutputDebugStrF("Used: %.2fM NumAllocs: %d Allocs: %.2fM\n", (gBfAllocCount - gBfFreeCount) / (1024.0 * 1024.0), gBfNumAllocs, gBfAllocCount / (1024.0 * 1024.0)); OutputDebugStrF("ChunkedDataBuffer allocated blocks: %d\n", ChunkedDataBuffer::sBlocksAllocated); - + if (gDebugManager != NULL) { MemReporter memReporter; @@ -493,7 +486,7 @@ void BfFullReportMemory() for (auto kv : byNameMap) { - //OutputDebugStrF("%dk %s\n", (kv.second + 1023) / 1024, kv.first.c_str()); + //OutputDebugStrF("%dk %s\n", (kv.second + 1023) / 1024, kv.first.c_str()); bySizeMap.insert(std::multimap::value_type(-kv.second, kv.first)); } @@ -528,7 +521,7 @@ struct _CrtMemBlockHeader //static _CrtMemBlockHeader* __acrt_last_block; void ShowMemoryUsage() -{ +{ #ifdef BF_PLATFORM_WINDOWS PROCESS_MEMORY_COUNTERS processMemCounters; processMemCounters.cb = sizeof(PROCESS_MEMORY_COUNTERS); @@ -538,7 +531,7 @@ void ShowMemoryUsage() static bool hasCheckpoint = true; _CrtMemState memState; - _CrtMemCheckpoint(&memState); + _CrtMemCheckpoint(&memState); //OutputDebugStrF("Crt Size: %dk\n", (int)(memState.lTotalCount / 1024)); char* names[6] = { "_FREE_BLOCK", "_NORMAL_BLOCK", "_CRT_BLOCK", "_IGNORE_BLOCK", "_CLIENT_BLOCK", "_MAX_BLOCKS" }; @@ -546,7 +539,7 @@ void ShowMemoryUsage() { OutputDebugStrF("%s : %d %dk\n", names[i], memState.lCounts[i], memState.lSizes[i] / 1024); } - + #ifdef _DEBUG // int64 totalCrtSize = 0; // int64 totalUseCrtSize = 0; @@ -568,9 +561,9 @@ void ShowMemoryUsage() while ((heapStatus = _heapwalk(&heapInfo)) == _HEAPOK) { heapSize += (int64)heapInfo._size; - } + } OutputDebugStrF("WALKED HEAP SIZE: %dk\n", heapSize / 1024); - + //_CrtMemDumpStatistics(&memState); #endif } @@ -591,9 +584,7 @@ BOOL WINAPI DllMain( HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) -{ - - +{ if (dwReason == DLL_PROCESS_ATTACH) { BpInit("127.0.0.1", "Beef IDE"); @@ -638,13 +629,13 @@ namespace BeefyDbg64 static _CrtMemState gStartMemCheckpoint; #endif BF_EXPORT void BF_CALLTYPE Debugger_Create() -{ +{ //TODO: Very slow, remove //_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF); //_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_EVERY_16_DF); //TODO: _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF /*| _CRTDBG_CHECK_EVERY_16_DF*/); //_CrtSetAllocHook(BfAllocHook); - + #ifdef BF_PLATFORM_WINDOWS _CrtMemCheckpoint(&gStartMemCheckpoint); #endif @@ -661,7 +652,7 @@ BF_EXPORT void BF_CALLTYPE Debugger_Create() gDebugManager->mDebugger64 = NULL; #else gDebugManager->mDebugger64 = CreateDebugger64(gDebugManager, NULL); -#endif +#endif #ifdef BF_PLATFORM_WINDOWS ::AllowSetForegroundWindow(ASFW_ANY); @@ -672,12 +663,11 @@ BF_EXPORT void BF_CALLTYPE Debugger_Create() BF_EXPORT void BF_CALLTYPE Debugger_SetCallbacks(void* callback) { - } BF_EXPORT void BF_CALLTYPE Debugger_FullReportMemory() { - //WdAllocTest(); + //WdAllocTest(); ShowMemoryUsage(); BfFullReportMemory(); } @@ -777,7 +767,7 @@ BF_EXPORT bool BF_CALLTYPE Debugger_OpenFile(const char* launchPath, const char* Array envBlock; if (envBlockPtr != NULL) - { + { if (envBlockSize != 0) envBlock.Insert(0, (uint8*)envBlockPtr, envBlockSize); } @@ -787,7 +777,7 @@ BF_EXPORT bool BF_CALLTYPE Debugger_OpenFile(const char* launchPath, const char* } BF_EXPORT bool BF_CALLTYPE Debugger_ComptimeAttach(void* bfCompiler) -{ +{ gDebugger = new CeDebugger(gDebugManager, (BfCompiler*)bfCompiler); return true; } @@ -808,12 +798,12 @@ BF_EXPORT void BF_CALLTYPE Debugger_SetSymSrvOptions(const char* symCacheDir, co if (!symStr.IsEmpty()) symServers.Add(symStr); startStr = cPtr; - } + } if (*cPtr == 0) break; } - + AutoCrit autoCrit(gDebugManager->mCritSect); gDebugManager->mSymSrvOptions.mCacheDir = symCacheDir; @@ -834,12 +824,11 @@ BF_EXPORT void BF_CALLTYPE Debugger_SetSymSrvOptions(const char* symCacheDir, co } gDebugManager->SetSourceServerCacheDir(); - } BF_EXPORT bool BF_CALLTYPE Debugger_OpenMiniDump(const char* fileName) { -#ifdef BF_PLATFORM_WINDOWS +#ifdef BF_PLATFORM_WINDOWS DbgMiniDump* dbgMiniDump = new DbgMiniDump(); bool result = dbgMiniDump->StartLoad(fileName); if (!result) @@ -847,7 +836,6 @@ BF_EXPORT bool BF_CALLTYPE Debugger_OpenMiniDump(const char* fileName) delete dbgMiniDump; return false; } - if (dbgMiniDump->GetTargetBitCount() == 32) gDebugger = CreateDebugger32(gDebugManager, dbgMiniDump); @@ -875,7 +863,7 @@ BF_EXPORT bool BF_CALLTYPE Debugger_Attach(int processId, BfDbgAttachFlags attac gDebugger = gDebugManager->mDebugger32; return true; } - + return false; } @@ -886,7 +874,7 @@ BF_EXPORT void BF_CALLTYPE Debugger_Run() BF_EXPORT bool BF_CALLTYPE Debugger_HotLoad(const char* fileNamesStr, int hotIdx) { - //DbgModule* dwarf = new DbgModule(gDebugger); + //DbgModule* dwarf = new DbgModule(gDebugger); //dwarf->ReadPE(fileName); Array fileNames; @@ -919,8 +907,8 @@ BF_EXPORT bool BF_CALLTYPE Debugger_HotLoad(const char* fileNamesStr, int hotIdx BF_EXPORT bool BF_CALLTYPE Debugger_LoadDebugVisualizers(const char* fileName) { String fn = fileName; - bool worked = false; - worked = gDebugManager->mDebugVisualizers->Load(fileName); + bool worked = false; + worked = gDebugManager->mDebugVisualizers->Load(fileName); if (!gDebugManager->mDebugVisualizers->mErrorString.empty()) { gDebugManager->mOutMessages.push_back(StrFormat("msg ERROR: %s\n", gDebugManager->mDebugVisualizers->mErrorString.c_str())); @@ -999,7 +987,7 @@ BF_EXPORT void BF_CALLTYPE Breakpoint_HotBindBreakpoint(Breakpoint* breakpoint, BF_EXPORT void BF_CALLTYPE Breakpoint_SetThreadId(Breakpoint* breakpoint, intptr threadId) { - BfLogDbg("Breakpoint %p set ThreadId=%d\n", breakpoint, threadId); + BfLogDbg("Breakpoint %p set ThreadId=%d\n", breakpoint, threadId); breakpoint->mThreadId = threadId; gDebugger->CheckBreakpoint(breakpoint); } @@ -1064,19 +1052,19 @@ BF_EXPORT void BF_CALLTYPE Breakpoint_Disable(Breakpoint* wdBreakpoint) BF_EXPORT void BF_CALLTYPE Debugger_CreateStepFilter(const char* filter, bool isGlobal, BfStepFilterKind filterKind) { - AutoCrit autoCrit(gDebugManager->mCritSect); + AutoCrit autoCrit(gDebugManager->mCritSect); StepFilter stepFilter; stepFilter.mFilterKind = filterKind; gDebugManager->mStepFilters[filter] = stepFilter; - gDebugManager->mStepFilterVersion++; + gDebugManager->mStepFilterVersion++; } BF_EXPORT void BF_CALLTYPE StepFilter_Delete(const char* filter) { - AutoCrit autoCrit(gDebugManager->mCritSect); + AutoCrit autoCrit(gDebugManager->mCritSect); bool didRemove = gDebugManager->mStepFilters.Remove(filter); BF_ASSERT(didRemove); - + gDebugManager->mStepFilterVersion++; } @@ -1110,7 +1098,7 @@ BF_EXPORT const char* BF_CALLTYPE Debugger_PopMessage() BF_EXPORT bool BF_CALLTYPE Debugger_HasMessages() { AutoCrit autoCrit(gDebugManager->mCritSect); - return gDebugManager->mOutMessages.size() != 0; + return gDebugManager->mOutMessages.size() != 0; } BF_EXPORT const char* BF_CALLTYPE Debugger_GetCurrentException() @@ -1177,7 +1165,7 @@ BF_EXPORT void BF_CALLTYPE Debugger_SetDisplayTypes(const char* referenceId, con displayInfo = &gDebugManager->mDefaultDisplayInfo; else gDebugManager->mDisplayInfos.TryAdd(referenceId, NULL, &displayInfo); - + if (formatStr != NULL) displayInfo->mFormatStr = formatStr; displayInfo->mIntDisplayType = (DwIntDisplayType)intDisplayType; @@ -1246,11 +1234,11 @@ BF_EXPORT const char* BF_CALLTYPE Debugger_EvaluateContinue() BF_EXPORT void BF_CALLTYPE Debugger_EvaluateContinueKeep() { auto debugger = gDebugger; - debugger->EvaluateContinueKeep(); + debugger->EvaluateContinueKeep(); } BF_EXPORT StringView BF_CALLTYPE Debugger_Evaluate(const char* expr, int callStackIdx, int cursorPos, int32 language, uint16 expressionFlags) -{ +{ auto debugger = gDebugger; if (debugger == NULL) @@ -1291,39 +1279,37 @@ BF_EXPORT const char* BF_CALLTYPE Debugger_EvaluateAtAddress(const char* expr, i BF_EXPORT const char* BF_CALLTYPE Debugger_GetAutoExpressions(int callStackIdx, uint64 memoryRangeStart, uint64 memoryRangeLen) { - String& outString = *gTLStrReturn.Get(); + String& outString = *gTLStrReturn.Get(); outString = gDebugger->GetAutoExpressions(callStackIdx, memoryRangeStart, memoryRangeLen); return outString.c_str(); } BF_EXPORT const char* BF_CALLTYPE Debugger_GetAutoLocals(int callStackIdx, bool showRegs) { - String& outString = *gTLStrReturn.Get(); + String& outString = *gTLStrReturn.Get(); outString = gDebugger->GetAutoLocals(callStackIdx, showRegs); return outString.c_str(); } BF_EXPORT const char* BF_CALLTYPE Debugger_CompactChildExpression(const char* expr, const char* parentExpr, int callStackIdx) { - String& outString = *gTLStrReturn.Get(); + String& outString = *gTLStrReturn.Get(); outString = gDebugger->CompactChildExpression(expr, parentExpr, callStackIdx); return outString.c_str(); } BF_EXPORT const char* BF_CALLTYPE Debugger_GetCollectionContinuation(const char* continuationData, int callStackIdx, int count) { - String& outString = *gTLStrReturn.Get(); + String& outString = *gTLStrReturn.Get(); outString = gDebugger->GetCollectionContinuation(continuationData, callStackIdx, count); return outString.c_str(); } - BF_EXPORT void BF_CALLTYPE Debugger_ForegroundTarget() { gDebugger->ForegroundTarget(); - - //BOOL worked = EnumThreadWindows(gDebugger->mProcessInfo.dwThreadId, WdEnumWindowsProc, 0); + //BOOL worked = EnumThreadWindows(gDebugger->mProcessInfo.dwThreadId, WdEnumWindowsProc, 0); //BF_ASSERT(worked); } @@ -1394,7 +1380,7 @@ BF_EXPORT int BF_CALLTYPE CallStack_GetBreakStackFrameIdx() BF_EXPORT const char* BF_CALLTYPE CallStack_GetStackFrameInfo(int stackFrameIdx, intptr* addr, const char** outFile, int32* outHotIdx, int32* outDefLineStart, int32* outDefLineEnd, int32* outLine, int32* outColumn, int32* outLanguage, int32* outStackSize, int8* outFlags) -{ +{ String& outString = *gTLStrReturn.Get(); String& outString2 = *gTLStrReturn2.Get(); @@ -1413,7 +1399,7 @@ BF_EXPORT const char* BF_CALLTYPE CallStack_GetStackFrameId(int stackFrameIdx) BF_EXPORT const char* BF_CALLTYPE Callstack_GetStackFrameOldFileInfo(int stackFrameIdx) { String& outString = *gTLStrReturn.Get(); - outString = gDebugger->Callstack_GetStackFrameOldFileInfo(stackFrameIdx); + outString = gDebugger->Callstack_GetStackFrameOldFileInfo(stackFrameIdx); return outString.c_str(); } @@ -1531,7 +1517,7 @@ BF_EXPORT int BF_CALLTYPE Debugger_LoadDebugInfoForModuleWith(const char* module } BF_EXPORT void BF_CALLTYPE Debugger_SetStepOverExternalFiles(bool stepOverExternalFiles) -{ +{ gDebugManager->mStepOverExternalFiles = stepOverExternalFiles; gDebugManager->mStepFilterVersion++; } @@ -1552,7 +1538,7 @@ BF_EXPORT Profiler* BF_CALLTYPE Debugger_StartProfiling(intptr threadId, char* d Profiler* profiler = gDebugger->StartProfiling(); profiler->mTargetThreadId = threadId; if (desc != NULL) - profiler->mDescription = desc; + profiler->mDescription = desc; profiler->mSamplesPerSecond = sampleRate; profiler->Start(); return profiler; @@ -1560,7 +1546,7 @@ BF_EXPORT Profiler* BF_CALLTYPE Debugger_StartProfiling(intptr threadId, char* d BF_EXPORT Profiler* BF_CALLTYPE Debugger_PopProfiler() { - Profiler* profiler = gDebugger->PopProfiler(); + Profiler* profiler = gDebugger->PopProfiler(); return profiler; } @@ -1570,7 +1556,6 @@ BF_EXPORT void BF_CALLTYPE Debugger_InitiateHotResolve(int flags) gDebugger->InitiateHotResolve((DbgHotResolveFlags)flags); } - BF_EXPORT intptr BF_CALLTYPE Debugger_GetDbgAllocHeapSize() { AutoCrit autoCrit(gDebugManager->mCritSect); @@ -1580,7 +1565,7 @@ BF_EXPORT intptr BF_CALLTYPE Debugger_GetDbgAllocHeapSize() BF_EXPORT const char* BF_CALLTYPE Debugger_GetDbgAllocInfo() { AutoCrit autoCrit(gDebugManager->mCritSect); - + String& outString = *gTLStrReturn.Get(); outString = gDebugger->GetDbgAllocInfo(); return outString.c_str(); @@ -1640,7 +1625,7 @@ BF_EXPORT NetResult* HTTP_GetFile(char* url, char* destPath) { AutoCrit autoCrit(gDebugManager->mNetManager->mThreadPool.mCritSect); - auto netResult = gDebugManager->mNetManager->QueueGet(url, destPath, false); + auto netResult = gDebugManager->mNetManager->QueueGet(url, destPath, false); netResult->mDoneEvent = new SyncEvent(); return netResult; } @@ -1674,7 +1659,7 @@ BF_EXPORT void HTTP_Delete(NetResult* netResult) netResult->mCurRequest->Cancel(); } netResult->mDoneEvent->WaitFor(-1); - } + } delete netResult; } @@ -1738,12 +1723,12 @@ BF_EXPORT void BF_CALLTYPE TimeTest(uint32 startTime) } BF_EXPORT void BF_CALLTYPE BFTest() -{ +{ struct DeferredResolveEntry2 { BfFieldDef* mFieldDef; int mTypeArrayIdx; - }; + }; DeferredResolveEntry2 entry = { NULL, 333 }; @@ -1752,10 +1737,10 @@ BF_EXPORT void BF_CALLTYPE BFTest() vec.push_back(DeferredResolveEntry2 { NULL, 222 } ); } -/// +/// -// __attribute__((weak)) +// __attribute__((weak)) // Debugger* Beefy::CreateDebugger32(DebugManager* debugManager, DbgMiniDump* miniDump) // { // return NULL; -// } +// } \ No newline at end of file diff --git a/IDEHelper/DebugManager.h b/IDEHelper/DebugManager.h index 2f8658b9..2c3ce576 100644 --- a/IDEHelper/DebugManager.h +++ b/IDEHelper/DebugManager.h @@ -44,7 +44,7 @@ public: StepFilter() { // Set global / local - mFilterKind = BfStepFilterKind_Filtered; + mFilterKind = BfStepFilterKind_Filtered; } bool IsFiltered(bool defaultValue) @@ -65,11 +65,11 @@ class DebugManager { public: Debugger* mDebugger32; - Debugger* mDebugger64; + Debugger* mDebugger64; CritSect mCritSect; Dictionary mStepFilters; - int mStepFilterVersion; + int mStepFilterVersion; std::deque mOutMessages; DebugVisualizers* mDebugVisualizers; diff --git a/IDEHelper/DebugVisualizers.cpp b/IDEHelper/DebugVisualizers.cpp index a95ed81c..eb5bdc5b 100644 --- a/IDEHelper/DebugVisualizers.cpp +++ b/IDEHelper/DebugVisualizers.cpp @@ -5,7 +5,7 @@ USING_NS_BF; void DebugVisualizers::Fail(const StringImpl& error) { if (mErrorString.length() != 0) - return; + return; mErrorString = StrFormat("Debug visualizer failure: %s in %s", error.c_str(), mCurFileName.c_str()); } @@ -125,7 +125,7 @@ bool DebugVisualizers::ReadFileTOML(const StringImpl& fileName) else if ((name == "DisplayString") | (name == "StringView")) { bool isStringView = name == "StringView"; - + if (value.is()) { for (auto& displayValue : ExpectArray(value)) @@ -143,7 +143,7 @@ bool DebugVisualizers::ReadFileTOML(const StringImpl& fileName) else Fail("Unexpected entry", value); } - + if (isStringView) entry->mStringViews.push_back(displayStringEntry); else @@ -158,7 +158,7 @@ bool DebugVisualizers::ReadFileTOML(const StringImpl& fileName) entry->mStringViews.push_back(displayStringEntry); else entry->mDisplayStrings.push_back(displayStringEntry); - } + } } else if (name == "Action") { @@ -193,7 +193,7 @@ bool DebugVisualizers::ReadFileTOML(const StringImpl& fileName) else if (name == "Condition") expandItem->mCondition = ExpectString(value); else - Fail("Unexpected entry", value); + Fail("Unexpected entry", value); } } } @@ -234,7 +234,7 @@ bool DebugVisualizers::ReadFileTOML(const StringImpl& fileName) else if (name == "LowerDimSizes") { for (auto& dimValue : ExpectArray(value)) - entry->mLowerDimSizes.push_back(ExpectString(dimValue)); + entry->mLowerDimSizes.push_back(ExpectString(dimValue)); } else if (name == "ValueNode") entry->mValuePointer = ExpectString(value); @@ -364,7 +364,7 @@ bool DebugVisualizers::Load(const StringImpl& fileNamesStr) fileNames.Add(fileNamesStr.Substring(startIdx, crPos - startIdx)); startIdx = crPos + 1; } - + HashContext hashCtx; for (auto fileName : fileNames) { @@ -376,7 +376,7 @@ bool DebugVisualizers::Load(const StringImpl& fileNamesStr) } hashCtx.Mixin(lastWrite); } - + Val128 hash = hashCtx.Finish128(); if ((hash == mHash) && (!hasError)) return true; @@ -394,13 +394,12 @@ bool DebugVisualizers::Load(const StringImpl& fileNamesStr) return success; } - DebugVisualizerEntry* DebugVisualizers::FindEntryForType(const StringImpl& typeName, DbgFlavor wantFlavor, Array* wildcardCaptures) -{ +{ //TODO: Do smarter name matching. Right now we just compare up to the '*' - + for (auto entry : mDebugVisualizers) - { + { if ((entry->mFlavor != DbgFlavor_Unknown) && (entry->mFlavor != wantFlavor)) continue; @@ -435,7 +434,7 @@ DebugVisualizerEntry* DebugVisualizers::FindEntryForType(const StringImpl& typeN int openDepth = 0; String wildcardCapture; while (true) - { + { typeC = *typeCharP; bool isSep = typeC == ','; @@ -459,7 +458,7 @@ DebugVisualizerEntry* DebugVisualizers::FindEntryForType(const StringImpl& typeN { typeCharP--; break; - } + } wildcardCapture += typeC; typeCharP++; @@ -476,14 +475,14 @@ DebugVisualizerEntry* DebugVisualizers::FindEntryForType(const StringImpl& typeN } else if (entryC != typeC) break; - + typeCharP++; entryCharP++; } if (wildcardCaptures != NULL) - wildcardCaptures->Clear(); - } + wildcardCaptures->Clear(); + } return NULL; } @@ -504,4 +503,4 @@ String DebugVisualizers::DoStringReplace(const StringImpl& origStr, const Array< } } return newString; -} +} \ No newline at end of file diff --git a/IDEHelper/DebugVisualizers.h b/IDEHelper/DebugVisualizers.h index aa25a744..1c797701 100644 --- a/IDEHelper/DebugVisualizers.h +++ b/IDEHelper/DebugVisualizers.h @@ -48,7 +48,7 @@ public: OwnedVector mExpandItems; CollectionType mCollectionType; - + String mSize; Array mLowerDimSizes; String mNextPointer; @@ -58,11 +58,11 @@ public: String mRightPointer; String mValueType; String mValuePointer; - String mTargetPointer; + String mTargetPointer; String mCondition; String mBuckets; String mEntries; - String mKey; + String mKey; bool mShowedError; bool mShowElementAddrs; @@ -76,7 +76,7 @@ public: mCollectionType = CollectionType_None; mShowedError = false; mShowElementAddrs = false; - } + } }; class DebugVisualizers @@ -87,9 +87,9 @@ public: String mCurFileName; const char* mSrcStr; OwnedVector mDebugVisualizers; - + void Fail(const StringImpl& error); - void Fail(const StringImpl& error, const toml::Value& value); + void Fail(const StringImpl& error, const toml::Value& value); String ExpectString(const toml::Value& value); bool ExpectBool(const toml::Value& value); diff --git a/IDEHelper/Debugger.cpp b/IDEHelper/Debugger.cpp index 727bbd99..d1bae9a5 100644 --- a/IDEHelper/Debugger.cpp +++ b/IDEHelper/Debugger.cpp @@ -5,7 +5,7 @@ USING_NS_BF; DbgModuleMemoryCache::DbgModuleMemoryCache(uintptr addr, int size) -{ +{ mAddr = addr; mSize = size; @@ -27,7 +27,7 @@ DbgModuleMemoryCache::DbgModuleMemoryCache(uintptr addr, int size) // mBlocks = new uint8*[1]; // mFlags = new DbgMemoryFlags[1]; // mSize = size; -// +// // if (makeCopy) // { // uint8* dataCopy = new uint8[size]; @@ -40,8 +40,8 @@ DbgModuleMemoryCache::DbgModuleMemoryCache(uintptr addr, int size) // else // { // mBlocks[0] = data; -// } -// +// } +// // mOwns = makeCopy; // mBlockCount = 1; // } @@ -75,7 +75,7 @@ DbgMemoryFlags DbgModuleMemoryCache::Read(uintptr addr, uint8* data, int size) int relAddr = (int)(addr - mAddr); int blockIdx = relAddr / mBlockSize; int curOffset = relAddr % mBlockSize; - + while (sizeLeft > 0) { uint8* block = mBlocks[blockIdx]; @@ -98,7 +98,7 @@ DbgMemoryFlags DbgModuleMemoryCache::Read(uintptr addr, uint8* data, int size) } sizeLeft -= readSize; curOffset = 0; - blockIdx++; + blockIdx++; } return flags; @@ -114,4 +114,4 @@ void DbgModuleMemoryCache::ReportMemory(MemReporter * memReporter) totalMemory += mBlockSize; } memReporter->Add(totalMemory); -} +} \ No newline at end of file diff --git a/IDEHelper/Debugger.h b/IDEHelper/Debugger.h index 984bd03c..ec7609d9 100644 --- a/IDEHelper/Debugger.h +++ b/IDEHelper/Debugger.h @@ -29,7 +29,7 @@ public: int mPendingHotBindIdx; int mHitCount; int mTargetHitCount; - DbgHitCountBreakKind mHitCountBreakKind; + DbgHitCountBreakKind mHitCountBreakKind; String mLogging; bool mBreakAfterLogging; @@ -40,7 +40,7 @@ public: Breakpoint* mLinkedSibling; // For things like templates with multiple imps on same source line bool mIsLinkedSibling; // Not in breakpoint list -public: +public: Breakpoint() { mRequestedLineNum = -1; @@ -50,11 +50,11 @@ public: mPendingHotBindIdx = -1; mHitCount = 0; mTargetHitCount = 0; - mHitCountBreakKind = DbgHitCountBreakKind_None; + mHitCountBreakKind = DbgHitCountBreakKind_None; mThreadId = -1; mHead = NULL; mLinkedSibling = NULL; - mIsLinkedSibling = false; + mIsLinkedSibling = false; mBreakAfterLogging = false; } @@ -62,7 +62,6 @@ public: virtual bool IsMemoryBreakpointBound() = 0; }; - enum DbgTypeKindFlags { DbgTypeKindFlag_None = 0, @@ -97,7 +96,7 @@ enum DwFloatDisplayType : int8 { DwFloatDisplayType_Default, DwFloatDisplayType_Minimal, - DwFloatDisplayType_Full, + DwFloatDisplayType_Full, DwFloatDisplayType_HexUpper, DwFloatDisplayType_HexLower, @@ -126,7 +125,7 @@ enum DwEvalExpressionFlags : int16 DwEvalExpressionFlag_MemoryAddress = 0x40, DwEvalExpressionFlag_MemoryWatch = 0x80, DwEvalExpressionFlag_Symbol = 0x100, - DwEvalExpressionFlag_StepIntoCalls = 0x200, + DwEvalExpressionFlag_StepIntoCalls = 0x200, DwEvalExpressionFlag_RawStr = 0x400, DwEvalExpressionFlag_AllowStringView = 0x800 }; @@ -148,7 +147,7 @@ struct DwDisplayInfo enum RunState { - RunState_NotStarted, + RunState_NotStarted, RunState_Running, RunState_Running_ToTempBreakpoint, RunState_Paused, @@ -158,7 +157,7 @@ enum RunState RunState_HotStep, RunState_Exception, RunState_Terminating, - RunState_Terminated, + RunState_Terminated, RunState_SearchingSymSrv, RunState_HotResolve }; @@ -203,16 +202,15 @@ enum DbgMemoryFlags : uint8 class DbgModuleMemoryCache { public: - -public: +public: uintptr mAddr; int mSize; int mBlockSize; uint8** mBlocks; DbgMemoryFlags* mFlags; int mBlockCount; - bool mOwns; + bool mOwns; public: DbgModuleMemoryCache(uintptr addr, int size); @@ -229,7 +227,7 @@ public: struct TypeData { intptr mCount; - intptr mSize; + intptr mSize; TypeData() { @@ -249,7 +247,7 @@ class Debugger { public: DebugManager* mDebugManager; - RunState mRunState; + RunState mRunState; DbgHotResolveData* mHotResolveData; bool mHadImageFindError; @@ -257,7 +255,7 @@ public: Debugger() { mDebugManager = NULL; - mRunState = RunState_NotStarted; + mRunState = RunState_NotStarted; mHotResolveData = NULL; mHadImageFindError = false; } @@ -283,7 +281,7 @@ public: virtual Breakpoint* CreateAddressBreakpoint(intptr address) = 0; virtual void CheckBreakpoint(Breakpoint* breakpoint) = 0; virtual void HotBindBreakpoint(Breakpoint* wdBreakpoint, int lineNum, int hotIdx) = 0; - virtual void DeleteBreakpoint(Breakpoint* wdBreakpoint) = 0; + virtual void DeleteBreakpoint(Breakpoint* wdBreakpoint) = 0; virtual void DetachBreakpoint(Breakpoint* wdBreakpoint) = 0; virtual void MoveBreakpoint(Breakpoint* wdBreakpoint, int lineNum, int wantColumn, bool rebindNow) = 0; virtual void MoveMemoryBreakpoint(Breakpoint* wdBreakpoint, intptr addr, int byteCount) = 0; @@ -306,13 +304,13 @@ public: virtual void EvaluateContinueKeep() = 0; virtual String EvaluateToAddress(const StringImpl& expr, int callStackIdx, int cursorPos) = 0; virtual String EvaluateAtAddress(const StringImpl& expr, intptr atAddr, int cursorPos) = 0; - virtual String GetCollectionContinuation(const StringImpl& continuationData, int callStackIdx, int count) = 0; + virtual String GetCollectionContinuation(const StringImpl& continuationData, int callStackIdx, int count) = 0; virtual String GetAutoExpressions(int callStackIdx, uint64 memoryRangeStart, uint64 memoryRangeLen) = 0; virtual String GetAutoLocals(int callStackIdx, bool showRegs) = 0; virtual String CompactChildExpression(const StringImpl& expr, const StringImpl& parentExpr, int callStackIdx) = 0; virtual String GetProcessInfo() = 0; virtual String GetThreadInfo() = 0; - virtual void SetActiveThread(int threadId) = 0; + virtual void SetActiveThread(int threadId) = 0; virtual int GetActiveThread() = 0; virtual void FreezeThread(int threadId) = 0; virtual void ThawThread(int threadId) = 0; @@ -321,12 +319,12 @@ public: virtual void UpdateCallStack(bool slowEarlyOut = true) = 0; virtual int GetCallStackCount() = 0; virtual int GetRequestedStackFrameIdx() = 0; - virtual int GetBreakStackFrameIdx() = 0; + virtual int GetBreakStackFrameIdx() = 0; virtual bool ReadMemory(intptr address, uint64 length, void* dest, bool local = false) = 0; virtual bool WriteMemory(intptr address, void* src, uint64 length) = 0; virtual DbgMemoryFlags GetMemoryFlags(intptr address) = 0; - virtual void UpdateRegisterUsage(int stackFrameIdx) = 0; - virtual void UpdateCallStackMethod(int stackFrameIdx) = 0; + virtual void UpdateRegisterUsage(int stackFrameIdx) = 0; + virtual void UpdateCallStackMethod(int stackFrameIdx) = 0; virtual void GetCodeAddrInfo(intptr addr, intptr inlineCallAddr, String* outFile, int* outHotIdx, int* outDefLineStart, int* outDefLineEnd, int* outLine, int* outColumn) = 0; virtual void GetStackAllocInfo(intptr addr, int* outThreadId, int* outStackIdx) = 0; virtual String GetStackFrameInfo(int stackFrameIdx, intptr* addr, String* outFile, int32* outHotIdx, int32* outDefLineStart, int32* outDefLineEnd, int32* outLine, int32* outColumn, int32* outLanguage, int32* outStackSize, int8* outFlags) = 0; @@ -340,8 +338,8 @@ public: virtual String GetAddressSymbolName(intptr address, bool demangle) = 0; virtual String DisassembleAtRaw(intptr address) = 0; virtual String DisassembleAt(intptr address) = 0; - virtual String FindLineCallAddresses(intptr address) = 0; - virtual String GetCurrentException() = 0; + virtual String FindLineCallAddresses(intptr address) = 0; + virtual String GetCurrentException() = 0; virtual String GetModulesInfo() = 0; virtual void SetAliasPath(const StringImpl& origPath, const StringImpl& localPath) = 0; virtual void CancelSymSrv() = 0; @@ -351,7 +349,7 @@ public: virtual int LoadDebugInfoForModule(const StringImpl& moduleName, const StringImpl& debugFileName) = 0; virtual void StopDebugging() = 0; virtual void Terminate() = 0; - virtual void Detach() = 0; + virtual void Detach() = 0; virtual Profiler* StartProfiling() = 0; virtual Profiler* PopProfiler() = 0; // Profiler requested by target program virtual void ReportMemory(MemReporter* memReporter) = 0; @@ -380,7 +378,7 @@ public: virtual bool IsSampling() = 0; virtual String GetOverview() = 0; virtual String GetThreadList() = 0; - virtual String GetCallTree(int threadId, bool reverse) = 0; + virtual String GetCallTree(int threadId, bool reverse) = 0; }; NS_BF_END diff --git a/IDEHelper/LLVMUtils.h b/IDEHelper/LLVMUtils.h index 71ec0575..415f257f 100644 --- a/IDEHelper/LLVMUtils.h +++ b/IDEHelper/LLVMUtils.h @@ -18,13 +18,13 @@ NS_BF_BEGIN /// raw_null_ostream - A raw_ostream that discards all output. -class debug_ostream : public llvm::raw_ostream +class debug_ostream : public llvm::raw_ostream { /// write_impl - See raw_ostream::write_impl. void write_impl(const char *Ptr, size_t size) override { StringT<1024> str; - str.Append(Ptr, size); + str.Append(Ptr, size); OutputDebugStr(str); } @@ -33,7 +33,7 @@ class debug_ostream : public llvm::raw_ostream uint64_t current_pos() const override { return 0; - } + } }; NS_BF_END \ No newline at end of file diff --git a/IDEHelper/NetManager.cpp b/IDEHelper/NetManager.cpp index 47ac716d..953ca872 100644 --- a/IDEHelper/NetManager.cpp +++ b/IDEHelper/NetManager.cpp @@ -83,10 +83,10 @@ void NetRequest::Cleanup() { if (mCURLMulti != NULL) curl_multi_remove_handle(mCURLMulti, mCURL); - if (mCURL != NULL) - curl_easy_cleanup(mCURL); - if (mCURLMulti != NULL) - curl_multi_cleanup(mCURLMulti); + if (mCURL != NULL) + curl_easy_cleanup(mCURL); + if (mCURLMulti != NULL) + curl_multi_cleanup(mCURLMulti); mCURL = NULL; mCURLMulti = NULL; @@ -160,7 +160,7 @@ void NetRequest::DoTransfer() // mFailed = true; // return; // } - + response_code = 0; curl_easy_getinfo(mCURL, CURLINFO_RESPONSE_CODE, &response_code); mNetManager->mDebugManager->OutputRawMessage(StrFormat("msgLo Result for '%s': %d\n", mURL.c_str(), response_code)); @@ -199,20 +199,20 @@ void NetRequest::DoTransfer() } if (response_code != 200) - { + { mOutFile.Close(); // Bad result mFailed = true; return; } - + BfLogDbg("NetManager successfully completed %s\n", mURL.c_str()); if (mCancelOnSuccess != NULL) mNetManager->Cancel(mCancelOnSuccess); if (!mOutFile.IsOpen()) - { + { mFailed = true; return; // No data } @@ -223,14 +223,14 @@ void NetRequest::DoTransfer() BfpFile_Rename(mOutTempPath.c_str(), mOutPath.c_str(), &renameResult); if (renameResult != BfpFileResult_Ok) - { - mFailed = true; + { + mFailed = true; } } void NetRequest::Perform() -{ - DoTransfer(); +{ + DoTransfer(); } #elif defined BF_PLATFORM_WINDOWS @@ -263,16 +263,16 @@ void NetRequest::Perform() Fail("Invalid URL"); return; } - + protoName = mURL.Substring(0, colonPos); serverName = mURL.Substring(colonPos + 3); - + int slashPos = (int)serverName.IndexOf('/'); if (slashPos != -1) { objectName = serverName.Substring(slashPos); serverName.RemoveToEnd(slashPos); - } + } mOutTempPath = mOutPath + "__partial"; @@ -291,8 +291,8 @@ void NetRequest::Perform() if (mOutFile.IsOpen()) mOutFile.Close(); - }; - + }; + bool isHttp = protoName.Equals("http", StringImpl::CompareKind_OrdinalIgnoreCase); bool isHttps = protoName.Equals("https", StringImpl::CompareKind_OrdinalIgnoreCase); if ((!isHttp) && (!isHttps)) @@ -350,23 +350,23 @@ void NetRequest::Perform() } if (mShowTracking) - { + { mNetManager->mDebugManager->OutputRawMessage(StrFormat("symsrv Getting '%s'", mURL.c_str())); } - uint8 buffer[4096]; + uint8 buffer[4096]; while (true) { DWORD dwBytesRead = 0; BOOL bRead = InternetReadFile(hHttpFile, buffer, 4096, &dwBytesRead); - if (dwBytesRead == 0) + if (dwBytesRead == 0) break; - if (!bRead) + if (!bRead) { //printf("InternetReadFile error : <%lu>\n", GetLastError()); Fail("Failed to receive"); return; - } + } if (!mOutFile.IsOpen()) { @@ -378,7 +378,7 @@ void NetRequest::Perform() } } mOutFile.Write(buffer, (int)dwBytesRead); - } + } BfLogDbg("NetManager successfully completed %s\n", mURL.c_str()); @@ -402,7 +402,6 @@ void NetRequest::Perform() void NetRequest::Cleanup() { - } #else @@ -414,7 +413,6 @@ void NetRequest::Perform() void NetRequest::Cleanup() { - } #endif @@ -437,7 +435,7 @@ NetRequest::~NetRequest() delete mResult; } - mNetManager->mRequestDoneEvent.Set(); + mNetManager->mRequestDoneEvent.Set(); } void NetRequest::Fail(const StringImpl& error) @@ -456,7 +454,7 @@ bool NetRequest::Cancel() } void NetRequest::ShowTracking() -{ +{ //mNetManager->mDebugManager->OutputMessage(StrFormat("Getting '%s'\n", mURL.c_str())); mNetManager->mDebugManager->OutputRawMessage(StrFormat("symsrv Getting '%s'", mURL.c_str())); mShowTracking = true; @@ -464,7 +462,6 @@ void NetRequest::ShowTracking() void NetManagerThread() { - } NetManager::NetManager() : mThreadPool(8, 1*1024*1024) @@ -480,13 +477,13 @@ NetManager::~NetManager() for (auto kv : mCachedResults) { delete kv.mValue; - } + } } NetRequest* NetManager::CreateGetRequest(const StringImpl& url, const StringImpl& destPath, bool useCache) { AutoCrit autoCrit(mThreadPool.mCritSect); - + NetRequest* netRequest = new NetRequest(); netRequest->mNetManager = this; netRequest->mURL = url; @@ -520,7 +517,7 @@ NetRequest* NetManager::CreateGetRequest(const StringImpl& url, const StringImpl NetResult* NetManager::QueueGet(const StringImpl& url, const StringImpl& destPath, bool useCache) { BfLogDbg("NetManager queueing %s %d\n", url.c_str(), useCache); - + auto netRequest = CreateGetRequest(url, destPath, useCache); auto netResult = netRequest->mResult; mThreadPool.AddJob(netRequest); @@ -528,7 +525,7 @@ NetResult* NetManager::QueueGet(const StringImpl& url, const StringImpl& destPat } bool NetManager::Get(const StringImpl& url, const StringImpl& destPath) -{ +{ NetRequest* netRequest = NULL; int waitCount = 0; while (true) @@ -539,7 +536,7 @@ bool NetManager::Get(const StringImpl& url, const StringImpl& destPath) mWaitingResult = NULL; NetResult* netResult; - if (mCachedResults.TryGetValue(url, &netResult)) + if (mCachedResults.TryGetValue(url, &netResult)) { if (netResult->mCurRequest == NULL) { @@ -547,7 +544,7 @@ bool NetManager::Get(const StringImpl& url, const StringImpl& destPath) return (!netResult->mFailed) && (FileExists(netResult->mOutPath)); } else if (!netResult->mCurRequest->mShowTracking) // Is done? - { + { if (!netResult->mCurRequest->mProcessing) { BfLogDbg("NetManager::Get pulling queued request into current thread %s\n", url.c_str()); @@ -557,9 +554,9 @@ bool NetManager::Get(const StringImpl& url, const StringImpl& destPath) break; } - mWaitingResult = netResult; + mWaitingResult = netResult; netResult->mCurRequest->ShowTracking(); - } + } } else { @@ -597,12 +594,12 @@ void NetManager::CancelAll() AutoCrit autoCrit(mThreadPool.mCritSect); if (mWaitingRequest != NULL) mWaitingRequest->Cancel(); - mThreadPool.CancelAll(); + mThreadPool.CancelAll(); } void NetManager::Clear() { - AutoCrit autoCrit(mThreadPool.mCritSect); + AutoCrit autoCrit(mThreadPool.mCritSect); BF_ASSERT(mWaitingResult == NULL); // The debugger thread shouldn't be waiting on anything, it should be detached at this point for (auto job : mThreadPool.mJobs) @@ -649,7 +646,7 @@ void NetManager::SetCancelOnSuccess(NetResult* dependentResult, NetResult* cance { AutoCrit autoCrit(mThreadPool.mCritSect); if (dependentResult->mCurRequest != NULL) - { + { dependentResult->mCurRequest->mCancelOnSuccess = cancelOnSucess; } -} +} \ No newline at end of file diff --git a/IDEHelper/NetManager.h b/IDEHelper/NetManager.h index 0b7aa101..623339d4 100644 --- a/IDEHelper/NetManager.h +++ b/IDEHelper/NetManager.h @@ -52,10 +52,10 @@ public: #else #endif mCancelling = false; - mFailed = false; + mFailed = false; mShowTracking = false; mResult = NULL; - mCancelOnSuccess = NULL; + mCancelOnSuccess = NULL; } ~NetRequest(); @@ -63,7 +63,7 @@ public: void Cleanup(); void Fail(const StringImpl& error); - bool Cancel() override; + bool Cancel() override; void Perform() override; void ShowTracking(); }; @@ -113,7 +113,7 @@ public: NetRequest* CreateGetRequest(const StringImpl& url, const StringImpl& destPath, bool useCache); NetResult* QueueGet(const StringImpl& url, const StringImpl& destPath, bool useCache); bool Get(const StringImpl& url, const StringImpl& destPath); - + void CancelAll(); void Clear(); void CancelCurrent(); diff --git a/IDEHelper/SpellChecker.cpp b/IDEHelper/SpellChecker.cpp index b28de411..0ea44a59 100644 --- a/IDEHelper/SpellChecker.cpp +++ b/IDEHelper/SpellChecker.cpp @@ -26,9 +26,9 @@ BF_EXPORT SpellChecker* BF_CALLTYPE SpellChecker_Create(const char* langPath) return NULL; } - SpellChecker* spellChecker = new SpellChecker(); + SpellChecker* spellChecker = new SpellChecker(); spellChecker->mHunHandle = hunHandle; - + return spellChecker; } diff --git a/IDEHelper/StrBloomMap.h b/IDEHelper/StrBloomMap.h index 78bc92c4..85e8277a 100644 --- a/IDEHelper/StrBloomMap.h +++ b/IDEHelper/StrBloomMap.h @@ -13,7 +13,7 @@ public: Beefy::BumpAllocator mAlloc; struct Entry - { + { T mValue; Entry* mNext; }; @@ -30,7 +30,7 @@ public: { mMap = map; mCurBucket = 0; - mCurEntry = NULL; + mCurEntry = NULL; } Iterator& operator++() @@ -67,7 +67,7 @@ public: public: int GetHash(const char* str, const char* strEnd) - { + { if (str == NULL) return 0; @@ -83,20 +83,20 @@ public: return curHash & 0x7FFFFFFF; } -public: +public: Entry** mHashHeads; public: StrBloomMap() { - mHashHeads = NULL; + mHashHeads = NULL; } void InsertUnique(int hash, T value) { if (mHashHeads == NULL) mHashHeads = (Entry**)mAlloc.AllocBytes(sizeof(Entry*) * HashSize, alignof(Entry*)); - + int hashIdx = hash % HashSize; Entry* headEntry = mHashHeads[hashIdx]; @@ -116,12 +116,12 @@ public: } Entry* FindFirst(const char* name) - { + { if (mHashHeads == NULL) return NULL; int hash = GetHash(name, NULL) % HashSize; - return mHashHeads[hash]; + return mHashHeads[hash]; } Iterator begin() @@ -138,4 +138,3 @@ public: }; NS_BF_DBG_END - diff --git a/IDEHelper/StrHashMap.h b/IDEHelper/StrHashMap.h index 0677673e..d698bf35 100644 --- a/IDEHelper/StrHashMap.h +++ b/IDEHelper/StrHashMap.h @@ -8,10 +8,10 @@ NS_BF_DBG_BEGIN template class StrHashMap { -public: +public: struct Entry { - T mValue; + T mValue; Entry* mNext; int mHash; }; @@ -102,7 +102,7 @@ public: public: Beefy::BumpAllocator mAlloc; Entry** mHashHeads; - int mHashSize; + int mHashSize; int mCount; public: @@ -140,7 +140,7 @@ public: Entry* checkEntry = mHashHeads[hashIdx]; while (checkEntry != NULL) { - auto nextEntry = checkEntry->mNext; + auto nextEntry = checkEntry->mNext; int newHashIdx = checkEntry->mHash % newHashSize; checkEntry->mNext = newHashHeads[newHashIdx]; newHashHeads[newHashIdx] = checkEntry; @@ -197,5 +197,4 @@ public: } }; - NS_BF_DBG_END diff --git a/IDEHelper/VSSupport.cpp b/IDEHelper/VSSupport.cpp index 262fc99e..a3bf55a7 100644 --- a/IDEHelper/VSSupport.cpp +++ b/IDEHelper/VSSupport.cpp @@ -56,7 +56,7 @@ struct Find_Result { int windows_sdk_version = 0; // Zero if no Windows SDK found. - wchar_t *windows_sdk_root = NULL; + wchar_t *windows_sdk_root = NULL; wchar_t* vs_version = NULL; wchar_t *vs_exe32_path = NULL; @@ -68,7 +68,7 @@ struct Find_Result { Find_Result find_visual_studio_and_windows_sdk(); void free_resources(Find_Result *result) { - free(result->windows_sdk_root); + free(result->windows_sdk_root); free(result->vs_version); free(result->vs_exe32_path); free(result->vs_exe64_path); @@ -95,10 +95,10 @@ void free_resources(Find_Result *result) { // I am not making this up: https://github.com/Microsoft/vswhere // // Several people have therefore found the need to solve this problem -// themselves. We referred to some of these other solutions when +// themselves. We referred to some of these other solutions when // figuring out what to do, most prominently ziglang's version, // by Ryan Saunderson. -// +// // I hate this kind of code. The fact that we have to do this at all // is stupid, and the actual maneuvers we need to go through // are just painful. If programming were like this all the time, @@ -148,7 +148,6 @@ public: #define defer const auto& CONCAT(defer__, __LINE__) = ExitScopeHelp() + [&]() - // COM objects for the ridiculous Microsoft craziness. struct DECLSPEC_UUID("B41463C3-8866-43B5-BC33-2B0676F7F42E") DECLSPEC_NOVTABLE ISetupInstance : public IUnknown @@ -178,7 +177,6 @@ struct DECLSPEC_UUID("42843719-DB4C-46C2-8E7C-64F1816EFD5B") DECLSPEC_NOVTABLE I STDMETHOD(GetInstanceForPath)(_In_z_ LPCWSTR wzPath, _Out_ ISetupInstance** ppInstance) = 0; }; - // The beginning of the actual code that does things. struct Version_Data { @@ -224,7 +222,6 @@ wchar_t *concat(wchar_t *a, wchar_t *b, wchar_t *c = nullptr, wchar_t *d = nullp typedef void(*Visit_Proc_W)(wchar_t *short_name, wchar_t *full_name, Version_Data *data); bool visit_files_w(wchar_t *dir_name, Version_Data *data, Visit_Proc_W proc) { - // Visit everything in one folder (non-recursively). If it's a directory // that doesn't start with ".", call the visit proc on it. The visit proc // will see if the filename conforms to the expected versioning pattern. @@ -253,7 +250,6 @@ bool visit_files_w(wchar_t *dir_name, Version_Data *data, Visit_Proc_W proc) { return true; } - wchar_t *find_windows_kit_root(HKEY key, wchar_t *version) { // Given a key to an already opened registry entry, // get the value stored under the 'version' subkey. @@ -340,7 +336,7 @@ void find_windows_kit_root(Find_Result *result) { // is stored in the same place in the registry. We open a key // to that place, first checking preferentially for a Windows 10 kit, // then, if that's not found, a Windows 8 kit. - + HKEY main_key; auto rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots", @@ -386,7 +382,6 @@ void find_windows_kit_root(Find_Result *result) { // If we get here, we failed to find anything. } - void find_visual_studio_by_fighting_through_microsoft_craziness(Find_Result *result) { // The name of this procedure is kind of cryptic. Its purpose is // to fight through Microsoft craziness. The things that the fine @@ -449,7 +444,7 @@ void find_visual_studio_by_fighting_through_microsoft_craziness(Find_Result *res if (!success) continue; auto version_bytes = (tools_file_size.QuadPart + 1) * 2; // Warning: This multiplication by 2 presumes there is no variable-length encoding in the wchars (wacky characters in the file could betray this expectation). - wchar_t *version = (wchar_t *)malloc(version_bytes); + wchar_t *version = (wchar_t *)malloc(version_bytes); auto read_result = fgetws(version, (int)version_bytes, f); if (!read_result) continue; @@ -465,15 +460,15 @@ void find_visual_studio_by_fighting_through_microsoft_craziness(Find_Result *res bool use = false; if ((os_file_exists(library_file)) && (os_file_exists(vs_exe64_link_path))) - { + { if (result->vs_version == NULL) { use = true; - } + } else if (wcscmp(version, result->vs_version) > 0) { use = true; - } + } } if (use) @@ -492,7 +487,7 @@ void find_visual_studio_by_fighting_through_microsoft_craziness(Find_Result *res free(library32_path); free(library64_path); } - + free(library_file); free(vs_exe64_link_path); @@ -562,7 +557,6 @@ void find_visual_studio_by_fighting_through_microsoft_craziness(Find_Result *res // If we get here, we failed to find anything. } - Find_Result find_visual_studio_and_windows_sdk() { Find_Result result; @@ -582,7 +576,7 @@ BF_EXPORT const char* BF_CALLTYPE VSSupport_Find() { Beefy::String& outString = *Beefy::gTLStrReturn.Get(); outString.clear(); - + Find_Result findResult = find_visual_studio_and_windows_sdk(); auto _AddPath = [&](wchar_t* str) @@ -593,11 +587,11 @@ BF_EXPORT const char* BF_CALLTYPE VSSupport_Find() outString += Beefy::UTF8Encode(str); } }; - + if (findResult.vs_exe32_path != NULL) outString += "TOOL32\t" + Beefy::UTF8Encode(findResult.vs_exe32_path) + "\n"; if (findResult.vs_exe64_path != NULL) - outString += "TOOL64\t" + Beefy::UTF8Encode(findResult.vs_exe64_path) + "\n"; + outString += "TOOL64\t" + Beefy::UTF8Encode(findResult.vs_exe64_path) + "\n"; if (findResult.windows_sdk_root != NULL) { @@ -630,7 +624,7 @@ BF_EXPORT const char* BF_CALLTYPE VSSupport_Find() outString += Beefy::UTF8Encode(findResult.vs_library64_path); outString += "\n"; } - + free_resources(&findResult); return outString.c_str(); diff --git a/IDEHelper/X64.cpp b/IDEHelper/X64.cpp index feebc3d2..4cced4ea 100644 --- a/IDEHelper/X64.cpp +++ b/IDEHelper/X64.cpp @@ -54,7 +54,7 @@ const char* X64CPURegisters::sCPURegisterNames[] = "NONE", // integer general registers (DO NOT REORDER THESE; must exactly match DbgModule x86 register mappings) - "RAX", + "RAX", "RDX", "RCX", "RBX", @@ -69,7 +69,7 @@ const char* X64CPURegisters::sCPURegisterNames[] = "R12", "R13", "R14", - "R15", + "R15", "RIP", "EFL", "GS", @@ -88,7 +88,7 @@ const char* X64CPURegisters::sCPURegisterNames[] = "R13D", "R14D", "R15D", - + "AX", "DX", "CX", @@ -141,7 +141,7 @@ const char* X64CPURegisters::sCPURegisterNames[] = "MM4", "MM5", "MM6", - "MM7", + "MM7", "XMM0_f64", "XMM1_f64", @@ -354,7 +354,7 @@ bool X64Instr::IsRep(bool& isPrefixOnly) bool X64Instr::IsReturn() { - const MCInstrDesc &instDesc = mX64->mInstrInfo->get(mMCInst.getOpcode()); + const MCInstrDesc &instDesc = mX64->mInstrInfo->get(mMCInst.getOpcode()); return (instDesc.getFlags() & (1 << MCID::Return)) != 0; } @@ -402,7 +402,7 @@ static int ConvertRegNum(const MCOperand& operand) return X64Reg_RBP; case llvm::X86::RSP: return X64Reg_RSP; - + case llvm::X86::R8: case llvm::X86::R8D: case llvm::X86::R8W: @@ -507,7 +507,7 @@ static int ConvertRegNum(const MCOperand& operand) case llvm::X86::XMM14: return X64Reg_M128_XMM14; case llvm::X86::XMM15: - return X64Reg_M128_XMM15; + return X64Reg_M128_XMM15; } return -1; @@ -573,13 +573,13 @@ bool X64Instr::GetImmediate(uint64* outImm) int X64Instr::GetJmpState(int flags) { - const MCInstrDesc &instDesc = mX64->mInstrInfo->get(mMCInst.getOpcode()); + const MCInstrDesc &instDesc = mX64->mInstrInfo->get(mMCInst.getOpcode()); if ((instDesc.getFlags() & (1 << MCID::Branch)) == 0) return -1; if (mMCInst.getNumOperands() < 1) return 0; - + #define FLAGVAR(abbr, name) int flag##abbr = ((flags & ((uint64)1 << X64CPURegisters::GetFlagBitForRegister(X64Reg_FLAG_##abbr##_##name))) != 0) ? 1 : 0 FLAGVAR(CF, CARRY); FLAGVAR(PF, PARITY); @@ -641,10 +641,10 @@ void X64Instr::MarkRegsUsed(Array& regsUsed, bool overrideForm) int opCode = instDesc.getOpcode(); auto form = (instDesc.TSFlags & llvm::X86II::FormMask); - - /*if (opCode == 1724) + + /*if (opCode == 1724) { - // MOVAPSrr is emitted for all moves between XMM registers, regardless of + // MOVAPSrr is emitted for all moves between XMM registers, regardless of // their actual format, so we just copy the actual RegForm form here if (instDesc.getNumOperands() != 2) return; @@ -655,7 +655,7 @@ void X64Instr::MarkRegsUsed(Array& regsUsed, bool overrideForm) int regNumFrom = ConvertRegNum(operand); if (regNumFrom == -1) // ?? - return; + return; while (std::max(regNumFrom, regNumTo) >= (int)regsUsed.size()) regsUsed.push_back(RegForm_Invalid); @@ -680,7 +680,7 @@ void X64Instr::MarkRegsUsed(Array& regsUsed, bool overrideForm) int checkIdx = opCode * 3; //const MCInstrDesc &instDesc = mX64->mInstrInfo->get(mMCInst.getOpcode()); - //auto form = (instDesc.TSFlags & llvm::X86II::FormMask); + //auto form = (instDesc.TSFlags & llvm::X86II::FormMask); for (int opIdx = 0; opIdx < std::min((int)instDesc.getNumOperands(), 3); opIdx++) { @@ -696,7 +696,7 @@ void X64Instr::MarkRegsUsed(Array& regsUsed, bool overrideForm) regsUsed[regNum] = regForm; checkIdx++; - } + } } } @@ -733,7 +733,7 @@ uint64 X64Instr::GetTarget(Debugger* debugger, X64CPURegisters* registers) if (operand.isImm()) { - auto targetAddr = (uint64)operand.getImm(); + auto targetAddr = (uint64)operand.getImm(); if (instDesc.OpInfo[opIdx].OperandType == MCOI::OPERAND_PCREL) targetAddr += mAddress + mSize; return targetAddr; @@ -756,10 +756,10 @@ bool X64Instr::PartialSimulate(Debugger* debugger, X64CPURegisters* registers) // auto form = (instDesc.TSFlags & llvm::X86II::FormMask); // // if ((form == llvm::X86II::MRMSrcMem) && (instDesc.NumOperands == 6)) -// { +// { // auto destReg = mMCInst.getOperand(llvm::X86::AddrBaseReg); // if (destReg.isReg()) -// { +// { // int regNum = 0; // int offset = 0; // if (GetIndexRegisterAndOffset(®Num, &offset)) @@ -767,7 +767,7 @@ bool X64Instr::PartialSimulate(Debugger* debugger, X64CPURegisters* registers) // uint64 addr = registers->mIntRegsArray[regNum] + offset; // uint64 val = 0; // debugger->ReadMemory(addr, 8, &val); -// +// // switch (destReg.getReg()) // { // @@ -779,7 +779,7 @@ bool X64Instr::PartialSimulate(Debugger* debugger, X64CPURegisters* registers) //// if ((form == llvm::X86II::MRMDestMem) || (form == llvm::X86II::MRMSrcMem) || //// ((form >= llvm::X86II::MRM0m) && (form <= llvm::X86II::MRM7m))) //// { -//// } +//// } // } // // if (instDesc.getOpcode() == X86::XOR8rr) @@ -792,7 +792,7 @@ bool X64Instr::PartialSimulate(Debugger* debugger, X64CPURegisters* registers) // if ((destReg.isReg()) && (srcReg.isReg())) // { // if (destReg.getReg() == srcReg.getReg()) -// { +// { // switch (destReg.getReg()) // { // case X86::AL: @@ -817,8 +817,8 @@ X64CPU::X64CPU() : mInstrInfo = NULL; mInstPrinter = NULL; - //InitializeAllTargets(); - + //InitializeAllTargets(); + auto& TheX86_64Target = llvm::getTheX86_64Target(); const char* triple = "x86_64-pc-mingw32"; @@ -835,7 +835,7 @@ X64CPU::X64CPU() : return; mInstrInfo = TheX86_64Target.createMCInstrInfo(); - + mMCContext = new MCContext(Triple(triple), mAsmInfo, mRegisterInfo, mSubtargetInfo); mMCObjectFileInfo = TheX86_64Target.createMCObjectFileInfo(*mMCContext, false); @@ -875,11 +875,11 @@ X64CPU::~X64CPU() } bool X64CPU::Decode(uint64 address, DbgModuleMemoryCache* memoryCache, X64Instr* inst) -{ +{ inst->mAddress = address; inst->mX64 = this; - uint64 size = 0; + uint64 size = 0; uint8 data[15]; memoryCache->Read(address, data, 15); @@ -939,7 +939,6 @@ void X64CPU::GetNextPC(uint64 baseAddress, const uint8* dataBase, int dataLength mDisAsm->CommentStream = &nulls(); ArrayRef dataArrayRef(dataPtr, dataLength - (dataPtr - dataBase)); MCDisassembler::DecodeStatus S = mDisAsm->getInstruction(mcInst, size, dataArrayRef, address, nulls()); - } bool X64CPU::IsReturnInstruction(X64Instr* inst) @@ -957,7 +956,7 @@ String X64CPU::InstructionToString(X64Instr* inst, uint64 addr) //mInstPrinter->CurPCRelImmOffset = addr + inst->GetLength(); mInstPrinter->printInst(&inst->mMCInst, addr, annotationsStr, *mSubtargetInfo, OS); //OS.flush(); - //llvm::StringRef str = OS.str(); + //llvm::StringRef str = OS.str(); String result; for (int idx = 0; idx < (int)insnStr.size(); idx++) @@ -991,21 +990,21 @@ String X64CPU::InstructionToString(X64Instr* inst, uint64 addr) } DbgBreakKind X64CPU::GetDbgBreakKind(uint64 address, DbgModuleMemoryCache* memoryCache, int64* regs, int64* outObjectPtr) -{ +{ // We've looking for a CMP BYTE PTR [], -0x80 // if is R12 then encoding takes an extra 2 bytes - X64Instr inst; + X64Instr inst; for (int checkLen = 5; checkLen >= 3; checkLen--) - { + { int offset = -3 - checkLen; if (!Decode(address + offset, memoryCache, &inst)) - continue; + continue; if (inst.GetLength() != checkLen) continue; - const MCInstrDesc &instDesc = mInstrInfo->get(inst.mMCInst.getOpcode()); + const MCInstrDesc &instDesc = mInstrInfo->get(inst.mMCInst.getOpcode()); if (!instDesc.isCompare()) continue; @@ -1052,18 +1051,18 @@ DbgBreakKind X64CPU::GetDbgBreakKind(uint64 address, DbgModuleMemoryCache* memor for (int offset = 3; offset <= 3; offset++) { if (!Decode(address - offset, memoryCache, &inst)) - continue; + continue; if (inst.GetLength() != 2) continue; - const MCInstrDesc &instDesc = mInstrInfo->get(inst.mMCInst.getOpcode()); + const MCInstrDesc &instDesc = mInstrInfo->get(inst.mMCInst.getOpcode()); if (!instDesc.isBranch()) continue; auto immediateType = (instDesc.TSFlags & llvm::X86II::ImmMask); if ((immediateType == llvm::X86II::Imm8PCRel) && (inst.mMCInst.getNumOperands() == 2)) - { + { auto immOp = inst.mMCInst.getOperand(1); if (!immOp.isImm()) continue; @@ -1181,4 +1180,4 @@ bool X64CPU::ParseInlineAsmInstructionLLVM(const StringImpl&asmInst, String& out //outError = StrFormat("%s: \"%s\"", diagMessage.c_str(), diagLineContents.c_str()); return result; -} +} \ No newline at end of file diff --git a/IDEHelper/X64.h b/IDEHelper/X64.h index 68085a93..3cadf1a5 100644 --- a/IDEHelper/X64.h +++ b/IDEHelper/X64.h @@ -36,7 +36,7 @@ enum X64CPURegister X64Reg_None = -1, // integer general registers (DO NOT REORDER THESE; must exactly match DbgModule X64 register mappings) - X64Reg_RAX = 0, + X64Reg_RAX = 0, X64Reg_RDX, X64Reg_RCX, X64Reg_RBX, @@ -51,7 +51,7 @@ enum X64CPURegister X64Reg_R12, X64Reg_R13, X64Reg_R14, - X64Reg_R15, + X64Reg_R15, X64Reg_RIP, X64Reg_EFL, X64Reg_GS, @@ -74,7 +74,7 @@ enum X64CPURegister X64Reg_AX, X64Reg_DX, X64Reg_CX, - X64Reg_BX, + X64Reg_BX, X64Reg_SI, X64Reg_DI, X64Reg_R8W, @@ -93,7 +93,7 @@ enum X64CPURegister X64Reg_AH, X64Reg_DH, X64Reg_CH, - X64Reg_BH, + X64Reg_BH, X64Reg_SIL, X64Reg_DIL, X64Reg_R8B, @@ -159,7 +159,7 @@ enum X64CPURegister X64Reg_XMM12_f32, X64Reg_XMM13_f32, X64Reg_XMM14_f32, - X64Reg_XMM15_f32, + X64Reg_XMM15_f32, // xmm registers X64Reg_XMM00, @@ -298,14 +298,14 @@ public: struct IntRegs { - int64 rax; + int64 rax; int64 rdx; int64 rcx; - int64 rbx; + int64 rbx; int64 rsi; int64 rdi; uint64 rbp; - uint64 rsp; + uint64 rsp; int64 r8; int64 r9; int64 r10; @@ -395,7 +395,7 @@ public: X64Reg_RSP, X64Reg_RBP, X64Reg_RSI, - X64Reg_RDI, + X64Reg_RDI, X64Reg_R8, X64Reg_R9, X64Reg_R10, @@ -466,7 +466,7 @@ public: bool IsCall(); bool IsRep(bool& isPrefixOnly); bool IsReturn(); - bool IsLoadAddress(); + bool IsLoadAddress(); bool GetIndexRegisterAndOffset(int* outRegister, int* outOffset); // IE: [ebp + 0x4] bool GetImmediate(uint64* outImm); int GetJmpState(int flags); @@ -476,7 +476,6 @@ public: bool PartialSimulate(Debugger* debugger, X64CPURegisters* registers); }; - class X64CPU { public: diff --git a/IDEHelper/X86.cpp b/IDEHelper/X86.cpp index 0b38a3c1..518cb331 100644 --- a/IDEHelper/X86.cpp +++ b/IDEHelper/X86.cpp @@ -159,10 +159,10 @@ bool X86Instr::StackAdjust(uint32& adjust) if (mMCInst.getOpcode() != X86::SUB32ri8) return true; - + auto operand0 = mMCInst.getOperand(0); if (operand0.getReg() != llvm::X86::ESP) - return true; + return true; auto operand2 = mMCInst.getOperand(2); if (!operand2.isImm()) return false; @@ -191,7 +191,7 @@ bool X86Instr::IsReturn() } bool X86Instr::IsRep(bool& isPrefixOnly) -{ +{ auto instFlags = mMCInst.getFlags(); if ((instFlags & (X86::IP_HAS_REPEAT_NE | X86::IP_HAS_REPEAT)) != 0) { @@ -208,7 +208,7 @@ bool X86Instr::IsRep(bool& isPrefixOnly) } bool X86Instr::IsLoadAddress() -{ +{ const MCInstrDesc &instDesc = mX86->mInstrInfo->get(mMCInst.getOpcode()); if (instDesc.NumOperands >= 6) { @@ -234,25 +234,25 @@ static int ConvertRegNum(const MCOperand& operand) case llvm::X86::CL: case llvm::X86::CH: case llvm::X86::ECX: - return X86Reg_ECX; + return X86Reg_ECX; case llvm::X86::DL: case llvm::X86::DH: case llvm::X86::EDX: - return X86Reg_EDX; + return X86Reg_EDX; case llvm::X86::BL: case llvm::X86::BH: case llvm::X86::EBX: - return X86Reg_EBX; + return X86Reg_EBX; case llvm::X86::ESP: - return X86Reg_ESP; + return X86Reg_ESP; case llvm::X86::EBP: - return X86Reg_EBP; + return X86Reg_EBP; case llvm::X86::ESI: - return X86Reg_ESI; + return X86Reg_ESI; case llvm::X86::EDI: - return X86Reg_EDI; + return X86Reg_EDI; case llvm::X86::EIP: - return X86Reg_EIP; + return X86Reg_EIP; case llvm::X86::EFLAGS: return X86Reg_EFL; @@ -272,7 +272,7 @@ static int ConvertRegNum(const MCOperand& operand) return X86Reg_FPST6; case llvm::X86::ST7: return X86Reg_FPST7; - + case llvm::X86::XMM0: return X86Reg_M128_XMM0; case llvm::X86::XMM1: @@ -299,9 +299,9 @@ bool X86Instr::GetIndexRegisterAndOffset(int* outRegister, int* outOffset) const MCInstrDesc &instDesc = mX86->mInstrInfo->get(mMCInst.getOpcode()); auto form = (instDesc.TSFlags & llvm::X86II::FormMask); - if ((form == llvm::X86II::MRMDestMem) || (form == llvm::X86II::MRMSrcMem) || + if ((form == llvm::X86II::MRMDestMem) || (form == llvm::X86II::MRMSrcMem) || ((form >= llvm::X86II::MRM0m) && (form <= llvm::X86II::MRM7m))) - { + { auto baseReg = mMCInst.getOperand(llvm::X86::AddrBaseReg); auto scaleAmt = mMCInst.getOperand(llvm::X86::AddrScaleAmt); auto indexReg = mMCInst.getOperand(llvm::X86::AddrIndexReg); @@ -320,12 +320,12 @@ bool X86Instr::GetIndexRegisterAndOffset(int* outRegister, int* outOffset) if ((baseReg.isReg()) && (scaleAmt.isImm()) && (scaleAmt.getImm() == 1) && (indexReg.isReg()) && (indexReg.getReg() == llvm::X86::NoRegister) && - (addrDisp.isImm())) + (addrDisp.isImm())) { int regNum = ConvertRegNum(baseReg); if (regNum == -1) return false; - *outRegister = regNum; + *outRegister = regNum; *outOffset = (int)addrDisp.getImm(); return true; } @@ -336,11 +336,11 @@ bool X86Instr::GetIndexRegisterAndOffset(int* outRegister, int* outOffset) bool X86Instr::GetImmediate(uint32* outImm) { const MCInstrDesc &instDesc = mX86->mInstrInfo->get(mMCInst.getOpcode()); - + auto immediateType = (instDesc.TSFlags & llvm::X86II::ImmMask); if ((immediateType == 0) && (mMCInst.getNumOperands() < 6)) return false; - + auto immOp = mMCInst.getOperand(5); if (!immOp.isImm()) return false; @@ -376,9 +376,9 @@ void X86Instr::MarkRegsUsed(Array& regsUsed, bool overrideForm) } uint32 X86Instr::GetTarget(Debugger* debugger, X86CPURegisters* registers) -{ +{ const MCInstrDesc &instDesc = mX86->mInstrInfo->get(mMCInst.getOpcode()); - + if (mMCInst.getNumOperands() < 1) return 0; @@ -389,7 +389,7 @@ uint32 X86Instr::GetTarget(Debugger* debugger, X86CPURegisters* registers) opIdx = 4; operand = mMCInst.getOperand(opIdx); } - + if (operand.isImm()) { auto targetAddr = (uint32)operand.getImm(); @@ -418,7 +418,7 @@ X86CPU::X86CPU() : mInstrInfo = NULL; mInstPrinter = NULL; - //InitializeAllTargets(); + //InitializeAllTargets(); auto& TheX86_32Target = getTheX86_32Target(); @@ -438,7 +438,7 @@ X86CPU::X86CPU() : //TargetOptions targetOptions; //TargetMachine* targetMachine = TheX86_32Target.createTargetMachine(triple, "x86", "", targetOptions); - //const MCInstrInfo* MII = targetMachine->getSubtargetImpl()->getInstrInfo(); + //const MCInstrInfo* MII = targetMachine->getSubtargetImpl()->getInstrInfo(); //STI->getIntr mInstrInfo = TheX86_32Target.createMCInstrInfo(); @@ -452,11 +452,11 @@ X86CPU::X86CPU() : mMCContext->setObjectFileInfo(mMCObjectFileInfo); MCDisassembler *disAsm = TheX86_32Target.createMCDisassembler(*mSubtargetInfo, *mMCContext); - mDisAsm = disAsm; + mDisAsm = disAsm; //TODO: LLVM3.8 - changed params /*mInstPrinter = TheX86_32Target.createMCInstPrinter(1, *mAsmInfo, - *mInstrInfo, *mRegisterInfo, *mSubtargetInfo);*/ + *mInstrInfo, *mRegisterInfo, *mSubtargetInfo);*/ mInstPrinter = TheX86_32Target.createMCInstPrinter(Triple(triple), 1, *mAsmInfo, *mInstrInfo, *mRegisterInfo); @@ -471,7 +471,7 @@ X86CPU::X86CPU() : extern "C" void LLVMShutdown(); X86CPU::~X86CPU() -{ +{ delete mInstPrinter; delete mDisAsm; delete mMCContext; @@ -485,11 +485,11 @@ X86CPU::~X86CPU() } bool X86CPU::Decode(uint32 address, DbgModuleMemoryCache* memoryCache, X86Instr* inst) -{ +{ inst->mAddress = address; inst->mX86 = this; - uint64 size = 0; + uint64 size = 0; uint8 data[15]; memoryCache->Read(address, data, 15); @@ -504,15 +504,15 @@ bool X86CPU::Decode(uint32 address, DbgModuleMemoryCache* memoryCache, X86Instr* bool X86CPU::Decode(uint32 baseAddress, const uint8* dataBase, int dataLength, const uint8* dataPtr, X86Instr* inst) { //X86GenericDisassembler assembler; - + //DisasmMemoryObject region((uint8*)dataBase, dataLength, baseAddress); //std::memorystream - + uint32 address = baseAddress + (uint32)(dataPtr - dataBase); inst->mAddress = address; inst->mX86 = this; - uint64 size = 0; + uint64 size = 0; //TODO: LLVM3.8 //MCDisassembler::DecodeStatus S = mDisAsm->getInstruction(inst->mMCInst, size, region, address, nulls(), inst->mAnnotationStream); @@ -526,7 +526,7 @@ bool X86CPU::Decode(uint32 baseAddress, const uint8* dataBase, int dataLength, c void X86CPU::GetNextPC(uint32 baseAddress, const uint8* dataBase, int dataLength, const uint8* dataPtr, uint32* regs, uint32 nextPCs[2]) { - //DisasmMemoryObject region((uint8*) dataBase, dataLength, baseAddress); + //DisasmMemoryObject region((uint8*) dataBase, dataLength, baseAddress); uint32 address = baseAddress + (uint32)(dataPtr - dataBase); uint64 size = 0; @@ -535,17 +535,16 @@ void X86CPU::GetNextPC(uint32 baseAddress, const uint8* dataBase, int dataLength mDisAsm->CommentStream = &nulls(); ArrayRef dataArrayRef(dataPtr, dataLength - (dataPtr - dataBase)); MCDisassembler::DecodeStatus S = mDisAsm->getInstruction(mcInst, size, dataArrayRef, address, nulls()); - } bool X86CPU::IsReturnInstruction(X86Instr* inst) { const MCInstrDesc &instDesc = mInstrInfo->get(inst->mMCInst.getOpcode()); - return (instDesc.getFlags() & (1< insnStr; @@ -553,8 +552,8 @@ String X86CPU::InstructionToString(X86Instr* inst, uint32 addr) //mInstPrinter->CurPCRelImmOffset = addr + inst->GetLength(); mInstPrinter->printInst(&inst->mMCInst, addr, annotationsStr, *mSubtargetInfo, OS); //OS.flush(); - //llvm::StringRef str = OS.str(); - + //llvm::StringRef str = OS.str(); + String result; for (int idx = 0; idx < (int)insnStr.size(); idx++) { @@ -570,8 +569,8 @@ String X86CPU::InstructionToString(X86Instr* inst, uint32 addr) else result.Append(c); } - - /*String result = String(insnStr.data(), insnStr.size()); + + /*String result = String(insnStr.data(), insnStr.size()); for (int i = 0; i < (int)result.length(); i++) { if (result[i] == '\t') @@ -671,12 +670,12 @@ int X86CPU::GetOpcodesForMnemonic(const StringImpl& mnemonic, Array& outOpc String s(mnemonic); std::transform(s.begin(), s.end(), s.begin(), ::tolower); std::pair range = mStringToOpcodeMap.equal_range(s); - + outOpcodes.Clear(); for (StringToOpcodeMap::iterator it = range.first; it != range.second; ++it) outOpcodes.push_back(it->second); - return (int)outOpcodes.size(); + return (int)outOpcodes.size(); } void X86CPU::GetClobbersForMnemonic(const StringImpl& mnemonic, int argCount, Array& outImplicitClobberRegNums, int& outClobberArgCount, bool& outMayClobberMem) diff --git a/IDEHelper/X86.h b/IDEHelper/X86.h index 76af5d72..0640ec52 100644 --- a/IDEHelper/X86.h +++ b/IDEHelper/X86.h @@ -193,7 +193,7 @@ public: struct XmmDReg { double d[2]; - }; + }; struct XmmI32Reg { @@ -289,7 +289,7 @@ public: llvm::raw_svector_ostream mAnnotationStream; static uint8 sRegForm[]; - X86Instr() : + X86Instr() : mAnnotationStream(mAnnotationStr) { mX86 = NULL; @@ -297,7 +297,7 @@ public: mSize = 0; } - int GetLength(); + int GetLength(); bool StackAdjust(uint32& adjust); bool IsBranch(); bool IsCall(); @@ -340,7 +340,7 @@ public: bool Decode(uint32 baseAddress, const uint8* dataBase, int dataLength, const uint8* dataPtr, X86Instr* inst); uint32 DecodeThunk(uint32 address, DbgModuleMemoryCache* memoryCache) { return 0; } - bool IsReturnInstruction(X86Instr* inst); + bool IsReturnInstruction(X86Instr* inst); String InstructionToString(X86Instr* inst, uint32 addr); void GetNextPC(uint32 baseAddress, const uint8* dataBase, int dataLength, const uint8* dataPtr, uint32* regs, uint32 nextPCs[2]); diff --git a/IDEHelper/X86Target.cpp b/IDEHelper/X86Target.cpp index 5a5b80fa..0812b0f2 100644 --- a/IDEHelper/X86Target.cpp +++ b/IDEHelper/X86Target.cpp @@ -103,4 +103,4 @@ X86Target::~X86Target() { delete mX86CPU; delete mX64CPU; -} +} \ No newline at end of file