Debian Codegraph @

CodeLite/PHPExpression.h

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // Copyright : (C) 2015 Eran Ifrah
5 // File name : PHPExpression.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 PHPEXPRESSION_H
27 #define PHPEXPRESSION_H
28
29 #include "codelite_exports.h"
30 #include <wx/string.h>
31 #include "PhpLexerAPI.h"
32 #include <list>
33 #include "PHPSourceFile.h"
34 #include "PHPLookupTable.h"
35
36 class WXDLLIMPEXP_CL PHPExpression
37 {
38 public:
39 enum eType {
40 kNone = -1,
41 kThis,
42 kSelf,
43 kStatic,
44 };
45 struct Part {
46 wxString m_text;
47 int m_operator;
48 int m_textType;
49 wxString m_operatorText;
50
51 Part()
52 : m_operator(kPHP_T_OBJECT_OPERATOR)
53 , m_textType(wxNOT_FOUND)
54 {
55 }
56 };
57 typedef std::list<PHPExpression::Part> List_t;
58 typedef wxSharedPtr<PHPExpression> Ptr_t;
59
60 protected:
61 eType m_type;
62 wxString m_text;
63 phpLexerToken::Vet_t m_expression;
64 PHPExpression::List_t m_parts;
65 wxString m_filter; // Part of the word that was typed by the user
66 // but will do no good to resolve the expression
67 PHPSourceFile::Ptr_t m_sourceFile;
68 bool m_functionCalltipExpr;
69 bool m_exprStartsWithOpenTag;
70
71 protected:
72 wxString DoSimplifyExpression(int depth, PHPSourceFile::Ptr_t sourceFile);
73 /**
74 * @brief make 'matches' a unique list by removing duplicates
75 */
76 void DoMakeUnique(PHPEntityBase::List_t& matches);
77
78 protected:
79 phpLexerToken::Vet_t CreateExpression(const wxString& text);
80 /**
81 * @brief fix the return value full path
82 */
83 bool FixReturnValueNamespace(
84 PHPLookupTable& lookup, PHPEntityBase::Ptr_t parent, const wxString& classFullpath, wxString& fixedpath);
85
86 public:
87 PHPExpression(const wxString& fulltext, const wxString& exprText = wxString(), bool functionCalltipExpr = false);
88 virtual ~PHPExpression();
89
90 const phpLexerToken::Vet_t& GetExpression() const { return m_expression; }
91 /**
92 * @brief return the parse expression as string. Useful for debuggin purposes
93 */
94 wxString GetExpressionAsString() const;
95
96 /**
97 * @brief suggest matches for this expression.
98 * This function must be called after a successfull call to 'Resolve'
99 * @param resolved the resolved object from the previous call to 'Resolve'
100 * @param matches [output]
101 */
102 void Suggest(PHPEntityBase::Ptr_t resolved, PHPLookupTable& lookup, PHPEntityBase::List_t& matches);
103
104 /**
105 * @brief return true of the token before the expression is "<?"
106 */
107 bool IsExprStartsWithOpenTag() const { return m_exprStartsWithOpenTag; }
108
109 /**
110 * @brief return the elements count in the expression.
111 * For example:
112 * $a->foo()->bar()->b // Code complete here
113 * will return 3 ($a, foo, bar)
114 */
115 size_t GetCount() const { return m_parts.size(); }
116
117 /**
118 * @brief return the source file used to create and parse this expression
119 */
120 PHPSourceFile::Ptr_t GetSourceFile() { return m_sourceFile; }
121
122 /**
123 * @brief resolve the expression and return the entity of the last part
124 * of the expression
125 */
126 PHPEntityBase::Ptr_t Resolve(PHPLookupTable& lookpTable, const wxString& sourceFileName);
127 /**
128 * @brief return the filter for this expression
129 */
130 const wxString& GetFilter() const { return m_filter; }
131
132 /**
133 * @brief get the lookup flags to pass to the lookup table for feteching members
134 */
135 size_t GetLookupFlags() const;
136 };
137
138 #endif // PHPEXPRESSION_H