Commit Graph

109 Commits

Author SHA1 Message Date
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
David Farler
f450f0ccdf Revert "Preserve whitespace and comments during lexing as Trivia"
This reverts commit d6e2b58382.
2016-11-18 13:23:31 -08:00
David Farler
d6e2b58382 Preserve whitespace and comments during lexing as Trivia
Store leading a trailing "trivia" around a token, such as whitespace,
comments, doc comments, and escaping backticks. These are syntactically
important for preserving formatting when printing ASTs but don't
semantically affect the program.

Tokens take all trailing trivia up to, but not including, the next
newline. This is important to maintain checks that statements without
semicolon separators start on a new line, among other things.

Trivia are now data attached to the ends of tokens, not tokens
themselves.

Create a new Syntax sublibrary for upcoming immutable, persistent,
thread-safe ASTs, which will contain only the syntactic information
about source structure, as well as for generating new source code, and
structural editing. Proactively move swift::Token into there.

Since this patch is getting a bit large, a token fuzzer which checks
for round-trip equivlence with the workflow:

fuzzer => token stream => file1
  => Lexer => token stream => file 2 => diff(file1, file2)

Will arrive in a subsequent commit.

This patch does not change the grammar.
2016-11-15 16:11:57 -08:00
Rintaro Ishizaki
81c1edee5d [CodeCompletion] Suffix ": " instead of "=" when completing attribute argument names
In addtion, renamed DeclAttrParamEqual to DeclAttrParamColon.
2016-08-17 02:33:04 +09:00
John McCall
c8c41b385c Implement SE-0077: precedence group declarations.
What I've implemented here deviates from the current proposal text
in the following ways:

- I had to introduce a FunctionArrowPrecedence to capture the parsing
  of -> in expression contexts.

- I found it convenient to continue to model the assignment property
  explicitly.

- The comparison and casting operators have historically been
  non-associative; I have chosen to preserve that, since I don't
  think this proposal intended to change it.

- This uses the precedence group names and higherThan/lowerThan
  as agreed in discussion.
2016-07-26 14:04:57 -07:00
Ben Langmuir
8f9299cc97 [CodeCompletion] Add assignment to experimental operator completion
When the LHS is an lvalue/assignable tuple and there is no leading
sequence of binary expressions.

It's a bit hacky right now since we don't have a good way to
differentiate general pattern completions from builtin operators.

rdar://problem/23209683
2016-03-02 18:21:37 -08:00
Doug Gregor
38c1de69e4 Reinstate "[SR-511][Parse] Add 'associatedtype' keyword and fixit"
This reverts commit ce7b2bcf09, tweaking
a few validation tests appropriately (1 crasher fixed, two -verify
tests that needed updating).
2016-01-14 00:21:48 -08:00
Erik Eckstein
ce7b2bcf09 Revert "[SR-511][Parse] Add 'associatedtype' keyword and fixit"
This reverts commit 2b2e9dc80e.

It broke some compiler crasher tests
2016-01-13 20:42:58 -08:00
gregomni
2b2e9dc80e [SR-511][Parse] Add 'associatedtype' keyword and fixit
Adds an associatedtype keyword to the parser tokens, and accepts either
typealias or associatedtype to create an AssociatedTypeDecl, warning
that the former is deprecated. The ASTPrinter now emits associatedtype
for AssociatedTypeDecls.

Separated AssociatedType from TypeAlias as two different kinds of
CodeCompletionDeclKinds. This part probably doesn’t turn out to be
absolutely necessary currently, but it is nice cleanup from formerly
specifically glomming the two together.

And then many, many changes to tests. The actual new tests for the fixits
is at the end of Generics/associated_types.swift.
2016-01-13 17:54:31 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Mayur Raiturkar
e917f8537a Typo fixes 2015-12-28 16:45:40 +05:30
Ben Langmuir
d871c9a529 [CodeCompletion] Split code completion operator kind out
...into separate prefix, postfix and infix operators. Also incidentally
make the whitespace around operators special so we can decide when to
skip over it. Tested in SourceKit.

Swift SVN r32468
2015-10-06 22:52:16 +00:00
Chris Lattner
f52f2bc47e fix a warning about an unhandled case
Swift SVN r31132
2015-08-11 16:52:13 +00:00
Ben Langmuir
7fcd0eeae5 [CodeCompletion] Add 'throws' and 'rethrows' to call descriptions
Completions for calling functions will now show 'throws' in the
description text so that users can differentiate throwing and
non-throwing calls. We don't insert this into the source text, since
it's not part of the call syntax.

rdar://problem/20978869

Swift SVN r28791
2015-05-19 21:46:20 +00:00
Ben Langmuir
f3ecb63f30 Move caching logic into the code completion consumer
This will let us implement caching in the client (e.g. SourceKit) at
some point and simplifies adding more levels of caching. Requires a
corresponding SourceKit change.

Swift SVN r28365
2015-05-09 18:51:30 +00:00
Xi Ge
566e54a81c [CodeCompletion] Supporting auto-completion of declaration attribute keywords. When a
developer inputs @, the code completion engine recommends built-in attributes.

Swift SVN r25785
2015-03-05 19:35:27 +00:00
Xi Ge
e71588a414 [CodeCompletion] The second step to complete @availability. Adding the second
or the later parameters in this attribute. rdar://19541135

Swift SVN r25762
2015-03-04 20:55:30 +00:00
Doug Gregor
b3badc601a Handle consistency checking that requires the entire module.
Objective-C method unintended override checking is one such case where
properly checking unintended overrides requires us to essentially look
at the whole module, because one translation unit may declare
something that produces an Objective-C method "setFoo:" in a
superclass while another translation unit declares something with a
distinct name that produces an Objective-C method "setFoo:". So, when
we don't have a primary file (e.g., when we're doing the merge-module
step), delay such checks until after all the source files for the
module have been type-checked. When there is a primary file, we
perform the checking that we can based on type checking that primary
file (and whatever got touched along the way), so we get a subset of
the proper diagnostics.

Swift SVN r23179
2014-11-08 06:20:57 +00:00
Dmitri Hrybenko
6a5f59831b Code completion: include access control keywords in override completion
When trying to implement deduplication of results, found and fixed an issue
with loose checks for generic overload checking.

rdar://17995317


Swift SVN r21276
2014-08-19 11:00:10 +00:00
Sonny Falk
efa1ff8ab4 [IDE/CodeComplete] Add CallParameterClosureType chunk, which resolves
optional & alias types for closure type parameters.

This allows code completion placeholder expansion to properly expand
closure parameters utilizing a typealias, e.g. dispatch_block_t.

Update and add test for the above.

Work for <rdar://problem/15860693>.

Swift SVN r20206
2014-07-19 03:18:29 +00:00
Ben Langmuir
b31a6d125d Preserve vararg... syntax in code completions
Int... should now be shown as Int... rather than [Int].

Swift SVN r19464
2014-07-02 15:05:59 +00:00
Dmitri Hrybenko
b0eb481bff Code completion: display correct syntax and type when using an @optional member
on a value


Swift SVN r18742
2014-06-09 13:06:18 +00:00
Dmitri Hrybenko
2664242045 REPL code completion: use a readable output format
rdar://16988159


Swift SVN r18516
2014-05-21 20:38:05 +00:00
Sonny Falk
a2680240c0 [IDE/CodeCompletion] Teach code completion to display the local parameter name
if there's no parameter API name. This is for display purposes only.
Update all relevant tests accordingly.
This addresses <rdar://problem/16768768>.

For example:
  class X {
    func f(a: Int, b: Int) { }
  }

Would previously display like this in code completion in Xcode:
  f(<#Int#>, b: <#Int#>)

The local parameter name, while not API, often still conveys meaning
to the user. So it's now included like this:
  f(<#a: Int#>, b: <#Int#>)

Swift SVN r18403
2014-05-19 08:31:10 +00:00
Sonny Falk
22633c2d83 [IDE/CodeCompletion] Make code completion include the leading paren in calls.
The leading paren is included for display purposes only, not inserted
in the code if already present. It makes the displayed text in the
code completion list symmetrical with respect to open/close parens.

Add markups when printing annotation chunks so it becomes testable.
Update tests accordingly, and include tests for leading parens.

This addresses <rdar://problem/16918310>.

Swift SVN r18126
2014-05-15 21:09:56 +00:00
Argyrios Kyrtzidis
8f2b5a0458 [IDE/CodeCompletion] Remove the space before a BraceStmtWithCursor chunk, if we are going to ignore it then the space is noise.
Swift SVN r17401
2014-05-04 21:21:12 +00:00
Argyrios Kyrtzidis
5f24181015 [IDE/CodeComplete] Create a separate chunk for the 'override' keyword.
Swift SVN r17387
2014-05-04 17:29:59 +00:00
Argyrios Kyrtzidis
1a7e6485f4 [IDE/CodeCompletion] For override completions, separate the introducer keywords like "override func" in
a new chunk kind, so that we can sort/filter based on the name of the function.

Swift SVN r17369
2014-05-04 07:20:57 +00:00
Doug Gregor
3d3ff6811a Add a pile of missing #includes exposed by pruning includes in top-of-tree LLVM.
Swift SVN r17157
2014-05-01 14:26:34 +00:00
Dmitri Hrybenko
0cb8ddd213 Code completion for overrides: use a special chunk BraceStmtWithCursor for
braces

This allows clients to process it in a special way, for example, to indent the
resulting code.


Swift SVN r16884
2014-04-26 17:52:16 +00:00
Dmitri Hrybenko
b3851a79e2 REPL code completion: handle PreferredCursorPosition chunk
Swift SVN r16759
2014-04-24 18:15:55 +00:00
Dmitri Hrybenko
236c581de7 Code completion: complete "?.member" on T?, and ".member" on @unchecked T?
In order for Xcode to use these completions, we complete "?.member" when the
user has typed "anOptional.", but we also say that in order to apply this
result, N bytes to the left of the cursor should be erased first.

rdar://16579657 rdar://15233283


Swift SVN r16409
2014-04-16 10:50:14 +00:00
Dmitri Hrybenko
ef0942c69c Add a convenience API SourceManager::addMemBufferCopy() to simplify adding a
buffer in case the client does not need a pointer to the buffer.


Swift SVN r14777
2014-03-07 11:41:08 +00:00
Dmitri Hrybenko
06be7781f8 Fix code completion for 'inout' by completing '&' in the function argument
Partially addresses rdar://15999689


Swift SVN r14299
2014-02-24 12:48:56 +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
John McCall
7173cec9db Thread contextual information about parsing the top-level
through various bits and use that to globally discriminate.

Swift SVN r11379
2013-12-17 04:31:40 +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
Argyrios Kyrtzidis
44d46de7c9 Use swift::SourceManager's addNewSourceBuffer() instead of llvm::SourceMgr's AddNewSourceBuffer().
Also remove the SourceLoc parameter from addNewSourceBuffer(). In llvm::SourceMgr
it is used to indicate textual inclusion, which we don't have in swift.

Swift SVN r10014
2013-11-07 00:51:56 +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
8d8b60f973 Code completion: implement result caching per-imported module across muptiple
ASTContexts

This introduces swift::ide::CodeCompletionCache, which is a persistent code
completion result cache.

Right now REPL happens to use it (try importing Cocoa and doing code
completion), and the difference is noticeable.  But completion in REPL is
still slow, because Cocoa goes through the AST Verifier on every completion
(for unknown reasons).

This commit does not implement cache invalidation yet, and it does not use
libcache to evict cache entries under memory pressure.

This commit also introduces two regressions:
- We get fewer Cocoa results that expected.  Module::isModuleVisible in Clang
does not incorrectly reports that that ObjectiveC.NSObject submodule is not
visible from Cocoa.

- We are not implementing the decl hiding rules correctly.  We used to rely on
visible decl lookup to do it for us, but now we have a different data structure
we have real decls from the current module and we have a text-only cache, so we
are forced to reimplement this part of name lookup in code completion.


Swift SVN r9633
2013-10-24 02:13:34 +00:00
Dmitri Hrybenko
0f93a9277d Code completion: complete '!' and '?' on Optional<T>
rdar://14848266


Swift SVN r9377
2013-10-15 21:36:42 +00:00
Doug Gregor
f7b84d4f41 Code completion: add chunks for <, >, and generic parameters.
Swift SVN r9107
2013-10-09 23:11:42 +00:00
Jordan Rose
9d09d9c7a5 Adopt SourceFile for type checking.
Swift SVN r9106
2013-10-09 22:44:33 +00:00
Jordan Rose
09787207fc Push TUKind into SourceFile (as InputKind).
Different SourceFiles in the same module will eventually have different
input kinds (at the very least Main vs. Library).

Swift SVN r9076
2013-10-09 18:38:25 +00:00
Jordan Rose
cba6b2cc70 Use SourceFile in REPL code completion.
Swift SVN r9074
2013-10-09 18:38:19 +00:00
Jordan Rose
f5de2e43d7 Push SourceFile into Parser and REPL somewhat.
Swift SVN r9073
2013-10-09 18:38:17 +00:00
Jordan Rose
597640a5d2 Introduce "SourceFile" within a TranslationUnit.
Right now this is just an extra layer of indirection for the decls,
operators, and imports in a TU, but it's the first step towards compiling
multiple source files at once without pretending they're all in a single
file. This is important for the "implicit visibility" feature, where
declarations from other source files in the same module are accessible
from the file currently being compiled.

Swift SVN r9072
2013-10-09 18:38:15 +00:00
Dmitri Hrybenko
6f4cb05603 Code completion: basic support for completing memebrs of DynamicLookup (id)
Only tested with functions (instance/class functions) declared in swift
classes.  Need more testcases.


Swift SVN r8800
2013-10-01 02:14:25 +00:00