#
#	File name: code_block.py
#
#	The code_block main class
#
#	This class contains all the information needed for defining a batch of source code
#	
#	Verion: 1.0
#	Date created: 	19/09/2018
#	Modified:		13/11/2018	-	Added nested
#
#	Author: Charalampos Marantos
#


#-----------------------------------------
class Code_block:

	# This is the constructor of the Code_block class
	# inputs:
	#	source_file: The name of the source code file that contains this batch of code
	#	type: the type of the statement (etc 'for', 'while', 'if')
	#	line_start: The line number that this starts
	#	line_end: The line number that this ends
	#	nested:	Check if this code block is nested in another
	def __init__(self, source_file, type, line_start, line_end):
		self.source_file = source_file
		self.type = type
		self.line_start = line_start
		self.line_end = line_end
		self.nested = 0

	def info(self):
		if self.nested == 0:
			print 'Source file: %s Type: %s, First line: %d, Last line: %d' % (self.source_file.split('/')[-1], self.type, self.line_start, self.line_end)
		else:
			print '=====> Source file: %s Type: %s, First line: %d, Last line: %d' % (self.source_file.split('/')[-1], self.type, self.line_start, self.line_end)

	# This method prints the source code part
	def print_code(self):
		f1 = open(self.source_file)
		for i, line in enumerate(f1):
			if i >= self.line_start-1 and i <= self.line_end-1:
				line = line.replace('\n','')
				print line
		f1.close()
