How to determine if there are Label inside the function?

Ask for help, how to use AHK_H, etc.
arcticir
Posts: 543
Joined: 17 Nov 2013, 11:32

How to determine if there are Label inside the function?

16 Aug 2018, 05:51

Because "IsLabel" can't tell if the label is inside the function, I usually use the following method to determine whether it exists, but if the number of sub-tabs reaches hundreds, I somewhat mind the cumbersomeness of it. Is there a better solution?

Code: Select all

func("str")

func(s){
    static list:={str:1}


    if list[s]
        gosub(s)
    return

    str:
    MsgBox "str"
    return
}

str:
return
HotKeyIt
Posts: 1705
Joined: 29 Sep 2013, 18:35
Contact:

Re: How to determine if there are Label inside the function?

16 Aug 2018, 10:49

Code: Select all

; AHK Structures
global _AHKDerefType := "LPTSTR marker,{_AHKVar *var,_AHKFunc *func,_AHKDerefType *next,UInt symbol},BYTE type,param_count,WORD length"
global _AHKExprTokenType := "{__int64 value_int64,double value_double,struct{{PTR *object,_AHKDerefType *deref,_AHKVar *var,LPTSTR marker},{LPTSTR buf,size_t marker_length}}},UINT symbol,{_AHKExprTokenType *circuit_token,LPTSTR mem_to_free}"
global _AHKArgStruct := "BYTE type,bool is_expression,WORD length,LPTSTR text,_AHKDerefType *deref,_AHKExprTokenType *postfix"
global _AHKBreakPoint := "INT id,BYTE type,BYTE state,bool temporary"
global _AHKLine := "BYTE mActionType,mArgc,WORD mFileIndex,UINT mLineNumber,_AHKArgStruct *mArg,PTR mAttribute,_AHKLine *mPrevLine,*mNextLine,*mRelatedLine,*mParentLine,_AHKBreakPoint *mBreakPoint"
global _AHKLabel := "PTR vTable,LPTSTR mName,_AHKLine *mJumpToLine,_AHKLabel *mPrevLabel,*mNextLabel"
global _AHKFuncParam := "_AHKVar *var,WORD is_byref,default_type,{LPTSTR default_str,Int64 default_int64,Double default_double}"
If (A_PtrSize = 8)
	global _AHKRCCallbackFunc := "UINT64 data1,data2,PTR stub,UINT_PTR callfuncptr,BYTE actual_param_count,create_new_thread,event_info,*_AHKFunc func"
else
	global _AHKRCCallbackFunc := "ULONG data1,data2,data3,PTR stub,UINT_PTR callfuncptr,ULONG data4,data5,BYTE actual_param_count,create_new_thread,event_info,*_AHKFunc func"
global _AHKFunc := "PTR vTable,LPTSTR mName,{struct{_AHKLine *mJumpToLine,_AHKFuncParam *mParam,PTR *mClass},struct{PTR mBIF,UCHAR *mOutputVars,PTR mID}},Int mParamCount,MinParams,_AHKLabel *mFirstLabel,*mLastLabel,_AHKVar **mGlobalvar,**mVar,**mLazyVar,**mStaticVar,**mStaticLazyVar,Int mGlobalVarCount,mVarCount,mVarCountMax,mLazyVarCount,mStaticVarCount,mStaticLazyVarCount,Instances,UCHAR mDefaultVarType,bool mIsBuiltIn,mIsVariadic,mHasReturn"
global _AHKVar := "{Int64 mContentsInt64,Double mContentsDouble,PTR mobject,PTR mVV},{char *mByteContents,LPTSTR mCharContents},{UINT_PTR mLength,_AHKVar *mAliasFor},{UINT_PTR mCapacity,UINT_PTR mBIV},BYTE mHowAllocated,mAttrib,mScope,mType,LPTSTR mName"

fn:=Struct(_AHKFunc,FindFunc("func"))
MsgBox "Name: " fn.mFirstLabel.mName "`nLine Number: " fn.mFirstLabel.mJumpToLine.mLineNumber

func(s){
    static list:={str:1}

    if list[s]
        gosub(s)
    return

    str:
    MsgBox "str"
    return
}

str:
return
arcticir
Posts: 543
Joined: 17 Nov 2013, 11:32

Re: How to determine if there are Label inside the function?

16 Aug 2018, 13:14

This seems to be another kind of complexity, But it is worth trying.
It seems to only get the last and first?
How do I traverse the function tags?

Thank you. ;)
HotKeyIt
Posts: 1705
Joined: 29 Sep 2013, 18:35
Contact:

Re: How to determine if there are Label inside the function?

16 Aug 2018, 15:41

;)

Code: Select all

; AHK Structures
global _AHKDerefType := "LPTSTR marker,{_AHKVar *var,_AHKFunc *func,_AHKDerefType *next,UInt symbol},BYTE type,param_count,WORD length"
global _AHKExprTokenType := "{__int64 value_int64,double value_double,struct{{PTR *object,_AHKDerefType *deref,_AHKVar *var,LPTSTR marker},{LPTSTR buf,size_t marker_length}}},UINT symbol,{_AHKExprTokenType *circuit_token,LPTSTR mem_to_free}"
global _AHKArgStruct := "BYTE type,bool is_expression,WORD length,LPTSTR text,_AHKDerefType *deref,_AHKExprTokenType *postfix"
global _AHKBreakPoint := "INT id,BYTE type,BYTE state,bool temporary"
global _AHKLine := "BYTE mActionType,mArgc,WORD mFileIndex,UINT mLineNumber,_AHKArgStruct *mArg,PTR mAttribute,_AHKLine *mPrevLine,*mNextLine,*mRelatedLine,*mParentLine,_AHKBreakPoint *mBreakPoint"
global _AHKLabel := "PTR vTable,LPTSTR mName,_AHKLine *mJumpToLine,_AHKLabel *mPrevLabel,*mNextLabel"
global _AHKFuncParam := "_AHKVar *var,WORD is_byref,default_type,{LPTSTR default_str,Int64 default_int64,Double default_double}"
If (A_PtrSize = 8)
	global _AHKRCCallbackFunc := "UINT64 data1,data2,PTR stub,UINT_PTR callfuncptr,BYTE actual_param_count,create_new_thread,event_info,*_AHKFunc func"
else
	global _AHKRCCallbackFunc := "ULONG data1,data2,data3,PTR stub,UINT_PTR callfuncptr,ULONG data4,data5,BYTE actual_param_count,create_new_thread,event_info,*_AHKFunc func"
global _AHKFunc := "PTR vTable,LPTSTR mName,{struct{_AHKLine *mJumpToLine,_AHKFuncParam *mParam,PTR *mClass},struct{PTR mBIF,UCHAR *mOutputVars,PTR mID}},Int mParamCount,MinParams,_AHKLabel *mFirstLabel,*mLastLabel,_AHKVar **mGlobalvar,**mVar,**mLazyVar,**mStaticVar,**mStaticLazyVar,Int mGlobalVarCount,mVarCount,mVarCountMax,mLazyVarCount,mStaticVarCount,mStaticLazyVarCount,Instances,UCHAR mDefaultVarType,bool mIsBuiltIn,mIsVariadic,mHasReturn"
global _AHKVar := "{Int64 mContentsInt64,Double mContentsDouble,PTR mobject,PTR mVV},{char *mByteContents,LPTSTR mCharContents},{UINT_PTR mLength,_AHKVar *mAliasFor},{UINT_PTR mCapacity,UINT_PTR mBIV},BYTE mHowAllocated,mAttrib,mScope,mType,LPTSTR mName"

fn:=Struct(_AHKFunc,FindFunc("func"))
if NumGet(fn.mFirstLabel[""]) && fl:=fn.mFirstLabel
	Loop {
		MsgBox "Name: " fl.mName "`nLine Number: " fl.mJumpToLine.mLineNumber
	} Until NumGet(fl.mNextLabel[""])=0 || !fl:=fl.mNextLabel
func(s){
    str1:
    MsgBox A_ThisLabel
    return
    str2:
    MsgBox A_ThisLabel
    return
    str3:
    MsgBox A_ThisLabel
    return
}

Return to “Ask For Help”

Who is online

Users browsing this forum: No registered users and 3 guests