Common asked question.  With an answer of yes, no, maybe.
Depending upon what exactly you are after.

Here's some replies that have been previously posted 
in regards to working with C code:
-------------------------------------------------------------------

> Do you know if it is possible to reverse C with Rational 
> Rose/C++ ?

Technically, yes, but practically, no.  There are no classes in 
C (structs only--maybe), and you will not have a package 
structure that will show up.  There will be almost no useful 
information garnered from a reverse-engineer of C code.  Try it 
and see with some of the code; you will see what it looks like. 
Results vary depending on customer's coding style.

------------------------------------------------------------------

Yes, Rose can reverse engineer plain old vanilla C.
It will give you whatever classes are in your C code
and nothing else.

Rose has very little support for plain old vanilla C.
The reason is Rose is a "OO" tool and wants to look at
classes. There are none in C.

Do you see the problem? There is not much there.
Structs become classes, but C does not have
operations in structs. Therefore the classes are not
very interesting. MOST code is ignored.

So you reverse engineer a bunch of stuff and get a blank
(or sparse) model. Not very interesting.

Rose can help with "design" doing Use Cases and sequence diagrams,
and state diagrams, and activity diagrams, and component diagrams,
and deployment diagrams, etc. etc.

-------------------------------------------------------------------

>Actually, C can be very object oriented if implemented in an OO 
>fashion (ex: X-Windows MOTIF).  However, this is rarely the case.  
>I think a good exercise would be to run just the header files 
>through the Rose Analyzer to get an idea of the code structure.  
>It may or may not be valuable.  

That is true, and I have coded in that way.  But there is no 
"class" key word and no structuring of "attributes" and "methods" 
because C is not an OO language.  If C structs could have methods 
(functions) then there might be something useful there.  Rose 
will ignore stand alone functions.

Rose is not good with some C++ code I have seen because of the 
way the code was written.  That is, there were stand alone 
functions and a few structures and no real classes in the code.

True, very rare to see C code that would have any aggregate of 
structs that would produce anything that looked like a class 
diagram.  Even then you would still not know where the functions 
went by looking at the diagram.

This question gets asked quite allot.  Just cannot get blood out 
of a turnip no matter how hard you squeeze. :-)

-------------------------------------------------------------------

C is not OO, yes indeed. But in the early days people simulated OO 
with structs: attributes are fields in the struct and member 
operations are function pointers. No polymorphism or encapsulation 
all has to be implemented: inheritance, type casting....

 If the code you have is rich of these constructs, it might be 
useful to reverse it (I don't think a forward engineer would be a 
good idea).

-------------------------------------------------------------------

As a side note, Rose RealTime supports full code generation and 
execution in both the C and C++ environments. The C version is for 
customers that require C for either historical reasons (interface 
to legacy C code), performance reasons, or to reduce dynamic memory 
allocation (no news and deletes), but still want the value of high 
level OO modelling, full code generation, and host/target based 
execution.

The C version uses structs to represent attributes and functions 
(that pass pointers to the data structs) as methods. It also allows 
you to use OO principles such as inheritance and polymorphism.

RoseRT uses the C++ Analyzer from Rose, so it does not have any 
special C reverse engineering capabilities.

-------------------------------------------------------------------

Regarding your question: Is it possible to reverse engineer C code 
with Rose?

It is possible with the analyzer to reverse engineer C code 
containing structs.
These can be exported to a rose model as if they were classes. 
For example, if you have the source code structs.h:

struct my1 {

            int arg1;
            double arg2;
};

struct my2 {

            int arg3;
            my1* ptr;
};

void myfunc(int a, my2* b);

you can load it in the Analyzer, analyze it, choose Export Options 
set Detailed Analysis and produce the attached model which will 
display the two UML classes my1 and my2, their attributes and a 
relationship due to the pointer.(The information about the function
is lost in the model, so if you then regenerate the code from the 
model you will lose that part of code).

The relevant option to set in the analyzer (which is automatically 
selected if you choose Detailed Analysys Export Option Set) is 
accessible in the Analyzer   menu:
Edit->Export Options->Class Model->POD Structs and Unions (POD = 
Plain Old Data) There you can choose to represent the PODs as class
when you export to a rose model.

On the other hand, when Forward engineering, you can choose to make
a struct out of a UML class by setting the following property in 
Rose:

Class Specification ->C++->Class->ClassKey Struct

-------------------------------------------------------------------

If you only want to document the old C code, you can partly trick 
the C++ analyzer in the following way:
by adding a class statement that encloses the whole header file 
content. You do not need to modify the file explicitely, you can 
add an auxiliary file in the analyzer project. This adding an 
explicit class statement is unavoidable, because otherwise you 
would lose all the global functions and global data (there's no way
to add an operation or an attribute to a module or to a package in 
Rose: only classes can have attributes and operations).
If you do not add the class statement you will only export to rose 
the structs, enums, unions as you discovered.

