@@ -1980,9 +1980,9 @@ FailureOr<ast::Expr *> Parser::parseAddSubExpr() {
1980
1980
// Check if it is in rewrite section but not in the let statement
1981
1981
bool inRewriteSection = parserContext == ParserContext::Rewrite;
1982
1982
if (inRewriteSection &&
1983
- nativeOperatorContext == NativeOperatorContext::Generic )
1984
- return emitError (
1985
- " nodiscard rule for add operator is applied in rewrite section " );
1983
+ nativeOperatorContext != NativeOperatorContext::Let )
1984
+ return emitError (" cannot evaluate add operator in rewrite section. "
1985
+ " Assign to a variable with `let` " );
1986
1986
1987
1987
lhs = inRewriteSection ? createBuiltinCall (curToken.getLoc (),
1988
1988
builtins.addRewrite , args)
@@ -2000,9 +2000,9 @@ FailureOr<ast::Expr *> Parser::parseAddSubExpr() {
2000
2000
// Check if it is in rewrite section but not in the let statement
2001
2001
bool inRewriteSection = parserContext == ParserContext::Rewrite;
2002
2002
if (inRewriteSection &&
2003
- nativeOperatorContext == NativeOperatorContext::Generic )
2004
- return emitError (
2005
- " nodiscard rule for sub operator is applied in rewrite section " );
2003
+ nativeOperatorContext != NativeOperatorContext::Let )
2004
+ return emitError (" cannot evaluate sub operator in rewrite section. "
2005
+ " Assign to a variable with `let` " );
2006
2006
2007
2007
lhs = inRewriteSection ? createBuiltinCall (curToken.getLoc (),
2008
2008
builtins.subRewrite , args)
@@ -2033,9 +2033,9 @@ FailureOr<ast::Expr *> Parser::parseMulDivModExpr() {
2033
2033
// Check if it is in rewrite section but not in the let statement
2034
2034
bool inRewriteSection = parserContext == ParserContext::Rewrite;
2035
2035
if (inRewriteSection &&
2036
- nativeOperatorContext == NativeOperatorContext::Generic )
2037
- return emitError (
2038
- " nodiscard rule for mul operator is applied in rewrite section " );
2036
+ nativeOperatorContext != NativeOperatorContext::Let )
2037
+ return emitError (" cannot evaluate mul operator in rewrite section. "
2038
+ " Assign to a variable with `let` " );
2039
2039
2040
2040
lhs = inRewriteSection ? createBuiltinCall (curToken.getLoc (),
2041
2041
builtins.mulRewrite , args)
@@ -2053,9 +2053,9 @@ FailureOr<ast::Expr *> Parser::parseMulDivModExpr() {
2053
2053
// Check if it is in rewrite section but not in the let statement
2054
2054
bool inRewriteSection = parserContext == ParserContext::Rewrite;
2055
2055
if (inRewriteSection &&
2056
- nativeOperatorContext == NativeOperatorContext::Generic )
2057
- return emitError (
2058
- " nodiscard rule for div operator is applied in rewrite section " );
2056
+ nativeOperatorContext != NativeOperatorContext::Let )
2057
+ return emitError (" cannot evaluate div operator in rewrite section. "
2058
+ " Assign to a variable with `let` " );
2059
2059
2060
2060
lhs = inRewriteSection ? createBuiltinCall (curToken.getLoc (),
2061
2061
builtins.divRewrite , args)
@@ -2071,9 +2071,9 @@ FailureOr<ast::Expr *> Parser::parseMulDivModExpr() {
2071
2071
SmallVector<ast::Expr *> args{*lhs, *rhs};
2072
2072
bool inRewriteSection = parserContext == ParserContext::Rewrite;
2073
2073
if (inRewriteSection &&
2074
- nativeOperatorContext == NativeOperatorContext::Generic )
2075
- return emitError (
2076
- " nodiscard rule for mod operator is applied in rewrite section " );
2074
+ nativeOperatorContext != NativeOperatorContext::Let )
2075
+ return emitError (" cannot evaluate mod operator in rewrite section. "
2076
+ " Assign to a variable with `let` " );
2077
2077
2078
2078
lhs = inRewriteSection ? createBuiltinCall (curToken.getLoc (),
2079
2079
builtins.modRewrite , args)
@@ -2100,10 +2100,9 @@ FailureOr<ast::Expr *> Parser::parseExp2Log2Expr() {
2100
2100
2101
2101
// Check if it is in rewrite section but not in the let statement
2102
2102
bool inRewriteSection = parserContext == ParserContext::Rewrite;
2103
- if (inRewriteSection &&
2104
- nativeOperatorContext == NativeOperatorContext::Generic)
2105
- return emitError (
2106
- " nodiscard rule for log2 operator is applied in rewrite section" );
2103
+ if (inRewriteSection && nativeOperatorContext != NativeOperatorContext::Let)
2104
+ return emitError (" cannot evaluate log2 operator in rewrite section. "
2105
+ " Assign to a variable with `let`" );
2107
2106
2108
2107
consumeToken (Token::r_paren);
2109
2108
return inRewriteSection
@@ -2121,10 +2120,9 @@ FailureOr<ast::Expr *> Parser::parseExp2Log2Expr() {
2121
2120
2122
2121
// Check if it is in rewrite section but not in the let statement
2123
2122
bool inRewriteSection = parserContext == ParserContext::Rewrite;
2124
- if (inRewriteSection &&
2125
- nativeOperatorContext == NativeOperatorContext::Generic)
2126
- return emitError (
2127
- " nodiscard rule for exp2 operator is applied in rewrite section" );
2123
+ if (inRewriteSection && nativeOperatorContext != NativeOperatorContext::Let)
2124
+ return emitError (" cannot evaluate exp2 operator in rewrite section. "
2125
+ " Assign to a variable with `let`" );
2128
2126
2129
2127
consumeToken (Token::r_paren);
2130
2128
return inRewriteSection
@@ -2762,8 +2760,6 @@ FailureOr<ast::Stmt *> Parser::parseStmt(bool expectTerminalSemicolon) {
2762
2760
break ;
2763
2761
case Token::kw_let: {
2764
2762
stmt = parseLetStmt ();
2765
- llvm::SaveAndRestore saveCtx (nativeOperatorContext,
2766
- NativeOperatorContext::Generic);
2767
2763
break ;
2768
2764
}
2769
2765
case Token::kw_replace:
0 commit comments