mirror of https://github.com/m-labs/artiq.git
Show origin of expansion in diagnostics for synthesized code.
This commit is contained in:
parent
50448ef554
commit
a7633f75c7
|
@ -12,9 +12,10 @@ from .transforms import ASTTypedRewriter, Inferencer
|
||||||
|
|
||||||
|
|
||||||
class ASTSynthesizer:
|
class ASTSynthesizer:
|
||||||
def __init__(self):
|
def __init__(self, expanded_from=None):
|
||||||
self.source = ""
|
self.source = ""
|
||||||
self.source_buffer = source.Buffer(self.source, "<synthesized>")
|
self.source_buffer = source.Buffer(self.source, "<synthesized>")
|
||||||
|
self.expanded_from = expanded_from
|
||||||
|
|
||||||
def finalize(self):
|
def finalize(self):
|
||||||
self.source_buffer.source = self.source
|
self.source_buffer.source = self.source
|
||||||
|
@ -24,7 +25,8 @@ class ASTSynthesizer:
|
||||||
range_from = len(self.source)
|
range_from = len(self.source)
|
||||||
self.source += fragment
|
self.source += fragment
|
||||||
range_to = len(self.source)
|
range_to = len(self.source)
|
||||||
return source.Range(self.source_buffer, range_from, range_to)
|
return source.Range(self.source_buffer, range_from, range_to,
|
||||||
|
expanded_from=self.expanded_from)
|
||||||
|
|
||||||
def quote(self, value):
|
def quote(self, value):
|
||||||
"""Construct an AST fragment equal to `value`."""
|
"""Construct an AST fragment equal to `value`."""
|
||||||
|
@ -128,7 +130,7 @@ class StitchingASTTypedRewriter(ASTTypedRewriter):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# It's just a value. Quote it.
|
# It's just a value. Quote it.
|
||||||
synthesizer = ASTSynthesizer()
|
synthesizer = ASTSynthesizer(expanded_from=node.loc)
|
||||||
node = synthesizer.quote(value)
|
node = synthesizer.quote(value)
|
||||||
synthesizer.finalize()
|
synthesizer.finalize()
|
||||||
return node
|
return node
|
||||||
|
|
|
@ -76,9 +76,12 @@ class Inferencer(algorithm.Visitor):
|
||||||
|
|
||||||
def visit_ListT(self, node):
|
def visit_ListT(self, node):
|
||||||
self.generic_visit(node)
|
self.generic_visit(node)
|
||||||
|
elt_type_loc = node.loc
|
||||||
for elt in node.elts:
|
for elt in node.elts:
|
||||||
self._unify(node.type["elt"], elt.type,
|
self._unify(node.type["elt"], elt.type,
|
||||||
node.loc, elt.loc, self._makenotes_elts(node.elts, "a list element"))
|
elt_type_loc, elt.loc,
|
||||||
|
self._makenotes_elts(node.elts, "a list element"))
|
||||||
|
elt_type_loc = elt.loc
|
||||||
|
|
||||||
def visit_AttributeT(self, node):
|
def visit_AttributeT(self, node):
|
||||||
self.generic_visit(node)
|
self.generic_visit(node)
|
||||||
|
|
Loading…
Reference in New Issue