1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 12:32:20 +02:00

Improved emit marker resolve/build selection, emitted Go To Definition

This commit is contained in:
Brian Fiete 2022-07-02 10:32:19 -07:00
parent faca458283
commit 6ded6a37cc
14 changed files with 216 additions and 44 deletions

View file

@ -3155,6 +3155,8 @@ bool BfAutoComplete::CheckFixit(BfAstNode* node)
{
if (mIgnoreFixits)
return false;
if (mModule == NULL)
return false;
if (mCompiler->mResolvePassData->mResolveType != BfResolveType_GetFixits)
return false;
if (!IsAutocompleteLineNode(node))

View file

@ -592,6 +592,8 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods)
auto owner = methodInstance->mMethodInstanceGroup->mOwner;
auto autoComplete = mCompiler->GetAutoComplete();
BF_ASSERT(!module->mAwaitingFinish);
if ((resolveParser != NULL) && (methodInstance->mMethodDef->mDeclaringType != NULL) && (methodInstance->mMethodDef->mDeclaringType->GetDefinition()->mSource != resolveParser))
{
@ -599,6 +601,39 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods)
if ((mCompiler->mResolvePassData != NULL) && (mCompiler->mResolvePassData->mHasCursorIdx))
{
auto parser = methodInstance->mMethodDef->mDeclaringType->GetLastSource()->ToParser();
if ((parser != NULL) && (autoComplete != NULL) && (autoComplete->mModule == NULL))
{
bool emitHasCursor = false;
for (auto& checkEntry : mCompiler->mResolvePassData->mEmitEmbedEntries)
{
if (checkEntry.mValue.mCursorIdx >= 0)
emitHasCursor = true;
}
if (emitHasCursor)
{
// Go To Definition in an emit mixin?
BfParser** foundParserPtr = NULL;
if (mCompiler->mResolvePassData->mCompatParserMap.TryAdd(parser, NULL, &foundParserPtr))
{
*foundParserPtr = NULL;
for (auto checkParser : mCompiler->mResolvePassData->mParsers)
{
if ((checkParser->mFileName == parser->mFileName) && (checkParser->mOrigSrcLength == parser->mOrigSrcLength) &&
(memcmp(checkParser->mSrc, parser->mSrc, checkParser->mOrigSrcLength) == 0))
{
*foundParserPtr = checkParser;
}
}
}
auto* compatParser = *foundParserPtr;
if (compatParser != NULL)
allow = true;
}
}
if ((parser != NULL) && (parser->mCursorIdx >= 0))
allow = true;
}
@ -616,13 +651,12 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods)
{
if (!mCompiler->mIsResolveOnly)
BF_ASSERT(!methodInstance->mIsReified || methodInstance->mDeclModule->mIsModuleMutable);
auto autoComplete = mCompiler->GetAutoComplete();
if ((autoComplete != NULL) && (autoComplete->mModule == NULL))
{
autoComplete->mModule = methodInstance->mDeclModule;
autoComplete->SetModule(methodInstance->mDeclModule);
ProcessMethod(methodInstance);
autoComplete->mModule = NULL;
autoComplete->SetModule(NULL);
}
else
ProcessMethod(methodInstance);

View file

@ -6232,6 +6232,15 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, BfMethodInstance*
((autoComplete->mResolveType != BfResolveType_Autocomplete) &&
(autoComplete->mResolveType != BfResolveType_Autocomplete_HighPri) &&
(autoComplete->mResolveType != BfResolveType_GetResultString));
for (auto& entry : mModule->mCompiler->mResolvePassData->mEmitEmbedEntries)
{
if (entry.mValue.mCursorIdx >= 0)
{
// Needed for Go To Definition in Compiler.Mixin
wantQuickEval = false;
}
}
}
if (wantQuickEval)

View file

