Commit Graph

44 Commits

Author SHA1 Message Date
Xi Ge
c93700aa8b Address several post-commit comments. NFC 2019-02-14 22:09:32 -08:00
Xi Ge
8dbbb2ba1d sourcekitd/format: avoid performing sibling-based indentation for PrefixUnaryExpr.
rdar://47659949
2019-01-31 15:44:19 -08:00
Keith Smiley
2d91af2077 IDE: Fix formatting of closing square brackets
Previously closing square brackets would be caught in the logic for
elements in collections, indenting them to the same level. Now they are
indented with the normal non-sibling logic, which indents them
correctly.
2018-07-25 20:27:32 -07:00
Slava Pestov
5213f80e7e IDE: Remove uses of AbstractFunctionDecl::getParameterLists() 2018-07-22 20:56:56 -07:00
Ben Langmuir
45936f5242 [gardening] Tweak comment wording 2018-04-13 13:49:57 -07:00
Sho Ikeda
976c7f9c27 [gardening][IDE] Replace typedef with using 2018-03-26 13:45:36 +09:00
Xi Ge
7fe3c5cfdd Formatting: Avoid crashing when indent width is 0. rdar://37835956 (#14873) 2018-02-28 11:00:20 -08:00
Xi Ge
61317432d7 Formatting: sanitize formatting option of 0 tab-width. rdar://37835956 (#14861)
If the format option specifies using tab of zero width, we reset the
tab width to a non-zero value.
2018-02-27 13:00:27 -08:00
Saleem Abdulrasool
b7963d8417 IDE: provide const overload for operator*
Provide a const overload for `operator*` for `SourceLocIterator` as the
MSVC C++ runtime uses the const overload for the `std::lower_bound`
algorithm.
2018-02-01 14:33:03 -08:00
John McCall
7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
Slava Pestov
0715eaeaed AST: Move SourceEntityWalker to IDE 2017-11-13 22:10:41 -08:00
Xi Ge
34e2aec662 Parser: use parser to generate a refined token stream to help syntax coloring. (#11809)
This patch allows Parser to generate a refined token stream to satisfy tooling's need. For syntax coloring, token stream from lexer is insufficient because (1) we have contextual keywords like get and set; (2) we may allow keywords to be used as argument labels and names; and (3) we need to split tokens like "==<". In this patch, these refinements are directly fulfilled through parsing without additional heuristics. The refined token vector is optionally saved in SourceFile instance.
2017-09-08 10:28:19 -07:00
Xi Ge
b17ccf1ae7 Formatting: when aligning siblings in indentation, we should respect use tab setting. rdar://32611247 (#11334)
We use white spaces for the remaining that cannot be filled with tabs.
2017-08-04 12:14:23 -07:00
Rintaro Ishizaki
6fa84150c5 [AST] Eliminate IfConfigStmt
Resolves: https://bugs.swift.org/browse/SR-4426

* Make IfConfigDecl be able to hold ASTNodes
* Parse #if as IfConfigDecl
* Stop enclosing toplevel #if into TopLevelCodeDecl.
* Eliminate IfConfigStmt
2017-05-16 12:19:54 +09:00
Xi Ge
df64cd7686 Formatting: Avoid formatting multi-line string literals since it may change behavior. rdar://32135036 (#9582) 2017-05-13 18:21:18 -07:00
practicalswift
437a186032 [gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar) 2017-05-09 11:26:07 +02:00
Slava Pestov
162b2d252e AST: Include gardening to minimize dependencies on Expr.h
A lot of files transitively include Expr.h, because it was
included from SILInstruction.h, SILLocation.h and SILDeclRef.h.

However in reality most of these files don't do anything
with Exprs, especially not anything in IRGen or the SILOptimizer.

Now we're down to 171 files in the frontend which depend on
Expr.h, which is still a lot but much better than before.
2017-03-12 22:26:56 -07:00
Slava Pestov
4f4e6f6ebf Sema: Remove another workaround and fuzz harder
We used to drop the entire generic parameter list if one of the
entries failed to parse. This caused a problem where the generic
parameters were still available for name lookup, so they had
to be special-cased since there's no generic environment set up
in this case.

Now, keep the parts of the generic parameter list around that
parsed successfully.

When I first made the change, almost a hundred crashers regressed;
now all the underlying issues have been fixed.

The result is that in addition to removing a crappy hack we get
some more mileage out of the compiler_crashers, because stuff like
this now builds a generic environment:

class S<T{...}
2017-02-03 17:02:04 -08:00
Slava Pestov
b3cabb0745 Use llvm casts in various places instead of looking at {Expr,Decl,TypeBase}::getKind()
Also add some FIXMEs for some code in debug info emission that
looks incorrect.
2017-01-30 00:08:53 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +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
c46c423da5 Revert "Fix ASan container-overflow in CodeFormatter"
This reverts commit 430c0abd2f.
2016-11-18 13:23:31 -08:00
David Farler
430c0abd2f Fix ASan container-overflow in CodeFormatter
I made an overzealous rebase earlier that caused a bad std::vector
iterator to be indirected.
2016-11-16 16:56:14 -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
Daniel Duan
d0de084a79 [swift-format] add option to indent switch block
add a boolean option to indent switch's block:

```
// with -indent-switch-case
switch xyz {
  case .x:
    doSomething()
}
```

```
// without -indent-switch-case
switch xyz {
case .x:
  doSomething()
}
```
2016-11-03 19:48:41 -07:00
Xi Ge
e5d77911a2 [SourceKit] Indent property getters disregarding of empty bodies. rdar://28049927 (#5246)
[SourceKit] Indentation: when the indented line starts with open brace and the
line before starts with a leading declaration keywords, we never add
indentation level on the brace. rdar://28049927
2016-10-11 19:23:29 -07:00
Xi Ge
7cb5d9a8a2 [SourceKit] When function calls taking multiple closures, align the end of them. rdar://27473586 (#4787) 2016-09-14 19:13:50 -07:00
Xi Ge
365bb52a31 [SourceKit] Avoid adding indentation at the end of a CaptureListExpr. rdar://28193169 (#4749) 2016-09-13 13:33:34 -07:00
Xi Ge
5d07b4b068 [SourceKit][Format] Avoid indenting when multiple function call ends at the same line.
This fixes SR-603.
2016-07-25 17:57:57 -07:00
Daniel Martín
953076d9fc Fix coding style in Formatting.cpp (#3493) 2016-07-13 11:00:01 -07:00
Xi Ge
2ed177046e [SourceKit] Check location validity before getting the line number to fix a crash. rdar://26756189 (#3364) 2016-07-06 21:26:09 -07:00
Argyrios Kyrtzidis
49d786557c Fix bad merge, "#ifdef 0" -> "if 0" 2016-06-05 12:09:07 -07:00
Argyrios Kyrtzidis
20c5f53372 Merge pull request #2891 from practicalswift/remove-commented-out-code
[gardening] Remove commented out code.
2016-06-05 12:06:20 -07:00
practicalswift
2ef95264fc [gardening] Use the preferred form "#ifdef 0" instead of "/*". 2016-06-05 10:28:58 +02:00
practicalswift
d34114fec5 [gardening] Normalize formatting. Use "OS X" instead of "OSX". 2016-06-04 23:38:42 +02:00
practicalswift
57bccc8b06 [gardening] Fix inconsistent formatting. 2016-06-04 00:37:15 +02:00
Argyrios Kyrtzidis
d10220920b [IDE/format] Disable the sibling check for dictionary/array literal elements.
This ends up creating too much indentation in some common cases.
This effectively get us back to indentation behavior of Swift 2.2.

Addresses rdar://26290643.
2016-05-23 17:23:40 -07:00
practicalswift
abfecfde17 [gardening] if ([space]…[space]) → if (…), for(…) → for (…), while(…) → while (…), [[space]x, y[space]] → [x, y] 2016-04-04 16:22:11 +02:00
Ben Langmuir
4d9c9f6098 Move SourceEntityWalker into libAST NFC
It fits right in among our other AST walkers and lets us use it lower in
the stack than libIDE.
2016-04-01 14:14:06 -07:00
Xi Ge
589d9a8a3e CodeFormat: Avoid indenting the close bracket of a closure if the closure is on the RHS of an assignment expression. rdar://24507930 2016-03-29 13:08:55 -07:00
practicalswift
ac87f428ea [gardening] Fix formatting of recently introduced headers. 2016-03-22 21:36:09 +01:00
John Regner
5b9fc3d832 [SourceKit] Add reformat function to libIDE
Move all the rest of the code formatters and helper classes out of the interface.
2016-03-18 21:37:00 -07:00
John Regner
e63678579b [SourceKit] Moved Formatting files into place in libIDE 2016-03-18 21:19:57 -07:00