Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r115:6318702e8b28
Date: 2014-11-29 11:26 +0100
http://bitbucket.org/cffi/creflect/changeset/6318702e8b28/

Log:    small rewrites

diff --git a/creflect/src/c_decl_parser.c b/creflect/src/c_decl_parser.c
--- a/creflect/src/c_decl_parser.c
+++ b/creflect/src/c_decl_parser.c
@@ -297,17 +297,20 @@
     tok->delay_slots = delay_slot;
     while (1) {
         intptr_t tok_kind = *delay_slot++;
-        if (tok_kind > 0) {
-            switch (tok_kind) {
-            case TOK_END:
-                return t1;
-            case TOK_STAR:
-                t1 = tok->cb->get_pointer_type(tok->cb, t1);
-                break;
-            case TOK_CONST:
-                t1 = tok->cb->get_const_type(tok->cb, t1);
-                break;
-            case TOK_OPEN_BRACKET:   /* array */
+        if (tok_kind <= 0) {
+            delay_slot = tok->all_delay_slots + (-tok_kind);
+            continue;
+        }
+        switch (tok_kind) {
+        case TOK_END:
+            return t1;
+        case TOK_STAR:
+            t1 = tok->cb->get_pointer_type(tok->cb, t1);
+            break;
+        case TOK_CONST:
+            t1 = tok->cb->get_const_type(tok->cb, t1);
+            break;
+        case TOK_OPEN_BRACKET:   /* array */
             {
                 uintptr_t length = (uintptr_t)*delay_slot++;
                 if (is_func_arg && *delay_slot == TOK_END) {
@@ -321,8 +324,8 @@
                     t1 = tok->cb->get_incomplete_array_type(tok->cb, t1);
                 break;
             }
-            case TOK_OPEN_PAREN:   /* function */
-            case TOK_DOTDOTDOT:    /* function ending with a '...' */
+        case TOK_OPEN_PAREN:   /* function */
+        case TOK_DOTDOTDOT:    /* function ending with a '...' */
             {
                 intptr_t nbargs = *delay_slot++;
                 crx_type_t **argtypes = (crx_type_t **)delay_slot;
@@ -339,12 +342,8 @@
                 }
                 break;
             }
-            default:
-                abort();
-            }
-        }
-        else {
-            delay_slot = tok->all_delay_slots + (-tok_kind);
+        default:
+            assert(!"missing delay slot case");
         }
     }
 }
@@ -397,8 +396,6 @@
     }
 
     if (modifiers_length || modifiers_sign) {
-        size_t size;
-        char *name;
 
         switch (tok->kind) {
 
@@ -427,17 +424,21 @@
             next_token(tok);
             /* fall-through */
         default:
-            switch (modifiers_length) {
-            case -2: size = sizeof(char);      name = "char";      break;
-            case -1: size = sizeof(short);     name = "short";     break;
-            case 1:  size = sizeof(long);      name = "long";      break;
-            case 2:  size = sizeof(long long); name = "long long"; break;
-            default: size = sizeof(int);       name = "int";       break;
+            {
+                size_t size;
+                char *name;
+                switch (modifiers_length) {
+                case -2: size = sizeof(char);      name = "char";      break;
+                case -1: size = sizeof(short);     name = "short";     break;
+                case 1:  size = sizeof(long);      name = "long";      break;
+                case 2:  size = sizeof(long long); name = "long long"; break;
+                default: size = sizeof(int);       name = "int";       break;
+                }
+                if (modifiers_sign < 0)
+                    t1 = tok->cb->get_unsigned_type(tok->cb, size, name);
+                else
+                    t1 = tok->cb->get_signed_type(tok->cb, size, name);
             }
-            if (modifiers_sign < 0)
-                t1 = tok->cb->get_unsigned_type(tok->cb, size, name);
-            else
-                t1 = tok->cb->get_signed_type(tok->cb, size, name);
         }
     }
     else {
@@ -474,11 +475,7 @@
         case TOK_UNION:
         {
             char identifier[1024];
-            crx_type_t *(*get_type)(crx_builder_t *, const char *);
-            if (tok->kind == TOK_STRUCT)
-                get_type = tok->cb->get_struct_type;
-            else
-                get_type = tok->cb->get_union_type;
+            int kind = tok->kind;
             next_token(tok);
             if (tok->kind != TOK_IDENTIFIER)
                 return parse_error(tok, "struct or union name expected");
@@ -486,7 +483,10 @@
                 return parse_error(tok, "struct or union name too long");
             memcpy(identifier, tok->p, tok->size);
             identifier[tok->size] = 0;
-            t1 = get_type(tok->cb, identifier);
+            if (kind == TOK_STRUCT)
+                t1 = tok->cb->get_struct_type(tok->cb, identifier);
+            else
+                t1 = tok->cb->get_union_type(tok->cb, identifier);
             break;
         }
         default:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to