From 8e1dc14197d8f7ce709b3345a7a84a4e486efc4a Mon Sep 17 00:00:00 2001 From: John Camelon Date: Wed, 15 Dec 2004 15:55:55 +0000 Subject: [PATCH] Switch DOM tests to use DOMScanner. Updated DOMScanner constructor. Added __asm__ macro to GNUScannerConfiguration --- .../core/parser/tests/ast2/AST2BaseTest.java | 23 +++++++++++-------- .../tests/parser2/CompleteParser2Tests.java | 22 ++++++++++++------ .../tests/parser2/QuickParser2Tests.java | 21 +++++++++++------ .../core/parser/scanner2/DOMScanner.java | 13 +++++++---- .../scanner2/GNUScannerConfiguration.java | 5 ++++ .../scanner2/GPPScannerConfiguration.java | 13 ----------- 6 files changed, 56 insertions(+), 41 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java index 9ac627c41b1..82eced9759b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java @@ -15,7 +15,6 @@ package org.eclipse.cdt.core.parser.tests.ast2; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import junit.framework.TestCase; @@ -37,14 +36,12 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IScanner; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.NullLogService; -import org.eclipse.cdt.core.parser.NullSourceElementRequestor; -import org.eclipse.cdt.core.parser.ParserFactory; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ScannerInfo; import org.eclipse.cdt.core.parser.tests.parser2.ProblemCollector; +import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory; import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser; import org.eclipse.cdt.internal.core.dom.parser.c.ANSICParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; @@ -55,13 +52,16 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPParserExtensionConfiguration; import org.eclipse.cdt.internal.core.parser.ParserException; +import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner; +import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerConfiguration; +import org.eclipse.cdt.internal.core.parser.scanner2.GPPScannerConfiguration; +import org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration; /** * @author aniefer */ public class AST2BaseTest extends TestCase { - private static final ISourceElementRequestor NULL_REQUESTOR = new NullSourceElementRequestor(); private static final IParserLogService NULL_LOG = new NullLogService(); /** @@ -72,10 +72,15 @@ public class AST2BaseTest extends TestCase { */ protected IASTTranslationUnit parse( String code, ParserLanguage lang ) throws ParserException { ProblemCollector collector = new ProblemCollector(); - IScanner scanner = ParserFactory.createScanner(new CodeReader(code - .toCharArray()), new ScannerInfo(), ParserMode.COMPLETE_PARSE, - lang, NULL_REQUESTOR, - NULL_LOG, Collections.EMPTY_LIST); + CodeReader codeReader = new CodeReader(code + .toCharArray()); + ScannerInfo scannerInfo = new ScannerInfo(); + IScannerConfiguration configuration = null; + if( lang == ParserLanguage.C ) + configuration = new GCCScannerConfiguration(); + else + configuration = new GPPScannerConfiguration(); + IScanner scanner = new DOMScanner( codeReader, scannerInfo, ParserMode.COMPLETE_PARSE, lang, NULL_LOG, configuration, SavedCodeReaderFactory.getInstance() ); ISourceCodeParser parser2 = null; if( lang == ParserLanguage.CPP ) { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/parser2/CompleteParser2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/parser2/CompleteParser2Tests.java index f03ba6009e3..722cdac9889 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/parser2/CompleteParser2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/parser2/CompleteParser2Tests.java @@ -12,7 +12,6 @@ package org.eclipse.cdt.core.parser.tests.parser2; import java.io.StringWriter; import java.io.Writer; -import java.util.Collections; import junit.framework.TestCase; @@ -20,11 +19,10 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.NullLogService; -import org.eclipse.cdt.core.parser.NullSourceElementRequestor; -import org.eclipse.cdt.core.parser.ParserFactory; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ScannerInfo; +import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory; import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser; import org.eclipse.cdt.internal.core.dom.parser.c.ANSICParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.c.GCCParserExtensionConfiguration; @@ -35,6 +33,10 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPParserExtensionConfigu import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPParserExtensionConfiguration; import org.eclipse.cdt.internal.core.parser.ParserException; +import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner; +import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerConfiguration; +import org.eclipse.cdt.internal.core.parser.scanner2.GPPScannerConfiguration; +import org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration; /** * @author jcamelon @@ -42,7 +44,7 @@ import org.eclipse.cdt.internal.core.parser.ParserException; public class CompleteParser2Tests extends TestCase { private static final NullLogService NULL_LOG = new NullLogService(); - private static final NullSourceElementRequestor NULL_REQUESTOR = new NullSourceElementRequestor(); + protected IASTTranslationUnit parse(String code, boolean expectedToPass, ParserLanguage lang) throws Exception { @@ -71,10 +73,16 @@ public class CompleteParser2Tests extends TestCase { ParserLanguage lang, boolean gcc) throws Exception { collector = new ProblemCollector(); - IScanner scanner = ParserFactory.createScanner(new CodeReader(code - .toCharArray()), new ScannerInfo(), ParserMode.COMPLETE_PARSE, - lang, NULL_REQUESTOR, NULL_LOG, Collections.EMPTY_LIST); + CodeReader codeReader = new CodeReader(code + .toCharArray()); + ScannerInfo scannerInfo = new ScannerInfo(); + IScannerConfiguration configuration = null; + if( lang == ParserLanguage.C ) + configuration = new GCCScannerConfiguration(); + else + configuration = new GPPScannerConfiguration(); ISourceCodeParser parser2 = null; + IScanner scanner = new DOMScanner( codeReader, scannerInfo, ParserMode.COMPLETE_PARSE, lang, NULL_LOG, configuration, SavedCodeReaderFactory.getInstance() ); if (lang == ParserLanguage.CPP) { ICPPParserExtensionConfiguration config = null; if (gcc) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/parser2/QuickParser2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/parser2/QuickParser2Tests.java index 75eb7f2d0e6..5918983b9a6 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/parser2/QuickParser2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/parser2/QuickParser2Tests.java @@ -12,18 +12,17 @@ package org.eclipse.cdt.core.parser.tests.parser2; import java.io.IOException; import java.io.StringWriter; import java.io.Writer; -import java.util.Collections; import junit.framework.TestCase; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.IScanner; +import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.NullLogService; -import org.eclipse.cdt.core.parser.NullSourceElementRequestor; -import org.eclipse.cdt.core.parser.ParserFactory; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ScannerInfo; +import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory; import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser; import org.eclipse.cdt.internal.core.dom.parser.c.ANSICParserExtensionConfiguration; import org.eclipse.cdt.internal.core.dom.parser.c.GCCParserExtensionConfiguration; @@ -34,6 +33,10 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPParserExtensionConfigu import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPParserExtensionConfiguration; import org.eclipse.cdt.internal.core.parser.ParserException; +import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner; +import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerConfiguration; +import org.eclipse.cdt.internal.core.parser.scanner2.GPPScannerConfiguration; +import org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration; /** * @author jcamelon @@ -41,7 +44,6 @@ import org.eclipse.cdt.internal.core.parser.ParserException; public class QuickParser2Tests extends TestCase { private static final NullLogService NULL_LOG = new NullLogService(); - private static final NullSourceElementRequestor NULL_REQUESTOR = new NullSourceElementRequestor(); /** * @@ -1355,9 +1357,14 @@ public class QuickParser2Tests extends TestCase { ParserLanguage lang, boolean gcc) throws Exception { ProblemCollector collector = new ProblemCollector(); - IScanner scanner = ParserFactory.createScanner(new CodeReader(code - .toCharArray()), new ScannerInfo(), ParserMode.QUICK_PARSE, - lang, NULL_REQUESTOR, NULL_LOG, Collections.EMPTY_LIST); + CodeReader codeReader = new CodeReader( code.toCharArray() ); + IScannerInfo scannerInfo = new ScannerInfo(); + IScannerConfiguration configuration = null; + if( lang == ParserLanguage.C ) + configuration = new GCCScannerConfiguration(); + else + configuration = new GPPScannerConfiguration(); + IScanner scanner = new DOMScanner( codeReader, scannerInfo, ParserMode.COMPLETE_PARSE, lang, NULL_LOG, configuration, SavedCodeReaderFactory.getInstance() ); ISourceCodeParser parser2 = null; if (lang == ParserLanguage.CPP) { ICPPParserExtensionConfiguration config = null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java index 78e21a815f3..4cb7505c0a2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java @@ -10,8 +10,8 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.parser.scanner2; -import java.util.List; +import org.eclipse.cdt.core.dom.ICodeReaderFactory; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IScannerInfo; @@ -24,18 +24,22 @@ import org.eclipse.cdt.core.parser.ast.IASTFactory; */ public class DOMScanner extends BaseScanner { + private final ICodeReaderFactory codeReaderFactory; + + /** * @param reader * @param info * @param parserMode * @param language * @param log - * @param workingCopies + * @param readerFactory TODO * @param requestor */ - public DOMScanner(CodeReader reader, IScannerInfo info, ParserMode parserMode, ParserLanguage language, IParserLogService log, List workingCopies, IScannerConfiguration configuration) { + public DOMScanner(CodeReader reader, IScannerInfo info, ParserMode parserMode, ParserLanguage language, IParserLogService log, IScannerConfiguration configuration, ICodeReaderFactory readerFactory) { super(reader, info, parserMode, language, log, configuration); this.expressionEvaluator = new ExpressionEvaluator(null, spf); + this.codeReaderFactory = readerFactory; postConstructorSetup(reader, info); } @@ -78,8 +82,7 @@ public class DOMScanner extends BaseScanner { * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#createReaderDuple(java.lang.String) */ protected CodeReader createReaderDuple(String finalPath) { - // TODO Auto-generated method stub - return null; + return codeReaderFactory.createCodeReaderForInclusion(finalPath); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GNUScannerConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GNUScannerConfiguration.java index 31d09d99832..e6760a467c2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GNUScannerConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GNUScannerConfiguration.java @@ -30,6 +30,10 @@ public abstract class GNUScannerConfiguration implements IScannerConfiguration { public char[] supportAdditionalNumericLiteralSuffixes() { return "ij".toCharArray(); //$NON-NLS-1$ } + + private static final ObjectStyleMacro __asm__ = new ObjectStyleMacro( + "__asm__".toCharArray(), "asm".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$ + private static final ObjectStyleMacro __inline__ = new ObjectStyleMacro( "__inline__".toCharArray(), "inline".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$ @@ -108,6 +112,7 @@ public abstract class GNUScannerConfiguration implements IScannerConfiguration { realDefinitions.put(__real__.name, __real__); realDefinitions.put(__builtin_va_arg.name, __builtin_va_arg); realDefinitions.put(__builtin_constant_p.name, __builtin_constant_p); + realDefinitions.put( __asm__.name, __asm__ ); return realDefinitions; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GPPScannerConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GPPScannerConfiguration.java index 557fe48d3b7..56d0113e7f5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GPPScannerConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GPPScannerConfiguration.java @@ -15,7 +15,6 @@ import org.eclipse.cdt.core.parser.IGCCToken; import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.Keywords; import org.eclipse.cdt.core.parser.util.CharArrayIntMap; -import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; /** * @author jcamelon @@ -43,16 +42,4 @@ public class GPPScannerConfiguration extends GNUScannerConfiguration implements return additionalCPPKeywords; } - private static final ObjectStyleMacro __asm__ = new ObjectStyleMacro( - "__asm__".toCharArray(), "asm".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$ - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration#getAdditionalMacros() - */ - public CharArrayObjectMap getAdditionalMacros() { - CharArrayObjectMap result = super.getAdditionalMacros(); - result.put( __asm__.name, __asm__ ); - return result; - } - }