mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-10-12 11:57:26 +00:00
Attempt to fix (once and for all) the way CMock handles const in arguments and return values.
This commit is contained in:
@@ -156,8 +156,9 @@ class CMockHeaderParser
|
|||||||
end
|
end
|
||||||
|
|
||||||
def divine_const(arg)
|
def divine_const(arg)
|
||||||
return false if /const[ *]/.match(arg).nil? # check for const
|
return false if !(/(?:^|\s|\*)const(?:\*|\s|$)/ =~ arg) # check for const as part of a larger word
|
||||||
return false if /\*/.match(arg) and /const[^*]*\*/.match(arg).nil? # check const comes before * indicating const data
|
return true if (/const(?:\w|\s)*\*/ =~ arg) # check const comes before * indicating const data
|
||||||
|
return false if (/\*\s*const/ =~ arg) # check const comes after * indicating const ptr
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -220,6 +221,7 @@ class CMockHeaderParser
|
|||||||
#build attribute and return type strings
|
#build attribute and return type strings
|
||||||
decl[:modifier] = []
|
decl[:modifier] = []
|
||||||
rettype = []
|
rettype = []
|
||||||
|
full_retval = descriptors[0..-2].join(' ')
|
||||||
descriptors[0..-2].each do |word|
|
descriptors[0..-2].each do |word|
|
||||||
if @c_attributes.include?(word)
|
if @c_attributes.include?(word)
|
||||||
decl[:modifier] << word
|
decl[:modifier] << word
|
||||||
@@ -235,7 +237,7 @@ class CMockHeaderParser
|
|||||||
decl[:return] = { :type => rettype,
|
decl[:return] = { :type => rettype,
|
||||||
:name => 'cmock_to_return',
|
:name => 'cmock_to_return',
|
||||||
:ptr? => divine_ptr(rettype),
|
:ptr? => divine_ptr(rettype),
|
||||||
:const? => decl[:modifier].split(/\s/).include?('const'),
|
:const? => divine_const(full_retval),
|
||||||
:str => "#{rettype} cmock_to_return",
|
:str => "#{rettype} cmock_to_return",
|
||||||
:void? => (rettype == 'void')
|
:void? => (rettype == 'void')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -781,6 +781,28 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do
|
|||||||
assert_equal(expected, @parser.parse("module", source)[:functions])
|
assert_equal(expected, @parser.parse("module", source)[:functions])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should properly handle const applied after asterisk in return type" do
|
||||||
|
|
||||||
|
source = "int * const PorkRoast(void);\n"
|
||||||
|
|
||||||
|
expected = [{ :var_arg=>nil,
|
||||||
|
:name=>"PorkRoast",
|
||||||
|
:return=> { :type => "int*",
|
||||||
|
:name => 'cmock_to_return',
|
||||||
|
:ptr? => true,
|
||||||
|
:const? => false,
|
||||||
|
:str => "int* cmock_to_return",
|
||||||
|
:void? => false
|
||||||
|
},
|
||||||
|
:modifier=>"const",
|
||||||
|
:contains_ptr? => false,
|
||||||
|
:args=>[],
|
||||||
|
:args_string=>"void",
|
||||||
|
:args_call=>""
|
||||||
|
}]
|
||||||
|
assert_equal(expected, @parser.parse("module", source)[:functions])
|
||||||
|
end
|
||||||
|
|
||||||
it "properly detect typedef'd variants of void and use those" do
|
it "properly detect typedef'd variants of void and use those" do
|
||||||
|
|
||||||
source = "typedef (void) FUNKY_VOID_T;\n" +
|
source = "typedef (void) FUNKY_VOID_T;\n" +
|
||||||
|
|||||||
Reference in New Issue
Block a user