protected IProject findDestProject() {
    IContainer c = SVFileUtils.getWorkspaceFolder(getOption(SOURCE_FOLDER, ""));

    if (c == null) {
      return null;
    } else if (c instanceof IProject) {
      return (IProject) c;
    } else {
      return c.getProject();
    }
  }
  protected void validate() {
    setErrorMessage(null);
    if (!SVCharacter.isSVIdentifier(getOption(NAME, ""))) {
      setErrorMessage("Invalid class name format");
    }

    IContainer c = SVFileUtils.getWorkspaceFolder(getOption(SOURCE_FOLDER, ""));
    if (c != null) {
      String filename_str = getOption(FILE_NAME, null);
      if (filename_str != null && !filename_str.equals("")) {
        IFile f = c.getFile(new Path(filename_str));
        if (f.exists()) {
          setErrorMessage("File \"" + filename_str + "\" exists");
        }
      }
    } else {
      setErrorMessage("Directory \"" + getOption(SOURCE_FOLDER, "") + "\" does not exist");
    }

    setPageComplete((getErrorMessage() == null));
  }
Exemple #3
0
  private void runTest(String name, String path) {
    BundleUtils utils = new BundleUtils(SVCoreTestsPlugin.getDefault().getBundle());

    File pdir = new File(fTmpDir, path);
    assertTrue(pdir.mkdirs());

    utils.unpackBundleZipToFS("uvmprimer-master.zip", pdir);

    utils.unpackBundleZipToFS("uvm.zip", pdir);

    File filelist = new File(pdir, "filelist.f");

    SVFileUtils.copy(
        "+define+QUESTA\n"
            + "+incdir+./uvm/src\n"
            + "./uvm/src/uvm_pkg.sv\n"
            + "+incdir+./uvmprimer-master/"
            + path
            + "\n"
            + "-F uvmprimer-master/"
            + path
            + "/rtl.f\n"
            + "-F uvmprimer-master/"
            + path
            + "/tb.f\n",
        filelist);

    ISVDBIndex index =
        fIndexRgy.findCreateIndex(
            new NullProgressMonitor(),
            "GENERIC",
            filelist.toString(),
            SVDBArgFileIndexFactory.TYPE,
            null);
    index.loadIndex(new NullProgressMonitor());

    IndexTestUtils.assertNoErrWarn(fLog, index);
  }
Exemple #4
0
  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;
  }
  @Override
  public void matchFound(PatternMatchEvent event) {
    String content = null;
    try {
      content = fConsole.getDocument().get(event.getOffset(), event.getLength());
    } catch (BadLocationException e) {
    }

    if (content == null) {
      return;
    }

    content = content.trim();

    int paren_idx = -1;
    int colon_idx = -1;
    int sp_idx = -1;
    int lineno = -1;

    if (SVFileUtils.isWin()) {
      content = content.replace('\\', '/');

      // Recognize MinGW-style paths: /c/foo/path
      // Convert to Windows-type path: c:/foo/path
      //			if (content.length() >= 3 &&
      //					(content.charAt(0) == '/') &&
      //					(content.charAt(2) == '/')) {
      //				int ch = Character.toLowerCase(content.charAt(1));
      //
      //				if (ch >= 'a' && ch <= 'z') {
      //					content = content.charAt(1) + ":" + content.substring(2);
      //				}
      //			}
    }

    if ((paren_idx = content.indexOf('(')) != -1) {
      int end_idx = paren_idx + 1;

      while (end_idx < content.length() && Character.isDigit(content.charAt(end_idx))) {
        end_idx++;
      }

      String number =
          (end_idx < content.length())
              ? content.substring(paren_idx + 1, end_idx)
              : content.substring(paren_idx + 1);

      content = content.substring(0, paren_idx);

      try {
        lineno = Integer.parseInt(number);
      } catch (NumberFormatException e) {
      }
    } else if ((colon_idx = content.indexOf(':')) != -1) {
      if (colon_idx != 1 || (colon_idx = content.indexOf(':', colon_idx + 1)) != -1) {
        int end_idx = colon_idx + 1;

        while (end_idx < content.length() && Character.isDigit(content.charAt(end_idx))) {
          end_idx++;
        }

        String number =
            (end_idx < content.length())
                ? content.substring(colon_idx + 1, end_idx)
                : content.substring(colon_idx + 1);

        content = content.substring(0, colon_idx);

        try {
          lineno = Integer.parseInt(number);
        } catch (NumberFormatException e) {
        }
      }
    } else if ((sp_idx = content.indexOf(' ')) != -1) {
      // See if there's a trailing number.
      int idx = sp_idx;
      while (idx < content.length() && Character.isWhitespace(content.charAt(idx))) {
        idx++;
      }

      if (idx < content.length() && content.charAt(idx) >= '0' && content.charAt(idx) <= '9') {
        String number = content.substring(idx).trim();
        content = content.substring(0, sp_idx);
        try {
          lineno = Integer.parseInt(number);
        } catch (NumberFormatException e) {
          e.printStackTrace();
        }
      }
    }

    String path = content;
    if (fMgr != null) {
      path = SVFileUtils.resolvePath(path, fMgr.getWorkingDirectory(), fFS, true);
    }

    IFile file = SVFileUtils.findWorkspaceFile(path);
    File efile = SVFileUtils.getFile(content);

    // Eclipse sometimes returns a file (that doesn't exist) for
    // a directory path. We only want to hyperlink 'real' files.
    if (file != null && file.exists()) {
      FileLink link = new FileLink(file, null, -1, -1, lineno);
      try {
        fConsole.addHyperlink(link, event.getOffset(), content.length());
      } catch (BadLocationException e) {
      }
    } else if (efile != null && efile.isFile()) {
      IFileStore fs = EFS.getLocalFileSystem().getStore(new Path(efile.getAbsolutePath()));
      ExternalPathHyperlink link = new ExternalPathHyperlink(fs, null, -1, -1, lineno);
      try {
        fConsole.addHyperlink(link, event.getOffset(), content.length());
      } catch (BadLocationException e) {
      }
    }
  }