lib/clippy: expand some macros

At least the "easy" cases of macros work.

Signed-off-by: David Lamparter <equinox@diac24.net>
This commit is contained in:
David Lamparter 2019-06-11 15:35:28 +02:00
parent 4381a59be0
commit b41b3f7bf1
2 changed files with 45 additions and 20 deletions

View File

@ -201,7 +201,27 @@ def get_always_args(token, always_args, args = [], stack = []):
for nexttkn in token.next(): for nexttkn in token.next():
get_always_args(nexttkn, always_args, args, stack) get_always_args(nexttkn, always_args, args, stack)
def process_file(fn, ofd, dumpfd, all_defun): class Macros(dict):
def load(self, filename):
filedata = clippy.parse(filename)
for entry in filedata['data']:
if entry['type'] != 'PREPROC':
continue
ppdir = entry['line'].lstrip().split(None, 1)
if ppdir[0] != 'define' or len(ppdir) != 2:
continue
ppdef = ppdir[1].split(None, 1)
name = ppdef[0]
if '(' in name:
continue
val = ppdef[1] if len(ppdef) == 2 else ''
val = val.strip(' \t\n\\')
if name in self:
sys.stderr.write('warning: macro %s redefined!\n' % (name))
self[name] = val
def process_file(fn, ofd, dumpfd, all_defun, macros):
errors = 0 errors = 0
filedata = clippy.parse(fn) filedata = clippy.parse(fn)
@ -213,15 +233,21 @@ def process_file(fn, ofd, dumpfd, all_defun):
continue continue
cmddef = entry['args'][2] cmddef = entry['args'][2]
cmddefx = []
for i in cmddef: for i in cmddef:
if not (i.startswith('"') and i.endswith('"')): while i in macros:
sys.stderr.write('%s:%d: DEFPY command string not parseable (%r)\n' % (fn, entry['lineno'], cmddef)) i = macros[i]
errors += 1 if i.startswith('"') and i.endswith('"'):
cmddef = None cmddefx.append(i[1:-1])
break continue
if cmddef is None:
sys.stderr.write('%s:%d: DEFPY command string not parseable (%r)\n' % (fn, entry['lineno'], cmddef))
errors += 1
cmddefx = None
break
if cmddefx is None:
continue continue
cmddef = ''.join([i[1:-1] for i in cmddef]) cmddef = ''.join([i for i in cmddefx])
graph = clippy.Graph(cmddef) graph = clippy.Graph(cmddef)
args = OrderedDict() args = OrderedDict()
@ -320,7 +346,13 @@ if __name__ == '__main__':
if args.show: if args.show:
dumpfd = sys.stderr dumpfd = sys.stderr
errors = process_file(args.cfile, ofd, dumpfd, args.all_defun) macros = Macros()
macros.load('lib/route_types.h')
macros.load('lib/command.h')
# sigh :(
macros['PROTO_REDIST_STR'] = 'FRR_REDIST_STR_ISISD'
errors = process_file(args.cfile, ofd, dumpfd, args.all_defun, macros)
if errors != 0: if errors != 0:
sys.exit(1) sys.exit(1)

View File

@ -2172,7 +2172,7 @@ DEFPY (show_evpn_mac_vni_all_dad,
DEFPY (show_evpn_mac_vni_dad, DEFPY (show_evpn_mac_vni_dad,
show_evpn_mac_vni_dad_cmd, show_evpn_mac_vni_dad_cmd,
"show evpn mac vni " CMD_VNI_RANGE " duplicate" "[json]", "show evpn mac vni " CMD_VNI_RANGE " duplicate [json]",
SHOW_STR SHOW_STR
"EVPN\n" "EVPN\n"
"MAC addresses\n" "MAC addresses\n"
@ -2182,10 +2182,8 @@ DEFPY (show_evpn_mac_vni_dad,
JSON_STR) JSON_STR)
{ {
struct zebra_vrf *zvrf; struct zebra_vrf *zvrf;
vni_t vni;
bool uj = use_json(argc, argv); bool uj = use_json(argc, argv);
vni = strtoul(argv[4]->arg, NULL, 10);
zvrf = zebra_vrf_get_evpn(); zvrf = zebra_vrf_get_evpn();
zebra_vxlan_print_macs_vni_dad(vty, zvrf, vni, uj); zebra_vxlan_print_macs_vni_dad(vty, zvrf, vni, uj);
@ -2195,7 +2193,7 @@ DEFPY (show_evpn_mac_vni_dad,
DEFPY (show_evpn_neigh_vni_dad, DEFPY (show_evpn_neigh_vni_dad,
show_evpn_neigh_vni_dad_cmd, show_evpn_neigh_vni_dad_cmd,
"show evpn arp-cache vni " CMD_VNI_RANGE "duplicate" "[json]", "show evpn arp-cache vni " CMD_VNI_RANGE "duplicate [json]",
SHOW_STR SHOW_STR
"EVPN\n" "EVPN\n"
"ARP and ND cache\n" "ARP and ND cache\n"
@ -2205,10 +2203,8 @@ DEFPY (show_evpn_neigh_vni_dad,
JSON_STR) JSON_STR)
{ {
struct zebra_vrf *zvrf; struct zebra_vrf *zvrf;
vni_t vni;
bool uj = use_json(argc, argv); bool uj = use_json(argc, argv);
vni = strtoul(argv[4]->arg, NULL, 10);
zvrf = zebra_vrf_get_evpn(); zvrf = zebra_vrf_get_evpn();
zebra_vxlan_print_neigh_vni_dad(vty, zvrf, vni, uj); zebra_vxlan_print_neigh_vni_dad(vty, zvrf, vni, uj);
return CMD_SUCCESS; return CMD_SUCCESS;
@ -2387,7 +2383,7 @@ DEFUN (show_pbr_iptable,
DEFPY (clear_evpn_dup_addr, DEFPY (clear_evpn_dup_addr,
clear_evpn_dup_addr_cmd, clear_evpn_dup_addr_cmd,
"clear evpn dup-addr vni <all$vni_all |" CMD_VNI_RANGE"$vni_val [mac M:A:C$mac_val | ip <A.B.C.D|X:X::X:X>]>", "clear evpn dup-addr vni <all$vni_all |" CMD_VNI_RANGE"$vni [mac M:A:C$mac_val | ip <A.B.C.D|X:X::X:X>]>",
CLEAR_STR CLEAR_STR
"EVPN\n" "EVPN\n"
"Duplicate address \n" "Duplicate address \n"
@ -2401,15 +2397,12 @@ DEFPY (clear_evpn_dup_addr,
"IPv6 address\n") "IPv6 address\n")
{ {
struct zebra_vrf *zvrf; struct zebra_vrf *zvrf;
vni_t vni = 0;
struct ipaddr host_ip = {.ipa_type = IPADDR_NONE }; struct ipaddr host_ip = {.ipa_type = IPADDR_NONE };
struct ethaddr mac_addr; struct ethaddr mac_addr;
int ret = CMD_SUCCESS; int ret = CMD_SUCCESS;
zvrf = zebra_vrf_get_evpn(); zvrf = zebra_vrf_get_evpn();
if (vni_val) { if (vni_str) {
vni = strtoul(vni_val, NULL, 10);
if (mac_val) { if (mac_val) {
prefix_str2mac(mac_val, &mac_addr); prefix_str2mac(mac_val, &mac_addr);
ret = zebra_vxlan_clear_dup_detect_vni_mac(vty, zvrf, ret = zebra_vxlan_clear_dup_detect_vni_mac(vty, zvrf,