[Lldb-commits] [lldb] [LLDB] Add type casting to DIL. (PR #159500)

Ilia Kuklin via lldb-commits lldb-commits at lists.llvm.org
Fri Sep 19 10:29:23 PDT 2025


================
@@ -80,15 +159,64 @@ ASTNodeUP DILParser::Run() {
 // Parse an expression.
 //
 //  expression:
-//    unary_expression
+//    cast_expression
 //
-ASTNodeUP DILParser::ParseExpression() { return ParseUnaryExpression(); }
+ASTNodeUP DILParser::ParseExpression() { return ParseCastExpression(); }
+
+// Parse a cast_expression.
+//
+// cast_expression:
+//   unary_expression
+//   "(" type_id ")" cast_expression
+
+ASTNodeUP DILParser::ParseCastExpression() {
+  // This can be a C-style cast, try parsing the contents as a type declaration.
+  if (CurToken().Is(Token::l_paren)) {
+    Token token = CurToken();
+    uint32_t loc = token.GetLocation();
+
+    // Enable lexer backtracking, so that we can rollback in case it's not
+    // actually a type declaration.
+
+    // Start tentative parsing (save token location/idx, for possible rollback).
+    uint32_t save_token_idx = m_dil_lexer.GetCurrentTokenIdx();
+
+    // Consume the token only after enabling the backtracking.
+    m_dil_lexer.Advance();
+
+    // Try parsing the type declaration. If the returned value is not valid,
+    // then we should rollback and try parsing the expression.
+    auto type_id = ParseTypeId();
+    if (type_id) {
+      // Successfully parsed the type declaration. Commit the backtracked
+      // tokens and parse the cast_expression.
+
+      if (!type_id.value().IsValid())
+        return std::make_unique<ErrorNode>();
+
+      Expect(Token::r_paren);
+      m_dil_lexer.Advance();
+      auto rhs = ParseCastExpression();
+
+      // return BuildCStyleCast(type_id.value(), std::move(rhs),
+      //                        token.GetLocation());
----------------
kuilpd wrote:

```suggestion
```

https://github.com/llvm/llvm-project/pull/159500


More information about the lldb-commits mailing list