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