mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-10 18:45:26 +02:00
Cosmetics.
This commit is contained in:
parent
83c26578b8
commit
4545b4c873
6 changed files with 45 additions and 28 deletions
|
@ -167,7 +167,7 @@ public abstract class ASTNode implements IASTNode {
|
||||||
if (floc != null && ast != null) {
|
if (floc != null && ast != null) {
|
||||||
ILocationResolver lr= (ILocationResolver) ast.getAdapter(ILocationResolver.class);
|
ILocationResolver lr= (ILocationResolver) ast.getAdapter(ILocationResolver.class);
|
||||||
if (lr != null) {
|
if (lr != null) {
|
||||||
return lr.getUnpreprocessedSignature(getFileLocation());
|
return lr.getUnpreprocessedSignature(floc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return CharArrayUtils.EMPTY;
|
return CharArrayUtils.EMPTY;
|
||||||
|
|
|
@ -31,7 +31,9 @@ import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||||
class ASTPreprocessorName extends ASTPreprocessorNode implements IASTName {
|
class ASTPreprocessorName extends ASTPreprocessorNode implements IASTName {
|
||||||
private final char[] fName;
|
private final char[] fName;
|
||||||
private final IBinding fBinding;
|
private final IBinding fBinding;
|
||||||
public ASTPreprocessorName(IASTNode parent, ASTNodeProperty property, int startNumber, int endNumber, char[] name, IBinding binding) {
|
|
||||||
|
public ASTPreprocessorName(IASTNode parent, ASTNodeProperty property, int startNumber,
|
||||||
|
int endNumber, char[] name, IBinding binding) {
|
||||||
super(parent, property, startNumber, endNumber);
|
super(parent, property, startNumber, endNumber);
|
||||||
fName= name;
|
fName= name;
|
||||||
fBinding= binding;
|
fBinding= binding;
|
||||||
|
@ -41,31 +43,38 @@ class ASTPreprocessorName extends ASTPreprocessorNode implements IASTName {
|
||||||
public IBinding resolveBinding() {
|
public IBinding resolveBinding() {
|
||||||
return fBinding;
|
return fBinding;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBinding resolvePreBinding() {
|
public IBinding resolvePreBinding() {
|
||||||
return fBinding;
|
return fBinding;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBinding getBinding() {
|
public IBinding getBinding() {
|
||||||
return fBinding;
|
return fBinding;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBinding getPreBinding() {
|
public IBinding getPreBinding() {
|
||||||
return fBinding;
|
return fBinding;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ILinkage getLinkage() {
|
public ILinkage getLinkage() {
|
||||||
final IASTTranslationUnit tu= getTranslationUnit();
|
final IASTTranslationUnit tu= getTranslationUnit();
|
||||||
return tu == null ? Linkage.NO_LINKAGE : tu.getLinkage();
|
return tu == null ? Linkage.NO_LINKAGE : tu.getLinkage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IASTCompletionContext getCompletionContext() {
|
public IASTCompletionContext getCompletionContext() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDeclaration() {
|
public boolean isDeclaration() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDefinition() {
|
public boolean isDefinition() {
|
||||||
return false;
|
return false;
|
||||||
|
@ -74,14 +83,17 @@ class ASTPreprocessorName extends ASTPreprocessorNode implements IASTName {
|
||||||
public boolean isReference() {
|
public boolean isReference() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public char[] toCharArray() {
|
public char[] toCharArray() {
|
||||||
return fName;
|
return fName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public char[] getSimpleID() {
|
public char[] getSimpleID() {
|
||||||
return fName;
|
return fName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public char[] getLookupKey() {
|
public char[] getLookupKey() {
|
||||||
return fName;
|
return fName;
|
||||||
|
@ -91,6 +103,7 @@ class ASTPreprocessorName extends ASTPreprocessorNode implements IASTName {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new String(fName);
|
return new String(fName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBinding(IBinding binding) {assert false;}
|
public void setBinding(IBinding binding) {assert false;}
|
||||||
|
|
||||||
|
@ -98,14 +111,17 @@ class ASTPreprocessorName extends ASTPreprocessorNode implements IASTName {
|
||||||
public int getRoleOfName(boolean allowResolution) {
|
public int getRoleOfName(boolean allowResolution) {
|
||||||
return IASTNameOwner.r_unclear;
|
return IASTNameOwner.r_unclear;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IASTName getLastName() {
|
public IASTName getLastName() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isQualified() {
|
public boolean isQualified() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IASTName copy() {
|
public IASTName copy() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
|
@ -134,18 +150,18 @@ class ASTPreprocessorDefinition extends ASTPreprocessorName {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ASTBuiltinName extends ASTPreprocessorDefinition {
|
class ASTBuiltinName extends ASTPreprocessorDefinition {
|
||||||
private final IASTFileLocation fFileLocation;
|
private final IASTFileLocation fFileLocation;
|
||||||
|
|
||||||
public ASTBuiltinName(IASTNode parent, ASTNodeProperty property, IASTFileLocation floc, char[] name, IBinding binding) {
|
public ASTBuiltinName(IASTNode parent, ASTNodeProperty property, IASTFileLocation floc,
|
||||||
|
char[] name, IBinding binding) {
|
||||||
super(parent, property, -1, -1, name, binding);
|
super(parent, property, -1, -1, name, binding);
|
||||||
fFileLocation= floc;
|
fFileLocation= floc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(IASTNode node) {
|
public boolean contains(IASTNode node) {
|
||||||
return node==this;
|
return node == this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -181,7 +197,8 @@ class ASTBuiltinName extends ASTPreprocessorDefinition {
|
||||||
class ASTMacroReferenceName extends ASTPreprocessorName {
|
class ASTMacroReferenceName extends ASTPreprocessorName {
|
||||||
private ImageLocationInfo fImageLocationInfo;
|
private ImageLocationInfo fImageLocationInfo;
|
||||||
|
|
||||||
public ASTMacroReferenceName(IASTNode parent, ASTNodeProperty property, int offset, int endOffset, IMacroBinding macro, ImageLocationInfo imgLocationInfo) {
|
public ASTMacroReferenceName(IASTNode parent, ASTNodeProperty property,
|
||||||
|
int offset, int endOffset, IMacroBinding macro, ImageLocationInfo imgLocationInfo) {
|
||||||
super(parent, property, offset, endOffset, macro.getNameCharArray(), macro);
|
super(parent, property, offset, endOffset, macro.getNameCharArray(), macro);
|
||||||
fImageLocationInfo= imgLocationInfo;
|
fImageLocationInfo= imgLocationInfo;
|
||||||
}
|
}
|
||||||
|
|
|
@ -509,7 +509,6 @@ class ASTMacroDefinition extends ASTPreprocessorNode implements IASTPreprocessor
|
||||||
fExpansionOffset= expansionOffset;
|
fExpansionOffset= expansionOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getContainingFilename() {
|
public String getContainingFilename() {
|
||||||
if (fName instanceof ASTBuiltinName) {
|
if (fName instanceof ASTBuiltinName) {
|
||||||
|
@ -534,7 +533,7 @@ class ASTMacroDefinition extends ASTPreprocessorNode implements IASTPreprocessor
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRoleForName(IASTName n) {
|
public int getRoleForName(IASTName n) {
|
||||||
return (fName == n) ? r_definition : r_unclear;
|
return fName == n ? r_definition : r_unclear;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -545,6 +544,7 @@ class ASTMacroDefinition extends ASTPreprocessorNode implements IASTPreprocessor
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setExpansion(String exp) {assert false;}
|
public void setExpansion(String exp) {assert false;}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setName(IASTName name) {assert false;}
|
public void setName(IASTName name) {assert false;}
|
||||||
|
|
||||||
|
|
|
@ -1928,10 +1928,10 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final boolean contentAssist = fContentAssistLimit>=0 && fCurrentContext == fRootContext;
|
final boolean contentAssist = fContentAssistLimit >= 0 && fCurrentContext == fRootContext;
|
||||||
final ITokenSequence input= stopAtNewline ? fLineInputToMacroExpansion : fInputToMacroExpansion;
|
final ITokenSequence input= stopAtNewline ? fLineInputToMacroExpansion : fInputToMacroExpansion;
|
||||||
final MacroExpander expander = withinExpansion ? new MacroExpander(this, fMacroDictionary,
|
final MacroExpander expander = withinExpansion ?
|
||||||
fLocationMap, fLexOptions) : fMacroExpander;
|
new MacroExpander(this, fMacroDictionary, fLocationMap, fLexOptions) : fMacroExpander;
|
||||||
TokenList replacement= expander.expand(input, options, macro, identifier, contentAssist, fCurrentContext);
|
TokenList replacement= expander.expand(input, options, macro, identifier, contentAssist, fCurrentContext);
|
||||||
final IASTName[] expansions= expander.clearImplicitExpansions();
|
final IASTName[] expansions= expander.clearImplicitExpansions();
|
||||||
final ImageLocationInfo[] ili= expander.clearImageLocationInfos();
|
final ImageLocationInfo[] ili= expander.clearImageLocationInfos();
|
||||||
|
|
|
@ -57,12 +57,12 @@ public class LocationMap implements ILocationResolver {
|
||||||
private ArrayList<ASTMacroDefinition> fBuiltinMacros= new ArrayList<ASTMacroDefinition>();
|
private ArrayList<ASTMacroDefinition> fBuiltinMacros= new ArrayList<ASTMacroDefinition>();
|
||||||
private ArrayList<ASTPreprocessorName> fMacroReferences= new ArrayList<ASTPreprocessorName>();
|
private ArrayList<ASTPreprocessorName> fMacroReferences= new ArrayList<ASTPreprocessorName>();
|
||||||
|
|
||||||
private LocationCtxFile fRootContext= null;
|
private LocationCtxFile fRootContext;
|
||||||
private LocationCtx fCurrentContext= null;
|
private LocationCtx fCurrentContext;
|
||||||
private int fLastChildInsertionOffset;
|
private int fLastChildInsertionOffset;
|
||||||
|
|
||||||
// stuff computed on demand
|
// stuff computed on demand
|
||||||
private IdentityHashMap<IBinding, IASTPreprocessorMacroDefinition> fMacroDefinitionMap= null;
|
private IdentityHashMap<IBinding, IASTPreprocessorMacroDefinition> fMacroDefinitionMap;
|
||||||
private List<ISkippedIndexedFilesListener> fSkippedFilesListeners= new ArrayList<ISkippedIndexedFilesListener>();
|
private List<ISkippedIndexedFilesListener> fSkippedFilesListeners= new ArrayList<ISkippedIndexedFilesListener>();
|
||||||
|
|
||||||
public LocationMap(LexerOptions lexOptions) {
|
public LocationMap(LexerOptions lexOptions) {
|
||||||
|
|
|
@ -49,6 +49,7 @@ public class MultiMacroExpansionExplorer extends MacroExpansionExplorer {
|
||||||
fOffset= offset;
|
fOffset= offset;
|
||||||
fLength= length;
|
fLength= length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getNodeOffset() { return fOffset; }
|
public int getNodeOffset() { return fOffset; }
|
||||||
@Override
|
@Override
|
||||||
|
@ -87,7 +88,7 @@ public class MultiMacroExpansionExplorer extends MacroExpansionExplorer {
|
||||||
fMacroLocations= getMacroLocations(resolver);
|
fMacroLocations= getMacroLocations(resolver);
|
||||||
fFilePath= tu.getFilePath();
|
fFilePath= tu.getFilePath();
|
||||||
fSource= resolver.getUnpreprocessedSignature(loc);
|
fSource= resolver.getUnpreprocessedSignature(loc);
|
||||||
fBoundaries= new int[count*2+1];
|
fBoundaries= new int[count * 2 + 1];
|
||||||
fDelegates= new SingleMacroExpansionExplorer[count];
|
fDelegates= new SingleMacroExpansionExplorer[count];
|
||||||
|
|
||||||
final int firstOffset= loc.getNodeOffset();
|
final int firstOffset= loc.getNodeOffset();
|
||||||
|
@ -102,12 +103,12 @@ public class MultiMacroExpansionExplorer extends MacroExpansionExplorer {
|
||||||
IASTFileLocation refLoc= expansion.getFileLocation();
|
IASTFileLocation refLoc= expansion.getFileLocation();
|
||||||
int from= refLoc.getNodeOffset()-firstOffset;
|
int from= refLoc.getNodeOffset()-firstOffset;
|
||||||
int to= from+refLoc.getNodeLength();
|
int to= from+refLoc.getNodeLength();
|
||||||
IASTNode enclosing= nodeLocator.findEnclosingNode(from+firstOffset-1, 2);
|
IASTNode enclosing= nodeLocator.findEnclosingNode(from + firstOffset - 1, 2);
|
||||||
boolean isPPCond= enclosing instanceof IASTPreprocessorIfStatement ||
|
boolean isPPCond= enclosing instanceof IASTPreprocessorIfStatement ||
|
||||||
enclosing instanceof IASTPreprocessorElifStatement;
|
enclosing instanceof IASTPreprocessorElifStatement;
|
||||||
fBoundaries[++bidx]= from;
|
fBoundaries[++bidx]= from;
|
||||||
fBoundaries[++bidx]= to;
|
fBoundaries[++bidx]= to;
|
||||||
fDelegates[++didx]= new SingleMacroExpansionExplorer(new String(fSource, from, to-from),
|
fDelegates[++didx]= new SingleMacroExpansionExplorer(new String(fSource, from, to - from),
|
||||||
refs.toArray(new IASTName[refs.size()]), fMacroLocations,
|
refs.toArray(new IASTName[refs.size()]), fMacroLocations,
|
||||||
fFilePath, refLoc.getStartingLineNumber(), isPPCond,
|
fFilePath, refLoc.getStartingLineNumber(), isPPCond,
|
||||||
(LexerOptions) tu.getAdapter(LexerOptions.class));
|
(LexerOptions) tu.getAdapter(LexerOptions.class));
|
||||||
|
@ -182,7 +183,7 @@ public class MultiMacroExpansionExplorer extends MacroExpansionExplorer {
|
||||||
*/
|
*/
|
||||||
private List<ReplaceEdit> combineReplaceEdits(int count) {
|
private List<ReplaceEdit> combineReplaceEdits(int count) {
|
||||||
ArrayList<ReplaceEdit> edits= new ArrayList<ReplaceEdit>();
|
ArrayList<ReplaceEdit> edits= new ArrayList<ReplaceEdit>();
|
||||||
for (int i=0; i < count; i++) {
|
for (int i= 0; i < count; i++) {
|
||||||
IMacroExpansionStep step= fDelegates[i].getFullExpansion();
|
IMacroExpansionStep step= fDelegates[i].getFullExpansion();
|
||||||
shiftAndAddEdits(fBoundaries[2*i], step.getReplacements(), edits);
|
shiftAndAddEdits(fBoundaries[2*i], step.getReplacements(), edits);
|
||||||
}
|
}
|
||||||
|
@ -200,11 +201,10 @@ public class MultiMacroExpansionExplorer extends MacroExpansionExplorer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getExpansionStepCount() {
|
public int getExpansionStepCount() {
|
||||||
int result= 0;
|
int result= 0;
|
||||||
for (int i=0; i < fDelegates.length; i++) {
|
for (int i= 0; i < fDelegates.length; i++) {
|
||||||
result+= fDelegates[i].getExpansionStepCount();
|
result+= fDelegates[i].getExpansionStepCount();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -223,7 +223,7 @@ public class MultiMacroExpansionExplorer extends MacroExpansionExplorer {
|
||||||
StringBuilder before= new StringBuilder();
|
StringBuilder before= new StringBuilder();
|
||||||
before.append(fSource, 0, fBoundaries[0]);
|
before.append(fSource, 0, fBoundaries[0]);
|
||||||
|
|
||||||
for (i=0; i < fDelegates.length; i++) {
|
for (i= 0; i < fDelegates.length; i++) {
|
||||||
final SingleMacroExpansionExplorer delegate = fDelegates[i];
|
final SingleMacroExpansionExplorer delegate = fDelegates[i];
|
||||||
int dsteps= delegate.getExpansionStepCount();
|
int dsteps= delegate.getExpansionStepCount();
|
||||||
if (step < dsteps) {
|
if (step < dsteps) {
|
||||||
|
@ -239,9 +239,9 @@ public class MultiMacroExpansionExplorer extends MacroExpansionExplorer {
|
||||||
}
|
}
|
||||||
|
|
||||||
final int shift= before.length();
|
final int shift= before.length();
|
||||||
final int end= fBoundaries[2*i+1];
|
final int end= fBoundaries[2 * i + 1];
|
||||||
before.append(dresult.getCodeBeforeStep());
|
before.append(dresult.getCodeBeforeStep());
|
||||||
before.append(fSource, end, fSource.length-end);
|
before.append(fSource, end, fSource.length - end);
|
||||||
|
|
||||||
List<ReplaceEdit> replacements= new ArrayList<ReplaceEdit>();
|
List<ReplaceEdit> replacements= new ArrayList<ReplaceEdit>();
|
||||||
shiftAndAddEdits(shift, dresult.getReplacements(), replacements);
|
shiftAndAddEdits(shift, dresult.getReplacements(), replacements);
|
||||||
|
@ -251,9 +251,9 @@ public class MultiMacroExpansionExplorer extends MacroExpansionExplorer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void appendGap(StringBuilder result, int i) {
|
private void appendGap(StringBuilder result, int i) {
|
||||||
int idx= 2*i+1;
|
int idx= 2 * i + 1;
|
||||||
int gapFrom= fBoundaries[idx];
|
int gapFrom= fBoundaries[idx];
|
||||||
int gapTo= fBoundaries[++idx];
|
int gapTo= fBoundaries[++idx];
|
||||||
result.append(fSource, gapFrom, gapTo-gapFrom);
|
result.append(fSource, gapFrom, gapTo - gapFrom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue