Commit Graph

459 Commits

Author SHA1 Message Date
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
Joe Groff
070ee26c56 Replace 'requires' keyword with 'where'.
Reuse the 'where' keyword to introduce generic requirement clauses, as in 'func foo<T:Enumerator where T.Element == Int>()'.

Swift SVN r6180
2013-07-11 22:20:40 +00:00
Doug Gregor
61060baf8e Eliminate the type-checking pass that resolves default arguments in tuple types.
Per r6154, this is now dead code. The only places we allow default
arguments will be visited by normal type validation, so there's
nothing specific to do here.


Swift SVN r6157
2013-07-11 18:06:14 +00:00
Doug Gregor
50d6fd0455 Lock down on the use of default values in patterns and types.
Per previous discussions, we only want to allow default values for
uncurried 'func' and 'constructor' parameters, and not for return
types or arbitrary tuple types. Introduce this restriction, fixing
part of <rdar://problem/13372694>. 



Swift SVN r6156
2013-07-11 17:53:05 +00:00
Dmitri Hrybenko
3c5b12fc0f Code completion: add a lot of infrastructure code
* Added a mode in swift-ide-test to test code completion.  Unlike c-index-test,
  the code completion token in tests is a real token -- we don't need to
  count lines and columns anymore.

* Added support in lexer to produce a code completion token.

* Added a parser interface to code completion.  It is passed down from the
  libFrontend to the parser, but its functions are not called yet.

* Added a sketch of the interface of code completion consumer and code
  completion results.

Note: all this is not doing anything useful yet.


Swift SVN r6128
2013-07-10 20:53:40 +00:00
Doug Gregor
85231a5d16 Remove || closures.
Swift SVN r6119
2013-07-10 17:40:52 +00:00
Doug Gregor
63ff23147f Implement another new closure syntax.
In this syntax, the closure signature (when present) is placed within
the braces and the 'in' keyword separates it from the body of the
closure, e.g.,

      magic(42, { (x : Int, y : Int) -> Bool in
        print("Comparing \(x) to \(y).\n")
        return y < x
      })

When types are omitted from the parameter list, one can also drop the
parentheses, e.g.,

      magic(42, { x, y -> Bool in
        print("Comparing \(x) to \(y).\n")
        return y < x
      })

The parsing is inefficient and recovers poorly (in part because 'in'
is a contextual keyword rather than a real keyword), but it should
handle the full grammar. A number of tests, along with the whitepaper
and related rational documents, still need to be updated. Still, this
is the core of <rdar://problem/14004323>.



Swift SVN r6105
2013-07-10 01:15:15 +00:00
Dmitri Hrybenko
cb98234d67 Allow the parser to persist after parseIntoTranslationUnit() returns
Swift SVN r6102
2013-07-10 00:25:37 +00:00
Dmitri Hrybenko
b92a157bc0 Remove the llvm::MemoryBuffer member from Parser, it is not used anywhere.
Swift SVN r6098
2013-07-09 22:43:39 +00:00
Dmitri Hrybenko
1c0233efb1 Move lib/Parse/{Parser.h, Scope.h} -> include/swift/Parse/
Swift SVN r6062
2013-07-08 20:36:40 +00:00
Chris Lattner
26f66a8b24 move all the parser headers into lib/Parse since they are now all private.
I chose to just delete the -lex action in swift, since it was only useful for
about 10 minutes during bringup and probably never will be again.




Swift SVN r557
2011-08-13 22:51:04 +00:00
Chris Lattner
92051fd98e add a new Subsystems.h file to hold the entrypoints for various subsystems,
instead of smashing them into Parser.h, resolving some FIXME's.



Swift SVN r556
2011-08-13 22:43:17 +00:00
Chris Lattner
73a3f9d888 fix clients to not poke the Parser class directly.
Swift SVN r555
2011-08-13 22:38:20 +00:00
Chris Lattner
c863bea58d merge SemaExpr into ParseExpr.cpp
Swift SVN r554
2011-08-13 22:33:33 +00:00
Chris Lattner
dab303a541 move statement parsing out to its own file.
Swift SVN r550
2011-08-13 22:13:33 +00:00
Chris Lattner
e5c5dab2df give parser its own ASTContext member instead of having to indirect through Sema.
Swift SVN r549
2011-08-13 22:09:49 +00:00
Chris Lattner
c86d4a5853 Split parsing for types out to its own ParseType.cpp file, and
merge SemaType into it.


Swift SVN r547
2011-08-13 22:06:33 +00:00
John McCall
9f2ca5e4cc Remove juxtaposition handling from the type-checker and put it
in the parser.  Implement the grammar which permits this.
Enforce that binary operators have to, well, operators.



Swift SVN r515
2011-08-12 05:49:30 +00:00
Chris Lattner
abe344bef2 switch statements to use ParseResult, enhance ParseResult to map ParseResult<BraceStmt>
convertible to ParseResult<Stmt>.


Swift SVN r505
2011-08-12 00:16:41 +00:00
Chris Lattner
7a5e383c0b some localized cleanups for diagnostics.
Swift SVN r504
2011-08-11 23:38:30 +00:00
Chris Lattner
0e8a66ec9d Introduce a new ParseResult<T> helper class, which is effectively
oneof { T*, Absent, ParseError, SemaError }.

This replaces the former convention used by the expression parsing
logic that used NullablePtr + bool to indicate all of these states,
in a way that I could never keep straight.

This should lead to better error recovery, but needs to be adopted by
more parts of the parser.  Sema still uses NullablePtr because it
either returns a valid AST node or has a semantic error, there is no
parse error possible in Sema.



Swift SVN r503
2011-08-11 23:35:27 +00:00
Chris Lattner
9e6817b3cd implement lexer, parser, and dox support for while loops, everything is hooked up now.
Swift SVN r502
2011-08-11 20:47:33 +00:00
Chris Lattner
433d6de807 implement AST and parser support for 'return'. We're still not doing a conversion
to a return type yet though.  We happily diagnose thigns like this as an error:

func foo() -> int {
  return 4 5
}



Swift SVN r493
2011-08-03 23:19:24 +00:00
Chris Lattner
a64c74ec94 Replace lambda keyword with func. One annoying aspect of this that I didn't
think about will occur when/if we want to support attributes on func expression.
That should look like "func [attributes]{ ... }" but now that requires looking
beyond that attributes to know if this is a funcdecl or funcexpr.  Nothing that
more heroic lookahead can't handle.



Swift SVN r486
2011-08-03 00:28:11 +00:00
Chris Lattner
0265e3cbd1 make 'else if' a special case, disallowing things like "else ;".
Swift SVN r482
2011-08-02 21:31:31 +00:00
Chris Lattner
c3bbefcbaa add support for lambda expressions (anonymous functions), which are the thing that
func is sugar for.  Unfortunately, we can't use 'func' without introducing ambiguity
since decls and exprs can exist in the same context, I'm not wed to 'lambda' as the
keyword, thoughts welcome.


Swift SVN r467
2011-07-31 20:12:20 +00:00
Chris Lattner
63ce0be641 make the big switch: {} are now statements, not expressions. This removes some
annoying things from the grammar (like expr-non-brace), and makes it so that 
the body/else of an if is just a statement.

This patch has a fairly serious caveat that we just drop function bodies on the
floor now, since we have no "stmtexpr" sort of thing to represent the syntactic
sugar that is func.  We'll fix that soon.


Swift SVN r462
2011-07-31 17:39:13 +00:00
Chris Lattner
382f33ec74 introduce statements, make if (and ;) a statement. This includes a
few horrible hacks, but is the right direction to go.


Swift SVN r457
2011-07-31 06:52:11 +00:00
Chris Lattner
0fc77abf5c Per discussion on swift-dev, unify 'meth' and 'func' syntax into just 'func' syntax
where you can optionally declare a receiver type.  This is cleaner both conceptually
and in implementation, and eliminates drug references. :)


Swift SVN r444
2011-07-24 20:11:35 +00:00
Chris Lattner
6f7c702321 disable copy and assignment of various types, and plain 'operator new' of others
using the new '0x way.


Swift SVN r443
2011-07-24 19:33:27 +00:00
Chris Lattner
6fbe70dd87 convert TokenKind to a scoped enum, eliminating the old c++'98 hackaround to
emulate it.


Swift SVN r442
2011-07-24 19:28:36 +00:00
Chris Lattner
3af81cccbe raw_ostream and NullablePtr. While there are more types that
could be handled in similar ways, this gets the most of them.


Swift SVN r424
2011-07-19 06:09:31 +00:00
Chris Lattner
10017bef15 ArrayRef and SmallVector[Impl]
Swift SVN r423
2011-07-19 06:03:26 +00:00
Chris Lattner
7275ca527a pull in StringRef and Twine.
Swift SVN r422
2011-07-19 06:00:20 +00:00
Chris Lattner
e647b29339 stop the llvm-namespace-qualification-insanity by caving in and
adding a new swift/AST/LLVM.h file which forward declares and imports
common llvm classes, starting with SMLoc.


Swift SVN r420
2011-07-19 05:49:43 +00:00
Chris Lattner
ba2793aa6b implement parser support for methods, including dox and
a testcase.  No AST or sema yet.


Swift SVN r415
2011-07-19 04:46:07 +00:00
Chris Lattner
2db54bd1e9 change consumeToken to return the location of the token that it
just consumed, simplifying some common callers.


Swift SVN r396
2011-06-05 02:26:19 +00:00
Chris Lattner
b9e7823656 Implement lexing and parsing support for a proper if expression. There
is no AST building or typechecking support yet.  Document the intended
semantics in LangRef.  This is clearly subject to change, but is a starting
point.


Swift SVN r393
2011-06-05 02:03:48 +00:00
Chris Lattner
d3d1278c7e John points out that struct foo { ... } is more consistent with oneof and generally makes more sense than struct foo (...). Switch!
Swift SVN r372
2011-04-22 06:12:21 +00:00