@Override
  public void addFileContent(
      IIndexFragmentFile sourceFile,
      IncludeInformation[] includes,
      IASTPreprocessorStatement[] macros,
      IASTName[][] names,
      ASTFilePathResolver pathResolver,
      YieldableIndexLock lock)
      throws CoreException, InterruptedException {
    assert sourceFile.getIndexFragment() == this;

    PDOMFile pdomFile = (PDOMFile) sourceFile;
    pdomFile.addMacros(macros);
    final ASTFilePathResolver origResolver = fPathResolver;
    fPathResolver = pathResolver;
    try {
      pdomFile.addNames(names, lock);
    } finally {
      fPathResolver = origResolver;
    }
    // Includes expose the temporary file in the index, we must not yield the lock beyond this
    // point.
    pdomFile.addIncludesTo(includes);

    final IIndexFileLocation location = pdomFile.getLocation();
    if (location != null) {
      fEvent.fClearedFiles.remove(location);
      fEvent.fFilesWritten.add(location);
    }
  }
Beispiel #2
0
 @Override
 public boolean equals(Object obj) {
   if (obj == this) return true;
   if (obj instanceof PDOMFile) {
     PDOMFile other = (PDOMFile) obj;
     return fLinkage.getPDOM().equals(other.getLinkage().getPDOM()) && record == other.record;
   }
   return false;
 }
Beispiel #3
0
  /**
   * Transfers names, macros and includes from another file to this one and deletes the other file.
   *
   * @param sourceFile the file to transfer the local bindings from.
   * @throws CoreException
   */
  public void replaceContentsFrom(PDOMFile sourceFile) throws CoreException {
    // Delete current content
    clear();

    // Link in the using directives
    setLastUsingDirective(sourceFile.getLastUsingDirectiveRec());

    // Link in the includes, replace the owner.
    PDOMInclude include = sourceFile.getFirstInclude();
    setFirstInclude(include);
    for (; include != null; include = include.getNextInIncludes()) {
      include.setIncludedBy(this);
    }

    // In the unexpected case that there is an included by relation, append it.
    transferIncluders(sourceFile);

    // Link in the macros.
    PDOMMacro macro = sourceFile.getFirstMacro();
    setFirstMacro(macro);
    for (; macro != null; macro = macro.getNextMacro()) {
      macro.setFile(this);
    }

    // Link in macro references
    PDOMMacroReferenceName mref = sourceFile.getFirstMacroReference();
    setFirstMacroReference(mref);
    for (; mref != null; mref = mref.getNextInFile()) {
      mref.setFile(this);
    }

    // Replace all the names in this file
    PDOMName name = sourceFile.getFirstName();
    setFirstName(name);
    for (; name != null; name = name.getNextInFile()) {
      name.setFile(this);
    }

    setTimestamp(sourceFile.getTimestamp());
    setSourceReadTime(sourceFile.getSourceReadTime());
    setSizeAndEncodingHashcode(sourceFile.getSizeAndEncodingHashcode());
    setContentsHash(sourceFile.getContentsHash());

    // Transfer the flags.
    Database db = fLinkage.getDB();
    db.putByte(record + FLAGS, db.getByte(sourceFile.record + FLAGS));

    // Transfer the replacement header.
    db.putRecPtr(record + REPLACEMENT_HEADER, db.getRecPtr(sourceFile.record + REPLACEMENT_HEADER));
    db.putRecPtr(sourceFile.record + REPLACEMENT_HEADER, 0);

    // Delete the source file
    sourceFile.delete();
  }
 @Override
 public void clearUncommittedFile() throws CoreException {
   if (uncommittedFile != null) {
     try {
       uncommittedFile.clear();
       uncommittedFile.delete();
     } finally {
       uncommittedFile = null;
       uncommittedKey = null;
       fileBeingUpdated = null;
     }
   }
 }
 @Override
 public boolean hasLastingDefinition(PDOMBinding binding) throws CoreException {
   if (fileBeingUpdated == null) {
     return binding.hasDefinition();
   }
   // Definitions in fileBeingUpdated will soon go away, so look for a definition elsewhere.
   for (PDOMName name = binding.getFirstDefinition();
       name != null;
       name = name.getNextInBinding()) {
     if (!fileBeingUpdated.getPDOM().equals(name.getPDOM())
         || fileBeingUpdated.getRecord() != name.getFileRecord()) {
       return true;
     }
   }
   return false;
 }
Beispiel #6
0
  @Override
  public void transferContext(IIndexFragmentFile sourceFile) throws CoreException {
    PDOMFile source = (PDOMFile) sourceFile;
    PDOMInclude include = source.getFirstIncludedBy();
    if (include != null) {
      // Detach the include
      final PDOMInclude next = include.getNextInIncludedBy();
      include.setNextInIncludedBy(null);
      source.setFirstIncludedBy(next);
      if (next != null) next.setPrevInIncludedBy(null);

      // Adjust the include
      include.setIncludes(this);

      // Insert the include
      addIncludedBy(include, false);
    }
  }
Beispiel #7
0
  public void addIncludesTo(IncludeInformation[] includeInfos) throws CoreException {
    assert getFirstInclude() == null;

    PDOMInclude lastInclude = null;
    for (final IncludeInformation info : includeInfos) {
      final PDOMFile targetFile = (PDOMFile) info.fTargetFile;

      PDOMInclude pdomInclude = new PDOMInclude(fLinkage, info.fStatement, this, targetFile);
      assert targetFile == null || targetFile.getIndexFragment() instanceof IWritableIndexFragment;
      if (targetFile != null) {
        targetFile.addIncludedBy(pdomInclude, info.fIsContext);
      }
      if (lastInclude == null) {
        setFirstInclude(pdomInclude);
      } else {
        lastInclude.setNextInIncludes(pdomInclude);
      }
      lastInclude = pdomInclude;
    }
  }
