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
|
@ -77,8 +77,7 @@ class LocationCtxContainer extends LocationCtx {
|
|||
final LocationCtx child= fChildren.get(i);
|
||||
if (child.fEndOffsetInParent > offset) { // child was inserted behind the offset, adjust sequence number
|
||||
result-= child.getSequenceLength();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -208,8 +207,7 @@ class LocationCtxContainer extends LocationCtx {
|
|||
}
|
||||
if (childSequenceNumber <= sequenceNumber) {
|
||||
lower= middle + 1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
upper= middle;
|
||||
}
|
||||
}
|
||||
|
@ -227,8 +225,7 @@ class LocationCtxContainer extends LocationCtx {
|
|||
for (LocationCtx ctx : fChildren) {
|
||||
if (ctx.getInclusionStatement() != null) {
|
||||
result.add(new ASTInclusionNode(ctx));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ctx.getInclusions(result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.parser.scanner;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroExpansion;
|
||||
|
||||
/**
|
||||
|
@ -24,9 +25,9 @@ class LocationCtxFile extends LocationCtxContainer {
|
|||
private final ASTInclusionStatement fASTInclude;
|
||||
private final boolean fIsSource;
|
||||
|
||||
public LocationCtxFile(LocationCtxContainer parent, String filename, AbstractCharArray source, int parentOffset,
|
||||
int parentEndOffset, int sequenceNumber, ASTInclusionStatement inclusionStatement,
|
||||
boolean isSource) {
|
||||
public LocationCtxFile(LocationCtxContainer parent, String filename, AbstractCharArray source,
|
||||
int parentOffset, int parentEndOffset, int sequenceNumber,
|
||||
ASTInclusionStatement inclusionStatement, boolean isSource) {
|
||||
super(parent, source, parentOffset, parentEndOffset, sequenceNumber);
|
||||
fFilename= new String(filename);
|
||||
fASTInclude= inclusionStatement;
|
||||
|
@ -49,9 +50,11 @@ class LocationCtxFile extends LocationCtxContainer {
|
|||
final int testEnd= length > 1 ? sequenceNumber + length - 1 : sequenceNumber;
|
||||
final int sequenceEnd= sequenceNumber+length;
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -61,25 +64,21 @@ class LocationCtxFile extends LocationCtxContainer {
|
|||
|
||||
if (child1 == null) {
|
||||
startOffset= sequenceNumber-fSequenceNumber;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
int childSequenceEnd= child1.fSequenceNumber + child1.getSequenceLength();
|
||||
if (sequenceNumber < childSequenceEnd) {
|
||||
startOffset= child1.fOffsetInParent;
|
||||
}
|
||||
else { // start beyond child1
|
||||
} else { // start beyond child1
|
||||
startOffset= child1.fEndOffsetInParent + sequenceNumber - childSequenceEnd;
|
||||
}
|
||||
}
|
||||
if (child2 == null) {
|
||||
endOffset= sequenceEnd - fSequenceNumber;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
int childSequenceEnd= child2.fSequenceNumber + child2.getSequenceLength();
|
||||
if (childSequenceEnd < sequenceEnd) { // beyond child2
|
||||
endOffset= child2.fEndOffsetInParent + sequenceEnd - childSequenceEnd;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
endOffset= child2.fEndOffsetInParent;
|
||||
}
|
||||
}
|
||||
|
@ -109,7 +108,8 @@ class LocationCtxFile extends LocationCtxContainer {
|
|||
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();
|
||||
for (LocationCtx ctx : children) {
|
||||
// context must start before the end of the search range
|
||||
|
@ -119,7 +119,9 @@ class LocationCtxFile extends LocationCtxContainer {
|
|||
if (ctx instanceof LocationCtxMacroExpansion) {
|
||||
// expansion must end after the search start
|
||||
if (ctx.fEndOffsetInParent > offset) {
|
||||
list.add((IASTPreprocessorMacroExpansion) ((LocationCtxMacroExpansion)ctx).getMacroReference().getParent());
|
||||
IASTNode macroExpansion =
|
||||
((LocationCtxMacroExpansion) ctx).getMacroReference().getParent();
|
||||
list.add((IASTPreprocessorMacroExpansion) macroExpansion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,18 +87,15 @@ class LocationCtxMacroExpansion extends LocationCtx {
|
|||
if (info.fTokenOffsetInExpansion == nextToCheck) {
|
||||
if (firstInfo == null || lastInfo == null) {
|
||||
firstInfo= lastInfo= info;
|
||||
}
|
||||
else if (lastInfo.canConcatenate(info)) {
|
||||
} else if (lastInfo.canConcatenate(info)) {
|
||||
lastInfo= info;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
if (++nextToCheck == end) {
|
||||
return firstInfo.createLocation(fLocationMap, lastInfo);
|
||||
}
|
||||
}
|
||||
else if (info.fTokenOffsetInExpansion > nextToCheck) {
|
||||
} else if (info.fTokenOffsetInExpansion > nextToCheck) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -109,5 +106,3 @@ class LocationCtxMacroExpansion extends LocationCtx {
|
|||
return fLocationMap.getNestedMacroReferences((ASTMacroExpansion) fExpansionName.getParent());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -37,13 +37,11 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTProblem;
|
|||
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
|
||||
* objects that are needed to conform with the IAST... interfaces.
|
||||
* Converts the offsets relative to various contexts to the global sequence number. Also creates
|
||||
* and stores objects that are needed to conform with the IAST... interfaces.
|
||||
* @since 5.0
|
||||
*/
|
||||
public class LocationMap implements ILocationResolver {
|
||||
private static final IASTName[] EMPTY_NAMES = {};
|
||||
|
||||
private final LexerOptions fLexerOptions;
|
||||
private String fTranslationUnitPath;
|
||||
private IASTTranslationUnit fTranslationUnit;
|
||||
|
@ -82,8 +80,7 @@ public class LocationMap implements ILocationResolver {
|
|||
ASTMacroDefinition astmacro;
|
||||
if (macro.isFunctionStyle()) {
|
||||
astmacro= new ASTFunctionStyleMacroDefinition(fTranslationUnit, macro, nameloc, expansionOffset);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
astmacro= new ASTMacroDefinition(fTranslationUnit, macro, nameloc, expansionOffset);
|
||||
}
|
||||
fBuiltinMacros.add(astmacro);
|
||||
|
@ -179,7 +176,8 @@ public class LocationMap implements ILocationResolver {
|
|||
final int length= endNumber - nameNumber;
|
||||
|
||||
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);
|
||||
for (IASTName implicitMacroReference : implicitMacroReferences) {
|
||||
ASTMacroReferenceName name = (ASTMacroReferenceName) implicitMacroReference;
|
||||
|
@ -188,7 +186,9 @@ public class LocationMap implements ILocationResolver {
|
|||
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);
|
||||
fCurrentContext= expansionCtx;
|
||||
fLastChildInsertionOffset= 0;
|
||||
|
@ -232,7 +232,8 @@ public class LocationMap implements ILocationResolver {
|
|||
nameOffset= getSequenceNumberForOffset(nameOffset);
|
||||
nameEndOffset= getSequenceNumberForOffset(nameEndOffset);
|
||||
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) {
|
||||
|
@ -244,7 +245,8 @@ public class LocationMap implements ILocationResolver {
|
|||
public void encounterProblem(int id, char[] arg, int offset, int endOffset) {
|
||||
offset= getSequenceNumberForOffset(offset);
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -302,7 +304,8 @@ public class LocationMap implements ILocationResolver {
|
|||
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);
|
||||
condOffset= getSequenceNumberForOffset(condOffset);
|
||||
condEndOffset= getSequenceNumberForOffset(condEndOffset);
|
||||
|
@ -313,7 +316,8 @@ public class LocationMap implements ILocationResolver {
|
|||
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);
|
||||
condOffset= getSequenceNumberForOffset(condOffset);
|
||||
condEndOffset= getSequenceNumberForOffset(condEndOffset);
|
||||
|
@ -324,8 +328,8 @@ public class LocationMap implements ILocationResolver {
|
|||
return ifndef;
|
||||
}
|
||||
|
||||
public ASTIf encounterPoundIf(int startOffset, int condOffset, int condEndOffset, int endOffset, boolean taken,
|
||||
IASTName[] macrosInDefinedExpression) {
|
||||
public ASTIf encounterPoundIf(int startOffset, int condOffset, int condEndOffset, int endOffset,
|
||||
boolean taken, IASTName[] macrosInDefinedExpression) {
|
||||
startOffset= getSequenceNumberForOffset(startOffset);
|
||||
condOffset= getSequenceNumberForOffset(condOffset);
|
||||
condEndOffset= getSequenceNumberForOffset(condEndOffset);
|
||||
|
@ -341,7 +345,8 @@ public class LocationMap implements ILocationResolver {
|
|||
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);
|
||||
nameOffset= getSequenceNumberForOffset(nameOffset);
|
||||
nameEndOffset= getSequenceNumberForOffset(nameEndOffset);
|
||||
|
@ -349,20 +354,23 @@ public class LocationMap implements ILocationResolver {
|
|||
endOffset= getSequenceNumberForOffset(endOffset);
|
||||
ASTPreprocessorNode astMacro;
|
||||
if (!macrodef.isFunctionStyle()) {
|
||||
astMacro= new ASTMacroDefinition(fTranslationUnit, macrodef, startOffset, nameOffset, nameEndOffset, expansionOffset, endOffset, isActive);
|
||||
}
|
||||
else {
|
||||
astMacro= new ASTFunctionStyleMacroDefinition(fTranslationUnit, macrodef, startOffset, nameOffset, nameEndOffset, expansionOffset, endOffset, isActive);
|
||||
astMacro= new ASTMacroDefinition(fTranslationUnit, macrodef, startOffset, nameOffset,
|
||||
nameEndOffset, expansionOffset, endOffset, isActive);
|
||||
} else {
|
||||
astMacro= new ASTFunctionStyleMacroDefinition(fTranslationUnit, macrodef, startOffset,
|
||||
nameOffset, nameEndOffset, expansionOffset, endOffset, isActive);
|
||||
}
|
||||
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);
|
||||
nameOffset= getSequenceNumberForOffset(nameOffset);
|
||||
nameEndOffset= getSequenceNumberForOffset(nameEndOffset);
|
||||
// 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);
|
||||
addMacroReference(undef.getMacroName());
|
||||
}
|
||||
|
@ -559,8 +567,7 @@ public class LocationMap implements ILocationResolver {
|
|||
ASTPreprocessorNode candidate= nodes.get(middle);
|
||||
if (candidate.getOffset() + candidate.getLength() >= sequenceStart) {
|
||||
upper= middle - 1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
lower= middle;
|
||||
}
|
||||
}
|
||||
|
@ -579,8 +586,7 @@ public class LocationMap implements ILocationResolver {
|
|||
}
|
||||
if (candidate.getOffset() + candidate.getLength() >= sequenceStart) {
|
||||
upper= middle - 1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
lower= middle;
|
||||
}
|
||||
}
|
||||
|
@ -600,8 +606,7 @@ public class LocationMap implements ILocationResolver {
|
|||
contexts.addAll(ctx.getChildren());
|
||||
if (contexts.isEmpty()) {
|
||||
ctx= null;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ctx= contexts.removeFirst();
|
||||
}
|
||||
}
|
||||
|
@ -676,7 +681,7 @@ public class LocationMap implements ILocationResolver {
|
|||
|
||||
public IASTName[] getDeclarations(IMacroBinding 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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue