mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 14:55:41 +02:00
Activated Scanner2 in HEAD.
Forgive me Lord, for I know what I do.
This commit is contained in:
parent
39dd636454
commit
fd62bdd86c
9 changed files with 18 additions and 55 deletions
|
@ -249,10 +249,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
|
||||||
i = getDeclarations( test );
|
i = getDeclarations( test );
|
||||||
IASTVariable someInt = (IASTVariable) i.next();
|
IASTVariable someInt = (IASTVariable) i.next();
|
||||||
IASTExpression exp = someInt.getInitializerClause().getAssigmentExpression();
|
IASTExpression exp = someInt.getInitializerClause().getAssigmentExpression();
|
||||||
if( ParserFactory.USE_NEW_SCANNER )
|
assertEquals( exp.toString(), "foo(int(3), short(4), double(3.0), float(4.0), char('a'), wchar_t('a'), signed(2), unsigned(3), bool(false), long(3L))" ); //$NON-NLS-1$
|
||||||
assertEquals( exp.toString(), "foo(int(3), short(4), double(3.0), float(4.0), char('a'), wchar_t('a'), signed(2), unsigned(3), bool(false), long(3L))" ); //$NON-NLS-1$
|
|
||||||
else
|
|
||||||
assertEquals( exp.toString(), "foo(int(3), short(4), double(3.0), float(4.0), char('a'), wchar_t('a'), signed(2), unsigned(3), bool(false), long(3))" ); //$NON-NLS-1$
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kind POSTFIX_TYPENAME_IDENTIFIER
|
// Kind POSTFIX_TYPENAME_IDENTIFIER
|
||||||
|
|
|
@ -16,7 +16,6 @@ import junit.framework.TestSuite;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.tests.CModelElementsTests;
|
import org.eclipse.cdt.core.model.tests.CModelElementsTests;
|
||||||
import org.eclipse.cdt.core.model.tests.StructuralCModelElementsTests;
|
import org.eclipse.cdt.core.model.tests.StructuralCModelElementsTests;
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
|
||||||
import org.eclipse.cdt.core.parser.tests.scanner2.ObjectMapTest;
|
import org.eclipse.cdt.core.parser.tests.scanner2.ObjectMapTest;
|
||||||
import org.eclipse.cdt.core.parser.tests.scanner2.Scanner2Test;
|
import org.eclipse.cdt.core.parser.tests.scanner2.Scanner2Test;
|
||||||
|
|
||||||
|
@ -29,14 +28,7 @@ import org.eclipse.cdt.core.parser.tests.scanner2.Scanner2Test;
|
||||||
public class ParserTestSuite extends TestCase {
|
public class ParserTestSuite extends TestCase {
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
TestSuite suite= new TestSuite(ParserTestSuite.class.getName());
|
TestSuite suite= new TestSuite(ParserTestSuite.class.getName());
|
||||||
if( ParserFactory.USE_NEW_SCANNER )
|
suite.addTestSuite(Scanner2Test.class );
|
||||||
suite.addTestSuite(Scanner2Test.class );
|
|
||||||
else
|
|
||||||
{
|
|
||||||
suite.addTestSuite(BranchTrackerTest.class);
|
|
||||||
suite.addTestSuite(ScannerTestCase.class);
|
|
||||||
suite.addTestSuite(ExprEvalTest.class);
|
|
||||||
}
|
|
||||||
suite.addTestSuite(QuickParseASTTests.class);
|
suite.addTestSuite(QuickParseASTTests.class);
|
||||||
suite.addTestSuite(ParserSymbolTableTest.class);
|
suite.addTestSuite(ParserSymbolTableTest.class);
|
||||||
suite.addTestSuite(ParserSymbolTableTemplateTests.class );
|
suite.addTestSuite(ParserSymbolTableTemplateTests.class );
|
||||||
|
|
|
@ -29,7 +29,6 @@ import org.eclipse.cdt.internal.core.parser.StructuralParser;
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.complete.CompleteParseASTFactory;
|
import org.eclipse.cdt.internal.core.parser.ast.complete.CompleteParseASTFactory;
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.expression.ExpressionParseASTFactory;
|
import org.eclipse.cdt.internal.core.parser.ast.expression.ExpressionParseASTFactory;
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.quick.QuickParseASTFactory;
|
import org.eclipse.cdt.internal.core.parser.ast.quick.QuickParseASTFactory;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.Scanner;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner2.Scanner2;
|
import org.eclipse.cdt.internal.core.parser.scanner2.Scanner2;
|
||||||
import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
|
import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
|
||||||
|
|
||||||
|
@ -40,8 +39,6 @@ import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
|
||||||
*/
|
*/
|
||||||
public class ParserFactory {
|
public class ParserFactory {
|
||||||
|
|
||||||
public static final boolean USE_NEW_SCANNER = false;
|
|
||||||
|
|
||||||
private static IParserExtensionFactory extensionFactory = new ParserExtensionFactory( ExtensionDialect.GCC );
|
private static IParserExtensionFactory extensionFactory = new ParserExtensionFactory( ExtensionDialect.GCC );
|
||||||
|
|
||||||
public static IASTFactory createASTFactory( ParserMode mode, ParserLanguage language )
|
public static IASTFactory createASTFactory( ParserMode mode, ParserLanguage language )
|
||||||
|
@ -104,12 +101,7 @@ public class ParserFactory {
|
||||||
IParserLogService logService = ( log == null ) ? createDefaultLogService() : log;
|
IParserLogService logService = ( log == null ) ? createDefaultLogService() : log;
|
||||||
ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode );
|
ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode );
|
||||||
ISourceElementRequestor ourRequestor = (( requestor == null) ? new NullSourceElementRequestor() : requestor );
|
ISourceElementRequestor ourRequestor = (( requestor == null) ? new NullSourceElementRequestor() : requestor );
|
||||||
IScanner s = null;
|
return new Scanner2( code, config, ourRequestor, ourMode, language, logService, extensionFactory.createScannerExtension(), workingCopies );
|
||||||
if( USE_NEW_SCANNER )
|
|
||||||
s = new Scanner2( code, config, ourRequestor, ourMode, language, logService, extensionFactory.createScannerExtension(), workingCopies );
|
|
||||||
else
|
|
||||||
s = new Scanner( code, config, ourRequestor, ourMode, language, logService, extensionFactory.createScannerExtension(), workingCopies );
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IScanner createScanner( String fileName, IScannerInfo config, ParserMode mode, ParserLanguage language, ISourceElementRequestor requestor, IParserLogService log, List workingCopies ) throws ParserFactoryError, IOException
|
public static IScanner createScanner( String fileName, IScannerInfo config, ParserMode mode, ParserLanguage language, ISourceElementRequestor requestor, IParserLogService log, List workingCopies ) throws ParserFactoryError, IOException
|
||||||
|
|
|
@ -551,10 +551,10 @@ public class DeclarationWrapper implements IDeclaratorOwner
|
||||||
for( int i = 0; i < currentParameters.size(); ++i )
|
for( int i = 0; i < currentParameters.size(); ++i )
|
||||||
{
|
{
|
||||||
DeclarationWrapper wrapper = (DeclarationWrapper)currentParameters.get(i);
|
DeclarationWrapper wrapper = (DeclarationWrapper)currentParameters.get(i);
|
||||||
List declarators = wrapper.getDeclaratorsList();
|
List decls = wrapper.getDeclaratorsList();
|
||||||
for( int j = 0; j < declarators.size(); j++ )
|
for( int j = 0; j < decls.size(); j++ )
|
||||||
{
|
{
|
||||||
Declarator declarator = (Declarator)declarators.get(j);
|
Declarator declarator = (Declarator)decls.get(j);
|
||||||
|
|
||||||
result.add(
|
result.add(
|
||||||
astFactory.createParameterDeclaration(
|
astFactory.createParameterDeclaration(
|
||||||
|
|
|
@ -22,7 +22,6 @@ import org.eclipse.cdt.core.parser.IProblem;
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
|
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
|
||||||
import org.eclipse.cdt.core.parser.IToken;
|
import org.eclipse.cdt.core.parser.IToken;
|
||||||
import org.eclipse.cdt.core.parser.ITokenDuple;
|
import org.eclipse.cdt.core.parser.ITokenDuple;
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||||
|
@ -1560,21 +1559,14 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
||||||
info = provider.completeConstruction();
|
info = provider.completeConstruction();
|
||||||
|
|
||||||
//types that need a pointer
|
//types that need a pointer
|
||||||
if( ParserFactory.USE_NEW_SCANNER ){
|
|
||||||
if( kind == IASTExpression.Kind.PRIMARY_STRING_LITERAL ||
|
if( kind == IASTExpression.Kind.PRIMARY_STRING_LITERAL ||
|
||||||
(literal.length > 3 && ( kind == IASTExpression.Kind.PRIMARY_CHAR_LITERAL ||
|
(literal.length > 3 && ( kind == IASTExpression.Kind.PRIMARY_CHAR_LITERAL ||
|
||||||
kind == IASTExpression.Kind.POSTFIX_SIMPLETYPE_CHAR )) )
|
kind == IASTExpression.Kind.POSTFIX_SIMPLETYPE_CHAR )) )
|
||||||
{
|
{
|
||||||
info.addPtrOperator(new ITypeInfo.PtrOp(ITypeInfo.PtrOp.t_pointer));
|
info.addPtrOperator(new ITypeInfo.PtrOp(ITypeInfo.PtrOp.t_pointer));
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if( kind == IASTExpression.Kind.PRIMARY_STRING_LITERAL ||
|
|
||||||
(literal.length > 1 && ( kind == IASTExpression.Kind.PRIMARY_CHAR_LITERAL ||
|
|
||||||
kind == IASTExpression.Kind.POSTFIX_SIMPLETYPE_CHAR )) )
|
|
||||||
{
|
|
||||||
info.addPtrOperator(new ITypeInfo.PtrOp(ITypeInfo.PtrOp.t_pointer));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ExpressionResult( info );
|
return new ExpressionResult( info );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ExpressionFactory {
|
public class ExpressionFactory {
|
||||||
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -187,8 +187,10 @@ public class ExpressionEvaluator {
|
||||||
long r2 = unaryExpression();
|
long r2 = unaryExpression();
|
||||||
if (t == tMULT)
|
if (t == tMULT)
|
||||||
r1 = r1 * r2;
|
r1 = r1 * r2;
|
||||||
else // t == tDIV;
|
else if( r2 != 0 )// t == tDIV;
|
||||||
r1 = r1 / r2;
|
r1 = r1 / r2;
|
||||||
|
else
|
||||||
|
throw new EvalException( "Divide by 0 encountered"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
return r1;
|
return r1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -746,6 +746,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
||||||
{
|
{
|
||||||
// escaped newline
|
// escaped newline
|
||||||
++bufferPos[bufferStackPos];
|
++bufferPos[bufferStackPos];
|
||||||
|
++bufferLineNums[bufferStackPos];
|
||||||
len += 2;
|
len += 2;
|
||||||
escapedNewline = true;
|
escapedNewline = true;
|
||||||
continue;
|
continue;
|
||||||
|
@ -1216,6 +1217,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
||||||
{
|
{
|
||||||
// escaped newline
|
// escaped newline
|
||||||
++bufferPos[bufferStackPos];
|
++bufferPos[bufferStackPos];
|
||||||
|
++bufferLineNums[bufferStackPos];
|
||||||
len += 2;
|
len += 2;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.parser.token;
|
package org.eclipse.cdt.internal.core.parser.token;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.ContextStack;
|
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.IScannerContext;
|
||||||
|
|
||||||
|
@ -77,18 +76,6 @@ public class ImagedToken extends SimpleToken {
|
||||||
public int getLength() {
|
public int getLength() {
|
||||||
if( getCharImage() == null )
|
if( getCharImage() == null )
|
||||||
return 0;
|
return 0;
|
||||||
if( ParserFactory.USE_NEW_SCANNER )
|
return getCharImage().length;
|
||||||
return getCharImage().length;
|
|
||||||
switch( getType() )
|
|
||||||
{
|
|
||||||
case tSTRING:
|
|
||||||
case tCHAR:
|
|
||||||
return getCharImage().length + 2; // 'c' is 3 characters, not 1
|
|
||||||
case tLSTRING:
|
|
||||||
case tLCHAR:
|
|
||||||
return getCharImage().length + 3; // L"X" if 4 characters, not 1
|
|
||||||
default:
|
|
||||||
return getCharImage().length;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue