Skip to content

Commit 265c223

Browse files
Merge #964 #965
964: Forbid unresolved test cases r=CohenArthur a=CohenArthur Closes #923 965: macro-invoc-lexer: Split implementation in its own file r=CohenArthur a=CohenArthur Closes #949 Co-authored-by: Arthur Cohen <[email protected]>
3 parents 133beb6 + 9b36f95 + 4e19c2f commit 265c223

File tree

6 files changed

+97
-47
lines changed

6 files changed

+97
-47
lines changed

.github/workflows/ccpp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
- name: Check regressions
6262
run: |
6363
cd gccrs-build; \
64-
if grep "# of unexpected" gcc/testsuite/rust/rust.sum;\
64+
if grep -e "unexpected" -e "unresolved" gcc/testsuite/rust/rust.sum;\
6565
then \
6666
echo "some tests are not correct"; \
6767
exit 1; \

gcc/rust/Make-lang.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ GRS_OBJS = \
7474
rust/rust-mangle.o \
7575
rust/rust-compile-resolve-path.o \
7676
rust/rust-macro-expand.o \
77+
rust/rust-macro-invoc-lexer.o \
7778
rust/rust-hir-full-test.o \
7879
rust/rust-hir-map.o \
7980
rust/rust-abi.o \

gcc/rust/expand/rust-macro-expand.h

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "rust-macro.h"
2727
#include "rust-hir-map.h"
2828
#include "rust-name-resolver.h"
29+
#include "rust-macro-invoc-lexer.h"
2930

3031
// Provides objects and method prototypes for macro expansion
3132

@@ -48,52 +49,6 @@ struct ExpansionCfg
4849
std::string crate_name = "";
4950
};
5051

51-
class MacroInvocLexer
52-
{
53-
public:
54-
MacroInvocLexer (std::vector<std::unique_ptr<AST::Token>> stream)
55-
: offs (0), token_stream (std::move (stream))
56-
{}
57-
58-
// Returns token n tokens ahead of current position.
59-
const_TokenPtr peek_token (int n)
60-
{
61-
if ((offs + n) >= token_stream.size ())
62-
return Token::make (END_OF_FILE, Location ());
63-
64-
return token_stream.at (offs + n)->get_tok_ptr ();
65-
}
66-
// Peeks the current token.
67-
const_TokenPtr peek_token () { return peek_token (0); }
68-
69-
// Advances current token to n + 1 tokens ahead of current position.
70-
void skip_token (int n) { offs += (n + 1); }
71-
72-
// Skips the current token.
73-
void skip_token () { skip_token (0); }
74-
75-
// Splits the current token into two. Intended for use with nested generics
76-
// closes (i.e. T<U<X>> where >> is wrongly lexed as one token). Note that
77-
// this will only work with "simple" tokens like punctuation.
78-
void split_current_token (TokenId /*new_left*/, TokenId /*new_right*/)
79-
{
80-
// FIXME
81-
gcc_unreachable ();
82-
}
83-
84-
std::string get_filename () const
85-
{
86-
gcc_unreachable ();
87-
return "FIXME";
88-
}
89-
90-
size_t get_offs () const { return offs; }
91-
92-
private:
93-
size_t offs;
94-
std::vector<std::unique_ptr<AST::Token>> token_stream;
95-
};
96-
9752
struct MatchedFragment
9853
{
9954
std::string fragment_ident;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "rust-macro-invoc-lexer.h"
2+
3+
namespace Rust {
4+
5+
const_TokenPtr
6+
MacroInvocLexer::peek_token (int n)
7+
{
8+
if ((offs + n) >= token_stream.size ())
9+
return Token::make (END_OF_FILE, Location ());
10+
11+
return token_stream.at (offs + n)->get_tok_ptr ();
12+
}
13+
14+
// Advances current token to n + 1 tokens ahead of current position.
15+
void
16+
MacroInvocLexer::skip_token (int n)
17+
{
18+
offs += (n + 1);
19+
}
20+
21+
void
22+
MacroInvocLexer::split_current_token (TokenId new_left __attribute__ ((unused)),
23+
TokenId new_right
24+
__attribute__ ((unused)))
25+
{
26+
// FIXME
27+
gcc_unreachable ();
28+
}
29+
} // namespace Rust
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (C) 2020-2022 Free Software Foundation, Inc.
2+
3+
// This file is part of GCC.
4+
5+
// GCC is free software; you can redistribute it and/or modify it under
6+
// the terms of the GNU General Public License as published by the Free
7+
// Software Foundation; either version 3, or (at your option) any later
8+
// version.
9+
10+
// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11+
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
// for more details.
14+
15+
// You should have received a copy of the GNU General Public License
16+
// along with GCC; see the file COPYING3. If not see
17+
// <http://www.gnu.org/licenses/>.
18+
19+
#ifndef RUST_MACRO_INVOC_LEXER_H
20+
#define RUST_MACRO_INVOC_LEXER_H
21+
22+
#include "rust-ast.h"
23+
24+
namespace Rust {
25+
class MacroInvocLexer
26+
{
27+
public:
28+
MacroInvocLexer (std::vector<std::unique_ptr<AST::Token>> stream)
29+
: offs (0), token_stream (std::move (stream))
30+
{}
31+
32+
// Returns token n tokens ahead of current position.
33+
const_TokenPtr peek_token (int n);
34+
35+
// Peeks the current token.
36+
const_TokenPtr peek_token () { return peek_token (0); }
37+
38+
// Advances current token to n + 1 tokens ahead of current position.
39+
void skip_token (int n);
40+
41+
// Skips the current token.
42+
void skip_token () { skip_token (0); }
43+
44+
// Splits the current token into two. Intended for use with nested generics
45+
// closes (i.e. T<U<X>> where >> is wrongly lexed as one token). Note that
46+
// this will only work with "simple" tokens like punctuation.
47+
void split_current_token (TokenId new_left, TokenId new_right);
48+
49+
std::string get_filename () const
50+
{
51+
// FIXME
52+
gcc_unreachable ();
53+
return "FIXME";
54+
}
55+
56+
size_t get_offs () const { return offs; }
57+
58+
private:
59+
size_t offs;
60+
std::vector<std::unique_ptr<AST::Token>> token_stream;
61+
};
62+
} // namespace Rust
63+
64+
#endif // RUST_MACRO_INVOC_LEXER_H

gcc/testsuite/rust/compile/inline_1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// { dg-additional-options "-fdump-tree-gimple" }
12
#[inline]
23
fn test_a() {}
34

0 commit comments

Comments
 (0)