1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Patch for Andrew Niefer

Core :
        - modified Symbol table interfaces to use List & Map instead of 
LinkedList and HashMap
        - fixed warnings in ParserSymbolTable
        - fixed bug43106 - Symbol Table support needed to resolve types
        - fixed bug43156 - require ability to add implicit inheritance 
copy constructor
        - fixed bug43159 - TypeInfo.equals() not working properly
        - fixed bug43238 - Postfix_Subscript expressions confuse function 
resolution

Tests:
        - removed testConditionalExpression_Bug43159 from 
FailedCompleteParseASTExpressionTest
          and uncommented it (testConditionalExpression) in 
CompleteParseASTExpressionTest
        - uncommented the following tests in 
CompleteParseASTExpressionTest :
            testPostfixSubscript, 
            testPostfixSubscriptA, 
            testPostfixSubscriptB,
            testPostfixSubscriptWithReferences
        - updated ParserSymbolTableTests to use new addOperatorExpression 
function
        - added testDerivedReference, testAddCopyConstructor to 
ParserSymbolTableTests
        - fixed warning in ClassDeclarationPatternTests
This commit is contained in:
John Camelon 2003-09-19 16:00:53 +00:00
parent 75031996e1
commit 8c79a22ec0
16 changed files with 572 additions and 336 deletions

View file

@ -1,3 +1,13 @@
2003-09-18 Andrew Niefer
- removed testConditionalExpression_Bug43159 from FailedCompleteParseASTExpressionTest
and uncommented it (testConditionalExpression) in CompleteParseASTExpressionTest
- uncommented the following tests in CompleteParseASTExpressionTest :
testPostfixSubscript, testPostfixSubscriptA, testPostfixSubscriptB,
testPostfixSubscriptWithReferences
- updated ParserSymbolTableTests to use new addOperatorExpression function
- added testDerivedReference, testAddCopyConstructor to ParserSymbolTableTests
- fixed warning in ClassDeclarationPatternTests
2003-09-17 Hoda Amer 2003-09-17 Hoda Amer
Added more success test cases to CompleteParseASTExpressionTest Added more success test cases to CompleteParseASTExpressionTest
and more failure test cases to FailedCompleteParseASTExpressionTest and more failure test cases to FailedCompleteParseASTExpressionTest

View file

@ -79,23 +79,23 @@ public class FailedCompleteParseASTExpressionTest extends CompleteParseBaseTest
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), pa ); // assertEquals( ((IASTReference)references.next()).getReferencedElement(), pa );
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), f1 ); // assertEquals( ((IASTReference)references.next()).getReferencedElement(), f1 );
// } // }
public void testConditionalExpression_Bug43159() throws Exception { // public void testConditionalExpression_Bug43159() throws Exception {
Iterator i = parse( "int foo(bool); int foo(int); int a = 10, b = 4, c = 2; int x = foo( a > 5 ? b : c );").getDeclarations(); // Iterator i = parse( "int foo(bool); int foo(int); int a = 10, b = 4, c = 2; int x = foo( a > 5 ? b : c );").getDeclarations();
IASTFunction foo1 = (IASTFunction)i.next(); // IASTFunction foo1 = (IASTFunction)i.next();
IASTFunction foo2 = (IASTFunction)i.next(); // IASTFunction foo2 = (IASTFunction)i.next();
IASTVariable a = (IASTVariable)i.next(); // IASTVariable a = (IASTVariable)i.next();
IASTVariable b = (IASTVariable)i.next(); // IASTVariable b = (IASTVariable)i.next();
IASTVariable c = (IASTVariable)i.next(); // IASTVariable c = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); // IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); // assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 3 ); // should be 4 // assertEquals( callback.getReferences().size(), 3 ); // should be 4
Iterator references =callback.getReferences().iterator(); // Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), a ); // assertEquals( ((IASTReference)references.next()).getReferencedElement(), a );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), b ); // assertEquals( ((IASTReference)references.next()).getReferencedElement(), b );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), c ); // assertEquals( ((IASTReference)references.next()).getReferencedElement(), c );
//assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); // //assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 );
assertFalse( references.hasNext() ); // assertFalse( references.hasNext() );
} // }
public void testConditionalExpressionWithReferencesB_Bug43106() throws Exception { public void testConditionalExpressionWithReferencesB_Bug43106() throws Exception {
Iterator i = parse( "class A{}; class B : public A{}; int foo(); int foo(A&); A a ; B b; int c = 0; int x = foo( c > 5 ? b : a );").getDeclarations(); Iterator i = parse( "class A{}; class B : public A{}; int foo(); int foo(A&); A a ; B b; int c = 0; int x = foo( c > 5 ? b : a );").getDeclarations();

View file

@ -170,59 +170,59 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
assertEquals( fr1.getReferencedElement(), f1 ); assertEquals( fr1.getReferencedElement(), f1 );
} }
// Kind POSTFIX_SUBSCRIPT // Kind POSTFIX_SUBSCRIPT
// public void testPostfixSubscript() throws Exception public void testPostfixSubscript() throws Exception
// { {
// Iterator i = parse ("int pa[10]; \n int f(int ia){} \n int f(void); \n int x = f(pa[1]);").getDeclarations(); Iterator i = parse ("int pa[10]; \n int f(int ia){} \n int f(void); \n int x = f(pa[1]);").getDeclarations();
// IASTVariable pa = (IASTVariable) i.next(); IASTVariable pa = (IASTVariable) i.next();
// IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
// IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
// IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
// Iterator references = callback.getReferences().iterator(); Iterator references = callback.getReferences().iterator();
// assertEquals( callback.getReferences().size(), 2 ); assertEquals( callback.getReferences().size(), 2 );
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), pa ); assertEquals( ((IASTReference)references.next()).getReferencedElement(), pa );
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), f1 ); assertEquals( ((IASTReference)references.next()).getReferencedElement(), f1 );
// } }
//
// public void testPostfixSubscriptA() throws Exception public void testPostfixSubscriptA() throws Exception
// { {
// Iterator i = parse ("int pa[10][5] ; \n int f(int ia){} \n int f(void); \n int x = f(pa[1][2]);").getDeclarations(); Iterator i = parse ("int pa[10][5] ; \n int f(int ia){} \n int f(void); \n int x = f(pa[1][2]);").getDeclarations();
// IASTVariable pa = (IASTVariable) i.next(); IASTVariable pa = (IASTVariable) i.next();
// IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
// IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
// IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
// Iterator references = callback.getReferences().iterator(); Iterator references = callback.getReferences().iterator();
// assertEquals( callback.getReferences().size(), 2 ); // should be = 2 assertEquals( callback.getReferences().size(), 2 ); // should be = 2
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), pa ); assertEquals( ((IASTReference)references.next()).getReferencedElement(), pa );
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), f1 ); assertEquals( ((IASTReference)references.next()).getReferencedElement(), f1 );
// } }
//
// public void testPostfixSubscriptB() throws Exception public void testPostfixSubscriptB() throws Exception
// { {
// Iterator i = parse ("int* pa[10][5] ; \n int f(int* ia){} \n int f(void); \n int x = f(pa[1][2]);").getDeclarations(); Iterator i = parse ("int* pa[10][5] ; \n int f(int* ia){} \n int f(void); \n int x = f(pa[1][2]);").getDeclarations();
// IASTVariable pa = (IASTVariable) i.next(); IASTVariable pa = (IASTVariable) i.next();
// IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
// IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
// IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
// Iterator references = callback.getReferences().iterator(); Iterator references = callback.getReferences().iterator();
// assertEquals( callback.getReferences().size(), 2 ); // should be = 2 assertEquals( callback.getReferences().size(), 2 ); // should be = 2
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), pa ); assertEquals( ((IASTReference)references.next()).getReferencedElement(), pa );
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), f1 ); assertEquals( ((IASTReference)references.next()).getReferencedElement(), f1 );
// } }
//
// public void testPostfixSubscriptWithReferences() throws Exception public void testPostfixSubscriptWithReferences() throws Exception
// { {
// Iterator i = parse ("class A{}; \n A *pa[10][5] ; \n int f(A* ia){} \n int f(void); \n int x = f(pa[1][2]);").getDeclarations(); Iterator i = parse ("class A{}; \n A *pa[10][5] ; \n int f(A* ia){} \n int f(void); \n int x = f(pa[1][2]);").getDeclarations();
// IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
// IASTVariable pa = (IASTVariable) i.next(); IASTVariable pa = (IASTVariable) i.next();
// IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
// IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
// IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
// Iterator references = callback.getReferences().iterator(); Iterator references = callback.getReferences().iterator();
// assertEquals( ((IASTClassReference) references.next()).getReferencedElement(), cl ); assertEquals( ((IASTClassReference) references.next()).getReferencedElement(), cl );
// assertEquals( ((IASTClassReference) references.next()).getReferencedElement(), cl ); assertEquals( ((IASTClassReference) references.next()).getReferencedElement(), cl );
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), pa ); assertEquals( ((IASTReference)references.next()).getReferencedElement(), pa );
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), f1 ); assertEquals( ((IASTReference)references.next()).getReferencedElement(), f1 );
// } }
// Kind POSTFIX_FUNCTIONCALL : return type of called function // Kind POSTFIX_FUNCTIONCALL : return type of called function
public void testPostfixFunctioncallBug42822() throws Exception public void testPostfixFunctioncallBug42822() throws Exception
@ -891,23 +891,23 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
assertFalse( references.hasNext() ); assertFalse( references.hasNext() );
} }
// Kind CONDITIONALEXPRESSION : conditional Expression Conversions // Kind CONDITIONALEXPRESSION : conditional Expression Conversions
// public void testConditionalExpression() throws Exception { public void testConditionalExpression() throws Exception {
// Iterator i = parse( "int foo(bool); int foo(int); int a = 10, b = 4, c = 2; int x = foo( a > 5 ? b : c );").getDeclarations(); Iterator i = parse( "int foo(bool); int foo(int); int a = 10, b = 4, c = 2; int x = foo( a > 5 ? b : c );").getDeclarations();
// IASTFunction foo1 = (IASTFunction)i.next(); IASTFunction foo1 = (IASTFunction)i.next();
// IASTFunction foo2 = (IASTFunction)i.next(); IASTFunction foo2 = (IASTFunction)i.next();
// IASTVariable a = (IASTVariable)i.next(); IASTVariable a = (IASTVariable)i.next();
// IASTVariable b = (IASTVariable)i.next(); IASTVariable b = (IASTVariable)i.next();
// IASTVariable c = (IASTVariable)i.next(); IASTVariable c = (IASTVariable)i.next();
// IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
// assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
// assertEquals( callback.getReferences().size(), 4 ); assertEquals( callback.getReferences().size(), 4 );
// Iterator references =callback.getReferences().iterator(); Iterator references =callback.getReferences().iterator();
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), a ); assertEquals( ((IASTReference)references.next()).getReferencedElement(), a );
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), b ); assertEquals( ((IASTReference)references.next()).getReferencedElement(), b );
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), c ); assertEquals( ((IASTReference)references.next()).getReferencedElement(), c );
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 );
// assertFalse( references.hasNext() ); assertFalse( references.hasNext() );
// } }
// Kind CONDITIONALEXPRESSION with references : conditional Expression Conversions // Kind CONDITIONALEXPRESSION with references : conditional Expression Conversions
public void testConditionalExpressionWithReferencesA() throws Exception { public void testConditionalExpressionWithReferencesA() throws Exception {
Iterator i = parse( "class A{}; class B : public A{}; int foo(); int foo(A*); A *a ; B *b; int c = 0; int x = foo( c > 5 ? b : a );").getDeclarations(); Iterator i = parse( "class A{}; class B : public A{}; int foo(); int foo(A*); A *a ; B *b; int c = 0; int x = foo( c > 5 ? b : a );").getDeclarations();

View file

@ -30,6 +30,7 @@ import org.eclipse.cdt.internal.core.parser.pst.StandardSymbolExtension;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo; import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.Mark; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.Mark;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.TemplateInstance; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.TemplateInstance;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.OperatorExpression;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp; import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp;
@ -1187,8 +1188,8 @@ public class ParserSymbolTableTest extends TestCase {
assertEquals( look.getType(), TypeInfo.t_type ); assertEquals( look.getType(), TypeInfo.t_type );
assertEquals( look.getTypeSymbol(), cls ); assertEquals( look.getTypeSymbol(), cls );
assertEquals( ((PtrOp)look.getPtrOperators().getFirst()).getType(), TypeInfo.PtrOp.t_pointer ); assertEquals( ((PtrOp)look.getPtrOperators().iterator().next()).getType(), TypeInfo.PtrOp.t_pointer );
assertTrue( ((PtrOp)look.getPtrOperators().getFirst()).isConst() ); assertTrue( ((PtrOp)look.getPtrOperators().iterator().next()).isConst() );
assertEquals( look.getContainingSymbol(), fn ); assertEquals( look.getContainingSymbol(), fn );
} }
@ -1364,7 +1365,9 @@ public class ParserSymbolTableTest extends TestCase {
LinkedList paramList = new LinkedList(); LinkedList paramList = new LinkedList();
look = compUnit.lookup( "a" ); look = compUnit.lookup( "a" );
assertEquals( look, a ); assertEquals( look, a );
TypeInfo param = new TypeInfo( look.getType(), 0, look, new PtrOp( PtrOp.t_reference ), false ); TypeInfo param = new TypeInfo( look.getType(), 0, look, null, false );
//new PtrOp( PtrOp.t_reference )
param.addOperatorExpression( OperatorExpression.addressof );
paramList.add( param ); paramList.add( param );
look = compUnit.unqualifiedFunctionLookup( "f", paramList ); look = compUnit.unqualifiedFunctionLookup( "f", paramList );
@ -1640,21 +1643,21 @@ public class ParserSymbolTableTest extends TestCase {
ISymbol look = compUnit.unqualifiedFunctionLookup( "f", paramList ); ISymbol look = compUnit.unqualifiedFunctionLookup( "f", paramList );
assertEquals( look, f2 ); assertEquals( look, f2 );
p.addPtrOperator( new PtrOp( PtrOp.t_reference, false, false ) ); p.addOperatorExpression( OperatorExpression.addressof );
look = compUnit.unqualifiedFunctionLookup( "f", paramList ); look = compUnit.unqualifiedFunctionLookup( "f", paramList );
assertEquals( look, f1 ); assertEquals( look, f1 );
p.setTypeSymbol( b ); p.setTypeSymbol( b );
p.getPtrOperators().clear(); p.getOperatorExpressions().clear();
look = compUnit.unqualifiedFunctionLookup( "f", paramList ); look = compUnit.unqualifiedFunctionLookup( "f", paramList );
assertEquals( look, f1 ); assertEquals( look, f1 );
p.addPtrOperator( new PtrOp( PtrOp.t_pointer, false, false ) ); p.addOperatorExpression( OperatorExpression.indirection );
look = compUnit.unqualifiedFunctionLookup( "f", paramList ); look = compUnit.unqualifiedFunctionLookup( "f", paramList );
assertEquals( look, f2 ); assertEquals( look, f2 );
p.setTypeSymbol( array ); p.setTypeSymbol( array );
p.getPtrOperators().clear(); p.getOperatorExpressions().clear();
look = compUnit.unqualifiedFunctionLookup( "f", paramList ); look = compUnit.unqualifiedFunctionLookup( "f", paramList );
assertEquals( look, f1 ); assertEquals( look, f1 );
@ -1765,7 +1768,8 @@ public class ParserSymbolTableTest extends TestCase {
compUnit.addSymbol( main ); compUnit.addSymbol( main );
LinkedList params = new LinkedList(); LinkedList params = new LinkedList();
TypeInfo p1 = new TypeInfo( TypeInfo.t_type, 0, i, new PtrOp( PtrOp.t_reference ), false ); TypeInfo p1 = new TypeInfo( TypeInfo.t_type, 0, i );
p1.addOperatorExpression( OperatorExpression.addressof );
TypeInfo p2 = new TypeInfo( TypeInfo.t_type, 0, s ); TypeInfo p2 = new TypeInfo( TypeInfo.t_type, 0, s );
params.add( p1 ); params.add( p1 );
params.add( p2 ); params.add( p2 );
@ -1794,7 +1798,8 @@ public class ParserSymbolTableTest extends TestCase {
assertEquals( look, f2 ); assertEquals( look, f2 );
params.clear(); params.clear();
((PtrOp)p1.getPtrOperators().getFirst()).setConst( true ); p1.addPtrOperator( new PtrOp( PtrOp.t_undef, true, false ) );
//((PtrOp)p1.getPtrOperators().iterator().next()).setConst( true );
params.add( p1 ); params.add( p1 );
params.add( p3 ); params.add( p3 );
look = main.unqualifiedFunctionLookup( "f", params ); look = main.unqualifiedFunctionLookup( "f", params );
@ -2660,8 +2665,10 @@ public class ParserSymbolTableTest extends TestCase {
table.getCompilationUnit().addSymbol( a ); table.getCompilationUnit().addSymbol( a );
table.getCompilationUnit().addSymbol( b ); table.getCompilationUnit().addSymbol( b );
TypeInfo secondOp = new TypeInfo( TypeInfo.t_type, 0, a, new PtrOp( PtrOp.t_reference ), false ); TypeInfo secondOp = new TypeInfo( TypeInfo.t_type, 0, a );
TypeInfo thirdOp = new TypeInfo( TypeInfo.t_type, 0, b, new PtrOp( PtrOp.t_reference ), false ); secondOp.addOperatorExpression( OperatorExpression.addressof );
TypeInfo thirdOp = new TypeInfo( TypeInfo.t_type, 0, b );
thirdOp.addOperatorExpression( OperatorExpression.addressof );
TypeInfo returned = ParserSymbolTable.getConditionalOperand( secondOp, thirdOp ); TypeInfo returned = ParserSymbolTable.getConditionalOperand( secondOp, thirdOp );
assertEquals( returned, secondOp ); assertEquals( returned, secondOp );
@ -2672,7 +2679,8 @@ public class ParserSymbolTableTest extends TestCase {
c.setTypeSymbol( clsC ); c.setTypeSymbol( clsC );
table.getCompilationUnit().addSymbol( c ); table.getCompilationUnit().addSymbol( c );
TypeInfo anotherOp = new TypeInfo( TypeInfo.t_type, 0, c, new PtrOp( PtrOp.t_reference ), false ); TypeInfo anotherOp = new TypeInfo( TypeInfo.t_type, 0, c );
anotherOp.addOperatorExpression( OperatorExpression.addressof );
returned = ParserSymbolTable.getConditionalOperand( secondOp, anotherOp ); returned = ParserSymbolTable.getConditionalOperand( secondOp, anotherOp );
assertEquals( returned, null ); assertEquals( returned, null );
@ -2685,8 +2693,8 @@ public class ParserSymbolTableTest extends TestCase {
constructorC.addParameter( clsA, null, false ); constructorC.addParameter( clsA, null, false );
clsC.addConstructor( constructorC ); clsC.addConstructor( constructorC );
secondOp.getPtrOperators().clear(); secondOp.getOperatorExpressions().clear();
anotherOp.getPtrOperators().clear(); anotherOp.getOperatorExpressions().clear();
try{ try{
returned = ParserSymbolTable.getConditionalOperand( secondOp, anotherOp ); returned = ParserSymbolTable.getConditionalOperand( secondOp, anotherOp );
@ -2696,5 +2704,123 @@ public class ParserSymbolTableTest extends TestCase {
} }
} }
/**
*
* @throws Exception
* class A {};
* class B : public A {} b;
* class C : private A {} c;
* int f ( A & );
*
* int i = f ( b ); //calls f( A & );
*
* int f ( B & );
* i = f( b ); //now calls f( B& );
*
* i = f( c ); //exception, A is not an accessible base class
*/
public void testDerivedReference() throws Exception{
newTable();
IDerivableContainerSymbol clsA = table.newDerivableContainerSymbol( "A", TypeInfo.t_class );
IDerivableContainerSymbol clsB = table.newDerivableContainerSymbol( "B", TypeInfo.t_class );
IDerivableContainerSymbol clsC = table.newDerivableContainerSymbol( "C", TypeInfo.t_class );
clsB.addParent( clsA );
clsC.addParent( clsA, false, ASTAccessVisibility.PRIVATE, 0, null );
ISymbol b = table.newSymbol("b", TypeInfo.t_type );
b.setTypeSymbol( clsB );
ISymbol c = table.newSymbol("c", TypeInfo.t_type );
c.setTypeSymbol( clsC );
table.getCompilationUnit().addSymbol( clsA );
table.getCompilationUnit().addSymbol( clsB );
table.getCompilationUnit().addSymbol( clsC );
table.getCompilationUnit().addSymbol( b );
table.getCompilationUnit().addSymbol( c );
IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
f1.addParameter( clsA, new PtrOp( PtrOp.t_reference ), false );
table.getCompilationUnit().addSymbol( f1 );
LinkedList parameters = new LinkedList();
TypeInfo param = new TypeInfo( TypeInfo.t_type, 0, b );
parameters.add( param );
ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", parameters );
assertEquals( look, f1 );
IParameterizedSymbol f2 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
f2.addParameter( clsB, new PtrOp( PtrOp.t_reference ), false );
table.getCompilationUnit().addSymbol( f2 );
look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", parameters );
assertEquals( look, f2 );
parameters.clear();
param = new TypeInfo( TypeInfo.t_type, 0, c );
parameters.add( param );
try{
look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", parameters );
assertTrue( false );
} catch ( ParserSymbolTableException e ){
//good
}
}
/**
*
* @throws Exception
*
* class A {
* private :
* A ( const A & ) {}
* } a;
*
* class B : public A {
* } b;
*
* 1 > 2 ? a : b; //fails, b can't be converted to a without the A( const A & ) copy constructor
* -----------------------
* class A {
* A ( const A & ) {}
* } a;
* class B : public A {} b;
*
* 1 > 2 ? a : b; //succeeds, b can be converted to a using copy constructor
*
*/
public void testAddCopyConstructor() throws Exception {
newTable();
IDerivableContainerSymbol clsA = table.newDerivableContainerSymbol( "A", TypeInfo.t_class );
table.getCompilationUnit().addSymbol( clsA );
ISymbol a = table.newSymbol( "a", TypeInfo.t_type );
a.setTypeSymbol( clsA );
table.getCompilationUnit().addSymbol( a );
IDerivableContainerSymbol clsB = table.newDerivableContainerSymbol( "B", TypeInfo.t_class );
clsB.addParent( clsA );
table.getCompilationUnit().addSymbol( clsB );
ISymbol b = table.newSymbol( "b", TypeInfo.t_type );
b.setTypeSymbol( clsB );
table.getCompilationUnit().addSymbol( b );
TypeInfo secondOp = new TypeInfo( TypeInfo.t_type, 0, a, null, false );
TypeInfo thirdOp = new TypeInfo( TypeInfo.t_type, 0, b, null, false );
TypeInfo returned = ParserSymbolTable.getConditionalOperand( secondOp, thirdOp );
assertEquals( returned, null );
clsA.addCopyConstructor();
clsB.addCopyConstructor();
returned = ParserSymbolTable.getConditionalOperand( secondOp, thirdOp );
assertEquals( returned, secondOp );
}
} }

View file

@ -80,7 +80,7 @@ public class BaseSearchTest extends TestCase implements ICSearchConstants {
fileManager = new FileManager(); fileManager = new FileManager();
//Add a file to the project //Add a file to the project
importFile("mail.cpp", "resources/indexer/mail.cpp"); //importFile("mail.cpp", "resources/indexer/mail.cpp");
importFile("classDecl.cpp", "resources/search/classDecl.cpp"); importFile("classDecl.cpp", "resources/search/classDecl.cpp");
importFile("include.h", "resources/search/include.h"); importFile("include.h", "resources/search/include.h");

View file

@ -22,7 +22,6 @@ import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.core.search.SearchEngine; import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.core.CharOperation; import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.search.matching.ClassDeclarationPattern; import org.eclipse.cdt.internal.core.search.matching.ClassDeclarationPattern;
import org.eclipse.cdt.internal.core.search.matching.MatchLocator;
import org.eclipse.cdt.internal.core.search.matching.OrPattern; import org.eclipse.cdt.internal.core.search.matching.OrPattern;
@ -34,10 +33,6 @@ import org.eclipse.cdt.internal.core.search.matching.OrPattern;
*/ */
public class ClassDeclarationPatternTests extends BaseSearchTest implements ICSearchConstants { public class ClassDeclarationPatternTests extends BaseSearchTest implements ICSearchConstants {
private MatchLocator matchLocator;
private String cppPath;
public ClassDeclarationPatternTests(String name) { public ClassDeclarationPatternTests(String name) {
super(name); super(name);
} }

View file

@ -138,6 +138,6 @@ public class FunctionMethodPatternTests extends BaseSearchTest {
pattern = SearchEngine.createSearchPattern( "operator *", METHOD, DECLARATIONS, true ); pattern = SearchEngine.createSearchPattern( "operator *", METHOD, DECLARATIONS, true );
search( workspace, pattern, scope, resultCollector ); search( workspace, pattern, scope, resultCollector );
matches = resultCollector.getSearchResults(); matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 5 ); //3 in classDecl.cpp, 2 in mail.cpp assertEquals( matches.size(), 3 ); //3 in classDecl.cpp
} }
} }

View file

@ -1,3 +1,11 @@
2003-09-18 Andrew Niefer
- modified Symbol table interfaces to use Lists & Maps instead of LinkedList and HashMap
- fixed warnings in ParserSymbolTable
- fixed bug43106 - Symbol Table support needed to resolve types
- fixed bug43156 - require ability to add implicit inheritance copy constructor
- fixed bug43159 - TypeInfo.equals() not working properly
- fixed bug43238 - Postfix_Subscript expressions confuse function resolution
2003-09-16 Andrew Niefer 2003-09-16 Andrew Niefer
- added setThrowExceptionOnBadCharacterRead to IScanner to help with wildcard bug43063 - added setThrowExceptionOnBadCharacterRead to IScanner to help with wildcard bug43063

View file

@ -1058,7 +1058,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
if( lhsResult.iterator().hasNext()) if( lhsResult.iterator().hasNext())
info = (TypeInfo)lhsResult.iterator().next(); info = (TypeInfo)lhsResult.iterator().next();
if ((info != null) && (info.getTypeSymbol() != null)){ if ((info != null) && (info.getTypeSymbol() != null)){
info.addPtrOperator(new TypeInfo.PtrOp(TypeInfo.PtrOp.t_reference)); info.addOperatorExpression( TypeInfo.OperatorExpression.addressof );
} }
result.add(info); result.add(info);
return result; return result;
@ -1069,22 +1069,22 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
if( lhsResult.iterator().hasNext()) if( lhsResult.iterator().hasNext())
info = (TypeInfo)lhsResult.iterator().next(); info = (TypeInfo)lhsResult.iterator().next();
if ((info != null)&& (info.getTypeSymbol() != null)){ if ((info != null)&& (info.getTypeSymbol() != null)){
info.addPtrOperator(new TypeInfo.PtrOp(TypeInfo.PtrOp.t_pointer)); info.addOperatorExpression( TypeInfo.OperatorExpression.indirection );
} }
result.add(info); result.add(info);
return result; return result;
} }
// subscript // subscript
// if (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_SUBSCRIPT){ if (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_SUBSCRIPT){
// List lhsResult = ((ASTExpression)expression.getLHSExpression()).getResultType(); List lhsResult = ((ASTExpression)expression.getLHSExpression()).getResultType();
// if( lhsResult.iterator().hasNext()) if( lhsResult.iterator().hasNext())
// info = (TypeInfo)lhsResult.iterator().next(); info = (TypeInfo)lhsResult.iterator().next();
// if ((info != null) && (info.getTypeSymbol() != null)){ if ((info != null) && (info.getTypeSymbol() != null)){
// info.addPtrOperator(new TypeInfo.PtrOp(TypeInfo.PtrOp.t_pointer)); info.addOperatorExpression( TypeInfo.OperatorExpression.subscript );
// } }
// result.add(info); result.add(info);
// return result; return result;
// } }
// the dot and the arrow resolves to the type of the member // the dot and the arrow resolves to the type of the member
if ((expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION) if ((expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION)
|| (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION) || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION)
@ -1105,7 +1105,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
if( rhsResult.iterator().hasNext()) if( rhsResult.iterator().hasNext())
info = (TypeInfo)rhsResult.iterator().next(); info = (TypeInfo)rhsResult.iterator().next();
if (info != null){ if (info != null){
info.addPtrOperator(new TypeInfo.PtrOp(TypeInfo.PtrOp.t_pointer)); info.addOperatorExpression( TypeInfo.OperatorExpression.indirection );
} }
if(symbol != null){ if(symbol != null){
info.setTypeSymbol(symbol); info.setTypeSymbol(symbol);
@ -1119,7 +1119,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
{ {
info.setType(TypeInfo.t_type); info.setType(TypeInfo.t_type);
info.setTypeSymbol(symbol); info.setTypeSymbol(symbol);
info.addPtrOperator(new TypeInfo.PtrOp(TypeInfo.PtrOp.t_reference)); info.addOperatorExpression( TypeInfo.OperatorExpression.addressof );
result.add(info); result.add(info);
return result; return result;
} }

View file

@ -16,7 +16,6 @@
*/ */
package org.eclipse.cdt.internal.core.parser.pst; package org.eclipse.cdt.internal.core.parser.pst;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -47,9 +46,9 @@ public interface IContainerSymbol extends ISymbol {
public IContainerSymbol lookupNestedNameSpecifier( String name ) throws ParserSymbolTableException; public IContainerSymbol lookupNestedNameSpecifier( String name ) throws ParserSymbolTableException;
public ISymbol qualifiedLookup( String name ) throws ParserSymbolTableException; public ISymbol qualifiedLookup( String name ) throws ParserSymbolTableException;
public ISymbol qualifiedLookup( String name, TypeInfo.eType t ) throws ParserSymbolTableException; public ISymbol qualifiedLookup( String name, TypeInfo.eType t ) throws ParserSymbolTableException;
public IParameterizedSymbol unqualifiedFunctionLookup( String name, LinkedList parameters ) throws ParserSymbolTableException; public IParameterizedSymbol unqualifiedFunctionLookup( String name, List parameters ) throws ParserSymbolTableException;
public IParameterizedSymbol memberFunctionLookup( String name, LinkedList parameters ) throws ParserSymbolTableException; public IParameterizedSymbol memberFunctionLookup( String name, List parameters ) throws ParserSymbolTableException;
public IParameterizedSymbol qualifiedFunctionLookup( String name, LinkedList parameters ) throws ParserSymbolTableException; public IParameterizedSymbol qualifiedFunctionLookup( String name, List parameters ) throws ParserSymbolTableException;
public TemplateInstance templateLookup( String name, LinkedList arguments ) throws ParserSymbolTableException; public TemplateInstance templateLookup( String name, List arguments ) throws ParserSymbolTableException;
public TemplateInstance instantiate( LinkedList arguments ) throws ParserSymbolTableException; public TemplateInstance instantiate( List arguments ) throws ParserSymbolTableException;
} }

View file

@ -16,7 +16,6 @@
*/ */
package org.eclipse.cdt.internal.core.parser.pst; package org.eclipse.cdt.internal.core.parser.pst;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
@ -35,13 +34,15 @@ public interface IDerivableContainerSymbol extends IContainerSymbol {
public boolean hasParents(); public boolean hasParents();
public void addConstructor( IParameterizedSymbol constructor ) throws ParserSymbolTableException; public void addConstructor( IParameterizedSymbol constructor ) throws ParserSymbolTableException;
public IParameterizedSymbol lookupConstructor( LinkedList parameters ) throws ParserSymbolTableException; public void addCopyConstructor() throws ParserSymbolTableException;
public LinkedList getConstructors(); public IParameterizedSymbol lookupConstructor( List parameters ) throws ParserSymbolTableException;
public List getConstructors();
public interface IParentSymbol{ public interface IParentSymbol{
public void setParent( ISymbol parent ); public void setParent( ISymbol parent );
public ISymbol getParent(); public ISymbol getParent();
public boolean isVirtual(); public boolean isVirtual();
public void setVirtual( boolean virtual ); public void setVirtual( boolean virtual );
public ASTAccessVisibility getVisibility();
} }
} }

View file

@ -16,8 +16,8 @@
*/ */
package org.eclipse.cdt.internal.core.parser.pst; package org.eclipse.cdt.internal.core.parser.pst;
import java.util.HashMap; import java.util.List;
import java.util.LinkedList; import java.util.Map;
/** /**
@ -33,12 +33,12 @@ public interface IParameterizedSymbol extends IContainerSymbol {
public void addParameter( ISymbol typeSymbol, TypeInfo.PtrOp ptrOp, boolean hasDefault ); public void addParameter( ISymbol typeSymbol, TypeInfo.PtrOp ptrOp, boolean hasDefault );
public void addArgument( ISymbol arg ); public void addArgument( ISymbol arg );
public LinkedList getArgumentList(); public List getArgumentList();
public void setArgumentList( LinkedList list ); public void setArgumentList( List list );
public HashMap getParameterMap(); public Map getParameterMap();
public LinkedList getParameterList(); public List getParameterList();
public void setParameterList( LinkedList list ); public void setParameterList( List list );
public boolean hasSameParameters(IParameterizedSymbol newDecl); public boolean hasSameParameters(IParameterizedSymbol newDecl);
@ -47,5 +47,5 @@ public interface IParameterizedSymbol extends IContainerSymbol {
public boolean hasSpecializations(); public boolean hasSpecializations();
public void addSpecialization( IParameterizedSymbol spec ); public void addSpecialization( IParameterizedSymbol spec );
public LinkedList getSpecializations(); public List getSpecializations();
} }

View file

@ -10,8 +10,8 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.core.parser.pst; package org.eclipse.cdt.internal.core.parser.pst;
import java.util.HashMap; import java.util.Map;
import java.util.LinkedList; import java.util.List;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.TemplateInstance; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.TemplateInstance;
/** /**
@ -45,40 +45,15 @@ public interface ISymbol extends Cloneable {
public void setIsForwardDeclaration( boolean forward ); public void setIsForwardDeclaration( boolean forward );
public int compareCVQualifiersTo( ISymbol symbol ); public int compareCVQualifiersTo( ISymbol symbol );
public LinkedList getPtrOperators(); public List getPtrOperators();
public void addPtrOperator( TypeInfo.PtrOp ptrOp ); public void addPtrOperator( TypeInfo.PtrOp ptrOp );
public boolean isTemplateMember(); public boolean isTemplateMember();
public void setIsTemplateMember( boolean isMember ); public void setIsTemplateMember( boolean isMember );
public ISymbol getTemplateInstance(); public ISymbol getTemplateInstance();
public HashMap getArgumentMap(); public Map getArgumentMap();
public void setTemplateInstance( TemplateInstance instance ); public void setTemplateInstance( TemplateInstance instance );
/*public interface ITypeInfo {
public boolean checkBit(int mask);
public void setBit(boolean b, int mask);
public boolean isType( int type );
public boolean isType( int type, int upperType );
public int getType();
public ISymbol getTypeSymbol();
public int getCVQualifier();
public void addCVQualifier( int cvQual );
public String getPtrOperator();
public void addPtrOperator( String ptrOp );
public void setType(int i);
public void setTypeSymbol(ISymbol typeSymbol);
public int getTypeInfo();
public void setTypeInfo( int typeInfo );
public void setPtrOperator(String string);
public boolean canHold(ITypeInfo src);
public String getInvertedPtrOperator();
public void setCVQualifier(int i);
public boolean getHasDefault();
public void setHasDefault(boolean hasDefault);
}
*/
public int getDepth(); public int getDepth();
/** /**

View file

@ -24,6 +24,7 @@ import java.util.Set;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp;
/** /**
* @author aniefer * @author aniefer
@ -31,12 +32,15 @@ import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
public class ParserSymbolTable { public class ParserSymbolTable {
public static final String EMPTY_NAME = ""; //$NON-NLS-1$
public static final String THIS = "this"; //$NON-NLS-1$
/** /**
* Constructor for ParserSymbolTable. * Constructor for ParserSymbolTable.
*/ */
public ParserSymbolTable( ParserLanguage language ) { public ParserSymbolTable( ParserLanguage language ) {
super(); super();
_compilationUnit = new Declaration(""); _compilationUnit = new Declaration(EMPTY_NAME);
_compilationUnit.setType( TypeInfo.t_namespace ); _compilationUnit.setType( TypeInfo.t_namespace );
_language = language; _language = language;
} }
@ -346,7 +350,7 @@ public class ParserSymbolTable {
} }
List scopes = container.getParents(); List scopes = container.getParents();
boolean foundSomething = false;
ISymbol temp = null; ISymbol temp = null;
ISymbol symbol = null; ISymbol symbol = null;
@ -472,9 +476,9 @@ public class ParserSymbolTable {
return false; return false;
} }
protected static boolean isValidOverload( LinkedList origList, ISymbol newSymbol ){ protected static boolean isValidOverload( List origList, ISymbol newSymbol ){
if( origList.size() == 1 ){ if( origList.size() == 1 ){
return isValidOverload( (ISymbol)origList.getFirst(), newSymbol ); return isValidOverload( (ISymbol)origList.iterator().next(), newSymbol );
} else if ( origList.size() > 1 ){ } else if ( origList.size() > 1 ){
//the first thing can be a class-name or enumeration name, but the rest //the first thing can be a class-name or enumeration name, but the rest
@ -667,7 +671,7 @@ public class ParserSymbolTable {
} }
} }
static protected IParameterizedSymbol resolveFunction( LookupData data, LinkedList functions ) throws ParserSymbolTableException{ static protected IParameterizedSymbol resolveFunction( LookupData data, List functions ) throws ParserSymbolTableException{
if( functions == null ){ if( functions == null ){
return null; return null;
} }
@ -683,7 +687,7 @@ public class ParserSymbolTable {
if( numFns == 0 ){ if( numFns == 0 ){
return null; return null;
} else if ( numFns == 1 ){ } else if ( numFns == 1 ){
return (IParameterizedSymbol)functions.getFirst(); return (IParameterizedSymbol)functions.iterator().next();
} else{ } else{
throw new ParserSymbolTableException( ParserSymbolTableException.r_Ambiguous ); throw new ParserSymbolTableException( ParserSymbolTableException.r_Ambiguous );
} }
@ -805,7 +809,7 @@ public class ParserSymbolTable {
return bestFn; return bestFn;
} }
static private void reduceToViable( LookupData data, LinkedList functions ){ static private void reduceToViable( LookupData data, List functions ){
int numParameters = ( data.parameters == null ) ? 0 : data.parameters.size(); int numParameters = ( data.parameters == null ) ? 0 : data.parameters.size();
int num; int num;
@ -930,7 +934,11 @@ public class ParserSymbolTable {
* *
* TBD: Consider rewriting iteratively for performance. * TBD: Consider rewriting iteratively for performance.
*/ */
static private int hasBaseClass( ISymbol obj, ISymbol base ){ static private int hasBaseClass( ISymbol obj, ISymbol base ) throws ParserSymbolTableException {
return hasBaseClass( obj, base, false );
}
static private int hasBaseClass( ISymbol obj, ISymbol base, boolean throwIfNotVisible ) throws ParserSymbolTableException{
if( obj == base ){ if( obj == base ){
return 0; return 0;
} }
@ -961,14 +969,17 @@ public class ParserSymbolTable {
for( int i = size; i > 0; i-- ){ for( int i = size; i > 0; i-- ){
wrapper = (IDerivableContainerSymbol.IParentSymbol) iter.next(); wrapper = (IDerivableContainerSymbol.IParentSymbol) iter.next();
temp = wrapper.getParent(); temp = wrapper.getParent();
boolean isVisible = ( wrapper.getVisibility() == ASTAccessVisibility.PUBLIC );
if( temp instanceof TemplateInstance ){ if( temp instanceof TemplateInstance ){
instance = (TemplateInstance) temp; instance = (TemplateInstance) temp;
if( instance.getInstantiatedSymbol() instanceof IDerivableContainerSymbol ){ if( instance.getInstantiatedSymbol() instanceof IDerivableContainerSymbol ){
if( instance.getInstantiatedSymbol() == base ){ if( instance.getInstantiatedSymbol() == base ){
return 1; if( throwIfNotVisible && !isVisible )
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadVisibility );
else
return 1;
} else { } else {
int n = hasBaseClass( instance, base ); int n = hasBaseClass( instance, base, throwIfNotVisible );
if( n > 0 ){ if( n > 0 ){
return n + 1; return n + 1;
} }
@ -989,9 +1000,12 @@ public class ParserSymbolTable {
continue; continue;
} }
if( parent == base ){ if( parent == base ){
return 1; if( throwIfNotVisible && !isVisible )
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadVisibility );
else
return 1;
} else { } else {
int n = hasBaseClass( parent, base ); int n = hasBaseClass( parent, base, throwIfNotVisible );
if( n > 0 ){ if( n > 0 ){
return n + 1; return n + 1;
} }
@ -1057,23 +1071,28 @@ public class ParserSymbolTable {
//7.3.3-4 //7.3.3-4
else if( context.isType( TypeInfo.t_class, TypeInfo.t_struct ) ){ else if( context.isType( TypeInfo.t_class, TypeInfo.t_struct ) ){
IContainerSymbol container = obj.getContainingSymbol(); IContainerSymbol container = obj.getContainingSymbol();
//a member of a base class
if( obj.getContainingSymbol().getType() == context.getType() ){ try{
okToAdd = ( hasBaseClass( (IDerivableContainerSymbol) context, (IDerivableContainerSymbol) container ) > 0 ); //a member of a base class
} if( obj.getContainingSymbol().getType() == context.getType() ){
else if ( obj.getContainingSymbol().getType() == TypeInfo.t_union ) { okToAdd = ( hasBaseClass( (IDerivableContainerSymbol) context, (IDerivableContainerSymbol) container ) > 0 );
// TODO : must be an _anonymous_ union }
container = container.getContainingSymbol(); else if ( obj.getContainingSymbol().getType() == TypeInfo.t_union ) {
okToAdd = ( container instanceof IDerivableContainerSymbol ) // TODO : must be an _anonymous_ union
? ( hasBaseClass( (IDerivableContainerSymbol)context, (IDerivableContainerSymbol) container ) > 0 ) container = container.getContainingSymbol();
: false; okToAdd = ( container instanceof IDerivableContainerSymbol )
} ? ( hasBaseClass( (IDerivableContainerSymbol)context, (IDerivableContainerSymbol) container ) > 0 )
//an enumerator for an enumeration : false;
else if ( obj.getType() == TypeInfo.t_enumerator ){ }
container = container.getContainingSymbol(); //an enumerator for an enumeration
okToAdd = ( container instanceof IDerivableContainerSymbol ) else if ( obj.getType() == TypeInfo.t_enumerator ){
? ( hasBaseClass( (IDerivableContainerSymbol)context, (IDerivableContainerSymbol) container ) > 0 ) container = container.getContainingSymbol();
: false; okToAdd = ( container instanceof IDerivableContainerSymbol )
? ( hasBaseClass( (IDerivableContainerSymbol)context, (IDerivableContainerSymbol) container ) > 0 )
: false;
}
} catch ( ParserSymbolTableException e ) {
//not going to happen since we didn't ask for the visibility exception from hasBaseClass
} }
} else { } else {
okToAdd = true; okToAdd = true;
@ -1109,11 +1128,11 @@ public class ParserSymbolTable {
TypeInfo.PtrOp op = null; TypeInfo.PtrOp op = null;
if( cost.source.hasPtrOperators() ){ if( cost.source.hasPtrOperators() ){
LinkedList sourcePtrs = cost.source.getPtrOperators(); List sourcePtrs = cost.source.getPtrOperators();
TypeInfo.PtrOp ptr = (TypeInfo.PtrOp)sourcePtrs.getFirst(); Iterator iterator = sourcePtrs.iterator();
TypeInfo.PtrOp ptr = (TypeInfo.PtrOp)iterator.next();
if( ptr.getType() == TypeInfo.PtrOp.t_reference ){ if( ptr.getType() == TypeInfo.PtrOp.t_reference ){
sourcePtrs.removeFirst(); iterator.remove();
} }
int size = sourcePtrs.size(); int size = sourcePtrs.size();
Iterator iter = sourcePtrs.iterator(); Iterator iter = sourcePtrs.iterator();
@ -1127,11 +1146,13 @@ public class ParserSymbolTable {
} }
if( cost.target.hasPtrOperators() ){ if( cost.target.hasPtrOperators() ){
LinkedList targetPtrs = cost.target.getPtrOperators(); List targetPtrs = cost.target.getPtrOperators();
TypeInfo.PtrOp ptr = (TypeInfo.PtrOp)targetPtrs.getFirst(); Iterator iterator = targetPtrs.iterator();
TypeInfo.PtrOp ptr = (TypeInfo.PtrOp)iterator.next();
if( ptr.getType() == TypeInfo.PtrOp.t_reference ){ if( ptr.getType() == TypeInfo.PtrOp.t_reference ){
targetPtrs.removeFirst(); iterator.remove();
cost.targetHadReference = true;
} }
int size = targetPtrs.size(); int size = targetPtrs.size();
Iterator iter = targetPtrs.iterator(); Iterator iter = targetPtrs.iterator();
@ -1271,7 +1292,7 @@ public class ParserSymbolTable {
TypeInfo src = cost.source; TypeInfo src = cost.source;
TypeInfo trg = cost.target; TypeInfo trg = cost.target;
int temp; int temp = -1;
cost.conversion = 0; cost.conversion = 0;
cost.detail = 0; cost.detail = 0;
@ -1280,7 +1301,7 @@ public class ParserSymbolTable {
return; return;
} }
if( src.hasPtrOperators() && src.getPtrOperators().size() == 1 ){ if( src.hasPtrOperators() && src.getPtrOperators().size() == 1 ){
TypeInfo.PtrOp ptr = (TypeInfo.PtrOp)src.getPtrOperators().getFirst(); TypeInfo.PtrOp ptr = (TypeInfo.PtrOp)src.getPtrOperators().iterator().next();
ISymbol srcDecl = src.isType( TypeInfo.t_type ) ? src.getTypeSymbol() : null; ISymbol srcDecl = src.isType( TypeInfo.t_type ) ? src.getTypeSymbol() : null;
ISymbol trgDecl = trg.isType( TypeInfo.t_type ) ? trg.getTypeSymbol() : null; ISymbol trgDecl = trg.isType( TypeInfo.t_type ) ? trg.getTypeSymbol() : null;
if( ptr.getType() == TypeInfo.PtrOp.t_pointer ){ if( ptr.getType() == TypeInfo.PtrOp.t_pointer ){
@ -1302,7 +1323,11 @@ public class ParserSymbolTable {
//4.10-3 An rvalue of type "pointer to cv D", where D is a class type can be converted //4.10-3 An rvalue of type "pointer to cv D", where D is a class type can be converted
// to an rvalue of type "pointer to cv B", where B is a base class of D. // to an rvalue of type "pointer to cv B", where B is a base class of D.
if( (srcDecl instanceof IDerivableContainerSymbol) && trgDecl.isType( srcDecl.getType() ) ){ if( (srcDecl instanceof IDerivableContainerSymbol) && trgDecl.isType( srcDecl.getType() ) ){
temp = hasBaseClass( (IDerivableContainerSymbol) srcDecl, (IDerivableContainerSymbol) trgDecl ); try {
temp = hasBaseClass( (IDerivableContainerSymbol) srcDecl, (IDerivableContainerSymbol) trgDecl );
} catch (ParserSymbolTableException e) {
//not going to happen since we didn't ask for the visibility exception
}
cost.rank = ( temp > -1 ) ? Cost.CONVERSION_RANK : Cost.NO_MATCH_RANK; cost.rank = ( temp > -1 ) ? Cost.CONVERSION_RANK : Cost.NO_MATCH_RANK;
cost.conversion = ( temp > -1 ) ? temp : 0; cost.conversion = ( temp > -1 ) ? temp : 0;
cost.detail = 1; cost.detail = 1;
@ -1316,9 +1341,13 @@ public class ParserSymbolTable {
return; return;
} }
TypeInfo.PtrOp srcPtr = trg.hasPtrOperators() ? (TypeInfo.PtrOp)trg.getPtrOperators().getFirst() : null; TypeInfo.PtrOp srcPtr = trg.hasPtrOperators() ? (TypeInfo.PtrOp)trg.getPtrOperators().iterator().next() : null;
if( trgDecl.isType( srcDecl.getType() ) && srcPtr != null && srcPtr.getType() == TypeInfo.PtrOp.t_memberPointer ){ if( trgDecl.isType( srcDecl.getType() ) && srcPtr != null && srcPtr.getType() == TypeInfo.PtrOp.t_memberPointer ){
temp = hasBaseClass( (IDerivableContainerSymbol)ptr.getMemberOf(), (IDerivableContainerSymbol)srcPtr.getMemberOf() ); try {
temp = hasBaseClass( (IDerivableContainerSymbol)ptr.getMemberOf(), (IDerivableContainerSymbol)srcPtr.getMemberOf() );
} catch (ParserSymbolTableException e) {
//not going to happen since we didn't ask for the visibility exception
}
cost.rank = ( temp > -1 ) ? Cost.CONVERSION_RANK : Cost.NO_MATCH_RANK; cost.rank = ( temp > -1 ) ? Cost.CONVERSION_RANK : Cost.NO_MATCH_RANK;
cost.detail = 1; cost.detail = 1;
cost.conversion = ( temp > -1 ) ? temp : 0; cost.conversion = ( temp > -1 ) ? temp : 0;
@ -1342,7 +1371,26 @@ public class ParserSymbolTable {
} }
} }
static private Cost checkStandardConversionSequence( TypeInfo source, TypeInfo target ){ static private void derivedToBaseConversion( Cost cost ) throws ParserSymbolTableException{
TypeInfo src = cost.source;
TypeInfo trg = cost.target;
ISymbol srcDecl = src.isType( TypeInfo.t_type ) ? src.getTypeSymbol() : null;
ISymbol trgDecl = trg.isType( TypeInfo.t_type ) ? trg.getTypeSymbol() : null;
if( !src.hasSamePtrs( trg ) || srcDecl == null || trgDecl == null || !cost.targetHadReference ){
return;
}
int temp = hasBaseClass( (IDerivableContainerSymbol) srcDecl, (IDerivableContainerSymbol) trgDecl, true );
if( temp > -1 ){
cost.rank = Cost.DERIVED_TO_BASE_CONVERSION;
cost.conversion = temp;
}
}
static private Cost checkStandardConversionSequence( TypeInfo source, TypeInfo target ) throws ParserSymbolTableException{
Cost cost = lvalue_to_rvalue( source, target ); Cost cost = lvalue_to_rvalue( source, target );
if( cost.source == null || cost.target == null ){ if( cost.source == null || cost.target == null ){
@ -1368,6 +1416,11 @@ public class ParserSymbolTable {
conversion( cost ); conversion( cost );
if( cost.rank > -1 )
return cost;
derivedToBaseConversion( cost );
return cost; return cost;
} }
@ -1385,7 +1438,7 @@ public class ParserSymbolTable {
if( target.getType() == TypeInfo.t_type ){ if( target.getType() == TypeInfo.t_type ){
targetDecl = target.getTypeSymbol(); targetDecl = target.getTypeSymbol();
if( targetDecl.isType( TypeInfo.t_class, TypeInfo.t_union ) ){ if( targetDecl.isType( TypeInfo.t_class, TypeInfo.t_union ) ){
LookupData data = new LookupData( "", TypeInfo.t_constructor, null ); LookupData data = new LookupData( EMPTY_NAME, TypeInfo.t_constructor, null );
data.parameters = new LinkedList(); data.parameters = new LinkedList();
data.parameters.add( source ); data.parameters.add( source );
data.forUserDefinedConversion = true; data.forUserDefinedConversion = true;
@ -1415,8 +1468,8 @@ public class ParserSymbolTable {
if( sourceDecl != null && (sourceDecl instanceof IContainerSymbol) ){ if( sourceDecl != null && (sourceDecl instanceof IContainerSymbol) ){
String name = target.toString(); String name = target.toString();
if( !name.equals("") ){ if( !name.equals(EMPTY_NAME) ){
LookupData data = new LookupData( "operator " + name, TypeInfo.t_function, null ); LookupData data = new LookupData( "operator " + name, TypeInfo.t_function, null ); //$NON-NLS-1$
LinkedList params = new LinkedList(); LinkedList params = new LinkedList();
data.parameters = params; data.parameters = params;
data.forUserDefinedConversion = true; data.forUserDefinedConversion = true;
@ -1545,20 +1598,35 @@ public class ParserSymbolTable {
returnInfo.setTypeInfo( info.getTypeInfo() ); returnInfo.setTypeInfo( info.getTypeInfo() );
returnInfo.setType( info.getType() ); returnInfo.setType( info.getType() );
returnInfo.setTypeSymbol( null ); returnInfo.setTypeSymbol( null );
returnInfo.addPtrOperator( info.getPtrOperators() );
} }
returnInfo.applyPtrsAsUnaryOperators( topInfo.getPtrOperators() ); returnInfo.applyOperatorExpressions( topInfo.getOperatorExpressions() );
if( topInfo.hasPtrOperators() ){
TypeInfo.PtrOp topPtr = (PtrOp) topInfo.getPtrOperators().iterator().next();
TypeInfo.PtrOp ptr = null;
if( returnInfo.hasPtrOperators() ){
ptr = (PtrOp)returnInfo.getPtrOperators().iterator().next();
} else {
ptr = new PtrOp();
returnInfo.addPtrOperator( ptr );
}
ptr.setConst( topPtr.isConst() );
ptr.setVolatile( topPtr.isVolatile() );
}
} }
return returnInfo; return returnInfo;
} }
static private IParameterizedSymbol matchTemplatePartialSpecialization( IParameterizedSymbol template, LinkedList args ){ static private IParameterizedSymbol matchTemplatePartialSpecialization( IParameterizedSymbol template, List args ){
if( template == null ){ if( template == null ){
return null; return null;
} }
LinkedList specs = template.getSpecializations(); List specs = template.getSpecializations();
int size = ( specs != null ) ? specs.size() : 0; int size = ( specs != null ) ? specs.size() : 0;
if( size == 0 ){ if( size == 0 ){
return template; return template;
@ -1568,7 +1636,7 @@ public class ParserSymbolTable {
boolean bestMatchIsBest = true; boolean bestMatchIsBest = true;
Iterator iter = specs.iterator(); Iterator iter = specs.iterator();
IParameterizedSymbol spec = null; IParameterizedSymbol spec = null;
LinkedList specArgs = null; List specArgs = null;
for( int i = size; i > 0; i-- ){ for( int i = size; i > 0; i-- ){
spec = (IParameterizedSymbol) iter.next(); spec = (IParameterizedSymbol) iter.next();
specArgs = spec.getArgumentList(); specArgs = spec.getArgumentList();
@ -1581,7 +1649,7 @@ public class ParserSymbolTable {
Iterator iter2 = args.iterator(); Iterator iter2 = args.iterator();
HashMap map = new HashMap(); HashMap map = new HashMap();
String name = null; //String name = null;
boolean match = true; boolean match = true;
for( int j = specArgs.size(); j > 0; j-- ){ for( int j = specArgs.size(); j > 0; j-- ){
sym1 = (ISymbol)iter1.next(); sym1 = (ISymbol)iter1.next();
@ -1589,7 +1657,7 @@ public class ParserSymbolTable {
if( info2.isType( TypeInfo.t_type ) ){ if( info2.isType( TypeInfo.t_type ) ){
sym2 = sym2.getTypeSymbol(); sym2 = sym2.getTypeSymbol();
} else { } else {
sym2 = template.getSymbolTable().newSymbol( "" ); sym2 = template.getSymbolTable().newSymbol( EMPTY_NAME );
sym2.setTypeInfo( info2 ); sym2.setTypeInfo( info2 );
} }
@ -1694,7 +1762,7 @@ public class ParserSymbolTable {
return false; return false;
} }
LinkedList args = ((IParameterizedSymbol) argFunction).getParameterList(); List args = ((IParameterizedSymbol) argFunction).getParameterList();
IParameterizedSymbol function = (IParameterizedSymbol) templateSymbol; IParameterizedSymbol function = (IParameterizedSymbol) templateSymbol;
@ -1715,7 +1783,7 @@ public class ParserSymbolTable {
return true; return true;
} }
static private boolean deduceTemplateArgument( HashMap map, ISymbol p, ISymbol a, HashMap argumentMap ){ static private boolean deduceTemplateArgument( Map map, ISymbol p, ISymbol a, Map argumentMap ){
if( argumentMap != null && argumentMap.containsKey( a ) ){ if( argumentMap != null && argumentMap.containsKey( a ) ){
a = (ISymbol) argumentMap.get( a ); a = (ISymbol) argumentMap.get( a );
} }
@ -1730,12 +1798,12 @@ public class ParserSymbolTable {
if( pSymbol.isTemplateMember() && pSymbol.isType( TypeInfo.t_undef ) ){ if( pSymbol.isTemplateMember() && pSymbol.isType( TypeInfo.t_undef ) ){
//T* or T& or T[ const ] //T* or T& or T[ const ]
//also //also
LinkedList pPtrs = pSymbol.getPtrOperators(); List pPtrs = pSymbol.getPtrOperators();
LinkedList aPtrs = aSymbol.getPtrOperators(); List aPtrs = aSymbol.getPtrOperators();
if( pPtrs != null ){ if( pPtrs != null ){
TypeInfo.PtrOp pOp = (TypeInfo.PtrOp) pPtrs.getFirst(); TypeInfo.PtrOp pOp = (TypeInfo.PtrOp) pPtrs.iterator().next();;
TypeInfo.PtrOp aOp = ( aPtrs != null ) ? (TypeInfo.PtrOp)aPtrs.getFirst() : null; TypeInfo.PtrOp aOp = ( aPtrs != null ) ? (TypeInfo.PtrOp)pPtrs.iterator().next() : null;
if( pOp != null && aOp != null && pOp.getType() == aOp.getType() ){ if( pOp != null && aOp != null && pOp.getType() == aOp.getType() ){
if( pOp.getType() == TypeInfo.PtrOp.t_memberPointer ){ if( pOp.getType() == TypeInfo.PtrOp.t_memberPointer ){
@ -1759,8 +1827,8 @@ public class ParserSymbolTable {
} }
//template-name<T> or template-name<i> //template-name<T> or template-name<i>
else if( pSymbol.isType( TypeInfo.t_template ) && aSymbol.isType( TypeInfo.t_template ) ){ else if( pSymbol.isType( TypeInfo.t_template ) && aSymbol.isType( TypeInfo.t_template ) ){
LinkedList pArgs = ((IParameterizedSymbol)pSymbol).getArgumentList(); List pArgs = ((IParameterizedSymbol)pSymbol).getArgumentList();
LinkedList aArgs = ((IParameterizedSymbol)aSymbol).getArgumentList(); List aArgs = ((IParameterizedSymbol)aSymbol).getArgumentList();
if( pArgs == null || aArgs == null || pArgs.size() != aArgs.size()){ if( pArgs == null || aArgs == null || pArgs.size() != aArgs.size()){
return false; return false;
@ -1782,8 +1850,8 @@ public class ParserSymbolTable {
return false; return false;
} }
if( pSymbol.getPtrOperators() != null ){ if( pSymbol.getPtrOperators() != null ){
LinkedList ptrs = pSymbol.getPtrOperators(); List ptrs = pSymbol.getPtrOperators();
TypeInfo.PtrOp op = (TypeInfo.PtrOp) ptrs.getFirst(); TypeInfo.PtrOp op = (TypeInfo.PtrOp) ptrs.iterator().next();;
if( op.getType() == TypeInfo.PtrOp.t_memberPointer ){ if( op.getType() == TypeInfo.PtrOp.t_memberPointer ){
if( !deduceTemplateArgument( map, op.getMemberOf(), pFunction.getContainingSymbol(), argumentMap ) ){ if( !deduceTemplateArgument( map, op.getMemberOf(), pFunction.getContainingSymbol(), argumentMap ) ){
return false; return false;
@ -1791,8 +1859,8 @@ public class ParserSymbolTable {
} }
} }
LinkedList pParams = pFunction.getParameterList(); List pParams = pFunction.getParameterList();
LinkedList aParams = aFunction.getParameterList(); List aParams = aFunction.getParameterList();
if( pParams.size() != aParams.size() ){ if( pParams.size() != aParams.size() ){
return false; return false;
} else { } else {
@ -1861,7 +1929,7 @@ public class ParserSymbolTable {
*/ */
static private TemplateInstance transformFunctionTemplateForOrdering( IParameterizedSymbol template ){ static private TemplateInstance transformFunctionTemplateForOrdering( IParameterizedSymbol template ){
LinkedList paramList = template.getParameterList(); List paramList = template.getParameterList();
int size = ( paramList != null ) ? paramList.size() : 0; int size = ( paramList != null ) ? paramList.size() : 0;
if( size == 0 ){ if( size == 0 ){
@ -1871,7 +1939,7 @@ public class ParserSymbolTable {
HashMap map = new HashMap(); HashMap map = new HashMap();
for( Iterator iterator = paramList.iterator(); iterator.hasNext(); ) { for( Iterator iterator = paramList.iterator(); iterator.hasNext(); ) {
ISymbol param = (ISymbol) iterator.next(); ISymbol param = (ISymbol) iterator.next();
ISymbol val = template.getSymbolTable().newSymbol( "", TypeInfo.t_type ); ISymbol val = template.getSymbolTable().newSymbol( EMPTY_NAME, TypeInfo.t_type );
if( false /* is value */ ){ if( false /* is value */ ){
//val.getTypeInfo().setHasDefault() //val.getTypeInfo().setHasDefault()
} }
@ -1971,7 +2039,7 @@ public class ParserSymbolTable {
_context.getContainedSymbols().remove( _decl.getName() ); _context.getContainedSymbols().remove( _decl.getName() );
} }
if( _removeThis && _decl instanceof IParameterizedSymbol ){ if( _removeThis && _decl instanceof IParameterizedSymbol ){
((IParameterizedSymbol)_decl).getContainedSymbols().remove( "this" ); ((IParameterizedSymbol)_decl).getContainedSymbols().remove( THIS );
} }
} }
@ -1987,7 +2055,7 @@ public class ParserSymbolTable {
_removeThis = removeThis; _removeThis = removeThis;
} }
public void undoIt(){ public void undoIt(){
LinkedList constructors = _context.getConstructors(); List constructors = _context.getConstructors();
ListIterator iter = constructors.listIterator(); ListIterator iter = constructors.listIterator();
int size = constructors.size(); int size = constructors.size();
@ -2001,7 +2069,7 @@ public class ParserSymbolTable {
} }
if( _removeThis ){ if( _removeThis ){
_constructor.getContainedSymbols().remove( "this" ); _constructor.getContainedSymbols().remove( THIS );
} }
} }
@ -2035,7 +2103,7 @@ public class ParserSymbolTable {
_decl.getParameterList().remove( _param ); _decl.getParameterList().remove( _param );
String name = _param.getName(); String name = _param.getName();
if( name != null && !name.equals("") ) if( name != null && !name.equals(EMPTY_NAME) )
{ {
_decl.getParameterMap().remove( name ); _decl.getParameterMap().remove( name );
} }
@ -2079,7 +2147,7 @@ public class ParserSymbolTable {
public HashSet inheritanceChain; //used to detect circular inheritance public HashSet inheritanceChain; //used to detect circular inheritance
public LinkedList parameters; //parameter info for resolving functions public List parameters; //parameter info for resolving functions
public HashSet associated; //associated namespaces for argument dependant lookup public HashSet associated; //associated namespaces for argument dependant lookup
public ISymbol stopAt; //stop looking along the stack once we hit this declaration public ISymbol stopAt; //stop looking along the stack once we hit this declaration
@ -2102,14 +2170,17 @@ public class ParserSymbolTable {
static private class Cost static private class Cost
{ {
public Cost( TypeInfo s, TypeInfo t ){ public Cost( TypeInfo s, TypeInfo t ){
source = s; source = new TypeInfo( s );
target = t; target = new TypeInfo( t );
} }
public TypeInfo source; public TypeInfo source;
public TypeInfo target; public TypeInfo target;
public boolean targetHadReference = false;
public int lvalue; public int lvalue;
public int promotion; public int promotion;
public int conversion; public int conversion;
@ -2126,7 +2197,10 @@ public class ParserSymbolTable {
public static final int LVALUE_OR_QUALIFICATION_RANK = 0; public static final int LVALUE_OR_QUALIFICATION_RANK = 0;
public static final int PROMOTION_RANK = 1; public static final int PROMOTION_RANK = 1;
public static final int CONVERSION_RANK = 2; public static final int CONVERSION_RANK = 2;
public static final int USERDEFINED_CONVERSION_RANK = 3; public static final int DERIVED_TO_BASE_CONVERSION = 3;
public static final int USERDEFINED_CONVERSION_RANK = 4;
public static final int ELLIPSIS_CONVERSION = 5;
public int compare( Cost cost ){ public int compare( Cost cost ){
int result = 0; int result = 0;
@ -2318,7 +2392,6 @@ public class ParserSymbolTable {
TypeInfo.PtrOp op1 = null, op2 = null; TypeInfo.PtrOp op1 = null, op2 = null;
int subOrSuper = 0;
for( int i = size; i > 0; i-- ){ for( int i = size; i > 0; i-- ){
op1 = (TypeInfo.PtrOp)iter1.next(); op1 = (TypeInfo.PtrOp)iter1.next();
op2 = (TypeInfo.PtrOp)iter2.next(); op2 = (TypeInfo.PtrOp)iter2.next();
@ -2332,7 +2405,7 @@ public class ParserSymbolTable {
return 0; return 0;
} }
public LinkedList getPtrOperators(){ public List getPtrOperators(){
return getTypeInfo().getPtrOperators(); return getTypeInfo().getPtrOperators();
} }
public void addPtrOperator( TypeInfo.PtrOp ptrOp ){ public void addPtrOperator( TypeInfo.PtrOp ptrOp ){
@ -2355,7 +2428,7 @@ public class ParserSymbolTable {
public void setTemplateInstance( TemplateInstance instance ){ public void setTemplateInstance( TemplateInstance instance ){
_templateInstance = instance; _templateInstance = instance;
} }
public HashMap getArgumentMap(){ public Map getArgumentMap(){
return null; return null;
} }
private String _name; //our name private String _name; //our name
@ -2370,8 +2443,8 @@ public class ParserSymbolTable {
public class TemplateInstance extends BasicSymbol public class TemplateInstance extends BasicSymbol
{ {
protected TemplateInstance( ISymbol symbol, HashMap argMap ){ protected TemplateInstance( ISymbol symbol, Map argMap ){
super(""); super(EMPTY_NAME);
_instantiatedSymbol = symbol; _instantiatedSymbol = symbol;
symbol.setTemplateInstance( this ); symbol.setTemplateInstance( this );
_argumentMap = argMap; _argumentMap = argMap;
@ -2471,16 +2544,14 @@ public class ParserSymbolTable {
return _instantiatedSymbol.getTypeInfo(); return _instantiatedSymbol.getTypeInfo();
} }
public HashMap getArgumentMap(){ public Map getArgumentMap(){
return _argumentMap; return _argumentMap;
} }
private ISymbol _instantiatedSymbol; private ISymbol _instantiatedSymbol;
//private LinkedList _arguments; //private LinkedList _arguments;
private HashMap _argumentMap; private Map _argumentMap;
private Object _callbackExtension;
} }
public class Declaration extends BasicSymbol implements Cloneable, public class Declaration extends BasicSymbol implements Cloneable,
@ -2568,11 +2639,11 @@ public class ParserSymbolTable {
return _containedDeclarations; return _containedDeclarations;
} }
public LinkedList getConstructors(){ public List getConstructors(){
return _constructors; return _constructors;
} }
public LinkedList createConstructors(){ public List createConstructors(){
if( _constructors == null ) if( _constructors == null )
_constructors = new LinkedList(); _constructors = new LinkedList();
@ -2601,23 +2672,23 @@ public class ParserSymbolTable {
_returnType = type; _returnType = type;
} }
public LinkedList getParameterList(){ public List getParameterList(){
return _parameterList; return _parameterList;
} }
public void setParameterList( LinkedList list ){ public void setParameterList( List list ){
_parameterList = list; _parameterList = new LinkedList( list );
} }
public HashMap getParameterMap(){ public Map getParameterMap(){
return _parameterHash; return _parameterHash;
} }
public LinkedList getArgumentList(){ public List getArgumentList(){
return _argumentList; return _argumentList;
} }
public void setArgumentList( LinkedList list ){ public void setArgumentList( List list ){
_argumentList = list; _argumentList = new LinkedList( list );
} }
public void addArgument( ISymbol arg ){ public void addArgument( ISymbol arg ){
if( _argumentList == null ){ if( _argumentList == null ){
@ -2637,7 +2708,7 @@ public class ParserSymbolTable {
_parameterList.addLast( param ); _parameterList.addLast( param );
String name = param.getName(); String name = param.getName();
if( name != null && !name.equals("") ) if( name != null && !name.equals(EMPTY_NAME) )
{ {
if( _parameterHash == null ) if( _parameterHash == null )
_parameterHash = new HashMap(); _parameterHash = new HashMap();
@ -2653,7 +2724,7 @@ public class ParserSymbolTable {
} }
public void addParameter( ISymbol typeSymbol, TypeInfo.PtrOp ptrOp, boolean hasDefault ){ public void addParameter( ISymbol typeSymbol, TypeInfo.PtrOp ptrOp, boolean hasDefault ){
BasicSymbol param = new BasicSymbol(""); BasicSymbol param = new BasicSymbol(EMPTY_NAME);
TypeInfo info = param.getTypeInfo(); TypeInfo info = param.getTypeInfo();
info.setType( TypeInfo.t_type ); info.setType( TypeInfo.t_type );
@ -2665,7 +2736,7 @@ public class ParserSymbolTable {
} }
public void addParameter( TypeInfo.eType type, int info, TypeInfo.PtrOp ptrOp, boolean hasDefault ){ public void addParameter( TypeInfo.eType type, int info, TypeInfo.PtrOp ptrOp, boolean hasDefault ){
BasicSymbol param = new BasicSymbol(""); BasicSymbol param = new BasicSymbol(EMPTY_NAME);
TypeInfo t = param.getTypeInfo(); TypeInfo t = param.getTypeInfo();
t.setTypeInfo( info ); t.setTypeInfo( info );
@ -2736,7 +2807,7 @@ public class ParserSymbolTable {
Map declarations = containing.getContainedSymbols(); Map declarations = containing.getContainedSymbols();
boolean unnamed = obj.getName().equals( "" ); boolean unnamed = obj.getName().equals( EMPTY_NAME );
Object origObj = null; Object origObj = null;
@ -2800,9 +2871,7 @@ public class ParserSymbolTable {
if( !constructor.isType( TypeInfo.t_constructor ) ) if( !constructor.isType( TypeInfo.t_constructor ) )
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo ); throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo );
Object origObj = null; List constructors = getConstructors();
LinkedList constructors = getConstructors();
if( constructors == null ) if( constructors == null )
constructors = createConstructors(); constructors = createConstructors();
@ -2820,6 +2889,20 @@ public class ParserSymbolTable {
pushCommand( command ); pushCommand( command );
} }
public void addCopyConstructor() throws ParserSymbolTableException{
List parameters = new LinkedList();
TypeInfo param = new TypeInfo( TypeInfo.t_type, 0, this, new TypeInfo.PtrOp( TypeInfo.PtrOp.t_reference, true, false ), false );
parameters.add( param );
IParameterizedSymbol constructor = lookupConstructor( parameters );
if( constructor == null ){
constructor = getSymbolTable().newParameterizedSymbol( getName(), TypeInfo.t_constructor );
constructor.addParameter( this, new TypeInfo.PtrOp( TypeInfo.PtrOp.t_reference, true, false ), false );
addConstructor( constructor );
}
}
/** /**
* *
* @param obj * @param obj
@ -2843,20 +2926,20 @@ public class ParserSymbolTable {
if( obj.getContainingSymbol().isType( TypeInfo.t_class, TypeInfo.t_union ) ){ if( obj.getContainingSymbol().isType( TypeInfo.t_class, TypeInfo.t_union ) ){
//check to see if there is already a this object, since using declarations //check to see if there is already a this object, since using declarations
//of function will have them from the original declaration //of function will have them from the original declaration
LookupData data = new LookupData( "this", TypeInfo.t_any, null ); LookupData data = new LookupData( THIS, TypeInfo.t_any, null );
lookupInContained( data, obj ); lookupInContained( data, obj );
//if we didn't find "this" then foundItems will still be null, no need to actually //if we didn't find "this" then foundItems will still be null, no need to actually
//check its contents //check its contents
if( data.foundItems == null ){ if( data.foundItems == null ){
Declaration thisObj = new Declaration("this"); Declaration thisObj = new Declaration( THIS );
thisObj.setType( TypeInfo.t_type ); thisObj.setType( TypeInfo.t_type );
thisObj.setTypeSymbol( obj.getContainingSymbol() ); thisObj.setTypeSymbol( obj.getContainingSymbol() );
//thisObj.setCVQualifier( obj.getCVQualifier() ); //thisObj.setCVQualifier( obj.getCVQualifier() );
TypeInfo.PtrOp ptr = new TypeInfo.PtrOp(); TypeInfo.PtrOp ptr = new TypeInfo.PtrOp();
ptr.setType( TypeInfo.PtrOp.t_pointer ); ptr.setType( TypeInfo.PtrOp.t_pointer );
if( obj.getTypeInfo().hasPtrOperators() ){ if( obj.getTypeInfo().hasPtrOperators() ){
ptr.setConst( ((TypeInfo.PtrOp) obj.getPtrOperators().getFirst()).isConst() ); ptr.setConst( ((TypeInfo.PtrOp) obj.getPtrOperators().iterator().next()).isConst() );
ptr.setVolatile( ((TypeInfo.PtrOp) obj.getPtrOperators().getFirst()).isVolatile() ); ptr.setVolatile( ((TypeInfo.PtrOp) obj.getPtrOperators().iterator().next()).isVolatile() );
} }
thisObj.addPtrOperator(ptr); thisObj.addPtrOperator(ptr);
@ -3129,7 +3212,7 @@ public class ParserSymbolTable {
* Member lookup really proceeds as an unqualified lookup, but doesn't * Member lookup really proceeds as an unqualified lookup, but doesn't
* include argument dependant scopes * include argument dependant scopes
*/ */
public IParameterizedSymbol memberFunctionLookup( String name, LinkedList parameters ) throws ParserSymbolTableException{ public IParameterizedSymbol memberFunctionLookup( String name, List parameters ) throws ParserSymbolTableException{
LookupData data = new LookupData( name, TypeInfo.t_function, getTemplateInstance() ); LookupData data = new LookupData( name, TypeInfo.t_function, getTemplateInstance() );
//if parameters == null, thats no parameters, but we need to distinguish that from //if parameters == null, thats no parameters, but we need to distinguish that from
//no parameter information at all, so make an empty list. //no parameter information at all, so make an empty list.
@ -3139,7 +3222,7 @@ public class ParserSymbolTable {
return (IParameterizedSymbol) ParserSymbolTable.resolveAmbiguities( data ); return (IParameterizedSymbol) ParserSymbolTable.resolveAmbiguities( data );
} }
public IParameterizedSymbol qualifiedFunctionLookup( String name, LinkedList parameters ) throws ParserSymbolTableException{ public IParameterizedSymbol qualifiedFunctionLookup( String name, List parameters ) throws ParserSymbolTableException{
LookupData data = new LookupData( name, TypeInfo.t_function, getTemplateInstance() ); LookupData data = new LookupData( name, TypeInfo.t_function, getTemplateInstance() );
data.qualified = true; data.qualified = true;
//if parameters == null, thats no parameters, but we need to distinguish that from //if parameters == null, thats no parameters, but we need to distinguish that from
@ -3164,7 +3247,7 @@ public class ParserSymbolTable {
return ParserSymbolTable.resolveAmbiguities( data ); return ParserSymbolTable.resolveAmbiguities( data );
} }
public TemplateInstance templateLookup( String name, LinkedList arguments ) throws ParserSymbolTableException public TemplateInstance templateLookup( String name, List arguments ) throws ParserSymbolTableException
{ {
LookupData data = new LookupData( name, TypeInfo.t_any, getTemplateInstance() ); LookupData data = new LookupData( name, TypeInfo.t_any, getTemplateInstance() );
data.parameters = arguments; data.parameters = arguments;
@ -3177,9 +3260,9 @@ public class ParserSymbolTable {
return null; return null;
} }
public IParameterizedSymbol lookupConstructor( LinkedList parameters ) throws ParserSymbolTableException public IParameterizedSymbol lookupConstructor( List parameters ) throws ParserSymbolTableException
{ {
LookupData data = new LookupData( "", TypeInfo.t_constructor, null ); LookupData data = new LookupData( EMPTY_NAME, TypeInfo.t_constructor, null );
data.parameters = parameters; data.parameters = parameters;
return ParserSymbolTable.resolveFunction( data, getConstructors() ); return ParserSymbolTable.resolveFunction( data, getConstructors() );
@ -3207,7 +3290,7 @@ public class ParserSymbolTable {
* ordinary unqualified lookup and the set of declarations found in the * ordinary unqualified lookup and the set of declarations found in the
* namespaces and classes associated with the argument types. * namespaces and classes associated with the argument types.
*/ */
public IParameterizedSymbol unqualifiedFunctionLookup( String name, LinkedList parameters ) throws ParserSymbolTableException{ public IParameterizedSymbol unqualifiedFunctionLookup( String name, List parameters ) throws ParserSymbolTableException{
//figure out the set of associated scopes first, so we can remove those that are searched //figure out the set of associated scopes first, so we can remove those that are searched
//during the normal lookup to avoid doing them twice //during the normal lookup to avoid doing them twice
HashSet associated = new HashSet(); HashSet associated = new HashSet();
@ -3231,7 +3314,7 @@ public class ParserSymbolTable {
//if T is a pointer to a data member of class X, its associated namespaces and classes //if T is a pointer to a data member of class X, its associated namespaces and classes
//are those associated with the member type together with those associated with X //are those associated with the member type together with those associated with X
if( param.hasPtrOperators() && param.getPtrOperators().size() == 1 ){ if( param.hasPtrOperators() && param.getPtrOperators().size() == 1 ){
TypeInfo.PtrOp op = (TypeInfo.PtrOp)param.getPtrOperators().getFirst(); TypeInfo.PtrOp op = (TypeInfo.PtrOp)param.getPtrOperators().iterator().next();
if( op.getType() == TypeInfo.PtrOp.t_pointer && if( op.getType() == TypeInfo.PtrOp.t_pointer &&
paramType.getContainingSymbol().isType( TypeInfo.t_class, TypeInfo.t_union ) ) paramType.getContainingSymbol().isType( TypeInfo.t_class, TypeInfo.t_union ) )
{ {
@ -3258,8 +3341,6 @@ public class ParserSymbolTable {
} }
Declaration decl; Declaration decl;
Declaration temp;
//dump the hash to an array and iterate over the array because we //dump the hash to an array and iterate over the array because we
//could be removing items from the collection as we go and we don't //could be removing items from the collection as we go and we don't
//want to get ConcurrentModificationExceptions //want to get ConcurrentModificationExceptions
@ -3286,7 +3367,7 @@ public class ParserSymbolTable {
return ( _specializations != null && !_specializations.isEmpty() ); return ( _specializations != null && !_specializations.isEmpty() );
} }
public LinkedList getSpecializations(){ public List getSpecializations(){
return _specializations; return _specializations;
} }
@ -3297,7 +3378,7 @@ public class ParserSymbolTable {
_specializations.add( spec ); _specializations.add( spec );
} }
public TemplateInstance instantiate( LinkedList arguments ) throws ParserSymbolTableException{ public TemplateInstance instantiate( List arguments ) throws ParserSymbolTableException{
if( getType() != TypeInfo.t_template ){ if( getType() != TypeInfo.t_template ){
return null; return null;
} }
@ -3350,16 +3431,14 @@ public class ParserSymbolTable {
return instance; return instance;
} }
private boolean _needsDefinition; //this name still needs to be defined private boolean _needsDefinition; //this name still needs to be defined
private LinkedList _parentScopes; //inherited scopes (is base classes)
private LinkedList _parentScopes; //inherited scopes (is base classes) private LinkedList _usingDirectives; //collection of nominated namespaces
private LinkedList _usingDirectives; //collection of nominated namespaces
private HashMap _containedDeclarations; //declarations contained by us. private HashMap _containedDeclarations; //declarations contained by us.
private LinkedList _specializations; //template specializations private LinkedList _specializations; //template specializations
private LinkedList _argumentList; //template specialization arguments private LinkedList _argumentList; //template specialization arguments
private LinkedList _parameterList; //have my cake private LinkedList _parameterList; //have my cake
private HashMap _parameterHash; //and eat it too private HashMap _parameterHash; //and eat it too
@ -3368,8 +3447,6 @@ public class ParserSymbolTable {
private ISymbol _returnType; private ISymbol _returnType;
public class ParentWrapper implements IDerivableContainerSymbol.IParentSymbol public class ParentWrapper implements IDerivableContainerSymbol.IParentSymbol
{ {
public ParentWrapper( ISymbol p, boolean v, ASTAccessVisibility s, int offset, List r ){ public ParentWrapper( ISymbol p, boolean v, ASTAccessVisibility s, int offset, List r ){
@ -3396,6 +3473,10 @@ public class ParserSymbolTable {
isVirtual = virtual; isVirtual = virtual;
} }
public ASTAccessVisibility getVisibility(){
return access;
}
private boolean isVirtual = false; private boolean isVirtual = false;
protected ISymbol parent = null; protected ISymbol parent = null;
private final ASTAccessVisibility access; private final ASTAccessVisibility access;

View file

@ -43,6 +43,7 @@ public class ParserSymbolTableException extends Exception {
public static final int r_InvalidOverload = 3; public static final int r_InvalidOverload = 3;
public static final int r_BadTemplate = 4; public static final int r_BadTemplate = 4;
public static final int r_InvalidUsing = 5; public static final int r_InvalidUsing = 5;
public static final int r_BadVisibility = 6;
public int reason = -1; public int reason = -1;
} }

View file

@ -13,7 +13,9 @@ package org.eclipse.cdt.internal.core.parser.pst;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.ListIterator;
import org.eclipse.cdt.core.parser.Enum;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.TemplateInstance; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.TemplateInstance;
@ -130,6 +132,26 @@ public class TypeInfo {
private int _val; private int _val;
} }
public static class OperatorExpression extends Enum{
//5.3.1-1 : The unary * operator, the expression to which it is applied shall be
//a pointer to an object type or a pointer to a function type and the result
//is an lvalue refering to the object or function to which the expression points
public static final OperatorExpression indirection = new OperatorExpression( 1 );
//5.3.1-2 : The result of the unary & operator is a pointer to its operand
public static final OperatorExpression addressof = new OperatorExpression( 0 );
//5.2.1 A postfix expression followed by an expression in square brackets is a postfix
//expression. one of the expressions shall have the type "pointer to T" and the other
//shall have a enumeration or integral type. The result is an lvalue of type "T"
public static final OperatorExpression subscript = new OperatorExpression( 2 );
protected OperatorExpression(int enumValue) {
super(enumValue);
}
}
public static class PtrOp { public static class PtrOp {
public PtrOp( TypeInfo.eType type ){ public PtrOp( TypeInfo.eType type ){
this.type = type; this.type = type;
@ -190,23 +212,27 @@ public class TypeInfo {
private ISymbol memberOf = null; private ISymbol memberOf = null;
} }
private static final String _image[] = { "", private static final String _image[] = { "", //$NON-NLS-1$ t_undef
"", "", //$NON-NLS-1$ t_type
"namespace", "namespace", //$NON-NLS-1$ t_namespace
"template", "class", //$NON-NLS-1$ t_class
"class", "struct", //$NON-NLS-1$ t_struct
"struct", "union", //$NON-NLS-1$ t_union
"union", "enum", //$NON-NLS-1$ t_enumeration
"enum", "", //$NON-NLS-1$ t_constructor
"", "", //$NON-NLS-1$ t_function
"bool", "bool", //$NON-NLS-1$ t_bool
"char", "char", //$NON-NLS-1$ t_char
"wchar_t", "wchar_t", //$NON-NLS-1$ t_wchar_t
"int", "int", //$NON-NLS-1$ t_int
"float", "float", //$NON-NLS-1$ t_float
"double", "double", //$NON-NLS-1$ t_double
"void", "void", //$NON-NLS-1$ t_void
"" "", //$NON-NLS-1$ t_enumerator
"", //$NON-NLS-1$ t_block
"template", //$NON-NLS-1$ t_template
"", //$NON-NLS-1$ t_asm
"" //$NON-NLS-1$ t_linkage
}; };
//Partial ordering : //Partial ordering :
// none < const // none < const
@ -286,7 +312,7 @@ public class TypeInfo {
return ( _ptrOperators != null && _ptrOperators.size() > 0 ); return ( _ptrOperators != null && _ptrOperators.size() > 0 );
} }
public LinkedList getPtrOperators(){ public List getPtrOperators(){
return _ptrOperators; return _ptrOperators;
} }
@ -311,40 +337,38 @@ public class TypeInfo {
return false; return false;
} }
public void applyPtrsAsUnaryOperators( LinkedList ptrs ){ public List getOperatorExpressions(){
if( ptrs == null || ptrs.isEmpty() ) return _operatorExpressions;
}
public void applyOperatorExpressions( List ops ){
if( ops == null || ops.isEmpty() )
return; return;
int size = ptrs.size(); int size = ops.size();
Iterator iter = ptrs.iterator(); Iterator iter = ops.iterator();
TypeInfo.PtrOp op = null; OperatorExpression op = null;
for( int i = size; i > 0; i-- ){ for( int i = size; i > 0; i-- ){
op = (TypeInfo.PtrOp)iter.next(); op = (OperatorExpression)iter.next();
if( op.getType() == PtrOp.t_pointer ){ if( op == OperatorExpression.indirection ||
op == OperatorExpression.subscript )
{
//indirection operator, can only be applied to a pointer //indirection operator, can only be applied to a pointer
//subscript should be applied to something that is "pointer to T", the result is a lvalue of type "T"
if( hasPtrOperators() ){ if( hasPtrOperators() ){
TypeInfo.PtrOp first = (TypeInfo.PtrOp)getPtrOperators().getFirst(); ListIterator iterator = getPtrOperators().listIterator( getPtrOperators().size() );
if( first.getType() == TypeInfo.PtrOp.t_pointer ) TypeInfo.PtrOp last = (TypeInfo.PtrOp)iterator.previous();
if( last.getType() == TypeInfo.PtrOp.t_pointer ||
last.getType() == TypeInfo.PtrOp.t_array )
{ {
getPtrOperators().removeFirst(); iterator.remove();
if( op.isConst() || op.isVolatile() ){
if( hasPtrOperators() ){
((TypeInfo.PtrOp)getPtrOperators().getFirst()).setConst( op.isConst() );
((TypeInfo.PtrOp)getPtrOperators().getFirst()).setVolatile( op.isVolatile() );
} else {
TypeInfo.PtrOp newOp = new TypeInfo.PtrOp( TypeInfo.PtrOp.t_undef, op.isConst(), op.isVolatile() );
addPtrOperator( newOp );
}
}
} }
} else {
//???
} }
} else if( op.getType() == PtrOp.t_reference ){ } else if( op == OperatorExpression.addressof ){
//Address-of unary operator, results in pointer to T //Address-of unary operator, results in pointer to T
//TODO or pointer to member //TODO or pointer to member
TypeInfo.PtrOp newOp = new TypeInfo.PtrOp( PtrOp.t_pointer , op.isConst(), op.isVolatile() ); TypeInfo.PtrOp newOp = new TypeInfo.PtrOp( PtrOp.t_pointer );
addPtrOperator( newOp ); addPtrOperator( newOp );
} }
} }
@ -366,6 +390,13 @@ public class TypeInfo {
_ptrOperators.addAll( ptrs ); _ptrOperators.addAll( ptrs );
} }
public void addOperatorExpression( OperatorExpression exp ){
if( _operatorExpressions == null ){
_operatorExpressions = new LinkedList();
}
_operatorExpressions.add( exp );
}
public boolean getHasDefault(){ public boolean getHasDefault(){
return _hasDefaultValue; return _hasDefaultValue;
} }
@ -414,10 +445,18 @@ public class TypeInfo {
if( _typeDeclaration instanceof TemplateInstance ){ if( _typeDeclaration instanceof TemplateInstance ){
result &= _typeDeclaration.equals( type._typeDeclaration ); result &= _typeDeclaration.equals( type._typeDeclaration );
} else { } else {
result &= ( _typeDeclaration == type._typeDeclaration ); if( _typeDeclaration != null && type._typeDeclaration != null &&
_typeDeclaration.isType( TypeInfo.t_bool, TypeInfo.t_void ) &&
type._typeDeclaration.isType( TypeInfo.t_bool, TypeInfo.t_void ) )
{
//if typeDeclaration is a basic type, then only need the types the same
result &= ( _typeDeclaration.getType() == type._typeDeclaration.getType() );
} else {
//otherwise, its a user defined type, need the decls the same
result &= ( _typeDeclaration == type._typeDeclaration );
}
} }
int size1 = (_ptrOperators == null) ? 0 : _ptrOperators.size(); int size1 = (_ptrOperators == null) ? 0 : _ptrOperators.size();
int size2 = (type._ptrOperators == null) ? 0 : type._ptrOperators.size(); int size2 = (type._ptrOperators == null) ? 0 : type._ptrOperators.size();
if( size1 == size2 ){ if( size1 == size2 ){
@ -457,4 +496,5 @@ public class TypeInfo {
private boolean _hasDefaultValue = false; private boolean _hasDefaultValue = false;
private Object _defaultValue = null; private Object _defaultValue = null;
private LinkedList _ptrOperators; private LinkedList _ptrOperators;
private LinkedList _operatorExpressions;
} }