summaryrefslogtreecommitdiffhomepage
path: root/tools/pyang_plugins
diff options
context:
space:
mode:
Diffstat (limited to 'tools/pyang_plugins')
-rw-r--r--tools/pyang_plugins/bgpyang2golang.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/tools/pyang_plugins/bgpyang2golang.py b/tools/pyang_plugins/bgpyang2golang.py
index 5c3819a7..af440407 100644
--- a/tools/pyang_plugins/bgpyang2golang.py
+++ b/tools/pyang_plugins/bgpyang2golang.py
@@ -95,6 +95,8 @@ def emit_go(ctx):
# emit
generate_header(ctx)
+ generate_common_functions(ctx)
+
for mod in ctx.module_deps:
if mod not in _module_excluded:
emit_typedef(ctx, mod)
@@ -310,10 +312,10 @@ def emit_class_def(ctx, yang_statement, struct_name, prefix):
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[string({0})] = &lhs.{1}[i]'.format(' + '.join('l.{0}'.format(convert_to_golang(v)) for v in elem.split(' ')), 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 _, r := range rhs.{0} {{'.format(val_name)
- print >> o, 'if l, y := lmap[string({0})]; !y {{'.format('+'.join('r.{0}'.format(convert_to_golang(v)) for v in elem.split(' ')))
+ 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'
@@ -690,6 +692,15 @@ def generate_header(ctx):
print ''
+def generate_common_functions(ctx):
+ print 'func mapkey(index int, name string) string {'
+ print 'if name != "" {'
+ print 'return name'
+ print '}'
+ print 'return fmt.Sprintf("%v", index)'
+ print '}'
+
+
def translate_type(key):
if key in _type_translation_map.keys():
return _type_translation_map[key]