The trick goes as follows:
I have created a project file to which I have added an auxiliary 
file:

//myTest.hxx
class myTest{
#include "myTest.h"
};

(I've added the extension .hxx to the project list of extensions)

I have then also added a myTest.h to the project but I have marked 
it type 3 so that it is not analyzed independently even if you 
select it. The .hxx is instead type 1.

I attach the files to the analyzer project and get the resulting 
model obtained by exporting with Detailed Analisys Export Options 
set.

This works fine if you limit yourself to reverse engineering the .h
file, which is what normally should be done.

All in all, if you can avoid reversing the .cpp, perhaps you can 
still get some useful documentation in this way.

-------------------------------------------------------------------

You can use either Rose Professional C++ Edition or Rose Enterprise
Edition to do this.

There is a partner called 3soft in Germany with the product OO2C 
which supports C. Please contact them directly (address on the web 
page) for details.

http://programs.rational.com/partner/SearchResults_Company.cfm?CMP

3SOFT (http://www.embeddedUML.de) has developed a C add-in mainly 
targetted at embedded devices (small footprint). 

Eval version of the add-in can be obtained by contacting:

        3SOFT GmbH method park=20
        Torsten Posch=20
        Wetterkreuz 19a=20
        91058 Erlangen=20
        Telefon: 09131 / 97206-230=20
        Telefax: 09131 / 97206-200=20
        e-Mail: [EMAIL PROTECTED]=20


>>> (1) I can tell you about the product: 
>>> - Product is now managed by www.methodpark.com (spinoff from 3Soft) 
>>> - pure generation 
>>> - positions towards the hard-realtime market 
>>> - uses standard Rose, generates C, NO reverse 

-------------------------------------------------------------------

It's definitely possible, BUT it depends a lot on the structure of 
their application, if there is one ;-). Because that will have major 
impact on the value of doing this exercise.
The structure of C-applications can be everything in the range from
perfectly object-oriented to messy spaghetti, and the UML model can 
be no better than that.

So again, any language can be modelled with UML. Depending on the
structuring techniques used, some stereotyping to UML may be needed 
to get optimum value.

I've done this before so I know it's possible. I've even done it 
with e.g. Intel x86 assembler code without any problem.

-------------------------------------------------------------------

TechnoteID: 11814

Subject: Can Rose produce flow charts from C source code?

PRODUCT: Rose
OS:
Windows
DEFECT #:  N/A
PATCH #:   N/A
REFERENCES:N/A

CREATED: 22/05/2000
REVISED: N/A


QUESTION:

Can Rose produce flow charts from C source code?


ANSWER:

Since Rose is Unified Modeling Language based OO design tool, 
and flowcharts are not an OO or UML diagram type, you will not 
get a flowchart out of Rose.  You will get class diagrams of 
any classes defined in your C++ and Visual C++ code. Since C 
doesn't support classes (only Plain Old Data (POD) types such as
struct, union, and enum), you won't see much after reverse 
engineering C sources unless you tell the C++ Analyzer to reverse 
POD types as well, and even then it won't see functions that 
aren't class methods.

-------------------------------------------------------------------
-------------------------------------------------------------------

Patrick Kennedy
 Rational Support


-----Original Message-----
From: brent [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 12, 2002 6:49 PM
To: [EMAIL PROTECTED]
Subject: (ROSE) C program reverse engineer



> hi, there,
> how can I reverse engineer an old C program ans sqlc
> program to rose model? or just import those c
> program
> and display them in logical view?
> 
> thanks.
> 
> rgsd
> brent
> 


__________________________________________________
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
http://mail.yahoo.com/
************************************************************************
* Rose Forum is a public venue for ideas and discussions.
* For technical support, visit http://www.rational.com/support
*
* Post or Reply to: [EMAIL PROTECTED]
* Subscription Requests: [EMAIL PROTECTED]
* Archive of messages:
*    http://www.rational.com/support/usergroups/rose/rose_forum.jsp
* Other Requests: [EMAIL PROTECTED]
*
* To unsubscribe from the list, please send email
*    To: [EMAIL PROTECTED]
*    Subject: <BLANK>
*    Body: unsubscribe rose_forum
*************************************************************************
************************************************************************
* Rose Forum is a public venue for ideas and discussions.
* For technical support, visit http://www.rational.com/support
*
* Post or Reply to: [EMAIL PROTECTED]
* Subscription Requests: [EMAIL PROTECTED]
* Archive of messages:
*    http://www.rational.com/support/usergroups/rose/rose_forum.jsp
* Other Requests: [EMAIL PROTECTED]
*
* To unsubscribe from the list, please send email
*    To: [EMAIL PROTECTED]
*    Subject: <BLANK>
*    Body: unsubscribe rose_forum
*************************************************************************

Reply via email to