1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Made significant footprint improvements to the parser.

This commit is contained in:
John Camelon 2004-05-18 20:41:15 +00:00
parent 245a435785
commit 4abe159ab8
25 changed files with 393 additions and 638 deletions

View file

@ -1832,4 +1832,9 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
assertFalse( localVariables.hasNext() ); assertFalse( localVariables.hasNext() );
assertAllReferences( 4, createTaskList( new Task( ABC, 2 ), new Task( variable ), new Task( destructor ))); assertAllReferences( 4, createTaskList( new Task( ABC, 2 ), new Task( variable ), new Task( destructor )));
} }
public void testBug39676_tough() throws Exception
{
parse( "int widths[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 };", true, ParserLanguage.C ); //$NON-NLS-1$
}
} }

View file

@ -2222,10 +2222,6 @@ public class QuickParseASTTests extends BaseASTTest
parse("struct file_operations driver_fops = { open: device_open, release: device_release };", true, true, ParserLanguage.C ).getDeclarations(); //$NON-NLS-1$ parse("struct file_operations driver_fops = { open: device_open, release: device_release };", true, true, ParserLanguage.C ).getDeclarations(); //$NON-NLS-1$
} }
public void testBug39676_tough() throws Exception
{
parse( "int widths[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 };", true, true, ParserLanguage.C ); //$NON-NLS-1$
}
public void testBug60142() throws Exception public void testBug60142() throws Exception
{ {

View file

@ -1,20 +0,0 @@
/*******************************************************************************
* Copyright (c) 2000 - 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.parser;
/**
* @author jcamelon
*/
public interface INumericToken extends IToken {
public long getIntegerValue();
}

View file

@ -117,8 +117,6 @@ public interface IToken {
static public final int tASSIGN = 38; static public final int tASSIGN = 38;
static public final int tHEXINT = 39;
static public final int tSHIFTL = 40; static public final int tSHIFTL = 40;
static public final int tLTEQUAL = 41; static public final int tLTEQUAL = 41;

View file

@ -122,11 +122,6 @@ public interface IASTFactory
IASTTypeId typeId, IASTTypeId typeId,
ITokenDuple idExpression, String literal, IASTNewExpressionDescriptor newDescriptor) throws ASTSemanticException; ITokenDuple idExpression, String literal, IASTNewExpressionDescriptor newDescriptor) throws ASTSemanticException;
public IASTExpression createExpression(
IASTExpression.Kind kind,
long literal,
boolean isHex) throws ASTSemanticException;
public IASTExpression.IASTNewExpressionDescriptor createNewDescriptor(List newPlacementExpressions,List newTypeIdExpressions,List newInitializerExpressions); public IASTExpression.IASTNewExpressionDescriptor createNewDescriptor(List newPlacementExpressions,List newTypeIdExpressions,List newInitializerExpressions);
public IASTInitializerClause createInitializerClause( public IASTInitializerClause createInitializerClause(
@ -277,5 +272,6 @@ public interface IASTFactory
*/ */
public boolean validateDirectMemberOperation(IASTNode node); public boolean validateDirectMemberOperation(IASTNode node);
public void constructExpressions( boolean flag );
} }

View file

@ -30,6 +30,7 @@ import org.eclipse.cdt.core.parser.ast.IASTScope;
*/ */
public class Declarator implements IParameterCollection, IDeclaratorOwner, IDeclarator public class Declarator implements IParameterCollection, IDeclaratorOwner, IDeclarator
{ {
private static final int DEFAULT_ARRAYLIST_SIZE = 4;
private boolean hasFunctionTryBlock; private boolean hasFunctionTryBlock;
private ITokenDuple pointerOperatorNameDuple; private ITokenDuple pointerOperatorNameDuple;
private ITokenDuple namedDuple; private ITokenDuple namedDuple;
@ -41,17 +42,16 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
private Declarator ownedDeclarator = null; private Declarator ownedDeclarator = null;
private String name = ""; //$NON-NLS-1$ private String name = ""; //$NON-NLS-1$
private IASTInitializerClause initializerClause = null; private IASTInitializerClause initializerClause = null;
private List ptrOps = new ArrayList();
private List parameters = new ArrayList();
private List arrayModifiers = new ArrayList();
private List constructorMemberInitializers = new ArrayList();
private IASTExceptionSpecification exceptionSpecification = null; private IASTExceptionSpecification exceptionSpecification = null;
private IASTExpression bitFieldExpression = null; private IASTExpression bitFieldExpression = null;
private boolean isConst = false; private boolean isConst = false;
private boolean isVolatile = false; private boolean isVolatile = false;
private boolean isKandR = false; private boolean isKandR = false;
private List ptrOps = Collections.EMPTY_LIST;
private List parameters = Collections.EMPTY_LIST;
private List arrayModifiers = Collections.EMPTY_LIST;
private List constructorMemberInitializers = Collections.EMPTY_LIST;
private int nameStartOffset, nameEndOffset; private int nameStartOffset, nameEndOffset;
private boolean varArgs; private boolean varArgs;
private int nameLine; private int nameLine;
@ -132,6 +132,9 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
public void addPointerOperator( ASTPointerOperator ptrOp ) public void addPointerOperator( ASTPointerOperator ptrOp )
{ {
if( ptrOps == Collections.EMPTY_LIST )
ptrOps = new ArrayList( DEFAULT_ARRAYLIST_SIZE );
ptrOps.add( ptrOp ); ptrOps.add( ptrOp );
} }
/** /**
@ -144,6 +147,9 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
public void addParameter( DeclarationWrapper param ) public void addParameter( DeclarationWrapper param )
{ {
if( parameters == Collections.EMPTY_LIST )
parameters = new ArrayList( DEFAULT_ARRAYLIST_SIZE );
parameters.add( param ); parameters.add( param );
} }
/** /**
@ -271,6 +277,8 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
*/ */
public void addArrayModifier(IASTArrayModifier arrayMod) public void addArrayModifier(IASTArrayModifier arrayMod)
{ {
if( arrayModifiers == Collections.EMPTY_LIST )
arrayModifiers = new ArrayList( DEFAULT_ARRAYLIST_SIZE );
arrayModifiers.add( arrayMod ); arrayModifiers.add( arrayMod );
} }
@ -319,6 +327,9 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
*/ */
public void addConstructorMemberInitializer(IASTConstructorMemberInitializer initializer) public void addConstructorMemberInitializer(IASTConstructorMemberInitializer initializer)
{ {
if( constructorMemberInitializers == Collections.EMPTY_LIST )
constructorMemberInitializers = new ArrayList( DEFAULT_ARRAYLIST_SIZE );
constructorMemberInitializers.add( initializer ); constructorMemberInitializers.add( initializer );
} }

View file

@ -17,7 +17,6 @@ import java.util.Stack;
import org.eclipse.cdt.core.parser.BacktrackException; import org.eclipse.cdt.core.parser.BacktrackException;
import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.EndOfFileException;
import org.eclipse.cdt.core.parser.INumericToken;
import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IParserLogService;
import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.IToken;
@ -388,16 +387,20 @@ public class ExpressionParser implements IExpressionParser, IParserData {
*/ */
protected ITokenDuple name(IASTScope scope, IASTCompletionNode.CompletionKind kind, Key key ) throws BacktrackException, EndOfFileException { protected ITokenDuple name(IASTScope scope, IASTCompletionNode.CompletionKind kind, Key key ) throws BacktrackException, EndOfFileException {
TemplateParameterManager argumentList = TemplateParameterManager.getInstance();
try
{
IToken first = LA(1); IToken first = LA(1);
IToken last = null; IToken last = null;
IToken mark = mark(); IToken mark = mark();
List argumentList = new LinkedList();
boolean hasTemplateId = false; boolean hasTemplateId = false;
boolean startsWithColonColon = false; boolean startsWithColonColon = false;
if (LT(1) == IToken.tCOLONCOLON){ if (LT(1) == IToken.tCOLONCOLON){
argumentList.add( null ); argumentList.addSegment( null );
last = consume( IToken.tCOLONCOLON ); last = consume( IToken.tCOLONCOLON );
setCompletionValues( scope, kind, Key.EMPTY, getCompliationUnit() ); setCompletionValues( scope, kind, Key.EMPTY, getCompliationUnit() );
startsWithColonColon = true; startsWithColonColon = true;
@ -455,9 +458,14 @@ public class ExpressionParser implements IExpressionParser, IParserData {
} }
} }
ITokenDuple tokenDuple = new TokenDuple(first, last, ( hasTemplateId ? argumentList : null ) ); ITokenDuple tokenDuple = new TokenDuple(first, last, ( hasTemplateId ? argumentList.getTemplateArgumentsList() : null ) );
setGreaterNameContext( tokenDuple ); setGreaterNameContext( tokenDuple );
return tokenDuple; return tokenDuple;
}
finally
{
TemplateParameterManager.returnInstance( argumentList );
}
} }
@ -514,22 +522,22 @@ public class ExpressionParser implements IExpressionParser, IParserData {
* @throws EndOfFileException * @throws EndOfFileException
* @throws BacktrackException * @throws BacktrackException
*/ */
protected IToken consumeTemplateArguments(IASTScope scope, IToken last, List argumentList) throws EndOfFileException, BacktrackException { protected IToken consumeTemplateArguments(IASTScope scope, IToken last, TemplateParameterManager argumentList) throws EndOfFileException, BacktrackException {
if( LT(1) == IToken.tLT ){ if( LT(1) == IToken.tLT ){
IToken secondMark = mark(); IToken secondMark = mark();
consume( IToken.tLT ); consume( IToken.tLT );
try try
{ {
List list = templateArgumentList( scope ); List list = templateArgumentList( scope );
argumentList.add( list ); argumentList.addSegment( list );
last = consume( IToken.tGT ); last = consume( IToken.tGT );
} catch( BacktrackException bt ) } catch( BacktrackException bt )
{ {
argumentList.add( null ); argumentList.addSegment( null );
backup( secondMark ); backup( secondMark );
} }
} else { } else {
argumentList.add( null ); argumentList.addSegment( null );
} }
return last; return last;
} }
@ -608,7 +616,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
} }
} }
protected void operatorId(Declarator d, IToken originalToken, List templateArgs) throws BacktrackException, EndOfFileException { protected void operatorId(Declarator d, IToken originalToken, TemplateParameterManager templateArgs) throws BacktrackException, EndOfFileException {
// we know this is an operator // we know this is an operator
IToken operatorToken = consume(IToken.t_operator); IToken operatorToken = consume(IToken.t_operator);
IToken toSend = null; IToken toSend = null;
@ -648,19 +656,32 @@ public class ExpressionParser implements IExpressionParser, IParserData {
toSend = lastToken; toSend = lastToken;
} }
List args = ( templateArgs != null ) ? templateArgs : new LinkedList();
boolean hasTemplateId = ( templateArgs != null ); boolean hasTemplateId = ( templateArgs != null );
boolean grabbedNewInstance = false;
if( templateArgs == null )
{
templateArgs = TemplateParameterManager.getInstance();
grabbedNewInstance = true;
}
toSend = consumeTemplateArguments( d.getDeclarationWrapper().getScope(), toSend, args ); try
{
toSend = consumeTemplateArguments( d.getDeclarationWrapper().getScope(), toSend, templateArgs );
if( toSend.getType() == IToken.tGT ){ if( toSend.getType() == IToken.tGT ){
hasTemplateId = true; hasTemplateId = true;
} }
ITokenDuple duple = ITokenDuple duple =
new TokenDuple( originalToken == null ? operatorToken : originalToken, toSend, (hasTemplateId ? args : null ) ); new TokenDuple( originalToken == null ? operatorToken : originalToken, toSend, (hasTemplateId ? templateArgs.getTemplateArgumentsList() : null ) );
d.setName(duple); d.setName(duple);
} }
finally
{
if( grabbedNewInstance )
TemplateParameterManager.returnInstance( templateArgs );
}
}
/** /**
* Parse a Pointer Operator. * Parse a Pointer Operator.
@ -1495,6 +1516,9 @@ public class ExpressionParser implements IExpressionParser, IParserData {
private CompletionKind getCastExpressionKind(CompletionKind kind) { private CompletionKind getCastExpressionKind(CompletionKind kind) {
return ((kind == CompletionKind.SINGLE_NAME_REFERENCE || kind == CompletionKind.FUNCTION_REFERENCE)? kind : CompletionKind.TYPE_REFERENCE); return ((kind == CompletionKind.SINGLE_NAME_REFERENCE || kind == CompletionKind.FUNCTION_REFERENCE)? kind : CompletionKind.TYPE_REFERENCE);
} }
/** /**
* @param completionKind TODO * @param completionKind TODO
* @throws BacktrackException * @throws BacktrackException
@ -1658,7 +1682,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
if( kind == null ) if( kind == null )
throw backtrack; throw backtrack;
TypeId id = new TypeId(scope); TypeId id = TypeId.getInstance(scope);
IToken last = lastToken; IToken last = lastToken;
//template parameters are consumed as part of name //template parameters are consumed as part of name
@ -2013,7 +2037,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
{ {
unaryExpression = unaryExpression(scope,kind, key); unaryExpression = unaryExpression(scope,kind, key);
} }
if (d != null & unaryExpression == null) if (unaryExpression == null)
try try
{ {
return astFactory.createExpression( return astFactory.createExpression(
@ -2033,7 +2057,6 @@ public class ExpressionParser implements IExpressionParser, IParserData {
logException( "unaryExpression_1::createExpression()", e ); //$NON-NLS-1$ logException( "unaryExpression_1::createExpression()", e ); //$NON-NLS-1$
throw backtrack; throw backtrack;
} }
else if (unaryExpression != null && d == null)
try try
{ {
return astFactory.createExpression( return astFactory.createExpression(
@ -2053,8 +2076,6 @@ public class ExpressionParser implements IExpressionParser, IParserData {
logException( "unaryExpression_1::createExpression()", e ); //$NON-NLS-1$ logException( "unaryExpression_1::createExpression()", e ); //$NON-NLS-1$
throw backtrack; throw backtrack;
} }
else
throw backtrack;
case IToken.t_new : case IToken.t_new :
return newExpression(scope,key); return newExpression(scope,key);
case IToken.t_delete : case IToken.t_delete :
@ -2535,15 +2556,9 @@ public class ExpressionParser implements IExpressionParser, IParserData {
{ {
// TO DO: we need more literals... // TO DO: we need more literals...
case IToken.tINTEGER : case IToken.tINTEGER :
case IToken.tHEXINT:
t = consume(); t = consume();
boolean isHex = ( t.getType() == IToken.tHEXINT );
try try
{ {
if( t instanceof INumericToken )
return astFactory.createExpression(
IASTExpression.Kind.PRIMARY_INTEGER_LITERAL,
((INumericToken)t).getIntegerValue(), isHex);
return astFactory.createExpression( scope, IASTExpression.Kind.PRIMARY_INTEGER_LITERAL, null, null, null, null, null, t.getImage(), null ); return astFactory.createExpression( scope, IASTExpression.Kind.PRIMARY_INTEGER_LITERAL, null, null, null, null, null, t.getImage(), null );
} }
catch (ASTSemanticException e1) catch (ASTSemanticException e1)

View file

@ -436,7 +436,6 @@ public class GCCParserExtension implements IParserExtension {
Map extensionParms = new Hashtable(); Map extensionParms = new Hashtable();
extensionParms.put( IASTGCCDesignator.SECOND_EXRESSION, constantExpression2 ); extensionParms.put( IASTGCCDesignator.SECOND_EXRESSION, constantExpression2 );
return parserData.getAstFactory().createDesignator( IASTGCCDesignator.DesignatorKind.SUBSCRIPT_RANGE, constantExpression1, null, extensionParms ); return parserData.getAstFactory().createDesignator( IASTGCCDesignator.DesignatorKind.SUBSCRIPT_RANGE, constantExpression1, null, extensionParms );
} }
} }
catch( EndOfFileException eof ) catch( EndOfFileException eof )

View file

@ -12,7 +12,6 @@ package org.eclipse.cdt.internal.core.parser;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.parser.BacktrackException; import org.eclipse.cdt.core.parser.BacktrackException;
@ -75,6 +74,7 @@ import org.eclipse.cdt.internal.core.parser.util.TraceUtil;
*/ */
public abstract class Parser extends ExpressionParser implements IParser public abstract class Parser extends ExpressionParser implements IParser
{ {
private static final int DEFAULT_DESIGNATOR_LIST_SIZE = 4;
protected ISourceElementRequestor requestor = null; protected ISourceElementRequestor requestor = null;
/** /**
@ -1810,6 +1810,10 @@ public abstract class Parser extends ExpressionParser implements IParser
throws EndOfFileException, BacktrackException throws EndOfFileException, BacktrackException
{ {
Declarator d = declarator(sdw, sdw.getScope(), strategy, kind ); Declarator d = declarator(sdw, sdw.getScope(), strategy, kind );
try
{
astFactory.constructExpressions(constructInitializers);
if( language == ParserLanguage.CPP ) if( language == ParserLanguage.CPP )
optionalCPPInitializer(d, constructInitializers); optionalCPPInitializer(d, constructInitializers);
else if( language == ParserLanguage.C ) else if( language == ParserLanguage.C )
@ -1817,6 +1821,11 @@ public abstract class Parser extends ExpressionParser implements IParser
sdw.addDeclarator(d); sdw.addDeclarator(d);
return d; return d;
} }
finally
{
astFactory.constructExpressions( true );
}
}
protected void optionalCPPInitializer(Declarator d, boolean constructInitializers) protected void optionalCPPInitializer(Declarator d, boolean constructInitializers)
throws EndOfFileException, BacktrackException throws EndOfFileException, BacktrackException
@ -2046,7 +2055,7 @@ public abstract class Parser extends ExpressionParser implements IParser
protected List designatorList(IASTScope scope) throws EndOfFileException, BacktrackException protected List designatorList(IASTScope scope) throws EndOfFileException, BacktrackException
{ {
List designatorList = new ArrayList(); List designatorList = Collections.EMPTY_LIST;
// designated initializers for C // designated initializers for C
if( LT(1) == IToken.tDOT || LT(1) == IToken.tLBRACKET ) if( LT(1) == IToken.tDOT || LT(1) == IToken.tLBRACKET )
@ -2075,7 +2084,11 @@ public abstract class Parser extends ExpressionParser implements IParser
{ {
IASTDesignator d = extension.parseDesignator( this, scope ); IASTDesignator d = extension.parseDesignator( this, scope );
if( d != null ) if( d != null )
{
if( designatorList == Collections.EMPTY_LIST )
designatorList = new ArrayList( DEFAULT_DESIGNATOR_LIST_SIZE );
designatorList.add( d ); designatorList.add( d );
}
break; break;
} }
} }
@ -2085,6 +2098,8 @@ public abstract class Parser extends ExpressionParser implements IParser
IASTDesignator d = IASTDesignator d =
astFactory.createDesignator( kind, constantExpression, id, null ); astFactory.createDesignator( kind, constantExpression, id, null );
if( designatorList == Collections.EMPTY_LIST )
designatorList = new ArrayList( DEFAULT_DESIGNATOR_LIST_SIZE );
designatorList.add( d ); designatorList.add( d );
} }
@ -2095,9 +2110,13 @@ public abstract class Parser extends ExpressionParser implements IParser
{ {
IASTDesignator d = extension.parseDesignator( this, scope ); IASTDesignator d = extension.parseDesignator( this, scope );
if( d != null ) if( d != null )
{
if( designatorList == Collections.EMPTY_LIST )
designatorList = new ArrayList( DEFAULT_DESIGNATOR_LIST_SIZE );
designatorList.add( d ); designatorList.add( d );
} }
} }
}
return designatorList; return designatorList;
} }
/** /**
@ -2337,6 +2356,9 @@ public abstract class Parser extends ExpressionParser implements IParser
protected void consumeTemplatedOperatorName(Declarator d, CompletionKind kind) protected void consumeTemplatedOperatorName(Declarator d, CompletionKind kind)
throws EndOfFileException, BacktrackException throws EndOfFileException, BacktrackException
{
TemplateParameterManager argumentList = TemplateParameterManager.getInstance();
try
{ {
if (LT(1) == IToken.t_operator) if (LT(1) == IToken.t_operator)
operatorId(d, null, null); operatorId(d, null, null);
@ -2354,7 +2376,6 @@ public abstract class Parser extends ExpressionParser implements IParser
Declarator d11 = d1; Declarator d11 = d1;
IToken start = null; IToken start = null;
List argumentList = new LinkedList();
boolean hasTemplateId = false; boolean hasTemplateId = false;
IToken mark = mark(); IToken mark = mark();
@ -2384,12 +2405,17 @@ public abstract class Parser extends ExpressionParser implements IParser
operatorId(d11, start, ( hasTemplateId ? argumentList : null ) ); operatorId(d11, start, ( hasTemplateId ? argumentList : null ) );
else else
{ {
backup(mark); backup(mark);
throw backtrack; throw backtrack;
} }
} }
} }
} }
} finally
{
TemplateParameterManager.returnInstance(argumentList );
}
} }
/** /**
* Parse an enumeration specifier, as according to the ANSI specs in C & C++. * Parse an enumeration specifier, as according to the ANSI specs in C & C++.

View file

@ -0,0 +1,102 @@
/**********************************************************************
* Copyright (c) 2002-2004 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.core.parser;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
final class TemplateParameterManager
{
protected void reset()
{
list = Collections.EMPTY_LIST;
emptySegmentCount = 0;
}
private TemplateParameterManager(int i)
{
reset();
counterId = i;
}
private final int counterId;
private List list;
private int emptySegmentCount;
public List getTemplateArgumentsList()
{
return list;
}
public void addSegment( List inputSegment )
{
if( inputSegment == null )
{
if( list == Collections.EMPTY_LIST )
++emptySegmentCount;
else
list.add( null );
}
else
{
if( list == Collections.EMPTY_LIST )
{
list = new ArrayList();
for( int i = 0; i < emptySegmentCount; ++i )
list.add( null );
}
list.add( inputSegment );
}
}
private static final int NUMBER_OF_INSTANCES = 8;
private static final boolean [] instancesUsed = new boolean[ NUMBER_OF_INSTANCES ];
private static final TemplateParameterManager [] counters = new TemplateParameterManager[ NUMBER_OF_INSTANCES ];
private static int counter = 8;
static
{
for( int i = 0; i < NUMBER_OF_INSTANCES; ++i )
{
instancesUsed[ i ] = false;
counters[ i ] = new TemplateParameterManager( i );
}
}
/**
* @return
*/
public static TemplateParameterManager getInstance() {
int index = findFreeCounter();
if( index == -1 )
return new TemplateParameterManager(++counter);
instancesUsed[ index ] = true;
return counters[ index ];
}
public static void returnInstance( TemplateParameterManager c )
{
if( c.counterId > 0 && c.counterId < NUMBER_OF_INSTANCES )
instancesUsed[ c.counterId ] = false;
c.reset();
}
/**
* @return
*/
private static int findFreeCounter() {
for( int i = 0; i < NUMBER_OF_INSTANCES; ++i )
if( instancesUsed[i] == false )
return i;
return -1;
}
}

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.internal.core.parser; package org.eclipse.cdt.internal.core.parser;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.ITokenDuple;
@ -24,16 +25,33 @@ import org.eclipse.cdt.core.parser.ast.IASTScope;
*/ */
public class TypeId implements IDeclarator public class TypeId implements IDeclarator
{ {
private static final int DEFAULT_ARRAYLIST_SIZE = 4;
private ITokenDuple name; private ITokenDuple name;
private List arrayModifiers = new ArrayList(); private List arrayModifiers;
private List pointerOperators = new ArrayList(); private List pointerOperators;
private final IASTScope scope; private IASTScope scope;
private static TypeId instance = new TypeId();
public static TypeId getInstance(IASTScope scope)
{
instance.reset(scope);
return instance;
}
/**
* @param scope2
*/
private void reset(IASTScope s) {
this.scope = s;
arrayModifiers = Collections.EMPTY_LIST;
pointerOperators = Collections.EMPTY_LIST;
name = null;
}
/** /**
* *
*/ */
public TypeId(IASTScope scope ) private TypeId()
{ {
this.scope = scope; reset( null );
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IDeclarator#getPointerOperators() * @see org.eclipse.cdt.internal.core.parser.IDeclarator#getPointerOperators()
@ -47,6 +65,8 @@ public class TypeId implements IDeclarator
*/ */
public void addPointerOperator(ASTPointerOperator ptrOp) public void addPointerOperator(ASTPointerOperator ptrOp)
{ {
if( pointerOperators == Collections.EMPTY_LIST )
pointerOperators = new ArrayList( DEFAULT_ARRAYLIST_SIZE );
pointerOperators.add( ptrOp ); pointerOperators.add( ptrOp );
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -54,6 +74,8 @@ public class TypeId implements IDeclarator
*/ */
public void addArrayModifier(IASTArrayModifier arrayMod) public void addArrayModifier(IASTArrayModifier arrayMod)
{ {
if( arrayModifiers == Collections.EMPTY_LIST )
arrayModifiers = new ArrayList( DEFAULT_ARRAYLIST_SIZE );
arrayModifiers.add( arrayMod ); arrayModifiers.add( arrayMod );
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -1,41 +0,0 @@
/*******************************************************************************
* Copyright (c) 2000 - 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.Collections;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
/**
* @author jcamelon
*/
public class ASTLiteralIntegerExpression extends ASTExpression implements IASTExpression {
private final boolean isHex;
private final long literal;
/**
* @param kind
* @param literal
* @param isHex
*/
public ASTLiteralIntegerExpression(Kind kind, long literal, boolean isHex) {
super( kind, Collections.EMPTY_LIST );
this.literal = literal;
this.isHex = isHex;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getLiteralString()
*/
public String getLiteralString() {
if( isHex )
return Long.toHexString( literal );
return Long.toString( literal );
}
}

View file

@ -2641,6 +2641,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
{ {
ISymbol variableSymbol = ((ASTVariable)clause.getOwnerVariableDeclaration()).getSymbol(); ISymbol variableSymbol = ((ASTVariable)clause.getOwnerVariableDeclaration()).getSymbol();
ISymbol currentSymbol = variableSymbol.getTypeSymbol(); ISymbol currentSymbol = variableSymbol.getTypeSymbol();
if( currentSymbol == null )
return;
TypeInfo currentTypeInfo = new TypeInfo( currentSymbol.getTypeInfo() ); TypeInfo currentTypeInfo = new TypeInfo( currentSymbol.getTypeInfo() );
Iterator designators = clause.getDesignators(); Iterator designators = clause.getDesignators();
@ -3552,21 +3554,10 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExpression(org.eclipse.cdt.core.parser.ast.IASTExpression.Kind, long, boolean) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#constructExpressions(boolean)
*/ */
public IASTExpression createExpression(Kind kind, long literal, boolean isHex) throws ASTSemanticException { public void constructExpressions(boolean flag) {
//ignore
// Try to figure out the result that this expression evaluates to
ExpressionResult expressionResult = getExpressionResultType(null, kind, null, null, null, null, Long.toString(literal), null);
// expression results could be empty, but should not be null
// assert expressionResult != null : expressionResult; //throw new ASTSemanticException();
// create the ASTExpression
ASTExpression expression = (ASTExpression) ExpressionFactory.createExpression( kind, literal, isHex );
// Assign the result to the created expression
expression.setResultType (expressionResult);
return expression;
} }
} }

View file

@ -52,14 +52,4 @@ public class ExpressionFactory {
return new ASTEmptyExpression( kind, references ); return new ASTEmptyExpression( kind, references );
} }
/**
* @param kind
* @param literal
* @param isHex
* @return
*/
public static IASTExpression createExpression(Kind kind, long literal, boolean isHex) {
return new ASTLiteralIntegerExpression( kind, literal, isHex );
}
} }

View file

@ -1,60 +0,0 @@
/*******************************************************************************
* Copyright (c) 2000 - 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.expression;
import org.eclipse.cdt.core.parser.ast.ASTExpressionEvaluationException;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
/**
* @author jcamelon
*/
public class ASTLiteralIntegerExpression extends ASTExpression
implements
IASTExpression {
private final long literal;
private final boolean isHex;
/**
* @param kind
* @param literal
*/
public ASTLiteralIntegerExpression(Kind kind, long literal, boolean isHex) {
super( kind );
this.literal = literal;
this.isHex = isHex;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getLiteralString()
*/
public String getLiteralString() {
if( isHex )
{
StringBuffer x = new StringBuffer( "0x"); //$NON-NLS-1$
x.append( Long.toHexString(literal));
return x.toString();
}
return Long.toString( literal );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#evaluateExpression()
*/
public long evaluateExpression() throws ASTExpressionEvaluationException {
if( getExpressionKind() == IASTExpression.Kind.PRIMARY_INTEGER_LITERAL )
return literal;
return super.evaluateExpression();
}
}

View file

@ -26,7 +26,6 @@ public class ExpressionFactory {
*/ */
public ExpressionFactory() { public ExpressionFactory() {
super(); super();
// TODO Auto-generated constructor stub
} }
/** /**
@ -68,19 +67,4 @@ public class ExpressionFactory {
return new ASTEmptyExpression( kind ); return new ASTEmptyExpression( kind );
} }
/**
* @param kind
* @param lhs
* @param rhs
* @param thirdExpression
* @param typeId
* @param string
* @param literal
* @param newDescriptor
* @return
*/
public static IASTExpression createExpression(Kind kind, long literal, boolean isHex) {
return new ASTLiteralIntegerExpression( kind, literal, isHex );
}
} }

View file

@ -908,10 +908,10 @@ public class ExpressionParseASTFactory extends BaseASTFactory implements IASTFac
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExpression(org.eclipse.cdt.core.parser.ast.IASTScope, org.eclipse.cdt.core.parser.ast.IASTExpression.Kind, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTTypeId, org.eclipse.cdt.core.parser.ITokenDuple, int, org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#constructExpressions(boolean)
*/ */
public IASTExpression createExpression(Kind kind, long literal, boolean isHex) throws ASTSemanticException { public void constructExpressions(boolean flag) {
return ExpressionFactory.createExpression( kind, literal, isHex ); //ignore
} }
} }

View file

@ -10,8 +10,8 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.quick; package org.eclipse.cdt.internal.core.parser.ast.quick;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ISourceElementRequestor;
@ -19,6 +19,7 @@ import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
import org.eclipse.cdt.core.parser.ast.IASTDeclaration; import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator;
import org.eclipse.cdt.internal.core.parser.ast.Offsets; import org.eclipse.cdt.internal.core.parser.ast.Offsets;
/** /**
@ -47,7 +48,7 @@ public class ASTTemplateDeclaration extends ASTDeclaration implements IASTTempla
*/ */
public Iterator getTemplateParameters() public Iterator getTemplateParameters()
{ {
return ( templateParameters != null ) ? templateParameters.iterator() : new LinkedList().iterator(); return ( templateParameters != null ) ? templateParameters.iterator() : EmptyIterator.EMPTY_ITERATOR;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration#getOwnedDeclaration() * @see org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration#getOwnedDeclaration()
@ -157,7 +158,7 @@ public class ASTTemplateDeclaration extends ASTDeclaration implements IASTTempla
* @see org.eclipse.cdt.core.parser.ast.IASTScope#getDeclarations() * @see org.eclipse.cdt.core.parser.ast.IASTScope#getDeclarations()
*/ */
public Iterator getDeclarations() throws ASTNotImplementedException { public Iterator getDeclarations() throws ASTNotImplementedException {
List decls = new LinkedList(); List decls = new ArrayList(1);
decls.add( getOwnedDeclaration() ); decls.add( getOwnedDeclaration() );
return decls.iterator(); return decls.iterator();
} }

View file

@ -18,7 +18,6 @@ import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.core.parser.ast.ASTClassKind; import org.eclipse.cdt.core.parser.ast.ASTClassKind;
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; import org.eclipse.cdt.core.parser.ast.ASTPointerOperator;
import org.eclipse.cdt.core.parser.ast.ASTSemanticException;
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
@ -70,6 +69,8 @@ import org.eclipse.cdt.internal.core.parser.ast.expression.ExpressionFactory;
*/ */
public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory { public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory {
private boolean temporarilyDisableNodeConstruction = true;
public QuickParseASTFactory( IASTFactoryExtension extension ) public QuickParseASTFactory( IASTFactoryExtension extension )
{ {
super(extension); super(extension);
@ -158,7 +159,7 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExpression(org.eclipse.cdt.core.parser.ast.IASTExpression.ExpressionKind, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTExpression, java.lang.String, java.lang.String, java.lang.String) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExpression(org.eclipse.cdt.core.parser.ast.IASTExpression.ExpressionKind, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTExpression, java.lang.String, java.lang.String, java.lang.String)
*/ */
public IASTExpression createExpression(IASTScope scope, Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression, IASTTypeId typeId, ITokenDuple idExpression, String literal, IASTNewExpressionDescriptor newDescriptor) { public IASTExpression createExpression(IASTScope scope, Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression, IASTTypeId typeId, ITokenDuple idExpression, String literal, IASTNewExpressionDescriptor newDescriptor) {
return ExpressionFactory.createExpression( kind, lhs, rhs, thirdExpression, typeId, idExpression == null ? "" : idExpression.toString(), literal, newDescriptor ); //$NON-NLS-1$ return temporarilyDisableNodeConstruction ? ExpressionFactory.createExpression( kind, lhs, rhs, thirdExpression, typeId, idExpression == null ? "" : idExpression.toString(), literal, newDescriptor ) : null; //$NON-NLS-1$
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -323,8 +324,8 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
public IASTTypeId createTypeId(IASTScope scope, Type kind, boolean isConst, boolean isVolatile, boolean isShort, public IASTTypeId createTypeId(IASTScope scope, Type kind, boolean isConst, boolean isVolatile, boolean isShort,
boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, ITokenDuple name, List pointerOps, List arrayMods, String completeSignature) boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, ITokenDuple name, List pointerOps, List arrayMods, String completeSignature)
{ {
return new ASTTypeId( kind, name == null ? "" : name.toString(), pointerOps, arrayMods, isConst, //$NON-NLS-1$ return ( temporarilyDisableNodeConstruction ? new ASTTypeId( kind, name == null ? "" : name.toString(), pointerOps, arrayMods, isConst, //$NON-NLS-1$
isVolatile, isUnsigned, isSigned, isShort, isLong, isTypename, completeSignature ); isVolatile, isUnsigned, isSigned, isShort, isLong, isTypename, completeSignature ) : null );
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -385,9 +386,9 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExpression(org.eclipse.cdt.core.parser.ast.IASTExpression.Kind, long, boolean) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#constructExpressions(boolean)
*/ */
public IASTExpression createExpression(Kind kind, long literal, boolean isHex) throws ASTSemanticException { public void constructExpressions(boolean flag) {
return ExpressionFactory.createExpression(kind, literal, isHex ); temporarilyDisableNodeConstruction = flag;
} }
} }

View file

@ -470,13 +470,7 @@ public class Scanner implements IScanner {
} }
protected IToken newToken(int t, String i) { protected IToken newToken(int t, String i) {
IToken token = null; IToken token = TokenFactory.createUniquelyImagedToken(t, i, scannerData );
if( t == IToken.tINTEGER )
token = TokenFactory.createIntegerToken( i, scannerData );
else if( t == IToken.tHEXINT )
token = TokenFactory.createHexadecimalIntegerToken( i, scannerData );
else
token = TokenFactory.createUniquelyImagedToken(t, i, scannerData );
setCurrentToken(token); setCurrentToken(token);
return currentToken; return currentToken;
} }
@ -1127,7 +1121,6 @@ public class Scanner implements IScanner {
handleProblem( IProblem.SCANNER_BAD_HEX_FORMAT, HEX_PREFIX, beginOffset, false, true ); handleProblem( IProblem.SCANNER_BAD_HEX_FORMAT, HEX_PREFIX, beginOffset, false, true );
return null; return null;
} }
tokenType = IToken.tHEXINT;
} }
return newToken( return newToken(

View file

@ -1,67 +0,0 @@
/*******************************************************************************
* Copyright (c) 2000 - 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.parser.token;
import org.eclipse.cdt.core.parser.INumericToken;
import org.eclipse.cdt.internal.core.parser.scanner.ContextStack;
/**
* @author jcamelon
*/
public class HexIntegerExpansionToken extends SimpleExpansionToken implements
INumericToken {
private final long intValue;
/**
* @param i
* @param value
* @param stack
*/
public HexIntegerExpansionToken(int type, String value, ContextStack stack) {
super( type, stack );
int minIndex = findMinIndex(value);
if( minIndex == -1 )
intValue = Long.parseLong(value.substring(2), 16 );
else
intValue = Long.parseLong(value.substring(2, minIndex), 16 );
setOffsetAndLength(stack.getCurrentContext());
}
/**
* @param value
* @return
*/
private int findMinIndex(String value) {
int endIndex = value.indexOf( "U"); //$NON-NLS-1$
int endIndex2 = value.indexOf( "L"); //$NON-NLS-1$
int minIndex = endIndex < endIndex2 ? endIndex : endIndex2;
return minIndex;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IToken#getImage()
*/
public String getImage() {
StringBuffer buffer = new StringBuffer( "0x" ); //$NON-NLS-1$
buffer.append( Long.toHexString(intValue) );
return buffer.toString();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.INumericToken#getIntegerValue()
*/
public long getIntegerValue() {
return intValue;
}
}

View file

@ -1,68 +0,0 @@
/*******************************************************************************
* Copyright (c) 2000 - 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.parser.token;
import org.eclipse.cdt.core.parser.INumericToken;
import org.eclipse.cdt.internal.core.parser.scanner.ContextStack;
/**
* @author jcamelon
*/
public class HexIntegerToken extends SimpleToken implements INumericToken {
private final long intValue;
/**
* @param i
* @param value
* @param stack
*/
public HexIntegerToken(int type, String value, ContextStack stack) {
super( type, stack );
int maxIndex = findMinIndex(value);
if( maxIndex > 2 )
intValue = Long.parseLong(value.substring(2, maxIndex), 16 );
else
intValue = Long.parseLong(value.substring(2), 16 );
setOffsetAndLength(stack.getCurrentContext());
}
/**
* @param value
* @return
*/
private int findMinIndex(String value) {
int endIndex = value.indexOf( "U"); //$NON-NLS-1$
int endIndex2 = value.indexOf( "L"); //$NON-NLS-1$
int minIndex = endIndex < endIndex2 ? endIndex : endIndex2;
return minIndex;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IToken#getImage()
*/
public String getImage() {
StringBuffer buffer = new StringBuffer( "0x" ); //$NON-NLS-1$
buffer.append( Long.toHexString(intValue) );
return buffer.toString();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.INumericToken#getIntegerValue()
*/
public long getIntegerValue() {
return intValue;
}
}

View file

@ -1,50 +0,0 @@
/*******************************************************************************
* Copyright (c) 2000 - 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.parser.token;
import org.eclipse.cdt.core.parser.INumericToken;
import org.eclipse.cdt.internal.core.parser.scanner.ContextStack;
/**
* @author jcamelon
*/
public class IntegerExpansionToken extends SimpleExpansionToken implements INumericToken
{
private final long value;
/**
* @param tokenType
* @param value
* @param stack
*/
public IntegerExpansionToken(int tokenType, long l, ContextStack stack) {
super( tokenType, stack );
this.value = l;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IToken#getImage()
*/
public String getImage() {
return Long.toString( value );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.INumericToken#getIntegerValue()
*/
public long getIntegerValue() {
return value;
}
}

View file

@ -1,47 +0,0 @@
/*******************************************************************************
* Copyright (c) 2000 - 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.parser.token;
import org.eclipse.cdt.core.parser.INumericToken;
import org.eclipse.cdt.internal.core.parser.scanner.ContextStack;
/**
* @author jcamelon
*/
public class IntegerToken extends SimpleToken implements INumericToken {
private final long value;
/**
* @param tokenType
* @param value
* @param stack
*/
public IntegerToken(int tokenType, long l, ContextStack stack) {
super( tokenType, stack );
this.value = l;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IToken#getImage()
*/
public String getImage() {
return Long.toString( value );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.INumericToken#getIntegerValue()
*/
public long getIntegerValue() {
return value;
}
}

View file

@ -24,28 +24,6 @@ public class TokenFactory {
static final String MAX_HEX_LONG_STRING = "0x" + Long.toString( Long.MAX_VALUE, 16 ); //$NON-NLS-1$ static final String MAX_HEX_LONG_STRING = "0x" + Long.toString( Long.MAX_VALUE, 16 ); //$NON-NLS-1$
static final int MAX_HEX_LONG_STRING_LENGTH = MAX_HEX_LONG_STRING.length(); static final int MAX_HEX_LONG_STRING_LENGTH = MAX_HEX_LONG_STRING.length();
public static IToken createIntegerToken( String value, IScannerData scannerData )
{
if( value.length() > MAX_LONG_STRING_LENGTH || value.compareTo( MAX_LONG_STRING ) > 0 )
return createUniquelyImagedToken( IToken.tINTEGER, value, scannerData );
if( scannerData.getContextStack().getCurrentContext().getKind() == IScannerContext.ContextKind.MACROEXPANSION )
return new IntegerExpansionToken( IToken.tINTEGER, Long.parseLong(value ), scannerData.getContextStack() );
return new IntegerToken( IToken.tINTEGER, Long.parseLong( value ), scannerData.getContextStack() );
}
public static IToken createHexadecimalIntegerToken( String value, IScannerData scannerData )
{
if( value.length() > MAX_HEX_LONG_STRING_LENGTH || value.compareTo( MAX_HEX_LONG_STRING ) > 0 )
return createUniquelyImagedToken( IToken.tHEXINT, value, scannerData );
if( scannerData.getContextStack().getCurrentContext().getKind() == IScannerContext.ContextKind.MACROEXPANSION )
return new HexIntegerExpansionToken( IToken.tHEXINT, value, scannerData.getContextStack() );
return new HexIntegerToken( IToken.tHEXINT, value, scannerData.getContextStack() );
}
public static IToken createToken( int tokenType, IScannerData scannerData ) public static IToken createToken( int tokenType, IScannerData scannerData )
{ {
if( scannerData.getContextStack().getCurrentContext().getKind() == IScannerContext.ContextKind.MACROEXPANSION ) if( scannerData.getContextStack().getCurrentContext().getKind() == IScannerContext.ContextKind.MACROEXPANSION )