Code::Blocks  SVN r11506
parserthread.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 PARSERTHREAD_H
7 #define PARSERTHREAD_H
8 
9 #include <wx/dynarray.h>
10 #include <wx/event.h>
11 #include <wx/string.h>
12 #include <wx/thread.h>
13 
14 #include <queue>
15 #include <vector>
16 
17 #include <cbthreadpool.h>
18 #include <filemanager.h>
19 #include <logmanager.h> // F()
20 
21 #include "cclogger.h"
22 #include "tokenizer.h"
23 #include "token.h"
24 #include "tokentree.h"
25 
26 
27 struct NameSpace
28 {
29  wxString Name; // namespace's name
30  int StartLine; // namespace start line (the line contains openbrace)
31  int EndLine; // namespace end line (the line contains closebrace)
32 };
33 
34 typedef std::vector<NameSpace> NameSpaceVec;
35 
36 class ParserBase;
37 
39 {
41 
42  useBuffer(false),
43  fileOfBuffer(),
44  parentIdxOfBuffer(-1),
45  initLineOfBuffer(1),
46  bufferSkipBlocks(false),
47  bufferSkipOuterBlocks(false),
48  isTemp(false),
49 
50  followLocalIncludes(true),
51  followGlobalIncludes(true),
52  wantPreprocessor(true),
53  parseComplexMacros(true),
54  platformCheck(true),
55 
56  handleFunctions(true),
57  handleVars(true),
58  handleClasses(true),
59  handleEnums(true),
60  handleTypedefs(true),
61 
62  storeDocumentation(false),
63 
64  loader(nullptr)
65  {}
66 
71  bool useBuffer;
72 
77 
80 
85 
88 
90  bool bufferSkipOuterBlocks; // classes, namespaces and functions
91 
93  bool isTemp;
94 
97 
100 
103 
106 
109 
112 
115 
118 
121 
124 
127 
128  LoaderBase* loader; // if not NULL, load through filemanager (using threads)
129 };
130 
139 {
140 public:
148  ParserThread(ParserBase* parent,
149  const wxString& bufferOrFilename,
150  bool isLocal,
151  ParserThreadOptions& parserThreadOptions,
152  TokenTree* tokenTree);
153 
155  virtual ~ParserThread();
156 
159  bool Parse();
160 
167  bool ParseBufferForNamespaces(const wxString& buffer, NameSpaceVec& result);
168 
175  bool ParseBufferForUsingNamespace(const wxString& buffer, wxArrayString& result);
176 
177  wxString GetFilename() { return m_Buffer; } // used in TRACE for debug only
178 
179 protected:
181  enum EClassType { ctStructure = 0, ctClass = 1, ctUnion = 3 };
182 
188  int Execute()
189  {
191 
192  bool success = Parse();
193 
195 
196  return success ? 0 : 1;
197  }
198 
205  wxChar SkipToOneOfChars(const wxString& chars, bool supportNesting = false, bool singleCharToken = true);
206 
208  void DoParse();
209 
211  void SkipBlock();
212 
214  void SkipAngleBraces();
215 
219  void HandleIncludes();
220 
224  void HandleNamespace();
225 
229  void HandleClass(EClassType ct);
230 
236  void HandleFunction(wxString& name, bool isOperator = false, bool isPointer = false);
237 
241  void HandleForLoopArguments();
242 
246  void HandleConditionalArguments();
247 
249  void HandleEnum();
250 
252  bool CalcEnumExpression(Token* tokenParent, long& result, wxString& peek);
253 
255  void HandleTypedef();
256 
261  bool ReadVarNames();
262 
274  bool ReadClsNames(wxString& ancestor);
275 
277  wxString ReadAngleBrackets();
278 
289  Token* DoAddToken(TokenKind kind,
290  const wxString& name,
291  int line,
292  int implLineStart = 0,
293  int implLineEnd = 0,
294  const wxString& args = wxEmptyString,
295  bool isOperator = false,
296  bool isImpl = false);
297 
302  wxString GetTokenBaseType();
303 
304 private:
306  bool InitTokenizer();
307 
313  Token* TokenExists(const wxString& name, const Token* parent = 0, short int kindMask = 0xFFFF);
314 
316  Token* TokenExists(const wxString& name, const wxString& baseArgs, const Token* parent, TokenKind kind);
317 
320  Token* FindTokenFromQueue(std::queue<wxString>& q,
321  Token* parent = 0,
322  bool createIfNotExist = false,
323  Token* parentIfCreated = 0);
324 
332  bool GetBaseArgs(const wxString & args, wxString& baseArgs);
333 
335  void GetTemplateArgs();
336 
346  void ResolveTemplateArgs(Token* newToken);
347 
351  wxArrayString GetTemplateArgArray(const wxString& templateArgs, bool remove_gt_lt, bool add_last);
352 
354  void SplitTemplateFormalParameters(const wxString& templateArgs, wxArrayString& formals);
355 
357  void SplitTemplateActualParameters(const wxString& templateArgs, wxArrayString& actuals);
358 
360  bool ResolveTemplateMap(const wxString& typeStr, const wxArrayString& actuals,
361  std::map<wxString, wxString>& results);
362 
369  void RemoveTemplateArgs(const wxString& expr, wxString &expNoArgs, wxString &templateArgs);
370 
372  bool IsStillAlive(const wxString& funcInfo);
373 
387  void RefineAnonymousTypeToken(short int typeMask, wxString alise);
388 
393 
398 
401 
406 
411 
414 
416  unsigned int m_FileSize;
417 
419  unsigned int m_FileIdx;
420 
424  bool m_IsLocal;
425 
433 
436 
439 
444  std::queue<wxString> m_EncounteredNamespaces;
445 
451  std::queue<wxString> m_EncounteredTypeNamespaces;
452 
457 
460 
463 
468 
471 
474 
476 
478 };
479 
480 #endif // PARSERTHREAD_H
wxString m_LastUnnamedTokenName
TODO: describe me here.
Definition: parserthread.h:459
LoaderBase * loader
Definition: parserthread.h:128
size_t m_EnumUnnamedCount
Definition: parserthread.h:477
wxMutex s_TokenTreeMutex
Definition: tokentree.cpp:49
wxString fileOfBuffer
which file the buffer belongs to, this usually happens when we parse a piece of the cbEditor and the ...
Definition: parserthread.h:76
std::queue< wxString > m_EncounteredNamespaces
for member funcs implementation or a function declaration below eg: int ClassA::FunctionB(); Encounte...
Definition: parserthread.h:444
A parser threaded task, which can be assigned to the thread task pool, and run there.
Definition: parserthread.h:138
bool followLocalIncludes
parse the file in #include "file" directive
Definition: parserthread.h:96
int StartLine
Definition: parserthread.h:30
wxString m_PointerOrRef
a pointer indicator or a references
Definition: parserthread.h:470
bool platformCheck
not used
Definition: parserthread.h:108
bool isTemp
this value is passed to the generated Token&#39;s m_IsTemp property
Definition: parserthread.h:93
TokenScope m_LastScope
this member define the scope type of member variables, which is: public, private protected or undefin...
Definition: parserthread.h:410
TokenIdxSet m_UsedNamespacesIds
globally included namespaces by "using namespace" statement
Definition: parserthread.h:456
bool bufferSkipOuterBlocks
not used
Definition: parserthread.h:90
unsigned int m_FileIdx
source file index on the "file map tree"
Definition: parserthread.h:419
a container class to hold all the Tokens getting from parsing stage
Definition: tokentree.h:37
int parentIdxOfBuffer
when parsing a function body, all the tokens are the children of the function token ...
Definition: parserthread.h:79
This is just a simple lexer class.
Definition: tokenizer.h:64
bool m_IsLocal
if true, means we are parsing a file which belongs to a C::B project, otherwise, we are parsing a fil...
Definition: parserthread.h:424
wxString m_Filename
the file name of the parsing source
Definition: parserthread.h:413
TokenTree * m_TokenTree
a pointer to the token tree, all the tokens will be added to that tree structure
Definition: parserthread.h:400
unsigned int m_FileSize
file size, actually the length of the wxString
Definition: parserthread.h:416
bool handleEnums
whether to parse "enum ..." like statement
Definition: parserthread.h:120
wxUSE_UNICODE_dependent wxChar
bool handleClasses
whether to parse "class ...." like statement
Definition: parserthread.h:117
ParserBase * m_Parent
a pointer to its parent Parser object, the Parserthread class has two place to communicate with Parse...
Definition: parserthread.h:397
wxString m_TemplateArgument
holds current template argument(s) when a template occurs
Definition: parserthread.h:473
std::vector< NameSpace > NameSpaceVec
Definition: parserthread.h:34
wxString GetFilename()
Definition: parserthread.h:177
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
null_pointer_t nullptr
Definition: nullptr.cpp:16
std::set< int, std::less< int > > TokenIdxSet
Definition: token.h:16
bool m_ParsingTypedef
this makes a difference in unnamed class/struct/enum handling
Definition: parserthread.h:462
EClassType
specify which "class like type" we are handling: struct or class or union
Definition: parserthread.h:181
bool handleFunctions
whether to parse the functions
Definition: parserthread.h:111
bool handleVars
whether to parse the variable definition
Definition: parserthread.h:114
wxString m_LastToken
hold the previous token string
Definition: parserthread.h:435
Tokenizer m_Tokenizer
if we regard the parserThread class as a syntax analyzer, then the Tokenizer class is regard as the l...
Definition: parserthread.h:392
bool wantPreprocessor
handle the #if like preprocessor directives, this value is passed to Tokenizer
Definition: parserthread.h:102
#define CC_LOCKER_TRACK_TT_MTX_UNLOCK(M)
Definition: cclogger.h:165
wxString wxEmptyString
TokenScope
Definition: token.h:21
bool parseComplexMacros
not used
Definition: parserthread.h:105
bool storeDocumentation
should tokenizer detect and store doxygen documentation?
Definition: parserthread.h:126
std::queue< wxString > m_EncounteredTypeNamespaces
namespaces in function return types for a function declaration below: e.g.
Definition: parserthread.h:451
wxString m_Str
This is a very important member variables! It serves as a type stack, eg: parsing the statement: "uns...
Definition: parserthread.h:432
#define CC_LOCKER_TRACK_TT_MTX_LOCK(M)
Definition: cclogger.h:159
This is what you have to use instead of wxThread to add tasks to the Thread Pool. ...
bool useBuffer
useBuffer specifies that we&#39;re not parsing a file, but a temporary buffer.
Definition: parserthread.h:71
Token * m_LastParent
parent Token, for example, when you are parsing in the class member variables, m_LastParent holds a p...
Definition: parserthread.h:405
bool handleTypedefs
whether to parse "typedef ..." like statement
Definition: parserthread.h:123
bool followGlobalIncludes
parse the file in #include <file> directive
Definition: parserthread.h:99
int initLineOfBuffer
since we are not parsing start from the first line of the file, this is the first line number of the ...
Definition: parserthread.h:84
bool bufferSkipBlocks
do we parse inside the {...} body
Definition: parserthread.h:87
size_t m_StructUnionUnnamedCount
Definition: parserthread.h:475
wxString Name
Definition: parserthread.h:29
ParserThreadOptions m_Options
parser options, see the ParserThreadOptions structure
Definition: parserthread.h:438
TokenKind
Definition: token.h:29
int Execute()
Execute() is a virtual function derived from cbThreadedTask class, we should override it here...
Definition: parserthread.h:188
wxString m_Buffer
a wxString holding the parsing buffer, if it is a file in the hard disk, then this stands for the fil...
Definition: parserthread.h:467