Beispiel #1
0
def _install_row_cases(row, values):
  """Installs row case names, based on values entries."""
  # First define base testers that add row constraints and safety checks.
  constraint_rows_map = values.get('constraint_rows')
  if constraint_rows_map:
    base_row = _filter_test_row(row, with_rules=False)
    values['base_test_case'] = (
        'Case%s' % constraint_rows_map[dgen_core.neutral_repr(base_row)])
  else:
    values['base_test_case'] = ''

  # Add test decoders associated with the row in the table.
  decoder_rows_map = values.get('decoder_rows')
  if decoder_rows_map:
    decoder_row = _filter_test_row(row)
    values['test_case'] = (
        'Case%s' % decoder_rows_map[dgen_core.neutral_repr(decoder_row)])
  else:
    values['test_case'] = ''

  # Encorporate patterns with each row.
  pattern_rows_map = values.get('test_rows')
  if pattern_rows_map:
    pattern_row = _filter_test_row(row, with_patterns=True)
    values['test_pattern'] = (
        'Case%s' % pattern_rows_map[dgen_core.neutral_repr(pattern_row)])
  else:
    values['test_pattern'] = ''
Beispiel #2
0
def _install_row_cases(row, values):
  """Installs row case names, based on values entries."""
  # First define base testers that add row constraints and safety checks.
  constraint_rows_map = values.get('constraint_rows')
  if constraint_rows_map:
    base_row = _filter_test_row(row)
    values['base_test_case'] = (
        'Case%s' % constraint_rows_map[dgen_core.neutral_repr(base_row)])
  else:
    values['base_test_case'] = ''

  # Add test decoders associated with the row in the table.
  decoder_rows_map = values.get('decoder_rows')
  if decoder_rows_map:
    decoder_row = _filter_test_row(row)
    values['test_case'] = (
        'Case%s' % decoder_rows_map[dgen_core.neutral_repr(decoder_row)])
  else:
    values['test_case'] = ''

  # Encorporate patterns with each row.
  pattern_rows_map = values.get('test_rows')
  if pattern_rows_map:
    pattern_row = _filter_test_row(row)
    values['test_pattern'] = (
        'Case%s' % pattern_rows_map[dgen_core.neutral_repr(pattern_row)])
  else:
    values['test_pattern'] = ''
Beispiel #3
0
def _index_neutral_map(values):
  """Returns a dictionary from each neutral_repr(value) in list
     values, to its corresponding index. This is done to reduce the
     number of compares to find the index, speeding up code
     generation.
     """
  lookup_map = {}
  index = 0
  for v in values:
    lookup_map[dgen_core.neutral_repr(v)] = index
    index += 1
  return lookup_map
Beispiel #4
0
def _index_neutral_map(values):
  """Returns a dictionary from each neutral_repr(value) in list
     values, to its corresponding index. This is done to reduce the
     number of compares to find the index, speeding up code
     generation.
     """
  lookup_map = {}
  index = 0
  for v in values:
    lookup_map[dgen_core.neutral_repr(v)] = index
    index += 1
  return lookup_map
Beispiel #5
0
def _install_test_row(row, decoder, values,
                      with_patterns=False, with_rules=True):
  """Installs data associated with the given row into the values map.

     Installs the baseline class, rule name, and constraints associated
     with the row. If with_patterns is specified, then pattern information and
     actual class information is also inserted.
     """
  action = _filter_test_action(row.action, with_patterns, with_rules)
  values['row_comment'] = (dgen_core.neutral_repr(row.copy_with_action(action)).
                           replace(NEWLINE_STR, COMMENTED_NEWLINE_STR))
  values['row_rep_comment'] = repr(
      row.copy_with_action(action)).replace(NEWLINE_STR, COMMENTED_NEWLINE_STR)
  _install_action(decoder, action, values)
  return action
Beispiel #6
0
def DefineDecoder(action, decoder_name, out):
  """Generates the C++ class definition for the given action.

     action: The decoder action to define.
     decoder_name: The name for the C++ decoder class.
     out: The output stream to write the class declation to.
  """

  values = {'decoder_name': decoder_name}
  for method in METHODS:
    if _IsMethodDefined(action, method):
      method_body = _FindMethodBody(action, method)
      values['neutral_rep'] = (
          '%s: %s' % (method, dgen_output.commented_string(
              repr(dgen_core.neutral_repr(method_body)), '  ')))
      DefineMethodFcn(method)(out, method_body, values)
Beispiel #7
0
def _rows_to_test(decoder, values):
  """Returns the rows of the decoder that define enough information
     that testing can be done.
     """
  generated_names = set()
  rows = []
  for table in decoder.tables():
    for row in table.rows():
      if (isinstance(row.action, dgen_core.DecoderAction) and
          row.action.pattern()):
        new_row = row.copy_with_action(_install_test_row(row, decoder, values))
        constraint_tester = dgen_core.neutral_repr(new_row)
        if constraint_tester not in generated_names:
          generated_names.add(constraint_tester)
          rows.append(new_row)
  return sorted(rows)
def _rows_to_test(decoder, values):
  """Returns the rows of the decoder that define enough information
     that testing can be done.
     """
  generated_names = set()
  rows = []
  for table in decoder.tables():
    for row in table.rows():
      if (isinstance(row.action, dgen_core.DecoderAction) and
          row.action.pattern()):
        new_row = row.copy_with_action(_install_test_row(row, decoder, values))
        constraint_tester = dgen_core.neutral_repr(new_row)
        if constraint_tester not in generated_names:
          generated_names.add(constraint_tester)
          rows.append(new_row)
  return sorted(rows)