From 3bdeb43cf3ff0e99e61c85063651849d3a8c8722 Mon Sep 17 00:00:00 2001 From: John Camelon Date: Thu, 28 Apr 2005 15:55:18 +0000 Subject: [PATCH] Fixed Bug 92806 - Clean up C & C++ Syntax AST Nodes for array usage. --- .../dom/parser/c/CASTArrayDeclarator.java | 35 +----- .../parser/c/CASTCompositeTypeSpecifier.java | 38 +------ .../dom/parser/c/CASTCompoundStatement.java | 45 ++------ .../core/dom/parser/c/CASTDeclarator.java | 34 +----- .../parser/c/CASTDesignatedInitializer.java | 34 +----- .../parser/c/CASTEnumerationSpecifier.java | 34 +----- .../core/dom/parser/c/CASTExpressionList.java | 47 ++------ .../dom/parser/c/CASTFunctionDeclarator.java | 37 +------ .../dom/parser/c/CASTInitializerList.java | 40 +------ .../dom/parser/c/CASTSimpleDeclaration.java | 34 +----- .../dom/parser/c/CASTTranslationUnit.java | 40 +------ .../core/dom/parser/c/GNUCSourceParser.java | 25 +---- .../dom/parser/cpp/CPPASTArrayDeclarator.java | 36 +----- .../cpp/CPPASTCompositeTypeSpecifier.java | 68 +----------- .../parser/cpp/CPPASTCompoundStatement.java | 50 ++------- .../core/dom/parser/cpp/CPPASTDeclarator.java | 34 +----- .../cpp/CPPASTEnumerationSpecifier.java | 34 +----- .../dom/parser/cpp/CPPASTExpressionList.java | 48 ++------ .../parser/cpp/CPPASTFunctionDeclarator.java | 104 ++---------------- .../cpp/CPPASTFunctionTryBlockDeclarator.java | 35 +----- .../dom/parser/cpp/CPPASTInitializerList.java | 38 +------ .../cpp/CPPASTLinkageSpecification.java | 36 +----- .../parser/cpp/CPPASTNamespaceDefinition.java | 39 +------ .../dom/parser/cpp/CPPASTNewExpression.java | 43 ++------ .../dom/parser/cpp/CPPASTQualifiedName.java | 33 +----- .../parser/cpp/CPPASTSimpleDeclaration.java | 34 +----- .../parser/cpp/CPPASTTemplateDeclaration.java | 34 +----- .../core/dom/parser/cpp/CPPASTTemplateId.java | 56 ++-------- .../CPPASTTemplatedTypeTemplateParameter.java | 33 +----- .../dom/parser/cpp/CPPASTTranslationUnit.java | 40 +------ .../parser/cpp/CPPASTTryBlockStatement.java | 34 +----- 31 files changed, 147 insertions(+), 1125 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDeclarator.java index 6b5cdd8cc61..3a436b42fd0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDeclarator.java @@ -13,54 +13,25 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTInitializer; +import org.eclipse.cdt.core.parser.util.ArrayUtil; /** * @author jcamelon */ public class CASTArrayDeclarator extends CASTDeclarator implements IASTArrayDeclarator { - - private int currentIndex = 0; - private void removeNullArrayModifiers() { - int nullCount = 0; - for( int i = 0; i < arrayMods.length; ++i ) - if( arrayMods[i] == null ) - ++nullCount; - if( nullCount == 0 ) return; - IASTArrayModifier [] old = arrayMods; - int newSize = old.length - nullCount; - arrayMods = new IASTArrayModifier[ newSize ]; - for( int i = 0; i < newSize; ++i ) - arrayMods[i] = old[i]; - currentIndex = newSize; - } - private IASTArrayModifier [] arrayMods = null; - private static final int DEFAULT_ARRAYMODS_LIST_SIZE = 4; public IASTArrayModifier[] getArrayModifiers() { if( arrayMods == null ) return IASTArrayModifier.EMPTY_ARRAY; - removeNullArrayModifiers(); - return arrayMods; + return (IASTArrayModifier[]) ArrayUtil.removeNulls( IASTArrayModifier.class, arrayMods ); } public void addArrayModifier(IASTArrayModifier arrayModifier) { - if( arrayMods == null ) - { - arrayMods = new IASTArrayModifier[ DEFAULT_ARRAYMODS_LIST_SIZE ]; - currentIndex = 0; - } - if( arrayMods.length == currentIndex ) - { - IASTArrayModifier [] old = arrayMods; - arrayMods = new IASTArrayModifier[ old.length * 2 ]; - for( int i = 0; i < old.length; ++i ) - arrayMods[i] = old[i]; - } - arrayMods[ currentIndex++ ] = arrayModifier; + arrayMods = (IASTArrayModifier[]) ArrayUtil.append( IASTArrayModifier.class, arrayMods, arrayModifier ); } protected boolean postAccept( ASTVisitor action ){ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompositeTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompositeTypeSpecifier.java index e9b2197a1eb..e268151de4e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompositeTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompositeTypeSpecifier.java @@ -14,6 +14,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier; +import org.eclipse.cdt.core.parser.util.ArrayUtil; /** * @author jcamelon @@ -53,55 +54,26 @@ public class CASTCompositeTypeSpecifier extends CASTBaseDeclSpecifier implements this.name = name; } - private int currentIndex = 0; + private IASTDeclaration [] declarations = null; private IScope scope = null; - private static final int DEFAULT_DECLARATIONS_LIST_SIZE = 4; + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier#getMembers() */ public IASTDeclaration [] getMembers() { if( declarations == null ) return IASTDeclaration.EMPTY_DECLARATION_ARRAY; - removeNullDeclarations(); - return declarations; + return (IASTDeclaration[]) ArrayUtil.removeNulls( IASTDeclaration.class, declarations ); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier#addMemberDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration) */ public void addMemberDeclaration(IASTDeclaration declaration) { - if( declarations == null ) - { - declarations = new IASTDeclaration[ DEFAULT_DECLARATIONS_LIST_SIZE ]; - currentIndex = 0; - } - if( declarations.length == currentIndex ) - { - IASTDeclaration [] old = declarations; - declarations = new IASTDeclaration[ old.length * 2 ]; - for( int i = 0; i < old.length; ++i ) - declarations[i] = old[i]; - } - declarations[ currentIndex++ ] = declaration; + declarations = (IASTDeclaration[]) ArrayUtil.append( IASTDeclaration.class, declarations, declaration ); } - /** - * @param decls2 - */ - private void removeNullDeclarations() { - int nullCount = 0; - for( int i = 0; i < declarations.length; ++i ) - if( declarations[i] == null ) - ++nullCount; - if( nullCount == 0 ) return; - IASTDeclaration [] old = declarations; - int newSize = old.length - nullCount; - declarations = new IASTDeclaration[ newSize ]; - for( int i = 0; i < newSize; ++i ) - declarations[i] = old[i]; - currentIndex = newSize; - } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier#getScope() diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatement.java index 602395a0c8f..1731232e319 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatement.java @@ -14,6 +14,7 @@ import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** @@ -22,25 +23,10 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; public class CASTCompoundStatement extends CASTNode implements IASTCompoundStatement, IASTAmbiguityParent { - 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 IScope scope = null; - private static final int DEFAULT_STATEMENT_LIST_SIZE = 8; /* (non-Javadoc) @@ -48,27 +34,14 @@ public class CASTCompoundStatement extends CASTNode implements */ public IASTStatement[] getStatements() { if( statements == null ) return IASTStatement.EMPTY_STATEMENT_ARRAY; - removeNullStatements(); - return statements; + return (IASTStatement[]) ArrayUtil.removeNulls( IASTStatement.class, 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; + statements = (IASTStatement[]) ArrayUtil.append( IASTStatement.class, statements, statement ); } /* (non-Javadoc) @@ -96,14 +69,14 @@ public class CASTCompoundStatement extends CASTNode implements } public void replace(IASTNode child, IASTNode other) { - IASTStatement [] s = getStatements(); - for( int i = 0; i < s.length; ++i ) + if( statements == null ) return; + for( int i = 0; i < statements.length; ++i ) { - if( s[i] == child ) + if( statements[i] == child ) { - other.setParent( s[i].getParent() ); - other.setPropertyInParent( s[i].getPropertyInParent() ); - s[i] = (IASTStatement) other; + other.setParent( statements[i].getParent() ); + other.setPropertyInParent( statements[i].getPropertyInParent() ); + statements[i] = (IASTStatement) other; break; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java index f4b3b0fc040..822769c8367 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java @@ -17,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.parser.util.ArrayUtil; /** * @author jcamelon @@ -27,22 +28,7 @@ public class CASTDeclarator extends CASTNode implements IASTDeclarator { private IASTName name; private IASTDeclarator nestedDeclarator; private IASTPointerOperator [] pointerOps = null; - private static final int DEFAULT_PTROPS_LIST_SIZE = 2; - private int currentIndex; - private void removeNullPointers() { - int nullCount = 0; - for( int i = 0; i < pointerOps.length; ++i ) - if( pointerOps[i] == null ) - ++nullCount; - if( nullCount == 0 ) return; - IASTPointerOperator [] old = pointerOps; - int newSize = old.length - nullCount; - pointerOps = new IASTPointerOperator[ newSize ]; - for( int i = 0; i < newSize; ++i ) - pointerOps[i] = old[i]; - currentIndex = newSize; - } /* (non-Javadoc) @@ -50,8 +36,7 @@ public class CASTDeclarator extends CASTNode implements IASTDeclarator { */ public IASTPointerOperator[] getPointerOperators() { if( pointerOps == null ) return IASTPointerOperator.EMPTY_ARRAY; - removeNullPointers(); - return pointerOps; + return (IASTPointerOperator[]) ArrayUtil.removeNulls( IASTPointerOperator.class, pointerOps ); } /* (non-Javadoc) @@ -86,19 +71,8 @@ public class CASTDeclarator extends CASTNode implements IASTDeclarator { * @see org.eclipse.cdt.core.dom.ast.IASTDeclarator#addPointerOperator(org.eclipse.cdt.core.dom.ast.IASTPointerOperator) */ public void addPointerOperator(IASTPointerOperator operator) { - if( pointerOps == null ) - { - pointerOps = new IASTPointerOperator[ DEFAULT_PTROPS_LIST_SIZE ]; - currentIndex = 0; - } - if( pointerOps.length == currentIndex ) - { - IASTPointerOperator [] old = pointerOps; - pointerOps = new IASTPointerOperator[ old.length * 2 ]; - for( int i = 0; i < old.length; ++i ) - pointerOps[i] = old[i]; - } - pointerOps[ currentIndex++ ] = operator; } + pointerOps = (IASTPointerOperator[]) ArrayUtil.append( IASTPointerOperator.class, pointerOps, operator ); + } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IASTDeclarator#setNestedDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDesignatedInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDesignatedInitializer.java index ed5c9f3f1d7..ad6633fc23e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDesignatedInitializer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDesignatedInitializer.java @@ -14,6 +14,7 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer; import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator; +import org.eclipse.cdt.core.parser.util.ArrayUtil; /** * @author jcamelon @@ -27,19 +28,7 @@ public class CASTDesignatedInitializer extends CASTNode implements * @see org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer#addDesignator(org.eclipse.cdt.core.dom.ast.c.ICASTDesignator) */ public void addDesignator(ICASTDesignator designator) { - if( designators == null ) - { - designators = new ICASTDesignator[ DEFAULT_DESIGNATORS_LIST_SIZE ]; - currentIndex = 0; - } - if( designators.length == currentIndex ) - { - ICASTDesignator [] old = designators; - designators = new ICASTDesignator[ old.length * 2 ]; - for( int i = 0; i < old.length; ++i ) - designators[i] = old[i]; - } - designators[ currentIndex++ ] = designator; + designators = (ICASTDesignator[]) ArrayUtil.append( ICASTDesignator.class, designators, designator ); } /* (non-Javadoc) @@ -47,27 +36,10 @@ public class CASTDesignatedInitializer extends CASTNode implements */ public ICASTDesignator[] getDesignators() { if( designators == null ) return ICASTDesignatedInitializer.EMPTY_DESIGNATOR_ARRAY; - removeNullDesignators(); - return designators; + return (ICASTDesignator[]) ArrayUtil.removeNulls( ICASTDesignator.class, designators ); } - private void removeNullDesignators() { - int nullCount = 0; - for( int i = 0; i < designators.length; ++i ) - if( designators[i] == null ) - ++nullCount; - if( nullCount == 0 ) return; - ICASTDesignator [] old = designators; - int newSize = old.length - nullCount; - designators = new ICASTDesignator[ newSize ]; - for( int i = 0; i < newSize; ++i ) - designators[i] = old[i]; - currentIndex = newSize; - } - - private int currentIndex = 0; private ICASTDesignator [] designators = null; - private static final int DEFAULT_DESIGNATORS_LIST_SIZE = 2; /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer#getRHSInitializer() */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerationSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerationSpecifier.java index 4f881311bec..a66f9004877 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerationSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerationSpecifier.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier; +import org.eclipse.cdt.core.parser.util.ArrayUtil; /** * @author jcamelon @@ -25,19 +26,7 @@ public class CASTEnumerationSpecifier extends CASTBaseDeclSpecifier implements * @see org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier#addEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator) */ public void addEnumerator(IASTEnumerator enumerator) { - if( enumerators == null ) - { - enumerators = new IASTEnumerator[ DEFAULT_ENUMERATOR_LIST_SIZE ]; - currentIndex = 0; - } - if( enumerators.length == currentIndex ) - { - IASTEnumerator [] old = enumerators; - enumerators = new IASTEnumerator[ old.length * 2 ]; - for( int i = 0; i < old.length; ++i ) - enumerators[i] = old[i]; - } - enumerators[ currentIndex++ ] = enumerator; + enumerators = (IASTEnumerator[]) ArrayUtil.append( IASTEnumerator.class, enumerators, enumerator ); } /* (non-Javadoc) @@ -45,27 +34,10 @@ public class CASTEnumerationSpecifier extends CASTBaseDeclSpecifier implements */ public IASTEnumerator[] getEnumerators() { if( enumerators == null ) return IASTEnumerator.EMPTY_ENUMERATOR_ARRAY; - removeNullEnumerators(); - return enumerators; + return (IASTEnumerator[]) ArrayUtil.removeNulls( IASTEnumerator.class, enumerators ); } - private void removeNullEnumerators() { - int nullCount = 0; - for( int i = 0; i < enumerators.length; ++i ) - if( enumerators[i] == null ) - ++nullCount; - if( nullCount == 0 ) return; - IASTEnumerator [] old = enumerators; - int newSize = old.length - nullCount; - enumerators = new IASTEnumerator[ newSize ]; - for( int i = 0; i < newSize; ++i ) - enumerators[i] = old[i]; - currentIndex = newSize; - } - - private int currentIndex = 0; private IASTEnumerator [] enumerators = null; - private static final int DEFAULT_ENUMERATOR_LIST_SIZE = 4; /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier#setName(org.eclipse.cdt.core.dom.ast.IASTName) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionList.java index a6815626aa8..b230924378f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionList.java @@ -13,6 +13,7 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpressionList; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** @@ -29,8 +30,7 @@ public class CASTExpressionList extends CASTNode implements IASTExpressionList, public IASTExpression[] getExpressions() { if (expressions == null) return IASTExpression.EMPTY_EXPRESSION_ARRAY; - removeNullExpressions(); - return expressions; + return (IASTExpression[]) ArrayUtil.removeNulls( IASTExpression.class, expressions ); } /* @@ -39,42 +39,11 @@ public class CASTExpressionList extends CASTNode implements IASTExpressionList, * @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; + expressions = (IASTExpression[]) ArrayUtil.append( IASTExpression.class, expressions, 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; + private IASTExpression [] expressions = new IASTExpression[2]; public boolean accept(ASTVisitor action) { if (action.shouldVisitExpressions) { @@ -97,12 +66,12 @@ public class CASTExpressionList extends CASTNode implements IASTExpressionList, } public void replace(IASTNode child, IASTNode other) { - IASTExpression[] ez = getExpressions(); - for (int i = 0; i < ez.length; ++i) { - if (child == ez[i]) { + if( expressions == null ) return; + for (int i = 0; i < expressions.length; ++i) { + if (child == expressions[i]) { other.setPropertyInParent(child.getPropertyInParent()); other.setParent(child.getParent()); - ez[i] = (IASTExpression) other; + expressions[i] = (IASTExpression) other; } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java index 8671e92f1b5..899852da79d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; +import org.eclipse.cdt.core.parser.util.ArrayUtil; /** * @author jcamelon @@ -20,27 +21,8 @@ public class CASTFunctionDeclarator extends CASTDeclarator implements IASTStandardFunctionDeclarator { private IASTParameterDeclaration [] parameters = null; - private static final int DEFAULT_PARAMETERS_LIST_SIZE = 2; - - private int currentIndex = 0; private boolean varArgs; - /** - * @param decls2 - */ - private void removeNullParameters() { - int nullCount = 0; - for( int i = 0; i < parameters.length; ++i ) - if( parameters[i] == null ) - ++nullCount; - if( nullCount == 0 ) return; - IASTParameterDeclaration [] old = parameters; - int newSize = old.length - nullCount; - parameters = new IASTParameterDeclaration[ newSize ]; - for( int i = 0; i < newSize; ++i ) - parameters[i] = old[i]; - currentIndex = newSize; - } /* (non-Javadoc) @@ -48,27 +30,14 @@ public class CASTFunctionDeclarator extends CASTDeclarator implements */ public IASTParameterDeclaration[] getParameters() { if( parameters == null ) return IASTParameterDeclaration.EMPTY_PARAMETERDECLARATION_ARRAY; - removeNullParameters(); - return parameters; + return (IASTParameterDeclaration[]) ArrayUtil.removeNulls( IASTParameterDeclaration.class, parameters ); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator#addParameterDeclaration(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration) */ public void addParameterDeclaration(IASTParameterDeclaration parameter) { - if( parameters == null ) - { - parameters = new IASTParameterDeclaration[ DEFAULT_PARAMETERS_LIST_SIZE ]; - currentIndex = 0; - } - if( parameters.length == currentIndex ) - { - IASTParameterDeclaration [] old = parameters; - parameters = new IASTParameterDeclaration[ old.length * 2 ]; - for( int i = 0; i < old.length; ++i ) - parameters[i] = old[i]; - } - parameters[ currentIndex++ ] = parameter; + parameters = (IASTParameterDeclaration[]) ArrayUtil.append( IASTParameterDeclaration.class, parameters, parameter ); } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerList.java index 0c1e782c1a2..ef6276662f1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTInitializerList.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializerList; +import org.eclipse.cdt.core.parser.util.ArrayUtil; /** * @author jcamelon @@ -20,55 +21,20 @@ public class CASTInitializerList extends CASTNode implements IASTInitializerList { - private int currentIndex = 0; - /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration#getDeclarators() */ public IASTInitializer[] getInitializers() { if( initializers == null ) return IASTInitializer.EMPTY_INITIALIZER_ARRAY; - removeNullInitializers(); - return initializers; + return (IASTInitializer[]) ArrayUtil.removeNulls( IASTInitializer.class, 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; - + initializers = (IASTInitializer[]) ArrayUtil.append( IASTInitializer.class, initializers, 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; public boolean accept( ASTVisitor action ){ if( action.shouldVisitInitializers ){ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java index 30fc6e86c3e..c72b235f4f1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java @@ -13,6 +13,7 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.parser.util.ArrayUtil; /** * @author jcamelon @@ -27,51 +28,22 @@ public class CASTSimpleDeclaration extends CASTNode implements return declSpecifier; } - /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration#getDeclarators() */ public IASTDeclarator[] getDeclarators() { if( declarators == null ) return IASTDeclarator.EMPTY_DECLARATOR_ARRAY; - removeNullDeclarators(); - return declarators; + return (IASTDeclarator[]) ArrayUtil.removeNulls( IASTDeclarator.class, 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; + declarators = (IASTDeclarator[]) ArrayUtil.append( IASTDeclarator.class, declarators, 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 = 2; private IASTDeclSpecifier declSpecifier; /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java index 97d27e7b52b..b8a6f158380 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java @@ -36,6 +36,7 @@ import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator; import org.eclipse.cdt.core.parser.ast.IASTEnumerator; +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.ASTPreprocessorSelectionResult; import org.eclipse.cdt.internal.core.dom.parser.IRequiresLocationInformation; @@ -50,10 +51,6 @@ public class CASTTranslationUnit extends CASTNode implements private IASTDeclaration[] decls = null; - private static final int DEFAULT_CHILDREN_LIST_SIZE = 8; - - private int currentIndex = 0; - // Binding private CScope compilationUnit = null; @@ -74,17 +71,7 @@ public class CASTTranslationUnit extends CASTNode implements private static final IASTName[] EMPTY_NAME_ARRAY = new IASTName[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; + decls = (IASTDeclaration[]) ArrayUtil.append( IASTDeclaration.class, decls, d ); } /* @@ -93,29 +80,10 @@ public class CASTTranslationUnit extends CASTNode implements * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations() */ public IASTDeclaration[] getDeclarations() { - if (decls == null) - return IASTDeclaration.EMPTY_DECLARATION_ARRAY; - removeNullDeclarations(); - return decls; + if (decls == null) return IASTDeclaration.EMPTY_DECLARATION_ARRAY; + return (IASTDeclaration[]) ArrayUtil.removeNulls( IASTDeclaration.class, 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) 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 6a9fa627c17..b359fa9244e 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 @@ -1938,7 +1938,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { IASTDeclarator d = null; if (numKnRCParms > 0) { ICASTKnRFunctionDeclarator functionDecltor = createKnRFunctionDeclarator(); - parmDeclarations = removeNullDeclarations(parmDeclarations); + parmDeclarations = (IASTDeclaration[]) ArrayUtil.removeNulls( IASTDeclaration.class, parmDeclarations ); for (int i = 0; i < parmDeclarations.length; ++i) { if (parmDeclarations[i] != null) { parmDeclarations[i].setParent(functionDecltor); @@ -2014,29 +2014,6 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { return d; } - /** - * @param parmDeclarations - * @return - */ - private IASTDeclaration[] removeNullDeclarations( - IASTDeclaration[] parmDeclarations) { - int nullCount = 0; - for (int i = 0; i < parmDeclarations.length; ++i) { - if (parmDeclarations[i] == null) - ++nullCount; - } - if (nullCount == 0) - return parmDeclarations; - IASTDeclaration[] result = new IASTDeclaration[parmDeclarations.length - - nullCount]; - int count = 0; - for (int i = 0; i < parmDeclarations.length; ++i) { - if (parmDeclarations[i] != null) - result[count++] = parmDeclarations[i]; - } - return result; - } - protected IASTArrayDeclarator createArrayDeclarator() { return new CASTArrayDeclarator(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayDeclarator.java index aedb7746130..49432bcda1b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayDeclarator.java @@ -14,54 +14,24 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTInitializer; +import org.eclipse.cdt.core.parser.util.ArrayUtil; /** * @author jcamelon */ public class CPPASTArrayDeclarator extends CPPASTDeclarator implements IASTArrayDeclarator { - - private int currentIndex = 0; - private void removeNullArrayModifiers() { - int nullCount = 0; - for( int i = 0; i < arrayMods.length; ++i ) - if( arrayMods[i] == null ) - ++nullCount; - if( nullCount == 0 ) return; - IASTArrayModifier [] old = arrayMods; - int newSize = old.length - nullCount; - arrayMods = new IASTArrayModifier[ newSize ]; - for( int i = 0; i < newSize; ++i ) - arrayMods[i] = old[i]; - currentIndex = newSize; - } - private IASTArrayModifier [] arrayMods = null; - private static final int DEFAULT_ARRAYMODS_LIST_SIZE = 4; public IASTArrayModifier[] getArrayModifiers() { if( arrayMods == null ) return IASTArrayModifier.EMPTY_ARRAY; - removeNullArrayModifiers(); - return arrayMods; - + return (IASTArrayModifier[]) ArrayUtil.removeNulls( IASTArrayModifier.class, arrayMods ); } public void addArrayModifier(IASTArrayModifier arrayModifier) { - if( arrayMods == null ) - { - arrayMods = new IASTArrayModifier[ DEFAULT_ARRAYMODS_LIST_SIZE ]; - currentIndex = 0; - } - if( arrayMods.length == currentIndex ) - { - IASTArrayModifier [] old = arrayMods; - arrayMods = new IASTArrayModifier[ old.length * 2 ]; - for( int i = 0; i < old.length; ++i ) - arrayMods[i] = old[i]; - } - arrayMods[ currentIndex++ ] = arrayModifier; + arrayMods = (IASTArrayModifier[]) ArrayUtil.append( IASTArrayModifier.class, arrayMods, arrayModifier ); } protected boolean postAccept( ASTVisitor action ){ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java index bd919107035..616d3da56b8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java @@ -15,6 +15,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; +import org.eclipse.cdt.core.parser.util.ArrayUtil; /** * @author jcamelon @@ -38,27 +39,14 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier */ public ICPPASTBaseSpecifier[] getBaseSpecifiers() { if( baseSpecs == null ) return ICPPASTBaseSpecifier.EMPTY_BASESPECIFIER_ARRAY; - removeNullBaseSpecs(); - return baseSpecs; + return (ICPPASTBaseSpecifier[]) ArrayUtil.removeNulls( ICPPASTBaseSpecifier.class, baseSpecs ); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier#addBaseSpecifier(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier) */ public void addBaseSpecifier(ICPPASTBaseSpecifier baseSpec) { - if( baseSpecs == null ) - { - baseSpecs = new ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier[ DEFAULT_DECLARATIONS_LIST_SIZE ]; - currentIndex2 = 0; - } - if( baseSpecs.length == currentIndex ) - { - ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier [] old = baseSpecs; - baseSpecs = new ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier[ old.length * 2 ]; - for( int i = 0; i < old.length; ++i ) - baseSpecs[i] = old[i]; - } - baseSpecs[ currentIndex2++ ] = baseSpec; + baseSpecs = (ICPPASTBaseSpecifier[]) ArrayUtil.append( ICPPASTBaseSpecifier.class, baseSpecs, baseSpec ); } /* (non-Javadoc) @@ -94,8 +82,7 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier */ public IASTDeclaration[] getMembers() { if( declarations == null ) return IASTDeclaration.EMPTY_DECLARATION_ARRAY; - removeNullDeclarations(); - return declarations; + return (IASTDeclaration[]) ArrayUtil.removeNulls( IASTDeclaration.class, declarations ); } @@ -103,54 +90,11 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier * @see org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier#addMemberDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration) */ public void addMemberDeclaration(IASTDeclaration declaration) { - if( declarations == null ) - { - declarations = new IASTDeclaration[ DEFAULT_DECLARATIONS_LIST_SIZE ]; - currentIndex = 0; - } - if( declarations.length == currentIndex ) - { - IASTDeclaration [] old = declarations; - declarations = new IASTDeclaration[ old.length * 2 ]; - for( int i = 0; i < old.length; ++i ) - declarations[i] = old[i]; - } - declarations[ currentIndex++ ] = declaration; + declarations = (IASTDeclaration[]) ArrayUtil.append( IASTDeclaration.class, declarations, declaration ); } - private void removeNullDeclarations() { - int nullCount = 0; - for( int i = 0; i < declarations.length; ++i ) - if( declarations[i] == null ) - ++nullCount; - if( nullCount == 0 ) return; - IASTDeclaration [] old = declarations; - int newSize = old.length - nullCount; - declarations = new IASTDeclaration[ newSize ]; - for( int i = 0; i < newSize; ++i ) - declarations[i] = old[i]; - currentIndex = newSize; - } - private int currentIndex = 0; - private IASTDeclaration [] declarations = null; - private static final int DEFAULT_DECLARATIONS_LIST_SIZE = 4; - - private void removeNullBaseSpecs() { - int nullCount = 0; - for( int i = 0; i < baseSpecs.length; ++i ) - if( baseSpecs[i] == null ) - ++nullCount; - if( nullCount == 0 ) return; - ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier [] old = baseSpecs; - int newSize = old.length - nullCount; - baseSpecs = new ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier[ newSize ]; - for( int i = 0; i < newSize; ++i ) - baseSpecs[i] = old[i]; - currentIndex2 = newSize; - } - - private int currentIndex2 = 0; + private IASTDeclaration [] declarations = new IASTDeclaration[4]; private ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier [] baseSpecs = null; /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java index d3ebca85ffd..9a930d06711 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java @@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; +import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** @@ -24,25 +25,8 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; public class CPPASTCompoundStatement extends CPPASTNode implements IASTCompoundStatement, IASTAmbiguityParent { - 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 IASTStatement [] statements = new IASTStatement[2]; private ICPPScope scope = null; - private static final int DEFAULT_STATEMENT_LIST_SIZE = 8; /* (non-Javadoc) @@ -50,27 +34,14 @@ public class CPPASTCompoundStatement extends CPPASTNode implements */ public IASTStatement[] getStatements() { if( statements == null ) return IASTStatement.EMPTY_STATEMENT_ARRAY; - removeNullStatements(); - return statements; + return (IASTStatement[]) ArrayUtil.removeNulls( IASTStatement.class, 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; + statements = (IASTStatement[]) ArrayUtil.append( IASTStatement.class, statements, statement ); } /* (non-Javadoc) @@ -98,15 +69,14 @@ public class CPPASTCompoundStatement extends CPPASTNode implements } public void replace(IASTNode child, IASTNode other) { - IASTStatement [] s = getStatements(); - for( int i = 0; i < s.length; ++i ) + if( statements == null ) return; + for( int i = 0; i < statements.length; ++i ) { - if( s[i] == child ) + if( statements[i] == child ) { - other.setParent( s[i].getParent() ); - other.setPropertyInParent( s[i].getPropertyInParent() ); - s[i] = (IASTStatement) other; - break; + other.setParent( statements[i].getParent() ); + other.setPropertyInParent( statements[i].getPropertyInParent() ); + statements[i] = (IASTStatement) other; } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java index 4175c83a26e..135540aa572 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java @@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.parser.util.ArrayUtil; /** * @author jcamelon @@ -25,22 +26,7 @@ public class CPPASTDeclarator extends CPPASTNode implements IASTDeclarator { private IASTName name; private IASTDeclarator nestedDeclarator; private IASTPointerOperator [] pointerOps = null; - private static final int DEFAULT_PTROPS_LIST_SIZE = 2; - private int currentIndex; - private void removeNullPointers() { - int nullCount = 0; - for( int i = 0; i < pointerOps.length; ++i ) - if( pointerOps[i] == null ) - ++nullCount; - if( nullCount == 0 ) return; - IASTPointerOperator [] old = pointerOps; - int newSize = old.length - nullCount; - pointerOps = new IASTPointerOperator[ newSize ]; - for( int i = 0; i < newSize; ++i ) - pointerOps[i] = old[i]; - currentIndex = newSize; - } /* (non-Javadoc) @@ -48,8 +34,7 @@ public class CPPASTDeclarator extends CPPASTNode implements IASTDeclarator { */ public IASTPointerOperator[] getPointerOperators() { if( pointerOps == null ) return IASTPointerOperator.EMPTY_ARRAY; - removeNullPointers(); - return pointerOps; + return (IASTPointerOperator[]) ArrayUtil.removeNulls( IASTPointerOperator.class, pointerOps ); } /* (non-Javadoc) @@ -84,19 +69,8 @@ public class CPPASTDeclarator extends CPPASTNode implements IASTDeclarator { * @see org.eclipse.cdt.core.dom.ast.IASTDeclarator#addPointerOperator(org.eclipse.cdt.core.dom.ast.IASTPointerOperator) */ public void addPointerOperator(IASTPointerOperator operator) { - if( pointerOps == null ) - { - pointerOps = new IASTPointerOperator[ DEFAULT_PTROPS_LIST_SIZE ]; - currentIndex = 0; - } - if( pointerOps.length == currentIndex ) - { - IASTPointerOperator [] old = pointerOps; - pointerOps = new IASTPointerOperator[ old.length * 2 ]; - for( int i = 0; i < old.length; ++i ) - pointerOps[i] = old[i]; - } - pointerOps[ currentIndex++ ] = operator; } + pointerOps = (IASTPointerOperator[]) ArrayUtil.append( IASTPointerOperator.class, pointerOps, operator ); + } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IASTDeclarator#setNestedDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java index 7ad2bb5fdcc..9c3b36e6888 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java @@ -14,6 +14,7 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier; +import org.eclipse.cdt.core.parser.util.ArrayUtil; /** * @author jcamelon @@ -29,17 +30,7 @@ public class CPPASTEnumerationSpecifier extends CPPASTBaseDeclSpecifier * @see org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier#addEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator) */ public void addEnumerator(IASTEnumerator enumerator) { - if (enumerators == null) { - enumerators = new IASTEnumerator[DEFAULT_ENUMERATORS_LIST_SIZE]; - currentIndex = 0; - } - if (enumerators.length == currentIndex) { - IASTEnumerator[] old = enumerators; - enumerators = new IASTEnumerator[old.length * 2]; - for (int i = 0; i < old.length; ++i) - enumerators[i] = old[i]; - } - enumerators[currentIndex++] = enumerator; + enumerators = (IASTEnumerator[]) ArrayUtil.append( IASTEnumerator.class, enumerators, enumerator ); } /* @@ -50,31 +41,12 @@ public class CPPASTEnumerationSpecifier extends CPPASTBaseDeclSpecifier public IASTEnumerator[] getEnumerators() { if (enumerators == null) return IASTEnumerator.EMPTY_ENUMERATOR_ARRAY; - removeNullEnumerators(); - return enumerators; + return (IASTEnumerator[]) ArrayUtil.removeNulls( IASTEnumerator.class, enumerators ); } - private void removeNullEnumerators() { - int nullCount = 0; - for (int i = 0; i < enumerators.length; ++i) - if (enumerators[i] == null) - ++nullCount; - if (nullCount == 0) - return; - IASTEnumerator[] old = enumerators; - int newSize = old.length - nullCount; - enumerators = new IASTEnumerator[newSize]; - for (int i = 0; i < newSize; ++i) - enumerators[i] = old[i]; - currentIndex = newSize; - } - - private int currentIndex = 0; private IASTEnumerator[] enumerators = null; - private static final int DEFAULT_ENUMERATORS_LIST_SIZE = 4; - /* * (non-Javadoc) * diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionList.java index 3075040a449..6d6ee2a9383 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionList.java @@ -14,6 +14,7 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpressionList; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** @@ -26,50 +27,17 @@ public class CPPASTExpressionList extends CPPASTNode implements */ public IASTExpression [] getExpressions() { if( expressions == null ) return IASTExpression.EMPTY_EXPRESSION_ARRAY; - removeNullExpressions(); - return expressions; + return (IASTExpression[]) ArrayUtil.removeNulls( IASTExpression.class, 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; + expressions = (IASTExpression [])ArrayUtil.append( IASTExpression.class, expressions, 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; - + private IASTExpression [] expressions = new IASTExpression[2]; public boolean accept( ASTVisitor action ){ if( action.shouldVisitExpressions ){ switch( action.visit( this ) ){ @@ -87,12 +55,12 @@ public class CPPASTExpressionList extends CPPASTNode implements } public void replace(IASTNode child, IASTNode other) { - IASTExpression[] ez = getExpressions(); - for (int i = 0; i < ez.length; ++i) { - if (child == ez[i]) { + if( expressions == null ) return; + for (int i = 0; i < expressions.length; ++i) { + if (child == expressions[i]) { other.setPropertyInParent(child.getPropertyInParent()); other.setParent(child.getParent()); - ez[i] = (IASTExpression) other; + expressions[i] = (IASTExpression) other; } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java index 50d26b89ed4..3b1aa0e1db2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java @@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionScope; +import org.eclipse.cdt.core.parser.util.ArrayUtil; /** * @author jcamelon @@ -28,58 +29,27 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPASTFunctionDeclarator { private IASTParameterDeclaration [] parameters = null; - private static final int DEFAULT_PARAMETERS_LIST_SIZE = 2; private ICPPFunctionScope scope = null; - private int currentIndex = 0; private boolean varArgs; private boolean pureVirtual; private boolean isVolatile; private boolean isConst; - /** - * @param decls2 - */ - private void removeNullParameters() { - int nullCount = 0; - for( int i = 0; i < parameters.length; ++i ) - if( parameters[i] == null ) - ++nullCount; - if( nullCount == 0 ) return; - IASTParameterDeclaration [] old = parameters; - int newSize = old.length - nullCount; - parameters = new IASTParameterDeclaration[ newSize ]; - for( int i = 0; i < newSize; ++i ) - parameters[i] = old[i]; - currentIndex = newSize; - } - + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator#getParameters() */ public IASTParameterDeclaration [] getParameters() { if( parameters == null ) return IASTParameterDeclaration.EMPTY_PARAMETERDECLARATION_ARRAY; - removeNullParameters(); - return parameters; + return (IASTParameterDeclaration[]) ArrayUtil.removeNulls( IASTParameterDeclaration.class, parameters ); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator#addParameterDeclaration(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration) */ public void addParameterDeclaration(IASTParameterDeclaration parameter) { - if( parameters == null ) - { - parameters = new IASTParameterDeclaration[ DEFAULT_PARAMETERS_LIST_SIZE ]; - currentIndex = 0; - } - if( parameters.length == currentIndex ) - { - IASTParameterDeclaration [] old = parameters; - parameters = new IASTParameterDeclaration[ old.length * 2 ]; - for( int i = 0; i < old.length; ++i ) - parameters[i] = old[i]; - } - parameters[ currentIndex++ ] = parameter; + parameters = (IASTParameterDeclaration []) ArrayUtil.append( IASTParameterDeclaration.class, parameters, parameter ); } /* (non-Javadoc) @@ -128,29 +98,13 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements this.isVolatile = value; } - private int currentTypeIdIndex = 0; private IASTTypeId [] typeIds = null; - private static final int DEFAULT_TYPEID_LIST_SIZE = 4; - private void removeNullTypeIds() { - int nullCount = 0; - for( int i = 0; i < typeIds.length; ++i ) - if( typeIds[i] == null ) - ++nullCount; - if( nullCount == 0 ) return; - IASTTypeId [] old = typeIds; - int newSize = old.length - nullCount; - typeIds = new IASTTypeId[ newSize ]; - for( int i = 0; i < newSize; ++i ) - typeIds[i] = old[i]; - currentTypeIdIndex = newSize; - } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator#getExceptionSpecification() */ public IASTTypeId[] getExceptionSpecification() { if( typeIds == null ) return IASTTypeId.EMPTY_TYPEID_ARRAY; - removeNullTypeIds(); - return typeIds; + return (IASTTypeId[]) ArrayUtil.removeNulls( IASTTypeId.class, typeIds ); } @@ -158,19 +112,7 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator#addExceptionSpecificationTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId) */ public void addExceptionSpecificationTypeId(IASTTypeId typeId) { - if( typeIds == null ) - { - typeIds = new IASTTypeId[ DEFAULT_TYPEID_LIST_SIZE ]; - currentTypeIdIndex = 0; - } - if( typeIds.length == currentTypeIdIndex ) - { - IASTTypeId [] old = typeIds; - typeIds = new IASTTypeId[ old.length * 2 ]; - for( int i = 0; i < old.length; ++i ) - typeIds[i] = old[i]; - } - typeIds[ currentTypeIdIndex++ ] = typeId; + typeIds = (IASTTypeId[]) ArrayUtil.append( IASTTypeId.class, typeIds, typeId ); } @@ -190,32 +132,14 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements } - private int currentConstructorChainIndex = 0; private ICPPASTConstructorChainInitializer [] constructorChain = null; - private static final int DEFAULT_CONS_LIST_SIZE = 4; - private void removeNullConstructors() { - int nullCount = 0; - for( int i = 0; i < constructorChain.length; ++i ) - if( constructorChain[i] == null ) - ++nullCount; - if( nullCount == 0 ) return; - ICPPASTConstructorChainInitializer [] old = constructorChain; - int newSize = old.length - nullCount; - constructorChain = new ICPPASTConstructorChainInitializer[ newSize ]; - for( int i = 0; i < newSize; ++i ) - constructorChain[i] = old[i]; - currentConstructorChainIndex = newSize; - } - - /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator#getConstructorChain() */ public ICPPASTConstructorChainInitializer[] getConstructorChain() { if( constructorChain == null ) return ICPPASTConstructorChainInitializer.EMPTY_CONSTRUCTORCHAININITIALIZER_ARRAY; - removeNullConstructors(); - return constructorChain; + return (ICPPASTConstructorChainInitializer[]) ArrayUtil.removeNulls( ICPPASTConstructorChainInitializer.class, constructorChain ); } @@ -223,19 +147,7 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator#addConstructorToChain(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer) */ public void addConstructorToChain(ICPPASTConstructorChainInitializer initializer) { - if( constructorChain == null ) - { - constructorChain = new ICPPASTConstructorChainInitializer[ DEFAULT_CONS_LIST_SIZE ]; - currentConstructorChainIndex = 0; - } - if( constructorChain.length == currentConstructorChainIndex ) - { - ICPPASTConstructorChainInitializer [] old = constructorChain; - constructorChain = new ICPPASTConstructorChainInitializer[ old.length * 2 ]; - for( int i = 0; i < old.length; ++i ) - constructorChain[i] = old[i]; - } - constructorChain[ currentConstructorChainIndex++ ] = initializer; + constructorChain = (ICPPASTConstructorChainInitializer[]) ArrayUtil.append( ICPPASTConstructorChainInitializer.class, constructorChain, initializer ); } public ICPPFunctionScope getFunctionScope(){ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionTryBlockDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionTryBlockDeclarator.java index 9f33d114243..3021350fbdd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionTryBlockDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionTryBlockDeclarator.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator; +import org.eclipse.cdt.core.parser.util.ArrayUtil; /** * @author jcamelon @@ -24,47 +25,19 @@ public class CPPASTFunctionTryBlockDeclarator extends CPPASTFunctionDeclarator * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator#addCatchHandler(org.eclipse.cdt.core.dom.ast.IASTStatement) */ public void addCatchHandler(ICPPASTCatchHandler statement) { - if( catchHandlers == null ) - { - catchHandlers = new ICPPASTCatchHandler[ DEFAULT_CATCH_HANDLER_LIST_SIZE ]; - currentIndex = 0; - } - if( catchHandlers.length == currentIndex ) - { - ICPPASTCatchHandler [] old = catchHandlers; - catchHandlers = new ICPPASTCatchHandler[ old.length * 2 ]; - for( int i = 0; i < old.length; ++i ) - catchHandlers[i] = old[i]; - } - catchHandlers[ currentIndex++ ] = statement; } + catchHandlers = (ICPPASTCatchHandler[]) ArrayUtil.append( ICPPASTCatchHandler.class, catchHandlers, statement ); + } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator#getCatchHandlers() */ public ICPPASTCatchHandler [] getCatchHandlers() { if( catchHandlers == null ) return ICPPASTCatchHandler.EMPTY_CATCHHANDLER_ARRAY; - removeNullCatchHandlers(); - return catchHandlers; + return (ICPPASTCatchHandler[]) ArrayUtil.removeNulls( ICPPASTCatchHandler.class, catchHandlers ); } - private void removeNullCatchHandlers() { - int nullCount = 0; - for( int i = 0; i < catchHandlers.length; ++i ) - if( catchHandlers[i] == null ) - ++nullCount; - if( nullCount == 0 ) return; - ICPPASTCatchHandler [] old = catchHandlers; - int newSize = old.length - nullCount; - catchHandlers = new ICPPASTCatchHandler[ newSize ]; - for( int i = 0; i < newSize; ++i ) - catchHandlers[i] = old[i]; - currentIndex = newSize; - } - private int currentIndex = 0; private ICPPASTCatchHandler [] catchHandlers = null; - private static final int DEFAULT_CATCH_HANDLER_LIST_SIZE = 4; - protected boolean postAccept( ASTVisitor action ){ if( !super.postAccept( action ) ) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java index 92ee1560fa8..867f3da5602 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializerList; +import org.eclipse.cdt.core.parser.util.ArrayUtil; /** * @author jcamelon @@ -20,55 +21,22 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializerList; public class CPPASTInitializerList extends CPPASTNode implements IASTInitializerList { - private int currentIndex = 0; /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration#getDeclarators() */ public IASTInitializer [] getInitializers() { if( initializers == null ) return IASTInitializer.EMPTY_INITIALIZER_ARRAY; - removeNullInitializers(); - return initializers; + return (IASTInitializer[]) ArrayUtil.removeNulls( IASTInitializer.class, 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; - + initializers = (IASTInitializer[]) ArrayUtil.append( IASTInitializer.class, initializers, 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; public boolean accept( ASTVisitor action ){ if( action.shouldVisitInitializers ){ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLinkageSpecification.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLinkageSpecification.java index 3459c6aed09..1a7edc725cb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLinkageSpecification.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLinkageSpecification.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification; +import org.eclipse.cdt.core.parser.util.ArrayUtil; /** * @author jcamelon @@ -40,46 +41,17 @@ public class CPPASTLinkageSpecification extends CPPASTNode implements */ public IASTDeclaration [] getDeclarations() { if( declarations == null ) return IASTDeclaration.EMPTY_DECLARATION_ARRAY; - removeNullDeclarations(); - return declarations; + return (IASTDeclaration[]) ArrayUtil.removeNulls( IASTDeclaration.class, declarations ); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification#addDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration) */ public void addDeclaration(IASTDeclaration declaration) { - if( declarations == null ) - { - declarations = new IASTDeclaration[ DEFAULT_DECLARATIONS_LIST_SIZE ]; - currentIndex = 0; - } - if( declarations.length == currentIndex ) - { - IASTDeclaration [] old = declarations; - declarations = new IASTDeclaration[ old.length * 2 ]; - for( int i = 0; i < old.length; ++i ) - declarations[i] = old[i]; - } - declarations[ currentIndex++ ] = declaration; + declarations = (IASTDeclaration[]) ArrayUtil.append( IASTDeclaration.class, declarations, declaration ); } - private void removeNullDeclarations() { - int nullCount = 0; - for( int i = 0; i < declarations.length; ++i ) - if( declarations[i] == null ) - ++nullCount; - if( nullCount == 0 ) return; - IASTDeclaration [] old = declarations; - int newSize = old.length - nullCount; - declarations = new IASTDeclaration[ newSize ]; - for( int i = 0; i < newSize; ++i ) - declarations[i] = old[i]; - currentIndex = newSize; - } - - private int currentIndex = 0; - private IASTDeclaration [] declarations = null; - private static final int DEFAULT_DECLARATIONS_LIST_SIZE = 4; + private IASTDeclaration [] declarations = new IASTDeclaration[4]; public boolean accept( ASTVisitor action ){ if( action.shouldVisitDeclarations ){ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java index d94c2b07193..dd0345fd51c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java @@ -18,6 +18,7 @@ import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; +import org.eclipse.cdt.core.parser.util.ArrayUtil; /** * @author jcamelon @@ -46,48 +47,18 @@ public class CPPASTNamespaceDefinition extends CPPASTNode implements */ public IASTDeclaration [] getDeclarations() { if( declarations == null ) return IASTDeclaration.EMPTY_DECLARATION_ARRAY; - removeNullDeclarations(); - return declarations; + return (IASTDeclaration[]) ArrayUtil.removeNulls( IASTDeclaration.class, declarations ); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition#addDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration) */ public void addDeclaration(IASTDeclaration declaration) { - if( declarations == null ) - { - declarations = new IASTDeclaration[ DEFAULT_DECLARATIONS_LIST_SIZE ]; - currentIndex = 0; - } - if( declarations.length == currentIndex ) - { - IASTDeclaration [] old = declarations; - declarations = new IASTDeclaration[ old.length * 2 ]; - for( int i = 0; i < old.length; ++i ) - declarations[i] = old[i]; - } - declarations[ currentIndex++ ] = declaration; + declarations = (IASTDeclaration[]) ArrayUtil.append( IASTDeclaration.class, declarations, declaration ); } - private void removeNullDeclarations() { - int nullCount = 0; - for( int i = 0; i < declarations.length; ++i ) - if( declarations[i] == null ) - ++nullCount; - if( nullCount == 0 ) return; - IASTDeclaration [] old = declarations; - int newSize = old.length - nullCount; - declarations = new IASTDeclaration[ newSize ]; - for( int i = 0; i < newSize; ++i ) - declarations[i] = old[i]; - currentIndex = newSize; - } - - private int currentIndex = 0; - private IASTDeclaration [] declarations = null; - private static final int DEFAULT_DECLARATIONS_LIST_SIZE = 4; - - /* (non-Javadoc) + private IASTDeclaration [] declarations = new IASTDeclaration[32]; + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition#getScope() */ public IScope getScope() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java index 841ff2a81ac..2af8bc7189d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNewExpression.java @@ -15,6 +15,7 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression; +import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** @@ -104,46 +105,17 @@ public class CPPASTNewExpression extends CPPASTNode implements */ public IASTExpression [] getNewTypeIdArrayExpressions() { if( arrayExpressions == null ) return IASTExpression.EMPTY_EXPRESSION_ARRAY; - removeNullExpressions(); - return arrayExpressions; + return (IASTExpression[]) ArrayUtil.removeNulls( IASTExpression.class, arrayExpressions ); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression#addNewTypeIdArrayExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) */ public void addNewTypeIdArrayExpression(IASTExpression expression) { - if( arrayExpressions == null ) - { - arrayExpressions = new IASTExpression[ DEFAULT_ARRAY_EXPRESSIONS_LIST_SIZE ]; - currentIndex = 0; - } - if( arrayExpressions.length == currentIndex ) - { - IASTExpression [] old = arrayExpressions; - arrayExpressions = new IASTExpression[ old.length * 2 ]; - for( int i = 0; i < old.length; ++i ) - arrayExpressions[i] = old[i]; - } - arrayExpressions[ currentIndex++ ] = expression; + arrayExpressions = (IASTExpression[]) ArrayUtil.append( IASTExpression.class, arrayExpressions, expression ); } - private void removeNullExpressions() { - int nullCount = 0; - for( int i = 0; i < arrayExpressions.length; ++i ) - if( arrayExpressions[i] == null ) - ++nullCount; - if( nullCount == 0 ) return; - IASTExpression [] old = arrayExpressions; - int newSize = old.length - nullCount; - arrayExpressions = new IASTExpression[ newSize ]; - for( int i = 0; i < newSize; ++i ) - arrayExpressions[i] = old[i]; - currentIndex = newSize; - } - - private int currentIndex = 0; private IASTExpression [] arrayExpressions = null; - private static final int DEFAULT_ARRAY_EXPRESSIONS_LIST_SIZE = 4; public boolean accept( ASTVisitor action ){ if( action.shouldVisitExpressions ){ @@ -178,6 +150,13 @@ public class CPPASTNewExpression extends CPPASTNode implements other.setParent( child.getParent() ); initializer = (IASTExpression) other; } - + if( arrayExpressions == null ) return; + for( int i = 0; i < arrayExpressions.length; ++i ) + if( arrayExpressions[i] == child ) + { + other.setPropertyInParent( child.getPropertyInParent() ); + other.setParent( child.getParent() ); + arrayExpressions[i] = (IASTExpression) other; + } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java index 5b8e9dab9e9..6bb89cb0043 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java @@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTOperatorName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; +import org.eclipse.cdt.core.parser.util.ArrayUtil; /** * @author jcamelon @@ -65,45 +66,19 @@ public class CPPASTQualifiedName extends CPPASTNode implements * @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; + names = (IASTName[]) ArrayUtil.append( IASTName.class, names, 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; + names = (IASTName[]) ArrayUtil.removeNulls( IASTName.class, names ); + } - private int currentIndex = 0; - private IASTName[] names = null; - - private static final int DEFAULT_NAMES_LIST_SIZE = 4; - private boolean value; - private String signature; /* diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java index f0008fcdaba..b4de6c2d2b1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java @@ -14,6 +14,7 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.parser.util.ArrayUtil; /** * @author jcamelon @@ -35,44 +36,15 @@ public class CPPASTSimpleDeclaration extends CPPASTNode implements */ public IASTDeclarator[] getDeclarators() { if( declarators == null ) return IASTDeclarator.EMPTY_DECLARATOR_ARRAY; - removeNullDeclarators(); - return declarators; + return (IASTDeclarator[]) ArrayUtil.removeNulls( IASTDeclarator.class, 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; + declarators = (IASTDeclarator[]) ArrayUtil.append( IASTDeclarator.class, declarators, 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 = 2; private IASTDeclSpecifier declSpecifier; /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateDeclaration.java index 490605bbe1c..a01e6d76bd6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateDeclaration.java @@ -15,6 +15,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope; +import org.eclipse.cdt.core.parser.util.ArrayUtil; /** * @author jcamelon @@ -59,46 +60,17 @@ public class CPPASTTemplateDeclaration extends CPPASTNode implements */ public ICPPASTTemplateParameter [] getTemplateParameters() { if( parameters == null ) return ICPPASTTemplateParameter.EMPTY_TEMPLATEPARAMETER_ARRAY; - removeNullParameters(); - return parameters; + return (ICPPASTTemplateParameter[]) ArrayUtil.removeNulls( ICPPASTTemplateParameter.class, parameters ); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration#addTemplateParamter(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter) */ public void addTemplateParamter(ICPPASTTemplateParameter parm) { - if( parameters == null ) - { - parameters = new ICPPASTTemplateParameter[ DEFAULT_PARMS_LIST_SIZE ]; - currentIndex = 0; - } - if( parameters.length == currentIndex ) - { - ICPPASTTemplateParameter [] old = parameters; - parameters = new ICPPASTTemplateParameter[ old.length * 2 ]; - for( int i = 0; i < old.length; ++i ) - parameters[i] = old[i]; - } - parameters[ currentIndex++ ] = parm; - } - private void removeNullParameters() { - int nullCount = 0; - for( int i = 0; i < parameters.length; ++i ) - if( parameters[i] == null ) - ++nullCount; - if( nullCount == 0 ) return; - ICPPASTTemplateParameter[] old = parameters; - int newSize = old.length - nullCount; - parameters = new ICPPASTTemplateParameter[ newSize ]; - for( int i = 0; i < newSize; ++i ) - parameters[i] = old[i]; - currentIndex = newSize; + parameters = (ICPPASTTemplateParameter[]) ArrayUtil.append( ICPPASTTemplateParameter.class, parameters, parm ); } - private int currentIndex = 0; private ICPPASTTemplateParameter [] parameters = null; - private static final int DEFAULT_PARMS_LIST_SIZE = 4; - public boolean accept( ASTVisitor action ){ if( action.shouldVisitDeclarations ){ switch( action.visit( this ) ){ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java index 412d2d402b6..d65c68de843 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java @@ -17,6 +17,7 @@ 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; +import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** @@ -43,38 +44,14 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, I * @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; + templateArguments = (IASTNode[]) ArrayUtil.append( IASTNode.class, templateArguments, 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; + templateArguments = (IASTNode[]) ArrayUtil.append( IASTNode.class, templateArguments, expression ); } /* (non-Javadoc) @@ -82,27 +59,10 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, I */ public IASTNode[] getTemplateArguments() { if( templateArguments == null ) return ICPPASTTemplateId.EMPTY_ARG_ARRAY; - removeNullArguments(); - return templateArguments; + return (IASTNode[]) ArrayUtil.removeNulls( IASTNode.class, 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; private IBinding binding = null; /* (non-Javadoc) @@ -185,12 +145,12 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, I } public void replace(IASTNode child, IASTNode other) { - IASTNode[] ez = getTemplateArguments(); - for (int i = 0; i < ez.length; ++i) { - if (child == ez[i]) { + if( templateArguments == null ) return; + for (int i = 0; i < templateArguments.length; ++i) { + if (child == templateArguments[i]) { other.setPropertyInParent(child.getPropertyInParent()); other.setParent(child.getParent()); - ez[i] = other; + templateArguments[i] = other; } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java index 6baaee32441..efb4d1897f3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java @@ -17,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter; +import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** @@ -27,42 +28,14 @@ public class CPPASTTemplatedTypeTemplateParameter extends CPPASTNode implements public ICPPASTTemplateParameter[] getTemplateParameters() { if( parameters == null ) return ICPPASTTemplateParameter.EMPTY_TEMPLATEPARAMETER_ARRAY; - removeNullParameters(); - return parameters; + return (ICPPASTTemplateParameter[]) ArrayUtil.removeNulls( ICPPASTTemplateParameter.class, parameters ); } public void addTemplateParamter(ICPPASTTemplateParameter parm) { - if( parameters == null ) - { - parameters = new ICPPASTTemplateParameter[ DEFAULT_PARMS_LIST_SIZE ]; - currentIndex = 0; - } - if( parameters.length == currentIndex ) - { - ICPPASTTemplateParameter [] old = parameters; - parameters = new ICPPASTTemplateParameter[ old.length * 2 ]; - for( int i = 0; i < old.length; ++i ) - parameters[i] = old[i]; - } - parameters[ currentIndex++ ] = parm; - } - private void removeNullParameters() { - int nullCount = 0; - for( int i = 0; i < parameters.length; ++i ) - if( parameters[i] == null ) - ++nullCount; - if( nullCount == 0 ) return; - ICPPASTTemplateParameter[] old = parameters; - int newSize = old.length - nullCount; - parameters = new ICPPASTTemplateParameter[ newSize ]; - for( int i = 0; i < newSize; ++i ) - parameters[i] = old[i]; - currentIndex = newSize; + parameters = (ICPPASTTemplateParameter[]) ArrayUtil.append( ICPPASTTemplateParameter.class, parameters, parm ); } - private int currentIndex = 0; private ICPPASTTemplateParameter [] parameters = null; - private static final int DEFAULT_PARMS_LIST_SIZE = 4; private IASTName name; private IASTExpression defaultValue; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java index 5135ba8a9e1..2122d694d10 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java @@ -45,6 +45,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.parser.ast.IASTEnumerator; +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.ASTPreprocessorSelectionResult; import org.eclipse.cdt.internal.core.dom.parser.IRequiresLocationInformation; @@ -56,16 +57,12 @@ import org.eclipse.cdt.internal.core.parser.scanner2.InvalidPreprocessorNodeExce */ public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslationUnit, IRequiresLocationInformation { - private IASTDeclaration[] decls = null; + private IASTDeclaration[] decls = new IASTDeclaration[32]; private ICPPNamespace binding = null; private ICPPScope scope = null; - private static final int DEFAULT_CHILDREN_LIST_SIZE = 8; - - private int currentIndex = 0; - private ILocationResolver resolver; @@ -82,17 +79,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements private static final IASTName[] EMPTY_NAME_ARRAY = new IASTName[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; + decls = (IASTDeclaration [])ArrayUtil.append( IASTDeclaration.class, decls, d ); } /* @@ -103,26 +90,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements public IASTDeclaration[] getDeclarations() { if (decls == null) return IASTDeclaration.EMPTY_DECLARATION_ARRAY; - removeNullDeclarations(); - return 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; + return (IASTDeclaration[]) ArrayUtil.removeNulls( IASTDeclaration.class, decls ); } /* diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java index 4d4c17d3583..6024357cc22 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java @@ -15,6 +15,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTryBlockStatement; +import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** @@ -27,46 +28,19 @@ public class CPPASTTryBlockStatement extends CPPASTNode implements * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator#addCatchHandler(org.eclipse.cdt.core.dom.ast.IASTStatement) */ public void addCatchHandler(ICPPASTCatchHandler statement) { - if( catchHandlers == null ) - { - catchHandlers = new ICPPASTCatchHandler[ DEFAULT_CATCH_HANDLER_LIST_SIZE ]; - currentIndex = 0; - } - if( catchHandlers.length == currentIndex ) - { - ICPPASTCatchHandler [] old = catchHandlers; - catchHandlers = new ICPPASTCatchHandler[ old.length * 2 ]; - for( int i = 0; i < old.length; ++i ) - catchHandlers[i] = old[i]; - } - catchHandlers[ currentIndex++ ] = statement; } + catchHandlers = (ICPPASTCatchHandler[]) ArrayUtil.append( ICPPASTCatchHandler.class, catchHandlers, statement ); + } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator#getCatchHandlers() */ public ICPPASTCatchHandler[] getCatchHandlers() { if( catchHandlers == null ) return ICPPASTCatchHandler.EMPTY_CATCHHANDLER_ARRAY; - removeNullCatchHandlers(); - return catchHandlers; + return (ICPPASTCatchHandler[]) ArrayUtil.removeNulls( ICPPASTCatchHandler.class, catchHandlers ); } - private void removeNullCatchHandlers() { - int nullCount = 0; - for( int i = 0; i < catchHandlers.length; ++i ) - if( catchHandlers[i] == null ) - ++nullCount; - if( nullCount == 0 ) return; - ICPPASTCatchHandler [] old = catchHandlers; - int newSize = old.length - nullCount; - catchHandlers = new ICPPASTCatchHandler[ newSize ]; - for( int i = 0; i < newSize; ++i ) - catchHandlers[i] = old[i]; - currentIndex = newSize; - } - private int currentIndex = 0; private ICPPASTCatchHandler [] catchHandlers = null; - private static final int DEFAULT_CATCH_HANDLER_LIST_SIZE = 4; private IASTStatement tryBody; /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTryBlockStatement#setTryBody(org.eclipse.cdt.core.dom.ast.IASTStatement)