Commit Graph
10 Commits
Author SHA1 Message Date
Richard Smith 7d9340880e Separate ClassType from ClassDeclaration. (#3329)
Retain the `ClassDeclaration` node to represent a syntactic declaration
of a class (including possibly a declaration of a generic class), but
use a separate SemIR node to represent the class type itself. This
allows us to give the two separate treatment.

The `ClassDeclaration` is still entered into the name lookup table for
its enclosing scope, but when it is named in an expression, the class
type is produced instead. When the class declaration is named in a
declaration name, it can be used to define members of the class, but an
expression that resolves to the class type cannot be used to define
members of the class.

In order to distinguish these cases, use `Name` rather than
`NameExpression` for the left-hand side of a `QualifiedName` parse node.
This removes the only use of the `Expression` form of a declaration
name, so that is also removed.

In the future, `ClassType` will also be used to describe types such as
`Vector(T)`, for which there is no corresponding `ClassDeclaration`.
2023-10-24 01:26:44 +00:00
Geoff Romer 9e0d831092 Handle let with no closing semicolon (#3323)
Also add a test for the `var` case
2023-10-21 00:12:42 +00:00
josh11bandRichard Smith a112f2e802 Validate parse nodes correspond to expected tokens (#3295)
Can specify which tokens are allowed generally, and any additional
tokens that only occur when the parse node has an error.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2023-10-13 21:44:51 +00:00
Richard Smith 74d52738ff Support for let declarations. (#3257)
A `let` declaration is represented by a `bind_name` node in SemIR:

```carbon-semir
  %b: i32 = bind_name "b", %a
```

Because `Check` encounters the pattern before it sees the value, we
first create the `bind_name` node with an unset value and don't add it
to the block. Then, once we've seen and converted the initializer, we
update the `bind_name` to have the value and add it to the current
block, after the initializer code.
2023-10-06 00:06:21 +00:00
Chandler Carruth a46ca6bf7a Add a start-of-file token and parse node. (#3263)
This removes a (very) hot branch in the lexer where we need to special
case when a token is the first token and can't look at its previous
token. It also seems like a generally nice change to the structure of
both the token buffer and parse tree as there are now bracketing
elements for both ends and we should be able to avoid similar branching
in the future.

Mostly mechanical updates to the lexer and parser code to handle this,
but also needed to special case the location information in the
autoupdate code. And then the usual large body of auto-updated tests.

No benchmark data for this change alone as in isolation and in the
current lexer structure it doesn't make a big difference. But this
branch was particularly difficult to handle when trying to update the
whitespace skipping code to be faster, and so I think it is worth
systematically avoiding the special case here.
2023-10-04 23:36:35 +00:00
Geoff Romer 7899154a21 Add "ERROR" to all error diagnostics (#3251)
This makes the difference between errors and lower-level diagnostics
visible to users, and aligns the toolchain's behavior with the
expectations in `driver_fuzzer.cpp`.
2023-09-26 16:52:49 +00:00
Jon Ross-Perkins ec9d73e471 When there are split files, put unattached stdout at the end of the last file. (#3234)
This is consistent with the goal of trying to push unattached stdout to
the bottom of the test file. The current logic had a single file in
mind, and was not adapted for split file logic.

Addresses
https://github.com/carbon-language/carbon-lang/pull/3217#discussion_r1323584624

Note this depends on #3233
2023-09-15 21:56:42 +00:00
Jon Ross-Perkins 0b340a2ed2 Update parse tree yaml for multi-file. (#3215)
Building on #3214, updates parse tree yaml to be:

```
- filename: name
  parse_tree: [ ... ]
```
2023-09-13 16:35:15 +00:00
Jon Ross-Perkins 87d4c2dfc6 Improve testing and handling of unsigned APInt values (#3202) 2023-09-07 18:53:38 +00:00
Jon Ross-Perkins c555b39a2c Rename parser dir to parse (#3178)
Continuing with #3070. Just a dir and file rename (mostly removing
prefixes, although for parse_tree_fuzzer and parse_tree_file_test I'm
dropping "tree" instead of "parse"). Everything in the parse dir should
be marked as a move.
2023-09-01 01:35:45 +00:00