2019-08-23 11:56:54 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BfCompiler.h"
|
|
|
|
#include "BfSourceClassifier.h"
|
|
|
|
#include "BfResolvePass.h"
|
|
|
|
|
|
|
|
NS_BF_BEGIN
|
|
|
|
|
|
|
|
class BfMethodInstance;
|
|
|
|
class BfLocalVariable;
|
|
|
|
|
|
|
|
class AutoCompleteEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
const char* mEntryType;
|
|
|
|
const char* mDisplay;
|
2020-10-08 09:41:05 -07:00
|
|
|
const char* mDocumentation;
|
2021-12-28 11:52:02 -05:00
|
|
|
mutable int8 mNamePrefixCount;
|
|
|
|
mutable int mScore;
|
|
|
|
mutable uint8* mMatches;
|
|
|
|
mutable uint8 mMatchesLength;
|
2019-08-23 11:56:54 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
AutoCompleteEntry()
|
|
|
|
{
|
2021-11-29 08:38:42 -08:00
|
|
|
mNamePrefixCount = 0;
|
2021-12-18 22:28:44 +01:00
|
|
|
mMatches = nullptr;
|
|
|
|
mMatchesLength = 0;
|
2019-08-23 11:56:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
AutoCompleteEntry(const char* entryType, const char* display)
|
|
|
|
{
|
|
|
|
mEntryType = entryType;
|
|
|
|
mDisplay = display;
|
|
|
|
mDocumentation = NULL;
|
2021-11-29 08:38:42 -08:00
|
|
|
mNamePrefixCount = 0;
|
2021-12-08 22:08:57 +01:00
|
|
|
mScore = 0;
|
2021-12-18 22:28:44 +01:00
|
|
|
mMatches = nullptr;
|
|
|
|
mMatchesLength = 0;
|
2019-08-23 11:56:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
AutoCompleteEntry(const char* entryType, const StringImpl& display)
|
|
|
|
{
|
|
|
|
mEntryType = entryType;
|
|
|
|
mDisplay = display.c_str();
|
|
|
|
mDocumentation = NULL;
|
2021-11-29 08:38:42 -08:00
|
|
|
mNamePrefixCount = 0;
|
2021-12-08 22:08:57 +01:00
|
|
|
mScore = 0;
|
2021-12-18 22:28:44 +01:00
|
|
|
mMatches = nullptr;
|
|
|
|
mMatchesLength = 0;
|
2021-11-29 08:38:42 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
AutoCompleteEntry(const char* entryType, const StringImpl& display, int namePrefixCount)
|
|
|
|
{
|
|
|
|
mEntryType = entryType;
|
|
|
|
mDisplay = display.c_str();
|
|
|
|
mDocumentation = NULL;
|
|
|
|
mNamePrefixCount = (int8)namePrefixCount;
|
2021-12-08 22:08:57 +01:00
|
|
|
mScore = 0;
|
2021-12-18 22:28:44 +01:00
|
|
|
mMatches = nullptr;
|
|
|
|
mMatchesLength = 0;
|
2019-08-23 11:56:54 -07:00
|
|
|
}
|
2021-12-18 22:28:44 +01:00
|
|
|
|
2019-08-23 11:56:54 -07:00
|
|
|
bool operator==(const AutoCompleteEntry& other) const
|
2022-07-26 13:27:03 -04:00
|
|
|
{
|
2019-08-23 11:56:54 -07:00
|
|
|
return strcmp(mDisplay, other.mDisplay) == 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_BF_END
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct BeefHash<Beefy::AutoCompleteEntry>
|
|
|
|
{
|
|
|
|
size_t operator()(const Beefy::AutoCompleteEntry& val)
|
2022-07-26 13:27:03 -04:00
|
|
|
{
|
2019-08-23 11:56:54 -07:00
|
|
|
intptr hash = 0;
|
2021-12-28 11:52:02 -05:00
|
|
|
const char* curPtr = val.mDisplay;
|
2019-08-23 11:56:54 -07:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
char c = *(curPtr++);
|
|
|
|
if (c == 0)
|
|
|
|
break;
|
2021-12-28 11:52:02 -05:00
|
|
|
hash = ((hash ^ (intptr)c) << 5) - hash;
|
2019-08-23 11:56:54 -07:00
|
|
|
}
|
|
|
|
|
2021-12-28 11:52:02 -05:00
|
|
|
return hash;
|
2019-08-23 11:56:54 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_BF_BEGIN
|
|
|
|
|
|
|
|
class AutoCompleteBase
|
|
|
|
{
|
2022-07-26 13:27:03 -04:00
|
|
|
public:
|
2019-08-23 11:56:54 -07:00
|
|
|
class EntryLess
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool operator()(const AutoCompleteEntry& left, const AutoCompleteEntry& right)
|
|
|
|
{
|
|
|
|
auto result = _stricmp(left.mDisplay, right.mDisplay);
|
|
|
|
if (result == 0)
|
|
|
|
result = strcmp(left.mDisplay, right.mDisplay);
|
|
|
|
return result < 0;
|
|
|
|
}
|
2022-07-26 13:27:03 -04:00
|
|
|
};
|
2019-08-23 11:56:54 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
BumpAllocator mAlloc;
|
|
|
|
HashSet<AutoCompleteEntry> mEntriesSet;
|
|
|
|
|
|
|
|
bool mIsGetDefinition;
|
|
|
|
bool mIsAutoComplete;
|
2021-12-25 20:14:23 +01:00
|
|
|
bool mDoFuzzyAutoComplete;
|
2019-08-23 11:56:54 -07:00
|
|
|
int mInsertStartIdx;
|
|
|
|
int mInsertEndIdx;
|
|
|
|
|
2021-12-08 22:08:57 +01:00
|
|
|
bool DoesFilterMatch(const char* entry, const char* filter, int& score, uint8* matches, int maxMatches);
|
2021-12-28 11:52:02 -05:00
|
|
|
AutoCompleteEntry* AddEntry(const AutoCompleteEntry& entry, const StringImpl& filter);
|
|
|
|
AutoCompleteEntry* AddEntry(const AutoCompleteEntry& entry, const char* filter);
|
2019-08-23 11:56:54 -07:00
|
|
|
AutoCompleteEntry* AddEntry(const AutoCompleteEntry& entry);
|
|
|
|
|
|
|
|
AutoCompleteBase();
|
|
|
|
virtual ~AutoCompleteBase();
|
|
|
|
|
|
|
|
void Clear();
|
|
|
|
};
|
|
|
|
|
|
|
|
class BfAutoComplete : public AutoCompleteBase
|
|
|
|
{
|
2022-07-26 13:27:03 -04:00
|
|
|
public:
|
2019-08-23 11:56:54 -07:00
|
|
|
class MethodMatchEntry
|
|
|
|
{
|
2022-07-26 13:27:03 -04:00
|
|
|
public:
|
2019-08-23 11:56:54 -07:00
|
|
|
BfMethodDef* mMethodDef;
|
|
|
|
BfFieldInstance* mPayloadEnumField;
|
2022-07-26 13:27:03 -04:00
|
|
|
BfTypeInstance* mTypeInstance;
|
2019-08-23 11:56:54 -07:00
|
|
|
BfTypeVector mGenericArguments;
|
|
|
|
BfMethodInstance* mCurMethodInstance;
|
|
|
|
|
|
|
|
MethodMatchEntry()
|
|
|
|
{
|
|
|
|
mMethodDef = NULL;
|
|
|
|
mPayloadEnumField = NULL;
|
2022-07-26 13:27:03 -04:00
|
|
|
mTypeInstance = NULL;
|
2019-08-23 11:56:54 -07:00
|
|
|
mCurMethodInstance = NULL;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class MethodMatchInfo
|
|
|
|
{
|
2022-07-26 13:27:03 -04:00
|
|
|
public:
|
2019-08-23 11:56:54 -07:00
|
|
|
BfTypeInstance* mCurTypeInstance;
|
|
|
|
BfMethodInstance* mCurMethodInstance;
|
|
|
|
Array<MethodMatchEntry> mInstanceList;
|
|
|
|
int mInvocationSrcIdx;
|
2022-07-26 13:27:03 -04:00
|
|
|
int mBestIdx;
|
|
|
|
int mPrevBestIdx;
|
2019-08-23 11:56:54 -07:00
|
|
|
bool mHadExactMatch;
|
2022-07-26 13:27:03 -04:00
|
|
|
int mMostParamsMatched;
|
2019-08-23 11:56:54 -07:00
|
|
|
Array<int> mSrcPositions; // start, commas, end
|
2022-07-26 13:27:03 -04:00
|
|
|
|
2019-08-23 11:56:54 -07:00
|
|
|
public:
|
|
|
|
MethodMatchInfo()
|
|
|
|
{
|
|
|
|
mInvocationSrcIdx = -1;
|
|
|
|
mCurTypeInstance = NULL;
|
|
|
|
mCurMethodInstance = NULL;
|
2022-07-26 13:27:03 -04:00
|
|
|
mBestIdx = 0;
|
|
|
|
mPrevBestIdx = -1;
|
2019-08-23 11:56:54 -07:00
|
|
|
mHadExactMatch = false;
|
2022-07-26 13:27:03 -04:00
|
|
|
mMostParamsMatched = 0;
|
2019-08-23 11:56:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
~MethodMatchInfo()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-07-26 13:27:03 -04:00
|
|
|
public:
|
2019-08-23 11:56:54 -07:00
|
|
|
BfModule* mModule;
|
|
|
|
BfCompiler* mCompiler;
|
2022-07-26 13:27:03 -04:00
|
|
|
BfSystem* mSystem;
|
2019-08-23 11:56:54 -07:00
|
|
|
MethodMatchInfo* mMethodMatchInfo;
|
|
|
|
bool mIsCapturingMethodMatchInfo;
|
|
|
|
String mDefaultSelection;
|
2019-12-24 13:13:04 -08:00
|
|
|
String mResultString;
|
2019-08-23 11:56:54 -07:00
|
|
|
String mDocumentationEntryName;
|
|
|
|
BfAstNode* mGetDefinitionNode;
|
|
|
|
BfResolveType mResolveType;
|
|
|
|
BfTypeInstance* mShowAttributeProperties;
|
2020-05-26 06:10:51 -07:00
|
|
|
BfAstNode* mIdentifierUsed;
|
2019-08-23 11:56:54 -07:00
|
|
|
bool mIgnoreFixits;
|
|
|
|
bool mHasFriendSet;
|
|
|
|
bool mUncertain; // May be an unknown identifier, do not aggressively autocomplete
|
2020-09-11 10:33:16 -07:00
|
|
|
bool mForceAllowNonStatic;
|
2019-08-23 11:56:54 -07:00
|
|
|
int mCursorLineStart;
|
|
|
|
int mCursorLineEnd;
|
2022-07-26 13:27:03 -04:00
|
|
|
|
|
|
|
int mReplaceLocalId;
|
2019-08-23 11:56:54 -07:00
|
|
|
BfMethodDef* mDefMethod;
|
|
|
|
BfTypeDef* mDefType;
|
|
|
|
BfFieldDef* mDefField;
|
|
|
|
BfPropertyDef* mDefProp;
|
2020-05-31 07:12:17 -07:00
|
|
|
BfAtomComposite mDefNamespace;
|
2019-08-23 11:56:54 -07:00
|
|
|
int mDefMethodGenericParamIdx;
|
|
|
|
int mDefTypeGenericParamIdx;
|
|
|
|
|
2022-07-26 13:27:03 -04:00
|
|
|
public:
|
2022-01-01 10:12:20 -05:00
|
|
|
BfProject* GetActiveProject();
|
2022-04-16 06:27:54 -07:00
|
|
|
bool WantsEntries();
|
2021-11-23 14:25:07 -08:00
|
|
|
bool CheckProtection(BfProtection protection, BfTypeDef* typeDef, bool allowProtected, bool allowPrivate);
|
2019-08-23 11:56:54 -07:00
|
|
|
String GetFilter(BfAstNode* node);
|
|
|
|
const char* GetTypeName(BfType* type);
|
|
|
|
int GetCursorIdx(BfAstNode* node);
|
|
|
|
bool IsAutocompleteNode(BfAstNode* node, int lengthAdd = 0, int startAdd = 0);
|
|
|
|
bool IsAutocompleteNode(BfAstNode* startNode, BfAstNode* endNode, int lengthAdd = 0, int startAdd = 0);
|
|
|
|
bool IsAutocompleteLineNode(BfAstNode* node);
|
2022-07-26 13:27:03 -04:00
|
|
|
BfTypedValue LookupTypeRefOrIdentifier(BfAstNode* node, bool* isStatic, BfEvalExprFlags evalExprFlags = BfEvalExprFlags_None, BfType* expectingType = NULL);
|
2019-08-23 11:56:54 -07:00
|
|
|
void SetDefinitionLocation(BfAstNode* astNode, bool force = false);
|
2022-07-26 13:27:03 -04:00
|
|
|
bool IsAttribute(BfTypeInstance* typeInst);
|
2020-10-08 09:41:05 -07:00
|
|
|
void AddMethod(BfTypeInstance* typeInstance, BfMethodDef* methodDef, BfMethodInstance* methodInstance, BfMethodDeclaration* methodDecl, const StringImpl& methodName, const StringImpl& filter);
|
|
|
|
void AddField(BfTypeInstance* typeInst, BfFieldDef* fieldDef, BfFieldInstance* fieldInstance, const StringImpl& filter);
|
|
|
|
void AddProp(BfTypeInstance* typeInst, BfPropertyDef* propDef, const StringImpl& filter);
|
2019-08-23 11:56:54 -07:00
|
|
|
void AddTypeDef(BfTypeDef* typeDef, const StringImpl& filter, bool onlyAttribute = false);
|
2022-06-24 06:45:35 -07:00
|
|
|
void AddInnerTypes(BfTypeInstance* typeInst, const StringImpl& filter, BfTypeInstance* startType, bool allowProtected, bool allowPrivate);
|
2019-08-23 11:56:54 -07:00
|
|
|
void AddCurrentTypes(BfTypeInstance* typeInst, const StringImpl& filter, bool allowProtected, bool allowPrivate, bool onlyAttribute);
|
2021-01-16 13:43:44 -08:00
|
|
|
void AddTypeMembers(BfTypeInstance* typeInst, bool addStatic, bool addNonStatic, const StringImpl& filter, BfTypeInstance* startType, bool allowInterfaces, bool allowImplicitThis, bool checkOuterType);
|
2019-08-23 11:56:54 -07:00
|
|
|
void AddSelfResultTypeMembers(BfTypeInstance* typeInst, BfTypeInstance* selfType, const StringImpl& filter, bool allowPrivate);
|
|
|
|
bool InitAutocomplete(BfAstNode* dotNode, BfAstNode* nameNode, String& filter);
|
2022-07-26 13:27:03 -04:00
|
|
|
void AddEnumTypeMembers(BfTypeInstance* typeInst, const StringImpl& filter, bool allowProtected, bool allowPrivate);
|
2020-06-03 05:22:11 -07:00
|
|
|
void AddExtensionMethods(BfTypeInstance* targetType, BfTypeInstance* extensionContainer, const StringImpl& filter, bool allowProtected, bool allowPrivate);
|
2020-05-26 06:10:51 -07:00
|
|
|
void AddTopLevelNamespaces(BfAstNode* identifierNode);
|
|
|
|
void AddTopLevelTypes(BfAstNode* identifierNode, bool onlyAttribute = false);
|
2019-08-23 11:56:54 -07:00
|
|
|
void AddOverrides(const StringImpl& filter);
|
2022-07-26 13:27:03 -04:00
|
|
|
void UpdateReplaceData();
|
2019-08-23 11:56:54 -07:00
|
|
|
void AddTypeInstanceEntry(BfTypeInstance* typeInst);
|
2020-10-08 09:41:05 -07:00
|
|
|
bool CheckDocumentation(AutoCompleteEntry* entry, BfCommentNode* documentation);
|
2020-02-07 08:44:06 -08:00
|
|
|
bool GetMethodInfo(BfMethodInstance* methodInst, StringImpl* methodName, StringImpl* insertString, bool isImplementing, bool isExplicitInterface);
|
2020-02-06 16:47:37 -08:00
|
|
|
void FixitGetParamString(const BfTypeVector& paramTypes, StringImpl& outStr);
|
2020-02-07 08:44:06 -08:00
|
|
|
int FixitGetMemberInsertPos(BfTypeDef* typeDef);
|
|
|
|
String FixitGetLocation(BfParserData* parserData, int insertPos);
|
2022-07-26 13:27:03 -04:00
|
|
|
String ConstantToString(BfIRConstHolder* constHolder, BfIRValue id);
|
2019-08-23 11:56:54 -07:00
|
|
|
|
|
|
|
public:
|
2021-12-25 20:14:23 +01:00
|
|
|
BfAutoComplete(BfResolveType resolveType = BfResolveType_Autocomplete, bool doFuzzyAutoComplete = false);
|
2019-08-23 11:56:54 -07:00
|
|
|
~BfAutoComplete();
|
|
|
|
|
|
|
|
void SetModule(BfModule* module);
|
2022-07-26 13:27:03 -04:00
|
|
|
void Clear();
|
2019-08-23 11:56:54 -07:00
|
|
|
void RemoveMethodMatchInfo();
|
|
|
|
void ClearMethodMatchEntries();
|
|
|
|
|
2020-05-26 06:10:51 -07:00
|
|
|
void CheckIdentifier(BfAstNode* identifierNode, bool isInExpression = false, bool isUsingDirective = false);
|
2019-08-23 11:56:54 -07:00
|
|
|
bool CheckMemberReference(BfAstNode* target, BfAstNode* dotToken, BfAstNode* memberName, bool onlyShowTypes = false, BfType* expectingType = NULL, bool isUsingDirective = false, bool onlyAttribute = false);
|
2019-12-13 14:22:23 -08:00
|
|
|
bool CheckExplicitInterface(BfTypeInstance* interfaceType, BfAstNode* dotToken, BfAstNode* memberName);
|
2019-08-23 11:56:54 -07:00
|
|
|
void CheckTypeRef(BfTypeReference* typeRef, bool mayBeIdentifier, bool isInExpression = false, bool onlyAttribute = false);
|
|
|
|
void CheckAttributeTypeRef(BfTypeReference* typeRef);
|
2022-07-26 13:27:03 -04:00
|
|
|
void CheckInvocation(BfAstNode* invocationNode, BfTokenNode* openParen, BfTokenNode* closeParen, const BfSizedArray<BfTokenNode*>& commas);
|
2022-02-05 09:23:44 -05:00
|
|
|
void CheckNode(BfAstNode* node, bool mayBeIdentifier, bool isInExpression = false);
|
2019-08-23 11:56:54 -07:00
|
|
|
void CheckMethod(BfMethodDeclaration* methodDeclaration, bool isLocalMethod);
|
2022-07-26 13:27:03 -04:00
|
|
|
void CheckProperty(BfPropertyDeclaration* propertyDeclaration);
|
2019-08-23 11:56:54 -07:00
|
|
|
void CheckVarResolution(BfAstNode* varTypeRef, BfType* resolvedTypeRef);
|
2019-12-24 13:13:04 -08:00
|
|
|
void CheckResult(BfAstNode* node, const BfTypedValue& typedValue);
|
2020-05-26 06:10:51 -07:00
|
|
|
void CheckLocalDef(BfAstNode* identifierNode, BfLocalVariable* varDecl);
|
|
|
|
void CheckLocalRef(BfAstNode* identifierNode, BfLocalVariable* varDecl);
|
2022-07-26 13:27:03 -04:00
|
|
|
void CheckFieldRef(BfAstNode* identifierNode, BfFieldInstance* fieldInst);
|
2020-05-29 16:58:47 -07:00
|
|
|
void CheckLabel(BfIdentifierNode* identifierNode, BfAstNode* precedingNode, BfScopeData* scopeData);
|
2020-05-31 07:12:17 -07:00
|
|
|
void CheckNamespace(BfAstNode* node, const BfAtomComposite& namespaceName);
|
2022-07-26 13:27:03 -04:00
|
|
|
void CheckEmptyStart(BfAstNode* prevNode, BfType* type);
|
|
|
|
bool CheckFixit(BfAstNode* node);
|
2020-02-07 08:44:06 -08:00
|
|
|
void CheckInterfaceFixit(BfTypeInstance* typeInstance, BfAstNode* node);
|
2022-07-26 13:27:03 -04:00
|
|
|
|
2020-02-06 16:47:37 -08:00
|
|
|
void FixitAddMember(BfTypeInstance* typeInst, BfType* fieldType, const StringImpl& fieldName, bool isStatic, BfTypeInstance* referencedFrom);
|
|
|
|
void FixitAddCase(BfTypeInstance * typeInst, const StringImpl & caseName, const BfTypeVector & fieldTypes);
|
|
|
|
void FixitAddMethod(BfTypeInstance* typeInst, const StringImpl& methodName, BfType* returnType, const BfTypeVector& paramTypes, bool wantStatic);
|
2020-03-21 13:09:42 -07:00
|
|
|
void FixitAddNamespace(BfAstNode* refNode, const StringImpl& namespacStr);
|
2020-09-11 14:01:40 -07:00
|
|
|
void FixitCheckNamespace(BfTypeDef* activeTypeDef, BfAstNode* typeRef, BfTokenNode* nextDotToken);
|
2020-09-19 15:36:25 -07:00
|
|
|
void FixitAddConstructor(BfTypeInstance* typeInstance);
|
2022-07-10 07:50:08 -04:00
|
|
|
void FixitAddFullyQualify(BfAstNode* refNode, const StringImpl& findName, const SizedArrayImpl<BfUsingFieldData::MemberRef>& foundList);
|
2020-09-03 09:31:22 -07:00
|
|
|
|
|
|
|
void SetResultStringType(BfType* type);
|
2019-08-23 11:56:54 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_BF_END
|