mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 12:55:40 +02:00
Added caching of type ID's in completeparse mode.
This commit is contained in:
parent
0c44656105
commit
03d8731b43
5 changed files with 56 additions and 30 deletions
|
@ -384,7 +384,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
|
||||||
}
|
}
|
||||||
// Kind POSTFIX_REINTERPRET_CAST
|
// Kind POSTFIX_REINTERPRET_CAST
|
||||||
public void testPostfixReinterpretCast() throws Exception{
|
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();
|
IASTVariable a = (IASTVariable) i.next();
|
||||||
IASTFunction f1 = (IASTFunction) i.next();
|
IASTFunction f1 = (IASTFunction) i.next();
|
||||||
IASTFunction f2 = (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)));
|
assertAllReferences( 2, createTaskList( new Task(a), new Task(f2)));
|
||||||
|
|
||||||
IASTExpression exp = x.getInitializerClause().getAssigmentExpression();
|
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
|
// Kind POSTFIX_STATIC_CAST
|
||||||
public void testPostfixStaticCast() throws Exception{
|
public void testPostfixStaticCast() throws Exception{
|
||||||
|
@ -419,7 +419,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
|
||||||
assertAllReferences( 2, createTaskList( new Task(a), new Task(f2)));
|
assertAllReferences( 2, createTaskList( new Task(a), new Task(f2)));
|
||||||
|
|
||||||
IASTExpression exp = x.getInitializerClause().getAssigmentExpression();
|
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
|
// Kind POSTFIX_TYPEID_EXPRESSION : LHS
|
||||||
public void testPostfixTypeIdExpression() throws Exception{
|
public void testPostfixTypeIdExpression() throws Exception{
|
||||||
|
|
|
@ -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.IASTScope;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
|
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
|
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.IASTTypedefDeclaration;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
|
import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
|
import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
|
||||||
|
@ -1563,7 +1564,7 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
|
||||||
assertFalse( i.hasNext() );
|
assertFalse( i.hasNext() );
|
||||||
IASTExpression exp = a.getInitializerClause().getAssigmentExpression();
|
IASTExpression exp = a.getInitializerClause().getAssigmentExpression();
|
||||||
assertEquals( exp.getExpressionKind(), IASTGCCExpression.Kind.UNARY_ALIGNOF_TYPEID );
|
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
|
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$
|
Iterator i = parse("int c = a <? b;").getDeclarations(); //$NON-NLS-1$
|
||||||
IASTVariable c = (IASTVariable) i.next();
|
IASTVariable c = (IASTVariable) i.next();
|
||||||
IASTExpression exp = c.getInitializerClause().getAssigmentExpression();
|
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
|
public void testBug39698B() throws Exception
|
||||||
{
|
{
|
||||||
Iterator i = parse("int c = a >? b;").getDeclarations(); //$NON-NLS-1$
|
Iterator i = parse("int c = a >? b;").getDeclarations(); //$NON-NLS-1$
|
||||||
IASTVariable c = (IASTVariable) i.next();
|
IASTVariable c = (IASTVariable) i.next();
|
||||||
IASTExpression exp = c.getInitializerClause().getAssigmentExpression();
|
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
|
public void testULong() throws Exception
|
||||||
|
@ -1951,8 +1952,8 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
|
||||||
public void testBug67680() throws Exception
|
public void testBug67680() throws Exception
|
||||||
{
|
{
|
||||||
Writer writer = new StringWriter();
|
Writer writer = new StringWriter();
|
||||||
writer.write( "template < class T> class Base {}; \n" );
|
writer.write( "template < class T> class Base {}; \n" ); //$NON-NLS-1$
|
||||||
writer.write( "class Derived : public Base, Base<int>, foo {}; \n" );
|
writer.write( "class Derived : public Base, Base<int>, foo {}; \n" ); //$NON-NLS-1$
|
||||||
|
|
||||||
Iterator i = parse( writer.toString(), false ).getDeclarations();
|
Iterator i = parse( writer.toString(), false ).getDeclarations();
|
||||||
|
|
||||||
|
@ -1967,4 +1968,12 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
|
||||||
|
|
||||||
assertEquals( parent.getParentClassSpecifier(), base );
|
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$
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -254,17 +254,17 @@ public class ASTUtil {
|
||||||
}
|
}
|
||||||
type.append( id.getFullSignature() );
|
type.append( id.getFullSignature() );
|
||||||
|
|
||||||
Iterator i = id.getPointerOperators();
|
// Iterator i = id.getPointerOperators();
|
||||||
while(i.hasNext()){
|
// while(i.hasNext()){
|
||||||
ASTPointerOperator po = (ASTPointerOperator) i.next();
|
// ASTPointerOperator po = (ASTPointerOperator) i.next();
|
||||||
type.append(getPointerOperator(po));
|
// type.append(getPointerOperator(po));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
i = id.getArrayModifiers();
|
// i = id.getArrayModifiers();
|
||||||
while (i.hasNext()){
|
// while (i.hasNext()){
|
||||||
i.next();
|
// i.next();
|
||||||
type.append("[]"); //$NON-NLS-1$
|
// type.append("[]"); //$NON-NLS-1$
|
||||||
}
|
// }
|
||||||
|
|
||||||
return type.toString();
|
return type.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -632,9 +632,10 @@ public class ExpressionParser implements IExpressionParser, IParserData {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void consumeArrayModifiers(IDeclarator d, IASTScope scope)
|
protected IToken consumeArrayModifiers(IDeclarator d, IASTScope scope)
|
||||||
throws EndOfFileException, BacktrackException {
|
throws EndOfFileException, BacktrackException {
|
||||||
int startingOffset = LA(1).getOffset();
|
int startingOffset = LA(1).getOffset();
|
||||||
|
IToken last = null;
|
||||||
while (LT(1) == IToken.tLBRACKET) {
|
while (LT(1) == IToken.tLBRACKET) {
|
||||||
consume(IToken.tLBRACKET); // eat the '['
|
consume(IToken.tLBRACKET); // eat the '['
|
||||||
|
|
||||||
|
@ -644,7 +645,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
|
||||||
CompletionKind.SINGLE_NAME_REFERENCE,
|
CompletionKind.SINGLE_NAME_REFERENCE,
|
||||||
KeywordSetKey.EXPRESSION);
|
KeywordSetKey.EXPRESSION);
|
||||||
}
|
}
|
||||||
consume(IToken.tRBRACKET);
|
last = consume(IToken.tRBRACKET);
|
||||||
IASTArrayModifier arrayMod = null;
|
IASTArrayModifier arrayMod = null;
|
||||||
try {
|
try {
|
||||||
arrayMod = astFactory.createArrayModifier(exp);
|
arrayMod = astFactory.createArrayModifier(exp);
|
||||||
|
@ -654,6 +655,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
|
||||||
}
|
}
|
||||||
d.addArrayModifier(arrayMod);
|
d.addArrayModifier(arrayMod);
|
||||||
}
|
}
|
||||||
|
return last;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void operatorId(Declarator d, IToken originalToken,
|
protected void operatorId(Declarator d, IToken originalToken,
|
||||||
|
@ -1615,27 +1617,31 @@ public class ExpressionParser implements IExpressionParser, IParserData {
|
||||||
|
|
||||||
TypeId id = getTypeIdInstance(scope);
|
TypeId id = getTypeIdInstance(scope);
|
||||||
IToken last = lastToken;
|
IToken last = lastToken;
|
||||||
|
IToken temp = last;
|
||||||
|
|
||||||
//template parameters are consumed as part of name
|
//template parameters are consumed as part of name
|
||||||
//lastToken = consumeTemplateParameters( last );
|
//lastToken = consumeTemplateParameters( last );
|
||||||
//if( lastToken == null ) lastToken = last;
|
//if( lastToken == null ) lastToken = last;
|
||||||
|
|
||||||
consumePointerOperators(id);
|
temp = consumePointerOperators(id);
|
||||||
if (lastToken == null)
|
if (temp != null)
|
||||||
lastToken = last;
|
last = temp;
|
||||||
|
|
||||||
if (!skipArrayModifiers) {
|
if (!skipArrayModifiers) {
|
||||||
last = lastToken;
|
temp = consumeArrayModifiers(id, scope);
|
||||||
consumeArrayModifiers(id, scope);
|
if (temp != null)
|
||||||
if (lastToken == null)
|
last = temp;
|
||||||
lastToken = last;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String signature = "";//$NON-NLS-1$
|
String signature = "";//$NON-NLS-1$
|
||||||
if (lastToken != null)
|
if (last != null)
|
||||||
|
{
|
||||||
|
if( lastToken == null )
|
||||||
|
lastToken = last;
|
||||||
signature = TokenFactory.createStringRepresentation(mark,
|
signature = TokenFactory.createStringRepresentation(mark,
|
||||||
lastToken);
|
last);
|
||||||
|
}
|
||||||
return astFactory.createTypeId(scope, kind, isConst, isVolatile,
|
return astFactory.createTypeId(scope, kind, isConst, isVolatile,
|
||||||
isShort, isLong, isSigned, isUnsigned, isTypename, name, id
|
isShort, isLong, isSigned, isUnsigned, isTypename, name, id
|
||||||
.getPointerOperators(), id.getArrayModifiers(),
|
.getPointerOperators(), id.getArrayModifiers(),
|
||||||
|
|
|
@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.parser.ast.complete;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Hashtable;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -121,6 +122,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
||||||
private final IFilenameProvider fileProvider;
|
private final IFilenameProvider fileProvider;
|
||||||
private final ParserMode mode;
|
private final ParserMode mode;
|
||||||
private final ReferenceCache cache = new ReferenceCache();
|
private final ReferenceCache cache = new ReferenceCache();
|
||||||
|
private static final int BUILTIN_TYPE_SIZE = 64;
|
||||||
|
private final Hashtable typeIdCache = new Hashtable( BUILTIN_TYPE_SIZE );
|
||||||
|
|
||||||
static
|
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,
|
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
|
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 =
|
ASTTypeId result =
|
||||||
new ASTTypeId( kind, name, pointerOps, arrayMods, completeSignature,
|
new ASTTypeId( kind, name, pointerOps, arrayMods, completeSignature,
|
||||||
isConst, isVolatile, isUnsigned, isSigned, isShort, isLong, isTypename );
|
isConst, isVolatile, isUnsigned, isSigned, isShort, isLong, isTypename );
|
||||||
result.setTypeSymbol( createSymbolForTypeId( scope, result ) );
|
result.setTypeSymbol( createSymbolForTypeId( scope, result ) );
|
||||||
|
if( kind != Type.CLASS_OR_TYPENAME )
|
||||||
|
typeIdCache.put( completeSignature, result );
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue