mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-09 19:43:27 +02:00
Patch for David Daoust.
Fix #include_next logic in BaseScanner.
This commit is contained in:
parent
a1776b3151
commit
1b38920013
1 changed files with 87 additions and 69 deletions
|
@ -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,79 +2644,89 @@ 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;
|
}
|
||||||
|
|
||||||
|
CodeReader reader = null;
|
||||||
|
File parentFile = null;
|
||||||
|
if (local || include_next) {
|
||||||
|
// we need to know what the current directory is!
|
||||||
|
File file = new File(String.valueOf(getCurrentFilename()));
|
||||||
|
parentFile = file.getParentFile();
|
||||||
|
}
|
||||||
|
|
||||||
if (local) {
|
if (local && !include_next) {
|
||||||
// create an include path reconciled to the current directory
|
// create an include path reconciled to the current directory
|
||||||
File file = new File(String.valueOf(getCurrentFilename()));
|
|
||||||
File parentFile = file.getParentFile();
|
if (parentFile != null) {
|
||||||
if (parentFile != null) {
|
String absolutePath = parentFile.getAbsolutePath();
|
||||||
String absolutePath = parentFile.getAbsolutePath();
|
String finalPath = ScannerUtility.createReconciledPath(
|
||||||
String finalPath = ScannerUtility.createReconciledPath(
|
absolutePath, filename);
|
||||||
absolutePath, 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);
|
if (reader != null && reader.filename != null)
|
||||||
if (reader != null && reader.filename != null)
|
fileCache.put(reader.filename, reader);
|
||||||
fileCache.put(reader.filename, reader);
|
}
|
||||||
}
|
if (reader != null) {
|
||||||
if (reader != null) {
|
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,
|
||||||
startingLineNumber, nameOffset, nameEndOffset,
|
nameEndOffset, nameLine, endOffset,
|
||||||
nameLine, endOffset, endLine, false)));
|
endLine, false)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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(
|
if (!foundme) {
|
||||||
includePaths[i], filename);
|
try {
|
||||||
if (!foundme) {
|
String path = new File(includePaths[i])
|
||||||
if (finalPath
|
.getCanonicalPath();
|
||||||
.equals(((InclusionData) bufferData[bufferStackPos]).reader.filename)) {
|
String parent = parentFile.getCanonicalPath();
|
||||||
foundme = true;
|
if (path.equals(parent))
|
||||||
continue;
|
foundme = true;
|
||||||
}
|
} catch (IOException e) {
|
||||||
} else {
|
}
|
||||||
reader = (CodeReader) fileCache.get(finalPath.toCharArray());
|
continue;
|
||||||
if (reader == null) {
|
}
|
||||||
reader = createReaderDuple(finalPath);
|
String finalPath = ScannerUtility.createReconciledPath(
|
||||||
if (reader != null && reader.filename != null)
|
includePaths[i], filename);
|
||||||
fileCache.put(reader.filename, reader);
|
reader = (CodeReader) fileCache.get(finalPath.toCharArray());
|
||||||
}
|
if (reader == null) {
|
||||||
if (reader != null) {
|
reader = createReaderDuple(finalPath);
|
||||||
Object inclusion = createInclusionConstruct(fileNameArray,
|
if (reader != null && reader.filename != null)
|
||||||
reader.filename, local, startOffset,
|
fileCache.put(reader.filename, reader);
|
||||||
startingLineNumber, nameOffset, nameEndOffset,
|
}
|
||||||
nameLine, endOffset, endLine, false);
|
if (reader != null) {
|
||||||
pushContext(reader.buffer, new InclusionData(reader,
|
pushContext(reader.buffer, new InclusionData(reader,
|
||||||
inclusion));
|
createInclusionConstruct(fileNameArray,
|
||||||
return;
|
reader.filename, local, startOffset,
|
||||||
}
|
startingLineNumber, nameOffset,
|
||||||
}
|
nameEndOffset, nameLine, endOffset,
|
||||||
}
|
endLine, false)));
|
||||||
|
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
|
||||||
*/
|
*/
|
||||||
protected abstract CodeReader createReaderDuple(String finalPath);
|
protected abstract CodeReader createReaderDuple(String finalPath);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4301,7 +4319,7 @@ abstract class BaseScanner implements IScanner {
|
||||||
protected ParserLanguage getLanguage() {
|
protected ParserLanguage getLanguage() {
|
||||||
return language;
|
return language;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CodeReader getMainReader()
|
protected CodeReader getMainReader()
|
||||||
{
|
{
|
||||||
if (bufferData != null && bufferData[0] != null
|
if (bufferData != null && bufferData[0] != null
|
||||||
|
|
Loading…
Add table
Reference in a new issue