Debian Codegraph @

CodeLite/ctags_manager.h

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // copyright : (C) 2008 by Eran Ifrah
5 // file name : ctags_manager.h
6 //
7 // -------------------------------------------------------------------------
8 // A
9 // _____ _ _ _ _
10 // / __ \ | | | | (_) |
11 // | / \/ ___ __| | ___| | _| |_ ___
12 // | | / _ \ / _ |/ _ \ | | | __/ _ )
13 // | \__/\ (_) | (_| | __/ |___| | || __/
14 // \____/\___/ \__,_|\___\_____/_|\__\___|
15 //
16 // F i l e
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 //////////////////////////////////////////////////////////////////////////////
24 //////////////////////////////////////////////////////////////////////////////
25
26 #ifndef CODELITE_CTAGS_MANAGER_H
27 #define CODELITE_CTAGS_MANAGER_H
28
29 #include "cl_calltip.h"
30 #include "cl_command_event.h"
31 #include "cl_process.h"
32 #include "codelite_exports.h"
33 #include "comment.h"
34 #include "cpptoken.h"
35 #include "entry.h"
36 #include "extdbdata.h"
37 #include "istorage.h"
38 #include "language.h"
39 #include "macros.h"
40 #include "setters_getters_data.h"
41 #include "singleton.h"
42 #include "tags_options_data.h"
43 #include "tree.h"
44 #include "wx/event.h"
45 #include "wx/process.h"
46 #include "wxStringHash.h"
47
48 #include <set>
49 #include <wx/stopwatch.h>
50 #include <wx/thread.h>
51 #include <wx/timer.h>
52
53 #ifdef USE_TRACE
54 #include <wx/stopwatch.h>
55 #endif
56
57 /// Forward declaration
58 class DirTraverser;
59 class Language;
60 class Language;
61 class IProcess;
62
63 // Change this macro if you dont want to use the parser thread for performing
64 // the workspcae retag
65 #define USE_PARSER_TREAD_FOR_RETAGGING_WORKSPACE 1
66
67 // BUG#3082954
68 #define MAX_TIP_LINE_SIZE 200
69
70 #define USE_TAGS_SQLITE3 1
71
72 struct DoxygenComment {
73 wxString name;
74 wxString comment;
75 };
76
77 // By default the NormalizeFunctionSig returns only the variables type
78 enum NormalizeFuncFlag {
79 // variable name
80 Normalize_Func_Name = (1 << 0),
81 // variable default value
82 Normalize_Func_Default_value = (1 << 1),
83 // Each argument is placed on a separate line
84 Normalize_Func_Arg_Per_Line = (1 << 2),
85 };
86
87 enum FunctionFormatFlag {
88 FunctionFormat_WithVirtual = (1 << 0),
89 FunctionFormat_Impl = (1 << 1),
90 FunctionFormat_Arg_Per_Line = (1 << 2),
91 FunctionFormat_WithOverride = (1 << 3),
92 };
93
94 /**
95 * This class is the interface to ctags and SQLite database.
96 * It contains various APIs that allows the caller to parse source file(s),
97 * store it into the database and return a symbol tree.
98 * TagsManager is also responsible for starting ctags processes.
99 *
100 * Before you use TagsManager, usually you would like to start ctags,
101 * this is easily done by writing something like this:
102 *
103 * In the destructor of your main frame it is recommended to call Free() to avoid memory leaks:
104 *
105 * @code
106 * // kill the TagsManager object first it will do the process termination and cleanup
107 * TagsManager::Free();
108 * @endcode
109 *
110 * @ingroup CodeLite
111 * @version 1.0
112 * first version
113 *
114 * @date 09-01-2006
115 *
116 * @author Eran
117 *
118 */
119 class WXDLLIMPEXP_CL TagsManager : public wxEvtHandler
120 {
121 // Members
122 friend class TagsManagerST;
123 friend class DirTraverser;
124 friend class Language;
125
126 public:
127 enum RetagType { Retag_Full, Retag_Quick, Retag_Quick_No_Scan };
128 enum eLanguage { kCxx, kJavaScript };
129
130 public:
131 wxCriticalSection m_crawlerLocker;
132
133 private:
134 wxStopWatch m_watch;
135 TagsOptionsData m_tagsOptions;
136 bool m_parseComments = false;
137 Language* m_lang;
138 std::vector<TagEntryPtr> m_cachedFileFunctionsTags;
139 wxString m_cachedFile;
140 bool m_enableCaching = false;
141 wxEvtHandler* m_evtHandler = nullptr;
142 wxStringSet_t m_CppIgnoreKeyWords;
143 wxArrayString m_projectPaths;
144 wxFontEncoding m_encoding;
145 wxFileName m_dbFile;
146
147 #if USE_TAGS_SQLITE3
148 ITagsStoragePtr m_db;
149 #endif
150 wxString m_indexer_path;
151
152 public:
153 /**
154 * @brief return a set of CXX keywords
155 */
156 static void GetCXXKeywords(wxStringSet_t& words);
157
158 /**
159 * @brief return an array of CXX keywords
160 */
161 static void GetCXXKeywords(wxArrayString& words);
162
163 void SetIndexerPath(const wxString& indexer_path) { m_indexer_path = indexer_path; }
164 const wxString& GetIndexerPath() const { return m_indexer_path; }
165
166 void SetLanguage(Language* lang);
167 Language* GetLanguage();
168 void SetEvtHandler(wxEvtHandler* handler) { m_evtHandler = handler; }
169
170 /**
171 * @brief return the currently cached file
172 */
173 bool IsFileCached(const wxString& fileName) const;
174
175 /**
176 * @brief clear the file cached
177 */
178 void ClearCachedFile(const wxString& fileName);
179
180 /**
181 4* @brief clear all the cached tags information stored in this class
182 */
183 void ClearAllCaches();
184
185 /**
186 * @brief load fileName into cache, note that this call will clear perivous
187 * cache
188 */
189 void CacheFile(const wxString& fileName);
190
191 /**
192 * @brief return the cached file tags
193 */
194 const std::vector<TagEntryPtr>& GetCachedFileTags() const { return m_cachedFileFunctionsTags; }
195
196 /**
197 * Return the CtagsOptions used by the tags manager
198 * @return
199 */
200 const TagsOptionsData& GetCtagsOptions() const { return m_tagsOptions; }
201
202 /**
203 * Set Ctags Options
204 * @param options options to use
205 */
206 void SetCtagsOptions(const TagsOptionsData& options);
207
208 void SetEncoding(const wxFontEncoding& encoding);
209
210 /**
211 * Locate symbol by name in database
212 * @param name name to search
213 * @param tags [output] result vector
214 */
215 void FindSymbol(const wxString& name, std::vector<TagEntryPtr>& tags);
216
217 /**
218 * Parse a source file and construct a TagTree.
219 * This function throws a std::exception*.
220 * @param fp Source file name
221 * @param comments if not null, comments will be parsed as well, and will be returned as vector
222 * @return tag tree
223 */
224 TagTreePtr ParseSourceFile2(const wxFileName& fp, const wxString& tags, std::vector<CommentPtr>* comments = NULL);
225
226 /**
227 * @brief parse source file (from memory) and return list of tags
228 * If "filename" is passed, each returned TagEntryPtr will have it as its "File" attribute
229 */
230 TagEntryPtrVector_t ParseBuffer(const wxString& content, const wxString& filename = wxEmptyString,
231 const wxString& kinds = "cdefgmnpstuv");
232
233 /**
234 * load all symbols of fileName from the database and return them
235 * to user as tree
236 * @param path file's symbols
237 * @param tags if tags is set to non NULL, the tags are converted to TagTreePtr
238 * @return tag tree
239 */
240 TagTreePtr Load(const wxFileName& fileName, TagEntryPtrVector_t* tags = NULL);
241
242 /**
243 * Open sqlite database.
244 * @param fileName Database file name
245 */
246 void OpenDatabase(const wxFileName& fileName);
247
248 /**
249 * Return a pointer to the underlying databases object.
250 * @return tags database
251 */
252 ITagsStoragePtr GetDatabase();
253
254 /**
255 * Delete all entries from database that are related to file name.
256 * @param path Database name
257 * @param fileName File name
258 */
259 void Delete(const wxFileName& path, const wxString& fileName);
260
261 /**
262 * Test if filename matches the current ctags file spec.
263 * @param filename file name to test
264 * @return true if the file name extension matches the current running ctags file spec
265 */
266 bool IsValidCtagsFile(const wxFileName& filename) const;
267
268 /**
269 * @brief set the project paths
270 */
271 void SetProjectPaths(const wxArrayString& paths);
272
273 /**
274 * @return project file paths
275 */
276 const wxArrayString& GetProjectPaths() const { return m_projectPaths; }
277
278 /**
279 * Find symbols by name and scope.
280 * @param name symbol name
281 * @param scope full path to symbol. if set to wxEmptyString, the search is performed against the global
282 * @param tags [output] a vector of the results tags
283 * @return true on success false otherwise
284 */
285 void FindByNameAndScope(const wxString& name, const wxString& scope, std::vector<TagEntryPtr>& tags);
286
287 /**
288 * Find tags with given path
289 * @param path path to search
290 * @param tags [output] output tags
291 */
292 void FindByPath(const wxString& path, std::vector<TagEntryPtr>& tags);
293
294 /**
295 * Get tags related to a scope.
296 * @param scope scope to search for members
297 * @param tags [output] vector of tags
298 */
299 void TagsByScope(const wxString& scope, std::vector<TagEntryPtr>& tags);
300
301 /**
302 * Get tags related to a scope and name (name can be partial name
303 * @param scope scope to search for members
304 * @param name partial tag name
305 * @param tags [output] vector of tags
306 */
307 void TagsByScopeAndName(const wxString& scope, const wxString& name, std::vector<TagEntryPtr>& tags,
308 size_t flags = PartialMatch);
309
310 /**
311 * Delete all tags related to these files
312 * @param files list of files, in absolute path
313 */
314 void DeleteFilesTags(const std::vector<wxFileName>& files);
315 void DeleteFilesTags(const wxArrayString& files);
316
317 /**
318 * @brief delete all entries from tags database which starts with. If the dbFileName is also an active one,
319 * clear any cache entries as well
320 * @param dbfileName database file path
321 * @param filePrefix tag file's prefix
322 */
323 void DeleteTagsByFilePrefix(const wxString& dbfileName, const wxString& filePrefix);
324
325 /**
326 * Close the workspace database
327 */
328 void CloseDatabase();
329
330 /**
331 * @brief trigger a complete parsing of the workspace
332 */
333 void ParseWorkspaceFull(const wxString& workspace_dir);
334
335 /**
336 * @brief trigger an incremental workspace parsing
337 */
338 void ParseWorkspaceIncremental();
339
340 /**
341 * Get a hover tip. This function is a wrapper around the Language::GetHoverTip.
342 * @param expr the current expression
343 * @param word the token under the cursor
344 * @param text scope where token was found
345 * @param scopeName scope name
346 * @param isFunc is token is a function
347 * @param tips array of tip strings
348 */
349 void GetHoverTip(const wxFileName& fileName, int lineno, const wxString& expr, const wxString& word,
350 const wxString& text, std::vector<wxString>& tips);
351
352 /**
353 * Return true if comment parsing is enabled, false otherwise
354 */
355 bool GetParseComments();
356
357 /**
358 * Generate doxygen based on file & line. The generated doxygen is partial, that is, only the "\param" "\return"
359 * is generated. On top of the comment, there will be the a place holder to be replaced by the application, the
360 * place
361 * holder can be one of:
362 * '$(ClassPattern)' or '$(FunctionPattern)'
363 * @param line line number
364 * @param file file name
365 * @param keyPrefix prefix to use for the 'param' & 'return' keyword (can be @ or \ )
366 */
367 DoxygenComment GenerateDoxygenComment(const wxString& file, const int line, wxChar keyPrefix);
368
369 /**
370 * Load all types from database. 'Type' is one of:
371 * class, namespace, struct, union, enum, macro, typedef
372 * @param &tags
373 */
374 void OpenType(std::vector<TagEntryPtr>& tags);
375
376 /**
377 * return string containing a code section to be inserted into the document. By providing
378 * decl which is not null, this function will split the generated code into two - decl & impl
379 * @param scope the current text from beginning of the document up to the cursor pos, this
380 * string will be parsed by CodeLite to determine the current scope
381 * @param data user's settings for the generation of the getters/setters
382 * @param tags list of members to create setters/getters for them.
383 * @param impl [output] the generated code - implementation, if 'decl' member is null,
384 it will include the declaration as well
385 * @param decl [output] if not null, will contain the declaration part of the functions
386 */
387 void GenerateSettersGetters(const wxString& scope, const SettersGettersData& data,
388 const std::vector<TagEntryPtr>& tags, wxString& impl, wxString* decl = NULL);
389
390 /**
391 * return tags belongs to given scope and kind
392 * @param scopeName the scope to search
393 * @param kind tags's kind to return
394 * @param tags [output] the result vector
395 * @param inherits set to true if you want inherited members as well members
396 */
397 void TagsByScope(const wxString& scopeName, const wxString& kind, std::vector<TagEntryPtr>& tags,
398 bool includeInherits = false, bool applyLimit = true);
399
400 /**
401 * return tags belongs to given scope and kind
402 * @param scopeName the scope to search
403 * @param kind list of tags kind to return
404 * @param tags [output] the result vector
405 * @param inherits set to true if you want inherited members as well members
406 * @param include_anon included anonymous members (of Unions/structs/enums)
407 */
408 void TagsByScope(const wxString& scopeName, const wxArrayString& kind, std::vector<TagEntryPtr>& tags,
409 bool include_anon = false);
410
411 /**
412 * return tags belongs to given typeref and kind
413 * @param scopeName the typeref to search
414 * @param kind list of tags kind to return
415 * @param tags [output] the result vector
416 * @param inherits set to true if you want inherited members as well members
417 * @param include_anon included anonymous members (of Unions/structs/enums)
418 */
419 void TagsByTyperef(const wxString& scopeName, const wxArrayString& kind, std::vector<TagEntryPtr>& tags,
420 bool include_anon = false);
421
422 /**
423 * @brief return a CppToken poiting to the offset of a local variable
424 * @param fileName file name to search in
425 * @param pos the position pointing to the *start* of the variable to search
426 * @param word the variable name to search
427 * @param modifiedText if the file is modified and not saved, user can pass the unmodified text here to override the
428 * file's content
429 * @return CppToken. Check CppToken::getOffset() != wxString::npos to make sure that this is a valid token
430 */
431 CppToken FindLocalVariable(const wxFileName& fileName, int pos, int lineNumber, const wxString& word,
432 const wxString& modifiedText = wxEmptyString);
433
434 /**
435 * @brief get the scope name. CodeLite assumes that the caret is placed at the end of the 'scope'
436 * @param scope the input string
437 * @return scope name or '<global>' if non found
438 */
439 wxString GetScopeName(const wxString& scope);
440
441 /**
442 * return list of files from the database(s). The returned list is ordered
443 * by name (ascending)
444 * @param partialName part of the file name to act as a filter
445 * @param files [output] array of files
446 */
447 void GetFiles(const wxString& partialName, std::vector<FileEntryPtr>& files);
448 void GetFiles(const wxString& partialName, std::vector<wxFileName>& files);
449 /**
450 * @brief this function is for supporting CC inside an include statement
451 * line
452 */
453 void GetFilesForCC(const wxString& userTyped, wxArrayString& matches);
454
455 /**
456 * Return function that is close to current line number and matches
457 * file name
458 * @param fileName file to search for
459 * @param lineno the line number
460 * @return pointer to the tage which matches the line number & files
461 */
462 TagEntryPtr FunctionFromFileLine(const wxFileName& fileName, int lineno, bool nextFunction = false);
463
464 /**
465 * @brief Return function that is close to current line number
466 * this is done by parsing `buffer`
467 * @param buffer input source file as string
468 * @param lineno the end buffer line number
469 * @param file_name the returned tag `GetFile()` value
470 */
471 TagEntryPtr FunctionFromBufferLine(const wxString& buffer, int lineno, const wxString& file_name);
472
473 /**
474 * @brief return the first function of 'fileName'
475 * @param fileName file to scan
476 * @return NULL or valid tag
477 */
478 TagEntryPtr FirstFunctionOfFile(const wxFileName& fileName);
479
480 /**
481 * @brief return the first scope of 'fileName'
482 * @param fileName file to scan
483 * @return NULL or valid tag
484 */
485 TagEntryPtr FirstScopeOfFile(const wxFileName& fileName);
486
487 /**
488 * @brief return list of scopes from a given file. This function is used by the navigation bar
489 * @param name
490 * @param scopes
491 */
492 void GetScopesFromFile(const wxFileName& fileName, std::vector<wxString>& scopes);
493
494 /**
495 * @brief return the scope's member type, for example:
496 * if yout class MyClass::m_str, and m_str is std::string, then calling this function will result with
497 * type=basic_string
498 * typeScope=std
499 * @param scope scope name
500 * @param name the member name
501 * @param type
502 * @param typeScope
503 * @return true on success, false otherwise
504 */
505 bool GetMemberType(const wxString& scope, const wxString& name, wxString& type, wxString& typeScope);
506
507 /**
508 * @brief return list of tags by file name & scope
509 * @param fileName
510 * @param scopeName
511 * @param tags
512 */
513 void TagsFromFileAndScope(const wxFileName& fileName, const wxString& scopeName, std::vector<TagEntryPtr>& tags);
514
515 /**
516 * @brief return list of tags for the given language
517 * @param tags [output]
518 * @param lang the requested language
519 */
520 void GetKeywordsTagsForLanguage(const wxString& filter, eLanguage lang, std::vector<TagEntryPtr>& tags);
521
522 /**
523 * @brief
524 * @param scope
525 * @param tags
526 */
527 virtual void GetSubscriptOperator(const wxString& scope, std::vector<TagEntryPtr>& tags);
528 /**
529 * @brief
530 * @param scope
531 * @param tags
532 */
533 virtual void GetDereferenceOperator(const wxString& scope, std::vector<TagEntryPtr>& tags);
534
535 /**
536 * @brief return information about the current function based on file & line
537 * @param fileName the current file name
538 * @param lineno the current line number
539 * @param tag [output]
540 * @param func [output]
541 * @return true on success, false otherwise
542 */
543 bool GetFunctionDetails(const wxFileName& fileName, int lineno, TagEntryPtr& tag, clFunction& func);
544
545 /**
546 * @brief return list of all classes.
547 * @param tags [output] vector of tags for the classes
548 * @param onlyWorkspace set to true if you wish to accept only classes belongs to the workspace, false if you would
549 * like to receive
550 * classes from the external database as well
551 */
552 void GetClasses(std::vector<TagEntryPtr>& tags, bool onlyWorkspace = true);
553
554 /**
555 * @brief return list of functions
556 * @param tags
557 * @param fileName
558 */
559 void GetFunctions(std::vector<TagEntryPtr>& tags, const wxString& fileName = wxEmptyString,
560 bool onlyWorkspace = true);
561
562 /**
563 * @brief return list of tags by KIND
564 * @param tags [output]
565 * @param kind the kind of the tags to fetch from the database
566 * @param partName name criterion (partial)
567 */
568 void GetTagsByKind(std::vector<TagEntryPtr>& tags, const wxArrayString& kind,
569 const wxString& partName = wxEmptyString);
570
571 /**
572 * @brief return list of tags by name
573 * @param prefix
574 * @param tags
575 */
576 void GetTagsByName(const wxString& prefix, std::vector<TagEntryPtr>& tags);
577
578 /**
579 * @brief return list of tags by name (or part of it)
580 */
581 void GetTagsByPartialName(const wxString& partialName, std::vector<TagEntryPtr>& tags);
582
583 /**
584 * @brief return list of tags by their partial names
585 */
586 void GetTagsByPartialNames(const wxArrayString& partialNames, std::vector<TagEntryPtr>& tags);
587
588 /**
589 * @brief return list of tags by KIND
590 * @param tags [output]
591 * @param kind the kind of the tags to fetch from the database
592 * @param partName name criterion (partial)
593 */
594 void GetTagsByKindLimit(std::vector<TagEntryPtr>& tags, const wxArrayString& kind, int limit,
595 const wxString& partName = wxEmptyString);
596
597 /**
598 * @brief generate function body/impl based on a tag
599 * @param tag the input tag which represents the requested tag
600 * @param impl set to true if you need an implementation, false otherwise. Default is set to false
601 * @param scope real function scope to use
602 * @return the function impl/decl
603 */
604 wxString FormatFunction(TagEntryPtr tag, size_t flags = FunctionFormat_WithVirtual,
605 const wxString& scope = wxEmptyString);
606
607 /**
608 * @brief return true of the tag contains a pure virtual function
609 * @param tag
610 */
611 bool IsPureVirtual(TagEntryPtr tag);
612
613 /**
614 * @brief return true of the tag contains a virtual function (can be pure)
615 * @param tag
616 */
617 bool IsVirtual(TagEntryPtr tag);
618
619 /**
620 * @brief get whether the tag contains virtual, pure virtual or final function
621 * @param tag
622 * @param isVirtual [output] true if the function is virtual
623 * @param isPureVirtual [output] true if the function is pure virtual
624 * @param isFinal [output] true if the function is not overridable
625 * @return true on success, false otherwise
626 */
627 bool GetVirtualProperty(TagEntryPtr tag, bool& isVirtual, bool& isPureVirtual, bool& isFinal);
628
629 /**
630 * @brief return true if type & scope do exist in the symbols database
631 * @param typeName
632 * @param scope
633 * @return
634 */
635 bool IsTypeAndScopeExists(wxString& typeName, wxString& scope);
636
637 /**
638 * @brief return true if type & scope do exist in the symbols database and is container. This function also modifies
639 * the
640 * typeName & scope to match real typename and scope (according to the TagsStorage)
641 * @param typeName [intput/output]
642 * @param scope [intput/output]
643 * @return
644 */
645 bool IsTypeAndScopeContainer(wxString& typeName, wxString& scope);
646
647 /**
648 * @brief try to process a given expression and evaluate it into type & typescope
649 * @param expression
650 * @param type
651 * @param typeScope
652 * @return true on success false otherwise
653 */
654 bool ProcessExpression(const wxString& expression, wxString& type, wxString& typeScope);
655
656 /**
657 * @brief strip comments from a given text
658 * @param text
659 */
660 void StripComments(const wxString& text, wxString& stippedText);
661
662 /**
663 * @brief return normalize function signature. This function strips any default values or variable
664 * name from the signature. The return value for signature like this: wxT("int value, const std::string &str = "",
665 * void *data = NULL"), is "int, const std::string&, void *"
666 * and by setting the includeVarNames to true, it will also returns the variables names
667 * @param sig signature
668 * @param includeVarNames set to true if the stripped signature should include the variables names. By default it is
669 * set to false
670 * @return stripped functions signature
671 */
672 wxString NormalizeFunctionSig(const wxString& sig, size_t flags = Normalize_Func_Name,
673 std::vector<std::pair<int, int>>* paramLen = NULL);
674
675 /**
676 * @brief return map of un-implemented methods of given scope
677 * @param scopeName scope to search
678 * @param protos map of methods prototypes
679 */
680 void GetUnImplementedFunctions(const wxString& scopeName, std::map<wxString, TagEntryPtr>& protos);
681
682 /**
683 * @brief get list of virtual functions from the parent which were not override by
684 * the derived class (scopeName)
685 * @param scopeName derived class
686 * @param protos [output]
687 */
688 void GetUnOverridedParentVirtualFunctions(const wxString& scopeName, bool onlyPureVirtual,
689 std::vector<TagEntryPtr>& protos);
690
691 /**
692 * @brief update the 'last_retagged' column in the 'files' table for the current timestamp
693 * @param files list of files
694 * @brief db database to use
695 */
696 void UpdateFilesRetagTimestamp(const wxArrayString& files, ITagsStoragePtr db);
697
698 /**
699 * @brief accept as input ctags pattern of a function and tries to evaluate the
700 * return value of the function
701 * @param pattern ctags pattern of the method
702 * @return return value of the method from the pattern of empty string
703 */
704 wxString GetFunctionReturnValueFromPattern(TagEntryPtr tag);
705 /**
706 * @brief fileter a recently tagged files from the strFiles array
707 * @param strFiles
708 * @param db
709 */
710 void FilterNonNeededFilesForRetaging(wxArrayString& strFiles, ITagsStoragePtr db);
711
712 /**
713 * Parse tags from memory and constructs a TagTree.
714 * This function throws a std::exception*.
715 * @param tags wxString containing the tags to parse
716 * @return tag tree, must be freed by caller
717 */
718 static TagTreePtr TreeFromTags(const wxString& tags, int& count);
719 static TagTreePtr TreeFromTags(const wxArrayString& tags, int& count);
720
721 /**
722 * @brief clear the underlying caching mechanism
723 */
724 void ClearTagsCache();
725
726 /**
727 * @brief return true of v1 cotnains the same tags as v2
728 */
729 bool AreTheSame(const TagEntryPtrVector_t& v1, const TagEntryPtrVector_t& v2) const;
730
731 /**
732 * @brief insert functionBody into clsname. This function will search for best location
733 * to place the function body. set visibility to 0 for 'pubilc' function, 1 for 'protected' and 2 for private
734 * return true if this function succeeded, false otherwise
735 */
736 bool InsertFunctionDecl(const wxString& clsname, const wxString& functionDecl, wxString& sourceContent,
737 int visibility = 0);
738
739 /**
740 * @brief insert forward declaration statement at the top of the file
741 * @param classname the class name to add
742 * @param fileContent [input] the file content
743 * @param lineToAdd [output] the line that should be added
744 * @param line [output] line number where to add the forward declaration
745 * @param impExpMacro [optional/input] Windows DLL Imp/Exp macro
746 */
747 void InsertForwardDeclaration(const wxString& classname, const wxString& fileContent, wxString& lineToAdd,
748 int& line, const wxString& impExpMacro = "");
749
750 protected:
751 std::map<wxString, bool> m_typeScopeCache;
752 std::map<wxString, bool> m_typeScopeContainerCache;
753
754 void DoParseModifiedText(const wxString& text, std::vector<TagEntryPtr>& tags);
755
756 private:
757 /**
758 * Construct a TagsManager object, for internal use
759 */
760 TagsManager();
761
762 /**
763 * Destructor
764 */
765 virtual ~TagsManager();
766
767 /**
768 * @param path
769 * @param parentTag
770 * @param derivationList
771 * @param scannedInherits
772 */
773 bool GetDerivationList(const wxString& path, TagEntryPtr parentTag,
774 std::vector<std::pair<wxString, int>>& derivationList, std::unordered_set<wxString>& visited,
775 int depth);
776
777 bool GetDerivationListInternal(const wxString& path, TagEntryPtr parentTag,
778 std::vector<std::pair<wxString, int>>& derivationList,
779 std::unordered_set<wxString>& visited, int depth);
780
781 public:
782 /**
783 * @brief return true if the file is binary (by searching for NULL chars)
784 * @param filepath file to examine
785 * @return return true if the file is binary
786 */
787 bool IsBinaryFile(const wxString& filepath, const TagsOptionsData& tod);
788
789 /**
790 * @brief given an input string 'str', wrap the string so each line will
791 * not be longer than MAX_TIP_LINE_SIZE bytes
792 */
793 wxString WrapLines(const wxString& str);
794
795 void GetFunctionTipFromTags(const std::vector<TagEntryPtr>& tags, const wxString& word,
796 std::vector<TagEntryPtr>& tips);
797
798 /**
799 * @brief create doxygen comment from a tag
800 * @param tag
801 * @param keyPrefix should we use @ or \\ to prefix doxy keywords?
802 */
803 DoxygenComment DoCreateDoxygenComment(TagEntryPtr tag, wxChar keyPrefix);
804
805 protected:
806 void DoTagsFromText(const wxString& text, std::vector<TagEntryPtr>& tags);
807 void DoFindByNameAndScope(const wxString& name, const wxString& scope, std::vector<TagEntryPtr>& tags);
808 void DoFilterDuplicatesByTagID(std::vector<TagEntryPtr>& src, std::vector<TagEntryPtr>& target);
809 void DoFilterDuplicatesBySignature(std::vector<TagEntryPtr>& src, std::vector<TagEntryPtr>& target);
810 void DoFilterCtorDtorIfNeeded(std::vector<TagEntryPtr>& tags, const wxString& oper);
811 void RemoveDuplicatesTips(std::vector<TagEntryPtr>& src, std::vector<TagEntryPtr>& target);
812 void GetGlobalTags(const wxString& name, std::vector<TagEntryPtr>& tags, size_t flags = PartialMatch);
813 void GetLocalTags(const wxString& name, const wxString& scope, std::vector<TagEntryPtr>& tags, bool isFuncSignature,
814 size_t flags = PartialMatch);
815 void TipsFromTags(const std::vector<TagEntryPtr>& tags, const wxString& word, std::vector<wxString>& tips);
816 bool ProcessExpression(const wxFileName& filename, int lineno, const wxString& expr, const wxString& scopeText,
817 wxString& typeName, wxString& typeScope, wxString& oper, wxString& scopeTempalteInitiList);
818 void FilterImplementation(const std::vector<TagEntryPtr>& src, std::vector<TagEntryPtr>& tags);
819 void FilterDeclarations(const std::vector<TagEntryPtr>& src, std::vector<TagEntryPtr>& tags);
820 wxString DoReplaceMacros(const wxString& name);
821 void DoFilterNonNeededFilesForRetaging(wxArrayString& strFiles, ITagsStoragePtr db);
822 void DoGetFunctionTipForEmptyExpression(const wxString& word, const wxString& text, std::vector<TagEntryPtr>& tips,
823 bool globalScopeOnly = false);
824 void TryFindImplDeclUsingNS(const wxString& scope, const wxString& word, bool imp,
825 const std::vector<wxString>& visibleScopes, std::vector<TagEntryPtr>& tags);
826 void TryReducingScopes(const wxString& scope, const wxString& word, bool imp, std::vector<TagEntryPtr>& tags);
827 wxArrayString BreakToOuterScopes(const wxString& scope);
828 wxString DoReplaceMacrosFromDatabase(const wxString& name);
829 void DoSortByVisibility(TagEntryPtrVector_t& tags);
830 void GetScopesByScopeName(const wxString& scopeName, wxArrayString& scopes);
831 };
832
833 /// create the singleton typedef
834 class WXDLLIMPEXP_CL TagsManagerST
835 {
836 public:
837 static TagsManager* Get();
838 static void Free();
839 };
840
841 #endif // CODELITE_CTAGS_MANAGER_H