Exemple #1
0
def _make_ir_from_emb(emb_text, name="m.emb"):
  ir, unused_debug_info, errors = glue.parse_emboss_file(
      name,
      test_util.dict_file_reader({name: emb_text}),
      stop_before_step="check_constraints")
  assert not errors, repr(errors)
  return ir
Exemple #2
0
def _make_ir_from_emb(emb_text, name="m.emb"):
    ir, unused_debug_info, errors = glue.parse_emboss_file(
        name,
        test_util.dict_file_reader({name: emb_text}),
        stop_before_step="normalize_and_verify")
    assert not errors
    return ir
Exemple #3
0
def _find_dependencies_for_snippet(emb_file):
    ir, unused_debug_info, errors = glue.parse_emboss_file(
        "m.emb",
        test_util.dict_file_reader({"m.emb": emb_file}),
        stop_before_step="set_dependency_order")
    assert not errors, errors
    return ir
Exemple #4
0
 def _make_ir(self, emb_text):
     ir, unused_debug_info, errors = glue.parse_emboss_file(
         "m.emb",
         test_util.dict_file_reader({"m.emb": emb_text}),
         stop_before_step="synthesize_fields")
     assert not errors, errors
     return ir
Exemple #5
0
 def test_parse_module_tokenization_error(self):
   file_name = "tokens.emb"
   ir, debug_info, errors = glue.parse_emboss_file(
       file_name, test_util.dict_file_reader({file_name: "@"}))
   self.assertTrue(debug_info.modules[file_name].source_code)
   self.assertTrue(errors)
   self.assertEqual("Unrecognized token", errors[0][0].message)
   self.assertFalse(ir)
Exemple #6
0
 def test_parse_module_indentation_error(self):
   file_name = "indent.emb"
   ir, debug_info, errors = glue.parse_emboss_file(
       file_name, test_util.dict_file_reader(
           {file_name: "struct Foo:\n"
                       "  1 [+1] Int x\n"
                       " 2 [+1] Int y\n"}))
   self.assertTrue(debug_info.modules[file_name].source_code)
   self.assertTrue(errors)
   self.assertEqual("Bad indentation", errors[0][0].message)
   self.assertFalse(ir)
Exemple #7
0
 def test_circular_dependency_error(self):
   file_name = "cycle.emb"
   ir, debug_info, errors = glue.parse_emboss_file(
       file_name, test_util.dict_file_reader({
           file_name: "struct Foo:\n"
                      "  0 [+field1]  UInt  field1\n"
       }))
   self.assertTrue(debug_info.modules[file_name].source_code)
   self.assertTrue(errors)
   self.assertEqual("Dependency cycle\nfield1", errors[0][0].message)
   self.assertFalse(ir)
Exemple #8
0
 def test_parse_module_no_such_file(self):
   file_name = "nonexistent.emb"
   ir, debug_info, errors = glue.parse_emboss_file(
       file_name, test_util.dict_file_reader({}))
   self.assertEqual([[
       error.error("nonexistent.emb", _location((1, 1), (1, 1)),
                   "Unable to read file."),
       error.note("nonexistent.emb", _location((1, 1), (1, 1)),
                  "File 'nonexistent.emb' not found."),
   ]], errors)
   self.assertFalse(file_name in debug_info.modules)
   self.assertFalse(ir)
Exemple #9
0
 def test_parse_module_parse_error(self):
   file_name = "parse.emb"
   ir, debug_info, errors = glue.parse_emboss_file(
       file_name, test_util.dict_file_reader(
           {file_name: "struct foo:\n"
                       "  1 [+1] Int x\n"
                       "  3 [+1] Int y\n"}))
   self.assertTrue(debug_info.modules[file_name].source_code)
   self.assertEqual([[
       error.error(file_name, _location((1, 8), (1, 11)),
                   "A type name must be CamelCase.\n"
                   "Found 'foo' (SnakeWord), expected CamelWord.")
   ]], errors)
   self.assertFalse(ir)
Exemple #10
0
 def test_error_on_import_cycle(self):
     ir, unused_debug_info, errors = glue.parse_emboss_file(
         "m.emb",
         test_util.dict_file_reader({
             "m.emb": 'import "n.emb" as n\n',
             "n.emb": 'import "m.emb" as m\n'
         }),
         stop_before_step="find_dependency_cycles")
     assert not errors
     self.assertEqual([[
         error.error("m.emb", ir.module[0].source_location,
                     "Import dependency cycle\nm.emb"),
         error.note("n.emb", ir.module[2].source_location, "n.emb")
     ]], dependency_checker.find_dependency_cycles(ir))
Exemple #11
0
 def test_parse_emboss_file(self):
   # parse_emboss_file calls parse_module, wraps its results, and calls
   # symbol_resolver.resolve_symbols() on the resulting IR.
   ir, debug_info, errors = glue.parse_emboss_file(_SPAN_SE_LOG_FILE_PATH,
                                                   _SPAN_SE_LOG_FILE_READER)
   module_ir, module_debug_info, module_errors = glue.parse_module(
       _SPAN_SE_LOG_FILE_PATH, _SPAN_SE_LOG_FILE_READER)
   self.assertEqual([], errors)
   self.assertEqual([], module_errors)
   self.assertTrue(test_util.proto_is_superset(ir.module[0], module_ir))
   self.assertEqual(module_debug_info,
                    debug_info.modules[_SPAN_SE_LOG_FILE_PATH])
   self.assertEqual(2, len(debug_info.modules))
   self.assertEqual(2, len(ir.module))
   self.assertEqual(_SPAN_SE_LOG_FILE_PATH, ir.module[0].source_file_name)
   self.assertEqual("", ir.module[1].source_file_name)
Exemple #12
0
def main(flags):
    ir, debug_info, errors = glue.parse_emboss_file(
        flags.input_file[0], _find_in_dirs_and_read(flags.import_dirs))
    if errors:
        _show_errors(errors, debug_info, flags)
        return 1
    main_module_debug_info = debug_info.modules[flags.input_file[0]]
    if flags.debug_show_tokenization:
        if flags.debug_show_header_lines:
            print("Tokenization:")
        print(main_module_debug_info.format_tokenization())
    if flags.debug_show_parse_tree:
        if flags.debug_show_header_lines:
            print("Parse Tree:")
        print(main_module_debug_info.format_parse_tree())
    if flags.debug_show_module_ir:
        if flags.debug_show_header_lines:
            print("Module IR:")
        print(main_module_debug_info.format_module_ir())
    if flags.debug_show_full_ir:
        if flags.debug_show_header_lines:
            print("Full IR:")
        print(str(ir))
    if flags.debug_show_used_productions:
        if flags.debug_show_header_lines:
            print("Used Productions:")
        print(
            glue.format_production_set(
                main_module_debug_info.used_productions))
    if flags.debug_show_unused_productions:
        if flags.debug_show_header_lines:
            print("Unused Productions:")
        print(
            glue.format_production_set(
                set(module_ir.PRODUCTIONS) -
                main_module_debug_info.used_productions))
    if flags.output_ir_to_stdout:
        print(ir.to_json())
    return 0
Exemple #13
0
 def test_error_on_import_cycle_and_field_cycle(self):
     ir, unused_debug_info, errors = glue.parse_emboss_file(
         "m.emb",
         test_util.dict_file_reader({
             "m.emb":
             'import "n.emb" as n\n'
             "struct Foo:\n"
             "  0 [+field1]  UInt  field1\n",
             "n.emb":
             'import "m.emb" as m\n'
         }),
         stop_before_step="find_dependency_cycles")
     assert not errors
     struct = ir.module[0].type[0].structure
     self.assertEqual(
         [[
             error.error("m.emb", ir.module[0].source_location,
                         "Import dependency cycle\nm.emb"),
             error.note("n.emb", ir.module[2].source_location, "n.emb")
         ],
          [
              error.error("m.emb", struct.field[0].source_location,
                          "Dependency cycle\nfield1")
          ]], dependency_checker.find_dependency_cycles(ir))