Dead Code

A while back someone had a Xojo app the scanned an XML Xojo project and showed possible Methods etc that were not being accessed… (ie. Dead Code)
Yes I know the compile strips it… but I’d like to use such a tool to remove the code, and help refactor the project

Doesn’t Analyze Project IDE identify these instances in the project?

no… it only finds un-used variables…

To do this properly you more or less need to compile the code for whatever target so you can identify what code is or is not reachable

for instance code like

 Sub Foo
  end sub

 Sub Bar
 end sub

would, in a text only analysis say “bar” is still used when in fact it is completely unreachable

The same for if you’re on Mac OS, you compile

 Sub Foo
    #if TargetWindows
  end sub

 Sub Bar
 end sub

Again just scanning text would say Bar is more than likely still used when in fact it will not be used in a Mac build

Norman… this I realize… and I am not expecting 100%, nor would I trust any such program to remove the code for me.
The app I had found (years ago) would have said that “Bar” was used… and actually I’d prefer that it said that… so should I later remove that “return” it still worked…

I have a similar program for Swift which basically makes a list of the method, and then scans to see if those methods are called outside of a comment… I can write one for Xojo that does the same thing… was just hoping to save some time

I think such an app would be pretty simple. Look through the XML for any item in tags. If it starts with Sub or Function, it’s a declaration. Otherwise, if matches the regular expression \\b\\w+\\b then it’s a call. Then match the declarations against the calls.

Off the top of my head, the regex I’d use is this:

"[^"]*(?:"|$)(*SKIP)(*FAIL) # skip quotes
(?:\\bREM\\b|//|').* (*SKIP)(*FAIL) # skip comments
(?:^(Function|Sub) \\x20+)? \\b(\\w+)\\b

Edit for composition.

Kem it is a bit more than that…
SInce a method name can be duplicated in differnet classes or modules, you need to keep track of the “parent”, if it is private or public, and the scope in which the call exists (ie. if there are two FooBar, which one might it be referencing)

I dont think that expression isn’t quite complete enough
Does it handle shared , attributes or scope which are all part of the declaration ?
It may misidentify events as well

Both of your concerns are valid.