list functions and list local variables

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

list functions and list local variables

26 Jul 2017, 01:29

I want to add support for #Warn to all my functions/scripts, and this will require adding the line 'local' to each function. Are there any scripts that can list the functions in a script and list all of the variables(/objects) within each function? Including/excluding parameter variables, either is fine. Thanks.

==================================================

[EDIT:] I've written a script to identify the start of functions, which I could expand upon, to identify the end of functions. The problem is then to identify variables, which perhaps I could do by creating a temporary script for each function and grabbing the variables. Is there a better way than that?

Code: Select all

q:: ;list functions (omits OTB functions and possibly others)
;vText := JEE_GetSelectedText()
vText := Clipboard
vOutput := ""
VarSetCapacity(vOutput, StrLen(vText)*2)
vText := RegExReplace(vText, "`r`n\K[ `t]*\w+?\(.*`r`n{", Chr(1) "$0")
Loop, Parse, vText, % Chr(1)
	if (A_Index > 1)
		vOutput .= RegExReplace(A_LoopField, "s)[ `t]*\w+?\K\(.*") "`r`n"
Clipboard := vOutput
MsgBox, % "done"
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: list functions and list local variables

26 Jul 2017, 16:23

Argh, just found out thing are worse than I thought:

#Warn
https://autohotkey.com/docs/commands/_Warn.htm
LocalSameAsGlobal: Before the script starts to run, display a warning for each undeclared local variable which has the same name as a global variable.
Whereas I was hoping for something like:

LocalUndeclared: Before the script starts to run, display a warning for each undeclared local variable.

Some of the AHK editors can handle problems like this, right? I.e. listing a function's local variables.

==================================================

Well I just thought of a workaround as I was typing, try and collect anything that looks like a variable name and define it as a variable in the main body of the script, to trigger any LocalSameAsGlobal warnings.

Code: Select all

q:: ;get anything that looks like a variable
;vText := JEE_GetSelectedText()
vText := Clipboard
vText := RegExReplace(vText, "\W", ",")
Sort, vText, U D,
vOutput := ""
VarSetCapacity(vOutput, StrLen(vText)*2*2)
vText := Trim(vText, ",")
Loop, Parse, vText, % ","
{
	if !(SubStr(A_LoopField, 1, 2) = "A_")
	&& !(A_LoopField = "ClipboardAll")
	&& !(A_LoopField = "ComSpec")
	&& !(A_LoopField = "False")
	&& !(A_LoopField = "ProgramFiles")
	&& !(A_LoopField = "True")
	vOutput .= A_LoopField " := """"`r`n"
}
Clipboard := vOutput
MsgBox, % "done"
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: jaka1, penguinautomator, Spawnova and 234 guests