Commit Graph

439 Commits

Author SHA1 Message Date
Doug Gregor
bb26f52585 Initial support for loading Clang modules into Swift.
From a user's perspective, one imports Clang modules using the normal
Swift syntax for module imports, e.g.,

  import Cocoa

However, to enable importing Clang modules, one needs to point Swift
at a particular SDK with the -sdk= argument, e.g.,

  swift -sdk=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9M.sdk

and, of course, that SDK needs to provide support for modules.

There are a number of moving parts here. The major pieces are:

CMake support for linking Clang into Swift: CMake users will now need
to set the SWIFT_PATH_TO_CLANG_SOURCE and SWIFT_PATH_TO_CLANG_BUILD
to the locations of the Clang source tree (which defaults to
tools/clang under your LLVM source tree) and the Clang build tree.

Makefile support for linking Clang into Swift: Makefile users will
need to have Clang located in tools/clang and Swift located in
tools/swift, and builds should just work.

Module loader abstraction: similar to Clang's module loader,
a module loader is responsible for resolving a module name to an
actual module, loading that module in the process. It will also be
responsible for performing name lookup into that module.

Clang importer: the only implementation of the module loader
abstraction, the importer creates a Clang compiler instance capable of
building and loading Clang modules. The approach we take here is to
parse a dummy .m file in Objective-C ARC mode with modules enabled,
but never tear down that compilation unit. Then, when we get a request
to import a Clang module, we turn that into a module-load request to
Clang's module loader, which will build an appropriate module
on-the-fly or used a cached module file.

Note that name lookup into Clang modules is not yet
implemented. That's the next major step.



Swift SVN r3199
2012-11-16 18:17:05 +00:00
Chris Lattner
a052faf351 remove some implementations of classof that are now unneeded with mainline LLVM changes.
Swift SVN r2989
2012-10-12 18:22:16 +00:00
Eli Friedman
960b0bfd35 Move most type lookup from name-binding into TypeChecker::validateType. Use this to make type resolution more powerful, so we can resolve members of types like S<Int>
and Int[].

Type resolution for types named in ExtensionDecls remains a part of name-binding; it has to use more restrictive rules because we can't perform general member lookup until
we've resolved all the types named in ExtensionDecls.



Swift SVN r2313
2012-07-06 01:51:09 +00:00
Eli Friedman
18dfa5cf7d More refactoring; allow ConstructorLookup to find constructors in classes.
Swift SVN r2171
2012-06-07 23:57:18 +00:00
Eli Friedman
0e7ef8cebb Start refactoring code towards a single complete implementation of unqualified lookup.
Swift SVN r2108
2012-06-01 01:37:44 +00:00
Eli Friedman
377972b1ba Start shuffling around code for name binding on values; with the proposed shadowing rules, we need to delay name binding on values until after some parts of type-checking.
Swift SVN r1946
2012-05-23 00:42:53 +00:00
Eli Friedman
87dd43a4b8 Refactor member and constructor lookup to depend on centralized routines in Module rather than scattering assumptions about how lookup works across Sema. This should make it easier to make changes in the future which affect lookup.
I'm not entirely sure these are the right APIs to expose, but this at least seems like progress.



Swift SVN r1848
2012-05-15 02:04:53 +00:00
Eli Friedman
907cc521ab Switch a couple booleans in Module over to an enum.
Swift SVN r1845
2012-05-15 00:20:01 +00:00
Eli Friedman
05fe3c907f Propagate a DeclContext through NameBinding for IdentifierTypes.
Swift SVN r1803
2012-05-10 23:34:01 +00:00
Eli Friedman
a143422c98 Teach name binding to look into default values for tuple types.
Swift SVN r1747
2012-05-04 23:09:55 +00:00
Eli Friedman
e6177f35a9 Get rid of the outdated notion of type lookup in Module. <rdar://problem/11026489>.
Swift SVN r1734
2012-05-04 00:41:54 +00:00
Eli Friedman
a2c6150c13 Error recovery for the REPL. Seems to be working reasonably well. <rdar://problem/11269380>.
Swift SVN r1523
2012-04-20 01:14:39 +00:00
Eli Friedman
be602fcd05 Get rid of the implicit BraceStmt for the TranslationUnit; instead, have the TranslationUnit directly store a list of decls.
Swift SVN r1521
2012-04-20 00:17:13 +00:00
Eli Friedman
acc17d69aa Initial implementation of the "print" part of the REPL.
Swift SVN r1484
2012-04-19 01:13:37 +00:00
Eli Friedman
37de44a35d Implement changes to parsing/sema/etc so that we can implement a REPL and the main module parses the same way as a REPL.
Next step: implement an actual REPL.



Swift SVN r1441
2012-04-16 23:52:01 +00:00
Eli Friedman
9bf8dcf0f1 Delete some dead code.
Swift SVN r1412
2012-04-13 01:05:12 +00:00
Eli Friedman
f477cf588e Introduce the notion of the "main" module, i.e. the module which defines main(). Disallow top-level statements in modules other than the main module. Fix IRGen to generate a main() function in the main module, and implement top-level statements. Get rid of the main() mangling hack. Part of <rdar://problem/11185451>.
I haven't really carefully considered whether existing type-checking etc. is correct for the main module (I think the name-binding rules need to be a bit different?), but it seems to work well enough for the obvious cases.

This is enough to get the one-liner "println(10)" to print "10" in "swift -i" mode, although the path to swift.swift still needs to be explicitly provided with -I.



Swift SVN r1325
2012-04-05 00:35:28 +00:00
Doug Gregor
5fffa75e7b Remove empty throw specifications from all of the overloaded new operators; reduces code size by 8k
Swift SVN r1282
2012-03-28 22:00:02 +00:00
Chris Lattner
50c95e7f32 resolve the FIXME.
Swift SVN r1172
2012-03-09 11:13:43 +00:00
Eli Friedman
48f0f1d77e Fix assertion failure on tests.
Swift SVN r1168
2012-03-05 19:58:06 +00:00
Chris Lattner
1c42e8f6a6 rename DottedNameType to IdentifierType. It captures loc information for random uses of type names, among other things.
Swift SVN r1064
2012-01-18 01:52:28 +00:00
Chris Lattner
c8ca11a199 Drop in the new DottedNameType and wire it up in name binding.
This is horribly hack and slash (but enough to pass all tests) for a few reasons:
- I've #if 0'd out the tendrils of the old code 
- This handles *just* what was handled before instead of being more general
- We don't have an llvm::MutableArrayRef type, so there is some really gross
  const_cast'ing and other struggles to deal with its absence.



Swift SVN r1050
2012-01-17 06:32:00 +00:00
John McCall
6b935588e5 On second thought, components need to be known in the AST.
Swift SVN r918
2011-12-07 03:57:41 +00:00
Chris Lattner
a1b7419a36 remove support for looking up global names with dot syntax. "x.y" != "y(x)" now.
Swift SVN r917
2011-12-07 00:59:09 +00:00
Chris Lattner
ff130c602e implement dot lookup in extensions!
Swift SVN r913
2011-12-07 00:11:01 +00:00
Chris Lattner
900d45f3c0 implement a Module::lookupExtensions method to find all the extensions for a
given type in a given module.  This depends on llvm r145898.


Swift SVN r906
2011-12-06 02:07:13 +00:00
Chris Lattner
fcdddd8d97 move ASTStage up to Module, sigh.
Swift SVN r904
2011-12-06 01:20:18 +00:00
Chris Lattner
32b248b7e3 [gs]etterize various members of Module, and make them check the invariants they depend on.
Swift SVN r903
2011-12-06 01:02:09 +00:00
Chris Lattner
212b56afec actually, the ASTStage should be on Translation unit. There can be multiple modules in a context and they can all be in different phases of translation.
Swift SVN r902
2011-12-06 00:51:56 +00:00
Chris Lattner
164ab0ffee move lookupTypeName out to Module::lookupGlobalType and have it look in the current
module as well for consistency.


Swift SVN r811
2011-11-01 06:27:24 +00:00
Chris Lattner
e0a18996cd move lookupGlobalValue into Module, making it accessable to all of sema.
Swift SVN r810
2011-11-01 06:22:44 +00:00
Chris Lattner
5d8d0fd2f6 Have the name binder publish the list of imported modules into the TranslationUnit,
making it a real part of the AST.  Also, rework TUModuleCache to do its computation
when it is constructed, instead of trying in each query.


Swift SVN r809
2011-11-01 06:19:36 +00:00
Chris Lattner
e3b53c3b15 move the module-level name lookup stuff out of NameBinding.cpp into the
Module class.  Add a new Module.cpp file to implement this (along with
the existing caching strategy, if you're curious).  This eliminates the
parallel 'ModuleProvider' heirarchy.


Swift SVN r802
2011-11-01 05:19:35 +00:00
Chris Lattner
4933a27098 clean up lookupType/lookupValue to only take an AccessPath instead of an import decl.
Strip of the module name implicit in the access path.


Swift SVN r801
2011-11-01 04:43:51 +00:00
Chris Lattner
2ea1e72890 merge two copies of the same predicate into a helper method.
Swift SVN r800
2011-11-01 04:30:25 +00:00
Chris Lattner
8e1c6c8ac6 flatten ModuleKind discriminator into DeclContext's one. Now Module is an
abstract class and we have an actual AST-level concept of the builtin module.


Swift SVN r798
2011-11-01 04:07:57 +00:00
Chris Lattner
fed35466d4 increase the # bits for DeclContextKind's to 3 bits.
Swift SVN r797
2011-11-01 03:58:21 +00:00
John McCall
c61c807589 Mangle types for all declarations. Save the names of modules and mangle
those in, too.



Swift SVN r713
2011-09-18 09:21:42 +00:00
John McCall
d56299972b Add the missing Module.h.
Swift SVN r697
2011-09-08 00:20:25 +00:00