1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2011-08-20 21:30:36 -07:00
parent 30ed2ca8c9
commit 41ee60794f
5 changed files with 102 additions and 103 deletions

View file

@ -77,8 +77,7 @@ class LocationCtxContainer extends LocationCtx {
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;
} }
} }
@ -208,8 +207,7 @@ class LocationCtxContainer extends LocationCtx {
} }
if (childSequenceNumber <= sequenceNumber) { if (childSequenceNumber <= sequenceNumber) {
lower= middle + 1; lower= middle + 1;
} } else {
else {
upper= middle; upper= middle;
} }
} }
@ -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);
} }
} }

View file

@ -13,6 +13,7 @@ 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;
@ -49,9 +50,11 @@ class LocationCtxFile extends LocationCtxContainer {
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,25 +64,21 @@ 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;
} }
} }
@ -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);
} }
} }
} }

View file

@ -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());
} }
} }

View file

@ -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);
@ -179,7 +176,8 @@ public class LocationMap implements ILocationResolver {
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());
} }
@ -559,8 +567,7 @@ public class LocationMap implements ILocationResolver {
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;
} }
} }
@ -579,8 +586,7 @@ public class LocationMap implements ILocationResolver {
} }
if (candidate.getOffset() + candidate.getLength() >= sequenceStart) { if (candidate.getOffset() + candidate.getLength() >= sequenceStart) {
upper= middle - 1; upper= middle - 1;
} } else {
else {
lower= middle; lower= middle;
} }
} }
@ -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();
} }
} }
@ -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) {