Ejemplo 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);
  }
Ejemplo n.º 2
0
  public void testEmptyConstraint() {
    String content =
        "class foobar;\n"
            + "\n"
            + "\n"
            + "    int a, b, c;\n"
            + "\n"
            + "    constraint empty_c {}\n"
            + "\n"
            + "endclass\n";

    SVDBFile file = SVDBTestUtils.parse(content, "testEmptyConstraint");

    SVDBClassDecl foobar = null;
    for (ISVDBItemBase it : file.getChildren()) {
      if (SVDBItem.getName(it).equals("foobar")) {
        foobar = (SVDBClassDecl) it;
        break;
      }
    }

    assertNotNull(foobar);

    SVDBConstraint empty_c = null;
    for (ISVDBItemBase it : foobar.getChildren()) {
      if (SVDBItem.getName(it).equals("empty_c")) {
        empty_c = (SVDBConstraint) it;
      }
    }

    assertNotNull(empty_c);
  }
Ejemplo n.º 3
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);
  }
Ejemplo n.º 4
0
  public void testCovergroup() {
    String content =
        "class foobar;\n"
            + "\n"
            + "\n"
            + "    int a, b, c;\n"
            + "\n"
            + "    covergroup cg;\n"
            + "        a_cp : coverpoint a;\n"
            + "        b_cp : coverpoint b {\n"
            + "            bins b[] = {[2:10]};\n"
            + "        }\n"
            + "        a_b_cross : cross a_cp, b_cp;\n"
            + "    endgroup\n"
            + "\n"
            + "    covergroup cg2;\n"
            + "        a_cp : coverpoint a;\n"
            + "        b_cp : coverpoint b {\n"
            + "            bins b[] = {[2:10]};\n"
            + "        }\n"
            + "        a_b_cross : cross a_cp, b_cp;\n"
            + "    endgroup\n"
            + "\n"
            + "endclass\n";
    SVCorePlugin.getDefault().enableDebug(false);

    SVDBFile file = SVDBTestUtils.parse(content, "testClassStringFields");

    SVDBClassDecl foobar = null;
    for (ISVDBItemBase it : file.getChildren()) {
      if (SVDBItem.getName(it).equals("foobar")) {
        foobar = (SVDBClassDecl) it;
        break;
      }
    }

    assertNotNull(foobar);

    SVDBCovergroup cg = null, cg2 = null;
    for (ISVDBItemBase it : foobar.getChildren()) {
      if (SVDBItem.getName(it).equals("cg")) {
        cg = (SVDBCovergroup) it;
      } else if (SVDBItem.getName(it).equals("cg2")) {
        cg2 = (SVDBCovergroup) it;
      }
    }

    assertNotNull(cg);
    assertNotNull(cg2);
  }
Ejemplo n.º 5
0
  public void testParamListFunctionWithPkg() throws SVParseException {
    String content =
        "function automatic void foobar(\n"
            + "        input int foobar,\n"
            + "        ref object bar,\n"
            + "        int foo);\n"
            + "    a_type foo, bar;\n"
            + "    b_type foo_q[$];\n"
            + "    int i, j, k;\n"
            + "    uvm_pkg::uvm_resource_db #(my_pkg::my_iface_container #(virtual my_iface)) "
            + "        ::set(\"my_ifaces\", $sformatf(\"my_iface_%01d\",0), ifc) ;"
            + "    for (int i=0; i<5; i++) begin\n"
            + "        a = 5;\n"
            + "    end\n"
            + "endfunction\n";

    SVCorePlugin.getDefault().enableDebug(false);

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

    ISVDBChildItem c = func.getParams().get(1).getChildren().iterator().next();

    assertEquals("bar", SVDBItem.getName(c));
    assertEquals(SVDBParamPortDecl.Direction_Ref, func.getParams().get(1).getDir());
  }
Ejemplo n.º 6
0
  public void testParamListFunction() throws SVParseException {
    String content =
        "function automatic void foobar(\n"
            + // 1
            "        input int foobar,\n"
            + // 2
            "        ref object bar,\n"
            + // 3
            "        int foo);\n"
            + // 4
            "    a_type foo, bar;\n"
            + // 5
            "    b_type foo_q[$];\n"
            + // 6
            "    b_cls #(foobar, bar) elem;\n"
            + "    int i, j, k;\n"
            + "    for (int i=0; i<5; i++) begin\n"
            + "        a = 5;\n"
            + "    end\n"
            + "endfunction\n";

    SVCorePlugin.getDefault().enableDebug(false);

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

    ISVDBChildItem c = func.getParams().get(1).getChildren().iterator().next();

    assertEquals("bar", SVDBItem.getName(c));
    assertEquals(SVDBParamPortDecl.Direction_Ref, func.getParams().get(1).getDir());
  }
