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

Further Scanner2 junit fixes.

This commit is contained in:
John Camelon 2004-07-28 19:28:40 +00:00
parent c24ed6aa2a
commit ccb8357725
2 changed files with 57 additions and 13 deletions

View file

@ -1473,7 +1473,6 @@ public class Scanner2Test extends BaseScanner2Test
initializeScanner("#if !defined FOO || FOO < 3\nprintf\n#endif\n"); //$NON-NLS-1$ initializeScanner("#if !defined FOO || FOO < 3\nprintf\n#endif\n"); //$NON-NLS-1$
validateIdentifier("printf"); //$NON-NLS-1$ validateIdentifier("printf"); //$NON-NLS-1$
validateEOF(); validateEOF();
} }
public void testBug56517() throws Exception public void testBug56517() throws Exception

View file

@ -23,6 +23,7 @@ import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.EndOfFileException;
import org.eclipse.cdt.core.parser.IMacroDescriptor; import org.eclipse.cdt.core.parser.IMacroDescriptor;
import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IParserLogService;
import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ISourceElementRequestor;
@ -41,6 +42,7 @@ import org.eclipse.cdt.internal.core.parser.scanner.BranchTracker;
import org.eclipse.cdt.internal.core.parser.scanner.ContextStack; import org.eclipse.cdt.internal.core.parser.scanner.ContextStack;
import org.eclipse.cdt.internal.core.parser.scanner.IScannerContext; import org.eclipse.cdt.internal.core.parser.scanner.IScannerContext;
import org.eclipse.cdt.internal.core.parser.scanner.IScannerData; import org.eclipse.cdt.internal.core.parser.scanner.IScannerData;
import org.eclipse.cdt.internal.core.parser.scanner.ScannerProblemFactory;
import org.eclipse.cdt.internal.core.parser.scanner.ScannerUtility; import org.eclipse.cdt.internal.core.parser.scanner.ScannerUtility;
import org.eclipse.cdt.internal.core.parser.scanner.ScannerUtility.InclusionDirective; import org.eclipse.cdt.internal.core.parser.scanner.ScannerUtility.InclusionDirective;
import org.eclipse.cdt.internal.core.parser.scanner.ScannerUtility.InclusionParseException; import org.eclipse.cdt.internal.core.parser.scanner.ScannerUtility.InclusionParseException;
@ -443,6 +445,19 @@ public class Scanner2 implements IScanner, IScannerData {
continue; continue;
return t; return t;
case '\\':
if (pos + 1 < limit && ( buffer[pos + 1] == 'u' || buffer[pos+1] == 'U' ) )
{
t = scanIdentifier();
if( t instanceof MacroExpansionToken )
continue;
return t;
}
//TODO - handle problem invalid char sequence
//error handling
bufferPos[ bufferStackPos ] += 2;
continue;
case '0': case '0':
case '1': case '1':
case '2': case '2':
@ -726,13 +741,22 @@ public class Scanner2 implements IScanner, IScannerData {
++len; ++len;
continue; continue;
} }
else if( c == '\\' && bufferPos[bufferStackPos] + 1 < buffer.length && buffer[ bufferPos[bufferStackPos] + 1 ] == '\n') else if( c == '\\' && bufferPos[bufferStackPos] + 1 < limit && buffer[ bufferPos[bufferStackPos] + 1 ] == '\n')
{ {
// escaped newline // escaped newline
++bufferPos[bufferStackPos]; ++bufferPos[bufferStackPos];
len += 2; len += 2;
continue; continue;
} }
else if( c == '\\' && ( bufferPos[bufferStackPos] + 1 < limit ) )
{
if (( buffer[ bufferPos[bufferStackPos] + 1 ] == 'u') || buffer[ bufferPos[bufferStackPos] + 1 ] == 'U')
{
++bufferPos[bufferStackPos];
len += 2;
continue;
}
}
break; break;
} }
@ -842,6 +866,11 @@ public class Scanner2 implements IScanner, IScannerData {
escaped = false; escaped = false;
} }
if( bufferPos[ bufferStackPos ] == limit )
{
handleProblem( IProblem.SCANNER_BAD_CHARACTER, start, CharArrayUtils.extract(buffer, start, length) );
return newToken( tokenType, emptyCharArray );
}
char[] image = length > 0 char[] image = length > 0
? CharArrayUtils.extract(buffer, start, length) ? CharArrayUtils.extract(buffer, start, length)
@ -850,6 +879,16 @@ public class Scanner2 implements IScanner, IScannerData {
return newToken(tokenType, image ); return newToken(tokenType, image );
} }
private static final ScannerProblemFactory spf = new ScannerProblemFactory();
/**
* @param scanner_bad_character
*/
private void handleProblem(int id, int startOffset, char [] arg ) {
IProblem p = spf.createProblem( id, startOffset, bufferPos[bufferStackPos], bufferLineNums[bufferStackPos], getCurrentFilename(), arg != null ? arg : emptyCharArray, false, true );
requestor.acceptProblem( p );
}
private IToken scanNumber() { private IToken scanNumber() {
char[] buffer = bufferStack[bufferStackPos]; char[] buffer = bufferStack[bufferStackPos];
int start = bufferPos[bufferStackPos]; int start = bufferPos[bufferStackPos];
@ -1214,7 +1253,12 @@ public class Scanner2 implements IScanner, IScannerData {
if (local) { if (local) {
// create an include path reconciled to the current directory // create an include path reconciled to the current directory
String finalPath = ScannerUtility.createReconciledPath( new File( new String( getCurrentFilename() ) ).getParentFile().getAbsolutePath(), filename ); File file = new File( String.valueOf( getCurrentFilename() ) );
File parentFile = file.getParentFile();
if( parentFile != null )
{
String absolutePath = parentFile.getAbsolutePath();
String finalPath = ScannerUtility.createReconciledPath( absolutePath, filename );
reader = (CodeReader)fileCache.get(finalPath); reader = (CodeReader)fileCache.get(finalPath);
if (reader == null) if (reader == null)
reader = ScannerUtility.createReaderDuple( finalPath, requestor, getWorkingCopies() ); reader = ScannerUtility.createReaderDuple( finalPath, requestor, getWorkingCopies() );
@ -1227,6 +1271,7 @@ public class Scanner2 implements IScanner, IScannerData {
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 looking for the // foundme has odd logic but if we're not include_next, then we are looking for the