mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-09-05 09:49:59 +00:00
Don't assume that pointer-to-constant types have "const" removed.
1. Update treat_as table to include pointer-to-constant types. 2. Remove unnecessary casts in assignments and return statements. 3. Improve logic for adding "const" to types of function arguments. 4. It's no longer necessary to prepend "const" to function return type.
This commit is contained in:
@@ -22,6 +22,19 @@ class CMockGeneratorUtils
|
||||
@helpers = helpers
|
||||
end
|
||||
|
||||
def self.arg_type_with_const(arg)
|
||||
# Restore any "const" that was removed in header parsing
|
||||
if arg[:type].include?('*')
|
||||
arg[:const_ptr?] ? "#{arg[:type]} const" : arg[:type]
|
||||
else
|
||||
arg[:const?] ? "const #{arg[:type]}" : arg[:type]
|
||||
end
|
||||
end
|
||||
|
||||
def arg_type_with_const(arg)
|
||||
self.class.arg_type_with_const(arg)
|
||||
end
|
||||
|
||||
def code_verify_an_arg_expectation(function, arg)
|
||||
if (@arrays)
|
||||
case(@ptr_handling)
|
||||
@@ -58,7 +71,7 @@ class CMockGeneratorUtils
|
||||
|
||||
def code_assign_argument_quickly(dest, arg)
|
||||
if (arg[:ptr?] or @treat_as.include?(arg[:type]))
|
||||
" #{dest} = #{arg[:const?] ? "(#{arg[:type]})" : ''}#{arg[:name]};\n"
|
||||
" #{dest} = #{arg[:name]};\n"
|
||||
else
|
||||
" memcpy(&#{dest}, &#{arg[:name]}, sizeof(#{arg[:type]}));\n"
|
||||
end
|
||||
@@ -68,8 +81,8 @@ class CMockGeneratorUtils
|
||||
if (function[:args_string] != "void")
|
||||
if (@arrays)
|
||||
args_string = function[:args].map do |m|
|
||||
const_str = m[ :const? ] ? 'const ' : ''
|
||||
m[:ptr?] ? "#{const_str}#{m[:type]} #{m[:name]}, int #{m[:name]}_Depth" : "#{const_str}#{m[:type]} #{m[:name]}"
|
||||
type = arg_type_with_const(m)
|
||||
m[:ptr?] ? "#{type} #{m[:name]}, int #{m[:name]}_Depth" : "#{type} #{m[:name]}"
|
||||
end.join(', ')
|
||||
"void CMockExpectParameters_#{function[:name]}(CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance, #{args_string})\n{\n" +
|
||||
function[:args].inject("") { |all, arg| all + code_add_an_arg_expectation(arg, (arg[:ptr?] ? "#{arg[:name]}_Depth" : 1) ) } +
|
||||
|
||||
Reference in New Issue
Block a user