Commit Graph

104 Commits

Author SHA1 Message Date
Michael Ilseman
5685ad9039 [ClangImporter] Begin refactoring of ImportName
Refactors out some definitions and types from the
ClangImporter::Implementation into a new component ImportName. Future
work will include more separation and finally some redesigning of name
determination components.
2016-09-09 11:05:59 -07:00
Ingmar Stein
98240ab871 [ClangImporter] import compound macros independent of order
This patch fixes an importer problem which occurred for macros defined
in terms of two other macros which might not have been imported before.
For example, the macro CPU_TYPE_X86_64 (defined as CPU_TYPE_X86 |
CPU_ARCH_ABI64) in Foundation wasn't imported although the importing
logic was implemented.

importMacro is now called for each of the constituents before checking
the constant value.
2016-09-03 16:43:11 +02:00
Ingmar Stein
28c141ff63 [ClangImporter] restrict import of macros with typedef'ed casts (#3676)
Import only casts with builtin canonical types to make sure they can be
typechecked.
2016-07-22 17:21:12 -07:00
IngmarStein
48079e7f25 [ClangImporter] fix crash when importing macros with bitwise operators
Fix an assertion which is triggered when the operands of a bitwise operator have different signedness.
This is done by promoting the operands to the largest bit width (taking sign/zero extension into account) and ignoring the signedness for the operation itself.
2016-07-21 13:44:22 +02:00
IngmarStein
e5cd80e21f [ClangImporter] import macros with type casts for some builtin types
This builds on #2538 by adding support for builtin types in addition to typedefs.
2016-07-05 15:33:40 +02:00
practicalswift
dd93d551df [gardening] Fix recently introduced typos 2016-07-01 19:28:34 +02:00
IngmarStein
31ab594b16 [ClangImporter] check bit width for bitwise operators 2016-06-29 23:01:30 +02:00
IngmarStein
f7a48a8733 [ClangImporter] Parse the type cast before pattern matching when importing macros
Setup the cast type early so that applies to all cases (as suggested by @DougGregor).
2016-06-29 23:01:30 +02:00
IngmarStein
b627123fc8 [ClangImporter] import macros of the form FLAG1 || FLAG2 and FLAG1 && FLAG2
Add another pattern to import
2016-06-29 23:01:30 +02:00
Ingmar Stein
11f1d96d23 Import macros of the form "FLAG1 | FLAG2" and "FLAG1 & FLAG2"
This commit adds a map to ClangImporter::Implementation to remember macros that were imported as constants in order to reuse the calculated values.
2016-06-29 23:01:30 +02:00
Ingmar Stein
4f800f8a21 [ClangImporter] Import preprocessor constants with a cast
Addresses SR-1509 by adding a heuristic to import numeric literals with a
type cast. Two new cases have been added for macros with 4 or 5 tokens
to cover cases with or without sign tokens.
2016-06-29 23:01:30 +02:00
Andrew Trick
ff02652108 Move enums into AttrKind.h.
This reorganization allows adding attributes that refer to types.
I need this for a @_specialize attribute with a type list.

PrintOptions.h and other headers depend on these enums. But Attr.h
defines a lot of classes that almost never need to be included.
2016-02-26 21:10:22 -08:00
Doug Gregor
8e000fb738 [Clang importer] Factor mapping of macro names into a single location. NFC 2016-02-03 16:11:59 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Doug Gregor
4c6d972691 Clang importer: collapse redefined macros.
In C, macros can be redefined so long as the redefinitions are
tokenwise equivalent. Provide the Clang importer with the same ability by
determining when tokenwise equivalent macros would be imported as
different Swift declarations, and collapse them into a single
declaration.
2015-12-21 14:43:46 -08:00
Jordan Rose
0b5428fcd3 Import DarwinBoolean as Bool in fully-bridgeable contexts.
These are contexts where we have enough information to bridge /back/
properly; that is, where we can distinguish CBool, ObjCBool, and
DarwinBoolean. In cases where we can't, we keep the three separate;
only CBool is really the same type as Bool.

This also affects current import behavior for ObjCBool, which was previously
incorrectly conflated with CBool in certain cases.

More rdar://problem/19013551

Swift SVN r30051
2015-07-10 01:11:30 +00:00
Dmitri Hrybenko
89a87c3c65 Revert "[test] Disable/remove tests that rely on iterating over all Clang macros."
...and add one extra check for invalid macro info.

This reinstates the tests that were disabled in my previous commit, now that the
Clang issue has been fixed.

Finishes rdar://problem/21480635.

Patch by Jordan Rose.

Swift SVN r29705
2015-06-25 22:01:44 +00:00
Dmitri Hrybenko
bc371ec1a2 [ClangImporter] Update for changes to how Clang manages macros in modules.
- Macros that aren't visible won't have macro info.
- Making a module visible to Sema doesn't make it visible to the Preprocessor.

Part of rdar://problem/21480635

Patch by Jordan Rose.

Swift SVN r29703
2015-06-25 22:01:42 +00:00
Chris Willmore
6d428b8d52 ClangImporter: Import macros of the form '#define FOO CFSTR("bar")'.
rdar://problem/18668528

Swift SVN r23544
2014-11-22 02:33:27 +00:00
Argyrios Kyrtzidis
a72c0e50c2 [ClangImporter] Expose a couple of functions in ClangImporter.
- getClangSema()
- shouldIgnoreMacro() which returns true if it is expected that a clang macro is ignored.

Swift SVN r23468
2014-11-20 05:08:36 +00:00
Anna Zaks
8cb6d45efb Only remap NSUInteger to Int in system frameworks
Makes NSUInteger come in as Uint from user declarations (and as Int from system modules).
Addresses radar://17473606

Swift SVN r19536
2014-07-03 21:46:47 +00:00
Joe Groff
10fae3e228 Remove -enable-string-pointer-conversion staging flag.
Swift SVN r19524
2014-07-03 18:43:20 +00:00
Joe Groff
c34b4f6a9e Enable string-to-pointer conversions and remove CString.
There is some follow-up work remaining:

- test/stdlib/UnicodeTrie test kills the type checker without manual type annotations. <rdar://problem/17539704>
- test/Sema/availability test raises a type error on 'a: String == nil', which we want, but probably not as a side effect of string-to-pointer conversions. I'll fix this next.

Swift SVN r19477
2014-07-02 19:15:10 +00:00
Joe Groff
e3b8a397a0 Import C string literal macros as ConstUnsafePointer<CChar> when string pointer conversions are enabled.
Swift SVN r19391
2014-07-01 04:48:52 +00:00
Ben Langmuir
133c469e05 Update for clang r211763
pointer, count -> ArrayRef

Swift SVN r19237
2014-06-26 16:28:41 +00:00
Jordan Rose
54c0baa9aa [ClangImporter] Don't recurse infinitely on "#define X X".
<rdar://problem/17182523>

Swift SVN r18772
2014-06-10 01:18:29 +00:00
Chris Lattner
7bda183b8b rename SuppressedMacros.def -> MacroTable.def
Swift SVN r18749
2014-06-09 17:32:55 +00:00
Chris Lattner
4dbff38780 Change NULL/Nil/nil and various other macros to be imported as an unavailable decl,
instead of importing them as _Nil (which will be going away when nil becomes an expr).

You now get an error saying:
error: 'NULL' is unavailable: use 'nil' instead of this imported macro

This is pretty cool all around, except for the GCD macros that need to be fixed, I'll
handle that as a follow-up.


Swift SVN r18747
2014-06-09 17:08:11 +00:00
Jordan Rose
0c46eb821e [ClangImporter] Handle decls declared in imported headers.
This improves the -import-objc-header option to read decls from the header
as well. Any declaration that is not from a module will be considered to be
part of the "header module". Conversely, forward-declarations appearing in
the header will be resolved by looking through all modules responsible for
importing a header.

More of <rdar://problem/16702101>

Swift SVN r17492
2014-05-05 22:52:17 +00:00
Jordan Rose
829d3e6de9 [ClangImporter] Handle macros that use bitshifts, like "(1 << 0)".
<rdar://problem/16202229>

Swift SVN r17462
2014-05-05 17:37:03 +00:00
Jordan Rose
ac15f949d2 [ClangImporter] Import macros that use ~.
This and the previous commit cover <rdar://problem/16521124>.

Swift SVN r17461
2014-05-05 17:37:02 +00:00
Jordan Rose
9e61c4bb62 [ClangImporter] Import NULL, nil, Nil, and ((void*)0) as Swift.nil.
Also, look through one layer of parentheses in general for macros, rather
than special-casing it for each token count.

<rdar://problem/16198517>

Swift SVN r17460
2014-05-05 17:37:00 +00:00
John McCall
23b224a655 Change the type importer to import types abstractly first,
and only later adjust the type for the manner in which
it is actually being used.

This gives us a foundation on which to build a consistent
and defensible model for importing typedefs.

Also fix a subtle problem with typedefs imported from
multiple clang modules.

Swift SVN r17079
2014-04-30 06:46:00 +00:00
Argyrios Kyrtzidis
b3f470ad16 [ClangImporter] Make getting the ClangNode from a swift Decl more efficient by
allocating extra memory and storing it directly before the swift AST object.

Reduces code-completion time for Cocoa by -25%.

Swift SVN r16615
2014-04-21 07:18:50 +00:00
Argyrios Kyrtzidis
3a60b89d95 [ClangImporter] Don't import include guard macros.
This depends on clang r205917.
rdar://16555519

Swift SVN r16126
2014-04-09 19:53:31 +00:00
Ted Kremenek
656fd1a2ee Add blacklist for imported macros, which can be extended over time.
Implements:

<rdar://problem/16454306> NS_BLOCKS_AVAILABLE probably should not be imported since by default it's true

Swift SVN r16067
2014-04-08 19:26:17 +00:00
Dmitri Hrybenko
2c96263f02 Clang importer: when importing a macro A that resolves to another macro B, put
the imported macro into the module that owns A, not B

rdar://16449405


Swift SVN r15675
2014-03-31 12:11:19 +00:00
Dmitri Hrybenko
a422886e6f Clang importer: add a workaround so that we don't import literals with ud-suffix
Workaround for rdar://16445608


Swift SVN r15559
2014-03-27 17:59:19 +00:00
Dmitri Hrybenko
962c924ab1 Clang importer: put macros into correct module and return them in visible decl
lookup


Swift SVN r15500
2014-03-26 10:27:44 +00:00
Jordan Rose
3d313fb3f0 [ClangImporter] Import macros containing a single NSString literal as String.
Bonus goodness related to the previous commit.

Swift SVN r14665
2014-03-05 00:29:44 +00:00
Jordan Rose
a84f939545 [ClangImporter] Import string macros as CStrings.
Also, pass "-std=gnu11" so that we accept UTF-8 strings in these macros.

<rdar://problem/16198953>

Swift SVN r14664
2014-03-05 00:29:43 +00:00
Argyrios Kyrtzidis
8ae03064fb [ClangImporter] Pass the imported declaration to ASTContext after we have finished importing it.
This is to reduce the 'recursiveness' of the clang importer and its stack usage.

Addresses rdar://15929821.

Swift SVN r13688
2014-02-08 23:57:16 +00:00
Jordan Rose
be12d86ddd Turn ClangModule into ClangModuleUnit.
Part of the FileUnit restructuring. A Clang module (whether from a framework
or a simple collection of headers) is now imported as a TranslationUnit
containing a single ClangModuleUnit.

One wrinkle in all this is that Swift very much wants to do searches on a
per-module basis, but Clang can only do lookups across the entire
TranslationUnit. Unless and until we get a better way to deal with this,
we're stuck with an inefficiency here. Previously, we used to hack around
this by ignoring the "per-module" bit and only performing one lookup into
all Clang modules, but that's not actually correct with respect to visibility.

Now, we're just taking the filtering hit for looking up a particular name,
and caching the results when we look up everything (for code completion).
This isn't ideal, but it doesn't seem to be costing too much in performance,
at least not right now, and it means we can get visibility correct.

In the future, it might make sense to include a ClangModuleUnit alongside a
SerializedASTFile for adapter modules, rather than having two separate
modules with the same name. I haven't really thought through this yet, though.

Swift SVN r10834
2013-12-05 01:51:11 +00:00
Joe Groff
fdd858dd21 ClangImporter: Import NS_OPTIONS constants as static properties.
Apply the same prefix-chopping logic as for NS_ENUM to produce static property names to put inside the Swift type we create. For now, continue importing NS_OPTIONS as structs with a single integer field; in the short term it's easy to put a C-like interface over them this way.

Swift SVN r10434
2013-11-13 23:19:32 +00:00
Jordan Rose
fc3a5f5726 [ClangImporter] Believe type info coming from integer literals in macros.
That is, 1234 is a CInt, 1234U is a CUnsignedInt, and 1234LL is a CLongLong.
Oh, and 3.14F is a CFloat.

One caveat here is that it is not actually possible in C to write a literal
INT_MIN:

  -0x80000000 is two tokens and the literal part is unsigned
  (-INT_MAX - 1) is several tokens

I've simply dropped this test for now, but it might be confusing in the rare
case where an INT_MIN-like value is used as a sentinel.

<rdar://problem/13839025>

Swift SVN r7639
2013-08-27 22:41:05 +00:00
Jordan Rose
d9b7c8ad5a Move ClangModule into the ClangImporter library.
This makes it very clear who is depending on special behavior at the
module level. Doing isa<ClangModule> now requires a header import; anything
more requires actually linking against the ClangImporter library.

If the current source file really can't import ClangModule.h, it can
still fall back to checking against the DeclContext's getContextKind()
(and indeed AST currently does in a few places).

Swift SVN r6695
2013-07-29 18:56:35 +00:00
Doug Gregor
9a70c0ebf4 [Clang Importer] Refactor the handling of type import contexts.
The importer has always imported types differently in different
places, e.g., function parameter types have special rules for C++
references. Formalize this notion a bit, and make it work properly
when dealing with typedefs where the underlying type itself might be
imported differently in different contexts. 

As part of this, limit the import of C's 'void' type to the result of
a function type.


Swift SVN r5055
2013-05-06 18:10:46 +00:00
Doug Gregor
f3bb94c166 Clang importer: look through macros that simply expand to another macro.
This allows us to import FOO in the following example:

  #define FOO BAR
  #define BAR 5

Fixes <rdar://problem/13768957>.


Swift SVN r5001
2013-04-30 20:25:56 +00:00
Doug Gregor
c057b21193 Ban the use of construction syntax T(x) for coercions and unchecked downcasts.
Use "x as T" for coercions and "x as! T" for unchecked downcasts.


Swift SVN r4683
2013-04-11 21:17:47 +00:00
Doug Gregor
6adc44dac1 Fix for Clang r175585
Swift SVN r4106
2013-02-20 17:56:58 +00:00