mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 397127: Limit raw-string detection to c++ parser.
This commit is contained in:
parent
3602ab4d96
commit
ce1fa180df
7 changed files with 64 additions and 29 deletions
|
@ -7420,4 +7420,9 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
public void testGCCDecltype_397227() throws Exception {
|
public void testGCCDecltype_397227() throws Exception {
|
||||||
parseAndCheckBindings(getAboveComment(), CPP, true);
|
parseAndCheckBindings(getAboveComment(), CPP, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #define macro(R) #R""
|
||||||
|
public void testNoRawStringInPlainC_397127() throws Exception {
|
||||||
|
parseAndCheckBindings(getAboveComment(), ParserLanguage.C, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,10 +27,12 @@ public class LexerTests extends BaseTestCase {
|
||||||
private static final LexerOptions NO_DOLLAR = new LexerOptions();
|
private static final LexerOptions NO_DOLLAR = new LexerOptions();
|
||||||
private static final LexerOptions NO_MINMAX = new LexerOptions();
|
private static final LexerOptions NO_MINMAX = new LexerOptions();
|
||||||
private static final LexerOptions SLASH_PERCENT = new LexerOptions();
|
private static final LexerOptions SLASH_PERCENT = new LexerOptions();
|
||||||
|
private static final LexerOptions CPP_OPTIONS = new LexerOptions();
|
||||||
static {
|
static {
|
||||||
NO_DOLLAR.fSupportDollarInIdentifiers= false;
|
NO_DOLLAR.fSupportDollarInIdentifiers= false;
|
||||||
NO_MINMAX.fSupportMinAndMax= false;
|
NO_MINMAX.fSupportMinAndMax= false;
|
||||||
SLASH_PERCENT.fSupportSlashPercentComments= true;
|
SLASH_PERCENT.fSupportSlashPercentComments= true;
|
||||||
|
CPP_OPTIONS.fSupportRawStringLiterals= true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static String TRIGRAPH_REPLACES_CHARS= "#^[]|{}~\\";
|
static String TRIGRAPH_REPLACES_CHARS= "#^[]|{}~\\";
|
||||||
|
@ -41,7 +43,7 @@ public class LexerTests extends BaseTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Lexer fLexer;
|
private Lexer fLexer;
|
||||||
private TestLexerLog fLog= new TestLexerLog();
|
private final TestLexerLog fLog= new TestLexerLog();
|
||||||
private int fLastEndOffset;
|
private int fLastEndOffset;
|
||||||
|
|
||||||
public LexerTests() {
|
public LexerTests() {
|
||||||
|
@ -576,51 +578,51 @@ public class LexerTests extends BaseTestCase {
|
||||||
|
|
||||||
public void testRawStringLiteral() throws Exception {
|
public void testRawStringLiteral() throws Exception {
|
||||||
String lit= "abc0123\\\"'.:; \\\\ \n\"(";
|
String lit= "abc0123\\\"'.:; \\\\ \n\"(";
|
||||||
init("R\"(" + lit + ")\"");
|
init("R\"(" + lit + ")\"", CPP_OPTIONS);
|
||||||
rstr("", lit);
|
rstr("", lit);
|
||||||
eof();
|
eof();
|
||||||
|
|
||||||
init("LR\"(" + lit + ")\"");
|
init("LR\"(" + lit + ")\"", CPP_OPTIONS);
|
||||||
wrstr("", lit);
|
wrstr("", lit);
|
||||||
eof();
|
eof();
|
||||||
|
|
||||||
init("u8R\"(" + lit + ")\"");
|
init("u8R\"(" + lit + ")\"", CPP_OPTIONS);
|
||||||
utf8rstr("", lit);
|
utf8rstr("", lit);
|
||||||
eof();
|
eof();
|
||||||
|
|
||||||
init("uR\"(" + lit + ")\"");
|
init("uR\"(" + lit + ")\"", CPP_OPTIONS);
|
||||||
utf16rstr("", lit);
|
utf16rstr("", lit);
|
||||||
eof();
|
eof();
|
||||||
|
|
||||||
init("UR\"(" + lit + ")\"");
|
init("UR\"(" + lit + ")\"", CPP_OPTIONS);
|
||||||
utf32rstr("", lit);
|
utf32rstr("", lit);
|
||||||
eof();
|
eof();
|
||||||
|
|
||||||
init("R\"ut");
|
init("R\"ut", CPP_OPTIONS);
|
||||||
problem(IProblem.SCANNER_UNBOUNDED_STRING, "R\"ut");
|
problem(IProblem.SCANNER_UNBOUNDED_STRING, "R\"ut");
|
||||||
token(IToken.tSTRING, "R\"ut");
|
token(IToken.tSTRING, "R\"ut");
|
||||||
eof();
|
eof();
|
||||||
|
|
||||||
init("LR\"(ut");
|
init("LR\"(ut", CPP_OPTIONS);
|
||||||
problem(IProblem.SCANNER_UNBOUNDED_STRING, "LR\"(ut");
|
problem(IProblem.SCANNER_UNBOUNDED_STRING, "LR\"(ut");
|
||||||
token(IToken.tLSTRING, "LR\"(ut");
|
token(IToken.tLSTRING, "LR\"(ut");
|
||||||
eof();
|
eof();
|
||||||
|
|
||||||
init("uR\"p()");
|
init("uR\"p()", CPP_OPTIONS);
|
||||||
problem(IProblem.SCANNER_UNBOUNDED_STRING, "uR\"p()");
|
problem(IProblem.SCANNER_UNBOUNDED_STRING, "uR\"p()");
|
||||||
token(IToken.tUTF16STRING, "uR\"p()");
|
token(IToken.tUTF16STRING, "uR\"p()");
|
||||||
eof();
|
eof();
|
||||||
|
|
||||||
init("UR\"(ut");
|
init("UR\"(ut", CPP_OPTIONS);
|
||||||
problem(IProblem.SCANNER_UNBOUNDED_STRING, "UR\"(ut");
|
problem(IProblem.SCANNER_UNBOUNDED_STRING, "UR\"(ut");
|
||||||
token(IToken.tUTF32STRING, "UR\"(ut");
|
token(IToken.tUTF32STRING, "UR\"(ut");
|
||||||
eof();
|
eof();
|
||||||
|
|
||||||
init("R\"+=(Text)=+\"Text)+=\"");
|
init("R\"+=(Text)=+\"Text)+=\"", CPP_OPTIONS);
|
||||||
rstr("+=", "Text)=+\"Text");
|
rstr("+=", "Text)=+\"Text");
|
||||||
eof();
|
eof();
|
||||||
|
|
||||||
init("UR uR LR u8R U8R\"\"");
|
init("UR uR LR u8R U8R\"\"", CPP_OPTIONS);
|
||||||
id("UR"); ws();
|
id("UR"); ws();
|
||||||
id("uR"); ws();
|
id("uR"); ws();
|
||||||
id("LR"); ws();
|
id("LR"); ws();
|
||||||
|
@ -630,7 +632,7 @@ public class LexerTests extends BaseTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRawStringLiteralInInactiveCode() throws Exception {
|
public void testRawStringLiteralInInactiveCode() throws Exception {
|
||||||
init("start\n" + "inactive: Rbla\n" + "#end");
|
init("start\n" + "inactive: Rbla\n" + "#end", CPP_OPTIONS);
|
||||||
id("start");
|
id("start");
|
||||||
nextDirective();
|
nextDirective();
|
||||||
token(IToken.tPOUND);
|
token(IToken.tPOUND);
|
||||||
|
@ -638,7 +640,7 @@ public class LexerTests extends BaseTestCase {
|
||||||
eof();
|
eof();
|
||||||
|
|
||||||
// raw string containing a directive
|
// raw string containing a directive
|
||||||
init("start\n" + "inactive: uR\"(\n#endif\n)\"\n" + "#end");
|
init("start\n" + "inactive: uR\"(\n#endif\n)\"\n" + "#end", CPP_OPTIONS);
|
||||||
id("start");
|
id("start");
|
||||||
nextDirective();
|
nextDirective();
|
||||||
token(IToken.tPOUND);
|
token(IToken.tPOUND);
|
||||||
|
|
|
@ -29,8 +29,8 @@ public abstract class AbstractScannerExtensionConfiguration implements IScannerE
|
||||||
private CharArrayIntMap fAddPreprocessorKeywords;
|
private CharArrayIntMap fAddPreprocessorKeywords;
|
||||||
|
|
||||||
protected static class MacroDefinition implements IMacro {
|
protected static class MacroDefinition implements IMacro {
|
||||||
private char[] fSignature;
|
private final char[] fSignature;
|
||||||
private char[] fExpansion;
|
private final char[] fExpansion;
|
||||||
|
|
||||||
MacroDefinition(char[] signature, char[] expansion) {
|
MacroDefinition(char[] signature, char[] expansion) {
|
||||||
fSignature= signature;
|
fSignature= signature;
|
||||||
|
@ -103,6 +103,14 @@ public abstract class AbstractScannerExtensionConfiguration implements IScannerE
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 5.5
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean supportRawStringLiterals() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharArrayIntMap getAdditionalPreprocessorKeywords() {
|
public CharArrayIntMap getAdditionalPreprocessorKeywords() {
|
||||||
return fAddPreprocessorKeywords;
|
return fAddPreprocessorKeywords;
|
||||||
|
|
|
@ -109,4 +109,10 @@ public interface IScannerExtensionConfiguration {
|
||||||
* @see "http://publib.boulder.ibm.com/infocenter/comphelp/v101v121/index.jsp?topic=/com.ibm.xlcpp101.aix.doc/language_ref/unicode_standard.html"
|
* @see "http://publib.boulder.ibm.com/infocenter/comphelp/v101v121/index.jsp?topic=/com.ibm.xlcpp101.aix.doc/language_ref/unicode_standard.html"
|
||||||
*/
|
*/
|
||||||
public boolean supportUTFLiterals();
|
public boolean supportUTFLiterals();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Support for C++ raw string literals.
|
||||||
|
* @since 5.5
|
||||||
|
*/
|
||||||
|
public boolean supportRawStringLiterals();
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,4 +113,12 @@ public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfigu
|
||||||
public boolean supportMinAndMaxOperators() {
|
public boolean supportMinAndMaxOperators() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 5.5
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean supportRawStringLiterals() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -290,6 +290,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
||||||
fLexOptions.fSupportMinAndMax = configuration.supportMinAndMaxOperators();
|
fLexOptions.fSupportMinAndMax = configuration.supportMinAndMaxOperators();
|
||||||
fLexOptions.fSupportSlashPercentComments= configuration.supportSlashPercentComments();
|
fLexOptions.fSupportSlashPercentComments= configuration.supportSlashPercentComments();
|
||||||
fLexOptions.fSupportUTFLiterals = configuration.supportUTFLiterals();
|
fLexOptions.fSupportUTFLiterals = configuration.supportUTFLiterals();
|
||||||
|
fLexOptions.fSupportRawStringLiterals = configuration.supportRawStringLiterals();
|
||||||
fLocationMap= new LocationMap(fLexOptions);
|
fLocationMap= new LocationMap(fLexOptions);
|
||||||
fKeywords= new CharArrayIntMap(40, -1);
|
fKeywords= new CharArrayIntMap(40, -1);
|
||||||
fPPKeywords= new CharArrayIntMap(40, -1);
|
fPPKeywords= new CharArrayIntMap(40, -1);
|
||||||
|
|
|
@ -54,6 +54,7 @@ final public class Lexer implements ITokenSequence {
|
||||||
public boolean fCreateImageLocations= true;
|
public boolean fCreateImageLocations= true;
|
||||||
public boolean fSupportSlashPercentComments= false;
|
public boolean fSupportSlashPercentComments= false;
|
||||||
public boolean fSupportUTFLiterals= true;
|
public boolean fSupportUTFLiterals= true;
|
||||||
|
public boolean fSupportRawStringLiterals= false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
|
@ -73,7 +74,7 @@ final public class Lexer implements ITokenSequence {
|
||||||
|
|
||||||
// the input to the lexer
|
// the input to the lexer
|
||||||
private final AbstractCharArray fInput;
|
private final AbstractCharArray fInput;
|
||||||
private int fStart;
|
private final int fStart;
|
||||||
private int fLimit;
|
private int fLimit;
|
||||||
|
|
||||||
// after phase 3 (newline, trigraph, line-splice)
|
// after phase 3 (newline, trigraph, line-splice)
|
||||||
|
@ -267,12 +268,14 @@ final public class Lexer implements ITokenSequence {
|
||||||
case 'L':
|
case 'L':
|
||||||
switch(d) {
|
switch(d) {
|
||||||
case 'R':
|
case 'R':
|
||||||
markPhase3();
|
if (fOptions.fSupportRawStringLiterals) {
|
||||||
if (nextCharPhase3() == '"') {
|
markPhase3();
|
||||||
nextCharPhase3();
|
if (nextCharPhase3() == '"') {
|
||||||
return rawStringLiteral(start, 3, IToken.tLSTRING);
|
nextCharPhase3();
|
||||||
|
return rawStringLiteral(start, 3, IToken.tLSTRING);
|
||||||
|
}
|
||||||
|
restorePhase3();
|
||||||
}
|
}
|
||||||
restorePhase3();
|
|
||||||
break;
|
break;
|
||||||
case '"':
|
case '"':
|
||||||
nextCharPhase3();
|
nextCharPhase3();
|
||||||
|
@ -288,12 +291,14 @@ final public class Lexer implements ITokenSequence {
|
||||||
if (fOptions.fSupportUTFLiterals) {
|
if (fOptions.fSupportUTFLiterals) {
|
||||||
switch(d) {
|
switch(d) {
|
||||||
case 'R':
|
case 'R':
|
||||||
markPhase3();
|
if (fOptions.fSupportRawStringLiterals) {
|
||||||
if (nextCharPhase3() == '"') {
|
markPhase3();
|
||||||
nextCharPhase3();
|
if (nextCharPhase3() == '"') {
|
||||||
return rawStringLiteral(start, 3, c == 'u' ? IToken.tUTF16STRING : IToken.tUTF32STRING);
|
nextCharPhase3();
|
||||||
|
return rawStringLiteral(start, 3, c == 'u' ? IToken.tUTF16STRING : IToken.tUTF32STRING);
|
||||||
|
}
|
||||||
|
restorePhase3();
|
||||||
}
|
}
|
||||||
restorePhase3();
|
|
||||||
break;
|
break;
|
||||||
case '"':
|
case '"':
|
||||||
nextCharPhase3();
|
nextCharPhase3();
|
||||||
|
@ -306,7 +311,7 @@ final public class Lexer implements ITokenSequence {
|
||||||
markPhase3();
|
markPhase3();
|
||||||
switch (nextCharPhase3()) {
|
switch (nextCharPhase3()) {
|
||||||
case 'R':
|
case 'R':
|
||||||
if (nextCharPhase3() == '"') {
|
if (fOptions.fSupportRawStringLiterals && nextCharPhase3() == '"') {
|
||||||
nextCharPhase3();
|
nextCharPhase3();
|
||||||
return rawStringLiteral(start, 4, IToken.tSTRING);
|
return rawStringLiteral(start, 4, IToken.tSTRING);
|
||||||
}
|
}
|
||||||
|
@ -323,7 +328,7 @@ final public class Lexer implements ITokenSequence {
|
||||||
return identifier(start, 1);
|
return identifier(start, 1);
|
||||||
|
|
||||||
case 'R':
|
case 'R':
|
||||||
if (d == '"') {
|
if (fOptions.fSupportRawStringLiterals && d == '"') {
|
||||||
nextCharPhase3();
|
nextCharPhase3();
|
||||||
return rawStringLiteral(start, 2, IToken.tSTRING);
|
return rawStringLiteral(start, 2, IToken.tSTRING);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue