1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +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,9 +277,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
} }
IMacro[] toAdd = config.getAdditionalMacros(); IMacro[] toAdd = config.getAdditionalMacros();
for (int i = 0; i < toAdd.length; i++) { for (final IMacro macro : toAdd) {
final IMacro macro = toAdd[i]; addMacroDefinition(macro.getSignature(), macro.getExpansion());
addMacroDefinition(macro.getSignature(), macro.getExpansion());
} }
final Map<String, String> macroDict= info.getDefinedSymbols(); final Map<String, String> macroDict= info.getDefinedSymbols();
@ -327,13 +326,13 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
private char[] createSyntheticFile(String[] files) { private char[] createSyntheticFile(String[] files) {
int totalLength= 0; int totalLength= 0;
final char[] instruction= "#include <".toCharArray(); //$NON-NLS-1$ final char[] instruction= "#include <".toCharArray(); //$NON-NLS-1$
for (int i = 0; i < files.length; i++) { for (String file : files) {
totalLength+= instruction.length + 2 + files[i].length(); totalLength+= instruction.length + 2 + file.length();
} }
final char[] buffer= new char[totalLength]; final char[] buffer= new char[totalLength];
int pos= 0; int pos= 0;
for (int i = 0; i < files.length; i++) { for (String file : files) {
final char[] fileName= files[i].toCharArray(); final char[] fileName= file.toCharArray();
System.arraycopy(instruction, 0, buffer, pos, instruction.length); System.arraycopy(instruction, 0, buffer, pos, instruction.length);
pos+= instruction.length; pos+= instruction.length;
System.arraycopy(fileName, 0, buffer, pos, fileName.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(); final int tt2= t2.getType();
switch(tt2) { switch(tt2) {
case IToken.tLSTRING: case IToken.tLSTRING:
isWide= true;
// no break;
case IToken.tSTRING: case IToken.tSTRING:
isWide= tt2 == IToken.tLSTRING;
if (buf == null) { if (buf == null) {
buf= new StringBuffer(); buf= new StringBuffer();
appendStringContent(buf, t1); 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.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; 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.ICPPASTTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; 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.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ASTNodeSpecification; 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. * Visitor to select nodes by image-location.
* @since 5.0 * @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 fOffset;
private final int fLength; private final int fLength;
private final ASTNodeSpecification<?> fNodeSpec; 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.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTImageLocation; import org.eclipse.cdt.core.dom.ast.IASTImageLocation;
import org.eclipse.cdt.core.dom.ast.IASTName; 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.IASTNodeLocation;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
@ -130,7 +131,7 @@ public interface ILocationResolver {
int getSequenceNumberForFileOffset(String filePath, int fileOffset); int getSequenceNumberForFileOffset(String filePath, int fileOffset);
/** /**
* @see IASTNode#getRawSignature(). * @see IASTNode#getRawSignature()
*/ */
char[] getUnpreprocessedSignature(IASTFileLocation loc); 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. * @param origin parameter for the {@link OffsetLimitReachedException} when it has to be thrown.
* @since 5.0 * @since 5.0
*/ */
@SuppressWarnings("fallthrough")
public final int consumeLine(int origin) throws OffsetLimitReachedException { public final int consumeLine(int origin) throws OffsetLimitReachedException {
Token t= fToken; Token t= fToken;
Token lt= null; Token lt= null;
@ -223,11 +224,15 @@ final public class Lexer {
d= nextCharPhase3(); d= nextCharPhase3();
break; break;
} }
// no break; fOffset= pos;
fCharPhase3= d;
fEndOffset= pos+1;
break;
default: default:
fOffset= pos; fOffset= pos;
fCharPhase3= d; fCharPhase3= d;
fEndOffset= pos+1; fEndOffset= pos+1;
break;
} }
} }
@ -640,7 +645,8 @@ final public class Lexer {
fLog.handleProblem(problemID, arg, offset, fOffset); fLog.handleProblem(problemID, arg, offset, fOffset);
} }
private Token headerName(final int start, final boolean expectQuotes) throws OffsetLimitReachedException { @SuppressWarnings("fallthrough")
private Token headerName(final int start, final boolean expectQuotes) throws OffsetLimitReachedException {
int length= 1; int length= 1;
boolean done = false; boolean done = false;
int c= fCharPhase3; int c= fCharPhase3;
@ -700,6 +706,7 @@ final public class Lexer {
} }
} }
@SuppressWarnings("fallthrough")
private Token stringLiteral(final int start, final boolean wide) throws OffsetLimitReachedException { private Token stringLiteral(final int start, final boolean wide) throws OffsetLimitReachedException {
boolean escaped = false; boolean escaped = false;
boolean done = false; boolean done = false;
@ -736,6 +743,7 @@ final public class Lexer {
return newToken(wide ? IToken.tLSTRING : IToken.tSTRING, start, length); return newToken(wide ? IToken.tLSTRING : IToken.tSTRING, start, length);
} }
@SuppressWarnings("fallthrough")
private Token charLiteral(final int start, boolean wide) throws OffsetLimitReachedException { private Token charLiteral(final int start, boolean wide) throws OffsetLimitReachedException {
boolean escaped = false; boolean escaped = false;
boolean done = 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. * Perform phase 1-3: Replace \r\n with \n, handle trigraphs, detect line-splicing.
* Changes fOffset, fEndOffset and fCharPhase3, stateless otherwise. * Changes fOffset, fEndOffset and fCharPhase3, stateless otherwise.
*/ */
@SuppressWarnings("fallthrough")
private int nextCharPhase3() { private int nextCharPhase3() {
int pos= fEndOffset; int pos= fEndOffset;
do { do {
@ -1025,6 +1034,7 @@ final public class Lexer {
/** /**
* Returns the endoffset for a line-splice sequence, or -1 if there is none. * Returns the endoffset for a line-splice sequence, or -1 if there is none.
*/ */
@SuppressWarnings("fallthrough")
private int findEndOfLineSpliceSequence(int pos) { private int findEndOfLineSpliceSequence(int pos) {
boolean haveBackslash= true; boolean haveBackslash= true;
int result= -1; int result= -1;

View file

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

View file

@ -83,10 +83,9 @@ class LocationCtxMacroExpansion extends LocationCtx {
int nextToCheck= offset; int nextToCheck= offset;
ImageLocationInfo firstInfo= null; ImageLocationInfo firstInfo= null;
ImageLocationInfo lastInfo= null; ImageLocationInfo lastInfo= null;
for (int i = 0; i < fLocationInfos.length; i++) { for (ImageLocationInfo info : fLocationInfos) {
ImageLocationInfo info = fLocationInfos[i];
if (info.fTokenOffsetInExpansion == nextToCheck) { if (info.fTokenOffsetInExpansion == nextToCheck) {
if (lastInfo == null) { if (firstInfo == null || lastInfo == null) {
firstInfo= lastInfo= info; firstInfo= lastInfo= info;
} }
else if (lastInfo.canConcatenate(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 * 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 macro the macro that has been expanded
* @param imageLocationInfo the image-location for the name of the macro. * @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); 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 (int i = 0; i < implicitMacroReferences.length; i++) { for (IASTName implicitMacroReference : implicitMacroReferences) {
ASTMacroReferenceName name = (ASTMacroReferenceName) implicitMacroReferences[i]; ASTMacroReferenceName name = (ASTMacroReferenceName) implicitMacroReference;
name.setParent(expansion); name.setParent(expansion);
name.setOffsetAndLength(nameNumber, length); name.setOffsetAndLength(nameNumber, length);
addMacroReference(name); addMacroReference(name);
@ -254,8 +254,8 @@ public class LocationMap implements ILocationResolver {
final ASTElif elif = new ASTElif(fTranslationUnit, startOffset, condOffset, condEndOffset, isActive); final ASTElif elif = new ASTElif(fTranslationUnit, startOffset, condOffset, condEndOffset, isActive);
fDirectives.add(elif); fDirectives.add(elif);
for (int i = 0; i < macrosInDefinedExpression.length; i++) { for (IASTName element : macrosInDefinedExpression) {
ASTMacroReferenceName name = (ASTMacroReferenceName) macrosInDefinedExpression[i]; ASTMacroReferenceName name = (ASTMacroReferenceName) element;
name.setParent(elif); name.setParent(elif);
name.setPropertyInParent(IASTPreprocessorStatement.MACRO_NAME); name.setPropertyInParent(IASTPreprocessorStatement.MACRO_NAME);
addMacroReference(name); addMacroReference(name);
@ -313,8 +313,8 @@ public class LocationMap implements ILocationResolver {
// not using endOffset, compatible with 4.0: endOffset= getSequenceNumberForOffset(endOffset); // not using endOffset, compatible with 4.0: endOffset= getSequenceNumberForOffset(endOffset);
final ASTIf astif = new ASTIf(fTranslationUnit, startOffset, condOffset, condEndOffset, isActive); final ASTIf astif = new ASTIf(fTranslationUnit, startOffset, condOffset, condEndOffset, isActive);
fDirectives.add(astif); fDirectives.add(astif);
for (int i = 0; i < macrosInDefinedExpression.length; i++) { for (IASTName element : macrosInDefinedExpression) {
ASTMacroReferenceName name = (ASTMacroReferenceName) macrosInDefinedExpression[i]; ASTMacroReferenceName name = (ASTMacroReferenceName) element;
name.setParent(astif); name.setParent(astif);
name.setPropertyInParent(IASTPreprocessorStatement.MACRO_NAME); name.setPropertyInParent(IASTPreprocessorStatement.MACRO_NAME);
addMacroReference(name); addMacroReference(name);
@ -658,8 +658,7 @@ public class LocationMap implements ILocationResolver {
} }
} }
IASTPreprocessorMacroDefinition[] defs= getMacroDefinitions(); IASTPreprocessorMacroDefinition[] defs= getMacroDefinitions();
for (int i = 0; i < defs.length; i++) { for (final IASTPreprocessorMacroDefinition def : defs) {
final IASTPreprocessorMacroDefinition def = defs[i];
final IASTName name = def.getName(); final IASTName name = def.getName();
if (name != null) { if (name != null) {
fMacroDefinitionMap.put(name.getBinding(), def); fMacroDefinitionMap.put(name.getBinding(), def);

View file

@ -65,6 +65,7 @@ public class MacroDefinitionParser {
TokenList tl= new TokenList(); TokenList tl= new TokenList();
Lexer lex= new Lexer(expansionImage, offset, endOffset, new LexerOptions(), ILexerLog.NULL, null); Lexer lex= new Lexer(expansionImage, offset, endOffset, new LexerOptions(), ILexerLog.NULL, null);
try { try {
lex.nextToken(); // consume the start token
new MacroDefinitionParser().parseExpansion(lex, ILexerLog.NULL, null, new char[][]{}, tl); new MacroDefinitionParser().parseExpansion(lex, ILexerLog.NULL, null, new char[][]{}, tl);
} catch (OffsetLimitReachedException e) { } catch (OffsetLimitReachedException e) {
} }
@ -229,7 +230,7 @@ public class MacroDefinitionParser {
next= param; next= param;
break; break;
} }
// no break; throw new InvalidMacroDefinitionException(name.getCharImage(), name.getOffset(), param.getEndOffset());
default: default:
throw new InvalidMacroDefinitionException(name.getCharImage(), name.getOffset(), param.getEndOffset()); throw new InvalidMacroDefinitionException(name.getCharImage(), name.getOffset(), param.getEndOffset());
} }
@ -243,6 +244,10 @@ public class MacroDefinitionParser {
return paramList.toArray(new char[paramList.size()][]); 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, public void parseExpansion(final Lexer lexer, final ILexerLog log, final char[] name, final char[][] paramList,
TokenList result) throws OffsetLimitReachedException { TokenList result) throws OffsetLimitReachedException {
boolean needParam= false; boolean needParam= false;

View file

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

View file

@ -66,7 +66,10 @@ abstract class PreprocessorMacro implements IMacroBinding {
return null; return null;
} }
public int hasVarArgs() { /**
* Returns {@link FunctionStyleMacro#NO_VAARGS}
*/
int hasVarArgs() {
return FunctionStyleMacro.NO_VAARGS; return FunctionStyleMacro.NO_VAARGS;
} }
@ -149,6 +152,7 @@ class ObjectStyleMacro extends PreprocessorMacro {
fExpansionTokens= new TokenList(); fExpansionTokens= new TokenList();
Lexer lex= new Lexer(fExpansion, fExpansionOffset, fEndOffset, lexOptions, ILexerLog.NULL, this); Lexer lex= new Lexer(fExpansion, fExpansionOffset, fEndOffset, lexOptions, ILexerLog.NULL, this);
try { try {
lex.nextToken(); // consume the start token
mdp.parseExpansion(lex, ILexerLog.NULL, getNameCharArray(), getParameterPlaceholderList(), fExpansionTokens); mdp.parseExpansion(lex, ILexerLog.NULL, getNameCharArray(), getParameterPlaceholderList(), fExpansionTokens);
} catch (OffsetLimitReachedException e) { } 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 @Override
public int hasVarArgs() { int hasVarArgs() {
return fHasVarArgs; 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. * a token of type {@link Lexer#tBEFORE_INPUT} will be returned.
* @since 5.0 * @since 5.0
*/ */

View file

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