It is currently Mon Dec 17, 2018 10:45 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Could we have an option to flag unused variable names,please
PostPosted: Thu Dec 18, 2008 4:20 pm 
Offline
User
User

Joined: Sun Oct 24, 2004 9:25 am
Posts: 78
Ok, EnableExplicit more or less protects me from using mis-typed
varnamens.

But I also find myself re-working code after some time,
and it could be quite helpful to have variable names flagged
that are never or no longer actually referenced in the code.

Thks.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Dec 19, 2008 1:21 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Jun 30, 2007 8:04 pm
Posts: 3225
+1

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Dec 19, 2008 4:40 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 24, 2008 12:21 am
Posts: 281
that would be very usefull.
Maybe someone could make a PlugIn? :wink:

_________________
pb 5.11


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Dec 19, 2008 8:42 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Jun 09, 2003 10:08 pm
Posts: 665
Location: Nottingham
I was thinking of writing code to solve this as I badly need it myself, but it would be a major undertaking. I have previously written a similar routine in Amstrad CPC Locomotive Basic and it worked very well.

One main problem would be acquiring a list of reserved words including the core words such as For and Select and SizeOf(), and the names of all installed library routines such as AddGadgetColumn(). I probably would not need a list of the API routines as I could cheat by assuming any name that ended in an underscore immediately before an opening parenthesis was an API routine.

Does anyone know of a quick and easy was of acquiring such lists? It would need to be done by interrogating files within the PureBasic installation directory structure otherwise it would be a pain to keep them up-to-date.

Another problem will be catering for the overloading of '*' which is used for both multiplication and the first character of the names of pointer variables e.g. *mypointer .

_________________
Anthony Jordan


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Dec 19, 2008 11:53 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7581
> I probably would not need a list of the API routines as I could cheat by
> assuming any name that ended in an underscore immediately before an
> opening parenthesis was an API routine

Actually, the API commands are those just ending in an underscore. You can
have a space between the underscore and opening parenthesis, and indeed
I've seen code samples in these forums just like that.

_________________
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Dec 20, 2008 12:28 am 
Offline
Enthusiast
Enthusiast

Joined: Mon Jun 09, 2003 10:08 pm
Posts: 665
Location: Nottingham
@PB:

Yes, I agree with you about the possibility of intrusive spaces, but it probably doesn't matter. It is standard practice to remove redundant white space during any parsing process, especially white space around punctuation (and I would count parentheses as punctuation).

Also, if I went ahead and coded a routine to identify user variables, I would do so for typically written programs and not those that failed to follow normal programming layouts. Otherwise it would take far too long to write it.

_________________
Anthony Jordan


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Dec 20, 2008 3:14 am 
Offline
Enthusiast
Enthusiast

Joined: Mon Jun 09, 2003 10:08 pm
Posts: 665
Location: Nottingham
I have now discovered how to get a complete (?) list of all the PureBasic library functions:
Code:
#file = 0
Define folder$, flags, prog, ln$, p, output.b=#False

CreateFile(#file, "C:\Temp\PB Functions.txt")
WriteStringN(#file, "PureBasic Library Functions")
WriteStringN(#file, "")

folder$ = #PB_Compiler_Home+"\Compilers\"
flags = #PB_Program_Open|#PB_Program_Read|#PB_Program_Write
prog = RunProgram(folder$+"pbcompiler.exe", "/STANDBY", folder$, flags)
WriteProgramStringN(prog, "FUNCTIONLIST")

Repeat
  ln$ = ReadProgramString(prog)
  If output
    p = FindString(ln$, ")", 1)
    If p
      ln$ = Left(ln$, p)
      WriteStringN(#file, RemoveString(ln$, " "))
    EndIf
  EndIf
  If ln$="READY": output = #True: EndIf
Until ln$ = "OUTPUT"+#TAB$+"COMPLETE"

CloseFile(#file)
WriteProgramStringN(prog, "END")
WaitProgram(prog)
Debug "Program exit code = " + Str(ProgramExitCode(prog))
CloseProgram(prog)

End

_________________
Anthony Jordan


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Dec 21, 2008 3:04 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 24, 2008 12:21 am
Posts: 281
I tried my self on it, pls test it:

http://www.purebasic.fr/english/viewtopic.php?p=271426#271426

_________________
pb 5.11


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Dec 21, 2008 2:09 pm 
Offline
User
User

Joined: Sun Oct 24, 2004 9:25 am
Posts: 78
gnasen wrote:


Thanks for the effort. Is it possible that lines like

Define Varname.s = "something"

are being dismissed ? The tools seems to see my procedures names, but not any variables. Since I have "EnableExplicit" active all the time, I must define all vars.
Additionally, i never write "a=40" but always "a = 40" instead. Maybe, that's another problem for the tool?


Genereally, I was hoping that fred or someone else came up with a tool that analyses a program's symbol table at compile time and draw conclusions from what it finds there.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Dec 21, 2008 11:27 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 24, 2008 12:21 am
Posts: 281
It should work with all kind of formalism.
I updated it some times this day, so you may have an to old version.

I tried both, both works fine.

Maybe he could not open the file (if it shows nothing at all).
I updated it ;)

_________________
pb 5.11


Top
 Profile  
Reply with quote  
 Post subject: Re: Could we have an option to flag unused variable names,pl
PostPosted: Sun Dec 21, 2008 11:32 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 31, 2005 11:09 pm
Posts: 3669
Location: Italy
Captn. Jinguji wrote:
But I also find myself re-working code after some time,
and it could be quite helpful to have variable names flagged
that are never or no longer actually referenced in the code.


Yes, it would be very nice to have an (optional maybe) warning.


Top
 Profile  
Reply with quote  
 Post subject: Re: Could we have an option to flag unused variable names,pl
PostPosted: Mon Dec 22, 2008 8:29 am 
Offline
User
User

Joined: Sun Oct 24, 2004 9:25 am
Posts: 78
luis wrote:
Captn. Jinguji wrote:
But I also find myself re-working code after some time,
and it could be quite helpful to have variable names flagged
that are never or no longer actually referenced in the code.


Yes, it would be very nice to have an (optional maybe) warning.


Sure, I wouldn't want to HAVE to adjust things to make the program actually compile.
Or at least : only with a selectable "paranoid" set of preferences for a "Production compile". Not that something like that could replacea developer's responsibilities, but I think it is desirable for any program's productive release to have its build run at the highest (i.e. most scrutinizing) warning level available, and get that finished with not a single diagnostic (other than "0 errors, 0 Warnings").


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 22, 2008 8:47 am 
Offline
User
User

Joined: Sun Oct 24, 2004 9:25 am
Posts: 78
gnasen wrote:
It should work with all kind of formalism.
I updated it some times this day, so you may have an to old version.
[/qoute]
Mhhm... that may well be the case. I'll check hte new version out later. If your tool still won't work as desired, I'll supply an example of unruly code of mine.

gnasen wrote:
I tried both, both works fine.
Maybe he could not open the file (if it shows nothing at all).
I updated it ;)

Strangely, I had that effect when I ran the tool standalone.
When I made it known to the ide as a tool, it saw and showed procedure names of my my code examples, but only very few variables, and the latter came from procedures generated by the old Visual Designer, which does not implement "EnableExplicit" in code that it generates.

Nevertheless, your tool will be helpful.

Maybe a general flag/option "Show unreferenced code elements only" could be useful ? (Probably easier to implement than a color coding ?)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Dec 25, 2008 1:43 pm 
Offline
User
User

Joined: Sun Oct 24, 2004 9:25 am
Posts: 78
gnasen wrote:
It should work with all kind of formalism.
I updated it some times this day, so you may have an to old version.

I tried both, both works fine.

Maybe he could not open the file (if it shows nothing at all).
I updated it ;)


Yes, it works well for me now, I obviously HAD downloaded the old version befor you had published the fresh version.

Very good work.

I only now see what that if/select/ business is actually about. Good idea, too, though I'd suggest to make the flagging read-only. (It confused me that I could set/reset the marks without any obvious effect.)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Dec 25, 2008 4:59 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 24, 2008 12:21 am
Posts: 281
nice to hear that it works now as expected.
I took the selectboxes to show it, because it was the easiest way I think.
I would be pleased if you (or anyone else) has a better idea to show the results and could tell me :wink:

_________________
pb 5.11


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

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