summaryrefslogtreecommitdiffhomepage
path: root/tools/pyang_plugins/bgpyang2golang.py
diff options
context:
space:
mode:
authorWataru Ishida <ishida.wataru@lab.ntt.co.jp>2016-11-10 04:52:17 +0000
committerWataru Ishida <ishida.wataru@lab.ntt.co.jp>2016-11-14 02:12:50 +0000
commitd23cea2d7c95b0d6683fbd80abcdb65e303816a4 (patch)
tree6e48b0c8dfb6872ca097ae19f6ae0616f2bd9d02 /tools/pyang_plugins/bgpyang2golang.py
parentb77dc6aa54d0d2ebe4858ab688a10a44ef4cf773 (diff)
config: delete Equal() method for State structures
we only use Equal() method for configuration structures Signed-off-by: Wataru Ishida <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'tools/pyang_plugins/bgpyang2golang.py')
-rw-r--r--tools/pyang_plugins/bgpyang2golang.py101
1 files changed, 51 insertions, 50 deletions
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()