File: PHPEntityVariable.cpp

package info (click to toggle)
codelite 17.0.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 136,244 kB
  • sloc: cpp: 491,547; ansic: 280,393; php: 10,259; sh: 8,930; lisp: 7,664; vhdl: 6,518; python: 6,020; lex: 4,920; yacc: 3,123; perl: 2,385; javascript: 1,715; cs: 1,193; xml: 1,110; makefile: 804; cobol: 741; sql: 709; ruby: 620; f90: 566; ada: 534; asm: 464; fortran: 350; objc: 289; tcl: 258; java: 157; erlang: 61; pascal: 51; ml: 49; awk: 44; haskell: 36
file content (201 lines) | stat: -rw-r--r-- 6,247 bytes parent folder | download | duplicates (2)
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include "PHPEntityVariable.h"
#include "PHPScannerTokens.h"
#include "PHPEntityFunction.h"
#include "PHPEntityClass.h"
#include "PHPLookupTable.h"

PHPEntityVariable::PHPEntityVariable() {}

PHPEntityVariable::~PHPEntityVariable() {}

void PHPEntityVariable::PrintStdout(int indent) const
{
    wxString indentString(' ', indent);
    wxPrintf("%s%s: %s", indentString, IsMember() ? "Member" : "Variable", GetShortName());
    if(!GetTypeHint().IsEmpty()) {
        wxPrintf(", TypeHint: %s", GetTypeHint());
    }
    if(!GetExpressionHint().IsEmpty()) {
        wxPrintf(", ExpressionHint: %s", GetExpressionHint());
    }
    if(IsReference()) {
        wxPrintf(", Reference");
    }
    if(!GetDefaultValue().IsEmpty()) {
        wxPrintf(", Default: %s", GetDefaultValue());
    }

    wxPrintf(", Ln. %d", GetLine());
    wxPrintf("\n");

    PHPEntityBase::List_t::const_iterator iter = m_children.begin();
    for(; iter != m_children.end(); ++iter) {
        (*iter)->PrintStdout(indent + 4);
    }
}

void PHPEntityVariable::SetVisibility(int visibility)
{
    switch(visibility) {
    case kPHP_T_PUBLIC:
        m_flags &= ~kVar_Private;
        m_flags &= ~kVar_Protected;
        m_flags |= kVar_Public;
        break;
    case kPHP_T_PROTECTED:
        m_flags &= ~kVar_Private;
        m_flags &= ~kVar_Public;
        m_flags |= kVar_Protected;
        break;
    case kPHP_T_PRIVATE:
        m_flags &= ~kVar_Public;
        m_flags &= ~kVar_Protected;
        m_flags |= kVar_Private;
        break;
    default:
        break;
    }
}

wxString PHPEntityVariable::ToFuncArgString() const
{
    if(!IsFunctionArg()) {
        return "";
    }

    wxString str;
    if(!GetTypeHint().IsEmpty()) {
        if(IsNullable()) {
            str << "?";
        }
        str << GetTypeHint() << " ";
    }

    if(IsReference()) {
        str << "&";
    }

    str << GetShortName();
    if(!GetDefaultValue().IsEmpty()) {
        str << " = " << GetDefaultValue();
    }
    return str;
}
void PHPEntityVariable::Store(PHPLookupTable* lookup)
{
    if(IsFunctionArg() || IsMember() || IsDefine()) {
        try {
            wxSQLite3Database& db = lookup->Database();
            wxSQLite3Statement statement = db.PrepareStatement(
                "INSERT OR REPLACE INTO VARIABLES_TABLE VALUES (NULL, "
                ":SCOPE_ID, :FUNCTION_ID, :NAME, :FULLNAME, :SCOPE, :TYPEHINT, :DEFAULT_VALUE, "
                ":FLAGS, :DOC_COMMENT, :LINE_NUMBER, :FILE_NAME)");
            wxLongLong functionId, scopeId;
            if(IsFunctionArg()) {
                functionId = Parent()->GetDbId();
            } else {
                functionId = -1;
            }

            if(IsMember() || IsDefine()) {
                scopeId = Parent()->GetDbId();
            } else {
                scopeId = -1;
            }
            statement.Bind(statement.GetParamIndex(":SCOPE_ID"), scopeId);
            statement.Bind(statement.GetParamIndex(":FUNCTION_ID"), functionId);
            statement.Bind(statement.GetParamIndex(":NAME"), GetShortName());
            statement.Bind(statement.GetParamIndex(":FULLNAME"), GetFullName());
            statement.Bind(statement.GetParamIndex(":SCOPE"), GetScope());
            statement.Bind(statement.GetParamIndex(":TYPEHINT"), GetTypeHint());
            statement.Bind(statement.GetParamIndex(":DEFAULT_VALUE"), GetDefaultValue());
            statement.Bind(statement.GetParamIndex(":FLAGS"), (int)GetFlags());
            statement.Bind(statement.GetParamIndex(":DOC_COMMENT"), GetDocComment());
            statement.Bind(statement.GetParamIndex(":LINE_NUMBER"), GetLine());
            statement.Bind(statement.GetParamIndex(":FILE_NAME"), GetFilename().GetFullPath());
            statement.ExecuteUpdate();
            SetDbId(db.GetLastRowId());

        } catch(wxSQLite3Exception& exc) {
            wxUnusedVar(exc);
        }
    }
}

void PHPEntityVariable::FromResultSet(wxSQLite3ResultSet& res)
{
    SetDbId(res.GetInt("ID"));
    SetFullName(res.GetString("FULLNAME"));
    SetShortName(res.GetString("NAME"));
    SetTypeHint(res.GetString("TYPEHINT"));
    SetFlags(res.GetInt("FLAGS"));
    SetDocComment(res.GetString("DOC_COMMENT"));
    SetLine(res.GetInt("LINE_NUMBER"));
    SetFilename(res.GetString("FILE_NAME"));
    SetDefaultValue(res.GetString("DEFAULT_VALUE"));
}

wxString PHPEntityVariable::GetScope() const
{
    PHPEntityBase* parent = Parent();
    if(parent && parent->Is(kEntityTypeFunction) && IsFunctionArg()) {
        return parent->Cast<PHPEntityFunction>()->GetScope();

    } else if(parent && parent->Is(kEntityTypeClass) && IsMember()) {
        return parent->GetFullName();

    } else if(parent && parent->Is(kEntityTypeNamespace) && IsDefine()) {
        return parent->GetFullName();

    } else {
        return "";
    }
}

wxString PHPEntityVariable::Type() const { return GetTypeHint(); }
bool PHPEntityVariable::Is(eEntityType type) const { return type == kEntityTypeVariable; }
wxString PHPEntityVariable::GetDisplayName() const { return GetFullName(); }

wxString PHPEntityVariable::GetNameNoDollar() const
{
    wxString name = GetShortName();
    if(name.StartsWith("$")) {
        name.Remove(0, 1);
    }
    name.Trim().Trim(false);
    return name;
}
wxString PHPEntityVariable::FormatPhpDoc(const CommentConfigData& data) const
{
    wxString doc;
    doc << data.GetCommentBlockPrefix() << "\n"
        << " * @var " << GetTypeHint() << "\n"
        << " */";
    return doc;
}

wxString PHPEntityVariable::ToTooltip() const
{
    if(IsConst() && !GetDefaultValue().IsEmpty()) {
        return GetDefaultValue();
    } else {
        return wxEmptyString;
    }
}

void PHPEntityVariable::FromJSON(const JSONItem& json)
{
    BaseFromJSON(json);
    m_typeHint = json.namedObject("type-hint").toString();
    m_expressionHint = json.namedObject("expr-hint").toString();
    m_defaultValue = json.namedObject("defaultValue").toString();
}

JSONItem PHPEntityVariable::ToJSON() const
{
    JSONItem json = BaseToJSON("v"); // type variable
    json.addProperty("type-hint", m_typeHint);
    json.addProperty("expr-hint", m_expressionHint);
    json.addProperty("defaultValue", m_defaultValue);
    return json;
}