Commit Graph

588 Commits

Author SHA1 Message Date
Joe Groff
0ea3dbc652 Lex '??' as an operator.
Change the lexing of '?' to be similar to '!', where we special-case the postfix case for the intrinsic postfix optional operator, but fall back to lexing as an operator when it isn't left-bound. For now, only accept '??' as an operator name--we could easily generalize this, but that warrants discussion first.

Swift SVN r20591
2014-07-26 19:48:42 +00:00
Chris Lattner
017c281f0d resolve <rdar://problem/17527814> remove old unicode escape parsing logic from beta 5
Swift SVN r20106
2014-07-17 18:26:39 +00:00
Chris Lattner
ef2608284d Add fixit hint to migrate code from the old unicode escapes to the new one:
swift x.swift
x.swift:3:15: error: unicode escapes changed, please use the \u{42} syntax instead
var x = "foo \x42 \u1234 \U12345678"
              ^~~~
              u{42}
x.swift:3:20: error: unicode escapes changed, please use the \u{1234} syntax instead
var x = "foo \x42 \u1234 \U12345678"
                   ^~~~~~
                   u{1234}
x.swift:3:27: error: unicode escapes changed, please use the \u{12345678} syntax instead
var x = "foo \x42 \u1234 \U12345678"
                          ^~~~~~~~~~
                          u{12345678}

No testcase since this is all temporary anyway.



Swift SVN r19449
2014-07-02 04:57:09 +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
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
f370ca0746 stdlib: fix a bunch of various Unicode issues, primarily in UTF-8 decoding
In UTF-8 decoder:
- implement U+FFFD insertion according to the recommendation given in the
  Unicode spec.  This required changing the decoder to become stateful, which
  significantly increased complexity due to the need to maintain an internal
  buffer.
- reject invalid code unit sequences properly instead of crashing rdar://16767868
- reject overlong sequences rdar://16767911

In stdlib:
- change APIs that assume that UTF decoding can never fail to account for
  possibility of errors
- fix a bug in UnicodeScalarView that could cause a crash during backward
  iteration if U+8000 is present in the string
- allow noncharacters in UnicodeScalar.  They are explicitly allowed in the
  definition of "Unicode scalar" in the specification.  Disallowing noncharacters
  in UnicodeScalar prevents actually using these scalar values as internal
  special values during string processing, which is exactly the reason why they
  are reserved in the first place.
- fix a crash in String.fromCString() that could happen if it was passed a null
  pointer

In Lexer:
- allow noncharacters in string literals.  These Unicode scalar values are not
  allowed to be exchanged externally, but it is totally reasonable to have them
  in literals as long as they don't escape the program.  For example, using
  U+FFFF as a delimiter and then calling str.split("\uffff") is completely
  reasonable.

This is a lot of changes in a single commit; the primary reason why they are
lumped together is the need to change stdlib APIs to account for the
possibility of UTF decoding failure, and this has long-reaching effects
throughout stdlib where these APIs are used.


Swift SVN r19045
2014-06-20 13:07:40 +00:00
Chris Lattner
64ac997c8b parse ..< as an operator, this will be extensively tested shortly.
Swift SVN r18997
2014-06-19 05:24:01 +00:00
Jordan Rose
574054b8fd Distance SourceManager from llvm::SourceMgr.
...in preparation for non-source locations, i.e. locations that don't come
frome source buffers.

No functionality change, but a fair bit of SourceManager API and idioms have
changed.

Swift SVN r18942
2014-06-17 01:15:47 +00:00
Joe Groff
b51b1f0cfd "invalid unicode code point" -> "invalid unicode scalar"
We reject surrogates in strings and characters, which are valid code points, but not valid Unicode scalars.

Swift SVN r18467
2014-05-20 21:21:38 +00:00
Ted Kremenek
7da31bdfdd Disable parsing of single quoted character literals, enabling under a flag.
I didn't want to rip this logic out wholesale.  There is a possibility
the character lexing can be reborn/revisited later, and
disabling it in the parser was easy.

Swift SVN r18102
2014-05-15 07:05:59 +00:00
Doug Gregor
c41f0e01ce Make # a real punctuator.
Swift SVN r17980
2014-05-13 00:03:01 +00:00
Doug Gregor
2872287dcd Add support for marking function arguments with the back-tick ("`").
Part of <rdar://problem/16742001>. At the moment, this is just a
parsing thing, because argument names are still API by default
anyway.

Swift SVN r16991
2014-04-28 19:35:57 +00:00
Doug Gregor
ab6b22fc75 When not used for an escaped identifier, back-tick is a token.
First part of <rdar://problem/16742001>.

Swift SVN r16990
2014-04-28 19:35:56 +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
Chris Lattner
fb56affff7 remove the highly controversial "newline at end of file" warning.
Swift SVN r16463
2014-04-17 21:26:18 +00:00
Manman Ren
9ce381f1fc SILParser: a decl in witness table can be from other modules.
Also fix operator as part of a SILDeclRef e.g "Equatable.==!".

rdar://16503632


Swift SVN r15951
2014-04-04 20:04:49 +00:00
Joe Pamer
7b771affd9 Add limited build configuration support for testing against compiler submit versions. (rdar://problem/16337966)
This is meant to be utilized for a narrow set of scenarios specific to dogfooding our pre-1.0 compiler, so please do not take any dependencies on this.  In fact, I'll be removing this in the next milestone.  (See rdar://problem/16380797.)

Also included - improve error recovery when parsing broken build configuration clauses.

Swift SVN r15694
2014-03-31 20:34:02 +00:00
Argyrios Kyrtzidis
d6698f3f32 [Parser] Skip form feed and vertical tab characters as whitespace.
Swift SVN r15555
2014-03-27 06:55:37 +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
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 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
Chris Lattner
c437dcbf06 remove 'val' compatibility support.
Swift SVN r14543
2014-03-01 00:11:09 +00:00
Dmitri Hrybenko
65cf5f2098 Lexer: compute ArtificialEOF correctly in a sublexer of a sublexer
This fixes code completion crash in rdar://15561934, but there are still no
code completion results in interpolated string literals.


Swift SVN r14539
2014-02-28 23:03:06 +00:00
Dmitri Hrybenko
d681b81641 Revert my r14516, it breaks the buildbot
Swift SVN r14518
2014-02-28 15:28:39 +00:00
Dmitri Hrybenko
3bb9166405 Lexer: don't advance current pointer past end of the source buffer in case
there is a string literal with embedded NUL just before EOF

This used to crash, rdar://15561934


Swift SVN r14516
2014-02-28 14:28:25 +00:00
Joe Pamer
535cb4667c Minor code cleanup for the build configuration implementation.
Swift SVN r14475
2014-02-27 21:19:03 +00:00
Chris Lattner
c16db63ae7 switch "val" to "let" in in the ASTPrinter, unbreaking tests.
Produce a warning + fixit for uses of 'val'.


Swift SVN r14435
2014-02-27 00:32:17 +00:00
Chris Lattner
aa5a42cb95 accept 'let' as an alias for 'val' this week, and release note it.
Swift SVN r14376
2014-02-26 04:40:34 +00:00
Joe Pamer
988a5877f2 Some updates:
- Respond to Doug's code review feedback
   - Stop hacking around with scopes and use "emplace" to work around RAII in the inactive config case
   - Limit use of StringRef on the front-end, in favor of std::string
   - Use ArrayRef rather than SmallVector within IfConfigDecl
   - Reorder new property declarations on BraceStmt to prevent unnecessary alignment issues
- Update ParseBraceItems to better capture top-level declarations, rather than using token lookahead

Swift SVN r14306
2014-02-24 18:16:49 +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
6871e96df7 Lexer: don't use locale-dependent ctype.h functions
The dependency on Clang is unfortunate here, hopefully these functions will be
moved to LLVM.


Swift SVN r14288
2014-02-23 18:47:15 +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
Chris Lattner
3404f27237 remove 'let' from the parser.
Swift SVN r13995
2014-02-17 16:56:54 +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
Chris Lattner
6072e1d40d parse the 'val' keyword. For now it is a synonym for let. I will rip
'let' out (and continue migrating terminology in the compiler) as an
ongoing project.


Swift SVN r13821
2014-02-12 06:29:15 +00:00
Dave Zarzycki
5556d24f3a Parser: Remove "too many '.'s" error
This only made sense when '...' was reserved. In other words, if we
allow '..' and '...' as formal operators, then why not '....'?

Swift SVN r13673
2014-02-08 02:15:17 +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
Manman Ren
729d30fb54 SILParser: first step towards parsing sil_witness_table.
Only one entry kind out of four is supported right now.


Swift SVN r12936
2014-01-24 21:58:45 +00:00
Jordan Rose
5bbdb23910 Fix up "invalid UTF-8" error, and add a test case.
Swift SVN r12447
2014-01-17 01:08:32 +00:00
Jordan Rose
11008f0ed1 Split diagnostics out into separate files.
Thanks to the way we've set up our diagnostics engine, there's not actually
a reason for /everything/ to get rebuilt when /one/ diagnostic changes.
I've split them up into five categories for now: Parse, Sema, SIL, IRGen,
and Frontend, plus a set of "Common" diagnostics that are used in multiple
areas of the compiler. We can massage this later.

No functionality change, but should speed up compile times!

Swift SVN r12438
2014-01-17 00:15:12 +00:00
Dave Zarzycki
adf26ccd2a 15836688 Fail gracefully on UTF-16 input files
Swift SVN r12420
2014-01-16 21:34:55 +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
1363140c81 Correct assertion message
Swift SVN r10869
2013-12-05 18:30:38 +00:00
Dave Abrahams
7ab9d369aa [stdlib] Rename Char => UnicodeScalar
Swift SVN r10864
2013-12-05 17:30:37 +00:00
Manman Ren
05899b7a8d SILParser: parse sil_global and sil_global_addr.
rdar://15493552


Swift SVN r10823
2013-12-05 00:46:40 +00:00
Chris Lattner
ef93c81ffb Introduce a new SIL-level "undef" value, useful for SIL transformations.
IRGen support is missing, Joe volenteers to implement it.


Swift SVN r9776
2013-10-30 00:58:09 +00:00
Dmitri Hrybenko
882b770983 Portability: replace isnumber() with isdigit()
Swift SVN r9578
2013-10-22 05:05:21 +00:00
Manman Ren
d503c65036 SILParser: parse sil_vtable
rdar://15165644


Swift SVN r9342
2013-10-15 00:52:40 +00:00
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