Revision cdc4ab5fdc61688193ca0526d08cdfe0e8bbdc11 authored by John McCall on 21 January 2016, 01:09:27 UTC, committed by John McCall on 21 January 2016, 02:37:45 UTC
If we ever add the ability for default arguments to refer to
enclosing variables, we should promote DefaultArgumentInitializer
to be an always-present entity, give it an independent capture
list, and make SILDeclRef refer to it directly.  In fact, we may
want to do that anyway.  Until then, it's a weird special case
in terms of not really being a reference to the function returned
by getAnyFunctionRef().

rdar://24242783
1 parent 9127dfd
Raw File
split_file.py
#!/usr/bin/env python

"""
split_file.py [-o <dir>] <path>

Take the file at <path> and write it to multiple files, switching to a new file
every time an annotation of the form "// BEGIN file1.swift" is encountered. If
<dir> is specified, place the files in <dir>; otherwise, put them in the
current directory.
"""

import os
import sys
import re
import getopt

def usage():
    sys.stderr.write(__doc__.strip() + "\n")
    sys.exit(1)

fp_out = None
dest_dir = '.'

try:
    opts, args = getopt.getopt(sys.argv[1:], 'o:h')
    for (opt, arg) in opts:
        if opt == '-o':
            dest_dir = arg
        elif opt == '-h':
            usage()
except getopt.GetoptError:
    usage()

if len(args) != 1:
    usage()
fp_in = open(args[0], 'r')

for line in fp_in:
    m = re.match(r'^//\s*BEGIN\s+([^\s]+)\s*$', line)
    if m:
        if fp_out:
            fp_out.close()
        fp_out = open(os.path.join(dest_dir, m.group(1)), 'w')
    elif fp_out:
        fp_out.write(line)

fp_in.close()
if fp_out:
    fp_out.close()
back to top