Commit Graph

727 Commits

Author SHA1 Message Date
Doug Gregor
57b2146c0b Remove the separated call syntax.
We had our transition path, and now it's time to kill it because it's
causing problems <rdar://problem/16672558>.

Amusing note: the SILGen test change is actually an improvement. We
weren't rebinding self when performing initializer delegation with the
separated call syntax.

Swift SVN r16707
2014-04-23 18:20:34 +00:00
Chris Lattner
b204be71cd simplify Parser::isStartOfStmt: just use the current token instead of having
all of the clients pass in the current token.  NFC.


Swift SVN r16601
2014-04-21 04:01:03 +00:00
Manman Ren
1b8087cf5d [SILParser] Handle overloaded members for protocol_method and dynamic_method.
We print the AST type for the member when printing SILDeclRef for
protocol_method and dynamic_method. The AST type can be polymorphic, so parsing
of PolymorphicFunctionType is added to the Parser. Also add parsing "inout"
right before an identifier type. "inout" was parsed only in parseTypeTupleBody.

rdar://15763213


Swift SVN r16460
2014-04-17 17:56:57 +00:00
Dmitri Hrybenko
f90e0c153b Make 'override' a keyword
rdar://16462192

Swift SVN r16115
2014-04-09 14:19:50 +00:00
Doug Gregor
6da952e798 Parse the new function syntax.
Parse the new function syntax, which allows both the argument (API)
and parameter (internal) name to be specified prior to the colon
within each parameter. Don't re-use the existing pattern-parsing
logic. Rather, implement a new (far simpler) parser for this purpose,
then map from its simple data structures to ArgParams and BodyParams
as we're used to.

There are a number of caveats here:
  - We no longer have the ability to use patterns for parameters in
  function declarations. The only place this really has an impact is
  that it makes the ~> hack in the standard library even uglier.
  - This exposed some issues with code completion with generic
  parameters that need to be investigated.
  - There's still some work to be done to improve recovery when things
  parse poorly within a parameter list; there are some XFAILs to deal
  with that.

I'll address the last two issues with follow-up commits.

Swift SVN r15967
2014-04-05 00:21:06 +00:00
Chris Lattner
30863729a0 remove parser support for DynamicSelf. The world should have switched
by now and it is in my way.  The internal compiler nomenclature still 
needs to be updated, Doug can handle that best.


Swift SVN r14604
2014-03-03 19:07:15 +00:00
Joe Pamer
a0c57f496d Improve error recover for parsing build configuration blocks. Specifically, improve diagnostics for when users try to use #if/#else/#endif blocks in ways that would break brace statement or member list parsing. (Like if they were trying to emulate the C preprocessor.)
Swift SVN r14369
2014-02-26 02:06:29 +00:00
Joe Pamer
cc91b28076 If a target configuration invocation is followed by an indented identifier on a new line, the target invocation expression may be parsed as having a trailing closure. Add a new StructureMarkerKind so we can prevent this from happening.
Swift SVN r14368
2014-02-26 02:06:29 +00:00
Dmitri Hrybenko
5af5711ab7 Code completion: implement delayed parsing for accessor bodies, allowing code
completion inside computed properties.

Adding tests for willSet/didSet uncovered some crashes while doing code
completion (see FIXMEs), and I will investigate these next.

Partially addresses rdar://15849262


Swift SVN r14338
2014-02-25 16:51:07 +00:00
Dmitri Hrybenko
ecd798b9fd Comment parsing: attaching comments to declarations
We can attach comments to declarations.  Right now we only support comments
that precede the declarations (trailing comments will be supported later).

The implementation approach is different from one we have in Clang.  In Swift
the Lexer attaches the comments to the next token, and parser checks if
comments are present on the first token of the declaration.  This is much
cleaner, and faster than Clang's approach (where we perform a binary search on
source locations and do ad-hoc fixups afterwards).

The comment <-> decl correspondence is modeled as "virtual" attributes that can
not be spelled in the source.  These attributes are not serialized at the
moment -- this will be implemented later.


Swift SVN r14031
2014-02-18 09:04:37 +00:00
John McCall
10ac15ed0d Lex $notAllDigits as an identifier and diagnose it in the lexer
outside of debugger-support mode.  Rip out the existing special-case
code when parsing expr-identifier.

This means that the Lexer needs a LangOptions.  Doug and I
talked about just adding that as a field of SourceMgr, but
decided that it was worth it to preserve the possibility of
parsing different dialects in different source files.

By design, the lexer doesn't tokenize fundamentally differently
in different language modes; it might decide something is invalid,
or it might (eventually) use a different token kind for the
same consumed text, but we don't want it deciding to consume more or
less of the stream per token.

Note that SIL mode does make that kind of difference, and that
arguably means that various APIs for tokenizing need to take a
"is SIL mode" flag, but we're getting away with it because we
just don't really care about fidelity of SIL source files.

rdar://14899000

Swift SVN r13896
2014-02-14 01:54:17 +00:00
Doug Gregor
45ca5fe987 Use whitespace indentation to detect selector-style call continuations.
Implement several rules that determine when an identifier on a new
line is a continuation of a selector-style call on a previous line:

  - In certain contexts, such as parentheses or square brackets, it's
    always a continuation because one does not split statements in
    those contexts;

  - Otherwise, compare the leading whitespace on the line containing
    the nearest enclosing statement or declaration to the leading
    whitespace for the line containing the identifier.

The leading whitespace for a line is currently defined as all space
and tab characters from the start of the line up to the first
non-space, non-tab character. Leading whitespace is compared via a
string comparison, which eliminates any dependency on the width of a
tab. One can run into a few amusing cases where adjacent lines that
look indented (under some specific tab width) aren't actually indented
according to this rule because there are different mixes of tabs and
spaces in the two lines. See the bottom of call-suffix-indent.swift
for an example.

I had to adjust two test cases that had lines with slightly different
indentation. The diagnostics here are awful; I've made no attempt at
improving them.



Swift SVN r13843
2014-02-12 22:50:50 +00:00
Argyrios Kyrtzidis
8758451a43 [Parser/IDE] Introduce ide::isSourceInputComplete() which returns true if the input source is fully formed,
or false if, for example, a closing brace is missing.

This is useful for the REPL.
rdar://15948039

Swift SVN r13313
2014-02-02 03:14:33 +00:00
Doug Gregor
6f42f69876 Parse DynamicSelf as a type, restricted to contexts in which it is allowed.
Take DynamicSelf as a keyword, but parse it as a type-identifier.
Teach function declaration checking to sniff out and validate
DynamicSelf early, with appropriate QoI for references to DynamicSelf
that appear in other places.

As a temporary hack, DynamicSelf resolves to an alias for 'Self' in a
protocol or the enclosing nominal type.

Swift SVN r12708
2014-01-22 05:54:11 +00:00
Jordan Rose
11008f0ed1 Split diagnostics out into separate files.
Thanks to the way we've set up our diagnostics engine, there's not actually
a reason for /everything/ to get rebuilt when /one/ diagnostic changes.
I've split them up into five categories for now: Parse, Sema, SIL, IRGen,
and Frontend, plus a set of "Common" diagnostics that are used in multiple
areas of the compiler. We can massage this later.

No functionality change, but should speed up compile times!

Swift SVN r12438
2014-01-17 00:15:12 +00:00
Argyrios Kyrtzidis
e244f51229 [Lexer] Add some const goodness to the SourceManager that the Lexer uses.
No functionality change.

Swift SVN r12182
2014-01-11 01:09:30 +00:00
Chris Lattner
6a8b1a40ef rename Parser::parseMatchingPatternIsa -> parseMatchingPatternIs
and Parser::parseMatchingPatternVar -> parseMatchingPatternVarOrLet

to better reflect what they are.


Swift SVN r11744
2013-12-30 21:17:42 +00:00
Jordan Rose
417b5d3982 Merge TranslationUnit into Module, and eliminate the term "translation unit".
This completes the FileUnit refactoring. A module consists of multiple
FileUnits, which provide decls from various file-like sources. I say
"file-like" because the Builtin module is implemented with a single
BuiltinUnit, and imported Clang modules are just a single FileUnit source
within a module.

Most modules, therefore, contain a single file unit; only the main module
will contain multiple source files (and eventually partial AST files).

