1
0
mirror of https://github.com/ThrowTheSwitch/CMock synced 2025-05-30 03:39:34 -04:00

Fix parsing of declarations like "int const* doStuff(void)".

The "const" in this case was not correctly stripped from the return type,
leading to a double const in generated typedefs, i.e.:

  typedef const int const* (* doStuff_CALLBACK)(int cmock_num_calls);

Add a test for these cases.
This commit is contained in:
John Lindgren 2017-09-01 12:30:11 -04:00
parent 42dab4836d
commit 55462aef40
2 changed files with 36 additions and 3 deletions

@ -228,8 +228,8 @@ class CMockHeaderParser
#process function attributes, return type, and name
descriptors = regex_match[1]
descriptors.gsub!(/\s+\*/,'*') #remove space to place asterisks with return type (where they belong)
descriptors.gsub!(/\*(\w)/,'* \1') #pull asterisks away from function name to place asterisks with return type (where they belong)
descriptors.gsub!(/(\w)\*/,'\1 *') #pull asterisks away from preceding word
descriptors.gsub!(/\*(\w)/,'* \1') #pull asterisks away from following word
descriptors = descriptors.split #array of all descriptor strings
#grab name
@ -249,7 +249,7 @@ class CMockHeaderParser
end
end
decl[:modifier] = decl[:modifier].join(' ')
rettype = rettype.join(' ')
rettype = rettype.join(' ').gsub(/\s+\*/,'*') #remove space before asterisks
rettype = 'void' if (@local_as_void.include?(rettype.strip))
decl[:return] = { :type => rettype,
:name => 'cmock_to_return',

@ -805,6 +805,39 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do
assert_equal(expected, @parser.parse("module", source)[:functions])
end
it "should properly handle const before or after return type" do
sources = [
"const int * PorkRoast(void);\n",
"int const * PorkRoast(void);\n",
"const int* PorkRoast(void);\n",
"int const* PorkRoast(void);\n",
"const int *PorkRoast(void);\n",
"int const *PorkRoast(void);\n"
]
expected = [{ :var_arg=>nil,
:name=>"PorkRoast",
:return=> { :type => "int*",
:name => 'cmock_to_return',
:ptr? => true,
:const? => true,
:const_ptr? => false,
:str => "int* cmock_to_return",
:void? => false
},
:modifier=>"const",
:contains_ptr? => false,
:args=>[],
:args_string=>"void",
:args_call=>""
}]
sources.each do |source|
assert_equal(expected, @parser.parse("module", source)[:functions])
end
end
it "should properly handle const applied after asterisk in return type (not legal C, but sometimes used)" do
source = "int * const PorkRoast(void);\n"