1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 12:55:40 +02:00

Scalability/Memory enhancements upon the Parser framework.

This commit is contained in:
John Camelon 2004-05-10 21:25:39 +00:00
parent 524a819cac
commit 5b6bd37541
42 changed files with 1469 additions and 801 deletions

View file

@ -51,9 +51,9 @@ public class BaseASTTest extends TestCase
{ {
ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE; ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE;
quickParseCallback = ParserFactory.createQuickParseCallback(); quickParseCallback = ParserFactory.createQuickParseCallback();
parser = ParserFactory.createParser( ParserFactory.createScanner( new StringReader( code ), "code", new ScannerInfo(), mode, lang, quickParseCallback, new NullLogService(), null), quickParseCallback, mode, lang, null ); parser = ParserFactory.createParser( ParserFactory.createScanner( new StringReader( code ), "code", new ScannerInfo(), mode, lang, quickParseCallback, new NullLogService(), null), quickParseCallback, mode, lang, null ); //$NON-NLS-1$
if( ! parser.parse() && throwExceptionOnError ) if( ! parser.parse() && throwExceptionOnError )
throw new ParserException("Parse failure"); throw new ParserException("Parse failure"); //$NON-NLS-1$
return quickParseCallback.getCompilationUnit(); return quickParseCallback.getCompilationUnit();
} }
@ -107,13 +107,13 @@ public class BaseASTTest extends TestCase
try { try {
parse(code, quick, throwOnError, CPP ); parse(code, quick, throwOnError, CPP );
testPassed = true; testPassed = true;
fail( "We should not reach this point"); fail( "We should not reach this point"); //$NON-NLS-1$
} catch (Throwable e) { } catch (Throwable e) {
if (!(e instanceof ParserException)) if (!(e instanceof ParserException))
fail("Unexpected Error: " + e.getMessage()); fail("Unexpected Error: " + e.getMessage()); //$NON-NLS-1$
} }
if (testPassed) if (testPassed)
fail("The expected error did not occur."); fail("The expected error did not occur."); //$NON-NLS-1$
} }
public void assertCodeFailsFullParse(String code) { public void assertCodeFailsFullParse(String code) {
@ -121,13 +121,13 @@ public class BaseASTTest extends TestCase
try { try {
fullParse(code); fullParse(code);
testPassed = true; testPassed = true;
fail( "We should not reach this point"); fail( "We should not reach this point"); //$NON-NLS-1$
} catch (Throwable e) { } catch (Throwable e) {
if (!(e instanceof ParserException)) if (!(e instanceof ParserException))
fail("Unexpected Error: " + e.getMessage()); fail("Unexpected Error: " + e.getMessage()); //$NON-NLS-1$
} }
if (testPassed) if (testPassed)
fail("The expected error did not occur."); fail("The expected error did not occur."); //$NON-NLS-1$
} }
protected void assertSimpleReturnType(IASTFunction function, IASTSimpleTypeSpecifier.Type type) protected void assertSimpleReturnType(IASTFunction function, IASTSimpleTypeSpecifier.Type type)
@ -153,12 +153,12 @@ public class BaseASTTest extends TestCase
protected void failedAsExpected() protected void failedAsExpected()
{ {
assertFalse( "The expected error did not occur.", false ); assertFalse( "The expected error did not occur.", false ); //$NON-NLS-1$
} }
protected void assertNotReached() protected void assertNotReached()
{ {
fail( "We should not reach this point"); fail( "We should not reach this point"); //$NON-NLS-1$
} }
protected void assertQualifiedName(String [] fromAST, String [] theTruth) protected void assertQualifiedName(String [] fromAST, String [] theTruth)

View file

@ -0,0 +1,20 @@
/*******************************************************************************
* 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

@ -116,6 +116,8 @@ public interface IToken {
static public final int tEQUAL = 37; static public final int tEQUAL = 37;
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;

View file

@ -259,7 +259,7 @@ public interface IASTExpression extends ISourceElementCallbackDelegate, IASTNode
public IASTTypeId getTypeId(); public IASTTypeId getTypeId();
public IASTNewExpressionDescriptor getNewExpressionDescriptor(); public IASTNewExpressionDescriptor getNewExpressionDescriptor();
public int evaluateExpression() throws ASTExpressionEvaluationException; public long evaluateExpression() throws ASTExpressionEvaluationException;
public void reconcileReferences() throws ASTNotImplementedException; public void reconcileReferences() throws ASTNotImplementedException;
public void purgeReferences() throws ASTNotImplementedException; public void purgeReferences() throws ASTNotImplementedException;

View file

@ -122,6 +122,11 @@ 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(

View file

@ -66,5 +66,4 @@ public interface IASTFactoryExtension {
public boolean overrideCreateDesignatorMethod( IASTDesignator.DesignatorKind kind ); public boolean overrideCreateDesignatorMethod( IASTDesignator.DesignatorKind kind );
public IASTDesignator createDesignator( IASTDesignator.DesignatorKind kind, IASTExpression constantExpression, IToken fieldIdentifier, Map extensionParms ); public IASTDesignator createDesignator( IASTDesignator.DesignatorKind kind, IASTExpression constantExpression, IToken fieldIdentifier, Map extensionParms );
} }

View file

@ -110,7 +110,7 @@ public class ContextualParser extends CompleteParser {
setCompletionKind(kind); setCompletionKind(kind);
setCompletionContext(null); setCompletionContext(null);
setCompletionFunctionName( ); setCompletionFunctionName( );
setCompletionToken( TokenFactory.createToken( IToken.tIDENTIFIER, prefix ) ); setCompletionToken( TokenFactory.createStandAloneToken( IToken.tIDENTIFIER, prefix ) );
} }
/** /**
@ -130,7 +130,7 @@ public class ContextualParser extends CompleteParser {
} }
protected void setCompletionValues(IASTScope scope, CompletionKind kind, Key key, IASTNode node, String prefix) throws EndOfFileException { protected void setCompletionValues(IASTScope scope, CompletionKind kind, Key key, IASTNode node, String prefix) throws EndOfFileException {
setCompletionToken( TokenFactory.createToken( IToken.tIDENTIFIER, prefix ) ); setCompletionToken( TokenFactory.createStandAloneToken( IToken.tIDENTIFIER, prefix ) );
setCompletionValues(scope, kind, key, node ); setCompletionValues(scope, kind, key, node );
} }

View file

@ -17,6 +17,7 @@ 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;
@ -41,7 +42,6 @@ import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind; import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind;
import org.eclipse.cdt.core.parser.extension.IParserExtension; import org.eclipse.cdt.core.parser.extension.IParserExtension;
import org.eclipse.cdt.internal.core.parser.token.KeywordSets; import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
import org.eclipse.cdt.internal.core.parser.token.SimpleToken;
import org.eclipse.cdt.internal.core.parser.token.TokenDuple; import org.eclipse.cdt.internal.core.parser.token.TokenDuple;
import org.eclipse.cdt.internal.core.parser.token.KeywordSets.Key; import org.eclipse.cdt.internal.core.parser.token.KeywordSets.Key;
import org.eclipse.cdt.internal.core.parser.util.TraceUtil; import org.eclipse.cdt.internal.core.parser.util.TraceUtil;
@ -170,7 +170,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
* *
*/ */
public void backup(IToken mark) { public void backup(IToken mark) {
currToken = (SimpleToken)mark; currToken = mark;
lastToken = null; // this is not entirely right ... lastToken = null; // this is not entirely right ...
} }
@ -2523,17 +2523,21 @@ 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
{ {
return astFactory.createExpression( if( t instanceof INumericToken )
scope, {
IASTExpression.Kind.PRIMARY_INTEGER_LITERAL, return astFactory.createExpression(
null, IASTExpression.Kind.PRIMARY_INTEGER_LITERAL,
null, ((INumericToken)t).getIntegerValue(), isHex);
null, }
null, else
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

@ -10,6 +10,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.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -74,7 +75,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 List EMPTY_LIST = new ArrayList(); protected static final List EMPTY_LIST = Collections.unmodifiableList(new ArrayList());
protected ISourceElementRequestor requestor = null; protected ISourceElementRequestor requestor = null;
/** /**
@ -807,9 +808,8 @@ public abstract class Parser extends ExpressionParser implements IParser
IASTTemplate ownerTemplate, CompletionKind overrideKind, Key overrideKey) IASTTemplate ownerTemplate, CompletionKind overrideKind, Key overrideKey)
throws EndOfFileException, BacktrackException throws EndOfFileException, BacktrackException
{ {
IToken mark = mark(); simpleDeclarationMark = mark();
try
try
{ {
return simpleDeclaration( return simpleDeclaration(
SimpleDeclarationStrategy.TRY_CONSTRUCTOR, SimpleDeclarationStrategy.TRY_CONSTRUCTOR,
@ -819,8 +819,10 @@ public abstract class Parser extends ExpressionParser implements IParser
} }
catch (BacktrackException bt) catch (BacktrackException bt)
{ {
if( simpleDeclarationMark == null )
throw backtrack;
// did not work // did not work
backup(mark); backup(simpleDeclarationMark);
try try
{ {
@ -831,7 +833,10 @@ public abstract class Parser extends ExpressionParser implements IParser
} }
catch( BacktrackException bt2 ) catch( BacktrackException bt2 )
{ {
backup( mark ); if( simpleDeclarationMark == null )
throw backtrack;
backup( simpleDeclarationMark );
try try
{ {
@ -842,7 +847,7 @@ public abstract class Parser extends ExpressionParser implements IParser
} }
catch( BacktrackException b3 ) catch( BacktrackException b3 )
{ {
backup( mark ); backup( simpleDeclarationMark );
throw b3; throw b3;
} }
} }
@ -1018,13 +1023,13 @@ public abstract class Parser extends ExpressionParser implements IParser
Declarator declarator = null; Declarator declarator = null;
if (LT(1) != IToken.tSEMI) if (LT(1) != IToken.tSEMI)
{ {
declarator = initDeclarator(sdw, strategy, completionKindForDeclaration declarator = initDeclarator(sdw, strategy, completionKindForDeclaration, constructInitializersInDeclarations
); );
while (LT(1) == IToken.tCOMMA) while (LT(1) == IToken.tCOMMA)
{ {
consume(); consume();
initDeclarator(sdw, strategy, completionKindForDeclaration ); initDeclarator(sdw, strategy, completionKindForDeclaration, constructInitializersInDeclarations );
} }
} }
@ -1228,6 +1233,9 @@ public abstract class Parser extends ExpressionParser implements IParser
} }
} }
protected boolean constructInitializersInParameters = true;
protected boolean constructInitializersInDeclarations = true;
/** /**
* This routine parses a parameter declaration * This routine parses a parameter declaration
* *
@ -1274,7 +1282,7 @@ public abstract class Parser extends ExpressionParser implements IParser
setCompletionValues(scope,CompletionKind.SINGLE_NAME_REFERENCE,Key.EMPTY ); setCompletionValues(scope,CompletionKind.SINGLE_NAME_REFERENCE,Key.EMPTY );
if (LT(1) != IToken.tSEMI) if (LT(1) != IToken.tSEMI)
initDeclarator(sdw, SimpleDeclarationStrategy.TRY_FUNCTION, CompletionKind.VARIABLE_TYPE ); initDeclarator(sdw, SimpleDeclarationStrategy.TRY_FUNCTION, CompletionKind.VARIABLE_TYPE, constructInitializersInParameters );
if( lastToken != null ) if( lastToken != null )
sdw.setEndingOffsetAndLineNumber( lastToken.getEndOffset(), lastToken.getLineNumber() ); sdw.setEndingOffsetAndLineNumber( lastToken.getEndOffset(), lastToken.getLineNumber() );
@ -1801,24 +1809,25 @@ public abstract class Parser extends ExpressionParser implements IParser
* *
* initDeclarator * initDeclarator
* : declarator ("=" initializerClause | "(" expressionList ")")? * : declarator ("=" initializerClause | "(" expressionList ")")?
* @param constructInitializers TODO
* @param owner IParserCallback object that represents the owner declaration object. * @param owner IParserCallback object that represents the owner declaration object.
* @return declarator that this parsing produced. * @return declarator that this parsing produced.
* @throws BacktrackException request a backtrack * @throws BacktrackException request a backtrack
*/ */
protected Declarator initDeclarator( protected Declarator initDeclarator(
DeclarationWrapper sdw, SimpleDeclarationStrategy strategy, CompletionKind kind ) DeclarationWrapper sdw, SimpleDeclarationStrategy strategy, CompletionKind kind, boolean constructInitializers )
throws EndOfFileException, BacktrackException throws EndOfFileException, BacktrackException
{ {
Declarator d = declarator(sdw, sdw.getScope(), strategy, kind ); Declarator d = declarator(sdw, sdw.getScope(), strategy, kind );
if( language == ParserLanguage.CPP ) if( language == ParserLanguage.CPP )
optionalCPPInitializer(d); optionalCPPInitializer(d, constructInitializers);
else if( language == ParserLanguage.C ) else if( language == ParserLanguage.C )
optionalCInitializer(d); optionalCInitializer(d, constructInitializers);
sdw.addDeclarator(d); sdw.addDeclarator(d);
return d; return d;
} }
protected void optionalCPPInitializer(Declarator d) protected void optionalCPPInitializer(Declarator d, boolean constructInitializers)
throws EndOfFileException, BacktrackException throws EndOfFileException, BacktrackException
{ {
// handle initializer // handle initializer
@ -1828,7 +1837,8 @@ public abstract class Parser extends ExpressionParser implements IParser
{ {
consume(IToken.tASSIGN); consume(IToken.tASSIGN);
setCompletionValues(scope,CompletionKind.SINGLE_NAME_REFERENCE,Key.EMPTY); setCompletionValues(scope,CompletionKind.SINGLE_NAME_REFERENCE,Key.EMPTY);
IASTInitializerClause clause = initializerClause(scope); simpleDeclarationMark = null;
IASTInitializerClause clause = initializerClause(scope,constructInitializers);
d.setInitializerClause(clause); d.setInitializerClause(clause);
setCompletionValues(scope,CompletionKind.NO_SUCH_KIND,Key.EMPTY); setCompletionValues(scope,CompletionKind.NO_SUCH_KIND,Key.EMPTY);
} }
@ -1853,15 +1863,16 @@ public abstract class Parser extends ExpressionParser implements IParser
} }
} }
protected void optionalCInitializer( Declarator d ) throws EndOfFileException, BacktrackException protected void optionalCInitializer( Declarator d, boolean constructInitializers ) throws EndOfFileException, BacktrackException
{ {
final IASTScope scope = d.getDeclarationWrapper().getScope(); final IASTScope scope = d.getDeclarationWrapper().getScope();
setCompletionValues(scope,CompletionKind.NO_SUCH_KIND,Key.EMPTY); setCompletionValues(scope,CompletionKind.NO_SUCH_KIND,Key.EMPTY);
if( LT(1) == IToken.tASSIGN ) if( LT(1) == IToken.tASSIGN )
{ {
consume( IToken.tASSIGN ); consume( IToken.tASSIGN );
simpleDeclarationMark = null;
setCompletionValues(scope,CompletionKind.SINGLE_NAME_REFERENCE,Key.EMPTY); setCompletionValues(scope,CompletionKind.SINGLE_NAME_REFERENCE,Key.EMPTY);
d.setInitializerClause( cInitializerClause(scope, EMPTY_LIST ) ); d.setInitializerClause( cInitializerClause(scope, EMPTY_LIST, constructInitializers ) );
setCompletionValues(scope,CompletionKind.NO_SUCH_KIND,Key.EMPTY); setCompletionValues(scope,CompletionKind.NO_SUCH_KIND,Key.EMPTY);
} }
} }
@ -1871,7 +1882,7 @@ public abstract class Parser extends ExpressionParser implements IParser
*/ */
protected IASTInitializerClause cInitializerClause( protected IASTInitializerClause cInitializerClause(
IASTScope scope, IASTScope scope,
List designators) List designators, boolean constructInitializers)
throws EndOfFileException, BacktrackException throws EndOfFileException, BacktrackException
{ {
if (LT(1) == IToken.tLBRACE) if (LT(1) == IToken.tLBRACE)
@ -1888,7 +1899,7 @@ public abstract class Parser extends ExpressionParser implements IParser
if( LT(1) == IToken.tASSIGN ) if( LT(1) == IToken.tASSIGN )
consume( IToken.tASSIGN ); consume( IToken.tASSIGN );
IASTInitializerClause initializer = IASTInitializerClause initializer =
cInitializerClause(scope, newDesignators ); cInitializerClause(scope, newDesignators, constructInitializers );
initializerList.add(initializer); initializerList.add(initializer);
// can end with just a '}' // can end with just a '}'
if (LT(1) == IToken.tRBRACE) if (LT(1) == IToken.tRBRACE)
@ -1907,13 +1918,13 @@ public abstract class Parser extends ExpressionParser implements IParser
} }
// consume the closing brace // consume the closing brace
consume(IToken.tRBRACE); consume(IToken.tRBRACE);
return astFactory.createInitializerClause( return createInitializerClause(
scope, scope,
( (
( designators.size() == 0 ) ? ( designators.size() == 0 ) ?
IASTInitializerClause.Kind.INITIALIZER_LIST : IASTInitializerClause.Kind.INITIALIZER_LIST :
IASTInitializerClause.Kind.DESIGNATED_INITIALIZER_LIST ), IASTInitializerClause.Kind.DESIGNATED_INITIALIZER_LIST ),
null, initializerList, designators ); null, initializerList, designators, constructInitializers );
} }
// if we get this far, it means that we have not yet succeeded // if we get this far, it means that we have not yet succeeded
// try this now instead // try this now instead
@ -1923,13 +1934,13 @@ public abstract class Parser extends ExpressionParser implements IParser
IASTExpression assignmentExpression = assignmentExpression(scope, CompletionKind.SINGLE_NAME_REFERENCE, Key.EXPRESSION); IASTExpression assignmentExpression = assignmentExpression(scope, CompletionKind.SINGLE_NAME_REFERENCE, Key.EXPRESSION);
try try
{ {
return astFactory.createInitializerClause( return createInitializerClause(
scope, scope,
( (
( designators.size() == 0 ) ? ( designators.size() == 0 ) ?
IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION : IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION :
IASTInitializerClause.Kind.DESIGNATED_ASSIGNMENT_EXPRESSION ), IASTInitializerClause.Kind.DESIGNATED_ASSIGNMENT_EXPRESSION ),
assignmentExpression, null, designators ); assignmentExpression, null, designators, constructInitializers );
} }
catch (Exception e) catch (Exception e)
{ {
@ -1946,7 +1957,7 @@ public abstract class Parser extends ExpressionParser implements IParser
/** /**
* *
*/ */
protected IASTInitializerClause initializerClause(IASTScope scope) protected IASTInitializerClause initializerClause(IASTScope scope, boolean constructInitializers)
throws EndOfFileException, BacktrackException throws EndOfFileException, BacktrackException
{ {
if (LT(1) == IToken.tLBRACE) if (LT(1) == IToken.tLBRACE)
@ -1957,10 +1968,10 @@ public abstract class Parser extends ExpressionParser implements IParser
consume(IToken.tRBRACE); consume(IToken.tRBRACE);
try try
{ {
return astFactory.createInitializerClause( return createInitializerClause(
scope, scope,
IASTInitializerClause.Kind.EMPTY, IASTInitializerClause.Kind.EMPTY,
null, null, EMPTY_LIST ); null, null, EMPTY_LIST, constructInitializers );
} }
catch (Exception e) catch (Exception e)
{ {
@ -1970,11 +1981,16 @@ public abstract class Parser extends ExpressionParser implements IParser
} }
// otherwise it is a list of initializer clauses // otherwise it is a list of initializer clauses
List initializerClauses = new ArrayList(); List initializerClauses = null;
for (;;) for (;;)
{ {
IASTInitializerClause clause = initializerClause(scope); IASTInitializerClause clause = initializerClause(scope, constructInitializers);
initializerClauses.add(clause); if( clause != null )
{
if( initializerClauses == null )
initializerClauses = new ArrayList();
initializerClauses.add(clause);
}
if (LT(1) == IToken.tRBRACE) if (LT(1) == IToken.tRBRACE)
break; break;
consume(IToken.tCOMMA); consume(IToken.tCOMMA);
@ -1982,10 +1998,10 @@ public abstract class Parser extends ExpressionParser implements IParser
consume(IToken.tRBRACE); consume(IToken.tRBRACE);
try try
{ {
return astFactory.createInitializerClause( return createInitializerClause(
scope, scope,
IASTInitializerClause.Kind.INITIALIZER_LIST, IASTInitializerClause.Kind.INITIALIZER_LIST,
null, initializerClauses, EMPTY_LIST ); null, initializerClauses == null ? EMPTY_LIST : initializerClauses, EMPTY_LIST, constructInitializers );
} }
catch (Exception e) catch (Exception e)
{ {
@ -2004,10 +2020,10 @@ public abstract class Parser extends ExpressionParser implements IParser
try try
{ {
return astFactory.createInitializerClause( return createInitializerClause(
scope, scope,
IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION, IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION,
assignmentExpression, null, EMPTY_LIST ); assignmentExpression, null, EMPTY_LIST, constructInitializers );
} }
catch (Exception e) catch (Exception e)
{ {
@ -2026,6 +2042,17 @@ public abstract class Parser extends ExpressionParser implements IParser
throw backtrack; throw backtrack;
} }
protected IASTInitializerClause createInitializerClause( IASTScope scope, IASTInitializerClause.Kind kind, IASTExpression expression,
List initializerClauses, List designators, boolean constructInitializer )
{
if( ! constructInitializer ) return null;
return astFactory.createInitializerClause(
scope,
kind,
expression, initializerClauses, designators );
}
protected List designatorList(IASTScope scope) throws EndOfFileException, BacktrackException protected List designatorList(IASTScope scope) throws EndOfFileException, BacktrackException
{ {
List designatorList = new ArrayList(); List designatorList = new ArrayList();
@ -3065,6 +3092,7 @@ public abstract class Parser extends ExpressionParser implements IParser
} }
protected IASTCompilationUnit compilationUnit; protected IASTCompilationUnit compilationUnit;
protected IToken simpleDeclarationMark;
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParser#getLanguage() * @see org.eclipse.cdt.internal.core.parser.IParser#getLanguage()
@ -3152,6 +3180,7 @@ public abstract class Parser extends ExpressionParser implements IParser
protected void cleanupLastToken() { protected void cleanupLastToken() {
if( lastToken != null ) if( lastToken != null )
lastToken.setNext( null ); lastToken.setNext( null );
simpleDeclarationMark = null;
} }

View file

@ -38,6 +38,7 @@ public class QuickParser extends Parser {
*/ */
public QuickParser(IScanner scanner, ISourceElementRequestor callback, ParserLanguage language, IParserLogService log, IParserExtension extension) { public QuickParser(IScanner scanner, ISourceElementRequestor callback, ParserLanguage language, IParserLogService log, IParserExtension extension) {
super(scanner, callback, language, log, extension); super(scanner, callback, language, log, extension);
constructInitializersInDeclarations = false;
} }
protected void handleFunctionBody(IASTScope scope) throws BacktrackException, EndOfFileException protected void handleFunctionBody(IASTScope scope) throws BacktrackException, EndOfFileException

View file

@ -67,7 +67,7 @@ public class ASTAbstractDeclaration implements IASTAbstractDeclaration
*/ */
public Iterator getPointerOperators() public Iterator getPointerOperators()
{ {
if( pointerOperators == null ) return new EmptyIterator(); if( pointerOperators == null ) return EmptyIterator.EMPTY_ITERATOR;
return pointerOperators.iterator(); return pointerOperators.iterator();
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -75,7 +75,7 @@ public class ASTAbstractDeclaration implements IASTAbstractDeclaration
*/ */
public Iterator getArrayModifiers() public Iterator getArrayModifiers()
{ {
if( arrayModifiers == null ) return new EmptyIterator(); if( arrayModifiers == null ) return EmptyIterator.EMPTY_ITERATOR;
return arrayModifiers.iterator(); return arrayModifiers.iterator();
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -83,7 +83,7 @@ public class ASTAbstractDeclaration implements IASTAbstractDeclaration
*/ */
public Iterator getParameters() public Iterator getParameters()
{ {
if( parms == null ) return new EmptyIterator(); if( parms == null ) return EmptyIterator.EMPTY_ITERATOR;
return parms.iterator(); return parms.iterator();
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -75,7 +75,7 @@ public class ASTCompletionNode implements IASTCompletionNode {
*/ */
public Iterator getKeywords() { public Iterator getKeywords() {
if( keywordSet == null ) if( keywordSet == null )
return new EmptyIterator(); return EmptyIterator.EMPTY_ITERATOR;
return keywordSet.iterator(); return keywordSet.iterator();
} }

View file

@ -14,13 +14,19 @@ import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
public class EmptyIterator implements Iterator public final class EmptyIterator implements Iterator
{ {
public static final EmptyIterator EMPTY_ITERATOR = new EmptyIterator();
private EmptyIterator()
{
}
/* (non-Javadoc) /* (non-Javadoc)
* @see java.util.Iterator#hasNext() * @see java.util.Iterator#hasNext()
*/ */
public boolean hasNext() public final boolean hasNext()
{ {
return false; return false;
} }
@ -28,7 +34,7 @@ public class EmptyIterator implements Iterator
/* (non-Javadoc) /* (non-Javadoc)
* @see java.util.Iterator#next() * @see java.util.Iterator#next()
*/ */
public Object next() public final Object next()
{ {
throw new NoSuchElementException(); throw new NoSuchElementException();
} }
@ -36,7 +42,7 @@ public class EmptyIterator implements Iterator
/* (non-Javadoc) /* (non-Javadoc)
* @see java.util.Iterator#remove() * @see java.util.Iterator#remove()
*/ */
public void remove() public final void remove()
{ {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

View file

@ -81,7 +81,7 @@ public class GCCASTExtension implements IASTFactoryExtension {
if( !idExpression.equals( EMPTY_STRING ) && literal.equals( EMPTY_STRING )) if( !idExpression.equals( EMPTY_STRING ) && literal.equals( EMPTY_STRING ))
return new ASTIdExpression( kind, idExpression ) return new ASTIdExpression( kind, idExpression )
{ {
public int evaluateExpression() throws ASTExpressionEvaluationException { public long evaluateExpression() throws ASTExpressionEvaluationException {
if( getExpressionKind() == Kind.ID_EXPRESSION ) if( getExpressionKind() == Kind.ID_EXPRESSION )
return 0; return 0;
return super.evaluateExpression(); return super.evaluateExpression();

View file

@ -40,7 +40,7 @@ public class ASTExceptionSpecification implements IASTExceptionSpecification
*/ */
public Iterator getTypeIds() public Iterator getTypeIds()
{ {
if( typeIds == null ) return new EmptyIterator(); if( typeIds == null ) return EmptyIterator.EMPTY_ITERATOR;
return typeIds.iterator(); return typeIds.iterator();
} }

View file

@ -53,7 +53,7 @@ public abstract class ASTExpression extends ASTNode implements IASTExpression
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#evaluateExpression() * @see org.eclipse.cdt.core.parser.ast.IASTExpression#evaluateExpression()
*/ */
public int evaluateExpression() throws ASTExpressionEvaluationException public long evaluateExpression() throws ASTExpressionEvaluationException
{ {
throw new ASTExpressionEvaluationException(); throw new ASTExpressionEvaluationException();
} }

View file

@ -58,7 +58,7 @@ public class ASTInitializerClause implements IASTInitializerClause
*/ */
public Iterator getInitializers() { public Iterator getInitializers() {
if( initializerClauses == null ) if( initializerClauses == null )
return new EmptyIterator(); return EmptyIterator.EMPTY_ITERATOR;
return initializerClauses.iterator(); return initializerClauses.iterator();
} }

View file

@ -0,0 +1,41 @@
/*******************************************************************************
* 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

@ -200,7 +200,7 @@ public class ASTMethod extends ASTFunction implements IASTMethod
public Iterator getConstructorChainInitializers() public Iterator getConstructorChainInitializers()
{ {
if( constructorChain == null ) if( constructorChain == null )
return new EmptyIterator(); return EmptyIterator.EMPTY_ITERATOR;
return constructorChain.iterator(); return constructorChain.iterator();
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -3522,4 +3522,22 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
if( lastOperator.getType() == TypeInfo.PtrOp.t_reference ) return true; if( lastOperator.getType() == TypeInfo.PtrOp.t_reference ) return true;
return false; return false;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExpression(org.eclipse.cdt.core.parser.ast.IASTExpression.Kind, long, boolean)
*/
public IASTExpression createExpression(Kind kind, long literal, boolean isHex) throws ASTSemanticException {
// 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,4 +52,14 @@ 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

@ -83,7 +83,7 @@ public class ASTExpression implements IASTExpression {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#evaluateExpression() * @see org.eclipse.cdt.core.parser.ast.IASTExpression#evaluateExpression()
*/ */
public int evaluateExpression() throws ASTExpressionEvaluationException { public long evaluateExpression() throws ASTExpressionEvaluationException {
// primary expressions // primary expressions
if( getExpressionKind() == IASTExpression.Kind.PRIMARY_INTEGER_LITERAL ) if( getExpressionKind() == IASTExpression.Kind.PRIMARY_INTEGER_LITERAL )
{ {

View file

@ -0,0 +1,60 @@
/*******************************************************************************
* 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

@ -68,4 +68,19 @@ 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

@ -381,8 +381,7 @@ public class ExpressionParseASTFactory extends BaseASTFactory implements IASTFac
throws ASTSemanticException { throws ASTSemanticException {
if( extension.overrideCreateExpressionMethod() ) if( extension.overrideCreateExpressionMethod() )
return extension.createExpression(scope, kind, lhs, rhs, thirdExpression, typeId, idExpression, literal, newDescriptor ); return extension.createExpression(scope, kind, lhs, rhs, thirdExpression, typeId, idExpression, literal, newDescriptor );
return ExpressionFactory.createExpression( kind, lhs, rhs, thirdExpression, typeId, idExpression == null ? "" : idExpression.toString(), literal, newDescriptor ); //$NON-NLS-1$ return ExpressionFactory.createExpression( kind, lhs, rhs, thirdExpression, typeId, idExpression == null ? "" : idExpression.toString(), literal, newDescriptor ); //$NON-NLS-1$
} }
/* /*
@ -908,5 +907,12 @@ public class ExpressionParseASTFactory extends BaseASTFactory implements IASTFac
return false; return false;
} }
/* (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)
*/
public IASTExpression createExpression(Kind kind, long literal, boolean isHex) throws ASTSemanticException {
return ExpressionFactory.createExpression( kind, literal, isHex );
}
} }

View file

@ -0,0 +1,44 @@
/*******************************************************************************
* 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.quick;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTInitializerClause;
import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator;
/**
* @author jcamelon
*/
public class ASTDesignatedExpressionInitializerClause
extends
ASTExpressionInitializerClause implements IASTInitializerClause {
private final List designators;
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getDesignators()
*/
public Iterator getDesignators() {
if( designators == null ) return EmptyIterator.EMPTY_ITERATOR;
return designators.iterator();
}
/**
* @param kind
* @param assignmentExpression
* @param designators
*/
public ASTDesignatedExpressionInitializerClause(Kind kind, IASTExpression assignmentExpression, List designators) {
super(kind, assignmentExpression);
this.designators = designators;
}
}

View file

@ -0,0 +1,47 @@
/*******************************************************************************
* 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.quick;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.parser.ast.IASTInitializerClause;
import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator;
/**
* @author jcamelon
*/
public class ASTDesignatedInitializerListInitializerClause
extends
ASTInitializerListInitializerClause
implements
IASTInitializerClause {
private final List designators;
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getDesignators()
*/
public Iterator getDesignators() {
if( designators == null ) return EmptyIterator.EMPTY_ITERATOR;
return designators.iterator();
}
/**
* @param kind
* @param initializerClauses
* @param designators
*/
public ASTDesignatedInitializerListInitializerClause(Kind kind, List initializerClauses, List designators) {
super( kind, initializerClauses );
this.designators = designators;
}
}

View file

@ -0,0 +1,41 @@
/*******************************************************************************
* 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.quick;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTInitializerClause;
/**
* @author jcamelon
*/
public class ASTExpressionInitializerClause extends ASTInitializerClause
implements
IASTInitializerClause {
private final IASTExpression expression;
/**
* @param kind
* @param assignmentExpression
*/
public ASTExpressionInitializerClause(Kind kind, IASTExpression assignmentExpression) {
super( kind );
this.expression = assignmentExpression;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getAssigmentExpression()
*/
public IASTExpression getAssigmentExpression() {
return expression;
}
}

View file

@ -11,7 +11,6 @@
package org.eclipse.cdt.internal.core.parser.ast.quick; package org.eclipse.cdt.internal.core.parser.ast.quick;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTExpression; import org.eclipse.cdt.core.parser.ast.IASTExpression;
@ -25,20 +24,14 @@ import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator;
public class ASTInitializerClause implements IASTInitializerClause { public class ASTInitializerClause implements IASTInitializerClause {
private final IASTInitializerClause.Kind kind; private final IASTInitializerClause.Kind kind;
private final IASTExpression assignmentExpression;
private final List initializerClauses;
private final List designators;
private IASTVariable ownerDeclaration = null; private IASTVariable ownerDeclaration = null;
/** /**
* @param kind * @param kind
* @param assignmentExpression * @param assignmentExpression
* @param initializerClauses * @param initializerClauses
*/ */
public ASTInitializerClause(Kind kind, IASTExpression assignmentExpression, List initializerClauses, List designators ) { public ASTInitializerClause(Kind kind ) {
this.kind = kind; this.kind = kind;
this.assignmentExpression = assignmentExpression;
this.initializerClauses = initializerClauses;
this.designators = designators;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -52,16 +45,14 @@ public class ASTInitializerClause implements IASTInitializerClause {
* @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getInitializerList() * @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getInitializerList()
*/ */
public Iterator getInitializers() { public Iterator getInitializers() {
if( initializerClauses == null ) return EmptyIterator.EMPTY_ITERATOR;
return new EmptyIterator();
return initializerClauses.iterator();
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getAssigmentExpression() * @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getAssigmentExpression()
*/ */
public IASTExpression getAssigmentExpression() { public IASTExpression getAssigmentExpression() {
return assignmentExpression; return null;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -90,7 +81,7 @@ public class ASTInitializerClause implements IASTInitializerClause {
*/ */
public Iterator getDesignators() public Iterator getDesignators()
{ {
return designators.iterator(); return EmptyIterator.EMPTY_ITERATOR;
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -0,0 +1,46 @@
/*******************************************************************************
* 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.quick;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.parser.ast.IASTInitializerClause;
import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator;
/**
* @author jcamelon
*/
public class ASTInitializerListInitializerClause extends ASTInitializerClause
implements
IASTInitializerClause {
private final List initializerClauses;
/**
* @param kind
* @param initializerClauses
*/
public ASTInitializerListInitializerClause(Kind kind, List initializerClauses) {
super( kind );
this.initializerClauses = initializerClauses;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getInitializers()
*/
public Iterator getInitializers() {
if( initializerClauses == null )
return EmptyIterator.EMPTY_ITERATOR;
return initializerClauses.iterator();
}
}

View file

@ -211,7 +211,7 @@ public class ASTMethod extends ASTFunction implements IASTMethod
public Iterator getConstructorChainInitializers() public Iterator getConstructorChainInitializers()
{ {
if( constructorChainElements == null ) if( constructorChainElements == null )
return new EmptyIterator(); return EmptyIterator.EMPTY_ITERATOR;
return constructorChainElements.iterator(); return constructorChainElements.iterator();
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -18,6 +18,7 @@ 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;
@ -335,7 +336,15 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
public IASTInitializerClause createInitializerClause(IASTScope scope, IASTInitializerClause.Kind kind, IASTExpression assignmentExpression, List initializerClauses, List designators) public IASTInitializerClause createInitializerClause(IASTScope scope, IASTInitializerClause.Kind kind, IASTExpression assignmentExpression, List initializerClauses, List designators)
{ {
return new ASTInitializerClause( kind, assignmentExpression, initializerClauses, designators ); if( kind == IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION )
return new ASTExpressionInitializerClause( kind, assignmentExpression );
else if( kind == IASTInitializerClause.Kind.INITIALIZER_LIST )
return new ASTInitializerListInitializerClause( kind, initializerClauses );
else if ( kind == IASTInitializerClause.Kind.DESIGNATED_INITIALIZER_LIST )
return new ASTDesignatedInitializerListInitializerClause( kind, initializerClauses, designators );
else if( kind == IASTInitializerClause.Kind.DESIGNATED_ASSIGNMENT_EXPRESSION )
return new ASTDesignatedExpressionInitializerClause( kind, assignmentExpression, designators );
return new ASTInitializerClause( kind );
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -374,4 +383,11 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExpression(org.eclipse.cdt.core.parser.ast.IASTExpression.Kind, long, boolean)
*/
public IASTExpression createExpression(Kind kind, long literal, boolean isHex) throws ASTSemanticException {
return ExpressionFactory.createExpression(kind, literal, isHex );
}
} }

View file

@ -278,7 +278,7 @@ public class GCCScannerExtension implements IScannerExtension {
get = (Integer) additionalCOperators.get( image ); get = (Integer) additionalCOperators.get( image );
} }
if( get == null ) return null; if( get == null ) return null;
return TokenFactory.createToken(get.intValue(),image,scannerData); return TokenFactory.createUniquelyImagedToken(get.intValue(),image,scannerData);
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -467,7 +467,14 @@ public class Scanner implements IScanner {
} }
protected IToken newToken(int t, String i) { protected IToken newToken(int t, String i) {
setCurrentToken(TokenFactory.createToken( t, i, scannerData )); IToken token = null;
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);
return currentToken; return currentToken;
} }
@ -1127,13 +1134,15 @@ public class Scanner implements IScanner {
if( pasting && pasteIntoInputStream(buff)) if( pasting && pasteIntoInputStream(buff))
return null; return null;
int tokenType;
String result = buff.toString(); String result = buff.toString();
if( floatingPoint && result.equals(".") ) //$NON-NLS-1$ if( floatingPoint && result.equals(".") ) //$NON-NLS-1$
tokenType = IToken.tDOT; return newConstantToken( IToken.tDOT );
else
tokenType = floatingPoint ? IToken.tFLOATINGPT : IToken.tINTEGER; int tokenType = floatingPoint ? IToken.tFLOATINGPT : IToken.tINTEGER;
if( tokenType == IToken.tINTEGER && hex )
tokenType = IToken.tHEXINT;
return newToken( return newToken(
tokenType, tokenType,
@ -2670,7 +2679,7 @@ public class Scanner implements IScanner {
protected IMacroDescriptor createObjectMacroDescriptor(String key, String value ) { protected IMacroDescriptor createObjectMacroDescriptor(String key, String value ) {
IToken t = null; IToken t = null;
if( !value.trim().equals( "" ) ) //$NON-NLS-1$ if( !value.trim().equals( "" ) ) //$NON-NLS-1$
t = TokenFactory.createToken( IToken.tIDENTIFIER, value, scannerData ); t = TokenFactory.createUniquelyImagedToken( IToken.tIDENTIFIER, value, scannerData );
return new ObjectMacroDescriptor( key, return new ObjectMacroDescriptor( key,
t, t,

View file

@ -45,7 +45,7 @@ public class ScannerData implements IScannerData
private final IScanner scanner; private final IScanner scanner;
private final IScannerInfo originalConfig; private final IScannerInfo originalConfig;
private List includePathNames = new ArrayList(); private List includePathNames = new ArrayList();
private static final Iterator EMPTY_ITERATOR = new EmptyIterator();
private final Map privateDefinitions; private final Map privateDefinitions;
/** /**
* @return Returns the contextStack. * @return Returns the contextStack.
@ -183,7 +183,7 @@ public class ScannerData implements IScannerData
public Iterator getWorkingCopies() { public Iterator getWorkingCopies() {
if( workingCopies != null ) if( workingCopies != null )
return workingCopies.iterator(); return workingCopies.iterator();
return EMPTY_ITERATOR; return EmptyIterator.EMPTY_ITERATOR;
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -0,0 +1,67 @@
/*******************************************************************************
* 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

@ -0,0 +1,68 @@
/*******************************************************************************
* 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

@ -0,0 +1,50 @@
/*******************************************************************************
* 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, int value, ContextStack stack) {
super( tokenType, stack );
this.value = value;
}
/* (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

@ -0,0 +1,47 @@
/*******************************************************************************
* 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, int value, ContextStack stack) {
super( tokenType, stack );
this.value = value;
}
/* (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

@ -44,7 +44,7 @@ public class SimpleToken extends AbstractToken implements IToken {
* @param context * @param context
*/ */
protected void setOffsetAndLength(IScannerContext context) { protected void setOffsetAndLength(IScannerContext context) {
offset = context.getOffset() - getImage().length() - context.undoStackSize(); offset = context.getOffset() - getLength() - context.undoStackSize();
} }
public String getImage() { public String getImage() {

View file

@ -18,6 +18,27 @@ import org.eclipse.cdt.internal.core.parser.scanner.IScannerData;
*/ */
public class TokenFactory { public class TokenFactory {
public static IToken createIntegerToken( String value, IScannerData scannerData )
{
if( scannerData.getContextStack().getCurrentContext().getMacroOffset() >= 0 )
return new IntegerExpansionToken( IToken.tINTEGER, Integer.parseInt(value ), scannerData.getContextStack() );
return new IntegerToken( IToken.tINTEGER, Integer.parseInt( value ), scannerData.getContextStack() );
}
public static IToken createHexadecimalIntegerToken( String value, IScannerData scannerData )
{
if( value.length() > 15 )
return createUniquelyImagedToken( IToken.tHEXINT, value, scannerData );
if( scannerData.getContextStack().getCurrentContext().getMacroOffset() >= 0 )
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().getMacroOffset() >= 0 ) if( scannerData.getContextStack().getCurrentContext().getMacroOffset() >= 0 )
@ -32,15 +53,14 @@ public class TokenFactory {
* @param scannerData * @param scannerData
* @return * @return
*/ */
public static IToken createToken(int type, String image, IScannerData scannerData) { public static IToken createUniquelyImagedToken(int type, String image, IScannerData scannerData) {
if( scannerData.getContextStack().getCurrentContext().getMacroOffset() >= 0 ) if( scannerData.getContextStack().getCurrentContext().getMacroOffset() >= 0 )
return new ImagedExpansionToken( type, scannerData.getContextStack(), image ); return new ImagedExpansionToken( type, scannerData.getContextStack(), image );
return new ImagedToken(type, scannerData.getContextStack(), image ); return new ImagedToken(type, scannerData.getContextStack(), image );
} }
public static IToken createStandAloneToken( int type, String image )
public static IToken createToken( int type, String image )
{ {
return new ImagedToken( type, image); return new ImagedToken( type, image);
} }