Commit Graph
15 Commits
Author SHA1 Message Date
Calvin a57c3d9801 Fix string literal parsing escaped whitespace (#2617)
The toolchain misinterprets escaped whitespace characters as unescaped when trimming trailing whitespace on a line. This PR adds a variable to track the length of the string after escaping the most recent escape, making sure we don't backup past that character, whatever it is.

I did try the approach mentioned in #2132 of not backing up `end_of_regular_text` number of characters, but this caused problems on lines like <kbd>tab</kbd> <kbd>space</kbd> <kbd>tab</kbd> (those characters literally, not escaped) where it would leave the first tab since that is processed in a different iteration of that loop.

I added a test case for this bug. I kept getting mixed up in the test output which one was the expected value, so I also changed a variable name there for clarity.

Fixes #2132.
2023-02-27 16:05:34 -08:00
Chandler CarruthandJon Ross-Perkins 94cf343b05 Update LLVM and switch to std::optional. (#2424)
LLVM's bazel build has changed a bit, so this updates the tree for that.

LLVM is also moving `llvm::Optional` to match the standard API, but it seemed simpler to just switch to `std::optional`.

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2022-12-01 09:22:43 -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
Jon Meow af694b97cb Prefix most macro names with CARBON_ (#1232)
I'm doing this to avoid macro name conflicts, following https://google.github.io/styleguide/cppguide.html#Preprocessor_Macros: "If you do export a macro from a header, it must have a globally unique name. To achieve this, it must be named with a prefix consisting of your project's namespace name (but upper case)."

Commands run:

```
sed -i 's/\(DCHECK\|CHECK\|FATAL\|MAKE_UNIQUE_NAME\|MAKE_UNIQUE_NAME_IMPL\|RAW_EXITING_STREAM\|RETURN_IF_ERROR\|RETURN_IF_ERROR_IMPL\|ASSIGN_OR_RETURN\|ASSIGN_OR_RETURN_IMPL\|DIAGNOSTIC_KIND\|RETURN_IF_STACK_LIMITED\)(/CARBON_\1(/g' $(git ls-files *.cpp *.h *.lpp *.ypp *.def ':!third_party')
sed -i 's/#undef DIAGNOSTIC_KIND/#undef CARBON_DIAGNOSTIC_KIND/' toolchain/diagnostics/diagnostic_registry.def
```

Note this isn't *quite* everything, but it's intended to be a large pass at everything:

```
╚╡git grep '#define ' *.cpp *.h *.lpp *.ypp *.def ':!third_party' | grep -v '#define CARBON' | grep -v _H_
explorer/syntax/lexer.lpp:  #define YY_USER_ACTION                                             \
explorer/syntax/lexer.lpp:  #define SIMPLE_TOKEN(name) \
explorer/syntax/lexer.lpp:  #define ARG_TOKEN(name, arg) \
explorer/syntax/parse_and_lex_context.h:#define YY_DECL                                                         \
migrate_cpp/cpp_refactoring/var_decl.cpp:#define ABSTRACT_TYPE(Class, Base)
migrate_cpp/cpp_refactoring/var_decl.cpp:#define TYPE(Class, Base)     \
```

We may in particular want to do a pass to clean up #ifdef guards and make them be CARBON_ rooted.
2022-05-06 15:30:25 -07:00
Jon Meow a24963ea6b Move diagnostic definitions to be closer to where they emit (#1169) 2022-04-04 15:14:43 -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 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 dfef55fc2c Improve string lexing performance (#1001)
See benchmark notes on https://github.com/carbon-language/carbon-lang/pull/1001
2022-01-28 10:05:07 -08:00
Jon Meow cab5bb0158 Clean up SimpleDiagnostic inheritance (#1004) 2022-01-07 11:01:01 -08:00
Jon MeowandChandler Carruth a562f872e7 Switch from assert to CHECK (#975)
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2021-12-08 08:38:27 -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
Richard Smith bd7502261e Disallow tabs in string literals. (#737) 2021-08-27 17:43:55 -07:00
Chandler Carruth a857b7ea1a Cleanup or suppress numerous clang-tidy issues. (#577)
This gets us to a nearly clean state across the toolchain. A couple of
these are checks that I don't think we want to try to rigidly use and
I've disabled them completely. Others I've added relevant `NOLINT` style
suppressions or applied the automatic fix suggested by `clang-tidy`.

The implicit conversions that are allowed here with `NOLINT` are
probably worth at least a tiny bit of scrutiny to see if we could
replace the construct with something more direct without undue effort
and no longer need the implicit conversion. But until then, it seemed
fine to suppress.
2021-06-14 19:46:49 -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