Exemple #1
0
def create_special_MIG(arch_info, ast):
	poly_list =(
	("MACH_MSG_TYPE_PORT_RECEIVE",	'32', 'MACH_MSG_TYPE_PORT_internal',	'MACH_MSG_TYPE_POLYMORPHIC'),
	("MACH_MSG_TYPE_PORT_SEND",		'32', 'MACH_MSG_TYPE_PORT_internal',	'MACH_MSG_TYPE_POLYMORPHIC'),
	("MACH_MSG_TYPE_PORT_SEND_ONCE", '32', 'MACH_MSG_TYPE_SEND_internal',	'MACH_MSG_TYPE_POLYMORPHIC'),
	("MACH_MSG_TYPE_COPY_SEND",		'32', 'MACH_MSG_TYPE_SEND_internal',	'MACH_MSG_TYPE_PORT_SEND'),
	("MACH_MSG_TYPE_MAKE_SEND",		'32', 'MACH_MSG_TYPE_SEND_internal',	'MACH_MSG_TYPE_PORT_SEND'),
	("MACH_MSG_TYPE_MOVE_SEND",		'32', 'MACH_MSG_TYPE_SEND_internal',	'MACH_MSG_TYPE_PORT_SEND'),
	("MACH_MSG_TYPE_MAKE_SEND_ONCE", '32', 'MACH_MSG_TYPE_SEND_internal',	'MACH_MSG_TYPE_PORT_SEND_ONCE'),
	("MACH_MSG_TYPE_MOVE_SEND_ONCE", '32', 'MACH_MSG_TYPE_SEND_internal',	'MACH_MSG_TYPE_PORT_SEND_ONCE'),
	("MACH_MSG_TYPE_MOVE_RECEIVE",	'32', 'MACH_MSG_TYPE_RECEIVE_internal', 'MACH_MSG_TYPE_PORT_RECEIVE')
	)

	type_list = ast.children
	for name, size, sender, receiver in poly_list:
		newType = TypeNode(ast, None, source_file = '<builtin>')
		newType.leaf = name
		newType.add_attribute('meta_type', 'polymorphic')
		info = Node(newType, 'info')
		newType.add_child(info)
		index = [element.leaf for element in type_list].index(sender)
		info.add_attribute('sender_type',type_list[index] )
		index = [element.leaf for element in type_list].index(receiver)
		info.add_attribute('receiver_type',type_list[index] )
		type_list.append(newType)
		ast.add_child(newType)
Exemple #2
0
    def _rename_params(self, ast):
        if self.get_is_pagefault(ast):
            new_ast = ast.copy()

            new_ast.children = []

            for child in ast.children:
                if child.name != 'parameter':
                    new_ast.children.append(child.copy())
                elif child.the('target').the('type').leaf != 'fpage':
                    new_ast.children.append(child.copy())
                else:
                    # Create a new magical node with the correct name...
                    fp_param = Node(new_ast, 'parameter', leaf=child.leaf)
                    fp_param.add_attribute(
                        'direction', child.get_single_attribute('direction'))
                    target = Node(fp_param, 'target')
                    target.add_child(
                        infogripper.getTypenode('idl4_mapitem', ast))
                    fp_param.add_child(target)

                    new_ast.children.append(fp_param)

            return new_ast
        else:
            return ast
Exemple #3
0
	def component(self,ast, pt, decorators):
		assert not decorators
		component = Node(ast, 'component', None, source = pt)
		component.leaf = pt.the('identifier').leaf
		dcl = pt.the('component_dcl')
		if  dcl != None:
			inh = dcl.the('component_inheritance_spec')
			if inh != None:
				inher_node = Node(component, 'inherits', leaf = self.scoped_name(interface, scope_name), source = dcl)
				component.add_child(inher_ndoe)
				inher_node.add_child(infogripper.find_scope(interface, inher))
			
			sup = dcl.the('supported_interface_spec')
			if sup != None:
				supnode = Node(component, 'support', source = sup)
				name_list = []
				for name in sup['scoped_name']:
					newname = self.scoped_name(name)
					name_list.append(newname)
					target_list.append(getTypenode(newname, component))
				supnode.leaf = name_list
				supnode.add_attribute('target_scope_list', target_list)
				component.add_child(supnode)
			
			bod = dcl.the('component_body')
			if bod != None:
				exp_list = self.component_body(component, bod)
				if exp_list != []:
					component.add_children(exp_list)

		ast.add_child(component)
Exemple #4
0
	def type_id_dcl(self, ast, pt, decorators):
		assert not decorators
		type_id = Node(ast, name='typeid', source = pt)
		type_id.leaf = self.scoped_name(ast, pt.the('scoped_name'))
		type_id.add_attribute('value', pt.the('string_literal').leaf)
		ast.add_child(type_id)
		self._dupes_check(type_id)
Exemple #5
0
	def param_dcl(self, ast, pt):
		"""
		Param decls look like constant declarations: refer to "const_dcl".
		1.	parameter blah  (3)
			+- meta_type = ['param']
		    +- direction = ['in']
			+- indirection = ['*']
			+- target = [<Node object type:unsigned int>]
		"""
		param_ast = Node(ast, 'parameter', None, source = pt)

		# Add direction
		param_ast.add_attribute('direction', pt.leaf)

		for child in pt.children:
			if child.type == 'param_type_spec':
				#param_ast.add_attribute('target',self.param_type_spec(ast, child))
				target_type, is_new_type = self._get_target_type(param_ast, child,
						defining_scope = param_ast)
				param_ast.add_child(target_type)
			elif child.type == 'allow_indirection':
				indirection_list = [child.leaf]
				for indirection in child['allow_indirection']:
					indirection_list.append(indirection.leaf)
				param_ast.add_attribute('indirection', indirection_list)
			elif child.type == 'simple_declarator':
				param_ast.leaf = child.leaf
			else:
				param_ast.add_child(UnkownNode(None, child, source = pt))

		# Check we're not passing raw void parameters.
		if not self.is_valid_parameter_spec(param_ast):
			raise InvalidTypeUsageError(target_type.the('type').leaf, child)
		return param_ast
Exemple #6
0
def make_literal_ast(scope_ast, pt):
	assert pt.name == 'literal'
	child_pt = pt.children[0]

	ast = Node(None, "expression")

	ast_type_name = TYPENAME_MAP.get(child_pt.name)
	if ast_type_name is None:
		raise Error("Unknown literal type %s" % child_pt.name)
	
	target_type = infogripper.getNode(ast_type_name, scope_ast, 'type')
	if target_type is None:
		raise Error("Couldn't find type %s in AST" % (ast_type_name))
	
	if target_type.has_attribute('smallest') and target_type.has_attribute('largest'):
		# FIXME: Shouldn't be doing this.
		ast_type_name = smallest_type_hack(get_python_value(child_pt.leaf))
		target_type = infogripper.getNode(ast_type_name, scope_ast, 'type')

	# FIXME: Use of eval is evil
	ast.add_attribute('value', get_python_value(child_pt.leaf))

	# Remember the original name for later.
	ast.add_attribute('display_name', child_pt.name)

	ast.add_child(target_type)

	return ast
Exemple #7
0
def make_scoped_name_ast(scope_ast, pt):
	assert pt.name == 'scoped_name'

	ast = Node(None, "expression", leaf = 'scoped_name')

	# Sanity check
	for child in pt.children:
		assert child.name in ('scope_operator', 'identifier')

	# Build the name.
	scoped_name_list = [child.leaf for child in pt.children]
	value = ''.join(scoped_name_list)

	# Check that it's valid
	target_asts = infogripper.getAllNodes(value, scope_ast, None)
	if len(target_asts) > 1:
		raise error.AmbiguousScopedNameError(value, scope_ast, target_asts)
	elif len(target_asts) == 0:
		raise error.NameNotFoundError(value, pt)

	target_wrapper = Node(scope_ast, 'target', [target_asts[0]])
	ast.add_child(target_wrapper)
	ast.add_attribute('value', value)

	return ast
Exemple #8
0
	def value_inheritance_spec(self, ast, pt):
		if pt.children[0].type == 'value_value_inheritance_spec':
			inh_node = Node(ast, 'inheritance', None, source = pt.children[0])
			inh_node.add_attribute('relation', 'value')
			if pt.children[0].the('value_value_inheritance_spec') != None:
				inh_node.add_attribute('modifier', pt.children[0].the('value_value_inheritance_spec').leaf)
			name_list = []
			target_list = []
			for name in pt.the('value_value_inheritance_spec')['value_name']:
				newname = self.scoped_name(name.the('scoped_name'))
				name_list.append(newname)
				target_list.append(getTypenode(newname, ast))
			inh_node.leaf = name_list
			inh_node.add_attribute('target_scope_list',target_list)
			return inh_node
		elif pt.children[0].type == 'value_interface_inheritance_spec':
			inh_node = Node(ast, 'inheritance', None, source = pt.children[0])
			inh_node.add_attribute('relation', 'interface')
			name_list = []
			target_list = []
			for name in pt.the('value_interface_inheritance_spec')['interface_name']:
				newname = self.scoped_name(name.the('scoped_name'))
				name_list.append(newname)
				target_list.append(getTypenode(newname, ast))
			inh_node.add_attribute('target_scope_list',target_list)
			inh_node.leaf = name_list
			return inh_node
		else:
			return UnknownNode(None, pt, source = pt)
Exemple #9
0
	def op_dcl(self,ast, pt):
		fcn = Node(ast, 'function', None, source = pt)
		ast.add_child(fcn)
		for child in pt.children:
			if child.type == 'decorator':
				#print child
				dec_children = self.decorator_elements(fcn, child)
				dec_node = Node(fcn, 'decorator', dec_children, source = child)
				fcn.add_child(dec_node)
			elif child.type == 'op_attribute':
				fcn.add_attribute('attribute', child.leaf)
			elif child.type == 'op_type_spec':
				#if child.leaf == 'void':
				#	target = getTypenode('void', fcn)
				#print 'trying to get typenode for: %s' %(child.the('param_type_spec'))
				#else:
				typenode = TypeNode(fcn, source = pt)
				typenode.name = 'return_type'
				fcn.add_child(typenode)
				target, new_type = self._get_target_type(typenode, child.the('param_type_spec'),
						defining_scope = typenode)
				# Add the target explicitly.
				typenode.add_child(target)
				if child.the('allow_indirection'):
					typenode.add_attribute('indirection', child.the('allow_indirection').leaf)
				elif child.the('ref_indirection'):
					typenode.add_attribute('indirection', ['*'])
			elif child.type == 'op_dcl':
				fcn.leaf = child.leaf
			elif child.type == 'parameter_dcls':
				fcn.add_children(self.parameter_dcls(fcn, child))
			elif child.type == 'raises_expr':
				raises = Node(fcn, name='raises', source = child)
				leaflist = []
				target_list = []
				for node in child.the('scoped_name_list').children:
					if node.type == 'scoped_name':
						newname = self.scoped_name(node)
						leaflist.append(newname)
						target_list.append(getTypenode(newname, fcn))
				raises.leaf = leaflist
				raises.add_attribute('target_scope_list', target_list)
				fcn.add_child(raises)
			elif child.type == 'context_expr':
				context = Node(fcn, name='context', source = child)
				leaflist = []
				for node in child.the('string_literal_list').children:
					if node.type == 'string_literal':
						leaflist.append(node.leaf)
				context.leaf = leaflist
				fcn.add_child(context)
			else:
				fcn = UnknownNode(None, child, source = child)

		# Add it and include its symbol.
		self._dupes_check(fcn)
Exemple #10
0
def make_identifier_ast(pt):
	assert pt.name == 'identifier'

	ast = Node(None, "expression")
	child_ast = Node(ast, "identifier")
	ast.add_child(child_ast)

	child_ast.add_attribute('value', pt.leaf)

	return ast
Exemple #11
0
	def init_param_decls(self, ast, pt):
		decl_list = []
		for child in pt['init_param_decl']:
			param_node = Node(ast, 'parameter', None, source = child)
			type_ast, new_type = self._get_target_type(param_node, child.the('param_type_spec'),
					defining_scope = param_node)
			param_node.leaf = child.the('simple_declarator').leaf
			if child.the('init_param_attribute') != None:
				param_node.add_attribute('attribute', child.the('init_param_attribute').leaf)
			decl_list.append(param_node)
		return decl_list
Exemple #12
0
	def string_type(self, ast, pt, wstring = False):
		typenode = Node(ast, 'type', source = pt)
		if wstring:
			target = Node(typenode, 'customised', [infogripper.getTypenode('wstring', ast)])
		else:
			target = Node(typenode, 'customised', [infogripper.getTypenode('string', ast)])
		typenode.add_child(target)
		pos_const_node = pt.the('positive_int_const')
		if pos_const_node != None:
			expr = self.getExpression(ast, pos_const_node.the('const_exp'))
			typenode.add_attribute('max_length', expr.leaf)
		# This is a new, anonymous type.
		return typenode
Exemple #13
0
def get_scoped_name(scope_ast, pt, ast_gen):
    the_name = pt.get_single_attribute('value')

    scoped_name = Node(scope_ast, 'expression', leaf='scoped_name', source=pt)
    scoped_name.add_attribute('value', the_name)

    # Try to find a target.
    type_ast = getNode(the_name, scope_ast)
    # It's not the end of the world if we don't find a target.
    if type_ast:
        target_ast = Node(scoped_name, 'target', [type_ast])
        scoped_name.add_child(target_ast)

    return scoped_name
Exemple #14
0
	def attr_raises_expr(self, pt):
		raisesnode = Node(None, None, source = pt)
		for child in pt.children:
			if child.type == 'get_excep_expr':
				raisesnode.leaf = 'getraises'
				exception_list = self.exception_list(child.the('exception_list'))
				raisesnode.add_attribute('exception_list', exception_list)
			elif child.type == 'set_excep_expr':
				raisesnode.leaf = 'setraises'
				exception_list = self.exception_list(child.the('exception_list'))
				raisesnode.add_attribute('exception_list', exception_list)
			else:
				raisesnode = UnknownNode(None, child, source = pt)
		return raisesnode
Exemple #15
0
def get_scoped_name(scope_ast, pt, ast_gen):
    the_name = pt.get_single_attribute("value")

    scoped_name = Node(scope_ast, "expression", leaf="scoped_name", source=pt)
    scoped_name.add_attribute("value", the_name)

    # Try to find a target.
    type_ast = getNode(the_name, scope_ast)
    # It's not the end of the world if we don't find a target.
    if type_ast:
        target_ast = Node(scoped_name, "target", [type_ast])
        scoped_name.add_child(target_ast)

    return scoped_name
Exemple #16
0
	def value_abs_dcl(self, at, pt):
		node = Node(ast, 'valuetype', None, source = pt)
		node.add_attribute('modifier', 'abstract')
		for child in pt.children:
			if child.type == 'identifier':
				node.leaf = child.leaf
			elif child.type == 'value_abs_full_dcl':
				val_inh_node = self.value_inheritance_spec(node, self, child.the('value_inheritance_spec'))
				export_node = Node(val_inh_node, 'export', source = child)
				for exp_child in child[export]:
					self.export(export_node, exp_child)
				if export_node.children:
					val_inh_node.add_child(export_node)
			else:
				node.add_child(UnknownNode(None, child, source = pt))
		return node
Exemple #17
0
	def attr_dcl(self, ast, pt):
		attr_node = Node(ast, 'attribute', None, source = pt)
		ast.add_child(attr_node)

		type_node, new_type = self._get_target_type(attr_node, pt.children[0].the('param_type_spec'),
				defining_scope = attr_node)
		if pt.children[0].type == 'readonly_attr_spec':
			attr_node.add_attribute('mode', 'readonly')
			attr_node.add_child(self.attr_declarator(attr_node, pt.children[0].the('readonly_attr_declarator')))
			#self.attr_declarator(pt.children[0].the('readonly_attr_declarator'), type_node)
		elif pt.children[0].type == 'attr_spec':
			attr_node.add_attribute('mode', 'readwrite')
			attr_node.add_child(self.attr_declarator(attr_node, pt.children[0].the('attr_declarator')))
			#attr_node.add_child(self.attr_declarator(pt.children[0].the('attr_declarator')), type_node)
		else:
			attr_node = UnknownNode(None, pt.children[0], source = pt.children[0])
Exemple #18
0
	def finder_dcl(self, ast, pt):
		fac_node = Node(ast, None, name = 'finder', source = pt)
		fac_node.leaf = pt.the('identifier').leaf
		fac_node.add_children(self.init_param_decls(fac_node, pt.the('init_param_decls')))
		if pt.the('raises_expr') != None:
			raises = Node(fac_node, name='raises', source = pt)
			leaflist = []
			target_list = []
			for node in child.the('scoped_name_list').children:
				if node.type == 'scoped_name':
					newname = self.scoped_name(node)
					target_list = getTypenode(newname, ast)
					leaflist.append(newname)
			raises.leaf = leaflist
			raises.add_attribute('target_scope_list', target_list)
			fac_node.add_child(raises)
		return fac_node
Exemple #19
0
	def home_dcl(self, ast, pt, decorators):
		assert not decorators
		homenode = Node(ast, 'home', source = pt)
		#
		#	HEADER
		#
		homeheader = pt.the('home_header')
		homenode.leaf = homeheader.the('identifier').leaf
		if homeheader.the('home_inheritance_spec') != None:
			inhnode = Node(homenode, 'inheritance', source = homeheader)
			inhnode.leaf = self.scoped_name(homeheader.the('home_inheritance_spec').the('scoped_name'))
			inhnode.add_attribute
			homenode.add_child(inhnode)
		if homeheader.the('supported_interface_spec') != None:
			supnode = Node(homenode, 'support', source = homeheader)
			namelist = []
			for name in homeheader.the('supported_interface_spec')['scoped_name']:
				namelist.append(self.scoped_name(name))
			supnode.leaf = namelist
			homenode.add_child(supnode)
		mannode = Node(homenode, None, name='manages', source = pt)
		mannode.leaf = self.scoped_name(homheader.the('scoped_name'))
		mannode.add_attribute('target_scope', infogripper.find_scope(mannode.leaf))
		if homeheader.the('primary_key_spec') != None:
			mannode.add_attribute('primarykey', infogripper.find_scope(self.scoped_name(homenode, homeheader.the('primary_key_spec').the('scoped_name'))))
		homenode.add_child(mannode)
		#
		#	BODY
		#
		homebody = pt.the('home_body')
		for child in homebody.children:
			if child.children[0].type == 'export':
				self.export(homenode, child.children[0])
			elif child.children[0].type == 'factory_dcl':
				homenbode.add_child(self.factory_dcl(homenode, child.children[0]))
			elif child.children[0].type == 'finder_dcl':
				homenode.add_child(self.finder_dcl(homenode, child.children[0]))
			else:
				homenode.add_child(UnknownNode(None, child.children[0]), source = pt)
		
		ast.add_child(homenode)
Exemple #20
0
def get_literal(scope_ast, pt, ast_gen):
    """
	Translate a constant that looks like this:
	expression literal
	 int 0   (or "float 3.1415", etc)

	to:
	expression literal
	 (value) = <constant>
	 type (backref)
	"""
    # Extract type
    type_list = [pt.child().name]
    type_ast = ast_gen.get_type_from_list(scope_ast, type_list)

    value = pt.child().leaf

    node = Node(scope_ast, "expression", leaf="literal", source=pt)
    node.add_attribute("value", value)
    node.add_child(type_ast)

    return node
Exemple #21
0
def get_literal(scope_ast, pt, ast_gen):
    """
	Translate a constant that looks like this:
	expression literal
	 int 0   (or "float 3.1415", etc)

	to:
	expression literal
	 (value) = <constant>
	 type (backref)
	"""
    # Extract type
    type_list = [pt.child().name]
    type_ast = ast_gen.get_type_from_list(scope_ast, type_list)

    value = pt.child().leaf

    node = Node(scope_ast, 'expression', leaf='literal', source=pt)
    node.add_attribute('value', value)
    node.add_child(type_ast)

    return node
Exemple #22
0
	def const_dcl(self, ast, pt, decorators):
		"""
		Create a constant declaration.
		They look like this:
		1.	type_instance blah  (3)
			+- meta_type = ['const']
		2.	+- value = [1]
		3.	 info  (4)
			 +- target = [<Node object type:unsigned int>]
		"""
		assert not decorators
		# 1: Set up the base.
		const_node = Node(ast, 'type_instance', source = pt)
		const_node.add_attribute('meta_type', 'const')
		const_node.leaf = pt.the('identifier').leaf

		# 2: Now store the target of the decl.
		target_type, is_new_type = self._get_target_type(const_node, pt.the('const_type'),
				defining_scope = const_node)
		# ... NB if we have a new type it will be added here already as a "type" node.
		# But we always add as a "target" node too.
		const_node.add_child(target_type)

		# 3: Add the expression result wrapped in a declarator (for c++ compat.)
		declarator_wrapper = Node(const_node, 'declarator', source = pt)
		const_node.add_child(declarator_wrapper)

		expr = self.getExpression(const_node, pt.the('const_exp'))
		declarator_wrapper.add_child(expr)

		# 4: Ensure the type of the expression can be coerced to the type of the target.
		if not infogripper.can_coerce_expr(expr, target_type.the('type')):
			raise CannotReconcileTypesError(expr.the('type').leaf,
					target_type.the('type').leaf,
					const_node)

		# 5: Hurrah!
		ast.add_child(const_node)
		self._dupes_check(const_node)
Exemple #23
0
	def event_def(self, ast, pt, decorators):
		assert not decorators
		event_node = Node(ast, 'event', source = pt)
		child = pt.children[0]
		if child.type == 'event_abs':
			event_node.add_attribute('modifier', 'abstract')
			event_node.leaf = child.the('event_abs_dcl').the('event_header').the('identifier').leaf
			if child.the('event_abs_dcl') != None:
				event_node.add_child(self.value_inheritance_spec(child.the('event_abs_dcl').the('value_inheritance_spec')))
				export_node = Node(event_node, 'export', exp_list, source = child)
				for exp_child in child.the('event_abs_dcl')[export]:
					self.export(export_node, exp_child)
				if export_node.children:
					event_node.add_child(export_node)
		elif child.type == 'event_custom':
			event_node.add_attribute('modifier', 'custom')
			event_node.leaf = child.the('event_custom').the('event_header').the('identifier').leaf
			if child.the('event_elem_dcl') != None:
				event_node.add_child(self.value_inheritance_spec(child.the('event_elem_dcl').the('value_inheritance_spec')))
				export_node = Node(event_node, 'export', exp_list, source = child)
				for exp_child in child.the('event_elem_dcl')[export]:
					self.export(export_node, exp_child)
				if export_node.children:
					event_node.add_child(export_node)
		elif child.type == 'event_dcl':
			event_node.leaf = child.the('event_dcl').the('event_header').the('identifier').leaf
			if child.the('event_elem_dcl') != None:
				event_node.add_child(self.value_inheritance_spec(child.the('event_elem_dcl').the('value_inheritance_spec')))
				export_node = Node(event_node, 'export', exp_list, source = child)
				for exp_child in child.the('event_elem_dcl')[export]:
					self.export(export_node, exp_child)
				if export_node.children:
					event_node.add_child(export_node)
		
		else:
			event_node = UnknownNode(None, child, source = pt)

		ast.add_child(event_node)
Exemple #24
0
	def value_def(self, ast, pt, decorators):
		assert not decorators

		if pt.children[0].type == 'value_dcl':
			ast.add_child(self.value_dcl(ast, pt.children[0]))
		elif pt.children[0].type == 'value_abs_dcl':
			ast.add_child(self.value_abs_dcl(ast, pt.children[0]))
		elif pt.children[0].type == 'value_box_dcl':
			val_node = Node(ast, 'valuetype', None, source = pt.children[0])
			val_node.leaf = pt.children[0].the('identifier').leaf
			val_node.add_child(self.type_spec(val_node, pt.children[0].the('type_spec')))
			ast.add_child(val_node)
		elif pt.children[0].type == 'value_custom_dcl':
			val_node = self.value_dcl(ast, pt.children[0].the('value_dcl'))
			val_node.add_attribute('modifier', 'custom')
			ast.add_child(val_node)
		elif pt.children[0].type == 'value_forward_dcl':
			val_node = Node(ast, 'valuetype', None, source = pt.children[0])
			val_node.leaf = val_node.leaf = pt.children[0].the('identifier').leaf
			val_node.add_attribute('modifier', 'forward')
			ast.add_child(val_node)
		else:
			ast.add_child(UnknownNode(None, pt.children[0].type, source = pt.children[0]))
Exemple #25
0
def create_special_MIG(arch_info, ast):
    poly_list = (("MACH_MSG_TYPE_PORT_RECEIVE", '32',
                  'MACH_MSG_TYPE_PORT_internal', 'MACH_MSG_TYPE_POLYMORPHIC'),
                 ("MACH_MSG_TYPE_PORT_SEND", '32',
                  'MACH_MSG_TYPE_PORT_internal', 'MACH_MSG_TYPE_POLYMORPHIC'),
                 ("MACH_MSG_TYPE_PORT_SEND_ONCE", '32',
                  'MACH_MSG_TYPE_SEND_internal', 'MACH_MSG_TYPE_POLYMORPHIC'),
                 ("MACH_MSG_TYPE_COPY_SEND", '32',
                  'MACH_MSG_TYPE_SEND_internal', 'MACH_MSG_TYPE_PORT_SEND'),
                 ("MACH_MSG_TYPE_MAKE_SEND", '32',
                  'MACH_MSG_TYPE_SEND_internal',
                  'MACH_MSG_TYPE_PORT_SEND'), ("MACH_MSG_TYPE_MOVE_SEND", '32',
                                               'MACH_MSG_TYPE_SEND_internal',
                                               'MACH_MSG_TYPE_PORT_SEND'),
                 ("MACH_MSG_TYPE_MAKE_SEND_ONCE", '32',
                  'MACH_MSG_TYPE_SEND_internal',
                  'MACH_MSG_TYPE_PORT_SEND_ONCE'),
                 ("MACH_MSG_TYPE_MOVE_SEND_ONCE", '32',
                  'MACH_MSG_TYPE_SEND_internal',
                  'MACH_MSG_TYPE_PORT_SEND_ONCE'),
                 ("MACH_MSG_TYPE_MOVE_RECEIVE", '32',
                  'MACH_MSG_TYPE_RECEIVE_internal',
                  'MACH_MSG_TYPE_PORT_RECEIVE'))

    type_list = ast.children
    for name, size, sender, receiver in poly_list:
        newType = TypeNode(ast, None, source_file='<builtin>')
        newType.leaf = name
        newType.add_attribute('meta_type', 'polymorphic')
        info = Node(newType, 'info')
        newType.add_child(info)
        index = [element.leaf for element in type_list].index(sender)
        info.add_attribute('sender_type', type_list[index])
        index = [element.leaf for element in type_list].index(receiver)
        info.add_attribute('receiver_type', type_list[index])
        type_list.append(newType)
        ast.add_child(newType)
Exemple #26
0
def pop_and_add(scope_ast, oper, operands):
	# Pop and create new tree
	node = Node(None, 'expression')
	node.leaf = OPER_NAMES[oper]
	for count in range(get_arity(oper)):
		node.add_front(operands.pop())
	
	# Work out the type for the resulting expression.
	type_ast = get_expr_type(node.children[0])
	for new_type_expr in node.children[1:]:
		new_type_ast = get_expr_type(new_type_expr)
		if infogripper.can_coerce_expr(new_type_expr, type_ast):
			type_ast = new_type_ast
		else:
			raise error.CannotReconcileTypesError(new_type_ast.leaf, type_ast.leaf, scope_ast)
	
	# Store a value, if we can. This over-rides the above discovered type.
	# FIXME: This is a cheesy hack.
	if type_ast.has_attribute('smallest') and type_ast.has_attribute('largest'):
		# It's a scalar type, we can play with it.
		if len(node.children) > 1:
			result = oper.join(['(%s)' % (child.attribute('value')) for child in node.children])
		else:
			# FIXME: Even cheesier
			result = "%s%s" % (PYTHON_UNARY[oper] , node.children[0].attribute('value'))
		try:
			result = eval(result)
			node.add_attribute('value', result)
		except:
			pass

		smallest_type_name = smallest_type_hack(result)
		if smallest_type_name:
			type_ast = infogripper.getNode(smallest_type_name, scope_ast, 'type')
	
	node.add_child(type_ast)
	operands.append(node)
Exemple #27
0
	def _rename_params(self, ast):
		if self.get_is_pagefault(ast):
			new_ast = ast.copy()

			new_ast.children = []

			for child in ast.children:
				if child.name != 'parameter':
					new_ast.children.append(child.copy())
				elif child.the('target').the('type').leaf != 'fpage':
					new_ast.children.append(child.copy())
				else:
					# Create a new magical node with the correct name...
					fp_param = Node(new_ast, 'parameter', leaf = child.leaf)
					fp_param.add_attribute('direction', child.get_single_attribute('direction'))
					target = Node(fp_param, 'target')
					target.add_child(infogripper.getTypenode('idl4_mapitem', ast))
					fp_param.add_child(target)

					new_ast.children.append(fp_param)

			return new_ast
		else:
			return ast
Exemple #28
0
	def interf(self,ast,  pt, decorators):
		# ... create the type
		interface = Node(ast, 'type', source = pt)
		interface.add_attribute('meta_type', 'interface')
		# ... add modifiers
		if pt.leaf == 'abstract' or pt.leaf == 'local':
			interface.add_attribute('modifier', pt.leaf)
		# ... set interface name
		interface.leaf = pt.the('identifier').leaf

		# If the interface already exists in incomplete form, use that instead.
		old_interfaces = infogripper.getAllNodes(interface.leaf, ast, 'type')
		if old_interfaces:
			# Found a previous declaration; use that.
			assert len(old_interfaces) == 1
			interface = old_interfaces[0]
		else:
			# Okay, it doesn't exist already: add it.
			ast.add_child(interface)

		# While we're building it, add the "incomplete" attribute.
		interface.add_attribute('incomplete', True)
		is_incomplete = True
		for child in pt.children:
			if child.type == 'interface_dcl':
				is_incomplete = False
				#print child
				if child.the('interface_header') != None:
					scope_list = child.the('interface_header').the('interface_inheritance_spec').the('scoped_name_list')
					for scope_name in scope_list['scoped_name']:
						inher_node = Node(interface, 'inherits', leaf = self.scoped_name(scope_name), source = child)
						inher_node.add_child(infogripper.find_scope(interface, inher_node.leaf))

						# Ensure we're not inheriting from the same class twice.
						self.check_not_inherited(interface, inher_node.children[0], error_infonode = scope_name)
						interface.add_child(inher_node)
						
						
				if child.the('interface_body') != None:
					for export_child in child.the('interface_body').children:
						self.export(interface, export_child)

		# Remove "incomplete" if the interface was fully-defined above.
		if not is_incomplete:
			interface.del_attributes('incomplete')

		interface.add_children(decorators)

		self._dupes_check(interface)
Exemple #29
0
def create_special_C(arch_info, ast):
	type_list = ast.children
	struct_t = TypeNode(ast, source_file = '<builtin>')
	struct_t.leaf = 'idl4_server_environment'
	struct_t.add_attribute('meta_type','struct')
	members = Node(struct_t, 'members')
	typeinst = Node(struct_t, 'type_instance')
	typeinst.leaf = '_action'
	index = [element.leaf for element in type_list].index('signed int')
	typeinst.add_attribute('target_type',type_list[index] )
	members.add_child(typeinst)
	typeinst = Node(struct_t, 'type_instance')
	typeinst.leaf = '_data'
	index = [element.leaf for element in type_list].index('void')
	typeinst.add_attribute('target_type',type_list[index] )
	members.add_child(typeinst)

	# Create IDL4 scope for giggles.
	idl4 = Node(ast, 'type', leaf = 'idl4', source_file = '<builtin>')
	idl4.add_attribute('meta_type', 'private')
	pagefault = Node(idl4, 'type', leaf = 'pagefault')
	idl4.add_child(pagefault)
	ast.add_child(idl4)
	
	#FIXME: CORBA-C Type-Hack!!!
	aliases = ( ('Object', 'signed int'),
			('any', 'signed int'),
			('ValueBase', 'signed int'),
			('Word', 'signed int')
	)

	# Create aliases to C nodes.
	for alias, name in aliases:
		newType = TypeNode(ast, source_file = '<builtin>')
		newType.leaf = alias
		newType.add_attribute('meta_type', 'alias') 
		type_list = ast.children
		index = [element.leaf for element in type_list].index(name)
		target_node = Node(newType, 'target')
		target_node.add_child(type_list[index])
		newType.add_child(target_node)

		ast.add_child(newType)
	
	# Explicitly add the IDL4 mapitem struct, yuck yuck
	mapitem = _make_struct(ast, 'idl4_mapitem', ('unsigned long int', 'base'), ('unsigned long int', 'fpage'))
	ast.add_child(mapitem)
Exemple #30
0
def create_special_C(arch_info, ast):
    type_list = ast.children
    struct_t = TypeNode(ast, source_file='<builtin>')
    struct_t.leaf = 'idl4_server_environment'
    struct_t.add_attribute('meta_type', 'struct')
    members = Node(struct_t, 'members')
    typeinst = Node(struct_t, 'type_instance')
    typeinst.leaf = '_action'
    index = [element.leaf for element in type_list].index('signed int')
    typeinst.add_attribute('target_type', type_list[index])
    members.add_child(typeinst)
    typeinst = Node(struct_t, 'type_instance')
    typeinst.leaf = '_data'
    index = [element.leaf for element in type_list].index('void')
    typeinst.add_attribute('target_type', type_list[index])
    members.add_child(typeinst)

    # Create IDL4 scope for giggles.
    idl4 = Node(ast, 'type', leaf='idl4', source_file='<builtin>')
    idl4.add_attribute('meta_type', 'private')
    pagefault = Node(idl4, 'type', leaf='pagefault')
    idl4.add_child(pagefault)
    ast.add_child(idl4)

    #FIXME: CORBA-C Type-Hack!!!
    aliases = (('Object', 'signed int'), ('any', 'signed int'),
               ('ValueBase', 'signed int'), ('Word', 'signed int'))

    # Create aliases to C nodes.
    for alias, name in aliases:
        newType = TypeNode(ast, source_file='<builtin>')
        newType.leaf = alias
        newType.add_attribute('meta_type', 'alias')
        type_list = ast.children
        index = [element.leaf for element in type_list].index(name)
        target_node = Node(newType, 'target')
        target_node.add_child(type_list[index])
        newType.add_child(target_node)

        ast.add_child(newType)

    # Explicitly add the IDL4 mapitem struct, yuck yuck
    mapitem = _make_struct(ast, 'idl4_mapitem', ('unsigned long int', 'base'),
                           ('unsigned long int', 'fpage'))
    ast.add_child(mapitem)
Exemple #31
0
	def component_body(self, ast, pt):
		exp_list = []
		for exp in pt.children:
			exp_node = Node(ast, 'export', source = exp)
			if exp.children[0].type == 'provides_dcl':
				exp_node.add_attribute('type', 'provides')
				exp_node.leaf = exp.children[0].the('identifier').leaf
				if exp.children[0].the('interface_type').the('scoped_name') != None:
					scopedname = self.scoped_name(exp.children[0].the('interface_type').the('scoped_name'))
					exp_node.add_attribute('name', scopedname)
				else:
					exp_node.add_attribute('name', 'Object')
			elif exp.children[0].type == 'uses_dcl':
				typestr = ''
				for child in exp.children[0]['uses_dcl']:
					typestr += child.leaf
				exp_node.add_attribute('type', typestr)
				exp_node.leaf = exp.children[0].the('identifier').leaf
				if exp.children[0].the('interface_type').the('scoped_name') != None:
					scopedname = self.scoped_name(exp.children[0].the('interface_type').the('scoped_name'))
					exp_node.add_attribute('name', scopedname)
				else:
					exp_node.add_attribute('name', 'Object')
			elif exp.children[0].type == 'emits_dcl':
				exp_node.add_attribute('type', 'emits')
				exp_node.leaf = exp.children[0].the('identifier').leaf
				scopedname = self.scoped_name(exp.children[0].the('scoped_name'))
				exp_node.add_attribute('name', scopedname)
			elif exp.children[0].type == 'publishes_dcl':
				exp_node.add_attribute('type', 'publishes')
				exp_node.leaf = exp.children[0].the('identifier').leaf
				scopedname = self.scoped_name(exp.children[0].the('scoped_name'))
				exp_node.add_attribute('name', scopedname)
			elif exp.children[0].type == 'consumes_dcl':
				exp_node.add_attribute('type', 'consumes')
				exp_node.leaf = exp.children[0].the('identifier').leaf
				scopedname = self.scoped_name(exp.children[0].the('scoped_name'))
				exp_node.add_attribute('name', scopedname)
			elif exp.children[0].type == 'attr_dcl':
				# FIXME: Not used?
				self.attr_dcl(exp_node, exp.children[0])
			else:
				exp_list.append(UnknownChild(None, exp))
			exp_list.append(exp_node)
		return exp_list