Commit Graph

6 Commits

Author SHA1 Message Date
Doug Gregor
2302f59288 Merge pull request #6531 from Fruneau/indirect-fields
Clang Importer: import all indirect fields.
2017-01-09 15:01:02 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Florent Bruneau
68bc423be3 Clang Importer: import all indirect fields.
Until now, only indirect fields that didn't belong to a C union (somewhere
between the field declaration and the type in which it is indirectly
exposed) were imported in swift. This patch tries to provide an approach
that allows all those fields to be exposed in swift. However, the downside
is that we introduce new intermediate fields and types, some of the fields
may already have been manually defined in type extension (as seen with the
GLKit overlay).

The main idea here is that we can simply expose the anonymous
struct/unions from which the indirect types are taken and then use swift
computed properties to access the content of those anonymous
struct/unions. As a consequence, each time we encounter an anonymous
struct or union, we actually expose it at __Anonymous_field<id> (where id
is the index of the field in the structure). At this point, we use the
existing mechanism to expose the type as
__Unnamed_<struct|union>_<fieldname>. Then, each indirect field is exposed
as a computed property.

The C object:

 typedef union foo_t {
     struct {
         int a;
         int b;
     };
     int c;
 } foo_t;

Is imported as

 struct foo_t {
   struct __Unnamed_struct___Anonymous_field1 {
     var a : Int32
     var b : Int32
   }
   var __Anonymous_field1 : foo_t.__Unnamed_struct___Anonymous_field1
   var a : Int32 {
     get {
       return __Anonymous_field1.a
     }
     set(newValue) {
       __Anonymous_field1.a = newValue
     }
   }
   var b : Int32 {
     get {
       return __Anonymous_field1.b
     }
     set(newValue) {
       __Anonymous_field1.b = newValue
     }
   }
   var c : Int32
 }

This has the advantage to work for both struct and union, even in case we
have several nested anonymous struct/unions. This does not require to know
the size and/or the offset of the fields in the structures and thus can be
properly implemented using front-end data.

Signed-off-by: Florent Bruneau <florent.bruneau@intersec.com>
2017-01-05 22:52:25 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
practicalswift
cc852042c9 [gardening] Fix accidental trailing whitespace. 2016-10-29 10:22:58 +02:00
Jordan Rose
896fc4f648 [SDK] Rename several small overlay source files. (#4520)
...to remove the temptation to put everything in one file with the same
name as the module. This doesn't do anything for overlays that /already/
have everything in one file with the same name as the module, except for
a few easy cases; we can unpack the rest later.
2016-09-28 11:39:07 -07:00