April 19, 2024, 11:08:28 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Source Tree

Started by fasecero, March 18, 2010, 05:04:38 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

fasecero

March 18, 2010, 05:04:38 PM Last Edit: March 26, 2010, 04:50:53 PM by fasecero
Hi, with this application you can watch how the functions are called in the given sources.
You can view how the sources are structured in a tree view, and the interpretation is simple, every child sub is called by its parent.
How to use: press the "Add" button, choose some file and press "Make Tree".

Current version: 1.1

fasecero

March 18, 2010, 10:46:01 PM #1 Last Edit: March 26, 2010, 03:13:15 PM by fasecero
A bug in BuildProcedures() and AddChildProcedures(...) leading to an infinite loop (in some special cases where functions share in part the same name) are fixed.
The procedure treeview now is sorted correctly.

aurelCB

fasecero that looks very interesting.
Your code have some elements of interpreters...
Very good..

fasecero

Thanks Aurel :)

About the elements of interpreters, you're probably referring to the function SearchProcFile, is already the third project where I use this function, which was originally writed by the master (Paul) in his Class Maker for Aurora.

Something I forgot, is that when I was doing this project I was thinking about how to export the functions to a file, and then Larry released days ago in this same section "Find_EBasic_subs" where the format was:

- Sub1
- Sub2

I liked it in that way, sorry Larry :)


sapero

Hi fasecero,
I have played a bit with your code, and found a problem after clicking MakeTree with a huge (122KB) source loaded: corrupted heap.
The debugger stopped at#pdata.subtext+=_lineso I have added a small protection to this line: if ((len(#pdata.subtext) + len(_line)) < MAX_SUB_SIZE)
#pdata.subtext+=_line
endif

With this fix it does not break into debugger, but finds only one subroutine from 120. By the way, I have loaded aurora code into it.

mrainey

This will be a very useful tool for me.  Big thanks to fascero and sapero.
Software For Metalworking
http://closetolerancesoftware.com

fasecero

Thanks MRainey :)
Sapero, your error checking will be added. I am currently working on adding support for Aurora and Creative.

fasecero

March 20, 2010, 06:32:03 PM #7 Last Edit: March 26, 2010, 03:12:37 PM by fasecero
- The program can make a procedure tree from Creative Basic Samples (Compile with TARGET_CREATIVE flag uncommented)
- The program avoid an overflow when saving the content of the sub to a istring variable (fixed with Sapero's solution)
- Similar when a line have more than MAX_LINE_SIZE characters. The program will show a warning if some kind of overflow was avoided (try compiling with TARGET_CREATIVE and make a tree for asteroids.cba sample and you will get a warning, then compile again with MAX_SUB_SIZE 30000 and load asteroids.cba again... no warning this time). If you get a warning then the procedure tree will probably contain mistakes.
- The program now clean the subitems of the files in the left panel in a remake of the right tree
- The program now show info in the statusbar about some base items when they are currently selected in the treeviews. This info is added in the exported file.
- The exported file now will show all the procedures in a separate section when examining more than one file.
   _____________________________________________________

Lets suppose we have a file with various classes, and each class have the same method name. When the program search in some function for that method name and find an occurrence, the problem is how to define to which class the method belongs to.
I don't know if is worth adding support for Aurora then, because Source Tree can't handle classes. And checking the Aurora samples, almost all is done through classes. Any hints are welcome.



fasecero

March 24, 2010, 06:28:30 PM #8 Last Edit: March 26, 2010, 03:11:58 PM by fasecero
Hello, new version released.

- The program now support the tree languages: EBasic, Creative and Aurora.
- Support for classes (experimental)
- Improved interface

To run, compile only STree.eba.

The research of classes is activated from 'Options-Search classes' menu.
The program will not always be able to determine to which class belongs a particular method.
If the program fails to determine the class, the method will shown the generic name "CLASS". For example CLASS::SomeMethod(...).

I forgot to mention one point: in the tree procedure, the base items are those functions not called by any other.

EDIT: I highly recommend to not load Aurora code in this program until new advice, my apologies. See next post.

sapero

fasecero, it has serious problems with a real Aurora code. I think your code is overwriting buffers, because your using the unsafe READ function.
Attached is one source file from my current project. If you load it and click Make, it will crash inside SearchProcFileAU (after call to AuroraCheckFunction), showing damaged stack-trace:

0 00416F89 sourcetree!_ibstrcpy+57
1 004055FB sourcetree!SearchProcFileAU+1675
2 43746E65 < string
3 626C6C61 < string
4 736B6361 < string
... 420 lines with bad trace


By te way, $use "shlwapi.lib" is missing

fasecero

Well, I've deleted the previous versions since all contain some 'big' bugs.
Sapero, now appears to work well. Thank you for providing me the file also, to make the research of the mistake more easily.
The error was due to several causes, but mainly because in SearchProcFileAU:

STRING subname = "", nameparams = ""

must be:

Istring subname [MAX_LINE_SIZE] = "", nameparams [MAX_LINE_SIZE] = ""

... and in occasions comments were not properly ignored.

I also added the missing sentence $USE "shlwapi.lib" and I also corrected a small error when opening the dialog language.

Download in the first post of this topic.

Techno

Quote from: fasecero on March 18, 2010, 05:04:38 PM
Hi, with this application you can watch how the functions are called in the given sources.
You can view how the sources are structured in a tree view, and the interpretation is simple, every child sub is called by its parent.
How to use: press the "Add" button, choose some file and press "Make Tree".

Current version: 1.1

Zip file corrupted

Bill-Bo

Techno,

I have corrected the zip and have it attached. I copied it to my XP and ran pkzipfix on it. I have also attached the pkzipfix program. The syntax is pkzipfix.exe filename.zip. If it can fix it, it will output a filename PKFIXED.ZIP; just rename it to your zip's filename, or whatever.

Bill

Brian

Hi,

I have just been messing with this SourceTree code, and have converted it to IWB. Some
errors still come up, but I don't know what to do with them! It still runs, though

Put all the files in the zip in one directory and compile stree.iwb

Brian

Bill-Bo

Brian,

I am curious. Did you happen to use my attachment? Just wondering if I contributed anything.

Bill

Brian

Bill,

No, I already had the files in my Emergence Basic archive. I realised afterwards that they
do need tickling up to include the "iwb" file extension, though

Brian

aurelCB

Hi Brian
Your files work for me  ;)
For testing you can try file in attachment  ;D

Brian

Hi,

Replace the stree.iwb and files.iwb with these two files, and it sorts out not being
able to select IWB files. Re-compile, of course

Aurel, I tried your eba file, and when you click the Make button, it comes up with an
error message about the treeview const. I increased that value, and it still barfs

Not having written the program, I don't know what to do to fix it. Better to leave
the value at 10000, I think

Brian

fasecero

Intrigued by Aurel code's warning I have checked his file.

The code have a circular reference where a function call to another and the second call the first one again, and so on.

eval -> eval_function -> eval -> eval_function .... this leads to an infinite treeview of nested tree items.

Of course the logic implemented by Aurel's code avoids the circular reference. These two changes worked to solve the issue, the first is to add one line to ProcListAddSub function located in Data file:



SUB ProcListAddSub(pointer pdata, string subname, string procparams, INT index), pointer
SETTYPE pdata, PROCDATA
pointer sdata : SETTYPE sdata, PROCCHILDDATA

if #pdata.name = subname THEN RETURN 0 ' <--------------------------------------------------  new adition

sdata = ListAdd(#pdata.procChildList, NEW(PROCCHILDDATA, 1) )
#sdata.name = subname
#sdata.nameparams = procparams
#sdata.index = index

RETURN sdata
ENDSUB



The second is to replace AddChildProcedures function with both the following ones:



SUB AddChildProcedures(uint itemid, STRING subname), INT
int findsubs = 0, itemnumber = 0, continue = 1
pointer pos, pdata : SETTYPE pdata, PROCDATA
pointer sdata : SETTYPE sdata, PROCCHILDDATA

IF AvoidCircularReference(itemid, subname) = 0 THEN
IF ProcList then
pos = ListGetFirst(ProcList)
WHILE pos <> 0 AND continue = 1
pdata = ListGetData(pos)
IF ShowParams THEN
IF #pdata.nameparams = subname THEN
findsubs = 1
continue = 0
ENDIF
ELSE
IF #pdata.name = subname THEN
findsubs = 1
continue = 0
ENDIF
ENDIF
pos = ListGetNext(pos)
ENDWHILE

IF findsubs = 1 THEN
pos = ListGetFirst(#pdata.procChildList)
WHILE pos <> 0
sdata = ListGetData(pos)
' add a child item procedure
itemnumber++
IF ShowParams THEN
IF subname <> #sdata.nameparams THEN Treeview4AddItem(#sdata.nameparams, itemid, #sdata.index)
ELSE
IF subname <> #sdata.name THEN Treeview4AddItem(#sdata.name, itemid, #sdata.index)
ENDIF
pos = ListGetNext(pos)
ENDWHILE
ENDIF
ENDIF
ENDIF

' finish with the item
tvSetItemData(d1, TREEVIEW_4, itemid, 0)
Treeview4SortItems(itemid)
RETURN itemnumber
ENDSUB

SUB AvoidCircularReference(uint itemid, STRING subname), int
uint parentID  = itemid
string name = ""

WHILE parentID > 0
parentID = SendMessage(d1, TVM_GETNEXTITEM, TVGN_PARENT, parentID, TREEVIEW_4)
tvGetItemText(d1, TREEVIEW_4, parentID, name, 255)

IF subname = name THEN RETURN 1
ENDWHILE

RETURN 0
ENDSUB



Hope this helps.

aurelCB

hi fasecero..
nice to se you  ;)