Changeset View
Changeset View
Standalone View
Standalone View
addons/symbolviewer/php_parser.cpp
Show First 20 Lines • Show All 81 Lines • ▼ Show 20 Line(s) | 23 | { | |||
---|---|---|---|---|---|
82 | QRegExp functionRegExp(QLatin1String("^((public|protected|private)?(\\s*static)?\\s+)?function\\s+&?\\s*([\\w_][\\w\\d_]*)\\s*(.*)$"), Qt::CaseInsensitive); | 82 | QRegExp functionRegExp(QLatin1String("^((public|protected|private)?(\\s*static)?\\s+)?function\\s+&?\\s*([\\w_][\\w\\d_]*)\\s*(.*)$"), Qt::CaseInsensitive); | ||
83 | // variables: http://www.php.net/manual/en/language.oop5.properties.php | 83 | // variables: http://www.php.net/manual/en/language.oop5.properties.php | ||
84 | QRegExp varRegExp(QLatin1String("^((var|public|protected|private)?(\\s*static)?\\s+)?\\$([\\w_][\\w\\d_]*)"), Qt::CaseInsensitive); | 84 | QRegExp varRegExp(QLatin1String("^((var|public|protected|private)?(\\s*static)?\\s+)?\\$([\\w_][\\w\\d_]*)"), Qt::CaseInsensitive); | ||
85 | 85 | | |||
86 | // function args detection: “function a($b, $c=null)” => “$b, $v” | 86 | // function args detection: “function a($b, $c=null)” => “$b, $v” | ||
87 | QRegExp functionArgsRegExp(QLatin1String("(\\$[\\w_]+)"), Qt::CaseInsensitive); | 87 | QRegExp functionArgsRegExp(QLatin1String("(\\$[\\w_]+)"), Qt::CaseInsensitive); | ||
88 | QStringList functionArgsList; | 88 | QStringList functionArgsList; | ||
89 | QString functionArgs; | 89 | QString functionArgs; | ||
90 | QString nameWithTypes; | ||||
90 | 91 | | |||
91 | // replace literals by empty strings: “function a($b='nothing', $c="pretty \"cool\" string")” => “function ($b='', $c="")” | 92 | // replace literals by empty strings: “function a($b='nothing', $c="pretty \"cool\" string")” => “function ($b='', $c="")” | ||
92 | QRegExp literalRegExp(QLatin1String("([\"'])(?:\\\\.|[^\\\\])*\\1")); | 93 | QRegExp literalRegExp(QLatin1String("([\"'])(?:\\\\.|[^\\\\])*\\1")); | ||
93 | literalRegExp.setMinimal(true); | 94 | literalRegExp.setMinimal(true); | ||
94 | // remove useless comments: “public/* static */ function a($b, $c=null) /* test */” => “public function a($b, $c=null)” | 95 | // remove useless comments: “public/* static */ function a($b, $c=null) /* test */” => “public function a($b, $c=null)” | ||
95 | QRegExp blockCommentInline(QLatin1String("/\\*.*\\*/")); | 96 | QRegExp blockCommentInline(QLatin1String("/\\*.*\\*/")); | ||
96 | blockCommentInline.setMinimal(true); | 97 | blockCommentInline.setMinimal(true); | ||
97 | 98 | | |||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Line(s) | 200 | { | |||
205 | lastClassNode = node; | 206 | lastClassNode = node; | ||
206 | } | 207 | } | ||
207 | else | 208 | else | ||
208 | { | 209 | { | ||
209 | node = new QTreeWidgetItem(m_symbols); | 210 | node = new QTreeWidgetItem(m_symbols); | ||
210 | } | 211 | } | ||
211 | if (isClass) | 212 | if (isClass) | ||
212 | { | 213 | { | ||
213 | if (m_plugin->typesOn && !classRegExp.cap(1).trimmed().isEmpty() && !classRegExp.cap(4).trimmed().isEmpty()) | 214 | if (m_plugin->typesOn) { | ||
215 | if (!classRegExp.cap(1).trimmed().isEmpty() && !classRegExp.cap(4).trimmed().isEmpty()) | ||||
214 | { | 216 | { | ||
215 | node->setText(0, classRegExp.cap(3)+QLatin1String(" [")+classRegExp.cap(1).trimmed()+QLatin1Char(',')+classRegExp.cap(4).trimmed()+QLatin1Char(']')); | 217 | nameWithTypes = classRegExp.cap(3)+QLatin1String(" [")+classRegExp.cap(1).trimmed()+QLatin1Char(',')+classRegExp.cap(4).trimmed()+QLatin1Char(']'); | ||
216 | } | 218 | } | ||
217 | else if (m_plugin->typesOn && !classRegExp.cap(1).trimmed().isEmpty()) | 219 | else if (!classRegExp.cap(1).trimmed().isEmpty()) | ||
218 | { | 220 | { | ||
219 | node->setText(0, classRegExp.cap(3)+QLatin1String(" [")+classRegExp.cap(1).trimmed()+QLatin1Char(']')); | 221 | nameWithTypes = classRegExp.cap(3)+QLatin1String(" [")+classRegExp.cap(1).trimmed()+QLatin1Char(']'); | ||
220 | } | 222 | } | ||
221 | else if (m_plugin->typesOn && !classRegExp.cap(4).trimmed().isEmpty()) | 223 | else if (!classRegExp.cap(4).trimmed().isEmpty()) | ||
222 | { | 224 | { | ||
223 | node->setText(0, classRegExp.cap(3)+QLatin1String(" [")+classRegExp.cap(4).trimmed()+QLatin1Char(']')); | 225 | nameWithTypes = classRegExp.cap(3)+QLatin1String(" [")+classRegExp.cap(4).trimmed()+QLatin1Char(']'); | ||
226 | } | ||||
227 | node->setText(0, nameWithTypes); | ||||
224 | } | 228 | } | ||
225 | else | 229 | else | ||
226 | { | 230 | { | ||
227 | node->setText(0, classRegExp.cap(3)); | 231 | node->setText(0, classRegExp.cap(3)); | ||
228 | } | 232 | } | ||
229 | } | 233 | } | ||
230 | else | 234 | else | ||
231 | { | 235 | { | ||
232 | if (m_plugin->typesOn) | 236 | if (m_plugin->typesOn) | ||
233 | { | 237 | { | ||
234 | node->setText(0, interfaceRegExp.cap(1) + QLatin1String(" [interface]")); | 238 | nameWithTypes = interfaceRegExp.cap(1) + QLatin1String(" [interface]"); | ||
239 | node->setText(0, nameWithTypes); | ||||
235 | } | 240 | } | ||
236 | else | 241 | else | ||
237 | { | 242 | { | ||
238 | node->setText(0, interfaceRegExp.cap(1)); | 243 | node->setText(0, interfaceRegExp.cap(1)); | ||
239 | } | 244 | } | ||
240 | } | 245 | } | ||
241 | node->setIcon(0, QIcon(classPix)); | 246 | node->setIcon(0, QIcon(classPix)); | ||
242 | node->setText(1, QString::number( i, 10)); | 247 | node->setText(1, QString::number( i, 10)); | ||
248 | node->setToolTip(0, nameWithTypes); | ||||
243 | inClass = true; | 249 | inClass = true; | ||
244 | inFunction = false; | 250 | inFunction = false; | ||
245 | } | 251 | } | ||
246 | 252 | | |||
247 | // detect class constants | 253 | // detect class constants | ||
248 | if (constantRegExp.indexIn(line) != -1) | 254 | if (constantRegExp.indexIn(line) != -1) | ||
249 | { | 255 | { | ||
250 | if (m_plugin->treeOn) | 256 | if (m_plugin->treeOn) | ||
Show All 39 Lines | 290 | { | |||
290 | { | 296 | { | ||
291 | node = new QTreeWidgetItem(lastFunctionNode); | 297 | node = new QTreeWidgetItem(lastFunctionNode); | ||
292 | } | 298 | } | ||
293 | else | 299 | else | ||
294 | { | 300 | { | ||
295 | node = new QTreeWidgetItem(m_symbols); | 301 | node = new QTreeWidgetItem(m_symbols); | ||
296 | } | 302 | } | ||
297 | 303 | | |||
298 | if (m_plugin->typesOn) | | |||
299 | { | | |||
300 | QString functionArgs(functionRegExp.cap(5)); | 304 | QString functionArgs(functionRegExp.cap(5)); | ||
301 | pos = 0; | 305 | pos = 0; | ||
302 | while (pos >= 0) { | 306 | while (pos >= 0) { | ||
303 | pos = functionArgsRegExp.indexIn(functionArgs, pos); | 307 | pos = functionArgsRegExp.indexIn(functionArgs, pos); | ||
304 | if (pos >= 0) { | 308 | if (pos >= 0) { | ||
305 | pos += functionArgsRegExp.matchedLength(); | 309 | pos += functionArgsRegExp.matchedLength(); | ||
306 | functionArgsList += functionArgsRegExp.cap(1); | 310 | functionArgsList += functionArgsRegExp.cap(1); | ||
307 | } | 311 | } | ||
308 | } | 312 | } | ||
309 | node->setText(0, functionRegExp.cap(4) + QLatin1Char('(') + functionArgsList.join(QLatin1String(", ")) + QLatin1Char(')')); | 313 | | ||
310 | functionArgsList.clear(); | 314 | nameWithTypes = functionRegExp.cap(4) + QLatin1Char('(') + functionArgsList.join(QLatin1String(", ")) + QLatin1Char(')'); | ||
315 | if (m_plugin->typesOn) | ||||
316 | { | ||||
317 | node->setText(0, nameWithTypes); | ||||
311 | } | 318 | } | ||
312 | else | 319 | else | ||
313 | { | 320 | { | ||
314 | node->setText(0, functionRegExp.cap(4)); | 321 | node->setText(0, functionRegExp.cap(4)); | ||
315 | } | 322 | } | ||
323 | | ||||
316 | node->setIcon(0, QIcon(functionPix)); | 324 | node->setIcon(0, QIcon(functionPix)); | ||
317 | node->setText(1, QString::number( i, 10)); | 325 | node->setText(1, QString::number( i, 10)); | ||
326 | node->setToolTip(0, nameWithTypes); | ||||
327 | | ||||
328 | functionArgsList.clear(); | ||||
318 | 329 | | |||
319 | inFunction = true; | 330 | inFunction = true; | ||
320 | } | 331 | } | ||
321 | } | 332 | } | ||
322 | } | 333 | } | ||
323 | } | 334 | } | ||
324 | 335 | |