Boost logo

Boost-Commit :

From: hartmut.kaiser_at_[hidden]
Date: 2008-02-15 09:35:37


Author: hkaiser
Date: 2008-02-15 09:35:36 EST (Fri, 15 Feb 2008)
New Revision: 43266
URL: http://svn.boost.org/trac/boost/changeset/43266

Log:
Wave: More fixes to whitespace insertion engine.
Text files modified:
   trunk/boost/wave/util/insert_whitespace_detection.hpp | 152 +++++++++++++++++++++++++++++++++------
   1 files changed, 126 insertions(+), 26 deletions(-)

Modified: trunk/boost/wave/util/insert_whitespace_detection.hpp
==============================================================================
--- trunk/boost/wave/util/insert_whitespace_detection.hpp (original)
+++ trunk/boost/wave/util/insert_whitespace_detection.hpp 2008-02-15 09:35:36 EST (Fri, 15 Feb 2008)
@@ -199,7 +199,29 @@
         }
         return false;
     }
-
+
+ inline bool
+ handle_parens(boost::wave::token_id prev)
+ {
+ switch (static_cast<unsigned int>(prev)) {
+ case T_LEFTPAREN:
+ case T_RIGHTPAREN:
+ case T_LEFTBRACKET:
+ case T_RIGHTBRACKET:
+ case T_LEFTBRACE:
+ case T_RIGHTBRACE:
+ case T_SEMICOLON:
+ case T_COMMA:
+ case T_COLON:
+ // no insertion between parens/brackets/braces and operators
+ return false;
+
+ default:
+ break;
+ }
+ return true;
+ }
+
 } // namespace impl
 
 class insert_whitespace_detection
@@ -294,30 +316,64 @@
                             
         case T_MINUS:
         case T_MINUSMINUS:
+ case T_MINUSASSIGN:
+ if (T_MINUS == prev || T_MINUSMINUS == prev)
+ return true;
+ if (!impl::handle_parens(prev))
+ return false;
+ if (T_QUESTION_MARK == prev && T_QUESTION_MARK == beforeprev)
+ return true;
+ break;
+
         case T_PLUS:
         case T_PLUSPLUS:
- case T_LESS:
- case T_EQUAL:
- case T_ASSIGN:
- case T_GREATER:
+ case T_PLUSASSIGN:
+ if (T_PLUS == prev || T_PLUSPLUS == prev)
+ return true;
+ if (!impl::handle_parens(prev))
+ return false;
+ if (T_QUESTION_MARK == prev && T_QUESTION_MARK == beforeprev)
+ return true;
+ break;
+
         case T_DIVIDE:
- case T_CHARLIT:
- case T_NOT:
- case T_NOTEQUAL:
         case T_DIVIDEASSIGN:
- case T_MINUSASSIGN:
+ if (T_DIVIDE == prev)
+ return true;
+ if (!impl::handle_parens(prev))
+ return false;
+ if (T_QUESTION_MARK == prev && T_QUESTION_MARK == beforeprev)
+ return true;
+ break;
+
+ case T_EQUAL:
+ case T_ASSIGN:
             switch (static_cast<unsigned int>(prev)) {
- case T_LEFTPAREN:
- case T_RIGHTPAREN:
- case T_LEFTBRACKET:
- case T_RIGHTBRACKET:
- case T_LEFTBRACE:
- case T_RIGHTBRACE:
- case T_SEMICOLON:
- case T_COMMA:
- case T_COLON:
- // no insertion between parens/brackets/braces and operators
- return false;
+ case T_PLUSASSIGN:
+ case T_MINUSASSIGN:
+ case T_DIVIDEASSIGN:
+ case T_STARASSIGN:
+ case T_SHIFTRIGHTASSIGN:
+ case T_SHIFTLEFTASSIGN:
+ case T_EQUAL:
+ case T_NOTEQUAL:
+ case T_LESSEQUAL:
+ case T_GREATEREQUAL:
+ case T_LESS:
+ case T_GREATER:
+ case T_PLUS:
+ case T_MINUS:
+ case T_STAR:
+ case T_DIVIDE:
+ case T_ORASSIGN:
+ case T_ANDASSIGN:
+ case T_XORASSIGN:
+ case T_OR:
+ case T_AND:
+ case T_XOR:
+ case T_OROR:
+ case T_ANDAND:
+ return true;
 
             case T_QUESTION_MARK:
                 if (T_QUESTION_MARK == beforeprev)
@@ -325,10 +381,48 @@
                 break;
                 
             default:
+ if (!impl::handle_parens(prev))
+ return false;
                 break;
             }
             break;
 
+ case T_GREATER:
+ if (T_MINUS == prev)
+ return true; // prevent ->
+ // fall through
+ case T_LESS:
+ case T_CHARLIT:
+ case T_NOT:
+ case T_NOTEQUAL:
+ if (!impl::handle_parens(prev))
+ return false;
+ if (T_QUESTION_MARK == prev && T_QUESTION_MARK == beforeprev)
+ return true;
+ break;
+
+ case T_AND:
+ case T_ANDAND:
+ if (!impl::handle_parens(prev))
+ return false;
+ if (T_AND == prev || T_ANDAND == prev)
+ return true;
+ break;
+
+ case T_OR:
+ if (!impl::handle_parens(prev))
+ return false;
+ if (T_OR == prev)
+ return true;
+ break;
+
+ case T_XOR:
+ if (!impl::handle_parens(prev))
+ return false;
+ if (T_XOR == prev)
+ return true;
+ break;
+
         case T_COMPL_ALT:
         case T_OR_ALT:
         case T_AND_ALT:
@@ -367,15 +461,21 @@
         case T_STAR:
             if (T_STAR == prev)
                 return false; // '*****' do not need to be separated
+ if (T_GREATER== prev &&
+ (T_MINUS == beforeprev || T_MINUSMINUS == beforeprev)
+ )
+ {
+ return true; // prevent ->*
+ }
             break;
         }
 
- // else, handle operators separately
- if (IS_CATEGORY(current, OperatorTokenType) &&
- IS_CATEGORY(prev, OperatorTokenType))
- {
- return true; // operators must be delimited always
- }
+ // FIXME: else, handle operators separately (will catch to many cases)
+// if (IS_CATEGORY(current, OperatorTokenType) &&
+// IS_CATEGORY(prev, OperatorTokenType))
+// {
+// return true; // operators must be delimited always
+// }
         return false;
     }
     void shift_tokens (boost::wave::token_id next_id)


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk