Code::Blocks  SVN r11506
Classes | Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Private Member Functions | Private Attributes | List of all members
NativeParserBase Class Reference

#include <nativeparser_base.h>

Inheritance diagram for NativeParserBase:
Collaboration diagram for NativeParserBase:

Classes

struct  ParserComponent
 a long statement can be divided to a ParserComponent chain. More...
 

Public Types

enum  ParserTokenType {
  pttUndefined = 0, pttSearchText, pttClass, pttNamespace,
  pttFunction
}
 divide a statement to several pieces(parser component), each component has a type member More...
 
enum  OperatorType {
  otOperatorUndefined = 0, otOperatorSquare, otOperatorParentheses, otOperatorPointer,
  otOperatorStar
}
 the delimiter separating two Parser Component, See ParserComponent struct for more details More...
 

Public Member Functions

 NativeParserBase ()
 Constructor. More...
 
virtual ~NativeParserBase ()
 Destructor. More...
 

Protected Member Functions

void Reset ()
 Init cc search member variables. More...
 
size_t FindAIMatches (TokenTree *tree, std::queue< ParserComponent > components, TokenIdxSet &result, int parentTokenIdx=-1, bool isPrefix=false, bool caseSensitive=false, bool use_inheritance=true, short int kindMask=0xFFFF, TokenIdxSet *search_scope=0)
 Artificial Intelligence Matching. More...
 
void FindCurrentFunctionScope (TokenTree *tree, const TokenIdxSet &procResult, TokenIdxSet &scopeResult)
 if the expression return the container tokens, which are the parent of the expression. More...
 
void CleanupSearchScope (TokenTree *tree, TokenIdxSet *searchScope)
 remove all the container tokens in the token index set. More...
 
void GetCallTipHighlight (const wxString &calltip, int *start, int *end, int typedCommas)
 Returns the start and end of the call-tip highlight region. More...
 
int FindFunctionOpenParenthesis (const wxString &calltip)
 Finds the position of the opening parenthesis marking the beginning of the params. More...
 
wxString GetCCToken (wxString &line, ParserTokenType &tokenType, OperatorType &tokenOperatorType)
 helper function to split the statement More...
 
unsigned int FindCCTokenStart (const wxString &line)
 helper function to split the statement More...
 
wxString GetNextCCToken (const wxString &line, unsigned int &startAt, OperatorType &tokenOperatorType)
 helper function to read the next CCToken, begin from the startAt, this point to a non-space character, and fetch the beginning identifier More...
 
void RemoveLastFunctionChildren (TokenTree *tree, int &lastFuncTokenIdx)
 Remove the last function's children, when doing codecompletion in a function body, the function body up to the caret position was parsed, and the local variables defined in the function were recorded as the function's children. More...
 
size_t BreakUpComponents (const wxString &actual, std::queue< ParserComponent > &components)
 break a statement to several ParserComponents, and store them in a queue. More...
 
size_t ResolveExpression (TokenTree *tree, std::queue< ParserComponent > components, const TokenIdxSet &searchScope, TokenIdxSet &result, bool caseSense=true, bool isPrefix=false)
 A statement(expression) is expressed by a ParserComponent queue We do a match from the left of the queue one by one. More...
 
void ResolveOperator (TokenTree *tree, const OperatorType &tokenOperatorType, const TokenIdxSet &tokens, const TokenIdxSet &searchScope, TokenIdxSet &result)
 used to solve the overloaded operator functions return type More...
 
size_t ResolveActualType (TokenTree *tree, wxString searchText, const TokenIdxSet &searchScope, TokenIdxSet &result)
 Get the Type information of the searchText string. More...
 
void ResolveTemplateMap (TokenTree *tree, const wxString &searchStr, const TokenIdxSet &actualTypeScope, TokenIdxSet &initialScope)
 resolve template map [formal parameter] to [actual parameter] More...
 
void AddTemplateAlias (TokenTree *tree, const int &id, const TokenIdxSet &actualTypeScope, TokenIdxSet &initialScope)
 add template parameter, get the actual parameter from the formal parameter list More...
 
size_t GenerateResultSet (TokenTree *tree, const wxString &target, int parentIdx, TokenIdxSet &result, bool caseSens=true, bool isPrefix=false, short int kindMask=0xFFFF)
 Generate the matching results under the Parent Token index set. More...
 
size_t GenerateResultSet (TokenTree *tree, const wxString &target, const TokenIdxSet &ptrParentID, TokenIdxSet &result, bool caseSens=true, bool isPrefix=false, short int kindMask=0xFFFF)
 This function is just like the one above, especially that it use a single parent Token id, not the parent id set in previous one. More...
 
bool IsAllocator (TokenTree *tree, const int &id)
 Test if token with this id is allocator class. More...
 
bool DependsOnAllocator (TokenTree *tree, const int &id)
 Test if token with this id depends on allocator class. More...
 
void CollectSearchScopes (const TokenIdxSet &searchScope, TokenIdxSet &actualTypeScope, TokenTree *tree)
 Collect search scopes, add the searchScopes's parent scope. More...
 
int GetTokenFromCurrentLine (TokenTree *tree, const TokenIdxSet &tokens, size_t curLine, const wxString &file)
 used to get the correct token index in current line, e.g. More...
 
void ComputeCallTip (TokenTree *tree, const TokenIdxSet &tokens, wxArrayString &items)
 call tips are tips when you are entering some functions, such as you have a class definition More...
 
bool PrettyPrintToken (TokenTree *tree, const Token *token, wxString &result, bool isRoot=true)
 For ComputeCallTip() No critical section needed in this recursive function! All functions that call this recursive function, should already entered a critical section. More...
 

Static Protected Member Functions

static int CountCommas (const wxString &lineText, int start)
 
static bool InsideToken (int startAt, const wxString &line)
 check whether the line[startAt] point to the identifier More...
 
static int BeginOfToken (int startAt, const wxString &line)
 go to the first character of the identifier, e.g More...
 
static int BeforeToken (int startAt, const wxString &line)
 
static bool IsOperatorEnd (int startAt, const wxString &line)
 check startAt is at some character like: More...
 
static bool IsOperatorPointer (int startAt, const wxString &line)
 
static bool IsOperatorBegin (int startAt, const wxString &line)
 check if startAt point to "->" or "::" operator More...
 
static bool IsOperatorDot (int startAt, const wxString &line)
 check whether line[startAt] is a dot character More...
 
static int BeforeWhitespace (int startAt, const wxString &line)
 move to the char before whitespace and tabs, e.g. More...
 
static int AfterWhitespace (int startAt, const wxString &line)
 search from left to right, move the cursor to the first character after the space More...
 
static bool IsOpeningBracket (int startAt, const wxString &line)
 Test whether the current character is a '(' or '['. More...
 
static bool IsClosingBracket (int startAt, const wxString &line)
 check the current char (line[startAt]) is either ')' or ']' More...
 

Private Member Functions

bool AddChildrenOfUnnamed (TokenTree *tree, const Token *parent, TokenIdxSet &result)
 collect child tokens of the specified token, the specified token must be unnamed. More...
 
bool AddChildrenOfEnum (TokenTree *tree, const Token *parent, TokenIdxSet &result)
 
bool IsChildOfUnnamedOrEnum (TokenTree *tree, const int targetIdx, const int parentIdx)
 check to see if the token is an unnamed class or enum under the parent token More...
 
void AddConstructors (TokenTree *tree, const TokenIdxSet &source, TokenIdxSet &dest)
 loop on the input Token index set (source), add all its public constructors to output Token index set (dest) More...
 
bool MatchText (const wxString &text, const wxString &target, bool caseSens, bool isPrefix)
 
bool MatchType (TokenKind kind, short int kindMask)
 

Private Attributes

ParserComponent m_LastComponent
 
std::map< wxString, wxStringm_TemplateMap
 

Detailed Description

Definition at line 23 of file nativeparser_base.h.

Member Enumeration Documentation

◆ OperatorType

the delimiter separating two Parser Component, See ParserComponent struct for more details

Enumerator
otOperatorUndefined 
otOperatorSquare 
otOperatorParentheses 
otOperatorPointer 
otOperatorStar 

Definition at line 37 of file nativeparser_base.h.

◆ ParserTokenType

divide a statement to several pieces(parser component), each component has a type member

Enumerator
pttUndefined 
pttSearchText 
pttClass 
pttNamespace 
pttFunction 

Definition at line 27 of file nativeparser_base.h.

Constructor & Destructor Documentation

◆ NativeParserBase()

NativeParserBase::NativeParserBase ( )

Constructor.

Definition at line 65 of file nativeparser_base.cpp.

Referenced by NativeParserBase::ParserComponent::Clear().

◆ ~NativeParserBase()

NativeParserBase::~NativeParserBase ( )
virtual

Destructor.

Definition at line 69 of file nativeparser_base.cpp.

Referenced by NativeParserBase::ParserComponent::Clear().

Member Function Documentation

◆ AddChildrenOfEnum()

bool NativeParserBase::AddChildrenOfEnum ( TokenTree tree,
const Token parent,
TokenIdxSet result 
)
inlineprivate

◆ AddChildrenOfUnnamed()

bool NativeParserBase::AddChildrenOfUnnamed ( TokenTree tree,
const Token parent,
TokenIdxSet result 
)
inlineprivate

collect child tokens of the specified token, the specified token must be unnamed.

used for GenerateResultSet() function

Parameters
treeTokenTree pointer
parentwe need to collect the children of this token
resultcollected tokens
Returns
bool true if parent is an unnamed class or enum

Definition at line 643 of file nativeparser_base.h.

References AddChildrenOfEnum(), TokenTree::at(), Token::m_Children, Token::m_IsAnonymous, Token::m_Scope, Token::m_TokenKind, tkClass, tkEnum, and tsPrivate.

Referenced by GenerateResultSet().

◆ AddConstructors()

void NativeParserBase::AddConstructors ( TokenTree tree,
const TokenIdxSet source,
TokenIdxSet dest 
)
private

loop on the input Token index set (source), add all its public constructors to output Token index set (dest)

Definition at line 966 of file nativeparser_base.cpp.

References TokenTree::at(), wxString::EndsWith(), Token::m_Children, Token::m_IsOperator, Token::m_Name, Token::m_Scope, Token::m_TokenKind, tkClass, tkConstructor, tsPublic, tsUndefined, and wxT.

Referenced by IsChildOfUnnamedOrEnum(), and ResolveExpression().

◆ AddTemplateAlias()

void NativeParserBase::AddTemplateAlias ( TokenTree tree,
const int &  id,
const TokenIdxSet actualTypeScope,
TokenIdxSet initialScope 
)
protected

add template parameter, get the actual parameter from the formal parameter list

Parameters
idtemplate token id
actualTypeScopesearch scope
initialScoperesolved result
treeToken tree pointer.

Definition at line 1160 of file nativeparser_base.cpp.

References _T, TokenTree::at(), CC_LOCKER_TRACK_TT_MTX_LOCK, CC_LOCKER_TRACK_TT_MTX_UNLOCK, TokenTree::empty(), wxString::IsEmpty(), wxString::Last(), Token::m_TemplateAlias, m_TemplateMap, Token::m_TokenKind, wxString::RemoveLast(), ResolveActualType(), s_TokenTreeMutex, and tkTypedef.

Referenced by NativeParserBase::ParserComponent::Clear(), ResolveExpression(), and ResolveOperator().

◆ AfterWhitespace()

static int NativeParserBase::AfterWhitespace ( int  startAt,
const wxString line 
)
inlinestaticprotected

search from left to right, move the cursor to the first character after the space

" :: f"
^begin ^end
Parameters
[in]startAtthe begin of the cursor
[in]linethe string buffer
Returns
the location of the cursor

Definition at line 598 of file nativeparser_base.h.

References wxString::GetChar(), and wxString::Len().

Referenced by FindCCTokenStart(), GetCCToken(), and GetNextCCToken().

◆ BeforeToken()

static int NativeParserBase::BeforeToken ( int  startAt,
const wxString line 
)
inlinestaticprotected

Definition at line 513 of file nativeparser_base.h.

References wxString::GetChar(), wxString::Len(), and wxIsalnum().

Referenced by FindCCTokenStart().

◆ BeforeWhitespace()

static int NativeParserBase::BeforeWhitespace ( int  startAt,
const wxString line 
)
inlinestaticprotected

move to the char before whitespace and tabs, e.g.

SomeNameSpace :: SomeClass
^end ^begin
note if there some spaces in the beginning like below
" f::"
^end ^begin

the returned index is -1.

Returns
the cursor after the operation

Definition at line 579 of file nativeparser_base.h.

References wxString::GetChar(), and wxString::Len().

Referenced by FindCCTokenStart().

◆ BeginOfToken()

static int NativeParserBase::BeginOfToken ( int  startAt,
const wxString line 
)
inlinestaticprotected

go to the first character of the identifier, e.g

" f(SomeNameSpace::SomeClass.SomeMethod"
return value^ ^begin

this is the index before the first character of the identifier

Definition at line 504 of file nativeparser_base.h.

References wxString::GetChar(), wxString::Len(), and wxIsalnum().

Referenced by FindCCTokenStart().

◆ BreakUpComponents()

size_t NativeParserBase::BreakUpComponents ( const wxString actual,
std::queue< ParserComponent > &  components 
)
protected

◆ CleanupSearchScope()

void NativeParserBase::CleanupSearchScope ( TokenTree tree,
TokenIdxSet searchScope 
)
protected

remove all the container tokens in the token index set.

Parameters
searchScopeThe Tokens we need to remove from the tree

Definition at line 339 of file nativeparser_base.cpp.

References TokenTree::at(), CC_LOCKER_TRACK_TT_MTX_LOCK, CC_LOCKER_TRACK_TT_MTX_UNLOCK, Token::m_TokenKind, s_TokenTreeMutex, tkAnyFunction, tkClass, tkNamespace, and tkTypedef.

Referenced by NativeParser::AI(), and NativeParserBase::ParserComponent::Clear().

◆ CollectSearchScopes()

void NativeParserBase::CollectSearchScopes ( const TokenIdxSet searchScope,
TokenIdxSet actualTypeScope,
TokenTree tree 
)
protected

Collect search scopes, add the searchScopes's parent scope.

Parameters
searchScopeinput search scope
actualTypeScopereturned search scope
treeTokenTree pointer

Definition at line 1635 of file nativeparser_base.cpp.

References TokenTree::at(), CC_LOCKER_TRACK_TT_MTX_LOCK, CC_LOCKER_TRACK_TT_MTX_UNLOCK, Token::m_Index, Token::m_ParentIndex, and s_TokenTreeMutex.

