예제 #1
0
  public void clear() throws CoreException {
    ICPPUsingDirective[] directives = getUsingDirectives();
    for (ICPPUsingDirective ud : directives) {
      if (ud instanceof IPDOMNode) {
        ((IPDOMNode) ud).delete(null);
      }
    }
    setLastUsingDirective(0);

    // Remove the includes
    PDOMInclude include = getFirstInclude();
    while (include != null) {
      PDOMInclude nextInclude = include.getNextInIncludes();
      //			if (contextsRemoved != null && include.getPrevInIncludedByRecord() == 0) {
      //				contextsRemoved.add(include.getIncludesLocation());
      //			}
      include.delete();
      include = nextInclude;
    }
    setFirstInclude(null);

    // Delete all the macros in this file
    PDOMLinkage linkage = getLinkage();
    PDOMMacro macro = getFirstMacro();
    while (macro != null) {
      PDOMMacro nextMacro = macro.getNextMacro();
      macro.delete(linkage);
      macro = nextMacro;
    }
    setFirstMacro(null);

    // Delete all the names in this file
    ArrayList<PDOMName> names = new ArrayList<PDOMName>();
    PDOMName name = getFirstName();
    while (name != null) {
      names.add(name);
      linkage.onDeleteName(name);
      name = name.getNextInFile();
    }
    for (Iterator<PDOMName> iterator = names.iterator(); iterator.hasNext(); ) {
      name = iterator.next();
      name.delete();
    }
    setFirstName(null);

    // Delete all macro references
    ArrayList<PDOMMacroReferenceName> mrefs = new ArrayList<PDOMMacroReferenceName>();
    PDOMMacroReferenceName mref = getFirstMacroReference();
    while (mref != null) {
      mrefs.add(mref);
      mref = mref.getNextInFile();
    }
    for (PDOMMacroReferenceName m : mrefs) {
      m.delete();
    }
    setFirstMacroReference(null);
    setSourceReadTime(0);
    setTimestamp(-1);
  }
예제 #2
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();
  }
  public void delete() throws CoreException {
    // Delete from the binding chain
    PDOMMacroReferenceName prevName = getPrevInContainer();
    PDOMMacroReferenceName nextName = getNextInContainer();
    if (prevName != null) {
      prevName.setNextInContainer(nextName);
    } else {
      getContainer().setFirstReference(nextName);
    }

    if (nextName != null) nextName.setPrevInContainer(prevName);

    // Delete our record
    linkage.getDB().free(record);
  }
예제 #4
0
 @Override
 public IIndexName[] findNames(int offset, int length) throws CoreException {
   ArrayList<IIndexName> result = new ArrayList<IIndexName>();
   for (PDOMName name = getFirstName(); name != null; name = name.getNextInFile()) {
     int nameOffset = name.getNodeOffset();
     if (nameOffset >= offset) {
       if (nameOffset + name.getNodeLength() <= offset + length) {
         result.add(name);
       } else if (name.isReference()) {
         // Names are ordered, but callers are inserted before
         // their references.
         break;
       }
     }
   }
   for (PDOMMacro macro = getFirstMacro(); macro != null; macro = macro.getNextMacro()) {
     int nameOffset = macro.getNodeOffset();
     if (nameOffset >= offset) {
       if (nameOffset + macro.getNodeLength() <= offset + length) {
         IIndexFragmentName name = macro.getDefinition();
         if (name != null) {
           result.add(name);
         }
       } else {
         break;
       }
     }
   }
   for (PDOMMacroReferenceName name = getFirstMacroReference();
       name != null;
       name = name.getNextInFile()) {
     int nameOffset = name.getNodeOffset();
     if (nameOffset >= offset) {
       if (nameOffset + name.getNodeLength() <= offset + length) {
         result.add(name);
       } else {
         break;
       }
     }
   }
   return result.toArray(new IIndexName[result.size()]);
 }
예제 #5
0
 public void addNames(IASTName[][] names, YieldableIndexLock lock)
     throws CoreException, InterruptedException {
   assert getFirstName() == null;
   assert getFirstMacroReference() == null;
   final PDOMLinkage linkage = getLinkage();
   HashMap<IASTName, PDOMName> nameCache = new HashMap<IASTName, PDOMName>();
   PDOMName lastName = null;
   PDOMMacroReferenceName lastMacroName = null;
   for (IASTName[] name : names) {
     if (name[0] != null) {
       if (lock != null) {
         lock.yield();
       }
       PDOMName caller = nameCache.get(name[1]);
       IIndexFragmentName fname = createPDOMName(linkage, name[0], caller);
       if (fname instanceof PDOMName) {
         PDOMName pdomName = (PDOMName) fname;
         nameCache.put(name[0], pdomName);
         if (lastName == null) {
           setFirstName(pdomName);
         } else {
           lastName.setNextInFile(pdomName);
         }
         lastName = pdomName;
       } else if (fname instanceof PDOMMacroReferenceName) {
         PDOMMacroReferenceName macroName = (PDOMMacroReferenceName) fname;
         if (lastMacroName == null) {
           setFirstMacroReference(macroName);
         } else {
           lastMacroName.setNextInFile(macroName);
         }
         lastMacroName = macroName;
       }
     }
   }
 }
예제 #6
0
 private void setFirstMacroReference(PDOMMacroReferenceName firstName) throws CoreException {
   long namerec = firstName != null ? firstName.getRecord() : 0;
   fLinkage.getDB().putRecPtr(record + FIRST_MACRO_REFERENCE, namerec);
 }
 private void setNameField(int offset, PDOMMacroReferenceName name) throws CoreException {
   long namerec = name != null ? name.getRecord() : 0;
   setRecField(offset, namerec);
 }
예제 #8
0
 @Override
 protected boolean isCommitted(PDOMMacroReferenceName name) throws CoreException {
   return uncommittedFile == null
       || !uncommittedFile.getPDOM().equals(name.getPDOM())
       || uncommittedFile.getRecord() != name.getFileRecord();
 }