1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 03:53:21 +02:00

Patch for David Daoust.

Fix #include_next logic in BaseScanner.
This commit is contained in:
John Camelon 2005-01-28 18:52:31 +00:00
parent a1776b3151
commit 1b38920013

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.internal.core.parser.scanner2; package org.eclipse.cdt.internal.core.parser.scanner2;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.HashMap; import java.util.HashMap;
@ -2516,7 +2517,7 @@ abstract class BaseScanner implements IScanner {
skipToNewLine(); skipToNewLine();
} }
protected void handlePPInclude(int pos2, boolean next, int startingLineNumber) { protected void handlePPInclude(int pos2, boolean include_next, int startingLineNumber) {
char[] buffer = bufferStack[bufferStackPos]; char[] buffer = bufferStack[bufferStackPos];
int limit = bufferLimit[bufferStackPos]; int limit = bufferLimit[bufferStackPos];
@ -2535,13 +2536,17 @@ abstract class BaseScanner implements IScanner {
int nameLine = 0, endLine = 0; int nameLine = 0, endLine = 0;
char c = buffer[pos]; char c = buffer[pos];
if (c == '\n') int start;
int length;
switch (c) {
case '\n' :
return; return;
if (c == '"') { case '"' :
nameLine = getLineNumber(bufferPos[bufferStackPos]); nameLine = getLineNumber(bufferPos[bufferStackPos]);
local = true; local = true;
int start = bufferPos[bufferStackPos] + 1; start = bufferPos[bufferStackPos] + 1;
int length = 0; length = 0;
boolean escaped = false; boolean escaped = false;
while (++bufferPos[bufferStackPos] < limit) { while (++bufferPos[bufferStackPos] < limit) {
++length; ++length;
@ -2561,11 +2566,12 @@ abstract class BaseScanner implements IScanner {
nameOffset = start; nameOffset = start;
nameEndOffset = start + length; nameEndOffset = start + length;
endOffset = start + length + 1; endOffset = start + length + 1;
} else if (c == '<') { break;
case '<' :
nameLine = getLineNumber(bufferPos[bufferStackPos]); nameLine = getLineNumber(bufferPos[bufferStackPos]);
local = false; local = false;
int start = bufferPos[bufferStackPos] + 1; start = bufferPos[bufferStackPos] + 1;
int length = 0; length = 0;
while (++bufferPos[bufferStackPos] < limit while (++bufferPos[bufferStackPos] < limit
&& buffer[bufferPos[bufferStackPos]] != '>') && buffer[bufferPos[bufferStackPos]] != '>')
@ -2575,7 +2581,8 @@ abstract class BaseScanner implements IScanner {
nameEndOffset = start + length; nameEndOffset = start + length;
filename = new String(buffer, start, length); filename = new String(buffer, start, length);
} else { break;
default:
// handle macro expansions // handle macro expansions
int startPos = pos; int startPos = pos;
int len = 1; int len = 1;
@ -2619,6 +2626,7 @@ abstract class BaseScanner implements IScanner {
} }
} }
} }
break;
} }
if (filename == null || filename == EMPTY_STRING) { if (filename == null || filename == EMPTY_STRING) {
@ -2636,13 +2644,20 @@ abstract class BaseScanner implements IScanner {
EMPTY_CHAR_ARRAY, local, startOffset, startingLineNumber, EMPTY_CHAR_ARRAY, local, startOffset, startingLineNumber,
nameOffset, nameEndOffset, nameLine, endOffset, endLine, false); nameOffset, nameEndOffset, nameLine, endOffset, endLine, false);
quickParsePushPopInclusion(inclusion); quickParsePushPopInclusion(inclusion);
} else { return;
CodeReader reader = null; }
if (local) { CodeReader reader = null;
// create an include path reconciled to the current directory File parentFile = null;
if (local || include_next) {
// we need to know what the current directory is!
File file = new File(String.valueOf(getCurrentFilename())); File file = new File(String.valueOf(getCurrentFilename()));
File parentFile = file.getParentFile(); parentFile = file.getParentFile();
}
if (local && !include_next) {
// create an include path reconciled to the current directory
if (parentFile != null) { if (parentFile != null) {
String absolutePath = parentFile.getAbsolutePath(); String absolutePath = parentFile.getAbsolutePath();
String finalPath = ScannerUtility.createReconciledPath( String finalPath = ScannerUtility.createReconciledPath(
@ -2657,8 +2672,9 @@ abstract class BaseScanner implements IScanner {
pushContext(reader.buffer, new InclusionData(reader, pushContext(reader.buffer, new InclusionData(reader,
createInclusionConstruct(fileNameArray, createInclusionConstruct(fileNameArray,
reader.filename, local, startOffset, reader.filename, local, startOffset,
startingLineNumber, nameOffset, nameEndOffset, startingLineNumber, nameOffset,
nameLine, endOffset, endLine, false))); nameEndOffset, nameLine, endOffset,
endLine, false)));
return; return;
} }
} }
@ -2667,19 +2683,24 @@ abstract class BaseScanner implements IScanner {
// iterate through the include paths // iterate through the include paths
// foundme has odd logic but if we're not include_next, then we are // foundme has odd logic but if we're not include_next, then we are
// looking for the // looking for the
// first occurance, otherwise, we're looking for the one after us // first occurance, otherwise, we're looking for the one after the
boolean foundme = !next; // current directory
boolean foundme = !include_next;
if (includePaths != null) if (includePaths != null)
for (int i = 0; i < includePaths.length; ++i) { for (int i = 0; i < includePaths.length; ++i) {
String finalPath = ScannerUtility.createReconciledPath(
includePaths[i], filename);
if (!foundme) { if (!foundme) {
if (finalPath try {
.equals(((InclusionData) bufferData[bufferStackPos]).reader.filename)) { String path = new File(includePaths[i])
.getCanonicalPath();
String parent = parentFile.getCanonicalPath();
if (path.equals(parent))
foundme = true; foundme = true;
} catch (IOException e) {
}
continue; continue;
} }
} else { String finalPath = ScannerUtility.createReconciledPath(
includePaths[i], filename);
reader = (CodeReader) fileCache.get(finalPath.toCharArray()); reader = (CodeReader) fileCache.get(finalPath.toCharArray());
if (reader == null) { if (reader == null) {
reader = createReaderDuple(finalPath); reader = createReaderDuple(finalPath);
@ -2687,24 +2708,21 @@ abstract class BaseScanner implements IScanner {
fileCache.put(reader.filename, reader); fileCache.put(reader.filename, reader);
} }
if (reader != null) { if (reader != null) {
Object inclusion = createInclusionConstruct(fileNameArray,
reader.filename, local, startOffset,
startingLineNumber, nameOffset, nameEndOffset,
nameLine, endOffset, endLine, false);
pushContext(reader.buffer, new InclusionData(reader, pushContext(reader.buffer, new InclusionData(reader,
inclusion)); createInclusionConstruct(fileNameArray,
reader.filename, local, startOffset,
startingLineNumber, nameOffset,
nameEndOffset, nameLine, endOffset,
endLine, false)));
return; return;
} }
} }
}
if (reader == null) if (reader == null)
handleProblem(IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND, handleProblem(IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND,
startOffset, fileNameArray); startOffset, fileNameArray);
} }
}
/** /**
* @param finalPath * @param finalPath
* @return * @return