Commit Graph

64 Commits

Author SHA1 Message Date
Doug Gregor
8336419844 Include completion source location information compound DeclNames.
When one spells a compound declaration name in the source (e.g.,
insertSubview(_:aboveSubview:), keep track of the locations of the
base name, parentheses, and argument labels.
2016-01-25 14:13:13 -08:00
practicalswift
77a1a15676 [gardening] Avoid unnamed parameters. Use same names as in definition. 2016-01-23 23:30:23 +01:00
Michael Ilseman
dc689e607c [Diagnostics] -suppress-warnings and -warnings-as-errors flags
Exposes the global warning suppression and treatment as errors
functionality to the Swift driver. Introduces the flags
"-suppress-warnings" and "-warnings-as-errors". Test case include.
2016-01-15 14:20:44 -08:00
Michael Ilseman
8b5fb7d200 [Diagnostics] Add in treating warnings as errors 2016-01-14 14:39:18 -08:00
Michael Ilseman
ab805ea3a5 [Diagnostics] Refactor and clarify diagnostic behavior rules.
Restores StoredDiagnosticInfo, which is useful to help distinguish
when the user explicitly modifies the behavior of a diagnostic vs
we're just picking up the default kind.

Adds some clarifying comments, and lays out the suppression workflow,
whereby different types of suppression (per-diagnostic, per-category,
etc) have different precedence levels.
2016-01-14 14:32:59 -08:00
Michael Ilseman
80270a9f94 Incorporate Doug's review suggestions 2016-01-11 21:30:18 -08:00
Michael Ilseman
d282fd743d Allow suppressing individual diagnostics.
Extend DiagnosticState to track per-diagnostic desired behaviors,
allowing users of the APIs to individually suppress diagnostics.
2016-01-11 16:48:42 -08:00
Michael Ilseman
31314b19b0 Add ignoreAllWarnings API
New API on DiagnosticEngine to disable the reporting of warnings. No
tests currently, as this is not exposed upwards to any test-able
level, but tests will come when this is exposed e.g. through command
line arguments.
2016-01-10 21:42:51 -08:00
Michael Ilseman
767597d006 Track previous diagnostic behavior
Switch from a fatal-state machine to a previous-behavior-state
machine, which is more flexible in the presence of suppressible
warnings.
2016-01-10 20:35:52 -08:00
Michael Ilseman
dcb1924425 Introduce DiagnosticState to track how we should handle diagnostics
Refactor DiagnosticEngine to separate out diagnostic state
tracking. This allows gives us a base from which to add further
refinements, e.g. warning suppression.
2016-01-10 19:04:19 -08:00
practicalswift
1339b5403b Consistent use of header comment format.
Correct format:
//===--- Name of file - Description ----------------------------*- Lang -*-===//
2016-01-04 13:26:31 +01:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
practicalswift
64f6c59bf4 Prune some redundant #includes 2015-12-28 22:18:46 +01:00
Chris Lattner
d03fc2c536 Prune some redundant #includes, noticed by inspection. 2015-12-27 20:55:01 -08:00
Chris Lattner
3ad108b0be Reapply r29419:
Enhance fixItRemove() to be a bit more careful about what whitespace it leaves around: if the thing it is removing has leading and trailing whitespace already, this nukes an extra space to avoid leaving double spaces or incorrectly indented results.  

This includes an extra fix for looking off the start of a buffer, which extractText doesn't and can't handle.

This fixes <rdar://problem/21045509> Fixit deletes 'let' from non-binding 'if case let' statements, but leaves an extra space




Swift SVN r29449
2015-06-17 16:31:26 +00:00
Ted Kremenek
d13549e607 Revert "enhance fixItRemove() to be a bit more careful about what whitespace it leaves around:"
This was breaking the bots.

Swift SVN r29432
2015-06-17 02:20:52 +00:00
Chris Lattner
6b3167ab36 enhance fixItRemove() to be a bit more careful about what whitespace it leaves around:
if the thing it is removing has leading and trailing whitespace already, this nukes
an extra space to avoid leaving double spaces or incorrectly indented results.  This
fixes <rdar://problem/21045509> Fixit deletes 'let' from non-binding 'if case let' statements, but leaves an extra space



Swift SVN r29419
2015-06-17 00:55:59 +00:00
Jordan Rose
b5e477e6be Allow passing arbitrary enums as diagnostic arguments.
Unless treated specially by the diagnostic system, the enum value will be
converted to its underlying type and treated as an integer. This is useful
for diagnostics that %select between a fixed set of choices.

Removes two special cases; also used by following commit.

Swift SVN r28848
2015-05-20 20:47:59 +00:00
Chris Willmore
6951e460f0 If 'throws' is written after the result type in a function decl, suggest
moving it to before the arrow.

<rdar://problem/20857518> QoI for "throws" in the wrong place

Swift SVN r28492
2015-05-12 22:50:42 +00:00
Chris Lattner
3e3f568179 By far, the most common use of Lexer::getLocForEndOfToken is in
conjunction with .fixItInsert().  As such, introduce a helper named
.fixItInsertAfter() that does what we all want.  Adopt this in various
places around the compiler.  NFC.



Swift SVN r26147
2015-03-15 05:30:04 +00:00
Chris Willmore
776c6a1bd2 Use RAII with DiagnosticTransaction instead of manually opening and
committing transactions.

Swift SVN r25440
2015-02-20 22:51:20 +00:00
Chris Willmore
b31eff245c Add transactional diagnostic support to DiagnosticEngine
Transactions may be opened by calling open() on a DiagnosticTransaction
instance. Any diagnostics recorded during an open transaction will be
saved until the transaction is either committed, at which point they
will be emitted as usual; or aborted, at which point they will be
discarded.

Swift SVN r25437
2015-02-20 22:06:34 +00:00
Jordan Rose
3fcdfd40e9 Remove the "swift/Basic/Optional.h" header.
llvm::Optional lives in "llvm/ADT/Optional.h". Like Clang, we can get
Optional in the 'swift' namespace by including "swift/Basic/LLVM.h".

We're now fully switched over to llvm::Optional!

Swift SVN r22477
2014-10-02 18:51:45 +00:00
Doug Gregor
f52c6789db Track the minimum deployment target and use it for 'unavailable' computations.
Swift SVN r20955
2014-08-02 18:05:45 +00:00
Jordan Rose
cfd7851a67 [Accessibility] When a private type is used in a public way, show its decl.
At the very least, this makes it easier to mark the private type as public
if that's the correct answer.

Swift SVN r19436
2014-07-01 23:42:01 +00:00
Jordan Rose
748efed913 [Accessibility] Protocol witnesses must be as accessible as the protocol.
...unless the type has less accessibility than the protocol, in which case
they must be as accessible as the type.

This restriction applies even with access control checking disabled, but
shouldn't affect any decls not already marked with access control modifiers.

Swift SVN r19382
2014-06-30 23:38:35 +00:00
Jordan Rose
727a7eb77a Attributes: Use class names in the DAK_* enum instead of attribute spellings.
This allows for single attributes that can be spelled multiple ways.
No functionality change.

Swift SVN r18993
2014-06-18 23:28:28 +00:00
Jordan Rose
4e7cee3932 Show notes immediately following a fatal diagnostic, but nothing else.
<rdar://problem/16844281>

Swift SVN r17650
2014-05-07 23:52:14 +00:00
Argyrios Kyrtzidis
9418fb9948 [DiagnosticEngine] Mark module import diagnostic errors as 'fatal' errors, and supress subsequent diagnostics
to avoid a cascade of errors that drown out the original failure.

Swift SVN r17141
2014-05-01 05:24:48 +00:00
Doug Gregor
cd4ca76b6a Introduce the ObjCSelector class to store an Objective-C selector.
We have to work with selectors quite often, so provide an efficient
representation for them. Switch ObjCAttr over to this representation,
which has the nice property that it efficiently represents implicit
@objc attributes with names and allows us to overwrite the Objective-C
name without losing all source information. Addresses
<rdar://problem/16478678>, and sets us up for dealing with selectors
better.

Swift SVN r16327
2014-04-14 20:05:35 +00:00
Dmitri Hrybenko
110f85bc16 Move @exported to use new attribute infrastructure
Swift SVN r16158
2014-04-10 13:35:35 +00:00
Doug Gregor
26c4620b35 Introduce a "descriptive declaration kind" for use in diagnostics, etc.
Provide a fine-grained classification of declarations that can be used
in diagnostics instead of ad hoc %select operations. For now, only cut
over the "overriding a final <whatever>" diagnostic.


Swift SVN r15932
2014-04-04 06:35:42 +00:00
Joe Groff
1585b625f9 Sema: Wire up compound name lookup to UnresolvedSelectorExpr.
Resolve selector references using compound name lookup, pushing DeclNames a bit deeper through the type-checker and diagnostics as necessary.

Swift SVN r14791
2014-03-07 20:52:30 +00:00
Doug Gregor
c4cc906210 Turn a sentinel value for diagnostics into an enum.
Swift SVN r14324
2014-02-24 23:36:31 +00:00
Dmitri Hrybenko
571c9b3c5e Split 'type' keyword into 'static' and 'class'
rdar://15911697


Swift SVN r13908
2014-02-14 14:50:32 +00:00
Jordan Rose
69a8860a53 Move diagnostics enum out-of-line.
Groundwork for splitting up Diagnostics.def.

Swift SVN r12437
2014-01-17 00:15:10 +00:00
Argyrios Kyrtzidis
93c15bed50 [AST] Introduce the ASTPrinter class, and have its callbacks invoked during AST printing.
This provides useful extension points during AST printing.

Swift SVN r11338
2013-12-16 01:26:36 +00:00
Dmitri Hrybenko
9bbfe27615 Add an option for diagnostics -- PointsToFirstBadToken
Diagnostics that point to the first bad token are marked with this option in
Diagnostics.def.  Parser::diagnose treats the source location of such
diagnostics in a special way: if source location points to a token at the
beginning of the line, then it moves the diagnostic to the end of the previous
token.

This behaviour improves experience for "expected token X" diagnostics.


Swift SVN r7965
2013-09-05 23:38:32 +00:00
Dmitri Hrybenko
70f2b64ad9 Add CharSourceRange -- a half-open character range, which will be used in IDE
integration

Motivation: libIDE clients should be simple, and they should not have to
translate token-based SourceRanges to character locations.

This also allows us to remove the dependency of DiagnosticConsumer on the
Lexer.  Now the DiagnosticEngine translates the diagnostics to CharSourceRanges
and passes character-based ranges to the DiagnosticConsumer.


Swift SVN r7173
2013-08-12 20:15:51 +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
Dmitri Hrybenko
c2e05bfcb9 REPL: use new code completion engine from libIDE
Swift SVN r6641
2013-07-26 04:05:28 +00:00
Argyrios Kyrtzidis
68ed84fe68 Allow TypeLocs as parameters to diagnostics.
Eventually TypeLocs coming from the Parser will contain only a TypeRepr and the TypeChecker will resolve and add the type.
Passing a TypeLoc to a diagnostic means "print as user written" (even before typechecking)
and if there is no TypeRepr (e.g. due to a TypeLoc coming from a module without location info) print the type.

Swift SVN r6280
2013-07-16 01:39:35 +00:00
Dmitri Hrybenko
c7421211a3 Factor out logic that creates and configures all objects required for
compilation into a 'Frontend' library.

This library is still not in its best shape, but now it can be reused in
swift-index-test.


Swift SVN r6040
2013-07-06 00:46:19 +00:00
Joe Groff
b5d6103bfc AST: Add an UnresolvedPatternExpr to parse patterns in expr position.
Because of '~=' lookahead and precedence parsing, we need to be able to parse pattern productions in expression position and validate them after name binding. Add an unresolved Expr node that can hold a subpattern for this purpose.

Swift SVN r5825
2013-06-27 00:01:14 +00:00
Ted Kremenek
e35aaec15d Wire up DiagnosticEngine to work with a chain of DiagnosticConsumers.
Swift SVN r5502
2013-06-06 22:27:16 +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
Jordan Rose
19c900b549 Standardize on the term "fix-its" (not "fixits").
The standard code spelling of this is "FixIt", not "Fixit".

Swift SVN r4788
2013-04-18 00:42:57 +00:00
Jordan Rose
519c9aec9e Thread fix-its all the way through the diagnostics machinery.
Fix-its are now working!

Feedback on the API is welcome. I mostly took what was in Clang as a model,
so the usual way to use a FixIt is to pipe it into an active diagnostic:

  << Diagnostic::FixIt::makeInsertion(Tok.getLoc(), "&")
  << Diagnostic::FixIt::makeDeletion(E->getRange())
  << Diagnostic::FixIt::makeReplacement(E->getRange(), "This")

(Yes, of course you can specify the first two in terms of makeReplacement,
but that's not as convenient or as communicative.)

I plan to extend the expected-* notation to include a notation for fix-its
before converting any other diagnostics over, but this is a start.

Swift SVN r4751
2013-04-16 01:46:35 +00:00
Jordan Rose
49c43d84e6 Allow diagnostics to take either a char range or a token range (SourceRange).
This will be necessary for things like typo-correction, but currently
serves no purpose because all of our diagnostics are token-based. It's
going to be the base range type for Swift fix-its, though, so I thought I'd
get it in place now.

Swift SVN r4750
2013-04-16 01:46:31 +00:00
Doug Gregor
263cf27548 Use the pretty-printer to render imported declarations for diagnostics.
Note: this is an experiment.

When we're asked to render a diagnostic for a declaration that does
not have source information, pretty-print the declaration into a
buffer and synthesize a location pointing into that buffer. This gives
the illusion of Clang-style diagnostics where we have all of the
source headers, but without actually requiring that source location
information. It may prove useful or infuriating, but at the very least
it might help us understand how the importer works. Example:

cfuncs_diags.swift:14:7: error: no candidates found for call
  exit(5)
  ~~~~^~~
cfuncs_diags.swift:6:6: note: found this candidate
func exit(_ : Float) {}
     ^
cfuncs.exit:1:6: note: found this candidate
func exit(_ : CInt)
     ^



Swift SVN r3434
2012-12-11 00:21:20 +00:00