本文整理汇总了Python中magpieparsers.parser_common.Node.add_attribute方法的典型用法代码示例。如果您正苦于以下问题:Python Node.add_attribute方法的具体用法?Python Node.add_attribute怎么用?Python Node.add_attribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类magpieparsers.parser_common.Node
的用法示例。
在下文中一共展示了Node.add_attribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: value_inheritance_spec
# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_attribute [as 别名]
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)
示例2: create_special_MIG
# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_attribute [as 别名]
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)
示例3: param_dcl
# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_attribute [as 别名]
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: make_literal_ast
# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_attribute [as 别名]
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
示例5: component
# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_attribute [as 别名]
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)
示例6: make_scoped_name_ast
# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_attribute [as 别名]
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
示例7: type_id_dcl
# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_attribute [as 别名]
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)
示例8: op_dcl
# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_attribute [as 别名]
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)
示例9: make_identifier_ast
# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_attribute [as 别名]
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
示例10: init_param_decls
# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_attribute [as 别名]
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
示例11: string_type
# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_attribute [as 别名]
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
示例12: attr_raises_expr
# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_attribute [as 别名]
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
示例13: get_scoped_name
# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_attribute [as 别名]
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
示例14: attr_dcl
# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_attribute [as 别名]
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])
示例15: value_abs_dcl
# 需要导入模块: from magpieparsers.parser_common import Node [as 别名]
# 或者: from magpieparsers.parser_common.Node import add_attribute [as 别名]
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