| 1 | #!/usr/bin/env python2
|
| 2 | """
|
| 3 | metrics.py
|
| 4 | """
|
| 5 | from __future__ import print_function
|
| 6 |
|
| 7 | from asdl import visitor
|
| 8 | from asdl.util import log
|
| 9 |
|
| 10 |
|
| 11 | class MetricsVisitor(visitor.AsdlVisitor):
|
| 12 | """Collect metrics"""
|
| 13 |
|
| 14 | def __init__(self, f):
|
| 15 | visitor.AsdlVisitor.__init__(self, f)
|
| 16 |
|
| 17 | def VisitSimpleSum(self, sum, sum_name, depth):
|
| 18 | pass
|
| 19 |
|
| 20 | def VisitCompoundSum(self, sum, sum_name, depth):
|
| 21 | num_variants = 0
|
| 22 | for i, variant in enumerate(sum.types):
|
| 23 | if variant.shared_type:
|
| 24 | continue # Don't generate a class for shared types.
|
| 25 | num_variants += 1
|
| 26 | self.f.write('%d %s\n' % (num_variants, sum_name))
|
| 27 |
|
| 28 | def VisitSubType(self, subtype):
|
| 29 | pass
|
| 30 |
|
| 31 | def VisitProduct(self, product, name, depth):
|
| 32 | pass
|
| 33 |
|
| 34 |
|
| 35 | def CountTypes(schema_ast, action):
|
| 36 | # 78
|
| 37 | log('defs: %d', len(schema_ast.dfns))
|
| 38 |
|
| 39 | t = schema_ast.type_lookup['command']
|
| 40 | print(t)
|