[Lldb-commits] [lldb] [lldb] Use Python script to generate SBLanguages.h (PR #90753)

Dave Lee via lldb-commits lldb-commits at lists.llvm.org
Wed May 1 11:01:34 PDT 2024


================
@@ -0,0 +1,65 @@
+#!/usr/bin/env python3
+
+import argparse
+import re
+
+HEADER = """\
+//===-- SBLanguages.h -----------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_API_SBLANGUAGE_H
+#define LLDB_API_SBLANGUAGE_H
+/// Used by \\ref SBExpressionOptions.
+/// These enumerations use the same language enumerations as the DWARF
+/// specification for ease of use and consistency.
+enum SBSourceLanguageName : uint16_t {
+"""
+
+FOOTER = """\
+};
+
+#endif
+"""
+
+REGEX = re.compile(r'(^ *HANDLE_DW_LNAME *\( *([^,]+), ([^,]+), )"(.*)",.*\).*')
+
+
+def emit_enum(input, output):
+    # Read the input and break it up by lines.
+    lines = []
+    with open(input, "r") as f:
+        lines = f.readlines()
+
+    # Write the output.
+    with open(output, "w") as f:
+        # Emit the header.
+        f.write(HEADER)
+
+        # Emit the enum values.
+        for line in lines:
+            match = REGEX.search(line)
+            if not match:
+                continue
+            f.write(f"  /// {match.group(4)}.\n")
+            f.write(f"  eLanguageName{match.group(3)} = {match.group(2)},\n")
----------------
kastiglione wrote:

these would benefit from using named captures, ex:

```suggestion
            f.write(f"  /// {match.group("whatever_group_4_is")}.\n")
            f.write(f"  eLanguageName{match.group("name")} = {match.group("value")},\n")
```

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


More information about the lldb-commits mailing list