mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
IASTProblems are now attached to the AST rather than reported.
This commit is contained in:
parent
c9c2c1498e
commit
d91724f835
26 changed files with 1380 additions and 568 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -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$
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 );
|
||||
|
||||
}
|
|
@ -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;
|
|
@ -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 {
|
||||
|
||||
}
|
|
@ -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 {
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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 {
|
||||
|
||||
}
|
|
@ -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,28 +94,24 @@ 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;
|
||||
|
||||
private static final int DEFAULT_DECLARATOR_LIST_SIZE = 4;
|
||||
|
||||
/**
|
||||
* @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
|
||||
.supportAlignOfUnaryExpression());
|
||||
|
@ -159,29 +159,32 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
|
||||
IASTInitializer initializer = cInitializerClause(newDesignators);
|
||||
|
||||
if( newDesignators.isEmpty() )
|
||||
{
|
||||
if (newDesignators.isEmpty()) {
|
||||
result.addInitializer(initializer);
|
||||
initializer.setParent(result);
|
||||
initializer.setPropertyInParent( IASTInitializerList.NESTED_INITIALIZER );
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
((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 );
|
||||
d
|
||||
.setPropertyInParent(ICASTDesignatedInitializer.DESIGNATOR);
|
||||
desigInitializer.addDesignator(d);
|
||||
}
|
||||
desigInitializer.setOperandInitializer(initializer);
|
||||
initializer.setParent(desigInitializer);
|
||||
initializer.setPropertyInParent( ICASTDesignatedInitializer.OPERAND );
|
||||
initializer
|
||||
.setPropertyInParent(ICASTDesignatedInitializer.OPERAND);
|
||||
result.addInitializer(desigInitializer);
|
||||
desigInitializer.setParent(result);
|
||||
desigInitializer.setPropertyInParent( IASTInitializerList.NESTED_INITIALIZER );
|
||||
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);
|
||||
|
@ -261,7 +266,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
n.setParent(designator);
|
||||
n.setPropertyInParent(ICASTFieldDesignator.FIELD_NAME);
|
||||
if (designatorList == Collections.EMPTY_LIST)
|
||||
designatorList = new ArrayList( DEFAULT_DESIGNATOR_LIST_SIZE );
|
||||
designatorList = new ArrayList(
|
||||
DEFAULT_DESIGNATOR_LIST_SIZE);
|
||||
designatorList.add(designator);
|
||||
} else if (LT(1) == IToken.tLBRACKET) {
|
||||
IToken mark = consume(IToken.tLBRACKET);
|
||||
|
@ -273,9 +279,11 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
((ASTNode) designator).setOffset(offset);
|
||||
designator.setSubscriptExpression(constantExpression);
|
||||
constantExpression.setParent(designator);
|
||||
constantExpression.setPropertyInParent( ICASTArrayDesignator.SUBSCRIPT_EXPRESSION );
|
||||
constantExpression
|
||||
.setPropertyInParent(ICASTArrayDesignator.SUBSCRIPT_EXPRESSION);
|
||||
if (designatorList == Collections.EMPTY_LIST)
|
||||
designatorList = new ArrayList( DEFAULT_DESIGNATOR_LIST_SIZE );
|
||||
designatorList = new ArrayList(
|
||||
DEFAULT_DESIGNATOR_LIST_SIZE);
|
||||
designatorList.add(designator);
|
||||
continue;
|
||||
}
|
||||
|
@ -290,16 +298,19 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
((ASTNode) designator).setOffset(startOffset);
|
||||
designator.setRangeFloor(constantExpression1);
|
||||
constantExpression1.setParent(designator);
|
||||
constantExpression1.setPropertyInParent( IGCCASTArrayRangeDesignator.SUBSCRIPT_FLOOR_EXPRESSION );
|
||||
constantExpression1
|
||||
.setPropertyInParent(IGCCASTArrayRangeDesignator.SUBSCRIPT_FLOOR_EXPRESSION);
|
||||
designator.setRangeCeiling(constantExpression2);
|
||||
constantExpression2.setParent(designator);
|
||||
constantExpression2.setPropertyInParent( IGCCASTArrayRangeDesignator.SUBSCRIPT_CEILING_EXPRESSION );
|
||||
constantExpression2
|
||||
.setPropertyInParent(IGCCASTArrayRangeDesignator.SUBSCRIPT_CEILING_EXPRESSION);
|
||||
if (designatorList == Collections.EMPTY_LIST)
|
||||
designatorList = new ArrayList( DEFAULT_DESIGNATOR_LIST_SIZE );
|
||||
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();
|
||||
|
@ -309,7 +320,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
n.setParent(designator);
|
||||
n.setPropertyInParent(ICASTFieldDesignator.FIELD_NAME);
|
||||
if (designatorList == Collections.EMPTY_LIST)
|
||||
designatorList = new ArrayList( DEFAULT_DESIGNATOR_LIST_SIZE );
|
||||
designatorList = new ArrayList(
|
||||
DEFAULT_DESIGNATOR_LIST_SIZE);
|
||||
designatorList.add(designator);
|
||||
}
|
||||
}
|
||||
|
@ -327,7 +339,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
n.setParent(designator);
|
||||
n.setPropertyInParent(ICASTFieldDesignator.FIELD_NAME);
|
||||
if (designatorList == Collections.EMPTY_LIST)
|
||||
designatorList = new ArrayList( DEFAULT_DESIGNATOR_LIST_SIZE );
|
||||
designatorList = new ArrayList(
|
||||
DEFAULT_DESIGNATOR_LIST_SIZE);
|
||||
designatorList.add(designator);
|
||||
} else if (LT(1) == IToken.tLBRACKET) {
|
||||
int startOffset = consume(IToken.tLBRACKET).getOffset();
|
||||
|
@ -339,12 +352,15 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
((ASTNode) designator).setOffset(startOffset);
|
||||
designator.setRangeFloor(constantExpression1);
|
||||
constantExpression1.setParent(designator);
|
||||
constantExpression1.setPropertyInParent( IGCCASTArrayRangeDesignator.SUBSCRIPT_FLOOR_EXPRESSION );
|
||||
constantExpression1
|
||||
.setPropertyInParent(IGCCASTArrayRangeDesignator.SUBSCRIPT_FLOOR_EXPRESSION);
|
||||
designator.setRangeCeiling(constantExpression2);
|
||||
constantExpression2.setParent(designator);
|
||||
constantExpression2.setPropertyInParent( IGCCASTArrayRangeDesignator.SUBSCRIPT_CEILING_EXPRESSION );
|
||||
constantExpression2
|
||||
.setPropertyInParent(IGCCASTArrayRangeDesignator.SUBSCRIPT_CEILING_EXPRESSION);
|
||||
if (designatorList == Collections.EMPTY_LIST)
|
||||
designatorList = new ArrayList( DEFAULT_DESIGNATOR_LIST_SIZE );
|
||||
designatorList = new ArrayList(
|
||||
DEFAULT_DESIGNATOR_LIST_SIZE);
|
||||
designatorList.add(designator);
|
||||
}
|
||||
}
|
||||
|
@ -386,8 +402,6 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @throws BacktrackException
|
||||
* @throws EndOfFileException
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -644,7 +692,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
operator = IASTBinaryExpression.op_greaterEqual;
|
||||
break;
|
||||
}
|
||||
firstExpression = buildBinaryExpression( operator, firstExpression, secondExpression );
|
||||
firstExpression = buildBinaryExpression(operator,
|
||||
firstExpression, secondExpression);
|
||||
break;
|
||||
default:
|
||||
return firstExpression;
|
||||
|
@ -678,7 +727,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
operator = IASTBinaryExpression.op_modulo;
|
||||
break;
|
||||
}
|
||||
firstExpression = buildBinaryExpression( operator, firstExpression, secondExpression );
|
||||
firstExpression = buildBinaryExpression(operator,
|
||||
firstExpression, secondExpression);
|
||||
break;
|
||||
default:
|
||||
return firstExpression;
|
||||
|
@ -709,7 +759,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
throwBacktrack(bte);
|
||||
}
|
||||
|
||||
return buildTypeIdUnaryExpression( IASTCastExpression.op_cast, typeId, castExpression, startingOffset );
|
||||
return buildTypeIdUnaryExpression(IASTCastExpression.op_cast,
|
||||
typeId, castExpression, startingOffset);
|
||||
} catch (BacktrackException b) {
|
||||
}
|
||||
}
|
||||
|
@ -760,8 +811,10 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
}
|
||||
mark = null;
|
||||
if (typeId == null && unaryExpression != null)
|
||||
return buildUnaryExpression( IASTUnaryExpression.op_sizeof, unaryExpression, startingOffset );
|
||||
return buildTypeIdExpression( IASTTypeIdExpression.op_sizeof, typeId, startingOffset );
|
||||
return buildUnaryExpression(IASTUnaryExpression.op_sizeof,
|
||||
unaryExpression, startingOffset);
|
||||
return buildTypeIdExpression(IASTTypeIdExpression.op_sizeof,
|
||||
typeId, startingOffset);
|
||||
|
||||
default:
|
||||
if (LT(1) == IGCCToken.t_typeof && supportTypeOfUnaries) {
|
||||
|
@ -784,7 +837,8 @@ 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);
|
||||
|
@ -814,17 +868,14 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
// ( type-name ) { initializer-list }
|
||||
// ( type-name ) { initializer-list , }
|
||||
IToken m = mark();
|
||||
try
|
||||
{
|
||||
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 )
|
||||
{
|
||||
} catch (BacktrackException bt) {
|
||||
backup(m);
|
||||
}
|
||||
|
||||
|
@ -841,13 +892,16 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
secondExpression = expression();
|
||||
consume(IToken.tRBRACKET);
|
||||
IASTArraySubscriptExpression s = createArraySubscriptExpression();
|
||||
((ASTNode)s).setOffset( ((ASTNode)firstExpression).getOffset() );
|
||||
((ASTNode) s)
|
||||
.setOffset(((ASTNode) firstExpression).getOffset());
|
||||
s.setArrayExpression(firstExpression);
|
||||
firstExpression.setParent(s);
|
||||
firstExpression.setPropertyInParent( IASTArraySubscriptExpression.ARRAY );
|
||||
firstExpression
|
||||
.setPropertyInParent(IASTArraySubscriptExpression.ARRAY);
|
||||
s.setSubscriptExpression(secondExpression);
|
||||
secondExpression.setParent(s);
|
||||
secondExpression.setPropertyInParent( IASTArraySubscriptExpression.SUBSCRIPT );
|
||||
secondExpression
|
||||
.setPropertyInParent(IASTArraySubscriptExpression.SUBSCRIPT);
|
||||
firstExpression = s;
|
||||
break;
|
||||
case IToken.tLPAREN:
|
||||
|
@ -857,37 +911,45 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
secondExpression = expression();
|
||||
consume(IToken.tRPAREN);
|
||||
IASTFunctionCallExpression f = createFunctionCallExpression();
|
||||
((ASTNode)f).setOffset( ((ASTNode)firstExpression).getOffset() );
|
||||
((ASTNode) f)
|
||||
.setOffset(((ASTNode) firstExpression).getOffset());
|
||||
f.setFunctionNameExpression(firstExpression);
|
||||
firstExpression.setParent(f);
|
||||
firstExpression.setPropertyInParent( IASTFunctionCallExpression.FUNCTION_NAME );
|
||||
firstExpression
|
||||
.setPropertyInParent(IASTFunctionCallExpression.FUNCTION_NAME);
|
||||
|
||||
if( secondExpression != null )
|
||||
{
|
||||
if (secondExpression != null) {
|
||||
f.setParameterExpression(secondExpression);
|
||||
secondExpression.setParent(f);
|
||||
secondExpression.setPropertyInParent( IASTFunctionCallExpression.PARAMETERS );
|
||||
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());
|
||||
IASTFieldReference result = createFieldReference();
|
||||
((ASTNode)result).setOffset( ((ASTNode)firstExpression).getOffset() );
|
||||
((ASTNode) result).setOffset(((ASTNode) firstExpression)
|
||||
.getOffset());
|
||||
result.setFieldOwner(firstExpression);
|
||||
result.setIsPointerDereference(false);
|
||||
firstExpression.setParent(result);
|
||||
firstExpression.setPropertyInParent( IASTFieldReference.FIELD_OWNER );
|
||||
firstExpression
|
||||
.setPropertyInParent(IASTFieldReference.FIELD_OWNER);
|
||||
result.setFieldName(name);
|
||||
name.setParent(result);
|
||||
name.setPropertyInParent(IASTFieldReference.FIELD_NAME);
|
||||
|
@ -898,11 +960,13 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
consume(IToken.tARROW);
|
||||
name = createName(identifier());
|
||||
result = createFieldReference();
|
||||
((ASTNode)result).setOffset( ((ASTNode)firstExpression).getOffset() );
|
||||
((ASTNode) result).setOffset(((ASTNode) firstExpression)
|
||||
.getOffset());
|
||||
result.setFieldOwner(firstExpression);
|
||||
result.setIsPointerDereference(true);
|
||||
firstExpression.setParent(result);
|
||||
firstExpression.setPropertyInParent( IASTFieldReference.FIELD_OWNER );
|
||||
firstExpression
|
||||
.setPropertyInParent(IASTFieldReference.FIELD_OWNER);
|
||||
result.setFieldName(name);
|
||||
name.setParent(result);
|
||||
name.setPropertyInParent(IASTFieldReference.FIELD_NAME);
|
||||
|
@ -934,7 +998,8 @@ 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);
|
||||
|
@ -973,7 +1038,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
case IToken.tINTEGER:
|
||||
t = consume();
|
||||
literalExpression = createLiteralExpression();
|
||||
literalExpression.setKind( IASTLiteralExpression.lk_integer_constant);
|
||||
literalExpression
|
||||
.setKind(IASTLiteralExpression.lk_integer_constant);
|
||||
literalExpression.setValue(t.getImage());
|
||||
((ASTNode) literalExpression).setOffset(t.getOffset());
|
||||
return literalExpression;
|
||||
|
@ -1046,13 +1112,10 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
IASTDeclSpecifier declSpecifier = null;
|
||||
IASTDeclarator declarator = null;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
declSpecifier = declSpecifierSeq(false);
|
||||
declarator = declarator();
|
||||
}
|
||||
catch( BacktrackException bt )
|
||||
{
|
||||
} catch (BacktrackException bt) {
|
||||
int endingOffset = lastToken == null ? 0 : lastToken.getEndOffset();
|
||||
backup(mark);
|
||||
throwBacktrack(startingOffset, endingOffset - startingOffset);
|
||||
|
@ -1103,8 +1166,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
|
||||
boolean isConst = false, isVolatile = false, isRestrict = false;
|
||||
|
||||
if( LT(1) != IToken.tSTAR )
|
||||
{
|
||||
if (LT(1) != IToken.tSTAR) {
|
||||
backup(mark);
|
||||
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,10 +1346,10 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
if (lookAheadForDeclarator(flags)) {
|
||||
break declSpecifiers;
|
||||
}
|
||||
switch( LT(2) )
|
||||
{
|
||||
switch (LT(2)) {
|
||||
case IToken.tLPAREN:
|
||||
if (isTypedef) break;
|
||||
if (isTypedef)
|
||||
break;
|
||||
case IToken.tSEMI:
|
||||
case IToken.tASSIGN:
|
||||
//TODO more
|
||||
|
@ -1333,8 +1393,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
}
|
||||
}
|
||||
|
||||
if( structSpec != null )
|
||||
{
|
||||
if (structSpec != null) {
|
||||
((ASTNode) structSpec).setOffset(startingOffset);
|
||||
structSpec.setConst(isConst);
|
||||
((ICASTCompositeTypeSpecifier) structSpec).setRestrict(isRestrict);
|
||||
|
@ -1345,8 +1404,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
return structSpec;
|
||||
}
|
||||
|
||||
if( enumSpec != null )
|
||||
{
|
||||
if (enumSpec != null) {
|
||||
((ASTNode) enumSpec).setOffset(startingOffset);
|
||||
enumSpec.setConst(isConst);
|
||||
((CASTEnumerationSpecifier) enumSpec).setRestrict(isRestrict);
|
||||
|
@ -1356,8 +1414,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
return enumSpec;
|
||||
|
||||
}
|
||||
if( elabSpec != null )
|
||||
{
|
||||
if (elabSpec != null) {
|
||||
((ASTNode) elabSpec).setOffset(startingOffset);
|
||||
elabSpec.setConst(isConst);
|
||||
((CASTElaboratedTypeSpecifier) elabSpec).setRestrict(isRestrict);
|
||||
|
@ -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
|
||||
|
@ -1475,8 +1533,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
((ASTNode) result).setOffset(classKey.getOffset());
|
||||
|
||||
result.setName(name);
|
||||
if( name != null )
|
||||
{
|
||||
if (name != null) {
|
||||
name.setParent(result);
|
||||
name.setPropertyInParent(IASTCompositeTypeSpecifier.TYPE_NAME);
|
||||
}
|
||||
|
@ -1491,7 +1548,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
try {
|
||||
IASTDeclaration d = declaration();
|
||||
d.setParent(result);
|
||||
d.setPropertyInParent( IASTCompositeTypeSpecifier.MEMBER_DECLARATION );
|
||||
d
|
||||
.setPropertyInParent(IASTCompositeTypeSpecifier.MEMBER_DECLARATION);
|
||||
result.addMemberDeclaration(d);
|
||||
} catch (BacktrackException bt) {
|
||||
if (checkToken == LA(1).hashCode())
|
||||
|
@ -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(
|
||||
|
@ -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 );
|
||||
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);
|
||||
}
|
||||
}
|
||||
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,7 +1765,6 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
return d;
|
||||
}
|
||||
|
||||
|
||||
protected IASTArrayDeclarator createArrayDeclarator() {
|
||||
return new CASTArrayDeclarator();
|
||||
}
|
||||
|
@ -1730,9 +1783,6 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
return new CASTFunctionDeclarator();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param t
|
||||
* @return
|
||||
|
@ -1803,8 +1853,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
IASTArrayModifier arrayMod = null;
|
||||
if (!(isStatic || isRestrict || isConst || isVolatile))
|
||||
arrayMod = createArrayModifier();
|
||||
else
|
||||
{
|
||||
else {
|
||||
ICASTArrayModifier temp = createCArrayModifier();
|
||||
temp.setStatic(isStatic);
|
||||
temp.setConst(isConst);
|
||||
|
@ -1814,8 +1863,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
arrayMod = temp;
|
||||
}
|
||||
((ASTNode) arrayMod).setOffset(startOffset);
|
||||
if( exp != null )
|
||||
{
|
||||
if (exp != null) {
|
||||
arrayMod.setConstantExpression(exp);
|
||||
exp.setParent(arrayMod);
|
||||
exp.setPropertyInParent(IASTArrayModifier.CONSTANT_EXPRESSION);
|
||||
|
@ -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,7 +2141,8 @@ 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:
|
||||
|
@ -2124,12 +2187,44 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
|
||||
}
|
||||
|
||||
/* (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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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 {
|
||||
|
||||
}
|
|
@ -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 {
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
try {
|
||||
boolean isEllipsis = false;
|
||||
IASTDeclaration decl = null;
|
||||
try {
|
||||
if (LT(1) == IToken.tELLIPSIS)
|
||||
{
|
||||
consume(IToken.tELLIPSIS);
|
||||
|
@ -3945,6 +3986,16 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
true);
|
||||
}
|
||||
consume(IToken.tRPAREN);
|
||||
}
|
||||
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();
|
||||
|
@ -3963,10 +4014,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
compoundStatement.setPropertyInParent( ICPPASTCatchHandler.CATCH_BODY );
|
||||
}
|
||||
collection.add( handler );
|
||||
} catch (BacktrackException bte) {
|
||||
failParse(bte);
|
||||
failParseWithErrorHandling();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue