Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2008-04-11 14:41:41 +0000
committerMarkus Schorn2008-04-11 14:41:41 +0000
commit822d9030aabe08234345dba34b8cff76a96be04b (patch)
treec906e38f18b2ffe471d224d756fcff1d75670729 /core/org.eclipse.cdt.core
parent306de145437a1f181ef99a50536c9e6094050cce (diff)
downloadorg.eclipse.cdt-822d9030aabe08234345dba34b8cff76a96be04b.tar.gz
org.eclipse.cdt-822d9030aabe08234345dba34b8cff76a96be04b.tar.xz
org.eclipse.cdt-822d9030aabe08234345dba34b8cff76a96be04b.zip
Fix warnings.
Diffstat (limited to 'core/org.eclipse.cdt.core')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java16
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/FindNodeByImageLocation.java3
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ILocationResolver.java3
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java14
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxContainer.java8
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxMacroExpansion.java5
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java17
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroDefinitionParser.java7
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpansionTracker.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/PreprocessorMacro.java10
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContext.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/TokenList.java6
12 files changed, 51 insertions, 42 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java
index 6225e6701b..99ef0bd17e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java
@@ -277,9 +277,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
}
IMacro[] toAdd = config.getAdditionalMacros();
- for (int i = 0; i < toAdd.length; i++) {
- final IMacro macro = toAdd[i];
- addMacroDefinition(macro.getSignature(), macro.getExpansion());
+ for (final IMacro macro : toAdd) {
+ addMacroDefinition(macro.getSignature(), macro.getExpansion());
}
final Map<String, String> macroDict= info.getDefinedSymbols();
@@ -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);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/FindNodeByImageLocation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/FindNodeByImageLocation.java
index 06114cfc9c..669edb6b36 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/FindNodeByImageLocation.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/FindNodeByImageLocation.java
@@ -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;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ILocationResolver.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ILocationResolver.java
index 4981f12177..450d81d282 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ILocationResolver.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ILocationResolver.java
@@ -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);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java
index d5b9b460b1..9e53248fc1 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java
@@ -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,7 +645,8 @@ final public class Lexer {
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;
boolean done = false;
int c= fCharPhase3;
@@ -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;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxContainer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxContainer.java
index 8859eddfe0..ce76be4612 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxContainer.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxContainer.java
@@ -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,9 +44,7 @@ class LocationCtxContainer extends LocationCtx {
if (fChildren == null) {
return Collections.emptyList();
}
- else {
- return fChildren;
- }
+ return fChildren;
}
public void addChild(LocationCtx locationCtx) {
@@ -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));
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxMacroExpansion.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxMacroExpansion.java
index 5346a3f9b4..934c6fabc3 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxMacroExpansion.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxMacroExpansion.java
@@ -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)) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java
index 3483c7a5b7..9cff7875c2 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java
@@ -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);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroDefinitionParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroDefinitionParser.java
index 50edd14168..7c81601e29 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroDefinitionParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroDefinitionParser.java
@@ -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;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpansionTracker.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpansionTracker.java
index fd398014a1..4ca52f1361 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpansionTracker.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpansionTracker.java
@@ -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(' ');
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/PreprocessorMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/PreprocessorMacro.java
index 92708ee66a..12002e383a 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/PreprocessorMacro.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/PreprocessorMacro.java
@@ -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;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContext.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContext.java
index 9b7988c9f6..dc0d01b3a1 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContext.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContext.java
@@ -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
*/
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/TokenList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/TokenList.java
index cbc020bdf2..3d02a1cb9e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/TokenList.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/TokenList.java
@@ -20,10 +20,8 @@ class TokenList {
fFirst= fLast= null;
return first;
}
- else {
- fFirst= (Token) first.getNext();
- return first;
- }
+ fFirst= (Token) first.getNext();
+ return first;
}
public final void append(Token t) {

Back to the top