@@ -53,9 +53,11 @@ static strConstant cstrTypes = "Variable|String|WAVE|NVAR|SVAR|DFREF|FUNCREF|STR
5353// Loosely based on the WM procedure from the documentation
5454// Returns a human readable string for the given parameter/return type.
5555// See the documentation for FunctionInfo for the exact values.
56- Function /S interpretParamType ( ptype, paramOrReturn)
56+ Function /S interpretParamType ( ptype, paramOrReturn, funcInfo )
5757 variable ptype, paramOrReturn
58+ string funcInfo
5859
60+ string typeName
5961 string typeStr = ""
6062
6163 if ( paramOrReturn != 0 && paramOrReturn != 1 )
@@ -117,7 +119,11 @@ Function/S interpretParamType(ptype, paramOrReturn)
117119 elseif ( ptype & 0x100 )
118120 typeStr += "dfref"
119121 elseif ( ptype & 0x200 )
120- typeStr += "struct"
122+ if ( GetStructureArgument ( funcInfo, typeName))
123+ typeStr += typeName
124+ else
125+ typeStr += "struct"
126+ endif
121127 elseif ( ptype & 0x400 )
122128 typeStr += "funcref"
123129 endif
@@ -191,7 +197,7 @@ Function/S interpretParameters(funcInfo)
191197
192198 for ( i = 0; i < numParams; i += 1 )
193199 sprintf key, "PARAM_%d_TYPE" , i
194- paramType = interpretParamType ( NumberByKey ( key, funcInfo) , 1 )
200+ paramType = interpretParamType ( NumberByKey ( key, funcInfo) , 1, funcInfo )
195201
196202 if ( i == numParams - numOptParams)
197203 str += "["
@@ -211,6 +217,34 @@ Function/S interpretParameters(funcInfo)
211217 return str
212218End
213219
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+
214248// Returns a cmd for the given fill *and* stroke color
215249Function /S getColorDef ( color)
216250 string color
@@ -268,15 +302,15 @@ Function/S createMarkerForType(type)
268302End
269303
270304// Pretty printing of function/macro with additional info
271- Function /S formatDecl ( funcOrMacro, params, subtypeTag, [ returnType] )
305+ Function /S formatDecl ( funcOrMacro, params, subtypeTag, returnType)
272306 string funcOrMacro, params, subtypeTag, returnType
273307
274308 if ( ! isEmpty ( subtypeTag))
275309 subtypeTag = " : " + subtypeTag
276310 endif
277311
278312 string decl
279- if ( ParamIsDefault ( returnType))
313+ if ( strlen ( returnType) == 0 )
280314 sprintf decl, "%s(%s)%s" , funcOrMacro, params, subtypeTag
281315 else
282316 sprintf decl, "%s(%s) -> %s%s" , funcOrMacro, params, returnType, subtypeTag
@@ -313,13 +347,13 @@ Function addDecoratedFunctions(module, procedure, declWave, lineWave)
313347 if ( isEmpty ( fi))
314348 debugPrint ( "macro or other error for " + module + "#" + func)
315349 endif
316- returnType = interpretParamType ( NumberByKey ( "RETURNTYPE" , fi) ,0 )
350+ returnType = interpretParamType ( NumberByKey ( "RETURNTYPE" , fi) , 0, fi )
317351 threadsafeTag = interpretThreadsafeTag ( StringByKey ( "THREADSAFE" , fi))
318352 specialTag = interpretSpecialTag ( StringByKey ( "SPECIAL" , fi))
319353 subtypeTag = interpretSubtypeTag ( StringByKey ( "SUBTYPE" , fi))
320354 params = interpretParameters ( fi)
321355 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)
323357 lineWave[ idx] = NumberByKey ( "PROCLINE" , fi)
324358 idx += 1
325359 endfor
@@ -339,7 +373,7 @@ Function addDecoratedConstants(module, procedureWithoutModule, declWave, lineWav
339373 String procText, re, def, name
340374
341375 // get procedure code
342- procText = getProcedureText ( module, procedureWithoutModule)
376+ procText = getProcedureText ( "" , 0, module, procedureWithoutModule)
343377 numLines = ItemsInList ( procText, "\r " )
344378
345379 // search code and return wavLineNumber
@@ -382,7 +416,7 @@ Function addDecoratedMacros(module, procedureWithoutModule, declWave, lineWave)
382416 String procText, re, def, name, arguments, type
383417
384418 // get procedure code
385- procText = getProcedureText ( module, procedureWithoutModule)
419+ procText = getProcedureText ( "" , 0, module, procedureWithoutModule)
386420 numLines = ItemsInList ( procText, "\r " )
387421
388422 // search code and return wavLineNumber
@@ -428,7 +462,7 @@ Function addDecoratedStructure(module, procedureWithoutModule, declWave, lineWav
428462 string procText, reStart, reEnd, name, StaticKeyword
429463
430464 // get procedure code
431- procText = getProcedureText ( module, procedureWithoutModule)
465+ procText = getProcedureText ( "" , 0, module, procedureWithoutModule)
432466 numLines = ItemsInList ( procText, "\r " )
433467 if ( numLines == 0 )
434468 debugPrint ( "no Content in Procedure " + procedureWithoutModule)
@@ -498,7 +532,7 @@ Function addDecoratedMenu(module, procedureWithoutModule, declWave, lineWave)
498532 String currentMenu = ""
499533
500534 // get procedure code
501- procText = getProcedureText ( module, procedureWithoutModule)
535+ procText = getProcedureText ( "" , 0, module, procedureWithoutModule)
502536 numLines = ItemsInList ( procText, "\r " )
503537
504538 // search code and return wavLineNumber
@@ -720,7 +754,7 @@ static Function saveResults(procedure)
720754 SaveVariablesWave[ procedure. row][ 2 ] = getCheckSumTime () // time in micro seconds
721755
722756 // 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.
724758 DebugPrint ( "Function list is not complete" )
725759 SaveStringsWave[ procedure. row][ 1 ] = "no checksum"
726760 endif
@@ -878,19 +912,57 @@ Function/S nicifyProcedureList(list)
878912 return niceList
879913End
880914
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
885928
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
893941 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)
894966End
895967
896968// Returns 1 if the procedure file has content which we can show, 0 otherwise
9791051
9801052// Shows the line/function for the function/macro with the given index into decl
9811053// With no index just the procedure file is shown
982- Function showCode ( procedure,[ index] )
1054+ Function showCode ( procedure, [ index] )
9831055 string procedure
9841056 variable index
9851057
@@ -1156,8 +1228,7 @@ static Function setCheckSum(procedure)
11561228
11571229 timer = timerStart ()
11581230
1159- procText = getProcedureText ( procedure. module, procedure. name)
1160- procText = ProcedureText ( "" , 0, procedure. fullname)
1231+ procText = getProcedureText ( "" , 0, procedure. module, procedure. name)
11611232 returnValue = setGlobalStr ( "parsingChecksum" , Hash ( procText, 1 ))
11621233
11631234 setCheckSumTime ( timerStop ( timer))
0 commit comments