Commit Graph

719 Commits

Author SHA1 Message Date
Jordan Rose
fc9ea1e329 Add Lexer::IsHashbangAllowed, drop SourceManager::getHashbangBufferID (#18534)
Having this be a single buffer hardcoded in the SourceManager and set
by all clients is silly. SourceFiles with the 'Main' kind are allowed
to have hashbang lines (`#!`), other files are not. And anyone
manually setting up a Lexer can decide for themselves.

No intended behavioral change.
2018-08-07 08:25:05 -07:00
Rintaro Ishizaki
1aacb8fefb Merge pull request #17788 from rintaro/parse-identifier-drop3
[Parse] Drop Swift3 support for '$', 'throws', and 'rethrows' as identifier
2018-07-25 19:36:39 +09:00
Alex Hoppen
fcc5a6b424 [libSyntax] Enable incremental parsing for syntax tree based syntax coloring 2018-07-17 14:17:58 -07:00
Rintaro Ishizaki
abc44ef44c [Parse] Drop Swift3 support for 'throws', 'rethrows' as identifier
Swift3 used to parse 'throws' and 'rethrows' as identififers.

Related a1760161c5
2018-07-06 17:59:23 +09:00
John Holdsworth
14213b84bd Revised implementation for raw strings 2018-07-02 12:54:06 +01:00
Robert Widmann
dfe42d2e55 Revert "Reject bad string interpolations (#17074)"
This reverts commit fc23f3404d.
2018-06-13 15:06:33 -07:00
Brent Royal-Gordon
fc23f3404d Reject bad string interpolations (#17074)
* Reject bad string interpolations

String interpolations with multiple comma-separate expressions or argument labels were being incorrectly accepted.

* Tweak error name to match message

* Diagnose empty interpolations more clearly

* Don’t double-diagnose parse errors

Fixes a test at Parse/recovery.swift:799 which the previous commit broke.

* Fix incorrect test RUN: line

A previous version of this test used FileCheck instead of -verify, and the run line wasn’t properly corrected to use -verify.

* Update comment

* Add more argument label tests

Ensures that we don’t get different results from an initializer that doesn’t exist or doesn’t take a String.

* Resolve the SR-7958 crasher test

We now diagnose the error and remove the label before it has an opportunity to crash.
2018-06-12 18:46:52 -07:00
Alex Hoppen
8c9e2e07ec [incParse] Make the SytnaxParsingCache operate on the leading trivia's start 2018-05-22 08:52:35 -07:00
Alex Hoppen
de9737c946 [incrParse] Support incremental parsing for edited files 2018-05-22 08:52:33 -07:00
Slava Pestov
8bf90f21d4 AST: Remove unneeded isDefinition and needsCapture methods from ValueDecl 2018-05-13 22:42:47 -07:00
David Zarzycki
f0c106c0e3 [AST] NFC: Avoid pointer indirection with ASTContext Impl storage
Most of this change is mechanical: `Impl` -> `getImpl()`.
2018-05-10 05:50:56 -04:00
Huon Wilson
0de6c9ee6b [Parse] std::function -> llvm::function_ref for some non-escaping params. 2018-05-01 08:29:06 +10:00
Slava Pestov
175b40919f AST: Fewer headers include Expr.h, Module.h, Stmt.h 2018-04-26 22:55:26 -07:00
Rintaro Ishizaki
6b2fb84cc7 [Parse] Remove dead code (#15723)
LeadingTrivia.empty() does nothing.
It was meant to be clear(), but clear() is also meaningless because
'LeadingTrivia' is immediately overwritten.
2018-04-04 11:25:57 +09:00
Slava Pestov
34fd4ae512 AST: Use DeclBaseName::Kind::Constructor
Fixes <rdar://problem/35852727>, <https://bugs.swift.org/browse/SR-1660>,
<https://bugs.swift.org/browse/SR-6557>.
2018-03-16 00:25:56 -07:00
omochimetaru
d12542503f [Syntax] test diagnostics in Lexer with libSyntax (#14954) 2018-03-04 08:53:54 +09:00
Xi Ge
37f352fe41 sourcekitd: build Swift syntax tree more lazily than collecting parsed tokens. (#14578)
Before this patch, we have one flag (KeepSyntaxInfo) to turn on two syntax
functionalities of parser: (1) collecting parsed tokens for coloring and
(2) building syntax trees. Since sourcekitd is the only consumer of either of these
functionalities, sourcekitd by default always enables such flag.
However, empirical results show (2) is both heavier and less-frequently
needed than (1). Therefore, separating the flag to two flags makes more
sense, where CollectParsedToken controls (1) and BuildSyntaxTree
controls (2).

CollectingParsedToken is always enabled by sourcekitd because
formatting and syntax-coloring need it; however BuildSyntaxTree should
be explicitly switched on by sourcekitd clients.

resolves: rdar://problem/37483076
2018-02-13 16:27:12 -08:00
Rintaro Ishizaki
2134f9f768 [Parse] Move SyntaxParsingContext to Parse (#14360)
This is only for the Parser.
Also, this resolves layering violation where libAST and libSyntax
depends on each other.
2018-02-03 10:43:52 +09:00
Rintaro Ishizaki
057254dbc1 [Syntax] Bump allocate and cache/reuse RawSyntax
Introduced SyntaxArena for managing memory and cache.

SyntaxArena holds BumpPtrAllocator as a allocation storage.
RawSyntax is now able to be constructed with normal heap allocation, or
by SyntaxArena. RawSyntax has ManualMemory flag which indicates it's managed by
SyntaxArena. If the flag is true, its Retain()/Release() is no-op thus it's
never destructed by IntrusiveRefCntPtr.
This speedups the memory allocation for RawSyntax.

Also, in Syntax parsing, "token" RawSyntax is reused if:
a) It's not string literal with >16 length; and
b) It doesn't contain random text trivia (e.g. comment).
This reduces the overall allocation cost.
2018-02-02 01:27:06 +09:00
Rintaro Ishizaki
0780c529c4 [Syntax] Unify RawSyntax and RawTokenSyntax using union and TrailingObjects
It better matches with SwiftSyntax model.

Using TrailingObjects reduces the number of heap allocation which
gains 18% performance improvement.
2018-01-18 14:49:46 +09:00
Xi Ge
71af76a87e libSyntax: optionally emit diagnostics for unknown expressions and declarations. (#13973)
With more syntax nodes being specialized, we'd like this
straight-forward way to pinpoint unknown entities. This diagnostics
is only issued in -emit-syntax frontend action and swift-syntax-test
invocation.
2018-01-16 16:14:57 -08:00
Slava Pestov
a293790e7d Fix a few unused variable warnings 2018-01-14 21:39:53 -08:00
John McCall
7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
Xi Ge
2833fc165d libSyntax: some refactoring on syntax parsing context. NFC
This allows the root context to have a separate place to keep track of
the global data that each sub-context can access to, for instance,
SourceFile, DiagnosticEngine, etc.
2018-01-11 13:13:13 -08:00
Xi Ge
22ce6934bd libSyntax: parse string interpolation expression. (#13708)
A string interpolation expression is composed of { OpenQuote, Segments,
CloseQuote }. To represent OpenQuote, CloseQuote and StringSegment, we have to
introduce new token kinds correspondingly.
2018-01-03 20:41:34 -08:00
omochimetaru
461c764734 [Parse] make tokenizeXxx into common 2018-01-03 10:58:16 -08:00
Rintaro Ishizaki
01f42c89d3 Merge pull request #13631 from omochi/lex-escape-backtick
[Parse] Lexer build backtick trivia around espaced identifier token
2017-12-29 12:36:00 +09:00
omochimetaru
bc88330740 [Parse] Lexer build backtick trivia around espaced identifier token 2017-12-29 00:22:49 +09:00
Rintaro Ishizaki
ed91d507d1 [Syntax] Handle EOF token at parseTopLevel()
instead of the destructor of Parser.
Destructor is not for this kind of tearDown work.
2017-12-26 13:35:12 +09:00
Rintaro Ishizaki
a1340fd9a2 [Syntax] Parse tuple pattern node 2017-12-20 17:32:30 +09:00
Rintaro Ishizaki
ef29650acd [Syntax] Parse: add support for TupleType and FunctionType
For now using SyntaxParsingContext.
2017-12-14 14:55:27 +09:00
Rintaro Ishizaki
60bfa893b9 [Parse] Make PersistentParserState to hold ParserPosition
instead of PersistentParserState::ParserPos.
2017-12-09 13:58:50 +09:00
Xi Ge
1b24d23c1e libSyntax: support function parameter nodes. (#13324) 2017-12-07 14:09:17 -08:00
Rintaro Ishizaki
c0ceb7a943 [Parse] Simplify parsing name for function declarations (#13141) 2017-12-05 02:04:01 +09:00
Rintaro Ishizaki
d1b0d137da [Parse] Set appropriate token kind when consumeStartingCharacterOfCurrentToken() 2017-11-29 09:37:22 +09:00
Xi Ge
036321546b libSyntax: Support tuple expression.
Tuple expression essentially has the same underlying structure as
function call arguments in libSyntax. However, we separate them as
different libSyntax kinds for better usability.

Different from AST, libSyntax currently allows single-child,
label-free tuple expressions (represented as ParenExpr in AST). This is
subject to change if we need to adopt the same differentiation in
libSyntax in the future.
2017-11-27 16:40:30 -08:00
Rintaro Ishizaki
0a401b381c [Syntax] Rewrite SyntaxParsingContext
Read RawSyntaxToken along with Parser::consumeToken()

* Single Lexer pass
* Backtracking support
* Split token support
2017-11-18 15:35:46 +09:00
Rintaro Ishizaki
a78fda0720 [Syntax] Always lex Trivia when SF.shouldKeepSyntaxInfo()
For backward compatibility, Don't lex comments as trailing trivias.
2017-11-17 14:56:49 +09:00
Rintaro Ishizaki
40b195d98c [Syntax] Get rid of fullLex
Defer (Token, Trivia) -> RawTokenSyntax conversion from Lexer to Parser.
This is a part of effort for consolidating Syntax and AST parsing.
2017-11-17 14:56:49 +09:00
Xi Ge
f69bc0eb14 libSyntax: various non-functional enhancements. NFC (#12842)
Avoid heap-allocated memory for syntax parsing context.
Add more assertions to ensure syntax nodes are created only at the top of context stack.
Allow syntax parsing context to delay the specifying of context kind and target syntax kind.
2017-11-09 15:59:25 -08:00
Xi Ge
0d9745f6eb libSyntax: teach parser to parse dictionary and array literals. (#12821)
This commit also adds ArrayExpr and DictionaryExpr to the libSyntax nodes
family. Also, it refactors the original parser code for these two
expressions to better fit to the design of SyntaxParsingContext.

This commit has also fixed two crashers.
2017-11-09 09:00:43 -08:00
Xi Ge
0390d452a6 libSyntax: parse function argument syntax node. (#12803)
This commit teaches parser to parse two libSyntax nodes: FunctionCallArgument and
FunctionCallArgumentList. Along with the change, some libSyntax parsing infrastructure changes
as well: (1) parser doesn't directly insert token into the buffer for libSyntax node creation;
instead, when creating a simple libSyntax node like integer literal expression, parser should indicate the location of the last token in the node; (2) implicit libSyntax nodes like empty
statement list must contain a source location indicating where the implicit nodes should appear
(immediately before the token at the given location).
2017-11-07 15:59:00 -08:00
Xi Ge
a448a7371f libSyntax: parse codeblock syntax node. (#12771)
This commit teaches parser to generate code block syntax node. As a support for this, 
SyntaxParsingContext can be created by a single syntax kind, indicating the whole context 
should be parsed into a node of that given syntax. Another change is to bridge created syntax 
node with the given context kind. For instance, if a statement context results into an expression 
node, the expression node will be bridged to a statement by wrapping it with a ExpressionStmt 
node.
2017-11-05 17:37:59 -08:00
Xi Ge
6af5d3c0bf libSyntax: rename KeepTokensInSourceFile to KeepSyntaxInfoInSourceFile. 2017-11-03 18:39:01 -07:00
Xi Ge
75db3c1db8 Re-apply libSyntax patches after fixing ASAN issue (#12730)
* Re-apply "libSyntax: Ensure round-trip printing when we build syntax tree from parser incrementally. (#12709)"

* Re-apply "libSyntax: Root parsing context should hold a reference to the current token in the parser, NFC."

* Re-apply "libSyntax: avoid copying token text when lexing token syntax nodes, NFC. (#12723)"

* Actually fix the container-overflow issue.
2017-11-03 13:25:33 -07:00
Xi Ge
7ebf66ed2d libSyntax: forward declare libSyntax entities in several header files, NFC. (#12735) 2017-11-02 20:55:18 -07:00
Xi Ge
4d1249aa82 Revert "libSyntax: Ensure round-trip printing when we build syntax tree from parser incrementally. (#12709)"
This reverts commit 0d98c4c5df.
2017-11-02 14:44:26 -07:00
Xi Ge
cabb6dd063 Revert "libSyntax: Root parsing context should hold a reference to the current token in the parser, NFC."
This reverts commit 19caca7890.
2017-11-02 14:44:10 -07:00
Xi Ge
19caca7890 libSyntax: Root parsing context should hold a reference to the current token in the parser, NFC.
Since all parsing contexts need a reference to the current token of the
parser, we should pass the token reference to the root context. Therefore, the derived
sub-contexts can just copy it while being spawned.
2017-11-02 12:31:45 -07:00
Xi Ge
0d98c4c5df libSyntax: Ensure round-trip printing when we build syntax tree from parser incrementally. (#12709) 2017-11-01 20:29:30 -07:00