Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
llvm/utils/UpdateTestChecks/common.py
Show All 16 Lines | |||||
_verbose = False | _verbose = False | ||||
_prefix_filecheck_ir_name = '' | _prefix_filecheck_ir_name = '' | ||||
""" | """ | ||||
Version changelog: | Version changelog: | ||||
1: Initial version, used by tests that don't specify --version explicitly. | 1: Initial version, used by tests that don't specify --version explicitly. | ||||
2: --function-signature now also checks return type/attributes. | 2: --function-signature is now enabled by default and also checks return | ||||
type/attributes. | |||||
""" | """ | ||||
DEFAULT_VERSION = 1 | DEFAULT_VERSION = 2 | ||||
class Regex(object): | class Regex(object): | ||||
"""Wrap a compiled regular expression object to allow deep copy of a regexp. | """Wrap a compiled regular expression object to allow deep copy of a regexp. | ||||
This is required for the deep copy done in do_scrub. | This is required for the deep copy done in do_scrub. | ||||
""" | """ | ||||
def __init__(self, regex): | def __init__(self, regex): | ||||
self.regex = regex | self.regex = regex | ||||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | parser.add_argument('--version', type=int, default=1, | ||||
help='The version of output format') | help='The version of output format') | ||||
args = parser.parse_args() | args = parser.parse_args() | ||||
global _verbose, _global_value_regex, _global_hex_value_regex | global _verbose, _global_value_regex, _global_hex_value_regex | ||||
_verbose = args.verbose | _verbose = args.verbose | ||||
_global_value_regex = args.global_value_regex | _global_value_regex = args.global_value_regex | ||||
_global_hex_value_regex = args.global_hex_value_regex | _global_hex_value_regex = args.global_hex_value_regex | ||||
return args | return args | ||||
def parse_args(parser, argv): | |||||
args = parser.parse_args(argv) | |||||
if args.version >= 2: | |||||
args.function_signature = True | |||||
return args | |||||
class InputLineInfo(object): | class InputLineInfo(object): | ||||
def __init__(self, line, line_number, args, argv): | def __init__(self, line, line_number, args, argv): | ||||
self.line = line | self.line = line | ||||
self.line_number = line_number | self.line_number = line_number | ||||
self.args = args | self.args = args | ||||
self.argv = argv | self.argv = argv | ||||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | for test in tests_list: | ||||
first_line = input_lines[0] if input_lines else "" | first_line = input_lines[0] if input_lines else "" | ||||
is_regenerate = UTC_ADVERT in first_line | is_regenerate = UTC_ADVERT in first_line | ||||
# If we're generating a new test, set the default version to the latest. | # If we're generating a new test, set the default version to the latest. | ||||
argv = sys.argv[:] | argv = sys.argv[:] | ||||
if not is_regenerate: | if not is_regenerate: | ||||
argv.insert(1, '--version=' + str(DEFAULT_VERSION)) | argv.insert(1, '--version=' + str(DEFAULT_VERSION)) | ||||
args = parser.parse_args(argv[1:]) | args = parse_args(parser, argv[1:]) | ||||
arichardson: I think this would be the place to add `if args.version >= 2: args.function_signature = True` | |||||
That wouldn't be sufficient due to the on-the-fly flags update feature (that probably isn't worth the complexity it introduces -- we should consider removing it.) I could extract the parse_args() calls into a common helper though, where we could do this. nikic: That wouldn't be sufficient due to the on-the-fly flags update feature (that probably isn't… | |||||
if argparse_callback is not None: | if argparse_callback is not None: | ||||
argparse_callback(args) | argparse_callback(args) | ||||
if is_regenerate: | if is_regenerate: | ||||
if script_name not in first_line and not args.force_update: | if script_name not in first_line and not args.force_update: | ||||
warn("Skipping test which wasn't autogenerated by " + script_name, test) | warn("Skipping test which wasn't autogenerated by " + script_name, test) | ||||
continue | continue | ||||
args, argv = check_for_command(first_line, parser, args, argv, argparse_callback) | args, argv = check_for_command(first_line, parser, args, argv, argparse_callback) | ||||
elif args.update_only: | elif args.update_only: | ||||
▲ Show 20 Lines • Show All 936 Lines • ▼ Show 20 Lines | for action in parser._actions: | ||||
value = getattr(args, action.dest) | value = getattr(args, action.dest) | ||||
if action.const is not None: # action stores a constant (usually True/False) | if action.const is not None: # action stores a constant (usually True/False) | ||||
# Skip actions with different constant values (this happens with boolean | # Skip actions with different constant values (this happens with boolean | ||||
# --foo/--no-foo options) | # --foo/--no-foo options) | ||||
if value != action.const: | if value != action.const: | ||||
continue | continue | ||||
if parser.get_default(action.dest) == value: | if parser.get_default(action.dest) == value: | ||||
continue # Don't add default values | continue # Don't add default values | ||||
if action.dest == 'function_signature' and args.version >= 2: | |||||
continue # Enabled by default in version 2 | |||||
if action.dest == 'filters': | if action.dest == 'filters': | ||||
# Create a separate option for each filter element. The value is a list | # Create a separate option for each filter element. The value is a list | ||||
# of Filter objects. | # of Filter objects. | ||||
for elem in value: | for elem in value: | ||||
opt_name = 'filter-out' if elem.is_filter_out else 'filter' | opt_name = 'filter-out' if elem.is_filter_out else 'filter' | ||||
opt_value = elem.pattern() | opt_value = elem.pattern() | ||||
new_arg = '--%s "%s" ' % (opt_name, opt_value.strip('"')) | new_arg = '--%s "%s" ' % (opt_name, opt_value.strip('"')) | ||||
if new_arg not in autogenerated_note_args: | if new_arg not in autogenerated_note_args: | ||||
Show All 10 Lines | |||||
def check_for_command(line, parser, args, argv, argparse_callback): | def check_for_command(line, parser, args, argv, argparse_callback): | ||||
cmd_m = UTC_ARGS_CMD.match(line) | cmd_m = UTC_ARGS_CMD.match(line) | ||||
if cmd_m: | if cmd_m: | ||||
for option in shlex.split(cmd_m.group('cmd').strip()): | for option in shlex.split(cmd_m.group('cmd').strip()): | ||||
if option: | if option: | ||||
argv.append(option) | argv.append(option) | ||||
args = parser.parse_args(filter(lambda arg: arg not in args.tests, argv)) | args = parse_args(parser, filter(lambda arg: arg not in args.tests, argv)) | ||||
if argparse_callback is not None: | if argparse_callback is not None: | ||||
argparse_callback(args) | argparse_callback(args) | ||||
return args, argv | return args, argv | ||||
def find_arg_in_test(test_info, get_arg_to_check, arg_string, is_global): | def find_arg_in_test(test_info, get_arg_to_check, arg_string, is_global): | ||||
result = get_arg_to_check(test_info.args) | result = get_arg_to_check(test_info.args) | ||||
if not result and is_global: | if not result and is_global: | ||||
# See if this has been specified via UTC_ARGS. This is a "global" option | # See if this has been specified via UTC_ARGS. This is a "global" option | ||||
▲ Show 20 Lines • Show All 68 Lines • Show Last 20 Lines |
I think this would be the place to add if args.version >= 2: args.function_signature = True