|
Lines 30-35
Link Here
|
| 30 |
import org.eclipse.cdt.core.dom.ast.IMacroBinding; |
30 |
import org.eclipse.cdt.core.dom.ast.IMacroBinding; |
| 31 |
import org.eclipse.cdt.core.dom.ast.IParameter; |
31 |
import org.eclipse.cdt.core.dom.ast.IParameter; |
| 32 |
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective; |
32 |
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective; |
|
|
33 |
import org.eclipse.cdt.core.index.IIndexFile; |
| 33 |
import org.eclipse.cdt.core.index.IIndexFileLocation; |
34 |
import org.eclipse.cdt.core.index.IIndexFileLocation; |
| 34 |
import org.eclipse.cdt.core.index.IIndexInclude; |
35 |
import org.eclipse.cdt.core.index.IIndexInclude; |
| 35 |
import org.eclipse.cdt.core.index.IIndexLocationConverter; |
36 |
import org.eclipse.cdt.core.index.IIndexLocationConverter; |
|
Lines 42-47
Link Here
|
| 42 |
import org.eclipse.cdt.internal.core.index.IndexFileLocation; |
43 |
import org.eclipse.cdt.internal.core.index.IndexFileLocation; |
| 43 |
import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation; |
44 |
import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation; |
| 44 |
import org.eclipse.cdt.internal.core.pdom.PDOM; |
45 |
import org.eclipse.cdt.internal.core.pdom.PDOM; |
|
|
46 |
import org.eclipse.cdt.internal.core.pdom.YieldableIndexLock; |
| 45 |
import org.eclipse.cdt.internal.core.pdom.db.BTree; |
47 |
import org.eclipse.cdt.internal.core.pdom.db.BTree; |
| 46 |
import org.eclipse.cdt.internal.core.pdom.db.Database; |
48 |
import org.eclipse.cdt.internal.core.pdom.db.Database; |
| 47 |
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator; |
49 |
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator; |
|
Lines 136-144
Link Here
|
| 136 |
} |
138 |
} |
| 137 |
|
139 |
|
| 138 |
/** |
140 |
/** |
| 139 |
* Directly changes this record's internal location string. The format |
141 |
* Transfers names, macros and includes from another file to this one and deletes the other file. |
| 140 |
* of this string is unspecified in general and is determined by the |
142 |
* @param sourceFile the file to transfer the local bindings from. |
| 141 |
* associated IIndexLocationConverter |
143 |
* @throws CoreException |
|
|
144 |
*/ |
| 145 |
public void replaceContentsFrom(PDOMFile sourceFile) throws CoreException { |
| 146 |
ICPPUsingDirective[] directives= getUsingDirectives(); |
| 147 |
for (ICPPUsingDirective ud : directives) { |
| 148 |
if (ud instanceof IPDOMNode) { |
| 149 |
((IPDOMNode) ud).delete(null); |
| 150 |
} |
| 151 |
} |
| 152 |
setFirstUsingDirectiveRec(sourceFile.getLastUsingDirectiveRec()); |
| 153 |
|
| 154 |
// Replace the includes |
| 155 |
PDOMInclude include = getFirstInclude(); |
| 156 |
while (include != null) { |
| 157 |
PDOMInclude nextInclude = include.getNextInIncludes(); |
| 158 |
IIndexFile includedBy = include.getIncludedBy(); |
| 159 |
if (includedBy.equals(this)) { |
| 160 |
include.delete(); |
| 161 |
} |
| 162 |
include = nextInclude; |
| 163 |
} |
| 164 |
include = sourceFile.getFirstInclude(); |
| 165 |
setFirstInclude(include); |
| 166 |
while (include != null) { |
| 167 |
IIndexFile includedBy = include.getIncludedBy(); |
| 168 |
if (includedBy.equals(sourceFile)) { |
| 169 |
include.setIncludedBy(this); |
| 170 |
} |
| 171 |
include = include.getNextInIncludes(); |
| 172 |
} |
| 173 |
|
| 174 |
include = sourceFile.getFirstIncludedBy(); |
| 175 |
setFirstIncludedBy(include); |
| 176 |
while (include != null) { |
| 177 |
include.setIncludes(this); |
| 178 |
include = include.getNextInIncludedBy(); |
| 179 |
} |
| 180 |
|
| 181 |
// Replace all the macros in this file. |
| 182 |
PDOMLinkage linkage= getLinkage(); |
| 183 |
PDOMMacro macro = getFirstMacro(); |
| 184 |
while (macro != null) { |
| 185 |
PDOMMacro nextMacro = macro.getNextMacro(); |
| 186 |
macro.delete(linkage); |
| 187 |
macro = nextMacro; |
| 188 |
} |
| 189 |
setFirstMacro(sourceFile.getFirstMacro()); |
| 190 |
|
| 191 |
// Replace all macro references |
| 192 |
ArrayList<PDOMMacroReferenceName> mrefs= new ArrayList<PDOMMacroReferenceName>(); |
| 193 |
PDOMMacroReferenceName mref = getFirstMacroReference(); |
| 194 |
while (mref != null) { |
| 195 |
mrefs.add(mref); |
| 196 |
mref= mref.getNextInFile(); |
| 197 |
} |
| 198 |
for (PDOMMacroReferenceName m : mrefs) { |
| 199 |
m.delete(); |
| 200 |
} |
| 201 |
setFirstMacroReference(sourceFile.getFirstMacroReference()); |
| 202 |
|
| 203 |
// Replace all the names in this file |
| 204 |
ArrayList<PDOMName> names= new ArrayList<PDOMName>(); |
| 205 |
PDOMName name = getFirstName(); |
| 206 |
while (name != null) { |
| 207 |
names.add(name); |
| 208 |
linkage.onDeleteName(name); |
| 209 |
name= name.getNextInFile(); |
| 210 |
} |
| 211 |
for (Iterator<PDOMName> iterator = names.iterator(); iterator.hasNext();) { |
| 212 |
name = iterator.next(); |
| 213 |
name.delete(); |
| 214 |
} |
| 215 |
setFirstName(sourceFile.getFirstName()); |
| 216 |
|
| 217 |
setTimestamp(sourceFile.getTimestamp()); |
| 218 |
setScannerConfigurationHashcode(sourceFile.getScannerConfigurationHashcode()); |
| 219 |
|
| 220 |
sourceFile.delete(); |
| 221 |
} |
| 222 |
|
| 223 |
/** |
| 224 |
* This method should not be called on PDOMFile objects that are referenced by the file index. |
| 225 |
* @param location a new location |
| 226 |
* @throws CoreException |
| 227 |
*/ |
| 228 |
public void setLocation(IIndexFileLocation location) throws CoreException { |
| 229 |
String locationString = fLinkage.getPDOM().getLocationConverter().toInternalFormat(location); |
| 230 |
if (locationString == null) |
| 231 |
throw new CoreException(CCorePlugin.createStatus(Messages.getString("PDOMFile.toInternalProblem") + //$NON-NLS-1$ |
| 232 |
location.getURI())); |
| 233 |
setInternalLocation(locationString); |
| 234 |
} |
| 235 |
|
| 236 |
/** |
| 237 |
* Directly changes this record's internal location string. The format of this string is unspecified |
| 238 |
* in general and is determined by the associated IIndexLocationConverter. |
| 239 |
* This method should not be called on PDOMFile objects that are referenced by the file index. |
| 142 |
* @param internalLocation |
240 |
* @param internalLocation |
| 143 |
* @throws CoreException |
241 |
* @throws CoreException |
| 144 |
*/ |
242 |
*/ |
|
Lines 260-274
Link Here
|
| 260 |
return fLinkage; |
358 |
return fLinkage; |
| 261 |
} |
359 |
} |
| 262 |
|
360 |
|
| 263 |
public void addNames(IASTName[][] names) throws CoreException { |
361 |
public void addNames(IASTName[][] names, YieldableIndexLock lock) throws CoreException, InterruptedException { |
| 264 |
assert getFirstName() == null; |
362 |
assert getFirstName() == null; |
| 265 |
assert getFirstMacroReference() == null; |
363 |
assert getFirstMacroReference() == null; |
| 266 |
final PDOMLinkage linkage= getLinkage(); |
364 |
final PDOMLinkage linkage= getLinkage(); |
| 267 |
HashMap<IASTName, PDOMName> nameCache= new HashMap<IASTName, PDOMName>(); |
365 |
HashMap<IASTName, PDOMName> nameCache= new HashMap<IASTName, PDOMName>(); |
| 268 |
PDOMName lastName= null; |
366 |
PDOMName lastName= null; |
| 269 |
PDOMMacroReferenceName lastMacroName= null; |
367 |
PDOMMacroReferenceName lastMacroName= null; |
|
|
368 |
int counter = 0; |
| 270 |
for (IASTName[] name : names) { |
369 |
for (IASTName[] name : names) { |
| 271 |
if (name[0] != null) { |
370 |
if (name[0] != null) { |
|
|
371 |
if (lock != null && ++counter >= 1000) { |
| 372 |
counter = 0; |
| 373 |
lock.yield(); |
| 374 |
} |
| 272 |
PDOMName caller= nameCache.get(name[1]); |
375 |
PDOMName caller= nameCache.get(name[1]); |
| 273 |
IIndexFragmentName fname= createPDOMName(linkage, name[0], caller); |
376 |
IIndexFragmentName fname= createPDOMName(linkage, name[0], caller); |
| 274 |
if (fname instanceof PDOMName) { |
377 |
if (fname instanceof PDOMName) { |
|
Lines 344-350
Link Here
|
| 344 |
include.delete(); |
447 |
include.delete(); |
| 345 |
include = nextInclude; |
448 |
include = nextInclude; |
| 346 |
} |
449 |
} |
| 347 |
setFirstInclude(include); |
450 |
setFirstInclude(null); |
| 348 |
|
451 |
|
| 349 |
// Delete all the macros in this file |
452 |
// Delete all the macros in this file |
| 350 |
PDOMLinkage linkage= getLinkage(); |
453 |
PDOMLinkage linkage= getLinkage(); |
|
Lines 385-390
Link Here
|
| 385 |
setTimestamp(-1); |
488 |
setTimestamp(-1); |
| 386 |
} |
489 |
} |
| 387 |
|
490 |
|
|
|
491 |
private void delete() throws CoreException { |
| 492 |
fLinkage.getDB().free(record); |
| 493 |
} |
| 494 |
|
| 388 |
public void addIncludesTo(IncludeInformation[] includeInfos) throws CoreException { |
495 |
public void addIncludesTo(IncludeInformation[] includeInfos) throws CoreException { |
| 389 |
assert getFirstInclude() == null; |
496 |
assert getFirstInclude() == null; |
| 390 |
|
497 |
|