MCPcopy Index your code
hub / github.com/python/cpython / MetadataVisitor

Class MetadataVisitor

Parser/asdl_c.py:143–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141 self._metadata = value
142
143class MetadataVisitor(asdl.VisitorBase):
144 ROOT_TYPE = "AST"
145
146 def __init__(self, *args, **kwargs):
147 super().__init__(*args, **kwargs)
148
149 # Metadata:
150 # - simple_sums: Tracks the list of compound type
151 # names where all the constructors
152 # belonging to that type lack of any
153 # fields.
154 # - identifiers: All identifiers used in the AST declarations
155 # - singletons: List of all constructors that originates from
156 # simple sums.
157 # - types: List of all top level type names
158 #
159 self.metadata = types.SimpleNamespace(
160 simple_sums=set(),
161 identifiers=set(),
162 singletons=set(),
163 types={self.ROOT_TYPE},
164 )
165
166 def visitModule(self, mod):
167 for dfn in mod.dfns:
168 self.visit(dfn)
169
170 def visitType(self, type):
171 self.visit(type.value, type.name)
172
173 def visitSum(self, sum, name):
174 self.metadata.types.add(name)
175
176 simple_sum = is_simple(sum)
177 if simple_sum:
178 self.metadata.simple_sums.add(name)
179
180 for constructor in sum.types:
181 if simple_sum:
182 self.metadata.singletons.add(constructor.name)
183 self.visitConstructor(constructor)
184 self.visitFields(sum.attributes)
185
186 def visitConstructor(self, constructor):
187 self.metadata.types.add(constructor.name)
188 self.visitFields(constructor.fields)
189
190 def visitProduct(self, product, name):
191 self.metadata.types.add(name)
192 self.visitFields(product.attributes)
193 self.visitFields(product.fields)
194
195 def visitFields(self, fields):
196 for field in fields:
197 self.visitField(field)
198
199 def visitField(self, field):
200 self.metadata.identifiers.add(field.name)

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…