MCPcopy Index your code
hub / github.com/nodejs/node / preprocess

Function preprocess

deps/v8/tools/torque/format-torque.py:25–103  ·  view source on GitHub ↗
(input)

Source from the content-addressed store, hash-verified

23kAddressofEscape = r'⌂'; # Unicode house
24
25def preprocess(input):
26 # Special handing of '%' for intrinsics, turn the percent
27 # into a unicode character so that it gets treated as part of the
28 # intrinsic's name if it's already adjacent to it.
29 input = re.sub(r'%([A-Za-z])', kPercentEscape + r'\1', input)
30 # Similarly, avoid treating * and & as binary operators when they're
31 # probably used as address operators.
32 input = re.sub(r'([^/])\*([a-zA-Z(])', r'\1' + kDerefEscape + r'\2', input)
33 input = re.sub(r'&([a-zA-Z(])', kAddressofEscape + r'\1', input)
34
35 input = re.sub(r'(if\s+)constexpr(\s*\()', r'\1/*COxp*/\2', input)
36 input = re.sub(r'\btypeswitch\s*(\([^{]*\))\s{', r' if /*tPsW*/ \1 {', input)
37 input = re.sub(r'\bcase\s*(\([^{]*\))\s*:\s*deferred\s*{', r' if /*cAsEdEfF*/ \1 {', input)
38 input = re.sub(r'\bcase\s*(\([^{]*\))\s*:\s*{', r' if /*cA*/ \1 {', input)
39
40 input = re.sub(r'\bgenerates\s+\'([^\']+)\'\s*', r'_GeNeRaT_/*\1@*/', input)
41 input = re.sub(r'\bconstexpr\s+\'([^\']+)\'\s*', r'_CoNsExP_/*\1@*/', input)
42
43 def createFunctionReplacement(m):
44 torque_def = m.group(1)
45 torque_def = re.sub(r'\s+', ' ', torque_def)
46 function_len = len("function")
47 function_and_comment_len = len("function /**/")
48 if len(torque_def) < function_len:
49 return f'// !!torquefunc {torque_def}\nfunction '
50 else:
51 return f'// !!torquefunc {torque_def}\nfunction /*{"-" * (len(torque_def) - function_and_comment_len)}*/ '
52
53 input = re.sub(
54 r'^[ \t]*((?:extern\s+)?(?:transitioning\s+)?(?:javascript\s+)?(?:operator\s*\'[^\']+\'\s*)?(?:macro|builtin|runtime))\s+&#x27;,
55 createFunctionReplacement,
56 input,
57 flags=re.MULTILINE)
58
59 def createClassReplacement(m):
60 torque_def = m.group(1)
61 class_len = len("class")
62 class_and_comment_len = len("class /**/")
63 if len(torque_def) < class_len:
64 return f'// !!torqueclass {torque_def}\nclass '
65 else:
66 return f'// !!torqueclass {torque_def}\nclass /*{"-" * (len(torque_def) - class_and_comment_len)}*/ '
67
68 input = re.sub(
69 r'^[ \t]*((?:extern\s+)?(?:bitfield\s+)?(?:struct|class|shape))\s+',
70 createClassReplacement,
71 input,
72 flags=re.MULTILINE)
73
74 input = re.sub(r'\notherwise',
75 r'\n otherwise', input)
76 input = re.sub(r'(\n\s*\S[^\n]*\s)otherwise',
77 r'\1_OtheSaLi', input)
78 input = re.sub(r'@if(not)?\(', r'if /*!if\1*/ (', input)
79 input = re.sub(
80 r'(js-)?implicit\s+([^)]*?)\s*\)\(\s*\)',
81 r'/*\1ImPl*/\2Ǝ)',
82 input,

Callers 1

processFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected