Commit Graph

2357 Commits

Author SHA1 Message Date
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
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
Argyrios Kyrtzidis
a70eff6609 Introduce TypeRepr and related subclasses, that is a representation of a type as written in source.
This the first part for improving source location fidelity for types,
changes to follow:

-The Parser will not create any types, it will just create TypeReprs.
-The type checker will create the types by going through TypeReprs.
-IdentifierType will be removed.

Swift SVN r6112
2013-07-10 14:58:52 +00:00
Dmitri Hrybenko
cb98234d67 Allow the parser to persist after parseIntoTranslationUnit() returns
Swift SVN r6102
2013-07-10 00:25:37 +00:00
John McCall
3ea0fbf377 Basic.
1d
1i
Add basic parsing and validation for the weak and unowned attributes.

Swift SVN r6090
2013-07-09 08:37:36 +00:00
Dave Zarzycki
f0d783f9b9 'var' comma syntax must not mix with get/set syntax
This fixes:
<rdar://problem/14381190> VarDecls should not let comma syntax mix with getter/setter syntax

Swift SVN r6083
2013-07-09 00:41:07 +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
Argyrios Kyrtzidis
207a085bfc [Parser] Mark an implicit constructor as such.
Swift SVN r6006
2013-07-05 15:02:40 +00:00
Dmitri Hrybenko
0b8f72b9c1 Introduce an artificial EOF in the Lexer
This ensures that we don't go past the end of a subrange of a buffer when doing
delayed parsing.


Swift SVN r5952
2013-07-01 21:48:38 +00:00
Joe Groff
f6d1999569 Parse: Introduce pattern vars into case scopes.
Create a scope for each case block to contain bindings from its patterns, and invoke addVarsToScope after parsing case label patterns to introduce vars into that scope. Refactor addVarsToScope to use an ASTWalker so it finds pattern vars embedded in expr patterns.

Swift SVN r5899
2013-06-29 16:41:57 +00:00
Joe Groff
dff8813642 Parse bare identifiers in 'var' patterns as new variables.
If we're under a 'var' pattern, reinterpret bare identifier exprs early on as variable bindings so we will be able to add them to the case scope.

Swift SVN r5898
2013-06-29 04:50:16 +00:00
Dmitri Hrybenko
f73d866d91 Implement delayed parsing for function bodies
In order to do this, we need to save and restore parser state easily.  The
important pieces of state are:

* lexer position;
* lexical scope stack.

Lexer position can be saved/restored easily.  We don't need to store the tokens
for the function body because swift does not have a preprocessor and we can
easily re-lex everything we need.  We just store the lexer state for the
beginning and the end of the body.

To save the lexical scope stack, we had to change the underlying data
structure.  Originally, the parser used the ScopedHashTable, which supports
only a stack of scopes.  But we need a *tree* of scopes.  I implemented
TreeScopedHashTable based on ScopedHashTable.  It has an optimization for
pushing/popping scopes in a stack fashion -- these scopes will not be allocated
on the heap.  While ‘detached’ scopes that we want to re-enter later, and all
their parent scopes, are moved to the heap.

In parseIntoTranslationUnit() we do a second pass over the 'structural AST'
that does not contain function bodies to actually parse them from saved token
ranges.


Swift SVN r5886
2013-06-28 22:38:10 +00:00
Dmitri Hrybenko
e10ca4cdb6 Verify SourceRanges on Patterns and fix bugs uncovered by this
Swift SVN r5848
2013-06-27 21:54:53 +00:00
Chris Lattner
c03d4454a0 implement support for a new [stdlib] attribute that can be slapped on an import decl.
This causes the SourceLoader to recursively parse the imported module in standard 
library mode, giving it access to the Builtin module.

This is all a terrible hack and should be ripped out with great victory someday, but 
until we have binary modules that persist the build setting used to produce the 
module, this is the best we can do.



Swift SVN r5847
2013-06-27 21:31:15 +00:00
Joe Groff
53221db84c AST: Add 'VarPattern' node.
We decided to go with 'var' as a distributive pattern introducer which applies to bare identifiers within the subpattern. For example, 'var (a, b)' and '(var a, var b)' would be equivalent patterns. To model this, give 'var' its own AST node with a subpattern and remove the introducer loc from NamedPattern.

