Code::Blocks  SVN r11506
tokentree.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
3  * http://www.gnu.org/licenses/gpl-3.0.html
4  */
5 
6 #ifndef TOKENTREE_H
7 #define TOKENTREE_H
8 
9 #include <wx/string.h>
10 #include <wx/thread.h>
11 
12 #include <vector>
13 #include <deque>
14 
15 #include "token.h"
16 #include "searchtree.h"
17 
20 
21 typedef std::deque<int> TokenIdxList;
22 typedef std::vector<Token*> TokenList;
25 typedef std::map< size_t, TokenIdxSet, std::less<size_t> > TokenFileMap;
26 typedef std::map< size_t, FileParsingStatus, std::less<size_t> > TokenFileStatusMap;
27 typedef std::map< int, wxString > TokenIdxStringMap;
28 
30 
37 class TokenTree
38 {
39  friend class CCDebugInfo;
40  friend class CCTest;
41  friend class CCTestFrame;
42  friend class NativeParserTest;
43 public:
44 
45  TokenTree();
46  virtual ~TokenTree();
47 
48  // STL compatibility functions
49  void clear();
50  inline Token* operator[](int idx) { return GetTokenAt(idx); }
51  inline Token* at(int idx) { return GetTokenAt(idx); }
52  inline const Token * at(int idx) const { return GetTokenAt(idx); }
53 
55  size_t size();
56 
60  size_t realsize();
61 
63  inline bool empty() { return size()==0; }
64 
69  int insert(Token* newToken);
70 
75  int insert(int loc, Token* newToken);
76 
78  int erase(int loc);
79 
84  void erase(Token* oldToken);
85 
86  inline void Clear() { clear(); }
87 
88  // Token specific functions
90  void RecalcFreeList();
91 
93  void RenameToken(Token* token, const wxString& newName);
94 
105  void RecalcInheritanceChain(Token* token);
106 
115  int TokenExists(const wxString& name, int parent, short int kindMask);
116 
126  int TokenExists(const wxString& name, const wxString& baseArgs, int parent, TokenKind kind);
127 
136  int TokenExists(const wxString& name, const TokenIdxSet& parents, short int kindMask);
137 
147  int TokenExists(const wxString& name, const wxString& baseArgs, const TokenIdxSet& parents,
148  TokenKind kind);
149 
159  size_t FindMatches(const wxString& query, TokenIdxSet& result, bool caseSensitive,
160  bool is_prefix, TokenKind kindMask = tkUndefined);
161 
162 
171  size_t FindTokensInFile(const wxString& filename, TokenIdxSet& result, short int kindMask);
172 
174  void RemoveFile(const wxString& filename);
175 
177  void RemoveFile(int fileIndex);
178 
180  const TokenList* GetTokens() const
181  {
182  return &m_Tokens;
183  }
184 
187  {
188  return &m_GlobalNameSpaces;
189  }
190 
191  const TokenFileMap* GetFilesMap() const
192  {
193  return &m_FileMap;
194  }
195 
196  const TokenIdxSet* GetTokensBelongToFile(size_t fileIdx) const
197  {
198  TokenFileMap::const_iterator it = m_FileMap.find(fileIdx);
199  return (it == m_FileMap.end() ? 0 : &(it->second));
200  }
201 
203  {
204  return &m_FilesToBeReparsed;
205  }
206 
207  size_t GetFileMapSize() const
208  {
209  return m_FileMap.size();
210  }
211 
212  void InsertTokenBelongToFile(size_t fileIdx, int tokenIdx)
213  {
214  m_FileMap[fileIdx].insert(tokenIdx);
215  }
216 
217  void EraseFileMapInFileMap(size_t fileIdx)
218  {
219  m_FileMap.erase(fileIdx);
220  }
221 
222  size_t GetFileStatusCountForIndex(size_t fileIdx) const
223  {
224  return m_FileStatusMap.count(fileIdx);
225  }
226 
227  void EraseFileStatusByIndex(size_t fileIdx)
228  {
229  m_FileStatusMap.erase(fileIdx);
230  }
231 
232  void EraseFilesToBeReparsedByIndex(size_t fileIdx)
233  {
234  m_FilesToBeReparsed.erase(fileIdx);
235  }
236 
237  // Parsing related functions
241  size_t InsertFileOrGetIndex(const wxString& filename);
242 
243  size_t GetFileMatches(const wxString& filename, std::set<size_t>& result,
244  bool caseSensitive, bool is_prefix);
245 
246  size_t GetFileIndex(const wxString& filename);
247 
248  const wxString GetFilename(size_t fileIdx) const;
249 
257  size_t ReserveFileForParsing(const wxString& filename, bool preliminary = false);
258 
262  void FlagFileForReparsing(const wxString& filename);
263 
265  void FlagFileAsParsed(const wxString& filename);
266 
270  bool IsFileParsed(const wxString& filename);
271 
278  void MarkFileTokensAsLocal(const wxString& filename, bool local = true, void* userData = 0);
279 
286  void MarkFileTokensAsLocal(size_t fileIdx, bool local = true, void* userData = 0);
287 
288  // Documentation related functions
289 
296  void AppendDocumentation(int tokenIdx, unsigned int fileIdx, const wxString& doc);
297 
303  wxString GetDocumentation(int tokenIdx);
304 
306 
307 protected:
308  Token* GetTokenAt(int idx);
309  Token const * GetTokenAt(int idx) const;
310  int AddToken(Token* newToken, int forceidx = -1);
311 
312  void RemoveToken(int idx);
313  void RemoveToken(Token* oldToken);
314 
321  int AddTokenToList(Token* newToken, int forceidx = -1);
325  void RemoveTokenFromList(int idx);
326 
327  void RecalcFullInheritance(int parentIdx, TokenIdxSet& result); // called by RecalcData
328 
334  bool CheckChildRemove(const Token* token, int fileIdx);
335 
346 
354 
361 
364 
367 
370 
373 
376 
379 };
380 
381 #endif // TOKENTREE_H
const TokenIdxSet * GetTokensBelongToFile(size_t fileIdx) const
Definition: tokentree.h:196
std::vector< Token * > TokenList
Definition: tokentree.h:22
int TokenExists(const wxString &name, int parent, short int kindMask)
query tokens by names
Definition: tokentree.cpp:141
BasicSearchTree TokenFilenameMap
Definition: tokentree.h:24
TokenSearchTree m_Tree
This is a string->TokenIndexSet map.
Definition: tokentree.h:345
void RenameToken(Token *token, const wxString &newName)
only the token&#39;s name need to be changed, thus update the index map of the TokenTree ...
Definition: tokentree.cpp:338
size_t InsertFileOrGetIndex(const wxString &filename)
put the filename in the m_FilenameMap, and return the file index, if this file is already in the m_Fi...
Definition: tokentree.cpp:835
Token * at(int idx)
Definition: tokentree.h:51
void clear()
Definition: tokentree.cpp:74
std::set< size_t, std::less< size_t > > TokenFileSet
Definition: token.h:19
void Clear()
Definition: tokentree.h:86
std::deque< int > TokenIdxList
Definition: tokentree.h:21
void InsertTokenBelongToFile(size_t fileIdx, int tokenIdx)
Definition: tokentree.h:212
int erase(int loc)
remove the Token specified by the index
Definition: tokentree.cpp:127
const wxString GetFilename(size_t fileIdx) const
Definition: tokentree.cpp:858
const TokenIdxSet * GetGlobalNameSpaces() const
all kinds of tokens under global name spaces
Definition: tokentree.h:186
virtual ~TokenTree()
Definition: tokentree.cpp:69
void EraseFilesToBeReparsedByIndex(size_t fileIdx)
Definition: tokentree.h:232
void FlagFileAsParsed(const wxString &filename)
mark the file status as fpsDone, since parsing this file is done
Definition: tokentree.cpp:931
friend class CCTestFrame
Definition: tokentree.h:41
TokenList m_Tokens
Contains the pointers to all the Token instances, it is just a std::vector<Token*>, the suggest way to access a Token instance is by first get its index in the m_Tokens, then get its address by m_Tokens[index], the reason we have such indirect access is that there are many Tokens which can reference each other, it is much safe using index instead of raw pointers.
Definition: tokentree.h:353
a container class to hold all the Tokens getting from parsing stage
Definition: tokentree.h:37
TokenFileMap m_FileMap
Map: file indices -> sets of TokenIndexes.
Definition: tokentree.h:372
size_t realsize()
some position of the std::vector<Token*> are not used, so the real size maybe a bit smaller than the ...
Definition: tokentree.cpp:103
TokenFileStatusMap m_FileStatusMap
Map: file indices -> status.
Definition: tokentree.h:375
size_t size()
total size of std::vector<Token*>
Definition: tokentree.cpp:98
size_t GetFileMapSize() const
Definition: tokentree.h:207
void AppendDocumentation(int tokenIdx, unsigned int fileIdx, const wxString &doc)
associate a document string with the token
Definition: tokentree.cpp:936
void RecalcFreeList()
collect the unused slots in the std::vector<Token*>
Definition: tokentree.cpp:633
void RecalcInheritanceChain(Token *token)
convert the Token&#39;s ancestor string to it&#39;s IDs this contains recursive calls, for example in such co...
Definition: tokentree.cpp:643
std::map< size_t, TokenIdxSet, std::less< size_t > > TokenFileMap
Definition: tokentree.h:25
bool empty()
check to see whether the TokenTree is empty
Definition: tokentree.h:63
void RecalcFullInheritance(int parentIdx, TokenIdxSet &result)
Definition: tokentree.cpp:787
friend class CCTest
Definition: tokentree.h:40
bool CheckChildRemove(const Token *token, int fileIdx)
Check all the children belong this token should be removed.
Definition: tokentree.cpp:609
std::map< size_t, FileParsingStatus, std::less< size_t > > TokenFileStatusMap
Definition: tokentree.h:26
void RemoveFile(const wxString &filename)
remove tokens belong to the file
Definition: tokentree.cpp:549
std::map< int, wxString > TokenIdxStringMap
Definition: tokentree.h:27
a symbol found in the parsed files, it can be many kinds, such as a variable, a class and so on...
Definition: token.h:82
int AddTokenToList(Token *newToken, int forceidx=-1)
add the Token pointer to the vector<Token*>, mostly the default value forceidx = -1 is used which add...
Definition: tokentree.cpp:485
std::set< int, std::less< int > > TokenIdxSet
Definition: token.h:16
wxMutex s_TokenTreeMutex
Definition: tokentree.cpp:49
size_t GetFileStatusCountForIndex(size_t fileIdx) const
Definition: tokentree.h:222
size_t GetFileIndex(const wxString &filename)
Definition: tokentree.cpp:851
const Token * at(int idx) const
Definition: tokentree.h:52
size_t FindTokensInFile(const wxString &filename, TokenIdxSet &result, short int kindMask)
find tokens belong to a specified file
Definition: tokentree.cpp:298
const TokenFileSet * GetFilesToBeReparsed() const
Definition: tokentree.h:202
This class is generally a string -> size_t map, the tree details (graph) is already show in the decla...
Definition: searchtree.h:276
const TokenList * GetTokens() const
Protected access to internal lists / maps.
Definition: tokentree.h:180
void MarkFileTokensAsLocal(const wxString &filename, bool local=true, void *userData=0)
mark the tokens so that they are associated with a C::B project
Definition: tokentree.cpp:874
undefined or just "all"
Definition: token.h:76
Token * operator[](int idx)
Definition: tokentree.h:50
size_t GetFileMatches(const wxString &filename, std::set< size_t > &result, bool caseSensitive, bool is_prefix)
Definition: tokentree.cpp:843
wxString GetDocumentation(int tokenIdx)
get the document string associated with the token
Definition: tokentree.cpp:960
Token * GetTokenAt(int idx)
Definition: tokentree.cpp:819
TokenIdxSet m_GlobalNameSpaces
any tokens belong to the global namespace
Definition: tokentree.h:366
void EraseFileStatusByIndex(size_t fileIdx)
Definition: tokentree.h:227
friend class NativeParserTest
Definition: tokentree.h:42
size_t FindMatches(const wxString &query, TokenIdxSet &result, bool caseSensitive, bool is_prefix, TokenKind kindMask=tkUndefined)
find a collection of matched tokens
Definition: tokentree.cpp:266
void RemoveToken(int idx)
Definition: tokentree.cpp:396
void RemoveTokenFromList(int idx)
Remove the Token specified by the idx in the vector<Token*>, note the Token instance is destroyed...
Definition: tokentree.cpp:536
TokenIdxSet m_TopNameSpaces
namespace tokens belongs to the global namespace
Definition: tokentree.h:363
size_t m_TokenTicketCount
Definition: tokentree.h:305
TokenFileSet m_FilesToBeReparsed
Set: file indices.
Definition: tokentree.h:378
TokenFilenameMap m_FilenameMap
Map: file names -> file indices.
Definition: tokentree.h:369
size_t ReserveFileForParsing(const wxString &filename, bool preliminary=false)
mark a file to be parsed.
Definition: tokentree.cpp:896
const TokenFileMap * GetFilesMap() const
Definition: tokentree.h:191
void EraseFileMapInFileMap(size_t fileIdx)
Definition: tokentree.h:217
SearchTree< TokenIdxSet > TokenSearchTree
Definition: tokentree.h:23
int insert(Token *newToken)
add a new Token instance to the TokenTree
Definition: tokentree.cpp:111
FileParsingStatus
Definition: tokentree.h:18
bool IsFileParsed(const wxString &filename)
is the file name is in the tokentree, and it&#39;s status is either assigned or beingparsed or done also...
Definition: tokentree.cpp:863
void FlagFileForReparsing(const wxString &filename)
mark the file as "need to be reparsed" status, usually happens that this file is saved(updated) so a ...
Definition: tokentree.cpp:926
TokenIdxList m_FreeTokens
List of all the deleted (and available) tokens.
Definition: tokentree.h:360
int AddToken(Token *newToken, int forceidx=-1)
Definition: tokentree.cpp:364
TokenKind
Definition: token.h:29