mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 06:05:24 +02:00
Broke the Parser up into separate classes per ParserMode.
This commit is contained in:
parent
8a0a4cb710
commit
4ec086bfd1
5 changed files with 124 additions and 29 deletions
|
@ -1,3 +1,6 @@
|
|||
2003-12-05 John Camelon
|
||||
Broke the Parser up into separate classes per ParserMode.
|
||||
|
||||
2003-12-04 John Camelon
|
||||
Removed some warnings.
|
||||
Fixed Bug 39678 : Scanner doesn't support concatenation of different-type string literals (GCC)
|
||||
|
|
|
@ -13,10 +13,11 @@ package org.eclipse.cdt.core.parser;
|
|||
import java.io.Reader;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.CompleteParser;
|
||||
import org.eclipse.cdt.internal.core.parser.LineOffsetReconciler;
|
||||
import org.eclipse.cdt.internal.core.parser.Parser;
|
||||
import org.eclipse.cdt.internal.core.parser.Preprocessor;
|
||||
import org.eclipse.cdt.internal.core.parser.QuickParseCallback;
|
||||
import org.eclipse.cdt.internal.core.parser.QuickParser;
|
||||
import org.eclipse.cdt.internal.core.parser.Scanner;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.complete.CompleteParseASTFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.quick.QuickParseASTFactory;
|
||||
|
@ -42,8 +43,11 @@ public class ParserFactory {
|
|||
if( language == null ) throw new ParserFactoryException( ParserFactoryException.Kind.NULL_LANGUAGE );
|
||||
IParserLogService logService = ( log == null ) ? createDefaultLogService() : log;
|
||||
ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode );
|
||||
ISourceElementRequestor ourCallback = (( callback == null) ? new NullSourceElementRequestor() : callback );
|
||||
return new Parser( scanner, ourCallback, ourMode, language, logService );
|
||||
ISourceElementRequestor ourCallback = (( callback == null) ? new NullSourceElementRequestor() : callback );
|
||||
if( ourMode == ParserMode.COMPLETE_PARSE)
|
||||
return new CompleteParser( scanner, ourCallback, language, logService );
|
||||
else
|
||||
return new QuickParser( scanner, ourCallback, language, logService );
|
||||
}
|
||||
|
||||
public static IScanner createScanner( Reader input, String fileName, IScannerInfo config, ParserMode mode, ParserLanguage language, ISourceElementRequestor requestor, IParserLogService log ) throws ParserFactoryException
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Created on Dec 5, 2003
|
||||
*
|
||||
* To change the template for this generated file go to
|
||||
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.parser;
|
||||
|
||||
import org.eclipse.cdt.core.parser.Backtrack;
|
||||
import org.eclipse.cdt.core.parser.EndOfFile;
|
||||
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.ParserFactory;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
* To change the template for this generated type comment go to
|
||||
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||
*/
|
||||
public class CompleteParser extends Parser {
|
||||
|
||||
/**
|
||||
* @param scanner
|
||||
* @param callback
|
||||
* @param mode
|
||||
* @param language
|
||||
* @param log
|
||||
*/
|
||||
public CompleteParser(IScanner scanner, ISourceElementRequestor callback, ParserLanguage language, IParserLogService log) {
|
||||
super(scanner, callback, language, log);
|
||||
astFactory = ParserFactory.createASTFactory( ParserMode.COMPLETE_PARSE, language);
|
||||
scanner.setASTFactory(astFactory);
|
||||
}
|
||||
|
||||
protected void handleFunctionBody(IASTScope scope, boolean isInlineFunction) throws Backtrack, EndOfFile
|
||||
{
|
||||
if ( isInlineFunction )
|
||||
skipOverCompoundStatement();
|
||||
else
|
||||
functionBody(scope);
|
||||
}
|
||||
|
||||
protected void catchBlockCompoundStatement(IASTScope scope) throws Backtrack, EndOfFile
|
||||
{
|
||||
compoundStatement(scope, true);
|
||||
}
|
||||
|
||||
}
|
|
@ -22,9 +22,7 @@ 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.ITokenDuple;
|
||||
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.ScannerException;
|
||||
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
|
||||
|
@ -69,7 +67,7 @@ import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind;
|
|||
*
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class Parser implements IParser
|
||||
public abstract class Parser implements IParser
|
||||
{
|
||||
protected final IParserLogService log;
|
||||
private static final List EMPTY_LIST = new ArrayList();
|
||||
|
@ -78,13 +76,12 @@ public class Parser implements IParser
|
|||
private int firstErrorOffset = DEFAULT_OFFSET;
|
||||
// offset where the first parse error occurred
|
||||
|
||||
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 ParserLanguage language = ParserLanguage.CPP; // C or CPP
|
||||
private ISourceElementRequestor requestor = null;
|
||||
// new callback mechanism
|
||||
private IASTFactory astFactory = null; // ast factory
|
||||
protected IASTFactory astFactory = null; // ast factory
|
||||
/**
|
||||
* This is the single entry point for setting parsePassed to
|
||||
* false, and also making note what token offset we failed upon.
|
||||
|
@ -117,15 +114,12 @@ public class Parser implements IParser
|
|||
public Parser(
|
||||
IScanner scanner,
|
||||
ISourceElementRequestor callback,
|
||||
ParserMode mode,
|
||||
ParserLanguage language, IParserLogService log )
|
||||
ParserLanguage language,
|
||||
IParserLogService log )
|
||||
{
|
||||
this.scanner = scanner;
|
||||
requestor = callback;
|
||||
this.mode = mode;
|
||||
this.language = language;
|
||||
astFactory = ParserFactory.createASTFactory( mode, language);
|
||||
scanner.setASTFactory(astFactory);
|
||||
this.log = log;
|
||||
}
|
||||
// counter that keeps track of the number of times Parser.parse() is called
|
||||
|
@ -1060,17 +1054,8 @@ public class Parser implements IParser
|
|||
}
|
||||
|
||||
}
|
||||
protected void handleFunctionBody(IASTScope scope, boolean isInlineFunction) throws Backtrack, EndOfFile
|
||||
{
|
||||
if ( mode == ParserMode.QUICK_PARSE || isInlineFunction )
|
||||
{
|
||||
skipOverCompoundStatement();
|
||||
}
|
||||
else
|
||||
{
|
||||
functionBody(scope);
|
||||
}
|
||||
}
|
||||
protected abstract void handleFunctionBody(IASTScope scope, boolean isInlineFunction) throws Backtrack, EndOfFile;
|
||||
|
||||
protected void skipOverCompoundStatement() throws Backtrack, EndOfFile
|
||||
{
|
||||
// speed up the parser by skiping the body
|
||||
|
@ -3034,13 +3019,13 @@ public class Parser implements IParser
|
|||
declaration(scope, null); // was exceptionDeclaration
|
||||
consume(IToken.tRPAREN);
|
||||
|
||||
if( mode == ParserMode.COMPLETE_PARSE )
|
||||
compoundStatement(scope, true);
|
||||
else
|
||||
skipOverCompoundStatement();
|
||||
catchBlockCompoundStatement(scope);
|
||||
}
|
||||
}
|
||||
protected void singleStatementScope(IASTScope scope) throws Backtrack
|
||||
|
||||
protected abstract void catchBlockCompoundStatement(IASTScope scope) throws Backtrack, EndOfFile;
|
||||
|
||||
protected void singleStatementScope(IASTScope scope) throws Backtrack
|
||||
{
|
||||
IASTCodeScope newScope;
|
||||
try
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Created on Dec 5, 2003
|
||||
*
|
||||
* To change the template for this generated file go to
|
||||
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.parser;
|
||||
|
||||
import org.eclipse.cdt.core.parser.Backtrack;
|
||||
import org.eclipse.cdt.core.parser.EndOfFile;
|
||||
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.ParserFactory;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
* To change the template for this generated type comment go to
|
||||
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||
*/
|
||||
public class QuickParser extends Parser {
|
||||
|
||||
/**
|
||||
* @param scanner
|
||||
* @param callback
|
||||
* @param mode
|
||||
* @param language
|
||||
* @param log
|
||||
*/
|
||||
public QuickParser(IScanner scanner, ISourceElementRequestor callback, ParserLanguage language, IParserLogService log) {
|
||||
super(scanner, callback, language, log);
|
||||
astFactory = ParserFactory.createASTFactory( ParserMode.QUICK_PARSE, language);
|
||||
scanner.setASTFactory(astFactory);
|
||||
}
|
||||
|
||||
protected void handleFunctionBody(IASTScope scope, boolean isInlineFunction) throws Backtrack, EndOfFile
|
||||
{
|
||||
skipOverCompoundStatement();
|
||||
}
|
||||
|
||||
protected void catchBlockCompoundStatement(IASTScope scope) throws Backtrack, EndOfFile
|
||||
{
|
||||
skipOverCompoundStatement();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue