MCPcopy Create free account
hub / github.com/beefytech/Beef / Resolve

Method Resolve

IDEHelper/Compiler/BfConstResolver.cpp:36–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36BfTypedValue 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;

Callers 10

GetCustomAttributesMethod · 0.45
DoMethodDeclarationMethod · 0.45
GetSymbolReferencesMethod · 0.45
ConstResolveMethod · 0.45
DoInvocationMethod · 0.45
EvaluateToVariantMethod · 0.45
DoHashMethod · 0.45

Calls 15

BfTypedValueClass · 0.85
GetInitializerMethod · 0.80
GetConstValueMethod · 0.80
GetUndefConstValueMethod · 0.80
GetCompilerFieldValueMethod · 0.80
GetStringPoolIdxMethod · 0.80
GetStringObjectValueMethod · 0.80
HasStringIdMethod · 0.80
FixIntUnknownMethod · 0.80
FixValueActualizationMethod · 0.80
sizeMethod · 0.45
GetPrimitiveTypeMethod · 0.45

Tested by

no test coverage detected