PermaLink LSCalls12/18/2005 03:13 PM
None


The next tool I wanted to talk about was
LSCalls. The origin of LSCalls was a need that I had to get a clearer picture of how the code in Teamstudio Build Manager was being used. Since it's inception the code (almost 99% LotusScript) had grown in complexity quite a bit. As with any project functions have been added, removed and changed a lot. The problem was that I knew that some code was not being used but it was a pretty painstaking process to find functions that were no longer being called. So, initially that was the point of LSCalls (hence the name). It turned out to be extremely fast to run through all the code and find the references. It's also didn't end up being very difficult to put together since Script Browser does this already, it just doesn't keep a track of the number of times a function is called. The other thing I was able to do was produce an accurate call tree. For each function I can see what other functions are being referenced and on what line.

So with that done I thought to myself, why not try it on other symbols as well like variables and labels? After spending a little more time I was able to add variable references as well.  Warnings has been something I  have always thought was missing from the script compiler. I've seen a lot of LotusScript in my time that is littered with unused variables. Not only does it make the code hard to read, but it's even harder to maintain. Can you delete that dim? Are you SURE it's not being used? If it is used are you sure you know where?


For Example:

 Sub
foo( sName as String )
    Dim
x As Integer
    Dim
y As Integer

    [ lots of code here.... ]
   [ lots of code here.... ]
   [ lots of code here.... ]
   [ lots of code here.... ]

 label1:        

    Print
x
 End Sub

Gives you this:

Symbol Y (Integer) found in 'FOO' references: 0
Symbol label1 (Label) found in 'FOO' references: 0

Parameter sName (String) found in 'FOO' references: 0


The other thing that LSCalls will tell you in regards to variable references are times when a symbol is 'read' from before it is 'written' too.
For example:

Sub
foo
Dim
x As Integer
If
x = 1 Then
   Print
"X is one"
End If

End Sub

Gives you this:

Symbol X (Integer) found in 'FOO' was read before written on line 4

In the above function, the variable X is read from in the ‘If’ statement. Since X was never initialized (written to) after it is declared lscalls will flag this as a potential error. This particular type of warning can be benign since LotusScript will initialize basic types like ‘integers’ for you. In this case 'X' is initialized to zero and the if will always be false to it will never be called... not a big deal, but it makes the code hard to read and what was the programmer really trying to accomplish? It's probably something that should be investigated.


However, classes are not initialized for you so this script would generate a runtime error:

Sub
foo
 Dim
s As NotesSession
If
s.Platform = "Windows/32" Then
    Print
"Running on windows"
 End If

End Sub

Gives you this:

Symbol S (Class) found in 'FOO' was read before written on line 3


In either case, there is a bug in the code that should be fixed. In the first example nothing bad will happen, but in the second example:



A picture named M2.




That being said, I think what you really want is something that tells you at the time when you are actually editing the code like
this.....
but........ we can talk about that later....

This page has been accessed 499 times. .
Comments :v

1. Chad Schelfhout12/19/2005 08:45:21 AM
Homepage: http://www.chadsmiley.com


You have my interest in the warnings add-on. The only question that I have is when can I use it?




2. Craig12/19/2005 02:19:04 PM
Homepage: http://blogs.teamstudio.com


There are a few wrinkles that need to be ironed out before I would be comfortable passing it out.... hopefully I'll have something soon.




3. martin hipfinger01/05/2006 11:09:25 AM
Homepage: http://www.konfabulieren.com


imho the warnings add-on would be THE killer app!!




4. Ondra01/11/2006 05:02:31 AM


Perfect! Do you plan some gui version ?




5. Craig01/16/2006 08:33:15 AM
Homepage: http://blogs.teamstudio.com


Wrapping a nice GUI around some or all of this would be nice, wouldn't it!




6. Art Zoutendijk01/17/2006 05:47:53 AM
Homepage: http://www.ecit.nl


Looks very handy. Minor typo in the export file (paremeters) and guess that also the codepage isn't handeling accents ?? (Kopi■ren iso Kopie■ren).




Contact Me
Free tools!
The BlogRoll
Lotus Domino ND6 RSS News Feed netcraft Lotus Geek Chris. A. Brandlehner CoComment Integrated
Monthly Archive
Photo Albums