<commit_before># language.py
# interface for language emitters
# author: <NAME>

import os

from util.visitor import stacked

import codecanvas.instructions as instructions

class Visitor(instructions.Visitor):
  def __init__(self):
    self._stack = []

  def get_stack(self): return self._stack
  stack = property(get_stack)

  def stack_as_string(self):
    return " > ".join([obj.__class__.__name__ for obj in self._stack])

  @stacked
  def visit_Unit(self, code):
    for child in code: child.accept(self)

  @stacked
  def visit_Section(self, code):
    for child in code: child.accept(self)

  @stacked
  def visit_Module(self, code):
    for child in code: child.accept(self)

  def visit_Constant(self, code): pass

  @stacked
  def visit_Function(self, code):
    for child in code: child.accept(self)

  @stacked
  def visit_Block(self, code):
    for child in code: child.accept(self)

  @stacked
  def visit_Print(self, code):
    for child in code: child.accept(self)

  @stacked
  def visit_Import(self, code):
    for child in code: child.accept(self)
  
  def visit_VoidType(self, code): pass
  def visit_IntegerType(self, code): pass
  def visit_ByteType(self, code): pass
  def visit_FloatType(self, code): pass
  def visit_BooleanType(self, code): pass
  def visit_LongType(self, type): pass
  
  @stacked
  def visit_TupleType(self, code): pass

  @stacked
  def visit_StructuredType(self, code):
    for child in code: child.accept(self)

  @stacked
  def visit_Property(self, code):
    code.type.accept(self)
  
  def visit_NamedType(self, code): pass
  
  # loops
  
  @stacked
  def visit_WhileDo(self, code):
    for child in code: child.accept(self)

  @stacked
  def visit_RepeatUntil(self, code):
    for child in code: child.accept(self)
    
  # calls

  @stacked
  def visit_FunctionCall(self, code):
    for child in code: child.accept(self)

  @stacked
  def visit_SimpleVariable(self, code): pass
  
  # literals
  @stacked
  def visit_BooleanLiteral(self, code): pass

  @stacked
  def visit_Comment(self, code): pass

  @stacked
  def visit_IfStatement(self, cond):
    for stmt in cond.true_clause: stmt.accept(self)
    for stmt in cond.false_clause: stmt.accept(self)

  @stacked
  def visit_CaseStatement(self, case):
    for stmt in case.cases: stmt.accept(self)
    for consequence in case.consequences:
      for stmt in consequence:
        stmt.accept(self)

  @stacked
  def visit_Assign(self, stmt):
    stmt.operand.accept(self)
    stmt.expression.accept(self)

  @stacked
  def visit_Add(self, stmt):
    stmt.operand.accept(self)
    stmt.expression.accept(self)

  @stacked
  def visit_Dec(self, stmt):
    stmt.operand.accept(self)
    stmt.expression.accept(self)

  @stacked
  def visit_MethodCall(self, stmt):
    stmt.obj.accept(self)
    stmt.method.accept(self)
    for arg in stmt.arguments:
      arg.accept(self)

  def visit_Object(self, obj): pass

  def visit_Identifier(self, id): pass

  @stacked
  def visit_ListLiteral(self, literal):
    for child in literal: child.accept(self)

  @stacked
  def visit_Inc(self, stmt):
    stmt.operand.accept(self)

  @stacked
  def visit_Dec(self, stmt):
    stmt.operand.accept(self)

  @stacked
  def visit_ManyType(self, type):
    type.type.accept(self)

  def visit_AtomLiteral(self, literal): pass

  def visit_IntegerLiteral(self, stmt): pass

  @stacked
  def visit_ObjectProperty(self, prop):
    prop.obj.accept(self)
    prop.prop.accept(self)<commit_msg>added tracking of visited children's index<commit_after># language.py
# interface for language emitters
# author: <NAME>

import os

from util.visitor import stacked

import codecanvas.instructions as instructions

class Visitor(instructions.Visitor):
  def __init__(self):
    self._stack = []
    self.child  = 0

  def get_stack(self): return self._stack
  stack = property(get_stack)

  def stack_as_string(self):
    return " > ".join([obj.__class__.__name__ for obj in self._stack])

  @stacked
  def visit_Unit(self, code):
    for index, child in enumerate(code):
      self.child = index
      child.accept(self)

  @stacked
  def visit_Section(self, code):
    for index, child in enumerate(code):
      self.child = index
      child.accept(self)

  @stacked
  def visit_Module(self, code):
    for index, child in enumerate(code):
      self.child = index
      child.accept(self)

  def visit_Constant(self, code): pass

  @stacked
  def visit_Function(self, code):
    for index, child in enumerate(code):
      self.child = index
      child.accept(self)

  @stacked
  def visit_Block(self, code):
    for index, child in enumerate(code):
      self.child = index
      child.accept(self)

  @stacked
  def visit_Print(self, code):
    for index, child in enumerate(code):
      self.child = index
      child.accept(self)

  @stacked
  def visit_Import(self, code):
    for index, child in enumerate(code):
      self.child = index
      child.accept(self)
  
  def visit_VoidType(self, code): pass
  def visit_IntegerType(self, code): pass
  def visit_ByteType(self, code): pass
  def visit_FloatType(self, code): pass
  def visit_BooleanType(self, code): pass
  def visit_LongType(self, type): pass
  
  @stacked
  def visit_TupleType(self, code): pass

  @stacked
  def visit_StructuredType(self, code):
    for index, child in enumerate(code):
      self.child = index
      child.accept(self)

  @stacked
  def visit_Property(self, code):
    code.type.accept(self)
  
  def visit_NamedType(self, code): pass
  
  # loops
  
  @stacked
  def visit_WhileDo(self, code):
    for index, child in enumerate(code):
      self.child = index
      child.accept(self)

  @stacked
  def visit_RepeatUntil(self, code):
    for index, child in enumerate(code):
      self.child = index
      child.accept(self)
    
  # calls

  @stacked
  def visit_FunctionCall(self, code):
    for index, child in enumerate(code):
      self.child = index
      child.accept(self)

  @stacked
  def visit_SimpleVariable(self, code): pass
  
  # literals
  @stacked
  def visit_BooleanLiteral(self, code): pass

  @stacked
  def visit_Comment(self, code): pass

  @stacked
  def visit_IfStatement(self, cond):
    for index, stmt in enumerate(cond.true_clause):
      self.child = index
      stmt.accept(self)
    for index, stmt in enumerate(cond.false_clause):
      self.child = index
      stmt.accept(self)

  @stacked
  def visit_CaseStatement(self, case):
    for index, stmt in enumerate(case.cases):
      self.child = index
      stmt.accept(self)
    for consequence in case.consequences:
      for index, stmt in enumerate(consequence):
        self.child = index
        stmt.accept(self)

  @stacked
  def visit_Assign(self, stmt):
    stmt.operand.accept(self)
    stmt.expression.accept(self)

  @stacked
  def visit_Add(self, stmt):
    stmt.operand.accept(self)
    stmt.expression.accept(self)

  @stacked
  def visit_Dec(self, stmt):
    stmt.operand.accept(self)
    stmt.expression.accept(self)

  @stacked
  def visit_MethodCall(self, stmt):
    stmt.obj.accept(self)
    stmt.method.accept(self)
    for index, arg in enumerate(stmt.arguments):
      self.child = index
      arg.accept(self)

  def visit_Object(self, obj): pass

  def visit_Identifier(self, id): pass

  @stacked
  def visit_ListLiteral(self, literal):
    for index, child in enumerate(literal):
      self.child = index
      child.accept(self)

  @stacked
  def visit_Inc(self, stmt):
    stmt.operand.accept(self)

  @stacked
  def visit_Dec(self, stmt):
    stmt.operand.accept(self)

  @stacked
  def visit_ManyType(self, type):
    type.type.accept(self)

  def visit_AtomLiteral(self, literal): pass

  def visit_IntegerLiteral(self, stmt): pass

  @stacked
  def visit_ObjectProperty(self, prop):
    prop.obj.accept(self)
    prop.prop.accept(self)
{'fraction_non_alphanumeric': 0.10329838915878292, 'fraction_numerical': 0.00012784454103809768, 'mean_word_length': 3.470285714285714, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1974698', 'n_tokens_mistral': 2685, 'n_tokens_neox': 2573, 'n_words': 663}