本文整理汇总了C++中TokenIdxSet类的典型用法代码示例。如果您正苦于以下问题:C++ TokenIdxSet类的具体用法?C++ TokenIdxSet怎么用?C++ TokenIdxSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TokenIdxSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: at
// caches the inheritance info for each token (recursive function)
void TokensTree::RecalcFullInheritance(int parentIdx, TokenIdxSet& result)
{
// no parent token? no ancestors...
if (parentIdx == -1)
return;
// no parent token? no ancestors...
Token* ancestor = at(parentIdx);
if (!ancestor)
return;
// only classes take part in inheritance
if (!(ancestor->m_TokenKind & (tkClass | tkTypedef)))
return;
TRACE(cc_text("RecalcFullInheritance() : Anc: '%s'"), ancestor->m_Name.wx_str());
// for all its ancestors
for (TokenIdxSet::iterator it = ancestor->m_Ancestors.begin(); it != ancestor->m_Ancestors.end(); it++)
{
if (*it != -1 && // not global scope
*it != parentIdx && // not the same token (avoid infinite loop)
result.find(*it) == result.end()) // not already in the set (avoid infinite loop)
{
// add it to the set
result.insert(*it);
// and recurse for its ancestors
RecalcFullInheritance(*it, result);
}
}
}
示例2: FindMatches
size_t TokenTree::FindMatches(const wxString& query, TokenIdxSet& result, bool caseSensitive, bool is_prefix, TokenKind kindMask)
{
result.clear();
std::set<size_t> lists;
int numitems = m_Tree.FindMatches(query, lists, caseSensitive, is_prefix);
if (!numitems)
return 0;
// now the lists contains indexes to all the matching keywords
// first loop will find all the keywords
for (std::set<size_t>::const_iterator it = lists.begin(); it != lists.end(); ++it)
{
const TokenIdxSet* curset = &(m_Tree.GetItemAtPos(*it));
// second loop will get all the items mapped by the same keyword,
// for example, we have ClassA::foo, ClassB::foo ...
if (curset)
{
for (TokenIdxSet::const_iterator it2 = curset->begin(); it2 != curset->end(); ++it2)
{
const Token* token = at(*it2);
if ( token
&& ( (kindMask == tkUndefined)
|| (token->m_TokenKind & kindMask) ) )
result.insert(*it2);
}
}
}
return result.size();
}
示例3: TokenExists
int TokenTree::TokenExists(const wxString& name, const TokenIdxSet& parents, short int kindMask)
{
int idx = m_Tree.GetItemNo(name);
if (!idx)
return -1;
TokenIdxSet::const_iterator it;
TokenIdxSet& curList = m_Tree.GetItemAtPos(idx);
int result = -1;
for (it = curList.begin(); it != curList.end(); ++it)
{
result = *it;
if (result < 0 || (size_t)result >= m_Tokens.size())
continue;
const Token* curToken = m_Tokens[result];
if (!curToken)
continue;
if (curToken->m_TokenKind & kindMask)
{
for ( TokenIdxSet::const_iterator pIt = parents.begin();
pIt != parents.end(); ++pIt )
{
if (curToken->m_ParentIndex == *pIt)
return result;
}
}
}
return -1;
}
示例4: SaveTokenIdxSetToFile
inline void SaveTokenIdxSetToFile(std::ostream& f,const TokenIdxSet& data)
{
SaveIntToFile(f, (int)(data.size()));
for (TokenIdxSet::iterator it = data.begin(); it != data.end(); it++)
{
int num = *it;
SaveIntToFile(f, num);
}
}
示例5: TRACE
size_t ParserBase::FindTokensInFile(const wxString& filename, TokenIdxSet& result, short int kindMask)
{
result.clear();
size_t tokens_found = 0;
TRACE(_T("Parser::FindTokensInFile() : Searching for file '%s' in tokens tree..."), filename.wx_str());
CC_LOCKER_TRACK_TT_MTX_LOCK(s_TokenTreeMutex)
TokenIdxSet tmpresult;
if ( m_TokenTree->FindTokensInFile(filename, tmpresult, kindMask) )
{
for (TokenIdxSet::const_iterator it = tmpresult.begin(); it != tmpresult.end(); ++it)
{
const Token* token = m_TokenTree->at(*it);
if (token)
result.insert(*it);
}
tokens_found = result.size();
}
CC_LOCKER_TRACK_TT_MTX_UNLOCK(s_TokenTreeMutex)
return tokens_found;
}
示例6: FindMatches
size_t TokensTree::FindMatches(const cc_string& s,TokenIdxSet& result,bool caseSensitive,bool is_prefix, int kindMask)
{
set<size_t> lists;
result.clear();
int numitems = m_Tree.FindMatches(s,lists,caseSensitive,is_prefix);
if(!numitems)
return 0;
// now the lists contains indexes to all the matching keywords
TokenIdxSet* curset;
set<size_t>::iterator it;
TokenIdxSet::iterator it2;
// first loop will find all the keywords
for(it = lists.begin(); it != lists.end(); it++)
{
curset = &(m_Tree.GetItemAtPos(*it));
// second loop will get all the items maped by the same keyword,
// for example, we have ClassA::foo, ClassB::foo ...
for(it2 = curset->begin();it2 != curset->end(); it2++)
{
if (kindMask == 0xffff || (at(*it)->m_TokenKind & kindMask))
result.insert(*it2);
}
}
return result.size();
}
示例7: f
size_t TokenTree::FindTokensInFile(const wxString& filename, TokenIdxSet& result, short int kindMask)
{
result.clear();
// get file idx
wxString f(filename); while (f.Replace(_T("\\"),_T("/"))) { ; }
if ( !m_FilenameMap.HasItem(f) )
{
// CCLogger::Get()->DebugLog(F(_T("TokenTree::FindTokensInFile() : File '%s' not found in file names map."), f.wx_str()));
TRACE(_T("TokenTree::FindTokensInFile() : File '%s' not found in file names map."), f.wx_str());
return 0;
}
int idx = m_FilenameMap.GetItemNo(f);
// now get the tokens set matching this file idx
TokenFileMap::iterator itf = m_FileMap.find(idx);
if (itf == m_FileMap.end())
{
// CCLogger::Get()->DebugLog(F(_T("TokenTree::FindTokensInFile() : No tokens found for file '%s' (index %d)."), f.wx_str(), idx));
TRACE(_T("TokenTree::FindTokensInFile() : No tokens found for file '%s' (index %d)."), f.wx_str(), idx);
return 0;
}
// loop all results and add to final result set after filtering on token kind
TokenIdxSet& tokens = itf->second;
for (TokenIdxSet::const_iterator it = tokens.begin(); it != tokens.end(); ++it)
{
const Token* token = at(*it);
if (token && (kindMask & token->m_TokenKind))
result.insert(*it);
}
// CCLogger::Get()->DebugLog(F(_T("TokenTree::FindTokensInFile() : Found %lu results for file '%s'."), static_cast<unsigned long>(result.size()), f.wx_str()));
TRACE(_T("TokenTree::FindTokensInFile() : Found %lu results for file '%s'."), static_cast<unsigned long>(result.size()), f.wx_str());
return result.size();
}
示例8: FindTokensInFile
size_t TokensTree::FindTokensInFile(const cc_string& file, TokenIdxSet& result, short int kindMask)
{
result.clear();
// get file idx
if (!m_FilenamesMap.HasItem(file))
return 0;
int idx = m_FilenamesMap.GetItemIdx(file);
// now get the tokens set matching this file idx
TokenFilesMap::iterator itf = m_FilesMap.find(idx);
if (itf == m_FilesMap.end())
return 0;
TokenIdxSet& tokens = itf->second;
// loop all results and add to final result set after filtering on token kind
for (TokenIdxSet::iterator it = tokens.begin(); it != tokens.end(); ++it)
{
Token* token = at(*it);
if (kindMask & token->m_TokenKind)
result.insert(*it);
}
return result.size();
}
示例9: OnFindClick
void CCDebugInfo::OnFindClick(wxCommandEvent& /*event*/)
{
TokensTree* tokens = m_Parser->GetTokensTree();
wxString search = txtFilter->GetValue();
m_Token = 0;
// first determine if the user entered an ID or a search mask
long unsigned id;
if (search.ToULong(&id, 10))
{
// easy; ID
m_Token = tokens->at(id);
}
else
{
// find all matching tokens
TokenIdxSet result;
for (size_t i = 0; i < tokens->size(); ++i)
{
Token* token = tokens->at(i);
if (token && token->m_Name.Matches(search))
result.insert(i);
}
// a single result?
if (result.size() == 1)
{
m_Token = tokens->at(*(result.begin()));
}
else
{
// fill a list and ask the user which token to display
wxArrayString arr;
wxArrayInt intarr;
for (TokenIdxSet::iterator it = result.begin(); it != result.end(); ++it)
{
Token* token = tokens->at(*it);
arr.Add(token->DisplayName());
intarr.Add(*it);
}
int sel = wxGetSingleChoiceIndex(_("Please make a selection:"), _("Multiple matches"), arr, this);
if (sel == -1)
return;
m_Token = tokens->at(intarr[sel]);
}
}
DisplayTokenInfo();
}
示例10: FindMatches
size_t TokensTree::FindMatches(const wxString& s,TokenIdxSet& result,bool caseSensitive,bool is_prefix, int kindMask)
{
set<size_t> lists;
result.clear();
int numitems = m_Tree.FindMatches(s,lists,caseSensitive,is_prefix);
if(!numitems)
return 0;
TokenIdxSet* curset;
set<size_t>::iterator it;
TokenIdxSet::iterator it2;
for(it = lists.begin(); it != lists.end(); it++)
{
curset = &(m_Tree.GetItemAtPos(*it));
for(it2 = curset->begin();it2 != curset->end(); it2++)
{
if (kindMask == 0xffff || (at(*it)->m_TokenKind & kindMask))
result.insert(*it2);
}
}
return result.size();
}
示例11: UnixFilename
size_t ParserBase::FindTokensInFile(const wxString& fileName, TokenIdxSet& result, short int kindMask)
{
result.clear();
wxString file = UnixFilename(fileName);
TRACE(_T("Parser::FindTokensInFile() : Searching for file '%s' in tokens tree..."), file.wx_str());
TRACK_THREAD_LOCKER(s_TokensTreeCritical);
wxCriticalSectionLocker locker(s_TokensTreeCritical);
THREAD_LOCKER_SUCCESS(s_TokensTreeCritical);
TokenIdxSet tmpresult;
if ( !m_TokensTree->FindTokensInFile(file, tmpresult, kindMask) )
return 0;
for (TokenIdxSet::iterator it = tmpresult.begin(); it != tmpresult.end(); ++it)
{
Token* token = m_TokensTree->at(*it);
if (token)
result.insert(*it);
}
return result.size();
}
示例12: GetSymbolUnderCursor
bool CodeRefactoring::Parse()
{
cbEditor* editor = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
if (!editor)
return false;
const wxString targetText = GetSymbolUnderCursor();
if (targetText.IsEmpty())
return false;
TokenIdxSet targetResult;
const int endOfWord = editor->GetControl()->WordEndPosition(editor->GetControl()->GetCurrentPos(), true);
m_NativeParser.MarkItemsByAI(targetResult, true, false, true, endOfWord);
if (targetResult.empty())
{
cbMessageBox(_("Symbol not found under cursor!"), _("Code Refactoring"), wxOK | wxICON_WARNING);
return false;
}
// handle local variables
bool isLocalVariable = false;
TokenTree* tree = m_NativeParser.GetParser().GetTokenTree();
CC_LOCKER_TRACK_TT_MTX_LOCK(s_TokenTreeMutex)
const Token* token = tree->at(*targetResult.begin());
if (token)
{
const Token* parent = tree->at(token->m_ParentIndex);
if (parent && parent->m_TokenKind == tkFunction)
isLocalVariable = true;
}
CC_LOCKER_TRACK_TT_MTX_UNLOCK(s_TokenTreeMutex)
wxArrayString files;
cbProject* project = m_NativeParser.GetProjectByEditor(editor);
if (isLocalVariable || !project)
files.Add(editor->GetFilename());
else
{
ScopeDialog scopeDlg(Manager::Get()->GetAppWindow(), _("Code Refactoring"));
const int ret = scopeDlg.ShowModal();
if (ret == ScopeDialog::ID_OPEN_FILES)
GetOpenedFiles(files);
else if (ret == ScopeDialog::ID_PROJECT_FILES)
GetAllProjectFiles(files, project);
else
return false;
}
if (files.IsEmpty())
return false;
size_t count = SearchInFiles(files, targetText);
if (count)
count = VerifyResult(targetResult, targetText, isLocalVariable);
return count != 0;
}
示例13: RemoveToken
void TokensTree::RemoveToken(Token* oldToken)
{
if(!oldToken)
return;
int idx = oldToken->m_Self;
if(m_Tokens[idx]!=oldToken)
return;
// Step 1: Detach token from its parent
Token* parentToken = 0;
if((size_t)(oldToken->m_ParentIndex) >= m_Tokens.size())
oldToken->m_ParentIndex = -1;
if(oldToken->m_ParentIndex >= 0)
parentToken = m_Tokens[oldToken->m_ParentIndex];
if(parentToken)
parentToken->m_Children.erase(idx);
TokenIdxSet nodes;
TokenIdxSet::iterator it;
// Step 2: Detach token from its ancestors
nodes = (oldToken->m_DirectAncestors);
for(it = nodes.begin();it!=nodes.end(); it++)
{
int ancestoridx = *it;
if(ancestoridx < 0 || (size_t)ancestoridx >= m_Tokens.size())
continue;
Token* ancestor = m_Tokens[ancestoridx];
if(ancestor)
ancestor->m_Descendants.erase(idx);
}
oldToken->m_Ancestors.clear();
oldToken->m_DirectAncestors.clear();
// Step 3: Remove children
nodes = (oldToken->m_Children); // Copy the list to avoid interference
for(it = nodes.begin();it!=nodes.end(); it++)
RemoveToken(*it);
// m_Children SHOULD be empty by now - but clear anyway.
oldToken->m_Children.clear();
// Step 4: Remove descendants
nodes = oldToken->m_Descendants; // Copy the list to avoid interference
for(it = nodes.begin();it!=nodes.end(); it++)
RemoveToken(*it);
// m_Descendants SHOULD be empty by now - but clear anyway.
oldToken->m_Descendants.clear();
// Step 5: Detach token from the SearchTrees
int idx2 = m_Tree.GetItemNo(oldToken->m_Name);
if(idx2)
{
TokenIdxSet& curlist = m_Tree.GetItemAtPos(idx2);
curlist.erase(idx);
}
// Now, from the global namespace (if applicable)
if(oldToken->m_ParentIndex == -1)
{
m_GlobalNameSpace.erase(idx);
m_TopNameSpaces.erase(idx);
}
// Step 6: Finally, remove it from the list.
RemoveTokenFromList(idx);
}
示例14: TRACE
void TokensTree::RecalcData()
{
TRACE(cc_text("RecalcData() : Calculating full inheritance tree."));
// first loop to convert ancestors string to token indices for each token
for (size_t i = 0; i < size(); ++i)
{
Token* token = at(i);
if (!token)
continue;
if (!(token->m_TokenKind & (tkClass | tkTypedef | tkEnum)))
continue;
if (token->m_AncestorsString.empty())
continue;
// only local symbols might change inheritance
// if (!token->m_IsLocal)
// continue;
token->m_DirectAncestors.clear();
token->m_Ancestors.clear();
TRACE(cc_text("RecalcData() : Token %s, Ancestors %s"),
token->m_Name.wx_str(),
token->m_AncestorsString.wx_str());
StringTokenizer tkz(token->m_AncestorsString, cc_text(","));
while (tkz.HasMoreTokens())
{
cc_string ancestor = tkz.GetNextToken();
if (ancestor.empty() || ancestor == token->m_Name)
continue;
TRACE(cc_text("RecalcData() : Ancestor %s"), ancestor.wx_str());
// ancestors might contain namespaces, e.g. NS::Ancestor
if (ancestor.find(cc_text("::")) != cc_string::npos)
{
Token* ancestorToken = 0;
StringTokenizer anctkz(ancestor, cc_text("::"));
while (anctkz.HasMoreTokens())
{
cc_string ns = anctkz.GetNextToken();
if (!ns.empty())
{
int ancestorIdx = TokenExists(ns, ancestorToken ? ancestorToken->GetSelf() : -1, tkNamespace | tkClass | tkTypedef);
ancestorToken = at(ancestorIdx);
// ancestorToken = token->HasChildToken(ns, tkNamespace | tkClass);
if (!ancestorToken) // unresolved
break;
}
}
if (ancestorToken && ancestorToken != token && ancestorToken->m_TokenKind == tkClass)// && !ancestorToken->m_IsTypedef)
{
TRACE(cc_text("RecalcData() : Resolved to %s"), ancestorToken->m_Name.wx_str());
token->m_Ancestors.insert(ancestorToken->GetSelf());
ancestorToken->m_Descendants.insert(i);
TRACE(cc_text("RecalcData() : + '%s'"), ancestorToken->m_Name.wx_str());
}
else
TRACE(cc_text("RecalcData() : ! '%s' (unresolved)"), ancestor.wx_str());
}
else // no namespaces in ancestor
{
// accept multiple matches for inheritance
TokenIdxSet result;
FindMatches(ancestor, result, true, false);
for (TokenIdxSet::iterator it = result.begin(); it != result.end(); it++)
{
Token* ancestorToken = at(*it);
// only classes take part in inheritance
if ( ancestorToken
&& (ancestorToken != token)
&& ( (ancestorToken->m_TokenKind == tkClass)
|| (ancestorToken->m_TokenKind == tkEnum)
|| (ancestorToken->m_TokenKind == tkTypedef) ) ) // && !ancestorToken->m_IsTypedef)
{
token->m_Ancestors.insert(*it);
ancestorToken->m_Descendants.insert(i);
TRACE(cc_text("RecalcData() : + '%s'"), ancestorToken->m_Name.wx_str());
}
}
#if TOKEN_DEBUG_OUTPUT
if (result.empty())
TRACE(_T("RecalcData() : ! '%s' (unresolved)"), ancestor.wx_str());
#endif
}
}
token->m_DirectAncestors = token->m_Ancestors;
if (!token->m_IsLocal) // global symbols are linked once
{
TRACE(cc_text("RecalcData() : Removing ancestor string from %s"), token->m_Name.wx_str(), token->m_Name.wx_str());
token->m_AncestorsString.clear();
}
}
// second loop to calculate full inheritance for each token
for (size_t i = 0; i < size(); ++i)
//.........这里部分代码省略.........
示例15: at
void TokensTree::RecalcData()
{
// Manager::Get()->GetMessageManager()->DebugLog(_T("Calculating full inheritance tree"));
// first loop to convert ancestors string to token indices for each token
for (size_t i = 0; i < size(); ++i)
{
Token* token = at(i);
if (!token)
continue;
if (!(token->m_TokenKind & (tkClass | tkTypedef | tkEnum)))
continue;
if (token->m_AncestorsString.IsEmpty())
continue;
// only local symbols might change inheritance
// if (!token->m_IsLocal)
// continue;
token->m_DirectAncestors.clear();
token->m_Ancestors.clear();
// Manager::Get()->GetMessageManager()->DebugLog(_T(" : '%s'"), token->m_Name.c_str());
//Manager::Get()->GetMessageManager()->DebugLog("Token %s, Ancestors %s", token->m_Name.c_str(), token->m_AncestorsString.c_str());
wxStringTokenizer tkz(token->m_AncestorsString, _T(","));
while (tkz.HasMoreTokens())
{
wxString ancestor = tkz.GetNextToken();
if (ancestor.IsEmpty() || ancestor == token->m_Name)
continue;
// Manager::Get()->GetMessageManager()->DebugLog(_T("Ancestor %s"), ancestor.c_str());
// ancestors might contain namespaces, e.g. NS::Ancestor
if (ancestor.Find(_T("::")) != wxNOT_FOUND)
{
Token* ancestorToken = 0;
wxStringTokenizer anctkz(ancestor, _T("::"));
while (anctkz.HasMoreTokens())
{
wxString ns = anctkz.GetNextToken();
if (!ns.IsEmpty())
{
int ancestorIdx = TokenExists(ns, ancestorToken ? ancestorToken->GetSelf() : -1, tkNamespace | tkClass | tkTypedef);
ancestorToken = at(ancestorIdx);
// ancestorToken = token->HasChildToken(ns, tkNamespace | tkClass);
if (!ancestorToken) // unresolved
break;
}
}
if (ancestorToken && ancestorToken != token && ancestorToken->m_TokenKind == tkClass)// && !ancestorToken->m_IsTypedef)
{
// Manager::Get()->GetMessageManager()->DebugLog(_T("Resolved to %s"), ancestorToken->m_Name.c_str());
token->m_Ancestors.insert(ancestorToken->GetSelf());
ancestorToken->m_Descendants.insert(i);
// Manager::Get()->GetMessageManager()->DebugLog(_T(" + '%s'"), ancestorToken->m_Name.c_str());
}
// else
// Manager::Get()->GetMessageManager()->DebugLog(_T(" ! '%s' (unresolved)"), ancestor.c_str());
}
else // no namespaces in ancestor
{
// accept multiple matches for inheritance
TokenIdxSet result;
FindMatches(ancestor, result, true, false);
for (TokenIdxSet::iterator it = result.begin(); it != result.end(); it++)
{
Token* ancestorToken = at(*it);
// only classes take part in inheritance
if (ancestorToken && ancestorToken != token && (ancestorToken->m_TokenKind == tkClass || ancestorToken->m_TokenKind == tkEnum))// && !ancestorToken->m_IsTypedef)
{
token->m_Ancestors.insert(*it);
ancestorToken->m_Descendants.insert(i);
// Manager::Get()->GetMessageManager()->DebugLog(_T(" + '%s'"), ancestorToken->m_Name.c_str());
}
}
// if (result.empty())
// Manager::Get()->GetMessageManager()->DebugLog(_T(" ! '%s' (unresolved)"), ancestor.c_str());
}
}
token->m_DirectAncestors = token->m_Ancestors;
if (!token->m_IsLocal) // global symbols are linked once
{
//Manager::Get()->GetMessageManager()->DebugLog("Removing ancestor string from %s", token->m_Name.c_str(), token->m_Name.c_str());
token->m_AncestorsString.Clear();
}
}
// second loop to calculate full inheritance for each token
for (size_t i = 0; i < size(); ++i)
{
Token* token = at(i);
if (!token)
continue;
if (!(token->m_TokenKind & (tkClass | tkTypedef | tkEnum)))
continue;
// recalc
TokenIdxSet result;
//.........这里部分代码省略.........