[clang] [ast-matcher][NFC] make dump_ast_matchers.py run in any path (PR #117942)

Congcong Cai via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 27 15:43:09 PST 2024


https://github.com/HerrCai0907 created https://github.com/llvm/llvm-project/pull/117942

None

>From 65d7cd18a67fba41fe8cfe191217765830829bc9 Mon Sep 17 00:00:00 2001
From: Congcong Cai <congcongcai0907 at 163.com>
Date: Thu, 28 Nov 2024 07:42:37 +0800
Subject: [PATCH] [ast-matcher][NFC] make dump_ast_matchers.py run in any path

---
 clang/docs/tools/dump_ast_matchers.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/docs/tools/dump_ast_matchers.py b/clang/docs/tools/dump_ast_matchers.py
index 705ff0d4d40985..63e8cd0a25b39c 100755
--- a/clang/docs/tools/dump_ast_matchers.py
+++ b/clang/docs/tools/dump_ast_matchers.py
@@ -5,6 +5,7 @@
 
 import collections
 import re
+import os
 
 try:
     from urllib.request import urlopen
@@ -18,7 +19,9 @@
     CLASS_INDEX_PAGE = None
     print("Unable to get %s: %s" % (CLASS_INDEX_PAGE_URL, e))
 
-MATCHERS_FILE = "../../include/clang/ASTMatchers/ASTMatchers.h"
+CURRENT_DIR = os.path.dirname(__file__)
+MATCHERS_FILE = os.path.join(CURRENT_DIR, "../../include/clang/ASTMatchers/ASTMatchers.h")
+HTML_FILE = os.path.join(CURRENT_DIR, "../LibASTMatchersReference.html")
 
 # Each matcher is documented in one row of the form:
 #   result | name | argA
@@ -590,7 +593,7 @@ def sort_table(matcher_type, matcher_map):
 narrowing_matcher_table = sort_table("NARROWING", narrowing_matchers)
 traversal_matcher_table = sort_table("TRAVERSAL", traversal_matchers)
 
-reference = open("../LibASTMatchersReference.html").read()
+reference = open(HTML_FILE).read()
 reference = re.sub(
     r"<!-- START_DECL_MATCHERS.*END_DECL_MATCHERS -->",
     node_matcher_table,



More information about the cfe-commits mailing list