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

Method LookupTypeProp

IDEHelper/Compiler/BfExprEvaluator.cpp:12283–12616  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12281}
12282
12283bool BfExprEvaluator::LookupTypeProp(BfTypeOfExpression* typeOfExpr, BfIdentifierNode* propName)
12284{
12285 auto typeType = mModule->ResolveTypeDef(mModule->mCompiler->mTypeTypeDef);
12286
12287 BfType* type;
12288 //
12289 {
12290 // We ignore errors because we go through the normal Visit(BfTypeOfExpression) if this fails, which will throw the error again
12291 SetAndRestoreValue<bool> prevIgnoreErrors(mModule->mIgnoreErrors, true);
12292 if (auto genericTypeRef = BfNodeDynCast<BfGenericInstanceTypeRef>(typeOfExpr->mTypeRef))
12293 {
12294 SetAndRestoreValue<bool> prevIgnoreErrors(mModule->mIgnoreErrors, true);
12295 type = mModule->ResolveTypeRefAllowUnboundGenerics(typeOfExpr->mTypeRef, BfPopulateType_Identity);
12296 }
12297 else
12298 {
12299 type = ResolveTypeRef(typeOfExpr->mTypeRef, BfPopulateType_Identity, BfResolveTypeRefFlag_IgnoreLookupError);
12300 }
12301 }
12302
12303 if (type == NULL)
12304 {
12305 mResult = mModule->GetDefaultTypedValue(mModule->ResolveTypeDef(mModule->mCompiler->mTypeTypeDef));
12306 return false;
12307 }
12308
12309 bool success = true;
12310
12311 defer(
12312 {
12313 if (success)
12314 mModule->AddDependency(type, mModule->mCurTypeInstance, BfDependencyMap::DependencyFlag_TypeSignature);
12315 });
12316
12317 // We want to try to avoid triggering OnTypeInit for basic info
12318 mModule->PopulateType(type, BfPopulateType_Interfaces_Direct);
12319 auto typeInstance = type->ToTypeInstance();
12320
12321 auto _BoolResult = [&](bool val)
12322 {
12323 mResult = BfTypedValue(mModule->mBfIRBuilder->CreateConst(BfTypeCode_Boolean, val ? 1 : 0), mModule->GetPrimitiveType(BfTypeCode_Boolean));
12324 };
12325
12326 auto _Int32Result = [&](int32 val)
12327 {
12328 mResult = BfTypedValue(mModule->GetConstValue32(val), mModule->GetPrimitiveType(BfTypeCode_Int32));
12329 };
12330
12331 String memberName;
12332 propName->ToString(memberName);
12333
12334 bool handled = true;
12335 if (memberName == "IsTypedPrimitive")
12336 _BoolResult(type->IsPrimitiveType());
12337 else if (memberName == "IsObject")
12338 _BoolResult(type->IsObject());
12339 else if (memberName == "IsValueType")
12340 _BoolResult(type->IsValueType());

Callers

nothing calls this directly

Calls 15

BfTypedValueClass · 0.85
AddDependencyMethod · 0.80
GetConstValue32Method · 0.80
GetInstStrideMethod · 0.80
GetUndefConstValueMethod · 0.80
MapTypeMethod · 0.80
CreateTypeDataRefMethod · 0.80
CheckTypeRefMethod · 0.80
ResolveTypeDefMethod · 0.45
GetDefaultTypedValueMethod · 0.45

Tested by

no test coverage detected