From d23cea2d7c95b0d6683fbd80abcdb65e303816a4 Mon Sep 17 00:00:00 2001 From: Wataru Ishida Date: Thu, 10 Nov 2016 04:52:17 +0000 Subject: config: delete Equal() method for State structures we only use Equal() method for configuration structures Signed-off-by: Wataru Ishida --- tools/pyang_plugins/bgpyang2golang.py | 101 +++++++++++++++++----------------- 1 file changed, 51 insertions(+), 50 deletions(-) (limited to 'tools') diff --git a/tools/pyang_plugins/bgpyang2golang.py b/tools/pyang_plugins/bgpyang2golang.py index ff5900c0..9f131df0 100644 --- a/tools/pyang_plugins/bgpyang2golang.py +++ b/tools/pyang_plugins/bgpyang2golang.py @@ -280,59 +280,60 @@ def emit_class_def(ctx, yang_statement, struct_name, prefix): print >> o, '}' - print >> o, 'func (lhs *{0}) Equal(rhs *{0}) bool {{'.format(convert_to_golang(struct_name)) - print >> o, 'if lhs == nil || rhs == nil {' - print >> o, 'return false' - print >> o, '}' + if not struct_name.endswith('state'): + print >> o, 'func (lhs *{0}) Equal(rhs *{0}) bool {{'.format(convert_to_golang(struct_name)) + print >> o, 'if lhs == nil || rhs == nil {' + print >> o, 'return false' + print >> o, '}' - for val_name, type_name, typ, elem in equal_elems: - if val_name == 'State': - continue - if typ == EQUAL_TYPE_LEAF: - if type_name == '[]byte': - print >> o, 'if bytes.Compare(lhs.{0}, rhs.{0}) != 0 {{'.format(val_name) - else: - print >> o, 'if lhs.{0} != rhs.{0} {{'.format(val_name) - print >> o, 'return false' - print >> o, '}' - elif typ == EQUAL_TYPE_CONTAINER: - print >> o, 'if !lhs.{0}.Equal(&(rhs.{0})) {{'.format(val_name) - print >> o, 'return false' - print >> o, '}' - elif typ == EQUAL_TYPE_ARRAY: - print >> o, 'if len(lhs.{0}) != len(rhs.{0}) {{'.format(val_name) - print >> o, 'return false' - print >> o, '}' - print >> o, 'for idx, l := range lhs.{0} {{'.format(val_name) - if type_name == '[][]byte': - print >> o, 'if bytes.Compare(l, rhs.{0}[idx]) != 0 {{'.format(val_name) + for val_name, type_name, typ, elem in equal_elems: + if val_name == 'State': + continue + if typ == EQUAL_TYPE_LEAF: + if type_name == '[]byte': + print >> o, 'if bytes.Compare(lhs.{0}, rhs.{0}) != 0 {{'.format(val_name) + else: + print >> o, 'if lhs.{0} != rhs.{0} {{'.format(val_name) + print >> o, 'return false' + print >> o, '}' + elif typ == EQUAL_TYPE_CONTAINER: + print >> o, 'if !lhs.{0}.Equal(&(rhs.{0})) {{'.format(val_name) + print >> o, 'return false' + print >> o, '}' + elif typ == EQUAL_TYPE_ARRAY: + print >> o, 'if len(lhs.{0}) != len(rhs.{0}) {{'.format(val_name) + print >> o, 'return false' + print >> o, '}' + print >> o, 'for idx, l := range lhs.{0} {{'.format(val_name) + if type_name == '[][]byte': + print >> o, 'if bytes.Compare(l, rhs.{0}[idx]) != 0 {{'.format(val_name) + else: + print >> o, 'if l != rhs.{0}[idx] {{'.format(val_name) + print >> o, 'return false' + print >> o, '}' + print >> o, '}' + elif typ == EQUAL_TYPE_MAP: + print >> o, 'if len(lhs.{0}) != len(rhs.{0}) {{'.format(val_name) + print >> o, 'return false' + print >> o, '}' + print >> o, '{' + print >> o, 'lmap := make(map[string]*{0})'.format(type_name[2:]) + print >> o, 'for i, l := range lhs.{0} {{'.format(val_name) + print >> o, 'lmap[mapkey(i, string({0}))] = &lhs.{1}[i]'.format(' + '.join('l.{0}'.format(convert_to_golang(v)) for v in elem.split(' ')), val_name) + print >> o, '}' + print >> o, 'for i, r := range rhs.{0} {{'.format(val_name) + print >> o, 'if l, y := lmap[mapkey(i, string({0}))]; !y {{'.format('+'.join('r.{0}'.format(convert_to_golang(v)) for v in elem.split(' '))) + print >> o, 'return false' + print >> o, '} else if !r.Equal(l) {' + print >> o, 'return false' + print >> o, '}' + print >> o, '}' + print >> o, '}' else: - print >> o, 'if l != rhs.{0}[idx] {{'.format(val_name) - print >> o, 'return false' - print >> o, '}' - print >> o, '}' - elif typ == EQUAL_TYPE_MAP: - print >> o, 'if len(lhs.{0}) != len(rhs.{0}) {{'.format(val_name) - print >> o, 'return false' - print >> o, '}' - print >> o, '{' - print >> o, 'lmap := make(map[string]*{0})'.format(type_name[2:]) - print >> o, 'for i, l := range lhs.{0} {{'.format(val_name) - print >> o, 'lmap[mapkey(i, string({0}))] = &lhs.{1}[i]'.format(' + '.join('l.{0}'.format(convert_to_golang(v)) for v in elem.split(' ')), val_name) - print >> o, '}' - print >> o, 'for i, r := range rhs.{0} {{'.format(val_name) - print >> o, 'if l, y := lmap[mapkey(i, string({0}))]; !y {{'.format('+'.join('r.{0}'.format(convert_to_golang(v)) for v in elem.split(' '))) - print >> o, 'return false' - print >> o, '} else if !r.Equal(l) {' - print >> o, 'return false' - print >> o, '}' - print >> o, '}' - print >> o, '}' - else: - sys.stderr.write("invalid equal type %s", typ) + sys.stderr.write("invalid equal type %s", typ) - print >> o, 'return true' - print >> o, '}' + print >> o, 'return true' + print >> o, '}' print o.getvalue() -- cgit v1.2.3