From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1QVJwA-0000BT-W1 for garchives@archives.gentoo.org; Sat, 11 Jun 2011 08:52:59 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 19F331C01D; Sat, 11 Jun 2011 08:52:17 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id C1EEF1C01C for ; Sat, 11 Jun 2011 08:52:16 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 564A51B4036 for ; Sat, 11 Jun 2011 08:52:15 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 52A2280048 for ; Sat, 11 Jun 2011 08:52:14 +0000 (UTC) From: "Petteri Räty" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Petteri Räty" Message-ID: <500e3427ff9ec64473f052e8c11a992d34f5e09f.betelgeuse@gentoo> Subject: [gentoo-commits] proj/libbash:master commit in: bashast/ X-VCS-Repository: proj/libbash X-VCS-Files: bashast/libbashWalker.g X-VCS-Directories: bashast/ X-VCS-Committer: betelgeuse X-VCS-Committer-Name: Petteri Räty X-VCS-Revision: 500e3427ff9ec64473f052e8c11a992d34f5e09f Date: Sat, 11 Jun 2011 08:52:14 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 0d3ac74c891a56baf44253f725e14b63 commit: 500e3427ff9ec64473f052e8c11a992d34f5e09f Author: Mu Qiao gentoo org> AuthorDate: Fri Jun 10 08:30:05 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Sat Jun 11 08:09:12 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3D500e3427 Walker: use namespace instead of static functions We removed the inline keyword as compiler will do it when proper optimization level/flag is on. --- bashast/libbashWalker.g | 137 ++++++++++++++++++++++++-----------------= ------ 1 files changed, 70 insertions(+), 67 deletions(-) diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g index 5587bfa..962a57d 100644 --- a/bashast/libbashWalker.g +++ b/bashast/libbashWalker.g @@ -62,84 +62,87 @@ options walker =3D w; } =20 - inline void set_index(const std::string& name, unsigned& index, int val= ue) + namespace { - if(value < 0) - throw interpreter_exception((boost::format("Array index is less than = 0: \%s[\%d]") \% name \% value).str()); - index =3D value; - } - - // seek to LT(2) and consume - static void seek_to_next_tree(plibbashWalker ctx) - { - // Current depth of the tree we are traversing - int depth =3D 1; - - // The beginning should always be ROOT DOWN ANY_TOKEN - // So we start from LA(4) - int index =3D 4; - for(; depth !=3D 0; ++index) + void set_index(const std::string& name, unsigned& index, int value) { - // Go one level done if we encounter DOWN - if(LA(index) =3D=3D DOWN) - ++depth; - // Go one level up if we encounter UP. When depth=3D=3D0, we finishe = one node - else if(LA(index) =3D=3D UP) - --depth; + if(value < 0) + throw interpreter_exception((boost::format("Array index is less than= 0: \%s[\%d]") \% name \% value).str()); + index =3D value; } =20 - // Seek to the correct offset and consume. - SEEK(INDEX() + index - 2); - CONSUME(); - } - - // The method is used to append a pattern with another one. Because it'= s not allowed to append an empty pattern, - // we need the argument 'do_append' to indicate whether the pattern is = empty. 'do_append' will be set to true after - // the first assignment. - inline void append(boost::xpressive::sregex& pattern, const boost::xpre= ssive::sregex& new_pattern, bool& do_append) - { - using namespace boost::xpressive; - if(do_append) + // seek to LT(2) and consume + void seek_to_next_tree(plibbashWalker ctx) { - pattern =3D sregex(pattern >> new_pattern); + // Current depth of the tree we are traversing + int depth =3D 1; + + // The beginning should always be ROOT DOWN ANY_TOKEN + // So we start from LA(4) + int index =3D 4; + for(; depth !=3D 0; ++index) + { + // Go one level done if we encounter DOWN + if(LA(index) =3D=3D DOWN) + ++depth; + // Go one level up if we encounter UP. When depth=3D=3D0, we finishe= one node + else if(LA(index) =3D=3D UP) + --depth; + } + + // Seek to the correct offset and consume. + SEEK(INDEX() + index - 2); + CONSUME(); } - else + + // The method is used to append a pattern with another one. Because it= 's not allowed to append an empty pattern, + // we need the argument 'do_append' to indicate whether the pattern is= empty. 'do_append' will be set to true after + // the first assignment. + void append(boost::xpressive::sregex& pattern, const boost::xpressive:= :sregex& new_pattern, bool& do_append) { - pattern =3D new_pattern; - do_append =3D true; + using namespace boost::xpressive; + if(do_append) + { + pattern =3D sregex(pattern >> new_pattern); + } + else + { + pattern =3D new_pattern; + do_append =3D true; + } } - } =20 - bool match(const std::string& target, - const boost::xpressive::sregex& pattern) - { - return boost::xpressive::regex_match(target, pattern); - } + bool match(const std::string& target, + const boost::xpressive::sregex& pattern) + { + return boost::xpressive::regex_match(target, pattern); + } =20 - /// \brief parse the text value of a tree to integer - /// \param the target tree - /// \return the parsed value - static int parse_int(ANTLR3_BASE_TREE* tree) - { - return tree->getText(tree)->toInt32(tree->getText(tree)); - } + /// \brief parse the text value of a tree to integer + /// \param the target tree + /// \return the parsed value + int parse_int(ANTLR3_BASE_TREE* tree) + { + return tree->getText(tree)->toInt32(tree->getText(tree)); + } =20 - /// \brief a helper function that get the string value - /// of the given pANTLR3_BASE_TREE node. - /// \param the target tree node - /// \return the value of node->text - static std::string get_string(pANTLR3_BASE_TREE node) - { - pANTLR3_COMMON_TOKEN token =3D node->getToken(node); - // The tree walker may send null pointer here, so return an empty - // string if that's the case. - if(!token->start) - return ""; - // Use reinterpret_cast here because we have to cast C code. - // The real type here is int64_t which is used as a pointer. - // token->stop - token->start + 1 should be bigger than 0. - return std::string(reinterpret_cast(token->start), - boost::numeric_cast(token->stop - token->start + 1)); + /// \brief a helper function that get the string value + /// of the given pANTLR3_BASE_TREE node. + /// \param the target tree node + /// \return the value of node->text + std::string get_string(pANTLR3_BASE_TREE node) + { + pANTLR3_COMMON_TOKEN token =3D node->getToken(node); + // The tree walker may send null pointer here, so return an empty + // string if that's the case. + if(!token->start) + return ""; + // Use reinterpret_cast here because we have to cast C code. + // The real type here is int64_t which is used as a pointer. + // token->stop - token->start + 1 should be bigger than 0. + return std::string(reinterpret_cast(token->start), + boost::numeric_cast(token->stop - token->start + 1))= ; + } } } =20