コード例 #1
0
ファイル: WittyFile.py プロジェクト: skerit/witty
	def parseStatements(self, workingStatements, scopeId = 1):

		wf.log(workingStatements, 'wittystats')

		statements = []

		for stat in workingStatements:
			statements.append(self.parseStatement(stat, scopeId))

		return statements
コード例 #2
0
ファイル: WittyFile.py プロジェクト: skerit/witty
	def __init__(self, project, fileName, core = False):

		# The project we're modifying
		self.project = project

		# The filename
		self.fileName = fileName
		self.name = fileName

		# Set the working string to empty
		self.working = ''

		# Create the statements
		self.splitStatements = []
		self.statements = []

		# Empty the blocks
		self.docblocks = []

		# Create the scopes
		self.scopes = []
		self.scopeDocBlocks = {}

		# First we add an empty scope because 0 == False and all
		self.createNewScope('global', False)
		self.createNewScope('root', 0)

		self.root = {}

		# See if the language is set already
		self.language = project.getFileLanguage(fileName)

		self.intel = None

		# Open the original file
		if not core:
			fileHandle = open(fileName, 'rU')

			# Read in the original file
			self.original = fileHandle.read()

			# The array
			self.fileArray = self.original.split('\n')

			# Close the file
			fileHandle.close()

			# Do we have to get the language of the file?
			self.detectLanguage()

			# Recursively split all the statements
			splitStatements = wf.splitStatements(self.original, 1)
			self.objStatements = self.parseStatements(splitStatements, 1)

			wf.log(self.scopes, self.language + 'scopes')
			wf.log({fileName: splitStatements, 'scopes': self.scopes})
			wf.log(self.objStatements, 'witty-' + self.language + '-objstatements')

			# Recursively go through all the statements in this file
			for stat in self.objStatements:
				WittyStatement(self, stat)

			for s in self.statements:
				wf.log(s, 'witty-' + self.language + '-statements')

		self.setIntel()
コード例 #3
0
ファイル: WittyProject.py プロジェクト: skerit/witty
	def postParse(self):

		# Reset everything
		# @todo: we could make it only reset the currently saved file,
		# but I haven't noticed any speed problems yet, so I'll do it later
		self.reset()
		info('Witty data has been reset, processing data ...')

		# Begin the real work
		for filename, wittyFile in self.files.items():

			pr('Processing ' + filename)

			# Prepare all the scopes
			# Here, we assume the file itself is also a scope
			# That's kind-of true for node.js, but false for javascript
			fileScope = self.root.addChildScope(wittyFile)
			fileScope.setName(filename)
			fileScope.makeFileScope(True)

			# Make a temporary map of the scopes inside this file
			scopeMap = {1: fileScope}

			# Loop over every scope
			for scope in wittyFile.scopes:

				# Skip the first 2 scopes
				if scope['id'] < 2:
					continue

				# Get this scope's parent scope
				parentScope = scopeMap[scope['parent']]
				
				newScope = parentScope.addChildScope()
				newScope.setName(scope['name'])
				newScope.setIdInFile(scope['id'])

				scopeMap[scope['id']] = newScope

			#for statement in wittyFile.statements:
			#	pr('Adding statement ' + statement.typeName + ' from line ' + str(statement.lineNr) + ' to scope ' + str(statement.scopeId))

			for statement in wittyFile.statements:
				# Get the statement's scope
				statementScope = scopeMap[statement.scopeId]
				statementScope.addVariable(statement)

			for scope in wittyFile.scopes:
				if scope['id'] == 0:
					targetScope = self.root
				else:
					targetScope = scopeMap[scope['id']]

				for name, varinfo in scope['variables'].items():
					targetScope.addVariable(False, varinfo)

				wf.log(scope, 'witty-' + self.language + '-simplescopes', True)

			for i, scope in scopeMap.items():
				wf.log(scope, 'witty-' + self.language + '-WTScopes')

			self.registerTypes()

		# for name, file in self.files.items():
		# 	wf.log('\n\nFILENAME: "' + name + '"', 'witty-final-variables')
		# 	wf.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n'*3, 'witty-final-variables')
			
		for scope in self.scopes:
			wf.log('\n\n>>\nScope: ' + str(scope.name), 'witty-' + self.language + '-final-variables')
			wf.log((('>>>'*20) + '\n')*2, 'witty-' + self.language + '-final-variables')
			wf.log(scope.variables, 'witty-' + self.language + '-final-variables', True)