36 #include "../classbrowser.h" 37 #include "../classbrowserbuilderthread.h" 44 #define CC_PARSER_DEBUG_OUTPUT 0 46 #if defined(CC_GLOBAL_DEBUG_OUTPUT) 47 #if CC_GLOBAL_DEBUG_OUTPUT == 1 48 #undef CC_PARSER_DEBUG_OUTPUT 49 #define CC_PARSER_DEBUG_OUTPUT 1 50 #elif CC_GLOBAL_DEBUG_OUTPUT == 2 51 #undef CC_PARSER_DEBUG_OUTPUT 52 #define CC_PARSER_DEBUG_OUTPUT 2 56 #if CC_PARSER_DEBUG_OUTPUT == 1 57 #define TRACE(format, args...) \ 58 CCLogger::Get()->DebugLog(F(format, ##args)) 59 #define TRACE2(format, args...) 60 #elif CC_PARSER_DEBUG_OUTPUT == 2 61 #define TRACE(format, args...) \ 64 if (g_EnableDebugTrace) \ 65 CCLogger::Get()->DebugLog(F(format, ##args)); \ 68 #define TRACE2(format, args...) \ 69 CCLogger::Get()->DebugLog(F(format, ##args)) 71 #define TRACE(format, args...) 72 #define TRACE2(format, args...) 102 m_Pool(this,
wxNewId(), 1, 2 * 1024 * 1024),
104 m_NeedsReparse(false),
105 m_IsFirstBatch(false),
106 m_ReparseTimer(this,
wxNewId()),
108 m_StopWatchRunning(false),
109 m_LastStopWatchTime(0),
110 m_IgnoreThreadEvents(true),
111 m_IsBatchParseDone(false),
113 m_NeedMarkFileAsLocal(true)
171 reason +=
_T(
"\n- still batch parse files to parse");
173 reason +=
_T(
"\n- still pre-defined macros to operate");
175 reason +=
_T(
"\n- still need to mark files as local");
177 reason +=
_T(
"\n- thread pool is not done yet");
189 TRACE(
_T(
"Parser::AddPredefinedMacros(): Stop the m_BatchTimer."));
204 TRACE(
_T(
"Parser::AddPredefinedMacros(): Starting m_BatchTimer."));
239 std::copy(filenames.begin(), filenames.end(), std::back_inserter(
m_BatchParseFiles));
246 TRACE(
_T(
"Parser::AddBatchParse(): Starting m_BatchTimer."));
266 TRACE(
_T(
"Parser::AddParse(): Starting m_BatchTimer."));
297 bool canparse =
false;
315 TRACE(
_T(
"Parser::Parse(): file already parsed or reserved for parsing") + filename);
342 TRACE(
_T(
"Parser::Parse(): Parsing included header, %s"), filename.
wx_str());
345 result = thread->
Parse();
353 TRACE(
_T(
"Parser::Parse(): Adding a Parsing job for %s"), filename.
wx_str());
365 bool bufferSkipBlocks,
bool isTemp,
366 const wxString& filename,
int parentIdx,
int initLine)
391 bool success = thread.
Parse();
419 bool success = thread.
Parse();
519 wxString msg(
_T(
"Parser::Reparse : The Parser is not done."));
535 TRACE(
_T(
"Parser::Reparse(): Starting m_ReparseTimer."));
560 wxString msg(
_T(
"Parser::UpdateParsingProject(): The Parser is not done."));
589 cbThrow(
_T(
"m_TokenTree is a nullptr?!"));
601 TRACE(
_T(
"Parser::OnAllThreadsDone(): Still some tasks left, starting m_BatchTimer."));
604 #if defined(CC_PARSER_PROFILE_TEST) 615 TRACE(
_T(
"Parser::OnAllThreadsDone(): Add a MarkFileAsLocalThreadedTask."));
637 parseEndLog.
Printf(
_T(
"Project '%s' parsing stage done (%lu total parsed files, ")
638 _T(
"%lu tokens in %ld minute(s), %ld.%03ld seconds)."), prj.
wx_str(),
656 TRACE(
_T(
"Parser::OnAllThreadsDone(): Post a PARSER_END event"));
670 const bool ret =
Parse(filename, !isGlobal, locked);
711 TRACE(
_T(
"Parser::OnBatchTimer(): Starting m_BatchTimer."));
724 bool send_event =
true;
725 bool sendStartParseEvent =
false;
732 TRACE(
_T(
"Parser::OnBatchTimer(): Adding a ParserThreadedTask thread to m_Pool."));
742 sendStartParseEvent =
true;
750 if (sendStartParseEvent)
761 wxString msg(
_T(
"Parser::ReparseModifiedFiles : The Parser is not done."));
765 TRACE(
_T(
"Parser::ReparseModifiedFiles(): Starting m_ReparseTimer."));
773 std::queue<size_t> files_idx;
774 std::queue<wxString> files_list;
775 TokenFileSet::const_iterator it;
786 files_list.push(filename);
794 files_list.push(filename);
800 while (!files_idx.empty())
813 while (!files_list.empty())
823 bool isParsed =
false;
848 evt.SetEventObject(
this);
860 bool force_all_on = !cfg->
ReadBool(
_T(
"/parser_defaults_changed"),
false);
863 cfg->
Write(
_T(
"/parser_defaults_changed"),
true);
865 cfg->
Write(
_T(
"/parser_follow_local_includes"),
true);
866 cfg->
Write(
_T(
"/parser_follow_global_includes"),
true);
867 cfg->
Write(
_T(
"/want_preprocessor"),
true);
868 cfg->
Write(
_T(
"/parse_complex_macros"),
true);
869 cfg->
Write(
_T(
"/platform_check"),
true);
902 wxUnusedVar(ft_dummy);
void AddParserThread(cbThreadedTask *task)
Remember a newly created internal running threads.
bool Parse()
Do the main job (syntax analysis) here.
bool Done() const
Tells if the pool has finished its job.
bool m_IsBatchParseDone
used to measure batch parse time
wxString fileOfBuffer
which file the buffer belongs to, this usually happens when we parse a piece of the cbEditor and the ...
BrowserSortType
specify the sort order of the symbol tree nodes
A parser threaded task, which can be assigned to the thread task pool, and run there.
bool caseSensitive
parse XXX.h in directive #include <XXX.h>
bool whileTyping
use real AI(scope sequence match) or not(plain text match)
size_t InsertFileOrGetIndex(const wxString &filename)
put the filename in the m_FilenameMap, and return the file index, if this file is already in the m_Fi...
bool m_IgnoreThreadEvents
Parser::OnAllThreadsDone will be called when m_Pool finished its job, but when we run a batch parsing...
bool followLocalIncludes
parse the file in #include "file" directive
bool useSmartSense
handle preprocessor directive in Tokenizer class
ConfigManager * GetConfigManager(const wxString &name_space) const
int ReadInt(const wxString &name, int defaultVal=0)
static Manager * Get()
Use Manager::Get() to get a pointer to its instance Manager::Get() is guaranteed to never return an i...
friend class ParserThread
static const int PARSER_BATCHPARSE_TIMER_RUN_IMMEDIATELY
#define CC_LOCKER_TRACK_P_MTX_UNLOCK
bool isTemp
this value is passed to the generated Token's m_IsTemp property
virtual bool RemoveFile(const wxString &filename)
this usually happens when the user removes a file from the existing project, it will remove all the t...
static bool IsAppShuttingDown()
wxStopWatch m_StopWatch
a stop watch to measure parsing time
ParserOptions m_Options
options for how the parser try to parse files
virtual void ReadOptions()
read Parser options from configure file
const wxString GetFilename(size_t fileIdx) const
void AbortParserThreads()
Tell internal running threads to abort further processing.
void OnBatchTimer(wxTimerEvent &event)
A timer is used to optimized the event handling for parsing, e.g.
bool bufferSkipOuterBlocks
not used
bool ReadBool(const wxString &name, bool defaultVal=false)
void EraseFilesToBeReparsedByIndex(size_t fileIdx)
bool m_NeedMarkFileAsLocal
if true, all the files of the current project will be labeled as "local"
bool storeDocumentation
this will check for the platform of the project/target when adding include folders to the parser ...
FileManager * GetFileManager() const
bool m_NeedsReparse
Indicates some files in the current project need to be re-parsed, this is commonly caused that the "r...
bool showInheritance
whether the base class or derive class information is shown as a child node default: false ...
BrowserOptions m_BrowserOptions
options for how the symbol browser was shown
virtual void WriteOptions()
write Parse options to configure file
bool Parse(const wxString &filename, bool isLocal=true, bool locked=false)
parse the file, either immediately or delayed.
int parentIdxOfBuffer
when parsing a function body, all the tokens are the children of the function token ...
size_t realsize()
some position of the std::vector<Token*> are not used, so the real size maybe a bit smaller than the ...
virtual bool AddFile(const wxString &filename, cbProject *project, bool isLocal=true)
this usually happens when user adds some files to an existing project, it just use AddParse() functio...
virtual bool Done()
check to see whether Parser is in Idle mode, there is no work need to be done in the Parser ...
std::list< wxString > StringList
DLLIMPORT FileType FileTypeOf(const wxString &filename)
size_t GetFileMapSize() const
void OnAllThreadsDone(CodeBlocksEvent &event)
When a ThreadPool batch parse stage is done, it will issue a cbEVT_THREADTASK_ALLDONE message...
EVTIMPORT const wxEventType cbEVT_THREADTASK_ALLDONE
virtual bool Start(int milliseconds=-1, bool oneShot=wxTIMER_CONTINUOUS)
wxString m_LastPredefinedMacros
A generic Code::Blocks event.
virtual void AddBatchParse(const StringList &filenames)
Add files to batch parse mode, internally.
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 ...
void DebugLog(const wxString &msg)
bool ParseBufferForNamespaces(const wxString &buffer, NameSpaceVec &result)
Get the context "namespace XXX { ... }" directive.
virtual ~Parser()
destructor
StringList m_BatchParseFiles
All other batch parse files, like the normal headers/sources.
mark all the tokens belong to the project as "local" E.g.
Parser(wxEvtHandler *parent, cbProject *project)
constructor
bool expandNS
whether a namespaces node is auto-expand auto-expand means the child of the namespace is automaticall...
std::vector< NameSpace > NameSpaceVec
void Write(const wxString &name, const wxString &value, bool ignoreEmpty=false)
friend class ParserThreadedTask
virtual bool ParseBufferForUsingNamespace(const wxString &buffer, wxArrayString &result, bool bufferSkipBlocks=true)
parse the buffer for collecting using namespace directive
Represents a Code::Blocks project.
void RemoveFile(const wxString &filename)
remove tokens belong to the file
TokenTree * m_TempTokenTree
a temp Token tree hold some temporary tokens, e.g.
virtual bool ParseBufferForNamespaces(const wxString &buffer, NameSpaceVec &result)
parse the buffer for collecting exposed namespace scopes
void ReparseModifiedFiles()
delete those files from the TokenTree, and add them again through AddParse() function ...
size_t GetFileStatusCountForIndex(size_t fileIdx) const
virtual const wxString & GetTitle() const
Read the target's title.
EFileType
the enum type of the file type
cbProject * m_Project
referring to the C::B cbp project currently parsing in one parser per workspace mode ...
bool handleFunctions
whether to parse the functions
const TokenFileSet * GetFilesToBeReparsed() const
TokenTree * m_TokenTree
each Parser class contains a TokenTree object which used to record tokens per project this tree will ...
bool wantPreprocessor
case sensitive in MarkItemsByAI
bool wantPreprocessor
handle the #if like preprocessor directives, this value is passed to Tokenizer
#define CC_LOCKER_TRACK_TT_MTX_UNLOCK(M)
const wxStringCharType * wx_str() const
virtual void AddPredefinedMacros(const wxString &defs)
set the predefined macro definition string was collected from the GCC command line, this function adds the string to an internal m_PredefinedMacros, and switch the ParserState
wxEvtHandler * m_Parent
when initialized, this variable will be an instance of a NativeParser
virtual bool UpdateParsingProject(cbProject *project)
set the associated C::B project pointer.
bool m_IsParsing
true, if the parser is still busy with parsing, false if the parsing stage has finished this value is...
ParserCommon::ParserState m_ParserState
indicated the current state the parser
bool parseComplexMacros
not used
static const int PARSER_BATCHPARSE_TIMER_DELAY_LONG
virtual bool IsFileParsed(const wxString &filename)
check to see a file is parsed already, it first check the TokenTree to see whether it has the specifi...
bool storeDocumentation
should tokenizer detect and store doxygen documentation?
bool followGlobalIncludes
parse XXX.h in directive #include "XXX.h"
virtual void AddParse(const wxString &filename)
Add one file to Batch mode Parsing, this is the bridge between the main thread and the thread pool...
#define CC_LOCKER_TRACK_TT_MTX_LOCK(M)
cb_must_consume_result LoaderBase * Load(const wxString &file, bool reuseEditors=false)
Loads a file, once this function is called, the actually loading process is done in the worker thread...
virtual bool Reparse(const wxString &filename, bool isLocal=true)
mark this file to be re-parsed in the TokenTree, tick the reparse timer, note it looks like the isLoc...
BrowserDisplayFilter displayFilter
token filter option
void RemoveParserThread(cbThreadedTask *task)
Remove a completed internal running threads.
int GetId() const
return the pool ID
BrowserDisplayFilter
specify the scope of the shown symbols
#define CC_LOCKER_TRACK_P_MTX_LOCK
cbThreadPool m_Pool
Thread Pool, executing all the ParserThread, used in batch parse mode.
This is what you have to use instead of wxThread to add tasks to the Thread Pool. ...
bool treeMembers
show members in the bottom tree.
void Start(long milliseconds=0)
non of the above three status, this means our Parser has finish all the jobs, and it is in idle mode ...
virtual const wxString GetPredefinedMacros() const
return the predefined macro definition string that has been collected
some files are changed by the user, so we are parsing the changed files
a cbThreadedTask can be executed in cbThreadPool to do a lot of parsing jobs in the begining stage of...
bool useBuffer
useBuffer specifies that we're not parsing a file, but a temporary buffer.
wxString m_PredefinedMacros
Pre-defined macros, its a buffer queried from the compiler command line.
void wxMilliSleep(unsigned long milliseconds)
virtual void ClearPredefinedMacros()
clears the list of predefined macros after it has been parsed
bool ParseBufferForUsingNamespace(const wxString &buffer, wxArrayString &result)
Get the context "using namespace XXX" directive.
static const int PARSER_BATCHPARSE_TIMER_DELAY
void AddTask(cbThreadedTask *task, bool autodelete=true)
Adds a new task to the pool.
void OnReparseTimer(wxTimerEvent &event)
some files in the Tokentree is marked as need to be reparsed, this can be done by a call of Reparse()...
bool parseComplexMacros
reparse the active editor while editing
BrowserSortType sortType
token sort option in the tree default: bstKind
void EraseFileStatusByIndex(size_t fileIdx)
void DisconnectEvents()
connect event handlers of the timers and thread pool
virtual bool ParseBufferForFunctions(const wxString &buffer)
parser the current editor control, this function is used to list all the functions in the current cod...
void ProcessParserEvent(ParserCommon::ParserState state, int id, const wxString &info=wxEmptyString)
The parser will let its parent (NativeParser) to handle the event, as the CodeCompletion instance was...
bool followGlobalIncludes
parse the file in #include <file> directive
the Parser object is newly created, and we are parsing the predefined macro buffer, the source files, and finally mark the project's tokens as local
static wxMutex s_ParserMutex
size_t ReserveFileForParsing(const wxString &filename, bool preliminary=false)
mark a file to be parsed.
the user has add some files to the cbproject, so we are parsing the new added files ...
int initLineOfBuffer
since we are not parsing start from the first line of the file, this is the first line number of the ...
void EraseFileMapInFileMap(size_t fileIdx)
static const int PARSER_REPARSE_TIMER_DELAY
virtual bool ParseFile(const wxString &filename, bool isGlobal, bool locked=false)
the only usage of this function is in the Parserthread class, when handling include directives the pa...
virtual wxString NotDoneReason()
if the Parser is not in Idle mode, show which need to be done
wxTimer m_BatchTimer
a timer to delay the operation of batch parsing, see OnBatchTimer() member function as a reference ...
int Printf(const wxString &pszFormat,...)
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...
bool IsFileParsed(const wxString &filename)
is the file name is in the tokentree, and it's status is either assigned or beingparsed or done also...
static volatile Parser * s_CurrentParser
#define TRACE(format, args...)
bool bufferSkipBlocks
do we parse inside the {...} body
void FlagFileForReparsing(const wxString &filename)
mark the file as "need to be reparsed" status, usually happens that this file is saved(updated) so a ...
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 ...
void TerminateAllThreads()
cancel all the tasks in the thread pool m_Pool
void AbortAllTasks()
Aborts all running and pending tasks.
void ConnectEvents()
connect event handlers of the timers and thread pool
Parser class holds all the tokens of a C::B project.