diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-02-17 09:22:03 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-17 09:22:03 +0000 |
commit | 6a6c21709314e72f2edb5539913a4b7ce7a1cb66 (patch) | |
tree | af8bdb51ac35038c8d6804e5ce0921981a80de94 /gcc/rust/ast/rust-macro.h | |
parent | d81ba63f4829c12b89e87564c398e95879c89db1 (diff) | |
parent | c1e72db48a0fa36966f2517cbf45fa2b758af268 (diff) | |
download | gcc-6a6c21709314e72f2edb5539913a4b7ce7a1cb66.zip gcc-6a6c21709314e72f2edb5539913a4b7ce7a1cb66.tar.gz gcc-6a6c21709314e72f2edb5539913a4b7ce7a1cb66.tar.bz2 |
Merge #932
932: Add location information to MacroRule r=CohenArthur a=CohenArthur
Closes #930
This PR adds location information to the `MacroRule` structure.
The location is from the beginning of the invokation pattern, so that errors look like so:
```rust
test.rs:2:5: error: ...
2 | ($a:expr, $b:expr) => { a + b }
| ^
```
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Diffstat (limited to 'gcc/rust/ast/rust-macro.h')
-rw-r--r-- | gcc/rust/ast/rust-macro.h | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index ef50e4a..e0524c6 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -20,6 +20,7 @@ #define RUST_AST_MACRO_H #include "rust-ast.h" +#include "rust-location.h" namespace Rust { namespace AST { @@ -295,26 +296,28 @@ struct MacroRule private: MacroMatcher matcher; MacroTranscriber transcriber; - - // TODO: should store location information? + Location locus; public: - MacroRule (MacroMatcher matcher, MacroTranscriber transcriber) - : matcher (std::move (matcher)), transcriber (std::move (transcriber)) + MacroRule (MacroMatcher matcher, MacroTranscriber transcriber, Location locus) + : matcher (std::move (matcher)), transcriber (std::move (transcriber)), + locus (locus) {} // Returns whether macro rule is in error state. bool is_error () const { return matcher.is_error (); } // Creates an error state macro rule. - static MacroRule create_error () + static MacroRule create_error (Location locus) { - // FIXME: Once #928 is merged, give location to MacroMatcher - return MacroRule (MacroMatcher::create_error (Location ()), + return MacroRule (MacroMatcher::create_error (locus), MacroTranscriber (DelimTokenTree::create_empty (), - Location ())); + Location ()), + locus); } + Location get_locus () const { return locus; } + std::string as_string () const; }; |