diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTemplateTests.java index 41cb92fa6f7..345c1669b55 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTemplateTests.java @@ -108,6 +108,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { look = instance.lookup( "i" ); //$NON-NLS-1$ assertEquals( look, i ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -165,6 +166,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { assertTrue( look.isTemplateInstance() ); assertEquals( look.getInstantiatedSymbol(), t ); assertTrue( look.isType( TypeInfo.t_int ) ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -234,6 +236,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { assertTrue( look.isTemplateInstance() ); assertEquals( look.getInstantiatedSymbol(), u ); assertTrue( look.isType( TypeInfo.t_char ) ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -307,6 +310,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ assertEquals( look, f2 ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } @@ -358,6 +362,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { look = f.lookup( "i" ); //$NON-NLS-1$ assertEquals( look, parami ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -446,6 +451,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { look = table.getCompilationUnit().lookupTemplateId( "S", args ); //$NON-NLS-1$ assertTrue( look.isTemplateInstance() ); assertEquals( look.getInstantiatedSymbol(), S ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -477,6 +483,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { ISymbol look = table.getCompilationUnit().lookupTemplateId( "String", args ); //$NON-NLS-1$ assertTrue( look.isTemplateInstance() ); assertEquals( look.getInstantiatedSymbol(), string ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -527,6 +534,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { } catch( ParserSymbolTableException e ){ assertEquals( e.reason, ParserSymbolTableException.r_BadTemplateArgument ); } + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -582,6 +590,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { ISymbol look = table.getCompilationUnit().lookupTemplateId( "X", args ); //$NON-NLS-1$ assertTrue( look.isTemplateInstance() ); assertEquals( look.getInstantiatedSymbol(), X ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -661,6 +670,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { args.add( arg ); assertNotNull( table.getCompilationUnit().lookupTemplateId( "X", args ) ); //$NON-NLS-1$ + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -710,6 +720,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { ISymbol look = table.getCompilationUnit().lookupTemplateId( "B", args ); //$NON-NLS-1$ assertTrue( look.isTemplateInstance() ); assertEquals( look.getInstantiatedSymbol(), B ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -830,6 +841,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { assertEquals( look.getType(), TypeInfo.t_int ); assertEquals( look.getTypeInfo().checkBit( TypeInfo.isLong ), true ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -943,6 +955,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { } catch ( ParserSymbolTableException e ){ assertEquals( e.reason, ParserSymbolTableException.r_BadTemplate ); } + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1018,7 +1031,8 @@ public class ParserSymbolTableTemplateTests extends TestCase { look = ((IDerivableContainerSymbol) look).lookup( "i" ); //$NON-NLS-1$ assertTrue( look.isTemplateInstance() ); assertEquals( look.getInstantiatedSymbol(), i ); - assertEquals( look.getType(), TypeInfo.t_int ); + assertEquals( look.getType(), TypeInfo.t_int ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1092,7 +1106,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { assertTrue( look.isType( TypeInfo.t_float ) ); assertTrue( look.isTemplateInstance() ); assertEquals( look.getInstantiatedSymbol(), newS ); - + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1199,6 +1213,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { assertTrue( look.getInstantiatedSymbol().isTemplateInstance() ); assertEquals( look.getInstantiatedSymbol().getInstantiatedSymbol(), u ); assertTrue( look.isType( TypeInfo.t_int ) ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1246,6 +1261,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { f.getTypeInfo().setBit( true, TypeInfo.isVirtual ); A.addSymbol( f ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1308,6 +1324,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { assertTrue( look != null ); assertTrue( look.isTemplateInstance() ); assertEquals( look.getInstantiatedSymbol(), A2 ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1470,6 +1487,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { } catch ( ParserSymbolTableException e ){ assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); } + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1533,6 +1551,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ assertTrue( look.isTemplateInstance() ); assertEquals( look.getInstantiatedSymbol(), f3 ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1580,6 +1599,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { } catch( ParserSymbolTableException e ){ assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); } + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1661,6 +1681,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { look = table.getCompilationUnit().unqualifiedFunctionLookup( "h", params ); //$NON-NLS-1$ assertTrue( look.isTemplateInstance() ); assertEquals( look.getInstantiatedSymbol(), h1 ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1699,6 +1720,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { TypeInfo type = (TypeInfo) iter.next(); assertTrue( type.isType( TypeInfo.t_type ) ); assertEquals( type.getTypeSymbol(), T ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1741,6 +1763,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { Iterator iter = deferred.getArguments().iterator(); TypeInfo type = (TypeInfo) iter.next(); assertTrue( type.isType( TypeInfo.t_int ) ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1800,6 +1823,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { } catch( ParserSymbolTableException e ){ assertEquals( e.reason, ParserSymbolTableException.r_BadTemplateParameter ); } + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } @@ -1877,6 +1901,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { flook = look.qualifiedFunctionLookup( "f", args ); //$NON-NLS-1$ assertEquals( flook, f3 ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1944,6 +1969,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { assertTrue( look.isTemplateInstance() ); assertEquals( look.getInstantiatedSymbol(), newSort ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -2031,6 +2057,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", args ); //$NON-NLS-1$ assertTrue( look.isTemplateInstance() ); assertEquals( look.getInstantiatedSymbol(), f5 ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } @@ -2119,6 +2146,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", argList ); //$NON-NLS-1$ assertTrue( look.isTemplateInstance()); assertEquals( look.getInstantiatedSymbol(), f ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -2200,6 +2228,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { arg.setTypeSymbol( g3 ); look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", argList ); //$NON-NLS-1$ assertEquals( look, null ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** * template< class T > void f( const T * ){} @@ -2249,6 +2278,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { assertTrue( op.isConst() ); assertEquals( op.getType(), PtrOp.t_pointer ); assertFalse( iter.hasNext() ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -2366,6 +2396,7 @@ public class ParserSymbolTableTemplateTests extends TestCase { //both are the template function instantiated with int, should be the same instance. assertEquals( look, look2 ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } @@ -2592,5 +2623,6 @@ public class ParserSymbolTableTemplateTests extends TestCase { assertTrue( look.isTemplateInstance() ); assertEquals( look.getInstantiatedSymbol(), c3 ); assertTrue( look.isType( TypeInfo.t_float ) ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java index 4acd34bdf30..588673e424a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java @@ -95,6 +95,7 @@ public class ParserSymbolTableTest extends TestCase { assertEquals( false, iter.hasNext() ); assertEquals( x, contained ); assertEquals( contained.getName(), "x" ); //$NON-NLS-1$ + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -111,6 +112,7 @@ public class ParserSymbolTableTest extends TestCase { ISymbol look = table.getCompilationUnit().lookup( "x" ); //$NON-NLS-1$ assertEquals( x, look ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } public void testLookupNonExistant() throws Exception{ @@ -118,6 +120,7 @@ public class ParserSymbolTableTest extends TestCase { ISymbol look = table.getCompilationUnit().lookup("boo"); //$NON-NLS-1$ assertEquals( look, null ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } public void testSimpleSetGetObject() throws Exception{ @@ -134,6 +137,7 @@ public class ParserSymbolTableTest extends TestCase { ISymbol look = table.getCompilationUnit().lookup( "x" ); //$NON-NLS-1$ assertEquals( look.getASTExtension(), extension ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -163,6 +167,7 @@ public class ParserSymbolTableTest extends TestCase { look = table.getCompilationUnit().lookup( "x" ); //$NON-NLS-1$ assertEquals( look, firstX ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -183,6 +188,7 @@ public class ParserSymbolTableTest extends TestCase { ISymbol look = decl.lookup( "x" ); //$NON-NLS-1$ assertEquals( x, look ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -209,6 +215,7 @@ public class ParserSymbolTableTest extends TestCase { ISymbol look = class1.lookup( "x" ); //$NON-NLS-1$ assertEquals( look, decl ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -239,6 +246,7 @@ public class ParserSymbolTableTest extends TestCase { catch ( ParserSymbolTableException e ){ assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); } + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -264,7 +272,7 @@ public class ParserSymbolTableTest extends TestCase { } catch ( ParserSymbolTableException e) { assertEquals( e.reason, ParserSymbolTableException.r_CircularInheritance ); } - + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** * testVirtualParentLookup @@ -306,6 +314,7 @@ public class ParserSymbolTableTest extends TestCase { ISymbol look = decl.lookup( "x" ); //$NON-NLS-1$ assertEquals( look, x ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -340,6 +349,7 @@ public class ParserSymbolTableTest extends TestCase { catch( ParserSymbolTableException e){ assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); } + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -413,6 +423,7 @@ public class ParserSymbolTableTest extends TestCase { catch ( ParserSymbolTableException e){ assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); } + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -458,6 +469,8 @@ public class ParserSymbolTableTest extends TestCase { assertEquals( look, struct ); look = a.elaboratedLookup( TypeInfo.t_union, "union" ); //$NON-NLS-1$ assertEquals( look, union ); + + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -495,6 +508,7 @@ public class ParserSymbolTableTest extends TestCase { look = type.lookup("member"); //$NON-NLS-1$ assertEquals( look, member ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -533,6 +547,7 @@ public class ParserSymbolTableTest extends TestCase { look = f.lookup( "stat" ); //$NON-NLS-1$ assertEquals( look, function ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -639,6 +654,7 @@ public class ParserSymbolTableTest extends TestCase { look = f4.lookup("i"); //$NON-NLS-1$ assertEquals( look, null );//neither i is visible here. + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** * @@ -705,6 +721,7 @@ public class ParserSymbolTableTest extends TestCase { look = ((IContainerSymbol) look).qualifiedLookup("i"); //ok //$NON-NLS-1$ assertEquals( look, nsN_i ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -767,6 +784,7 @@ public class ParserSymbolTableTest extends TestCase { assertEquals( look, nsBC ); look = ((IContainerSymbol)look).qualifiedLookup("a"); //$NON-NLS-1$ assertEquals( look, a ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -833,6 +851,7 @@ public class ParserSymbolTableTest extends TestCase { look = lookB.qualifiedLookup("b"); //$NON-NLS-1$ assertEquals( look, b ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -880,6 +899,7 @@ public class ParserSymbolTableTest extends TestCase { ISymbol look = f.lookup("i"); //$NON-NLS-1$ assertEquals( look, null ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -964,6 +984,7 @@ public class ParserSymbolTableTest extends TestCase { } catch ( ParserSymbolTableException e ) { assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); } + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1008,6 +1029,7 @@ public class ParserSymbolTableTest extends TestCase { //but notice if you wanted to do A::f1 as a function call, it is ok look = lookA.qualifiedLookup( "f1" ); //$NON-NLS-1$ assertEquals( look, f1 ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1094,6 +1116,7 @@ public class ParserSymbolTableTest extends TestCase { catch ( ParserSymbolTableException exception ){ assertTrue( true ); } + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1186,6 +1209,7 @@ public class ParserSymbolTableTest extends TestCase { look = bar.unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ assertTrue( look != null ); assertEquals( look, list.get( index ) ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1217,6 +1241,7 @@ public class ParserSymbolTableTest extends TestCase { assertEquals( ((PtrOp)look.getPtrOperators().iterator().next()).getType(), TypeInfo.PtrOp.t_pointer ); assertEquals( look.getContainingSymbol(), fn ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1247,6 +1272,7 @@ public class ParserSymbolTableTest extends TestCase { assertEquals( look, enumerator ); assertEquals( look.getContainingSymbol(), cls ); assertEquals( look.getTypeSymbol(), enumeration ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1310,6 +1336,7 @@ public class ParserSymbolTableTest extends TestCase { look = main.unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ assertEquals( look, f ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1397,6 +1424,7 @@ public class ParserSymbolTableTest extends TestCase { look = compUnit.unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ assertEquals( look, f2 ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1479,6 +1507,7 @@ public class ParserSymbolTableTest extends TestCase { paramList.add( p3 ); look = C.memberFunctionLookup( "foo", paramList ); //$NON-NLS-1$ assertEquals( look, f3 ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1529,6 +1558,7 @@ public class ParserSymbolTableTest extends TestCase { look = compUnit.unqualifiedFunctionLookup( "f", null ); //$NON-NLS-1$ assertEquals( look, f2 ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1598,6 +1628,7 @@ public class ParserSymbolTableTest extends TestCase { paramList.add( p2 ); look = compUnit.unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ assertEquals( look, f2 ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1685,7 +1716,7 @@ public class ParserSymbolTableTest extends TestCase { p.getOperatorExpressions().clear(); look = compUnit.unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ assertEquals( look, f1 ); - + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1738,6 +1769,7 @@ public class ParserSymbolTableTest extends TestCase { ISymbol look = compUnit.unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ assertEquals( look, f ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1829,6 +1861,7 @@ public class ParserSymbolTableTest extends TestCase { params.add( p3 ); look = main.unqualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ assertEquals( look, f1 ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -1928,6 +1961,7 @@ public class ParserSymbolTableTest extends TestCase { look = compUnit.unqualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ assertEquals( look, f3 ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } // public void testMarkRollback() throws Exception{ @@ -2030,6 +2064,7 @@ public class ParserSymbolTableTest extends TestCase { lookup = table.getCompilationUnit().elaboratedLookup( TypeInfo.t_class, "A" ); //$NON-NLS-1$ assertEquals( lookup, classA ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -2119,6 +2154,7 @@ public class ParserSymbolTableTest extends TestCase { paramList.add( p1 ); look = classB.memberFunctionLookup( "f", paramList ); //$NON-NLS-1$ assertEquals( look, fn1 ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } public void testConstructors() throws Exception{ @@ -2154,6 +2190,7 @@ public class ParserSymbolTableTest extends TestCase { ISymbol lookup = classA.lookupConstructor( paramList ); assertEquals( lookup, constructor2 ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -2187,6 +2224,7 @@ public class ParserSymbolTableTest extends TestCase { lookup = NSB.lookup( "x" ); //$NON-NLS-1$ assertEquals( lookup, x ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -2227,6 +2265,7 @@ public class ParserSymbolTableTest extends TestCase { look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ assertEquals( look, f ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -2267,6 +2306,7 @@ public class ParserSymbolTableTest extends TestCase { look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", paramList ); //$NON-NLS-1$ assertEquals( look, null ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -2341,6 +2381,7 @@ public class ParserSymbolTableTest extends TestCase { } catch ( ParserSymbolTableException e ){ //good } + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -2407,6 +2448,7 @@ public class ParserSymbolTableTest extends TestCase { } catch ( ParserSymbolTableException e ){ //good } + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -2460,6 +2502,7 @@ public class ParserSymbolTableTest extends TestCase { returned = ParserSymbolTable.getConditionalOperand( secondOp, thirdOp ); assertEquals( returned, secondOp ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } public void testbug43834() throws Exception{ @@ -2482,6 +2525,7 @@ public class ParserSymbolTableTest extends TestCase { look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", parameters ); //$NON-NLS-1$ assertEquals( look, f ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -2523,6 +2567,7 @@ public class ParserSymbolTableTest extends TestCase { } catch ( ParserSymbolTableException e ){ assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); } + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -2549,7 +2594,7 @@ public class ParserSymbolTableTest extends TestCase { } catch( ParserSymbolTableException e ){ assertEquals( e.reason, ParserSymbolTableException.r_UnableToResolveFunction ); } - + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -2582,6 +2627,7 @@ public class ParserSymbolTableTest extends TestCase { look = table.getCompilationUnit().unqualifiedFunctionLookup( "initialize", new ArrayList() ); //$NON-NLS-1$ assertEquals( look, init2 ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -2629,6 +2675,7 @@ public class ParserSymbolTableTest extends TestCase { params.clear(); look = B.qualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ assertEquals( look, null ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -2656,6 +2703,7 @@ public class ParserSymbolTableTest extends TestCase { assertTrue( results.contains( aVar ) ); assertTrue( results.contains( anotherVar ) ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -2692,6 +2740,8 @@ public class ParserSymbolTableTest extends TestCase { assertTrue( !results.contains( aVar ) ); assertTrue( results.contains( aField ) ); assertTrue( results.contains( aMethod ) ); + + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -2745,6 +2795,7 @@ public class ParserSymbolTableTest extends TestCase { assertTrue( results.contains( aVar ) ); assertTrue( results.contains( anotherVar2 ) ); assertTrue( results.contains( af2 ) ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -2806,6 +2857,7 @@ public class ParserSymbolTableTest extends TestCase { assertTrue( results != null ); assertEquals( results.size(), 1 ); assertTrue( results.contains( aa ) ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -2834,6 +2886,7 @@ public class ParserSymbolTableTest extends TestCase { assertEquals( null, A.qualifiedLookup( "i" ) ); //$NON-NLS-1$ assertEquals( i, g.lookup( "i" ) ); //$NON-NLS-1$ + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -2898,6 +2951,7 @@ public class ParserSymbolTableTest extends TestCase { assertTrue( table.getCompilationUnit().isVisible(i, C ) ); assertTrue( D.isVisible( j, A ) ); assertFalse( D.isVisible( j, B ) ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -2981,6 +3035,7 @@ public class ParserSymbolTableTest extends TestCase { results = f.prefixLookup( new TypeFilter( LookupKind.FIELDS), "a", false, null ); //$NON-NLS-1$ assertEquals( results.size(), 1 ); assertTrue( results.contains( a3_int ) ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -3006,6 +3061,7 @@ public class ParserSymbolTableTest extends TestCase { ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "foo", params ); //$NON-NLS-1$ assertEquals( foo, look ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -3035,6 +3091,7 @@ public class ParserSymbolTableTest extends TestCase { ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "foo", params ); //$NON-NLS-1$ assertEquals( foo2, look ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -3060,6 +3117,7 @@ public class ParserSymbolTableTest extends TestCase { ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "foo", params ); //$NON-NLS-1$ assertEquals( foo1, look ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -3102,6 +3160,7 @@ public class ParserSymbolTableTest extends TestCase { assertEquals( iter.next(), var ); assertEquals( iter.next(), foo ); assertFalse( iter.hasNext() ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -3180,6 +3239,7 @@ public class ParserSymbolTableTest extends TestCase { assertEquals( iter.next(), using ); assertFalse( iter.hasNext() ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -3211,6 +3271,7 @@ public class ParserSymbolTableTest extends TestCase { params.add( new TypeInfo( TypeInfo.t_int, TypeInfo.isLongLong, null ) ); lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ assertEquals( lookup, f1 ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -3263,6 +3324,7 @@ public class ParserSymbolTableTest extends TestCase { lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ assertEquals( lookup, f ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } public void test_Bool() throws Exception{ @@ -3291,7 +3353,7 @@ public class ParserSymbolTableTest extends TestCase { params.add( new TypeInfo( TypeInfo.t_int, 0, null ) ); look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params ); //$NON-NLS-1$ assertEquals( look, f ); - + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -3316,6 +3378,7 @@ public class ParserSymbolTableTest extends TestCase { f2.addParameter( Int, 0, null, false ); assertTrue( f1.hasSameParameters( f2 ) ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -3332,6 +3395,7 @@ public class ParserSymbolTableTest extends TestCase { g2.addParameter( TypeInfo.t_char, 0, new PtrOp( PtrOp.t_array ), false ); assertTrue( g1.hasSameParameters( g2 ) ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -3351,6 +3415,7 @@ public class ParserSymbolTableTest extends TestCase { h2.addParameter( f, 0, new PtrOp( PtrOp.t_pointer ), false ); assertTrue( h1.hasSameParameters( h2 ) ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } /** @@ -3367,6 +3432,7 @@ public class ParserSymbolTableTest extends TestCase { f2.addParameter( TypeInfo.t_int, TypeInfo.isConst, null, false ); assertTrue( f1.hasSameParameters( f2 ) ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } public void testBug52111RemoveSymbol() throws Exception{ @@ -3436,6 +3502,7 @@ public class ParserSymbolTableTest extends TestCase { assertNull( look ); assertEquals( A.getContainedSymbols().size(), 0 ); + assertEquals( ParserSymbolTable.TypeInfoProvider.numAllocated(), 0 ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTExpression.java index 440576d863c..243aaa97da6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTExpression.java @@ -172,33 +172,37 @@ public abstract class ASTExpression extends ASTNode implements IASTExpression public IContainerSymbol getLookupQualificationSymbol() throws LookupError { ExpressionResult result = getResultType(); TypeInfo type = (result != null ) ? result.getResult() : null; + IContainerSymbol symbol = null; if( type != null ){ - type = type.getFinalType(); + type = type.getFinalType(true); if( type.isType( TypeInfo.t_type ) && type.getTypeSymbol() != null && type.getTypeSymbol() instanceof IContainerSymbol ) { - return (IContainerSymbol) type.getTypeSymbol(); + symbol = (IContainerSymbol) type.getTypeSymbol(); } + type.release(); } - return null; + return symbol; } public boolean shouldFilterLookupResult( ISymbol symbol ){ ExpressionResult result = getResultType(); TypeInfo type = ( result != null ) ? result.getResult() : null; - + boolean shouldFilter = false; if( type != null ){ - type = type.getFinalType(); + type = type.getFinalType(false); if( type.checkBit( TypeInfo.isConst ) && !symbol.getTypeInfo().checkBit( TypeInfo.isConst ) ) - return true; + shouldFilter = true; if( type.checkBit( TypeInfo.isVolatile ) && !symbol.getTypeInfo().checkBit( TypeInfo.isVolatile ) ) - return true; + shouldFilter = true; + + type.release(); } - return false; + return shouldFilter; } /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSymbol.java index bef81ecc94c..2e1d5e51ea6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSymbol.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSymbol.java @@ -42,36 +42,40 @@ public abstract class ASTSymbol extends ASTSymbolOwner implements ISymbolOwner, public IContainerSymbol getLookupQualificationSymbol() throws LookupError { ISymbol sym = getSymbol(); + IContainerSymbol result = null; TypeInfo info = null; try{ - info = sym.getTypeInfo().getFinalType(); + info = sym.getTypeInfo().getFinalType(true); } catch( ParserSymbolTableError e ){ throw new LookupError(); } if( info.isType( TypeInfo.t_type ) && info.getTypeSymbol() != null && info.getTypeSymbol() instanceof IContainerSymbol ) - return (IContainerSymbol) info.getTypeSymbol(); + result = (IContainerSymbol) info.getTypeSymbol(); else if( sym instanceof IContainerSymbol ) - return (IContainerSymbol) sym; + result = (IContainerSymbol) sym; - return null; + info.release(); + return result; } public boolean shouldFilterLookupResult( ISymbol sym ){ + boolean result = false; TypeInfo info = null; try{ - info = getSymbol().getTypeInfo().getFinalType(); + info = getSymbol().getTypeInfo().getFinalType(true); } catch( ParserSymbolTableError e ){ return true; } if( info.checkBit( TypeInfo.isConst ) && !sym.getTypeInfo().checkBit( TypeInfo.isConst ) ) - return true; + result = true; if( info.checkBit( TypeInfo.isVolatile ) && !sym.getTypeInfo().checkBit( TypeInfo.isVolatile ) ) - return true; + result = true; - return false; + info.release(); + return result; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java index e8595d71248..1c9f8f23936 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java @@ -1128,8 +1128,9 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto private boolean createConstructorReference( ISymbol classSymbol, ASTExpression expressionList, ITokenDuple duple, List references ){ if( classSymbol != null && classSymbol.getTypeInfo().checkBit( TypeInfo.isTypedef ) ){ - TypeInfo info = classSymbol.getTypeInfo().getFinalType(); + TypeInfo info = classSymbol.getTypeInfo().getFinalType(true); classSymbol = info.getTypeSymbol(); + info.release(); } if( classSymbol == null || ! (classSymbol instanceof IDerivableContainerSymbol ) ){ return false; @@ -1263,11 +1264,12 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto if(lhsInfo != null){ TypeInfo info = null; try{ - info = lhsInfo.getFinalType(); + info = lhsInfo.getFinalType(true); } catch ( ParserSymbolTableError e ){ return null; } ISymbol containingScope = info.getTypeSymbol(); + info.release(); // assert containingScope != null : "Malformed Expression"; if( containingScope instanceof IDeferredTemplateInstance ) return ((IDeferredTemplateInstance) containingScope).getTemplate().getTemplatedSymbol(); @@ -3440,8 +3442,9 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto } catch (ASTSemanticException e) { } if( classSymbol != null && classSymbol.getTypeInfo().checkBit( TypeInfo.isTypedef ) ){ - TypeInfo info = classSymbol.getTypeInfo().getFinalType(); + TypeInfo info = classSymbol.getTypeInfo().getFinalType(true); classSymbol = (IContainerSymbol) info.getTypeSymbol(); + info.release(); } if( classSymbol == null || ! (classSymbol instanceof IDerivableContainerSymbol ) ){ return null; @@ -3530,13 +3533,18 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto if( ( node instanceof ISymbolOwner ) ) { ISymbol symbol = ((ISymbolOwner) node).getSymbol(); - pointerOps = symbol.getTypeInfo().getFinalType().getPtrOperators(); + TypeInfo info = symbol.getTypeInfo().getFinalType( true ); + pointerOps = info.getPtrOperators(); + info.release(); } else if( node instanceof ASTExpression ) { ISymbol typeSymbol = ((ASTExpression)node).getResultType().getResult().getTypeSymbol(); - if( typeSymbol != null ) - pointerOps = typeSymbol.getTypeInfo().getFinalType().getPtrOperators(); + if( typeSymbol != null ){ + TypeInfo info = typeSymbol.getTypeInfo().getFinalType( true ); + pointerOps = info.getPtrOperators(); + info.release(); + } } else return false; @@ -3556,7 +3564,9 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto if( ( node instanceof ISymbolOwner ) ) { ISymbol symbol = ((ISymbolOwner) node).getSymbol(); - pointerOps = symbol.getTypeInfo().getFinalType().getPtrOperators(); + TypeInfo info = symbol.getTypeInfo().getFinalType( true ); + pointerOps = info.getPtrOperators(); + info.release(); } else if( node instanceof ASTExpression ) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java index 5fb0d3c69be..9d562157ae5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java @@ -691,7 +691,9 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol { ISymbol paramType = null; for( int i = 0; i < size; i++ ){ param = (TypeInfo) parameters.get(i); - paramType = ParserSymbolTable.getFlatTypeInfo( param ).getTypeSymbol(); + TypeInfo info = ParserSymbolTable.getFlatTypeInfo( param, true ); + paramType = info.getTypeSymbol(); + info.release(); if( paramType == null ){ continue; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/DerivableContainerSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/DerivableContainerSymbol.java index 8e9c5d7a129..44d419147af 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/DerivableContainerSymbol.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/DerivableContainerSymbol.java @@ -185,14 +185,19 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva paramType = TemplateEngine.instantiateWithinTemplateScope( this, (ITemplateSymbol) getContainingSymbol() ); } - TypeInfo param = new TypeInfo( TypeInfo.t_type, TypeInfo.isConst, paramType, new TypeInfo.PtrOp( TypeInfo.PtrOp.t_reference, false, false ), false ); + TypeInfo param = ParserSymbolTable.TypeInfoProvider.getTypeInfo(); + param.setType( TypeInfo.t_type ); + param.setBit( true, TypeInfo.isConst ); + param.setTypeSymbol( paramType ); + param.addPtrOperator( new TypeInfo.PtrOp( TypeInfo.PtrOp.t_reference, false, false ) ); parameters.add( param ); IParameterizedSymbol constructor = null; try{ constructor = lookupConstructor( parameters ); } catch ( ParserSymbolTableException e ){ - + } finally { + param.release(); } if( constructor == null ){ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParameterizedSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParameterizedSymbol.java index 16957dba398..789f0e621fd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParameterizedSymbol.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParameterizedSymbol.java @@ -24,6 +24,7 @@ import java.util.TreeMap; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp; +import org.eclipse.cdt.utils.debug.stabs.TypeInformation; /** * @author aniefer @@ -226,8 +227,8 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz fInfo = pf.getTypeInfo(); //parameters that differ only in the use of equivalent typedef types are equivalent. - info = ParserSymbolTable.getFlatTypeInfo( info ); - fInfo = ParserSymbolTable.getFlatTypeInfo( fInfo ); + info = ParserSymbolTable.getFlatTypeInfo( info, true ); + fInfo = ParserSymbolTable.getFlatTypeInfo( fInfo, true ); for( TypeInfo nfo = info; nfo != null; nfo = fInfo ){ //an array declaration is adjusted to become a pointer declaration @@ -255,7 +256,7 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz nfo.setBit( false, TypeInfo.isConst ); nfo.setBit( false, TypeInfo.isVolatile ); } else { - PtrOp op = (PtrOp) nfo.getPtrOperators().listIterator( nfo.getPtrOperators().size() ).previous(); + PtrOp op = (PtrOp) nfo.getPtrOperators().get( nfo.getPtrOperators().size() - 1 ); op.setConst( false ); op.setVolatile( false ); } @@ -264,9 +265,13 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz break; } - if( !info.equals( fInfo ) ){ + boolean equals = info.equals( fInfo ); + + info.release(); + fInfo.release(); + + if( ! equals ) return false; - } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java index 92c63a9c37e..728a6b79a97 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java @@ -455,8 +455,11 @@ public class ParserSymbolTable { return true; } - TypeInfo typeInfo = ParserSymbolTable.getFlatTypeInfo( symbol.getTypeInfo() ); - return data.getFilter().shouldAccept( symbol, typeInfo ) || data.getFilter().shouldAccept( symbol ); + TypeInfo typeInfo = ParserSymbolTable.getFlatTypeInfo( symbol.getTypeInfo(), true ); + boolean accept = data.getFilter().shouldAccept( symbol, typeInfo ) || data.getFilter().shouldAccept( symbol ); + typeInfo.release(); + + return accept; } private static Object collectSymbol(LookupData data, Object object ) throws ParserSymbolTableException { @@ -1013,6 +1016,7 @@ public class ParserSymbolTable { TypeInfo source = null; //parameter we are called with TypeInfo target = null; //function's parameter + TypeInfo voidInfo = null; //used to compare f() and f(void) int comparison; Cost cost = null; //the cost of converting source to target @@ -1030,165 +1034,214 @@ public class ParserSymbolTable { if( numSourceParams == 0 ){ //f() is the same as f( void ) sourceParameters = new ArrayList(1); - sourceParameters.add( new TypeInfo( TypeInfo.t_void, 0, null ) ); + voidInfo = TypeInfoProvider.getTypeInfo(); + voidInfo.setType( TypeInfo.t_void ); + sourceParameters.add( voidInfo ); numSourceParams = 1; } else { sourceParameters = data.getParameters(); } - for( int fnIdx = 0; fnIdx < numFns; fnIdx++ ){ - currFn = (IParameterizedSymbol) functions.get( fnIdx ); - - if( bestFn != null ){ - if( bestFn.isForwardDeclaration() && bestFn.getTypeSymbol() == currFn ){ - bestFn = currFn; - continue; - } else if( currFn.isForwardDeclaration() && currFn.getTypeSymbol() == bestFn ){ - continue; + try { + for( int fnIdx = 0; fnIdx < numFns; fnIdx++ ){ + currFn = (IParameterizedSymbol) functions.get( fnIdx ); + + if( bestFn != null ){ + if( bestFn.isForwardDeclaration() && bestFn.getTypeSymbol() == currFn ){ + bestFn = currFn; + continue; + } else if( currFn.isForwardDeclaration() && currFn.getTypeSymbol() == bestFn ){ + continue; + } } - } - - - if( currFn.getParameterList().isEmpty() && !currFn.hasVariableArgs() ){ - //the only way we get here and have no parameters, is if we are looking - //for a function that takes void parameters ie f( void ) - targetParameters = new ArrayList(1); - targetParameters.add( currFn.getSymbolTable().newSymbol( "", TypeInfo.t_void ) ); //$NON-NLS-1$ - } else { - targetParameters = currFn.getParameterList(); - } - - int numTargetParams = targetParameters.size(); - if( currFnCost == null ){ - currFnCost = new Cost [ numSourceParams ]; - } - - comparison = 0; - boolean varArgs = false; - - for( int j = 0; j < numSourceParams; j++ ){ - source = (TypeInfo) sourceParameters.get(j); - if( j < numTargetParams ) - target = ((ISymbol)targetParameters.get(j)).getTypeInfo(); - else - varArgs = true; - if( varArgs ){ - cost = new Cost( source, null ); - cost.rank = Cost.ELLIPSIS_CONVERSION; - } else if ( target.getHasDefault() && source.isType( TypeInfo.t_void ) && !source.hasPtrOperators() ){ - //source is just void, ie no parameter, if target had a default, then use that - cost = new Cost( source, target ); - cost.rank = Cost.IDENTITY_RANK; - } else if( source.equals( target ) ){ - cost = new Cost( source, target ); - cost.rank = Cost.IDENTITY_RANK; //exact match, no cost + if( currFn.getParameterList().isEmpty() && !currFn.hasVariableArgs() ){ + //the only way we get here and have no parameters, is if we are looking + //for a function that takes void parameters ie f( void ) + targetParameters = new ArrayList(1); + targetParameters.add( currFn.getSymbolTable().newSymbol( "", TypeInfo.t_void ) ); //$NON-NLS-1$ } else { + targetParameters = currFn.getParameterList(); + } - cost = checkStandardConversionSequence( source, target ); + int numTargetParams = targetParameters.size(); + if( currFnCost == null ){ + currFnCost = new Cost [ numSourceParams ]; + } + + comparison = 0; + boolean varArgs = false; + + for( int j = 0; j < numSourceParams; j++ ){ + source = (TypeInfo) sourceParameters.get(j); - //12.3-4 At most one user-defined conversion is implicitly applied to - //a single value. (also prevents infinite loop) - if( cost.rank == Cost.NO_MATCH_RANK && !data.forUserDefinedConversion ){ - temp = checkUserDefinedConversionSequence( source, target ); - if( temp != null ){ - cost = temp; + if( j < numTargetParams ) + target = ((ISymbol)targetParameters.get(j)).getTypeInfo(); + else + varArgs = true; + + if( varArgs ){ + cost = new Cost( source, null ); + cost.rank = Cost.ELLIPSIS_CONVERSION; + } else if ( target.getHasDefault() && source.isType( TypeInfo.t_void ) && !source.hasPtrOperators() ){ + //source is just void, ie no parameter, if target had a default, then use that + cost = new Cost( source, target ); + cost.rank = Cost.IDENTITY_RANK; + } else if( source.equals( target ) ){ + cost = new Cost( source, target ); + cost.rank = Cost.IDENTITY_RANK; //exact match, no cost + } else { + try{ + cost = checkStandardConversionSequence( source, target ); + + //12.3-4 At most one user-defined conversion is implicitly applied to + //a single value. (also prevents infinite loop) + if( cost.rank == Cost.NO_MATCH_RANK && !data.forUserDefinedConversion ){ + temp = checkUserDefinedConversionSequence( source, target ); + if( temp != null ){ + cost.release(); + cost = temp; + } + } + } catch( ParserSymbolTableException e ) { + if( cost != null ) { cost.release(); cost = null; } + if( temp != null ) { temp.release(); temp = null; } + throw e; + } catch( ParserSymbolTableError e ) { + if( cost != null ) { cost.release(); cost = null; } + if( temp != null ) { temp.release(); temp = null; } + throw e; } } - } - - currFnCost[ j ] = cost; - } - - - hasWorse = false; - hasBetter = false; - //In order for this function to be better than the previous best, it must - //have at least one parameter match that is better that the corresponding - //match for the other function, and none that are worse. - for( int j = 0; j < numSourceParams; j++ ){ - if( currFnCost[ j ].rank < 0 ){ - hasWorse = true; - hasBetter = false; - if( data.isPrefixLookup() ){ - //for prefix lookup, just remove from the function list those functions - //that don't fit the parameters - functions.remove( fnIdx-- ); - numFns--; - } - break; + currFnCost[ j ] = cost; } - //an ambiguity in the user defined conversion sequence is only a problem - //if this function turns out to be the best. - currHasAmbiguousParam = ( currFnCost[ j ].userDefined == 1 ); - if( bestFnCost != null ){ - comparison = currFnCost[ j ].compare( bestFnCost[ j ] ); - hasWorse |= ( comparison < 0 ); - hasBetter |= ( comparison > 0 ); - } else { - hasBetter = true; - } - } - - //during a prefix lookup, we don't need to rank the functions - if( data.isPrefixLookup() ) - continue; - - //If function has a parameter match that is better than the current best, - //and another that is worse (or everything was just as good, neither better nor worse). - //then this is an ambiguity (unless we find something better than both later) - ambiguous |= ( hasWorse && hasBetter ) || ( !hasWorse && !hasBetter ); - - if( !hasWorse ){ - if( !hasBetter ){ - //if they are both template functions, we can order them that way - boolean bestIsTemplate = bestFn.getContainingSymbol() instanceof ITemplateSymbol; - boolean currIsTemplate = currFn.getContainingSymbol() instanceof ITemplateSymbol; - if( bestIsTemplate && currIsTemplate ) - { - ITemplateSymbol t1 = (ITemplateSymbol) bestFn.getInstantiatedSymbol().getContainingSymbol(); - ITemplateSymbol t2 = (ITemplateSymbol) currFn.getInstantiatedSymbol().getContainingSymbol(); - int order = TemplateEngine.orderTemplateFunctions( t1, t2 ); - if ( order < 0 ){ - hasBetter = true; - } else if( order > 0 ){ - ambiguous = false; + hasWorse = false; + hasBetter = false; + //In order for this function to be better than the previous best, it must + //have at least one parameter match that is better that the corresponding + //match for the other function, and none that are worse. + for( int j = 0; j < numSourceParams; j++ ){ + if( currFnCost[ j ].rank < 0 ){ + hasWorse = true; + hasBetter = false; + + if( data.isPrefixLookup() ){ + //for prefix lookup, just remove from the function list those functions + //that don't fit the parameters + functions.remove( fnIdx-- ); + numFns--; } + break; + } + + //an ambiguity in the user defined conversion sequence is only a problem + //if this function turns out to be the best. + currHasAmbiguousParam = ( currFnCost[ j ].userDefined == 1 ); + + if( bestFnCost != null ){ + comparison = currFnCost[ j ].compare( bestFnCost[ j ] ); + hasWorse |= ( comparison < 0 ); + hasBetter |= ( comparison > 0 ); + } else { + hasBetter = true; } - //we prefer normal functions over template functions, unless we specified template arguments - else if( bestIsTemplate && !currIsTemplate ){ - if( data.getTemplateParameters() == null ) - hasBetter = true; - else - ambiguous = false; - } else if( !bestIsTemplate && currIsTemplate ){ - if( data.getTemplateParameters() == null ) - ambiguous = false; - else - hasBetter = true; - } } - if( hasBetter ){ - //the new best function. - ambiguous = false; - bestFnCost = currFnCost; - bestHasAmbiguousParam = currHasAmbiguousParam; - currFnCost = null; - bestFn = currFn; - } + + //during a prefix lookup, we don't need to rank the functions + if( data.isPrefixLookup() ){ + releaseCosts( currFnCost ); + continue; + } + + //If function has a parameter match that is better than the current best, + //and another that is worse (or everything was just as good, neither better nor worse). + //then this is an ambiguity (unless we find something better than both later) + ambiguous |= ( hasWorse && hasBetter ) || ( !hasWorse && !hasBetter ); + + if( !hasWorse ){ + if( !hasBetter ){ + //if they are both template functions, we can order them that way + boolean bestIsTemplate = bestFn.getContainingSymbol() instanceof ITemplateSymbol; + boolean currIsTemplate = currFn.getContainingSymbol() instanceof ITemplateSymbol; + if( bestIsTemplate && currIsTemplate ) + { + try{ + ITemplateSymbol t1 = (ITemplateSymbol) bestFn.getInstantiatedSymbol().getContainingSymbol(); + ITemplateSymbol t2 = (ITemplateSymbol) currFn.getInstantiatedSymbol().getContainingSymbol(); + int order = TemplateEngine.orderTemplateFunctions( t1, t2 ); + if ( order < 0 ){ + hasBetter = true; + } else if( order > 0 ){ + ambiguous = false; + } + } catch( ParserSymbolTableException e ) { + if( currFnCost != null ) releaseCosts( currFnCost ); + if( bestFnCost != null ) releaseCosts( bestFnCost ); + throw e; + } catch( ParserSymbolTableError e ) { + if( currFnCost != null ) releaseCosts( currFnCost ); + if( bestFnCost != null ) releaseCosts( bestFnCost ); + throw e; + } + } + //we prefer normal functions over template functions, unless we specified template arguments + else if( bestIsTemplate && !currIsTemplate ){ + if( data.getTemplateParameters() == null ) + hasBetter = true; + else + ambiguous = false; + } else if( !bestIsTemplate && currIsTemplate ){ + if( data.getTemplateParameters() == null ) + ambiguous = false; + else + hasBetter = true; + } + } + if( hasBetter ){ + //the new best function. + ambiguous = false; + releaseCosts( bestFnCost ); + bestFnCost = currFnCost; + bestHasAmbiguousParam = currHasAmbiguousParam; + currFnCost = null; + bestFn = currFn; + } else { + releaseCosts( currFnCost ); + } + } else { + releaseCosts( currFnCost ); + } } + } finally { + if( currFnCost != null ){ + releaseCosts( currFnCost ); + currFnCost = null; + } + if( bestFnCost != null ){ + releaseCosts( bestFnCost ); + bestFnCost = null; + } + if( voidInfo != null ) + voidInfo.release(); } - + if( ambiguous || bestHasAmbiguousParam ){ throw new ParserSymbolTableException( ParserSymbolTableException.r_Ambiguous ); } return bestFn; } + static private void releaseCosts( Cost [] costs ){ + if( costs != null ) { + for( int i = 0; i < costs.length; i++ ){ + costs[i].release(); + } + } + } static private boolean functionHasParameters( IParameterizedSymbol function, List params ){ if( params == null ){ @@ -1518,7 +1571,7 @@ public class ParserSymbolTable { //lvalues will have type t_type if( source.isType( TypeInfo.t_type ) ){ - source = getFlatTypeInfo( source ); + source = getFlatTypeInfo( source, false ); } if( target.isType( TypeInfo.t_type ) ){ @@ -1534,14 +1587,14 @@ public class ParserSymbolTable { //if either source or target is null here, then there was a problem //with the parameters and we can't match them. - if( cost.source == null || cost.target == null ){ + if( cost.getSource() == null || cost.getTarget() == null ){ return cost; } TypeInfo.PtrOp op = null; - if( cost.source.hasPtrOperators() ){ - List sourcePtrs = cost.source.getPtrOperators(); + if( cost.getSource().hasPtrOperators() ){ + List sourcePtrs = cost.getSource().getPtrOperators(); TypeInfo.PtrOp ptr = (TypeInfo.PtrOp)sourcePtrs.get( 0 ); if( ptr.getType() == TypeInfo.PtrOp.t_reference ){ sourcePtrs.remove( 0 ); @@ -1555,8 +1608,8 @@ public class ParserSymbolTable { } } - if( cost.target.hasPtrOperators() ){ - List targetPtrs = cost.target.getPtrOperators(); + if( cost.getTarget().hasPtrOperators() ){ + List targetPtrs = cost.getTarget().getPtrOperators(); //ListIterator iterator = targetPtrs.listIterator(); TypeInfo.PtrOp ptr = (TypeInfo.PtrOp)targetPtrs.get(0); @@ -1583,8 +1636,8 @@ public class ParserSymbolTable { * see spec section 4.4 regarding qualification conversions */ static private void qualificationConversion( Cost cost ){ - List sourcePtrs = cost.source.getPtrOperators(); - List targetPtrs = cost.target.getPtrOperators(); + List sourcePtrs = cost.getSource().getPtrOperators(); + List targetPtrs = cost.getTarget().getPtrOperators(); int size = sourcePtrs.size(); int size2 = targetPtrs.size(); @@ -1626,8 +1679,8 @@ public class ParserSymbolTable { } } - if( ( cost.source.checkBit( TypeInfo.isConst ) && !cost.target.checkBit( TypeInfo.isConst ) ) || - ( cost.source.checkBit( TypeInfo.isVolatile ) && !cost.target.checkBit( TypeInfo.isVolatile ) ) ) + if( ( cost.getSource().checkBit( TypeInfo.isConst ) && !cost.getTarget().checkBit( TypeInfo.isConst ) ) || + ( cost.getSource().checkBit( TypeInfo.isVolatile ) && !cost.getTarget().checkBit( TypeInfo.isVolatile ) ) ) { canConvert = false; } @@ -1655,8 +1708,8 @@ public class ParserSymbolTable { * 4.6 float can be promoted to double */ static private void promotion( Cost cost ){ - TypeInfo src = cost.source; - TypeInfo trg = cost.target; + TypeInfo src = cost.getSource(); + TypeInfo trg = cost.getTarget(); int mask = TypeInfo.isShort | TypeInfo.isLong | TypeInfo.isUnsigned | TypeInfo.isLongLong | TypeInfo.isSigned; @@ -1689,8 +1742,8 @@ public class ParserSymbolTable { * */ static private void conversion( Cost cost ){ - TypeInfo src = cost.source; - TypeInfo trg = cost.target; + TypeInfo src = cost.getSource(); + TypeInfo trg = cost.getTarget(); int temp = -1; @@ -1772,8 +1825,8 @@ public class ParserSymbolTable { } static private void derivedToBaseConversion( Cost cost ) throws ParserSymbolTableException{ - TypeInfo src = cost.source; - TypeInfo trg = cost.target; + TypeInfo src = cost.getSource(); + TypeInfo trg = cost.getTarget(); ISymbol srcDecl = src.isType( TypeInfo.t_type ) ? src.getTypeSymbol() : null; ISymbol trgDecl = trg.isType( TypeInfo.t_type ) ? trg.getTypeSymbol() : null; @@ -1793,11 +1846,11 @@ public class ParserSymbolTable { static protected Cost checkStandardConversionSequence( TypeInfo source, TypeInfo target ) throws ParserSymbolTableException{ Cost cost = lvalue_to_rvalue( source, target ); - if( cost.source == null || cost.target == null ){ + if( cost.getSource() == null || cost.getTarget() == null ){ return cost; } - if( cost.source.equals( cost.target ) ){ + if( cost.getSource().equals( cost.getTarget() ) ){ cost.rank = Cost.IDENTITY_RANK; return cost; } @@ -1810,10 +1863,10 @@ public class ParserSymbolTable { } //was the qualification conversion enough? - if( cost.source.isType( TypeInfo.t_type ) && cost.target.isType( TypeInfo.t_type ) ){ - if( cost.target.hasSamePtrs( cost.source ) ){ - ISymbol srcSymbol = cost.source.getTypeSymbol(); - ISymbol trgSymbol = cost.target.getTypeSymbol(); + if( cost.getSource().isType( TypeInfo.t_type ) && cost.getTarget().isType( TypeInfo.t_type ) ){ + if( cost.getTarget().hasSamePtrs( cost.getSource() ) ){ + ISymbol srcSymbol = cost.getSource().getTypeSymbol(); + ISymbol trgSymbol = cost.getTarget().getTypeSymbol(); if( srcSymbol != null && trgSymbol != null ){ if( srcSymbol.equals( trgSymbol ) ) { @@ -1821,8 +1874,8 @@ public class ParserSymbolTable { } } } - } else if( cost.source.getType() == cost.target.getType() && - (cost.source.getTypeInfo() & ~TypeInfo.isConst & ~TypeInfo.isVolatile) == (cost.target.getTypeInfo() & ~TypeInfo.isConst & ~TypeInfo.isVolatile) ) + } else if( cost.getSource().getType() == cost.getTarget().getType() && + (cost.getSource().getTypeInfo() & ~TypeInfo.isConst & ~TypeInfo.isVolatile) == (cost.getTarget().getTypeInfo() & ~TypeInfo.isConst & ~TypeInfo.isVolatile) ) { return cost; } @@ -1884,8 +1937,9 @@ public class ParserSymbolTable { //conversion operators if( source.getType() == TypeInfo.t_type ){ - source = getFlatTypeInfo( source ); + source = getFlatTypeInfo( source, true ); sourceDecl = ( source != null ) ? source.getTypeSymbol() : null; + source.release(); if( sourceDecl != null && (sourceDecl instanceof IContainerSymbol) ){ String name = target.toString(); @@ -1902,32 +1956,46 @@ public class ParserSymbolTable { } } - if( constructor != null ){ - constructorCost = checkStandardConversionSequence( new TypeInfo( TypeInfo.t_type, 0, constructor.getContainingSymbol() ), target ); - } - if( conversion != null ){ - conversionCost = checkStandardConversionSequence( new TypeInfo( target.getType(), 0, target.getTypeSymbol() ), target ); - } - - //if both are valid, then the conversion is ambiguous - if( constructorCost != null && constructorCost.rank != Cost.NO_MATCH_RANK && - conversionCost != null && conversionCost.rank != Cost.NO_MATCH_RANK ) - { - cost = constructorCost; - cost.userDefined = Cost.AMBIGUOUS_USERDEFINED_CONVERSION; - cost.rank = Cost.USERDEFINED_CONVERSION_RANK; - } else { - if( constructorCost != null && constructorCost.rank != Cost.NO_MATCH_RANK ){ + try { + if( constructor != null ){ + TypeInfo info = TypeInfoProvider.getTypeInfo(); + info.setType( TypeInfo.t_type ); + info.setTypeSymbol( constructor.getContainingSymbol() ); + constructorCost = checkStandardConversionSequence( info, target ); + info.release(); + } + if( conversion != null ){ + TypeInfo info = TypeInfoProvider.getTypeInfo(); + info.setType( target.getType() ); + info.setTypeSymbol( target.getTypeSymbol() ); + conversionCost = checkStandardConversionSequence( info, target ); + info.release(); + } + + //if both are valid, then the conversion is ambiguous + if( constructorCost != null && constructorCost.rank != Cost.NO_MATCH_RANK && + conversionCost != null && conversionCost.rank != Cost.NO_MATCH_RANK ) + { cost = constructorCost; - cost.userDefined = constructor.hashCode(); + cost.userDefined = Cost.AMBIGUOUS_USERDEFINED_CONVERSION; cost.rank = Cost.USERDEFINED_CONVERSION_RANK; - } else if( conversionCost != null && conversionCost.rank != Cost.NO_MATCH_RANK ){ - cost = conversionCost; - cost.userDefined = conversion.hashCode(); - cost.rank = Cost.USERDEFINED_CONVERSION_RANK; - } + } else { + if( constructorCost != null && constructorCost.rank != Cost.NO_MATCH_RANK ){ + cost = constructorCost; + cost.userDefined = constructor.hashCode(); + cost.rank = Cost.USERDEFINED_CONVERSION_RANK; + } else if( conversionCost != null && conversionCost.rank != Cost.NO_MATCH_RANK ){ + cost = conversionCost; + cost.userDefined = conversion.hashCode(); + cost.rank = Cost.USERDEFINED_CONVERSION_RANK; + } + } + } finally { + if( constructorCost != null && constructorCost != cost ) + constructorCost.release(); + if( conversionCost != null && conversionCost != cost ) + conversionCost.release(); } - return cost; } @@ -1944,20 +2012,32 @@ public class ParserSymbolTable { * - If exactly one conversion is possible, that conversion is applied ( return the other TypeInfo ) */ static public TypeInfo getConditionalOperand( TypeInfo secondOp, TypeInfo thirdOp ) throws ParserSymbolTableException{ + Cost thirdCost = null, secondCost = null; + TypeInfo temp = null; - //can secondOp convert to thirdOp ? - Cost secondCost = checkStandardConversionSequence( secondOp, getFlatTypeInfo( thirdOp ) ); - - if( secondCost.rank == Cost.NO_MATCH_RANK ){ - secondCost = checkUserDefinedConversionSequence( secondOp, getFlatTypeInfo( thirdOp ) ); + try{ + //can secondOp convert to thirdOp ? + temp = getFlatTypeInfo( thirdOp, true ); + secondCost = checkStandardConversionSequence( secondOp, temp ); + + if( secondCost.rank == Cost.NO_MATCH_RANK ){ + secondCost.release(); + secondCost = checkUserDefinedConversionSequence( secondOp, temp ); + } + temp.release(); + temp = getFlatTypeInfo( secondOp, true ); + + thirdCost = checkStandardConversionSequence( thirdOp, temp ); + if( thirdCost.rank == Cost.NO_MATCH_RANK ){ + thirdCost.release(); + thirdCost = checkUserDefinedConversionSequence( thirdOp, temp ); + } + } finally { + if( thirdCost != null ) thirdCost.release(); + if( secondCost != null ) secondCost.release(); + if( temp != null ) temp.release(); } - Cost thirdCost = checkStandardConversionSequence( thirdOp, getFlatTypeInfo( secondOp ) ); - if( thirdCost.rank == Cost.NO_MATCH_RANK ){ - thirdCost = checkUserDefinedConversionSequence( thirdOp, getFlatTypeInfo( secondOp ) ); - } - - boolean canConvertSecond = ( secondCost != null && secondCost.rank != Cost.NO_MATCH_RANK ); boolean canConvertThird = ( thirdCost != null && thirdCost.rank != Cost.NO_MATCH_RANK ); @@ -1985,17 +2065,20 @@ public class ParserSymbolTable { /** * + * @param usePool TODO * @param decl * @return TypeInfo * The top level TypeInfo represents modifications to the object and the * remaining TypeInfo's represent the object. */ - static protected TypeInfo getFlatTypeInfo( TypeInfo topInfo ){ - TypeInfo returnInfo = topInfo; + static protected TypeInfo getFlatTypeInfo( TypeInfo topInfo, boolean usePool ){ + TypeInfo returnInfo = null; TypeInfo info = null; if( topInfo.getType() == TypeInfo.t_type && topInfo.getTypeSymbol() != null ){ - returnInfo = new TypeInfo(); + if( usePool ) returnInfo = TypeInfoProvider.getTypeInfo(); + else returnInfo = new TypeInfo(); + returnInfo.setTypeInfo( topInfo.getTypeInfo() ); ISymbol typeSymbol = topInfo.getTypeSymbol(); @@ -2007,8 +2090,11 @@ public class ParserSymbolTable { returnInfo.addPtrOperator( info.getPtrOperators() ); returnInfo.setTypeInfo( ( returnInfo.getTypeInfo() | info.getTypeInfo() ) & ~TypeInfo.isTypedef & ~TypeInfo.isForward ); info = typeSymbol.getTypeInfo(); - if( ++j > TYPE_LOOP_THRESHOLD ) + if( ++j > TYPE_LOOP_THRESHOLD ){ + if( usePool ) + returnInfo.release(); throw new ParserSymbolTableError(); + } } if( info.isType( TypeInfo.t_class, TypeInfo.t_enumeration ) || info.isType( TypeInfo.t_function ) ){ @@ -2031,7 +2117,11 @@ public class ParserSymbolTable { returnInfo.addPtrOperator( ptr ); } } else { - returnInfo = new TypeInfo( topInfo ); + if( usePool ){ + returnInfo = TypeInfoProvider.getTypeInfo(); + returnInfo.copy( topInfo ); + } else + returnInfo = new TypeInfo( topInfo ); } return returnInfo; @@ -2040,7 +2130,8 @@ public class ParserSymbolTable { private IContainerSymbol _compilationUnit; private ParserLanguage _language; private ParserMode _mode; -public void setLanguage( ParserLanguage language ){ + + public void setLanguage( ParserLanguage language ){ _language = language; } @@ -2143,12 +2234,17 @@ public void setLanguage( ParserLanguage language ){ { public Cost( TypeInfo s, TypeInfo t ){ - source = ( s != null ) ? new TypeInfo( s ) : new TypeInfo(); - target = ( t != null ) ? new TypeInfo( t ) : new TypeInfo(); + source = TypeInfoProvider.getTypeInfo(); + if( s != null ) + source.copy( s ); + + target = TypeInfoProvider.getTypeInfo(); + if( t != null ) + target.copy( t ); } - public TypeInfo source; - public TypeInfo target; + private TypeInfo source; + private TypeInfo target; public boolean targetHadReference = false; @@ -2172,6 +2268,10 @@ public void setLanguage( ParserLanguage language ){ public static final int USERDEFINED_CONVERSION_RANK = 4; public static final int ELLIPSIS_CONVERSION = 5; + public void release(){ + getSource().release(); + getTarget().release(); + } public int compare( Cost cost ){ int result = 0; @@ -2210,11 +2310,11 @@ public void setLanguage( ParserLanguage language ){ } else if( (cost.qualification == qualification) && qualification == 0 ){ return 0; } else { - int size = cost.target.hasPtrOperators() ? cost.target.getPtrOperators().size() : 0; - int size2 = target.hasPtrOperators() ? target.getPtrOperators().size() : 0; + int size = cost.getTarget().hasPtrOperators() ? cost.getTarget().getPtrOperators().size() : 0; + int size2 = getTarget().hasPtrOperators() ? getTarget().getPtrOperators().size() : 0; - ListIterator iter1 = cost.target.getPtrOperators().listIterator( size ); - ListIterator iter2 = target.getPtrOperators().listIterator( size2 ); + ListIterator iter1 = cost.getTarget().getPtrOperators().listIterator( size ); + ListIterator iter2 = getTarget().getPtrOperators().listIterator( size2 ); TypeInfo.PtrOp op1 = null, op2 = null; @@ -2246,6 +2346,20 @@ public void setLanguage( ParserLanguage language ){ return result; } + + /** + * @return Returns the source. + */ + public TypeInfo getSource() { + return source; + } + + /** + * @return Returns the target. + */ + public TypeInfo getTarget() { + return target; + } } /** @@ -2321,4 +2435,62 @@ public void setLanguage( ParserLanguage language ){ } return resultingAccess; } + + public static class TypeInfoProvider + { + private static final int POOL_SIZE = 16; + private static final TypeInfo [] pool; + private static final boolean [] free; + private static int firstFreeHint = 0; + + static + { + pool = new TypeInfo[ POOL_SIZE ]; + free = new boolean[POOL_SIZE]; + for( int i = 0; i < POOL_SIZE; i++ ) + { + pool[i] = new TypeInfo(); + free[i] = true; + } + } + + public static synchronized TypeInfo getTypeInfo() + { + for( int i = firstFreeHint; i < POOL_SIZE; ++i ) + { + if( free[i] ) + { + free[i] = false; + firstFreeHint = i + 1; + return pool[i]; + } + } + //if there is nothing free, just give them a new one + return new TypeInfo(); + } + + public static synchronized void returnTypeInfo( TypeInfo t ) + { + for( int i = 0; i < POOL_SIZE; i++ ){ + if( pool[i] == t ){ + t.clear(); + free[i] = true; + if( i < firstFreeHint ){ + firstFreeHint = i; + } + return; + } + } + //else it was one allocated outside the pool + } + + public static synchronized int numAllocated(){ + int num = 0; + for( int i = 0; i < POOL_SIZE; i++ ){ + if( !free[i] ) + num++; + } + return num; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateEngine.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateEngine.java index ea37d5ffcbf..621d8c27e4c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateEngine.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateEngine.java @@ -166,16 +166,21 @@ public final class TemplateEngine { return true; } else { Cost cost = null; - try { - TypeInfo info = new TypeInfo( param.getTypeInfo() ); - info.setType( info.getTemplateParameterType() ); - cost = ParserSymbolTable.checkStandardConversionSequence( arg, info ); - } catch (ParserSymbolTableException e) { + try{ + try { + TypeInfo info = new TypeInfo( param.getTypeInfo() ); + info.setType( info.getTemplateParameterType() ); + cost = ParserSymbolTable.checkStandardConversionSequence( arg, info ); + } catch (ParserSymbolTableException e) { + } + + if( cost == null || cost.rank != Cost.NO_MATCH_RANK ){ + return false; + } + } finally{ + if( cost != null ) + cost.release(); } - - if( cost == null || cost.rank != Cost.NO_MATCH_RANK ){ - return false; - } } return true; } @@ -307,7 +312,7 @@ public final class TemplateEngine { */ static private TypeInfo getArgumentTypeForDeduction( TypeInfo aInfo, boolean pIsAReferenceType ) throws ParserSymbolTableException{ - TypeInfo a = ParserSymbolTable.getFlatTypeInfo( aInfo ); + TypeInfo a = ParserSymbolTable.getFlatTypeInfo( aInfo, false ); if( !pIsAReferenceType ){ ISymbol aSymbol = a.getTypeSymbol(); @@ -689,7 +694,7 @@ public final class TemplateEngine { static private boolean deduceArgument( Map map, ISymbol p, TypeInfo a ){ - a = ParserSymbolTable.getFlatTypeInfo( a ); + a = ParserSymbolTable.getFlatTypeInfo( a, false ); if( map.containsKey( p ) ){ TypeInfo current = (TypeInfo)map.get( p ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TypeInfo.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TypeInfo.java index 0531d5e0495..944e8ad4da7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TypeInfo.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TypeInfo.java @@ -12,7 +12,6 @@ package org.eclipse.cdt.internal.core.parser.pst; import java.util.ArrayList; import java.util.Collections; -import java.util.Iterator; import java.util.List; import java.util.ListIterator; @@ -286,8 +285,14 @@ public class TypeInfo { _templateParameterType = type; } - public TypeInfo getFinalType(){ - return ParserSymbolTable.getFlatTypeInfo( this ); + /** + * + * @param usePool - whether or not use to the pool, if true, TypeInfo.release() must + * be called on the returned TypeInfo when itis no longer needed + * @return + */ + public TypeInfo getFinalType(boolean usePool){ + return ParserSymbolTable.getFlatTypeInfo( this, usePool ); } /** * @@ -531,6 +536,40 @@ public class TypeInfo { return TypeInfo._image[ getType().toInt() ]; } + public void clear(){ + _typeBits = 0; + _type = TypeInfo.t_undef; + _templateParameterType = t_typeName; + _typeDeclaration = null; + _hasDefaultValue = false; + _defaultValue = null; + _ptrOperators = Collections.EMPTY_LIST; + _operatorExpressions = Collections.EMPTY_LIST; + } + + public void copy( TypeInfo t ){ + _typeBits = t._typeBits; + _type = t._type; + _templateParameterType = t._templateParameterType; + _typeDeclaration = t._typeDeclaration; + _hasDefaultValue = t._hasDefaultValue; + _defaultValue = t._defaultValue; + if( t._ptrOperators != Collections.EMPTY_LIST ) + _ptrOperators = (ArrayList)((ArrayList)t._ptrOperators).clone(); + else + _ptrOperators = Collections.EMPTY_LIST; + + if( t._operatorExpressions != Collections.EMPTY_LIST ) + _operatorExpressions = (ArrayList)((ArrayList)t._operatorExpressions).clone(); + else + _operatorExpressions = Collections.EMPTY_LIST; + } + + public void release() { + ParserSymbolTable.TypeInfoProvider.returnTypeInfo( this ); + } + + private int _typeBits = 0; private eType _type = TypeInfo.t_undef; private eType _templateParameterType = t_typeName;