Skip to content

Commit e624a6b

Browse files
committed
add support for negated constraints to PDLL parsing
1 parent 0f00bff commit e624a6b

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

mlir/lib/Tools/PDLL/Parser/Lexer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ Token Lexer::lexToken() {
233233
return formToken(Token::l_paren, tokStart);
234234
case ')':
235235
return formToken(Token::r_paren, tokStart);
236+
case '!':
237+
return formToken(Token::exclam, tokStart);
236238
case '/':
237239
if (*curPtr == '/') {
238240
lexComment();

mlir/lib/Tools/PDLL/Parser/Lexer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class Token {
7979
equal,
8080
equal_arrow,
8181
semicolon,
82+
exclam,
8283
/// Paired punctuation.
8384
less,
8485
greater,

mlir/lib/Tools/PDLL/Parser/Parser.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ class Parser {
316316
/// Identifier expressions.
317317
FailureOr<ast::Expr *> parseArrayAttrExpr();
318318
FailureOr<ast::Expr *> parseAttributeExpr();
319-
FailureOr<ast::Expr *> parseCallExpr(ast::Expr *parentExpr);
319+
FailureOr<ast::Expr *> parseCallExpr(ast::Expr *parentExpr,
320+
bool isNegated = false);
320321
FailureOr<ast::Expr *> parseDeclRefExpr(StringRef name, SMRange loc);
321322
FailureOr<ast::Expr *> parseDictAttrExpr();
322323
FailureOr<ast::Expr *> parseIdentifierExpr();
@@ -406,7 +407,7 @@ class Parser {
406407

407408
FailureOr<ast::CallExpr *>
408409
createCallExpr(SMRange loc, ast::Expr *parentExpr,
409-
MutableArrayRef<ast::Expr *> arguments);
410+
MutableArrayRef<ast::Expr *> arguments, bool isNegated);
410411
FailureOr<ast::DeclRefExpr *> createDeclRefExpr(SMRange loc, ast::Decl *decl);
411412
FailureOr<ast::DeclRefExpr *>
412413
createInlineVariableExpr(ast::Type type, StringRef name, SMRange loc,
@@ -1844,6 +1845,11 @@ FailureOr<ast::Expr *> Parser::parseExpr() {
18441845
case Token::dot:
18451846
lhsExpr = parseMemberAccessExpr(*lhsExpr);
18461847
break;
1848+
case Token::exclam:
1849+
// TODO: Fx: This parses the "!" as suffix instead of prefix.
1850+
consumeToken(Token::exclam);
1851+
lhsExpr = parseCallExpr(*lhsExpr, /*isNegated = */ true);
1852+
break;
18471853
case Token::l_paren:
18481854
lhsExpr = parseCallExpr(*lhsExpr);
18491855
break;
@@ -1912,7 +1918,8 @@ FailureOr<ast::Expr *> Parser::parseAttributeExpr() {
19121918
return ast::AttributeExpr::create(ctx, loc, attrExpr);
19131919
}
19141920

1915-
FailureOr<ast::Expr *> Parser::parseCallExpr(ast::Expr *parentExpr) {
1921+
FailureOr<ast::Expr *> Parser::parseCallExpr(ast::Expr *parentExpr,
1922+
bool isNegated) {
19161923
consumeToken(Token::l_paren);
19171924

19181925
// Parse the arguments of the call.
@@ -1936,7 +1943,7 @@ FailureOr<ast::Expr *> Parser::parseCallExpr(ast::Expr *parentExpr) {
19361943
if (failed(parseToken(Token::r_paren, "expected `)` after argument list")))
19371944
return failure();
19381945

1939-
return createCallExpr(loc, parentExpr, arguments);
1946+
return createCallExpr(loc, parentExpr, arguments, isNegated);
19401947
}
19411948

19421949
FailureOr<ast::Expr *> Parser::parseDeclRefExpr(StringRef name, SMRange loc) {
@@ -2789,7 +2796,8 @@ Parser::validateTypeRangeConstraintExpr(const ast::Expr *typeExpr) {
27892796

27902797
FailureOr<ast::CallExpr *>
27912798
Parser::createCallExpr(SMRange loc, ast::Expr *parentExpr,
2792-
MutableArrayRef<ast::Expr *> arguments) {
2799+
MutableArrayRef<ast::Expr *> arguments,
2800+
bool isNegated = false) {
27932801
ast::Type parentType = parentExpr->getType();
27942802

27952803
ast::CallableDecl *callableDecl = tryExtractCallableDecl(parentExpr);
@@ -2835,7 +2843,7 @@ Parser::createCallExpr(SMRange loc, ast::Expr *parentExpr,
28352843
}
28362844

28372845
return ast::CallExpr::create(ctx, loc, parentExpr, arguments,
2838-
callableDecl->getResultType());
2846+
callableDecl->getResultType(), isNegated);
28392847
}
28402848

28412849
FailureOr<ast::DeclRefExpr *> Parser::createDeclRefExpr(SMRange loc,
@@ -2959,8 +2967,7 @@ FailureOr<ast::OperationExpr *> Parser::createOperationExpr(
29592967
OpResultTypeContext resultTypeContext,
29602968
SmallVectorImpl<ast::Expr *> &operands,
29612969
MutableArrayRef<ast::NamedAttributeDecl *> attributes,
2962-
SmallVectorImpl<ast::Expr *> &results,
2963-
unsigned numRegions) {
2970+
SmallVectorImpl<ast::Expr *> &results, unsigned numRegions) {
29642971
std::optional<StringRef> opNameRef = name->getName();
29652972
const ods::Operation *odsOp = lookupODSOperation(opNameRef);
29662973

0 commit comments

Comments
 (0)