From 6dc6b84d4b926c6b8ae8d199bcc8e51a31cd5699 Mon Sep 17 00:00:00 2001 From: John Camelon Date: Mon, 30 Aug 2004 15:17:40 +0000 Subject: [PATCH] Fixed 72527 - [Scanner] Remove Scanner, ScannerException & clean up IScanner interface --- .../core/parser/tests/BaseScannerTest.java | 233 -- .../core/parser/tests/BranchTrackerTest.java | 205 - .../core/parser/tests/CharArrayUtilsTest.java | 6 +- .../parser/tests/ParserSymbolTableTest.java | 4 +- .../tests/PreprocessorConditionalTest.java | 10 +- .../core/parser/tests/ScannerSpeedTest.java | 6 +- .../core/parser/tests/ScannerTestCase.java | 1751 -------- .../tests/scanner2/BaseScanner2Test.java | 41 +- .../parser/tests/scanner2/ObjectMapTest.java | 4 +- .../tests/scanner2/Scanner2SpeedTest.java | 5 +- .../parser/tests/scanner2/Scanner2Test.java | 147 +- .../core/search/indexing/IndexManager.java | 2 +- .../eclipse/cdt/core/parser/CodeReader.java | 2 +- .../cdt/core/parser/IMacroDescriptor.java | 65 - .../org/eclipse/cdt/core/parser/IScanner.java | 28 +- .../cdt/core/parser/ScannerException.java | 30 - .../cdt/core/parser/ast/IASTFactory.java | 3 +- .../parser/extension/IScannerExtension.java | 2 +- .../parser/util}/CharArrayIntMap.java | 2 +- .../parser/util}/CharArrayObjectMap.java | 2 +- .../parser/util}/CharArrayPool.java | 2 +- .../parser/util}/CharArraySet.java | 2 +- .../parser/util}/CharArrayUtils.java | 2 +- .../parser/util}/CharTable.java | 2 +- .../parser/util}/HashTable.java | 2 +- .../parser/util}/ObjectMap.java | 2 +- .../parser/util}/ObjectSet.java | 2 +- .../parser/util}/ObjectStyleMacro.java | 2 +- .../parser/util}/ObjectTable.java | 2 +- .../core/parser/ExpressionParser.java | 13 +- .../cdt/internal/core/parser/Parser.java | 2 +- .../core/parser/ParserExtensionFactory.java | 2 +- .../internal/core/parser/ast/ASTMacro.java | 49 +- .../core/parser/ast/BaseASTFactory.java | 5 +- .../ast/complete/CompleteParseASTFactory.java | 2 +- .../parser/ast/complete/ReferenceCache.java | 2 +- .../expression/ExpressionParseASTFactory.java | 3 +- .../internal/core/parser/pst/BasicSymbol.java | 2 +- .../core/parser/pst/ContainerSymbol.java | 10 +- .../parser/pst/DeferredTemplateInstance.java | 2 +- .../parser/pst/DerivableContainerSymbol.java | 4 +- .../core/parser/pst/IContainerSymbol.java | 2 +- .../core/parser/pst/IParameterizedSymbol.java | 2 +- .../cdt/internal/core/parser/pst/ISymbol.java | 2 +- .../core/parser/pst/ITemplateSymbol.java | 2 +- .../core/parser/pst/ParameterizedSymbol.java | 4 +- .../core/parser/pst/ParserSymbolTable.java | 10 +- .../core/parser/pst/SpecializedSymbol.java | 2 +- .../core/parser/pst/TemplateEngine.java | 8 +- .../core/parser/pst/TemplateFactory.java | 4 +- .../core/parser/pst/TemplateSymbol.java | 4 +- .../internal/core/parser/pst/TypeFilter.java | 2 +- .../core/parser/scanner/BranchTracker.java | 188 - .../core/parser/scanner/ContextException.java | 37 - .../core/parser/scanner/ContextStack.java | 225 - .../scanner/DynamicMacroDescriptor.java | 91 - .../parser/scanner/DynamicMacroEvaluator.java | 23 - .../scanner/FunctionMacroDescriptor.java | 180 - .../parser/scanner/GCCScannerExtension.java | 311 -- .../core/parser/scanner/IScannerContext.java | 37 - .../parser/scanner/LimitedScannerContext.java | 56 - .../parser/scanner/ObjectMacroDescriptor.java | 123 - .../internal/core/parser/scanner/Scanner.java | 3614 ----------------- .../scanner/ScannerContextInclusion.java | 109 - .../parser/scanner/ScannerContextMacro.java | 90 - .../parser/scanner/ScannerContextTop.java | 25 - .../scanner/ScannerContextTopString.java | 113 - .../parser/scanner/ScannerStringBuffer.java | 61 - .../parser/scanner2/ExpressionEvaluator.java | 4 + .../parser/scanner2/FunctionStyleMacro.java | 3 + .../parser/scanner2/GCCScannerExtension.java | 306 ++ .../{scanner => scanner2}/IScannerData.java | 47 +- .../core/parser/scanner2/Scanner2.java | 180 +- .../ScannerProblemFactory.java | 2 +- .../{scanner => scanner2}/ScannerUtility.java | 23 +- .../core/parser/token/AbstractToken.java | 2 +- .../core/parser/token/BasicTokenDuple.java | 2 +- .../parser/token/ImagedExpansionToken.java | 23 +- .../core/parser/token/ImagedToken.java | 27 +- .../parser/token/SimpleExpansionToken.java | 50 - .../core/parser/token/SimpleToken.java | 16 +- .../core/parser/token/TokenFactory.java | 30 - .../core/search/matching/CSearchPattern.java | 5 +- .../core/search/matching/MatchLocator.java | 2 +- .../text/contentassist/CompletionEngine.java | 2 +- 85 files changed, 476 insertions(+), 8235 deletions(-) delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BranchTrackerTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IMacroDescriptor.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ScannerException.java rename core/org.eclipse.cdt.core/parser/org/eclipse/cdt/{internal/core/parser/scanner2 => core/parser/util}/CharArrayIntMap.java (96%) rename core/org.eclipse.cdt.core/parser/org/eclipse/cdt/{internal/core/parser/scanner2 => core/parser/util}/CharArrayObjectMap.java (98%) rename core/org.eclipse.cdt.core/parser/org/eclipse/cdt/{internal/core/parser/scanner2 => core/parser/util}/CharArrayPool.java (97%) rename core/org.eclipse.cdt.core/parser/org/eclipse/cdt/{internal/core/parser/scanner2 => core/parser/util}/CharArraySet.java (97%) rename core/org.eclipse.cdt.core/parser/org/eclipse/cdt/{internal/core/parser/scanner2 => core/parser/util}/CharArrayUtils.java (99%) rename core/org.eclipse.cdt.core/parser/org/eclipse/cdt/{internal/core/parser/scanner2 => core/parser/util}/CharTable.java (98%) rename core/org.eclipse.cdt.core/parser/org/eclipse/cdt/{internal/core/parser/scanner2 => core/parser/util}/HashTable.java (98%) rename core/org.eclipse.cdt.core/parser/org/eclipse/cdt/{internal/core/parser/scanner2 => core/parser/util}/ObjectMap.java (98%) rename core/org.eclipse.cdt.core/parser/org/eclipse/cdt/{internal/core/parser/scanner2 => core/parser/util}/ObjectSet.java (97%) rename core/org.eclipse.cdt.core/parser/org/eclipse/cdt/{internal/core/parser/scanner2 => core/parser/util}/ObjectStyleMacro.java (93%) rename core/org.eclipse.cdt.core/parser/org/eclipse/cdt/{internal/core/parser/scanner2 => core/parser/util}/ObjectTable.java (98%) delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/BranchTracker.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ContextException.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ContextStack.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/DynamicMacroDescriptor.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/DynamicMacroEvaluator.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/FunctionMacroDescriptor.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/GCCScannerExtension.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/IScannerContext.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LimitedScannerContext.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ObjectMacroDescriptor.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Scanner.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContextInclusion.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContextMacro.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContextTop.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContextTopString.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerStringBuffer.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GCCScannerExtension.java rename core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/{scanner => scanner2}/IScannerData.java (51%) rename core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/{scanner => scanner2}/ScannerProblemFactory.java (98%) rename core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/{scanner => scanner2}/ScannerUtility.java (88%) delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/SimpleExpansionToken.java diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java deleted file mode 100644 index 771ea51f723..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java +++ /dev/null @@ -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); - } - } - - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BranchTrackerTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BranchTrackerTest.java deleted file mode 100644 index 2a1881ab5ba..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BranchTrackerTest.java +++ /dev/null @@ -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$ - } - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CharArrayUtilsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CharArrayUtilsTest.java index c617d3375f3..b1420b1754a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CharArrayUtilsTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CharArrayUtilsTest.java @@ -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 diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java index 7d6741bd3c3..256057f31bc 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java @@ -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; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PreprocessorConditionalTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PreprocessorConditionalTest.java index b598550c78f..37e211cd8c0 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PreprocessorConditionalTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PreprocessorConditionalTest.java @@ -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 diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerSpeedTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerSpeedTest.java index e0691bfb813..d9aafd7c0f6 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerSpeedTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerSpeedTest.java @@ -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) { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java deleted file mode 100644 index daf11736594..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java +++ /dev/null @@ -1,1751 +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.io.StringWriter; -import java.io.Writer; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.cdt.core.parser.IGCCToken; -import org.eclipse.cdt.core.parser.IMacroDescriptor; -import org.eclipse.cdt.core.parser.IProblem; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -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.scanner.Scanner; - -/** - * @author jcamelon - */ -public class ScannerTestCase extends BaseScannerTest -{ - public class TableRow - { - private int[] values; - private int length; - - public TableRow(int[] v) - { - length= v.length; - values= new int[length]; - System.arraycopy(v, 0, values, 0, length); - } - - public String toString() - { - StringBuffer s= new StringBuffer(); - for (int i= 0; i < length; ++i) - { - s.append("var").append(i).append("=").append(values[i]).append(" "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - return s.toString(); - } - - public String symbolName(int index) - { - return "DEFINITION" + index; //$NON-NLS-1$ - } - - public int symbolValue(int index) - { - return new Long(Math.round(Math.pow(index, index))).intValue(); - } - - public String generateCode() - { - if (length < 2) - { - return "Array must have at least 2 elements"; //$NON-NLS-1$ - } - int numberOfElsifs= length - 1; - StringBuffer buffer= new StringBuffer(); - buffer.append("#if ").append(values[0]).append("\n#\tdefine "); //$NON-NLS-1$ //$NON-NLS-2$ - buffer.append(symbolName(0)).append(" ").append(symbolValue(0)); //$NON-NLS-1$ - for (int i= 0; i < numberOfElsifs; ++i) - buffer - .append("\n#elif ") //$NON-NLS-1$ - .append(values[1 + i]) - .append("\n#\tdefine ") //$NON-NLS-1$ - .append(symbolName(i + 1)) - .append(" ") //$NON-NLS-1$ - .append(symbolValue(i + 1)); - buffer - .append("\n#else \n#\tdefine ") //$NON-NLS-1$ - .append(symbolName(length)) - .append(" ") //$NON-NLS-1$ - .append(symbolValue(length)) - .append("\n#endif"); //$NON-NLS-1$ - return buffer.toString(); - } - - public int selectWinner() - { - for (int i= 0; i < values.length; ++i) - { - if (values[i] != 0) - { - return i; - } - } - return length; - } - /** - * Returns the length. - * @return int - */ - public int getLength() - { - return length; - } - - } - - public class TruthTable - { - private int numberOfVariables; - private int numberOfRows; - public TableRow[] rows; - - public TruthTable(int n) - { - numberOfVariables= n; - numberOfRows= new Long(Math.round(Math.pow(2, n))).intValue(); - - rows= new TableRow[numberOfRows]; - for (int i= 0; i < numberOfRows; ++i) - { - String Z= Integer.toBinaryString(i); - - int[] input= new int[numberOfVariables]; - for (int j= 0; j < numberOfVariables; ++j) - { - int padding= numberOfVariables - Z.length(); - int k= 0; - for (; k < padding; ++k) - { - input[k]= 0; - } - for (int l= 0; l < Z.length(); ++l) - { - char c= Z.charAt(l); - int value= Character.digit(c, 10); - input[k++]= value; - } - } - rows[i]= new TableRow(input); - } - } - /** - * Returns the numberOfRows. - * @return int - */ - public int getNumberOfRows() - { - return numberOfRows; - } - - } - - public final static int SIZEOF_TRUTHTABLE = 10; - - - 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$ - validateFloatingPointLiteral( ".5"); //$NON-NLS-1$ - validateFloatingPointLiteral( "3."); //$NON-NLS-1$ - validateFloatingPointLiteral( "4E5"); //$NON-NLS-1$ - validateFloatingPointLiteral( "2.01E-03" ); //$NON-NLS-1$ - validateToken( IToken.tELLIPSIS ); - validateEOF(); - } - catch( ScannerException se ) - { - fail(EXCEPTION_THROWN + se.toString()); - } - - } - - - /** - * Constructor for ScannerTestCase. - * @param name - */ - public ScannerTestCase(String name) - { - super(name); - } - - public void testPreprocessorDefines()throws Exception - { - try - { - initializeScanner("#define SIMPLE_NUMERIC 5\nint x = SIMPLE_NUMERIC"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateDefinition("SIMPLE_NUMERIC", "5"); //$NON-NLS-1$ //$NON-NLS-2$ - validateIdentifier("x"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("5"); //$NON-NLS-1$ - validateEOF(); - - initializeScanner("#define SIMPLE_STRING \"This is a simple string.\"\n\nconst char * myVariable = SIMPLE_STRING;"); //$NON-NLS-1$ - validateToken(IToken.t_const); - validateDefinition("SIMPLE_STRING", "\"This is a simple string.\""); //$NON-NLS-1$ //$NON-NLS-2$ - validateToken(IToken.t_char); - validateToken(IToken.tSTAR); - validateIdentifier("myVariable"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateString("This is a simple string."); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define FOOL 5 \n int tryAFOOL = FOOL + FOOL;"); //$NON-NLS-1$ - - validateToken(IToken.t_int); - validateIdentifier("tryAFOOL"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("5"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("5"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define FOOL 5 \n int FOOLer = FOOL;"); //$NON-NLS-1$ - - validateToken(IToken.t_int); - validateIdentifier("FOOLer"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("5"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - // the case we were failing against in ctype.h - // this is a definition, not a macro! - initializeScanner("#define _ALPHA (0x0100|_UPPER|_LOWER)"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("_ALPHA", "(0x0100|_UPPER|_LOWER)"); //$NON-NLS-1$ //$NON-NLS-2$ - - // test for comments after the macro - initializeScanner("#define NO_COMMENT// ignore me"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("NO_COMMENT", ""); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define NO_COMMENT/* ignore me*/"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("NO_COMMENT", ""); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define ANSWER 42 // i think"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("ANSWER", "42"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define ANSWER 42 /* i think */"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("ANSWER", "42"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define MULTILINE 3 /* comment \n that goes more than one line */"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("MULTILINE", "3"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define MULTICOMMENT X /* comment1 */ + Y /* comment 2 */"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("MULTICOMMENT", "X + Y"); //$NON-NLS-1$ //$NON-NLS-2$ - - for (int i= 0; i < 7; ++i) - { - switch (i) - { - case 0 : - initializeScanner("#define SIMPLE_STRING This is a simple string.\n"); //$NON-NLS-1$ - break; - case 1 : - initializeScanner("# define SIMPLE_NUMERIC 5\n"); //$NON-NLS-1$ - break; - case 2 : - initializeScanner("# define SIMPLE_NUMERIC 5\n"); //$NON-NLS-1$ - break; - case 3 : - initializeScanner("#define SIMPLE_STRING \"This is a simple string.\"\n"); //$NON-NLS-1$ - break; - case 4 : - initializeScanner("#define SIMPLE_STRING This is a simple string.\n"); //$NON-NLS-1$ - break; - case 5 : - initializeScanner("#define FLAKE\n\nFLAKE"); //$NON-NLS-1$ - break; - case 6 : - initializeScanner("#define SIMPLE_STRING This is a simple string.\\\n Continue please."); //$NON-NLS-1$ - break; - } - validateEOF(); - - switch (i) - { - case 0 : - validateDefinition( - "SIMPLE_STRING", //$NON-NLS-1$ - "This is a simple string."); //$NON-NLS-1$ - break; - case 1 : - validateDefinition("SIMPLE_NUMERIC", "5"); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case 2 : - validateDefinition("SIMPLE_NUMERIC", "5"); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case 3 : - validateDefinition( - "SIMPLE_STRING", //$NON-NLS-1$ - "\"This is a simple string.\""); //$NON-NLS-1$ - break; - case 4 : - validateDefinition( - "SIMPLE_STRING", //$NON-NLS-1$ - "This is a simple string."); //$NON-NLS-1$ - break; - case 5 : - validateDefinition("FLAKE", ""); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case 6 : - validateDefinition( - "SIMPLE_STRING", //$NON-NLS-1$ - "This is a simple string. Continue please."); //$NON-NLS-1$ - } - } - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - - public void testConcatenation() - { - try - { - initializeScanner("#define F1 3\n#define F2 F1##F1\nint x=F2;"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateDefinition("F1", "3"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition( "F2", "F1##F1"); //$NON-NLS-1$ //$NON-NLS-2$ - validateIdentifier("x"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("33"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define PREFIX RT_\n#define RUN PREFIX##Run"); //$NON-NLS-1$ - validateEOF(); - validateDefinition( "PREFIX", "RT_" ); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition( "RUN", "PREFIX##Run" ); //$NON-NLS-1$ //$NON-NLS-2$ - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - try - { - initializeScanner( "#define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name\n DECLARE_HANDLE( joe )" ); //$NON-NLS-1$ - validateToken( IToken.t_struct ); - validateIdentifier( "joe__"); //$NON-NLS-1$ - validateToken( IToken.tLBRACE); - validateToken( IToken.t_int ); - validateIdentifier( "unused"); //$NON-NLS-1$ - validateToken( IToken.tSEMI ); - validateToken( IToken.tRBRACE ); - validateToken( IToken.tSEMI ); - validateToken( IToken.t_typedef ); - validateToken( IToken.t_struct ); - validateIdentifier( "joe__" ); //$NON-NLS-1$ - validateToken( IToken.tSTAR ); - validateIdentifier( "joe"); //$NON-NLS-1$ - validateEOF(); - } - catch( Exception e ) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - public void testSimpleIfdef() - { - try - { - - initializeScanner("#define SYMBOL 5\n#ifdef SYMBOL\nint counter(SYMBOL);\n#endif"); //$NON-NLS-1$ - - validateToken(IToken.t_int); - validateIdentifier("counter"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateInteger("5"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define SYMBOL 5\n#ifndef SYMBOL\nint counter(SYMBOL);\n#endif"); //$NON-NLS-1$ - validateEOF(); - - initializeScanner("#ifndef DEFINED\n#define DEFINED 100\n#endif\nint count = DEFINED;"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateDefinition("DEFINED", "100"); //$NON-NLS-1$ //$NON-NLS-2$ - - validateIdentifier("count"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("100"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#ifndef DEFINED\n#define DEFINED 100\n#endif\nint count = DEFINED;"); //$NON-NLS-1$ - scanner.addDefinition("DEFINED", "101"); //$NON-NLS-1$ //$NON-NLS-2$ - - validateDefinition("DEFINED", "101"); //$NON-NLS-1$ //$NON-NLS-2$ - validateToken(IToken.t_int); - validateIdentifier("count"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("101"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner( "/* NB: This is #if 0'd out */"); //$NON-NLS-1$ - validateEOF(); - - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - public void testMultipleLines() throws Exception - { - Writer code = new StringWriter(); - code.write( "#define COMPLEX_MACRO 33 \\\n"); //$NON-NLS-1$ - code.write( " + 44\n\nCOMPLEX_MACRO"); //$NON-NLS-1$ - initializeScanner( code.toString() ); - validateInteger( "33" ); //$NON-NLS-1$ - validateToken( IToken.tPLUS ); - validateInteger( "44" ); //$NON-NLS-1$ - } - - public void testSlightlyComplexIfdefStructure() - { - try - { - 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) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - try - { - 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$ - - validateToken(IToken.t_int); - validateDefinition("ONE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - validateAsUndefined("TWO"); //$NON-NLS-1$ - validateAsUndefined("THREE"); //$NON-NLS-1$ - validateIdentifier("three"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateIdentifier("THREE"); //$NON-NLS-1$ - 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); - validateDefinition("ONE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("TWO", "2"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("THREE", "ONE + TWO"); //$NON-NLS-1$ //$NON-NLS-2$ - - validateIdentifier("three"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateInteger("1"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("2"); //$NON-NLS-1$ - 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$ - - 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("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$ - - 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("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$ - - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - public void testIfs() - { - try - { - 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$ - - initializeScanner("#if T < 20\n#define Z T + 1\n#endif"); //$NON-NLS-1$ - scanner.addDefinition("X", "5"); //$NON-NLS-1$ //$NON-NLS-2$ - 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$ - validateDefinition("Z", "T + 1"); //$NON-NLS-1$ //$NON-NLS-2$ - - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - try - { - 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) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - try - { - initializeScanner("#ifndef FIVE \n#define FIVE 5\n#endif \n#ifndef TEN\n#define TEN 2 * FIVE\n#endif\n#if TEN != 10\n#define MISTAKE 1\n#error Five does not equal 10\n#endif\n"); //$NON-NLS-1$ - scanner.addDefinition("FIVE", "55"); //$NON-NLS-1$ //$NON-NLS-2$ - validateEOF(); - fail(EXPECTED_FAILURE); - } - catch (ScannerException se) - { - validateBalance(1); - validateDefinition("FIVE", "55"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("TEN", "2 * FIVE"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("MISTAKE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - try - { - initializeScanner("#if ((( FOUR / TWO ) * THREE )< FIVE )\n#error 6 is not less than 5 \n#endif\n#if ( ( FIVE * ONE ) != (( (FOUR) + ONE ) * ONE ) )\n#error 5 should equal 5\n#endif \n"); //$NON-NLS-1$ - - scanner.addDefinition("ONE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - scanner.addDefinition("TWO", "(ONE + ONE)"); //$NON-NLS-1$ //$NON-NLS-2$ - scanner.addDefinition("THREE", "(TWO + ONE)"); //$NON-NLS-1$ //$NON-NLS-2$ - scanner.addDefinition("FOUR", "(TWO * TWO)"); //$NON-NLS-1$ //$NON-NLS-2$ - 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$ - validateDefinition("FOUR", "(TWO * TWO)"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("FIVE", "(THREE + TWO)"); //$NON-NLS-1$ //$NON-NLS-2$ - - TruthTable table= new TruthTable(SIZEOF_TRUTHTABLE); - int numberOfRows= table.getNumberOfRows(); - TableRow[] rows= table.rows; - - for (int i= 0; i < numberOfRows; ++i) - { - TableRow row= rows[i]; - String code= row.generateCode(); - if (verbose) - System.out.println("\n\nRow " + i + " has code\n" + code); //$NON-NLS-1$ //$NON-NLS-2$ - initializeScanner(code); - validateEOF(); - validateBalance(); - validateAllDefinitions(row); - } - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - try - { - initializeScanner("#if ! 0\n#error Correct!\n#endif"); //$NON-NLS-1$ - scanner.nextToken(); - fail(EXPECTED_FAILURE); - } - catch (ScannerException se) - { - validateBalance(1); - assertEquals( se.getProblem().getID(), IProblem.PREPROCESSOR_POUND_ERROR); - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - public void testBug67834() throws Exception { - initializeScanner( - "#if ! BAR\n" + //$NON-NLS-1$ - "foo\n" + //$NON-NLS-1$ - "#else\n" + //$NON-NLS-1$ - "bar\n" + //$NON-NLS-1$ - "#endif\n" //$NON-NLS-1$ - ); //$NON-NLS-1$ - validateIdentifier("foo"); //$NON-NLS-1$ - validateEOF(); - validateBalance(); - - initializeScanner( - "#if ! (BAR)\n" + //$NON-NLS-1$ - "foo\n" + //$NON-NLS-1$ - "#else\n" + //$NON-NLS-1$ - "bar\n" + //$NON-NLS-1$ - "#endif\n" //$NON-NLS-1$ - ); //$NON-NLS-1$ - validateIdentifier("foo"); //$NON-NLS-1$ - validateEOF(); - validateBalance(); - } - public void testPreprocessorMacros() - { - try - { - initializeScanner("#define GO(x) x+1\nint y(5);\ny = GO(y);"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateIdentifier("y"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateInteger("5"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - - IMacroDescriptor descriptor= - scanner.getDefinition("GO"); //$NON-NLS-1$ - String [] parms= descriptor.getParameters(); - assertNotNull(parms); - assertTrue(parms.length == 1); - String parm1= parms[0]; - assertTrue(parm1.equals("x")); //$NON-NLS-1$ - IToken [] expansion= descriptor.getTokenizedExpansion(); - assertNotNull(parms); - assertTrue(expansion.length == 3); - assertTrue((expansion[0]).getType() == IToken.tIDENTIFIER); - assertTrue((expansion[0]).getImage().equals("x")); //$NON-NLS-1$ - assertTrue((expansion[1]).getType() == IToken.tPLUS); - assertTrue((expansion[2]).getType() == IToken.tINTEGER); - assertTrue((expansion[2]).getImage().equals("1")); //$NON-NLS-1$ - - validateIdentifier("y"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateIdentifier("y"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - 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$ - + "int daSum = SUM(ONE,3,5,7,9,11,13);"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateIdentifier("daSum"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateToken(IToken.tLPAREN); - validateInteger("1"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("3"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("5"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("7"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("9"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("11"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("13"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateEOF(); - - IMacroDescriptor macro= scanner.getDefinition("SUM"); //$NON-NLS-1$ - String [] params= macro.getParameters(); - assertNotNull(params); - assertTrue(params.length == 7); - - IToken [] tokens= macro.getTokenizedExpansion(); - assertNotNull(tokens); - assertTrue(tokens.length == 15); - - initializeScanner("#define LOG( format, var1) printf( format, var1 )\nLOG( \"My name is %s\", \"Bogdan\" );\n"); //$NON-NLS-1$ - validateIdentifier("printf"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateString("My name is %s"); //$NON-NLS-1$ - validateToken(IToken.tCOMMA); - validateString("Bogdan"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define INCR( x ) ++x\nint y(2);\nINCR(y);"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateIdentifier("y"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateInteger("2"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateToken(IToken.tINCR); - validateIdentifier("y"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define CHECK_AND_SET( x, y, z ) if( x ) { \\\n y = z; \\\n }\n\nCHECK_AND_SET( 1, balance, 5000 );\nCHECK_AND_SET( confused(), you, dumb );"); //$NON-NLS-1$ - validateToken(IToken.t_if); - validateToken(IToken.tLPAREN); - validateInteger("1"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tLBRACE); - validateIdentifier("balance"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("5000"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateToken(IToken.tRBRACE); - validateToken(IToken.tSEMI); - - validateToken(IToken.t_if); - validateToken(IToken.tLPAREN); - validateIdentifier("confused"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateToken(IToken.tRPAREN); - validateToken(IToken.tRPAREN); - validateToken(IToken.tLBRACE); - validateIdentifier("you"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateIdentifier("dumb"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateToken(IToken.tRBRACE); - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define ON 7\n#if defined(ON)\nint itsOn = ON;\n#endif"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateBalance(1); - validateIdentifier("itsOn"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("7"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - validateBalance(); - - initializeScanner("#if defined( NOTHING ) \nint x = NOTHING;\n#endif"); //$NON-NLS-1$ - validateEOF(); - validateBalance(); - - - - - - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - public void testQuickScan() throws ParserFactoryError - { - 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$ - validateToken( IToken.tASSIGN ); - validateInteger( "1"); //$NON-NLS-1$ - 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() ); - } - - } - - - public void testOtherPreprocessorCommands() throws ParserFactoryError - { - try - { - initializeScanner("#\n#\t\n#define MAX_SIZE 1024\n#\n# "); //$NON-NLS-1$ - validateEOF(); - validateDefinition("MAX_SIZE", "1024"); //$NON-NLS-1$ //$NON-NLS-2$ - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - for (int i= 0; i < 4; ++i) - { - switch (i) - { - case 0 : - initializeScanner("# ape"); //$NON-NLS-1$ - break; - case 1 : - initializeScanner("# #"); //$NON-NLS-1$ - break; - case 2 : - initializeScanner("# 32"); //$NON-NLS-1$ - break; - case 3 : - initializeScanner("# defines"); //$NON-NLS-1$ - break; - } - - try - { - validateEOF(); - fail(EXPECTED_FAILURE); - } - catch (ScannerException se) - { - validateBalance(); - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - } - - public void validateAllDefinitions(TableRow row) - { - int winner= row.selectWinner(); - int rowLength= row.getLength(); - for (int i= 0; i <= rowLength; ++i) - { - if (i == winner) - validateDefinition(row.symbolName(i), row.symbolValue(i)); - else - validateAsUndefined(row.symbolName(i)); - } - } - - public void testBug36287() throws Exception - { - initializeScanner( "X::X( const X & rtg_arg ) : U( rtg_arg ) , Z( rtg_arg.Z ) , er( rtg_arg.er ){}" ); //$NON-NLS-1$ - validateIdentifier("X"); //$NON-NLS-1$ - validateToken( IToken.tCOLONCOLON); - validateIdentifier("X"); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateToken( IToken.t_const ); - validateIdentifier("X"); //$NON-NLS-1$ - validateToken( IToken.tAMPER ); - validateIdentifier( "rtg_arg"); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tCOLON ); - validateIdentifier( "U"); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateIdentifier( "rtg_arg"); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tCOMMA ); - validateIdentifier( "Z"); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateIdentifier( "rtg_arg"); //$NON-NLS-1$ - validateToken( IToken.tDOT ); - validateIdentifier( "Z"); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tCOMMA ); - validateIdentifier( "er"); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateIdentifier( "rtg_arg"); //$NON-NLS-1$ - validateToken( IToken.tDOT ); - validateIdentifier( "er"); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tLBRACE); - validateToken( IToken.tRBRACE); - validateEOF(); - - initializeScanner( "foo.*bar"); //$NON-NLS-1$ - validateIdentifier("foo"); //$NON-NLS-1$ - validateToken( IToken.tDOTSTAR ); - validateIdentifier("bar"); //$NON-NLS-1$ - validateEOF(); - - initializeScanner( "foo...bar"); //$NON-NLS-1$ - validateIdentifier("foo"); //$NON-NLS-1$ - validateToken( IToken.tELLIPSIS ); - validateIdentifier("bar"); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug35892() throws ParserFactoryError - { - try - { - initializeScanner( "'c'" ); //$NON-NLS-1$ - validateChar( 'c' ); - validateEOF(); - } - catch( ScannerException se ) - { - fail( EXCEPTION_THROWN + se.getMessage() ); - } - } - - public void testBug36045() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( '"' ); - buffer.append( '\\'); - buffer.append( '"'); - buffer.append( '"'); - - buffer.append( '"'); - buffer.append( '\\'); - buffer.append( '\\'); - buffer.append( '"'); - buffer.append( "\n\n"); //$NON-NLS-1$ - initializeScanner( buffer.toString()); - validateString( "\\\"\\\\"); //$NON-NLS-1$ - } - - public void testConditionalWithBraces() throws ParserFactoryError - { - 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$ - switch( i ) - { - case 0: - scanner.addDefinition( "THIS", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - scanner.addDefinition( "THAT", "1" ); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case 1: - scanner.addDefinition( "THIS", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - scanner.addDefinition( "THAT", "0" ); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case 2: - scanner.addDefinition( "THAT", "1" ); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case 3: - scanner.addDefinition( "THAT", "0" ); //$NON-NLS-1$ //$NON-NLS-2$ - break; - } - - validateToken( IToken.t_int ); - validateIdentifier( "foobar"); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateToken( IToken.t_int ); - validateIdentifier( "a" ); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tLBRACE ); - validateToken( IToken.t_if ); - validateToken( IToken.tLPAREN ); - validateIdentifier( "a" ); //$NON-NLS-1$ - validateToken( IToken.tEQUAL ); - validateInteger( "0" ); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tLBRACE ); - - if( i <= 1 ) - { - validateToken( IToken.tRBRACE ); - validateToken( IToken.t_else ); - validateToken( IToken.tLBRACE ); - validateToken( IToken.tRBRACE ); - } - - if( i == 2 ) - { - validateToken( IToken.tRBRACE ); - validateToken( IToken.t_else ); - validateToken( IToken.tLBRACE ); - validateToken( IToken.tRBRACE ); - } - - validateToken( IToken.t_return ); - validateInteger( "0"); //$NON-NLS-1$ - validateToken( IToken.tSEMI ); - validateToken( IToken.tRBRACE ); - validateEOF(); - } - } catch( ScannerException se ) - { - fail(EXCEPTION_THROWN + se.toString()); - } - } - - public void testNestedRecursiveDefines() throws Exception - { - initializeScanner( "#define C B A\n#define B C C\n#define A B\nA" ); //$NON-NLS-1$ - - validateIdentifier("B"); //$NON-NLS-1$ - validateDefinition("A", "B"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("B", "C C"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("C", "B A"); //$NON-NLS-1$ //$NON-NLS-2$ - validateIdentifier("A"); //$NON-NLS-1$ - validateIdentifier("B"); //$NON-NLS-1$ - validateIdentifier("A"); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug36316() throws Exception - { - initializeScanner( "#define A B->A\nA" ); //$NON-NLS-1$ - - validateIdentifier("B"); //$NON-NLS-1$ - validateDefinition("A", "B->A"); //$NON-NLS-1$ //$NON-NLS-2$ - validateToken(IToken.tARROW); - validateIdentifier("A"); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug36434() throws Exception - { - initializeScanner( "#define X(Y)"); //$NON-NLS-1$ - validateEOF(); - IMacroDescriptor macro = scanner.getDefinition( "X" ); //$NON-NLS-1$ - assertNotNull( macro ); - assertEquals( macro.getParameters().length, 1 ); - assertEquals( macro.getParameters()[0], "Y" ); //$NON-NLS-1$ - assertEquals( macro.getTokenizedExpansion().length, 0 ); - } - - public void testBug36047() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "# define MAD_VERSION_STRINGIZE(str) #str\n" ); //$NON-NLS-1$ - writer.write( "# define MAD_VERSION_STRING(num) MAD_VERSION_STRINGIZE(num)\n" ); //$NON-NLS-1$ - writer.write( "# define MAD_VERSION MAD_VERSION_STRING(MAD_VERSION_MAJOR) \".\" \\\n" ); //$NON-NLS-1$ - writer.write( " MAD_VERSION_STRING(MAD_VERSION_MINOR) \".\" \\\n" ); //$NON-NLS-1$ - writer.write( " MAD_VERSION_STRING(MAD_VERSION_PATCH) \".\" \\\n" ); //$NON-NLS-1$ - writer.write( " MAD_VERSION_STRING(MAD_VERSION_EXTRA)\n" ); //$NON-NLS-1$ - writer.write( "# define MAD_VERSION_MAJOR 2\n" ); //$NON-NLS-1$ - writer.write( "# define MAD_VERSION_MINOR 1\n" ); //$NON-NLS-1$ - writer.write( "# define MAD_VERSION_PATCH 3\n" ); //$NON-NLS-1$ - writer.write( "# define MAD_VERSION_EXTRA boo\n" ); //$NON-NLS-1$ - writer.write( "MAD_VERSION\n" ); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - - validateString( "2.1.3.boo" ); //$NON-NLS-1$ - - validateEOF(); - } - - public void testBug36475() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( " \"A\" \"B\" \"C\" " ); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - - validateString( "ABC" ); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug36509() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write("#define debug(s, t) printf(\"x\" # s \"= %d, x\" # t \"= %s\", \\\n"); //$NON-NLS-1$ - writer.write(" x ## s, x ## t) \n"); //$NON-NLS-1$ - writer.write("debug(1, 2);"); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - //printf("x1=%d, x2= %s", x1, x2); - validateIdentifier( "printf" ); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateString("x1= %d, x2= %s"); //$NON-NLS-1$ - validateToken(IToken.tCOMMA); - validateIdentifier("x1"); //$NON-NLS-1$ - validateToken(IToken.tCOMMA); - validateIdentifier("x2"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateEOF(); - } - - public void testBug36695() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write("\'\\4\' \'\\n\'"); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - - validateChar( "\\4" ); //$NON-NLS-1$ - validateChar( "\\n" ); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug36521() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write("#define str(s) # s\n"); //$NON-NLS-1$ - writer.write("fputs(str(strncmp(\"abc\\0d\", \"abc\", \'\\4\')\n"); //$NON-NLS-1$ - writer.write(" == 0), s);\n"); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - validateIdentifier("fputs"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateString("strncmp(\\\"abc\\\\0d\\\", \\\"abc\\\", '\\\\4') == 0"); //$NON-NLS-1$ - validateToken(IToken.tCOMMA); - validateIdentifier("s"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - } - - public void testBug36770() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "#define A 0\n" ); //$NON-NLS-1$ - writer.write( "#if ( A == 1 )\n"); //$NON-NLS-1$ - writer.write( "# define foo 1\n"); //$NON-NLS-1$ - writer.write( "#else\n"); //$NON-NLS-1$ - writer.write( "# define foo 2\n"); //$NON-NLS-1$ - writer.write( "#endif\n"); //$NON-NLS-1$ - writer.write( "foo\n"); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - validateInteger( "2" ); //$NON-NLS-1$ - validateEOF(); - } - - 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 ); - } - - initializeScanner( "#include \n" ); //$NON-NLS-1$ - - Callback callback = new Callback( ParserMode.QUICK_PARSE ); - initializeScanner( buffer.toString(), ParserMode.QUICK_PARSE, callback ); - validateEOF(); - assertEquals( callback.problems.size(), 0 ); - assertEquals( callback.inclusions.size(), 1 ); - assertEquals( callback.inclusions.get(0), "stdio.h"); //$NON-NLS-1$ - } - - public void testBug46402() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "#define X 5\n" ); //$NON-NLS-1$ - buffer.append( "#if defined( X )\n" ); //$NON-NLS-1$ - buffer.append( "// blah\n" ); //$NON-NLS-1$ - buffer.append( "#elif Y > 5 \n" ); //$NON-NLS-1$ - buffer.append( "// coo\n" ); //$NON-NLS-1$ - buffer.append( "#endif\n" ); //$NON-NLS-1$ - initializeScanner( buffer.toString(), ParserMode.COMPLETE_PARSE ); - validateEOF(); - } - - public void testBug50821() throws Exception - { - Callback callback = new Callback( ParserMode.QUICK_PARSE ); - initializeScanner( "\'\n\n\n", ParserMode.QUICK_PARSE, callback ); //$NON-NLS-1$ - scanner.nextToken(); - assertEquals( callback.problems.size(), 1 ); - } - - - public void test54778() throws ScannerException - { - initializeScanner("#if 1 || 0 < 3 \n printf \n #endif\n"); //$NON-NLS-1$ - validateIdentifier("printf"); //$NON-NLS-1$ - validateEOF(); - initializeScanner("#if !defined FOO || FOO > 3\nprintf\n#endif\n"); //$NON-NLS-1$ - validateIdentifier("printf"); //$NON-NLS-1$ - validateEOF(); - initializeScanner("#if !defined FOO || FOO < 3\nprintf\n#endif\n"); //$NON-NLS-1$ - validateIdentifier("printf"); //$NON-NLS-1$ - validateEOF(); - - } - - public void testBug56517() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#if 0 \n"); //$NON-NLS-1$ - writer.write( "char * x = \"#boo\";\n" ); //$NON-NLS-1$ - writer.write( "#endif\n"); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - validateEOF(); - } - - public void testBug36770B() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#define A 0\n" ); //$NON-NLS-1$ - writer.write( "#if ( A == 1 )\n" ); //$NON-NLS-1$ - writer.write( "# define foo\n" ); //$NON-NLS-1$ - writer.write( "#else\n" ); //$NON-NLS-1$ - writer.write( "# define bar\n" ); //$NON-NLS-1$ - writer.write( "#endif\n" ); //$NON-NLS-1$ - initializeScanner( writer.toString(), ParserMode.QUICK_PARSE ); - validateEOF(); - validateDefinition( "A", 0 ); //$NON-NLS-1$ - validateDefinition( "bar", "" ); //$NON-NLS-1$ //$NON-NLS-2$ - - } - - public void testBug47797() throws Exception - { - initializeScanner( "\"\\uABCD\" \'\\uABCD\' \\uABCD_ident \\u001A01BC_ident ident\\U01AF ident\\u01bc00AF"); //$NON-NLS-1$ - validateString( "\\uABCD"); //$NON-NLS-1$ - validateChar( "\\uABCD"); //$NON-NLS-1$ - validateIdentifier( "\\uABCD_ident"); //$NON-NLS-1$ - validateIdentifier( "\\u001A01BC_ident"); //$NON-NLS-1$ - validateIdentifier( "ident\\U01AF" ); //$NON-NLS-1$ - validateIdentifier( "ident\\u01bc00AF" ); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug39698() throws Exception - { - initializeScanner( "?"); //$NON-NLS-1$ - validateToken( IGCCToken.tMIN ); - validateToken( IGCCToken.tMAX ); - validateEOF(); - } - - public void testBug59768() throws Exception - { - initializeScanner( "#define A A\nA"); //$NON-NLS-1$ - validateIdentifier( "A"); //$NON-NLS-1$ - validateEOF(); - IMacroDescriptor d = scanner.getDefinition( "A"); //$NON-NLS-1$ - assertTrue( d.isCircular() ); - } - - public void testBug60764() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#define P a,b\n"); //$NON-NLS-1$ - writer.write( "#define M(x) M1(x)\n"); //$NON-NLS-1$ - writer.write( "#define M1(x,y) #x #y\n"); //$NON-NLS-1$ - writer.write( "M(P)\n"); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - validateString( "ab"); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug62042() throws Exception - { - Callback callback = new Callback(ParserMode.QUICK_PARSE); - initializeScanner( "0x", ParserMode.QUICK_PARSE, callback ); //$NON-NLS-1$ - validateEOF(); - assertFalse( callback.problems.isEmpty() ); - } - - public void testBug61968() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "unsigned int ui = 2172748163; //ok \n" ); //$NON-NLS-1$ - writer.write( "int big = 999999999999999;//ok \n" ); //$NON-NLS-1$ - writer.write( "void main() { \n" ); //$NON-NLS-1$ - writer.write( "caller(4); //ok\n" ); //$NON-NLS-1$ - writer.write( "caller(2172748163);//causes java.lang.NumberFormatException \n" ); //$NON-NLS-1$ - writer.write( "caller(999999999999999); //also causes NumberFormatException \n" ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - Callback callback = new Callback(ParserMode.QUICK_PARSE); - initializeScanner( writer.toString(), ParserMode.QUICK_PARSE, callback ); - fullyTokenize(); - assertTrue( callback.problems.isEmpty() ); - } - - public void testBug62378() throws Exception - { - initializeScanner( "\"\\?\\?<\""); //$NON-NLS-1$ - validateString("\\?\\?<" ); //$NON-NLS-1$ - } - - public void testBug62384() throws Exception - { - initializeScanner( "18446744073709551615LL"); //$NON-NLS-1$ - validateInteger( "18446744073709551615"); //$NON-NLS-1$ - } - - public void testBug62390() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#define f(x) x\n"); //$NON-NLS-1$ - writer.write( "#if f(\n"); //$NON-NLS-1$ - writer.write( "5) == 5\n"); //$NON-NLS-1$ - writer.write( "true1\n"); //$NON-NLS-1$ - writer.write( "#endif\n"); //$NON-NLS-1$ - writer.write( "#if A\n"); //$NON-NLS-1$ - writer.write( "#elif f(\n"); //$NON-NLS-1$ - writer.write( "5) == 5\n"); //$NON-NLS-1$ - writer.write( "true2\n"); //$NON-NLS-1$ - writer.write( "#endif\n"); //$NON-NLS-1$ - writer.write( "#undef f\n"); //$NON-NLS-1$ - writer.write( "#define f(x) \"A0I70_001.h\"\n"); //$NON-NLS-1$ - writer.write( "#include f(\n"); //$NON-NLS-1$ - writer.write( "5\n"); //$NON-NLS-1$ - writer.write( ")\n"); //$NON-NLS-1$ - writer.write( "#undef f\n"); //$NON-NLS-1$ - writer.write( "#define f(x) 1467\n"); //$NON-NLS-1$ - writer.write( "#line f(\n"); //$NON-NLS-1$ - writer.write( "5\n"); //$NON-NLS-1$ - writer.write( ")\n"); //$NON-NLS-1$ - writer.write( "#pragma f(\n"); //$NON-NLS-1$ - writer.write( "5\n"); //$NON-NLS-1$ - writer.write( ")\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - Callback callback = new Callback( ParserMode.QUICK_PARSE ); - initializeScanner( writer.toString(), ParserMode.QUICK_PARSE, callback ); - fullyTokenize(); - } - - public void testBug62009() throws Exception - { - Callback callback = new Callback( ParserMode.QUICK_PARSE ); - initializeScanner( "#define def(x) (x#)\ndef(orange)\n", ParserMode.QUICK_PARSE, callback ); //$NON-NLS-1$ - fullyTokenize(); - assertFalse( callback.problems.isEmpty() ); - } - - public void testBug61972() throws Exception - { - initializeScanner( "#define DEF1(A1) A1\n#define DEF2 DEF1(DEF2)\nDEF2;" ); //$NON-NLS-1$ - validateIdentifier( "DEF2"); //$NON-NLS-1$ - validateToken( IToken.tSEMI ); - validateEOF(); - } - - public void testBug64268() throws Exception - { - Writer writer = new StringWriter(); - writer.write("#define BODY \\\n"); //$NON-NLS-1$ - writer.write(" { \\\n"); //$NON-NLS-1$ - writer.write(" /* this multi-line comment messes \\\n"); //$NON-NLS-1$ - writer.write(" up the parser. */ }\n"); //$NON-NLS-1$ - writer.write("BODY "); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - validateToken( IToken.tLBRACE); - validateToken( IToken.tRBRACE); - validateEOF(); - } - - public void testEndif() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#ifdef __X__\n" ); //$NON-NLS-1$ - writer.write( " // comment\n" ); //$NON-NLS-1$ - writer.write( "#endif\n" ); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - validateEOF(); - assertEquals( ((Scanner)scanner).getBranchTracker().getDepth(), 0 ); - } - - public void test68229() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "#define COUNT 0 \n" ); //$NON-NLS-1$ - writer.write( "1 \n" ); //$NON-NLS-1$ - writer.write( "#if COUNT \n" ); //$NON-NLS-1$ - writer.write( " 2 \n" ); //$NON-NLS-1$ - writer.write( "#endif \n" ); //$NON-NLS-1$ - writer.write( "3 \n" ); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - - IToken t1 = scanner.nextToken(); - IToken t3 = scanner.nextToken(); - - assertEquals( t1.getImage(), "1" ); //$NON-NLS-1$ - assertEquals( t3.getImage(), "3" ); //$NON-NLS-1$ - assertEquals( t1.getNext(), t3 ); - validateEOF(); - - writer = new StringWriter(); - writer.write( "#define FOO( x ) x \n" ); //$NON-NLS-1$ - writer.write( "1 FOO( 2 ) 3 \n" ); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - t1 = scanner.nextToken(); - IToken t2 = scanner.nextToken(); - t3 = scanner.nextToken(); - validateEOF(); - - assertEquals( t1.getImage(), "1" ); //$NON-NLS-1$ - assertEquals( t2.getImage(), "2" ); //$NON-NLS-1$ - assertEquals( t3.getImage(), "3" ); //$NON-NLS-1$ - - assertEquals( t1.getNext(), t2 ); - } - -// public void testBug69134() throws Exception -// { -// Writer writer = new StringWriter(); -// writer.write( "# ifdef YYDEBUG\n" ); -// writer.write( " if (yyDebug) {\n" ); -// writer.write( " (void) fprintf (yyTrace,\n" ); -// writer.write( "\" # |Position|State|Mod|Lev|Action |Terminal and Lookahead or Rule\n\");\n" ); -// writer.write( "yyNl ();\n" ); -// writer.write( "}\n" ); -// writer.write( "# endif\n" ); -// Callback callback = new Callback( ParserMode.COMPLETE_PARSE ); -// initializeScanner(writer.toString(), ParserMode.COMPLETE_PARSE, callback ); -// fullyTokenize(); -// assertTrue( callback.problems.isEmpty() ); -// } -// -// public void testBug69161() throws Exception -// { -// Writer writer = new StringWriter(); -// writer.write( "#define MACRO(s) s\n" ); -// writer.write( "char *testQueries[] =\n"); -// writer.write( "{\n"); -// writer.write( "MACRO(\",\"), // if you change the comma to anything else there is no error\n"); -// writer.write( "MACRO(\"(\"),\n" ); -// writer.write( "MACRO(\")\")\n" ); -// writer.write( "};\n"); -// Callback callback = new Callback( ParserMode.COMPLETE_PARSE ); -// initializeScanner( writer.toString(), ParserMode.COMPLETE_PARSE, callback ); -// fullyTokenize(); -// assertTrue( callback.problems.isEmpty() ); -// } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/BaseScanner2Test.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/BaseScanner2Test.java index 3ca38a21b28..1b5a861b49a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/BaseScanner2Test.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/BaseScanner2Test.java @@ -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); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/ObjectMapTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/ObjectMapTest.java index b75a9ed473b..d5199921b66 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/ObjectMapTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/ObjectMapTest.java @@ -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 diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2SpeedTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2SpeedTest.java index 17fc4b20fbc..fa2eebbaab5 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2SpeedTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2SpeedTest.java @@ -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) { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java index f1bf8a75288..fa95a693380 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java @@ -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 ); - } - - initializeScanner( "#include 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(); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ContextException.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ContextException.java deleted file mode 100644 index 8265468748c..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ContextException.java +++ /dev/null @@ -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; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ContextStack.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ContextStack.java deleted file mode 100644 index 9428bf3ea76..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ContextStack.java +++ /dev/null @@ -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; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/DynamicMacroDescriptor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/DynamicMacroDescriptor.java deleted file mode 100644 index d2f30a4fba1..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/DynamicMacroDescriptor.java +++ /dev/null @@ -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; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/DynamicMacroEvaluator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/DynamicMacroEvaluator.java deleted file mode 100644 index 094c9596071..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/DynamicMacroEvaluator.java +++ /dev/null @@ -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(); - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/FunctionMacroDescriptor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/FunctionMacroDescriptor.java deleted file mode 100644 index f912f93bff2..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/FunctionMacroDescriptor.java +++ /dev/null @@ -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; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/GCCScannerExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/GCCScannerExtension.java deleted file mode 100644 index c575645f2e4..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/GCCScannerExtension.java +++ /dev/null @@ -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$ - private final List workingCopies; - protected final ContextStack contextStack; - private IASTFactory astFactory = null; - private ISourceElementRequestor requestor; - private ParserMode parserMode; - private final CodeReader reader; - private final ParserLanguage language; - protected IParserLogService log; - private final IProblemFactory problemFactory = new ScannerProblemFactory(); - private Map definitions = new Hashtable(); - private BranchTracker branches = new BranchTracker(); - private final IScannerInfo originalConfig; - private List includePathNames = new ArrayList(); - - private final Map privateDefinitions = new Hashtable(); - - private boolean initialContextInitialized = false; - - protected IToken finalToken; - private final IScannerExtension scannerExtension; - private static final int NO_OFFSET_LIMIT = -1; - private int offsetLimit = NO_OFFSET_LIMIT; - private boolean limitReached = false; - private IScannerContext currentContext; - - private final Map fileCache = new HashMap(100); - - public void setScannerContext(IScannerContext context) { - currentContext = context; - } - - protected void handleProblem( int problemID, String argument, int beginningOffset, boolean warning, boolean error ) throws ScannerException - { - handleProblem( problemID, argument, beginningOffset, warning, error, true ); - } - - protected void handleProblem( int problemID, String argument, int beginningOffset, boolean warning, boolean error, boolean extra ) throws ScannerException - { - IProblem problem = problemFactory.createProblem( - problemID, - beginningOffset, - getCurrentOffset(), - contextStack.getCurrentLineNumber(), - getCurrentFile().toCharArray(), - argument != null ? argument.toCharArray() : EMPTY_STRING_CHAR_ARRAY, - warning, - error ); - - // trace log - TraceUtil.outputTrace(log, "Scanner problem encountered: ", problem ); //$NON-NLS-1$ - - if( (! requestor.acceptProblem( problem )) && extra ) - throw new ScannerException( problem ); - } - - Scanner( CodeReader reader, Map definitions, List includePaths, ISourceElementRequestor requestor, ParserMode mode, ParserLanguage language, IParserLogService log, IScannerExtension extension ) - { - String [] incs = (String [])includePaths.toArray(STRING_ARRAY); - this.log = log; - this.requestor = requestor; - this.parserMode = mode; - this.reader = reader; - this.language = language; - this.originalConfig = new ScannerInfo( definitions, incs ); - this.contextStack = new ContextStack( this, log ); - this.workingCopies = null; - this.scannerExtension = extension; - this.definitions = definitions; - this.includePathNames = includePaths; - - if (reader.isFile()) - fileCache.put(reader.filename, reader); - - setupBuiltInMacros(); - } - - public Scanner(CodeReader reader, IScannerInfo info, ISourceElementRequestor requestor, ParserMode parserMode, ParserLanguage language, IParserLogService log, IScannerExtension extension, List workingCopies ) { - - this.log = log; - this.requestor = requestor; - this.parserMode = parserMode; - this.reader = reader; - this.language = language; - this.originalConfig = info; - this.contextStack = new ContextStack( this, log ); - this.workingCopies = workingCopies; - this.scannerExtension = extension; - this.astFactory = ParserFactory.createASTFactory( parserMode, language ); - - if (reader.isFile()) - fileCache.put(reader.filename, reader); - - TraceUtil.outputTrace(log, "Scanner constructed with the following configuration:"); //$NON-NLS-1$ - TraceUtil.outputTrace(log, "\tPreprocessor definitions from IScannerInfo: "); //$NON-NLS-1$ - - if( info.getDefinedSymbols() != null ) - { - Iterator i = info.getDefinedSymbols().keySet().iterator(); - Map m = info.getDefinedSymbols(); - int numberOfSymbolsLogged = 0; - while( i.hasNext() ) - { - String symbolName = (String) i.next(); - Object value = m.get( symbolName ); - if( value instanceof String ) - { - //TODO add in check here for '(' and ')' - addDefinition( symbolName, scannerExtension.initializeMacroValue(this, (String) value)); - TraceUtil.outputTrace(log, "\t\tNAME = ", symbolName, " VALUE = ", value.toString() ); //$NON-NLS-1$ //$NON-NLS-2$ - ++numberOfSymbolsLogged; - - } - else if( value instanceof IMacroDescriptor ) - addDefinition( symbolName, (IMacroDescriptor)value); - } - if( numberOfSymbolsLogged == 0 ) - TraceUtil.outputTrace(log, "\t\tNo definitions specified."); //$NON-NLS-1$ - - } - else - TraceUtil.outputTrace(log, "\t\tNo definitions specified."); //$NON-NLS-1$ - - - TraceUtil.outputTrace( log, "\tInclude paths from IScannerInfo: "); //$NON-NLS-1$ - if( info.getIncludePaths() != null ) - { - overwriteIncludePath( info.getIncludePaths() ); - for( int i = 0; i < info.getIncludePaths().length; ++i ) - TraceUtil.outputTrace( log, "\t\tPATH: ", info.getIncludePaths()[i], null, null); //$NON-NLS-1$ - } - else - TraceUtil.outputTrace(log, "\t\tNo include paths specified."); //$NON-NLS-1$ - - setupBuiltInMacros(); - } - - public final ParserLanguage getLanguage() { - return language; - } - - public final Map getPrivateDefinitions() { - return privateDefinitions; - } - - public final ContextStack getContextStack() { - return contextStack; - } - - public final IParserLogService getLogService() { - return log; - } - - public final List getIncludePathNames() { - return includePathNames; - } - - public final Map getPublicDefinitions() { - return definitions; - } - - public final ParserMode getParserMode() { - return parserMode; - } - - public final ISourceElementRequestor getClientRequestor() { - return requestor; - } - - public final Iterator getWorkingCopies() { - return workingCopies != null ? workingCopies.iterator() : EmptyIterator.EMPTY_ITERATOR; - } - /** - * - */ - protected void setupBuiltInMacros() { - - scannerExtension.setupBuiltInMacros(this); - if( getDefinition(__STDC__) == null ) - addDefinition( __STDC__, STDC_MACRO ); - - if( language == ParserLanguage.C ) - { - if( getDefinition(__STDC_HOSTED__) == null ) - addDefinition( __STDC_HOSTED__, STDC_HOSTED_MACRO); - if( getDefinition( __STDC_VERSION__) == null ) - addDefinition( __STDC_VERSION__, STDC_VERSION_MACRO); - } - else - if( getDefinition( __CPLUSPLUS ) == null ) - addDefinition( __CPLUSPLUS, CPLUSPLUS_MACRO); //$NON-NLS-1$ - - if( getDefinition(__FILE__) == null ) - addDefinition( __FILE__, - new DynamicMacroDescriptor( __FILE__, new DynamicMacroEvaluator() { - public String execute() { - String fName = contextStack.getMostRelevantFileContext().getContextName(); - StringBuffer buff = new StringBuffer(fName.length() + 2); - buff.append('"'); - buff.append(fName); - buff.append('"'); - return buff.toString(); - } - } ) ); - - if( getDefinition( __LINE__) == null ) - addDefinition( __LINE__, - new DynamicMacroDescriptor( __LINE__, new DynamicMacroEvaluator() { - public String execute() { - return new Integer( contextStack.getCurrentLineNumber() ).toString(); - } - } ) ); - - - if( getDefinition( __DATE__ ) == null ) - addDefinition( __DATE__, - new DynamicMacroDescriptor( __DATE__, new DynamicMacroEvaluator() { - - public String getMonth() - { - if( Calendar.MONTH == Calendar.JANUARY ) return "Jan" ; //$NON-NLS-1$ - if( Calendar.MONTH == Calendar.FEBRUARY) return "Feb"; //$NON-NLS-1$ - if( Calendar.MONTH == Calendar.MARCH) return "Mar"; //$NON-NLS-1$ - if( Calendar.MONTH == Calendar.APRIL) return "Apr"; //$NON-NLS-1$ - if( Calendar.MONTH == Calendar.MAY) return "May"; //$NON-NLS-1$ - if( Calendar.MONTH == Calendar.JUNE) return "Jun"; //$NON-NLS-1$ - if( Calendar.MONTH == Calendar.JULY) return "Jul"; //$NON-NLS-1$ - if( Calendar.MONTH == Calendar.AUGUST) return "Aug"; //$NON-NLS-1$ - if( Calendar.MONTH == Calendar.SEPTEMBER) return "Sep"; //$NON-NLS-1$ - if( Calendar.MONTH == Calendar.OCTOBER) return "Oct"; //$NON-NLS-1$ - if( Calendar.MONTH == Calendar.NOVEMBER) return "Nov"; //$NON-NLS-1$ - if( Calendar.MONTH == Calendar.DECEMBER) return "Dec"; //$NON-NLS-1$ - return ""; //$NON-NLS-1$ - } - - public String execute() { - StringBuffer result = new StringBuffer(); - result.append( getMonth() ); - result.append(" "); //$NON-NLS-1$ - if( Calendar.DAY_OF_MONTH < 10 ) - result.append(" "); //$NON-NLS-1$ - result.append(Calendar.DAY_OF_MONTH); - result.append(" "); //$NON-NLS-1$ - result.append( Calendar.YEAR ); - return result.toString(); - } - } ) ); - - if( getDefinition( __TIME__) == null ) - addDefinition( __TIME__, - new DynamicMacroDescriptor( __TIME__, new DynamicMacroEvaluator() { - - - public String execute() { - StringBuffer result = new StringBuffer(); - if( Calendar.AM_PM == Calendar.PM ) - result.append( Calendar.HOUR + 12 ); - else - { - if( Calendar.HOUR < 10 ) - result.append( '0'); - result.append(Calendar.HOUR); - } - result.append(':'); - if( Calendar.MINUTE < 10 ) - result.append( '0'); - result.append(Calendar.MINUTE); - result.append(':'); - if( Calendar.SECOND < 10 ) - result.append( '0'); - result.append(Calendar.SECOND); - return result.toString(); - } - } ) ); - - - } - - private void setupInitialContext() - { - IScannerContext context = null; - try - { - if( offsetLimit == NO_OFFSET_LIMIT ) - context = new ScannerContextTop(reader); - else - context = new LimitedScannerContext( this, reader, offsetLimit, 0 ); - contextStack.pushInitialContext( context ); - } catch( ContextException ce ) - { - handleInternalError(); - } - initialContextInitialized = true; - } - - public void addIncludePath(String includePath) { - includePathNames.add(includePath); - } - - public void overwriteIncludePath(String [] newIncludePaths) { - if( newIncludePaths == null ) return; - includePathNames = new ArrayList(newIncludePaths.length); - - for( int i = 0; i < newIncludePaths.length; ++i ) - { - String path = newIncludePaths[i]; - - File file = new File( path ); - - if( !file.exists() && path.indexOf('\"') != -1 ) - { - StringTokenizer tokenizer = new StringTokenizer(path, "\"" ); //$NON-NLS-1$ - strbuff.startString(); - while( tokenizer.hasMoreTokens() ){ - strbuff.append( tokenizer.nextToken() ); - } - file = new File( strbuff.toString() ); - } - - if( file.exists() && file.isDirectory() ) - includePathNames.add( path ); - - } - } - - public void addDefinition(String key, IMacroDescriptor macro) { - definitions.put(key, macro); - } - - public void addDefinition(String key, String value) { - addDefinition(key, new ObjectMacroDescriptor( key, value )); - } - - public final IMacroDescriptor getDefinition(String key) { - IMacroDescriptor descriptor = (IMacroDescriptor) definitions.get(key); - if( descriptor != null ) - return descriptor; - return (IMacroDescriptor) privateDefinitions.get(key); - } - - public final String[] getIncludePaths() { - return (String[])includePathNames.toArray(); - } - - protected boolean skipOverWhitespace() throws ScannerException { - int c = getChar(false); - boolean result = false; - while ((c != NOCHAR) && ((c == ' ') || (c == '\t'))) - { - c = getChar(false); - result = true; - } - if (c != NOCHAR) - ungetChar(c); - return result; - - } - - protected String getRestOfPreprocessorLine() throws ScannerException, EndOfFileException { - - skipOverWhitespace(); - int c = getChar(false); - if (c == '\n') - return ""; //$NON-NLS-1$ - strbuff.startString(); - boolean inString = false; - boolean inChar = false; - while (true) { - while ((c != '\n') - && (c != '\r') - && (c != '\\') - && (c != '/') - && (c != '"' || ( c == '"' && inChar ) ) - && (c != '\'' || ( c == '\'' && inString ) ) - && (c != NOCHAR)) { - strbuff.append(c); - c = getChar( true ); - } - - if (c == '/') { - //only care about comments outside of a quote - if( inString || inChar ){ - strbuff.append( c ); - c = getChar( true ); - continue; - } - - // we need to peek ahead at the next character to see if - // this is a comment or not - int next = getChar(false); - if (next == '/') { - // single line comment - skipOverSinglelineComment(); - break; - } else if (next == '*') { - // multiline comment - skipOverMultilineComment(); - c = getChar( true ); - continue; - } else { - // we are not in a comment - strbuff.append(c); - c = next; - continue; - } - } else if( c == '"' ){ - inString = !inString; - strbuff.append(c); - c = getChar( true ); - continue; - } else if( c == '\'' ){ - inChar = !inChar; - strbuff.append(c); - c = getChar( true ); - continue; - } else if( c == '\\' ){ - c = getChar(true); - if( c == '\r' ){ - c = getChar(true); - if( c == '\n' ){ - c = getChar(true); - } - } else if( c == '\n' ){ - c = getChar(true); - } else { - strbuff.append('\\'); - if( c == '"' || c == '\'' ){ - strbuff.append(c); - c = getChar( true ); - } - } - continue; - } else { - ungetChar(c); - break; - } - } - - return strbuff.toString(); - } - - protected void skipOverTextUntilNewline() throws ScannerException { - for (;;) { - switch (getChar(false)) { - case NOCHAR : - case '\n' : - return; - case '\\' : - getChar(false); - } - } - } - - private void setCurrentToken(IToken t) { - if (currentToken != null) - currentToken.setNext(t); - finalToken = t; - currentToken = t; - } - - protected void resetStorageBuffer() - { - if( storageBuffer != null ) - storageBuffer = null; - } - - protected IToken newToken(int t, String i) { - IToken token = TokenFactory.createUniquelyImagedToken(t, i, this ); - setCurrentToken(token); - return currentToken; - } - - protected IToken newConstantToken(int t) { - setCurrentToken( TokenFactory.createToken(t, this)); - return currentToken; - } - - protected String getNextIdentifier() throws ScannerException { - strbuff.startString(); - skipOverWhitespace(); - int c = getChar(false); - - if (((c >= 'a') && (c <= 'z')) - || ((c >= 'A') && (c <= 'Z')) | (c == '_')) { - strbuff.append(c); - - c = getChar(false); - while (((c >= 'a') && (c <= 'z')) - || ((c >= 'A') && (c <= 'Z')) - || ((c >= '0') && (c <= '9')) - || (c == '_')) { - strbuff.append(c); - c = getChar(false); - } - } - ungetChar(c); - - return strbuff.toString(); - } - - protected void handleInclusion(String fileName, boolean useIncludePaths, int beginOffset, int startLine, int nameOffset, int nameLine, int endOffset, int endLine ) throws ScannerException { - - CodeReader duple = null; - totalLoop: for( int i = 0; i < 2; ++i ) - { - if( useIncludePaths ) // search include paths for this file - { - // iterate through the include paths - Iterator iter = includePathNames.iterator(); - - while (iter.hasNext()) { - - String path = (String)iter.next(); - String finalPath = ScannerUtility.createReconciledPath(path, fileName); - duple = (CodeReader)fileCache.get(finalPath); - if (duple == null) { - duple = ScannerUtility.createReaderDuple( finalPath, requestor, getWorkingCopies() ); - if (duple != null && duple.isFile()) - fileCache.put(duple.filename, duple); - } - if( duple != null ) - break totalLoop; - } - - if (duple == null ) - handleProblem( IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND, fileName, beginOffset, false, true ); - - } - else // local inclusion - { - String finalPath = ScannerUtility.createReconciledPath(new File( currentContext.getContextName() ).getParentFile().getAbsolutePath(), fileName); - duple = (CodeReader)fileCache.get(finalPath); - if (duple == null) { - duple = ScannerUtility.createReaderDuple( finalPath, requestor, getWorkingCopies() ); - if (duple != null && duple.isFile()) - fileCache.put(duple.filename, duple); - } - if( duple != null ) - break totalLoop; - useIncludePaths = true; - continue totalLoop; - } - } - - if (duple!= null) { - IASTInclusion inclusion = null; - try - { - inclusion = - getASTFactory().createInclusion( - fileName.toCharArray(), - duple.filename, - !useIncludePaths, - beginOffset, - startLine, - nameOffset, - nameOffset + fileName.length(), nameLine, endOffset, endLine, getCurrentFilename()); - } - catch (Exception e) - { - /* do nothing */ - } - - try - { - contextStack.updateInclusionContext( - duple, - inclusion, - requestor); - } - catch (ContextException e1) - { - handleProblem( e1.getId(), fileName, beginOffset, false, true ); - } - } - } - -/* protected void handleInclusion(String fileName, boolean useIncludePaths, int beginOffset, int startLine, int nameOffset, int nameLine, int endOffset, int endLine ) throws ScannerException { -// if useIncludePaths is true then -// #include -// else -// #include "foo.h" - - Reader inclusionReader = null; - File includeFile = null; - - if( !useIncludePaths ) { // local inclusion is checked first - String currentFilename = currentContext.getFilename(); - File currentIncludeFile = new File( currentFilename ); - String parentDirectory = currentIncludeFile.getParentFile().getAbsolutePath(); - currentIncludeFile = null; - - //TODO remove ".." and "." segments - includeFile = new File( parentDirectory, fileName ); - if (includeFile.exists() && includeFile.isFile()) { - try { - inclusionReader = new BufferedReader(new FileReader(includeFile)); - } catch (FileNotFoundException fnf) { - inclusionReader = null; - } - } - } - - // search include paths for this file - // iterate through the include paths - Iterator iter = scannerData.getIncludePathNames().iterator(); - - while ((inclusionReader == null) && iter.hasNext()) { - String path = (String)iter.next(); - //TODO remove ".." and "." segments - includeFile = new File (path, fileName); - if (includeFile.exists() && includeFile.isFile()) { - try { - inclusionReader = new BufferedReader(new FileReader(includeFile)); - } catch (FileNotFoundException fnf) { - inclusionReader = null; - } - } - } - - if (inclusionReader == null ) - handleProblem( IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND, fileName, beginOffset, false, true ); - - else { - IASTInclusion inclusion = null; - try - { - inclusion = - scannerData.getASTFactory().createInclusion( - fileName, - includeFile.getPath(), - !useIncludePaths, - beginOffset, - startLine, - nameOffset, - nameOffset + fileName.length(), nameLine, endOffset, endLine); - } - catch (Exception e) - { - do nothing - } - - try - { - scannerData.getContextStack().updateContext(inclusionReader, includeFile.getPath(), ScannerContext.ContextKind.INCLUSION, inclusion, scannerData.getClientRequestor() ); - } - catch (ContextException e1) - { - handleProblem( e1.getId(), fileName, beginOffset, false, true ); - } - } - } -*/ - // constants - private static final int NOCHAR = -1; - - private static final String TEXT = ""; //$NON-NLS-1$ - private static final String EXPRESSION = ""; //$NON-NLS-1$ - private static final String PASTING = ""; //$NON-NLS-1$ - - private static final String DEFINED = "defined"; //$NON-NLS-1$ - - private static final String POUND_DEFINE = "#define "; //$NON-NLS-1$ - - private IScannerContext lastContext = null; - - private StringBuffer storageBuffer = null; - - private int count = 0; - private static HashMap cppKeywords = new HashMap(); - private static HashMap cKeywords = new HashMap(); - private static HashMap ppDirectives = new HashMap(); - - private IToken currentToken = null; - private IToken cachedToken = null; - - private boolean passOnToClient = true; - - - // these are scanner configuration aspects that we perhaps want to tweak - // eventually, these should be configurable by the client, but for now - // we can just leave it internal -// private boolean enableDigraphReplacement = true; -// private boolean enableTrigraphReplacement = true; -// private boolean enableTrigraphReplacementInStrings = true; - private boolean throwExceptionOnBadCharacterRead = false; - - private boolean tokenizingMacroReplacementList = false; - protected static final String EMPTY_STRING = ""; //$NON-NLS-1$ - protected static final char[] EMPTY_STRING_CHAR_ARRAY = "".toCharArray(); //$NON-NLS-1$ - private Map tempMap = new HashMap(); //$NON-NLS-1$ - public void setTokenizingMacroReplacementList( boolean mr ){ - tokenizingMacroReplacementList = mr; - } - - public final int getCharacter() throws ScannerException - { - if( ! initialContextInitialized ) - setupInitialContext(); - - return getChar(false); - } - - final int getChar() throws ScannerException { - return getChar(false); - } - - private final int getChar( boolean insideString ) throws ScannerException { - - lastContext = currentContext; - - if (lastContext.getKind() == IScannerContext.ContextKind.SENTINEL) - // past the end of file - return NOCHAR; - - int c = currentContext.getChar(); - if (c != NOCHAR) - return c; - - if (currentContext.isFinal()) - return c; - - while (contextStack.rollbackContext(requestor)) { - c = currentContext.getChar(); - if (c != NOCHAR) - return c; - if (currentContext.isFinal()) - return c; - } - - return NOCHAR; - - /* - if (enableTrigraphReplacement && (!insideString || enableTrigraphReplacementInStrings)) { - // Trigraph processing - enableTrigraphReplacement = false; - if (c == '?') { - c = getChar(insideString); - if (c == '?') { - c = getChar(insideString); - switch (c) { - case '(': - expandDefinition("??(", "[", lastContext.getOffset() - 1); //$NON-NLS-1$ //$NON-NLS-2$ - c = getChar(insideString); - break; - case ')': - expandDefinition("??)", "]", lastContext.getOffset() - 1); //$NON-NLS-1$ //$NON-NLS-2$ - c = getChar(insideString); - break; - case '<': - expandDefinition("??<", "{", lastContext.getOffset() - 1); //$NON-NLS-1$ //$NON-NLS-2$ - c = getChar(insideString); - break; - case '>': - expandDefinition("??>", "}", lastContext.getOffset() - 1); //$NON-NLS-1$ //$NON-NLS-2$ - c = getChar(insideString); - break; - case '=': - expandDefinition("??=", "#", lastContext.getOffset() - 1); //$NON-NLS-1$ //$NON-NLS-2$ - c = getChar(insideString); - break; - case '/': - expandDefinition("??/", "\\", lastContext.getOffset() - 1); //$NON-NLS-1$ //$NON-NLS-2$ - c = getChar(insideString); - break; - case '\'': - expandDefinition("??\'", "^", lastContext.getOffset() - 1); //$NON-NLS-1$ //$NON-NLS-2$ - c = getChar(insideString); - break; - case '!': - expandDefinition("??!", "|", lastContext.getOffset() - 1); //$NON-NLS-1$ //$NON-NLS-2$ - c = getChar(insideString); - break; - case '-': - expandDefinition("??-", "~", lastContext.getOffset() - 1); //$NON-NLS-1$ //$NON-NLS-2$ - c = getChar(insideString); - break; - default: - // Not a trigraph - ungetChar(c); - ungetChar('?'); - c = '?'; - } - } else { - // Not a trigraph - ungetChar(c); - c = '?'; - } - } - enableTrigraphReplacement = true; - } - - if (!insideString) - { - if (enableDigraphReplacement) { - enableDigraphReplacement = false; - // Digraph processing - if (c == '<') { - c = getChar(false); - if (c == '%') { - expandDefinition("<%", "{", lastContext.getOffset() - 1); //$NON-NLS-1$ //$NON-NLS-2$ - c = getChar(false); - } else if (c == ':') { - expandDefinition("<:", "[", lastContext.getOffset() - 1); //$NON-NLS-1$ //$NON-NLS-2$ - c = getChar(false); - } else { - // Not a digraph - ungetChar(c); - c = '<'; - } - } else if (c == ':') { - c = getChar(false); - if (c == '>') { - expandDefinition(":>", "]", lastContext.getOffset() - 1); //$NON-NLS-1$ //$NON-NLS-2$ - c = getChar(false); - } else { - // Not a digraph - ungetChar(c); - c = ':'; - } - } else if (c == '%') { - c = getChar(false); - if (c == '>') { - expandDefinition("%>", "}", lastContext.getOffset() - 1); //$NON-NLS-1$ //$NON-NLS-2$ - c = getChar(false); - } else if (c == ':') { - expandDefinition("%:", "#", lastContext.getOffset() - 1); //$NON-NLS-1$ //$NON-NLS-2$ - c = getChar(false); - } else { - // Not a digraph - ungetChar(c); - c = '%'; - } - } - enableDigraphReplacement = true; - } - } - return c;*/ - } - - final void ungetChar(int c) { - currentContext.ungetChar(c); - if( lastContext != currentContext) - contextStack.undoRollback( lastContext, requestor ); - } - - protected boolean lookAheadForTokenPasting() throws ScannerException - { - int c = getChar(false); - if( c == '#' ) - { - c = getChar(false); - if( c == '#' ) - return true; - ungetChar( c ); - } - - ungetChar( c ); - return false; - - } - - protected void consumeUntilOutOfMacroExpansion() throws ScannerException - { - while( currentContext.getKind() == IScannerContext.ContextKind.MACROEXPANSION ) - getChar(false); - } - - public IToken nextToken() throws ScannerException, EndOfFileException { - return nextToken( true ); - } - - public boolean pasteIntoInputStream(String buff) throws ScannerException, EndOfFileException - { - // we have found ## in the input stream -- so save the results - if( lookAheadForTokenPasting() ) - { - if( storageBuffer == null ) - storageBuffer = new StringBuffer(buff); - else - storageBuffer.append( buff ); - return true; - } - - // a previous call has stored information, so we will add to it - if( storageBuffer != null ) - { - storageBuffer.append( buff.toString() ); - try - { - contextStack.updateMacroContext( - storageBuffer.toString(), - PASTING, - requestor, -1, -1 ); - } - catch (ContextException e) - { - handleProblem( e.getId(), currentContext.getContextName(), getCurrentOffset(), false, true ); - } - storageBuffer = null; - return true; - } - - // there is no need to save the results -- we will not concatenate - return false; - } - - public int consumeNewlineAfterSlash() throws ScannerException - { - int c; - c = getChar(false); - if (c == '\r') - { - c = getChar(false); - if (c == '\n') - { - // consume \ \r \n and then continue - return getChar(true); - } - // consume the \ \r and then continue - return c; - } - - if (c == '\n') - { - // consume \ \n and then continue - return getChar(true); - } - - // '\' is not the last character on the line - ungetChar(c); - return '\\'; - } - - public IToken processStringLiteral(boolean wideLiteral) throws ScannerException, EndOfFileException - { - int beginOffset = getCurrentOffset(); - strbuff.startString(); - int beforePrevious = NOCHAR; - int previous = '"'; - int c = getChar(true); - - for( ; ; ) { - if (c == '\\') - c = consumeNewlineAfterSlash(); - - - if ( ( c == '"' ) && ( previous != '\\' || beforePrevious == '\\') ) break; - if ( ( c == NOCHAR ) || (( c == '\n' ) && ( previous != '\\' || beforePrevious == '\\')) ) - { - // TODO : we could probably return the partial string -- it might cause - // the parse to get by... - handleProblem( IProblem.SCANNER_UNBOUNDED_STRING, null, beginOffset, false, true ); - return null; - } - - strbuff.append(c); - beforePrevious = previous; - previous = c; - c = getChar(true); - } - - int type = wideLiteral ? IToken.tLSTRING : IToken.tSTRING; - - //If the next token is going to be a string as well, we need to concatenate - //it with this token. This will be recursive for as many strings as need to be concatenated - - String result = strbuff.toString(); - IToken returnToken = newToken( type, result ); - - IToken next = null; - try{ - next = nextToken( true ); - if ( next != null && - (next.getType() == IToken.tSTRING || - next.getType() == IToken.tLSTRING )) { - returnToken.setImage(result + next.getImage()); - } - else - cachedToken = next; - } catch( EndOfFileException e ){ - next = null; - } - - currentToken = returnToken; - returnToken.setNext( null ); - return returnToken; - } - public IToken processNumber(int c, boolean pasting) throws ScannerException, EndOfFileException - { - // pasting happens when a macro appears in the middle of a number - // we will "store" the first part of the number in the "pasting" buffer - // until we have the full monty to evaluate - // for example - // #define F1 3 - // #define F2 F1##F1 - // int x = F2; - - int beginOffset = getCurrentOffset(); - strbuff.startString(); - - boolean hex = false; - boolean floatingPoint = ( c == '.' ) ? true : false; - boolean firstCharZero = ( c== '0' )? true : false; - - strbuff.append(c); - - int firstChar = c; - c = getChar(false); - - if( ! firstCharZero && floatingPoint && !(c >= '0' && c <= '9') ){ - //if pasting, there could actually be a float here instead of just a . - if( firstChar == '.' ) { - if( c == '*' ){ - return newConstantToken( IToken.tDOTSTAR ); - } else if( c == '.' ){ - if( getChar(false) == '.' ) - return newConstantToken( IToken.tELLIPSIS ); - handleProblem( IProblem.SCANNER_BAD_FLOATING_POINT, null, beginOffset, false, true ); - } else { - ungetChar( c ); - return newConstantToken( IToken.tDOT ); - } - } - } else if (c == 'x') { - if( ! firstCharZero ) - { - handleProblem( IProblem.SCANNER_BAD_HEX_FORMAT, null, beginOffset, false, true ); - return null; -// c = getChar(); -// continue; - } - strbuff.append(c); - hex = true; - c = getChar(false); - } - - while ((c >= '0' && c <= '9') - || (hex - && ((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')))) { - strbuff.append(c); - c = getChar(false); - } - - if( c == '.' ) - { - strbuff.append(c); - - floatingPoint = true; - c= getChar(false); - while ((c >= '0' && c <= '9') - || (hex - && ((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')))) - { - strbuff.append(c); - c = getChar(false); - } - } - - - if (c == 'e' || c == 'E' || (hex && (c == 'p' || c == 'P'))) - { - if( ! floatingPoint ) floatingPoint = true; - // exponent type for floating point - strbuff.append(c); - c = getChar(false); - - // optional + or - - if( c == '+' || c == '-' ) - { - strbuff.append(c ); - c = getChar(false); - } - - // digit sequence of exponent part - while ((c >= '0' && c <= '9') ) - { - strbuff.append(c); - c = getChar(false); - } - - // optional suffix - if( c == 'l' || c == 'L' || c == 'f' || c == 'F' ) - { - strbuff.append(c ); - c = getChar(false); - } - } else { - if( floatingPoint ){ - //floating-suffix - if( c == 'l' || c == 'L' || c == 'f' || c == 'F' ){ - c = getChar(false); - } - } else { - //integer suffix - if( c == 'u' || c == 'U' ){ - c = getChar(false); - if( c == 'l' || c == 'L') - c = getChar(false); - if( c == 'l' || c == 'L') - c = getChar(false); - } else if( c == 'l' || c == 'L' ){ - c = getChar(false); - if( c == 'l' || c == 'L') - c = getChar(false); - if( c == 'u' || c == 'U' ) - c = getChar(false); - } - } - } - - ungetChar( c ); - - String result = strbuff.toString(); - - if( pasting && pasteIntoInputStream(result)) - return null; - - if( floatingPoint && result.equals(".") ) //$NON-NLS-1$ - return newConstantToken( IToken.tDOT ); - - int tokenType = floatingPoint ? IToken.tFLOATINGPT : IToken.tINTEGER; - if( tokenType == IToken.tINTEGER && hex ) - { - if( result.equals( HEX_PREFIX ) ) - { - handleProblem( IProblem.SCANNER_BAD_HEX_FORMAT, HEX_PREFIX, beginOffset, false, true ); - return null; - } - } - - return newToken( - tokenType, - result); - } - public IToken processPreprocessor() throws ScannerException, EndOfFileException - { - int c; - int beginningOffset = currentContext.getOffset() - 1; - int beginningLine = contextStack.getCurrentLineNumber(); - - // we are allowed arbitrary whitespace after the '#' and before the rest of the text - boolean skipped = skipOverWhitespace(); - - c = getChar(false); - - if( c == '#' ) - { - if( skipped ) - handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, "# #", beginningOffset, false, true ); //$NON-NLS-1$ - else - return newConstantToken( tPOUNDPOUND ); //$NON-NLS-1$ - } else if( tokenizingMacroReplacementList ) { - ungetChar( c ); - return newConstantToken( tPOUND ); //$NON-NLS-1$ - } - - strbuff.startString(); - strbuff.append('#'); - while (((c >= 'a') && (c <= 'z')) - || ((c >= 'A') && (c <= 'Z')) || (c == '_') ) { - strbuff.append(c); - c = getChar(false); - } - - ungetChar(c); - - String token = strbuff.toString(); - - if( isLimitReached() ) - handleCompletionOnPreprocessorDirective(token); - - Object directive = ppDirectives.get(token); - if (directive == null) { - if( scannerExtension.canHandlePreprocessorDirective( token ) ) - scannerExtension.handlePreprocessorDirective( this, token, getRestOfPreprocessorLine() ); - else - { - if( passOnToClient ) - handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, token, beginningOffset, false, true ); - } - return null; - } - - int type = ((Integer) directive).intValue(); - switch (type) { - case PreprocessorDirectives.DEFINE : - if ( ! passOnToClient ) { - skipOverTextUntilNewline(); - if( isLimitReached() ) - handleInvalidCompletion(); - return null; - } - poundDefine(beginningOffset, beginningLine); - return null; - - case PreprocessorDirectives.INCLUDE : - if (! passOnToClient ) { - skipOverTextUntilNewline(); - if( isLimitReached() ) - handleInvalidCompletion(); - return null; - } - poundInclude( beginningOffset, beginningLine ); - return null; - - case PreprocessorDirectives.UNDEFINE : - if (! passOnToClient) { - - skipOverTextUntilNewline(); - if( isLimitReached() ) - handleInvalidCompletion(); - return null; - } - removeSymbol(getNextIdentifier()); - skipOverTextUntilNewline(); - return null; - - case PreprocessorDirectives.IF : - //TODO add in content assist stuff here - // get the rest of the line - int currentOffset = getCurrentOffset(); - String expression = getRestOfPreprocessorLine(); - - - if( isLimitReached() ) - handleCompletionOnExpression( expression ); - - if (expression.trim().equals("")) //$NON-NLS-1$ - handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, "#if", beginningOffset, false, true ); //$NON-NLS-1$ - - boolean expressionEvalResult = false; - - if( branches.queryCurrentBranchForIf() ) - expressionEvalResult = evaluateExpression(expression, currentOffset); - - passOnToClient = branches.poundIf( expressionEvalResult ); - return null; - - case PreprocessorDirectives.IFDEF : - //TODO add in content assist stuff here - - String definition = getNextIdentifier(); - if( isLimitReached() ) - handleCompletionOnDefinition( definition ); - - if (getDefinition(definition) == null) { - // not defined - passOnToClient = branches.poundIf( false ); - skipOverTextUntilNewline(); - } else - // continue along, act like nothing is wrong :-) - passOnToClient = branches.poundIf( true ); - return null; - - case PreprocessorDirectives.ENDIF : - String restOfLine = getRestOfPreprocessorLine().trim(); - if( isLimitReached() ) - handleInvalidCompletion(); - - if( ! restOfLine.equals( "" ) ) //$NON-NLS-1$ - { - strbuff.startString(); - strbuff.append("#endif "); //$NON-NLS-1$ - strbuff.append( restOfLine ); - handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, strbuff.toString(), beginningOffset, false, true ); - } - try{ - passOnToClient = branches.poundEndif(); - } - catch( EmptyStackException ese ) - { - handleProblem( IProblem.PREPROCESSOR_UNBALANCE_CONDITION, - token, - beginningOffset, - false, true ); - } - return null; - - case PreprocessorDirectives.IFNDEF : - //TODO add in content assist stuff here - - String definition2 = getNextIdentifier(); - if( isLimitReached() ) - handleCompletionOnDefinition( definition2 ); - - if (getDefinition(definition2) != null) { - // not defined - skipOverTextUntilNewline(); - passOnToClient = branches.poundIf( false ); - if( isLimitReached() ) - handleInvalidCompletion(); - - } else - // continue along, act like nothing is wrong :-) - passOnToClient = branches.poundIf( true ); - return null; - - case PreprocessorDirectives.ELSE : - try - { - passOnToClient = branches.poundElse(); - } - catch( EmptyStackException ese ) - { - handleProblem( IProblem.PREPROCESSOR_UNBALANCE_CONDITION, - token, - beginningOffset, - false, true ); - } - - skipOverTextUntilNewline(); - if( isLimitReached() ) - handleInvalidCompletion(); - return null; - - case PreprocessorDirectives.ELIF : - //TODO add in content assist stuff here - int co = getCurrentOffset(); - String elifExpression = getRestOfPreprocessorLine(); - if( isLimitReached() ) - handleCompletionOnExpression( elifExpression ); - - - if (elifExpression.equals("")) //$NON-NLS-1$ - handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, "#elif", beginningOffset, false, true ); //$NON-NLS-1$ - - boolean elsifResult = false; - if( branches.queryCurrentBranchForElif() ) - elsifResult = evaluateExpression(elifExpression, co ); - - try - { - passOnToClient = branches.poundElif( elsifResult ); - } - catch( EmptyStackException ese ) - { - strbuff.startString(); - strbuff.append( token ); - strbuff.append( ' ' ); - strbuff.append( elifExpression ); - handleProblem( IProblem.PREPROCESSOR_UNBALANCE_CONDITION, - strbuff.toString(), - beginningOffset, - false, true ); - } - return null; - - case PreprocessorDirectives.LINE : - skipOverTextUntilNewline(); - if( isLimitReached() ) - handleInvalidCompletion(); - return null; - - case PreprocessorDirectives.ERROR : - if (! passOnToClient) { - skipOverTextUntilNewline(); - if( isLimitReached() ) - handleInvalidCompletion(); - return null; - } - String restOfErrorLine = getRestOfPreprocessorLine(); - if( isLimitReached() ) - handleInvalidCompletion(); - - handleProblem( IProblem.PREPROCESSOR_POUND_ERROR, restOfErrorLine, beginningOffset, false, true ); - return null; - - case PreprocessorDirectives.PRAGMA : - skipOverTextUntilNewline(); - if( isLimitReached() ) - handleInvalidCompletion(); - return null; - - case PreprocessorDirectives.BLANK : - String remainderOfLine = - getRestOfPreprocessorLine().trim(); - if (!remainderOfLine.equals("")) { //$NON-NLS-1$ - strbuff.startString(); - strbuff.append( "# "); //$NON-NLS-1$ - strbuff.append( remainderOfLine ); - handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, strbuff.toString(), beginningOffset, false, true); - } - return null; - - default : - strbuff.startString(); - strbuff.append( "# "); //$NON-NLS-1$ - strbuff.append( token ); - handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, strbuff.toString(), beginningOffset, false, true ); - return null; - } - } - - // buff contains \\u or \\U - protected boolean processUniversalCharacterName() throws ScannerException - { - // first octet is mandatory - for( int i = 0; i < 4; ++i ) - { - int c = getChar(false); - if( ! isHex( c )) - return false; - strbuff.append( c ); - } - - Vector v = new Vector(); - Overall: for( int i = 0; i < 4; ++i ) - { - int c = getChar(false); - if( ! isHex( c )) - { - ungetChar( c ); - break; - } - v.add( new Character((char) c )); - } - - if( v.size() == 4 ) - { - for( int i = 0; i < 4; ++i ) - strbuff.append( ((Character)v.get(i)).charValue()); - } - else - { - for( int i = v.size() - 1; i >= 0; --i ) - ungetChar( ((Character)v.get(i)).charValue() ); - } - return true; - } - - /** - * @param c - * @return - */ - private boolean isHex(int c) { - switch( c ) - { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - return true; - default: - return false; - - } - } - - protected IToken processKeywordOrIdentifier(boolean pasting) throws ScannerException, EndOfFileException - { - int baseOffset = lastContext.getOffset() - 1; - - // String buffer is slow, we need a better way such as memory mapped files - int c = getChar(false); - - for( ; ; ) - { - // do the least expensive tests first! - while ( ( scannerExtension.offersDifferentIdentifierCharacters() && - scannerExtension.isValidIdentifierCharacter(c) ) || - isValidIdentifierCharacter(c) ) { - strbuff.append(c); - c = getChar(false); - if (c == '\\') { - c = consumeNewlineAfterSlash(); - } - } - if( c == '\\') - { - int next = getChar(false); - if( next == 'u' || next == 'U') - { - strbuff.append( '\\'); - strbuff.append( next ); - if( !processUniversalCharacterName() ) - return null; - c = getChar(false); - continue; // back to top of loop - } - ungetChar( next ); - } - break; - } - - ungetChar(c); - - String ident = strbuff. toString(); - - if (ident.equals(DEFINED)) - return newToken(IToken.tINTEGER, handleDefinedMacro()); - - if( ident.equals(Directives._PRAGMA) && language == ParserLanguage.C ) - { - handlePragmaOperator(); - return null; - } - - if (!disableMacroExpansion) { - IMacroDescriptor mapping = getDefinition(ident); - - if (mapping != null && !isLimitReached() && !mapping.isCircular() ) - if( contextStack.shouldExpandDefinition( ident ) ) { - expandDefinition(ident, mapping, baseOffset); - return null; - } - } - if( pasting && pasteIntoInputStream(ident)) - return null; - - Object tokenTypeObject; - if( language == ParserLanguage.CPP ) - tokenTypeObject = cppKeywords.get(ident); - else - tokenTypeObject = cKeywords.get(ident); - - if (tokenTypeObject != null) - return newConstantToken(((Integer) tokenTypeObject).intValue()); - if( scannerExtension.isExtensionKeyword( language, ident ) ) - return newExtensionToken( scannerExtension.createExtensionToken(this, ident )); - return newToken(IToken.tIDENTIFIER, ident); - } - - /** - * @param token - * @return - */ - protected IToken newExtensionToken(IToken token) { - setCurrentToken( token ); - return currentToken; - } - - /** - * @param c - * @return - */ - protected boolean isValidIdentifierCharacter(int c) { - return ((c >= 'a') && (c <= 'z')) - || ((c >= 'A') && (c <= 'Z')) - || ((c >= '0') && (c <= '9')) - || (c == '_') || Character.isUnicodeIdentifierPart( (char)c); - } - - public IToken nextToken( boolean pasting ) throws ScannerException, EndOfFileException - { - if( ! initialContextInitialized ) - setupInitialContext(); - - if( cachedToken != null ){ - setCurrentToken( cachedToken ); - cachedToken = null; - return currentToken; - } - - IToken token; - count++; - - int c = getChar(false); - - while (c != NOCHAR) { - if ( ! passOnToClient ) { - while (c != NOCHAR && c != '#' ) - { - c = getChar(false); - if( c == '/' ) - { - c = getChar(false); - if( c == '/' ) - { - skipOverSinglelineComment(); - continue; - } - else if( c == '*' ) - { - skipOverMultilineComment(); - continue; - } - } - } - - if( c == NOCHAR ) - { - if( isLimitReached() ) - handleInvalidCompletion(); - continue; - } - } - - switch (c) { - case ' ' : - case '\r' : - case '\t' : - case '\n' : - c = getChar(false); - continue; - case ':' : - c = getChar(false); - switch (c) { - case ':' : return newConstantToken(IToken.tCOLONCOLON); - // Diagraph - case '>' : return newConstantToken(IToken.tRBRACKET); - default : - ungetChar(c); - return newConstantToken(IToken.tCOLON); - } - case ';' : return newConstantToken(IToken.tSEMI); - case ',' : return newConstantToken(IToken.tCOMMA); - case '?' : - c = getChar(false); - if (c == '?') - { - // trigraph - c = getChar(false); - switch (c) { - case '=': - // this is the same as the # case - token = processPreprocessor(); - if (token == null) - { - c = getChar(false); - continue; - } - return token; - default: - // Not a trigraph - ungetChar(c); - ungetChar('?'); - return newConstantToken(IToken.tQUESTION); - } - } - - ungetChar(c); - return newConstantToken(IToken.tQUESTION); - - case '(' : return newConstantToken(IToken.tLPAREN); - case ')' : return newConstantToken(IToken.tRPAREN); - case '[' : return newConstantToken(IToken.tLBRACKET); - case ']' : return newConstantToken(IToken.tRBRACKET); - case '{' : return newConstantToken(IToken.tLBRACE); - case '}' : return newConstantToken(IToken.tRBRACE); - case '+' : - c = getChar(false); - switch (c) { - case '=' : return newConstantToken(IToken.tPLUSASSIGN); - case '+' : return newConstantToken(IToken.tINCR); - default : - ungetChar(c); - return newConstantToken(IToken.tPLUS); - } - case '-' : - c = getChar(false); - switch (c) { - case '=' : return newConstantToken(IToken.tMINUSASSIGN); - case '-' : return newConstantToken(IToken.tDECR); - case '>' : - c = getChar(false); - switch (c) { - case '*' : return newConstantToken(IToken.tARROWSTAR); - default : - ungetChar(c); - return newConstantToken(IToken.tARROW); - } - default : - ungetChar(c); - return newConstantToken(IToken.tMINUS); - } - case '*' : - c = getChar(false); - switch (c) { - case '=' : return newConstantToken(IToken.tSTARASSIGN); - default : - ungetChar(c); - return newConstantToken(IToken.tSTAR); - } - case '%' : - c = getChar(false); - switch (c) { - case '=' : return newConstantToken(IToken.tMODASSIGN); - - // Diagraph - case '>' : return newConstantToken(IToken.tRBRACE); - case ':' : - // this is the same as the # case - token = processPreprocessor(); - if (token == null) - { - c = getChar(false); - continue; - } - return token; - default : - ungetChar(c); - return newConstantToken(IToken.tMOD); - } - case '^' : - c = getChar(false); - switch (c) { - case '=' : return newConstantToken(IToken.tXORASSIGN); - default : - ungetChar(c); - return newConstantToken(IToken.tXOR); - } - case '&' : - c = getChar(false); - switch (c) { - case '=' : return newConstantToken(IToken.tAMPERASSIGN); - case '&' : return newConstantToken(IToken.tAND); - default : - ungetChar(c); - return newConstantToken(IToken.tAMPER); - } - case '|' : - c = getChar(false); - switch (c) { - case '=' : return newConstantToken(IToken.tBITORASSIGN); - case '|' : return newConstantToken(IToken.tOR); - default : - ungetChar(c); - return newConstantToken(IToken.tBITOR); - } - case '~' : return newConstantToken(IToken.tCOMPL); - case '!' : - c = getChar(false); - switch (c) { - case '=' : return newConstantToken(IToken.tNOTEQUAL); - default : - ungetChar(c); - return newConstantToken(IToken.tNOT); - } - case '=' : - c = getChar(false); - switch (c) { - case '=' : return newConstantToken(IToken.tEQUAL); - default : - ungetChar(c); - return newConstantToken(IToken.tASSIGN); - } - case '<' : - c = getChar(false); - switch (c) { - case '<' : - c = getChar(false); - switch (c) { - case '=' : return newConstantToken(IToken.tSHIFTLASSIGN); - default : - ungetChar(c); - return newConstantToken(IToken.tSHIFTL); - } - case '=' : return newConstantToken(IToken.tLTEQUAL); - - // Diagraphs - case '%' : return newConstantToken(IToken.tLBRACE); - case ':' : return newConstantToken(IToken.tLBRACKET); - - default : - strbuff.startString(); - strbuff.append('<'); - strbuff.append(c); - String query = strbuff.toString(); - if( scannerExtension.isExtensionOperator( language, query ) ) - return newExtensionToken( scannerExtension.createExtensionToken( this, query )); - ungetChar(c); - if( forInclusion ) - temporarilyReplaceDefinitionsMap(); - return newConstantToken(IToken.tLT); - } - case '>' : - c = getChar(false); - switch (c) { - case '>' : - c = getChar(false); - switch (c) { - case '=' : return newConstantToken(IToken.tSHIFTRASSIGN); - default : - ungetChar(c); - return newConstantToken(IToken.tSHIFTR); - } - case '=' : return newConstantToken(IToken.tGTEQUAL); - default : - strbuff.startString(); - strbuff.append('>'); - strbuff.append( (char)c); - String query = strbuff.toString(); - if( scannerExtension.isExtensionOperator( language, query ) ) - return newExtensionToken( scannerExtension.createExtensionToken( this, query )); - ungetChar(c); - if( forInclusion ) - temporarilyReplaceDefinitionsMap(); - return newConstantToken(IToken.tGT); - } - case '.' : - c = getChar(false); - switch (c) { - case '.' : - c = getChar(false); - switch (c) { - case '.' : return newConstantToken(IToken.tELLIPSIS); - default : - // TODO : there is something missing here! - break; - } - break; - case '*' : return newConstantToken(IToken.tDOTSTAR); - case '0' : - case '1' : - case '2' : - case '3' : - case '4' : - case '5' : - case '6' : - case '7' : - case '8' : - case '9' : - ungetChar(c); - return processNumber('.', pasting); - default : - ungetChar(c); - return newConstantToken(IToken.tDOT); - } - break; - -// The logic around the escape \ is fuzzy. There is code in getChar(boolean) and -// in consumeNewLineAfterSlash(). It currently works, but is fragile. -// case '\\' : -// c = consumeNewlineAfterSlash(); -// -// // if we are left with the \ we can skip it. -// if (c == '\\') -// c = getChar(); -// continue; - - case '/' : - c = getChar(false); - switch (c) { - case '/' : - skipOverSinglelineComment(); - c = getChar(false); - continue; - case '*' : - skipOverMultilineComment(); - c = getChar(false); - continue; - case '=' : return newConstantToken(IToken.tDIVASSIGN); - default : - ungetChar(c); - return newConstantToken(IToken.tDIV); - } - case '0' : - case '1' : - case '2' : - case '3' : - case '4' : - case '5' : - case '6' : - case '7' : - case '8' : - case '9' : - token = processNumber(c, pasting); - if (token == null) - { - c = getChar(false); - continue; - } - return token; - - case 'L' : - // check for wide literal - c = getChar(false); - if (c == '"') - token = processStringLiteral(true); - else if (c == '\'') - return processCharacterLiteral( c, true ); - else - { - // This is not a wide literal -- it must be a token or keyword - ungetChar(c); - strbuff.startString(); - strbuff.append('L'); - token = processKeywordOrIdentifier(pasting); - } - if (token == null) - { - c = getChar(false); - continue; - } - return token; - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - // 'L' is handled elsewhere - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '_': - strbuff.startString(); - strbuff.append( c ); - token = processKeywordOrIdentifier(pasting); - if (token == null) - { - c = getChar(false); - continue; - } - return token; - case '"' : - token = processStringLiteral(false); - if (token == null) - { - c = getChar(false); - continue; - } - return token; - case '\'' : return processCharacterLiteral( c, false ); - case '#': - // This is a special case -- the preprocessor is integrated into - // the scanner. If we get a null token, it means that everything - // was handled correctly and we can go on to the next characgter. - - token = processPreprocessor(); - if (token == null) - { - c = getChar(false); - continue; - } - return token; - - default: - if ( ( scannerExtension.offersDifferentIdentifierCharacters() && - scannerExtension.isValidIdentifierStartCharacter(c) ) || - isValidIdentifierStartCharacter(c) ) - { - strbuff.startString(); - strbuff.append( c ); - token = processKeywordOrIdentifier(pasting); - if (token == null) - { - c = getChar(false); - continue; - } - return token; - } - else if( c == '\\' ) - { - int next = getChar(false); - strbuff.startString(); - strbuff.append( '\\'); - strbuff.append( next ); - - if( next == 'u' || next =='U' ) - { - if( !processUniversalCharacterName() ) - { - handleProblem( IProblem.SCANNER_BAD_CHARACTER, strbuff.toString(), getCurrentOffset(), false, true, throwExceptionOnBadCharacterRead ); - c = getChar(false); - continue; - } - token = processKeywordOrIdentifier( pasting ); - if (token == null) - { - c = getChar(false); - continue; - } - return token; - } - ungetChar( next ); - handleProblem( IProblem.SCANNER_BAD_CHARACTER, strbuff.toString(), getCurrentOffset(), false, true, throwExceptionOnBadCharacterRead ); - } - - handleProblem( IProblem.SCANNER_BAD_CHARACTER, new Character( (char)c ).toString(), getCurrentOffset(), false, true, throwExceptionOnBadCharacterRead ); - c = getChar(false); - continue; - } - } - - // we're done - throwEOF(null); - return null; - } - - - - /** - * @param c - * @return - */ - protected boolean isValidIdentifierStartCharacter(int c) { - return Character.isLetter((char)c) || ( c == '_'); - } - - /** - * @param definition - */ - protected void handleCompletionOnDefinition(String definition) throws EndOfFileException { - IASTCompletionNode node = new ASTCompletionNode( IASTCompletionNode.CompletionKind.MACRO_REFERENCE, - null, null, definition, KeywordSets.getKeywords(KeywordSetKey.EMPTY, language), EMPTY_STRING, null ); - - throwEOF( node ); - } - - /** - * @param expression2 - */ - protected void handleCompletionOnExpression(String expression) throws EndOfFileException { - int completionPoint = expression.length() + 2; - IASTCompletionNode.CompletionKind kind = IASTCompletionNode.CompletionKind.MACRO_REFERENCE; - - String prefix = EMPTY_STRING; - - if( ! expression.trim().equals(EMPTY_STRING)) - { - IScanner subScanner = new Scanner( - new CodeReader(expression.toCharArray()), - getTemporaryHashtable(), - Collections.EMPTY_LIST, - NULL_REQUESTOR, - ParserMode.QUICK_PARSE, - language, - NULL_LOG_SERVICE, - scannerExtension ); - IToken lastToken = null; - while( true ) - { - try - { - lastToken = subScanner.nextToken(); - } - catch( EndOfFileException eof ) - { - // ok - break; - } catch (ScannerException e) { - handleInternalError(); - break; - } - } - - - if( ( lastToken != null )) - { - if( ( lastToken.getType() == IToken.tIDENTIFIER ) - && ( lastToken.getEndOffset() == completionPoint ) ) - prefix = lastToken.getImage(); - else if( ( lastToken.getEndOffset() == completionPoint ) && - ( lastToken.getType() != IToken.tIDENTIFIER ) ) - kind = IASTCompletionNode.CompletionKind.NO_SUCH_KIND; - - - } - } - - IASTCompletionNode node = new ASTCompletionNode( kind, - null, null, prefix, - KeywordSets.getKeywords(((kind == IASTCompletionNode.CompletionKind.NO_SUCH_KIND )? KeywordSetKey.EMPTY : KeywordSetKey.MACRO), language), EMPTY_STRING, null ); - - throwEOF( node ); - } - - /** - * @return - */ - private Map getTemporaryHashtable() { - tempMap.clear(); - return tempMap = new HashMap(); - } - - protected void handleInvalidCompletion() throws EndOfFileException - { - throwEOF( new ASTCompletionNode( IASTCompletionNode.CompletionKind.UNREACHABLE_CODE, null, null, EMPTY_STRING, KeywordSets.getKeywords(KeywordSetKey.EMPTY, language ) , EMPTY_STRING, null)); - } - - protected void handleCompletionOnPreprocessorDirective( String prefix ) throws EndOfFileException - { - throwEOF( new ASTCompletionNode( IASTCompletionNode.CompletionKind.NO_SUCH_KIND, null, null, prefix, KeywordSets.getKeywords(KeywordSetKey.PP_DIRECTIVE, language ), EMPTY_STRING, null)); - } - /** - * @param key - */ - protected void removeSymbol(String key) { - definitions.remove(key); - } - - /** - * - */ - protected void handlePragmaOperator() throws ScannerException, EndOfFileException - { - // until we know what to do with pragmas, do the equivalent as - // to what we do for #pragma blah blah blah (ignore it) - getRestOfPreprocessorLine(); - } - - /** - * @param c - * @param wideLiteral - */ - protected IToken processCharacterLiteral(int c, boolean wideLiteral) - throws ScannerException - { - int beginOffset = getCurrentOffset(); - int type = wideLiteral ? IToken.tLCHAR : IToken.tCHAR; - - strbuff.startString(); - int prev = c; - int prevPrev = c; - c = getChar(true); - - for( ; ; ) - { - // error conditions - if( ( c == '\n' ) || - ( ( c == '\\' || c =='\'' )&& prev == '\\' ) || - ( c == NOCHAR ) ) - { - handleProblem( IProblem.SCANNER_BAD_CHARACTER, new Character( (char)c ).toString(),beginOffset, false, true, throwExceptionOnBadCharacterRead ); - c = '\''; - } - // exit condition - if ( ( c =='\'' ) && ( prev != '\\' || prevPrev == '\\' ) ) break; - - strbuff.append(c); - prevPrev = prev; - prev = c; - c = getChar(true); - } - - return newToken( type, strbuff.toString()); - } - - - - protected String getCurrentFile() - { - return contextStack.getMostRelevantFileContext() != null ? contextStack.getMostRelevantFileContext().getContextName() : ""; //$NON-NLS-1$ - } - - - protected int getCurrentOffset() - { - return contextStack.getMostRelevantFileContext() != null ? contextStack.getMostRelevantFileContext().getOffset() : -1; - } - - - protected static class endOfMacroTokenException extends Exception {} - // the static instance we always use - protected static endOfMacroTokenException endOfMacroToken = new endOfMacroTokenException(); - - public IToken nextTokenForStringizing() throws ScannerException, EndOfFileException - { - int beginOffset = getCurrentOffset(); - int c = getChar(false); - strbuff.startString(); - - try { - while (c != NOCHAR) { - switch (c) { - case ' ' : - case '\r' : - case '\t' : - case '\n' : - if (strbuff.length() > 0) throw endOfMacroToken; - c = getChar(false); - continue; - case '"' : - if (strbuff.length() > 0) throw endOfMacroToken; - - // string - strbuff.startString(); - c = getChar(true); - - for( ; ; ) - { - if ( c =='"' ) break; - if( c == NOCHAR) break; - strbuff.append(c); - c = getChar(true); - } - - if (c != NOCHAR ) - { - return newToken( IToken.tSTRING, strbuff.toString()); - - } - handleProblem( IProblem.SCANNER_UNBOUNDED_STRING, null, beginOffset, false, true ); - c = getChar(false); - continue; - - case '\'' : - if (strbuff.length() > 0) throw endOfMacroToken; - return processCharacterLiteral( c, false ); - case ',' : - if (strbuff.length() > 0) throw endOfMacroToken; - return newToken(IToken.tCOMMA, ","); //$NON-NLS-1$ - case '(' : - if (strbuff.length() > 0) throw endOfMacroToken; - return newToken(IToken.tLPAREN, "("); //$NON-NLS-1$ - case ')' : - if (strbuff.length() > 0) throw endOfMacroToken; - return newToken(IToken.tRPAREN, ")"); //$NON-NLS-1$ - case '/' : - if (strbuff.length() > 0) throw endOfMacroToken; - c = getChar(false); - switch (c) { - case '/' : - skipOverSinglelineComment(); - c = getChar(false); - continue; - case '*' : - skipOverMultilineComment(); - c = getChar(false); - continue; - default: - strbuff.append('/'); - continue; - } - default : - strbuff.append(c); - c = getChar(false); - } - } - } catch (endOfMacroTokenException e) { - // unget the first character after the end of token - ungetChar(c); - } - - // return completed token - if (strbuff.length() > 0) { - return newToken(IToken.tIDENTIFIER, strbuff.toString()); - } - - // we're done - throwEOF(null); - return null; - } - - - /** - * - */ - protected void throwEOF(IASTCompletionNode node) throws EndOfFileException, OffsetLimitReachedException { - if( node == null ) - { - if( offsetLimit == NO_OFFSET_LIMIT ) - throw EOF; - - if( finalToken != null && finalToken.getEndOffset() == offsetLimit ) - throw new OffsetLimitReachedException(finalToken); - throw new OffsetLimitReachedException( (IToken)null ); - } - throw new OffsetLimitReachedException( node ); - } - - - static { - cppKeywords.put( Keywords.AND, new Integer(IToken.t_and)); - cppKeywords.put( Keywords.AND_EQ, new Integer(IToken.t_and_eq)); - cppKeywords.put( Keywords.ASM, new Integer(IToken.t_asm)); - cppKeywords.put( Keywords.AUTO, new Integer(IToken.t_auto)); - cppKeywords.put( Keywords.BITAND, new Integer(IToken.t_bitand)); - cppKeywords.put( Keywords.BITOR, new Integer(IToken.t_bitor)); - cppKeywords.put( Keywords.BOOL, new Integer(IToken.t_bool)); - cppKeywords.put( Keywords.BREAK, new Integer(IToken.t_break)); - cppKeywords.put( Keywords.CASE, new Integer(IToken.t_case)); - cppKeywords.put( Keywords.CATCH, new Integer(IToken.t_catch)); - cppKeywords.put( Keywords.CHAR, new Integer(IToken.t_char)); - cppKeywords.put( Keywords.CLASS, new Integer(IToken.t_class)); - cppKeywords.put( Keywords.COMPL, new Integer(IToken.t_compl)); - cppKeywords.put( Keywords.CONST, new Integer(IToken.t_const)); - cppKeywords.put( Keywords.CONST_CAST, new Integer(IToken.t_const_cast)); - cppKeywords.put( Keywords.CONTINUE, new Integer(IToken.t_continue)); - cppKeywords.put( Keywords.DEFAULT, new Integer(IToken.t_default)); - cppKeywords.put( Keywords.DELETE, new Integer(IToken.t_delete)); - cppKeywords.put( Keywords.DO, new Integer(IToken.t_do)); - cppKeywords.put( Keywords.DOUBLE, new Integer(IToken.t_double)); - cppKeywords.put( Keywords.DYNAMIC_CAST, new Integer(IToken.t_dynamic_cast)); - cppKeywords.put( Keywords.ELSE, new Integer(IToken.t_else)); - cppKeywords.put( Keywords.ENUM, new Integer(IToken.t_enum)); - cppKeywords.put( Keywords.EXPLICIT, new Integer(IToken.t_explicit)); - cppKeywords.put( Keywords.EXPORT, new Integer(IToken.t_export)); - cppKeywords.put( Keywords.EXTERN, new Integer(IToken.t_extern)); - cppKeywords.put( Keywords.FALSE, new Integer(IToken.t_false)); - cppKeywords.put( Keywords.FLOAT, new Integer(IToken.t_float)); - cppKeywords.put( Keywords.FOR, new Integer(IToken.t_for)); - cppKeywords.put( Keywords.FRIEND, new Integer(IToken.t_friend)); - cppKeywords.put( Keywords.GOTO, new Integer(IToken.t_goto)); - cppKeywords.put( Keywords.IF, new Integer(IToken.t_if)); - cppKeywords.put( Keywords.INLINE, new Integer(IToken.t_inline)); - cppKeywords.put( Keywords.INT, new Integer(IToken.t_int)); - cppKeywords.put( Keywords.LONG, new Integer(IToken.t_long)); - cppKeywords.put( Keywords.MUTABLE, new Integer(IToken.t_mutable)); - cppKeywords.put( Keywords.NAMESPACE, new Integer(IToken.t_namespace)); - cppKeywords.put( Keywords.NEW, new Integer(IToken.t_new)); - cppKeywords.put( Keywords.NOT, new Integer(IToken.t_not)); - cppKeywords.put( Keywords.NOT_EQ, new Integer(IToken.t_not_eq)); - cppKeywords.put( Keywords.OPERATOR, new Integer(IToken.t_operator)); - cppKeywords.put( Keywords.OR, new Integer(IToken.t_or)); - cppKeywords.put( Keywords.OR_EQ, new Integer(IToken.t_or_eq)); - cppKeywords.put( Keywords.PRIVATE, new Integer(IToken.t_private)); - cppKeywords.put( Keywords.PROTECTED, new Integer(IToken.t_protected)); - cppKeywords.put( Keywords.PUBLIC, new Integer(IToken.t_public)); - cppKeywords.put( Keywords.REGISTER, new Integer(IToken.t_register)); - cppKeywords.put( Keywords.REINTERPRET_CAST, new Integer(IToken.t_reinterpret_cast)); - cppKeywords.put( Keywords.RETURN, new Integer(IToken.t_return)); - cppKeywords.put( Keywords.SHORT, new Integer(IToken.t_short)); - cppKeywords.put( Keywords.SIGNED, new Integer(IToken.t_signed)); - cppKeywords.put( Keywords.SIZEOF, new Integer(IToken.t_sizeof)); - cppKeywords.put( Keywords.STATIC, new Integer(IToken.t_static)); - cppKeywords.put( Keywords.STATIC_CAST, new Integer(IToken.t_static_cast)); - cppKeywords.put( Keywords.STRUCT, new Integer(IToken.t_struct)); - cppKeywords.put( Keywords.SWITCH, new Integer(IToken.t_switch)); - cppKeywords.put( Keywords.TEMPLATE, new Integer(IToken.t_template)); - cppKeywords.put( Keywords.THIS, new Integer(IToken.t_this)); - cppKeywords.put( Keywords.THROW, new Integer(IToken.t_throw)); - cppKeywords.put( Keywords.TRUE, new Integer(IToken.t_true)); - cppKeywords.put( Keywords.TRY, new Integer(IToken.t_try)); - cppKeywords.put( Keywords.TYPEDEF, new Integer(IToken.t_typedef)); - cppKeywords.put( Keywords.TYPEID, new Integer(IToken.t_typeid)); - cppKeywords.put( Keywords.TYPENAME, new Integer(IToken.t_typename)); - cppKeywords.put( Keywords.UNION, new Integer(IToken.t_union)); - cppKeywords.put( Keywords.UNSIGNED, new Integer(IToken.t_unsigned)); - cppKeywords.put( Keywords.USING, new Integer(IToken.t_using)); - cppKeywords.put( Keywords.VIRTUAL, new Integer(IToken.t_virtual)); - cppKeywords.put( Keywords.VOID, new Integer(IToken.t_void)); - cppKeywords.put( Keywords.VOLATILE, new Integer(IToken.t_volatile)); - cppKeywords.put( Keywords.WCHAR_T, new Integer(IToken.t_wchar_t)); - cppKeywords.put( Keywords.WHILE, new Integer(IToken.t_while)); - cppKeywords.put( Keywords.XOR, new Integer(IToken.t_xor)); - cppKeywords.put( Keywords.XOR_EQ, new Integer(IToken.t_xor_eq)); - - ppDirectives.put(Directives.POUND_DEFINE, new Integer(PreprocessorDirectives.DEFINE)); - ppDirectives.put(Directives.POUND_UNDEF,new Integer(PreprocessorDirectives.UNDEFINE)); - ppDirectives.put(Directives.POUND_IF, new Integer(PreprocessorDirectives.IF)); - ppDirectives.put(Directives.POUND_IFDEF, new Integer(PreprocessorDirectives.IFDEF)); - ppDirectives.put(Directives.POUND_IFNDEF, new Integer(PreprocessorDirectives.IFNDEF)); - ppDirectives.put(Directives.POUND_ELSE, new Integer(PreprocessorDirectives.ELSE)); - ppDirectives.put(Directives.POUND_ENDIF, new Integer(PreprocessorDirectives.ENDIF)); - ppDirectives.put(Directives.POUND_INCLUDE, new Integer(PreprocessorDirectives.INCLUDE)); - ppDirectives.put(Directives.POUND_LINE, new Integer(PreprocessorDirectives.LINE)); - ppDirectives.put(Directives.POUND_ERROR, new Integer(PreprocessorDirectives.ERROR)); - ppDirectives.put(Directives.POUND_PRAGMA, new Integer(PreprocessorDirectives.PRAGMA)); - ppDirectives.put(Directives.POUND_ELIF, new Integer(PreprocessorDirectives.ELIF)); - ppDirectives.put(Directives.POUND_BLANK, new Integer(PreprocessorDirectives.BLANK)); - - cKeywords.put( Keywords.AUTO, new Integer(IToken.t_auto)); - cKeywords.put( Keywords.BREAK, new Integer(IToken.t_break)); - cKeywords.put( Keywords.CASE, new Integer(IToken.t_case)); - cKeywords.put( Keywords.CHAR, new Integer(IToken.t_char)); - cKeywords.put( Keywords.CONST, new Integer(IToken.t_const)); - cKeywords.put( Keywords.CONTINUE, new Integer(IToken.t_continue)); - cKeywords.put( Keywords.DEFAULT, new Integer(IToken.t_default)); - cKeywords.put( Keywords.DELETE, new Integer(IToken.t_delete)); - cKeywords.put( Keywords.DO, new Integer(IToken.t_do)); - cKeywords.put( Keywords.DOUBLE, new Integer(IToken.t_double)); - cKeywords.put( Keywords.ELSE, new Integer(IToken.t_else)); - cKeywords.put( Keywords.ENUM, new Integer(IToken.t_enum)); - cKeywords.put( Keywords.EXTERN, new Integer(IToken.t_extern)); - cKeywords.put( Keywords.FLOAT, new Integer(IToken.t_float)); - cKeywords.put( Keywords.FOR, new Integer(IToken.t_for)); - cKeywords.put( Keywords.GOTO, new Integer(IToken.t_goto)); - cKeywords.put( Keywords.IF, new Integer(IToken.t_if)); - cKeywords.put( Keywords.INLINE, new Integer(IToken.t_inline)); - cKeywords.put( Keywords.INT, new Integer(IToken.t_int)); - cKeywords.put( Keywords.LONG, new Integer(IToken.t_long)); - cKeywords.put( Keywords.REGISTER, new Integer(IToken.t_register)); - cKeywords.put( Keywords.RESTRICT, new Integer(IToken.t_restrict)); - cKeywords.put( Keywords.RETURN, new Integer(IToken.t_return)); - cKeywords.put( Keywords.SHORT, new Integer(IToken.t_short)); - cKeywords.put( Keywords.SIGNED, new Integer(IToken.t_signed)); - cKeywords.put( Keywords.SIZEOF, new Integer(IToken.t_sizeof)); - cKeywords.put( Keywords.STATIC, new Integer(IToken.t_static)); - cKeywords.put( Keywords.STRUCT, new Integer(IToken.t_struct)); - cKeywords.put( Keywords.SWITCH, new Integer(IToken.t_switch)); - cKeywords.put( Keywords.TYPEDEF, new Integer(IToken.t_typedef)); - cKeywords.put( Keywords.UNION, new Integer(IToken.t_union)); - cKeywords.put( Keywords.UNSIGNED, new Integer(IToken.t_unsigned)); - cKeywords.put( Keywords.VOID, new Integer(IToken.t_void)); - cKeywords.put( Keywords.VOLATILE, new Integer(IToken.t_volatile)); - cKeywords.put( Keywords.WHILE, new Integer(IToken.t_while)); - cKeywords.put( Keywords._BOOL, new Integer(IToken.t__Bool)); - cKeywords.put( Keywords._COMPLEX, new Integer(IToken.t__Complex)); - cKeywords.put( Keywords._IMAGINARY, new Integer(IToken.t__Imaginary)); - - } - - static public class PreprocessorDirectives { - static public final int DEFINE = 0; - static public final int UNDEFINE = 1; - static public final int IF = 2; - static public final int IFDEF = 3; - static public final int IFNDEF = 4; - static public final int ELSE = 5; - static public final int ENDIF = 6; - static public final int INCLUDE = 7; - static public final int LINE = 8; - static public final int ERROR = 9; - static public final int PRAGMA = 10; - static public final int BLANK = 11; - static public final int ELIF = 12; - } - - public final int getCount() { - return count; - } - - public final int getDepth() { - return branches.getDepth(); - } - - protected boolean evaluateExpressionNew(String expression, int beginningOffset ) - throws ScannerException { - - // TODO John HELP! something has changed. If I turn this to true, My tests finish early (but the JUnits pass!) - IScannerContext context = new ScannerContextTopString(expression, EXPRESSION, ';', true); - contextStack.cs_push(context); - IToken previousToken = currentToken; - ISourceElementRequestor savedRequestor = requestor; - IParserLogService savedLog = log; - log = NULL_LOG_SERVICE; - requestor = NULL_REQUESTOR; - - - boolean savedPassOnToClient = passOnToClient; - ParserMode savedParserMode = parserMode; - IASTFactory savedFactory = astFactory; - - - passOnToClient = true; - parserMode = ParserMode.QUICK_PARSE; - - IExpressionParser parser = InternalParserUtil.createExpressionParser(this, language, NULL_LOG_SERVICE); - try { - IASTExpression exp = parser.expression(null, null, null); - return (exp.evaluateExpression() != 0); - } catch( BacktrackException backtrack ) - { - return false; - } catch (ASTExpressionEvaluationException e) { - return false; - } catch (EndOfFileException e) { - return false; - } finally { - currentToken = previousToken; - if( currentToken != null ) - currentToken.setNext( null ); - contextStack.cs_pop(); - requestor = savedRequestor; - passOnToClient = savedPassOnToClient; - parserMode = savedParserMode; - astFactory = savedFactory; - log = savedLog; - } - } - - - protected boolean evaluateExpression(String expression, int beginningOffset ) - throws ScannerException { - return evaluateExpressionNew(expression, beginningOffset); - } - - - protected void skipOverSinglelineComment() throws ScannerException, EndOfFileException { - int c; - - loop: - for (;;) { - c = getChar(false); - switch (c) { - case NOCHAR : - case '\n' : - break loop; - default : - break; - } - } - if( c== NOCHAR && isLimitReached() ) - handleInvalidCompletion(); - - } - - protected boolean skipOverMultilineComment() throws ScannerException, EndOfFileException { - int state = 0; - boolean encounteredNewline = false; - // simple state machine to handle multi-line comments - // state 0 == no end of comment in site - // state 1 == encountered *, expecting / - // state 2 == we are no longer in a comment - - int c = getChar(false); - while (state != 2 && c != NOCHAR) { - if (c == '\n') - encounteredNewline = true; - - switch (state) { - case 0 : - if (c == '*') - state = 1; - break; - case 1 : - if (c == '/') - state = 2; - else if (c != '*') - state = 0; - break; - } - c = getChar(false); - } - - if ( state != 2) - if (c == NOCHAR && !isLimitReached() ) - handleProblem( IProblem.SCANNER_UNEXPECTED_EOF, null, getCurrentOffset(), false, true ); - else if( c== NOCHAR ) // limit reached - handleInvalidCompletion(); - - ungetChar(c); - - return encounteredNewline; - } - - private static final InclusionParseException INCLUSION_PARSE_EXCEPTION = new InclusionParseException(); - - public InclusionDirective parseInclusionDirective( String includeLine, int baseOffset ) throws InclusionParseException - { - if (includeLine.equals("")) //$NON-NLS-1$ - throw INCLUSION_PARSE_EXCEPTION ; - - ISourceElementRequestor savedRequestor = requestor; - IToken previousToken = currentToken; - try - { - IScannerContext context = new ScannerContextTopString( includeLine, "INCLUDE", true ); //$NON-NLS-1$ - contextStack.cs_push(context); - requestor = NULL_REQUESTOR; - - boolean useIncludePath = true; - StringBuffer localStringBuff = new StringBuffer(100); - int startOffset = baseOffset, endOffset = baseOffset; - - IToken t = null; - - try { - t = nextToken(false); - } catch (EndOfFileException eof) { - throw INCLUSION_PARSE_EXCEPTION ; - } - - try { - if (t.getType() == IToken.tSTRING) { - localStringBuff.append(t.getImage()); - startOffset = baseOffset + t.getOffset(); - endOffset = baseOffset + t.getEndOffset(); - useIncludePath = false; - - // This should throw EOF - t = nextToken(false); - contextStack.cs_pop(); - requestor = savedRequestor; - throw INCLUSION_PARSE_EXCEPTION ; - } else if (t.getType() == IToken.tLT) { - disableMacroExpansion = true; - try { - - t = nextToken(false); - startOffset = baseOffset + t.getOffset(); - - while (t.getType() != IToken.tGT) { - localStringBuff.append(t.getImage()); - skipOverWhitespace(); - int c = getChar(); - if (c == '\\') - localStringBuff.append('\\'); - else - ungetChar(c); - t = nextToken(false); - } - - endOffset = baseOffset + t.getEndOffset(); - - } catch (EndOfFileException eof) { - throw INCLUSION_PARSE_EXCEPTION ; - } - - // This should throw EOF - t = nextToken(false); - - throw INCLUSION_PARSE_EXCEPTION ; - - } else - throw INCLUSION_PARSE_EXCEPTION ; - } - catch( EndOfFileException eof ) - { - // good - } - - return new InclusionDirective( localStringBuff.toString(), useIncludePath, startOffset, endOffset ); - } - catch( ScannerException se ) - { - throw INCLUSION_PARSE_EXCEPTION ; - } finally { - currentToken = previousToken; - if( currentToken != null ) - currentToken.setNext( null ); - contextStack.cs_pop(); - requestor = savedRequestor; - disableMacroExpansion = false; - } - } - protected void poundInclude( int beginningOffset, int startLine ) throws ScannerException, EndOfFileException { - skipOverWhitespace(); - int baseOffset = lastContext.getOffset() ; - int nameLine = contextStack.getCurrentLineNumber(); - String includeLine = getRestOfPreprocessorLine(); - if( isLimitReached() ) - handleInvalidCompletion(); - - int endLine = contextStack.getCurrentLineNumber(); - - ScannerUtility.InclusionDirective directive = null; - try - { - directive = parseInclusionDirective( includeLine, baseOffset ); - } - catch( ScannerUtility.InclusionParseException ipe ) - { - strbuff.startString(); - strbuff.append( "#include "); //$NON-NLS-1$ - strbuff.append( includeLine ); - handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, strbuff.toString(), beginningOffset, false, true ); - return; - } - - if( parserMode == ParserMode.QUICK_PARSE ) - { - if( requestor != null ) - { - IASTInclusion i = null; - try - { - i = getASTFactory().createInclusion( - directive.getFilename().toCharArray(), - EMPTY_STRING_CHAR_ARRAY, //$NON-NLS-1$ - !directive.useIncludePaths(), - beginningOffset, - startLine, - directive.getStartOffset(), - directive.getStartOffset() + directive.getFilename().length(), nameLine, directive.getEndOffset(), endLine, getCurrentFilename()); - } - catch (Exception e) - { - /* do nothing */ - } - if( i != null ) - { - i.enterScope( requestor, null ); - i.exitScope( requestor, null ); - } - } - } - else - handleInclusion(directive.getFilename().trim(), directive.useIncludePaths(), beginningOffset, startLine, directive.getStartOffset(), nameLine, directive.getEndOffset(), endLine); - } - - protected Map definitionsBackupMap = null; - - protected void temporarilyReplaceDefinitionsMap() - { - definitionsBackupMap = definitions; - definitions = Collections.EMPTY_MAP; - } - - protected void restoreDefinitionsMap() - { - definitions = definitionsBackupMap; - definitionsBackupMap = null; - } - - - protected boolean forInclusion = false; - private final static IParserLogService NULL_LOG_SERVICE = new NullLogService(); - private static final String [] STRING_ARRAY = new String[0]; - private static final IToken [] EMPTY_TOKEN_ARRAY = new IToken[0]; - private static final int START_BUFFER_SIZE = 8; - private IToken[] tokenArrayBuffer = new IToken[START_BUFFER_SIZE]; - /** - * @param b - */ - protected void setForInclusion(boolean b) - { - forInclusion = b; - } - - public boolean disableMacroExpansion = false; - - protected IToken[] tokenizeReplacementString( int beginning, String key, String replacementString, String[] parameterIdentifiers ) - { - if( replacementString.trim().equals( "" ) ) //$NON-NLS-1$ - return EMPTY_TOKEN_ARRAY; - IToken [] macroReplacementTokens = getTokenBuffer(); - int currentIndex = 0; - IScannerContext context = new ScannerContextTopString(replacementString, SCRATCH, true); - contextStack.cs_push(context); - ISourceElementRequestor savedRequestor = requestor; - IParserLogService savedLog = log; - IToken previousToken = currentToken; - - setTokenizingMacroReplacementList( true ); - disableMacroExpansion = true; - requestor = NULL_REQUESTOR; - log = NULL_LOG_SERVICE; - - try { - IToken t = null; - try { - t = nextToken(false); - } catch (ScannerException e) { - } catch (EndOfFileException e) { - } - - if( t == null ) - return EMPTY_TOKEN_ARRAY; - - try { - while (true) { - //each # preprocessing token in the replacement list shall be followed - //by a parameter as the next reprocessing token in the list - if( t.getType() == tPOUND ){ - if( currentIndex == macroReplacementTokens.length ) - { - IToken [] doubled = new IToken[macroReplacementTokens.length * 2]; - System.arraycopy( macroReplacementTokens, 0, doubled, 0, macroReplacementTokens.length ); - macroReplacementTokens = doubled; - } - macroReplacementTokens[currentIndex++] = t; - t = nextToken(false); - if( parameterIdentifiers != null ) - { - int index = findIndex( parameterIdentifiers, t.getImage()); - if (index == -1 ) { - //not found - - if( beginning != NO_OFFSET_LIMIT ) - { - strbuff.startString(); - strbuff.append( POUND_DEFINE ); - strbuff.append( key ); - strbuff.append( ' ' ); - strbuff.append( replacementString ); - handleProblem( IProblem.PREPROCESSOR_MACRO_PASTING_ERROR, strbuff.toString(), - beginning, false, true ); - return EMPTY_TOKEN_ARRAY; - } - } - } - } - - if( currentIndex == macroReplacementTokens.length ) - { - IToken [] doubled = new IToken[macroReplacementTokens.length * 2]; - System.arraycopy( macroReplacementTokens, 0, doubled, 0, macroReplacementTokens.length ); - macroReplacementTokens = doubled; - } - macroReplacementTokens[currentIndex++] = t; - t = nextToken(false); - } - } - catch( EndOfFileException eof ) - { - } - catch( ScannerException sc ) - { - } - - IToken [] result = new IToken[ currentIndex ]; - System.arraycopy( macroReplacementTokens, 0, result, 0, currentIndex ); - return result; - } - finally { - currentToken = previousToken; - if( currentToken != null ) - currentToken.setNext( null ); - contextStack.cs_pop(); - setTokenizingMacroReplacementList( false ); - requestor = savedRequestor; - log = savedLog; - disableMacroExpansion = false; - } - } - - /** - * @return - */ - IToken[] getTokenBuffer() { - Arrays.fill( tokenArrayBuffer, null ); - return tokenArrayBuffer; - } - - protected IMacroDescriptor createObjectMacroDescriptor(String key, String value ) { - IToken t = null; - if( !value.trim().equals( "" ) ) //$NON-NLS-1$ - t = TokenFactory.createUniquelyImagedToken( IToken.tIDENTIFIER, value, this ); - - return new ObjectMacroDescriptor( key, - t, - value); - } - - protected void poundDefine(int beginning, int beginningLine ) throws ScannerException, EndOfFileException { - // definition - String key = getNextIdentifier(); - int offset = currentContext.getOffset() - key.length(); - int nameLine = contextStack.getCurrentLineNumber(); - - // store the previous definition to check against later - IMacroDescriptor previousDefinition = getDefinition( key ); - IMacroDescriptor descriptor = null; - // get the next character - // the C++ standard says that macros must not put - // whitespace between the end of the definition - // identifier and the opening parenthesis - int c = getChar(false); - if (c == '(') { - strbuff.startString(); - c = getChar(true); - while (c != ')') { - if( c == '\\' ){ - c = getChar(false); - if( c == '\r' ) - c = getChar(false); - - if( c == '\n' ){ - c = getChar(false); - continue; - } - ungetChar( c ); - String line = strbuff.toString(); - strbuff.startString(); - strbuff.append( POUND_DEFINE ); - strbuff.append( line ); - strbuff.append( '\\'); - strbuff.append( c ); - handleProblem( IProblem.PREPROCESSOR_INVALID_MACRO_DEFN, strbuff.toString(), beginning, false, true); - return; - } else if( c == '\r' || c == '\n' || c == NOCHAR ){ - String line = strbuff.toString(); - strbuff.startString(); - strbuff.append( POUND_DEFINE ); - strbuff.append( line ); - strbuff.append( '\\'); - strbuff.append( c ); - handleProblem( IProblem.PREPROCESSOR_INVALID_MACRO_DEFN, strbuff.toString(), beginning, false, true ); - return; - } - - strbuff.append(c); - c = getChar(true); - } - - String parameters = strbuff.toString(); - - // replace StringTokenizer later -- not performant - StringTokenizer tokenizer = new StringTokenizer(parameters, ","); //$NON-NLS-1$ - String []parameterIdentifiers = new String[tokenizer.countTokens()]; - int ct = 0; - while (tokenizer.hasMoreTokens()) { - parameterIdentifiers[ ct++ ] = tokenizer.nextToken().trim(); - } - - skipOverWhitespace(); - - IToken [] macroReplacementTokens = null; - String replacementString = getRestOfPreprocessorLine(); - // TODO: This tokenization could be done live, instead of using a sub-scanner. - - macroReplacementTokens = ( ! replacementString.equals( "" ) ) ? //$NON-NLS-1$ - tokenizeReplacementString( beginning, key, replacementString, parameterIdentifiers ) : - EMPTY_TOKEN_ARRAY; - - descriptor = new FunctionMacroDescriptor( - key, - parameterIdentifiers, - macroReplacementTokens, - replacementString); - - checkValidMacroRedefinition(key, previousDefinition, descriptor, beginning); - addDefinition(key, descriptor); - - } - else if ((c == '\n') || (c == '\r')) - { - descriptor = createObjectMacroDescriptor(key, ""); //$NON-NLS-1$ - checkValidMacroRedefinition(key, previousDefinition, descriptor, beginning); - addDefinition( key, descriptor ); - } - else if ((c == ' ') || (c == '\t') ) { - // this is a simple definition - skipOverWhitespace(); - - // get what we are to map the name to and add it to the definitions list - String value = getRestOfPreprocessorLine(); - - descriptor = createObjectMacroDescriptor(key, value); - checkValidMacroRedefinition(key, previousDefinition, descriptor, beginning); - addDefinition( key, descriptor ); - - } else if (c == '/') { - // this could be a comment - c = getChar(false); - if (c == '/') // one line comment - { - skipOverSinglelineComment(); - descriptor = createObjectMacroDescriptor(key, ""); //$NON-NLS-1$ - checkValidMacroRedefinition(key, previousDefinition, descriptor, beginning); - addDefinition(key, descriptor); - } else if (c == '*') // multi-line comment - { - if (skipOverMultilineComment()) { - // we have gone over a newline - // therefore, this symbol was defined to an empty string - descriptor = createObjectMacroDescriptor(key, ""); //$NON-NLS-1$ - checkValidMacroRedefinition(key, previousDefinition, descriptor, beginning); - addDefinition(key, descriptor); - } else { - String value = getRestOfPreprocessorLine(); - - descriptor = createObjectMacroDescriptor(key, value); - checkValidMacroRedefinition(key, previousDefinition, descriptor, beginning); - addDefinition(key, descriptor); - } - } else { - // this is not a comment - // it is a bad statement - StringBuffer potentialErrorMessage = new StringBuffer( POUND_DEFINE ); - potentialErrorMessage.append( key ); - potentialErrorMessage.append( " /"); //$NON-NLS-1$ - potentialErrorMessage.append( getRestOfPreprocessorLine() ); - handleProblem( IProblem.PREPROCESSOR_INVALID_MACRO_DEFN, potentialErrorMessage.toString(), beginning, false, true ); - return; - } - } else { - StringBuffer potentialErrorMessage = new StringBuffer( POUND_DEFINE ); - potentialErrorMessage.append( key ); - potentialErrorMessage.append( (char)c ); - potentialErrorMessage.append( getRestOfPreprocessorLine() ); - handleProblem( IProblem.PREPROCESSOR_INVALID_MACRO_DEFN, potentialErrorMessage.toString(), beginning, false, true ); - return; - } - - try - { - getASTFactory().createMacro( key.toCharArray(), beginning, beginningLine, offset, offset + key.length(), nameLine, currentContext.getOffset(), contextStack.getCurrentLineNumber(), descriptor, getCurrentFilename() ).acceptElement( requestor, null ); - } - catch (Exception e) - { - /* do nothing */ - } - } - - protected void checkValidMacroRedefinition( - String key, - IMacroDescriptor previousDefinition, - IMacroDescriptor newDefinition, int beginningOffset ) - throws ScannerException - { - if( parserMode != ParserMode.QUICK_PARSE && previousDefinition != null ) - { - if( previousDefinition.compatible( newDefinition ) ) - return; - - handleProblem( IProblem.PREPROCESSOR_INVALID_MACRO_REDEFN, key, beginningOffset, false, true ); - } - } - - /** - * - */ - protected void handleInternalError() { - // TODO Auto-generated method stub - - } - - protected Vector getMacroParameters (String params, boolean forStringizing) throws ScannerException { - - // split params up into single arguments - int nParen = 0; - Vector parameters = new Vector(); - strbuff.startString(); - for (int i = 0; i < params.length(); i++) { - char c = params.charAt(i); - switch (c) { - case '(' : - nParen++; - break; - case ')' : - nParen--; - break; - case ',' : - if (nParen == 0) { - parameters.add(strbuff.toString()); - strbuff.startString(); - continue; - } - break; - default : - break; - } - strbuff.append( c ); - } - parameters.add(strbuff.toString()); - - setThrowExceptionOnBadCharacterRead(false); - ISourceElementRequestor savedRequestor = requestor; - IParserLogService savedLog = log; - log = NULL_LOG_SERVICE; - requestor = NULL_REQUESTOR; - IToken previousToken = currentToken; - - Vector parameterValues = new Vector(); - for (int i = 0; i < parameters.size(); i++) { - IScannerContext context = new ScannerContextTopString((String)parameters.elementAt(i), TEXT, true); - contextStack.cs_push(context); - IToken t = null; - StringBuffer strBuff2 = new StringBuffer(); - boolean space = false; - - try { - while (true) { - int c = getCharacter(); - if ((c != ' ') && (c != '\t') && (c != '\r') && (c != '\n')) { - space = false; - } - if (c != NOCHAR) ungetChar(c); - t = (forStringizing ? nextTokenForStringizing() : nextToken(false)); - - if (space) - strBuff2.append( ' ' ); - - switch (t.getType()) { - case IToken.tSTRING : - strBuff2.append('\"'); - strBuff2.append(t.getImage()); - strBuff2.append('\"'); - break; - case IToken.tLSTRING : - strBuff2.append( "L\""); //$NON-NLS-1$ - strBuff2.append(t.getImage()); - strBuff2.append('\"'); - break; - case IToken.tCHAR : - strBuff2.append('\''); - strBuff2.append(t.getImage()); - strBuff2.append('\''); - break; - default : - strBuff2.append( t.getImage()); - break; - } - space = true; - } - } - catch (EndOfFileException e) { - // Good - contextStack.cs_pop(); - parameterValues.add(strBuff2.toString()); - } - } - currentToken = previousToken; - if( currentToken != null ) - currentToken.setNext( null ); - setThrowExceptionOnBadCharacterRead(true); - requestor = savedRequestor; - log = savedLog; - return parameterValues; - } - - protected void expandDefinition(String symbol, String expansion, int symbolOffset ) throws ScannerException - { - expandDefinition( symbol, - new ObjectMacroDescriptor( symbol, - expansion ), - symbolOffset); - } - - protected void expandDefinition(String symbol, IMacroDescriptor expansion, int symbolOffset) - throws ScannerException - { - // All the tokens generated by the macro expansion - // will have dimensions (offset and length) equal to the expanding symbol. - if ( expansion.getMacroType() == MacroType.OBJECT_LIKE || expansion.getMacroType() == MacroType.INTERNAL_LIKE ) { - String replacementValue = expansion.getExpansionSignature(); - try - { - contextStack.updateMacroContext( - replacementValue, - symbol, - requestor, - symbolOffset, - symbol.length()); - } - catch (ContextException e) - { - handleProblem( e.getId(), currentContext.getContextName(), getCurrentOffset(), false, true ); - consumeUntilOutOfMacroExpansion(); - return; - } - } else if (expansion.getMacroType() == MacroType.FUNCTION_LIKE ) { - skipOverWhitespace(); - int c = getChar(false); - - if (c == '(') { - strbuff.startString(); - int bracketCount = 1; - c = getChar(false); - - while (true) { - if (c == '(') - ++bracketCount; - else if (c == ')') - --bracketCount; - - if(bracketCount == 0 || c == NOCHAR) - break; - strbuff.append(c); - c = getChar( true ); - } - - - String betweenTheBrackets = strbuff.toString().trim(); - - if (expansion.getExpansionSignature() == EMPTY_STRING) { - return; // - } - // Position of the closing ')' - int endMacroOffset = lastContext.getOffset() - 1; - - Vector parameterValues = getMacroParameters(betweenTheBrackets, false); - Vector parameterValuesForStringizing = null; - SimpleToken t = null; - - // create a string that represents what needs to be tokenized - - IToken [] tokens = expansion.getTokenizedExpansion(); - String [] parameterNames = expansion.getParameters(); - - if (parameterNames.length != parameterValues.size()) - { - handleProblem( IProblem.PREPROCESSOR_MACRO_USAGE_ERROR, symbol, getCurrentOffset(), false, true ); - consumeUntilOutOfMacroExpansion(); - return; - } - - strbuff.startString(); - - int numberOfTokens = tokens.length; - - for (int i = 0; i < numberOfTokens; ++i) { - t = (SimpleToken) tokens[i]; - if (t.getType() == IToken.tIDENTIFIER) { - - // is this identifier in the parameterNames - // list? - int index = findIndex( parameterNames, t.getImage() ); - if (index == -1 ) { - // not found - // just add image to buffer - strbuff.append(t.getImage() ); - } else { - strbuff.append( - (String) parameterValues.elementAt(index) ); - } - } else if (t.getType() == tPOUND) { - //next token should be a parameter which needs to be turned into - //a string literal - if( parameterValuesForStringizing == null) - { - String cache = strbuff.toString(); - parameterValuesForStringizing = getMacroParameters(betweenTheBrackets, true); - strbuff.startString(); - strbuff.append(cache); - } - ++i; - if( tokens.length == i ){ - handleProblem( IProblem.PREPROCESSOR_MACRO_USAGE_ERROR, expansion.getName(), getCurrentOffset(), false, true ); - return; - } - - t = (SimpleToken) tokens[ i ]; - int index = findIndex( parameterNames, t.getImage()); - if( index == -1 ){ - handleProblem( IProblem.PREPROCESSOR_MACRO_USAGE_ERROR, expansion.getName(), getCurrentOffset(), false, true ); - return; - } - strbuff.append('\"'); - String value = (String)parameterValuesForStringizing.elementAt(index); - char val [] = value.toCharArray(); - char ch; - int length = value.length(); - for( int j = 0; j < length; j++ ){ - ch = val[j]; - if( ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n' ){ - //Each occurance of whitespace becomes a single space character - while( ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n' ){ - ch = val[++j]; - } - strbuff.append(' '); - } - //a \ character is inserted before each " and \ - if( ch == '\"' || ch == '\\' ){ - strbuff.append('\\'); - strbuff.append(ch); - } else { - strbuff.append(ch); - } - } - strbuff.append('\"'); - - } else { - switch( t.getType() ) - { - case IToken.tSTRING: - strbuff.append('\"'); - strbuff.append(t.getImage()); - strbuff.append('\"'); - break; - case IToken.tLSTRING: - strbuff.append("L\""); //$NON-NLS-1$ - strbuff.append(t.getImage()); - strbuff.append('\"'); - break; - case IToken.tCHAR: - strbuff.append('\''); - strbuff.append(t.getImage()); - strbuff.append('\''); - - break; - default: - strbuff.append(t.getImage()); - break; - } - } - - boolean pastingNext = false; - - if( i != numberOfTokens - 1) - { - IToken t2 = tokens[i+1]; - if( t2.getType() == tPOUNDPOUND ) { - pastingNext = true; - i++; - } - } - - if( t.getType() != tPOUNDPOUND && ! pastingNext ) - if (i < (numberOfTokens-1)) // Do not append to the last one - strbuff.append( ' ' ); - } - String finalString = strbuff.toString(); - try - { - contextStack.updateMacroContext( - finalString, - expansion.getName(), - requestor, - symbolOffset, - endMacroOffset - symbolOffset + 1 ); - } - catch (ContextException e) - { - handleProblem( e.getId(), currentContext.getContextName(), getCurrentOffset(), false, true ); - consumeUntilOutOfMacroExpansion(); - return; - } - } else - { - handleProblem( IProblem.PREPROCESSOR_MACRO_USAGE_ERROR, symbol, getCurrentOffset(), false, true ); - consumeUntilOutOfMacroExpansion(); - return; - } - - } - else { - TraceUtil.outputTrace(log, "Unexpected type of MacroDescriptor stored in definitions table: ", null, expansion.getMacroType().toString(), null, null); //$NON-NLS-1$ - } - - } - - /** - * @param parameterNames - * @param image - * @return - */ - private int findIndex(String[] parameterNames, String image) { - for( int i = 0; i < parameterNames.length; ++i ) - if( parameterNames[i].equals( image ) ) - return i; - - return -1; - } - - protected String handleDefinedMacro() throws ScannerException { - int o = getCurrentOffset(); - skipOverWhitespace(); - - int c = getChar(false); - - String definitionIdentifier = null; - if (c == '(') { - - definitionIdentifier = getNextIdentifier(); - skipOverWhitespace(); - c = getChar(false); - if (c != ')') - { - handleProblem( IProblem.PREPROCESSOR_MACRO_USAGE_ERROR, "defined()", o, false, true ); //$NON-NLS-1$ - return "0"; //$NON-NLS-1$ - } - } - else - { - ungetChar(c); - definitionIdentifier = getNextIdentifier(); - } - - if (getDefinition(definitionIdentifier) != null) - return "1"; //$NON-NLS-1$ - - return "0"; //$NON-NLS-1$ - } - - public void setThrowExceptionOnBadCharacterRead( boolean throwOnBad ){ - throwExceptionOnBadCharacterRead = throwOnBad; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.IScanner#setASTFactory(org.eclipse.cdt.internal.core.parser.ast.IASTFactory) - */ - public void setASTFactory(IASTFactory f) { - astFactory = f; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.IScanner#setOffsetBoundary(int) - */ - public void setOffsetBoundary(int offset) { - offsetLimit = offset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.IScanner#getDefinitions() - */ - public Map getDefinitions() { - return Collections.unmodifiableMap(definitions); - } - - /** - * @param b - */ - public void setOffsetLimitReached(boolean b) { - limitReached = b; - } - - protected boolean isLimitReached() - { - if( offsetLimit == NO_OFFSET_LIMIT ) return false; - return limitReached; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.IScanner#isOnTopContext() - */ - public boolean isOnTopContext() { - return ( currentContext.getKind() == IScannerContext.ContextKind.TOP ); - } /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.IFilenameProvider#getCurrentFilename() - */ - public char[] getCurrentFilename() { - return getCurrentFile().toCharArray(); - } - - - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - public String toString() { - StringBuffer buffer = new StringBuffer(); - buffer.append( "Scanner @"); //$NON-NLS-1$ - if( currentContext != null ) - buffer.append( currentContext.toString()); - else - buffer.append( "EOF"); //$NON-NLS-1$ - return buffer.toString(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.IFilenameProvider#getCurrentFileIndex() - */ - public int getCurrentFileIndex() { - return contextStack.getMostRelevantFileContextIndex(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.IFilenameProvider#getFilenameForIndex(int) - */ - public String getFilenameForIndex(int index) { - if( index < 0 ) return EMPTY_STRING; - return contextStack.getInclusionFilename(index); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getASTFactory() - */ - public IASTFactory getASTFactory() { - if( astFactory == null ) - astFactory = ParserFactory.createASTFactory( parserMode, language ); - return astFactory; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getBranchTracker() - */ - public BranchTracker getBranchTracker() { - return branches; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getInitialReader() - */ - public CodeReader getInitialReader() { - return reader; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getOriginalConfig() - */ - public IScannerInfo getOriginalConfig() { - return originalConfig; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getProblemFactory() - */ - public IProblemFactory getProblemFactory() { - return problemFactory; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getScanner() - */ - public IScanner getScanner() { - return this; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#setDefinitions(java.util.Map) - */ - public void setDefinitions(Map map) { - definitions = map; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#setIncludePathNames(java.util.List) - */ - public void setIncludePathNames(List includePathNames) { - this.includePathNames = includePathNames; - } - - public Map getFileCache() { - return fileCache; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContextInclusion.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContextInclusion.java deleted file mode 100644 index b68bfffc470..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContextInclusion.java +++ /dev/null @@ -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(); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContextMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContextMacro.java deleted file mode 100644 index a5e8d76d2c4..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContextMacro.java +++ /dev/null @@ -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(); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContextTop.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContextTop.java deleted file mode 100644 index 6016cfd4874..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContextTop.java +++ /dev/null @@ -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; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContextTopString.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContextTopString.java deleted file mode 100644 index c4e470485a4..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerContextTopString.java +++ /dev/null @@ -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(); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerStringBuffer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerStringBuffer.java deleted file mode 100644 index a1bdfb5f36c..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerStringBuffer.java +++ /dev/null @@ -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); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ExpressionEvaluator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ExpressionEvaluator.java index 4cecd76e8c5..ed82d3045bd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ExpressionEvaluator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ExpressionEvaluator.java @@ -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 */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/FunctionStyleMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/FunctionStyleMacro.java index ad05cddab9c..f732c45b5eb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/FunctionStyleMacro.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/FunctionStyleMacro.java @@ -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 */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GCCScannerExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GCCScannerExtension.java new file mode 100644 index 00000000000..55dd423577b --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GCCScannerExtension.java @@ -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 = "= 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 ) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerProblemFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerProblemFactory.java similarity index 98% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerProblemFactory.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerProblemFactory.java index 3f2f020e228..317edc48d3d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerProblemFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerProblemFactory.java @@ -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; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerUtility.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerUtility.java similarity index 88% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerUtility.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerUtility.java index 7aeb4d26720..60eb4babe83 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerUtility.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerUtility.java @@ -1,13 +1,14 @@ -/******************************************************************************* - * 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 +/********************************************************************** + * 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; + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.internal.core.parser.scanner2; import java.io.File; import java.util.Iterator; @@ -18,9 +19,10 @@ import org.eclipse.cdt.core.parser.ISourceElementRequestor; /** * @author jcamelon + * */ public class ScannerUtility { - + public static String reconcilePath(String originalPath ) { if( originalPath == null ) return null; originalPath = removeQuotes( originalPath ); @@ -105,7 +107,7 @@ public class ScannerUtility { return useIncludePaths; } - String getFilename() + public String getFilename() { return fileName; } @@ -124,5 +126,6 @@ public class ScannerUtility { public static class InclusionParseException extends Exception { } - + + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/AbstractToken.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/AbstractToken.java index 900968d90f9..bb5add0ecf0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/AbstractToken.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/AbstractToken.java @@ -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; /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/BasicTokenDuple.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/BasicTokenDuple.java index 410bde5028f..48ee0aa2f45 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/BasicTokenDuple.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/BasicTokenDuple.java @@ -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 diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/ImagedExpansionToken.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/ImagedExpansionToken.java index 52373dd7e64..9a8744f0e08 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/ImagedExpansionToken.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/ImagedExpansionToken.java @@ -11,23 +11,11 @@ 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 @@ -47,16 +35,7 @@ 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() */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/ImagedToken.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/ImagedToken.java index 50e24ebab42..8d8ea168735 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/ImagedToken.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/ImagedToken.java @@ -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); @@ -60,19 +47,7 @@ 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; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/SimpleExpansionToken.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/SimpleExpansionToken.java deleted file mode 100644 index a9a78b78ee6..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/SimpleExpansionToken.java +++ /dev/null @@ -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; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/SimpleToken.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/SimpleToken.java index 00be00a7eb6..b50e8605d88 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/SimpleToken.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/SimpleToken.java @@ -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(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/TokenFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/TokenFactory.java index 8bf56ea234f..be32cfc72ea 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/TokenFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/TokenFactory.java @@ -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 ) { diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java index 46f4d8bfeb3..79745aa4510 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java @@ -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,8 +607,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte } } catch (EndOfFileException e) { list.addLast( name.toCharArray() ); - } catch (ScannerException e) { - } + } return list; } diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java index 6d57dbb4a47..e051cb8d3c4 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java @@ -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; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java index fb1c8ea7d7c..c93028223e0 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java @@ -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;