Commit Graph

84 Commits

Author SHA1 Message Date
Joe Groff
cd5a624bbc IRGen: Emit more accurate property metadata.
Instead of hacking together inaccurate metadata only for object-typed properties, make an effort to produce accurate metadata for all types of properties, and accurately capture the "copy", "dynamic", and "weak" semantics of some properties. This is necessary for Core Data to accurately synthesize property accessors for non-object properties; currently it will generate bogus object accessors over properties with non-object type. <rdar://problem/17373368>

This isn't fully accurate, since Clang hides property type encoding behind a 'getObjCEncodingForPropertyDecl' that only accepts an ObjCPropertyDecl. With some refactoring, it should be possible to expose this.

Swift SVN r19567
2014-07-04 15:58:18 +00:00
John McCall
bafeb84a56 Generate unique type metadata for foreign classes.
Swift SVN r17430
2014-05-05 06:45:42 +00:00
Jordan Rose
bb25f9fd2c Teach abitypes.swift to use the clang-importer-sdk instead of the real SDK.
This will allow us to write consistent tests across platforms, and also
just remove reliance on the real SDK.

See <rdar://problem/15897024>.

Swift SVN r14174
2014-02-20 22:15:19 +00:00
Mark Lacey
e54a454cca Handle the remaining types in Clang type generation.
With this we generate Clang types for everything we allow to be in the
signature of a C/@objc function.

Swift SVN r13734
2014-02-10 05:07:22 +00:00
Fariborz Jahanian
7578316937 Test for type encoding of imported
ObjectiveC enum type which is not
modernized.


Swift SVN r13687
2014-02-08 21:28:21 +00:00
Mark Lacey
af31d67fcb Add a test for plain enums.
Also remove some code that I added recently and thought I had hit in
testing, but appears to be unreachable.

Swift SVN r13594
2014-02-06 19:43:26 +00:00
Mark Lacey
7c259ea9ef Add ABI tests for enum and fix issue with getting TypeDecl types.
Swift SVN r13424
2014-02-04 09:30:24 +00:00
Mark Lacey
1a97f18887 Switch ABI tests to using the real SDK.
Swift SVN r13423
2014-02-04 09:30:21 +00:00
Mark Lacey
d69b305200 Generate IR for inline functions from Clang modules.
Currently only inline functions referenced from Swift source files, or
from the REPL, will get IR generated for them. Inline functions
referenced by other inline functions will require additional effort to
generate properly.

With this change we use the clang::CodeGenerator-created llvm::Module
for all IR generation in Swift. This is perhaps undesirable, but
unavoidable given the interface the public Clang APIs expose, which do
not allow for building a ModuleBuilder that borrows an existing
llvm::Module.

Also unfortunate is the hack to generate a UsedAttr for each imported
inline function, but the public Clang APIs do not provide a way to only
emit deferred decls without emitting other things (e.g. module flags
that conflict with what the Swift IRGen emits). Note that we do not do
IRGen for every inline function in the module - only the ones that the
importer pulls in, which appears to be only those transitively
referenced from Swift code.

Swift SVN r13134
2014-01-30 02:33:37 +00:00
Mark Lacey
b1cc2545b4 Test calling an imported func that uses BOOL.
Swift SVN r12717
2014-01-22 07:09:11 +00:00
Doug Gregor
3caa3b78c5 Make CBool a typealias of Bool.
Swift SVN r12657
2014-01-21 21:28:55 +00:00
Argyrios Kyrtzidis
3882ab6bd4 [ClangImporter] When checking for NS_ENUM/NS_OPTIONS enums, use clang::Preprocessor::getImmediateMacroName()
and check for CF_ENUM/CF_OPTIONS, which NS_ENUM/NS_OPTIONS expand to.

This:
- Simplifies code
- Handles CF_ENUM/CF_OPTIONS enums
- Handles correctly an NS_ENUM/NS_OPTIONS enum that was itself expanded from another macro.

Swift SVN r11542
2013-12-21 17:40:28 +00:00
Mark Lacey
9b81800432 Choose correct IR types for @objc return values.
This change updates signature generation as well as IR generation for
calls and returns so that the correct ABI types are generated for the
results of @objc functions.

Swift SVN r11527
2013-12-20 23:31:01 +00:00
Mark Lacey
a7f6f9e006 Handle indirect returns in @objc methods properly.
Reapply r11184 with fixes for makefile builds.

Use CodeGenABITypes to determine which return values should be indirect
in @objc methods.

Swift SVN r11226
2013-12-13 00:39:24 +00:00
Mark Lacey
dffef5d02b Revert "Handle indirect returns in @objc methods properly."
This reverts r11184, which broke some builds due to a missing library.

Swift SVN r11186
2013-12-12 09:11:39 +00:00
Mark Lacey
973ece4dc9 Handle indirect returns in @objc methods properly.
Use CodeGenABITypes to determine which return values should be indirect
in @objc methods.

Swift SVN r11184
2013-12-12 07:22:12 +00:00
Joe Groff
6370f91383 ClangImporter: Handle negative C enum constants.
We needed some patching up to convert negative enum constants into proper negative IntegerLiteralExprs in the imported Swift AST, to handle the obnoxious INT_MIN edge case, and to handle "negative" values of unsigned enums.

