| 1 |
////////////////////////////////////////////////////////////////////////////// |
| 2 |
////////////////////////////////////////////////////////////////////////////// |
| 3 |
// |
| 4 |
// copyright : (C) 2008 by Eran Ifrah |
| 5 |
// file name : entry.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 |
#ifndef CODELITE_ENTRY_H |
| 26 |
#define CODELITE_ENTRY_H |
| 27 |
|
| 28 |
#if wxUSE_GUI |
| 29 |
#include <wx/treectrl.h> |
| 30 |
#endif |
| 31 |
|
| 32 |
#include "codelite_exports.h" |
| 33 |
#include "macros.h" |
| 34 |
#include "smart_ptr.h" |
| 35 |
|
| 36 |
#include <map> |
| 37 |
#include <vector> |
| 38 |
#include <wx/string.h> |
| 39 |
|
| 40 |
class TagEntry; |
| 41 |
typedef SmartPtr<TagEntry> TagEntryPtr; |
| 42 |
typedef std::vector<TagEntryPtr> TagEntryPtrVector_t; |
| 43 |
|
| 44 |
#define KIND_CLASS "class" |
| 45 |
#define KIND_ENUM "enum" |
| 46 |
#define KIND_CLASS_ENUM "cenum" |
| 47 |
#define KIND_ENUMERATOR "enumerator" |
| 48 |
#define KIND_FUNCTION "function" |
| 49 |
#define KIND_PROTOTYPE "prototype" |
| 50 |
#define KIND_MEMBER "member" |
| 51 |
#define KIND_NAMESPACE "namespace" |
| 52 |
#define KIND_VARIABLE "variable" |
| 53 |
#define KIND_UNION "union" |
| 54 |
#define KIND_TYPEDEF "typedef" |
| 55 |
#define KIND_MACRO "macro" |
| 56 |
#define KIND_STRUCT "struct" |
| 57 |
#define KIND_FILE "file" |
| 58 |
|
| 59 |
// make it public |
| 60 |
enum class eTagKind { |
| 61 |
TAG_KIND_UNKNOWN = -1, |
| 62 |
TAG_KIND_CLASS, |
| 63 |
TAG_KIND_STRUCT, |
| 64 |
TAG_KIND_NAMESPACE, |
| 65 |
TAG_KIND_UNION, |
| 66 |
TAG_KIND_ENUM, |
| 67 |
TAG_KIND_ENUMERATOR, |
| 68 |
TAG_KIND_CENUM, // class enum |
| 69 |
TAG_KIND_MEMBER, |
| 70 |
TAG_KIND_VARIABLE, |
| 71 |
TAG_KIND_MACRO, |
| 72 |
TAG_KIND_TYPEDEF, |
| 73 |
TAG_KIND_LOCAL, |
| 74 |
TAG_KIND_PARAMETER, // function parameter |
| 75 |
TAG_KIND_FUNCTION, |
| 76 |
TAG_KIND_PROTOTYPE, |
| 77 |
TAG_KIND_KEYWORD, |
| 78 |
}; |
| 79 |
|
| 80 |
/** |
| 81 |
* TagEntry is a persistent object which is capable of storing and loading itself from |
| 82 |
* various inputs: |
| 83 |
* - tagEntry (ctags structure) |
| 84 |
* |
| 85 |
* It contains all the knowledge of storing and retrieving itself from the database |
| 86 |
* |
| 87 |
* \ingroup CodeLite |
| 88 |
* \version 1.0 |
| 89 |
* first version |
| 90 |
* |
| 91 |
* \date 11-11-2006 |
| 92 |
* \author Eran |
| 93 |
*/ |
| 94 |
class WXDLLIMPEXP_CL TagEntry |
| 95 |
{ |
| 96 |
private: |
| 97 |
enum eTagFlag { |
| 98 |
TAG_PROP_CONST = (1 << 0), |
| 99 |
TAG_PROP_VIRTUAL = (1 << 2), |
| 100 |
TAG_PROP_STATIC = (1 << 3), |
| 101 |
TAG_PROP_DEFAULT = (1 << 4), |
| 102 |
TAG_PROP_OVERRIDE = (1 << 5), |
| 103 |
TAG_PROP_DELETED = (1 << 6), |
| 104 |
TAG_PROP_INLINE = (1 << 7), |
| 105 |
TAG_PROP_PURE = (1 << 8), |
| 106 |
TAG_PROP_SCOPEDENUM = (1 << 9), |
| 107 |
TAG_PROP_AUTO_VARIABLE = (1 << 10), |
| 108 |
TAG_PROP_LAMBDA = (1 << 11), |
| 109 |
}; |
| 110 |
|
| 111 |
private: |
| 112 |
wxString m_path; ///< Tag full path |
| 113 |
wxString m_file; ///< File this tag is found |
| 114 |
int m_lineNumber; ///< Line number |
| 115 |
wxString m_pattern; ///< A pattern that can be used to locate the tag in the file |
| 116 |
wxString m_kind; ///< Member, function, class, typedef etc. |
| 117 |
wxString m_parent; ///< Direct parent |
| 118 |
#if wxUSE_GUI |
| 119 |
wxTreeItemId m_hti; ///< Handle to tree item, not persistent item |
| 120 |
#endif |
| 121 |
wxString m_name; ///< Tag name (short name, excluding any scope names) |
| 122 |
wxStringMap_t m_extFields; ///< Additional extension fields |
| 123 |
long m_id; |
| 124 |
wxString m_scope; |
| 125 |
size_t m_flags; // This member is not saved into the database |
| 126 |
wxString m_comment; // This member is not saved into the database |
| 127 |
wxString m_template_definition; |
| 128 |
wxString m_tag_properties; |
| 129 |
size_t m_tag_properties_flags = 0; // bitwise eTagFlag |
| 130 |
eTagKind m_tag_kind = eTagKind::TAG_KIND_UNKNOWN; |
| 131 |
wxString m_assignment; |
| 132 |
|
| 133 |
public: |
| 134 |
enum { |
| 135 |
Tag_No_Signature_Format = 0x00000001, // Do not attempt to format the signature. Use the GetSignature() as is |
| 136 |
Tag_No_Return_Value_Eval = 0x00000002 // Do not evaluate the return value. Use GetReturnValue() instead |
| 137 |
}; |
| 138 |
|
| 139 |
// Used by std::for_each to copy elements which are constructors |
| 140 |
class ForEachCopyIfCtor |
| 141 |
{ |
| 142 |
TagEntryPtrVector_t& m_matches; |
| 143 |
|
| 144 |
public: |
| 145 |
ForEachCopyIfCtor(TagEntryPtrVector_t& v) |
| 146 |
: m_matches(v) |
| 147 |
{ |
| 148 |
} |
| 149 |
void operator()(TagEntryPtr tag) |
| 150 |
{ |
| 151 |
if(tag->IsConstructor()) { |
| 152 |
m_matches.push_back(tag); |
| 153 |
} |
| 154 |
} |
| 155 |
}; |
| 156 |
|
| 157 |
void set_extra_field(const wxString& name, const wxString& value); |
| 158 |
|
| 159 |
public: |
| 160 |
void SetComment(const wxString& comment) { this->m_comment = comment; } |
| 161 |
const wxString& GetComment() const { return m_comment; } |
| 162 |
void SetFlags(size_t flags) { this->m_flags = flags; } |
| 163 |
size_t GetFlags() const { return m_flags; } |
| 164 |
/** |
| 165 |
* Default constructor. |
| 166 |
*/ |
| 167 |
TagEntry(); |
| 168 |
|
| 169 |
void FromLine(const wxString& line); |
| 170 |
|
| 171 |
bool IsClassTemplate() const; |
| 172 |
wxString GetTemplateDefinition() const; |
| 173 |
|
| 174 |
// function properties |
| 175 |
bool is_func_virtual() const; |
| 176 |
bool is_func_default() const; |
| 177 |
bool is_func_override() const; |
| 178 |
bool is_func_deleted() const; |
| 179 |
bool is_func_inline() const; |
| 180 |
bool is_func_pure() const; |
| 181 |
bool is_const() const; |
| 182 |
bool is_static() const; |
| 183 |
bool is_scoped_enum() const; |
| 184 |
bool is_auto() const; |
| 185 |
bool is_lambda() const; |
| 186 |
const wxString& get_assigment() const { return m_assignment; } |
| 187 |
|
| 188 |
void SetTagProperties(const wxString& prop); |
| 189 |
const wxString& GetTagProperties() const { return m_tag_properties; } |
| 190 |
|
| 191 |
/** |
| 192 |
* @brief assuming this tag is a variable, return its rvalue |
| 193 |
* this is done by parsing the pattern |
| 194 |
*/ |
| 195 |
static wxString TypenameFromPattern(const TagEntry* tag); |
| 196 |
|
| 197 |
/** |
| 198 |
* @brief return true if this tag a local variable of type `auto` |
| 199 |
*/ |
| 200 |
static bool IsAuto(const TagEntry* tag); |
| 201 |
|
| 202 |
/** |
| 203 |
* @brief create a function signature (including return value + properties) |
| 204 |
* that could be used in a header file |
| 205 |
*/ |
| 206 |
wxString GetFunctionDeclaration() const; |
| 207 |
|
| 208 |
/** |
| 209 |
* @brief create a function signature that could be used in a definition file |
| 210 |
*/ |
| 211 |
wxString GetFunctionDefinition() const; |
| 212 |
|
| 213 |
/** |
| 214 |
* Copy constructor. |
| 215 |
*/ |
| 216 |
TagEntry(const TagEntry& rhs); |
| 217 |
|
| 218 |
/** |
| 219 |
* \param rhs Source to copy from (right hand side) |
| 220 |
* \return this |
| 221 |
*/ |
| 222 |
TagEntry& operator=(const TagEntry& rhs); |
| 223 |
|
| 224 |
/** |
| 225 |
* Compare two TagEntry objects. |
| 226 |
* \param rhs Right hand side |
| 227 |
* \return true if identical, false otherwise |
| 228 |
*/ |
| 229 |
bool operator==(const TagEntry& rhs); |
| 230 |
|
| 231 |
/** |
| 232 |
* Destructor |
| 233 |
*/ |
| 234 |
virtual ~TagEntry(); |
| 235 |
|
| 236 |
/** |
| 237 |
* @brief return if this tag entry is a function tempalte |
| 238 |
*/ |
| 239 |
bool IsTemplateFunction() const; |
| 240 |
|
| 241 |
/** |
| 242 |
* @brief is this a local variable? |
| 243 |
*/ |
| 244 |
bool IsLocalVariable() const; |
| 245 |
|
| 246 |
/** |
| 247 |
* Construct a TagEntry from values. |
| 248 |
* \param fileName File name |
| 249 |
* \param name Tag name |
| 250 |
* \param lineNumber Tag line number |
| 251 |
* \param pattern Pattern |
| 252 |
* \param kind Tag kind (class, struct, etc) |
| 253 |
* \param extFields Map of extenstion fields (key:value) |
| 254 |
* \param project Project name |
| 255 |
*/ |
| 256 |
void Create(const wxString& fileName, const wxString& name, int lineNumber, const wxString& pattern, |
| 257 |
const wxString& kind, wxStringMap_t& extFields); |
| 258 |
|
| 259 |
/** |
| 260 |
* Test if this entry has been initialised. |
| 261 |
* \return true if this tag entry has been initialised |
| 262 |
*/ |
| 263 |
const bool IsOk() const { return GetKind() != _T("<unknown>"); } |
| 264 |
|
| 265 |
/** |
| 266 |
* Test of this tag is a container (class, union, struct or namespace |
| 267 |
*/ |
| 268 |
const bool IsContainer() const; |
| 269 |
|
| 270 |
/** |
| 271 |
* @brief return true if this tag represents a constructor |
| 272 |
*/ |
| 273 |
bool IsConstructor() const; |
| 274 |
/** |
| 275 |
* @brief return true if this tag represents a destructor |
| 276 |
*/ |
| 277 |
bool IsDestructor() const; |
| 278 |
|
| 279 |
/** |
| 280 |
* @brief return true of the this tag is a function or prototype |
| 281 |
*/ |
| 282 |
bool IsMethod() const; |
| 283 |
|
| 284 |
bool IsFunction() const; |
| 285 |
bool IsPrototype() const; |
| 286 |
bool IsMacro() const; |
| 287 |
bool IsClass() const; |
| 288 |
bool IsStruct() const; |
| 289 |
bool IsScopeGlobal() const; |
| 290 |
bool IsTypedef() const; |
| 291 |
bool IsMember() const; |
| 292 |
bool IsNamespace() const; |
| 293 |
bool IsEnum() const; |
| 294 |
bool IsEnumClass() const; |
| 295 |
bool IsParameter() const; |
| 296 |
bool IsVariable() const; |
| 297 |
bool IsUnion() const; |
| 298 |
bool IsEnumerator() const; |
| 299 |
bool IsKeyword() const; |
| 300 |
|
| 301 |
//------------------------------------------ |
| 302 |
// Operations |
| 303 |
//------------------------------------------ |
| 304 |
int GetId() const { return m_id; } |
| 305 |
void SetId(int id) { m_id = id; } |
| 306 |
|
| 307 |
const wxString& GetName() const { return m_name; } |
| 308 |
void SetName(const wxString& name) { m_name = name; } |
| 309 |
|
| 310 |
const wxString& GetPath() const { return m_path; } |
| 311 |
void SetPath(const wxString& path) { m_path = path; } |
| 312 |
|
| 313 |
const wxString& GetFile() const { return m_file; } |
| 314 |
void SetFile(const wxString& file) { m_file = file; } |
| 315 |
|
| 316 |
int GetLine() const { return m_lineNumber; } |
| 317 |
void SetLine(int line) { m_lineNumber = line; } |
| 318 |
|
| 319 |
wxString GetPattern() const; |
| 320 |
/** |
| 321 |
* @brief return the entry pattern without the regex prefix/suffix |
| 322 |
*/ |
| 323 |
wxString GetPatternClean() const; |
| 324 |
|
| 325 |
void SetPattern(const wxString& pattern) { m_pattern = pattern; } |
| 326 |
|
| 327 |
wxString GetKind() const; |
| 328 |
void SetKind(const wxString& kind); |
| 329 |
|
| 330 |
const wxString& GetParent() const { return m_parent; } |
| 331 |
void SetParent(const wxString& parent) { m_parent = parent; } |
| 332 |
#if wxUSE_GUI |
| 333 |
wxTreeItemId& GetTreeItemId() { return m_hti; } |
| 334 |
void SetTreeItemId(wxTreeItemId& hti) { m_hti = hti; } |
| 335 |
#endif |
| 336 |
|
| 337 |
wxString GetAccess() const { return GetExtField(_T("access")); } |
| 338 |
void SetAccess(const wxString& access) { set_extra_field("access", access); } |
| 339 |
|
| 340 |
wxString GetSignature() const { return GetExtField(_T("signature")); } |
| 341 |
void SetSignature(const wxString& sig) { set_extra_field("signature", sig); } |
| 342 |
void SetInherits(const wxString& inherits) { set_extra_field("inherits", inherits); } |
| 343 |
|
| 344 |
wxString GetInheritsAsString() const; |
| 345 |
wxArrayString GetInheritsAsArrayNoTemplates() const; |
| 346 |
wxArrayString GetInheritsAsArrayWithTemplates() const; |
| 347 |
|
| 348 |
wxString GetTypename() const; |
| 349 |
wxString GetMacrodef() const; |
| 350 |
void SetTypename(const wxString& value); |
| 351 |
void SetMacrodef(const wxString& value); |
| 352 |
void SetTemplateDefinition(const wxString& def) { set_extra_field("template", def); } |
| 353 |
|
| 354 |
const wxString& GetScope() const { return m_scope; } |
| 355 |
void SetScope(const wxString& scope) { m_scope = scope; } |
| 356 |
|
| 357 |
/** |
| 358 |
* \return Scope name of the tag. |
| 359 |
* If path is empty in db or contains just the project name, it will return the literal <global>. |
| 360 |
* For project tags, an empty string is returned. |
| 361 |
*/ |
| 362 |
wxString GetScopeName() const; |
| 363 |
|
| 364 |
/** |
| 365 |
* Generate a Key for this tag based on its attributes |
| 366 |
* \return tag key |
| 367 |
*/ |
| 368 |
wxString Key() const; |
| 369 |
|
| 370 |
/** |
| 371 |
* @brief return the local variable type |
| 372 |
*/ |
| 373 |
wxString GetLocalType() const; |
| 374 |
|
| 375 |
/** |
| 376 |
* Generate a display name for this tag to be used by the symbol tree |
| 377 |
* \return tag display name |
| 378 |
*/ |
| 379 |
wxString GetDisplayName() const; |
| 380 |
|
| 381 |
/** |
| 382 |
* Generate a full display name for this tag that includes: |
| 383 |
* full scope + name + signature |
| 384 |
* \return tag full display name |
| 385 |
*/ |
| 386 |
wxString GetFullDisplayName() const; |
| 387 |
|
| 388 |
//------------------------------------------ |
| 389 |
// Extenstion fields |
| 390 |
//------------------------------------------ |
| 391 |
const wxString& GetExtField(const wxString& extField) const; |
| 392 |
|
| 393 |
//------------------------------------------ |
| 394 |
// Misc |
| 395 |
//------------------------------------------ |
| 396 |
void Print(); |
| 397 |
TagEntryPtr ReplaceSimpleMacro(); |
| 398 |
|
| 399 |
private: |
| 400 |
/** |
| 401 |
* Update the path with full path (e.g. namespace::class) |
| 402 |
* \param path path to add |
| 403 |
*/ |
| 404 |
void UpdatePath(wxString& path); |
| 405 |
}; |
| 406 |
|
| 407 |
#endif // CODELITE_ENTRY_H |