734 Commits

Author SHA1 Message Date
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
Xi Ge
844aeae2d5 Re-apply "libSyntax: create a basic infrastructure for generating libSyntax entities by using Parser." (#12538) 2017-10-20 22:58:28 -07:00
Greg Parker
48a6b9d464 Revert "libSyntax: create a basic infrastructure for generating libSyntax entities by using Parser."
This reverts commit ee7a06276d.
It causes build failures like "'swift/Syntax/SyntaxNodes.h' file not found".
2017-10-19 17:11:48 -07:00
Xi Ge
ee7a06276d libSyntax: create a basic infrastructure for generating libSyntax entities by using Parser. 2017-10-18 17:02:00 -07:00
Xi Ge
5626c72718 Refactoring tool: Avoid re-tokenizing when collecting the available refactorings in a given source range. NFC (#11857) 2017-09-11 15:45:26 -07:00
Xi Ge
34e2aec662 Parser: use parser to generate a refined token stream to help syntax coloring. (#11809)
This patch allows Parser to generate a refined token stream to satisfy tooling's need. For syntax coloring, token stream from lexer is insufficient because (1) we have contextual keywords like get and set; (2) we may allow keywords to be used as argument labels and names; and (3) we need to split tokens like "==<". In this patch, these refinements are directly fulfilled through parsing without additional heuristics. The refined token vector is optionally saved in SourceFile instance.
2017-09-08 10:28:19 -07:00
Rintaro Ishizaki
546aeb2336 [Parse] Remove Parser support for C-style for statement. 2017-08-04 23:27:15 +09:00
Jordan Rose
b4759bc8e2 [Parse] Split ParseSIL out into its own library.
...finally breaking the dependency of Parse on Sema.

There are still some unfortunate dependencies here -- Xi's working on
getting /AST/ not dependent on Sema -- but this is a step forward.

It is a little strange that parseIntoSourceFile is in ParseSIL, and
therefore that that's still a dependency for anyone trying to, well,
parse. However, nearly all clients that parse want to type-check as
well, and that requires Sema, Serialization, and the ClangImporter...
and Serialization and SIL currently require each other as well
(another circular dependency). So it's not actively causing us trouble
right now.
2017-07-17 12:18:41 -06:00
Jordan Rose
e4794e87f8 [Parse] Simplify SILParserState and its use in Parser.
Preparation for separating ParseSIL out into its own library, but a
nice cleanup regardless.
2017-07-17 12:18:41 -06:00
Harlan
70089a7bcc [Syntax] Represent TokenSyntax as a Syntax node (#10606)
Previously, users of TokenSyntax would always deal with RC<TokenSyntax>
which is a subclass of RawSyntax. Instead, provide TokenSyntax as a
fully-realized Syntax node, that will always exist as a leaf in the
Syntax tree.

This hides the implementation detail of RawSyntax and SyntaxData
completely from clients of libSyntax, and paves the way for future
generation of Syntax nodes.
2017-06-27 11:08:10 -07:00
Alex Hoppen
2078ec6f0a Remove getName from ValueDecl
Push the getName method from ValueDecl down to only those types that are
guaranteed to have a name that is backed by an identifier and that will
not be special.
2017-06-15 21:49:34 +02:00
Alex Hoppen
de5000f9a6 [Parser] Preparations for removal of getName on ValueDecl
With the introduction of special decl names, `Identifier getName()` on
`ValueDecl` will be removed and pushed down to nominal declarations
whose name is guaranteed not to be special. Prepare for this by calling
to `DeclBaseName getBaseName()` instead where appropriate.
2017-05-28 19:13:24 -07:00
Rintaro Ishizaki
04f31a76c0 Merge pull request #7955 from rintaro/parse-ifconfig-validate
[Parse] Separate compilation condition validation and evaluation
2017-05-16 12:06:31 +09:00
Louis D'hauwe
a9e228b4e7 [Parser] Fix comment typo 2017-05-15 19:02:59 +02:00
Nathan Hawes
52374a9812 [parser] Account for the length of multine string quotes when tokenizing interpolated string components
This fixes a syntax coloring issue when only the innermost " character were highlighted as part of the string, e.g:

""<str>"
  This is a string
  "</str>""
2017-05-13 12:08:45 -07:00
David Farler
303a3e5824 Start the Migrator library
The Swift 4 Migrator is invoked through either the driver and frontend
with the -update-code flag.

The basic pipeline in the frontend is:

- Perform some list of syntactic fixes (there are currently none).
- Perform N rounds of sema fix-its on the primary input file, currently
  set to 7 based on prior migrator seasons.  Right now, this is just set
  to take any fix-it suggested by the compiler.
- Emit a replacement map file, a JSON file describing replacements to a
  file that Xcode knows how to understand.

Currently, the Migrator maintains a history of migration states along
the way for debugging purposes.

- Add -emit-remap frontend option
  This will indicate the EmitRemap frontend action.
- Don't fork to a separte swift-update binary.
  This is going to be a mode of the compiler, invoked by the same flags.
- Add -disable-migrator-fixits option
  Useful for debugging, this skips the phase in the Migrator that
  automatically applies fix-its suggested by the compiler.
- Add -emit-migrated-file-path option
  This is used for testing/debugging scenarios. This takes the final
  migration state's output text and writes it to the file specified
  by this option.
- Add -dump-migration-states-dir

  This dumps all of the migration states encountered during a migration
  run for a file to the given directory. For example, the compiler
  fix-it migration pass dumps the input file, the output file, and the
  remap file between the two.

  State output has the following naming convention:
  ${Index}-${MigrationPassName}-${What}.${extension}, such as:
  1-FixitMigrationState-Input.swift

rdar://problem/30926261
2017-04-17 16:25:02 -07:00
Rintaro Ishizaki
b56ab17fa5 [Parse] Separate compilation condition validation and evaluation
Fixes:
https://bugs.swift.org/browse/SR-3455
https://bugs.swift.org/browse/SR-3663
https://bugs.swift.org/browse/SR-4032
https://bugs.swift.org/browse/SR-4031

Now, compilation conditions are validated at first, then evaluated. Also,
in non-Swift3 mode, '&&' now has higher precedence than '||'.
'A || B && C || D' are evaluated as 'A || (B && C) || D'.

Swift3 source breaking changes:

* [SR-3663] This used to be accepted and evaluate to 'true' because of short
  circuit without any validation.

  #if true || true * 12 = try Anything is OK?
  print("foo")
  #endif

  In this change, remaining expressions are properly validated and
  diagnosed if it's invalid.

* [SR-4031] Compound name references are now diagnosed as errors.
  e.g. `#if os(foo:bar:)(macOS)` or `#if FLAG(x:y:)`

Swift3 compatibility:

* [SR-3663] The precedence of '||' and '&&' are still the same and the
  following code evaluates to 'true'.

  #if false || true && false
  print("foo")
  #endif
2017-03-23 01:25:29 +09:00
Michael Gottesman
cfb5893663 [silgen] Fix destroying destructor to use proper ownership with its @owned return value.
rdar://29791263
2017-03-02 17:17:17 -08:00
David Farler
7ee42994c8 Start the Syntax library and optional full token lexing
Add an option to the lexer to go back and get a list of "full"
tokens, which include their leading and trailing trivia, which
we can index into from SourceLocs in the current AST.

This starts the Syntax sublibrary, which will support structured
editing APIs. Some skeleton support and basic implementations are
in place for types and generics in the grammar. Yes, it's slightly
redundant with what we have right now. lib/AST conflates syntax
and semantics in the same place(s); this is a first step in changing
that to separate the two concepts for clarity and also to get closer
to incremental parsing and type-checking. The goal is to eventually
extract all of the syntactic information from lib/AST and change that
to be more of a semantic/symbolic model.

Stub out a Semantics manager. This ought to eventually be used as a hub
for encapsulating lazily computed semantic information for syntax nodes.
For the time being, it can serve as a temporary place for mapping from
Syntax nodes to semantically full lib/AST nodes.

This is still in a molten state - don't get too close, wear appropriate
proximity suits, etc.
2017-02-17 12:57:04 -08:00
Hugh Bellamy
f001b7562b Use relatively new LLVM_FALLLTHROUGH instead of our own SWIFT_FALLTHROUGH 2017-02-12 10:47:03 +07:00
Rintaro Ishizaki
ff826e3491 [Parse] Limit max nesting level of StructureMarkerRAII (#7330)
The threshold is 256, for now.
2017-02-09 15:04:09 +09:00
Rintaro Ishizaki
9b4f549943 [Parse] Improve diagnostics for consecutive identifiers 2017-01-26 15:37:19 +09:00
Matthew Carroll
93a7a9f80d [DiagnosticsQoI] SR-3599: Better recovery for decls with consecutive identifiers
Add diagnostics to fix decls with consecutive identifiers. This applies to
types, properties, variables, and enum cases. The diagnostic adds a camel-cased option if it is different than the first option.

https://bugs.swift.org/browse/SR-3599
2017-01-19 23:44:33 -05:00
Rintaro Ishizaki
c92dbe5319 [Parse] Remove declaration list specific logic from parseList() 2017-01-17 17:19:36 +09:00
Brian Gesiak
663b92ece9 [AST] Completely replace Module with ModuleDecl
The typedef `swift::Module` was a temporary solution that allowed
`swift::Module` to be renamed to `swift::ModuleDecl` without requiring
every single callsite to be modified.

Modify all the callsites, and get rid of the typedef.
2017-01-08 00:36:08 -05:00
Robert Widmann
0febbf0b72 Effectively revert #5778
This reverts the contents of #5778 and replaces it with a far simpler
implementation of condition resolution along with canImport.  When
combined with the optimizations in #6279 we get the best of both worlds
with a performance win and a simpler implementation.
2017-01-06 16:16:39 -07:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +01:00
Robert Widmann
cededef0d6 Add condition resolution as a new phrase post-parse
An unfortunately necessary thing to delay defrosting function bodies as
long as we can.
2016-12-14 15:39:19 -05:00
Robert Widmann
a060eb5aca [SE-0075] Transfer the power of config resolution to Namebinding
This completely removes Parse’s ability to make any judgement calls
about compilation conditions, instead the parser-relevant parts of
‘evaluateConditionalCompilationExpr’ have been moved into
‘classifyConditionalCompilationExpr’ where they exist to make sure only
decls that we want to parse actually parse later.

The condition-evaluation parts have been moved into NameBinding in the
form of a Walker that evaluates and collapses IfConfigs.  This walker
is meant as an homage to PlaygroundLogger.  It should probably be
factored out into a common walker at some point in the future.
2016-12-14 14:59:47 -05:00
Michael Gottesman
59c6a64f5a [gardening] 0 => nullptr. Fixed with clang-tidy. 2016-12-06 23:14:13 -08:00
swift-ci
1e4bf0f2d3 Merge pull request #5909 from rintaro/parse-reject-throws-identifier 2016-11-23 19:08:03 -08:00
Rintaro Ishizaki
a1760161c5 [Parse] Don't parse 'throws' or 'rethrows' as identifiers
It seems there is no reason to accept them.
Why we want to accept `class C<throws> { ... }`?
2016-11-24 10:55:24 +09:00
Slava Pestov
02ad3cccef Merge pull request #5879 from apple/diag-split-tokens
[Lexer] Don’t suppress diagnostics when splitting a token
2016-11-23 18:25:17 -05:00
Jacob Bandes-Storch
f02e4ac2bf [Lexer] Don’t suppress diagnostics when splitting a token 2016-11-21 22:32:26 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00