mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-09-21 01:27:27 +00:00
tightened up function recognition to ignore array declarations; reordered commentprocessing to take out block comments before line comments (in case line comments are embedded in block comments)
git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@87 bf332499-1b4d-0410-844d-d2d48d5cc64c
This commit is contained in:
@@ -5,8 +5,7 @@ class CMockHeaderParser
|
||||
def initialize(source, cfg)
|
||||
@funcs = []
|
||||
@c_attributes = cfg.attributes
|
||||
@declaration_parse_matcher = /([\d\w\s\*\(\),]+??)\(([\d\w\s\*\(\),\.]*)\)/m
|
||||
@braces_matcher = /(\{|\})/m
|
||||
@declaration_parse_matcher = /([\d\w\s\*\(\),]+??)\(([\d\w\s\*\(\),\.]*)\)$/m
|
||||
|
||||
import_source(source)
|
||||
end
|
||||
@@ -26,12 +25,12 @@ class CMockHeaderParser
|
||||
|
||||
def import_source(source)
|
||||
source.gsub!(/\s*\\\s*/m, ' ') # smush multiline into single line
|
||||
source.gsub!(/\/\/.*$/, '') # remove line comments
|
||||
source.gsub!(/\/\*.*?\*\//m, '') # remove block comments
|
||||
source.gsub!(/\/\/.*$/, '') # remove line comments
|
||||
source.gsub!(/#.*/, '') # remove preprocessor statements
|
||||
source.gsub!(/typedef.*/, '') # remove typedef statements
|
||||
|
||||
@src_lines = source.split(/;/)
|
||||
@src_lines = source.split(/\s*;\s*/)
|
||||
@src_lines.delete_if {|line| line.strip.length == 0} # remove blank lines
|
||||
end
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
expected =
|
||||
[
|
||||
" abcd",
|
||||
"\n\nwho \n"
|
||||
"who \n"
|
||||
]
|
||||
|
||||
assert_equal(expected, @parser.src_lines)
|
||||
@@ -38,14 +38,14 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
" abcd;\n" +
|
||||
"/* hello;*/\n" +
|
||||
"who /* is you\n" +
|
||||
"whatdya say? */\n" +
|
||||
"// embedded line comment */\n" +
|
||||
"/* shizzzle*/"
|
||||
@parser = CMockHeaderParser.new(source, @config)
|
||||
|
||||
expected =
|
||||
[
|
||||
" abcd",
|
||||
"\n\nwho \n"
|
||||
"who \n"
|
||||
]
|
||||
|
||||
assert_equal(expected, @parser.src_lines)
|
||||
@@ -121,7 +121,9 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
"void FunkyChicken (\n uint la,\n int de,\n bool da);\n" +
|
||||
"void\n shiz(void);\n" +
|
||||
"void tat();\n" +
|
||||
"#define get_foo() \\\n (Thing)foo())" # should extract no function declarations
|
||||
# following lines should yield no function declarations
|
||||
"#define get_foo() \\\n (Thing)foo())\n" +
|
||||
"array_type[((U8)10)];\n"
|
||||
|
||||
@parser = CMockHeaderParser.new(source, @config)
|
||||
parsed_stuff = @parser.parse
|
||||
|
||||
Reference in New Issue
Block a user