mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
org.eclipse.cdt.core<BR>
Fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=39703<BR> Removed method IScanner.addIncludePath() as it wasn't being used. <BR> Fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=39698<BR> <BR> org.eclipse.cdt.core.tests<BR> Moved testBug39703() from ASTFailedTests to QuickParseASTTest.<BR> Added ScannerTestCase::testBug39698().<BR> Moved testBug39698A() & testBug39698B() from ASTFailedTests to QuickParseASTTest.<BR> Added testBug39698A() & testBug39698B() to CompleteParseASTTest.
This commit is contained in:
parent
22c63f4e56
commit
03144000c4
22 changed files with 246 additions and 66 deletions
|
@ -1,3 +1,9 @@
|
|||
2004-04-21 John Camelon
|
||||
Moved testBug39703() from ASTFailedTests to QuickParseASTTest.
|
||||
Added ScannerTestCase::testBug39698().
|
||||
Moved testBug39698A() & testBug39698B() from ASTFailedTests to QuickParseASTTest.
|
||||
Added testBug39698A() & testBug39698B() to CompleteParseASTTest.
|
||||
|
||||
2004-04-21 Andrew Niefer
|
||||
fox bugs 52695 & 45372
|
||||
added parser/CompleteParseASTSymbolIteratorTest.testUsingDirectives()
|
||||
|
|
|
@ -13,8 +13,6 @@ import java.io.IOException;
|
|||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
|
||||
import org.eclipse.cdt.core.parser.tests.BaseASTTest;
|
||||
/**
|
||||
|
@ -125,14 +123,7 @@ public class ASTFailedTests extends BaseASTTest
|
|||
{
|
||||
assertCodeFailsParse("register int *foo asm (\"a5\");");
|
||||
}
|
||||
public void testBug39698A() throws Exception
|
||||
{
|
||||
assertCodeFailsParse("int c = a <? b;");
|
||||
}
|
||||
public void testBug39698B() throws Exception
|
||||
{
|
||||
assertCodeFailsParse("int c = a >? b;");
|
||||
}
|
||||
|
||||
public void testBug39701A() throws Exception
|
||||
{
|
||||
assertCodeFailsParse("extern template int max (int, int);");
|
||||
|
@ -160,24 +151,6 @@ public class ASTFailedTests extends BaseASTTest
|
|||
}
|
||||
assertCodeFailsFullParse(code.toString());
|
||||
}
|
||||
public void testBug39703() throws Exception
|
||||
{
|
||||
Writer code = new StringWriter();
|
||||
try
|
||||
{
|
||||
code.write(
|
||||
"/* __extension__ enables GNU C mode for the duration of the declaration. */\n");
|
||||
code.write("__extension__ struct G {\n");
|
||||
code.write(" struct { char z; };\n");
|
||||
code.write(" char g;\n");
|
||||
code.write("};\n");
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
}
|
||||
IASTAbstractTypeSpecifierDeclaration abs = (IASTAbstractTypeSpecifierDeclaration)assertSoleDeclaration(code.toString());
|
||||
assertEquals( ((IASTClassSpecifier)abs.getTypeSpecifier()).getName(), "G" );
|
||||
}
|
||||
|
||||
|
||||
public void testBug40422() throws Exception {
|
||||
|
|
|
@ -1598,4 +1598,14 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
|
|||
assertEquals( B.getFriends().next(), N );
|
||||
}
|
||||
|
||||
|
||||
public void testBug39698A() throws Exception
|
||||
{
|
||||
parse("int c = a <? b;");
|
||||
}
|
||||
public void testBug39698B() throws Exception
|
||||
{
|
||||
parse("int c = a >? b;");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2187,4 +2187,31 @@ public class QuickParseASTTests extends BaseASTTest
|
|||
parse("typeof(foo(1)) bar () { return foo(1); }");
|
||||
}
|
||||
|
||||
public void testBug39703() throws Exception
|
||||
{
|
||||
Writer code = new StringWriter();
|
||||
code.write("/* __extension__ enables GNU C mode for the duration of the declaration. */\n");
|
||||
code.write("__extension__ struct G {\n");
|
||||
code.write(" struct { char z; };\n");
|
||||
code.write(" char g;\n");
|
||||
code.write("};\n");
|
||||
IASTAbstractTypeSpecifierDeclaration abs = (IASTAbstractTypeSpecifierDeclaration)assertSoleDeclaration(code.toString());
|
||||
IASTClassSpecifier G = ((IASTClassSpecifier)abs.getTypeSpecifier());
|
||||
assertEquals( G.getName(), "G" );
|
||||
assertEquals( G.getClassKind(), ASTClassKind.STRUCT );
|
||||
Iterator i = G.getDeclarations();
|
||||
assertEquals( ((IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier()).getName(), "" );
|
||||
assertEquals( ((IASTField)i.next()).getName(), "g" );
|
||||
assertFalse( i.hasNext() );
|
||||
}
|
||||
|
||||
public void testBug39698A() throws Exception
|
||||
{
|
||||
parse("int c = a <? b;");
|
||||
}
|
||||
public void testBug39698B() throws Exception
|
||||
{
|
||||
parse("int c = a >? b;");
|
||||
}
|
||||
|
||||
}
|
|
@ -16,6 +16,7 @@ import java.io.Writer;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.parser.IGCCToken;
|
||||
import org.eclipse.cdt.core.parser.IMacroDescriptor;
|
||||
import org.eclipse.cdt.core.parser.IProblem;
|
||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||
|
@ -1533,4 +1534,12 @@ public class ScannerTestCase extends BaseScannerTest
|
|||
validateIdentifier( "ident\\u01bc00AF" );
|
||||
validateEOF();
|
||||
}
|
||||
|
||||
public void testBug39698() throws Exception
|
||||
{
|
||||
initializeScanner( "<? >?");
|
||||
validateToken( IGCCToken.tMIN );
|
||||
validateToken( IGCCToken.tMAX );
|
||||
validateEOF();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
2004-04-21 John Camelon
|
||||
Fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=39703
|
||||
Removed method IScanner.addIncludePath() as it wasn't being used.
|
||||
Fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=39698
|
||||
|
||||
2004-04-21 Andrew Niefer
|
||||
fixing 52695 & 45372
|
||||
- updated CompleteParseASTFactory.createUsingDirective & createUsingDeclaration
|
||||
|
|
|
@ -18,5 +18,7 @@ public interface IGCCToken extends IToken {
|
|||
|
||||
public static final int t_typeof = tLAST + 1;
|
||||
public static final int t___alignof__ = tLAST + 2;
|
||||
public static final int tMAX = tLAST + 3;
|
||||
public static final int tMIN = tLAST + 4;
|
||||
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ public interface IScanner extends IFilenameProvider {
|
|||
public Map getDefinitions();
|
||||
|
||||
public String[] getIncludePaths();
|
||||
public void addIncludePath(String includePath);
|
||||
public void overwriteIncludePath( String [] newIncludePaths );
|
||||
|
||||
public IToken nextToken() throws ScannerException, EndOfFileException;
|
||||
|
|
|
@ -24,6 +24,8 @@ public interface IASTGCCExpression extends IASTExpression {
|
|||
public static final Kind UNARY_ALIGNOF_TYPEID = new Kind( LAST_KIND + 2 );
|
||||
public static final Kind UNARY_TYPEOF_UNARYEXPRESSION = new Kind( LAST_KIND + 3 );
|
||||
public static final Kind UNARY_TYPEOF_TYPEID = new Kind( LAST_KIND + 4 );
|
||||
public static final Kind RELATIONAL_MAX = new Kind( LAST_KIND + 5 );
|
||||
public static final Kind RELATIONAL_MIN = new Kind( LAST_KIND + 6 );
|
||||
|
||||
protected Kind( int kind )
|
||||
{
|
||||
|
|
|
@ -30,12 +30,14 @@ public interface IParserExtension {
|
|||
|
||||
public boolean isValidUnaryExpressionStart( int tokenType );
|
||||
public IASTExpression parseUnaryExpression( IASTScope scope, IParserData data, CompletionKind kind );
|
||||
|
||||
public boolean isValidRelationalExpressionStart( ParserLanguage language, int tokenType );
|
||||
public IASTExpression parseRelationalExpression( IASTScope scope, IParserData data, CompletionKind kind, IASTExpression lhsExpression );
|
||||
/**
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
public boolean canHandleDeclSpecifierSequence(int tokenType );
|
||||
|
||||
public interface IDeclSpecifierExtensionResult
|
||||
{
|
||||
public IToken getFirstToken();
|
||||
|
|
|
@ -20,13 +20,13 @@ import org.eclipse.cdt.internal.core.parser.scanner.IScannerData;
|
|||
public interface IScannerExtension {
|
||||
|
||||
public String initializeMacroValue( IScannerData scannerData, String original );
|
||||
public void setupBuiltInMacros(IScannerData scannerData, ParserLanguage language);
|
||||
public void setupBuiltInMacros(IScannerData scannerData);
|
||||
|
||||
public boolean canHandlePreprocessorDirective( String directive );
|
||||
public void handlePreprocessorDirective( IScannerData scannerData, String directive, String restOfLine );
|
||||
|
||||
public boolean isExtensionKeyword(String tokenImage);
|
||||
public IToken createExtensionToken(String image, IScannerData scannerData);
|
||||
public boolean isExtensionKeyword(ParserLanguage language, String tokenImage);
|
||||
public IToken createExtensionToken(IScannerData scannerData, String image);
|
||||
|
||||
/**
|
||||
* @return
|
||||
|
@ -39,4 +39,10 @@ public interface IScannerExtension {
|
|||
*/
|
||||
public boolean isValidIdentifierStartCharacter(int c);
|
||||
public boolean isValidIdentifierCharacter( int c );
|
||||
/**
|
||||
* @param language TODO
|
||||
* @param query
|
||||
* @return
|
||||
*/
|
||||
public boolean isExtensionOperator(ParserLanguage language, String query);
|
||||
}
|
||||
|
|
|
@ -67,6 +67,7 @@ public class CompletionParser extends ContextualParser implements IParser {
|
|||
*/
|
||||
private Set reconcileKeywords(Set keywords, String prefix) {
|
||||
if( keywords == null ) return null;
|
||||
if( prefix.equals( "")) return keywords; //$NON-NLS-1$
|
||||
Set resultSet = new TreeSet();
|
||||
Iterator i = keywords.iterator();
|
||||
while( i.hasNext() )
|
||||
|
|
|
@ -72,7 +72,7 @@ public class ContextualParser extends CompleteParser {
|
|||
protected IASTNode context;
|
||||
protected IToken finalToken;
|
||||
protected Set keywordSet;
|
||||
protected String functionOrConstructorName = "";
|
||||
protected String functionOrConstructorName = "";//$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* @return
|
||||
|
|
|
@ -1224,6 +1224,11 @@ public class ExpressionParser implements IExpressionParser, IParserData {
|
|||
}
|
||||
break;
|
||||
default :
|
||||
if( extension.isValidRelationalExpressionStart(language, LT(1)))
|
||||
{
|
||||
IASTExpression extensionExpression = extension.parseRelationalExpression(scope, this, kind, firstExpression );
|
||||
if( extensionExpression != null ) return extensionExpression;
|
||||
}
|
||||
return firstExpression;
|
||||
}
|
||||
}
|
||||
|
@ -1233,7 +1238,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
|
|||
* @param expression
|
||||
* @throws BacktrackException
|
||||
*/
|
||||
protected IASTExpression shiftExpression(IASTScope scope, CompletionKind kind) throws BacktrackException, EndOfFileException {
|
||||
public IASTExpression shiftExpression(IASTScope scope, CompletionKind kind) throws BacktrackException, EndOfFileException {
|
||||
IASTExpression firstExpression = additiveExpression(scope,kind);
|
||||
for (;;)
|
||||
{
|
||||
|
@ -1649,7 +1654,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
|
|||
|
||||
try
|
||||
{
|
||||
String signature = "";
|
||||
String signature = "";//$NON-NLS-1$
|
||||
if( start != null && lastToken != null )
|
||||
signature = new TokenDuple( start, lastToken ).toString();
|
||||
return astFactory.createTypeId( scope, kind, isConst, isVolatile, isShort, isLong, isSigned, isUnsigned, isTypename, name, id.getPointerOperators(), id.getArrayModifiers(), signature);
|
||||
|
@ -2885,4 +2890,10 @@ public class ExpressionParser implements IExpressionParser, IParserData {
|
|||
public IToken getLastToken() {
|
||||
return lastToken;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserData#getParserLanguage()
|
||||
*/
|
||||
public final ParserLanguage getParserLanguage() {
|
||||
return language;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ import org.eclipse.cdt.internal.core.parser.ast.complete.gcc.ASTGCCSimpleTypeSpe
|
|||
*/
|
||||
public class GCCParserExtension implements IParserExtension {
|
||||
|
||||
private static final String EMPTY_STRING = "";
|
||||
private static final String EMPTY_STRING = "";//$NON-NLS-1$
|
||||
protected static BacktrackException backtrack = new BacktrackException();
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -269,10 +269,6 @@ public class GCCParserExtension implements IParserExtension {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
// catch( BacktrackException bt )
|
||||
// {
|
||||
//
|
||||
// }
|
||||
catch( EndOfFileException eof )
|
||||
{
|
||||
data.backup( startingPoint );
|
||||
|
@ -319,4 +315,78 @@ public class GCCParserExtension implements IParserExtension {
|
|||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.extension.IParserExtension#isValidRelationalExpressionStart(int)
|
||||
*/
|
||||
public boolean isValidRelationalExpressionStart(ParserLanguage language, int tokenType) {
|
||||
switch( tokenType )
|
||||
{
|
||||
case IGCCToken.tMAX:
|
||||
case IGCCToken.tMIN:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.extension.IParserExtension#parseRelationalExpression(org.eclipse.cdt.core.parser.ast.IASTScope, org.eclipse.cdt.internal.core.parser.IParserData, org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind)
|
||||
*/
|
||||
public IASTExpression parseRelationalExpression(IASTScope scope, IParserData data, CompletionKind kind, IASTExpression lhsExpression) {
|
||||
if( data.getParserLanguage() == ParserLanguage.C ) return null;
|
||||
IToken mark = null;
|
||||
try {
|
||||
mark = data.mark();
|
||||
} catch (EndOfFileException e) {
|
||||
return null;
|
||||
}
|
||||
IASTGCCExpression.Kind expressionKind = null;
|
||||
try
|
||||
{
|
||||
switch( data.LT(1) )
|
||||
{
|
||||
case IGCCToken.tMAX:
|
||||
data.consume( IGCCToken.tMAX );
|
||||
expressionKind = IASTGCCExpression.Kind.RELATIONAL_MAX;
|
||||
break;
|
||||
case IGCCToken.tMIN:
|
||||
data.consume( IGCCToken.tMIN );
|
||||
expressionKind = IASTGCCExpression.Kind.RELATIONAL_MIN;
|
||||
break;
|
||||
default:
|
||||
data.backup( mark );
|
||||
return null;
|
||||
}
|
||||
|
||||
IToken next = data.LA(1);
|
||||
IASTExpression secondExpression = data.shiftExpression(scope,kind);
|
||||
if (next == data.LA(1))
|
||||
{
|
||||
// we did not consume anything
|
||||
// this is most likely an error
|
||||
data.backup(mark);
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
IASTExpression resultExpression = data.getAstFactory().createExpression(
|
||||
scope, expressionKind, lhsExpression, secondExpression, null, null, null, EMPTY_STRING, null );
|
||||
return resultExpression;
|
||||
} catch (ASTSemanticException e1) {
|
||||
data.backup( mark );
|
||||
return null;
|
||||
}
|
||||
|
||||
} catch( EndOfFileException eof )
|
||||
{
|
||||
data.backup( mark );
|
||||
return null;
|
||||
} catch( BacktrackException backtrack )
|
||||
{
|
||||
data.backup( mark );
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.eclipse.cdt.core.parser.BacktrackException;
|
|||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
||||
|
@ -98,4 +99,14 @@ public interface IParserData {
|
|||
* @return
|
||||
*/
|
||||
public IToken getLastToken();
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public abstract ParserLanguage getParserLanguage();
|
||||
/**
|
||||
* @param scope
|
||||
* @param kind
|
||||
* @return
|
||||
*/
|
||||
public IASTExpression shiftExpression(IASTScope scope, CompletionKind kind) throws BacktrackException, EndOfFileException;
|
||||
}
|
|
@ -180,7 +180,7 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.traceLog( "Parser::translationUnit: Unexpected exception occurred : " + e.getMessage() );
|
||||
log.traceLog( "Parser::translationUnit: Unexpected exception occurred : " + e.getMessage() ); //$NON-NLS-1$
|
||||
failParse();
|
||||
}
|
||||
}
|
||||
|
@ -2173,7 +2173,7 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
catch (BacktrackException e)
|
||||
{
|
||||
failParse();
|
||||
TraceUtil.outputTrace( log, "Unexpected Token =", null, image, null, null );
|
||||
TraceUtil.outputTrace( log, "Unexpected Token =", null, image, null, null ); //$NON-NLS-1$
|
||||
consume();
|
||||
// eat this token anyway
|
||||
continue;
|
||||
|
|
|
@ -65,7 +65,7 @@ public class GCCASTExtension implements IASTFactoryExtension {
|
|||
ITokenDuple idExpression, String literal,
|
||||
IASTNewExpressionDescriptor newDescriptor)
|
||||
{
|
||||
return new ASTGCCExpression( kind, lhs, rhs, thirdExpression, typeId, idExpression == null ? "" : idExpression.toString(), literal, newDescriptor );
|
||||
return new ASTGCCExpression( kind, lhs, rhs, thirdExpression, typeId, idExpression == null ? "" : idExpression.toString(), literal, newDescriptor );//$NON-NLS-1$
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.extension.IASTFactoryExtension#canHandleExpressionKind(org.eclipse.cdt.core.parser.ast.IASTExpression.Kind)
|
||||
|
@ -74,7 +74,9 @@ public class GCCASTExtension implements IASTFactoryExtension {
|
|||
if( kind == IASTGCCExpression.Kind.UNARY_ALIGNOF_TYPEID ||
|
||||
kind == IASTGCCExpression.Kind.UNARY_ALIGNOF_UNARYEXPRESSION ||
|
||||
kind == IASTGCCExpression.Kind.UNARY_TYPEOF_UNARYEXPRESSION ||
|
||||
kind == IASTGCCExpression.Kind.UNARY_TYPEOF_TYPEID )
|
||||
kind == IASTGCCExpression.Kind.UNARY_TYPEOF_TYPEID ||
|
||||
kind == IASTGCCExpression.Kind.RELATIONAL_MAX ||
|
||||
kind == IASTGCCExpression.Kind.RELATIONAL_MIN )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
@ -84,7 +86,9 @@ public class GCCASTExtension implements IASTFactoryExtension {
|
|||
public TypeInfo getExpressionResultType(Kind kind, IASTExpression lhs, IASTExpression rhs, IASTTypeId typeId) {
|
||||
TypeInfo info = null;
|
||||
if( kind == IASTGCCExpression.Kind.UNARY_ALIGNOF_TYPEID ||
|
||||
kind == IASTGCCExpression.Kind.UNARY_ALIGNOF_UNARYEXPRESSION )
|
||||
kind == IASTGCCExpression.Kind.UNARY_ALIGNOF_UNARYEXPRESSION ||
|
||||
kind == IASTGCCExpression.Kind.RELATIONAL_MAX ||
|
||||
kind == IASTGCCExpression.Kind.RELATIONAL_MIN )
|
||||
{
|
||||
info = new TypeInfo();
|
||||
info.setType(TypeInfo.t_int);
|
||||
|
@ -127,6 +131,4 @@ public class GCCASTExtension implements IASTFactoryExtension {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public class ContextStack {
|
|||
|
||||
private static class SentinelContext implements IScannerContext {
|
||||
public int read() throws IOException { return '\n'; }
|
||||
public String getFilename() { return ""; }
|
||||
public String getFilename() { return ""; } //$NON-NLS-1$
|
||||
public int getMacroOffset() { return -1; }
|
||||
public int getMacroLength() { return -1; }
|
||||
public int getOffset() { return 0; }
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.eclipse.cdt.internal.core.parser.util.TraceUtil;
|
|||
public class GCCScannerExtension implements IScannerExtension {
|
||||
|
||||
|
||||
|
||||
protected static final String POUND_IDENT = "#ident"; //$NON-NLS-1$
|
||||
protected static final String POUND_WARNING = "#warning"; //$NON-NLS-1$
|
||||
protected static final String POUND_INCLUDE_NEXT = "#include_next"; //$NON-NLS-1$
|
||||
|
@ -59,7 +60,8 @@ public class GCCScannerExtension implements IScannerExtension {
|
|||
private static final List simpleIdentifiersDeclSpec;
|
||||
private static final List simpleIdentifiersAttribute;
|
||||
|
||||
private ParserLanguage language;
|
||||
private static final String __EXTENSION__ = "__extension__"; //$NON-NLS-1$
|
||||
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
|
||||
|
||||
static
|
||||
{
|
||||
|
@ -81,10 +83,9 @@ public class GCCScannerExtension implements IScannerExtension {
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScannerExtension#setupBuiltInMacros()
|
||||
*/
|
||||
public void setupBuiltInMacros(IScannerData scannerData, ParserLanguage language) {
|
||||
this.language = language;
|
||||
public void setupBuiltInMacros(IScannerData scannerData) {
|
||||
|
||||
if( language == ParserLanguage.CPP )
|
||||
if( scannerData.getLanguage() == ParserLanguage.CPP )
|
||||
if( scannerData.getScanner().getDefinition( IScanner.__CPLUSPLUS ) == null )
|
||||
scannerData.getScanner().addDefinition( IScanner.__CPLUSPLUS, new ObjectMacroDescriptor( IScanner.__CPLUSPLUS, "1")); //$NON-NLS-1$
|
||||
|
||||
|
@ -101,6 +102,9 @@ public class GCCScannerExtension implements IScannerExtension {
|
|||
if( scannerData.getScanner().getDefinition( __DECLSPEC) == null )
|
||||
scannerData.getScanner().addDefinition( __DECLSPEC, new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiersDeclSpec, EMPTY_LIST, "" )); //$NON-NLS-1$ $NON-NLS-2$
|
||||
|
||||
if( scannerData.getScanner().getDefinition( __EXTENSION__ ) == null )
|
||||
scannerData.getScanner().addDefinition( __EXTENSION__, new ObjectMacroDescriptor( __EXTENSION__, EMPTY_STRING ));
|
||||
|
||||
setupAlternativeKeyword(scannerData, __CONST__, Keywords.CONST);
|
||||
setupAlternativeKeyword(scannerData, __CONST, Keywords.CONST);
|
||||
setupAlternativeKeyword(scannerData, __INLINE__, Keywords.INLINE);
|
||||
|
@ -109,7 +113,7 @@ public class GCCScannerExtension implements IScannerExtension {
|
|||
setupAlternativeKeyword( scannerData, __RESTRICT, Keywords.RESTRICT);
|
||||
setupAlternativeKeyword( scannerData, __RESTRICT__, Keywords.RESTRICT);
|
||||
setupAlternativeKeyword( scannerData, __TYPEOF__, GCCKeywords.TYPEOF );
|
||||
if( language == ParserLanguage.CPP )
|
||||
if( scannerData.getLanguage() == ParserLanguage.CPP )
|
||||
setupAlternativeKeyword( scannerData, __ASM__, Keywords.ASM );
|
||||
|
||||
}
|
||||
|
@ -225,6 +229,11 @@ public class GCCScannerExtension implements IScannerExtension {
|
|||
|
||||
private static final Map additionalCPPKeywords;
|
||||
private static final Map additionalCKeywords;
|
||||
private static final Map additionalCPPOperators;
|
||||
private static final Map additionalCOperators;
|
||||
private static final String MAX_OPERATOR = ">?"; //$NON-NLS-1$
|
||||
private static final String MIN_OPERATOR = "<?"; //$NON-NLS-1$
|
||||
|
||||
static
|
||||
{
|
||||
additionalCKeywords = new HashMap();
|
||||
|
@ -232,12 +241,18 @@ public class GCCScannerExtension implements IScannerExtension {
|
|||
additionalCKeywords.put( GCCKeywords.TYPEOF, new Integer( IGCCToken.t_typeof ));
|
||||
additionalCPPKeywords = new HashMap(additionalCKeywords);
|
||||
additionalCPPKeywords.put( Keywords.RESTRICT, new Integer( IToken.t_restrict ));
|
||||
|
||||
additionalCOperators = new HashMap();
|
||||
|
||||
additionalCPPOperators = new HashMap();
|
||||
additionalCPPOperators.put( MAX_OPERATOR, new Integer( IGCCToken.tMAX ) );
|
||||
additionalCPPOperators.put( MIN_OPERATOR, new Integer( IGCCToken.tMIN ) );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.extension.IScannerExtension#isExtensionKeyword()
|
||||
*/
|
||||
public boolean isExtensionKeyword(String tokenImage) {
|
||||
public boolean isExtensionKeyword(ParserLanguage language, String tokenImage) {
|
||||
if( language == ParserLanguage.CPP )
|
||||
return ( additionalCPPKeywords.get( tokenImage ) != null );
|
||||
else if( language == ParserLanguage.C )
|
||||
|
@ -248,14 +263,33 @@ public class GCCScannerExtension implements IScannerExtension {
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.extension.IScannerExtension#createExtensionToken()
|
||||
*/
|
||||
public IToken createExtensionToken(String image, IScannerData scannerData) {
|
||||
public IToken createExtensionToken(IScannerData scannerData, String image) {
|
||||
Integer get = null;
|
||||
if( language == ParserLanguage.CPP )
|
||||
if( scannerData.getLanguage() == ParserLanguage.CPP )
|
||||
{
|
||||
get = (Integer) additionalCPPKeywords.get( image );
|
||||
else if( language == ParserLanguage.C )
|
||||
if( get == null )
|
||||
get = (Integer) additionalCPPOperators.get( image );
|
||||
}
|
||||
else if( scannerData.getLanguage() == ParserLanguage.C )
|
||||
{
|
||||
get = (Integer) additionalCKeywords.get( image );
|
||||
if( get == null )
|
||||
get = (Integer) additionalCOperators.get( image );
|
||||
}
|
||||
if( get == null ) return null;
|
||||
return TokenFactory.createToken(get.intValue(),scannerData);
|
||||
return TokenFactory.createToken(get.intValue(),image,scannerData);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.extension.IScannerExtension#isExtensionOperator(java.lang.String)
|
||||
*/
|
||||
public boolean isExtensionOperator(ParserLanguage language, String query) {
|
||||
if( language == ParserLanguage.CPP )
|
||||
return ( additionalCPPOperators.get( query ) != null );
|
||||
else if (language == ParserLanguage.C )
|
||||
return ( additionalCOperators.get( query ) != null );
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -177,7 +177,7 @@ public class Scanner implements IScanner {
|
|||
*/
|
||||
protected void setupBuiltInMacros() {
|
||||
|
||||
scannerExtension.setupBuiltInMacros(scannerData, scannerData.getLanguage());
|
||||
scannerExtension.setupBuiltInMacros(scannerData);
|
||||
if( getDefinition(__STDC__) == null )
|
||||
addDefinition( __STDC__, new ObjectMacroDescriptor( __STDC__, "1") ); //$NON-NLS-1$
|
||||
|
||||
|
@ -1535,8 +1535,8 @@ public class Scanner implements IScanner {
|
|||
return newConstantToken(((Integer) tokenTypeObject).intValue());
|
||||
else
|
||||
{
|
||||
if( scannerExtension.isExtensionKeyword( ident ) )
|
||||
return newExtensionToken( scannerExtension.createExtensionToken(ident, scannerData ));
|
||||
if( scannerExtension.isExtensionKeyword( scannerData.getLanguage(), ident ) )
|
||||
return newExtensionToken( scannerExtension.createExtensionToken(scannerData, ident ));
|
||||
return newToken(IToken.tIDENTIFIER, ident);
|
||||
}
|
||||
}
|
||||
|
@ -1775,6 +1775,11 @@ public class Scanner implements IScanner {
|
|||
case ':' : return newConstantToken(IToken.tLBRACKET);
|
||||
|
||||
default :
|
||||
StringBuffer buff = new StringBuffer( "<"); //$NON-NLS-1$
|
||||
buff.append( (char)c);
|
||||
String query =buff.toString();
|
||||
if( scannerExtension.isExtensionOperator( scannerData.getLanguage(), query ) )
|
||||
return newExtensionToken( scannerExtension.createExtensionToken( scannerData, query ));
|
||||
ungetChar(c);
|
||||
if( forInclusion )
|
||||
temporarilyReplaceDefinitionsMap();
|
||||
|
@ -1793,9 +1798,14 @@ public class Scanner implements IScanner {
|
|||
}
|
||||
case '=' : return newConstantToken(IToken.tGTEQUAL);
|
||||
default :
|
||||
StringBuffer buff = new StringBuffer( ">"); //$NON-NLS-1$
|
||||
buff.append( (char)c);
|
||||
String query =buff.toString();
|
||||
if( scannerExtension.isExtensionOperator( scannerData.getLanguage(), query ) )
|
||||
return newExtensionToken( scannerExtension.createExtensionToken( scannerData, query ));
|
||||
ungetChar(c);
|
||||
if( forInclusion )
|
||||
restoreDefinitionsMap();
|
||||
temporarilyReplaceDefinitionsMap();
|
||||
return newConstantToken(IToken.tGT);
|
||||
}
|
||||
case '.' :
|
||||
|
@ -1884,7 +1894,7 @@ public class Scanner implements IScanner {
|
|||
{
|
||||
// This is not a wide literal -- it must be a token or keyword
|
||||
ungetChar(c);
|
||||
token = processKeywordOrIdentifier(new StringBuffer( "L"), pasting);
|
||||
token = processKeywordOrIdentifier(new StringBuffer( "L"), pasting);//$NON-NLS-1$
|
||||
}
|
||||
if (token == null)
|
||||
{
|
||||
|
@ -1932,7 +1942,7 @@ public class Scanner implements IScanner {
|
|||
else if( c == '\\' )
|
||||
{
|
||||
int next = getChar();
|
||||
StringBuffer ucnBuffer = new StringBuffer( "\\");
|
||||
StringBuffer ucnBuffer = new StringBuffer( "\\");//$NON-NLS-1$
|
||||
ucnBuffer.append( (char) next );
|
||||
|
||||
if( next == 'u' || next =='U' )
|
||||
|
|
|
@ -70,7 +70,7 @@ public class ScannerUtility {
|
|||
* @return
|
||||
*/
|
||||
private static String removeQuotes(String originalPath) {
|
||||
String [] segments = originalPath.split( "\"");
|
||||
String [] segments = originalPath.split( "\""); //$NON-NLS-1$
|
||||
if( segments.length == 1 ) return originalPath;
|
||||
StringBuffer result = new StringBuffer();
|
||||
for( int i = 0; i < segments.length; ++ i )
|
||||
|
|
Loading…
Add table
Reference in a new issue