From patchwork Fri Feb 3 04:28:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 19103 Received: (qmail 61947 invoked by alias); 3 Feb 2017 04:28:54 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 61707 invoked by uid 89); 3 Feb 2017 04:28:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=OFFSET, *flags, *type, TYPE_CODE X-HELO: gproxy6-pub.mail.unifiedlayer.com Received: from gproxy6-pub.mail.unifiedlayer.com (HELO gproxy6-pub.mail.unifiedlayer.com) (67.222.39.168) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Fri, 03 Feb 2017 04:28:41 +0000 Received: (qmail 3002 invoked by uid 0); 3 Feb 2017 04:28:39 -0000 Received: from unknown (HELO CMOut01) (10.0.90.82) by gproxy6.mail.unifiedlayer.com with SMTP; 3 Feb 2017 04:28:39 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id g4Uc1u00c2f2jeq014UfFy; Thu, 02 Feb 2017 21:28:39 -0700 X-Authority-Analysis: v=2.1 cv=NJxGpSKg c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=n2v9WMKugxEA:10 a=zstS-IiYAAAA:8 a=5D1kXAnyyetmH0apZWwA:9 a=sk81SBjpHy3Blbus:21 a=jbAKplTxoYjE3SSq:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 174-16-146-181.hlrn.qwest.net ([174.16.146.181]:54284 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1cZVUC-0002Mm-Jg; Thu, 02 Feb 2017 21:28:36 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [FYI 3/3] Use bool in Rust code Date: Thu, 2 Feb 2017 21:28:30 -0700 Message-Id: <20170203042830.31311-4-tom@tromey.com> In-Reply-To: <20170203042830.31311-1-tom@tromey.com> References: <20170203042830.31311-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1cZVUC-0002Mm-Jg X-Source-Sender: 174-16-146-181.hlrn.qwest.net (bapiya.Home) [174.16.146.181]:54284 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This changes various functions in the Rust code to use a bool rather than an int when a boolean is intended. 2017-02-02 Tom Tromey * rust-exp.y (ends_raw_string, space_then_number) (rust_identifier_start_p): Return bool. * rust-lang.c (rust_tuple_type_p, rust_underscore_fields) (rust_tuple_struct_type_p, rust_tuple_variant_type_p) (rust_slice_type_p, rust_range_type_p, rust_u8_type_p) (rust_chartype_p): Return bool. (val_print_struct, rust_print_struct_def, rust_print_type): Update. * rust-lang.h (rust_tuple_type_p, rust_tuple_struct_type_p): Return bool. --- gdb/ChangeLog | 13 +++++++++++++ gdb/rust-exp.y | 12 ++++++------ gdb/rust-lang.c | 39 ++++++++++++++++++++------------------- gdb/rust-lang.h | 4 ++-- 4 files changed, 41 insertions(+), 27 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index d133a2e..2f5ba2f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,18 @@ 2017-02-02 Tom Tromey + * rust-exp.y (ends_raw_string, space_then_number) + (rust_identifier_start_p): Return bool. + * rust-lang.c (rust_tuple_type_p, rust_underscore_fields) + (rust_tuple_struct_type_p, rust_tuple_variant_type_p) + (rust_slice_type_p, rust_range_type_p, rust_u8_type_p) + (rust_chartype_p): Return bool. + (val_print_struct, rust_print_struct_def, rust_print_type): + Update. + * rust-lang.h (rust_tuple_type_p, rust_tuple_struct_type_p): + Return bool. + +2017-02-02 Tom Tromey + * rust-lang.c: Reindent. 2017-02-02 Tom Tromey diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y index 98301a4..b3e0366 100644 --- a/gdb/rust-exp.y +++ b/gdb/rust-exp.y @@ -1197,7 +1197,7 @@ starts_raw_string (const char *str) /* Return true if STR looks like the end of a raw string that had N hashes at the start. */ -static int +static bool ends_raw_string (const char *str, int n) { int i; @@ -1205,8 +1205,8 @@ ends_raw_string (const char *str, int n) gdb_assert (str[0] == '"'); for (i = 0; i < n; ++i) if (str[i + 1] != '#') - return 0; - return 1; + return false; + return true; } /* Lex a string constant. */ @@ -1283,7 +1283,7 @@ lex_string (void) /* Return true if STRING starts with whitespace followed by a digit. */ -static int +static bool space_then_number (const char *string) { const char *p = string; @@ -1291,14 +1291,14 @@ space_then_number (const char *string) while (p[0] == ' ' || p[0] == '\t') ++p; if (p == string) - return 0; + return false; return *p >= '0' && *p <= '9'; } /* Return true if C can start an identifier. */ -static int +static bool rust_identifier_start_p (char c) { return ((c >= 'a' && c <= 'z') diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index a483b96..a804824 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -272,7 +272,7 @@ rust_get_disr_info (struct type *type, const gdb_byte *valaddr, /* See rust-lang.h. */ -int +bool rust_tuple_type_p (struct type *type) { /* The current implementation is a bit of a hack, but there's @@ -287,7 +287,7 @@ rust_tuple_type_p (struct type *type) /* Return true if all non-static fields of a structlike type are in a sequence like __0, __1, __2. OFFSET lets us skip fields. */ -static int +static bool rust_underscore_fields (struct type *type, int offset) { int i, field_number; @@ -295,7 +295,7 @@ rust_underscore_fields (struct type *type, int offset) field_number = 0; if (TYPE_CODE (type) != TYPE_CODE_STRUCT) - return 0; + return false; for (i = 0; i < TYPE_NFIELDS (type); ++i) { if (!field_is_static (&TYPE_FIELD (type, i))) @@ -308,17 +308,17 @@ rust_underscore_fields (struct type *type, int offset) xsnprintf (buf, sizeof (buf), "__%d", field_number); if (strcmp (buf, TYPE_FIELD_NAME (type, i)) != 0) - return 0; + return false; field_number++; } } } - return 1; + return true; } /* See rust-lang.h. */ -int +bool rust_tuple_struct_type_p (struct type *type) { /* This is just an approximation until DWARF can represent Rust more @@ -329,7 +329,7 @@ rust_tuple_struct_type_p (struct type *type) /* Return true if a variant TYPE is a tuple variant, false otherwise. */ -static int +static bool rust_tuple_variant_type_p (struct type *type) { /* First field is discriminant */ @@ -338,7 +338,7 @@ rust_tuple_variant_type_p (struct type *type) /* Return true if TYPE is a slice type, otherwise false. */ -static int +static bool rust_slice_type_p (struct type *type) { return (TYPE_CODE (type) == TYPE_CODE_STRUCT @@ -348,7 +348,7 @@ rust_slice_type_p (struct type *type) /* Return true if TYPE is a range type, otherwise false. */ -static int +static bool rust_range_type_p (struct type *type) { int i; @@ -357,22 +357,22 @@ rust_range_type_p (struct type *type) || TYPE_NFIELDS (type) > 2 || TYPE_TAG_NAME (type) == NULL || strstr (TYPE_TAG_NAME (type), "::Range") == NULL) - return 0; + return false; if (TYPE_NFIELDS (type) == 0) - return 1; + return true; i = 0; if (strcmp (TYPE_FIELD_NAME (type, 0), "start") == 0) { if (TYPE_NFIELDS (type) == 1) - return 1; + return true; i = 1; } else if (TYPE_NFIELDS (type) == 2) { /* First field had to be "start". */ - return 0; + return false; } return strcmp (TYPE_FIELD_NAME (type, i), "end") == 0; @@ -380,7 +380,7 @@ rust_range_type_p (struct type *type) /* Return true if TYPE seems to be the type "u8", otherwise false. */ -static int +static bool rust_u8_type_p (struct type *type) { return (TYPE_CODE (type) == TYPE_CODE_INT @@ -390,7 +390,7 @@ rust_u8_type_p (struct type *type) /* Return true if TYPE is a Rust character type. */ -static int +static bool rust_chartype_p (struct type *type) { return (TYPE_CODE (type) == TYPE_CODE_CHAR @@ -479,8 +479,8 @@ val_print_struct (struct type *type, int embedded_offset, { int i; int first_field; - int is_tuple = rust_tuple_type_p (type); - int is_tuple_struct = !is_tuple && rust_tuple_struct_type_p (type); + bool is_tuple = rust_tuple_type_p (type); + bool is_tuple_struct = !is_tuple && rust_tuple_struct_type_p (type); struct value_print_options opts; if (!is_tuple) @@ -763,7 +763,8 @@ rust_print_struct_def (struct type *type, const char *varstring, struct ui_file *stream, int show, int level, const struct type_print_options *flags) { - int is_tuple_struct, i; + bool is_tuple_struct; + int i; /* Print a tuple type simply. */ if (rust_tuple_type_p (type)) @@ -988,7 +989,7 @@ rust_print_type (struct type *type, const char *varstring, if (TYPE_NFIELDS (variant_type) > skip_to) { int first = 1; - int is_tuple = rust_tuple_variant_type_p (variant_type); + bool is_tuple = rust_tuple_variant_type_p (variant_type); int j; fputs_filtered (is_tuple ? "(" : "{", stream); diff --git a/gdb/rust-lang.h b/gdb/rust-lang.h index 6c627ae..8f2b682 100644 --- a/gdb/rust-lang.h +++ b/gdb/rust-lang.h @@ -30,10 +30,10 @@ extern int rust_parse (struct parser_state *); extern void rustyyerror (char *); /* Return true if TYPE is a tuple type; otherwise false. */ -extern int rust_tuple_type_p (struct type *type); +extern bool rust_tuple_type_p (struct type *type); /* Return true if TYPE is a tuple struct type; otherwise false. */ -extern int rust_tuple_struct_type_p (struct type *type); +extern bool rust_tuple_struct_type_p (struct type *type); /* Given a block, find the name of the block's crate. Returns an empty stringif no crate name can be found. */