| 1 |
////////////////////////////////////////////////////////////////////////////// |
| 2 |
////////////////////////////////////////////////////////////////////////////// |
| 3 |
// |
| 4 |
// copyright : (C) 2009 by Eran Ifrah |
| 5 |
// file name : parsedtoken.h |
| 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 |
#ifndef PARSEDTOKEN_H |
| 27 |
#define PARSEDTOKEN_H |
| 28 |
|
| 29 |
#include <wx/string.h> |
| 30 |
#include <wx/arrstr.h> |
| 31 |
#include <vector> |
| 32 |
#include <set> |
| 33 |
|
| 34 |
class TagsManager; |
| 35 |
class ParsedToken |
| 36 |
{ |
| 37 |
wxString m_type; |
| 38 |
wxString m_typeScope; |
| 39 |
wxString m_oper; |
| 40 |
bool m_isTemplate; |
| 41 |
wxArrayString m_templateInitialization; |
| 42 |
wxArrayString m_templateArgList; |
| 43 |
wxString m_name; |
| 44 |
bool m_subscriptOperator; |
| 45 |
wxString m_currentScopeName; |
| 46 |
wxString m_argumentList; |
| 47 |
ParsedToken* m_next; |
| 48 |
ParsedToken* m_prev; |
| 49 |
bool m_isAutoVariable; |
| 50 |
wxString m_autoExpression; |
| 51 |
|
| 52 |
public: |
| 53 |
static void DeleteTokens(ParsedToken* head); |
| 54 |
|
| 55 |
public: |
| 56 |
ParsedToken(); |
| 57 |
~ParsedToken(); |
| 58 |
|
| 59 |
void SetAutoExpression(const wxString& autoExpression) { this->m_autoExpression = autoExpression; } |
| 60 |
void SetIsAutoVariable(bool isAutoVariable) { this->m_isAutoVariable = isAutoVariable; } |
| 61 |
const wxString& GetAutoExpression() const { return m_autoExpression; } |
| 62 |
bool IsAutoVariable() const { return m_isAutoVariable; } |
| 63 |
bool IsThis() const; |
| 64 |
void SetCurrentScopeName(const wxString& currentScopeName) |
| 65 |
{ |
| 66 |
this->m_currentScopeName = currentScopeName; |
| 67 |
this->m_currentScopeName.Trim().Trim(false); |
| 68 |
} |
| 69 |
const wxString& GetCurrentScopeName() const { return m_currentScopeName; } |
| 70 |
void SetName(const wxString& name) |
| 71 |
{ |
| 72 |
this->m_name = name; |
| 73 |
this->m_name.Trim().Trim(false); |
| 74 |
; |
| 75 |
} |
| 76 |
const wxString& GetName() const { return m_name; } |
| 77 |
void SetNext(ParsedToken* next) { this->m_next = next; } |
| 78 |
void SetPrev(ParsedToken* prev) { this->m_prev = prev; } |
| 79 |
ParsedToken* GetNext() const { return m_next; } |
| 80 |
ParsedToken* GetPrev() const { return m_prev; } |
| 81 |
void SetSubscriptOperator(bool subscriptOperator) { this->m_subscriptOperator = subscriptOperator; } |
| 82 |
bool GetSubscriptOperator() const { return m_subscriptOperator; } |
| 83 |
|
| 84 |
void SetIsTemplate(bool isTemplate) { this->m_isTemplate = isTemplate; } |
| 85 |
bool GetIsTemplate() const { return m_isTemplate; } |
| 86 |
void SetOperator(const wxString& oper) |
| 87 |
{ |
| 88 |
this->m_oper = oper; |
| 89 |
this->m_oper.Trim().Trim(false); |
| 90 |
} |
| 91 |
void SetTypeName(const wxString& type) |
| 92 |
{ |
| 93 |
this->m_type = type; |
| 94 |
this->m_type.Trim().Trim(false); |
| 95 |
} |
| 96 |
void SetTypeScope(const wxString& typeScope) |
| 97 |
{ |
| 98 |
this->m_typeScope = typeScope; |
| 99 |
this->m_typeScope.Trim().Trim(false); |
| 100 |
|
| 101 |
if(this->m_typeScope.IsEmpty()) { |
| 102 |
this->m_typeScope = wxT("<global>"); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
const wxString& GetOperator() const { return m_oper; } |
| 107 |
const wxString& GetTypeName() const { return m_type; } |
| 108 |
const wxString& GetTypeScope() const { return m_typeScope; } |
| 109 |
void SetTemplateArgList(const wxArrayString& templateArgList, std::set<wxString>& argsSet) |
| 110 |
{ |
| 111 |
this->m_templateArgList = templateArgList; |
| 112 |
// Keep track of the template arguments |
| 113 |
argsSet.insert(m_templateArgList.begin(), m_templateArgList.end()); |
| 114 |
} |
| 115 |
|
| 116 |
void SetTemplateInitialization(const wxArrayString& templateInitialization) |
| 117 |
{ |
| 118 |
this->m_templateInitialization = templateInitialization; |
| 119 |
} |
| 120 |
const wxArrayString& GetTemplateArgList() const { return m_templateArgList; } |
| 121 |
const wxArrayString& GetTemplateInitialization() const { return m_templateInitialization; } |
| 122 |
|
| 123 |
void SetArgumentList(const wxString& argumentList) { this->m_argumentList = argumentList; } |
| 124 |
const wxString& GetArgumentList() const { return m_argumentList; } |
| 125 |
wxString GetContextScope() const; |
| 126 |
wxString GetPath() const; |
| 127 |
void RemoveScopeFromType(); |
| 128 |
|
| 129 |
/** |
| 130 |
* @brief replace the current type which is template with an actual type |
| 131 |
*/ |
| 132 |
bool ResovleTemplate(TagsManager* lookup); |
| 133 |
|
| 134 |
/** |
| 135 |
* @brief fix the template type with actual type |
| 136 |
* This method aims to fix the template argument NOT the token's type. |
| 137 |
* so it will fix code like this: |
| 138 |
* |
| 139 |
* template <typename T> class A { |
| 140 |
* typedef iterator<T> Iter; |
| 141 |
* }; |
| 142 |
* |
| 143 |
* And assuming iterator class: |
| 144 |
* |
| 145 |
* template <typename _T1> class iterator { |
| 146 |
* _T1 m_current; |
| 147 |
* }; |
| 148 |
* |
| 149 |
* so this method replaces _T1 with T which can then be replaced with the actual type |
| 150 |
* |
| 151 |
* @param lookup |
| 152 |
*/ |
| 153 |
void ResolveTemplateType(TagsManager* lookup); |
| 154 |
|
| 155 |
/** |
| 156 |
* @brief return the full scope (starting from the start until we reach this current token) |
| 157 |
*/ |
| 158 |
wxString GetFullScope() const; |
| 159 |
/** |
| 160 |
* @brief replace template argument with the actual type (std::vector<wxString>: _Tp --> wxString) |
| 161 |
* @param templateArg the template argument to replace |
| 162 |
*/ |
| 163 |
wxString TemplateToType(const wxString& templateArg); |
| 164 |
}; |
| 165 |
|
| 166 |
class TokenContainer |
| 167 |
{ |
| 168 |
public: |
| 169 |
ParsedToken* head; |
| 170 |
ParsedToken* current; |
| 171 |
bool rew; |
| 172 |
int retries; |
| 173 |
|
| 174 |
public: |
| 175 |
TokenContainer() |
| 176 |
: head(NULL) |
| 177 |
, current(NULL) |
| 178 |
, rew(false) |
| 179 |
, retries(0) |
| 180 |
{ |
| 181 |
} |
| 182 |
|
| 183 |
bool Rewind() |
| 184 |
{ |
| 185 |
if(retries > 3) return false; |
| 186 |
|
| 187 |
return rew; |
| 188 |
} |
| 189 |
|
| 190 |
void SetRewind(bool r) |
| 191 |
{ |
| 192 |
if(r) { |
| 193 |
retries++; |
| 194 |
} else { |
| 195 |
rew = r; |
| 196 |
} |
| 197 |
|
| 198 |
if(r && retries <= 3) { // we allow maximum of 3 retries |
| 199 |
rew = r; |
| 200 |
} |
| 201 |
} |
| 202 |
}; |
| 203 |
|
| 204 |
#endif // PARSEDTOKEN_H |