File: Synopsis/Parsers/IDL/__init__.py 1
2
3
4
5
6
7
8"""Parser for IDL using omniidl for low-level parsing."""
9
10from Synopsis.Processor import *
11import omni
12import os, os.path, tempfile
13
14class Parser(Processor):
15
16 preprocess = Parameter(True, 'whether or not to preprocess the input')
17 cppflags = Parameter([], 'list of preprocessor flags such as -I or -D')
18 primary_file_only = Parameter(True, 'should only primary file be processed')
19 base_path = Parameter('', 'path prefix to strip off of the file names')
20
21 def process(self, ir, **kwds):
22
23 self.set_parameters(kwds)
24 if not self.input: raise MissingArgument('input')
25 self.ir = ir
26
27 if self.preprocess:
28
29 from Synopsis.Parsers import Cpp
30 cpp = Cpp.Parser(base_path = self.base_path,
31 language = 'IDL',
32 flags = self.cppflags,
33 emulate_compiler = None)
34
35 for file in self.input:
36
37 i_file = file
38 if self.preprocess:
39
40 if self.output:
41 i_file = os.path.splitext(self.output)[0] + '.i'
42 else:
43 i_file = os.path.join(tempfile.gettempdir(),
44 'synopsis-%s.i'%os.getpid())
45 self.ir = cpp.process(self.ir,
46 cpp_output = i_file,
47 input = [file],
48 primary_file_only = self.primary_file_only,
49 verbose = self.verbose,
50 debug = self.debug)
51
52
53 self.ir = omni.parse(self.ir, i_file,
54 os.path.abspath(file),
55 self.primary_file_only,
56 os.path.abspath(self.base_path) + os.sep,
57 self.verbose,
58 self.debug)
59
60 if self.preprocess: os.remove(i_file)
61
62 return self.output_and_return_ir()
63
64
Generated on Thu Apr 16 16:27:15 2009 by
synopsis (version devel)