1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-10 17:55:39 +02:00

Bug 286081.

This commit is contained in:
Sergey Prigogin 2009-08-16 23:31:33 +00:00
parent 4b2dc9b25f
commit 44d46d0b79

View file

@ -291,8 +291,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
Keywords.addKeywordsPreprocessor(fPPKeywords);
if (language == ParserLanguage.C) {
Keywords.addKeywordsC(fKeywords);
}
else {
} else {
Keywords.addKeywordsCpp(fKeywords);
}
CharArrayIntMap additionalKeywords= configuration.getAdditionalKeywords();
@ -350,9 +349,9 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
fMacroDictionary.put(__TIME__.getNameCharArray(), __TIME__);
fMacroDictionary.put(__LINE__.getNameCharArray(), __LINE__);
if (lang == ParserLanguage.CPP)
if (lang == ParserLanguage.CPP) {
fMacroDictionary.put(__cplusplus.getNameCharArray(), __cplusplus);
else {
} else {
fMacroDictionary.put(__STDC_HOSTED__.getNameCharArray(), __STDC_HOSTED__);
fMacroDictionary.put(__STDC_VERSION__.getNameCharArray(), __STDC_VERSION__);
}
@ -444,8 +443,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
fLocationMap.registerPredefinedMacro(result);
fMacroDictionary.put(result.getNameCharArray(), result);
return result;
}
catch (Exception e) {
} catch (Exception e) {
fLog.traceLog("Invalid macro definition: '" + String.valueOf(key) + "'"); //$NON-NLS-1$//$NON-NLS-2$
return null;
}
@ -619,7 +617,6 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
return t1;
}
public void skipInactiveCode() throws OffsetLimitReachedException {
final Lexer lexer= fCurrentContext.getLexer();
if (lexer != null) {
@ -864,17 +861,13 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
// The check for bin has to come before float, otherwise binary integers
// with float components get flagged as BAD_FLOATING_POINT
handleProblem(IProblem.SCANNER_BAD_BINARY_FORMAT, image, number.getOffset(), number.getEndOffset());
}
else if (isFloat) {
} else if (isFloat) {
handleProblem(IProblem.SCANNER_BAD_FLOATING_POINT, image, number.getOffset(), number.getEndOffset());
}
else if (isHex) {
} else if (isHex) {
handleProblem(IProblem.SCANNER_BAD_HEX_FORMAT, image, number.getOffset(), number.getEndOffset());
}
else if (isOctal) {
} else if (isOctal) {
handleProblem(IProblem.SCANNER_BAD_OCTAL_FORMAT, image, number.getOffset(), number.getEndOffset());
}
else {
} else {
handleProblem(IProblem.SCANNER_BAD_DECIMAL_FORMAT, image, number.getOffset(), number.getEndOffset());
}
return;
@ -901,9 +894,16 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
}
}
// if we're not include_next, then we are looking for the first occurrence of
// the file, otherwise, we ignore all the paths before the current directory
IncludeSearchPathElement searchAfter= includeNext ? fCurrentContext.getFoundOnPath() : null;
// If we're not include_next, then we are looking for the first occurrence of
// the file, otherwise, we ignore all the paths before the current directory.
IncludeSearchPathElement searchAfter= null;
if (includeNext) {
searchAfter = fCurrentContext.getFoundOnPath();
if (searchAfter == null) {
searchAfter = findFileInIncludePath(currentFile, includeDirective);
}
}
for (IncludeSearchPathElement path : fIncludeSearchPath) {
if (searchAfter != null) {
if (searchAfter.equals(path)) {
@ -928,6 +928,16 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
return null;
}
private IncludeSearchPathElement findFileInIncludePath(String file, String includeDirective) {
for (IncludeSearchPathElement path : fIncludeSearchPath) {
String fileLocation = path.getLocation(includeDirective);
if (file.equals(fileLocation)) {
return path;
}
}
return null;
}
@Override
public String toString() {
StringBuffer buffer = new StringBuffer("Scanner @ file:"); //$NON-NLS-1$
@ -937,22 +947,19 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
return buffer.toString();
}
private void addMacroDefinition(IIndexMacro macro) {
try {
final char[] expansionImage = macro.getExpansionImage();
if (expansionImage == null) {
// this is an undef
fMacroDictionary.remove(macro.getNameCharArray());
}
else {
} else {
PreprocessorMacro result= MacroDefinitionParser.parseMacroDefinition(macro.getNameCharArray(), macro.getParameterList(), expansionImage);
final IASTFileLocation loc= macro.getFileLocation();
fLocationMap.registerMacroFromIndex(result, loc, -1);
fMacroDictionary.put(result.getNameCharArray(), result);
}
}
catch (Exception e) {
} catch (Exception e) {
fLog.traceLog("Invalid macro definition: '" + macro.getName() + "'"); //$NON-NLS-1$//$NON-NLS-2$
}
}
@ -1166,14 +1173,15 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
if (!active) {
// test if the include is inactive just because it was included before (bug 167100)
final IncludeResolution resolved= findInclusion(new String(headerName), userInclude, include_next, getCurrentFilename(), createPathTester);
final IncludeResolution resolved= findInclusion(new String(headerName), userInclude, include_next,
getCurrentFilename(), createPathTester);
if (resolved != null && fCodeReaderFactory.hasFileBeenIncludedInCurrentTranslationUnit(resolved.fLocation)) {
path= resolved.fLocation;
isHeuristic= resolved.fHeuristic;
}
}
else {
final IncludeFileContent fi= findInclusion(new String(headerName), userInclude, include_next, getCurrentFilename(), createCodeReaderTester);
} else {
final IncludeFileContent fi= findInclusion(new String(headerName), userInclude, include_next,
getCurrentFilename(), createCodeReaderTester);
if (fi != null) {
path= fi.getFileLocation();
isHeuristic= fi.isFoundByHeuristics();
@ -1186,8 +1194,10 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
if (reader != null && !isCircularInclusion(path)) {
reported= true;
fAllIncludedFiles.add(path);
ILocationCtx ctx= fLocationMap.pushInclusion(poundOffset, nameOffsets[0], nameOffsets[1], condEndOffset, reader.buffer, path, headerName, userInclude, isHeuristic, fi.isSource());
ScannerContext fctx= new ScannerContext(ctx, fCurrentContext, new Lexer(reader.buffer, fLexOptions, this, this));
ILocationCtx ctx= fLocationMap.pushInclusion(poundOffset, nameOffsets[0], nameOffsets[1],
condEndOffset, reader.buffer, path, headerName, userInclude, isHeuristic, fi.isSource());
ScannerContext fctx= new ScannerContext(ctx, fCurrentContext, new Lexer(reader.buffer,
fLexOptions, this, this));
fctx.setFoundOnPath(fi.getFoundOnPath());
fCurrentContext= fctx;
}
@ -1196,8 +1206,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
case SKIP_FILE:
break;
}
}
else {
} else {
final int len = headerName.length + 2;
StringBuilder name= new StringBuilder(len);
name.append(userInclude ? '"' : '<');