summaryrefslogtreecommitdiff
path: root/buildscripts/PhpDocumentor/phpDocumentor/IntermediateParser.inc
blob: 92a54ea0d86b0ef587f1d45efafdf2c3e8e6b569 (plain)
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
<?php
//
// +------------------------------------------------------------------------+
// | phpDocumentor                                                          |
// +------------------------------------------------------------------------+
// | Copyright (c) 2000-2003 Joshua Eichorn, Gregory Beaver                 |
// | Email         jeichorn@phpdoc.org, cellog@phpdoc.org                   |
// | Web           http://www.phpdoc.org                                    |
// | Mirror        http://phpdocu.sourceforge.net/                          |
// | PEAR          http://pear.php.net/package-info.php?pacid=137           |
// +------------------------------------------------------------------------+
// | This source file is subject to version 3.00 of the PHP License,        |
// | that is available at http://www.php.net/license/3_0.txt.               |
// | If you did not receive a copy of the PHP license and are unable to     |
// | obtain it through the world-wide-web, please send a note to            |
// | license@php.net so we can mail you a copy immediately.                 |
// +------------------------------------------------------------------------+
//

/** The phpDocumentor_IntermediateParser Class
 *
 *  The Intermediary Data Parser (intermediate between Parse and Converter)
 *
 *  @author Gregory Beaver
 *  @version $Revision: 1.2 $
 *  @copyright 2002 Gregory Beaver
 *  @package     phpDocumentor
 */
/** The phpDocumentor_IntermediateParser Class
 *
 * This class performs the work of organizing raw data from the parser in the
 * format of descendants of the {@link parserElement} class.  This is also where
 * processing of package pages occurs, in
 * {@link phpDocumentor_IntermediateParser::handleClass()} for class-level
 * packages and {@link phpDocumentor_IntermediateParser::handleDocBlock()} for
 * page-level packages.
 *
 * Most of the work of this parser goes to matching up
 * DocBlocks with the elements that they are documenting.  Since DocBlocks are
 * passed before the element they document, the last DocBlock is stored in
 * {@link phpDocumentor_IntermediateParser::$last} and then placed into the
 * $docblock parameter of the parserElement
 * descendant object.
 *  @author Gregory Beaver
 *  @version $Id: IntermediateParser.inc,v 1.2 2005/11/20 19:26:12 cellog Exp $
 *  @copyright 2002 Gregory Beaver
 *  @package     phpDocumentor
 */
class phpDocumentor_IntermediateParser
{
    /**
     * @var parserDocBlock
     */
    var $last;
    
    /**
     * type of the last parser Element handled
     *
     * This is used in handleDocBlock to determine whether a DocBlock is a
     * page-level DocBlock in conjunction with the {@link parserData::$clean}
     * var.  A page-level DocBlock is alwaysthe first DocBlock in a file, and
     * must be followed by another DocBlock.  The first test is handled by
     * parserData::$clean, which is set to false on the first encounter of an
     * element, and the second test is handled by this variable, which must be
     * equal to "docblock"
     * @see handleDocBlock()
     * @var string
     */
    var $lasttype = '';
    
    /**
     * Name of the class currently being parsed.
     * It is only used (and only valid) when phpDocumentor_IntermediateParser is
     * parsing a class
     * @var string
     */
    var $cur_class = '';
    
    /**
     * type of the current parser Element being handled
     * 
     * This is used by {@link HandleEvent()} to set the {@link $lasttype} var,
     * which is used to detect page-level DocBlocks
     * @var string
     */
    var $type = '';
    
    /**
     * set in {@link Setup.inc.php} to the value of the parseprivate commandline
     * option.  If this option is true, elements with an @access private tag
     * will be parsed and displayed
     * @tutorial phpDocumentor.howto.pkg#using.command-line.parseprivate
     * @var boolean
     */
    var $parsePrivate = false;
    
    /**
     * this variable is used to prevent parsing of elements with an @ignore tag
     * @see $packageoutput
     * @see $parsePrivate
     */
    var $private_class = false;
    
    /**
     * used to set the output directory
     * @see setTargetDir()
     */
    var $targetDir;
    
    /**
     * used to set the template base directory
     * @see setTemplateBase()
     */
    var $templateBase;
    
    /**
     * array of parsed package pages
     *
     * used by {@link Convert()} to convert all package pages into output
     * @var array
     */
    var $package_pages = array();
    
    /**
     * @var array array of all {@link parserData} containing page information
     */
    var $pages = array();
    /**
     * Put away a page that has been @ignored or @access private if
     * !{@link $parsePrivate}
     *
     * When a page has @access private in its DocBlock, it is placed here
     * instead of in {@link $pages}, to allow for proper Class parsing.  Since
     * classes and pages are parsed as if they were separate, this array allows
     * public classes on private pages to retrieve information needed about the
     * page that holds the class and to {@link addPageIfNecessary()} to the
     * $pages array
     * @var array
     */
    var $privatepages = array();
    /**
     * Keeps track of packages of classes that have parent classes in another
     * package.  Used in automatic linking.
     *
     * This array is updated by {@link addPackageParent()}, which is called in
     * {@link Classes::processChild()} to keep track of classes that descend
     * from classes in different packages.  In other words, if class foo is in
     * package one, and class bar is in package two, an entry
     * $package_parents['two'] = 'one' will be made.
     * @var array Format: packagename => parentpackagename
     * @see Converter::getLink()
     */
    var $package_parents = array();
    
    /**
     * Used to determine the category for tutorials.
     *
     * <b>WARNING:</b> If more than one category exists, the last category
     * encountered will overwrite the previous and will raise a big warning
     * @var array Format: packagename => categoryname
     */
    var $packagecategories = array();
    
    /**
     * list of all packages encountered while documenting.  Used in automatic
     * linking.
     * 
     * Converter::getLink() first checks if an ambiguous link is found in the
     * current package.  If not, it then checks in parent packages, and if still
     * not found, uses this array to check in the rest of the packages before
     * giving up
     * @var array Format: array(packagename => 1, packagename => 1,...)
     * @see Converter::getLink()
     */
    var $all_packages = array();
    
    /**
     * array of packages to parser and output documentation for, if not all
     * packages should be documented
     *
     * Format:<br />
     * array(package1,package2,...)<br />
     * or false if not set
     *
     * Use this option to limit output similar to ignoring files.  If you have
     * some temporary files that you don't want to specify by name but don't
     * want included in output, set a package name for all the elements in your
     * project, and set packageoutput to that name.  the default package will be
     * ignored.  Parsing speed does not improve.  If you want to ignore files
     * for speed reasons, use the ignore command-line option
     * @tutorial phpDocumentor.howto.pkg#using.command-line.packageoutput
     * @see Io
     * @var false|array
     */
    var $packageoutput = false;
    
    /**
     * the functions which handle output from the {@link Parser}
     * @see handleEvent(), handleDocBlock(), handlePage(), handleClass()
     * @see handleDefine(), handleFunction(), handleMethod(), handleVar()
     * @see handlePackagePage(), handleInclude(), handleTutorial()
     */
    var $event_handlers = array(
            'docblock' => 'handleDocBlock',
            'page' => 'handlePage',
            'class' => 'handleClass',
            'define' => 'handleDefine',
            'function' => 'handleFunction',
            'method' => 'handleMethod',
            'var' => 'handleVar',
            'const' => 'handleConst',
            'packagepage' => 'handlePackagePage',
            'include' => 'handleInclude',
            'global' => 'handleGlobal',
            'tutorial' => 'handleTutorial',
            );
    
    /**
     * $data contains parsed structures for the current page being parsed
     *
     * In version 1.1+, $data is only used to store the current page information.
     * All handling of documented elements is handled by the
     * {@link ProceduralPages} and {@link Classes} classes.
     * @var parserData
     */
    var $data;
    