The term "translation unit" has been scrubbed from the project. To refer
to the context of declarations outside of any other declarations, use
"top-level" or "module scope". To refer to a .swift file or its DeclContext,
use "source file". To refer to a single unit of compilation, use "module",
since the model is that an entire module will be compiled with a single
driver call. (It will still be possible to compile a single source file
through the direct-to-frontend interface, but only in the context of the
whole module.)

Swift SVN r10837
2013-12-05 01:51:15 +00:00
Jordan Rose
32130d3cc3 Teach delayed parsing to get its SourceFile from the saved DeclContext.
This makes it possible to delay decls in more than one source file.

Swift SVN r9672
2013-10-25 17:30:43 +00:00
Jordan Rose
2aeba96d53 Use SourceFile in a few more places.
- Local name lookup
- AST verification
- Delayed parsing
- Type checker, for the file kind
- Context of synthesized REPL decls

Swift SVN r9648
2013-10-24 18:59:26 +00:00
Dmitri Hrybenko
e2b0f08f57 Parser: allow an optional trailing comma in array and dictionary literals
rdar://14874038


Swift SVN r9567
2013-10-21 23:13:22 +00:00
Dmitri Hrybenko
964dd6a5b6 Replace assert(false) with llvm_unreachable
Swift SVN r9403
2013-10-16 02:16:37 +00:00
Dmitri Hrybenko
46a4bc1402 Code completion: preserve the AST for the parsed top-level code. This enables
us to find iteration variables while doing code completion in nested top-level
code.

Fixes part of rdar://15199468


Swift SVN r9343
2013-10-15 01:24:16 +00:00
Argyrios Kyrtzidis
c5f20cabcc [IDE] When syntax-annotating a string interpolation, make sure that quotes are always annotated in a string-literal token.
Swift SVN r9295
2013-10-13 21:27:31 +00:00
Doug Gregor
e0f3477483 Diagnose attempts to declare a postfix '!' operator.
Swift SVN r9184
2013-10-11 00:08:34 +00:00
Jordan Rose
f5de2e43d7 Push SourceFile into Parser and REPL somewhat.
Swift SVN r9073
2013-10-09 18:38:17 +00:00
Dmitri Hrybenko
2099abfa5d Parser: improve recovery for extra braces in a nominal decl
parseList() insisted on having a separator token, even if it is optional.  If
it did not find the separator token during recovery, it stopped parsing the
nominal decl body.


Swift SVN r9045
2013-10-09 01:07:57 +00:00
Argyrios Kyrtzidis
f32167d166 [AST] Introduce a walk() method for TranslationUnit.
Swift SVN r8729
2013-09-27 17:24:35 +00:00
Argyrios Kyrtzidis
b955d8e134 [Parser] Adjust the end source locations in a few places.
Swift SVN r8728
2013-09-27 17:24:33 +00:00
Dmitri Hrybenko
5b1c412e70 Use 'override' when overriding ASTWalker functions
Swift SVN r8345
2013-09-17 19:31:24 +00:00
Dmitri Hrybenko
07e83ea49c Code completion: basic completion in constructor bodies
Swift SVN r8338
2013-09-17 18:20:26 +00:00
Dmitri Hrybenko
3cc01cf7d6 Introduce AbstractFunctionDecl -- a base class for ConstructorDecl,
DestructorDecl, FuncDecl -- and move some of the common concepts and logic
into it

No functionality change.


Swift SVN r8090
2013-09-11 04:04:01 +00:00
Dmitri Hrybenko
1e23c936e0 Rename FuncDecl::getBody() to FuncDecl::getFuncExpr()
ConstructorDecl::getBody() and DestructorDecl::getBody() return 'BraceStmt *'.
After changing the AST representation for functions, FuncDecl::getBody() will
return 'BraceStmt *' and FuncDecl::getFuncExpr() will be gone.


Swift SVN r8050
2013-09-09 19:57:27 +00:00
Dmitri Hrybenko
94d417a838 Parser: introduce skipUntilGreaterInTypeList(), which implements a better
heuristic than skipUntilAnyOperator() to find the end of a type list

Almost all testcases added in this commit used to skip all the way to EOF.


Swift SVN r7991
2013-09-06 17:50:11 +00:00
Dmitri Hrybenko
53652960a6 Make 'self' and 'Self' real keywords.
Also, remove IDENTIFIER_KEYWORD macro because these two were the last
identifier keywords.


Swift SVN r7806
2013-08-30 22:07:47 +00:00
Dmitri Hrybenko
ddfa9bc8d8 Parser::skip*() routines: don't stop on code completion token anymore
Our recovery is better now, and we don't skip that much.  Actually, even if we
would stop at code completion token during recovery, completion results would
be something very generic anyway (because there is no interesting parser state
to observe), and these results can be produced as a fallback separately (not
implemented).


Swift SVN r7754
2013-08-29 22:15:12 +00:00
Dmitri Hrybenko
80ca07d152 Remove comment that already exists in the header
Swift SVN r7744
2013-08-29 21:20:40 +00:00
Jordan Rose
fa3dd42c54 Don't parse function bodies in imported TUs.
...unless the functions are declared [transparent], or if we're in an
immediate mode (in which case we won't get a separate chance to link
against the imported TUs).

This is an optimization that will matter more when we start dealing with
Xcode projects with many cross-file dependencies, especially if we have
some kind of implicit import of the other source files in the project.

In the future, we may want to parse more function bodies for the purpose
of inlining, not just the transparent ones, but we weren't taking
advantage of that now, so it's not a regression. (We're still not taking
advantage of it even for [transparent] functions.)

Swift SVN r7698
2013-08-28 22:53:28 +00:00
Dmitri Hrybenko
9447f6c73f parseBraceItems(): don't skip over braced lists of statements during recovery
This increases the amount of noise in diagnostics.  But we did not get these
diagnostics before because we were just skipping these brace statements.  We
shoud improve recovery in parsing of whatever declaration that precedes the
brace statement so that it is picked up as a body of that declaration.


Swift SVN r7679
2013-08-28 19:33:43 +00:00
Dmitri Hrybenko
fec5c851d0 Code completion: complete types in protocol compositions
Swift SVN r7495
2013-08-23 00:30:32 +00:00
Dmitri Hrybenko
354c5f4a18 Parser: replace diagnose(Tok.getLoc(), ...) -> diagnose(Tok, ...)
We already had the Parser::diagnose(Token, ...) overload, but it was not used
in all these cases.


Swift SVN r7395
2013-08-21 00:26:30 +00:00
Dmitri Hrybenko
6e41124d54 Parser: don't use Diags directly, use diagnose()
Swift SVN r7394
2013-08-21 00:23:07 +00:00
Dmitri Hrybenko
c4a1367b0d Parser::parseList(): no need for special handling of tok::code_complete anymore
Swift SVN r7392
2013-08-21 00:08:52 +00:00
Dmitri Hrybenko
b701fe48d7 parseList(): don't create throw away the existing status which might contain
the CodeCompletion bit set.


Swift SVN r7387
2013-08-20 23:40:57 +00:00
Dmitri Hrybenko
b434f7cf3e Added a convenience operator| on ParserStatus
Swift SVN r7383
2013-08-20 23:15:19 +00:00
Dmitri Hrybenko
f13b5845bb Parser: use ParserStatus in parseList()
This will allow us to do code completion inside lists (e.g., tuples) *and* get
parser recovery instead of stopping at the code completion token immediately.


Swift SVN r7366
2013-08-20 18:26:01 +00:00
Dmitri Hrybenko
1e78a3b78a Fix indentation
Swift SVN r7281
2013-08-16 17:57:08 +00:00
Dmitri Hrybenko
536723eca4 Code completion: implement delayed parsing of all (?) declarations
This allows us to show generic parameters in:
struct S<T> {
  func f(a: #^A^#
}

And show the type Z in:
struct S {
  func f(a: #^A^#
  typealias Z = Int
}


Swift SVN r7216
2013-08-13 23:53:39 +00:00
Dmitri Hrybenko
e6d816897b Pattern parsing: fix awful recovery when while parsing the tuple we would try
to skip to the matching right paren no matter what, skipping over other
declarations, instead of resynchronizing on them


Swift SVN r7206
2013-08-13 18:48:05 +00:00
Dmitri Hrybenko
3d37954e81 Remove SourceManager::decompose() and switch its clients to normal location and
range printing


Swift SVN r7122
2013-08-10 02:19:50 +00:00