From 03de1e32fdf963c55ca2d1d7ed3c977a642855c7 Mon Sep 17 00:00:00 2001 From: John Camelon Date: Wed, 24 Nov 2004 04:28:19 +0000 Subject: [PATCH] Separated C++ and C Physical Implementations to provide Andrew more flexibility. Added ICPPASTTemplateId and implementation. --- .../tests/parser2/QuickParser2Tests.java | 2 +- .../core/dom/ast/cpp/ICPPASTTemplateId.java | 34 ++ .../parser2/AbstractGNUSourceCodeParser.java | 484 ++++-------------- .../parser2/{cpp => }/IProblemRequestor.java | 2 +- .../cdt/internal/core/parser2/c/CASTNode.java | 1 - .../core/parser2/c/GNUCSourceParser.java | 389 +++++++++++++- .../parser2/cpp/CPPASTASMDeclaration.java | 36 ++ .../parser2/cpp/CPPASTBinaryExpression.java | 68 +++ .../parser2/cpp/CPPASTBreakStatement.java | 21 + .../core/parser2/cpp/CPPASTCaseStatement.java | 37 ++ .../parser2/cpp/CPPASTCastExpression.java | 37 ++ .../parser2/cpp/CPPASTCompoundStatement.java | 74 +++ .../CPPASTCompoundStatementExpression.java | 37 ++ .../cpp/CPPASTConditionalExpression.java | 67 +++ .../parser2/cpp/CPPASTContinueStatement.java | 21 + .../cpp/CPPASTDeclarationStatement.java | 38 ++ .../parser2/cpp/CPPASTDefaultStatement.java | 21 + .../core/parser2/cpp/CPPASTDoStatement.java | 52 ++ .../core/parser2/cpp/CPPASTEnumerator.java | 52 ++ .../parser2/cpp/CPPASTExpressionList.java | 75 +++ .../cpp/CPPASTExpressionStatement.java | 37 ++ .../parser2/cpp/CPPASTFieldDeclarator.java | 39 ++ .../core/parser2/cpp/CPPASTForStatement.java | 100 ++++ .../cpp/CPPASTFunctionCallExpression.java | 52 ++ .../parser2/cpp/CPPASTFunctionDefinition.java | 71 +++ .../core/parser2/cpp/CPPASTGotoStatement.java | 37 ++ .../core/parser2/cpp/CPPASTIdExpression.java | 36 ++ .../core/parser2/cpp/CPPASTIfStatement.java | 67 +++ .../cpp/CPPASTInitializerExpresion.java | 38 ++ .../parser2/cpp/CPPASTInitializerList.java | 76 +++ .../parser2/cpp/CPPASTLabelStatement.java | 37 ++ .../parser2/cpp/CPPASTLiteralExpression.java | 36 +- .../internal/core/parser2/cpp/CPPASTName.java | 103 ++-- .../parser2/cpp/CPPASTNamespaceAlias.java | 3 +- .../core/parser2/cpp/CPPASTNullStatement.java | 21 + .../core/parser2/cpp/CPPASTQualifiedName.java | 112 ++++ .../parser2/cpp/CPPASTReturnStatement.java | 37 ++ .../parser2/cpp/CPPASTSimpleDeclaration.java | 88 ++++ .../parser2/cpp/CPPASTSwitchStatement.java | 54 ++ .../core/parser2/cpp/CPPASTTemplateId.java | 119 +++++ .../parser2/cpp/CPPASTTranslationUnit.java | 99 ++++ .../parser2/cpp/CPPASTTypeIdExpression.java | 53 ++ .../parser2/cpp/CPPASTUnaryExpression.java | 53 ++ .../parser2/cpp/CPPASTWhileStatement.java | 53 ++ .../core/parser2/cpp/GNUCPPSourceParser.java | 473 +++++++++++++++-- 45 files changed, 2928 insertions(+), 514 deletions(-) create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTTemplateId.java rename core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/{cpp => }/IProblemRequestor.java (92%) create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTASMDeclaration.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTBinaryExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTBreakStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTCaseStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTCastExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTCompoundStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTCompoundStatementExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTConditionalExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTContinueStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTDeclarationStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTDefaultStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTDoStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTEnumerator.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTExpressionList.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTExpressionStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTFieldDeclarator.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTForStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTFunctionCallExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTFunctionDefinition.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTGotoStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTIdExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTIfStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTInitializerExpresion.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTInitializerList.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTLabelStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTNullStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTQualifiedName.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTReturnStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTSimpleDeclaration.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTSwitchStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTTemplateId.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTTranslationUnit.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTTypeIdExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTUnaryExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTWhileStatement.java 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 59c013215e5..6f3b57083fa 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 @@ -29,6 +29,7 @@ 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.internal.core.parser.ParserException; +import org.eclipse.cdt.internal.core.parser2.IProblemRequestor; import org.eclipse.cdt.internal.core.parser2.ISourceCodeParser; import org.eclipse.cdt.internal.core.parser2.c.ANSICParserExtensionConfiguration; import org.eclipse.cdt.internal.core.parser2.c.GCCParserExtensionConfiguration; @@ -38,7 +39,6 @@ import org.eclipse.cdt.internal.core.parser2.cpp.ANSICPPParserExtensionConfigura import org.eclipse.cdt.internal.core.parser2.cpp.GNUCPPParserExtensionConfiguration; import org.eclipse.cdt.internal.core.parser2.cpp.GNUCPPSourceParser; import org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser2.cpp.IProblemRequestor; /** * @author jcamelon diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTTemplateId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTTemplateId.java new file mode 100644 index 00000000000..e1bef5d4271 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTTemplateId.java @@ -0,0 +1,34 @@ +/********************************************************************** + * 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.cpp; + +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTTypeId; + +/** + * @author jcamelon + */ +public interface ICPPASTTemplateId extends IASTName { + + public static final ASTNodeProperty TEMPLATE_NAME = new ASTNodeProperty( "TemplateId Name"); //$NON-NLS-1$ + public IASTName getTemplateName(); + public void setTemplateName( IASTName name ); + + public static final ASTNodeProperty TEMPLATE_ID_ARGUMENT = new ASTNodeProperty( "TemplateId Arg"); //$NON-NLS-1$ + public void addTemplateArgument( IASTTypeId typeId ); + public void addTemplateArgument( IASTExpression expression ); + public List getTemplateArguments(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/AbstractGNUSourceCodeParser.java index 7234892bc12..385e2f01549 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/AbstractGNUSourceCodeParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/AbstractGNUSourceCodeParser.java @@ -59,25 +59,6 @@ import org.eclipse.cdt.core.parser.ParseError; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.internal.core.parser.ParserProblemFactory; import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory; -import org.eclipse.cdt.internal.core.parser2.c.CASTASMDeclaration; -import org.eclipse.cdt.internal.core.parser2.c.CASTBreakStatement; -import org.eclipse.cdt.internal.core.parser2.c.CASTCaseStatement; -import org.eclipse.cdt.internal.core.parser2.c.CASTCastExpression; -import org.eclipse.cdt.internal.core.parser2.c.CASTContinueStatement; -import org.eclipse.cdt.internal.core.parser2.c.CASTDeclarationStatement; -import org.eclipse.cdt.internal.core.parser2.c.CASTDefaultStatement; -import org.eclipse.cdt.internal.core.parser2.c.CASTDoStatement; -import org.eclipse.cdt.internal.core.parser2.c.CASTEnumerationSpecifier; -import org.eclipse.cdt.internal.core.parser2.c.CASTExpressionStatement; -import org.eclipse.cdt.internal.core.parser2.c.CASTForStatement; -import org.eclipse.cdt.internal.core.parser2.c.CASTGotoStatement; -import org.eclipse.cdt.internal.core.parser2.c.CASTIfStatement; -import org.eclipse.cdt.internal.core.parser2.c.CASTLabelStatement; -import org.eclipse.cdt.internal.core.parser2.c.CASTNullStatement; -import org.eclipse.cdt.internal.core.parser2.c.CASTReturnStatement; -import org.eclipse.cdt.internal.core.parser2.c.CASTSwitchStatement; -import org.eclipse.cdt.internal.core.parser2.c.CASTWhileStatement; -import org.eclipse.cdt.internal.core.parser2.cpp.IProblemRequestor; /** * @author jcamelon @@ -757,6 +738,11 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { return result; } + /** + * @return + */ + protected abstract IASTBinaryExpression createBinaryExpression(); + /** * @param expression * @throws BacktrackException @@ -805,11 +791,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } } - /** - * @return - */ - protected abstract IASTBinaryExpression createBinaryExpression(); - /** * @param expression * @return @throws @@ -1157,20 +1138,30 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { return null; } + protected abstract IASTStatement statement() throws EndOfFileException, + BacktrackException; + /** * @return */ - protected abstract IASTEnumerator createEnumerator(); + protected abstract IASTEnumerator createEnumerator(); + + /** + * @return + */ + protected abstract IASTEnumerationSpecifier createEnumerationSpecifier(); + + /** + * @return + */ + protected abstract IASTName createName(); /** * @param token * @return */ - protected abstract IASTName createName(IToken token); - /** - * @return - */ - protected abstract IASTName createName(); + protected abstract IASTName createName(IToken token); + /** * @throws BacktrackException @@ -1191,368 +1182,83 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser2.GNUBaseParser#statement(java.lang.Object) + /** + * @return */ - protected IASTStatement statement() throws EndOfFileException, - BacktrackException { + protected abstract IASTDeclarationStatement createDeclarationStatement(); - switch (LT(1)) { - // labeled statements - case IToken.t_case: - int startOffset = consume(IToken.t_case).getOffset(); - IASTExpression case_exp = constantExpression(); - consume(IToken.tCOLON); - cleanupLastToken(); - IASTCaseStatement cs = createCaseStatement(); - ((ASTNode)cs).setOffset( startOffset ); - cs.setExpression( case_exp ); - case_exp.setParent( cs ); - case_exp.setPropertyInParent( IASTCaseStatement.EXPRESSION ); - return cs; - case IToken.t_default: - startOffset = consume(IToken.t_default).getOffset(); - consume(IToken.tCOLON); - cleanupLastToken(); - IASTDefaultStatement df = createDefaultStatement(); - ((ASTNode)df).setOffset( startOffset ); - return df; - // compound statement - case IToken.tLBRACE: - IASTCompoundStatement compound = compoundStatement(); - cleanupLastToken(); - return compound; - // selection statement - case IToken.t_if: - startOffset = consume(IToken.t_if).getOffset(); - consume(IToken.tLPAREN); - IASTExpression if_condition = condition(); - consume(IToken.tRPAREN); - IASTStatement then_clause = statement(); - IASTStatement else_clause = null; - if (LT(1) == IToken.t_else) { - consume(IToken.t_else); - else_clause = statement(); - } - - IASTIfStatement if_stmt = createIfStatement(); - if_stmt.setCondition( if_condition ); - ((ASTNode)if_stmt).setOffset( startOffset ); - if_condition.setParent( if_stmt ); - if_condition.setPropertyInParent( IASTIfStatement.CONDITION ); - if_stmt.setThenClause( then_clause ); - then_clause.setParent( if_stmt ); - then_clause.setPropertyInParent( IASTIfStatement.THEN ); - if( else_clause != null ) - { - if_stmt.setElseClause( else_clause ); - else_clause.setParent( if_stmt ); - else_clause.setPropertyInParent( IASTIfStatement.ELSE ); - } - cleanupLastToken(); - return if_stmt; - case IToken.t_switch: - startOffset = consume( IToken.t_switch ).getOffset(); - consume(IToken.tLPAREN); - IASTExpression switch_condition = condition(); - consume(IToken.tRPAREN); - IASTStatement switch_body = statement(); - cleanupLastToken(); - IASTSwitchStatement switch_statement = createSwitchStatement(); - ((ASTNode)switch_statement).setOffset( startOffset ); - switch_statement.setController( switch_condition ); - switch_condition.setParent( switch_statement ); - switch_condition.setPropertyInParent( IASTSwitchStatement.CONTROLLER ); - switch_statement.setBody( switch_body ); - switch_body.setParent( switch_statement ); - switch_body.setPropertyInParent( IASTSwitchStatement.BODY ); - return switch_statement; - //iteration statements - case IToken.t_while: - startOffset = consume(IToken.t_while).getOffset(); - consume(IToken.tLPAREN); - IASTExpression while_condition = condition(); - consume(IToken.tRPAREN); - IASTStatement while_body = statement(); - cleanupLastToken(); - IASTWhileStatement while_statement = createWhileStatement(); - ((ASTNode)while_statement).setOffset( startOffset ); - while_statement.setCondition( while_condition ); - while_condition.setParent( while_statement ); - while_condition.setPropertyInParent( IASTWhileStatement.CONDITION ); - while_statement.setBody( while_body ); - while_condition.setParent( while_statement ); - while_condition.setPropertyInParent( IASTWhileStatement.BODY ); - while_body.setParent( while_statement ); - return while_statement; - case IToken.t_do: - startOffset = consume(IToken.t_do).getOffset(); - IASTStatement do_body = statement(); - consume(IToken.t_while); - consume(IToken.tLPAREN); - IASTExpression do_condition = condition(); - consume(IToken.tRPAREN); - cleanupLastToken(); - IASTDoStatement do_statement = createDoStatement(); - ((ASTNode)do_statement).setOffset( startOffset ); - do_statement.setBody( do_body ); - do_body.setParent( do_statement ); - do_body.setPropertyInParent( IASTDoStatement.BODY ); - do_statement.setCondition( do_condition ); - do_condition.setParent( do_statement ); - do_condition.setPropertyInParent( IASTDoStatement.CONDITION ); - return do_statement; - case IToken.t_for: - startOffset = consume( IToken.t_for ).getOffset(); - consume(IToken.tLPAREN); - IASTNode init = forInitStatement(); - IASTExpression for_condition = null; - if (LT(1) != IToken.tSEMI) - for_condition = condition(); - consume(IToken.tSEMI); - IASTExpression iterationExpression = null; - if (LT(1) != IToken.tRPAREN) { - iterationExpression = expression(); - cleanupLastToken(); - } - consume(IToken.tRPAREN); - IASTStatement for_body = statement(); - cleanupLastToken(); - IASTForStatement for_statement = createForStatement(); - ((ASTNode)for_statement).setOffset( startOffset ); - if( init instanceof IASTDeclaration ) - { - for_statement.setInit((IASTDeclaration) init); - ((IASTDeclaration) init).setParent( for_statement ); - ((IASTDeclaration) init).setPropertyInParent( IASTForStatement.INITDECLARATION ); - } - else if( init instanceof IASTExpression ) - { - for_statement.setInit((IASTExpression) init); - ((IASTExpression) init).setParent( for_statement ); - ((IASTExpression) init).setPropertyInParent( IASTForStatement.INITEXPRESSION ); - } - if( for_condition != null ) - { - for_statement.setCondition( for_condition ); - for_condition.setParent( for_statement ); - for_condition.setPropertyInParent( IASTForStatement.CONDITION ); - } - if( iterationExpression != null ) - { - for_statement.setIterationExpression( iterationExpression ); - iterationExpression.setParent( for_statement ); - iterationExpression.setPropertyInParent( IASTForStatement.ITERATION ); - } - for_statement.setBody( for_body ); - for_body.setParent( for_statement ); - for_body.setPropertyInParent( IASTForStatement.BODY ); - return for_statement; - //jump statement - case IToken.t_break: - startOffset = consume(IToken.t_break).getOffset(); - consume(IToken.tSEMI); - cleanupLastToken(); - IASTBreakStatement break_statement = createBreakStatement(); - ((ASTNode)break_statement).setOffset( startOffset ); - return break_statement; - case IToken.t_continue: - startOffset = consume(IToken.t_continue).getOffset(); - consume(IToken.tSEMI); - cleanupLastToken(); - IASTContinueStatement continue_statement = createContinueStatement(); - ((ASTNode)continue_statement).setOffset( startOffset ); - return continue_statement; - case IToken.t_return: - startOffset = consume(IToken.t_return).getOffset(); - IASTExpression result = null; - if (LT(1) != IToken.tSEMI) { - result = expression(); - cleanupLastToken(); - } - consume(IToken.tSEMI); - cleanupLastToken(); - IASTReturnStatement return_statement = createReturnStatement(); - ((ASTNode)return_statement).setOffset( startOffset ); - if( result != null ) - { - return_statement.setReturnValue( result ); - result.setParent( return_statement ); - result.setPropertyInParent( IASTReturnStatement.RETURNVALUE ); - } - return return_statement; - case IToken.t_goto: - startOffset = consume(IToken.t_goto).getOffset(); - IToken identifier = consume(IToken.tIDENTIFIER); - consume(IToken.tSEMI); - cleanupLastToken(); - IASTName goto_label_name = createName( identifier ); - IASTGotoStatement goto_statement = createGoToStatement(); - ((ASTNode)goto_statement).setOffset( startOffset ); - goto_statement.setName( goto_label_name ); - goto_label_name.setParent( goto_statement ); - goto_label_name.setPropertyInParent( IASTGotoStatement.NAME ); - return goto_statement; - case IToken.tSEMI: - startOffset = consume(IToken.tSEMI ).getOffset(); - cleanupLastToken(); - IASTNullStatement null_statement = createNullStatement(); - ((ASTNode)null_statement).setOffset( startOffset ); - return null_statement; - default: - // can be many things: - // label - if (LT(1) == IToken.tIDENTIFIER && LT(2) == IToken.tCOLON) { - IToken labelName = consume(IToken.tIDENTIFIER); - consume(IToken.tCOLON); - IASTLabelStatement label_statement = createLabelStatement(); - ((ASTNode)label_statement).setOffset( labelName.getOffset() ); - IASTName name = createName( labelName ); - label_statement.setName( name ); - name.setParent( label_statement ); - name.setPropertyInParent( IASTLabelStatement.NAME ); - return label_statement; - } - // expressionStatement - // Note: the function style cast ambiguity is handled in - // expression - // Since it only happens when we are in a statement - IToken mark = mark(); - try { - IASTExpression expression = expression(); - consume(IToken.tSEMI); - IASTExpressionStatement expressionStatement = createExpressionStatement(); - expressionStatement.setExpression( expression ); - expression.setParent( expressionStatement ); - expression.setPropertyInParent( IASTExpressionStatement.EXPFRESSION ); - cleanupLastToken(); - return expressionStatement; - } catch (BacktrackException b) { - backup(mark); - } + /** + * @return + */ + protected abstract IASTExpressionStatement createExpressionStatement(); - // declarationStatement - IASTDeclaration d = declaration(); - IASTDeclarationStatement ds = createDeclarationStatement(); - ds.setDeclaration(d); - d.setParent( ds ); - d.setPropertyInParent( IASTDeclarationStatement.DECLARATION ); - cleanupLastToken(); - return ds; - } + /** + * @return + */ + protected abstract IASTLabelStatement createLabelStatement(); - } + /** + * @return + */ + protected abstract IASTNullStatement createNullStatement(); + /** + * @return + */ + protected abstract IASTGotoStatement createGoToStatement(); + /** + * @return + */ + protected abstract IASTReturnStatement createReturnStatement(); + + /** + * @return + */ + protected abstract IASTContinueStatement createContinueStatement(); + + /** + * @return + */ + protected abstract IASTBreakStatement createBreakStatement(); + + /** + * @return + */ + protected abstract IASTForStatement createForStatement(); + + /** + * @return + */ + protected abstract IASTDoStatement createDoStatement(); + + /** + * @return + */ + protected abstract IASTWhileStatement createWhileStatement(); + + /** + * @return + */ + protected abstract IASTSwitchStatement createSwitchStatement(); + + /** + * @return + */ + protected abstract IASTIfStatement createIfStatement(); + + /** + * @return + */ + protected abstract IASTDefaultStatement createDefaultStatement(); + + /** + * @return + */ + protected abstract IASTCaseStatement createCaseStatement(); protected abstract IASTDeclaration declaration() throws BacktrackException, EndOfFileException; - /** - * @return - */ - protected IASTLabelStatement createLabelStatement() { - return new CASTLabelStatement(); - } - - /** - * @return - */ - protected IASTGotoStatement createGoToStatement() { - return new CASTGotoStatement(); - } - - /** - * @return - */ - protected IASTReturnStatement createReturnStatement() { - return new CASTReturnStatement(); - } - - /** - * @return - */ - protected IASTForStatement createForStatement() { - return new CASTForStatement(); - } - - /** - * @return - */ - protected IASTContinueStatement createContinueStatement() { - return new CASTContinueStatement(); - } - - /** - * @return - */ - protected IASTDoStatement createDoStatement() { - return new CASTDoStatement(); - } - - /** - * @return - */ - protected IASTBreakStatement createBreakStatement() { - return new CASTBreakStatement(); - } - - /** - * @return - */ - protected IASTWhileStatement createWhileStatement() { - return new CASTWhileStatement(); - } - - /** - * @return - */ - protected IASTNullStatement createNullStatement() { - return new CASTNullStatement(); - } - - /** - * @return - */ - protected IASTSwitchStatement createSwitchStatement() { - return new CASTSwitchStatement(); - } - - /** - * @return - */ - protected IASTIfStatement createIfStatement() { - return new CASTIfStatement(); - } - - /** - * @return - */ - protected IASTDefaultStatement createDefaultStatement() { - return new CASTDefaultStatement(); - } - - /** - * @return - */ - protected IASTCaseStatement createCaseStatement() { - return new CASTCaseStatement(); - } - - /** - * @return - */ - protected IASTExpressionStatement createExpressionStatement() { - return new CASTExpressionStatement(); - } - - /** - * @return - */ - protected IASTDeclarationStatement createDeclarationStatement() { - return new CASTDeclarationStatement(); - } protected abstract IASTNode forInitStatement() throws BacktrackException, EndOfFileException; @@ -1587,13 +1293,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { /** * @return */ - protected IASTASMDeclaration createASMDirective() { - return new CASTASMDeclaration(); - } - - protected IASTEnumerationSpecifier createEnumerationSpecifier() { - return new CASTEnumerationSpecifier(); - } + protected abstract IASTASMDeclaration createASMDirective(); /** * @param op @@ -1618,8 +1318,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { /** * @return */ - protected IASTCastExpression createCastExpression() { - return new CASTCastExpression(); - } + protected abstract IASTCastExpression createCastExpression(); } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/IProblemRequestor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/IProblemRequestor.java similarity index 92% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/IProblemRequestor.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/IProblemRequestor.java index 357fc2a5bb2..f3bd70c7583 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/IProblemRequestor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/IProblemRequestor.java @@ -11,7 +11,7 @@ /* * Created on Oct 22, 2004 */ -package org.eclipse.cdt.internal.core.parser2.cpp; +package org.eclipse.cdt.internal.core.parser2; import org.eclipse.cdt.core.parser.IProblem; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTNode.java index 6a1d47e1865..828e27499ba 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTNode.java @@ -19,7 +19,6 @@ import org.eclipse.cdt.internal.core.parser2.ASTNode; */ public class CASTNode extends ASTNode implements IASTNode { - private IASTNode parent; private ASTNodeProperty property; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/GNUCSourceParser.java index d26ed296d46..ac966c26d70 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/GNUCSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/GNUCSourceParser.java @@ -13,43 +13,59 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; +import org.eclipse.cdt.core.dom.ast.IASTBreakStatement; +import org.eclipse.cdt.core.dom.ast.IASTCaseStatement; import org.eclipse.cdt.core.dom.ast.IASTCastExpression; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression; +import org.eclipse.cdt.core.dom.ast.IASTContinueStatement; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement; +import org.eclipse.cdt.core.dom.ast.IASTDoStatement; import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpressionList; +import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFieldReference; +import org.eclipse.cdt.core.dom.ast.IASTForStatement; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; +import org.eclipse.cdt.core.dom.ast.IASTGotoStatement; import org.eclipse.cdt.core.dom.ast.IASTIdExpression; +import org.eclipse.cdt.core.dom.ast.IASTIfStatement; import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; import org.eclipse.cdt.core.dom.ast.IASTInitializerList; +import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier; 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.IASTReturnStatement; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; +import org.eclipse.cdt.core.dom.ast.IASTWhileStatement; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; import org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator; import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier; @@ -74,7 +90,7 @@ import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.internal.core.parser.token.TokenFactory; import org.eclipse.cdt.internal.core.parser2.ASTNode; import org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser; -import org.eclipse.cdt.internal.core.parser2.cpp.IProblemRequestor; +import org.eclipse.cdt.internal.core.parser2.IProblemRequestor; /** * @author jcamelon @@ -1930,4 +1946,375 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { return new CASTEnumerator(); } + /** + * @return + */ + protected IASTLabelStatement createLabelStatement() { + return new CASTLabelStatement(); + } + + /** + * @return + */ + protected IASTGotoStatement createGoToStatement() { + return new CASTGotoStatement(); + } + + /** + * @return + */ + protected IASTReturnStatement createReturnStatement() { + return new CASTReturnStatement(); + } + + /** + * @return + */ + protected IASTForStatement createForStatement() { + return new CASTForStatement(); + } + + /** + * @return + */ + protected IASTContinueStatement createContinueStatement() { + return new CASTContinueStatement(); + } + + /** + * @return + */ + protected IASTDoStatement createDoStatement() { + return new CASTDoStatement(); + } + + /** + * @return + */ + protected IASTBreakStatement createBreakStatement() { + return new CASTBreakStatement(); + } + + /** + * @return + */ + protected IASTWhileStatement createWhileStatement() { + return new CASTWhileStatement(); + } + + /** + * @return + */ + protected IASTNullStatement createNullStatement() { + return new CASTNullStatement(); + } + + /** + * @return + */ + protected IASTSwitchStatement createSwitchStatement() { + return new CASTSwitchStatement(); + } + + /** + * @return + */ + protected IASTIfStatement createIfStatement() { + return new CASTIfStatement(); + } + + /** + * @return + */ + protected IASTDefaultStatement createDefaultStatement() { + return new CASTDefaultStatement(); + } + + /** + * @return + */ + protected IASTCaseStatement createCaseStatement() { + return new CASTCaseStatement(); + } + + /** + * @return + */ + protected IASTExpressionStatement createExpressionStatement() { + return new CASTExpressionStatement(); + } + + /** + * @return + */ + protected IASTDeclarationStatement createDeclarationStatement() { + return new CASTDeclarationStatement(); + } + + /** + * @return + */ + protected IASTASMDeclaration createASMDirective() { + return new CASTASMDeclaration(); + } + + protected IASTEnumerationSpecifier createEnumerationSpecifier() { + return new CASTEnumerationSpecifier(); + } + + /** + * @return + */ + protected IASTCastExpression createCastExpression() { + return new CASTCastExpression(); + } + + protected IASTStatement statement() throws EndOfFileException, BacktrackException { + + switch (LT(1)) { + // labeled statements + case IToken.t_case: + int startOffset = consume(IToken.t_case).getOffset(); + IASTExpression case_exp = constantExpression(); + consume(IToken.tCOLON); + cleanupLastToken(); + IASTCaseStatement cs = createCaseStatement(); + ((ASTNode)cs).setOffset( startOffset ); + cs.setExpression( case_exp ); + case_exp.setParent( cs ); + case_exp.setPropertyInParent( IASTCaseStatement.EXPRESSION ); + return cs; + case IToken.t_default: + startOffset = consume(IToken.t_default).getOffset(); + consume(IToken.tCOLON); + cleanupLastToken(); + IASTDefaultStatement df = createDefaultStatement(); + ((ASTNode)df).setOffset( startOffset ); + return df; + // compound statement + case IToken.tLBRACE: + IASTCompoundStatement compound = compoundStatement(); + cleanupLastToken(); + return compound; + // selection statement + case IToken.t_if: + startOffset = consume(IToken.t_if).getOffset(); + consume(IToken.tLPAREN); + IASTExpression if_condition = condition(); + consume(IToken.tRPAREN); + IASTStatement then_clause = statement(); + IASTStatement else_clause = null; + if (LT(1) == IToken.t_else) { + consume(IToken.t_else); + else_clause = statement(); + } + + IASTIfStatement if_stmt = createIfStatement(); + if_stmt.setCondition( if_condition ); + ((ASTNode)if_stmt).setOffset( startOffset ); + if_condition.setParent( if_stmt ); + if_condition.setPropertyInParent( IASTIfStatement.CONDITION ); + if_stmt.setThenClause( then_clause ); + then_clause.setParent( if_stmt ); + then_clause.setPropertyInParent( IASTIfStatement.THEN ); + if( else_clause != null ) + { + if_stmt.setElseClause( else_clause ); + else_clause.setParent( if_stmt ); + else_clause.setPropertyInParent( IASTIfStatement.ELSE ); + } + cleanupLastToken(); + return if_stmt; + case IToken.t_switch: + startOffset = consume( IToken.t_switch ).getOffset(); + consume(IToken.tLPAREN); + IASTExpression switch_condition = condition(); + consume(IToken.tRPAREN); + IASTStatement switch_body = statement(); + cleanupLastToken(); + IASTSwitchStatement switch_statement = createSwitchStatement(); + ((ASTNode)switch_statement).setOffset( startOffset ); + switch_statement.setController( switch_condition ); + switch_condition.setParent( switch_statement ); + switch_condition.setPropertyInParent( IASTSwitchStatement.CONTROLLER ); + switch_statement.setBody( switch_body ); + switch_body.setParent( switch_statement ); + switch_body.setPropertyInParent( IASTSwitchStatement.BODY ); + return switch_statement; + //iteration statements + case IToken.t_while: + startOffset = consume(IToken.t_while).getOffset(); + consume(IToken.tLPAREN); + IASTExpression while_condition = condition(); + consume(IToken.tRPAREN); + IASTStatement while_body = statement(); + cleanupLastToken(); + IASTWhileStatement while_statement = createWhileStatement(); + ((ASTNode)while_statement).setOffset( startOffset ); + while_statement.setCondition( while_condition ); + while_condition.setParent( while_statement ); + while_condition.setPropertyInParent( IASTWhileStatement.CONDITION ); + while_statement.setBody( while_body ); + while_condition.setParent( while_statement ); + while_condition.setPropertyInParent( IASTWhileStatement.BODY ); + while_body.setParent( while_statement ); + return while_statement; + case IToken.t_do: + startOffset = consume(IToken.t_do).getOffset(); + IASTStatement do_body = statement(); + consume(IToken.t_while); + consume(IToken.tLPAREN); + IASTExpression do_condition = condition(); + consume(IToken.tRPAREN); + cleanupLastToken(); + IASTDoStatement do_statement = createDoStatement(); + ((ASTNode)do_statement).setOffset( startOffset ); + do_statement.setBody( do_body ); + do_body.setParent( do_statement ); + do_body.setPropertyInParent( IASTDoStatement.BODY ); + do_statement.setCondition( do_condition ); + do_condition.setParent( do_statement ); + do_condition.setPropertyInParent( IASTDoStatement.CONDITION ); + return do_statement; + case IToken.t_for: + startOffset = consume( IToken.t_for ).getOffset(); + consume(IToken.tLPAREN); + IASTNode init = forInitStatement(); + IASTExpression for_condition = null; + if (LT(1) != IToken.tSEMI) + for_condition = condition(); + consume(IToken.tSEMI); + IASTExpression iterationExpression = null; + if (LT(1) != IToken.tRPAREN) { + iterationExpression = expression(); + cleanupLastToken(); + } + consume(IToken.tRPAREN); + IASTStatement for_body = statement(); + cleanupLastToken(); + IASTForStatement for_statement = createForStatement(); + ((ASTNode)for_statement).setOffset( startOffset ); + if( init instanceof IASTDeclaration ) + { + for_statement.setInit((IASTDeclaration) init); + ((IASTDeclaration) init).setParent( for_statement ); + ((IASTDeclaration) init).setPropertyInParent( IASTForStatement.INITDECLARATION ); + } + else if( init instanceof IASTExpression ) + { + for_statement.setInit((IASTExpression) init); + ((IASTExpression) init).setParent( for_statement ); + ((IASTExpression) init).setPropertyInParent( IASTForStatement.INITEXPRESSION ); + } + if( for_condition != null ) + { + for_statement.setCondition( for_condition ); + for_condition.setParent( for_statement ); + for_condition.setPropertyInParent( IASTForStatement.CONDITION ); + } + if( iterationExpression != null ) + { + for_statement.setIterationExpression( iterationExpression ); + iterationExpression.setParent( for_statement ); + iterationExpression.setPropertyInParent( IASTForStatement.ITERATION ); + } + for_statement.setBody( for_body ); + for_body.setParent( for_statement ); + for_body.setPropertyInParent( IASTForStatement.BODY ); + return for_statement; + //jump statement + case IToken.t_break: + startOffset = consume(IToken.t_break).getOffset(); + consume(IToken.tSEMI); + cleanupLastToken(); + IASTBreakStatement break_statement = createBreakStatement(); + ((ASTNode)break_statement).setOffset( startOffset ); + return break_statement; + case IToken.t_continue: + startOffset = consume(IToken.t_continue).getOffset(); + consume(IToken.tSEMI); + cleanupLastToken(); + IASTContinueStatement continue_statement = createContinueStatement(); + ((ASTNode)continue_statement).setOffset( startOffset ); + return continue_statement; + case IToken.t_return: + startOffset = consume(IToken.t_return).getOffset(); + IASTExpression result = null; + if (LT(1) != IToken.tSEMI) { + result = expression(); + cleanupLastToken(); + } + consume(IToken.tSEMI); + cleanupLastToken(); + IASTReturnStatement return_statement = createReturnStatement(); + ((ASTNode)return_statement).setOffset( startOffset ); + if( result != null ) + { + return_statement.setReturnValue( result ); + result.setParent( return_statement ); + result.setPropertyInParent( IASTReturnStatement.RETURNVALUE ); + } + return return_statement; + case IToken.t_goto: + startOffset = consume(IToken.t_goto).getOffset(); + IToken identifier = consume(IToken.tIDENTIFIER); + consume(IToken.tSEMI); + cleanupLastToken(); + IASTName goto_label_name = createName( identifier ); + IASTGotoStatement goto_statement = createGoToStatement(); + ((ASTNode)goto_statement).setOffset( startOffset ); + goto_statement.setName( goto_label_name ); + goto_label_name.setParent( goto_statement ); + goto_label_name.setPropertyInParent( IASTGotoStatement.NAME ); + return goto_statement; + case IToken.tSEMI: + startOffset = consume(IToken.tSEMI ).getOffset(); + cleanupLastToken(); + IASTNullStatement null_statement = createNullStatement(); + ((ASTNode)null_statement).setOffset( startOffset ); + return null_statement; + default: + // can be many things: + // label + if (LT(1) == IToken.tIDENTIFIER && LT(2) == IToken.tCOLON) { + IToken labelName = consume(IToken.tIDENTIFIER); + consume(IToken.tCOLON); + IASTLabelStatement label_statement = createLabelStatement(); + ((ASTNode)label_statement).setOffset( labelName.getOffset() ); + IASTName name = createName( labelName ); + label_statement.setName( name ); + name.setParent( label_statement ); + name.setPropertyInParent( IASTLabelStatement.NAME ); + return label_statement; + } + // expressionStatement + // Note: the function style cast ambiguity is handled in + // expression + // Since it only happens when we are in a statement + IToken mark = mark(); + try { + IASTExpression expression = expression(); + consume(IToken.tSEMI); + IASTExpressionStatement expressionStatement = createExpressionStatement(); + expressionStatement.setExpression( expression ); + expression.setParent( expressionStatement ); + expression.setPropertyInParent( IASTExpressionStatement.EXPFRESSION ); + cleanupLastToken(); + return expressionStatement; + } catch (BacktrackException b) { + backup(mark); + } + + // declarationStatement + IASTDeclaration d = declaration(); + IASTDeclarationStatement ds = createDeclarationStatement(); + ds.setDeclaration(d); + d.setParent( ds ); + d.setPropertyInParent( IASTDeclarationStatement.DECLARATION ); + cleanupLastToken(); + return ds; + } + + } + } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTASMDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTASMDeclaration.java new file mode 100644 index 00000000000..d702d9aaf3f --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTASMDeclaration.java @@ -0,0 +1,36 @@ +/********************************************************************** + * 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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration; + +/** + * @author jcamelon + */ +public class CPPASTASMDeclaration extends CPPASTNode implements + IASTASMDeclaration { + char [] assembly = null; + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTASMDeclaration#getAssembly() + */ + public String getAssembly() { + if( assembly == null ) return ""; //$NON-NLS-1$ + return new String( assembly ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTASMDeclaration#setAssembly(java.lang.String) + */ + public void setAssembly(String assembly) { + this.assembly = assembly.toCharArray(); + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTBinaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTBinaryExpression.java new file mode 100644 index 00000000000..03264671438 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTBinaryExpression.java @@ -0,0 +1,68 @@ +/********************************************************************** + * 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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; +import org.eclipse.cdt.core.dom.ast.IASTExpression; + +/** + * @author jcamelon + */ +public class CPPASTBinaryExpression extends CPPASTNode implements + IASTBinaryExpression { + + private int op; + private IASTExpression operand1; + private IASTExpression operand2; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTBinaryExpression#getOperator() + */ + public int getOperator() { + return op; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTBinaryExpression#getOperand1() + */ + public IASTExpression getOperand1() { + return operand1; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTBinaryExpression#getOperand2() + */ + public IASTExpression getOperand2() { + return operand2; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTBinaryExpression#setOperator(int) + */ + public void setOperator(int op) { + this.op = op; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTBinaryExpression#setOperand1(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setOperand1(IASTExpression expression) { + operand1 = expression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTBinaryExpression#setOperand2(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setOperand2(IASTExpression expression) { + operand2 = expression; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTBreakStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTBreakStatement.java new file mode 100644 index 00000000000..15f9458f5b9 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTBreakStatement.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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTBreakStatement; + +/** + * @author jcamelon + */ +public class CPPASTBreakStatement extends CPPASTNode implements + IASTBreakStatement { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTCaseStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTCaseStatement.java new file mode 100644 index 00000000000..be49216cef1 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTCaseStatement.java @@ -0,0 +1,37 @@ +/********************************************************************** + * 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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTCaseStatement; +import org.eclipse.cdt.core.dom.ast.IASTExpression; + +/** + * @author jcamelon + */ +public class CPPASTCaseStatement extends CPPASTNode implements + IASTCaseStatement { + private IASTExpression expression; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTCaseStatement#getExpression() + */ + public IASTExpression getExpression() { + return expression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTCaseStatement#setExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setExpression(IASTExpression expression) { + this.expression = expression; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTCastExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTCastExpression.java new file mode 100644 index 00000000000..d64b4d0a450 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTCastExpression.java @@ -0,0 +1,37 @@ +/********************************************************************** + * 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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTCastExpression; +import org.eclipse.cdt.core.dom.ast.IASTTypeId; + +/** + * @author jcamelon + */ +public class CPPASTCastExpression extends CPPASTUnaryExpression implements + IASTCastExpression { + private IASTTypeId typeId; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTUnaryTypeIdExpression#setTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId) + */ + public void setTypeId(IASTTypeId typeId) { + this.typeId = typeId; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTUnaryTypeIdExpression#getTypeId() + */ + public IASTTypeId getTypeId() { + return typeId; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTCompoundStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTCompoundStatement.java new file mode 100644 index 00000000000..a5d6957cb30 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTCompoundStatement.java @@ -0,0 +1,74 @@ +/********************************************************************** + * 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.parser2.cpp; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; +import org.eclipse.cdt.core.dom.ast.IASTStatement; + +/** + * @author jcamelon + */ +public class CPPASTCompoundStatement extends CPPASTNode implements + IASTCompoundStatement { + + private int currentIndex = 0; + private void removeNullStatements() { + int nullCount = 0; + for( int i = 0; i < statements.length; ++i ) + if( statements[i] == null ) + ++nullCount; + if( nullCount == 0 ) return; + IASTStatement [] old = statements; + int newSize = old.length - nullCount; + statements = new IASTStatement[ newSize ]; + for( int i = 0; i < newSize; ++i ) + statements[i] = old[i]; + currentIndex = newSize; + } + + + private IASTStatement [] statements = null; + private static final int DEFAULT_STATEMENT_LIST_SIZE = 8; + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTCompoundStatement#getStatements() + */ + public List getStatements() { + if( statements == null ) return Collections.EMPTY_LIST; + removeNullStatements(); + return Arrays.asList( statements ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTCompoundStatement#addStatement(org.eclipse.cdt.core.dom.ast.IASTStatement) + */ + public void addStatement(IASTStatement statement) { + if( statements == null ) + { + statements = new IASTStatement[ DEFAULT_STATEMENT_LIST_SIZE ]; + currentIndex = 0; + } + if( statements.length == currentIndex ) + { + IASTStatement [] old = statements; + statements = new IASTStatement[ old.length * 2 ]; + for( int i = 0; i < old.length; ++i ) + statements[i] = old[i]; + } + statements[ currentIndex++ ] = statement; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTCompoundStatementExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTCompoundStatementExpression.java new file mode 100644 index 00000000000..1a7d37757ec --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTCompoundStatementExpression.java @@ -0,0 +1,37 @@ +/********************************************************************** + * 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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; +import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; + +/** + * @author jcamelon + */ +public class CPPASTCompoundStatementExpression extends CPPASTNode implements + IGNUASTCompoundStatementExpression { + private IASTCompoundStatement statement; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.gcc.IGCCASTCompoundStatementExpression#getCompoundStatement() + */ + public IASTCompoundStatement getCompoundStatement() { + return statement; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.gcc.IGCCASTCompoundStatementExpression#setCompoundStatement(org.eclipse.cdt.core.dom.ast.IASTCompoundStatement) + */ + public void setCompoundStatement(IASTCompoundStatement statement) { + this.statement = statement; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTConditionalExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTConditionalExpression.java new file mode 100644 index 00000000000..17d6294d731 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTConditionalExpression.java @@ -0,0 +1,67 @@ +/********************************************************************** + * 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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression; +import org.eclipse.cdt.core.dom.ast.IASTExpression; + +/** + * @author jcamelon + */ +public class CPPASTConditionalExpression extends CPPASTNode implements + IASTConditionalExpression { + private IASTExpression condition; + private IASTExpression negative; + private IASTExpression postive; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTConditionalExpression#getLogicalConditionExpression() + */ + public IASTExpression getLogicalConditionExpression() { + return condition; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTConditionalExpression#setLogicalConditionExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setLogicalConditionExpression(IASTExpression expression) { + condition = expression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTConditionalExpression#getPositiveResultExpression() + */ + public IASTExpression getPositiveResultExpression() { + return postive; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTConditionalExpression#setPositiveResultExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setPositiveResultExpression(IASTExpression expression) { + this.postive = expression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTConditionalExpression#getNegativeResultExpression() + */ + public IASTExpression getNegativeResultExpression() { + return negative; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTConditionalExpression#setNegativeResultExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setNegativeResultExpression(IASTExpression expression) { + this.negative = expression; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTContinueStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTContinueStatement.java new file mode 100644 index 00000000000..2cc4d6bc437 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTContinueStatement.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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTContinueStatement; + +/** + * @author jcamelon + */ +public class CPPASTContinueStatement extends CPPASTNode implements + IASTContinueStatement { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTDeclarationStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTDeclarationStatement.java new file mode 100644 index 00000000000..55058f20980 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTDeclarationStatement.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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement; + +/** + * @author jcamelon + */ +public class CPPASTDeclarationStatement extends CPPASTNode implements + IASTDeclarationStatement { + + private IASTDeclaration declaration; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement#getDeclaration() + */ + public IASTDeclaration getDeclaration() { + return declaration; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement#setDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration) + */ + public void setDeclaration(IASTDeclaration declaration) { + this.declaration = declaration; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTDefaultStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTDefaultStatement.java new file mode 100644 index 00000000000..8de2f422e3b --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTDefaultStatement.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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement; + +/** + * @author jcamelon + */ +public class CPPASTDefaultStatement extends CPPASTNode implements + IASTDefaultStatement { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTDoStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTDoStatement.java new file mode 100644 index 00000000000..3f3e8d1d1a6 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTDoStatement.java @@ -0,0 +1,52 @@ +/********************************************************************** + * 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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTDoStatement; +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTStatement; + +/** + * @author jcamelon + */ +public class CPPASTDoStatement extends CPPASTNode implements IASTDoStatement { + private IASTStatement body; + private IASTExpression condition; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTDoStatement#getBody() + */ + public IASTStatement getBody() { + return body; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTDoStatement#setBody(org.eclipse.cdt.core.dom.ast.IASTStatement) + */ + public void setBody(IASTStatement body) { + this.body = body; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTDoStatement#getCondition() + */ + public IASTExpression getCondition() { + return condition; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTDoStatement#setCondition(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setCondition(IASTExpression condition) { + this.condition = condition; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTEnumerator.java new file mode 100644 index 00000000000..82a544b848e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTEnumerator.java @@ -0,0 +1,52 @@ +/********************************************************************** + * 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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; + +/** + * @author jcamelon + */ +public class CPPASTEnumerator extends CPPASTNode implements IASTEnumerator { + private IASTName name; + private IASTExpression value; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator#setName(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public void setName(IASTName name) { + this.name = name; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator#getName() + */ + public IASTName getName() { + return name; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator#setValue(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setValue(IASTExpression expression) { + this.value = expression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator#getValue() + */ + public IASTExpression getValue() { + return value; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTExpressionList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTExpressionList.java new file mode 100644 index 00000000000..0f898720463 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTExpressionList.java @@ -0,0 +1,75 @@ +/********************************************************************** + * 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.parser2.cpp; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTExpressionList; + +/** + * @author jcamelon + */ +public class CPPASTExpressionList extends CPPASTNode implements + IASTExpressionList { + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTExpressionList#getExpressions() + */ + public List getExpressions() { + if( expressions == null ) return Collections.EMPTY_LIST; + removeNullExpressions(); + return Arrays.asList( expressions ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTExpressionList#addExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void addExpression(IASTExpression expression) { + if( expressions == null ) + { + expressions = new IASTExpression[ DEFAULT_EXPRESSIONLIST_SIZE ]; + currentIndex = 0; + } + if( expressions.length == currentIndex ) + { + IASTExpression [] old = expressions; + expressions = new IASTExpression[ old.length * 2 ]; + for( int i = 0; i < old.length; ++i ) + expressions[i] = old[i]; + } + expressions[ currentIndex++ ] = expression; + } + + /** + * @param decls2 + */ + private void removeNullExpressions() { + int nullCount = 0; + for( int i = 0; i < expressions.length; ++i ) + if( expressions[i] == null ) + ++nullCount; + if( nullCount == 0 ) return; + IASTExpression [] old = expressions; + int newSize = old.length - nullCount; + expressions = new IASTExpression[ newSize ]; + for( int i = 0; i < newSize; ++i ) + expressions[i] = old[i]; + currentIndex = newSize; + } + + private int currentIndex = 0; + private IASTExpression [] expressions = null; + private static final int DEFAULT_EXPRESSIONLIST_SIZE = 4; + + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTExpressionStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTExpressionStatement.java new file mode 100644 index 00000000000..713ecf06e45 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTExpressionStatement.java @@ -0,0 +1,37 @@ +/********************************************************************** + * 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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; + +/** + * @author jcamelon + */ +public class CPPASTExpressionStatement extends CPPASTNode implements + IASTExpressionStatement { + private IASTExpression expression; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTExpressionStatement#getExpression() + */ + public IASTExpression getExpression() { + return expression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTExpressionStatement#setExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setExpression(IASTExpression expression) { + this.expression = expression; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTFieldDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTFieldDeclarator.java new file mode 100644 index 00000000000..45210c5aab3 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTFieldDeclarator.java @@ -0,0 +1,39 @@ +/********************************************************************** + * 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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator; + +/** + * @author jcamelon + */ +public class CPPASTFieldDeclarator extends CPPASTDeclarator implements + IASTFieldDeclarator { + + private IASTExpression bitField; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator#getBitFieldSize() + */ + public IASTExpression getBitFieldSize() { + return bitField; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator#setBitFieldSize(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setBitFieldSize(IASTExpression size) { + this.bitField = size; + } + + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTForStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTForStatement.java new file mode 100644 index 00000000000..e921a647475 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTForStatement.java @@ -0,0 +1,100 @@ +/********************************************************************** + * 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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTForStatement; +import org.eclipse.cdt.core.dom.ast.IASTStatement; + +/** + * @author jcamelon + */ +public class CPPASTForStatement extends CPPASTNode implements IASTForStatement { + + private IASTExpression initialExpression; + private IASTDeclaration initDeclaration; + private IASTExpression condition; + private IASTExpression iterationExpression; + private IASTStatement body; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTForStatement#getInitExpression() + */ + public IASTExpression getInitExpression() { + return initialExpression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTForStatement#setInit(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setInit(IASTExpression expression) { + this.initialExpression = expression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTForStatement#getInitDeclaration() + */ + public IASTDeclaration getInitDeclaration() { + return initDeclaration; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTForStatement#setInit(org.eclipse.cdt.core.dom.ast.IASTDeclaration) + */ + public void setInit(IASTDeclaration declaration) { + this.initDeclaration = declaration; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTForStatement#getCondition() + */ + public IASTExpression getCondition() { + return condition; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTForStatement#setCondition(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setCondition(IASTExpression condition) { + this.condition = condition; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTForStatement#getIterationExpression() + */ + public IASTExpression getIterationExpression() { + return iterationExpression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTForStatement#setIterationExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setIterationExpression(IASTExpression iterator) { + this.iterationExpression = iterator; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTForStatement#getBody() + */ + public IASTStatement getBody() { + return body; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTForStatement#setBody(org.eclipse.cdt.core.dom.ast.IASTStatement) + */ + public void setBody(IASTStatement statement) { + body = statement; + + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTFunctionCallExpression.java new file mode 100644 index 00000000000..e8847380d7a --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTFunctionCallExpression.java @@ -0,0 +1,52 @@ +/********************************************************************** + * 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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; + +/** + * @author jcamelon + */ +public class CPPASTFunctionCallExpression extends CPPASTNode implements + IASTFunctionCallExpression { + private IASTExpression functionName; + private IASTExpression parameter; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression#setFunctionNameExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setFunctionNameExpression(IASTExpression expression) { + this.functionName = expression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression#getFunctionNameExpression() + */ + public IASTExpression getFunctionNameExpression() { + return functionName; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression#setParameterExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setParameterExpression(IASTExpression expression) { + this.parameter = expression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression#getParameterExpression() + */ + public IASTExpression getParameterExpression() { + return parameter; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTFunctionDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTFunctionDefinition.java new file mode 100644 index 00000000000..a61d3db0d42 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTFunctionDefinition.java @@ -0,0 +1,71 @@ +/********************************************************************** + * 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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; +import org.eclipse.cdt.core.dom.ast.IASTStatement; + +/** + * @author jcamelon + */ +public class CPPASTFunctionDefinition extends CPPASTNode implements + IASTFunctionDefinition { + + private IASTDeclSpecifier declSpecifier; + private IASTFunctionDeclarator declarator; + private IASTStatement bodyStatement; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition#getDeclSpecifier() + */ + public IASTDeclSpecifier getDeclSpecifier() { + return declSpecifier; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition#setDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier) + */ + public void setDeclSpecifier(IASTDeclSpecifier declSpec) { + declSpecifier = declSpec; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition#getDeclarator() + */ + public IASTFunctionDeclarator getDeclarator() { + return declarator; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition#setDeclarator(org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator) + */ + public void setDeclarator(IASTFunctionDeclarator declarator) { + this.declarator = declarator; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition#getBody() + */ + public IASTStatement getBody() { + return bodyStatement; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition#setBody(org.eclipse.cdt.core.dom.ast.IASTStatement) + */ + public void setBody(IASTStatement statement) { + bodyStatement = statement; + } + + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTGotoStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTGotoStatement.java new file mode 100644 index 00000000000..4eeb868ab1b --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTGotoStatement.java @@ -0,0 +1,37 @@ +/********************************************************************** + * 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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTGotoStatement; +import org.eclipse.cdt.core.dom.ast.IASTName; + +/** + * @author jcamelon + */ +public class CPPASTGotoStatement extends CPPASTNode implements + IASTGotoStatement { + private IASTName name; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTGotoStatement#getName() + */ + public IASTName getName() { + return this.name; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTGotoStatement#setName(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public void setName(IASTName name) { + this.name = name; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTIdExpression.java new file mode 100644 index 00000000000..9b5b8bf36d5 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTIdExpression.java @@ -0,0 +1,36 @@ +/********************************************************************** + * 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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTIdExpression; +import org.eclipse.cdt.core.dom.ast.IASTName; + +/** + * @author jcamelon + */ +public class CPPASTIdExpression extends CPPASTNode implements IASTIdExpression { + private IASTName name; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTIdExpression#getName() + */ + public IASTName getName() { + return name; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTIdExpression#setName(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public void setName(IASTName name) { + this.name = name; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTIfStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTIfStatement.java new file mode 100644 index 00000000000..6411026e73e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTIfStatement.java @@ -0,0 +1,67 @@ +/********************************************************************** + * 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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTIfStatement; +import org.eclipse.cdt.core.dom.ast.IASTStatement; + +/** + * @author jcamelon + */ +public class CPPASTIfStatement extends CPPASTNode implements IASTIfStatement { + private IASTExpression condition; + private IASTStatement thenClause; + private IASTStatement elseClause; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTIfStatement#getCondition() + */ + public IASTExpression getCondition() { + return condition; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTIfStatement#setCondition(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setCondition(IASTExpression condition) { + this.condition = condition; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTIfStatement#getThenClause() + */ + public IASTStatement getThenClause() { + return thenClause; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTIfStatement#setThenClause(org.eclipse.cdt.core.dom.ast.IASTStatement) + */ + public void setThenClause(IASTStatement thenClause) { + this.thenClause = thenClause; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTIfStatement#getElseClause() + */ + public IASTStatement getElseClause() { + return elseClause; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTIfStatement#setElseClause(org.eclipse.cdt.core.dom.ast.IASTStatement) + */ + public void setElseClause(IASTStatement elseClause) { + this.elseClause = elseClause; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTInitializerExpresion.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTInitializerExpresion.java new file mode 100644 index 00000000000..c016b774f13 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTInitializerExpresion.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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; + +/** + * @author jcamelon + */ +public class CPPASTInitializerExpresion extends CPPASTNode implements + IASTInitializerExpression { + + private IASTExpression exp; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTInitializerExpression#getExpression() + */ + public IASTExpression getExpression() { + return exp; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTInitializerExpression#setExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setExpression(IASTExpression expression) { + this.exp = expression; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTInitializerList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTInitializerList.java new file mode 100644 index 00000000000..ca5118e00f8 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTInitializerList.java @@ -0,0 +1,76 @@ +/********************************************************************** + * 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.parser2.cpp; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTInitializer; +import org.eclipse.cdt.core.dom.ast.IASTInitializerList; + +/** + * @author jcamelon + */ +public class CPPASTInitializerList extends CPPASTNode implements + IASTInitializerList { + + private int currentIndex = 0; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration#getDeclarators() + */ + public List getInitializers() { + if( initializers == null ) return Collections.EMPTY_LIST; + removeNullInitializers(); + return Arrays.asList( initializers ); + } + + public void addInitializer( IASTInitializer d ) + { + if( initializers == null ) + { + initializers = new IASTInitializer[ DEFAULT_INITIALIZERS_LIST_SIZE ]; + currentIndex = 0; + } + if( initializers.length == currentIndex ) + { + IASTInitializer [] old = initializers; + initializers = new IASTInitializer[ old.length * 2 ]; + for( int i = 0; i < old.length; ++i ) + initializers[i] = old[i]; + } + initializers[ currentIndex++ ] = d; + + } + + /** + * @param decls2 + */ + private void removeNullInitializers() { + int nullCount = 0; + for( int i = 0; i < initializers.length; ++i ) + if( initializers[i] == null ) + ++nullCount; + if( nullCount == 0 ) return; + IASTInitializer [] old = initializers; + int newSize = old.length - nullCount; + initializers = new IASTInitializer[ newSize ]; + for( int i = 0; i < newSize; ++i ) + initializers[i] = old[i]; + currentIndex = newSize; + } + + + private IASTInitializer [] initializers = null; + private static final int DEFAULT_INITIALIZERS_LIST_SIZE = 4; + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTLabelStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTLabelStatement.java new file mode 100644 index 00000000000..6f28c4f15e1 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTLabelStatement.java @@ -0,0 +1,37 @@ +/********************************************************************** + * 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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; +import org.eclipse.cdt.core.dom.ast.IASTName; + +/** + * @author jcamelon + */ +public class CPPASTLabelStatement extends CPPASTNode implements + IASTLabelStatement { + private IASTName name; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTLabelStatement#getName() + */ + public IASTName getName() { + return name; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTLabelStatement#setName(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public void setName(IASTName name) { + this.name = name; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTLiteralExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTLiteralExpression.java index d9ccbabc7c7..a363aaf8bbe 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTLiteralExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTLiteralExpression.java @@ -11,13 +11,45 @@ package org.eclipse.cdt.internal.core.parser2.cpp; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression; -import org.eclipse.cdt.internal.core.parser2.c.CASTLiteralExpression; + /** * @author jcamelon */ -public class CPPASTLiteralExpression extends CASTLiteralExpression implements +public class CPPASTLiteralExpression extends CPPASTNode implements ICPPASTLiteralExpression { + private int kind; + private String value = ""; //$NON-NLS-1$ + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTLiteralExpression#getKind() + */ + public int getKind() { + return kind; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTLiteralExpression#setKind(int) + */ + public void setKind(int value) { + this.kind = value; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTLiteralExpression#setValue(java.lang.String) + */ + public void setValue(String value) { + this.value = value; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString() { + return value; + } + + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTName.java index 26e7aa1860c..946b67e7718 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTName.java @@ -10,103 +10,58 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.parser2.cpp; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IBinding; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; /** * @author jcamelon */ -public class CPPASTName extends CPPASTNode implements ICPPASTQualifiedName { +public class CPPASTName extends CPPASTNode implements IASTName { + + private char[] name; + private static final char[] EMPTY_CHAR_ARRAY = { }; /** - * @param duple + * @param name + */ + public CPPASTName(char [] name ) { + this.name = name; + } + + /** + * */ public CPPASTName() { + name = EMPTY_CHAR_ARRAY; } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IASTName#resolveBinding() */ public IBinding resolveBinding() { - // TODO Auto-generated method stub + //TODO return null; } + + protected void setBinding( IBinding binding ){ + //TODO + } - - /* (non-Javadoc) * @see java.lang.Object#toString() */ public String toString() { - if( names == null ) return null; - removeNullNames(); - StringBuffer buffer = new StringBuffer(); - for( int i = 0; i < names.length; ++i ) - { - String n = names[i].toString(); - if( n == null ) - return null; - buffer.append( n ); - if( i != names.length - 1 ) - buffer.append( "::"); //$NON-NLS-1$ - } - return buffer.toString(); + if( name == EMPTY_CHAR_ARRAY ) return null; + return new String( name ); + } + + public char[] toCharArray() { + return name; + } + + public void setName( char [] name ) + { + this.name = name; } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName#addName(org.eclipse.cdt.core.dom.ast.IASTName) - */ - public void addName(IASTName name) { - if( names == null ) - { - names = new IASTName[ DEFAULT_NAMES_LIST_SIZE ]; - currentIndex = 0; - } - if( names.length == currentIndex ) - { - IASTName [] old = names; - names = new IASTName[ old.length * 2 ]; - for( int i = 0; i < old.length; ++i ) - names[i] = old[i]; - } - names[ currentIndex++ ] = name; - } - - /** - * @param decls2 - */ - private void removeNullNames() { - int nullCount = 0; - for( int i = 0; i < names.length; ++i ) - if( names[i] == null ) - ++nullCount; - if( nullCount == 0 ) return; - IASTName [] old = names; - int newSize = old.length - nullCount; - names = new IASTName[ newSize ]; - for( int i = 0; i < newSize; ++i ) - names[i] = old[i]; - currentIndex = newSize; - } - - private int currentIndex = 0; - private IASTName [] names = null; - private static final int DEFAULT_NAMES_LIST_SIZE = 4; - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName#getNames() - */ - public List getNames() { - if( names == null ) return Collections.EMPTY_LIST; - removeNullNames(); - return Arrays.asList( names ); - } - - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTNamespaceAlias.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTNamespaceAlias.java index a67e3a3420d..255ee5b7b3b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTNamespaceAlias.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTNamespaceAlias.java @@ -12,12 +12,11 @@ package org.eclipse.cdt.internal.core.parser2.cpp; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias; -import org.eclipse.cdt.internal.core.parser2.c.CASTNode; /** * @author jcamelon */ -public class CPPASTNamespaceAlias extends CASTNode implements +public class CPPASTNamespaceAlias extends CPPASTNode implements ICPPASTNamespaceAlias { private IASTName alias; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTNullStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTNullStatement.java new file mode 100644 index 00000000000..2733e5c34e1 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTNullStatement.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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTNullStatement; + +/** + * @author jcamelon + */ +public class CPPASTNullStatement extends CPPASTNode implements + IASTNullStatement { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTQualifiedName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTQualifiedName.java new file mode 100644 index 00000000000..1e26ffc15e9 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTQualifiedName.java @@ -0,0 +1,112 @@ +/********************************************************************** + * 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.parser2.cpp; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; + +/** + * @author jcamelon + */ +public class CPPASTQualifiedName extends CPPASTNode implements ICPPASTQualifiedName { + + /** + * @param duple + */ + public CPPASTQualifiedName() { + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTName#resolveBinding() + */ + public IBinding resolveBinding() { + // TODO Auto-generated method stub + return null; + } + + + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString() { + if( names == null ) return null; + removeNullNames(); + StringBuffer buffer = new StringBuffer(); + for( int i = 0; i < names.length; ++i ) + { + String n = names[i].toString(); + if( n == null ) + return null; + buffer.append( n ); + if( i != names.length - 1 ) + buffer.append( "::"); //$NON-NLS-1$ + } + return buffer.toString(); + } + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName#addName(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public void addName(IASTName name) { + if( names == null ) + { + names = new IASTName[ DEFAULT_NAMES_LIST_SIZE ]; + currentIndex = 0; + } + if( names.length == currentIndex ) + { + IASTName [] old = names; + names = new IASTName[ old.length * 2 ]; + for( int i = 0; i < old.length; ++i ) + names[i] = old[i]; + } + names[ currentIndex++ ] = name; + } + + /** + * @param decls2 + */ + private void removeNullNames() { + int nullCount = 0; + for( int i = 0; i < names.length; ++i ) + if( names[i] == null ) + ++nullCount; + if( nullCount == 0 ) return; + IASTName [] old = names; + int newSize = old.length - nullCount; + names = new IASTName[ newSize ]; + for( int i = 0; i < newSize; ++i ) + names[i] = old[i]; + currentIndex = newSize; + } + + private int currentIndex = 0; + private IASTName [] names = null; + private static final int DEFAULT_NAMES_LIST_SIZE = 4; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName#getNames() + */ + public List getNames() { + if( names == null ) return Collections.EMPTY_LIST; + removeNullNames(); + return Arrays.asList( names ); + } + + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTReturnStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTReturnStatement.java new file mode 100644 index 00000000000..9b672600b6a --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTReturnStatement.java @@ -0,0 +1,37 @@ +/********************************************************************** + * 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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTReturnStatement; + +/** + * @author jcamelon + */ +public class CPPASTReturnStatement extends CPPASTNode implements + IASTReturnStatement { + private IASTExpression retValue; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTReturnStatement#getReturnValue() + */ + public IASTExpression getReturnValue() { + return retValue; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTReturnStatement#setReturnValue(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setReturnValue(IASTExpression returnValue) { + retValue = returnValue; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTSimpleDeclaration.java new file mode 100644 index 00000000000..39f86974575 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTSimpleDeclaration.java @@ -0,0 +1,88 @@ +/********************************************************************** + * 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.parser2.cpp; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; + +/** + * @author jcamelon + */ +public class CPPASTSimpleDeclaration extends CPPASTNode implements + IASTSimpleDeclaration { + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration#getDeclSpecifier() + */ + public IASTDeclSpecifier getDeclSpecifier() { + return declSpecifier; + } + + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration#getDeclarators() + */ + public List getDeclarators() { + if( declarators == null ) return Collections.EMPTY_LIST; + removeNullDeclarators(); + return Arrays.asList( declarators ); + } + + public void addDeclarator( IASTDeclarator d ) + { + if( declarators == null ) + { + declarators = new IASTDeclarator[ DEFAULT_DECLARATORS_LIST_SIZE ]; + currentIndex = 0; + } + if( declarators.length == currentIndex ) + { + IASTDeclarator [] old = declarators; + declarators = new IASTDeclarator[ old.length * 2 ]; + for( int i = 0; i < old.length; ++i ) + declarators[i] = old[i]; + } + declarators[ currentIndex++ ] = d; + } + + private void removeNullDeclarators() { + int nullCount = 0; + for( int i = 0; i < declarators.length; ++i ) + if( declarators[i] == null ) + ++nullCount; + if( nullCount == 0 ) return; + IASTDeclarator [] old = declarators; + int newSize = old.length - nullCount; + declarators = new IASTDeclarator[ newSize ]; + for( int i = 0; i < newSize; ++i ) + declarators[i] = old[i]; + currentIndex = newSize; + } + + private int currentIndex = 0; + private IASTDeclarator [] declarators = null; + private static final int DEFAULT_DECLARATORS_LIST_SIZE = 4; + private IASTDeclSpecifier declSpecifier; + + /** + * @param declSpecifier The declSpecifier to set. + */ + public void setDeclSpecifier(IASTDeclSpecifier declSpecifier) { + this.declSpecifier = declSpecifier; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTSwitchStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTSwitchStatement.java new file mode 100644 index 00000000000..04d5408fc52 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTSwitchStatement.java @@ -0,0 +1,54 @@ +/********************************************************************** + * 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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement; + +/** + * @author jcamelon + */ +public class CPPASTSwitchStatement extends CPPASTNode implements + IASTSwitchStatement { + + private IASTExpression controller; + private IASTStatement body; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTSwitchStatement#getController() + */ + public IASTExpression getController() { + return controller; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTSwitchStatement#setController(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setController(IASTExpression controller) { + this.controller = controller; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTSwitchStatement#getBody() + */ + public IASTStatement getBody() { + return body; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTSwitchStatement#setBody(org.eclipse.cdt.core.dom.ast.IASTStatement) + */ + public void setBody(IASTStatement body) { + this.body = body; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTTemplateId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTTemplateId.java new file mode 100644 index 00000000000..bcf9ae03934 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTTemplateId.java @@ -0,0 +1,119 @@ +/********************************************************************** + * 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.parser2.cpp; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; + +/** + * @author jcamelon + */ +public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId { + + private IASTName templateName; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId#getTemplateName() + */ + public IASTName getTemplateName() { + return templateName; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId#setTemplateName(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public void setTemplateName(IASTName name) { + templateName = name; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId#addTemplateArgument(org.eclipse.cdt.core.dom.ast.IASTTypeId) + */ + public void addTemplateArgument(IASTTypeId typeId) { + if( templateArguments == null ) + { + templateArguments = new IASTNode[ DEFAULT_ARGS_LIST_SIZE ]; + currentIndex = 0; + } + if( templateArguments.length == currentIndex ) + { + IASTNode [] old = templateArguments; + templateArguments = new IASTNode[ old.length * 2 ]; + for( int i = 0; i < old.length; ++i ) + templateArguments[i] = old[i]; + } + templateArguments[ currentIndex++ ] = typeId; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId#addTemplateArgument(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void addTemplateArgument(IASTExpression expression) { + if( templateArguments == null ) + { + templateArguments = new IASTNode[ DEFAULT_ARGS_LIST_SIZE ]; + currentIndex = 0; + } + if( templateArguments.length == currentIndex ) + { + IASTNode [] old = templateArguments; + templateArguments = new IASTNode[ old.length * 2 ]; + for( int i = 0; i < old.length; ++i ) + templateArguments[i] = old[i]; + } + templateArguments[ currentIndex++ ] = expression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId#getTemplateArguments() + */ + public List getTemplateArguments() { + if( templateArguments == null ) return Collections.EMPTY_LIST; + removeNullArguments(); + return Arrays.asList( templateArguments ); + } + + private void removeNullArguments() { + int nullCount = 0; + for( int i = 0; i < templateArguments.length; ++i ) + if( templateArguments[i] == null ) + ++nullCount; + if( nullCount == 0 ) return; + IASTNode [] old = templateArguments; + int newSize = old.length - nullCount; + templateArguments = new IASTNode[ newSize ]; + for( int i = 0; i < newSize; ++i ) + templateArguments[i] = old[i]; + currentIndex = newSize; + } + + private int currentIndex = 0; + private IASTNode [] templateArguments = null; + private static final int DEFAULT_ARGS_LIST_SIZE = 4; + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTName#resolveBinding() + */ + public IBinding resolveBinding() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTTranslationUnit.java new file mode 100644 index 00000000000..e564f64e9c4 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTTranslationUnit.java @@ -0,0 +1,99 @@ +/********************************************************************** + * 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.parser2.cpp; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IScope; + +/** + * @author jcamelon + */ +public class CPPASTTranslationUnit extends CPPASTNode implements + IASTTranslationUnit { + private IASTDeclaration [] decls = null; + private static final int DEFAULT_CHILDREN_LIST_SIZE = 8; + private int currentIndex = 0; + + public void addDeclaration( IASTDeclaration d ) + { + if( decls == null ) + { + decls = new IASTDeclaration[ DEFAULT_CHILDREN_LIST_SIZE ]; + currentIndex = 0; + } + if( decls.length == currentIndex ) + { + IASTDeclaration [] old = decls; + decls = new IASTDeclaration[ old.length * 2 ]; + for( int i = 0; i < old.length; ++i ) + decls[i] = old[i]; + } + decls[ currentIndex++ ] = d; + } + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations() + */ + public List getDeclarations() { + if( decls == null ) return Collections.EMPTY_LIST; + removeNullDeclarations(); + return Arrays.asList( decls ); + } + + /** + * @param decls2 + */ + private void removeNullDeclarations() { + int nullCount = 0; + for( int i = 0; i < decls.length; ++i ) + if( decls[i] == null ) + ++nullCount; + if( nullCount == 0 ) return; + IASTDeclaration [] old = decls; + int newSize = old.length - nullCount; + decls = new IASTDeclaration[ newSize ]; + for( int i = 0; i < newSize; ++i ) + decls[i] = old[i]; + currentIndex = newSize; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getScope() + */ + public IScope getScope() { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations(org.eclipse.cdt.core.dom.ast.IBinding) + */ + public List getDeclarations(IBinding binding) { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getReferences(org.eclipse.cdt.core.dom.ast.IBinding) + */ + public List getReferences(IBinding binding) { + // TODO Auto-generated method stub + return null; + } + + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTTypeIdExpression.java new file mode 100644 index 00000000000..1770cff5e27 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTTypeIdExpression.java @@ -0,0 +1,53 @@ +/********************************************************************** + * 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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; + +/** + * @author jcamelon + */ +public class CPPASTTypeIdExpression extends CPPASTNode implements + IASTTypeIdExpression { + + private int op; + private IASTTypeId typeId; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression#getOperator() + */ + public int getOperator() { + return op; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression#setOperator(int) + */ + public void setOperator(int value) { + this.op = value; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression#setTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId) + */ + public void setTypeId(IASTTypeId typeId) { + this.typeId = typeId; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression#getTypeId() + */ + public IASTTypeId getTypeId() { + return typeId; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTUnaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTUnaryExpression.java new file mode 100644 index 00000000000..34b15173597 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTUnaryExpression.java @@ -0,0 +1,53 @@ +/********************************************************************** + * 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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; + +/** + * @author jcamelon + */ +public class CPPASTUnaryExpression extends CPPASTNode implements + IASTUnaryExpression { + + private int operator; + private IASTExpression operand; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTUnaryExpression#getOperator() + */ + public int getOperator() { + return operator; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTUnaryExpression#setOperator(int) + */ + public void setOperator(int value) { + this.operator = value; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTUnaryExpression#getOperand() + */ + public IASTExpression getOperand() { + return operand; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTUnaryExpression#setOperand(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setOperand(IASTExpression expression) { + operand = expression; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTWhileStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTWhileStatement.java new file mode 100644 index 00000000000..9735c297042 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/CPPASTWhileStatement.java @@ -0,0 +1,53 @@ +/********************************************************************** + * 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.parser2.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.core.dom.ast.IASTWhileStatement; + +/** + * @author jcamelon + */ +public class CPPASTWhileStatement extends CPPASTNode implements + IASTWhileStatement { + private IASTExpression condition; + private IASTStatement body; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTWhileStatement#getCondition() + */ + public IASTExpression getCondition() { + return condition; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTWhileStatement#setCondition(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setCondition(IASTExpression condition) { + this.condition = condition; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTWhileStatement#getBody() + */ + public IASTStatement getBody() { + return body; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTWhileStatement#setBody(org.eclipse.cdt.core.dom.ast.IASTStatement) + */ + public void setBody(IASTStatement body) { + this.body = body; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/GNUCPPSourceParser.java index 17c4b3f9b27..1ff3f513576 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/GNUCPPSourceParser.java @@ -14,43 +14,59 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; +import org.eclipse.cdt.core.dom.ast.IASTBreakStatement; +import org.eclipse.cdt.core.dom.ast.IASTCaseStatement; import org.eclipse.cdt.core.dom.ast.IASTCastExpression; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression; +import org.eclipse.cdt.core.dom.ast.IASTContinueStatement; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement; +import org.eclipse.cdt.core.dom.ast.IASTDoStatement; import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpressionList; +import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFieldReference; +import org.eclipse.cdt.core.dom.ast.IASTForStatement; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; +import org.eclipse.cdt.core.dom.ast.IASTGotoStatement; import org.eclipse.cdt.core.dom.ast.IASTIdExpression; +import org.eclipse.cdt.core.dom.ast.IASTIfStatement; import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; import org.eclipse.cdt.core.dom.ast.IASTInitializerList; +import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier; 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.IASTPointer; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; +import org.eclipse.cdt.core.dom.ast.IASTReturnStatement; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; +import org.eclipse.cdt.core.dom.ast.IASTWhileStatement; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression; @@ -78,6 +94,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter; @@ -110,23 +127,7 @@ import org.eclipse.cdt.internal.core.parser.TemplateParameterManager; import org.eclipse.cdt.internal.core.parser.token.TokenFactory; import org.eclipse.cdt.internal.core.parser2.ASTNode; import org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser; -import org.eclipse.cdt.internal.core.parser2.c.CASTBinaryExpression; -import org.eclipse.cdt.internal.core.parser2.c.CASTCompoundStatement; -import org.eclipse.cdt.internal.core.parser2.c.CASTCompoundStatementExpression; -import org.eclipse.cdt.internal.core.parser2.c.CASTConditionalExpression; -import org.eclipse.cdt.internal.core.parser2.c.CASTEnumerator; -import org.eclipse.cdt.internal.core.parser2.c.CASTExpressionList; -import org.eclipse.cdt.internal.core.parser2.c.CASTFieldDeclarator; -import org.eclipse.cdt.internal.core.parser2.c.CASTFunctionCallExpression; -import org.eclipse.cdt.internal.core.parser2.c.CASTFunctionDefinition; -import org.eclipse.cdt.internal.core.parser2.c.CASTIdExpression; -import org.eclipse.cdt.internal.core.parser2.c.CASTInitializerExpresion; -import org.eclipse.cdt.internal.core.parser2.c.CASTInitializerList; -import org.eclipse.cdt.internal.core.parser2.c.CASTName; -import org.eclipse.cdt.internal.core.parser2.c.CASTSimpleDeclaration; -import org.eclipse.cdt.internal.core.parser2.c.CASTTranslationUnit; -import org.eclipse.cdt.internal.core.parser2.c.CASTTypeIdExpression; -import org.eclipse.cdt.internal.core.parser2.c.CASTUnaryExpression; +import org.eclipse.cdt.internal.core.parser2.IProblemRequestor; /** * This is our implementation of the IParser interface, serving as a @@ -1514,7 +1515,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * @return */ private IASTFunctionCallExpression createFunctionCallExpression() { - return new CASTFunctionCallExpression(); + return new CPPASTFunctionCallExpression(); } /** @@ -1655,7 +1656,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * @return */ protected IASTIdExpression createIdExpression() { - return new CASTIdExpression(); + return new CPPASTIdExpression(); } protected ITokenDuple idExpression() throws EndOfFileException, BacktrackException @@ -2350,7 +2351,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * @return */ protected ICPPASTQualifiedName createQualifiedName(ITokenDuple duple) { - CPPASTName result = new CPPASTName(); + CPPASTQualifiedName result = new CPPASTQualifiedName(); result.setOffset( duple.getStartOffset()); ITokenDuple [] segments = duple.getSegments(); for( int i = 0; i < segments.length; ++i ) @@ -2377,8 +2378,35 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * @param duple * @return */ - private IASTName createTemplateID(ITokenDuple duple) { - return new CASTName(); //TODO - what is a template ID? + protected ICPPASTTemplateId createTemplateID(ITokenDuple duple) { + ICPPASTTemplateId result = new CPPASTTemplateId(); + ((ASTNode)result).setOffset( duple.getStartOffset() ); + char [] image = duple.extractNameFromTemplateId(); + CPPASTName templateIdName = (CPPASTName) createName(); + templateIdName.setOffset(duple.getStartOffset()); + templateIdName.setName( image ); + result.setTemplateName( templateIdName ); + templateIdName.setParent( result ); + templateIdName.setPropertyInParent( ICPPASTTemplateId.TEMPLATE_NAME ); + if( duple.getTemplateIdArgLists() != null ) + { + List args = duple.getTemplateIdArgLists()[0]; + if( args != null ) + for( int i = 0; i < args.size(); ++i ) + { + IASTNode n = (IASTNode) args.get(i); + if( n instanceof IASTTypeId || n instanceof IASTExpression ) + { + n.setParent( result ); + n.setPropertyInParent( ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT ); + if( n instanceof IASTTypeId ) + result.addTemplateArgument((IASTTypeId) n); + else + result.addTemplateArgument((IASTExpression)n); + } + } + } + return result; } /** @@ -2388,7 +2416,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { protected IASTName createName(ITokenDuple duple) { if( duple == null ) return createName(); if( duple.getSegmentCount() != 1 ) return createQualifiedName( duple ); - CASTName name = new CASTName( duple.toCharArray() ); + CPPASTName name = new CPPASTName( duple.toCharArray() ); name.setOffset( duple.getStartOffset()); return name; } @@ -2553,14 +2581,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * @return */ protected IASTFunctionDefinition createFunctionDefinition() { - return new CASTFunctionDefinition(); + return new CPPASTFunctionDefinition(); } /** * @return */ protected IASTSimpleDeclaration createSimpleDeclaration() { - return new CASTSimpleDeclaration(); + return new CPPASTSimpleDeclaration(); } /** @@ -3258,14 +3286,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * @return */ protected IASTInitializerList createInitializerList() { - return new CASTInitializerList(); + return new CPPASTInitializerList(); } /** * @return */ private IASTInitializerExpression createInitializerExpression() { - return new CASTInitializerExpresion(); + return new CPPASTInitializerExpresion(); } /** @@ -3599,7 +3627,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * @return */ private IASTFieldDeclarator createFieldDeclarator() { - return new CASTFieldDeclarator(); + return new CPPASTFieldDeclarator(); } /** @@ -4100,7 +4128,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * @return */ protected IASTTranslationUnit createTranslationUnit() { - return new CASTTranslationUnit(); + return new CPPASTTranslationUnit(); } protected void consumeArrayModifiers(List collection) throws EndOfFileException, BacktrackException { @@ -4143,63 +4171,63 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createCompoundStatement() */ protected IASTCompoundStatement createCompoundStatement() { - return new CASTCompoundStatement(); + return new CPPASTCompoundStatement(); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createBinaryExpression() */ protected IASTBinaryExpression createBinaryExpression() { - return new CASTBinaryExpression(); + return new CPPASTBinaryExpression(); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createConditionalExpression() */ protected IASTConditionalExpression createConditionalExpression() { - return new CASTConditionalExpression(); + return new CPPASTConditionalExpression(); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createUnaryExpression() */ protected IASTUnaryExpression createUnaryExpression() { - return new CASTUnaryExpression(); + return new CPPASTUnaryExpression(); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createCompoundStatementExpression() */ protected IGNUASTCompoundStatementExpression createCompoundStatementExpression() { - return new CASTCompoundStatementExpression(); + return new CPPASTCompoundStatementExpression(); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createExpressionList() */ protected IASTExpressionList createExpressionList() { - return new CASTExpressionList(); + return new CPPASTExpressionList(); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createName(org.eclipse.cdt.core.parser.IToken) */ protected IASTName createName(IToken token) { - return new CASTName( token.getCharImage() ); + return new CPPASTName( token.getCharImage() ); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createName() */ protected IASTName createName() { - return new CASTName(); + return new CPPASTName(); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createEnumerator() */ protected IASTEnumerator createEnumerator() { - return new CASTEnumerator(); + return new CPPASTEnumerator(); } /* (non-Javadoc) @@ -4219,7 +4247,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * @return */ protected IASTTypeIdExpression createTypeIdExpression() { - return new CASTTypeIdExpression(); + return new CPPASTTypeIdExpression(); } /* (non-Javadoc) @@ -4229,5 +4257,372 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return new CPPASTEnumerationSpecifier(); } + /** + * @return + */ + protected IASTLabelStatement createLabelStatement() { + return new CPPASTLabelStatement(); + } + + /** + * @return + */ + protected IASTGotoStatement createGoToStatement() { + return new CPPASTGotoStatement(); + } + + /** + * @return + */ + protected IASTReturnStatement createReturnStatement() { + return new CPPASTReturnStatement(); + } + + /** + * @return + */ + protected IASTForStatement createForStatement() { + return new CPPASTForStatement(); + } + + /** + * @return + */ + protected IASTContinueStatement createContinueStatement() { + return new CPPASTContinueStatement(); + } + + /** + * @return + */ + protected IASTDoStatement createDoStatement() { + return new CPPASTDoStatement(); + } + + /** + * @return + */ + protected IASTBreakStatement createBreakStatement() { + return new CPPASTBreakStatement(); + } + + /** + * @return + */ + protected IASTWhileStatement createWhileStatement() { + return new CPPASTWhileStatement(); + } + + /** + * @return + */ + protected IASTNullStatement createNullStatement() { + return new CPPASTNullStatement(); + } + + /** + * @return + */ + protected IASTSwitchStatement createSwitchStatement() { + return new CPPASTSwitchStatement(); + } + + /** + * @return + */ + protected IASTIfStatement createIfStatement() { + return new CPPASTIfStatement(); + } + + /** + * @return + */ + protected IASTDefaultStatement createDefaultStatement() { + return new CPPASTDefaultStatement(); + } + + /** + * @return + */ + protected IASTCaseStatement createCaseStatement() { + return new CPPASTCaseStatement(); + } + + /** + * @return + */ + protected IASTExpressionStatement createExpressionStatement() { + return new CPPASTExpressionStatement(); + } + + /** + * @return + */ + protected IASTDeclarationStatement createDeclarationStatement() { + return new CPPASTDeclarationStatement(); + } + + /** + * @return + */ + protected IASTASMDeclaration createASMDirective() { + return new CPPASTASMDeclaration(); + } + + /** + * @return + */ + protected IASTCastExpression createCastExpression() { + return new CPPASTCastExpression(); + } + + protected IASTStatement statement() throws EndOfFileException, BacktrackException { + + switch (LT(1)) { + // labeled statements + case IToken.t_case: + int startOffset = consume(IToken.t_case).getOffset(); + IASTExpression case_exp = constantExpression(); + consume(IToken.tCOLON); + cleanupLastToken(); + IASTCaseStatement cs = createCaseStatement(); + ((ASTNode)cs).setOffset( startOffset ); + cs.setExpression( case_exp ); + case_exp.setParent( cs ); + case_exp.setPropertyInParent( IASTCaseStatement.EXPRESSION ); + return cs; + case IToken.t_default: + startOffset = consume(IToken.t_default).getOffset(); + consume(IToken.tCOLON); + cleanupLastToken(); + IASTDefaultStatement df = createDefaultStatement(); + ((ASTNode)df).setOffset( startOffset ); + return df; + // compound statement + case IToken.tLBRACE: + IASTCompoundStatement compound = compoundStatement(); + cleanupLastToken(); + return compound; + // selection statement + case IToken.t_if: + startOffset = consume(IToken.t_if).getOffset(); + consume(IToken.tLPAREN); + IASTExpression if_condition = condition(); + consume(IToken.tRPAREN); + IASTStatement then_clause = statement(); + IASTStatement else_clause = null; + if (LT(1) == IToken.t_else) { + consume(IToken.t_else); + else_clause = statement(); + } + + IASTIfStatement if_stmt = createIfStatement(); + if_stmt.setCondition( if_condition ); + ((ASTNode)if_stmt).setOffset( startOffset ); + if_condition.setParent( if_stmt ); + if_condition.setPropertyInParent( IASTIfStatement.CONDITION ); + if_stmt.setThenClause( then_clause ); + then_clause.setParent( if_stmt ); + then_clause.setPropertyInParent( IASTIfStatement.THEN ); + if( else_clause != null ) + { + if_stmt.setElseClause( else_clause ); + else_clause.setParent( if_stmt ); + else_clause.setPropertyInParent( IASTIfStatement.ELSE ); + } + cleanupLastToken(); + return if_stmt; + case IToken.t_switch: + startOffset = consume( IToken.t_switch ).getOffset(); + consume(IToken.tLPAREN); + IASTExpression switch_condition = condition(); + consume(IToken.tRPAREN); + IASTStatement switch_body = statement(); + cleanupLastToken(); + IASTSwitchStatement switch_statement = createSwitchStatement(); + ((ASTNode)switch_statement).setOffset( startOffset ); + switch_statement.setController( switch_condition ); + switch_condition.setParent( switch_statement ); + switch_condition.setPropertyInParent( IASTSwitchStatement.CONTROLLER ); + switch_statement.setBody( switch_body ); + switch_body.setParent( switch_statement ); + switch_body.setPropertyInParent( IASTSwitchStatement.BODY ); + return switch_statement; + //iteration statements + case IToken.t_while: + startOffset = consume(IToken.t_while).getOffset(); + consume(IToken.tLPAREN); + IASTExpression while_condition = condition(); + consume(IToken.tRPAREN); + IASTStatement while_body = statement(); + cleanupLastToken(); + IASTWhileStatement while_statement = createWhileStatement(); + ((ASTNode)while_statement).setOffset( startOffset ); + while_statement.setCondition( while_condition ); + while_condition.setParent( while_statement ); + while_condition.setPropertyInParent( IASTWhileStatement.CONDITION ); + while_statement.setBody( while_body ); + while_condition.setParent( while_statement ); + while_condition.setPropertyInParent( IASTWhileStatement.BODY ); + while_body.setParent( while_statement ); + return while_statement; + case IToken.t_do: + startOffset = consume(IToken.t_do).getOffset(); + IASTStatement do_body = statement(); + consume(IToken.t_while); + consume(IToken.tLPAREN); + IASTExpression do_condition = condition(); + consume(IToken.tRPAREN); + cleanupLastToken(); + IASTDoStatement do_statement = createDoStatement(); + ((ASTNode)do_statement).setOffset( startOffset ); + do_statement.setBody( do_body ); + do_body.setParent( do_statement ); + do_body.setPropertyInParent( IASTDoStatement.BODY ); + do_statement.setCondition( do_condition ); + do_condition.setParent( do_statement ); + do_condition.setPropertyInParent( IASTDoStatement.CONDITION ); + return do_statement; + case IToken.t_for: + startOffset = consume( IToken.t_for ).getOffset(); + consume(IToken.tLPAREN); + IASTNode init = forInitStatement(); + IASTExpression for_condition = null; + if (LT(1) != IToken.tSEMI) + for_condition = condition(); + consume(IToken.tSEMI); + IASTExpression iterationExpression = null; + if (LT(1) != IToken.tRPAREN) { + iterationExpression = expression(); + cleanupLastToken(); + } + consume(IToken.tRPAREN); + IASTStatement for_body = statement(); + cleanupLastToken(); + IASTForStatement for_statement = createForStatement(); + ((ASTNode)for_statement).setOffset( startOffset ); + if( init instanceof IASTDeclaration ) + { + for_statement.setInit((IASTDeclaration) init); + ((IASTDeclaration) init).setParent( for_statement ); + ((IASTDeclaration) init).setPropertyInParent( IASTForStatement.INITDECLARATION ); + } + else if( init instanceof IASTExpression ) + { + for_statement.setInit((IASTExpression) init); + ((IASTExpression) init).setParent( for_statement ); + ((IASTExpression) init).setPropertyInParent( IASTForStatement.INITEXPRESSION ); + } + if( for_condition != null ) + { + for_statement.setCondition( for_condition ); + for_condition.setParent( for_statement ); + for_condition.setPropertyInParent( IASTForStatement.CONDITION ); + } + if( iterationExpression != null ) + { + for_statement.setIterationExpression( iterationExpression ); + iterationExpression.setParent( for_statement ); + iterationExpression.setPropertyInParent( IASTForStatement.ITERATION ); + } + for_statement.setBody( for_body ); + for_body.setParent( for_statement ); + for_body.setPropertyInParent( IASTForStatement.BODY ); + return for_statement; + //jump statement + case IToken.t_break: + startOffset = consume(IToken.t_break).getOffset(); + consume(IToken.tSEMI); + cleanupLastToken(); + IASTBreakStatement break_statement = createBreakStatement(); + ((ASTNode)break_statement).setOffset( startOffset ); + return break_statement; + case IToken.t_continue: + startOffset = consume(IToken.t_continue).getOffset(); + consume(IToken.tSEMI); + cleanupLastToken(); + IASTContinueStatement continue_statement = createContinueStatement(); + ((ASTNode)continue_statement).setOffset( startOffset ); + return continue_statement; + case IToken.t_return: + startOffset = consume(IToken.t_return).getOffset(); + IASTExpression result = null; + if (LT(1) != IToken.tSEMI) { + result = expression(); + cleanupLastToken(); + } + consume(IToken.tSEMI); + cleanupLastToken(); + IASTReturnStatement return_statement = createReturnStatement(); + ((ASTNode)return_statement).setOffset( startOffset ); + if( result != null ) + { + return_statement.setReturnValue( result ); + result.setParent( return_statement ); + result.setPropertyInParent( IASTReturnStatement.RETURNVALUE ); + } + return return_statement; + case IToken.t_goto: + startOffset = consume(IToken.t_goto).getOffset(); + IToken identifier = consume(IToken.tIDENTIFIER); + consume(IToken.tSEMI); + cleanupLastToken(); + IASTName goto_label_name = createName( identifier ); + IASTGotoStatement goto_statement = createGoToStatement(); + ((ASTNode)goto_statement).setOffset( startOffset ); + goto_statement.setName( goto_label_name ); + goto_label_name.setParent( goto_statement ); + goto_label_name.setPropertyInParent( IASTGotoStatement.NAME ); + return goto_statement; + case IToken.tSEMI: + startOffset = consume(IToken.tSEMI ).getOffset(); + cleanupLastToken(); + IASTNullStatement null_statement = createNullStatement(); + ((ASTNode)null_statement).setOffset( startOffset ); + return null_statement; + default: + // can be many things: + // label + if (LT(1) == IToken.tIDENTIFIER && LT(2) == IToken.tCOLON) { + IToken labelName = consume(IToken.tIDENTIFIER); + consume(IToken.tCOLON); + IASTLabelStatement label_statement = createLabelStatement(); + ((ASTNode)label_statement).setOffset( labelName.getOffset() ); + IASTName name = createName( labelName ); + label_statement.setName( name ); + name.setParent( label_statement ); + name.setPropertyInParent( IASTLabelStatement.NAME ); + return label_statement; + } + // expressionStatement + // Note: the function style cast ambiguity is handled in + // expression + // Since it only happens when we are in a statement + IToken mark = mark(); + try { + IASTExpression expression = expression(); + consume(IToken.tSEMI); + IASTExpressionStatement expressionStatement = createExpressionStatement(); + expressionStatement.setExpression( expression ); + expression.setParent( expressionStatement ); + expression.setPropertyInParent( IASTExpressionStatement.EXPFRESSION ); + cleanupLastToken(); + return expressionStatement; + } catch (BacktrackException b) { + backup(mark); + } + + // declarationStatement + IASTDeclaration d = declaration(); + IASTDeclarationStatement ds = createDeclarationStatement(); + ds.setDeclaration(d); + d.setParent( ds ); + d.setPropertyInParent( IASTDeclarationStatement.DECLARATION ); + cleanupLastToken(); + return ds; + } + + } + } \ No newline at end of file