how to get sub/function name and parameters

Post

Posted
Rating:
#1 (In Topic #568)
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’
lets say … i have a sub/function like

Code (gambas)

  1.      ' something like Print FunctionName
  2.      ' something like For Each Parameter in FunctionCall
  3.      '                  Print ParName, ParValue
  4.      '                End With
  5.  

and i like to know the name of the function and the given parameters and their values …

tried a lot but no glue … so can anybody push me in the right direction?
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
Can you expand your requirements, as I see it all the answers you are looking for are in the routine.

Code (gambas)

  1.  
  2.   Print "test"
  3.   Print "par1", Str(par1)
  4.   Print "par2", par2
  5.  
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’
but what if i want that with every function? seems much typing …

what im thinking of is something like:

Code (gambas)

  1. strCName = Split(System.Backtrace[0],".")[0] ' class name
  2. strFName = Split(System.Backtrace[0],".")[1] ' function name name
  3. For Each a??????? As ???????? (Variant?) in strCName.strFName
  4.      Print a??????.Name ' Name of Parameter
  5.      Print a??????.Type ' Typ of Parameter
  6.      Print a??????.Value ' Value of Parameter
  7.  

hope this is more understandable :)
Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’
It's complicated and undocumented but it might be worth looking into gb.eval.highlight.

The IDE runs through the code very quickly and lists all symbols, function names, values etc in an enumerable collection.

How exactly it happens i do not know but code using it is in the TextHighlighter_Gambas.class file.

comp/src/gb.eval.highlight/.src/TextHighlighter_Gambas.class · master · Gambas / gambas · GitLab

something like…

Code (gambas)

  1.  Highlight.Analyze(Text, False)
  2.  
  3.   iPos = 0
  4.   For I = 0 To Highlight.Symbols.Max
  5.    '  Read the data here...
  6.   Next
  7.  
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’

BruceSteers said

The IDE runs through the code very quickly and lists all symbols, function names, values etc in an enumerable collection.

thats what im looking for …

your example did not work because:

1. in

Code (gambas)

  1. Highlight.Analyze("form1", False)
i have to manually give the name, and

2.

Code (gambas)

  1. Highlight.Symbols
gives back a string[] with one entry and that is "form1" … i think i knew that allready …

thank for trying :)
Online now: No Back to the top

Post

Posted
Rating:
#6
Regular
vuott is in the usergroup ‘Regular’
The function "name" can be obtained with….

Exemplum simplex:

Code (gambas)

  1. Public Sub Main()
  2.  
  3.  
  4.   For Each s In Class.Load("Main").Symbols
  5.     Print s
  6.   Next
  7.  
  8.  
  9.  
  10.    

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
I do this in a rather 'clunky' way and it takes extra effort but it works.
The following example shows a toolbox routine to get the id field from any table by providing 'a' name.
All my tables have an id field and the names are unique.

The AE ( Application Error management) module has a collection that is used like a stack.
Procedure calls are loaded as they are accessed and removed as the procedure closes.
The Finally statement removes the next procedure listed in the stack and as all procedures close,
the stack empties.

The AE module generates an error form from scratch and then provides valuable data to error tracking.
I've found over the years that the extra effort in coding is worth the benefits of being able to quickly identify the error
and to be able to see the values of the parameters passed.
It also lists the backtrace in reverse order so that it's easier to follow.

Note # The return statement HAS to be after the stack remove call as once you call a RETURN statement in
any procedure, it terminates and no other statements are processed

Code (gambas)

  1. Public Function GetIdFromName(InTable As String, InField As String, InName As String) As Integer
  2.  
  3.   Dim $Rec As Result
  4.   Dim $Query As String = "SELECT Id," & InField & " FROM " & InTable & " WHERE " & InField & " = '" & InName & "'"
  5.   Dim TmpId as Integer = 0
  6.  
  7.   AE.ErrorWhere = "Public Function GetIdFromName(InTable As String, InField As String, InName As String) As Integer" & Gb.NewLine
  8.   AE.ErrorWhere &= "Par1: " & InTable & Gb.NewLine
  9.   AE.ErrorWhere &= "Par2: " & InField & Gb.NewLine
  10.   AE.ErrorWhere &= "Par3: " & InName
  11.  
  12.   AE.LocationAdd(AE.ErrorWhere)
  13.  
  14.   $Rec = DB.$Con.Exec($Query)
  15.   If (Not IsNull($Rec)) And $Rec.Available Then TmpId =  $Rec!Id
  16.   AE.LocationRemove
  17.   Return TmpId
  18.  
  19.   AE.DisplayErrorData(2, Error.Text, Error.Class, Error.Where, Error.Code, Error.Backtrace)
  20.  

This is an example of the output of a typical error.
Attachment

AE Module.


Cheers - Quin.
I code therefore I am
Online now: No Back to the top

Post

Posted
Rating:
#8
Guru
BruceSteers is in the usergroup ‘Guru’

PJBlack said

BruceSteers said

The IDE runs through the code very quickly and lists all symbols, function names, values etc in an enumerable collection.

thats what im looking for …

your example did not work because:

1. in

Code (gambas)

  1. Highlight.Analyze("form1", False)
i have to manually give the name, and

2.

Code (gambas)

  1. Highlight.Symbols
gives back a string[] with one entry and that is "form1" … i think i knew that allready …

thank for trying :)

you have to analize the whole file text , you have essentially only analized only the word "form1" there, you'd load in the class file like…

Code (gambas)

  1.  
  2. sText=File.Load("./.src/FMain.class")
  3. Highlight.Analyze(sText, False)
  4.  
  5.  

then iterate through the results somehow.
Like i say i do not know how.

Vuotts method looked pretty simple :)
Online now: No Back to the top

Post

Posted
Rating:
#9
Regular
vuott is in the usergroup ‘Regular’

BruceSteers said

Vuotts method looked pretty simple :)

…but more complexly and for more generic elements, by accessing the "CLASS_DESC_SYMBOL *table " member of " _CLASS " Structure (in the header file "gbx_class.h "):

Code (gambas)

  1. Public Sub Main()
  2.  
  3.  
  4.   p = Object.Address(Me)
  5.  
  6.   Functio(p)
  7.  
  8.  
  9.  
  10.  
  11.   Dim p1, p2 As Pointer
  12.  
  13.   p1 = Pointer@(po + SizeOf(gb.Pointer) * 5)
  14.   p2 = Pointer@(p1)
  15.  
  16.   For i = 0 To 63
  17.     If Byte@(p2 + i) == 0 Then
  18.       Print
  19.       Continue
  20.     Endif
  21.     Print Chr(Byte@(p2 + i));
  22.   Next
  23.  

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top
1 guest and 0 members have just viewed this.