Commit Graph

118 Commits

Author SHA1 Message Date
Hamish Knight
628dcd6eb1 [Parse] Improve diagnostic for no platform condition argument
Drop the "only one" in the message in this case,
as that should only apply for too many args.
2021-09-24 16:38:30 +01:00
Hamish Knight
e3257fd0fa [Parse] Fix empty platform condition crash
Handle the empty argument case in `getSingleSubExp`,
otherwise we'd crash with an index out of bounds.

rdar://83017601
2021-09-24 16:38:29 +01:00
Hamish Knight
a5775482ee [Parser] Adopt ArgumentList
Split up the expr list parsing members such that
there are separate entry points for tuple and
argument list parsing, and start using the argument
list parsing member for call and subscripts.
2021-09-01 18:40:24 +01:00
Hamish Knight
46fa6e5721 [AST] Improve BinaryExpr
Abstract away the TupleExpr gunk and expose
`getLHS` and `getRHS` accessors. This is in
preparation for completely expunging the use
of TupleExpr as an argument list.
2021-05-19 14:48:01 +01:00
Xi Ge
ebfa459b3e CanImport: allow using string literal to indicate desired version 2021-05-17 11:10:41 -07:00
Xi Ge
c446253075 Use underscored syntax for versioned canImport condition 2021-05-04 19:59:57 -07:00
Xi Ge
bbe5b83de9 Parser: teach canImport to take an additional parameter indicating the minimum module version
canImport should be able to take an additional parameter labeled by either version or
underlyingVersion. We need underlyingVersion for clang modules with Swift overlays because they
have separate version numbers. The library users are usually interested in checking the importability
of the underlying clang module instead of its Swift overlay.

Part of rdar://73992299
2021-05-02 17:47:44 -07:00
Rintaro Ishizaki
ce87bf7537 [Parse] Postfix '#if' expression
Implement postfix ifconfig expression which expands '#if' functionality
to postfix member reference expressions.

rdar://problem/51690082
2021-04-29 09:12:23 -07:00
Doug Gregor
fd16deecba Introduce checking for language features via "#if $FeatureName"
Introduce some basic support for defining specific language features
that can be checked by name, e.g.,

    #if $AsyncAwait
    // use the feature
    #endif

For backward compatibility with older compilers, to actually prevent
the parser from parsing, one will have to do a Swift compiler version
check, even though the version number doesn't matter. For example:

    #if compiler(>=5.3) && $AsyncAwait
    // use the feature
    #endif
2021-02-05 15:22:02 -08:00
Robert Widmann
73ac8d3531 Replace llvm::MD5 with StableHasher 2021-01-21 17:19:38 -08:00
Kk Shinkai
d2bbdb8743 Fix a misspelling 2021-01-03 17:28:27 +08:00
Slava Pestov
1a6f86be71 Parse: Use InInactiveClauseEnvironment instead of looking at the Scope
We have two ways of knowing if we're inside of an inactive #if clause.
Refactor the only two places that called getScopeInfo().isInactiveConfigBlock()
to check InInactiveClauseEnvironment instead.

This removes the last remaining usage of Scope that's not related to
parse-time name lookup.
2020-11-16 15:35:55 -05:00
Rintaro Ishizaki
6cfdaf662d [CodeCompletion] Reduce backtracking for searching CC token in IfConfig 2020-08-14 11:15:18 -07:00
Rintaro Ishizaki
dd6046ba16 [CodeCompletion] Stop recording interface hash when searching CC token 2020-08-14 10:33:53 -07:00
Rintaro Ishizaki
22c157f159 [CodeCompletion] Parse #if block containing CC token as active
rdar://problem/67027408
2020-08-14 10:33:53 -07:00
Hamish Knight
f57299a587 Formalize some SourceFile parsing outputs
Currently when parsing a SourceFile, the parser
gets handed pointers so that it can write the
interface hash and collected tokens directly into
the file. It can also call `setSyntaxRoot` at
the end of parsing to set the syntax tree.