@ -11509,6 +11509,7 @@ void BfModule::ClearConstData()
mStringCharPtrPool.Clear();
mStringPoolRefs.Clear();
mUnreifiedStringPoolRefs.Clear();
mStaticFieldRefs.Clear();
}
BfTypedValue BfModule::GetTypedValueFromConstant(BfConstant* constant, BfIRConstHolder* constHolder, BfType* wantType)
@ -14860,11 +14861,11 @@ BfTypedValue BfModule::ReferenceStaticField(BfFieldInstance* fieldInstance)
}
}
if ((mIsScratchModule) && (mCompiler->mIsResolveOnly))
{
if ((mIsScratchModule) && (mCompiler->mIsResolveOnly) && (!fieldInstance->mOwner->IsInstanceOf(mCompiler->mCompilerTypeDef)))
{
// Just fake it for the extern and unspecialized modules
// We can't do this for compilation because unreified methods with default params need to get acutal global variable refs
return BfTypedValue(mBfIRBuilder->CreateConstNull(), fieldInstance->GetResolvedType(), true);
// We can't do this for compilation because unreified methods with default params need to get actual global variable refs
return BfTypedValue(mBfIRBuilder->CreateConstNull(), fieldInstance->GetResolvedType(), true);
}
BfIRValue* globalValuePtr = NULL;

View file

@ -2378,8 +2378,8 @@ void BfModule::UpdateCEEmit(CeEmitContext* ceEmitContext, BfTypeInstance* typeIn
if (emitParser->mSourceClassifier != NULL)
{
emitParser->mSourceClassifier->VisitChild(emitParser->mRootNode);
emitParser->mSourceClassifier->VisitChild(emitParser->mSidechannelRootNode);
emitParser->mSourceClassifier->VisitChild(emitParser->mErrorRootNode);
emitParser->mSourceClassifier->DeferNodes(emitParser->mSidechannelRootNode);
emitParser->mSourceClassifier->DeferNodes(emitParser->mErrorRootNode);
}
if (typeInstance->mTypeDef->mEmitParent != NULL)

View file

@ -64,6 +64,7 @@ public:
BfResolveType mResolveType;
Array<BfParser*> mParsers;
Dictionary<BfParser*, BfParser*> mCompatParserMap;
BfAutoComplete* mAutoComplete;
Array<BfTypeDef*> mAutoCompleteTempTypes; // Contains multiple values when we have nested types
Dictionary<BfTypeDef*, BfStaticSearch> mStaticSearchMap;

View file

@ -694,6 +694,19 @@ void BfSourceClassifier::MarkSkipped(BfAstNode* node)
MarkSkipped(node->GetSrcStart(), node->GetSrcEnd());
}
void BfSourceClassifier::DeferNodes(BfBlock* block)
{
for (auto child : *block)
mDeferredNodes.Add(child);
}
void BfSourceClassifier::FlushDeferredNodes()
{
for (auto node : mDeferredNodes)
VisitChild(node);
mDeferredNodes.Clear();
}
void BfSourceClassifier::Visit(BfTypeAliasDeclaration* typeDeclaration)
{
if (typeDeclaration->mIgnoreDeclaration)

View file

@ -70,6 +70,7 @@ public:
BfAstNode* mPrevNode;
BfAstNode* mCurMember;
BfLocalMethodDeclaration* mCurLocalMethodDeclaration;
Array<BfAstNode*> mDeferredNodes;
public:
void HandleLeafNode(BfAstNode* node);
@ -86,6 +87,8 @@ public:
void Handle(BfTypeDeclaration* typeDeclaration);
void MarkSkipped(int startPos, int endPos);
void MarkSkipped(BfAstNode* node);
void DeferNodes(BfBlock* block);
void FlushDeferredNodes();
public:
BfSourceClassifier(BfParser* bfParser, CharData* charData);

View file

@ -4075,6 +4075,10 @@ BF_EXPORT void* BfResolvePassData_GetEmitEmbedData(BfResolvePassData* resolvePas
return NULL;
*revision = emitEmbedEntry->mRevision;
*charCount = emitEmbedEntry->mParser->mSrcLength;
auto emitParser = emitEmbedEntry->mParser;
emitParser->mSourceClassifier->FlushDeferredNodes();
return emitEmbedEntry->mParser->mSourceClassifier->mCharData;
}