It is currently Sat Sep 22, 2018 12:37 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: List of defined but unused variables, constant etc.
PostPosted: Mon Feb 05, 2018 10:21 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 11, 2006 12:07 am
Posts: 418
Location: Germany / one of the fishheads
My current project is growing to a huge size and after making changes to some procedures it would be helpful if the IDE would provide a list of all defined but not used variables, constants, procedures and so on.

Sometimes there are subsequent changes (optimizations) in the code where one or more variables are no longer needed. Starting from a certain source code size it will be difficult to keep track of everything - or you have to search all variables manually in all files.

_________________
Excuse my bad english, my nativ language is german.
PB 5.62, OS: Windows 7 Pro x64, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520
"Happiness is a pet." | "Never run a changing system!"
My current age: 50 years


Top
 Profile  
Reply with quote  
 Post subject: Re: List of defined but unused variables, constant etc.
PostPosted: Thu Feb 08, 2018 10:04 am 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 633
Location: Berlin and Ibiza
+1

_________________
ImageImageImageImage


Top
 Profile  
Reply with quote  
 Post subject: Re: List of defined but unused variables, constant etc.
PostPosted: Tue Jul 31, 2018 5:00 am 
Offline
User
User

Joined: Tue Jun 06, 2006 3:39 pm
Posts: 66
Location: Maryland US
+1

I have run into similar issues.


Top
 Profile  
Reply with quote  
 Post subject: Re: List of defined but unused variables, constant etc.
PostPosted: Tue Jul 31, 2018 7:00 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3231
Location: Berlin, Germany
+1

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: List of defined but unused variables, constant etc.
PostPosted: Tue Jul 31, 2018 12:37 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Jun 24, 2006 3:29 am
Posts: 149
+1

_________________
Proud supporter of PB! * Musician * C64/6502 Freak


Top
 Profile  
Reply with quote  
 Post subject: Re: List of defined but unused variables, constant etc.
PostPosted: Tue Jul 31, 2018 2:44 pm 
Offline
User
User

Joined: Fri Dec 10, 2010 6:31 pm
Posts: 73
+1

_________________
Sorry for my bad English.


Top
 Profile  
Reply with quote  
 Post subject: Re: List of defined but unused variables, constant etc.
PostPosted: Tue Jul 31, 2018 5:08 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 31, 2005 11:09 pm
Posts: 3661
Location: Italy
Already asked 10 years ago :shock:

viewtopic.php?f=3&t=35703

_________________
Philosophy is questions that may never be answered. Religion is answers that must never be questioned.

[ My little PureBasic review ]


Top
 Profile  
Reply with quote  
 Post subject: Re: List of defined but unused variables, constant etc.
PostPosted: Tue Jul 31, 2018 7:38 pm 
Offline
Addict
Addict

Joined: Fri Nov 09, 2012 11:04 pm
Posts: 1588
Location: Uttoxeter, UK
+1

_________________
DE AA EB


Top
 Profile  
Reply with quote  
 Post subject: Re: List of defined but unused variables, constant etc.
PostPosted: Tue Jul 31, 2018 10:18 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jun 25, 2014 5:25 pm
Posts: 257
Location: Germany
Since a long time, I have a PB-Tool on my ToDo-List, which should be able to do this, but it is a lot of work.

A native solution would be better and certainly easier, because the PB parser already has this information
and we don't have to write a code parser again ourselves.

+1

_________________
Image
Why OpenSource should have a license
PureBasic-CodeArchiv-Rebirth: Git-Repository / Download -- Any help is welcome!
Manjaro Xfce x64 (Main system) :: WindowsXP/Xubuntu x86 (VirtualBox) :: PureBasic (Linux: x86/x64, Windows: x86) :: All are up to date


Top
 Profile  
Reply with quote  
 Post subject: Re: List of defined but unused variables, constant etc.
PostPosted: Fri Sep 14, 2018 2:27 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Apr 30, 2009 5:23 pm
Posts: 273
Location: Côtes d'Azur, France
+1

_________________
There are 2 methods to program bugless.
But only the third works fine.


Top
 Profile  
Reply with quote  
 Post subject: Re: List of defined but unused variables, constant etc.
PostPosted: Fri Sep 14, 2018 2:46 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 22, 2003 7:43 pm
Posts: 250
Location: Germany, Homburg (Saar)
+1

_________________
Electronics, Crazy & Interesting Stuff, all that with text, image and sound? Click here!

The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.


Top
 Profile  
Reply with quote  
 Post subject: Re: List of defined but unused variables, constant etc.
PostPosted: Fri Sep 14, 2018 3:02 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat Feb 08, 2014 3:26 pm
Posts: 464
+1

I had the idea to do that too. (It's on my ToDo list one day or next next year or more :? )
:idea: The principle was to force user to use EnableExplicit, then the tool follow the source and "just" enter all the keywords in an array or map and count all the occurrences of the following words after "Define", "Global", "Dim", "NewList", "NewMap" etc starting from the main file and following all (X)IncludeFile
If a word in the table appears only once, it means that the variable or constant is unused.

There are some difficulties because it is sometimes necessary to differentiate between two keywords in succession (ex: Global Dim ABC())
So keyword must be exclude keyword following

It's not as simple as I imagined at first :o :shock:

When (If) done :arrow: Make it a program that will be launched before compilation or on demand

So that's the idea, but maybe there's something better or simpler?

In the same vein, we should list the AllocateMemory() that do not have FreeMemory(). Except when they are in a procedure that must automatically release when exiting (although I don't know if AllocateMemory() is not persistent?

8)

_________________
(English is not my native language, I used an online translator)
Windows 10 x64 - CPU intel i3 - RAM 16Go - NVidia GT 620 - 1920x1080 - Linux Slackware, Debian - xfce - (VirtualBox 5) - raspberry pi


Top
 Profile  
Reply with quote  
 Post subject: Re: List of defined but unused variables, constant etc.
PostPosted: Fri Sep 14, 2018 3:29 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 2713
Location: Boston, MA
Yes, in the meantime, we have to build our own.
I have started and stopped many times trying to build this.
I want to focus the Tool within a Procedure.
(Macro's would be more difficult due to runtime expansion.)
Main space variables could be added later since the PureBasic IDE already lists these and more.
Unfortunately, the IDE does not jump to their definitions?
And the IDE Variable browser in locked in a tabbed panel with dropdowns for each type.
It is many many clicks to search.
These should be individual floating windows.

Does this pseudo code satisfy a Procedure scan?
1. Parse all selected text(Procedure..EndProcedure) by newline.
2. Search for keywords that define Variables and Procedures.
Define
Shared
Protected
Static
= AllocateMemory(
= Ascii(
= UTF8(
Array: Dim, ReDim
Map: NewMap
List: NewList
3. Search within each found item from 2.
Add names to mapVAR()
4. Add names to mapVAR() from the Procedure call list.
5. Loop through all mapVAR() items and search parsed text for existence > 1.

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: List of defined but unused variables, constant etc.
PostPosted: Fri Sep 14, 2018 3:40 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 22, 2003 7:43 pm
Posts: 250
Location: Germany, Homburg (Saar)
You miss something: Scopes. I can use the variable 'i' multiple times in my code, a new declaration in every procedure if I want to. You need to start a new scope for every procedure you encounter and also for every module and every procedure in every module. They are independent of each other.
And then thera are AllocateMemory(), AllocateStructure(), Ascii(), UTF8() and so on. You must not check these. You can not track down where these pointers will go at compile time. Just ignore them. If the developer forgot to free the allocated memory in the end it is his fault.

_________________
Electronics, Crazy & Interesting Stuff, all that with text, image and sound? Click here!

The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.


Top
 Profile  
Reply with quote  
 Post subject: Re: List of defined but unused variables, constant etc.
PostPosted: Fri Sep 14, 2018 5:56 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 2713
Location: Boston, MA
That's why I want to limit within a Procedure.
And reporting multiple or single instance pointers would not hurt anyone.

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye