Code::Blocks  SVN r11506
parserthreadedtask.cpp
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  * $Revision: 11505 $
6  * $Id: parserthreadedtask.cpp 11505 2018-10-20 14:29:48Z ollydbg $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/plugins/codecompletion/parser/parserthreadedtask.cpp $
8  */
9 
10 #include <sdk.h>
11 
12 #ifndef CB_PRECOMP
13  #include <wx/string.h>
14 
15  #include <cbproject.h>
16  #include <projectfile.h>
17 #endif
18 
19 #include "parserthreadedtask.h"
20 
21 #include "cclogger.h"
22 #include "parser.h"
23 #include "tokentree.h"
24 
25 #define CC_PARSERTHREADEDTASK_DEBUG_OUTPUT 0
26 
27 #if defined(CC_GLOBAL_DEBUG_OUTPUT)
28  #if CC_GLOBAL_DEBUG_OUTPUT == 1
29  #undef CC_PARSERTHREADEDTASK_DEBUG_OUTPUT
30  #define CC_PARSERTHREADEDTASK_DEBUG_OUTPUT 1
31  #elif CC_GLOBAL_DEBUG_OUTPUT == 2
32  #undef CC_PARSERTHREADEDTASK_DEBUG_OUTPUT
33  #define CC_PARSERTHREADEDTASK_DEBUG_OUTPUT 2
34  #endif
35 #endif
36 
37 #if CC_PARSERTHREADEDTASK_DEBUG_OUTPUT == 1
38  #define TRACE(format, args...) \
39  CCLogger::Get()->DebugLog(F(format, ##args))
40  #define TRACE2(format, args...)
41 #elif CC_PARSERTHREADEDTASK_DEBUG_OUTPUT == 2
42  #define TRACE(format, args...) \
43  do \
44  { \
45  if (g_EnableDebugTrace) \
46  CCLogger::Get()->DebugLog(F(format, ##args)); \
47  } \
48  while (false)
49  #define TRACE2(format, args...) \
50  CCLogger::Get()->DebugLog(F(format, ##args))
51 #else
52  #define TRACE(format, args...)
53  #define TRACE2(format, args...)
54 #endif
55 
56 // class ParserThreadedTask
57 
59  m_Parser(parser),
60  m_ParserMutex(parserMTX)
61 {
62 }
63 
65 {
66  TRACE(_T("ParserThreadedTask::Execute(): Enter"));
67  if (!m_Parser) return 0;
68 
70 
73 
75 
76  // Here, it first parse the predefs, which is the predefined macros
77  TRACE(_T("ParserThreadedTask::Execute(): Parse predefined macros(in buffer)"));
78  if (!preDefs.IsEmpty())
79  m_Parser->ParseBuffer(preDefs, false, false);
80 
81  // clear the predefined macro string after it get parsed
83 
85  m_Parser->m_IsFirstBatch = true;
86 
87  TRACE(_T("ParserThreadedTask::Execute(): Parse source files"));
88  while (!batchFiles.empty())
89  {
90  TRACE(_T("-ParserThreadedTask::Execute(): Parse %s"), batchFiles.front().wx_str());
91  m_Parser->Parse(batchFiles.front()); // bool isLocal = true, bool locked = false
92  batchFiles.pop_front();
93  }
94 
96 
97  m_Parser->m_BatchParseFiles.clear();
98 
100  {
101  m_Parser->m_IgnoreThreadEvents = false; // we need to hear the pool finish event
102  m_Parser->m_IsParsing = true;
103  }
104 
106  TRACE(_T("ParserThreadedTask::Execute(): Leave"));
107 
108  return 0;
109 }
110 
111 // class MarkFileAsLocalThreadedTask
112 
114  m_Parser(parser), m_Project(project)
115 {
116 }
117 
119 {
120  TRACE(_T("MarkFileAsLocalThreadedTask::Execute()"));
121  if (!m_Project) return 0;
122  if (!m_Parser) return 0;
123 
124  // mark all project files as local
125  for (FilesList::const_iterator it = m_Project->GetFilesList().begin();
126  it != m_Project->GetFilesList().end(); ++it)
127  {
128  ProjectFile* pf = *it;
129  if (!pf)
130  continue;
131 
133  {
134  TokenTree* tree = m_Parser->GetTokenTree();
135 
137 
138  tree->MarkFileTokensAsLocal(pf->file.GetFullPath(), true, m_Project);
139 
141  }
142  }
143 
144  return 0;
145 }
wxMutex & m_ParserMutex
a Parser object which contain TokenTree
wxMutex s_TokenTreeMutex
Definition: tokentree.cpp:49
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
wxString relativeFilename
The relative (to the project) filename of this file.
Definition: projectfile.h:131
cbProject * m_Project
a Parser object which contain TokenTree
#define CC_LOCKER_TRACK_P_MTX_UNLOCK
Definition: cclogger.h:174
virtual int Execute()
Override this function with the task&#39;s job Return value doesn&#39;t matter.
virtual int Execute()
Override this function with the task&#39;s job Return value doesn&#39;t matter.
virtual FilesList & GetFilesList()
Provides an easy way to iterate all the files belonging in this target.
Definition: cbproject.h:685
wxFileName file
The full filename of this file.
Definition: projectfile.h:126
MarkFileAsLocalThreadedTask(Parser *parser, cbProject *project)
a container class to hold all the Tokens getting from parsing stage
Definition: tokentree.h:37
bool Parse(const wxString &filename, bool isLocal=true, bool locked=false)
parse the file, either immediately or delayed.
Definition: parser.cpp:273
#define _T(string)
#define TRACE(format, args...)
std::list< wxString > StringList
Definition: parser_base.h:20
Represents a file in a Code::Blocks project.
Definition: projectfile.h:39
EFileType FileType(const wxString &filename, bool force_refresh=false)
return a file type, which can be either header files or implementation files or other files ...
StringList m_BatchParseFiles
All other batch parse files, like the normal headers/sources.
Definition: parser.h:344
Represents a Code::Blocks project.
Definition: cbproject.h:96
#define CC_LOCKER_TRACK_TT_MTX_UNLOCK(M)
Definition: cclogger.h:165
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
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
#define CC_LOCKER_TRACK_TT_MTX_LOCK(M)
Definition: cclogger.h:159
bool m_IsFirstBatch
batch Parse mode flag.
Definition: parser.h:315
bool IsEmpty() const
#define CC_LOCKER_TRACK_P_MTX_LOCK
Definition: cclogger.h:173
wxString m_PredefinedMacros
Pre-defined macros, its a buffer queried from the compiler command line.
Definition: parser.h:347
virtual void ClearPredefinedMacros()
clears the list of predefined macros after it has been parsed
Definition: parser.cpp:211
virtual TokenTree * GetTokenTree() const
wxString GetFullPath(wxPathFormat format=wxPATH_NATIVE) const
virtual bool ParseBuffer(const wxString &buffer, bool isLocal, bool bufferSkipBlocks=false, bool isTemp=false, const wxString &filename=wxEmptyString, int parentIdx=-1, int initLine=0)
Must add a locker before call all named ParseBufferXXX functions, ParseBuffer function will directly ...
Definition: parser.cpp:364
ParserThreadedTask(Parser *parser, wxMutex &parserCS)
Parser class holds all the tokens of a C::B project.
Definition: parser.h:117