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:
mkarlesky
2009-06-03 21:30:20 +00:00
parent 82eb878cf6
commit 8683a6b3ff
2 changed files with 9 additions and 8 deletions
+6 -6
View File
@@ -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
+3 -2
View File
@@ -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