Commit Graph

218 Commits

Author SHA1 Message Date
Dmitri Gribenko
8b86dac8c1 Revert "[gardening] Fix typo: "nul-terminated" → "null-terminated"" 2016-02-13 15:27:53 -08:00
Peter Friese
888d0f3fa6 [gardening] Fix typo: "nul-terminated" → "null-terminated" 2016-02-11 11:03:38 +00:00
Chris Lattner
d522cd4270 Centralize the parsing logic for #identifiers and make it more similar to
the identifier parsing logic.
2016-02-03 22:37:28 -08:00
Doug Gregor
67c81154af Add a swift3_migration attribute to describe how an API gets migrated.
Introduce a new attribute, swift3_migration, that lets us describe the
transformation required to map a Swift 2.x API into its Swift 3
equivalent. The only transformation understood now is "renamed" (to
some other declaration name), but there's a message field where we can
record information about other changes. The attribute can grow
somewhat (e.g., to represent parameter reordering) as we need it.

Right now, we do nothing but store and validate this attribute.
2016-01-13 16:53:01 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Chris Lattner
443af4ad91 In the deprecation warnings for ++/-- on index types, emit a fixit hint to rewrite into
the correct call to .successor() or .predecessor().

This wraps up <rdar://problem/23708702> Emit deprecation warnings for ++/-- in Swift 2.2
2015-12-22 21:04:48 -08:00
Chris Lattner
e28c2e2c6e Fix <rdar://14296004> [QoI] Poor diagnostic/recovery when two operators (e.g., == and -) are adjacted without spaces.
This is a frequently reported and surprising issue where lack of whitespace leads to
rejecting common code like "X*-4".  Fix this by diagnosing it specifically as a lack
of whitespace problem, including a fixit to insert the missing whitespace (to transform
it into "X * -4".  This even handles the cases where there are multiple valid (single)
splits possible by emitting a series of notes.
2015-12-16 13:20:28 -08:00
Leo Shimonaka
70e66973ee Fix spelling error in documentation / comments / method name 2015-12-05 00:28:08 -05:00
Xi Ge
ecd836049c Correct typo.
Swift SVN r32024
2015-09-17 01:17:49 +00:00
Xi Ge
7f6a8b1315 Remove the constructor of CharSourceRange that takes SourceRange;
And add a utility function at lexer that converts SourceRange to CharSourceRange.

Swift SVN r32023
2015-09-17 01:15:34 +00:00
Chris Willmore
4b8a5cf894 Lex single-quote string literals but emit an error if they're encountered.
Emit a fix-it replacing them with double-quote string literals.

<rdar://problem/21950709> QoI: Parse single-quoted literals like double-quoted literals

Swift SVN r31973
2015-09-15 22:24:18 +00:00
Chris Lattner
0001dc27bb remove support for the experiemental "character literals" feature.
Swift SVN r30509
2015-07-22 22:35:19 +00:00
Chris Lattner
5b49a63f46 Fix an egregious lack of QoI: <rdar://problem/16990885> support curly quotes for string literals
Swift SVN r28699
2015-05-18 05:59:43 +00:00
Chris Willmore
690daa539a Back out changes for in-place methods/operators from Xcode 7.
This reverts commits r26508, r26545, and r26576.

Swift SVN r26900
2015-04-02 21:14:28 +00:00
Chris Willmore
1ee6f7e67c Implement syntax changes for in-place methods.
Rename 'assignment' attribute of infix operators to 'mutating'. Add
'has_assignment' attribute, which results in an implicit declaration of
the assignment version of the same operator. Parse "func =foo"
declaration and "foo.=bar" expression. Validate some basic properties of
in-place methods.

Not yet implemented: automatic generation of wrapper for =foo() if foo()
is implemented, or vice versa; likewise for operators.

Swift SVN r26508
2015-03-25 00:22:41 +00:00
Chris Lattner
d15d544d87 make a (horrible) lexer diagnostic precise instead of leaving it to the user to figure out
whether it is unhappy about prefix or postfix.


Swift SVN r26407
2015-03-22 05:39:17 +00:00
Argyrios Kyrtzidis
a935e7c13e [Lexer] Recognize editor placeholders as identifiers and provide a specific error when encountered.
Swift SVN r26212
2015-03-17 01:52:59 +00:00
Chris Willmore
f723b05672 Don't remove 'with' from ObjC method arg name if resulting name is keyword.
Also, remove calls to isSwiftReservedName in
ClangImporter::Implementation::importName(), since 'true' and 'false'
are now keywords and rdar://problem/13187570 is no longer a problem.

rdar://problem/18797808

Swift SVN r23244
2014-11-11 19:34:53 +00:00
Doug Gregor
26816e2b8c QoI: Improve diagnostic for a missing required initializer with a Fix-It.
When a subclass is missing a required initializer, produce an error
within the subclass that mentions the required initializer along with
a Fix-It that provides an initializer stub, e.g.,

  required init(coder aDecoder: NSCoder!) {
      fatalError("init(coder:) has not been implemented")
  }

We take care to insert this stub in the main class, after all of the
initializers (if there are any) or near the beginning of the class (if
there aren't any initializers), and try to match the existing
indentation. If this works out, we should handle unsatisfied protocol
requirements the same way. <rdar://problem/17923210>

Swift SVN r21055
2014-08-06 00:33:54 +00:00
Argyrios Kyrtzidis
8eb7d43d32 [Parser] Introduce a convenience wrapper for Parser functionality.
This is useful when wanting to just do some syntactic parsing for a snippet of code.

Swift SVN r20174
2014-07-18 19:57:32 +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
Chris Lattner
287059b360 implement <rdar://problem/17279286> Swift has too many Unicode escape sequence forms
This consolidates the \x, \u, and \U escape sequences into one \u{abc} escape sequence.
For now we still parse and cleanly reject the old forms with a nice error message, this
will eventually be removed in a later beta (tracked by rdar://17527814)


Swift SVN r19435
2014-07-01 23:27:44 +00:00
Dmitri Hrybenko
6f03508f4a Fix a few issues with parsing bulid configuration directive
* replaced yet another variant of isWhitespace with the version from
  clang/Basic/CharInfo.h.  The major difference is that our variant used to
  consider '\0' whitespace.

* made sure that we don't construct StringRefs that point after the end of the
  buffer.  If the buffer ends with "#", then MemoryBuffer will only guarantee
  that there is one additional NUL character.  memcmp(), OTOH, is allowed to
  access the complete span of the provided memory.  I colud not actually get
  this to crash on OSX 10.10, but I do remember similar crashes we fixed in Clang.

* added checks to reject extra tokens at the end of the build configuration
  directive -- see tests, that code used to compile without diagnostics.  The
  lexer tried to do this, but in a self-referential way -- by checking the
  NextToken variable (which is actually the previous token, when viewed from
  the point of lexImpl()).  The checks I added are a little too strict, they
  reject comments at the end of the directive, but at least we don't accept
  strange constructs.  Allowing comments would not be hard, just requires
  factoring out lexer's routines to skip comments so that they accept a pointer
  to the buffer and return the comment end point.  Filed
    <rdar://problem/16301704> Allow comments at the end of bulid configuration directives
  for that.

Found by inspection... I was grepping the codebase for 'isWhitespace'.


Swift SVN r14959
2014-03-12 16:54:09 +00:00
Dmitri Hrybenko
f11c348362 Clarify how Lexer::isIdentifier() operates, in context of adding escaped
identifiers


Swift SVN r14781
2014-03-07 14:36:37 +00:00
Joe Groff
424187e482 Lexer: Lex escaped identifier tokens.
Lex a backtick-enclosed `[:identifier_start:][:identifier_cont:]+` as an identifier, even if it's a Swift keyword. For now, require that the escaped name still be a valid identifier, keyword collisions notwithstanding. (We could in theory allow an arbitrary string, but we'd have to invent a mangling for non-identifier characters and do other tooling which doesn't seem productive.)

Swift SVN r14671
2014-03-05 03:47:12 +00:00
Dmitri Hrybenko
3da05e347d Change property accessor syntax to include braces
See release notes update for details.

rdar://15966905


Swift SVN r14271
2014-02-22 21:00:56 +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
Dmitri Hrybenko
7d29d25b7d Fix include order
Swift SVN r13912
2014-02-14 16:37:03 +00:00
John McCall
10ac15ed0d Lex $notAllDigits as an identifier and diagnose it in the lexer
outside of debugger-support mode.  Rip out the existing special-case
code when parsing expr-identifier.

This means that the Lexer needs a LangOptions.  Doug and I
talked about just adding that as a field of SourceMgr, but
decided that it was worth it to preserve the possibility of
parsing different dialects in different source files.

By design, the lexer doesn't tokenize fundamentally differently
in different language modes; it might decide something is invalid,
or it might (eventually) use a different token kind for the
same consumed text, but we don't want it deciding to consume more or
less of the stream per token.

Note that SIL mode does make that kind of difference, and that
arguably means that various APIs for tokenizing need to take a
"is SIL mode" flag, but we're getting away with it because we
just don't really care about fidelity of SIL source files.

rdar://14899000

Swift SVN r13896
2014-02-14 01:54:17 +00:00
Argyrios Kyrtzidis
e244f51229 [Lexer] Add some const goodness to the SourceManager that the Lexer uses.
No functionality change.

Swift SVN r12182
2014-01-11 01:09:30 +00:00
Dmitri Hrybenko
81dc5deee8 Change 'def' keyword back to 'func'
Swift SVN r10522
2013-11-17 07:45:28 +00:00
Dmitri Hrybenko
91ce21666d Change 'func' keyword to 'def'
I tried hard find all references to 'func' in documentation, comments and
diagnostics, but I am sure that I missed a few.  If you find something, please
let me know.

rdar://15346654


Swift SVN r9886
2013-11-02 01:00:42 +00:00
Argyrios Kyrtzidis
61b4e8ede5 [Lexer] Add some comments for Lexer::getLocForStartOfToken().
Swift SVN r8288
2013-09-16 19:32:13 +00:00
Argyrios Kyrtzidis
5db368ce7b [Lexer] Introduce Lexer::getLocForStartOfToken() that returns the location at the start of the token that a given offset points to.
Swift SVN r8281
2013-09-16 18:41:16 +00:00
Dmitri Hrybenko
c98719dc03 Cleanup includes and forward declarations
Swift SVN r7194
2013-08-13 03:36:47 +00:00
Dmitri Hrybenko
dc655eb1cb Remove more abuse of SourceLoc::Value::getPointer()
Swift SVN r7109
2013-08-09 22:35:33 +00:00
Dmitri Hrybenko
db08a32a95 Factor out SourceManager::getLocOffsetInBuffer()
and remove some abuse of SourceLoc::Value::getPointer()


Swift SVN r7105
2013-08-09 21:53:32 +00:00
Dmitri Hrybenko
23b4e9fa86 Lexer: make some implementation details private
Swift SVN r7096
2013-08-09 20:21:29 +00:00
Dmitri Hrybenko
888d9b4e58 Tighten the contract of Lexer::getEncodedCharacterLiteral():
treat the token as a token (instead of a string) and check that it has the
correct kind


Swift SVN r7094
2013-08-09 20:15:37 +00:00
Dmitri Hrybenko
de59d8dcd4 Remove unneeded llvm:: qualifier for llvm::StringRef and llvm::SmallVector
Swift SVN r7089
2013-08-09 18:41:46 +00:00
Dmitri Hrybenko
d1453b3f9d Lexer constuctors: allow to create a lexer that scans a subrange without having
to create a parent lexer first.


Swift SVN r7085
2013-08-09 18:19:55 +00:00
Dmitri Hrybenko
49e15b33e7 Remove the public Lexer::getBufferEnd() function which breaks encapsulation
of the source buffer


Swift SVN r7084
2013-08-09 18:10:29 +00:00
Dmitri Hrybenko
987590ae8c Lexer: constify permanent configuration parameters
Swift SVN r7082
2013-08-09 17:50:13 +00:00
Dmitri Hrybenko
056923e802 Lexer constructors: inline Lexer::initLexer into the principal constructor.
Introducing it was just a refactoring step.


Swift SVN r7081
2013-08-09 17:46:31 +00:00
Dmitri Hrybenko
ea710cd62a Lexer constructors: simplify and establish an invariant:
Lexer::BufferID is the single point of truth, Lexer::BufferStart and
Lexer::BufferEnd is just a cache -- they always point to the beginning and end
of the buffer, even in a sublexer.


Swift SVN r7079
2013-08-09 17:40:17 +00:00
Dmitri Hrybenko
c92fd7cbdd Lexer: refactor constructors to bring the parameter count back to a sane number
Now we have a clear separation between a primary lexer, which scans the whole
buffer, and a sublexer, which can be created from a primary lexer to scan a
part of the buffer.


Swift SVN r7077
2013-08-09 02:06:50 +00:00
Dmitri Hrybenko
02cf73dc30 Lexer: remove redundant parameters from the sublexer constructor
Swift SVN r7073
2013-08-09 00:15:01 +00:00
Dmitri Hrybenko
e5923592e1 Refactor Lexer::State to store a SourceLoc intead of a pointer into the buffer
Swift SVN r7065
2013-08-08 23:51:03 +00:00
Argyrios Kyrtzidis
4908da8361 [Lexer] Remove the public Lexer constructor that accepts a StringRef.
Replace uses of it with the newly introduced constructor that accepts a buffer ID.
The StringRef constructor was rather unsafe since it had the implicit requirement that the StringRef
was null-terminated.

Swift SVN r6942
2013-08-06 14:59:03 +00:00
Argyrios Kyrtzidis
d6b048dfe0 [Lexer] Refactor lexing of interpolated strings.
Decouple splitting an interpolated string to segments, from encoding the string segments.
This allows us to tokenize or re-lex a string literal without having to allocate memory for
encoding the string segments when we don't need them encoded.

Swift SVN r6940
2013-08-06 14:59:01 +00:00