mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-17 13:15:44 +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
|
2003-12-04 John Camelon
|
||||||
Removed some warnings.
|
Removed some warnings.
|
||||||
Fixed Bug 39678 : Scanner doesn't support concatenation of different-type string literals (GCC)
|
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 java.io.Reader;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
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.LineOffsetReconciler;
|
||||||
import org.eclipse.cdt.internal.core.parser.Parser;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.Preprocessor;
|
import org.eclipse.cdt.internal.core.parser.Preprocessor;
|
||||||
import org.eclipse.cdt.internal.core.parser.QuickParseCallback;
|
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.Scanner;
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.complete.CompleteParseASTFactory;
|
import org.eclipse.cdt.internal.core.parser.ast.complete.CompleteParseASTFactory;
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.quick.QuickParseASTFactory;
|
import org.eclipse.cdt.internal.core.parser.ast.quick.QuickParseASTFactory;
|
||||||
|
@ -43,7 +44,10 @@ public class ParserFactory {
|
||||||
IParserLogService logService = ( log == null ) ? createDefaultLogService() : log;
|
IParserLogService logService = ( log == null ) ? createDefaultLogService() : log;
|
||||||
ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode );
|
ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode );
|
||||||
ISourceElementRequestor ourCallback = (( callback == null) ? new NullSourceElementRequestor() : callback );
|
ISourceElementRequestor ourCallback = (( callback == null) ? new NullSourceElementRequestor() : callback );
|
||||||
return new Parser( scanner, ourCallback, ourMode, language, logService );
|
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
|
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.ISourceElementRequestor;
|
||||||
import org.eclipse.cdt.core.parser.IToken;
|
import org.eclipse.cdt.core.parser.IToken;
|
||||||
import org.eclipse.cdt.core.parser.ITokenDuple;
|
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.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
|
||||||
import org.eclipse.cdt.core.parser.ScannerException;
|
import org.eclipse.cdt.core.parser.ScannerException;
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
|
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
|
||||||
|
@ -69,7 +67,7 @@ import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind;
|
||||||
*
|
*
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
*/
|
*/
|
||||||
public class Parser implements IParser
|
public abstract class Parser implements IParser
|
||||||
{
|
{
|
||||||
protected final IParserLogService log;
|
protected final IParserLogService log;
|
||||||
private static final List EMPTY_LIST = new ArrayList();
|
private static final List EMPTY_LIST = new ArrayList();
|
||||||
|
@ -78,13 +76,12 @@ public class Parser implements IParser
|
||||||
private int firstErrorOffset = DEFAULT_OFFSET;
|
private int firstErrorOffset = DEFAULT_OFFSET;
|
||||||
// offset where the first parse error occurred
|
// 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?
|
// are we doing the high-level parse, or an in depth parse?
|
||||||
private boolean parsePassed = true; // did the parse pass?
|
private boolean parsePassed = true; // did the parse pass?
|
||||||
private ParserLanguage language = ParserLanguage.CPP; // C or CPP
|
private ParserLanguage language = ParserLanguage.CPP; // C or CPP
|
||||||
private ISourceElementRequestor requestor = null;
|
private ISourceElementRequestor requestor = null;
|
||||||
// new callback mechanism
|
// 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
|
* This is the single entry point for setting parsePassed to
|
||||||
* false, and also making note what token offset we failed upon.
|
* false, and also making note what token offset we failed upon.
|
||||||
|
@ -117,15 +114,12 @@ public class Parser implements IParser
|
||||||
public Parser(
|
public Parser(
|
||||||
IScanner scanner,
|
IScanner scanner,
|
||||||
ISourceElementRequestor callback,
|
ISourceElementRequestor callback,
|
||||||
ParserMode mode,
|
ParserLanguage language,
|
||||||
ParserLanguage language, IParserLogService log )
|
IParserLogService log )
|
||||||
{
|
{
|
||||||
this.scanner = scanner;
|
this.scanner = scanner;
|
||||||
requestor = callback;
|
requestor = callback;
|
||||||
this.mode = mode;
|
|
||||||
this.language = language;
|
this.language = language;
|
||||||
astFactory = ParserFactory.createASTFactory( mode, language);
|
|
||||||
scanner.setASTFactory(astFactory);
|
|
||||||
this.log = log;
|
this.log = log;
|
||||||
}
|
}
|
||||||
// counter that keeps track of the number of times Parser.parse() is called
|
// 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
|
protected abstract void handleFunctionBody(IASTScope scope, boolean isInlineFunction) throws Backtrack, EndOfFile;
|
||||||
{
|
|
||||||
if ( mode == ParserMode.QUICK_PARSE || isInlineFunction )
|
|
||||||
{
|
|
||||||
skipOverCompoundStatement();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
functionBody(scope);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
protected void skipOverCompoundStatement() throws Backtrack, EndOfFile
|
protected void skipOverCompoundStatement() throws Backtrack, EndOfFile
|
||||||
{
|
{
|
||||||
// speed up the parser by skiping the body
|
// speed up the parser by skiping the body
|
||||||
|
@ -3034,12 +3019,12 @@ public class Parser implements IParser
|
||||||
declaration(scope, null); // was exceptionDeclaration
|
declaration(scope, null); // was exceptionDeclaration
|
||||||
consume(IToken.tRPAREN);
|
consume(IToken.tRPAREN);
|
||||||
|
|
||||||
if( mode == ParserMode.COMPLETE_PARSE )
|
catchBlockCompoundStatement(scope);
|
||||||
compoundStatement(scope, true);
|
|
||||||
else
|
|
||||||
skipOverCompoundStatement();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract void catchBlockCompoundStatement(IASTScope scope) throws Backtrack, EndOfFile;
|
||||||
|
|
||||||
protected void singleStatementScope(IASTScope scope) throws Backtrack
|
protected void singleStatementScope(IASTScope scope) throws Backtrack
|
||||||
{
|
{
|
||||||
IASTCodeScope newScope;
|
IASTCodeScope newScope;
|
||||||
|
|
|
@ -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