diff options
-rw-r--r-- | Dockerfile | 5 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast.h | 2 | ||||
-rw-r--r-- | gcc/rust/ast/rust-macro.h | 51 | ||||
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 14 |
4 files changed, 46 insertions, 26 deletions
@@ -1,4 +1,4 @@ -FROM ubuntu:latest +FROM ubuntu:latest AS gcc-builder RUN apt-get update; \ DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \ @@ -67,5 +67,8 @@ RUN /bin/sh -c set -ex; \ dpkg-divert --divert /usr/bin/g++.orig --rename /usr/bin/g++; \ update-alternatives --install /usr/bin/cc cc /usr/local/bin/gcc 999 +FROM rust +COPY --from=gcc-builder /usr/ /usr/ +RUN cargo install --git https://github.com/Rust-GCC/cargo-gccrs cargo-gccrs CMD ["bash"] diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 0c22c37..ba973f1 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -111,6 +111,7 @@ public: virtual ~MacroMatch () {} virtual std::string as_string () const = 0; + virtual Location get_match_locus () const = 0; // Unique pointer custom clone function std::unique_ptr<MacroMatch> clone_macro_match () const @@ -217,6 +218,7 @@ public: } std::string as_string () const override; + Location get_match_locus () const override { return tok_ref->get_locus (); }; void accept_vis (ASTVisitor &vis) override; diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index 6ea7de8..2d59b18 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -87,24 +87,24 @@ class MacroMatchFragment : public MacroMatch { Identifier ident; MacroFragSpec frag_spec; - - // TODO: should store location information? + Location locus; public: - MacroMatchFragment (Identifier ident, MacroFragSpec frag_spec) - : ident (std::move (ident)), frag_spec (frag_spec) + MacroMatchFragment (Identifier ident, MacroFragSpec frag_spec, Location locus) + : ident (std::move (ident)), frag_spec (frag_spec), locus (locus) {} // Returns whether macro match fragment is in an error state. bool is_error () const { return frag_spec == INVALID; } // Creates an error state macro match fragment. - static MacroMatchFragment create_error () + static MacroMatchFragment create_error (Location locus) { - return MacroMatchFragment (std::string (""), INVALID); + return MacroMatchFragment (std::string (""), INVALID, locus); } std::string as_string () const override; + Location get_match_locus () const override { return locus; }; void accept_vis (ASTVisitor &vis) override; @@ -137,20 +137,22 @@ private: typedef Token MacroRepSep; // any token except delimiters and repetition operators std::unique_ptr<MacroRepSep> sep; - - // TODO: should store location information? + Location locus; public: // Returns whether macro match repetition has separator token. bool has_sep () const { return sep != nullptr; } MacroMatchRepetition (std::vector<std::unique_ptr<MacroMatch> > matches, - MacroRepOp op, std::unique_ptr<MacroRepSep> sep) - : matches (std::move (matches)), op (op), sep (std::move (sep)) + MacroRepOp op, std::unique_ptr<MacroRepSep> sep, + Location locus) + : matches (std::move (matches)), op (op), sep (std::move (sep)), + locus (locus) {} // Copy constructor with clone - MacroMatchRepetition (MacroMatchRepetition const &other) : op (other.op) + MacroMatchRepetition (MacroMatchRepetition const &other) + : op (other.op), locus (other.locus) { // guard to protect from null pointer dereference if (other.sep != nullptr) @@ -165,6 +167,7 @@ public: MacroMatchRepetition &operator= (MacroMatchRepetition const &other) { op = other.op; + locus = other.locus; // guard to protect from null pointer dereference if (other.sep != nullptr) @@ -184,6 +187,7 @@ public: MacroMatchRepetition &operator= (MacroMatchRepetition &&other) = default; std::string as_string () const override; + Location get_match_locus () const override { return locus; }; void accept_vis (ASTVisitor &vis) override; @@ -201,20 +205,22 @@ class MacroMatcher : public MacroMatch { DelimType delim_type; std::vector<std::unique_ptr<MacroMatch> > matches; + Location locus; // TODO: think of way to mark invalid that doesn't take up more space bool is_invalid; - // TODO: should store location information? - public: MacroMatcher (DelimType delim_type, - std::vector<std::unique_ptr<MacroMatch> > matches) - : delim_type (delim_type), matches (std::move (matches)), is_invalid (false) + std::vector<std::unique_ptr<MacroMatch> > matches, + Location locus) + : delim_type (delim_type), matches (std::move (matches)), locus (locus), + is_invalid (false) {} // copy constructor with vector clone - MacroMatcher (MacroMatcher const &other) : delim_type (other.delim_type) + MacroMatcher (MacroMatcher const &other) + : delim_type (other.delim_type), locus (other.locus) { matches.reserve (other.matches.size ()); for (const auto &e : other.matches) @@ -225,6 +231,7 @@ public: MacroMatcher &operator= (MacroMatcher const &other) { delim_type = other.delim_type; + locus = other.locus; matches.reserve (other.matches.size ()); for (const auto &e : other.matches) @@ -238,10 +245,14 @@ public: MacroMatcher &operator= (MacroMatcher &&other) = default; // Creates an error state macro matcher. - static MacroMatcher create_error () { return MacroMatcher (true); } + static MacroMatcher create_error (Location locus) + { + return MacroMatcher (true, locus); + } // Returns whether MacroMatcher is in an error state. bool is_error () const { return is_invalid; } + Location get_match_locus () const override { return locus; } std::string as_string () const override; @@ -256,7 +267,8 @@ protected: } // constructor only used to create error matcher - MacroMatcher (bool is_invalid) : delim_type (PARENS), is_invalid (is_invalid) + MacroMatcher (bool is_invalid, Location locus) + : delim_type (PARENS), locus (locus), is_invalid (is_invalid) {} }; @@ -296,7 +308,8 @@ public: // Creates an error state macro rule. static MacroRule create_error () { - return MacroRule (MacroMatcher::create_error (), + // FIXME: Once #928 is merged, give location to MacroMatcher + return MacroRule (MacroMatcher::create_error (Location ()), MacroTranscriber (DelimTokenTree::create_empty ())); } diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 6d393b0..b500c87 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -1709,6 +1709,7 @@ Parser<ManagedTokenSource>::parse_macro_matcher () // Map tokens to DelimType const_TokenPtr t = lexer.peek_token (); + Location locus = t->get_locus (); switch (t->get_id ()) { case LEFT_PAREN: @@ -1726,7 +1727,7 @@ Parser<ManagedTokenSource>::parse_macro_matcher () "unexpected token %qs - expecting delimiters (for a macro matcher)", t->get_token_description ())); - return AST::MacroMatcher::create_error (); + return AST::MacroMatcher::create_error (t->get_locus ()); } lexer.skip_token (); @@ -1747,7 +1748,7 @@ Parser<ManagedTokenSource>::parse_macro_matcher () t->get_token_description ()); add_error (std::move (error)); - return AST::MacroMatcher::create_error (); + return AST::MacroMatcher::create_error (t->get_locus ()); } matches.push_back (std::move (match)); @@ -1765,7 +1766,7 @@ Parser<ManagedTokenSource>::parse_macro_matcher () // tokens match opening delimiter, so skip. lexer.skip_token (); - return AST::MacroMatcher (delim_type, std::move (matches)); + return AST::MacroMatcher (delim_type, std::move (matches), locus); } else { @@ -1781,7 +1782,7 @@ Parser<ManagedTokenSource>::parse_macro_matcher () /* return error macro matcher despite possibly parsing mostly correct one? * TODO is this the best idea? */ - return AST::MacroMatcher::create_error (); + return AST::MacroMatcher::create_error (t->get_locus ()); } } @@ -1857,6 +1858,7 @@ template <typename ManagedTokenSource> std::unique_ptr<AST::MacroMatchFragment> Parser<ManagedTokenSource>::parse_macro_match_fragment () { + Location fragment_locus = lexer.peek_token ()->get_locus (); skip_token (DOLLAR_SIGN); const_TokenPtr ident_tok = expect_token (IDENTIFIER); @@ -1893,7 +1895,7 @@ Parser<ManagedTokenSource>::parse_macro_match_fragment () } return std::unique_ptr<AST::MacroMatchFragment> ( - new AST::MacroMatchFragment (std::move (ident), frag)); + new AST::MacroMatchFragment (std::move (ident), frag, fragment_locus)); } // Parses a repetition macro match. @@ -2002,7 +2004,7 @@ Parser<ManagedTokenSource>::parse_macro_match_repetition () return std::unique_ptr<AST::MacroMatchRepetition> ( new AST::MacroMatchRepetition (std::move (matches), op, - std::move (separator))); + std::move (separator), t->get_locus ())); } /* Parses a visibility syntactical production (i.e. creating a non-default |