Commit Graph
21 Commits
Author SHA1 Message Date
Chandler Carruth 2a39e83779 Fix a new C-style cast clang-tidy error in #3963. (#3965)
This isn't *technically* a C-style cast, but a function-style cast. And
newer versions of `clang-tidy` no longer fire on this code, so it is a
little sad to have to work around. But the version on our build bots
seems old enough to still hit this issue (and possibly some others).

Our merge queue also doesn't seem to catch these reliably, but that's
for a separate PR.
2024-05-21 15:22:47 +00:00
Richard Smith 23f9065949 Implement proposal #3927. (#3963)
Change syntax for package declaration to put the `impl` keyword at the
start and remove the `api` keyword.

To support this, rearrange processing of package, library, and import
declarations to use the general modifier handling support in declaration
parsing rather than special-case logic.

There is an ambiguity in `impl package.Foo as Bar`, which we resolve by
treating `package` as an introducer after a modifier only if it's not
followed by `.`.
2024-05-21 00:36:03 +00:00
Jon Ross-Perkins ecb300ee5e Move 'export name' out of the import section. (#3950)
This implements recent updates to #3938
2024-05-17 18:26:14 +00:00
Jon Ross-Perkins a16842ab37 Add export keyword handling. (#3944)
This provides `export import` logic in lex, parse, and check; `export
name` logic is only in lex and parse, not check.

I think with `export name` I'm going to need to modify import_ref and
some consolidation logic, whereas `export import` seems feasible to keep
as primarily import logic. Given the implementations were looking like
they'd diverge more substantially, I thought it'd be helpful to cut the
PR here.
2024-05-10 22:54:06 +00:00
Richard Smith c5b7ff212b Parsing support for adapt declarations. (#3871) 2024-04-09 13:27:33 +00:00
Jon Ross-Perkins 1437b0e26d Implement 'alias' with transparent semantics. (#3701)
Adds `BindAlias` with a hybrid of `BindName` and `NameRef` semantics. I
think it's slightly closer to `BindName` because it introduces a name,
so I'm going more in that direction. This also matches the need for
`bind_name_id` with imports on enclosing scopes.

Note, only things that look like a name reference are being allowed on
the RHS of `alias`. This includes builtins that look like name
references, such as `bool`, but not ones that turn into values
underneath, such as `false`.
2024-02-14 18:33:18 +00:00
kshokhin 65e95942de Choice parsing in toolchain (#3574)
Implement Choice parsing in toolchain according to
[design](https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/sum_types.md).
2024-01-23 18:22:27 +00:00
josh11bandJon Ross-Perkins 6067ca3f49 Change return of SkipPastLikelyEnd to be last consumed token (#3493)
This approach means the parse subtree includes the full token range
consumed.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2023-12-11 22:11:09 +00:00
josh11bandJon Ross-Perkins 5f439b842b Parsing impl...as (#3473)
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2023-12-09 04:04:00 +00:00
josh11b b7d129b88c Add PushState overload to combine Parse::State change with StateStackEntry (#3485)
Shortens a common `PushState` pattern
2023-12-08 23:58:30 +00:00
Jon Ross-Perkins 50071532fe Refactor state construction and change how the decl loop makes state. (#3467)
Building on #3463. The PushState+PopState to construct a state feels
worth cleanup. The rest is just kind of making it easier to do without
adding another PushState overload.
2023-12-08 17:29:23 +00:00
2705a32b92 Refactor the decl scope loop to consolidate modifier handling. (#3463)
Building on #3462, trying to make the flow easier to see, also making a
little more use of macros for boilerplate modifier handling.

---------

Co-authored-by: josh11b <josh11b@users.noreply.github.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2023-12-08 17:04:05 +00:00
Jon Ross-Perkins 9b194a31c9 Support modifiers on namespace, in theory. (#3462)
In theory because none are allowed. This is to improve consistency in
handle_decl_name_scope's modifier handling, removing the namespace
special-case.

I noticed there's a crash bug on `impl <declaration>` which I'll address
separately.

This builds on #3461.
2023-12-06 22:45:19 +00:00
Jon Ross-Perkins d73729179a Switch modifiers to use distinct parse nodes. (#3461)
This is supporting a direction that all parse nodes should correspond to
a single token, allowing for reduced tokenized buffer access during
checking (it's still necessary for diagnostics, and some literals).

One of the justifications for a unified parse node was implementation
LOC: note this is slightly smaller, using macros to reduce some
duplication. While this does add more switching in HandleDeclScopeLoop,
that's offset by less explicit switching in the check handlers. Also, I
think the duplication in HandleDeclScopeLoop can be reduced by shifting
the flow there, which I'll do in a separate PR.
2023-12-06 22:14:53 +00:00
josh11b a970b1e587 Require extend before base: BaseType; (#3459) 2023-12-06 20:14:16 +00:00
josh11bandJon Ross-Perkins fada410559 Support declaration modifier keywords (#3412)
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2023-12-05 22:45:57 +00:00
Richard Smith 7dffa0c7ec Support for base: T;, .base, x.base. (#3450)
No support for `extend base` yet, in an effort to minimize collisions
with #3412.
2023-12-04 22:45:59 +00:00
Jon Ross-Perkins 3f208e27f9 Align on FileStart/FileEnd for naming. (#3428)
The lexer has been using EndOfFile form (stemming from EOF), parser went
to FileEnd form. This consolidates on FileEnd form.
2023-11-29 16:36:57 +00:00
Jon Ross-Perkins 204c04dbb9 Add more package and import support. (#3402)
This should cover:

```
library "lib" api;
import Foo library default;
import library default;
import library "lib";
```

This splits out `PackageName` and `LibraryName` to their own parse nodes
so that checking can ignore them and still get a balanced parse tree
(otherwise, we essentially need to implement handling of the parse nodes
only to remove the identifiers/string literals -- the optional names
mean we can't blindly do that as before). For reference, these nodes
don't need to be handled because CheckParseTree will need to directly
funnel import information along with checked IRs.
2023-11-16 17:09:36 +00:00
Richard SmithandJon Ross-Perkins 2715e2276e Parsing and basic checking for abstract class and base class. (#3385)
For now, we require the same introducer to be used each time a class is
declared, but see #3384.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2023-11-13 20:38:21 +00:00
josh11b 109e7889dd Rename files to use abbreviations (#3389)
Reflects these recent PRs:
* #3375 
* #3382
2023-11-11 00:25:40 +00:00