Commit Graph

4049 Commits

Author SHA1 Message Date
Dmitri Hrybenko
469c01cc46 Update comment and parameter names: SourceLoc::getAdvancedLoc():
it accepts the offset in bytes, not in characters


Swift SVN r7057
2013-08-08 22:05:32 +00:00
Dmitri Hrybenko
e93bcda055 Rename SourceManager::rangeContainsLoc() to rangeContainsTokenLoc()
to emphasize its limitations


Swift SVN r6999
2013-08-07 21:05:11 +00:00
Dmitri Hrybenko
686f9ec7fc SourceManager: add functions that compare SourceLocs and SourceRanges
Swift SVN r6994
2013-08-07 20:06:12 +00:00
Anna Zaks
aaa4b2c332 [SIL Printer] Add optional source location printing.
Added a -v(verbose) option to swift that will trigger verbose printing in SIL
Printer. SIL Printer will print the location info only in the verbose mode.

Here is the example of the format - only the line and colon are displayed for
brevity:

%24 = apply %13(%22) : $[cc(method), thin] ((), [byref] Bool) -> Builtin.Int1 // user: %26 line:46:10

(This will be used to test the validity of SILLocation info.)

Swift SVN r6991
2013-08-07 18:39:48 +00:00
Jordan Rose
9d5c803aff Enable specific-decl imports.
Note that the import kind is not checked yet; this is effectively our old
behavior for "import swift.print".

Infrastructure: move Module::forAllVisibleModules out-of-line, and add
makeStackLambda to STLExtras for using a non-escaping lambda with
std::function.

Swift SVN r6852
2013-08-02 21:00:41 +00:00
Argyrios Kyrtzidis
99512e4220 When printing SourceRanges, add an option to not print the text as well.
Swift SVN r6836
2013-08-02 02:50:32 +00:00
Dmitri Hrybenko
2c7dc9e967 SourceManager::setCodeCompletionPoint(): allow setting code completion point multiple times.
This is required to do multiple completions in the REPL.


Swift SVN r6826
2013-08-02 00:07:02 +00:00
Dmitri Hrybenko
7684d6dc2a Add a good diagnostic for a hashbang line when it is not allowed
Also centralizes the knowledge about whether the hashbang is allowed in the
SourceManager.  This fixes a bug in tokenize() because previously it just had
to guess.


Swift SVN r6822
2013-08-01 23:07:43 +00:00
Dmitri Hrybenko
5cea4ebf41 Code completion: put CodeCompletionOffset on SourceManager instead of passing
around everywhere

Fixes:
rdar://14585108 Code completion does not work at the beginning of the file
rdar://14592634 Code completion returns zero results at EOF in a function
                without a closing brace


Swift SVN r6820
2013-08-01 22:08:58 +00:00
Enrico Granata
c3d42b5f86 Removing the demangleType() API and the --type flag to swift-demangle
Types now have proper mangled names of the form _Tt<...> so they don't need any special treatment



Swift SVN r6816
2013-08-01 21:00:05 +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
Enrico Granata
c75fe924a1 Moving the Swift demangler from libSIL to libBasic
Plus, a couple of minor cosmetic changes that I had held off for a couple days now



Swift SVN r6691
2013-07-29 17:42:57 +00:00
Argyrios Kyrtzidis
66d1e516c8 Refactor how multiple parsing passes and delayed parsing works.
-Introduce PersistentParserState to represent state persistent among multiple parsing passes.
  The advantage is that PersistentParserState is independent of a particular Parser or Lexer object.
-Use PersistentParserState to keep information about delayed function body parsing and eliminate parser-specific
  state from the AST (ParserTokenRange).
-Introduce DelayedParsingCallbacks to abstract out of the parser the logic about which functions should be delayed
  or skipped.

Many thanks to Dmitri for his valuable feedback!

Swift SVN r6580
2013-07-25 01:40:16 +00:00
Jordan Rose
e3999dde36 [serialization] Handle absent protocol conformances.
These still need to be serialized, because they are one-to-one with the
type's protocol list, but don't actually require any data. Found on
attempting to emit a module for the standard library.

Most of the churn here is moving Interleave.h to a more general STLExtras.h.

Swift SVN r6167
2013-07-11 18:38:50 +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
43061a7391 Move NullablePtr from llvm into Swift.
There are no other uses of it outside of swift.

Swift SVN r6113
2013-07-10 15:33:40 +00:00
Argyrios Kyrtzidis
f478157ab4 Revert "Print source ranges of the AST nodes when dumping the AST."
See if it fixes the buildbot.
This reverts commit 5957.

Swift SVN r5960
2013-07-02 16:45:07 +00:00
Argyrios Kyrtzidis
0a3fc1b195 Print source ranges of the AST nodes when dumping the AST.
Swift SVN r5959
2013-07-02 00:42:01 +00:00
Dave Abrahams
096ffc6eaf Silence warnings in the release build
Swift SVN r5950
2013-07-01 21:42:16 +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
4e982aadd7 Quiet warnings about TreeScopedHashTable forward-declared as a class.
Swift SVN r5897
2013-06-29 04:50:12 +00:00
Dmitri Hrybenko
8cc8ca9f60 Fix a warning: declare TreeScopedHashTableScopeImpl as a struct consistently
Swift SVN r5892
2013-06-29 01:00:06 +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
Joe Groff
8a5cec78e1 ClangImporter: Enable import of objc protocol types.
Remove the -import-objc-protocol-types flag and make it the default behavior. Update swiftFoundation's NSDictionary extensions to use NSCopyingProto keys instead of plain id.

This breaks a test because the type-checker isn't able to solve for NSCopyingProto from a literal type, requiring a manual 'as NSNumber/NSString' coercion to help it along.

Swift SVN r5641
2013-06-18 02:31:20 +00:00
Joe Groff
e9cd5b255c ClangImporter: Conditionally reenable import of ObjC protocol types.
Import ObjC protocol decls into Swift with the [class_protocol] and [objc] attributes. Add an -import-objc-protocol-types flag to reenable import of ObjC qualified object types as Swift protocol types.

Swift SVN r5604
2013-06-16 02:08:24 +00:00
Jordan Rose
c8958a232e Replace PointerIntUnion with a PointerUnion-compatible Fixnum type.
Per discussion on swift-dev, we'd prefer to have a "pointer-like" integer
with limited bit width, to reuse all the existing infrastructure for
pointer-like types, rather than invent another new data structure.

Swift SVN r5529
2013-06-08 00:18:19 +00:00
Joe Groff
dbc314cdab Add a -use-malloc switch for memory debugging.
This flag makes ASTContext and SILModule's allocators go through malloc instead of using bump pointer allocators, so that GuardMalloc or similar tools can be used to look for memory bugs.

Swift SVN r5472
2013-06-04 20:35:01 +00:00
Doug Gregor
c038ab92e6 Remove -no-constraint-checker/-constraint-checker and the corresponding language option.
Swift SVN r5387
2013-05-29 22:16:34 +00:00
Joe Groff
12c5999b44 Strip out -no-nsstring-is-string flag and associated LangOptions bit.
Swift SVN r5383
2013-05-29 19:42:12 +00:00
Joe Groff
8693c5efaa SIL: Emit String-to-NSString conversions.
If -nsstring-is-string is enabled, lower Strings in cc(c) and cc(objc) function types to NSString, and when calling them, insert calls to StringToNSString/NSStringToString to perform the bridging conversion.

This isn't quite ready for prime-time yet, because we still need to emit the inverse bridging for ObjC method thunks, and I haven't tested the IRGen end of things yet.

Swift SVN r5355
2013-05-26 20:29:09 +00:00
Jordan Rose
965035dc2a [serialization] Load the decl and type offset arrays from the module.
...but don't do anything with them yet. This does check that they're being
correctly serialized, though.

This introduces a new ADT, PointerIntUnion, which like PointerUnion is an
efficient variant type using the lowest bit of data as a discriminator.
By default, the union can store any pointer-bits-minus-one-sized integer,
but both the integer type and the underlying storage type can be
customized.

Swift SVN r5321
2013-05-25 01:34:52 +00:00
Doug Gregor
27575443e2 [Constraint solver] Use the new constraint solver, start deleting the old one.
The new constraint solver is very close to providing parity with the
old solver, and is significantly faster, so cut over to the new
solver. There are minor adjustments to two tests: one where we're
losing sugar (Int becomes Int64) and another where our ignorance of
overload resolution means we don't reject something silly that we
should.

Note that this only affects the *solver* component of the
constraint-based type checker; we haven't completely obsoleted the old
type checker yet.



Swift SVN r5281
2013-05-23 20:18:22 +00:00
Doug Gregor
00c8099fe6 [Constraint solver] Initial work on a less horrible solver.
This solver handles most of what the old solver does (enabling it by
default only causes 9 test failures), but is radically simpler and
already significantly faster (~50% slower than the old-old type
checker on swift.swift). There are some egregious hacks here to still
be eliminated (see FIXMEs), but it's a start.


Swift SVN r5272
2013-05-22 20:01:32 +00:00
Chris Lattner
02f02fca0f [overpedantic] Get plurality right in the # users comment, printing:
%0 = tuple ()                                   // user: %1
  %1 = return %0 : $()

instead of "users".



Swift SVN r5268
2013-05-22 17:58:44 +00:00
Chris Lattner
0c294501d6 add a "container" version of interleave, use it in SILPrinter a bit more.
No behavior change.


Swift SVN r5262
2013-05-22 16:52:51 +00:00
Joe Groff
b34a665fb6 Fix Optional assignment bugs.
Assigning from Nothing to Nothing should be a no-op, not copy a junk value into the destination. Also, in move-assignment we should reset the source (and thereby call the destructor) instead of abandoning the source value after moving it.

Swift SVN r5234
2013-05-20 22:29:19 +00:00
Jordan Rose
f6822e8c53 Fix -Wdocumentation issues.
No functionality change.

Swift SVN r5127
2013-05-09 21:40:33 +00:00
Joe Groff
c0a44f71c9 IRGen: Reify SpecializeInst thunks.
Teach IRGen how to emit thunks for SpecializeInsts that aren't immediately called and actually get used as values. This allows generic function instance to get passed around as values (again), and is a step along the way to making closures in generic contexts work (so we can specialize the local function, then partially apply its specialized context).

This doesn't work yet if we specialize to local archetypes--SIL needs to learn that we need a [thick]-typed thunk for local archetype specializations, in order to pack the metadata and wtables for the local type variables.

Swift SVN r5083
2013-05-07 23:39:06 +00:00
Doug Gregor
01e1240b35 [Clang Importer] Map NSString* function parameters/results to String.
This is the trivial part of <rdar://problem/13723763>, which performs
an import-time remapping of NSString* to String. Because this change
completele breaks IR generation, it is under the off-by-default flag
-nsstring-is-string.


Swift SVN r5058
2013-05-06 20:07:42 +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
1013781bcc Parse: Allow Unicode identifier characters.
Extend the character set for identifiers according to WG14 N1518, which recommends an extended character set for identifier start and continuation characters in C. Mangle identifiers containing non-ASCII characters by borrowing the Punycode encoding used for international domain names.

No Unicode operators just yet.

Swift SVN r4968
2013-04-28 21:39:02 +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
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
Joe Groff
f6c72885a6 SILGen: Emit curried function calls.
Teach SILGen's CallEmission how to emit calls to an uncurry level above the natural uncurry level of the callee. Factor out a Callee object (like in IRGen) that encapsulates how to emit an abstract callee at any uncurry level. Currently only currying standalone non-generic functions works.

Swift SVN r4720
2013-04-12 23:10:48 +00:00
John McCall
e46bb068f1 Add ASSERT_IMPLEMENTS_STATIC for overrides of static methods.
Swift SVN r4704
2013-04-12 01:39:50 +00:00
John McCall
9fb7a07e1e Add AssertImplements.h, for asserting that a class overrides a method.
Swift SVN r4702
2013-04-12 00:54:52 +00:00
Joe Groff
bfd2f85b5c Parse 'fallthrough' statements.
Create a new FallthroughStmt, which transfers control from a 'case' or 'default' block to the next 'case' or 'default' block within a switch. Implement parsing and sema for FallthroughStmt, which syntactically consists of a single 'fallthrough' keyword. Sema verifies that 'fallthrough' actually appears inside a switch statement and that there is a following case or default block to pass control to.

SILGen/IRGen support forthcoming.

Swift SVN r4653
2013-04-10 17:30:42 +00:00
Chris Lattner
e6a644780f remove an attribute.
Swift SVN r4569
2013-04-01 23:25:09 +00:00
Joe Groff
b105e02534 IRGen: Lower SIL bb arguments to LLVM phi nodes.
Swift SVN r4493
2013-03-27 17:07:17 +00:00