~ubuntu-branches/ubuntu/lucid/codelite/lucid

« back to all changes in this revision

Viewing changes to CodeLite/entry.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2009-02-10 02:27:55 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090210022755-m5692nfc1t5uf1w9
Tags: 1.0.2759+dfsg-0ubuntu1
* New upstream release (LP: #327216).
* debian/patches/series, debian/patches/00_fix-ia64-build.patch:
  + Dropped, applied upstream already.
* debian/patches/02_fix-desktop.patch,
  debian/patches/03_fix-sh.patch:
  + Refreshed to patch cleanly.
* debian/rules:
  + Make get-orig-source honour UPSTREAM_VERSION if set.
* debian/ctags-le.1,
  debian/codelite_indexer.1,
  debian/codelite.manpages:
  + Dropped ctags-le manpage, since ctags-le was replaced by
    codelite_indexer.
  + Added codelite_indexer manpage.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//////////////////////////////////////////////////////////////////////////////
2
2
//////////////////////////////////////////////////////////////////////////////
3
3
//
4
 
// copyright            : (C) 2008 by Eran Ifrah                            
5
 
// file name            : entry.cpp              
6
 
//                                                                          
 
4
// copyright            : (C) 2008 by Eran Ifrah
 
5
// file name            : entry.cpp
 
6
//
7
7
// -------------------------------------------------------------------------
8
 
// A                                                                        
9
 
//              _____           _      _     _ _                            
10
 
//             /  __ \         | |    | |   (_) |                           
11
 
//             | /  \/ ___   __| | ___| |    _| |_ ___                      
12
 
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )                    
13
 
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/                     
14
 
//              \____/\___/ \__,_|\___\_____/_|\__\___|                     
15
 
//                                                                          
16
 
//                                                  F i l e                 
17
 
//                                                                          
18
 
//    This program is free software; you can redistribute it and/or modify  
19
 
//    it under the terms of the GNU General Public License as published by  
20
 
//    the Free Software Foundation; either version 2 of the License, or     
21
 
//    (at your option) any later version.                                   
22
 
//                                                                          
 
8
// A
 
9
//              _____           _      _     _ _
 
10
//             /  __ \         | |    | |   (_) |
 
11
//             | /  \/ ___   __| | ___| |    _| |_ ___
 
12
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
 
13
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
 
14
//              \____/\___/ \__,_|\___\_____/_|\__\___|
 
15
//
 
16
//                                                  F i l e
 
17
//
 
18
//    This program is free software; you can redistribute it and/or modify
 
19
//    it under the terms of the GNU General Public License as published by
 
20
//    the Free Software Foundation; either version 2 of the License, or
 
21
//    (at your option) any later version.
 
22
//
23
23
//////////////////////////////////////////////////////////////////////////////
24
24
//////////////////////////////////////////////////////////////////////////////
25
25
 #include "precompiled_header.h"
26
26
#include "tags_database.h"
27
27
 
28
28
#include "entry.h"
 
29
#include <wx/tokenzr.h>
29
30
#include "tokenizer.h"
30
31
#include "language.h"
31
32
 
33
34
#ifdef _DEBUG
34
35
#define new DEBUG_NEW
35
36
#endif
36
 
#endif 
 
37
#endif
37
38
 
