Fixed style issues

pull/4814/head
Daniel Mensinger 6 years ago
parent 4b3e21b894
commit dbb94f122d
No known key found for this signature in database
GPG Key ID: 54DD94C131E277D4
  1. 28
      mesonbuild/ast/printer.py
  2. 12
      mesonbuild/rewriter.py

@ -51,7 +51,7 @@ class AstPrinter(AstVisitor):
self.result += data self.result += data
self.is_newline = False self.is_newline = False
def appendS(self, data: str, node: mparser.BaseNode): def append_padded(self, data: str, node: mparser.BaseNode):
if self.result[-1] not in [' ', '\n']: if self.result[-1] not in [' ', '\n']:
data = ' ' + data data = ' ' + data
self.append(data + ' ', node) self.append(data + ' ', node)
@ -90,26 +90,26 @@ class AstPrinter(AstVisitor):
def visit_OrNode(self, node: mparser.OrNode): def visit_OrNode(self, node: mparser.OrNode):
node.left.accept(self) node.left.accept(self)
self.appendS('or', node) self.append_padded('or', node)
node.right.accept(self) node.right.accept(self)
def visit_AndNode(self, node: mparser.AndNode): def visit_AndNode(self, node: mparser.AndNode):
node.left.accept(self) node.left.accept(self)
self.appendS('and', node) self.append_padded('and', node)
node.right.accept(self) node.right.accept(self)
def visit_ComparisonNode(self, node: mparser.ComparisonNode): def visit_ComparisonNode(self, node: mparser.ComparisonNode):
node.left.accept(self) node.left.accept(self)
self.appendS(mparser.comparison_map[node.ctype], node) self.append_padded(mparser.comparison_map[node.ctype], node)
node.right.accept(self) node.right.accept(self)
def visit_ArithmeticNode(self, node: mparser.ArithmeticNode): def visit_ArithmeticNode(self, node: mparser.ArithmeticNode):
node.left.accept(self) node.left.accept(self)
self.appendS(arithmic_map[node.operation], node) self.append_padded(arithmic_map[node.operation], node)
node.right.accept(self) node.right.accept(self)
def visit_NotNode(self, node: mparser.NotNode): def visit_NotNode(self, node: mparser.NotNode):
self.appendS('not', node) self.append_padded('not', node)
node.value.accept(self) node.value.accept(self)
def visit_CodeBlockNode(self, node: mparser.CodeBlockNode): def visit_CodeBlockNode(self, node: mparser.CodeBlockNode):
@ -143,9 +143,9 @@ class AstPrinter(AstVisitor):
def visit_ForeachClauseNode(self, node: mparser.ForeachClauseNode): def visit_ForeachClauseNode(self, node: mparser.ForeachClauseNode):
varnames = [x.value for x in node.varnames] varnames = [x.value for x in node.varnames]
self.appendS('foreach', node) self.append_padded('foreach', node)
self.appendS(', '.join(varnames), node) self.append_padded(', '.join(varnames), node)
self.appendS(':', node) self.append_padded(':', node)
node.items.accept(self) node.items.accept(self)
self.newline() self.newline()
node.block.accept(self) node.block.accept(self)
@ -154,7 +154,7 @@ class AstPrinter(AstVisitor):
def visit_IfClauseNode(self, node: mparser.IfClauseNode): def visit_IfClauseNode(self, node: mparser.IfClauseNode):
prefix = '' prefix = ''
for i in node.ifs: for i in node.ifs:
self.appendS(prefix + 'if', node) self.append_padded(prefix + 'if', node)
prefix = 'el' prefix = 'el'
i.accept(self) i.accept(self)
if node.elseblock: if node.elseblock:
@ -163,7 +163,7 @@ class AstPrinter(AstVisitor):
self.append('endif', node) self.append('endif', node)
def visit_UMinusNode(self, node: mparser.UMinusNode): def visit_UMinusNode(self, node: mparser.UMinusNode):
self.appendS('-', node) self.append_padded('-', node)
node.value.accept(self) node.value.accept(self)
def visit_IfNode(self, node: mparser.IfNode): def visit_IfNode(self, node: mparser.IfNode):
@ -173,9 +173,9 @@ class AstPrinter(AstVisitor):
def visit_TernaryNode(self, node: mparser.TernaryNode): def visit_TernaryNode(self, node: mparser.TernaryNode):
node.condition.accept(self) node.condition.accept(self)
self.appendS('?', node) self.append_padded('?', node)
node.trueblock.accept(self) node.trueblock.accept(self)
self.appendS(':', node) self.append_padded(':', node)
node.falseblock.accept(self) node.falseblock.accept(self)
def visit_ArgumentNode(self, node: mparser.ArgumentNode): def visit_ArgumentNode(self, node: mparser.ArgumentNode):
@ -192,7 +192,7 @@ class AstPrinter(AstVisitor):
self.newline() self.newline()
for key, val in node.kwargs.items(): for key, val in node.kwargs.items():
self.append(key, node) self.append(key, node)
self.appendS(':', node) self.append_padded(':', node)
val.accept(self) val.accept(self)
self.append(', ', node) self.append(', ', node)
if break_args: if break_args:

@ -130,9 +130,6 @@ class Rewriter:
return args return args
if cmd['operation'] == 'src_add': if cmd['operation'] == 'src_add':
#################################
### Add sources to the target ###
#################################
node = None node = None
if target['sources']: if target['sources']:
node = target['sources'][0] node = target['sources'][0]
@ -159,10 +156,8 @@ class Rewriter:
# Mark the node as modified # Mark the node as modified
if node not in self.modefied_nodes: if node not in self.modefied_nodes:
self.modefied_nodes += [node] self.modefied_nodes += [node]
elif cmd['operation'] == 'src_rm': elif cmd['operation'] == 'src_rm':
######################################
### Remove sources from the target ###
######################################
# Helper to find the exact string node and its parent # Helper to find the exact string node and its parent
def find_node(src): def find_node(src):
for i in target['sources']: for i in target['sources']:
@ -195,10 +190,9 @@ class Rewriter:
# Mark the node as modified # Mark the node as modified
if root not in self.modefied_nodes: if root not in self.modefied_nodes:
self.modefied_nodes += [root] self.modefied_nodes += [root]
elif cmd['operation'] == 'test': elif cmd['operation'] == 'test':
###################################### # List all sources in the target
### List all sources in the target ###
######################################
src_list = [] src_list = []
for i in target['sources']: for i in target['sources']:
for j in arg_list_from_node(i): for j in arg_list_from_node(i):

Loading…
Cancel
Save