@@ -53,9 +53,11 @@ static strConstant cstrTypes = "Variable|String|WAVE|NVAR|SVAR|DFREF|FUNCREF|STR
53
53
// Loosely based on the WM procedure from the documentation
54
54
// Returns a human readable string for the given parameter/return type.
55
55
// See the documentation for FunctionInfo for the exact values.
56
- Function /S interpretParamType ( ptype, paramOrReturn)
56
+ Function /S interpretParamType ( ptype, paramOrReturn, funcInfo )
57
57
variable ptype, paramOrReturn
58
+ string funcInfo
58
59
60
+ string typeName
59
61
string typeStr = ""
60
62
61
63
if ( paramOrReturn != 0 && paramOrReturn != 1 )
@@ -117,7 +119,11 @@ Function/S interpretParamType(ptype, paramOrReturn)
117
119
elseif ( ptype & 0x100 )
118
120
typeStr += "dfref"
119
121
elseif ( ptype & 0x200 )
120
- typeStr += "struct"
122
+ if ( GetStructureArgument ( funcInfo, typeName))
123
+ typeStr += typeName
124
+ else
125
+ typeStr += "struct"
126
+ endif
121
127
elseif ( ptype & 0x400 )
122
128
typeStr += "funcref"
123
129
endif
@@ -191,7 +197,7 @@ Function/S interpretParameters(funcInfo)
191
197
192
198
for ( i = 0; i < numParams; i += 1 )
193
199
sprintf key, "PARAM_%d_TYPE" , i
194
- paramType = interpretParamType ( NumberByKey ( key, funcInfo) , 1 )
200
+ paramType = interpretParamType ( NumberByKey ( key, funcInfo) , 1, funcInfo )
195
201
196
202
if ( i == numParams - numOptParams)
197
203
str += "["
@@ -211,6 +217,34 @@ Function/S interpretParameters(funcInfo)
211
217
return str
212
218
End
213
219
220
+ // check if Function has as a structure as first parameter
221
+ //
222
+ // the structure definition has to be in the first line after the function definition
223
+ //
224
+ // @param[in] funcInfo output of FunctionInfo for the function in question
225
+ // @param[out] structureName matched name of the structure as string.
226
+ // Not changed if 0 is returned.
227
+ //
228
+ // @returns 1 if function has such a parameter, 0 otherwise
229
+ Function GetStructureArgument ( funcInfo, structureName)
230
+ string funcInfo
231
+ string & structureName
232
+
233
+ string declaration, re, str0
234
+
235
+ if ( NumberByKey ( "PARAM_0_TYPE" , funcInfo) & ( 0x200 | 0x1000 )) // struct | pass-by-reference
236
+ declaration = getFunctionLine ( 1, funcInfo)
237
+ re = "(?i)^\s *struct\s +(\w +)\s +"
238
+ SplitString / E= ( re) declaration, str0
239
+ if ( V_flag == 1 )
240
+ structureName = str0
241
+ return 1
242
+ endif
243
+ endif
244
+
245
+ return 0
246
+ End
247
+
214
248
// Returns a cmd for the given fill *and* stroke color
215
249
Function /S getColorDef ( color)
216
250
string color
@@ -268,15 +302,15 @@ Function/S createMarkerForType(type)
268
302
End
269
303
270
304
// Pretty printing of function/macro with additional info
271
- Function /S formatDecl ( funcOrMacro, params, subtypeTag, [ returnType] )
305
+ Function /S formatDecl ( funcOrMacro, params, subtypeTag, returnType)
272
306
string funcOrMacro, params, subtypeTag, returnType
273
307
274
308
if ( ! isEmpty ( subtypeTag))
275
309
subtypeTag = " : " + subtypeTag
276
310
endif
277
311
278
312
string decl
279
- if ( ParamIsDefault ( returnType))
313
+ if ( strlen ( returnType) == 0 )
280
314
sprintf decl, "%s(%s)%s" , funcOrMacro, params, subtypeTag
281
315
else
282
316
sprintf decl, "%s(%s) -> %s%s" , funcOrMacro, params, returnType, subtypeTag
@@ -313,13 +347,13 @@ Function addDecoratedFunctions(module, procedure, declWave, lineWave)
313
347
if ( isEmpty ( fi))
314
348
debugPrint ( "macro or other error for " + module + "#" + func)
315
349
endif
316
- returnType = interpretParamType ( NumberByKey ( "RETURNTYPE" , fi) ,0 )
350
+ returnType = interpretParamType ( NumberByKey ( "RETURNTYPE" , fi) , 0, fi )
317
351
threadsafeTag = interpretThreadsafeTag ( StringByKey ( "THREADSAFE" , fi))
318
352
specialTag = interpretSpecialTag ( StringByKey ( "SPECIAL" , fi))
319
353
subtypeTag = interpretSubtypeTag ( StringByKey ( "SUBTYPE" , fi))
320
354
params = interpretParameters ( fi)
321
355
declWave[ idx][ 0 ] = createMarkerForType ( "function" + specialTag + threadsafeTag)
322
- declWave[ idx][ 1 ] = formatDecl ( func, params, subtypeTag, returnType = returnType )
356
+ declWave[ idx][ 1 ] = formatDecl ( func, params, subtypeTag, returnType)
323
357
lineWave[ idx] = NumberByKey ( "PROCLINE" , fi)
324
358
idx += 1
325
359
endfor
@@ -339,7 +373,7 @@ Function addDecoratedConstants(module, procedureWithoutModule, declWave, lineWav
339
373
String procText, re, def, name
340
374
341
375
// get procedure code
342
- procText = getProcedureText ( module, procedureWithoutModule)
376
+ procText = getProcedureText ( "" , 0, module, procedureWithoutModule)
343
377
numLines = ItemsInList ( procText, "\r " )
344
378
345
379
// search code and return wavLineNumber
@@ -382,7 +416,7 @@ Function addDecoratedMacros(module, procedureWithoutModule, declWave, lineWave)
382
416
String procText, re, def, name, arguments, type
383
417
384
418
// get procedure code
385
- procText = getProcedureText ( module, procedureWithoutModule)
419
+ procText = getProcedureText ( "" , 0, module, procedureWithoutModule)
386
420
numLines = ItemsInList ( procText, "\r " )
387
421
388
422
// search code and return wavLineNumber
@@ -428,7 +462,7 @@ Function addDecoratedStructure(module, procedureWithoutModule, declWave, lineWav
428
462
string procText, reStart, reEnd, name, StaticKeyword
429
463
430
464
// get procedure code
431
- procText = getProcedureText ( module, procedureWithoutModule)
465
+ procText = getProcedureText ( "" , 0, module, procedureWithoutModule)
432
466
numLines = ItemsInList ( procText, "\r " )
433
467
if ( numLines == 0 )
434
468
debugPrint ( "no Content in Procedure " + procedureWithoutModule)
@@ -498,7 +532,7 @@ Function addDecoratedMenu(module, procedureWithoutModule, declWave, lineWave)
498
532
String currentMenu = ""
499
533
500
534
// get procedure code
501
- procText = getProcedureText ( module, procedureWithoutModule)
535
+ procText = getProcedureText ( "" , 0, module, procedureWithoutModule)
502
536
numLines = ItemsInList ( procText, "\r " )
503
537
504
538
// search code and return wavLineNumber
@@ -720,7 +754,7 @@ static Function saveResults(procedure)
720
754
SaveVariablesWave[ procedure. row][ 2 ] = getCheckSumTime () // time in micro seconds
721
755
722
756
// if function list could not be acquired don't save the checksum
723
- if ( ! numpnts ( declWave) || ! cmpstr ( declWave[ 0 ][ 1 ] , "Procedures Not Compiled() -> " ))
757
+ if ( ! DimSize ( declWave, 0 ) || ! cmpstr ( declWave[ 0 ][ 1 ] , "Procedures Not Compiled()" )) ///@todo check in all rows.
724
758
DebugPrint ( "Function list is not complete" )
725
759
SaveStringsWave[ procedure. row][ 1 ] = "no checksum"
726
760
endif
@@ -878,19 +912,57 @@ Function/S nicifyProcedureList(list)
878
912
return niceList
879
913
End
880
914
881
- // returns code of procedure in module
882
- Function /S getProcedureText ( module, procedureWithoutModule)
883
- String module, procedureWithoutModule
884
- String strProcedure
915
+ // Get the specified line of code from a function
916
+ //
917
+ // @see getProcedureText
918
+ //
919
+ // @param funcInfo output of FunctionInfo for the function in question
920
+ // @param lineNo line number relative to the function definition
921
+ // set to -1 to return lines before the procedure that are not part of the preceding macro or function
922
+ // see `DisplayHelpTopic ( "ProcedureText" ) `
923
+ //
924
+ // @returns lines of code from a function inside a procedure file
925
+ Function /S getFunctionLine ( lineNo, funcInfo)
926
+ variable lineNo
927
+ string funcInfo
885
928
886
- if ( isProcGlobal ( module))
887
- debugPrint ( module + " is in ProcGlobal" )
888
- strProcedure = ProcedureText ( "" , 0, procedureWithoutModule)
889
- return strProcedure
890
- else
891
- debugPrint ( procedureWithoutModule + " is in " + module)
892
- return ProcedureText ( "" , 0, procedureWithoutModule + " [" + module + "]" )
929
+ string funcName, module, procedure, context
930
+ variable linesOfContext
931
+
932
+ funcName = StringByKey ( "NAME" , funcInfo)
933
+ module = StringByKey ( "INDEPENDENTMODULE" , funcInfo)
934
+ procedure = StringByKey ( "PROCWIN" , funcInfo)
935
+
936
+ linesOfContext = lineNo < 0 ? lineNo : 0
937
+ context = getProcedureText ( funcName, linesOfContext, module, procedure)
938
+
939
+ if ( lineNo < 0 )
940
+ return context
893
941
endif
942
+
943
+ return StringFromList ( lineNo, context, "\r " )
944
+ End
945
+
946
+ // get code of procedure in module
947
+ //
948
+ // see `DisplayHelpTopic ( "ProcedureText" ) `
949
+ //
950
+ // @param funcName Name of Function. Leave blank to get full procedure text
951
+ // @param linesOfContext line numbers in addition to the function definition. Set to 0 to return only the function.
952
+ // set to -1 to return lines before the procedure that are not part of the preceding macro or function
953
+ // @param module independent module
954
+ // @param procedure procedure without module definition
955
+ // @return multi-line string with function definition
956
+ Function /S getProcedureText ( funcName, linesOfContext, module, procedure)
957
+ string funcName, module, procedure
958
+ variable linesOfContext
959
+
960
+ if ( ! isProcGlobal ( module))
961
+ debugPrint ( procedure + " is not in ProcGlobal" )
962
+ procedure = procedure + " [" + module + "]"
963
+ endif
964
+
965
+ return ProcedureText ( funcName, linesOfContext, procedure)
894
966
End
895
967
896
968
// Returns 1 if the procedure file has content which we can show, 0 otherwise
979
1051
980
1052
// Shows the line/function for the function/macro with the given index into decl
981
1053
// With no index just the procedure file is shown
982
- Function showCode ( procedure,[ index] )
1054
+ Function showCode ( procedure, [ index] )
983
1055
string procedure
984
1056
variable index
985
1057
@@ -1156,8 +1228,7 @@ static Function setCheckSum(procedure)
1156
1228
1157
1229
timer = timerStart ()
1158
1230
1159
- procText = getProcedureText ( procedure. module, procedure. name)
1160
- procText = ProcedureText ( "" , 0, procedure. fullname)
1231
+ procText = getProcedureText ( "" , 0, procedure. module, procedure. name)
1161
1232
returnValue = setGlobalStr ( "parsingChecksum" , Hash ( procText, 1 ))
1162
1233
1163
1234
setCheckSumTime ( timerStop ( timer))
0 commit comments