本文整理汇总了Python中magpieparsers.parser_common.Node类的典型用法代码示例。如果您正苦于以下问题:Python Node类的具体用法?Python Node怎么用?Python Node使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: except_dcl
def except_dcl(self, ast, pt, decorators):
excep_node = Node(ast, 'exception', None, source = pt)
excep_node.leaf = pt.the('identifier').leaf
if pt.the('opt_member_list') != None:
excep_node.add_children(self.member_list(ast, pt.the('opt_member_list')))
ast.add(excep_node)
self._dupes_check(excep_node)
示例2: addASTChild
def addASTChild(self,currentAST, child):
if not child:
return
rootnode = Node(None,sys._getframe(1).f_code.co_name,
source_line = self.LT(1).getLine(),
source_file = self.getFilename())
if child.node:
if not currentAST.root:
rootnode.children = [child.node]
else:
rootnode = child.node # Node(sys._getframe(1).f_code.co_name, children=[child.node])
child.node = rootnode
child.node.leaf = child.getText()
if child.node is None:
print child
if not currentAST.root:
currentAST.root = child
elif not currentAST.child:
currentAST.root.setFirstChild(child)
else:
currentAST.root.node.add_child(child.node)
currentAST.child.setNextSibling(child)
currentAST.child = child
currentAST.advanceChildToEnd()
示例3: type_from_declarator
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
示例4: param_dcl
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
示例5: enum_type
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: create_special_MIG
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)
示例7: case_stmt_list
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
示例8: get_call
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
示例9: make_scoped_name_ast
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
示例10: structure
def structure(self):
s = None
f = None
try: ## for error handling
pass
s = Node(None, "structure")
f = self.LT(1)
self.match(ATOM)
s.leaf = f.getText()
self.match(LBRACKET)
la1 = self.LA(1)
if False:
pass
elif la1 and la1 in [ATOM,VARIABLE,NUMBER,LCURLY,LSQUARE]:
pass
t=self.termlist()
s.children.extend(t)
elif la1 and la1 in [RBRACKET]:
pass
else:
raise antlr.NoViableAltException(self.LT(1), self.getFilename())
self.match(RBRACKET)
except antlr.RecognitionException, ex:
self.reportError(ex)
self.consume()
self.consumeUntil(_tokenSet_3)
示例11: type_id_dcl
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)
示例12: init_param_decls
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
示例13: get_conditional_expression
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
示例14: string_type
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
示例15: dictionary
def dictionary(self):
d = None
try: ## for error handling
pass
self.match(LCURLY)
self.match(RCURLY)
d = Node(None, "dictionary"); d._internal_data = {}
except antlr.RecognitionException, ex:
self.reportError(ex)
self.consume()
self.consumeUntil(_tokenSet_1)