Debian Codegraph @

CodeLite/PHPEntityBase.h

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // Copyright : (C) 2015 Eran Ifrah
5 // File name : PHPEntityBase.h
6 //
7 // -------------------------------------------------------------------------
8 // A
9 // _____ _ _ _ _
10 // / __ \ | | | | (_) |
11 // | / \/ ___ __| | ___| | _| |_ ___
12 // | | / _ \ / _ |/ _ \ | | | __/ _ )
13 // | \__/\ (_) | (_| | __/ |___| | || __/
14 // \____/\___/ \__,_|\___\_____/_|\__\___|
15 //
16 // F i l e
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 //////////////////////////////////////////////////////////////////////////////
24 //////////////////////////////////////////////////////////////////////////////
25
26 #ifndef PHPENTITYIMPL_H
27 #define PHPENTITYIMPL_H
28
29 #include "codelite_exports.h"
30 #include <wx/sharedptr.h>
31 #include <list>
32 #include <map>
33 #include <wx/string.h>
34 #include <iostream>
35 #include <wx/filename.h>
36 #include "wx/wxsqlite3.h"
37 #include <wx/wxcrtvararg.h> // Needed for wxPrintf
38 #include "smart_ptr.h"
39 #include <set>
40 #include "commentconfigdata.h"
41 #include "wxStringHash.h"
42 #include "JSON.h"
43
44 // The entity type
45 class WXDLLIMPEXP_CL PHPLookupTable;
46 enum eEntityType {
47 kEntityTypeVariable = 0,
48 kEntityTypeFunction = 1,
49 kEntityTypeClass = 2,
50 kEntityTypeNamespace = 3,
51 kEntityTypeKeyword = 4,
52 kEntityTypeFunctionAlias = 5,
53 };
54
55 // Variable flags
56 enum {
57 kVar_Public = (1 << 1),
58 kVar_Private = (1 << 2),
59 kVar_Protected = (1 << 3),
60 kVar_Member = (1 << 4),
61 kVar_Reference = (1 << 5),
62 kVar_Const = (1 << 6),
63 kVar_FunctionArg = (1 << 7),
64 kVar_Static = (1 << 8),
65 kVar_Define = (1 << 9),
66 kVar_Nullable = (1 << 10),
67 };
68
69 // Function flags
70 enum {
71 kFunc_Public = (1 << 1),
72 kFunc_Private = (1 << 2),
73 kFunc_Protected = (1 << 3),
74 kFunc_Final = (1 << 4),
75 kFunc_Static = (1 << 5),
76 kFunc_Abstract = (1 << 6),
77 kFunc_ReturnReference = (1 << 7),
78 kFunc_ReturnNullable = (1 << 8),
79 };
80
81 // Class flags
82 enum {
83 kClass_Interface = (1 << 1),
84 kClass_Trait = (1 << 2),
85 kClass_Abstract = (1 << 3),
86 };
87
88 class WXDLLIMPEXP_CL PHPEntityBase
89 {
90 public:
91 typedef SmartPtr<PHPEntityBase> Ptr_t;
92 typedef std::vector<PHPEntityBase::Ptr_t> List_t;
93 typedef std::unordered_map<wxString, PHPEntityBase::Ptr_t> Map_t;
94
95 protected:
96 PHPEntityBase::Map_t m_childrenMap;
97 PHPEntityBase::List_t m_children;
98 PHPEntityBase* m_parent;
99 wxFileName m_filename;
100 int m_line;
101 int m_column;
102 wxString m_fullname;
103 wxString m_shortName;
104 wxString m_docComment;
105 size_t m_flags;
106
107 // The database identifier
108 wxLongLong m_dbId;
109
110 protected:
111 JSONItem BaseToJSON(const wxString& entityType) const;
112 void BaseFromJSON(const JSONItem& json);
113
114 public:
115 PHPEntityBase();
116 virtual ~PHPEntityBase(){};
117
118 const PHPEntityBase::List_t& GetChildren() const { return m_children; }
119 PHPEntityBase* Parent() const { return m_parent; }
120 /**
121 * @brief set this entity children
122 */
123 void SetChildren(const PHPEntityBase::List_t& children);
124
125 /**
126 * @brief search for child in the children list of this entity.
127 * Optionally, you can request to search for a child with or without the dollar "$" sign
128 */
129 PHPEntityBase::Ptr_t FindChild(const wxString& name, bool tryPrependingDollar = false) const;
130
131 /**
132 * @brief generate a php doc comment that matches this entry
133 */
134 virtual wxString FormatPhpDoc(const CommentConfigData& data) const = 0;
135
136 /**
137 * @brief serialization to JSON
138 */
139 virtual JSONItem ToJSON() const = 0;
140 /**
141 * @brief serialization from JSON
142 */
143 virtual void FromJSON(const JSONItem& json) = 0;
144
145 // Setters / Getters
146 void SetFlag(size_t flag, bool b = true) { b ? this->m_flags |= flag : this->m_flags &= ~flag; }
147 bool HasFlag(size_t flag) const { return m_flags & flag; }
148 size_t GetFlags() const { return m_flags; }
149 void SetFlags(size_t flags) { this->m_flags = flags; }
150 void SetDocComment(const wxString& docComment) { this->m_docComment = docComment; }
151 const wxString& GetDocComment() const { return m_docComment; }
152 void SetDbId(wxLongLong dbId) { this->m_dbId = dbId; }
153 wxLongLong GetDbId() const { return m_dbId; }
154 void SetColumn(int column) { this->m_column = column; }
155 void SetFilename(const wxFileName& filename) { this->m_filename = filename; }
156 void SetLine(int line) { this->m_line = line; }
157 int GetColumn() const { return m_column; }
158 const wxFileName& GetFilename() const { return m_filename; }
159 int GetLine() const { return m_line; }
160
161 // Fullname, including the namespace prefix
162 void SetFullName(const wxString& fullname);
163 const wxString& GetFullName() const { return m_fullname; }
164
165 // Short name (usually, this is the last part after the namespace separator)
166 void SetShortName(const wxString& shortName) { this->m_shortName = shortName; }
167 const wxString& GetShortName() const { return m_shortName; }
168
169 /**
170 * @brief recursive print to stdout this object and all its children
171 * @param parent
172 */
173 void RecursivePrintStdout(PHPEntityBase::Ptr_t parent, int indent);
174
175 /**
176 * @brief print this object to the stdout
177 */
178 virtual void PrintStdout(int indent) const = 0;
179
180 /**
181 * @brief convert this object into a string tooltip
182 */
183 virtual wxString ToTooltip() const { return wxEmptyString; }
184
185 /**
186 * @brief return a nicely formatted string to display for this
187 * entity, mainly used for UI purposes
188 */
189 virtual wxString GetDisplayName() const = 0;
190
191 /**
192 * @brief return the actual type that this entity deduced to.
193 * + class: the return value is the fullpath of the class
194 * + namespace: it will be the fullpath of the namespace
195 * + function: return the return value type
196 * + variable: the typehint
197 * @return
198 */
199 virtual wxString Type() const = 0;
200
201 /**
202 * @brief return the underlying type of this instance
203 */
204 virtual bool Is(eEntityType type) const = 0;
205
206 /**
207 * @brief add a child to this scope
208 */
209 void AddChild(PHPEntityBase::Ptr_t child);
210
211 /**
212 * @brief remove a child
213 */
214 void RemoveChild(PHPEntityBase::Ptr_t child);
215
216 /**
217 * @brief convert this base class to its concrete
218 * @return
219 */
220 template <typename T> T* Cast() const { return dynamic_cast<T*>(const_cast<PHPEntityBase*>(this)); }
221
222 /**
223 * @brief store this object and all its children into the database
224 * @param db
225 */
226 virtual void Store(PHPLookupTable* lookup) = 0;
227
228 /**
229 * @brief construct this instance from a sqlite3 result set
230 */
231 virtual void FromResultSet(wxSQLite3ResultSet& res) = 0;
232
233 /**
234 * @brief store this entry and all its children
235 */
236 void StoreRecursive(PHPLookupTable* lookup);
237 };
238 #endif // PHPENTITYIMPL_H