| 1 |
#include "CxxVariable.h" |
| 2 |
|
| 3 |
#include "CxxLexerAPI.h" |
| 4 |
#include "CxxScannerTokens.h" |
| 5 |
#include "CxxTokenizer.h" |
| 6 |
|
| 7 |
#include <algorithm> |
| 8 |
|
| 9 |
CxxVariable::CxxVariable(eCxxStandard standard) |
| 10 |
: m_standard(standard) |
| 11 |
, m_isAuto(false) |
| 12 |
{ |
| 13 |
} |
| 14 |
|
| 15 |
CxxVariable::~CxxVariable() {} |
| 16 |
|
| 17 |
wxString CxxVariable::GetTypeAsString(const wxStringTable_t& table) const |
| 18 |
{ |
| 19 |
return PackType(m_type, m_standard, false, table); |
| 20 |
} |
| 21 |
|
| 22 |
wxString CxxVariable::GetTypeAsCxxString(const wxStringTable_t& table) const |
| 23 |
{ |
| 24 |
if(IsUsing()) { |
| 25 |
// A name of the real data type is parsed as assignment expression |
| 26 |
return m_defaultValue; |
| 27 |
} |
| 28 |
return PackType(m_type, m_standard, true, table); |
| 29 |
} |
| 30 |
|
| 31 |
wxString CxxVariable::ToString(size_t flags, const wxStringTable_t& table) const |
| 32 |
{ |
| 33 |
wxUnusedVar(table); |
| 34 |
|
| 35 |
wxString str; |
| 36 |
str << GetTypeAsString({}); |
| 37 |
|
| 38 |
if(!GetPointerOrReference().IsEmpty()) { |
| 39 |
str << GetPointerOrReference(); |
| 40 |
} |
| 41 |
|
| 42 |
if(flags & kToString_Name) { |
| 43 |
str << " " << GetName(); |
| 44 |
} |
| 45 |
|
| 46 |
if((flags & kToString_DefaultValue) && !GetDefaultValue().IsEmpty()) { |
| 47 |
str << " = " << GetDefaultValue(); |
| 48 |
} |
| 49 |
return str; |
| 50 |
} |
| 51 |
|
| 52 |
wxString CxxVariable::PackType(const CxxVariable::LexerToken::Vec_t& type, eCxxStandard standard, bool omitClassKeyword, |
| 53 |
const wxStringTable_t& table) |
| 54 |
{ |
| 55 |
CxxTokenizer tokenizer; |
| 56 |
CxxLexerToken token; |
| 57 |
|
| 58 |
// create a string with spaces |
| 59 |
wxString packed; |
| 60 |
for(const CxxVariable::LexerToken& tok : type) { |
| 61 |
packed << tok.text << " "; |
| 62 |
} |
| 63 |
|
| 64 |
tokenizer.Reset(packed); |
| 65 |
wxString s; |
| 66 |
while(tokenizer.NextToken(token)) { |
| 67 |
if(s.empty() && (token.GetType() == T_CLASS || token.GetType() == T_STRUCT || token.GetType() == T_ENUM) && |
| 68 |
omitClassKeyword) |
| 69 |
continue; |
| 70 |
|
| 71 |
if(token.is_keyword() || token.is_builtin_type()) { |
| 72 |
s << token.GetWXString() << " "; |
| 73 |
} else if(token.is_pp_keyword()) { |
| 74 |
continue; |
| 75 |
} else { |
| 76 |
s << token.GetWXString(); |
| 77 |
} |
| 78 |
} |
| 79 |
return s.Trim(); |
| 80 |
} |