|
Lines 9-14
Link Here
|
| 9 |
* QNX - Initial API and implementation |
9 |
* QNX - Initial API and implementation |
| 10 |
* Markus Schorn (Wind River Systems) |
10 |
* Markus Schorn (Wind River Systems) |
| 11 |
* Andrew Ferguson (Symbian) |
11 |
* Andrew Ferguson (Symbian) |
|
|
12 |
* Sergey Prigogin (Google) |
| 12 |
*******************************************************************************/ |
13 |
*******************************************************************************/ |
| 13 |
package org.eclipse.cdt.internal.core.pdom.dom; |
14 |
package org.eclipse.cdt.internal.core.pdom.dom; |
| 14 |
|
15 |
|
|
Lines 30-35
Link Here
|
| 30 |
import org.eclipse.cdt.core.dom.ast.IMacroBinding; |
31 |
import org.eclipse.cdt.core.dom.ast.IMacroBinding; |
| 31 |
import org.eclipse.cdt.core.dom.ast.IParameter; |
32 |
import org.eclipse.cdt.core.dom.ast.IParameter; |
| 32 |
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective; |
33 |
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective; |
|
|
34 |
import org.eclipse.cdt.core.index.IIndexFile; |
| 33 |
import org.eclipse.cdt.core.index.IIndexFileLocation; |
35 |
import org.eclipse.cdt.core.index.IIndexFileLocation; |
| 34 |
import org.eclipse.cdt.core.index.IIndexInclude; |
36 |
import org.eclipse.cdt.core.index.IIndexInclude; |
| 35 |
import org.eclipse.cdt.core.index.IIndexLocationConverter; |
37 |
import org.eclipse.cdt.core.index.IIndexLocationConverter; |
|
Lines 42-47
Link Here
|
| 42 |
import org.eclipse.cdt.internal.core.index.IndexFileLocation; |
44 |
import org.eclipse.cdt.internal.core.index.IndexFileLocation; |
| 43 |
import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation; |
45 |
import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation; |
| 44 |
import org.eclipse.cdt.internal.core.pdom.PDOM; |
46 |
import org.eclipse.cdt.internal.core.pdom.PDOM; |
|
|
47 |
import org.eclipse.cdt.internal.core.pdom.YieldableIndexLock; |
| 45 |
import org.eclipse.cdt.internal.core.pdom.db.BTree; |
48 |
import org.eclipse.cdt.internal.core.pdom.db.BTree; |
| 46 |
import org.eclipse.cdt.internal.core.pdom.db.Database; |
49 |
import org.eclipse.cdt.internal.core.pdom.db.Database; |
| 47 |
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator; |
50 |
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator; |
|
Lines 119-124
Link Here
|
| 119 |
return record; |
122 |
return record; |
| 120 |
} |
123 |
} |
| 121 |
|
124 |
|
|
|
125 |
public PDOM getPDOM() { |
| 126 |
return fLinkage.getPDOM(); |
| 127 |
} |
| 128 |
|
| 122 |
@Override |
129 |
@Override |
| 123 |
public boolean equals(Object obj) { |
130 |
public boolean equals(Object obj) { |
| 124 |
if (obj == this) |
131 |
if (obj == this) |
|
Lines 136-144
Link Here
|
| 136 |
} |
143 |
} |
| 137 |
|
144 |
|
| 138 |
/** |
145 |
/** |
| 139 |
* Directly changes this record's internal location string. The format |
146 |
* 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 |
147 |
* @param sourceFile the file to transfer the local bindings from. |
| 141 |
* associated IIndexLocationConverter |
148 |
* @throws CoreException |
|
|
149 |
*/ |
| 150 |
public void replaceContentsFrom(PDOMFile sourceFile) throws CoreException { |
| 151 |
ICPPUsingDirective[] directives= getUsingDirectives(); |
| 152 |
for (ICPPUsingDirective ud : directives) { |
| 153 |
if (ud instanceof IPDOMNode) { |
| 154 |
((IPDOMNode) ud).delete(null); |
| 155 |
} |
| 156 |
} |
| 157 |
setFirstUsingDirectiveRec(sourceFile.getLastUsingDirectiveRec()); |
| 158 |
|
| 159 |
// Replace the includes |
| 160 |
PDOMInclude include = getFirstInclude(); |
| 161 |
while (include != null) { |
| 162 |
PDOMInclude nextInclude = include.getNextInIncludes(); |
| 163 |
IIndexFile includedBy = include.getIncludedBy(); |
| 164 |
if (includedBy.equals(this)) { |
| 165 |
include.delete(); |
| 166 |
} |
| 167 |
include = nextInclude; |
| 168 |
} |
| 169 |
include = sourceFile.getFirstInclude(); |
| 170 |
setFirstInclude(include); |
| 171 |
while (include != null) { |
| 172 |
IIndexFile includedBy = include.getIncludedBy(); |
| 173 |
if (includedBy.equals(sourceFile)) { |
| 174 |
include.setIncludedBy(this); |
| 175 |
} |
| 176 |
include = include.getNextInIncludes(); |
| 177 |
} |
| 178 |
|
| 179 |
include = sourceFile.getFirstIncludedBy(); |
| 180 |
setFirstIncludedBy(include); |
| 181 |
while (include != null) { |
| 182 |
include.setIncludes(this); |
| 183 |
include = include.getNextInIncludedBy(); |
| 184 |
} |
| 185 |
|
| 186 |
// Replace all the macros in this file. |
| 187 |
PDOMLinkage linkage= getLinkage(); |
| 188 |
PDOMMacro macro = getFirstMacro(); |
| 189 |
while (macro != null) { |
| 190 |
PDOMMacro nextMacro = macro.getNextMacro(); |
| 191 |
macro.delete(linkage); |
| 192 |
macro = nextMacro; |
| 193 |
} |
| 194 |
macro = sourceFile.getFirstMacro(); |
| 195 |
setFirstMacro(macro); |
| 196 |
for (; macro != null; macro = macro.getNextMacro()) { |
| 197 |
macro.setFile(this); |
| 198 |
} |
| 199 |
|
| 200 |
// Replace all macro references |
| 201 |
ArrayList<PDOMMacroReferenceName> mrefs= new ArrayList<PDOMMacroReferenceName>(); |
| 202 |
PDOMMacroReferenceName mref = getFirstMacroReference(); |
| 203 |
while (mref != null) { |
| 204 |
mrefs.add(mref); |
| 205 |
mref= mref.getNextInFile(); |
| 206 |
} |
| 207 |
for (PDOMMacroReferenceName m : mrefs) { |
| 208 |
m.delete(); |
| 209 |
} |
| 210 |
mref = sourceFile.getFirstMacroReference(); |
| 211 |
setFirstMacroReference(mref); |
| 212 |
for (; mref != null; mref = mref.getNextInFile()) { |
| 213 |
mref.setFile(this); |
| 214 |
} |
| 215 |
|
| 216 |
// Replace all the names in this file |
| 217 |
ArrayList<PDOMName> names= new ArrayList<PDOMName>(); |
| 218 |
PDOMName name = getFirstName(); |
| 219 |
for (; name != null; name= name.getNextInFile()) { |
| 220 |
names.add(name); |
| 221 |
linkage.onDeleteName(name); |
| 222 |
} |
| 223 |
for (Iterator<PDOMName> iterator = names.iterator(); iterator.hasNext();) { |
| 224 |
name = iterator.next(); |
| 225 |
name.delete(); |
| 226 |
} |
| 227 |
name = sourceFile.getFirstName(); |
| 228 |
setFirstName(name); |
| 229 |
for (; name != null; name= name.getNextInFile()) { |
| 230 |
name.setFile(this); |
| 231 |
} |
| 232 |
|
| 233 |
setTimestamp(sourceFile.getTimestamp()); |
| 234 |
setScannerConfigurationHashcode(sourceFile.getScannerConfigurationHashcode()); |
| 235 |
|
| 236 |
sourceFile.delete(); |
| 237 |
} |
| 238 |
|
| 239 |
/** |
| 240 |
* This method should not be called on PDOMFile objects that are referenced by the file index. |
| 241 |
* @param location a new location |
| 242 |
* @throws CoreException |
| 243 |
*/ |
| 244 |
public void setLocation(IIndexFileLocation location) throws CoreException { |
| 245 |
String locationString = fLinkage.getPDOM().getLocationConverter().toInternalFormat(location); |
| 246 |
if (locationString == null) |
| 247 |
throw new CoreException(CCorePlugin.createStatus(Messages.getString("PDOMFile.toInternalProblem") + //$NON-NLS-1$ |
| 248 |
location.getURI())); |
| 249 |
setInternalLocation(locationString); |
| 250 |
} |
| 251 |
|
| 252 |
/** |
| 253 |
* Directly changes this record's internal location string. The format of this string is unspecified |
| 254 |
* in general and is determined by the associated IIndexLocationConverter. |
| 255 |
* This method should not be called on PDOMFile objects that are referenced by the file index. |
| 142 |
* @param internalLocation |
256 |
* @param internalLocation |
| 143 |
* @throws CoreException |
257 |
* @throws CoreException |
| 144 |
*/ |
258 |
*/ |
|
Lines 260-274
Link Here
|
| 260 |
return fLinkage; |
374 |
return fLinkage; |
| 261 |
} |
375 |
} |
| 262 |
|
376 |
|
| 263 |
public void addNames(IASTName[][] names) throws CoreException { |
377 |
public void addNames(IASTName[][] names, YieldableIndexLock lock) throws CoreException, InterruptedException { |
| 264 |
assert getFirstName() == null; |
378 |
assert getFirstName() == null; |
| 265 |
assert getFirstMacroReference() == null; |
379 |
assert getFirstMacroReference() == null; |
| 266 |
final PDOMLinkage linkage= getLinkage(); |
380 |
final PDOMLinkage linkage= getLinkage(); |
| 267 |
HashMap<IASTName, PDOMName> nameCache= new HashMap<IASTName, PDOMName>(); |
381 |
HashMap<IASTName, PDOMName> nameCache= new HashMap<IASTName, PDOMName>(); |
| 268 |
PDOMName lastName= null; |
382 |
PDOMName lastName= null; |
| 269 |
PDOMMacroReferenceName lastMacroName= null; |
383 |
PDOMMacroReferenceName lastMacroName= null; |
|
|
384 |
int counter = 0; |
| 270 |
for (IASTName[] name : names) { |
385 |
for (IASTName[] name : names) { |
| 271 |
if (name[0] != null) { |
386 |
if (name[0] != null) { |
|
|
387 |
// Once in a while check if anybody waits for index reader lock |
| 388 |
// and yield the writer lock if so. |
| 389 |
if (lock != null && ++counter >= 50) { |
| 390 |
counter = 0; |
| 391 |
lock.yield(); |
| 392 |
} |
| 272 |
PDOMName caller= nameCache.get(name[1]); |
393 |
PDOMName caller= nameCache.get(name[1]); |
| 273 |
IIndexFragmentName fname= createPDOMName(linkage, name[0], caller); |
394 |
IIndexFragmentName fname= createPDOMName(linkage, name[0], caller); |
| 274 |
if (fname instanceof PDOMName) { |
395 |
if (fname instanceof PDOMName) { |
|
Lines 344-350
Link Here
|
| 344 |
include.delete(); |
465 |
include.delete(); |
| 345 |
include = nextInclude; |
466 |
include = nextInclude; |
| 346 |
} |
467 |
} |
| 347 |
setFirstInclude(include); |
468 |
setFirstInclude(null); |
| 348 |
|
469 |
|
| 349 |
// Delete all the macros in this file |
470 |
// Delete all the macros in this file |
| 350 |
PDOMLinkage linkage= getLinkage(); |
471 |
PDOMLinkage linkage= getLinkage(); |
|
Lines 385-390
Link Here
|
| 385 |
setTimestamp(-1); |
506 |
setTimestamp(-1); |
| 386 |
} |
507 |
} |
| 387 |
|
508 |
|
|
|
509 |
private void delete() throws CoreException { |
| 510 |
fLinkage.getDB().free(record); |
| 511 |
} |
| 512 |
|
| 388 |
public void addIncludesTo(IncludeInformation[] includeInfos) throws CoreException { |
513 |
public void addIncludesTo(IncludeInformation[] includeInfos) throws CoreException { |
| 389 |
assert getFirstInclude() == null; |
514 |
assert getFirstInclude() == null; |
| 390 |
|
515 |
|