From f3e8ae7487d633592d61c4574c1ce0df92fad501 Mon Sep 17 00:00:00 2001 From: mkarlesky Date: Wed, 30 Jun 2010 14:53:11 +0000 Subject: [PATCH] prettified debug output produced for function prototype parsing that fails git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@177 bf332499-1b4d-0410-844d-d2d48d5cc64c --- lib/cmock_header_parser.rb | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/cmock_header_parser.rb b/lib/cmock_header_parser.rb index ac30b54..cc3143d 100644 --- a/lib/cmock_header_parser.rb +++ b/lib/cmock_header_parser.rb @@ -236,14 +236,33 @@ class CMockHeaderParser if (decl[:return][:type].nil? or decl[:name].nil? or decl[:args].nil? or decl[:return][:type].empty? or decl[:name].empty?) raise "Failed Parsing Declaration Prototype!\n" + - " declaration: #{declaration}\n" + - " modifier: #{decl[:modifier]}\n" + - " return: #{decl[:return]}\n" + - " function: #{decl[:name]}\n" + - " args:#{decl[:args]}\n" + " declaration: '#{declaration}'\n" + + " modifier: '#{decl[:modifier]}'\n" + + " return: #{prototype_inspect_hash(decl[:return])}\n" + + " function: '#{decl[:name]}'\n" + + " args: #{prototype_inspect_array_of_hashes(decl[:args])}\n" end - + return decl end + def prototype_inspect_hash(hash) + pairs = [] + hash.each_pair { |name, value| pairs << ":#{name} => #{"'" if (value.class == String)}#{value}#{"'" if (value.class == String)}" } + return "{#{pairs.join(', ')}}" + end + + def prototype_inspect_array_of_hashes(array) + hashes = [] + array.each { |hash| hashes << prototype_inspect_hash(hash) } + case (array.size) + when 0 + return "[]" + when 1 + return "[#{hashes[0]}]" + else + return "[\n #{hashes.join("\n ")}\n ]\n" + end + end + end