Re: What Refactorings Would you Like for C



pingu219 wrote:
Thanks for the replies all.

At the moment I'm kind of limiting the refactorings I consider as my
aim is to allow such refactorings to be able to be done via a click,
drag and drop...etc visual interface without the user actually delving
into the code itself. That's the reason why my initial list seemed
somewhat small.

However I'm also compiling a list of all useful refactorings so that
in future I may be able to find a way to design the visualisation so
to speak so that I can incorporate the other refactorings
(particularly those that are performed within a function) in a way
that continues to be intuitive.

Currently though, I'm looking for a good C parser which I can use.

I considered using ANTLR with the GCC translation framework available
on its website to generate a lexer/parser for C but some of the
replies I've received here and in Google Groups point out the issue
with the preprocessor which the framework can't handle. So I'm
currently researching into the Eclipse CDT parser but it seems
unnecessarily complicated for my uses and so far I haven't really been
able to find any available standalone projects/tools which use the
parser package without having anything to do with the Eclipse IDE.

Anyone have any recommendations of examples which use the CDT parser
for code transformations or maybe another parser I should use?

Thanks!

I was frustrated by the available GNU-C-compatible parsers, so I wrote
my own. It's not perfect, but it generally works alright in NetBSD and
Linux with their respective libc. I extended GNU-C with linked-list
keywords, and loop constructs (foreach, and rforeach) to go with those.

http://code.google.com/p/opennexx/source/browse/trunk/coop.src/src/c_lex.l

http://code.google.com/p/opennexx/source/browse/trunk/coop.src/src/c_yacc.y

This is what starts it all:
http://code.google.com/p/opennexx/source/browse/trunk/coop.src/main.c

This is the build script:
http://code.google.com/p/opennexx/source/browse/trunk/coop.src/build.sh

It was my first parser/translator that used lexx/yacc. It was a good
learning experience, but as I said, it's not perfect. The parser should
handle most, if not all of C99. I also worked on a coop.experiment
branch in the trunk. It's very very difficult to parse GNU-C. Most of
GNU-C is hand parsed these days. There is very little yacc code in gcc.
I found it's a lot of work to resolve the ambiguities in the asm,
attribute, and extension features of GNU-C, but what I have works for
most of those. The parser should only have 1 ambiguity, in the IF/ELSE
that is normal.


George


On Mar 30, 8:47 am, George Peter Staplin
<georgepsSPAMME...@xxxxxxxxxxxx> wrote:
pingu219 wrote:
Hi I'm currently a student working on an honours-level project to
create a visual tool which will be able to represent C project files
and code as well as allow the user to perform high and certain low-
level refactorings.

At the moment I'm compiling a list of refactorings which are
applicable to C that people who program alot with structured
programming languages find useful.

So far I've got (some I got from someone else's post on another google
group):

- Rename variable/function
- Move variable/function
- Reduce scope of variable
- Publish function (make it public, put a declaration in the .h file)
- Perish function (make it static, remove it from the .h file)
- Add/Remove parameter from function
- Reorder function arguments
- Remove unnecessary includes

Cheers

Isn't that more like restructuring than refactoring?

I wrote something intended to evolve to do some of what you suggest.  
It's here:http://wiki.tcl.tk/11180 Fed Builder is portable too, thanks
to Tcl/Tk.

It saves code in a database and generates C code from that database.  
Feel free to use the code (it's BSD licensed) as long as you give me
credit.

Some of those features you mention sound very useful.

George

.



Relevant Pages

  • Re: What Refactorings Would you Like for C
    ... At the moment I'm kind of limiting the refactorings I consider as my ... in future I may be able to find a way to design the visualisation so ... I'm looking for a good C parser which I can use. ... It saves code in a database and generates C code from that database. ...
    (comp.programming)
  • Re: Is D2005 the most expensive editor in the world?
    ... if you really want to split hairs Syntax Colouring only ... but some refactorings may not need a parser either- Consider a ...
    (borland.public.delphi.non-technical)
  • Re: Is D2005 the most expensive editor in the world?
    ... if you really want to split hairs Syntax Colouring only ... but some refactorings may not need a parser either ...
    (borland.public.delphi.non-technical)