Commit Graph

172 Commits

Author SHA1 Message Date
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Doug Gregor
c8dd8d0661 Implement SE-0001: Allow (most) keywords as argument labels.
Allow all keywords except for parameter introducers (var/let/inout) to
be argument labels when declaring or calling a
function/initializer/subscript, e.g., this

  func touchesMatching(phase: NSTouchPhase, `in` view: NSView?) -> Set<NSTouch>

can now be expressed as

  func touchesMatching(phase: NSTouchPhase, in view: NSView?) -> Set<NSTouch>

and the call goes from

  event.touchesMatching(phase, `in`: view)

to

  event.touchesMatching(phase, in: view)

Fixes [SR-344](https://bugs.swift.org/browse/SR-344) /
rdar://problem/22415674.
2015-12-22 16:18:28 -08:00
Xi Ge
d569159ffb [Token] Trim surrounding whitespace when querying the ranges of tokens' associated comments.
Need this for rdar://21607719

Swift SVN r31880
2015-09-11 02:14:30 +00:00
Doug Gregor
c02cd1a424 Factor omit-needless-words logic out of the Clang importer.
Sink the actual logic for omitting needless words way down into
Basic, so we can re-use it elsewhere. Tie the Clang importer into that
logic, mapping Clang types down to strings appropriately. NFC

Swift SVN r31233
2015-08-13 23:39:29 +00:00
Doug Gregor
f76bc108fc Don't omit words down to "get", "set", or a Swift keyword.
Swift SVN r31189
2015-08-12 21:24:42 +00:00
Jordan Rose
f5b1efb354 Move client-affecting configuration options into a generated Config.h.
This way they can be used from other projects, like LLDB. The downside
is we now have to make sure the header is included consistently in all
the places we care about, but I think in practice that won't be a problem,
especially not with tests.

rdar://problem/22240127

Swift SVN r31173
2015-08-12 17:50:13 +00:00
Chris Willmore
5ea5ce0e70 Source range of backtick-escaped identifier token should include backticks.
<rdar://problem/21392294> Swift 2 Migration failures, redux

Swift SVN r30907
2015-08-01 05:07:32 +00:00
Chris Lattner
0001dc27bb remove support for the experiemental "character literals" feature.
Swift SVN r30509
2015-07-22 22:35:19 +00:00
Joe Groff
66ba6827bf Parse the 'indirect' attribute on enums and cases.
Swift SVN r29777
2015-06-28 21:52:59 +00:00
Devin Coughlin
8b5f6fec60 Rename '#os' to '#available'
The API review list found it confusing that if #os() and #if os() looked so similar, so
change the availability checking query to be spelled #available:

if #available(iOS >= 9.0, *) {
  ...
}

Swift SVN r26995
2015-04-04 23:33:13 +00:00
Chris Lattner
a0d02cdcdd Several minor changes:
- Strength reduce isAtStartOfBindingName() to just check for 
   identifier or _ and inline into its two callers.
 - Rename Token::isIdentifierOrNone to isIdentifierOrUnderscore.
 - Teach InVarOrLetPattern about matching patterns, so that the
   parser knows when it is parsing an expression as a matching
   pattern but is not yet inside a let/var pattern.
 - Use newfound knowledge of matching patterns to refine handling
   of unexpected let/var when parsing an expression, but not in a
   pattern context, slightly improving QoI in invalid cases.



Swift SVN r26172
2015-03-15 23:36:05 +00:00
Chris Lattner
65b432a495 split tok::oper_postfix into two token kinds, one that indicates that it was spaced
and one that indicates that it was unspaced.  NFC, needed by my next patch.


Swift SVN r25225
2015-02-12 05:19:18 +00:00
Dmitri Hrybenko
d225e496e6 Fix warnings about && nested in ||
Swift SVN r22326
2014-09-28 01:55:18 +00:00
Devin Coughlin
0d7996f4ee Add parsing of availability query expressions (#os(...))
This patch adds a new 'pound_os' token, a new case for it in parseExprPostfix, and parsing of platform version constraints, e.g., OSX >= 10.10. 

It also adds enough type checking and SILGen to get the parsing tests to run without triggering "Unimplemented" assertions.


Swift SVN r21865
2014-09-11 02:59:05 +00:00
Chris Lattner
8991456ff2 Switch infix/postfix/prefix to be declaration modifiers instead of attributes,
eliminating the @'s from them when used on func's.  This is progress towards
<rdar://problem/17527000> change operator declarations from "operator prefix" to "prefix operator" & make operator a keyword

This also consolidates rejection of custom operator definitions into one
place and makes it consistent, and adds postfix "?" to the list of rejected
operators.

This also changes the demangler to demangle weak/inout/postfix and related things
without the @.



Swift SVN r19929
2014-07-14 15:51:49 +00:00
Chris Lattner
8078fecd18 fix <rdar://problem/17625253> Remove the 'strong' context-sensitive keyword
Swift SVN r19819
2014-07-10 19:46:22 +00:00
Chris Lattner
5b49d59c57 Remove the @ from @final and @lazy, the last major piece of
rdar://17168115.

Also, reinstate the ARM driver change and testcase that I removed
in my last patch.


Swift SVN r19790
2014-07-10 06:23:27 +00:00
Chris Lattner
fe95f81397 introduce a new 'DeclModifier' flag on attributes, which mark that the
attribute is a "modifier" of a decl, not an "attribute" and thus shouldn't
be spelt with an @ sign.  Teach the parser to parse "@foo" but reject it with
a nice diagnostic and a fixit if "foo" is a decl modifier.

Move 'dynamic' over to this (since it simplifies some code), and switch the
@optional and @required attributes to be declmodifiers (eliminating their @'s).



Swift SVN r19787
2014-07-10 05:49:10 +00:00
Joe Groff
9ddad1d718 Sema: Basic parsing and checking for 'dynamic'.
Parse 'dynamic' as a contextual keyword, and check that it's applied only to ObjC-compatible members of classes. We don't handle inheritance of the attribute yet.

Swift SVN r19781
2014-07-10 05:05:29 +00:00
Jordan Rose
9320f1a7c5 Claim 'private', 'internal', and 'public' as full keywords.
Swift SVN r19756
2014-07-09 22:56:28 +00:00
Chris Lattner
02999cac51 Reinstate the @ on the @objc attribute. This is largely a revert of r19555 with a few tweaks.
Swift SVN r19706
2014-07-08 21:50:34 +00:00
Jordan Rose
3f59d6b9ee Drop the '@' from access control modifiers.
Test and stdlib changes to follow.

Swift SVN r19671
2014-07-08 02:16:59 +00:00
Chris Lattner
7a56499d61 Start making @objc not start with an @ sign:
- Change the parser to accept "objc" without an @ sign as a contextual
   keyword, including the dance to handle the general parenthesized case.
 - Update all comments to refer to "objc" instead of "@objc".
 - Update all diagnostics accordingly.
 - Update all tests that fail due to the diagnostics change.
 - Switch the stdlib to use the new syntax.

This does not switch all tests to use the new syntax, nor does it warn about
the old syntax yet.  That will be forthcoming.  Also, this needs a bit of 
refactoring, which will be coming up.



Swift SVN r19555
2014-07-04 05:57:57 +00:00
Chris Lattner
cb97c11214 Fix a super-obscure bug where we could attach the doc comment attached to a token when
backtracking, because we didn't restore the lexer state to before the comment, preventing
it from being attached to the token that followed it after backtracking was restored.

This is super obscure right now, but causes two tests to fail with my forthcoming patch,
lets nip this in the bud.



Swift SVN r19553
2014-07-04 05:54:26 +00:00
Adrian Prantl
400f1774e9 Add support for a #line directive.
This patch extends the syntax with a new #line directive that is inspired
by the homonymous CPP directive. It can be specified in all locations a #if
is legal (Stmt, Decl).

Semantics
---------

#line 42 "file.swift"
This makes diagnostics and debug information behave as if the subsequent
lines came from file.swift+42.

#line // without arguments
This switches back to the main source file and the switches back to the
normal line numbering. Any previous #line directives will result in gaps
in the main file.

Rationale
---------

LLDB and the REPL need this for making expressions that are entered into
the expression evaluator or REPL debugable. For more info see
<rdar://problem/17441710> Need #line directive or something similar so we can enhance the debugging of expressions and REPL

Also, I believe the stdlib would benefit from this and it would allow us
to get rid of the line-directive wrapper script.

Swift SVN r19384
2014-06-30 23:50:11 +00:00
Dmitri Hrybenko
a01b72ea2f Comment parsing: increase the maximum size of documentation comment
Turns out 64 Kib is closer than it seems -- I hit this limit with an
autogenerated source file where a part of it was commented out, and the
compiler crashed in an obscure way.


Swift SVN r19339
2014-06-30 12:59:43 +00:00
Joe Groff
88f2632a44 Allow trailing closures with a line break before '{'.
Swift SVN r19322
2014-06-28 05:12:48 +00:00
Dave Abrahams
b7a8fc7d4c Revert "Allow trailing closures with a line break before '{'."
This reverts r19315, which broke my build:

-- Testing: 1 tests, 1 threads --
FAIL: Swift :: Interpreter/arrays.swift (1 of 1)
******************** TEST 'Swift :: Interpreter/arrays.swift' FAILED ********************
Script:
--
rm -rf /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/test/Interpreter/Output/arrays.swift.tmp && mkdir -p /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/test/Interpreter/Output/arrays.swift.tmp && xcrun -sdk macosx10.10 /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/bin/swift -target x86_64-apple-macosx10.9 -resource-dir '/Users/dave/build/swift/Ninja-RelWithDebInfo/swift/lib/swift' -module-cache-path /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/swift-module-cache -module-cache-path /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/test/Interpreter/Output/arrays.swift.tmp/clang-module-cache /Users/dave/src/s/swift/test/Interpreter/arrays.swift -o /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/test/Interpreter/Output/arrays.swift.tmp/a.out &&  /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/test/Interpreter/Output/arrays.swift.tmp/a.out | FileCheck /Users/dave/src/s/swift/test/Interpreter/arrays.swift
--
Exit Code: 1

Command Output (stderr):
--
/Users/dave/src/s/swift/test/Interpreter/arrays.swift:54:1: error: invalid use of '()' to call a value of non-function type '()'
println()
^

Swift SVN r19317
2014-06-28 01:51:45 +00:00
Joe Groff
0c9fc15ae1 Allow trailing closures with a line break before '{'.
Swift SVN r19315
2014-06-28 00:36:45 +00:00
Chris Lattner
2dc1df52d1 Implement <rdar://problem/16954464> Cannot make a strong IBOutlet
This adds support for the "strong" ownership modifier, and specifically 
make it override the "implicit weak" behavior of @IBOutlet.



Swift SVN r18737
2014-06-08 20:49:21 +00:00
Chris Lattner
bca1634958 fix rdar://16889886 - Assert when trying to weak capture a property of self in a lazy closure
also improve error recovery.


Swift SVN r18008
2014-05-13 16:45:15 +00:00
Jordan Rose
57e771ca38 [Parse] Make Token::isAny and Token::isNotAny variadic.
No functionality change.

Swift SVN r17519
2014-05-06 02:06:02 +00:00
Chris Lattner
0ceb7ab023 introduce new Token::isAny and Token::isNotAny methods which are
helper predicates to see if the token is any of a set.


Swift SVN r17498
2014-05-05 23:52:49 +00:00
Chris Lattner
2427e36ff8 Introduce a new "convenience" context sensitive keyword, which can only be
used on init decls, with the same semantics as "-> Self".  Switch the ast
printer, and fixits to use it.

As driveby's, simplify verification of contextual keywords in declparsing,
and rename parseConstructor/Destructor to parseInit/Deinit.


Swift SVN r17356
2014-05-04 04:02:32 +00:00
Chris Lattner
b3133da827 Parse weak/unowned/unowned(safe)/unowned(unsafe) as context sensitive keywords.
This is part of <rdar://problem/16782966> make weak and unowned be context sensitive keywords

The part still missing is where we ban the attribute with a fixit to use the
non-attribute syntax.



Swift SVN r17235
2014-05-02 06:21:44 +00:00
Chris Lattner
0f6c01a6e8 factor a test for decl contextual keywords out into a helper function. NFC.
Swift SVN r17227
2014-05-02 04:33:35 +00:00
Chris Lattner
0c390777ba Implement <rdar://problem/16204675> Need #elseif
This restructures IfConfigDecl/Stmt to be a list of clauses controlled
by a condition.  This makes it straight-forward to drop in #elseif support.

While I'm in here, this patch moves checking for extraneous stuff at the
end of the #if line from the lexer to the parser.  This means that you can
now put a comment on the same line as a #if/#else/#elseif/#endif.



Swift SVN r16912
2014-04-27 04:51:36 +00:00
Doug Gregor
6da952e798 Parse the new function syntax.
Parse the new function syntax, which allows both the argument (API)
and parameter (internal) name to be specified prior to the colon
within each parameter. Don't re-use the existing pattern-parsing
logic. Rather, implement a new (far simpler) parser for this purpose,
then map from its simple data structures to ArgParams and BodyParams
as we're used to.

There are a number of caveats here:
  - We no longer have the ability to use patterns for parameters in
  function declarations. The only place this really has an impact is
  that it makes the ~> hack in the standard library even uglier.
  - This exposed some issues with code completion with generic
  parameters that need to be investigated.
  - There's still some work to be done to improve recovery when things
  parse poorly within a parameter list; there are some XFAILs to deal
  with that.

I'll address the last two issues with follow-up commits.

Swift SVN r15967
2014-04-05 00:21:06 +00:00
Doug Gregor
93ae2c8664 Clear out the "escaped identifier" bit when we form a token.
Test coming.

Swift SVN r15178
2014-03-18 01:05:44 +00:00
Joe Groff
5ebfb131ee Lexer: Don't contextualize escaped identifiers as keywords.
Track whether an identifier token is an escaped identifier token so that 'isContextualKeyword' can say "no" when an identifier is escaped.

Swift SVN r14712
2014-03-06 01:37:31 +00:00
Joe Pamer
f83f94d9d8 Support build and target configurations
These changes add support for build and target configurations in the compiler.
Build and target configurations, combined with the use of #if/#else/#endif allow
for conditional compilation within declaration and statement contexts.

Build configurations can be passed into the compiler via the new '-D' flag, or
set within the LangOptions class. Target configurations are implicit, and
currently only "os" and "arch" are supported.

Swift SVN r14305
2014-02-24 18:16:48 +00:00
Dmitri Hrybenko
34df7b494e Comment parsing: recognize documentation and non-documentation comments, merge
consecutive documentation comments and form 'RawComment's.


Swift SVN r14084
2014-02-19 16:20:38 +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
Dave Zarzycki
1e3fd1a5b1 Parser: allow '...' to be an operator for ranges
<rdar://problem/16018151> Allow me to declare an operator spelled "..."

Swift SVN r13670
2014-02-08 02:10:37 +00:00
Joe Groff
911929f1dd Parse and type check initializer closures after 'new T[n]' exprs.
Require that either T be default constructible or that the user provide a closure that maps indices to initial values. We don't actually call the closure yet to initialize the array; that's blocked on function abstraction difference <rdar://problem/13251236>.

Swift SVN r8801
2013-10-01 05:12:54 +00:00
Joe Groff
cc45633714 SIL: Don't print instruction labels for value-less instructions.
Swift SVN r6756
2013-07-30 22:33:34 +00:00
Dmitri Hrybenko
a0cd8e93ae Lexer: don't consume the first token before we apply all code completion
settings

This allows us to code complete at EOF when there is no newline.


Swift SVN r6640
2013-07-26 03:48:20 +00:00
Dmitri Hrybenko
3c5b12fc0f Code completion: add a lot of infrastructure code
* Added a mode in swift-ide-test to test code completion.  Unlike c-index-test,
  the code completion token in tests is a real token -- we don't need to
  count lines and columns anymore.

* Added support in lexer to produce a code completion token.

* Added a parser interface to code completion.  It is passed down from the
  libFrontend to the parser, but its functions are not called yet.

* Added a sketch of the interface of code completion consumer and code
  completion results.

Note: all this is not doing anything useful yet.


Swift SVN r6128
2013-07-10 20:53:40 +00:00
Argyrios Kyrtzidis
6e7d0490f7 Allow optionally to produce comment tokens when lexing and add a tokenize() utility function.
Swift SVN r6008
2013-07-05 15:02:42 +00:00
Chris Lattner
98d708d1fc In a SIL function body, lex %42 as a new sil_local_name token.
Swift SVN r5261
2013-05-22 05:34:18 +00:00