diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java index f4109ac8784..1d5744f71e7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java @@ -9,8 +9,6 @@ * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.dom.parser; -import java.util.List; - import org.eclipse.cdt.core.dom.ast.ASTCompletionNode; import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; @@ -2058,11 +2056,10 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { * @param declarators * @return */ - protected int figureEndOffset(IASTDeclSpecifier declSpec, List declarators) { - if (declarators.isEmpty()) + protected int figureEndOffset(IASTDeclSpecifier declSpec, IASTDeclarator [] declarators) { + if (declarators.length == 0 ) return calculateEndOffset(declSpec); - return calculateEndOffset((IASTDeclarator) declarators.get(declarators - .size() - 1)); + return calculateEndOffset(declarators[ declarators.length - 1 ] ); } /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java index 0e27ef08368..f27a0d6f4b1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java @@ -94,6 +94,7 @@ import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.ParseError; import org.eclipse.cdt.core.parser.ParserMode; +import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser; @@ -106,8 +107,6 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { private final boolean supportGCCStyleDesignators; - private static final int DEFAULT_DECLARATOR_LIST_SIZE = 4; - /** * @param scanner * @param parserMode @@ -433,16 +432,16 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { IASTDeclSpecifier declSpec = declSpecifierSeq(false); - List declarators = Collections.EMPTY_LIST; + IASTDeclarator [] declarators = new IASTDeclarator[2]; if (LT(1) != IToken.tSEMI) { - declarators = new ArrayList(DEFAULT_DECLARATOR_LIST_SIZE); - declarators.add(initDeclarator()); + declarators = (IASTDeclarator[]) ArrayUtil.append( IASTDeclarator.class, declarators, initDeclarator()); while (LT(1) == IToken.tCOMMA) { consume(IToken.tCOMMA); - declarators.add(initDeclarator()); + declarators = (IASTDeclarator[]) ArrayUtil.append( IASTDeclarator.class, declarators, initDeclarator()); } } + declarators = (IASTDeclarator[]) ArrayUtil.removeNulls( IASTDeclarator.class, declarators ); boolean hasFunctionBody = false; boolean hasFunctionTryBlock = false; @@ -470,10 +469,10 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { } if (hasFunctionBody) { - if (declarators.size() != 1) + if (declarators.length != 1) throwBacktrack(firstOffset, LA(1).getEndOffset()); - IASTDeclarator declarator = (IASTDeclarator) declarators.get(0); + IASTDeclarator declarator = declarators[0]; if (!(declarator instanceof IASTFunctionDeclarator)) throwBacktrack(firstOffset, LA(1).getEndOffset()); @@ -508,8 +507,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { declSpec.setParent(simpleDeclaration); declSpec.setPropertyInParent(IASTSimpleDeclaration.DECL_SPECIFIER); - for (int i = 0; i < declarators.size(); ++i) { - IASTDeclarator declarator = (IASTDeclarator) declarators.get(i); + for (int i = 0; i < declarators.length; ++i) { + IASTDeclarator declarator = declarators[i]; simpleDeclaration.addDeclarator(declarator); declarator.setParent(simpleDeclaration); declarator.setPropertyInParent(IASTSimpleDeclaration.DECLARATOR); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java index ed31dff855f..7fcb5b8da8d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java @@ -131,6 +131,7 @@ import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.ParseError; import org.eclipse.cdt.core.parser.ParserMode; +import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser; import org.eclipse.cdt.internal.core.dom.parser.BacktrackException; @@ -1860,7 +1861,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private final boolean supportLongLong; private static final int DEFAULT_PARM_LIST_SIZE = 4; - private static final int DEFAULT_DECLARATOR_LIST_SIZE = 4; private static final int DEFAULT_POINTEROPS_LIST_SIZE = 4; private static final int DEFAULT_SIZE_EXCEPTIONS_LIST = 2; private static final int DEFAULT_CONSTRUCTOR_CHAIN_LIST_SIZE = 4; @@ -2697,16 +2697,17 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { ICPPASTDeclSpecifier declSpec = declSpecifierSeq(false, strategy == SimpleDeclarationStrategy.TRY_CONSTRUCTOR); - List declarators = Collections.EMPTY_LIST; + IASTDeclarator [] declarators = new IASTDeclarator[2]; if (LT(1) != IToken.tSEMI && LT(1) != IToken.tEOC) { - declarators = new ArrayList(DEFAULT_DECLARATOR_LIST_SIZE); - declarators.add(initDeclarator(strategy)); + declarators = (IASTDeclarator []) ArrayUtil.append( IASTDeclarator.class, declarators,initDeclarator(strategy) ); while (LT(1) == IToken.tCOMMA) { consume(IToken.tCOMMA); - declarators.add(initDeclarator(strategy)); + declarators = (IASTDeclarator []) ArrayUtil.append( IASTDeclarator.class, declarators,initDeclarator(strategy) ); } } + declarators = (IASTDeclarator[]) ArrayUtil.removeNulls( IASTDeclarator.class, declarators ); + boolean hasFunctionBody = false; boolean hasFunctionTryBlock = false; boolean consumedSemi = false; @@ -2756,10 +2757,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } if (hasFunctionBody) { - if (declarators.size() != 1) + if (declarators.length != 1) throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset); - IASTDeclarator declarator = (IASTDeclarator) declarators.get(0); + IASTDeclarator declarator = declarators[0]; if (!(declarator instanceof IASTStandardFunctionDeclarator)) throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset); @@ -2835,8 +2836,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { declSpec.setParent(simpleDeclaration); declSpec.setPropertyInParent(IASTSimpleDeclaration.DECL_SPECIFIER); - for (int i = 0; i < declarators.size(); ++i) { - IASTDeclarator declarator = (IASTDeclarator) declarators.get(i); + for (int i = 0; i < declarators.length; ++i) { + IASTDeclarator declarator = declarators[i]; simpleDeclaration.addDeclarator(declarator); declarator.setParent(simpleDeclaration); declarator.setPropertyInParent(IASTSimpleDeclaration.DECLARATOR);