Swift SVN r10005
2013-11-06 21:28:24 +00:00
Joe Groff
1d31ce558b Add tests that we import octal and hex enum constants properly.
Swift SVN r9994
2013-11-06 18:24:40 +00:00
Joe Groff
c5305f3e60 IRGen: Lay out enums from Clang with C-compatible layout.
Borrow the scalar type of the raw type as the representation type of C enums, and use the raw values from C as the discriminator values of the cases.

Swift SVN r9988
2013-11-06 05:54:17 +00:00
Joe Groff
5ec3cad5f6 ClangImporter: Emit metadata for imported enums.
Whatever kind of Swift decl we cons up for a Clang enum, add it to the externals list so we can pick it up and emit Swift metadata for it in IRGen. Fixes <rdar://problem/15242452>.

Swift SVN r9801
2013-10-30 18:15:09 +00:00
Joe Groff
514d659ead IRGen: Emit categories for extensions that conform to ObjC protocols.
Swift SVN r5659
2013-06-18 22:37:55 +00:00
Joe Groff
34dc94679d IRGen: Get objc protocol erasure working.
Don't try to emit witness tables for protocols that don't need them when emitting a protocol erasure. (We'll need to eventually ensure that ObjC method metadata gets generated for the conforming methods, but we don't yet, so this will only work for types that already have ObjC-dispatchable methods.)

Swift SVN r5610
2013-06-16 05:06:28 +00:00
Joe Groff
b50eb85fc9 Flip the -nsstring-is-string switch and update tests.
Make nsstring-is-string the default, and invert the commandline flag to -no-nsstring-is-string. Update tests to use String where they used to use NSString, particularly with block arguments. (While we're here, update them to use the new closure syntax.)

Swift SVN r5374
2013-05-29 16:27:16 +00:00
Joe Groff
72e53052dc IRGen: Build method/property encodings based on bridged type.
This gives [objc] properties or property-ish methods of String type encodings as their NSString counterparts in the ObjC world.

Swift SVN r5365
2013-05-28 21:05:14 +00:00
Joe Groff
0132f279a7 IRGen: ObjC super dispatch for super.constructor.
Implement super.constructor for ObjC superclasses by dispatching the superclass init message with objc_msgSendSuper2. Fixes <rdar://problem/13107128>.

Swift SVN r4288
2013-03-05 21:39:42 +00:00
Joe Groff
a9f747ec1f IRGen: Emit categories for ObjC class extensions.
Emit ObjC stubs and categories for methods defined in extensions of ObjC-compatible classes. This makes extensions of ObjC classes available to ObjC in statically compiled code. For immediate-mode code we'll still need to dynamically register extension methods using the ObjC runtime.

Swift SVN r4149
2013-02-22 05:40:09 +00:00
Joe Groff
4792c60d2d IRGen: Implement super method calls.
For Objective-C super calls, build an objc_super struct value containing the receiver and class/metaclass object and pass it to objc_msgSendSuper2. For Swift super calls, emit a direct call to the super implementation.

Swift SVN r4023
2013-02-13 02:41:20 +00:00
Joe Groff
aa75885266 IRGen: Fix C funcs with big struct return and arg.
Should have tested both together. Oops.

Swift SVN r3998
2013-02-09 01:39:22 +00:00
Joe Groff
9c022d5d65 IRGen: Fudge passing large ObjC structs as byvals.
Push LLVM attribute generation from expandAbstractCC into getFunctionSignature and CallEmission so that they can generate sret and/or byval attributes per-argument according to the calling convention. Copy our bogus rule for emitting sret returns (more than three elements in the explosion) and reuse it to pass large struct values as byvals rather than as explosions. This should be good enough to get both 'NSRect' and
'NSRange', 'NSSize' etc. to pass correctly to ObjC methods. Next step is to set the AbstractCC correctly for imported func decls so that standalone C functions follow the same bogus rule.

Swift SVN r3993
2013-02-08 21:50:08 +00:00
Joe Groff
6cca08826a IRGen: Hack in calls to block converter funcs.
Add a mangling for 'block converter' functions and for [objc_block] function types. [objc_block] types also need their own HeapTypeInfo representation that uses ObjC retain/release. When we see a BridgeToBlockExpr, feed the function pointer and context from the Swift closure to the external conversion function and hope we get a block back.

Swift SVN r3899
2013-01-30 01:01:34 +00:00
John McCall
521f0742b4 Account for types that explode to sizes != 1 when computing the
consumed arguments of a method.

Swift SVN r3464
2012-12-13 00:24:42 +00:00
John McCall
4b246bce50 Implement the ObjC ownership conventions, using ARC-in-clang's
method annotations when possible.

Swift SVN r3427
2012-12-10 08:18:11 +00:00
John McCall
c6374093f6 Add support for messaging Objective-C classes.
Notably, there is still no support for +1 return values,
so we'll leak when doing alloc/init and so on;  but this gets
the fundamentals in place.  A lot of the extra stuff in here
is dealing with mapping between metatypes and class objects.

Swift SVN r3425
2012-12-10 08:18:03 +00:00
John McCall
59d4677b35 Implement metatype references to ObjC classes.
The interesting thing here is that we need runtime support in
order to generate references to metatypes for classes, mostly
because normal ObjC classes don't have all the information we want
in a metatype (which for now just means the VWT pointer).
We'll need to be able to reverse this mapping when finding a
class pointer to hand off to, say, an Objective-C class method,
of course.

Swift SVN r3424
2012-12-10 08:17:57 +00:00