Swift SVN r5824
2013-06-26 23:01:47 +00:00
Dmitri Hrybenko
efffe5c065 Don't add names to non-resolvable scopes
Currently not only we insert names in non-resolvable scopes, but every
overloaded name gets stored only once (the last one wins).  Everything just
happens to work, because we never do name lookup in these scopes.

I also added a ScopeKind to every Scope (instead of just adding the bit --
isResolvableScope), because this provides a better debugging experience, and
centralizes knowledge about what scope kind is resolvable in the function
isResolvableScope(ScopeKind).


Swift SVN r5822
2013-06-26 21:44:11 +00:00
Joe Groff
e460a01af6 Remove the 'UnresolvedCallPattern' I stubbed out.
I talked to John about parsing patterns today, and because of the magnitude of name-lookup-dependent ambiguities between patterns and expressions, we agreed that at least for a first-pass implementation it makes sense to parse patterns as extensions of the expr grammar and charge name binding with distinguishing patterns from expressions. This gets us out of needing the concept of an "unresolved pattern", at least in the short term.

Swift SVN r5808
2013-06-26 04:23:47 +00:00
Joe Groff
7ba95cfd26 Add AST nodes for refutable patterns.
Introduce Pattern subclasses for the 'is T', 'T(<pattern>)', and '<expr>' pattern syntaxes we'll be introducing for pattern-matching "switch" statements. Also add an 'UnresolvedCalLPattern' to act as an intermediate for name lookup to resolve to a nominal type, oneof element, or function call expression pattern. Since we'll need to be able to rewrite patterns like we do expressions, add setters to AST nodes that contain references to subpatterns. Implement some basic walking logic in places we search patterns for var decls, but punt on any more complex type-checking or SILGen derived from these nodes until we actually use them.

Swift SVN r5780
2013-06-24 17:17:34 +00:00
Jordan Rose
3b07d4e102 Make Pattern (more) const-correct.
Sub-patterns are now considered part of the enclosing pattern, so if the
parent pattern pointer is const, the child pointer will be too.

I changed the minimal number of files to make this work, but future code
should use "const Pattern *" when intended, and "Pattern *" only if they
intend to modify the pattern.

Swift SVN r5743
2013-06-21 17:51:39 +00:00
Chris Lattner
a5c7c65ee7 Move around the logic for handling autoimport of the swift standard
library.  We use the same (somewhat broken heuristics), they are
just implemented in another way.

The major functionality change is that previously, .sil files would
auto import "swift" if they started with a non-sil decl.  Now they
never do.



Swift SVN r5731
2013-06-20 23:39:27 +00:00
Doug Gregor
720cb9348d LLVM's PathV2.h has become Path.h. Update includes appropriately
Swift SVN r5574
2013-06-13 14:53:52 +00:00
Joe Groff
952028c5f2 Parse [class_protocol] attribute on protocols.
Add a [class_protocol] attribute and only allow it on protocol decls. It has no effect yet.

Swift SVN r5551
2013-06-09 03:22:50 +00:00
Chris Lattner
dfef589a4b implement generic support for parsing the [thin] attribute on function types.
Switch SILType parsing to parse type annotations.
This allows us to use thin functions in .sil files.


Swift SVN r5351
2013-05-26 06:11:13 +00:00
Chris Lattner
bd217c9227 extend the general form of parseIdentifier to optionally return a SourceLoc,
and use this throughout the parser.


Swift SVN r5314
2013-05-25 00:07:56 +00:00
Joe Groff
8993ed707e Split 'C' and 'ObjCMethod' calling conventions.
This cleans up some wishy-washy control flow that relied on the uncurryLevel of a type to distinguish ObjC methods from freestanding C functions. While we're here, clean up all the places we use ad-hoc comparison logic on the AbstractCC enum to use switches that properly cover the enum.

Swift SVN r5251
2013-05-21 15:19:37 +00:00
Chris Lattner
f2e3af3cf6 Eliminate the "global" list of unresolved identifier types maintained
by TranslationUnit.  This list existed solely to allow name lookup of
an unbound IdentifierType to know its DeclContext.  Instead of indirecting
through this list, just store the DeclContext in the IdentifierType in its
uninitialized state.