In preparation for the removal of
`performParseOnly`, this commit formalizes these
values as outputs of `ParseSourceFileRequest`,
ensuring that the file gets parsed when the
interface hash, collected tokens, or syntax tree
is queried.
2020-06-03 11:03:56 -07:00
Rintaro Ishizaki
ec0c9484ab [CodeCompletion] Inherit options when parsing new buffer
for fast completions. Options may affect the parsing result.
Also, don't collect interface hash tokens inside inactive blocks.
2020-05-12 15:43:24 -07:00
Kuba (Brecka) Mracek
0d400ca310 Merge branch 'master' into mracek/arm64e 2020-03-04 09:36:25 -08:00
Kuba (Brecka) Mracek
5d918e5ee1 Merge branch 'master' into mracek/arm64e 2020-03-03 08:28:01 -08:00
Hamish Knight
f56b061407 [Parse] Check the SourceFile for #if evaluation
Remove the `EvaluateConditionals` flags from the
parser, and instead query the source file.

This commit also changes ParserUnit such that it
doesn't evaluate #if conditions by default, as
none of its clients appear to require it. The
only client that wasn't explicitly disabling #if
evaluation and is processing the resulting AST is
swift-indent, so this commit also adds a test to
ensure it continues to work correctly with #if
decls.
2020-03-02 14:12:37 -08:00
Hamish Knight
0d5a5e12d5 Move #if evaluation flag out of PersistentParserState
Move this flag onto the parser instead. Now the
only client of PersistentParserState is code
completion.
2020-02-28 10:51:12 -08:00
Kuba Mracek
84c4864911 [arm64e] Add Swift compiler support for arm64e pointer authentication 2020-02-27 16:10:31 -08:00
Devin Coughlin
8c5c5ec802 [Parse] Support macCatalyst conditional compilation
Add support for conditional compilation under macCatalyst

Developers can now detect whether they are compiling for macCatalyst at
compile time with:

  #if targetEnvironment(macCatalyst)
    // Code only compiled under macCatalyst.
  #end
2020-01-21 18:28:17 -08:00
David Ungar
2e8920ba64 Don't addUnvalidatedDeclWithOpaqueResultType when inside of an inactive clause environment. 2019-10-16 22:23:36 -07:00
Rintaro Ishizaki
8a03e08966 Revert "Merge pull request #26403 from rintaro/gsoc-2019-part1"
This reverts commit 1a211e6e5f, reversing
changes made to 482d0621a6.
2019-10-14 15:18:05 -07:00
Sasha Krassovsky
037f168126 Fix warnings in Parse 2019-09-13 09:57:48 -07:00
Roopesh Chander
b75711c2d2 Make a .def file for PlatformConditionKind 2019-08-21 19:52:00 +00:00
Roopesh Chander
34fec7f1d4 [Parser][QoI] Offer fixit for changing the platform condition kind
For example, for "#if os(simulator)", offer a fixit to change
"os" to "targetEnvironment", instead of offering to change "simulator".

Resolves SR-11037.
2019-08-21 19:51:47 +00:00
Jan Svoboda
f0395a469a Revert "Revert "[Parser] Decouple the parser from AST creation (part 1)"" 2019-07-30 04:34:09 +00:00
Brent Royal-Gordon
c66a8be4eb Revert "[Parser] Decouple the parser from AST creation (part 1)" 2019-07-09 14:07:43 -07:00
Jan Svoboda
44d7769238 [Parser] Decouple the parser from AST creation (part 1)
Instead of creating the AST directly in the parser (and libSyntax or
SwiftSyntax via SyntaxParsingContext), make Parser to explicitly create
a tree of ParsedSyntaxNodes. Their OpaqueSyntaxNodes can be either
libSyntax or SwiftSyntax. If AST is needed, it can be generated from the
libSyntax tree.
2019-06-28 14:28:19 +02:00
Rintaro Ishizaki
7b37072adf [Parse] Don't evaluate IfConfig condtion inside inactive block
rdar://problem/50903021
2019-06-19 09:39:54 -07:00
Rintaro Ishizaki
6c0806419f Merge pull request #25008 from owenv/improved_#else_if_diagnostic
[Parse] Improve diagnostic and add fixit to correct '#else if' to '#elseif'
2019-05-24 09:38:12 -07:00
Owen Voorhees
901d947478 Improve diagnostic and add fixit to correct '#else if' to 'elseif'
Resolves SR-10581
2019-05-23 19:34:21 -07:00
Xi Ge
f25925fc84 Parser: suppress diagnostics when parsing inside inactive code 2019-05-17 12:36:34 -07:00
Xi Ge
c8dd6a9ba1 Parser: avoid skipping inactive code if we are building syntax trees.
If syntax trees are requested, we shouldn't skip inactive code. Notice the
inactive code won't be skipped in SwiftSyntax because we always set
PerformConditionEvaluation false for the in-process parser.

