1#! /usr/bin/env python3 2import sys, os, re, urllib.request 3 4 5default_issue_list_path = 'cwg_index.html' 6issue_list_url = "https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_index.html" 7output = 'cxx_dr_status.html' 8dr_test_dir = '../test/CXX/drs' 9 10class DR: 11 def __init__(self, section, issue, url, status, title): 12 self.section, self.issue, self.url, self.status, self.title = \ 13 section, issue, url, status, title 14 def __repr__(self): 15 return '%s (%s): %s' % (self.issue, self.status, self.title) 16 17def parse(dr): 18 try: 19 section, issue_link, status, liaison, title = [ 20 col.split('>', 1)[1].split('</TD>')[0] 21 for col in dr.split('</TR>', 1)[0].split('<TD')[1:] 22 ] 23 except Exception as ex: 24 print(f"Parse error: {ex}\n{dr}", file=sys.stderr) 25 sys.exit(1) 26 _, url, issue = issue_link.split('"', 2) 27 url = url.strip() 28 issue = int(issue.split('>', 1)[1].split('<', 1)[0]) 29 title = title.replace('<issue_title>', '').replace('</issue_title>', '').replace('\r\n', '\n').strip() 30 return DR(section, issue, url, status, title) 31 32def collect_tests(): 33 status_re = re.compile(r'\bdr([0-9]+): (.*)') 34 status_map = {} 35 for test_cpp in os.listdir(dr_test_dir): 36 if not test_cpp.endswith('.cpp'): 37 continue 38 test_cpp = os.path.join(dr_test_dir, test_cpp) 39 found_any = False; 40 for match in re.finditer(status_re, open(test_cpp, 'r').read()): 41 status_map[int(match.group(1))] = match.group(2) 42 found_any = True 43 if not found_any: 44 print("warning:%s: no '// dr123: foo' comments in this file" % test_cpp, file=sys.stderr) 45 return status_map 46 47def get_issues(path): 48 buffer = None 49 if not path and os.path.exists(default_issue_list_path): 50 path = default_issue_list_path 51 try: 52 if path is None: 53 print('Fetching issue list from {}'.format(issue_list_url)) 54 with urllib.request.urlopen(issue_list_url) as f: 55 buffer = f.read().decode('utf-8') 56 else: 57 print('Opening issue list from file {}'.format(path)) 58 with open(path, 'r') as f: 59 buffer = f.read() 60 except Exception as ex: 61 print('Unable to read the core issue list', file=sys.stderr) 62 print(ex, file=sys.stderr) 63 sys.exit(1) 64 65 return sorted((parse(dr) for dr in buffer.split('<TR>')[2:]), 66 key = lambda dr: dr.issue) 67 68 69issue_list_path = None 70if len(sys.argv) == 1: 71 pass 72elif len(sys.argv) == 2: 73 issue_list_path = sys.argv[1] 74else: 75 print('Usage: {} [<path to cwg_index.html>]'.format(sys.argv[0]), file=sys.stderr) 76 sys.exit(1) 77 78status_map = collect_tests() 79drs = get_issues(issue_list_path) 80out_file = open(output, 'w') 81out_file.write('''\ 82<!DOCTYPE html> 83<!-- This file is auto-generated by make_cxx_dr_status. Do not modify. --> 84<html> 85<head> 86 <META http-equiv="Content-Type" content="text/html; charset=utf-8"> 87 <title>Clang - C++ Defect Report Status</title> 88 <link type="text/css" rel="stylesheet" href="menu.css"> 89 <link type="text/css" rel="stylesheet" href="content.css"> 90 <style type="text/css"> 91 .none { background-color: #FFCCCC } 92 .partial { background-color: #FFE0B0 } 93 .unreleased { background-color: #FFFF99 } 94 .full { background-color: #CCFF99 } 95 .na { background-color: #DDDDDD } 96 .open * { color: #AAAAAA } 97 //.open { filter: opacity(0.2) } 98 tr:target { background-color: #FFFFBB } 99 th { background-color: #FFDDAA } 100 </style> 101</head> 102<body> 103 104<!--#include virtual="menu.html.incl"--> 105 106<div id="content"> 107 108<!--*************************************************************************--> 109<h1>C++ Defect Report Support in Clang</h1> 110<!--*************************************************************************--> 111 112<h2 id="cxxdr">C++ defect report implementation status</h2> 113 114<p>This page tracks which C++ defect reports are implemented within Clang.</p> 115 116<table width="689" border="1" cellspacing="0"> 117 <tr> 118 <th>Number</th> 119 <th>Status</th> 120 <th>Issue title</th> 121 <th>Available in Clang?</th> 122 </tr>''') 123 124latest_release = 15 125 126def availability(issue): 127 status = status_map.get(issue, 'unknown') 128 129 unresolved_status = '' 130 if status.endswith(' open'): 131 status = status[:-5] 132 unresolved_status = 'open' 133 elif status.endswith(' drafting'): 134 status = status[:-9] 135 unresolved_status = 'drafting' 136 elif status.endswith(' review'): 137 status = status[:-7] 138 unresolved_status = 'review' 139 140 avail_suffix = '' 141 if status.endswith(' c++11'): 142 status = status[:-6] 143 avail_suffix = ' (C++11 onwards)' 144 elif status.endswith(' c++14'): 145 status = status[:-6] 146 avail_suffix = ' (C++14 onwards)' 147 elif status.endswith(' c++17'): 148 status = status[:-6] 149 avail_suffix = ' (C++17 onwards)' 150 elif status.endswith(' c++20'): 151 status = status[:-6] 152 avail_suffix = ' (C++20 onwards)' 153 if status == 'unknown': 154 avail = 'Unknown' 155 avail_style = ' class="none"' 156 elif re.match('^[0-9]+\.?[0-9]*', status): 157 avail = 'Clang %s' % status 158 if float(status) > latest_release: 159 avail_style = ' class="unreleased"' 160 else: 161 avail_style = ' class="full"' 162 elif status == 'yes': 163 avail = 'Yes' 164 avail_style = ' class="full"' 165 elif status == 'partial': 166 avail = 'Partial' 167 avail_style = ' class="partial"' 168 elif status == 'no': 169 avail = 'No' 170 avail_style = ' class="none"' 171 elif status == 'na': 172 avail = 'N/A' 173 avail_style = ' class="na"' 174 elif status == 'na lib': 175 avail = 'N/A (Library DR)' 176 avail_style = ' class="na"' 177 elif status == 'na abi': 178 avail = 'N/A (ABI constraint)' 179 avail_style = ' class="na"' 180 elif status.startswith('sup '): 181 dup = status.split(' ', 1)[1] 182 if dup.startswith('P'): 183 avail = 'Superseded by <a href="https://wg21.link/%s">%s</a>' % (dup, dup) 184 avail_style = ' class="na"' 185 else: 186 avail = 'Superseded by <a href="#%s">%s</a>' % (dup, dup) 187 try: 188 _, avail_style, _ = availability(int(dup)) 189 except: 190 print("issue %s marked as sup %s" % (issue, dup), file=sys.stderr) 191 avail_style = ' class="none"' 192 elif status.startswith('dup '): 193 dup = int(status.split(' ', 1)[1]) 194 avail = 'Duplicate of <a href="#%s">%s</a>' % (dup, dup) 195 _, avail_style, _ = availability(dup) 196 else: 197 assert False, 'unknown status %s for issue %s' % (status, dr.issue) 198 return (avail + avail_suffix, avail_style, unresolved_status) 199 200count = {} 201for dr in drs: 202 if dr.status in ('concepts',): 203 # This refers to the old ("C++0x") concepts feature, which was not part 204 # of any C++ International Standard or Technical Specification. 205 continue 206 207 elif dr.status == 'extension': 208 row_style = ' class="open"' 209 avail = 'Extension' 210 avail_style = '' 211 212 elif dr.status in ('open', 'drafting', 'review'): 213 row_style = ' class="open"' 214 avail, avail_style, unresolved_status = availability(dr.issue) 215 if avail == 'Unknown': 216 avail = 'Not resolved' 217 avail_style = '' 218 else: 219 assert unresolved_status == dr.status, \ 220 "Issue %s is marked '%s', which differs from CWG index status '%s'" \ 221 % (dr.issue, unresolved_status, dr.status) 222 else: 223 row_style = '' 224 avail, avail_style, unresolved_status = availability(dr.issue) 225 assert not unresolved_status, \ 226 "Issue %s is marked '%s', even though it is resolved in CWG index" \ 227 % (dr.issue, unresolved_status) 228 229 if not avail.startswith('Sup') and not avail.startswith('Dup'): 230 count[avail] = count.get(avail, 0) + 1 231 232 out_file.write(''' 233 <tr%s id="%s"> 234 <td><a href="https://wg21.link/cwg%s">%s</a></td> 235 <td>%s</td> 236 <td>%s</td> 237 <td%s align="center">%s</td> 238 </tr>''' % (row_style, dr.issue, dr.issue, dr.issue, dr.status, dr.title, avail_style, avail)) 239 240for status, num in sorted(count.items()): 241 print("%s: %s" % (status, num), file=sys.stderr) 242 243out_file.write('''\ 244</table> 245 246</div> 247</body> 248</html> 249''') 250out_file.close() 251 252