@@ -59,12 +59,14 @@ def cleanup!
5959
6060 # Entry point for this parser
6161 # Parse `filename` out of the hash `files`
62- def parse_file ( orig_filename )
62+ def parse_file ( orig_filename , opts = { } )
6363
6464 includes = find_clang_includes + [ @tmpdir ]
6565
6666 # Override the path we want to filter by
6767 filename = File . join ( @tmpdir , orig_filename )
68+ debug_enable if opts [ :debug ]
69+ debug "parsing #{ filename } #{ @tmpdir } "
6870 args = includes . map { |path | "-I#{ path } " }
6971 args << '-ferror-limit=1'
7072
@@ -73,12 +75,13 @@ def parse_file(orig_filename)
7375 recs = [ ]
7476
7577 tu . cursor . visit_children do |cursor , parent |
76- #puts "visiting #{cursor.kind} - #{cursor.spelling}"
7778 location = cursor . location
7879 next :continue if location . file == nil
7980 next :continue unless location . file == filename
8081
81- #puts "for file #{location.file} #{cursor.kind} #{cursor.spelling} #{cursor.comment.kind} #{location.line}"
82+ loc = "%d:%d-%d:%d" % [ cursor . extent . start . line , cursor . extent . start . column , cursor . extent . end . line , cursor . extent . end . column ]
83+ debug "#{ cursor . location . file } :#{ loc } - visiting #{ cursor . kind } : #{ cursor . spelling } , comment is #{ cursor . comment . kind } "
84+
8285 #cursor.visit_children do |c|
8386 # puts " child #{c.kind}, #{c.spelling}, #{c.comment.kind}"
8487 # :continue
@@ -95,25 +98,38 @@ def parse_file(orig_filename)
9598 :tdef => nil ,
9699 }
97100
98- case cursor . kind
101+ extract = case cursor . kind
99102 when :cursor_function
100- #puts "have function"
101- rec . merge! extract_function ( cursor )
103+ debug "have function #{ cursor . spelling } "
104+ rec . update extract_function ( cursor )
102105 when :cursor_enum_decl
103- rec . merge! extract_enum ( cursor )
106+ debug "have enum #{ cursor . spelling } "
107+ rec . update extract_enum ( cursor )
104108 when :cursor_struct
105- #puts "raw struct"
106- rec . merge! extract_struct ( cursor )
109+ debug "have struct #{ cursor . spelling } "
110+ rec . update extract_struct ( cursor )
107111 when :cursor_typedef_decl
108- rec . merge! extract_typedef ( cursor )
112+ debug "have typedef #{ cursor . spelling } #{ cursor . underlying_type . spelling } "
113+ rec . update extract_typedef ( cursor )
109114 else
110115 raise "No idea how to deal with #{ cursor . kind } "
111116 end
112117
118+ rec . merge! extract
119+
113120 recs << rec
114121 :continue
115122 end
116123
124+ if debug_enabled
125+ puts "parse_file: parsed #{ recs . size } records for #{ filename } :"
126+ recs . each do |r |
127+ puts "\t #{ r } "
128+ end
129+ end
130+
131+ debug_restore
132+
117133 recs
118134 end
119135
@@ -187,15 +203,27 @@ def extract_function_args(cursor, cmt)
187203
188204 def extract_subject_desc ( comment )
189205 subject = comment . child . text
206+ debug "\t \t subject: #{ subject } "
190207 paras = comment . find_all { |cmt | cmt . kind == :comment_paragraph } . drop ( 1 ) . map { |p | p . text }
191208 desc = paras . join ( "\n \n " )
209+ debug "\t \t desc: #{ desc } "
192210 return subject , desc
193211 end
194212
195213 def extract_function ( cursor )
196214 comment = cursor . comment
197215
198- #puts "looking at function #{cursor.spelling}, #{cursor.display_name}"
216+ $buggy_functions = %w( )
217+ debug_set ( $buggy_functions. include? cursor . spelling )
218+ if debug_enabled
219+ puts "\t looking at function #{ cursor . spelling } , #{ cursor . display_name } "
220+ puts "\t comment: #{ comment } , #{ comment . kind } "
221+ cursor . visit_children do |cur , parent |
222+ puts "\t \t child: #{ cur . spelling } , #{ cur . kind } "
223+ :continue
224+ end
225+ end
226+
199227 cmt = extract_function_comment ( comment )
200228 args = extract_function_args ( cursor , cmt )
201229 #args = args.reject { |arg| arg[:comment].nil? }
@@ -220,6 +248,7 @@ def extract_function(cursor)
220248 decl = "#{ ret [ :type ] } #{ cursor . spelling } (#{ argline } )"
221249 body = "#{ decl } ;"
222250
251+ debug_restore
223252 #puts cursor.display_name
224253 # Return the format that docurium expects
225254 {
@@ -238,6 +267,7 @@ def extract_function(cursor)
238267
239268 def extract_function_comment ( comment )
240269 subject , desc = extract_subject_desc ( comment )
270+ debug "\t \t extract_function_comment: #{ comment } , #{ comment . kind } , #{ subject } , #{ desc } "
241271
242272 args = { }
243273 ( comment . find_all { |cmt | cmt . kind == :comment_param_command } ) . each do |param |
@@ -313,7 +343,7 @@ def extract_struct(cursor)
313343 :continue
314344 end
315345
316- #puts "struct value #{values}"
346+ debug " \t struct value #{ values } "
317347
318348 rec = {
319349 :type => :struct ,
0 commit comments