From 8c3a9a10b11733c16a40653dab4c88217197d28a Mon Sep 17 00:00:00 2001 From: John Camelon Date: Thu, 5 Aug 2004 17:48:22 +0000 Subject: [PATCH] Further progress in making Scanner2 pass the IIncludeTests. --- .../cdt/core/model/tests/IIncludeTests.java | 2 +- .../parser/tests/scanner2/Scanner2Test.java | 13 ++++++++++++ .../core/parser/scanner2/Scanner2.java | 21 ++++++++++++++++--- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/IIncludeTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/IIncludeTests.java index 3eae4cfac86..c6de49a85a6 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/IIncludeTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/IIncludeTests.java @@ -76,7 +76,7 @@ public class IIncludeTests extends IntegratedCModelTest { new String("whitespace_before_hash"), new String("resync_after_bad_parse_1"), 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("invalid.h"), // C-spec does not allow this, but that's OK for our present purposes new String("myInclude1.h"), diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java index 91db16c85f0..2a1420d1b85 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java @@ -14,6 +14,7 @@ package org.eclipse.cdt.core.parser.tests.scanner2; import java.io.StringWriter; import java.io.Writer; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; 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.ScannerException; import org.eclipse.cdt.core.parser.ast.IASTInclusion; +import org.eclipse.cdt.internal.core.parser.QuickParseCallback; /** * @author jcamelon @@ -1690,4 +1692,15 @@ public class Scanner2Test extends BaseScanner2Test validateEOF(); } + public void testEmptyIncludeDirective() throws Exception + { + QuickParseCallback qpc = new QuickParseCallback(); + initializeScanner( "#include \n#include \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$ + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java index 76d673d29f3..3768a747a53 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java @@ -1146,7 +1146,7 @@ public class Scanner2 implements IScanner, IScannerData { } private void handlePPInclude(int pos2, boolean next) { - char[] buffer = bufferStack[bufferStackPos]; + char[] buffer = bufferStack[bufferStackPos]; int limit = bufferLimit[bufferStackPos]; skipOverWhiteSpace(); @@ -1164,6 +1164,7 @@ public class Scanner2 implements IScanner, IScannerData { int nameLine= 0, startLine= 0, endLine = 0; char c = buffer[pos]; + if( c == '\n') return; if (c == '"') { local = true; int start = bufferPos[bufferStackPos] + 1; @@ -1229,13 +1230,27 @@ public class Scanner2 implements IScanner, IScannerData { if (expObject != null) { --bufferPos[bufferStackPos]; + char [] t = null; if (expObject instanceof FunctionStyleMacro) { - filename = new String( handleFunctionStyleMacro((FunctionStyleMacro)expObject, false) ); + t = handleFunctionStyleMacro((FunctionStyleMacro)expObject, false); } 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 ); + } } } }