Remove internal regex for inline functions and make them fully user-defined

- We set the defaults but the user is free to add his own.
  This will overwrite our defaults but they will be added to the
  documentation as reference for the user
This commit is contained in:
laurens
2019-11-13 13:33:16 +01:00
parent 8a7c45c20b
commit 9bc3f25281
3 changed files with 16 additions and 21 deletions
+9 -1
View File
@@ -40,7 +40,15 @@ class CMockConfig
:orig_header_include_fmt => "#include \"%s\"",
:array_size_type => [],
:array_size_name => 'size|len',
:inline_function_patterns => [],
# Format to look for inline functions.
# This is a combination of "static" and "inline" keywords ("static inline", "inline static", "inline", "static")
# There are several possibilities:
# - sometimes they appear together, sometimes individually,
# - The keywords can appear before or after the return type (this is a compiler warning but people do weird stuff),
# so we check for word boundaries when searching for them
# - We first remove "static inline" combinations and boil down to single inline or static statements
:inline_function_patterns => ['(static\s+inline|inline\s+static)\s*', '(\bstatic\b|\binline\b)\s*'], # Last part (\s*) is just to remove whitespaces (only to prettify the output)
}
def initialize(options=nil)
+6 -19
View File
@@ -103,28 +103,15 @@ class CMockHeaderParser
# Transform inline functions to regular functions in the source by the user
# +source+:: String containing the source to be processed
def transform_inline_functions(source)
# Format to look for inline functions.
# This is a combination of "static" and "inline" keywords ("static inline", "inline static", "inline", "static")
# There are several possibilities:
# - sometimes they appear together, sometimes individually,
# - The keywords can appear before or after the return type (this is a compiler warning but people do weird stuff),
# so we check for word boundaries when searching for them
# - We first remove "static inline" combinations and boil down to single inline or static statements
inline_function_regex_formats = [
/(static\s+inline|inline\s+static)\s*/, # Last part (\s*) is just to remove whitespaces (only to prettify the output)
/(\bstatic\b|\binline\b)\s*/, # Last part (\s*) is just to remove whitespaces (only to prettify the output)
]
user_regex_formats = []
inline_function_regex_formats = []
square_bracket_pair_regex_format = /\{[^\{\}]*\}/ # Regex to match one whole block enclosed by two square brackets
@inline_function_patterns.each { |user_format_string|
user_regex = Regexp.new(Regexp.quote(user_format_string))
# Convert user provided string patterns to regex
@inline_function_patterns.each do |user_format_string|
user_regex = Regexp.new(user_format_string)
cleanup_spaces_after_user_regex = /\s*/
user_regex_formats << Regexp.new((user_regex.source) + cleanup_spaces_after_user_regex.source) # Convert user provided string to regex pattern
}
# We first parse the user regex to avoid removing basic inline keywords that the user regex depends upon
inline_function_regex_formats = user_regex_formats + inline_function_regex_formats
inline_function_regex_formats << Regexp.new(user_regex.source + cleanup_spaces_after_user_regex.source)
end
# let's clean up the encoding in case they've done anything weird with the characters we might find
source = source.force_encoding("ISO-8859-1").encode("utf-8", :replace => nil)
+1 -1
View File
@@ -24,7 +24,7 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do
@config.expect :verbosity, 1
@config.expect :treat_externs, :exclude
@config.expect :treat_inlines, :exclude
@config.expect :inline_function_patterns, ['static __inline__ __attribute__ ((always_inline))', 'static __inline__']
@config.expect :inline_function_patterns, ['static __inline__ __attribute__ \(\(always_inline\)\)', 'static __inline__', '(static\s+inline|inline\s+static)\s*', '(\bstatic\b|\binline\b)\s*']
@config.expect :array_size_type, ['int', 'size_t']
@config.expect :array_size_name, 'size|len'