Пример #1
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
Пример #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
Пример #3
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
Пример #4
0
	def create_instance_list(self, ast, typeref, declarators):
		instance_list = []
		for child in declarators:
			instance = Node(ast, 'type_instance', None, source = child)
			
			if child.children[0].type == 'simple_declarator':
				instance.leaf = child.children[0].leaf
				instance.add_child(typeref)
			else: #complex_declarator
				newtype = TypeNode(ast, source = pt)
				newtype.add_attribute('meta_type','array')
				
				array_dcl = child.the('complex_declarator').the('array_declarator')
				array_dim = []
				for dimension in array_dcl.children:
					exp_node = dimension.the('positive_int_const').the('const_exp')
					expr = self.getExpression(ast, exp_node)
					array_dim.append(expr.leaf)
					'''
					if res != None:
						array_dcl.append(str(res))
					else:
						array_dcl.append(exp_str)
					'''
				newtype.add_attribute('shape',array_dim)
				newtype.add_child(typeref)
				
				instance.add_child(newtype)
				instance.leaf = array_dcl.leaf
			instance_list.append(instance)
		return instance_list
Пример #5
0
	def enum_type(self, ast, pt, defining_scope):
		type_node = TypeNode(ast, source = pt)
		type_node.add_attribute('meta_type', 'enum')

		enum_list = []
		for child in pt.children:
			if child.type == 'identifier':
				type_node.leaf = child.leaf
			elif child.type == 'enumerator_list':
				for enum in child['enumerator']:
					enum_list.append(enum.leaf)
				type_node.add_attribute('enumeration', enum_list)
	
		# All the enum internal names get added to the outer scope (Do they?!)
		if defining_scope:
			# Add the enum itself, too.
			defining_scope.add_child(type_node)

			for count, child_pt in enumerate(pt.the('enumerator_list')['enumerator']):
				enum_item_ast = TypeNode(defining_scope, leaf = child_pt.leaf, source = child)
				defining_scope.add_child(enum_item_ast)
				enum_item_ast.add_attribute('meta_type', 'enum_member')
				enum_item_ast.add_attribute('value', count)
				self._dupes_check(enum_item_ast)

				enum_item_target = Node(enum_item_ast, 'target')
				enum_item_target.add_child(type_node)
				enum_item_ast.add_child(enum_item_target)


		return type_node
Пример #6
0
def get_call(scope_ast, pt, ast_gen):
    """
	Translate function calls. PT looks like this:
	expression call
	 expression identifier
	  (value) = <function name>
	 expression comma (optional)
	  expression param1
	  expression param2
	  ...
	
	We turn them into this AST:
	expression call
	 expression scoped_name
	  (value) = <function name>
	 expression parameters (optional)
	  expression param1
	  expression param2
	  ...
	"""
    # Translate function calls.
    node = Node(scope_ast, 'expression', leaf='call', source=pt)

    expression_identifier = pt.children[0]
    assert expression_identifier.leaf == 'id_expression'

    node.add_child(get_scoped_name(node, expression_identifier, ast_gen))

    # Add parameters.
    if len(pt.children) == 2:
        node.add_child(_get_call_params(node, pt.children[1], ast_gen))

    return node
Пример #7
0
def get_call(scope_ast, pt, ast_gen):
    """
	Translate function calls. PT looks like this:
	expression call
	 expression identifier
	  (value) = <function name>
	 expression comma (optional)
	  expression param1
	  expression param2
	  ...
	
	We turn them into this AST:
	expression call
	 expression scoped_name
	  (value) = <function name>
	 expression parameters (optional)
	  expression param1
	  expression param2
	  ...
	"""
    # Translate function calls.
    node = Node(scope_ast, "expression", leaf="call", source=pt)

    expression_identifier = pt.children[0]
    assert expression_identifier.leaf == "id_expression"

    node.add_child(get_scoped_name(node, expression_identifier, ast_gen))

    # Add parameters.
    if len(pt.children) == 2:
        node.add_child(_get_call_params(node, pt.children[1], ast_gen))

    return node