38
39
TagEntry::TagEntry(const tagEntry& entry)
39
40
{
76
77
        m_hti = rhs.m_hti;
77
78
        m_scope = rhs.m_scope.c_str();
78
79
        m_differOnByLineNumber = rhs.m_differOnByLineNumber;
79
 
        
 
80
 
80
81
        // loop over the map and copy item by item
81
 
        // we use the c_str() method to force our own copy of the string and to avoid 
 
82
        // we use the c_str() method to force our own copy of the string and to avoid
82
83
        // ref counting which may cause crash when sharing wxString among threads
83
84
        m_extFields.clear();
84
85
        std::map<wxString, wxString>::const_iterator iter = rhs.m_extFields.begin();
91
92
bool TagEntry::operator ==(const TagEntry& rhs)
92
93
{
93
94
        //Note: tree item id is not used in this function!
94
 
        bool res =      
 
95
        bool res =
95
96
                m_scope == rhs.m_scope &&
96
97
                m_file == rhs.m_file &&
97
98
                m_kind == rhs.m_kind &&
104
105
                GetAccess() == rhs.GetAccess() &&
105
106
                GetSignature() == rhs.GetSignature() &&
106
107
                GetTyperef() == rhs.GetTyperef();
107
 
        
 
108
 
108
109
        bool res2 = m_scope == rhs.m_scope &&
109
110
                m_file == rhs.m_file &&
110
111
                m_kind == rhs.m_kind &&
116
117
                GetAccess() == rhs.GetAccess() &&
117
118
                GetSignature() == rhs.GetSignature() &&
118
119
                GetTyperef() == rhs.GetTyperef();
119
 
                
 
120
 
120
121
        if(res2 && !res) {
121
122
                // the entries are differs only in the line numbers
122
123
                m_differOnByLineNumber = true;
124
125
        return res;
125
126
}
126
127
 
127
 
void TagEntry::Create(const wxString &fileName, 
128
 
                                          const wxString &name, 
129
 
                                          int lineNumber, 
130
 
                                          const wxString &pattern, 
131
 
                                          const wxString &kind, 
 
128
void TagEntry::Create(const wxString &fileName,
 
129
                                          const wxString &name,
 
130
                                          int lineNumber,
 
131
                                          const wxString &pattern,
 
132
                                          const wxString &kind,
132
133
                                          std::map<wxString, wxString>& extFields)
133
134
{
134
135
        SetName( name );
206
207
                wxString value = _U(entry.fields.list[i].value);
207
208
                m_extFields[key] = value;
208
209
        }
209
 
        Create( _U(entry.file), 
210
 
                _U(entry.name), 
211
 
                entry.address.lineNumber, 
212
 
                _U(entry.address.pattern), 
213
 
                _U(entry.kind), 
 
210
        Create( _U(entry.file),
 
211
                _U(entry.name),
 
212
                entry.address.lineNumber,
 
213
                _U(entry.address.pattern),
 
214
                _U(entry.kind),
214
215
                m_extFields);
215
216
}
216
217
 
231
232
        std::cout << "======================================" << std::endl;
232
233
}
233
234
 
234
 
wxString TagEntry::Key() const 
 
235
wxString TagEntry::Key() const
235
236
{
236
237
        wxString key;
237
238
        if(GetKind() == wxT("prototype") || GetKind() == wxT("macro")) {
238
239
                key << GetKind() << wxT(": ");
239
240
        }
240
 
        
 
241
 
241
242
        key << GetPath() << GetSignature();
242
243
        return key;
243
244
}
254
255
        wxString name;
255
256
 
256
257
        if( GetParent() == wxT("<global>") ){
257
 
                name << GetDisplayName(); 
 
258
                name << GetDisplayName();
258
259
        } else {
259
260
                name << GetParent() << wxT("::") << GetName() << GetSignature();
260
261
        }
307
308
                insertPerepareStmnt.Bind(12, GetScope());
308
309
                insertPerepareStmnt.ExecuteUpdate();
309
310
                insertPerepareStmnt.Reset();
310
 
                
 
311
 
311
312
                // update the ID
312
313
//              SetId( db->LastRowId() );
313
314
 
387
388
 
388
389
const bool TagEntry::IsContainer() const
389
390
{
390
 
        return  GetKind() == wxT("class")  || 
391
 
                GetKind() == wxT("struct") || 
392
 
                GetKind() == wxT("union")  || 
 
391
        return  GetKind() == wxT("class")  ||
 
392
                GetKind() == wxT("struct") ||
 
393
                GetKind() == wxT("union")  ||
393
394
                GetKind() == wxT("namespace") ||
394
395
                GetKind() == wxT("project");
395
396
}
411
412
        if( typeref.IsEmpty() == false )
412
413
        {
413
414
                wxString name = typeref.BeforeFirst(wxT(':'));
414
 
                return name;            
 
415
                return name;
415
416
        }
416
417
        return wxEmptyString;
417
418
}
423
424
        if( typeref.IsEmpty() == false )
424
425
        {
425
426
                wxString name = typeref.AfterFirst(wxT(':'));
426
 
                return name;            
 
427
                return name;
427
428
        }
428
429
 
429
 
        // incase our entry is a typedef, and it is not marked as typeref, 
 
430
        // incase our entry is a typedef, and it is not marked as typeref,
430
431
        // try to get the real name from the pattern
431
432
        if( GetKind() == wxT("typedef"))
432
433
        {
478
479
                                templateInit << token;
479
480
                        }
480
481
                        break;
481
 
                        
 
482
 
482
483
                case IDENTIFIER:
483
484
                        if(depth == 0){
484
485
                                name << token;
486
487
                                templateInit << token;
487
488
                        }
488
489
                        break;
489
 
                        
 
490
 
490
491
                case wxT('<'):
491
492
                        depth++;
492
493
                        if(depth > 0){ templateInit << token; }
493
494
                        break;
494
 
                        
 
495
 
495
496
                case wxT('>'):
496
497
                        if(depth > 0){ templateInit << token; }
497
498
                        depth--;
498
499
                        break;
499
 
                        
 
500
 
500
501
                case wxT('{'):
501
502
                case wxT('('):
502
503
                case wxT('['):
503
504
                        if(depth > 0){ templateInit << token; }
504
505
                        depth++;
505
506
                        break;
506
 
                
 
507
 
507
508
                case wxT('}'):
508
509
                case wxT(')'):
509
510
                case wxT(']'):
510
511
                        if(depth > 0){ templateInit << token; }
511
512
                        depth--;
512
513
                        break;
513
 
                        
 
514
 
514
515
                default:
515
516
                        if(depth > 0){ templateInit << token; }
516
517
                        break;
531
532
 
532
533
wxString TagEntry::GetInsertOneStatement()
533
534
{
534
 
        return wxT("INSERT INTO TAGS VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");       
 
535
        return wxT("INSERT INTO TAGS VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
535
536
}
536
537
 
537
538
wxString TagEntry::GetPattern()
541
542
        m_pattern.Replace(wxT("\\/"), wxT("/"));
542
543
        return m_pattern;
543
544
}
 
545
 
 
546
void TagEntry::FromLine(const wxString& line)
 
547
{
 
548
        wxString pattern, kind;
 
549
        wxString strLine = line;
 
550
        long lineNumber = wxNOT_FOUND;
 
551
        std::map<wxString, wxString> extFields;
 
552
 
 
553
        //get the token name
 
554
        wxString name = strLine.BeforeFirst(wxT('\t'));
 
555
        strLine = strLine.AfterFirst(wxT('\t'));
 
556
 
 
557
        //get the file name
 
558
        wxString fileName = strLine.BeforeFirst(wxT('\t'));
 
559
        strLine = strLine.AfterFirst(wxT('\t'));
 
560
 
 
561
        //here we can get two options:
 
562
        //pattern followed by ;"
 
563
        //or
 
564
        //line number followed by ;"
 
565
        int end = strLine.Find(wxT(";\""));
 
566
        if (end == wxNOT_FOUND) {
 
567
                //invalid pattern found
 
568
                return;
 
569
        }
 
570
 
 
571
        if (strLine.StartsWith(wxT("/^"))) {
 
572
                //regular expression pattern found
 
573
                pattern = strLine.Mid(0, end);
 
574
                strLine = strLine.Right(strLine.Length() - (end + 2));
 
575
        } else {
 
576
                //line number pattern found, this is usually the case when
 
577
                //dealing with macros in C++
 
578
                pattern = strLine.Mid(0, end);
 
579
                strLine = strLine.Right(strLine.Length() - (end + 2));
 
580
 
 
581
                pattern = pattern.Trim();
 
582
                pattern = pattern.Trim(false);
 
583
                pattern.ToLong(&lineNumber);
 
584
        }
 
585
 
 
586
        //next is the kind of the token
 
587
        if (strLine.StartsWith(wxT("\t"))) {
 
588
                strLine = strLine.AfterFirst(wxT('\t'));
 
589
        }
 
590
 
 
591
        kind = strLine.BeforeFirst(wxT('\t'));
 
592
        strLine = strLine.AfterFirst(wxT('\t'));
 
593
 
 
594
        if (strLine.IsEmpty() == false) {
 
595
                wxStringTokenizer tkz(strLine, wxT('\t'));
 
596
                while (tkz.HasMoreTokens()) {
 
597
                        wxString token = tkz.NextToken();
 
598
                        wxString key = token.BeforeFirst(wxT(':'));
 
599
                        wxString val = token.AfterFirst(wxT(':'));
 
600
                        key = key.Trim();
 
601
                        key = key.Trim(false);
 
602
 
 
603
                        val = val.Trim();
 
604
                        val = val.Trim(false);
 
605
                        if (key == wxT("line") && !val.IsEmpty()) {
 
606
                                val.ToLong(&lineNumber);
 
607
                        } else {
 
608
                                if (key == wxT("union") || key == wxT("struct")) {
 
609
 
 
610
                                        // remove the anonymous part of the struct / union
 
611
                                        if (!val.StartsWith(wxT("__anon"))) {
 
612
                                                // an internal anonymous union / struct
 
613
                                                // remove all parts of the
 
614
                                                wxArrayString scopeArr;
 
615
                                                wxString tmp, new_val;
 
616
 
 
617
                                                scopeArr = wxStringTokenize(val, wxT(":"), wxTOKEN_STRTOK);
 
618
                                                for (size_t i=0; i<scopeArr.GetCount(); i++) {
 
619
                                                        if (scopeArr.Item(i).StartsWith(wxT("__anon")) == false) {
 
620
                                                                tmp << scopeArr.Item(i) << wxT("::");
 
621
                                                        }
 
622
                                                }
 
623
 
 
624
                                                tmp.EndsWith(wxT("::"), &new_val);
 
625
                                                val = new_val;
 
626
                                        }
 
627
                                }
 
628
 
 
629
                                extFields[key] = val;
 
630
                        }
 
631
                }
 
632
        }
 
633
 
 
634
        kind = kind.Trim();
 
635
        name = name.Trim();
 
636
        fileName = fileName.Trim();
 
637
        pattern = pattern.Trim();
 
638
 
 
639
        if (kind == wxT("enumerator")) {
 
640
                // enums are specials, they are not really a scope so they should appear when I type:
 
641
                // enumName::
 
642
                // they should be member of their parent (which can be <global>, or class)
 
643
                // but we want to know the "enum" type they belong to, so save that in typeref,
 
644
                // then patch the enum field to lift the enumerator into the enclosing scope.
 
645
                // watch out for anonymous enums -- leave their typeref field blank.
 
646
                std::map<wxString,wxString>::iterator e = extFields.find(wxT("enum"));
 
647
                if (e != extFields.end()) {
 
648
                        wxString typeref = e->second;
 
649
                        e->second = e->second.BeforeLast(wxT(':')).BeforeLast(wxT(':'));
 
650
                        if (!typeref.AfterLast(wxT(':')).StartsWith(wxT("__anon"))) {
 
651
                                extFields[wxT("typeref")] = typeref;
 
652
                        }
 
653
                }
 
654
        }
 
655
 
 
656
        this->Create(fileName, name, lineNumber, pattern, kind, extFields);
 
657
}