Code::Blocks  SVN r11506
nativeparser.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 NATIVEPARSER_H
7 #define NATIVEPARSER_H
8 
9 #include "nativeparser_base.h"
10 #include "parser/parser.h"
11 
12 #include <queue>
13 #include <map>
14 
15 #include <wx/event.h>
16 
18 extern bool s_DebugSmartSense;
19 
20 extern const int g_EditorActivatedDelay;
21 
22 // forward declaration
23 class cbEditor;
24 class EditorBase;
25 class cbProject;
26 class cbStyledTextCtrl;
27 class ClassBrowser;
28 class Compiler;
29 class Token;
30 
31 
32 typedef std::map<cbProject*, wxArrayString> ProjectSearchDirsMap;
33 
34 // TODO (ollydbg#1#), this class is dirty, I'm going to change its name like CursorLocation
37 {
40 };
41 
44 {
45  bvmRaw = 0,
47 };
48 
56 {
57 public:
59  NativeParser();
60 
62  ~NativeParser();
63 
65  ParserBase& GetParser() { return *m_Parser; }
66 
71  ParserBase* GetParserByProject(cbProject* project);
72 
78  ParserBase* GetParserByFilename(const wxString& filename);
79 
84  cbProject* GetProjectByParser(ParserBase* parser);
85 
93  cbProject* GetProjectByFilename(const wxString& filename);
94 
99  cbProject* GetProjectByEditor(cbEditor* editor);
100 
102  cbProject* GetCurrentProject();
103 
105  bool IsParserPerWorkspace() const { return m_ParserPerWorkspace; }
106 
108  bool Done();
109 
113  wxImageList* GetImageList() { return m_ImageList; }
114 
116  int GetTokenKindImage(const Token* token);
117 
124  wxArrayString GetAllPathsByFilename(const wxString& filename);
125 
132 static void AddPaths(wxArrayString& dirs, const wxString& path, bool hasExt);
133 
134  // the functions below are handling and managing Parser object
135 
142  ParserBase* CreateParser(cbProject* project);
143 
148  bool DeleteParser(cbProject* project);
149 
165  bool ReparseFile(cbProject* project, const wxString& filename);
166 
171  bool AddFileToParser(cbProject* project, const wxString& filename, ParserBase* parser = nullptr);
172 
177  bool RemoveFileFromParser(cbProject* project, const wxString& filename);
178 
180  void RereadParserOptions();
181 
183  void ReparseCurrentProject();
184 
186  void ReparseSelectedProject();
187 
199  size_t MarkItemsByAI(ccSearchData* searchData, TokenIdxSet& result, bool reallyUseAI = true,
200  bool isPrefix = true, bool caseSensitive = false, int caretPos = -1);
201 
205  size_t MarkItemsByAI(TokenIdxSet& result, bool reallyUseAI = true, bool isPrefix = true,
206  bool caseSensitive = false, int caretPos = -1);
207 
228  int GetCallTips(wxArrayString& items, int& typedCommas, cbEditor* ed, int pos = wxNOT_FOUND);
229 
231  wxArrayString& GetProjectSearchDirs(cbProject* project);
232 
233  // The function below is used to manage symbols browser
235  ClassBrowser* GetClassBrowser() const { return m_ClassBrowser; }
236 
238  void CreateClassBrowser();
239 
241  void RemoveClassBrowser(bool appShutDown = false);
242 
244  void UpdateClassBrowser();
245 
246 protected:
251  bool DoFullParsing(cbProject* project, ParserBase* parser);
252 
254  bool SwitchParser(cbProject* project, ParserBase* parser);
255 
262  void SetParser(ParserBase* parser);
263 
265  void ClearParsers();
266 
271  void RemoveObsoleteParsers();
272 
274  std::pair<cbProject*, ParserBase*> GetParserInfoByCurrentEditor();
275 
279  void SetTokenKindImage(int kind, const wxBitmap& bitmap, const wxBitmap& mask = wxNullBitmap);
280  void SetTokenKindImage(int kind, const wxBitmap& bitmap, const wxColour& maskColour);
281  void SetTokenKindImage(int kind, const wxIcon& icon);
282 
284  void SetCBViewMode(const BrowserViewMode& mode);
285 
286 private:
287  friend class CodeCompletion;
288 
295  void OnProjectLoadingHook(cbProject* project, TiXmlElement* elem, bool loading);
296 
308  size_t AI(TokenIdxSet& result,
309  ccSearchData* searchData,
310  const wxString& lineText = wxEmptyString,
311  bool isPrefix = false,
312  bool caseSensitive = false,
313  TokenIdxSet* search_scope = 0,
314  int caretPos = -1);
315 
322  size_t FindCurrentFunctionToken(ccSearchData* searchData, TokenIdxSet& result, int caretPos = -1);
323 
333  int FindCurrentFunctionStart(ccSearchData* searchData,
334  wxString* nameSpace = 0L,
335  wxString* procName = 0L,
336  int* functionIndex = 0L,
337  int caretPos = -1);
338 
340  bool LastAISearchWasGlobal() const { return m_LastAISearchWasGlobal; }
341 
343  const wxString& LastAIGlobalSearch() const { return m_LastAIGlobalSearch; }
344 
350  bool ParseUsingNamespace(ccSearchData* searchData, TokenIdxSet& search_scope, int caretPos = -1);
351 
357  bool ParseBufferForUsingNamespace(const wxString& buffer, TokenIdxSet& search_scope, bool bufferSkipBlocks = true);
358 
363  bool ParseFunctionArguments(ccSearchData* searchData, int caretPos = -1);
364 
370  bool ParseLocalBlock(ccSearchData* searchData, TokenIdxSet& search_scope, int caretPos = -1);
371 
378  bool AddCompilerDirs(cbProject* project, ParserBase* parser);
379 
384  bool AddCompilerPredefinedMacros(cbProject* project, ParserBase* parser);
385 
387  bool AddCompilerPredefinedMacrosGCC(const wxString& compilerId, cbProject* project, wxString& defs, ParserBase* parser);
388 
390  wxString GetCompilerStandardGCC(Compiler* compiler, cbProject* project);
391 
393  wxString GetCompilerUsingStandardGCC(const wxArrayString& compilerOptions);
394 
396  bool AddCompilerPredefinedMacrosVC(const wxString& compilerId, wxString& defs, ParserBase* parser);
397 
402  bool AddProjectDefinedMacros(cbProject* project, ParserBase* parser);
403 
405  void AddCompilerIncludeDirsToParser(const Compiler* compiler, ParserBase* parser);
406 
408  const wxArrayString& GetGCCCompilerDirs(const wxString &cpp_compiler);
409 
411  void AddGCCCompilerDirs(const wxString& masterPath, const wxString& compilerCpp, ParserBase* parser);
412 
416  void AddIncludeDirsToParser(const wxArrayString& dirs, const wxString& base, ParserBase* parser);
417 
419  void OnParserStart(wxCommandEvent& event);
420 
424  void OnParserEnd(wxCommandEvent& event);
425 
434  void OnParsingOneByOneTimer(wxTimerEvent& event);
435 
437  void OnEditorActivated(EditorBase* editor);
438 
442  void OnEditorClosed(EditorBase* editor);
443 
445  void InitCCSearchVariables();
446 
450  bool AddProjectToParser(cbProject* project);
451 
455  bool RemoveProjectFromParser(cbProject* project);
456 
457 private:
458  typedef std::pair<cbProject*, ParserBase*> ProjectParserPair;
459  typedef std::list<ProjectParserPair> ParserList;
460 
465  ParserList m_ParserList;
470 
477 
482  int m_HookId;
484 
492  std::set<cbProject*> m_ParsedProjects;
493 
494  /* CC Search Member Variables => START */
505  /* CC Search Member Variables => END */
506 };
507 
508 #endif // NATIVEPARSER_H
509 
Search location combination, a pointer to cbStyledTextCtrl and a filename is enough.
Definition: nativeparser.h:36
void OnEditorActivated(CodeBlocksEvent &event)
BrowserViewMode
Symbol browser tree showing option.
Definition: nativeparser.h:43
int m_LastFunctionIndex
Definition: nativeparser.h:499
ClassBrowser * GetClassBrowser() const
return active class browser pointer
Definition: nativeparser.h:235
bool m_ClassBrowserIsFloating
if true, which means m_ClassBrowser is floating (not docked)
Definition: nativeparser.h:476
ProjectSearchDirsMap m_ProjectSearchDirsMap
a map: project pointer -> C/C++ parser search paths for this project, this is the per-project code co...
Definition: nativeparser.h:481
wxString file
Definition: nativeparser.h:39
ClassBrowser * m_ClassBrowser
symbol browser window
Definition: nativeparser.h:474
cbStyledTextCtrl * control
Definition: nativeparser.h:38
wxString m_LastAIGlobalSearch
same case like above, it holds the search string
Definition: nativeparser.h:495
int m_LastFuncTokenIdx
saved the function token&#39;s index, for remove all local variable
Definition: nativeparser.h:500
#define wxNOT_FOUND
Code completion plugin has those features: show tool-tip when the mouse hover over the variables/func...
bool m_LastAISearchWasGlobal
true if the phrase for code-completion is empty or partial text (i.e. no . -> or :: operators) ...
Definition: nativeparser.h:496
Represents a Code::Blocks project.
Definition: cbproject.h:96
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
wxString m_LastNamespace
Definition: nativeparser.h:502
std::set< int, std::less< int > > TokenIdxSet
Definition: token.h:16
wxArrayString m_StandaloneFiles
all the files which opened, but does not belong to any cbp
Definition: nativeparser.h:486
bool m_ParserPerWorkspace
if true, which means the parser hold tokens of the whole workspace&#39;s project, if false then one parse...
Definition: nativeparser.h:490
wxImageList * m_ImageList
Images for class browser.
Definition: nativeparser.h:483
Base class that all "editors" should inherit from.
Definition: editorbase.h:30
std::list< ProjectParserPair > ParserList
Definition: nativeparser.h:459
wxTimer m_TimerParsingOneByOne
a delay timer to parser every project in sequence
Definition: nativeparser.h:472
symbol browser panel is shown in the Management panel besides projects browser panel.
Definition: classbrowser.h:53
const wxString & LastAIGlobalSearch() const
The same as above.
Definition: nativeparser.h:343
std::pair< cbProject *, ParserBase * > ProjectParserPair
Definition: nativeparser.h:458
cbStyledTextCtrl * m_LastControl
Definition: nativeparser.h:497
NativeParser class is just like a manager class to control Parser objects.
Definition: nativeparser.h:55
std::map< cbProject *, wxArrayString > ProjectSearchDirsMap
Definition: nativeparser.h:29
ParserBase & GetParser()
return a reference to the currently active Parser object
Definition: nativeparser.h:65
Abstract base class for compilers.
Definition: compiler.h:274
A file editor.
Definition: cbeditor.h:43
std::set< cbProject * > m_ParsedProjects
only used when m_ParserPerWorkspace is true, and holds all the cbps for the common parser ...
Definition: nativeparser.h:492
void OnEditorClosed(CodeBlocksEvent &event)
ParserBase * m_TempParser
a temp parser object pointer
Definition: nativeparser.h:467
wxString m_LastPROC
Definition: nativeparser.h:503
wxString m_LastFile
Definition: nativeparser.h:498
wxBitmap wxNullBitmap
ParserBase * m_Parser
active parser object pointer
Definition: nativeparser.h:469
bool LastAISearchWasGlobal() const
used in CodeCompletion suggestion list to boost the performance, we use a caches
Definition: nativeparser.h:340
const int g_EditorActivatedDelay
void OnParserStart(wxCommandEvent &event)
batch parsing start event this event usually be fired when an Parser object try to start parsing task...
void OnParserEnd(wxCommandEvent &event)
batch parsing end event this event usually be fired when the task pool becomes empty ...
int m_HookId
project loader hook ID
Definition: nativeparser.h:482
ParserList m_ParserList
a list holing all the cbp->parser pairs, if in one parser per project mode, there are many many pairs...
Definition: nativeparser.h:465
bool s_DebugSmartSense
debug only variable, used to print the AI match related log message
bool IsParserPerWorkspace() const
Return true if use one Parser per whole workspace.
Definition: nativeparser.h:105
wxImageList * GetImageList()
Used to support Symbol browser and codecompletion UI Image list is used to initialize the symbol brow...
Definition: nativeparser.h:113