Пример #8
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
Пример #9
0
	def type_from_declarator(self, parent_ast, declarator):
		"""
		Construct a partial type. Only used for typdefs currently.
		"""
		typenode = TypeNode(parent_ast, None, source = declarator)
		# Don't know the meta type here

		if declarator.my_children_are('simple_declarator'):
			typenode.leaf = declarator.the('simple_declarator').leaf
			#typenode.add_attribute('target_type', typeref)
		else: #complex_declarator
			newtype = TypeNode(parent_ast, source = declarator)
			newtype.add_attribute('meta_type','array')
			
			array_dcl = declarator.the('complex_declarator').the('array_declarator')
			array_dim = []
			shape = Node(newtype, 'shape', source = declarator)
			newtype.add_child(shape)

			for dimension in array_dcl.children:
				exp_node = dimension.the('positive_int_const').the('const_exp')
				expr = self.getExpression(shape, exp_node)
				if expr.attribute('value') < 0:
					raise DimensionOutOfRangeError(dimension)
				shape.add_child(expr)
			
			typenode.leaf = array_dcl.leaf
			typenode.add_child(newtype)
			
		assert typenode.leaf != None
		return typenode
Пример #10
0
	def decorator_element(self, ast, pt):
		dec_node = Node(None, 'annotation', source = pt)
		for child in pt.children:
			if child.type == 'identifier':
				dec_node.leaf = child.leaf
			elif child.type == 'expr_list':
				dec_node.add_children(self.expr_list(ast, child, True))
			else:
				dec_node.add_child(UnknownNode(child, source = pt))
		return dec_node
Пример #11
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
Пример #12
0
	def attr_declarator(self, ast, pt):
		decl = Node(ast, 'declarator', None, source = pt)
		decl.leaf = []
		for child in pt.children:
			if child.type == 'simple_declarator':
				decl.leaf.append(child.leaf)
			elif child.type == 'attr_raises_expr':
				decl.add_child(self.attr_raises_expr(decl, child))
			else:
				decl.add_child(UnkownNode(None, child, source = pt))
		return decl
Пример #13
0
	def value_dcl(self, ast, pt):
		node = Node(ast, 'valuetype', None, source = pt)
		for child in pt.children:
			if child.type == 'identifier':
				node.leaf = child.leaf
			elif child.type == 'value_inheritance_spec':
				val_inh_node = self.value_inheritance_spec(node, self, child)
				node.add_child(val_inh_node)
			else:
				node.add_child(UnknownNode(child, source = pt))
		return node
Пример #14
0
def get_conditional_expression(scope_ast, pt, ast_gen):
    """
	Conditional expressions (ternary expression)
	"""
    node = Node(scope_ast, "expression", leaf="ternary_if", source=pt)
    cond_pt, true_pt, false_pt = pt.children

    node.add_child(get_expression(node, cond_pt, ast_gen))
    node.add_child(get_expression(node, true_pt, ast_gen))
    node.add_child(get_expression(node, false_pt, ast_gen))

    return node
Пример #15
0
def get_conditional_expression(scope_ast, pt, ast_gen):
    """
	Conditional expressions (ternary expression)
	"""
    node = Node(scope_ast, "expression", leaf="ternary_if", source=pt)
    cond_pt, true_pt, false_pt = pt.children

    node.add_child(get_expression(node, cond_pt, ast_gen))
    node.add_child(get_expression(node, true_pt, ast_gen))
    node.add_child(get_expression(node, false_pt, ast_gen))

    return node
Пример #16
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
Пример #17
0
def get_expression(scope_ast, pt, ast_gen):
    if pt.name == "expression" and pt.leaf == "" and len(pt.children) == 1:
        pt = pt.children[0]

    if pt.name == "expression" and pt.leaf in OK_ALREADY:
        node = Node(scope_ast, "expression", leaf=pt.leaf, source=pt)
        for child_pt in pt.children:
            node.add_child(get_expression(node, child_pt, ast_gen))
        return node
    elif pt.name == "expression" and pt.leaf in HANDLERS:
        return HANDLERS[pt.leaf](scope_ast, pt, ast_gen)
    else:
        pt.print_tree()
        raise Error("Couldn't translate PT")
Пример #18
0
def get_expression(scope_ast, pt, ast_gen):
    if pt.name == 'expression' and pt.leaf == '' and len(pt.children) == 1:
        pt = pt.children[0]

    if pt.name == 'expression' and pt.leaf in OK_ALREADY:
        node = Node(scope_ast, 'expression', leaf=pt.leaf, source=pt)
        for child_pt in pt.children:
            node.add_child(get_expression(node, child_pt, ast_gen))
        return node
    elif pt.name == 'expression' and pt.leaf in HANDLERS:
        return HANDLERS[pt.leaf](scope_ast, pt, ast_gen)
    else:
        pt.print_tree()
        raise Error("Couldn't translate PT")