    /**
     * set in {@link Setup.inc.php} to the value of the quitemode commandline
     * option.
     *
     * If this option is true, informative output while parsing will not be
     * displayed (documentation is unaffected)
     * @var boolean
     * @tutorial phpDocumentor.howto.pkg#using.command-line.quiet
     */
    var $quietMode = false;
    
    /**
     * used to keep track of inheritance at the smartest level possible for a
     * dumb computer
     * @var Classes
     */
    var $classes = false;
    
    /**
     * used to keep track of all elements in a procedural page.  Handles name
     * conflicts with elegance
     * @since 1.1
     * @var ProceduralPages
     */
    var $proceduralpages = false;
    
    /**
     * an array of template names indexed by converter name
     *
     * For example, if the default HTMLframesConverter is using the DOM/l0l33t
     * template, the array will be
     * <code>$converters['frames'] = 'DOM/l0l33t'</code>
     * @var array Format: array(Convertername1 => templatename)
     * @see Converter
     */
    var $converters = false;
    /** 
     * @var string Title of generated documentation, passed to Converters
     */
    var $title = '';
    
    var $uses = array();

    var $db_template;
    
    /**
     * Stores parsed CHANGELOG/INSTALL/README files
     * @var array Format: array(CHANGELOG => contents,
     *                          INSTALL => contents,
     *                          README => contents)
     */
    var $ric = array();
    
    /**
     * Flag used to determine whether the last docblock
     * was a page-level docblock.
     * @var boolean
     * @access private
     */
    var $_lastDocBlockWasPageLevel = false;
    
    /**
     * Flag used to determine whether the Page-level
     * DocBlock was declared in old or new style
     * @var boolean
     * @access private
     */
    var $_oldPageLevel = false;

    /**
     * sets up basic data structures
     * @param string Title of generated documentation, passed to Converters
     * @see $title, $data, $classes, $proceduralpages
     */
    function phpDocumentor_IntermediateParser($title='Generated Documentation')
    {
        $this->title = $title;
        $this->data = new parserData;
        $this->classes = new Classes;
        $this->proceduralpages = new ProceduralPages;
    }
    
    /**
     * Retrieve the relative path.  If the path contains "pear/" it will
     * be used as the base, otherwise the Program_Root string will be used.
     * @global array uses 'Program_Root' option to replace it with '' for
     *               retrieving the source location of a file
     * @param string path to file
     * @return string
     * @see $sourceLocation
     * @access private
     */
    function _getSourceLocation($sl, $sourceloc)
    {
        global $_phpDocumentor_options;
        if (empty($sl)) return false;
        $sl = str_replace('\\','/',$sl);
        if (strpos($sl,'pear/'))
        {
            $sl = substr($sl,strpos($sl,'pear/') + 5);
            if (dirname($sl) == '.')
            {
                return 'PEAR';
            }
            return dirname($sl);
        } else
        {
            if (strpos(str_replace($_phpDocumentor_options['Program_Root'] . PATH_DELIMITER,'',$sourceloc),PATH_DELIMITER) === false)
                return '';
            return dirname(str_replace($_phpDocumentor_options['Program_Root'] . PATH_DELIMITER,'',$sourceloc));
        }
    }
    
    /**
     * Guess the package/subpackage based on subdirectory if the --pear option
     *
     * A file in pear/dir/file.php will be in package "dir."  A file in
     * pear/dir/subdir/file.php will be in package "dir," subpackage "subdir."
     * @param string full path of file
     * @param template-ready source location Program_Root/dir/file.php
     * @global array uses the 'pear' option to determine whether to guess based
     *               on subdirectory
     * @tutorial phpDocumentor.howto.pkg#using.command-line.pear
     */
    function _guessPackage($path, $sourceloc)
    {
        global $_phpDocumentor_setting;
        if ($_phpDocumentor_setting['pear'])
        {
            $subpath = explode(PATH_DELIMITER, $this->_getSourceLocation($path, $sourceloc));
            if (!empty($subpath[0]))
            { // can only have package and subpackage in this version
                $package = $subpath[0];
                $subpackage = '';
                if (isset($subpath[1])) $subpackage = $subpath[1];
                return array($package,$subpackage);
            } else return array($this->package, $this->subpackage);
        } else return array($this->package, $this->subpackage);
    }
    
    /**
     * handles post-parsing of include/require/include_once/include_once
     *
     * This function sets {@link $data}->clean to false to tell the
     * phpDocumentor_IntermediateParser that a page-level DocBlock can't be
     * found after this point on this page.  It then sets the package
     * to be the same as the page, and adds itself to the
     * {@link ProceduralPages} class
     * @param integer $event Event number from {@link Parser.inc}
     * @param parserInclude $data
     */
    function handleInclude($event,$data)
    {
        if ($this->_lastDocBlockWasPageLevel)
        {
            addWarning(PDERROR_DOCBLOCK_CONFLICT, $data->getName(), $data->getFile());
            if (!$this->_oldPageLevel)
            {
                unset($this->last);
            }
        }
        $this->_lastDocBlockWasPageLevel =
        $this->data->clean = false;
        // page was @ignored
        if ($this->private_page)
        {
            unset($this->last);
            return;
        }
        if (empty($this->last))
        {
            if (isset($this->db_template))
            // use the docblock template
            $this->last = phpDocumentor_clone($this->db_template);
            else
            // we don't have a docblock, create an empty one to get rid of errors
            $this->last = new parserDocblock();
        }
//        $this->last->setLineNumber($data->getLineNumber());
        if ($this->last->getKeyword('ignore'))
        {
            $this->last = false;
            return;
//            addWarning(PDERROR_IGNORE_TAG_IGNORED,'include',$data->getName().'('.$data->getValue().')');
        }

        $this->last->overridePackage($this->category,$this->package,$this->subpackage,$data->getName(),'include');
        $data->setDocBlock($this->last);
        $this->proceduralpages->addInclude($data);
        $this->last = false;
    }
    
    /**
     * handles post-parsing of global variables
     *
     * This function sets {@link $data}->clean to false to tell the
     * phpDocumentor_IntermediateParser that a page-level DocBlock can't be
     * found after this point on this page.  It then sets the package
     * to be the same as the page, and adds itself to the
     * {@link ProceduralPages} class
     * @param integer $event Event number from {@link Parser.inc}
     * @param parserGlobal $data
     */
    function handleGlobal($event,$data)
    {
        if ($this->_lastDocBlockWasPageLevel)
        {
            addWarning(PDERROR_DOCBLOCK_CONFLICT, 'global variable', $data->getName());
            if (!$this->_oldPageLevel)
            {
                unset($this->last);
            }
        }
        $this->_lastDocBlockWasPageLevel =
        $this->data->clean = false;
        if ($this->private_page)
        {
            unset($this->last);
            return;
        }
        if (empty($this->last))
        {
            if (isset($this->db_template))
            // use the docblock template
            $this->last = phpDocumentor_clone($this->db_template);
            else
            // we don't have a docblock, create an empty one to get rid of errors
            $this->last = new parserDocblock();
        }
//        $this->last->setLineNumber($data->getLineNumber());
        if ($this->last->getKeyword('ignore'))
        {
            addWarning(PDERROR_IGNORE_TAG_IGNORED,'global variable - just don\'t document the',$data->getName());
            $this->last = false;
            return;
        }
        $this->last->overridePackage($this->category,$this->package,$this->subpackage,$data->getName(),'global');
        $data->setDocBlock($this->last);
        if ($data->docblock->getKeyword('name'))
        {
            $a = $data->docblock->getKeyword('name');
            if (is_object($a)) $a = $a->value;
            $data->setName($a);
        }
        $this->proceduralpages->addGlobal($data);
        $this->last = false;
    }
    
    /**
     * handles post-parsing of Package-level documentation pages.
     *
     * sets the {@link $package_pages}[$data->package] to $data
     * @param integer $event Event number from {@link Parser.inc}
     * @param parserPackagePage $data
     */
    function handlePackagePage($event,$data)
    {
        $this->package_pages[$data->package] = &$data;
        $this->last = false;
    }
    
    /**
     * handle post-parsing of Tutorials.
     *
     * This adds the parsed tutorial to the tutorial tree
     * @uses $tutorials sets the value of tutorials to parameter $data
     * @param integer $event Event Number
     * @param parserTutorial $data
     * @since 1.2
     */
    function handleTutorial($event,$data)
    {
        if (isset($this->packagecategories[$data->package]))
        {
            $data->category = $this->packagecategories[$data->package];
        } else
        {
            $data->category = $GLOBALS['phpDocumentor_DefaultCategoryName'];
        }
        $this->tutorials[$data->package][$data->subpackage][$data->tutorial_type][$data->name] = $data;
    }
    
    /**
     * handles post-parsing of class vars
     *
     * This function sets up a @var tag if none is found, and aligns $data's
     * $path var and packages to match the parent object
     * @param integer $event Event number from {@link Parser.inc}
     * @param parserVar $data
     */
    function handleVar($event,$data)
    {
        global $_phpDocumentor_setting;
        if ($this->private_class)
        {
            unset($this->last);
            return;
        }
        if (empty($this->last))
        {
            if (isset($this->db_template))
            {
                // use the docblock template
                $this->last = phpDocumentor_clone($this->db_template);
            } else {
                // we don't have a docblock, create an empty one to get rid of errors
                $this->last = new parserDocblock();
            }
        }
//        $this->last->setLineNumber($data->getLineNumber());
        $this->last->overridePackage($this->category,$this->package,$this->subpackage,$data->getName(),'var');
        $this->last->updateModifiers($data->getModifiers());

        if ($this->last->getKeyword('ignore'))
        {
            $this->last = false;
            return;
//            addWarning(PDERROR_IGNORE_TAG_IGNORED,'var',$this->cur_class.'::'.$data->getName());
        }
        if (!$this->last->var)
        {
            $this->last->addVar('mixed',new parserStringWithInlineTags);
        }
        
        if ($_phpDocumentor_setting['pear'])
        {
            if (strpos($data->getName(), '_') == 1 && !$this->last->getKeyword('access'))
            {
                addWarning(PDERROR_PRIVATE_ASSUMED,'class variable',$data->class.'::'.$data->getName());
                $this->last->addKeyword('access','private');
                $data->setDocBlock($this->last);
            }
        }
        $data->setDocBlock($this->last);
        $data->path = $this->data->parent->path;
        $this->classes->addVar($data);
        $this->last = false;
    }
    
    /**
     * handles post-parsing of class constants
     *
     * This function aligns $data's
     * $path var and packages to match the parent object
     * @param integer $event Event number from {@link Parser.inc}
     * @param parserVar $data
     */
    function handleConst($event,$data)
    {
        global $_phpDocumentor_setting;
        if ($this->private_class)
        {
            unset($this->last);
            return;
        }
        if (empty($this->last))
        {
            if (isset($this->db_template))
            // use the docblock template
            $this->last = phpDocumentor_clone($this->db_template);
            else
            // we don't have a docblock, create an empty one to get rid of errors
            $this->last = new parserDocblock();
        }
//        $this->last->setLineNumber($data->getLineNumber());
        $this->last->overridePackage($this->category,$this->package,$this->subpackage,$data->getName(),'const');

        if ($this->last->getKeyword('ignore'))
        {
            $this->last = false;
            return;
//            addWarning(PDERROR_IGNORE_TAG_IGNORED,'var',$this->cur_class.'::'.$data->getName());
        }
        $data->setDocBlock($this->last);
        $data->path = $this->data->parent->path;
        $this->classes->addConst($data);
        $this->last = false;
    }
    
    /**
     * handles post-parsing of class methods
     *
     * This function first aligns $data's path and package to match the parent
     * object, and also aligns the docblock's @param, @global, and @staticvar
     * tags with the information parsed from the method source code.  It also
     * checks to see if the method is a constructor and sets the $isConstructor
     * flag.  If source code has been parsed by a {@}source} tag, the source is
     * added to its docblock
     *
     * Finally, it adds the method to the {@link Classes} class.
     * @param integer $event Event number from {@link Parser.inc}
     * @param parserMethod $data
     */
    function handleMethod($event,$data)
    {
        global $_phpDocumentor_setting;
        if ($this->private_class)
        {
            unset($this->last);
            return;
        }

        if (empty($this->last))
        {
            if (isset($this->db_template))
            // use the docblock template
            $this->last = phpDocumentor_clone($this->db_template);
            else
            // we don't have a docblock, create an empty one to get rid of errors
            $this->last = new parserDocblock();
        }
//        $this->last->setLineNumber($data->getLineNumber());
        if ($this->last->getKeyword('ignore'))
        {
            $this->last = false;
            return;
//            addWarning(PDERROR_IGNORE_TAG_IGNORED,'method',$this->cur_class.'::'.$data->getName());
        }
        $this->last->overridePackage($this->category,$this->package,$this->subpackage,$data->getName(),'method');
        if ($data->hasSource())
        {
            $this->last->setSource($data->getSource(), $data->getClass());
        }
        foreach($data->listParams() as $param)
        {
            $update_params[] = $param[0];
        }
        foreach($data->listGlobals() as $param)
        {
            $update_globals[] = $param[1];
        }
        foreach($data->listStatics() as $param)
        {
            $update_statics[] = $param[0];
        }
        if (isset($update_params))
        $this->last->updateParams($update_params);
        if (isset($update_globals))
        $this->last->updateGlobals($update_globals);
        if (isset($update_statics))
        $this->last->updateStatics($update_statics);
        $this->last->updateModifiers($data->getModifiers());
        unset($update_params);
        unset($update_globals);
        unset($update_statics);

        if ($data->getName() == $this->cur_class) $data->setConstructor();
        if ($data->getName() == '__construct') {
            $data->setConstructor();
        }
        if ($data->getName() == '__destruct') {
            $data->setDestructor();
        }

        if ($_phpDocumentor_setting['pear'])
        {
            if (strpos($data->getName(), '_') === 0 && substr($data->getName(), 1) == $data->class)
            { // is destructor
                $data->setDestructor();
            } elseif (strpos($data->getName(), '_') === 0 && !$this->last->getKeyword('access'))
            {
                if (strpos($data->getName(), '__') !== 0) {
                    addWarning(PDERROR_PRIVATE_ASSUMED,'method',$data->class.'::'.$data->getName().'()');
                    $this->last->addKeyword('access','private');
                    $data->setDocBlock($this->last);
                }
            }
        }
        $data->setDocBlock($this->last);
        $data->path = $this->data->parent->path;
        $this->classes->addMethod($data);
        $this->last = false;
    }

    /**
     * handles post-parsing of functions
     *
     * This function sets {@link $data}->clean to false to tell the
     * phpDocumentor_IntermediateParser that a page-level DocBlock can't be
     * found after this point on this page.  It then sets the package to be the
     * same as the page, aligns the docblock's @param, @global, and @staticvar
     * tags with the information parsed from the function source code.
     *
     * If source code has been parsed by a {@}source} tag, the source is added
     * to its docblock, and then the parserFunction adds itself to the
     * {@link ProceduralPages} class
     * @param integer $event Event number from {@link Parser.inc}
     * @param parserFunction $data
     */
    function handleFunction($event,$data)
    {
        if ($this->_lastDocBlockWasPageLevel)
        {
            addWarning(PDERROR_DOCBLOCK_CONFLICT, 'function', $data->getName());
            if (!$this->_oldPageLevel)
            {
                unset($this->last);
            }
        }
        $this->_lastDocBlockWasPageLevel =
        $this->data->clean = false;
        if ($this->private_page)
        {
            unset($this->last);
            return;
        }

        if (empty($this->last))
        {
            if (isset($this->db_template))
            // use the docblock template
            $this->last = phpDocumentor_clone($this->db_template);
            else
            // we don't have a docblock, create an empty one to get rid of errors
            $this->last = new parserDocblock();
        }
//        $this->last->setLineNumber($data->getLineNumber());
        if ($this->last->getKeyword('ignore'))
        {
            unset($this->last);
            return;
        }
        $this->last->overridePackage($this->category,$this->package,$this->subpackage,$data->getName(),'function');

        foreach($data->listParams() as $param)
        {
            $update_params[] = $param[0];
        }
        foreach($data->listGlobals() as $param)
        {
            $update_globals[] = $param[1];
        }
        foreach($data->listStatics() as $param)
        {
            $update_statics[] = $param[0];
        }
        if (isset($update_params))
        $this->last->updateParams($update_params);
        if (isset($update_globals))
        $this->last->updateGlobals($update_globals);
        if (isset($update_statics))
        $this->last->updateStatics($update_statics);
        unset($update_params);
        unset($update_globals);
        unset($update_statics);

        if ($data->hasSource())
        {
            $this->last->setSource($data->getSource());
        }
        if (count($this->last->params) == 1 && !count($data->listParams()))
        {
            // if the function has no parameters, and 1 @param, add it to the list as optional, default value is description from @param
            $pars = $this->last->listParams();
            $data->addParam($pars[0]['var'],$pars[0]['data']->getString());
        }
        $data->setDocBlock($this->last);
        $this->proceduralpages->addFunction($data);
        $this->last = false;
    }
    
    /**
     * handles post-parsing of defines
     *
     * This function sets {@link $data}->clean to false to tell the
     * phpDocumentor_IntermediateParser that a page-level DocBlock can't be
     * found after this point on this page.  It then sets the package to be the
     * same as the page and adds itself to the {@link ProceduralPages} class
     * @param integer $event Event number from {@link Parser.inc}
     * @param parserDefine $data
     */
    function handleDefine($event,$data)
    {
        if ($this->_lastDocBlockWasPageLevel)
        {
            addWarning(PDERROR_DOCBLOCK_CONFLICT, 'define', $data->getName());
            if (!$this->_oldPageLevel)
            {
                unset($this->last);
            }
        }
        $this->_lastDocBlockWasPageLevel =
        $this->data->clean = false;
        if ($this->private_page)
        {
            unset($this->last);
            return;
        }
        if (empty($this->last))
        {
            if (isset($this->db_template))
            // use the docblock template
            $this->last = phpDocumentor_clone($this->db_template);
            else
            // we don't have a docblock, create an empty one to get rid of errors
            $this->last = new parserDocblock();
        }
//        $this->last->setLineNumber($data->getLineNumber());
        if ($this->last->getKeyword('ignore'))
        {
            unset($this->last);
            return;
        }

        $this->last->overridePackage($this->category,$this->package,$this->subpackage,$data->getName(),'define');
        $data->setDocBlock($this->last);
        $this->proceduralpages->addDefine($data);
        $this->last = false;
    }
    
    /**
     * handles post-parsing of classes
     *
     * This function sets {@link $data}->clean to false to tell the
     * phpDocumentor_IntermediateParser that a page-level DocBlock can't be
     * found after this point on this page.  It sets {@link $cur_class} to its
     * name, and if an @ignore tag is found in the DocBlock, it sets
     * {@link $private_class} to true, to prevent post-parsing of any of the
     * class's vars or methods.  Then it checks for the existence of a package
     * page for the class's package
     * @param integer $event Event number from {@link Parser.inc}
     * @param parserClass $data
     */
    function handleClass($event,$data)
    {
        global $_phpDocumentor_setting;
        if ($this->_lastDocBlockWasPageLevel)
        {
            if (!$this->_oldPageLevel)
            {
                addWarning(PDERROR_DOCBLOCK_GOES_CLASS, $data->getName());
                $doc = new parserDocBlock;
                $doc->category = $this->category;
                $doc->package = $this->package;
                $doc->subpackage = $this->subpackage;
                if ($_phpDocumentor_setting['sourcecode']) {
                    $doc->canSource();
                    $doc->addFileSource($this->data->parent->path, $this->data->parent->source);
                }
                $this->data->setDocBlock($doc);
                unset($doc);
                $this->last->cantSource();
            }
        }
        $this->_lastDocBlockWasPageLevel =
        $this->data->clean = false;
        if (empty($this->last))
        {
            if (isset($this->db_template))
            // use the docblock template
            $this->last = phpDocumentor_clone($this->db_template);
            else
            // we don't have a docblock, create an empty one to get rid of errors
            $this->last = new parserDocblock();
            list($this->last->package, $this->last->subpackage) = $this->_guessPackage($this->data->parent->path, $this->data->parent->getSourceLocation('dummy'));
            addWarning(PDERROR_NO_PACKAGE_TAG,'class',$data->getName(),$this->last->package);
        } else
        {
            if (!$this->last->getExplicitPackage())
            {
                list($this->last->package, $this->last->subpackage) = $this->_guessPackage($this->data->parent->path, $this->data->parent->getSourceLocation('dummy'));
                addWarning(PDERROR_NO_PACKAGE_TAG,'class',$data->getName(),$this->last->package);
            } else
            {
                if (isset($this->packagecategories[$this->package])
                    && $this->packagecategories[$this->package] != $this->category)
                    addWarning(PDERROR_PACKAGECAT_SET,$this->package,
                                $this->packagecategories[$this->package],
                                $this->category);
                $this->packagecategories[$this->package] = $this->category;
            }
        }
        $this->last->updateModifiers($data->getModifiers());
//        $this->last->setLineNumber($data->getLineNumber());
        $data->setDocBlock($this->last);
        $this->cur_class = $name = $data->getName();
        if ($this->last->getKeyword('ignore'))
        {
            $this->private_class = true;
            unset($this->last);
            return;
        }
        $data->path = $this->data->parent->path;
        $this->classes->addClass($data);
        $this->private_class = false;
        if ($this->last->package)
        {
            $this->parsePackagePage($this->last->package, $this->data->parent->getPath());
        }
        $this->last = false;
    }
    
    /**
     * handles post-parsing of procedural pages
     *
     * this event is called at the start of a new page, before the Parser knows
     * whether the page will contain any procedural pages or not
     * @param integer $event Event number from {@link Parser.inc}
     * @param parserPage $data
     */
    function handlePage($event,$data)
    {
        $type = 'page';
        $this->private_page = false;
        $this->data = new parserData;
        $data->category = $this->category = $GLOBALS['phpDocumentor_DefaultCategoryName'];
        $this->package = $GLOBALS['phpDocumentor_DefaultPackageName'];
        $this->subpackage = '';
        $this->proceduralpages->addPage($data);
        $this->data->setParent($data);
        $this->pages[$data->getPath()] = $this->data;
        $this->classes->nextFile($data->getPath());
        $this->packageoutput = $data->getPackageOutput();
    }
    
    /**
     * handles post-parsing of DocBlocks
     *
     * This function sets {@link $last} to the DocBlock represented by $data, to
     * allow the next documentable element passed to
     * phpDocumentor_IntermediateParser to link the DocBlock into its $docblock
     * property.  This function also checks for two special cases of DocBlocks:
     * <ol>
     *    <li>First DocBlock in the file contains a @package tag</li>
     *    <li>First DocBlock in the file is immediately followed by another
     *        DocBlock</li>
     * </ol>
     * In both cases, the function extracts this tag and uses it as the
     * page-level package.  If the @package tag is in the DocBlock of an
     * element (function, global variable, whatever) that isn't a page-level
     * DocBlock, a warning will be raised to notify the author that a @package
     * tag belongs in a page-level DocBlock.
     *
     * <b>New</b> in version 1.2.2, if the first DocBlock in a file contains
     * a @package tag, it is a page-level DocBlock.
     *
     * If the DocBlock is page-level, it is processed with
     * {@link _processPageLevelDocBlock}
     *
     * Finally, the function replaces the old parserPage in
     * {@link parserData::$data}->parent with the new one containing information
     * from the DocBlock by calling {@link addPage()}, and checks for
     * package-level docs.
     * @param integer $event Event number from {@link Parser.inc}
     * @param parserDocBlock $data
     */
    function handleDocBlock($event,$data)
    {
        $type = 'docblock';
        $data->postProcess();
        // Zend desc support
        if ($tdesc = $data->getKeyword('desc'))
        {
            $data->setShortDesc($tdesc);
            unset($data->tags['desc']);
        }
        $this->_lastDocBlockWasPageLevel = false;
        // 1st docblock in file, check for @package
        if ($this->data->isClean() && !isset($this->last))
        {
            if ($data->getExplicitPackage())
            {
                // new with 1.2.2:
                // if the first docblock in a file
                // contains a @package tag, then it is
                // a page-level docblock
                $this->_processPageLevelDocBlock($data);
                $this->_lastDocBlockWasPageLevel = true;
                $this->all_packages[$data->package] = 1;
                $this->last = $data;
                return;
            }
            $doc = new parserDocBlock;
            $doc->category = $this->category;
            $doc->package = $this->package;
            $doc->subpackage = $this->subpackage;
            $this->data->setDocBlock($doc);
            $this->proceduralpages->addPagePackage($this->data->parent->getPath(),$this->package,$this->subpackage);
            unset($doc);
        }
        // 2nd docblock in a row, and it's at the top of the file, page-level docblock
        if ($this->lasttype == "docblock" && $this->data->isClean())
        {
            $this->_processPageLevelDocBlock($this->last);
            $this->_oldPageLevel = true;
            $this->_lastDocBlockWasPageLevel = false;
        }
        $this->all_packages[$data->package] = 1;
        $this->last = $data;
    }
    
    /**
     * Process a Page-level DocBlock
     *
     * First, it checks for an @ignore tag,
     * and if found, calls {@link ProceduralPages::ignorePage()}.  An @ignore
     * tag in a page-level DocBlock will ignore all functions, defines, global
     * variables, and includes.  It will not ignore classes!  The function next
     * checks for an @access private, and if --parseprivate is off, performs the
     * same actions as @ignore, raising a warning for the unsuspecting user.
     * Next, it checks for the @name tag, which is used to rename the page.
     * This is also a PEAR compatibility issue, and may not be very useful in
     * the long run.  Documentation is best when it refers to real entities in
     * the package, and not to aliases.
     * @access private
     */
    function _processPageLevelDocBlock($data)
    {
        global $_phpDocumentor_setting;
        // can only have 1 package-level docblock, others are ignored
        if (!$this->data->isClean())
        {
            return;
        }
        $this->data->clean = false;
        $this->data->explicitDocBlock();
        $data->canSource();
        if ($_phpDocumentor_setting['sourcecode'])
        {
            $data->addFileSource($this->data->parent->path, $this->data->parent->source);
        }
        if (!$data->getExplicitPackage())
        {
            list($data->package,$data->subpackage) = $this->_guessPackage($this->data->parent->getPath(), $this->data->parent->getSourceLocation('dummy'));
            addWarning(PDERROR_NO_PACKAGE_TAG,'file',$this->data->parent->getPath(),$this->last->package);
        }
        if (isset($this->packagecategories[$this->package])
            && $this->packagecategories[$this->package] != $this->category)
            addWarning(PDERROR_PACKAGECAT_SET,$this->package,
                        $this->packagecategories[$this->package],
                        $data->category);
        $this->packagecategories[$this->package] = $data->category;
        $this->category = $this->data->parent->category = $data->category;
        $this->packagecategories[$this->package] = $this->category;
        $this->subpackage = $this->data->parent->subpackage = $data->subpackage;
        if ($data->getKeyword('ignore'))
        {
            $this->proceduralpages->ignorePage($this->data->parent);
            $this->private_page = true;
            unset($this->last);
            $this->privatepages[$this->data->parent->getPath()] = $this->data;
            unset($this->pages[$this->data->parent->getPath()]);
            return;
        }
        $this->data->setDocBlock($data);
        $this->package = $this->data->parent->package = $data->package;
        $this->subpackage = $this->data->parent->subpackage = $data->subpackage;
        $this->proceduralpages->addPagePackage($this->data->parent->getPath(),$this->package,$this->subpackage);
        if ($access = $data->getKeyword('access'))
        {
            if (is_object($access) && ($access->getString() == 'private') && (!$this->parsePrivate))
            {
                addWarning(PDERROR_PARSEPRIVATE, $this->data->parent->getPath());
                $this->proceduralpages->ignorePage($this->data->parent);
                $this->private_page = true;
                unset($this->last);
                $this->privatepages[$this->data->parent->getPath()] = $this->data;
                unset($this->pages[$this->data->parent->getPath()]);
                return;
            }
        }
        if ($data->getKeyword('name'))
        {
            $a = $data->getKeyword('name');
            if (is_object($a)) $a = $a->value;
            $this->data->parent->setFile($a);
            $this->proceduralpages->setName($a);
        }
        $this->addPage($this->data->parent, $this->data->parent->getPath());
        if ($this->package)
        {
            $this->parsePackagePage($this->package, $this->data->parent->getPath());
        }
    }
    
    /**
     * Backward-compatibility only, use the new tutorials for more power
     * @tutorial tutorials.pkg
     * @param string package name of package file to parse
     * @param string directory of file that contains package name
     */
    function parsePackagePage($package, $path)
    {
        if (!isset($this->package_pages[$package]))
        {
            if (file_exists(dirname($path) . SMART_PATH_DELIMITER . $package . '.html'))
            {
                if ($this->quietMode === false)
                {
                    phpDocumentor_out("Reading package-level file ".$package . '.html');
                          flush();
                }
                $fp = fopen(dirname($path) . SMART_PATH_DELIMITER . $package . '.html',"r");
                $ret = fread($fp,filesize(dirname($path) . SMART_PATH_DELIMITER . $package . '.html'));
                fclose($fp);
                unset($fp);
                if ($this->quietMode === false)
                {
                    phpDocumentor_out(" -- Parsing File\n");
                          flush();
                }
                $pageParser = new ppageParser;
                $tempp = $this->package;
                $lp = $this->last;
                $pageParser->subscribe('*',$this);
                $pageParser->parse($ret,false,$package);
                $this->package = $tempp;
                $this->last = $lp;
                unset($tempp);
                unset($pageParser);
            }
        }
    }
    
