mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Cosmetics.
This commit is contained in:
parent
30ed2ca8c9
commit
41ee60794f
5 changed files with 102 additions and 103 deletions
|
@ -6,7 +6,7 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||||
|
|
||||||
|
@ -111,14 +111,14 @@ abstract class LocationCtx implements ILocationCtx {
|
||||||
* that it is contained in this context.
|
* that it is contained in this context.
|
||||||
*/
|
*/
|
||||||
public ASTFileLocation findMappedFileLocation(int sequenceNumber, int length) {
|
public ASTFileLocation findMappedFileLocation(int sequenceNumber, int length) {
|
||||||
return fParent.createMappedFileLocation(fOffsetInParent, fEndOffsetInParent-fOffsetInParent);
|
return fParent.createMappedFileLocation(fOffsetInParent, fEndOffsetInParent - fOffsetInParent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the file location containing the specified offset range in this context.
|
* Returns the file location containing the specified offset range in this context.
|
||||||
*/
|
*/
|
||||||
public ASTFileLocation createMappedFileLocation(int offset, int length) {
|
public ASTFileLocation createMappedFileLocation(int offset, int length) {
|
||||||
return fParent.createMappedFileLocation(fOffsetInParent, fEndOffsetInParent-fOffsetInParent);
|
return fParent.createMappedFileLocation(fOffsetInParent, fEndOffsetInParent - fOffsetInParent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ class LocationCtxContainer extends LocationCtx {
|
||||||
}
|
}
|
||||||
|
|
||||||
public char[] getSource(int offset, int length) {
|
public char[] getSource(int offset, int length) {
|
||||||
if (fSource.isValidOffset(offset+length-1)) {
|
if (fSource.isValidOffset(offset + length - 1)) {
|
||||||
char[] result= new char[length];
|
char[] result= new char[length];
|
||||||
fSource.arraycopy(offset, result, 0, length);
|
fSource.arraycopy(offset, result, 0, length);
|
||||||
return result;
|
return result;
|
||||||
|
@ -73,12 +73,11 @@ class LocationCtxContainer extends LocationCtx {
|
||||||
public final int getSequenceNumberForOffset(int offset, boolean checkChildren) {
|
public final int getSequenceNumberForOffset(int offset, boolean checkChildren) {
|
||||||
int result= fSequenceNumber + fChildSequenceLength + offset;
|
int result= fSequenceNumber + fChildSequenceLength + offset;
|
||||||
if (checkChildren && fChildren != null) {
|
if (checkChildren && fChildren != null) {
|
||||||
for (int i= fChildren.size()-1; i >= 0; i--) {
|
for (int i= fChildren.size() - 1; i >= 0; i--) {
|
||||||
final LocationCtx child= fChildren.get(i);
|
final LocationCtx child= fChildren.get(i);
|
||||||
if (child.fEndOffsetInParent > offset) { // child was inserted behind the offset, adjust sequence number
|
if (child.fEndOffsetInParent > offset) { // child was inserted behind the offset, adjust sequence number
|
||||||
result-= child.getSequenceLength();
|
result-= child.getSequenceLength();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,7 +92,7 @@ class LocationCtxContainer extends LocationCtx {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final LocationCtx findSurroundingContext(int sequenceNumber, int length) {
|
public final LocationCtx findSurroundingContext(int sequenceNumber, int length) {
|
||||||
int testEnd= length > 1 ? sequenceNumber+length-1 : sequenceNumber;
|
int testEnd= length > 1 ? sequenceNumber + length - 1 : sequenceNumber;
|
||||||
final LocationCtx child= findChildLessOrEqualThan(sequenceNumber, false);
|
final LocationCtx child= findChildLessOrEqualThan(sequenceNumber, false);
|
||||||
if (child != null && child.fSequenceNumber+child.getSequenceLength() > testEnd) {
|
if (child != null && child.fSequenceNumber+child.getSequenceLength() > testEnd) {
|
||||||
return child.findSurroundingContext(sequenceNumber, length);
|
return child.findSurroundingContext(sequenceNumber, length);
|
||||||
|
@ -103,7 +102,7 @@ class LocationCtxContainer extends LocationCtx {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final LocationCtxMacroExpansion findEnclosingMacroExpansion(int sequenceNumber, int length) {
|
public final LocationCtxMacroExpansion findEnclosingMacroExpansion(int sequenceNumber, int length) {
|
||||||
int testEnd= length > 1 ? sequenceNumber+length-1 : sequenceNumber;
|
int testEnd= length > 1 ? sequenceNumber + length - 1 : sequenceNumber;
|
||||||
final LocationCtx child= findChildLessOrEqualThan(sequenceNumber, true);
|
final LocationCtx child= findChildLessOrEqualThan(sequenceNumber, true);
|
||||||
if (child != null && child.fSequenceNumber+child.getSequenceLength() > testEnd) {
|
if (child != null && child.fSequenceNumber+child.getSequenceLength() > testEnd) {
|
||||||
return child.findEnclosingMacroExpansion(sequenceNumber, length);
|
return child.findEnclosingMacroExpansion(sequenceNumber, length);
|
||||||
|
@ -129,9 +128,9 @@ class LocationCtxContainer extends LocationCtx {
|
||||||
@Override
|
@Override
|
||||||
public ASTFileLocation findMappedFileLocation(int sequenceNumber, int length) {
|
public ASTFileLocation findMappedFileLocation(int sequenceNumber, int length) {
|
||||||
// try to delegate to a child.
|
// try to delegate to a child.
|
||||||
int testEnd= length > 1 ? sequenceNumber+length-1 : sequenceNumber;
|
int testEnd= length > 1 ? sequenceNumber + length - 1 : sequenceNumber;
|
||||||
final LocationCtx child= findChildLessOrEqualThan(sequenceNumber, false);
|
final LocationCtx child= findChildLessOrEqualThan(sequenceNumber, false);
|
||||||
if (child != null && child.fSequenceNumber+child.getSequenceLength() > testEnd) {
|
if (child != null && child.fSequenceNumber + child.getSequenceLength() > testEnd) {
|
||||||
return child.findMappedFileLocation(sequenceNumber, length);
|
return child.findMappedFileLocation(sequenceNumber, length);
|
||||||
}
|
}
|
||||||
return super.findMappedFileLocation(sequenceNumber, length);
|
return super.findMappedFileLocation(sequenceNumber, length);
|
||||||
|
@ -139,7 +138,7 @@ class LocationCtxContainer extends LocationCtx {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean collectLocations(int sequenceNumber, final int length, ArrayList<IASTNodeLocation> locations) {
|
public boolean collectLocations(int sequenceNumber, final int length, ArrayList<IASTNodeLocation> locations) {
|
||||||
final int endSequenceNumber= sequenceNumber+length;
|
final int endSequenceNumber= sequenceNumber + length;
|
||||||
if (fChildren != null) {
|
if (fChildren != null) {
|
||||||
int childIdx= Math.max(0, findChildIdxLessOrEqualThan(sequenceNumber, false));
|
int childIdx= Math.max(0, findChildIdxLessOrEqualThan(sequenceNumber, false));
|
||||||
for (; childIdx < fChildren.size(); childIdx++) {
|
for (; childIdx < fChildren.size(); childIdx++) {
|
||||||
|
@ -151,18 +150,18 @@ class LocationCtxContainer extends LocationCtx {
|
||||||
final int offset= child.fEndOffsetInParent - (child.fSequenceNumber - sequenceNumber);
|
final int offset= child.fEndOffsetInParent - (child.fSequenceNumber - sequenceNumber);
|
||||||
// it the child is not affected, we are done.
|
// it the child is not affected, we are done.
|
||||||
if (endSequenceNumber <= child.fSequenceNumber) {
|
if (endSequenceNumber <= child.fSequenceNumber) {
|
||||||
addFileLocation(offset, endSequenceNumber-sequenceNumber, locations);
|
addFileLocation(offset, endSequenceNumber - sequenceNumber, locations);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (offset < child.fOffsetInParent)
|
if (offset < child.fOffsetInParent)
|
||||||
addFileLocation(offset, child.fOffsetInParent-offset, locations);
|
addFileLocation(offset, child.fOffsetInParent - offset, locations);
|
||||||
sequenceNumber= child.fSequenceNumber;
|
sequenceNumber= child.fSequenceNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
// let the child create locations
|
// let the child create locations
|
||||||
final int childEndSequenceNumber= child.fSequenceNumber + child.getSequenceLength();
|
final int childEndSequenceNumber= child.fSequenceNumber + child.getSequenceLength();
|
||||||
if (sequenceNumber < childEndSequenceNumber) {
|
if (sequenceNumber < childEndSequenceNumber) {
|
||||||
if (child.collectLocations(sequenceNumber, endSequenceNumber-sequenceNumber, locations)) {
|
if (child.collectLocations(sequenceNumber, endSequenceNumber - sequenceNumber, locations)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
sequenceNumber= childEndSequenceNumber;
|
sequenceNumber= childEndSequenceNumber;
|
||||||
|
@ -174,10 +173,10 @@ class LocationCtxContainer extends LocationCtx {
|
||||||
final int myEndNumber = fSequenceNumber + getSequenceLength();
|
final int myEndNumber = fSequenceNumber + getSequenceLength();
|
||||||
final int offset= fSource.getLength() - (myEndNumber - sequenceNumber);
|
final int offset= fSource.getLength() - (myEndNumber - sequenceNumber);
|
||||||
if (endSequenceNumber <= myEndNumber) {
|
if (endSequenceNumber <= myEndNumber) {
|
||||||
addFileLocation(offset, endSequenceNumber-sequenceNumber, locations);
|
addFileLocation(offset, endSequenceNumber - sequenceNumber, locations);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
addFileLocation(offset, fSource.getLength()-offset, locations);
|
addFileLocation(offset, fSource.getLength() - offset, locations);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,20 +199,19 @@ class LocationCtxContainer extends LocationCtx {
|
||||||
int upper= fChildren.size();
|
int upper= fChildren.size();
|
||||||
int lower= 0;
|
int lower= 0;
|
||||||
while (upper > lower) {
|
while (upper > lower) {
|
||||||
int middle= (upper+lower)/2;
|
int middle= (upper + lower) / 2;
|
||||||
LocationCtx child= fChildren.get(middle);
|
LocationCtx child= fChildren.get(middle);
|
||||||
int childSequenceNumber= child.fSequenceNumber;
|
int childSequenceNumber= child.fSequenceNumber;
|
||||||
if (beforeReplacedChars) {
|
if (beforeReplacedChars) {
|
||||||
childSequenceNumber-= child.fEndOffsetInParent-child.fOffsetInParent;
|
childSequenceNumber-= child.fEndOffsetInParent - child.fOffsetInParent;
|
||||||
}
|
}
|
||||||
if (childSequenceNumber <= sequenceNumber) {
|
if (childSequenceNumber <= sequenceNumber) {
|
||||||
lower= middle+1;
|
lower= middle + 1;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
upper= middle;
|
upper= middle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return lower-1;
|
return lower - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
final LocationCtx findChildLessOrEqualThan(final int sequenceNumber, boolean beforeReplacedChars) {
|
final LocationCtx findChildLessOrEqualThan(final int sequenceNumber, boolean beforeReplacedChars) {
|
||||||
|
@ -227,8 +225,7 @@ class LocationCtxContainer extends LocationCtx {
|
||||||
for (LocationCtx ctx : fChildren) {
|
for (LocationCtx ctx : fChildren) {
|
||||||
if (ctx.getInclusionStatement() != null) {
|
if (ctx.getInclusionStatement() != null) {
|
||||||
result.add(new ASTInclusionNode(ctx));
|
result.add(new ASTInclusionNode(ctx));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ctx.getInclusions(result);
|
ctx.getInclusions(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,14 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroExpansion;
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroExpansion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,9 +25,9 @@ class LocationCtxFile extends LocationCtxContainer {
|
||||||
private final ASTInclusionStatement fASTInclude;
|
private final ASTInclusionStatement fASTInclude;
|
||||||
private final boolean fIsSource;
|
private final boolean fIsSource;
|
||||||
|
|
||||||
public LocationCtxFile(LocationCtxContainer parent, String filename, AbstractCharArray source, int parentOffset,
|
public LocationCtxFile(LocationCtxContainer parent, String filename, AbstractCharArray source,
|
||||||
int parentEndOffset, int sequenceNumber, ASTInclusionStatement inclusionStatement,
|
int parentOffset, int parentEndOffset, int sequenceNumber,
|
||||||
boolean isSource) {
|
ASTInclusionStatement inclusionStatement, boolean isSource) {
|
||||||
super(parent, source, parentOffset, parentEndOffset, sequenceNumber);
|
super(parent, source, parentOffset, parentEndOffset, sequenceNumber);
|
||||||
fFilename= new String(filename);
|
fFilename= new String(filename);
|
||||||
fASTInclude= inclusionStatement;
|
fASTInclude= inclusionStatement;
|
||||||
|
@ -46,12 +47,14 @@ class LocationCtxFile extends LocationCtxContainer {
|
||||||
@Override
|
@Override
|
||||||
public ASTFileLocation findMappedFileLocation(int sequenceNumber, int length) {
|
public ASTFileLocation findMappedFileLocation(int sequenceNumber, int length) {
|
||||||
// try to delegate to a child.
|
// try to delegate to a child.
|
||||||
final int testEnd= length > 1 ? sequenceNumber+length-1 : sequenceNumber;
|
final int testEnd= length > 1 ? sequenceNumber + length - 1 : sequenceNumber;
|
||||||
final int sequenceEnd= sequenceNumber+length;
|
final int sequenceEnd= sequenceNumber+length;
|
||||||
final LocationCtx child1= findChildLessOrEqualThan(sequenceNumber, false);
|
final LocationCtx child1= findChildLessOrEqualThan(sequenceNumber, false);
|
||||||
final LocationCtx child2= testEnd == sequenceNumber ? child1 : findChildLessOrEqualThan(testEnd, false);
|
final LocationCtx child2= testEnd == sequenceNumber ?
|
||||||
|
child1 : findChildLessOrEqualThan(testEnd, false);
|
||||||
|
|
||||||
if (child1 == child2 && child1 != null && child1.fSequenceNumber + child1.getSequenceLength() > testEnd) {
|
if (child1 == child2 && child1 != null &&
|
||||||
|
child1.fSequenceNumber + child1.getSequenceLength() > testEnd) {
|
||||||
return child1.findMappedFileLocation(sequenceNumber, length);
|
return child1.findMappedFileLocation(sequenceNumber, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,29 +64,25 @@ class LocationCtxFile extends LocationCtxContainer {
|
||||||
|
|
||||||
if (child1 == null) {
|
if (child1 == null) {
|
||||||
startOffset= sequenceNumber-fSequenceNumber;
|
startOffset= sequenceNumber-fSequenceNumber;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
int childSequenceEnd= child1.fSequenceNumber + child1.getSequenceLength();
|
int childSequenceEnd= child1.fSequenceNumber + child1.getSequenceLength();
|
||||||
if (sequenceNumber < childSequenceEnd) {
|
if (sequenceNumber < childSequenceEnd) {
|
||||||
startOffset= child1.fOffsetInParent;
|
startOffset= child1.fOffsetInParent;
|
||||||
}
|
} else { // start beyond child1
|
||||||
else { // start beyond child1
|
startOffset= child1.fEndOffsetInParent + sequenceNumber - childSequenceEnd;
|
||||||
startOffset= child1.fEndOffsetInParent + sequenceNumber-childSequenceEnd;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (child2 == null) {
|
if (child2 == null) {
|
||||||
endOffset= sequenceEnd-fSequenceNumber;
|
endOffset= sequenceEnd - fSequenceNumber;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
int childSequenceEnd= child2.fSequenceNumber + child2.getSequenceLength();
|
int childSequenceEnd= child2.fSequenceNumber + child2.getSequenceLength();
|
||||||
if (childSequenceEnd < sequenceEnd) { // beyond child2
|
if (childSequenceEnd < sequenceEnd) { // beyond child2
|
||||||
endOffset= child2.fEndOffsetInParent+sequenceEnd-childSequenceEnd;
|
endOffset= child2.fEndOffsetInParent + sequenceEnd - childSequenceEnd;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
endOffset= child2.fEndOffsetInParent;
|
endOffset= child2.fEndOffsetInParent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new ASTFileLocation(this, startOffset, endOffset-startOffset);
|
return new ASTFileLocation(this, startOffset, endOffset - startOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -109,7 +108,8 @@ class LocationCtxFile extends LocationCtxContainer {
|
||||||
return sequenceNumber >= child.fSequenceNumber + child.getSequenceLength();
|
return sequenceNumber >= child.fSequenceNumber + child.getSequenceLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void collectMacroExpansions(int offset, int length, ArrayList<IASTPreprocessorMacroExpansion> list) {
|
public void collectMacroExpansions(int offset, int length,
|
||||||
|
ArrayList<IASTPreprocessorMacroExpansion> list) {
|
||||||
Collection<LocationCtx> children= getChildren();
|
Collection<LocationCtx> children= getChildren();
|
||||||
for (LocationCtx ctx : children) {
|
for (LocationCtx ctx : children) {
|
||||||
// context must start before the end of the search range
|
// context must start before the end of the search range
|
||||||
|
@ -119,7 +119,9 @@ class LocationCtxFile extends LocationCtxContainer {
|
||||||
if (ctx instanceof LocationCtxMacroExpansion) {
|
if (ctx instanceof LocationCtxMacroExpansion) {
|
||||||
// expansion must end after the search start
|
// expansion must end after the search start
|
||||||
if (ctx.fEndOffsetInParent > offset) {
|
if (ctx.fEndOffsetInParent > offset) {
|
||||||
list.add((IASTPreprocessorMacroExpansion) ((LocationCtxMacroExpansion)ctx).getMacroReference().getParent());
|
IASTNode macroExpansion =
|
||||||
|
((LocationCtxMacroExpansion) ctx).getMacroReference().getParent();
|
||||||
|
list.add((IASTPreprocessorMacroExpansion) macroExpansion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||||
|
|
||||||
|
@ -46,10 +46,10 @@ class LocationCtxMacroExpansion extends LocationCtx {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean collectLocations(int start, int length, ArrayList<IASTNodeLocation> locations) {
|
public boolean collectLocations(int start, int length, ArrayList<IASTNodeLocation> locations) {
|
||||||
final int offset= start-fSequenceNumber;
|
final int offset= start - fSequenceNumber;
|
||||||
assert offset >= 0 && length >= 0;
|
assert offset >= 0 && length >= 0;
|
||||||
|
|
||||||
if (offset+length <= fLength) {
|
if (offset + length <= fLength) {
|
||||||
locations.add(new ASTMacroExpansionLocation(this, offset, length));
|
locations.add(new ASTMacroExpansionLocation(this, offset, length));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -87,18 +87,15 @@ class LocationCtxMacroExpansion extends LocationCtx {
|
||||||
if (info.fTokenOffsetInExpansion == nextToCheck) {
|
if (info.fTokenOffsetInExpansion == nextToCheck) {
|
||||||
if (firstInfo == null || lastInfo == null) {
|
if (firstInfo == null || lastInfo == null) {
|
||||||
firstInfo= lastInfo= info;
|
firstInfo= lastInfo= info;
|
||||||
}
|
} else if (lastInfo.canConcatenate(info)) {
|
||||||
else if (lastInfo.canConcatenate(info)) {
|
|
||||||
lastInfo= info;
|
lastInfo= info;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (++nextToCheck == end) {
|
if (++nextToCheck == end) {
|
||||||
return firstInfo.createLocation(fLocationMap, lastInfo);
|
return firstInfo.createLocation(fLocationMap, lastInfo);
|
||||||
}
|
}
|
||||||
}
|
} else if (info.fTokenOffsetInExpansion > nextToCheck) {
|
||||||
else if (info.fTokenOffsetInExpansion > nextToCheck) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,5 +106,3 @@ class LocationCtxMacroExpansion extends LocationCtx {
|
||||||
return fLocationMap.getNestedMacroReferences((ASTMacroExpansion) fExpansionName.getParent());
|
return fLocationMap.getNestedMacroReferences((ASTMacroExpansion) fExpansionName.getParent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - Initial API and implementation
|
* Markus Schorn - Initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||||
|
|
||||||
|
@ -37,13 +37,11 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTProblem;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.Lexer.LexerOptions;
|
import org.eclipse.cdt.internal.core.parser.scanner.Lexer.LexerOptions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the offsets relative to various contexts to the global sequence number. Also creates and stores
|
* Converts the offsets relative to various contexts to the global sequence number. Also creates
|
||||||
* objects that are needed to conform with the IAST... interfaces.
|
* and stores objects that are needed to conform with the IAST... interfaces.
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
public class LocationMap implements ILocationResolver {
|
public class LocationMap implements ILocationResolver {
|
||||||
private static final IASTName[] EMPTY_NAMES = {};
|
|
||||||
|
|
||||||
private final LexerOptions fLexerOptions;
|
private final LexerOptions fLexerOptions;
|
||||||
private String fTranslationUnitPath;
|
private String fTranslationUnitPath;
|
||||||
private IASTTranslationUnit fTranslationUnit;
|
private IASTTranslationUnit fTranslationUnit;
|
||||||
|
@ -82,8 +80,7 @@ public class LocationMap implements ILocationResolver {
|
||||||
ASTMacroDefinition astmacro;
|
ASTMacroDefinition astmacro;
|
||||||
if (macro.isFunctionStyle()) {
|
if (macro.isFunctionStyle()) {
|
||||||
astmacro= new ASTFunctionStyleMacroDefinition(fTranslationUnit, macro, nameloc, expansionOffset);
|
astmacro= new ASTFunctionStyleMacroDefinition(fTranslationUnit, macro, nameloc, expansionOffset);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
astmacro= new ASTMacroDefinition(fTranslationUnit, macro, nameloc, expansionOffset);
|
astmacro= new ASTMacroDefinition(fTranslationUnit, macro, nameloc, expansionOffset);
|
||||||
}
|
}
|
||||||
fBuiltinMacros.add(astmacro);
|
fBuiltinMacros.add(astmacro);
|
||||||
|
@ -176,10 +173,11 @@ public class LocationMap implements ILocationResolver {
|
||||||
int nameNumber= getSequenceNumberForOffset(nameOffset);
|
int nameNumber= getSequenceNumberForOffset(nameOffset);
|
||||||
int nameEndNumber= getSequenceNumberForOffset(nameEndOffset);
|
int nameEndNumber= getSequenceNumberForOffset(nameEndOffset);
|
||||||
int endNumber= getSequenceNumberForOffset(endOffset);
|
int endNumber= getSequenceNumberForOffset(endOffset);
|
||||||
final int length= endNumber-nameNumber;
|
final int length= endNumber - nameNumber;
|
||||||
|
|
||||||
ASTMacroExpansion expansion= new ASTMacroExpansion(fTranslationUnit, nameNumber, endNumber);
|
ASTMacroExpansion expansion= new ASTMacroExpansion(fTranslationUnit, nameNumber, endNumber);
|
||||||
ASTMacroReferenceName explicitRef= new ASTMacroReferenceName(expansion, IASTPreprocessorMacroExpansion.EXPANSION_NAME, nameNumber, nameEndNumber, macro, null);
|
ASTMacroReferenceName explicitRef= new ASTMacroReferenceName(expansion,
|
||||||
|
IASTPreprocessorMacroExpansion.EXPANSION_NAME, nameNumber, nameEndNumber, macro, null);
|
||||||
addMacroReference(explicitRef);
|
addMacroReference(explicitRef);
|
||||||
for (IASTName implicitMacroReference : implicitMacroReferences) {
|
for (IASTName implicitMacroReference : implicitMacroReferences) {
|
||||||
ASTMacroReferenceName name = (ASTMacroReferenceName) implicitMacroReference;
|
ASTMacroReferenceName name = (ASTMacroReferenceName) implicitMacroReference;
|
||||||
|
@ -188,7 +186,9 @@ public class LocationMap implements ILocationResolver {
|
||||||
addMacroReference(name);
|
addMacroReference(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
LocationCtxMacroExpansion expansionCtx= new LocationCtxMacroExpansion(this, (LocationCtxContainer) fCurrentContext, nameOffset, endOffset, endNumber, contextLength, imageLocations, explicitRef);
|
LocationCtxMacroExpansion expansionCtx= new LocationCtxMacroExpansion(this,
|
||||||
|
(LocationCtxContainer) fCurrentContext, nameOffset, endOffset, endNumber,
|
||||||
|
contextLength, imageLocations, explicitRef);
|
||||||
expansion.setContext(expansionCtx);
|
expansion.setContext(expansionCtx);
|
||||||
fCurrentContext= expansionCtx;
|
fCurrentContext= expansionCtx;
|
||||||
fLastChildInsertionOffset= 0;
|
fLastChildInsertionOffset= 0;
|
||||||
|
@ -232,7 +232,8 @@ public class LocationMap implements ILocationResolver {
|
||||||
nameOffset= getSequenceNumberForOffset(nameOffset);
|
nameOffset= getSequenceNumberForOffset(nameOffset);
|
||||||
nameEndOffset= getSequenceNumberForOffset(nameEndOffset);
|
nameEndOffset= getSequenceNumberForOffset(nameEndOffset);
|
||||||
endOffset= getSequenceNumberForOffset(endOffset);
|
endOffset= getSequenceNumberForOffset(endOffset);
|
||||||
fDirectives.add(new ASTInclusionStatement(fTranslationUnit, startOffset, nameOffset, nameEndOffset, endOffset, name, filename, userInclude, active, heuristic));
|
fDirectives.add(new ASTInclusionStatement(fTranslationUnit, startOffset, nameOffset,
|
||||||
|
nameEndOffset, endOffset, name, filename, userInclude, active, heuristic));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void encounteredComment(int offset, int endOffset, boolean isBlockComment) {
|
public void encounteredComment(int offset, int endOffset, boolean isBlockComment) {
|
||||||
|
@ -244,7 +245,8 @@ public class LocationMap implements ILocationResolver {
|
||||||
public void encounterProblem(int id, char[] arg, int offset, int endOffset) {
|
public void encounterProblem(int id, char[] arg, int offset, int endOffset) {
|
||||||
offset= getSequenceNumberForOffset(offset);
|
offset= getSequenceNumberForOffset(offset);
|
||||||
endOffset= getSequenceNumberForOffset(endOffset);
|
endOffset= getSequenceNumberForOffset(endOffset);
|
||||||
ASTProblem problem = new ASTProblem(fTranslationUnit, IASTTranslationUnit.SCANNER_PROBLEM, id, arg, false, offset, endOffset);
|
ASTProblem problem = new ASTProblem(fTranslationUnit, IASTTranslationUnit.SCANNER_PROBLEM,
|
||||||
|
id, arg, false, offset, endOffset);
|
||||||
fProblems.add(problem);
|
fProblems.add(problem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,7 +304,8 @@ public class LocationMap implements ILocationResolver {
|
||||||
fDirectives.add(new ASTPragmaOperator(fTranslationUnit, startNumber, condNumber, condEndNumber, endNumber));
|
fDirectives.add(new ASTPragmaOperator(fTranslationUnit, startNumber, condNumber, condEndNumber, endNumber));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ASTIfdef encounterPoundIfdef(int startOffset, int condOffset, int condEndOffset, int endOffset, boolean taken, IMacroBinding macro) {
|
public ASTIfdef encounterPoundIfdef(int startOffset, int condOffset, int condEndOffset,
|
||||||
|
int endOffset, boolean taken, IMacroBinding macro) {
|
||||||
startOffset= getSequenceNumberForOffset(startOffset);
|
startOffset= getSequenceNumberForOffset(startOffset);
|
||||||
condOffset= getSequenceNumberForOffset(condOffset);
|
condOffset= getSequenceNumberForOffset(condOffset);
|
||||||
condEndOffset= getSequenceNumberForOffset(condEndOffset);
|
condEndOffset= getSequenceNumberForOffset(condEndOffset);
|
||||||
|
@ -313,7 +316,8 @@ public class LocationMap implements ILocationResolver {
|
||||||
return ifdef;
|
return ifdef;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ASTIfndef encounterPoundIfndef(int startOffset, int condOffset, int condEndOffset, int endOffset, boolean taken, IMacroBinding macro) {
|
public ASTIfndef encounterPoundIfndef(int startOffset, int condOffset, int condEndOffset,
|
||||||
|
int endOffset, boolean taken, IMacroBinding macro) {
|
||||||
startOffset= getSequenceNumberForOffset(startOffset);
|
startOffset= getSequenceNumberForOffset(startOffset);
|
||||||
condOffset= getSequenceNumberForOffset(condOffset);
|
condOffset= getSequenceNumberForOffset(condOffset);
|
||||||
condEndOffset= getSequenceNumberForOffset(condEndOffset);
|
condEndOffset= getSequenceNumberForOffset(condEndOffset);
|
||||||
|
@ -324,8 +328,8 @@ public class LocationMap implements ILocationResolver {
|
||||||
return ifndef;
|
return ifndef;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ASTIf encounterPoundIf(int startOffset, int condOffset, int condEndOffset, int endOffset, boolean taken,
|
public ASTIf encounterPoundIf(int startOffset, int condOffset, int condEndOffset, int endOffset,
|
||||||
IASTName[] macrosInDefinedExpression) {
|
boolean taken, IASTName[] macrosInDefinedExpression) {
|
||||||
startOffset= getSequenceNumberForOffset(startOffset);
|
startOffset= getSequenceNumberForOffset(startOffset);
|
||||||
condOffset= getSequenceNumberForOffset(condOffset);
|
condOffset= getSequenceNumberForOffset(condOffset);
|
||||||
condEndOffset= getSequenceNumberForOffset(condEndOffset);
|
condEndOffset= getSequenceNumberForOffset(condEndOffset);
|
||||||
|
@ -341,7 +345,8 @@ public class LocationMap implements ILocationResolver {
|
||||||
return astif;
|
return astif;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void encounterPoundDefine(int startOffset, int nameOffset, int nameEndOffset, int expansionOffset, int endOffset, boolean isActive, IMacroBinding macrodef) {
|
public void encounterPoundDefine(int startOffset, int nameOffset, int nameEndOffset,
|
||||||
|
int expansionOffset, int endOffset, boolean isActive, IMacroBinding macrodef) {
|
||||||
startOffset= getSequenceNumberForOffset(startOffset);
|
startOffset= getSequenceNumberForOffset(startOffset);
|
||||||
nameOffset= getSequenceNumberForOffset(nameOffset);
|
nameOffset= getSequenceNumberForOffset(nameOffset);
|
||||||
nameEndOffset= getSequenceNumberForOffset(nameEndOffset);
|
nameEndOffset= getSequenceNumberForOffset(nameEndOffset);
|
||||||
|
@ -349,20 +354,23 @@ public class LocationMap implements ILocationResolver {
|
||||||
endOffset= getSequenceNumberForOffset(endOffset);
|
endOffset= getSequenceNumberForOffset(endOffset);
|
||||||
ASTPreprocessorNode astMacro;
|
ASTPreprocessorNode astMacro;
|
||||||
if (!macrodef.isFunctionStyle()) {
|
if (!macrodef.isFunctionStyle()) {
|
||||||
astMacro= new ASTMacroDefinition(fTranslationUnit, macrodef, startOffset, nameOffset, nameEndOffset, expansionOffset, endOffset, isActive);
|
astMacro= new ASTMacroDefinition(fTranslationUnit, macrodef, startOffset, nameOffset,
|
||||||
}
|
nameEndOffset, expansionOffset, endOffset, isActive);
|
||||||
else {
|
} else {
|
||||||
astMacro= new ASTFunctionStyleMacroDefinition(fTranslationUnit, macrodef, startOffset, nameOffset, nameEndOffset, expansionOffset, endOffset, isActive);
|
astMacro= new ASTFunctionStyleMacroDefinition(fTranslationUnit, macrodef, startOffset,
|
||||||
|
nameOffset, nameEndOffset, expansionOffset, endOffset, isActive);
|
||||||
}
|
}
|
||||||
fDirectives.add(astMacro);
|
fDirectives.add(astMacro);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void encounterPoundUndef(IMacroBinding definition, int startOffset, int nameOffset, int nameEndOffset, int endOffset, char[] name, boolean isActive) {
|
public void encounterPoundUndef(IMacroBinding definition, int startOffset, int nameOffset,
|
||||||
|
int nameEndOffset, int endOffset, char[] name, boolean isActive) {
|
||||||
startOffset= getSequenceNumberForOffset(startOffset);
|
startOffset= getSequenceNumberForOffset(startOffset);
|
||||||
nameOffset= getSequenceNumberForOffset(nameOffset);
|
nameOffset= getSequenceNumberForOffset(nameOffset);
|
||||||
nameEndOffset= getSequenceNumberForOffset(nameEndOffset);
|
nameEndOffset= getSequenceNumberForOffset(nameEndOffset);
|
||||||
// not using endOffset, compatible with 4.0: endOffset= getSequenceNumberForOffset(endOffset);
|
// not using endOffset, compatible with 4.0: endOffset= getSequenceNumberForOffset(endOffset);
|
||||||
final ASTUndef undef = new ASTUndef(fTranslationUnit, name, startOffset, nameOffset, nameEndOffset, definition, isActive);
|
final ASTUndef undef = new ASTUndef(fTranslationUnit, name, startOffset, nameOffset,
|
||||||
|
nameEndOffset, definition, isActive);
|
||||||
fDirectives.add(undef);
|
fDirectives.add(undef);
|
||||||
addMacroReference(undef.getMacroName());
|
addMacroReference(undef.getMacroName());
|
||||||
}
|
}
|
||||||
|
@ -462,7 +470,7 @@ public class LocationMap implements ILocationResolver {
|
||||||
|
|
||||||
int length= 0;
|
int length= 0;
|
||||||
if (nodeLength > 0) {
|
if (nodeLength > 0) {
|
||||||
length= getSequenceNumberForFileOffset(fileName, nodeOffset + nodeLength-1)+1 - sequenceNumber;
|
length= getSequenceNumberForFileOffset(fileName, nodeOffset + nodeLength - 1) + 1 - sequenceNumber;
|
||||||
if (length < 0) {
|
if (length < 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -506,7 +514,7 @@ public class LocationMap implements ILocationResolver {
|
||||||
|
|
||||||
// check directives
|
// check directives
|
||||||
int from= findLastNodeBefore(fDirectives, sequenceStart);
|
int from= findLastNodeBefore(fDirectives, sequenceStart);
|
||||||
for (int i= from+1; i < fDirectives.size(); i++) {
|
for (int i= from + 1; i < fDirectives.size(); i++) {
|
||||||
ASTPreprocessorNode directive= fDirectives.get(i);
|
ASTPreprocessorNode directive= fDirectives.get(i);
|
||||||
if (directive.getOffset() > sequenceEnd) {
|
if (directive.getOffset() > sequenceEnd) {
|
||||||
break;
|
break;
|
||||||
|
@ -516,7 +524,7 @@ public class LocationMap implements ILocationResolver {
|
||||||
|
|
||||||
// check macro references and expansions
|
// check macro references and expansions
|
||||||
from= findLastMacroReferenceBefore(fMacroReferences, sequenceStart);
|
from= findLastMacroReferenceBefore(fMacroReferences, sequenceStart);
|
||||||
for (int i= from+1; i < fMacroReferences.size(); i++) {
|
for (int i= from + 1; i < fMacroReferences.size(); i++) {
|
||||||
ASTPreprocessorNode macroRef= fMacroReferences.get(i);
|
ASTPreprocessorNode macroRef= fMacroReferences.get(i);
|
||||||
if (macroRef.getOffset() > sequenceEnd) {
|
if (macroRef.getOffset() > sequenceEnd) {
|
||||||
break;
|
break;
|
||||||
|
@ -552,15 +560,14 @@ public class LocationMap implements ILocationResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int findLastNodeBefore(ArrayList<? extends ASTPreprocessorNode> nodes, int sequenceStart) {
|
private int findLastNodeBefore(ArrayList<? extends ASTPreprocessorNode> nodes, int sequenceStart) {
|
||||||
int lower=-1;
|
int lower= -1;
|
||||||
int upper= nodes.size()-1;
|
int upper= nodes.size() - 1;
|
||||||
while(lower < upper) {
|
while (lower < upper) {
|
||||||
int middle= (lower+upper+1)/2;
|
int middle= (lower + upper + 1) / 2;
|
||||||
ASTPreprocessorNode candidate= nodes.get(middle);
|
ASTPreprocessorNode candidate= nodes.get(middle);
|
||||||
if (candidate.getOffset() + candidate.getLength() >= sequenceStart) {
|
if (candidate.getOffset() + candidate.getLength() >= sequenceStart) {
|
||||||
upper= middle-1;
|
upper= middle - 1;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
lower= middle;
|
lower= middle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -568,19 +575,18 @@ public class LocationMap implements ILocationResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int findLastMacroReferenceBefore(ArrayList<? extends ASTPreprocessorName> nodes, int sequenceStart) {
|
private int findLastMacroReferenceBefore(ArrayList<? extends ASTPreprocessorName> nodes, int sequenceStart) {
|
||||||
int lower=-1;
|
int lower= -1;
|
||||||
int upper= nodes.size()-1;
|
int upper= nodes.size() - 1;
|
||||||
while(lower < upper) {
|
while (lower < upper) {
|
||||||
int middle= (lower+upper+1)/2;
|
int middle= (lower + upper + 1) / 2;
|
||||||
ASTPreprocessorNode candidate= nodes.get(middle);
|
ASTPreprocessorNode candidate= nodes.get(middle);
|
||||||
IASTNode parent= candidate.getParent();
|
IASTNode parent= candidate.getParent();
|
||||||
if (parent instanceof ASTMacroExpansion) {
|
if (parent instanceof ASTMacroExpansion) {
|
||||||
candidate= (ASTMacroExpansion) parent;
|
candidate= (ASTMacroExpansion) parent;
|
||||||
}
|
}
|
||||||
if (candidate.getOffset() + candidate.getLength() >= sequenceStart) {
|
if (candidate.getOffset() + candidate.getLength() >= sequenceStart) {
|
||||||
upper= middle-1;
|
upper= middle - 1;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
lower= middle;
|
lower= middle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -591,7 +597,7 @@ public class LocationMap implements ILocationResolver {
|
||||||
LocationCtx ctx= fRootContext;
|
LocationCtx ctx= fRootContext;
|
||||||
if (filePath != null) {
|
if (filePath != null) {
|
||||||
LinkedList<LocationCtx> contexts= new LinkedList<LocationCtx>();
|
LinkedList<LocationCtx> contexts= new LinkedList<LocationCtx>();
|
||||||
while(ctx != null) {
|
while (ctx != null) {
|
||||||
if (ctx instanceof LocationCtxFile) {
|
if (ctx instanceof LocationCtxFile) {
|
||||||
if (filePath.equals(ctx.getFilePath())) {
|
if (filePath.equals(ctx.getFilePath())) {
|
||||||
break;
|
break;
|
||||||
|
@ -600,8 +606,7 @@ public class LocationMap implements ILocationResolver {
|
||||||
contexts.addAll(ctx.getChildren());
|
contexts.addAll(ctx.getChildren());
|
||||||
if (contexts.isEmpty()) {
|
if (contexts.isEmpty()) {
|
||||||
ctx= null;
|
ctx= null;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ctx= contexts.removeFirst();
|
ctx= contexts.removeFirst();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -617,7 +622,7 @@ public class LocationMap implements ILocationResolver {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
IASTFileLocation from= locations[0].asFileLocation();
|
IASTFileLocation from= locations[0].asFileLocation();
|
||||||
IASTFileLocation to= locations[locations.length-1].asFileLocation();
|
IASTFileLocation to= locations[locations.length - 1].asFileLocation();
|
||||||
if (from == to) {
|
if (from == to) {
|
||||||
return from;
|
return from;
|
||||||
}
|
}
|
||||||
|
@ -676,7 +681,7 @@ public class LocationMap implements ILocationResolver {
|
||||||
|
|
||||||
public IASTName[] getDeclarations(IMacroBinding binding) {
|
public IASTName[] getDeclarations(IMacroBinding binding) {
|
||||||
IASTPreprocessorMacroDefinition def = getMacroDefinition(binding);
|
IASTPreprocessorMacroDefinition def = getMacroDefinition(binding);
|
||||||
return def == null ? EMPTY_NAMES : new IASTName[] {def.getName()};
|
return def == null ? IASTName.EMPTY_NAME_ARRAY: new IASTName[] { def.getName() };
|
||||||
}
|
}
|
||||||
|
|
||||||
IASTPreprocessorMacroDefinition getMacroDefinition(IMacroBinding binding) {
|
IASTPreprocessorMacroDefinition getMacroDefinition(IMacroBinding binding) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue