Debian Codegraph @

CodeLite/CxxExpression.hpp

raw
1 #ifndef CXXEXPRESSION_HPP
2 #define CXXEXPRESSION_HPP
3
4 #include "CxxTokenizer.h"
5 #include "codelite_exports.h"
6 #include "entry.h"
7 #include "macros.h"
8
9 #include <vector>
10 #include <wx/string.h>
11
12 /// A remainder is the part of an expression chain that was not processed.
13 /// Consider the following simple expression:
14 ///
15 /// std::string::size_
16 ///
17 /// Passing the above to CxxExpression::from_expression
18 /// and assuming that the it succeed, the mainder will be:
19 /// filter -> size_
20 /// operand_string -> "::"
21 struct WXDLLIMPEXP_CL CxxRemainder {
22 wxString filter;
23 wxString operand_string;
24 };
25
26 /// a class representing a single expression
27 /// in a longer chain of expressions
28 class WXDLLIMPEXP_CL CxxExpression
29 {
30 private:
31 wxString m_type_name;
32 wxArrayString m_scopes; // potential scopes for the type
33 int m_operand = 0;
34 wxString m_operand_string; // string representation for the operand
35 wxArrayString m_template_init_list; // template init list vector<wxString> -> `wxString`
36 wxArrayString m_template_placeholder_list; // template placeholders (e.g. `T`)
37 std::vector<wxArrayString> m_subscript_params; // subscript operator params
38 wxArrayString m_func_call_params; // function params
39 size_t m_flags = 0;
40
41 public:
42 enum eFlags {
43 FLAGS_NONE = 0,
44 FLAGS_AUTO = (1 << 0),
45 FLAGS_THIS = (1 << 1),
46 };
47
48 private:
49 static bool parse_template(CxxTokenizer& tokenizer, wxArrayString* init_list);
50 static bool parse_subscript(CxxTokenizer& tokenizer, wxArrayString* subscript_param);
51 static bool parse_func_call(CxxTokenizer& tokenizer, wxArrayString* func_call_params);
52 static bool parse_list(CxxTokenizer& tokenizer, wxArrayString* params, int open_char, int close_char);
53 static bool handle_cxx_casting(CxxTokenizer& tokenizer, wxString* cast_type);
54
55 public:
56 CxxExpression();
57 ~CxxExpression();
58
59 bool ok() const { return !m_type_name.empty() || m_operand != 0; }
60
61 /**
62 * set the operand for this expression
63 */
64 void set_operand(int op);
65
66 const wxString& type_name() const { return m_type_name; }
67 wxString& type_name() { return m_type_name; }
68
69 wxString template_placeholder_to_type(const wxString& placeholder) const;
70
71 /**
72 * @brief given a template definition line, parse and build the template placeholders list
73 * e.g. `template<typename Key, typename Value> class A {...}` -> we build the placeholders list `{"Key", "Value"}`
74 */
75 void parse_template_placeholders(const wxString& expr);
76
77 /**
78 * @brief reutn template placeholders map
79 */
80 wxStringMap_t get_template_placeholders_map() const;
81 /**
82 * @brief is this expression represents a template one?
83 */
84 bool is_template() const { return !m_template_init_list.empty(); }
85
86 const wxString& operand_string() const;
87 const wxArrayString& template_init_list() const { return m_template_init_list; }
88 const std::vector<wxArrayString>& subscript_params() const { return m_subscript_params; }
89 void set_subscript_params(const std::vector<wxArrayString>& params);
90 const wxArrayString& func_call_params() const { return m_func_call_params; }
91 bool is_auto() const { return m_flags & FLAGS_AUTO; }
92 bool is_this() const { return m_flags & FLAGS_THIS; }
93
94 /// example `subclass_pattern`:
95 /// `class ContextManager : public Singleton<ContextManager>, OtherClass, SecondClass<wxString, wxArrayString>`
96 /// returns:
97 /// {"Singleton<ContextManager>", "OtherClass", "SecondClass<wxString, wxArrayString>"}
98 static std::vector<wxString> split_subclass_expression(const wxString& subclass_pattern);
99 static std::vector<CxxExpression> from_expression(const wxString& expression, CxxRemainder* remainder);
100
101 /**
102 * should the code completion check for subscript operator overloading?
103 */
104 bool check_subscript_operator() const { return !m_subscript_params.empty(); }
105 void pop_subscript_operator()
106 {
107 if(!m_subscript_params.empty()) {
108 m_subscript_params.erase(m_subscript_params.begin());
109 }
110 }
111 };
112
113 #endif // CXXEXPRESSION_HPP