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:
|
||||
def __init__(self):
|
||||
def __init__(self, expanded_from=None):
|
||||
self.source = ""
|
||||
self.source_buffer = source.Buffer(self.source, "<synthesized>")
|
||||
self.expanded_from = expanded_from
|
||||
|
||||
def finalize(self):
|
||||
self.source_buffer.source = self.source
|
||||
|
@ -24,7 +25,8 @@ class ASTSynthesizer:
|
|||
range_from = len(self.source)
|
||||
self.source += fragment
|
||||
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):
|
||||
"""Construct an AST fragment equal to `value`."""
|
||||
|
@ -128,7 +130,7 @@ class StitchingASTTypedRewriter(ASTTypedRewriter):
|
|||
|
||||
else:
|
||||
# It's just a value. Quote it.
|
||||
synthesizer = ASTSynthesizer()
|
||||
synthesizer = ASTSynthesizer(expanded_from=node.loc)
|
||||
node = synthesizer.quote(value)
|
||||
synthesizer.finalize()
|
||||
return node
|
||||
|
|
|
@ -76,9 +76,12 @@ class Inferencer(algorithm.Visitor):
|
|||
|
||||
def visit_ListT(self, node):
|
||||
self.generic_visit(node)
|
||||
elt_type_loc = node.loc
|
||||
for elt in node.elts:
|
||||
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):
|
||||
self.generic_visit(node)
|
||||
|
|
Loading…
Reference in New Issue