Bug 1865597 - Add error checking when initializing parallel marking and disable on...
[gecko.git] / js / src / frontend / align_stack_comment.py
blob28d5d8cf7fe17761fe35e3421364de5420848a66
1 #!/usr/bin/python -B
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 # You can obtain one at http://mozilla.org/MPL/2.0/.
7 """ Usage: align_stack_comment.py FILE
9 This script aligns the stack transition comment in BytecodeEmitter and
10 its helper classes.
12 The stack transition comment looks like the following:
13 // [stack] VAL1 VAL2 VAL3
14 """
16 import re
17 import sys
19 # The column index of '[' of '[stack]'
20 ALIGNMENT_COLUMN = 20
22 # The maximum column for comment
23 MAX_CHARS_PER_LINE = 80
25 stack_comment_pat = re.compile("^( *//) *(\[stack\].*)$")
28 def align_stack_comment(path):
29 lines = []
30 changed = False
32 with open(path) as f:
33 max_head_len = 0
34 max_comment_len = 0
36 line_num = 0
38 for line in f:
39 line_num += 1
40 # Python includes \n in lines.
41 line = line.rstrip("\n")
43 m = stack_comment_pat.search(line)
44 if m:
45 head = m.group(1) + " "
46 head_len = len(head)
47 comment = m.group(2)
48 comment_len = len(comment)
50 if head_len > ALIGNMENT_COLUMN:
51 print(
52 "Warning: line {} overflows from alignment column {}: {}".format(
53 line_num, ALIGNMENT_COLUMN, head_len
55 file=sys.stderr,
58 line_len = max(head_len, ALIGNMENT_COLUMN) + comment_len
59 if line_len > MAX_CHARS_PER_LINE:
60 print(
61 "Warning: line {} overflows from {} chars: {}".format(
62 line_num, MAX_CHARS_PER_LINE, line_len
64 file=sys.stderr,
67 max_head_len = max(max_head_len, head_len)
68 max_comment_len = max(max_comment_len, comment_len)
70 spaces = max(ALIGNMENT_COLUMN - head_len, 0)
71 formatted = head + " " * spaces + comment
73 if formatted != line:
74 changed = True
76 lines.append(formatted)
77 else:
78 lines.append(line)
80 print(
81 "Info: Minimum column number for [stack]: {}".format(max_head_len),
82 file=sys.stderr,
84 print(
85 "Info: Alignment column number for [stack]: {}".format(ALIGNMENT_COLUMN),
86 file=sys.stderr,
88 print(
89 "Info: Max length of stack transition comments: {}".format(max_comment_len),
90 file=sys.stderr,
93 if changed:
94 with open(path, "w") as f:
95 for line in lines:
96 print(line, file=f)
97 else:
98 print("No change.")
101 if __name__ == "__main__":
102 if len(sys.argv) < 2:
103 print("Usage: align_stack_comment.py FILE", file=sys.stderr)
104 sys.exit(1)
106 for path in sys.argv[1:]:
107 print(path)
108 align_stack_comment(path)