589 Commits

Author SHA1 Message Date
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
Ben Langmuir
7eaed61b6f [CodeCompletion] Fix completion after unspaced binary operator
We were miscalculating 'isRightBound' when the RHS was a code-completion
token leading to missing completions in unspaced binary expressions
  1+<here>
  1...<here>

rdar://problem/24278699
2016-02-03 18:46:15 -08:00
Doug Gregor
dccf3155f1 SE-0022: Implement parsing, AST, and semantic analysis for #selector. 2016-01-26 21:12:04 -08:00
Trent Nadeau
e983501bfd Don't error when lexing UTF-8 BOM 2016-01-26 05:49:39 +00:00
Anton Blanchard
baf0a4b004 [Parser] Missed signed cast of CurPtr
A char is unsigned by default on PowerPC. CurPtr is cast
to a signed char whenever a signed comparison is required,
but we are missing one place.

This fixes a testcase failure in Parse/BOM.swift
2016-01-18 05:52:14 +00:00
Chris Lattner
8d81349fe1 fix rdar://24029542 "Postfix '.' is reserved" error message" isn't helpful
This adds some heuristics so we can emit a fixit to remove extraneous
whitespace after a . and diagnose the case where a member just hasn't
been written yet better.  This also improves handling of tok::unknown
throughout the parser a bit.

This is a re-commit of ff4ea54 with an update for a SourceKit test.
2016-01-11 15:11:20 -08:00
Erik Eckstein
acc243a002 Revert "fix rdar://24029542 "Postfix '.' is reserved" error message" isn't helpful"
It's probably the cause for the fail of SourceKit/SyntaxMapData/syntaxmap-edit-del.swift

This reverts commit ff4ea54614.
2016-01-11 10:43:39 -08:00
Chris Lattner
ff4ea54614 fix rdar://24029542 "Postfix '.' is reserved" error message" isn't helpful
This adds some heuristics so we can emit a fixit to remove extraneous
whitespace after a . and diagnose the case where a member just hasn't
been written yet better.  This also improves handling of tok::unknown
throughout the parser a bit.
2016-01-10 15:28:03 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Chris Lattner
0bfacde242 Fix: <rdar://problem/16230507> Cannot use a negative constant as the second operator of ... operator
This is a case that the operator splitting code didn't handle because of
the bizarre lexer code for handling operators with periods in them.  We had
accreted some weird special case logic for what is valid in an operator
(but which even had a special case hack for ..<).  The policy is now very
simple: if an operator name starts with a dot, it is allowed to include other
dots in its name.  If it doesn't, it doesn't.  This allows us to get lexer
level operator splitting in cases like x=.Foo, allowing our existing operator
set that have dots in them without hacks, and provides a superior QoI
experience due to operator splitting.

This is technically a language change, but the TSPL operator grammar was
incorrect for it anyway.  I will file an internal radar to get TSPL updated
with the actual behavior (now that it is defensible).
2015-12-16 22:16:19 -08:00
Chris Lattner
a8b87f167f fix a regression that e28c2e2 introduced in IDE/coloring.swift. 2015-12-16 14:33:03 -08:00
Chris Lattner
d5934da6e3 QoI: improve the error message for when whitespace is inconsistent on either
side of the = to say that, instead of talking about prefix/postfix = operators,
which are "not a thing".
2015-12-16 14:27:17 -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
Chris Willmore
c99c02b5a6 Transform EditorPlaceholderExpr into trap if executed in playground
mode (take 2)

Allow untyped placeholder to take arbitrary type, but default to Void.
Add _undefined<T>() function, which is like fatalError() but has
arbitrary return type. In playground mode, merely warn about outstanding
placeholders instead of erroring out, and transform placeholders into
calls to _undefined(). This way, code with outstanding placeholders will
only crash when it attempts to evaluate such placeholders.

When generating constraints for an iterated sequence of type T, emit

    T convertible to $T1
    $T1 conforms to SequenceType

instead of

    T convertible to SequenceType

This ensures that an untyped placeholder in for-each sequence position
doesn't get inferred to have type SequenceType. (The conversion is still
necessary because the sequence may have IUO type.) The new constraint
system precipitates changes in CSSimplify and CSDiag, and ends up fixing
18741539 along the way.

(NOTE: There is a small regression in diagnosis of issues like the
following:

    class C {}
    class D: C {}
    func f(a: [C]!) { for _: D in a {} }

It complains that [C]! doesn't conform to SequenceType when it should be
complaining that C is not convertible to D.)

<rdar://problem/21167372>

(Originally Swift SVN r31481)
2015-12-10 22:05:16 -08:00
Frederick Kellison-Linn
0bfba2972e Fix lexer to properly handle single quote strings
Lexer now suggests escaping unescaped double quotes and unescaping escaped single quotes in single quote strings..
2015-12-09 20:09:04 -05:00
Dmitri Hrybenko
2e51d23875 Un-ifdef object literals
Swift SVN r32880
2015-10-25 07:50:53 +00:00
David Farler
7fceb124ba Look for EOF in addition to whitespace to lex the #endif token
In addition to just a whitespace char, also look ahead to a null
character to lex the #endif token.  This allows the token to be formed
when at the end of a file.

Fix endif-on-end-of-file.swift test file to not end in whitespace.

rdar://problem/21692337

Swift SVN r32224
2015-09-25 07:28:32 +00:00
Chris Lattner
92fc60f619 fix rdar://22387625 QoI: Common errors: 'let x= 5' and 'let x =5' could use Fix-its
Swift SVN r32004
2015-09-16 20:12:14 +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 Willmore
9c1f3e907a Revert "Transform EditorPlaceholderExpr into trap if executed in playground mode."
This reverts commit r31481, which apparently needed some parallel
changes to SourceKit and broke the build as a result.

Swift SVN r31483
2015-08-26 05:28:04 +00:00
Chris Willmore
0addd80bb3 Transform EditorPlaceholderExpr into trap if executed in playground mode.
Allow untyped placeholder to take arbitrary type, but default to Void.
Add _undefined<T>() function, which is like fatalError() but has
arbitrary return type. In playground mode, merely warn about outstanding
placeholders instead of erroring out, and transform placeholders into
calls to _undefined(). This way, code with outstanding placeholders will
only crash when it attempts to evaluate such placeholders.

<rdar://problem/21167372> transform EditorPlaceholderExpr into fatalError()

Swift SVN r31481
2015-08-26 04:50:55 +00:00
Chris Willmore
265f91fead Allow string literals in string literal interpolation.
Teach skipToEndOfInterpolatedExpression() to match quote marks as well
as parentheses in the interpolated expression. This makes expressions
like "hello \(names["bob"])" possible.

Swift SVN r31283
2015-08-18 00:41:01 +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
9757294002 [Lex] Use clang::isIdentifierBody instead of checking for '_' separately.
Also, use 'isHexDigit' instead of the built-in 'isxdigit' for consistency,
even though 'isxdigit' is locale-independent.

No intended functionality change.

Swift SVN r31139
2015-08-11 18:29:35 +00:00
Jordan Rose
8a9a238cc8 [SIL] Allow all ASCII identifier characters in SIL variable names.
For better test cases. The comment even made it look like this was
intended at one point.

('$' is not an identifier character.)

Swift SVN r31136
2015-08-11 17:56:55 +00:00
Jordan Rose
953424072e Guard "object literals" feature with SWIFT_ENABLE_OBJECT_LITERALS.
This is not a feature we're releasing at the moment, so provide a way
to turn it off.

rdar://problem/21935551

Swift SVN r30966
2015-08-04 00:16:52 +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
Chris Lattner
84787421c5 fix <rdar://problem/21196171> compiler should recover better from "unicode Specials" characters
There are a few changes here:
 - Exclude the "unicode specials" block (http://en.wikipedia.org/wiki/Specials_(Unicode_block))
   from being considered part of the valid identifier characters.
 - Have the compiler produce a fixit hint that replaces invalid UTF8 codepoints and invalid
   characters in general with whitespace with a blank space.
 - When the lexer sees an invalid character like this at the start of a token, rescan for the
   next token, improving error recovery, instead of returning tok::invalid.
 - Fix the order that diagnostics are generated in the curly quoted string case to report the
   end quote last.  This interacts better with Xcode's fixit hints, because just fixing the last
   quote allows the compiler to detect that remaining problem, but fixing the first quote hides
   the second one with our current implementation.



Swift SVN r29222
2015-06-02 04:18:34 +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
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