From patchwork Tue Oct 12 23:05:05 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 67631 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id E49F1B70A8 for ; Wed, 13 Oct 2010 10:05:26 +1100 (EST) Received: (qmail 13557 invoked by alias); 12 Oct 2010 23:05:24 -0000 Received: (qmail 13547 invoked by uid 22791); 12 Oct 2010 23:05:21 -0000 X-SWARE-Spam-Status: No, hits=-1.2 required=5.0 tests=AWL, BAYES_00, TW_BJ, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (140.186.70.10) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 12 Oct 2010 23:05:14 +0000 Received: from eggs.gnu.org ([140.186.70.92]:41489) by fencepost.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1P5nuB-00008W-Qe for gcc-patches@gnu.org; Tue, 12 Oct 2010 19:05:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P5nu6-00019J-BA for gcc-patches@gnu.org; Tue, 12 Oct 2010 19:05:11 -0400 Received: from smtp191.iad.emailsrvr.com ([207.97.245.191]:36240) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P5nu6-00019F-6F for gcc-patches@gnu.org; Tue, 12 Oct 2010 19:05:06 -0400 Received: from relay29.relay.iad.mlsrvr.com (localhost [127.0.0.1]) by relay29.relay.iad.mlsrvr.com (SMTP Server) with ESMTP id A27E31B4150 for ; Tue, 12 Oct 2010 19:05:05 -0400 (EDT) Received: from dynamic4.wm-web.iad.mlsrvr.com (dynamic4.wm-web.iad.mlsrvr.com [192.168.2.153]) by relay29.relay.iad.mlsrvr.com (SMTP Server) with ESMTP id 8D80B1B4014 for ; Tue, 12 Oct 2010 19:05:05 -0400 (EDT) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic4.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id 747D31D4A24D for ; Tue, 12 Oct 2010 19:05:05 -0400 (EDT) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Wed, 13 Oct 2010 01:05:05 +0200 (CEST) Date: Wed, 13 Oct 2010 01:05:05 +0200 (CEST) Subject: libobjc - encoding tidyup From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 X-Type: plain Message-ID: <1286924705.475419601@192.168.2.228> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This tidies up some details in encoding.c, and fixes the historical bug where objc_skip_offset would skip a byte even if there is no offset to skip. The fix comes from GNUstep. Thanks 2010-10-12 Nicola Pero * encoding.c: Tidied up comments. (objc_skip_variable_name): New static inline function. (objc_sizeof_type): Use objc_skip_variable_name instead of copying the same code over and over. (objc_alignof_type): Same. (objc_aligned_size): Same. (objc_promoted_size): Same. (objc_skip_typespec): Same. (objc_layout_structure_next_member): Same. (objc_skip_offset): Skip a '-' before the digits (if any). Fixed historical bug where objc_skip_offset would skip one byte even if there is no offset: check that the first offset digit is actually a digit before skipping it. (objc_skip_type_qualifiers): Mark as inline. (objc_skip_typespec): Mark as inline. Index: encoding.c =================================================================== --- encoding.c (revision 165400) +++ encoding.c (working copy) @@ -28,8 +28,7 @@ see the files COPYING3 and COPYING.RUNTIME respect /* FIXME: This file has no business including tm.h. */ /* FIXME: This file contains functions that will abort the entire - program if they fail. Is that really needed ? -*/ + program if they fail. Is that really needed ? */ #include "objc-private/common.h" #include "objc-private/error.h" @@ -139,22 +138,34 @@ static int __attribute__ ((__unused__)) not_target #define darwin_rs6000_special_round_type_align(S,C,S2) \ rs6000_special_round_type_align(S,C,S2) -/* - return the size of an object specified by type -*/ -int -objc_sizeof_type (const char *type) +/* Skip a variable name, enclosed in quotes ("). */ +static inline +const char * +objc_skip_variable_name (const char *type) { - /* Skip the variable name if any */ + /* Skip the variable name if any. */ if (*type == '"') { /* FIXME: How do we know we won't read beyond the end of the string. Here and in the rest of the file! */ - for (type++; *type++ != '"';) - /* do nothing */; + /* Skip '"'. */ + type++; + /* Skip to the next '"'. */ + while (*type != '"') + type++; + /* Skip '"'. */ + type++; } + return type; +} + +int +objc_sizeof_type (const char *type) +{ + type = objc_skip_variable_name (type); + switch (*type) { case _C_BOOL: return sizeof (_Bool); @@ -258,7 +269,8 @@ static int __attribute__ ((__unused__)) not_target case _C_BFLD: { - /* The new encoding of bitfields is: b 'position' 'type' 'size' */ + /* The GNU encoding of bitfields is: b 'position' 'type' + 'size'. */ int position, size; int startByte, endByte; @@ -363,20 +375,11 @@ static int __attribute__ ((__unused__)) not_target } } - -/* - Return the alignment of an object specified by type -*/ - int objc_alignof_type (const char *type) { - /* Skip the variable name if any */ - if (*type == '"') - { - for (type++; *type++ != '"';) - /* do nothing */; - } + type = objc_skip_variable_name (type); + switch (*type) { case _C_BOOL: return __alignof__ (_Bool); @@ -562,56 +565,31 @@ objc_alignof_type (const char *type) } } -/* - The aligned size if the size rounded up to the nearest alignment. -*/ - int objc_aligned_size (const char *type) { int size, align; - /* Skip the variable name */ - if (*type == '"') - { - for (type++; *type++ != '"';) - /* do nothing */; - } - + type = objc_skip_variable_name (type); size = objc_sizeof_type (type); align = objc_alignof_type (type); return ROUND (size, align); } -/* - The size rounded up to the nearest integral of the wordsize, taken - to be the size of a void *. -*/ - int objc_promoted_size (const char *type) { int size, wordsize; - /* Skip the variable name */ - if (*type == '"') - { - for (type++; *type++ != '"';) - /* do nothing */; - } - + type = objc_skip_variable_name (type); size = objc_sizeof_type (type); wordsize = sizeof (void *); return ROUND (size, wordsize); } -/* - Skip type qualifiers. These may eventually precede typespecs - occurring in method prototype encodings. -*/ - +inline const char * objc_skip_type_qualifiers (const char *type) { @@ -629,22 +607,11 @@ objc_skip_type_qualifiers (const char *type) return type; } - -/* - Skip one typespec element. If the typespec is prepended by type - qualifiers, these are skipped as well. -*/ - +inline const char * objc_skip_typespec (const char *type) { - /* Skip the variable name if any */ - if (*type == '"') - { - for (type++; *type++ != '"';) - /* do nothing */; - } - + type = objc_skip_variable_name (type); type = objc_skip_type_qualifiers (type); switch (*type) { @@ -728,7 +695,8 @@ objc_skip_typespec (const char *type) } case _C_BFLD: - /* The new encoding of bitfields is: b 'position' 'type' 'size' */ + /* The GNU encoding of bitfields is: b 'position' 'type' + 'size'. */ while (isdigit ((unsigned char)*++type)) ; /* skip position */ while (isdigit ((unsigned char)*++type)) @@ -770,25 +738,29 @@ objc_skip_typespec (const char *type) } } -/* - Skip an offset as part of a method encoding. This is prepended by a - '+' if the argument is passed in registers. - - FIXME: The compiler never generates '+'. -*/ +inline const char * objc_skip_offset (const char *type) { + /* The offset is prepended by a '+' if the argument is passed in + registers. PS: The compiler stopped generating this '+' in + version 3.4. */ if (*type == '+') type++; - while (isdigit ((unsigned char) *++type)) - ; + + /* Some people claim that on some platforms, where the stack grows + backwards, the compiler generates negative offsets (??). Skip a + '-' for such a negative offset. */ + if (*type == '-') + type++; + + /* Skip the digits that represent the offset. */ + while (isdigit ((unsigned char) *type)) + type++; + return type; } -/* - Skip an argument specification of a method encoding. -*/ const char * objc_skip_argspec (const char *type) { @@ -832,12 +804,9 @@ method_get_number_of_arguments (struct objc_method return method_getNumberOfArguments (mth); } -/* - Return the size of the argument block needed on the stack to invoke - the method MTH. This may be zero, if all arguments are passed in - registers. -*/ - +/* Return the size of the argument block needed on the stack to invoke + the method MTH. This may be zero, if all arguments are passed in + registers. */ int method_get_sizeof_arguments (struct objc_method *mth) { @@ -884,12 +853,10 @@ method_get_next_argument (arglist_t argframe, cons return argframe->arg_ptr + atoi (t); } -/* - Return a pointer to the value of the first argument of the method - described in M with the given argumentframe ARGFRAME. The type - is returned in TYPE. type must be passed to successive calls of - method_get_next_argument. -*/ +/* Return a pointer to the value of the first argument of the method + described in M with the given argumentframe ARGFRAME. The type + is returned in TYPE. type must be passed to successive calls of + method_get_next_argument. */ char * method_get_first_argument (struct objc_method *m, arglist_t argframe, @@ -899,12 +866,9 @@ method_get_first_argument (struct objc_method *m, return method_get_next_argument (argframe, type); } -/* - Return a pointer to the ARGth argument of the method +/* Return a pointer to the ARGth argument of the method M from the frame ARGFRAME. The type of the argument - is returned in the value-result argument TYPE -*/ - + is returned in the value-result argument TYPE. */ char * method_get_nth_argument (struct objc_method *m, arglist_t argframe, int arg, @@ -936,13 +900,13 @@ objc_get_type_qualifiers (const char *type) while (flag) switch (*type++) { - case _C_CONST: res |= _F_CONST; break; - case _C_IN: res |= _F_IN; break; - case _C_INOUT: res |= _F_INOUT; break; - case _C_OUT: res |= _F_OUT; break; - case _C_BYCOPY: res |= _F_BYCOPY; break; - case _C_BYREF: res |= _F_BYREF; break; - case _C_ONEWAY: res |= _F_ONEWAY; break; + case _C_CONST: res |= _F_CONST; break; + case _C_IN: res |= _F_IN; break; + case _C_INOUT: res |= _F_INOUT; break; + case _C_OUT: res |= _F_OUT; break; + case _C_BYCOPY: res |= _F_BYCOPY; break; + case _C_BYREF: res |= _F_BYREF; break; + case _C_ONEWAY: res |= _F_ONEWAY; break; case _C_GCINVISIBLE: res |= _F_GCINVISIBLE; break; default: flag = NO; } @@ -950,7 +914,6 @@ objc_get_type_qualifiers (const char *type) return res; } - /* The following three functions can be used to determine how a structure is laid out by the compiler. For example: @@ -972,7 +935,7 @@ objc_get_type_qualifiers (const char *type) functions to compute the size and alignment of structures. The previous method of computing the size and alignment of a structure was not working on some architectures, particulary on AIX, and in - the presence of bitfields inside the structure. */ + the presence of bitfields inside the structure. */ void objc_layout_structure (const char *type, struct objc_struct_layout *layout) @@ -1006,7 +969,6 @@ objc_layout_structure (const char *type, layout->record_align = MAX (layout->record_align, STRUCTURE_SIZE_BOUNDARY); } - BOOL objc_layout_structure_next_member (struct objc_struct_layout *layout) { @@ -1048,12 +1010,7 @@ objc_layout_structure_next_member (struct objc_str return NO; /* Skip the variable name if any */ - if (*layout->type == '"') - { - for (layout->type++; *layout->type++ != '"';) - /* do nothing */; - } - + layout->type = objc_skip_variable_name (layout->type); type = objc_skip_type_qualifiers (layout->type); if (*type != _C_BFLD) @@ -1139,7 +1096,6 @@ objc_layout_structure_next_member (struct objc_str return YES; } - void objc_layout_finish_structure (struct objc_struct_layout *layout, unsigned int *size, unsigned int *align) @@ -1177,7 +1133,6 @@ void objc_layout_finish_structure (struct objc_str *align = layout->record_align / BITS_PER_UNIT; } - void objc_layout_structure_get_info (struct objc_struct_layout *layout, unsigned int *offset, unsigned int *align, Index: ChangeLog =================================================================== --- ChangeLog (revision 165400) +++ ChangeLog (working copy) @@ -1,5 +1,23 @@ 2010-10-12 Nicola Pero + * encoding.c: Tidied up comments. + (objc_skip_variable_name): New static inline function. + (objc_sizeof_type): Use objc_skip_variable_name instead of copying + the same code over and over. + (objc_alignof_type): Same. + (objc_aligned_size): Same. + (objc_promoted_size): Same. + (objc_skip_typespec): Same. + (objc_layout_structure_next_member): Same. + (objc_skip_offset): Skip a '-' before the digits (if any). Fixed + historical bug where objc_skip_offset would skip one byte even if + there is no offset: check that the first offset digit is actually + a digit before skipping it. + (objc_skip_type_qualifiers): Mark as inline. + (objc_skip_typespec): Mark as inline. + +2010-10-12 Nicola Pero + * Makefile.in (C_SOURCE_FILES): Added methods.c. * encoding.c (method_getNumberOfArguments): New. (method_get_number_of_arguments): Call