Beispiel #8
0
 @Override
 public void transferIncluders(IIndexFragmentFile sourceFile) throws CoreException {
   PDOMFile source = (PDOMFile) sourceFile;
   PDOMInclude include = source.getFirstIncludedBy();
   if (include != null) {
     // Detach the includes
     source.setFirstIncludedBy(null);
     // Adjust the includes
     for (PDOMInclude i = include; i != null; i = i.getNextInIncludedBy()) {
       i.setIncludes(this);
     }
     // Append the includes
     PDOMInclude last = getFirstIncludedBy();
     if (last == null) {
       setFirstIncludedBy(include);
     } else {
       for (PDOMInclude i = last; i != null; i = i.getNextInIncludedBy()) {
         last = i;
       }
       last.setNextInIncludedBy(include);
       include.setPrevInIncludedBy(last);
     }
   }
 }
  public PDOMMacroReferenceName(
      PDOMLinkage linkage, IASTName name, PDOMFile file, PDOMMacroContainer container)
      throws CoreException {
    this.linkage = linkage;
    Database db = linkage.getDB();
    record = db.malloc(RECORD_SIZE);

    db.putRecPtr(record + CONTAINER_REC_OFFSET, container.getRecord());
    db.putRecPtr(record + FILE_REC_OFFSET, file.getRecord());

    // Record our location in the file
    IASTFileLocation fileloc = name.getFileLocation();
    db.putInt(record + NODE_OFFSET_OFFSET, fileloc.getNodeOffset());
    db.putShort(record + NODE_LENGTH_OFFSET, (short) fileloc.getNodeLength());
    container.addReference(this);
  }
  @Override
  public void clearFile(IIndexFragmentFile file) throws CoreException {
    assert file.getIndexFragment() == this;
    IIndexFileLocation location = file.getLocation();
    PDOMFile pdomFile = (PDOMFile) file;
    pdomFile.clear();
    IIndexInclude include = pdomFile.getParsedInContext();
    if (include != null) {
      PDOMFile includedBy = (PDOMFile) include.getIncludedBy();
      if (includedBy.getTimestamp() > 0)
        getIndexOfFilesWithUnresolvedIncludes().insert(includedBy.getRecord());
    }

    fEvent.fClearedFiles.add(location);
  }
  /**
   * Uses the specified location converter to update each internal representation of a file
   * location. The file index is rebuilt with the new representations. Individual PDOMFile records
   * are unmoved so as to maintain referential integrity with other PDOM records.
   *
   * <p><b>A write-lock must be obtained before calling this method</b>
   *
   * @param newConverter the converter to use to update internal file representations
   * @throws CoreException
   */
  public void rewriteLocations(final IIndexLocationConverter newConverter) throws CoreException {
    final List<PDOMFile> pdomfiles = new ArrayList<PDOMFile>();
    getFileIndex()
        .accept(
            new IBTreeVisitor() {
              @Override
              public int compare(long record) throws CoreException {
                return 0;
              }

              @Override
              public boolean visit(long record) throws CoreException {
                PDOMFile file = PDOMFile.recreateFile(WritablePDOM.this, record);
                pdomfiles.add(file);
                return true;
              }
            });

    clearFileIndex();
    final List<PDOMFile> notConverted = new ArrayList<PDOMFile>();
    for (PDOMFile file : pdomfiles) {
      String internalFormat = newConverter.toInternalFormat(file.getLocation());
      if (internalFormat != null) {
        file.setInternalLocation(internalFormat);
        getFileIndex().insert(file.getRecord());
      } else {
        notConverted.add(file);
      }
    }

    // remove content where converter returns null
    for (PDOMFile file : notConverted) {
      file.convertIncludersToUnresolved();
      file.clear();
    }
  }
 void setFile(PDOMFile file) throws CoreException {
   linkage.getDB().putRecPtr(record + FILE_REC_OFFSET, file != null ? file.getRecord() : 0);
 }
  @Override
  public IIndexFragmentFile commitUncommittedFile() throws CoreException {
    if (uncommittedFile == null) return null;

    int defectiveStateChange = uncommittedFile.getTimestamp() == 0 ? 1 : 0;
    int unresolvedIncludeStateChange = uncommittedFile.hasUnresolvedInclude() ? 1 : 0;

    PDOMFile file;
    if (fileBeingUpdated == null) {
      // New file, insert it into the index.
      file = uncommittedFile;
      getFileIndex().insert(file.getRecord());
    } else {
      // Existing file.
      if (fileBeingUpdated.getTimestamp() == 0) defectiveStateChange -= 1;
      if (fileBeingUpdated.hasUnresolvedInclude()) unresolvedIncludeStateChange -= 1;
      fileBeingUpdated.replaceContentsFrom(uncommittedFile);
      file = fileBeingUpdated;
      fileBeingUpdated = null;
    }
    if (defectiveStateChange > 0) {
      getIndexOfDefectiveFiles().insert(file.getRecord());
    } else if (defectiveStateChange < 0) {
      getIndexOfDefectiveFiles().delete(file.getRecord());
    }
    if (unresolvedIncludeStateChange > 0) {
      getIndexOfFilesWithUnresolvedIncludes().insert(file.getRecord());
    } else if (unresolvedIncludeStateChange < 0) {
      getIndexOfFilesWithUnresolvedIncludes().delete(file.getRecord());
    }

    fEvent.fFilesWritten.add(uncommittedKey.getLocation());
    uncommittedFile = null;
    uncommittedKey = null;
    return file;
  }
 @Override
 protected boolean isCommitted(PDOMMacroReferenceName name) throws CoreException {
   return uncommittedFile == null
       || !uncommittedFile.getPDOM().equals(name.getPDOM())
       || uncommittedFile.getRecord() != name.getFileRecord();
 }