Пример #19
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
Пример #20
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
Пример #21
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)
Пример #22
0
	def member_list(self, ast, pt):
		members = Node(ast, None, source = pt)
		members.type = 'members'
		for child in pt.children:
			if child.type == 'member':
				typeref, new_type = self.type_spec(members, child.the('type_spec'))
				if new_type:
					if isinstance(typeref, str):
						pass
					else:
						members.add_child(typeref)
				members.add_children(self.create_instance_list(members, typeref, child.the('declarators').children))
			else:
				print 'memberlist_unknown' + child.type
		return [members]
Пример #23
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
Пример #24
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])
Пример #25
0
def _get_call_params(scope_ast, pt, ast_gen):
    params_ast = Node(scope_ast, "expression", leaf="parameters", source=pt)

    if pt.leaf == "comma":
        for param_pt in pt.get_children_named("expression"):
            param_expr_ast = get_expression(params_ast, param_pt, ast_gen)
            if param_expr_ast is None:
                param_pt.print_tree()
            params_ast.add_child(param_expr_ast)
    elif pt.name == "expression":
        params_ast.add_child(get_expression(params_ast, pt, ast_gen))
    else:
        # hm
        pt.print_tree()
        raise Error("Unable to decode parameter list")

    return params_ast
Пример #26
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
Пример #27
0
def _get_call_params(scope_ast, pt, ast_gen):
    params_ast = Node(scope_ast, 'expression', leaf='parameters', source=pt)

    if pt.leaf == 'comma':
        for param_pt in pt.get_children_named('expression'):
            param_expr_ast = get_expression(params_ast, param_pt, ast_gen)
            if param_expr_ast is None:
                param_pt.print_tree()
            params_ast.add_child(param_expr_ast)
    elif pt.name == 'expression':
        params_ast.add_child(get_expression(params_ast, pt, ast_gen))
    else:
        # hm
        pt.print_tree()
        raise Error("Unable to decode parameter list")

    return params_ast
Пример #28
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)
Пример #29
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)
Пример #30
0
def create_basictype_ast(arch_name, typetype):
	ast = Node(None, 'MagpieAST', None)
	arch_info = construct_for_arch(arch_name, typetype)
	if typetype == 'idl4':
		names = CORBA_NAMES + C_NAMES
		aliases = C_ALIAS
		
	if typetype == 'mig':
		names = CORBA_NAMES + MIG_NAMES
		aliases = MIG_ALIAS
		
	for name in names:
		newType = TypeNode(ast, None, source_file = '<builtin>')
		newType.leaf = name
		newType.add_attribute('meta_type', 'basic')
		newType.add_attribute('size', arch_info.size_in_bits(name))
		
		if arch_info.smallest(name) is not None:
			newType.add_attribute('smallest', arch_info.smallest(name))

		if arch_info.largest(name) is not None:
			newType.add_attribute('largest', arch_info.largest(name))

		ast.add_child(newType)
		
	for alias, name in aliases:
		newType = TypeNode(ast, None, 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(newType, 'target', [type_list[index]])
		newType.add_child(target)
		ast.add_child(newType)
		
	if typetype == 'idl4':
		create_special_C(arch_info, ast)
	if typetype == 'mig':
		create_special_MIG(arch_info, ast)
	
	return ast
Пример #31
0
def create_basictype_ast(arch_name, typetype):
    ast = Node(None, 'MagpieAST', None)
    arch_info = construct_for_arch(arch_name, typetype)
    if typetype == 'idl4':
        names = CORBA_NAMES + C_NAMES
        aliases = C_ALIAS

    if typetype == 'mig':
        names = CORBA_NAMES + MIG_NAMES
        aliases = MIG_ALIAS

    for name in names:
        newType = TypeNode(ast, None, source_file='<builtin>')
        newType.leaf = name
        newType.add_attribute('meta_type', 'basic')
        newType.add_attribute('size', arch_info.size_in_bits(name))

        if arch_info.smallest(name) is not None:
            newType.add_attribute('smallest', arch_info.smallest(name))

        if arch_info.largest(name) is not None:
            newType.add_attribute('largest', arch_info.largest(name))

        ast.add_child(newType)

    for alias, name in aliases:
        newType = TypeNode(ast, None, 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(newType, 'target', [type_list[index]])
        newType.add_child(target)
        ast.add_child(newType)

    if typetype == 'idl4':
        create_special_C(arch_info, ast)
    if typetype == 'mig':
        create_special_MIG(arch_info, ast)

    return ast
Пример #32
0
 def clauses(self):    
     l = None
     
     l = Node(None, "clauses")
     try:      ## for error handling
         pass
         c=self.clause()
         l.add_child(c)
         while True:
             if (self.LA(1)==DEFINEDAS or self.LA(1)==FULLSTOP or self.LA(1)==ATOM):
                 pass
                 c=self.clause()
                 l.add_child(c)
             else:
                 break
             
     
     except antlr.RecognitionException, ex:
         self.reportError(ex)
         self.consume()
         self.consumeUntil(_tokenSet_0)
Пример #33
0
    def clauses(self):
        l = None

        l = Node(None, "clauses")
        try:  ## for error handling
            pass
            c = self.clause()
            l.add_child(c)
            while True:
                if (self.LA(1) == DEFINEDAS or self.LA(1) == FULLSTOP
                        or self.LA(1) == ATOM):
                    pass
                    c = self.clause()
                    l.add_child(c)
                else:
                    break

        except antlr.RecognitionException, ex:
            self.reportError(ex)
            self.consume()
            self.consumeUntil(_tokenSet_0)
Пример #34
0
	def case_stmt_list(self, ast, pt):
		"""
		switch
		 case
		  expression
		  [expression...]
		  declarator
		 [case...]
		"""
		# Find the appropriate scope for resolving scoped names, if any are present in
		# the case statement list. Switches on enums are constrained to the scope of
		# the enum (I think).
		
		switch_ast = Node(ast, 'switch', source = pt)
		for case_pt in pt.children:
			case_ast = Node(switch_ast, 'case', source = case_pt)
			switch_ast.add_child(case_ast)

			for choice_pt in case_pt['const_exp']:
				expr_ast = self.getExpression(case_ast, choice_pt)
				case_ast.add_child(expr_ast)

			typeref, new_type = self.type_spec(case_ast, case_pt.the('element_spec').the('type_spec'))
			if new_type:
				case_ast.add_child(typeref)
			
			decl = case_pt.the('element_spec').the('declarator')

			inst_list = self.create_instance_list(case_ast, typeref, [decl])
			case_ast.add_children(inst_list)

		return switch_ast
Пример #35
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)
Пример #36
0
	def module(self, ast, pt, decorators):
		assert not decorators
		module_name = pt.the('identifier').leaf
		mod = infogripper.getNode(module_name, ast, 'module')
		mod_is_new = False
		if mod is None:
			mod = Node(ast, 'module', None, source = pt)
			ast.add_child(mod)
			mod_is_new = True
		for child in pt.children:
			if child.type == 'identifier':
				mod.leaf = child.leaf
				# Modules can be re-opened, hence the check:
				if mod_is_new:
					self._dupes_check(mod)
			elif child.type == 'definition_list':
				for def_child in child.children:
					self.decorated_def(mod, def_child)
				#def_child = self.definition(def_child)
				#mod.add_child(def_child)
			else:
				mod.add_child(UnknownNode(None,child, source = pt))
Пример #37
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
Пример #38
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
Пример #39
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]))
Пример #40
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)
Пример #41
0
def _make_struct(ast, name, *args):
    struct = TypeNode(ast, leaf=name, source_file='<builtin>')
    struct.add_attribute('meta_type', 'struct')

    members = Node(struct, 'members')
    struct.add_child(members)

    for arg_type, arg_name in args:
        inst_node = Node(None, 'type_instance', leaf=arg_name)

        target = Node(inst_node, 'target')
        type_node = getTypenode(arg_type, ast)
        target.add_child(type_node)

        inst_node.add_child(target)
        members.add_child(inst_node)

    return struct
Пример #42
0
    def clause(self):
        c = None

        c = Node(None, "clause")
        try:  ## for error handling
            pass
            if (self.LA(1) == ATOM) and (self.LA(2) == LBRACKET):
                pass
                s = self.structure()
                c.add_child(s)
            elif (self.LA(1) == ATOM) and (self.LA(2) == DEFINEDAS
                                           or self.LA(2) == FULLSTOP):
                pass
                a = self.atom()
                c.add_child(a)
            elif (self.LA(1) == DEFINEDAS or self.LA(1) == FULLSTOP):
                pass
            else:
                raise antlr.NoViableAltException(self.LT(1),
                                                 self.getFilename())

            la1 = self.LA(1)
            if False:
                pass
            elif la1 and la1 in [DEFINEDAS]:
                pass
                self.match(DEFINEDAS)
                e = self.expression()
                c.add_child(e)
            elif la1 and la1 in [FULLSTOP]:
                pass
            else:
                raise antlr.NoViableAltException(self.LT(1),
                                                 self.getFilename())

            self.match(FULLSTOP)

        except antlr.RecognitionException, ex:
            self.reportError(ex)
            self.consume()
            self.consumeUntil(_tokenSet_2)