Exemplo n.º 1
0
    def add_expression(self, expression, debug):
        '''
		Add expression to data structure

		May have multiple keys to add for a given expression

		@param expression: KLL Expression (fully tokenized and parsed)
		@param debug:      Enable debug output
		'''
        # Lookup unique keys for expression
        keys = expression.unique_keys()

        # Add/Modify expressions in datastructure
        for key, uniq_expr in keys:
            # Check which operation we are trying to do, add or modify
            if debug[0]:
                if key in self.data.keys():
                    output = self.debug_output['mod'].format(key)
                else:
                    output = self.debug_output['add'].format(key)
                print(debug[1] and output or ansi_escape.sub('', output))

            # If key already exists, just update
            if key in self.data.keys():
                self.data[key].update(uniq_expr)
            else:
                self.data[key] = uniq_expr
Exemplo n.º 2
0
	def add_expression( self, expression, debug ):
		'''
		Add expression to data structure

		May have multiple keys to add for a given expression

		@param expression: KLL Expression (fully tokenized and parsed)
		@param debug:      Enable debug output
		'''
		# Lookup unique keys for expression
		keys = expression.unique_keys()

		# Add/Modify expressions in datastructure
		for key, uniq_expr in keys:
			# Check which operation we are trying to do, add or modify
			if debug[0]:
				if key in self.data.keys():
					output = self.debug_output['mod'].format( key )
				else:
					output = self.debug_output['add'].format( key )
				print( debug[1] and output or ansi_escape.sub( '', output ) )

			# If key already exists, just update
			if key in self.data.keys():
				self.data[ key ].update( uniq_expr )
			else:
				self.data[ key ] = uniq_expr
Exemplo n.º 3
0
    def add_expression(self, expression, debug):
        '''
        Add expression to data structure

        May have multiple keys to add for a given expression

        In the case of indexed variables, only replaced the specified index

        @param expression: KLL Expression (fully tokenized and parsed)
        @param debug:      Enable debug output
        '''
        # Lookup unique keys for expression
        keys = expression.unique_keys()

        # Add/Modify expressions in datastructure
        for key, uniq_expr in keys:
            # Check which operation we are trying to do, add or modify
            if debug[0]:
                if key in self.data.keys():
                    output = self.debug_output['mod'].format(key)
                else:
                    output = self.debug_output['add'].format(key)
                print(debug[1] and output or ansi_escape.sub('', output))

            # Check to see if we need to cap-off the array (a position parameter is given)
            if uniq_expr.type == 'Array' and uniq_expr.pos is not None:
                # Modify existing array
                if key in self.data.keys():
                    self.data[key].merge_array(uniq_expr)

                # Add new array
                else:
                    uniq_expr.merge_array()
                    self.data[key] = uniq_expr

            # Otherwise just add/replace expression
            else:
                self.data[key] = uniq_expr

            # Append to log
            self.merge_in_log_expression(key, uniq_expr, debug)
Exemplo n.º 4
0
	def add_expression( self, expression, debug ):
		'''
		Add expression to data structure

		May have multiple keys to add for a given expression

		In the case of indexed variables, only replaced the specified index

		@param expression: KLL Expression (fully tokenized and parsed)
		@param debug:      Enable debug output
		'''
		# Lookup unique keys for expression
		keys = expression.unique_keys()

		# Add/Modify expressions in datastructure
		for key, uniq_expr in keys:
			# Check which operation we are trying to do, add or modify
			if debug[0]:
				if key in self.data.keys():
					output = self.debug_output['mod'].format( key )
				else:
					output = self.debug_output['add'].format( key )
				print( debug[1] and output or ansi_escape.sub( '', output ) )

			# Check to see if we need to cap-off the array (a position parameter is given)
			if uniq_expr.type == 'Array' and uniq_expr.pos is not None:
				# Modify existing array
				if key in self.data.keys():
					self.data[ key ].merge_array( uniq_expr )

				# Add new array
				else:
					uniq_expr.merge_array()
					self.data[ key ] = uniq_expr

			# Otherwise just add/replace expression
			else:
				self.data[ key ] = uniq_expr
Exemplo n.º 5
0
    def add_expression(self, expression, debug):
        '''
		Add expression to data structure

		May have multiple keys to add for a given expression

		Map expressions insert into the datastructure according to their operator.

		+Operators+
		:   Add/Modify
		:+  Append
		:-  Remove
		::  Lazy Add/Modify

		i:  Add/Modify
		i:+ Append
		i:- Remove
		i:: Lazy Add/Modify

		The i or isolation operators are stored separately from the main ones.
		Each key is pre-pended with an i

		The :: or lazy operators act just like : operators, except that they will be ignore if the evaluation
		merge cannot resolve a ScanCode.

		@param expression: KLL Expression (fully tokenized and parsed)
		@param debug:      Enable debug output
		'''
        # Lookup unique keys for expression
        keys = expression.unique_keys()

        # Add/Modify expressions in datastructure
        for key, uniq_expr in keys:
            # Determine which the expression operator
            operator = expression.operator

            # Except for the : operator, all others have delayed action
            # Meaning, they change behaviour depending on how Contexts are merged
            # This means we can't simplify yet
            # In addition, :+ and :- are stackable, which means each key has a list of expressions
            # We append the operator to differentiate between the different types of delayed operations
            key = "{0}{1}".format(operator, key)

            # Determine if key exists already
            exists = key in self.data.keys()

            # Add/Modify
            if operator in [':', '::', 'i:', 'i::']:
                debug_tag = exists and 'mod' or 'add'

            # Append/Remove
            else:
                # Check to make sure we haven't already appended expression
                # Use the string representation to do the comparison (general purpose)
                if exists and "{0}".format(uniq_expr) in [
                        "{0}".format(elem) for elem in self.data[key]
                ]:
                    debug_tag = 'dup'

                # Append
                elif operator in [':+', 'i:+']:
                    debug_tag = 'app'

                # Remove
                else:
                    debug_tag = 'rem'

            # Debug output
            if debug[0]:
                output = self.debug_output[debug_tag].format(key)
                print(debug[1] and output or ansi_escape.sub('', output))

            # Don't append if a duplicate
            if debug_tag == 'dup':
                continue

            # Append, rather than replace
            if operator in [':+', ':-', 'i:+', 'i:-']:
                if exists:
                    self.data[key].append(uniq_expr)

                # Create initial list
                else:
                    self.data[key] = [uniq_expr]
            else:
                self.data[key] = [uniq_expr]
Exemplo n.º 6
0
	def add_expression( self, expression, debug ):
		'''
		Add expression to data structure

		May have multiple keys to add for a given expression

		Map expressions insert into the datastructure according to their operator.

		+Operators+
		:   Add/Modify
		:+  Append
		:-  Remove
		::  Lazy Add/Modify

		i:  Add/Modify
		i:+ Append
		i:- Remove
		i:: Lazy Add/Modify

		The i or isolation operators are stored separately from the main ones.
		Each key is pre-pended with an i

		The :: or lazy operators act just like : operators, except that they will be ignore if the evaluation
		merge cannot resolve a ScanCode.

		@param expression: KLL Expression (fully tokenized and parsed)
		@param debug:      Enable debug output
		'''
		# Lookup unique keys for expression
		keys = expression.unique_keys()

		# Add/Modify expressions in datastructure
		for key, uniq_expr in keys:
			# Determine which the expression operator
			operator = expression.operator

			# Except for the : operator, all others have delayed action
			# Meaning, they change behaviour depending on how Contexts are merged
			# This means we can't simplify yet
			# In addition, :+ and :- are stackable, which means each key has a list of expressions
			# We append the operator to differentiate between the different types of delayed operations
			key = "{0}{1}".format( operator, key )

			# Determine if key exists already
			exists = key in self.data.keys()

			# Add/Modify
			if operator in [':', '::', 'i:', 'i::']:
				debug_tag = exists and 'mod' or 'add'

			# Append/Remove
			else:
				# Check to make sure we haven't already appended expression
				# Use the string representation to do the comparison (general purpose)
				if exists and "{0}".format( uniq_expr ) in [ "{0}".format( elem ) for elem in self.data[ key ] ]:
					debug_tag = 'dup'

				# Append
				elif operator in [':+', 'i:+']:
					debug_tag = 'app'

				# Remove
				else:
					debug_tag = 'rem'

			# Debug output
			if debug[0]:
				output = self.debug_output[ debug_tag ].format( key )
				print( debug[1] and output or ansi_escape.sub( '', output ) )

			# Don't append if a duplicate
			if debug_tag == 'dup':
				continue

			# Append, rather than replace
			if operator in [':+', ':-', 'i:+', 'i:-']:
				if exists:
					self.data[ key ].append( uniq_expr )

				# Create initial list
				else:
					self.data[ key ] = [ uniq_expr ]
			else:
				self.data[ key ] = [ uniq_expr ]