Ejemplo n.º 7
0
  public void testTypedefClass() {
    String content =
        "class foobar;\n"
            + "\n"
            + "    typedef class other_foo_t;\n"
            + "    typedef class other_foo_t1;\n"
            + "    typedef class other_foo_t2;\n"
            + "    typedef class other_foo_t3;\n"
            + "    typedef class other_foo_t4;\n"
            + "\n"
            + "    other_foo_t	    foo_f;"
            + "\n"
            + "endclass\n";

    SVDBFile file = SVDBTestUtils.parse(content, "testClassStringFields");

    SVDBClassDecl foobar = null;
    for (ISVDBItemBase it : file.getChildren()) {
      if (SVDBItem.getName(it).equals("foobar")) {
        foobar = (SVDBClassDecl) it;
        break;
      }
    }

    SVDBTypedefStmt foobar_td = null;
    ISVDBItemBase foobar_i = null;
    ISVDBItemBase foobar_i1 = null;

    for (ISVDBItemBase it : foobar.getChildren()) {
      if (SVDBItem.getName(it).equals("other_foo_t")) {
        foobar_i = it;
      } else if (SVDBItem.getName(it).equals("other_foo_t1")) {
        foobar_i1 = it;
      }
    }

    assertNotNull("Failed to find other_foo_t", foobar_i);
    assertNotNull("Failed to find other_foo_t1", foobar_i1);
    assertEquals("other_foo_t is of wrong type", foobar_i.getType(), SVDBItemType.TypedefStmt);

    foobar_td = (SVDBTypedefStmt) foobar_i;

    assertEquals(
        "other_foo_t type-info is of wrong type",
        SVDBItemType.TypeInfoFwdDecl,
        foobar_td.getTypeInfo().getType());
  }
Ejemplo n.º 8
0
  public void testTypedef() {
    String content =
        "class foobar;\n"
            + "\n"
            + "    typedef enum {\n"
            + "        FOO,\n"
            + "        BAR\n"
            + "    } foobar_t;\n"
            + "\n"
            + "\n"
            + "    foobar_t     foo_f;"
            + "\n"
            + "endclass\n";

    SVDBFile file = SVDBTestUtils.parse(content, "testClassStringFields");

    SVDBClassDecl foobar = null;
    for (ISVDBItemBase it : file.getChildren()) {
      if (SVDBItem.getName(it).equals("foobar")) {
        foobar = (SVDBClassDecl) it;
        break;
      }
    }

    SVDBTypedefStmt foobar_td = null;
    ISVDBItemBase foobar_i = null;

    for (ISVDBItemBase it : foobar.getChildren()) {
      if (SVDBItem.getName(it).equals("foobar_t")) {
        foobar_i = it;
      }
    }

    assertNotNull("Failed to find foobar_t", foobar_i);
    assertEquals("foobar_t is of wrong type", foobar_i.getType(), SVDBItemType.TypedefStmt);

    foobar_td = (SVDBTypedefStmt) foobar_i;

    assertEquals(
        "foobar_t type-info is of wrong type",
        SVDBItemType.TypeInfoEnum,
        foobar_td.getTypeInfo().getType());

    SVDBTypeInfoEnum enum_t = (SVDBTypeInfoEnum) foobar_td.getTypeInfo();
    assertEquals(
        "foobar_t doesn't have correct number of elements", 2, enum_t.getEnumerators().size());
  }
Ejemplo n.º 9
0
  public void testClassStringFields() {
    String content =
        "class __sv_builtin_covergroup_options;\n"
            + "int 	weight;\n"
            + "\n"
            + "real 	goal;\n"
            + "\n"
            + "string 	name;\n"
            + "\n"
            + "string 	comment;\n"
            + "\n"
            + "int		at_least;\n"
            + "\n"
            + "bit		detect_overlap;\n"
            + "\n"
            + "int		auto_bin_max;\n"
            + "\n"
            + "bit		per_instance;\n"
            + "\n"
            + "bit		cross_num_print_missing;\n"
            + "\n"
            + "endclass\n";
    LogHandle log = LogFactory.getLogHandle("testClassStringFields");
    SVDBFile file = SVDBTestUtils.parse(content, "testClassStringFields");

    SVDBClassDecl cg_options = null;
    for (ISVDBItemBase it : file.getChildren()) {
      if (SVDBItem.getName(it).equals("__sv_builtin_covergroup_options")) {
        cg_options = (SVDBClassDecl) it;
      }
      log.debug("Item: " + it.getType() + " " + SVDBItem.getName(it));
    }

    assertNotNull("Failed to find class __sv_builtin_covergroup_options", cg_options);

    for (ISVDBItemBase it : cg_options.getChildren()) {
      log.debug("    Item: " + it.getType() + " " + SVDBItem.getName(it));
      assertNotNull("Item " + SVDBItem.getName(it) + " does not have a location", it.getLocation());
      if (SVDBStmt.isType(it, SVDBItemType.VarDeclStmt)) {
        assertNotNull(
            "Field " + SVDBItem.getName(it) + " does not have a type",
            ((SVDBVarDeclStmt) it).getTypeInfo());
      }
    }
  }
Ejemplo n.º 10
0
 public SVCompletionProposal(
     ISVDBItemBase item, String prefix, int replacementOffset, int replacementLength) {
   fItem = item;
   fPrefix = prefix;
   fReplacement = SVDBItem.getName(item);
   fReplacementOffset = replacementOffset;
   fReplacementLength = replacementLength;
   fType = SVCompletionProposalType.SVObject;
 }
Ejemplo n.º 11
0
 public String getName() {
   if (fCacheItem != null) {
     return fCacheItem.getName();
   } else {
     ISVDBItemBase item = getItem();
     if (item != null) {
       return SVDBItem.getName(item);
     } else {
       return fReplacement;
     }
   }
 }
Ejemplo n.º 12
0
  public synchronized List<ISVDBItemBase> findItems(
      ISVDBChildItem context, String name, boolean stop_on_first_match, SVDBItemType... types) {
    int scope_level = 0;
    List<ISVDBItemBase> ret = new ArrayList<ISVDBItemBase>();
    fLog.debug(
        "--> find: context="
            + ((context != null) ? SVDBItem.getName(context) : "null")
            + " type="
            + ((context != null) ? context.getType() : "null")
            + " name="
            + name);

    fRet = ret;

    // Search up the scope
    while (context != null
        && context.getType() != SVDBItemType.File
        && context instanceof ISVDBChildParent) {
      fLog.debug("Scope " + SVDBItem.getName(context) + " " + context.getType());

      if (context.getType() == SVDBItemType.ClassDecl) {
        SVDBClassDecl cls = (SVDBClassDecl) context;
        if (cls.getParameters() != null) {
          for (SVDBModIfcClassParam p : cls.getParameters()) {
            if (fMatcher.match(p, name)) {
              add(p, Scope.ScopeModIfcClsVars, scope_level);
            }
          }
        }
      } else if (context.getType() == SVDBItemType.Function
          || context.getType() == SVDBItemType.Task) {
        String tf_name = ((ISVDBNamedItem) context).getName();
        int idx;
        if (tf_name != null && (idx = tf_name.indexOf("::")) != -1) {
          // This is an external method. Go find the class that this is part of
          String clsname = tf_name.substring(0, idx);
          SVDBFindByName finder = new SVDBFindByName(fIndexIt);
          List<SVDBDeclCacheItem> cls_l = finder.find(clsname, false, SVDBItemType.ClassDecl);
          ISVDBItemBase cls_i;
          if (cls_l.size() > 0 && (cls_i = cls_l.get(0).getSVDBItem()) != null) {
            SVDBFindByNameInClassHierarchy cls_h_finder =
                new SVDBFindByNameInClassHierarchy(fIndexIt, fMatcher);
            List<ISVDBItemBase> it_l = cls_h_finder.find((SVDBClassDecl) cls_i, name);

            for (ISVDBItemBase it_t : it_l) {
              add(it_t, Scope.ScopeModIfcClsVars, scope_level);
            }
          }
        }
      }

      // First, search the local variables
      for (ISVDBItemBase it : ((ISVDBChildParent) context).getChildren()) {
        fLog.debug("Scope " + SVDBItem.getName(context) + " child " + SVDBItem.getName(it));
        if (it instanceof SVDBVarDeclStmt) {
          for (ISVDBItemBase it_t : ((SVDBVarDeclStmt) it).getChildren()) {
            fLog.debug("  Variable " + SVDBItem.getName(it_t) + " (match " + name + ")");
            if (it_t instanceof ISVDBNamedItem && fMatcher.match((ISVDBNamedItem) it_t, name)) {
              boolean match = (types.length == 0 || it_t.getType().isElemOf(types));

              if (match) {
                fLog.debug("    Matches Variable " + SVDBItem.getName(it_t));
                add(it_t, Scope.ScopeModIfcClsVars, scope_level);

                if (stop_on_first_match) {
                  break;
                }
              }
            }
          }
        } else if (it instanceof SVDBModIfcInst) {
          for (ISVDBItemBase it_t : ((SVDBModIfcInst) it).getChildren()) {
            if (it_t instanceof ISVDBNamedItem && fMatcher.match((ISVDBNamedItem) it_t, name)) {
              boolean match = (types.length == 0);

              for (SVDBItemType t : types) {
                if (it_t.getType() == t) {
                  match = true;
                  break;
                }
              }

              if (match) {
                add(it_t, Scope.ScopeModIfcClsVars, scope_level);

                if (stop_on_first_match) {
                  break;
                }
              }
            }
          }
        } else if (it.getType() == SVDBItemType.TypedefStmt
            && ((SVDBTypedefStmt) it).getTypeInfo().getType() == SVDBItemType.TypeInfoEnum) {
          // Check the enumerators for matches
          SVDBTypeInfoEnum e = (SVDBTypeInfoEnum) ((SVDBTypedefStmt) it).getTypeInfo();
          for (SVDBTypeInfoEnumerator en : e.getEnumerators()) {
            if (fMatcher.match(en, name)) {
              add(en, Scope.ScopeModIfcClsVars, scope_level);
              if (stop_on_first_match) {
                break;
              }
            }
          }
          if (ret.size() > 0 && stop_on_first_match) {
            break;
          }
        } else {
          if (it instanceof ISVDBNamedItem && fMatcher.match((ISVDBNamedItem) it, name)) {
            boolean match = (types.length == 0);

            for (SVDBItemType t : types) {
              if (it.getType() == t) {
                match = true;
                break;
              }
            }

            if (match) {
              add(it, Scope.ScopeModIfcClsVars, scope_level);

              if (stop_on_first_match) {
                break;
              }
            }
          }
        }
      }

      if (ret.size() > 0 && stop_on_first_match) {
        break;
      }

      // Next, search the parameters, if we're in a function/task scope
      if (context.getType().isElemOf(SVDBItemType.Function, SVDBItemType.Task)) {
        for (SVDBParamPortDecl p : ((SVDBTask) context).getParams()) {
          for (ISVDBChildItem pi : p.getChildren()) {
            fLog.debug("check param \"" + SVDBItem.getName(pi) + "\"");
            if (fMatcher.match((ISVDBNamedItem) pi, name)) {
              add(pi, Scope.ScopeLocalVars, scope_level);

              if (stop_on_first_match) {
                break;
              }
            }
          }
          if (ret.size() > 0 && stop_on_first_match) {
            break;
          }
        }
      }

      if (ret.size() > 0 && stop_on_first_match) {
        break;
      }

      // Next, if we check the class parameters if we're in a class scope,
      // or the module ports/parameters if we're in an interface/module scope
      fLog.debug("context type: " + context.getType());
      if (context.getType() == SVDBItemType.ClassDecl) {
        //				SVDBClassDecl cls = (SVDBClassDecl)context;

      } else if (context.getType() == SVDBItemType.ModuleDecl
          || context.getType() == SVDBItemType.InterfaceDecl) {
        List<SVDBParamPortDecl> p_list = ((SVDBModIfcDecl) context).getPorts();

        // Check ports
        for (SVDBParamPortDecl p : p_list) {
          for (ISVDBChildItem c : p.getChildren()) {
            SVDBVarDeclItem pi = (SVDBVarDeclItem) c;
            fLog.debug("  Check port " + pi.getName() + " == " + name);
            if (fMatcher.match((ISVDBNamedItem) pi, name)) {
              add(pi, Scope.ScopeModIfcClsVars, scope_level);

              if (ret.size() > 0 && stop_on_first_match) {
                break;
              }
            }
            if (ret.size() > 0 && stop_on_first_match) {
              break;
            }
          }
        }

        // Check parameters
        List<SVDBModIfcClassParam> param_l = ((SVDBModIfcDecl) context).getParameters();
        if (param_l != null && (ret.size() == 0 || !stop_on_first_match)) {
          for (SVDBModIfcClassParam p : param_l) {
            if (fMatcher.match(p, name)) {
              add(p, Scope.ScopeModIfcClsVars, scope_level);
            }

            if (ret.size() > 0 && stop_on_first_match) {
              break;
            }
          }
        }
      }

      if (ret.size() > 0 && stop_on_first_match) {
        break;
      }

      while ((context = context.getParent()) != null && !(context instanceof ISVDBChildParent)) {
        fLog.debug("SKIP: " + context.getType() + " " + SVDBItem.getName(context));
      }

      fLog.debug("parent: " + ((context != null) ? context.getType() : "NULL"));
      scope_level++;
    }

    fLog.debug(
        "<-- find: context="
            + ((context != null) ? SVDBItem.getName(context) : "null")
            + " name="
            + name);

    return ret;
  }
Ejemplo n.º 13
0
  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());
  }