List of Variablen in Code?

Just starting out? Need help? Post your questions and find answers here.
User avatar
tft
User
User
Posts: 99
Joined: Mon Dec 29, 2008 9:34 am

List of Variablen in Code?

Post by tft »

Is there a tool or function that searches a project for which variables exist and how they are declared, including Define & Global?

thx TFT
TFT seid 1989
Aktuelles Projekte : Driving School Evergarden
YouTube : Pure Basic to go
FaceBook : Temuçin SourceMagic Games
DISCORD : SourceMagic
W10 , i9 9900K ,32 GB Ram , GTX Titan , 3 Monitore FHD
ARDUINO Freak :-)
PBJim
Enthusiast
Enthusiast
Posts: 296
Joined: Fri Jan 19, 2024 11:56 pm

Re: List of Variablen in Code?

Post by PBJim »

I recall some past discussions about this — it would be nice if the PureBasic compiler made the symbol table available in the form of output. I'm not sure if that is possible. In particular, I would love to see an unused variable warnings list, as this was always a standard practice of compilers in the past, where, for reasons of code refactoring for instance, we had perhaps defined a variable but no longer use it.
User avatar
Michael Vogel
Addict
Addict
Posts: 2808
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: List of Variablen in Code?

Post by Michael Vogel »

Tried all these tools but never was absolute happy with them.

The 'Unused Vars' searcher seems to be very precise (and scans 200% of the source :lol:) but fails for code lines like r=2*mmm : mmm=r+bb+bb.

The 'Variable Renamer' is quite fast (except filling the ListIconGadget with the results) but show results like ?DataPosition, @XYZ and XYZ or sometimes special characters or non existent variables like Ascii.
Anyhow this tool seems to be a good start - maybe some more information about the variables like the type (integer, string,...) or its position (line number or procedure) would be fine, as well a quick jump to it's (first) location in the source code.
BarryG
Addict
Addict
Posts: 4178
Joined: Thu Apr 18, 2019 8:17 am

Re: List of Variablen in Code?

Post by BarryG »

Michael Vogel wrote: Mon Jul 15, 2024 9:01 am fails for code lines like r=2*mmm : mmm=r+bb+bb
Is that because of the colon? Perhaps the parser needs to separate any lines with colons into their own lines before parsing.
User avatar
Michael Vogel
Addict
Addict
Posts: 2808
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: List of Variablen in Code?

Post by Michael Vogel »

No, I've had inserted two lines in fact (just summarized them for the posting).
I saw also some other issues - for instance not only variables but also procedures are shown in the list. Of course, these procedures have been called from the program.
User avatar
tft
User
User
Posts: 99
Joined: Mon Dec 29, 2008 9:34 am

Re: List of Variablen in Code?

Post by tft »

It looks like I'll have to write something myself. I did this once 15 years ago. But I no longer have the code. As part of my game project, I need to have something like this. Maybe someone will still get in touch. The procedure is not that difficult. First, remove all unnecessary tabs and spaces. Also, do this for all include files. Then list the procedure and macro names. Then the function names, which can be obtained from the compiler executable. Exclude all keywords. If you explicitly assume as a condition. Everything has already been defined somewhere. Consider brackets and quotation marks. If something like this doesn't already exist, I guess I'll have to create it myself. Does anyone else need it?

TFT
TFT seid 1989
Aktuelles Projekte : Driving School Evergarden
YouTube : Pure Basic to go
FaceBook : Temuçin SourceMagic Games
DISCORD : SourceMagic
W10 , i9 9900K ,32 GB Ram , GTX Titan , 3 Monitore FHD
ARDUINO Freak :-)
User avatar
skywalk
Addict
Addict
Posts: 4220
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: List of Variablen in Code?

Post by skywalk »

tft wrote: Mon Jul 15, 2024 1:52 pmDoes anyone else need it?
I tried a bunch of times over the years but the Tool system has no way to jump to another opened TAB. I think freak said it would be made available at some point and he suggested opening a file in the Tool since that would make the newly opened file the active tab. But, that is tricky with large code files and what if the variable exists in multiple includes?

Now that the IDE is open source, maybe the FindInFiles dialog can be customized to support variable search across open/unopened tabs. :idea:
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
AZJIO
Addict
Addict
Posts: 2191
Joined: Sun May 14, 2017 1:48 am

Re: List of Variablen in Code?

Post by AZJIO »

Michael Vogel wrote: Mon Jul 15, 2024 9:01 am The 'Variable Renamer' is quite fast (except filling the ListIconGadget with the results)
Uses "PureBasic\SDK\Syntax Highlighting\SyntaxHighlighting.dll", which is a code analyzer (included with PureBasic). Those code elements that are highlighted as variables in the IDE will be captured. Therefore, there is high accuracy here. Next, they are checked for uniqueness and their number is counted as a whole word and as part of a word to show whether there will be collisions. Taking a variable pointer is also printed. You get complete statistics. If the variable occurs 1 time and does not take the variable pointer, then this is what you are looking for (sorting works by columns). But you can have local variables in different functions that are essentially unused, meaning that ideally you would handle each function separately.
2. When dividing the code into two files, the second file contains universal functions that can be considered as separate files, that is, I do not use a variable in different files, or until I have such complex projects and I think that this is an incorrect division of the project into blocks. Therefore, I do not seek to remake the program to work with a project, that is, with several files.
3. I have few variables so I didn't use (already added)

Code: Select all

SendMessage_(hGadget, #WM_SETREDRAW, 0, 0)
...filling...
SendMessage_(hGadget, #WM_SETREDRAW, 1, 0)
SMaag
Enthusiast
Enthusiast
Posts: 325
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: List of Variablen in Code?

Post by SMaag »

tft wrote: Mon Jul 15, 2024 1:52 pm Does anyone else need it?

TFT
It would be nice to have! I tought about sometimes!

Maybe a solution as a Cross-Reference-Tool which you have to activate manually.
You'll get a treeview and/or ListGadget with all Modules, Procedures, Constants, Variables
with a list of the X-Ref.

Like:

Module: "MyTestModule"
Procedures:
MyTestProcedure1
-(and here the X-Ref)
- File: TestProject_Main.pb
-Line 127
- Line 251
-Line 45

MyTestProcedure2
Post Reply