diff options
author | Richard Stallman <rms@gnu.org> | 1992-12-19 09:04:47 +0000 |
---|---|---|
committer | Richard Stallman <rms@gnu.org> | 1992-12-19 09:04:47 +0000 |
commit | b53241dce54ba589d0dacd9cbc30f73b27995705 (patch) | |
tree | 4653a46d736b2ce04e8392b4c5f97144aa453a52 /gcc/objc/objc-act.c | |
parent | 0e9934c8fcd9d05b2054a1d43745bd8350663ecc (diff) | |
download | gcc-b53241dce54ba589d0dacd9cbc30f73b27995705.zip gcc-b53241dce54ba589d0dacd9cbc30f73b27995705.tar.gz gcc-b53241dce54ba589d0dacd9cbc30f73b27995705.tar.bz2 |
(build_encode_expr): Terminate the encode string with a null.
(encode_aggregate): Distinguish pointer to record from a
record. Output fields for record. Fix unions.
From-SVN: r2896
Diffstat (limited to 'gcc/objc/objc-act.c')
-rw-r--r-- | gcc/objc/objc-act.c | 70 |
1 files changed, 47 insertions, 23 deletions
diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index 0bb1c10..edfc0b0 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -2951,6 +2951,7 @@ build_encode_expr (type) fatal ("Objective-C text in C source file"); encode_type (type, OBJC_ENCODE_INLINE_DEFS); + obstack_1grow (&util_obstack, 0); /* null terminate string */ string = obstack_finish (&util_obstack); /* synthesize a string that represents the encoded struct/union */ @@ -3749,63 +3750,86 @@ encode_aggregate (type, format) { case RECORD_TYPE: { - if (*obstack_next_free (&util_obstack) == '^' - || format != OBJC_ENCODE_INLINE_DEFS) + int have_pointer = 0; + + if (obstack_object_size (&util_obstack) > 0 + && *(obstack_next_free (&util_obstack)-1) == '^') + have_pointer = 1; + + obstack_1grow (&util_obstack, '{'); + if (TYPE_NAME (type)) { - /* we have a reference - this is a NeXT extension-- - or we don't want the details. */ - if (TYPE_NAME (type) - && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)) + if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) { - obstack_1grow (&util_obstack, '{'); - obstack_grow (&util_obstack, + obstack_grow (&util_obstack, IDENTIFIER_POINTER (TYPE_NAME (type)), strlen (IDENTIFIER_POINTER (TYPE_NAME (type)))); - obstack_1grow (&util_obstack, '}'); } else /* we have an untagged structure or a typedef */ - obstack_grow (&util_obstack, "{?}", 3); + { + obstack_1grow (&util_obstack, '?'); + } + } + + if (have_pointer + || format == OBJC_ENCODE_DONT_INLINE_DEFS) + { + /* we have a pointer + or we don't want the details. */ + obstack_1grow (&util_obstack, '}'); } else { tree fields = TYPE_FIELDS (type); - obstack_1grow (&util_obstack, '{'); + obstack_1grow (&util_obstack, '='); for ( ; fields; fields = TREE_CHAIN (fields)) encode_field_decl (fields, format); obstack_1grow (&util_obstack, '}'); } break; } + case UNION_TYPE: { - if (*obstack_next_free (&util_obstack) == '^' - || format != OBJC_ENCODE_INLINE_DEFS) + int have_pointer = 0; + + if (obstack_object_size (&util_obstack) > 0 + && *(obstack_next_free (&util_obstack)-1) == '^') + have_pointer = 1; + + obstack_1grow (&util_obstack, '('); + if (have_pointer && TYPE_NAME (type)) { - /* we have a reference - this is a NeXT extension-- - or we don't want the details. */ - if (TYPE_NAME (type) - && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)) + if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) { - obstack_1grow (&util_obstack, '<'); - obstack_grow (&util_obstack, + obstack_grow (&util_obstack, IDENTIFIER_POINTER (TYPE_NAME (type)), strlen (IDENTIFIER_POINTER (TYPE_NAME (type)))); - obstack_1grow (&util_obstack, '>'); } else /* we have an untagged structure or a typedef */ - obstack_grow (&util_obstack, "<?>", 3); + { + obstack_1grow (&util_obstack, '?'); + } + } + + if (have_pointer + || format == OBJC_ENCODE_DONT_INLINE_DEFS) + { + /* we have a pointer + or we don't want the details. */ + obstack_1grow (&util_obstack, ')'); } else { tree fields = TYPE_FIELDS (type); - obstack_1grow (&util_obstack, '<'); for ( ; fields; fields = TREE_CHAIN (fields)) encode_field_decl (fields, format); - obstack_1grow (&util_obstack, '>'); + obstack_1grow (&util_obstack, ')'); } break; } + case ENUMERAL_TYPE: obstack_1grow (&util_obstack, 'i'); break; |