mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-14 14:24:10 +02:00
Made Compiler 'Caller' values work inside mixins
This commit is contained in:
parent
1519a60104
commit
8406e00a60
3 changed files with 52 additions and 0 deletions
|
@ -6889,6 +6889,12 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, const BfTypedValu
|
||||||
argValue = BfTypedValue(mModule->GetStringObjectValue(projectName),
|
argValue = BfTypedValue(mModule->GetStringObjectValue(projectName),
|
||||||
mModule->ResolveTypeDef(mModule->mCompiler->mStringTypeDef));
|
mModule->ResolveTypeDef(mModule->mCompiler->mStringTypeDef));
|
||||||
}
|
}
|
||||||
|
else if (strcmp(globalVar->mName, "#ProjectName") == 0)
|
||||||
|
{
|
||||||
|
String projectName = methodInstance->mMethodDef->mDeclaringType->mProject->mName;
|
||||||
|
argValue = BfTypedValue(mModule->GetStringObjectValue(projectName),
|
||||||
|
mModule->ResolveTypeDef(mModule->mCompiler->mStringTypeDef));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
argValue = mModule->GetCompilerFieldValue(globalVar->mName);
|
argValue = mModule->GetCompilerFieldValue(globalVar->mName);
|
||||||
|
@ -15185,6 +15191,7 @@ void BfExprEvaluator::InjectMixin(BfAstNode* targetSrc, BfTypedValue target, boo
|
||||||
auto rootMethodState = mModule->mCurMethodState->GetRootMethodState();
|
auto rootMethodState = mModule->mCurMethodState->GetRootMethodState();
|
||||||
|
|
||||||
BfMixinState* mixinState = rootMethodState->mMixinStates.Alloc();
|
BfMixinState* mixinState = rootMethodState->mMixinStates.Alloc();
|
||||||
|
mixinState->mInjectFilePosition = mModule->mCurFilePosition;
|
||||||
mixinState->mPrevMixinState = curMethodState->mMixinState;
|
mixinState->mPrevMixinState = curMethodState->mMixinState;
|
||||||
mixinState->mLocalsStartIdx = (int)mModule->mCurMethodState->mLocals.size();
|
mixinState->mLocalsStartIdx = (int)mModule->mCurMethodState->mLocals.size();
|
||||||
mixinState->mMixinMethodInstance = methodInstance;
|
mixinState->mMixinMethodInstance = methodInstance;
|
||||||
|
|
|
@ -13521,6 +13521,50 @@ BfTypedValue BfModule::GetCompilerFieldValue(const StringImpl& str)
|
||||||
if (mProject != NULL)
|
if (mProject != NULL)
|
||||||
return BfTypedValue(GetStringObjectValue(mProject->mName), ResolveTypeDef(mCompiler->mStringTypeDef));
|
return BfTypedValue(GetStringObjectValue(mProject->mName), ResolveTypeDef(mCompiler->mStringTypeDef));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mCurMethodState->mMixinState != NULL)
|
||||||
|
{
|
||||||
|
if (str == "#CallerLineNum")
|
||||||
|
{
|
||||||
|
return BfTypedValue(GetConstValue(mCurMethodState->mMixinState->mInjectFilePosition.mCurLine + 1), GetPrimitiveType(BfTypeCode_Int32));
|
||||||
|
}
|
||||||
|
else if (str == "#CallerFilePath")
|
||||||
|
{
|
||||||
|
String filePath = "";
|
||||||
|
if (mCurMethodState->mMixinState->mInjectFilePosition.mFileInstance != NULL)
|
||||||
|
filePath = mCurMethodState->mMixinState->mInjectFilePosition.mFileInstance->mParser->mFileName;
|
||||||
|
return BfTypedValue(GetStringObjectValue(filePath), ResolveTypeDef(mCompiler->mStringTypeDef));
|
||||||
|
}
|
||||||
|
else if (str == "#CallerFileName")
|
||||||
|
{
|
||||||
|
String filePath = "";
|
||||||
|
if (mCurMethodState->mMixinState->mInjectFilePosition.mFileInstance != NULL)
|
||||||
|
filePath = mCurMethodState->mMixinState->mInjectFilePosition.mFileInstance->mParser->mFileName;
|
||||||
|
return BfTypedValue(GetStringObjectValue(GetFileName(filePath)), ResolveTypeDef(mCompiler->mStringTypeDef));
|
||||||
|
}
|
||||||
|
else if (str == "#CallerFileDir")
|
||||||
|
{
|
||||||
|
String filePath = "";
|
||||||
|
if (mCurMethodState->mMixinState->mInjectFilePosition.mFileInstance != NULL)
|
||||||
|
filePath = mCurMethodState->mMixinState->mInjectFilePosition.mFileInstance->mParser->mFileName;
|
||||||
|
return BfTypedValue(GetStringObjectValue(GetFileDir(filePath)), ResolveTypeDef(mCompiler->mStringTypeDef));
|
||||||
|
}
|
||||||
|
else if (str == "#CallerMemberName")
|
||||||
|
{
|
||||||
|
String memberName = "";
|
||||||
|
if (mCurMethodState->mMixinState->mMixinMethodInstance)
|
||||||
|
memberName = MethodToString(mCurMethodState->mMixinState->mMixinMethodInstance);
|
||||||
|
return BfTypedValue(GetStringObjectValue(memberName), ResolveTypeDef(mCompiler->mStringTypeDef));
|
||||||
|
}
|
||||||
|
else if (str == "#CallerProject")
|
||||||
|
{
|
||||||
|
BfProject* project = NULL;
|
||||||
|
project = mCurMethodState->mMixinState->mMixinMethodInstance->mMethodDef->mDeclaringType->mProject;
|
||||||
|
if (project != NULL)
|
||||||
|
return BfTypedValue(GetStringObjectValue(mProject->mName), ResolveTypeDef(mCompiler->mStringTypeDef));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (str == "#TimeLocal")
|
if (str == "#TimeLocal")
|
||||||
{
|
{
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
|
|
|
@ -767,6 +767,7 @@ public:
|
||||||
BfAstNode* mSource;
|
BfAstNode* mSource;
|
||||||
BfScopeData* mCallerScope;
|
BfScopeData* mCallerScope;
|
||||||
BfScopeData* mTargetScope; // Equals caller scope unless user explicitly calls specifies scope override
|
BfScopeData* mTargetScope; // Equals caller scope unless user explicitly calls specifies scope override
|
||||||
|
BfFilePosition mInjectFilePosition;
|
||||||
BfMethodInstance* mMixinMethodInstance;
|
BfMethodInstance* mMixinMethodInstance;
|
||||||
BfAstNode* mResultExpr;
|
BfAstNode* mResultExpr;
|
||||||
int mLocalsStartIdx;
|
int mLocalsStartIdx;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue