From 9b20aa3fd258f05d9afc33040986830b31a69aa7 Mon Sep 17 00:00:00 2001 From: "TOKITA, Hiroshi" Date: Tue, 21 Jul 2020 20:18:53 +0900 Subject: [PATCH] Store scripts for development --- libraries/OpenThread/dist/format_protptype.rb | 35 +++++++++++++++++++ .../OpenThread/dist/funclist_filter_api.rb | 15 ++++++++ libraries/OpenThread/dist/gen_class_decls.rb | 34 ++++++++++++++++++ .../dist/gen_funclist_from_doxyxml.rb | 25 +++++++++++++ libraries/OpenThread/dist/gen_impls.rb | 29 +++++++++++++++ 5 files changed, 138 insertions(+) create mode 100644 libraries/OpenThread/dist/format_protptype.rb create mode 100644 libraries/OpenThread/dist/funclist_filter_api.rb create mode 100644 libraries/OpenThread/dist/gen_class_decls.rb create mode 100644 libraries/OpenThread/dist/gen_funclist_from_doxyxml.rb create mode 100644 libraries/OpenThread/dist/gen_impls.rb diff --git a/libraries/OpenThread/dist/format_protptype.rb b/libraries/OpenThread/dist/format_protptype.rb new file mode 100644 index 00000000..28bd1df9 --- /dev/null +++ b/libraries/OpenThread/dist/format_protptype.rb @@ -0,0 +1,35 @@ +def classese_extract(line, classes) + classes.each do |clz| + if line =~ / ot#{clz}([^\(]*\()/ + line.sub!(/ ot#{clz}/, "\t#{clz}::") + return true + end + end + + return false +end + +def compact_space(line) + line.gsub!(/\ \ */," ") + line.gsub!(/ \*/,"* ") + line.gsub!(/const /,"const_") + line.gsub!(/static_/,"static_") + line.gsub!(/OT_TOOL_WEAK /,"OT_TOOL_WEAK_") +end + +readlines.each do |line| + compact_space(line) + ret = classese_extract(line, + ['Udp', 'Thread', 'Tasklets', 'SntpClient', 'Server', 'RandomNonCrypto', 'RandomCrypto', + 'Plat', 'NetworkTime', 'NetData', 'Ncp', 'Message', 'Logging', 'Link', 'Joiner', 'JamDetection', + 'Ip6', 'Instance', 'Icmp6', 'Heap', 'Entropy', 'DnsClient', 'Diag', 'Dataset', + 'Crypto', 'Cli', 'Commissioner', 'CoapSecure', 'Coap', 'ChildSupervision', 'ChannelMonitor', + 'ChannelManager', 'BorderRouter', 'BorderAgent', 'BackboneRouter']) + + if ret + STDOUT.print line + else + STDERR.print line + end + +end diff --git a/libraries/OpenThread/dist/funclist_filter_api.rb b/libraries/OpenThread/dist/funclist_filter_api.rb new file mode 100644 index 00000000..055f0bc2 --- /dev/null +++ b/libraries/OpenThread/dist/funclist_filter_api.rb @@ -0,0 +1,15 @@ + +headers = [ "backbone_router.h", "backbone_router_ftd.h", "border_agent.h", "border_router.h", "channel_manager.h", "channel_monitor.h", "child_supervision.h", "cli.h", "coap.h", "coap_secure.h", "commissioner.h", "config.h", "crypto.h", "dataset.h", "dataset_ftd.h", "diag.h", "dns.h", "entropy.h", "error.h", "heap.h", "icmp6.h", "instance.h", "ip6.h", "jam_detection.h", "joiner.h", "link.h", "link_raw.h", "logging.h", "message.h", "ncp.h", "netdata.h", "netdiag.h", "network_time.h", "ot_api_doc.h", "platform", "random_crypto.h", "random_noncrypto.h", "server.h", "sntp.h", "tasklet.h", "thread.h", "thread_ftd.h", "udp.h"] + +filtered = readlines.select do |line| + x = true + x = false if not headers.include?( line.split("\t")[0].split(/\//).last ) + x = false if not line =~ /\(/ + x = false if line =~ /::/ + x = false if line =~ /typedef/ + x +end + +filtered.sort.uniq.each do |line| + print line +end diff --git a/libraries/OpenThread/dist/gen_class_decls.rb b/libraries/OpenThread/dist/gen_class_decls.rb new file mode 100644 index 00000000..79c77572 --- /dev/null +++ b/libraries/OpenThread/dist/gen_class_decls.rb @@ -0,0 +1,34 @@ + +lines = readlines + +clzz = [] + +lines.each do |line| + line =~ /(\w*)::/ + clzz.append($1) +end + + +clzz.sort.uniq.each do |clz| + + print " class OT#{clz} {\n" + print " friend class OpenThreadClass;\n" + print " public:\n" + lines.each do |line| + if line =~ /#{clz}::/ + if line =~ /\(otInstance\* aInstance/ + line.gsub!(/#{clz}::/,"") + line.gsub!(/\(otInstance\* aInstance/,"(") + line.gsub!(/\(, /,"(") + print " #{line.strip.sub(/\t/, " ")}".gsub(/const_/, "const ") + print ";\n" + else + print " //#{line.strip.sub(/\t/, " ")}".gsub(/const_/, "const ") + print ";\n" + end + end + end + print " };\n" + print "\n" +end + diff --git a/libraries/OpenThread/dist/gen_funclist_from_doxyxml.rb b/libraries/OpenThread/dist/gen_funclist_from_doxyxml.rb new file mode 100644 index 00000000..7be97aec --- /dev/null +++ b/libraries/OpenThread/dist/gen_funclist_from_doxyxml.rb @@ -0,0 +1,25 @@ +require 'rexml/document' +require 'rexml/formatters/pretty' +require 'pp' +require 'stringio' + +formatter = REXML::Formatters::Pretty.new + +ARGV.each do |file| + xml = REXML::Document.new(File.new(file)) + + + REXML::XPath.each(xml, "/doxygen/compounddef/sectiondef/memberdef") do |e| +# print "---- #{file}\n" + if e.elements['definition'] + print e.elements['location'].attributes['file'] + print "\t" + print e.elements['definition'].text + print e.elements['argsstring'].text if e.elements['argsstring'] + print "\n" + end + end + output = StringIO.new +# formatter.write(xml, output) +# print output.string +end diff --git a/libraries/OpenThread/dist/gen_impls.rb b/libraries/OpenThread/dist/gen_impls.rb new file mode 100644 index 00000000..dfa17f80 --- /dev/null +++ b/libraries/OpenThread/dist/gen_impls.rb @@ -0,0 +1,29 @@ +print "#include \"OpenThread.h\"\n" +print "#include \n" +print "\n" + +readlines.each do |line| + line.gsub!(/\s[\w\*]*,/, ",") + line.gsub!(/\s[\w\*]*\)/, ")") + line.gsub!(/\s+\w+\[], /, "*, ") + line.gsub!(/::/,"\t") + line.gsub!(/\(/,"\t") + line.gsub!(/,/,"\t") + line.gsub!(/\)/,"") + line.gsub!(/static /, "") + data = line.chomp.split(/\t/).collect {|d| d.strip} + + if data[3] == "otInstance*" + cols = [(data.count-4).to_s, data[1], data[0], data[2] ].concat( data[4..-1].reject{|i|i=='void'} ) + if data[0] == "void" + print "OT_DECL_VFUNC(#{cols.join(', ')})\n".gsub(/const_/,"const ") + else + print "OT_DECL__FUNC(#{cols.join(', ')})\n".gsub(/const_/,"const ") + end + else + cols = [(data.count-3).to_s, data[1], data[2], data[0] ] + data[3..-1] + print "/*OT_DECL__FUNC(#{cols.join(', ')})*/\n".gsub(/const_/,"const ") + end + + +end