mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-25 01:45:33 +02:00
Scalability/Memory enhancements upon the Parser framework.
This commit is contained in:
parent
524a819cac
commit
5b6bd37541
42 changed files with 1469 additions and 801 deletions
|
@ -51,9 +51,9 @@ public class BaseASTTest extends TestCase
|
|||
{
|
||||
ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE;
|
||||
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 )
|
||||
throw new ParserException("Parse failure");
|
||||
throw new ParserException("Parse failure"); //$NON-NLS-1$
|
||||
return quickParseCallback.getCompilationUnit();
|
||||
}
|
||||
|
||||
|
@ -107,13 +107,13 @@ public class BaseASTTest extends TestCase
|
|||
try {
|
||||
parse(code, quick, throwOnError, CPP );
|
||||
testPassed = true;
|
||||
fail( "We should not reach this point");
|
||||
fail( "We should not reach this point"); //$NON-NLS-1$
|
||||
} catch (Throwable e) {
|
||||
if (!(e instanceof ParserException))
|
||||
fail("Unexpected Error: " + e.getMessage());
|
||||
fail("Unexpected Error: " + e.getMessage()); //$NON-NLS-1$
|
||||
}
|
||||
if (testPassed)
|
||||
fail("The expected error did not occur.");
|
||||
fail("The expected error did not occur."); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void assertCodeFailsFullParse(String code) {
|
||||
|
@ -121,13 +121,13 @@ public class BaseASTTest extends TestCase
|
|||
try {
|
||||
fullParse(code);
|
||||
testPassed = true;
|
||||
fail( "We should not reach this point");
|
||||
fail( "We should not reach this point"); //$NON-NLS-1$
|
||||
} catch (Throwable e) {
|
||||
if (!(e instanceof ParserException))
|
||||
fail("Unexpected Error: " + e.getMessage());
|
||||
fail("Unexpected Error: " + e.getMessage()); //$NON-NLS-1$
|
||||
}
|
||||
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)
|
||||
|
@ -153,12 +153,12 @@ public class BaseASTTest extends TestCase
|
|||
|
||||
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()
|
||||
{
|
||||
fail( "We should not reach this point");
|
||||
fail( "We should not reach this point"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
protected void assertQualifiedName(String [] fromAST, String [] theTruth)
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -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();
|
||||
|
||||
}
|
|
@ -116,6 +116,8 @@ public interface IToken {
|
|||
static public final int tEQUAL = 37;
|
||||
|
||||
static public final int tASSIGN = 38;
|
||||
|
||||
static public final int tHEXINT = 39;
|
||||
|
||||
static public final int tSHIFTL = 40;
|
||||
|
||||
|
|
|
@ -259,7 +259,7 @@ public interface IASTExpression extends ISourceElementCallbackDelegate, IASTNode
|
|||
public IASTTypeId getTypeId();
|
||||
public IASTNewExpressionDescriptor getNewExpressionDescriptor();
|
||||
|
||||
public int evaluateExpression() throws ASTExpressionEvaluationException;
|
||||
public long evaluateExpression() throws ASTExpressionEvaluationException;
|
||||
public void reconcileReferences() throws ASTNotImplementedException;
|
||||
public void purgeReferences() throws ASTNotImplementedException;
|
||||
|
||||
|
|
|
@ -122,6 +122,11 @@ public interface IASTFactory
|
|||
IASTTypeId typeId,
|
||||
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 IASTInitializerClause createInitializerClause(
|
||||
|
|
|
@ -66,5 +66,4 @@ public interface IASTFactoryExtension {
|
|||
|
||||
public boolean overrideCreateDesignatorMethod( IASTDesignator.DesignatorKind kind );
|
||||
public IASTDesignator createDesignator( IASTDesignator.DesignatorKind kind, IASTExpression constantExpression, IToken fieldIdentifier, Map extensionParms );
|
||||
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ public class ContextualParser extends CompleteParser {
|
|||
setCompletionKind(kind);
|
||||
setCompletionContext(null);
|
||||
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 {
|
||||
setCompletionToken( TokenFactory.createToken( IToken.tIDENTIFIER, prefix ) );
|
||||
setCompletionToken( TokenFactory.createStandAloneToken( IToken.tIDENTIFIER, prefix ) );
|
||||
setCompletionValues(scope, kind, key, node );
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import java.util.Stack;
|
|||
|
||||
import org.eclipse.cdt.core.parser.BacktrackException;
|
||||
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.IScanner;
|
||||
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.extension.IParserExtension;
|
||||
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.KeywordSets.Key;
|
||||
import org.eclipse.cdt.internal.core.parser.util.TraceUtil;
|
||||
|
@ -170,7 +170,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
|
|||
*
|
||||
*/
|
||||
public void backup(IToken mark) {
|
||||
currToken = (SimpleToken)mark;
|
||||
currToken = mark;
|
||||
lastToken = null; // this is not entirely right ...
|
||||
}
|
||||
|
||||
|
@ -2523,17 +2523,21 @@ public class ExpressionParser implements IExpressionParser, IParserData {
|
|||
{
|
||||
// TO DO: we need more literals...
|
||||
case IToken.tINTEGER :
|
||||
case IToken.tHEXINT:
|
||||
t = consume();
|
||||
boolean isHex = ( t.getType() == IToken.tHEXINT );
|
||||
try
|
||||
{
|
||||
return astFactory.createExpression(
|
||||
scope,
|
||||
IASTExpression.Kind.PRIMARY_INTEGER_LITERAL,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null, t.getImage(), null);
|
||||
if( t instanceof INumericToken )
|
||||
{
|
||||
return astFactory.createExpression(
|
||||
IASTExpression.Kind.PRIMARY_INTEGER_LITERAL,
|
||||
((INumericToken)t).getIntegerValue(), isHex);
|
||||
}
|
||||
else
|
||||
{
|
||||
return astFactory.createExpression( scope, IASTExpression.Kind.PRIMARY_INTEGER_LITERAL, null, null, null, null, null, t.getImage(), null );
|
||||
}
|
||||
}
|
||||
catch (ASTSemanticException e1)
|
||||
{
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
***********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
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
|
||||
{
|
||||
private static final List EMPTY_LIST = new ArrayList();
|
||||
protected static final List EMPTY_LIST = Collections.unmodifiableList(new ArrayList());
|
||||
protected ISourceElementRequestor requestor = null;
|
||||
|
||||
/**
|
||||
|
@ -807,9 +808,8 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
IASTTemplate ownerTemplate, CompletionKind overrideKind, Key overrideKey)
|
||||
throws EndOfFileException, BacktrackException
|
||||
{
|
||||
IToken mark = mark();
|
||||
|
||||
try
|
||||
simpleDeclarationMark = mark();
|
||||
try
|
||||
{
|
||||
return simpleDeclaration(
|
||||
SimpleDeclarationStrategy.TRY_CONSTRUCTOR,
|
||||
|
@ -819,8 +819,10 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
}
|
||||
catch (BacktrackException bt)
|
||||
{
|
||||
if( simpleDeclarationMark == null )
|
||||
throw backtrack;
|
||||
// did not work
|
||||
backup(mark);
|
||||
backup(simpleDeclarationMark);
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -831,7 +833,10 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
}
|
||||
catch( BacktrackException bt2 )
|
||||
{
|
||||
backup( mark );
|
||||
if( simpleDeclarationMark == null )
|
||||
throw backtrack;
|
||||
|
||||
backup( simpleDeclarationMark );
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -842,7 +847,7 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
}
|
||||
catch( BacktrackException b3 )
|
||||
{
|
||||
backup( mark );
|
||||
backup( simpleDeclarationMark );
|
||||
throw b3;
|
||||
}
|
||||
}
|
||||
|
@ -1018,13 +1023,13 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
Declarator declarator = null;
|
||||
if (LT(1) != IToken.tSEMI)
|
||||
{
|
||||
declarator = initDeclarator(sdw, strategy, completionKindForDeclaration
|
||||
declarator = initDeclarator(sdw, strategy, completionKindForDeclaration, constructInitializersInDeclarations
|
||||
);
|
||||
|
||||
while (LT(1) == IToken.tCOMMA)
|
||||
{
|
||||
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
|
||||
*
|
||||
|
@ -1274,7 +1282,7 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
|
||||
setCompletionValues(scope,CompletionKind.SINGLE_NAME_REFERENCE,Key.EMPTY );
|
||||
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 )
|
||||
sdw.setEndingOffsetAndLineNumber( lastToken.getEndOffset(), lastToken.getLineNumber() );
|
||||
|
@ -1801,24 +1809,25 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
*
|
||||
* initDeclarator
|
||||
* : declarator ("=" initializerClause | "(" expressionList ")")?
|
||||
* @param constructInitializers TODO
|
||||
* @param owner IParserCallback object that represents the owner declaration object.
|
||||
* @return declarator that this parsing produced.
|
||||
* @throws BacktrackException request a backtrack
|
||||
*/
|
||||
protected Declarator initDeclarator(
|
||||
DeclarationWrapper sdw, SimpleDeclarationStrategy strategy, CompletionKind kind )
|
||||
DeclarationWrapper sdw, SimpleDeclarationStrategy strategy, CompletionKind kind, boolean constructInitializers )
|
||||
throws EndOfFileException, BacktrackException
|
||||
{
|
||||
Declarator d = declarator(sdw, sdw.getScope(), strategy, kind );
|
||||
if( language == ParserLanguage.CPP )
|
||||
optionalCPPInitializer(d);
|
||||
optionalCPPInitializer(d, constructInitializers);
|
||||
else if( language == ParserLanguage.C )
|
||||
optionalCInitializer(d);
|
||||
optionalCInitializer(d, constructInitializers);
|
||||
sdw.addDeclarator(d);
|
||||
return d;
|
||||
}
|
||||
|
||||
protected void optionalCPPInitializer(Declarator d)
|
||||
protected void optionalCPPInitializer(Declarator d, boolean constructInitializers)
|
||||
throws EndOfFileException, BacktrackException
|
||||
{
|
||||
// handle initializer
|
||||
|
@ -1828,7 +1837,8 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
{
|
||||
consume(IToken.tASSIGN);
|
||||
setCompletionValues(scope,CompletionKind.SINGLE_NAME_REFERENCE,Key.EMPTY);
|
||||
IASTInitializerClause clause = initializerClause(scope);
|
||||
simpleDeclarationMark = null;
|
||||
IASTInitializerClause clause = initializerClause(scope,constructInitializers);
|
||||
d.setInitializerClause(clause);
|
||||
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();
|
||||
setCompletionValues(scope,CompletionKind.NO_SUCH_KIND,Key.EMPTY);
|
||||
if( LT(1) == IToken.tASSIGN )
|
||||
{
|
||||
consume( IToken.tASSIGN );
|
||||
simpleDeclarationMark = null;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -1871,7 +1882,7 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
*/
|
||||
protected IASTInitializerClause cInitializerClause(
|
||||
IASTScope scope,
|
||||
List designators)
|
||||
List designators, boolean constructInitializers)
|
||||
throws EndOfFileException, BacktrackException
|
||||
{
|
||||
if (LT(1) == IToken.tLBRACE)
|
||||
|
@ -1888,7 +1899,7 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
if( LT(1) == IToken.tASSIGN )
|
||||
consume( IToken.tASSIGN );
|
||||
IASTInitializerClause initializer =
|
||||
cInitializerClause(scope, newDesignators );
|
||||
cInitializerClause(scope, newDesignators, constructInitializers );
|
||||
initializerList.add(initializer);
|
||||
// can end with just a '}'
|
||||
if (LT(1) == IToken.tRBRACE)
|
||||
|
@ -1907,13 +1918,13 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
}
|
||||
// consume the closing brace
|
||||
consume(IToken.tRBRACE);
|
||||
return astFactory.createInitializerClause(
|
||||
return createInitializerClause(
|
||||
scope,
|
||||
(
|
||||
( designators.size() == 0 ) ?
|
||||
IASTInitializerClause.Kind.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
|
||||
// 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);
|
||||
try
|
||||
{
|
||||
return astFactory.createInitializerClause(
|
||||
return createInitializerClause(
|
||||
scope,
|
||||
(
|
||||
( designators.size() == 0 ) ?
|
||||
IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION :
|
||||
IASTInitializerClause.Kind.DESIGNATED_ASSIGNMENT_EXPRESSION ),
|
||||
assignmentExpression, null, designators );
|
||||
assignmentExpression, null, designators, constructInitializers );
|
||||
}
|
||||
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
|
||||
{
|
||||
if (LT(1) == IToken.tLBRACE)
|
||||
|
@ -1957,10 +1968,10 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
consume(IToken.tRBRACE);
|
||||
try
|
||||
{
|
||||
return astFactory.createInitializerClause(
|
||||
return createInitializerClause(
|
||||
scope,
|
||||
IASTInitializerClause.Kind.EMPTY,
|
||||
null, null, EMPTY_LIST );
|
||||
null, null, EMPTY_LIST, constructInitializers );
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -1970,11 +1981,16 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
}
|
||||
|
||||
// otherwise it is a list of initializer clauses
|
||||
List initializerClauses = new ArrayList();
|
||||
List initializerClauses = null;
|
||||
for (;;)
|
||||
{
|
||||
IASTInitializerClause clause = initializerClause(scope);
|
||||
initializerClauses.add(clause);
|
||||
IASTInitializerClause clause = initializerClause(scope, constructInitializers);
|
||||
if( clause != null )
|
||||
{
|
||||
if( initializerClauses == null )
|
||||
initializerClauses = new ArrayList();
|
||||
initializerClauses.add(clause);
|
||||
}
|
||||
if (LT(1) == IToken.tRBRACE)
|
||||
break;
|
||||
consume(IToken.tCOMMA);
|
||||
|
@ -1982,10 +1998,10 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
consume(IToken.tRBRACE);
|
||||
try
|
||||
{
|
||||
return astFactory.createInitializerClause(
|
||||
return createInitializerClause(
|
||||
scope,
|
||||
IASTInitializerClause.Kind.INITIALIZER_LIST,
|
||||
null, initializerClauses, EMPTY_LIST );
|
||||
null, initializerClauses == null ? EMPTY_LIST : initializerClauses, EMPTY_LIST, constructInitializers );
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -2004,10 +2020,10 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
|
||||
try
|
||||
{
|
||||
return astFactory.createInitializerClause(
|
||||
return createInitializerClause(
|
||||
scope,
|
||||
IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION,
|
||||
assignmentExpression, null, EMPTY_LIST );
|
||||
assignmentExpression, null, EMPTY_LIST, constructInitializers );
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -2026,6 +2042,17 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
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
|
||||
{
|
||||
List designatorList = new ArrayList();
|
||||
|
@ -3065,6 +3092,7 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
}
|
||||
|
||||
protected IASTCompilationUnit compilationUnit;
|
||||
protected IToken simpleDeclarationMark;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParser#getLanguage()
|
||||
|
@ -3152,6 +3180,7 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
protected void cleanupLastToken() {
|
||||
if( lastToken != null )
|
||||
lastToken.setNext( null );
|
||||
simpleDeclarationMark = null;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ public class QuickParser extends Parser {
|
|||
*/
|
||||
public QuickParser(IScanner scanner, ISourceElementRequestor callback, ParserLanguage language, IParserLogService log, IParserExtension extension) {
|
||||
super(scanner, callback, language, log, extension);
|
||||
constructInitializersInDeclarations = false;
|
||||
}
|
||||
|
||||
protected void handleFunctionBody(IASTScope scope) throws BacktrackException, EndOfFileException
|
||||
|
|
|
@ -67,7 +67,7 @@ public class ASTAbstractDeclaration implements IASTAbstractDeclaration
|
|||
*/
|
||||
public Iterator getPointerOperators()
|
||||
{
|
||||
if( pointerOperators == null ) return new EmptyIterator();
|
||||
if( pointerOperators == null ) return EmptyIterator.EMPTY_ITERATOR;
|
||||
return pointerOperators.iterator();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
|
@ -75,7 +75,7 @@ public class ASTAbstractDeclaration implements IASTAbstractDeclaration
|
|||
*/
|
||||
public Iterator getArrayModifiers()
|
||||
{
|
||||
if( arrayModifiers == null ) return new EmptyIterator();
|
||||
if( arrayModifiers == null ) return EmptyIterator.EMPTY_ITERATOR;
|
||||
return arrayModifiers.iterator();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
|
@ -83,7 +83,7 @@ public class ASTAbstractDeclaration implements IASTAbstractDeclaration
|
|||
*/
|
||||
public Iterator getParameters()
|
||||
{
|
||||
if( parms == null ) return new EmptyIterator();
|
||||
if( parms == null ) return EmptyIterator.EMPTY_ITERATOR;
|
||||
return parms.iterator();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -75,7 +75,7 @@ public class ASTCompletionNode implements IASTCompletionNode {
|
|||
*/
|
||||
public Iterator getKeywords() {
|
||||
if( keywordSet == null )
|
||||
return new EmptyIterator();
|
||||
return EmptyIterator.EMPTY_ITERATOR;
|
||||
return keywordSet.iterator();
|
||||
}
|
||||
|
||||
|
|
|
@ -14,13 +14,19 @@ import java.util.Iterator;
|
|||
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)
|
||||
* @see java.util.Iterator#hasNext()
|
||||
*/
|
||||
public boolean hasNext()
|
||||
public final boolean hasNext()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -28,7 +34,7 @@ public class EmptyIterator implements Iterator
|
|||
/* (non-Javadoc)
|
||||
* @see java.util.Iterator#next()
|
||||
*/
|
||||
public Object next()
|
||||
public final Object next()
|
||||
{
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
@ -36,7 +42,7 @@ public class EmptyIterator implements Iterator
|
|||
/* (non-Javadoc)
|
||||
* @see java.util.Iterator#remove()
|
||||
*/
|
||||
public void remove()
|
||||
public final void remove()
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ public class GCCASTExtension implements IASTFactoryExtension {
|
|||
if( !idExpression.equals( EMPTY_STRING ) && literal.equals( EMPTY_STRING ))
|
||||
return new ASTIdExpression( kind, idExpression )
|
||||
{
|
||||
public int evaluateExpression() throws ASTExpressionEvaluationException {
|
||||
public long evaluateExpression() throws ASTExpressionEvaluationException {
|
||||
if( getExpressionKind() == Kind.ID_EXPRESSION )
|
||||
return 0;
|
||||
return super.evaluateExpression();
|
||||
|
|
|
@ -40,7 +40,7 @@ public class ASTExceptionSpecification implements IASTExceptionSpecification
|
|||
*/
|
||||
public Iterator getTypeIds()
|
||||
{
|
||||
if( typeIds == null ) return new EmptyIterator();
|
||||
if( typeIds == null ) return EmptyIterator.EMPTY_ITERATOR;
|
||||
return typeIds.iterator();
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ public abstract class ASTExpression extends ASTNode implements IASTExpression
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#evaluateExpression()
|
||||
*/
|
||||
public int evaluateExpression() throws ASTExpressionEvaluationException
|
||||
public long evaluateExpression() throws ASTExpressionEvaluationException
|
||||
{
|
||||
throw new ASTExpressionEvaluationException();
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ public class ASTInitializerClause implements IASTInitializerClause
|
|||
*/
|
||||
public Iterator getInitializers() {
|
||||
if( initializerClauses == null )
|
||||
return new EmptyIterator();
|
||||
return EmptyIterator.EMPTY_ITERATOR;
|
||||
return initializerClauses.iterator();
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
|
@ -200,7 +200,7 @@ public class ASTMethod extends ASTFunction implements IASTMethod
|
|||
public Iterator getConstructorChainInitializers()
|
||||
{
|
||||
if( constructorChain == null )
|
||||
return new EmptyIterator();
|
||||
return EmptyIterator.EMPTY_ITERATOR;
|
||||
return constructorChain.iterator();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -3522,4 +3522,22 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
if( lastOperator.getType() == TypeInfo.PtrOp.t_reference ) return true;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,4 +52,14 @@ public class ExpressionFactory {
|
|||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ public class ASTExpression implements IASTExpression {
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#evaluateExpression()
|
||||
*/
|
||||
public int evaluateExpression() throws ASTExpressionEvaluationException {
|
||||
public long evaluateExpression() throws ASTExpressionEvaluationException {
|
||||
// primary expressions
|
||||
if( getExpressionKind() == IASTExpression.Kind.PRIMARY_INTEGER_LITERAL )
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -68,4 +68,19 @@ public class ExpressionFactory {
|
|||
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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -381,8 +381,7 @@ public class ExpressionParseASTFactory extends BaseASTFactory implements IASTFac
|
|||
throws ASTSemanticException {
|
||||
if( extension.overrideCreateExpressionMethod() )
|
||||
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;
|
||||
}
|
||||
|
||||
/* (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 );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -11,7 +11,6 @@
|
|||
package org.eclipse.cdt.internal.core.parser.ast.quick;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||
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 {
|
||||
|
||||
private final IASTInitializerClause.Kind kind;
|
||||
private final IASTExpression assignmentExpression;
|
||||
private final List initializerClauses;
|
||||
private final List designators;
|
||||
private IASTVariable ownerDeclaration = null;
|
||||
/**
|
||||
* @param kind
|
||||
* @param assignmentExpression
|
||||
* @param initializerClauses
|
||||
*/
|
||||
public ASTInitializerClause(Kind kind, IASTExpression assignmentExpression, List initializerClauses, List designators ) {
|
||||
public ASTInitializerClause(Kind kind ) {
|
||||
this.kind = kind;
|
||||
this.assignmentExpression = assignmentExpression;
|
||||
this.initializerClauses = initializerClauses;
|
||||
this.designators = designators;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -52,16 +45,14 @@ public class ASTInitializerClause implements IASTInitializerClause {
|
|||
* @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getInitializerList()
|
||||
*/
|
||||
public Iterator getInitializers() {
|
||||
if( initializerClauses == null )
|
||||
return new EmptyIterator();
|
||||
return initializerClauses.iterator();
|
||||
return EmptyIterator.EMPTY_ITERATOR;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getAssigmentExpression()
|
||||
*/
|
||||
public IASTExpression getAssigmentExpression() {
|
||||
return assignmentExpression;
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -90,7 +81,7 @@ public class ASTInitializerClause implements IASTInitializerClause {
|
|||
*/
|
||||
public Iterator getDesignators()
|
||||
{
|
||||
return designators.iterator();
|
||||
return EmptyIterator.EMPTY_ITERATOR;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -211,7 +211,7 @@ public class ASTMethod extends ASTFunction implements IASTMethod
|
|||
public Iterator getConstructorChainInitializers()
|
||||
{
|
||||
if( constructorChainElements == null )
|
||||
return new EmptyIterator();
|
||||
return EmptyIterator.EMPTY_ITERATOR;
|
||||
return constructorChainElements.iterator();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -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.ASTNotImplementedException;
|
||||
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.IASTAbstractDeclaration;
|
||||
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)
|
||||
{
|
||||
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)
|
||||
|
@ -374,4 +383,11 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
|
|||
// TODO Auto-generated method stub
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -278,7 +278,7 @@ public class GCCScannerExtension implements IScannerExtension {
|
|||
get = (Integer) additionalCOperators.get( image );
|
||||
}
|
||||
if( get == null ) return null;
|
||||
return TokenFactory.createToken(get.intValue(),image,scannerData);
|
||||
return TokenFactory.createUniquelyImagedToken(get.intValue(),image,scannerData);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -467,7 +467,14 @@ public class Scanner implements IScanner {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1127,13 +1134,15 @@ public class Scanner implements IScanner {
|
|||
if( pasting && pasteIntoInputStream(buff))
|
||||
return null;
|
||||
|
||||
int tokenType;
|
||||
|
||||
String result = buff.toString();
|
||||
|
||||
if( floatingPoint && result.equals(".") ) //$NON-NLS-1$
|
||||
tokenType = IToken.tDOT;
|
||||
else
|
||||
tokenType = floatingPoint ? IToken.tFLOATINGPT : IToken.tINTEGER;
|
||||
return newConstantToken( IToken.tDOT );
|
||||
|
||||
int tokenType = floatingPoint ? IToken.tFLOATINGPT : IToken.tINTEGER;
|
||||
if( tokenType == IToken.tINTEGER && hex )
|
||||
tokenType = IToken.tHEXINT;
|
||||
|
||||
return newToken(
|
||||
tokenType,
|
||||
|
@ -2670,7 +2679,7 @@ public class Scanner implements IScanner {
|
|||
protected IMacroDescriptor createObjectMacroDescriptor(String key, String value ) {
|
||||
IToken t = null;
|
||||
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,
|
||||
t,
|
||||
|
|
|
@ -45,7 +45,7 @@ public class ScannerData implements IScannerData
|
|||
private final IScanner scanner;
|
||||
private final IScannerInfo originalConfig;
|
||||
private List includePathNames = new ArrayList();
|
||||
private static final Iterator EMPTY_ITERATOR = new EmptyIterator();
|
||||
|
||||
private final Map privateDefinitions;
|
||||
/**
|
||||
* @return Returns the contextStack.
|
||||
|
@ -183,7 +183,7 @@ public class ScannerData implements IScannerData
|
|||
public Iterator getWorkingCopies() {
|
||||
if( workingCopies != null )
|
||||
return workingCopies.iterator();
|
||||
return EMPTY_ITERATOR;
|
||||
return EmptyIterator.EMPTY_ITERATOR;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -44,7 +44,7 @@ public class SimpleToken extends AbstractToken implements IToken {
|
|||
* @param context
|
||||
*/
|
||||
protected void setOffsetAndLength(IScannerContext context) {
|
||||
offset = context.getOffset() - getImage().length() - context.undoStackSize();
|
||||
offset = context.getOffset() - getLength() - context.undoStackSize();
|
||||
}
|
||||
|
||||
public String getImage() {
|
||||
|
|
|
@ -18,6 +18,27 @@ import org.eclipse.cdt.internal.core.parser.scanner.IScannerData;
|
|||
*/
|
||||
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 )
|
||||
{
|
||||
if( scannerData.getContextStack().getCurrentContext().getMacroOffset() >= 0 )
|
||||
|
@ -32,15 +53,14 @@ public class TokenFactory {
|
|||
* @param scannerData
|
||||
* @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 )
|
||||
return new ImagedExpansionToken( type, scannerData.getContextStack(), image );
|
||||
|
||||
return new ImagedToken(type, scannerData.getContextStack(), image );
|
||||
}
|
||||
|
||||
|
||||
public static IToken createToken( int type, String image )
|
||||
public static IToken createStandAloneToken( int type, String image )
|
||||
{
|
||||
return new ImagedToken( type, image);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue