589 Commits

Author SHA1 Message Date
Doug Gregor
611a5cce4b Replace the library-defined postfix '!' with an expr-postfix production.
As with the monadic '?', we treat any left-bound '!' as a postfix
operator. Currently, it extracts the value of its optional
subexpression, failing at run-time if the optional is empty.


Swift SVN r8948
2013-10-06 23:09:58 +00:00
Joe Groff
2728b7d23c Improve lexer error for multiple-Unicode-scalar "character" literals.
Swift SVN r8945
2013-10-05 22:22:24 +00:00
Chris Lattner
af509afe67 make '@' be a valid token, even when not in sil mode. No functionality change.
Swift SVN r8898
2013-10-04 00:18:51 +00:00
John McCall
298577676e Introduce the monadic ? operator.
A ? operator is interpreted as this if it's left-bound,
so ternary operators now have to be spaced on the left.

Swift SVN r8832
2013-10-02 01:27:45 +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
Jordan Rose
d40f74f2c1 [Parse] Treat ! as a postfix operator when both left- and right-bound.
For most operators, an expression like "a@b" is lexed with '@' as a binary
operation on 'a' and 'b'. However, we want to make sure we can support
calling optional functions using the syntax "a!()". Consequently, if there
are no spaces around a single '!' token, it is treated as a postfix operator
instead of an infix operator. The infix interpretation can still be requested
by using spaces on both sides of the operator.

Swift SVN r7651
2013-08-28 00:18:19 +00:00
Dmitri Hrybenko
8a8b97985b Lexer: fix a bug where restoring lexer state could produce duplicate
code_complete tokens


Swift SVN r7636
2013-08-27 22:34:29 +00:00
Jordan Rose
a62cfd3c30 [Parse] Parse the '@' in "x@.y" as a postfix op.
...but make sure plain "@.y" still parses as a prefix op.

This allows our planned postfix ! operator for Optional types to parse
correctly when a member is accessed. There's probably still QoI work here:
the following member may have been intended to be a free member as in
"x @ .y", where '@' is a binary operator.

Swift SVN r7513
2013-08-23 19:03:30 +00:00
Dmitri Hrybenko
dc439adb59 Lexer: improve recovery for invalid character literals and invalid escape
sequences in charater literals

Now we return tok::character_literal with REPLACEMENT CHARACTER U+FFFD instead
of tok::unknown.


Swift SVN r7475
2013-08-22 20:56:47 +00:00
Dmitri Hrybenko
3bee330e50 Lexer: don't inf loop on an unterminated string literal near EOF
Swift SVN r7474
2013-08-22 20:40:34 +00:00
Dmitri Hrybenko
39d40c54dd Lexer: don't emit a diagnostic if it was not requested
Swift SVN r7472
2013-08-22 19:05:19 +00:00
Dmitri Hrybenko
c4775b8287 Lexer: unterminated/invalid character literals: recover by skipping to a single
quote, newline, or EOF, whichever is first


Swift SVN r7470
2013-08-22 18:51:17 +00:00
Dmitri Hrybenko
4ba6197a9c Lexer: add a specific diagnostic "unterminated character literal" instead of a
generic one "invalid character literal"


Swift SVN r7467
2013-08-22 18:36:04 +00:00
Dmitri Hrybenko
4536a90421 Lexer: fix a crash on an unterminated character literal starting right before EOF
Swift SVN r7463
2013-08-22 18:22:57 +00:00
Dmitri Hrybenko
c98719dc03 Cleanup includes and forward declarations
Swift SVN r7194
2013-08-13 03:36:47 +00:00
Dmitri Hrybenko
70f2b64ad9 Add CharSourceRange -- a half-open character range, which will be used in IDE
integration

Motivation: libIDE clients should be simple, and they should not have to
translate token-based SourceRanges to character locations.

This also allows us to remove the dependency of DiagnosticConsumer on the
Lexer.  Now the DiagnosticEngine translates the diagnostics to CharSourceRanges
and passes character-based ranges to the DiagnosticConsumer.


Swift SVN r7173
2013-08-12 20:15:51 +00:00
Dmitri Hrybenko
13070a31bd SourceManager: make findBufferContainingLoc() always succeed.
Every valid source location corresponds to a source buffer.  There should be no
cases where we create a source location for a random string.  Thus,
findBufferContainingLoc() always succeeds.


Swift SVN r7120
2013-08-10 01:48:04 +00:00
Dmitri Hrybenko
8f7a437d44 Wrap a few functions from LLVM SourceMgr in preparation of making
SourceLoc::Value private


Swift SVN r7114
2013-08-09 23:15:59 +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
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
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
8c15b7d1cf Lexer constructors: remove redundant code: Lexer::initLexer will query the
SourceManager and set the code completion point correctly, no need to do this
elsewhere.


Swift SVN r7080
2013-08-09 17:41:55 +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
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
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
Argyrios Kyrtzidis
cda7a109bd [Lexer] Remove the special hack in the Lexer that handles lexing an expression in an interpolated string.
-Parse the expression using a begin/end state sub-Lexer instead of a general StringRef Lexer
-Introduce a Lexer constructor accepting a BufferID and a range inside the buffer, and use it for swift::tokenize.

Swift SVN r6938
2013-08-06 14:58:59 +00:00
Argyrios Kyrtzidis
f875f05a30 [Lexer] When encountering invalid characters, emit diagnostic and ignore them.
...instead of returning tok::unknown, which may confuse the Parser and cause it to crash with llvm::unreachable.
By ignoring them we reduce the complexity in the Parser by not having it worry about tok::unknown.

Swift SVN r6910
2013-08-05 18:29:14 +00:00
Dmitri Hrybenko
7684d6dc2a Add a good diagnostic for a hashbang line when it is not allowed
Also centralizes the knowledge about whether the hashbang is allowed in the
SourceManager.  This fixes a bug in tokenize() because previously it just had
to guess.


Swift SVN r6822
2013-08-01 23:07:43 +00:00
Dmitri Hrybenko
5cea4ebf41 Code completion: put CodeCompletionOffset on SourceManager instead of passing
around everywhere

Fixes:
rdar://14585108 Code completion does not work at the beginning of the file
rdar://14592634 Code completion returns zero results at EOF in a function
                without a closing brace


Swift SVN r6820
2013-08-01 22:08:58 +00:00
Dmitri Hrybenko
e1c4ae3174 Wrap llvm::SourceMgr in swift::SourceManager so that we can add new members
to the source manager.


Swift SVN r6815
2013-08-01 20:39:22 +00:00
Dmitri Hrybenko
015cea67a5 Move hashbang line detection to the Lexer implementation, instead of requiring
the Lexer client to skip it before constructing the Lexer.


Swift SVN r6801
2013-08-01 02:18:25 +00:00
Joe Groff
ba774364f1 SIL: Have SILModules track their SILStage.
Modules can be in either 'Raw' or 'Canonical' form, with different invariants on each. We don't actually distinguish those invariants yet, but this patch adds the field to SILModule and adds a "sil_stage" declaration to SIL printer/parser syntax.

Swift SVN r6793
2013-08-01 00:58:31 +00:00
Joe Groff
69d3392191 Accept underscore separators in numeric literals.
This makes long literals like 1_000_000_000 or 0x7FFF_FFFF_FFFF_FFFF much easier to read, and has precedent in Perl, OCaml, Python, Ruby, Rust, ... Fixes <rdar://problem/14247571>.

Swift SVN r6681
2013-07-28 18:56:30 +00:00
Dmitri Hrybenko
c2e05bfcb9 REPL: use new code completion engine from libIDE
Swift SVN r6641
2013-07-26 04:05:28 +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
1f3c026202 Relax the assertion in Lexer to allow it to save state at tok::eof.
This enables us to do code completion at EOF.


Swift SVN r6639
2013-07-26 01:54:54 +00:00
Dmitri Hrybenko
f9fa6aa8fc Code completion: insert a zero character into the buffer to mark the code
completion token

This is required to handle cases like fooObject.#^A^#.bar where code completion
is invoked inside the ".." token.  Previously, the token would not be split and
the lexer would produce an incorrect tokenization for this case.  Now we
produce ".", tok::code_complete, ".".


Swift SVN r6635
2013-07-26 00:45:57 +00:00
Dmitri Hrybenko
464df1cc11 Lexer: make tok::eof length equal to 0
It used to be equal to 1, which makes Lexer::getLocForEndOfToken() return
an out-of-bounds location for tok::eof.


Swift SVN r6626
2013-07-26 00:14:09 +00:00
Chris Lattner
1433bd7287 fix pasto
Swift SVN r6582
2013-07-25 03:31:27 +00:00
Argyrios Kyrtzidis
66d1e516c8 Refactor how multiple parsing passes and delayed parsing works.
-Introduce PersistentParserState to represent state persistent among multiple parsing passes.
  The advantage is that PersistentParserState is independent of a particular Parser or Lexer object.
-Use PersistentParserState to keep information about delayed function body parsing and eliminate parser-specific
  state from the AST (ParserTokenRange).
-Introduce DelayedParsingCallbacks to abstract out of the parser the logic about which functions should be delayed
  or skipped.

Many thanks to Dmitri for his valuable feedback!

Swift SVN r6580
2013-07-25 01:40:16 +00:00
Chris Lattner
7e985f1336 Fix the lexer to produce an error in every case it produces a tok::unknown token,
it was silently swallowing # and @.  This fixes rdar://14418336


Swift SVN r6446
2013-07-22 14:48:09 +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
Chris Lattner
063b1dad66 Apply Manman's patch to add lexer support for SIL # and ! tokens.
Swift SVN r6046
2013-07-08 15:09:08 +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
Argyrios Kyrtzidis
fe8d9bba2f [Lexer] Make the order of parameters of the protected constructor significantly different than the public one.
This is to make overload resolution for the protected constructor call sites more explicit.
Otherwise, adding a parameter in the protected constructor and a default parameter in the public one
can inadvertently result in the protected constructor call sites switching to picking the public one.

Swift SVN r6007
2013-07-05 15:02:41 +00:00
Dmitri Hrybenko
03074dceb2 StringLiteralExpr: always include a good source range
When we are interpreting escape sequences in the lexer, we copy the string
literal bytes to ASTContext instead of storing a pointer to the source buffer.
But then we used to try to get a source location for that string in the heap,
which is not a valid source buffer. It succeeds during parsing, but breaks
when we try to print a diagnostic using this location.

Added a verifier check for this.

Also added a real source range for StringLiteralExpr, instead of a source range
with begin == end, produced from the beginning location.


Swift SVN r5961
2013-07-02 17:19:27 +00:00