Referenced by NativeParserBase::ParserComponent::Clear(), ResolveExpression(), and ResolveOperator().

◆ ComputeCallTip()

void NativeParserBase::ComputeCallTip ( TokenTree tree,
const TokenIdxSet tokens,
wxArrayString items 
)
protected

call tips are tips when you are entering some functions, such as you have a class definition

class A {
public:
void A() {};
void test() { };
};
when you are entering some text like
A(| or objA.test(|

then there will be a tip window show the function prototype of the function

Definition at line 1737 of file nativeparser_base.cpp.

References _T, wxArrayString::Add(), TokenTree::at(), CC_LOCKER_TRACK_TT_MTX_LOCK, CC_LOCKER_TRACK_TT_MTX_UNLOCK, wxString::empty(), wxString::EndsWith(), TokenTree::FindMatches(), Tokenizer::GetToken(), Tokenizer::InitFromBuffer(), Token::m_Args, Token::m_BaseType, Token::m_Children, Token::m_FullType, Token::m_IsOperator, Token::m_Name, Token::m_Scope, Token::m_TokenKind, Tokenizer::PeekToken(), PrettyPrintToken(), s_TokenTreeMutex, tkClass, tkConstructor, tkFunction, tkMacroDef, tkVariable, TokenTree::TokenExists(), tsPublic, tsUndefined, and wxT.

Referenced by NativeParserBase::ParserComponent::Clear(), and NativeParser::GetCallTips().

◆ CountCommas()

static int NativeParserBase::CountCommas ( const wxString lineText,
int  start 
)
inlinestaticprotected

Definition at line 464 of file nativeparser_base.h.

References wxString::GetChar().

◆ DependsOnAllocator()

bool NativeParserBase::DependsOnAllocator ( TokenTree tree,
const int &  id 
)
protected

Test if token with this id depends on allocator class.

Currently, this function only identifies STL containers dependent on allocator.

All functions that call this recursive function, should already entered a critical section.

Parameters
treeTokenTree pointer
idtoken idx

Definition at line 1611 of file nativeparser_base.cpp.

References _T, TokenTree::at(), wxString::Find(), Token::m_ParentIndex, Token::m_TemplateArgument, and wxNOT_FOUND.

Referenced by NativeParserBase::ParserComponent::Clear(), and GenerateResultSet().

◆ FindAIMatches()

size_t NativeParserBase::FindAIMatches ( TokenTree tree,
std::queue< ParserComponent components,
TokenIdxSet result,
int  parentTokenIdx = -1,
bool  isPrefix = false,
bool  caseSensitive = false,
bool  use_inheritance = true,
short int  kindMask = 0xFFFF,
TokenIdxSet search_scope = 0 
)
protected

Artificial Intelligence Matching.

All functions that call this recursive function, should already entered a critical section or a mutex to protect the TokenTree.

match (consume) the ParserComponent queue from left to right, the output result becomes the search scope of the next match. finally, give the results which match the last ParserComponent.

Parameters
componentsinput ParserComponent queue
parentTokenIdx,initialsearch scope of the left most component, this is the direct parent of the current statement(expression)
fullMatchthe result should be a full text match or prefix match
Returns
matching token number, it is the size of result

Definition at line 87 of file nativeparser_base.cpp.

References _(), _T, TokenTree::at(), BreakUpComponents(), NativeParserBase::ParserComponent::component, CCLogger::DebugLog(), F(), GenerateResultSet(), CCLogger::Get(), wxString::IsEmpty(), Token::m_BaseType, Token::m_Children, Token::m_Index, Token::m_IsOperator, Token::m_Name, Token::m_ParentIndex, Token::m_TokenKind, pttSearchText, s_DebugSmartSense, tkClass, tkEnum, tkNamespace, tkTypedef, NativeParserBase::ParserComponent::tokenType, TRACE, and wxString::wx_str().

Referenced by NativeParserBase::ParserComponent::Clear(), and NativeParser::FindCurrentFunctionToken().

◆ FindCCTokenStart()

unsigned int NativeParserBase::FindCCTokenStart ( const wxString line)
protected

helper function to split the statement

" SomeNameSpace::SomeClass.SomeMethod|"
^ should stop here <------------ ^ start from here, go backward(right to left)
" f(SomeNameSpace::SomeClass.SomeMethod|"
^ should stop here

so, brace level should be considered

Definition at line 482 of file nativeparser_base.cpp.

References _T, AfterWhitespace(), BeforeToken(), BeforeWhitespace(), BeginOfToken(), wxString::GetChar(), wxUniChar::GetValue(), IsClosingBracket(), IsOpeningBracket(), IsOperatorDot(), IsOperatorEnd(), wxString::Len(), wxString::Mid(), TRACE, and wxString::wx_str().

Referenced by NativeParserBase::ParserComponent::Clear(), and GetCCToken().

◆ FindCurrentFunctionScope()

void NativeParserBase::FindCurrentFunctionScope ( TokenTree tree,
const TokenIdxSet procResult,
TokenIdxSet scopeResult 
)
protected

if the expression return the container tokens, which are the parent of the expression.

Parameters
[in]procResultinput function index collection
[out]scopeResultfiltered output function index collection For example, if we have such code
class A
{
void f()
{
statement|<-----CC here
};
}
We try to locate the Tokens their scopes "Cover" the "statement"

Definition at line 306 of file nativeparser_base.cpp.

References _T, TokenTree::at(), CC_LOCKER_TRACK_TT_MTX_LOCK, CC_LOCKER_TRACK_TT_MTX_UNLOCK, CCLogger::DebugLog(), CCLogger::Get(), Token::HasChildren(), Token::m_Name, Token::m_ParentIndex, Token::m_TokenKind, s_DebugSmartSense, s_TokenTreeMutex, tkAnyFunction, and tkClass.

Referenced by NativeParser::AI(), and NativeParserBase::ParserComponent::Clear().

◆ FindFunctionOpenParenthesis()

int NativeParserBase::FindFunctionOpenParenthesis ( const wxString calltip)
protected

Finds the position of the opening parenthesis marking the beginning of the params.

See GetCallTipHighlight() for more details

Definition at line 401 of file nativeparser_base.cpp.

References wxString::length(), and wxT.

Referenced by NativeParserBase::ParserComponent::Clear(), and GetCallTipHighlight().

◆ GenerateResultSet() [1/2]

size_t NativeParserBase::GenerateResultSet ( TokenTree tree,
const wxString target,
int  parentIdx,
TokenIdxSet result,
bool  caseSens = true,
bool  isPrefix = false,
short int  kindMask = 0xFFFF 
)
protected

Generate the matching results under the Parent Token index set.

All functions that call this recursive function, should already entered a critical section.

Parameters
treeTokenTree pointer
targetScope (defined in TokenIdxSet)
resultresult token index set
isPrefixwhether a full match is used or only do a prefix match
kindMaskdefine the result tokens filter, such as only class type is OK
Returns
result token set number

Definition at line 1221 of file nativeparser_base.cpp.

References _(), _T, AddChildrenOfEnum(), AddChildrenOfUnnamed(), TokenTree::at(), wxString::begin(), CCLogger::DebugLog(), DependsOnAllocator(), wxString::end(), F(), TokenTree::FindMatches(), CCLogger::Get(), Token::GetTokenKindString(), TokenTree::GetTokens(), IsAllocator(), IsChildOfUnnamedOrEnum(), wxString::IsEmpty(), Token::m_Aliases, Token::m_Ancestors, Token::m_Children, Token::m_Index, Token::m_Name, Token::m_ParentIndex, Token::m_TokenKind, MatchText(), MatchType(), ParserConsts::ptr, TokenTree::RecalcInheritanceChain(), s_DebugSmartSense, tkEnum, tkNamespace, TRACE, and wxString::wx_str().

Referenced by NativeParserBase::ParserComponent::Clear(), FindAIMatches(), NativeParser::FindCurrentFunctionToken(), ResolveActualType(), ResolveExpression(), and ResolveOperator().

◆ GenerateResultSet() [2/2]

size_t NativeParserBase::GenerateResultSet ( TokenTree tree,
const wxString target,
const TokenIdxSet ptrParentID,
TokenIdxSet result,
bool  caseSens = true,
bool  isPrefix = false,
short int  kindMask = 0xFFFF 
)
protected

This function is just like the one above, especially that it use a single parent Token id, not the parent id set in previous one.

All functions that call this recursive function, should already entered a critical section.

◆ GetCallTipHighlight()

void NativeParserBase::GetCallTipHighlight ( const wxString calltip,
int *  start,
int *  end,
int  typedCommas 
)
protected

Returns the start and end of the call-tip highlight region.

For a function prototype "void MyNamespace::SomeClass::func(int a, float b)" if we have a function call statement "obj->f(x,y)", when we hover on the "y", we should high light the "float b" in the calltip

Parameters
[in]calltipis the calltip string
[out]startthe start index of the high light string
[out]endthe end index of the high light string
[in]typedCommase.g. "func(x, y)", in this case, we say we have typed one comma before the hovered "y", so we know we need to high light the second parameter, which is "float b"

Definition at line 360 of file nativeparser_base.cpp.

References _T, FindFunctionOpenParenthesis(), wxString::GetChar(), wxString::length(), and TRACE.

Referenced by NativeParserBase::ParserComponent::Clear().

◆ GetCCToken()

wxString NativeParserBase::GetCCToken ( wxString line,
ParserTokenType tokenType,
OperatorType tokenOperatorType 
)
protected

helper function to split the statement

Parameters
linea statement string
[out]tokenTypethe returned type of the string
[out]tokenOperatorTypeif it is a function call token, specify which type of function call It contains a string on the following form:
char* mychar = SomeNamespace::m_SomeVar.SomeMeth
^----start from here
Usually, the caret is located at the end of the line.

first we locate the first non-space char starting from the end:

char* mychar = SomeNamespace::m_SomeVar.SomeMeth
^----stop here

then we remove everything before it, so we get "SomeNamespace::m_SomeVar.SomeMeth"

Now we cut the first component "SomeNamespace" and return it. The statement line becomes:

m_SomeVar.SomeMeth

so that if we call this function again with the (modified) line, we'll return "m_SomeVar" and modify line (again) to become:

SomeMeth

and so on and so forth until we return an empty string... NOTE: if we find () args or [] arrays in our way, we skip them (done in GetNextCCToken)... todo: it looks like [] is not skipped, because we have to handle the operator[] also, if we see a aaa(), we always think it is a function call

Definition at line 419 of file nativeparser_base.cpp.

References _T, AfterWhitespace(), wxString::Clear(), FindCCTokenStart(), wxString::GetChar(), GetNextCCToken(), wxString::IsEmpty(), IsOperatorDot(), IsOperatorEnd(), IsOperatorPointer(), wxString::Len(), otOperatorParentheses, otOperatorPointer, otOperatorSquare, otOperatorUndefined, pttClass, pttFunction, pttNamespace, pttSearchText, wxString::Remove(), TRACE, wxString::wx_str(), and wxEmptyString.

Referenced by BreakUpComponents(), and NativeParserBase::ParserComponent::Clear().

◆ GetNextCCToken()

wxString NativeParserBase::GetNextCCToken ( const wxString line,
unsigned int &  startAt,
OperatorType tokenOperatorType 
)
protected

helper function to read the next CCToken, begin from the startAt, this point to a non-space character, and fetch the beginning identifier

Parameters
startAtthis will be updated to the char after the identifier
tokenOperatorTypethe type of the operator E.g.
SomeMethod()->
^begin
the returned wxString is "SomeMethod", the tokenOperatorType is pointer member access

Definition at line 558 of file nativeparser_base.cpp.

References _T, AfterWhitespace(), wxString::GetChar(), wxUniChar::GetValue(), InsideToken(), IsClosingBracket(), IsOpeningBracket(), IsOperatorBegin(), wxString::Len(), otOperatorParentheses, otOperatorSquare, otOperatorStar, TRACE, and wxString::wx_str().

Referenced by NativeParserBase::ParserComponent::Clear(), and GetCCToken().

◆ GetTokenFromCurrentLine()

int NativeParserBase::GetTokenFromCurrentLine ( TokenTree tree,
const TokenIdxSet tokens,
size_t  curLine,
const wxString file 
)
protected

used to get the correct token index in current line, e.g.

class A
{
void test()
{ // start of the function body
|
}; // end of the function body
};
Parameters
tokensall current file's function and class, which cover the current line
curLinethe line of the current caret position
fileeditor file name

Definition at line 1666 of file nativeparser_base.cpp.

References _T, TokenTree::at(), Token::DisplayName(), Token::GetFilename(), TokenTree::InsertFileOrGetIndex(), Token::m_ImplFileIdx, Token::m_ImplLine, Token::m_ImplLineEnd, Token::m_ImplLineStart, Token::m_Index, Token::m_TokenKind, tkAnyFunction, tkClass, tkConstructor, TRACE, and wxString::wx_str().

Referenced by NativeParserBase::ParserComponent::Clear(), and NativeParser::FindCurrentFunctionStart().

◆ InsideToken()

static bool NativeParserBase::InsideToken ( int  startAt,
const wxString line 
)
inlinestaticprotected

check whether the line[startAt] point to the identifier

SomeMethod(arg1, arg2)->Method2()
^^^^^^^^^^ those index will return true

Definition at line 489 of file nativeparser_base.h.

References wxString::GetChar(), wxString::Len(), and wxIsalnum().

Referenced by GetNextCCToken().

◆ IsAllocator()

bool NativeParserBase::IsAllocator ( TokenTree tree,
const int &  id 
)
protected

Test if token with this id is allocator class.

All functions that call this function, should already entered a critical section.

Parameters
treeTokenTree pointer
idtoken idx

Definition at line 1597 of file nativeparser_base.cpp.

References _T, TokenTree::at(), wxString::IsSameAs(), and Token::m_Name.

Referenced by NativeParserBase::ParserComponent::Clear(), and GenerateResultSet().

◆ IsChildOfUnnamedOrEnum()

bool NativeParserBase::IsChildOfUnnamedOrEnum ( TokenTree tree,
const int  targetIdx,
const int  parentIdx 
)
inlineprivate

check to see if the token is an unnamed class or enum under the parent token

This function will internally recursive call itself.

Parameters
treepointer to the TokenTree
targetIdxthe checked token index
parentIdxthe search scope
Returns
bool true if success

Definition at line 695 of file nativeparser_base.h.

References AddConstructors(), TokenTree::at(), Token::m_Children, Token::m_IsAnonymous, Token::m_TokenKind, tkClass, and tkEnum.

Referenced by GenerateResultSet().

◆ IsClosingBracket()

static bool NativeParserBase::IsClosingBracket ( int  startAt,
const wxString line 
)
inlinestaticprotected

check the current char (line[startAt]) is either ')' or ']'

Definition at line 621 of file nativeparser_base.h.

References wxString::GetChar().

Referenced by FindCCTokenStart(), and GetNextCCToken().

◆ IsOpeningBracket()

static bool NativeParserBase::IsOpeningBracket ( int  startAt,
const wxString line 
)
inlinestaticprotected

Test whether the current character is a '(' or '['.

Parameters
startAtthe current cursor on the buffer
Returns
true if test is OK

Definition at line 613 of file nativeparser_base.h.

References wxString::GetChar(), and wxString::Len().

Referenced by FindCCTokenStart(), and GetNextCCToken().

◆ IsOperatorBegin()

static bool NativeParserBase::IsOperatorBegin ( int  startAt,
const wxString line 
)
inlinestaticprotected

check if startAt point to "->" or "::" operator

Definition at line 550 of file nativeparser_base.h.

References wxString::GetChar(), and wxString::Len().

Referenced by GetNextCCToken().

◆ IsOperatorDot()

static bool NativeParserBase::IsOperatorDot ( int  startAt,
const wxString line 
)
inlinestaticprotected

check whether line[startAt] is a dot character

Definition at line 561 of file nativeparser_base.h.

References wxString::GetChar(), and wxString::Len().

Referenced by FindCCTokenStart(), and GetCCToken().

◆ IsOperatorEnd()

static bool NativeParserBase::IsOperatorEnd ( int  startAt,
const wxString line 
)
inlinestaticprotected

check startAt is at some character like:

SomeNameSpace::SomeClass
^ here is a double colon
SomeObject->SomeMethod
^ here is a pointer member access operator

Definition at line 531 of file nativeparser_base.h.

References wxString::GetChar(), and wxString::Len().

Referenced by FindCCTokenStart(), and GetCCToken().

◆ IsOperatorPointer()

static bool NativeParserBase::IsOperatorPointer ( int  startAt,
const wxString line 
)
inlinestaticprotected

Definition at line 540 of file nativeparser_base.h.

References wxString::GetChar(), and wxString::Len().

Referenced by GetCCToken().

◆ MatchText()

bool NativeParserBase::MatchText ( const wxString text,
const wxString target,
bool  caseSens,
bool  isPrefix 
)
inlineprivate

◆ MatchType()

bool NativeParserBase::MatchType ( TokenKind  kind,
short int  kindMask 
)
inlineprivate

Definition at line 743 of file nativeparser_base.h.

Referenced by GenerateResultSet().

◆ PrettyPrintToken()

bool NativeParserBase::PrettyPrintToken ( TokenTree tree,
const Token token,
wxString result,
bool  isRoot = true 
)
protected

◆ RemoveLastFunctionChildren()

void NativeParserBase::RemoveLastFunctionChildren ( TokenTree tree,
int &  lastFuncTokenIdx 
)
protected

Remove the last function's children, when doing codecompletion in a function body, the function body up to the caret position was parsed, and the local variables defined in the function were recorded as the function's children.

Note that these tokens are marked as temporary tokens, so if the edit caret moves to another function body, these temporary tokens should be removed.

Definition at line 651 of file nativeparser_base.cpp.

References TokenTree::at(), CC_LOCKER_TRACK_TT_MTX_LOCK, CC_LOCKER_TRACK_TT_MTX_UNLOCK, Token::DeleteAllChildren(), Token::m_TokenKind, s_TokenTreeMutex, and tkAnyFunction.

Referenced by NativeParserBase::ParserComponent::Clear(), NativeParser::MarkItemsByAI(), and NativeParser::SetParser().

◆ Reset()

void NativeParserBase::Reset ( )
protected

◆ ResolveActualType()

size_t NativeParserBase::ResolveActualType ( TokenTree tree,
wxString  searchText,
const TokenIdxSet searchScope,
TokenIdxSet result 
)
protected

Get the Type information of the searchText string.

Parameters
searchTextinput search text
searchScopesearch scope defined in TokenIdxSet format
resultresult token specify the Type of searchText

Definition at line 1086 of file nativeparser_base.cpp.

References BreakUpComponents(), CC_LOCKER_TRACK_TT_MTX_LOCK, CC_LOCKER_TRACK_TT_MTX_UNLOCK, NativeParserBase::ParserComponent::component, GenerateResultSet(), and s_TokenTreeMutex.

Referenced by AddTemplateAlias(), NativeParserBase::ParserComponent::Clear(), ResolveExpression(), ResolveOperator(), and ResolveTemplateMap().

◆ ResolveExpression()

size_t NativeParserBase::ResolveExpression ( TokenTree tree,
std::queue< ParserComponent components,
const TokenIdxSet searchScope,
TokenIdxSet result,
bool  caseSense = true,
bool  isPrefix = false 
)
protected

A statement(expression) is expressed by a ParserComponent queue We do a match from the left of the queue one by one.

Here is a simple description about the algorithm, suppose we have such code snippet

namespace AAA
{
class BBB
{
public:
int m_aaa;
}
class CCC
{
public:
BBB fun();
}
}
AAA::CCC obj;
obj.fun().|-----we want to get code suggestion list here

We first split the statement "obj.fun()." into 3 components: component name

1, obj
2, fun

We do three loops here, each loop, we consume one component. Also each loop's result will serve as the next loop's search scope.

Loop 1 We first search the tree by the text "obj", we find a matched variable token, which has the type string "AAA::CCC", then the text "AAA::CCC" is resolved to a class kind token "class CCC" Loop 2 We search the tree by the text "fun". Here the search scope should be "CCC", it's the result from the previous loop, so we find that there is a function kind token under "class CCC", which is "function fun()" token. Then we need to see the return type of the fun() token, which is the name "BBB". Then we do another text search for "BBB" in the tree, and find a class kind token "class BBB" Loop 3 Since the last search text is empty, we just return all the children of the "class BBB" token, so finally, we give the child variable kind token "m_aaa", then the code suggestion should prompt the string "m_aaa"

Parameters
treethe token tree pointer
componentsexpression structure expressed in std::queue<ParserComponent>
searchScopesearch scope defined by TokenIdxSet
[out]thefinal result token index
caseSensecase sensitive match
isPrefixmatch type( full match or prefix match)
Returns
result tokens count

Definition at line 740 of file nativeparser_base.cpp.

References _T, AddConstructors(), AddTemplateAlias(), TokenTree::at(), CC_LOCKER_TRACK_TT_MTX_LOCK, CC_LOCKER_TRACK_TT_MTX_UNLOCK, CollectSearchScopes(), NativeParserBase::ParserComponent::component, CCLogger::DebugLog(), wxString::erase(), F(), GenerateResultSet(), CCLogger::Get(), wxString::IsEmpty(), Token::m_BaseType, Token::m_Index, Token::m_IsOperator, m_LastComponent, Token::m_Name, Token::m_ParentIndex, Token::m_TemplateMap, m_TemplateMap, Token::m_TokenKind, otOperatorUndefined, pttNamespace, pttSearchText, ResolveActualType(), ResolveOperator(), ResolveTemplateMap(), s_DebugSmartSense, s_TokenTreeMutex, tkClass, NativeParserBase::ParserComponent::tokenOperatorType, NativeParserBase::ParserComponent::tokenType, and wxString::wx_str().

Referenced by NativeParser::AI(), and NativeParserBase::ParserComponent::Clear().

◆ ResolveOperator()

void NativeParserBase::ResolveOperator ( TokenTree tree,
const OperatorType tokenOperatorType,
const TokenIdxSet tokens,
const TokenIdxSet searchScope,
TokenIdxSet result 
)
protected

used to solve the overloaded operator functions return type

Parameters
tokenOperatorTypeoverloaded operator type, could be [], (), ->
tokensinput tokens set
treeToken tree pointer
searchScopesearch scope
resultoutput result

Definition at line 995 of file nativeparser_base.cpp.

References _T, AddTemplateAlias(), TokenTree::at(), CC_LOCKER_TRACK_TT_MTX_LOCK, CC_LOCKER_TRACK_TT_MTX_UNLOCK, CollectSearchScopes(), TokenTree::empty(), GenerateResultSet(), wxString::IsEmpty(), Token::m_BaseType, Token::m_TokenKind, otOperatorParentheses, otOperatorPointer, otOperatorSquare, otOperatorStar, otOperatorUndefined, ResolveActualType(), ResolveTemplateMap(), s_TokenTreeMutex, tkClass, and tkTypedef.

Referenced by NativeParserBase::ParserComponent::Clear(), and ResolveExpression().

◆ ResolveTemplateMap()

void NativeParserBase::ResolveTemplateMap ( TokenTree tree,
const wxString searchStr,
const TokenIdxSet actualTypeScope,
TokenIdxSet initialScope 
)
protected

resolve template map [formal parameter] to [actual parameter]

Parameters
searchStrinput Search String
actualtypeScopeToken type(actual parameter)
initialScopesearch scope

Definition at line 1137 of file nativeparser_base.cpp.

References m_TemplateMap, and ResolveActualType().

Referenced by NativeParserBase::ParserComponent::Clear(), ResolveExpression(), and ResolveOperator().

Member Data Documentation

◆ m_LastComponent

ParserComponent NativeParserBase::m_LastComponent
private

Definition at line 749 of file nativeparser_base.h.

Referenced by Reset(), and ResolveExpression().

◆ m_TemplateMap

std::map<wxString, wxString> NativeParserBase::m_TemplateMap
private

Definition at line 750 of file nativeparser_base.h.

Referenced by AddTemplateAlias(), ResolveExpression(), and ResolveTemplateMap().


The documentation for this class was generated from the following files: