Class: MxxRu::Cpp::Analyzer::CppAnalyzer
- Inherits:
-
Object
- Object
- MxxRu::Cpp::Analyzer::CppAnalyzer
- Includes:
- Singleton
- Defined in:
- lib/mxx_ru/cpp/analyzer.rb
Constant Summary collapse
- @@include_regex =
Regexp.new( '^[ \t]*#[ \t]*include[ \t]*(<|")([^>"]+)(>|")' )
Instance Method Summary collapse
-
#add_include_paths(a_paths) ⇒ Object
Add paths to header files.
-
#add_sources(a_sources) ⇒ Object
Add files to view.
-
#analyze(a_encoding) ⇒ Object
Perform file analisys.
-
#get_depends_for(a_file_name) ⇒ Object
Get full dependencies list for a file.
-
#initialize ⇒ CppAnalyzer
constructor
A new instance of CppAnalyzer.
Constructor Details
#initialize ⇒ CppAnalyzer
Returns a new instance of CppAnalyzer.
69 70 71 72 73 74 |
# File 'lib/mxx_ru/cpp/analyzer.rb', line 69 def initialize # Key is a string, value - SourceFile. @sources = Hash.new # A list of folders to look header files in. @include_paths = Array.new end |
Instance Method Details
#add_include_paths(a_paths) ⇒ Object
Add paths to header files.
- a_paths
-
Should be Array of Strings.
89 90 91 92 93 94 95 |
# File 'lib/mxx_ru/cpp/analyzer.rb', line 89 def add_include_paths( a_paths ) a_paths.each { |p| if !@include_paths.include?( p ) @include_paths << p end } end |
#add_sources(a_sources) ⇒ Object
Add files to view.
- a_sources
-
Should be Array of Strings.
78 79 80 81 82 83 84 85 |
# File 'lib/mxx_ru/cpp/analyzer.rb', line 78 def add_sources( a_sources ) a_sources.each { |s| if !@sources.key?( s ) @sources[ s ] = SourceFile.new end } end |
#analyze(a_encoding) ⇒ Object
Perform file analisys.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/mxx_ru/cpp/analyzer.rb', line 98 def analyze ( a_encoding ) # Current list of keys should be taken to avoid # dynamic growth of file list. # Repeat iterations until source file list changes stop old_size = 0 files = @sources.keys while old_size != files.size files.each { |file_name| current = @sources[ file_name ] if !current.is_processed process_file( file_name, current, a_encoding ) end } old_size = files.size files = @sources.keys end end |
#get_depends_for(a_file_name) ⇒ Object
Get full dependencies list for a file. Returns Array of Strings.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/mxx_ru/cpp/analyzer.rb', line 119 def get_depends_for( a_file_name ) result_hash = Hash.new file_obj = @sources[ a_file_name ] if nil != file_obj to_review = file_obj.depends to_review_next = Hash.new while to_review.size != to_review_next.size to_review.each_key { |f| if !result_hash.key?( f ) result_hash[ f ] = nil to_review_next_obj = @sources[ f ] to_review_next_obj.depends.each_key { |k| to_review_next[ k ] = nil } end } to_review = to_review_next to_review_next = Hash.new end end return result_hash.keys end |