mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-09-12 21:29:57 +00:00
Deal with more complex array length expressions. (thanks @jlindgren90 !)
This commit is contained in:
@@ -16,7 +16,7 @@ class CMockHeaderParser
|
|||||||
@c_calling_conventions = cfg.c_calling_conventions.uniq
|
@c_calling_conventions = cfg.c_calling_conventions.uniq
|
||||||
@treat_as_array = cfg.treat_as_array
|
@treat_as_array = cfg.treat_as_array
|
||||||
@treat_as_void = (['void'] + cfg.treat_as_void).uniq
|
@treat_as_void = (['void'] + cfg.treat_as_void).uniq
|
||||||
@function_declaration_parse_base_match = '([\w\s\*\(\),\[\]]+??)\(([\w\s\*\(\),\.\[\]+-]*)\)'
|
@function_declaration_parse_base_match = '([\w\s\*\(\),\[\]]+??)\(([\w\s\*\(\),\.\[\]+\-\/]*)\)'
|
||||||
@declaration_parse_matcher = /#{@function_declaration_parse_base_match}$/m
|
@declaration_parse_matcher = /#{@function_declaration_parse_base_match}$/m
|
||||||
@standards = (['int','short','char','long','unsigned','signed'] + cfg.treat_as.keys).uniq
|
@standards = (['int','short','char','long','unsigned','signed'] + cfg.treat_as.keys).uniq
|
||||||
@array_size_name = cfg.array_size_name
|
@array_size_name = cfg.array_size_name
|
||||||
@@ -392,7 +392,7 @@ class CMockHeaderParser
|
|||||||
else
|
else
|
||||||
c = 0
|
c = 0
|
||||||
# magically turn brackets into asterisks, also match for parentheses that come from macros
|
# magically turn brackets into asterisks, also match for parentheses that come from macros
|
||||||
arg_list.gsub!(/(\w+)(?:\s*\[[\s\w\(\)+-]*\])+/, '*\1')
|
arg_list.gsub!(/(\w+)(?:\s*\[[^\[\]]*\])+/, '*\1')
|
||||||
# remove space to place asterisks with type (where they belong)
|
# remove space to place asterisks with type (where they belong)
|
||||||
arg_list.gsub!(/\s+\*/, '*')
|
arg_list.gsub!(/\s+\*/, '*')
|
||||||
# pull asterisks away from arg to place asterisks with type (where they belong)
|
# pull asterisks away from arg to place asterisks with type (where they belong)
|
||||||
|
|||||||
@@ -1291,7 +1291,7 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do
|
|||||||
|
|
||||||
it "handle arrays and treat them as pointers or strings" do
|
it "handle arrays and treat them as pointers or strings" do
|
||||||
source = 'void KeyOperated(CUSTOM_TYPE thing1[], int thing2 [ ], ' \
|
source = 'void KeyOperated(CUSTOM_TYPE thing1[], int thing2 [ ], ' \
|
||||||
'char thing3 [][2 ][ 3], int* thing4[4], u8 thing5[((u8)5)])'
|
'char thing3 [][2 ][ 3], int* thing4[4], u8 thing5[((u8)((5 + 5*2)/3))])'
|
||||||
expected_args = [
|
expected_args = [
|
||||||
{ type: 'CUSTOM_TYPE*', name: 'thing1', ptr?: true, const?: false, const_ptr?: false },
|
{ type: 'CUSTOM_TYPE*', name: 'thing1', ptr?: true, const?: false, const_ptr?: false },
|
||||||
{ type: 'int*', name: 'thing2', ptr?: true, const?: false, const_ptr?: false },
|
{ type: 'int*', name: 'thing2', ptr?: true, const?: false, const_ptr?: false },
|
||||||
|
|||||||
Reference in New Issue
Block a user