@@ -37,6 +37,10 @@ StrConstant pkgFolder = "root:Packages:CodeBrowser"
37
37
// second column: full declaration of the function/macro
38
38
// one row for each function/macro
39
39
StrConstant declarations = "declarations"
40
+ // 2D Wave
41
+ // first column: marker description
42
+ // second column: function comment
43
+ StrConstant helpWave = "help"
40
44
// 1D Wave in each row having the line of the function or -1 for macros
41
45
StrConstant declarationLines = "lines"
42
46
// database-like global multidimensional waves for storing parsing results to minimize time.
@@ -327,15 +331,17 @@ Function addDecoratedFunctions(module, procedure, declWave, lineWave)
327
331
328
332
String options, funcList
329
333
string func, funcDec, fi
330
- string threadsafeTag, specialTag, params, subtypeTag, returnType
334
+ string threadsafeTag, specialTag, params, subtypeTag, returnType, entityType
331
335
variable i , idx, numMatches, numEntries
332
336
337
+ Wave /T helpWave = getHelpWave ()
338
+
333
339
// list normal, userdefined, override and static functions
334
340
options = "KIND:18,WIN:" + procedure
335
341
funcList = FunctionList ( "*" , ";" , options)
336
342
numMatches = ItemsInList ( funcList)
337
343
numEntries = DimSize ( declWave, 0 )
338
- Redimension / N= ( numEntries + numMatches, -1 ) declWave, lineWave
344
+ Redimension / N= ( numEntries + numMatches, -1 ) declWave, lineWave, helpWave
339
345
340
346
idx = numEntries
341
347
for ( i = 0; i < numMatches; i += 1 )
@@ -352,8 +358,11 @@ Function addDecoratedFunctions(module, procedure, declWave, lineWave)
352
358
specialTag = interpretSpecialTag ( StringByKey ( "SPECIAL" , fi))
353
359
subtypeTag = interpretSubtypeTag ( StringByKey ( "SUBTYPE" , fi))
354
360
params = interpretParameters ( fi)
355
- declWave[ idx][ 0 ] = createMarkerForType ( "function" + specialTag + threadsafeTag)
361
+ entityType = "function" + specialTag + threadsafeTag
362
+ declWave[ idx][ 0 ] = createMarkerForType ( entityType)
356
363
declWave[ idx][ 1 ] = formatDecl ( func, params, subtypeTag, returnType)
364
+ helpWave[ idx][ 0 ] = entityType
365
+ helpWave[ idx][ 1 ] = AddHTML ( TrimFunctionComment ( getFunctionLine ( - inf , fi)))
357
366
lineWave[ idx] = NumberByKey ( "PROCLINE" , fi)
358
367
idx += 1
359
368
endfor
@@ -372,6 +381,8 @@ Function addDecoratedConstants(module, procedureWithoutModule, declWave, lineWav
372
381
Variable numLines, i , idx, numEntries, numMatches
373
382
String procText, re, def, name
374
383
384
+ Wave /T helpWave = getHelpWave ()
385
+
375
386
// get procedure code
376
387
procText = getProcedureText ( "" , 0, module, procedureWithoutModule)
377
388
numLines = ItemsInList ( procText, "\r " )
@@ -392,7 +403,7 @@ Function addDecoratedConstants(module, procedureWithoutModule, declWave, lineWav
392
403
393
404
numMatches = DimSize ( wavLineNumber, 0 )
394
405
numEntries = DimSize ( declWave, 0 )
395
- Redimension / N= ( numEntries + numMatches, -1 ) declWave, lineWave
406
+ Redimension / N= ( numEntries + numMatches, -1 ) declWave, lineWave, helpWave
396
407
397
408
idx = numEntries
398
409
for ( i = 0; i < numMatches; i += 1 )
@@ -415,6 +426,8 @@ Function addDecoratedMacros(module, procedureWithoutModule, declWave, lineWave)
415
426
Variable numLines, idx, numEntries, numMatches
416
427
String procText, re, def, name, arguments, type
417
428
429
+ Wave /T helpWave = getHelpWave ()
430
+
418
431
// get procedure code
419
432
procText = getProcedureText ( "" , 0, module, procedureWithoutModule)
420
433
numLines = ItemsInList ( procText, "\r " )
@@ -437,7 +450,7 @@ Function addDecoratedMacros(module, procedureWithoutModule, declWave, lineWave)
437
450
438
451
numMatches = DimSize ( wavLineNumber, 0 )
439
452
numEntries = DimSize ( declWave, 0 )
440
- Redimension / N= ( numEntries + numMatches, -1 ) declWave, lineWave
453
+ Redimension / N= ( numEntries + numMatches, -1 ) declWave, lineWave, helpWave
441
454
442
455
for ( idx = numEntries; idx < ( numEntries + numMatches) ; idx += 1 )
443
456
SplitString / E= re text[ wavLineNumber[( idx - numEntries)]] , def, name, arguments, type
@@ -461,6 +474,8 @@ Function addDecoratedStructure(module, procedureWithoutModule, declWave, lineWav
461
474
variable numLines, idx, numEntries, numMatches
462
475
string procText, reStart, reEnd, name, StaticKeyword
463
476
477
+ Wave /T helpWave = getHelpWave ()
478
+
464
479
// get procedure code
465
480
procText = getProcedureText ( "" , 0, module, procedureWithoutModule)
466
481
numLines = ItemsInList ( procText, "\r " )
@@ -502,7 +517,7 @@ Function addDecoratedStructure(module, procedureWithoutModule, declWave, lineWav
502
517
endif
503
518
504
519
numEntries = DimSize ( declWave, 0 )
505
- Redimension / N= ( numEntries + numMatches, -1 ) declWave, lineWave
520
+ Redimension / N= ( numEntries + numMatches, -1 ) declWave, lineWave, helpWave
506
521
507
522
for ( idx = numEntries; idx < ( numEntries + numMatches) ; idx +=1 )
508
523
SplitString / E= reStart text[ wavStructureStart[( idx - numEntries)]] , StaticKeyword, name
@@ -531,6 +546,8 @@ Function addDecoratedMenu(module, procedureWithoutModule, declWave, lineWave)
531
546
String procText, re, def, name, type
532
547
String currentMenu = ""
533
548
549
+ Wave /T helpWave = getHelpWave ()
550
+
534
551
// get procedure code
535
552
procText = getProcedureText ( "" , 0, module, procedureWithoutModule)
536
553
numLines = ItemsInList ( procText, "\r " )
@@ -551,7 +568,7 @@ Function addDecoratedMenu(module, procedureWithoutModule, declWave, lineWave)
551
568
552
569
numMatches = DimSize ( wavLineNumber, 0 )
553
570
numEntries = DimSize ( declWave, 0 )
554
- Redimension / N= ( numEntries + numMatches, -1 ) declWave, lineWave
571
+ Redimension / N= ( numEntries + numMatches, -1 ) declWave, lineWave, helpWave
555
572
556
573
for ( idx = numEntries; idx < ( numEntries + numMatches) ; idx += 1 )
557
574
SplitString / E= re text[ wavLineNumber[( idx - numEntries)]] , def, name, type
@@ -646,15 +663,18 @@ Function/S getVariableName(strDefinition)
646
663
return strVariableName
647
664
End
648
665
649
- static Function resetLists ( decls, lines)
666
+ static Function resetLists ( decls, lines, helps )
650
667
Wave /T decls
651
668
Wave /D lines
652
- Redimension / N= ( 0, -1 ) decls, lines
669
+ Wave /T helps
670
+ Redimension / N= ( 0, -1 ) decls, lines, helps
653
671
End
654
672
655
- static Function sortListByLineNumber ( decls, lines)
673
+ // @todo IgorPro >= 7 supports SortColumns
674
+ static Function sortListByLineNumber ( decls, lines, helps)
656
675
Wave /T decls
657
676
Wave /D lines
677
+ Wave /T helps
658
678
659
679
// check if sort is necessary
660
680
if ( Dimsize ( decls, 0 ) * Dimsize ( lines, 0 ) == 0 )
@@ -663,14 +683,20 @@ static Function sortListByLineNumber(decls, lines)
663
683
664
684
Duplicate / T/ FREE/ R= [][ 0 ] decls, declCol0
665
685
Duplicate / T/ FREE/ R= [][ 1 ] decls, declCol1
666
- Sort / A lines, lines, declCol0, declCol1
686
+ Duplicate / T/ FREE/ R= [][ 0 ] helps, helpCol0
687
+ Duplicate / T/ FREE/ R= [][ 1 ] helps, helpCol1
688
+ Sort / A lines, lines, declCol0, declCol1, helpCol0, helpCol1
667
689
decls[][ 0 ] = declCol0 [ p][ 0 ]
668
690
decls[][ 1 ] = declCol1 [ p][ 0 ]
691
+ helps[][ 0 ] = helpCol0 [ p][ 0 ]
692
+ helps[][ 1 ] = helpCol1 [ p][ 0 ]
669
693
End
670
694
671
- static Function sortListByName ( decls, lines)
695
+ // @todo IgorPro >= 7 supports SortColumns
696
+ static Function sortListByName ( decls, lines, helps)
672
697
Wave /T decls
673
698
Wave /D lines
699
+ Wave /T helps
674
700
675
701
// check if sort is necessary
676
702
if ( Dimsize ( decls, 0 ) * Dimsize ( lines, 0 ) == 0 )
@@ -679,9 +705,13 @@ static Function sortListByName(decls, lines)
679
705
680
706
Duplicate / T/ FREE/ R= [][ 0 ] decls, declCol0
681
707
Duplicate / T/ FREE/ R= [][ 1 ] decls, declCol1
682
- Sort / A declCol1, lines, declCol0, declCol1
708
+ Duplicate / T/ FREE/ R= [][ 0 ] helps, helpCol0
709
+ Duplicate / T/ FREE/ R= [][ 1 ] helps, helpCol1
710
+ Sort / A declCol1, lines, declCol0, declCol1, helpCol0, helpCol1
683
711
decls[][ 0 ] = declCol0 [ p][ 0 ]
684
712
decls[][ 1 ] = declCol1 [ p][ 0 ]
713
+ helps[][ 0 ] = helpCol0 [ p][ 0 ]
714
+ helps[][ 1 ] = helpCol1 [ p][ 0 ]
685
715
End
686
716
687
717
// Parses all procedure windows and write into the decl and line waves
@@ -702,9 +732,10 @@ Function/S parseProcedure(procedure, [checksumIsCalculated])
702
732
// load global lists
703
733
Wave /T decls = getDeclWave ()
704
734
Wave /I lines = getLineWave ()
735
+ Wave /T helps = getHelpWave ()
705
736
706
737
// scan and add elements to lists
707
- resetLists ( decls, lines)
738
+ resetLists ( decls, lines, helps )
708
739
addDecoratedFunctions ( procedure. module, procedure. fullName, decls, lines)
709
740
addDecoratedConstants ( procedure. module, procedure. name, decls, lines)
710
741
addDecoratedMacros ( procedure. module, procedure. name, decls, lines)
@@ -721,6 +752,7 @@ static Function saveResults(procedure)
721
752
722
753
Wave /T declWave = getDeclWave ()
723
754
Wave /I lineWave = getLineWave ()
755
+ Wave /T helpWave = getHelpWave ()
724
756
725
757
Wave /WAVE SaveWavesWave = getSaveWaves ()
726
758
Wave /T SaveStringsWave = getSaveStrings ()
@@ -745,10 +777,12 @@ static Function saveResults(procedure)
745
777
// save Results. Waves as References to free waves and the Id-Identifier
746
778
Duplicate / FREE declWave myFreeDeclWave
747
779
Duplicate / FREE lineWave myFreeLineWave
780
+ Duplicate / FREE helpWave myFreeHelpWave
748
781
SaveStringsWave[ procedure. row][ 0 ] = procedure. id
749
782
SaveStringsWave[ procedure. row][ 1 ] = getChecksum ()
750
783
SaveWavesWave[ procedure. row][ 0 ] = myFreeDeclWave
751
784
SaveWavesWave[ procedure. row][ 1 ] = myFreeLineWave
785
+ SaveWavesWave[ procedure. row][ 2 ] = myFreeHelpWave
752
786
SaveVariablesWave[ procedure. row][ 0 ] = 1 // mark as valid
753
787
SaveVariablesWave[ procedure. row][ 1 ] = getParsingTime () // time in micro seconds
754
788
SaveVariablesWave[ procedure. row][ 2 ] = getCheckSumTime () // time in micro seconds
@@ -776,6 +810,7 @@ static Function saveLoad(procedure)
776
810
777
811
Wave /T declWave = getDeclWave ()
778
812
Wave /I lineWave = getLineWave ()
813
+ Wave /T helpWave = getHelpWave ()
779
814
780
815
Wave /WAVE SaveWavesWave = getSaveWaves ()
781
816
Wave /T SaveStringsWave = getSaveStrings ()
@@ -808,16 +843,18 @@ static Function saveLoad(procedure)
808
843
endif
809
844
810
845
numResults = Dimsize ( SaveWavesWave[ procedure. row][ 0 ] , 0 )
811
- Redimension / N= ( numResults, -1 ) declWave, lineWave
846
+ Redimension / N= ( numResults, -1 ) declWave, lineWave, helpWave
812
847
if ( numResults == 0 )
813
848
debugPrint ( "no elements in save state" )
814
849
return 0
815
850
endif
816
851
817
852
WAVE /T load0 = SaveWavesWave[ procedure. row][ 0 ]
818
853
WAVE /I load1 = SaveWavesWave[ procedure. row][ 1 ]
854
+ WAVE /T load2 = SaveWavesWave[ procedure. row][ 2 ]
819
855
declWave[][ 0, 1 ] = load0 [ p][ q]
820
856
lineWave[] = load1 [ p]
857
+ helpWave[][ 0, 1 ] = load2 [ p][ q]
821
858
822
859
debugPrint ( "save state loaded successfully" )
823
860
return 1
@@ -958,6 +995,56 @@ Function/S getFunctionLine(lineNo, funcInfo)
958
995
return StringFromList ( lineNo, context, "\r " )
959
996
End
960
997
998
+ // return only fully-commented lines from the given input
999
+ Function /S TrimFunctionComment ( context)
1000
+ string context
1001
+
1002
+ string comment = GrepList ( context, "^(?i)//.*$" , 0, "\r " )
1003
+ return RemoveEnding ( comment, "\r " )
1004
+ End
1005
+
1006
+ // add basic html
1007
+ Function /S AddHTML ( context)
1008
+ string context
1009
+
1010
+ string line, html, re
1011
+ string str0, str1, str2, str3, str4
1012
+ variable n, lines
1013
+
1014
+ html = ""
1015
+ lines = ItemsInList ( context, "\r " )
1016
+ for ( n = 0; n < lines; n += 1 )
1017
+ line = StringFromList ( n, context, "\r " )
1018
+ re = "\s *([\/ ]{2,})\s ?(.*)"
1019
+ SplitString / E= ( re) line, str0, str1
1020
+ if ( V_flag != 2 )
1021
+ break
1022
+ endif
1023
+ line = str1
1024
+ if ( strlen ( str0 ) == 3 ) // Doxygen comments
1025
+ re = "(?i)(.*@param(?:\[ (?:in|out)\] )?\s +)(\w +)(\s .*)"
1026
+ SplitString / E= ( re) line, str0, str1, str2
1027
+ if ( V_flag == 3 )
1028
+ line = str0
1029
+ line += "<b>" + str1 + "</b> "
1030
+ line += str2
1031
+ endif
1032
+ re = "(?i)(.*)@(\w +)(\s .*)"
1033
+ SplitString / E= ( re) line, str0, str1, str2
1034
+ if ( V_flag == 3 )
1035
+ line = str0
1036
+ line += "<b>@</b><i>" + str1 + "</i>"
1037
+ line += str2
1038
+ endif
1039
+ endif
1040
+ html += line + "<br>"
1041
+ endfor
1042
+ html = RemoveEnding ( html, "<br>" )
1043
+ html = "<code>" + html + "</code>"
1044
+
1045
+ return html
1046
+ End
1047
+
961
1048
// get code of procedure in module
962
1049
//
963
1050
// see `DisplayHelpTopic ( "ProcedureText" ) `
@@ -990,6 +1077,7 @@ Function updateListBoxHook()
990
1077
// load global lists (for sort)
991
1078
Wave /T decls = getDeclWave ()
992
1079
Wave /I lines = getLineWave ()
1080
+ Wave /T helps = getHelpWave ()
993
1081
994
1082
// get procedure information
995
1083
procedure. fullName = getCurrentItem ( procedure = 1 )
@@ -1014,22 +1102,23 @@ Function updateListBoxHook()
1014
1102
// check if search is necessary
1015
1103
searchString = getGlobalStr ( "search" )
1016
1104
if ( strlen ( searchString) > 0 )
1017
- searchAndDelete ( decls, lines, searchString)
1105
+ searchAndDelete ( decls, lines, helps , searchString)
1018
1106
endif
1019
1107
1020
1108
// switch sort type
1021
1109
if ( returnCheckBoxSort ())
1022
- sortListByName ( decls, lines)
1110
+ sortListByName ( decls, lines, helps )
1023
1111
else
1024
- sortListByLineNumber ( decls, lines)
1112
+ sortListByLineNumber ( decls, lines, helps )
1025
1113
endif
1026
1114
1027
1115
return DimSize ( decls, 0 )
1028
1116
End
1029
1117
1030
- Function searchAndDelete ( decls, lines, searchString)
1118
+ Function searchAndDelete ( decls, lines, helps, searchString)
1031
1119
Wave /T decls
1032
1120
Wave /I lines
1121
+ Wave /T helps
1033
1122
String searchString
1034
1123
1035
1124
Variable i , numEntries
@@ -1041,16 +1130,16 @@ Function searchAndDelete(decls, lines, searchString)
1041
1130
1042
1131
for ( i = numEntries - 1; i > 0; i -= 1 )
1043
1132
if ( strsearch ( decls[ i ][ 1 ] , searchString, 0, 2 ) == -1 )
1044
- DeletePoints / M=0 i , 1, decls, lines
1133
+ DeletePoints / M=0 i , 1, decls, lines, helps
1045
1134
endif
1046
1135
endfor
1047
1136
1048
1137
// prevent loss of dimension if no match was found at all.
1049
1138
if ( strsearch ( decls[ 0 ][ 1 ] , searchString, 0, 2 ) == -1 )
1050
1139
if ( Dimsize ( decls, 0 ) == 1 )
1051
- Redimension / N= ( 0, -1 ) decls, lines
1140
+ Redimension / N= ( 0, -1 ) decls, lines, helps
1052
1141
else
1053
- DeletePoints / M=0 i , 1, decls, lines
1142
+ DeletePoints / M=0 i , 1, decls, lines, helps
1054
1143
endif
1055
1144
endif
1056
1145
End
@@ -1129,6 +1218,20 @@ Function/S getModuleList()
1129
1218
return moduleList
1130
1219
End
1131
1220
1221
+ // get help wave: after parsing the function comment is stored here
1222
+ //
1223
+ // Return refrence to (text) Wave/T
1224
+ Function /Wave getHelpWave ()
1225
+ DFREF dfr = createDFWithAllParents ( pkgFolder)
1226
+ WAVE /Z/ T/ SDFR= dfr wv = $ helpWave
1227
+
1228
+ if ( ! WaveExists ( wv))
1229
+ Make / T/ N= ( 128, 2 ) dfr:$ helpWave/Wave = wv
1230
+ endif
1231
+
1232
+ return wv
1233
+ End
1234
+
1132
1235
// Returns declarations: after parsing the object names and variables are stored in this wave.
1133
1236
// Return refrence to (text) Wave/T
1134
1237
Function /Wave getDeclWave ()
@@ -1177,11 +1280,18 @@ static Function/Wave getSaveWaves()
1177
1280
DFREF dfr = createDFWithAllParents ( pkgFolder)
1178
1281
WAVE /Z/ WAVE /SDFR= dfr wv = $ CsaveWaves
1179
1282
1180
- if ( ! WaveExists ( wv))
1181
- Make / WAVE /N= ( 0,2 ) dfr:$ CsaveWaves/Wave = wv // wave of wave references
1283
+ if ( WaveExists ( wv))
1284
+ if ( DimSize ( wv, 1 ) == 2 )
1285
+ // update version 0 to 1
1286
+ Redimension / N= ( -1, 3 ) wv
1287
+ endif
1288
+ elseif ( ! WaveExists ( wv))
1289
+ //version 1
1290
+ Make / WAVE /N= ( 0,3 ) dfr:$ CsaveWaves/Wave = wv // wave of wave references
1182
1291
// Wave with Free Waves:
1183
1292
// Column 1: decl (a (text) Wave/T with the results of parsing the procedure file)
1184
- // Column 1: line (a (integer) Wave/I with the corresponding line numbers within the procedure file)
1293
+ // Column 2: line (a (integer) Wave/I with the corresponding line numbers within the procedure file)
1294
+ // Column 3: help (a (text) Wave/T with the corresponding function comment)
1185
1295
endif
1186
1296
1187
1297
return wv
0 commit comments