- added support for stripping out things like gcc __attributes__

- moved targets into a subdirectory called targets, like unity


git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@188 bf332499-1b4d-0410-844d-d2d48d5cc64c
This commit is contained in:
mvandervoord
2010-09-19 02:17:29 +00:00
parent ea78315418
commit cc9abe8e18
7 changed files with 50 additions and 2 deletions
+1
View File
@@ -13,6 +13,7 @@ class CMockConfig
:mock_prefix => 'Mock',
:plugins => [],
:includes => [],
:strippables => ['(?:__attribute__\s*\(+.*?\)+)'],
:attributes => ['__ramfunc', '__irq', '__fiq', 'register', 'extern'],
:enforce_strict_ordering => false,
:unity_helper => false,
+3 -1
View File
@@ -10,6 +10,7 @@ class CMockHeaderParser
def initialize(cfg)
@funcs = []
@c_strippables = cfg.strippables
@c_attributes = (['const'] + cfg.attributes).uniq
@treat_as_void = (['void'] + cfg.treat_as_void).uniq
@declaration_parse_matcher = /([\d\w\s\*\(\),\[\]]+??)\(([\d\w\s\*\(\),\.\[\]]*)\)$/m
@@ -71,9 +72,10 @@ class CMockHeaderParser
# forward declared structs are removed before struct definitions so they don't mess up real thing later. we leave structs keywords in function prototypes
source.gsub!(/^[\w\s]*struct[^;\{\}\(\)]+;/m, '') # remove forward declared structs
source.gsub!(/^[\w\s]*(enum|union|struct|typepdef)[\w\s]*\{[^\}]+\}[\w\s\*\,]*;/m, '') # remove struct, union, and enum definitions and typedefs with braces
source.gsub!(/(\W)(register|auto|static|restrict)(\W)/, '\1\3') # remove problem keywords
source.gsub!(/(\W)(?:register|auto|static|restrict)(\W)/, '\1\2') # remove problem keywords
source.gsub!(/\s*=\s*['"a-zA-Z0-9_\.]+\s*/, '') # remove default value statements from argument lists
source.gsub!(/^(?:[\w\s]*\W)?typedef\W.*/, '') # remove typedef statements
source.gsub!(/(^|\W+)(?:#{@c_strippables.join('|')})(?=$|\W+)/,'\1') unless @c_strippables.empty? # remove known attributes slated to be stripped
#scan for functions which return function pointers, because they are a pain
source.gsub!(/([\w\s\*]+)\(*\(\s*\*([\w\s\*]+)\s*\(([\w\s\*,]*)\)\)\s*\(([\w\s\*,]*)\)\)*/) do |m|
+1 -1
View File
@@ -21,7 +21,7 @@ module RakefileHelpers
def load_configuration(config_file)
$cfg_file = config_file
$cfg = YAML.load(File.read($cfg_file))
$cfg = YAML.load(File.read('targets/' + $cfg_file))
$colour_output = false unless $cfg['colour']
end
View File
+45
View File
@@ -14,6 +14,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
def setup
create_mocks :config
@test_name = 'test_file.h'
@config.expect.strippables.returns(['(?:__attribute__\s*\(+.*?\)+)'])
@config.expect.attributes.returns(['__ramfunc', 'funky_attrib'])
@config.expect.treat_as_void.returns(['MY_FUNKY_VOID'])
@config.expect.treat_as.returns({ "BANJOS" => "INT", "TUBAS" => "HEX16"} )
@@ -1121,5 +1122,49 @@ class CMockHeaderParserTest < Test::Unit::TestCase
}]
assert_equal(expected, @parser.parse("module", source)[:functions])
end
should "extract functions with strippable confusing junk like gcc attributes" do
source = "int LaverneAndShirley(int Lenny, int Squiggy) __attribute__((weak)) __attribute__ ((deprecated));\n"
expected = [{ :var_arg=>nil,
:return=> { :type => "int",
:name => 'cmock_to_return',
:ptr? => false,
:const? => false,
:str => "int cmock_to_return",
:void? => false
},
:name=>"LaverneAndShirley",
:modifier=>"",
:contains_ptr? => false,
:args=>[ {:type=>"int", :name=>"Lenny", :ptr? => false, :const? => false},
{:type=>"int", :name=>"Squiggy", :ptr? => false, :const? => false}
],
:args_string=>"int Lenny, int Squiggy",
:args_call=>"Lenny, Squiggy"
}]
assert_equal(expected, @parser.parse("module", source)[:functions])
end
should "extract functions with strippable confusing junk like gcc attributes with parenthesis" do
source = "int TheCosbyShow(int Cliff, int Claire) __attribute__((weak, alias (\"__f\"));\n"
expected = [{ :var_arg=>nil,
:return=> { :type => "int",
:name => 'cmock_to_return',
:ptr? => false,
:const? => false,
:str => "int cmock_to_return",
:void? => false
},
:name=>"TheCosbyShow",
:modifier=>"",
:contains_ptr? => false,
:args=>[ {:type=>"int", :name=>"Cliff", :ptr? => false, :const? => false},
{:type=>"int", :name=>"Claire", :ptr? => false, :const? => false}
],
:args_string=>"int Cliff, int Claire",
:args_call=>"Cliff, Claire"
}]
assert_equal(expected, @parser.parse("module", source)[:functions])
end
end