1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 06:45:43 +02:00

Switch DOM tests to use DOMScanner.

Updated DOMScanner constructor.
Added __asm__ macro to GNUScannerConfiguration
This commit is contained in:
John Camelon 2004-12-15 15:55:55 +00:00
parent cac97aa220
commit 8e1dc14197
6 changed files with 56 additions and 41 deletions

View file

@ -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 )
{

View file

@ -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)

View file

@ -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;

View file

@ -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);
}

View file

@ -31,6 +31,10 @@ public abstract class GNUScannerConfiguration implements IScannerConfiguration {
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;
}

View file

@ -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;
}
}