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 82eced9759b..3723978287e 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 @@ -40,7 +40,6 @@ import org.eclipse.cdt.core.parser.NullLogService; 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; @@ -71,7 +70,6 @@ public class AST2BaseTest extends TestCase { * @throws ParserException */ protected IASTTranslationUnit parse( String code, ParserLanguage lang ) throws ParserException { - ProblemCollector collector = new ProblemCollector(); CodeReader codeReader = new CodeReader(code .toCharArray()); ScannerInfo scannerInfo = new ScannerInfo(); @@ -86,7 +84,7 @@ public class AST2BaseTest extends TestCase { { ICPPParserExtensionConfiguration config = null; config = new ANSICPPParserExtensionConfiguration(); - parser2 = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, collector, + parser2 = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config ); } @@ -95,14 +93,14 @@ public class AST2BaseTest extends TestCase { ICParserExtensionConfiguration config = null; config = new ANSICParserExtensionConfiguration(); - parser2 = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, collector, + parser2 = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config ); } IASTTranslationUnit tu = parser2.parse(); if( parser2.encounteredError() ) throw new ParserException( "FAILURE"); //$NON-NLS-1$ - assertTrue( collector.hasNoProblems() ); + //TODO add in assertion here to visit all problems return tu; } 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 1734c8bea82..4eefccea516 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 @@ -116,7 +116,6 @@ public class CompleteParser2Tests extends TestCase { return parse(code, true, ParserLanguage.CPP); } - ProblemCollector collector; /** * @param string * @param b @@ -126,7 +125,7 @@ public class CompleteParser2Tests extends TestCase { protected IASTTranslationUnit parse(String code, boolean expectedToPass, ParserLanguage lang, boolean gcc) throws Exception { - collector = new ProblemCollector(); + CodeReader codeReader = new CodeReader(code .toCharArray()); ScannerInfo scannerInfo = new ScannerInfo(); @@ -144,7 +143,7 @@ public class CompleteParser2Tests extends TestCase { else config = new ANSICPPParserExtensionConfiguration(); parser2 = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, - collector, NULL_LOG, config); + NULL_LOG, config); } else { ICParserExtensionConfiguration config = null; if (gcc) @@ -153,13 +152,15 @@ public class CompleteParser2Tests extends TestCase { config = new ANSICParserExtensionConfiguration(); parser2 = new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE, - collector, NULL_LOG, config); + NULL_LOG, config); } IASTTranslationUnit tu = parser2.parse(); if (parser2.encounteredError() && expectedToPass) throw new ParserException("FAILURE"); //$NON-NLS-1$ if (expectedToPass) - assertTrue(collector.hasNoProblems()); + { + //TODO visit translation unit and ensure that there aren't any problems + } return tu; } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/parser2/ProblemCollector.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/parser2/ProblemCollector.java deleted file mode 100644 index fe37c3d1c56..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/parser2/ProblemCollector.java +++ /dev/null @@ -1,44 +0,0 @@ -/********************************************************************** - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM - Initial API and implementation - **********************************************************************/ -package org.eclipse.cdt.core.parser.tests.parser2; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.cdt.core.dom.ast.IASTProblem; -import org.eclipse.cdt.internal.core.dom.parser.IProblemRequestor; - - -/** - * @author jcamelon - */ -public class ProblemCollector implements IProblemRequestor { - - List problems = new ArrayList(); - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser2.IProblemRequestor#acceptProblem(org.eclipse.cdt.core.parser.IProblem) - */ - public boolean acceptProblem(IASTProblem problem) { - problems.add(problem); - return true; - } - - /** - * @return - */ - public boolean hasNoProblems() { - return problems.isEmpty(); - } - -} \ No newline at end of file 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 5918983b9a6..7a36280b059 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 @@ -1356,7 +1356,6 @@ public class QuickParser2Tests extends TestCase { protected void parse(String code, boolean expectedToPass, ParserLanguage lang, boolean gcc) throws Exception { - ProblemCollector collector = new ProblemCollector(); CodeReader codeReader = new CodeReader( code.toCharArray() ); IScannerInfo scannerInfo = new ScannerInfo(); IScannerConfiguration configuration = null; @@ -1373,7 +1372,7 @@ public class QuickParser2Tests extends TestCase { else config = new ANSICPPParserExtensionConfiguration(); parser2 = new GNUCPPSourceParser(scanner, ParserMode.QUICK_PARSE, - collector, NULL_LOG, config); + NULL_LOG, config); } else { ICParserExtensionConfiguration config = null; if (gcc) @@ -1382,13 +1381,15 @@ public class QuickParser2Tests extends TestCase { config = new ANSICParserExtensionConfiguration(); parser2 = new GNUCSourceParser(scanner, ParserMode.QUICK_PARSE, - collector, NULL_LOG, config); + NULL_LOG, config); } parser2.parse(); if (parser2.encounteredError() && expectedToPass) throw new ParserException("FAILURE"); //$NON-NLS-1$ if (expectedToPass) - assertTrue(collector.hasNoProblems()); + { + //TODO need visitor to ensure that there aren't any problems + } } public void testBug60142() throws Exception { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTProblemDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTProblemDeclaration.java new file mode 100644 index 00000000000..c2b432cb240 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTProblemDeclaration.java @@ -0,0 +1,21 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * @author jcamelon + */ +public interface IASTProblemDeclaration extends IASTDeclaration { + + public static final ASTNodeProperty PROBLEM = new ASTNodeProperty( "Problem"); //$NON-NLS-1$ + public IASTProblem getProblem(); + public void setProblem(IASTProblem p); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTProblemExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTProblemExpression.java new file mode 100644 index 00000000000..fac2ac4f54f --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTProblemExpression.java @@ -0,0 +1,23 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + + +/** + * @author jcamelon + */ +public interface IASTProblemExpression extends IASTExpression { + + public static final ASTNodeProperty PROBLEM = new ASTNodeProperty( "Problem"); //$NON-NLS-1$ + public IASTProblem getProblem(); + public void setProblem(IASTProblem p); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTProblemStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTProblemStatement.java new file mode 100644 index 00000000000..41d427e1ae6 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTProblemStatement.java @@ -0,0 +1,22 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * @author jcamelon + */ +public interface IASTProblemStatement extends IASTStatement { + + public static final ASTNodeProperty PROBLEM = new ASTNodeProperty( "Problem"); //$NON-NLS-1$ + public IASTProblem getProblem(); + public void setProblem(IASTProblem p); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTProblemTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTProblemTypeId.java new file mode 100644 index 00000000000..e9b697c3c1b --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTProblemTypeId.java @@ -0,0 +1,22 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * @author jcamelon + */ +public interface IASTProblemTypeId extends IASTTypeId { + + public static final ASTNodeProperty PROBLEM = new ASTNodeProperty( "Problem"); //$NON-NLS-1$ + public IASTProblem getProblem(); + public void setProblem(IASTProblem p); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeId.java index 345c3243f7c..7b3bb32e525 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeId.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.core.dom.ast; * @author jcamelon */ public interface IASTTypeId extends IASTNode { + public static final IASTTypeId [] EMPTY_TYPEID_ARRAY = new IASTTypeId[0]; public static final ASTNodeProperty DECL_SPECIFIER = new ASTNodeProperty( "Decl Specifier"); //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java index 058ead58698..eed2f7c8812 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java @@ -37,6 +37,8 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNullStatement; import org.eclipse.cdt.core.dom.ast.IASTProblem; +import org.eclipse.cdt.core.dom.ast.IASTProblemExpression; +import org.eclipse.cdt.core.dom.ast.IASTProblemStatement; import org.eclipse.cdt.core.dom.ast.IASTReturnStatement; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; @@ -70,7 +72,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { protected final ParserMode mode; - protected IProblemRequestor requestor = null; protected final boolean supportStatementsInExpressions; @@ -80,12 +81,11 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { protected AbstractGNUSourceCodeParser(IScanner scanner, IParserLogService logService, ParserMode parserMode, - IProblemRequestor callback, boolean supportStatementsInExpressions, - boolean supportTypeOfUnaries, boolean supportAlignOfUnaries) { + boolean supportStatementsInExpressions, boolean supportTypeOfUnaries, + boolean supportAlignOfUnaries) { this.scanner = scanner; this.log = logService; this.mode = parserMode; - this.requestor = callback; this.supportStatementsInExpressions = supportStatementsInExpressions; this.supportTypeOfUnaries = supportTypeOfUnaries; this.supportAlignOfUnaries = supportAlignOfUnaries; @@ -286,15 +286,16 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { throw bt; } - protected void failParse(BacktrackException bt) { - if (requestor != null) { - if (bt.getProblem() == null) { - IASTProblem problem = createProblem( IASTProblem.SYNTAX_ERROR, bt.getOffset(), bt.getLength() ); - requestor.acceptProblem(problem); - } else - requestor.acceptProblem(bt.getProblem()); - } + protected IASTProblem failParse(BacktrackException bt) { + IASTProblem result = null; + + if (bt.getProblem() == null) + result = createProblem( IASTProblem.SYNTAX_ERROR, bt.getOffset(), bt.getLength() ); + else + result = bt.getProblem(); + failParse(); + return result; } /** @@ -303,14 +304,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { * @param length * @return */ - protected IASTProblem createProblem(int signal, int offset, int length) - { - IASTProblem result = new ASTProblem( signal, EMPTY_STRING, false, true ); - ((ASTNode)result).setOffset( offset ); - ((ASTNode)result).setLength( length ); - return result; - } - + protected abstract IASTProblem createProblem(int signal, int offset, int length); /** * @param string * @param e @@ -477,7 +471,13 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { DEFAULT_COMPOUNDSTATEMENT_LIST_SIZE); statements.add(s); } catch (BacktrackException b) { - failParse(b); + IASTProblem p = failParse(b); + IASTProblemStatement ps = createProblemStatement(); + ps.setProblem( p ); + ((ASTNode)ps).setOffset( ((ASTNode)p).getOffset() ); + p.setParent( ps ); + p.setPropertyInParent( IASTProblemStatement.PROBLEM ); + statements.add( ps ); if (LA(1).hashCode() == checkToken) failParseWithErrorHandling(); } @@ -495,6 +495,11 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { return result; } + /** + * @return + */ + protected abstract IASTProblemStatement createProblemStatement(); + /** * @return */ @@ -1683,17 +1688,13 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { condition = condition(); consume(IToken.tRPAREN); } catch (BacktrackException b) { - //if the problem has no offset info, make a new one that does - if( b.getProblem() != null ){ - IASTProblem p = b.getProblem(); -// IASTProblem p2 = problemFactory.createProblem( p.getID(), start.getOffset(), -// lastToken != null ? lastToken.getEndOffset() : start.getEndOffset(), -// start.getLineNumber(), p.getOriginatingFileName(), -// p.getArguments() != null ? p.getArguments().toCharArray() : null, -// p.isWarning(), p.isError() ); - b.initialize( p ); - } - failParse(b); + IASTProblem p = failParse(b); + IASTProblemExpression ps = createProblemExpression(); + ps.setProblem( p ); + ((ASTNode)ps).setOffset( ((ASTNode)p).getOffset() ); + p.setParent( ps ); + p.setPropertyInParent( IASTProblemExpression.PROBLEM ); + condition = ps; failParseWithErrorHandling(); passedCondition = false; } @@ -1742,6 +1743,11 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { return if_statement; } + /** + * @return + */ + protected abstract IASTProblemExpression createProblemExpression(); + /** * @return * @throws EndOfFileException diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IProblemRequestor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IProblemRequestor.java deleted file mode 100644 index 70286dbe3ad..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IProblemRequestor.java +++ /dev/null @@ -1,26 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002-2004 IBM Canada 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 */ - -/* - * Created on Oct 22, 2004 - */ -package org.eclipse.cdt.internal.core.dom.parser; - -import org.eclipse.cdt.core.dom.ast.IASTProblem; - -/** - * @author jcamelon - * - */ -public interface IProblemRequestor { - - public boolean acceptProblem( IASTProblem problem ); - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTProblem.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblem.java similarity index 98% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTProblem.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblem.java index fc0552df1ef..9cf2e55316d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTProblem.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblem.java @@ -8,7 +8,7 @@ * Contributors: * IBM - Initial API and implementation **********************************************************************/ -package org.eclipse.cdt.internal.core.dom.parser; +package org.eclipse.cdt.internal.core.dom.parser.c; import java.text.MessageFormat; import java.util.HashMap; @@ -24,7 +24,7 @@ import org.eclipse.cdt.internal.core.parser.ParserMessages; /** * @author jcamelon */ -public class ASTProblem extends ASTNode implements IASTProblem { +public class CASTProblem extends CASTNode implements IASTProblem { private IASTNode parent; @@ -76,7 +76,7 @@ public class ASTProblem extends ASTNode implements IASTProblem { private String message = null; - public ASTProblem(int id, char[] arg, boolean warn, boolean error) { + public CASTProblem(int id, char[] arg, boolean warn, boolean error) { this.id = id; this.arg = arg; this.isWarning = warn; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemDeclaration.java new file mode 100644 index 00000000000..1fdac5290dc --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemDeclaration.java @@ -0,0 +1,21 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.c; + +import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration; + +/** + * @author jcamelon + */ +public class CASTProblemDeclaration extends CASTProblemOwner implements + IASTProblemDeclaration { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemExpression.java new file mode 100644 index 00000000000..3bbe6a5c26b --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemExpression.java @@ -0,0 +1,21 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.c; + +import org.eclipse.cdt.core.dom.ast.IASTProblemExpression; + +/** + * @author jcamelon + */ +public class CASTProblemExpression extends CASTProblemOwner implements + IASTProblemExpression { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemOwner.java new file mode 100644 index 00000000000..0be81e75b97 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemOwner.java @@ -0,0 +1,32 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.c; + +import org.eclipse.cdt.core.dom.ast.IASTProblem; + +/** + * @author jcamelon + */ +class CASTProblemOwner extends CASTNode { + + private IASTProblem problem; + + public IASTProblem getProblem() + { + return problem; + } + + public void setProblem(IASTProblem p) + { + problem = p; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemStatement.java new file mode 100644 index 00000000000..74c99081a1d --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemStatement.java @@ -0,0 +1,21 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.c; + +import org.eclipse.cdt.core.dom.ast.IASTProblemStatement; + +/** + * @author jcamelon + */ +public class CASTProblemStatement extends CASTProblemOwner implements + IASTProblemStatement { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java index 617abc036db..23253ff0e01 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java @@ -56,6 +56,10 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNullStatement; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; +import org.eclipse.cdt.core.dom.ast.IASTProblem; +import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTProblemExpression; +import org.eclipse.cdt.core.dom.ast.IASTProblemStatement; import org.eclipse.cdt.core.dom.ast.IASTReturnStatement; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; @@ -90,13 +94,11 @@ import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser; import org.eclipse.cdt.internal.core.dom.parser.BacktrackException; -import org.eclipse.cdt.internal.core.dom.parser.IProblemRequestor; /** * @author jcamelon */ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { - private final boolean supportGCCStyleDesignators; @@ -104,16 +106,14 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { /** * @param scanner - * @param logService * @param parserMode - * @param callback + * @param logService */ public GNUCSourceParser(IScanner scanner, ParserMode parserMode, - IProblemRequestor callback, IParserLogService logService, - ICParserExtensionConfiguration config) { - super(scanner, logService, parserMode, callback, config + IParserLogService logService, ICParserExtensionConfiguration config) { + super(scanner, logService, parserMode, config .supportStatementsInExpressions(), config - .supportTypeofUnaryExpressions(), config + .supportTypeofUnaryExpressions(), config .supportAlignOfUnaryExpression()); supportGCCStyleDesignators = config.supportGCCStyleDesignators(); } @@ -147,7 +147,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { if (LT(1) == IToken.tLBRACE) { consume(IToken.tLBRACE); IASTInitializerList result = createInitializerList(); - ((ASTNode)result).setOffset( startingOffset ); + ((ASTNode) result).setOffset(startingOffset); for (;;) { int checkHashcode = LA(1).hashCode(); // required at least one initializer list @@ -156,32 +156,35 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { if (newDesignators.size() != 0) if (LT(1) == IToken.tASSIGN) consume(IToken.tASSIGN); - + IASTInitializer initializer = cInitializerClause(newDesignators); - - if( newDesignators.isEmpty() ) - { - result.addInitializer(initializer); - initializer.setParent( result ); - initializer.setPropertyInParent( IASTInitializerList.NESTED_INITIALIZER ); - } - else - { + + if (newDesignators.isEmpty()) { + result.addInitializer(initializer); + initializer.setParent(result); + initializer + .setPropertyInParent(IASTInitializerList.NESTED_INITIALIZER); + } else { ICASTDesignatedInitializer desigInitializer = createDesignatorInitializer(); - ((CASTNode)desigInitializer).setOffset( ((CASTNode)newDesignators.get(0)).getOffset()); - for( int i = 0; i < newDesignators.size(); ++i ) - { - ICASTDesignator d = (ICASTDesignator) newDesignators.get(i); - d.setParent( desigInitializer ); - d.setPropertyInParent( ICASTDesignatedInitializer.DESIGNATOR ); - desigInitializer.addDesignator( d ); + ((CASTNode) desigInitializer) + .setOffset(((CASTNode) newDesignators.get(0)) + .getOffset()); + for (int i = 0; i < newDesignators.size(); ++i) { + ICASTDesignator d = (ICASTDesignator) newDesignators + .get(i); + d.setParent(desigInitializer); + d + .setPropertyInParent(ICASTDesignatedInitializer.DESIGNATOR); + desigInitializer.addDesignator(d); } desigInitializer.setOperandInitializer(initializer); - initializer.setParent( desigInitializer ); - initializer.setPropertyInParent( ICASTDesignatedInitializer.OPERAND ); - result.addInitializer( desigInitializer ); - desigInitializer.setParent( result ); - desigInitializer.setPropertyInParent( IASTInitializerList.NESTED_INITIALIZER ); + initializer.setParent(desigInitializer); + initializer + .setPropertyInParent(ICASTDesignatedInitializer.OPERAND); + result.addInitializer(desigInitializer); + desigInitializer.setParent(result); + desigInitializer + .setPropertyInParent(IASTInitializerList.NESTED_INITIALIZER); } // can end with just a '}' if (LT(1) == IToken.tRBRACE) @@ -193,7 +196,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { break; if (checkHashcode == LA(1).hashCode()) { IToken l2 = LA(1); - throwBacktrack(startingOffset, l2.getEndOffset() - startingOffset); + throwBacktrack(startingOffset, l2.getEndOffset() + - startingOffset); return null; } @@ -210,7 +214,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { IASTExpression assignmentExpression = assignmentExpression(); IASTInitializerExpression result = createInitializerExpression(); result.setExpression(assignmentExpression); - ((ASTNode)result).setOffset(((ASTNode)assignmentExpression).getOffset()); + ((ASTNode) result).setOffset(((ASTNode) assignmentExpression) + .getOffset()); assignmentExpression.setParent(result); assignmentExpression .setPropertyInParent(IASTInitializerExpression.INITIALIZER_EXPRESSION); @@ -248,21 +253,22 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { BacktrackException { //designated initializers for C List designatorList = Collections.EMPTY_LIST; - + if (LT(1) == IToken.tDOT || LT(1) == IToken.tLBRACKET) { while (LT(1) == IToken.tDOT || LT(1) == IToken.tLBRACKET) { if (LT(1) == IToken.tDOT) { int offset = consume(IToken.tDOT).getOffset(); IToken id = identifier(); ICASTFieldDesignator designator = createFieldDesignator(); - ((ASTNode)designator).setOffset( offset ); - IASTName n = createName( id ); - designator.setName( n ); - n.setParent( designator ); - n.setPropertyInParent( ICASTFieldDesignator.FIELD_NAME ); - if( designatorList == Collections.EMPTY_LIST ) - designatorList = new ArrayList( DEFAULT_DESIGNATOR_LIST_SIZE ); - designatorList.add( designator ); + ((ASTNode) designator).setOffset(offset); + IASTName n = createName(id); + designator.setName(n); + n.setParent(designator); + n.setPropertyInParent(ICASTFieldDesignator.FIELD_NAME); + if (designatorList == Collections.EMPTY_LIST) + designatorList = new ArrayList( + DEFAULT_DESIGNATOR_LIST_SIZE); + designatorList.add(designator); } else if (LT(1) == IToken.tLBRACKET) { IToken mark = consume(IToken.tLBRACKET); int offset = mark.getOffset(); @@ -270,47 +276,53 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { if (LT(1) == IToken.tRBRACKET) { consume(IToken.tRBRACKET); ICASTArrayDesignator designator = createArrayDesignator(); - ((ASTNode)designator).setOffset( offset ); - designator.setSubscriptExpression( constantExpression ); - constantExpression.setParent( designator ); - constantExpression.setPropertyInParent( ICASTArrayDesignator.SUBSCRIPT_EXPRESSION ); - if( designatorList == Collections.EMPTY_LIST ) - designatorList = new ArrayList( DEFAULT_DESIGNATOR_LIST_SIZE ); - designatorList.add( designator ); + ((ASTNode) designator).setOffset(offset); + designator.setSubscriptExpression(constantExpression); + constantExpression.setParent(designator); + constantExpression + .setPropertyInParent(ICASTArrayDesignator.SUBSCRIPT_EXPRESSION); + if (designatorList == Collections.EMPTY_LIST) + designatorList = new ArrayList( + DEFAULT_DESIGNATOR_LIST_SIZE); + designatorList.add(designator); continue; } backup(mark); - if (supportGCCStyleDesignators ) { + if (supportGCCStyleDesignators) { int startOffset = consume(IToken.tLBRACKET).getOffset(); IASTExpression constantExpression1 = expression(); consume(IToken.tELLIPSIS); IASTExpression constantExpression2 = expression(); consume(IToken.tRBRACKET); IGCCASTArrayRangeDesignator designator = createArrayRangeDesignator(); - ((ASTNode)designator).setOffset( startOffset ); - designator.setRangeFloor( constantExpression1 ); - constantExpression1.setParent( designator ); - constantExpression1.setPropertyInParent( IGCCASTArrayRangeDesignator.SUBSCRIPT_FLOOR_EXPRESSION ); - designator.setRangeCeiling( constantExpression2 ); - constantExpression2.setParent( designator ); - constantExpression2.setPropertyInParent( IGCCASTArrayRangeDesignator.SUBSCRIPT_CEILING_EXPRESSION ); - if( designatorList == Collections.EMPTY_LIST ) - designatorList = new ArrayList( DEFAULT_DESIGNATOR_LIST_SIZE ); - designatorList.add( designator ); + ((ASTNode) designator).setOffset(startOffset); + designator.setRangeFloor(constantExpression1); + constantExpression1.setParent(designator); + constantExpression1 + .setPropertyInParent(IGCCASTArrayRangeDesignator.SUBSCRIPT_FLOOR_EXPRESSION); + designator.setRangeCeiling(constantExpression2); + constantExpression2.setParent(designator); + constantExpression2 + .setPropertyInParent(IGCCASTArrayRangeDesignator.SUBSCRIPT_CEILING_EXPRESSION); + if (designatorList == Collections.EMPTY_LIST) + designatorList = new ArrayList( + DEFAULT_DESIGNATOR_LIST_SIZE); + designatorList.add(designator); } - } else if ( supportGCCStyleDesignators && LT(1) == IToken.tIDENTIFIER ) - { + } else if (supportGCCStyleDesignators + && LT(1) == IToken.tIDENTIFIER) { IToken identifier = identifier(); consume(IToken.tCOLON); ICASTFieldDesignator designator = createFieldDesignator(); - ((ASTNode)designator).setOffset( identifier.getOffset() ); - IASTName n = createName( identifier ); - designator.setName( n ); - n.setParent( designator ); - n.setPropertyInParent( ICASTFieldDesignator.FIELD_NAME ); - if( designatorList == Collections.EMPTY_LIST ) - designatorList = new ArrayList( DEFAULT_DESIGNATOR_LIST_SIZE ); - designatorList.add( designator ); + ((ASTNode) designator).setOffset(identifier.getOffset()); + IASTName n = createName(identifier); + designator.setName(n); + n.setParent(designator); + n.setPropertyInParent(ICASTFieldDesignator.FIELD_NAME); + if (designatorList == Collections.EMPTY_LIST) + designatorList = new ArrayList( + DEFAULT_DESIGNATOR_LIST_SIZE); + designatorList.add(designator); } } } else { @@ -321,14 +333,15 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { IToken identifier = identifier(); consume(IToken.tCOLON); ICASTFieldDesignator designator = createFieldDesignator(); - ((ASTNode)designator).setOffset( identifier.getOffset() ); - IASTName n = createName( identifier ); - designator.setName( n ); - n.setParent( designator ); - n.setPropertyInParent( ICASTFieldDesignator.FIELD_NAME ); - if( designatorList == Collections.EMPTY_LIST ) - designatorList = new ArrayList( DEFAULT_DESIGNATOR_LIST_SIZE ); - designatorList.add( designator ); + ((ASTNode) designator).setOffset(identifier.getOffset()); + IASTName n = createName(identifier); + designator.setName(n); + n.setParent(designator); + n.setPropertyInParent(ICASTFieldDesignator.FIELD_NAME); + if (designatorList == Collections.EMPTY_LIST) + designatorList = new ArrayList( + DEFAULT_DESIGNATOR_LIST_SIZE); + designatorList.add(designator); } else if (LT(1) == IToken.tLBRACKET) { int startOffset = consume(IToken.tLBRACKET).getOffset(); IASTExpression constantExpression1 = expression(); @@ -336,16 +349,19 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { IASTExpression constantExpression2 = expression(); consume(IToken.tRBRACKET); IGCCASTArrayRangeDesignator designator = createArrayRangeDesignator(); - ((ASTNode)designator).setOffset( startOffset ); - designator.setRangeFloor( constantExpression1 ); - constantExpression1.setParent( designator ); - constantExpression1.setPropertyInParent( IGCCASTArrayRangeDesignator.SUBSCRIPT_FLOOR_EXPRESSION ); - designator.setRangeCeiling( constantExpression2 ); - constantExpression2.setParent( designator ); - constantExpression2.setPropertyInParent( IGCCASTArrayRangeDesignator.SUBSCRIPT_CEILING_EXPRESSION ); - if( designatorList == Collections.EMPTY_LIST ) - designatorList = new ArrayList( DEFAULT_DESIGNATOR_LIST_SIZE ); - designatorList.add( designator ); + ((ASTNode) designator).setOffset(startOffset); + designator.setRangeFloor(constantExpression1); + constantExpression1.setParent(designator); + constantExpression1 + .setPropertyInParent(IGCCASTArrayRangeDesignator.SUBSCRIPT_FLOOR_EXPRESSION); + designator.setRangeCeiling(constantExpression2); + constantExpression2.setParent(designator); + constantExpression2 + .setPropertyInParent(IGCCASTArrayRangeDesignator.SUBSCRIPT_CEILING_EXPRESSION); + if (designatorList == Collections.EMPTY_LIST) + designatorList = new ArrayList( + DEFAULT_DESIGNATOR_LIST_SIZE); + designatorList.add(designator); } } } @@ -386,8 +402,6 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { } - - /** * @throws BacktrackException * @throws EndOfFileException @@ -397,7 +411,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { IToken firstToken = LA(1); int firstOffset = firstToken.getOffset(); if (firstToken.getType() == IToken.tLBRACE) - throwBacktrack(firstToken.getOffset(), firstToken.getLength() ); + throwBacktrack(firstToken.getOffset(), firstToken.getLength()); firstToken = null; // necessary for scalability @@ -435,7 +449,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { } if (hasFunctionTryBlock && !hasFunctionBody) - throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset ); + throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset); } if (hasFunctionBody) { @@ -447,7 +461,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { throwBacktrack(firstOffset, LA(1).getEndOffset()); IASTFunctionDefinition funcDefinition = createFunctionDefinition(); - ((ASTNode)funcDefinition).setOffset(firstOffset); + ((ASTNode) funcDefinition).setOffset(firstOffset); funcDefinition.setDeclSpecifier(declSpec); declSpec.setParent(funcDefinition); declSpec.setPropertyInParent(IASTFunctionDefinition.DECL_SPECIFIER); @@ -466,7 +480,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { } IASTSimpleDeclaration simpleDeclaration = createSimpleDeclaration(); - ((ASTNode)simpleDeclaration).setOffset(firstOffset); + ((ASTNode) simpleDeclaration).setOffset(firstOffset); simpleDeclaration.setDeclSpecifier(declSpec); declSpec.setParent(simpleDeclaration); declSpec.setPropertyInParent(IASTSimpleDeclaration.DECL_SPECIFIER); @@ -537,7 +551,16 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { } catch (BacktrackException b) { try { // Mark as failure and try to reach a recovery point - failParse(b); + IASTProblem p = failParse(b); + IASTProblemDeclaration pd = createProblemDeclaration(); + pd.setProblem(p); + ((CASTNode) pd).setOffset(((CASTNode) p).getOffset()); + p.setParent(pd); + p.setPropertyInParent(IASTProblemDeclaration.PROBLEM); + pd.setParent(translationUnit); + pd + .setPropertyInParent(IASTTranslationUnit.OWNED_DECLARATION); + translationUnit.addDeclaration(pd); errorHandling(); if (lastBacktrack != -1 && lastBacktrack == LA(1).hashCode()) { @@ -576,6 +599,13 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { // compilationUnit.exitScope( requestor ); } + /** + * @return + */ + protected IASTProblemDeclaration createProblemDeclaration() { + return new CASTProblemDeclaration(); + } + /** * @param expression * @throws BacktrackException @@ -584,31 +614,49 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { BacktrackException { IASTExpression conditionalExpression = conditionalExpression(); // if the condition not taken, try assignment operators - if (conditionalExpression != null && conditionalExpression instanceof IASTConditionalExpression ) //&& + if (conditionalExpression != null + && conditionalExpression instanceof IASTConditionalExpression) //&& return conditionalExpression; switch (LT(1)) { case IToken.tASSIGN: - return assignmentOperatorExpression(IASTBinaryExpression.op_assign, conditionalExpression); + return assignmentOperatorExpression(IASTBinaryExpression.op_assign, + conditionalExpression); case IToken.tSTARASSIGN: - return assignmentOperatorExpression(IASTBinaryExpression.op_multiplyAssign, conditionalExpression); + return assignmentOperatorExpression( + IASTBinaryExpression.op_multiplyAssign, + conditionalExpression); case IToken.tDIVASSIGN: - return assignmentOperatorExpression(IASTBinaryExpression.op_divideAssign, conditionalExpression); + return assignmentOperatorExpression( + IASTBinaryExpression.op_divideAssign, conditionalExpression); case IToken.tMODASSIGN: - return assignmentOperatorExpression(IASTBinaryExpression.op_moduloAssign, conditionalExpression); + return assignmentOperatorExpression( + IASTBinaryExpression.op_moduloAssign, conditionalExpression); case IToken.tPLUSASSIGN: - return assignmentOperatorExpression(IASTBinaryExpression.op_plusAssign, conditionalExpression); + return assignmentOperatorExpression( + IASTBinaryExpression.op_plusAssign, conditionalExpression); case IToken.tMINUSASSIGN: - return assignmentOperatorExpression(IASTBinaryExpression.op_minusAssign, conditionalExpression); + return assignmentOperatorExpression( + IASTBinaryExpression.op_minusAssign, conditionalExpression); case IToken.tSHIFTRASSIGN: - return assignmentOperatorExpression(IASTBinaryExpression.op_shiftRightAssign, conditionalExpression); + return assignmentOperatorExpression( + IASTBinaryExpression.op_shiftRightAssign, + conditionalExpression); case IToken.tSHIFTLASSIGN: - return assignmentOperatorExpression(IASTBinaryExpression.op_shiftLeftAssign, conditionalExpression); + return assignmentOperatorExpression( + IASTBinaryExpression.op_shiftLeftAssign, + conditionalExpression); case IToken.tAMPERASSIGN: - return assignmentOperatorExpression(IASTBinaryExpression.op_binaryAndAssign, conditionalExpression); + return assignmentOperatorExpression( + IASTBinaryExpression.op_binaryAndAssign, + conditionalExpression); case IToken.tXORASSIGN: - return assignmentOperatorExpression(IASTBinaryExpression.op_binaryXorAssign, conditionalExpression); + return assignmentOperatorExpression( + IASTBinaryExpression.op_binaryXorAssign, + conditionalExpression); case IToken.tBITORASSIGN: - return assignmentOperatorExpression(IASTBinaryExpression.op_binaryOrAssign, conditionalExpression); + return assignmentOperatorExpression( + IASTBinaryExpression.op_binaryOrAssign, + conditionalExpression); } return conditionalExpression; } @@ -632,19 +680,20 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { int operator = 0; switch (t) { case IToken.tGT: - operator = IASTBinaryExpression.op_greaterThan; + operator = IASTBinaryExpression.op_greaterThan; break; case IToken.tLT: - operator = IASTBinaryExpression.op_lessThan; + operator = IASTBinaryExpression.op_lessThan; break; case IToken.tLTEQUAL: operator = IASTBinaryExpression.op_lessEqual; break; case IToken.tGTEQUAL: - operator = IASTBinaryExpression.op_greaterEqual; + operator = IASTBinaryExpression.op_greaterEqual; break; } - firstExpression = buildBinaryExpression( operator, firstExpression, secondExpression ); + firstExpression = buildBinaryExpression(operator, + firstExpression, secondExpression); break; default: return firstExpression; @@ -672,13 +721,14 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { operator = IASTBinaryExpression.op_multiply; break; case IToken.tDIV: - operator = IASTBinaryExpression.op_divide; + operator = IASTBinaryExpression.op_divide; break; case IToken.tMOD: - operator = IASTBinaryExpression.op_modulo; + operator = IASTBinaryExpression.op_modulo; break; } - firstExpression = buildBinaryExpression( operator, firstExpression, secondExpression ); + firstExpression = buildBinaryExpression(operator, + firstExpression, secondExpression); break; default: return firstExpression; @@ -708,8 +758,9 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { backup(mark); throwBacktrack(bte); } - - return buildTypeIdUnaryExpression( IASTCastExpression.op_cast, typeId, castExpression, startingOffset ); + + return buildTypeIdUnaryExpression(IASTCastExpression.op_cast, + typeId, castExpression, startingOffset); } catch (BacktrackException b) { } } @@ -725,15 +776,15 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { int startingOffset = LA(1).getOffset(); switch (LT(1)) { case IToken.tSTAR: - return unaryOperatorCastExpression(IASTUnaryExpression.op_star ); + return unaryOperatorCastExpression(IASTUnaryExpression.op_star); case IToken.tAMPER: return unaryOperatorCastExpression(IASTUnaryExpression.op_amper); case IToken.tPLUS: - return unaryOperatorCastExpression(IASTUnaryExpression.op_plus ); + return unaryOperatorCastExpression(IASTUnaryExpression.op_plus); case IToken.tMINUS: - return unaryOperatorCastExpression(IASTUnaryExpression.op_minus ); + return unaryOperatorCastExpression(IASTUnaryExpression.op_minus); case IToken.tNOT: - return unaryOperatorCastExpression(IASTUnaryExpression.op_not ); + return unaryOperatorCastExpression(IASTUnaryExpression.op_not); case IToken.tCOMPL: return unaryOperatorCastExpression(IASTUnaryExpression.op_tilde); case IToken.tINCR: @@ -759,10 +810,12 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { unaryExpression = unaryExpression(); } mark = null; - if (typeId == null && unaryExpression != null ) - return buildUnaryExpression( IASTUnaryExpression.op_sizeof, unaryExpression, startingOffset ); - return buildTypeIdExpression( IASTTypeIdExpression.op_sizeof, typeId, startingOffset ); - + if (typeId == null && unaryExpression != null) + return buildUnaryExpression(IASTUnaryExpression.op_sizeof, + unaryExpression, startingOffset); + return buildTypeIdExpression(IASTTypeIdExpression.op_sizeof, + typeId, startingOffset); + default: if (LT(1) == IGCCToken.t_typeof && supportTypeOfUnaries) { IASTExpression unary = unaryTypeofExpression(); @@ -784,13 +837,14 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { * @param startingOffset * @return */ - protected IASTExpression buildTypeIdExpression(int op_sizeof, IASTTypeId typeId, int startingOffset) { + protected IASTExpression buildTypeIdExpression(int op_sizeof, + IASTTypeId typeId, int startingOffset) { IASTTypeIdExpression result = createTypeIdExpression(); - result.setOperator( op_sizeof ); - ((ASTNode)result).setOffset( startingOffset ); - result.setTypeId( typeId ); - typeId.setParent( result ); - typeId.setPropertyInParent( IASTTypeIdExpression.TYPE_ID ); + result.setOperator(op_sizeof); + ((ASTNode) result).setOffset(startingOffset); + result.setTypeId(typeId); + typeId.setParent(result); + typeId.setPropertyInParent(IASTTypeIdExpression.TYPE_ID); return result; } @@ -814,20 +868,17 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { // ( type-name ) { initializer-list } // ( type-name ) { initializer-list , } IToken m = mark(); - try - { - int offset = consume(IToken.tLPAREN).getOffset(); - IASTTypeId t = typeId(false); - consume( IToken.tRPAREN ); - IASTInitializer i = cInitializerClause(Collections.EMPTY_LIST); - firstExpression = buildTypeIdInitializerExpression( t, i, offset ); - break; - } - catch( BacktrackException bt ) - { - backup( m ); - } - + try { + int offset = consume(IToken.tLPAREN).getOffset(); + IASTTypeId t = typeId(false); + consume(IToken.tRPAREN); + IASTInitializer i = cInitializerClause(Collections.EMPTY_LIST); + firstExpression = buildTypeIdInitializerExpression(t, i, offset); + break; + } catch (BacktrackException bt) { + backup(m); + } + default: firstExpression = primaryExpression(); } @@ -840,73 +891,86 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { consume(IToken.tLBRACKET); secondExpression = expression(); consume(IToken.tRBRACKET); - IASTArraySubscriptExpression s = createArraySubscriptExpression(); - ((ASTNode)s).setOffset( ((ASTNode)firstExpression).getOffset() ); - s.setArrayExpression( firstExpression ); - firstExpression.setParent( s ); - firstExpression.setPropertyInParent( IASTArraySubscriptExpression.ARRAY ); - s.setSubscriptExpression( secondExpression ); - secondExpression.setParent( s ); - secondExpression.setPropertyInParent( IASTArraySubscriptExpression.SUBSCRIPT ); + IASTArraySubscriptExpression s = createArraySubscriptExpression(); + ((ASTNode) s) + .setOffset(((ASTNode) firstExpression).getOffset()); + s.setArrayExpression(firstExpression); + firstExpression.setParent(s); + firstExpression + .setPropertyInParent(IASTArraySubscriptExpression.ARRAY); + s.setSubscriptExpression(secondExpression); + secondExpression.setParent(s); + secondExpression + .setPropertyInParent(IASTArraySubscriptExpression.SUBSCRIPT); firstExpression = s; break; case IToken.tLPAREN: // function call consume(IToken.tLPAREN); - if( LT(1) != IToken.tRPAREN ) - secondExpression = expression(); + if (LT(1) != IToken.tRPAREN) + secondExpression = expression(); consume(IToken.tRPAREN); IASTFunctionCallExpression f = createFunctionCallExpression(); - ((ASTNode)f).setOffset( ((ASTNode)firstExpression).getOffset() ); - f.setFunctionNameExpression( firstExpression ); - firstExpression.setParent( f ); - firstExpression.setPropertyInParent( IASTFunctionCallExpression.FUNCTION_NAME ); - - if( secondExpression != null ) - { - f.setParameterExpression( secondExpression ); - secondExpression.setParent( f ); - secondExpression.setPropertyInParent( IASTFunctionCallExpression.PARAMETERS ); + ((ASTNode) f) + .setOffset(((ASTNode) firstExpression).getOffset()); + f.setFunctionNameExpression(firstExpression); + firstExpression.setParent(f); + firstExpression + .setPropertyInParent(IASTFunctionCallExpression.FUNCTION_NAME); + + if (secondExpression != null) { + f.setParameterExpression(secondExpression); + secondExpression.setParent(f); + secondExpression + .setPropertyInParent(IASTFunctionCallExpression.PARAMETERS); } firstExpression = f; break; case IToken.tINCR: int offset = consume(IToken.tINCR).getOffset(); - firstExpression = buildUnaryExpression( IASTUnaryExpression.op_postFixIncr, firstExpression, offset ); + firstExpression = buildUnaryExpression( + IASTUnaryExpression.op_postFixIncr, firstExpression, + offset); break; case IToken.tDECR: offset = consume().getOffset(); - firstExpression = buildUnaryExpression( IASTUnaryExpression.op_postFixDecr, firstExpression, offset ); + firstExpression = buildUnaryExpression( + IASTUnaryExpression.op_postFixDecr, firstExpression, + offset); break; case IToken.tDOT: // member access consume(IToken.tDOT); - IASTName name = createName( identifier() ); + IASTName name = createName(identifier()); IASTFieldReference result = createFieldReference(); - ((ASTNode)result).setOffset( ((ASTNode)firstExpression).getOffset() ); - result.setFieldOwner( firstExpression ); + ((ASTNode) result).setOffset(((ASTNode) firstExpression) + .getOffset()); + result.setFieldOwner(firstExpression); result.setIsPointerDereference(false); - firstExpression.setParent( result ); - firstExpression.setPropertyInParent( IASTFieldReference.FIELD_OWNER ); - result.setFieldName( name ); - name.setParent( result ); - name.setPropertyInParent( IASTFieldReference.FIELD_NAME ); + firstExpression.setParent(result); + firstExpression + .setPropertyInParent(IASTFieldReference.FIELD_OWNER); + result.setFieldName(name); + name.setParent(result); + name.setPropertyInParent(IASTFieldReference.FIELD_NAME); firstExpression = result; break; case IToken.tARROW: // member access consume(IToken.tARROW); - name = createName( identifier() ); - result = createFieldReference(); - ((ASTNode)result).setOffset( ((ASTNode)firstExpression).getOffset() ); - result.setFieldOwner( firstExpression ); - result.setIsPointerDereference(true); - firstExpression.setParent( result ); - firstExpression.setPropertyInParent( IASTFieldReference.FIELD_OWNER ); - result.setFieldName( name ); - name.setParent( result ); - name.setPropertyInParent( IASTFieldReference.FIELD_NAME ); - firstExpression = result; + name = createName(identifier()); + result = createFieldReference(); + ((ASTNode) result).setOffset(((ASTNode) firstExpression) + .getOffset()); + result.setFieldOwner(firstExpression); + result.setIsPointerDereference(true); + firstExpression.setParent(result); + firstExpression + .setPropertyInParent(IASTFieldReference.FIELD_OWNER); + result.setFieldName(name); + name.setParent(result); + name.setPropertyInParent(IASTFieldReference.FIELD_NAME); + firstExpression = result; break; default: return firstExpression; @@ -917,7 +981,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { /** * @return */ - protected IASTFunctionCallExpression createFunctionCallExpression() { + protected IASTFunctionCallExpression createFunctionCallExpression() { return new CASTFunctionCallExpression(); } @@ -934,15 +998,16 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { * @param offset * @return */ - protected ICASTTypeIdInitializerExpression buildTypeIdInitializerExpression(IASTTypeId t, IASTInitializer i, int offset) { + protected ICASTTypeIdInitializerExpression buildTypeIdInitializerExpression( + IASTTypeId t, IASTInitializer i, int offset) { ICASTTypeIdInitializerExpression result = createTypeIdInitializerExpression(); - ((ASTNode)result).setOffset( offset ); - result.setTypeId( t ); - t.setParent( result ); - t.setPropertyInParent( ICASTTypeIdInitializerExpression.TYPE_ID ); - result.setInitializer( i ); - i.setParent( result ); - i.setPropertyInParent( ICASTTypeIdInitializerExpression.INITIALIZER ); + ((ASTNode) result).setOffset(offset); + result.setTypeId(t); + t.setParent(result); + t.setPropertyInParent(ICASTTypeIdInitializerExpression.TYPE_ID); + result.setInitializer(i); + i.setParent(result); + i.setPropertyInParent(ICASTTypeIdInitializerExpression.INITIALIZER); return result; } @@ -972,37 +1037,38 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { // TO DO: we need more literals... case IToken.tINTEGER: t = consume(); - literalExpression = createLiteralExpression(); - literalExpression.setKind( IASTLiteralExpression.lk_integer_constant); - literalExpression.setValue( t.getImage() ); - ((ASTNode)literalExpression).setOffset( t.getOffset() ); - return literalExpression; + literalExpression = createLiteralExpression(); + literalExpression + .setKind(IASTLiteralExpression.lk_integer_constant); + literalExpression.setValue(t.getImage()); + ((ASTNode) literalExpression).setOffset(t.getOffset()); + return literalExpression; case IToken.tFLOATINGPT: t = consume(); - literalExpression = createLiteralExpression(); - literalExpression.setKind( IASTLiteralExpression.lk_float_constant ); - literalExpression.setValue( t.getImage() ); - ((ASTNode)literalExpression).setOffset( t.getOffset() ); - return literalExpression; + literalExpression = createLiteralExpression(); + literalExpression.setKind(IASTLiteralExpression.lk_float_constant); + literalExpression.setValue(t.getImage()); + ((ASTNode) literalExpression).setOffset(t.getOffset()); + return literalExpression; case IToken.tSTRING: case IToken.tLSTRING: t = consume(); - literalExpression = createLiteralExpression(); - literalExpression.setKind( IASTLiteralExpression.lk_string_literal ); - literalExpression.setValue( t.getImage() ); - ((ASTNode)literalExpression).setOffset( t.getOffset() ); - return literalExpression; + literalExpression = createLiteralExpression(); + literalExpression.setKind(IASTLiteralExpression.lk_string_literal); + literalExpression.setValue(t.getImage()); + ((ASTNode) literalExpression).setOffset(t.getOffset()); + return literalExpression; case IToken.tCHAR: case IToken.tLCHAR: t = consume(); - literalExpression = createLiteralExpression(); - literalExpression.setKind( IASTLiteralExpression.lk_char_constant ); - literalExpression.setValue( t.getImage() ); - ((ASTNode)literalExpression).setOffset( t.getOffset() ); - return literalExpression; + literalExpression = createLiteralExpression(); + literalExpression.setKind(IASTLiteralExpression.lk_char_constant); + literalExpression.setValue(t.getImage()); + ((ASTNode) literalExpression).setOffset(t.getOffset()); + return literalExpression; case IToken.tLPAREN: t = consume(); - //TODO - do we need to return a wrapper? + //TODO - do we need to return a wrapper? IASTExpression lhs = expression(); consume(IToken.tRPAREN); return lhs; @@ -1019,7 +1085,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { default: IToken la = LA(1); startingOffset = la.getOffset(); - throwBacktrack( startingOffset, la.getLength() ); + throwBacktrack(startingOffset, la.getLength()); return null; } @@ -1046,35 +1112,32 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { IASTDeclSpecifier declSpecifier = null; IASTDeclarator declarator = null; - try - { - declSpecifier = declSpecifierSeq(false); - declarator = declarator(); + try { + declSpecifier = declSpecifierSeq(false); + declarator = declarator(); + } catch (BacktrackException bt) { + int endingOffset = lastToken == null ? 0 : lastToken.getEndOffset(); + backup(mark); + throwBacktrack(startingOffset, endingOffset - startingOffset); } - catch( BacktrackException bt ) + if (declarator == null || declarator.getName().toString() != null) //$NON-NLS-1$ { int endingOffset = lastToken == null ? 0 : lastToken.getEndOffset(); - backup( mark ); - throwBacktrack( startingOffset, endingOffset - startingOffset ); + backup(mark); + throwBacktrack(startingOffset, endingOffset - startingOffset); } - if( declarator == null || declarator.getName().toString() != null ) //$NON-NLS-1$ - { - int endingOffset = lastToken == null ? 0 : lastToken.getEndOffset(); - backup( mark ); - throwBacktrack( startingOffset, endingOffset - startingOffset ); - } - + IASTTypeId result = createTypeId(); - ((ASTNode)result).setOffset( startingOffset ); - - result.setDeclSpecifier( declSpecifier ); - declSpecifier.setParent( result ); - declSpecifier.setPropertyInParent( IASTTypeId.DECL_SPECIFIER ); - - result.setAbstractDeclarator( declarator ); - declarator.setParent( result ); - declarator.setPropertyInParent( IASTTypeId.ABSTRACT_DECLARATOR ); - + ((ASTNode) result).setOffset(startingOffset); + + result.setDeclSpecifier(declSpecifier); + declSpecifier.setParent(result); + declSpecifier.setPropertyInParent(IASTTypeId.DECL_SPECIFIER); + + result.setAbstractDeclarator(declarator); + declarator.setParent(result); + declarator.setPropertyInParent(IASTTypeId.ABSTRACT_DECLARATOR); + return result; } @@ -1103,9 +1166,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { boolean isConst = false, isVolatile = false, isRestrict = false; - if( LT(1) != IToken.tSTAR ) - { - backup( mark ); + if (LT(1) != IToken.tSTAR) { + backup(mark); break; } @@ -1133,7 +1195,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { } IASTPointerOperator po = createPointer(); - ((ASTNode)po).setOffset( startOffset ); + ((ASTNode) po).setOffset(startOffset); ((ICASTPointer) po).setConst(isConst); ((ICASTPointer) po).setVolatile(isVolatile); ((ICASTPointer) po).setRestrict(isRestrict); @@ -1163,7 +1225,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { IASTElaboratedTypeSpecifier elabSpec = null; IASTEnumerationSpecifier enumSpec = null; boolean isTypedef = false; - + declSpecifiers: for (;;) { switch (LT(1)) { //Storage Class Specifiers @@ -1184,7 +1246,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { consume(); break; case IToken.t_typedef: - isTypedef = true; + isTypedef = true; storageClass = IASTDeclSpecifier.sc_typedef; consume(); break; @@ -1233,12 +1295,10 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { case IToken.t_long: flags.setEncounteredRawType(true); consume(); - if( isLong ) - { + if (isLong) { isLongLong = true; isLong = false; - } - else + } else isLong = true; break; case IToken.t_float: @@ -1286,14 +1346,14 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { if (lookAheadForDeclarator(flags)) { break declSpecifiers; } - switch( LT(2) ) - { - case IToken.tLPAREN: - if (isTypedef) break; - case IToken.tSEMI: - case IToken.tASSIGN: - //TODO more - break declSpecifiers; + switch (LT(2)) { + case IToken.tLPAREN: + if (isTypedef) + break; + case IToken.tSEMI: + case IToken.tASSIGN: + //TODO more + break declSpecifiers; } identifier = identifier(); @@ -1303,11 +1363,11 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { case IToken.t_struct: case IToken.t_union: try { - structSpec = structOrUnionSpecifier( ); + structSpec = structOrUnionSpecifier(); flags.setEncounteredTypename(true); break; } catch (BacktrackException bt) { - elabSpec = elaboratedTypeSpecifier( ); + elabSpec = elaboratedTypeSpecifier(); flags.setEncounteredTypename(true); break; } @@ -1318,7 +1378,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { break; } catch (BacktrackException bt) { // this is an elaborated class specifier - elabSpec = elaboratedTypeSpecifier( ); + elabSpec = elaboratedTypeSpecifier(); flags.setEncounteredTypename(true); break; } @@ -1332,35 +1392,32 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { break declSpecifiers; } } - - if( structSpec != null ) - { - ((ASTNode)structSpec).setOffset( startingOffset ); + + if (structSpec != null) { + ((ASTNode) structSpec).setOffset(startingOffset); structSpec.setConst(isConst); - ((ICASTCompositeTypeSpecifier)structSpec).setRestrict(isRestrict); + ((ICASTCompositeTypeSpecifier) structSpec).setRestrict(isRestrict); structSpec.setVolatile(isVolatile); structSpec.setInline(isInline); structSpec.setStorageClass(storageClass); return structSpec; } - - if( enumSpec != null ) - { - ((ASTNode)enumSpec).setOffset( startingOffset ); + + if (enumSpec != null) { + ((ASTNode) enumSpec).setOffset(startingOffset); enumSpec.setConst(isConst); - ((CASTEnumerationSpecifier)enumSpec).setRestrict(isRestrict); + ((CASTEnumerationSpecifier) enumSpec).setRestrict(isRestrict); enumSpec.setVolatile(isVolatile); enumSpec.setInline(isInline); enumSpec.setStorageClass(storageClass); return enumSpec; - + } - if( elabSpec != null ) - { - ((ASTNode)elabSpec).setOffset( startingOffset ); + if (elabSpec != null) { + ((ASTNode) elabSpec).setOffset(startingOffset); elabSpec.setConst(isConst); - ((CASTElaboratedTypeSpecifier)elabSpec).setRestrict(isRestrict); + ((CASTElaboratedTypeSpecifier) elabSpec).setRestrict(isRestrict); elabSpec.setVolatile(isVolatile); elabSpec.setInline(isInline); elabSpec.setStorageClass(storageClass); @@ -1375,11 +1432,11 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { declSpec.setInline(isInline); declSpec.setStorageClass(storageClass); - ((ASTNode)declSpec).setOffset(startingOffset); - IASTName name = createName( identifier ); - declSpec.setName( name ); - name.setParent( declSpec ); - name.setPropertyInParent( IASTNamedTypeSpecifier.NAME ); + ((ASTNode) declSpec).setOffset(startingOffset); + IASTName name = createName(identifier); + declSpec.setName(name); + name.setParent(declSpec); + name.setPropertyInParent(IASTNamedTypeSpecifier.NAME); return declSpec; } ICASTSimpleDeclSpecifier declSpec = createSimpleTypeSpecifier(); @@ -1391,12 +1448,12 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { declSpec.setType(simpleType); declSpec.setLong(isLong); - declSpec.setLongLong( isLongLong ); + declSpec.setLongLong(isLongLong); declSpec.setUnsigned(isUnsigned); declSpec.setSigned(isSigned); declSpec.setShort(isShort); - ((ASTNode)declSpec).setOffset(startingOffset); + ((ASTNode) declSpec).setOffset(startingOffset); return declSpec; } @@ -1419,6 +1476,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { * * classSpecifier : classKey name (baseClause)? "{" (memberSpecification)* * "}" + * * @param owner * IParserCallback object that represents the declaration that * owns this classSpecifier @@ -1427,7 +1485,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { * @throws BacktrackException * request a backtrack */ - protected ICASTCompositeTypeSpecifier structOrUnionSpecifier( ) + protected ICASTCompositeTypeSpecifier structOrUnionSpecifier() throws BacktrackException, EndOfFileException { int classKind = 0; @@ -1445,7 +1503,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { classKind = IASTCompositeTypeSpecifier.k_union; break; default: - throwBacktrack(mark.getOffset(), mark.getLength() ); + throwBacktrack(mark.getOffset(), mark.getLength()); } IToken nameToken = null; @@ -1462,23 +1520,22 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { consume(IToken.tLBRACE); cleanupLastToken(); - + IASTName name = null; - if( nameToken != null ) - name = createName( nameToken ); + if (nameToken != null) + name = createName(nameToken); else name = createName(); - + ICASTCompositeTypeSpecifier result = createCompositeTypeSpecifier(); - - result.setKey( classKind ); - ((ASTNode)result).setOffset( classKey.getOffset() ); - - result.setName( name ); - if( name != null ) - { - name.setParent( result ); - name.setPropertyInParent( IASTCompositeTypeSpecifier.TYPE_NAME ); + + result.setKey(classKind); + ((ASTNode) result).setOffset(classKey.getOffset()); + + result.setName(name); + if (name != null) { + name.setParent(result); + name.setPropertyInParent(IASTCompositeTypeSpecifier.TYPE_NAME); } memberDeclarationLoop: while (LT(1) != IToken.tRBRACE) { @@ -1490,9 +1547,10 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { default: try { IASTDeclaration d = declaration(); - d.setParent( result ); - d.setPropertyInParent( IASTCompositeTypeSpecifier.MEMBER_DECLARATION ); - result.addMemberDeclaration( d ); + d.setParent(result); + d + .setPropertyInParent(IASTCompositeTypeSpecifier.MEMBER_DECLARATION); + result.addMemberDeclaration(d); } catch (BacktrackException bt) { if (checkToken == LA(1).hashCode()) failParseWithErrorHandling(); @@ -1538,16 +1596,16 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { break; default: backup(t); - throwBacktrack(t.getOffset(), t.getLength() ); + throwBacktrack(t.getOffset(), t.getLength()); } IToken identifier = identifier(); - IASTName name = createName( identifier ); + IASTName name = createName(identifier); ICASTElaboratedTypeSpecifier result = createElaboratedTypeSpecifier(); - result.setName( name ); - name.setParent( result ); - name.setPropertyInParent( IASTElaboratedTypeSpecifier.TYPE_NAME ); - result.setKind( eck ); + result.setName(name); + name.setParent(result); + name.setPropertyInParent(IASTElaboratedTypeSpecifier.TYPE_NAME); + result.setKind(eck); return result; } @@ -1600,8 +1658,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { declaratorName = createName(); } else if (LT(1) == IToken.tIDENTIFIER) { declaratorName = createName(identifier()); - } - else + } else declaratorName = createName(); for (;;) { @@ -1630,7 +1687,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { int endOffset = (lastToken != null) ? lastToken .getEndOffset() : 0; if (seenParameter) - throwBacktrack(startingOffset, endOffset - startingOffset); + throwBacktrack(startingOffset, endOffset + - startingOffset); IASTParameterDeclaration pd = parameterDeclaration(); if (parameters == Collections.EMPTY_LIST) parameters = new ArrayList( @@ -1639,12 +1697,12 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { seenParameter = true; } } - + break; case IToken.tLBRACKET: - if( arrayMods == Collections.EMPTY_LIST ) - arrayMods = new ArrayList( DEFAULT_POINTEROPS_LIST_SIZE ); - consumeArrayModifiers( arrayMods ); + if (arrayMods == Collections.EMPTY_LIST) + arrayMods = new ArrayList(DEFAULT_POINTEROPS_LIST_SIZE); + consumeArrayModifiers(arrayMods); continue; case IToken.tCOLON: consume(IToken.tCOLON); @@ -1663,32 +1721,28 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { if (isFunction) { IASTFunctionDeclarator fc = createFunctionDeclarator(); fc.setVarArgs(encounteredVarArgs); - for (int i = 0; i < parameters.size(); ++i) - { + for (int i = 0; i < parameters.size(); ++i) { IASTParameterDeclaration p = (IASTParameterDeclaration) parameters - .get(i); - p.setParent( fc ); - p.setPropertyInParent( IASTFunctionDeclarator.FUNCTION_PARAMETER ); + .get(i); + p.setParent(fc); + p + .setPropertyInParent(IASTFunctionDeclarator.FUNCTION_PARAMETER); fc.addParameterDeclaration(p); } d = fc; - } else if( arrayMods != Collections.EMPTY_LIST ) - { + } else if (arrayMods != Collections.EMPTY_LIST) { d = createArrayDeclarator(); - for( int i = 0; i < arrayMods.size(); ++i ) - { + for (int i = 0; i < arrayMods.size(); ++i) { IASTArrayModifier m = (IASTArrayModifier) arrayMods.get(i); - m.setParent( d ); - m.setPropertyInParent( IASTArrayDeclarator.ARRAY_MODIFIER ); - ((IASTArrayDeclarator)d).addArrayModifier( m ); + m.setParent(d); + m.setPropertyInParent(IASTArrayDeclarator.ARRAY_MODIFIER); + ((IASTArrayDeclarator) d).addArrayModifier(m); } - } - else if (bitField != null) { + } else if (bitField != null) { IASTFieldDeclarator fl = createFieldDeclarator(); fl.setBitFieldSize(bitField); d = fl; - } else - { + } else { d = createDeclarator(); } for (int i = 0; i < pointerOps.size(); ++i) { @@ -1711,10 +1765,9 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { return d; } - - protected IASTArrayDeclarator createArrayDeclarator() { - return new CASTArrayDeclarator(); - } + protected IASTArrayDeclarator createArrayDeclarator() { + return new CASTArrayDeclarator(); + } /** * @return @@ -1730,16 +1783,13 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { return new CASTFunctionDeclarator(); } - - - /** * @param t * @return */ protected IASTName createName(IToken t) { IASTName n = new CASTName(t.getCharImage()); - ((ASTNode)n).setOffset(t.getOffset()); + ((ASTNode) n).setOffset(t.getOffset()); return n; } @@ -1750,41 +1800,41 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { return new CASTDeclarator(); } - protected void consumeArrayModifiers(List arrayMods ) + protected void consumeArrayModifiers(List arrayMods) throws EndOfFileException, BacktrackException { while (LT(1) == IToken.tLBRACKET) { //eat the '[' - int startOffset = consume(IToken.tLBRACKET).getOffset(); + int startOffset = consume(IToken.tLBRACKET).getOffset(); boolean isStatic = false; boolean isConst = false; boolean isRestrict = false; boolean isVolatile = false; boolean isVarSized = false; - + outerLoop: do { switch (LT(1)) { case IToken.t_static: isStatic = true; - consume(); - break; + consume(); + break; case IToken.t_const: isConst = true; - consume(); - break; + consume(); + break; case IToken.t_volatile: isVolatile = true; - consume(); - break; + consume(); + break; case IToken.t_restrict: isRestrict = true; - consume(); + consume(); break; case IToken.tSTAR: isVarSized = true; - consume(); - //deliberate fall through + consume(); + //deliberate fall through default: break outerLoop; } @@ -1793,34 +1843,32 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { IASTExpression exp = null; if (LT(1) != IToken.tRBRACKET) { - if (!( isStatic || isRestrict || isConst || isVolatile )) + if (!(isStatic || isRestrict || isConst || isVolatile)) exp = assignmentExpression(); else exp = constantExpression(); } consume(IToken.tRBRACKET); - + IASTArrayModifier arrayMod = null; - if(!( isStatic || isRestrict || isConst || isVolatile )) + if (!(isStatic || isRestrict || isConst || isVolatile)) arrayMod = createArrayModifier(); - else - { + else { ICASTArrayModifier temp = createCArrayModifier(); - temp.setStatic( isStatic ); - temp.setConst( isConst ); - temp.setVolatile( isVolatile ); + temp.setStatic(isStatic); + temp.setConst(isConst); + temp.setVolatile(isVolatile); temp.setRestrict(isRestrict); - temp.setVariableSized(isVarSized ); + temp.setVariableSized(isVarSized); arrayMod = temp; } - ((ASTNode)arrayMod).setOffset( startOffset ); - if( exp != null ) - { - arrayMod.setConstantExpression( exp ); - exp.setParent( arrayMod ); - exp.setPropertyInParent( IASTArrayModifier.CONSTANT_EXPRESSION ); + ((ASTNode) arrayMod).setOffset(startOffset); + if (exp != null) { + arrayMod.setConstantExpression(exp); + exp.setParent(arrayMod); + exp.setPropertyInParent(IASTArrayModifier.CONSTANT_EXPRESSION); } - arrayMods.add( arrayMod ); + arrayMods.add(arrayMod); } } @@ -1850,11 +1898,11 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { if (current == LA(1)) { int endOffset = (lastToken != null) ? lastToken.getEndOffset() : 0; - throwBacktrack(current.getOffset(), endOffset - current.getOffset() ); + throwBacktrack(current.getOffset(), endOffset - current.getOffset()); } IASTParameterDeclaration result = createParameterDeclaration(); - ((ASTNode)result).setOffset(startingOffset); + ((ASTNode) result).setOffset(startingOffset); result.setDeclSpecifier(declSpec); declSpec.setParent(result); declSpec.setPropertyInParent(IASTParameterDeclaration.DECL_SPECIFIER); @@ -1887,11 +1935,15 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { try { return simpleDeclaration(); } catch (BacktrackException b) { - failParse(b); - throwBacktrack(b); + IASTProblem p = failParse(b); + IASTProblemExpression pe = createProblemExpression(); + ((CASTNode) pe).setOffset(((CASTNode) p).getOffset()); + pe.setProblem(p); + p.setParent(pe); + p.setPropertyInParent(IASTProblemExpression.PROBLEM); + return pe; } } - return null; } /* @@ -1921,35 +1973,45 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { return new CASTBinaryExpression(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createConditionalExpression() */ protected IASTConditionalExpression createConditionalExpression() { return new CASTConditionalExpression(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createUnaryExpression() */ protected IASTUnaryExpression createUnaryExpression() { return new CASTUnaryExpression(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createCompoundStatementExpression() */ protected IGNUASTCompoundStatementExpression createCompoundStatementExpression() { return new CASTCompoundStatementExpression(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createExpressionList() */ protected IASTExpressionList createExpressionList() { return new CASTExpressionList(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createEnumerator() */ protected IASTEnumerator createEnumerator() { @@ -2079,11 +2141,12 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { return new CASTCastExpression(); } - protected IASTStatement statement() throws EndOfFileException, BacktrackException { + protected IASTStatement statement() throws EndOfFileException, + BacktrackException { switch (LT(1)) { // labeled statements case IToken.t_case: - return parseCaseStatement(); + return parseCaseStatement(); case IToken.t_default: return parseDefaultStatement(); // compound statement @@ -2118,18 +2181,50 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { if (LT(1) == IToken.tIDENTIFIER && LT(2) == IToken.tCOLON) { return parseLabelStatement(); } - - return parseDeclarationOrExpressionStatement(); + + return parseDeclarationOrExpressionStatement(); } - + } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser#nullifyTranslationUnit() */ protected void nullifyTranslationUnit() { translationUnit = null; } + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser#createProblemStatement() + */ + protected IASTProblemStatement createProblemStatement() { + return new CASTProblemStatement(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser#createProblemExpression() + */ + protected IASTProblemExpression createProblemExpression() { + return new CASTProblemExpression(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser#createProblem(int, + * int, int) + */ + protected IASTProblem createProblem(int signal, int offset, int length) { + IASTProblem result = new CASTProblem(signal, EMPTY_STRING, false, true); + ((ASTNode) result).setOffset(offset); + ((ASTNode) result).setLength(length); + return result; + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblem.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblem.java new file mode 100644 index 00000000000..2d70f159a37 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblem.java @@ -0,0 +1,397 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.cpp; + +import java.text.MessageFormat; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTProblem; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.parser.IProblem; +import org.eclipse.cdt.internal.core.parser.ParserMessages; + +/** + * @author jcamelon + */ +public class CPPASTProblem extends CPPASTNode implements IASTProblem { + private IASTNode parent; + + private ASTNodeProperty property; + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.dom.ast.IASTNode#getParent() + */ + public IASTNode getParent() { + return parent; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.dom.ast.IASTNode#setParent(org.eclipse.cdt.core.dom.ast.IASTNode) + */ + public void setParent(IASTNode node) { + this.parent = node; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.dom.ast.IASTNode#getPropertyInParent() + */ + public ASTNodeProperty getPropertyInParent() { + return property; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.dom.ast.IASTNode#setPropertyInParent(org.eclipse.cdt.core.dom.ast.ASTNodeProperty) + */ + public void setPropertyInParent(ASTNodeProperty property) { + this.property = property; + } + + private final char[] arg; + + private final int id; + + private final boolean isError; + + private final boolean isWarning; + + private String message = null; + + public CPPASTProblem(int id, char[] arg, boolean warn, boolean error) { + this.id = id; + this.arg = arg; + this.isWarning = warn; + this.isError = error; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.parser.IProblem#getID() + */ + public int getID() { + return id; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.parser.IProblem#isError() + */ + public boolean isError() { + return isError; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.parser.IProblem#isWarning() + */ + public boolean isWarning() { + return isWarning; + } + + protected static final Map errorMessages; + static { + errorMessages = new HashMap(); + errorMessages + .put( + new Integer(IProblem.SEMANTIC_UNIQUE_NAME_PREDEFINED), + ParserMessages + .getString("ASTProblemFactory.error.semantic.uniqueNamePredefined")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SEMANTIC_NAME_NOT_FOUND), + ParserMessages + .getString("ASTProblemFactory.error.semantic.nameNotFound")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SEMANTIC_NAME_NOT_PROVIDED), + ParserMessages + .getString("ASTProblemFactory.error.semantic.nameNotProvided")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SEMANTIC_INVALID_CONVERSION_TYPE), + ParserMessages + .getString("ASTProblemFactory.error.semantic.invalidConversionType")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SEMANTIC_MALFORMED_EXPRESSION), + ParserMessages + .getString("ASTProblemFactory.error.semantic.malformedExpression")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SEMANTIC_AMBIGUOUS_LOOKUP), + ParserMessages + .getString("ASTProblemFactory.error.semantic.pst.ambiguousLookup")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SEMANTIC_INVALID_TYPE), + ParserMessages + .getString("ASTProblemFactory.error.semantic.pst.invalidType")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SEMANTIC_CIRCULAR_INHERITANCE), + ParserMessages + .getString("ASTProblemFactory.error.semantic.pst.circularInheritance")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SEMANTIC_INVALID_OVERLOAD), + ParserMessages + .getString("ASTProblemFactory.error.semantic.pst.invalidOverload")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SEMANTIC_INVALID_TEMPLATE), + ParserMessages + .getString("ASTProblemFactory.error.semantic.pst.invalidTemplate")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SEMANTIC_INVALID_USING), + ParserMessages + .getString("ASTProblemFactory.error.semantic.pst.invalidUsing")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SEMANTIC_BAD_VISIBILITY), + ParserMessages + .getString("ASTProblemFactory.error.semantic.pst.badVisibility")); //$NON-NLS-1$ + errorMessages + .put( + new Integer( + IProblem.SEMANTIC_UNABLE_TO_RESOLVE_FUNCTION), + ParserMessages + .getString("ASTProblemFactory.error.semantic.pst.unableToResolveFunction")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SEMANTIC_INVALID_TEMPLATE_ARGUMENT), + ParserMessages + .getString("ASTProblemFactory.error.semantic.pst.invalidTemplateArgument")); //$NON-NLS-1$ + errorMessages + .put( + new Integer( + IProblem.SEMANTIC_INVALID_TEMPLATE_PARAMETER), + ParserMessages + .getString("ASTProblemFactory.error.semantic.pst.invalidTemplateParameter")); //$NON-NLS-1$ + errorMessages + .put( + new Integer( + IProblem.SEMANTIC_REDECLARED_TEMPLATE_PARAMETER), + ParserMessages + .getString("ASTProblemFactory.error.semantic.pst.redeclaredTemplateParameter")); //$NON-NLS-1$ + errorMessages + .put( + new Integer( + IProblem.SEMANTIC_RECURSIVE_TEMPLATE_INSTANTIATION), + ParserMessages + .getString("ASTProblemFactory.error.semantic.pst.recursiveTemplateInstantiation")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.PREPROCESSOR_POUND_ERROR), + ParserMessages + .getString("ScannerProblemFactory.error.preproc.error")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND), + ParserMessages + .getString("ScannerProblemFactory.error.preproc.inclusionNotFound")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.PREPROCESSOR_DEFINITION_NOT_FOUND), + ParserMessages + .getString("ScannerProblemFactory.error.preproc.definitionNotFound")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.PREPROCESSOR_INVALID_MACRO_DEFN), + ParserMessages + .getString("ScannerProblemFactory.error.preproc.invalidMacroDefn")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.PREPROCESSOR_INVALID_MACRO_REDEFN), + ParserMessages + .getString("ScannerProblemFactory.error.preproc.invalidMacroRedefn")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.PREPROCESSOR_UNBALANCE_CONDITION), + ParserMessages + .getString("ScannerProblemFactory.error.preproc.unbalancedConditional")); //$NON-NLS-1$ + errorMessages + .put( + new Integer( + IProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR), + ParserMessages + .getString("ScannerProblemFactory.error.preproc.conditionalEval")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.PREPROCESSOR_MACRO_USAGE_ERROR), + ParserMessages + .getString("ScannerProblemFactory.error.preproc.macroUsage")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.PREPROCESSOR_CIRCULAR_INCLUSION), + ParserMessages + .getString("ScannerProblemFactory.error.preproc.circularInclusion")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.PREPROCESSOR_INVALID_DIRECTIVE), + ParserMessages + .getString("ScannerProblemFactory.error.preproc.invalidDirective")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.PREPROCESSOR_MACRO_PASTING_ERROR), + ParserMessages + .getString("ScannerProblemFactory.error.preproc.macroPasting")); //$NON-NLS-1$ + errorMessages + .put( + new Integer( + IProblem.PREPROCESSOR_MISSING_RPAREN_PARMLIST), + ParserMessages + .getString("ScannerProblemFactory.error.preproc.missingRParen")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.PREPROCESSOR_INVALID_VA_ARGS), + ParserMessages + .getString("ScannerProblemFactory.error.preproc.invalidVaArgs")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SCANNER_INVALID_ESCAPECHAR), + ParserMessages + .getString("ScannerProblemFactory.error.scanner.invalidEscapeChar")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SCANNER_UNBOUNDED_STRING), + ParserMessages + .getString("ScannerProblemFactory.error.scanner.unboundedString")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SCANNER_BAD_FLOATING_POINT), + ParserMessages + .getString("ScannerProblemFactory.error.scanner.badFloatingPoint")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SCANNER_BAD_HEX_FORMAT), + ParserMessages + .getString("ScannerProblemFactory.error.scanner.badHexFormat")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SCANNER_BAD_OCTAL_FORMAT), + ParserMessages + .getString("ScannerProblemFactory.error.scanner.badOctalFormat")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SCANNER_BAD_DECIMAL_FORMAT), + ParserMessages + .getString("ScannerProblemFactory.error.scanner.badDecimalFormat")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SCANNER_ASSIGNMENT_NOT_ALLOWED), + ParserMessages + .getString("ScannerProblemFactory.error.scanner.assignmentNotAllowed")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SCANNER_DIVIDE_BY_ZERO), + ParserMessages + .getString("ScannerProblemFactory.error.scanner.divideByZero")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SCANNER_MISSING_R_PAREN), + ParserMessages + .getString("ScannerProblemFactory.error.scanner.missingRParen")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SCANNER_EXPRESSION_SYNTAX_ERROR), + ParserMessages + .getString("ScannerProblemFactory.error.scanner.expressionSyntaxError")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SCANNER_ILLEGAL_IDENTIFIER), + ParserMessages + .getString("ScannerProblemFactory.error.scanner.illegalIdentifier")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SCANNER_BAD_CONDITIONAL_EXPRESSION), + ParserMessages + .getString("ScannerProblemFactory.error.scanner.badConditionalExpression")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SCANNER_UNEXPECTED_EOF), + ParserMessages + .getString("ScannerProblemFactory.error.scanner.unexpectedEOF")); //$NON-NLS-1$ + errorMessages + .put( + new Integer(IProblem.SCANNER_BAD_CHARACTER), + ParserMessages + .getString("ScannerProblemFactory.error.scanner.badCharacter")); //$NON-NLS-1$ + errorMessages.put(new Integer(IProblem.SYNTAX_ERROR), ParserMessages + .getString("ParserProblemFactory.error.syntax.syntaxError")); //$NON-NLS-1$ + } + + protected final static String PROBLEM_PATTERN = "BaseProblemFactory.problemPattern"; //$NON-NLS-1$ + + public String getMessage() { + if (message != null) + return message; + + String msg = (String) errorMessages.get(new Integer(id)); + if (msg == null) + msg = ""; //$NON-NLS-1$ + + if (arg != null) { + msg = MessageFormat.format(msg, new Object[] { new String(arg) }); + } + + Object[] args = new Object[] { msg, new String(""), new Integer(0) }; //$NON-NLS-1$ + message = ParserMessages.getFormattedString(PROBLEM_PATTERN, args); + return message; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.parser.IProblem#checkCategory(int) + */ + public boolean checkCategory(int bitmask) { + return ((id & bitmask) != 0); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.parser.IProblem#getArguments() + */ + public String getArguments() { + return arg != null ? String.valueOf(arg) : ""; //$NON-NLS-1$ + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.dom.ast.IASTNode#getTranslationUnit() + */ + public IASTTranslationUnit getTranslationUnit() { + if (this instanceof IASTTranslationUnit) + return (IASTTranslationUnit) this; + IASTNode node = getParent(); + while (!(node instanceof IASTTranslationUnit) && node != null) { + node = node.getParent(); + } + return (IASTTranslationUnit) node; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemDeclaration.java new file mode 100644 index 00000000000..7c6a59c32d4 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemDeclaration.java @@ -0,0 +1,21 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration; + +/** + * @author jcamelon + */ +public class CPPASTProblemDeclaration extends CPPASTProblemOwner implements + IASTProblemDeclaration { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemExpression.java new file mode 100644 index 00000000000..f6e0221f734 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemExpression.java @@ -0,0 +1,21 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTProblemExpression; + +/** + * @author jcamelon + */ +public class CPPASTProblemExpression extends CPPASTProblemOwner implements + IASTProblemExpression { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemOwner.java new file mode 100644 index 00000000000..f0544152785 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemOwner.java @@ -0,0 +1,31 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTProblem; + +/** + * @author jcamelon + */ +class CPPASTProblemOwner extends CPPASTNode { + + private IASTProblem problem; + + public IASTProblem getProblem() + { + return problem; + } + + public void setProblem(IASTProblem p) + { + problem = p; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemStatement.java new file mode 100644 index 00000000000..16ac631cda8 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemStatement.java @@ -0,0 +1,21 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTProblemStatement; + +/** + * @author jcamelon + */ +public class CPPASTProblemStatement extends CPPASTProblemOwner implements + IASTProblemStatement { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemTypeId.java new file mode 100644 index 00000000000..958283e7f0b --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemTypeId.java @@ -0,0 +1,38 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTProblem; +import org.eclipse.cdt.core.dom.ast.IASTProblemTypeId; + +/** + * @author jcamelon + */ +public class CPPASTProblemTypeId extends CPPASTTypeId implements + IASTProblemTypeId { + + private IASTProblem problem; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTProblemTypeId#getProblem() + */ + public IASTProblem getProblem() { + return problem; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTProblemTypeId#setProblem(org.eclipse.cdt.core.dom.ast.IASTProblem) + */ + public void setProblem(IASTProblem p) { + problem = p; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java index b60b1ed7b25..ab445d5f65f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java @@ -59,6 +59,10 @@ import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTPointer; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; import org.eclipse.cdt.core.dom.ast.IASTProblem; +import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTProblemExpression; +import org.eclipse.cdt.core.dom.ast.IASTProblemStatement; +import org.eclipse.cdt.core.dom.ast.IASTProblemTypeId; import org.eclipse.cdt.core.dom.ast.IASTReturnStatement; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; @@ -128,7 +132,6 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser; import org.eclipse.cdt.internal.core.dom.parser.BacktrackException; -import org.eclipse.cdt.internal.core.dom.parser.IProblemRequestor; import org.eclipse.cdt.internal.core.parser.SimpleDeclarationStrategy; import org.eclipse.cdt.internal.core.parser.TemplateParameterManager; import org.eclipse.cdt.internal.core.parser.token.TokenFactory; @@ -1718,10 +1721,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * */ public GNUCPPSourceParser(IScanner scanner, ParserMode mode, - IProblemRequestor callback, IParserLogService log, - ICPPParserExtensionConfiguration config) { - super( scanner, log, mode, callback, config.supportStatementsInExpressions(), - config.supportTypeofUnaryExpressions(), config.supportAlignOfUnaryExpression() ); + IParserLogService log, ICPPParserExtensionConfiguration config) { + super( scanner, log, mode, config.supportStatementsInExpressions(), config.supportTypeofUnaryExpressions(), + config.supportAlignOfUnaryExpression() ); allowCPPRestrict = config.allowRestrictPointerOperators(); supportExtendedTemplateSyntax = config .supportExtendedTemplateSyntax(); @@ -1838,9 +1840,18 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { d.setParent( linkage ); d.setPropertyInParent( ICPPASTLinkageSpecification.OWNED_DECLARATION ); } catch (BacktrackException bt) { - failParse(bt); + IASTProblem p = failParse(bt); + IASTProblemDeclaration pd = createProblemDeclaration(); + p.setParent( pd ); + pd.setProblem( p ); + ((CPPASTNode)pd).setOffset( ((CPPASTNode)p).getOffset() ); + p.setPropertyInParent( IASTProblemDeclaration.PROBLEM ); + linkage.addDeclaration( pd ); + pd.setParent( linkage ); + pd.setPropertyInParent( ICPPASTLinkageSpecification.OWNED_DECLARATION ); + errorHandling(); if (checkToken == LA(1).hashCode()) - failParseWithErrorHandling(); + errorHandling(); } } if (checkToken == LA(1).hashCode()) @@ -2277,9 +2288,18 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { d.setPropertyInParent( ICPPASTNamespaceDefinition.OWNED_DECLARATION ); namespaceDefinition.addDeclaration( d ); } catch (BacktrackException bt) { - failParse(bt); + IASTProblem p = failParse(bt); + IASTProblemDeclaration pd = createProblemDeclaration(); + p.setParent( pd ); + pd.setProblem( p ); + ((CPPASTNode)pd).setOffset( ((CPPASTNode)p).getOffset() ); + p.setPropertyInParent( IASTProblemDeclaration.PROBLEM ); + namespaceDefinition.addDeclaration( pd ); + pd.setParent( namespaceDefinition ); + pd.setPropertyInParent( ICPPASTNamespaceDefinition.OWNED_DECLARATION ); + errorHandling(); if (checkToken == LA(1).hashCode()) - failParseWithErrorHandling(); + errorHandling(); } } if (checkToken == LA(1).hashCode()) @@ -3460,8 +3480,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { try { exceptionSpecIds.add(typeId(false)); } catch (BacktrackException e) { - failParse(e); - break; + IASTProblem p = failParse(e); + IASTProblemTypeId typeIdProblem = createTypeIDProblem(); + typeIdProblem.setProblem( p ); + ((CPPASTNode)typeIdProblem).setOffset( ((CPPASTNode)p).getOffset() ); + p.setParent( typeIdProblem ); + p.setPropertyInParent( IASTProblemTypeId.PROBLEM ); + exceptionSpecIds.add( typeIdProblem ); } break; } @@ -3581,6 +3606,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } + /** + * @return + */ + protected IASTProblemTypeId createTypeIDProblem() { + return new CPPASTProblemTypeId(); + } + /** * @return */ @@ -3767,8 +3799,17 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { d.setParent( astClassSpecifier ); d.setPropertyInParent( IASTCompositeTypeSpecifier.MEMBER_DECLARATION ); } catch (BacktrackException bt) { + IASTProblem p = failParse(bt); + IASTProblemDeclaration pd = createProblemDeclaration(); + pd.setProblem( p ); + ((CPPASTNode)pd).setOffset( ((CPPASTNode)p).getOffset() ); + p.setParent( pd ); + p.setPropertyInParent( IASTProblemDeclaration.PROBLEM ); + astClassSpecifier.addMemberDeclaration( pd ); + pd.setParent( astClassSpecifier ); + pd.setPropertyInParent( IASTCompositeTypeSpecifier.MEMBER_DECLARATION ); if (checkToken == LA(1).hashCode()) - failParseWithErrorHandling(); + errorHandling(); } } if (checkToken == LA(1).hashCode()) @@ -3931,9 +3972,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { while (LT(1) == IToken.t_catch) { int startOffset = consume(IToken.t_catch).getOffset(); consume(IToken.tLPAREN); + boolean isEllipsis = false; + IASTDeclaration decl = null; try { - boolean isEllipsis = false; - IASTDeclaration decl = null; if (LT(1) == IToken.tELLIPSIS) { consume(IToken.tELLIPSIS); @@ -3945,29 +3986,35 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { true); } consume(IToken.tRPAREN); - - IASTStatement compoundStatement = catchBlockCompoundStatement(); - ICPPASTCatchHandler handler = createCatchHandler(); - ((ASTNode)handler).setOffset( startOffset ); - handler.setIsCatchAll( isEllipsis ); - if( decl != null ) - { - handler.setDeclaration( decl ); - decl.setParent( handler ); - decl.setPropertyInParent( ICPPASTCatchHandler.DECLARATION ); - } - if( compoundStatement != null ) - { - handler.setCatchBody( compoundStatement ); - compoundStatement.setParent( handler ); - compoundStatement.setPropertyInParent( ICPPASTCatchHandler.CATCH_BODY ); - } - collection.add( handler ); - } catch (BacktrackException bte) { - failParse(bte); - failParseWithErrorHandling(); } - } + catch (BacktrackException bte) { + IASTProblem p = failParse(bte); + IASTProblemDeclaration pd = createProblemDeclaration(); + pd.setProblem( p ); + ((CPPASTNode)pd).setOffset( ((CPPASTNode)p).getOffset() ); + p.setParent( pd ); + p.setPropertyInParent( IASTProblemDeclaration.PROBLEM ); + decl = pd; + } + + IASTStatement compoundStatement = catchBlockCompoundStatement(); + ICPPASTCatchHandler handler = createCatchHandler(); + ((ASTNode)handler).setOffset( startOffset ); + handler.setIsCatchAll( isEllipsis ); + if( decl != null ) + { + handler.setDeclaration( decl ); + decl.setParent( handler ); + decl.setPropertyInParent( ICPPASTCatchHandler.DECLARATION ); + } + if( compoundStatement != null ) + { + handler.setCatchBody( compoundStatement ); + compoundStatement.setParent( handler ); + compoundStatement.setPropertyInParent( ICPPASTCatchHandler.CATCH_BODY ); + } + collection.add( handler ); + } } /** @@ -4011,7 +4058,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { try { return simpleDeclarationStrategyUnion(); } catch (BacktrackException b) { - failParse(b); + failParse(); throwBacktrack(b); return null; } @@ -4051,20 +4098,16 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } catch (BacktrackException b) { try { // Mark as failure and try to reach a recovery point - failParse(b); + IASTProblem p = failParse(b); + IASTProblemDeclaration pd = createProblemDeclaration(); + p.setParent( pd ); + pd.setProblem( p ); + ((CPPASTNode)pd).setOffset( ((CPPASTNode)p).getOffset() ); + p.setPropertyInParent( IASTProblemDeclaration.PROBLEM ); + translationUnit.addDeclaration( pd ); + pd.setParent( translationUnit ); + pd.setPropertyInParent( IASTTranslationUnit.OWNED_DECLARATION ); errorHandling(); - // if (lastBacktrack != -1 && lastBacktrack == - // LA(1).hashCode()) - // { - // // we haven't progressed from the last backtrack - // // try and find tne next definition - // failParseWithErrorHandling(); - // } - // else - // { - // // start again from here - // lastBacktrack = LA(1).hashCode(); - // } } catch (EndOfFileException e) { break; } @@ -4091,6 +4134,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } } + /** + * @return + */ + protected IASTProblemDeclaration createProblemDeclaration() { + return new CPPASTProblemDeclaration(); + } + /** * @return */ @@ -4431,5 +4481,31 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { translationUnit = null; } - + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser#createProblemStatement() + */ + protected IASTProblemStatement createProblemStatement() { + return new CPPASTProblemStatement(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser#createProblemExpression() + */ + protected IASTProblemExpression createProblemExpression() { + return new CPPASTProblemExpression(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser#createProblem(int, + * int, int) + */ + protected IASTProblem createProblem(int signal, int offset, int length) { + IASTProblem result = new CPPASTProblem(signal, EMPTY_STRING, false, true); + ((ASTNode) result).setOffset(offset); + ((ASTNode) result).setLength(length); + return result; + } + } \ No newline at end of file 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 87f8b433285..551e28af050 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 @@ -21,7 +21,7 @@ import org.eclipse.cdt.core.parser.IToken; 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.dom.parser.ASTProblem; +import org.eclipse.cdt.internal.core.dom.parser.c.CASTProblem; import org.eclipse.cdt.internal.core.parser.token.ImagedExpansionToken; import org.eclipse.cdt.internal.core.parser.token.ImagedToken; import org.eclipse.cdt.internal.core.parser.token.SimpleExpansionToken; @@ -180,7 +180,7 @@ public class DOMScanner extends BaseScanner { * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#handleProblem(int, int, char[]) */ protected void handleProblem(int id, int startOffset, char[] arg) { - IASTProblem problem = new ASTProblem(id, arg, true, false ); + IASTProblem problem = new CASTProblem(id, arg, true, false ); locationMap.encounterProblem(problem); } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java index c77b2ac257b..4a725f7755a 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java @@ -17,7 +17,6 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IASTServiceProvider; import org.eclipse.cdt.core.dom.ICodeReaderFactory; import org.eclipse.cdt.core.dom.IParserConfiguration; -import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.filetype.ICFileType; import org.eclipse.cdt.core.filetype.ICFileTypeConstants; @@ -32,7 +31,6 @@ import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ParserUtil; import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.internal.core.dom.parser.IProblemRequestor; import org.eclipse.cdt.internal.core.dom.parser.IRequiresLocationInformation; import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser; import org.eclipse.cdt.internal.core.dom.parser.c.ANSICParserExtensionConfiguration; @@ -58,12 +56,6 @@ public class InternalASTServiceProvider implements IASTServiceProvider { "GNUC", //$NON-NLS-1$ "GNUC++" }; //$NON-NLS-1$ private static final ISourceElementRequestor NULL_REQUESTOR = new NullSourceElementRequestor(); - private static final IProblemRequestor PROBLEM_REQUESTOR = new IProblemRequestor() { - - public boolean acceptProblem(IASTProblem problem) { - return true; - } - }; /* (non-Javadoc) @@ -124,9 +116,9 @@ public class InternalASTServiceProvider implements IASTServiceProvider { ParserUtil.getScannerLogService(), Collections.EMPTY_LIST); //assume GCC if( l == ParserLanguage.C ) - parser = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, PROBLEM_REQUESTOR, ParserUtil.getParserLogService(), new GCCParserExtensionConfiguration() ); + parser = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, ParserUtil.getParserLogService(), new GCCParserExtensionConfiguration() ); else - parser = new GNUCPPSourceParser( scanner, ParserMode.COMPLETE_PARSE, PROBLEM_REQUESTOR, ParserUtil.getParserLogService(), new GNUCPPParserExtensionConfiguration() ); + parser = new GNUCPPSourceParser( scanner, ParserMode.COMPLETE_PARSE, ParserUtil.getParserLogService(), new GNUCPPParserExtensionConfiguration() ); } else { @@ -145,22 +137,22 @@ public class InternalASTServiceProvider implements IASTServiceProvider { if( dialect.equals( dialects[0])) { ICParserExtensionConfiguration config = new ANSICParserExtensionConfiguration(); - parser = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, PROBLEM_REQUESTOR, ParserUtil.getParserLogService(), config ); + parser = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, ParserUtil.getParserLogService(), config ); } else if( dialect.equals( dialects[1] )) { ICPPParserExtensionConfiguration config = new ANSICPPParserExtensionConfiguration(); - parser = new GNUCPPSourceParser( scanner, ParserMode.COMPLETE_PARSE, PROBLEM_REQUESTOR, ParserUtil.getParserLogService(), config ); + parser = new GNUCPPSourceParser( scanner, ParserMode.COMPLETE_PARSE, ParserUtil.getParserLogService(), config ); } else if( dialect.equals( dialects[2])) { ICParserExtensionConfiguration config = new GCCParserExtensionConfiguration(); - parser = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, PROBLEM_REQUESTOR, ParserUtil.getParserLogService(), config ); + parser = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, ParserUtil.getParserLogService(), config ); } else if( dialect.equals( dialects[3])) { ICPPParserExtensionConfiguration config = new GNUCPPParserExtensionConfiguration(); - parser = new GNUCPPSourceParser( scanner, ParserMode.COMPLETE_PARSE, PROBLEM_REQUESTOR, ParserUtil.getParserLogService(), config ); + parser = new GNUCPPSourceParser( scanner, ParserMode.COMPLETE_PARSE, ParserUtil.getParserLogService(), config ); } } IASTTranslationUnit tu = parser.parse();