示例#1
0
	def run(self, baseast):
		debug_import ("***** Preprocessing %s" % (self.filename_list))
		data = self.preprocess_and_grab_data(self.filename_list)
		
		# Calculate the path to the parse tables.
		filename_for_parser = '_'.join(self.filename_list)
		try:
			#print '*** DATA'
			#print data
			#print 'END *** DATA'
			ast = cparse(baseast, filename_for_parser, data)
		except Exception, e:
			print "*** Exception encountered while processing %s" % (self.filename_list)
			file("inputparser.error.out", 'w').write(data)
			print "Preprocessed input written to inputparser.error.out"
			raise
示例#2
0
	def preprocess_and_grab_data(self, filename_list):
		# Make a tiny C file containing all the filenames as included.
		cpp_file = ['#include "%s"' % (filename) for filename in filename_list]
		cpp_file = '\n'.join(cpp_file) + '\n'
		# Ensure that the specified cpp actually exists
		full_cpp_path = usr_bin_which(self.cpp)
		if full_cpp_path is None:
			raise CPPNotFoundError("C pre-processor '%s' not found" % self.cpp)
		cpp_command_line = ' '.join ([self.cpp] + self.cpp_options \
			+ ['-I%s' % (incdir) for incdir in self.include_dirs]
			+ ['-D%s' % (define) for define in self.defines]
		)
		debug_import ("***** cpp: %s" % (cpp_command_line))
		child_out, child_in = popen2.popen2(cpp_command_line)
		child_in.write(cpp_file)
		child_in.close()
		return child_out.read()