mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Further progress in making Scanner2 pass the IIncludeTests.
This commit is contained in:
parent
8ce89a5cc0
commit
8c3a9a10b1
3 changed files with 32 additions and 4 deletions
|
@ -76,7 +76,7 @@ public class IIncludeTests extends IntegratedCModelTest {
|
||||||
new String("whitespace_before_hash"),
|
new String("whitespace_before_hash"),
|
||||||
new String("resync_after_bad_parse_1"),
|
new String("resync_after_bad_parse_1"),
|
||||||
new String("resync_after_bad_parse_2"),
|
new String("resync_after_bad_parse_2"),
|
||||||
new String("onetwothree"), // C-spec does not allow this, but that's OK for our present purposes
|
new String("one"), // C-spec does not allow this, but that's OK for our present purposes
|
||||||
new String("resync_after_bad_parse_3"),
|
new String("resync_after_bad_parse_3"),
|
||||||
new String("invalid.h"), // C-spec does not allow this, but that's OK for our present purposes
|
new String("invalid.h"), // C-spec does not allow this, but that's OK for our present purposes
|
||||||
new String("myInclude1.h"),
|
new String("myInclude1.h"),
|
||||||
|
|
|
@ -14,6 +14,7 @@ package org.eclipse.cdt.core.parser.tests.scanner2;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.IGCCToken;
|
import org.eclipse.cdt.core.parser.IGCCToken;
|
||||||
|
@ -25,6 +26,7 @@ import org.eclipse.cdt.core.parser.ParserFactoryError;
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
import org.eclipse.cdt.core.parser.ScannerException;
|
import org.eclipse.cdt.core.parser.ScannerException;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
|
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.QuickParseCallback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
|
@ -1690,4 +1692,15 @@ public class Scanner2Test extends BaseScanner2Test
|
||||||
validateEOF();
|
validateEOF();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testEmptyIncludeDirective() throws Exception
|
||||||
|
{
|
||||||
|
QuickParseCallback qpc = new QuickParseCallback();
|
||||||
|
initializeScanner( "#include \n#include <foo.h>\n", ParserMode.QUICK_PARSE, qpc ); //$NON-NLS-1$
|
||||||
|
validateEOF();
|
||||||
|
Iterator i = qpc.getInclusions();
|
||||||
|
assertTrue( i.hasNext() );
|
||||||
|
IASTInclusion inc = (IASTInclusion) i.next();
|
||||||
|
assertFalse( i.hasNext() );
|
||||||
|
assertEquals( inc.getName(), "foo.h"); //$NON-NLS-1$
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1164,6 +1164,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
||||||
|
|
||||||
int nameLine= 0, startLine= 0, endLine = 0;
|
int nameLine= 0, startLine= 0, endLine = 0;
|
||||||
char c = buffer[pos];
|
char c = buffer[pos];
|
||||||
|
if( c == '\n') return;
|
||||||
if (c == '"') {
|
if (c == '"') {
|
||||||
local = true;
|
local = true;
|
||||||
int start = bufferPos[bufferStackPos] + 1;
|
int start = bufferPos[bufferStackPos] + 1;
|
||||||
|
@ -1229,13 +1230,27 @@ public class Scanner2 implements IScanner, IScannerData {
|
||||||
|
|
||||||
if (expObject != null) {
|
if (expObject != null) {
|
||||||
--bufferPos[bufferStackPos];
|
--bufferPos[bufferStackPos];
|
||||||
|
char [] t = null;
|
||||||
if (expObject instanceof FunctionStyleMacro)
|
if (expObject instanceof FunctionStyleMacro)
|
||||||
{
|
{
|
||||||
filename = new String( handleFunctionStyleMacro((FunctionStyleMacro)expObject, false) );
|
t = handleFunctionStyleMacro((FunctionStyleMacro)expObject, false);
|
||||||
}
|
}
|
||||||
else if ( expObject instanceof ObjectStyleMacro )
|
else if ( expObject instanceof ObjectStyleMacro )
|
||||||
{
|
{
|
||||||
filename = new String( ((ObjectStyleMacro)expObject).expansion );
|
t = ((ObjectStyleMacro)expObject).expansion;
|
||||||
|
}
|
||||||
|
if( t != null )
|
||||||
|
{
|
||||||
|
if( (t[ t.length - 1 ] == t[0] ) && ( t[0] == '\"') )
|
||||||
|
{
|
||||||
|
local = true;
|
||||||
|
filename = new String( t, 1, t.length - 2 );
|
||||||
|
}
|
||||||
|
else if( t[0] == '<' && t[t.length - 1] == '>' )
|
||||||
|
{
|
||||||
|
local = false;
|
||||||
|
filename = new String( t, 1, t.length - 2 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue