Commit Graph

1147 Commits

Author SHA1 Message Date
Dmitri Hrybenko
2e3d313d6b parseExprSuper(): use ParserResult
Swift SVN r7427
2013-08-21 21:26:09 +00:00
Dmitri Hrybenko
faff10f310 Parser: use ParserResult in 'is' and 'as' expression parsing
Swift SVN r7426
2013-08-21 21:15:43 +00:00
Dmitri Hrybenko
ec7b2eb3db Parser: use ParserResult in the interface of parseExpr()
But the implementation of expression parsing still does not propagate the code
completion bits because it uses NullablePtr for results.


Swift SVN r7425
2013-08-21 21:10:09 +00:00
Dmitri Hrybenko
f7ad1c9b03 parseDeclVar(): use ParserStatus
Swift SVN r7421
2013-08-21 20:15:01 +00:00
Dmitri Hrybenko
ad2ca67858 parseDeclSubscript(): use ParserStatus
Swift SVN r7415
2013-08-21 19:15:55 +00:00
Dmitri Hrybenko
255aeae1f9 parseDeclUnionElement(): use ParserResult because this function returns at most
one Decl, no need to pass in a vector


Swift SVN r7414
2013-08-21 19:04:12 +00:00
Dmitri Hrybenko
76d11315b0 parseDeclImport(): use ParserResult because this function returns at most one
Decl, no need to pass in a vector


Swift SVN r7413
2013-08-21 18:49:24 +00:00
Dmitri Hrybenko
ecf4cc44b1 parseDeclClass(): use ParserResult because this function returns at most one
Decl, no need to pass in a vector


Swift SVN r7410
2013-08-21 18:26:23 +00:00
Dmitri Hrybenko
e392e1a551 parseStruct(): use ParserResult because this function returns at most one Decl,
no need to pass in a vector


Swift SVN r7407
2013-08-21 18:10:16 +00:00
Dmitri Hrybenko
53685fe05f parseUnion(): use ParserResult because; it returns at most one Decl, no need to
pass in a vector

This a bit of noise to the diagnostics (see test change); this issue will be
fixed uniformly for all nominal decls in future commits.


Swift SVN r7399
2013-08-21 02:23:38 +00:00
Dmitri Hrybenko
581db767bf Use ParserResult and ParserStatus in tuple and function argument parsing
This finally fixes a few code completion test cases.

This also regresses the error message in one parsing testcase because
previously we would just happily skip those tokens, but now error handling path
is a little bit different and these tokens hit different error handling code.
This can be fixed by parsing a tuple for the selector argument and complaining
if the tuple had more than one element.


Swift SVN r7389
2013-08-20 23:55:00 +00:00
Dmitri Hrybenko
11b5e47479 Add a default argument to skipUntilDeclRBrace() so that it can be used with a
single token


Swift SVN r7381
2013-08-20 23:08:41 +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
26bde07f76 Parser: use ParserResult in parseTypeArray() and parseTypeOptional()
While there, improve recovery in parseTypeArray() a bit: don't drop the
previously parsed type if we see a syntax error *after that*.


Swift SVN r7365
2013-08-20 17:57:06 +00:00
Dmitri Hrybenko
c3954987d6 Parser: use ParserResult in parseTypeSimple() and everything that uses it/
is used in it


Swift SVN r7355
2013-08-20 02:12:31 +00:00
Dmitri Hrybenko
b0dd877454 Use ParserResult in type parsing
Swift SVN r7353
2013-08-20 01:19:31 +00:00
Doug Gregor
1ddb34fb71 Factor generic parameters and associated types into their own decl nodes.
Previously, TypeAliasDecl was used for typealiases, generic
parameters, and assocaited types, which is hideous and the source of
much confusion. Factor the latter two out into their own decl nodes,
with a common abstract base for "type parameters", and push these
nodes throughout the frontend.

No real functionality change, but this is a step toward uniquing
polymorphic types, among other things.


Swift SVN r7345
2013-08-19 23:36:58 +00:00
Dmitri Hrybenko
deff836592 Parser: use ParserResult in parseDeclFunc
Swift SVN r7341
2013-08-19 23:02:06 +00:00
Dmitri Hrybenko
c098cd1476 Parser: convert some pattern parsing functions to ParserResult
Swift SVN r7336
2013-08-19 22:38:34 +00:00
Dmitri Hrybenko
19a90b69f7 Parser: add ParserResult<T> -- a wrapper around the AST node plus extra bits
This allows the parser to recover, create an AST node, return it to the caller
*and* signal the caller that there was an error to trigger recovery in the
caller.  Until now the error was signalled with a nullptr result (any non-null
result was considered a success and no recovery was done in that case).

This also allows us to signal the caller if there was a code completion token
inside the production we tried to parse to trigger delayed parsing in the
caller while doing recovery in the callee.  Until now we could not do recovery
in the callee so that the caller could find the code completion token.

Right now we don't take any advantage of these features.  This commit just
replaces some uses of NullablePtr with ParserResult.


Swift SVN r7332
2013-08-19 22:11:23 +00:00
Dmitri Hrybenko
23d48b6b3b Use NullablePtr in more decl parser functions
Swift SVN r7274
2013-08-16 00:46:26 +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
dc655eb1cb Remove more abuse of SourceLoc::Value::getPointer()
Swift SVN r7109
2013-08-09 22:35:33 +00:00
Jordan Rose
0a84ed0c03 Parse: Allow type-simple in expr-new, and make "T?" part of type-simple.
These constructs are now legal:
  Int?.metatype
  new Int?[4]
  new NSWindow.metatype[4]
  new (Int -> Int)[4]

Swift SVN r7103
2013-08-09 21:33:59 +00:00
Jordan Rose
88cad52d72 Implement type sugar "T?" for Optional<T>.
- New type representation OptionalTypeRepr.
- New sugared type OptionalType.
- New base type SyntaxSugarType, parent of ArraySliceType and OptionalType.
  These two are the same in a lot of ways.
- The form "T[]?" is forbidden, because it makes "Int[4][2]" oddly
  different from "Int[4]?[2]". The type can be spelled "(T[])?" or
  Optional<T[]>.
- Like Slice, "Optional" is just looked up in the current module. This may
  or may not be the desired behavior in the long run.

<rdar://problem/14666783>

Swift SVN r7100
2013-08-09 21:33:36 +00:00
Dmitri Hrybenko
48faba29f3 Simplify parser constructors
Constructor delegation in parser was useless, because the code was split
between the constructors arbitrarily.

There was no need to pass down IsMainModule because the parser could figure
that out on its own.  Also rename it to allowTopLevelCode() to better describe
what it actually affects.


Swift SVN r7098
2013-08-09 20:43:21 +00:00
Dmitri Hrybenko
de59d8dcd4 Remove unneeded llvm:: qualifier for llvm::StringRef and llvm::SmallVector
Swift SVN r7089
2013-08-09 18:41:46 +00:00
Argyrios Kyrtzidis
47c04e760a [Parser] Remove a constructor that is not used anymore.
Swift SVN r6939
2013-08-06 14:59:00 +00:00
Dmitri Hrybenko
5cea4ebf41 Code completion: put CodeCompletionOffset on SourceManager instead of passing
around everywhere

Fixes:
rdar://14585108 Code completion does not work at the beginning of the file
rdar://14592634 Code completion returns zero results at EOF in a function
                without a closing brace


Swift SVN r6820
2013-08-01 22:08:58 +00:00
Dmitri Hrybenko
e1c4ae3174 Wrap llvm::SourceMgr in swift::SourceManager so that we can add new members
to the source manager.


Swift SVN r6815
2013-08-01 20:39:22 +00:00
Joe Groff
ba774364f1 SIL: Have SILModules track their SILStage.
Modules can be in either 'Raw' or 'Canonical' form, with different invariants on each. We don't actually distinguish those invariants yet, but this patch adds the field to SILModule and adds a "sil_stage" declaration to SIL printer/parser syntax.

Swift SVN r6793
2013-08-01 00:58:31 +00:00
Jordan Rose
757cf9826f Add Parse and AST support for the new import syntax.
Also, update LangRef.

Note that an explicit "import module" has been left out for now, since
it's not strictly necessary and "module" isn't a keyword yet.

Swift SVN r6786
2013-07-31 23:23:26 +00:00
Jordan Rose
674a03b085 Replace "oneof" with "union"...everywhere.
We haven't fully updated references to union cases, and enums still are not
their own thing yet, but "oneof" is gone. Long live "union"!

Swift SVN r6783
2013-07-31 21:33:33 +00:00
Jordan Rose
3ca6768be3 Using a variable within its own initializer is an error.
Currently, this includes cases where a variable of the same name is
available in an outer scope. We can change this later if desired.

<rdar://problem/14566648>

Swift SVN r6729
2013-07-30 00:17:28 +00:00
Dmitri Hrybenko
5142210a3e Code completion: delay parsing of top-level var decls
This allows us to do code completion inside top-lever var initializers.

As a part of implementation, we make sure that error recovery does not
implicitly skip over the code completion token.  This also fixes a bug that
prevented us from doing code completion inside function argument list, added
tests for that.


Swift SVN r6708
2013-07-29 21:31:44 +00:00
Dmitri Hrybenko
6beee6a62e Code completion: implement delayed parsing and code completion for
TopLevelCodeDecls


Swift SVN r6638
2013-07-26 01:44:23 +00:00
Dmitri Hrybenko
497ec93ec9 Code completion: generate a tok::code_complete token during the first pass of
parsing

No functionality change, this will be used by next commits.


Swift SVN r6637
2013-07-26 01:40:47 +00:00
Argyrios Kyrtzidis
803ba0e2be [Parser] Introduce PersistentParserState::ParserPos to encapsulate a Parser/Lexer independent info for restoring parsing from a certain token location.
Swift SVN r6593
2013-07-25 14:42:07 +00:00
Argyrios Kyrtzidis
cfd3e09e1e [Parser] Make PersistentParserState parameter optional and remove it from the constructor that accepts a StringRef fragment.
Swift SVN r6592
2013-07-25 14:42:06 +00:00
Argyrios Kyrtzidis
66d1e516c8 Refactor how multiple parsing passes and delayed parsing works.
-Introduce PersistentParserState to represent state persistent among multiple parsing passes.
  The advantage is that PersistentParserState is independent of a particular Parser or Lexer object.
-Use PersistentParserState to keep information about delayed function body parsing and eliminate parser-specific
  state from the AST (ParserTokenRange).
-Introduce DelayedParsingCallbacks to abstract out of the parser the logic about which functions should be delayed
  or skipped.

Many thanks to Dmitri for his valuable feedback!

Swift SVN r6580
2013-07-25 01:40:16 +00:00
Argyrios Kyrtzidis
694ab2cacf Remove 'Flags' from FunctionBodyParserState, it's not getting used.
Swift SVN r6579
2013-07-25 01:40:14 +00:00
Argyrios Kyrtzidis
de4a2dbd8b [Parser] Abstract a bit access to Parser's ScopeInfo.
This will be more useful later on.

Swift SVN r6578
2013-07-25 01:40:13 +00:00
Doug Gregor
109cb0db74 Parse 'static' more permissively, but complain if it isn't used.
Fixes <rdar://problem/14446888>.


Swift SVN r6453
2013-07-22 16:35:57 +00:00
Argyrios Kyrtzidis
015c1a892b Refactor Parser methods to return TypeReprs directly, instead of modifying TypeLocs.
Swift SVN r6328
2013-07-17 14:57:40 +00:00
Argyrios Kyrtzidis
f616eeee8b Utilize TypeReprs for type checking.
-Refactor Parser to stop creating types
-Refactor TypeChecker to create types by resolving TypeReprs.
-Remove "validation" bit from the type system.
  We don't need to "validate" every type that gets created but there's still a validation bit in TypeLoc,
  necessary because of generic substitutions.

Swift SVN r6326
2013-07-17 14:57:35 +00:00
Joe Groff
d956fdbd9e Update 'oneof' syntax.
Give oneof bodies syntax consistent with other NominalTypes. Give oneof elements first-class declaration syntax using the 'case' introducer, as suggested by Jordan. Oneofs can contain 'case' decls, functions, properties, and constructors, but not physical ivars. Non-oneof scopes cannot contain 'case' decls. Add some QoI to the oneof 'case' parser to also parse and complain about things that resemble switch 'case' labels inside decl contexts.

Swift SVN r6211
2013-07-12 20:42:19 +00:00
Manman Ren
80ffd6e693 Parse generic parameters in SIL function definition.
sil_type: '$' '*'? attribute-list (generic-params)? type
Refactor parseTypeAnnotation to separate applyAttributeToType which can be
used from SILParser.


Swift SVN r6209
2013-07-12 19:44:04 +00:00
Dmitri Hrybenko
02084efab7 Implement code completion for some function calls and member variable accesses
in expr-dot and expr-postfix that can be typechecked without typechecking the
beginning of the function body.


Swift SVN r6198
2013-07-12 02:00:41 +00:00
Chris Lattner
910cbb2270 Fix a 'requires' that got away.
Swift SVN r6190
2013-07-11 23:40:55 +00:00