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 1QCY1g-0002aL-Hm for garchives@archives.gentoo.org; Wed, 20 Apr 2011 14:05:04 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id B00051C09A; Wed, 20 Apr 2011 14:04:16 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 585091C09A for ; Wed, 20 Apr 2011 14:04:16 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id CC55D1B405C for ; Wed, 20 Apr 2011 14:04:15 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 24EC28024E for ; Wed, 20 Apr 2011 14:04: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: <196d4ef6e15ec963d1b932706c537f42c231e248.betelgeuse@gentoo> Subject: [gentoo-commits] proj/libbash:master commit in: bashast/, coding_standard/ X-VCS-Repository: proj/libbash X-VCS-Files: bashast/libbashWalker.g coding_standard/coding_standard.tex X-VCS-Directories: bashast/ coding_standard/ X-VCS-Committer: betelgeuse X-VCS-Committer-Name: Petteri Räty X-VCS-Revision: 196d4ef6e15ec963d1b932706c537f42c231e248 Date: Wed, 20 Apr 2011 14:04: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: ffc6de40152f0ffccb3780d652e43da4 commit: 196d4ef6e15ec963d1b932706c537f42c231e248 Author: Mu Qiao gentoo org> AuthorDate: Mon Apr 18 11:23:37 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Wed Apr 20 12:48:43 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3D196d4ef6 Coding standard: Add indentation rule for walker grammar Put colon and the first alternative of a rule in the same line. Add space between the rule and the left brace of the embedded action block. Use one space between rule name and 'returns'. Limit for line length is also added to the coding standard. --- bashast/libbashWalker.g | 208 +++++++++++++++++------------= ------ coding_standard/coding_standard.tex | 7 + 2 files changed, 109 insertions(+), 106 deletions(-) diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g index 848c110..76400f3 100644 --- a/bashast/libbashWalker.g +++ b/bashast/libbashWalker.g @@ -27,86 +27,85 @@ options =20 @includes{ =20 -#include -#include + #include + #include =20 -class interpreter; -void set_interpreter(std::shared_ptr w); + class interpreter; + void set_interpreter(std::shared_ptr w); =20 } =20 @postinclude{ =20 -#include "core/interpreter.h" -#include + #include "core/interpreter.h" + #include =20 } =20 @members{ =20 -static std::shared_ptr walker; + static std::shared_ptr walker; =20 -void set_interpreter(std::shared_ptr w) -{ - walker =3D w; -} - -inline void set_index(const std::string& name, unsigned& index, int valu= e) -{ - if(value < 0) - throw interpreter_exception((boost::format("Array index is less than 0= : \%s[\%d]") \% name \% value).str()); - index =3D value; -} + void set_interpreter(std::shared_ptr w) + { + walker =3D w; + } =20 -// Recursively count number of nodes of curr -static int count_nodes(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_T= REE curr) -{ - int child_count =3D adaptor->getChildCount(adaptor, curr); - if(child_count =3D=3D 0) + inline void set_index(const std::string& name, unsigned& index, int val= ue) { - // Leaf node - return 1; + if(value < 0) + throw interpreter_exception((boost::format("Array index is less than = 0: \%s[\%d]") \% name \% value).str()); + index =3D value; } - else + + // Recursively count number of nodes of curr + static int count_nodes(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_= TREE curr) { - int result =3D 0; - // Count every child - for(int i =3D 0; i !=3D child_count; ++i) - result +=3D count_nodes(adaptor, (pANTLR3_BASE_TREE)(adaptor->getChil= d(adaptor, curr, i))); - // Add itself, DOWN and UP - return result + 3; + int child_count =3D adaptor->getChildCount(adaptor, curr); + if(child_count =3D=3D 0) + { + // Leaf node + return 1; + } + else + { + int result =3D 0; + // Count every child + for(int i =3D 0; i !=3D child_count; ++i) + result +=3D count_nodes(adaptor, (pANTLR3_BASE_TREE)(adaptor->getChi= ld(adaptor, curr, i))); + // Add itself, DOWN and UP + return result + 3; + } } -} =20 } =20 start: list|EOF; =20 -list: - ^(LIST (function_def|logic_command_list)+); +list: ^(LIST (function_def|logic_command_list)+); =20 variable_definitions: ^(VARIABLE_DEFINITIONS var_def+); =20 -name_base returns[std::string libbash_value]: - NAME {$libbash_value =3D walker->get_string($NAME);} - | LETTER {$libbash_value =3D walker->get_string($LETTER);} - | '_' {$libbash_value=3D"_";}; +name_base returns[std::string libbash_value] + :NAME { $libbash_value =3D walker->get_string($NAME); } + |LETTER { $libbash_value =3D walker->get_string($LETTER); } + |'_' { $libbash_value=3D"_"; }; =20 -name returns[std::string libbash_value, unsigned index] +name returns[std::string libbash_value, unsigned index] @init { $index =3D 0; -}: - ^(libbash_name=3Dname_base value=3Darithmetics){ +} + :^(libbash_name=3Dname_base value=3Darithmetics) { set_index(libbash_name, $index, value); $libbash_value =3D libbash_name; } - |libbash_name=3Dname_base{ + |libbash_name=3Dname_base { $libbash_value =3D libbash_name; }; =20 num returns[std::string libbash_value] -options{ k=3D1; }: - DIGIT { $libbash_value =3D walker->get_string($DIGIT); } +options{ k=3D1; } + :DIGIT { $libbash_value =3D walker->get_string($DIGIT); } |NUMBER { $libbash_value =3D walker->get_string($NUMBER); }; =20 var_def @@ -114,8 +113,8 @@ var_def std::map values; unsigned index =3D 0; bool is_null =3D true; -}: - ^(EQUALS name (libbash_string=3Dstring_expr { is_null =3D false; })?){ +} + :^(EQUALS name (libbash_string=3Dstring_expr { is_null =3D false; })?) = { walker->set_value($name.libbash_value, libbash_string, $name.index, is= _null); } |^(EQUALS libbash_name=3Dname_base ^(ARRAY ( @@ -128,8 +127,8 @@ var_def walker->define(libbash_name, values); }; =20 -string_expr returns[std::string libbash_value]: - ^(STRING( +string_expr returns[std::string libbash_value] + :^(STRING( (DOUBLE_QUOTED_STRING) =3D> ^(DOUBLE_QUOTED_STRING (libbash_string=3Dd= ouble_quoted_string { $libbash_value +=3D libbash_string; })*) |(ARITHMETIC_EXPRESSION) =3D> ^(ARITHMETIC_EXPRESSION value=3Darithmet= ics { $libbash_value =3D boost::lexical_cast(value); }) |(var_ref[false]) =3D> libbash_string=3Dvar_ref[false] { $libbash_valu= e =3D libbash_string; } @@ -137,30 +136,30 @@ string_expr returns[std::string libbash_value]: )); =20 //double quoted string rule, allows expansions -double_quoted_string returns[std::string libbash_value]: - (var_ref[true]) =3D> libbash_string=3Dvar_ref[true] { $libbash_value =3D= libbash_string; } +double_quoted_string returns[std::string libbash_value] + :(var_ref[true]) =3D> libbash_string=3Dvar_ref[true] { $libbash_value =3D= libbash_string; } |(ARITHMETIC_EXPRESSION) =3D> ^(ARITHMETIC_EXPRESSION value=3Darithmeti= cs) { $libbash_value =3D boost::lexical_cast(value); } |libbash_string=3Dany_string { $libbash_value =3D libbash_string; }; =20 any_string returns[std::string libbash_value] @declarations { pANTLR3_BASE_TREE any_token; -}: - any_token=3D. { $libbash_value =3D walker->get_string(any_token); }; +} + :any_token=3D. { $libbash_value =3D walker->get_string(any_token); }; =20 //Allowable variable names in the variable expansion var_name returns[std::string libbash_value, unsigned index] @init { $var_name.index =3D 0; -}: - libbash_string=3Dnum { $libbash_value =3D libbash_string; } +} + :libbash_string=3Dnum { $libbash_value =3D libbash_string; } |name { $libbash_value =3D $name.libbash_value; $index =3D $name.index; }; =20 -var_expansion returns[std::string libbash_value]: - ^(USE_DEFAULT_WHEN_UNSET_OR_NULL var_name libbash_word=3Dword) { +var_expansion returns[std::string libbash_value] + :^(USE_DEFAULT_WHEN_UNSET_OR_NULL var_name libbash_word=3Dword) { libbash_value =3D walker->do_default_expansion($var_name.libbash_value= , libbash_word, $var_name.index); } |^(ASSIGN_DEFAULT_WHEN_UNSET_OR_NULL var_name libbash_word=3Dword) { @@ -184,14 +183,14 @@ var_expansion returns[std::string libbash_value]: } )); =20 -word returns[std::string libbash_value]: - |(num) =3D> libbash_string=3Dnum { $libbash_value =3D libbash_string; } +word returns[std::string libbash_value] + :(num) =3D> libbash_string=3Dnum { $libbash_value =3D libbash_string; } |libbash_string=3Dstring_expr { $libbash_value =3D libbash_string; } |value=3Darithmetics { $libbash_value =3D boost::lexical_cast(value); }; =20 //variable reference -var_ref [bool double_quoted] returns[std::string libbash_value]: - ^(VAR_REF name) { $libbash_value =3D walker->resolve($name= .libbash_value, $name.index); } +var_ref [bool double_quoted] returns[std::string libbash_value] + :^(VAR_REF name) { $libbash_value =3D walker->resolve($nam= e.libbash_value, $name.index); } |^(VAR_REF ^(libbash_string=3Dname_base AT)) { walker->get_all_elements= (libbash_string, $libbash_value); } |^(VAR_REF ^(libbash_string=3Dname_base TIMES)) { if(double_quoted) @@ -201,12 +200,12 @@ var_ref [bool double_quoted] returns[std::string li= bbash_value]: } |^(VAR_REF libbash_string=3Dvar_expansion) { $libbash_value =3D libbash= _string; }; =20 -command: - variable_definitions +command + :variable_definitions |simple_command; =20 -simple_command: - ^(COMMAND libbash_string=3Dstring_expr argument* var_def*) { +simple_command + :^(COMMAND libbash_string=3Dstring_expr argument* var_def*) { ANTLR3_MARKER func_index; if((func_index =3D walker->get_function_index(libbash_string)) !=3D -1= ) { @@ -225,23 +224,21 @@ simple_command: } }; =20 -argument: - var_ref[false] +argument + :var_ref[false] |string_expr; =20 -logic_command_list: - command - | ^(LOGICAND command command) - | ^(LOGICOR command command); +logic_command_list + :command + |^(LOGICAND command command) + |^(LOGICOR command command); =20 -command_list: - ^(LIST logic_command_list+); +command_list: ^(LIST logic_command_list+); =20 -compound_command: - ^(CURRENT_SHELL command_list); +compound_command: ^(CURRENT_SHELL command_list); =20 -function_def returns[int placeholder]: - ^(FUNCTION ^(STRING name) { +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 off= set right. @@ -252,8 +249,8 @@ function_def returns[int placeholder]: }); =20 // Only used in arithmetic expansion -primary returns[std::string libbash_value, unsigned index]: - (^(VAR_REF name)) =3D> ^(VAR_REF name) { +primary returns[std::string libbash_value, unsigned index] + :(^(VAR_REF name)) =3D> ^(VAR_REF name) { $libbash_value =3D $name.libbash_value; $index =3D $name.index; } @@ -269,38 +266,37 @@ primary returns[std::string libbash_value, unsigned= index]: =20 // shell arithmetic arithmetics returns[int value] -: - ^(LOGICOR l=3Darithmetics r=3Darithmetics){ $value =3D walker->logicor(= l, r); } - |^(LOGICAND l=3Darithmetics r=3Darithmetics){ $value =3D walker->logica= nd(l, r); } - |^(PIPE l=3Darithmetics r=3Darithmetics){ $value =3D walker->bitwiseor(= l, r); } - |^(CARET l=3Darithmetics r=3Darithmetics){ $value =3D walker->bitwisexo= r(l, r); } - |^(AMP l=3Darithmetics r=3Darithmetics){ $value =3D walker->bitwiseand(= l, r); } - |^(LEQ l=3Darithmetics r=3Darithmetics){ $value =3D walker->less_equal_= than(l, r); } - |^(GEQ l=3Darithmetics r=3Darithmetics){ $value =3D walker->greater_equ= al_than(l, r); } - |^(LESS_THAN l=3Darithmetics r=3Darithmetics){ $value =3D walker->less_= than(l, r); } - |^(GREATER_THAN l=3Darithmetics r=3Darithmetics){ $value =3D walker->gr= eater_than(l, r); } - |^(LSHIFT l=3Darithmetics r=3Darithmetics){ $value =3D walker->left_shi= ft(l, r); } - |^(RSHIFT l=3Darithmetics r=3Darithmetics){ $value =3D walker->right_sh= ift(l, r); } - |^(PLUS l=3Darithmetics r=3Darithmetics){ $value =3D walker->plus(l, r)= ; } - |^(PLUS_SIGN l=3Darithmetics){ $value =3D l; } - |^(MINUS l=3Darithmetics r=3Darithmetics){ $value =3D walker->minus(l, = r); } - |^(MINUS_SIGN l=3Darithmetics){ $value =3D -l; } - |^(TIMES l=3Darithmetics r=3Darithmetics){ $value =3D walker->multiply(= l, r); } - |^(SLASH l=3Darithmetics r=3Darithmetics){ $value =3D walker->divide(l,= r); } - |^(PCT l=3Darithmetics r=3Darithmetics){ $value =3D walker->mod(l, r); = } - |^(EXP l=3Darithmetics r=3Darithmetics){ $value =3D walker->exp(l, r); = } - |^(BANG l=3Darithmetics){ $value =3D walker->negation(l); } - |^(TILDE l=3Darithmetics){ $value =3D walker->bitwise_negation(l); } - |^(ARITHMETIC_CONDITION cnd=3Darithmetics l=3Darithmetics r=3Darithmeti= cs){ + :^(LOGICOR l=3Darithmetics r=3Darithmetics) { $value =3D walker->logico= r(l, r); } + |^(LOGICAND l=3Darithmetics r=3Darithmetics) { $value =3D walker->logic= and(l, r); } + |^(PIPE l=3Darithmetics r=3Darithmetics) { $value =3D walker->bitwiseor= (l, r); } + |^(CARET l=3Darithmetics r=3Darithmetics) { $value =3D walker->bitwisex= or(l, r); } + |^(AMP l=3Darithmetics r=3Darithmetics) { $value =3D walker->bitwiseand= (l, r); } + |^(LEQ l=3Darithmetics r=3Darithmetics) { $value =3D walker->less_equal= _than(l, r); } + |^(GEQ l=3Darithmetics r=3Darithmetics) { $value =3D walker->greater_eq= ual_than(l, r); } + |^(LESS_THAN l=3Darithmetics r=3Darithmetics) { $value =3D walker->less= _than(l, r); } + |^(GREATER_THAN l=3Darithmetics r=3Darithmetics) { $value =3D walker->g= reater_than(l, r); } + |^(LSHIFT l=3Darithmetics r=3Darithmetics) { $value =3D walker->left_sh= ift(l, r); } + |^(RSHIFT l=3Darithmetics r=3Darithmetics) { $value =3D walker->right_s= hift(l, r); } + |^(PLUS l=3Darithmetics r=3Darithmetics) { $value =3D walker->plus(l, r= ); } + |^(PLUS_SIGN l=3Darithmetics) { $value =3D l; } + |^(MINUS l=3Darithmetics r=3Darithmetics) { $value =3D walker->minus(l,= r); } + |^(MINUS_SIGN l=3Darithmetics) { $value =3D -l; } + |^(TIMES l=3Darithmetics r=3Darithmetics) { $value =3D walker->multiply= (l, r); } + |^(SLASH l=3Darithmetics r=3Darithmetics) { $value =3D walker->divide(l= , r); } + |^(PCT l=3Darithmetics r=3Darithmetics) { $value =3D walker->mod(l, r);= } + |^(EXP l=3Darithmetics r=3Darithmetics) { $value =3D walker->exp(l, r);= } + |^(BANG l=3Darithmetics) { $value =3D walker->negation(l); } + |^(TILDE l=3Darithmetics) { $value =3D walker->bitwise_negation(l); } + |^(ARITHMETIC_CONDITION cnd=3Darithmetics l=3Darithmetics r=3Darithmeti= cs) { $value =3D walker->arithmetic_condition(cnd, l, r); } |primary { $value =3D walker->resolve($primary.libbash_value, $primary.index= ); } - |^(PRE_INCR primary){ $value =3D walker->pre_incr($primary.libbash_valu= e, $primary.index); } - |^(PRE_DECR primary){ $value =3D walker->pre_decr($primary.libbash_valu= e, $primary.index); } - |^(POST_INCR primary){ $value =3D walker->post_incr($primary.libbash_va= lue, $primary.index); } - |^(POST_DECR primary){ $value =3D walker->post_decr($primary.libbash_va= lue, $primary.index); } + |^(PRE_INCR primary) { $value =3D walker->pre_incr($primary.libbash_val= ue, $primary.index); } + |^(PRE_DECR primary) { $value =3D walker->pre_decr($primary.libbash_val= ue, $primary.index); } + |^(POST_INCR primary) { $value =3D walker->post_incr($primary.libbash_v= alue, $primary.index); } + |^(POST_DECR primary) { $value =3D walker->post_decr($primary.libbash_v= alue, $primary.index); } |^(EQUALS primary l=3Darithmetics) { $value =3D walker->set_value($primary.libbash_value, l, $primary.index= ); } diff --git a/coding_standard/coding_standard.tex b/coding_standard/coding= _standard.tex index e039fb0..4d663a1 100644 --- a/coding_standard/coding_standard.tex +++ b/coding_standard/coding_standard.tex @@ -97,6 +97,13 @@ Tabs should not be used for indentation, only spaces. = Indentation width will be Tabs should be used for ANTLR grammar because antlrworks automatically g= enerate tabs. \\ Tabs should also be used for autotools related files(Makefile.am, config= ure.ac, etc). \\ Use ts=3D4 for indentation. +\subsection{Line length} +We don't have strict line length limit but you shouldn't write a line th= at is too long to be read easily. In general, we should keep the line len= gth under 110 characters. +\subsubsection{More indentation rules for tree walker grammar} +Put colon and the first alternative of a rule in the same line with no s= pace between them.\\ +Do not use space between the alternatives and '\textbar'.\\ +Put left brace of the embedded action block and the rule in the same lin= e with one space between them.\\ +Use one space between rule name and 'returns'. \subsection{Naming conventions} The name of a variable, function, class, or struct should be obvious fro= m it's name.\\ Names will use underscored names not mixed case.\\