mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-09-15 06:39:57 +00:00
made struct, union, and enum handling more robust to remove up to beginning of line containing them (helpful when 'extern' is only word left)
git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@128 bf332499-1b4d-0410-844d-d2d48d5cc64c
This commit is contained in:
@@ -48,12 +48,12 @@ class CMockHeaderParser
|
||||
|
||||
# unions, structs, and typedefs can all contain things (e.g. function pointers) that parse like function prototypes, so yank them;
|
||||
# enums might cause trouble or might not - pull 'em just to be safe
|
||||
source.gsub!(/enum[\w\s]*\{[^\}]+\}[\w\s]*;/m, '') # remove enum definitions (do before typedef removal because an enum can be typedef'd)
|
||||
source.gsub!(/union[\w\s]*\{[^\}]+\}[\w\s]*;/m, '') # remove union definitions (do before typedef removal because a union can be typedef'd)
|
||||
source.gsub!(/struct[^;\{\}\(\)]+;/m, '') # remove forward declared structs but leave prototypes having struct in types
|
||||
# (do before struct definitions so as to not mess up recognizing full struct definitions)
|
||||
source.gsub!(/struct[\w\s]*\{[^\}]+\}[\w\s]*;/m, '') # remove struct definitions (do before typedef removal because a struct can be typedef'd)
|
||||
source.gsub!(/typedef.*/, '') # remove typedef statements
|
||||
source.gsub!(/^[\w\s]*enum[\w\s]*\{[^\}]+\}[\w\s]*;/m, '') # remove enum definitions (do before typedef removal because an enum can be typedef'd)
|
||||
source.gsub!(/^[\w\s]*union[\w\s]*\{[^\}]+\}[\w\s]*;/m, '') # remove union definitions (do before typedef removal because a union can be typedef'd)
|
||||
source.gsub!(/^[\w\s]*struct[^;\{\}\(\)]+;/m, '') # remove forward declared structs but leave prototypes having struct in types
|
||||
# (do before struct definitions so as to not mess up recognizing full struct definitions)
|
||||
source.gsub!(/^[\w\s]*struct[\w\s]*\{[^\}]+\}[\w\s]*;/m, '') # remove struct definitions (do before typedef removal because a struct can be typedef'd)
|
||||
source.gsub!(/typedef.*/, '') # remove typedef statements
|
||||
|
||||
source.gsub!(/\s*=\s*['"a-zA-Z0-9_\.]+\s*/, '') # remove default value statements from argument lists
|
||||
|
||||
|
||||
@@ -144,7 +144,8 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
" unsigned int a;\n" +
|
||||
" signed long int b;\n" +
|
||||
"} Thing ;\n\n" +
|
||||
"struct ForwardDeclared_t TestDataType1;\n\n" +
|
||||
"extern struct ForwardDeclared_t TestDataType1;\n" +
|
||||
"void foo(void);\n" +
|
||||
"struct\n"+
|
||||
" MultilineForwardDeclared_t\n" +
|
||||
" TestDataType2;\n" +
|
||||
@@ -156,7 +157,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
"I want to live!!\n"
|
||||
@parser = CMockHeaderParser.new(@prototype_parser, source, @config, @test_name)
|
||||
|
||||
assert_equal(["struct THINGER foo(void)", "I want to live!!"], @parser.src_lines)
|
||||
assert_equal(["void foo(void)", "struct THINGER foo(void)", "I want to live!!"], @parser.src_lines)
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user