[Mlir-commits] [mlir] 6d4471e - [mlir:PDLL] Improve the location ranges of several expressions during parsing

River Riddle llvmlistbot at llvm.org
Wed May 18 00:24:07 PDT 2022


Author: River Riddle
Date: 2022-05-18T00:23:47-07:00
New Revision: 6d4471efb0b94c066e5e93c99278397691869dbc

URL: https://github.com/llvm/llvm-project/commit/6d4471efb0b94c066e5e93c99278397691869dbc
DIFF: https://github.com/llvm/llvm-project/commit/6d4471efb0b94c066e5e93c99278397691869dbc.diff

LOG: [mlir:PDLL] Improve the location ranges of several expressions during parsing

This allows for the range to encompass more of the source associated
with the full expression, making diagnostics easier to see/tooling easier/etc.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Tools/PDLL/Parser/Parser.cpp b/mlir/lib/Tools/PDLL/Parser/Parser.cpp
index f2406bae5d48e..8efc3d0fce7b8 100644
--- a/mlir/lib/Tools/PDLL/Parser/Parser.cpp
+++ b/mlir/lib/Tools/PDLL/Parser/Parser.cpp
@@ -1766,6 +1766,7 @@ FailureOr<ast::Expr *> Parser::parseAttributeExpr() {
   std::string attrExpr = curToken.getStringValue();
   consumeToken();
 
+  loc.End = curToken.getEndLoc();
   if (failed(
           parseToken(Token::greater, "expected `>` after attribute literal")))
     return failure();
@@ -1773,7 +1774,6 @@ FailureOr<ast::Expr *> Parser::parseAttributeExpr() {
 }
 
 FailureOr<ast::Expr *> Parser::parseCallExpr(ast::Expr *parentExpr) {
-  SMRange loc = curToken.getLoc();
   consumeToken(Token::l_paren);
 
   // Parse the arguments of the call.
@@ -1792,7 +1792,8 @@ FailureOr<ast::Expr *> Parser::parseCallExpr(ast::Expr *parentExpr) {
       arguments.push_back(*argument);
     } while (consumeIf(Token::comma));
   }
-  loc.End = curToken.getEndLoc();
+
+  SMRange loc(parentExpr->getLoc().Start, curToken.getEndLoc());
   if (failed(parseToken(Token::r_paren, "expected `)` after argument list")))
     return failure();
 
@@ -1846,7 +1847,7 @@ FailureOr<ast::Expr *> Parser::parseInlineRewriteLambdaExpr() {
 }
 
 FailureOr<ast::Expr *> Parser::parseMemberAccessExpr(ast::Expr *parentExpr) {
-  SMRange loc = curToken.getLoc();
+  SMRange dotLoc = curToken.getLoc();
   consumeToken(Token::dot);
 
   // Check for code completion of the member name.
@@ -1857,8 +1858,9 @@ FailureOr<ast::Expr *> Parser::parseMemberAccessExpr(ast::Expr *parentExpr) {
   Token memberNameTok = curToken;
   if (memberNameTok.isNot(Token::identifier, Token::integer) &&
       !memberNameTok.isKeyword())
-    return emitError(loc, "expected identifier or numeric member name");
+    return emitError(dotLoc, "expected identifier or numeric member name");
   StringRef memberName = memberNameTok.getSpelling();
+  SMRange loc(parentExpr->getLoc().Start, curToken.getEndLoc());
   consumeToken();
 
   return createMemberAccessExpr(parentExpr, memberName, loc);
@@ -2099,6 +2101,7 @@ FailureOr<ast::Expr *> Parser::parseTypeExpr() {
   std::string attrExpr = curToken.getStringValue();
   consumeToken();
 
+  loc.End = curToken.getEndLoc();
   if (failed(parseToken(Token::greater, "expected `>` after type literal")))
     return failure();
   return ast::TypeExpr::create(ctx, loc, attrExpr);


        


More information about the Mlir-commits mailing list