mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Removed the ScannerData object and moved it's fields right into the Scanner.
Made all users of getChar in the scanner call getChar(boolean) directly to remove the extra call to getChar(void). Merged readFromStream in as well. Finally, I have remove the trigraph code to remove the checks for every character. A bug will be raised to reimplement this functionality elsewhere.
This commit is contained in:
parent
9e483cb5fc
commit
bee373939f
6 changed files with 358 additions and 583 deletions
|
@ -36,7 +36,6 @@ public class ParserTestSuite extends TestCase {
|
|||
suite.addTestSuite(StructuralCModelElementsTests.class);
|
||||
suite.addTestSuite(CompletionParseTest.class);
|
||||
// suite.addTestSuite(MacroTests.class);
|
||||
suite.addTestSuite( PreprocessorTest.class );
|
||||
suite.addTestSuite( PreprocessorConditionalTest.class );
|
||||
suite.addTestSuite( QuickParseASTQualifiedNameTest.class);
|
||||
suite.addTestSuite( CompleteParseASTTest.class );
|
||||
|
|
|
@ -1,81 +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.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.ISourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
*/
|
||||
public class PreprocessorTest extends TestCase {
|
||||
|
||||
public static class Callback extends NullSourceElementRequestor
|
||||
{
|
||||
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#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#exitInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion)
|
||||
*/
|
||||
public void exitInclusion(IASTInclusion inclusion) {
|
||||
exitedInc.add( inclusion );
|
||||
}
|
||||
}
|
||||
|
||||
public PreprocessorTest( String name )
|
||||
{
|
||||
super( name );
|
||||
}
|
||||
|
||||
public void testSimpleExample()
|
||||
{
|
||||
Callback c = new Callback();
|
||||
IPreprocessor p = setupPreprocessor( "#include <stdio.h>", //$NON-NLS-1$
|
||||
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.createPreprocessor( new StringReader( text ), "test", new ScannerInfo( defns, //$NON-NLS-1$
|
||||
includePaths == null ? null : (String [])includePaths.toArray()), ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, rq, null, null );
|
||||
return p;
|
||||
}
|
||||
}
|
|
@ -30,7 +30,6 @@ import org.eclipse.cdt.internal.core.parser.ast.complete.CompleteParseASTFactory
|
|||
import org.eclipse.cdt.internal.core.parser.ast.expression.ExpressionParseASTFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.quick.QuickParseASTFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.LineOffsetReconciler;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.Preprocessor;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.Scanner;
|
||||
|
||||
|
||||
|
@ -111,19 +110,6 @@ public class ParserFactory {
|
|||
return s;
|
||||
}
|
||||
|
||||
public static IPreprocessor createPreprocessor( Reader input, String fileName, IScannerInfo info, ParserMode mode, ParserLanguage language, ISourceElementRequestor requestor, IParserLogService logService, List workingCopies )
|
||||
{
|
||||
if( input == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_READER );
|
||||
if( fileName == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_FILENAME );
|
||||
if( info == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_CONFIG );
|
||||
if( language == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_LANGUAGE );
|
||||
IParserLogService log = ( logService == null ) ? createDefaultLogService() : logService;
|
||||
ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode );
|
||||
ISourceElementRequestor ourRequestor = (( requestor == null) ? new NullSourceElementRequestor() : requestor );
|
||||
IPreprocessor s = new Preprocessor( input, fileName, info, ourRequestor, ourMode, language, log, extensionFactory.createScannerExtension(), workingCopies );
|
||||
return s;
|
||||
}
|
||||
|
||||
public static ILineOffsetReconciler createLineOffsetReconciler( Reader input )
|
||||
{
|
||||
return new LineOffsetReconciler( input );
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003 Rational Software Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IPreprocessor;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ScannerException;
|
||||
import org.eclipse.cdt.core.parser.extension.IScannerExtension;
|
||||
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
*/
|
||||
public class Preprocessor extends Scanner implements IPreprocessor {
|
||||
|
||||
/**
|
||||
* @param reader
|
||||
* @param filename
|
||||
* @param defns
|
||||
*/
|
||||
public Preprocessor(Reader reader, String filename, IScannerInfo info, ISourceElementRequestor requestor, ParserMode mode, ParserLanguage language, IParserLogService logService, IScannerExtension scannerExtension, List workingCopies ) {
|
||||
super(reader, filename, info, requestor, mode, language, logService, scannerExtension, workingCopies );
|
||||
}
|
||||
|
||||
public void process()
|
||||
{
|
||||
try
|
||||
{
|
||||
while( true )
|
||||
nextToken();
|
||||
}
|
||||
catch( ScannerException se )
|
||||
{
|
||||
// callback IProblem here
|
||||
scannerData.getLogService().errorLog("Preprocessor Exception "+ se.getProblem().getMessage()); //$NON-NLS-1$h
|
||||
}
|
||||
catch( EndOfFileException eof )
|
||||
{
|
||||
// expected
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,195 +0,0 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003 Rational Software Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator;
|
||||
import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory;
|
||||
|
||||
|
||||
public class ScannerData implements IScannerData
|
||||
{
|
||||
private final List workingCopies;
|
||||
private final ContextStack contextStack;
|
||||
private IASTFactory astFactory = null;
|
||||
private final ISourceElementRequestor requestor;
|
||||
private final ParserMode parserMode;
|
||||
private final String filename;
|
||||
private final Reader reader;
|
||||
private final ParserLanguage language;
|
||||
private final IParserLogService log;
|
||||
private final IProblemFactory problemFactory = new ScannerProblemFactory();
|
||||
private Map definitions = new Hashtable();
|
||||
private BranchTracker branches = new BranchTracker();
|
||||
private final IScanner scanner;
|
||||
private final IScannerInfo originalConfig;
|
||||
private List includePathNames = new ArrayList();
|
||||
|
||||
private final Map privateDefinitions;
|
||||
/**
|
||||
* @return Returns the contextStack.
|
||||
*/
|
||||
public ContextStack getContextStack() {
|
||||
return contextStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param includePathNames The includePathNames to set.
|
||||
*/
|
||||
public void setIncludePathNames(List includePathNames) {
|
||||
this.includePathNames = includePathNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the includePathNames.
|
||||
*/
|
||||
public List getIncludePathNames() {
|
||||
return includePathNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the originalConfig.
|
||||
*/
|
||||
public IScannerInfo getOriginalConfig() {
|
||||
return originalConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the scanner.
|
||||
*/
|
||||
public IScanner getScanner() {
|
||||
return scanner;
|
||||
}
|
||||
|
||||
public IASTFactory getASTFactory()
|
||||
{
|
||||
return astFactory;
|
||||
}
|
||||
|
||||
public void setASTFactory( IASTFactory factory )
|
||||
{
|
||||
astFactory = factory;
|
||||
}
|
||||
|
||||
public BranchTracker getBranchTracker()
|
||||
{
|
||||
return branches;
|
||||
}
|
||||
|
||||
public Map getPublicDefinitions()
|
||||
{
|
||||
return definitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the problemFactory.
|
||||
*/
|
||||
public IProblemFactory getProblemFactory() {
|
||||
return problemFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the filename.
|
||||
*/
|
||||
public String getInitialFilename() {
|
||||
return filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the language.
|
||||
*/
|
||||
public ParserLanguage getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the parserMode.
|
||||
*/
|
||||
public ParserMode getParserMode() {
|
||||
return parserMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the reader.
|
||||
*/
|
||||
public Reader getInitialReader() {
|
||||
return reader;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the requestor.
|
||||
*/
|
||||
public ISourceElementRequestor getClientRequestor() {
|
||||
return requestor;
|
||||
}
|
||||
|
||||
public ScannerData( IScanner scanner, IParserLogService log,
|
||||
ISourceElementRequestor requestor,
|
||||
ParserMode parserMode,
|
||||
String filename,
|
||||
Reader reader,
|
||||
ParserLanguage language, IScannerInfo info, ContextStack stack, List workingCopies )
|
||||
{
|
||||
this.scanner = scanner;
|
||||
this.log = log;
|
||||
this.requestor = requestor;
|
||||
this.parserMode = parserMode;
|
||||
this.filename = filename;
|
||||
this.reader = reader;
|
||||
this.language = language;
|
||||
this.originalConfig = info;
|
||||
this.contextStack = stack;
|
||||
this.workingCopies = workingCopies;
|
||||
privateDefinitions = new Hashtable();
|
||||
}
|
||||
|
||||
|
||||
public IParserLogService getLogService()
|
||||
{
|
||||
return log;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param empty_map
|
||||
*/
|
||||
public void setDefinitions(Map map) {
|
||||
definitions = map;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getWorkingCopies()
|
||||
*/
|
||||
public Iterator getWorkingCopies() {
|
||||
if( workingCopies != null )
|
||||
return workingCopies.iterator();
|
||||
return EmptyIterator.EMPTY_ITERATOR;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getPrivateDefinitions()
|
||||
*/
|
||||
public Map getPrivateDefinitions() {
|
||||
return privateDefinitions;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue