Commit Graph

309 Commits

Author SHA1 Message Date
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
d4db635e3d Add object literal syntax and _{Color,Image}LiteralConvertible protocols
Add syntax "[#Color(...)#]" for object literals, to be used by
Playgrounds for inline color wells etc. The arguments are forwarded to
the relevant constructor (although we will probably change this soon,
since (colorLiteralRed:... blue:... green:... alpha) is kind of
verbose). Add _ColorLiteralConvertible and _ImageLiteralConvertible
protocols, and link them to the new expressions in the type checker.
CSApply replaces the object literal expressions with a call to the
appropriate protocol witness.

Swift SVN r27479
2015-04-20 12:55:56 +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 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
Denis Vnukov
9e76e2ba50 Minor (swift migrator related fixes):
Corrected several places where compiler generated AST nodes were not properly 
marked as implicit.

For interpolated strings also fixed string segment locations and made sure 
the first and last segments are preserved in AST even if they are empty.



Swift SVN r25983
2015-03-11 18:08:36 +00:00
Argyrios Kyrtzidis
3e1390fe70 [LangOptions] Enable dollar identifiers under a separate language option.
I intend to use such identifiers for placeholder replacements.

Swift SVN r25896
2015-03-09 23:02:55 +00:00
Ben Langmuir
ef071c3cdc Update for LLVM API change r228930
CountPopulation_{32,64} => countPopulation
Count{Trailing,Leading}Ones_{32,64} => count{Trailing,Leading}Ones

Swift SVN r25239
2015-02-12 16:46:14 +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
Justin Bogner
59bb06b0fb InstrProf: SIL-level coverage mapping and lowering to LLVM
The adds the sil_coveragemap construct to SIL and the needed IRGen to
turn these into LLVM's coverage maps.

Swift SVN r25210
2015-02-12 00:28:39 +00:00
Manman Ren
16cc4dfa65 Revert r23713
Swift SVN r23739
2014-12-05 18:41:27 +00:00
Manman Ren
d0068877f5 [PGO] Add SILMetadata for branch weights.
SILMetadata is the base class with a single enum member (MDKind).
SILBranchNode is the derived class with additional members:
  unsigned NumOperands
  an array of uint32_t

A static member function SILBranchNode::get is implemented to get or create
SILBranchNode. All SILMetadata created are uniqued and saved in SILModule's
member variable:
  llvm::FoldingSet<SILMetadata> Metadatas

Usage of SILMetadta by SILInstruction is captured in SILModule's member variable:
  llvm::DenseMap<const SILInstruction *, SILMetadata *> MetadataStore
This is similar to LLVM's Metadata. Another option is to add a SILMetadata* to
SILInstruction. The disadvantage is the waste of space when we don't have PGO on.

This commit also enables parsing and printing of SILMetadata.

We add keyword sil_metadata to define SILMetadata:
  sil_metadata !0 = {"branch_weights", 3, 5}

For parsing, we add a map in SILModule
  llvm::DenseMap<unsigned, SILMetadata *> NumberedMetadata
that maps from ID to SILMetadata* to help matching usage of "!id" in SILFunction
with definition of "!id" in sil_metadata section.

For printing, we assign IDs to SILMetadata at SILModule scope, we then pass in
an optional argument of
  llvm::DenseMap<const SILMetadata *, unsigned> *MetadataMap
to SILFunction::print in order to get the ID of SILMetadata used in
SILInstruction.

Post-commit review will be appreciated.

rdar://18269754


Swift SVN r23713
2014-12-05 01:47:11 +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
Joe Groff
e102c521cc Improve parsing of '>>?!>?' jumbles in type context.
Use the same token-splitting technique we use to interpret '>>>' as a series of closing angle brackets to also extract '?' and '!' IUO sigils. Tweak it so that we properly reset the lexer state instead of just peeking the next token, because otherwise, when we chop a token like '>?>>', we'll see only the '?' (because '?' by itself is a question_postfix) and drop the '>>' on the floor. Remove the lexer hacks that pattern-matched specific >?>? sequences.

Swift SVN r22669
2014-10-10 17:41:03 +00:00
Manman Ren
bbe9479565 [Parser] parsing A<C, B<V>?>?.
This extends a workaround that handles A<C, B<V>?> to further handle
A<C, B<V>?>?. If we return ">?>?" as a single token, consumingStartingGreater
consumes ">", returns a token for "?" and silently drops the other characters.

The workaround is to return ">?" as a token when we see ">?>?".


Swift SVN r22585
2014-10-08 00:17:40 +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
Manman Ren
ebf7db3c97 [Parser] parsing "<a, b<c>?>" as the generic arguments.
Also enable parsing of operator name "??" in sil mode.


Swift SVN r21150
2014-08-12 17:14:22 +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
Chris Lattner
d7bcbc3817 make ? a general operator character, allowing user defined operators like ??=. We already
reserve ? itself as a special token that cannot be defined (protecting ternary, postfix ?, 
etc) but add some defensive code to prevent people from defining those operators.

<rdar://problem/17923322> allow ? as a general operator character



Swift SVN r21051
2014-08-05 23:06:29 +00:00
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