Debian Codegraph @

CodeLite/PHPDocVar.cpp

raw
1 #include "PHPDocVar.h"
2 #include <wx/regex.h>
3 #include <wx/tokenzr.h>
4
5 PHPDocVar::PHPDocVar(PHPSourceFile& sourceFile, const wxString& doc)
6 : m_isOk(false)
7 , m_dbId(wxNOT_FOUND)
8 , m_lineNumber(wxNOT_FOUND)
9 {
10 Parse(sourceFile, doc);
11 }
12
13 PHPDocVar::PHPDocVar()
14 : m_isOk(false)
15 , m_dbId(wxNOT_FOUND)
16 , m_lineNumber(wxNOT_FOUND)
17 {
18 }
19
20 PHPDocVar::~PHPDocVar() {}
21
22 void PHPDocVar::Parse(PHPSourceFile& sourceFile, const wxString& doc)
23 {
24 wxString sname;
25 wxString stype;
26 m_isOk = false;
27 wxStringTokenizer tokenizer(doc, " \n\r", wxTOKEN_STRTOK);
28
29 // @var Type $name
30 // @var Type
31 // @var $Name Type
32 if(!tokenizer.HasMoreTokens() || tokenizer.GetNextToken() != "@var") {
33 return;
34 }
35
36 // Next word should be the type
37 if(!tokenizer.HasMoreTokens()) {
38 return;
39 }
40 stype = tokenizer.GetNextToken();
41
42 // Next comes the name
43 if(tokenizer.HasMoreTokens()) {
44 sname = tokenizer.GetNextToken();
45 }
46
47 // Handle common developer mistake
48 if (stype.StartsWith("$")) {
49 sname.swap(stype);
50 }
51
52 // TODO Support nullable parameters
53 if (stype.StartsWith("?")) {
54 stype.Remove(0, 1);
55 }
56
57 // Got the type
58 m_type = sourceFile.MakeIdentifierAbsolute(stype);
59 m_isOk = true;
60
61 // Found the name
62 m_name = sname;
63 }
64
65 void PHPDocVar::Store(wxSQLite3Database& db, wxLongLong parentDdId)
66 {
67 try {
68 wxSQLite3Statement statement =
69 db.PrepareStatement("REPLACE INTO PHPDOC_VAR_TABLE (ID, SCOPE_ID, NAME, TYPE, LINE_NUMBER, FILE_NAME) "
70 "VALUES (NULL, :SCOPE_ID, :NAME, :TYPE, :LINE_NUMBER, :FILE_NAME)");
71
72 statement.Bind(statement.GetParamIndex(":SCOPE_ID"), parentDdId);
73 statement.Bind(statement.GetParamIndex(":NAME"), GetName());
74 statement.Bind(statement.GetParamIndex(":TYPE"), GetType());
75 statement.Bind(statement.GetParamIndex(":LINE_NUMBER"), GetLineNumber());
76 statement.Bind(statement.GetParamIndex(":FILE_NAME"), GetFilename().GetFullPath());
77 statement.ExecuteUpdate();
78 SetDbId(db.GetLastRowId());
79 } catch(wxSQLite3Exception& exc) {
80 wxUnusedVar(exc);
81 }
82 }
83
84 void PHPDocVar::FromResultSet(wxSQLite3ResultSet& res)
85 {
86 SetDbId(res.GetInt("ID"));
87 SetParentDbId(res.GetInt("SCOPE_ID"));
88 SetName(res.GetString("NAME"));
89 SetType(res.GetString("TYPE"));
90 SetLineNumber(res.GetInt("LINE_NUMBER"));
91 SetFilename(res.GetString("FILE_NAME"));
92 }