mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-10-08 09:57:25 +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)
|
def initialize(source, cfg)
|
||||||
@funcs = []
|
@funcs = []
|
||||||
@c_attributes = cfg.attributes
|
@c_attributes = cfg.attributes
|
||||||
@declaration_parse_matcher = /([\d\w\s\*\(\),]+??)\(([\d\w\s\*\(\),\.]*)\)/m
|
@declaration_parse_matcher = /([\d\w\s\*\(\),]+??)\(([\d\w\s\*\(\),\.]*)\)$/m
|
||||||
@braces_matcher = /(\{|\})/m
|
|
||||||
|
|
||||||
import_source(source)
|
import_source(source)
|
||||||
end
|
end
|
||||||
@@ -26,12 +25,12 @@ class CMockHeaderParser
|
|||||||
|
|
||||||
def import_source(source)
|
def import_source(source)
|
||||||
source.gsub!(/\s*\\\s*/m, ' ') # smush multiline into single line
|
source.gsub!(/\s*\\\s*/m, ' ') # smush multiline into single line
|
||||||
source.gsub!(/\/\/.*$/, '') # remove line comments
|
|
||||||
source.gsub!(/\/\*.*?\*\//m, '') # remove block comments
|
source.gsub!(/\/\*.*?\*\//m, '') # remove block comments
|
||||||
|
source.gsub!(/\/\/.*$/, '') # remove line comments
|
||||||
source.gsub!(/#.*/, '') # remove preprocessor statements
|
source.gsub!(/#.*/, '') # remove preprocessor statements
|
||||||
source.gsub!(/typedef.*/, '') # remove typedef 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
|
@src_lines.delete_if {|line| line.strip.length == 0} # remove blank lines
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
|||||||
expected =
|
expected =
|
||||||
[
|
[
|
||||||
" abcd",
|
" abcd",
|
||||||
"\n\nwho \n"
|
"who \n"
|
||||||
]
|
]
|
||||||
|
|
||||||
assert_equal(expected, @parser.src_lines)
|
assert_equal(expected, @parser.src_lines)
|
||||||
@@ -38,14 +38,14 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
|||||||
" abcd;\n" +
|
" abcd;\n" +
|
||||||
"/* hello;*/\n" +
|
"/* hello;*/\n" +
|
||||||
"who /* is you\n" +
|
"who /* is you\n" +
|
||||||
"whatdya say? */\n" +
|
"// embedded line comment */\n" +
|
||||||
"/* shizzzle*/"
|
"/* shizzzle*/"
|
||||||
@parser = CMockHeaderParser.new(source, @config)
|
@parser = CMockHeaderParser.new(source, @config)
|
||||||
|
|
||||||
expected =
|
expected =
|
||||||
[
|
[
|
||||||
" abcd",
|
" abcd",
|
||||||
"\n\nwho \n"
|
"who \n"
|
||||||
]
|
]
|
||||||
|
|
||||||
assert_equal(expected, @parser.src_lines)
|
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 FunkyChicken (\n uint la,\n int de,\n bool da);\n" +
|
||||||
"void\n shiz(void);\n" +
|
"void\n shiz(void);\n" +
|
||||||
"void tat();\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)
|
@parser = CMockHeaderParser.new(source, @config)
|
||||||
parsed_stuff = @parser.parse
|
parsed_stuff = @parser.parse
|
||||||
|
|||||||
Reference in New Issue
Block a user