    /**
     * called via {@link Parser::parse()} and Parser's inherited method
     * {@link Publisher::publishEvent()}
     *
     * $event is one of the PHPDOC constants from Parser.inc.  If it is not
     * PHPDOCUMENTOR_EVENT_NEWSTATE, then a function name is retrieved from the
     * {@link $event_handlers} array and called to handle the $data
     * @param integer $event event number from {@link Parser.inc}
     * @param mixed $data if $event is {@link PHPDOCUMENTOR_EVENT_NEWSTATE}, $data is a {@link PHP_DOC_EVENT_END_PAGE} or {@link STATE_END_CLASS},
     *                    otherwise $data is either a {@link parserDocBlock}, {@link parserPage} or descendant of {@link parserElement}
     * @global array we use 'sourcecode' to determine whether to highlight the source
     *               of the current file if it has no file-level docblock
     */
    function HandleEvent($event,$data)
    {
        global $_phpDocumentor_setting;
        global $phpDocumentor_DefaultPackageName, $phpDocumentor_DefaultCategoryName;
        if (empty($this->packagecategories))
        $this->packagecategories[$phpDocumentor_DefaultPackageName] = $phpDocumentor_DefaultCategoryName;
        if ($event == PHPDOCUMENTOR_EVENT_NEWSTATE)
        {
            if ($data == STATE_END_CLASS)
            {
            } elseif ($data == PHPDOCUMENTOR_EVENT_END_PAGE)
            {
                if (!$this->private_page)
                {
                    $this->all_packages[$this->package] = 1;
                    if (!$this->data->hasExplicitDocBlock())
                    {
                        $doc = $this->data->docblock;
                        if (!$this->data->docblock)
                        {
                            $doc = new parserDocBlock;
                        }
                        if ($_phpDocumentor_setting['sourcecode'])
                        {
                            $doc->canSource();
                            $doc->addFileSource($this->data->parent->path, $this->data->parent->source);
                        }
                        list($doc->package,$doc->subpackage) = $this->_guessPackage($this->data->parent->getPath(), $this->data->parent->getSourceLocation('dummy'));
                        addWarning(PDERROR_NO_PAGE_LEVELDOCBLOCK,$this->data->parent->getPath());
                        $this->data->setDocBlock($doc);
                        $this->proceduralpages->addPage($this->data->parent,$doc->package,$doc->subpackage);
                    }
                    $this->pages[$this->data->parent->getPath()] = $this->data;
                }
                $this->private_page = false;
                $this->private_class = false;
                if (isset($this->db_template))
                {
                    addWarning(PDERROR_DB_TEMPLATE_UNTERMINATED);
                }
                unset($this->db_template);
                unset($this->last);
            } elseif ($data == PHPDOCUMENTOR_EVENT_END_DOCBLOCK_TEMPLATE)
            {
                unset($this->db_template);
            }
            //echo $this->state_lookup[$data] . "\n";
            //echo $data."\n";
        } 
         else 
        {
            if ($event == PHPDOCUMENTOR_EVENT_README_INSTALL_CHANGELOG)
            {
                $this->ric[$data[0]] = $data[1];
                return;
            }
            if ($event == PHPDOCUMENTOR_EVENT_DOCBLOCK_TEMPLATE)
            {
                $data->postProcess();
                $this->db_template = $data;
                $this->_lastDocBlockWasPageLevel = false;
                // 2nd docblock in a row, and it's at the top of the file, page-level docblock
                if ($this->type == "docblock" && $this->data->isClean())
                {
                    // can only have 1 package-level docblock, others are ignored
                    $this->data->clean = false;
                    if ($this->last->getKeyword('ignore'))
                    {
                        $this->proceduralpages->ignorePage($this->data->parent);
                        $this->private_page = true;
                        unset($this->last);
                        $this->privatepages[$this->data->parent->getPath()] = $this->data;
                        unset($this->pages[$this->data->parent->getPath()]);
                        return;
                    }
                    $this->data->setDocBlock($this->last);
                    $this->package = $this->data->parent->package = $this->last->package;
                    $this->subpackage = $this->data->parent->subpackage = $this->last->subpackage;
                    $this->proceduralpages->addPagePackage($this->data->parent->getPath(),$this->package,$this->subpackage);
                    if ($access = $this->last->getKeyword('access'))
                    {
                        if (is_object($access) && ($access->getString() == 'private') && (!$this->parsePrivate))
                        {
                            addWarning(PDERROR_PARSEPRIVATE, $this->data->parent->getPath());
                            $this->proceduralpages->ignorePage($this->data->parent);
                            $this->private_page = true;
                            unset($this->last);
                            $this->privatepages[$this->data->parent->getPath()] = $this->data;
                            unset($this->pages[$this->data->parent->getPath()]);
                            return;
                        }
                    }
                    if ($this->last->getKeyword('name'))
                    {
                        $a = $this->last->getKeyword('name');
                        if (is_object($a)) $a = $a->value;
                        $this->data->parent->setFile($a);
                        $this->proceduralpages->setName($a);
                    }
                    $this->addPage($this->data->parent, $this->data->parent->getPath());
                    if ($this->package)
                    {
                        $this->parsePackagePage($this->package, $this->data->parent->getPath());
                    }
                }
                unset($this->last);
            } else
            {
                $this->lasttype = $this->type;
                $type = $data->getType();
//                fancy_debug($type,$data);
                if (($type != 'page') && ($type != 'docblock') && ($type != 'packagepage') && ($type != 'tutorial'))
                {
                    $data->setFile($this->data->parent->getFile());
                }
                $this->type = $type;
                //echo $type . "\n";
                
                if (isset($this->event_handlers[$type]))
                {
                    $handle = $this->event_handlers[$type];
                    $this->$handle($event,$data);
                }
            } 
        }
    }
    
    /**
     * Replaces the {@link parserPage} represented by $this->pages[$path] with
     * $page
     *
     * Called by {@link addPageIfNecessary(), handleDocBlock()} and
     * {@link ProceduralPages::setupPages()}, this method first checks to see if
     * the page has been added.  If not, it assumes that the page has either
     * been @ignored or set with @access private with --parseprivate off, and
     * returns {@link addPrivatePage()}.  Otherwise, it sets the pages[$path] to
     * be the parserPage $page and sets the package and subpackage to that of
     * $page
     * @see $pages
     * @param parserPage
     * @param string full path to the file
     */
    function addPage($page, $path)
    {
        if (!isset($this->pages[$path])) return $this->addPrivatePage($page, $path);
        $this->pages[$path]->setParent($page);
        if ($page->package != $GLOBALS['phpDocumentor_DefaultPackageName'])
        {
            if (!$this->pages[$path]->docblock)
            {
                $docblock = new parserDocBlock;
                $docblock->package = $page->package;
                $docblock->subpackage = $page->subpackage;
                $this->pages[$path]->docblock = $docblock;
            } else
            {
                $this->pages[$path]->docblock->package = $page->package;
                $this->pages[$path]->docblock->subpackage = $page->subpackage;
            }
        }
    }
    
    /**
     * add a new {@link parserPage} to the $pages array if none is found
     *
     * This method is used when a page has been @ignored or marked with @access
     * private, and a public class is in the page (a class with no @access
     * private in its DocBlock).  The method first creates a new page in the
     * {@link $pages} array and then copies path information, and calls
     * {@link addPage()} to set up packages
     * @param string full path of page
     */
    function addPageIfNecessary($path, &$class)
    {
        global $_phpDocumentor_setting;
        if (!$this->parsePrivate)
        {
            if (!isset($this->pages[$path]))
            {
                $this->pages[$path] = new parserData;
                $this->pages[$path]->docblock = new parserDocBlock;
                $this->pages[$path]->docblock->package = $this->privatepages[$path]->docblock->package;
                $this->pages[$path]->docblock->subpackage = $this->privatepages[$path]->docblock->subpackage;
                $par = $this->privatepages[$path]->parent;
                $this->pages[$path]->setParent($par);
                $this->proceduralpages->addPage($par);
            }
        }
        if (isset($_phpDocumentor_setting['packageoutput']))
            $packages = explode(',',$_phpDocumentor_setting['packageoutput']);
        if (isset($_phpDocumentor_setting['packageoutput']) &&
            $this->pages[$path]->parent->package != $class->docblock->package &&
            !in_array($this->pages[$path]->parent->package,$packages))
        {
            $this->pages[$path]->parent->package = $class->docblock->package;
            $this->addPage($this->pages[$path]->parent, $path);
            $this->proceduralpages->addPage($this->pages[$path]->parent);
        }
    }
    
