Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def prune(self):
def p(n):
if hasattr(n, 'i_children'):
deletes = []
for ch in n.i_children:
if hasattr(ch, 'i_not_implemented'):
deletes.append(ch)
else:
p(ch)
if len(deletes) > 0:
for d in deletes:
idx = n.i_children.index(d)
del n.i_children[idx]
p(self)
class AugmentStatement(Statement):
__slots__ = (
# see v_type_augment()
'i_target_node', # Statement augmented by self
# also present in DeviationStatement
'i_has_i_children', # also present in GroupingStatement
)
class BaseStatement(Statement):
__slots__ = (
# see v_type_base()
'i_identity',
)
class BitStatement(Statement):
def update_or_add_stmt(stmt, keyword, arg, index=None):
child = stmt.search_one(keyword)
currarg = child.arg if child else None
(argval, replace) = get_arg_value(arg, currarg)
if argval is None:
child = None
elif child:
if not replace and child.arg and child.arg != argval and child.arg \
!= 'TBD':
sys.stderr.write('%s: not replacing existing %s %r with %r\n' % (
child.pos, keyword, child.arg, argval))
else:
child.arg = argval
else:
child = statements.Statement(stmt.top, stmt, None, keyword, argval)
if index is None:
index = len(stmt.substmts)
# XXX this hack ensures that 'reference' is always last
if index > 0 and stmt.substmts[index - 1].keyword == 'reference':
index -= 1
stmt.substmts.insert(index, child)
return child
input_.i_children = []
input_.i_module = stmt.i_module
stmt.i_children.append(input_)
else:
# check that there is at least one data definition statement
found = False
for c in input_.substmts:
if c.keyword in data_definition_keywords:
found = True
if not found:
err_add(ctx.errors, input_.pos,'EXPECTED_DATA_DEF', 'input')
output = stmt.search_one('output')
if output is None:
# create the implicitly defined output node
output = Statement(stmt.top, stmt, stmt.pos, 'output', 'output')
v_init_stmt(ctx, output)
output.i_children = []
output.i_module = stmt.i_module
stmt.i_children.append(output)
else:
# check that there is at least one data definition statement
found = False
for c in output.substmts:
if c.keyword in data_definition_keywords:
found = True
if not found:
err_add(ctx.errors, output.pos,'EXPECTED_DATA_DEF', 'output')
if stmt.keyword == 'grouping':
stmt.i_expanded = False
for s in stmt.substmts:
'i_position',
)
class CommentStatement(Statement):
__slots__ = (
'i_line_end',
'i_multi_line',
)
class ChoiceStatement(Statement):
__slots__ = (
'i_augment',
)
class ContainerStatement(Statement):
__slots__ = (
'i_augment',
'i_not_supported',
'i_this_not_supported',
)
class DeviationStatement(Statement):
__slots__ = (
'i_target_node', # Statement deviated by self
# also present in AugmentStatement
)
class EnumStatement(Statement):
__slots__ = (
def gen_new_import(module, modname, revision):
i = 0
pre = "p" + str(i)
while pre in module.i_prefixes:
i = i + 1
pre = "p" + str(i)
module.i_prefixes[pre] = (modname, revision)
imp = statements.Statement(module, module, None, 'import', modname)
if revision is not None:
rev = statements.Statement(module, imp, None, 'revision-date',
revision)
imp.substmts.append(rev)
module.i_gen_import.append(imp)
return pre
if len(deletes) > 0:
for d in deletes:
idx = n.i_children.index(d)
del n.i_children[idx]
p(self)
class AugmentStatement(Statement):
__slots__ = (
# see v_type_augment()
'i_target_node', # Statement augmented by self
# also present in DeviationStatement
'i_has_i_children', # also present in GroupingStatement
)
class BaseStatement(Statement):
__slots__ = (
# see v_type_base()
'i_identity',
)
class BitStatement(Statement):
__slots__ = (
'i_position',
)
class CommentStatement(Statement):
__slots__ = (
'i_line_end',
'i_multi_line',
)
err_add(ctx.errors, stmt.pos, 'NODE_NOT_FOUND',
(module.i_modulename, identifier))
return None
# then recurse down the path
for prefix, identifier in path[1:]:
if hasattr(node, 'i_children'):
module = util.prefix_to_module(
stmt.i_module, prefix, stmt.pos, ctx.errors)
if module is None:
return None
child = search_child(node.i_children, module.i_modulename,
identifier)
if child is None and module == stmt.i_module and is_augment:
# create a temporary statement
child = Statement(node.top, node, stmt.pos, '__tmp_augment__',
identifier)
v_init_stmt(ctx, child)
child.i_module = module
child.i_children = []
child.i_config = node.i_config
node.i_children.append(child)
# keep track of this temporary statement
stmt.i_module.i_undefined_augment_nodes[child] = child
elif child is None:
err_add(ctx.errors, stmt.pos, 'NODE_NOT_FOUND',
(module.i_modulename, identifier))
return None
node = child
else:
err_add(ctx.errors, stmt.pos, 'NODE_NOT_FOUND',
(module.i_modulename, identifier))