mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 17:26:01 +02:00
Patch for Victor Mozgin.
Fixed PR 39553 : Macros are not expanded in #include statements.
This commit is contained in:
parent
432273ae87
commit
136320038c
8 changed files with 117 additions and 62 deletions
|
@ -1,6 +1,10 @@
|
||||||
2003-07-25 Bogdan Gheorghe
|
2003-07-25 Bogdan Gheorghe
|
||||||
Added new indexer test for refs
|
Added new indexer test for refs
|
||||||
|
|
||||||
|
2003-07-25 Victor Mozgin
|
||||||
|
Moved testBug39553() from ASTFailedTests.java to QuickParseASTTests.java.
|
||||||
|
Fixed IIncludeTest.h and IIncludeTests.java with #include macro tests.
|
||||||
|
|
||||||
2003-07-24 John Camelon
|
2003-07-24 John Camelon
|
||||||
Updated CompleteParseASTTests for Method/Field updates.
|
Updated CompleteParseASTTests for Method/Field updates.
|
||||||
Fixed TortureTest's parser mode switch (was always QuickParsing).
|
Fixed TortureTest's parser mode switch (was always QuickParsing).
|
||||||
|
|
|
@ -145,11 +145,6 @@ public class ASTFailedTests extends BaseASTTest
|
||||||
assertEquals( variable.getName(), "id");
|
assertEquals( variable.getName(), "id");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBug39553() throws Exception
|
|
||||||
{
|
|
||||||
parse("#define COMP_INC \"foobar.h\" \n" + "#include COMP_INC");
|
|
||||||
assertFalse( quickParseCallback.getInclusions().hasNext() );
|
|
||||||
}
|
|
||||||
public void testBug39554() throws Exception
|
public void testBug39554() throws Exception
|
||||||
{
|
{
|
||||||
assertCodeFailsParse("_Pragma(\"foobar\")");
|
assertCodeFailsParse("_Pragma(\"foobar\")");
|
||||||
|
|
|
@ -76,11 +76,11 @@ 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("one"), // C-spec does not allow this, but that's OK for our present purposes
|
new String("onetwothree"), // 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
|
||||||
// TODO: expect new String("MYINCFILE"),
|
new String("myInclude1.h"),
|
||||||
// TODO: expect new String("xstr(INCFILE(2)).h")
|
new String("vers2.h")
|
||||||
};
|
};
|
||||||
assertEquals( getIncludeNameList.length, theIncludes.length );
|
assertEquals( getIncludeNameList.length, theIncludes.length );
|
||||||
for( int i=0; i<getIncludeNameList.length; i++ )
|
for( int i=0; i<getIncludeNameList.length; i++ )
|
||||||
|
|
|
@ -1157,8 +1157,8 @@ public class QuickParseASTTests extends BaseASTTest
|
||||||
|
|
||||||
assertEquals( i.getName(), "stdio.h");
|
assertEquals( i.getName(), "stdio.h");
|
||||||
assertEquals( i.getStartingOffset(), 0 );
|
assertEquals( i.getStartingOffset(), 0 );
|
||||||
assertEquals( i.getNameOffset(), 10 );
|
assertEquals( i.getNameOffset(), 9 );
|
||||||
assertEquals( i.getEndingOffset(), 18 );
|
assertEquals( i.getEndingOffset(), 19 );
|
||||||
|
|
||||||
|
|
||||||
IASTMacro m = (IASTMacro)macros.next();
|
IASTMacro m = (IASTMacro)macros.next();
|
||||||
|
@ -1703,4 +1703,10 @@ public class QuickParseASTTests extends BaseASTTest
|
||||||
|
|
||||||
parse(code.toString());
|
parse(code.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug39553() throws Exception
|
||||||
|
{
|
||||||
|
parse("#define COMP_INC \"foobar.h\" \n" + "#include COMP_INC");
|
||||||
|
assertTrue( quickParseCallback.getInclusions().hasNext() );
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1241,7 +1241,7 @@ public class ScannerTestCase extends BaseScannerTest
|
||||||
initializeScanner( writer.toString() );
|
initializeScanner( writer.toString() );
|
||||||
validateIdentifier("fputs");
|
validateIdentifier("fputs");
|
||||||
validateToken(IToken.tLPAREN);
|
validateToken(IToken.tLPAREN);
|
||||||
validateString("strncmp ( \\\"abc\\\\0d\\\" , \\\"abc\\\" , '\\\\4' ) == 0");
|
validateString("strncmp(\\\"abc\\\\0d\\\", \\\"abc\\\", '\\\\4') == 0");
|
||||||
validateToken(IToken.tCOMMA);
|
validateToken(IToken.tCOMMA);
|
||||||
validateIdentifier("s");
|
validateIdentifier("s");
|
||||||
validateToken(IToken.tRPAREN);
|
validateToken(IToken.tRPAREN);
|
||||||
|
@ -1270,7 +1270,7 @@ public class ScannerTestCase extends BaseScannerTest
|
||||||
try{
|
try{
|
||||||
validateEOF();
|
validateEOF();
|
||||||
} catch ( ScannerException e ){
|
} catch ( ScannerException e ){
|
||||||
assertTrue( e.getMessage().equals( "Ill-formed #include: reached end of line before \"" ));
|
assertTrue( e.getMessage().equals( "Unbounded string" ));
|
||||||
}
|
}
|
||||||
|
|
||||||
initializeScanner( "#include <foo.h" );
|
initializeScanner( "#include <foo.h" );
|
||||||
|
|
|
@ -38,5 +38,5 @@ EMPTY #include "invalid.h"
|
||||||
#define INCFILE(x) vers ## x
|
#define INCFILE(x) vers ## x
|
||||||
#define xstr(x) str(x)
|
#define xstr(x) str(x)
|
||||||
#define str(x) #x
|
#define str(x) #x
|
||||||
#include xstr(INCFILE(2)).h
|
#include xstr(INCFILE(2).h)
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
2003-07-25 Victor Mozgin
|
||||||
|
Fixed PR 39553 : Macros are not expanded in #include statements.
|
||||||
|
|
||||||
2003-07-24 John Camelon
|
2003-07-24 John Camelon
|
||||||
Added COMPLETE_PARSE support for Method and Field declarations and cross-references.
|
Added COMPLETE_PARSE support for Method and Field declarations and cross-references.
|
||||||
Fixed some small ParserSymbolTable bugs.
|
Fixed some small ParserSymbolTable bugs.
|
||||||
|
|
|
@ -1872,70 +1872,111 @@ public class Scanner implements IScanner {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void poundInclude( int beginningOffset ) throws ScannerException {
|
protected void poundInclude( int beginningOffset ) throws ScannerException {
|
||||||
skipOverWhitespace();
|
|
||||||
int c = getChar();
|
|
||||||
int offset;
|
|
||||||
|
|
||||||
if( c == '/' ){
|
|
||||||
c = getChar();
|
|
||||||
if( c == '*' ){
|
|
||||||
skipOverMultilineComment();
|
|
||||||
skipOverWhitespace();
|
|
||||||
c = getChar();
|
|
||||||
} else {
|
|
||||||
if( throwExceptionOnBadPreprocessorSyntax )
|
|
||||||
throw new ScannerException( "Encountered ill-formed #include" );
|
|
||||||
else return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
skipOverWhitespace();
|
||||||
|
int baseOffset = lastContext.getOffset() - lastContext.undoStackSize();
|
||||||
|
String includeLine = getRestOfPreprocessorLine();
|
||||||
StringBuffer fileName = new StringBuffer();
|
StringBuffer fileName = new StringBuffer();
|
||||||
boolean useIncludePath = true;
|
boolean useIncludePath = true;
|
||||||
int endChar = -1;
|
int startOffset = baseOffset;
|
||||||
if( c == '<' ){
|
int endOffset = baseOffset;
|
||||||
endChar = '>';
|
|
||||||
} else if ( c == '"' ){
|
|
||||||
endChar = '"';
|
|
||||||
useIncludePath = false;
|
|
||||||
} else {
|
|
||||||
if( throwExceptionOnBadPreprocessorSyntax )
|
|
||||||
throw new ScannerException( "Encountered ill-formed #include");
|
|
||||||
else return;
|
|
||||||
}
|
|
||||||
|
|
||||||
c = getChar();
|
|
||||||
|
|
||||||
while ((c != '\n') && (c != endChar) && (c != NOCHAR)){
|
|
||||||
if( c == '\r' ){
|
|
||||||
c = getChar();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
fileName.append((char) c);
|
|
||||||
c = getChar();
|
|
||||||
}
|
|
||||||
|
|
||||||
if( c != endChar ){
|
if (! includeLine.equals("")) {
|
||||||
if( throwExceptionOnBadPreprocessorSyntax )
|
Scanner helperScanner = new Scanner(
|
||||||
throw new ScannerException( "Ill-formed #include: reached end of line before " + (char)endChar );
|
new StringReader(includeLine),
|
||||||
else return;
|
null,
|
||||||
|
new ScannerInfo(definitions, originalConfig.getIncludePaths()),
|
||||||
|
problemReporter,
|
||||||
|
translationResult,
|
||||||
|
new NullSourceElementRequestor(),
|
||||||
|
mode);
|
||||||
|
IToken t = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
t = helperScanner.nextToken(false);
|
||||||
|
} catch (EndOfFile eof) {
|
||||||
|
if (throwExceptionOnBadPreprocessorSyntax) {
|
||||||
|
throw new ScannerException( "Encountered ill-formed #include" );
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (t.getType() == IToken.tSTRING) {
|
||||||
|
fileName.append(t.getImage());
|
||||||
|
startOffset = baseOffset + t.getOffset();
|
||||||
|
endOffset = baseOffset + t.getEndOffset();
|
||||||
|
useIncludePath = false;
|
||||||
|
|
||||||
|
// This should throw EOF
|
||||||
|
t = helperScanner.nextToken(false);
|
||||||
|
|
||||||
|
if (throwExceptionOnBadPreprocessorSyntax) {
|
||||||
|
throw new ScannerException( "Encountered ill-formed #include" );
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
} else if (t.getType() == IToken.tLT) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
startOffset = baseOffset + t.getOffset();
|
||||||
|
t = helperScanner.nextToken(false);
|
||||||
|
|
||||||
|
while (t.getType() != IToken.tGT) {
|
||||||
|
fileName.append(t.getImage());
|
||||||
|
helperScanner.skipOverWhitespace();
|
||||||
|
int c = helperScanner.getChar();
|
||||||
|
if (c == '\\') fileName.append('\\'); else helperScanner.ungetChar(c);
|
||||||
|
t = helperScanner.nextToken(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
endOffset = baseOffset + t.getEndOffset();
|
||||||
|
|
||||||
|
} catch (EndOfFile eof) {
|
||||||
|
if (throwExceptionOnBadPreprocessorSyntax) {
|
||||||
|
throw new ScannerException( "Ill-formed #include: reached end of line before >" );
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This should throw EOF
|
||||||
|
t = helperScanner.nextToken(false);
|
||||||
|
|
||||||
|
if (throwExceptionOnBadPreprocessorSyntax) {
|
||||||
|
throw new ScannerException( "Encountered ill-formed #include" );
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
} else if (throwExceptionOnBadPreprocessorSyntax) {
|
||||||
|
throw new ScannerException( "Encountered ill-formed #include" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch( EndOfFile eof )
|
||||||
|
{
|
||||||
|
// good
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (throwExceptionOnBadPreprocessorSyntax) {
|
||||||
|
throw new ScannerException( "Encountered ill-formed #include" );
|
||||||
}
|
}
|
||||||
|
|
||||||
String f = fileName.toString();
|
String f = fileName.toString();
|
||||||
offset = contextStack.getCurrentContext().getOffset() - f.length() - 1; // -1 for the end quote
|
|
||||||
|
|
||||||
if( mode == ParserMode.QUICK_PARSE )
|
if( mode == ParserMode.QUICK_PARSE )
|
||||||
{
|
{
|
||||||
if( requestor != null )
|
if( requestor != null )
|
||||||
{
|
{
|
||||||
IASTInclusion i = astFactory.createInclusion( f, "", !useIncludePath, beginningOffset,
|
IASTInclusion i = astFactory.createInclusion( f, "", !useIncludePath, beginningOffset,
|
||||||
contextStack.getCurrentContext().getOffset(), offset );
|
endOffset, startOffset );
|
||||||
i.enterScope( requestor );
|
i.enterScope( requestor );
|
||||||
i.exitScope( requestor );
|
i.exitScope( requestor );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
handleInclusion(f.trim(), useIncludePath, offset, beginningOffset, contextStack.getCurrentContext().getOffset() );
|
handleInclusion(f.trim(), useIncludePath, startOffset, beginningOffset, endOffset);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void poundDefine(int beginning) throws ScannerException, EndOfFile {
|
protected void poundDefine(int beginning) throws ScannerException, EndOfFile {
|
||||||
|
@ -2097,7 +2138,7 @@ public class Scanner implements IScanner {
|
||||||
|
|
||||||
protected Vector getMacroParameters (String params, boolean forStringizing) throws ScannerException {
|
protected Vector getMacroParameters (String params, boolean forStringizing) throws ScannerException {
|
||||||
|
|
||||||
IScanner tokenizer = ParserFactory.createScanner(new StringReader(params), TEXT, new ScannerInfo( definitions, originalConfig.getIncludePaths() ), mode, new NullSourceElementRequestor(), problemReporter, translationResult );
|
Scanner tokenizer = new Scanner(new StringReader(params), TEXT, new ScannerInfo( definitions, originalConfig.getIncludePaths() ), problemReporter, translationResult, new NullSourceElementRequestor(), mode);
|
||||||
Vector parameterValues = new Vector();
|
Vector parameterValues = new Vector();
|
||||||
Token t = null;
|
Token t = null;
|
||||||
String str = new String();
|
String str = new String();
|
||||||
|
@ -2106,6 +2147,12 @@ public class Scanner implements IScanner {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
int c = tokenizer.getChar();
|
||||||
|
if ((c != ' ') && (c != '\t') && (c != '\r') && (c != '\n')) {
|
||||||
|
space = false;
|
||||||
|
}
|
||||||
|
if (c != NOCHAR) tokenizer.ungetChar(c);
|
||||||
|
|
||||||
t = (Token)(forStringizing ? tokenizer.nextTokenForStringizing() : tokenizer.nextToken(false));
|
t = (Token)(forStringizing ? tokenizer.nextTokenForStringizing() : tokenizer.nextToken(false));
|
||||||
if (t.type == IToken.tLPAREN) {
|
if (t.type == IToken.tLPAREN) {
|
||||||
nParen++;
|
nParen++;
|
||||||
|
@ -2261,7 +2308,7 @@ public class Scanner implements IScanner {
|
||||||
|
|
||||||
if( t.getType() != tPOUNDPOUND && ! pastingNext )
|
if( t.getType() != tPOUNDPOUND && ! pastingNext )
|
||||||
if (i < (numberOfTokens-1)) // Do not append to the last one
|
if (i < (numberOfTokens-1)) // Do not append to the last one
|
||||||
buffer.append( " " );
|
buffer.append( " " );
|
||||||
}
|
}
|
||||||
String finalString = buffer.toString();
|
String finalString = buffer.toString();
|
||||||
contextStack.updateContext(
|
contextStack.updateContext(
|
||||||
|
|
Loading…
Add table
Reference in a new issue