
I think it might be useful (well it would certainly be useful for me at the moment

to determine the return type of a / the current procedure.
Code: Select all
TypeOf(MyProcedure())
#PB_Compiler_ProcedureType
thanks.

Code: Select all
TypeOf(MyProcedure())
#PB_Compiler_ProcedureType
Code: Select all
EnableExplicit
Global Window_0, ListIcon_0, Filename$=ProgramParameter(0) , TmpFilename$=ProgramParameter(1)
Define NewList entries.s(), event.i
Procedure DoTypes(Filename$, List entries.s())
Protected regex_proctype, *mem, buffer.i, FileString$, spos.i, epos.i, procname.s, type.s, retstring.s, nbr.i, i.i
regex_proctype.i = CreateRegularExpression(#PB_Any, "(ProcedureC\.|Procedure\.|ProcedureCDLL\.|ProcedureDLL\.)[scbwliqfdau]\s.+?\(.*\)")
Dim pt$(0)
If ReadFile(0,Filename$)
*mem=AllocateMemory(Lof(0))
If *mem
buffer=ReadData(0, *mem, Lof(0))
FileString$=PeekS(*mem)
nbr=ExtractRegularExpression(regex_proctype, FileString$, pt$())
If nbr>0
For i=0 To nbr-1
If FindString(pt$(i), Chr(46))
spos=FindString(pt$(i), Chr(46)) ; find the point
epos=FindString(pt$(i), Chr(40) , spos+1) ; find the brace
type=Mid(pt$(i), spos+1, 1) ; this is the return type
procname=Mid(pt$(i), spos+3) ; this is the procedure name
If type
Select type
Case "s"
type="String"
Case "c"
type="Character "
Case "b"
type="Byte"
Case "w"
type="Word"
Case "l"
type="Long"
Case "i"
type="Integer"
Case "q"
type="Quad"
Case "f"
type="Float"
Case "d"
type="Double"
Case "a"
type="Ascii"
Case "u"
type="Unicode"
EndSelect
AddElement(entries())
entries()=procname+Chr(10)+type
EndIf
EndIf
Next
SortList(entries(), #PB_Sort_Ascending)
EndIf
EndIf
CloseFile(0)
FreeRegularExpression(regex_proctype)
FreeArray(pt$())
FreeMemory(*mem)
If nbr=0
MessageRequester("Error", "No Procedure/s With Return Types Found")
End
EndIf
EndIf
EndProcedure
Procedure OpenWindow_0(x = 0, y = 0, width = 560, height = 310)
Window_0 = OpenWindow(#PB_Any, x, y, width, height, "Procedure Return Types", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreateStatusBar(0, WindowID(Window_0))
AddStatusBarField(50)
StatusBarText(0, 0, "Entries:")
AddStatusBarField(510)
ListIcon_0 = ListIconGadget(#PB_Any, 0, 7, 560, 280, "Nbr", 50, #PB_ListIcon_GridLines)
AddGadgetColumn(ListIcon_0, 1, "Procedure", 410)
AddGadgetColumn(ListIcon_0, 2, "Ret Type", 100)
EndProcedure
Procedure Window_0_Events(event, List entries.s())
Select event
Case #PB_Event_CloseWindow
FreeList(entries())
ProcedureReturn #False
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure
Procedure Main(List entries.s())
OpenWindow_0()
StickyWindow(Window_0, 1)
ForEach entries()
AddGadgetItem(ListIcon_0, -1, Str(ListIndex(entries())+1)+Chr(10)+entries())
Next
StatusBarText(0, 1 ,Str(ListSize(entries())))
EndProcedure
If Filename$
DoTypes(Filename$, entries())
Main(entries())
ElseIf TmpFilename$
DoTypes(TmpFilename$, entries())
Main(entries())
Else
End
EndIf
Repeat
event = WaitWindowEvent()
Until Window_0_Events(event,entries()) = #False
End
Code: Select all
Structure PB_Any
type.i
StructureUnion
a.a
b.b
c.c
u.u
w.w
l.l
i.i
f.f
d.d
q.q
*ptr
EndStructureUnion
s.s
EndStructure
Macro New_PB_Any()
AllocateMemory(SizeOf(pb_any))
EndMacro
Macro PB_Any_EQ(ResultAny,ValAny)
Select ValAny\type
Case #PB_String
ResultAny\s = ValAny\s
Default
ResultAny\q = ValAny\q
EndSelect
ResultAny\type = ValAny\type
EndMacro
Macro Free_PB_Any(pAny)
Select pAny\type
Case #PB_String
pany\s=""
EndSelect
FreeMemory(pany)
EndMacro
Procedure foo(*val.PB_Any)
Protected *p.pb_any = New_PB_Any()
PB_Any_EQ(*p,*val)
ProcedureReturn *p
EndProcedure
Global *pr.pb_any,in.pb_any
in\type = #PB_String
in\s = "hello"
*pr = foo(@in)
If *pr\type = #PB_String
Debug *pr\s
EndIf
Free_PB_Any(*pr)
in\type = #PB_Float
in\f = 1.235
*pr = foo(@in)
If *pr\type = #PB_Float
Debug *pr\f
EndIf
Free_PB_Any(*pr)