Commit Graph

986 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
Joe Groff
6449655e21 Implement selector-style function definition syntax.
rdar://12315571
Allow a function to be defined with this syntax:

  func doThing(a:Thing) withItem(b:Item) -> Result { ... }

This allows the keyword names in the function type (in this case
`(_:Thing, withItem:Item) -> Result`) to differ from the names bound in the
function body (in this case `(a:Thing, b:Item) -> Result`, which allows
for Cocoa-style `verbingNoun` keyword idioms to be used without requiring
those keywords to also be used as awkward variable names. In addition
to modifying the parser, this patch extends the FuncExpr type by replacing
the former `getParamPatterns` accessor with separate `getArgParamPatterns`
and `getBodyParamPatterns`, which retrieve the argument name patterns and
body parameter binding patterns respectively.



Swift SVN r3098
2012-11-01 21:53:15 +00:00
Ted Kremenek
a5ec0af7e8 Rename 'BraceStmt::elements()' to 'getElements()' to match Swift
naming style for accessors.

Swift SVN r2742
2012-08-24 14:17:28 +00:00
Eli Friedman
eb1689710f Delete isa, cast, and dyn_cast on Type. Hopefully, this will lead to fewer stupid mistakes.
Swift SVN r2691
2012-08-20 22:15:10 +00:00
Eli Friedman
bef302d2ee Initial attempt at implementing semantic analysis of overriding for classes.
Still a lot of missing pieces, but it mostly works.



Swift SVN r2633
2012-08-15 01:21:35 +00:00
Eli Friedman
6781f56cfd Start of support for class inheritance.
Swift SVN r2598
2012-08-09 21:56:05 +00:00
Ted Kremenek
479077e354 Remove individual element setters from BraceStmt, and just use MutableArrayRef and ArrayRef to access its elements.
Swift SVN r2586
2012-08-08 05:06:33 +00:00
Doug Gregor
4d4ab92859 When unqualified name lookup from an instance method, constructor, or
destructor finds a metatype member (e.g., a typealias), the resulting
access expression should be based on the metatype (possibly
specialized) rather than based on 'this'. Fixes <rdar://problem/11926972>.


Swift SVN r2390
2012-07-22 07:39:42 +00:00
Eli Friedman
d6a4ba90dd Move TypeLocs to a design where a TypeLoc is a struct containing a type plus
location info for that type.  Propagate TypeLocs a bit more through the AST.



Swift SVN r2383
2012-07-20 21:00:30 +00:00
Eli Friedman
c9cb594eb3 IRGen for destructors. (This code is likely to change a lot once we design classes properly, but it should be a decent start.)
Swift SVN r2365
2012-07-17 22:41:23 +00:00
Eli Friedman
908cf4573f A couple minor tweaks to get extensions for generic types working.
Swift SVN r2335
2012-07-10 22:19:53 +00:00
Eli Friedman
0aee5f30d5 A few misc fixes for constructing generic types. Add a WIP implementation of Slice<T>.
Swift SVN r2334
2012-07-10 21:56:43 +00:00
Eli Friedman
6258942b30 Explicitly specify whether we're performing type lookup to the name lookup code, rather than deducing it from the translation phase.
Swift SVN r2312
2012-07-06 01:06:46 +00:00
Eli Friedman
a65b737730 Allow name lookup into generic types.
Swift SVN r2305
2012-07-04 02:36:45 +00:00
Eli Friedman
99fac3aaa8 Change MetaTypeType so that the instance type is actually a Type, not a TypeDecl*.
Swift SVN r2301
2012-07-03 23:12:19 +00:00
Eli Friedman
4555345440 Add basic parser/AST support for defining generic types.
Swift SVN r2292
2012-07-03 01:34:58 +00:00
Eli Friedman
a1a182e3d9 Initial implementation of member operators. Known limitations: currently only works for operators on structs/classes, the lookup rules aren't completely settled,
and we don't actually check whether it's reasonable to declare a given operator as a member.



Swift SVN r2277
2012-06-29 00:47:33 +00:00
Doug Gregor
827e87cac3 Switch the representation of the list of protocols to which an
archetype conforms from a list of Types (each of which is existential)
to the minimized, sorted list of protocol declarations as used by
canonical protocol composition types. This stable list is more
suitable for IR generation.


Swift SVN r2238
2012-06-25 18:37:52 +00:00
Eli Friedman
ab2998431c Simplify our handling of tuple elements in the AST and Sema.
Swift SVN r2224
2012-06-21 21:30:57 +00:00
Doug Gregor
efd92be870 Introduce a form of TypeChecker::buildMemberRefExpr() that accepts the
results of member lookup, and eliminate all uses of
MemberLookup::createResultAST(). The AST library should not be
performing this semantic analysis.


Swift SVN r2221
2012-06-21 17:18:47 +00:00
Doug Gregor
f4bdd9ddf3 Introduce support for using static protocol functions within generics.
Swift SVN r2216
2012-06-20 17:59:03 +00:00
Doug Gregor
dfc23195ae Make liberal use of the new TypeBase::getRValueType().
Swift SVN r2208
2012-06-20 00:04:27 +00:00
Eli Friedman
433de7c3d2 Fix a crash-on-invalid in name lookup.
Swift SVN r2205
2012-06-19 22:18:09 +00:00
Doug Gregor
f847fe4a22 Introduce basic support for type-checking the definitions of generic
functions. This involves a few steps:

  - When assigning archetypes to type parameters, also walk all of the
  protocols to which the type parameter conforms and assign archetypes
  to each of the associated types.
  - When performing name lookup into an archetype, look into all of
  the protocols to which it conforms. If we find something, it can be
  referenced via the new ArchetypeMemberRefExpr.
  - When type-checking ArchetypeMemberRefExpr, substitute the values
  of the various associated types into the type of the member, so the
  resulting expression involves the archetypes for the enclosing
  generic method.

The rest of the type checking essentially follows from the fact that
archetypes are unique types which (therefore) have no behavior beyond
what is provided via the protocols they conform to. However, there is
still much work to do to ensure that we get the archetypes set up
correctly.



Swift SVN r2201
2012-06-19 21:16:14 +00:00
Doug Gregor
bf71eeb26d Include the generic parameter list of a function declaration in the
FuncDecl AST, and use it for local name lookup.


Swift SVN r2198
2012-06-18 23:49:40 +00:00
Chris Lattner
db0cd646fc lexer/parser/ast/sema support for do/while statements. irgen next.
Swift SVN r2186
2012-06-17 02:29:54 +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
72e1bed79e Refactoring for constructor lookup.
Swift SVN r2170
2012-06-07 23:33:08 +00:00
Eli Friedman
45f1fa1f6c Fix some comments; remove unused ErrorStmt.
Swift SVN r2169
2012-06-07 22:14:17 +00:00
Eli Friedman
f1ffa870a3 A few adjustments to AST/Sema for ConstructorDecls, and starting IRGen.
Swift SVN r2160
2012-06-06 00:53:44 +00:00
Eli Friedman
75907029f1 Add parsing and semantic analysis for a basic ConstructorDecl. Still missing: no IRGen, and semantic analysis to actually call them.
Swift SVN r2159
2012-06-05 23:51:19 +00:00
Eli Friedman
27f8a5ab62 Teach the parser's handling of scopes to handle local types correctly.
Swift SVN r2138
2012-06-04 19:14:58 +00:00
Eli Friedman
26159b59ee First draft of some code to make the general unqualified lookup able to perform lookup into local scopes. Normally, name-binding doesn't need this because the parser can resolve references to locals, but we need this sort of lookup to handle cases involving local types. It's also likely this will be generally useful for tools consuming the AST, typo-correction, etc.
We probably need to add some sort of data structure to represent this information, but as a proof of concept the current code appears to work.  I'm still working out how to make sure the parser doesn't prematurely bind names and how to make name-binding use it where appropriate (and avoid it when we don't need it, because no matter how efficient we make it, it will still be relatively expensive).



Swift SVN r2112
2012-06-02 01:26:58 +00:00
Eli Friedman
d829b3c775 Unify the complete unqualified lookup logic in the UnqualifiedLookup class.
Swift SVN r2109
2012-06-01 23:26:58 +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
29a13e9ae0 Move the NameLookup class into the AST library.
Swift SVN r2101
2012-05-31 22:35:50 +00:00