Commit Graph

63 Commits

Author SHA1 Message Date
Jordan Rose
45bad83c54 Add a protected LoadedModule::getOwner to simplify r6519.
(r6159 stashed a LoadedModule's owner in the "LookupCachePimpl" field.)

Swift SVN r6696
2013-07-29 18:56:45 +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
Jordan Rose
8e081367ca Basic implementation of lookupVisibleDecls() for serialized modules.
This involved threading it through ModuleLoader, as with all the other
module-generic callbacks. I plan to collapse a bit of the chaining, but
unfortunately not that much.

This brings back the CodeCompletion tests.

Swift SVN r6527
2013-07-23 23:10:28 +00:00
Jordan Rose
3087e8d5ea Add the notion of "re-exported" modules, and use that where it makes sense.
Rather than automatically re-exporting or not re-exporting every import in
a TranslationUnit, we'll eventually want to control which imports are local
(most of them) and which imports are shared with eventual module loaders.
It's probably not worth implementing this for TranslationUnit, but
LoadedModule can certainly do something here.

Currently, a LoadedModule is even more permissive than a TranslationUnit:
all imports are re-exported. We can lock down on this once we have a
re-export syntax.

Swift SVN r6523
2013-07-23 23:10:17 +00:00
Jordan Rose
110d644297 Provide a skeleton for re-exports from serialized modules...
...and use it for shadowed modules (e.g. the Clang module "Foundation"
referenced by the Swift module "Foundation"), so that we can actually
find "NSString" when building AppKit.

Additionally, record shadowed modules as dependencies, so that they can
be loaded when the adapter module is loaded.

Swift SVN r6522
2013-07-23 23:10:13 +00:00
Jordan Rose
f12f3c29ac Reuse "LookupCache" pointer for a LoadedModule’s owner.
Minor size optimization. No functionality change.

Swift SVN r6521
2013-07-23 23:10:11 +00:00
Dmitri Hrybenko
aa46064432 Pass a const ASTContext and const DeclContext whenever possible. This makes it
possible to use lookupVisibleDecls() with a const DeclContext.


Swift SVN r6274
2013-07-15 23:39:00 +00:00
Dmitri Hrybenko
5e4db6f19c Remove useless dyn_cast
Swift SVN r5537
2013-06-08 01:04:10 +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
Jordan Rose
ec1e47cbf0 Thread operator lookup through Module to ModuleLoader...
...even though Swift modules don't provide this lookup yet, and Clang
modules never will.

Swift SVN r5173
2013-05-16 00:23:10 +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
Joe Groff
ac23437886 Replace infix attributes with operator decl lookup
During name binding, associate func decls with operator decls. When parsing SequenceExprs, look up operator decls to determine associativity and precedence of infix operators. Remove the infix_left and infix_left attributes, and make the infix attribute a simple declared attribute [infix] with no precedence.

Operator decls are resolved as follows:

- If an operator is declared in the same module as the use, resolve to the declaration in the current module.
- Otherwise, import operator declarations from all imported modules. If more than one declaration is imported for the operator and they conflict, raise an ambiguity error. If they are equivalent, pick one arbitrarily.

This allows operator declarations within the current module to override imported declarations if desired or to disambiguate conflicting operator declarations.

I've updated the standard library and the tests. stdlib2 and some of the examples still need to be updated.

Swift SVN r4629
2013-04-07 02:43:03 +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
Joe Groff
7a7e3d5615 REPL: Hook up completions to name lookup.
Implement a 'lookupVisibleDecls' API similar to Clang's that replicates the UnqualifiedLookup logic for walking through a given scope looking for decls. Use it to populate the completion list in the repl.

Still to be done: Clang module lookup via Clang's lookupVisibleDecls, and context deduction from dotted path expressions.

Swift SVN r4056
2013-02-15 20:17:44 +00:00
Doug Gregor
f3857df469 Implement an AST pretty-printer for declarations, under -print-ast.
Swift SVN r3431
2012-12-10 23:21:49 +00:00
Doug Gregor
b27c6d94f1 Implement global, unqualified name lookup into Clang modules.
Currently, we only support C functions with the signature
void(void).


Swift SVN r3203
2012-11-16 19:42:03 +00:00
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
Eli Friedman
9e06964c8a Make the TypeLoc constructor which takes just a type private, and expose a
static method to call it, to make it more explicit what is happening.  Avoid
using TypeLoc::withoutLoc for function definitions; instead, just use an empty
TypeLoc.



Swift SVN r2606
2012-08-10 02:09:00 +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
Doug Gregor
c5a1edd1b8 Revert r2372, which is breaking some tests.
Swift SVN r2375
2012-07-19 21:32:22 +00:00
Eli Friedman
fca009f280 TypeLoc-related cleanup: add FIXMEs to the places in validateType that need to
compute sub-TypeLocs, and fix the places that don't need them not to reuse the
parent TypeLoc.



Swift SVN r2374
2012-07-19 04:01:59 +00:00
Eli Friedman
361f931a16 Start propgating TypeLocs from the parser into the AST.
Swift SVN r2372
2012-07-19 02:54:28 +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
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
d969aeea39 Switch everything over to new-style constructors. Change name lookup so it doesn't use old-style constructors for construction anymore.
Swift SVN r2168
2012-06-07 21:04:57 +00:00
Eli Friedman
64d67103fa One more small fix for constructor name lookup. Make the auto-generated element-wise constructor use the name "constructor".
Swift SVN r2165
2012-06-07 19:50:18 +00:00
Eli Friedman
e5b4b924a1 More work on constructors. Basic testcases with "constructor" declarations appear to be working, although there's probably more work to be done. (Both old-style and new-style constructors work for the moment.)
Swift SVN r2163
2012-06-07 01:57:57 +00:00
Doug Gregor
9abd2340bc Allow an 'inheritance' clause on typealiases, specifying what
protocols the underlying type of the type alias shall conform to. This
isn't super-motivating by itself (one could extend the underying type
instead), but serves as documentation, makes typealiases provide the
same syntax as other nominal types in this regard, and will also be
used to specify requirements on associated types.


Swift SVN r2133
2012-06-04 16:15:47 +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
ae86d64644 Rename Decl::getLocStart() to Decl::getStartLoc(). Add Decl::getLoc(), which is essentially the location which should be used for diagnostics.
Swift SVN r2105
2012-05-31 23:56:30 +00:00
Eli Friedman
ba4a76038b Make oneofs never implicitly generate an ExtensionDecl. This matters for local oneofs.
Swift SVN r2098
2012-05-31 21:20:56 +00:00
Eli Friedman
a454d62619 Implement some reasonable shadowing rules for declarations.
Swift SVN r2061
2012-05-29 23:48:40 +00:00
Eli Friedman
8d985dcc38 Change extension lookup so that decls in the current module don't always shadow imports, which should be enough to unblock demo work. <rdar://problem/11492474>.
Swift SVN r1950
2012-05-23 03:16:20 +00:00
Eli Friedman
03a0704ca0 Add a really ugly hack to get shadowing for types working. I'm working on the right solution, but I'm not sure how long that will take.
Swift SVN r1940
2012-05-22 21:16:11 +00:00
Eli Friedman
98933b8510 More work on ClassDecls; this is enough to get member access working.
Swift SVN r1863
2012-05-16 00:22:09 +00:00
Eli Friedman
6f045aad2f Throw the switch to use "var" syntax to declare members of structs. This also means we no longer build an implicit extension for every struct decl. Everything seems to be working, but please yell if this breaks anything.
Swift SVN r1851
2012-05-15 03:27:13 +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
4ca443d0f5 Add OneOfDecl; use it as a DeclContext for OneOfElementDecls instead of OneOfType, and get rid of the implicit TypeAliasDecl. Add TypeDecl as a base class for OneOfDecl and TypeAliasDecl (and StructDecl, once we have it). Adjust a whole bunch of stuff to this new scheme.
Swift SVN r1774
2012-05-08 21:09:42 +00:00
Chris Lattner
774a557e5c Merge NamedDecl into ValueDecl, rdar://11379147.
Swift SVN r1737
2012-05-04 04:50:53 +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
Doug Gregor
a04776044e Teach the import mechanism that it's rude to parse the same library
multiple times, as well as teaching the name lookup mechanism that
it's similarly rude to report ambiguous results because it searched
the same import twice. Fixes <rdar://problem/11287213>.

Yes, this is a bit of an ugly hack.


Swift SVN r1610
2012-04-24 22:36:17 +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
d5e7784010 Get rid of isModuleScope bit, since we don't like scattering bits across the AST; as a replacement, introduce TopLevelCodeDecl, which provides a DeclContext for all expressions and statements at the top level. <rdar://problem/11259941>.
Swift SVN r1503
2012-04-19 21:22:12 +00:00
Chris Lattner
6ab877ad83 fix name lookup to search through all modules to build the candidate set, instead of stopping with the first module that matches. Without this, we don't get the unified overload set for all "+" operators, for example. We arguably should stop searching when we get a type (since they cannot be overloaded) but we can treat that as a follow on issue.
Swift SVN r1481
2012-04-19 00:43:16 +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
361481835c Introduce a notion of module scope declarations; use it where appropriate instead of checking for a local declcontext.
Swift SVN r1380
2012-04-11 02:52:40 +00:00
Chris Lattner
cb1d2cacbe implement a new CanType subclass of Type, for use when we known that we have a canonical type.
Unlike Type, it implements equality operators.  It is returned by Type->getCanonicalType().

This adopts it in the minimal places required to get the build to work, it would also be nice
to switch IRGen to canonical types and use it there.


Swift SVN r1298
2012-03-29 20:33:20 +00:00
Eli Friedman
ddffb633eb Fix build errors with clang-421.
Swift SVN r1167
2012-03-05 19:31:12 +00:00