Sha256: 993571d0f0658c106abe10bea93a9f99ff1fb2bb3c356c4f0f6ac784e9495d63
Contents?: true
Size: 1.29 KB
Versions: 17
Compression:
Stored size: 1.29 KB
Contents
class PreprocessinatorExtractor constructor :file_wrapper # extract from cpp-processed file only content of file we care about def extract_base_file_from_preprocessed_expansion(filepath) contents = [] extract = false # 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 @file_wrapper.readlines(filepath).each do |line| if (extract) # flip to ignore mode if line begins with '#' except if it's a #pragma line if ((line =~ /^#/) and not (line =~ /#\s*pragma/)) extract = false # otherwise, extract the line else contents << line end end # enable extract mode if line matches preprocessor expression for our original file name extract = true if (line =~ /^#.*(\s|\/|\\|\")#{Regexp.escape(File.basename(filepath))}/) end return contents end end
Version data entries
17 entries across 17 versions & 1 rubygems