| 1 |
#ifndef CXXVARIABLESCANNER_H |
| 2 |
#define CXXVARIABLESCANNER_H |
| 3 |
|
| 4 |
#include "CxxLexerAPI.h" |
| 5 |
#include "CxxVariable.h" |
| 6 |
#include "codelite_exports.h" |
| 7 |
#include "macros.h" |
| 8 |
#include "wxStringHash.h" |
| 9 |
|
| 10 |
#include <stack> |
| 11 |
|
| 12 |
class WXDLLIMPEXP_CL CxxVariableScanner |
| 13 |
{ |
| 14 |
protected: |
| 15 |
Scanner_t m_scanner = nullptr; |
| 16 |
wxString m_buffer; |
| 17 |
bool m_eof = false; |
| 18 |
int m_parenthesisDepth = 0; |
| 19 |
std::unordered_set<int> m_nativeTypes; |
| 20 |
eCxxStandard m_standard = eCxxStandard::kCxx11; |
| 21 |
wxStringTable_t m_macros; |
| 22 |
std::vector<wxString> m_buffers; |
| 23 |
bool m_isFuncSignature = false; |
| 24 |
wxString m_optimized_buffer; |
| 25 |
bool m_buffer_optimized = false; |
| 26 |
|
| 27 |
protected: |
| 28 |
bool GetNextToken(CxxLexerToken& token); |
| 29 |
void UngetToken(const CxxLexerToken& token); |
| 30 |
bool IsEof() const { return m_eof; } |
| 31 |
bool TypeHasIdentifier(const CxxVariable::LexerToken::Vec_t& type); |
| 32 |
bool HasNativeTypeInList(const CxxVariable::LexerToken::Vec_t& type) const; |
| 33 |
|
| 34 |
wxString& Buffer(); |
| 35 |
wxString& PushBuffer(); |
| 36 |
wxString& PopBuffer(); |
| 37 |
|
| 38 |
bool OnForLoop(Scanner_t scanner, wxString& variable_definition); |
| 39 |
bool OnCatch(Scanner_t scanner); |
| 40 |
bool OnWhile(Scanner_t scanner); |
| 41 |
bool OnDeclType(Scanner_t scanner); |
| 42 |
bool SkipToClosingParenthesis(Scanner_t scanner); |
| 43 |
|
| 44 |
protected: |
| 45 |
/** |
| 46 |
* @brief read the variable type |
| 47 |
*/ |
| 48 |
bool ReadType(CxxVariable::LexerToken::Vec_t& vartype, bool& isAuto); |
| 49 |
/** |
| 50 |
* @brief read the variable name. Return true if there are more variables |
| 51 |
* for the current type |
| 52 |
*/ |
| 53 |
bool ReadName(wxString& varname, wxString& pointerOrRef, int& line_number, wxString& varInitialization); |
| 54 |
|
| 55 |
/** |
| 56 |
* @brief consume variable initialization |
| 57 |
*/ |
| 58 |
void ConsumeInitialization(wxString& consumed); |
| 59 |
|
| 60 |
int ReadUntil(const std::unordered_set<int>& delims, CxxLexerToken& token, wxString& consumed); |
| 61 |
|
| 62 |
CxxVariable::Vec_t DoGetVariables(const wxString& buffer, bool sort); |
| 63 |
CxxVariable::Vec_t DoParseFunctionArguments(const wxString& buffer); |
| 64 |
|
| 65 |
void DoOptimizeBuffer(); |
| 66 |
|
| 67 |
/** |
| 68 |
* @brief move the scanner until we find the closing parenthesis `)` |
| 69 |
* @param scanner |
| 70 |
* @return true if found, false, when reached EOF |
| 71 |
*/ |
| 72 |
bool skip_parenthesis_block(Scanner_t scanner); |
| 73 |
|
| 74 |
/** |
| 75 |
* @brief move the scanner until we find the closing parenthesis `}` |
| 76 |
* @param scanner |
| 77 |
* @return true if found, false, when reached EOF |
| 78 |
*/ |
| 79 |
bool skip_curly_brackets_block(Scanner_t scanner); |
| 80 |
|
| 81 |
public: |
| 82 |
CxxVariableScanner(const wxString& buffer, eCxxStandard standard, const wxStringTable_t& macros, |
| 83 |
bool isFuncSignature); |
| 84 |
virtual ~CxxVariableScanner(); |
| 85 |
|
| 86 |
/** |
| 87 |
* @brief helper method to join variable type into a single string |
| 88 |
*/ |
| 89 |
static wxString ToString(CxxVariable::LexerToken::Vec_t& vartype); |
| 90 |
|
| 91 |
/** |
| 92 |
* @brief return the optimized buffer |
| 93 |
*/ |
| 94 |
const wxString& GetOptimizeBuffer() const { return m_optimized_buffer; } |
| 95 |
|
| 96 |
/** |
| 97 |
* @brief return the variables from the optimized buffer |
| 98 |
* @return |
| 99 |
*/ |
| 100 |
CxxVariable::Vec_t GetVariables(bool sort = true); |
| 101 |
|
| 102 |
/** |
| 103 |
* @brief parse the buffer and return list of variables |
| 104 |
* @return |
| 105 |
*/ |
| 106 |
CxxVariable::Vec_t ParseFunctionArguments(); |
| 107 |
|
| 108 |
/** |
| 109 |
* @brief parse the buffer and return a unique set of variables |
| 110 |
*/ |
| 111 |
CxxVariable::Map_t GetVariablesMap(); |
| 112 |
}; |
| 113 |
|
| 114 |
#endif // CXXVARIABLESCANNER_H |