Commit Graph
25 Commits
Author SHA1 Message Date
Jon Ross-Perkins 87dbc4bd8a Fix missing forward_list include (#2911)
Noticed due to some build issues not caught by github actions.
2023-06-15 11:33:51 -07:00
Jon Ross-Perkins 8b1e820848 Migrate some lexer tests to file tests. (#2892)
These tests are doing string comparisons on output that don't seem to be meaningfully different from a file_test.

I'm tempted to migrate lexer tests in general, but I'm not doing that here since others may find more value in the current approach.
2023-06-14 09:50:48 -07:00
Jon Ross-Perkins d18c1347d7 Migrate compatible uses to TestRawOstream. (#2891)
Replacing direct raw_string_ostream uses. I figure the wrapper should be used more consistently.

There are still remaining raw_string_ostream uses that weren't compatible -- I'm continuing to look at those, but felt it was cleaner to have this on its own.
2023-06-14 09:31:56 -07:00
Jon Ross-PerkinsandRichard Smith a93e621488 Add vfs support to toolchain. (#2888)
This adds vfs support to the toolchain, allowing Driver to take in-memory inputs in tests. As a consequence, I'm simplifying SourceBuffer: rather than allowing tests to pass in their own memory buffer, I'm using InMemoryFileSystem to push for greater consistency with production code. This does hit a quirk where I need to be careful about null terminator handling because fuzzer imports don't always have one, but that's probably more robust anyways.

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2023-06-12 13:19:57 -07:00
Jon Ross-Perkins 1b662cbe73 Remove reference to None.h (#2613)
Reported by a Googler.
2023-02-17 11:45:59 -08:00
Jon Ross-PerkinsandChandler Carruth 78ac6cb7d1 Switch TokenKind to EnumBase (#2509)
This shouldn't have any behavior change, it's just using #2504

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2023-01-05 14:11:30 -08:00
Jon Ross-Perkins 04f0288cd2 Bracket the tokenized buffer output. (#2446)
This makes TokenizedBuffer more consistent with ParseTree and SemanticsIR, which also wrap with [] to produce a sequence value.

It also makes it possible in driver.cpp to just prefix the line with a name, so it ends up with:

var_name: [
  (content)
]
Noticed this due to bracketing comments on #2443 and trying to think of better answers. With this, we can also say that the [] bracket a variable.
2022-12-07 11:22:33 -08:00
Richard Smith dcc80f5491 Lex '''-delimited multiline string literals. (#2133)
"""-delimited literals are still lexed for error recovery but produce an error.
2022-09-01 18:00:37 -07:00
Kareem Ergawyandergawy 3d44169199 Fix integer literal token printing. (#2050)
Summary:
An `llvm::APInt` is always treated as a signed value by `operator<<`;
check [1]. This resulted in printing incorrect values for tokens that
have their MSB set to 1. For example, a value 9 would be printed as -7
since its `APInt` object would be 4-bits wide. However, integer literals
are always tokenized without the sign character so it is safe to treat
the values as unsigned for printing pruposes.

[1] https://llvm.org/doxygen/APInt_8h_source.html

Co-authored-by: ergawy <kareem.ergawy@guardsquare.com>
2022-08-17 09:29:07 -07:00
Jon MeowandRichard Smith aaca540a05 Restructure Diagnostic objects to allow late formatting (#1131)
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2022-04-04 10:59:09 -07:00
Jon Meow f9014a6d10 clang-tidy with readability checks (#1148) 2022-03-24 13:22:44 -07:00
Jon Meow 16c6ba6bd1 Accessor renames on lexer (#1134) 2022-03-15 13:02:44 -07:00
Jon Meow f5f02babdd Apply a digit limit for all getAsInteger calls (#1117)
In particular noticed the issue in type literal parsing, but given this has come up once before, trying to address it consistently.
2022-03-03 12:26:04 -08:00
Jon MeowandRichard Smith 0a8c0dc271 Adjust string parsing to consume everything until the terminator. (#1111)
Note I've added a few TODOs, particularly that multi-line strings should only consume until the dedent.

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2022-03-03 10:21:16 -08:00
Jon Meow f4f9b23291 Add int and real printing (#1116) 2022-03-03 09:57:41 -08:00
Jon Meow 8a2ef22c2a Validate source text size and fix empty buffer bugs. (#1113)
There's currently a bug with empty files, in that it initializes SourceBuffer with an invalid StringRef that results in a crash. That got me looking at the std::optional TODO, but the issue is that there are really three states:

- Buffered
- mmapped (not buffered)
- Moved out of (no longer initialized)

Technically an optional could work if we initialize the buffer on move out, indicating the mmap is gone. But the mode setup felt better to me.

And then this also adds the size check. Which is really how I started looking at this.
2022-03-02 13:43:03 -08:00
Jon Meow fa07a016b8 Sync the keyword list (#1097)
I was mainly looking at keywords trying to figure out what needs work and the amount to which it doesn't reflect the design confused me (including some things that we've decided not to include, and some things I'm not aware of discussion about). I figured this cleanup would at least make it somewhat clearer why things are in there.

I'm treating https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/lexical_conventions/words.md as canonical, with `_` and `xor` as presumably deliberate exceptions. Similarly avoiding symbol tokens because I assume you'll push proposals for the difference.

I dropped the `Keyword` qualifier because `is` makes `IsKeyword` a name conflict, and dropping the qualifier seemed like the more consistent solution (it doesn't do `AmpSymbol`, after all). If we need clarity I might lean towards a separate namespace to avoid naming conflicts.
2022-02-24 13:46:17 -08:00
Jon Meow 9c716e9c3b Move tests into Carbon::Testing, set small size (#992)
The small size is for the 1m vs 5m time limit -- all these tests _should_ be fast so a lower limit seems consistent, and the 5m timeout was getting in my way when trying to debug *actual* timeouts.

The Carbon::Testing bit is for convenience -- test libraries are generally using it, it seems like the tests should too. Note this reduces the need for `using`.

This does push NodeMatchers into Carbon::Testing -- I don't think this was benefiting from having its own namespace; `using namespace` is discouraged [under style](https://google.github.io/styleguide/cppguide.html#Namespaces), we wouldn't support an equivalent in Carbon, and it feels like it's not helping to avoid name collisions. (also tidy was bugging about it, and while I could NOLINT that, this felt like the better approach)
2021-12-15 15:18:44 -08:00
Jon MeowandChandler Carruth 652cd8c636 Style updates, mostly _ naming (#970)
There are some declaration order changes, and a few test classes switched from `struct` to `class`. However, this PR is mostly adopting `_` naming of private member variables due to the shift in naming style. None of what's here should have behavior impacts, it should just be style.

Note, there are a lot of things that *look* like they could be accessor-named, but I'm not doing that in this change. Happy to do it separately if you want me to do another PR focused on it.

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2021-12-07 09:46:44 -08:00
Jon Meow 5f0da883e4 Run clang-tidy over toolchain (#969) 2021-12-06 14:12:35 -08:00
Chandler Carruth 5f67029479 Use upstream GoogleTest and add related test utils. (#876)
This moves over to the vanilla upstream GoogleTest pulled in the more
expected manner with Bazel. It also adds Abseil and Google Benchmark
libraries in the same fashion (there are cross dependencies here).

As part of this, also introduce a dependency check test that can enforce
basic layering of dependencies. For example, this lets us ensure that
non-test Carbon code only depends on LLVM and Clang despite having other
libraries available. There remains some cleanup to improve the way these
dependency tests work, but this at least ensures we don't regress.

I've also provided workarounds to allow both Carbon code and LLVM code
to freely be used with GoogleTest (and other `std::ostream` based
output code). This is done by extending the code in
`//common/ostream.h`. One downside is that it requires opening the
`llvm` namespace and adding an ADL_found overload there. I think on
balance this is still a win and doesn't make me too nervous.

The new version of GoogleTest requires printing more often from matchers
and so I've also added several printing routines to types that
previously didn't require them. Otherwise, most of the updates are just
using the more conventional upstream style of including the headers and
adding `ostream.h` where it is needed.

I did consider moving code over to use `std::ostream` instead of LLVM's
`raw_ostream`, but the advantages of not doing virtual dispatch still
seem significant, and it also seems good to retain access to LLVM's
formatting utilities built around `raw_ostream` given that we can't pull
arbitrary dependencies into Carbon code outside of test code.

All of this was slightly motivated by requests for newer features in
GoogleTest, but much more-so by my desire to have access to Google
Benchmark and Abseil when writing benchmarks. For example, using
Abseil's random number generator seems extremely helpful when generating
inputs for benchmarks. The growing dependencies between these packages
further motivated me to just pull them all in and ensure they worked
well.
2021-11-02 20:14:12 -07:00
Richard SmithandChandler Carruth a83c22288f [toolchain] Implement lexing and parsing support for #543. (#693)
Lex [iuf][1-9][0-9]* as a new kind of "sized type literal" token. When
parsing that token, form a literal expression.

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2021-08-02 15:37:43 -07:00
Richard Smith 6a4c8a5186 [toolchain] Add simpler mechanism for matching YAML output in tests. (#583) 2021-06-17 18:42:19 -07:00
Richard Smith 1b122924e8 [toolchain] Parse postfix operator * as a type operator. (#576) 2021-06-14 16:12:14 -07:00
Chandler Carruth 8f8ab23a77 Move the toolchain into a top-level directory. (#567)
This should clean up our top level directory and the build patterns.

No non-mechanical edits here. Just injecting `toolchain/` and
`TOOLCHAIN_` and then running formatting tools.
2021-06-08 03:01:37 -07:00