1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Fix warnings.

This commit is contained in:
Markus Schorn 2008-04-11 14:41:41 +00:00
parent 306de14543
commit 822d9030aa
12 changed files with 51 additions and 42 deletions

View file

@ -277,8 +277,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
}
IMacro[] toAdd = config.getAdditionalMacros();
for (int i = 0; i < toAdd.length; i++) {
final IMacro macro = toAdd[i];
for (final IMacro macro : toAdd) {
addMacroDefinition(macro.getSignature(), macro.getExpansion());
}
@ -327,13 +326,13 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
private char[] createSyntheticFile(String[] files) {
int totalLength= 0;
final char[] instruction= "#include <".toCharArray(); //$NON-NLS-1$
for (int i = 0; i < files.length; i++) {
totalLength+= instruction.length + 2 + files[i].length();
for (String file : files) {
totalLength+= instruction.length + 2 + file.length();
}
final char[] buffer= new char[totalLength];
int pos= 0;
for (int i = 0; i < files.length; i++) {
final char[] fileName= files[i].toCharArray();
for (String file : files) {
final char[] fileName= file.toCharArray();
System.arraycopy(instruction, 0, buffer, pos, instruction.length);
pos+= instruction.length;
System.arraycopy(fileName, 0, buffer, pos, fileName.length);
@ -476,9 +475,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
final int tt2= t2.getType();
switch(tt2) {
case IToken.tLSTRING:
isWide= true;
// no break;
case IToken.tSTRING:
isWide= tt2 == IToken.tLSTRING;
if (buf == null) {
buf= new StringBuffer();
appendStringContent(buf, t1);

View file

@ -29,7 +29,6 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ASTNodeSpecification;
@ -38,7 +37,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNodeSpecification;
* Visitor to select nodes by image-location.
* @since 5.0
*/
public class FindNodeByImageLocation extends CPPASTVisitor implements ICASTVisitor, ICPPASTVisitor {
public class FindNodeByImageLocation extends CPPASTVisitor implements ICASTVisitor {
private final int fOffset;
private final int fLength;
private final ASTNodeSpecification<?> fNodeSpec;

View file

@ -15,6 +15,7 @@ import org.eclipse.cdt.core.dom.ast.IASTComment;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTImageLocation;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
@ -130,7 +131,7 @@ public interface ILocationResolver {
int getSequenceNumberForFileOffset(String filePath, int fileOffset);
/**
* @see IASTNode#getRawSignature().
* @see IASTNode#getRawSignature()
*/
char[] getUnpreprocessedSignature(IASTFileLocation loc);

View file

@ -162,6 +162,7 @@ final public class Lexer {
* @param origin parameter for the {@link OffsetLimitReachedException} when it has to be thrown.
* @since 5.0
*/
@SuppressWarnings("fallthrough")
public final int consumeLine(int origin) throws OffsetLimitReachedException {
Token t= fToken;
Token lt= null;
@ -223,11 +224,15 @@ final public class Lexer {
d= nextCharPhase3();
break;
}
// no break;
fOffset= pos;
fCharPhase3= d;
fEndOffset= pos+1;
break;
default:
fOffset= pos;
fCharPhase3= d;
fEndOffset= pos+1;
break;
}
}
@ -640,6 +645,7 @@ final public class Lexer {
fLog.handleProblem(problemID, arg, offset, fOffset);
}
@SuppressWarnings("fallthrough")
private Token headerName(final int start, final boolean expectQuotes) throws OffsetLimitReachedException {
int length= 1;
boolean done = false;
@ -700,6 +706,7 @@ final public class Lexer {
}
}
@SuppressWarnings("fallthrough")
private Token stringLiteral(final int start, final boolean wide) throws OffsetLimitReachedException {
boolean escaped = false;
boolean done = false;
@ -736,6 +743,7 @@ final public class Lexer {
return newToken(wide ? IToken.tLSTRING : IToken.tSTRING, start, length);
}
@SuppressWarnings("fallthrough")
private Token charLiteral(final int start, boolean wide) throws OffsetLimitReachedException {
boolean escaped = false;
boolean done = false;
@ -938,6 +946,7 @@ final public class Lexer {
* Perform phase 1-3: Replace \r\n with \n, handle trigraphs, detect line-splicing.
* Changes fOffset, fEndOffset and fCharPhase3, stateless otherwise.
*/
@SuppressWarnings("fallthrough")
private int nextCharPhase3() {
int pos= fEndOffset;
do {
@ -1025,6 +1034,7 @@ final public class Lexer {
/**
* Returns the endoffset for a line-splice sequence, or -1 if there is none.
*/
@SuppressWarnings("fallthrough")
private int findEndOfLineSpliceSequence(int pos) {
boolean haveBackslash= true;
int result= -1;

View file

@ -14,7 +14,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
@ -45,10 +44,8 @@ class LocationCtxContainer extends LocationCtx {
if (fChildren == null) {
return Collections.emptyList();
}
else {
return fChildren;
}
}
public void addChild(LocationCtx locationCtx) {
if (fChildren == null) {
@ -209,8 +206,7 @@ class LocationCtxContainer extends LocationCtx {
@Override
public void getInclusions(ArrayList<IASTInclusionNode> result) {
if (fChildren != null) {
for (Iterator<LocationCtx> iterator = fChildren.iterator(); iterator.hasNext();) {
LocationCtx ctx= iterator.next();
for (LocationCtx ctx : fChildren) {
if (ctx.getInclusionStatement() != null) {
result.add(new ASTInclusionNode(ctx));
}

View file

@ -83,10 +83,9 @@ class LocationCtxMacroExpansion extends LocationCtx {
int nextToCheck= offset;
ImageLocationInfo firstInfo= null;
ImageLocationInfo lastInfo= null;
for (int i = 0; i < fLocationInfos.length; i++) {
ImageLocationInfo info = fLocationInfos[i];
for (ImageLocationInfo info : fLocationInfos) {
if (info.fTokenOffsetInExpansion == nextToCheck) {
if (lastInfo == null) {
if (firstInfo == null || lastInfo == null) {
firstInfo= lastInfo= info;
}
else if (lastInfo.canConcatenate(info)) {

View file

@ -132,7 +132,7 @@ public class LocationMap implements ILocationResolver {
/**
* Creates a name representing an implicit macro expansion. The returned name can be fed into
* {@link #pushMacroExpansion(int, int, int, int, IMacroBinding, IASTName[])}.
* {@link #pushMacroExpansion(int, int, int, int, IMacroBinding, IASTName[], ImageLocationInfo[])}
* @param macro the macro that has been expanded
* @param imageLocationInfo the image-location for the name of the macro.
*/
@ -172,8 +172,8 @@ public class LocationMap implements ILocationResolver {
ASTMacroExpansion expansion= new ASTMacroExpansion(fTranslationUnit, nameNumber, endNumber);
ASTMacroReferenceName explicitRef= new ASTMacroReferenceName(expansion, IASTPreprocessorMacroExpansion.EXPANSION_NAME, nameNumber, nameEndNumber, macro, null);
addMacroReference(explicitRef);
for (int i = 0; i < implicitMacroReferences.length; i++) {
ASTMacroReferenceName name = (ASTMacroReferenceName) implicitMacroReferences[i];
for (IASTName implicitMacroReference : implicitMacroReferences) {
ASTMacroReferenceName name = (ASTMacroReferenceName) implicitMacroReference;
name.setParent(expansion);
name.setOffsetAndLength(nameNumber, length);
addMacroReference(name);
@ -254,8 +254,8 @@ public class LocationMap implements ILocationResolver {
final ASTElif elif = new ASTElif(fTranslationUnit, startOffset, condOffset, condEndOffset, isActive);
fDirectives.add(elif);
for (int i = 0; i < macrosInDefinedExpression.length; i++) {
ASTMacroReferenceName name = (ASTMacroReferenceName) macrosInDefinedExpression[i];
for (IASTName element : macrosInDefinedExpression) {
ASTMacroReferenceName name = (ASTMacroReferenceName) element;
name.setParent(elif);
name.setPropertyInParent(IASTPreprocessorStatement.MACRO_NAME);
addMacroReference(name);
@ -313,8 +313,8 @@ public class LocationMap implements ILocationResolver {
// not using endOffset, compatible with 4.0: endOffset= getSequenceNumberForOffset(endOffset);
final ASTIf astif = new ASTIf(fTranslationUnit, startOffset, condOffset, condEndOffset, isActive);
fDirectives.add(astif);
for (int i = 0; i < macrosInDefinedExpression.length; i++) {
ASTMacroReferenceName name = (ASTMacroReferenceName) macrosInDefinedExpression[i];
for (IASTName element : macrosInDefinedExpression) {
ASTMacroReferenceName name = (ASTMacroReferenceName) element;
name.setParent(astif);
name.setPropertyInParent(IASTPreprocessorStatement.MACRO_NAME);
addMacroReference(name);
@ -658,8 +658,7 @@ public class LocationMap implements ILocationResolver {
}
}
IASTPreprocessorMacroDefinition[] defs= getMacroDefinitions();
for (int i = 0; i < defs.length; i++) {
final IASTPreprocessorMacroDefinition def = defs[i];
for (final IASTPreprocessorMacroDefinition def : defs) {
final IASTName name = def.getName();
if (name != null) {
fMacroDefinitionMap.put(name.getBinding(), def);

View file

@ -65,6 +65,7 @@ public class MacroDefinitionParser {
TokenList tl= new TokenList();
Lexer lex= new Lexer(expansionImage, offset, endOffset, new LexerOptions(), ILexerLog.NULL, null);
try {
lex.nextToken(); // consume the start token
new MacroDefinitionParser().parseExpansion(lex, ILexerLog.NULL, null, new char[][]{}, tl);
} catch (OffsetLimitReachedException e) {
}
@ -229,7 +230,7 @@ public class MacroDefinitionParser {
next= param;
break;
}
// no break;
throw new InvalidMacroDefinitionException(name.getCharImage(), name.getOffset(), param.getEndOffset());
default:
throw new InvalidMacroDefinitionException(name.getCharImage(), name.getOffset(), param.getEndOffset());
}
@ -243,6 +244,10 @@ public class MacroDefinitionParser {
return paramList.toArray(new char[paramList.size()][]);
}
/**
* Parses the expansion for a macro, the current token must be the first token of the expansion
* @since 5.0
*/
public void parseExpansion(final Lexer lexer, final ILexerLog log, final char[] name, final char[][] paramList,
TokenList result) throws OffsetLimitReachedException {
boolean needParam= false;

View file

@ -152,7 +152,7 @@ public class MacroExpansionTracker {
Token n;
for (; t != null; l=t, t=n) {
n= (Token) t.getNext();
if (MacroExpander.hasImplicitSpace(l, t)) {
if (l != null && MacroExpander.hasImplicitSpace(l, t)) {
char[] input= getInputForSource(l.fSource, rootInput);
if (input == null) {
buf.append(' ');

View file

@ -66,7 +66,10 @@ abstract class PreprocessorMacro implements IMacroBinding {
return null;
}
public int hasVarArgs() {
/**
* Returns {@link FunctionStyleMacro#NO_VAARGS}
*/
int hasVarArgs() {
return FunctionStyleMacro.NO_VAARGS;
}
@ -149,6 +152,7 @@ class ObjectStyleMacro extends PreprocessorMacro {
fExpansionTokens= new TokenList();
Lexer lex= new Lexer(fExpansion, fExpansionOffset, fEndOffset, lexOptions, ILexerLog.NULL, this);
try {
lex.nextToken(); // consume the start token
mdp.parseExpansion(lex, ILexerLog.NULL, getNameCharArray(), getParameterPlaceholderList(), fExpansionTokens);
} catch (OffsetLimitReachedException e) {
}
@ -249,10 +253,10 @@ class FunctionStyleMacro extends ObjectStyleMacro {
}
/**
* Returns one of {@link #NO_VAARGS}, {@link #VAARGS} or {@link #NAMED_VAARGS}.
* Returns one of {@link FunctionStyleMacro#NO_VAARGS}, {@link #VAARGS} or {@link #NAMED_VAARGS}.
*/
@Override
public int hasVarArgs() {
int hasVarArgs() {
return fHasVarArgs;
}

View file

@ -107,7 +107,7 @@ final class ScannerContext {
}
/**
* Returns the current token from this context. When called before calling {@link #nextPPToken()}
* Returns the current token from this context. When called before calling nextPPToken()
* a token of type {@link Lexer#tBEFORE_INPUT} will be returned.
* @since 5.0
*/

View file

@ -20,11 +20,9 @@ class TokenList {
fFirst= fLast= null;
return first;
}
else {
fFirst= (Token) first.getNext();
return first;
}
}
public final void append(Token t) {
if (fFirst == null) {