diff options
Diffstat (limited to 'tinyusb/test/vendor/ceedling/lib/ceedling/preprocessinator_extractor.rb')
-rwxr-xr-x | tinyusb/test/vendor/ceedling/lib/ceedling/preprocessinator_extractor.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tinyusb/test/vendor/ceedling/lib/ceedling/preprocessinator_extractor.rb b/tinyusb/test/vendor/ceedling/lib/ceedling/preprocessinator_extractor.rb new file mode 100755 index 00000000..49509a8b --- /dev/null +++ b/tinyusb/test/vendor/ceedling/lib/ceedling/preprocessinator_extractor.rb @@ -0,0 +1,30 @@ +class PreprocessinatorExtractor + def extract_base_file_from_preprocessed_expansion(filepath) + # preprocessing by way of toolchain preprocessor expands macros, eliminates + # comments, strips out #ifdef code, etc. however, it also expands in place + # each #include'd file. so, we must extract only the lines of the file + # that belong to the file originally preprocessed + + # iterate through all lines and alternate between extract and ignore modes + # all lines between a '#'line containing file name of our filepath and the + # next '#'line should be extracted + + base_name = File.basename(filepath) + not_pragma = /^#(?!pragma\b)/ # preprocessor directive that's not a #pragma + pattern = /^#.*(\s|\/|\\|\")#{Regexp.escape(base_name)}/ + found_file = false # have we found the file we care about? + + lines = [] + File.readlines(filepath).each do |line| + if found_file and not line =~ not_pragma + lines << line + else + found_file = false + end + + found_file = true if line =~ pattern + end + + return lines + end +end |