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); }
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); }
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()); }
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()); }
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()); } } }
public SVDBFile parse(SVDBFile file, List<SVDBMarker> markers) throws SVParseException { fMarkers = markers; if (fDebugEn) { fLog.debug("--> parse() " + fFilename); } while (fLexer.peek() != null) { if (fLexer.isOption()) { // Recognize the special-case -SVE_SET_CWD option if (fLexer.peek().equals("-SVE_SET_CWD")) { // Reset the working directory fLexer.consumeToken(); fBaseLocation = fLexer.readPath(); fResolvedBaseLocation = fBaseLocation; } else { SVArgFileToken tok = fLexer.consumeToken(); OptionType type = fOptionProviders.getOptionType(tok.getImage()); int arg_count = fOptionProviders.optionArgCount(tok.getImage()); if (fDebugEn) { fLog.debug( " isOption: " + tok.getImage() + " type=" + type + " arg_count=" + arg_count); } // Determine what type of option this is switch (type) { case Unrecognized: { // Treat plus-args as zero-option switches // Treat dash-args are one-option switches if (tok.getImage().startsWith("-")) { fLexer.eatToken(); } } break; // Recognized, but ignored, option case Ignored: { // TODO: Consume known options for (int i = 0; i < arg_count; i++) { fLexer.eatToken(); } } break; case Incdir: { List<String> inc_path_l = null; SVDBLocation loc = fLexer.getStartLocation(); if (arg_count > 0) { // include path is the argument String path = fLexer.readPath(); inc_path_l = fOptionProviders.getIncPaths(tok.getImage(), path); } else { inc_path_l = fOptionProviders.getIncPaths(tok.getImage(), tok.getOptionVal()); } if (inc_path_l != null) { for (String path : inc_path_l) { path = SVFileUtils.resolvePath(path, fResolvedBaseLocation, fFSProvider, true); if (!fFSProvider.fileExists(path)) { error( tok.getStartLocation(), "Include path \"" + path + "\" does not exist. " + "Resolved relative to \"" + fResolvedBaseLocation + "\""); } SVDBArgFileIncDirStmt stmt = new SVDBArgFileIncDirStmt(); stmt.setLocation(loc); stmt.setIncludePath(path); file.addChildItem(stmt); } } else { error(tok.getStartLocation(), "No include-file path provided"); } } break; case Define: { SVDBArgFileDefineStmt stmt = new SVDBArgFileDefineStmt(); stmt.setLocation(fLexer.getStartLocation()); Tuple<String, String> def; if (arg_count > 0) { // Define is the argument def = fOptionProviders.getDefValue(tok.getImage(), fLexer.readPath()); } else { String val = (tok.getOptionVal() != null) ? tok.getOptionVal() : ""; def = fOptionProviders.getDefValue(tok.getImage(), val); } stmt.setKey(def.first()); stmt.setValue(def.second()); file.addChildItem(stmt); } break; case ArgFileInc: case ArgFileRootInc: { SVDBArgFileIncFileStmt stmt = new SVDBArgFileIncFileStmt(); stmt.setLocation(tok.getStartLocation()); List<String> incs; // Flag the root-include status stmt.setRootInclude((type == OptionType.ArgFileRootInc)); if (arg_count > 0) { incs = fOptionProviders.getArgFilePaths(tok.getImage(), fLexer.readPath()); } else { incs = fOptionProviders.getArgFilePaths(tok.getImage(), tok.getOptionVal()); } if (incs == null || incs.size() == 0) { error(tok.getStartLocation(), "No argument-file path provided"); } else { String inc = incs.get(0); if (inc != null) { String path = SVFileUtils.resolvePath( incs.get(0), fResolvedBaseLocation, fFSProvider, true); if (!fFSProvider.fileExists(path)) { error( tok.getStartLocation(), "Argument-file path \"" + path + "\" does not exist; " + "Resolved relative to \"" + fResolvedBaseLocation + "\""); } stmt.setPath(path); } else { error(tok.getStartLocation(), "No argument-file path provided"); stmt.setPath(""); } file.addChildItem(stmt); } } break; case MFCU: { SVDBArgFileMfcuStmt stmt = new SVDBArgFileMfcuStmt(); stmt.setLocation(fLexer.getStartLocation()); file.addChildItem(stmt); } break; case SrcLibPath: { SVDBArgFileSrcLibPathStmt stmt = new SVDBArgFileSrcLibPathStmt(); stmt.setLocation(fLexer.getStartLocation()); String path = fLexer.readPath(); path = SVFileUtils.resolvePath(path, fResolvedBaseLocation, fFSProvider, true); if (!fFSProvider.isDir(path)) { error( tok.getStartLocation(), "Source library path \"" + path + "\" does not exist; " + "Resolved relative to \"" + fResolvedBaseLocation + "\""); } stmt.setSrcLibPath(path); file.addChildItem(stmt); } break; default: error(tok.getStartLocation(), "Unrecognized option type " + type); break; } } } else { // It's a path SVDBArgFilePathStmt p = new SVDBArgFilePathStmt(); SVDBLocation loc = fLexer.getStartLocation(); p.setLocation(loc); String path = fLexer.eatToken(); file.addChildItem(p); // Try to resolve path path = SVFileUtils.resolvePath(path, fResolvedBaseLocation, fFSProvider, true); p.setPath(path); if (!fFSProvider.fileExists(path)) { error( loc, "Path \"" + path + "\" does not exist; " + "Resolved relative to \"" + fResolvedBaseLocation + "\""); } } } fLog.debug("<-- parse() " + fFilename); return file; }