Changeset View
Changeset View
Standalone View
Standalone View
clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||||
import os | import os | ||||
import sys | import sys | ||||
import json | import json | ||||
import filecmp | |||||
import shutil | |||||
import argparse | import argparse | ||||
class Generator(object): | class Generator(object): | ||||
implementationContent = '' | implementationContent = '' | ||||
def GeneratePrologue(self): | def GeneratePrologue(self): | ||||
▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | |||||
def main(): | def main(): | ||||
parser = argparse.ArgumentParser() | parser = argparse.ArgumentParser() | ||||
parser.add_argument('--json-input-path', | parser.add_argument('--json-input-path', | ||||
help='Read API description from FILE', metavar='FILE') | help='Read API description from FILE', metavar='FILE') | ||||
parser.add_argument('--output-file', help='Generate output in FILEPATH', | parser.add_argument('--output-file', help='Generate output in FILEPATH', | ||||
metavar='FILEPATH') | metavar='FILEPATH') | ||||
parser.add_argument('--empty-implementation', | parser.add_argument('--use-empty-implementation', | ||||
help='Generate empty implementation', | help='Generate empty implementation', | ||||
action="store", type=int) | action="store", type=int) | ||||
parser.add_argument('--empty-implementation', | |||||
help='Copy empty implementation from FILEPATH', | |||||
action="store", metavar='FILEPATH') | |||||
options = parser.parse_args() | options = parser.parse_args() | ||||
use_empty_implementation = options.empty_implementation | use_empty_implementation = options.use_empty_implementation | ||||
if (not use_empty_implementation | if (not use_empty_implementation | ||||
and not os.path.exists(options.json_input_path)): | and not os.path.exists(options.json_input_path)): | ||||
use_empty_implementation = True | use_empty_implementation = True | ||||
if not use_empty_implementation: | if not use_empty_implementation: | ||||
with open(options.json_input_path) as f: | with open(options.json_input_path) as f: | ||||
jsonData = json.load(f) | jsonData = json.load(f) | ||||
if not 'classesInClade' in jsonData or not jsonData["classesInClade"]: | if not 'classesInClade' in jsonData or not jsonData["classesInClade"]: | ||||
use_empty_implementation = True | use_empty_implementation = True | ||||
if use_empty_implementation: | if use_empty_implementation: | ||||
with open(os.path.join(os.getcwd(), | if not os.path.exists(options.output_file) or \ | ||||
options.output_file), 'w') as f: | not filecmp.cmp(options.empty_implementation, options.output_file): | ||||
f.write(""" | shutil.copyfile(options.empty_implementation, options.output_file) | ||||
thakis: Shouldn't this be `f.write(open(options.empty_implementation).read())`?
If you're changing… | |||||
namespace clang { | |||||
namespace tooling { | |||||
NodeLocationAccessors NodeIntrospection::GetLocations(clang::Stmt const *) { | |||||
return {}; | |||||
} | |||||
NodeLocationAccessors | |||||
NodeIntrospection::GetLocations(clang::DynTypedNode const &) { | |||||
return {}; | |||||
} | |||||
} // namespace tooling | |||||
} // namespace clang | |||||
""") | |||||
sys.exit(0) | sys.exit(0) | ||||
g = Generator() | g = Generator() | ||||
g.GeneratePrologue() | g.GeneratePrologue() | ||||
for (CladeName, ClassNameData) in jsonData['classesInClade'].items(): | for (CladeName, ClassNameData) in jsonData['classesInClade'].items(): | ||||
g.GenerateBaseGetLocationsDeclaration(CladeName) | g.GenerateBaseGetLocationsDeclaration(CladeName) | ||||
Show All 16 Lines |
Shouldn't this be f.write(open(options.empty_implementation).read())?
If you're changing this, you could also make it so that it only writes the output if it'd be different from what it's there, with something like this: