aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/resolve
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-03-06 20:50:55 +0000
committerGitHub <noreply@github.com>2022-03-06 20:50:55 +0000
commite2bccf43ed1bf33d5f454eab39a7a4a1f115b0bd (patch)
tree6e9e933267fd6c651c59607668e2fa08641b8b9d /gcc/rust/resolve
parentd89c8ccf3237e66029125c0fe007297bb86eca74 (diff)
parent58d1721529e99c7c633615e7491b777a6198ed00 (diff)
downloadgcc-e2bccf43ed1bf33d5f454eab39a7a4a1f115b0bd.zip
gcc-e2bccf43ed1bf33d5f454eab39a7a4a1f115b0bd.tar.gz
gcc-e2bccf43ed1bf33d5f454eab39a7a4a1f115b0bd.tar.bz2
Merge #985
985: Parse macro!(); as MacroInvocation with semicolon r=CohenArthur a=CohenArthur When parsing a macro invocation as a statement, the parser would parse an expression and then try parsing a semicolon. Since no actual lookahead was done (which is a good thing), we couldn't convert a `MacroInvocation` to a `MacroInvocationSemi` after the fact. Since, unlike function calls, macro invocations can act differently based on whether or not they are followed by a semicolon, we actually need to differentiate between the two up until expansion. This commits adds a new virtual method for ExprWithoutBlock when converting to ExprStmtWithoutBlock so that classes inheriting ExprWithoutBlock can specify a new behavior. In the case of our MacroInvocation class, it simply means toggling a boolean: If we're converting a macro from an expression to a statement, it must mean that it should contain a semicolon. Closes #941 Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Diffstat (limited to 'gcc/rust/resolve')
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-base.h1
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-implitem.h15
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-item.h10
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-stmt.h5
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-toplevel.h2
5 files changed, 25 insertions, 8 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-base.h b/gcc/rust/resolve/rust-ast-resolve-base.h
index 6ee5f3d..eca9694 100644
--- a/gcc/rust/resolve/rust-ast-resolve-base.h
+++ b/gcc/rust/resolve/rust-ast-resolve-base.h
@@ -38,7 +38,6 @@ public:
void visit (AST::IdentifierExpr &) {}
void visit (AST::Lifetime &) {}
void visit (AST::LifetimeParam &) {}
- void visit (AST::MacroInvocationSemi &) {}
void visit (AST::PathInExpression &) {}
void visit (AST::TypePathSegment &) {}
void visit (AST::TypePathSegmentGeneric &) {}
diff --git a/gcc/rust/resolve/rust-ast-resolve-implitem.h b/gcc/rust/resolve/rust-ast-resolve-implitem.h
index ce7234c..7393393 100644
--- a/gcc/rust/resolve/rust-ast-resolve-implitem.h
+++ b/gcc/rust/resolve/rust-ast-resolve-implitem.h
@@ -49,8 +49,11 @@ public:
item->accept_vis (resolver);
}
- void visit (AST::MacroInvocationSemi &invoc) override
+ void visit (AST::MacroInvocation &invoc) override
{
+ if (!invoc.has_semicolon ())
+ return;
+
AST::ASTFragment &fragment = invoc.get_fragment ();
for (auto &node : fragment.get_nodes ())
node.accept_vis (*this);
@@ -144,8 +147,11 @@ public:
item->accept_vis (resolver);
};
- void visit (AST::MacroInvocationSemi &invoc) override
+ void visit (AST::MacroInvocation &invoc) override
{
+ if (!invoc.has_semicolon ())
+ return;
+
AST::ASTFragment &fragment = invoc.get_fragment ();
for (auto &node : fragment.get_nodes ())
node.accept_vis (*this);
@@ -254,8 +260,11 @@ public:
item->accept_vis (resolver);
};
- void visit (AST::MacroInvocationSemi &invoc) override
+ void visit (AST::MacroInvocation &invoc) override
{
+ if (!invoc.has_semicolon ())
+ return;
+
AST::ASTFragment &fragment = invoc.get_fragment ();
for (auto &node : fragment.get_nodes ())
node.accept_vis (*this);
diff --git a/gcc/rust/resolve/rust-ast-resolve-item.h b/gcc/rust/resolve/rust-ast-resolve-item.h
index 48f93e5..2cb0006 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.h
+++ b/gcc/rust/resolve/rust-ast-resolve-item.h
@@ -45,8 +45,11 @@ public:
item->accept_vis (resolver);
};
- void visit (AST::MacroInvocationSemi &invoc) override
+ void visit (AST::MacroInvocation &invoc) override
{
+ if (!invoc.has_semicolon ())
+ return;
+
AST::ASTFragment &fragment = invoc.get_fragment ();
for (auto &node : fragment.get_nodes ())
node.accept_vis (*this);
@@ -234,8 +237,11 @@ public:
item->accept_vis (resolver);
};
- void visit (AST::MacroInvocationSemi &invoc) override
+ void visit (AST::MacroInvocation &invoc) override
{
+ if (!invoc.has_semicolon ())
+ return;
+
AST::ASTFragment &fragment = invoc.get_fragment ();
for (auto &node : fragment.get_nodes ())
node.accept_vis (*this);
diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.h b/gcc/rust/resolve/rust-ast-resolve-stmt.h
index 7521739..785f3de 100644
--- a/gcc/rust/resolve/rust-ast-resolve-stmt.h
+++ b/gcc/rust/resolve/rust-ast-resolve-stmt.h
@@ -44,8 +44,11 @@ public:
stmt->accept_vis (resolver);
};
- void visit (AST::MacroInvocationSemi &invoc) override
+ void visit (AST::MacroInvocation &invoc) override
{
+ if (!invoc.has_semicolon ())
+ return;
+
AST::ASTFragment &fragment = invoc.get_fragment ();
for (auto &node : fragment.get_nodes ())
diff --git a/gcc/rust/resolve/rust-ast-resolve-toplevel.h b/gcc/rust/resolve/rust-ast-resolve-toplevel.h
index 39d6818..1f528fe 100644
--- a/gcc/rust/resolve/rust-ast-resolve-toplevel.h
+++ b/gcc/rust/resolve/rust-ast-resolve-toplevel.h
@@ -43,7 +43,7 @@ public:
item->accept_vis (resolver);
};
- void visit (AST::MacroInvocationSemi &invoc) override
+ void visit (AST::MacroInvocation &invoc) override
{
AST::ASTFragment &fragment = invoc.get_fragment ();
for (auto &node : fragment.get_nodes ())