This eliminates a really terrible performance fixme about scanning the list,
eliminates the management fiddling around with this list in the parser, and
is generally much cleaner.


Swift SVN r5246
2013-05-21 05:27:37 +00:00
Chris Lattner
b4eee19287 Switch the SIL parse to parse the file in a model similar to "immediate"
mode for normal .swift files.  We basically parse batches of non-sil function
decls, type check them as a batch, then process any SIL functions.  This allows
us to have mutually recursive types and other things that are fully sema'd and
that are referenced by SIL functions, without involving SIL functions too
intimately with type checking.

This does mean that SIL functions can't forward reference types, oh well.



Swift SVN r5243
2013-05-21 03:27:27 +00:00
Joe Groff
a790341d3a Parse: Parse cc attribute on function types.
Swift SVN r5235
2013-05-20 22:29:22 +00:00
Joe Groff
94b651f929 Parse: Parse 'func +*/<T>(x:T)' w/o requiring a space.
If the name of a func declaration ends in '<' and the following token is an identifier, the '<' has to be a generic angle bracket instead of part of the operator name. Fixes <rdar://problem/13782566>.

Swift SVN r5226
2013-05-20 18:30:49 +00:00
Doug Gregor
fab984aeae Test and improve parser error recovery for closures.
Swift SVN r5203
2013-05-17 16:39:20 +00:00
Chris Lattner
192475ad88 carve out a new file for the sil parser logic.
Swift SVN r5177
2013-05-16 17:59:30 +00:00
Joe Groff
e1c838962e Revert "Remove [objc_block] attribute from Swift type system."
Implementing SIL bridging is going to take more IRGen work than I anticipated.

Swift SVN r5113
2013-05-09 16:32:18 +00:00
Joe Groff
38f13e56f5 Remove [objc_block] attribute from Swift type system.
We will handle Swift-function-to-ObjC-block bridging in SILGen as part of general Cocoa-to-Swift type bridging. Temporarily disable building swiftAppKit and tests that exercise block bridging until the new implementation lands.

Swift SVN r5090
2013-05-08 16:52:12 +00:00
Doug Gregor
57002ac3dc Remove byref(heap).
Most of this is mechanical, because we weren't actually relying on
byref(heap) for anything. Simplify capture analysis, now that the only
way a variable can have non-fixed lifetime is if it is actually
captured. Fixes <rdar://problem/11247831>.


Swift SVN r5046
2013-05-06 14:07:54 +00:00
Joe Groff
b818405034 Replace direct use of [[clang::fallthrough]] with a macro.
Add a SWIFT_FALLTHROUGH macro that expands to [[clang::fallthrough]] for Clang and nothing for other compilers. No functionality change.

Swift SVN r5043
2013-05-05 18:54:03 +00:00
Joe Groff
2eb4ac563a Parse [force_inline] attribute.
Add a force_inline attribute and allow it to be applied for now only to uncurried nongeneric functions. It doesn't do anything yet.

Swift SVN r5036
2013-05-04 00:46:48 +00:00
Chris Lattner
15f40068d4 remove stmt-brace. If you need something like it for scoping purposes, you can always use "if true {}".
Swift SVN r5034
2013-05-03 05:59:27 +00:00
Jordan Rose
790248d8b4 Diagnostics: use builder pattern instead of streaming for ranges/fix-its.
Per Chris's feedback and suggestions on the verbose fix-it API, convert
diagnostics over to using the builder pattern instead of Clang's streaming
pattern (<<) for fix-its and ranges. Ranges are included because
otherwise it's syntactically difficult to add a fix-it after a range.

New syntax:

  diagnose(Loc, diag::warn_problem)
    .highlight(E->getRange())
    .fixItRemove(E->getLHS()->getRange())
    .fixItInsert(E->getRHS()->getLoc(), "&")
    .fixItReplace(E->getOp()->getRange(), "++");

These builder functions only exist on InFlightDiagnostic; while you can
still modify a plain Diagnostic, you have to do it with plain accessors
and a raw DiagnosticInfo::FixIt.

Swift SVN r4894
2013-04-24 23:15:53 +00:00
Dave Abrahams
05121795fb Revert unintended partial commit
Swift SVN r4830
2013-04-19 21:46:35 +00:00
Dave Abrahams
19750ac4ec Eliminate unused variable
Swift SVN r4829
2013-04-19 21:45:30 +00:00
Doug Gregor
b5a848e8b2 <rdar://problem/11926374> Only introduce the implicit, memberwise struct constructor when there is no similar constructor within the struct declaration.
For the implicit memberwise struct constructor to be suppressed, one
has to write a constructor with the same parameters (names, types, and
order) as the instance variables of the struct.


Swift SVN r4819
2013-04-19 00:10:46 +00:00
Jordan Rose
b6c1ff4483 All the rest of the easy fix-its.
Also, turn a diagnostic into an assertion (string_interpolation_extra),

Swift SVN r4816
2013-04-18 23:34:27 +00:00
Jordan Rose
f7cd3a6ec6 Add fix-its for missing and spurious separators.
Swift SVN r4789
2013-04-18 00:42:59 +00:00
Joe Groff
6ed98ac0e5 Parse [objc_block] attribute on function types.
So we can use it in tests.

Swift SVN r4722
2013-04-13 17:05:35 +00:00
Chris Lattner
af3b55c1f0 Further reinforce TopLevelCodeDecl as the container for top level code.
This nests top level PatternBindingDecls (in "main modules") under TopLevelCodeDecls,
instead of having them live in a translation unit.  They contain code that is executed,
so they should be in a TLCD.


Swift SVN r4668
2013-04-10 23:13:22 +00:00
Chris Lattner
1ee0bed38f Clean up Parser::parseBraceItemList even more:
Extend the existing "isTerminatorForBraceItemListKind" logic to
handle the special case for top level code, instead of having
weird logic dumped in the middle of parseBraceItemList with no comments.

This logic is still seriously dubious, but at least it is out of the way
instead of dump into already really complex logic.


Swift SVN r4665
2013-04-10 22:24:08 +00:00
Chris Lattner
a00464dde1 refactor the logic that determines whether newly parsed top-level decls need to
be immediately run by the REPL to live in one simple place, out of the braceitem
parsing loop.


Swift SVN r4663
2013-04-10 22:06:07 +00:00
Dave Zarzycki
54f8cdeb32 Consolidate list parsing and error recovery boilerplate
Fix array/dictionary literal parsing robustness by consolidating and improving
the parsing of lists in general (tuples/array/dictionary literals, attribute
lists, statement lists, declaration lists, etc).

Missing commas in tuple/array/dictionary literals or declaration attributes
are now detected, reported, and recovered from.

Premature ellipsis in tuples are now detected, reported, and recovered from.

Swift SVN r4631
2013-04-08 08:29:51 +00:00
Joe Groff
ac23437886 Replace infix attributes with operator decl lookup
During name binding, associate func decls with operator decls. When parsing SequenceExprs, look up operator decls to determine associativity and precedence of infix operators. Remove the infix_left and infix_left attributes, and make the infix attribute a simple declared attribute [infix] with no precedence.

Operator decls are resolved as follows:

- If an operator is declared in the same module as the use, resolve to the declaration in the current module.
- Otherwise, import operator declarations from all imported modules. If more than one declaration is imported for the operator and they conflict, raise an ambiguity error. If they are equivalent, pick one arbitrarily.

This allows operator declarations within the current module to override imported declarations if desired or to disambiguate conflicting operator declarations.

I've updated the standard library and the tests. stdlib2 and some of the examples still need to be updated.

Swift SVN r4629
2013-04-07 02:43:03 +00:00
Chris Lattner
28774bf9fc Come full circle on TopLevelCodeDecl, making top level stmts and exprs each get their
own TLCD.  This is important to preserve the ordering of stmt and expr w.r.t. 
PatternBindingDecls that initialize the decls.

We keep the BraceStmt wrapping it to make it more similar to other decls
though.


Swift SVN r4626
2013-04-06 21:58:26 +00:00