Commit Graph

1877 Commits

Author SHA1 Message Date
Jordan Rose
9b9e669bf7 Add support for :print_module on Clang modules.
This isn't very efficient: it scans every decl in the Clang TU (forcing
deserialization) and filters based on the decl's enclosing module.
Moreover, since getClangModuleForDecl() currently only handles top-level
modules, all submodules get implicitly added to the top-level module...
and will /not/ match an explicit submodule request.

(This is probably close to the behavior we actually want: include decls that
are from modules that are (a) submodules and (b) re-exported by the top-level
module. We do want that extra check, though, and we would want to find things
specifically by submodule.)

Swift SVN r7602
2013-08-26 23:07:54 +00:00
Jordan Rose
7d6d336983 Add autolinking infrastructure to Module and ClangImporter.
...and use it to load frameworks and libraries in immediate modes (-i and
the REPL), replacing a walk of visible modules that checked if any imported
modules were Clang modules.

Swift SVN r7488
2013-08-22 23:20:23 +00:00
Jordan Rose
f1bc7801f4 Rework getReexportedModules to optionally find all imported modules.
...instead of just those that are re-exported. This will be used for
autolinking (and probably few other places).

As part of this, we get two name changes:
  (1) Module::getReexportedModules -> getImportedModules
  (2) TranslationUnit::getImportedModules -> getImports

The latter doesn't just get modules-plus-access-paths; it also includes
whether or not the import is re-exported. Mainly, though, it just didn't
seem like a good idea to overload this name when the two functions aren't
really related.

No tests yet, will come with autolinking.

Swift SVN r7487
2013-08-22 23:20:18 +00:00
Argyrios Kyrtzidis
0306a7f416 [ClangImporter] Stop ClangImporter from trying to figure out where the swift runtime library is,
this should be the responsibility of the caller to provide it.

Swift SVN r7480
2013-08-22 21:49:30 +00:00
Argyrios Kyrtzidis
ae65ab1ee0 Introduce NullClangImporter library which is for clients that don't want to link Clang.
ClangImporter::create had a 'weak' attribute but it did not actually have the desired effect,
static libraries still want to link to ClangImporter::create if it is used.
Avoiding linking ClangImporter kinda "worked" because CompilerInvocation::setSDKPath was inline,
so if you didn't call it then you didn't need to link to Clang importer, but that is avoiding
ClangImporter statically, not dynamically.
You could see this by moving CompilerInvocation::setSDKPath out-of-line and then sil-opt would fail to link.

In order to have clients avoiding linking Clang, introduce NullClangImporter which just returns null for the
ClangImporter constructor function.

Swift SVN r7465
2013-08-22 18:29:58 +00:00
Jordan Rose
4cefdf263c [ClangImporter] Don't unique selector names when doing id-style lookup.
Dmitri pointed out that we're just bloating the AST context's identifier
table and not actually saving any string comparison. StringRef's == is
pretty efficient anyway.

Swift SVN r7339
2013-08-19 22:45:14 +00:00
Jordan Rose
2c7858bfb2 Add an entry point for id-style lookup of a known name.
This will be used to resolve properties and method calls on objects with
dynamic-lookup ("id") type. For now, this is tested in swift-ide-test
by using the -dynamic-lookup-completion option and providing a
-code-completion-token value.

Caveats/TODOs:
- As before, since we're using the global method pool, this isn't scoped by
  module. We could do a per-module filter, but I don't know if that will
  actually buy us much.
- Again, Clang's method pool does not include methods from protocols.
- Lookup by selector name cannot find properties with a customized getter
  name. <rdar://problem/14776565>
- The Clang-side method pool is keyed by selector, but Swift wants to look
  things up by method name, which maps to the first selector piece, so we
  end up having to do a scan of all the selectors in the pool.

Swift SVN r7330
2013-08-19 21:33:33 +00:00
Jordan Rose
49d8b2c584 Add ClangImporter results to dynamic class member lookup.
Caveats / TODOs:
- Since we're using the global method pool, this isn't scoped by module.
  We could do a per-module filter, but I don't know if that will actually
  buy us much.
- Clang's method pool does not include methods from protocols.
- This requires importing every single method found into Swift's AST just
  to print them in the completion results.

Swift SVN r7329
2013-08-19 18:54:31 +00:00
Jordan Rose
f04d6459d8 Uncomment the code that actually made r7291 work.
/Now/ <rdar://problem/14759044> should be fixed.

Swift SVN r7302
2013-08-16 23:17:03 +00:00
Jordan Rose
2ebd4756b6 [ClangImporter] Force load adapter modules whenever a Clang module is named.
Loading Cocoa (Clang) triggers the loading of several other modules,
including Foundation (Clang). We want to make sure we bring in the adapter
module Foundation (Swift), so loading Cocoa currently triggers a walk of
all imported modules to check for an adapter. The problem is that
Foundation (Swift) contains some eagerly-deserialized decls, which refer
to decls in Foundation (Clang). These decls were not importing correctly
because we hadn't finished loading all the adapters -- specifically, we
hadn't yet loaded ObjectiveC (Swift). This meant SEL was loaded as
swift.COpaquePointer instead of ObjectiveC.ObjCSel.

Now, when Foundation (Swift) asks to load Foundation (Clang), we'll walk
all imported modules under Foundation (Clang) to check for an adapter
before returning, even if Foundation (Clang) is already in our system.
This probably still isn't the best way to deal with this (particularly
since the modules in the subtree will get visited twice), but it ensures
that we've loaded all necessary adapter modules before trying to import
any decls.

TLDR: Importing Cocoa now correctly imports the Swift overlay for the
ObjectiveC module, meaning SELs are correctly imported.

<rdar://problem/14759044>

Swift SVN r7293
2013-08-16 21:56:00 +00:00
Jordan Rose
d3b31b8b72 Don't include re-exports in a TU's imported module list.
We can get to these transitively; we should only record what the TU
actually claims to reference.

It turns out that we were still relying on this to force the load of
adapter modules for Clang modules. For now, we just force that up front,
even though currently that also forces the creation of ClangModule
wrappers for all transitive includes.

No intended visible functionality change.

Swift SVN r7012
2013-08-07 22:56:32 +00:00
Dmitri Hrybenko
dfe28a76bb Clang importer: put the Objective-C class into the module that contains the
@interface definition, not just @class forward declaration.


Swift SVN r6961
2013-08-06 23:45:12 +00:00
Dmitri Hrybenko
e223048bb2 Clang importer: when a function is re-declared in multiple imported Clang
modules, put the imported decl into the ClangModule where the canonical
decl is.

This is not a complete fix, the function should be visible from all modules
that declare it.  See rdar://14665250


Swift SVN r6956
2013-08-06 22:05:07 +00:00
Dmitri Hrybenko
849ad1a14d libFrontend, swift-ide-test: add -F option to specify framework search paths
Swift SVN r6950
2013-08-06 21:12:05 +00:00
Dmitri Hrybenko
bb3d38b727 Clang importer: put the top-level declarations into the correct ClangModule
Before this change, DeclContext of all imported decls was set to the first
imported module.

No tests now, will be tested by future code completion commits.


Swift SVN r6949
2013-08-06 21:06:44 +00:00
Jordan Rose
f03245a206 Fix up a bunch of filtering-by-decl-access-path.
Mostly cleanup, a few filled-in FIXMEs to filter out decls that don't match
the access path name.

Swift SVN r6850
2013-08-02 21:00:28 +00:00
Sean Callanan
f9a446b410 Added the option to override Clang's resource
directory when constructing a ClangImporter.
This is for lldb, which keeps Clang's resource
directory inside its own framework bundle.


Swift SVN r6833
2013-08-02 02:25:42 +00:00
Dmitri Hrybenko
e1c4ae3174 Wrap llvm::SourceMgr in swift::SourceManager so that we can add new members
to the source manager.


Swift SVN r6815
2013-08-01 20:39:22 +00:00
Adrian Prantl
aecfb851cd Wire clang::TargetInfo into swift::IRGenDebugInfo so we have access to
the target size of types, which may be different from the LLVM storage size.

Swift SVN r6774
2013-07-31 18:08:38 +00:00
Adrian Prantl
5295671f3b typo
Swift SVN r6773
2013-07-31 18:08:36 +00:00
Jordan Rose
3e7eef56e7 Kill [stdlib] attribute.
Now that we have true serialized modules, the standard library can import
the Builtin module without any special direction (beyond -parse-stdlib),
and anyone can include those modules without special direction.

Swift SVN r6752
2013-07-30 21:27:42 +00:00
Adrian Prantl
2306563aa2 Debug info: emit the module name for types declare in a swiftmodule.
Swift SVN r6734
2013-07-30 01:17:02 +00:00
Jordan Rose
501b0e9394 Implement getReexportedModules for Clang modules.
This handles both Clang’s transitive inclusion and the use of
"adapter modules" to augment the Clang modules (e.g. Foundation.swift),
at the cost of a bit more memory (used to wrap all the Clang modules
in ClangModule objects). This is paving the way for making Sema
independent of ClangImporter.

Swift SVN r6698
2013-07-29 18:56:58 +00:00
Jordan Rose
0b75d86d77 Remove now-unused "LoadedClangModules" hack.
Swift SVN r6697
2013-07-29 18:56:52 +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
Dmitri Hrybenko
dcd26e8a1f Code completion: implement completion of imported Clang declarations by first
importing them

Because going through the import for every code completion request is slow,
Clang code completion results are cached in the CodeCompletionContext.  The
cache needs to be invalidated whenever a new Clang module is loaded.  In order
to implement this, ModuleLoadListener class was added.


Swift SVN r6505
2013-07-23 18:12:58 +00:00
Dmitri Hrybenko
02084efab7 Implement code completion for some function calls and member variable accesses
in expr-dot and expr-postfix that can be typechecked without typechecking the
beginning of the function body.


Swift SVN r6198
2013-07-12 02:00:41 +00:00
Chris Lattner
c03d4454a0 implement support for a new [stdlib] attribute that can be slapped on an import decl.
This causes the SourceLoader to recursively parse the imported module in standard 
library mode, giving it access to the Builtin module.

This is all a terrible hack and should be ripped out with great victory someday, but 
until we have binary modules that persist the build setting used to produce the 
module, this is the best we can do.



Swift SVN r5847
2013-06-27 21:31:15 +00:00
Dmitri Hrybenko
8c3995996f Add infrastructure to easily map C types to swift stdlib types when they are
binary compatible.

This enables us to import MacTypes.h types as stdlib swift types to avoid name
conflicts.  We also import stdint.h types as stdlib swift types.

We can not map 'long double'-based ctypes.Float80 to swift.Float80 because size
of long double is 128 according to SysV ABI, and I compare that against what
the type name says (I did not find a way to find the size of the type).

Darwin.Float80 is a struct, so I don’t think we can import it as swift.Float80.
So with import Darwin, Float80 is still ambiguous.

I had to rename test/ClangModules/ctypes.swift ->
test/ClangModules/ctypes_test.swift because other tests do 'import ctypes',
which picks up 'ctypes.swift'.


Swift SVN r5727
2013-06-20 22:08:35 +00:00
Dmitri Hrybenko
7bf6d30b62 Disambiguate imported functions and structs that have the same name.
For example, now we disambiguate 'stat()' function and 'struct stat' from
the Darwin module.


Swift SVN r5587
2013-06-14 21:12:46 +00:00
Doug Gregor
720cb9348d LLVM's PathV2.h has become Path.h. Update includes appropriately
Swift SVN r5574
2013-06-13 14:53:52 +00:00
Dmitri Hrybenko
aeda419ea1 Fix indentation
Swift SVN r5524
2013-06-07 22:40:44 +00:00
Doug Gregor
1641477826 Eliminate lookupExtensions() and the extension cache.
This infrastructure has been replaced by the extension list on nominal
declaration, which is simpler and more efficient.


Swift SVN r5225
2013-05-20 18:26:07 +00:00
Doug Gregor
8114ce16f8 Use the list of extensions of a nominal type for name lookup into that type.
This replaces the obscure, inefficient lookup into extensions with
something more straightforward: walk all of the known extensions
(available as a simple list), then eliminate any declarations that
have been shadowed by other declarations. The shadowing rules still
need to consider the module re-export DAG, but we'll leave that for
later.

As part of this, keep track of the last time we loaded extensions for
a given nominal type. If the list of extensions is out-of-date with
respect to the global generation count (which tracks resolved module
imports), ask the modules to load any additional extensions. Only the
Clang module importer can currently load extensions in this manner.


Swift SVN r5223
2013-05-20 18:06:51 +00:00
Jordan Rose
7bea410369 Introduce a LoadedModule base class for ClangModule and SerializedModule.
This keeps AST insulated from the various module-loading interfaces, which
minimizes special-casing of the differences between ClangModule and the
(upcoming) SerializedModule.

Swift SVN r5096
2013-05-08 18:33:36 +00:00
Jordan Rose
ccae995f61 Use a list of module loaders instead of a single Clang importer.
This paves the way for having a Swift module importer. The eventual goal
here is to eliminate all explicit uses of the Clang module loader, but
I'm not going to push too hard on that for now.

Swift SVN r5092
2013-05-08 18:09:33 +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
ce0d0aeda2 Use the same module cache directory as Clang
Swift SVN r4927
2013-04-26 22:08:54 +00:00
Doug Gregor
7ab788244f Sync up with Clang API changes when accessing macros.
Swift SVN r4494
2013-03-27 17:48:58 +00:00
Doug Gregor
f43ecceadd <rdar://problem/13037793> Remove the "ObjectiveC" module name hack now that Clang doesn't need it (per Clang r177621).
Unfortunately, we're replacing that hack with a different hack to work
around the complete lack of mapping from Swift source locations to
Clang source locations.


Swift SVN r4460
2013-03-21 01:29:17 +00:00
Doug Gregor
774b454e0d Fake a source location to pass to Clang when asking it to load a module
Swift SVN r4458
2013-03-20 23:17:43 +00:00
Joe Groff
2e15d99e80 CMake: Install Clang headers.
Move the path for the Clang headers to lib/swift/clang since that's a place swift can find them either in the build dir or in an installation. Arrange for the headers out of the Clang build dir to be installed in the Swift tree.

Swift SVN r4296
2013-03-06 01:29:49 +00:00
Doug Gregor
6adc44dac1 Fix for Clang r175585
Swift SVN r4106
2013-02-20 17:56:58 +00:00
Joe Groff
bd59da3e9e REPL: Find completions from Clang modules.
Integrating Clang's FindVisibleDecls with Swift's by importing every decl created too much per-repl-entry compile time overhead, so as a workaround, just wire completions directly to FindVisibleDecls on the clang translation unit itself. Unfortunately this means we get completions for things Swift can't import yet, but it also means we don't have to wait 30 seconds to compile every entry after doing a completion.

Swift SVN r4061
2013-02-15 22:30:29 +00:00
Doug Gregor
949067001a Don't import 'true' or 'false' from Clang modules <rdar://problem/13187570>.
Swift SVN r4028
2013-02-13 13:56:31 +00:00
Joe Groff
55997e255c ClangImporter: Update for Clang options change.
'-fmodule-cache-path foo' became '-fmodules-cache-path=foo' upstream.

Swift SVN r3982
2013-02-07 22:19:03 +00:00
Doug Gregor
a9a90fd56a Track the Clang macros that were used to generate Swift constants.
Swift SVN r3960
2013-02-06 00:57:03 +00:00
Joe Groff
77fc671d91 ClangImporter: Groundwork for importing #defines.
When doing name lookup into a Clang module, look for a macro with the given name and try to convert it into a Swift decl. Turn simple literal macros with expansions <number>, -<number>, or (-<number>) into Swift read-only properties. Map integer literals to Swift 'Int' and float literals to Swift 'Double' for want of a better type to map them to--it would probably be better if we had a decl that behaved like Pascal 'const' and converted like a literal value. Codegen for the synthesized properties isn't wired up, so compiling code that tries to use macro values will currently die because of missing externals.

Swift SVN r3941
2013-02-03 19:06:11 +00:00
Jordan Rose
8f095564aa Update the module importer for Clang r172665.
Only import visible categories as extensions. Don't import hidden ones
(whether from submodules or elsewhere), and most importantly don't use
the raw category chain.

Swift SVN r3792
2013-01-18 00:40:27 +00:00
Jordan Rose
a0c019ed4d HACK: Search for modules in /usr/include/objc/ to find the ObjectiveC module.
The removal of this hack is tracked by <rdar://problem/13037793>.

Swift SVN r3790
2013-01-18 00:40:25 +00:00