From 65b7a52b8ea800c61d69214f0d95125f3172cbb8 Mon Sep 17 00:00:00 2001 From: mvandervoord Date: Tue, 3 Jun 2008 02:31:50 +0000 Subject: [PATCH] Generates same code as previous version now (fixed some remaining quirks) git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@13 bf332499-1b4d-0410-844d-d2d48d5cc64c --- lib/cmock_generator.rb | 22 +++++++++++++++++----- lib/cmock_header_parser.rb | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/cmock_generator.rb b/lib/cmock_generator.rb index c97ba37..b55d38e 100644 --- a/lib/cmock_generator.rb +++ b/lib/cmock_generator.rb @@ -24,10 +24,22 @@ class CMockGenerator def create_mock(parsed_stuff) update_vars + create_shortcuts(parsed_stuff) create_mock_header_file(parsed_stuff) create_mock_source_file(parsed_stuff) end + def create_shortcuts(parsed_stuff) + parsed_stuff[:functions].each do |function| + function[:args_string_without_varargs] = function[:args_string].gsub(/\,[a-zA-Z0-9_\*\s]*\.\.\./,'') + if (function[:modifier].empty?) + function[:mod_and_rettype] = function[:rettype] + else + function[:mod_and_rettype] = function[:modifier] + ' ' + function[:rettype] + end + end + end + def update_vars @mock_name = "Mock" + @module_name @mock_header_name_dest = @mock_name + ".h" @@ -49,8 +61,6 @@ class CMockGenerator create_mock_header_header(header, @mock_header_name_dest.gsub(/\.h/, "_h").upcase) create_mock_header_externs(header, parsed_stuff) parsed_stuff[:functions].each do |function| - - function[:args_string_without_varargs] = function[:args_string].gsub(/\,[a-zA-Z0-9_\*\s]*\.\.\./,'') create_mock_header_function_declaration(header, function) end create_mock_header_footer(header) @@ -141,7 +151,9 @@ class CMockGenerator file << "#include \n" file << "#include \"unity.h\"\n" file << "#include \"Exception.h\"\n" if (@use_cexception) ####MSV : REMOVE ME - include_files.each {|include| file << "#include \"#{include}\"\n"} + + #(@includes + include_files).uniq.each {|include| file << "#include \"#{include}\"\n"} #### MSV This is what the comments said in original version, but it wasnt actually doing this + @includes.each {|include| file << "#include \"#{include}\"\n"} file << "#include \"#{@mock_header_name_dest}\"\n\n" end @@ -249,7 +261,7 @@ class CMockGenerator end def create_mock_argument_verifier(file, function) - file << "void AssertParameters_#{function[:name]}(#{function[:args_string]})\n{\n" + file << "void AssertParameters_#{function[:name]}(#{function[:args_string_without_varargs]})\n{\n" function[:args].each do |arg| type = arg[:type].sub(/const/, '').strip file << make_handle_expected(function, type, arg[:name]) @@ -268,7 +280,7 @@ class CMockGenerator # Create mock function file << "#{function[:attributes]} " if (!function[:attributes].nil? && function[:attributes].length > 0) - file << "#{function[:rettype]} #{function[:name]}(#{function[:args_string]})\n" + file << "#{function[:mod_and_rettype]} #{function[:name]}(#{function[:args_string]})\n" file << "{\n" # start ignore block diff --git a/lib/cmock_header_parser.rb b/lib/cmock_header_parser.rb index dba5aaa..199f5ef 100644 --- a/lib/cmock_header_parser.rb +++ b/lib/cmock_header_parser.rb @@ -4,12 +4,12 @@ class CMockHeaderParser def initialize(source, match_type=/\w+\**/, attributes=['static', '__monitor', '__ramfunc', '__irq', '__fiq']) source = source.gsub(/\/\/.*$/, '') #remove line comments - source = source.gsub(/\#define.*$/, '') #remove defines source = source.gsub(/\/\*.*?\*\//m, '') #remove block comments @lines = source.split(/(^\s*\#.*$) # Treat preprocessor directives as a logical line | (;|\{|\}) /x) # Match ;, {, and } as end of lines @lines.delete_if {|line| line =~ /\\\n/} #ignore lines that contain continuation lines @lines.delete_if {|line| line =~ /typedef/} #ignore lines that contain typedef statements + @lines.delete_if {|line| line =~ /\#define/} #remove defines @functions = nil @match_type = match_type