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

Method DoForLess

IDEHelper/Compiler/BfStmtEvaluator.cpp:6272–6455  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6270}
6271
6272void BfModule::DoForLess(BfForEachStatement* forEachStmt)
6273{
6274 UpdateSrcPos(forEachStmt);
6275
6276 auto startBB = mBfIRBuilder->GetInsertBlock();
6277 auto condBB = mBfIRBuilder->CreateBlock("forless.cond", true);
6278 mBfIRBuilder->SetInsertPoint(condBB);
6279
6280 BfScopeData scopeData;
6281 // We set mIsLoop later
6282 if (forEachStmt->mLabelNode != NULL)
6283 scopeData.mLabelNode = forEachStmt->mLabelNode->mLabel;
6284 mCurMethodState->AddScope(&scopeData);
6285 NewScopeState();
6286
6287 auto autoComplete = mCompiler->GetAutoComplete();
6288
6289 auto isLet = BfNodeDynCast<BfLetTypeReference>(forEachStmt->mVariableTypeRef) != 0;
6290 auto isVar = BfNodeDynCast<BfVarTypeReference>(forEachStmt->mVariableTypeRef) != 0;
6291
6292 BfTypedValue target;
6293 BfType* varType = NULL;
6294 bool didInference = false;
6295 if (isLet || isVar)
6296 {
6297 if (forEachStmt->mCollectionExpression != NULL)
6298 target = CreateValueFromExpression(forEachStmt->mCollectionExpression);
6299 if (target)
6300 {
6301 FixIntUnknown(target);
6302 varType = target.mType;
6303 }
6304
6305 if (autoComplete != NULL)
6306 autoComplete->CheckVarResolution(forEachStmt->mVariableTypeRef, varType);
6307 didInference = true;
6308 }
6309 else
6310 {
6311 varType = ResolveTypeRef(forEachStmt->mVariableTypeRef, BfPopulateType_Data, BfResolveTypeRefFlag_AllowRef);
6312 if (forEachStmt->mCollectionExpression != NULL)
6313 target = CreateValueFromExpression(forEachStmt->mCollectionExpression, varType);
6314 }
6315 if (varType == NULL)
6316 varType = GetPrimitiveType(BfTypeCode_IntPtr);
6317
6318 BfDeferredLocalAssignData deferredLocalAssignData(mCurMethodState->mCurScope);
6319 deferredLocalAssignData.mIsIfCondition = true;
6320 deferredLocalAssignData.ExtendFrom(mCurMethodState->mDeferredLocalAssignData, true);
6321 deferredLocalAssignData.mVarIdBarrier = mCurMethodState->GetRootMethodState()->mCurLocalVarId;
6322 SetAndRestoreValue<BfDeferredLocalAssignData*> prevDLA(mCurMethodState->mDeferredLocalAssignData, &deferredLocalAssignData);
6323
6324 deferredLocalAssignData.mIsIfCondition = false;
6325
6326 // The "extend chain" is only valid for the conditional -- since that expression may contain unconditionally executed and
6327 // conditionally executed code (in the case of "(GetVal(out a) && GetVal(out b))" for example
6328 mCurMethodState->mDeferredLocalAssignData->BreakExtendChain();
6329

Callers

nothing calls this directly

Calls 15

FailFunction · 0.85
TypeToStringFunction · 0.85
AddScopeMethod · 0.80
CheckVarResolutionMethod · 0.80
ExtendFromMethod · 0.80
GetRootMethodStateMethod · 0.80
BreakExtendChainMethod · 0.80
CreateCmpLTEMethod · 0.80
CreateCmpLTMethod · 0.80
CreateAddMethod · 0.80
SetHadReturnMethod · 0.80

Tested by

no test coverage detected