Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Camelon2004-05-27 23:25:16 -0400
committerJohn Camelon2004-05-27 23:25:16 -0400
commitcf2a2a38e853df4ea454f7f4c2e79927200a720a (patch)
treeed34e14207d4fa6b7ebff17b6b323b33e54843c5
parentfb764be87ab93979dc3775a5b1d12c76b546660b (diff)
downloadorg.eclipse.cdt-cf2a2a38e853df4ea454f7f4c2e79927200a720a.tar.gz
org.eclipse.cdt-cf2a2a38e853df4ea454f7f4c2e79927200a720a.tar.xz
org.eclipse.cdt-cf2a2a38e853df4ea454f7f4c2e79927200a720a.zip
Further footprint optimization in parser and scanner.
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java43
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java35
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IMacroDescriptor.java5
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java3
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/extension/IASTFactoryExtension.java3
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java27
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Declarator.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTMacro.java6
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/GCCASTExtension.java3
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ExpressionParseASTFactory.java3
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java29
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java11
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/DynamicMacroDescriptor.java14
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/FunctionMacroDescriptor.java90
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/GCCScannerExtension.java21
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ObjectMacroDescriptor.java38
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Scanner.java91
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerUtility.java10
21 files changed, 231 insertions, 213 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java
index c2c0e4c757..196585866f 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java
@@ -13,7 +13,6 @@ import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Iterator;
-import java.util.List;
import org.eclipse.cdt.core.parser.IMacroDescriptor;
import org.eclipse.cdt.core.parser.IToken;
@@ -2039,28 +2038,28 @@ public class QuickParseASTTests extends BaseASTTest
assertFalse( macros.hasNext() );
assertEquals( swap.getName(), "SWAP"); //$NON-NLS-1$
assertEquals( swap.getMacroType(), IMacroDescriptor.MacroType.FUNCTION_LIKE );
- List params = swap.getParameters();
- assertEquals( params.size(), 2 );
- assertEquals( params.get(0), "x"); //$NON-NLS-1$
- assertEquals( params.get(1), "y"); //$NON-NLS-1$
- assertEquals( swap.getCompleteSignature().trim(), "#define SWAP(x,y) {x|=y;y|=x;x|=y;}"); //$NON-NLS-1$
+ String [] params = swap.getParameters();
+ assertEquals( params.length, 2 );
+ assertEquals( params[0], "x"); //$NON-NLS-1$
+ assertEquals( params[1], "y"); //$NON-NLS-1$
+ String completeSignature = swap.getCompleteSignature().trim();
+ assertEquals( completeSignature, "#define SWAP(x,y) {x|=y;y|=x;x|=y;}"); //$NON-NLS-1$
assertEquals( swap.getExpansionSignature().trim(),"{x|=y;y|=x;x|=y;}"); //$NON-NLS-1$
- Iterator tokens = swap.getTokenizedExpansion().iterator();
- validateToken( (IToken)tokens.next(), IToken.tLBRACE);
- validateIdentifier( (IToken)tokens.next(), "x"); //$NON-NLS-1$
- validateToken( (IToken) tokens.next(), IToken.tBITORASSIGN );
- validateIdentifier( (IToken) tokens.next(), "y"); //$NON-NLS-1$
- validateToken( (IToken) tokens.next(), IToken.tSEMI );
- validateIdentifier( (IToken) tokens.next(), "y"); //$NON-NLS-1$
- validateToken( (IToken) tokens.next(), IToken.tBITORASSIGN );
- validateIdentifier( (IToken)tokens.next(), "x"); //$NON-NLS-1$
- validateToken( (IToken) tokens.next(), IToken.tSEMI );
- validateIdentifier( (IToken)tokens.next(), "x"); //$NON-NLS-1$
- validateToken( (IToken) tokens.next(), IToken.tBITORASSIGN );
- validateIdentifier( (IToken) tokens.next(), "y"); //$NON-NLS-1$
- validateToken( (IToken) tokens.next(), IToken.tSEMI );
- validateToken( (IToken) tokens.next(), IToken.tRBRACE );
- assertFalse( tokens.hasNext() );
+ IToken [] tokens = swap.getTokenizedExpansion();
+ validateToken( tokens[0], IToken.tLBRACE);
+ validateIdentifier( tokens[1], "x"); //$NON-NLS-1$
+ validateToken( tokens[2], IToken.tBITORASSIGN );
+ validateIdentifier( tokens[3], "y"); //$NON-NLS-1$
+ validateToken( tokens[4], IToken.tSEMI );
+ validateIdentifier( tokens[5], "y"); //$NON-NLS-1$
+ validateToken( tokens[6], IToken.tBITORASSIGN );
+ validateIdentifier( tokens[7], "x"); //$NON-NLS-1$
+ validateToken( tokens[8], IToken.tSEMI );
+ validateIdentifier( tokens[9], "x"); //$NON-NLS-1$
+ validateToken( tokens[10], IToken.tBITORASSIGN );
+ validateIdentifier( tokens[11], "y"); //$NON-NLS-1$
+ validateToken( tokens[12], IToken.tSEMI );
+ validateToken( tokens[13], IToken.tRBRACE );
}
/**
* @param token
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java
index 6a888ccc51..f499230b39 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java
@@ -26,7 +26,6 @@ import org.eclipse.cdt.core.parser.ParserFactoryError;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ScannerException;
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
-import org.eclipse.cdt.internal.core.parser.token.SimpleToken;
/**
* @author jcamelon
@@ -688,19 +687,19 @@ public class ScannerTestCase extends BaseScannerTest
IMacroDescriptor descriptor=
scanner.getDefinition("GO"); //$NON-NLS-1$
- List parms= descriptor.getParameters();
+ String [] parms= descriptor.getParameters();
assertNotNull(parms);
- assertTrue(parms.size() == 1);
- String parm1= (String) parms.get(0);
+ assertTrue(parms.length == 1);
+ String parm1= parms[0];
assertTrue(parm1.equals("x")); //$NON-NLS-1$
- List expansion= descriptor.getTokenizedExpansion();
+ IToken [] expansion= descriptor.getTokenizedExpansion();
assertNotNull(parms);
- assertTrue(expansion.size() == 3);
- assertTrue(((SimpleToken) expansion.get(0)).getType() == IToken.tIDENTIFIER);
- assertTrue(((SimpleToken) expansion.get(0)).getImage().equals("x")); //$NON-NLS-1$
- assertTrue(((SimpleToken) expansion.get(1)).getType() == IToken.tPLUS);
- assertTrue(((SimpleToken) expansion.get(2)).getType() == IToken.tINTEGER);
- assertTrue(((SimpleToken) expansion.get(2)).getImage().equals("1")); //$NON-NLS-1$
+ assertTrue(expansion.length == 3);
+ assertTrue((expansion[0]).getType() == IToken.tIDENTIFIER);
+ assertTrue((expansion[0]).getImage().equals("x")); //$NON-NLS-1$
+ assertTrue((expansion[1]).getType() == IToken.tPLUS);
+ assertTrue((expansion[2]).getType() == IToken.tINTEGER);
+ assertTrue((expansion[2]).getImage().equals("1")); //$NON-NLS-1$
validateIdentifier("y"); //$NON-NLS-1$
validateToken(IToken.tASSIGN);
@@ -737,13 +736,13 @@ public class ScannerTestCase extends BaseScannerTest
validateEOF();
IMacroDescriptor macro= scanner.getDefinition("SUM"); //$NON-NLS-1$
- List params= macro.getParameters();
+ String [] params= macro.getParameters();
assertNotNull(params);
- assertTrue(params.size() == 7);
+ assertTrue(params.length == 7);
- List tokens= macro.getTokenizedExpansion();
+ IToken [] tokens= macro.getTokenizedExpansion();
assertNotNull(tokens);
- assertTrue(tokens.size() == 15);
+ assertTrue(tokens.length == 15);
initializeScanner("#define LOG( format, var1) printf( format, var1 )\nLOG( \"My name is %s\", \"Bogdan\" );\n"); //$NON-NLS-1$
validateIdentifier("printf"); //$NON-NLS-1$
@@ -1090,9 +1089,9 @@ public class ScannerTestCase extends BaseScannerTest
validateEOF();
IMacroDescriptor macro = scanner.getDefinition( "X" ); //$NON-NLS-1$
assertNotNull( macro );
- assertEquals( macro.getParameters().size(), 1 );
- assertEquals( (String)macro.getParameters().get(0), "Y" ); //$NON-NLS-1$
- assertEquals( macro.getTokenizedExpansion().size(), 0 );
+ assertEquals( macro.getParameters().length, 1 );
+ assertEquals( macro.getParameters()[0], "Y" ); //$NON-NLS-1$
+ assertEquals( macro.getTokenizedExpansion().length, 0 );
}
public void testBug36047() throws Exception
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IMacroDescriptor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IMacroDescriptor.java
index 615120bcb8..b18e49358c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IMacroDescriptor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IMacroDescriptor.java
@@ -10,7 +10,6 @@
******************************************************************************/
package org.eclipse.cdt.core.parser;
-import java.util.List;
/**
* @author jcamelon
*
@@ -42,10 +41,10 @@ public interface IMacroDescriptor {
public MacroType getMacroType();
// parameters for macros of type FUNCTION_LIKE
- public List getParameters();
+ public String[] getParameters();
// the RHS side of the macro separated into ITokens
- public List getTokenizedExpansion();
+ public IToken[] getTokenizedExpansion();
// the symbol name
public String getName();
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java
index 6e650ee86a..7f668ae270 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java
@@ -9,7 +9,6 @@
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.core.parser.ast;
-import java.util.Hashtable;
import java.util.List;
import java.util.Map;
@@ -154,7 +153,7 @@ public interface IASTFactory
boolean isLong,
boolean isSigned,
boolean isUnsigned,
- boolean isTypename, boolean isComplex, boolean isImaginary, boolean isGlobal, Hashtable extensionParms ) throws ASTSemanticException;
+ boolean isTypename, boolean isComplex, boolean isImaginary, boolean isGlobal, Map map ) throws ASTSemanticException;
public IASTFunction createFunction(
IASTScope scope,
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/extension/IASTFactoryExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/extension/IASTFactoryExtension.java
index dcc8778b4c..25e43a633a 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/extension/IASTFactoryExtension.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/extension/IASTFactoryExtension.java
@@ -10,7 +10,6 @@
package org.eclipse.cdt.core.parser.extension;
-import java.util.Hashtable;
import java.util.Map;
import org.eclipse.cdt.core.parser.IToken;
@@ -62,7 +61,7 @@ public interface IASTFactoryExtension {
boolean isShort,
boolean isLong,
boolean isSigned,
- boolean isUnsigned, boolean isTypename, boolean isComplex, boolean isImaginary, boolean isGlobal, Hashtable extensionParms );
+ boolean isUnsigned, boolean isTypename, boolean isComplex, boolean isImaginary, boolean isGlobal, Map extensionParms );
public boolean overrideCreateDesignatorMethod( IASTDesignator.DesignatorKind kind );
public IASTDesignator createDesignator( IASTDesignator.DesignatorKind kind, IASTExpression constantExpression, IToken fieldIdentifier, Map extensionParms );
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java
index 1b907aae6f..95133a7500 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java
@@ -14,6 +14,7 @@ import java.util.Collections;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import org.eclipse.cdt.core.parser.BacktrackException;
import org.eclipse.cdt.core.parser.IProblem;
@@ -338,10 +339,10 @@ public class DeclarationWrapper implements IDeclaratorOwner
public List createASTNodes(IASTFactory astFactoryToWorkWith) throws ASTSemanticException, BacktrackException
{
this.astFactory = astFactoryToWorkWith;
- Iterator i = declarators.iterator();
- List l = new ArrayList();
- while (i.hasNext())
- l.add(createASTNode((Declarator)i.next()));
+ if( declarators.isEmpty() ) return Collections.EMPTY_LIST;
+ List l = new ArrayList(declarators.size());
+ for( int i = 0; i < declarators.size(); ++i )
+ l.add(createASTNode((Declarator)declarators.get(i)));
return l;
}
/**
@@ -538,11 +539,11 @@ public class DeclarationWrapper implements IDeclaratorOwner
private List createParameterList(List currentParameters) throws ASTSemanticException
{
- List result = new ArrayList();
- Iterator i = currentParameters.iterator();
- while (i.hasNext())
+ if( currentParameters.isEmpty() ) return Collections.EMPTY_LIST;
+ List result = new ArrayList(currentParameters.size());
+ for( int i = 0; i < currentParameters.size(); ++i )
{
- DeclarationWrapper wrapper = (DeclarationWrapper)i.next();
+ DeclarationWrapper wrapper = (DeclarationWrapper)currentParameters.get(i);
Iterator j = wrapper.getDeclarators();
while (j.hasNext())
{
@@ -555,9 +556,7 @@ public class DeclarationWrapper implements IDeclaratorOwner
wrapper.getTypeSpecifier(),
declarator.getPointerOperators(),
declarator.getArrayModifiers(),
- null, null, declarator.getName() == null
- ? "" //$NON-NLS-1$
- : declarator.getName(), declarator.getInitializerClause(), wrapper.getStartingOffset(), getStartingLine(), declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine(), wrapper.getEndOffset(), getEndLine()));
+ null, null, declarator.getName(), declarator.getInitializerClause(), wrapper.getStartingOffset(), getStartingLine(), declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine(), wrapper.getEndOffset(), getEndLine()));
}
}
return result;
@@ -765,16 +764,18 @@ public class DeclarationWrapper implements IDeclaratorOwner
return checkBit( IS_GLOBAL );
}
- private Hashtable extensionParameters = new Hashtable();
+ private Map extensionParameters = Collections.EMPTY_MAP;
/**
* @param key
* @param typeOfExpression
*/
public void setExtensionParameter(String key, Object value) {
+ if( extensionParameters == Collections.EMPTY_MAP )
+ extensionParameters = new Hashtable( 4 );
extensionParameters.put( key, value );
}
- public Hashtable getExtensionParameters()
+ public Map getExtensionParameters()
{
return extensionParameters;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Declarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Declarator.java
index d640b600ea..8a4258b022 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Declarator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Declarator.java
@@ -353,7 +353,7 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
public DeclarationWrapper getDeclarationWrapper()
{
Declarator d = this;
- while( d.getOwner() instanceof IDeclarator )
+ while( d.getOwner() instanceof Declarator )
d = (Declarator)d.getOwner();
return (DeclarationWrapper)d.getOwner();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java
index ce6ac356d1..2dc9c8660f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java
@@ -680,7 +680,7 @@ public abstract class Parser extends ExpressionParser implements IParser
declarator.getPointerOperators(),
declarator.getArrayModifiers(),
null, null,
- declarator.getName() == null ? "" : declarator.getName(), //$NON-NLS-1$
+ declarator.getName(),
declarator.getInitializerClause(),
wrapper.getStartingOffset(), wrapper.getStartingLine(),
declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine(),
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTMacro.java
index 1f9b059229..ec717aba67 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTMacro.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTMacro.java
@@ -10,10 +10,10 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast;
-import java.util.List;
import org.eclipse.cdt.core.parser.IMacroDescriptor;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
+import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ast.IASTMacro;
/**
@@ -133,13 +133,13 @@ public class ASTMacro implements IASTMacro {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getParameters()
*/
- public List getParameters() {
+ public String[] getParameters() {
return innerMacro.getParameters();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getTokenizedExpansion()
*/
- public List getTokenizedExpansion() {
+ public IToken[] getTokenizedExpansion() {
return innerMacro.getTokenizedExpansion();
}
/* (non-Javadoc)
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/GCCASTExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/GCCASTExtension.java
index 25e7921d16..a7dd5352a9 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/GCCASTExtension.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/GCCASTExtension.java
@@ -11,7 +11,6 @@
package org.eclipse.cdt.internal.core.parser.ast;
import java.util.Collections;
-import java.util.Hashtable;
import java.util.Map;
import org.eclipse.cdt.core.parser.IToken;
@@ -159,7 +158,7 @@ public class GCCASTExtension implements IASTFactoryExtension {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.extension.IASTFactoryExtension#createSimpleTypeSpecifier(org.eclipse.cdt.core.parser.ast.IASTScope, org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type, org.eclipse.cdt.core.parser.ITokenDuple, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean)
*/
- public IASTSimpleTypeSpecifier createSimpleTypeSpecifier(ParserSymbolTable pst, IASTScope scope, Type kind, ITokenDuple typeName, boolean isShort, boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, boolean isComplex, boolean isImaginary, boolean isGlobal, Hashtable extensionParms) {
+ public IASTSimpleTypeSpecifier createSimpleTypeSpecifier(ParserSymbolTable pst, IASTScope scope, Type kind, ITokenDuple typeName, boolean isShort, boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, boolean isComplex, boolean isImaginary, boolean isGlobal, Map extensionParms) {
if( kind == IASTGCCSimpleTypeSpecifier.Type.TYPEOF )
{
ASTExpression typeOfExpression = (ASTExpression) extensionParms.get( IASTGCCSimpleTypeSpecifier.TYPEOF_EXRESSION );
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java
index 2f696c5e43..e8595d7124 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java
@@ -12,10 +12,10 @@ package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.ArrayList;
-import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.Stack;
import org.eclipse.cdt.core.parser.Enum;
@@ -1885,7 +1885,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
boolean isTypename,
boolean isComplex,
boolean isImaginary,
- boolean isGlobal, Hashtable extensionParms ) throws ASTSemanticException
+ boolean isGlobal, Map extensionParms ) throws ASTSemanticException
{
if( extension.overrideCreateSimpleTypeSpecifierMethod( kind ))
return extension.createSimpleTypeSpecifier(pst, scope, kind, typeName, isShort, isLong, isSigned, isUnsigned, isTypename, isComplex, isImaginary, isGlobal, extensionParms );
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ExpressionParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ExpressionParseASTFactory.java
index 9bf8752cb3..9050ca6213 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ExpressionParseASTFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ExpressionParseASTFactory.java
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.expression;
-import java.util.Hashtable;
import java.util.List;
import java.util.Map;
@@ -475,7 +474,7 @@ public class ExpressionParseASTFactory extends BaseASTFactory implements IASTFac
boolean isTypename,
boolean isComplex,
boolean isImaginary,
- boolean isGlobal, Hashtable extensionParms)
+ boolean isGlobal, Map extensionParms)
throws ASTSemanticException {
// TODO Auto-generated method stub
return null;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java
index 27a0a8bcca..4faf5815dc 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java
@@ -10,8 +10,8 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.quick;
-import java.util.Hashtable;
import java.util.List;
+import java.util.Map;
import org.eclipse.cdt.core.parser.ITokenDuple;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
@@ -189,7 +189,7 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createSimpleTypeSpecifier(org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.SimpleType, org.eclipse.cdt.core.parser.ITokenDuple)
*/
- public IASTSimpleTypeSpecifier createSimpleTypeSpecifier(IASTScope scope, Type kind, ITokenDuple typeName, boolean isShort, boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, boolean isComplex, boolean isImaginary, boolean isGlobal, Hashtable extensionParms)
+ public IASTSimpleTypeSpecifier createSimpleTypeSpecifier(IASTScope scope, Type kind, ITokenDuple typeName, boolean isShort, boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, boolean isComplex, boolean isImaginary, boolean isGlobal, Map extensionParms)
{
return new ASTSimpleTypeSpecifier( kind, typeName, isShort, isLong, isSigned, isUnsigned, isTypename, isComplex, isImaginary);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java
index 6624cfd40a..7555c1a218 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java
@@ -454,11 +454,9 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
LookupData data = new LookupData( name ){
public TypeFilter getFilter() {
if( t == TypeInfo.t_any ) return ANY_FILTER;
- else {
- if( filter == null ) filter = new TypeFilter( t );
- return filter;
- }
- };
+ if( filter == null ) filter = new TypeFilter( t );
+ return filter;
+ }
private TypeFilter filter = null;
private final TypeInfo.eType t = type;
};
@@ -554,7 +552,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
public IParameterizedSymbol lookupMethodForDefinition( String name, final List parameters ) throws ParserSymbolTableException{
LookupData data = new LookupData( name ){
- public List getParameters() { return params; };
+ public List getParameters() { return params; }
final private List params = ( parameters == null ) ? Collections.EMPTY_LIST : parameters;
};
data.qualified = true;
@@ -642,14 +640,13 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
LookupData data = new LookupData( name ){
public TypeFilter getFilter() {
if( t == TypeInfo.t_any ) return ANY_FILTER;
- else {
- if( filter == null )
- filter = new TypeFilter( t );
- return filter;
- }
+
+ if( filter == null )
+ filter = new TypeFilter( t );
+ return filter;
+
}
private TypeFilter filter = null;
- private final TypeInfo.eType type = t;
};
data.qualified = true;
ParserSymbolTable.lookup( data, this );
@@ -776,7 +773,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
*/
public IParameterizedSymbol memberFunctionLookup( String name, final List parameters ) throws ParserSymbolTableException{
LookupData data = new LookupData( name ){
- public List getParameters() { return params; };
+ public List getParameters() { return params; }
final private List params = ( parameters == null ) ? Collections.EMPTY_LIST : parameters;
public TypeFilter getFilter() { return FUNCTION_FILTER; }
};
@@ -789,7 +786,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
*/
public IParameterizedSymbol qualifiedFunctionLookup( String name, final List parameters ) throws ParserSymbolTableException{
LookupData data = new LookupData( name ){
- public List getParameters() { return params; };
+ public List getParameters() { return params; }
final private List params = ( parameters == null ) ? Collections.EMPTY_LIST : parameters;
public TypeFilter getFilter() { return FUNCTION_FILTER; }
};
@@ -857,11 +854,11 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
public Set getAmbiguities(){ return ambiguities; }
public TypeFilter getFilter() { return typeFilter; }
- public void addAmbiguity( String name ){
+ public void addAmbiguity( String n ){
if( ambiguities == Collections.EMPTY_SET ){
ambiguities = new HashSet();
}
- ambiguities.add( name );
+ ambiguities.add( n );
}
final private List params = paramList;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java
index 6dfd8af900..576f20b665 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java
@@ -1859,7 +1859,7 @@ public class ParserSymbolTable {
}
if( targetDecl.isType( TypeInfo.t_class, TypeInfo.t_union ) ){
LookupData data = new LookupData( EMPTY_NAME){
- public List getParameters() { return parameters; };
+ public List getParameters() { return parameters; }
public TypeFilter getFilter() { return CONSTRUCTOR_FILTER; }
private List parameters = new ArrayList( 1 );
};
@@ -1892,7 +1892,7 @@ public class ParserSymbolTable {
if( !name.equals(EMPTY_NAME) ){
LookupData data = new LookupData( "operator " + name ){ //$NON-NLS-1$
- public List getParameters() { return Collections.EMPTY_LIST; };
+ public List getParameters() { return Collections.EMPTY_LIST; }
public TypeFilter getFilter() { return FUNCTION_FILTER; }
};
data.forUserDefinedConversion = true;
@@ -2040,10 +2040,7 @@ public class ParserSymbolTable {
private IContainerSymbol _compilationUnit;
private ParserLanguage _language;
private ParserMode _mode;
-// private ArrayList undoList = new ArrayList();
- private HashSet markSet = new HashSet();
-
- public void setLanguage( ParserLanguage language ){
+public void setLanguage( ParserLanguage language ){
_language = language;
}
@@ -2133,7 +2130,7 @@ public class ParserSymbolTable {
//this LookupData
public boolean isPrefixLookup(){ return false;} //prefix lookup
public Set getAmbiguities() { return null; }
- public void addAmbiguity(String name) { }
+ public void addAmbiguity(String n ) { }
public List getParameters() { return null; } //parameter info for resolving functions
public HashSet getAssociated() { return null; } //associated namespaces for argument dependant lookup
public ISymbol getStopAt() { return null; } //stop looking along the stack once we hit this declaration
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/DynamicMacroDescriptor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/DynamicMacroDescriptor.java
index 6deae38bee..1ef21dfe2b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/DynamicMacroDescriptor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/DynamicMacroDescriptor.java
@@ -10,10 +10,8 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner;
-import java.util.Collections;
-import java.util.List;
-
import org.eclipse.cdt.core.parser.IMacroDescriptor;
+import org.eclipse.cdt.core.parser.IToken;
/**
* @author jcamelon
@@ -25,6 +23,8 @@ public class DynamicMacroDescriptor implements IMacroDescriptor {
private final String name;
private final DynamicMacroEvaluator proxy;
+ private static final String[] EMPTY_STRING_ARRAY = new String[0];
+ private static final IToken[] EMPTY_TOKEN_ARRAY = new IToken[0];
public DynamicMacroDescriptor( String name, DynamicMacroEvaluator proxy )
{
@@ -41,15 +41,15 @@ public class DynamicMacroDescriptor implements IMacroDescriptor {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getParameters()
*/
- public List getParameters() {
- return Collections.EMPTY_LIST;
+ public String[] getParameters() {
+ return EMPTY_STRING_ARRAY;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getTokenizedExpansion()
*/
- public List getTokenizedExpansion() {
- return Collections.EMPTY_LIST;
+ public IToken[] getTokenizedExpansion() {
+ return EMPTY_TOKEN_ARRAY;
}
/* (non-Javadoc)
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/FunctionMacroDescriptor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/FunctionMacroDescriptor.java
index 0d58931b8d..f912f93bff 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/FunctionMacroDescriptor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/FunctionMacroDescriptor.java
@@ -10,8 +10,7 @@
******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner;
-import java.util.Iterator;
-import java.util.List;
+import java.util.Arrays;
import org.eclipse.cdt.core.parser.IMacroDescriptor;
import org.eclipse.cdt.core.parser.IToken;
@@ -27,7 +26,7 @@ public class FunctionMacroDescriptor implements IMacroDescriptor {
* RHS expansion in the macro definition.
* @param sig The complete signature of the macro, as a string.
*/
- public FunctionMacroDescriptor( String name, List identifiers, List tokens, String expansionSignature )
+ public FunctionMacroDescriptor( String name, String[] identifiers, IToken[] tokens, String expansionSignature )
{
this.name = name;
identifierParameters = identifiers;
@@ -36,15 +35,15 @@ public class FunctionMacroDescriptor implements IMacroDescriptor {
}
private String name;
- private List identifierParameters;
- private List tokenizedExpansion;
+ private String [] identifierParameters;
+ private IToken [] tokenizedExpansion;
private String expansionSignature;
- private Boolean isCircular = null;
+
/**
* Returns the identifiers.
* @return List
*/
- public final List getParameters() {
+ public final String[] getParameters() {
return identifierParameters;
}
@@ -52,7 +51,7 @@ public class FunctionMacroDescriptor implements IMacroDescriptor {
* Returns the tokens.
* @return List
*/
- public final List getTokenizedExpansion() {
+ public final IToken[] getTokenizedExpansion() {
return tokenizedExpansion;
}
@@ -71,25 +70,23 @@ public class FunctionMacroDescriptor implements IMacroDescriptor {
public String toString()
{
StringBuffer buffer = new StringBuffer( 128 );
- int count = getParameters().size();
+
+ int count = identifierParameters.length;
buffer.append( "MacroDescriptor with name=" + getName() + "\n" ); //$NON-NLS-1$//$NON-NLS-2$
buffer.append( "Number of parameters = " + count + "\n" ); //$NON-NLS-1$//$NON-NLS-2$
- Iterator iter = getParameters().iterator();
- int current = 0;
- while( iter.hasNext() )
- {
- buffer.append( "Parameter #" + current++ + " with name=" + (String) iter.next() + "\n" ); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
- }
+
+ for( int current = 0; current < count; ++current)
+ buffer.append( "Parameter #" + current + " with name=" + identifierParameters[current] + "\n" ); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
+
- count = getTokenizedExpansion().size();
- iter = getTokenizedExpansion().iterator();
+ count = tokenizedExpansion.length;
+
buffer.append( "Number of tokens = " + count + "\n" ); //$NON-NLS-1$//$NON-NLS-2$
- current = 0;
- while( iter.hasNext() )
+ for( int current = 0; current < count; ++current )
{
- buffer.append( "Token #" + current++ + " is " + ((IToken)iter.next()).toString() + "\n" ); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
+ buffer.append( "Token #" + current++ + " is " + tokenizedExpansion[current].toString() + "\n" ); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
}
return buffer.toString();
@@ -104,13 +101,11 @@ public class FunctionMacroDescriptor implements IMacroDescriptor {
StringBuffer fullSignature = new StringBuffer( "#define " ); //$NON-NLS-1$
fullSignature.append( name );
fullSignature.append( '(');
- Iterator iter = getParameters().iterator();
- int current = 0;
- while( iter.hasNext() )
+
+ for( int current = 0; current < identifierParameters.length; ++current )
{
if (current > 0) fullSignature.append(',');
- fullSignature.append((String)iter.next() );
- current++;
+ fullSignature.append(identifierParameters[current] );
}
fullSignature.append( ") "); //$NON-NLS-1$
fullSignature.append( expansionSignature );
@@ -126,11 +121,33 @@ public class FunctionMacroDescriptor implements IMacroDescriptor {
if( descriptor.getParameters() == null ) return false;
if( descriptor.getMacroType() != getMacroType() ) return false;
if( ! name.equals( descriptor.getName() )) return false;
- if( descriptor.getParameters().size() != identifierParameters.size() ) return false;
- if( descriptor.getTokenizedExpansion().size() != tokenizedExpansion.size() ) return false;
+ if( descriptor.getParameters().length != identifierParameters.length ) return false;
+ if( descriptor.getTokenizedExpansion().length != tokenizedExpansion.length ) return false;
- if( ! (descriptor.getParameters().containsAll( identifierParameters ) )) return false;
- if( ! (descriptor.getTokenizedExpansion().containsAll( tokenizedExpansion ))) return false;
+ if( ! equivalentArrayContents( descriptor.getParameters(), getParameters() ) ) return false;
+ if( ! equivalentArrayContents( descriptor.getTokenizedExpansion(), getTokenizedExpansion() ) ) return false;
+ return true;
+ }
+
+ /**
+ * @param list1
+ * @param list2
+ * @return
+ */
+ private boolean equivalentArrayContents(Object[] list1, Object[] list2 ) {
+ if( Arrays.equals( list1, list2 )) return true;
+ // otherwise
+ topLoop: for( int i = 0; i < list1.length; ++i )
+ {
+ Object key = list1[i];
+ for( int j = 0; j < list2 .length; ++j )
+ {
+ if( key.equals( list2 [j]) )
+ continue topLoop;
+
+ }
+ return false;
+ }
return true;
}
@@ -152,23 +169,12 @@ public class FunctionMacroDescriptor implements IMacroDescriptor {
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#isCircular()
*/
public boolean isCircular() {
- if( isCircular == null )
- isCircular = new Boolean( checkIsCircular() );
- return isCircular.booleanValue();
- }
-
- /**
- * @return
- */
- protected boolean checkIsCircular() {
- Iterator i = getTokenizedExpansion().iterator();
- while( i.hasNext() )
+ for( int i = 0; i < tokenizedExpansion.length; ++i )
{
- IToken t = (IToken) i.next();
+ IToken t = tokenizedExpansion[i];
if( t.getType() == IToken.tIDENTIFIER && t.getImage().equals(getName()))
return true;
}
return false;
}
-
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/GCCScannerExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/GCCScannerExtension.java
index accdd975cf..04c5b06db1 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/GCCScannerExtension.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/GCCScannerExtension.java
@@ -10,12 +10,9 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner;
-import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -40,15 +37,15 @@ public class GCCScannerExtension implements IScannerExtension {
protected static final ObjectMacroDescriptor STDC_VERSION_MACRO = new ObjectMacroDescriptor( IScanner.__STDC_VERSION__, "199001L"); //$NON-NLS-1$
protected static final ObjectMacroDescriptor STDC_HOSTED_MACRO = new ObjectMacroDescriptor( IScanner.__STDC_HOSTED__, "0"); //$NON-NLS-1$
protected static final ObjectMacroDescriptor CPLUSPLUS_MACRO = new ObjectMacroDescriptor( IScanner.__CPLUSPLUS, "1"); //$NON-NLS-1$
- private static final List simpleIdentifiersDeclSpec;
- private static final List simpleIdentifiersAttribute;
+ private static final String [] simpleIdentifiersDeclSpec;
+ private static final String [] simpleIdentifiersAttribute;
static
{
- simpleIdentifiersDeclSpec = new ArrayList( 1 );
- simpleIdentifiersDeclSpec.add( "x" ); //$NON-NLS-1$
+ simpleIdentifiersDeclSpec = new String[ 1 ];
+ simpleIdentifiersDeclSpec[0]= "x"; //$NON-NLS-1$
- simpleIdentifiersAttribute = new ArrayList( 1 );
- simpleIdentifiersAttribute.add( "xyz"); //$NON-NLS-1$
+ simpleIdentifiersAttribute = new String[ 1 ];
+ simpleIdentifiersAttribute[0] = "xyz"; //$NON-NLS-1$
}
@@ -77,8 +74,10 @@ public class GCCScannerExtension implements IScannerExtension {
private static final String __ATTRIBUTE__ = "__attribute__"; //$NON-NLS-1$
private static final String __DECLSPEC = "__declspec"; //$NON-NLS-1$
- protected static final FunctionMacroDescriptor DECLSPEC_MACRO = new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiersDeclSpec, Collections.EMPTY_LIST, "" ); //$NON-NLS-1$
- protected static final FunctionMacroDescriptor ATTRIBUTE_MACRO = new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiersAttribute, Collections.EMPTY_LIST, "" ); //$NON-NLS-1$
+ private static final IToken [] EMPTY_TOKEN_ARRAY = new IToken[0];
+ protected static final FunctionMacroDescriptor DECLSPEC_MACRO = new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiersDeclSpec, EMPTY_TOKEN_ARRAY, "" ); //$NON-NLS-1$
+
+ protected static final FunctionMacroDescriptor ATTRIBUTE_MACRO = new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiersAttribute, EMPTY_TOKEN_ARRAY, "" ); //$NON-NLS-1$
private static final String __EXTENSION__ = "__extension__"; //$NON-NLS-1$
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ObjectMacroDescriptor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ObjectMacroDescriptor.java
index f7ba923568..73f8979faa 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ObjectMacroDescriptor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ObjectMacroDescriptor.java
@@ -10,11 +10,6 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
import org.eclipse.cdt.core.parser.IMacroDescriptor;
import org.eclipse.cdt.core.parser.IToken;
@@ -26,8 +21,9 @@ public class ObjectMacroDescriptor implements IMacroDescriptor {
private final String expansionSignature;
private final String name;
private final IToken token;
- private Boolean isCircular = null;
- private List tokenizedExpansion = null;
+ private IToken[] tokenizedExpansion = null;
+ private static final String[] EMPTY_STRING_ARRAY = new String[0];
+ private static final IToken[] EMPTY_TOKEN_ARRAY = new IToken[0];
public ObjectMacroDescriptor( String name, String expansionSignature )
{
@@ -53,19 +49,19 @@ public class ObjectMacroDescriptor implements IMacroDescriptor {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getParameters()
*/
- public List getParameters() {
- return Collections.EMPTY_LIST;
+ public String[] getParameters() {
+ return EMPTY_STRING_ARRAY ;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getTokenizedExpansion()
*/
- public List getTokenizedExpansion() {
- if( token == null ) return Collections.EMPTY_LIST;
+ public IToken[] getTokenizedExpansion() {
+ if( token == null ) return EMPTY_TOKEN_ARRAY;
if( tokenizedExpansion == null )
{
- tokenizedExpansion = new ArrayList(1);
- tokenizedExpansion.add(token);
+ tokenizedExpansion = new IToken[1];
+ tokenizedExpansion[0]= token;
}
return tokenizedExpansion;
}
@@ -112,23 +108,13 @@ public class ObjectMacroDescriptor implements IMacroDescriptor {
return expansionSignature;
}
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IMacroDescriptor#isCircular()
- */
- public boolean isCircular() {
- if( isCircular == null )
- isCircular = new Boolean( checkIsCircular() );
- return isCircular.booleanValue();
- }
-
/**
* @return
*/
- protected boolean checkIsCircular() {
- Iterator i = getTokenizedExpansion().iterator();
- while( i.hasNext() )
+ public boolean isCircular() {
+ for( int i = 0; i < getTokenizedExpansion().length; ++i)
{
- IToken t = (IToken) i.next();
+ IToken t = tokenizedExpansion[i];
if( t.getType() == IToken.tIDENTIFIER && t.getImage().equals(getName()))
return true;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Scanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Scanner.java
index 624f8a7784..1ea1321777 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Scanner.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Scanner.java
@@ -15,6 +15,7 @@ import java.io.File;
import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.EmptyStackException;
@@ -305,7 +306,7 @@ public class Scanner implements IScanner {
public void overwriteIncludePath(String [] newIncludePaths) {
if( newIncludePaths == null ) return;
- scannerData.setIncludePathNames(new ArrayList());
+ scannerData.setIncludePathNames(new ArrayList(newIncludePaths.length));
for( int i = 0; i < newIncludePaths.length; ++i )
{
@@ -2644,6 +2645,9 @@ public class Scanner implements IScanner {
protected boolean forInclusion = false;
private final static IParserLogService NULL_LOG_SERVICE = new NullLogService();
private static final String [] STRING_ARRAY = new String[0];
+ private static final IToken [] EMPTY_TOKEN_ARRAY = new IToken[0];
+ private static final int START_BUFFER_SIZE = 8;
+ private IToken[] tokenArrayBuffer = new IToken[START_BUFFER_SIZE];
/**
* @param b
*/
@@ -2652,12 +2656,12 @@ public class Scanner implements IScanner {
forInclusion = b;
}
- protected List tokenizeReplacementString( int beginning, String key, String replacementString, List parameterIdentifiers )
+ protected IToken[] tokenizeReplacementString( int beginning, String key, String replacementString, String[] parameterIdentifiers )
{
-
if( replacementString.trim().equals( "" ) ) //$NON-NLS-1$
- return Collections.EMPTY_LIST;
- List macroReplacementTokens = new ArrayList();
+ return EMPTY_TOKEN_ARRAY;
+ IToken [] macroReplacementTokens = getTokenBuffer();
+ int currentIndex = 0;
IScanner helperScanner=null;
try {
helperScanner = new Scanner(
@@ -2679,18 +2683,24 @@ public class Scanner implements IScanner {
}
if( t == null )
- return macroReplacementTokens;
+ return EMPTY_TOKEN_ARRAY;
try {
while (true) {
//each # preprocessing token in the replacement list shall be followed
//by a parameter as the next reprocessing token in the list
if( t.getType() == tPOUND ){
- macroReplacementTokens.add( t );
+ if( currentIndex == macroReplacementTokens.length )
+ {
+ IToken [] doubled = new IToken[macroReplacementTokens.length * 2];
+ System.arraycopy( macroReplacementTokens, 0, doubled, 0, macroReplacementTokens.length );
+ macroReplacementTokens = doubled;
+ }
+ macroReplacementTokens[currentIndex++] = t;
t = helperScanner.nextToken(false);
if( parameterIdentifiers != null )
{
- int index = parameterIdentifiers.indexOf(t.getImage());
+ int index = findIndex( parameterIdentifiers, t.getImage());
if (index == -1 ) {
//not found
@@ -2703,13 +2713,19 @@ public class Scanner implements IScanner {
strbuff.append( replacementString );
handleProblem( IProblem.PREPROCESSOR_MACRO_PASTING_ERROR, strbuff.toString(),
beginning, false, true );
- return Collections.EMPTY_LIST;
+ return EMPTY_TOKEN_ARRAY;
}
}
}
}
- macroReplacementTokens.add(t);
+ if( currentIndex == macroReplacementTokens.length )
+ {
+ IToken [] doubled = new IToken[macroReplacementTokens.length * 2];
+ System.arraycopy( macroReplacementTokens, 0, doubled, 0, macroReplacementTokens.length );
+ macroReplacementTokens = doubled;
+ }
+ macroReplacementTokens[currentIndex++] = t;
t = helperScanner.nextToken(false);
}
}
@@ -2720,9 +2736,19 @@ public class Scanner implements IScanner {
{
}
- return macroReplacementTokens;
+ IToken [] result = new IToken[ currentIndex ];
+ System.arraycopy( macroReplacementTokens, 0, result, 0, currentIndex );
+ return result;
}
+ /**
+ * @return
+ */
+ IToken[] getTokenBuffer() {
+ Arrays.fill( tokenArrayBuffer, null );
+ return tokenArrayBuffer;
+ }
+
protected IMacroDescriptor createObjectMacroDescriptor(String key, String value ) {
IToken t = null;
if( !value.trim().equals( "" ) ) //$NON-NLS-1$
@@ -2788,21 +2814,21 @@ public class Scanner implements IScanner {
// replace StringTokenizer later -- not performant
StringTokenizer tokenizer = new StringTokenizer(parameters, ","); //$NON-NLS-1$
- ArrayList parameterIdentifiers =
- new ArrayList(tokenizer.countTokens());
+ String []parameterIdentifiers = new String[tokenizer.countTokens()];
+ int ct = 0;
while (tokenizer.hasMoreTokens()) {
- parameterIdentifiers.add(tokenizer.nextToken().trim());
+ parameterIdentifiers[ ct++ ] = tokenizer.nextToken().trim();
}
skipOverWhitespace();
- List macroReplacementTokens = null;
+ IToken [] macroReplacementTokens = null;
String replacementString = getRestOfPreprocessorLine();
// TODO: This tokenization could be done live, instead of using a sub-scanner.
macroReplacementTokens = ( ! replacementString.equals( "" ) ) ? //$NON-NLS-1$
tokenizeReplacementString( beginning, key, replacementString, parameterIdentifiers ) :
- Collections.EMPTY_LIST;
+ EMPTY_TOKEN_ARRAY;
descriptor = new FunctionMacroDescriptor(
key,
@@ -3059,10 +3085,10 @@ public class Scanner implements IScanner {
// create a string that represents what needs to be tokenized
- List tokens = expansion.getTokenizedExpansion();
- List parameterNames = expansion.getParameters();
+ IToken [] tokens = expansion.getTokenizedExpansion();
+ String [] parameterNames = expansion.getParameters();
- if (parameterNames.size() != parameterValues.size())
+ if (parameterNames.length != parameterValues.size())
{
handleProblem( IProblem.PREPROCESSOR_MACRO_USAGE_ERROR, symbol, getCurrentOffset(), false, true );
consumeUntilOutOfMacroExpansion();
@@ -3071,15 +3097,15 @@ public class Scanner implements IScanner {
strbuff.startString();
- int numberOfTokens = tokens.size();
+ int numberOfTokens = tokens.length;
for (int i = 0; i < numberOfTokens; ++i) {
- t = (SimpleToken) tokens.get(i);
+ t = (SimpleToken) tokens[i];
if (t.getType() == IToken.tIDENTIFIER) {
// is this identifier in the parameterNames
// list?
- int index = parameterNames.indexOf(t.getImage());
+ int index = findIndex( parameterNames, t.getImage() );
if (index == -1 ) {
// not found
// just add image to buffer
@@ -3099,13 +3125,13 @@ public class Scanner implements IScanner {
strbuff.append(cache);
}
++i;
- if( tokens.size() == i ){
+ if( tokens.length == i ){
handleProblem( IProblem.PREPROCESSOR_MACRO_USAGE_ERROR, expansion.getName(), getCurrentOffset(), false, true );
return;
}
- t = (SimpleToken) tokens.get( i );
- int index = parameterNames.indexOf(t.getImage());
+ t = (SimpleToken) tokens[ i ];
+ int index = findIndex( parameterNames, t.getImage());
if( index == -1 ){
handleProblem( IProblem.PREPROCESSOR_MACRO_USAGE_ERROR, expansion.getName(), getCurrentOffset(), false, true );
return;
@@ -3163,7 +3189,7 @@ public class Scanner implements IScanner {
if( i != numberOfTokens - 1)
{
- IToken t2 = (IToken) tokens.get(i+1);
+ IToken t2 = tokens[i+1];
if( t2.getType() == tPOUNDPOUND ) {
pastingNext = true;
i++;
@@ -3204,6 +3230,19 @@ public class Scanner implements IScanner {
}
+ /**
+ * @param parameterNames
+ * @param image
+ * @return
+ */
+ private int findIndex(String[] parameterNames, String image) {
+ for( int i = 0; i < parameterNames.length; ++i )
+ if( parameterNames[i].equals( image ) )
+ return i;
+
+ return -1;
+ }
+
protected String handleDefinedMacro() throws ScannerException {
int o = getCurrentOffset();
skipOverWhitespace();
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerUtility.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerUtility.java
index 87968ea05d..8e766d0bc2 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerUtility.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerUtility.java
@@ -12,6 +12,7 @@
import java.io.File;
import java.io.Reader;
import java.io.StringReader;
+
import java.util.Iterator;
import java.util.Vector;
@@ -37,7 +38,7 @@ public class ScannerUtility {
String [] segments = originalPath.split( "[/\\\\]" ); //$NON-NLS-1$
if( segments.length == 1 ) return originalPath;
- Vector results = new Vector();
+ Vector results = new Vector(segments.length);
for( int i = 0; i < segments.length; ++i )
{
String segment = segments[i];
@@ -51,11 +52,10 @@ public class ScannerUtility {
results.add( segment );
}
strbuff.startString();
- Iterator i = results.iterator();
- while( i.hasNext() )
+ for( int i = 0; i < results.size(); ++i )
{
- strbuff.append( (String)i.next() );
- if( i.hasNext() )
+ strbuff.append( (String)results.elementAt(i) );
+ if( i != results.size() - 1 )
strbuff.append( File.separatorChar );
}
return strbuff.toString();

Back to the top