File: PHPExpression.h

package info (click to toggle)
codelite 12.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 95,112 kB
  • sloc: cpp: 424,040; ansic: 18,284; php: 9,569; lex: 4,186; yacc: 2,820; python: 2,294; sh: 312; makefile: 51; xml: 13
file content (138 lines) | stat: -rw-r--r-- 4,530 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// Copyright            : (C) 2015 Eran Ifrah
// File name            : PHPExpression.h
//
// -------------------------------------------------------------------------
// A
//              _____           _      _     _ _
//             /  __ \         | |    | |   (_) |
//             | /  \/ ___   __| | ___| |    _| |_ ___
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
//              \____/\___/ \__,_|\___\_____/_|\__\___|
//
//                                                  F i l e
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

#ifndef PHPEXPRESSION_H
#define PHPEXPRESSION_H

#include "codelite_exports.h"
#include <wx/string.h>
#include "PhpLexerAPI.h"
#include <list>
#include "PHPSourceFile.h"
#include "PHPLookupTable.h"

class WXDLLIMPEXP_CL PHPExpression
{
public:
    enum eType {
        kNone = -1,
        kThis,
        kSelf,
        kStatic,
    };
    struct Part {
        wxString m_text;
        int m_operator;
        int m_textType;
        wxString m_operatorText;

        Part()
            : m_operator(kPHP_T_OBJECT_OPERATOR)
            , m_textType(wxNOT_FOUND)
        {
        }
    };
    typedef std::list<PHPExpression::Part> List_t;
    typedef wxSharedPtr<PHPExpression> Ptr_t;

protected:
    eType m_type;
    wxString m_text;
    phpLexerToken::Vet_t m_expression;
    PHPExpression::List_t m_parts;
    wxString m_filter; // Part of the word that was typed by the user
                       // but will do no good to resolve the expression
    PHPSourceFile::Ptr_t m_sourceFile;
    bool m_functionCalltipExpr;
    bool m_exprStartsWithOpenTag;

protected:
    wxString DoSimplifyExpression(int depth, PHPSourceFile::Ptr_t sourceFile);
    /**
     * @brief make 'matches' a unique list by removing duplicates
     */
    void DoMakeUnique(PHPEntityBase::List_t& matches);

protected:
    phpLexerToken::Vet_t CreateExpression(const wxString& text);
    /**
     * @brief fix the return value full path
     */
    bool FixReturnValueNamespace(
        PHPLookupTable& lookup, PHPEntityBase::Ptr_t parent, const wxString& classFullpath, wxString& fixedpath);

public:
    PHPExpression(const wxString& fulltext, const wxString& exprText = wxString(), bool functionCalltipExpr = false);
    virtual ~PHPExpression();

    const phpLexerToken::Vet_t& GetExpression() const { return m_expression; }
    /**
     * @brief return the parse expression as string. Useful for debuggin purposes
     */
    wxString GetExpressionAsString() const;

    /**
     * @brief suggest matches for this expression.
     * This function must be called after a successfull call to 'Resolve'
     * @param resolved the resolved object from the previous call to 'Resolve'
     * @param matches [output]
     */
    void Suggest(PHPEntityBase::Ptr_t resolved, PHPLookupTable& lookup, PHPEntityBase::List_t& matches);
    
    /**
     * @brief return true of the token before the expression is "<?"
     */
    bool IsExprStartsWithOpenTag() const { return m_exprStartsWithOpenTag; }
    
    /**
     * @brief return the elements count in the expression.
     * For example:
     * $a->foo()->bar()->b // Code complete here
     * will return 3 ($a, foo, bar)
     */
    size_t GetCount() const { return m_parts.size(); }

    /**
     * @brief return the source file used to create and parse this expression
     */
    PHPSourceFile::Ptr_t GetSourceFile() { return m_sourceFile; }

    /**
     * @brief resolve the expression and return the entity of the last part
     * of the expression
     */
    PHPEntityBase::Ptr_t Resolve(PHPLookupTable& lookpTable, const wxString& sourceFileName);
    /**
     * @brief return the filter for this expression
     */
    const wxString& GetFilter() const { return m_filter; }

    /**
     * @brief get the lookup flags to pass to the lookup table for feteching members
     */
    size_t GetLookupFlags() const;
};

#endif // PHPEXPRESSION_H