bug-indent
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/7] handletoken: Detect C99 compound literals


From: Tim Hentenaar
Subject: [PATCH 1/7] handletoken: Detect C99 compound literals
Date: Sun, 5 Jul 2015 15:07:57 +0200

This wil detect a lbrace following a cast as a C99 compound literal.

In order for the cast to be detected with a typedef, you must first
add the typedef to the list with the -T option.
---
 src/handletoken.c | 8 +++++++-
 src/indent.h      | 3 ++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/handletoken.c b/src/handletoken.c
index f6ca8a8..7bdb7f8 100644
--- a/src/handletoken.c
+++ b/src/handletoken.c
@@ -487,7 +487,7 @@ static void handle_token_rparen(
    exit_values_ty * file_exit_value,
    BOOLEAN        * pbreak_line)
 {
-    char tmpchar[2];
+    char tmpchar[2], *tmp;
 
     parser_state_tos->paren_depth--;
     
@@ -527,6 +527,12 @@ static void handle_token_rparen(
             parser_state_tos->want_blank = false;
             parser_state_tos->can_break = bb_cast;
         }
+
+        /* Check for a C99 compound literal */
+        tmp = token + 1;
+        while (isspace(*tmp)) tmp++;
+        if (*tmp == '{')
+            parser_state_tos->block_init = 3;
     }
     else if (parser_state_tos->in_decl &&
              !parser_state_tos->block_init &&
diff --git a/src/indent.h b/src/indent.h
index 4d8f5e1..5a278ce 100644
--- a/src/indent.h
+++ b/src/indent.h
@@ -402,7 +402,8 @@ typedef struct parser_state
     int                   sizeof_mask; /*!<  indicates which close parens 
close off
                                         * sizeof''s */
     int                   block_init;  /*!<  set to 1 if inside a block 
initialization
-                                        * set to 2 if inside an enum 
declaration */
+                                        * set to 2 if inside an enum 
declaration
+                                        * and 3 for C99 compound literals. */
     int block_init_level;         /*!<  The level of brace nesting in an
                                    * initialization (0 in an enum decl) */
     int last_nl;                  /*!<  this is true if the last thing scanned 
was
-- 
2.3.6




reply via email to

[Prev in Thread] Current Thread [Next in Thread]