Debian Codegraph @

CodeLite/parsedtoken.cpp

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // copyright : (C) 2014 Eran Ifrah
5 // file name : parsedtoken.cpp
6 //
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 //
23 //////////////////////////////////////////////////////////////////////////////
24 //////////////////////////////////////////////////////////////////////////////
25
26 #include "parsedtoken.h"
27 #include "ctags_manager.h"
28
29 ParsedToken::ParsedToken()
30 : m_isTemplate(false)
31 , m_subscriptOperator(false)
32 , m_next(NULL)
33 , m_prev(NULL)
34 {
35 }
36
37 ParsedToken::~ParsedToken() {}
38
39 void ParsedToken::DeleteTokens(ParsedToken* head)
40 {
41 if(!head) {
42 return;
43 }
44
45 ParsedToken* n(head);
46 ParsedToken* tmpPtr(NULL);
47 while(n) {
48 tmpPtr = n->GetNext();
49 delete n;
50
51 n = tmpPtr;
52 }
53 }
54
55 wxString ParsedToken::GetPath() const
56 {
57 wxString path;
58 if(m_typeScope != wxT("<global>"))
59 path << m_typeScope;
60
61 if(!path.empty() && !m_type.empty()) {
62 path << "::";
63 }
64 path << m_type;
65 return path;
66 }
67
68 wxString ParsedToken::GetContextScope() const
69 {
70 if(GetCurrentScopeName() == GetName() && GetPrev() == NULL) {
71 // the scope name is equal the 'name'?
72 // copy ctor
73 return wxT("<global>");
74 }
75
76 if(GetPrev() == NULL) {
77 // we are the first in chain, return the current scope name
78 return GetCurrentScopeName();
79 } else {
80 return GetPrev()->GetPath();
81 }
82 }
83
84 void ParsedToken::RemoveScopeFromType()
85 {
86 // incase the realName already includes the scope, remove it from the typename
87 if(!GetTypeScope().IsEmpty() && GetTypeName().StartsWith(GetTypeScope() + wxT("::"))) {
88 wxString tt;
89 GetTypeName().StartsWith(GetTypeScope() + wxT("::"), &tt);
90 SetTypeName(tt);
91 }
92
93 // If the typeName already contains a scope in it, replace the
94 // scopename with it
95 if(GetTypeName().Contains(wxT("::"))) {
96 m_typeScope.Clear();
97 wxString tmpTypeName(m_type);
98 m_type = tmpTypeName.AfterLast(wxT(':'));
99 m_typeScope = tmpTypeName.BeforeLast(wxT(':'));
100
101 if(m_typeScope.EndsWith(wxT(":"))) {
102 m_typeScope.Truncate(m_typeScope.Length() - 1);
103 }
104 }
105 }
106
107 bool ParsedToken::ResovleTemplate(TagsManager* lookup)
108 {
109 wxString oldName = m_type;
110 if(!lookup->GetDatabase()->IsTypeAndScopeExistLimitOne(m_type, m_typeScope)) {
111
112 // Loop until the end of the chain and see if any of the context is template
113 ParsedToken* cur = this;
114 while(cur) {
115 if(cur->GetIsTemplate()) {
116 // our context is template
117 wxString newType = cur->TemplateToType(m_type);
118
119 if(newType != m_type) {
120 m_type = newType;
121 RemoveScopeFromType();
122 return true;
123 }
124 }
125 cur = cur->GetPrev();
126 }
127 }
128 return false;
129 }
130
131 wxString ParsedToken::TemplateToType(const wxString& templateArg)
132 {
133 int where = m_templateArgList.Index(templateArg);
134 if(where != wxNOT_FOUND) {
135 // it exists, return the name in the templateInstantiation list
136 if(m_templateInitialization.GetCount() > (size_t)where && m_templateInitialization.Item(where) != templateArg)
137 return m_templateInitialization.Item(where);
138 }
139 return templateArg;
140 }
141
142 void ParsedToken::ResolveTemplateType(TagsManager* lookup)
143 {
144 for(size_t i = 0; i < m_templateInitialization.GetCount(); i++) {
145 if(!lookup->GetDatabase()->IsTypeAndScopeExistLimitOne(m_templateInitialization.Item(i), wxT("<global>"))) {
146
147 // Loop until the end of the chain and see if any of the context is template
148 ParsedToken* cur = this;
149 while(cur) {
150 if(cur->GetIsTemplate()) {
151 // our context is template
152 wxString newType = cur->TemplateToType(m_templateInitialization.Item(i));
153
154 if(newType != m_templateInitialization.Item(i)) {
155 m_templateInitialization.Item(i) = newType;
156 break;
157 }
158 }
159 cur = cur->GetPrev();
160 }
161 }
162 }
163 }
164
165 bool ParsedToken::IsThis() const { return m_name == wxT("this"); }
166
167 wxString ParsedToken::GetFullScope() const
168 {
169 // rewind
170 auto cur = this;
171 while(cur && cur->m_prev) {
172 cur = cur->m_prev;
173 }
174 // build the scope
175 wxString scope;
176 while(cur != this) {
177 if(cur->GetTypeName() != "<global>" && !cur->GetTypeName().empty()) {
178 if(!scope.empty()) {
179 scope << "::";
180 }
181 scope << cur->GetTypeName();
182 }
183 cur = cur->m_next;
184 }
185 return scope;
186 }