1
1
//////////////////////////////////////////////////////////////////////////////
2
2
//////////////////////////////////////////////////////////////////////////////
4
// copyright : (C) 2008 by Eran Ifrah
5
// file name : entry.cpp
4
// copyright : (C) 2008 by Eran Ifrah
5
// file name : entry.cpp
7
7
// -------------------------------------------------------------------------
10
// / __ \ | | | | (_) |
11
// | / \/ ___ __| | ___| | _| |_ ___
12
// | | / _ \ / _ |/ _ \ | | | __/ _ )
13
// | \__/\ (_) | (_| | __/ |___| | || __/
14
// \____/\___/ \__,_|\___\_____/_|\__\___|
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.
10
// / __ \ | | | | (_) |
11
// | / \/ ___ __| | ___| | _| |_ ___
12
// | | / _ \ / _ |/ _ \ | | | __/ _ )
13
// | \__/\ (_) | (_| | __/ |___| | || __/
14
// \____/\___/ \__,_|\___\_____/_|\__\___|
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.
23
23
//////////////////////////////////////////////////////////////////////////////
24
24
//////////////////////////////////////////////////////////////////////////////
25
25
#include "precompiled_header.h"
26
26
#include "tags_database.h"
29
#include <wx/tokenzr.h>
29
30
#include "tokenizer.h"
30
31
#include "language.h"
532
533
wxString TagEntry::GetInsertOneStatement()
534
return wxT("INSERT INTO TAGS VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
535
return wxT("INSERT INTO TAGS VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
537
538
wxString TagEntry::GetPattern()
541
542
m_pattern.Replace(wxT("\\/"), wxT("/"));
542
543
return m_pattern;
546
void TagEntry::FromLine(const wxString& line)
548
wxString pattern, kind;
549
wxString strLine = line;
550
long lineNumber = wxNOT_FOUND;
551
std::map<wxString, wxString> extFields;
554
wxString name = strLine.BeforeFirst(wxT('\t'));
555
strLine = strLine.AfterFirst(wxT('\t'));
558
wxString fileName = strLine.BeforeFirst(wxT('\t'));
559
strLine = strLine.AfterFirst(wxT('\t'));
561
//here we can get two options:
562
//pattern followed by ;"
564
//line number followed by ;"
565
int end = strLine.Find(wxT(";\""));
566
if (end == wxNOT_FOUND) {
567
//invalid pattern found
571
if (strLine.StartsWith(wxT("/^"))) {
572
//regular expression pattern found
573
pattern = strLine.Mid(0, end);
574
strLine = strLine.Right(strLine.Length() - (end + 2));
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));
581
pattern = pattern.Trim();
582
pattern = pattern.Trim(false);
583
pattern.ToLong(&lineNumber);
586
//next is the kind of the token
587
if (strLine.StartsWith(wxT("\t"))) {
588
strLine = strLine.AfterFirst(wxT('\t'));
591
kind = strLine.BeforeFirst(wxT('\t'));
592
strLine = strLine.AfterFirst(wxT('\t'));
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(':'));
601
key = key.Trim(false);
604
val = val.Trim(false);
605
if (key == wxT("line") && !val.IsEmpty()) {
606
val.ToLong(&lineNumber);
608
if (key == wxT("union") || key == wxT("struct")) {
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;
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("::");
624
tmp.EndsWith(wxT("::"), &new_val);
629
extFields[key] = val;
636
fileName = fileName.Trim();
637
pattern = pattern.Trim();
639
if (kind == wxT("enumerator")) {
640
// enums are specials, they are not really a scope so they should appear when I type:
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;
656
this->Create(fileName, name, lineNumber, pattern, kind, extFields);