[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Refactoring in Emacs
From: |
Dmitry Antipov |
Subject: |
Re: Refactoring in Emacs |
Date: |
Wed, 01 Aug 2012 08:14:47 +0400 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120713 Thunderbird/14.0 |
On 07/31/2012 10:06 PM, Eli Zaretskii wrote:
IIUC real refactoring of C should imply preprocessing and full
syntactic analysis
Why is that? Can you give a couple of examples?
It's easy to use regexps to make
foo (2, 1);
from
foo (1, 2);
But it may be very tricky or even impossible to do the same for:
1) foo (bar (x, y, z), baz (a, b, c));
2) foo (bar (x, y, foo (z, 1)), baz (foo (a, b) > 0 ? c : d, e, f));
3) foo (
#ifdef AAA
a,
#else
b,
#endif
c > 0 ? c : -c);
etc.
For 2), syntax tree may looks like:
++++++++++++[foo]++++++++++++
+ +
+++[bar]+++ ++++++[baz]++++++
+ + + + + +
x y +[foo]+ ++++[> ?]++++ e f
+ + + + +
z 1 +[foo]+ c d
+ +
a b
So, refactoring is (hm, relatively) simple: you should traverse the tree,
look for
+[foo]+
+ +
x y
pattern and swap subtrees.
Check http://gcc-melt.org, it looks very similar to what I'm thinking about.
Dmitry
- Re: Refactoring in Emacs,
Dmitry Antipov <=