all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Dmitry Antipov <dmantipov@yandex.ru>
To: Eli Zaretskii <eliz@gnu.org>
Cc: joakim@verona.se, emacs-devel@gnu.org
Subject: Re: Refactoring in Emacs
Date: Wed, 01 Aug 2012 08:14:47 +0400	[thread overview]
Message-ID: <5018AD37.1000509@yandex.ru> (raw)
In-Reply-To: <83pq7berfa.fsf@gnu.org>

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



  reply	other threads:[~2012-08-01  4:14 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-31 12:38 Note on 109327 Dmitry Antipov
2012-07-31 13:13 ` Dan Nicolaescu
2012-07-31 13:25   ` Dmitry Antipov
2012-07-31 13:33     ` Tom Tromey
2012-07-31 13:50       ` Dmitry Antipov
2012-07-31 21:47         ` Thien-Thi Nguyen
2012-08-01  4:34           ` Dmitry Antipov
2012-07-31 13:54 ` Juanma Barranquero
2012-07-31 17:04   ` Eli Zaretskii
2012-07-31 17:17     ` Juanma Barranquero
2012-07-31 17:35     ` joakim
2012-07-31 17:56       ` Dmitry Antipov
2012-07-31 17:42     ` Dmitry Antipov
2012-07-31 18:06       ` Refactoring in Emacs (was: Note on 109327) Eli Zaretskii
2012-08-01  4:14         ` Dmitry Antipov [this message]
2012-08-01 11:41           ` Refactoring in Emacs : CEDET Eric M. Ludlam
2012-08-01 14:50             ` Eli Zaretskii
2012-08-01 23:42               ` Eric Ludlam
2012-08-01 22:41           ` Refactoring in Emacs Richard Stallman
2012-08-01 14:05         ` Jason Rumney
2012-07-31 15:16 ` Note on 109327 Jan Djärv

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5018AD37.1000509@yandex.ru \
    --to=dmantipov@yandex.ru \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=joakim@verona.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.