Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Camelon2003-06-05 21:37:27 +0000
committerJohn Camelon2003-06-05 21:37:27 +0000
commit1f0e53bbf71530c489a0a22317f999391159b2ee (patch)
treeb6be53b26a9fc6886dc43f7f3334117e493b5a6c
parenta96a0eb64e733bf0ae8201ad678fc30f945faf17 (diff)
downloadorg.eclipse.cdt-1f0e53bbf71530c489a0a22317f999391159b2ee.tar.gz
org.eclipse.cdt-1f0e53bbf71530c489a0a22317f999391159b2ee.tar.xz
org.eclipse.cdt-1f0e53bbf71530c489a0a22317f999391159b2ee.zip
Patch for Andrew Niefer.
For the symbol table: this patch contains the current (incomplete) implementation for matching template arguments and ranking specializations. This still needs work before you can properly instantiate a template and get the correct specialization. Implicit instantiation of template functions has not really been started, but these changes are an integral part of that as well. The relevant functions are : ParserSymbolTable.matchTemplatePartialSpecialization ParserSymbolTable.orderSpecializations ParserSymbolTable.deduceTemplateArguments ParserSymbolTable.deduceTemplateArgument ParserSymbolTable.classTemplateSpecializationToFunctionTemplate ParserSymbolTable.transformFunctionTemplateForOrdering Templates are going on the back burner for a little bit, so this is it for a while.
-rw-r--r--core/org.eclipse.cdt.core/parser/ChangeLog4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pst/IParameterizedSymbol.java4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pst/ParserSymbolTable.java305
-rw-r--r--core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java48
4 files changed, 293 insertions, 68 deletions
diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog
index 8f5dc031edc..1232d1db79a 100644
--- a/core/org.eclipse.cdt.core/parser/ChangeLog
+++ b/core/org.eclipse.cdt.core/parser/ChangeLog
@@ -1,3 +1,7 @@
+2003-06-05 Andrew Niefer
+ Begin implementation of functions for template specializations: deduceTemplateArgument,
+ classTemplateSpecializationToFunctionTemplate, transformFunctionTemplateForOrdering
+
2003-06-05 John Camelon
Fix Bug 38380 "Include" class public methods fails JUnit tests
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pst/IParameterizedSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pst/IParameterizedSymbol.java
index b4b4c263559..6893d8e87d6 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pst/IParameterizedSymbol.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pst/IParameterizedSymbol.java
@@ -35,6 +35,7 @@ public interface IParameterizedSymbol extends IContainerSymbol {
public void addArgument( ISymbol arg );
public LinkedList getArgumentList();
+ public void setArgumentList( LinkedList list );
public HashMap getParameterMap();
public LinkedList getParameterList();
@@ -42,7 +43,8 @@ public interface IParameterizedSymbol extends IContainerSymbol {
public boolean hasSameParameters(IParameterizedSymbol newDecl);
- public void setReturnType( TypeInfo.eType type );
+ public void setReturnType( ISymbol type );
+ public ISymbol getReturnType();
public boolean hasSpecializations();
public void addSpecialization( IParameterizedSymbol spec );
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pst/ParserSymbolTable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pst/ParserSymbolTable.java
index 1f52470048e..acfac22fab3 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pst/ParserSymbolTable.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pst/ParserSymbolTable.java
@@ -22,7 +22,6 @@ import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
-
/**
* @author aniefer
*/
@@ -1217,10 +1216,9 @@ public class ParserSymbolTable {
}
if( src.hasPtrOperators() && src.getPtrOperators().size() == 1 ){
TypeInfo.PtrOp ptr = (TypeInfo.PtrOp)src.getPtrOperators().getFirst();
+ ISymbol srcDecl = src.isType( TypeInfo.t_type ) ? src.getTypeSymbol() : null;
+ ISymbol trgDecl = trg.isType( TypeInfo.t_type ) ? trg.getTypeSymbol() : null;
if( ptr.getType() == TypeInfo.PtrOp.t_pointer ){
- ISymbol srcDecl = src.isType( TypeInfo.t_type ) ? src.getTypeSymbol() : null;
- ISymbol trgDecl = trg.isType( TypeInfo.t_type ) ? trg.getTypeSymbol() : null;
-
if( srcDecl == null || (trgDecl == null && !trg.isType( TypeInfo.t_void )) ){
return;
}
@@ -1245,15 +1243,21 @@ public class ParserSymbolTable {
cost.detail = 1;
return;
}
-
+ } else if( ptr.getType() == TypeInfo.PtrOp.t_memberPointer ){
//4.11-2 An rvalue of type "pointer to member of B of type cv T", where B is a class type,
//can be converted to an rvalue of type "pointer to member of D of type cv T" where D is a
//derived class of B
- if( srcDecl.getContainingSymbol().isType( TypeInfo.t_class ) && trgDecl.getContainingSymbol().isType( TypeInfo.t_class ) ){
- temp = hasBaseClass( (IDerivableContainerSymbol)trgDecl.getContainingSymbol(), (IDerivableContainerSymbol)srcDecl.getContainingSymbol() );
+ if( srcDecl == null || trgDecl == null ){
+ return;
+ }
+
+ TypeInfo.PtrOp srcPtr = trg.hasPtrOperators() ? (TypeInfo.PtrOp)trg.getPtrOperators().getFirst() : null;
+ if( trgDecl.isType( srcDecl.getType() ) && srcPtr != null && srcPtr.getType() == TypeInfo.PtrOp.t_memberPointer ){
+ temp = hasBaseClass( (IDerivableContainerSymbol)ptr.getMemberOf(), (IDerivableContainerSymbol)srcPtr.getMemberOf() );
cost.rank = 2;
+ cost.detail = 1;
cost.conversion = ( temp > -1 ) ? temp : 0;
- return;
+ return;
}
}
} else if( !src.hasPtrOperators() ) {
@@ -1425,8 +1429,8 @@ public class ParserSymbolTable {
}
LinkedList specs = template.getSpecializations();
- int size = specs.size();
- if( specs == null || size == 0 ){
+ int size = ( specs != null ) ? specs.size() : 0;
+ if( size == 0 ){
return template;
}
@@ -1451,8 +1455,19 @@ public class ParserSymbolTable {
boolean match = true;
for( int j = specArgs.size(); j > 0; j-- ){
sym1 = (ISymbol)iter1.next();
- sym2 = (ISymbol)iter2.next();
+ TypeInfo info2 = (TypeInfo) iter2.next();
+ if( info2.isType( TypeInfo.t_type ) ){
+ sym2 = sym2.getTypeSymbol();
+ } else {
+ sym2 = template.getSymbolTable().newSymbol( "" );
+ sym2.setTypeInfo( info2 );
+ }
+ if( !deduceTemplateArgument( map, sym1, sym2, null ) ){
+ match = false;
+ break;
+ }
+ /*
name = sym1.getName();
if( name.equals( "" ) ){
//no name, only type
@@ -1465,6 +1480,7 @@ public class ParserSymbolTable {
} else {
map.put( name, sym2 );
}
+ */
}
if( match ){
int compare = orderSpecializations( bestMatch, spec );
@@ -1477,7 +1493,7 @@ public class ParserSymbolTable {
}
}
- return null;
+ return bestMatchIsBest ? bestMatch : null;
}
/**
@@ -1488,23 +1504,26 @@ public class ParserSymbolTable {
* @return
*/
static private int orderSpecializations( IParameterizedSymbol spec1, IParameterizedSymbol spec2 ){
+ if( spec1 == null ){
+ return -1;
+ }
Iterator iter = spec1.getContainedSymbols().keySet().iterator();
ISymbol decl = (ISymbol) spec1.getContainedSymbols().get( iter.next() );
//to order class template specializations, we need to transform them into function templates
if( decl.isType( TypeInfo.t_class ) ) {
- spec1 = transformClassTemplateToFunctionTemplate( spec1 );
- spec2 = transformClassTemplateToFunctionTemplate( spec2 );
+ spec1 = classTemplateSpecializationToFunctionTemplate( spec1 );
+ spec2 = classTemplateSpecializationToFunctionTemplate( spec2 );
}
- IParameterizedSymbol transformed1 = transformFunctionTemplateForOrdering( spec1 );
- IParameterizedSymbol transformed2 = transformFunctionTemplateForOrdering( spec2 );
+ TemplateInstance transformed1 = transformFunctionTemplateForOrdering( spec1 );
+ TemplateInstance transformed2 = transformFunctionTemplateForOrdering( spec2 );
//Using the transformed parameter list, perform argument deduction against the other
//function template
- boolean d1 = deduceTemplateArguments( spec2, transformed1.getParameterList() );
- boolean d2 = deduceTemplateArguments( spec1, transformed2.getParameterList() );
+ boolean d1 = deduceTemplateArguments( spec2, transformed1 );
+ boolean d2 = deduceTemplateArguments( spec1, transformed2 );
//The transformed template is at least as specialized as the other iff the deduction
//succeeds and the deduced parameter types are an exact match
@@ -1528,10 +1547,150 @@ public class ParserSymbolTable {
* type (A), and an attempt is made to find template argument vaules that will make P,
* after substitution of the deduced values, compatible with A.
*/
- static private boolean deduceTemplateArguments( IParameterizedSymbol template, LinkedList args ){
+ static private boolean deduceTemplateArguments( IParameterizedSymbol template, TemplateInstance argSource ){
+ if( template.getContainedSymbols() == null || template.getContainedSymbols().size() != 1 ){
+ return false;
+ }
+ Iterator iter = template.getContainedSymbols().keySet().iterator();
+ ISymbol templateSymbol = (ISymbol) template.getContainedSymbols().get( iter.next() );
+ if( !templateSymbol.isType( TypeInfo.t_function ) ){
+ return false;
+ }
+
+ IParameterizedSymbol argTemplate = (IParameterizedSymbol)argSource.getInstantiatedSymbol();
+ iter = argTemplate.getContainedSymbols().keySet().iterator();
+ ISymbol argFunction = (ISymbol) argTemplate.getContainedSymbols().get( iter.next() );
+ if( !argFunction.isType( TypeInfo.t_function ) ){
+ return false;
+ }
+
+ LinkedList args = ((IParameterizedSymbol) argFunction).getParameterList();
+
+ IParameterizedSymbol function = (IParameterizedSymbol) templateSymbol;
+
+ if( function.getParameterList() == null || function.getParameterList().size() != args.size() ){
+ return false;
+ }
+
+ HashMap map = new HashMap();
+
+ Iterator pIter = function.getParameterList().iterator();
+ Iterator aIter = args.iterator();
+ while( pIter.hasNext() ){
+ if( !deduceTemplateArgument( map, (ISymbol) pIter.next(), (ISymbol) aIter.next(), argSource.getArgumentMap() ) ){
+ return false;
+ }
+ }
+
return true;
}
+ static private boolean deduceTemplateArgument( HashMap map, ISymbol p, ISymbol a, HashMap argumentMap ){
+ if( argumentMap != null && argumentMap.containsKey( a ) ){
+ a = (ISymbol) argumentMap.get( a );
+ }
+
+ ISymbol pSymbol = p, aSymbol = a;
+
+ if( p.isType( TypeInfo.t_type ) ){
+ pSymbol = p.getTypeSymbol();
+ aSymbol = a.isType( TypeInfo.t_type ) ? a.getTypeSymbol() : a;
+ return deduceTemplateArgument( map, pSymbol, aSymbol, argumentMap );
+ } else {
+ if( pSymbol.isTemplateMember() && pSymbol.isType( TypeInfo.t_undef ) ){
+ //T* or T& or T[ const ]
+ //also
+ LinkedList pPtrs = pSymbol.getPtrOperators();
+ LinkedList aPtrs = aSymbol.getPtrOperators();
+
+ if( pPtrs != null ){
+ TypeInfo.PtrOp pOp = (TypeInfo.PtrOp) pPtrs.getFirst();
+ TypeInfo.PtrOp aOp = ( aPtrs != null ) ? (TypeInfo.PtrOp)aPtrs.getFirst() : null;
+
+ if( pOp != null && aOp != null && pOp.getType() == aOp.getType() ){
+ if( pOp.getType() == TypeInfo.PtrOp.t_memberPointer ){
+
+ } else {
+ TypeInfo type = new TypeInfo( aSymbol.getTypeInfo() );
+ type.getPtrOperators().clear();
+ map.put( pSymbol.getName(), type );
+ return true;
+ }
+ } else {
+ return false;
+ }
+ } else {
+ //T
+ map.put( pSymbol.getName(), a.getTypeInfo() );
+ return true;
+ }
+
+
+ }
+ //template-name<T> or template-name<i>
+ else if( pSymbol.isType( TypeInfo.t_template ) && aSymbol.isType( TypeInfo.t_template ) ){
+ LinkedList pArgs = ((IParameterizedSymbol)pSymbol).getArgumentList();
+ LinkedList aArgs = ((IParameterizedSymbol)aSymbol).getArgumentList();
+
+ if( pArgs == null || aArgs == null || pArgs.size() != aArgs.size()){
+ return false;
+ }
+ Iterator pIter = pArgs.iterator();
+ Iterator aIter = aArgs.iterator();
+ while( pIter.hasNext() ){
+ if( !deduceTemplateArgument( map, (ISymbol) pIter.next(), (ISymbol) aIter.next(), argumentMap ) ){
+ return false;
+ }
+ }
+ }
+ //T (*) ( ), T ( T::* ) ( T ), & variations
+ else if( pSymbol.isType( TypeInfo.t_function ) && aSymbol.isType( TypeInfo.t_function ) ){
+ IParameterizedSymbol pFunction = (IParameterizedSymbol)pSymbol;
+ IParameterizedSymbol aFunction = (IParameterizedSymbol)aSymbol;
+
+ if( !deduceTemplateArgument( map, aFunction.getReturnType(), pFunction.getReturnType(), argumentMap ) ){
+ return false;
+ }
+ if( pSymbol.getPtrOperators() != null ){
+ LinkedList ptrs = pSymbol.getPtrOperators();
+ TypeInfo.PtrOp op = (TypeInfo.PtrOp) ptrs.getFirst();
+ if( op.getType() == TypeInfo.PtrOp.t_memberPointer ){
+ if( !deduceTemplateArgument( map, op.getMemberOf(), pFunction.getContainingSymbol(), argumentMap ) ){
+ return false;
+ }
+ }
+ }
+
+ LinkedList pParams = pFunction.getParameterList();
+ LinkedList aParams = aFunction.getParameterList();
+ if( pParams.size() != aParams.size() ){
+ return false;
+ } else {
+ Iterator pIter = pParams.iterator();
+ Iterator aIter = aParams.iterator();
+ while( pIter.hasNext() ){
+ if( !deduceTemplateArgument( map, (ISymbol) pIter.next(), (ISymbol) aIter.next(), argumentMap ) ){
+ return false;
+ }
+ }
+ }
+
+ } else if( pSymbol.getType() == aSymbol.getType() ){
+ if( pSymbol.getTypeInfo().getHasDefault() ){
+ if( !aSymbol.getTypeInfo().getHasDefault() ||
+ aSymbol.getTypeInfo().getDefault().equals( pSymbol.getTypeInfo().getDefault() ) )
+ {
+ return false;
+ }
+ }
+ //value
+ map.put( pSymbol.getName(), aSymbol.getTypeInfo() );
+ return true;
+ }
+ }
+
+ return false;
+ }
/**
* transform the class template to a function template as described in the spec
* 14.5.4.2-1
@@ -1541,8 +1700,21 @@ public class ParserSymbolTable {
* has a single function parameter whose type is a class template specialization with the template
* arguments of the partial specialization
*/
- static private IParameterizedSymbol transformClassTemplateToFunctionTemplate( IParameterizedSymbol template ){
- return null;
+ static private IParameterizedSymbol classTemplateSpecializationToFunctionTemplate( IParameterizedSymbol template ){
+ IParameterizedSymbol transformed = (IParameterizedSymbol) template.clone();
+ transformed.setArgumentList( null );
+ transformed.getContainedSymbols().clear();
+
+ IParameterizedSymbol function = template.getSymbolTable().newParameterizedSymbol( transformed.getName(), TypeInfo.t_function );
+ try{
+ transformed.addSymbol( function );
+ } catch ( ParserSymbolTableException e ){
+ //we shouldn't get this because there aren't any other symbols in the template
+ }
+
+ function.addParameter( template );
+
+ return transformed;
}
/**
@@ -1557,8 +1729,26 @@ public class ParserSymbolTable {
* for each template template parameter, synthesize a unique class template and substitute that
* for each occurence of that parameter in the function parameter list
*/
- static private IParameterizedSymbol transformFunctionTemplateForOrdering( IParameterizedSymbol template ){
- return null;
+ static private TemplateInstance transformFunctionTemplateForOrdering( IParameterizedSymbol template ){
+
+ LinkedList paramList = template.getParameterList();
+
+ int size = ( paramList != null ) ? paramList.size() : 0;
+ if( size == 0 ){
+ return null;
+ }
+
+ HashMap map = new HashMap();
+ for( Iterator iterator = paramList.iterator(); iterator.hasNext(); ) {
+ ISymbol param = (ISymbol) iterator.next();
+ ISymbol val = template.getSymbolTable().newSymbol( "", TypeInfo.t_type );
+ if( false /* is value */ ){
+ //val.getTypeInfo().setHasDefault()
+ }
+ map.put( param, val );
+ }
+
+ return template.getSymbolTable().new TemplateInstance( template, map );
}
//private Stack _contextStack = new Stack();
@@ -2202,11 +2392,11 @@ public class ParserSymbolTable {
// _typeInfo.addPtrOperator( ptrStr, isConst, isVolatile );
//}
- public TypeInfo.eType getReturnType(){
+ public ISymbol getReturnType(){
return _returnType;
}
- public void setReturnType( TypeInfo.eType type ){
+ public void setReturnType( ISymbol type ){
_returnType = type;
}
@@ -2225,12 +2415,17 @@ public class ParserSymbolTable {
public LinkedList getArgumentList(){
return _argumentList;
}
+ public void setArgumentList( LinkedList list ){
+ _argumentList = list;
+ }
public void addArgument( ISymbol arg ){
if( _argumentList == null ){
_argumentList = new LinkedList();
}
_argumentList.addLast( arg );
+ arg.setIsTemplateMember( isTemplateMember() || getType() == TypeInfo.t_template );
+
Command command = new AddArgumentCommand( this, (BasicSymbol) arg );
pushCommand( command );
}
@@ -2837,7 +3032,16 @@ public class ParserSymbolTable {
if( getType() != TypeInfo.t_template ){
return null;
}
- List paramList = getParameterList();
+
+ //TODO uncomment when template specialization matching & ordering is working
+ //IParameterizedSymbol template = ParserSymbolTable.matchTemplatePartialSpecialization( this, arguments );
+ IParameterizedSymbol template = null;
+
+ if( template == null ){
+ template = this;
+ }
+
+ List paramList = template.getParameterList();
int numParams = ( paramList != null ) ? paramList.size() : 0;
if( numParams == 0 ){
@@ -2866,12 +3070,12 @@ public class ParserSymbolTable {
}
}
- if( getContainedSymbols().size() != 1 ){
+ if( template.getContainedSymbols().size() != 1 ){
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate );
}
- Iterator iter = getContainedSymbols().keySet().iterator();
- IContainerSymbol symbol = (IContainerSymbol) getContainedSymbols().get( iter.next() );
+ Iterator iter = template.getContainedSymbols().keySet().iterator();
+ IContainerSymbol symbol = (IContainerSymbol) template.getContainedSymbols().get( iter.next() );
TemplateInstance instance = new TemplateInstance( symbol, map );
return instance;
@@ -2891,7 +3095,7 @@ public class ParserSymbolTable {
private LinkedList _parameterList; //have my cake
private HashMap _parameterHash; //and eat it too
- private TypeInfo.eType _returnType;
+ private ISymbol _returnType;
@@ -3013,6 +3217,7 @@ public class ParserSymbolTable {
public static final eType t_enumerator = new eType( 15 );
public static final eType t_block = new eType( 16 );
public static final eType t_template = new eType( 17 );
+ //public static final eType t_templateParameter = new eType( 18 );
public static class eType implements Comparable{
private eType( int v ){
@@ -3040,27 +3245,33 @@ public class ParserSymbolTable {
this.isConst = isConst;
this.isVolatile = isVolatile;
}
+ public PtrOp( ISymbol memberOf, boolean isConst, boolean isVolatile ){
+ this.type = t_memberPointer;
+ this.isConst = isConst;
+ this.isVolatile = isVolatile;
+ this.memberOf = memberOf;
+ }
+
public PtrOp(){
super();
}
- public static final eType t_undef = new eType( 0 );
- public static final eType t_pointer = new eType( 1 );
- public static final eType t_reference = new eType( 2 );
- public static final eType t_array = new eType( 3 );
-
-
- private eType type = t_undef;
- private boolean isConst = false;
- private boolean isVolatile = false;
+ public static final eType t_undef = new eType( 0 );
+ public static final eType t_pointer = new eType( 1 );
+ public static final eType t_reference = new eType( 2 );
+ public static final eType t_array = new eType( 3 );
+ public static final eType t_memberPointer = new eType( 4 );
+
+ public eType getType() { return type; }
+ public void setType( eType type ) { this.type = type; }
- public eType getType() { return type; }
- public void setType( eType type ){ this.type = type; }
+ public boolean isConst() { return isConst; }
+ public boolean isVolatile() { return isVolatile; }
+ public void setConst( boolean isConst ) { this.isConst = isConst; }
+ public void setVolatile(boolean isVolatile) { this.isVolatile = isVolatile; }
- public boolean isConst() { return isConst; }
- public boolean isVolatile() { return isVolatile; }
- public void setConst( boolean isConst ) { this.isConst = isConst; }
- public void setVolatile( boolean isVolatile ){ this.isVolatile = isVolatile; }
+ public ISymbol getMemberOf() { return memberOf; }
+ public void setMemberOf( ISymbol member ) { this.memberOf = member; }
public int compareCVTo( PtrOp ptr ){
int cv1 = ( isConst() ? 1 : 0 ) + ( isVolatile() ? 1 : 0 );
@@ -3079,6 +3290,10 @@ public class ParserSymbolTable {
getType() == op.getType() );
}
+ private eType type = t_undef;
+ private boolean isConst = false;
+ private boolean isVolatile = false;
+ private ISymbol memberOf = null;
}
private static final String _image[] = { "",
diff --git a/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java b/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java
index 47f688280a6..b45ccf84e3a 100644
--- a/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java
+++ b/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java
@@ -1107,7 +1107,7 @@ public class ParserSymbolTableTest extends TestCase {
ParserSymbolTable.Declaration f1 = table.new Declaration( "f" );
f1.setType( ParserSymbolTable.TypeInfo.t_function );
- f1.setReturnType( ParserSymbolTable.TypeInfo.t_void );
+ f1.setReturnType( table.newSymbol( "", TypeInfo.t_void ) );
f1.addParameter( ParserSymbolTable.TypeInfo.t_int, 0, null, false );
A.addSymbol( f1 );
@@ -1121,7 +1121,7 @@ public class ParserSymbolTableTest extends TestCase {
IParameterizedSymbol f2 = table.newParameterizedSymbol("f");
f2.setType( ParserSymbolTable.TypeInfo.t_function );
- f2.setReturnType( ParserSymbolTable.TypeInfo.t_void );
+ f2.setReturnType( table.newSymbol( "", TypeInfo.t_void ) );
f2.addParameter( ParserSymbolTable.TypeInfo.t_char, 0, null, false );
A.addSymbol( f2 );
@@ -1244,7 +1244,7 @@ public class ParserSymbolTableTest extends TestCase {
IParameterizedSymbol f = table.newParameterizedSymbol("f");
f.setType( ParserSymbolTable.TypeInfo.t_function );
- f.setReturnType( ParserSymbolTable.TypeInfo.t_void );
+ f.setReturnType( table.newSymbol( "", TypeInfo.t_void ) );
ISymbol look = NS.Lookup( "T" );
assertEquals( look, T );
@@ -1264,7 +1264,7 @@ public class ParserSymbolTableTest extends TestCase {
IParameterizedSymbol main = table.newParameterizedSymbol("main");
main.setType( ParserSymbolTable.TypeInfo.t_function );
- main.setReturnType( ParserSymbolTable.TypeInfo.t_int );
+ main.setReturnType( table.newSymbol( "", TypeInfo.t_int ) );
compUnit.addSymbol( main );
LinkedList paramList = new LinkedList();
@@ -1312,7 +1312,7 @@ public class ParserSymbolTableTest extends TestCase {
ParserSymbolTable.Declaration f1 = table.new Declaration( "f" );
f1.setType( ParserSymbolTable.TypeInfo.t_function );
- f1.setReturnType( ParserSymbolTable.TypeInfo.t_void );
+ f1.setReturnType( table.newSymbol( "", TypeInfo.t_void ) );
f1.addParameter( ParserSymbolTable.TypeInfo.t_void, 0, new PtrOp( PtrOp.t_pointer ), false );
NS1.addSymbol( f1 );
@@ -1331,7 +1331,7 @@ public class ParserSymbolTableTest extends TestCase {
IParameterizedSymbol f2 = table.newParameterizedSymbol( "f" );
f2.setType( ParserSymbolTable.TypeInfo.t_function );
- f2.setReturnType( ParserSymbolTable.TypeInfo.t_void );
+ f2.setReturnType( table.newSymbol( "", TypeInfo.t_void ) );
f2.addParameter( ParserSymbolTable.TypeInfo.t_void, 0, new PtrOp( PtrOp.t_pointer ), false );
NS2.addSymbol( f2 );
@@ -1394,20 +1394,20 @@ public class ParserSymbolTableTest extends TestCase {
IParameterizedSymbol f1 = table.newParameterizedSymbol("foo");
f1.setType( ParserSymbolTable.TypeInfo.t_function );
- f1.setReturnType( ParserSymbolTable.TypeInfo.t_void );
+ f1.setReturnType( table.newSymbol( "", TypeInfo.t_void ) );
f1.addParameter( ParserSymbolTable.TypeInfo.t_int, 0, null, false );
C.addSymbol( f1 );
IParameterizedSymbol f2 = table.newParameterizedSymbol("foo");
f2.setType( ParserSymbolTable.TypeInfo.t_function );
- f2.setReturnType( ParserSymbolTable.TypeInfo.t_void );
+ f2.setReturnType( table.newSymbol( "", TypeInfo.t_void ) );
f2.addParameter( ParserSymbolTable.TypeInfo.t_int, 0, null, false );
f2.addParameter( ParserSymbolTable.TypeInfo.t_char, 0, null, false );
C.addSymbol( f2 );
IParameterizedSymbol f3 = table.newParameterizedSymbol("foo");
f3.setType( ParserSymbolTable.TypeInfo.t_function );
- f3.setReturnType( ParserSymbolTable.TypeInfo.t_void );
+ f3.setReturnType( table.newSymbol( "", TypeInfo.t_void ) );
f3.addParameter( ParserSymbolTable.TypeInfo.t_int, 0, null, false );
f3.addParameter( ParserSymbolTable.TypeInfo.t_char, 0, null, false );
f3.addParameter( C, new PtrOp( PtrOp.t_pointer ), false );
@@ -2186,7 +2186,6 @@ public class ParserSymbolTableTest extends TestCase {
/**
*
- * @throws Exception
* template < class T1, class T2, int I > class A {} //#1
* template < class T, int I > class A < T, T*, I > {} //#2
* template < class T1, class T2, int I > class A < T1*, T2, I > {} //#3
@@ -2198,12 +2197,17 @@ public class ParserSymbolTableTest extends TestCase {
* A <int, char*, 5> a3; //uses #4, T is char
* A <int, char*, 1> a4; //uses #5, T is int, T2 is char, I is1
* A <int*, int*, 2> a5; //ambiguous, matches #3 & #5.
- *
+ *
+ * @throws Exception
*/
public void incompletetestTemplateSpecialization() throws Exception{
newTable();
- IDerivableContainerSymbol cls = table.newDerivableContainerSymbol( "A", TypeInfo.t_class );
+ IDerivableContainerSymbol cls1 = table.newDerivableContainerSymbol( "A", TypeInfo.t_class );
+ IDerivableContainerSymbol cls2 = table.newDerivableContainerSymbol( "A", TypeInfo.t_class );
+ IDerivableContainerSymbol cls3 = table.newDerivableContainerSymbol( "A", TypeInfo.t_class );
+ IDerivableContainerSymbol cls4 = table.newDerivableContainerSymbol( "A", TypeInfo.t_class );
+ IDerivableContainerSymbol cls5 = table.newDerivableContainerSymbol( "A", TypeInfo.t_class );
IParameterizedSymbol template1 = table.newParameterizedSymbol( "A", TypeInfo.t_template );
ISymbol T1p1 = table.newSymbol( "T1", TypeInfo.t_undef );
@@ -2212,7 +2216,7 @@ public class ParserSymbolTableTest extends TestCase {
template1.addParameter( T1p1 );
template1.addParameter( T1p2 );
template1.addParameter( T1p3 );
- template1.addSymbol( cls );
+ template1.addSymbol( cls1 );
table.getCompilationUnit().addSymbol( template1 );
IParameterizedSymbol template2 = table.newParameterizedSymbol( "A", TypeInfo.t_template );
@@ -2227,7 +2231,7 @@ public class ParserSymbolTableTest extends TestCase {
template2.addArgument( T2a1 );
template2.addArgument( T2a2 );
template2.addArgument( T2a3 );
- template2.addSymbol( cls );
+ template2.addSymbol( cls2 );
template1.addSpecialization( template2 );
IParameterizedSymbol template3 = table.newParameterizedSymbol( "A", TypeInfo.t_template );
@@ -2244,7 +2248,7 @@ public class ParserSymbolTableTest extends TestCase {
template3.addArgument( T3a1 );
template3.addArgument( T3a2 );
template3.addArgument( T3a3 );
- template3.addSymbol( cls );
+ template3.addSymbol( cls3 );
template1.addSpecialization( template3 );
IParameterizedSymbol template4 = table.newParameterizedSymbol( "A", TypeInfo.t_template );
@@ -2253,13 +2257,13 @@ public class ParserSymbolTableTest extends TestCase {
ISymbol T4a1 = table.newSymbol( "", TypeInfo.t_int );
ISymbol T4a2 = table.newSymbol( "T", TypeInfo.t_undef );
- T4a1.addPtrOperator( new PtrOp( PtrOp.t_pointer ) );
+ T4a2.addPtrOperator( new PtrOp( PtrOp.t_pointer ) );
ISymbol T4a3 = table.newSymbol( "", TypeInfo.t_int );
T4a3.getTypeInfo().setDefault( new Integer(5) );
template4.addArgument( T4a1 );
template4.addArgument( T4a2 );
template4.addArgument( T4a3 );
- template4.addSymbol( cls );
+ template4.addSymbol( cls4 );
template1.addSpecialization( template4 );
IParameterizedSymbol template5 = table.newParameterizedSymbol( "A", TypeInfo.t_template );
@@ -2276,7 +2280,7 @@ public class ParserSymbolTableTest extends TestCase {
template5.addArgument( T5a1 );
template5.addArgument( T5a2 );
template5.addArgument( T5a3 );
- template5.addSymbol( cls );
+ template5.addSymbol( cls5 );
template1.addSpecialization( template5 );
IParameterizedSymbol a = (IParameterizedSymbol) table.getCompilationUnit().Lookup( "A" );
@@ -2288,7 +2292,7 @@ public class ParserSymbolTableTest extends TestCase {
args.add( new TypeInfo( TypeInfo.t_int, 0, null, null, new Integer(1) ) );
TemplateInstance a1 = a.instantiate( args );
- assertEquals( a1.getInstantiatedSymbol(), template1 );
+ assertEquals( a1.getInstantiatedSymbol(), cls1 );
args.clear();
args.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
@@ -2296,21 +2300,21 @@ public class ParserSymbolTableTest extends TestCase {
args.add( new TypeInfo( TypeInfo.t_int, 0, null, null, new Integer(1) ) );
TemplateInstance a2 = a.instantiate( args );
- assertEquals( a2.getInstantiatedSymbol(), template2 );
+ assertEquals( a2.getInstantiatedSymbol(), cls2 );
args.clear();
args.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
args.add( new TypeInfo( TypeInfo.t_char, 0, null, new PtrOp( PtrOp.t_pointer ), false ) );
args.add( new TypeInfo( TypeInfo.t_int, 0, null, null, new Integer(5) ) );
TemplateInstance a3 = a.instantiate( args );
- assertEquals( a3.getInstantiatedSymbol(), template4 );
+ assertEquals( a3.getInstantiatedSymbol(), cls4 );
args.clear();
args.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
args.add( new TypeInfo( TypeInfo.t_char, 0, null, new PtrOp( PtrOp.t_pointer ), false ) );
args.add( new TypeInfo( TypeInfo.t_int, 0, null, null, new Integer(1) ) );
TemplateInstance a4 = a.instantiate( args );
- assertEquals( a4.getInstantiatedSymbol(), template5 );
+ assertEquals( a4.getInstantiatedSymbol(), cls5 );
args.clear();
args.add( new TypeInfo( TypeInfo.t_int, 0, null, new PtrOp( PtrOp.t_pointer ), false ) );

Back to the top