| 34 | } |
| 35 | |
| 36 | BfTypedValue BfConstResolver::Resolve(BfExpression* expr, BfType* wantType, BfConstResolveFlags flags) |
| 37 | { |
| 38 | mBfEvalExprFlags = (BfEvalExprFlags)(mBfEvalExprFlags | BfEvalExprFlags_Comptime); |
| 39 | |
| 40 | // Handle the 'int[?] val = .(1, 2, 3)' case |
| 41 | if ((flags & BfConstResolveFlag_ArrayInitSize) != 0) |
| 42 | { |
| 43 | if (auto uninitExpr = BfNodeDynCast<BfUninitializedExpression>(expr)) |
| 44 | { |
| 45 | BfAstNode* initializer = NULL; |
| 46 | int arraySize = -1; |
| 47 | |
| 48 | if (mModule->mContext->mCurTypeState != NULL) |
| 49 | { |
| 50 | if (mModule->mContext->mCurTypeState->mCurFieldDef != NULL) |
| 51 | initializer = mModule->mContext->mCurTypeState->mCurFieldDef->GetInitializer(); |
| 52 | if (mModule->mContext->mCurTypeState->mCurVarInitializer != NULL) |
| 53 | initializer = mModule->mContext->mCurTypeState->mCurVarInitializer; |
| 54 | if (mModule->mContext->mCurTypeState->mArrayInitializerSize != -1) |
| 55 | arraySize = mModule->mContext->mCurTypeState->mArrayInitializerSize; |
| 56 | } |
| 57 | |
| 58 | if (initializer != NULL) |
| 59 | { |
| 60 | if (auto invocationExpr = BfNodeDynCast<BfInvocationExpression>(initializer)) |
| 61 | { |
| 62 | if (auto memberRefExpr = BfNodeDynCast<BfMemberReferenceExpression>(invocationExpr->mTarget)) |
| 63 | { |
| 64 | // Dot-initialized |
| 65 | if (memberRefExpr->mTarget == NULL) |
| 66 | arraySize = (int)invocationExpr->mArguments.size(); |
| 67 | } |
| 68 | else if (auto indexerExpr = BfNodeDynCast<BfIndexerExpression>(invocationExpr->mTarget)) |
| 69 | { |
| 70 | if (indexerExpr->mArguments.size() == 0) |
| 71 | { |
| 72 | // Inferred-type sized array initializer |
| 73 | arraySize = (int)invocationExpr->mArguments.size(); |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | if (arraySize != -1) |
| 80 | { |
| 81 | mResult = BfTypedValue(mModule->GetConstValue(arraySize), mModule->GetPrimitiveType(BfTypeCode_IntPtr)); |
| 82 | return mResult; |
| 83 | } |
| 84 | else |
| 85 | { |
| 86 | mResult = BfTypedValue(mModule->mBfIRBuilder->GetUndefConstValue(mModule->mBfIRBuilder->GetPrimitiveType(BfTypeCode_IntPtr)), mModule->GetPrimitiveType(BfTypeCode_IntPtr)); |
| 87 | return mResult; |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | bool explicitCast = (flags & BfConstResolveFlag_ExplicitCast) != 0; |
| 93 | bool noCast = (flags & BfConstResolveFlag_NoCast) != 0; |
no test coverage detected