Code::Blocks  SVN r11506
parser.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 PARSER_H
7 #define PARSER_H
8 
9 #include <wx/arrstr.h>
10 #include <wx/event.h>
11 #include <wx/file.h>
12 #include <wx/filefn.h> // wxPathList
13 #include <wx/imaglist.h>
14 #include <wx/string.h>
15 #include <wx/thread.h>
16 #include <wx/timer.h>
17 #include <wx/treectrl.h>
18 
19 #include <cbthreadpool.h>
20 #include <sdk_events.h>
21 
22 #include "parserthread.h"
23 #include "parser_base.h"
24 
25 #define PARSER_IMG_NONE -2
26 #define PARSER_IMG_CLASS_FOLDER 0
27 #define PARSER_IMG_CLASS 1
28 #define PARSER_IMG_CLASS_PRIVATE 2
29 #define PARSER_IMG_CLASS_PROTECTED 3
30 #define PARSER_IMG_CLASS_PUBLIC 4
31 #define PARSER_IMG_CTOR_PRIVATE 5
32 #define PARSER_IMG_CTOR_PROTECTED 6
33 #define PARSER_IMG_CTOR_PUBLIC 7
34 #define PARSER_IMG_DTOR_PRIVATE 8
35 #define PARSER_IMG_DTOR_PROTECTED 9
36 #define PARSER_IMG_DTOR_PUBLIC 10
37 #define PARSER_IMG_FUNC_PRIVATE 11
38 #define PARSER_IMG_FUNC_PROTECTED 12
39 #define PARSER_IMG_FUNC_PUBLIC 13
40 #define PARSER_IMG_VAR_PRIVATE 14
41 #define PARSER_IMG_VAR_PROTECTED 15
42 #define PARSER_IMG_VAR_PUBLIC 16
43 #define PARSER_IMG_MACRO_DEF 17
44 #define PARSER_IMG_ENUM 18
45 #define PARSER_IMG_ENUM_PRIVATE 19
46 #define PARSER_IMG_ENUM_PROTECTED 20
47 #define PARSER_IMG_ENUM_PUBLIC 21
48 #define PARSER_IMG_ENUMERATOR 22
49 #define PARSER_IMG_NAMESPACE 23
50 #define PARSER_IMG_TYPEDEF 24
51 #define PARSER_IMG_TYPEDEF_PRIVATE 25
52 #define PARSER_IMG_TYPEDEF_PROTECTED 26
53 #define PARSER_IMG_TYPEDEF_PUBLIC 27
54 #define PARSER_IMG_SYMBOLS_FOLDER 28
55 #define PARSER_IMG_VARS_FOLDER 29
56 #define PARSER_IMG_FUNCS_FOLDER 30
57 #define PARSER_IMG_ENUMS_FOLDER 31
58 #define PARSER_IMG_MACRO_DEF_FOLDER 32
59 #define PARSER_IMG_OTHERS_FOLDER 33
60 #define PARSER_IMG_TYPEDEF_FOLDER 34
61 #define PARSER_IMG_MACRO_USE 35
62 #define PARSER_IMG_MACRO_USE_PRIVATE 36
63 #define PARSER_IMG_MACRO_USE_PROTECTED 37
64 #define PARSER_IMG_MACRO_USE_PUBLIC 38
65 #define PARSER_IMG_MACRO_USE_FOLDER 39
66 
67 #define PARSER_IMG_MIN PARSER_IMG_CLASS_FOLDER
68 #define PARSER_IMG_MAX PARSER_IMG_MACRO_USE_FOLDER
69 
72 {
73 public:
74  ClassTreeData(Token* token) { m_Token = token; }
75  Token* GetToken() { return m_Token; }
76  void SetToken(Token* token) { m_Token = token; }
77 private:
79 };
80 
81 class ClassBrowser;
82 
83 namespace ParserCommon
84 {
85  extern int idParserStart;
86  extern int idParserEnd;
87 
89  {
94 
97 
100 
105  };
106 }
107 
117 class Parser : public ParserBase
118 {
119  friend class ParserThreadedTask;
120 
121 public:
126  Parser(wxEvtHandler* parent, cbProject* project);
128  virtual ~Parser();
129 
133  virtual void AddBatchParse(const StringList& filenames);
134 
140  virtual void AddParse(const wxString& filename);
141 
145  virtual void AddPredefinedMacros(const wxString& defs);
146 
148  virtual void ClearPredefinedMacros();
149 
151  virtual const wxString GetPredefinedMacros() const;
152 
156  virtual bool UpdateParsingProject(cbProject* project);
157 
162  virtual bool ParseBuffer(const wxString& buffer, bool isLocal, bool bufferSkipBlocks = false,
163  bool isTemp = false, const wxString& filename = wxEmptyString,
164  int parentIdx = -1, int initLine = 0);
165 
169  virtual bool ParseBufferForFunctions(const wxString& buffer);
170 
172  virtual bool ParseBufferForNamespaces(const wxString& buffer, NameSpaceVec& result);
173 
175  virtual bool ParseBufferForUsingNamespace(const wxString& buffer, wxArrayString& result, bool bufferSkipBlocks = true);
176 
181  virtual bool Reparse(const wxString& filename, bool isLocal = true);
182 
186  virtual bool AddFile(const wxString& filename, cbProject* project, bool isLocal = true);
187 
191  virtual bool RemoveFile(const wxString& filename);
192 
197  virtual bool IsFileParsed(const wxString& filename);
198 
200  virtual bool Done();
201 
203  virtual wxString NotDoneReason();
204 
205 protected:
206  // used for measuring the batch parsing time
207  void StartStopWatch();
208  // used for measuring the batch parsing time
209  void EndStopWatch();
210 
214  unsigned int GetMaxThreads() const { return m_Pool.GetConcurrentThreads(); }
215 
217  void SetMaxThreads(unsigned int max) { m_Pool.SetConcurrentThreads(max); }
218 
223  bool Parse(const wxString& filename, bool isLocal = true, bool locked = false);
224 
226  void ReparseModifiedFiles();
227 
229  void TerminateAllThreads();
230 
236  void OnAllThreadsDone(CodeBlocksEvent& event);
237 
243  void OnReparseTimer(wxTimerEvent& event);
244 
249  void OnBatchTimer(wxTimerEvent& event);
250 
258  void ProcessParserEvent(ParserCommon::ParserState state, int id, const wxString& info = wxEmptyString);
259 
261  virtual void ReadOptions();
263  virtual void WriteOptions();
264 
265 private:
276  virtual bool ParseFile(const wxString& filename, bool isGlobal, bool locked = false);
277 
279  void ConnectEvents();
280 
282  void DisconnectEvents();
283 
286 
289 
290 protected:
293 
299 
305 
306 
311 
316 
317 private:
318 
324 
329 
334 
342 
345 
349 
352 
355 
358 
360  typedef std::list<cbThreadedTask*> TasksQueue;
361  TasksQueue m_tasksQueue;
362 
364  void AddParserThread(cbThreadedTask* task);
365 
367  void RemoveParserThread(cbThreadedTask* task);
368 
370  void AbortParserThreads();
371 };
372 
373 #endif // PARSER_H
bool m_IsBatchParseDone
used to measure batch parse time
Definition: parser.h:351
bool m_UsingCache
used to detect changes between in-memory data and cache, true if loaded from cache ...
Definition: parser.h:292
bool m_IgnoreThreadEvents
Parser::OnAllThreadsDone will be called when m_Pool finished its job, but when we run a batch parsing...
Definition: parser.h:341
wxStopWatch m_StopWatch
a stop watch to measure parsing time
Definition: parser.h:331
A Thread Pool implementation.
Definition: cbthreadpool.h:19
bool m_NeedMarkFileAsLocal
if true, all the files of the current project will be labeled as "local"
Definition: parser.h:357
bool m_NeedsReparse
Indicates some files in the current project need to be re-parsed, this is commonly caused that the "r...
Definition: parser.h:310
std::list< wxString > StringList
Definition: parser_base.h:20
int idParserStart
Definition: parser.cpp:93
wxString m_LastPredefinedMacros
Definition: parser.h:348
A generic Code::Blocks event.
Definition: sdk_events.h:20
StringList m_BatchParseFiles
All other batch parse files, like the normal headers/sources.
Definition: parser.h:344
void SetMaxThreads(unsigned int max)
Not used, because the ThreadPool only support running ONE ParserThread concurrently.
Definition: parser.h:217
std::vector< NameSpace > NameSpaceVec
Definition: parserthread.h:34
Tree data associate with the symbol tree item.
Definition: parser.h:71
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
ClassTreeData(Token *token)
Definition: parser.h:74
std::list< cbThreadedTask * > TasksQueue
A list to contain pointers to internal running threads.
Definition: parser.h:360
cbProject * m_Project
referring to the C::B cbp project currently parsing in one parser per workspace mode ...
Definition: parser.h:288
bool m_StopWatchRunning
Definition: parser.h:332
unsigned int GetMaxThreads() const
Node: Currently, the max.
Definition: parser.h:214
wxEvtHandler * m_Parent
when initialized, this variable will be an instance of a NativeParser
Definition: parser.h:285
wxString wxEmptyString
bool m_IsParsing
true, if the parser is still busy with parsing, false if the parsing stage has finished this value is...
Definition: parser.h:304
ParserCommon::ParserState m_ParserState
indicated the current state the parser
Definition: parser.h:354
symbol browser panel is shown in the Management panel besides projects browser panel.
Definition: classbrowser.h:53
Token * GetToken()
Definition: parser.h:75
TasksQueue m_tasksQueue
Definition: parser.h:361
void SetToken(Token *token)
Definition: parser.h:76
long m_LastStopWatchTime
Definition: parser.h:333
bool m_IsFirstBatch
batch Parse mode flag.
Definition: parser.h:315
cbThreadPool m_Pool
Thread Pool, executing all the ParserThread, used in batch parse mode.
Definition: parser.h:298
This is what you have to use instead of wxThread to add tasks to the Thread Pool. ...
non of the above three status, this means our Parser has finish all the jobs, and it is in idle mode ...
Definition: parser.h:104
some files are changed by the user, so we are parsing the changed files
Definition: parser.h:96
a cbThreadedTask can be executed in cbThreadPool to do a lot of parsing jobs in the begining stage of...
wxString m_PredefinedMacros
Pre-defined macros, its a buffer queried from the compiler command line.
Definition: parser.h:347
bool RemoveFile(const wxString &src)
Definition: sc_io.cpp:134
int idParserEnd
Definition: parser.cpp:94
the Parser object is newly created, and we are parsing the predefined macro buffer, the source files, and finally mark the project&#39;s tokens as local
Definition: parser.h:93
the user has add some files to the cbproject, so we are parsing the new added files ...
Definition: parser.h:99
wxTimer m_BatchTimer
a timer to delay the operation of batch parsing, see OnBatchTimer() member function as a reference ...
Definition: parser.h:328
wxTimer m_ReparseTimer
a file is need to be reparsed, maybe another file will to be reparsed very soon, so use a timer to co...
Definition: parser.h:323
Token * m_Token
Definition: parser.h:78
Parser class holds all the tokens of a C::B project.
Definition: parser.h:117