summaryrefslogtreecommitdiffstats
path: root/js/src/regexp/update-headers.py
blob: 0cff9d6aee663688d0da8db8dffe7b312fc46312 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

#
# This script modifies V8 regexp source files to make them suitable for
# inclusion in SpiderMonkey. Specifically, it:
#
# 1. Rewrites all #includes of V8 regexp headers to point to their location in
#    the SM tree: src/regexp/* --> regexp/*
# 2. Removes all #includes of other V8 src/* headers. The required definitions
#    will be provided by regexp-shim.h.
#
# Usage:
#    cd js/src/regexp
#    find . -name "*.h" -o -name "*.cc" | xargs ./update_headers.py
#

import fileinput
import re
import sys

# 1. Rewrite includes of V8 regexp headers
regexp_include = re.compile('#include "src/regexp')
regexp_include_new = '#include "regexp'

# 2. Remove includes of other V8 headers
other_include = re.compile('#include "src/')

for line in fileinput.input(inplace=1):
    if regexp_include.search(line):
        sys.stdout.write(re.sub(regexp_include, regexp_include_new, line))
    elif other_include.search(line):
        pass
    else:
        sys.stdout.write(line)