mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-14 14:24:10 +02:00
Better handling of this/base for autocomplete, colorization, goto def
This commit is contained in:
parent
b856f48006
commit
590df7aec7
6 changed files with 71 additions and 20 deletions
|
@ -977,6 +977,27 @@ bool BfAstNode::Equals(const StringImpl& str)
|
||||||
return strncmp(str.GetPtr(), source->mSrc + mSrcStart, len) == 0;
|
return strncmp(str.GetPtr(), source->mSrc + mSrcStart, len) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BfAstNode::Equals(const char* str)
|
||||||
|
{
|
||||||
|
auto source = GetSourceData();
|
||||||
|
const char* ptrLhs = source->mSrc + mSrcStart;
|
||||||
|
const char* ptrLhsEnd = source->mSrc + mSrcEnd;
|
||||||
|
const char* ptrRhs = str;
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
char cRhs = *(ptrRhs++);
|
||||||
|
if (cRhs == 0)
|
||||||
|
return ptrLhs == ptrLhsEnd;
|
||||||
|
if (ptrLhs == ptrLhsEnd)
|
||||||
|
return false;
|
||||||
|
char cLhs = *(ptrLhs++);
|
||||||
|
if (cLhs != cRhs)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void BfBlock::Init(const SizedArrayImpl<BfAstNode*>& vec, BfAstAllocator* alloc)
|
void BfBlock::Init(const SizedArrayImpl<BfAstNode*>& vec, BfAstAllocator* alloc)
|
||||||
|
|
|
@ -1031,6 +1031,7 @@ public:
|
||||||
StringView ToStringView();
|
StringView ToStringView();
|
||||||
void ToString(StringImpl& str);
|
void ToString(StringImpl& str);
|
||||||
bool Equals(const StringImpl& str);
|
bool Equals(const StringImpl& str);
|
||||||
|
bool Equals(const char* str);
|
||||||
void Init(BfParser* bfParser);
|
void Init(BfParser* bfParser);
|
||||||
void Accept(BfStructuralVisitor* bfVisitor);
|
void Accept(BfStructuralVisitor* bfVisitor);
|
||||||
static void ClassAccept(BfAstNode* node, BfStructuralVisitor* bfVisitor) { bfVisitor->Visit(node); }
|
static void ClassAccept(BfAstNode* node, BfStructuralVisitor* bfVisitor) { bfVisitor->Visit(node); }
|
||||||
|
|
|
@ -2330,9 +2330,11 @@ void BfAutoComplete::CheckLocalRef(BfIdentifierNode* identifierNode, BfLocalVari
|
||||||
if (mResolveType == BfResolveType_GoToDefinition)
|
if (mResolveType == BfResolveType_GoToDefinition)
|
||||||
{
|
{
|
||||||
if (IsAutocompleteNode(identifierNode))
|
if (IsAutocompleteNode(identifierNode))
|
||||||
{
|
{
|
||||||
if (varDecl->mNameNode != NULL)
|
if (varDecl->mNameNode != NULL)
|
||||||
SetDefinitionLocation(varDecl->mNameNode);
|
SetDefinitionLocation(varDecl->mNameNode);
|
||||||
|
else if (varDecl->mIsThis)
|
||||||
|
SetDefinitionLocation(mModule->mCurTypeInstance->mTypeDef->GetRefNode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mResolveType == BfResolveType_GetSymbolInfo)
|
else if (mResolveType == BfResolveType_GetSymbolInfo)
|
||||||
|
@ -2351,15 +2353,19 @@ void BfAutoComplete::CheckLocalRef(BfIdentifierNode* identifierNode, BfLocalVari
|
||||||
if (rootMethodInstance == NULL)
|
if (rootMethodInstance == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto resolvePassData = mModule->mCompiler->mResolvePassData;
|
if (varDecl->mIsThis)
|
||||||
mReplaceLocalId = varDecl->mLocalVarId;
|
return;
|
||||||
|
|
||||||
|
auto resolvePassData = mModule->mCompiler->mResolvePassData;
|
||||||
mDefType = mModule->mCurTypeInstance->mTypeDef;
|
mDefType = mModule->mCurTypeInstance->mTypeDef;
|
||||||
|
|
||||||
|
mReplaceLocalId = varDecl->mLocalVarId;
|
||||||
mDefMethod = rootMethodInstance->mMethodDef;
|
mDefMethod = rootMethodInstance->mMethodDef;
|
||||||
if (mInsertStartIdx == -1)
|
if (mInsertStartIdx == -1)
|
||||||
{
|
{
|
||||||
mInsertStartIdx = identifierNode->GetSrcStart();
|
mInsertStartIdx = identifierNode->GetSrcStart();
|
||||||
mInsertEndIdx = identifierNode->GetSrcEnd();
|
mInsertEndIdx = identifierNode->GetSrcEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7170,7 +7170,7 @@ void BfExprEvaluator::LookupQualifiedName(BfQualifiedNameNode* nameNode, bool ig
|
||||||
bool wasBaseLookup = false;
|
bool wasBaseLookup = false;
|
||||||
if (auto qualifiedLeftName = BfNodeDynCast<BfQualifiedNameNode>(nameNode->mLeft))
|
if (auto qualifiedLeftName = BfNodeDynCast<BfQualifiedNameNode>(nameNode->mLeft))
|
||||||
{
|
{
|
||||||
if ((qualifiedLeftName->mRight->GetSrcLength() == 4) && (qualifiedLeftName->mRight->ToStringView() == "base"))
|
if (CheckIsBase(qualifiedLeftName->mRight))
|
||||||
{
|
{
|
||||||
wasBaseLookup = true;
|
wasBaseLookup = true;
|
||||||
auto type = mModule->ResolveTypeRef(qualifiedLeftName->mLeft, NULL);
|
auto type = mModule->ResolveTypeRef(qualifiedLeftName->mLeft, NULL);
|
||||||
|
@ -7338,7 +7338,7 @@ void BfExprEvaluator::LookupQualifiedName(BfQualifiedNameNode* nameNode, bool ig
|
||||||
if (mPropDef != NULL)
|
if (mPropDef != NULL)
|
||||||
{
|
{
|
||||||
mOrigPropTarget = origResult;
|
mOrigPropTarget = origResult;
|
||||||
if ((nameNode->mLeft->ToString() == "base") || (wasBaseLookup))
|
if ((CheckIsBase(nameNode->mLeft)) || (wasBaseLookup))
|
||||||
{
|
{
|
||||||
mPropDefBypassVirtual = true;
|
mPropDefBypassVirtual = true;
|
||||||
}
|
}
|
||||||
|
@ -7367,7 +7367,7 @@ void BfExprEvaluator::LookupQualifiedName(BfAstNode* nameNode, BfIdentifierNode*
|
||||||
bool wasBaseLookup = false;
|
bool wasBaseLookup = false;
|
||||||
if (auto qualifiedLeftName = BfNodeDynCast<BfQualifiedNameNode>(nameLeft))
|
if (auto qualifiedLeftName = BfNodeDynCast<BfQualifiedNameNode>(nameLeft))
|
||||||
{
|
{
|
||||||
if (qualifiedLeftName->mRight->ToString() == "base")
|
if (CheckIsBase(qualifiedLeftName->mRight))
|
||||||
{
|
{
|
||||||
wasBaseLookup = true;
|
wasBaseLookup = true;
|
||||||
auto type = mModule->ResolveTypeRef(qualifiedLeftName->mLeft, NULL);
|
auto type = mModule->ResolveTypeRef(qualifiedLeftName->mLeft, NULL);
|
||||||
|
@ -7549,7 +7549,7 @@ void BfExprEvaluator::LookupQualifiedName(BfAstNode* nameNode, BfIdentifierNode*
|
||||||
if (mPropDef != NULL)
|
if (mPropDef != NULL)
|
||||||
{
|
{
|
||||||
mOrigPropTarget = origResult;
|
mOrigPropTarget = origResult;
|
||||||
if ((nameLeft->ToString() == "base") || (wasBaseLookup))
|
if ((CheckIsBase(nameLeft)) || (wasBaseLookup))
|
||||||
{
|
{
|
||||||
mPropDefBypassVirtual = true;
|
mPropDefBypassVirtual = true;
|
||||||
}
|
}
|
||||||
|
@ -7760,19 +7760,20 @@ void BfExprEvaluator::Visit(BfQualifiedNameNode* nameNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
void BfExprEvaluator::Visit(BfThisExpression* thisExpr)
|
void BfExprEvaluator::Visit(BfThisExpression* thisExpr)
|
||||||
{
|
{
|
||||||
mResult = mModule->GetThis();
|
mResult = mModule->GetThis();
|
||||||
if (!mResult)
|
if (!mResult)
|
||||||
{
|
{
|
||||||
mModule->Fail("Static methods don't have 'this'", thisExpr);
|
mModule->Fail("Static methods don't have 'this'", thisExpr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//if (mResult.mType->IsTypedPrimitive())
|
|
||||||
{
|
auto autoComplete = GetAutoComplete();
|
||||||
|
if ((autoComplete != NULL) && (autoComplete->IsAutocompleteNode(thisExpr)))
|
||||||
mResultLocalVar = mModule->GetThisVariable();
|
autoComplete->SetDefinitionLocation(mModule->mCurTypeInstance->mTypeDef->GetRefNode());
|
||||||
mResultFieldInstance = NULL;
|
|
||||||
}
|
mResultLocalVar = mModule->GetThisVariable();
|
||||||
|
mResultFieldInstance = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BfExprEvaluator::Visit(BfBaseExpression* baseExpr)
|
void BfExprEvaluator::Visit(BfBaseExpression* baseExpr)
|
||||||
|
@ -7787,6 +7788,11 @@ void BfExprEvaluator::Visit(BfBaseExpression* baseExpr)
|
||||||
auto baseType = mModule->mCurTypeInstance->mBaseType;
|
auto baseType = mModule->mCurTypeInstance->mBaseType;
|
||||||
if (baseType == NULL)
|
if (baseType == NULL)
|
||||||
baseType = mModule->mContext->mBfObjectType;
|
baseType = mModule->mContext->mBfObjectType;
|
||||||
|
|
||||||
|
auto autoComplete = GetAutoComplete();
|
||||||
|
if ((autoComplete != NULL) && (autoComplete->IsAutocompleteNode(baseExpr)))
|
||||||
|
autoComplete->SetDefinitionLocation(baseType->mTypeDef->GetRefNode());
|
||||||
|
|
||||||
mModule->PopulateType(baseType, BfPopulateType_Data);
|
mModule->PopulateType(baseType, BfPopulateType_Data);
|
||||||
mResult = mModule->Cast(baseExpr, mResult, baseType, BfCastFlags_Explicit);
|
mResult = mModule->Cast(baseExpr, mResult, baseType, BfCastFlags_Explicit);
|
||||||
}
|
}
|
||||||
|
@ -13408,10 +13414,8 @@ void BfExprEvaluator::DoInvocation(BfAstNode* target, BfMethodBoundExpression* m
|
||||||
GetAutoComplete()->CheckMemberReference(qualifiedName->mLeft, qualifiedName->mDot, qualifiedName->mRight);
|
GetAutoComplete()->CheckMemberReference(qualifiedName->mLeft, qualifiedName->mDot, qualifiedName->mRight);
|
||||||
|
|
||||||
if (qualifiedName->mLeft->GetSrcLength() == 4)
|
if (qualifiedName->mLeft->GetSrcLength() == 4)
|
||||||
{
|
{
|
||||||
StringT<16> leftName;
|
if (CheckIsBase(qualifiedName->mLeft))
|
||||||
qualifiedName->mLeft->ToString(leftName);
|
|
||||||
if (leftName == "base")
|
|
||||||
bypassVirtual = true;
|
bypassVirtual = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14281,6 +14285,21 @@ void BfExprEvaluator::MakeResultAsValue()
|
||||||
mResultFieldInstance = NULL;
|
mResultFieldInstance = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BfExprEvaluator::CheckIsBase(BfAstNode* checkNode)
|
||||||
|
{
|
||||||
|
if (checkNode == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
auto autoComplete = GetAutoComplete();
|
||||||
|
if ((autoComplete != NULL) && (autoComplete->IsAutocompleteNode(checkNode)))
|
||||||
|
{
|
||||||
|
if ((mModule->mCurTypeInstance != NULL) && (mModule->mCurTypeInstance->mBaseType != NULL))
|
||||||
|
autoComplete->SetDefinitionLocation(mModule->mCurTypeInstance->mBaseType->mTypeDef->GetRefNode());
|
||||||
|
}
|
||||||
|
|
||||||
|
return checkNode->Equals("base");
|
||||||
|
}
|
||||||
|
|
||||||
bool BfExprEvaluator::CheckModifyResult(BfTypedValue typedVal, BfAstNode* refNode, const char* modifyType, bool onlyNeedsMut)
|
bool BfExprEvaluator::CheckModifyResult(BfTypedValue typedVal, BfAstNode* refNode, const char* modifyType, bool onlyNeedsMut)
|
||||||
{
|
{
|
||||||
BfLocalVariable* localVar = NULL;
|
BfLocalVariable* localVar = NULL;
|
||||||
|
|
|
@ -336,6 +336,7 @@ public:
|
||||||
void MarkResultUsed();
|
void MarkResultUsed();
|
||||||
void MarkResultAssigned();
|
void MarkResultAssigned();
|
||||||
void MakeResultAsValue();
|
void MakeResultAsValue();
|
||||||
|
bool CheckIsBase(BfAstNode* checkNode);
|
||||||
bool CheckModifyResult(BfTypedValue typeValue, BfAstNode* refNode, const char* modifyType, bool onlyNeedsMut = false);
|
bool CheckModifyResult(BfTypedValue typeValue, BfAstNode* refNode, const char* modifyType, bool onlyNeedsMut = false);
|
||||||
bool CheckGenericCtor(BfGenericParamType* genericParamType, BfResolvedArgs& argValues, BfAstNode* targetSrc);
|
bool CheckGenericCtor(BfGenericParamType* genericParamType, BfResolvedArgs& argValues, BfAstNode* targetSrc);
|
||||||
BfTypedValue LookupField(BfAstNode* targetSrc, BfTypedValue target, const StringImpl& fieldName, BfLookupFieldFlags flags = BfLookupFieldFlag_None);
|
BfTypedValue LookupField(BfAstNode* targetSrc, BfTypedValue target, const StringImpl& fieldName, BfLookupFieldFlags flags = BfLookupFieldFlag_None);
|
||||||
|
|
|
@ -234,7 +234,10 @@ void BfSourceClassifier::Visit(BfIdentifierNode* identifier)
|
||||||
|
|
||||||
Visit(identifier->ToBase());
|
Visit(identifier->ToBase());
|
||||||
|
|
||||||
SetElementType(identifier, BfSourceElementType_Identifier);
|
if ((identifier->Equals("this")) || (identifier->Equals("base")))
|
||||||
|
SetElementType(identifier, BfSourceElementType_Keyword);
|
||||||
|
else
|
||||||
|
SetElementType(identifier, BfSourceElementType_Identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BfSourceClassifier::Visit(BfQualifiedNameNode* qualifiedName)
|
void BfSourceClassifier::Visit(BfQualifiedNameNode* qualifiedName)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue