Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2014-03-10 02:17:40 +0000
committerSergey Prigogin2014-04-01 02:32:50 +0000
commit27a02639b944d872e4218254dddbf97aa71e0839 (patch)
tree1e4037df6e477d87a07a10e968ef6a1ecee45000
parent6fc76a8adc2ab04e6dab944a4de69fc9da343624 (diff)
downloadorg.eclipse.cdt-27a02639b944d872e4218254dddbf97aa71e0839.tar.gz
org.eclipse.cdt-27a02639b944d872e4218254dddbf97aa71e0839.tar.xz
org.eclipse.cdt-27a02639b944d872e4218254dddbf97aa71e0839.zip
Bug 151329 - Accept '\r' as line delimiter in the lexer
Change-Id: Ie3fb2926270a605db2a8590f6e00c1dc6ab7855a Signed-off-by: Nathan Ridge <zeratul976@hotmail.com> Reviewed-on: https://git.eclipse.org/r/23096 Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com> IP-Clean: Sergey Prigogin <eclipse.sprigogin@gmail.com> Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java23
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java6
2 files changed, 27 insertions, 2 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
index 02fc18b3c28..5c1f393c9d2 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
@@ -121,6 +121,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
@@ -7516,4 +7517,26 @@ public class AST2Tests extends AST2TestBase {
public void testOctalFloatingPointLiteral_394048() throws Exception {
parseAndCheckBindings();
}
+
+ public void testMacOS9LineEnding_151329a() throws Exception {
+ parseAndCheckBindings("int waldo;\r#define bar");
+ }
+
+ public void testMaxOS9LineEnding_151329b() throws Exception {
+ // This tests that if there is an \r\n in a macro continuation,
+ // the \r is not treated as an extra newline. The code
+ // stringifies the macro expansion and arranges for the string
+ // length to show up in a template parameter, whose value is
+ // checked by the test.
+ String code = "#define MACRO foo\\\r\n"
+ + "bar\r\n"
+ + "#define STRINGIFY_(x) #x\r\n"
+ + "#define STRINGIFY(x) STRINGIFY_(x)\r\n"
+ + "template <int N> void f(const char (&)[N]);\r\n"
+ + "int main() { f(STRINGIFY(MACRO)); }\r\n";
+ BindingAssertionHelper helper = new BindingAssertionHelper(code, true);
+ ICPPTemplateInstance f = helper.assertNonProblem("f(STRINGIFY", "f");
+ // 7 characters for "foobar" + the null terminator.
+ assertEquals(7, f.getTemplateArguments()[0].getNonTypeValue().numericalValue().longValue());
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java
index 90c2925af9f..96c8e66469b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java
@@ -1045,14 +1045,16 @@ final public class Lexer implements ITokenSequence {
fEndOffset= ++pos;
fCharPhase3= c;
switch (c) {
- // windows line-ending
case '\r':
+ // windows line-ending
if (fInput.get(pos) == '\n') {
fEndOffset= pos+1;
fCharPhase3= '\n';
return '\n';
}
- return c;
+ // mac os 9 line ending
+ fCharPhase3= '\n';
+ return '\n';
// trigraph sequences
case '?':

Back to the top