This class manages the parsing of the C++ code. Please use RbGCCXML.parse and not this class directly
Methods
Public Class methods
[ show source ]
# File lib/rbgccxml/parser.rb, line 9
9: def initialize(config = {})
10: if config[:pregenerated]
11: @xml_file = config.delete[:pregenerated]
12: else
13: require 'gccxml'
14: @gccxml = GCCXML.new
15:
16: if includes = config.delete(:includes)
17: @gccxml.add_include includes
18: end
19:
20: if flags = config.delete(:cxxflags)
21: @gccxml.add_cxxflags flags
22: end
23:
24: validate_glob(config[:files])
25: end
26: end
Public Instance methods
Starts the parsing process. If the parser was configured with one or more header files, this includes:
- Creating a temp file for the resulting XML.
- Finding all the files to run through GCC-XML.
- If applicable (more than one header was specified), build another temp file and include the header files to ensure one and only one pass into GCC-XML.
- Build up our :: Namespace node and pass that back to the user for querying.
If the parser was configured for pregenerated GCC-XML output, we only have to perform step 4 above.
[ show source ]
# File lib/rbgccxml/parser.rb, line 40
40: def parse
41: if @gccxml
42: require 'tempfile'
43: @results_file = Tempfile.new("rbgccxml")
44: parse_file = nil
45:
46: if @files.length == 1
47: parse_file = @files[0]
48: else
49: # Otherwise we need to build up a single header file
50: # that #include's all of the files in the list, and
51: # parse that out instead
52: parse_file = build_header_for(@files)
53: end
54:
55: xml_file = @results_file.path
56: @gccxml.parse(parse_file, xml_file)
57: else
58: xml_file = @xml_file
59: end
60:
61: NodeCache.clear
62:
63: parser = SAXParser.new(xml_file)
64:
65: # Runs the SAX parser and returns the root level node
66: # which will be the Namespace node for "::"
67: parser.parse
68: end