| 1 |
#ifndef CXXVARIABLE_H |
| 2 |
#define CXXVARIABLE_H |
| 3 |
|
| 4 |
#include "CxxLexerAPI.h" |
| 5 |
#include "codelite_exports.h" |
| 6 |
#include "macros.h" |
| 7 |
#include "smart_ptr.h" |
| 8 |
|
| 9 |
#include <map> |
| 10 |
#include <set> |
| 11 |
#include <unordered_map> |
| 12 |
#include <vector> |
| 13 |
#include <wx/string.h> |
| 14 |
#include <wxStringHash.h> |
| 15 |
|
| 16 |
class WXDLLIMPEXP_CL CxxVariable |
| 17 |
{ |
| 18 |
public: |
| 19 |
struct LexerToken { |
| 20 |
int type; |
| 21 |
int _depth; |
| 22 |
wxString text; |
| 23 |
wxString comment; |
| 24 |
|
| 25 |
LexerToken() |
| 26 |
: type(0) |
| 27 |
, _depth(0) |
| 28 |
{ |
| 29 |
} |
| 30 |
|
| 31 |
LexerToken(const CxxLexerToken& token, int depth) |
| 32 |
{ |
| 33 |
FromCxxLexerToken(token); |
| 34 |
this->_depth = depth; |
| 35 |
} |
| 36 |
|
| 37 |
int GetType() const { return type; } |
| 38 |
void FromCxxLexerToken(const CxxLexerToken& token) |
| 39 |
{ |
| 40 |
this->type = token.GetType(); |
| 41 |
this->comment = token.GetWXComment(); |
| 42 |
this->text = token.GetWXString(); |
| 43 |
} |
| 44 |
typedef std::vector<CxxVariable::LexerToken> Vec_t; |
| 45 |
}; |
| 46 |
|
| 47 |
enum eFlags { |
| 48 |
kToString_None = 0, |
| 49 |
// Include the variable name |
| 50 |
kToString_Name = (1 << 0), |
| 51 |
// Include the default value |
| 52 |
kToString_DefaultValue = (1 << 1), |
| 53 |
kToString_Default = kToString_Name, |
| 54 |
// Revert back type->macro (e.g. wxWindowMSW -> wxWindow) |
| 55 |
kToString_ReverseMacros = (1 << 2), |
| 56 |
}; |
| 57 |
|
| 58 |
protected: |
| 59 |
wxString m_name; |
| 60 |
CxxVariable::LexerToken::Vec_t m_type; |
| 61 |
wxString m_defaultValue; |
| 62 |
eCxxStandard m_standard; |
| 63 |
wxString m_pointerOrReference; |
| 64 |
bool m_isAuto = false; |
| 65 |
int m_lineNumber = wxNOT_FOUND; |
| 66 |
|
| 67 |
public: |
| 68 |
typedef SmartPtr<CxxVariable> Ptr_t; |
| 69 |
typedef std::vector<CxxVariable::Ptr_t> Vec_t; |
| 70 |
typedef std::unordered_map<wxString, CxxVariable::Ptr_t> Map_t; |
| 71 |
|
| 72 |
public: |
| 73 |
CxxVariable(eCxxStandard standard); |
| 74 |
CxxVariable() |
| 75 |
: m_standard(eCxxStandard::kCxx11) |
| 76 |
, m_isAuto(false) |
| 77 |
{ |
| 78 |
} |
| 79 |
|
| 80 |
virtual ~CxxVariable(); |
| 81 |
|
| 82 |
void SetName(const wxString& name) { this->m_name = name; } |
| 83 |
void SetType(const CxxVariable::LexerToken::Vec_t& type) { this->m_type = type; } |
| 84 |
const wxString& GetName() const { return m_name; } |
| 85 |
const CxxVariable::LexerToken::Vec_t& GetType() const { return m_type; } |
| 86 |
// @see ToString() for description about 'table' |
| 87 |
wxString GetTypeAsString(const wxStringTable_t& table = wxStringTable_t()) const; |
| 88 |
// @see ToString() for description about 'table' |
| 89 |
wxString GetTypeAsCxxString(const wxStringTable_t& table = wxStringTable_t()) const; |
| 90 |
|
| 91 |
static wxString PackType(const CxxVariable::LexerToken::Vec_t& type, eCxxStandard standard, |
| 92 |
bool omitClassKeyword = false, const wxStringTable_t& table = wxStringTable_t()); |
| 93 |
|
| 94 |
/** |
| 95 |
* @brief return true if this variable was constructed from a statement like: |
| 96 |
* using MyInt = int; |
| 97 |
*/ |
| 98 |
bool IsUsing() const { return GetTypeAsString() == "using" && !m_defaultValue.IsEmpty(); } |
| 99 |
|
| 100 |
/** |
| 101 |
* @brief is this a valid variable? |
| 102 |
*/ |
| 103 |
bool IsOk() const { return !m_name.IsEmpty() && !m_type.empty(); } |
| 104 |
|
| 105 |
/** |
| 106 |
* @brief is this an "auto" variable? |
| 107 |
*/ |
| 108 |
bool IsAuto() const { return m_isAuto; } |
| 109 |
|
| 110 |
void SetLine(int l) { m_lineNumber = l; } |
| 111 |
int GetLineNumber() const { return m_lineNumber; } |
| 112 |
|
| 113 |
void SetIsAuto(bool b) { m_isAuto = b; } |
| 114 |
/** |
| 115 |
* @brief return a string representation for this variable |
| 116 |
* @param flags see values in eFlags |
| 117 |
* @param table macros table - reversed. i.e. the actual type is the key and the value is the macro name |
| 118 |
* this table is used when the flag kToString_ReverseMacros is passed |
| 119 |
*/ |
| 120 |
wxString ToString(size_t flags = CxxVariable::kToString_Default, |
| 121 |
const wxStringTable_t& table = wxStringTable_t()) const; |
| 122 |
|
| 123 |
void SetDefaultValue(const wxString& defaultValue) { this->m_defaultValue = defaultValue; } |
| 124 |
const wxString& GetDefaultValue() const { return m_defaultValue; } |
| 125 |
|
| 126 |
void SetPointerOrReference(const wxString& pointerOrReference) { this->m_pointerOrReference = pointerOrReference; } |
| 127 |
const wxString& GetPointerOrReference() const { return m_pointerOrReference; } |
| 128 |
}; |
| 129 |
|
| 130 |
#endif // CXXVARIABLE_H |