[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Applied [ HEAD ] Preprocessor entity added
|
Updated Factory infrastructure, constructors
of classes, modes of parsing.
Introduced Preprocessor interface for transitive-closure
purposes.
JohnC
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/ChangeLog,v
retrieving revision 1.107
diff -u -r1.107 ChangeLog
--- ChangeLog 23 Jun 2003 14:36:26 -0000 1.107
+++ ChangeLog 23 Jun 2003 17:57:52 -0000
@@ -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
Index: src/org/eclipse/cdt/internal/ui/compare/ComparatorModelBuilder.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/ComparatorModelBuilder.java,v
retrieving revision 1.4
diff -u -r1.4 ComparatorModelBuilder.java
--- src/org/eclipse/cdt/internal/ui/compare/ComparatorModelBuilder.java 13 Jun 2003 15:01:26 -0000 1.4
+++ src/org/eclipse/cdt/internal/ui/compare/ComparatorModelBuilder.java 23 Jun 2003 17:57:53 -0000
@@ -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.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 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);
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/ChangeLog,v
retrieving revision 1.69
diff -u -r1.69 ChangeLog
--- ChangeLog 23 Jun 2003 14:36:24 -0000 1.69
+++ ChangeLog 23 Jun 2003 17:57:34 -0000
@@ -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
Index: parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java,v
retrieving revision 1.8
diff -u -r1.8 AutomatedTest.java
--- parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java 13 Jun 2003 15:01:12 -0000 1.8
+++ parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java 23 Jun 2003 17:57:34 -0000
@@ -14,6 +14,7 @@
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.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 @@
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 )
Index: parser/org/eclipse/cdt/core/parser/tests/BaseDOMTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/BaseDOMTest.java,v
retrieving revision 1.3
diff -u -r1.3 BaseDOMTest.java
--- parser/org/eclipse/cdt/core/parser/tests/BaseDOMTest.java 13 Jun 2003 15:01:12 -0000 1.3
+++ parser/org/eclipse/cdt/core/parser/tests/BaseDOMTest.java 23 Jun 2003 17:57:34 -0000
@@ -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 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 );
Index: parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java,v
retrieving revision 1.3
diff -u -r1.3 BaseScannerTest.java
--- parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java 13 Jun 2003 19:59:47 -0000 1.3
+++ parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java 23 Jun 2003 17:57:34 -0000
@@ -15,10 +15,12 @@
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 @@
*/
public class BaseScannerTest extends TestCase {
- protected Scanner scanner;
+ protected IScanner scanner;
public BaseScannerTest( String x )
{
@@ -35,8 +37,7 @@
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
Index: parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java,v
retrieving revision 1.6
diff -u -r1.6 ExprEvalTest.java
--- parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java 13 Jun 2003 15:01:12 -0000 1.6
+++ parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java 23 Jun 2003 17:57:34 -0000
@@ -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 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());
}
Index: parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java,v
retrieving revision 1.4
diff -u -r1.4 FractionalAutomatedTest.java
--- parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java 11 Jun 2003 19:14:01 -0000 1.4
+++ parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java 23 Jun 2003 17:57:34 -0000
@@ -15,13 +15,16 @@
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 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();
Index: parser/org/eclipse/cdt/core/parser/tests/LineNumberTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/LineNumberTest.java,v
retrieving revision 1.6
diff -u -r1.6 LineNumberTest.java
--- parser/org/eclipse/cdt/core/parser/tests/LineNumberTest.java 13 Jun 2003 19:59:47 -0000 1.6
+++ parser/org/eclipse/cdt/core/parser/tests/LineNumberTest.java 23 Jun 2003 17:57:34 -0000
@@ -13,14 +13,17 @@
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.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 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 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");
Index: parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java,v
retrieving revision 1.24
diff -u -r1.24 ScannerTestCase.java
--- parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java 20 Jun 2003 17:15:56 -0000 1.24
+++ parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java 23 Jun 2003 17:57:35 -0000
@@ -6,6 +6,7 @@
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 @@
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 @@
try
{
initializeScanner( "#if 0\n int error = 666;\n#endif" );
- scanner.setQuickScan( true );
+ scanner.setMode( ParserMode.COMPLETE_PARSE );
validateEOF();
}
catch( ScannerException se )
Index: parser/org/eclipse/cdt/core/parser/tests/TortureTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java,v
retrieving revision 1.2
diff -u -r1.2 TortureTest.java
--- parser/org/eclipse/cdt/core/parser/tests/TortureTest.java 13 Jun 2003 15:01:12 -0000 1.2
+++ parser/org/eclipse/cdt/core/parser/tests/TortureTest.java 23 Jun 2003 17:57:35 -0000
@@ -14,6 +14,7 @@
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.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 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);
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/ChangeLog,v
retrieving revision 1.4
diff -u -r1.4 ChangeLog
--- ChangeLog 23 Jun 2003 14:36:28 -0000 1.4
+++ ChangeLog 23 Jun 2003 17:57:10 -0000
@@ -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.
Index: parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java,v
retrieving revision 1.1
diff -u -r1.1 AutomatedTest.java
--- parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java 18 Jun 2003 21:29:47 -0000 1.1
+++ parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java 23 Jun 2003 17:57:10 -0000
@@ -14,6 +14,7 @@
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.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 @@
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() );
Index: parser/org/eclipse/cdt/core/parser/tests/BaseDOMTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseDOMTest.java,v
retrieving revision 1.1
diff -u -r1.1 BaseDOMTest.java
--- parser/org/eclipse/cdt/core/parser/tests/BaseDOMTest.java 18 Jun 2003 21:29:47 -0000 1.1
+++ parser/org/eclipse/cdt/core/parser/tests/BaseDOMTest.java 23 Jun 2003 17:57:10 -0000
@@ -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 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 );
Index: parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java,v
retrieving revision 1.1
diff -u -r1.1 BaseScannerTest.java
--- parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java 18 Jun 2003 21:29:47 -0000 1.1
+++ parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java 23 Jun 2003 17:57:10 -0000
@@ -15,10 +15,11 @@
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 @@
*/
public class BaseScannerTest extends TestCase {
- protected Scanner scanner;
+ protected IScanner scanner;
public BaseScannerTest( String x )
{
@@ -35,8 +36,7 @@
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
Index: parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java,v
retrieving revision 1.1
diff -u -r1.1 ExprEvalTest.java
--- parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java 18 Jun 2003 21:29:47 -0000 1.1
+++ parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java 23 Jun 2003 17:57:10 -0000
@@ -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 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());
}
Index: parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java,v
retrieving revision 1.1
diff -u -r1.1 FractionalAutomatedTest.java
--- parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java 18 Jun 2003 21:29:47 -0000 1.1
+++ parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java 23 Jun 2003 17:57:10 -0000
@@ -15,13 +15,16 @@
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 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();
Index: parser/org/eclipse/cdt/core/parser/tests/LineNumberTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/LineNumberTest.java,v
retrieving revision 1.1
diff -u -r1.1 LineNumberTest.java
--- parser/org/eclipse/cdt/core/parser/tests/LineNumberTest.java 18 Jun 2003 21:29:47 -0000 1.1
+++ parser/org/eclipse/cdt/core/parser/tests/LineNumberTest.java 23 Jun 2003 17:57:10 -0000
@@ -13,14 +13,17 @@
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.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 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 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");
Index: parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java,v
retrieving revision 1.2
diff -u -r1.2 ParserTestSuite.java
--- parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java 20 Jun 2003 17:16:05 -0000 1.2
+++ parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java 23 Jun 2003 17:57:10 -0000
@@ -33,6 +33,7 @@
suite.addTestSuite(ParserSymbolTableTest.class);
suite.addTestSuite(CModelElementsTests.class);
suite.addTestSuite(MacroTests.class);
+ suite.addTestSuite( PreprocessorTest.class );
return suite;
}
Index: parser/org/eclipse/cdt/core/parser/tests/PreprocessorTest.java
===================================================================
RCS file: parser/org/eclipse/cdt/core/parser/tests/PreprocessorTest.java
diff -N parser/org/eclipse/cdt/core/parser/tests/PreprocessorTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ parser/org/eclipse/cdt/core/parser/tests/PreprocessorTest.java 23 Jun 2003 17:57:10 -0000
@@ -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;
+ }
+}
Index: parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java,v
retrieving revision 1.2
diff -u -r1.2 ScannerTestCase.java
--- parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java 20 Jun 2003 17:16:05 -0000 1.2
+++ parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java 23 Jun 2003 17:57:11 -0000
@@ -6,6 +6,7 @@
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 @@
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 @@
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 @@
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 @@
prepareForWindowsRH();
validateEOF();
validateBalance();
- if (verbose)
- System.out.println(
- "For WinUser.rh, Scanner produced "
- + scanner.getCount()
- + " tokens");
}
}
catch (Exception e)
Index: parser/org/eclipse/cdt/core/parser/tests/TortureTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java,v
retrieving revision 1.1
diff -u -r1.1 TortureTest.java
--- parser/org/eclipse/cdt/core/parser/tests/TortureTest.java 18 Jun 2003 21:29:47 -0000 1.1
+++ parser/org/eclipse/cdt/core/parser/tests/TortureTest.java 23 Jun 2003 17:57:11 -0000
@@ -14,6 +14,7 @@
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.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 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);
Index: dom/org/eclipse/cdt/internal/core/dom/Name.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/Name.java,v
retrieving revision 1.4
diff -u -r1.4 Name.java
--- dom/org/eclipse/cdt/internal/core/dom/Name.java 20 Jun 2003 17:15:59 -0000 1.4
+++ dom/org/eclipse/cdt/internal/core/dom/Name.java 23 Jun 2003 17:56:43 -0000
@@ -35,7 +35,7 @@
}
public String toString() {
- Token t = nameStart;
+ IToken t = nameStart;
StringBuffer buffer = new StringBuffer();
buffer.append( t.getImage() );
if( t.getType() == IToken.t_operator )
Index: model/org/eclipse/cdt/internal/core/model/CModelBuilder.java
===================================================================
RCS file: model/org/eclipse/cdt/internal/core/model/CModelBuilder.java
diff -N model/org/eclipse/cdt/internal/core/model/CModelBuilder.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ model/org/eclipse/cdt/internal/core/model/CModelBuilder.java 23 Jun 2003 17:56:43 -0000
@@ -0,0 +1,1014 @@
+package org.eclipse.cdt.internal.core.model;
+
+
+/*******************************************************************************
+ * 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
+ ******************************************************************************/
+
+import java.io.StringReader;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.INamespace;
+import org.eclipse.cdt.core.model.IParent;
+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;
+import org.eclipse.cdt.internal.core.dom.DOMBuilder;
+import org.eclipse.cdt.internal.core.dom.DeclSpecifier;
+import org.eclipse.cdt.internal.core.dom.Declaration;
+import org.eclipse.cdt.internal.core.dom.Declarator;
+import org.eclipse.cdt.internal.core.dom.ElaboratedTypeSpecifier;
+import org.eclipse.cdt.internal.core.dom.EnumerationSpecifier;
+import org.eclipse.cdt.internal.core.dom.EnumeratorDefinition;
+import org.eclipse.cdt.internal.core.dom.IOffsetable;
+import org.eclipse.cdt.internal.core.dom.ITemplateParameterListOwner;
+import org.eclipse.cdt.internal.core.dom.Inclusion;
+import org.eclipse.cdt.internal.core.dom.Macro;
+import org.eclipse.cdt.internal.core.dom.NamespaceDefinition;
+import org.eclipse.cdt.internal.core.dom.OldKRParameterDeclarationClause;
+import org.eclipse.cdt.internal.core.dom.ParameterDeclaration;
+import org.eclipse.cdt.internal.core.dom.ParameterDeclarationClause;
+import org.eclipse.cdt.internal.core.dom.PointerOperator;
+import org.eclipse.cdt.internal.core.dom.SimpleDeclaration;
+import org.eclipse.cdt.internal.core.dom.TemplateDeclaration;
+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.core.resources.IProject;
+
+
+public class CModelBuilder {
+
+ protected org.eclipse.cdt.internal.core.model.TranslationUnit translationUnit;
+ protected Map newElements;
+
+ public CModelBuilder(org.eclipse.cdt.internal.core.model.TranslationUnit tu) {
+ this.translationUnit = tu ;
+ this.newElements = new HashMap();
+ }
+
+ public Map parse(boolean requiresLineNumbers) throws Exception {
+ // 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();
+ 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 )
+ {
+ IProject currentProject = translationUnit.getCProject().getProject();
+ boolean hasCppNature = CoreModel.getDefault().hasCCNature(currentProject);
+ parser.setCppNature(hasCppNature);
+ }
+ try
+ {
+ parser.parse();
+ }
+ catch( Exception e )
+ {
+ System.out.println( "Parse Exception in Outline View" );
+ e.printStackTrace();
+ }
+ long startTime = System.currentTimeMillis();
+ try
+ {
+ generateModelElements(domBuilder.getTranslationUnit());
+ }
+ catch( NullPointerException npe )
+ {
+ System.out.println( "NullPointer exception generating CModel");
+ npe.printStackTrace();
+ }
+
+ // For the debuglog to take place, you have to call
+ // Util.setDebugging(true);
+ // Or set debug to true in the core plugin preference
+ Util.debugLog("CModel build: "+ ( System.currentTimeMillis() - startTime ) + "ms");
+ return this.newElements;
+ }
+
+ protected void generateModelElements(TranslationUnit tu){
+ Iterator i = tu.iterateOffsetableElements();
+ while (i.hasNext()){
+ IOffsetable offsetable = (IOffsetable)i.next();
+ if(offsetable instanceof Inclusion){
+ createInclusion(translationUnit, (Inclusion) offsetable);
+ }
+ else if(offsetable instanceof Macro){
+ createMacro(translationUnit, (Macro) offsetable);
+ }else if(offsetable instanceof Declaration){
+ generateModelElements (translationUnit, (Declaration) offsetable);
+ }
+ }
+ }
+
+ protected void generateModelElements (Parent parent, Declaration declaration){
+ // Namespace Definition
+ if(declaration instanceof NamespaceDefinition){
+ NamespaceDefinition nsDef = (NamespaceDefinition) declaration;
+ IParent namespace = createNamespace(parent, nsDef);
+ List nsDeclarations = nsDef.getDeclarations();
+ Iterator nsDecls = nsDeclarations.iterator();
+ while (nsDecls.hasNext()){
+ Declaration subNsDeclaration = (Declaration) nsDecls.next();
+ generateModelElements((Parent)namespace, subNsDeclaration);
+ }
+ }// end Namespace Definition
+
+ // Simple Declaration
+ if(declaration instanceof SimpleDeclaration){
+ SimpleDeclaration simpleDeclaration = (SimpleDeclaration) declaration;
+
+ /*-------------------------------------------
+ * Checking the type if it is a composite one
+ *-------------------------------------------*/
+ TypeSpecifier typeSpec = simpleDeclaration.getTypeSpecifier();
+ // Enumeration
+ if (typeSpec instanceof EnumerationSpecifier){
+ EnumerationSpecifier enumSpecifier = (EnumerationSpecifier) typeSpec;
+ IParent enumElement = createEnumeration (parent, enumSpecifier);
+ }
+ // Structure
+ else if (typeSpec instanceof ClassSpecifier){
+ ClassSpecifier classSpecifier = (ClassSpecifier) typeSpec;
+ IParent classElement = createClass (parent, simpleDeclaration, classSpecifier, false);
+ // create the sub declarations
+ List declarations = classSpecifier.getDeclarations();
+ Iterator j = declarations.iterator();
+ while (j.hasNext()){
+ Declaration subDeclaration = (Declaration)j.next();
+ generateModelElements((Parent)classElement, subDeclaration);
+ } // end while j
+ }
+ /*-----------------------------------------
+ * Create declarators of simple declaration
+ * ----------------------------------------*/
+ List declarators = simpleDeclaration.getDeclarators();
+ Iterator d = declarators.iterator();
+ while (d.hasNext()){
+ Declarator declarator = (Declarator)d.next();
+ createElement(parent, simpleDeclaration, declarator);
+ } // end while d
+ } // end if SimpleDeclaration
+
+ // Template Declaration
+ if(declaration instanceof TemplateDeclaration){
+ TemplateDeclaration templateDeclaration = (TemplateDeclaration)declaration;
+ SimpleDeclaration simpleDeclaration = (SimpleDeclaration)templateDeclaration.getDeclarations().get(0);
+ TypeSpecifier typeSpec = simpleDeclaration.getTypeSpecifier();
+ if (typeSpec instanceof ClassSpecifier){
+ ClassSpecifier classSpecifier = (ClassSpecifier) typeSpec;
+ ITemplate classTemplate = (StructureTemplate)createClass(parent, simpleDeclaration, classSpecifier, true);
+ CElement element = (CElement) classTemplate;
+ // set the element position
+ element.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getTotalLength());
+ // set the element lines
+ element.setLines(templateDeclaration.getTopLine(), templateDeclaration.getBottomLine());
+ // set the template parameters
+ String[] parameterTypes = getTemplateParameters(templateDeclaration);
+ classTemplate.setTemplateParameterTypes(parameterTypes);
+
+ // create the sub declarations
+ List declarations = classSpecifier.getDeclarations();
+ Iterator j = declarations.iterator();
+ while (j.hasNext()){
+ Declaration subDeclaration = (Declaration)j.next();
+ generateModelElements((Parent)classTemplate, subDeclaration);
+ } // end while j
+ }
+ List declarators = simpleDeclaration.getDeclarators();
+ Iterator d = declarators.iterator();
+ while (d.hasNext()){
+ Declarator declarator = (Declarator)d.next();
+ createTemplateElement(parent,templateDeclaration, simpleDeclaration, declarator);
+ } // end while d
+
+ }// end Template Declaration
+
+ }
+
+ protected void createElement(Parent parent, SimpleDeclaration simpleDeclaration, Declarator declarator)
+ {
+ // typedef
+ if(simpleDeclaration.getDeclSpecifier().isTypedef()){
+ createTypeDef(parent, declarator, simpleDeclaration);
+ } else {
+ if (isFunctionSpecification(declarator)) {
+ // function or method
+ createFunctionSpecification(parent, simpleDeclaration, declarator, false);
+ } else {
+ // variable or field
+ createVariableSpecification(parent, simpleDeclaration, declarator, false);
+ }
+ }
+ }
+
+ protected void createTemplateElement(Parent parent, TemplateDeclaration templateDeclaration, SimpleDeclaration simpleDeclaration, Declarator declarator){
+ ParameterDeclarationClause pdc = declarator.getParms();
+ ITemplate template = null;
+ if (pdc == null){
+ template = (ITemplate) createVariableSpecification(parent, simpleDeclaration, declarator, true);
+ }
+ else{
+ // template of function or method
+ template = (ITemplate) createFunctionSpecification(parent, simpleDeclaration, declarator, true);
+ }
+
+ if(template != null){
+ CElement element = (CElement)template;
+ // set the element position
+ element.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getTotalLength());
+ // set the element lines
+ element.setLines(templateDeclaration.getTopLine(), templateDeclaration.getBottomLine());
+ // set the template parameters
+ String[] parameterTypes = getTemplateParameters(templateDeclaration);
+ template.setTemplateParameterTypes(parameterTypes);
+ }
+ }
+ protected Include createInclusion(Parent parent, Inclusion inclusion){
+ // create element
+ Include element = new Include((CElement)parent, inclusion.getName(), !inclusion.isLocal());
+ // add to parent
+ parent.addChild((CElement) element);
+ // set position
+ element.setIdPos(inclusion.getNameOffset(), inclusion.getNameLength());
+ element.setPos(inclusion.getStartingOffset(), inclusion.getTotalLength());
+ // set the element lines
+ element.setLines(inclusion.getTopLine(), inclusion.getBottomLine());
+ this.newElements.put(element, element.getElementInfo());
+ return element;
+ }
+
+ protected org.eclipse.cdt.internal.core.model.Macro createMacro(Parent parent, Macro macro){
+ // create element
+ org.eclipse.cdt.internal.core.model.Macro element = new org.eclipse.cdt.internal.core.model.Macro(parent, macro.getName());
+ // add to parent
+ parent.addChild((CElement) element);
+ // set position
+ element.setIdPos(macro.getNameOffset(), macro.getNameLength());
+ element.setPos(macro.getStartingOffset(), macro.getTotalLength());
+ // set the element lines
+ element.setLines(macro.getTopLine(), macro.getBottomLine());
+ this.newElements.put(element, element.getElementInfo());
+ return element;
+ }
+
+ protected Namespace createNamespace(Parent parent, NamespaceDefinition nsDef){
+ // create element
+ String nsName = (nsDef.getName() == null ) ? "" : nsDef.getName().toString();
+ Namespace element = new Namespace ((ICElement)parent, nsName );
+ // add to parent
+ parent.addChild((ICElement)element);
+ // set element position
+ if(nsDef.getName() != null){
+ element.setIdPos(nsDef.getNameOffset(), nsDef.getName().length());
+ }else{
+ element.setIdPos(nsDef.getStartingOffset(), new String( "namespace").length());
+ }
+ element.setPos(nsDef.getStartingOffset(), nsDef.getTotalLength());
+ element.setTypeName(new String( "namespace"));
+ // set the element lines
+ element.setLines(nsDef.getTopLine(), nsDef.getBottomLine());
+
+ this.newElements.put(element, element.getElementInfo());
+ return element;
+ }
+
+ protected Enumeration createEnumeration(Parent parent, EnumerationSpecifier enumSpecifier){
+ // create element
+ String enumName = (enumSpecifier.getName() == null ) ? "" : enumSpecifier.getName().toString();
+ Enumeration element = new Enumeration ((ICElement)parent, enumName );
+ // add to parent
+ parent.addChild((ICElement)element);
+ List enumItems = enumSpecifier.getEnumeratorDefinitions();
+ Iterator i = enumItems.iterator();
+ while (i.hasNext()){
+ // create sub element
+ EnumeratorDefinition enumDef = (EnumeratorDefinition) i.next();
+ createEnumerator(element, enumDef);
+ }
+ // set enumeration position
+ if(enumSpecifier.getName() != null ){
+ element.setIdPos(enumSpecifier.getName().getStartOffset(), enumSpecifier.getName().length());
+ }else {
+ element.setIdPos(enumSpecifier.getStartToken().getOffset(), enumSpecifier.getStartToken().getLength());
+ }
+ element.setPos(enumSpecifier.getStartingOffset(), enumSpecifier.getTotalLength());
+ element.setTypeName(enumSpecifier.getStartToken().getImage());
+ // set the element lines
+ element.setLines(enumSpecifier.getTopLine(), enumSpecifier.getBottomLine());
+
+ this.newElements.put(element, element.getElementInfo());
+ return element;
+ }
+
+ protected Enumerator createEnumerator(Parent enum, EnumeratorDefinition enumDef){
+ Enumerator element = new Enumerator (enum, enumDef.getName().toString());
+ // add to parent
+ enum.addChild(element);
+ // set enumerator position
+ element.setIdPos(enumDef.getName().getStartOffset(), enumDef.getName().length());
+ element.setPos(enumDef.getStartingOffset(), enumDef.getTotalLength());
+ // set the element lines
+ element.setLines(enumDef.getTopLine(), enumDef.getBottomLine());
+
+ this.newElements.put(element, element.getElementInfo());
+ return element;
+ }
+
+ protected Structure createClass(Parent parent, SimpleDeclaration simpleDeclaration, ClassSpecifier classSpecifier, boolean isTemplate){
+ // create element
+ String className = (classSpecifier.getName() == null ) ? "" : classSpecifier.getName().toString();
+ int kind;
+ switch( classSpecifier.getClassKey() )
+ {
+ case ClassKey.t_class:
+ if(!isTemplate)
+ kind = ICElement.C_CLASS;
+ else
+ kind = ICElement.C_TEMPLATE_CLASS;
+ break;
+ case ClassKey.t_struct:
+ if(!isTemplate)
+ kind = ICElement.C_STRUCT;
+ else
+ kind = ICElement.C_TEMPLATE_STRUCT;
+ break;
+ default:
+ if(!isTemplate)
+ kind = ICElement.C_UNION;
+ else
+ kind = ICElement.C_TEMPLATE_UNION;
+ break;
+ }
+
+ Structure element;
+ if(!isTemplate){
+ Structure classElement = new Structure( (CElement)parent, kind, className );
+ element = classElement;
+ } else {
+ StructureTemplate classTemplate = new StructureTemplate( (CElement)parent, kind, className );
+ element = classTemplate;
+ }
+
+
+ // add to parent
+ parent.addChild((ICElement) element);
+ String type;
+ // set element position
+ if( classSpecifier.getName() != null )
+ {
+ type = simpleDeclaration.getDeclSpecifier().getTypeName();
+ element.setIdPos( classSpecifier.getName().getStartOffset(), classSpecifier.getName().length() );
+ }
+ else
+ {
+ type = classSpecifier.getClassKeyToken().getImage();
+ element.setIdPos(classSpecifier.getClassKeyToken().getOffset(), classSpecifier.getClassKeyToken().getLength());
+
+ }
+ element.setTypeName( type );
+ if(!isTemplate){
+ // set the element position
+ element.setPos(classSpecifier.getStartingOffset(), classSpecifier.getTotalLength());
+ // set the element lines
+ element.setLines(classSpecifier.getTopLine(), classSpecifier.getBottomLine());
+ }
+
+ this.newElements.put(element, element.getElementInfo());
+ return element;
+ }
+
+ protected TypeDef createTypeDef(Parent parent, Declarator declarator, SimpleDeclaration simpleDeclaration){
+ // create the element
+ Name domName = getDOMName(declarator);
+ if (domName == null) {
+ // Something is wrong, skip this element
+ return null;
+ }
+
+ String declaratorName = domName.toString();
+
+ TypeDef element = new TypeDef( parent, declaratorName );
+
+ StringBuffer typeName = new StringBuffer(getType(simpleDeclaration, declarator));
+ element.setTypeName(typeName.toString());
+
+ // add to parent
+ parent.addChild((CElement)element);
+
+ // set positions
+ element.setIdPos(domName.getStartOffset(), domName.length());
+ element.setPos(simpleDeclaration.getStartingOffset(), simpleDeclaration.getTotalLength());
+ // set the element lines
+ element.setLines(simpleDeclaration.getTopLine(), simpleDeclaration.getBottomLine());
+
+ this.newElements.put(element, element.getElementInfo());
+ return element;
+ }
+
+ protected VariableDeclaration createVariableSpecification(Parent parent, SimpleDeclaration simpleDeclaration, Declarator declarator, boolean isTemplate)
+ {
+ Name domName = getDOMName(declarator);
+ if (domName == null) {
+ // TODO : improve errorhandling
+ // When parsing syntactically incorrect code, we might
+ // end up here. Most often, function/method declaration
+ // misses return type, and is neither a constructor nor
+ // a conversion operator. Like
+ // A::B() {}
+ // Parser sees A::B, understands that it is not a constructor
+ // /conversion, then considers it a declaration. So its
+ // type is read as A::B, no name, and a list of declarations
+ // in ().
+ // For now, we just ignore this scenario (and create no
+ // model elements), but in the future we can process this
+ // declaration as a function (with undefined/no type)
+ return null;
+ }
+
+ String variableName = domName.toString();
+ DeclSpecifier declSpecifier = simpleDeclaration.getDeclSpecifier();
+
+ VariableDeclaration element = null;
+ if(parent instanceof IStructure){
+ // field
+ Field newElement = new Field( parent, variableName);
+ newElement.setMutable(declSpecifier.isMutable());
+ newElement.setVisibility(simpleDeclaration.getAccessSpecifier().getAccess());
+ element = newElement;
+ }
+ else {
+ if(isTemplate){
+ // variable
+ VariableTemplate newElement = new VariableTemplate( parent, variableName );
+ element = newElement;
+ }else {
+ if(declSpecifier.isExtern()){
+ // variableDeclaration
+ VariableDeclaration newElement = new VariableDeclaration( parent, variableName );
+ element = newElement;
+ }
+ else {
+ // variable
+ Variable newElement = new Variable( parent, variableName );
+ element = newElement;
+ }
+ }
+ }
+ element.setTypeName ( getType(simpleDeclaration, declarator) );
+ element.setConst(declSpecifier.isConst());
+ element.setVolatile(declSpecifier.isVolatile());
+ element.setStatic(declSpecifier.isStatic());
+ // add to parent
+ parent.addChild( element );
+
+ // set position
+ element.setIdPos( domName.getStartOffset(), domName.length() );
+ if(!isTemplate){
+ // set element position
+ element.setPos(simpleDeclaration.getStartingOffset(), simpleDeclaration.getTotalLength());
+ // set the element lines
+ element.setLines(simpleDeclaration.getTopLine(), simpleDeclaration.getBottomLine());
+ }
+
+ this.newElements.put(element, element.getElementInfo());
+ return element;
+ }
+
+ protected FunctionDeclaration createFunctionSpecification(Parent parent, SimpleDeclaration simpleDeclaration, Declarator declarator, boolean isTemplate)
+ {
+ Name domName = getDOMName(declarator);
+ if (domName == null) {
+ // Something is wrong, skip this element
+ return null;
+ }
+
+ String declaratorName = domName.toString();
+ DeclSpecifier declSpecifier = simpleDeclaration.getDeclSpecifier();
+
+ // get parameters types
+ String[] parameterTypes = getFunctionParameterTypes(declarator);
+
+ FunctionDeclaration element = null;
+
+ if( parent instanceof IStructure )
+ {
+ if (simpleDeclaration.isFunctionDefinition())
+ {
+ // method
+ if(!isTemplate){
+ Method newElement = new Method( parent, declaratorName );
+ newElement.setVisibility(simpleDeclaration.getAccessSpecifier().getAccess());
+ element = newElement;
+ }else {
+ MethodTemplate newElement = new MethodTemplate(parent, declaratorName);
+ newElement.setVisibility(simpleDeclaration.getAccessSpecifier().getAccess());
+ element = newElement;
+ }
+ }
+ else
+ {
+ // method declaration
+ if(!isTemplate){
+ MethodDeclaration newElement = new MethodDeclaration( parent, declaratorName );
+ newElement.setVisibility(simpleDeclaration.getAccessSpecifier().getAccess());
+ element = newElement;
+ }else {
+ MethodTemplate newElement = new MethodTemplate(parent, declaratorName);
+ newElement.setVisibility(simpleDeclaration.getAccessSpecifier().getAccess());
+ element = newElement;
+ }
+
+ }
+ }
+ else if(( parent instanceof ITranslationUnit )
+ || ( parent instanceof INamespace ))
+ {
+ if (simpleDeclaration.isFunctionDefinition())
+ {
+ // if it belongs to a class, then create a method
+ // else create a function
+ // this will not be known until we have cross reference information
+
+ // function
+ if(!isTemplate){
+ Function newElement = new Function( parent, declaratorName );
+ element = newElement;
+ } else {
+ FunctionTemplate newElement = new FunctionTemplate( parent, declaratorName );
+ element = newElement;
+ }
+ }
+ else
+ {
+ // functionDeclaration
+ if(!isTemplate){
+ FunctionDeclaration newElement = new FunctionDeclaration( parent, declaratorName );
+ element = newElement;
+ } else {
+ FunctionTemplate newElement = new FunctionTemplate( parent, declaratorName );
+ element = newElement;
+ }
+ }
+ }
+ element.setParameterTypes(parameterTypes);
+ element.setReturnType( getFunctionReturnType(simpleDeclaration, declarator) );
+ element.setVolatile(declSpecifier.isVolatile());
+ element.setStatic(declSpecifier.isStatic());
+ element.setConst(declarator.isConst());
+
+ // add to parent
+ parent.addChild( element );
+
+ // hook up the offsets
+ element.setIdPos( domName.getStartOffset(), domName.length() );
+ if(!isTemplate){
+ // set the element position
+ element.setPos(simpleDeclaration.getStartingOffset(), simpleDeclaration.getTotalLength());
+ // set the element lines
+ element.setLines(simpleDeclaration.getTopLine(), simpleDeclaration.getBottomLine());
+ }
+
+ this.newElements.put(element, element.getElementInfo());
+ return element;
+ }
+
+
+ private String[] getTemplateParameters(ITemplateParameterListOwner templateDeclaration){
+ // add the parameters
+ List templateParameters = templateDeclaration.getTemplateParms().getDeclarations();
+ Iterator i = templateParameters.iterator();
+ String[] parameterTypes = new String[templateParameters.size()];
+
+ for( int j = 0; j< templateParameters.size(); ++j ){
+ StringBuffer paramType = new StringBuffer();
+ Declaration decl = (Declaration)templateParameters.get(j);
+ if(decl instanceof TemplateParameter){
+ TemplateParameter parameter = (TemplateParameter) decl;
+ if(parameter.getName() != null){
+ paramType.append(parameter.getName().toString());
+ }else {
+ int kind = parameter.getKind();
+ switch (kind){
+ case TemplateParameter.k_class:
+ paramType.append("class");
+ break;
+ case TemplateParameter.k_typename:
+ paramType.append("typename");
+ break;
+ case TemplateParameter.k_template:
+ paramType.append("template<");
+ String[] subParams =getTemplateParameters(parameter);
+ int p = 0;
+ if ( subParams.length > 0)
+ paramType.append(subParams[p++]);
+ while( p < subParams.length){
+ paramType.append(", ");
+ paramType.append(subParams[p++]);
+ }
+ paramType.append(">");
+ break;
+ default:
+ break;
+ } // switch
+ }
+ } else if(decl instanceof ParameterDeclaration){
+ ParameterDeclaration parameter = (ParameterDeclaration) decl;
+ paramType.append(getType(parameter, (Declarator)parameter.getDeclarators().get(0)));
+ }
+ parameterTypes[j] = new String(paramType.toString());
+ } // end for
+ return parameterTypes;
+ }
+
+ private String getType(Declaration declaration, Declarator declarator)
+ {
+ StringBuffer type = new StringBuffer();
+
+ // get type from declaration
+ type.append(getDeclarationType(declaration));
+
+ type.append(getSubType(declarator, new SubTypeProcessingFlags(false)));
+
+ return type.toString();
+ }
+
+ private String getFunctionReturnType(Declaration declaration, Declarator declarator)
+ {
+ StringBuffer type = new StringBuffer();
+
+ // get type from declaration
+ type.append(getDeclarationType(declaration));
+
+ type.append(getSubType(declarator, new SubTypeProcessingFlags(true)));
+
+ return type.toString();
+ }
+
+ private class SubTypeProcessingFlags {
+ boolean returnTypeForFunction = false;
+ boolean processedInnermostParameterList = false;
+
+ SubTypeProcessingFlags(boolean returnTypeForFunction) {
+ this.returnTypeForFunction = returnTypeForFunction;
+ }
+ }
+
+ private String getSubType(Declarator declarator, SubTypeProcessingFlags flags) {
+ StringBuffer type = new StringBuffer();
+
+ // add pointer or reference from declarator if any
+ String declaratorPointerOperation = getDeclaratorPointerOperation(declarator);
+ try {
+ switch (declaratorPointerOperation.charAt(0)) {
+ case '*':
+ case '&':
+ break; // pointer/reference
+ default:
+ type.append(" "); // pointer to member
+ }
+ } catch (Exception e) {} // Empty/null strings
+ type.append(declaratorPointerOperation);
+
+ String subType = null;
+
+ if (declarator.getDeclarator() != null){
+ // process inner declarator
+ subType = getSubType(declarator.getDeclarator(), flags);
+ boolean appendParen = true;
+
+ if ( (subType == null) || (subType.length() == 0)
+ ||
+ ((subType.charAt(0) == '(')
+ &&
+ (subType.charAt(subType.length()-1) == ')'))) {
+
+ // Additional () are not necessary
+ appendParen = false;
+ }
+
+ if (appendParen) type.append("(");
+ type.append(subType);
+ if (appendParen) type.append(")");
+ }
+
+ // parameters
+ if (declarator.getParms() != null) {
+ // If we process return type for a function,
+ // skip innermost parameter list - it is a part
+ // of function's signature
+ if ( !flags.returnTypeForFunction
+ || flags.processedInnermostParameterList) {
+
+ if ((subType == null) || (subType.length() == 0)) {
+ type.append("()");
+ }
+
+ type.append(getParametersString(declarator));
+ }
+ flags.processedInnermostParameterList = true;
+ }
+
+ // arrays
+ type.append(getDeclaratorArrayQualifiers(declarator));
+
+ return type.toString();
+ }
+
+
+ /**
+ * Here is a tricky one. Determines if a declarator represents a function
+ * specification, or a variable declaration (that includes pointers to functions).
+ * If none of the nested declarators contain parameter list, then it is obviously a variable.
+ * It is a function specification only if no declarators in (A..B] range
+ * contain any pointer/array specificators. A is the declarator containing
+ * the innermost parameter list (which corresponds to parameters of the function),
+ * and B is the innermost declarator (should contain the name of the element).
+ *
+ * @param declarator
+ * @return True, if the declarator represents a function specification
+ */
+
+ private boolean isFunctionSpecification(Declarator declarator)
+ {
+ Declarator currentDeclarator = declarator;
+ boolean result = false;
+
+ while (currentDeclarator != null) {
+ if (currentDeclarator.getParms() != null) {
+ result = true;
+ } else {
+ List ptrOps = currentDeclarator.getPointerOperators();
+ List arrayQs = currentDeclarator.getArrayQualifiers();
+
+ if ( ((ptrOps != null) && (ptrOps.size() > 0))
+ || ((arrayQs != null) && (arrayQs.size() > 0))
+ )
+ {
+ result = false;
+ }
+ }
+
+ currentDeclarator = currentDeclarator.getDeclarator();
+ }
+
+ return result;
+ }
+
+
+ private String getDeclarationType(Declaration declaration){
+ StringBuffer type = new StringBuffer();
+ if(declaration instanceof ParameterDeclaration){
+ ParameterDeclaration paramDeclaration = (ParameterDeclaration) declaration;
+ if(paramDeclaration.getDeclSpecifier().isConst())
+ type.append("const ");
+ if(paramDeclaration.getDeclSpecifier().isVolatile())
+ type.append("volatile ");
+ TypeSpecifier typeSpecifier = paramDeclaration.getTypeSpecifier();
+ if(typeSpecifier == null){
+ type.append(paramDeclaration.getDeclSpecifier().getTypeName());
+ }
+ else if(typeSpecifier instanceof ElaboratedTypeSpecifier){
+ ElaboratedTypeSpecifier elab = (ElaboratedTypeSpecifier) typeSpecifier;
+ type.append(getElaboratedTypeSignature(elab));
+ }
+ }
+
+ if(declaration instanceof SimpleDeclaration){
+ SimpleDeclaration simpleDeclaration = (SimpleDeclaration) declaration;
+ if(simpleDeclaration.getDeclSpecifier().isConst())
+ type.append("const ");
+ if(simpleDeclaration.getDeclSpecifier().isVolatile())
+ type.append("volatile ");
+ TypeSpecifier typeSpecifier = simpleDeclaration.getTypeSpecifier();
+ if(typeSpecifier == null){
+ type.append(simpleDeclaration.getDeclSpecifier().getTypeName());
+ }
+ else if(typeSpecifier instanceof ElaboratedTypeSpecifier){
+ ElaboratedTypeSpecifier elab = (ElaboratedTypeSpecifier) typeSpecifier;
+ type.append(getElaboratedTypeSignature(elab));
+ }
+ }
+
+ return type.toString();
+ }
+
+ private String getElaboratedTypeSignature(ElaboratedTypeSpecifier elab){
+ StringBuffer type = new StringBuffer();
+ int t = elab.getClassKey();
+ switch (t){
+ case ClassKey.t_class:
+ type.append("class");
+ break;
+ case ClassKey.t_struct:
+ type.append("struct");
+ break;
+ case ClassKey.t_union:
+ type.append("union");
+ break;
+ case ClassKey.t_enum:
+ type.append("enum");
+ break;
+ };
+ type.append(" ");
+ type.append(elab.getName().toString());
+ return type.toString();
+ }
+
+ private String getDeclaratorPointerOperation(Declarator declarator){
+ StringBuffer pointerString = new StringBuffer();
+ List pointerOperators = declarator.getPointerOperators();
+ if(pointerOperators != null) {
+ Iterator i = pointerOperators.iterator();
+ while(i.hasNext()){
+ PointerOperator po = (PointerOperator) i.next();
+ switch (po.getType()){
+ case PointerOperator.t_pointer_to_member:
+ pointerString.append(po.getNameSpecifier());
+ // Intentional fall-through
+ case PointerOperator.t_pointer:
+ pointerString.append("*");
+ break;
+ case PointerOperator.t_reference:
+ pointerString.append("&");
+ break;
+ }
+
+ if(po.isConst())
+ pointerString.append(" const");
+ if(po.isVolatile())
+ pointerString.append(" volatile");
+ }
+ }
+ return pointerString.toString();
+ }
+
+ private String getDeclaratorArrayQualifiers(Declarator declarator){
+ StringBuffer arrayString = new StringBuffer();
+ List arrayQualifiers = declarator.getArrayQualifiers();
+ if(arrayQualifiers != null){
+ Iterator i = arrayQualifiers.iterator();
+ while (i.hasNext()){
+ ArrayQualifier q = (ArrayQualifier) i.next();
+ arrayString.append("[]");
+ }
+ }
+ return arrayString.toString();
+ }
+
+
+ private String[] getParameterTypes(Declarator declarator)
+ {
+ return getParameterTypes(declarator, null);
+ }
+
+ private String[] getParameterTypes(Declarator declarator, HashMap mapOfKRParams)
+ {
+ if (declarator == null) return null;
+
+ ParameterDeclarationClause pdc = declarator.getParms();
+ String[] parameterTypes = null;
+
+ if (pdc != null) {
+ List parameterList = pdc.getDeclarations();
+ parameterTypes = new String[parameterList.size()];
+
+ for (int j = 0; j < parameterList.size(); ++j) {
+ ParameterDeclaration param = (ParameterDeclaration) parameterList.get(j);
+ Declarator decl = (Declarator) param.getDeclarators().get(0);
+ parameterTypes[j] = getType(param, decl);
+
+ if ( (mapOfKRParams != null)
+ && (mapOfKRParams.size() > 0)
+ && (decl.getName() == null))
+ {
+ // We have some K&R-style parameter declarations,
+ // and the current parameter has been declared with a single identifier,
+ // (like ...(argname)...)
+ // It has been parsed as a typename, so 'argname' is a name of the type,
+ // and parameter name is empty. But for this particular case,
+ // 'argname' is a name, and its type we have to lookup in the map
+ // of old K&R-style parameter declarations.
+ // If we can't find it, we keep parameter name in the signature
+ String oldKRParamType = (String)mapOfKRParams.get(parameterTypes[j]);
+ if (oldKRParamType != null) {
+ parameterTypes[j] = oldKRParamType;
+ }
+ }
+ }
+ }
+
+ return parameterTypes;
+ }
+
+ private String[] getFunctionParameterTypes(Declarator declarator)
+ {
+ Declarator currentDeclarator = declarator;
+ Declarator innermostPDCDeclarator = null;
+
+ while (currentDeclarator != null) {
+ if (currentDeclarator.getParms() != null) {
+ innermostPDCDeclarator = currentDeclarator;
+ }
+ currentDeclarator = currentDeclarator.getDeclarator();
+ }
+
+ HashMap mapOfKRParams = null;
+
+ if ( declarator != null
+ && declarator.getParms() != null
+ && declarator.getParms().getOldKRParms() != null) {
+
+ mapOfKRParams = new HashMap();
+
+ OldKRParameterDeclarationClause oldKRpdc = declarator.getParms().getOldKRParms();
+ List oldKRParameterList = oldKRpdc.getDeclarations();
+
+ for (int j = 0; j < oldKRParameterList.size(); ++j) {
+ if(oldKRParameterList.get(j) instanceof SimpleDeclaration) { // Must be
+ SimpleDeclaration declKR = (SimpleDeclaration)oldKRParameterList.get(j);
+
+ List declarators = declKR.getDeclarators();
+ Iterator d = declarators.iterator();
+ while (d.hasNext()) {
+ Declarator decl = (Declarator) d.next();
+
+ Name oldKRparamName = getDOMName(decl);
+ String oldKRparamType = getType(declKR, decl);
+
+ if ( (oldKRparamType != null)
+ && (oldKRparamName != null)
+ && (oldKRparamName.toString().length() > 0)
+ ) {
+ mapOfKRParams.put(oldKRparamName.toString(), oldKRparamType);
+ }
+ }
+ }
+ }
+ }
+
+ return getParameterTypes(innermostPDCDeclarator, mapOfKRParams);
+ }
+
+ private String getParametersString(String[] parameterTypes)
+ {
+ StringBuffer parameters = new StringBuffer("");
+
+ if ((parameterTypes != null) && (parameterTypes.length > 0)) {
+ parameters.append("(");
+ int i = 0;
+ parameters.append(parameterTypes[i++]);
+ while (i < parameterTypes.length) {
+ parameters.append(", ");
+ parameters.append(parameterTypes[i++]);
+ }
+ parameters.append(")");
+ } else {
+ if (parameterTypes != null) parameters.append("()");
+ }
+
+ return parameters.toString();
+ }
+
+ private String getParametersString(Declarator declarator)
+ {
+ return getParametersString(getParameterTypes(declarator));
+ }
+
+ private Name getDOMName(Declarator declarator)
+ {
+ Declarator currentDeclarator = declarator;
+ Name name = null;
+
+ if (currentDeclarator != null) {
+ while (currentDeclarator.getDeclarator() != null) {
+ currentDeclarator = currentDeclarator.getDeclarator();
+ }
+ }
+ // The innermost declarator must contain the name
+ if (currentDeclarator != null) {
+ name = currentDeclarator.getName();
+ }
+
+ return name;
+ }
+}
Index: parser/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/ChangeLog,v
retrieving revision 1.61
diff -u -r1.61 ChangeLog
--- parser/ChangeLog 20 Jun 2003 17:15:59 -0000 1.61
+++ parser/ChangeLog 23 Jun 2003 17:56:44 -0000
@@ -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.
Index: parser/org/eclipse/cdt/core/parser/IPreprocessor.java
===================================================================
RCS file: parser/org/eclipse/cdt/core/parser/IPreprocessor.java
diff -N parser/org/eclipse/cdt/core/parser/IPreprocessor.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ parser/org/eclipse/cdt/core/parser/IPreprocessor.java 23 Jun 2003 17:56:44 -0000
@@ -0,0 +1,22 @@
+/**********************************************************************
+ * 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 interface IPreprocessor extends IScanner {
+
+ public void process();
+
+}
Index: parser/org/eclipse/cdt/core/parser/IScanner.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java,v
retrieving revision 1.3
diff -u -r1.3 IScanner.java
--- parser/org/eclipse/cdt/core/parser/IScanner.java 13 Jun 2003 20:03:14 -0000 1.3
+++ parser/org/eclipse/cdt/core/parser/IScanner.java 23 Jun 2003 17:56:44 -0000
@@ -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 @@
* @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);
}
Index: parser/org/eclipse/cdt/core/parser/IToken.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IToken.java,v
retrieving revision 1.1
diff -u -r1.1 IToken.java
--- parser/org/eclipse/cdt/core/parser/IToken.java 13 Jun 2003 20:03:14 -0000 1.1
+++ parser/org/eclipse/cdt/core/parser/IToken.java 23 Jun 2003 17:56:44 -0000
@@ -20,12 +20,13 @@
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();
Index: parser/org/eclipse/cdt/core/parser/ParserFactory.java
===================================================================
RCS file: parser/org/eclipse/cdt/core/parser/ParserFactory.java
diff -N parser/org/eclipse/cdt/core/parser/ParserFactory.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ parser/org/eclipse/cdt/core/parser/ParserFactory.java 23 Jun 2003 17:56:44 -0000
@@ -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;
+ }
+}
Index: parser/org/eclipse/cdt/core/parser/ParserMode.java
===================================================================
RCS file: parser/org/eclipse/cdt/core/parser/ParserMode.java
diff -N parser/org/eclipse/cdt/core/parser/ParserMode.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ parser/org/eclipse/cdt/core/parser/ParserMode.java 23 Jun 2003 17:56:44 -0000
@@ -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;
+}
Index: parser/org/eclipse/cdt/core/parser/ast/IASTClassSpecifier.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTClassSpecifier.java,v
retrieving revision 1.3
diff -u -r1.3 IASTClassSpecifier.java
--- parser/org/eclipse/cdt/core/parser/ast/IASTClassSpecifier.java 13 Jun 2003 20:03:15 -0000 1.3
+++ parser/org/eclipse/cdt/core/parser/ast/IASTClassSpecifier.java 23 Jun 2003 17:56:44 -0000
@@ -24,6 +24,6 @@
public Iterator getBaseClauses();
- public AccessVisibility getCurrentVisiblity();
+ public AccessVisibility getCurrentVisibilityMode();
}
Index: parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java
===================================================================
RCS file: parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java
diff -N parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java
--- parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java 18 Jun 2003 19:36:20 -0000 1.28
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,1013 +0,0 @@
-package org.eclipse.cdt.internal.core.model;
-
-
-/*******************************************************************************
- * 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
- ******************************************************************************/
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.cdt.core.model.CoreModel;
-import org.eclipse.cdt.core.model.ICElement;
-import org.eclipse.cdt.core.model.INamespace;
-import org.eclipse.cdt.core.model.IParent;
-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.internal.core.dom.ArrayQualifier;
-import org.eclipse.cdt.internal.core.dom.ClassKey;
-import org.eclipse.cdt.internal.core.dom.ClassSpecifier;
-import org.eclipse.cdt.internal.core.dom.DOMBuilder;
-import org.eclipse.cdt.internal.core.dom.DeclSpecifier;
-import org.eclipse.cdt.internal.core.dom.Declaration;
-import org.eclipse.cdt.internal.core.dom.Declarator;
-import org.eclipse.cdt.internal.core.dom.ElaboratedTypeSpecifier;
-import org.eclipse.cdt.internal.core.dom.EnumerationSpecifier;
-import org.eclipse.cdt.internal.core.dom.EnumeratorDefinition;
-import org.eclipse.cdt.internal.core.dom.IOffsetable;
-import org.eclipse.cdt.internal.core.dom.ITemplateParameterListOwner;
-import org.eclipse.cdt.internal.core.dom.Inclusion;
-import org.eclipse.cdt.internal.core.dom.Macro;
-import org.eclipse.cdt.internal.core.dom.NamespaceDefinition;
-import org.eclipse.cdt.internal.core.dom.OldKRParameterDeclarationClause;
-import org.eclipse.cdt.internal.core.dom.ParameterDeclaration;
-import org.eclipse.cdt.internal.core.dom.ParameterDeclarationClause;
-import org.eclipse.cdt.internal.core.dom.PointerOperator;
-import org.eclipse.cdt.internal.core.dom.SimpleDeclaration;
-import org.eclipse.cdt.internal.core.dom.TemplateDeclaration;
-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;
-
-
-public class CModelBuilder {
-
- protected org.eclipse.cdt.internal.core.model.TranslationUnit translationUnit;
- protected Map newElements;
-
- public CModelBuilder(org.eclipse.cdt.internal.core.model.TranslationUnit tu) {
- this.translationUnit = tu ;
- this.newElements = new HashMap();
- }
-
- public Map parse(boolean requiresLineNumbers) throws Exception {
- // 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);
- parser.mapLineNumbers(requiresLineNumbers);
- if( translationUnit.getCProject() != null )
- {
- IProject currentProject = translationUnit.getCProject().getProject();
- boolean hasCppNature = CoreModel.getDefault().hasCCNature(currentProject);
- parser.setCppNature(hasCppNature);
- }
- try
- {
- parser.parse();
- }
- catch( Exception e )
- {
- System.out.println( "Parse Exception in Outline View" );
- e.printStackTrace();
- }
- long startTime = System.currentTimeMillis();
- try
- {
- generateModelElements(domBuilder.getTranslationUnit());
- }
- catch( NullPointerException npe )
- {
- System.out.println( "NullPointer exception generating CModel");
- npe.printStackTrace();
- }
-
- // For the debuglog to take place, you have to call
- // Util.setDebugging(true);
- // Or set debug to true in the core plugin preference
- Util.debugLog("CModel build: "+ ( System.currentTimeMillis() - startTime ) + "ms");
- return this.newElements;
- }
-
- protected void generateModelElements(TranslationUnit tu){
- Iterator i = tu.iterateOffsetableElements();
- while (i.hasNext()){
- IOffsetable offsetable = (IOffsetable)i.next();
- if(offsetable instanceof Inclusion){
- createInclusion(translationUnit, (Inclusion) offsetable);
- }
- else if(offsetable instanceof Macro){
- createMacro(translationUnit, (Macro) offsetable);
- }else if(offsetable instanceof Declaration){
- generateModelElements (translationUnit, (Declaration) offsetable);
- }
- }
- }
-
- protected void generateModelElements (Parent parent, Declaration declaration){
- // Namespace Definition
- if(declaration instanceof NamespaceDefinition){
- NamespaceDefinition nsDef = (NamespaceDefinition) declaration;
- IParent namespace = createNamespace(parent, nsDef);
- List nsDeclarations = nsDef.getDeclarations();
- Iterator nsDecls = nsDeclarations.iterator();
- while (nsDecls.hasNext()){
- Declaration subNsDeclaration = (Declaration) nsDecls.next();
- generateModelElements((Parent)namespace, subNsDeclaration);
- }
- }// end Namespace Definition
-
- // Simple Declaration
- if(declaration instanceof SimpleDeclaration){
- SimpleDeclaration simpleDeclaration = (SimpleDeclaration) declaration;
-
- /*-------------------------------------------
- * Checking the type if it is a composite one
- *-------------------------------------------*/
- TypeSpecifier typeSpec = simpleDeclaration.getTypeSpecifier();
- // Enumeration
- if (typeSpec instanceof EnumerationSpecifier){
- EnumerationSpecifier enumSpecifier = (EnumerationSpecifier) typeSpec;
- IParent enumElement = createEnumeration (parent, enumSpecifier);
- }
- // Structure
- else if (typeSpec instanceof ClassSpecifier){
- ClassSpecifier classSpecifier = (ClassSpecifier) typeSpec;
- IParent classElement = createClass (parent, simpleDeclaration, classSpecifier, false);
- // create the sub declarations
- List declarations = classSpecifier.getDeclarations();
- Iterator j = declarations.iterator();
- while (j.hasNext()){
- Declaration subDeclaration = (Declaration)j.next();
- generateModelElements((Parent)classElement, subDeclaration);
- } // end while j
- }
- /*-----------------------------------------
- * Create declarators of simple declaration
- * ----------------------------------------*/
- List declarators = simpleDeclaration.getDeclarators();
- Iterator d = declarators.iterator();
- while (d.hasNext()){
- Declarator declarator = (Declarator)d.next();
- createElement(parent, simpleDeclaration, declarator);
- } // end while d
- } // end if SimpleDeclaration
-
- // Template Declaration
- if(declaration instanceof TemplateDeclaration){
- TemplateDeclaration templateDeclaration = (TemplateDeclaration)declaration;
- SimpleDeclaration simpleDeclaration = (SimpleDeclaration)templateDeclaration.getDeclarations().get(0);
- TypeSpecifier typeSpec = simpleDeclaration.getTypeSpecifier();
- if (typeSpec instanceof ClassSpecifier){
- ClassSpecifier classSpecifier = (ClassSpecifier) typeSpec;
- ITemplate classTemplate = (StructureTemplate)createClass(parent, simpleDeclaration, classSpecifier, true);
- CElement element = (CElement) classTemplate;
- // set the element position
- element.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getTotalLength());
- // set the element lines
- element.setLines(templateDeclaration.getTopLine(), templateDeclaration.getBottomLine());
- // set the template parameters
- String[] parameterTypes = getTemplateParameters(templateDeclaration);
- classTemplate.setTemplateParameterTypes(parameterTypes);
-
- // create the sub declarations
- List declarations = classSpecifier.getDeclarations();
- Iterator j = declarations.iterator();
- while (j.hasNext()){
- Declaration subDeclaration = (Declaration)j.next();
- generateModelElements((Parent)classTemplate, subDeclaration);
- } // end while j
- }
- List declarators = simpleDeclaration.getDeclarators();
- Iterator d = declarators.iterator();
- while (d.hasNext()){
- Declarator declarator = (Declarator)d.next();
- createTemplateElement(parent,templateDeclaration, simpleDeclaration, declarator);
- } // end while d
-
- }// end Template Declaration
-
- }
-
- protected void createElement(Parent parent, SimpleDeclaration simpleDeclaration, Declarator declarator)
- {
- // typedef
- if(simpleDeclaration.getDeclSpecifier().isTypedef()){
- createTypeDef(parent, declarator, simpleDeclaration);
- } else {
- if (isFunctionSpecification(declarator)) {
- // function or method
- createFunctionSpecification(parent, simpleDeclaration, declarator, false);
- } else {
- // variable or field
- createVariableSpecification(parent, simpleDeclaration, declarator, false);
- }
- }
- }
-
- protected void createTemplateElement(Parent parent, TemplateDeclaration templateDeclaration, SimpleDeclaration simpleDeclaration, Declarator declarator){
- ParameterDeclarationClause pdc = declarator.getParms();
- ITemplate template = null;
- if (pdc == null){
- template = (ITemplate) createVariableSpecification(parent, simpleDeclaration, declarator, true);
- }
- else{
- // template of function or method
- template = (ITemplate) createFunctionSpecification(parent, simpleDeclaration, declarator, true);
- }
-
- if(template != null){
- CElement element = (CElement)template;
- // set the element position
- element.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getTotalLength());
- // set the element lines
- element.setLines(templateDeclaration.getTopLine(), templateDeclaration.getBottomLine());
- // set the template parameters
- String[] parameterTypes = getTemplateParameters(templateDeclaration);
- template.setTemplateParameterTypes(parameterTypes);
- }
- }
- protected Include createInclusion(Parent parent, Inclusion inclusion){
- // create element
- Include element = new Include((CElement)parent, inclusion.getName(), !inclusion.isLocal());
- // add to parent
- parent.addChild((CElement) element);
- // set position
- element.setIdPos(inclusion.getNameOffset(), inclusion.getNameLength());
- element.setPos(inclusion.getStartingOffset(), inclusion.getTotalLength());
- // set the element lines
- element.setLines(inclusion.getTopLine(), inclusion.getBottomLine());
- this.newElements.put(element, element.getElementInfo());
- return element;
- }
-
- protected org.eclipse.cdt.internal.core.model.Macro createMacro(Parent parent, Macro macro){
- // create element
- org.eclipse.cdt.internal.core.model.Macro element = new org.eclipse.cdt.internal.core.model.Macro(parent, macro.getName());
- // add to parent
- parent.addChild((CElement) element);
- // set position
- element.setIdPos(macro.getNameOffset(), macro.getNameLength());
- element.setPos(macro.getStartingOffset(), macro.getTotalLength());
- // set the element lines
- element.setLines(macro.getTopLine(), macro.getBottomLine());
- this.newElements.put(element, element.getElementInfo());
- return element;
- }
-
- protected Namespace createNamespace(Parent parent, NamespaceDefinition nsDef){
- // create element
- String nsName = (nsDef.getName() == null ) ? "" : nsDef.getName().toString();
- Namespace element = new Namespace ((ICElement)parent, nsName );
- // add to parent
- parent.addChild((ICElement)element);
- // set element position
- if(nsDef.getName() != null){
- element.setIdPos(nsDef.getNameOffset(), nsDef.getName().length());
- }else{
- element.setIdPos(nsDef.getStartingOffset(), new String( "namespace").length());
- }
- element.setPos(nsDef.getStartingOffset(), nsDef.getTotalLength());
- element.setTypeName(new String( "namespace"));
- // set the element lines
- element.setLines(nsDef.getTopLine(), nsDef.getBottomLine());
-
- this.newElements.put(element, element.getElementInfo());
- return element;
- }
-
- protected Enumeration createEnumeration(Parent parent, EnumerationSpecifier enumSpecifier){
- // create element
- String enumName = (enumSpecifier.getName() == null ) ? "" : enumSpecifier.getName().toString();
- Enumeration element = new Enumeration ((ICElement)parent, enumName );
- // add to parent
- parent.addChild((ICElement)element);
- List enumItems = enumSpecifier.getEnumeratorDefinitions();
- Iterator i = enumItems.iterator();
- while (i.hasNext()){
- // create sub element
- EnumeratorDefinition enumDef = (EnumeratorDefinition) i.next();
- createEnumerator(element, enumDef);
- }
- // set enumeration position
- if(enumSpecifier.getName() != null ){
- element.setIdPos(enumSpecifier.getName().getStartOffset(), enumSpecifier.getName().length());
- }else {
- element.setIdPos(enumSpecifier.getStartToken().getOffset(), enumSpecifier.getStartToken().getLength());
- }
- element.setPos(enumSpecifier.getStartingOffset(), enumSpecifier.getTotalLength());
- element.setTypeName(enumSpecifier.getStartToken().getImage());
- // set the element lines
- element.setLines(enumSpecifier.getTopLine(), enumSpecifier.getBottomLine());
-
- this.newElements.put(element, element.getElementInfo());
- return element;
- }
-
- protected Enumerator createEnumerator(Parent enum, EnumeratorDefinition enumDef){
- Enumerator element = new Enumerator (enum, enumDef.getName().toString());
- // add to parent
- enum.addChild(element);
- // set enumerator position
- element.setIdPos(enumDef.getName().getStartOffset(), enumDef.getName().length());
- element.setPos(enumDef.getStartingOffset(), enumDef.getTotalLength());
- // set the element lines
- element.setLines(enumDef.getTopLine(), enumDef.getBottomLine());
-
- this.newElements.put(element, element.getElementInfo());
- return element;
- }
-
- protected Structure createClass(Parent parent, SimpleDeclaration simpleDeclaration, ClassSpecifier classSpecifier, boolean isTemplate){
- // create element
- String className = (classSpecifier.getName() == null ) ? "" : classSpecifier.getName().toString();
- int kind;
- switch( classSpecifier.getClassKey() )
- {
- case ClassKey.t_class:
- if(!isTemplate)
- kind = ICElement.C_CLASS;
- else
- kind = ICElement.C_TEMPLATE_CLASS;
- break;
- case ClassKey.t_struct:
- if(!isTemplate)
- kind = ICElement.C_STRUCT;
- else
- kind = ICElement.C_TEMPLATE_STRUCT;
- break;
- default:
- if(!isTemplate)
- kind = ICElement.C_UNION;
- else
- kind = ICElement.C_TEMPLATE_UNION;
- break;
- }
-
- Structure element;
- if(!isTemplate){
- Structure classElement = new Structure( (CElement)parent, kind, className );
- element = classElement;
- } else {
- StructureTemplate classTemplate = new StructureTemplate( (CElement)parent, kind, className );
- element = classTemplate;
- }
-
-
- // add to parent
- parent.addChild((ICElement) element);
- String type;
- // set element position
- if( classSpecifier.getName() != null )
- {
- type = simpleDeclaration.getDeclSpecifier().getTypeName();
- element.setIdPos( classSpecifier.getName().getStartOffset(), classSpecifier.getName().length() );
- }
- else
- {
- type = classSpecifier.getClassKeyToken().getImage();
- element.setIdPos(classSpecifier.getClassKeyToken().getOffset(), classSpecifier.getClassKeyToken().getLength());
-
- }
- element.setTypeName( type );
- if(!isTemplate){
- // set the element position
- element.setPos(classSpecifier.getStartingOffset(), classSpecifier.getTotalLength());
- // set the element lines
- element.setLines(classSpecifier.getTopLine(), classSpecifier.getBottomLine());
- }
-
- this.newElements.put(element, element.getElementInfo());
- return element;
- }
-
- protected TypeDef createTypeDef(Parent parent, Declarator declarator, SimpleDeclaration simpleDeclaration){
- // create the element
- Name domName = getDOMName(declarator);
- if (domName == null) {
- // Something is wrong, skip this element
- return null;
- }
-
- String declaratorName = domName.toString();
-
- TypeDef element = new TypeDef( parent, declaratorName );
-
- StringBuffer typeName = new StringBuffer(getType(simpleDeclaration, declarator));
- element.setTypeName(typeName.toString());
-
- // add to parent
- parent.addChild((CElement)element);
-
- // set positions
- element.setIdPos(domName.getStartOffset(), domName.length());
- element.setPos(simpleDeclaration.getStartingOffset(), simpleDeclaration.getTotalLength());
- // set the element lines
- element.setLines(simpleDeclaration.getTopLine(), simpleDeclaration.getBottomLine());
-
- this.newElements.put(element, element.getElementInfo());
- return element;
- }
-
- protected VariableDeclaration createVariableSpecification(Parent parent, SimpleDeclaration simpleDeclaration, Declarator declarator, boolean isTemplate)
- {
- Name domName = getDOMName(declarator);
- if (domName == null) {
- // TODO : improve errorhandling
- // When parsing syntactically incorrect code, we might
- // end up here. Most often, function/method declaration
- // misses return type, and is neither a constructor nor
- // a conversion operator. Like
- // A::B() {}
- // Parser sees A::B, understands that it is not a constructor
- // /conversion, then considers it a declaration. So its
- // type is read as A::B, no name, and a list of declarations
- // in ().
- // For now, we just ignore this scenario (and create no
- // model elements), but in the future we can process this
- // declaration as a function (with undefined/no type)
- return null;
- }
-
- String variableName = domName.toString();
- DeclSpecifier declSpecifier = simpleDeclaration.getDeclSpecifier();
-
- VariableDeclaration element = null;
- if(parent instanceof IStructure){
- // field
- Field newElement = new Field( parent, variableName);
- newElement.setMutable(declSpecifier.isMutable());
- newElement.setVisibility(simpleDeclaration.getAccessSpecifier().getAccess());
- element = newElement;
- }
- else {
- if(isTemplate){
- // variable
- VariableTemplate newElement = new VariableTemplate( parent, variableName );
- element = newElement;
- }else {
- if(declSpecifier.isExtern()){
- // variableDeclaration
- VariableDeclaration newElement = new VariableDeclaration( parent, variableName );
- element = newElement;
- }
- else {
- // variable
- Variable newElement = new Variable( parent, variableName );
- element = newElement;
- }
- }
- }
- element.setTypeName ( getType(simpleDeclaration, declarator) );
- element.setConst(declSpecifier.isConst());
- element.setVolatile(declSpecifier.isVolatile());
- element.setStatic(declSpecifier.isStatic());
- // add to parent
- parent.addChild( element );
-
- // set position
- element.setIdPos( domName.getStartOffset(), domName.length() );
- if(!isTemplate){
- // set element position
- element.setPos(simpleDeclaration.getStartingOffset(), simpleDeclaration.getTotalLength());
- // set the element lines
- element.setLines(simpleDeclaration.getTopLine(), simpleDeclaration.getBottomLine());
- }
-
- this.newElements.put(element, element.getElementInfo());
- return element;
- }
-
- protected FunctionDeclaration createFunctionSpecification(Parent parent, SimpleDeclaration simpleDeclaration, Declarator declarator, boolean isTemplate)
- {
- Name domName = getDOMName(declarator);
- if (domName == null) {
- // Something is wrong, skip this element
- return null;
- }
-
- String declaratorName = domName.toString();
- DeclSpecifier declSpecifier = simpleDeclaration.getDeclSpecifier();
-
- // get parameters types
- String[] parameterTypes = getFunctionParameterTypes(declarator);
-
- FunctionDeclaration element = null;
-
- if( parent instanceof IStructure )
- {
- if (simpleDeclaration.isFunctionDefinition())
- {
- // method
- if(!isTemplate){
- Method newElement = new Method( parent, declaratorName );
- newElement.setVisibility(simpleDeclaration.getAccessSpecifier().getAccess());
- element = newElement;
- }else {
- MethodTemplate newElement = new MethodTemplate(parent, declaratorName);
- newElement.setVisibility(simpleDeclaration.getAccessSpecifier().getAccess());
- element = newElement;
- }
- }
- else
- {
- // method declaration
- if(!isTemplate){
- MethodDeclaration newElement = new MethodDeclaration( parent, declaratorName );
- newElement.setVisibility(simpleDeclaration.getAccessSpecifier().getAccess());
- element = newElement;
- }else {
- MethodTemplate newElement = new MethodTemplate(parent, declaratorName);
- newElement.setVisibility(simpleDeclaration.getAccessSpecifier().getAccess());
- element = newElement;
- }
-
- }
- }
- else if(( parent instanceof ITranslationUnit )
- || ( parent instanceof INamespace ))
- {
- if (simpleDeclaration.isFunctionDefinition())
- {
- // if it belongs to a class, then create a method
- // else create a function
- // this will not be known until we have cross reference information
-
- // function
- if(!isTemplate){
- Function newElement = new Function( parent, declaratorName );
- element = newElement;
- } else {
- FunctionTemplate newElement = new FunctionTemplate( parent, declaratorName );
- element = newElement;
- }
- }
- else
- {
- // functionDeclaration
- if(!isTemplate){
- FunctionDeclaration newElement = new FunctionDeclaration( parent, declaratorName );
- element = newElement;
- } else {
- FunctionTemplate newElement = new FunctionTemplate( parent, declaratorName );
- element = newElement;
- }
- }
- }
- element.setParameterTypes(parameterTypes);
- element.setReturnType( getFunctionReturnType(simpleDeclaration, declarator) );
- element.setVolatile(declSpecifier.isVolatile());
- element.setStatic(declSpecifier.isStatic());
- element.setConst(declarator.isConst());
-
- // add to parent
- parent.addChild( element );
-
- // hook up the offsets
- element.setIdPos( domName.getStartOffset(), domName.length() );
- if(!isTemplate){
- // set the element position
- element.setPos(simpleDeclaration.getStartingOffset(), simpleDeclaration.getTotalLength());
- // set the element lines
- element.setLines(simpleDeclaration.getTopLine(), simpleDeclaration.getBottomLine());
- }
-
- this.newElements.put(element, element.getElementInfo());
- return element;
- }
-
-
- private String[] getTemplateParameters(ITemplateParameterListOwner templateDeclaration){
- // add the parameters
- List templateParameters = templateDeclaration.getTemplateParms().getDeclarations();
- Iterator i = templateParameters.iterator();
- String[] parameterTypes = new String[templateParameters.size()];
-
- for( int j = 0; j< templateParameters.size(); ++j ){
- StringBuffer paramType = new StringBuffer();
- Declaration decl = (Declaration)templateParameters.get(j);
- if(decl instanceof TemplateParameter){
- TemplateParameter parameter = (TemplateParameter) decl;
- if(parameter.getName() != null){
- paramType.append(parameter.getName().toString());
- }else {
- int kind = parameter.getKind();
- switch (kind){
- case TemplateParameter.k_class:
- paramType.append("class");
- break;
- case TemplateParameter.k_typename:
- paramType.append("typename");
- break;
- case TemplateParameter.k_template:
- paramType.append("template<");
- String[] subParams =getTemplateParameters(parameter);
- int p = 0;
- if ( subParams.length > 0)
- paramType.append(subParams[p++]);
- while( p < subParams.length){
- paramType.append(", ");
- paramType.append(subParams[p++]);
- }
- paramType.append(">");
- break;
- default:
- break;
- } // switch
- }
- } else if(decl instanceof ParameterDeclaration){
- ParameterDeclaration parameter = (ParameterDeclaration) decl;
- paramType.append(getType(parameter, (Declarator)parameter.getDeclarators().get(0)));
- }
- parameterTypes[j] = new String(paramType.toString());
- } // end for
- return parameterTypes;
- }
-
- private String getType(Declaration declaration, Declarator declarator)
- {
- StringBuffer type = new StringBuffer();
-
- // get type from declaration
- type.append(getDeclarationType(declaration));
-
- type.append(getSubType(declarator, new SubTypeProcessingFlags(false)));
-
- return type.toString();
- }
-
- private String getFunctionReturnType(Declaration declaration, Declarator declarator)
- {
- StringBuffer type = new StringBuffer();
-
- // get type from declaration
- type.append(getDeclarationType(declaration));
-
- type.append(getSubType(declarator, new SubTypeProcessingFlags(true)));
-
- return type.toString();
- }
-
- private class SubTypeProcessingFlags {
- boolean returnTypeForFunction = false;
- boolean processedInnermostParameterList = false;
-
- SubTypeProcessingFlags(boolean returnTypeForFunction) {
- this.returnTypeForFunction = returnTypeForFunction;
- }
- }
-
- private String getSubType(Declarator declarator, SubTypeProcessingFlags flags) {
- StringBuffer type = new StringBuffer();
-
- // add pointer or reference from declarator if any
- String declaratorPointerOperation = getDeclaratorPointerOperation(declarator);
- try {
- switch (declaratorPointerOperation.charAt(0)) {
- case '*':
- case '&':
- break; // pointer/reference
- default:
- type.append(" "); // pointer to member
- }
- } catch (Exception e) {} // Empty/null strings
- type.append(declaratorPointerOperation);
-
- String subType = null;
-
- if (declarator.getDeclarator() != null){
- // process inner declarator
- subType = getSubType(declarator.getDeclarator(), flags);
- boolean appendParen = true;
-
- if ( (subType == null) || (subType.length() == 0)
- ||
- ((subType.charAt(0) == '(')
- &&
- (subType.charAt(subType.length()-1) == ')'))) {
-
- // Additional () are not necessary
- appendParen = false;
- }
-
- if (appendParen) type.append("(");
- type.append(subType);
- if (appendParen) type.append(")");
- }
-
- // parameters
- if (declarator.getParms() != null) {
- // If we process return type for a function,
- // skip innermost parameter list - it is a part
- // of function's signature
- if ( !flags.returnTypeForFunction
- || flags.processedInnermostParameterList) {
-
- if ((subType == null) || (subType.length() == 0)) {
- type.append("()");
- }
-
- type.append(getParametersString(declarator));
- }
- flags.processedInnermostParameterList = true;
- }
-
- // arrays
- type.append(getDeclaratorArrayQualifiers(declarator));
-
- return type.toString();
- }
-
-
- /**
- * Here is a tricky one. Determines if a declarator represents a function
- * specification, or a variable declaration (that includes pointers to functions).
- * If none of the nested declarators contain parameter list, then it is obviously a variable.
- * It is a function specification only if no declarators in (A..B] range
- * contain any pointer/array specificators. A is the declarator containing
- * the innermost parameter list (which corresponds to parameters of the function),
- * and B is the innermost declarator (should contain the name of the element).
- *
- * @param declarator
- * @return True, if the declarator represents a function specification
- */
-
- private boolean isFunctionSpecification(Declarator declarator)
- {
- Declarator currentDeclarator = declarator;
- boolean result = false;
-
- while (currentDeclarator != null) {
- if (currentDeclarator.getParms() != null) {
- result = true;
- } else {
- List ptrOps = currentDeclarator.getPointerOperators();
- List arrayQs = currentDeclarator.getArrayQualifiers();
-
- if ( ((ptrOps != null) && (ptrOps.size() > 0))
- || ((arrayQs != null) && (arrayQs.size() > 0))
- )
- {
- result = false;
- }
- }
-
- currentDeclarator = currentDeclarator.getDeclarator();
- }
-
- return result;
- }
-
-
- private String getDeclarationType(Declaration declaration){
- StringBuffer type = new StringBuffer();
- if(declaration instanceof ParameterDeclaration){
- ParameterDeclaration paramDeclaration = (ParameterDeclaration) declaration;
- if(paramDeclaration.getDeclSpecifier().isConst())
- type.append("const ");
- if(paramDeclaration.getDeclSpecifier().isVolatile())
- type.append("volatile ");
- TypeSpecifier typeSpecifier = paramDeclaration.getTypeSpecifier();
- if(typeSpecifier == null){
- type.append(paramDeclaration.getDeclSpecifier().getTypeName());
- }
- else if(typeSpecifier instanceof ElaboratedTypeSpecifier){
- ElaboratedTypeSpecifier elab = (ElaboratedTypeSpecifier) typeSpecifier;
- type.append(getElaboratedTypeSignature(elab));
- }
- }
-
- if(declaration instanceof SimpleDeclaration){
- SimpleDeclaration simpleDeclaration = (SimpleDeclaration) declaration;
- if(simpleDeclaration.getDeclSpecifier().isConst())
- type.append("const ");
- if(simpleDeclaration.getDeclSpecifier().isVolatile())
- type.append("volatile ");
- TypeSpecifier typeSpecifier = simpleDeclaration.getTypeSpecifier();
- if(typeSpecifier == null){
- type.append(simpleDeclaration.getDeclSpecifier().getTypeName());
- }
- else if(typeSpecifier instanceof ElaboratedTypeSpecifier){
- ElaboratedTypeSpecifier elab = (ElaboratedTypeSpecifier) typeSpecifier;
- type.append(getElaboratedTypeSignature(elab));
- }
- }
-
- return type.toString();
- }
-
- private String getElaboratedTypeSignature(ElaboratedTypeSpecifier elab){
- StringBuffer type = new StringBuffer();
- int t = elab.getClassKey();
- switch (t){
- case ClassKey.t_class:
- type.append("class");
- break;
- case ClassKey.t_struct:
- type.append("struct");
- break;
- case ClassKey.t_union:
- type.append("union");
- break;
- case ClassKey.t_enum:
- type.append("enum");
- break;
- };
- type.append(" ");
- type.append(elab.getName().toString());
- return type.toString();
- }
-
- private String getDeclaratorPointerOperation(Declarator declarator){
- StringBuffer pointerString = new StringBuffer();
- List pointerOperators = declarator.getPointerOperators();
- if(pointerOperators != null) {
- Iterator i = pointerOperators.iterator();
- while(i.hasNext()){
- PointerOperator po = (PointerOperator) i.next();
- switch (po.getType()){
- case PointerOperator.t_pointer_to_member:
- pointerString.append(po.getNameSpecifier());
- // Intentional fall-through
- case PointerOperator.t_pointer:
- pointerString.append("*");
- break;
- case PointerOperator.t_reference:
- pointerString.append("&");
- break;
- }
-
- if(po.isConst())
- pointerString.append(" const");
- if(po.isVolatile())
- pointerString.append(" volatile");
- }
- }
- return pointerString.toString();
- }
-
- private String getDeclaratorArrayQualifiers(Declarator declarator){
- StringBuffer arrayString = new StringBuffer();
- List arrayQualifiers = declarator.getArrayQualifiers();
- if(arrayQualifiers != null){
- Iterator i = arrayQualifiers.iterator();
- while (i.hasNext()){
- ArrayQualifier q = (ArrayQualifier) i.next();
- arrayString.append("[]");
- }
- }
- return arrayString.toString();
- }
-
-
- private String[] getParameterTypes(Declarator declarator)
- {
- return getParameterTypes(declarator, null);
- }
-
- private String[] getParameterTypes(Declarator declarator, HashMap mapOfKRParams)
- {
- if (declarator == null) return null;
-
- ParameterDeclarationClause pdc = declarator.getParms();
- String[] parameterTypes = null;
-
- if (pdc != null) {
- List parameterList = pdc.getDeclarations();
- parameterTypes = new String[parameterList.size()];
-
- for (int j = 0; j < parameterList.size(); ++j) {
- ParameterDeclaration param = (ParameterDeclaration) parameterList.get(j);
- Declarator decl = (Declarator) param.getDeclarators().get(0);
- parameterTypes[j] = getType(param, decl);
-
- if ( (mapOfKRParams != null)
- && (mapOfKRParams.size() > 0)
- && (decl.getName() == null))
- {
- // We have some K&R-style parameter declarations,
- // and the current parameter has been declared with a single identifier,
- // (like ...(argname)...)
- // It has been parsed as a typename, so 'argname' is a name of the type,
- // and parameter name is empty. But for this particular case,
- // 'argname' is a name, and its type we have to lookup in the map
- // of old K&R-style parameter declarations.
- // If we can't find it, we keep parameter name in the signature
- String oldKRParamType = (String)mapOfKRParams.get(parameterTypes[j]);
- if (oldKRParamType != null) {
- parameterTypes[j] = oldKRParamType;
- }
- }
- }
- }
-
- return parameterTypes;
- }
-
- private String[] getFunctionParameterTypes(Declarator declarator)
- {
- Declarator currentDeclarator = declarator;
- Declarator innermostPDCDeclarator = null;
-
- while (currentDeclarator != null) {
- if (currentDeclarator.getParms() != null) {
- innermostPDCDeclarator = currentDeclarator;
- }
- currentDeclarator = currentDeclarator.getDeclarator();
- }
-
- HashMap mapOfKRParams = null;
-
- if ( declarator != null
- && declarator.getParms() != null
- && declarator.getParms().getOldKRParms() != null) {
-
- mapOfKRParams = new HashMap();
-
- OldKRParameterDeclarationClause oldKRpdc = declarator.getParms().getOldKRParms();
- List oldKRParameterList = oldKRpdc.getDeclarations();
-
- for (int j = 0; j < oldKRParameterList.size(); ++j) {
- if(oldKRParameterList.get(j) instanceof SimpleDeclaration) { // Must be
- SimpleDeclaration declKR = (SimpleDeclaration)oldKRParameterList.get(j);
-
- List declarators = declKR.getDeclarators();
- Iterator d = declarators.iterator();
- while (d.hasNext()) {
- Declarator decl = (Declarator) d.next();
-
- Name oldKRparamName = getDOMName(decl);
- String oldKRparamType = getType(declKR, decl);
-
- if ( (oldKRparamType != null)
- && (oldKRparamName != null)
- && (oldKRparamName.toString().length() > 0)
- ) {
- mapOfKRParams.put(oldKRparamName.toString(), oldKRparamType);
- }
- }
- }
- }
- }
-
- return getParameterTypes(innermostPDCDeclarator, mapOfKRParams);
- }
-
- private String getParametersString(String[] parameterTypes)
- {
- StringBuffer parameters = new StringBuffer("");
-
- if ((parameterTypes != null) && (parameterTypes.length > 0)) {
- parameters.append("(");
- int i = 0;
- parameters.append(parameterTypes[i++]);
- while (i < parameterTypes.length) {
- parameters.append(", ");
- parameters.append(parameterTypes[i++]);
- }
- parameters.append(")");
- } else {
- if (parameterTypes != null) parameters.append("()");
- }
-
- return parameters.toString();
- }
-
- private String getParametersString(Declarator declarator)
- {
- return getParametersString(getParameterTypes(declarator));
- }
-
- private Name getDOMName(Declarator declarator)
- {
- Declarator currentDeclarator = declarator;
- Name name = null;
-
- if (currentDeclarator != null) {
- while (currentDeclarator.getDeclarator() != null) {
- currentDeclarator = currentDeclarator.getDeclarator();
- }
- }
- // The innermost declarator must contain the name
- if (currentDeclarator != null) {
- name = currentDeclarator.getName();
- }
-
- return name;
- }
-}
Index: parser/org/eclipse/cdt/internal/core/parser/Parser.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java,v
retrieving revision 1.54
diff -u -r1.54 Parser.java
--- parser/org/eclipse/cdt/internal/core/parser/Parser.java 18 Jun 2003 19:36:20 -0000 1.54
+++ parser/org/eclipse/cdt/internal/core/parser/Parser.java 23 Jun 2003 17:56:45 -0000
@@ -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 @@
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 @@
* @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 @@
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 @@
catch( Backtrack bt )
{
try { callback.constructorChainAbort( constructorChain );} catch( Exception e ) {}
- if( ! quickParse )
+ if( mode != ParserMode.QUICK_PARSE )
throw backtrack;
}
Index: parser/org/eclipse/cdt/internal/core/parser/ParserFactory.java
===================================================================
RCS file: parser/org/eclipse/cdt/internal/core/parser/ParserFactory.java
diff -N parser/org/eclipse/cdt/internal/core/parser/ParserFactory.java
--- parser/org/eclipse/cdt/internal/core/parser/ParserFactory.java 13 Jun 2003 15:01:22 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,30 +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;
-
-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 static IASTFactory createASTFactory( boolean quickParse )
- {
- if( quickParse )
- return new QuickParseASTFactory();
- else
- return new FullParseASTFactory();
- }
-}
Index: parser/org/eclipse/cdt/internal/core/parser/Preprocessor.java
===================================================================
RCS file: parser/org/eclipse/cdt/internal/core/parser/Preprocessor.java
diff -N parser/org/eclipse/cdt/internal/core/parser/Preprocessor.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ parser/org/eclipse/cdt/internal/core/parser/Preprocessor.java 23 Jun 2003 17:56:45 -0000
@@ -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
+ }
+ }
+}
Index: parser/org/eclipse/cdt/internal/core/parser/Scanner.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java,v
retrieving revision 1.32
diff -u -r1.32 Scanner.java
--- parser/org/eclipse/cdt/internal/core/parser/Scanner.java 20 Jun 2003 17:15:59 -0000 1.32
+++ parser/org/eclipse/cdt/internal/core/parser/Scanner.java 23 Jun 2003 17:56:46 -0000
@@ -21,6 +21,7 @@
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.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 @@
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 @@
} 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 void overwriteIncludePath(List newIncludePaths) {
+ if( newIncludePaths == null ) return;
includePathNames = null;
includePaths = null;
includePathNames = new ArrayList();
@@ -223,7 +216,7 @@
}
}
- private void setCurrentToken(Token t) {
+ private void setCurrentToken(IToken t) {
if (currentToken != null)
currentToken.setNext(t);
currentToken = t;
@@ -235,12 +228,12 @@
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 @@
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 @@
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 @@
}
- 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 @@
//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 @@
// 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 @@
String error = getRestOfPreprocessorLine();
- if (!quickScan) {
+ if (mode == ParserMode.COMPLETE_PARSE) {
throw new ScannerException("#error " + error);
}
c = getChar();
@@ -1379,7 +1373,7 @@
// 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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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();
Index: parser/org/eclipse/cdt/internal/core/parser/Token.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Token.java,v
retrieving revision 1.15
diff -u -r1.15 Token.java
--- parser/org/eclipse/cdt/internal/core/parser/Token.java 20 Jun 2003 17:15:59 -0000 1.15
+++ parser/org/eclipse/cdt/internal/core/parser/Token.java 23 Jun 2003 17:56:46 -0000
@@ -61,9 +61,9 @@
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()
{
@@ -139,6 +139,13 @@
default:
return false;
}
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.IToken#setImage()
+ */
+ public void setImage( String i ) {
+ image = i;
}
}
Index: parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTClassSpecifier.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTClassSpecifier.java,v
retrieving revision 1.3
diff -u -r1.3 ASTClassSpecifier.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTClassSpecifier.java 13 Jun 2003 20:03:15 -0000 1.3
+++ parser/org/eclipse/cdt/internal/core/parser/ast/full/ASTClassSpecifier.java 23 Jun 2003 17:56:46 -0000
@@ -138,7 +138,7 @@
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTClassSpecifier#getCurrentVisiblity()
*/
- public AccessVisibility getCurrentVisiblity() {
+ public AccessVisibility getCurrentVisibilityMode() {
// TODO Auto-generated method stub
return null;
}
Index: parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTClassSpecifier.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTClassSpecifier.java,v
retrieving revision 1.1
diff -u -r1.1 ASTClassSpecifier.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTClassSpecifier.java 13 Jun 2003 20:03:14 -0000 1.1
+++ parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTClassSpecifier.java 23 Jun 2003 17:56:46 -0000
@@ -76,7 +76,7 @@
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTClassSpecifier#getCurrentVisiblity()
*/
- public AccessVisibility getCurrentVisiblity() {
+ public AccessVisibility getCurrentVisibilityMode() {
return access;
}