This is mostly needed for testing purposes where we add -verify-syntax-tree
to regular compiler invocations.

rdar://50837165
2019-05-17 12:32:10 -07:00
Jordan Rose
ceaa5db623 Merge pull request #17960 from danielmartin/new-unary-operator-ifconfig
[Parser] Support "<" unary operator in #if swift() and #if compiler() expressions
2018-09-26 15:00:48 -07:00
Rintaro Ishizaki
deb4aa84e0 [CodeCompletion] Add completion for platform condition
* 'true'/'false' keyword
* 'os(<name>)', 'canImport(<module>)' etc.
* Custom flags specified with '-D'

rdar://problem/19572779
2018-08-24 12:24:54 +09:00
Daniel Martín
e66095b10a [Parser] Support "<" unary operator in #if swift() expressions
Until now, only ">=" was supported in #if swift() expressions, for example:

```#if swift(>=2.1)
```#endif

This means that if we want to evaluate code only when the language version is
less than a particular version we need to do the following:

```#if !swift(>=2.1)
```#endif

An alernative to make this more readable (the "!" can be easily missed in a code
review) is to introduce another supported unary operator, "<". The previous
example could be rewritten like this:

```#if swift(<2.1)
```#endif

This commit adds support for that unary operator, along with some tests.
2018-08-02 20:35:58 +02:00
Rintaro Ishizaki
2946597362 [Parse] Drop Swift3 support for conditional compilation condition
In Swift3:
* `#if A is B` were warning
* `#if A(foo:)` were warning
* `#if A || B && C` has different meaning from Swift4+ and was diagnosed with
  migration support fix-it.
2018-07-07 23:27:31 +09:00
David Hart
2abb931d4e Reuse code between swift and compiler directives 2018-06-01 22:15:09 +02:00
David Hart
ff0156c1fa Replace _compiler_version with a new directive 2018-06-01 07:20:32 +02:00
Rintaro Ishizaki
fc3cbcda88 [Syntax] Redesign IfConfigDecl syntax 2018-04-03 01:31:33 +09: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
Xi Ge
df7db884cf libSyntax: create syntax nodes for IfConfigDecl. 2017-12-15 13:36:47 -08:00
Graydon Hoare
dd81583b1a [Parse] Fix a couple typos in PR #12964 2017-11-29 11:27:21 -08:00
Graydon Hoare
d31bad45b8 [Parse] Add fixit for targetEnvironment(simulator) 2017-11-28 13:51:01 -08:00
Graydon Hoare
3807b3fa1e [Parse] Add platform conditional targetEnvironment(simulator) 2017-11-28 13:51:01 -08:00
Xi Ge
87ce54e3f2 Re-apply "Paser: IfConfigDecl should reflect the underlying source. rdar://34315827" 2017-09-12 12:59:25 -07:00
Xi Ge
2a07534bc1 Revert "Paser: IfConfigDecl should reflect the underlying source. rdar://34315827"
For test failure witnessed in bots: https://ci.swift.org/job/oss-swift-incremental-RA-osx/462/
2017-09-12 12:49:02 -07:00