~ubuntu-branches/ubuntu/maverick/codelite/maverick

« back to all changes in this revision

Viewing changes to CodeLite/parse_thread.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-07-29 19:42:47 UTC
  • mfrom: (1.1.9 upstream) (18.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20100729194247-cuibfk03wog33nxq
Tags: 2.6.0.4189~dfsg-1
* New upstream release.
* Bump Standards.
* Refresh patches.
* Add license information about files under ./Debugger/

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
                        DEBUG_MESSAGE( wxString::Format(wxT("ParseThread::ProcessIncludes -> received 'TestDestroy()'") ) );\
53
53
                        return;\
54
54
                }\
55
 
}
 
55
        }
56
56
 
57
57
const wxEventType wxEVT_PARSE_THREAD_UPDATED_FILE_SYMBOLS = XRCID("parse_thread_updated_symbols");
58
58
const wxEventType wxEVT_PARSE_THREAD_MESSAGE              = XRCID("parse_thread_update_status_bar");
59
59
const wxEventType wxEVT_PARSE_THREAD_SCAN_INCLUDES_DONE   = XRCID("parse_thread_scan_includes_done");
60
60
const wxEventType wxEVT_PARSE_THREAD_CLEAR_TAGS_CACHE     = XRCID("parse_thread_clear_tags_cache");
61
 
 
 
61
const wxEventType wxEVT_PARSE_THREAD_RETAGGING_PROGRESS   = XRCID("parse_thread_clear_retagging_progress");
 
62
const wxEventType wxEVT_PARSE_THREAD_RETAGGING_COMPLETED  = XRCID("parse_thread_clear_retagging_compelted");
62
63
 
63
64
ParseThread::ParseThread()
64
 
                : WorkerThread()
65
 
                , m_pDb              ( NULL )
 
65
        : WorkerThread()
 
66
        , m_pDb              ( NULL )
66
67
{
67
68
}
68
69
 
86
87
        case ParseRequest::PR_FILESAVED:
87
88
                ProcessSimple( req );
88
89
                break;
 
90
        case ParseRequest::PR_PARSE_AND_STORE:
 
91
                ProcessParseAndStore( req );
 
92
                break;
89
93
        }
90
94
}
91
95
 
170
174
        // Remove from this list all files which starts with one of the crawler search paths
171
175
        wxArrayString searchPaths, excludePaths, filteredFileList;
172
176
        GetSearchPaths( searchPaths, excludePaths );
173
 
        
 
177
 
174
178
        DEBUG_MESSAGE( wxString::Format(wxT("Initial workspace files count is %d"), req->_workspaceFiles.size()) ) ;
175
 
        
 
179
 
176
180
        for(size_t i=0; i<req->_workspaceFiles.size(); i++) {
177
181
                wxString name(req->_workspaceFiles.at(i).c_str(), wxConvUTF8);
178
182
                wxFileName fn(name);
179
183
                fn.MakeAbsolute();
180
 
 
181
 
                bool isFromSearchPath(false);
182
 
                for(size_t j=0; j<searchPaths.GetCount(); j++) {
183
 
                        wxFileName p ( searchPaths.Item(j) + wxFileName::GetPathSeparator());
184
 
                        //DEBUG_MESSAGE( wxString::Format(wxT("Comparing %s vs %s"), fn.GetFullPath().c_str(), p.GetPath().c_str()));
185
 
                        if( fn.GetFullPath().StartsWith(p.GetPath()) ) {
186
 
                                //DEBUG_MESSAGE(wxT("Match was found for file, this file will NOT be parsed!"));
187
 
                                isFromSearchPath = true;
188
 
                                break;
189
 
                        }
190
 
                }
191
 
 
192
 
                // this file is not part of the search paths
193
 
                if( !isFromSearchPath ) {
194
 
                        filteredFileList.Add( fn.GetFullPath() );
195
 
                }
 
184
                filteredFileList.Add( fn.GetFullPath() );
196
185
        }
197
186
 
198
187
        DEBUG_MESSAGE( wxString::Format(wxT("ParseThread::ProcessIncludes -> Workspace files %d"), filteredFileList.GetCount()) );
202
191
        // Clear the results once
203
192
        {
204
193
                wxCriticalSectionLocker locker( TagsManagerST::Get()->m_crawlerLocker );
205
 
                
 
194
 
206
195
                fcFileOpener::Instance()->ClearResults();
207
196
                fcFileOpener::Instance()->ClearSearchPath();
208
197
 
228
217
                        }
229
218
                }
230
219
        }
231
 
        
 
220
 
232
221
        std::set<std::string> *newSet = new std::set<std::string>(fcFileOpener::Instance()->GetResults());
233
222
 
234
223
#ifdef PARSE_THREAD_DBG
238
227
                DEBUG_MESSAGE( wxString::Format(wxT("ParseThread::ProcessIncludes -> %s"), fileN.c_str() ) );
239
228
        }
240
229
#endif
241
 
        
 
230
 
242
231
        // collect the results
243
232
        wxCommandEvent event(wxEVT_PARSE_THREAD_SCAN_INCLUDES_DONE);
244
233
        event.SetClientData(newSet);
337
326
        // If there is no event handler set to handle this comaprison
338
327
        // results, then nothing more to be done
339
328
        if (m_notifiedWindow ) {
340
 
                
 
329
 
341
330
                bool sendClearCacheEvent(false);
342
331
                std::vector<std::pair<wxString, TagEntry> >  realModifiedItems;
343
 
                
 
332
 
344
333
                sendClearCacheEvent = (!deletedItems.empty() || !realModifiedItems.empty() || !newItems.empty());
345
 
                
 
334
 
346
335
                // send "end" event
347
336
                wxCommandEvent e(wxEVT_PARSE_THREAD_UPDATED_FILE_SYMBOLS);
348
337
                wxPostEvent(m_notifiedWindow, e);
355
344
                        SendEvent(wxEVT_COMMAND_SYMBOL_TREE_ADD_ITEM, req->getFile(), goodNewItems);
356
345
 
357
346
                if ( !modifiedItems.empty() ) {
358
 
                        
 
347
 
359
348
                        for (size_t i=0; i<modifiedItems.size(); i++) {
360
349
                                std::pair<wxString, TagEntry> p = modifiedItems.at(i);
361
350
                                if (!p.second.GetDifferOnByLineNumber()) {
366
355
                                SendEvent(wxEVT_COMMAND_SYMBOL_TREE_UPDATE_ITEM, req->getFile(), realModifiedItems);
367
356
                        }
368
357
                }
369
 
                
 
358
 
370
359
                if(sendClearCacheEvent) {
371
360
                        wxCommandEvent clearCacheEvent(wxEVT_PARSE_THREAD_CLEAR_TAGS_CACHE);
372
361
                        wxPostEvent(m_notifiedWindow, clearCacheEvent);
383
372
        if ( !this->IsCrawlerEnabled() ) {
384
373
                return;
385
374
        }
386
 
        
387
 
        
 
375
 
 
376
 
388
377
        {
389
378
                wxCriticalSectionLocker locker( TagsManagerST::Get()->m_crawlerLocker );
390
 
                
 
379
 
391
380
                wxArrayString includePaths, excludePaths;
392
381
                GetSearchPaths( includePaths, excludePaths );
393
382
 
405
394
 
406
395
                // Before using the 'crawlerScan' we lock it, since it is not mt-safe
407
396
                crawlerScan( cfile.data() );
408
 
                
 
397
 
409
398
        }
410
 
        
 
399
 
411
400
        std::set<std::string> fileSet = fcFileOpener::Instance()->GetResults();
412
401
        std::set<std::string>::iterator iter = fileSet.begin();
413
402
        for (; iter != fileSet.end(); iter++ ) {
450
439
 
451
440
                e.SetClientData(new wxString(message.c_str()));
452
441
                m_notifiedWindow->AddPendingEvent( e );
453
 
                
 
442
 
454
443
                // if we added new symbols to the database, send an even to the main thread
455
444
                // to clear the tags cache
456
445
                if(totalSymbols) {
460
449
        }
461
450
}
462
451
 
 
452
void ParseThread::ProcessParseAndStore(ParseRequest* req)
 
453
{
 
454
        wxString      dbfile = req->getDbfile();
 
455
 
 
456
        // convert the file to tags
 
457
        double maxVal = (double)req->_workspaceFiles.size();
 
458
        if ( maxVal == 0.0 ) {
 
459
                return;
 
460
        }
 
461
 
 
462
        // we report every 10%
 
463
        double reportingPoint = maxVal / 100.0;
 
464
        reportingPoint = ceil( reportingPoint );
 
465
        if(reportingPoint == 0.0) {
 
466
                reportingPoint = 1.0;
 
467
        }
 
468
 
 
469
        if ( !m_pDb ) {
 
470
                m_pDb = new TagsStorageSQLite();
 
471
        }
 
472
        m_pDb->OpenDatabase( dbfile );
 
473
 
 
474
        // We commit every 10 files
 
475
        m_pDb->Begin();
 
476
        int    precent               (0);
 
477
        int    lastPercentageReported(0);
 
478
 
 
479
        for (size_t i=0; i<maxVal; i++) {
 
480
 
 
481
                // give a shutdown request a chance
 
482
                if( TestDestroy() ) {
 
483
                        // Do an ordered shutdown:
 
484
                        // rollback any transaction
 
485
                        // and close the database
 
486
                        m_pDb->Rollback();
 
487
                        delete m_pDb;
 
488
                        m_pDb = NULL;
 
489
                        return;
 
490
                }
 
491
 
 
492
                wxFileName curFile(wxString(req->_workspaceFiles.at(i).c_str(), wxConvUTF8));
 
493
 
 
494
                // Send notification to the main window with our progress report
 
495
                precent = (int)((i / maxVal) * 100);
 
496
 
 
497
                if( lastPercentageReported !=  precent) {
 
498
                        lastPercentageReported = precent;
 
499
                        wxCommandEvent retaggingProgressEvent(wxEVT_PARSE_THREAD_RETAGGING_PROGRESS);
 
500
                        retaggingProgressEvent.SetInt( (int)precent );
 
501
                        m_notifiedWindow->AddPendingEvent(retaggingProgressEvent);
 
502
                }
 
503
 
 
504
                TagTreePtr tree = TagsManagerST::Get()->ParseSourceFile(curFile);
 
505
                m_pDb->Store(tree, wxFileName(), false);
 
506
                if(m_pDb->InsertFileEntry(curFile.GetFullPath(), (int)time(NULL)) == TagExist) {
 
507
                        m_pDb->UpdateFileEntry(curFile.GetFullPath(), (int)time(NULL));
 
508
                }
 
509
 
 
510
                if ( i % 50 == 0 ) {
 
511
                        // Commit what we got so far
 
512
                        m_pDb->Commit();
 
513
                        // Start a new transaction
 
514
                        m_pDb->Begin();
 
515
                }
 
516
        }
 
517
 
 
518
        // Commit whats left
 
519
        m_pDb->Commit();
 
520
 
 
521
        /// Send notification to the main window with our progress report
 
522
        if(m_notifiedWindow) {
 
523
 
 
524
                wxCommandEvent retaggingCompletedEvent(wxEVT_PARSE_THREAD_RETAGGING_COMPLETED);
 
525
                std::vector<std::string> *arrFiles = new std::vector<std::string>;
 
526
                *arrFiles = req->_workspaceFiles;
 
527
                retaggingCompletedEvent.SetClientData( arrFiles );
 
528
 
 
529
                m_notifiedWindow->AddPendingEvent(retaggingCompletedEvent);
 
530
        }
 
531
 
 
532
        // Close the database
 
533
        delete m_pDb;
 
534
        m_pDb = NULL;
 
535
}
 
536
 
463
537
//--------------------------------------------------------------------------------------
464
538
// Parse Request Class
465
539
//--------------------------------------------------------------------------------------