    /**
     * Adds a {@link parserPage} element to the {@link parserData} element in
     * $this->privatepages[$path]
     *
     * Performs a similar function to addPage, but adds to the
     * {@link $privatePages} array
     * @param parserPage $page
     * @param string $path full path to the page
     * @see addPage()
     */
    function addPrivatePage($page, $path)
    {
        $this->privatepages[$path]->setParent($page);
        if ($page->package != $GLOBALS['phpDocumentor_DefaultPackageName'])
        {
            if (!$this->privatepages[$path]->docblock)
            {
                $docblock = new parserDocBlock;
                $docblock->package = $page->package;
                $docblock->subpackage = $page->subpackage;
                $this->privatepages[$path]->docblock = $docblock;
            } else
            {
                $this->privatepages[$path]->docblock->package = $page->package;
                $this->privatepages[$path]->docblock->subpackage = $page->subpackage;
            }
        }
    }
    
    /**
     * adds a processed descendant of {@link parserElement} to the {@link $pages}
     * array or {@link $privatepages} array
     *
     * This function expects the page to exist in either $pages or $privatepages.  It calls the
     * {@link parserData::addElement()} method to add $element to the page.
     * @param parserElement $element this will actually be a descendant of parserElement
     * @param string $path
     */
    function addElementToPage($element, $path)
    {
        if (isset($this->privatepages[$path]))
        {
            if (isset($this->pages[$path]))
            {
                if ($element->type == 'class' || $element->type == 'method'
                    || $element->type == 'var' || $element->type == 'const')
                {
                    $this->pages[$path]->addElement($element);
                } else
                $this->privatepages[$path]->addElement($element);
            } else
            $this->privatepages[$path]->addElement($element);
        } else
        {
            if (isset($this->pages[$path]))
            {
                $this->pages[$path]->addElement($element);
            }
        }
    }
    
    /**
     * Add all the @uses tags from $element to the $uses array so that @usedby
     * virtual tags can be added
     * @uses parserUsesTag::getSeeElement() used to initialize {@link $uses}
     * @uses parserUsesTag::getDescription() used to initialize {@link $uses}
     * @param parserElement descendant of parserElement
     * @param string full path to the file 
     */
    function addUses($element, $path)
    {
        if ($element->type == 'page')
        {
            $element = $this->pages[$element->path];
        }
        if (!$this->parsePrivate && $element->docblock->hasaccess)
        {
            $a =  $element->docblock->getKeyword('access');
            if (is_object($a) && $a->getString() == 'private') return;
        }
        if (isset($this->privatepages[$path]))
        {
            if (isset($this->pages[$path]))
            {
//                if ($element->type == 'function' || $element->type == 'method')
                {
                    $uses = $element->docblock->getKeyword('uses');
                    if ($uses)
                    {
                        if (!is_array($uses)) $uses = array($uses);
                        foreach($uses as $use)
                        {
                            if (!is_object($use)) continue;
                            $el = $use->getSeeElement();
                            $description = $use->getDescription();
                            $this->uses[$el][] = array($element, $description);
                        }
                    }
                }
            }
        } else
        {
            if (isset($this->pages[$path]))
            {
//                if ($element->type == 'function' || $element->type == 'method')
                {
                    $uses = $element->docblock->getKeyword('uses');
                    if ($uses)
                    {
                        if (!is_array($uses)) $uses = array($uses);
                        foreach($uses as $use)
                        {
                            if (!is_object($use)) continue;
                            $el = $use->getSeeElement();
                            $description = $use->getDescription();
                            $this->uses[$el][] = array($element, $description);
                        }
                    }
                }
            }
        }
    }
    
    /**
     * Add a {@link parserUsedByTag} link to every element referred to by @uses
     * @param Converter temporary converter used to retrieve abstract links
     * @uses phpDocumentor_IntermediateParser::addUses() indirectly, as
     *       addUses() sets up $uses, which is iterated over here
     * @uses $pages sets up all @usedby tags from here
     * @access private
     */
    function _setupUsesList(&$converter)
    {
        ob_start();
        $converter->_createPkgElements($this->pages);
        ob_end_clean();
        foreach($this->uses as $link => $elements)
        {
            foreach($elements as $element)
            {
                if ($element[0]->type == 'method' || $element[0]->type == 'var' ||
                    $element[0]->type == 'const')
                {
                    $converter->class = $element[0]->getClass();
                }
                if ($element[0]->type == 'class')
                {
                    $converter->class = $element[0]->getName();
                }
                $reallink = $converter->getLink($link,$element[0]->docblock->package);
                if (is_object($reallink))
                {
                    // add a used by tag to the docblock of the destination
                    switch(phpDocumentor_get_class($reallink))
                    {
                        case 'pagelink' :
                        case 'functionlink' :
                        case 'definelink' :
                        case 'globallink' :
                        if (isset($this->pages[$reallink->path]))
                        {
                            for ($i=0;$i<count($this->pages[$reallink->path]->elements);$i++)
                            {
                                if ($this->pages[$reallink->path]->elements[$i]->type == str_replace('link','',phpDocumentor_get_class($reallink)) && $this->pages[$reallink->path]->elements[$i]->getName() == $reallink->name)
                                {
                                    $this->pages[$reallink->path]->elements[$i]->docblock->addUsedBy($element[0]->getLink($converter,false,true), $element[1]);
//                                   debug('added @usedby to '.str_replace('link','',phpDocumentor_get_class($reallink)).' '.$reallink->name);
                                }
                            }
                        }
                        break;
                        case 'classlink' :
                        case 'methodlink' :
                        case 'varlink' :
                        case 'constlink' :
                        if (isset($this->pages[$reallink->path]))
                        {
                            for ($i=0;$i<count($this->pages[$reallink->path]->classelements);$i++)
                            {
                                if ($this->pages[$reallink->path]->classelements[$i]->type == str_replace('link','',phpDocumentor_get_class($reallink)) && $this->pages[$reallink->path]->classelements[$i]->getName() == $reallink->name)
                                {
                                    $this->pages[$reallink->path]->classelements[$i]->docblock->addUsedBy($element[0]->getLink($converter,false,true), $element[1]);
//                                   debug('added @usedby to '.str_replace('link','',phpDocumentor_get_class($reallink)).' '.$reallink->name);
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }
    }
    
    /**
     * Interface to the Converter
     *
     * This function simply passes {@link $pages} and {@link package_pages} to
     * the walk() method, and then calls the Output() method.  Note that
     * Output() is not required to do anything, and in fact doesn't in
     * HTMLframesConverter.
     * @uses Converter::walk() passes {@link $pages} and {@link $package_pages}
     * @uses Converter::Output()
     */
    function Convert($title, $converter)
    {
        $converter->walk($this->pages, $this->package_pages);
        $converter->Output($title);
    }
    
    /**
     * Clean up classes
     *
     * {@source}
     * @access private
     * @uses Classes::Inherit() passes $this
     */
    function fixClasses()
    {
        $this->classes->Inherit($this);
    }
    
    /**
     * Clean up Procedural Pages
     * {@source}
     * @access private
     * @uses ProceduralPages::setupPages() passes $this
     */
    function fixProcPages()
    {
        $this->proceduralpages->setupPages($this);
    }
    
    /**
     * If the parent class of $class is in a different package, adds it to the
     * {@link $package_parents} array
     * @param parserClass &$class
     */
    function addPackageParent(&$class)
    {
        if (!is_array($class->parent)) return;
        $par = $this->classes->getClass($class->parent[1], $class->parent[0]);
        if ($class->docblock->package == $par->docblock->package) return;
        $this->package_parents[$class->docblock->package] = $par->docblock->package;
        if (!isset($this->package_parents[$par->docblock->package]) || !$this->package_parents[$par->docblock->package]) $this->package_parents[$par->docblock->package] = false;
    }
    
    /**
     * Add a converter name to use to the list of converters
     *
     * Sets up the {@link $converters} array.
     * {@internal
     * First, the Converter's file is included, and then, if successful,
     * the converter classname is tested for existance.  If all is good,
     * then the templates are added to the list of converters/templates to use}}
     * @param string $output output format (HTML, PDF, XML).  Must be all caps
     * @param string $name Converter name (frames, for example, is the name of
     *                     HTMLframesConverter)
     * @param string $template template to use, should be a relative path to the
     *                         templates dir (like DOM/default)
     */
    function addConverter($output,$name,$template)
    {
        if (strpos($name,PATH_DELIMITER))
        {
            $parent = explode(PATH_DELIMITER,$name);
            $parent = $parent[0];
            if ('@VER@' != '@'.'VER@') {
                $filename = 'PhpDocumentor/phpDocumentor/Converters' .
                    PATH_DELIMITER . $output . PATH_DELIMITER . $parent . PATH_DELIMITER . $output . $parent . "Converter" . ".inc";
                if (Io::isIncludeable($filename))
                {
                    include_once($filename);
                }
            } else {
                $filename = str_replace('\\','/',$GLOBALS['_phpDocumentor_install_dir']) . '/phpDocumentor/Converters' .
                    PATH_DELIMITER . $output . PATH_DELIMITER . $parent . PATH_DELIMITER . $output . $parent . "Converter" . ".inc";
                if (file_exists($filename) && is_readable($filename))
                {
                    include_once($filename);
                }
            }
            if (!class_exists($output . $parent . 'Converter'))
            {
                addError(PDERROR_CONVERTER_NOT_FOUND,"parent Converter ".$output . $parent . "Converter of child Converter ".$output . str_replace(PATH_DELIMITER,'',$name) . "Converter");
            }
        }
        $filename = str_replace('\\', '/', $GLOBALS['_phpDocumentor_install_dir']) . '/phpDocumentor/Converters' .
             PATH_DELIMITER . $output . PATH_DELIMITER . $name . PATH_DELIMITER . $output .
             str_replace(PATH_DELIMITER, '', $name) . "Converter" . ".inc";
        if (file_exists($filename) && is_readable($filename))
        {
            include_once($filename);
        }
        if (class_exists($output . str_replace(PATH_DELIMITER,'',$name) . 'Converter'))
        {
            $this->converters[$output][$output . str_replace(PATH_DELIMITER,'',$name) . "Converter"][] = $template;
        } else
        {
            addError(PDERROR_CONVERTER_NOT_FOUND,$output . str_replace(PATH_DELIMITER,'',$name) . "Converter");
        }
    }

    /**
     * does a natural case sort on two {@link parserElement} descendants
     *
     * @param    mixed    $a
     * @param    mixed    $b
     * @return    int
     * @see        generateElementIndex()
     */
    function elementCmp ($a, $b)
    {
        return strnatcasecmp($a->getName(), $b->getName());
    }
    
    /**
     * does a natural case sort on two class elements (either
     * {@link parserClass, parserMethod} or {@link parserVar}
     *
     * @param    mixed    $a
     * @param    mixed    $b
     * @return    int
     * @see        generateElementIndex()
     */
    function ClasselementCmp ($a, $b)
    {
        if (phpDocumentor_get_class($a) == 'parserclass') $atest = $a->name; else $atest = $a->class;
        if (phpDocumentor_get_class($b) == 'parserclass') $btest = $b->name; else $btest = $b->class;
        
        if(($c = strnatcasecmp($atest, $btest)) != 0) return $c;
        if (phpDocumentor_get_class($a) != 'parserclass') $atest .= $a->name;
        if (phpDocumentor_get_class($b) != 'parserclass') $btest .= $b->name;
        if (phpDocumentor_get_class($a) == 'parsermethod' && phpDocumentor_get_class($b) == 'parsermethod')
        {
            if ($a->isConstructor) return -1;
            if ($b->isConstructor) return 1;
            if ($a->isDestructor) return -1;
            if ($b->isDestructor) return 1;
        }
        return strnatcasecmp($atest,$btest);
    }
    
    /**
     * call this method once parsing has completed.
     *
     * This method calls the private methods fixClasses and fixProcPages, both
     * of which adjust inheritance and package information based on complicated
     * post-parsing rules described in {@link ProceduralPages::setupPages()}
     * and {@link Classes::Inherit()}.  Then, it sorts elements of the $pages
     * array and calls Convert for each Converter in the $converters array
     * @see $converters
     * @see $pages
     * @see Convert()
     */
    function Output ($title = "Generated Documentation")
    {
        $GLOBALS['phpDocumentor_errors']->curfile = false;
        $this->fixClasses();
        $this->fixProcPages();
//        var_dump($this->uses);
//        exit;
        phpDocumentor_out("\nSorting page elements...");
        flush();
        uasort($this->pages,'pagesort');
        foreach($this->pages as $i => $page)
        {
            usort($this->pages[$i]->elements,array($this,'elementCmp'));
            usort($this->pages[$i]->classelements,array($this,'ClasselementCmp'));
        }
        phpDocumentor_out("done\n");
        flush();
        $complicatedout = false;
        if (is_array($this->converters))
        {
            if (count($this->converters) > 1)
            {
                $complicatedout = true;
            }
            phpDocumentor_out("Formatting @uses list...");
            flush();
            $a = new __dummyConverter($this->all_packages, $this->package_parents, $this->classes, $this->proceduralpages, $this->packageoutput, $this->parsePrivate, $this->quietMode, $this->targetDir , '', $this->title);
            $this->_setupUsesList($a);
            unset($a);
            phpDocumentor_out("done\n\n");
            flush();
            foreach($this->converters as $converter => $blah)
            {
                if (is_array($blah))
                {
                    if (count($blah) > 1)
                    {
                        $complicatedout = true;
                    }
                    foreach($blah as $converter => $templates)
                    {
                        foreach($templates as $template)
                        {
                            $extraout = '';
                            if ($complicatedout)
                            {
                                $extraout = SMART_PATH_DELIMITER . $converter;
                            }
                            if (count($templates) > 1)
                            {
                                $extraout .= SMART_PATH_DELIMITER . str_replace(PATH_DELIMITER, SMART_PATH_DELIMITER, substr($template,0,strlen($template) - 1));
                            }
                            $a = new $converter($this->all_packages, $this->package_parents, $this->classes, $this->proceduralpages, $this->packageoutput, $this->parsePrivate, $this->quietMode, $this->targetDir . $extraout, $template, $this->title);
                            if (isset($this->templateBase))
                            {
                                $a->setTemplateBase($this->templateBase, $template);
                            }
                            $a->ric = $this->ric;
                            $a->packagecategories = $this->packagecategories;
                            if (isset($this->tutorials)) $a->setTutorials($this->tutorials);
                            $this->Convert($title, $a);
                            unset($a);
                        }
                    }
                }
            }
        } else
        {
            addErrorDie(PDERROR_NO_CONVERTERS);
        }
    }

    /**
     * Sets the output directory
     *
     * @param string $dir the output directory
     */
    function setTargetDir($dir)
    {
        $this->targetDir = $dir;
    }

    /**
     * Sets the template base directory
     *
     * @param string $dir the template base directory
     * @tutorial phpDocumentor.howto.pkg#using.command-line.templatebase
     */
    function setTemplateBase($dir)
    {
        $this->templateBase = $dir;
    }

    /**
     * set parsing information output mode (quiet or verbose)
     *
     * If set to false, no parsing information (parsing /php/file/thisfile.php,
     * Converting etc.) will be displayed.
     * Useful for cron jobs
     * @param    bool $quietMode
     */
    function setQuietMode($quietMode)
    {
        $this->quietMode = $quietMode;
    }
    
    /**
     * set display of elements marked with @access private
     *
     * If set to true, elements will be displayed
     * @param    bool $parse
     */
    function setParsePrivate($parse)
    {
        $this->parsePrivate = $parse;
    }
}

/** @access private */
function pagesort($a, $b)
{
    return strnatcasecmp($a->parent->file,$b->parent->file);
}
?>