Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/org.eclipse.cdt.core.tests/ChangeLog3
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java12
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseDOMTest.java8
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java8
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java6
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java8
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/LineNumberTest.java12
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java1
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PreprocessorTest.java345
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java16
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java9
-rw-r--r--core/org.eclipse.cdt.core.tests/resources/parser/TortureTest/.cvsignore1
-rw-r--r--core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/Name.java2
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java (renamed from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java)7
-rw-r--r--core/org.eclipse.cdt.core/parser/ChangeLog4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IPreprocessor.java (renamed from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserFactory.java)16
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java27
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IToken.java5
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java63
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserMode.java34
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTClassSpecifier.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java89
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Preprocessor.java50
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java83
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Token.java13
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTClassSpecifier.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTClassSpecifier.java2
-rw-r--r--core/org.eclipse.cdt.ui.tests/ChangeLog4
-rw-r--r--core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java14
-rw-r--r--core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/BaseDOMTest.java8
-rw-r--r--core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java9
-rw-r--r--core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java6
-rw-r--r--core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java8
-rw-r--r--core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/LineNumberTest.java12
-rw-r--r--core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java5
-rw-r--r--core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java7
-rw-r--r--core/org.eclipse.cdt.ui/ChangeLog4
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/ComparatorModelBuilder.java8
38 files changed, 686 insertions, 227 deletions
diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog
index 35fc8a774b..8e24b338a1 100644
--- a/core/org.eclipse.cdt.core.tests/ChangeLog
+++ b/core/org.eclipse.cdt.core.tests/ChangeLog
@@ -1,3 +1,6 @@
+2003-06-23 John Camelon
+ Factory/constructor signature updates.
+
2003-06-17 Victor Mozgin
Added MacroTests.java (invocation in AllCoreTests).
Added MacroTests.c to resources.
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java
index 4013302990..5fb2a2d67b 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java
@@ -14,6 +14,7 @@ package org.eclipse.cdt.core.parser.tests;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.InputStreamReader;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
@@ -21,7 +22,8 @@ import junit.framework.AssertionFailedError;
import junit.framework.Test;
import org.eclipse.cdt.core.parser.IParser;
-import org.eclipse.cdt.internal.core.parser.Parser;
+import org.eclipse.cdt.core.parser.ParserFactory;
+import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.core.runtime.Path;
@@ -51,12 +53,8 @@ public class AutomatedTest extends AutomatedFramework {
FileInputStream stream = new FileInputStream( file );
String filePath = file.getCanonicalPath();
- String nature = (String)natures.get( filePath );
-
- boolean cppNature = nature.equalsIgnoreCase("cpp");
-
- parser = new Parser( stream, nullCallback, true);
- parser.setCppNature( cppNature );
+ parser = ParserFactory.createParser( ParserFactory.createScanner( new InputStreamReader (stream), filePath, null, null, ParserMode.QUICK_PARSE ), nullCallback, ParserMode.QUICK_PARSE);
+ parser.setCppNature( ((String)natures.get( filePath )).equalsIgnoreCase("cpp") );
parser.mapLineNumbers(true);
assertTrue( parser.parse() );
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseDOMTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseDOMTest.java
index 715e37106d..6e298ef132 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseDOMTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseDOMTest.java
@@ -10,12 +10,15 @@
******************************************************************************/
package org.eclipse.cdt.core.parser.tests;
+import java.io.StringReader;
+
import junit.framework.TestCase;
import org.eclipse.cdt.core.parser.IParser;
+import org.eclipse.cdt.core.parser.ParserFactory;
+import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.internal.core.dom.DOMBuilder;
import org.eclipse.cdt.internal.core.dom.TranslationUnit;
-import org.eclipse.cdt.internal.core.parser.Parser;
import org.eclipse.cdt.internal.core.parser.ParserException;
/**
@@ -36,7 +39,8 @@ public class BaseDOMTest extends TestCase {
public TranslationUnit parse(String code, boolean quickParse, boolean throwOnError ) throws Exception {
DOMBuilder domBuilder = new DOMBuilder();
- IParser parser = new Parser(code, domBuilder, quickParse );
+ ParserMode mode = quickParse ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE;
+ IParser parser = ParserFactory.createParser(ParserFactory.createScanner( new StringReader( code ), null, null, null, mode ), domBuilder, mode );
if( ! parser.parse() )
if( throwOnError ) throw new ParserException( "Parse failure" );
else domBuilder.getTranslationUnit().setParseSuccessful( false );
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
index 954d2c208a..fc00630130 100644
--- 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
@@ -15,10 +15,11 @@ import java.io.StringReader;
import junit.framework.TestCase;
+import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.IToken;
+import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ScannerException;
import org.eclipse.cdt.internal.core.parser.Parser;
-import org.eclipse.cdt.internal.core.parser.Scanner;
/**
* @author jcamelon
@@ -26,7 +27,7 @@ import org.eclipse.cdt.internal.core.parser.Scanner;
*/
public class BaseScannerTest extends TestCase {
- protected Scanner scanner;
+ protected IScanner scanner;
public BaseScannerTest( String x )
{
@@ -35,8 +36,7 @@ public class BaseScannerTest extends TestCase {
public void initializeScanner(String input)
{
- scanner= new Scanner();
- scanner.initialize( new StringReader(input),"TEXT");
+ scanner= ParserFactory.createScanner( new StringReader(input),"TEXT", null, null, null );
}
public int fullyTokenize() throws Exception
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java
index 19a192d510..a01d9c5fb3 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java
@@ -1,12 +1,14 @@
package org.eclipse.cdt.core.parser.tests;
+import java.io.StringReader;
+
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.parser.IParser;
+import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.internal.core.parser.ExpressionEvaluator;
-import org.eclipse.cdt.internal.core.parser.Parser;
public class ExprEvalTest extends TestCase {
@@ -20,7 +22,7 @@ public class ExprEvalTest extends TestCase {
public void runTest(String code, int expectedValue) throws Exception {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
- IParser parser = new Parser(code, evaluator);
+ IParser parser = ParserFactory.createParser(ParserFactory.createScanner( new StringReader( code ), null, null, null, null ), evaluator, null);
parser.expression(null);
assertEquals(expectedValue, ((Integer)evaluator.getResult()).intValue());
}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java
index 8420c4d786..ec4e405dbf 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java
@@ -15,13 +15,16 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.StringReader;
import java.io.StringWriter;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import junit.framework.Test;
-import org.eclipse.cdt.internal.core.parser.Parser;
+import org.eclipse.cdt.core.parser.IParser;
+import org.eclipse.cdt.core.parser.ParserFactory;
+import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.core.runtime.Path;
/**
@@ -234,7 +237,8 @@ public class FractionalAutomatedTest extends AutomatedFramework {
public void run(){
try{
result = null;
- Parser parser = new Parser( code, nullCallback, true);
+ IParser parser = ParserFactory.createParser(
+ ParserFactory.createScanner( new StringReader( code ), null, null, null, ParserMode.QUICK_PARSE ), nullCallback, ParserMode.QUICK_PARSE);
parser.setCppNature( cppNature );
parser.mapLineNumbers(true);
parser.parse();
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/LineNumberTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/LineNumberTest.java
index 9c4d37e5e9..662fa4451f 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/LineNumberTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/LineNumberTest.java
@@ -13,14 +13,17 @@ package org.eclipse.cdt.core.parser.tests;
import java.io.FileInputStream;
import java.io.InputStream;
-import java.io.Reader;
+import java.io.InputStreamReader;
import java.io.StringReader;
import java.util.List;
import junit.framework.TestCase;
import org.eclipse.cdt.core.parser.IParser;
+import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.IToken;
+import org.eclipse.cdt.core.parser.ParserFactory;
+import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.internal.core.dom.ClassSpecifier;
import org.eclipse.cdt.internal.core.dom.DOMBuilder;
import org.eclipse.cdt.internal.core.dom.EnumerationSpecifier;
@@ -29,7 +32,6 @@ import org.eclipse.cdt.internal.core.dom.NamespaceDefinition;
import org.eclipse.cdt.internal.core.dom.SimpleDeclaration;
import org.eclipse.cdt.internal.core.dom.TemplateDeclaration;
import org.eclipse.cdt.internal.core.parser.Parser;
-import org.eclipse.cdt.internal.core.parser.Scanner;
import org.eclipse.core.runtime.Path;
/**
@@ -53,9 +55,7 @@ public class LineNumberTest extends TestCase {
public void testLineNos() throws Exception
{
- Scanner scanner = new Scanner();
- Reader reader = new StringReader( "int x = 3;\n foo\nfire\nfoe ");
- scanner.initialize( reader, "string");
+ IScanner scanner = ParserFactory.createScanner( new StringReader( "int x = 3;\n foo\nfire\nfoe " ), "string", null, null, null );
scanner.mapLineNumbers(true);
IToken t = scanner.nextToken();
assertEquals( t.getType(), IToken.t_int );
@@ -92,7 +92,7 @@ public class LineNumberTest extends TestCase {
public void testDOMLineNos() throws Exception
{
DOMBuilder domBuilder = new DOMBuilder();
- IParser parser = new Parser( fileIn, domBuilder, true );
+ IParser parser = ParserFactory.createParser( ParserFactory.createScanner( new InputStreamReader( fileIn ), null, null, null, ParserMode.QUICK_PARSE ), domBuilder, ParserMode.QUICK_PARSE );
parser.mapLineNumbers(true);
if( ! parser.parse() ) fail( "Parse of file failed");
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java
index 84c874c900..7c57daa85f 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java
@@ -33,6 +33,7 @@ public class ParserTestSuite extends TestCase {
suite.addTestSuite(ParserSymbolTableTest.class);
suite.addTestSuite(CModelElementsTests.class);
suite.addTestSuite(MacroTests.class);
+ suite.addTestSuite( PreprocessorTest.class );
return suite;
}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PreprocessorTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PreprocessorTest.java
new file mode 100644
index 0000000000..cdbf0c6209
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PreprocessorTest.java
@@ -0,0 +1,345 @@
+/**********************************************************************
+ * 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.core.parser.tests;
+
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.eclipse.cdt.core.parser.IPreprocessor;
+import org.eclipse.cdt.core.parser.IProblem;
+import org.eclipse.cdt.core.parser.ISourceElementRequestor;
+import org.eclipse.cdt.core.parser.ParserFactory;
+import org.eclipse.cdt.core.parser.ParserMode;
+import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
+import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
+import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
+import org.eclipse.cdt.core.parser.ast.IASTConstructor;
+import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
+import org.eclipse.cdt.core.parser.ast.IASTField;
+import org.eclipse.cdt.core.parser.ast.IASTFunction;
+import org.eclipse.cdt.core.parser.ast.IASTInclusion;
+import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification;
+import org.eclipse.cdt.core.parser.ast.IASTMacro;
+import org.eclipse.cdt.core.parser.ast.IASTMethod;
+import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
+import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
+import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation;
+import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization;
+import org.eclipse.cdt.core.parser.ast.IASTTypedef;
+import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
+import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
+import org.eclipse.cdt.core.parser.ast.IASTVariable;
+
+/**
+ * @author jcamelon
+ *
+ */
+public class PreprocessorTest extends TestCase {
+
+ public static class Callback implements ISourceElementRequestor
+ {
+ private List enteredInc = new ArrayList(), exitedInc = new ArrayList();
+
+ public boolean asExpected( int balance )
+ {
+ return( ( enteredInc.size() - exitedInc.size() ) == balance );
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptProblem(org.eclipse.cdt.core.parser.IProblem)
+ */
+ public void acceptProblem(IProblem problem) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMacro(org.eclipse.cdt.core.parser.ast.IASTMacro)
+ */
+ public void acceptMacro(IASTMacro macro) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptVariable(org.eclipse.cdt.core.parser.ast.IASTVariable)
+ */
+ public void acceptVariable(IASTVariable variable) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFunctionDeclaration(org.eclipse.cdt.core.parser.ast.IASTFunction)
+ */
+ public void acceptFunctionDeclaration(IASTFunction function) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsingDirective(org.eclipse.cdt.core.parser.ast.IASTUsingDirective)
+ */
+ public void acceptUsingDirective(IASTUsingDirective usageDirective) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsingDeclaration(org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration)
+ */
+ public void acceptUsingDeclaration(IASTUsingDeclaration usageDeclaration) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptASMDefinition(org.eclipse.cdt.core.parser.ast.IASTASMDefinition)
+ */
+ public void acceptASMDefinition(IASTASMDefinition asmDefinition) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTypedef(org.eclipse.cdt.core.parser.ast.IASTTypedef)
+ */
+ public void acceptTypedef(IASTTypedef typedef) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumerationSpecifier(org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier)
+ */
+ public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction)
+ */
+ public void enterFunctionBody(IASTFunction function) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction)
+ */
+ public void exitFunctionBody(IASTFunction function) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit)
+ */
+ public void enterCompilationUnit(IASTCompilationUnit compilationUnit) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion)
+ */
+ public void enterInclusion(IASTInclusion inclusion) {
+ enteredInc.add( inclusion );
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition)
+ */
+ public void enterNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier)
+ */
+ public void enterClassSpecifier(IASTClassSpecifier classSpecification) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification)
+ */
+ public void enterLinkageSpecification(IASTLinkageSpecification linkageSpec) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration)
+ */
+ public void enterTemplateDeclaration(IASTTemplateDeclaration declaration) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization)
+ */
+ public void enterTemplateSpecialization(IASTTemplateSpecialization specialization) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateExplicitInstantiation(org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation)
+ */
+ public void enterTemplateExplicitInstantiation(IASTTemplateInstantiation instantiation) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMethodDeclaration(org.eclipse.cdt.core.parser.ast.IASTMethod)
+ */
+ public void acceptMethodDeclaration(IASTMethod method) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod)
+ */
+ public void enterMethodBody(IASTMethod method) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod)
+ */
+ public void exitMethodBody(IASTMethod method) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptField(org.eclipse.cdt.core.parser.ast.IASTField)
+ */
+ public void acceptField(IASTField field) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptConstructor(org.eclipse.cdt.core.parser.ast.IASTConstructor)
+ */
+ public void acceptConstructor(IASTConstructor constructor) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptClassReference(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier, int)
+ */
+ public void acceptClassReference(IASTClassSpecifier classSpecifier, int referenceOffset) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration)
+ */
+ public void exitTemplateDeclaration(IASTTemplateDeclaration declaration) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization)
+ */
+ public void exitTemplateSpecialization(IASTTemplateSpecialization specialization) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateExplicitInstantiation(org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation)
+ */
+ public void exitTemplateExplicitInstantiation(IASTTemplateInstantiation instantiation) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification)
+ */
+ public void exitLinkageSpecification(IASTLinkageSpecification linkageSpec) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier)
+ */
+ public void exitClassSpecifier(IASTClassSpecifier classSpecification) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition)
+ */
+ public void exitNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion)
+ */
+ public void exitInclusion(IASTInclusion inclusion) {
+ exitedInc.add( inclusion );
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit)
+ */
+ public void exitCompilationUnit(IASTCompilationUnit compilationUnit) {
+ // TODO Auto-generated method stub
+
+ }
+ }
+
+ public PreprocessorTest( String name )
+ {
+ super( name );
+ }
+
+ public void testSimpleExample()
+ {
+ Callback c = new Callback();
+ IPreprocessor p = setupPreprocessor( "#include <stdio.h>",
+ null, // NOTE -- to demonstrate simple example, this should be set up with the info from the
+ // build properties
+ null, c );
+ p.process();
+ c.asExpected(0);
+ }
+
+ public IPreprocessor setupPreprocessor( String text, List includePaths, Map defns, ISourceElementRequestor rq )
+ {
+ IPreprocessor p = ParserFactory.createPreprocesor( new StringReader( text ), "test", defns, includePaths, ParserMode.COMPLETE_PARSE );
+ p.setRequestor( rq );
+ return p;
+ }
+}
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
index 397fcfc179..6265127742 100644
--- 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
@@ -6,6 +6,7 @@ import java.util.List;
import org.eclipse.cdt.core.parser.IMacroDescriptor;
import org.eclipse.cdt.core.parser.IToken;
+import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ScannerException;
import org.eclipse.cdt.internal.core.parser.Parser;
import org.eclipse.cdt.internal.core.parser.Token;
@@ -851,7 +852,7 @@ public class ScannerTestCase extends BaseScannerTest
try
{
initializeScanner( "#if X + 5 < 7\n int found = 1;\n#endif" );
- scanner.setQuickScan( true );
+ scanner.setMode( ParserMode.QUICK_PARSE );
validateToken( IToken.t_int );
validateIdentifier( "found" );
validateToken( IToken.tASSIGN );
@@ -868,7 +869,7 @@ public class ScannerTestCase extends BaseScannerTest
try
{
initializeScanner( "#if 0\n int error = 666;\n#endif" );
- scanner.setQuickScan( true );
+ scanner.setMode( ParserMode.COMPLETE_PARSE );
validateEOF();
}
catch( ScannerException se )
@@ -905,11 +906,7 @@ public class ScannerTestCase extends BaseScannerTest
initializeScanner("#include <Windows.h>");
prepareForWindowsH();
int count= fullyTokenize();
- if (verbose)
- System.out.println(
- "For Windows.h, Scanner produced "
- + scanner.getCount()
- + " tokens");
+
validateBalance();
}
@@ -919,11 +916,6 @@ public class ScannerTestCase extends BaseScannerTest
prepareForWindowsRH();
validateEOF();
validateBalance();
- if (verbose)
- System.out.println(
- "For WinUser.rh, Scanner produced "
- + scanner.getCount()
- + " tokens");
}
}
catch (Exception e)
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java
index 3950b534a8..41a2ee0336 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java
@@ -14,6 +14,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.StringReader;
import java.io.StringWriter;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
@@ -22,8 +23,9 @@ import junit.framework.AssertionFailedError;
import junit.framework.Test;
import org.eclipse.cdt.core.parser.IParser;
+import org.eclipse.cdt.core.parser.ParserFactory;
+import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.internal.core.dom.DOMBuilder;
-import org.eclipse.cdt.internal.core.parser.Parser;
import org.eclipse.core.runtime.Path;
@@ -200,8 +202,9 @@ public class TortureTest extends FractionalAutomatedTest {
public void run(){
try {
DOMBuilder domBuilder = new DOMBuilder();
- parser = new Parser(code.toString(), domBuilder, quickParse);
-
+ IParser parser = ParserFactory.createParser(
+ ParserFactory.createScanner( new StringReader( code ), null, null, null, ParserMode.QUICK_PARSE ), nullCallback, ParserMode.QUICK_PARSE);
+
parser.setCppNature(cppNature);
parser.mapLineNumbers(true);
diff --git a/core/org.eclipse.cdt.core.tests/resources/parser/TortureTest/.cvsignore b/core/org.eclipse.cdt.core.tests/resources/parser/TortureTest/.cvsignore
new file mode 100644
index 0000000000..813113959c
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/resources/parser/TortureTest/.cvsignore
@@ -0,0 +1 @@
+TortureTest.properties \ No newline at end of file
diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/Name.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/Name.java
index 6448e89afa..0fd726d5f3 100644
--- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/Name.java
+++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/Name.java
@@ -35,7 +35,7 @@ public class Name {
}
public String toString() {
- Token t = nameStart;
+ IToken t = nameStart;
StringBuffer buffer = new StringBuffer();
buffer.append( t.getImage() );
if( t.getType() == IToken.t_operator )
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java
index 85a4b115a0..3f281f5e09 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java
@@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.model;
* Rational Software - initial implementation
******************************************************************************/
+import java.io.StringReader;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -25,6 +26,8 @@ import org.eclipse.cdt.core.model.IStructure;
import org.eclipse.cdt.core.model.ITemplate;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.IParser;
+import org.eclipse.cdt.core.parser.ParserFactory;
+import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.internal.core.dom.ArrayQualifier;
import org.eclipse.cdt.internal.core.dom.ClassKey;
import org.eclipse.cdt.internal.core.dom.ClassSpecifier;
@@ -50,7 +53,6 @@ import org.eclipse.cdt.internal.core.dom.TemplateParameter;
import org.eclipse.cdt.internal.core.dom.TranslationUnit;
import org.eclipse.cdt.internal.core.dom.TypeSpecifier;
import org.eclipse.cdt.internal.core.parser.Name;
-import org.eclipse.cdt.internal.core.parser.Parser;
import org.eclipse.core.resources.IProject;
@@ -68,8 +70,7 @@ public class CModelBuilder {
// Note - if a CModel client wishes to have a CModel with valid line numbers
// DOMFactory.createDOMBuilder should be given the parameter 'true'
DOMBuilder domBuilder = new DOMBuilder();
- String code = translationUnit.getBuffer().getContents();
- IParser parser = new Parser(code, domBuilder, true);
+ IParser parser = ParserFactory.createParser(ParserFactory.createScanner( new StringReader( translationUnit.getBuffer().getContents() ), null, null, null, ParserMode.QUICK_PARSE ), domBuilder, ParserMode.QUICK_PARSE);
parser.mapLineNumbers(requiresLineNumbers);
if( translationUnit.getCProject() != null )
{
diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog
index ef6705a2f1..445dfb5cf6 100644
--- a/core/org.eclipse.cdt.core/parser/ChangeLog
+++ b/core/org.eclipse.cdt.core/parser/ChangeLog
@@ -1,3 +1,7 @@
+2003-06-23 John Camelon
+ Updated Factory infrastructure, constructors, etc.
+ Introduced Preprocessor class for transitive closure calc. client.
+
2003-06-20 Victor Mozgin
Fixed PR 36463 : Offsets of macros are incorrect.
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IPreprocessor.java
index e97c8b7786..9a023f51dd 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IPreprocessor.java
@@ -8,23 +8,15 @@
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
-package org.eclipse.cdt.internal.core.parser;
+package org.eclipse.cdt.core.parser;
-import org.eclipse.cdt.core.parser.ast.IASTFactory;
-import org.eclipse.cdt.internal.core.parser.ast.full.FullParseASTFactory;
-import org.eclipse.cdt.internal.core.parser.ast.quick.QuickParseASTFactory;
/**
* @author jcamelon
*
*/
-public class ParserFactory {
+public interface IPreprocessor extends IScanner {
+
+ public void process();
- public static IASTFactory createASTFactory( boolean quickParse )
- {
- if( quickParse )
- return new QuickParseASTFactory();
- else
- return new FullParseASTFactory();
- }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java
index aa4b268cda..c1e057fd61 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java
@@ -1,6 +1,5 @@
package org.eclipse.cdt.core.parser;
-import java.io.Reader;
import java.util.List;
import org.eclipse.cdt.core.parser.ast.IASTFactory;
@@ -10,27 +9,37 @@ import org.eclipse.cdt.internal.core.parser.Parser;
* @author jcamelon
*
*/
-public interface IScanner {
-
+public interface IScanner {
+
public static final int tPOUNDPOUND = -6;
public static final int tPOUND = -7;
- public IScanner initialize( Reader sourceToBeRead, String fileName );
-
+ public void setASTFactory( IASTFactory f );
public void addDefinition(String key, IMacroDescriptor macroToBeAdded );
public void addDefinition(String key, String value);
public Object getDefinition(String key);
-
+
public Object[] getIncludePaths();
public void addIncludePath(String includePath);
public void overwriteIncludePath( List newIncludePaths );
+ public void setRequestor( ISourceElementRequestor r );
public IToken nextToken() throws ScannerException, Parser.EndOfFile;
+ public IToken nextToken( boolean next ) throws ScannerException, Parser.EndOfFile;
public int getLineNumberForOffset(int offset) throws NoSuchMethodException;
public void setCppNature( boolean value );
public void mapLineNumbers( boolean value );
- public void setQuickScan(boolean qs);
+ public void setMode(ParserMode mode);
public void setCallback(IParserCallback c);
- public void setRequestor( ISourceElementRequestor r );
- public void setASTFactory( IASTFactory f );
+
+ public int getCount();
+ public int getDepth();
+ /**
+ * @return
+ */
+ public IToken nextTokenForStringizing() throws ScannerException, Parser.EndOfFile;
+ /**
+ * @param b
+ */
+ public void setTokenizingMacroReplacementList(boolean b);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IToken.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IToken.java
index 5e0182abbd..8bcae4c984 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IToken.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IToken.java
@@ -20,12 +20,13 @@ public interface IToken {
public abstract String toString();
public abstract int getType();
public abstract String getImage();
+ public void setImage( String i );
public abstract int getOffset();
public abstract int getLength();
public abstract int getEndOffset();
public abstract int getDelta(IToken other);
- public abstract Token getNext();
- public abstract void setNext(Token t);
+ public abstract IToken getNext();
+ public abstract void setNext(IToken t);
public abstract boolean looksLikeExpression();
public abstract boolean isPointer();
public abstract boolean isOperator();
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java
new file mode 100644
index 0000000000..cbce06a607
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java
@@ -0,0 +1,63 @@
+/**********************************************************************
+ * 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.core.parser;
+
+import java.io.Reader;
+import java.util.Map;
+import java.util.List;
+
+import org.eclipse.cdt.core.parser.ast.IASTFactory;
+import org.eclipse.cdt.internal.core.parser.NullSourceElementRequestor;
+import org.eclipse.cdt.internal.core.parser.Parser;
+import org.eclipse.cdt.internal.core.parser.Preprocessor;
+import org.eclipse.cdt.internal.core.parser.Scanner;
+import org.eclipse.cdt.internal.core.parser.ast.full.FullParseASTFactory;
+import org.eclipse.cdt.internal.core.parser.ast.quick.QuickParseASTFactory;
+
+/**
+ * @author jcamelon
+ *
+ */
+public class ParserFactory {
+
+ public static IASTFactory createASTFactory( ParserMode mode )
+ {
+ if( mode == ParserMode.QUICK_PARSE )
+ return new QuickParseASTFactory();
+ else
+ return new FullParseASTFactory();
+ }
+
+ public static IParser createParser( IScanner scanner, IParserCallback callback, ParserMode mode )
+ {
+ ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode );
+ IParserCallback ourCallback = (( callback == null) ? new NullSourceElementRequestor() : callback );
+ return new Parser( scanner, ourCallback, ourMode );
+ }
+
+ public static IScanner createScanner( Reader input, String fileName, Map defns, List inclusions, ParserMode mode )
+ {
+ ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode );
+ IScanner s = new Scanner( input, fileName, defns );
+ s.setMode( ourMode );
+ s.overwriteIncludePath(inclusions);
+ return s;
+ }
+
+ public static IPreprocessor createPreprocesor( Reader input, String fileName, Map defns, List inclusions, ParserMode mode )
+ {
+ ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode );
+ IPreprocessor s = new Preprocessor( input, fileName, defns );
+ s.setMode( ourMode );
+ s.overwriteIncludePath(inclusions);
+ return s;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserMode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserMode.java
new file mode 100644
index 0000000000..ed5e666875
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserMode.java
@@ -0,0 +1,34 @@
+/**********************************************************************
+ * 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.core.parser;
+
+/**
+ * @author jcamelon
+ *
+ */
+public class ParserMode {
+
+ // follow inclusions, parse function/method bodies
+ public static final ParserMode COMPLETE_PARSE = new ParserMode( 1 );
+
+ // follow inclusions, do not parse function/method bodies
+ public static final ParserMode STRUCTURAL_PARSE = new ParserMode( 2 );
+
+ // do not follow inclusions, do not parse function/method bodies
+ public static final ParserMode QUICK_PARSE = new ParserMode( 3 );
+
+ private ParserMode( int value )
+ {
+ this.value = value;
+ }
+
+ private final int value;
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTClassSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTClassSpecifier.java
index c73597c29a..d82d9a24a1 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTClassSpecifier.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTClassSpecifier.java
@@ -24,6 +24,6 @@ public interface IASTClassSpecifier extends IASTTypeSpecifier, IASTScope, IASTOf
public Iterator getBaseClauses();
- public AccessVisibility getCurrentVisiblity();
+ public AccessVisibility getCurrentVisibilityMode();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java
index 42d378dcae..4e9a352b71 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java
@@ -11,15 +11,13 @@
package org.eclipse.cdt.internal.core.parser;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.StringReader;
-
import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IParserCallback;
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.ParserFactory;
+import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ScannerException;
import org.eclipse.cdt.core.parser.ast.AccessVisibility;
import org.eclipse.cdt.core.parser.ast.ClassKind;
@@ -49,7 +47,7 @@ public class Parser implements IParser {
private static int DEFAULT_OFFSET = -1; // sentinel initial value for offsets
private int firstErrorOffset = DEFAULT_OFFSET; // offset where the first parse error occurred
private IParserCallback callback; // the parser callback that was registered with us
- private boolean quickParse = false; // are we doing the high-level parse, or an in depth parse?
+ private ParserMode mode = ParserMode.COMPLETE_PARSE; // are we doing the high-level parse, or an in depth parse?
private boolean parsePassed = true; // did the parse pass?
private boolean cppNature = true; // true for C++, false for C
private ISourceElementRequestor requestor = null; // new callback mechanism
@@ -77,86 +75,18 @@ public class Parser implements IParser {
* @param c IParserCallback instance that will receive callbacks as we parse
* @param quick Are we asking for a high level parse or not?
*/
- public Parser(IScanner s, IParserCallback c, boolean quick) {
+ public Parser(IScanner s, IParserCallback c, ParserMode m) {
callback = c;
scanner = s;
if( c instanceof ISourceElementRequestor )
setRequestor( (ISourceElementRequestor)c );
- quickParse = quick;
- astFactory = ParserFactory.createASTFactory( quick );
- scanner.setQuickScan(quick);
+ mode = m;
+ astFactory = ParserFactory.createASTFactory( m );
+ scanner.setMode( m );
scanner.setCallback(c);
scanner.setASTFactory( astFactory );
}
-
- /**
- * An additional constructor provided for ease of use and tezting.
- *
- * @param s IScanner instance that has been initialized to the code input
- * @param c IParserCallback instance that will receive callbacks as we parse
- */
- public Parser(IScanner s, IParserCallback c) {
- this(s, c, false);
- }
-
- /**
- * An additional constructor provided for ease of use and tezting.
- *
- * @param s IScanner instance that has been initialized to the code input
- */
- public Parser( IScanner s) {
- this(s, new NullSourceElementRequestor(), false);
- }
-
-
- /**
- * An additional constructor provided for ease of use and tezting.
- *
- * * @param code The code that we wish to parse
- */
- public Parser(String code) {
- this(new Scanner().initialize( new StringReader( code ), null
-));
- }
-
- /**
- * An additional constructor provided for ease of use and tezting.
- *
- * @param code The code that we wish to parse
- * @param c IParserCallback instance that will receive callbacks as we parse
- */
- public Parser(String code, IParserCallback c) {
- this(new Scanner().initialize( new StringReader( code ), null
-), c, false);
- }
-
-
- /**
- * An additional constructor provided for ease of use and tezting.
- *
- * @param code The code that we wish to parse
- * @param c IParserCallback instance that will receive callbacks as we parse
- * @param quickParse Are we asking for a high level parse or not?
- */
- public Parser(String code, IParserCallback c, boolean quickParse ) {
- this(new Scanner().initialize( new StringReader( code ), null
-), c, quickParse);
- }
-
-
- /**
- * An additional constructor provided for ease of use and tezting.
- *
- * @param stream An InputStream represnting the code that we wish to parse
- * @param c IParserCallback instance that will receive callbacks as we parse
- * @param quickParse Are we asking for a high level parse or not?
- */
- public Parser(InputStream stream, IParserCallback c, boolean quickParse) {
- this(new Scanner().initialize( new InputStreamReader(stream), null ),
-c, quickParse);
- }
-
private static int parseCount = 0; // counter that keeps track of the number of times Parser.parse() is called
@@ -788,7 +718,8 @@ c, quickParse);
if (forKR) throw backtrack;
Object function = null;
try{ function = callback.functionBodyBegin(simpleDecl ); } catch( Exception e ) {}
- if (quickParse) {
+
+ if ( mode == ParserMode.QUICK_PARSE ) {
// speed up the parser by skiping the body
// simply look for matching brace and return
consume(IToken.tLBRACE);
@@ -868,7 +799,7 @@ c, quickParse);
catch( Backtrack bt )
{
try { callback.constructorChainAbort( constructorChain );} catch( Exception e ) {}
- if( ! quickParse )
+ if( mode != ParserMode.QUICK_PARSE )
throw backtrack;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Preprocessor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Preprocessor.java
new file mode 100644
index 0000000000..52c47b7246
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Preprocessor.java
@@ -0,0 +1,50 @@
+/**********************************************************************
+ * 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;
+
+import java.io.Reader;
+import java.util.Map;
+
+import org.eclipse.cdt.core.parser.IPreprocessor;
+import org.eclipse.cdt.core.parser.ScannerException;
+
+/**
+ * @author jcamelon
+ *
+ */
+public class Preprocessor extends Scanner implements IPreprocessor {
+
+ /**
+ * @param reader
+ * @param filename
+ * @param defns
+ */
+ public Preprocessor(Reader reader, String filename, Map defns) {
+ super(reader, filename, defns);
+ }
+
+ public void process()
+ {
+ try
+ {
+ while( true )
+ nextToken();
+ }
+ catch( ScannerException se )
+ {
+ // callback IProblem here
+ }
+ catch( Parser.EndOfFile eof )
+ {
+ // expected
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java
index d3b58691a3..2f46fd66b4 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java
@@ -21,6 +21,7 @@ import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector;
@@ -31,6 +32,8 @@ import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.IScannerContext;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.IToken;
+import org.eclipse.cdt.core.parser.ParserFactory;
+import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ScannerException;
import org.eclipse.cdt.core.parser.ast.IASTFactory;
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
@@ -44,12 +47,7 @@ import org.eclipse.cdt.core.parser.ast.IASTMacro;
public class Scanner implements IScanner {
- public IScanner initialize(Reader reader, String filename) {
- init(reader, filename);
- return this;
- }
-
- protected void init(Reader reader, String filename) {
+ public Scanner(Reader reader, String filename, Map defns) {
try {
//this is a hack to get around a sudden EOF experience
contextStack.push(
@@ -65,14 +63,8 @@ public class Scanner implements IScanner {
} catch( ScannerException se ) {
//won't happen since we aren't adding an include or a macro
}
- }
-
- public Scanner() {
- }
-
- protected Scanner(Reader reader, String filename, Hashtable defns) {
- initialize(reader, filename);
- definitions = defns;
+ if( defns != null )
+ definitions.putAll( defns );
}
@@ -83,6 +75,7 @@ public class Scanner implements IScanner {
}
public void overwriteIncludePath(List newIncludePaths) {
+ if( newIncludePaths == null ) return;
includePathNames = null;
includePaths = null;
includePathNames = new ArrayList();
@@ -223,7 +216,7 @@ public class Scanner implements IScanner {
}
}
- private void setCurrentToken(Token t) {
+ private void setCurrentToken(IToken t) {
if (currentToken != null)
currentToken.setNext(t);
currentToken = t;
@@ -235,12 +228,12 @@ public class Scanner implements IScanner {
storageBuffer = null;
}
- protected Token newToken(int t, String i, IScannerContext c) {
+ protected IToken newToken(int t, String i, IScannerContext c) {
setCurrentToken(new Token(t, i, c));
return currentToken;
}
- protected Token newToken(int t, String i) {
+ protected IToken newToken(int t, String i) {
setCurrentToken(new Token(t, i));
return currentToken;
}
@@ -345,8 +338,8 @@ public class Scanner implements IScanner {
private static HashMap cKeywords = new HashMap();
private static HashMap ppDirectives = new HashMap();
- private Token currentToken = null;
- private Token cachedToken = null;
+ private IToken currentToken = null;
+ private IToken cachedToken = null;
private boolean passOnToClient = true;
private BranchTracker branches = new BranchTracker();
@@ -368,9 +361,10 @@ public class Scanner implements IScanner {
tokenizingMacroReplacementList = mr;
}
- private boolean quickScan = false;
- public void setQuickScan(boolean qs) {
- quickScan = qs;
+ private ParserMode mode = ParserMode.COMPLETE_PARSE;
+
+ public void setMode(ParserMode mode) {
+ this.mode = mode;
}
private IParserCallback callback;
@@ -485,7 +479,7 @@ public class Scanner implements IScanner {
}
- protected Token nextToken( boolean pasting ) throws ScannerException, Parser.EndOfFile
+ public IToken nextToken( boolean pasting ) throws ScannerException, Parser.EndOfFile
{
if( cachedToken != null ){
setCurrentToken( cachedToken );
@@ -569,16 +563,16 @@ public class Scanner implements IScanner {
//If the next token is going to be a string as well, we need to concatenate
//it with this token.
- Token returnToken = newToken( type, buff.toString(), contextStack.getCurrentContext());
- Token next = null;
+ IToken returnToken = newToken( type, buff.toString(), contextStack.getCurrentContext());
+ IToken next = null;
try{
next = nextToken( true );
} catch( Parser.EndOfFile e ){
next = null;
}
- while( next != null && next.type == returnToken.type ){
- returnToken.image += next.image;
+ while( next != null && next.getType() == returnToken.getType() ){
+ returnToken.setImage( returnToken.getImage() + next.getImage() );
returnToken.setNext( null );
currentToken = returnToken;
try{
@@ -895,7 +889,7 @@ public class Scanner implements IScanner {
// definition
String toBeUndefined = getNextIdentifier();
- if( ( definitions.remove(toBeUndefined) == null ) && ! quickScan )
+ if( ( definitions.remove(toBeUndefined) == null ) && mode == ParserMode.COMPLETE_PARSE )
throw new ScannerException( "Attempt to #undef symbol " + toBeUndefined + " when it was never defined");
skipOverTextUntilNewline();
@@ -993,7 +987,7 @@ public class Scanner implements IScanner {
String error = getRestOfPreprocessorLine();
- if (!quickScan) {
+ if (mode == ParserMode.COMPLETE_PARSE) {
throw new ScannerException("#error " + error);
}
c = getChar();
@@ -1379,7 +1373,7 @@ public class Scanner implements IScanner {
// the static instance we always use
protected static endOfMacroTokenException endOfMacroToken = new endOfMacroTokenException();
- protected IToken nextTokenForStringizing() throws ScannerException, Parser.EndOfFile
+ public IToken nextTokenForStringizing() throws ScannerException, Parser.EndOfFile
{
int c = getChar();
StringBuffer tokenImage = new StringBuffer();
@@ -1648,7 +1642,7 @@ public class Scanner implements IScanner {
protected boolean evaluateExpression(String expression )
throws ScannerException {
- if( quickScan )
+ if( mode == ParserMode.QUICK_PARSE )
{
if( expression.trim().equals( "0" ) )
return false;
@@ -1659,13 +1653,13 @@ public class Scanner implements IScanner {
Object expressionEvalResult = null;
try {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
- Scanner trial =
- new Scanner(
- // Semicolon makes this valid C (hopefully)
+ IScanner trial =
+ ParserFactory.createScanner(
new StringReader(expression + ";"),
EXPRESSION,
- definitions);
- IParser parser = new Parser(trial, evaluator);
+ definitions,
+ null, ParserMode.COMPLETE_PARSE );
+ IParser parser = ParserFactory.createParser(trial, evaluator, ParserMode.COMPLETE_PARSE );
parser.expression(null);
expressionEvalResult = evaluator.getResult();
@@ -1792,7 +1786,7 @@ public class Scanner implements IScanner {
String f = fileName.toString();
offset = contextStack.getCurrentContext().getOffset() - f.length() - 1; // -1 for the end quote
- if( quickScan )
+ if( mode == ParserMode.QUICK_PARSE )
{
if( callback != null )
{
@@ -1818,7 +1812,7 @@ public class Scanner implements IScanner {
String key = getNextIdentifier();
int offset = contextStack.getCurrentContext().getOffset() - key.length() - contextStack.getCurrentContext().undoStackSize();
- if (!quickScan) {
+ if (mode == ParserMode.COMPLETE_PARSE) {
String checkForRedefinition = (String) definitions.get(key);
if (checkForRedefinition != null) {
throw new ScannerException(
@@ -1884,21 +1878,18 @@ public class Scanner implements IScanner {
if( ! replacementString.equals( "" ) )
{
- Scanner helperScanner = new Scanner();
- helperScanner.initialize(
- new StringReader(replacementString),
- null);
+ IScanner helperScanner = ParserFactory.createScanner( new StringReader(replacementString), null, null, null, mode );
helperScanner.setTokenizingMacroReplacementList( true );
- Token t = helperScanner.nextToken(false);
+ IToken t = helperScanner.nextToken(false);
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.type == tPOUND ){
+ if( t.getType() == tPOUND ){
macroReplacementTokens.add( t );
t = helperScanner.nextToken(false);
- int index = parameterIdentifiers.indexOf(t.image);
+ int index = parameterIdentifiers.indexOf(t.getImage());
if (index == -1 ) {
//not found
if (throwExceptionOnBadPreprocessorSyntax)
@@ -1985,7 +1976,7 @@ public class Scanner implements IScanner {
protected Vector getMacroParameters (String params, boolean forStringizing) throws ScannerException {
- Scanner tokenizer = new Scanner(new StringReader(params), TEXT, definitions);
+ IScanner tokenizer = ParserFactory.createScanner(new StringReader(params), TEXT, definitions, null, mode );
Vector parameterValues = new Vector();
Token t = null;
String str = new String();
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Token.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Token.java
index 38415c4c8f..83e1edc70c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Token.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Token.java
@@ -61,9 +61,9 @@ public class Token implements IToken {
return other.getOffset() + other.getLength() - getOffset();
}
- private Token next;
- public Token getNext() { return next; }
- public void setNext(Token t) { next = t; }
+ private IToken next;
+ public IToken getNext() { return next; }
+ public void setNext(IToken t) { next = t; }
public boolean looksLikeExpression()
{
@@ -141,4 +141,11 @@ public class Token implements IToken {
}
}
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.IToken#setImage()
+ */
+ public void setImage( String i ) {
+ image = i;
+ }
+
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTClassSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTClassSpecifier.java
index 1fda98aabb..e3ac4d8cb2 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTClassSpecifier.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTClassSpecifier.java
@@ -138,7 +138,7 @@ public class ASTClassSpecifier implements IASTFClassSpecifier, IPSTSymbolExtensi
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTClassSpecifier#getCurrentVisiblity()
*/
- public AccessVisibility getCurrentVisiblity() {
+ public AccessVisibility getCurrentVisibilityMode() {
// TODO Auto-generated method stub
return null;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTClassSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTClassSpecifier.java
index 86e220d85e..ed8a5e56e4 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTClassSpecifier.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTClassSpecifier.java
@@ -76,7 +76,7 @@ public class ASTClassSpecifier extends ASTDeclaration implements IASTQClassSpeci
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTClassSpecifier#getCurrentVisiblity()
*/
- public AccessVisibility getCurrentVisiblity() {
+ public AccessVisibility getCurrentVisibilityMode() {
return access;
}
diff --git a/core/org.eclipse.cdt.ui.tests/ChangeLog b/core/org.eclipse.cdt.ui.tests/ChangeLog
index f10cfa8fe1..17890c59c6 100644
--- a/core/org.eclipse.cdt.ui.tests/ChangeLog
+++ b/core/org.eclipse.cdt.ui.tests/ChangeLog
@@ -1,3 +1,7 @@
+2003-06-23 John Camelon
+ Updated Factory infrastructure, constructors, etc.
+ Introduced Preprocessor class for transitive closure calc. client.
+
2003-06-20 Sean Evoy
Moved the ManagedBuildInfo extension point to the plugin file in org.eclipse.cdt.core.tests
diff --git a/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java b/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java
index 030dc584af..6abe3a34f5 100644
--- a/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java
+++ b/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java
@@ -14,6 +14,7 @@ package org.eclipse.cdt.core.parser.tests;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.InputStreamReader;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
@@ -21,7 +22,8 @@ import junit.framework.AssertionFailedError;
import junit.framework.Test;
import org.eclipse.cdt.core.parser.IParser;
-import org.eclipse.cdt.internal.core.parser.Parser;
+import org.eclipse.cdt.core.parser.ParserFactory;
+import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.core.runtime.Path;
@@ -51,14 +53,10 @@ public class AutomatedTest extends AutomatedFramework {
FileInputStream stream = new FileInputStream( file );
String filePath = file.getCanonicalPath();
- String nature = (String)natures.get( filePath );
-
- boolean cppNature = nature.equalsIgnoreCase("cpp");
-
- parser = new Parser( stream, nullCallback, true);
- parser.setCppNature( cppNature );
+ parser = ParserFactory.createParser( ParserFactory.createScanner( new InputStreamReader (stream), filePath, null, null, ParserMode.QUICK_PARSE ), nullCallback, ParserMode.QUICK_PARSE);
+ parser.setCppNature( ((String)natures.get( filePath )).equalsIgnoreCase("cpp") );
parser.mapLineNumbers(true);
-
+
assertTrue( parser.parse() );
}
catch( Throwable e )
diff --git a/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/BaseDOMTest.java b/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/BaseDOMTest.java
index 715e37106d..6e298ef132 100644
--- a/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/BaseDOMTest.java
+++ b/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/BaseDOMTest.java
@@ -10,12 +10,15 @@
******************************************************************************/
package org.eclipse.cdt.core.parser.tests;
+import java.io.StringReader;
+
import junit.framework.TestCase;
import org.eclipse.cdt.core.parser.IParser;
+import org.eclipse.cdt.core.parser.ParserFactory;
+import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.internal.core.dom.DOMBuilder;
import org.eclipse.cdt.internal.core.dom.TranslationUnit;
-import org.eclipse.cdt.internal.core.parser.Parser;
import org.eclipse.cdt.internal.core.parser.ParserException;
/**
@@ -36,7 +39,8 @@ public class BaseDOMTest extends TestCase {
public TranslationUnit parse(String code, boolean quickParse, boolean throwOnError ) throws Exception {
DOMBuilder domBuilder = new DOMBuilder();
- IParser parser = new Parser(code, domBuilder, quickParse );
+ ParserMode mode = quickParse ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE;
+ IParser parser = ParserFactory.createParser(ParserFactory.createScanner( new StringReader( code ), null, null, null, mode ), domBuilder, mode );
if( ! parser.parse() )
if( throwOnError ) throw new ParserException( "Parse failure" );
else domBuilder.getTranslationUnit().setParseSuccessful( false );
diff --git a/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java b/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java
index 954d2c208a..1dc4dd5e33 100644
--- a/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java
+++ b/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java
@@ -15,10 +15,12 @@ import java.io.StringReader;
import junit.framework.TestCase;
+import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.IToken;
+import org.eclipse.cdt.core.parser.ParserFactory;
+import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ScannerException;
import org.eclipse.cdt.internal.core.parser.Parser;
-import org.eclipse.cdt.internal.core.parser.Scanner;
/**
* @author jcamelon
@@ -26,7 +28,7 @@ import org.eclipse.cdt.internal.core.parser.Scanner;
*/
public class BaseScannerTest extends TestCase {
- protected Scanner scanner;
+ protected IScanner scanner;
public BaseScannerTest( String x )
{
@@ -35,8 +37,7 @@ public class BaseScannerTest extends TestCase {
public void initializeScanner(String input)
{
- scanner= new Scanner();
- scanner.initialize( new StringReader(input),"TEXT");
+ scanner= ParserFactory.createScanner( new StringReader(input),"TEXT", null, null, ParserMode.COMPLETE_PARSE );
}
public int fullyTokenize() throws Exception
diff --git a/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java b/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java
index 19a192d510..59d8f2ce6a 100644
--- a/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java
+++ b/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java
@@ -1,12 +1,14 @@
package org.eclipse.cdt.core.parser.tests;
+import java.io.StringReader;
+
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.parser.IParser;
+import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.internal.core.parser.ExpressionEvaluator;
-import org.eclipse.cdt.internal.core.parser.Parser;
public class ExprEvalTest extends TestCase {
@@ -20,7 +22,7 @@ public class ExprEvalTest extends TestCase {
public void runTest(String code, int expectedValue) throws Exception {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
- IParser parser = new Parser(code, evaluator);
+ IParser parser = ParserFactory.createParser(ParserFactory.createScanner( new StringReader( code ), null, null, null, null ), evaluator, null);;
parser.expression(null);
assertEquals(expectedValue, ((Integer)evaluator.getResult()).intValue());
}
diff --git a/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java b/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java
index f93fd8faf3..034e2d29b6 100644
--- a/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java
+++ b/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java
@@ -15,13 +15,16 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.StringReader;
import java.io.StringWriter;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import junit.framework.Test;
-import org.eclipse.cdt.internal.core.parser.Parser;
+import org.eclipse.cdt.core.parser.IParser;
+import org.eclipse.cdt.core.parser.ParserFactory;
+import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.core.runtime.Path;
/**
@@ -234,7 +237,8 @@ public class FractionalAutomatedTest extends AutomatedFramework {
public void run(){
try{
result = null;
- Parser parser = new Parser( code, nullCallback, true);
+ IParser parser = ParserFactory.createParser(
+ ParserFactory.createScanner( new StringReader( code ), null, null, null, ParserMode.QUICK_PARSE ), nullCallback, ParserMode.QUICK_PARSE);
parser.setCppNature( cppNature );
parser.mapLineNumbers(true);
parser.parse();
diff --git a/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/LineNumberTest.java b/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/LineNumberTest.java
index 5d49518375..49c01ab1d8 100644
--- a/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/LineNumberTest.java
+++ b/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/LineNumberTest.java
@@ -13,14 +13,17 @@ package org.eclipse.cdt.core.parser.tests;
import java.io.FileInputStream;
import java.io.InputStream;
-import java.io.Reader;
+import java.io.InputStreamReader;
import java.io.StringReader;
import java.util.List;
import junit.framework.TestCase;
import org.eclipse.cdt.core.parser.IParser;
+import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.IToken;
+import org.eclipse.cdt.core.parser.ParserFactory;
+import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.internal.core.dom.ClassSpecifier;
import org.eclipse.cdt.internal.core.dom.DOMBuilder;
import org.eclipse.cdt.internal.core.dom.EnumerationSpecifier;
@@ -29,7 +32,6 @@ import org.eclipse.cdt.internal.core.dom.NamespaceDefinition;
import org.eclipse.cdt.internal.core.dom.SimpleDeclaration;
import org.eclipse.cdt.internal.core.dom.TemplateDeclaration;
import org.eclipse.cdt.internal.core.parser.Parser;
-import org.eclipse.cdt.internal.core.parser.Scanner;
import org.eclipse.core.runtime.Path;
/**
@@ -53,9 +55,7 @@ public class LineNumberTest extends TestCase {
public void testLineNos() throws Exception
{
- Scanner scanner = new Scanner();
- Reader reader = new StringReader( "int x = 3;\n foo\nfire\nfoe ");
- scanner.initialize( reader, "string");
+ IScanner scanner = ParserFactory.createScanner( new StringReader( "int x = 3;\n foo\nfire\nfoe " ), "string", null, null, null );
scanner.mapLineNumbers(true);
IToken t = scanner.nextToken();
assertEquals( t.getType(), IToken.t_int );
@@ -92,7 +92,7 @@ public class LineNumberTest extends TestCase {
public void testDOMLineNos() throws Exception
{
DOMBuilder domBuilder = new DOMBuilder();
- IParser parser = new Parser( fileIn, domBuilder, true );
+ IParser parser = ParserFactory.createParser( ParserFactory.createScanner( new InputStreamReader( fileIn ), null, null, null, ParserMode.QUICK_PARSE ), domBuilder, ParserMode.QUICK_PARSE );
parser.mapLineNumbers(true);
if( ! parser.parse() ) fail( "Parse of file failed");
diff --git a/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java b/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java
index 397fcfc179..8f08b199a9 100644
--- a/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java
+++ b/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java
@@ -6,6 +6,7 @@ import java.util.List;
import org.eclipse.cdt.core.parser.IMacroDescriptor;
import org.eclipse.cdt.core.parser.IToken;
+import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ScannerException;
import org.eclipse.cdt.internal.core.parser.Parser;
import org.eclipse.cdt.internal.core.parser.Token;
@@ -851,7 +852,7 @@ public class ScannerTestCase extends BaseScannerTest
try
{
initializeScanner( "#if X + 5 < 7\n int found = 1;\n#endif" );
- scanner.setQuickScan( true );
+ scanner.setMode( ParserMode.QUICK_PARSE );
validateToken( IToken.t_int );
validateIdentifier( "found" );
validateToken( IToken.tASSIGN );
@@ -868,7 +869,7 @@ public class ScannerTestCase extends BaseScannerTest
try
{
initializeScanner( "#if 0\n int error = 666;\n#endif" );
- scanner.setQuickScan( true );
+ scanner.setMode( ParserMode.COMPLETE_PARSE );
validateEOF();
}
catch( ScannerException se )
diff --git a/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java b/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java
index d6376b5c5e..478fe6bb50 100644
--- a/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java
+++ b/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java
@@ -14,6 +14,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.StringReader;
import java.io.StringWriter;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
@@ -22,8 +23,9 @@ import junit.framework.AssertionFailedError;
import junit.framework.Test;
import org.eclipse.cdt.core.parser.IParser;
+import org.eclipse.cdt.core.parser.ParserFactory;
+import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.internal.core.dom.DOMBuilder;
-import org.eclipse.cdt.internal.core.parser.Parser;
import org.eclipse.core.runtime.Path;
@@ -200,7 +202,8 @@ public class TortureTest extends FractionalAutomatedTest {
public void run(){
try {
DOMBuilder domBuilder = new DOMBuilder();
- parser = new Parser(code.toString(), domBuilder, quickParse);
+ IParser parser = ParserFactory.createParser(
+ ParserFactory.createScanner( new StringReader( code ), null, null, null, ParserMode.QUICK_PARSE ), nullCallback, ParserMode.QUICK_PARSE);
parser.setCppNature(cppNature);
parser.mapLineNumbers(true);
diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog
index 1d3776710b..ac3fb21cd5 100644
--- a/core/org.eclipse.cdt.ui/ChangeLog
+++ b/core/org.eclipse.cdt.ui/ChangeLog
@@ -1,3 +1,7 @@
+2003-06-23 John Camelon
+ Updated Factory infrastructure, constructors, etc.
+ Introduced Preprocessor class for transitive closure calc. client.
+
2003-06-20 Sean Evoy
Added (again) the icons required for the new managed project wizard and property pages
* icons/full/build16/config-command.gif
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/ComparatorModelBuilder.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/ComparatorModelBuilder.java
index 2d97552055..343997da4f 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/ComparatorModelBuilder.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/ComparatorModelBuilder.java
@@ -11,10 +11,14 @@
package org.eclipse.cdt.internal.ui.compare;
+import java.io.StringReader;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.parser.IParser;
+import org.eclipse.cdt.core.parser.ParserFactory;
+import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.internal.core.dom.ClassKey;
import org.eclipse.cdt.internal.core.dom.ClassSpecifier;
import org.eclipse.cdt.internal.core.dom.DOMBuilder;
@@ -31,7 +35,6 @@ import org.eclipse.cdt.internal.core.dom.TemplateDeclaration;
import org.eclipse.cdt.internal.core.dom.TranslationUnit;
import org.eclipse.cdt.internal.core.dom.TypeSpecifier;
import org.eclipse.cdt.internal.core.parser.Name;
-import org.eclipse.cdt.internal.core.parser.Parser;
import org.eclipse.cdt.internal.parser.IStructurizerCallback;
/**
@@ -54,8 +57,7 @@ public class ComparatorModelBuilder {
public void parse() {
DOMBuilder domBuilder = new DOMBuilder();
try {
-
- Parser parser = new Parser(code, domBuilder, true);
+ IParser parser = ParserFactory.createParser(ParserFactory.createScanner( new StringReader( code ), null, null, null, ParserMode.QUICK_PARSE ), domBuilder, ParserMode.QUICK_PARSE);
parser.parse();
} catch (Exception e) {
callback.reportError(e);

Back to the top