This required adding a few headers that were found transitively before,
but not too many. This is sadly a fairly manual process of opening every
file in my IDE, but I think I got everything in `//common` and
`//toolchain`.
There are a few cases where technically we don't need `foo.h` to be
included into `foo.cpp`, but I've forced those to stay with a pragma.
I've tried to catch the places where we can cut deps in Bazel as well,
but not sure I got all of those.
I had been noticing these in other PRs and it seemed better to isolate
the change.
Rationale: this convention avoids forcing closely-related code to be far
apart in the namespace hierarchy, and vice versa. By the same token, it
makes the namespace hierarchy more consistent with the directory
hierarchy.
This does some more work to the run_clang_tidy.py wrapper script, and runs an example pass.
"again" because it's really the proto fuzzer changes that broke it, it had been working before.
"mostly" because there's still an issue within the proto fuzzer that it can't find "port/protobuf.h", i.e. https://github.com/google/libprotobuf-mutator/tree/master/port, but I'm still hesitant to add an include path there.
* test cases for raw string literals
* raw string literal implementation
* match as block string if starting with triple ", and better error message for simple string
except for *#"""#*
* fix broken test case
block string literal cannot be one line
* test cases for raw string literals
* raw string literal implementation
* match as block string if starting with triple ", and better error message for simple string
except for *#"""#*
* fix broken test case
block string literal cannot be one line
* removed unused initial value
* rename flag to indicate multi-line string and remove comment
* use * to get value from std::optional
* clean-ups
* removed skip_scan flag and directly return in case of a single line string starting with #+\'\'\'
* Updated error message: simple string -> single-line string.
Co-authored-by: josh11b <josh11b@users.noreply.github.com>
* Updated test cases according to changes in error message
* Removed counting_hashtag flag.
* Implemented ScanHelper class to handle scanning
* Fixed explanation of ReadHashTags.
* Addressed PR comment.
* Clarify that scan_helper holds the source text.
* Addressed PR comments.
* Updated error messages in test cases.
* Added const keyword to return type of GetCurrentStr().
* addressed PR comments.
1. Moved ScanHelper class to lex_scan_helper.h and lex_scan_helper.cpp.
2. Moved ReadHashTags and Process* functions to lex_scan_helper.cpp. Moved YY_USER_ACTION, SIMPLE_TOKEN and ARG_TOKEN to lex_helper.h. Added a wrapper function YyinputWrapper to call static function yyinput in lexer.lpp.
3. Renamed ScanHelper with StringLexHelper.
4. Modified BUILD accordingly.
5. Renamed data members and functions.
* Addressed PR comments.
1. Adjusted order to keep ret usage close.
2. Used resize to construct the string to avoid creation of temp string.
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
* Removed the multi_line flag and skip_read field to improve readability.
* Copied default parameter value to definition of UnescapeStringLiteral.
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
* Copied default parameter value to definition of ParseBlockStringLiteral.
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
* Prefix CARBON_ to SIMPLE_TOKEN and ARG_TOKEN macros.
* Rollback redefinition of arguments.
* Updated comment on the flex macro.
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
* Updated wording.
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
* Moved the EOF error out of the loop.
* Removed duplicated declaration.
* Changed type of `hashtag_num` and `leading_quotes` to int.
* Minor fix: string copy.
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
* Added comment on YyinputWrapper.
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
* Garmmar in comment.
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
* Added check of eof before readling next char.
* Minor updates based on PR comments.
* Minor changes to address PR comments.
* Used a clearer way to calculate `hashtag_num` and `leading_quotes`. Switched back to indicate muti-line string with a flag.
* Directly copy StringRef for compilation error message.
* Make str_with_quote const as we don't change it.
Co-authored-by: josh11b <josh11b@users.noreply.github.com>
* Added TODO for unsupported cases.
* Fixed a typo.
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
Co-authored-by: josh11b <josh11b@users.noreply.github.com>
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
* Initial implementation of block string literals following lexical_conventions/string_literals.md.
Enabled yyinput() in flex to implement parsing.
Added ParseBlockStringLiteral() helper to handler further transformations such as indenting.
Modified formar_grammar to support single-quoted strings to prevent a failure on lexer.lpp.
* Fixed _find_string_end quote parameter type int -> str.
* Update executable_semantics/syntax/BUILD
Co-authored-by: Geoff Romer <gromer@google.com>
* Addressed code review comments - split table-drived test into individual tests, renamed constants to match style guide.
* Addressed code review comments -- using EXPECT_THAT_EXPECTED() in tests, lexer comments and code cleanup.
Co-authored-by: Geoff Romer <gromer@google.com>
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.
This is based on discussion on #732: that we should probably parse the invalid whitespace, then reject it as part of string validation, rather than having different parses. I worry the question of "how is this parsed" may lead to subtly unexpected results if we aren't consistent, so I'm switching the logic from the lexer to the unescape library (and also adjusting the list of rejected whitespace).
It was in my mind to add String in order to support libraries in `package`. `print` is added in order to have a String go to stdout. I've tried to do `print` in a way that won't be too hard to add other printable types, but it's probably also somewhat optional here -- that is, if desired, I could remove it. But it was a lot easier to doublecheck `\n` behavior with it, and I suspect it'll be helpful in other tests if it supports more value types.
On the side, this also fixes dereferencing in Pattern/Expression Print() calls, which I was noticing printing pointers instead of values. This may be another argument for moving away from passing pointers, since this seems to be a difficult-to-catch error.
Co-authored-by: Geoff Romer <gromer@google.com>