Exemplo n.º 1
0
  // Tests that local variables are correctly recognized and that
  // cast expressions are skipped appropriately
  public void testLocalTypedef() throws SVParseException {
    String content =
        "function void foobar();\n"
            + "    typedef foo #(BAR) foo_t;\n"
            + "    foo_t              a;\n"
            + "    a = 5;\n"
            + "endfunction\n";

    //		ParserSVDBFileFactory parser = new ParserSVDBFileFactory(null);

    SVDBTask func = parse_tf(content, "testLocalTypedef");

    SVDBVarDeclItem a = null;
    for (ISVDBItemBase it : func.getChildren()) {
      if (it.getType() == SVDBItemType.VarDeclStmt) {
        for (ISVDBChildItem vi : ((SVDBVarDeclStmt) it).getChildren()) {
          if (SVDBItem.getName(vi).equals("a")) {
            a = (SVDBVarDeclItem) vi;
          }
        }
      }
    }

    assertEquals(3, SVDBUtil.getChildrenSize(func));
    assertEquals("foo_t", SVDBItem.getName(SVDBUtil.getFirstChildItem(func)));
    assertNotNull(a);
  }
  public void testClassLineNumbers() {
    String content =
        "class foobar;\n"
            + // 1
            "    int a;\n"
            + // 2
            "    int b;\n"
            + // 3
            "\n"
            + // 4
            "endclass\n"
            + // 5
            "\n"
            + // 6
            "\n" // 7
        ;
    SVDBFile file = SVDBTestUtils.parse(content, "testClassStringFields");

    SVDBClassDecl cls = null;

    assertEquals("Wrong number of file elements", 1, SVDBUtil.getChildrenSize(file));

    cls = (SVDBClassDecl) SVDBUtil.getFirstChildItem(file);

    assertNotNull("Start location not specified", cls.getLocation());
    assertNotNull("End location not specified", cls.getEndLocation());

    assertEquals("Wrong start location", 1, cls.getLocation().getLine());
    assertEquals("Wrong end location", 5, cls.getEndLocation().getLine());
  }
Exemplo n.º 3
0
  // Tests that local variables are correctly recognized and that
  // cast expressions are skipped appropriately
  public void testLocalTimeVar() throws SVParseException {
    String content =
        "function void foobar();\n" + "    time t = 10ns;\n" + "    t = 20ns;\n" + "endfunction\n";

    SVCorePlugin.getDefault().enableDebug(false);

    SVDBTask func = parse_tf(content, "testLocalTimeVar");

    assertEquals(2, SVDBUtil.getChildrenSize(func));
    assertTrue(SVDBUtil.getFirstChildItem(func).getType() == SVDBItemType.VarDeclStmt);
    SVDBVarDeclStmt stmt = (SVDBVarDeclStmt) SVDBUtil.getFirstChildItem(func);
    SVDBVarDeclItem vi = (SVDBVarDeclItem) stmt.getChildren().iterator().next();
    assertEquals("t", vi.getName());
  }
Exemplo n.º 4
0
  // Tests that local variables are correctly recognized and that
  // cast expressions are skipped appropriately
  public void testLocalVarsWithCast() throws SVParseException {
    String content =
        "function void foobar();\n"
            + "    int a = integer'(5);\n"
            + "    int b = longint'(6);\n"
            + "    a = 5;\n"
            + "endfunction\n";

    SVCorePlugin.getDefault().enableDebug(false);

    SVDBTask func = parse_tf(content, "testLocalVarsWithCast");

    assertEquals(3, SVDBUtil.getChildrenSize(func));
    SVDBVarDeclItem a = null, b = null;
    for (ISVDBItemBase it_t : func.getChildren()) {
      if (it_t.getType() == SVDBItemType.VarDeclStmt) {
        SVDBVarDeclStmt v = (SVDBVarDeclStmt) it_t;
        for (ISVDBChildItem vi : v.getChildren()) {
          if (SVDBItem.getName(vi).equals("a")) {
            a = (SVDBVarDeclItem) vi;
          } else if (SVDBItem.getName(vi).equals("b")) {
            b = (SVDBVarDeclItem) vi;
          }
        }
      }
    }
    assertNotNull(a);
    assertNotNull(b);
  }
  public void testClassFunctionLineNumbers() {
    String content =
        "class foobar;\n"
            + // 1
            "    int a;\n"
            + // 2
            "    int b;\n"
            + // 3
            "\n"
            + // 4
            "    function void foobar_f();\n"
            + // 5
            "        a = 5;\n"
            + // 6
            "        b = 6;\n"
            + // 7
            "    endfunction\n"
            + // 8
            "\n"
            + // 9
            "    function void foobar_f2();\n"
            + // 10
            "        a = 4;\n"
            + // 11
            "        b = 12;\n"
            + // 12
            "    endfunction\n"
            + // 13
            "\n"
            + // 14
            "endclass\n"
            + // 15
            "\n"
            + // 16
            "\n" // 17
        ;
    SVDBFile file = SVDBTestUtils.parse(content, "testClassStringFields");

    SVDBClassDecl cls = null;

    assertEquals("Wrong number of file elements", 1, SVDBUtil.getChildrenSize(file));

    cls = (SVDBClassDecl) SVDBUtil.getFirstChildItem(file);

    assertNotNull("Start location not specified", cls.getLocation());
    assertNotNull("End location not specified", cls.getEndLocation());

    assertEquals("Wrong start location", 1, cls.getLocation().getLine());
    assertEquals("Wrong end location", 15, cls.getEndLocation().getLine());

    SVDBTask f1 = null, f2 = null;

    for (ISVDBItemBase it : cls.getChildren()) {
      if (SVDBItem.getName(it).equals("foobar_f")) {
        f1 = (SVDBTask) it;
      }
      if (SVDBItem.getName(it).equals("foobar_f2")) {
        f2 = (SVDBTask) it;
      }
    }

    assertNotNull(f1);
    assertNotNull(f2);
    assertEquals("Wrong foobar_f start location", 5, f1.getLocation().getLine());
    assertEquals("Wrong foobar_f end location", 8, f1.getEndLocation().getLine());

    assertEquals("Wrong foobar_f2 start location", 10, f2.getLocation().getLine());
    assertEquals("Wrong foobar_f2 end location", 13, f2.getEndLocation().getLine());
  }