mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fixed 72527 - [Scanner] Remove Scanner, ScannerException & clean up IScanner interface
This commit is contained in:
parent
efc06fdd8c
commit
6dc6b84d4b
85 changed files with 476 additions and 8235 deletions
|
@ -1,233 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2001 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corp. - Rational Software - initial implementation
|
||||
******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.parser.tests;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||
import org.eclipse.cdt.core.parser.ParserFactoryError;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ScannerException;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
*/
|
||||
public class BaseScannerTest extends TestCase {
|
||||
|
||||
protected IScanner scanner;
|
||||
|
||||
public BaseScannerTest( String x )
|
||||
{
|
||||
super(x);
|
||||
}
|
||||
|
||||
protected void initializeScanner( String input, ParserMode mode ) throws ParserFactoryError
|
||||
{
|
||||
initializeScanner( input, mode, new NullSourceElementRequestor( mode ));
|
||||
}
|
||||
|
||||
protected void initializeScanner( String input, ParserMode mode, ISourceElementRequestor requestor ) throws ParserFactoryError
|
||||
{
|
||||
scanner= ParserFactory.createScanner( new CodeReader(input.toCharArray()), new ScannerInfo(), mode, ParserLanguage.CPP, requestor, null, null ); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
protected void initializeScanner(String input) throws ParserFactoryError
|
||||
{
|
||||
initializeScanner( input, ParserMode.COMPLETE_PARSE );
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int fullyTokenize() throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
IToken t= scanner.nextToken();
|
||||
while (t != null)
|
||||
{
|
||||
if (verbose)
|
||||
System.out.println("Token t = " + t); //$NON-NLS-1$
|
||||
|
||||
if ((t.getType()> IToken.tLAST))
|
||||
System.out.println("Unknown type for token " + t); //$NON-NLS-1$
|
||||
t= scanner.nextToken();
|
||||
}
|
||||
}
|
||||
catch ( EndOfFileException e)
|
||||
{
|
||||
}
|
||||
catch (ScannerException se)
|
||||
{
|
||||
throw se;
|
||||
}
|
||||
return scanner.getCount();
|
||||
}
|
||||
public void validateIdentifier(String expectedImage) throws ScannerException
|
||||
{
|
||||
try {
|
||||
IToken t= scanner.nextToken();
|
||||
assertEquals( t.getType(), IToken.tIDENTIFIER );
|
||||
assertEquals(t.getImage(), expectedImage );
|
||||
} catch (EndOfFileException e) {
|
||||
assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void validateInteger(String expectedImage) throws ScannerException
|
||||
{
|
||||
try {
|
||||
IToken t= scanner.nextToken();
|
||||
assertTrue(t.getType() == IToken.tINTEGER);
|
||||
assertTrue(t.getImage().equals(expectedImage));
|
||||
} catch (EndOfFileException e) {
|
||||
assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void validateFloatingPointLiteral(String expectedImage) throws ScannerException
|
||||
{
|
||||
try {
|
||||
IToken t= scanner.nextToken();
|
||||
assertTrue(t.getType() == IToken.tFLOATINGPT);
|
||||
assertTrue(t.getImage().equals(expectedImage));
|
||||
} catch (EndOfFileException e) {
|
||||
assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void validateChar( char expected )throws ScannerException
|
||||
{
|
||||
try {
|
||||
IToken t= scanner.nextToken();
|
||||
assertTrue(t.getType() == IToken.tCHAR );
|
||||
Character c = new Character( expected );
|
||||
assertEquals( t.getImage(), c.toString() );
|
||||
} catch (EndOfFileException e) {
|
||||
assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void validateChar( String expected ) throws ScannerException
|
||||
{
|
||||
try {
|
||||
IToken t= scanner.nextToken();
|
||||
assertTrue(t.getType() == IToken.tCHAR );
|
||||
assertEquals( t.getImage(), expected );
|
||||
} catch (EndOfFileException e) {
|
||||
assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void validateString( String expectedImage ) throws ScannerException
|
||||
{
|
||||
validateString( expectedImage, false );
|
||||
}
|
||||
|
||||
public void validateString(String expectedImage, boolean lString ) throws ScannerException
|
||||
{
|
||||
try {
|
||||
IToken t= scanner.nextToken();
|
||||
if( lString )
|
||||
assertTrue(t.getType() == IToken.tLSTRING);
|
||||
else
|
||||
assertTrue(t.getType() == IToken.tSTRING);
|
||||
assertTrue(t.getImage().equals(expectedImage));
|
||||
} catch (EndOfFileException e) {
|
||||
assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void validateToken(int tokenType) throws ScannerException
|
||||
{
|
||||
try {
|
||||
IToken t= scanner.nextToken();
|
||||
assertTrue(t.getType() == tokenType);
|
||||
} catch (EndOfFileException e) {
|
||||
assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void validateBalance(int expected)
|
||||
{
|
||||
assertTrue(scanner.getDepth() == expected);
|
||||
}
|
||||
|
||||
public void validateBalance()
|
||||
{
|
||||
assertTrue(scanner.getDepth() == 0);
|
||||
}
|
||||
|
||||
public void validateEOF() throws ScannerException
|
||||
{
|
||||
try {
|
||||
assertNull(scanner.nextToken());
|
||||
} catch (EndOfFileException e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void validateDefinition(String name, String value)
|
||||
{
|
||||
String definition= null;
|
||||
definition= scanner.getDefinition(name).getExpansionSignature();
|
||||
assertNotNull(definition);
|
||||
assertTrue(definition.trim().equals(value));
|
||||
}
|
||||
|
||||
public void validateDefinition(String name, int value)
|
||||
{
|
||||
String definition= null;
|
||||
definition= scanner.getDefinition(name).getExpansionSignature();
|
||||
assertNotNull(definition);
|
||||
int intValue= (Integer.valueOf(definition)).intValue();
|
||||
assertEquals(value, intValue);
|
||||
}
|
||||
|
||||
public void validateAsUndefined(String name)
|
||||
{
|
||||
assertNull(scanner.getDefinition(name));
|
||||
}
|
||||
|
||||
public static final String EXCEPTION_THROWN = "Exception thrown "; //$NON-NLS-1$
|
||||
|
||||
public static final String EXPECTED_FAILURE = "This statement should not be reached " //$NON-NLS-1$
|
||||
+ "as we sent in bad preprocessor input to the scanner"; //$NON-NLS-1$
|
||||
|
||||
public static final boolean verbose = false;
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
*/
|
||||
protected void validateWideChar(String string) throws Exception
|
||||
{
|
||||
try {
|
||||
IToken t= scanner.nextToken();
|
||||
assertTrue(t.getType() == IToken.tLCHAR );
|
||||
assertEquals( t.getImage(), string );
|
||||
} catch (EndOfFileException e) {
|
||||
assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,205 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003,2004 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corp. - Rational Software - initial implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests;
|
||||
|
||||
import java.util.EmptyStackException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.BranchTracker;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class BranchTrackerTest extends TestCase {
|
||||
|
||||
public BranchTrackerTest( String ignoreMe )
|
||||
{
|
||||
super( ignoreMe );
|
||||
}
|
||||
|
||||
public static void assertFalse( boolean input )
|
||||
{
|
||||
assertTrue( input == false );
|
||||
}
|
||||
|
||||
public void testIgnore()
|
||||
{
|
||||
|
||||
BranchTracker bt = new BranchTracker();
|
||||
try
|
||||
{
|
||||
/*
|
||||
* #if 0
|
||||
* # if 1
|
||||
* # elif 1
|
||||
* # else
|
||||
* # endif
|
||||
* #else
|
||||
* #endif
|
||||
*/
|
||||
|
||||
assertFalse( bt.poundIf( false ) );
|
||||
assertFalse( bt.poundIf( true ) );
|
||||
assertFalse( bt.poundElif( true ) );
|
||||
assertFalse( bt.poundElse() );
|
||||
assertFalse( bt.poundEndif() );
|
||||
assertTrue( bt.poundElse() );
|
||||
assertTrue( bt.poundEndif() );
|
||||
|
||||
/*
|
||||
* #if 0
|
||||
* # if 1
|
||||
* # elif 1
|
||||
* # else
|
||||
* # endif
|
||||
* #else
|
||||
* # if 0
|
||||
* # elif 1
|
||||
* # elif 0
|
||||
* # elif 1
|
||||
* # else
|
||||
* # endif
|
||||
* #endif
|
||||
*/
|
||||
|
||||
bt = new BranchTracker();
|
||||
assertFalse( bt.poundIf( false ) );
|
||||
assertFalse( bt.poundIf( true ));
|
||||
assertFalse( bt.poundElif( true ) );
|
||||
assertFalse( bt.poundElse() );
|
||||
assertFalse( bt.poundEndif() );
|
||||
assertTrue( bt.poundElse() );
|
||||
assertFalse( bt.poundIf( false ) );
|
||||
assertTrue( bt.poundElif( true ) );
|
||||
assertFalse( bt.poundElif( false ) );
|
||||
assertFalse( bt.poundElif( true ) );
|
||||
assertFalse( bt.poundElse() );
|
||||
assertTrue( bt.poundEndif() );
|
||||
assertTrue( bt.poundEndif() );
|
||||
assertEquals( 0, bt.getDepth() );
|
||||
|
||||
/*
|
||||
* #if 0
|
||||
* # if 1
|
||||
* # elif 0
|
||||
* # elif 1
|
||||
* # else
|
||||
* # endif
|
||||
* #elif 0
|
||||
* # if 0
|
||||
* # elif 0
|
||||
* # elif 1
|
||||
* # else
|
||||
* # endif
|
||||
* #elif 1
|
||||
* # if 0
|
||||
* # elif 0
|
||||
* # elif 0
|
||||
* # else
|
||||
* # endif
|
||||
* #else
|
||||
* # if 1
|
||||
* # elif 0
|
||||
* # elif 1
|
||||
* # else
|
||||
* # endif
|
||||
* #endif
|
||||
*/
|
||||
|
||||
assertFalse(bt.poundIf(false));
|
||||
assertFalse(bt.poundIf(true));
|
||||
assertFalse(bt.poundElif(false));
|
||||
assertFalse(bt.poundElif(true));
|
||||
assertFalse(bt.poundElse());
|
||||
assertFalse( bt.poundEndif() );
|
||||
assertFalse(bt.poundElif(false));
|
||||
assertFalse(bt.poundIf(false));
|
||||
assertFalse(bt.poundElif(false));
|
||||
assertFalse(bt.poundElif(true));
|
||||
assertFalse(bt.poundElse());
|
||||
assertFalse( bt.poundEndif());
|
||||
assertTrue(bt.poundElif(true));
|
||||
assertFalse(bt.poundIf(false));
|
||||
assertFalse(bt.poundElif(false));
|
||||
assertFalse(bt.poundElif(false));
|
||||
assertTrue(bt.poundElse());
|
||||
assertTrue( bt.poundEndif() );
|
||||
assertFalse(bt.poundElse());
|
||||
assertFalse(bt.poundIf(true));
|
||||
assertFalse(bt.poundElif(false));
|
||||
assertFalse(bt.poundElif(true));
|
||||
assertFalse(bt.poundElse());
|
||||
assertFalse( bt.poundEndif() );
|
||||
assertTrue( bt.poundEndif() );
|
||||
assertEquals(0, bt.getDepth());
|
||||
} catch (EmptyStackException se) {
|
||||
fail("Unexpected Scanner exception thrown"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
public void testSimpleBranches()
|
||||
{
|
||||
try
|
||||
{
|
||||
/*
|
||||
* code sequence is
|
||||
* #if 1
|
||||
* #else
|
||||
* #endif
|
||||
*/
|
||||
BranchTracker bt = new BranchTracker();
|
||||
assertTrue( bt.poundIf( true ) );
|
||||
assertFalse( bt.poundElse() );
|
||||
assertTrue( bt.poundEndif() );
|
||||
|
||||
/*
|
||||
* code sequence is
|
||||
* #if 1
|
||||
* # if 0
|
||||
* # elif 0
|
||||
* # else
|
||||
* # endif
|
||||
* #else
|
||||
* #endif
|
||||
*/
|
||||
bt = new BranchTracker();
|
||||
assertTrue( bt.poundIf( true ));
|
||||
assertFalse( bt.poundIf( false ));
|
||||
assertFalse( bt.poundElif( false ));
|
||||
assertTrue( bt.poundElse());
|
||||
assertTrue( bt.poundEndif() );
|
||||
assertFalse( bt.poundElse() );
|
||||
assertTrue( bt.poundEndif() );
|
||||
|
||||
/*
|
||||
* #if 1
|
||||
* #elsif 1
|
||||
* #elsif 0
|
||||
* #else
|
||||
* #endif
|
||||
*/
|
||||
|
||||
bt = new BranchTracker();
|
||||
assertTrue( bt.poundIf( true ) );
|
||||
assertFalse( bt.poundElif( true ));
|
||||
assertFalse( bt.poundElif( false ));
|
||||
assertFalse( bt.poundElse());
|
||||
assertTrue( bt.poundEndif() );
|
||||
|
||||
|
||||
}
|
||||
catch( EmptyStackException se )
|
||||
{
|
||||
fail( "Exception" ); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,9 +12,9 @@ package org.eclipse.cdt.core.parser.tests;
|
|||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayPool;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayPool;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
|
|
|
@ -26,6 +26,8 @@ import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
|
|||
import org.eclipse.cdt.core.parser.ast.IASTField;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTClassSpecifier;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTCompilationUnit;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTField;
|
||||
|
@ -43,8 +45,6 @@ import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException;
|
|||
import org.eclipse.cdt.internal.core.parser.pst.StandardSymbolExtension;
|
||||
import org.eclipse.cdt.internal.core.parser.pst.TypeFilter;
|
||||
import org.eclipse.cdt.internal.core.parser.pst.TypeInfoProvider;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -21,14 +21,14 @@ import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
|
|||
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ScannerException;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.tests.scanner2.BaseScanner2Test;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
*/
|
||||
public class PreprocessorConditionalTest extends BaseScannerTest
|
||||
public class PreprocessorConditionalTest extends BaseScanner2Test
|
||||
{
|
||||
|
||||
private ISourceElementRequestor nullSourceElementRequestor = new NullSourceElementRequestor();
|
||||
|
@ -64,7 +64,7 @@ public class PreprocessorConditionalTest extends BaseScannerTest
|
|||
/**
|
||||
*
|
||||
*/
|
||||
private void evaluate()
|
||||
private void evaluate() throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -74,10 +74,6 @@ public class PreprocessorConditionalTest extends BaseScannerTest
|
|||
scanner.nextToken();
|
||||
fail( "Should have hit EOF by now"); //$NON-NLS-1$
|
||||
}
|
||||
catch( ScannerException se )
|
||||
{
|
||||
fail( "Got #error, should not have gotten that."); //$NON-NLS-1$
|
||||
}
|
||||
catch( EndOfFileException eof )
|
||||
{
|
||||
// expected
|
||||
|
|
|
@ -20,7 +20,6 @@ import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
|
|||
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ScannerException;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
|
@ -85,7 +84,7 @@ public class ScannerSpeedTest extends SpeedTest {
|
|||
int count = 0;
|
||||
try {
|
||||
while (true) {
|
||||
try {
|
||||
|
||||
IToken t = scanner.nextToken();
|
||||
|
||||
if (stream != null)
|
||||
|
@ -94,8 +93,7 @@ public class ScannerSpeedTest extends SpeedTest {
|
|||
if (t == null)
|
||||
break;
|
||||
++count;
|
||||
} catch (ScannerException e) {
|
||||
}
|
||||
|
||||
}
|
||||
} catch (EndOfFileException e2) {
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -19,6 +19,7 @@ import junit.framework.TestCase;
|
|||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
|
@ -27,12 +28,11 @@ import org.eclipse.cdt.core.parser.ParserFactory;
|
|||
import org.eclipse.cdt.core.parser.ParserFactoryError;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ScannerException;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.extension.ExtensionDialect;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectStyleMacro;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserExtensionFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectStyleMacro;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.Scanner2;
|
||||
|
||||
/**
|
||||
|
@ -41,7 +41,7 @@ import org.eclipse.cdt.internal.core.parser.scanner2.Scanner2;
|
|||
*/
|
||||
public class BaseScanner2Test extends TestCase {
|
||||
|
||||
protected Scanner2 scanner;
|
||||
protected IScanner scanner;
|
||||
|
||||
public BaseScanner2Test( String x )
|
||||
{
|
||||
|
@ -91,13 +91,9 @@ public class BaseScanner2Test extends TestCase {
|
|||
catch ( EndOfFileException e)
|
||||
{
|
||||
}
|
||||
catch (ScannerException se)
|
||||
{
|
||||
throw se;
|
||||
}
|
||||
return scanner.getCount();
|
||||
}
|
||||
public void validateIdentifier(String expectedImage) throws ScannerException
|
||||
public void validateIdentifier(String expectedImage) throws Exception
|
||||
{
|
||||
try {
|
||||
IToken t= scanner.nextToken();
|
||||
|
@ -108,7 +104,7 @@ public class BaseScanner2Test extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void validateInteger(String expectedImage) throws ScannerException
|
||||
public void validateInteger(String expectedImage) throws Exception
|
||||
{
|
||||
try {
|
||||
IToken t= scanner.nextToken();
|
||||
|
@ -119,7 +115,7 @@ public class BaseScanner2Test extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void validateFloatingPointLiteral(String expectedImage) throws ScannerException
|
||||
public void validateFloatingPointLiteral(String expectedImage) throws Exception
|
||||
{
|
||||
try {
|
||||
IToken t= scanner.nextToken();
|
||||
|
@ -130,7 +126,7 @@ public class BaseScanner2Test extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void validateChar( char expected )throws ScannerException
|
||||
public void validateChar( char expected )throws Exception
|
||||
{
|
||||
try {
|
||||
IToken t= scanner.nextToken();
|
||||
|
@ -142,7 +138,7 @@ public class BaseScanner2Test extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void validateChar( String expected ) throws ScannerException
|
||||
public void validateChar( String expected ) throws Exception
|
||||
{
|
||||
try {
|
||||
IToken t= scanner.nextToken();
|
||||
|
@ -153,12 +149,12 @@ public class BaseScanner2Test extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void validateString( String expectedImage ) throws ScannerException
|
||||
public void validateString( String expectedImage ) throws Exception
|
||||
{
|
||||
validateString( expectedImage, false );
|
||||
}
|
||||
|
||||
public void validateString(String expectedImage, boolean lString ) throws ScannerException
|
||||
public void validateString(String expectedImage, boolean lString ) throws Exception
|
||||
{
|
||||
try {
|
||||
IToken t= scanner.nextToken();
|
||||
|
@ -168,11 +164,11 @@ public class BaseScanner2Test extends TestCase {
|
|||
assertEquals(IToken.tSTRING, t.getType());
|
||||
assertEquals(expectedImage, t.getImage());
|
||||
} catch (EndOfFileException e) {
|
||||
fail("EOF received");
|
||||
fail("EOF received"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
public void validateToken(int tokenType) throws ScannerException
|
||||
public void validateToken(int tokenType) throws Exception
|
||||
{
|
||||
try {
|
||||
IToken t= scanner.nextToken();
|
||||
|
@ -188,12 +184,7 @@ public class BaseScanner2Test extends TestCase {
|
|||
//assertTrue(scanner.getDepth() == expected);
|
||||
}
|
||||
|
||||
public void validateBalance()
|
||||
{
|
||||
assertTrue(scanner.getDepth() == 0);
|
||||
}
|
||||
|
||||
public void validateEOF() throws ScannerException
|
||||
public void validateEOF() throws Exception
|
||||
{
|
||||
try {
|
||||
assertNull(scanner.nextToken());
|
||||
|
@ -221,7 +212,7 @@ public class BaseScanner2Test extends TestCase {
|
|||
|
||||
public void validateAsUndefined(String name)
|
||||
{
|
||||
assertNull(scanner.getDefinition(name));
|
||||
assertNull(scanner.getDefinitions().get(name.toCharArray()));
|
||||
}
|
||||
|
||||
public static final String EXCEPTION_THROWN = "Exception thrown "; //$NON-NLS-1$
|
||||
|
@ -240,7 +231,7 @@ public class BaseScanner2Test extends TestCase {
|
|||
try {
|
||||
IToken t= scanner.nextToken();
|
||||
assertEquals(IToken.tLCHAR, t.getType());
|
||||
assertEquals(t.getImage(), "L\'" + string + "\'");
|
||||
assertEquals(t.getImage(), "L\'" + string + "\'"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
} catch (EndOfFileException e) {
|
||||
assertTrue(false);
|
||||
}
|
||||
|
|
|
@ -16,8 +16,8 @@ package org.eclipse.cdt.core.parser.tests.scanner2;
|
|||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
|
|
@ -18,7 +18,6 @@ import org.eclipse.cdt.core.parser.IToken;
|
|||
import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ScannerException;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.Scanner2;
|
||||
|
||||
/**
|
||||
|
@ -84,7 +83,6 @@ public class Scanner2SpeedTest extends SpeedTest2 {
|
|||
int count = 0;
|
||||
try {
|
||||
while (true) {
|
||||
try {
|
||||
IToken t = scanner.nextToken();
|
||||
|
||||
if (stream != null)
|
||||
|
@ -93,8 +91,7 @@ public class Scanner2SpeedTest extends SpeedTest2 {
|
|||
if (t == null)
|
||||
break;
|
||||
++count;
|
||||
} catch (ScannerException e) {
|
||||
}
|
||||
|
||||
}
|
||||
} catch (EndOfFileException e2) {
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.eclipse.cdt.core.parser.IToken;
|
|||
import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
|
||||
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;
|
||||
|
||||
|
@ -164,26 +163,17 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
|
||||
public void testWeirdStrings() throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
initializeScanner( "Living Life L\"LONG\""); //$NON-NLS-1$
|
||||
validateIdentifier( "Living" ); //$NON-NLS-1$
|
||||
validateIdentifier( "Life" ); //$NON-NLS-1$
|
||||
validateString("LONG", true); //$NON-NLS-1$
|
||||
validateEOF();
|
||||
}
|
||||
catch( ScannerException se )
|
||||
{
|
||||
fail(EXCEPTION_THROWN + se.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void testNumerics()throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
initializeScanner("3.0 0.9 .5 3. 4E5 2.01E-03 ..."); //$NON-NLS-1$
|
||||
validateFloatingPointLiteral( "3.0"); //$NON-NLS-1$
|
||||
validateFloatingPointLiteral( "0.9"); //$NON-NLS-1$
|
||||
|
@ -193,11 +183,6 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
validateFloatingPointLiteral( "2.01E-03" ); //$NON-NLS-1$
|
||||
validateToken( IToken.tELLIPSIS );
|
||||
validateEOF();
|
||||
}
|
||||
catch( ScannerException se )
|
||||
{
|
||||
fail(EXCEPTION_THROWN + se.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -327,8 +312,6 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
); //$NON-NLS-1$
|
||||
validateIdentifier("foo"); //$NON-NLS-1$
|
||||
validateEOF();
|
||||
validateBalance();
|
||||
|
||||
initializeScanner(
|
||||
"#if ! (BAR)\n" + //$NON-NLS-1$
|
||||
"foo\n" + //$NON-NLS-1$
|
||||
|
@ -338,7 +321,6 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
); //$NON-NLS-1$
|
||||
validateIdentifier("foo"); //$NON-NLS-1$
|
||||
validateEOF();
|
||||
validateBalance();
|
||||
}
|
||||
|
||||
public void testConcatenation()
|
||||
|
@ -453,7 +435,6 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
{
|
||||
initializeScanner("#ifndef BASE\n#define BASE 10\n#endif\n#ifndef BASE\n#error BASE is defined\n#endif"); //$NON-NLS-1$
|
||||
validateEOF();
|
||||
validateBalance();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -474,8 +455,6 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
validateToken(IToken.tRPAREN);
|
||||
validateToken(IToken.tSEMI);
|
||||
validateEOF();
|
||||
validateBalance();
|
||||
|
||||
initializeScanner("#ifndef ONE\n#define ONE 1\n#ifdef TWO\n#define THREE ONE + TWO\n#endif\n#endif\nint three(THREE);"); //$NON-NLS-1$
|
||||
scanner.addDefinition("TWO", "2"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
validateToken(IToken.t_int);
|
||||
|
@ -491,22 +470,17 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
validateToken(IToken.tRPAREN);
|
||||
validateToken(IToken.tSEMI);
|
||||
validateEOF();
|
||||
validateBalance();
|
||||
|
||||
initializeScanner("#ifndef FOO\n#define FOO 4\n#else\n#undef FOO\n#define FOO 6\n#endif"); //$NON-NLS-1$
|
||||
validateEOF();
|
||||
validateBalance();
|
||||
validateDefinition("FOO", "4"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
initializeScanner("#ifndef FOO\n#define FOO 4\n#else\n#undef FOO\n#define FOO 6\n#endif"); //$NON-NLS-1$
|
||||
scanner.addDefinition("FOO", "2"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
validateEOF();
|
||||
validateBalance();
|
||||
validateDefinition("FOO", "6"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
initializeScanner("#ifndef ONE\n# define ONE 1\n# ifndef TWO\n# define TWO ONE + ONE \n# else\n# undef TWO\n# define TWO 2 \n# endif\n#else\n# ifndef TWO\n# define TWO ONE + ONE \n# else\n# undef TWO\n# define TWO 2 \n# endif\n#endif\n"); //$NON-NLS-1$
|
||||
validateEOF();
|
||||
validateBalance();
|
||||
validateDefinition("ONE", "1"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
validateDefinition("TWO", "ONE + ONE"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
|
@ -530,7 +504,6 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
|
||||
scanner.addDefinition("ONE", "one"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
validateEOF();
|
||||
validateBalance();
|
||||
validateDefinition("ONE", "one"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
validateDefinition("TWO", "ONE + ONE"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
|
@ -538,16 +511,12 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
scanner.addDefinition("ONE", "one"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
scanner.addDefinition("TWO", "two"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
validateEOF();
|
||||
validateBalance();
|
||||
|
||||
validateDefinition("ONE", "one"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
validateDefinition("TWO", "2"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
initializeScanner("#ifndef ONE\n# define ONE 1\n# ifndef TWO\n# define TWO ONE + ONE \n# else\n# undef TWO\n# define TWO 2 \n# endif\n#else\n# ifndef TWO\n# define TWO ONE + ONE \n# else\n# undef TWO\n# define TWO 2 \n# endif\n#endif\n"); //$NON-NLS-1$
|
||||
scanner.addDefinition("TWO", "two"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
validateEOF();
|
||||
validateBalance();
|
||||
|
||||
validateDefinition("ONE", "1"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
validateDefinition("TWO", "2"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
|
@ -564,11 +533,8 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
{
|
||||
initializeScanner("#if 0\n#error NEVER\n#endif\n"); //$NON-NLS-1$
|
||||
validateEOF();
|
||||
validateBalance();
|
||||
|
||||
initializeScanner("#define X 5\n#define Y 7\n#if (X < Y)\n#define Z X + Y\n#endif"); //$NON-NLS-1$
|
||||
validateEOF();
|
||||
validateBalance();
|
||||
validateDefinition("X", "5"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
validateDefinition("Y", "7"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
validateDefinition("Z", "X + Y"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
@ -578,7 +544,6 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
scanner.addDefinition("Y", "7"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
scanner.addDefinition("T", "X + Y"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
validateEOF();
|
||||
validateBalance();
|
||||
validateDefinition("X", "5"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
validateDefinition("Y", "7"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
validateDefinition("T", "X + Y"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
@ -594,7 +559,6 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
{
|
||||
initializeScanner("#if ( 10 / 5 ) != 2\n#error 10/5 seems to not equal 2 anymore\n#endif\n"); //$NON-NLS-1$
|
||||
validateEOF();
|
||||
validateBalance();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -631,7 +595,6 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
scanner.addDefinition("FIVE", "(THREE + TWO)"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
validateEOF();
|
||||
validateBalance();
|
||||
validateDefinition("ONE", "1"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
validateDefinition("TWO", "(ONE + ONE)"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
validateDefinition("THREE", "(TWO + ONE)"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
@ -650,7 +613,6 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
System.out.println("\n\nRow " + i + " has code\n" + code); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
initializeScanner(code);
|
||||
validateEOF();
|
||||
validateBalance();
|
||||
validateAllDefinitions(row);
|
||||
}
|
||||
}
|
||||
|
@ -699,8 +661,6 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
validateInteger("1"); //$NON-NLS-1$
|
||||
validateToken(IToken.tSEMI);
|
||||
validateEOF();
|
||||
validateBalance();
|
||||
|
||||
initializeScanner(
|
||||
"#define ONE 1\n" //$NON-NLS-1$
|
||||
+ "#define SUM(a,b,c,d,e,f,g) ( a + b + c + d + e + f + g )\n" //$NON-NLS-1$
|
||||
|
@ -794,11 +754,8 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
validateInteger("7"); //$NON-NLS-1$
|
||||
validateToken(IToken.tSEMI);
|
||||
validateEOF();
|
||||
validateBalance();
|
||||
|
||||
initializeScanner("#if defined( NOTHING ) \nint x = NOTHING;\n#endif"); //$NON-NLS-1$
|
||||
validateEOF();
|
||||
validateBalance();
|
||||
|
||||
|
||||
|
||||
|
@ -811,10 +768,8 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
}
|
||||
}
|
||||
|
||||
public void testQuickScan() throws ParserFactoryError
|
||||
public void testQuickScan() throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
initializeScanner( "#if X + 5 < 7\n int found = 1;\n#endif", ParserMode.QUICK_PARSE ); //$NON-NLS-1$
|
||||
validateToken( IToken.t_int );
|
||||
validateIdentifier( "found" ); //$NON-NLS-1$
|
||||
|
@ -823,21 +778,8 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
validateToken( IToken.tSEMI );
|
||||
validateEOF();
|
||||
|
||||
}
|
||||
catch( ScannerException se )
|
||||
{
|
||||
fail( EXCEPTION_THROWN + se.getMessage() );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
initializeScanner( "#if 0\n int error = 666;\n#endif" ); //$NON-NLS-1$
|
||||
validateEOF();
|
||||
}
|
||||
catch( ScannerException se )
|
||||
{
|
||||
fail( EXCEPTION_THROWN + se.getMessage() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -879,10 +821,6 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
// These are no longer scanner exceptions, the are simply ignored.
|
||||
//fail(EXPECTED_FAILURE);
|
||||
}
|
||||
catch (ScannerException se)
|
||||
{
|
||||
validateBalance();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
fail(EXCEPTION_THROWN + e.toString());
|
||||
|
@ -952,18 +890,11 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
validateEOF();
|
||||
}
|
||||
|
||||
public void testBug35892() throws ParserFactoryError
|
||||
public void testBug35892() throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
initializeScanner( "'c'" ); //$NON-NLS-1$
|
||||
validateChar( 'c' );
|
||||
validateEOF();
|
||||
}
|
||||
catch( ScannerException se )
|
||||
{
|
||||
fail( EXCEPTION_THROWN + se.getMessage() );
|
||||
}
|
||||
initializeScanner( "'c'" ); //$NON-NLS-1$
|
||||
validateChar( 'c' );
|
||||
validateEOF();
|
||||
}
|
||||
|
||||
public void testBug36045() throws Exception
|
||||
|
@ -983,10 +914,8 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
validateString( "\\\"\\\\"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void testConditionalWithBraces() throws ParserFactoryError
|
||||
public void testConditionalWithBraces() throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
for( int i = 0; i < 4; ++i )
|
||||
{
|
||||
initializeScanner( "int foobar(int a) { if(a == 0) {\n#ifdef THIS\n} else {}\n#elif THAT\n} else {}\n#endif\nreturn 0;}" ); //$NON-NLS-1$
|
||||
|
@ -1045,10 +974,7 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
validateToken( IToken.tRBRACE );
|
||||
validateEOF();
|
||||
}
|
||||
} catch( ScannerException se )
|
||||
{
|
||||
fail(EXCEPTION_THROWN + se.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testNestedRecursiveDefines() throws Exception
|
||||
|
@ -1190,31 +1116,27 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
|
||||
public void testBug36816() throws Exception
|
||||
{
|
||||
initializeScanner( "#include \"foo.h" ); //$NON-NLS-1$
|
||||
try{
|
||||
validateEOF();
|
||||
} catch ( ScannerException e ){
|
||||
assertTrue( e.getProblem().getID() == IProblem.PREPROCESSOR_INVALID_DIRECTIVE );
|
||||
}
|
||||
Callback c;
|
||||
c = new Callback( ParserMode.QUICK_PARSE );
|
||||
initializeScanner( "#include \"foo.h", ParserMode.QUICK_PARSE, c ); //$NON-NLS-1$
|
||||
validateEOF();
|
||||
// assertTrue( ((IProblem)c.problems.get(0)).getID() == IProblem.PREPROCESSOR_INVALID_DIRECTIVE );
|
||||
|
||||
c = new Callback( ParserMode.QUICK_PARSE );
|
||||
initializeScanner( "#include <foo.h", ParserMode.QUICK_PARSE, c ); //$NON-NLS-1$
|
||||
validateEOF();
|
||||
// assertTrue( ((IProblem)c.problems.get(0)).getID() == IProblem.PREPROCESSOR_INVALID_DIRECTIVE);
|
||||
|
||||
c = new Callback( ParserMode.QUICK_PARSE );
|
||||
initializeScanner( "#define FOO(A", ParserMode.QUICK_PARSE, c ); //$NON-NLS-1$
|
||||
validateEOF();
|
||||
// assertTrue( ((IProblem)c.problems.get(0)).getID() == IProblem.PREPROCESSOR_INVALID_MACRO_DEFN );
|
||||
|
||||
c = new Callback( ParserMode.QUICK_PARSE );
|
||||
initializeScanner( "#define FOO(A \\ B", ParserMode.QUICK_PARSE, c ); //$NON-NLS-1$
|
||||
validateEOF();
|
||||
// assertTrue( ((IProblem)c.problems.get(0)).getID() == IProblem.PREPROCESSOR_INVALID_MACRO_DEFN);
|
||||
|
||||
initializeScanner( "#include <foo.h" ); //$NON-NLS-1$
|
||||
try{
|
||||
validateEOF();
|
||||
} catch ( ScannerException e ){
|
||||
assertTrue( e.getProblem().getID() == IProblem.PREPROCESSOR_INVALID_DIRECTIVE);
|
||||
}
|
||||
initializeScanner( "#define FOO(A" ); //$NON-NLS-1$
|
||||
try{
|
||||
validateEOF();
|
||||
} catch( ScannerException e ){
|
||||
assertTrue( e.getProblem().getID() == IProblem.PREPROCESSOR_INVALID_MACRO_DEFN );
|
||||
}
|
||||
initializeScanner( "#define FOO(A \\ B" ); //$NON-NLS-1$
|
||||
try{
|
||||
validateEOF();
|
||||
} catch( ScannerException e ){
|
||||
assertTrue( e.getProblem().getID() == IProblem.PREPROCESSOR_INVALID_MACRO_DEFN);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1388,16 +1310,7 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
}
|
||||
|
||||
initializeScanner( buffer.toString() );
|
||||
try
|
||||
{
|
||||
validateEOF();
|
||||
// Preprocess overwrites are now allowed without correctness checking
|
||||
//fail( "Should not reach here"); //$NON-NLS-1$
|
||||
}
|
||||
catch( ScannerException se )
|
||||
{
|
||||
assertTrue( se.getProblem().getID() == IProblem.PREPROCESSOR_INVALID_MACRO_REDEFN);
|
||||
}
|
||||
validateEOF();
|
||||
}
|
||||
|
||||
buffer = new StringBuffer();
|
||||
|
@ -1473,7 +1386,7 @@ public class Scanner2Test extends BaseScanner2Test
|
|||
}
|
||||
|
||||
|
||||
public void test54778() throws ScannerException
|
||||
public void test54778() throws Exception
|
||||
{
|
||||
initializeScanner("#if 1 || 0 < 3 \n printf \n #endif\n"); //$NON-NLS-1$
|
||||
validateIdentifier("printf"); //$NON-NLS-1$
|
||||
|
|
|
@ -30,12 +30,12 @@ import org.eclipse.cdt.core.index.IIndexChangeListener;
|
|||
import org.eclipse.cdt.core.index.IndexChangeEvent;
|
||||
import org.eclipse.cdt.core.model.ICModelMarker;
|
||||
import org.eclipse.cdt.core.parser.ParserTimeOut;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectSet;
|
||||
import org.eclipse.cdt.internal.core.CharOperation;
|
||||
import org.eclipse.cdt.internal.core.Util;
|
||||
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||
import org.eclipse.cdt.internal.core.index.impl.Index;
|
||||
import org.eclipse.cdt.internal.core.index.impl.IndexDelta;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectSet;
|
||||
import org.eclipse.cdt.internal.core.search.CWorkspaceScope;
|
||||
import org.eclipse.cdt.internal.core.search.IndexSelector;
|
||||
import org.eclipse.cdt.internal.core.search.SimpleLookupTable;
|
||||
|
|
|
@ -19,7 +19,7 @@ import java.nio.MappedByteBuffer;
|
|||
import java.nio.channels.FileChannel;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2001 Rational Software Corp. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* Rational Software - initial implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
*/
|
||||
public interface IMacroDescriptor {
|
||||
|
||||
public static class MacroType extends Enum
|
||||
{
|
||||
// two kinds of macros as defined by ISO C++98
|
||||
|
||||
// object like - #define SYMBOL REPLACEMENT TOKENS
|
||||
public static final MacroType OBJECT_LIKE = new MacroType( 1 );
|
||||
|
||||
// function like - #define SYMBOL( parm1, parm2 ) TOKENS USING parms
|
||||
public static final MacroType FUNCTION_LIKE = new MacroType( 2 );
|
||||
|
||||
// built in internal macro who's value is dynamic
|
||||
public static final MacroType INTERNAL_LIKE = new MacroType(3);
|
||||
/**
|
||||
* @param enumValue
|
||||
*/
|
||||
protected MacroType(int enumValue) {
|
||||
super(enumValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// what kind of macro is it?
|
||||
public MacroType getMacroType();
|
||||
|
||||
// parameters for macros of type FUNCTION_LIKE
|
||||
public String[] getParameters();
|
||||
|
||||
// the RHS side of the macro separated into ITokens
|
||||
public IToken[] getTokenizedExpansion();
|
||||
|
||||
// the symbol name
|
||||
public String getName();
|
||||
|
||||
// the full preprocessor line of source that spawned this object
|
||||
public String getCompleteSignature();
|
||||
|
||||
// the RHS of the macro
|
||||
public String getExpansionSignature();
|
||||
|
||||
// similar to equals() but according to the C99 & C++98
|
||||
public boolean compatible(IMacroDescriptor descriptor);
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isCircular();
|
||||
}
|
|
@ -13,7 +13,7 @@ package org.eclipse.cdt.core.parser;
|
|||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.IScannerContext;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -34,30 +34,16 @@ public interface IScanner {
|
|||
public static final int tPOUND = -7;
|
||||
|
||||
public void setOffsetBoundary( int offset );
|
||||
|
||||
public void setASTFactory( IASTFactory f );
|
||||
public void addDefinition(String key, IMacroDescriptor macroToBeAdded );
|
||||
|
||||
public void addDefinition(String key, String value);
|
||||
public IMacroDescriptor getDefinition(String key);
|
||||
public Map getDefinitions();
|
||||
|
||||
public String[] getIncludePaths();
|
||||
public void overwriteIncludePath( String [] newIncludePaths );
|
||||
|
||||
public IToken nextToken() throws ScannerException, EndOfFileException;
|
||||
public IToken nextToken( boolean next ) throws ScannerException, EndOfFileException;
|
||||
public IToken nextToken() throws EndOfFileException;
|
||||
|
||||
public int getCount();
|
||||
public int getDepth();
|
||||
|
||||
public IToken nextTokenForStringizing() throws ScannerException, EndOfFileException;
|
||||
public void setTokenizingMacroReplacementList(boolean b);
|
||||
public void setThrowExceptionOnBadCharacterRead( boolean throwOnBad );
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isOnTopContext();
|
||||
public void setScannerContext(IScannerContext context);
|
||||
public CharArrayObjectMap getRealDefinitions();
|
||||
|
||||
}
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2001 Rational Software Corp. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* Rational Software - initial implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser;
|
||||
|
||||
|
||||
public class ScannerException extends Exception {
|
||||
|
||||
private final IProblem problem;
|
||||
|
||||
public ScannerException( IProblem p )
|
||||
{
|
||||
problem = p;
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public IProblem getProblem()
|
||||
{
|
||||
return problem;
|
||||
}
|
||||
|
||||
}
|
|
@ -12,7 +12,6 @@ package org.eclipse.cdt.core.parser.ast;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.parser.IMacroDescriptor;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.ITokenDuple;
|
||||
|
@ -28,7 +27,7 @@ public interface IASTFactory
|
|||
char[] name,
|
||||
int startingOffset,
|
||||
int startingLine,
|
||||
int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine, IMacroDescriptor info, char[] fn);
|
||||
int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine, char[] fn);
|
||||
|
||||
public IASTInclusion createInclusion(
|
||||
char[] name,
|
||||
|
|
|
@ -12,7 +12,7 @@ package org.eclipse.cdt.core.parser.extension;
|
|||
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.IScannerData;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.IScannerData;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
* Contributors:
|
||||
* IBM - Initial implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
package org.eclipse.cdt.core.parser.util;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
|
@ -8,7 +8,7 @@
|
|||
* Contributors:
|
||||
* IBM - Initial implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
package org.eclipse.cdt.core.parser.util;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
|
@ -14,7 +14,7 @@
|
|||
* TODO To change the template for this generated file go to
|
||||
* Window - Preferences - Java - Code Style - Code Templates
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
package org.eclipse.cdt.core.parser.util;
|
||||
|
||||
/**
|
||||
* @author dschaefe
|
|
@ -12,7 +12,7 @@
|
|||
/*
|
||||
* Created on Jul 21, 2004
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
package org.eclipse.cdt.core.parser.util;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
|
@ -14,7 +14,7 @@
|
|||
* TODO To change the template for this generated file go to
|
||||
* Window - Preferences - Java - Code Style - Code Templates
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
package org.eclipse.cdt.core.parser.util;
|
||||
|
||||
/**
|
||||
* @author dschaefe
|
|
@ -9,7 +9,7 @@
|
|||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
package org.eclipse.cdt.core.parser.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
|
@ -9,7 +9,7 @@
|
|||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
package org.eclipse.cdt.core.parser.util;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
* cloned from CharArrayMap & CharArrayObjectMap
|
||||
* Created on Jul 14, 2004
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
package org.eclipse.cdt.core.parser.util;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
|
@ -12,7 +12,7 @@
|
|||
/*
|
||||
* Created on Jul 15, 2004
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
package org.eclipse.cdt.core.parser.util;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
|
@ -8,7 +8,7 @@
|
|||
* Contributors:
|
||||
* IBM Corporation - initial implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
package org.eclipse.cdt.core.parser.util;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
|
@ -13,7 +13,7 @@
|
|||
* For use by the Parser Symbol Table
|
||||
* Created on Jul 15, 2004
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
package org.eclipse.cdt.core.parser.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
|
@ -26,7 +26,6 @@ import org.eclipse.cdt.core.parser.ParseError;
|
|||
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ScannerException;
|
||||
import org.eclipse.cdt.core.parser.ast.ASTPointerOperator;
|
||||
import org.eclipse.cdt.core.parser.ast.ASTSemanticException;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTArrayModifier;
|
||||
|
@ -40,9 +39,8 @@ import org.eclipse.cdt.core.parser.ast.IASTTypeId;
|
|||
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind;
|
||||
import org.eclipse.cdt.core.parser.extension.IParserExtension;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.parser.token.TokenFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.util.TraceUtil;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -2725,13 +2723,6 @@ public class ExpressionParser implements IExpressionParser, IParserData {
|
|||
limitReached = true;
|
||||
handleOffsetLimitException(olre);
|
||||
return null;
|
||||
} catch (ScannerException e) {
|
||||
TraceUtil
|
||||
.outputTrace(
|
||||
log,
|
||||
"ScannerException thrown : ", e.getProblem() ); //$NON-NLS-1$
|
||||
// log.errorLog("Scanner Exception: " + e.getProblem().getMessage()); //$NON-NLS-1$
|
||||
return fetchToken();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -59,8 +59,8 @@ import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
|
|||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
|
||||
import org.eclipse.cdt.core.parser.extension.IParserExtension;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.parser.token.TokenFactory;
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,7 +18,7 @@ import org.eclipse.cdt.core.parser.extension.IParserExtension;
|
|||
import org.eclipse.cdt.core.parser.extension.IParserExtensionFactory;
|
||||
import org.eclipse.cdt.core.parser.extension.IScannerExtension;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.GCCASTExtension;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.GCCScannerExtension;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerExtension;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
|
|
@ -11,9 +11,7 @@
|
|||
package org.eclipse.cdt.internal.core.parser.ast;
|
||||
|
||||
|
||||
import org.eclipse.cdt.core.parser.IMacroDescriptor;
|
||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTMacro;
|
||||
import org.eclipse.cdt.core.parser.ast.IReferenceManager;
|
||||
|
||||
|
@ -25,17 +23,15 @@ public class ASTMacro implements IASTMacro {
|
|||
|
||||
private int nameEndOffset = 0;
|
||||
private final char[] name;
|
||||
private final IMacroDescriptor innerMacro;
|
||||
private final char[] fn;
|
||||
|
||||
public ASTMacro( char[] name, IMacroDescriptor info, int start, int startLine, int nameBeg, int nameEnd, int nameLine, int end, int endLine, char[] fn )
|
||||
public ASTMacro( char[] name, int start, int startLine, int nameBeg, int nameEnd, int nameLine, int end, int endLine, char[] fn )
|
||||
{
|
||||
this.name =name;
|
||||
setStartingOffsetAndLineNumber(start, startLine);
|
||||
setNameOffset(nameBeg);
|
||||
setNameEndOffsetAndLineNumber(nameEnd, nameLine);
|
||||
setEndingOffsetAndLineNumber(end, endLine);
|
||||
innerMacro = info;
|
||||
this.fn = fn;
|
||||
}
|
||||
|
||||
|
@ -131,42 +127,6 @@ public class ASTMacro implements IASTMacro {
|
|||
nameEndOffset = offset;
|
||||
nameLineNumber = lineNumber;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getMacroType()
|
||||
*/
|
||||
public IMacroDescriptor.MacroType getMacroType() {
|
||||
return innerMacro.getMacroType();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getParameters()
|
||||
*/
|
||||
public String[] getParameters() {
|
||||
return innerMacro.getParameters();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getTokenizedExpansion()
|
||||
*/
|
||||
public IToken[] getTokenizedExpansion() {
|
||||
return innerMacro.getTokenizedExpansion();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getCompleteSignature()
|
||||
*/
|
||||
public String getCompleteSignature() {
|
||||
return innerMacro.getCompleteSignature();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getExpansionSignature()
|
||||
*/
|
||||
public String getExpansionSignature() {
|
||||
return innerMacro.getExpansionSignature();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#compatible(org.eclipse.cdt.core.parser.IMacroDescriptor)
|
||||
*/
|
||||
public boolean compatible(IMacroDescriptor descriptor) {
|
||||
return innerMacro.compatible(descriptor);
|
||||
}
|
||||
|
||||
private int startingLineNumber, endingLineNumber, nameLineNumber;
|
||||
/* (non-Javadoc)
|
||||
|
@ -187,12 +147,7 @@ public class ASTMacro implements IASTMacro {
|
|||
public int getNameLineNumber() {
|
||||
return nameLineNumber;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#isCircular()
|
||||
*/
|
||||
public boolean isCircular() {
|
||||
return innerMacro.isCircular();
|
||||
}
|
||||
|
||||
|
||||
private int fileIndex;
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -13,7 +13,6 @@ package org.eclipse.cdt.internal.core.parser.ast;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.parser.IMacroDescriptor;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.ast.ASTPointerOperator;
|
||||
|
@ -44,8 +43,8 @@ public class BaseASTFactory {
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.ast.IASTFactory#createMacro(java.lang.String, int, int, int)
|
||||
*/
|
||||
public IASTMacro createMacro(char[] name, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine, IMacroDescriptor info, char[] fn) {
|
||||
IASTMacro m = new ASTMacro( name, info, startingOffset, startingLine, nameOffset, nameEndOffset, nameLine, endingOffset, endingLine, fn );
|
||||
public IASTMacro createMacro(char[] name, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine, char[] fn) {
|
||||
IASTMacro m = new ASTMacro( name, startingOffset, startingLine, nameOffset, nameEndOffset, nameLine, endingOffset, endingLine, fn );
|
||||
return m;
|
||||
}
|
||||
|
||||
|
|
|
@ -73,6 +73,7 @@ import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind;
|
|||
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter.ParamKind;
|
||||
import org.eclipse.cdt.core.parser.extension.IASTFactoryExtension;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.ASTAbstractDeclaration;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.ASTDesignator;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.BaseASTFactory;
|
||||
|
@ -100,7 +101,6 @@ import org.eclipse.cdt.internal.core.parser.pst.StandardSymbolExtension;
|
|||
import org.eclipse.cdt.internal.core.parser.pst.TemplateSymbolExtension;
|
||||
import org.eclipse.cdt.internal.core.parser.pst.TypeInfoProvider;
|
||||
import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension.ExtensionException;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.parser.token.TokenFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.util.TraceUtil;
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ import org.eclipse.cdt.core.parser.ast.IASTTypedefReference;
|
|||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTVariableReference;
|
||||
import org.eclipse.cdt.core.parser.ast.IReferenceManager;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
|
|
@ -13,7 +13,6 @@ package org.eclipse.cdt.internal.core.parser.ast.expression;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.parser.IMacroDescriptor;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.ITokenDuple;
|
||||
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||
|
@ -100,7 +99,7 @@ public class ExpressionParseASTFactory extends BaseASTFactory implements IASTFac
|
|||
int nameLine,
|
||||
int endingOffset,
|
||||
int endingLine,
|
||||
IMacroDescriptor info, char[] fn) {
|
||||
char[] fn) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ package org.eclipse.cdt.internal.core.parser.pst;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
public class BasicSymbol extends ExtensibleSymbol implements ISymbol
|
||||
{
|
||||
|
|
|
@ -26,12 +26,12 @@ import org.eclipse.cdt.core.parser.ParserLanguage;
|
|||
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTMember;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArraySet;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectSet;
|
||||
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.LookupData;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArraySet;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectSet;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
|
|
@ -13,7 +13,7 @@ package org.eclipse.cdt.internal.core.parser.pst;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
|
|
@ -20,9 +20,9 @@ import java.util.List;
|
|||
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.LookupData;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
|
|
@ -16,7 +16,7 @@ package org.eclipse.cdt.internal.core.parser.pst;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
|
|
@ -18,7 +18,7 @@ package org.eclipse.cdt.internal.core.parser.pst;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
|
|
@ -12,7 +12,7 @@ package org.eclipse.cdt.internal.core.parser.pst;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
|
|
@ -12,7 +12,7 @@ package org.eclipse.cdt.internal.core.parser.pst;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
|
|
@ -17,8 +17,8 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
|
|
@ -23,12 +23,12 @@ import org.eclipse.cdt.core.parser.ParserMode;
|
|||
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTMember;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArraySet;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectSet;
|
||||
import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol.IParentSymbol;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArraySet;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectSet;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
|
|
@ -17,7 +17,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
/**
|
||||
* @author aniefe
|
||||
|
|
|
@ -13,12 +13,12 @@ package org.eclipse.cdt.internal.core.parser.pst;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectSet;
|
||||
import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol.IParentSymbol;
|
||||
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.Cost;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectSet;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
|
|
@ -15,11 +15,11 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateDeclaration;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateInstantiation;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateSpecialization;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
|
|
@ -15,8 +15,8 @@ import java.util.Collections;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
package org.eclipse.cdt.internal.core.parser.pst;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectSet;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectSet;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
|
|
@ -1,188 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003, 2004 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
import java.util.EmptyStackException;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
* To change this generated comment edit the template variable
|
||||
"typecomment":
|
||||
* Window>Preferences>Java>Templates.
|
||||
* To enable and disable the creation of type comments go to
|
||||
* Window>Preferences>Java>Code Generation.
|
||||
*/
|
||||
public class BranchTracker {
|
||||
|
||||
private static final int IGNORE_SENTINEL = -1;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
* @see java.lang.Object#Object()
|
||||
*/
|
||||
public BranchTracker()
|
||||
{
|
||||
}
|
||||
|
||||
private Stack branches = new Stack();
|
||||
|
||||
private int ignore = IGNORE_SENTINEL;
|
||||
private static final Boolean FALSE = new Boolean( false );
|
||||
private static final Boolean TRUE = new Boolean( true );
|
||||
|
||||
/**
|
||||
* Method poundif.
|
||||
*
|
||||
* This method is called whenever one encounters a #if, #ifndef
|
||||
* or #ifdef preprocessor directive.
|
||||
*
|
||||
* @param taken - boolean indicates whether or not the condition
|
||||
* evaluates to true or false
|
||||
* @return boolean - are we set to continue scanning or not?
|
||||
*/
|
||||
public boolean poundIf( boolean taken )
|
||||
{
|
||||
if( ignore == IGNORE_SENTINEL )
|
||||
{
|
||||
// we are entering an if
|
||||
// push the taken value onto the stack
|
||||
branches.push( new Boolean( taken ) );
|
||||
|
||||
if( taken == false )
|
||||
{
|
||||
ignore = branches.size();
|
||||
}
|
||||
|
||||
return taken;
|
||||
}
|
||||
branches.push( FALSE );
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean queryCurrentBranchForElif()
|
||||
{
|
||||
if( ignore != IGNORE_SENTINEL && ignore < branches.size() )
|
||||
return true;
|
||||
return !((Boolean)branches.peek()).booleanValue();
|
||||
}
|
||||
|
||||
public boolean queryCurrentBranchForIf()
|
||||
{
|
||||
if( branches.isEmpty() ) return true;
|
||||
if( ignore != IGNORE_SENTINEL & ignore < branches.size() )
|
||||
return false;
|
||||
return ((Boolean)branches.peek()).booleanValue();
|
||||
}
|
||||
|
||||
public boolean poundElif( boolean taken ) throws EmptyStackException
|
||||
{
|
||||
if( ignore != IGNORE_SENTINEL && ignore < branches.size() )
|
||||
{
|
||||
branches.pop();
|
||||
branches.push( FALSE );
|
||||
return false;
|
||||
}
|
||||
|
||||
// so at this point we are either
|
||||
// --> ignore == IGNORE_SENTINEL
|
||||
// --> ignore >= branches.size()
|
||||
// check the branch queue to see whether or not the branch has already been taken
|
||||
Boolean branchAlreadyTaken;
|
||||
branchAlreadyTaken = (Boolean) branches.peek();
|
||||
|
||||
if( ignore == IGNORE_SENTINEL )
|
||||
{
|
||||
if( ! branchAlreadyTaken.booleanValue() )
|
||||
{
|
||||
branches.pop();
|
||||
branches.push( new Boolean( taken ) );
|
||||
if( ! taken )
|
||||
ignore = branches.size();
|
||||
|
||||
return taken;
|
||||
}
|
||||
|
||||
// otherwise this section is to be ignored as well
|
||||
ignore = branches.size();
|
||||
return false;
|
||||
}
|
||||
|
||||
// if we have gotten this far then ignore == branches.size()
|
||||
if( ! branchAlreadyTaken.booleanValue() )
|
||||
{
|
||||
branches.pop();
|
||||
branches.push( new Boolean( taken ) );
|
||||
if( taken )
|
||||
ignore = IGNORE_SENTINEL;
|
||||
|
||||
return taken;
|
||||
}
|
||||
ignore = branches.size();
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean poundElse() throws EmptyStackException
|
||||
{
|
||||
if( ignore != IGNORE_SENTINEL && ignore < branches.size() )
|
||||
{
|
||||
branches.pop();
|
||||
branches.push( FALSE );
|
||||
return false;
|
||||
}
|
||||
|
||||
Boolean branchAlreadyTaken;
|
||||
branchAlreadyTaken = (Boolean) branches.peek();
|
||||
|
||||
if( ignore == IGNORE_SENTINEL )
|
||||
{
|
||||
if( branchAlreadyTaken.booleanValue() )
|
||||
{
|
||||
ignore = branches.size();
|
||||
return false;
|
||||
}
|
||||
|
||||
branches.pop();
|
||||
branches.push( TRUE );
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
// now ignore >= branches.size()
|
||||
if( branchAlreadyTaken.booleanValue() )
|
||||
{
|
||||
ignore = branches.size();
|
||||
return false;
|
||||
}
|
||||
|
||||
branches.pop();
|
||||
branches.push( TRUE );
|
||||
ignore = IGNORE_SENTINEL;
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
// taken only on an #endif
|
||||
public boolean poundEndif( ) throws EmptyStackException
|
||||
{
|
||||
if( ignore == branches.size() )
|
||||
ignore = IGNORE_SENTINEL;
|
||||
branches.pop();
|
||||
return ( ignore == IGNORE_SENTINEL );
|
||||
}
|
||||
|
||||
public int getDepth()
|
||||
{
|
||||
return branches.size();
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003 Rational Software Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
*/
|
||||
public class ContextException extends Exception
|
||||
{
|
||||
private final int id;
|
||||
|
||||
/**
|
||||
* @param i
|
||||
*/
|
||||
public ContextException(int i)
|
||||
{
|
||||
id = i;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public int getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,225 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003, 2004 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corp. - Rational Software - initial implementation
|
||||
******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IProblem;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
|
||||
import org.eclipse.cdt.internal.core.parser.util.TraceUtil;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*
|
||||
* To change the template for this generated type comment go to
|
||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||
*/
|
||||
public class ContextStack {
|
||||
|
||||
private static class SentinelContext implements IScannerContext {
|
||||
public int getChar() { return '\n'; }
|
||||
public String getContextName() { return ""; } //$NON-NLS-1$
|
||||
public int getOffset() { return 0; }
|
||||
public void ungetChar(int undo) { }
|
||||
public boolean isFinal() { return false; }
|
||||
public int getKind() { return IScannerContext.ContextKind.SENTINEL; }
|
||||
public void close() { }
|
||||
}
|
||||
private final IParserLogService log;
|
||||
private int current_size = 8;
|
||||
|
||||
private int lastFileContext = 0;
|
||||
|
||||
private IScannerContext [] cs = new IScannerContext[current_size];
|
||||
private int cs_pos = 0;
|
||||
|
||||
private int currentInclusionArraySize = 16;
|
||||
private int currentInclusionIndex = 0;
|
||||
private String [] fileNames = new String[ currentInclusionArraySize ];
|
||||
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
|
||||
|
||||
|
||||
public final String getInclusionFilename( int index )
|
||||
{
|
||||
try
|
||||
{
|
||||
return fileNames[ index ];
|
||||
}
|
||||
catch( ArrayIndexOutOfBoundsException aioobe )
|
||||
{
|
||||
return EMPTY_STRING;
|
||||
}
|
||||
}
|
||||
|
||||
private final void addInclusionFilename( String filename )
|
||||
{
|
||||
try
|
||||
{
|
||||
fileNames[ currentInclusionIndex++ ] = filename;
|
||||
}
|
||||
catch( ArrayIndexOutOfBoundsException aioobe )
|
||||
{
|
||||
int newSize = currentInclusionArraySize * 2;
|
||||
String newFileNames [] = new String[ newSize ];
|
||||
System.arraycopy( fileNames, 0, newFileNames, 0, fileNames.length );
|
||||
newFileNames[ currentInclusionArraySize++ ] = filename;
|
||||
currentInclusionArraySize = newSize;
|
||||
fileNames = newFileNames;
|
||||
}
|
||||
}
|
||||
|
||||
private static IScannerContext sentinel = new SentinelContext();
|
||||
|
||||
private IScanner scanner;
|
||||
|
||||
public final void cs_push(IScannerContext c) {
|
||||
try {
|
||||
cs[cs_pos++] = c;
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException a)
|
||||
{
|
||||
int new_size = current_size*2;
|
||||
IScannerContext [] new_cs = new IScannerContext[new_size];
|
||||
System.arraycopy( cs, 0, new_cs, 0, cs.length );
|
||||
new_cs[current_size] = c;
|
||||
current_size = new_size;
|
||||
cs = new_cs;
|
||||
}
|
||||
scanner.setScannerContext(c);
|
||||
}
|
||||
public final IScannerContext cs_pop() {
|
||||
IScannerContext context = cs[--cs_pos];
|
||||
scanner.setScannerContext((cs_pos == 0) ? sentinel : cs[cs_pos -1]);
|
||||
return context;
|
||||
}
|
||||
|
||||
public ContextStack( IScanner scanner, IParserLogService l ) {
|
||||
log = l;
|
||||
this.scanner = scanner;
|
||||
cs_push(sentinel);
|
||||
scanner.setScannerContext(sentinel);
|
||||
}
|
||||
|
||||
public void updateInclusionContext(CodeReader code, IASTInclusion inclusion, ISourceElementRequestor requestor) throws ContextException {
|
||||
addInclusionFilename( new String( code.filename ));
|
||||
ScannerContextInclusion context = new ScannerContextInclusion( code, inclusion, currentInclusionIndex - 1 );
|
||||
|
||||
if( isCircularInclusion( context.getContextName() ) )
|
||||
throw new ContextException( IProblem.PREPROCESSOR_CIRCULAR_INCLUSION );
|
||||
|
||||
TraceUtil.outputTrace(log, "Scanner::ContextStack: entering inclusion ", null, context.getContextName(), null, null ); //$NON-NLS-1$
|
||||
context.getExtension().enterScope( requestor, null );
|
||||
cs_push(context);
|
||||
lastFileContext++;
|
||||
}
|
||||
|
||||
public void updateMacroContext(String reader, String filename, ISourceElementRequestor requestor, int macroOffset, int macroLength) throws ContextException
|
||||
{
|
||||
// If we expand a macro within a macro, then keep offsets of the top-level one,
|
||||
// as only the top level macro identifier is properly positioned
|
||||
if (getCurrentContext().getKind() == IScannerContext.ContextKind.MACROEXPANSION) {
|
||||
macroOffset = ((ScannerContextMacro)getCurrentContext()).getOffset();
|
||||
macroLength = ((ScannerContextMacro)getCurrentContext()).getMacroLength();
|
||||
}
|
||||
|
||||
cs_push(new ScannerContextMacro(
|
||||
reader,
|
||||
filename,
|
||||
macroOffset, macroLength));
|
||||
}
|
||||
|
||||
protected void pushInitialContext( IScannerContext context ) throws ContextException
|
||||
{
|
||||
addInclusionFilename( context.getContextName() );
|
||||
lastFileContext++;
|
||||
cs_push(context);
|
||||
}
|
||||
|
||||
public boolean rollbackContext(ISourceElementRequestor requestor) {
|
||||
IScannerContext context = getCurrentContext();
|
||||
context.close();
|
||||
|
||||
if( context.getKind() == IScannerContext.ContextKind.INCLUSION )
|
||||
{
|
||||
TraceUtil.outputTrace(log, "Scanner::ContextStack: ending inclusion ", null, context.getContextName(), null, null); //$NON-NLS-1$
|
||||
((ScannerContextInclusion)context).getExtension().exitScope( requestor, null );
|
||||
lastFileContext--;
|
||||
}
|
||||
cs_pop();
|
||||
return cs_pos != 0;
|
||||
}
|
||||
|
||||
public void undoRollback( IScannerContext undoTo, ISourceElementRequestor requestor ) {
|
||||
IScannerContext context;
|
||||
while (getCurrentContext() != undoTo ) {
|
||||
context = cs[cs_pos++];
|
||||
if(context.getKind() == IScannerContext.ContextKind.INCLUSION)
|
||||
lastFileContext++;
|
||||
scanner.setScannerContext(context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param symbol
|
||||
* @return boolean, whether or not we should expand this definition
|
||||
*
|
||||
* 16.3.4-2 If the name of the macro being replaced is found during
|
||||
* this scan of the replacement list it is not replaced. Further, if
|
||||
* any nested replacements encounter the name of the macro being replaced,
|
||||
* it is not replaced.
|
||||
*/
|
||||
protected boolean shouldExpandDefinition( String symbol )
|
||||
{
|
||||
for(int i = cs_pos-1; i >= 0; i--)
|
||||
if (cs[i].getKind() == IScannerContext.ContextKind.MACROEXPANSION
|
||||
&& cs[i].getContextName().equals(symbol))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean isCircularInclusion( String symbol )
|
||||
{
|
||||
for(int i = cs_pos-1; i >= 0; i--)
|
||||
if (cs[i].getKind() == IScannerContext.ContextKind.INCLUSION &&
|
||||
cs[i].getContextName().equals(symbol))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public final IScannerContext getCurrentContext(){
|
||||
return cs[cs_pos -1];
|
||||
}
|
||||
|
||||
public ScannerContextInclusion getMostRelevantFileContext()
|
||||
{
|
||||
if( cs[lastFileContext] != null && cs[lastFileContext] instanceof ScannerContextInclusion )
|
||||
return (ScannerContextInclusion)cs[lastFileContext];
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getMostRelevantFileContextIndex()
|
||||
{
|
||||
return getMostRelevantFileContext().getFilenameIndex();
|
||||
}
|
||||
public int getCurrentLineNumber()
|
||||
{
|
||||
|
||||
ScannerContextInclusion mostRelevantFileContext = getMostRelevantFileContext();
|
||||
if( mostRelevantFileContext != null )
|
||||
return mostRelevantFileContext.getLine();
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003, 2004 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
import org.eclipse.cdt.core.parser.IMacroDescriptor;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
* To change the template for this generated type comment go to
|
||||
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||
*/
|
||||
public class DynamicMacroDescriptor implements IMacroDescriptor {
|
||||
|
||||
private final String name;
|
||||
private final DynamicMacroEvaluator proxy;
|
||||
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||
private static final IToken[] EMPTY_TOKEN_ARRAY = new IToken[0];
|
||||
|
||||
public DynamicMacroDescriptor( String name, DynamicMacroEvaluator proxy )
|
||||
{
|
||||
this.proxy = proxy;
|
||||
this.name = name;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getMacroType()
|
||||
*/
|
||||
public MacroType getMacroType() {
|
||||
return MacroType.INTERNAL_LIKE;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getParameters()
|
||||
*/
|
||||
public String[] getParameters() {
|
||||
return EMPTY_STRING_ARRAY;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getTokenizedExpansion()
|
||||
*/
|
||||
public IToken[] getTokenizedExpansion() {
|
||||
return EMPTY_TOKEN_ARRAY;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getCompleteSignature()
|
||||
*/
|
||||
public String getCompleteSignature() {
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getExpansionSignature()
|
||||
*/
|
||||
public String getExpansionSignature() {
|
||||
return proxy.execute();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#compatible(org.eclipse.cdt.core.parser.IMacroDescriptor)
|
||||
*/
|
||||
public boolean compatible(IMacroDescriptor descriptor) {
|
||||
if( getMacroType() != descriptor.getMacroType() ) return false;
|
||||
if( !name.equals( descriptor.getName() )) return false;
|
||||
return true;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#isCircular()
|
||||
*/
|
||||
public boolean isCircular() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003, 2004 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
abstract class DynamicMacroEvaluator {
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
abstract String execute();
|
||||
|
||||
}
|
|
@ -1,180 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2001 Rational Software Corp. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* Rational Software - initial implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.eclipse.cdt.core.parser.IMacroDescriptor;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
|
||||
public class FunctionMacroDescriptor implements IMacroDescriptor {
|
||||
|
||||
/**
|
||||
* Method initialize.
|
||||
* @param name The name or label that the Macro can be identified by.
|
||||
* @param identifiers An ordered list of parameters in the macro
|
||||
* definition.
|
||||
* @param tokens An ordered list of tokens that describe the
|
||||
* RHS expansion in the macro definition.
|
||||
* @param sig The complete signature of the macro, as a string.
|
||||
*/
|
||||
public FunctionMacroDescriptor( String name, String[] identifiers, IToken[] tokens, String expansionSignature )
|
||||
{
|
||||
this.name = name;
|
||||
identifierParameters = identifiers;
|
||||
tokenizedExpansion = tokens;
|
||||
this.expansionSignature = expansionSignature;
|
||||
}
|
||||
|
||||
private String name;
|
||||
private String [] identifierParameters;
|
||||
private IToken [] tokenizedExpansion;
|
||||
private String expansionSignature;
|
||||
|
||||
/**
|
||||
* Returns the identifiers.
|
||||
* @return List
|
||||
*/
|
||||
public final String[] getParameters() {
|
||||
return identifierParameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tokens.
|
||||
* @return List
|
||||
*/
|
||||
public final IToken[] getTokenizedExpansion() {
|
||||
return tokenizedExpansion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name.
|
||||
* @return String
|
||||
*/
|
||||
public final String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer buffer = new StringBuffer( 128 );
|
||||
|
||||
int count = identifierParameters.length;
|
||||
|
||||
buffer.append( "MacroDescriptor with name=" + getName() + "\n" ); //$NON-NLS-1$//$NON-NLS-2$
|
||||
buffer.append( "Number of parameters = " + count + "\n" ); //$NON-NLS-1$//$NON-NLS-2$
|
||||
|
||||
for( int current = 0; current < count; ++current)
|
||||
buffer.append( "Parameter #" + current + " with name=" + identifierParameters[current] + "\n" ); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
|
||||
|
||||
|
||||
count = tokenizedExpansion.length;
|
||||
|
||||
|
||||
buffer.append( "Number of tokens = " + count + "\n" ); //$NON-NLS-1$//$NON-NLS-2$
|
||||
for( int current = 0; current < count; ++current )
|
||||
{
|
||||
buffer.append( "Token #" + current++ + " is " + tokenizedExpansion[current].toString() + "\n" ); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the signature.
|
||||
* @return String
|
||||
*/
|
||||
public final String getCompleteSignature()
|
||||
{
|
||||
StringBuffer fullSignature = new StringBuffer( "#define " ); //$NON-NLS-1$
|
||||
fullSignature.append( name );
|
||||
fullSignature.append( '(');
|
||||
|
||||
for( int current = 0; current < identifierParameters.length; ++current )
|
||||
{
|
||||
if (current > 0) fullSignature.append(',');
|
||||
fullSignature.append(identifierParameters[current] );
|
||||
}
|
||||
fullSignature.append( ") "); //$NON-NLS-1$
|
||||
fullSignature.append( expansionSignature );
|
||||
return fullSignature.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#compatible(org.eclipse.cdt.core.parser.IMacroDescriptor)
|
||||
*/
|
||||
public boolean compatible(IMacroDescriptor descriptor) {
|
||||
if( descriptor.getName() == null ) return false;
|
||||
if( descriptor.getTokenizedExpansion() == null ) return false;
|
||||
if( descriptor.getParameters() == null ) return false;
|
||||
if( descriptor.getMacroType() != getMacroType() ) return false;
|
||||
if( ! name.equals( descriptor.getName() )) return false;
|
||||
if( descriptor.getParameters().length != identifierParameters.length ) return false;
|
||||
if( descriptor.getTokenizedExpansion().length != tokenizedExpansion.length ) return false;
|
||||
|
||||
if( ! equivalentArrayContents( descriptor.getParameters(), getParameters() ) ) return false;
|
||||
if( ! equivalentArrayContents( descriptor.getTokenizedExpansion(), getTokenizedExpansion() ) ) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list1
|
||||
* @param list2
|
||||
* @return
|
||||
*/
|
||||
private boolean equivalentArrayContents(Object[] list1, Object[] list2 ) {
|
||||
if( Arrays.equals( list1, list2 )) return true;
|
||||
// otherwise
|
||||
topLoop: for( int i = 0; i < list1.length; ++i )
|
||||
{
|
||||
Object key = list1[i];
|
||||
for( int j = 0; j < list2 .length; ++j )
|
||||
{
|
||||
if( key.equals( list2 [j]) )
|
||||
continue topLoop;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getMacroType()
|
||||
*/
|
||||
public MacroType getMacroType() {
|
||||
return MacroType.FUNCTION_LIKE;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getExpansionSignature()
|
||||
*/
|
||||
public String getExpansionSignature() {
|
||||
return expansionSignature;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#isCircular()
|
||||
*/
|
||||
public boolean isCircular() {
|
||||
for( int i = 0; i < tokenizedExpansion.length; ++i )
|
||||
{
|
||||
IToken t = tokenizedExpansion[i];
|
||||
if( t.getType() == IToken.tIDENTIFIER && t.getImage().equals(getName()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,311 +0,0 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2004 IBM Rational Software and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.GCCKeywords;
|
||||
import org.eclipse.cdt.core.parser.IGCCToken;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.Keywords;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
|
||||
import org.eclipse.cdt.core.parser.extension.IScannerExtension;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.ScannerUtility.InclusionParseException;
|
||||
import org.eclipse.cdt.internal.core.parser.token.TokenFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.util.TraceUtil;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class GCCScannerExtension implements IScannerExtension {
|
||||
|
||||
protected static final ObjectMacroDescriptor STDC_VERSION_MACRO = new ObjectMacroDescriptor( IScanner.__STDC_VERSION__, "199001L"); //$NON-NLS-1$
|
||||
protected static final ObjectMacroDescriptor STDC_HOSTED_MACRO = new ObjectMacroDescriptor( IScanner.__STDC_HOSTED__, "0"); //$NON-NLS-1$
|
||||
protected static final ObjectMacroDescriptor CPLUSPLUS_MACRO = new ObjectMacroDescriptor( IScanner.__CPLUSPLUS, "1"); //$NON-NLS-1$
|
||||
private static final String [] simpleIdentifiersDeclSpec;
|
||||
private static final String [] simpleIdentifiersAttribute;
|
||||
static
|
||||
{
|
||||
simpleIdentifiersDeclSpec = new String[ 1 ];
|
||||
simpleIdentifiersDeclSpec[0]= "x"; //$NON-NLS-1$
|
||||
|
||||
simpleIdentifiersAttribute = new String[ 1 ];
|
||||
simpleIdentifiersAttribute[0] = "xyz"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
|
||||
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$
|
||||
|
||||
private static final String __CONST__ = "__const__"; //$NON-NLS-1$
|
||||
protected static final ObjectMacroDescriptor __CONST__MACRO = new ObjectMacroDescriptor( __CONST__, Keywords.CONST );
|
||||
private static final String __CONST = "__const"; //$NON-NLS-1$
|
||||
protected static final ObjectMacroDescriptor __CONST_MACRO = new ObjectMacroDescriptor( __CONST, Keywords.CONST );
|
||||
private static final String __INLINE__ = "__inline__"; //$NON-NLS-1$
|
||||
protected static final ObjectMacroDescriptor __INLINE__MACRO = new ObjectMacroDescriptor( __INLINE__, Keywords.INLINE );
|
||||
private static final String __VOLATILE__ = "__volatile__"; //$NON-NLS-1$
|
||||
protected static final ObjectMacroDescriptor __VOLATILE__MACRO = new ObjectMacroDescriptor( __VOLATILE__, Keywords.VOLATILE );
|
||||
private static final String __SIGNED__ = "__signed__"; //$NON-NLS-1$
|
||||
private static final ObjectMacroDescriptor __SIGNED__MACRO = new ObjectMacroDescriptor( __SIGNED__, Keywords.SIGNED );
|
||||
private static final String __RESTRICT = "__restrict"; //$NON-NLS-1$
|
||||
private static final String __RESTRICT__ = "__restrict__"; //$NON-NLS-1$
|
||||
private static final ObjectMacroDescriptor __RESTRICT__MACRO = new ObjectMacroDescriptor( __RESTRICT__, Keywords.RESTRICT );
|
||||
private static final String __ASM__ = "__asm__"; //$NON-NLS-1$
|
||||
protected static final ObjectMacroDescriptor __ASM__MACRO = new ObjectMacroDescriptor( __ASM__, Keywords.ASM );
|
||||
private static final String __TYPEOF__ = "__typeof__"; //$NON-NLS-1$
|
||||
protected static final ObjectMacroDescriptor __TYPEOF__MACRO = new ObjectMacroDescriptor( __TYPEOF__, GCCKeywords.TYPEOF );
|
||||
|
||||
|
||||
private static final String __ATTRIBUTE__ = "__attribute__"; //$NON-NLS-1$
|
||||
private static final String __DECLSPEC = "__declspec"; //$NON-NLS-1$
|
||||
private static final IToken [] EMPTY_TOKEN_ARRAY = new IToken[0];
|
||||
protected static final FunctionMacroDescriptor DECLSPEC_MACRO = new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiersDeclSpec, EMPTY_TOKEN_ARRAY, "" ); //$NON-NLS-1$
|
||||
|
||||
protected static final FunctionMacroDescriptor ATTRIBUTE_MACRO = new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiersAttribute, EMPTY_TOKEN_ARRAY, "" ); //$NON-NLS-1$
|
||||
|
||||
private static final String __EXTENSION__ = "__extension__"; //$NON-NLS-1$
|
||||
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
|
||||
protected static final ObjectMacroDescriptor EXTENSION_MACRO = new ObjectMacroDescriptor( __EXTENSION__, EMPTY_STRING );
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScannerExtension#initializeMacroValue(java.lang.String)
|
||||
*/
|
||||
public String initializeMacroValue(IScannerData scannerData, String original) {
|
||||
if( original == null || original.trim().equals( "") ) //$NON-NLS-1$
|
||||
return "1"; //$NON-NLS-1$
|
||||
return original;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScannerExtension#setupBuiltInMacros()
|
||||
*/
|
||||
public void setupBuiltInMacros(IScannerData scannerData) {
|
||||
|
||||
if( scannerData.getLanguage() == ParserLanguage.CPP )
|
||||
if( scannerData.getScanner().getDefinition( IScanner.__CPLUSPLUS ) == null )
|
||||
scannerData.getScanner().addDefinition( IScanner.__CPLUSPLUS, CPLUSPLUS_MACRO);
|
||||
|
||||
if( scannerData.getScanner().getDefinition(IScanner.__STDC_HOSTED__) == null )
|
||||
scannerData.getScanner().addDefinition(IScanner.__STDC_HOSTED__, STDC_HOSTED_MACRO);
|
||||
if( scannerData.getScanner().getDefinition( IScanner.__STDC_VERSION__) == null )
|
||||
scannerData.getScanner().addDefinition( IScanner.__STDC_VERSION__, STDC_VERSION_MACRO);
|
||||
|
||||
// add these to private table
|
||||
if( scannerData.getScanner().getDefinition( __ATTRIBUTE__) == null )
|
||||
scannerData.getPrivateDefinitions().put( __ATTRIBUTE__, ATTRIBUTE_MACRO);
|
||||
|
||||
if( scannerData.getScanner().getDefinition( __DECLSPEC) == null )
|
||||
scannerData.getPrivateDefinitions().put( __DECLSPEC, DECLSPEC_MACRO );
|
||||
|
||||
if( scannerData.getScanner().getDefinition( __EXTENSION__ ) == null )
|
||||
scannerData.getPrivateDefinitions().put( __EXTENSION__, EXTENSION_MACRO);
|
||||
|
||||
if( scannerData.getScanner().getDefinition( __CONST__ ) == null )
|
||||
scannerData.getPrivateDefinitions().put( __CONST__, __CONST__MACRO);
|
||||
if( scannerData.getScanner().getDefinition( __CONST ) == null )
|
||||
scannerData.getPrivateDefinitions().put( __CONST, __CONST_MACRO);
|
||||
if( scannerData.getScanner().getDefinition( __INLINE__ ) == null )
|
||||
scannerData.getPrivateDefinitions().put( __INLINE__, __INLINE__MACRO);
|
||||
if( scannerData.getScanner().getDefinition( __SIGNED__ ) == null )
|
||||
scannerData.getPrivateDefinitions().put( __SIGNED__, __SIGNED__MACRO);
|
||||
if( scannerData.getScanner().getDefinition( __VOLATILE__ ) == null )
|
||||
scannerData.getPrivateDefinitions().put( __VOLATILE__, __VOLATILE__MACRO);
|
||||
ObjectMacroDescriptor __RESTRICT_MACRO = new ObjectMacroDescriptor( __RESTRICT, Keywords.RESTRICT );
|
||||
if( scannerData.getScanner().getDefinition( __RESTRICT ) == null )
|
||||
scannerData.getPrivateDefinitions().put( __RESTRICT, __RESTRICT_MACRO);
|
||||
if( scannerData.getScanner().getDefinition( __RESTRICT__ ) == null )
|
||||
scannerData.getPrivateDefinitions().put( __RESTRICT__, __RESTRICT__MACRO);
|
||||
if( scannerData.getScanner().getDefinition( __TYPEOF__ ) == null )
|
||||
scannerData.getPrivateDefinitions().put( __TYPEOF__, __TYPEOF__MACRO);
|
||||
if( scannerData.getLanguage() == ParserLanguage.CPP )
|
||||
if( scannerData.getScanner().getDefinition( __ASM__ ) == null )
|
||||
scannerData.getPrivateDefinitions().put( __ASM__, __ASM__MACRO);
|
||||
|
||||
}
|
||||
|
||||
private static final Set directives;
|
||||
static
|
||||
{
|
||||
directives = new HashSet();
|
||||
directives.add( POUND_INCLUDE_NEXT );
|
||||
directives.add( POUND_WARNING);
|
||||
directives.add( POUND_IDENT);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.extension.IScannerExtension#canHandlePreprocessorDirective(java.lang.String)
|
||||
*/
|
||||
public boolean canHandlePreprocessorDirective(String directive) {
|
||||
return directives.contains( directive );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.extension.IScannerExtension#handlePreprocessorDirective(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void handlePreprocessorDirective(IScannerData iscanner, String directive, String restOfLine) {
|
||||
if( directive.equals(POUND_INCLUDE_NEXT) )
|
||||
{
|
||||
TraceUtil.outputTrace(iscanner.getLogService(), "GCCScannerExtension handling #include_next directive" ); //$NON-NLS-1$
|
||||
// figure out the name of the current file and its path
|
||||
IScannerContext context = iscanner.getContextStack().getCurrentContext();
|
||||
if( context == null || context.getKind() != IScannerContext.ContextKind.INCLUSION )
|
||||
return;
|
||||
|
||||
String fullInclusionPath = context.getContextName();
|
||||
IASTInclusion inclusion = ((ScannerContextInclusion)context).getExtension();
|
||||
|
||||
Iterator iter = iscanner.getIncludePathNames().iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
String path = (String)iter.next();
|
||||
String completePath = ScannerUtility.createReconciledPath(path, inclusion.getName() );
|
||||
if( completePath.equals( fullInclusionPath ) )
|
||||
break;
|
||||
}
|
||||
|
||||
ScannerUtility.InclusionDirective parsedDirective = null;
|
||||
try {
|
||||
parsedDirective = iscanner.parseInclusionDirective( restOfLine, iscanner.getContextStack().getCurrentContext().getOffset() );
|
||||
} catch (InclusionParseException e) {
|
||||
return;
|
||||
}
|
||||
CodeReader duple = null;
|
||||
// search through include paths
|
||||
while (iter.hasNext()) {
|
||||
String path = (String)iter.next();
|
||||
String finalPath = ScannerUtility.createReconciledPath(path, parsedDirective.getFilename());
|
||||
duple = (CodeReader)iscanner.getFileCache().get(finalPath);
|
||||
if (duple == null) {
|
||||
duple = ScannerUtility.createReaderDuple( finalPath, iscanner.getClientRequestor(), iscanner.getWorkingCopies() );
|
||||
if (duple != null && duple.isFile())
|
||||
iscanner.getFileCache().put(duple.filename, duple);
|
||||
}
|
||||
if( duple != null )
|
||||
break;
|
||||
}
|
||||
|
||||
if( duple != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
iscanner.getContextStack().updateInclusionContext(duple, inclusion, iscanner.getClientRequestor() );
|
||||
TraceUtil.outputTrace( iscanner.getLogService(), "GCCScannerExtension handling #include_next directive successfully pushed on new include file" ); //$NON-NLS-1$
|
||||
}
|
||||
catch (ContextException e1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if( directive.equals( POUND_WARNING) || directive.equals(POUND_IDENT))
|
||||
return; // good enough -- the rest of the line has been consumed
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.extension.IScannerExtension#offersDifferentIdentifierCharacters()
|
||||
*/
|
||||
public boolean offersDifferentIdentifierCharacters() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.extension.IScannerExtension#isValidIdentifierStartCharacter(int)
|
||||
*/
|
||||
public boolean isValidIdentifierStartCharacter(int c) {
|
||||
return Character.isLetter((char)c) || ( c == '_') || ( c == '$' );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.extension.IScannerExtension#isValidIdentifierCharacter(int)
|
||||
*/
|
||||
public boolean isValidIdentifierCharacter(int c) {
|
||||
return ((c >= 'a') && (c <= 'z'))
|
||||
|| ((c >= 'A') && (c <= 'Z'))
|
||||
|| ((c >= '0') && (c <= '9'))
|
||||
|| (c == '_') || ( c== '$' ) ||
|
||||
Character.isUnicodeIdentifierPart( (char)c);
|
||||
}
|
||||
|
||||
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();
|
||||
additionalCKeywords.put( GCCKeywords.__ALIGNOF__, new Integer( IGCCToken.t___alignof__ ));
|
||||
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(ParserLanguage language, String tokenImage) {
|
||||
if( language == ParserLanguage.CPP )
|
||||
return ( additionalCPPKeywords.get( tokenImage ) != null );
|
||||
else if( language == ParserLanguage.C )
|
||||
return ( additionalCKeywords.get( tokenImage ) != null );
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.extension.IScannerExtension#createExtensionToken()
|
||||
*/
|
||||
public IToken createExtensionToken(IScannerData scannerData, String image) {
|
||||
Integer get = null;
|
||||
if( scannerData.getLanguage() == ParserLanguage.CPP )
|
||||
{
|
||||
get = (Integer) additionalCPPKeywords.get( image );
|
||||
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.createUniquelyImagedToken(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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003, 2004 IBM - Rational Software and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Rational Software - initial implementation
|
||||
******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
*/
|
||||
public interface IScannerContext {
|
||||
|
||||
public static class ContextKind
|
||||
{
|
||||
public static int SENTINEL = 0;
|
||||
public static int TOP = 1;
|
||||
public static int INCLUSION = 2;
|
||||
public static int MACROEXPANSION = 3;
|
||||
}
|
||||
public int getKind();
|
||||
|
||||
public int getChar();
|
||||
public void ungetChar(int undo);
|
||||
|
||||
public boolean isFinal();
|
||||
public String getContextName();
|
||||
public int getOffset();
|
||||
public void close();
|
||||
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2004 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class LimitedScannerContext
|
||||
extends ScannerContextInclusion
|
||||
implements IScannerContext {
|
||||
|
||||
private final int limit;
|
||||
private final Scanner scanner;
|
||||
|
||||
/**
|
||||
* @param reader
|
||||
* @param string
|
||||
* @param i
|
||||
* @param object
|
||||
* @param offsetLimit
|
||||
*/
|
||||
public LimitedScannerContext(Scanner scanner, CodeReader code, int offsetLimit, int index ) {
|
||||
super( code, null, index );
|
||||
this.scanner = scanner;
|
||||
limit = offsetLimit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IScannerContext#read()
|
||||
*/
|
||||
public int getChar() {
|
||||
if( getOffset() == limit )
|
||||
{
|
||||
scanner.setOffsetLimitReached(true);
|
||||
return -1;
|
||||
}
|
||||
return super.getChar();
|
||||
}
|
||||
|
||||
public int getKind() {
|
||||
return ScannerContextInclusion.ContextKind.TOP;
|
||||
}
|
||||
}
|
|
@ -1,123 +0,0 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003 Rational Software Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
import org.eclipse.cdt.core.parser.IMacroDescriptor;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class ObjectMacroDescriptor implements IMacroDescriptor {
|
||||
|
||||
private final String expansionSignature;
|
||||
private final String name;
|
||||
private final IToken token;
|
||||
private IToken[] tokenizedExpansion = null;
|
||||
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||
private static final IToken[] EMPTY_TOKEN_ARRAY = new IToken[0];
|
||||
|
||||
public ObjectMacroDescriptor( String name, String expansionSignature )
|
||||
{
|
||||
this.name = name;
|
||||
this.expansionSignature = expansionSignature;
|
||||
token = null;
|
||||
}
|
||||
|
||||
public ObjectMacroDescriptor( String name, IToken t, String expansionSignature )
|
||||
{
|
||||
this.name = name;
|
||||
this.token = t;
|
||||
this.expansionSignature = expansionSignature;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getMacroType()
|
||||
*/
|
||||
public MacroType getMacroType() {
|
||||
return MacroType.OBJECT_LIKE;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getParameters()
|
||||
*/
|
||||
public String[] getParameters() {
|
||||
return EMPTY_STRING_ARRAY ;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getTokenizedExpansion()
|
||||
*/
|
||||
public IToken[] getTokenizedExpansion() {
|
||||
if( token == null ) return EMPTY_TOKEN_ARRAY;
|
||||
if( tokenizedExpansion == null )
|
||||
{
|
||||
tokenizedExpansion = new IToken[1];
|
||||
tokenizedExpansion[0]= token;
|
||||
}
|
||||
return tokenizedExpansion;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getSignature()
|
||||
*/
|
||||
public String getCompleteSignature() {
|
||||
StringBuffer signatureBuffer = new StringBuffer();
|
||||
signatureBuffer.append( "#define " ); //$NON-NLS-1$
|
||||
signatureBuffer.append( name );
|
||||
signatureBuffer.append( ' ' );
|
||||
signatureBuffer.append( expansionSignature );
|
||||
return signatureBuffer.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#compatible(org.eclipse.cdt.core.parser.IMacroDescriptor)
|
||||
*/
|
||||
public boolean compatible(IMacroDescriptor descriptor) {
|
||||
if( descriptor.getName() == null ) return false;
|
||||
if( descriptor.getMacroType() != getMacroType() ) return false;
|
||||
|
||||
// Both macros are ObjectMacroDescriptors!
|
||||
|
||||
if( ! name.equals( descriptor.getName() )) return false;
|
||||
String result = descriptor.getExpansionSignature();
|
||||
if( result == null ) return expansionSignature == null;
|
||||
|
||||
return result.equals(expansionSignature);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getExpansionSignature()
|
||||
*/
|
||||
public String getExpansionSignature() {
|
||||
return expansionSignature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isCircular() {
|
||||
for( int i = 0; i < getTokenizedExpansion().length; ++i)
|
||||
{
|
||||
IToken t = tokenizedExpansion[i];
|
||||
if( t.getType() == IToken.tIDENTIFIER && t.getImage().equals(getName()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,109 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2001, 2004 IBM - Rational Software and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Rational Software - initial implementation
|
||||
******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
|
||||
|
||||
public class ScannerContextInclusion implements IScannerContext
|
||||
{
|
||||
public static final int UNDO_BUFFER_SIZE = 4;
|
||||
public CodeReader code;
|
||||
private IASTInclusion inc;
|
||||
private final int index;
|
||||
private int line;
|
||||
protected int offset = 0;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IScannerContext#initialize(Reader, String, int, IASTInclusion)
|
||||
*/
|
||||
public ScannerContextInclusion(CodeReader code, IASTInclusion i, int index) {
|
||||
this.code = code;
|
||||
line = 1;
|
||||
inc = i;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public boolean isFinal() { return false; }
|
||||
|
||||
public final String getContextName()
|
||||
{
|
||||
return new String( code.filename );
|
||||
}
|
||||
|
||||
public int getOffset()
|
||||
{
|
||||
return offset;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
//TODO remove close and replace by releasing from file cache
|
||||
}
|
||||
|
||||
public int getChar() {
|
||||
if (offset == code.buffer.length)
|
||||
return -1;
|
||||
|
||||
int c = code.buffer[offset++];
|
||||
if ((char)c == '\n') line++;
|
||||
return c;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerContext#ungetChar(int)
|
||||
*/
|
||||
public void ungetChar(int undo) {
|
||||
--offset;
|
||||
if (undo == '\n') line--;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the kind.
|
||||
* @return int
|
||||
*/
|
||||
public int getKind() {
|
||||
return ScannerContextInclusion.ContextKind.INCLUSION;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IScannerContext#getExtension()
|
||||
*/
|
||||
public IASTInclusion getExtension() {
|
||||
return inc;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerContext#getFilenameIndex()
|
||||
*/
|
||||
public int getFilenameIndex() {
|
||||
return index;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IScannerContext#getLine()
|
||||
*/
|
||||
public final int getLine()
|
||||
{
|
||||
return line;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "file "); //$NON-NLS-1$
|
||||
buffer.append( getContextName() );
|
||||
buffer.append( ":"); //$NON-NLS-1$
|
||||
buffer.append( getLine() );
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2001, 2004 IBM - Rational Software and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Rational Software - initial implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
|
||||
public class ScannerContextMacro implements IScannerContext
|
||||
{
|
||||
private int macroOffset;
|
||||
private int macroLength;
|
||||
int position=0;
|
||||
int length;
|
||||
char [] reader;
|
||||
String macroName;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IScannerContext#initialize(Reader, String, int, IASTInclusion, int, int, int)
|
||||
*/
|
||||
public ScannerContextMacro(String in, String macro, int mO, int mL)
|
||||
{
|
||||
macroName = macro;
|
||||
reader = in.toCharArray();
|
||||
length = in.length();
|
||||
macroOffset = mO;
|
||||
macroLength = mL;
|
||||
}
|
||||
|
||||
public boolean isFinal() { return false; }
|
||||
|
||||
public final String getContextName() {
|
||||
return macroName;
|
||||
}
|
||||
public int getChar() {
|
||||
if (position < length)
|
||||
return reader[position++];
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
|
||||
}
|
||||
|
||||
public final void ungetChar(int c)
|
||||
{
|
||||
position--;
|
||||
// may want to assert that reader.charAt(position) == c
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IScannerContext#getMacroLength()
|
||||
*/
|
||||
public final int getMacroLength()
|
||||
{
|
||||
return macroLength;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IScannerContext#getOffset()
|
||||
*/
|
||||
public int getOffset()
|
||||
{
|
||||
// All the tokens generated by the macro expansion
|
||||
// will have dimensions (offset and length) equal to the expanding symbol.
|
||||
return macroOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the kind.
|
||||
* @return int
|
||||
*/
|
||||
public int getKind() {
|
||||
return IScannerContext.ContextKind.MACROEXPANSION;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "Macro "); //$NON-NLS-1$
|
||||
buffer.append( getContextName() );
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2001, 2004 IBM - Rational Software and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Rational Software - initial implementation
|
||||
******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
|
||||
public class ScannerContextTop extends ScannerContextInclusion
|
||||
{
|
||||
ScannerContextTop(CodeReader code) {
|
||||
super(code, null, 0);
|
||||
}
|
||||
|
||||
public int getKind() {
|
||||
return ScannerContextInclusion.ContextKind.TOP;
|
||||
}
|
||||
}
|
|
@ -1,113 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2001, 2004 IBM - Rational Software and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Rational Software - initial implementation
|
||||
*
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
/**
|
||||
* @author ddaoust
|
||||
*
|
||||
*/
|
||||
public class ScannerContextTopString implements IScannerContext {
|
||||
int position=0;
|
||||
int line = 1;
|
||||
int length;
|
||||
String reader;
|
||||
String textName;
|
||||
int extra = -1;
|
||||
boolean stop = false;
|
||||
|
||||
public ScannerContextTopString(String in, String contextName, boolean stop)
|
||||
{
|
||||
textName = contextName;
|
||||
reader = in;
|
||||
length = in.length();
|
||||
this.stop = stop;
|
||||
}
|
||||
public ScannerContextTopString(String in, String contextName, char e, boolean stop)
|
||||
{
|
||||
textName = contextName;
|
||||
reader = in;
|
||||
length = in.length();
|
||||
this.stop = stop;
|
||||
extra = e;
|
||||
}
|
||||
|
||||
|
||||
public boolean isFinal() { return stop;}
|
||||
public final String getContextName() {
|
||||
return textName;
|
||||
}
|
||||
public int getChar() {
|
||||
int c;
|
||||
if (position < length)
|
||||
c = reader.charAt(position++);
|
||||
else if (position++ == length)
|
||||
c = extra;
|
||||
else c = -1;
|
||||
if (c == '\n') line++;
|
||||
return c;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
|
||||
}
|
||||
|
||||
public int getFilenameIndex() { return 0; }
|
||||
|
||||
public final void ungetChar(int c)
|
||||
{
|
||||
position--;
|
||||
if (c == '\n') line--;
|
||||
// may want to assert that reader.charAt(position) == c
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IScannerContext#getOffset()
|
||||
*/
|
||||
public int getOffset()
|
||||
{
|
||||
// All the tokens generated by the macro expansion
|
||||
// will have dimensions (offset and length) equal to the expanding symbol.
|
||||
return position;
|
||||
}
|
||||
public int getLine()
|
||||
{
|
||||
return line;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the kind.
|
||||
* @return int
|
||||
*/
|
||||
public int getKind() {
|
||||
return IScannerContext.ContextKind.TOP;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( getContextName() );
|
||||
if (position <= length) {
|
||||
buffer.append( reader.substring(0, position ));
|
||||
buffer.append( '*' );
|
||||
buffer.append( reader.substring(position, length-position));
|
||||
if (extra != -1 ) buffer.append( (char)extra );
|
||||
}
|
||||
else {
|
||||
buffer.append( reader.substring(0, length ));
|
||||
if ( extra != -1 ) buffer.append( (char)extra );
|
||||
buffer.append( '*' );
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
|
||||
/**
|
||||
* @author ddaoust
|
||||
*
|
||||
*/
|
||||
public class ScannerStringBuffer {
|
||||
private int current_size;
|
||||
private char [] s_buff;
|
||||
private int s_pos;
|
||||
|
||||
public ScannerStringBuffer(int initialSize) {
|
||||
current_size = initialSize;
|
||||
s_buff = new char[current_size];
|
||||
s_pos = 0;
|
||||
}
|
||||
public final void startString(){
|
||||
s_pos = 0;
|
||||
}
|
||||
public final void append(int c) {
|
||||
try {
|
||||
s_buff[s_pos++]= (char)c;
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException a)
|
||||
{
|
||||
int new_size = current_size*2;
|
||||
char [] new_sbuf = new char[new_size];
|
||||
for (int i = 0; i < current_size; i++)
|
||||
new_sbuf[i] = s_buff[i];
|
||||
new_sbuf[current_size] = (char)c;
|
||||
current_size = new_size;
|
||||
s_buff = new_sbuf;
|
||||
}
|
||||
}
|
||||
public final void append(String s) {
|
||||
int len = s.length();
|
||||
for(int i=0; i < len; i++)
|
||||
append(s.charAt(i));
|
||||
}
|
||||
public final void append(IToken t) {
|
||||
append(t.getImage());
|
||||
}
|
||||
public final int length() {
|
||||
return s_pos;
|
||||
}
|
||||
public final String toString() {
|
||||
return String.valueOf(s_buff, 0, s_pos);
|
||||
}
|
||||
}
|
|
@ -10,6 +10,10 @@
|
|||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectStyleMacro;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
*/
|
||||
|
|
|
@ -10,6 +10,9 @@
|
|||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectStyleMacro;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,306 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2004 IBM Rational Software and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.parser.GCCKeywords;
|
||||
import org.eclipse.cdt.core.parser.IGCCToken;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.Keywords;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.extension.IScannerExtension;
|
||||
import org.eclipse.cdt.internal.core.parser.util.TraceUtil;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class GCCScannerExtension implements IScannerExtension {
|
||||
|
||||
// protected static final ObjectMacroDescriptor STDC_VERSION_MACRO = new ObjectMacroDescriptor( IScanner.__STDC_VERSION__, "199001L"); //$NON-NLS-1$
|
||||
// protected static final ObjectMacroDescriptor STDC_HOSTED_MACRO = new ObjectMacroDescriptor( IScanner.__STDC_HOSTED__, "0"); //$NON-NLS-1$
|
||||
// protected static final ObjectMacroDescriptor CPLUSPLUS_MACRO = new ObjectMacroDescriptor( IScanner.__CPLUSPLUS, "1"); //$NON-NLS-1$
|
||||
private static final String [] simpleIdentifiersDeclSpec;
|
||||
private static final String [] simpleIdentifiersAttribute;
|
||||
static
|
||||
{
|
||||
simpleIdentifiersDeclSpec = new String[ 1 ];
|
||||
simpleIdentifiersDeclSpec[0]= "x"; //$NON-NLS-1$
|
||||
|
||||
simpleIdentifiersAttribute = new String[ 1 ];
|
||||
simpleIdentifiersAttribute[0] = "xyz"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
|
||||
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$
|
||||
|
||||
// private static final String __CONST__ = "__const__"; //$NON-NLS-1$
|
||||
// protected static final ObjectMacroDescriptor __CONST__MACRO = new ObjectMacroDescriptor( __CONST__, Keywords.CONST );
|
||||
// private static final String __CONST = "__const"; //$NON-NLS-1$
|
||||
// protected static final ObjectMacroDescriptor __CONST_MACRO = new ObjectMacroDescriptor( __CONST, Keywords.CONST );
|
||||
// private static final String __INLINE__ = "__inline__"; //$NON-NLS-1$
|
||||
// protected static final ObjectMacroDescriptor __INLINE__MACRO = new ObjectMacroDescriptor( __INLINE__, Keywords.INLINE );
|
||||
// private static final String __VOLATILE__ = "__volatile__"; //$NON-NLS-1$
|
||||
// protected static final ObjectMacroDescriptor __VOLATILE__MACRO = new ObjectMacroDescriptor( __VOLATILE__, Keywords.VOLATILE );
|
||||
// private static final String __SIGNED__ = "__signed__"; //$NON-NLS-1$
|
||||
// private static final ObjectMacroDescriptor __SIGNED__MACRO = new ObjectMacroDescriptor( __SIGNED__, Keywords.SIGNED );
|
||||
// private static final String __RESTRICT = "__restrict"; //$NON-NLS-1$
|
||||
// private static final String __RESTRICT__ = "__restrict__"; //$NON-NLS-1$
|
||||
// private static final ObjectMacroDescriptor __RESTRICT__MACRO = new ObjectMacroDescriptor( __RESTRICT__, Keywords.RESTRICT );
|
||||
// private static final String __ASM__ = "__asm__"; //$NON-NLS-1$
|
||||
// protected static final ObjectMacroDescriptor __ASM__MACRO = new ObjectMacroDescriptor( __ASM__, Keywords.ASM );
|
||||
// private static final String __TYPEOF__ = "__typeof__"; //$NON-NLS-1$
|
||||
// protected static final ObjectMacroDescriptor __TYPEOF__MACRO = new ObjectMacroDescriptor( __TYPEOF__, GCCKeywords.TYPEOF );
|
||||
|
||||
|
||||
// private static final String __ATTRIBUTE__ = "__attribute__"; //$NON-NLS-1$
|
||||
// private static final String __DECLSPEC = "__declspec"; //$NON-NLS-1$
|
||||
// private static final IToken [] EMPTY_TOKEN_ARRAY = new IToken[0];
|
||||
// protected static final FunctionMacroDescriptor DECLSPEC_MACRO = new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiersDeclSpec, EMPTY_TOKEN_ARRAY, "" ); //$NON-NLS-1$
|
||||
//
|
||||
// protected static final FunctionMacroDescriptor ATTRIBUTE_MACRO = new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiersAttribute, EMPTY_TOKEN_ARRAY, "" ); //$NON-NLS-1$
|
||||
|
||||
// private static final String __EXTENSION__ = "__extension__"; //$NON-NLS-1$
|
||||
// private static final String EMPTY_STRING = ""; //$NON-NLS-1$
|
||||
// protected static final ObjectMacroDescriptor EXTENSION_MACRO = new ObjectMacroDescriptor( __EXTENSION__, EMPTY_STRING );
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScannerExtension#initializeMacroValue(java.lang.String)
|
||||
*/
|
||||
public String initializeMacroValue(IScannerData scannerData, String original) {
|
||||
if( original == null || original.trim().equals( "") ) //$NON-NLS-1$
|
||||
return "1"; //$NON-NLS-1$
|
||||
return original;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScannerExtension#setupBuiltInMacros()
|
||||
*/
|
||||
public void setupBuiltInMacros(IScannerData scannerData) {
|
||||
|
||||
// if( scannerData.getLanguage() == ParserLanguage.CPP )
|
||||
// if( scannerData.getScanner().getDefinition( IScanner.__CPLUSPLUS ) == null )
|
||||
// scannerData.getScanner().addDefinition( IScanner.__CPLUSPLUS, CPLUSPLUS_MACRO);
|
||||
//
|
||||
// if( scannerData.getScanner().getDefinition(IScanner.__STDC_HOSTED__) == null )
|
||||
// scannerData.getScanner().addDefinition(IScanner.__STDC_HOSTED__, STDC_HOSTED_MACRO);
|
||||
// if( scannerData.getScanner().getDefinition( IScanner.__STDC_VERSION__) == null )
|
||||
// scannerData.getScanner().addDefinition( IScanner.__STDC_VERSION__, STDC_VERSION_MACRO);
|
||||
//
|
||||
// // add these to private table
|
||||
//// if( scannerData.getScanner().getDefinition( __ATTRIBUTE__) == null )
|
||||
//// scannerData.getPrivateDefinitions().put( __ATTRIBUTE__, ATTRIBUTE_MACRO);
|
||||
////
|
||||
//// if( scannerData.getScanner().getDefinition( __DECLSPEC) == null )
|
||||
//// scannerData.getPrivateDefinitions().put( __DECLSPEC, DECLSPEC_MACRO );
|
||||
////
|
||||
// if( scannerData.getScanner().getDefinition( __EXTENSION__ ) == null )
|
||||
// scannerData.getPrivateDefinitions().put( __EXTENSION__, EXTENSION_MACRO);
|
||||
//
|
||||
// if( scannerData.getScanner().getDefinition( __CONST__ ) == null )
|
||||
// scannerData.getPrivateDefinitions().put( __CONST__, __CONST__MACRO);
|
||||
// if( scannerData.getScanner().getDefinition( __CONST ) == null )
|
||||
// scannerData.getPrivateDefinitions().put( __CONST, __CONST_MACRO);
|
||||
// if( scannerData.getScanner().getDefinition( __INLINE__ ) == null )
|
||||
// scannerData.getPrivateDefinitions().put( __INLINE__, __INLINE__MACRO);
|
||||
// if( scannerData.getScanner().getDefinition( __SIGNED__ ) == null )
|
||||
// scannerData.getPrivateDefinitions().put( __SIGNED__, __SIGNED__MACRO);
|
||||
// if( scannerData.getScanner().getDefinition( __VOLATILE__ ) == null )
|
||||
// scannerData.getPrivateDefinitions().put( __VOLATILE__, __VOLATILE__MACRO);
|
||||
// ObjectMacroDescriptor __RESTRICT_MACRO = new ObjectMacroDescriptor( __RESTRICT, Keywords.RESTRICT );
|
||||
// if( scannerData.getScanner().getDefinition( __RESTRICT ) == null )
|
||||
// scannerData.getPrivateDefinitions().put( __RESTRICT, __RESTRICT_MACRO);
|
||||
// if( scannerData.getScanner().getDefinition( __RESTRICT__ ) == null )
|
||||
// scannerData.getPrivateDefinitions().put( __RESTRICT__, __RESTRICT__MACRO);
|
||||
// if( scannerData.getScanner().getDefinition( __TYPEOF__ ) == null )
|
||||
// scannerData.getPrivateDefinitions().put( __TYPEOF__, __TYPEOF__MACRO);
|
||||
// if( scannerData.getLanguage() == ParserLanguage.CPP )
|
||||
// if( scannerData.getScanner().getDefinition( __ASM__ ) == null )
|
||||
// scannerData.getPrivateDefinitions().put( __ASM__, __ASM__MACRO);
|
||||
//
|
||||
}
|
||||
|
||||
private static final Set directives;
|
||||
static
|
||||
{
|
||||
directives = new HashSet();
|
||||
directives.add( POUND_INCLUDE_NEXT );
|
||||
directives.add( POUND_WARNING);
|
||||
directives.add( POUND_IDENT);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.extension.IScannerExtension#canHandlePreprocessorDirective(java.lang.String)
|
||||
*/
|
||||
public boolean canHandlePreprocessorDirective(String directive) {
|
||||
return directives.contains( directive );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.extension.IScannerExtension#handlePreprocessorDirective(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void handlePreprocessorDirective(IScannerData iscanner, String directive, String restOfLine) {
|
||||
if( directive.equals(POUND_INCLUDE_NEXT) )
|
||||
{
|
||||
TraceUtil.outputTrace(iscanner.getLogService(), "GCCScannerExtension handling #include_next directive" ); //$NON-NLS-1$
|
||||
// figure out the name of the current file and its path
|
||||
// IScannerContext context = iscanner.getContextStack().getCurrentContext();
|
||||
// if( context == null || context.getKind() != IScannerContext.ContextKind.INCLUSION )
|
||||
// return;
|
||||
//
|
||||
// String fullInclusionPath = context.getContextName();
|
||||
// IASTInclusion inclusion = ((ScannerContextInclusion)context).getExtension();
|
||||
//
|
||||
// Iterator iter = iscanner.getIncludePathNames().iterator();
|
||||
//
|
||||
// while (iter.hasNext()) {
|
||||
// String path = (String)iter.next();
|
||||
// String completePath = ScannerUtility.createReconciledPath(path, inclusion.getName() );
|
||||
// if( completePath.equals( fullInclusionPath ) )
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// ScannerUtility.InclusionDirective parsedDirective = null;
|
||||
// try {
|
||||
// parsedDirective = iscanner.parseInclusionDirective( restOfLine, iscanner.getContextStack().getCurrentContext().getOffset() );
|
||||
// } catch (InclusionParseException e) {
|
||||
// return;
|
||||
// }
|
||||
// CodeReader duple = null;
|
||||
// // search through include paths
|
||||
// while (iter.hasNext()) {
|
||||
// String path = (String)iter.next();
|
||||
// String finalPath = ScannerUtility.createReconciledPath(path, parsedDirective.getFilename());
|
||||
// duple = (CodeReader)iscanner.getFileCache().get(finalPath);
|
||||
// if (duple == null) {
|
||||
// duple = ScannerUtility.createReaderDuple( finalPath, iscanner.getClientRequestor(), iscanner.getWorkingCopies() );
|
||||
// if (duple != null && duple.isFile())
|
||||
// iscanner.getFileCache().put(duple.filename, duple);
|
||||
// }
|
||||
// if( duple != null )
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// if( duple != null )
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// iscanner.getContextStack().updateInclusionContext(duple, inclusion, iscanner.getClientRequestor() );
|
||||
// TraceUtil.outputTrace( iscanner.getLogService(), "GCCScannerExtension handling #include_next directive successfully pushed on new include file" ); //$NON-NLS-1$
|
||||
// }
|
||||
// catch (ContextException e1)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
}
|
||||
else if( directive.equals( POUND_WARNING) || directive.equals(POUND_IDENT))
|
||||
return; // good enough -- the rest of the line has been consumed
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.extension.IScannerExtension#offersDifferentIdentifierCharacters()
|
||||
*/
|
||||
public boolean offersDifferentIdentifierCharacters() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.extension.IScannerExtension#isValidIdentifierStartCharacter(int)
|
||||
*/
|
||||
public boolean isValidIdentifierStartCharacter(int c) {
|
||||
return Character.isLetter((char)c) || ( c == '_') || ( c == '$' );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.extension.IScannerExtension#isValidIdentifierCharacter(int)
|
||||
*/
|
||||
public boolean isValidIdentifierCharacter(int c) {
|
||||
return ((c >= 'a') && (c <= 'z'))
|
||||
|| ((c >= 'A') && (c <= 'Z'))
|
||||
|| ((c >= '0') && (c <= '9'))
|
||||
|| (c == '_') || ( c== '$' ) ||
|
||||
Character.isUnicodeIdentifierPart( (char)c);
|
||||
}
|
||||
|
||||
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();
|
||||
additionalCKeywords.put( GCCKeywords.__ALIGNOF__, new Integer( IGCCToken.t___alignof__ ));
|
||||
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(ParserLanguage language, String tokenImage) {
|
||||
if( language == ParserLanguage.CPP )
|
||||
return ( additionalCPPKeywords.get( tokenImage ) != null );
|
||||
else if( language == ParserLanguage.C )
|
||||
return ( additionalCKeywords.get( tokenImage ) != null );
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.extension.IScannerExtension#createExtensionToken()
|
||||
*/
|
||||
public IToken createExtensionToken(IScannerData scannerData, String image) {
|
||||
Integer get = null;
|
||||
if( scannerData.getLanguage() == ParserLanguage.CPP )
|
||||
{
|
||||
get = (Integer) additionalCPPKeywords.get( image );
|
||||
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 null;
|
||||
// return TokenFactory.createUniquelyImagedToken(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;
|
||||
}
|
||||
|
||||
}
|
|
@ -8,54 +8,24 @@
|
|||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.ScannerUtility.InclusionDirective;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.ScannerUtility.InclusionParseException;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public interface IScannerData {
|
||||
public Map getFileCache();
|
||||
/**
|
||||
* @return Returns the contextStack.
|
||||
*/
|
||||
public abstract ContextStack getContextStack();
|
||||
/**
|
||||
* @param includePathNames The includePathNames to set.
|
||||
*/
|
||||
public abstract void setIncludePathNames(List includePathNames);
|
||||
/**
|
||||
* @return Returns the includePathNames.
|
||||
*/
|
||||
public abstract List getIncludePathNames();
|
||||
/**
|
||||
* @return Returns the originalConfig.
|
||||
*/
|
||||
public abstract IScannerInfo getOriginalConfig();
|
||||
/**
|
||||
* @return Returns the scanner.
|
||||
*/
|
||||
public abstract IScanner getScanner();
|
||||
public abstract IASTFactory getASTFactory();
|
||||
public abstract void setASTFactory(IASTFactory factory);
|
||||
public abstract BranchTracker getBranchTracker(); // deprecated
|
||||
public abstract Map getPublicDefinitions();
|
||||
public Map getPrivateDefinitions();
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns the problemFactory.
|
||||
*/
|
||||
|
@ -68,19 +38,12 @@ public interface IScannerData {
|
|||
* @return Returns the parserMode.
|
||||
*/
|
||||
public abstract ParserMode getParserMode();
|
||||
/**
|
||||
* @return Returns the reader.
|
||||
*/
|
||||
public abstract CodeReader getInitialReader();
|
||||
|
||||
/**
|
||||
* @return Returns the requestor.
|
||||
*/
|
||||
public abstract ISourceElementRequestor getClientRequestor();
|
||||
public abstract IParserLogService getLogService();
|
||||
/**
|
||||
* @param empty_map
|
||||
*/
|
||||
public abstract void setDefinitions(Map map);
|
||||
|
||||
public Iterator getWorkingCopies();
|
||||
/**
|
||||
|
@ -88,5 +51,5 @@ public interface IScannerData {
|
|||
* @param offset
|
||||
* @return
|
||||
*/
|
||||
public abstract InclusionDirective parseInclusionDirective(String restOfLine, int offset) throws InclusionParseException;
|
||||
// public abstract InclusionDirective parseInclusionDirective(String restOfLine, int offset) throws InclusionParseException;
|
||||
}
|
|
@ -20,7 +20,6 @@ import java.util.Map;
|
|||
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
||||
import org.eclipse.cdt.core.parser.IMacroDescriptor;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IProblem;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
|
@ -32,23 +31,18 @@ import org.eclipse.cdt.core.parser.OffsetLimitReachedException;
|
|||
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ScannerException;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTMacro;
|
||||
import org.eclipse.cdt.core.parser.extension.IScannerExtension;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectStyleMacro;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.ASTCompletionNode;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator;
|
||||
import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.BranchTracker;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.ContextStack;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.IScannerContext;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.IScannerData;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.ScannerProblemFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.ScannerUtility;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.ScannerUtility.InclusionDirective;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.ScannerUtility.InclusionParseException;
|
||||
import org.eclipse.cdt.internal.core.parser.token.ImagedExpansionToken;
|
||||
import org.eclipse.cdt.internal.core.parser.token.ImagedToken;
|
||||
import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
|
||||
|
@ -168,8 +162,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
if( value instanceof String ) {
|
||||
//TODO add in check here for '(' and ')'
|
||||
addDefinition( symbolName, scannerExtension.initializeMacroValue(this, (String) value));
|
||||
} else if( value instanceof IMacroDescriptor )
|
||||
addDefinition( symbolName, (IMacroDescriptor)value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -297,13 +290,6 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
callbackPos = -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScanner#addDefinition(java.lang.String, org.eclipse.cdt.core.parser.IMacroDescriptor)
|
||||
*/
|
||||
public void addDefinition(String key, IMacroDescriptor macroToBeAdded) {
|
||||
//definitions.put(key.toCharArray(), macroToBeAdded);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScanner#addDefinition(java.lang.String, java.lang.String)
|
||||
*/
|
||||
|
@ -319,13 +305,6 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
return count;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScanner#getDefinition(java.lang.String)
|
||||
*/
|
||||
public IMacroDescriptor getDefinition(String key) {
|
||||
return (IMacroDescriptor)definitions.get(key.toCharArray());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScanner#getDefinitions()
|
||||
*/
|
||||
|
@ -344,13 +323,6 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
return definitions;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScanner#getDepth()
|
||||
*/
|
||||
public int getDepth() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScanner#getIncludePaths()
|
||||
|
@ -379,7 +351,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScanner#nextToken()
|
||||
*/
|
||||
public IToken nextToken() throws ScannerException, EndOfFileException {
|
||||
public IToken nextToken() throws EndOfFileException {
|
||||
if (nextToken == null && !finished ) {
|
||||
nextToken = fetchToken();
|
||||
if (nextToken == null)
|
||||
|
@ -446,7 +418,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
}
|
||||
|
||||
// Return null to signify end of file
|
||||
private IToken fetchToken() throws ScannerException, EndOfFileException{
|
||||
private IToken fetchToken() throws EndOfFileException{
|
||||
++count;
|
||||
contextLoop:
|
||||
while (bufferStackPos >= 0) {
|
||||
|
@ -1270,7 +1242,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
return false;
|
||||
}
|
||||
|
||||
private void handlePPDirective(int pos) throws ScannerException, EndOfFileException {
|
||||
private void handlePPDirective(int pos) throws EndOfFileException {
|
||||
char[] buffer = bufferStack[bufferStackPos];
|
||||
int limit = bufferLimit[bufferStackPos];
|
||||
int startingLineNumber = getLineNumber( pos );
|
||||
|
@ -1690,7 +1662,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
? new ObjectStyleMacro(name, text)
|
||||
: new FunctionStyleMacro(name, text, arglist) );
|
||||
|
||||
pushCallback( getASTFactory().createMacro( name, startingOffset, startingLineNumber, idstart, idstart + idlen, nameLine, textstart + textlen, endingLine, null, getCurrentFilename() ) );//TODO - IMacroDescriptor?
|
||||
pushCallback( getASTFactory().createMacro( name, startingOffset, startingLineNumber, idstart, idstart + idlen, nameLine, textstart + textlen, endingLine, getCurrentFilename() ) );
|
||||
}
|
||||
|
||||
|
||||
|
@ -2839,30 +2811,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
*/
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScanner#nextToken(boolean)
|
||||
*/
|
||||
public IToken nextToken(boolean next) throws ScannerException,
|
||||
EndOfFileException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScanner#nextTokenForStringizing()
|
||||
*/
|
||||
public IToken nextTokenForStringizing() throws ScannerException,
|
||||
EndOfFileException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScanner#overwriteIncludePath(java.lang.String[])
|
||||
*/
|
||||
public void overwriteIncludePath(String[] newIncludePaths) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#setASTFactory(org.eclipse.cdt.core.parser.ast.IASTFactory)
|
||||
*/
|
||||
|
@ -2876,27 +2825,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
offsetBoundary = offset;
|
||||
bufferLimit[0] = offset;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScanner#setScannerContext(org.eclipse.cdt.internal.core.parser.scanner.IScannerContext)
|
||||
*/
|
||||
public void setScannerContext(IScannerContext context) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScanner#setThrowExceptionOnBadCharacterRead(boolean)
|
||||
*/
|
||||
public void setThrowExceptionOnBadCharacterRead(boolean throwOnBad) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScanner#setTokenizingMacroReplacementList(boolean)
|
||||
*/
|
||||
public void setTokenizingMacroReplacementList(boolean b) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getASTFactory()
|
||||
*/
|
||||
|
@ -2905,47 +2834,14 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
astFactory = ParserFactory.createASTFactory( parserMode, language );
|
||||
return astFactory;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getBranchTracker()
|
||||
*/
|
||||
public BranchTracker getBranchTracker() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getClientRequestor()
|
||||
*/
|
||||
public ISourceElementRequestor getClientRequestor() {
|
||||
return requestor;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getContextStack()
|
||||
*/
|
||||
public ContextStack getContextStack() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getFileCache()
|
||||
*/
|
||||
public Map getFileCache() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getIncludePathNames()
|
||||
*/
|
||||
public List getIncludePathNames() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getInitialReader()
|
||||
*/
|
||||
public CodeReader getInitialReader() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getLanguage()
|
||||
*/
|
||||
|
@ -2958,46 +2854,19 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
public IParserLogService getLogService() {
|
||||
return log;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getOriginalConfig()
|
||||
*/
|
||||
public IScannerInfo getOriginalConfig() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getParserMode()
|
||||
*/
|
||||
public ParserMode getParserMode() {
|
||||
return parserMode;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getPrivateDefinitions()
|
||||
*/
|
||||
public Map getPrivateDefinitions() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getProblemFactory()
|
||||
*/
|
||||
public IProblemFactory getProblemFactory() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getPublicDefinitions()
|
||||
*/
|
||||
public Map getPublicDefinitions() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getScanner()
|
||||
*/
|
||||
public IScanner getScanner() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return spf;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getWorkingCopies()
|
||||
|
@ -3006,28 +2875,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
if( workingCopies == null ) return EmptyIterator.EMPTY_ITERATOR;
|
||||
return workingCopies.iterator();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#parseInclusionDirective(java.lang.String, int)
|
||||
*/
|
||||
public InclusionDirective parseInclusionDirective(String restOfLine,
|
||||
int offset) throws InclusionParseException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#setDefinitions(java.util.Map)
|
||||
*/
|
||||
public void setDefinitions(Map map) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#setIncludePathNames(java.util.List)
|
||||
*/
|
||||
public void setIncludePathNames(List includePathNames) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
private final char[] getCurrentFilename() {
|
||||
for( int i = bufferStackPos; i >= 0; --i )
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
|
||||
import org.eclipse.cdt.core.parser.IProblem;
|
||||
import org.eclipse.cdt.internal.core.parser.problem.BaseProblemFactory;
|
|
@ -1,13 +1,14 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003, 2004 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
/**********************************************************************
|
||||
* Copyright (c) 2002-2004 Rational Software Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corp. - Rational Software - initial implementation
|
||||
******************************************************************************/package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Iterator;
|
||||
|
@ -18,6 +19,7 @@ import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
|||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
*/
|
||||
public class ScannerUtility {
|
||||
|
||||
|
@ -105,7 +107,7 @@ public class ScannerUtility {
|
|||
return useIncludePaths;
|
||||
}
|
||||
|
||||
String getFilename()
|
||||
public String getFilename()
|
||||
{
|
||||
return fileName;
|
||||
}
|
||||
|
@ -125,4 +127,5 @@ public class ScannerUtility {
|
|||
{
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -17,7 +17,7 @@ import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
|||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.ITokenDuple;
|
||||
import org.eclipse.cdt.core.parser.ast.IReferenceManager;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,7 +19,7 @@ import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
|||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.ITokenDuple;
|
||||
import org.eclipse.cdt.core.parser.ast.IReferenceManager;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
|
|
@ -11,24 +11,12 @@
|
|||
package org.eclipse.cdt.internal.core.parser.token;
|
||||
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.ContextStack;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.IScannerContext;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.ScannerContextMacro;
|
||||
|
||||
/**
|
||||
* @author johnc
|
||||
*/
|
||||
public class ImagedExpansionToken extends ImagedToken implements IToken {
|
||||
|
||||
/**
|
||||
* @param t
|
||||
* @param contextStack
|
||||
* @param i
|
||||
*/
|
||||
public ImagedExpansionToken(int t, ContextStack contextStack, char[] i, char [] f) {
|
||||
super(t, contextStack, i, f);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param t
|
||||
* @param contextStack
|
||||
|
@ -48,15 +36,6 @@ public class ImagedExpansionToken extends ImagedToken implements IToken {
|
|||
|
||||
protected int length;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.token.SimpleToken#setOffsetAndLength(org.eclipse.cdt.internal.core.parser.scanner.IScannerContext)
|
||||
*/
|
||||
protected void setOffsetAndLength(IScannerContext context) {
|
||||
ScannerContextMacro m = (ScannerContextMacro) context;
|
||||
offset = m.getOffset();
|
||||
length = m.getMacroLength();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.token.AbstractToken#getLength()
|
||||
*/
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
***********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.token;
|
||||
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.ContextStack;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.IScannerContext;
|
||||
|
||||
/**
|
||||
* @author johnc
|
||||
|
@ -20,17 +18,6 @@ public class ImagedToken extends SimpleToken {
|
|||
|
||||
protected char [] image = null;
|
||||
|
||||
/**
|
||||
* @param t
|
||||
* @param contextStack
|
||||
* @param i
|
||||
*/
|
||||
public ImagedToken(int t, ContextStack contextStack, char[] i, char [] f) {
|
||||
super(t, contextStack, f );
|
||||
setImage( i );
|
||||
setOffsetAndLength(contextStack.getCurrentContext());
|
||||
}
|
||||
|
||||
public ImagedToken( int t, char[] i, int endOffset, char [] f, int l ) {
|
||||
super( t, 0, f, l );
|
||||
setImage(i);
|
||||
|
@ -61,18 +48,6 @@ public class ImagedToken extends SimpleToken {
|
|||
this.image = image;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context
|
||||
*/
|
||||
protected void setOffsetAndLength(IScannerContext context) {
|
||||
if( getImage() == null ) return;
|
||||
offset = context.getOffset() - getCharImage().length;
|
||||
if( getType() == tSTRING || getType() == tCHAR )
|
||||
offset--;
|
||||
else if( getType() == tLSTRING || getType() == tLCHAR )
|
||||
offset -= 2;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
if( getCharImage() == null )
|
||||
return 0;
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002-2004 IBM Canada and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.token;
|
||||
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.ContextStack;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.IScannerContext;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.ScannerContextMacro;
|
||||
|
||||
/**
|
||||
* @author johnc
|
||||
*/
|
||||
public class SimpleExpansionToken extends SimpleToken implements IToken {
|
||||
|
||||
/**
|
||||
* @param tokenType
|
||||
* @param stack
|
||||
*/
|
||||
public SimpleExpansionToken(int tokenType, ContextStack stack, char [] f) {
|
||||
super( tokenType, stack, f );
|
||||
}
|
||||
|
||||
protected int length;
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.token.SimpleToken#setOffsetAndLength(org.eclipse.cdt.internal.core.parser.scanner.IScannerContext)
|
||||
*/
|
||||
protected void setOffsetAndLength(IScannerContext context) {
|
||||
ScannerContextMacro m = (ScannerContextMacro) context;
|
||||
offset = m.getOffset();
|
||||
length = m.getMacroLength();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.token.AbstractToken#getLength()
|
||||
*/
|
||||
public final int getLength() {
|
||||
return length;
|
||||
}
|
||||
}
|
|
@ -13,16 +13,9 @@ package org.eclipse.cdt.internal.core.parser.token;
|
|||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.Keywords;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.ContextStack;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.IScannerContext;
|
||||
|
||||
public class SimpleToken extends AbstractToken implements IToken {
|
||||
|
||||
public SimpleToken(int t, ContextStack contextStack, char [] filename ) {
|
||||
super(t,contextStack.getCurrentLineNumber(), filename );
|
||||
setOffsetAndLength(contextStack.getCurrentContext());
|
||||
}
|
||||
|
||||
public SimpleToken( int t, int endOffset, char [] filename, int line )
|
||||
{
|
||||
super( t, filename, line );
|
||||
|
@ -41,13 +34,6 @@ public class SimpleToken extends AbstractToken implements IToken {
|
|||
return getCharImage().length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context
|
||||
*/
|
||||
protected void setOffsetAndLength(IScannerContext context) {
|
||||
offset = context.getOffset() - getLength();
|
||||
}
|
||||
|
||||
protected void setOffsetAndLength( int endOffset )
|
||||
{
|
||||
this.offset = endOffset - getLength();
|
||||
|
|
|
@ -15,8 +15,6 @@ import java.util.List;
|
|||
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.ITokenDuple;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.IScannerContext;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.IScannerData;
|
||||
|
||||
/**
|
||||
* @author johnc
|
||||
|
@ -24,34 +22,6 @@ import org.eclipse.cdt.internal.core.parser.scanner.IScannerData;
|
|||
public class TokenFactory {
|
||||
|
||||
protected static final char[] EMPTY_CHAR_ARRAY = "".toCharArray(); //$NON-NLS-1$
|
||||
public static IToken createToken( int tokenType, IScannerData scannerData )
|
||||
{
|
||||
if( scannerData.getContextStack().getCurrentContext().getKind() == IScannerContext.ContextKind.MACROEXPANSION )
|
||||
return new SimpleExpansionToken( tokenType, scannerData.getContextStack(), getCurrentFilename(scannerData) );
|
||||
|
||||
return new SimpleToken( tokenType, scannerData.getContextStack(), getCurrentFilename(scannerData) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param scannerData
|
||||
* @return
|
||||
*/
|
||||
private static char[] getCurrentFilename(IScannerData scannerData) {
|
||||
return scannerData.getContextStack().getInclusionFilename(scannerData.getContextStack().getMostRelevantFileContextIndex() ).toCharArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type
|
||||
* @param image
|
||||
* @param scannerData
|
||||
* @return
|
||||
*/
|
||||
public static IToken createUniquelyImagedToken(int type, String image, IScannerData scannerData) {
|
||||
if( scannerData.getContextStack().getCurrentContext().getKind() == IScannerContext.ContextKind.MACROEXPANSION )
|
||||
return new ImagedExpansionToken( type, scannerData.getContextStack(), image.toCharArray(), getCurrentFilename(scannerData) );
|
||||
|
||||
return new ImagedToken(type, scannerData.getContextStack(), image.toCharArray(), getCurrentFilename(scannerData));
|
||||
}
|
||||
|
||||
public static IToken createStandAloneToken( int type, String image )
|
||||
{
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.eclipse.cdt.core.parser.ParserFactoryError;
|
|||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||
import org.eclipse.cdt.core.parser.ScannerException;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
|
||||
import org.eclipse.cdt.core.parser.ast.ASTUtil;
|
||||
|
@ -370,7 +369,6 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
|
|||
try {
|
||||
token = scanner.nextToken();
|
||||
} catch (EndOfFileException e) {
|
||||
} catch (ScannerException e) {
|
||||
}
|
||||
|
||||
if( token != null ){
|
||||
|
@ -609,7 +607,6 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
|
|||
}
|
||||
} catch (EndOfFileException e) {
|
||||
list.addLast( name.toCharArray() );
|
||||
} catch (ScannerException e) {
|
||||
}
|
||||
|
||||
return list;
|
||||
|
|
|
@ -76,12 +76,12 @@ import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
|
|||
import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTVariableReference;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectSet;
|
||||
import org.eclipse.cdt.core.search.ICSearchPattern;
|
||||
import org.eclipse.cdt.core.search.ICSearchResultCollector;
|
||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||
import org.eclipse.cdt.core.search.IMatch;
|
||||
import org.eclipse.cdt.core.search.IMatchLocator;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectSet;
|
||||
import org.eclipse.cdt.internal.core.search.AcceptMatchOperation;
|
||||
import org.eclipse.cdt.internal.core.search.indexing.IndexProblemHandler;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
|
|
@ -57,9 +57,9 @@ import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
|||
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNode.ILookupResult;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectStyleMacro;
|
||||
import org.eclipse.cdt.internal.core.CharOperation;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.FunctionStyleMacro;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectStyleMacro;
|
||||
import org.eclipse.cdt.internal.ui.CUIMessages;
|
||||
import org.eclipse.cdt.internal.ui.util.IDebugLogConstants;
|
||||
import org.eclipse.cdt.internal.ui.util.Util;
|
||||
|
|
Loading…
Add table
Reference in a new issue