1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 08:55:25 +02:00

Added caching of type ID's in completeparse mode.

This commit is contained in:
John Camelon 2004-06-18 18:54:00 +00:00
parent 0c44656105
commit 03d8731b43
5 changed files with 56 additions and 30 deletions

View file

@ -384,7 +384,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
}
// Kind POSTFIX_REINTERPRET_CAST
public void testPostfixReinterpretCast() throws Exception{
Iterator i = parse( "int *a; \n int foo(); int foo( double* ); \n int x = foo( reinterpret_cast<double*>(a) );").getDeclarations(); //$NON-NLS-1$
Iterator i = parse( "int *a; \n int foo(); int foo( double* ); \n int x = foo( reinterpret_cast<double *>(a) );").getDeclarations(); //$NON-NLS-1$
IASTVariable a = (IASTVariable) i.next();
IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next();
@ -393,7 +393,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
assertAllReferences( 2, createTaskList( new Task(a), new Task(f2)));
IASTExpression exp = x.getInitializerClause().getAssigmentExpression();
assertEquals( exp.toString(), "foo(reinterpret_cast<double*>(a))" ); //$NON-NLS-1$
assertEquals( exp.toString(), "foo(reinterpret_cast<double *>(a))" ); //$NON-NLS-1$
}
// Kind POSTFIX_STATIC_CAST
public void testPostfixStaticCast() throws Exception{
@ -419,7 +419,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
assertAllReferences( 2, createTaskList( new Task(a), new Task(f2)));
IASTExpression exp = x.getInitializerClause().getAssigmentExpression();
assertEquals( exp.toString(), "foo(const_cast<int*>(&a))" ); //$NON-NLS-1$
assertEquals( exp.toString(), "foo(const_cast<int *>(&a))" ); //$NON-NLS-1$
}
// Kind POSTFIX_TYPEID_EXPRESSION : LHS
public void testPostfixTypeIdExpression() throws Exception{

View file

@ -39,6 +39,7 @@ import org.eclipse.cdt.core.parser.ast.IASTReference;
import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTTypeId;
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
@ -1563,7 +1564,7 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
assertFalse( i.hasNext() );
IASTExpression exp = a.getInitializerClause().getAssigmentExpression();
assertEquals( exp.getExpressionKind(), IASTGCCExpression.Kind.UNARY_ALIGNOF_TYPEID );
assertEquals( exp.toString(), "__alignof__(int)");
assertEquals( exp.toString(), "__alignof__(int)"); //$NON-NLS-1$
}
public void testBug39684() throws Exception
@ -1597,14 +1598,14 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
Iterator i = parse("int c = a <? b;").getDeclarations(); //$NON-NLS-1$
IASTVariable c = (IASTVariable) i.next();
IASTExpression exp = c.getInitializerClause().getAssigmentExpression();
assertEquals( ASTUtil.getExpressionString( exp ), "a <? b" );
assertEquals( ASTUtil.getExpressionString( exp ), "a <? b" ); //$NON-NLS-1$
}
public void testBug39698B() throws Exception
{
Iterator i = parse("int c = a >? b;").getDeclarations(); //$NON-NLS-1$
IASTVariable c = (IASTVariable) i.next();
IASTExpression exp = c.getInitializerClause().getAssigmentExpression();
assertEquals( ASTUtil.getExpressionString( exp ), "a >? b" );
assertEquals( ASTUtil.getExpressionString( exp ), "a >? b" ); //$NON-NLS-1$
}
public void testULong() throws Exception
@ -1951,8 +1952,8 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
public void testBug67680() throws Exception
{
Writer writer = new StringWriter();
writer.write( "template < class T> class Base {}; \n" );
writer.write( "class Derived : public Base, Base<int>, foo {}; \n" );
writer.write( "template < class T> class Base {}; \n" ); //$NON-NLS-1$
writer.write( "class Derived : public Base, Base<int>, foo {}; \n" ); //$NON-NLS-1$
Iterator i = parse( writer.toString(), false ).getDeclarations();
@ -1967,4 +1968,12 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
assertEquals( parent.getParentClassSpecifier(), base );
}
public void testTypeIDSignature() throws Exception
{
IASTVariable v = (IASTVariable) parse( "int * v = (int*)0;").getDeclarations().next();
IASTTypeId typeId = v.getInitializerClause().getAssigmentExpression().getTypeId();
assertEquals( typeId.getFullSignature(), "int *"); //$NON-NLS-1$
}
}

View file

@ -254,17 +254,17 @@ public class ASTUtil {
}
type.append( id.getFullSignature() );
Iterator i = id.getPointerOperators();
while(i.hasNext()){
ASTPointerOperator po = (ASTPointerOperator) i.next();
type.append(getPointerOperator(po));
}
i = id.getArrayModifiers();
while (i.hasNext()){
i.next();
type.append("[]"); //$NON-NLS-1$
}
// Iterator i = id.getPointerOperators();
// while(i.hasNext()){
// ASTPointerOperator po = (ASTPointerOperator) i.next();
// type.append(getPointerOperator(po));
// }
//
// i = id.getArrayModifiers();
// while (i.hasNext()){
// i.next();
// type.append("[]"); //$NON-NLS-1$
// }
return type.toString();
}

View file

@ -632,9 +632,10 @@ public class ExpressionParser implements IExpressionParser, IParserData {
return result;
}
protected void consumeArrayModifiers(IDeclarator d, IASTScope scope)
protected IToken consumeArrayModifiers(IDeclarator d, IASTScope scope)
throws EndOfFileException, BacktrackException {
int startingOffset = LA(1).getOffset();
IToken last = null;
while (LT(1) == IToken.tLBRACKET) {
consume(IToken.tLBRACKET); // eat the '['
@ -644,7 +645,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
CompletionKind.SINGLE_NAME_REFERENCE,
KeywordSetKey.EXPRESSION);
}
consume(IToken.tRBRACKET);
last = consume(IToken.tRBRACKET);
IASTArrayModifier arrayMod = null;
try {
arrayMod = astFactory.createArrayModifier(exp);
@ -654,6 +655,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
}
d.addArrayModifier(arrayMod);
}
return last;
}
protected void operatorId(Declarator d, IToken originalToken,
@ -1615,27 +1617,31 @@ public class ExpressionParser implements IExpressionParser, IParserData {
TypeId id = getTypeIdInstance(scope);
IToken last = lastToken;
IToken temp = last;
//template parameters are consumed as part of name
//lastToken = consumeTemplateParameters( last );
//if( lastToken == null ) lastToken = last;
consumePointerOperators(id);
if (lastToken == null)
lastToken = last;
temp = consumePointerOperators(id);
if (temp != null)
last = temp;
if (!skipArrayModifiers) {
last = lastToken;
consumeArrayModifiers(id, scope);
if (lastToken == null)
lastToken = last;
temp = consumeArrayModifiers(id, scope);
if (temp != null)
last = temp;
}
try {
String signature = "";//$NON-NLS-1$
if (lastToken != null)
if (last != null)
{
if( lastToken == null )
lastToken = last;
signature = TokenFactory.createStringRepresentation(mark,
lastToken);
last);
}
return astFactory.createTypeId(scope, kind, isConst, isVolatile,
isShort, isLong, isSigned, isUnsigned, isTypename, name, id
.getPointerOperators(), id.getArrayModifiers(),

View file

@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@ -121,6 +122,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
private final IFilenameProvider fileProvider;
private final ParserMode mode;
private final ReferenceCache cache = new ReferenceCache();
private static final int BUILTIN_TYPE_SIZE = 64;
private final Hashtable typeIdCache = new Hashtable( BUILTIN_TYPE_SIZE );
static
{
@ -3380,10 +3383,18 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
public IASTTypeId createTypeId(IASTScope scope, Type kind, boolean isConst, boolean isVolatile, boolean isShort,
boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, ITokenDuple name, List pointerOps, List arrayMods, String completeSignature) throws ASTSemanticException
{
if( kind != Type.CLASS_OR_TYPENAME )
{
IASTTypeId check = (IASTTypeId) typeIdCache.get( completeSignature );
if( check != null )
return check;
}
ASTTypeId result =
new ASTTypeId( kind, name, pointerOps, arrayMods, completeSignature,
isConst, isVolatile, isUnsigned, isSigned, isShort, isLong, isTypename );
result.setTypeSymbol( createSymbolForTypeId( scope, result ) );
if( kind != Type.CLASS_OR_TYPENAME )
typeIdCache.put( completeSignature, result );
return result;
}