From: "Petteri Räty" <betelgeuse@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/libbash:master commit in: bashast/
Date: Wed, 27 Apr 2011 15:11:10 +0000 (UTC) [thread overview]
Message-ID: <cab98c13280a953bc5cedb911dae493b74c8093c.betelgeuse@gentoo> (raw)
commit: cab98c13280a953bc5cedb911dae493b74c8093c
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Sun Apr 24 12:28:21 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Mon Apr 25 10:07:50 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=cab98c13
Walker: change the implementation of index searching
We used recursive counting algorithm to find the index of LT(2).
Now it's changed to recurrence algorithm that directly traverse the
input stream. This can benefit function definition and compound
command.
---
bashast/libbashWalker.g | 40 ++++++++++++++++++++--------------------
1 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index b6123d9..a3bf40d 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -64,24 +64,27 @@ options
index = value;
}
- // Recursively count number of nodes of curr
- static int count_nodes(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE curr)
+ // seek to LT(2) and consume
+ static void seek_to_next_tree(plibbashWalker ctx)
{
- int child_count = adaptor->getChildCount(adaptor, curr);
- if(child_count == 0)
- {
- // Leaf node
- return 1;
- }
- else
+ // We start from LA(1)
+ int index = 1;
+ // Current depth of the tree we are traversing
+ int depth = 1;
+
+ for(index = 1; depth != 0; ++index)
{
- int result = 0;
- // Count every child
- for(int i = 0; i != child_count; ++i)
- result += count_nodes(adaptor, (pANTLR3_BASE_TREE)(adaptor->getChild(adaptor, curr, i)));
- // Add itself, DOWN and UP
- return result + 3;
+ // Go one level done if we encounter DOWN
+ if(LA(index) == DOWN)
+ ++depth;
+ // Go one level up if we encounter UP. When depth==0, we finishe one node
+ else if(LA(index) == UP)
+ --depth;
}
+
+ // Seek to the correct offset and consume.
+ SEEK(INDEX() + index - 3);
+ CONSUME();
}
}
@@ -324,11 +327,8 @@ function_def returns[int placeholder]
:^(FUNCTION ^(STRING name) {
// Define the function with current index
walker->define_function($name.libbash_value, INDEX());
- // Skip the AST for function body, minus one is needed to make the offset right.
- // LT(1) is the function body. It should match the compound_command rule.
- SEEK(INDEX() + count_nodes(ADAPTOR, LT(1)) - 1);
- // After seeking ahead, we need to call CONSUME to eat all the nodes we've skipped.
- CONSUME();
+ // Skip the AST for function body
+ seek_to_next_tree(ctx);
});
// Only used in arithmetic expansion
next reply other threads:[~2011-04-27 15:12 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-27 15:11 Petteri Räty [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-08-04 13:53 [gentoo-commits] proj/libbash:master commit in: bashast/ Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-08-04 13:53 Petteri Räty
2011-06-26 13:38 Petteri Räty
2011-06-14 8:28 Petteri Räty
2011-06-14 8:28 Petteri Räty
2011-06-11 8:52 Petteri Räty
2011-05-29 11:20 Petteri Räty
2011-05-29 11:20 Petteri Räty
2011-05-22 21:00 Petteri Räty
2011-05-12 14:06 Petteri Räty
2011-04-21 7:55 Petteri Räty
2011-04-20 11:26 Petteri Räty
2011-04-20 11:26 Petteri Räty
2011-04-20 11:26 Petteri Räty
2011-04-20 11:26 Petteri Räty
2011-04-20 11:26 Petteri Räty
2011-04-20 11:26 Petteri Räty
2011-04-20 11:26 Petteri Räty
2011-04-20 11:26 Petteri Räty
2011-04-14 4:50 Petteri Räty
2011-04-12 18:29 Petteri Räty
2011-04-12 7:19 Petteri Räty
2011-04-12 7:19 Petteri Räty
2011-04-12 7:19 Petteri Räty
2011-04-11 6:50 Petteri Räty
2011-04-11 6:50 Petteri Räty
2011-04-09 13:08 Petteri Räty
2011-04-09 13:08 Petteri Räty
2011-04-09 6:36 Petteri Räty
2011-04-09 6:27 Petteri Räty
2011-04-09 6:27 Petteri Räty
2011-04-09 6:27 Petteri Räty
2011-04-09 6:27 Petteri Räty
2011-04-09 6:27 Petteri Räty
2011-04-08 14:26 Petteri Räty
2011-04-08 14:26 Petteri Räty
2011-04-07 16:44 Petteri Räty
2011-04-07 7:48 Petteri Räty
2011-04-06 15:07 Petteri Räty
2011-04-04 15:52 Petteri Räty
2011-04-02 15:50 Petteri Räty
2011-04-02 15:50 Petteri Räty
2011-03-22 20:52 Petteri Räty
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=cab98c13280a953bc5cedb911dae493b74c8093c.betelgeuse@gentoo \
--to=betelgeuse@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox