1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Testcase and fix for 162214, line comment after directive

This commit is contained in:
Markus Schorn 2006-11-02 14:54:45 +00:00
parent 92b49872f2
commit fe91086213

View file

@ -2871,7 +2871,7 @@ abstract class BaseScanner implements IScanner {
char[] fileNameArray = filename.toCharArray(); char[] fileNameArray = filename.toCharArray();
// TODO else we need to do macro processing on the rest of the line // TODO else we need to do macro processing on the rest of the line
endLine = getLineNumber(bufferPos[bufferStackPos]); endLine = getLineNumber(bufferPos[bufferStackPos]);
skipToLastBeforeNewline(); skipToNewLine(false, true);
findAndPushInclusion(filename, fileNameArray, local, include_next, startOffset, nameOffset, nameEndOffset, endOffset, startingLineNumber, nameLine, endLine); findAndPushInclusion(filename, fileNameArray, local, include_next, startOffset, nameOffset, nameEndOffset, endOffset, startingLineNumber, nameLine, endLine);
} }
@ -3573,9 +3573,7 @@ abstract class BaseScanner implements IScanner {
if (pos + 1 < limit) { if (pos + 1 < limit) {
if (buffer[pos + 1] == '/') { if (buffer[pos + 1] == '/') {
// C++ comment, skip rest of line // C++ comment, skip rest of line
skipToNewLine(true); skipToNewLine(true, true);
// leave the new line there
--bufferPos[bufferStackPos];
return false; return false;
} else if (buffer[pos + 1] == '*') { } else if (buffer[pos + 1] == '*') {
// C comment, find closing */ // C comment, find closing */
@ -3917,81 +3915,25 @@ abstract class BaseScanner implements IScanner {
} }
protected void skipToNewLine() { protected void skipToNewLine() {
skipToNewLine(false); skipToNewLine(false, false);
}
protected void skipToNewLine(boolean insideComment) {
char[] buffer = bufferStack[bufferStackPos];
int limit = bufferLimit[bufferStackPos];
int pos = ++bufferPos[bufferStackPos];
if ((pos < limit && buffer[pos] == '\n') ||
(pos+1 < limit && buffer[pos] == '\r' && buffer[pos+1] == '\n'))
return;
boolean escaped = false;
while (++bufferPos[bufferStackPos] < limit) {
switch (buffer[bufferPos[bufferStackPos]]) {
case '/':
if (insideComment)
break;
pos = bufferPos[bufferStackPos];
if (pos + 1 < limit && buffer[pos + 1] == '*') {
++bufferPos[bufferStackPos];
while (++bufferPos[bufferStackPos] < limit) {
pos = bufferPos[bufferStackPos];
if (buffer[pos] == '*' && pos + 1 < limit
&& buffer[pos + 1] == '/') {
++bufferPos[bufferStackPos];
break;
}
}
}
break;
case '\\':
escaped = !escaped;
continue;
case '\n':
if (escaped) {
escaped = false;
break;
}
return;
case '\r':
if (escaped && bufferPos[bufferStackPos] < limit
&& buffer[bufferPos[bufferStackPos] + 1] == '\n') {
escaped = false;
bufferPos[bufferStackPos]++;
break;
} else if (!escaped && bufferPos[bufferStackPos] < limit
&& buffer[bufferPos[bufferStackPos] + 1] == '\n') {
// bufferPos[bufferStackPos]++; // Do not want to skip past the \r
return;
}
break;
}
escaped = false;
}
} }
/** /**
* Skips everything up to the next newline. Returns offset for last * Skips everything up to the next newline.
* character that was not a whitespace and no comment.
* @since 4.0
*/ */
protected int skipToLastBeforeNewline() { protected void skipToNewLine(boolean insideComment, boolean stopBefore) {
char[] buffer = bufferStack[bufferStackPos]; char[] buffer = bufferStack[bufferStackPos];
int limit = bufferLimit[bufferStackPos]; int limit = bufferLimit[bufferStackPos];
int pos = bufferPos[bufferStackPos]; int pos = bufferPos[bufferStackPos];
int lastMeaningful= pos;
boolean escaped = false; boolean escaped = false;
boolean inComment= false;
while (++pos < limit) { while (++pos < limit) {
char ch= buffer[pos]; char ch= buffer[pos];
switch (ch) { switch (ch) {
case '/': case '/':
if (insideComment) {
break;
}
if (pos + 1 < limit) { if (pos + 1 < limit) {
char c= buffer[pos + 1]; char c= buffer[pos + 1];
if (c == '*') { if (c == '*') {
@ -4006,45 +3948,35 @@ abstract class BaseScanner implements IScanner {
break; break;
} }
else if (c == '/') { else if (c == '/') {
inComment= true; insideComment= true;
} }
} }
if (!inComment) {
lastMeaningful= pos;
}
break; break;
case '\\': case '\\':
escaped = !escaped; escaped = !escaped;
if (!inComment) {
lastMeaningful= pos;
}
continue; continue;
case '\n': case '\n':
if (escaped) { if (escaped) {
escaped = false;
break; break;
} }
bufferPos[bufferStackPos]= pos-1; bufferPos[bufferStackPos]= stopBefore ? pos-1 : pos;
return lastMeaningful; return;
case '\r': case '\r':
if (escaped) { if (pos+1 < limit && buffer[pos+1] == '\n') {
escaped = false; if (escaped) {
break; pos++;
} else if (pos+1 < limit && buffer[pos+1] == '\n') { break;
bufferPos[bufferStackPos]= pos-1; }
return lastMeaningful; bufferPos[bufferStackPos]= stopBefore ? pos-1 : pos;
return;
} }
break; break;
default: default:
if (!inComment && !Character.isWhitespace(ch)) {
lastMeaningful= pos;
}
break; break;
} }
escaped = false; escaped = false;
} }
bufferPos[bufferStackPos]= pos-1; bufferPos[bufferStackPos]= stopBefore ? pos-1 : pos;
return lastMeaningful;
} }
protected char[] handleFunctionStyleMacro(FunctionStyleMacro macro, protected char[] handleFunctionStyleMacro(FunctionStyleMacro macro,