Commit Graph

140 Commits

Author SHA1 Message Date
Jordan Rose
63cd1258ea Stop using SourceManager::getBufferIdentifierForLoc to find buffer IDs
The right way is findBufferContainingLoc. getBufferIdentifierForLoc is
both slower and wrong in the presence of #sourceLocation.

I couldn't come up with a test for the change in IDE/Utils.cpp because
refactoring still seems to be broken around #sourceLocation. I'll file
bugs for that.
2018-08-29 11:46:41 -07:00
Jordan Rose
537954fb93 [AST] Rename several DeclContext methods to be clearer and shorter (#18798)
- getAsDeclOrDeclExtensionContext -> getAsDecl

This is basically the same as a dyn_cast, so it should use a 'getAs'
name like TypeBase does.

- getAsNominalTypeOrNominalTypeExtensionContext -> getSelfNominalTypeDecl
- getAsClassOrClassExtensionContext -> getSelfClassDecl
- getAsEnumOrEnumExtensionContext -> getSelfEnumDecl
- getAsStructOrStructExtensionContext -> getSelfStructDecl
- getAsProtocolOrProtocolExtensionContext -> getSelfProtocolDecl
- getAsTypeOrTypeExtensionContext -> getSelfTypeDecl (private)

These do /not/ return some form of 'this'; instead, they get the
extended types when 'this' is an extension. They started off life with
'is' names, which makes sense, but changed to this at some point.  The
names I went with match up with getSelfInterfaceType and
getSelfTypeInContext, even though strictly speaking they're closer to
what getDeclaredInterfaceType does. But it didn't seem right to claim
that an extension "declares" the ClassDecl here.

- getAsProtocolExtensionContext -> getExtendedProtocolDecl

Like the above, this didn't return the ExtensionDecl; it returned its
extended type.

This entire commit is a mechanical change: find-and-replace, followed
by manual reformatted but no code changes.
2018-08-17 14:05:24 -07:00
Slava Pestov
31a570d53c AST: Replace TypeBase::getRValueInstanceType() with getMetatypeInstanceType()
That is, don't look through InOutType anymore, and update callers to
call getInOutObjectType() as well (or not, where it was obvious to me
that InOutType could not appear).

This surfaces more remaining uses of getInOutObjectType() directly.
2018-08-13 21:13:10 -07:00
Slava Pestov
b67752a15f Minor NFC cleanups 2018-08-08 10:18:49 -07:00
Jordan Rose
fc9ea1e329 Add Lexer::IsHashbangAllowed, drop SourceManager::getHashbangBufferID (#18534)
Having this be a single buffer hardcoded in the SourceManager and set
by all clients is silly. SourceFiles with the 'Main' kind are allowed
to have hashbang lines (`#!`), other files are not. And anyone
manually setting up a Lexer can decide for themselves.

No intended behavioral change.
2018-08-07 08:25:05 -07:00
Ben Langmuir
31eae3675b [sourcekitd] Remove XPCTracing
This code was an experiment in how to collect information after a crash,
that did not end up being used.  It's unclear how much it has bitrotted
at this point, since it has no tests and was not designed with automated
testing in mind.  Parts of it interfere with some changes I want to make
to the underlying tracing mechanism, so I am finally removing it.  This
also lets us remove the buffer copying in the parts of tracing used by
the compile notifications, improving performance.

For rdar://39538847
2018-04-19 11:52:38 -07:00
Ben Langmuir
79d641d89b [sourcekit] Add optional compile notifications
When enabled, send a notification before/after every "compilation",
which for now means `performSema`. This piggy-backs and modifies some
existing code that we had for "tracing" operations in sourcekitd that
unfortunately was untested.  At least now some of the basic parts are
tested via the new notifications.

Part of rdar://38438512
2018-03-29 14:59:30 -07:00
Ben Langmuir
38963ce883 [sourcekit] Tweak traced operation to be single-operator per RAII object
This is how it was used in all but one place anyway, and makes it easier
to understand.  It also aligns better with some further refactoring I
want to do...
2018-03-29 14:05:57 -07:00
Nathan Hawes
60a6c02328 Merge pull request #15301 from nathawes/rdar38550117-range-info-on-comment-mark-crashing
[refactoring] fix RangeInfo crash inside comment, due to unhandled invalid CharSourceRange
2018-03-16 14:46:10 -07:00
Nathan Hawes
ff76c265f3 [refactoring] fix RangeInfo crash inside comment, due to unhandled invalid CharSourceRange.
Resolves rdar://problem/38550117
2018-03-16 11:24:44 -07:00
Slava Pestov
34fd4ae512 AST: Use DeclBaseName::Kind::Constructor
Fixes <rdar://problem/35852727>, <https://bugs.swift.org/browse/SR-1660>,
<https://bugs.swift.org/browse/SR-6557>.
2018-03-16 00:25:56 -07:00
Slava Pestov
615d068d63 Sema: Replace some uses of getBaseIdentifier() with userFacingName() 2018-03-14 22:26:58 -07:00
Rintaro Ishizaki
3f232e753b [SourceKit] Add defensive guard for invalid offset
Invalid offset used to cause a inifinite loop in Lexer in some race
condition.

This is a quick fix until we fix underlying problem in SourceKit.
2018-02-27 18:14:52 +09:00
Huon Wilson
cb60dbeee2 [IDE] Teach type checker about conditional conformance extensions.
Before conditional conformances, the archetypes in conformance
extensions (i.e. extension Foo: SomeProtocol) were equivalent to those
in the type decl, with the same protocol bounds and so on. The code for
printing "synthesized" members relied on this fact. This commit teaches
that code to deal with archetypes in the conditional conformance
extension when required.

Fixes rdar://problem/36553066 and SR-6930.
2018-02-13 17:37:15 +11:00
Nathan Hawes
cbf07dae19 [CursorInfo] Fix crash on init call of inner NTD with generic outer NTD
Resolves rdar://problem/35819975
2018-01-25 13:24:51 -08:00
Saleem Abdulrasool
aaeac4cb34 SourceKit: use explicit struct constructor for C++14
Explicitly instantiate the `CursorInfoData` instances when using it with
the default constructor rather than using the inline initializer list.
This is needed to build with C++14 mode.  Provide a default value for
the `Optional` type in the structure which prevents a non-copy default
constructor from being synthesized.  NFC.
2017-12-18 12:44:19 -08:00
Slava Pestov
0715eaeaed AST: Move SourceEntityWalker to IDE 2017-11-13 22:10:41 -08:00
Alex Hoppen
746bfc6d59 [Refactoring] Add refactoring action to move type members to extension (#12795)
This implements SR-6297.
2017-11-09 11:08:34 -08:00
Davide Italiano
3b800aa11f [gardening] Remove unused lambda capture(s). NFCI. 2017-09-10 21:44:38 -07:00
Xi Ge
7f29b362d6 SourceKitd: Rename SemaToken to ResolvedCursorInfo. NFC (#11680) 2017-08-29 15:34:15 -07:00
Argyrios Kyrtzidis
60a91bb736 [refactoring] Upstreaming the implementation for Swift local refactoring (#11568)
[refactoring] Upstreaming the implementation for Swift local refactoring
2017-08-22 16:50:16 -07:00
Xi Ge
7595ed353e [RangeInfo] Address Argyrios' code review comments. NFC (#11114) 2017-07-21 18:10:52 -07:00
Xi Ge
ac348b597a [RangeInfo] Using the underlying token array reference to represent the content of a range under selection. (#11106)
Comparing to CharSourceRange, token stream is a better way because we can preserve comment information at the start of the range.

Needed for rdar://33437855
2017-07-21 16:19:25 -07:00
Slava Pestov
fb9d410350 AST: Rename UnqualifiedLookupResult => LookupResultEntry
There's a similar LookupResult::Result type in Sema, and I'd like
to combine the two.
2017-07-18 22:09:02 -07:00
Xi Ge
0bba7d900b ASTPrinter: Remove ASTPrinter's dependency on Sema. (#10985) 2017-07-14 20:02:25 -07:00
Xi Ge
243ec5ac86 Name translation: Allow type name translation when cursor points to constructor call. rdar://33163114 (#10872) 2017-07-11 12:46:52 -07:00
Xi Ge
351ffabf1a CursorInfo: silence a warning after recently introducing a new enum case. (#10412) 2017-06-20 15:32:27 -07:00
Xi Ge
1ea4d9ff98 CursorInfo: Teach SemaLocResolver to recognize the start of an expression, if the location cannot be further refined to other kind, e.g. a reference. rdar://32749670 2017-06-19 13:28:36 -07:00
Alex Hoppen
58c956a29a [Misc] Preparations for removal of getName on ValueDecl
With the introduction of special decl names, `Identifier getName()` on
`ValueDecl` will be removed and pushed down to nominal declarations
whose name is guaranteed not to be special. Prepare for this by calling
to `DeclBaseName getBaseName()` instead where appropriate.
2017-05-28 19:13:24 -07:00
Jordan Rose
c0ccdb1626 Change getBaseName to return DeclBaseName instead of Identifier (#9968)
This changes `getBaseName()` on `DeclName` to return a `DeclBaseName`
instead of an `Identifier`. All places that will continue to be
expecting an `Identifier` are changed to call `getBaseIdentifier` which
will later assert that the `DeclName` is actually backed by an
identifier and not a special name.

For transitional purposes, a conversion operator from `DeclBaseName` to
`Identifier` has been added that will be removed again once migration
to DeclBaseName has been completed in other parts of the compiler.

Unify approach to printing declaration names

Printing a declaration's name using `<<` and `getBaseName()` is be
independent of the return type of `getBaseName()` which will change in
the future from `Identifier` to `DeclBaseName`
2017-05-28 17:55:03 -07:00
Xi Ge
d6b4c3e77b RangeInfo: unbox switch statement to ensure all branches agree on return information. rdar://32289109 (#9788) 2017-05-19 14:36:56 -07:00
Xi Ge
83183abc38 RangeInfo: Add a new range info kind that describes part of a parent expression. rdar://32039874 (#9707) 2017-05-17 14:21:47 -07:00
Xi Ge
9c6e3bd398 RangeInfo: Use CharSourceRange to represent the selected range, NFC. rdar://32225277 (#9660) 2017-05-16 15:45:30 -07:00
Ben Langmuir
c89d024cd2 [sourcekitd] When searching for a clang decl, look at overrides
Allows us to do name-transation on an override of a clang decl.

rdar://problem/32187817
2017-05-14 15:05:35 -07:00
Ben Langmuir
8aaf2d64ed [sourcekitd] Take the colons out of name-translation API
This makes us more lenient about what we accept for Objective-C
selectors by allowing you to include or not include the trailing colons.
We don't actually need that information, because we have access to the
declaration, so it was only being used for validation, which made the
API harder to use for clients that didn't carefully track zero vs
one-arg selector names.

Also remove the colons from the response, and instead add a bit to say
whether it is a zero-arg or one-arg selector.  This makes the response
easier to use for clients that don't care about this information, and
more consistent with the change to the input.

rdar://problem/32177934
2017-05-14 09:57:12 -07:00
Ben Langmuir
773434416f Merge pull request #9395 from benlangmuir/no-cancel-cursor
[cursor-info] Add a way to opt out of automatic request cancellation
2017-05-08 13:28:55 -07:00
Xi Ge
166d388de0 RangeInfo: stuff a bit about whether the selected range exits. (#9389) 2017-05-08 13:28:32 -07:00
Ben Langmuir
d13b1c719f [cursor-info] Add a way to opt out of automatic request cancellation
The OncePerASTToken machinery lets us automatically cancel "stale"
requests after a new one comes in.  This avoid wasting time processing
requests that have been superceded, which is common for cursor-info, but
sometimes you really want to get results even later, so this commit adds
a way to opt out of the cancellation.

Incidentally, disable cancellation of name translation, which doesn't
really make sense and no one should be relying on that.

rdar://problem/31905379
2017-05-08 12:01:33 -07:00
Ben Langmuir
651bb4c506 [cursor-info] Tweak check to not report parent_loc on locals in body
We were checking only for the specific loc of the declaration of the
param, but that didn't handle references to a local parameter inside the
body.

rdar://problem/32019195
2017-05-05 10:51:30 -07:00
Xi Ge
e9f014a446 [SourceKit] Avoid reporting parent locations for internal only parameter names. rdar://30702790 2017-05-04 12:57:14 -07:00
Ben Langmuir
7e5dd1fa01 [sourcekitd] Allow mising name pieces preferred names
With the interpretation that they mean to retain whatever the name
piece was in the original name.
2017-04-25 15:25:53 -07:00
practicalswift
797c2d8118 [gardening] Fix end of namespace comments 2017-04-20 22:01:01 +02:00
practicalswift
a596961187 [gardening] Make parameter name comments match actual parameter names 2017-04-20 13:47:10 +02:00
Nathan Hawes
534ec7ed87 Merge pull request #8569 from nathawes/rdar30248264-cursorinfo-invalid-base-type
[cursor-info] Fix crash due to invalid base type in the PrintOptions passed to the AST printer
2017-04-06 17:11:33 -07:00
Nathan Hawes
53e1bdc1e3 [cursor-info] Fix crash due to invalid base type in the PrintOptions passed to the AST printer
Resolves rdar://problem/30248264
Also added test cases for rdar://problem/30292429 (already fixed)
2017-04-06 16:04:07 -07:00
Xi Ge
1fcbc90f5f [SourceKit] Use offset to indicate the locations of parameters' parents to facilitate subsequent cursor-info requests. 2017-04-04 17:32:30 -07:00
Xi Ge
f669afff50 [SourceKit] When reporting the cursor info for parameter decls, report the locations of the function-like entities they belong to. rdar://30702790 (#8541) 2017-04-04 15:24:36 -07:00
swift-ci
a460cbbd28 Merge pull request #8516 from nkcsgexi/asan-scope 2017-04-03 16:26:22 -07:00
Xi Ge
6f6d4fc50e SourceKit: Fix a stack-use-after-scope issue found by ASAN. rdar://31117311 2017-04-03 15:10:33 -07:00
Xi Ge
9e76187829 SourceKit: Simplify some unnecessary vector size initializations. NFC (#8502) 2017-04-03 13:51:37 -07:00