Commit Graph

650 Commits

Author SHA1 Message Date
Doug Gregor
4f9f945d62 Teach the Clang importer to add @objc(selector) attributes for imported methods and initializers.
With this in place, remove the hacks that peeked at the imported Clang
node to determine the selector for a method. We're all
attribute-driven now. Part of <rdar://problem/16019773>.


Swift SVN r15663
2014-03-31 04:26:32 +00:00
Ted Kremenek
8ddd56e28f Don't allow 'unavailable' methods to be overridden.
Swift SVN r15646
2014-03-30 08:22:34 +00:00
Ted Kremenek
16ffbc6f3a Extend @availability(*,unavailable) checking to protocol methods.
Protocols can declare methods as being unavailable, as they do
in NSObjectProtocol (e.g., 'retain').  We both need to flag these
uses, but understand this for protocol conformance.  For protocol
conformance, treat unavailable methods as if they were marked
optional.  The compiler will not allow you to use these methods
anyway.

This finishes up support for:

    <rdar://problem/16331335> Ban ObjC ARC entry points

Swift SVN r15644
2014-03-30 07:11:39 +00:00
Ted Kremenek
80df698ccc Teach ClangImporter to import __attribute__((unavailable)) as @availability(*,unavailable).
This is a direct translation which happens when a Clang declaration
gets translated to a Swift declaration.  This changed, coupled
with the current @availability checking (which is still limited)
now prohibits cases such as using 'NSDeallocateObject()' or
'- (BOOL) allowsWeakReference' from Swift.

Interestingly, it doesn't catch uses of -retain/-release yet, because
those methods are marked unavailable in the NSObject *protocol*.
While the attributes are being mapped over, the @availability
checking needs to be enhanced to replicate more of what Clang does
for this case.

Swift SVN r15643
2014-03-30 05:25:52 +00:00
Doug Gregor
b0e3789d7b Add some printing utilities for ObjCAttr.
Swift SVN r15633
2014-03-29 21:27:09 +00:00
Doug Gregor
a0e384f517 A named 'objc' attribute on a class or attribute provides the Objective-C runtime name.
Replace the use of 'asmname' for the runtime name of a class or
protocol with 'objc'. Use it for SwiftObject to eliminate a hack.


Swift SVN r15631
2014-03-29 20:53:17 +00:00
Doug Gregor
936d26e213 @objc naming: classes, protocols, and properties must have simple names.
Swift SVN r15627
2014-03-29 20:00:04 +00:00
Doug Gregor
b49978675e Parsing, representation, and printing for @objc(name)
The @objc attribute can now be provided with a name (in parentheses),
which names the corresponding entity in Objective-C. The name will
either be a selector (for anything that maps down to an Objective-C
method) or a single identifier (for classes and protocols).

The extra information is not used for anything yet.



Swift SVN r15626
2014-03-29 19:36:05 +00:00
Doug Gregor
055e0ef136 Add an "implicit" bit to DeclAttribute.
Swift SVN r15623
2014-03-29 17:24:15 +00:00
Doug Gregor
51672965f4 Remove the unused @fragile, @resilient, and @born_fragile attributes.
Swift SVN r15518
2014-03-26 19:47:08 +00:00
Doug Gregor
1cdd295182 Move the @objc attribute over to a DeclAttribute.
Swift SVN r15517
2014-03-26 19:33:07 +00:00
Ted Kremenek
3f0ff8fa05 Remove @unavailable, and move to introducing basic (sham) parsing for @availability.
The parsing here for @availability isn't real yet; but it provides
scaffolding.  Intended grammar:

  @availability(*, unavailable, message="...")
  @availability(*, unavailable)

  @availability(ios, unavailable)

  and so on.

Much of this doesn't work yet in a general way, but I wanted something
basic to work with to start with to wire up the functionality
for @availability end-to-end (at least for 'unavailable').

As part of this, extend DECL_ATTR to include whether or not an
attribute supports multiple declarations, and use this for
@availability.

Also hardwire darwin platforms, which we will need to have this
list come from somewhere.  The checking could be done at parsing
or elsewhere.

Swift SVN r15491
2014-03-26 06:51:15 +00:00
Ted Kremenek
72ffc9105c Clean up attribute checking during serialization.
Swift SVN r15480
2014-03-26 03:59:07 +00:00
Ted Kremenek
4712476353 Wire up basic parsing support for @unavailable. WIP.
Swift SVN r15434
2014-03-25 01:14:51 +00:00
Ted Kremenek
c8c4e83c15 Fix DeclAttribute::print support for @asmname.
Swift SVN r15431
2014-03-25 00:20:17 +00:00
Ted Kremenek
f43842e160 Change processing of @asmname to use a new internal representation.
This representation is inspired by Clang's internal representation.
The current attribute representation, which is basically a union
of "stuff" in DeclAttributes, is not amendable to richer
attributes, such as @availability, that need to be implemented.
In Clang, attributes are modeled with actual objects that
encode both semantic and syntactic information (e.g., source ranges)
that facilitate richer checking, better diagnostics, and better tools.

This change is foundational for implementing @availability, but
also is a better long-term representation.  As a migratory path,
it creates some duplications, with AttrKind and DeclAttrKind, the
two which should eventually become the same thing.

As part of this patch, there is some additional parser recovery
(for the new attribute representation) for duplicate attributes.
The parser now parses the entire duplicate attribute, which could
be quite complex, and then issues a diagnostic that the attribute
is a duplicate (and discarding it).  This delayed diagnostic
also allows us to present ranges for the duplicate attribute, which
provides a better user experience.

Swift SVN r15365
2014-03-22 14:58:30 +00:00
Doug Gregor
15be2159a2 Rename "abstract initializers" to "required initializers".
It's better than what we have.

Swift SVN r14620
2014-03-03 23:12:40 +00:00
Doug Gregor
230c8a4982 Introduce the 'override' attribute and start requiring it on all overrides.
The 'override' attribute indicates that the given declaration, which
may be a method, property, or subscript, overrides a declaration in
its superclass. Per today's discussion, the 'override' attribute must
be present if and only if the corresponding declaration overrides a
declaration in its superclass. 

This implements most of <rdar://problem/14798539>. There's still more
work to do to on property and subscript overrides.



Swift SVN r14388
2014-02-26 08:53:06 +00:00
Doug Gregor
0da11a8b0b Implement semantic analysis for abstract initializers.
Swift SVN r14221
2014-02-21 19:41:14 +00:00
Dmitri Hrybenko
ecd798b9fd Comment parsing: attaching comments to declarations
We can attach comments to declarations.  Right now we only support comments
that precede the declarations (trailing comments will be supported later).

The implementation approach is different from one we have in Clang.  In Swift
the Lexer attaches the comments to the next token, and parser checks if
comments are present on the first token of the declaration.  This is much
cleaner, and faster than Clang's approach (where we perform a binary search on
source locations and do ad-hoc fixups afterwards).

The comment <-> decl correspondence is modeled as "virtual" attributes that can
not be spelled in the source.  These attributes are not serialized at the
moment -- this will be implemented later.


Swift SVN r14031
2014-02-18 09:04:37 +00:00
Doug Gregor
a688bca7fb Infer @requires_stored_property_inits for CoreData's NSManagedObject.
Swift SVN r12317
2014-01-15 05:11:54 +00:00
Manman Ren
ce642b89f7 Move printing of DeclAttributes from PrintAST::printAttributes to
DeclAttributes::print.

Also add printing of mutating to the print functions.
In serializer, print out the unhandled attributes.


Swift SVN r12073
2014-01-08 23:44:05 +00:00
Jordan Rose
308c6139f9 Change ASTContext::allocate(unsigned) to return a MutableArrayRef.
...rather than a raw pointer that points to a buffer with space for N
elements. Just because we *can* get N from context doesn't mean it's
convenient/safe.

No functionality change.

Swift SVN r11488
2013-12-19 23:25:04 +00:00
Jordan Rose
7b936e2b85 Remove unfinished notion of "Component" (originally for resilience).
docs/Resilience.rst describes the notion of a resilience component:
if the current source file is in the same component as a module being
used, it can use fragile access for everything in the other module,
with the assumption that everything in a component will always be
recompiled together.

However, nothing is actually using this today, and the interface we
have is probably not what we'll want in 2.0, when we actually implement
resilience.

Swift SVN r9174
2013-10-10 21:41:57 +00:00
Argyrios Kyrtzidis
963b6f0579 [serialization] Introduce 'FailedImportModule', which is used to track of when a module file failed to load (e.g. because of missing dependencies).
Swift SVN r8934
2013-10-04 21:29:24 +00:00
Argyrios Kyrtzidis
3e2f360e45 [AST] In the ModuleKind enum class, shorten enumerators by removing 'Module'. No functionality change.
Swift SVN r8933
2013-10-04 21:29:22 +00:00
Anna Zaks
f0dda149ab Move attributes from ValueDecl to Decl.
Swift SVN r8734
2013-09-27 20:29:29 +00:00
Joe Groff
e109124186 Replace 'union' keyword with 'enum'.
This only touches the compiler and tests. Doc updates to follow.

Swift SVN r8478
2013-09-20 01:33:14 +00:00
Dmitri Hrybenko
10291e0334 Make AbstractClosureExpr a DeclContext
(remove DeclContext base class from PipeClosureExpr and ImplicitClosureExpr)


Swift SVN r8303
2013-09-16 22:39:12 +00:00
Dmitri Hrybenko
45e654fbaa Make AbstractFunctionDecl a DeclContext
and remove DeclContext base class from FuncDecl, ConstructorDecl and
DestructorDecl

This decreases the number of DeclContexts to 7 and allows us to apply
alignas(8) to DeclContext.


Swift SVN r8186
2013-09-13 03:38:33 +00:00
Dmitri Hrybenko
0d6d9a0ffb Move the DeclContext base class from FuncExpr to FuncDecl
FuncDecl still has a FuncExpr because capture list is stored in FuncExpr
(which is a CapturingExpr).


Swift SVN r8179
2013-09-13 01:40:41 +00:00
Dmitri Hrybenko
7da84fd13d Make FuncExpr, PipeClosureExpr and ClosureExpr DeclContexts on their own.
This is a first step to detach them from CapturingExpr and eventually move them
in the AST class hierarchy.


Swift SVN r8171
2013-09-12 23:58:06 +00:00
Chris Lattner
55200e5274 Now that Module has its own kind field, drop the various module
discriminators from DeclContext.  This is cleaner and should
enable us to drop the alignment of DeclContext (coming next Jordan!)



Swift SVN r8059
2013-09-09 22:43:11 +00:00
Jordan Rose
674a03b085 Replace "oneof" with "union"...everywhere.
We haven't fully updated references to union cases, and enums still are not
their own thing yet, but "oneof" is gone. Long live "union"!

Swift SVN r6783
2013-07-31 21:33:33 +00:00
Jordan Rose
77ce3f31cb Add a DeclContextKind for Swift modules.
Swift SVN r5095
2013-05-08 18:33:34 +00:00
Joe Groff
74589d788e Make ObjC-ness implicit to ObjC-inherited classes.
Add 'isObjC' as a property of ValueDecl, and set it during type checking if a class is either explicitly annotated with an [objc] attribute or inherits from an isObjC class, or if a func is a method of an isObjC class. Tweak the ClangImporter and other places that summon magic ValueDecl nodes to set up the decls they synthesize as isObjC. Replace logic in typechecking and IRGen that branched on the 'isObjC' attribute to now branch on the 'isObjC' property of ValueDecls.

Swift SVN r4078
2013-02-19 02:11:09 +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
6b4a248f04 Parsing and AST support for destructors on classes.
Swift SVN r2348
2012-07-12 01:26:02 +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
5e206bc10f Rename DistinctTypeDecl to NominalTypeDecl.
Swift SVN r1882
2012-05-17 01:54:15 +00:00
Eli Friedman
79c3276b07 AST representation for ClassDecls.
Swift SVN r1858
2012-05-15 21:53:38 +00:00
Eli Friedman
77fa49ec2b Introduce StructDecl and StructType; use them for structs instead of OneOfDecl/OneOfType. To keep this patch small, I'm leaving in LookThroughOneOf etc. for the moment, but that's next on the agenda.
Swift SVN r1780
2012-05-09 00:27:44 +00:00
Doug Gregor
5f2344afe0 Introduce ProtocolDecl, which describes (*gasp*) a protocol. Move the
guts of ProtocolType over to ProtocolDecl.


Swift SVN r1778
2012-05-08 23:28:55 +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
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
Eli Friedman
d39a7abe36 Implement CapturingExpr. In addition to unifying the hierarchy between FuncExpr and ClosureExpr, this introduces a DeclContext for ClosureExprs. <rdar://problem/11076715>
Swift SVN r1240
2012-03-20 01:08:04 +00:00
John McCall
76ad8fff02 Add more parentheses to Types.h.
Swift SVN r1103
2012-01-31 04:32:37 +00:00
John McCall
8a8f297bde Basic resilience query.
Swift SVN r937
2011-12-15 00:45:31 +00:00
John McCall
a1f7eefba3 Extract out decl attributes into a separately-allocated structure.
Swift SVN r920
2011-12-10 00:39:10 +00:00